r209449 - An inline function redeclaration does not drop the dllimport attribute

Hans Wennborg hans at hanshq.net
Thu May 22 08:46:16 PDT 2014


Author: hans
Date: Thu May 22 10:46:15 2014
New Revision: 209449

URL: http://llvm.org/viewvc/llvm-project?rev=209449&view=rev
Log:
An inline function redeclaration does not drop the dllimport attribute

Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/Rewriter/missing-dllimport.c
    cfe/trunk/test/Sema/dllimport.c

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=209449&r1=209448&r2=209449&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu May 22 10:46:15 2014
@@ -4898,9 +4898,11 @@ static void checkDLLAttributeRedeclarati
 
   // 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<FunctionDecl>(NewDecl) && cast<FunctionDecl>(NewDecl)->isInlined();
+
+  if (OldImportAttr && !HasNewAttr && !IsInline) {
     S.Diag(NewDecl->getLocation(),
            diag::warn_redeclaration_without_attribute_prev_attribute_ignored)
       << NewDecl << OldImportAttr;

Modified: cfe/trunk/test/Rewriter/missing-dllimport.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/missing-dllimport.c?rev=209449&r1=209448&r2=209449&view=diff
==============================================================================
--- cfe/trunk/test/Rewriter/missing-dllimport.c (original)
+++ cfe/trunk/test/Rewriter/missing-dllimport.c Thu May 22 10:46:15 2014
@@ -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 <rdar://problem/7653912>.
 
+// 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
-

Modified: cfe/trunk/test/Sema/dllimport.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/dllimport.c?rev=209449&r1=209448&r2=209449&view=diff
==============================================================================
--- cfe/trunk/test/Sema/dllimport.c (original)
+++ cfe/trunk/test/Sema/dllimport.c Thu May 22 10:46:15 2014
@@ -118,5 +118,9 @@ __declspec(dllimport) void redecl3(); //
                       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'}}





More information about the cfe-commits mailing list