[llvm] r228901 - Fixed a bug where CFLAA would crash the compiler.
George Burgess IV
george.burgess.iv at gmail.com
Wed Feb 11 19:07:07 PST 2015
Author: gbiv
Date: Wed Feb 11 21:07:07 2015
New Revision: 228901
URL: http://llvm.org/viewvc/llvm-project?rev=228901&view=rev
Log:
Fixed a bug where CFLAA would crash the compiler.
We would crash if we couldn't locate a Function that either Location's
Value belonged to. Now we just print out a debug message and return
conservatively.
Added:
llvm/trunk/test/Analysis/CFLAliasAnalysis/asm-global-bugfix.ll
Modified:
llvm/trunk/lib/Analysis/CFLAliasAnalysis.cpp
Modified: llvm/trunk/lib/Analysis/CFLAliasAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/CFLAliasAnalysis.cpp?rev=228901&r1=228900&r2=228901&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/CFLAliasAnalysis.cpp (original)
+++ llvm/trunk/lib/Analysis/CFLAliasAnalysis.cpp Wed Feb 11 21:07:07 2015
@@ -43,6 +43,7 @@
#include "llvm/Pass.h"
#include "llvm/Support/Allocator.h"
#include "llvm/Support/Compiler.h"
+#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include <algorithm>
#include <cassert>
@@ -51,6 +52,8 @@
using namespace llvm;
+#define DEBUG_TYPE "cfl-aa"
+
// Try to go from a Value* to a Function*. Never returns nullptr.
static Optional<Function *> parentFunctionOfValue(Value *);
@@ -229,6 +232,7 @@ public:
if (isa<Constant>(LocA.Ptr) && isa<Constant>(LocB.Ptr)) {
return AliasAnalysis::alias(LocA, LocB);
}
+
AliasResult QueryResult = query(LocA, LocB);
if (QueryResult == MayAlias)
return AliasAnalysis::alias(LocA, LocB);
@@ -973,8 +977,10 @@ CFLAliasAnalysis::query(const AliasAnaly
auto MaybeFnA = parentFunctionOfValue(ValA);
auto MaybeFnB = parentFunctionOfValue(ValB);
if (!MaybeFnA.hasValue() && !MaybeFnB.hasValue()) {
- llvm_unreachable("Don't know how to extract the parent function "
- "from values A or B");
+ // The only times this is known to happen are when globals + InlineAsm
+ // are involved
+ DEBUG(dbgs() << "CFLAA: could not extract parent function information.\n");
+ return AliasAnalysis::MayAlias;
}
if (MaybeFnA.hasValue()) {
@@ -1002,14 +1008,15 @@ CFLAliasAnalysis::query(const AliasAnaly
auto SetB = *MaybeB;
auto AttrsA = Sets.getLink(SetA.Index).Attrs;
auto AttrsB = Sets.getLink(SetB.Index).Attrs;
+
// Stratified set attributes are used as markets to signify whether a member
- // of a StratifiedSet (or a member of a set above the current set) has
+ // of a StratifiedSet (or a member of a set above the current set) has
// interacted with either arguments or globals. "Interacted with" meaning
- // its value may be different depending on the value of an argument or
+ // its value may be different depending on the value of an argument or
// global. The thought behind this is that, because arguments and globals
// may alias each other, if AttrsA and AttrsB have touched args/globals,
- // we must conservatively say that they alias. However, if at least one of
- // the sets has no values that could legally be altered by changing the value
+ // we must conservatively say that they alias. However, if at least one of
+ // the sets has no values that could legally be altered by changing the value
// of an argument or global, then we don't have to be as conservative.
if (AttrsA.any() && AttrsB.any())
return AliasAnalysis::MayAlias;
Added: llvm/trunk/test/Analysis/CFLAliasAnalysis/asm-global-bugfix.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/CFLAliasAnalysis/asm-global-bugfix.ll?rev=228901&view=auto
==============================================================================
--- llvm/trunk/test/Analysis/CFLAliasAnalysis/asm-global-bugfix.ll (added)
+++ llvm/trunk/test/Analysis/CFLAliasAnalysis/asm-global-bugfix.ll Wed Feb 11 21:07:07 2015
@@ -0,0 +1,16 @@
+; Test case for a bug where we would crash when we were requested to report
+; whether two values that didn't belong to a function (i.e. two globals, etc)
+; aliased.
+
+; RUN: opt < %s -cfl-aa -aa-eval -print-may-aliases -disable-output 2>&1 | FileCheck %s
+
+ at G = private unnamed_addr constant [1 x i8] c"\00", align 1
+
+; CHECK: Function: test_no_crash
+; CHECK: 1 no alias responses
+define void @test_no_crash() #0 {
+entry:
+ call i8* asm "nop", "=r,r"(
+ i8* getelementptr inbounds ([1 x i8]* @G, i64 0, i64 0))
+ ret void
+}
More information about the llvm-commits
mailing list