Skip to content

Commit 52bffdf

Browse files
authored
[IPSCCP][FuncSpec] Protect against metadata access from call args. (#124284)
Fixes an issue reported from #114964, where metadata arguments were attempted to be accessed as constants.
1 parent 2696e4f commit 52bffdf

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

llvm/lib/Transforms/IPO/FunctionSpecialization.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,8 @@ Constant *InstCostVisitor::visitCallBase(CallBase &I) {
415415

416416
for (unsigned Idx = 0, E = I.getNumOperands() - 1; Idx != E; ++Idx) {
417417
Value *V = I.getOperand(Idx);
418+
if (isa<MetadataAsValue>(V))
419+
return nullptr;
418420
Constant *C = findConstantFor(V);
419421
if (!C)
420422
return nullptr;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt -passes=ipsccp -force-specialization -S < %s | FileCheck %s
3+
4+
define float @test(ptr %this, float %cm, i1 %0) strictfp {
5+
; CHECK-LABEL: define float @test(
6+
; CHECK-SAME: ptr [[THIS:%.*]], float [[CM:%.*]], i1 [[TMP0:%.*]]) #[[ATTR0:[0-9]+]] {
7+
; CHECK-NEXT: [[ENTRY:.*:]]
8+
; CHECK-NEXT: [[CMP:%.*]] = call i1 @llvm.experimental.constrained.fcmps.f32(float [[CM]], float 0.000000e+00, metadata !"ole", metadata !"fpexcept.strict")
9+
; CHECK-NEXT: [[CALL295:%.*]] = call float @test.specialized.1(ptr null, float 0.000000e+00, i1 false)
10+
; CHECK-NEXT: ret float 0.000000e+00
11+
;
12+
entry:
13+
%cmp = call i1 @llvm.experimental.constrained.fcmps.f32(float %cm, float 0.000000e+00, metadata !"ole", metadata !"fpexcept.strict") #0
14+
%call295 = call float @test(ptr null, float 0.000000e+00, i1 false) #0
15+
ret float 0.000000e+00
16+
}
17+

0 commit comments

Comments
 (0)