[llvm-commits] [llvm] r52851 - in /llvm/trunk: include/llvm/Analysis/ValueTracking.h lib/Analysis/ValueTracking.cpp lib/CodeGen/SelectionDAG/SelectionDAG.cpp
Chris Lattner
sabre at nondot.org
Fri Jun 27 22:33:32 PDT 2008
Author: lattner
Date: Sat Jun 28 00:33:32 2008
New Revision: 52851
URL: http://llvm.org/viewvc/llvm-project?rev=52851&view=rev
Log:
Add back the capability to include nul characters in strings with
GetConstantStringInfo. This will hopefully restore llvm-gcc to
happy bootstrap land.
Modified:
llvm/trunk/include/llvm/Analysis/ValueTracking.h
llvm/trunk/lib/Analysis/ValueTracking.cpp
llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
Modified: llvm/trunk/include/llvm/Analysis/ValueTracking.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ValueTracking.h?rev=52851&r1=52850&r2=52851&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/ValueTracking.h (original)
+++ llvm/trunk/include/llvm/Analysis/ValueTracking.h Sat Jun 28 00:33:32 2008
@@ -76,8 +76,12 @@
/// GetConstantStringInfo - This function computes the length of a
/// null-terminated C string pointed to by V. If successful, it returns true
- /// and returns the string in Str. If unsuccessful, it returns false.
- bool GetConstantStringInfo(Value *V, std::string &Str, uint64_t Offset = 0);
+ /// and returns the string in Str. If unsuccessful, it returns false. If
+ /// StopAtNul is set to true (the default), the returned string is truncated
+ /// by a nul character in the global. If StopAtNul is false, the nul
+ /// character is included in the result string.
+ bool GetConstantStringInfo(Value *V, std::string &Str, uint64_t Offset = 0,
+ bool StopAtNul = true);
} // end namespace llvm
#endif
Modified: llvm/trunk/lib/Analysis/ValueTracking.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ValueTracking.cpp?rev=52851&r1=52850&r2=52851&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ValueTracking.cpp (original)
+++ llvm/trunk/lib/Analysis/ValueTracking.cpp Sat Jun 28 00:33:32 2008
@@ -935,13 +935,14 @@
/// GetConstantStringInfo - This function computes the length of a
/// null-terminated C string pointed to by V. If successful, it returns true
/// and returns the string in Str. If unsuccessful, it returns false.
-bool llvm::GetConstantStringInfo(Value *V, std::string &Str, uint64_t Offset) {
+bool llvm::GetConstantStringInfo(Value *V, std::string &Str, uint64_t Offset,
+ bool StopAtNul) {
// If V is NULL then return false;
if (V == NULL) return false;
// Look through bitcast instructions.
if (BitCastInst *BCI = dyn_cast<BitCastInst>(V))
- return GetConstantStringInfo(BCI->getOperand(0), Str, Offset);
+ return GetConstantStringInfo(BCI->getOperand(0), Str, Offset, StopAtNul);
// If the value is not a GEP instruction nor a constant expression with a
// GEP instruction, then return false because ConstantArray can't occur
@@ -951,7 +952,7 @@
GEP = GEPI;
} else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) {
if (CE->getOpcode() == Instruction::BitCast)
- return GetConstantStringInfo(CE->getOperand(0), Str, Offset);
+ return GetConstantStringInfo(CE->getOperand(0), Str, Offset, StopAtNul);
if (CE->getOpcode() != Instruction::GetElementPtr)
return false;
GEP = CE;
@@ -982,7 +983,8 @@
StartIdx = CI->getZExtValue();
else
return false;
- return GetConstantStringInfo(GEP->getOperand(0), Str, StartIdx+Offset);
+ return GetConstantStringInfo(GEP->getOperand(0), Str, StartIdx+Offset,
+ StopAtNul);
}
// The GEP instruction, constant or instruction, must reference a global
@@ -1020,7 +1022,7 @@
ConstantInt *CI = dyn_cast<ConstantInt>(Elt);
if (!CI) // This array isn't suitable, non-int initializer.
return false;
- if (CI->isZero())
+ if (StopAtNul && CI->isZero())
return true; // we found end of string, success!
Str += (char)CI->getZExtValue();
}
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp?rev=52851&r1=52850&r2=52851&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp Sat Jun 28 00:33:32 2008
@@ -2594,7 +2594,7 @@
return false;
GlobalVariable *GV = dyn_cast<GlobalVariable>(G->getGlobal());
- if (GV && GetConstantStringInfo(GV, Str)) {
+ if (GV && GetConstantStringInfo(GV, Str, SrcDelta, false)) {
SrcOff += SrcDelta;
return true;
}
More information about the llvm-commits
mailing list