diff options
author | Derek Schuff <dschuff@chromium.org> | 2013-05-29 14:24:59 -0700 |
---|---|---|
committer | Derek Schuff <dschuff@chromium.org> | 2013-05-29 14:24:59 -0700 |
commit | 90346495718550e80e0bc671ade46cdd3a7ebc1e (patch) | |
tree | 0068ed436c923f90a84ee54da5f1bcb828cf67e3 | |
parent | dc58e24a36836fc19c534bdcbef5152717a3c3fc (diff) |
Fix PromoteIntegers pass to handle undef constants
ConvertConstant now returns an undef constant of the appropriate type.
This fixes the translator build failure caused by enabling the pass.
R=mseaborn@chromium.org
BUG= https://code.google.com/p/nativeclient/issues/detail?id=3360
Review URL: https://codereview.chromium.org/16086005
-rw-r--r-- | lib/Transforms/NaCl/PromoteIntegers.cpp | 16 | ||||
-rw-r--r-- | test/Transforms/NaCl/promote-integers.ll | 9 |
2 files changed, 20 insertions, 5 deletions
diff --git a/lib/Transforms/NaCl/PromoteIntegers.cpp b/lib/Transforms/NaCl/PromoteIntegers.cpp index 37805f8d30..c72fe5f80d 100644 --- a/lib/Transforms/NaCl/PromoteIntegers.cpp +++ b/lib/Transforms/NaCl/PromoteIntegers.cpp @@ -103,11 +103,17 @@ static bool shouldConvert(Value *Val) { // Return a constant which has been promoted to a legal size. static Value *convertConstant(Constant *C, bool SignExt=false) { assert(shouldConvert(C)); - ConstantInt *CInt = cast<ConstantInt>(C); - return ConstantInt::get( - getPromotedType(cast<IntegerType>(CInt->getType())), - SignExt ? CInt->getSExtValue() : CInt->getZExtValue(), - /*isSigned=*/SignExt); + if (isa<UndefValue>(C)) { + return UndefValue::get(getPromotedType(C->getType())); + } else if (ConstantInt *CInt = dyn_cast<ConstantInt>(C)) { + return ConstantInt::get( + getPromotedType(C->getType()), + SignExt ? CInt->getSExtValue() : CInt->getZExtValue(), + /*isSigned=*/SignExt); + } else { + errs() << "Value: " << *C << "\n"; + report_fatal_error("Unexpected constant value"); + } } // Holds the state for converting/replacing values. Conversion is done in one diff --git a/test/Transforms/NaCl/promote-integers.ll b/test/Transforms/NaCl/promote-integers.ll index 5e73dc8353..19d5321c47 100644 --- a/test/Transforms/NaCl/promote-integers.ll +++ b/test/Transforms/NaCl/promote-integers.ll @@ -344,3 +344,12 @@ define void @store56(i8* %a, i8 %b) { store i56 %b56, i56* %bc ret void } + +; CHECK: @undefoperand +; CHECK-NEXT: %a40 = zext i32 %a to i64 +; CHECK-NEXT: %au = and i64 %a40, undef +define void @undefoperand(i32 %a) { + %a40 = zext i32 %a to i40 + %au = and i40 %a40, undef + ret void +}
\ No newline at end of file |