From c6d2f15037643a3738d6bce1c09a9d3bdb3bdcaf Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 17 Aug 2004 17:26:41 +0000 Subject: [PATCH] Work around PR424 for old c/c++ frontends. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15882 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AsmParser/llvmAsmParser.y | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/lib/AsmParser/llvmAsmParser.y b/lib/AsmParser/llvmAsmParser.y index efa34f6d74b..e48d6cfc9fc 100644 --- a/lib/AsmParser/llvmAsmParser.y +++ b/lib/AsmParser/llvmAsmParser.y @@ -916,7 +916,6 @@ Module *llvm::RunVMAsmParser(const std::string &Filename, FILE *F) { %token RET BR SWITCH INVOKE UNWIND // Binary Operators -%type BinaryOps // all the binary operators %type ArithmeticOps LogicalOps SetCondOps // Binops Subcatagories %token ADD SUB MUL DIV REM AND OR XOR %token SETLE SETGE SETLT SETGT SETEQ SETNE // Binary Comarators @@ -955,7 +954,6 @@ EINT64VAL : EUINT64VAL { ArithmeticOps: ADD | SUB | MUL | DIV | REM; LogicalOps : AND | OR | XOR; SetCondOps : SETLE | SETGE | SETLT | SETGT | SETEQ | SETNE; -BinaryOps : ArithmeticOps | LogicalOps | SetCondOps; ShiftOps : SHL | SHR; @@ -1326,9 +1324,37 @@ ConstExpr: CAST '(' ConstVal TO Types ')' { ThrowException("Select operand types must match!"); $$ = ConstantExpr::getSelect($3, $5, $7); } - | BinaryOps '(' ConstVal ',' ConstVal ')' { + | ArithmeticOps '(' ConstVal ',' ConstVal ')' { if ($3->getType() != $5->getType()) ThrowException("Binary operator types must match!"); + // HACK: llvm 1.3 and earlier used to emit invalid pointer constant exprs. + // To retain backward compatibility with these early compilers, we emit a + // cast to the appropriate integer type automatically if we are in the + // broken case. See PR424 for more information. + if (!isa($3->getType())) { + $$ = ConstantExpr::get($1, $3, $5); + } else { + const Type *IntPtrTy; + switch (CurModule.CurrentModule->getPointerSize()) { + case Module::Pointer32: IntPtrTy = Type::IntTy; break; + case Module::Pointer64: IntPtrTy = Type::LongTy; break; + default: ThrowException("invalid pointer binary constant expr!"); + } + $$ = ConstantExpr::get($1, ConstantExpr::getCast($3, IntPtrTy), + ConstantExpr::getCast($5, IntPtrTy)); + $$ = ConstantExpr::getCast($$, $3->getType()); + } + } + | LogicalOps '(' ConstVal ',' ConstVal ')' { + if ($3->getType() != $5->getType()) + ThrowException("Logical operator types must match!"); + if (!$3->getType()->isIntegral()) + ThrowException("Logical operands must have integral types!"); + $$ = ConstantExpr::get($1, $3, $5); + } + | SetCondOps '(' ConstVal ',' ConstVal ')' { + if ($3->getType() != $5->getType()) + ThrowException("setcc operand types must match!"); $$ = ConstantExpr::get($1, $3, $5); } | ShiftOps '(' ConstVal ',' ConstVal ')' {