[cfe-commits] r145424 - in /cfe/trunk: lib/StaticAnalyzer/Core/RegionStore.cpp test/Analysis/misc-ps-region-store.cpp

Ted Kremenek kremenek at apple.com
Tue Nov 29 11:39:29 PST 2011


Author: kremenek
Date: Tue Nov 29 13:39:29 2011
New Revision: 145424

URL: http://llvm.org/viewvc/llvm-project?rev=145424&view=rev
Log:
Relax RegionStore to allow loads from CodeTextRegions.  Apparently you 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.

Modified:
    cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
    cfe/trunk/test/Analysis/misc-ps-region-store.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp?rev=145424&r1=145423&r2=145424&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp Tue Nov 29 13:39:29 2011
@@ -882,7 +882,9 @@
 
   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);
@@ -890,10 +892,6 @@
     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);

Modified: cfe/trunk/test/Analysis/misc-ps-region-store.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/misc-ps-region-store.cpp?rev=145424&r1=145423&r2=145424&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/misc-ps-region-store.cpp (original)
+++ cfe/trunk/test/Analysis/misc-ps-region-store.cpp Tue Nov 29 13:39:29 2011
@@ -484,3 +484,11 @@
     *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;
+}
+





More information about the cfe-commits mailing list