From ab38736dccaf7269562779f4f70d441b5c2285ec Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Tue, 17 Oct 2017 21:14:02 +0000 Subject: [PATCH] Fix PR34981, a crash-on-invalid merging dllimport to an invalid redecl. 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 | 5 +++-- test/Sema/dllimport.c | 7 ++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 7df9ed5180..9e5fa0e563 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -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(); } } 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(); NewDecl->dropAttr(); S.Diag(NewDecl->getLocation(), diff --git a/test/Sema/dllimport.c b/test/Sema/dllimport.c index d05ed6ef3f..53bf372c65 100644 --- a/test/Sema/dllimport.c +++ b/test/Sema/dllimport.c @@ -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'}} -- 2.40.0