From 00f4747bad78c33ba0f78d480db866804f592235 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Mon, 25 Jan 2010 21:55:39 +0000 Subject: [PATCH] Fix the bitcode reader to deserialize nuw/nsw/etc. bits properly in the case of a forward-reference, which doesn't use an "abbrev" encoding. llvm-svn: 94454 --- llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 6 ++--- llvm/test/Bitcode/flags.ll | 27 +++++++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 llvm/test/Bitcode/flags.ll diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 2549a5162c63..6dae45f38401 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -1702,12 +1702,12 @@ bool BitcodeReader::ParseFunctionBody(Function *F) { if (Opc == Instruction::Add || Opc == Instruction::Sub || Opc == Instruction::Mul) { - if (Record[3] & (1 << bitc::OBO_NO_SIGNED_WRAP)) + if (Record[OpNum] & (1 << bitc::OBO_NO_SIGNED_WRAP)) cast(I)->setHasNoSignedWrap(true); - if (Record[3] & (1 << bitc::OBO_NO_UNSIGNED_WRAP)) + if (Record[OpNum] & (1 << bitc::OBO_NO_UNSIGNED_WRAP)) cast(I)->setHasNoUnsignedWrap(true); } else if (Opc == Instruction::SDiv) { - if (Record[3] & (1 << bitc::SDIV_EXACT)) + if (Record[OpNum] & (1 << bitc::SDIV_EXACT)) cast(I)->setIsExact(true); } } diff --git a/llvm/test/Bitcode/flags.ll b/llvm/test/Bitcode/flags.ll new file mode 100644 index 000000000000..7b0c5b538894 --- /dev/null +++ b/llvm/test/Bitcode/flags.ll @@ -0,0 +1,27 @@ +; RUN: llvm-as < %s | llvm-dis > %t0 +; RUN: opt -S < %s > %t1 +; RUN: diff %t0 %t1 +; PR6140 + +; Make sure the flags are serialized/deserialized properly for both +; forward and backward references. + +define void @foo() nounwind { +entry: + br label %first + +second: ; preds = %first + %u = add nuw i32 %a, 0 ; [#uses=0] + %s = add nsw i32 %a, 0 ; [#uses=0] + %us = add nuw nsw i32 %a, 0 ; [#uses=0] + %z = add i32 %a, 0 ; [#uses=0] + unreachable + +first: ; preds = %entry + %a = bitcast i32 0 to i32 ; [#uses=8] + %uu = add nuw i32 %a, 0 ; [#uses=0] + %ss = add nsw i32 %a, 0 ; [#uses=0] + %uuss = add nuw nsw i32 %a, 0 ; [#uses=0] + %zz = add i32 %a, 0 ; [#uses=0] + br label %second +}