diff options
author | serge-sans-paille <sguelton@redhat.com> | 2022-04-13 10:31:44 +0200 |
---|---|---|
committer | serge-sans-paille <sguelton@redhat.com> | 2022-04-13 19:17:28 +0200 |
commit | 262eba01b33fd5cda5e4b65a744bac9d87cd7453 (patch) | |
tree | f64cf7df816466dfaacf37613cb0bfd5091c9561 /llvm/lib/Analysis/ValueTracking.cpp | |
parent | 4585bff408bca58a883b9593f578652cff0f43c9 (diff) | |
download | llvm-262eba01b33fd5cda5e4b65a744bac9d87cd7453.zip llvm-262eba01b33fd5cda5e4b65a744bac9d87cd7453.tar.gz llvm-262eba01b33fd5cda5e4b65a744bac9d87cd7453.tar.bz2 |
Revert "[ValueTracking] Make getStringLenth aware of strdup"
This reverts commit e810d558093cff40caaa1aff24d289c76c59916d.
The commit was not taken into account the fact that strduped string could be
modified. Checking if such modification happens would make the function very
costly, without a test case in mind it's not worth the effort.
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r-- | llvm/lib/Analysis/ValueTracking.cpp | 30 |
1 files changed, 6 insertions, 24 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index c4ceb91..75381f5 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -4199,8 +4199,7 @@ bool llvm::getConstantStringInfo(const Value *V, StringRef &Str, /// If we can compute the length of the string pointed to by /// the specified pointer, return 'len+1'. If we can't, return 0. static uint64_t GetStringLengthH(const Value *V, - SmallPtrSetImpl<const PHINode *> &PHIs, - const TargetLibraryInfo *TLI, + SmallPtrSetImpl<const PHINode*> &PHIs, unsigned CharSize) { // Look through noop bitcast instructions. V = V->stripPointerCasts(); @@ -4214,7 +4213,7 @@ static uint64_t GetStringLengthH(const Value *V, // If it was new, see if all the input strings are the same length. uint64_t LenSoFar = ~0ULL; for (Value *IncValue : PN->incoming_values()) { - uint64_t Len = GetStringLengthH(IncValue, PHIs, TLI, CharSize); + uint64_t Len = GetStringLengthH(IncValue, PHIs, CharSize); if (Len == 0) return 0; // Unknown length -> unknown. if (Len == ~0ULL) continue; @@ -4230,9 +4229,9 @@ static uint64_t GetStringLengthH(const Value *V, // strlen(select(c,x,y)) -> strlen(x) ^ strlen(y) if (const SelectInst *SI = dyn_cast<SelectInst>(V)) { - uint64_t Len1 = GetStringLengthH(SI->getTrueValue(), PHIs, TLI, CharSize); + uint64_t Len1 = GetStringLengthH(SI->getTrueValue(), PHIs, CharSize); if (Len1 == 0) return 0; - uint64_t Len2 = GetStringLengthH(SI->getFalseValue(), PHIs, TLI, CharSize); + uint64_t Len2 = GetStringLengthH(SI->getFalseValue(), PHIs, CharSize); if (Len2 == 0) return 0; if (Len1 == ~0ULL) return Len2; if (Len2 == ~0ULL) return Len1; @@ -4240,22 +4239,6 @@ static uint64_t GetStringLengthH(const Value *V, return Len1; } - if (auto *CB = dyn_cast<CallBase>(V)) { - Function *Callee = CB->getCalledFunction(); - if (!Callee) - return 0; - - LibFunc TLIFn; - if (!TLI || !TLI->getLibFunc(*CB->getCalledFunction(), TLIFn) || - !TLI->has(TLIFn)) - return 0; - - if (TLIFn == LibFunc_strdup || TLIFn == LibFunc_dunder_strdup) - return GetStringLengthH(CB->getArgOperand(0), PHIs, TLI, CharSize); - - return 0; - } - // Otherwise, see if we can read the string. ConstantDataArraySlice Slice; if (!getConstantDataArrayInfo(V, Slice, CharSize)) @@ -4276,13 +4259,12 @@ static uint64_t GetStringLengthH(const Value *V, /// If we can compute the length of the string pointed to by /// the specified pointer, return 'len+1'. If we can't, return 0. -uint64_t llvm::GetStringLength(const Value *V, const TargetLibraryInfo *TLI, - unsigned CharSize) { +uint64_t llvm::GetStringLength(const Value *V, unsigned CharSize) { if (!V->getType()->isPointerTy()) return 0; SmallPtrSet<const PHINode*, 32> PHIs; - uint64_t Len = GetStringLengthH(V, PHIs, TLI, CharSize); + uint64_t Len = GetStringLengthH(V, PHIs, CharSize); // If Len is ~0ULL, we had an infinite phi cycle: this is dead code, so return // an empty string as a length. return Len == ~0ULL ? 1 : Len; |