Fix the bitcode reader to deserialize nuw/nsw/etc. bits properly in the case
authorDan Gohman <gohman@apple.com>
Mon, 25 Jan 2010 21:55:39 +0000 (21:55 +0000)
committerDan Gohman <gohman@apple.com>
Mon, 25 Jan 2010 21:55:39 +0000 (21:55 +0000)
of a forward-reference, which doesn't use an "abbrev" encoding.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@94454 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Bitcode/Reader/BitcodeReader.cpp
test/Bitcode/flags.ll [new file with mode: 0644]

index 2549a5162c6354a58165605bfd9c390be9488a10..6dae45f38401afe428f7a3db0dc879449d576c57 100644 (file)
@@ -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<BinaryOperator>(I)->setHasNoSignedWrap(true);
-          if (Record[3] & (1 << bitc::OBO_NO_UNSIGNED_WRAP))
+          if (Record[OpNum] & (1 << bitc::OBO_NO_UNSIGNED_WRAP))
             cast<BinaryOperator>(I)->setHasNoUnsignedWrap(true);
         } else if (Opc == Instruction::SDiv) {
-          if (Record[3] & (1 << bitc::SDIV_EXACT))
+          if (Record[OpNum] & (1 << bitc::SDIV_EXACT))
             cast<BinaryOperator>(I)->setIsExact(true);
         }
       }
diff --git a/test/Bitcode/flags.ll b/test/Bitcode/flags.ll
new file mode 100644 (file)
index 0000000..7b0c5b5
--- /dev/null
@@ -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                          ; <i32> [#uses=0]
+  %s = add nsw i32 %a, 0                          ; <i32> [#uses=0]
+  %us = add nuw nsw i32 %a, 0                     ; <i32> [#uses=0]
+  %z = add i32 %a, 0                              ; <i32> [#uses=0]
+  unreachable
+
+first:                                            ; preds = %entry
+  %a = bitcast i32 0 to i32                       ; <i32> [#uses=8]
+  %uu = add nuw i32 %a, 0                         ; <i32> [#uses=0]
+  %ss = add nsw i32 %a, 0                         ; <i32> [#uses=0]
+  %uuss = add nuw nsw i32 %a, 0                   ; <i32> [#uses=0]
+  %zz = add i32 %a, 0                             ; <i32> [#uses=0]
+  br label %second
+}