All of lore.kernel.org
 help / color / mirror / Atom feed
* [SPARSE v2 00/28] detect invalid branches
@ 2020-05-19  0:57 Luc Van Oostenryck
  2020-05-19  0:57 ` [PATCH v1 01/28] misc: fix testcase typeof-safe Luc Van Oostenryck
                   ` (28 more replies)
  0 siblings, 29 replies; 47+ messages in thread
From: Luc Van Oostenryck @ 2020-05-19  0:57 UTC (permalink / raw)
  To: linux-sparse; +Cc: Linus Torvalds, Luc Van Oostenryck

It's not allowed to do a goto into an expression statement.
For example, it's not well defined what should happen if such
an expression is not otherwise reachable and/or can be optimized
away. For such situations GCC issues an error, clang doesn't
and produce a valid IR but Spare produce an invalid IR with
branches to unexisting BBs.

The goals of the patches in this series are:
*) to detect such gotos at evaluation time;
*) issue a sensible error message;
*) avoid the linearization of functions with invalid gotos.

The implementation principle behind these is to add a new kind
of scope (label_scope), one for the usual function scope of
labels one for each statement expressions. This new scope,
instead of being used as a real scope for the visibility of
labels, is used to mark where labels are defined and where
they're used. 

Using this label scope as a real scope controling the
visibility of labels was quite appealing and was the initial
drive for this implementation but has the problem of inner
scope shadowing earlier occurence of labels identically
named. This is of course desired for 'normal' symbols but for
labels (which are normally visible in the whole function
and which may be used before being declared/defined)
it has the disadvantage of:
*) inhibiting the detecting of misuses once an inner scope
   is closed
*) allowing several distinct labels with the same name
   in a single function (this can be regarded as a feature
   but __label__ at block scope should be used for this)
*) create diffrences about what is permssble or not between
   sparse and GCC or clang.


Changes since v1:
* move most of the checks from eveluation time to parsing time
* add warnings for unused labels based on code from Linus
* add support for label attributes 'unused'
* add to label-expressions the same kind of checks than
  those done for gotos
* use the correct position in warnings
* lots of small improvements


Luc Van Oostenryck (28):
  misc: fix testcase typeof-safe
  misc: s/fntype/rettype/
  misc: always use the node for current_fn
  bad-goto: add testcase for 'jump inside discarded expression statement'
  bad-goto: add testcases for linearization of invalid labels
  bad-goto: reorganize testcases and add some more
  bad-goto: do not linearize if the IR will be invalid
  bad-goto: reorg test in evaluate_goto_statement()
  bad-goto: simplify testing of undeclared labels
  bad-goto: do not linearize function with undeclared labels
  bad-goto: catch labels with reserved names
  scope: no memset() needed after __alloc_scope()
  scope: move scope opening/ending inside compound_statement()
  scope: extract bind_symbol_with_scope() from bind_symbol()
  scope: __func__ is special
  scope: __label__ is special
  scope: s/{start,end}_symbol_scope/{start,end}_block_scope/
  scope: make function_scope invalid outside functions
  scope: let labels have their own scope
  scope: add is_in_scope()
  scope: give a scope for labels & gotos
  bad-goto: jumping inside a statemet expression is an error
  bad-goto: label expression inside a statement expression is UB
  bad-goto: extract check_label_declaration()
  bad-goto: check declaration of label expressions
  bad-label: check for unused labels
  bad-label: mark labels as used when needed
  bad-label: respect attribute((unused))

 evaluate.c                                    | 36 ++++++--
 expand.c                                      |  2 +-
 expression.c                                  | 12 +--
 linearize.c                                   |  2 +-
 parse.c                                       | 73 +++++++++++++----
 parse.h                                       |  4 +-
 scope.c                                       | 46 +++++++++--
 scope.h                                       | 10 ++-
 symbol.c                                      | 13 ++-
 symbol.h                                      |  7 ++
 validation/__func__-scope.c                   |  8 ++
 .../{asm-goto-lables.c => asm-goto-labels.c}  |  0
 validation/label-asm.c                        |  1 +
 validation/label-attr.c                       |  2 +-
 validation/label-scope-cgoto.c                | 82 +++++++++++++++++++
 validation/label-scope.c                      |  5 +-
 validation/label-scope1.c                     | 42 ++++++++++
 validation/label-scope2.c                     | 31 +++++++
 validation/label-stmt-expr0.c                 | 38 +++++++++
 validation/label-stmt-expr1.c                 | 28 +++++++
 validation/label-stmt-expr2.c                 | 46 +++++++++++
 validation/label-unused.c                     | 29 +++++++
 validation/linear/goto-invalid.c              | 18 ++++
 .../linear/goto-stmt-expr-conditional.c       | 27 ++++++
 .../linear/goto-stmt-expr-short-circuit.c     | 31 +++++++
 validation/linear/label-scope-cgoto.c         | 10 +++
 .../label-stmt-dropped.c}                     |  4 +-
 .../label-stmt-expr0.c}                       |  4 +-
 ...reachable-label0.c => label-unreachable.c} |  3 +-
 validation/typeof-safe.c                      | 26 ++++--
 30 files changed, 576 insertions(+), 64 deletions(-)
 create mode 100644 validation/__func__-scope.c
 rename validation/{asm-goto-lables.c => asm-goto-labels.c} (100%)
 create mode 100644 validation/label-scope-cgoto.c
 create mode 100644 validation/label-scope1.c
 create mode 100644 validation/label-scope2.c
 create mode 100644 validation/label-stmt-expr0.c
 create mode 100644 validation/label-stmt-expr1.c
 create mode 100644 validation/label-stmt-expr2.c
 create mode 100644 validation/label-unused.c
 create mode 100644 validation/linear/goto-invalid.c
 create mode 100644 validation/linear/goto-stmt-expr-conditional.c
 create mode 100644 validation/linear/goto-stmt-expr-short-circuit.c
 create mode 100644 validation/linear/label-scope-cgoto.c
 rename validation/{discarded-label-statement.c => linear/label-stmt-dropped.c} (84%)
 rename validation/{label-expr.c => linear/label-stmt-expr0.c} (75%)
 rename validation/linear/{unreachable-label0.c => label-unreachable.c} (80%)


base-commit: 146e6a63e715e0c3e08aacbcaa79ff8930289297
-- 
2.26.2

^ permalink raw reply	[flat|nested] 47+ messages in thread

end of thread, other threads:[~2020-05-20 16:39 UTC | newest]

Thread overview: 47+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-19  0:57 [SPARSE v2 00/28] detect invalid branches Luc Van Oostenryck
2020-05-19  0:57 ` [PATCH v1 01/28] misc: fix testcase typeof-safe Luc Van Oostenryck
2020-05-20  0:33   ` Ramsay Jones
2020-05-20 15:34     ` Ramsay Jones
2020-05-20 16:12       ` Luc Van Oostenryck
2020-05-19  0:57 ` [PATCH v1 02/28] misc: s/fntype/rettype/ Luc Van Oostenryck
2020-05-20  0:35   ` Ramsay Jones
2020-05-20 16:39     ` Luc Van Oostenryck
2020-05-19  0:57 ` [PATCH v1 03/28] misc: always use the node for current_fn Luc Van Oostenryck
2020-05-20  0:37   ` Ramsay Jones
2020-05-19  0:57 ` [PATCH v1 04/28] bad-goto: add testcase for 'jump inside discarded expression statement' Luc Van Oostenryck
2020-05-19  0:57 ` [PATCH v1 05/28] bad-goto: add testcases for linearization of invalid labels Luc Van Oostenryck
2020-05-19  0:57 ` [PATCH v1 06/28] bad-goto: reorganize testcases and add some more Luc Van Oostenryck
2020-05-19  0:57 ` [PATCH v1 07/28] bad-goto: do not linearize if the IR will be invalid Luc Van Oostenryck
2020-05-19  0:57 ` [PATCH v1 08/28] bad-goto: reorg test in evaluate_goto_statement() Luc Van Oostenryck
2020-05-19  0:57   ` Luc Van Oostenryck
2020-05-19  0:57 ` [PATCH v1 09/28] bad-goto: simplify testing of undeclared labels Luc Van Oostenryck
2020-05-19  0:57 ` [PATCH v1 10/28] bad-goto: do not linearize function with " Luc Van Oostenryck
2020-05-19  0:57 ` [PATCH v1 11/28] bad-goto: catch labels with reserved names Luc Van Oostenryck
2020-05-19  0:57 ` [PATCH v1 12/28] scope: no memset() needed after __alloc_scope() Luc Van Oostenryck
2020-05-19  0:57 ` [PATCH v1 13/28] scope: move scope opening/ending inside compound_statement() Luc Van Oostenryck
2020-05-19  0:57   ` Luc Van Oostenryck
2020-05-19  0:57 ` [PATCH v1 14/28] scope: extract bind_symbol_with_scope() from bind_symbol() Luc Van Oostenryck
2020-05-20  0:44   ` Ramsay Jones
2020-05-19  0:57 ` [PATCH v1 15/28] scope: __func__ is special Luc Van Oostenryck
2020-05-20  0:45   ` Ramsay Jones
2020-05-19  0:57 ` [PATCH v1 16/28] scope: __label__ " Luc Van Oostenryck
2020-05-20  0:47   ` Ramsay Jones
2020-05-19  0:57 ` [PATCH v1 17/28] scope: s/{start,end}_symbol_scope/{start,end}_block_scope/ Luc Van Oostenryck
2020-05-19  0:57 ` [PATCH v1 18/28] scope: make function_scope invalid outside functions Luc Van Oostenryck
2020-05-19  1:38   ` Linus Torvalds
2020-05-19 20:57     ` Luc Van Oostenryck
2020-05-19  0:57 ` [PATCH v1 19/28] scope: let labels have their own scope Luc Van Oostenryck
2020-05-19  0:57 ` [PATCH v1 20/28] scope: add is_in_scope() Luc Van Oostenryck
2020-05-19  0:57 ` [PATCH v1 21/28] scope: give a scope for labels & gotos Luc Van Oostenryck
2020-05-19  0:57 ` [PATCH v1 22/28] bad-goto: jumping inside a statemet expression is an error Luc Van Oostenryck
2020-05-20  0:53   ` Ramsay Jones
2020-05-20 16:37     ` Luc Van Oostenryck
2020-05-19  0:57 ` [PATCH v1 23/28] bad-goto: label expression inside a statement expression is UB Luc Van Oostenryck
2020-05-19  0:57 ` [PATCH v1 24/28] bad-goto: extract check_label_declaration() Luc Van Oostenryck
2020-05-19  0:57 ` [PATCH v1 25/28] bad-goto: check declaration of label expressions Luc Van Oostenryck
2020-05-20  0:56   ` Ramsay Jones
2020-05-19  0:57 ` [PATCH v1 26/28] bad-label: check for unused labels Luc Van Oostenryck
2020-05-19  0:57 ` [PATCH v1 27/28] bad-label: mark labels as used when needed Luc Van Oostenryck
2020-05-19  0:57 ` [PATCH v1 28/28] bad-label: respect attribute((unused)) Luc Van Oostenryck
2020-05-19  1:41 ` [SPARSE v2 00/28] detect invalid branches Linus Torvalds
2020-05-19 21:16   ` Luc Van Oostenryck

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.