[PATCH] D28266: Transparent_union attribute should be possible in front of union (rework)

Erich Keane via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 3 16:48:23 PST 2017


erichkeane created this revision.
erichkeane added reviewers: cfe-commits, bruno, aaron.ballman, rsmith.

This is an update of this patch: https://reviews.llvm.org/D25824

I cannot seem to get that review to update with my diff.  This first patch removes the dependency on isParsing and switches to isBeingDefined.  In order to get that to work, changing where attributes where changed was necessary.

Original description below:

Clang compiles with error following test case

typedef union attribute((transparent_union)) {

int *i;
struct st *s;

} TU;

void bar(TU);

void foo(int *i) {

bar(i);

}

clang -c tu.c
tu.c:1:30: warning: transparent_union attribute can only be applied to a union definition; attribute ignored [-Wignored-attributes]
typedef union attribute((transparent_union)) {

^

tu.c:8:24: error: passing 'int *' to parameter of incompatible type 'TU'
void foo(int *i) { bar(i); }

^

tu.c:6:12: note: passing argument to parameter here
void bar(TU);

^

GCC compiles this test successfully.

The compilation is failed because the routine handleTransparentUnionAttr requires for the record decl to be completed. This fix provides handling of the attribute ‘transparent_union’ after parsing of union.


https://reviews.llvm.org/D28266

Files:
  include/clang/Sema/Sema.h
  lib/Parse/ParseDeclCXX.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaDeclAttr.cpp
  test/CodeGen/transparent-union.c
  test/Sema/transparent-union.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28266.82976.patch
Type: text/x-patch
Size: 5618 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170104/41df556a/attachment-0001.bin>


More information about the cfe-commits mailing list