Skip to content

Commit 5ed5ad3

Browse files
Add regression test for TagDecl de-nesting with outer qualifier.
1 parent 4c85580 commit 5ed5ad3

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

clang/test/3C/inline_anon_structs.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,3 +323,34 @@ typedef const struct { int *x; } SFOO_CONST, *PSFOO_CONST;
323323
//CHECK: struct SFOO_CONST_struct_1 { _Ptr<int> x; };
324324
//CHECK-NEXT: typedef const struct SFOO_CONST_struct_1 SFOO_CONST;
325325
//CHECK-NEXT: typedef _Ptr<const struct SFOO_CONST_struct_1> PSFOO_CONST;
326+
327+
// Test that when the outer struct is preceded by a qualifier, de-nesting
328+
// inserts inner structs before the qualifier, not between the qualifier and the
329+
// outer `struct` keyword. This is moot if the outer struct is split as part of
330+
// multi-decl rewriting because multi-decl rewriting will delete the qualifier
331+
// and add it before the first member, but the problem can happen if the
332+
// multi-decl isn't rewritten or the outer struct isn't split because we have a
333+
// typedef for it.
334+
335+
typedef struct { struct q_not_rewritten_inner {} *x; } *q_not_rewritten_outer;
336+
q_not_rewritten_outer onr = (q_not_rewritten_outer)1;
337+
//CHECK: struct q_not_rewritten_inner {};
338+
//CHECK-NEXT: typedef struct { _Ptr<struct q_not_rewritten_inner> x; } *q_not_rewritten_outer;
339+
340+
typedef struct {
341+
struct q_typedef_inner {} *x;
342+
} q_typedef_outer, *q_typedef_outer_trigger_rewrite;
343+
//CHECK: struct q_typedef_inner {};
344+
//CHECK-NEXT: typedef struct {
345+
//CHECK-NEXT: _Ptr<struct q_typedef_inner> x;
346+
//CHECK-NEXT: } q_typedef_outer;
347+
//CHECK-NEXT: typedef _Ptr<q_typedef_outer> q_typedef_outer_trigger_rewrite;
348+
349+
// As noted in the comment in DeclRewriter::denestTagDecls, when the outer
350+
// struct isn't part of a multi-decl, we don't have an easy way to find the
351+
// location before the (useless) qualifier, so the output is a bit weird but
352+
// still has only a compiler warning, though in a different place than it
353+
// should.
354+
typedef struct { struct q_pointless_inner {} *x; };
355+
//CHECK: typedef struct q_pointless_inner {};
356+
//CHECK-NEXT: struct { _Ptr<struct q_pointless_inner> x; };

0 commit comments

Comments
 (0)