Add a new keyword 'inbounds' for use with getelementptr. See the
LangRef.html changes for details.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77259 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AsmParser/LLLexer.cpp b/lib/AsmParser/LLLexer.cpp
index e047002..c9b2821 100644
--- a/lib/AsmParser/LLLexer.cpp
+++ b/lib/AsmParser/LLLexer.cpp
@@ -504,6 +504,7 @@
KEYWORD(nuw);
KEYWORD(nsw);
KEYWORD(exact);
+ KEYWORD(inbounds);
KEYWORD(align);
KEYWORD(addrspace);
KEYWORD(section);
diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp
index f9db409..adcd79f 100644
--- a/lib/AsmParser/LLParser.cpp
+++ b/lib/AsmParser/LLParser.cpp
@@ -457,7 +457,7 @@
/// Aliasee
/// ::= TypeAndValue
/// ::= 'bitcast' '(' TypeAndValue 'to' Type ')'
-/// ::= 'getelementptr' '(' ... ')'
+/// ::= 'getelementptr' 'inbounds'? '(' ... ')'
///
/// Everything through visibility has already been parsed.
///
@@ -2039,7 +2039,11 @@
case lltok::kw_select: {
unsigned Opc = Lex.getUIntVal();
SmallVector<Constant*, 16> Elts;
+ bool InBounds = false;
Lex.Lex();
+ if (Opc == Instruction::GetElementPtr)
+ if (EatIfPresent(lltok::kw_inbounds))
+ InBounds = true;
if (ParseToken(lltok::lparen, "expected '(' in constantexpr") ||
ParseGlobalValueVector(Elts) ||
ParseToken(lltok::rparen, "expected ')' in constantexpr"))
@@ -2055,6 +2059,8 @@
return Error(ID.Loc, "invalid indices for getelementptr");
ID.ConstantVal = Context.getConstantExprGetElementPtr(Elts[0],
Elts.data() + 1, Elts.size() - 1);
+ if (InBounds)
+ cast<GEPOperator>(ID.ConstantVal)->setIsInBounds(true);
} else if (Opc == Instruction::Select) {
if (Elts.size() != 3)
return Error(ID.Loc, "expected three operands to select");
@@ -3368,9 +3374,14 @@
}
/// ParseGetElementPtr
-/// ::= 'getelementptr' TypeAndValue (',' TypeAndValue)*
+/// ::= 'getelementptr' 'inbounds'? TypeAndValue (',' TypeAndValue)*
bool LLParser::ParseGetElementPtr(Instruction *&Inst, PerFunctionState &PFS) {
Value *Ptr, *Val; LocTy Loc, EltLoc;
+ bool InBounds = false;
+
+ if (EatIfPresent(lltok::kw_inbounds))
+ InBounds = true;
+
if (ParseTypeAndValue(Ptr, Loc, PFS)) return true;
if (!isa<PointerType>(Ptr->getType()))
@@ -3388,6 +3399,8 @@
Indices.begin(), Indices.end()))
return Error(Loc, "invalid getelementptr indices");
Inst = GetElementPtrInst::Create(Ptr, Indices.begin(), Indices.end());
+ if (InBounds)
+ cast<GEPOperator>(Inst)->setIsInBounds(true);
return false;
}
diff --git a/lib/AsmParser/LLToken.h b/lib/AsmParser/LLToken.h
index c8cdff6..75cc1db 100644
--- a/lib/AsmParser/LLToken.h
+++ b/lib/AsmParser/LLToken.h
@@ -54,6 +54,7 @@
kw_nuw,
kw_nsw,
kw_exact,
+ kw_inbounds,
kw_align,
kw_addrspace,
kw_section,