From: David Majnemer Date: Sat, 29 Mar 2014 14:19:55 +0000 (+0000) Subject: CodeGen: Don't crash when replacing functions X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6614bf2dd1f7e09bbef38b243fd42f7182897908;p=clang 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 --- diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index addf8d09e4..92f49379f1 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -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 { diff --git a/test/CodeGen/inline2.c b/test/CodeGen/inline2.c index 670ae201f9..84cd4db027 100644 --- a/test/CodeGen/inline2.c +++ b/test/CodeGen/inline2.c @@ -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);