From a6714922d100fc9ca90cfc4dc4bb0df875206197 Mon Sep 17 00:00:00 2001 From: Hans Wennborg Date: Tue, 29 Nov 2016 22:31:00 +0000 Subject: [PATCH] Don't try to merge DLL attributes on redeclaration of invalid decl (PR31069) llvm-svn: 288207 --- clang/lib/Sema/SemaDecl.cpp | 3 +++ clang/test/Sema/dllimport.c | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 58776e8..e8764a0 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -5651,6 +5651,9 @@ static void checkDLLAttributeRedeclaration(Sema &S, NamedDecl *OldDecl, NamedDecl *NewDecl, bool IsSpecialization, bool IsDefinition) { + if(OldDecl->isInvalidDecl()) + return; + if (TemplateDecl *OldTD = dyn_cast(OldDecl)) { OldDecl = OldTD->getTemplatedDecl(); if (!IsSpecialization) diff --git a/clang/test/Sema/dllimport.c b/clang/test/Sema/dllimport.c index 0728cf1..a7fb00e3 100644 --- a/clang/test/Sema/dllimport.c +++ b/clang/test/Sema/dllimport.c @@ -210,6 +210,10 @@ __declspec(dllimport) void redecl6(); void redecl7(); __declspec(dllimport) inline void redecl7() {} +// 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'}} + // External linkage is required. __declspec(dllimport) static int staticFunc(); // expected-error{{'staticFunc' must have external linkage when declared 'dllimport'}} -- 2.7.4