Skip to content

[LLParser] Merge xor constantexpr parsing with add/mul/shl/lshr/ashr. #67371

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 5 additions & 25 deletions llvm/lib/AsmParser/LLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3903,7 +3903,8 @@ bool LLParser::parseValID(ValID &ID, PerFunctionState *PFS, Type *ExpectedTy) {
case lltok::kw_mul:
case lltok::kw_shl:
case lltok::kw_lshr:
case lltok::kw_ashr: {
case lltok::kw_ashr:
case lltok::kw_xor: {
bool NUW = false;
bool NSW = false;
bool Exact = false;
Expand Down Expand Up @@ -3934,34 +3935,13 @@ bool LLParser::parseValID(ValID &ID, PerFunctionState *PFS, Type *ExpectedTy) {
return error(ID.Loc, "operands of constexpr must have same type");
// Check that the type is valid for the operator.
if (!Val0->getType()->isIntOrIntVectorTy())
return error(ID.Loc, "constexpr requires integer operands");
return error(ID.Loc,
"constexpr requires integer or integer vector operands");
unsigned Flags = 0;
if (NUW) Flags |= OverflowingBinaryOperator::NoUnsignedWrap;
if (NSW) Flags |= OverflowingBinaryOperator::NoSignedWrap;
if (Exact) Flags |= PossiblyExactOperator::IsExact;
Constant *C = ConstantExpr::get(Opc, Val0, Val1, Flags);
ID.ConstantVal = C;
ID.Kind = ValID::t_Constant;
return false;
}

// Logical Operations
case lltok::kw_xor: {
unsigned Opc = Lex.getUIntVal();
Constant *Val0, *Val1;
Lex.Lex();
if (parseToken(lltok::lparen, "expected '(' in logical constantexpr") ||
parseGlobalTypeAndValue(Val0) ||
parseToken(lltok::comma, "expected comma in logical constantexpr") ||
parseGlobalTypeAndValue(Val1) ||
parseToken(lltok::rparen, "expected ')' in logical constantexpr"))
return true;
if (Val0->getType() != Val1->getType())
return error(ID.Loc, "operands of constexpr must have same type");
if (!Val0->getType()->isIntOrIntVectorTy())
return error(ID.Loc,
"constexpr requires integer or integer vector operands");
ID.ConstantVal = ConstantExpr::get(Opc, Val0, Val1);
ID.ConstantVal = ConstantExpr::get(Opc, Val0, Val1, Flags);
ID.Kind = ValID::t_Constant;
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/Assembler/2003-05-21-MalformedShiftCrash.ll
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; Found by inspection of the code
; RUN: not llvm-as < %s > /dev/null 2> %t
; RUN: grep "constexpr requires integer operands" %t
; RUN: grep "constexpr requires integer or integer vector operands" %t

@0 = global i32 ashr (float 1.0, float 2.0)