[llvm-commits] [dragonegg] r89559 - /dragonegg/trunk/llvm-backend.cpp
Duncan Sands
baldrick at free.fr
Sat Nov 21 01:52:13 PST 2009
Author: baldrick
Date: Sat Nov 21 03:52:13 2009
New Revision: 89559
URL: http://llvm.org/viewvc/llvm-project?rev=89559&view=rev
Log:
Add assertions checking that globals we output have the same size as the
corresponding gcc declaration. I'm pretty sure we get this wrong from
time to time, when DECL_SIZE differs from the type size. These asserts
are there to find examples of this.
Modified:
dragonegg/trunk/llvm-backend.cpp
Modified: dragonegg/trunk/llvm-backend.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/llvm-backend.cpp?rev=89559&r1=89558&r2=89559&view=diff
==============================================================================
--- dragonegg/trunk/llvm-backend.cpp (original)
+++ dragonegg/trunk/llvm-backend.cpp Sat Nov 21 03:52:13 2009
@@ -272,6 +272,18 @@
return 200;
}
+// SizeOfGlobalMatchesDecl - Whether the size of the given global value
+// is the same as that of the given GCC declaration.
+static bool SizeOfGlobalMatchesDecl(GlobalValue *GV, tree decl) {
+ const Type *Ty = GV->getType()->getElementType();
+ if (!DECL_SIZE(decl) || !Ty->isSized())
+ return true;
+ if (!isInt64(DECL_SIZE(decl), true))
+ return false;
+ return TheTarget->getTargetData()->getTypeAllocSizeInBits(Ty) ==
+ getInt64(DECL_SIZE(decl), true);
+}
+
#ifndef LLVM_TARGET_NAME
#error LLVM_TARGET_NAME macro not specified
#endif
@@ -1049,6 +1061,7 @@
GV->isConstant(),
GV->getLinkage(), 0,
GV->getName());
+ assert(SizeOfGlobalMatchesDecl(NGV, decl) && "Global has wrong size!");
NGV->setVisibility(GV->getVisibility());
NGV->setSection(GV->getSection());
NGV->setAlignment(GV->getAlignment());
@@ -1126,6 +1139,7 @@
GV->isConstant(),
GlobalValue::ExternalLinkage, 0,
GV->getName());
+ assert(SizeOfGlobalMatchesDecl(NGV, decl) && "Global has wrong size!");
GV->replaceAllUsesWith(TheFolder->CreateBitCast(NGV, GV->getType()));
changeLLVMConstant(GV, NGV);
delete GV;
@@ -1494,6 +1508,7 @@
if (TREE_CODE(decl) == VAR_DECL && DECL_THREAD_LOCAL_P(decl))
GV->setThreadLocal(true);
+ assert(SizeOfGlobalMatchesDecl(GV, decl) && "Global has wrong size!");
return SET_DECL_LLVM(decl, GV);
}
//TODO timevar_pop(TV_LLVM_GLOBALS);
More information about the llvm-commits
mailing list