Skip to content

Commit b46638d

Browse files
committed
[Local] Handle undef FP constant in getExpressionForConstant.
Check for FP constant instead of checking for floating point types, as Undef/Poison values can have floating point types while not being FPConstants. This fixes a crash introduced by llvm#66745 (f3b20cb).
1 parent 1228bec commit b46638d

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

llvm/lib/Transforms/Utils/Local.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3593,8 +3593,8 @@ DIExpression *llvm::getExpressionForConstant(DIBuilder &DIB, const Constant &C,
35933593
if (isa<ConstantInt>(C))
35943594
return createIntegerExpression(C);
35953595

3596-
if (Ty.isFloatTy() || Ty.isDoubleTy()) {
3597-
const APFloat &APF = cast<ConstantFP>(&C)->getValueAPF();
3596+
if (auto *FP = dyn_cast<ConstantFP>(&C)) {
3597+
const APFloat &APF = FP->getValueAPF();
35983598
return DIB.createConstantValueExpression(
35993599
APF.bitcastToAPInt().getZExtValue());
36003600
}

llvm/test/Transforms/SCCP/pr50901.ll

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
; CHECK-DAG: ![[DBG6]] = distinct !DIGlobalVariable(name: "g_66", {{.*}}
5050
; CHECK: ![[G7:[0-9]+]] = !DIGlobalVariableExpression(var: ![[DBG7:[0-9]+]], expr: !DIExpression(DW_OP_constu, 70, DW_OP_stack_value))
5151
; CHECK-DAG: ![[DBG7]] = distinct !DIGlobalVariable(name: "g_77", {{.*}}
52+
; CHECK: = !DIGlobalVariableExpression(var: ![[DBG_FLOAT_UNDEF:.+]], expr: !DIExpression())
53+
; CHECK-DAG: ![[DBG_FLOAT_UNDEF]] = distinct !DIGlobalVariable(name: "g_float_undef"
5254

5355
@g_1 = dso_local global i32 -4, align 4, !dbg !0
5456
@g_2 = dso_local global float 0x4011C28F60000000, align 4, !dbg !8
@@ -64,6 +66,7 @@
6466
@_ZL4g_55 = internal global i8 1, align 1, !dbg !33
6567
@_ZL4g_66 = internal global ptr null, align 8, !dbg !35
6668
@_ZL4g_77 = internal global ptr inttoptr (i64 70 to ptr), align 8, !dbg !37
69+
@g_float_undef = internal global float undef, align 4, !dbg !83
6770

6871
define dso_local void @_Z3barv() !dbg !46 {
6972
entry:
@@ -83,6 +86,8 @@ entry:
8386
store ptr %5, ptr @g_6, align 8, !dbg !59
8487
%6 = load ptr, ptr @_ZL4g_77, align 8, !dbg !59
8588
store ptr %6, ptr @g_7, align 8, !dbg !59
89+
%l = load float, ptr @g_float_undef, align 8, !dbg !59
90+
store float %l, ptr @g_2, align 8, !dbg !59
8691
ret void, !dbg !59
8792
}
8893

@@ -103,7 +108,7 @@ entry:
103108
!4 = !{!5}
104109
!5 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !6, size: 64)
105110
!6 = !DIBasicType(name: "float", size: 32, encoding: DW_ATE_float)
106-
!7 = !{!0, !8, !10, !13, !16, !19, !23, !25, !27, !29, !31, !33, !35, !37}
111+
!7 = !{!0, !8, !10, !13, !16, !19, !23, !25, !27, !29, !31, !33, !35, !37, !83}
107112
!8 = !DIGlobalVariableExpression(var: !9, expr: !DIExpression())
108113
!9 = distinct !DIGlobalVariable(name: "g_2", scope: !2, file: !3, line: 2, type: !6, isLocal: false, isDefinition: true)
109114
!10 = !DIGlobalVariableExpression(var: !11, expr: !DIExpression())
@@ -152,3 +157,5 @@ entry:
152157
!80 = !DILocation(line: 29, column: 5, scope: !81)
153158
!81 = distinct !DILexicalBlock(scope: !77, file: !3, line: 28, column: 3)
154159
!82 = !DILocation(line: 31, column: 1, scope: !77)
160+
!83 = !DIGlobalVariableExpression(var: !84, expr: !DIExpression())
161+
!84 = distinct !DIGlobalVariable(name: "g_float_undef", linkageName: "g_float_undef", scope: !2, file: !3, line: 15, type: !6, isLocal: true, isDefinition: true)

0 commit comments

Comments
 (0)