[all-commits] [llvm/llvm-project] fd2dff: [clang][lex][minimizer] Ensure whitespace between ...

Jan Svoboda via All-commits all-commits at lists.llvm.org
Tue Feb 15 00:50:58 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: fd2dff17c53dbfd89789989bedd949c496e7b6b7
      https://github.com/llvm/llvm-project/commit/fd2dff17c53dbfd89789989bedd949c496e7b6b7
  Author: Jan Svoboda <jan_svoboda at apple.com>
  Date:   2022-02-15 (Tue, 15 Feb 2022)

  Changed paths:
    M clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp
    M clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp

  Log Message:
  -----------
  [clang][lex][minimizer] Ensure whitespace between squashed lines

The minimizer tries to squash multi-line macro definitions into single line. For that to work, contents of each line need to be separated by a space. Since we always strip leading whitespace on lines of a macro definition, the code currently tries to preserve exactly one space that appeared before the backslash.

This means the following code:

```
#define FOO(BAR) \
  #BAR           \
  baz
```

gets minimized into:

```
#define FOO(BAR) #BAR baz
```

However, if there are no spaces before the backslash on line 2:

```
#define FOO(BAR) \
  #BAR\
  baz
```

no space can be preserved, leading to (most likely) malformed macro definition:

```
#define FOO(BAR) #BARbaz
```

This patch makes sure we always put exactly one space at the end of line ending with a backslash.

Reviewed By: arphaman

Differential Revision: https://reviews.llvm.org/D119231


  Commit: d8298f04a9681fcbb16d7fc4872690b5504a0d52
      https://github.com/llvm/llvm-project/commit/d8298f04a9681fcbb16d7fc4872690b5504a0d52
  Author: Jan Svoboda <jan_svoboda at apple.com>
  Date:   2022-02-15 (Tue, 15 Feb 2022)

  Changed paths:
    M clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp
    M clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp

  Log Message:
  -----------
  [clang][lex][minimizer] Avoid treating path separators as comments

The minimizer strips out single-line comments (introduced by `//`). This sequence of characters can also appear in `#include` or `#import` directives where they play the role of path separators. We already avoid stripping this character sequence for `#include` but not for `#import` (which has the same semantics). This patch makes it so `#import <A//A.h>` is not affected by minimization. Previously, we would incorrectly reduce it into `#import <A`.

Reviewed By: arphaman

Differential Revision: https://reviews.llvm.org/D119226


Compare: https://github.com/llvm/llvm-project/compare/edd09bb5a49c...d8298f04a968


More information about the All-commits mailing list