Skip to content

Commit 9b85191

Browse files
authored
Merge pull request #3280 from smowton/smowton/fix/preserve-float-literal-types
Ensure floating-point literals preserve distinction between types with same representation
2 parents d1733d8 + df1c57b commit 9b85191

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/ansi-c/literals/convert_float_literal.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,21 @@ exprt convert_float_literal(const std::string &src)
8484
else
8585
UNREACHABLE;
8686

87-
const constant_exprt result = a.to_expr();
87+
constant_exprt result = a.to_expr();
88+
// ieee_floatt::to_expr gives us the representation, but doesn't preserve the
89+
// distinction between bitwise-identical types such as _Float32 vs. float,
90+
// so ensure we preserve that here:
91+
result.type() = type;
8892

8993
if(parsed_float.is_imaginary)
9094
{
9195
const complex_typet complex_type(type);
92-
return complex_exprt(
93-
ieee_floatt::zero(type).to_expr(), result, complex_type);
96+
97+
constant_exprt zero_real_component = ieee_floatt::zero(type).to_expr();
98+
// As above, ensure we preserve the exact type of the literal:
99+
zero_real_component.type() = type;
100+
101+
return complex_exprt(zero_real_component, result, complex_type);
94102
}
95103

96104
return result;

0 commit comments

Comments
 (0)