-
Notifications
You must be signed in to change notification settings - Fork 274
_Static_assert failures should be reported in the front-end #5677
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
_Static_assert(1 == 0, "must fail"); | ||
|
||
int main() | ||
{ | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
CORE gcc-only | ||
global.c | ||
|
||
static assertion failed: must fail | ||
^CONVERSION ERROR$ | ||
^EXIT=(1|64)$ | ||
^SIGNAL=0$ | ||
-- | ||
^warning: ignoring | ||
Invariant check failed |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
int main() | ||
{ | ||
_Static_assert(1 == 0, "must fail"); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
CORE gcc-only | ||
local.c | ||
|
||
static assertion failed: must fail | ||
^CONVERSION ERROR$ | ||
^EXIT=(1|64)$ | ||
^SIGNAL=0$ | ||
-- | ||
^warning: ignoring | ||
Invariant check failed |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
int main() | ||
{ | ||
int x; | ||
_Static_assert(x, "must fail"); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
CORE gcc-only | ||
not_constant.c | ||
|
||
expected constant expression | ||
^CONVERSION ERROR$ | ||
^EXIT=(1|64)$ | ||
^SIGNAL=0$ | ||
-- | ||
^warning: ignoring | ||
Invariant check failed |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ Author: Daniel Kroening, [email protected] | |
#include <util/config.h> | ||
#include <util/expr_initializer.h> | ||
#include <util/range.h> | ||
#include <util/string_constant.h> | ||
|
||
#include "ansi_c_declaration.h" | ||
|
||
|
@@ -102,9 +103,24 @@ void c_typecheck_baset::typecheck_code(codet &code) | |
} | ||
else if(statement==ID_static_assert) | ||
{ | ||
assert(code.operands().size()==2); | ||
PRECONDITION(code.operands().size() == 2); | ||
|
||
typecheck_expr(code.op0()); | ||
typecheck_expr(code.op1()); | ||
|
||
implicit_typecast_bool(code.op0()); | ||
make_constant(code.op0()); | ||
|
||
if(code.op0().is_false()) | ||
{ | ||
// failed | ||
error().source_location = code.find_source_location(); | ||
error() << "static assertion failed"; | ||
if(code.op1().id() == ID_string_constant) | ||
error() << ": " << to_string_constant(code.op1()).get_value(); | ||
error() << eom; | ||
throw 0; | ||
} | ||
} | ||
else if(statement==ID_CPROVER_try_catch || | ||
statement==ID_CPROVER_try_finally) | ||
|
@@ -247,7 +263,6 @@ void c_typecheck_baset::typecheck_decl(codet &code) | |
|
||
if(declaration.get_is_static_assert()) | ||
{ | ||
assert(declaration.operands().size()==2); | ||
codet new_code(ID_static_assert); | ||
new_code.add_source_location()=code.source_location(); | ||
new_code.operands().swap(declaration.operands()); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,8 +20,7 @@ Author: Daniel Kroening, [email protected] | |
simplify_exprt::resultt<> | ||
simplify_exprt::simplify_isinf(const unary_exprt &expr) | ||
{ | ||
if(expr.op().type().id() != ID_floatbv) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would leave that as a PRECONDITION. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could do, but would be redundant with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, please add, the idea being "fail early" and "clarity". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! |
||
return unchanged(expr); | ||
PRECONDITION(expr.op().type().id() == ID_floatbv); | ||
|
||
if(expr.op().is_constant()) | ||
{ | ||
|
@@ -35,6 +34,8 @@ simplify_exprt::simplify_isinf(const unary_exprt &expr) | |
simplify_exprt::resultt<> | ||
simplify_exprt::simplify_isnan(const unary_exprt &expr) | ||
{ | ||
PRECONDITION(expr.op().type().id() == ID_floatbv); | ||
|
||
if(expr.op().is_constant()) | ||
{ | ||
ieee_floatt value(to_constant_expr(expr.op())); | ||
|
@@ -47,6 +48,8 @@ simplify_exprt::simplify_isnan(const unary_exprt &expr) | |
simplify_exprt::resultt<> | ||
simplify_exprt::simplify_isnormal(const unary_exprt &expr) | ||
{ | ||
PRECONDITION(expr.op().type().id() == ID_floatbv); | ||
|
||
if(expr.op().is_constant()) | ||
{ | ||
ieee_floatt value(to_constant_expr(expr.op())); | ||
|
Uh oh!
There was an error while loading. Please reload this page.