Skip to content

Commit

Permalink
Relax RegionStore to allow loads from CodeTextRegions. Apparently you…
Browse files Browse the repository at this point in the history
… can actually write code that does this. This seems worthy of a checker, but the StoreManager should handle the memory abstraction without crashing. Fixes PR 11450.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@145424 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
tkremenek committed Nov 29, 2011
1 parent cfbc5b5 commit 214323b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
8 changes: 3 additions & 5 deletions lib/StaticAnalyzer/Core/RegionStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -882,18 +882,16 @@ SVal RegionStoreManager::Retrieve(Store store, Loc L, QualType T) {

const MemRegion *MR = cast<loc::MemRegionVal>(L).getRegion();

if (isa<AllocaRegion>(MR) || isa<SymbolicRegion>(MR)) {
if (isa<AllocaRegion>(MR) ||
isa<SymbolicRegion>(MR) ||
isa<CodeTextRegion>(MR)) {
if (T.isNull()) {
const SymbolicRegion *SR = cast<SymbolicRegion>(MR);
T = SR->getSymbol()->getType(Ctx);
}
MR = GetElementZeroRegion(MR, T);
}

if (isa<CodeTextRegion>(MR)) {
llvm_unreachable("Why load from a code text region?");
}

// FIXME: Perhaps this method should just take a 'const MemRegion*' argument
// instead of 'Loc', and have the other Loc cases handled at a higher level.
const TypedValueRegion *R = cast<TypedValueRegion>(MR);
Expand Down
8 changes: 8 additions & 0 deletions test/Analysis/misc-ps-region-store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,3 +484,11 @@ void PR11249()
*p = 0xDEADBEEF; // no-warning
}

// Handle doing a load from the memory associated with the code for
// a function.
extern double nan( const char * );
double PR11450() {
double NaN = *(double*) nan;
return NaN;
}

0 comments on commit 214323b

Please sign in to comment.