Sema: Allow aliases to have incomplete type
authorDavid Majnemer <david.majnemer@gmail.com>
Wed, 9 Jul 2014 17:15:52 +0000 (17:15 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Wed, 9 Jul 2014 17:15:52 +0000 (17:15 +0000)
gcc supports this behavior and it is pervasively used inside the Linux
kernel.

Note that both gcc and clang will reject code that attempts to do this
in a C++ language mode.

This fixes PR17998.

llvm-svn: 212631

clang/lib/Sema/SemaDecl.cpp
clang/test/Sema/attr-alias-elf.c

index 82d28fa..13a77f1 100644 (file)
@@ -8897,11 +8897,13 @@ void Sema::ActOnUninitializedDecl(Decl *RealDecl,
     if (Var->isInvalidDecl())
       return;
 
-    if (RequireCompleteType(Var->getLocation(), 
-                            Context.getBaseElementType(Type),
-                            diag::err_typecheck_decl_incomplete_type)) {
-      Var->setInvalidDecl();
-      return;
+    if (!Var->hasAttr<AliasAttr>()) {
+      if (RequireCompleteType(Var->getLocation(),
+                              Context.getBaseElementType(Type),
+                              diag::err_typecheck_decl_incomplete_type)) {
+        Var->setInvalidDecl();
+        return;
+      }
     }
 
     // The variable can not have an abstract class type.
index 04d1392..f14514d 100644 (file)
@@ -64,3 +64,6 @@ void test3_foo() __attribute__((alias("test3_bar")));
 __attribute__((section("test"))) void test4_bar() { }
 void test4_foo() __attribute__((section("test")));
 void test4_foo() __attribute__((alias("test4_bar")));
+
+int test5_bar = 0;
+extern struct incomplete_type test5_foo __attribute__((alias("test5_bar")));