diff options
| author | Nicolai Stange <nicstange@gmail.com> | 2016-02-01 03:32:32 +0100 |
|---|---|---|
| committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2017-03-31 02:14:10 +0200 |
| commit | 4a99724da62bfe56c6347be07cf01579b16c6e68 (patch) | |
| tree | 70f4b7864b4f676651cbb5bc22f11849b4a4b8fe /validation | |
| parent | 1b62f0f61f38d8f6881c6ee14da2f9137bd68fc7 (diff) | |
| download | sparse-dev-4a99724da62bfe56c6347be07cf01579b16c6e68.tar.gz | |
constexpr: examine constness of binops and alike at evaluation only
Move the whole calculation of binary operations', compare and logical
expressions' constness flags to the evaluation phase such that expressions
like
0 + __builtin_choose_expr(0, 0, 0)
0 < __builtin_choose_expr(0, 0, 0)
0 && __builtin_choose_expr(0, 0, 0)
can now be recognized as qualifying as integer constant expressions.
Signed-off-by: Nicolai Stange <nicstange@gmail.com>
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Diffstat (limited to 'validation')
| -rw-r--r-- | validation/constexpr-binop.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/validation/constexpr-binop.c b/validation/constexpr-binop.c new file mode 100644 index 00000000..85a88e3c --- /dev/null +++ b/validation/constexpr-binop.c @@ -0,0 +1,33 @@ +static int a[] = { + [0 + 0] = 0, // OK + [0 + 0.] = 0, // KO + [(void*)0 + 0] = 0, // KO + [0 + __builtin_choose_expr(0, 0, 0)] = 0, // OK + [0 + __builtin_choose_expr(0, 0., 0)] = 0, // OK + [0 + __builtin_choose_expr(0, 0, 0.)] = 0, // KO + [0 < 0] = 0, // OK + [0 < 0.] = 0, // KO + [0 < __builtin_choose_expr(0, 0, 0)] = 0, // OK + [0 < __builtin_choose_expr(0, 0., 0)] = 0, // OK + [0 < __builtin_choose_expr(0, 0, 0.)] = 0, // KO + [0 && 0] = 0, // OK + [0 && 0.] = 0, // KO + [0 && __builtin_choose_expr(0, 0, 0)] = 0, // OK + [0 && __builtin_choose_expr(0, 0., 0)] = 0, // OK + [0 && __builtin_choose_expr(0, 0, 0.)] = 0, // KO + [0 + __builtin_types_compatible_p(int, float)] = 0, // OK +}; + +/* + * check-name: Expression constness propagation in binops and alike + * + * check-error-start +constexpr-binop.c:3:12: error: bad constant expression +constexpr-binop.c:4:19: error: bad integer constant expression +constexpr-binop.c:7:12: error: bad constant expression +constexpr-binop.c:9:12: error: bad integer constant expression +constexpr-binop.c:12:12: error: bad integer constant expression +constexpr-binop.c:14:12: error: bad integer constant expression +constexpr-binop.c:17:12: error: bad integer constant expression + * check-error-end + */ |
