llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Mariya Podchishchaeva (Fznamznon) <details> <summary>Changes</summary> For long enough _BitInt types we use different types for memory, storing-loading and operations. Makes sure it is correct for mixed sign __builtin_mul_overflow cases. Using pointer element type as a result type doesn't work, because it will be "in-memory" type which is usually bigger than "operations" type and that caused crashes because clang was trying to emit trunc to a bigger type. Fixes https://github.com/llvm/llvm-project/issues/144771 --- Full diff: https://github.com/llvm/llvm-project/pull/145497.diff 2 Files Affected: - (modified) clang/lib/CodeGen/CGBuiltin.cpp (+1-1) - (modified) clang/test/CodeGen/builtins-overflow.c (+12) ``````````diff diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 2c011a9519860..2a8722221f24b 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -2356,7 +2356,7 @@ EmitCheckedMixedSignMultiply(CodeGenFunction &CGF, const clang::Expr *Op1, llvm::Type *OpTy = Signed->getType(); llvm::Value *Zero = llvm::Constant::getNullValue(OpTy); Address ResultPtr = CGF.EmitPointerWithAlignment(ResultArg); - llvm::Type *ResTy = ResultPtr.getElementType(); + llvm::Type *ResTy = CGF.getTypes().ConvertType(ResultQTy); unsigned OpWidth = std::max(Op1Info.Width, Op2Info.Width); // Take the absolute value of the signed operand. diff --git a/clang/test/CodeGen/builtins-overflow.c b/clang/test/CodeGen/builtins-overflow.c index 7c524723f76e8..0e04191b9e2ac 100644 --- a/clang/test/CodeGen/builtins-overflow.c +++ b/clang/test/CodeGen/builtins-overflow.c @@ -604,3 +604,15 @@ long long test_mixed_sign_mul_overflow_extend_unsigned(int x, unsigned y) { return LongLongErrorCode; return result; } + +_BitInt(65) test_mixed_sign_mul_overflow_bitint(unsigned _BitInt(65) y, _BitInt(119) a) { +// CHECK: call { i119, i1 } @llvm.umul.with.overflow.i119 +// CHECK: select i1 %{{.*}}, i119 %{{.*}}, i119 %{{.*}} +// CHECK: trunc i119 +// CHECK: zext i65 +// CHECK: store + unsigned _BitInt(65) result; + if (__builtin_mul_overflow(a, y, &result)) + return LongLongErrorCode; + return result; +} `````````` </details> https://github.com/llvm/llvm-project/pull/145497 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits