[llvm] r236023 - Make getModRefInfo(Instruction *) not crash on certain types of instructions

Daniel Berlin dberlin at dberlin.org
Tue Apr 28 12:19:15 PDT 2015


Author: dannyb
Date: Tue Apr 28 14:19:14 2015
New Revision: 236023

URL: http://llvm.org/viewvc/llvm-project?rev=236023&view=rev
Log:
Make getModRefInfo(Instruction *) not crash on certain types of instructions

Modified:
    llvm/trunk/lib/Analysis/AliasAnalysis.cpp
    llvm/trunk/unittests/Analysis/AliasAnalysisTest.cpp

Modified: llvm/trunk/lib/Analysis/AliasAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/AliasAnalysis.cpp?rev=236023&r1=236022&r2=236023&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/AliasAnalysis.cpp (original)
+++ llvm/trunk/lib/Analysis/AliasAnalysis.cpp Tue Apr 28 14:19:14 2015
@@ -379,15 +379,18 @@ AliasAnalysis::getModRefInfo(const Store
 
 AliasAnalysis::ModRefResult
 AliasAnalysis::getModRefInfo(const VAArgInst *V, const Location &Loc) {
-  // If the va_arg address cannot alias the pointer in question, then the
-  // specified memory cannot be accessed by the va_arg.
-  if (!alias(getLocation(V), Loc))
-    return NoModRef;
 
-  // If the pointer is a pointer to constant memory, then it could not have been
-  // modified by this va_arg.
-  if (pointsToConstantMemory(Loc))
-    return NoModRef;
+  if (Loc.Ptr) {
+    // If the va_arg address cannot alias the pointer in question, then the
+    // specified memory cannot be accessed by the va_arg.
+    if (!alias(getLocation(V), Loc))
+      return NoModRef;
+
+    // If the pointer is a pointer to constant memory, then it could not have
+    // been modified by this va_arg.
+    if (pointsToConstantMemory(Loc))
+      return NoModRef;
+  }
 
   // Otherwise, a va_arg reads and writes.
   return ModRef;
@@ -400,7 +403,7 @@ AliasAnalysis::getModRefInfo(const Atomi
     return ModRef;
 
   // If the cmpxchg address does not alias the location, it does not access it.
-  if (!alias(getLocation(CX), Loc))
+  if (Loc.Ptr && !alias(getLocation(CX), Loc))
     return NoModRef;
 
   return ModRef;
@@ -413,7 +416,7 @@ AliasAnalysis::getModRefInfo(const Atomi
     return ModRef;
 
   // If the atomicrmw address does not alias the location, it does not access it.
-  if (!alias(getLocation(RMW), Loc))
+  if (Loc.Ptr && !alias(getLocation(RMW), Loc))
     return NoModRef;
 
   return ModRef;

Modified: llvm/trunk/unittests/Analysis/AliasAnalysisTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Analysis/AliasAnalysisTest.cpp?rev=236023&r1=236022&r2=236023&view=diff
==============================================================================
--- llvm/trunk/unittests/Analysis/AliasAnalysisTest.cpp (original)
+++ llvm/trunk/unittests/Analysis/AliasAnalysisTest.cpp Tue Apr 28 14:19:14 2015
@@ -81,6 +81,13 @@ TEST_F(AliasAnalysisTest, getModRefInfo)
   auto *Store1 = new StoreInst(Value, Addr, BB);
   auto *Load1 = new LoadInst(Addr, "load", BB);
   auto *Add1 = BinaryOperator::CreateAdd(Value, Value, "add", BB);
+  auto *VAArg1 = new VAArgInst(Addr, PtrType, "vaarg", BB);
+  auto *CmpXChg1 = new AtomicCmpXchgInst(Addr, ConstantInt::get(IntType, 0),
+                                         ConstantInt::get(IntType, 1),
+                                         Monotonic, Monotonic, CrossThread, BB);
+  auto *AtomicRMW =
+      new AtomicRMWInst(AtomicRMWInst::Xchg, Addr, ConstantInt::get(IntType, 1),
+                        Monotonic, CrossThread, BB);
 
   ReturnInst::Create(C, nullptr, BB);
 
@@ -88,6 +95,9 @@ TEST_F(AliasAnalysisTest, getModRefInfo)
   CheckModRef(Store1, AliasAnalysis::ModRefResult::Mod);
   CheckModRef(Load1, AliasAnalysis::ModRefResult::Ref);
   CheckModRef(Add1, AliasAnalysis::ModRefResult::NoModRef);
+  CheckModRef(VAArg1, AliasAnalysis::ModRefResult::ModRef);
+  CheckModRef(CmpXChg1, AliasAnalysis::ModRefResult::ModRef);
+  CheckModRef(AtomicRMW, AliasAnalysis::ModRefResult::ModRef);
 }
 
 } // end anonymous namspace





More information about the llvm-commits mailing list