Commit 8ce0349f
8ce0349fff93Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 7 months ago · 1 file · ~1 modified
Description
fix: bind Integer(ARGV[0] || N) LHS to a temp to silence -Wnonnull
The previous expansion textually repeated the left-hand side of the
|| inside the strtoll call, so the guarded ternary and the strtoll
argument looked like independent expressions to GCC's nonnull analysis:
((guard) ? strtoll((guard), ...) : N)
GCC correctly flagged this because it couldn't prove the strtoll argument was non-null despite the enclosing guard. Rewrite to a statement-expression that binds the LHS once:
({ const char *_t = guard; _t ? strtoll(_t, ...) : N; })
Functionally equivalent (also drops one duplicate evaluation of the ARGV lookup), and the -Wnonnull warning is gone.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 8ce0349fff93
- Parent
- b08940494d82
spinel_codegen.rbmodifiedView file
@@ -12006,13 +12006,16 @@
1200612006
lt = infer_type(@nd_left[a0])1200712007
rt = infer_type(@nd_right[a0])1200812008
if lt == "string" or lt == "argv"12009-
# ARGV access || default12009+
# Bind the left-hand expression to a temp so it's evaluated12010+
# only once, and so GCC's nonnull analysis can see that the12011+
# strtoll call sits in the truthy branch of the same test.1201012012
lc = compile_expr(@nd_left[a0])1201112013
rc2 = compile_expr(@nd_right[a0])12014+
tmp = new_temp1201212015
if rt == "int"12013-
return "((" + lc + ") ? (mrb_int)strtoll(" + lc + ", NULL, 10) : " + rc2 + ")"12016+
return "({ const char *" + tmp + " = " + lc + "; " + tmp + " ? (mrb_int)strtoll(" + tmp + ", NULL, 10) : " + rc2 + "; })"1201412017
else12015-
return "((" + lc + ") ? (mrb_int)strtoll(" + lc + ", NULL, 10) : (mrb_int)strtoll(" + rc2 + ", NULL, 10))"12018+
return "({ const char *" + tmp + " = " + lc + "; " + tmp + " ? (mrb_int)strtoll(" + tmp + ", NULL, 10) : (mrb_int)strtoll(" + rc2 + ", NULL, 10); })"1201612019
end1201712020
end1201812021
end