[llvm] 8c26e47 - [LLParser] Merge xor constantexpr parsing with add/mul/shl/lshr/ashr. (#67371)

via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 26 14:48:35 PDT 2023


Author: Craig Topper
Date: 2023-09-26T14:48:30-07:00
New Revision: 8c26e473e703ff0af32b0015b6a64713e6de3c31

URL: https://github.com/llvm/llvm-project/commit/8c26e473e703ff0af32b0015b6a64713e6de3c31
DIFF: https://github.com/llvm/llvm-project/commit/8c26e473e703ff0af32b0015b6a64713e6de3c31.diff

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

Not sure if xor is sticking around or not. I see and/or was already
removed.

This changes the error messages and makes one error message more
accurate.

Added: 
    

Modified: 
    llvm/lib/AsmParser/LLParser.cpp
    llvm/test/Assembler/2003-05-21-MalformedShiftCrash.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index a451aa508a55577..04eabc94cfc6abe 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -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;
@@ -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;
   }

diff  --git a/llvm/test/Assembler/2003-05-21-MalformedShiftCrash.ll b/llvm/test/Assembler/2003-05-21-MalformedShiftCrash.ll
index 5b456008751285a..0ec3c8b1045cbcc 100644
--- a/llvm/test/Assembler/2003-05-21-MalformedShiftCrash.ll
+++ b/llvm/test/Assembler/2003-05-21-MalformedShiftCrash.ll
@@ -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)


        


More information about the llvm-commits mailing list