[PATCH] D98548: [clang][Sema] Don't try to initialize implicit variable of invalid anonymous union/struct

Ta-Wei Tu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 12 12:38:24 PST 2021


TaWeiTu created this revision.
TaWeiTu added reviewers: tmatheson, rsmith, dnsampaio.
TaWeiTu requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This fixes https://bugs.llvm.org/show_bug.cgi?id=49534, where the call to the constructor 
of the anonymous union is checked and triggers assertion failure when trying to retrieve 
the alignment of the `this` argument (which is a union with virtual function).

The extra check for alignment was introduced in D97187 <https://reviews.llvm.org/D97187>.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D98548

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/SemaCXX/PR49534.cpp


Index: clang/test/SemaCXX/PR49534.cpp
===================================================================
--- /dev/null
+++ clang/test/SemaCXX/PR49534.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -x c++ -fsyntax-only %s -verify
+
+static union {     // expected-warning {{declaration does not declare anything}}
+  virtual int a(); // expected-error {{unions cannot have virtual functions}} \
+                   // expected-error {{functions cannot be declared in an anonymous union}}
+};
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -5211,7 +5211,8 @@
     // trivial in almost all cases, except if a union member has an in-class
     // initializer:
     //   union { int n = 0; };
-    ActOnUninitializedDecl(Anon);
+    if (!Invalid)
+      ActOnUninitializedDecl(Anon);
   }
   Anon->setImplicit();
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98548.330347.patch
Type: text/x-patch
Size: 927 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210312/070578ea/attachment.bin>


More information about the cfe-commits mailing list