Better codegen support for DLL attributes being dropped after the first declaration (PR20792)

For the following code:

  __declspec(dllimport) int f(int x);
  int user(int x) {
    return f(x);
  }
  int f(int x) { return 1; }

Clang will drop the dllimport attribute in the AST, but CodeGen would have
already put it on the LLVM::Function, and that would never get updated.
(The same thing happens for global variables.)

This makes Clang check dropped DLL attribute case each time the LLVM object
is referenced.

This isn't perfect, because we will still get it wrong if the function is
never referenced by codegen after the attribute is dropped, but this handles
the common cases and makes us not fail in the verifier.

llvm-svn: 216699
This commit is contained in:
Hans Wennborg
2014-08-29 00:16:06 +00:00
parent 400e725bde
commit 0a20f5417c
2 changed files with 25 additions and 4 deletions

View File

@@ -1449,6 +1449,10 @@ CodeGenModule::GetOrCreateLLVMFunction(StringRef MangledName,
Entry->setLinkage(llvm::Function::ExternalLinkage);
}
// Handle dropped DLL attributes.
if (D && !D->hasAttr<DLLImportAttr>() && !D->hasAttr<DLLExportAttr>())
Entry->setDLLStorageClass(llvm::GlobalValue::DefaultStorageClass);
if (Entry->getType()->getElementType() == Ty)
return Entry;
@@ -1614,6 +1618,10 @@ CodeGenModule::GetOrCreateLLVMGlobal(StringRef MangledName,
Entry->setLinkage(llvm::Function::ExternalLinkage);
}
// Handle dropped DLL attributes.
if (D && !D->hasAttr<DLLImportAttr>() && !D->hasAttr<DLLExportAttr>())
Entry->setDLLStorageClass(llvm::GlobalValue::DefaultStorageClass);
if (Entry->getType() == Ty)
return Entry;