]> granicus.if.org Git - clang/commitdiff
Fix PR34981, a crash-on-invalid merging dllimport to an invalid redecl.
authorNico Weber <nicolasweber@gmx.de>
Tue, 17 Oct 2017 21:14:02 +0000 (21:14 +0000)
committerNico Weber <nicolasweber@gmx.de>
Tue, 17 Oct 2017 21:14:02 +0000 (21:14 +0000)
This is basically like r288207, just the other way round.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@316032 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/Sema/dllimport.c

index 7df9ed5180471ac3f04a2c8bb777306ff0af2c69..9e5fa0e563494d0f811c499de92b5352285925b7 100644 (file)
@@ -5975,7 +5975,7 @@ static void checkDLLAttributeRedeclaration(Sema &S, NamedDecl *OldDecl,
                                            NamedDecl *NewDecl,
                                            bool IsSpecialization,
                                            bool IsDefinition) {
-  if (OldDecl->isInvalidDecl())
+  if (OldDecl->isInvalidDecl() || NewDecl->isInvalidDecl())
     return;
 
   bool IsTemplate = false;
@@ -6081,7 +6081,8 @@ static void checkDLLAttributeRedeclaration(Sema &S, NamedDecl *OldDecl,
       NewDecl->dropAttr<DLLImportAttr>();
     }
   } else if (IsInline && OldImportAttr && !IsMicrosoft) {
-    // In MinGW, seeing a function declared inline drops the dllimport attribute.
+    // In MinGW, seeing a function declared inline drops the dllimport
+    // attribute.
     OldDecl->dropAttr<DLLImportAttr>();
     NewDecl->dropAttr<DLLImportAttr>();
     S.Diag(NewDecl->getLocation(),
index d05ed6ef3fa57dddf1cf522cc56377d38ddb44ef..53bf372c65423f61af6544a54034f7bc30b468a3 100644 (file)
@@ -211,9 +211,14 @@ __declspec(dllimport) void redecl6();
                       void redecl7();
 __declspec(dllimport) inline void redecl7() {}
 
-// PR31069: Don't crash trying to merge attributes for redeclaration of invalid decl.
+// PR31069: Don't crash trying to merge attributes for redeclaration of invalid
+// decl.
 void __declspec(dllimport) redecl8(unknowntype X); // expected-error{{unknown type name 'unknowntype'}}
 void redecl8(unknowntype X) { } // expected-error{{unknown type name 'unknowntype'}}
+// PR32021: Similarly, don't crash trying to merge attributes from a valid
+// decl to an invalid redeclaration.
+void __declspec(dllimport) redecl9(void); // expected-note{{previous declaration is here}}
+int redecl9(void) {} // expected-error{{conflicting types for 'redecl9'}}
 
 // External linkage is required.
 __declspec(dllimport) static int staticFunc(); // expected-error{{'staticFunc' must have external linkage when declared 'dllimport'}}