[llvm-commits] [dragonegg] r156262 - /dragonegg/trunk/src/Backend.cpp
Duncan Sands
baldrick at free.fr
Sun May 6 10:28:23 PDT 2012
Author: baldrick
Date: Sun May 6 12:28:22 2012
New Revision: 156262
URL: http://llvm.org/viewvc/llvm-project?rev=156262&view=rev
Log:
Don't use freed memory when a global is initialized to itself. Fires with
gcc-4.7 on Sema/const-ptr-int-ptr-cast.c from the clang testsuite (which is
tested by dragonegg's "compilator").
Modified:
dragonegg/trunk/src/Backend.cpp
Modified: dragonegg/trunk/src/Backend.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/src/Backend.cpp?rev=156262&r1=156261&r2=156262&view=diff
==============================================================================
--- dragonegg/trunk/src/Backend.cpp (original)
+++ dragonegg/trunk/src/Backend.cpp Sun May 6 12:28:22 2012
@@ -990,16 +990,21 @@
// global union, and the LLVM type followed a union initializer that is
// different from the union element used for the type.
if (GV->getType()->getElementType() != Init->getType()) {
- GV->removeFromParent();
- GlobalVariable *NGV = new GlobalVariable(*TheModule, Init->getType(),
- GV->isConstant(),
- GlobalValue::ExternalLinkage, 0,
- GV->getName());
- GV->replaceAllUsesWith(TheFolder->CreateBitCast(NGV, GV->getType()));
- changeLLVMConstant(GV, NGV);
- delete GV;
- SET_DECL_LLVM(decl, NGV);
- GV = NGV;
+ if (GV == Init) {
+ // Global initialized to its own address.
+ Init = TheFolder->CreateBitCast(Init, GV->getType()->getElementType());
+ } else {
+ GV->removeFromParent();
+ GlobalVariable *NGV = new GlobalVariable(*TheModule, Init->getType(),
+ GV->isConstant(),
+ GlobalValue::ExternalLinkage, 0,
+ GV->getName());
+ GV->replaceAllUsesWith(TheFolder->CreateBitCast(NGV, GV->getType()));
+ changeLLVMConstant(GV, NGV);
+ delete GV;
+ SET_DECL_LLVM(decl, NGV);
+ GV = NGV;
+ }
}
// Set the initializer.
More information about the llvm-commits
mailing list