From: Hans Wennborg Date: Thu, 22 May 2014 15:46:15 +0000 (+0000) Subject: An inline function redeclaration does not drop the dllimport attribute X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e15696045114a756a06daa24e213d084050af17d;p=clang An inline function redeclaration does not drop the dllimport attribute git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@209449 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index d65ba117dc..88f099f96d 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -4898,9 +4898,11 @@ static void checkDLLAttributeRedeclaration(Sema &S, NamedDecl *OldDecl, // A redeclaration is not allowed to drop a dllimport attribute, the only // exception being inline function definitions. - // FIXME: Handle inline functions. // NB: MSVC converts such a declaration to dllexport. - if (OldImportAttr && !HasNewAttr) { + bool IsInline = + isa(NewDecl) && cast(NewDecl)->isInlined(); + + if (OldImportAttr && !HasNewAttr && !IsInline) { S.Diag(NewDecl->getLocation(), diag::warn_redeclaration_without_attribute_prev_attribute_ignored) << NewDecl << OldImportAttr; diff --git a/test/Rewriter/missing-dllimport.c b/test/Rewriter/missing-dllimport.c index 1e4689fba0..a09ebff44d 100644 --- a/test/Rewriter/missing-dllimport.c +++ b/test/Rewriter/missing-dllimport.c @@ -1,19 +1,8 @@ -// RUN: not %clang_cc1 -triple i686-pc-win32 -fms-extensions -fsyntax-only %s 2>&1 | FileCheck -check-prefix=CHECK-NEG %s -// RUN: not %clang_cc1 -triple i686-pc-win32 -fsyntax-only %s 2>&1 | FileCheck -check-prefix=CHECK-POS %s +// RUN: %clang_cc1 -triple i686-pc-win32 -verify %s -// Do not report that 'foo()' is redeclared without dllimport attribute with -fms-extensions +// Do not report that 'foo()' is redeclared without dllimport attribute. // specified. Addresses . +// expected-no-diagnostics __declspec(dllimport) int __cdecl foo(void); inline int __cdecl foo() { return 0; } - -// This function is added just to trigger a diagnostic. This way we can test how many -// diagnostics we expect. -void bar() { return 1; } - -// CHECK-NEG: error: void function 'bar' should not return a value -// CHECK-NEG: 1 error generated -// CHECK-POS: warning: 'foo' redeclared without 'dllimport' attribute: previous 'dllimport' ignored -// CHECK-POS: error: void function 'bar' should not return a value -// CHECK-POS: 1 warning and 1 error generated - diff --git a/test/Sema/dllimport.c b/test/Sema/dllimport.c index fa3e2b385a..2c504d1f77 100644 --- a/test/Sema/dllimport.c +++ b/test/Sema/dllimport.c @@ -118,5 +118,9 @@ __declspec(dllimport) void redecl3(); // expected-note{{previous declaration is void redecl4(); // expected-note{{previous declaration is here}} __declspec(dllimport) void redecl4(); // expected-error{{redeclaration of 'redecl4' cannot add 'dllimport' attribute}} +// Inline redeclarations are fine. +__declspec(dllimport) void redecl5(); +inline void redecl5() {} + // External linkage is required. __declspec(dllimport) static int staticFunc(); // expected-error{{'staticFunc' must have external linkage when declared 'dllimport'}}