Skip to content

Commit 0c8d6df

Browse files
committed
Fix handling of FP-classify where the last arg fails to convert
The last argument of an FP-classify function was checked for vailidity as an expression, but we never ensured that the usual unary conversions/etc properly resulted in a valid value. Thus, when we got the value, it was null, so we had a null dereference. This patch instead fails out/marks the function call as invalid if the argument is incorrect. I DID consider just allowing it to continue, but the result was an extraneous error about how the last argument wasn't a float (in this case, it was an overload set). Fixes: #107411
1 parent 122874c commit 0c8d6df

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

clang/lib/Sema/SemaChecking.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4936,10 +4936,19 @@ bool Sema::BuiltinFPClassification(CallExpr *TheCall, unsigned NumArgs,
49364936
// Usual Unary Conversions will convert half to float, which we want for
49374937
// machines that use fp16 conversion intrinsics. Else, we wnat to leave the
49384938
// type how it is, but do normal L->Rvalue conversions.
4939-
if (Context.getTargetInfo().useFP16ConversionIntrinsics())
4940-
OrigArg = UsualUnaryConversions(OrigArg).get();
4941-
else
4942-
OrigArg = DefaultFunctionArrayLvalueConversion(OrigArg).get();
4939+
if (Context.getTargetInfo().useFP16ConversionIntrinsics()) {
4940+
ExprResult Res = UsualUnaryConversions(OrigArg);
4941+
4942+
if (!Res.isUsable())
4943+
return true;
4944+
OrigArg = Res.get();
4945+
} else {
4946+
ExprResult Res = DefaultFunctionArrayLvalueConversion(OrigArg);
4947+
4948+
if (!Res.isUsable())
4949+
return true;
4950+
OrigArg = Res.get();
4951+
}
49434952
TheCall->setArg(FPArgNo, OrigArg);
49444953

49454954
QualType VectorResultTy;

clang/test/Sema/builtin-unary-fp.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,8 @@ void a(void) {
1414
check(__builtin_fpclassify(0, 1, 2, 3, 4.5, 5.0)); // expected-warning{{implicit conversion from 'double' to 'int' changes value from 4.5 to 4}}
1515
check(__builtin_fpclassify(0, 0, 0, 0, 1)); // expected-error{{too few arguments}}
1616
check(__builtin_fpclassify(0, 0, 0, 0, 0, 1, 0)); // expected-error{{too many arguments}}
17+
18+
check(__builtin_fpclassify(0,0,0,0,0, (invalid))); // expected-error{{use of undeclared identifier 'invalid'}}
19+
check(__builtin_fpclassify(0,0,0,0,0, (inf))); // expected-error{{use of undeclared identifier 'inf'}}
20+
// expected-error@-1{{reference to overloaded function could not be resolved}}
1721
}

0 commit comments

Comments
 (0)