mirror of https://github.com/microsoft/clang.git
CodeGen: Don't crash when replacing functions
The peculiarities of C99 create scenario where an LLVM IR function declaration may need to be replaced with a definition baring a different type because the prototype and definition are not required to agree. However, we were not properly deferring this when it occurred. This fixes PR19280. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@205099 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
4eff9acb0b
commit
6614bf2dd1
|
@ -1177,12 +1177,14 @@ void CodeGenModule::EmitGlobal(GlobalDecl GD) {
|
|||
if (!FD->doesDeclarationForceExternallyVisibleDefinition())
|
||||
return;
|
||||
|
||||
const FunctionDecl *InlineDefinition = 0;
|
||||
FD->getBody(InlineDefinition);
|
||||
|
||||
StringRef MangledName = getMangledName(GD);
|
||||
DeferredDecls.erase(MangledName);
|
||||
EmitGlobalDefinition(InlineDefinition);
|
||||
|
||||
// Compute the function info and LLVM type.
|
||||
const CGFunctionInfo &FI = getTypes().arrangeGlobalDeclaration(GD);
|
||||
llvm::Type *Ty = getTypes().GetFunctionType(FI);
|
||||
|
||||
GetOrCreateLLVMFunction(MangledName, Ty, GD, /*ForVTable=*/false,
|
||||
/*DontDefer=*/false);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -39,6 +39,9 @@ extern int f7(void) { return 0; }
|
|||
// CHECK-GNU89-LABEL: define i32 @fA()
|
||||
inline int fA(void) { return 0; }
|
||||
|
||||
// CHECK-GNU89-LABEL: define i32 @fB()
|
||||
inline int fB() { return 0; }
|
||||
|
||||
// CHECK-GNU89-LABEL: define available_externally i32 @f4()
|
||||
// CHECK-C99-LABEL: define i32 @f4()
|
||||
int f4(void);
|
||||
|
@ -56,7 +59,11 @@ extern inline int f9(void) { return 0; }
|
|||
|
||||
// CHECK-C99-LABEL: define available_externally i32 @fA()
|
||||
|
||||
// CHECK-C99-LABEL: define i32 @fB()
|
||||
|
||||
int test_all() {
|
||||
return f0() + f1() + f2() + f3() + f4() + f5() + f6() + f7() + f8() + f9()
|
||||
+ fA();
|
||||
+ fA() + fB();
|
||||
}
|
||||
|
||||
int fB(void);
|
||||
|
|
Loading…
Reference in New Issue