Author: arphaman
Date: Wed Oct 12 04:36:35 2016
New Revision: 283995

URL: http://llvm.org/viewvc/llvm-project?rev=283995&view=rev
Log:
[Sema] Handle transparent_union attributes in C mode only

This commit marks the transparent_union attributes as C only because clang
doesn't support them in C++ mode. Prior to this commit, clang still tried to
verify these attributes in C++, leading to crashes when analyzing templated
transparent_union unions that have dependent field types. This commit ensures
that such crashes won't happen again.

As a result of this commit clang now displays a warning every time it encounters
a transparent_union attribute in C++ mode.

Differential Revision: https://reviews.llvm.org/D25308

Modified:
    cfe/trunk/include/clang/Basic/Attr.td
    cfe/trunk/test/SemaCXX/attr-gnu.cpp

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=283995&r1=283994&r2=283995&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Wed Oct 12 04:36:35 2016
@@ -1543,6 +1543,7 @@ def TransparentUnion : InheritableAttr {
   let Spellings = [GCC<"transparent_union">];
 //  let Subjects = SubjectList<[Record, TypedefName]>;
   let Documentation = [Undocumented];
+  let LangOpts = [COnly];
 }
 
 def Unavailable : InheritableAttr {

Modified: cfe/trunk/test/SemaCXX/attr-gnu.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/attr-gnu.cpp?rev=283995&r1=283994&r2=283995&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/attr-gnu.cpp (original)
+++ cfe/trunk/test/SemaCXX/attr-gnu.cpp Wed Oct 12 04:36:35 2016
@@ -27,3 +27,19 @@ public:
   void test3() __attribute__((cf_unknown_transfer)) override {} // Ok, not 
known to GCC.
 };
 }
+
+template<typename T>
+union Tu { T b; } __attribute__((transparent_union)); // expected-warning 
{{'transparent_union' attribute ignored}}
+
+template<typename T>
+union Tu2 { int x; T b; } __attribute__((transparent_union)); // 
expected-warning {{'transparent_union' attribute ignored}}
+
+union Tu3 { int x; } __attribute((transparent_union)); // expected-warning 
{{'transparent_union' attribute ignored}}
+
+void tuTest1(Tu<int> u); // expected-note {{candidate function not viable: no 
known conversion from 'int' to 'Tu<int>' for 1st argument}}
+void tuTest2(Tu3 u); // expected-note {{candidate function not viable: no 
known conversion from 'int' to 'Tu3' for 1st argument}}
+void tu() {
+  int x = 2;
+  tuTest1(x); // expected-error {{no matching function for call to 'tuTest1'}}
+  tuTest2(x); // expected-error {{no matching function for call to 'tuTest2'}}
+}


_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to