[llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp
Alkis Evlogimenos
alkis at cs.uiuc.edu
Thu Feb 17 19:19:17 PST 2005
Changes in directory llvm-java/lib/Compiler:
Compiler.cpp updated: 1.221 -> 1.222
---
Log message:
Mark static final fields with a static initializer as Constants.
---
Diffs of the changes: (+14 -5)
Compiler.cpp | 19 ++++++++++++++-----
1 files changed, 14 insertions(+), 5 deletions(-)
Index: llvm-java/lib/Compiler/Compiler.cpp
diff -u llvm-java/lib/Compiler/Compiler.cpp:1.221 llvm-java/lib/Compiler/Compiler.cpp:1.222
--- llvm-java/lib/Compiler/Compiler.cpp:1.221 Tue Feb 15 19:27:25 2005
+++ llvm-java/lib/Compiler/Compiler.cpp Thu Feb 17 21:19:06 2005
@@ -1471,17 +1471,26 @@
Field* field = fields[i];
if (field->isStatic()) {
Type* globalTy = getType(field->getDescriptor());
- ConstantValueAttribute* cv = field->getConstantValueAttribute();
- llvm::Constant* init = cv ?
- ConstantExpr::getCast(getConstant(cv->getValue()), globalTy) :
- llvm::Constant::getNullValue(globalTy);
+ // A java field can be final/constant even if it has a
+ // dynamic initializer. Because LLVM does not currently
+ // support these semantics, we consider constants only
+ // final fields with static initializers.
+ bool isConstant = field->isStatic();
+ llvm::Constant* init;
+ if (ConstantValueAttribute* cv = field->getConstantValueAttribute())
+ init =
+ ConstantExpr::getCast(getConstant(cv->getValue()), globalTy);
+ else {
+ init = llvm::Constant::getNullValue(globalTy);
+ isConstant = false;
+ }
std::string globalName =
classfile->getThisClass()->getName()->str() + '/' +
field->getName()->str();
DEBUG(std::cerr << "Adding global: " << globalName << '\n');
new GlobalVariable(globalTy,
- false,
+ isConstant,
GlobalVariable::ExternalLinkage,
init,
globalName,
More information about the llvm-commits
mailing list