Skip to content

improve constexpr handling

Nicolai Stange linux-sparse 3 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest21 patches 49 repliesIn review
  2. v213 patches 29 repliesSuperseded
  3. v1 RFC13 patches 18 repliesSuperseded

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/21expression: introduce additional expression constness tracking flagsevaluate.c expand.c expression.c +1 more+171 -691 reply
2/21expression: init constexpr_flags at expression allocationexpression.h+2 -01 reply
3/21expression: examine constness of casts at evaluation onlyevaluate.c expression.c expression.h +1 more+53 -301 reply
4/21expression: examine constness of binops and alike at evaluation onlyevaluate.c expression.c validation/constexpr-binop.c+42 -241 reply
5/21expression: examine constness of preops at evaluation onlyevaluate.c expression.c validation/constexpr-preop.c+35 -111 reply
6/21expression: examine constness of conditionals at evaluation onlyevaluate.c expression.c validation/constexpr-conditional.c+38 -171 reply
7/21expression: add support for tagging arithmetic constant expressionsexpression.h+8 -41 reply
8/21expression, evaluate: add support for tagging address constantsevaluate.c expression.h+24 -51 reply
9/21evaluate: check static storage duration objects' intializers' constnessevaluate.c lib.c lib.h +2 more+97 -11 reply
10/21expression, evaluate: recognize static objects as address constantsevaluate.c expression.c validation/constexpr-addr-of-static.c+46 -11 reply
11/21evaluate: recognize address constants created through castsevaluate.c validation/constexpr-pointer-cast.c+22 -11 reply
12/21evaluate: recognize address constants created through pointer arithmeticevaluate.c validation/constexpr-pointer-arith.c+36 -01 reply
13/21evaluate: recognize members of static compound objects as address constantsevaluate.c validation/constexpr-addr-of-static-member.c+32 -01 reply
14/21evaluate: recognize string literals as address constantsevaluate.c validation/constexpr-string.c+10 -01 reply
15/21expression: recognize references to labels as address constantsexpression.c validation/constexpr-labelref.c+16 -01 reply
16/21expression: examine constness of __builtin_offsetof at evaluation onlyevaluate.c expression.c validation/constexpr-offsetof.c+28 -91 reply
17/21symbol: flag builtins constant_p, safe_p and warning as constexprssymbol.c+5 -41 reply
18/21evaluate: relax some constant expression rules for pointer expressionsevaluate.c+32 -63 replies
19/21expression, evaluate: support compound literals as address constantsevaluate.c expression.c validation/constexpr-compound-literal.c+23 -01 reply
20/21symbol: do not inherit storage modifiers from base types at examinationsymbol.c+2 -11 reply
21/21evaluation: treat comparsions between types as integer constexprevaluate.c expression.c validation/constexpr-types-compatible-p.c+20 -101 reply

Reviews trailers per patch

14 of 21 patches have a Reviewed-by or Acked-by.

PatchLuc Van Oostenryck
1/21
2/21R-b
3/21R-b
4/21R-b
5/21R-b
6/21R-b
7/21R-b
8/21R-b
9/21
10/21
11/21
12/21R-b
13/21R-b
14/21R-b
15/21R-b
16/21
17/21R-b
18/21R-b
19/21
20/21
21/21R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v3 thread

Cover letter [PATCH v3 00/21] improve constexpr handling

Here comes the greatly enhanced v3 of this series.

Luc's suggestions about splitting some patches turned out to be very fruitful!

Former [01/13] ("expression: introduce additional expression constness tracking flags") has been split into
- [01/21] ("expression: introduce additional expression constness tracking flags")
- [02/21] ("expression: init constexpr_flags at expression allocation")
- [07/21] ("expression: add support for tagging arithmetic constant expressions")

In particular, the introduction of the arithmetic constant expression flag is deferred until the last one of these three. This addresses Luc's concerns that the arithmetic constant expression handlings within the v2 "examine constness of XXX at evaluation only"-patches should better get split off into a separate patch each.

Former [06/13] ("expression, evaluate: add support for recognizing address constants") has been split into
- [08/21] ("expression, evaluate: add support for tagging address constants")
- [10/21] ("expression, evaluate: recognize static objects as address constants")
- [12/21] ("evaluate: recognize address constants created through pointer arithmetic")
- [13/21] ("evaluate: recognize members of static compound objects as address constants")
- [14/21] ("evaluate: recognize string literals as address constants")

The address constant handling part from former
[02/13] ("expression: examine constness of casts at evaluation only") has been extracted into a patch on its own, namely
[11/21] ("evaluate: recognize address constants created through casts")

Patches [10-14/21] have been placed just until after static initializer checking has been introduced in
[09/21] ("evaluate: check static storage duration objects' intializers' constness"). This way, the monster testcase from former
[07/13] ("evaluate: check static storage duration objects' intializers' constness") can be split and the individual tests attached to the different patches as appropriate.

Note that we still have got this
[20/21] ("symbol: do not inherit storage modifiers from base types at examination") thing.

Detailed changes:
[01/21] ("expression: introduce additional expression constness tracking flags"):
- The expr_{set,clear}_flag() helpers have been replaced by bitmasks to be ored in or anded outnow.
- Renamed ->flags to ->constexpr_flags
- ->constexpr_flags initialization at expression allocation has been extracted into
[02/21] ("expression: init constexpr_flags at expression allocation")
- neither of the arithmetic constant expression flag nor address nor the address constant flag gets introduced by this patch anymore.
They get introduced in
[07/21] ("expression: add support for tagging arithmetic constant expressions") [08/21] ("expression, evaluate: add support for tagging address constants") as needed.
- Luc's remarks about the 'sic' comments carried over from the original code have been addressed in the new
[21/21] ("evaluation: treat comparsions between types as integer constexpr")
- Changes to patch description as suggested by Luc.
- Tag a TOKEN_ZERO_IDENT by integer constant instead of integer constant expression. Feels more natural but should not matter.

[02/21] ("expression: init constexpr_flags at expression allocation")
This one is new. Split off from former [01/13].

[03-06/21] ("expression: examine constness of XXX at evaluation only")
Adjusted patch descriptions as suggested by Luc.

[07/21] ("expression: add support for tagging arithmetic constant expressions")
This one is new. Split off from former [01/13].

[08/21] ("expression, evaluate: add support for tagging address constants")
Split off actual recognition of various address constant forms into separate patches [10-14/21]

[09/21] ("evaluate: check static storage duration objects' intializers' constness").
- -W-flag has been renamed to -Wconstexpr-not-const
- the associated warning message has been shortened to
"non-constant initializer for static object".
- the attached testcase has been greatly reduced as the tests are now

    attached to the patches [10-14/21].

[10-14/21]
These ones are new and split off from former
[06/13] ("expression, evaluate: add support for tagging address constants") They implement actual address constant recognition functionality.

In
[12/21] ("evaluate: recognize address constants created through pointer arithmetic") a whitespace issue from former
[06/13] ("expression, evaluate: add support for recognizing address constants") in an if-clause has been fixed.

[15/21] ("expression: recognize references to labels as address constants")
A testcase for has been added.

[19/21] ("evaluate: relax some constant expression rules for pointer expressions")
A typo ("adress") has been fixed.

[21/21] ("evaluation: treat comparsions between types as integer constexpr")
This one is new.

Nicolai Stange (21):
expression: introduce additional expression constness tracking flags
expression: init constexpr_flags at expression allocation
expression: examine constness of casts at evaluation only
expression: examine constness of binops and alike at evaluation only
expression: examine constness of preops at evaluation only
expression: examine constness of conditionals at evaluation only
expression: add support for tagging arithmetic constant expressions expression, evaluate: add support for tagging address constants
evaluate: check static storage duration objects' intializers'
constness
expression, evaluate: recognize static objects as address constants
evaluate: recognize address constants created through casts
evaluate: recognize address constants created through pointer
arithmetic
evaluate: recognize members of static compound objects as address
constants
evaluate: recognize string literals as address constants
expression: recognize references to labels as address constants
expression: examine constness of __builtin_offsetof at evaluation only
symbol: flag builtins constant_p, safe_p and warning as constexprs
evaluate: relax some constant expression rules for pointer expressions expression, evaluate: support compound literals as address constants
symbol: do not inherit storage modifiers from base types at
examination
evaluation: treat comparsions between types as integer constexpr

 evaluate.c                                   | 207 +++++++++++++++++++++------
 expand.c                                     |  10 +-
 expression.c                                 |  50 +++----
 expression.h                                 |  83 ++++++++++-
 lib.c                                        |   2 +
 lib.h                                        |   1 +
 sparse.1                                     |   9 ++
 symbol.c                                     |  12 +-
 validation/constexpr-addr-of-static-member.c |  26 ++++
 validation/constexpr-addr-of-static.c        |  36 +++++
 validation/constexpr-binop.c                 |  33 +++++
 validation/constexpr-cast.c                  |  25 ++++
 validation/constexpr-compound-literal.c      |  19 +++
 validation/constexpr-conditional.c           |  34 +++++
 validation/constexpr-init.c                  |  60 ++++++++
 validation/constexpr-labelref.c              |  15 ++
 validation/constexpr-offsetof.c              |  21 +++
 validation/constexpr-pointer-arith.c         |  28 ++++
 validation/constexpr-pointer-cast.c          |  13 ++
 validation/constexpr-preop.c                 |  29 ++++
 validation/constexpr-string.c                |   9 ++
 validation/constexpr-types-compatible-p.c    |   9 ++
 22 files changed, 640 insertions(+), 91 deletions(-)
 create mode 100644 validation/constexpr-addr-of-static-member.c
 create mode 100644 validation/constexpr-addr-of-static.c
 create mode 100644 validation/constexpr-binop.c
 create mode 100644 validation/constexpr-cast.c
 create mode 100644 validation/constexpr-compound-literal.c
 create mode 100644 validation/constexpr-conditional.c
 create mode 100644 validation/constexpr-init.c
 create mode 100644 validation/constexpr-labelref.c
 create mode 100644 validation/constexpr-offsetof.c
 create mode 100644 validation/constexpr-pointer-arith.c
 create mode 100644 validation/constexpr-pointer-cast.c
 create mode 100644 validation/constexpr-preop.c
 create mode 100644 validation/constexpr-string.c
 create mode 100644 validation/constexpr-types-compatible-p.c
Signature · 1 line
2.7.0