[clang-tools-extra] e42f5d4 - [clangd] Fix filename ranges while replaying preamble

2021-10-27 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2021-10-27T09:34:17+02:00
New Revision: e42f5d4b488e78ebf5b756e1e76422c7458ba81c

URL: 
https://github.com/llvm/llvm-project/commit/e42f5d4b488e78ebf5b756e1e76422c7458ba81c
DIFF: 
https://github.com/llvm/llvm-project/commit/e42f5d4b488e78ebf5b756e1e76422c7458ba81c.diff

LOG: [clangd] Fix filename ranges while replaying preamble

Clangd used first token of filename as filename range rather than the
synthezied filename token. Unfortunately the former only contains `"` or `<` in
the raw lexing mode, resulting in wrong range information and breaking tidy
checks that relied on it.

Fixes https://github.com/clangd/clangd/issues/896.

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

Added: 


Modified: 
clang-tools-extra/clangd/ParsedAST.cpp
clang-tools-extra/clangd/unittests/ParsedASTTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/ParsedAST.cpp 
b/clang-tools-extra/clangd/ParsedAST.cpp
index a62169c8c241f..8fce756b83c1d 100644
--- a/clang-tools-extra/clangd/ParsedAST.cpp
+++ b/clang-tools-extra/clangd/ParsedAST.cpp
@@ -222,11 +222,14 @@ class ReplayPreamble : private PPCallbacks {
   const FileEntry *FE = File ? &File->getFileEntry() : nullptr;
   llvm::StringRef WrittenFilename =
   llvm::StringRef(Inc.Written).drop_front().drop_back();
-  Delegate->InclusionDirective(HashTok->location(), SynthesizedIncludeTok,
-   WrittenFilename, Inc.Written.front() == '<',
-   FileTok->range(SM).toCharRange(SM), FE,
-   "SearchPath", "RelPath",
-   /*Imported=*/nullptr, Inc.FileKind);
+  Delegate->InclusionDirective(
+  HashTok->location(), SynthesizedIncludeTok, WrittenFilename,
+  Inc.Written.front() == '<',
+  syntax::FileRange(SM, SynthesizedFilenameTok.getLocation(),
+SynthesizedFilenameTok.getEndLoc())
+  .toCharRange(SM),
+  FE, "SearchPath", "RelPath",
+  /*Imported=*/nullptr, Inc.FileKind);
   if (File)
 Delegate->FileSkipped(*File, SynthesizedFilenameTok, Inc.FileKind);
   else {

diff  --git a/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp 
b/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
index 211f289eae734..eabd174823cc5 100644
--- a/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
+++ b/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
@@ -361,7 +361,11 @@ TEST(ParsedASTTest, ReplayPreambleForTidyCheckers) {
 : HashOffset(SM.getDecomposedLoc(HashLoc).second), IncTok(IncludeTok),
   IncDirective(IncludeTok.getIdentifierInfo()->getName()),
   FileNameOffset(SM.getDecomposedLoc(FilenameRange.getBegin()).second),
-  FileName(FileName), IsAngled(IsAngled) {}
+  FileName(FileName), IsAngled(IsAngled) {
+  EXPECT_EQ(
+  toSourceCode(SM, 
FilenameRange.getAsRange()).drop_back().drop_front(),
+  FileName);
+}
 size_t HashOffset;
 syntax::Token IncTok;
 llvm::StringRef IncDirective;



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112559: [clangd] Fix filename ranges while replaying preamble

2021-10-27 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe42f5d4b488e: [clangd] Fix filename ranges while replaying 
preamble (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112559/new/

https://reviews.llvm.org/D112559

Files:
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/unittests/ParsedASTTests.cpp


Index: clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
===
--- clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
+++ clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
@@ -361,7 +361,11 @@
 : HashOffset(SM.getDecomposedLoc(HashLoc).second), IncTok(IncludeTok),
   IncDirective(IncludeTok.getIdentifierInfo()->getName()),
   FileNameOffset(SM.getDecomposedLoc(FilenameRange.getBegin()).second),
-  FileName(FileName), IsAngled(IsAngled) {}
+  FileName(FileName), IsAngled(IsAngled) {
+  EXPECT_EQ(
+  toSourceCode(SM, 
FilenameRange.getAsRange()).drop_back().drop_front(),
+  FileName);
+}
 size_t HashOffset;
 syntax::Token IncTok;
 llvm::StringRef IncDirective;
Index: clang-tools-extra/clangd/ParsedAST.cpp
===
--- clang-tools-extra/clangd/ParsedAST.cpp
+++ clang-tools-extra/clangd/ParsedAST.cpp
@@ -222,11 +222,14 @@
   const FileEntry *FE = File ? &File->getFileEntry() : nullptr;
   llvm::StringRef WrittenFilename =
   llvm::StringRef(Inc.Written).drop_front().drop_back();
-  Delegate->InclusionDirective(HashTok->location(), SynthesizedIncludeTok,
-   WrittenFilename, Inc.Written.front() == '<',
-   FileTok->range(SM).toCharRange(SM), FE,
-   "SearchPath", "RelPath",
-   /*Imported=*/nullptr, Inc.FileKind);
+  Delegate->InclusionDirective(
+  HashTok->location(), SynthesizedIncludeTok, WrittenFilename,
+  Inc.Written.front() == '<',
+  syntax::FileRange(SM, SynthesizedFilenameTok.getLocation(),
+SynthesizedFilenameTok.getEndLoc())
+  .toCharRange(SM),
+  FE, "SearchPath", "RelPath",
+  /*Imported=*/nullptr, Inc.FileKind);
   if (File)
 Delegate->FileSkipped(*File, SynthesizedFilenameTok, Inc.FileKind);
   else {


Index: clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
===
--- clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
+++ clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
@@ -361,7 +361,11 @@
 : HashOffset(SM.getDecomposedLoc(HashLoc).second), IncTok(IncludeTok),
   IncDirective(IncludeTok.getIdentifierInfo()->getName()),
   FileNameOffset(SM.getDecomposedLoc(FilenameRange.getBegin()).second),
-  FileName(FileName), IsAngled(IsAngled) {}
+  FileName(FileName), IsAngled(IsAngled) {
+  EXPECT_EQ(
+  toSourceCode(SM, FilenameRange.getAsRange()).drop_back().drop_front(),
+  FileName);
+}
 size_t HashOffset;
 syntax::Token IncTok;
 llvm::StringRef IncDirective;
Index: clang-tools-extra/clangd/ParsedAST.cpp
===
--- clang-tools-extra/clangd/ParsedAST.cpp
+++ clang-tools-extra/clangd/ParsedAST.cpp
@@ -222,11 +222,14 @@
   const FileEntry *FE = File ? &File->getFileEntry() : nullptr;
   llvm::StringRef WrittenFilename =
   llvm::StringRef(Inc.Written).drop_front().drop_back();
-  Delegate->InclusionDirective(HashTok->location(), SynthesizedIncludeTok,
-   WrittenFilename, Inc.Written.front() == '<',
-   FileTok->range(SM).toCharRange(SM), FE,
-   "SearchPath", "RelPath",
-   /*Imported=*/nullptr, Inc.FileKind);
+  Delegate->InclusionDirective(
+  HashTok->location(), SynthesizedIncludeTok, WrittenFilename,
+  Inc.Written.front() == '<',
+  syntax::FileRange(SM, SynthesizedFilenameTok.getLocation(),
+SynthesizedFilenameTok.getEndLoc())
+  .toCharRange(SM),
+  FE, "SearchPath", "RelPath",
+  /*Imported=*/nullptr, Inc.FileKind);
   if (File)
 Delegate->FileSkipped(*File, SynthesizedFilenameTok, Inc.FileKind);
   else {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112284: [Clang][NFC] Clang CUDA codegen clean-up

2021-10-27 Thread Uday Bondhugula via Phabricator via cfe-commits
bondhugula added a comment.

In D112284#3088531 , @tra wrote:

> In D112284#3086499 , @bondhugula 
> wrote:
>
>> @tra While on this, I also wanted to ask as to why clang cuda codegen is 
>> using an argument on the global ctor and the dtor it's generating.
>
> It's a good question, and I don't have a good answer. It's quite possible 
> that the parameter is not needed.

As a result of this parameter, there appears to be a lot of code in 
`CodegenModule.cpp` to add the ctor/dtor to the global lists. All of that would 
disappear with a single call to `appendToGlobalCtors` or `appendToGlobalDtors` 
if we got rid of the argument. Perhaps the extra argument was used initially 
for debugging or the fact that an extra argument bumps up the stack frame and 
makes something else work?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112284/new/

https://reviews.llvm.org/D112284

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112447: [clangd] IncludeCleaner: Support macros

2021-10-27 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

Very nice. As discussed it'd be nice to enhance MainFileMacros at some point 
but it doesn't seem urgent




Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:174
 
+// Gets the tokens from the main file, iterates through them and adds 
definition
+// locations for the found macros.

This describes the implementation, not the purpose.

```
Finds locations of all macros referenced from within the main file.
This includes references that were not yet expanded, like `BAR` in `#define FOO 
BAR`.
```




Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:181
+  // FIXME(kirillbobyrev): We are iterating through all tokens in the main 
file.
+  // To improve performance, we can improve CollectMainFileMacros: right now
+  // it populates ParsedAST's MainFileMacros with macro references but does not

I'd rephrase a little:
 - emphasize the data structure MainFileMacros and the data that's missing, 
rather than the process how it's collected
 - "in the definitions" isn't the essential property, it's rather that they 
weren't expanded. (e.g. macros uses in PP-disabled sections too). Then macro 
definitions are an example.




Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:191
+   AST.getTokens().spelledTokens(SM.getMainFileID())) {
+if (Tok.kind() != tok::identifier ||
+!PP.getIdentifierInfo(Tok.text(SM))->hadMacroDefinition())

this is just a fast-fail for non-identifiers, right? The hadMacroDefinition 
check is already done in locateMacroAt.

 Probably cleaner to move the == tok::identifier check inside locateMacroAt and 
remove the checks here.



Comment at: clang-tools-extra/clangd/IncludeCleaner.h:36
 ///
-/// Uses RecursiveASTVisitor to go through main file AST and computes all the
-/// locations used symbols are coming from. Returned locations may be macro
-/// expansions, and are not resolved to their spelling/expansion location. 
These
-/// locations are later used to determine which headers should be marked as
-/// "used" and "directly used".
+/// - For non-macros uses RecursiveASTVisitor to go through main file AST and
+///   computes all the locations used symbols are coming from. Returned

The start of this sentence is hard to parse: "non-macros" as a noun is vague, 
and probably needs a comma after. "uses" and "go through" are a bit vague too.

Maybe "A RecursiveASTVisitor finds references to symbols and records their 
associated locations. These may be macro expansions..."
And "We also examine all identifier tokens in the file in case they reference 
macros".

Really this is all describing the implementation though, and could be left out 
of the header entirely...



Comment at: clang-tools-extra/clangd/IncludeCleaner.h:40
+///   or expansion location. These locations are later used to determine which
+///   headers should /   be marked as "used" and "directly used".
+/// - For macros iteratates over \p AST tokens and collects locations of the

something's happened to the punctuation here



Comment at: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp:127
+  "#define BAR FOO",
+  },
+  {

Maybe PP-disabled too?

```
"#define ^FOO\n"
"#define ^BAR

"#if 0
#if FOO
BAR
#endif
#endif
"
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112447/new/

https://reviews.llvm.org/D112447

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112408: [WIP][RISCV] Add the zve extension according to the v1.0-rc2 spec

2021-10-27 Thread Yueh-Ting Chen via Phabricator via cfe-commits
eopXD added inline comments.



Comment at: llvm/lib/Target/RISCV/RISCVSubtarget.h:141
+  // either v or zve* suppaort v instructions
+  bool hasStdExtV() const { return HasStdExtV || HasStdExtZve32x; }
+  bool hasStdExtZve32x() const { return HasStdExtZve32x; }

craig.topper wrote:
> frasercrmck wrote:
> > Is this correct? I thought we'd keep `hasStdExtV` as being the 
> > single-letter V extension, and Zve32x isn't that.
> I just put up D112496 to stop using hasStdExtV everywhere.
Thank you @craig.topper for the patch.
LGTM, and we can have it landed after this series on `zvl`, `zve` patch are 
done.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112408/new/

https://reviews.llvm.org/D112408

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D108694: [WIP][RISCV] Add the zvl extension according to the v1.0-rc2 spec

2021-10-27 Thread Yueh-Ting Chen via Phabricator via cfe-commits
eopXD updated this revision to Diff 382540.
eopXD added a comment.

Rebase.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D108694/new/

https://reviews.llvm.org/D108694

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  clang/test/Driver/riscv-arch.c
  clang/test/Preprocessor/riscv-target-features.c
  llvm/include/llvm/Support/RISCVISAInfo.h
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVSubtarget.cpp
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s

Index: llvm/test/MC/RISCV/attribute-arch.s
===
--- llvm/test/MC/RISCV/attribute-arch.s
+++ llvm/test/MC/RISCV/attribute-arch.s
@@ -34,7 +34,7 @@
 # CHECK: attribute  5, "rv32i2p0_m2p0_a2p0_f2p0_d2p0_c2p0"
 
 .attribute arch, "rv32iv"
-# CHECK: attribute  5, "rv32i2p0_v0p10_zvlsseg0p10"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
 
 .attribute arch, "rv32izba"
 # CHECK: attribute  5, "rv32i2p0_zba1p0"
@@ -70,7 +70,43 @@
 # CHECK: attribute  5, "rv32i2p0_f2p0_zfh0p1"
 
 .attribute arch, "rv32ivzvamo_zvlsseg"
-# CHECK: attribute  5, "rv32i2p0_v0p10_zvamo0p10_zvlsseg0p10"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvamo0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
 
 .attribute arch, "rv32iv_zvamo0p10_zvlsseg"
-# CHECK: attribute  5, "rv32i2p0_v0p10_zvamo0p10_zvlsseg0p10"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvamo0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32ifdv_zvl32b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32ifdv_zvl64b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32ifdv_zvl128b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32ifdv_zvl256b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl128b0p10_zvl256b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32ifdv_zvl512b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl128b0p10_zvl256b0p10_zvl32b0p10_zvl512b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32ifdv_zvl1024b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl256b0p10_zvl32b0p10_zvl512b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32ifdv_zvl2048b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl2048b0p10_zvl256b0p10_zvl32b0p10_zvl512b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32ifdv_zvl4096b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl2048b0p10_zvl256b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32ifdv_zvl8192b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl2048b0p10_zvl256b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvl8192b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32ifdv_zvl16384b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl16384b0p10_zvl2048b0p10_zvl256b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvl8192b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32ifdv_zvl32768b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl16384b0p10_zvl2048b0p10_zvl256b0p10_zvl32768b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvl8192b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32ifdv_zvl65536b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl16384b0p10_zvl2048b0p10_zvl256b0p10_zvl32768b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvl65536b0p10_zvl8192b0p10_zvlsseg0p10"
Index: llvm/test/CodeGen/RISCV/attributes.ll
===
--- llvm/test/CodeGen/RISCV/attributes.ll
+++ llvm/test/CodeGen/RISCV/attributes.ll
@@ -42,7 +42,7 @@
 ; RV32F: .attribute 5, "rv32i2p0_f2p0"
 ; RV32D: .attribute 5, "rv32i2p0_f2p0_d2p0"
 ; RV32C: .attribute 5, "rv32i2p0_c2p0"
-; RV32V: .attribute 5, "rv32i2p0_v0p10_zvamo0p10_zvlsseg0p10"
+; RV32V: .attribute 5, "rv32i2p0_v0p10_zvamo0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
 ; RV32ZFH: .attribute 5, "rv32i2p0_f2p0_zfh0p1"
 ; RV32ZBA: .attribute 5, "rv32i2p0_zba1p0"
 ; RV32ZBB: .attribute 5, "rv32i2p0_zbb1p0"
@@ -54,7 +54,7 @@
 ; RV32ZBR: .attribute 5, "rv32i2p0_zbr0p93"
 ; RV32ZBS: .attribute 5, "rv32i2p0_zbs1p0"
 ; RV32ZBT: .attribute 5, "rv32i2p0_zbt0p93"
-; RV32COMBINED: .attribute 5, "rv32i2p0_f2p0_v0p10_zfh0p1_zbb1p0_zvamo0p10_zvlsseg0p10"
+; RV32COMBINED: .attribute 5, "rv32i2p0_f2p0_v0p10_zfh0p1_zbb1p0_zvamo0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
 
 ; RV64M: .attribute 5, "rv64i2p0_m2p0"
 ; RV64A: .attribute 5, "rv64i2p0_a2p0"
@@ -72,8 +72,

[PATCH] D108694: [WIP][RISCV] Add the zvl extension according to the v1.0-rc2 spec

2021-10-27 Thread Yueh-Ting Chen via Phabricator via cfe-commits
eopXD updated this revision to Diff 382543.
eopXD added a comment.

Fix clang-format.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D108694/new/

https://reviews.llvm.org/D108694

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  clang/test/Driver/riscv-arch.c
  clang/test/Preprocessor/riscv-target-features.c
  llvm/include/llvm/Support/RISCVISAInfo.h
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVSubtarget.cpp
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s

Index: llvm/test/MC/RISCV/attribute-arch.s
===
--- llvm/test/MC/RISCV/attribute-arch.s
+++ llvm/test/MC/RISCV/attribute-arch.s
@@ -34,7 +34,7 @@
 # CHECK: attribute  5, "rv32i2p0_m2p0_a2p0_f2p0_d2p0_c2p0"
 
 .attribute arch, "rv32iv"
-# CHECK: attribute  5, "rv32i2p0_v0p10_zvlsseg0p10"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
 
 .attribute arch, "rv32izba"
 # CHECK: attribute  5, "rv32i2p0_zba1p0"
@@ -70,7 +70,43 @@
 # CHECK: attribute  5, "rv32i2p0_f2p0_zfh0p1"
 
 .attribute arch, "rv32ivzvamo_zvlsseg"
-# CHECK: attribute  5, "rv32i2p0_v0p10_zvamo0p10_zvlsseg0p10"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvamo0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
 
 .attribute arch, "rv32iv_zvamo0p10_zvlsseg"
-# CHECK: attribute  5, "rv32i2p0_v0p10_zvamo0p10_zvlsseg0p10"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvamo0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32ifdv_zvl32b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32ifdv_zvl64b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32ifdv_zvl128b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32ifdv_zvl256b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl128b0p10_zvl256b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32ifdv_zvl512b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl128b0p10_zvl256b0p10_zvl32b0p10_zvl512b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32ifdv_zvl1024b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl256b0p10_zvl32b0p10_zvl512b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32ifdv_zvl2048b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl2048b0p10_zvl256b0p10_zvl32b0p10_zvl512b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32ifdv_zvl4096b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl2048b0p10_zvl256b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32ifdv_zvl8192b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl2048b0p10_zvl256b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvl8192b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32ifdv_zvl16384b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl16384b0p10_zvl2048b0p10_zvl256b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvl8192b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32ifdv_zvl32768b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl16384b0p10_zvl2048b0p10_zvl256b0p10_zvl32768b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvl8192b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32ifdv_zvl65536b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl16384b0p10_zvl2048b0p10_zvl256b0p10_zvl32768b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvl65536b0p10_zvl8192b0p10_zvlsseg0p10"
Index: llvm/test/CodeGen/RISCV/attributes.ll
===
--- llvm/test/CodeGen/RISCV/attributes.ll
+++ llvm/test/CodeGen/RISCV/attributes.ll
@@ -42,7 +42,7 @@
 ; RV32F: .attribute 5, "rv32i2p0_f2p0"
 ; RV32D: .attribute 5, "rv32i2p0_f2p0_d2p0"
 ; RV32C: .attribute 5, "rv32i2p0_c2p0"
-; RV32V: .attribute 5, "rv32i2p0_v0p10_zvamo0p10_zvlsseg0p10"
+; RV32V: .attribute 5, "rv32i2p0_v0p10_zvamo0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
 ; RV32ZFH: .attribute 5, "rv32i2p0_f2p0_zfh0p1"
 ; RV32ZBA: .attribute 5, "rv32i2p0_zba1p0"
 ; RV32ZBB: .attribute 5, "rv32i2p0_zbb1p0"
@@ -54,7 +54,7 @@
 ; RV32ZBR: .attribute 5, "rv32i2p0_zbr0p93"
 ; RV32ZBS: .attribute 5, "rv32i2p0_zbs1p0"
 ; RV32ZBT: .attribute 5, "rv32i2p0_zbt0p93"
-; RV32COMBINED: .attribute 5, "rv32i2p0_f2p0_v0p10_zfh0p1_zbb1p0_zvamo0p10_zvlsseg0p10"
+; RV32COMBINED: .attribute 5, "rv32i2p0_f2p0_v0p10_zfh0p1_zbb1p0_zvamo0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
 
 ; RV64M: .attribute 5, "rv64i2p0_m2p0"
 ; RV64A: .attribute 5, "rv64i2p0_a2p0"
@@ 

[PATCH] D108694: [WIP][RISCV] Add the zvl extension according to the v1.0-rc2 spec

2021-10-27 Thread Yueh-Ting Chen via Phabricator via cfe-commits
eopXD updated this revision to Diff 382544.
eopXD added a comment.

Update code.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D108694/new/

https://reviews.llvm.org/D108694

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  clang/test/Driver/riscv-arch.c
  clang/test/Preprocessor/riscv-target-features.c
  llvm/include/llvm/Support/RISCVISAInfo.h
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVSubtarget.cpp
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s

Index: llvm/test/MC/RISCV/attribute-arch.s
===
--- llvm/test/MC/RISCV/attribute-arch.s
+++ llvm/test/MC/RISCV/attribute-arch.s
@@ -34,7 +34,7 @@
 # CHECK: attribute  5, "rv32i2p0_m2p0_a2p0_f2p0_d2p0_c2p0"
 
 .attribute arch, "rv32iv"
-# CHECK: attribute  5, "rv32i2p0_v0p10_zvlsseg0p10"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
 
 .attribute arch, "rv32izba"
 # CHECK: attribute  5, "rv32i2p0_zba1p0"
@@ -70,7 +70,43 @@
 # CHECK: attribute  5, "rv32i2p0_f2p0_zfh0p1"
 
 .attribute arch, "rv32ivzvamo_zvlsseg"
-# CHECK: attribute  5, "rv32i2p0_v0p10_zvamo0p10_zvlsseg0p10"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvamo0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
 
 .attribute arch, "rv32iv_zvamo0p10_zvlsseg"
-# CHECK: attribute  5, "rv32i2p0_v0p10_zvamo0p10_zvlsseg0p10"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvamo0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32ifdv_zvl32b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32ifdv_zvl64b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32ifdv_zvl128b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32ifdv_zvl256b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl128b0p10_zvl256b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32ifdv_zvl512b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl128b0p10_zvl256b0p10_zvl32b0p10_zvl512b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32ifdv_zvl1024b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl256b0p10_zvl32b0p10_zvl512b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32ifdv_zvl2048b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl2048b0p10_zvl256b0p10_zvl32b0p10_zvl512b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32ifdv_zvl4096b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl2048b0p10_zvl256b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32ifdv_zvl8192b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl2048b0p10_zvl256b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvl8192b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32ifdv_zvl16384b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl16384b0p10_zvl2048b0p10_zvl256b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvl8192b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32ifdv_zvl32768b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl16384b0p10_zvl2048b0p10_zvl256b0p10_zvl32768b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvl8192b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32ifdv_zvl65536b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl16384b0p10_zvl2048b0p10_zvl256b0p10_zvl32768b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvl65536b0p10_zvl8192b0p10_zvlsseg0p10"
Index: llvm/test/CodeGen/RISCV/attributes.ll
===
--- llvm/test/CodeGen/RISCV/attributes.ll
+++ llvm/test/CodeGen/RISCV/attributes.ll
@@ -42,7 +42,7 @@
 ; RV32F: .attribute 5, "rv32i2p0_f2p0"
 ; RV32D: .attribute 5, "rv32i2p0_f2p0_d2p0"
 ; RV32C: .attribute 5, "rv32i2p0_c2p0"
-; RV32V: .attribute 5, "rv32i2p0_v0p10_zvamo0p10_zvlsseg0p10"
+; RV32V: .attribute 5, "rv32i2p0_v0p10_zvamo0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
 ; RV32ZFH: .attribute 5, "rv32i2p0_f2p0_zfh0p1"
 ; RV32ZBA: .attribute 5, "rv32i2p0_zba1p0"
 ; RV32ZBB: .attribute 5, "rv32i2p0_zbb1p0"
@@ -54,7 +54,7 @@
 ; RV32ZBR: .attribute 5, "rv32i2p0_zbr0p93"
 ; RV32ZBS: .attribute 5, "rv32i2p0_zbs1p0"
 ; RV32ZBT: .attribute 5, "rv32i2p0_zbt0p93"
-; RV32COMBINED: .attribute 5, "rv32i2p0_f2p0_v0p10_zfh0p1_zbb1p0_zvamo0p10_zvlsseg0p10"
+; RV32COMBINED: .attribute 5, "rv32i2p0_f2p0_v0p10_zfh0p1_zbb1p0_zvamo0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
 
 ; RV64M: .attribute 5, "rv64i2p0_m2p0"
 ; RV64A: .attribute 5, "rv64i2p0_a2p0"
@@ -72,8

[PATCH] D112447: [clangd] IncludeCleaner: Support macros

2021-10-27 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 382549.
kbobyrev marked 6 inline comments as done.
kbobyrev added a comment.

Address review comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112447/new/

https://reviews.llvm.org/D112447

Files:
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/clangd/SourceCode.cpp
  clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp

Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -116,6 +116,35 @@
   "struct ^X { enum ^Language { ^CXX = 42, Python = 9000}; };",
   "int Lang = X::CXX;",
   },
+  // Macros
+  {
+  "#define ^CONSTANT 42",
+  "int Foo = CONSTANT;",
+  },
+  {
+  "#define ^FOO x",
+  "#define BAR FOO",
+  },
+  {
+  "#define INNER 42\n"
+  "#define ^OUTER INNER",
+  "int answer = OUTER;",
+  },
+  {
+  "#define ^ANSWER 42\n"
+  "#define ^SQUARE(X) X * X",
+  "int sq = SQUARE(ANSWER);",
+  },
+  {
+  "#define ^FOO\n"
+  "#define ^BAR",
+  "#if 0\n"
+  "#if FOO\n"
+  "BAR\n"
+  "#endif\n"
+  "#endif",
+  },
+  // Misc
   {
   "enum class ^Color : int;",
   "enum class Color : int {};",
Index: clang-tools-extra/clangd/SourceCode.cpp
===
--- clang-tools-extra/clangd/SourceCode.cpp
+++ clang-tools-extra/clangd/SourceCode.cpp
@@ -975,6 +975,8 @@
 
 llvm::Optional locateMacroAt(const syntax::Token &SpelledTok,
Preprocessor &PP) {
+  if (SpelledTok.kind() != tok::identifier)
+return None;
   SourceLocation Loc = SpelledTok.location();
   assert(Loc.isFileID());
   const auto &SM = PP.getSourceManager();
Index: clang-tools-extra/clangd/IncludeCleaner.h
===
--- clang-tools-extra/clangd/IncludeCleaner.h
+++ clang-tools-extra/clangd/IncludeCleaner.h
@@ -33,11 +33,12 @@
 using ReferencedLocations = llvm::DenseSet;
 /// Finds locations of all symbols used in the main file.
 ///
-/// Uses RecursiveASTVisitor to go through main file AST and computes all the
-/// locations used symbols are coming from. Returned locations may be macro
-/// expansions, and are not resolved to their spelling/expansion location. These
-/// locations are later used to determine which headers should be marked as
-/// "used" and "directly used".
+/// - A RecursiveASTVisitor finds references to symbols and records their
+///   associated locations. These may be macro expansions, and are not resolved
+///   to their spelling or expansion location. These locations are later used to
+///   determine which headers should be marked as "used" and "directly used".
+/// - We also examine all identifier tokens in the file in case they reference
+///   macros.
 ///
 /// We use this to compute unused headers, so we:
 ///
Index: clang-tools-extra/clangd/IncludeCleaner.cpp
===
--- clang-tools-extra/clangd/IncludeCleaner.cpp
+++ clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -11,8 +11,11 @@
 #include "Protocol.h"
 #include "SourceCode.h"
 #include "support/Logger.h"
+#include "support/Trace.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/TokenKinds.h"
+#include "clang/Tooling/Syntax/Tokens.h"
 #include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/Path.h"
 
@@ -168,13 +171,40 @@
   return Result;
 }
 
+// Finds locations of all macros referenced from within the main file. This
+// includes references that were not yet expanded, like `BAR` in `#define FOO
+// BAR`.
+void findReferencedMacros(ParsedAST &AST, ReferencedLocations &Result) {
+  trace::Span Tracer("IncludeCleaner::findReferencedMacros");
+  auto &SM = AST.getSourceManager();
+  auto &PP = AST.getPreprocessor();
+  // FIXME(kirillbobyrev): The macros from the main file are collected in
+  // ParsedAST's MainFileMacros. However, we can't use it here because it
+  // doesn't handle macro references that were not expanded, e.g. in macro
+  // definitions or preprocessor-disabled sections.
+  //
+  // Extending MainFileMacros to collect missing references and switching to
+  // this mechanism (as opposed to iterating through all tokens) will improve
+  // the performance of findReferencedMacros and also improve other features
+  // relying on MainFileMacros.
+  for (const syntax::Token &Tok :
+   AST.getTokens().spelledTokens(SM.getMainFileID())) {
+auto Macro = locateMacroAt(Tok, PP);
+if (!Macro

[PATCH] D112447: [clangd] IncludeCleaner: Support macros

2021-10-27 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 382550.
kbobyrev added a comment.

Use IncludeCleaner to clean the includes and clean up a little.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112447/new/

https://reviews.llvm.org/D112447

Files:
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/clangd/SourceCode.cpp
  clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp

Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -116,6 +116,35 @@
   "struct ^X { enum ^Language { ^CXX = 42, Python = 9000}; };",
   "int Lang = X::CXX;",
   },
+  // Macros
+  {
+  "#define ^CONSTANT 42",
+  "int Foo = CONSTANT;",
+  },
+  {
+  "#define ^FOO x",
+  "#define BAR FOO",
+  },
+  {
+  "#define INNER 42\n"
+  "#define ^OUTER INNER",
+  "int answer = OUTER;",
+  },
+  {
+  "#define ^ANSWER 42\n"
+  "#define ^SQUARE(X) X * X",
+  "int sq = SQUARE(ANSWER);",
+  },
+  {
+  "#define ^FOO\n"
+  "#define ^BAR",
+  "#if 0\n"
+  "#if FOO\n"
+  "BAR\n"
+  "#endif\n"
+  "#endif",
+  },
+  // Misc
   {
   "enum class ^Color : int;",
   "enum class Color : int {};",
Index: clang-tools-extra/clangd/SourceCode.cpp
===
--- clang-tools-extra/clangd/SourceCode.cpp
+++ clang-tools-extra/clangd/SourceCode.cpp
@@ -975,6 +975,8 @@
 
 llvm::Optional locateMacroAt(const syntax::Token &SpelledTok,
Preprocessor &PP) {
+  if (SpelledTok.kind() != tok::identifier)
+return None;
   SourceLocation Loc = SpelledTok.location();
   assert(Loc.isFileID());
   const auto &SM = PP.getSourceManager();
Index: clang-tools-extra/clangd/IncludeCleaner.h
===
--- clang-tools-extra/clangd/IncludeCleaner.h
+++ clang-tools-extra/clangd/IncludeCleaner.h
@@ -33,11 +33,12 @@
 using ReferencedLocations = llvm::DenseSet;
 /// Finds locations of all symbols used in the main file.
 ///
-/// Uses RecursiveASTVisitor to go through main file AST and computes all the
-/// locations used symbols are coming from. Returned locations may be macro
-/// expansions, and are not resolved to their spelling/expansion location. These
-/// locations are later used to determine which headers should be marked as
-/// "used" and "directly used".
+/// - RecursiveASTVisitor finds references to symbols and records their
+///   associated locations. These may be macro expansions, and are not resolved
+///   to their spelling or expansion location. These locations are later used to
+///   determine which headers should be marked as "used" and "directly used".
+/// - We also examine all identifier tokens in the file in case they reference
+///   macros.
 ///
 /// We use this to compute unused headers, so we:
 ///
Index: clang-tools-extra/clangd/IncludeCleaner.cpp
===
--- clang-tools-extra/clangd/IncludeCleaner.cpp
+++ clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -11,8 +11,10 @@
 #include "Protocol.h"
 #include "SourceCode.h"
 #include "support/Logger.h"
+#include "support/Trace.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/Basic/SourceLocation.h"
+#include "clang/Tooling/Syntax/Tokens.h"
 #include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/Path.h"
 
@@ -168,13 +170,39 @@
   return Result;
 }
 
+// Finds locations of macros referenced from within the main file. That includes
+// references that were not yet expanded, e.g `BAR` in `#define FOO BAR`.
+void findReferencedMacros(ParsedAST &AST, ReferencedLocations &Result) {
+  trace::Span Tracer("IncludeCleaner::findReferencedMacros");
+  auto &SM = AST.getSourceManager();
+  auto &PP = AST.getPreprocessor();
+  // FIXME(kirillbobyrev): The macros from the main file are collected in
+  // ParsedAST's MainFileMacros. However, we can't use it here because it
+  // doesn't handle macro references that were not expanded, e.g. in macro
+  // definitions or preprocessor-disabled sections.
+  //
+  // Extending MainFileMacros to collect missing references and switching to
+  // this mechanism (as opposed to iterating through all tokens) will improve
+  // the performance of findReferencedMacros and also improve other features
+  // relying on MainFileMacros.
+  for (const syntax::Token &Tok :
+   AST.getTokens().spelledTokens(SM.getMainFileID())) {
+auto Macro = locateMacroAt(Tok, PP);
+if (!Macro)
+  continue;
+auto Loc = Macro->Info->getD

[clang-tools-extra] e3c6090 - [clangd] IncludeCleaner: Support macros

2021-10-27 Thread Kirill Bobyrev via cfe-commits

Author: Kirill Bobyrev
Date: 2021-10-27T10:30:04+02:00
New Revision: e3c6090e597685c23e9d2aac27d45c5a35b2f9bd

URL: 
https://github.com/llvm/llvm-project/commit/e3c6090e597685c23e9d2aac27d45c5a35b2f9bd
DIFF: 
https://github.com/llvm/llvm-project/commit/e3c6090e597685c23e9d2aac27d45c5a35b2f9bd.diff

LOG: [clangd] IncludeCleaner: Support macros

Collect the macro definition locations for all the macros used in the main
file.

Reviewed By: sammccall

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

Added: 


Modified: 
clang-tools-extra/clangd/IncludeCleaner.cpp
clang-tools-extra/clangd/IncludeCleaner.h
clang-tools-extra/clangd/SourceCode.cpp
clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/IncludeCleaner.cpp 
b/clang-tools-extra/clangd/IncludeCleaner.cpp
index af82c96e494a..95b4b2419cbe 100644
--- a/clang-tools-extra/clangd/IncludeCleaner.cpp
+++ b/clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -11,8 +11,10 @@
 #include "Protocol.h"
 #include "SourceCode.h"
 #include "support/Logger.h"
+#include "support/Trace.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/Basic/SourceLocation.h"
+#include "clang/Tooling/Syntax/Tokens.h"
 #include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/Path.h"
 
@@ -168,13 +170,39 @@ clangd::Range getDiagnosticRange(llvm::StringRef Code, 
unsigned HashOffset) {
   return Result;
 }
 
+// Finds locations of macros referenced from within the main file. That 
includes
+// references that were not yet expanded, e.g `BAR` in `#define FOO BAR`.
+void findReferencedMacros(ParsedAST &AST, ReferencedLocations &Result) {
+  trace::Span Tracer("IncludeCleaner::findReferencedMacros");
+  auto &SM = AST.getSourceManager();
+  auto &PP = AST.getPreprocessor();
+  // FIXME(kirillbobyrev): The macros from the main file are collected in
+  // ParsedAST's MainFileMacros. However, we can't use it here because it
+  // doesn't handle macro references that were not expanded, e.g. in macro
+  // definitions or preprocessor-disabled sections.
+  //
+  // Extending MainFileMacros to collect missing references and switching to
+  // this mechanism (as opposed to iterating through all tokens) will improve
+  // the performance of findReferencedMacros and also improve other features
+  // relying on MainFileMacros.
+  for (const syntax::Token &Tok :
+   AST.getTokens().spelledTokens(SM.getMainFileID())) {
+auto Macro = locateMacroAt(Tok, PP);
+if (!Macro)
+  continue;
+auto Loc = Macro->Info->getDefinitionLoc();
+if (Loc.isValid())
+  Result.insert(Loc);
+  }
+}
+
 } // namespace
 
 ReferencedLocations findReferencedLocations(ParsedAST &AST) {
   ReferencedLocations Result;
   ReferencedLocationCrawler Crawler(Result);
   Crawler.TraverseAST(AST.getASTContext());
-  // FIXME(kirillbobyrev): Handle macros.
+  findReferencedMacros(AST, Result);
   return Result;
 }
 

diff  --git a/clang-tools-extra/clangd/IncludeCleaner.h 
b/clang-tools-extra/clangd/IncludeCleaner.h
index 19d471e2e761..c7dd7efd4ed6 100644
--- a/clang-tools-extra/clangd/IncludeCleaner.h
+++ b/clang-tools-extra/clangd/IncludeCleaner.h
@@ -33,11 +33,12 @@ namespace clangd {
 using ReferencedLocations = llvm::DenseSet;
 /// Finds locations of all symbols used in the main file.
 ///
-/// Uses RecursiveASTVisitor to go through main file AST and computes all the
-/// locations used symbols are coming from. Returned locations may be macro
-/// expansions, and are not resolved to their spelling/expansion location. 
These
-/// locations are later used to determine which headers should be marked as
-/// "used" and "directly used".
+/// - RecursiveASTVisitor finds references to symbols and records their
+///   associated locations. These may be macro expansions, and are not resolved
+///   to their spelling or expansion location. These locations are later used 
to
+///   determine which headers should be marked as "used" and "directly used".
+/// - We also examine all identifier tokens in the file in case they reference
+///   macros.
 ///
 /// We use this to compute unused headers, so we:
 ///

diff  --git a/clang-tools-extra/clangd/SourceCode.cpp 
b/clang-tools-extra/clangd/SourceCode.cpp
index 014bdfc63281..16072f3803c5 100644
--- a/clang-tools-extra/clangd/SourceCode.cpp
+++ b/clang-tools-extra/clangd/SourceCode.cpp
@@ -975,6 +975,8 @@ llvm::Optional 
SpelledWord::touching(SourceLocation SpelledLoc,
 
 llvm::Optional locateMacroAt(const syntax::Token &SpelledTok,
Preprocessor &PP) {
+  if (SpelledTok.kind() != tok::identifier)
+return None;
   SourceLocation Loc = SpelledTok.location();
   assert(Loc.isFileID());
   const auto &SM = PP.getSourceManager();

diff  --git a/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp 
b/clang-tools-extra/clangd/unittests/IncludeCleane

[PATCH] D112447: [clangd] IncludeCleaner: Support macros

2021-10-27 Thread Kirill Bobyrev via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe3c6090e5976: [clangd] IncludeCleaner: Support macros 
(authored by kbobyrev).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112447/new/

https://reviews.llvm.org/D112447

Files:
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/clangd/SourceCode.cpp
  clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp

Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -116,6 +116,35 @@
   "struct ^X { enum ^Language { ^CXX = 42, Python = 9000}; };",
   "int Lang = X::CXX;",
   },
+  // Macros
+  {
+  "#define ^CONSTANT 42",
+  "int Foo = CONSTANT;",
+  },
+  {
+  "#define ^FOO x",
+  "#define BAR FOO",
+  },
+  {
+  "#define INNER 42\n"
+  "#define ^OUTER INNER",
+  "int answer = OUTER;",
+  },
+  {
+  "#define ^ANSWER 42\n"
+  "#define ^SQUARE(X) X * X",
+  "int sq = SQUARE(ANSWER);",
+  },
+  {
+  "#define ^FOO\n"
+  "#define ^BAR",
+  "#if 0\n"
+  "#if FOO\n"
+  "BAR\n"
+  "#endif\n"
+  "#endif",
+  },
+  // Misc
   {
   "enum class ^Color : int;",
   "enum class Color : int {};",
Index: clang-tools-extra/clangd/SourceCode.cpp
===
--- clang-tools-extra/clangd/SourceCode.cpp
+++ clang-tools-extra/clangd/SourceCode.cpp
@@ -975,6 +975,8 @@
 
 llvm::Optional locateMacroAt(const syntax::Token &SpelledTok,
Preprocessor &PP) {
+  if (SpelledTok.kind() != tok::identifier)
+return None;
   SourceLocation Loc = SpelledTok.location();
   assert(Loc.isFileID());
   const auto &SM = PP.getSourceManager();
Index: clang-tools-extra/clangd/IncludeCleaner.h
===
--- clang-tools-extra/clangd/IncludeCleaner.h
+++ clang-tools-extra/clangd/IncludeCleaner.h
@@ -33,11 +33,12 @@
 using ReferencedLocations = llvm::DenseSet;
 /// Finds locations of all symbols used in the main file.
 ///
-/// Uses RecursiveASTVisitor to go through main file AST and computes all the
-/// locations used symbols are coming from. Returned locations may be macro
-/// expansions, and are not resolved to their spelling/expansion location. These
-/// locations are later used to determine which headers should be marked as
-/// "used" and "directly used".
+/// - RecursiveASTVisitor finds references to symbols and records their
+///   associated locations. These may be macro expansions, and are not resolved
+///   to their spelling or expansion location. These locations are later used to
+///   determine which headers should be marked as "used" and "directly used".
+/// - We also examine all identifier tokens in the file in case they reference
+///   macros.
 ///
 /// We use this to compute unused headers, so we:
 ///
Index: clang-tools-extra/clangd/IncludeCleaner.cpp
===
--- clang-tools-extra/clangd/IncludeCleaner.cpp
+++ clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -11,8 +11,10 @@
 #include "Protocol.h"
 #include "SourceCode.h"
 #include "support/Logger.h"
+#include "support/Trace.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/Basic/SourceLocation.h"
+#include "clang/Tooling/Syntax/Tokens.h"
 #include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/Path.h"
 
@@ -168,13 +170,39 @@
   return Result;
 }
 
+// Finds locations of macros referenced from within the main file. That includes
+// references that were not yet expanded, e.g `BAR` in `#define FOO BAR`.
+void findReferencedMacros(ParsedAST &AST, ReferencedLocations &Result) {
+  trace::Span Tracer("IncludeCleaner::findReferencedMacros");
+  auto &SM = AST.getSourceManager();
+  auto &PP = AST.getPreprocessor();
+  // FIXME(kirillbobyrev): The macros from the main file are collected in
+  // ParsedAST's MainFileMacros. However, we can't use it here because it
+  // doesn't handle macro references that were not expanded, e.g. in macro
+  // definitions or preprocessor-disabled sections.
+  //
+  // Extending MainFileMacros to collect missing references and switching to
+  // this mechanism (as opposed to iterating through all tokens) will improve
+  // the performance of findReferencedMacros and also improve other features
+  // relying on MainFileMacros.
+  for (const syntax::Token &Tok :
+   AST.getTokens().spelledTokens(SM.getMainFileID())) {
+auto Macro = lo

[clang] 9fb52cb - [MLIR][OpenMP] Added omp.atomic.read and omp.atomic.write

2021-10-27 Thread Shraiysh Vaishay via cfe-commits

Author: Shraiysh Vaishay
Date: 2021-10-27T14:05:44+05:30
New Revision: 9fb52cb3f1235639a5a357fb5de18e1aeeb5b5f4

URL: 
https://github.com/llvm/llvm-project/commit/9fb52cb3f1235639a5a357fb5de18e1aeeb5b5f4
DIFF: 
https://github.com/llvm/llvm-project/commit/9fb52cb3f1235639a5a357fb5de18e1aeeb5b5f4.diff

LOG: [MLIR][OpenMP] Added omp.atomic.read and omp.atomic.write

This patch supports the atomic construct (read and write) following
section 2.17.7 of OpenMP 5.0 standard. Also added tests and
verifier for the same.

Reviewed By: kiranchandramohan

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

Added: 


Modified: 
clang/lib/CodeGen/CGStmtOpenMP.cpp
flang/lib/Semantics/check-omp-structure.cpp
llvm/include/llvm/Frontend/OpenMP/OMP.td
mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
mlir/test/Dialect/OpenMP/invalid.mlir
mlir/test/Dialect/OpenMP/ops.mlir

Removed: 




diff  --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp 
b/clang/lib/CodeGen/CGStmtOpenMP.cpp
index a3b509f91414a..991c9573f8973 100644
--- a/clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -5991,6 +5991,7 @@ static void emitOMPAtomicExpr(CodeGenFunction &CGF, 
OpenMPClauseKind Kind,
   case OMPC_when:
   case OMPC_adjust_args:
   case OMPC_append_args:
+  case OMPC_memory_order:
 llvm_unreachable("Clause is not allowed in 'omp atomic'.");
   }
 }

diff  --git a/flang/lib/Semantics/check-omp-structure.cpp 
b/flang/lib/Semantics/check-omp-structure.cpp
index d173d679d440e..919853792944a 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -1479,6 +1479,7 @@ CHECK_SIMPLE_CLAUSE(Filter, OMPC_filter)
 CHECK_SIMPLE_CLAUSE(When, OMPC_when)
 CHECK_SIMPLE_CLAUSE(AdjustArgs, OMPC_adjust_args)
 CHECK_SIMPLE_CLAUSE(AppendArgs, OMPC_append_args)
+CHECK_SIMPLE_CLAUSE(MemoryOrder, OMPC_memory_order)
 
 CHECK_REQ_SCALAR_INT_CLAUSE(Grainsize, OMPC_grainsize)
 CHECK_REQ_SCALAR_INT_CLAUSE(NumTasks, OMPC_num_tasks)

diff  --git a/llvm/include/llvm/Frontend/OpenMP/OMP.td 
b/llvm/include/llvm/Frontend/OpenMP/OMP.td
index 551ed6915162e..fffd8d75f6a71 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMP.td
+++ b/llvm/include/llvm/Frontend/OpenMP/OMP.td
@@ -144,6 +144,26 @@ def OMPC_Schedule : Clause<"schedule"> {
   ];
 }
 
+def OMP_MEMORY_ORDER_SeqCst : ClauseVal<"seq_cst", 1, 1> {}
+def OMP_MEMORY_ORDER_AcqRel : ClauseVal<"acq_rel", 2, 1> {}
+def OMP_MEMORY_ORDER_Acquire : ClauseVal<"acquire", 3, 1> {}
+def OMP_MEMORY_ORDER_Release : ClauseVal<"release", 4, 1> {}
+def OMP_MEMORY_ORDER_Relaxed : ClauseVal<"relaxed", 5, 1> {}
+def OMP_MEMORY_ORDER_Default : ClauseVal<"default", 6, 0> {
+  let isDefault = 1;
+}
+def OMPC_MemoryOrder : Clause<"memory_order"> {
+  let enumClauseValue = "MemoryOrderKind";
+  let allowedClauseValues = [
+OMP_MEMORY_ORDER_SeqCst,
+OMP_MEMORY_ORDER_AcqRel,
+OMP_MEMORY_ORDER_Acquire,
+OMP_MEMORY_ORDER_Release,
+OMP_MEMORY_ORDER_Relaxed,
+OMP_MEMORY_ORDER_Default
+  ];
+}
+
 def OMPC_Ordered : Clause<"ordered"> {
   let clangClass = "OMPOrderedClause";
   let flangClass = "ScalarIntConstantExpr";

diff  --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td 
b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
index 54649fd570efb..ed04dc4ca395d 100644
--- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
+++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
@@ -499,6 +499,37 @@ def TaskwaitOp : OpenMP_Op<"taskwait"> {
   let assemblyFormat = "attr-dict";
 }
 
+//===--===//
+// 2.17.7 atomic construct
+//===--===//
+
+// In the OpenMP Specification, atomic construct has an `atomic-clause` which
+// can take the values `read`, `write`, `update` and `capture`. These four
+// kinds of atomic constructs are fundamentally independent and are handled
+// separately while lowering. Having four separate operations (one for each
+// value of the clause) here decomposes handling of this construct into a
+// two-step process.
+
+def AtomicReadOp : OpenMP_Op<"atomic.read"> {
+  let arguments = (ins OpenMP_PointerLikeType:$address,
+   DefaultValuedAttr:$hint,
+   OptionalAttr:$memory_order);
+  let results = (outs AnyType);
+  let parser = [{ return parseAtomicReadOp(parser, result); }];
+  let printer = [{ return printAtomicReadOp(p, *this); }];
+  let verifier = [{ return verifyAtomicReadOp(*this); }];
+}
+
+def AtomicWriteOp : OpenMP_Op<"atomic.write"> {
+  let arguments = (ins OpenMP_PointerLikeType:$address,
+   AnyType:$value,
+   DefaultValuedAttr:$hint,
+   OptionalAttr:$memory_order);
+  let parser = [{ return parseAtomicWriteOp(parser, result); }];
+  let pr

[PATCH] D112565: [clangd] Add integration test for crash handling

2021-10-27 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added a comment.
This revision is now accepted and ready to land.

thanks, lgtm!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112565/new/

https://reviews.llvm.org/D112565

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112571: [clangd] IncludeCleaner: Don't warn on system headers

2021-10-27 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:258
   for (const auto *Inc : computeUnusedIncludes(AST)) {
+// FIXME(kirillbobyrev): Standard library headers are not handled correctly
+// now because the symbols are typically not directly defined in the

As discussed offline, I'm not sure this difference in behavior is as temporary 
or as narrow as we originally planned.

I think the reason we want this hack is:
 - umbrella headers need special handling
 - standard library headers are umbrella headers
 - system headers are likely to be standard library headers

But this is complicated by the fact that non-stdlib headers can be umbrella 
headers, system headers are likely to be umbrella headers even if not stdlib, 
stdlib needs different special handling from other umbrella headers, there are 
other headers (non-self-contained) that need special handling, etc.

Among other things, it's going to be hard to just turn this back on.

For now, I'd suggest extracting a function `mayConsiderUnused(const 
Inclusion&)` with the simple logic you have here for now, but we should come up 
with a more concrete plan soon.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112571/new/

https://reviews.llvm.org/D112571

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112600: [ARM] Use hardware TLS register in Thumb2 mode when -mtp=cp15 is passed

2021-10-27 Thread Ard Biesheuvel via Phabricator via cfe-commits
ardb created this revision.
ardb added reviewers: nickdesaulniers, nathanchance, psmith.
Herald added subscribers: hiraditya, kristof.beyls.
ardb requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

In ARM mode, passing -mtp=cp15 forces the use of an inline MRC system register 
read to move the thread pointer value into a register.

Currently, in Thumb2 mode, -mtp=cp15 is ignored, and a call to the 
__aeabi_read_tp helper is emitted instead.

This is inconsistent, and breaks the Linux/ARM build for Thumb2 targets, as the 
Linux kernel does not provide an implementation of __aeabi_read_tp,.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D112600

Files:
  clang/test/CodeGen/arm-tphard.c
  llvm/lib/Target/ARM/ARMInstrThumb.td
  llvm/lib/Target/ARM/ARMInstrThumb2.td


Index: llvm/lib/Target/ARM/ARMInstrThumb2.td
===
--- llvm/lib/Target/ARM/ARMInstrThumb2.td
+++ llvm/lib/Target/ARM/ARMInstrThumb2.td
@@ -4670,7 +4670,9 @@
   let DecoderNamespace = "Thumb2CoProc";
 }
 
-
+// Reading thread pointer from coprocessor register
+def : T2Pat<(ARMthread_pointer), (t2MRC 15, 0, 13, 0, 3)>,
+  Requires<[IsThumb2, IsReadTPHard]>;
 
 
//===--===//
 // ARMv8.1 Privilege Access Never extension
Index: llvm/lib/Target/ARM/ARMInstrThumb.td
===
--- llvm/lib/Target/ARM/ARMInstrThumb.td
+++ llvm/lib/Target/ARM/ARMInstrThumb.td
@@ -1520,6 +1520,7 @@
 let isCall = 1, Defs = [R0, R12, LR, CPSR], Uses = [SP] in
 def tTPsoft : tPseudoInst<(outs), (ins), 4, IIC_Br,
   [(set R0, ARMthread_pointer)]>,
+  Requires<[IsThumb, IsReadTPSoft]>,
   Sched<[WriteBr]>;
 
 
//===--===//
Index: clang/test/CodeGen/arm-tphard.c
===
--- /dev/null
+++ clang/test/CodeGen/arm-tphard.c
@@ -0,0 +1,10 @@
+// REQUIRES: arm-registered-target
+
+// RUN: %clang -target armv7-linux-gnueabihf -mtp=cp15 -S -o - %s | FileCheck 
%s
+// RUN: %clang -target armv7-linux-gnueabihf -mtp=cp15 -mthumb -S -o - %s | 
FileCheck %s
+
+void *tphard(void) {
+// CHECK-NOT: __aeabi_read_tp
+  return __builtin_thread_pointer();
+}
+


Index: llvm/lib/Target/ARM/ARMInstrThumb2.td
===
--- llvm/lib/Target/ARM/ARMInstrThumb2.td
+++ llvm/lib/Target/ARM/ARMInstrThumb2.td
@@ -4670,7 +4670,9 @@
   let DecoderNamespace = "Thumb2CoProc";
 }
 
-
+// Reading thread pointer from coprocessor register
+def : T2Pat<(ARMthread_pointer), (t2MRC 15, 0, 13, 0, 3)>,
+  Requires<[IsThumb2, IsReadTPHard]>;
 
 //===--===//
 // ARMv8.1 Privilege Access Never extension
Index: llvm/lib/Target/ARM/ARMInstrThumb.td
===
--- llvm/lib/Target/ARM/ARMInstrThumb.td
+++ llvm/lib/Target/ARM/ARMInstrThumb.td
@@ -1520,6 +1520,7 @@
 let isCall = 1, Defs = [R0, R12, LR, CPSR], Uses = [SP] in
 def tTPsoft : tPseudoInst<(outs), (ins), 4, IIC_Br,
   [(set R0, ARMthread_pointer)]>,
+  Requires<[IsThumb, IsReadTPSoft]>,
   Sched<[WriteBr]>;
 
 //===--===//
Index: clang/test/CodeGen/arm-tphard.c
===
--- /dev/null
+++ clang/test/CodeGen/arm-tphard.c
@@ -0,0 +1,10 @@
+// REQUIRES: arm-registered-target
+
+// RUN: %clang -target armv7-linux-gnueabihf -mtp=cp15 -S -o - %s | FileCheck %s
+// RUN: %clang -target armv7-linux-gnueabihf -mtp=cp15 -mthumb -S -o - %s | FileCheck %s
+
+void *tphard(void) {
+// CHECK-NOT: __aeabi_read_tp
+  return __builtin_thread_pointer();
+}
+
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112408: [WIP][RISCV] Add the zve extension according to the v1.0-rc2 spec

2021-10-27 Thread Yueh-Ting Chen via Phabricator via cfe-commits
eopXD added inline comments.



Comment at: llvm/lib/Support/RISCVISAInfo.cpp:735
   const StringMap> Implications = {
-{"v", {"zvlsseg", "zvl128b"}},
+{"v", {"zvlsseg", "zvl128b", "zve64d"}},
+

khchen wrote:
> please update implication rule based on 
> https://github.com/riscv/riscv-v-spec/issues/723#issuecomment-949542444
> 1. The Zve32f and Zve64f extensions depend upon the F extension
> 2. The Zve64d extension depends upon the D extension
> 3. The V extension depends upon the F and D
Thanks for the reminder. Addressed.



Comment at: llvm/test/CodeGen/RISCV/attributes.ll:8
 ; RUN: llc -mtriple=riscv32 -mattr=+c %s -o - | FileCheck --check-prefix=RV32C 
%s
-; RUN: llc -mtriple=riscv32 
-mattr=+experimental-v,+experimental-zvamo,+experimental-zvlsseg %s -o - | 
FileCheck --check-prefix=RV32V %s
+; RUN: llc -mtriple=riscv32 
-mattr=+f,+d,+experimental-v,+experimental-zvamo,+experimental-zvlsseg %s -o - 
| FileCheck --check-prefix=RV32V %s
 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zfh %s -o - | FileCheck 
--check-prefix=RV32ZFH %s

frasercrmck wrote:
> Why is this being changed in this patch?
You are right. This should not be changed.

Removed.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112408/new/

https://reviews.llvm.org/D112408

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112596: [clang-tidy] Correct typo in bugprone-easily-swappable-parameters

2021-10-27 Thread Whisperity via Phabricator via cfe-commits
whisperity added a comment.

100% typo. 😂 Aww 'chute... Bunch of rebases.
Yeah I didn't add extensive tests for simply the configuration, only for the 
configurations working.

Did you check the documentation file? It should mention the default values for 
the checker configuration options. Does it say `ForwardIt` there properly?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112596/new/

https://reviews.llvm.org/D112596

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112596: [clang-tidy] Correct typo in bugprone-easily-swappable-parameters

2021-10-27 Thread Salman Javed via Phabricator via cfe-commits
salman-javed-nz added a comment.

The documentation looks correct.
https://clang.llvm.org/extra/clang-tidy/checks/bugprone-easily-swappable-parameters.html

> By default, the following, and their lowercase-initial variants are ignored: 
> bool, It, Iterator, InputIt, ForwardIt, BidirIt, RandomIt, random_iterator, 
> ReverseIt, reverse_iterator, reverse_const_iterator, RandomIt, 
> random_iterator, ReverseIt, reverse_iterator, reverse_const_iterator, 
> Const_Iterator, ConstIterator, const_reverse_iterator, ConstReverseIterator. 
> In addition, _Bool (but not _bool) is also part of the default value.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112596/new/

https://reviews.llvm.org/D112596

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112596: [clang-tidy] Correct typo in bugprone-easily-swappable-parameters

2021-10-27 Thread Whisperity via Phabricator via cfe-commits
whisperity accepted this revision.
whisperity added a comment.
This revision is now accepted and ready to land.

Perfect! Have you obtained commit rights already, or should I go ahead and 
commit this?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112596/new/

https://reviews.llvm.org/D112596

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112408: [WIP][RISCV] Add the zve extension according to the v1.0-rc2 spec

2021-10-27 Thread Fraser Cormack via Phabricator via cfe-commits
frasercrmck added a comment.

I think the rest of my comments would be to do with `zvl` so I'll leave it 
there to avoid repetition.




Comment at: llvm/include/llvm/Support/RISCVISAInfo.h:65
+  unsigned getMinVLen() const { return MinVLen; }
+  unsigned getMaxEew() const { return MaxEew; }
+  unsigned getMaxEewFp() const { return MaxEewFp; }

Aside from the discussion about EEW vs. ELEN, something about the 
capitalization irks me. I realise we already have `XLen` but `Eew` looks... 
wrong. If other people disagree then that's fine.



Comment at: llvm/lib/Support/RISCVISAInfo.cpp:67
 {"zvlsseg", RISCVExtensionVersion{0, 10}},
+{"zvl32b", RISCVExtensionVersion{0, 10}},
+{"zvl64b", RISCVExtensionVersion{0, 10}},

Should this be in this patch? Or has some rebasing gone wrong and introduced 
code for D108694?



Comment at: llvm/lib/Support/RISCVISAInfo.cpp:733
+
+  {"zvl64b", {"zvl32b"}},
+  {"zvl128b", {"zvl64b"}},

Again, should `zvl` code be in this patch?



Comment at: llvm/lib/Support/RISCVISAInfo.cpp:765
+if (Implication != Implications.end()) {
+  for (auto ImpliedExtName : Implication->second) {
+if (WorkList.count(ImpliedExtName))

Really minor, but here you're using `auto` for `StringRef` but earlier and 
elsewhere it's `auto &`. I'm not sure which is preferred. Presumably 
`StringRef`s are cheap to copy and `auto` is fine? If `auto &` is more 
prominent in this file then go with that.



Comment at: llvm/lib/Support/RISCVISAInfo.cpp:787
 
+void RISCVISAInfo::updateMinVLen() {
+  for (auto &Ext : Exts) {

`zvl` patch?



Comment at: llvm/lib/Support/RISCVISAInfo.cpp:468
+
+  if (Error Result = ISAInfo->checkDependency())
+return std::move(Result);

I'm not the most familiar with this API, but do we really need to 
`checkDependency` here when it's done in the next line?



Comment at: llvm/lib/Support/RISCVISAInfo.cpp:696
+
+  if (Error Result = ISAInfo->checkDependency())
+return std::move(Result);

Same here. Duplicate `checkDependency`?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112408/new/

https://reviews.llvm.org/D112408

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112596: [clang-tidy] Correct typo in bugprone-easily-swappable-parameters

2021-10-27 Thread Salman Javed via Phabricator via cfe-commits
salman-javed-nz added a comment.

I have just received commit access, and this will be my first patch that I can 
commit on my own. 
I'll be in touch if I run into committing issues. Thanks for the review!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112596/new/

https://reviews.llvm.org/D112596

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112408: [WIP][RISCV] Add the zve extension according to the v1.0-rc2 spec

2021-10-27 Thread Yueh-Ting Chen via Phabricator via cfe-commits
eopXD added a comment.

Sorry I mixed zvl patch when rebasing. I will remove it ASAP.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112408/new/

https://reviews.llvm.org/D112408

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D108694: [WIP][RISCV] Add the zvl extension according to the v1.0-rc2 spec

2021-10-27 Thread Yueh-Ting Chen via Phabricator via cfe-commits
eopXD updated this revision to Diff 382571.
eopXD added a comment.

Add implication: v imply d and f


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D108694/new/

https://reviews.llvm.org/D108694

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  clang/test/Driver/riscv-arch.c
  clang/test/Preprocessor/riscv-target-features.c
  llvm/include/llvm/Support/RISCVISAInfo.h
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVSubtarget.cpp
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s

Index: llvm/test/MC/RISCV/attribute-arch.s
===
--- llvm/test/MC/RISCV/attribute-arch.s
+++ llvm/test/MC/RISCV/attribute-arch.s
@@ -34,7 +34,7 @@
 # CHECK: attribute  5, "rv32i2p0_m2p0_a2p0_f2p0_d2p0_c2p0"
 
 .attribute arch, "rv32iv"
-# CHECK: attribute  5, "rv32i2p0_v0p10_zvlsseg0p10"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
 
 .attribute arch, "rv32izba"
 # CHECK: attribute  5, "rv32i2p0_zba1p0"
@@ -70,7 +70,43 @@
 # CHECK: attribute  5, "rv32i2p0_f2p0_zfh0p1"
 
 .attribute arch, "rv32ivzvamo_zvlsseg"
-# CHECK: attribute  5, "rv32i2p0_v0p10_zvamo0p10_zvlsseg0p10"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvamo0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
 
 .attribute arch, "rv32iv_zvamo0p10_zvlsseg"
-# CHECK: attribute  5, "rv32i2p0_v0p10_zvamo0p10_zvlsseg0p10"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvamo0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl32b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl64b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl128b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl256b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl128b0p10_zvl256b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl512b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl128b0p10_zvl256b0p10_zvl32b0p10_zvl512b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl1024b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl256b0p10_zvl32b0p10_zvl512b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl2048b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl2048b0p10_zvl256b0p10_zvl32b0p10_zvl512b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl4096b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl2048b0p10_zvl256b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl8192b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl2048b0p10_zvl256b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvl8192b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl16384b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl16384b0p10_zvl2048b0p10_zvl256b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvl8192b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl32768b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl16384b0p10_zvl2048b0p10_zvl256b0p10_zvl32768b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvl8192b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl65536b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl16384b0p10_zvl2048b0p10_zvl256b0p10_zvl32768b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvl65536b0p10_zvl8192b0p10_zvlsseg0p10"
Index: llvm/test/CodeGen/RISCV/attributes.ll
===
--- llvm/test/CodeGen/RISCV/attributes.ll
+++ llvm/test/CodeGen/RISCV/attributes.ll
@@ -17,7 +17,7 @@
 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbr %s -o - | FileCheck --check-prefix=RV32ZBR %s
 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbs %s -o - | FileCheck --check-prefix=RV32ZBS %s
 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbt %s -o - | FileCheck --check-prefix=RV32ZBT %s
-; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbb,+experimental-zfh,+experimental-zvamo,+experimental-v,+f,+experimental-zvlsseg %s -o - | FileCheck --check-prefix=RV32COMBINED %s
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbb,+experimental-zfh,+experimental-zvamo,+experimental-v,+experimental-zvlsseg %s -o - | FileCheck --check-prefix=RV32COMBINED %s
 ; RUN: llc -mtriple=riscv64 -mattr=+m %s -o - | FileCheck --check-prefix=RV64M %s
 ; RUN: llc -mtriple=riscv64 -mattr=+a %s -o - | FileCheck --check-prefix=RV64A %s
 ; RUN: llc -mtriple=riscv64 -mattr=+f 

[PATCH] D112608: [clangd] IncludeCleaner: Do not process locations in built-in files

2021-10-27 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev created this revision.
kbobyrev added a reviewer: sammccall.
Herald added subscribers: usaxena95, arphaman.
kbobyrev requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Doing otherwise leads to crashing. Way to reproduce: open "gmock/gmock.h" in
the LLVM source tree.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D112608

Files:
  clang-tools-extra/clangd/IncludeCleaner.cpp


Index: clang-tools-extra/clangd/IncludeCleaner.cpp
===
--- clang-tools-extra/clangd/IncludeCleaner.cpp
+++ clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -133,7 +133,7 @@
   void add(SourceLocation Loc) { add(SM.getFileID(Loc), Loc); }
 
   void add(FileID FID, SourceLocation Loc) {
-if (FID.isInvalid())
+if (FID.isInvalid() || SM.isWrittenInBuiltinFile(Loc))
   return;
 assert(SM.isInFileID(Loc, FID));
 if (Loc.isFileID()) {


Index: clang-tools-extra/clangd/IncludeCleaner.cpp
===
--- clang-tools-extra/clangd/IncludeCleaner.cpp
+++ clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -133,7 +133,7 @@
   void add(SourceLocation Loc) { add(SM.getFileID(Loc), Loc); }
 
   void add(FileID FID, SourceLocation Loc) {
-if (FID.isInvalid())
+if (FID.isInvalid() || SM.isWrittenInBuiltinFile(Loc))
   return;
 assert(SM.isInFileID(Loc, FID));
 if (Loc.isFileID()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 897402e - [clang-tidy] Correct typo in bugprone-easily-swappable-parameters

2021-10-27 Thread Salman Javed via cfe-commits

Author: Salman Javed
Date: 2021-10-27T22:38:52+13:00
New Revision: 897402e95988d41d7be88075f80a35ecdbc10d52

URL: 
https://github.com/llvm/llvm-project/commit/897402e95988d41d7be88075f80a35ecdbc10d52
DIFF: 
https://github.com/llvm/llvm-project/commit/897402e95988d41d7be88075f80a35ecdbc10d52.diff

LOG: [clang-tidy] Correct typo in bugprone-easily-swappable-parameters

The string table `DefaultIgnoredParameterTypeSuffixes` has a typo:
`ForwardIt` is mistyped as `FowardIt`.

Correct typo and add test coverage.

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

Added: 

clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-ignore-default.cpp

Modified: 
clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
index 16ede76af6ab8..d111016ca3457 100644
--- a/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
@@ -40,7 +40,7 @@ static const std::string DefaultIgnoredParameterTypeSuffixes =
"inputit",
"InputIt",
"forwardit",
-   "FowardIt",
+   "ForwardIt",
"bidirit",
"BidirIt",
"constiterator",

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-ignore-default.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-ignore-default.cpp
new file mode 100644
index 0..624b9ddcb7390
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-ignore-default.cpp
@@ -0,0 +1,77 @@
+// RUN: %check_clang_tidy %s bugprone-easily-swappable-parameters %t --
+
+// Test that all of the default entries in the IgnoredParameterTypeSuffixes
+// option are indeed ignored.
+
+struct A {};
+
+namespace IgnoredTypes {
+using Bool = A;
+using _Bool = A;
+using it = A;
+using It = A;
+using iterator = A;
+using Iterator = A;
+using inputit = A;
+using InputIt = A;
+using forwardit = A;
+using ForwardIt = A;
+using bidirit = A;
+using BidirIt = A;
+using constiterator = A;
+using const_iterator = A;
+using Const_Iterator = A;
+using Constiterator = A;
+using ConstIterator = A;
+using RandomIt = A;
+using randomit = A;
+using random_iterator = A;
+using ReverseIt = A;
+using reverse_iterator = A;
+using reverse_const_iterator = A;
+using ConstReverseIterator = A;
+using Const_Reverse_Iterator = A;
+using const_reverse_iterator = A;
+using Constreverseiterator = A;
+using constreverseiterator = A;
+} // namespace IgnoredTypes
+
+// The types used here all have a suffix that is present in the default value 
of
+// IgnoredParameterTypeSuffixes, and should therefore be ignored:
+void f1(bool Foo, bool Bar) {}
+void f2(IgnoredTypes::Bool Foo, IgnoredTypes::Bool Bar) {}
+void f3(IgnoredTypes::_Bool Foo, IgnoredTypes::_Bool Bar) {}
+void f4(IgnoredTypes::it Foo, IgnoredTypes::it Bar) {}
+void f5(IgnoredTypes::It Foo, IgnoredTypes::It Bar) {}
+void f6(IgnoredTypes::iterator Foo, IgnoredTypes::iterator Bar) {}
+void f7(IgnoredTypes::Iterator Foo, IgnoredTypes::Iterator Bar) {}
+void f8(IgnoredTypes::inputit Foo, IgnoredTypes::inputit Bar) {}
+void f9(IgnoredTypes::InputIt Foo, IgnoredTypes::InputIt Bar) {}
+void f10(IgnoredTypes::forwardit Foo, IgnoredTypes::forwardit Bar) {}
+void f11(IgnoredTypes::ForwardIt Foo, IgnoredTypes::ForwardIt Bar) {}
+void f12(IgnoredTypes::bidirit Foo, IgnoredTypes::bidirit Bar) {}
+void f13(IgnoredTypes::BidirIt Foo, IgnoredTypes::BidirIt Bar) {}
+void f14(IgnoredTypes::constiterator Foo, IgnoredTypes::constiterator Bar) {}
+void f15(IgnoredTypes::const_iterator Foo, IgnoredTypes::const_iterator Bar) {}
+void f16(IgnoredTypes::Const_Iterator Foo, IgnoredTypes::Const_Iterator Bar) {}
+void f17(IgnoredTypes::Constiterator Foo, IgnoredTypes::Constiterator Bar) {}
+void f18(IgnoredTypes::ConstIterator Foo, IgnoredTypes::ConstIterator Bar) {}
+void f19(IgnoredTypes::RandomIt Foo, IgnoredTypes::RandomIt Bar) {}
+void f20(IgnoredTypes::randomit Foo, IgnoredTypes::randomit Bar) {}
+void f21(IgnoredTypes::random_iterator Foo, IgnoredTypes::random_iterator Bar) 
{}
+void f22(IgnoredTypes::ReverseIt Foo, IgnoredTypes::ReverseIt Bar) {}
+void f23(IgnoredTypes::reverse_iterator Foo, IgnoredTypes::reverse_iterator 
Bar) {}
+void f24(IgnoredTypes::reverse_const_iterator Foo, 
IgnoredTypes::reverse_const_iterator Bar) {}
+void f25(IgnoredTypes::ConstReverseIterator Foo, 
IgnoredTypes::ConstReverseIterator Bar) {}
+void f2

[PATCH] D112596: [clang-tidy] Correct typo in bugprone-easily-swappable-parameters

2021-10-27 Thread Salman Javed via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG897402e95988: [clang-tidy] Correct typo in 
bugprone-easily-swappable-parameters (authored by salman-javed-nz).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112596/new/

https://reviews.llvm.org/D112596

Files:
  clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-ignore-default.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-ignore-default.cpp
===
--- /dev/null
+++ 
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-ignore-default.cpp
@@ -0,0 +1,77 @@
+// RUN: %check_clang_tidy %s bugprone-easily-swappable-parameters %t --
+
+// Test that all of the default entries in the IgnoredParameterTypeSuffixes
+// option are indeed ignored.
+
+struct A {};
+
+namespace IgnoredTypes {
+using Bool = A;
+using _Bool = A;
+using it = A;
+using It = A;
+using iterator = A;
+using Iterator = A;
+using inputit = A;
+using InputIt = A;
+using forwardit = A;
+using ForwardIt = A;
+using bidirit = A;
+using BidirIt = A;
+using constiterator = A;
+using const_iterator = A;
+using Const_Iterator = A;
+using Constiterator = A;
+using ConstIterator = A;
+using RandomIt = A;
+using randomit = A;
+using random_iterator = A;
+using ReverseIt = A;
+using reverse_iterator = A;
+using reverse_const_iterator = A;
+using ConstReverseIterator = A;
+using Const_Reverse_Iterator = A;
+using const_reverse_iterator = A;
+using Constreverseiterator = A;
+using constreverseiterator = A;
+} // namespace IgnoredTypes
+
+// The types used here all have a suffix that is present in the default value 
of
+// IgnoredParameterTypeSuffixes, and should therefore be ignored:
+void f1(bool Foo, bool Bar) {}
+void f2(IgnoredTypes::Bool Foo, IgnoredTypes::Bool Bar) {}
+void f3(IgnoredTypes::_Bool Foo, IgnoredTypes::_Bool Bar) {}
+void f4(IgnoredTypes::it Foo, IgnoredTypes::it Bar) {}
+void f5(IgnoredTypes::It Foo, IgnoredTypes::It Bar) {}
+void f6(IgnoredTypes::iterator Foo, IgnoredTypes::iterator Bar) {}
+void f7(IgnoredTypes::Iterator Foo, IgnoredTypes::Iterator Bar) {}
+void f8(IgnoredTypes::inputit Foo, IgnoredTypes::inputit Bar) {}
+void f9(IgnoredTypes::InputIt Foo, IgnoredTypes::InputIt Bar) {}
+void f10(IgnoredTypes::forwardit Foo, IgnoredTypes::forwardit Bar) {}
+void f11(IgnoredTypes::ForwardIt Foo, IgnoredTypes::ForwardIt Bar) {}
+void f12(IgnoredTypes::bidirit Foo, IgnoredTypes::bidirit Bar) {}
+void f13(IgnoredTypes::BidirIt Foo, IgnoredTypes::BidirIt Bar) {}
+void f14(IgnoredTypes::constiterator Foo, IgnoredTypes::constiterator Bar) {}
+void f15(IgnoredTypes::const_iterator Foo, IgnoredTypes::const_iterator Bar) {}
+void f16(IgnoredTypes::Const_Iterator Foo, IgnoredTypes::Const_Iterator Bar) {}
+void f17(IgnoredTypes::Constiterator Foo, IgnoredTypes::Constiterator Bar) {}
+void f18(IgnoredTypes::ConstIterator Foo, IgnoredTypes::ConstIterator Bar) {}
+void f19(IgnoredTypes::RandomIt Foo, IgnoredTypes::RandomIt Bar) {}
+void f20(IgnoredTypes::randomit Foo, IgnoredTypes::randomit Bar) {}
+void f21(IgnoredTypes::random_iterator Foo, IgnoredTypes::random_iterator Bar) 
{}
+void f22(IgnoredTypes::ReverseIt Foo, IgnoredTypes::ReverseIt Bar) {}
+void f23(IgnoredTypes::reverse_iterator Foo, IgnoredTypes::reverse_iterator 
Bar) {}
+void f24(IgnoredTypes::reverse_const_iterator Foo, 
IgnoredTypes::reverse_const_iterator Bar) {}
+void f25(IgnoredTypes::ConstReverseIterator Foo, 
IgnoredTypes::ConstReverseIterator Bar) {}
+void f26(IgnoredTypes::Const_Reverse_Iterator Foo, 
IgnoredTypes::Const_Reverse_Iterator Bar) {}
+void f27(IgnoredTypes::const_reverse_iterator Foo, 
IgnoredTypes::const_reverse_iterator Bar) {}
+void f28(IgnoredTypes::Constreverseiterator Foo, 
IgnoredTypes::Constreverseiterator Bar) {}
+void f29(IgnoredTypes::constreverseiterator Foo, 
IgnoredTypes::constreverseiterator Bar) {}
+
+// This suffix of this type is not present in IgnoredParameterTypeSuffixes'
+// default value, therefore, a warning _should_ be generated.
+using ShouldNotBeIgnored = A;
+void f30(ShouldNotBeIgnored Foo, ShouldNotBeIgnored Bar) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: 2 adjacent parameters of 'f30' of 
similar type ('ShouldNotBeIgnored') are easily swapped by mistake 
[bugprone-easily-swappable-parameters]
+// CHECK-MESSAGES: :[[@LINE-2]]:29: note: the first parameter in the range is 
'Foo'
+// CHECK-MESSAGES: :[[@LINE-3]]:53: note: the last parameter in the range is 
'Bar'
Index: clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
@@ 

[PATCH] D108694: [WIP][RISCV] Add the zvl extension according to the v1.0-rc2 spec

2021-10-27 Thread Yueh-Ting Chen via Phabricator via cfe-commits
eopXD updated this revision to Diff 382574.
eopXD added a comment.

Address comments:

- remove duplicate `checkDependency()`
- stay consistent in my patch of using auto for `StringRef`


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D108694/new/

https://reviews.llvm.org/D108694

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  clang/test/Driver/riscv-arch.c
  clang/test/Preprocessor/riscv-target-features.c
  llvm/include/llvm/Support/RISCVISAInfo.h
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVSubtarget.cpp
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s

Index: llvm/test/MC/RISCV/attribute-arch.s
===
--- llvm/test/MC/RISCV/attribute-arch.s
+++ llvm/test/MC/RISCV/attribute-arch.s
@@ -34,7 +34,7 @@
 # CHECK: attribute  5, "rv32i2p0_m2p0_a2p0_f2p0_d2p0_c2p0"
 
 .attribute arch, "rv32iv"
-# CHECK: attribute  5, "rv32i2p0_v0p10_zvlsseg0p10"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
 
 .attribute arch, "rv32izba"
 # CHECK: attribute  5, "rv32i2p0_zba1p0"
@@ -70,7 +70,43 @@
 # CHECK: attribute  5, "rv32i2p0_f2p0_zfh0p1"
 
 .attribute arch, "rv32ivzvamo_zvlsseg"
-# CHECK: attribute  5, "rv32i2p0_v0p10_zvamo0p10_zvlsseg0p10"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvamo0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
 
 .attribute arch, "rv32iv_zvamo0p10_zvlsseg"
-# CHECK: attribute  5, "rv32i2p0_v0p10_zvamo0p10_zvlsseg0p10"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvamo0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl32b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl64b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl128b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl256b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl128b0p10_zvl256b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl512b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl128b0p10_zvl256b0p10_zvl32b0p10_zvl512b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl1024b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl256b0p10_zvl32b0p10_zvl512b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl2048b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl2048b0p10_zvl256b0p10_zvl32b0p10_zvl512b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl4096b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl2048b0p10_zvl256b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl8192b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl2048b0p10_zvl256b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvl8192b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl16384b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl16384b0p10_zvl2048b0p10_zvl256b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvl8192b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl32768b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl16384b0p10_zvl2048b0p10_zvl256b0p10_zvl32768b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvl8192b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl65536b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl16384b0p10_zvl2048b0p10_zvl256b0p10_zvl32768b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvl65536b0p10_zvl8192b0p10_zvlsseg0p10"
Index: llvm/test/CodeGen/RISCV/attributes.ll
===
--- llvm/test/CodeGen/RISCV/attributes.ll
+++ llvm/test/CodeGen/RISCV/attributes.ll
@@ -17,7 +17,7 @@
 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbr %s -o - | FileCheck --check-prefix=RV32ZBR %s
 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbs %s -o - | FileCheck --check-prefix=RV32ZBS %s
 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbt %s -o - | FileCheck --check-prefix=RV32ZBT %s
-; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbb,+experimental-zfh,+experimental-zvamo,+experimental-v,+f,+experimental-zvlsseg %s -o - | FileCheck --check-prefix=RV32COMBINED %s
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbb,+experimental-zfh,+experimental-zvamo,+experimental-v,+experimental-zvlsseg %s -o - | FileCheck --check-prefix=RV32COMBINED %s
 ; RUN: llc -mtriple=riscv64 -mattr=+m %s -o - | FileCheck --check-prefix=RV64M %s
 ; RUN: llc -mtriple=riscv64 -mattr=+

[PATCH] D112571: [clangd] IncludeCleaner: Don't warn on system headers

2021-10-27 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 382576.
kbobyrev marked an inline comment as done.
kbobyrev added a comment.

Resolve review comment.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112571/new/

https://reviews.llvm.org/D112571

Files:
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
  clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp


Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -206,6 +206,7 @@
 #include "dir/c.h"
 #include "dir/unused.h"
 #include "unused.h"
+#include 
 void foo() {
   a();
   b();
@@ -220,17 +221,17 @@
   TU.AdditionalFiles["dir/c.h"] = "void c();";
   TU.AdditionalFiles["unused.h"] = "void unused();";
   TU.AdditionalFiles["dir/unused.h"] = "void dirUnused();";
-  TU.AdditionalFiles["not_included.h"] = "void notIncluded();";
-  TU.ExtraArgs = {"-I" + testPath("dir")};
+  TU.AdditionalFiles["system/system_header.h"] = "";
+  TU.ExtraArgs.push_back("-I" + testPath("dir"));
+  TU.ExtraArgs.push_back("-isystem" + testPath("system"));
   TU.Code = MainFile.str();
   ParsedAST AST = TU.build();
-  auto UnusedIncludes = computeUnusedIncludes(AST);
-  std::vector UnusedHeaders;
-  UnusedHeaders.reserve(UnusedIncludes.size());
-  for (const auto &Include : UnusedIncludes)
-UnusedHeaders.push_back(Include->Written);
-  EXPECT_THAT(UnusedHeaders,
-  UnorderedElementsAre("\"unused.h\"", "\"dir/unused.h\""));
+  std::vector UnusedIncludes;
+  for (const auto &Include : computeUnusedIncludes(AST))
+UnusedIncludes.push_back(Include->Written);
+  EXPECT_THAT(UnusedIncludes,
+  UnorderedElementsAre("\"unused.h\"", "\"dir/unused.h\"",
+   ""));
 }
 
 TEST(IncludeCleaner, ScratchBuffer) {
Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -1483,7 +1483,9 @@
 TEST(DiagnosticsTest, IncludeCleaner) {
   Annotations Test(R"cpp(
 $fix[[  $diag[[#include "unused.h"]]
-]]  #include "used.h"
+]]#include "used.h"
+
+  #include 
 
   void foo() {
 used();
@@ -1497,6 +1499,8 @@
   TU.AdditionalFiles["used.h"] = R"cpp(
 void used() {}
   )cpp";
+  TU.AdditionalFiles["system/system_header.h"] = "";
+  TU.ExtraArgs = {"-isystem" + testPath("system")};
   // Off by default.
   EXPECT_THAT(*TU.build().getDiagnostics(), IsEmpty());
   Config Cfg;
Index: clang-tools-extra/clangd/IncludeCleaner.cpp
===
--- clang-tools-extra/clangd/IncludeCleaner.cpp
+++ clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -196,6 +196,14 @@
   }
 }
 
+// FIXME(kirillbobyrev): We currently do not support the umbrella headers.
+// Standard Library headers are typically umbrella headers, and system headers
+// are likely to be the Standard Library headers. Until we have a good support
+// for umbrella headers and Standard Library headers, don't warn about them.
+bool mayConsiderUnused(const Inclusion *Inc) {
+  return Inc->Written.front() != '<';
+}
+
 } // namespace
 
 ReferencedLocations findReferencedLocations(ParsedAST &AST) {
@@ -283,6 +291,8 @@
   ->getName()
   .str();
   for (const auto *Inc : computeUnusedIncludes(AST)) {
+if (!mayConsiderUnused(Inc))
+  continue;
 Diag D;
 D.Message =
 llvm::formatv("included header {0} is not used",


Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -206,6 +206,7 @@
 #include "dir/c.h"
 #include "dir/unused.h"
 #include "unused.h"
+#include 
 void foo() {
   a();
   b();
@@ -220,17 +221,17 @@
   TU.AdditionalFiles["dir/c.h"] = "void c();";
   TU.AdditionalFiles["unused.h"] = "void unused();";
   TU.AdditionalFiles["dir/unused.h"] = "void dirUnused();";
-  TU.AdditionalFiles["not_included.h"] = "void notIncluded();";
-  TU.ExtraArgs = {"-I" + testPath("dir")};
+  TU.AdditionalFiles["system/system_header.h"] = "";
+  TU.ExtraArgs.push_back("-I" + testPath("dir"));
+  TU.ExtraArgs.push_back("-isystem" + testPath("system"));
   TU.Code = MainFile.str();
   ParsedAST AST = TU.build();
-  auto UnusedIncludes = computeUnusedIncludes(AST);
-  std::vector UnusedHeaders;
-  UnusedHeaders.reserve(UnusedIncludes.size());
-  for (const auto &Include : UnusedIncludes)
-UnusedHeaders.push_back(Include->Written);
-  EXPECT_THAT(UnusedHeaders,
- 

[PATCH] D112571: [clangd] IncludeCleaner: Don't warn on system headers

2021-10-27 Thread Kirill Bobyrev via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc4723785c190: [clangd] IncludeCleaner: Don't warn on 
system headers (authored by kbobyrev).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112571/new/

https://reviews.llvm.org/D112571

Files:
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
  clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp


Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -206,6 +206,7 @@
 #include "dir/c.h"
 #include "dir/unused.h"
 #include "unused.h"
+#include 
 void foo() {
   a();
   b();
@@ -220,17 +221,17 @@
   TU.AdditionalFiles["dir/c.h"] = "void c();";
   TU.AdditionalFiles["unused.h"] = "void unused();";
   TU.AdditionalFiles["dir/unused.h"] = "void dirUnused();";
-  TU.AdditionalFiles["not_included.h"] = "void notIncluded();";
-  TU.ExtraArgs = {"-I" + testPath("dir")};
+  TU.AdditionalFiles["system/system_header.h"] = "";
+  TU.ExtraArgs.push_back("-I" + testPath("dir"));
+  TU.ExtraArgs.push_back("-isystem" + testPath("system"));
   TU.Code = MainFile.str();
   ParsedAST AST = TU.build();
-  auto UnusedIncludes = computeUnusedIncludes(AST);
-  std::vector UnusedHeaders;
-  UnusedHeaders.reserve(UnusedIncludes.size());
-  for (const auto &Include : UnusedIncludes)
-UnusedHeaders.push_back(Include->Written);
-  EXPECT_THAT(UnusedHeaders,
-  UnorderedElementsAre("\"unused.h\"", "\"dir/unused.h\""));
+  std::vector UnusedIncludes;
+  for (const auto &Include : computeUnusedIncludes(AST))
+UnusedIncludes.push_back(Include->Written);
+  EXPECT_THAT(UnusedIncludes,
+  UnorderedElementsAre("\"unused.h\"", "\"dir/unused.h\"",
+   ""));
 }
 
 TEST(IncludeCleaner, ScratchBuffer) {
Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -1483,7 +1483,9 @@
 TEST(DiagnosticsTest, IncludeCleaner) {
   Annotations Test(R"cpp(
 $fix[[  $diag[[#include "unused.h"]]
-]]  #include "used.h"
+]]#include "used.h"
+
+  #include 
 
   void foo() {
 used();
@@ -1497,6 +1499,8 @@
   TU.AdditionalFiles["used.h"] = R"cpp(
 void used() {}
   )cpp";
+  TU.AdditionalFiles["system/system_header.h"] = "";
+  TU.ExtraArgs = {"-isystem" + testPath("system")};
   // Off by default.
   EXPECT_THAT(*TU.build().getDiagnostics(), IsEmpty());
   Config Cfg;
Index: clang-tools-extra/clangd/IncludeCleaner.cpp
===
--- clang-tools-extra/clangd/IncludeCleaner.cpp
+++ clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -196,6 +196,14 @@
   }
 }
 
+// FIXME(kirillbobyrev): We currently do not support the umbrella headers.
+// Standard Library headers are typically umbrella headers, and system headers
+// are likely to be the Standard Library headers. Until we have a good support
+// for umbrella headers and Standard Library headers, don't warn about them.
+bool mayConsiderUnused(const Inclusion *Inc) {
+  return Inc->Written.front() != '<';
+}
+
 } // namespace
 
 ReferencedLocations findReferencedLocations(ParsedAST &AST) {
@@ -283,6 +291,8 @@
   ->getName()
   .str();
   for (const auto *Inc : computeUnusedIncludes(AST)) {
+if (!mayConsiderUnused(Inc))
+  continue;
 Diag D;
 D.Message =
 llvm::formatv("included header {0} is not used",


Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -206,6 +206,7 @@
 #include "dir/c.h"
 #include "dir/unused.h"
 #include "unused.h"
+#include 
 void foo() {
   a();
   b();
@@ -220,17 +221,17 @@
   TU.AdditionalFiles["dir/c.h"] = "void c();";
   TU.AdditionalFiles["unused.h"] = "void unused();";
   TU.AdditionalFiles["dir/unused.h"] = "void dirUnused();";
-  TU.AdditionalFiles["not_included.h"] = "void notIncluded();";
-  TU.ExtraArgs = {"-I" + testPath("dir")};
+  TU.AdditionalFiles["system/system_header.h"] = "";
+  TU.ExtraArgs.push_back("-I" + testPath("dir"));
+  TU.ExtraArgs.push_back("-isystem" + testPath("system"));
   TU.Code = MainFile.str();
   ParsedAST AST = TU.build();
-  auto UnusedIncludes = computeUnusedIncludes(AST);
-  std::vector UnusedHeaders;
-  UnusedHeaders.reserve(UnusedIncludes.size());
-  for (const auto &Include : 

[clang-tools-extra] c472378 - [clangd] IncludeCleaner: Don't warn on system headers

2021-10-27 Thread Kirill Bobyrev via cfe-commits

Author: Kirill Bobyrev
Date: 2021-10-27T11:51:08+02:00
New Revision: c4723785c1902d6a53f3808fa1dabb2a97c1cc6e

URL: 
https://github.com/llvm/llvm-project/commit/c4723785c1902d6a53f3808fa1dabb2a97c1cc6e
DIFF: 
https://github.com/llvm/llvm-project/commit/c4723785c1902d6a53f3808fa1dabb2a97c1cc6e.diff

LOG: [clangd] IncludeCleaner: Don't warn on system headers

This is a temporary hack to disable diagnostics for system headers. As of right
now, IncludeCleaner does not handle the Standard Library correctly and will
report most system headers as unused because very few symbols are defined in
top-level system headers. This will eventually be fixed, but for now we are
aiming for the most conservative approach with as little false-positive
warnings as possible. After the initial prototype and core functionality is
polished, I will turn back to handling the Standard Library as it requires
custom logic.

Reviewed By: sammccall

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

Added: 


Modified: 
clang-tools-extra/clangd/IncludeCleaner.cpp
clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/IncludeCleaner.cpp 
b/clang-tools-extra/clangd/IncludeCleaner.cpp
index 95b4b2419cbe..cc69fdaa5e41 100644
--- a/clang-tools-extra/clangd/IncludeCleaner.cpp
+++ b/clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -196,6 +196,14 @@ void findReferencedMacros(ParsedAST &AST, 
ReferencedLocations &Result) {
   }
 }
 
+// FIXME(kirillbobyrev): We currently do not support the umbrella headers.
+// Standard Library headers are typically umbrella headers, and system headers
+// are likely to be the Standard Library headers. Until we have a good support
+// for umbrella headers and Standard Library headers, don't warn about them.
+bool mayConsiderUnused(const Inclusion *Inc) {
+  return Inc->Written.front() != '<';
+}
+
 } // namespace
 
 ReferencedLocations findReferencedLocations(ParsedAST &AST) {
@@ -283,6 +291,8 @@ std::vector issueUnusedIncludesDiagnostics(ParsedAST 
&AST,
   ->getName()
   .str();
   for (const auto *Inc : computeUnusedIncludes(AST)) {
+if (!mayConsiderUnused(Inc))
+  continue;
 Diag D;
 D.Message =
 llvm::formatv("included header {0} is not used",

diff  --git a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp 
b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
index c3c56bdbbe03..4d269684b65a 100644
--- a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -1483,7 +1483,9 @@ TEST(Diagnostics, Tags) {
 TEST(DiagnosticsTest, IncludeCleaner) {
   Annotations Test(R"cpp(
 $fix[[  $diag[[#include "unused.h"]]
-]]  #include "used.h"
+]]#include "used.h"
+
+  #include 
 
   void foo() {
 used();
@@ -1497,6 +1499,8 @@ TEST(DiagnosticsTest, IncludeCleaner) {
   TU.AdditionalFiles["used.h"] = R"cpp(
 void used() {}
   )cpp";
+  TU.AdditionalFiles["system/system_header.h"] = "";
+  TU.ExtraArgs = {"-isystem" + testPath("system")};
   // Off by default.
   EXPECT_THAT(*TU.build().getDiagnostics(), IsEmpty());
   Config Cfg;

diff  --git a/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp 
b/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
index 38cd8da23066..aeb76f8dee22 100644
--- a/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ b/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -206,6 +206,7 @@ TEST(IncludeCleaner, GetUnusedHeaders) {
 #include "dir/c.h"
 #include "dir/unused.h"
 #include "unused.h"
+#include 
 void foo() {
   a();
   b();
@@ -220,17 +221,17 @@ TEST(IncludeCleaner, GetUnusedHeaders) {
   TU.AdditionalFiles["dir/c.h"] = "void c();";
   TU.AdditionalFiles["unused.h"] = "void unused();";
   TU.AdditionalFiles["dir/unused.h"] = "void dirUnused();";
-  TU.AdditionalFiles["not_included.h"] = "void notIncluded();";
-  TU.ExtraArgs = {"-I" + testPath("dir")};
+  TU.AdditionalFiles["system/system_header.h"] = "";
+  TU.ExtraArgs.push_back("-I" + testPath("dir"));
+  TU.ExtraArgs.push_back("-isystem" + testPath("system"));
   TU.Code = MainFile.str();
   ParsedAST AST = TU.build();
-  auto UnusedIncludes = computeUnusedIncludes(AST);
-  std::vector UnusedHeaders;
-  UnusedHeaders.reserve(UnusedIncludes.size());
-  for (const auto &Include : UnusedIncludes)
-UnusedHeaders.push_back(Include->Written);
-  EXPECT_THAT(UnusedHeaders,
-  UnorderedElementsAre("\"unused.h\"", "\"dir/unused.h\""));
+  std::vector UnusedIncludes;
+  for (const auto &Include : computeUnusedIncludes(AST))
+UnusedIncludes.push_back(Include->Written);
+  EXPECT_THAT(UnusedIncludes,
+  UnorderedElementsAre("\"unused.h\"", "\"dir/unused.h\"",
+   ""));
 }
 
 TEST(Inc

[clang-tools-extra] 9cc08cb - [clangd] Add integration test for crash handling

2021-10-27 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2021-10-27T11:52:31+02:00
New Revision: 9cc08cb02fdc4f8a2b717519c3bf33b4ed3070e4

URL: 
https://github.com/llvm/llvm-project/commit/9cc08cb02fdc4f8a2b717519c3bf33b4ed3070e4
DIFF: 
https://github.com/llvm/llvm-project/commit/9cc08cb02fdc4f8a2b717519c3bf33b4ed3070e4.diff

LOG: [clangd] Add integration test for crash handling

This replaces the test removed in 51be7061d025139ba66869d5d99c7157a3ae9edd
It is more principled and tests more critical cases: a crash while parsing.

We need two pieces of plumbing:
 - a way to re-enable the crashing #pragmas via a flag, to test parse crashes
 - a bit of reshuffling around ASTWorker execution so that we set up the
   crash handler in both sync/async modes.
   Sync mode is useful for debugging, so I tested both.

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

Added: 
clang-tools-extra/clangd/test/crash-parse.test
clang-tools-extra/clangd/test/crash-preamble.test

Modified: 
clang-tools-extra/clangd/Compiler.cpp
clang-tools-extra/clangd/Compiler.h
clang-tools-extra/clangd/TUScheduler.cpp
clang-tools-extra/clangd/tool/ClangdMain.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Compiler.cpp 
b/clang-tools-extra/clangd/Compiler.cpp
index 809119cda6b1a..cdc29198d434f 100644
--- a/clang-tools-extra/clangd/Compiler.cpp
+++ b/clang-tools-extra/clangd/Compiler.cpp
@@ -42,6 +42,9 @@ void 
IgnoreDiagnostics::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
   IgnoreDiagnostics::log(DiagLevel, Info);
 }
 
+static bool AllowCrashPragmasForTest = false;
+void allowCrashPragmasForTest() { AllowCrashPragmasForTest = true; }
+
 void disableUnsupportedOptions(CompilerInvocation &CI) {
   // Disable "clang -verify" diagnostics, they are rarely useful in clangd, and
   // our compiler invocation set-up doesn't seem to work with it (leading
@@ -66,7 +69,8 @@ void disableUnsupportedOptions(CompilerInvocation &CI) {
   CI.getPreprocessorOpts().PCHWithHdrStop = false;
   CI.getPreprocessorOpts().PCHWithHdrStopCreate = false;
   // Don't crash on `#pragma clang __debug parser_crash`
-  CI.getPreprocessorOpts().DisablePragmaDebugCrash = true;
+  if (!AllowCrashPragmasForTest)
+CI.getPreprocessorOpts().DisablePragmaDebugCrash = true;
 
   // Always default to raw container format as clangd doesn't registry any 
other
   // and clang dies when faced with unknown formats.

diff  --git a/clang-tools-extra/clangd/Compiler.h 
b/clang-tools-extra/clangd/Compiler.h
index b46765f6813ad..67b92c564550d 100644
--- a/clang-tools-extra/clangd/Compiler.h
+++ b/clang-tools-extra/clangd/Compiler.h
@@ -87,6 +87,10 @@ std::unique_ptr prepareCompilerInstance(
 std::unique_ptr MainFile,
 IntrusiveRefCntPtr, DiagnosticConsumer &);
 
+/// Respect `#pragma clang __debug crash` etc, which are usually disabled.
+/// This may only be called before threads are spawned.
+void allowCrashPragmasForTest();
+
 } // namespace clangd
 } // namespace clang
 

diff  --git a/clang-tools-extra/clangd/TUScheduler.cpp 
b/clang-tools-extra/clangd/TUScheduler.cpp
index 8d696b00084fe..afaf6ed780b0c 100644
--- a/clang-tools-extra/clangd/TUScheduler.cpp
+++ b/clang-tools-extra/clangd/TUScheduler.cpp
@@ -589,6 +589,8 @@ class ASTWorker {
   void startTask(llvm::StringRef Name, llvm::unique_function Task,
  llvm::Optional Update,
  TUScheduler::ASTActionInvalidation);
+  /// Runs a task synchronously.
+  void runTask(llvm::StringRef Name, llvm::function_ref Task);
 
   /// Determines the next action to perform.
   /// All actions that should never run are discarded.
@@ -1025,7 +1027,7 @@ void 
ASTWorker::updatePreamble(std::unique_ptr CI,
 generateDiagnostics(std::move(CI), std::move(PI), std::move(CIDiags));
   };
   if (RunSync) {
-Task();
+runTask(TaskName, Task);
 return;
   }
   {
@@ -1195,15 +1197,23 @@ void ASTWorker::stop() {
   RequestsCV.notify_all();
 }
 
+void ASTWorker::runTask(llvm::StringRef Name, llvm::function_ref Task) 
{
+  ThreadCrashReporter ScopedReporter([this, Name]() {
+llvm::errs() << "Signalled during AST worker action: " << Name << "\n";
+crashDumpParseInputs(llvm::errs(), FileInputs);
+  });
+  trace::Span Tracer(Name);
+  WithContext WithProvidedContext(ContextProvider(FileName));
+  Task();
+}
+
 void ASTWorker::startTask(llvm::StringRef Name,
   llvm::unique_function Task,
   llvm::Optional Update,
   TUScheduler::ASTActionInvalidation Invalidation) {
   if (RunSync) {
 assert(!Done && "running a task after stop()");
-trace::Span Tracer(Name + ":" + llvm::sys::path::filename(FileName));
-WithContext WithProvidedContext(ContextProvider(FileName));
-Task();
+runTask(Name, Task);
 return;
   }
 
@@ -1323,18 +1333,11 @@ void ASTWorker::run() {
 Lock.lock();
   }
   WithContext Guard(

[PATCH] D112565: [clangd] Add integration test for crash handling

2021-10-27 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9cc08cb02fdc: [clangd] Add integration test for crash 
handling (authored by sammccall).

Changed prior to commit:
  https://reviews.llvm.org/D112565?vs=382407&id=382579#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112565/new/

https://reviews.llvm.org/D112565

Files:
  clang-tools-extra/clangd/Compiler.cpp
  clang-tools-extra/clangd/Compiler.h
  clang-tools-extra/clangd/TUScheduler.cpp
  clang-tools-extra/clangd/test/crash-parse.test
  clang-tools-extra/clangd/test/crash-preamble.test
  clang-tools-extra/clangd/tool/ClangdMain.cpp

Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -8,6 +8,7 @@
 
 #include "ClangdLSPServer.h"
 #include "CodeComplete.h"
+#include "Compiler.h"
 #include "Config.h"
 #include "ConfigProvider.h"
 #include "Feature.h"
@@ -344,12 +345,20 @@
 "lit-test",
 cat(Misc),
 desc("Abbreviation for -input-style=delimited -pretty -sync "
- "-enable-test-scheme -enable-config=0 -log=verbose. "
+ "-enable-test-scheme -enable-config=0 -log=verbose -crash-pragmas. "
  "Intended to simplify lit tests"),
 init(false),
 Hidden,
 };
 
+opt CrashPragmas{
+"crash-pragmas",
+cat(Misc),
+desc("Respect `#pragma clang __debug crash` and friends."),
+init(false),
+Hidden,
+};
+
 opt CheckFile{
 "check",
 cat(Misc),
@@ -707,7 +716,10 @@
   llvm::cl::ParseCommandLineOptions(argc, argv, Overview,
 /*Errs=*/nullptr, FlagsEnvVar);
   if (Test) {
-Sync = true;
+if (!Sync.getNumOccurrences())
+  Sync = true;
+if (!CrashPragmas.getNumOccurrences())
+  CrashPragmas = true;
 InputStyle = JSONStreamStyle::Delimited;
 LogLevel = Logger::Verbose;
 PrettyPrint = true;
@@ -725,6 +737,8 @@
 static URISchemeRegistry::Add X(
 "test", "Test scheme for clangd lit tests.");
   }
+  if (CrashPragmas)
+allowCrashPragmasForTest();
 
   if (!Sync && WorkerThreadsCount == 0) {
 llvm::errs() << "A number of worker threads cannot be 0. Did you mean to "
Index: clang-tools-extra/clangd/test/crash-preamble.test
===
--- /dev/null
+++ clang-tools-extra/clangd/test/crash-preamble.test
@@ -0,0 +1,19 @@
+# RUN: not --crash clangd -lit-test < %s 2> %t.err
+# RUN: FileCheck %s < %t.err --check-prefixes=CHECK,CHECK-SYNC
+# RUN: not --crash clangd -lit-test -sync=0 < %s 2> %t.async.err
+# RUN: FileCheck %s < %t.async.err
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{}}
+---
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{
+  "uri":"test:///foo.cc",
+  "languageId":"cpp",
+  "text":"#pragma clang __debug llvm_fatal_error"
+}}}
+---
+{"jsonrpc":"2.0","id":1,"method":"sync","params":{}}
+#  CHECK:  Signalled while building preamble
+# CHECK-NEXT:  Filename: foo.cc
+# CHECK-SYNC: Signalled during AST worker action: Update
+# CHECK-SYNC:   Filename: foo.cc
+# CHECK-SYNC: Signalled while processing message:
+# CHECK-SYNC:   "languageId":"cpp"
Index: clang-tools-extra/clangd/test/crash-parse.test
===
--- /dev/null
+++ clang-tools-extra/clangd/test/crash-parse.test
@@ -0,0 +1,19 @@
+# RUN: not --crash clangd -lit-test < %s 2> %t.err
+# RUN: FileCheck %s < %t.err --check-prefixes=CHECK,CHECK-SYNC
+# RUN: not --crash clangd -lit-test -sync=0 < %s 2> %t.async.err
+# RUN: FileCheck %s < %t.async.err
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{}}
+---
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{
+  "uri":"test:///foo.cc",
+  "languageId":"cpp",
+  "text":"int x;\n#pragma clang __debug llvm_fatal_error"
+}}}
+---
+{"jsonrpc":"2.0","id":1,"method":"sync","params":{}}
+#  CHECK: Signalled during AST worker action: Build AST
+# CHECK-NEXT:   Filename: foo.cc
+# CHECK-SYNC: Signalled during AST worker action: Update
+# CHECK-SYNC:   Filename: foo.cc
+# CHECK-SYNC: Signalled while processing message:
+# CHECK-SYNC:   "languageId":"cpp"
Index: clang-tools-extra/clangd/TUScheduler.cpp
===
--- clang-tools-extra/clangd/TUScheduler.cpp
+++ clang-tools-extra/clangd/TUScheduler.cpp
@@ -589,6 +589,8 @@
   void startTask(llvm::StringRef Name, llvm::unique_function Task,
  llvm::Optional Update,
  TUScheduler::ASTActionInvalidation);
+  /// Runs a task synchronously.
+  void runTask(llvm::StringRef Name, llvm::function_ref Task);
 
   /// Determines the next action to perform.
   /// All actions that should never run are discarded.
@@ -1025,7 +1027,7 @@
 generateDiagnostics(std::move(CI), s

[PATCH] D112409: [clang-tidy] Add check 'cert-err33-c'.

2021-10-27 Thread Whisperity via Phabricator via cfe-commits
whisperity added inline comments.



Comment at: clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp:45-50
+// The following functions are
+// deliberately excluded because they can
+// be called with NULL argument and in
+// this case the check is not applicable:
+// mblen, mbrlen, mbrtowc, mbtowc, wctomb,
+// wctomb_s

aaron.ballman wrote:
> Pretty sure this comment can be re-flowed to 80 columns. Also needs trailing 
> punctuation.
Shouldn't we reuse `utils::options::serializeStringList` here instead of 
hardcoding the separator character into a giant literal? I know executing that 
operation has an associated run-time cost, and as it is not `constexpr` it 
needs to be done somewhere else, and `std::string` could throw so we can't do 
it at "static initialisation" time... But having those extra chars there just 
seems way too fragile at a later modification. We've had cases where people 
missed separating `,`s even -- and those are syntactically highlighted 
differently due to being outside the string literal.

Suggestion:

 * An array of `StringRef`s or even `llvm::StringLiteral`s containing the 
individual function names. Array separated with `,`, the separator outside the 
literal. Aligned to column and probably one per line.
 * When using this variable later (🌟), instead of passing the stringref, pass 
the result of `serializeStringList`.



Comment at: clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp:325
 Opts["cert-str34-c.DiagnoseSignedUnsignedCharComparisons"] = "false";
+Opts["cert-err33-c.CheckedFunctions"] = CertErr33CCheckedFunctions;
 return Options;

(🌟)



Comment at: clang-tools-extra/docs/clang-tidy/checks/cert-err33-c.rst:11
+
+* aligned_alloc()
+* asctime_s()

`mblen`, `mbrlen`, etc. are with backticks later. But this list isn't. Was this 
intended?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112409/new/

https://reviews.llvm.org/D112409

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112296: [Analyzer][solver] Handle adjustments in constraint assignor remainder

2021-10-27 Thread Gabor Marton via Phabricator via cfe-commits
martong marked 4 inline comments as done.
martong added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp:44-49
+// Handle adjustment with non-comparison ops.
+const llvm::APSInt &Zero = getBasicVals().getValue(0, SIE->getType());
+if (Assumption) {
+  return assumeSymRel(State, SIE, BO_NE, Zero);
+}
+return assumeSymRel(State, SIE, BO_EQ, Zero);

ASDenysPetrov wrote:
> Actually what you are trying to do here is already inside 
> `assumeSymUnsupported` and it will work for all `SymIntExpr`.
> Please, proveide a test case which works with `assumeSymRel` and doesn't with 
> `asume` from the previous change. That is what we are trying to fix here.
Thanks for suggesting the use of the ternary op, the code is way more elegant 
that way!

> Actually what you are trying to do here is already inside 
> `assumeSymUnsupported` and it will work for all `SymIntExpr`.

I see your point and I acknowledge that this new code resembles to the one in 
`assumeSymUnsupported`. However, there is a subtle but very important 
difference. In `assumeSymUnsupported` we use assumeSym**NE/EQ**, but here I use 
assumeSym**Rel**.  And assumeSym**Rel** does compute the adjustment, but 
assumeSym**NE/EQ** do not. Also, it makes sense to compute the adjustment only 
in case of `SymIntExpr`s, thus this could not be done in `assumeSymUnsupported`.

> Please, proveide a test case which works with `assumeSymRel` and doesn't with 
> `asume` from the previous change. That is what we are trying to fix here.

You are right, it desires a test case, so I just added the one I had pasted 
here previously (with `(x + y + 1) % 3`). If you comment-out the modifications 
here in `assumSym` then that test case will fail.




Comment at: clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp:52
+
+  if (const SymSymExpr *SSE = dyn_cast(Sym)) {
 BinaryOperator::Opcode Op = SSE->getOpcode();

ASDenysPetrov wrote:
> 
Yep, good point.



Comment at: clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp:46-49
+if (Assumption) {
+  return assumeSymRel(State, SIE, BO_NE, Zero);
+}
+return assumeSymRel(State, SIE, BO_EQ, Zero);

ASDenysPetrov wrote:
> 
> 




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112296/new/

https://reviews.llvm.org/D112296

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112296: [Analyzer][solver] Handle adjustments in constraint assignor remainder

2021-10-27 Thread Gabor Marton via Phabricator via cfe-commits
martong updated this revision to Diff 382581.
martong marked 3 inline comments as done.
martong added a comment.

- Add new test case
- Adapt style changes


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112296/new/

https://reviews.llvm.org/D112296

Files:
  clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
  clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
  clang/test/Analysis/constraint-assignor.c


Index: clang/test/Analysis/constraint-assignor.c
===
--- clang/test/Analysis/constraint-assignor.c
+++ clang/test/Analysis/constraint-assignor.c
@@ -3,9 +3,8 @@
 // RUN:   -analyzer-checker=debug.ExprInspection \
 // RUN:   -verify
 
-// expected-no-diagnostics
-
 void clang_analyzer_warnIfReached();
+void clang_analyzer_eval();
 
 void rem_constant_rhs_ne_zero(int x, int y) {
   if (x % 3 == 0) // x % 3 != 0 -> x != 0
@@ -67,3 +66,19 @@
   if (d % 2 != 0)
 return;
 }
+
+void remainder_with_adjustment(int x) {
+  if ((x + 1) % 3 == 0) // (x + 1) % 3 != 0 -> x + 1 != 0 -> x != -1
+return;
+  clang_analyzer_eval(x + 1 != 0); // expected-warning{{TRUE}}
+  clang_analyzer_eval(x != -1);// expected-warning{{TRUE}}
+  (void)x; // keep the constraints alive.
+}
+
+void remainder_with_adjustment_of_composit_lhs(int x, int y) {
+  if ((x + y + 1) % 3 == 0) // (x + 1) % 3 != 0 -> x + 1 != 0 -> x != -1
+return;
+  clang_analyzer_eval(x + y + 1 != 0); // expected-warning{{TRUE}}
+  clang_analyzer_eval(x + y != -1);// expected-warning{{TRUE}}
+  (void)(x * y); // keep the constraints alive.
+}
Index: clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
@@ -41,7 +41,12 @@
   return assumeSymRel(State, SIE->getLHS(), op, SIE->getRHS());
 }
 
-  } else if (const SymSymExpr *SSE = dyn_cast(Sym)) {
+// Handle adjustment with non-comparison ops.
+const llvm::APSInt &Zero = getBasicVals().getValue(0, SIE->getType());
+return assumeSymRel(State, SIE, (Assumption ? BO_NE : BO_EQ), Zero);
+  }
+
+  if (const auto *SSE = dyn_cast(Sym)) {
 BinaryOperator::Opcode Op = SSE->getOpcode();
 assert(BinaryOperator::isComparisonOp(Op));
 
Index: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -1615,14 +1615,14 @@
   bool handleRemainderOp(const SymT *Sym, RangeSet Constraint) {
 if (Sym->getOpcode() != BO_Rem)
   return true;
-const SymbolRef LHS = Sym->getLHS();
-const llvm::APSInt &Zero =
-Builder.getBasicValueFactory().getValue(0, Sym->getType());
 // a % b != 0 implies that a != 0.
 if (!Constraint.containsZero()) {
-  State = RCM.assumeSymNE(State, LHS, Zero, Zero);
-  if (!State)
-return false;
+  SVal SymSVal = Builder.makeSymbolVal(Sym->getLHS());
+  if (auto NonLocSymSVal = SymSVal.getAs()) {
+State = State->assume(*NonLocSymSVal, true);
+if (!State)
+  return false;
+  }
 }
 return true;
   }


Index: clang/test/Analysis/constraint-assignor.c
===
--- clang/test/Analysis/constraint-assignor.c
+++ clang/test/Analysis/constraint-assignor.c
@@ -3,9 +3,8 @@
 // RUN:   -analyzer-checker=debug.ExprInspection \
 // RUN:   -verify
 
-// expected-no-diagnostics
-
 void clang_analyzer_warnIfReached();
+void clang_analyzer_eval();
 
 void rem_constant_rhs_ne_zero(int x, int y) {
   if (x % 3 == 0) // x % 3 != 0 -> x != 0
@@ -67,3 +66,19 @@
   if (d % 2 != 0)
 return;
 }
+
+void remainder_with_adjustment(int x) {
+  if ((x + 1) % 3 == 0) // (x + 1) % 3 != 0 -> x + 1 != 0 -> x != -1
+return;
+  clang_analyzer_eval(x + 1 != 0); // expected-warning{{TRUE}}
+  clang_analyzer_eval(x != -1);// expected-warning{{TRUE}}
+  (void)x; // keep the constraints alive.
+}
+
+void remainder_with_adjustment_of_composit_lhs(int x, int y) {
+  if ((x + y + 1) % 3 == 0) // (x + 1) % 3 != 0 -> x + 1 != 0 -> x != -1
+return;
+  clang_analyzer_eval(x + y + 1 != 0); // expected-warning{{TRUE}}
+  clang_analyzer_eval(x + y != -1);// expected-warning{{TRUE}}
+  (void)(x * y); // keep the constraints alive.
+}
Index: clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
@@ -41,7 +41,12 @@
   return assumeSymRel(State, SIE->getLHS(), op, SIE->getRHS());
 }
 
-  } else if (const SymSymExpr *SSE = dyn_cast(Sym)) {
+// Handle adjustm

[PATCH] D108694: [WIP][RISCV] Add the zvl extension according to the v1.0-rc2 spec

2021-10-27 Thread Yueh-Ting Chen via Phabricator via cfe-commits
eopXD updated this revision to Diff 382582.
eopXD added a comment.

Update.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D108694/new/

https://reviews.llvm.org/D108694

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  clang/test/Driver/riscv-arch.c
  clang/test/Preprocessor/riscv-target-features.c
  llvm/include/llvm/Support/RISCVISAInfo.h
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVSubtarget.cpp
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s

Index: llvm/test/MC/RISCV/attribute-arch.s
===
--- llvm/test/MC/RISCV/attribute-arch.s
+++ llvm/test/MC/RISCV/attribute-arch.s
@@ -34,7 +34,7 @@
 # CHECK: attribute  5, "rv32i2p0_m2p0_a2p0_f2p0_d2p0_c2p0"
 
 .attribute arch, "rv32iv"
-# CHECK: attribute  5, "rv32i2p0_v0p10_zvlsseg0p10"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
 
 .attribute arch, "rv32izba"
 # CHECK: attribute  5, "rv32i2p0_zba1p0"
@@ -70,7 +70,43 @@
 # CHECK: attribute  5, "rv32i2p0_f2p0_zfh0p1"
 
 .attribute arch, "rv32ivzvamo_zvlsseg"
-# CHECK: attribute  5, "rv32i2p0_v0p10_zvamo0p10_zvlsseg0p10"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvamo0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
 
 .attribute arch, "rv32iv_zvamo0p10_zvlsseg"
-# CHECK: attribute  5, "rv32i2p0_v0p10_zvamo0p10_zvlsseg0p10"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvamo0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl32b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl64b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl128b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl256b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl128b0p10_zvl256b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl512b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl128b0p10_zvl256b0p10_zvl32b0p10_zvl512b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl1024b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl256b0p10_zvl32b0p10_zvl512b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl2048b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl2048b0p10_zvl256b0p10_zvl32b0p10_zvl512b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl4096b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl2048b0p10_zvl256b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl8192b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl2048b0p10_zvl256b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvl8192b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl16384b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl16384b0p10_zvl2048b0p10_zvl256b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvl8192b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl32768b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl16384b0p10_zvl2048b0p10_zvl256b0p10_zvl32768b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvl8192b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl65536b"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl16384b0p10_zvl2048b0p10_zvl256b0p10_zvl32768b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvl65536b0p10_zvl8192b0p10_zvlsseg0p10"
Index: llvm/test/CodeGen/RISCV/attributes.ll
===
--- llvm/test/CodeGen/RISCV/attributes.ll
+++ llvm/test/CodeGen/RISCV/attributes.ll
@@ -17,7 +17,7 @@
 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbr %s -o - | FileCheck --check-prefix=RV32ZBR %s
 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbs %s -o - | FileCheck --check-prefix=RV32ZBS %s
 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbt %s -o - | FileCheck --check-prefix=RV32ZBT %s
-; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbb,+experimental-zfh,+experimental-zvamo,+experimental-v,+f,+experimental-zvlsseg %s -o - | FileCheck --check-prefix=RV32COMBINED %s
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbb,+experimental-zfh,+experimental-zvamo,+experimental-v,+experimental-zvlsseg %s -o - | FileCheck --check-prefix=RV32COMBINED %s
 ; RUN: llc -mtriple=riscv64 -mattr=+m %s -o - | FileCheck --check-prefix=RV64M %s
 ; RUN: llc -mtriple=riscv64 -mattr=+a %s -o - | FileCheck --check-prefix=RV64A %s
 ; RUN: llc -mtriple=riscv64 -mattr=+f %s -o - | FileCheck --che

[PATCH] D110065: [AArch64] Add support for the 'R' architecture profile.

2021-10-27 Thread Alexandros Lamprineas via Phabricator via cfe-commits
labrinea updated this revision to Diff 382584.
labrinea added a comment.

Changed AppleA10 to HasV8_0aOps


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110065/new/

https://reviews.llvm.org/D110065

Files:
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/AArch64.h
  clang/lib/Driver/ToolChains/Arch/AArch64.cpp
  clang/test/Driver/aarch64-cpus.c
  clang/test/Preprocessor/aarch64-target-features.c
  llvm/lib/Support/AArch64TargetParser.cpp
  llvm/lib/Target/AArch64/AArch64.td
  llvm/lib/Target/AArch64/AArch64InstrInfo.td
  llvm/lib/Target/AArch64/AArch64Subtarget.h
  llvm/lib/Target/AArch64/AArch64SystemOperands.td
  llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
  llvm/lib/Target/AArch64/MCTargetDesc/AArch64InstPrinter.cpp
  llvm/lib/Target/AArch64/Utils/AArch64BaseInfo.h
  llvm/test/CodeGen/AArch64/arm64-crc32.ll
  llvm/test/MC/AArch64/arm64-branch-encoding.s
  llvm/test/MC/AArch64/arm64-system-encoding.s
  llvm/test/MC/AArch64/armv8.1a-lse.s
  llvm/test/MC/AArch64/armv8.1a-pan.s
  llvm/test/MC/AArch64/armv8.1a-rdma.s
  llvm/test/MC/AArch64/armv8.2a-at.s
  llvm/test/MC/AArch64/armv8.2a-crypto.s
  llvm/test/MC/AArch64/armv8.2a-dotprod-errors.s
  llvm/test/MC/AArch64/armv8.2a-dotprod.s
  llvm/test/MC/AArch64/armv8.2a-persistent-memory.s
  llvm/test/MC/AArch64/armv8.2a-uao.s
  llvm/test/MC/AArch64/armv8r-inst.s
  llvm/test/MC/AArch64/armv8r-sysreg.s
  llvm/test/MC/AArch64/armv8r-unsupported-inst.s
  llvm/test/MC/AArch64/armv8r-unsupported-sysreg.s
  llvm/test/MC/AArch64/basic-a64-instructions.s
  llvm/test/MC/AArch64/ras-extension.s
  llvm/test/MC/Disassembler/AArch64/arm64-branch.txt
  llvm/test/MC/Disassembler/AArch64/armv8.3a-complex.txt
  llvm/test/MC/Disassembler/AArch64/armv8.3a-js.txt
  llvm/test/MC/Disassembler/AArch64/armv8.3a-rcpc.txt
  llvm/test/MC/Disassembler/AArch64/armv8.4a-dit.txt
  llvm/test/MC/Disassembler/AArch64/armv8.4a-flag.txt
  llvm/test/MC/Disassembler/AArch64/armv8.4a-ras.txt
  llvm/test/MC/Disassembler/AArch64/armv8.4a-tlb.txt
  llvm/test/MC/Disassembler/AArch64/armv8.4a-trace.txt
  llvm/test/MC/Disassembler/AArch64/armv8.4a-virt.txt
  llvm/test/MC/Disassembler/AArch64/armv8.5a-predres.txt
  llvm/test/MC/Disassembler/AArch64/armv8.5a-specrestrict.txt
  llvm/test/MC/Disassembler/AArch64/armv8.5a-ssbs.txt
  llvm/test/MC/Disassembler/AArch64/armv8a-el3.txt
  llvm/test/MC/Disassembler/AArch64/armv8a-fpmul.txt
  llvm/test/MC/Disassembler/AArch64/basic-a64-instructions.txt

Index: llvm/test/MC/Disassembler/AArch64/basic-a64-instructions.txt
===
--- llvm/test/MC/Disassembler/AArch64/basic-a64-instructions.txt
+++ llvm/test/MC/Disassembler/AArch64/basic-a64-instructions.txt
@@ -1257,27 +1257,21 @@
 0xe1 0xff 0x1f 0xd4
 
 # CHECK: hvc  #{{1|0x1}}
-# CHECK: smc  #{{12000|0x2ee0}}
 # CHECK: brk  #{{12|0xc}}
 # CHECK: hlt  #{{123|0x7b}}
 0x22 0x0 0x0 0xd4
-0x3 0xdc 0x5 0xd4
 0x80 0x1 0x20 0xd4
 0x60 0xf 0x40 0xd4
 
 # CHECK: dcps1#{{42|0x2a}}
 # CHECK: dcps2#{{9|0x9}}
-# CHECK: dcps3#{{1000|0x3e8}}
 0x41 0x5 0xa0 0xd4
 0x22 0x1 0xa0 0xd4
-0x3 0x7d 0xa0 0xd4
 
 # CHECK: dcps1
 # CHECK: dcps2
-# CHECK: dcps3
 0x1 0x0 0xa0 0xd4
 0x2 0x0 0xa0 0xd4
-0x3 0x0 0xa0 0xd4
 
 #--
 # Extract (immediate)
@@ -3258,13 +3252,11 @@
 # CHECK: msr  {{hacr_el2|HACR_EL2}}, x12
 # CHECK: msr  {{mdcr_el3|MDCR_EL3}}, x12
 # CHECK: msr  {{ttbr0_el1|TTBR0_EL1}}, x12
-# CHECK: msr  {{ttbr0_el2|TTBR0_EL2}}, x12
 # CHECK: msr  {{ttbr0_el3|TTBR0_EL3}}, x12
 # CHECK: msr  {{ttbr1_el1|TTBR1_EL1}}, x12
 # CHECK: msr  {{tcr_el1|TCR_EL1}}, x12
 # CHECK: msr  {{tcr_el2|TCR_EL2}}, x12
 # CHECK: msr  {{tcr_el3|TCR_EL3}}, x12
-# CHECK: msr  {{vttbr_el2|VTTBR_EL2}}, x12
 # CHECK: msr  {{vtcr_el2|VTCR_EL2}}, x12
 # CHECK: msr  {{dacr32_el2|DACR32_EL2}}, x12
 # CHECK: msr  {{spsr_el1|SPSR_EL1}}, x12
@@ -3554,13 +3546,11 @@
 # CHECK: mrs  x9, {{hacr_el2|HACR_EL2}}
 # CHECK: mrs  x9, {{mdcr_el3|MDCR_EL3}}
 # CHECK: mrs  x9, {{ttbr0_el1|TTBR0_EL1}}
-# CHECK: mrs  x9, {{ttbr0_el2|TTBR0_EL2}}
 # CHECK: mrs  x9, {{ttbr0_el3|TTBR0_EL3}}
 # CHECK: mrs  x9, {{ttbr1_el1|TTBR1_EL1}}
 # CHECK: mrs  x9, {{tcr_el1|TCR_EL1}}
 # CHECK: mrs  x9, {{tcr_el2|TCR_EL2}}
 # CHECK: mrs  x9, {{tcr_el3|TCR_EL3}}
-# CHECK: mrs  x9, {{vttbr_el2|VTTBR_EL2}}
 # CHECK: mrs  x9, {{vtcr_el2|VTCR_EL2}}
 # CHECK: mrs  x9, {{dacr32_el2|DACR32_EL2}}
 # CHECK: mrs  x9, {{spsr_el1|SPSR_EL1}}
Index: llvm/test/MC/Disassembler/AArch64/armv8a-fpmul.txt
===
--- llvm/test/MC/Disassembler/AArch64/armv8a-fpmul.txt
+++ llvm/test/MC/Disassembler/AArch64/armv8a-fpmul.txt
@@ -1,5 +1,6 @@
 # RUN: llvm-mc -triple aarch64-none-linux-gnu -mattr=+fp16fml   --disassemble < %s 2>&1 | FileCheck %s --check-prefixes=CHECK

[PATCH] D112408: [WIP][RISCV] Add the zve extension according to the v1.0-rc2 spec

2021-10-27 Thread Yueh-Ting Chen via Phabricator via cfe-commits
eopXD marked an inline comment as done.
eopXD added inline comments.



Comment at: clang/lib/Basic/Targets/RISCV.cpp:181
   }
 
+  if (MinVLen) {

khchen wrote:
> please add a note in commit or comment here for those macros are proposed in 
> the PR https://github.com/riscv-non-isa/riscv-c-api-doc/pull/21
Added in commit message.



Comment at: llvm/include/llvm/Support/RISCVISAInfo.h:65
+  unsigned getMinVLen() const { return MinVLen; }
+  unsigned getMaxEew() const { return MaxEew; }
+  unsigned getMaxEewFp() const { return MaxEewFp; }

frasercrmck wrote:
> Aside from the discussion about EEW vs. ELEN, something about the 
> capitalization irks me. I realise we already have `XLen` but `Eew` looks... 
> wrong. If other people disagree then that's fine.
Hi Fraser,
FYI, I think there is a discussion happening 
[here](https://github.com/riscv-non-isa/riscv-c-api-doc/pull/21#issuecomment-952307965).



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112408/new/

https://reviews.llvm.org/D112408

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112406: [Driver][AArch64]Add driver support for neoverse-512tvb target

2021-10-27 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen accepted this revision.
sdesmalen added a comment.
This revision is now accepted and ready to land.

LGTM with nit addressed.




Comment at: llvm/lib/Target/AArch64/AArch64.td:840
+def TuneNeoverse512TVB : SubtargetFeature<"neoverse512tvb", "ARMProcFamily", 
"Neoverse512TVB",
+  "Neoverse 512 ARM processors", [
+  FeaturePostRAScheduler,

nit: s/512/512-TVB/


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112406/new/

https://reviews.llvm.org/D112406

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] f0d527b - [clang-repl] Remove redundant link libraries and drop unused file.

2021-10-27 Thread Vassil Vassilev via cfe-commits

Author: Vassil Vassilev
Date: 2021-10-27T10:13:30Z
New Revision: f0d527b28d07f2ce321e7055efb6635a62829eac

URL: 
https://github.com/llvm/llvm-project/commit/f0d527b28d07f2ce321e7055efb6635a62829eac
DIFF: 
https://github.com/llvm/llvm-project/commit/f0d527b28d07f2ce321e7055efb6635a62829eac.diff

LOG: [clang-repl] Remove redundant link libraries and drop unused file.

Many thanks to @thakis for pointing this out.

That commit should have been a part of https://reviews.llvm.org/D107049

Added: 


Modified: 
clang/unittests/Interpreter/CMakeLists.txt

Removed: 
clang/examples/clang-interpreter/main.cpp



diff  --git a/clang/examples/clang-interpreter/main.cpp 
b/clang/examples/clang-interpreter/main.cpp
deleted file mode 100644
index a2c50167f6b1c..0
--- a/clang/examples/clang-interpreter/main.cpp
+++ /dev/null
@@ -1,235 +0,0 @@
-//===-- examples/clang-interpreter/main.cpp - Clang C Interpreter Example 
-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-
-#include "clang/Basic/DiagnosticOptions.h"
-#include "clang/CodeGen/CodeGenAction.h"
-#include "clang/Driver/Compilation.h"
-#include "clang/Driver/Driver.h"
-#include "clang/Driver/Tool.h"
-#include "clang/Frontend/CompilerInstance.h"
-#include "clang/Frontend/CompilerInvocation.h"
-#include "clang/Frontend/FrontendDiagnostic.h"
-#include "clang/Frontend/TextDiagnosticPrinter.h"
-#include "llvm/ADT/SmallString.h"
-#include "llvm/ExecutionEngine/ExecutionEngine.h"
-#include "llvm/ExecutionEngine/Orc/CompileUtils.h"
-#include "llvm/ExecutionEngine/Orc/ExecutionUtils.h"
-#include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
-#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
-#include "llvm/ExecutionEngine/SectionMemoryManager.h"
-#include "llvm/IR/DataLayout.h"
-#include "llvm/IR/Mangler.h"
-#include "llvm/IR/Module.h"
-#include "llvm/Support/FileSystem.h"
-#include "llvm/Support/Host.h"
-#include "llvm/Support/ManagedStatic.h"
-#include "llvm/Support/Path.h"
-#include "llvm/Support/TargetSelect.h"
-#include "llvm/Support/raw_ostream.h"
-#include "llvm/Target/TargetMachine.h"
-
-using namespace clang;
-using namespace clang::driver;
-
-// This function isn't referenced outside its translation unit, but it
-// can't use the "static" keyword because its address is used for
-// GetMainExecutable (since some platforms don't support taking the
-// address of main, and some platforms can't implement GetMainExecutable
-// without being given the address of a function in the main executable).
-std::string GetExecutablePath(const char *Argv0, void *MainAddr) {
-  return llvm::sys::fs::getMainExecutable(Argv0, MainAddr);
-}
-
-namespace llvm {
-namespace orc {
-
-class SimpleJIT {
-private:
-  ExecutionSession ES;
-  std::unique_ptr TM;
-  const DataLayout DL;
-  MangleAndInterner Mangle{ES, DL};
-  JITDylib &MainJD{ES.createBareJITDylib("")};
-  RTDyldObjectLinkingLayer ObjectLayer{ES, createMemMgr};
-  IRCompileLayer CompileLayer{ES, ObjectLayer,
-  std::make_unique(*TM)};
-
-  static std::unique_ptr createMemMgr() {
-return std::make_unique();
-  }
-
-  SimpleJIT(
-  std::unique_ptr TM, DataLayout DL,
-  std::unique_ptr ProcessSymbolsGenerator)
-  : ES(cantFail(SelfExecutorProcessControl::Create())), TM(std::move(TM)),
-DL(std::move(DL)) {
-llvm::sys::DynamicLibrary::LoadLibraryPermanently(nullptr);
-MainJD.addGenerator(std::move(ProcessSymbolsGenerator));
-  }
-
-public:
-  ~SimpleJIT() {
-if (auto Err = ES.endSession())
-  ES.reportError(std::move(Err));
-  }
-
-  static Expected> Create() {
-auto JTMB = JITTargetMachineBuilder::detectHost();
-if (!JTMB)
-  return JTMB.takeError();
-
-auto TM = JTMB->createTargetMachine();
-if (!TM)
-  return TM.takeError();
-
-auto DL = (*TM)->createDataLayout();
-
-auto ProcessSymbolsGenerator =
-DynamicLibrarySearchGenerator::GetForCurrentProcess(
-DL.getGlobalPrefix());
-
-if (!ProcessSymbolsGenerator)
-  return ProcessSymbolsGenerator.takeError();
-
-return std::unique_ptr(new SimpleJIT(
-std::move(*TM), std::move(DL), std::move(*ProcessSymbolsGenerator)));
-  }
-
-  const TargetMachine &getTargetMachine() const { return *TM; }
-
-  Error addModule(ThreadSafeModule M) {
-return CompileLayer.add(MainJD, std::move(M));
-  }
-
-  Expected findSymbol(const StringRef &Name) {
-return ES.lookup({&MainJD}, Mangle(Name));
-  }
-
-  Expected getSymbolAddress(const StringRef &Name) {
-auto Sym = findSymbol(Name);
-if (!Sym)
-  return Sym.takeError();
-return Sym->getAddress();
-  }
-};
-
-} // end namespace orc
-}

[PATCH] D107049: [clang-repl] Re-implement clang-interpreter as a test case.

2021-10-27 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev marked an inline comment as done.
v.g.vassilev added inline comments.



Comment at: clang/unittests/Interpreter/CMakeLists.txt:5
+  OrcJIT
+  Support
   )

thakis wrote:
> v.g.vassilev wrote:
> > v.g.vassilev wrote:
> > > thakis wrote:
> > > > Why are these additions needed here again? This change doesn't add any 
> > > > code to ClangReplInterpreterTests as far as I can tell. Are these 
> > > > remnants from before the exception tests were in a different binary?
> > > Thanks for noticing that. The story was that 
> > > `clang/unittests/Interpreter/ExceptionTests/CMakeLists.txt` required 
> > > `${LLVM_TARGETS_TO_BUILD} Core OrcJIT Support` as a dependency -- I was 
> > > not sure why but I added the same here. I am testing now if I can get rid 
> > > of both. I do not understand why we will need different set of 
> > > dependencies for these tests as they should be using more or less the 
> > > same set of functionality...
> > I dropped these dependencies as you mentioned -- thanks again.
> Looks like they're back in the reland. Mind dropping them again?
Yeah, thanks for keeping an eye on this. Not sure what I did wrong there.. Too 
many reverts I guess...


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D107049/new/

https://reviews.llvm.org/D107049

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112296: [Analyzer][solver] Handle adjustments in constraint assignor remainder

2021-10-27 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov accepted this revision.
ASDenysPetrov added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp:44-49
+// Handle adjustment with non-comparison ops.
+const llvm::APSInt &Zero = getBasicVals().getValue(0, SIE->getType());
+if (Assumption) {
+  return assumeSymRel(State, SIE, BO_NE, Zero);
+}
+return assumeSymRel(State, SIE, BO_EQ, Zero);

martong wrote:
> ASDenysPetrov wrote:
> > Actually what you are trying to do here is already inside 
> > `assumeSymUnsupported` and it will work for all `SymIntExpr`.
> > Please, proveide a test case which works with `assumeSymRel` and doesn't 
> > with `asume` from the previous change. That is what we are trying to fix 
> > here.
> Thanks for suggesting the use of the ternary op, the code is way more elegant 
> that way!
> 
> > Actually what you are trying to do here is already inside 
> > `assumeSymUnsupported` and it will work for all `SymIntExpr`.
> 
> I see your point and I acknowledge that this new code resembles to the one in 
> `assumeSymUnsupported`. However, there is a subtle but very important 
> difference. In `assumeSymUnsupported` we use assumeSym**NE/EQ**, but here I 
> use assumeSym**Rel**.  And assumeSym**Rel** does compute the adjustment, but 
> assumeSym**NE/EQ** do not. Also, it makes sense to compute the adjustment 
> only in case of `SymIntExpr`s, thus this could not be done in 
> `assumeSymUnsupported`.
> 
> > Please, proveide a test case which works with `assumeSymRel` and doesn't 
> > with `asume` from the previous change. That is what we are trying to fix 
> > here.
> 
> You are right, it desires a test case, so I just added the one I had pasted 
> here previously (with `(x + y + 1) % 3`). If you comment-out the 
> modifications here in `assumSym` then that test case will fail.
> 
> However, there is a subtle but very important difference. 
Now I see the difference. OK, then. Your solution is sensible.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112296/new/

https://reviews.llvm.org/D112296

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D111992: [MLIR][OpenMP] Added omp.atomic.read and omp.atomic.write

2021-10-27 Thread Shraiysh via Phabricator via cfe-commits
shraiysh updated this revision to Diff 382537.
shraiysh added a comment.

Rebase with main


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D111992/new/

https://reviews.llvm.org/D111992

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  flang/lib/Semantics/check-omp-structure.cpp
  llvm/include/llvm/Frontend/OpenMP/OMP.td
  mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
  mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
  mlir/test/Dialect/OpenMP/invalid.mlir
  mlir/test/Dialect/OpenMP/ops.mlir

Index: mlir/test/Dialect/OpenMP/ops.mlir
===
--- mlir/test/Dialect/OpenMP/ops.mlir
+++ mlir/test/Dialect/OpenMP/ops.mlir
@@ -454,3 +454,37 @@
 
   return
 }
+
+// CHECK-LABEL: omp_atomic_read
+// CHECK-SAME: (%[[ADDR:.*]]: memref)
+func @omp_atomic_read(%addr : memref) {
+  // CHECK: %{{.*}} = omp.atomic.read %[[ADDR]] : memref -> i32
+  %1 = omp.atomic.read %addr : memref -> i32
+  // CHECK: %{{.*}} = omp.atomic.read %[[ADDR]] memory_order(seq_cst) : memref -> i32
+  %2 = omp.atomic.read %addr memory_order(seq_cst) : memref -> i32
+  // CHECK: %{{.*}} = omp.atomic.read %[[ADDR]] memory_order(acquire) : memref -> i32
+  %5 = omp.atomic.read %addr memory_order(acquire) : memref -> i32
+  // CHECK: %{{.*}} = omp.atomic.read %[[ADDR]] memory_order(relaxed) : memref -> i32
+  %6 = omp.atomic.read %addr memory_order(relaxed) : memref -> i32
+  // CHECK: %{{.*}} = omp.atomic.read %[[ADDR]] hint(contended, nonspeculative) : memref -> i32
+  %7 = omp.atomic.read %addr hint(nonspeculative, contended) : memref -> i32
+  // CHECK: %{{.*}} = omp.atomic.read %[[ADDR]] memory_order(seq_cst) hint(contended, speculative) : memref -> i32
+  %8 = omp.atomic.read %addr hint(speculative, contended) memory_order(seq_cst) : memref -> i32
+  return
+}
+
+// CHECK-LABEL: omp_atomic_write
+// CHECK-SAME: (%[[ADDR:.*]]: memref, %[[VAL:.*]]: i32)
+func @omp_atomic_write(%addr : memref, %val : i32) {
+  // CHECK: omp.atomic.write %[[ADDR]], %[[VAL]] : memref, i32
+  omp.atomic.write %addr, %val : memref, i32
+  // CHECK: omp.atomic.write %[[ADDR]], %[[VAL]] memory_order(seq_cst) : memref, i32
+  omp.atomic.write %addr, %val memory_order(seq_cst) : memref, i32
+  // CHECK: omp.atomic.write %[[ADDR]], %[[VAL]] memory_order(release) : memref, i32
+  omp.atomic.write %addr, %val memory_order(release) : memref, i32
+  // CHECK: omp.atomic.write %[[ADDR]], %[[VAL]] memory_order(relaxed) : memref, i32
+  omp.atomic.write %addr, %val memory_order(relaxed) : memref, i32
+  // CHECK: omp.atomic.write %[[ADDR]], %[[VAL]] hint(uncontended, speculative) : memref, i32
+  omp.atomic.write %addr, %val hint(speculative, uncontended) : memref, i32
+  return
+}
Index: mlir/test/Dialect/OpenMP/invalid.mlir
===
--- mlir/test/Dialect/OpenMP/invalid.mlir
+++ mlir/test/Dialect/OpenMP/invalid.mlir
@@ -375,3 +375,99 @@
   }
   return
 }
+
+// -
+
+func @omp_atomic_read1(%addr : memref) {
+  // expected-error @below {{the hints omp_sync_hint_nonspeculative and omp_sync_hint_speculative cannot be combined.}}
+  %1 = omp.atomic.read %addr hint(speculative, nonspeculative) : memref -> i32
+  return
+}
+
+// -
+
+func @omp_atomic_read2(%addr : memref) {
+  // expected-error @below {{attribute 'memory_order' failed to satisfy constraint: MemoryOrderKind Clause}}
+  %1 = omp.atomic.read %addr memory_order(xyz) : memref -> i32
+  return
+}
+
+// -
+
+func @omp_atomic_read3(%addr : memref) {
+  // expected-error @below {{memory-order must not be acq_rel or release for atomic reads}}
+  %1 = omp.atomic.read %addr memory_order(acq_rel) : memref -> i32
+  return
+}
+
+// -
+
+func @omp_atomic_read4(%addr : memref) {
+  // expected-error @below {{memory-order must not be acq_rel or release for atomic reads}}
+  %1 = omp.atomic.read %addr memory_order(release) : memref -> i32
+  return
+}
+
+// -
+
+func @omp_atomic_read5(%addr : memref) {
+  // expected-error @below {{at most one memory_order clause can appear on the omp.atomic.read operation}}
+  %1 = omp.atomic.read %addr memory_order(acquire) memory_order(relaxed) : memref -> i32
+  return
+}
+
+// -
+
+func @omp_atomic_read6(%addr : memref) {
+  // expected-error @below {{at most one hint clause can appear on the omp.atomic.read operation}}
+  %1 = omp.atomic.read  %addr hint(speculative) hint(contended) : memref -> i32
+  return
+}
+
+// -
+
+func @omp_atomic_write1(%addr : memref, %val : i32) {
+  // expected-error @below {{the hints omp_sync_hint_uncontended and omp_sync_hint_contended cannot be combined}}
+  omp.atomic.write  %addr, %val hint(contended, uncontended) : memref, i32
+  return
+}
+
+// -
+
+func @omp_atomic_write2(%addr : memref, %val : i32) {
+  // expected-error @below {{memory-order must not be acq_rel or acquire for atomic writes}}
+  omp.atomic.write  %addr, %val memory_order(acq_rel) : memref, i32
+  return
+}

[PATCH] D111992: [MLIR][OpenMP] Added omp.atomic.read and omp.atomic.write

2021-10-27 Thread Shraiysh via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9fb52cb3f123: [MLIR][OpenMP] Added omp.atomic.read and 
omp.atomic.write (authored by shraiysh).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D111992/new/

https://reviews.llvm.org/D111992

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  flang/lib/Semantics/check-omp-structure.cpp
  llvm/include/llvm/Frontend/OpenMP/OMP.td
  mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
  mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
  mlir/test/Dialect/OpenMP/invalid.mlir
  mlir/test/Dialect/OpenMP/ops.mlir

Index: mlir/test/Dialect/OpenMP/ops.mlir
===
--- mlir/test/Dialect/OpenMP/ops.mlir
+++ mlir/test/Dialect/OpenMP/ops.mlir
@@ -454,3 +454,37 @@
 
   return
 }
+
+// CHECK-LABEL: omp_atomic_read
+// CHECK-SAME: (%[[ADDR:.*]]: memref)
+func @omp_atomic_read(%addr : memref) {
+  // CHECK: %{{.*}} = omp.atomic.read %[[ADDR]] : memref -> i32
+  %1 = omp.atomic.read %addr : memref -> i32
+  // CHECK: %{{.*}} = omp.atomic.read %[[ADDR]] memory_order(seq_cst) : memref -> i32
+  %2 = omp.atomic.read %addr memory_order(seq_cst) : memref -> i32
+  // CHECK: %{{.*}} = omp.atomic.read %[[ADDR]] memory_order(acquire) : memref -> i32
+  %5 = omp.atomic.read %addr memory_order(acquire) : memref -> i32
+  // CHECK: %{{.*}} = omp.atomic.read %[[ADDR]] memory_order(relaxed) : memref -> i32
+  %6 = omp.atomic.read %addr memory_order(relaxed) : memref -> i32
+  // CHECK: %{{.*}} = omp.atomic.read %[[ADDR]] hint(contended, nonspeculative) : memref -> i32
+  %7 = omp.atomic.read %addr hint(nonspeculative, contended) : memref -> i32
+  // CHECK: %{{.*}} = omp.atomic.read %[[ADDR]] memory_order(seq_cst) hint(contended, speculative) : memref -> i32
+  %8 = omp.atomic.read %addr hint(speculative, contended) memory_order(seq_cst) : memref -> i32
+  return
+}
+
+// CHECK-LABEL: omp_atomic_write
+// CHECK-SAME: (%[[ADDR:.*]]: memref, %[[VAL:.*]]: i32)
+func @omp_atomic_write(%addr : memref, %val : i32) {
+  // CHECK: omp.atomic.write %[[ADDR]], %[[VAL]] : memref, i32
+  omp.atomic.write %addr, %val : memref, i32
+  // CHECK: omp.atomic.write %[[ADDR]], %[[VAL]] memory_order(seq_cst) : memref, i32
+  omp.atomic.write %addr, %val memory_order(seq_cst) : memref, i32
+  // CHECK: omp.atomic.write %[[ADDR]], %[[VAL]] memory_order(release) : memref, i32
+  omp.atomic.write %addr, %val memory_order(release) : memref, i32
+  // CHECK: omp.atomic.write %[[ADDR]], %[[VAL]] memory_order(relaxed) : memref, i32
+  omp.atomic.write %addr, %val memory_order(relaxed) : memref, i32
+  // CHECK: omp.atomic.write %[[ADDR]], %[[VAL]] hint(uncontended, speculative) : memref, i32
+  omp.atomic.write %addr, %val hint(speculative, uncontended) : memref, i32
+  return
+}
Index: mlir/test/Dialect/OpenMP/invalid.mlir
===
--- mlir/test/Dialect/OpenMP/invalid.mlir
+++ mlir/test/Dialect/OpenMP/invalid.mlir
@@ -375,3 +375,99 @@
   }
   return
 }
+
+// -
+
+func @omp_atomic_read1(%addr : memref) {
+  // expected-error @below {{the hints omp_sync_hint_nonspeculative and omp_sync_hint_speculative cannot be combined.}}
+  %1 = omp.atomic.read %addr hint(speculative, nonspeculative) : memref -> i32
+  return
+}
+
+// -
+
+func @omp_atomic_read2(%addr : memref) {
+  // expected-error @below {{attribute 'memory_order' failed to satisfy constraint: MemoryOrderKind Clause}}
+  %1 = omp.atomic.read %addr memory_order(xyz) : memref -> i32
+  return
+}
+
+// -
+
+func @omp_atomic_read3(%addr : memref) {
+  // expected-error @below {{memory-order must not be acq_rel or release for atomic reads}}
+  %1 = omp.atomic.read %addr memory_order(acq_rel) : memref -> i32
+  return
+}
+
+// -
+
+func @omp_atomic_read4(%addr : memref) {
+  // expected-error @below {{memory-order must not be acq_rel or release for atomic reads}}
+  %1 = omp.atomic.read %addr memory_order(release) : memref -> i32
+  return
+}
+
+// -
+
+func @omp_atomic_read5(%addr : memref) {
+  // expected-error @below {{at most one memory_order clause can appear on the omp.atomic.read operation}}
+  %1 = omp.atomic.read %addr memory_order(acquire) memory_order(relaxed) : memref -> i32
+  return
+}
+
+// -
+
+func @omp_atomic_read6(%addr : memref) {
+  // expected-error @below {{at most one hint clause can appear on the omp.atomic.read operation}}
+  %1 = omp.atomic.read  %addr hint(speculative) hint(contended) : memref -> i32
+  return
+}
+
+// -
+
+func @omp_atomic_write1(%addr : memref, %val : i32) {
+  // expected-error @below {{the hints omp_sync_hint_uncontended and omp_sync_hint_contended cannot be combined}}
+  omp.atomic.write  %addr, %val hint(contended, uncontended) : memref, i32
+  return
+}
+
+// -
+
+func @omp_atomic_write2(%addr : memref, %val : i32) {
+  // expected-error @below {{memory-order must not be acq_rel or acquire for 

[PATCH] D110065: [AArch64] Add support for the 'R' architecture profile.

2021-10-27 Thread John Brawn via Phabricator via cfe-commits
john.brawn accepted this revision.
john.brawn added a comment.

LGTM.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110065/new/

https://reviews.llvm.org/D110065

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112296: [Analyzer][solver] Handle adjustments in constraint assignor remainder

2021-10-27 Thread Balázs Benics via Phabricator via cfe-commits
steakhal accepted this revision.
steakhal added inline comments.



Comment at: clang/test/Analysis/constraint-assignor.c:7
 void clang_analyzer_warnIfReached();
+void clang_analyzer_eval();
 

Expect an `int` parameter.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112296/new/

https://reviews.llvm.org/D112296

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 8689f5e - [AArch64] Add support for the 'R' architecture profile.

2021-10-27 Thread Alexandros Lamprineas via cfe-commits

Author: Alexandros Lamprineas
Date: 2021-10-27T12:32:30+01:00
New Revision: 8689f5e6e77394528155b624d74557790278a407

URL: 
https://github.com/llvm/llvm-project/commit/8689f5e6e77394528155b624d74557790278a407
DIFF: 
https://github.com/llvm/llvm-project/commit/8689f5e6e77394528155b624d74557790278a407.diff

LOG: [AArch64] Add support for the 'R' architecture profile.

This change introduces subtarget features to predicate certain
instructions and system registers that are available only on
'A' profile targets. Those features are not present when
targeting a generic CPU, which is the default processor.

In other words the generic CPU now means the intersection of
'A' and 'R' profiles. To maintain backwards compatibility we
enable the features that correspond to -march=armv8-a when the
architecture is not explicitly specified on the command line.

References: https://developer.arm.com/documentation/ddi0600/latest

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

Added: 
llvm/test/MC/AArch64/armv8r-inst.s
llvm/test/MC/AArch64/armv8r-sysreg.s
llvm/test/MC/AArch64/armv8r-unsupported-inst.s
llvm/test/MC/AArch64/armv8r-unsupported-sysreg.s
llvm/test/MC/Disassembler/AArch64/armv8a-el3.txt

Modified: 
clang/lib/Basic/Targets/AArch64.cpp
clang/lib/Basic/Targets/AArch64.h
clang/lib/Driver/ToolChains/Arch/AArch64.cpp
clang/test/Driver/aarch64-cpus.c
clang/test/Preprocessor/aarch64-target-features.c
llvm/lib/Support/AArch64TargetParser.cpp
llvm/lib/Target/AArch64/AArch64.td
llvm/lib/Target/AArch64/AArch64InstrInfo.td
llvm/lib/Target/AArch64/AArch64Subtarget.h
llvm/lib/Target/AArch64/AArch64SystemOperands.td
llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
llvm/lib/Target/AArch64/MCTargetDesc/AArch64InstPrinter.cpp
llvm/lib/Target/AArch64/Utils/AArch64BaseInfo.h
llvm/test/CodeGen/AArch64/arm64-crc32.ll
llvm/test/MC/AArch64/arm64-branch-encoding.s
llvm/test/MC/AArch64/arm64-system-encoding.s
llvm/test/MC/AArch64/armv8.1a-lse.s
llvm/test/MC/AArch64/armv8.1a-pan.s
llvm/test/MC/AArch64/armv8.1a-rdma.s
llvm/test/MC/AArch64/armv8.2a-at.s
llvm/test/MC/AArch64/armv8.2a-crypto.s
llvm/test/MC/AArch64/armv8.2a-dotprod-errors.s
llvm/test/MC/AArch64/armv8.2a-dotprod.s
llvm/test/MC/AArch64/armv8.2a-persistent-memory.s
llvm/test/MC/AArch64/armv8.2a-uao.s
llvm/test/MC/AArch64/basic-a64-instructions.s
llvm/test/MC/AArch64/ras-extension.s
llvm/test/MC/Disassembler/AArch64/arm64-branch.txt
llvm/test/MC/Disassembler/AArch64/armv8.3a-complex.txt
llvm/test/MC/Disassembler/AArch64/armv8.3a-js.txt
llvm/test/MC/Disassembler/AArch64/armv8.3a-rcpc.txt
llvm/test/MC/Disassembler/AArch64/armv8.4a-dit.txt
llvm/test/MC/Disassembler/AArch64/armv8.4a-flag.txt
llvm/test/MC/Disassembler/AArch64/armv8.4a-ras.txt
llvm/test/MC/Disassembler/AArch64/armv8.4a-tlb.txt
llvm/test/MC/Disassembler/AArch64/armv8.4a-trace.txt
llvm/test/MC/Disassembler/AArch64/armv8.4a-virt.txt
llvm/test/MC/Disassembler/AArch64/armv8.5a-predres.txt
llvm/test/MC/Disassembler/AArch64/armv8.5a-specrestrict.txt
llvm/test/MC/Disassembler/AArch64/armv8.5a-ssbs.txt
llvm/test/MC/Disassembler/AArch64/armv8a-fpmul.txt
llvm/test/MC/Disassembler/AArch64/basic-a64-instructions.txt

Removed: 




diff  --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index a86019a0222d4..f75b8ffcb53d8 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -51,6 +51,15 @@ static StringRef 
getArchVersionString(llvm::AArch64::ArchKind Kind) {
   }
 }
 
+StringRef AArch64TargetInfo::getArchProfile() const {
+  switch (ArchKind) {
+  case llvm::AArch64::ArchKind::ARMV8R:
+return "R";
+  default:
+return "A";
+  }
+}
+
 AArch64TargetInfo::AArch64TargetInfo(const llvm::Triple &Triple,
  const TargetOptions &Opts)
 : TargetInfo(Triple), ABI("aapcs") {
@@ -257,7 +266,7 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions 
&Opts,
   // ACLE predefines. Many can only have one possible value on v8 AArch64.
   Builder.defineMacro("__ARM_ACLE", "200");
   Builder.defineMacro("__ARM_ARCH", getArchVersionString(ArchKind));
-  Builder.defineMacro("__ARM_ARCH_PROFILE", "'A'");
+  Builder.defineMacro("__ARM_ARCH_PROFILE", "'" + getArchProfile() + "'");
 
   Builder.defineMacro("__ARM_64BIT_STATE", "1");
   Builder.defineMacro("__ARM_PCS_AAPCS64", "1");
@@ -511,7 +520,7 @@ bool 
AArch64TargetInfo::handleTargetFeatures(std::vector &Features,
   HasMatmulFP32 = false;
   HasLSE = false;
 
-  ArchKind = llvm::AArch64::ArchKind::ARMV8A;
+  ArchKind = llvm::AArch64::ArchKind::INVALID;
 
   for (const auto &Feature : Features) {
 if (Feature == "+neon")
@@ -573,6 +582,8 @@ bool 
AArch64TargetInfo::handleTargetFeatures(std::vector

[PATCH] D110065: [AArch64] Add support for the 'R' architecture profile.

2021-10-27 Thread Alexandros Lamprineas via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8689f5e6e773: [AArch64] Add support for the 'R' 
architecture profile. (authored by labrinea).

Changed prior to commit:
  https://reviews.llvm.org/D110065?vs=382584&id=382605#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110065/new/

https://reviews.llvm.org/D110065

Files:
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/AArch64.h
  clang/lib/Driver/ToolChains/Arch/AArch64.cpp
  clang/test/Driver/aarch64-cpus.c
  clang/test/Preprocessor/aarch64-target-features.c
  llvm/lib/Support/AArch64TargetParser.cpp
  llvm/lib/Target/AArch64/AArch64.td
  llvm/lib/Target/AArch64/AArch64InstrInfo.td
  llvm/lib/Target/AArch64/AArch64Subtarget.h
  llvm/lib/Target/AArch64/AArch64SystemOperands.td
  llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
  llvm/lib/Target/AArch64/MCTargetDesc/AArch64InstPrinter.cpp
  llvm/lib/Target/AArch64/Utils/AArch64BaseInfo.h
  llvm/test/CodeGen/AArch64/arm64-crc32.ll
  llvm/test/MC/AArch64/arm64-branch-encoding.s
  llvm/test/MC/AArch64/arm64-system-encoding.s
  llvm/test/MC/AArch64/armv8.1a-lse.s
  llvm/test/MC/AArch64/armv8.1a-pan.s
  llvm/test/MC/AArch64/armv8.1a-rdma.s
  llvm/test/MC/AArch64/armv8.2a-at.s
  llvm/test/MC/AArch64/armv8.2a-crypto.s
  llvm/test/MC/AArch64/armv8.2a-dotprod-errors.s
  llvm/test/MC/AArch64/armv8.2a-dotprod.s
  llvm/test/MC/AArch64/armv8.2a-persistent-memory.s
  llvm/test/MC/AArch64/armv8.2a-uao.s
  llvm/test/MC/AArch64/armv8r-inst.s
  llvm/test/MC/AArch64/armv8r-sysreg.s
  llvm/test/MC/AArch64/armv8r-unsupported-inst.s
  llvm/test/MC/AArch64/armv8r-unsupported-sysreg.s
  llvm/test/MC/AArch64/basic-a64-instructions.s
  llvm/test/MC/AArch64/ras-extension.s
  llvm/test/MC/Disassembler/AArch64/arm64-branch.txt
  llvm/test/MC/Disassembler/AArch64/armv8.3a-complex.txt
  llvm/test/MC/Disassembler/AArch64/armv8.3a-js.txt
  llvm/test/MC/Disassembler/AArch64/armv8.3a-rcpc.txt
  llvm/test/MC/Disassembler/AArch64/armv8.4a-dit.txt
  llvm/test/MC/Disassembler/AArch64/armv8.4a-flag.txt
  llvm/test/MC/Disassembler/AArch64/armv8.4a-ras.txt
  llvm/test/MC/Disassembler/AArch64/armv8.4a-tlb.txt
  llvm/test/MC/Disassembler/AArch64/armv8.4a-trace.txt
  llvm/test/MC/Disassembler/AArch64/armv8.4a-virt.txt
  llvm/test/MC/Disassembler/AArch64/armv8.5a-predres.txt
  llvm/test/MC/Disassembler/AArch64/armv8.5a-specrestrict.txt
  llvm/test/MC/Disassembler/AArch64/armv8.5a-ssbs.txt
  llvm/test/MC/Disassembler/AArch64/armv8a-el3.txt
  llvm/test/MC/Disassembler/AArch64/armv8a-fpmul.txt
  llvm/test/MC/Disassembler/AArch64/basic-a64-instructions.txt

Index: llvm/test/MC/Disassembler/AArch64/basic-a64-instructions.txt
===
--- llvm/test/MC/Disassembler/AArch64/basic-a64-instructions.txt
+++ llvm/test/MC/Disassembler/AArch64/basic-a64-instructions.txt
@@ -1257,27 +1257,21 @@
 0xe1 0xff 0x1f 0xd4
 
 # CHECK: hvc  #{{1|0x1}}
-# CHECK: smc  #{{12000|0x2ee0}}
 # CHECK: brk  #{{12|0xc}}
 # CHECK: hlt  #{{123|0x7b}}
 0x22 0x0 0x0 0xd4
-0x3 0xdc 0x5 0xd4
 0x80 0x1 0x20 0xd4
 0x60 0xf 0x40 0xd4
 
 # CHECK: dcps1#{{42|0x2a}}
 # CHECK: dcps2#{{9|0x9}}
-# CHECK: dcps3#{{1000|0x3e8}}
 0x41 0x5 0xa0 0xd4
 0x22 0x1 0xa0 0xd4
-0x3 0x7d 0xa0 0xd4
 
 # CHECK: dcps1
 # CHECK: dcps2
-# CHECK: dcps3
 0x1 0x0 0xa0 0xd4
 0x2 0x0 0xa0 0xd4
-0x3 0x0 0xa0 0xd4
 
 #--
 # Extract (immediate)
@@ -3258,13 +3252,11 @@
 # CHECK: msr  {{hacr_el2|HACR_EL2}}, x12
 # CHECK: msr  {{mdcr_el3|MDCR_EL3}}, x12
 # CHECK: msr  {{ttbr0_el1|TTBR0_EL1}}, x12
-# CHECK: msr  {{ttbr0_el2|TTBR0_EL2}}, x12
 # CHECK: msr  {{ttbr0_el3|TTBR0_EL3}}, x12
 # CHECK: msr  {{ttbr1_el1|TTBR1_EL1}}, x12
 # CHECK: msr  {{tcr_el1|TCR_EL1}}, x12
 # CHECK: msr  {{tcr_el2|TCR_EL2}}, x12
 # CHECK: msr  {{tcr_el3|TCR_EL3}}, x12
-# CHECK: msr  {{vttbr_el2|VTTBR_EL2}}, x12
 # CHECK: msr  {{vtcr_el2|VTCR_EL2}}, x12
 # CHECK: msr  {{dacr32_el2|DACR32_EL2}}, x12
 # CHECK: msr  {{spsr_el1|SPSR_EL1}}, x12
@@ -3554,13 +3546,11 @@
 # CHECK: mrs  x9, {{hacr_el2|HACR_EL2}}
 # CHECK: mrs  x9, {{mdcr_el3|MDCR_EL3}}
 # CHECK: mrs  x9, {{ttbr0_el1|TTBR0_EL1}}
-# CHECK: mrs  x9, {{ttbr0_el2|TTBR0_EL2}}
 # CHECK: mrs  x9, {{ttbr0_el3|TTBR0_EL3}}
 # CHECK: mrs  x9, {{ttbr1_el1|TTBR1_EL1}}
 # CHECK: mrs  x9, {{tcr_el1|TCR_EL1}}
 # CHECK: mrs  x9, {{tcr_el2|TCR_EL2}}
 # CHECK: mrs  x9, {{tcr_el3|TCR_EL3}}
-# CHECK: mrs  x9, {{vttbr_el2|VTTBR_EL2}}
 # CHECK: mrs  x9, {{vtcr_el2|VTCR_EL2}}
 # CHECK: mrs  x9, {{dacr32_el2|DACR32_EL2}}
 # CHECK: mrs  x9, {{spsr_el1|SPSR_EL1}}
Index: llvm/test/MC/Disassembler/AArch64/armv8a-fpmul.txt
===
--- llvm/test/MC/Disassembler/AArch64/armv8a-fpmul.txt
+++ 

[PATCH] D112608: [clangd] IncludeCleaner: Do not process locations in built-in files

2021-10-27 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 382608.
kbobyrev added a comment.

Also handle the Command-Line defines.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112608/new/

https://reviews.llvm.org/D112608

Files:
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp


Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -234,7 +234,7 @@
""));
 }
 
-TEST(IncludeCleaner, ScratchBuffer) {
+TEST(IncludeCleaner, VirtualBuffers) {
   TestTU TU;
   TU.Filename = "foo.cpp";
   TU.Code = R"cpp(
@@ -242,6 +242,8 @@
 
 using flags::FLAGS_FOO;
 
+int y = CLI;
+
 int concat(a, b) = 42;
 )cpp";
   // The pasting operator in combination with DEFINE_FLAG will create
@@ -258,6 +260,7 @@
 #define ab x
 #define concat(x, y) x##y
 )cpp";
+  TU.ExtraArgs = {"-DCLI=42"};
   ParsedAST AST = TU.build();
   auto &SM = AST.getSourceManager();
   auto &Includes = AST.getIncludeStructure();
Index: clang-tools-extra/clangd/IncludeCleaner.cpp
===
--- clang-tools-extra/clangd/IncludeCleaner.cpp
+++ clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -133,7 +133,8 @@
   void add(SourceLocation Loc) { add(SM.getFileID(Loc), Loc); }
 
   void add(FileID FID, SourceLocation Loc) {
-if (FID.isInvalid())
+// Check if Loc is not written in a physical file.
+if (FID.isInvalid() || SM.isWrittenInBuiltinFile(Loc))
   return;
 assert(SM.isInFileID(Loc, FID));
 if (Loc.isFileID()) {


Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -234,7 +234,7 @@
""));
 }
 
-TEST(IncludeCleaner, ScratchBuffer) {
+TEST(IncludeCleaner, VirtualBuffers) {
   TestTU TU;
   TU.Filename = "foo.cpp";
   TU.Code = R"cpp(
@@ -242,6 +242,8 @@
 
 using flags::FLAGS_FOO;
 
+int y = CLI;
+
 int concat(a, b) = 42;
 )cpp";
   // The pasting operator in combination with DEFINE_FLAG will create
@@ -258,6 +260,7 @@
 #define ab x
 #define concat(x, y) x##y
 )cpp";
+  TU.ExtraArgs = {"-DCLI=42"};
   ParsedAST AST = TU.build();
   auto &SM = AST.getSourceManager();
   auto &Includes = AST.getIncludeStructure();
Index: clang-tools-extra/clangd/IncludeCleaner.cpp
===
--- clang-tools-extra/clangd/IncludeCleaner.cpp
+++ clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -133,7 +133,8 @@
   void add(SourceLocation Loc) { add(SM.getFileID(Loc), Loc); }
 
   void add(FileID FID, SourceLocation Loc) {
-if (FID.isInvalid())
+// Check if Loc is not written in a physical file.
+if (FID.isInvalid() || SM.isWrittenInBuiltinFile(Loc))
   return;
 assert(SM.isInFileID(Loc, FID));
 if (Loc.isFileID()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 6edc509 - [clangd] NFC: Remove single-line braces in IncludeCleaner

2021-10-27 Thread Kirill Bobyrev via cfe-commits

Author: Kirill Bobyrev
Date: 2021-10-27T13:53:30+02:00
New Revision: 6edc50971953775ab32d2bf298b4c991e8961055

URL: 
https://github.com/llvm/llvm-project/commit/6edc50971953775ab32d2bf298b4c991e8961055
DIFF: 
https://github.com/llvm/llvm-project/commit/6edc50971953775ab32d2bf298b4c991e8961055.diff

LOG: [clangd] NFC: Remove single-line braces in IncludeCleaner

Added: 


Modified: 
clang-tools-extra/clangd/IncludeCleaner.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/IncludeCleaner.cpp 
b/clang-tools-extra/clangd/IncludeCleaner.cpp
index cc69fdaa5e41..b1d0f956157f 100644
--- a/clang-tools-extra/clangd/IncludeCleaner.cpp
+++ b/clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -81,16 +81,14 @@ class ReferencedLocationCrawler
   }
 
   bool TraverseType(QualType T) {
-if (isNew(T.getTypePtrOrNull())) { // don't care about quals
+if (isNew(T.getTypePtrOrNull())) // don't care about quals
   Base::TraverseType(T);
-}
 return true;
   }
 
   bool VisitUsingDecl(UsingDecl *D) {
-for (const auto *Shadow : D->shadows()) {
+for (const auto *Shadow : D->shadows())
   add(Shadow->getTargetDecl());
-}
 return true;
   }
 
@@ -107,12 +105,10 @@ class ReferencedLocationCrawler
   using Base = RecursiveASTVisitor;
 
   void add(const Decl *D) {
-if (!D || !isNew(D->getCanonicalDecl())) {
+if (!D || !isNew(D->getCanonicalDecl()))
   return;
-}
-for (const Decl *Redecl : D->redecls()) {
+for (const Decl *Redecl : D->redecls())
   Result.insert(Redecl->getLocation());
-}
   }
 
   bool isNew(const void *P) { return P && Visited.insert(P).second; }
@@ -243,9 +239,8 @@ getUnused(const IncludeStructure &Structure,
   continue;
 }
 auto IncludeID = static_cast(*MFI.HeaderID);
-if (!ReferencedFiles.contains(IncludeID)) {
+if (!ReferencedFiles.contains(IncludeID))
   Unused.push_back(&MFI);
-}
 dlog("{0} is {1}", MFI.Written,
  ReferencedFiles.contains(IncludeID) ? "USED" : "UNUSED");
   }



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] e76a9f1 - [clang][deps] Fix fragile test

2021-10-27 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2021-10-27T14:00:13+02:00
New Revision: e76a9f16363c4a37b2b68da816a7bc2de0e7965e

URL: 
https://github.com/llvm/llvm-project/commit/e76a9f16363c4a37b2b68da816a7bc2de0e7965e
DIFF: 
https://github.com/llvm/llvm-project/commit/e76a9f16363c4a37b2b68da816a7bc2de0e7965e.diff

LOG: [clang][deps] Fix fragile test

This test was failing on GreenDragon.

Added: 
clang/test/ClangScanDeps/Inputs/modules-context-hash/cdb_a.json.template
clang/test/ClangScanDeps/Inputs/modules-context-hash/cdb_b.json.template

Modified: 
clang/test/ClangScanDeps/modules-context-hash.c

Removed: 
clang/test/ClangScanDeps/Inputs/modules-context-hash/cdb.json.template



diff  --git 
a/clang/test/ClangScanDeps/Inputs/modules-context-hash/cdb.json.template 
b/clang/test/ClangScanDeps/Inputs/modules-context-hash/cdb_a.json.template
similarity index 50%
rename from 
clang/test/ClangScanDeps/Inputs/modules-context-hash/cdb.json.template
rename to 
clang/test/ClangScanDeps/Inputs/modules-context-hash/cdb_a.json.template
index 81f7084ca8854..60438df0fb339 100644
--- a/clang/test/ClangScanDeps/Inputs/modules-context-hash/cdb.json.template
+++ b/clang/test/ClangScanDeps/Inputs/modules-context-hash/cdb_a.json.template
@@ -3,10 +3,5 @@
 "directory": "DIR",
 "command": "clang -c DIR/tu.c -fmodules -fmodules-cache-path=DIR/cache 
-IDIR/a -o DIR/tu_a.o",
 "file": "DIR/tu.c"
-  },
-  {
-"directory": "DIR",
-"command": "clang -c DIR/tu.c -fmodules -fmodules-cache-path=DIR/cache 
-IDIR/b -o DIR/tu_b.o",
-"file": "DIR/tu.c"
   }
 ]

diff  --git 
a/clang/test/ClangScanDeps/Inputs/modules-context-hash/cdb_b.json.template 
b/clang/test/ClangScanDeps/Inputs/modules-context-hash/cdb_b.json.template
new file mode 100644
index 0..3a4ec35943370
--- /dev/null
+++ b/clang/test/ClangScanDeps/Inputs/modules-context-hash/cdb_b.json.template
@@ -0,0 +1,7 @@
+[
+  {
+"directory": "DIR",
+"command": "clang -c DIR/tu.c -fmodules -fmodules-cache-path=DIR/cache 
-IDIR/b -o DIR/tu_b.o",
+"file": "DIR/tu.c"
+  }
+]

diff  --git a/clang/test/ClangScanDeps/modules-context-hash.c 
b/clang/test/ClangScanDeps/modules-context-hash.c
index 0b9a3e085ee6b..dfa3328335ef6 100644
--- a/clang/test/ClangScanDeps/modules-context-hash.c
+++ b/clang/test/ClangScanDeps/modules-context-hash.c
@@ -5,9 +5,17 @@
 // a single translation unit gets compiled with multiple command-lines that
 // produce 
diff erent **strict** context hashes.
 
-// RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-context-hash/cdb.json.template > 
%t/cdb.json
+// RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-context-hash/cdb_a.json.template > 
%t/cdb_a.json
+// RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-context-hash/cdb_b.json.template > 
%t/cdb_b.json
+
+// We run two separate scans. The context hash for "a" and "b" can 
diff er between
+// systems. If we'd scan both Clang invocations in a single run, the order of 
JSON
+// entities would be non-deterministic. To prevent this, run the scans 
separately
+// and verify that the context hashes 
diff er with a single FileCheck invocation.
+//
 // RUN: echo -%t > %t/result.json
-// RUN: clang-scan-deps -compilation-database %t/cdb.json -format 
experimental-full -j 1 >> %t/result.json
+// RUN: clang-scan-deps -compilation-database %t/cdb_a.json -format 
experimental-full -j 1 >> %t/result.json
+// RUN: clang-scan-deps -compilation-database %t/cdb_b.json -format 
experimental-full -j 1 >> %t/result.json
 // RUN: cat %t/result.json | sed 's:\?:/:g' | FileCheck %s 
-check-prefix=CHECK
 
 // CHECK:  -[[PREFIX:.*]]
@@ -30,24 +38,6 @@
 // CHECK-NEXT: "[[PREFIX]]/module.modulemap"
 // CHECK-NEXT:   ],
 // CHECK-NEXT:   "name": "mod"
-// CHECK-NEXT: },
-// CHECK-NEXT: {
-// CHECK-NEXT:   "clang-module-deps": [],
-// CHECK-NEXT:   "clang-modulemap-file": "[[PREFIX]]/module.modulemap",
-// CHECK-NEXT:   "command-line": [
-// CHECK-NEXT: "-cc1"
-// CHECK:  "-emit-module"
-// CHECK:  "-I"
-// CHECK:  "[[PREFIX]]/b"
-// CHECK:  "-fmodule-name=mod"
-// CHECK:],
-// CHECK-NEXT:   "context-hash": "[[HASH_MOD_B:.*]]",
-// CHECK-NEXT:   "file-deps": [
-// CHECK-NEXT: "[[PREFIX]]/b/dep.h",
-// CHECK-NEXT: "[[PREFIX]]/mod.h",
-// CHECK-NEXT: "[[PREFIX]]/module.modulemap"
-// CHECK-NEXT:   ],
-// CHECK-NEXT:   "name": "mod"
 // CHECK-NEXT: }
 // CHECK-NEXT:   ],
 // CHECK-NEXT:   "translation-units": [
@@ -67,13 +57,37 @@
 // CHECK-NEXT: "[[PREFIX]]/tu.c"
 // CHECK-NEXT:   ],
 // CHECK-NEXT:   "input-file": "[[PREFIX]]/tu.c"
-// CHECK-NEXT: },
+// CHECK-NEXT: }
+// CHECK-NEXT:   ]
+// CHECK-NEXT: }
+// CHECK-NEXT: {
+// CHECK-NEXT:   "modules": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "clang-module-deps": [],
+// CHECK-NEXT:   "clang-modulemap-file": "[[PRE

[PATCH] D112542: [clang] Convert ObjCAtTryStmt to llvm::TrailingObjects

2021-10-27 Thread Hans Wennborg via Phabricator via cfe-commits
hans accepted this revision.
hans added a comment.
This revision is now accepted and ready to land.

Nice!

Do you think the ObjCAtTryStmt::Create and CreateEmpty methods could be 
simplified by using totalSizeToAlloc()?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112542/new/

https://reviews.llvm.org/D112542

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112400: [clang][compiler-rt][atomics] Add `__c11_atomic_fetch_nand` builtin and support `__atomic_fetch_nand` libcall

2021-10-27 Thread Kai Luo via Phabricator via cfe-commits
lkail updated this revision to Diff 382618.
lkail retitled this revision from "[compiler-rt][atomics] Support 
__atomic_fetch_nand" to "[clang][compiler-rt][atomics] Add 
`__c11_atomic_fetch_nand` builtin and support `__atomic_fetch_nand` libcall".
lkail edited the summary of this revision.
lkail added a comment.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Add `__c11_atomic_fetch_nand` in clang; Use `__c11_atomic_fetch_nand` to 
implement lock-free `__atomic_fetch_nand` libcall; Updated 
`LanguageExtensions.rst`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112400/new/

https://reviews.llvm.org/D112400

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/Basic/Builtins.def
  clang/lib/AST/Expr.cpp
  clang/lib/CodeGen/CGAtomic.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/atomic-implicit-seq_cst.c
  clang/test/Sema/atomic-ops.c
  compiler-rt/lib/builtins/atomic.c
  compiler-rt/test/builtins/Unit/atomic_test.c

Index: compiler-rt/test/builtins/Unit/atomic_test.c
===
--- compiler-rt/test/builtins/Unit/atomic_test.c
+++ compiler-rt/test/builtins/Unit/atomic_test.c
@@ -96,6 +96,11 @@
 uint32_t __atomic_fetch_xor_4(uint32_t *ptr, uint32_t val, int model);
 uint64_t __atomic_fetch_xor_8(uint64_t *ptr, uint64_t val, int model);
 
+uint8_t __atomic_fetch_nand_1(uint8_t *ptr, uint8_t val, int model);
+uint16_t __atomic_fetch_nand_2(uint16_t *ptr, uint16_t val, int model);
+uint32_t __atomic_fetch_nand_4(uint32_t *ptr, uint32_t val, int model);
+uint64_t __atomic_fetch_nand_8(uint64_t *ptr, uint64_t val, int model);
+
 // We conditionally test the *_16 atomic function variants based on the same
 // condition that compiler_rt (atomic.c) uses to conditionally generate them.
 // Currently atomic.c tests if __SIZEOF_INT128__ is defined (which can be the
@@ -119,6 +124,7 @@
 uint128_t __atomic_fetch_and_16(uint128_t *ptr, uint128_t val, int model);
 uint128_t __atomic_fetch_or_16(uint128_t *ptr, uint128_t val, int model);
 uint128_t __atomic_fetch_xor_16(uint128_t *ptr, uint128_t val, int model);
+uint128_t __atomic_fetch_nand_16(uint128_t *ptr, uint128_t val, int model);
 #else
 typedef uint64_t maxuint_t;
 #endif
@@ -540,6 +546,28 @@
   abort();
 #endif
 
+// Fetch nand.
+
+set_a_values(V + m);
+set_b_values(0);
+b8 = __atomic_fetch_nand_1(&a8, U8(ONES), model);
+if (b8 != U8(V + m) || a8 != U8(~((V + m) & ONES)))
+  abort();
+b16 = __atomic_fetch_nand_2(&a16, U16(ONES), model);
+if (b16 != U16(V + m) || a16 != U16(~((V + m) & ONES)))
+  abort();
+b32 = __atomic_fetch_nand_4(&a32, U32(ONES), model);
+if (b32 != U32(V + m) || a32 != U32(~((V + m) & ONES)))
+  abort();
+b64 = __atomic_fetch_nand_8(&a64, U64(ONES), model);
+if (b64 != U64(V + m) || a64 != U64(~((V + m) & ONES)))
+  abort();
+#ifdef TEST_16
+b128 = __atomic_fetch_nand_16(&a128, ONES, model);
+if (b128 != (V + m) || a128 != ~((V + m) & ONES))
+  abort();
+#endif
+
 // Check signed integer overflow behavior
 
 set_a_values(V + m);
Index: compiler-rt/lib/builtins/atomic.c
===
--- compiler-rt/lib/builtins/atomic.c
+++ compiler-rt/lib/builtins/atomic.c
@@ -336,6 +336,18 @@
 return tmp;\
   }
 
+#define ATOMIC_RMW_NAND(n, lockfree, type) \
+  type __atomic_fetch_nand_##n(type *ptr, type val, int model) {   \
+if (lockfree(ptr)) \
+  return __c11_atomic_fetch_nand((_Atomic(type) *)ptr, val, model);\
+Lock *l = lock_for_pointer(ptr);   \
+lock(l);   \
+type tmp = *ptr;   \
+*ptr = ~(tmp & val);   \
+unlock(l); \
+return tmp;\
+  }
+
 #define OPTIMISED_CASE(n, lockfree, type) ATOMIC_RMW(n, lockfree, type, add, +)
 OPTIMISED_CASES
 #undef OPTIMISED_CASE
@@ -351,3 +363,6 @@
 #define OPTIMISED_CASE(n, lockfree, type) ATOMIC_RMW(n, lockfree, type, xor, ^)
 OPTIMISED_CASES
 #undef OPTIMISED_CASE
+#define OPTIMISED_CASE(n, lockfree, type) ATOMIC_RMW_NAND(n, lockfree, type)
+OPTIMISED_CASES
+#undef OPTIMISED_CASE
Index: clang/test/Sema/atomic-ops.c
===
--- clang/test/Sema/atomic-ops.c
+++ clang/test/Sema/atomic-ops.c
@@ -362,6 +362,13 @@
   (void)__c11_atomic_fetch_xor(Ap, val, memory_order_acq_rel);
   (void)__c11_atomic_fetch_xor(Ap, val, memory_order_seq_cst)

[PATCH] D112400: [clang][compiler-rt][atomics] Add `__c11_atomic_fetch_nand` builtin and support `__atomic_fetch_nand` libcall

2021-10-27 Thread Kai Luo via Phabricator via cfe-commits
lkail added a comment.

> The GCC builtins paint the ABI into a corner.  They accept 
> non-`_Atomic`-qualified types (the C11 spec guarantees only that these 
> operations work on `_Atomic` types).  The goal of the original C++ 
> specification was to allow implementations to use atomic operations for 
> register-sized chunks and fall back to an implementation with an inline lock 
> for larger types, so `std::atomic` would either have a single field of `T` 
> or a `std::atomic_flag` field and a `T` field, depending on the size of `T`.  
> The goal of the C11 import was to allow `_Atomic(T)` to be ABI-compatible 
> with `std::atomic`.  Implementing this requires that `_Atomic(T)` be 
> allowed to have a different representation to `T`.  GCC messed this up and 
> defined builtins that took a `T*`, not an `_Atomic(T*)`, which forced all 
> GCC-compatible ABIs to have the same representation for `T` and `_Atomic(T)`. 
>  This, in turn, meant that the atomics support library couldn't use inline 
> locks, and had to maintain a pool of locks to use for different types.  This, 
> in turn, means that `_Atomic(T)` silently fails in surprising ways in shared 
> memory, some of the time, depending on the target CPU.  This is a horrible 
> mess and I would like to ensure that we always provide builtins that allow 
> target ABIs to do the right thing, even if Linux and *BSD are trapped in a 
> broken ABI by GCC and legacy compatibility.

Good to know, thanks for your detailed explanation!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112400/new/

https://reviews.llvm.org/D112400

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112400: [clang][compiler-rt][atomics] Add `__c11_atomic_fetch_nand` builtin and support `__atomic_fetch_nand` libcall

2021-10-27 Thread David Chisnall via Phabricator via cfe-commits
theraven accepted this revision.
theraven added a comment.
This revision is now accepted and ready to land.

Thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112400/new/

https://reviews.llvm.org/D112400

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112400: [clang][compiler-rt][atomics] Add `__c11_atomic_fetch_nand` builtin and support `__atomic_fetch_nand` libcall

2021-10-27 Thread Kai Luo via Phabricator via cfe-commits
lkail updated this revision to Diff 382624.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112400/new/

https://reviews.llvm.org/D112400

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/Basic/Builtins.def
  clang/lib/AST/Expr.cpp
  clang/lib/CodeGen/CGAtomic.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/atomic-implicit-seq_cst.c
  clang/test/Sema/atomic-ops.c
  compiler-rt/lib/builtins/atomic.c
  compiler-rt/test/builtins/Unit/atomic_test.c

Index: compiler-rt/test/builtins/Unit/atomic_test.c
===
--- compiler-rt/test/builtins/Unit/atomic_test.c
+++ compiler-rt/test/builtins/Unit/atomic_test.c
@@ -96,6 +96,11 @@
 uint32_t __atomic_fetch_xor_4(uint32_t *ptr, uint32_t val, int model);
 uint64_t __atomic_fetch_xor_8(uint64_t *ptr, uint64_t val, int model);
 
+uint8_t __atomic_fetch_nand_1(uint8_t *ptr, uint8_t val, int model);
+uint16_t __atomic_fetch_nand_2(uint16_t *ptr, uint16_t val, int model);
+uint32_t __atomic_fetch_nand_4(uint32_t *ptr, uint32_t val, int model);
+uint64_t __atomic_fetch_nand_8(uint64_t *ptr, uint64_t val, int model);
+
 // We conditionally test the *_16 atomic function variants based on the same
 // condition that compiler_rt (atomic.c) uses to conditionally generate them.
 // Currently atomic.c tests if __SIZEOF_INT128__ is defined (which can be the
@@ -119,6 +124,7 @@
 uint128_t __atomic_fetch_and_16(uint128_t *ptr, uint128_t val, int model);
 uint128_t __atomic_fetch_or_16(uint128_t *ptr, uint128_t val, int model);
 uint128_t __atomic_fetch_xor_16(uint128_t *ptr, uint128_t val, int model);
+uint128_t __atomic_fetch_nand_16(uint128_t *ptr, uint128_t val, int model);
 #else
 typedef uint64_t maxuint_t;
 #endif
@@ -540,6 +546,28 @@
   abort();
 #endif
 
+// Fetch nand.
+
+set_a_values(V + m);
+set_b_values(0);
+b8 = __atomic_fetch_nand_1(&a8, U8(ONES), model);
+if (b8 != U8(V + m) || a8 != U8(~((V + m) & ONES)))
+  abort();
+b16 = __atomic_fetch_nand_2(&a16, U16(ONES), model);
+if (b16 != U16(V + m) || a16 != U16(~((V + m) & ONES)))
+  abort();
+b32 = __atomic_fetch_nand_4(&a32, U32(ONES), model);
+if (b32 != U32(V + m) || a32 != U32(~((V + m) & ONES)))
+  abort();
+b64 = __atomic_fetch_nand_8(&a64, U64(ONES), model);
+if (b64 != U64(V + m) || a64 != U64(~((V + m) & ONES)))
+  abort();
+#ifdef TEST_16
+b128 = __atomic_fetch_nand_16(&a128, ONES, model);
+if (b128 != (V + m) || a128 != ~((V + m) & ONES))
+  abort();
+#endif
+
 // Check signed integer overflow behavior
 
 set_a_values(V + m);
Index: compiler-rt/lib/builtins/atomic.c
===
--- compiler-rt/lib/builtins/atomic.c
+++ compiler-rt/lib/builtins/atomic.c
@@ -336,6 +336,18 @@
 return tmp;\
   }
 
+#define ATOMIC_RMW_NAND(n, lockfree, type) \
+  type __atomic_fetch_nand_##n(type *ptr, type val, int model) {   \
+if (lockfree(ptr)) \
+  return __c11_atomic_fetch_nand((_Atomic(type) *)ptr, val, model);\
+Lock *l = lock_for_pointer(ptr);   \
+lock(l);   \
+type tmp = *ptr;   \
+*ptr = ~(tmp & val);   \
+unlock(l); \
+return tmp;\
+  }
+
 #define OPTIMISED_CASE(n, lockfree, type) ATOMIC_RMW(n, lockfree, type, add, +)
 OPTIMISED_CASES
 #undef OPTIMISED_CASE
@@ -351,3 +363,6 @@
 #define OPTIMISED_CASE(n, lockfree, type) ATOMIC_RMW(n, lockfree, type, xor, ^)
 OPTIMISED_CASES
 #undef OPTIMISED_CASE
+#define OPTIMISED_CASE(n, lockfree, type) ATOMIC_RMW_NAND(n, lockfree, type)
+OPTIMISED_CASES
+#undef OPTIMISED_CASE
Index: clang/test/Sema/atomic-ops.c
===
--- clang/test/Sema/atomic-ops.c
+++ clang/test/Sema/atomic-ops.c
@@ -362,6 +362,13 @@
   (void)__c11_atomic_fetch_xor(Ap, val, memory_order_acq_rel);
   (void)__c11_atomic_fetch_xor(Ap, val, memory_order_seq_cst);
 
+  (void)__c11_atomic_fetch_nand(Ap, val, memory_order_relaxed);
+  (void)__c11_atomic_fetch_nand(Ap, val, memory_order_acquire);
+  (void)__c11_atomic_fetch_nand(Ap, val, memory_order_consume);
+  (void)__c11_atomic_fetch_nand(Ap, val, memory_order_release);
+  (void)__c11_atomic_fetch_nand(Ap, val, memory_order_acq_rel);
+  (void)__c11_atomic_fetch_nand(Ap, val, memory_order_seq_cst);
+
   (void)__c11_atomic_fetch_min(Ap, val, memory_order_relaxed);
   (void)__c11_atomic_fetch_min(Ap, val, mem

[PATCH] D112543: [clang] Add range accessor for ObjCAtTryStmt catch_stmts and use it

2021-10-27 Thread Hans Wennborg via Phabricator via cfe-commits
hans accepted this revision.
hans added a comment.
This revision is now accepted and ready to land.

Nice!




Comment at: clang/include/clang/AST/StmtObjC.h:279
+  catch_stmt_iterator catch_stmts_end() {
+return getStmts() + 1 + NumCatchStmts;
+  }

i might have gone with 
```
catch_stmts_begin() + NumCatchStmts
```
but up to you. Same for the const one below.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112543/new/

https://reviews.llvm.org/D112543

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112542: [clang] Convert ObjCAtTryStmt to llvm::TrailingObjects

2021-10-27 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

> Do you think the ObjCAtTryStmt::Create and CreateEmpty methods could be 
> simplified by using totalSizeToAlloc()?

Oh nice. Done :)


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112542/new/

https://reviews.llvm.org/D112542

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112542: [clang] Convert ObjCAtTryStmt to llvm::TrailingObjects

2021-10-27 Thread Nico Weber via Phabricator via cfe-commits
thakis updated this revision to Diff 382627.
thakis added a comment.

more


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112542/new/

https://reviews.llvm.org/D112542

Files:
  clang/include/clang/AST/StmtObjC.h
  clang/lib/AST/StmtObjC.cpp


Index: clang/lib/AST/StmtObjC.cpp
===
--- clang/lib/AST/StmtObjC.cpp
+++ clang/lib/AST/StmtObjC.cpp
@@ -46,9 +46,8 @@
  SourceLocation atTryLoc, Stmt *atTryStmt,
  Stmt **CatchStmts, unsigned NumCatchStmts,
  Stmt *atFinallyStmt) {
-  unsigned Size =
-  sizeof(ObjCAtTryStmt) +
-  (1 + NumCatchStmts + (atFinallyStmt != nullptr)) * sizeof(Stmt *);
+  size_t Size =
+  totalSizeToAlloc(1 + NumCatchStmts + (atFinallyStmt != nullptr));
   void *Mem = Context.Allocate(Size, alignof(ObjCAtTryStmt));
   return new (Mem) ObjCAtTryStmt(atTryLoc, atTryStmt, CatchStmts, 
NumCatchStmts,
  atFinallyStmt);
@@ -57,8 +56,7 @@
 ObjCAtTryStmt *ObjCAtTryStmt::CreateEmpty(const ASTContext &Context,
   unsigned NumCatchStmts,
   bool HasFinally) {
-  unsigned Size =
-  sizeof(ObjCAtTryStmt) + (1 + NumCatchStmts + HasFinally) * sizeof(Stmt 
*);
+  size_t Size = totalSizeToAlloc(1 + NumCatchStmts + HasFinally);
   void *Mem = Context.Allocate(Size, alignof(ObjCAtTryStmt));
   return new (Mem) ObjCAtTryStmt(EmptyShell(), NumCatchStmts, HasFinally);
 }
Index: clang/include/clang/AST/StmtObjC.h
===
--- clang/include/clang/AST/StmtObjC.h
+++ clang/include/clang/AST/StmtObjC.h
@@ -162,8 +162,14 @@
 };
 
 /// Represents Objective-C's \@try ... \@catch ... \@finally statement.
-class ObjCAtTryStmt : public Stmt {
-private:
+class ObjCAtTryStmt final
+: public Stmt,
+  private llvm::TrailingObjects {
+  friend TrailingObjects;
+  size_t numTrailingObjects(OverloadToken) const {
+return 1 + NumCatchStmts + HasFinally;
+  }
+
   // The location of the @ in the \@try.
   SourceLocation AtTryLoc;
 
@@ -178,10 +184,8 @@
   /// The order of the statements in memory follows the order in the source,
   /// with the \@try body first, followed by the \@catch statements (if any)
   /// and, finally, the \@finally (if it exists).
-  Stmt **getStmts() { return reinterpret_cast (this + 1); }
-  const Stmt* const *getStmts() const {
-return reinterpret_cast (this + 1);
-  }
+  Stmt **getStmts() { return getTrailingObjects(); }
+  Stmt *const *getStmts() const { return getTrailingObjects(); }
 
   ObjCAtTryStmt(SourceLocation atTryLoc, Stmt *atTryStmt,
 Stmt **CatchStmts, unsigned NumCatchStmts,
@@ -257,8 +261,8 @@
   }
 
   child_range children() {
-return child_range(getStmts(),
-   getStmts() + 1 + NumCatchStmts + HasFinally);
+return child_range(
+getStmts(), getStmts() + numTrailingObjects(OverloadToken()));
   }
 
   const_child_range children() const {


Index: clang/lib/AST/StmtObjC.cpp
===
--- clang/lib/AST/StmtObjC.cpp
+++ clang/lib/AST/StmtObjC.cpp
@@ -46,9 +46,8 @@
  SourceLocation atTryLoc, Stmt *atTryStmt,
  Stmt **CatchStmts, unsigned NumCatchStmts,
  Stmt *atFinallyStmt) {
-  unsigned Size =
-  sizeof(ObjCAtTryStmt) +
-  (1 + NumCatchStmts + (atFinallyStmt != nullptr)) * sizeof(Stmt *);
+  size_t Size =
+  totalSizeToAlloc(1 + NumCatchStmts + (atFinallyStmt != nullptr));
   void *Mem = Context.Allocate(Size, alignof(ObjCAtTryStmt));
   return new (Mem) ObjCAtTryStmt(atTryLoc, atTryStmt, CatchStmts, NumCatchStmts,
  atFinallyStmt);
@@ -57,8 +56,7 @@
 ObjCAtTryStmt *ObjCAtTryStmt::CreateEmpty(const ASTContext &Context,
   unsigned NumCatchStmts,
   bool HasFinally) {
-  unsigned Size =
-  sizeof(ObjCAtTryStmt) + (1 + NumCatchStmts + HasFinally) * sizeof(Stmt *);
+  size_t Size = totalSizeToAlloc(1 + NumCatchStmts + HasFinally);
   void *Mem = Context.Allocate(Size, alignof(ObjCAtTryStmt));
   return new (Mem) ObjCAtTryStmt(EmptyShell(), NumCatchStmts, HasFinally);
 }
Index: clang/include/clang/AST/StmtObjC.h
===
--- clang/include/clang/AST/StmtObjC.h
+++ clang/include/clang/AST/StmtObjC.h
@@ -162,8 +162,14 @@
 };
 
 /// Represents Objective-C's \@try ... \@catch ... \@finally statement.
-class ObjCAtTryStmt : public Stmt {
-private:
+class ObjCAtTryStmt final
+: public Stmt,
+  private llvm::TrailingObjects {
+  friend TrailingObjects;
+  size_t numTrailingObjects(OverloadToken) const {
+return 1 + N

[PATCH] D112543: [clang] Add range accessor for ObjCAtTryStmt catch_stmts and use it

2021-10-27 Thread Nico Weber via Phabricator via cfe-commits
thakis marked an inline comment as done.
thakis added a comment.

Done, thanks.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112543/new/

https://reviews.llvm.org/D112543

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D108694: [WIP][RISCV] Add the zvl extension according to the v1.0-rc2 spec

2021-10-27 Thread Yueh-Ting Chen via Phabricator via cfe-commits
eopXD updated this revision to Diff 382628.
eopXD marked 4 inline comments as done.
eopXD added a comment.

Change:

- Address commments on restrictions in RISCVSubtarget.cpp
- Fix clang-format fail
- Fix test case fail


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D108694/new/

https://reviews.llvm.org/D108694

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  clang/test/Driver/riscv-arch.c
  clang/test/Preprocessor/riscv-target-features.c
  llvm/include/llvm/Support/RISCVISAInfo.h
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVSubtarget.cpp
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s

Index: llvm/test/MC/RISCV/attribute-arch.s
===
--- llvm/test/MC/RISCV/attribute-arch.s
+++ llvm/test/MC/RISCV/attribute-arch.s
@@ -34,7 +34,7 @@
 # CHECK: attribute  5, "rv32i2p0_m2p0_a2p0_f2p0_d2p0_c2p0"
 
 .attribute arch, "rv32iv"
-# CHECK: attribute  5, "rv32i2p0_v0p10_zvlsseg0p10"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
 
 .attribute arch, "rv32izba"
 # CHECK: attribute  5, "rv32i2p0_zba1p0"
@@ -70,7 +70,43 @@
 # CHECK: attribute  5, "rv32i2p0_f2p0_zfh0p1"
 
 .attribute arch, "rv32ivzvamo_zvlsseg"
-# CHECK: attribute  5, "rv32i2p0_v0p10_zvamo0p10_zvlsseg0p10"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvamo0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
 
 .attribute arch, "rv32iv_zvamo0p10_zvlsseg"
-# CHECK: attribute  5, "rv32i2p0_v0p10_zvamo0p10_zvlsseg0p10"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvamo0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl32b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl64b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl128b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl256b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl128b0p10_zvl256b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl512b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl128b0p10_zvl256b0p10_zvl32b0p10_zvl512b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl1024b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl256b0p10_zvl32b0p10_zvl512b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl2048b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl2048b0p10_zvl256b0p10_zvl32b0p10_zvl512b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl4096b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl2048b0p10_zvl256b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl8192b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl2048b0p10_zvl256b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvl8192b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl16384b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl16384b0p10_zvl2048b0p10_zvl256b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvl8192b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl32768b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl16384b0p10_zvl2048b0p10_zvl256b0p10_zvl32768b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvl8192b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl65536b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl16384b0p10_zvl2048b0p10_zvl256b0p10_zvl32768b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvl65536b0p10_zvl8192b0p10_zvlsseg0p10"
Index: llvm/test/CodeGen/RISCV/attributes.ll
===
--- llvm/test/CodeGen/RISCV/attributes.ll
+++ llvm/test/CodeGen/RISCV/attributes.ll
@@ -17,7 +17,7 @@
 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbr %s -o - | FileCheck --check-prefix=RV32ZBR %s
 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbs %s -o - | FileCheck --check-prefix=RV32ZBS %s
 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbt %s -o - | FileCheck --check-prefix=RV32ZBT %s
-; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbb,+experimental-zfh,+experimental-zvamo,+experimental-v,+f,+experimental-zvlsseg %s -o - | FileCheck --check-prefix=RV32COMBINED %s
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbb,+experimental-zfh,+experimental-zvamo,+experimental-v,+experimental-zvlsseg %s -o - | FileCheck --check-prefix=RV32COMBINED %s
 ; RUN: llc -mtriple=riscv64 -mattr=+m %s -o - | FileCheck --check-prefix=RV64M %s
 ; RUN: llc -mtriple=riscv64 -mattr=+a %s -o - | FileCheck --check-prefix=RV64A %s
 ; RUN: llc -mtriple=riscv64 -mattr=+f %s -o - | F

[PATCH] D112577: [clang][OpenMP] Initial parsing/sema for 'align' clause

2021-10-27 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/include/clang/AST/OpenMPClause.h:334
+/// value of 8.
+class OMPAlignClause : public OMPClause {
+  friend class OMPClauseReader;

`final`



Comment at: clang/include/clang/AST/OpenMPClause.h:362-364
+  /// Sets the location of '('.
+  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
+

Also worth to make it private



Comment at: clang/include/clang/AST/OpenMPClause.h:377-382
+  child_range used_children() {
+return child_range(child_iterator(), child_iterator());
+  }
+  const_child_range used_children() const {
+return const_child_range(const_child_iterator(), const_child_iterator());
+  }

IIRC, must return same as `children` here


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112577/new/

https://reviews.llvm.org/D112577

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D108694: [WIP][RISCV] Add the zvl extension according to the v1.0-rc2 spec

2021-10-27 Thread Yueh-Ting Chen via Phabricator via cfe-commits
eopXD added inline comments.



Comment at: llvm/lib/Target/RISCV/RISCVSubtarget.cpp:134
  "maximum!");
+  assert(RVVVectorBitsMin >= ZvlLen &&
+ "Minimum V extension vector length should be at least the length "

eopXD wrote:
> craig.topper wrote:
> > eopXD wrote:
> > > craig.topper wrote:
> > > > HsiangKai wrote:
> > > > > Should it be `RVVVectorBitsMin < ZvlLen`?
> > > > > 
> > > > > I suggest to return 0 and print a warning message for users.
> > > > This isn't a good place to print warnings. It would just be a random 
> > > > message printed to stderr without going through any of clang's 
> > > > diagnostic infrastructure.
> > > I think moving the check to `initializeSubtargetDependencies` and use 
> > > `report_fatal_error` will be a more appropriate approach?
> > I think that causes clang to generate a crash report and telling the user 
> > to file a bug.
> > 
> > Forgot to mention, all this code is also being modified by D107290
> I see, then my proposal is invalid.
> 
> I am not yet that familiar with the code base. I see `RISCVFrameLowering.cpp` 
> using `LLVMContext::diagnose`, but `RISCVSubtarget` here doesn't seem to have 
> access to `LLVMContext`. 
> 
> May you recommend a pointer to some diagnose function I can use to tell the 
> user this is an invalid setting between `RVVVectorBitsMin`(from 
> `riscv-v-vector-bits-min`) and `ZvlLen` (from `-march=zvl*b`)?
I see code under `RISCVSubtarget::initializeSubtargetDependencies` also using 
`report_fatal_error`:



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D108694/new/

https://reviews.llvm.org/D108694

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112616: Fix crash on invalid code involving late parsed inline methods

2021-10-27 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman created this revision.
aaron.ballman added reviewers: rsmith, erichkeane, rjmccall, arthur.j.odwyer.
aaron.ballman requested review of this revision.
Herald added a project: clang.

When parsing the following construct, we parse it as an erroneous deduction 
guide declaration and correctly diagnose the issues with it.

template struct B;
struct A { B() noexcept(false); };

However, we then go on to finish late parsing the declaration and this expects 
that what we've parsed is a `CXXMethodDecl`. A `CXXDeductionGuideDecl` is not a 
`CXXMethodDecl` (it's a `FunctionDecl`), and so we assert on the cast.

This fixes the crash by switching from `cast<>` to `dyn_cast<>` and not setting 
up a "this" scope when the declaration is not a `CXXMethodDecl`. This fixes 
PR49735.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D112616

Files:
  clang/lib/Parse/ParseCXXInlineMethods.cpp
  clang/test/Parser/cxx1z-class-template-argument-deduction.cpp


Index: clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
===
--- clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
+++ clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
@@ -230,3 +230,21 @@
 
   template struct Z { Y y; };
 }
+
+namespace PR49735 {
+// Ensure that we do not crash when parsing code which looks like an invalid
+// deduction guide declaration.
+template struct B; // expected-note 2{{template is declared here}}
+struct A1 {
+  B() noexcept(false); // expected-error {{deduction guide must be declared in 
the same scope as template 'PR49735::B'}} \
+   // expected-error {{deduction guide declaration without 
trailing return type}}
+};
+
+struct A2 {
+  template  // expected-note {{non-deducible template parameter 
'Ty'}}
+  B() noexcept(false); // expected-error {{deduction guide must be declared in 
the same scope as template 'PR49735::B'}} \
+   // expected-error {{deduction guide template contains a 
template parameter that cannot be deduced}} \
+   // expected-error {{deduction guide declaration without 
trailing return type}}
+};
+
+}
Index: clang/lib/Parse/ParseCXXInlineMethods.cpp
===
--- clang/lib/Parse/ParseCXXInlineMethods.cpp
+++ clang/lib/Parse/ParseCXXInlineMethods.cpp
@@ -452,13 +452,14 @@
 CXXMethodDecl *Method;
 if (FunctionTemplateDecl *FunTmpl
   = dyn_cast(LM.Method))
-  Method = cast(FunTmpl->getTemplatedDecl());
+  Method = dyn_cast(FunTmpl->getTemplatedDecl());
 else
-  Method = cast(LM.Method);
+  Method = dyn_cast(LM.Method);
 
-Sema::CXXThisScopeRAII ThisScope(Actions, Method->getParent(),
- Method->getMethodQualifiers(),
- getLangOpts().CPlusPlus11);
+Sema::CXXThisScopeRAII ThisScope(
+Actions, Method ? Method->getParent() : nullptr,
+Method ? Method->getMethodQualifiers() : Qualifiers{},
+Method && getLangOpts().CPlusPlus11);
 
 // Parse the exception-specification.
 SourceRange SpecificationRange;


Index: clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
===
--- clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
+++ clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
@@ -230,3 +230,21 @@
 
   template struct Z { Y y; };
 }
+
+namespace PR49735 {
+// Ensure that we do not crash when parsing code which looks like an invalid
+// deduction guide declaration.
+template struct B; // expected-note 2{{template is declared here}}
+struct A1 {
+  B() noexcept(false); // expected-error {{deduction guide must be declared in the same scope as template 'PR49735::B'}} \
+   // expected-error {{deduction guide declaration without trailing return type}}
+};
+
+struct A2 {
+  template  // expected-note {{non-deducible template parameter 'Ty'}}
+  B() noexcept(false); // expected-error {{deduction guide must be declared in the same scope as template 'PR49735::B'}} \
+   // expected-error {{deduction guide template contains a template parameter that cannot be deduced}} \
+   // expected-error {{deduction guide declaration without trailing return type}}
+};
+
+}
Index: clang/lib/Parse/ParseCXXInlineMethods.cpp
===
--- clang/lib/Parse/ParseCXXInlineMethods.cpp
+++ clang/lib/Parse/ParseCXXInlineMethods.cpp
@@ -452,13 +452,14 @@
 CXXMethodDecl *Method;
 if (FunctionTemplateDecl *FunTmpl
   = dyn_cast(LM.Method))
-  Method = cast(FunTmpl->getTemplatedDecl());
+  Method = dyn_cast(FunTmpl->getTemplatedDecl());
 else
-  Method = cast(LM.Method);
+  Method = dyn_cast(LM.Method);
 
-Sema::CXXThisScopeRAII ThisSc

[clang] 7c10c9d - [clang] Convert ObjCAtTryStmt to llvm::TrailingObjects

2021-10-27 Thread Nico Weber via cfe-commits

Author: Nico Weber
Date: 2021-10-27T08:57:05-04:00
New Revision: 7c10c9d8e8004a09b7477806eef53cbebee82333

URL: 
https://github.com/llvm/llvm-project/commit/7c10c9d8e8004a09b7477806eef53cbebee82333
DIFF: 
https://github.com/llvm/llvm-project/commit/7c10c9d8e8004a09b7477806eef53cbebee82333.diff

LOG: [clang] Convert ObjCAtTryStmt to llvm::TrailingObjects

And make it final while here.

No behavior change.

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

Added: 


Modified: 
clang/include/clang/AST/StmtObjC.h
clang/lib/AST/StmtObjC.cpp

Removed: 




diff  --git a/clang/include/clang/AST/StmtObjC.h 
b/clang/include/clang/AST/StmtObjC.h
index 948ef2421cb97..5f56f49358f93 100644
--- a/clang/include/clang/AST/StmtObjC.h
+++ b/clang/include/clang/AST/StmtObjC.h
@@ -162,8 +162,14 @@ class ObjCAtFinallyStmt : public Stmt {
 };
 
 /// Represents Objective-C's \@try ... \@catch ... \@finally statement.
-class ObjCAtTryStmt : public Stmt {
-private:
+class ObjCAtTryStmt final
+: public Stmt,
+  private llvm::TrailingObjects {
+  friend TrailingObjects;
+  size_t numTrailingObjects(OverloadToken) const {
+return 1 + NumCatchStmts + HasFinally;
+  }
+
   // The location of the @ in the \@try.
   SourceLocation AtTryLoc;
 
@@ -178,10 +184,8 @@ class ObjCAtTryStmt : public Stmt {
   /// The order of the statements in memory follows the order in the source,
   /// with the \@try body first, followed by the \@catch statements (if any)
   /// and, finally, the \@finally (if it exists).
-  Stmt **getStmts() { return reinterpret_cast (this + 1); }
-  const Stmt* const *getStmts() const {
-return reinterpret_cast (this + 1);
-  }
+  Stmt **getStmts() { return getTrailingObjects(); }
+  Stmt *const *getStmts() const { return getTrailingObjects(); }
 
   ObjCAtTryStmt(SourceLocation atTryLoc, Stmt *atTryStmt,
 Stmt **CatchStmts, unsigned NumCatchStmts,
@@ -257,8 +261,8 @@ class ObjCAtTryStmt : public Stmt {
   }
 
   child_range children() {
-return child_range(getStmts(),
-   getStmts() + 1 + NumCatchStmts + HasFinally);
+return child_range(
+getStmts(), getStmts() + numTrailingObjects(OverloadToken()));
   }
 
   const_child_range children() const {

diff  --git a/clang/lib/AST/StmtObjC.cpp b/clang/lib/AST/StmtObjC.cpp
index 3d586795517c4..12d8a9e7dac8e 100644
--- a/clang/lib/AST/StmtObjC.cpp
+++ b/clang/lib/AST/StmtObjC.cpp
@@ -46,9 +46,8 @@ ObjCAtTryStmt *ObjCAtTryStmt::Create(const ASTContext 
&Context,
  SourceLocation atTryLoc, Stmt *atTryStmt,
  Stmt **CatchStmts, unsigned NumCatchStmts,
  Stmt *atFinallyStmt) {
-  unsigned Size =
-  sizeof(ObjCAtTryStmt) +
-  (1 + NumCatchStmts + (atFinallyStmt != nullptr)) * sizeof(Stmt *);
+  size_t Size =
+  totalSizeToAlloc(1 + NumCatchStmts + (atFinallyStmt != nullptr));
   void *Mem = Context.Allocate(Size, alignof(ObjCAtTryStmt));
   return new (Mem) ObjCAtTryStmt(atTryLoc, atTryStmt, CatchStmts, 
NumCatchStmts,
  atFinallyStmt);
@@ -57,8 +56,7 @@ ObjCAtTryStmt *ObjCAtTryStmt::Create(const ASTContext 
&Context,
 ObjCAtTryStmt *ObjCAtTryStmt::CreateEmpty(const ASTContext &Context,
   unsigned NumCatchStmts,
   bool HasFinally) {
-  unsigned Size =
-  sizeof(ObjCAtTryStmt) + (1 + NumCatchStmts + HasFinally) * sizeof(Stmt 
*);
+  size_t Size = totalSizeToAlloc(1 + NumCatchStmts + HasFinally);
   void *Mem = Context.Allocate(Size, alignof(ObjCAtTryStmt));
   return new (Mem) ObjCAtTryStmt(EmptyShell(), NumCatchStmts, HasFinally);
 }



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] c7aaa2e - [clang] Add range accessor for ObjCAtTryStmt catch_stmts and use it

2021-10-27 Thread Nico Weber via cfe-commits

Author: Nico Weber
Date: 2021-10-27T08:57:05-04:00
New Revision: c7aaa2efefdd1bfc56b877dc08a4ee5633048195

URL: 
https://github.com/llvm/llvm-project/commit/c7aaa2efefdd1bfc56b877dc08a4ee5633048195
DIFF: 
https://github.com/llvm/llvm-project/commit/c7aaa2efefdd1bfc56b877dc08a4ee5633048195.diff

LOG: [clang] Add range accessor for ObjCAtTryStmt catch_stmts and use it

No behavior change.

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

Added: 


Modified: 
clang/include/clang/AST/StmtObjC.h
clang/lib/AST/StmtPrinter.cpp
clang/lib/Analysis/CFG.cpp
clang/lib/CodeGen/CGObjCMac.cpp
clang/lib/CodeGen/CGObjCRuntime.cpp
clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
clang/lib/Sema/JumpDiagnostics.cpp
clang/lib/Serialization/ASTWriterStmt.cpp

Removed: 




diff  --git a/clang/include/clang/AST/StmtObjC.h 
b/clang/include/clang/AST/StmtObjC.h
index 5f56f49358f93..c46ff4634c825 100644
--- a/clang/include/clang/AST/StmtObjC.h
+++ b/clang/include/clang/AST/StmtObjC.h
@@ -268,6 +268,27 @@ class ObjCAtTryStmt final
   const_child_range children() const {
 return const_child_range(const_cast(this)->children());
   }
+
+  using catch_stmt_iterator = CastIterator;
+  using const_catch_stmt_iterator = ConstCastIterator;
+  using catch_range = llvm::iterator_range;
+  using catch_const_range = llvm::iterator_range;
+
+  catch_stmt_iterator catch_stmts_begin() { return getStmts() + 1; }
+  catch_stmt_iterator catch_stmts_end() {
+return catch_stmts_begin() + NumCatchStmts;
+  }
+  catch_range catch_stmts() {
+return catch_range(catch_stmts_begin(), catch_stmts_end());
+  }
+
+  const_catch_stmt_iterator catch_stmts_begin() const { return getStmts() + 1; 
}
+  const_catch_stmt_iterator catch_stmts_end() const {
+return catch_stmts_begin() + NumCatchStmts;
+  }
+  catch_const_range catch_stmts() const {
+return catch_const_range(catch_stmts_begin(), catch_stmts_end());
+  }
 };
 
 /// Represents Objective-C's \@synchronized statement.

diff  --git a/clang/lib/AST/StmtPrinter.cpp b/clang/lib/AST/StmtPrinter.cpp
index 80638336aa1e7..ce0b3bf62eb4e 100644
--- a/clang/lib/AST/StmtPrinter.cpp
+++ b/clang/lib/AST/StmtPrinter.cpp
@@ -521,13 +521,10 @@ void StmtPrinter::VisitObjCAtTryStmt(ObjCAtTryStmt *Node) 
{
 OS << NL;
   }
 
-  for (unsigned I = 0, N = Node->getNumCatchStmts(); I != N; ++I) {
-ObjCAtCatchStmt *catchStmt = Node->getCatchStmt(I);
+  for (ObjCAtCatchStmt *catchStmt : Node->catch_stmts()) {
 Indent() << "@catch(";
-if (catchStmt->getCatchParamDecl()) {
-  if (Decl *DS = catchStmt->getCatchParamDecl())
-PrintRawDecl(DS);
-}
+if (Decl *DS = catchStmt->getCatchParamDecl())
+  PrintRawDecl(DS);
 OS << ")";
 if (auto *CS = dyn_cast(catchStmt->getCatchBody())) {
   PrintRawCompoundStmt(CS);

diff  --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp
index 1ac960862ddba..11987dfd55656 100644
--- a/clang/lib/Analysis/CFG.cpp
+++ b/clang/lib/Analysis/CFG.cpp
@@ -3935,10 +3935,9 @@ CFGBlock *CFGBuilder::VisitObjCAtTryStmt(ObjCAtTryStmt 
*Terminator) {
   NewTryTerminatedBlock->setTerminator(Terminator);
 
   bool HasCatchAll = false;
-  for (unsigned I = 0, E = Terminator->getNumCatchStmts(); I != E; ++I) {
+  for (ObjCAtCatchStmt *CS : Terminator->catch_stmts()) {
 // The code after the try is the implicit successor.
 Succ = TrySuccessor;
-ObjCAtCatchStmt *CS = Terminator->getCatchStmt(I);
 if (CS->hasEllipsis()) {
   HasCatchAll = true;
 }

diff  --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index dbe39dd47d63d..36555ce3cbd9e 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -4721,9 +4721,7 @@ void 
CGObjCMac::EmitTryOrSynchronizedStmt(CodeGen::CodeGenFunction &CGF,
 // matched and avoid generating code for falling off the end if
 // so.
 bool AllMatched = false;
-for (unsigned I = 0, N = AtTryStmt->getNumCatchStmts(); I != N; ++I) {
-  const ObjCAtCatchStmt *CatchStmt = AtTryStmt->getCatchStmt(I);
-
+for (const ObjCAtCatchStmt *CatchStmt : AtTryStmt->catch_stmts()) {
   const VarDecl *CatchParam = CatchStmt->getCatchParamDecl();
   const ObjCObjectPointerType *OPT = nullptr;
 

diff  --git a/clang/lib/CodeGen/CGObjCRuntime.cpp 
b/clang/lib/CodeGen/CGObjCRuntime.cpp
index 7f26f8a3b8ff6..33ae3c7c2b28a 100644
--- a/clang/lib/CodeGen/CGObjCRuntime.cpp
+++ b/clang/lib/CodeGen/CGObjCRuntime.cpp
@@ -163,8 +163,7 @@ void CGObjCRuntime::EmitTryCatchStmt(CodeGenFunction &CGF,
 
   // Enter the catch, if there is one.
   if (S.getNumCatchStmts()) {
-for (unsigned I = 0, N = S.getNumCatchStmts(); I != N; ++I) {
-  const ObjCAtCatchStmt *CatchStmt = S.getCatchStmt(I);
+for (const ObjCAtCatchStmt *CatchStmt : S.catch_stmts()) {
   const VarDecl *CatchDecl = CatchStmt->getCatchParamDecl();
 

[PATCH] D112542: [clang] Convert ObjCAtTryStmt to llvm::TrailingObjects

2021-10-27 Thread Nico Weber via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7c10c9d8e800: [clang] Convert ObjCAtTryStmt to 
llvm::TrailingObjects (authored by thakis).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112542/new/

https://reviews.llvm.org/D112542

Files:
  clang/include/clang/AST/StmtObjC.h
  clang/lib/AST/StmtObjC.cpp


Index: clang/lib/AST/StmtObjC.cpp
===
--- clang/lib/AST/StmtObjC.cpp
+++ clang/lib/AST/StmtObjC.cpp
@@ -46,9 +46,8 @@
  SourceLocation atTryLoc, Stmt *atTryStmt,
  Stmt **CatchStmts, unsigned NumCatchStmts,
  Stmt *atFinallyStmt) {
-  unsigned Size =
-  sizeof(ObjCAtTryStmt) +
-  (1 + NumCatchStmts + (atFinallyStmt != nullptr)) * sizeof(Stmt *);
+  size_t Size =
+  totalSizeToAlloc(1 + NumCatchStmts + (atFinallyStmt != nullptr));
   void *Mem = Context.Allocate(Size, alignof(ObjCAtTryStmt));
   return new (Mem) ObjCAtTryStmt(atTryLoc, atTryStmt, CatchStmts, 
NumCatchStmts,
  atFinallyStmt);
@@ -57,8 +56,7 @@
 ObjCAtTryStmt *ObjCAtTryStmt::CreateEmpty(const ASTContext &Context,
   unsigned NumCatchStmts,
   bool HasFinally) {
-  unsigned Size =
-  sizeof(ObjCAtTryStmt) + (1 + NumCatchStmts + HasFinally) * sizeof(Stmt 
*);
+  size_t Size = totalSizeToAlloc(1 + NumCatchStmts + HasFinally);
   void *Mem = Context.Allocate(Size, alignof(ObjCAtTryStmt));
   return new (Mem) ObjCAtTryStmt(EmptyShell(), NumCatchStmts, HasFinally);
 }
Index: clang/include/clang/AST/StmtObjC.h
===
--- clang/include/clang/AST/StmtObjC.h
+++ clang/include/clang/AST/StmtObjC.h
@@ -162,8 +162,14 @@
 };
 
 /// Represents Objective-C's \@try ... \@catch ... \@finally statement.
-class ObjCAtTryStmt : public Stmt {
-private:
+class ObjCAtTryStmt final
+: public Stmt,
+  private llvm::TrailingObjects {
+  friend TrailingObjects;
+  size_t numTrailingObjects(OverloadToken) const {
+return 1 + NumCatchStmts + HasFinally;
+  }
+
   // The location of the @ in the \@try.
   SourceLocation AtTryLoc;
 
@@ -178,10 +184,8 @@
   /// The order of the statements in memory follows the order in the source,
   /// with the \@try body first, followed by the \@catch statements (if any)
   /// and, finally, the \@finally (if it exists).
-  Stmt **getStmts() { return reinterpret_cast (this + 1); }
-  const Stmt* const *getStmts() const {
-return reinterpret_cast (this + 1);
-  }
+  Stmt **getStmts() { return getTrailingObjects(); }
+  Stmt *const *getStmts() const { return getTrailingObjects(); }
 
   ObjCAtTryStmt(SourceLocation atTryLoc, Stmt *atTryStmt,
 Stmt **CatchStmts, unsigned NumCatchStmts,
@@ -257,8 +261,8 @@
   }
 
   child_range children() {
-return child_range(getStmts(),
-   getStmts() + 1 + NumCatchStmts + HasFinally);
+return child_range(
+getStmts(), getStmts() + numTrailingObjects(OverloadToken()));
   }
 
   const_child_range children() const {


Index: clang/lib/AST/StmtObjC.cpp
===
--- clang/lib/AST/StmtObjC.cpp
+++ clang/lib/AST/StmtObjC.cpp
@@ -46,9 +46,8 @@
  SourceLocation atTryLoc, Stmt *atTryStmt,
  Stmt **CatchStmts, unsigned NumCatchStmts,
  Stmt *atFinallyStmt) {
-  unsigned Size =
-  sizeof(ObjCAtTryStmt) +
-  (1 + NumCatchStmts + (atFinallyStmt != nullptr)) * sizeof(Stmt *);
+  size_t Size =
+  totalSizeToAlloc(1 + NumCatchStmts + (atFinallyStmt != nullptr));
   void *Mem = Context.Allocate(Size, alignof(ObjCAtTryStmt));
   return new (Mem) ObjCAtTryStmt(atTryLoc, atTryStmt, CatchStmts, NumCatchStmts,
  atFinallyStmt);
@@ -57,8 +56,7 @@
 ObjCAtTryStmt *ObjCAtTryStmt::CreateEmpty(const ASTContext &Context,
   unsigned NumCatchStmts,
   bool HasFinally) {
-  unsigned Size =
-  sizeof(ObjCAtTryStmt) + (1 + NumCatchStmts + HasFinally) * sizeof(Stmt *);
+  size_t Size = totalSizeToAlloc(1 + NumCatchStmts + HasFinally);
   void *Mem = Context.Allocate(Size, alignof(ObjCAtTryStmt));
   return new (Mem) ObjCAtTryStmt(EmptyShell(), NumCatchStmts, HasFinally);
 }
Index: clang/include/clang/AST/StmtObjC.h
===
--- clang/include/clang/AST/StmtObjC.h
+++ clang/include/clang/AST/StmtObjC.h
@@ -162,8 +162,14 @@
 };
 
 /// Represents Objective-C's \@try ... \@catch ... \@finally state

[PATCH] D112543: [clang] Add range accessor for ObjCAtTryStmt catch_stmts and use it

2021-10-27 Thread Nico Weber via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc7aaa2efefdd: [clang] Add range accessor for ObjCAtTryStmt 
catch_stmts and use it (authored by thakis).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D112543?vs=382329&id=382635#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112543/new/

https://reviews.llvm.org/D112543

Files:
  clang/include/clang/AST/StmtObjC.h
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/Analysis/CFG.cpp
  clang/lib/CodeGen/CGObjCMac.cpp
  clang/lib/CodeGen/CGObjCRuntime.cpp
  clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
  clang/lib/Sema/JumpDiagnostics.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp

Index: clang/lib/Serialization/ASTWriterStmt.cpp
===
--- clang/lib/Serialization/ASTWriterStmt.cpp
+++ clang/lib/Serialization/ASTWriterStmt.cpp
@@ -1482,8 +1482,8 @@
   Record.push_back(S->getNumCatchStmts());
   Record.push_back(S->getFinallyStmt() != nullptr);
   Record.AddStmt(S->getTryBody());
-  for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I)
-Record.AddStmt(S->getCatchStmt(I));
+  for (ObjCAtCatchStmt *C : S->catch_stmts())
+Record.AddStmt(C);
   if (S->getFinallyStmt())
 Record.AddStmt(S->getFinallyStmt());
   Record.AddSourceLocation(S->getAtTryLoc());
Index: clang/lib/Sema/JumpDiagnostics.cpp
===
--- clang/lib/Sema/JumpDiagnostics.cpp
+++ clang/lib/Sema/JumpDiagnostics.cpp
@@ -493,8 +493,7 @@
 }
 
 // Jump from the catch to the finally or try is not valid.
-for (unsigned I = 0, N = AT->getNumCatchStmts(); I != N; ++I) {
-  ObjCAtCatchStmt *AC = AT->getCatchStmt(I);
+for (ObjCAtCatchStmt *AC : AT->catch_stmts()) {
   unsigned NewParentScope = Scopes.size();
   Scopes.push_back(GotoScope(ParentScope,
  diag::note_protected_by_objc_catch,
Index: clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
===
--- clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
+++ clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
@@ -1957,15 +1957,15 @@
 // @try -> try
 ReplaceText(startLoc, 1, "");
 
-  for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
-ObjCAtCatchStmt *Catch = S->getCatchStmt(I);
+  for (ObjCAtCatchStmt *Catch : S->catch_stmts()) {
 VarDecl *catchDecl = Catch->getCatchParamDecl();
 
 startLoc = Catch->getBeginLoc();
 bool AtRemoved = false;
 if (catchDecl) {
   QualType t = catchDecl->getType();
-  if (const ObjCObjectPointerType *Ptr = t->getAs()) {
+  if (const ObjCObjectPointerType *Ptr =
+  t->getAs()) {
 // Should be a pointer to a class.
 ObjCInterfaceDecl *IDecl = Ptr->getObjectType()->getInterface();
 if (IDecl) {
Index: clang/lib/CodeGen/CGObjCRuntime.cpp
===
--- clang/lib/CodeGen/CGObjCRuntime.cpp
+++ clang/lib/CodeGen/CGObjCRuntime.cpp
@@ -163,8 +163,7 @@
 
   // Enter the catch, if there is one.
   if (S.getNumCatchStmts()) {
-for (unsigned I = 0, N = S.getNumCatchStmts(); I != N; ++I) {
-  const ObjCAtCatchStmt *CatchStmt = S.getCatchStmt(I);
+for (const ObjCAtCatchStmt *CatchStmt : S.catch_stmts()) {
   const VarDecl *CatchDecl = CatchStmt->getCatchParamDecl();
 
   Handlers.push_back(CatchHandler());
Index: clang/lib/CodeGen/CGObjCMac.cpp
===
--- clang/lib/CodeGen/CGObjCMac.cpp
+++ clang/lib/CodeGen/CGObjCMac.cpp
@@ -4721,9 +4721,7 @@
 // matched and avoid generating code for falling off the end if
 // so.
 bool AllMatched = false;
-for (unsigned I = 0, N = AtTryStmt->getNumCatchStmts(); I != N; ++I) {
-  const ObjCAtCatchStmt *CatchStmt = AtTryStmt->getCatchStmt(I);
-
+for (const ObjCAtCatchStmt *CatchStmt : AtTryStmt->catch_stmts()) {
   const VarDecl *CatchParam = CatchStmt->getCatchParamDecl();
   const ObjCObjectPointerType *OPT = nullptr;
 
Index: clang/lib/Analysis/CFG.cpp
===
--- clang/lib/Analysis/CFG.cpp
+++ clang/lib/Analysis/CFG.cpp
@@ -3935,10 +3935,9 @@
   NewTryTerminatedBlock->setTerminator(Terminator);
 
   bool HasCatchAll = false;
-  for (unsigned I = 0, E = Terminator->getNumCatchStmts(); I != E; ++I) {
+  for (ObjCAtCatchStmt *CS : Terminator->catch_stmts()) {
 // The code after the try is the implicit successor.
 Succ = TrySuccessor;
-ObjCAtCatchStmt *CS = Terminator->getCatchStmt(I);
 if (CS->hasEllipsis()) {
   HasCatchAll = true;
 }
Index: clang/lib/AST/StmtPrinter.cpp
===
--- cla

[PATCH] D107450: [clang-tidy] Fix wrong FixIt in performance-move-const-arg

2021-10-27 Thread gehry via Phabricator via cfe-commits
Sockke updated this revision to Diff 382632.
Sockke added a comment.

Update!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D107450/new/

https://reviews.llvm.org/D107450

Files:
  clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp
  clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/performance-move-const-arg.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/performance-move-const-arg.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/performance-move-const-arg.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/performance-move-const-arg.cpp
@@ -246,3 +246,40 @@
   };
   f(MoveSemantics());
 }
+
+void showInt(int &&v) {}
+void showInt(int v1, int &&v2) {}
+void testInt() {
+  int a = 10;
+  showInt(std::move(a));
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: std::move of the variable 'a' of the trivially-copyable type 'int' has no effect [performance-move-const-arg]
+  // CHECK-MESSAGES: :[[@LINE-6]]:20: note: consider changing the 1st parameter of showInt from 'int &&' to 'const int &'
+  showInt(int());
+  showInt(a, std::move(a));
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: std::move of the variable 'a' of the trivially-copyable type 'int' has no effect [performance-move-const-arg]
+  // CHECK-MESSAGES: :[[@LINE-9]]:28: note: consider changing the 2nd parameter of showInt from 'int &&' to 'const int &'
+}
+template 
+void forwardToShowInt(T && t) {
+  showInt(static_cast(t));
+}
+void testTemplate() {
+  int a = 10;
+  forwardToShowInt(std::move(a));
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: std::move of the variable 'a' of the trivially-copyable type 'int' has no effect [performance-move-const-arg]
+}
+
+struct Tmp {};
+void showTmp(Tmp &&v) {}
+void testTmp() {
+  Tmp t;
+  showTmp(std::move(t));
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: std::move of the variable 't' of the trivially-copyable type 'Tmp' has no effect [performance-move-const-arg]
+  // CHECK-MESSAGES: :[[@LINE-5]]:20: note: consider changing the 1st parameter of showTmp from 'Tmp &&' to 'const Tmp &'
+}
+
+void showA(A && v) {}
+void testA() {
+  A a;
+  showA(std::move(a));
+}
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -113,6 +113,10 @@
 Changes in existing checks
 ^^
 
+- Improved :doc:`performance-move-const-arg` check.
+
+  Removed fixes for that a trivially-copyable object wrapped by std::move is passed to the function with rvalue reference parameters because the code was broken by removing std::move.
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.h
===
--- clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.h
+++ clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.h
@@ -10,6 +10,7 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_MOVECONSTANTARGUMENTCHECK_H
 
 #include "../ClangTidyCheck.h"
+#include "llvm/ADT/DenseSet.h"
 
 namespace clang {
 namespace tidy {
@@ -36,6 +37,7 @@
 
 private:
   const bool CheckTriviallyCopyableMove;
+  llvm::DenseSet AlreadyCheckedMoves;
 };
 
 } // namespace performance
Index: clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp
===
--- clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp
+++ clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp
@@ -50,7 +50,9 @@
   Finder->addMatcher(
   invocation(forEachArgumentWithParam(
  MoveCallMatcher,
- parmVarDecl(hasType(references(isConstQualified())
+ parmVarDecl(anyOf(hasType(references(isConstQualified())),
+   hasType(rValueReferenceType(
+ .bind("invocation-parm")))
   .bind("receiving-expr"),
   this);
 }
@@ -58,6 +60,15 @@
 void MoveConstArgCheck::check(const MatchFinder::MatchResult &Result) {
   const auto *CallMove = Result.Nodes.getNodeAs("call-move");
   const auto *ReceivingExpr = Result.Nodes.getNodeAs("receiving-expr");
+  const auto *InvocationParm =
+  Result.Nodes.getNodeAs("invocation-parm");
+
+  if (!ReceivingExpr && AlreadyCheckedMoves.contains(CallMove))
+return;
+
+  if (ReceivingExpr)
+AlreadyCheckedMoves.insert(CallMove);
+
   const Expr *Arg = CallMove->getArg(0);
   SourceManager &SM = Result.Context->getSourceManager();
 
@@ -90,20 +101,53 @@
   return;
 
 bool IsVariable = isa(Arg);
+bool IsRValueReferenceArg = false;
 const auto *Var =
 IsVariable ? dyn_cast(Arg)->getDecl() : nullptr;
-auto Diag = diag(FileMoveRange.getBegin(),
-

[PATCH] D107450: [clang-tidy] Fix wrong FixIt in performance-move-const-arg

2021-10-27 Thread gehry via Phabricator via cfe-commits
Sockke marked 2 inline comments as done.
Sockke added a comment.

In D107450#3087103 , @whisperity 
wrote:

> I think this is becoming okay and looks safe enough. I can't really grasp 
> what `HasCheckedMoveSet` means, and how it synergises with storing 
> `CallExpr`s so maybe a better name should be added. Do you mean 
> `AlreadyCheckedMoves`? When is it possible that the same `CallExpr` of 
> `std::move` will be matched multiple times?

Yes, you're right!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D107450/new/

https://reviews.llvm.org/D107450

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112400: [clang][compiler-rt][atomics] Add `__c11_atomic_fetch_nand` builtin and support `__atomic_fetch_nand` libcall

2021-10-27 Thread James Y Knight via Phabricator via cfe-commits
jyknight added inline comments.



Comment at: compiler-rt/lib/builtins/atomic.c:339
 
+#define ATOMIC_RMW_NAND(n, lockfree, type) 
\
+  type __atomic_fetch_nand_##n(type *ptr, type val, int model) {   
\

Same as ATOMIC_RMW now, isn't it?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112400/new/

https://reviews.llvm.org/D112400

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D111654: [analyzer] Retrieve a value from list initialization of multi-dimensional array declaration.

2021-10-27 Thread Gabor Marton via Phabricator via cfe-commits
martong added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/RegionStore.cpp:1706-1743
+  // Check offsets for being out of bounds.
   // C++20 [expr.add] 7.6.6.4 (excerpt):
   //   If P points to an array element i of an array object x with n
   //   elements, where i < 0 or i > n, the behavior is undefined.
   //   Dereferencing is not allowed on the "one past the last
   //   element", when i == n.
   // Example:

ASDenysPetrov wrote:
> martong wrote:
> > Perhaps this hunk could be in an individual implementation function?
> There are two //returns// inside the loop. That would not such easy to do a 
> separate function for this.
> There are two //returns// inside the loop. That would not such easy to do a 
> separate function for this.

I think you could return with an `Optional` and then in the call site you 
could check if the optional is set.
`Optional areOffsetsOutOfBounds(...)` ?

Then in the caller:
```
if (Optional CheckResult = areOffsetsOutOfBounds(...))
  return *CheckResult;
```


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D111654/new/

https://reviews.llvm.org/D111654

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D107339: [analyzer] Retrieve a character from StringLiteral as an initializer for constant arrays.

2021-10-27 Thread Gabor Marton via Phabricator via cfe-commits
martong added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/RegionStore.cpp:1757-1760
+  // FIXME: Nevertheless, we can't do the same for cases, like:
+  //   const char *str = "123"; // literal length is 4
+  //   char c = str[41];// offset is 41
+  // It should be properly handled before reaching this point.

ASDenysPetrov wrote:
> ASDenysPetrov wrote:
> > martong wrote:
> > > Thanks for updating the patch! However, this `FIXME` makes me worried. Do 
> > > you think you could pass the `Decl` itself to `getSValFromInitListExpr` 
> > > in order to be able to check whether the type is a pointer or an array? 
> > This worried me as well. Currently I can't find a way to get the `Decl` for 
> > `SL`.
> > 
> We can load this as is for now with mentioning the known issue.
This might cause some itchy false positives. Perhaps, we could address this in 
a follow-up patch and then commit them together?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D107339/new/

https://reviews.llvm.org/D107339

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112621: [analyzer][solver] Introduce reasoning for not equal to operator

2021-10-27 Thread Manas Gupta via Phabricator via cfe-commits
manas created this revision.
Herald added subscribers: steakhal, ASDenysPetrov, martong, dkrupp, donat.nagy, 
Szelethus, mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, xazax.hun.
Herald added a reviewer: teemperor.
manas requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

With this patch, the solver can infer results for not equal to operator
over Ranges as well. This also fixes the issue of comparison between
different types, by first converting the RangeSets to resulting type,
which then can be used for comparisons.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D112621

Files:
  clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
  clang/test/Analysis/constant-folding.c

Index: clang/test/Analysis/constant-folding.c
===
--- clang/test/Analysis/constant-folding.c
+++ clang/test/Analysis/constant-folding.c
@@ -281,3 +281,49 @@
 clang_analyzer_eval((b % a) < x + 10); // expected-warning{{TRUE}}
   }
 }
+
+void testDisequalityRules(unsigned int u1, unsigned int u2, int s1, int s2) {
+  // Checks when ranges are not overlapping
+  if (u1 <= 10 && u2 >= 20) {
+// u1: [0,10], u2: [20,UINT_MAX]
+clang_analyzer_eval((u1 != u2) != 0); // expected-warning{{TRUE}}
+  }
+
+  if (s1 <= INT_MIN + 10 && s2 >= INT_MAX - 10) {
+// s1: [INT_MIN,INT_MIN + 10], s2: [INT_MAX - 10,INT_MAX]
+clang_analyzer_eval((s1 != s2) == 0); // expected-warning{{FALSE}}
+  }
+
+  // Checks when ranges are completely overlapping and have more than one point
+  if (u1 >= 20 && u1 <= 50 && u2 >= 20 && u2 <= 50) {
+// u1: [20,50], u2: [20,50]
+clang_analyzer_eval((u1 != u2) != 0); // expected-warning{{UNKNOWN}}
+  }
+
+  if (s1 >= -20 && s1 <= 20 && s2 >= -20 && s2 <= 20) {
+// s1: [-20,20], s2: [-20,20]
+clang_analyzer_eval((s1 != s2) != 0); // expected-warning{{UNKNOWN}}
+  }
+
+  // Checks when ranges are partially overlapping
+  if (u1 >= 100 && u1 <= 200 && u2 >= 150 && u2 <= 300) {
+// u1: [100,200], u2: [150,300]
+clang_analyzer_eval((u1 != u2) != 0); // expected-warning{{UNKNOWN}}
+  }
+
+  if (s1 >= -80 && s1 <= -50 && s2 >= -100 && s2 <= -75) {
+// s1: [-80,-50], s2: [-100,-75]
+clang_analyzer_eval((s1 != s2) == 0); // expected-warning{{UNKNOWN}}
+  }
+
+  // Checks for ranges which are subset of one-another
+  if (u1 >= 500 && u1 <= 1000 && u2 >= 750 && u2 <= 1000) {
+// u1: [500,1000], u2: [750,1000]
+clang_analyzer_eval((u1 != u2) == 0); // expected-warning{{UNKNOWN}}
+  }
+
+  if (s1 >= -1000 && s1 <= -500 && s2 <= -500 && s2 >= -750) {
+// s1: [-1000,-500], s2: [-500,-750]
+clang_analyzer_eval((s1 != s2) == 0); // expected-warning{{UNKNOWN}}
+  }
+}
Index: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -20,8 +20,8 @@
 #include "llvm/ADT/FoldingSet.h"
 #include "llvm/ADT/ImmutableSet.h"
 #include "llvm/ADT/STLExtras.h"
-#include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/SmallSet.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
@@ -957,6 +957,8 @@
   RangeSet VisitBinaryOperator(RangeSet LHS, BinaryOperator::Opcode Op,
RangeSet RHS, QualType T) {
 switch (Op) {
+case BO_NE:
+  return VisitBinaryOperator(LHS, RHS, T);
 case BO_Or:
   return VisitBinaryOperator(LHS, RHS, T);
 case BO_And:
@@ -1231,6 +1233,26 @@
 //   Range-based reasoning about symbolic operations
 //===--===//
 
+template <>
+RangeSet SymbolicRangeInferrer::VisitBinaryOperator(Range LHS, Range RHS,
+   QualType T) {
+  // When both the Ranges are non-overlapping then all possible pairs of (x, y)
+  // in LHS, RHS respectively, will satisfy expression (x != y).
+  if ((LHS.To() < RHS.From()) || (LHS.From() > RHS.To())) {
+return getTrueRange(T);
+  }
+
+  // If both Ranges contain only one Point which is equal, then the expression
+  // will always return true.
+  if ((LHS.From() == RHS.To()) && (LHS.To() == RHS.To()) &&
+  (LHS.From() == RHS.From())) {
+return getFalseRange(T);
+  }
+
+  // In all other cases, the resulting range cannot be deduced.
+  return infer(T);
+}
+
 template <>
 RangeSet SymbolicRangeInferrer::VisitBinaryOperator(Range LHS, Range RHS,
QualType T) {
@@ -1721,7 +1743,6 @@
   RangeSet::Factory &RangeFactory;
 };
 
-
 bool ConstraintAssignor::assignSymExprToConst(const SymExpr *Sym,
   const llvm::APSInt &Constraint) {
   llvm::SmallSet SimplifiedCl

[PATCH] D112400: [clang][compiler-rt][atomics] Add `__c11_atomic_fetch_nand` builtin and support `__atomic_fetch_nand` libcall

2021-10-27 Thread Kai Luo via Phabricator via cfe-commits
lkail added inline comments.



Comment at: compiler-rt/lib/builtins/atomic.c:339
 
+#define ATOMIC_RMW_NAND(n, lockfree, type) 
\
+  type __atomic_fetch_nand_##n(type *ptr, type val, int model) {   
\

jyknight wrote:
> Same as ATOMIC_RMW now, isn't it?
Not totally. The `ATOMIC_RMW` macro also accept binary op sign as its argument, 
i.e., in the form `a op b`. However, nand is `~(a & b)`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112400/new/

https://reviews.llvm.org/D112400

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112621: [analyzer][solver] Introduce reasoning for not equal to operator

2021-10-27 Thread Manas Gupta via Phabricator via cfe-commits
manas added a comment.

@steakhal @martong This patch solves the comparison between different types by 
bypassing the RangeSets first to `VisitBinaryOperator` which coarses/converts, 
and then only it checks for any True/False ranges via comparison. This is 
similar to what happens with `BO_Rem`, `BO_And` etc. as well.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112621/new/

https://reviews.llvm.org/D112621

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112621: [analyzer][solver] Introduce reasoning for not equal to operator

2021-10-27 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

Please also demonstrate that the patch can deal with sign mismatching ranges.
Aside from that, it looks clean and sweet.
Although, I still miss the point of how it would bypass anything.




Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:1241
+  // in LHS, RHS respectively, will satisfy expression (x != y).
+  if ((LHS.To() < RHS.From()) || (LHS.From() > RHS.To())) {
+return getTrueRange(T);

I would probably host this logic into a `Range::intersects(Range Other) const` 
member function.



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:1245-1250
+  // If both Ranges contain only one Point which is equal, then the expression
+  // will always return true.
+  if ((LHS.From() == RHS.To()) && (LHS.To() == RHS.To()) &&
+  (LHS.From() == RHS.From())) {
+return getFalseRange(T);
+  }

Technically, it's correct, but I would rather follow a similar logic to what 
the comment would suggest.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112621/new/

https://reviews.llvm.org/D112621

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112094: Add support for floating-point option `ffp-eval-method` and for `pragma clang fp eval_method`.

2021-10-27 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam updated this revision to Diff 382663.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112094/new/

https://reviews.llvm.org/D112094

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/UsersManual.rst
  clang/include/clang/Basic/FPOptions.def
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Basic/TargetInfo.h
  clang/include/clang/Driver/Options.td
  clang/include/clang/Lex/Preprocessor.h
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Basic/Targets/OSTargets.h
  clang/lib/Basic/Targets/X86.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Parse/ParsePragma.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaAttr.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/CodeGen/fp-floatcontrol-pragma.cpp
  clang/test/Preprocessor/init-aarch64.c
  clang/test/Preprocessor/init-arm.c
  clang/test/Preprocessor/init-mips.c
  clang/test/Preprocessor/init-ppc.c
  clang/test/Preprocessor/init-ppc64.c
  clang/test/Preprocessor/init-s390x.c
  clang/test/Preprocessor/init-v7k-compat.c
  clang/test/Preprocessor/init-x86.c
  clang/test/Preprocessor/init.c

Index: clang/test/Preprocessor/init.c
===
--- clang/test/Preprocessor/init.c
+++ clang/test/Preprocessor/init.c
@@ -323,7 +323,7 @@
 // MSP430:#define __FLT_DENORM_MIN__ 1.40129846e-45F
 // MSP430:#define __FLT_DIG__ 6
 // MSP430:#define __FLT_EPSILON__ 1.19209290e-7F
-// MSP430:#define __FLT_EVAL_METHOD__ 0
+// MSP430:#define __FLT_EVAL_METHOD__ -1
 // MSP430:#define __FLT_HAS_DENORM__ 1
 // MSP430:#define __FLT_HAS_INFINITY__ 1
 // MSP430:#define __FLT_HAS_QUIET_NAN__ 1
@@ -511,7 +511,7 @@
 // NVPTX32:#define __FLT_DENORM_MIN__ 1.40129846e-45F
 // NVPTX32:#define __FLT_DIG__ 6
 // NVPTX32:#define __FLT_EPSILON__ 1.19209290e-7F
-// NVPTX32:#define __FLT_EVAL_METHOD__ 0
+// NVPTX32:#define __FLT_EVAL_METHOD__ -1
 // NVPTX32:#define __FLT_HAS_DENORM__ 1
 // NVPTX32:#define __FLT_HAS_INFINITY__ 1
 // NVPTX32:#define __FLT_HAS_QUIET_NAN__ 1
@@ -700,7 +700,7 @@
 // NVPTX64:#define __FLT_DENORM_MIN__ 1.40129846e-45F
 // NVPTX64:#define __FLT_DIG__ 6
 // NVPTX64:#define __FLT_EPSILON__ 1.19209290e-7F
-// NVPTX64:#define __FLT_EVAL_METHOD__ 0
+// NVPTX64:#define __FLT_EVAL_METHOD__ -1
 // NVPTX64:#define __FLT_HAS_DENORM__ 1
 // NVPTX64:#define __FLT_HAS_INFINITY__ 1
 // NVPTX64:#define __FLT_HAS_QUIET_NAN__ 1
@@ -904,7 +904,7 @@
 // SPARC:#define __FLT_DENORM_MIN__ 1.40129846e-45F
 // SPARC:#define __FLT_DIG__ 6
 // SPARC:#define __FLT_EPSILON__ 1.19209290e-7F
-// SPARC:#define __FLT_EVAL_METHOD__ 0
+// SPARC:#define __FLT_EVAL_METHOD__ -1
 // SPARC:#define __FLT_HAS_DENORM__ 1
 // SPARC:#define __FLT_HAS_INFINITY__ 1
 // SPARC:#define __FLT_HAS_QUIET_NAN__ 1
@@ -1105,7 +1105,7 @@
 // TCE:#define __FLT_DENORM_MIN__ 1.40129846e-45F
 // TCE:#define __FLT_DIG__ 6
 // TCE:#define __FLT_EPSILON__ 1.19209290e-7F
-// TCE:#define __FLT_EVAL_METHOD__ 0
+// TCE:#define __FLT_EVAL_METHOD__ -1
 // TCE:#define __FLT_HAS_DENORM__ 1
 // TCE:#define __FLT_HAS_INFINITY__ 1
 // TCE:#define __FLT_HAS_QUIET_NAN__ 1
@@ -1272,7 +1272,7 @@
 // PS4:#define __FLT_DENORM_MIN__ 1.40129846e-45F
 // PS4:#define __FLT_DIG__ 6
 // PS4:#define __FLT_EPSILON__ 1.19209290e-7F
-// PS4:#define __FLT_EVAL_METHOD__ 0
+// PS4:#define __FLT_EVAL_METHOD__ -1
 // PS4:#define __FLT_HAS_DENORM__ 1
 // PS4:#define __FLT_HAS_INFINITY__ 1
 // PS4:#define __FLT_HAS_QUIET_NAN__ 1
@@ -1574,7 +1574,7 @@
 // WEBASSEMBLY-NEXT:#define __FLT_DENORM_MIN__ 1.40129846e-45F
 // WEBASSEMBLY-NEXT:#define __FLT_DIG__ 6
 // WEBASSEMBLY-NEXT:#define __FLT_EPSILON__ 1.19209290e-7F
-// WEBASSEMBLY-NEXT:#define __FLT_EVAL_METHOD__ 0
+// WEBASSEMBLY-NEXT:#define __FLT_EVAL_METHOD__ -1
 // WEBASSEMBLY-NEXT:#define __FLT_HAS_DENORM__ 1
 // WEBASSEMBLY-NEXT:#define __FLT_HAS_INFINITY__ 1
 // WEBASSEMBLY-NEXT:#define __FLT_HAS_QUIET_NAN__ 1
@@ -1930,7 +1930,7 @@
 // AVR:#define __FLT_DENORM_MIN__ 1.40129846e-45F
 // AVR:#define __FLT_DIG__ 6
 // AVR:#define __FLT_EPSILON__ 1.19209290e-7F
-// AVR:#define __FLT_EVAL_METHOD__ 0
+// AVR:#define __FLT_EVAL_METHOD__ -1
 // AVR:#define __FLT_HAS_DENORM__ 1
 // AVR:#define __FLT_HAS_INFINITY__ 1
 // AVR:#define __FLT_HAS_QUIET_NAN__ 1
@@ -2213,7 +2213,7 @@
 // RISCV32: #define __FLT_DENORM_MIN__ 1.40129846e-45F
 // RISCV32: #define __FLT_DIG__ 6
 // RISCV32: #define __FLT_EPSILON__ 1.19209290e-7F
-// RISCV32: #define __FLT_EVAL_METHOD__ 0
+// RISCV32: #define __FLT_EVAL_METHOD__ -1
 // RISCV32: #define __FLT_HAS_DENORM__ 1
 // RISCV32: #define __FLT_HAS_INFINITY__ 1
 // RISCV32: #define __FLT_HAS_QUIET_NAN__ 1
@@ -2421,7 +2421,7 @@
 // RISCV64: #define __FLT_DENORM_MIN__ 1.40129846e-45F
 // RISCV64: #define __FLT_DIG__ 6
 // RISCV64: #define __FLT_EPSILON__ 1.19209290e-7F
-// RISCV64: #define __FLT_EVAL_METHOD__ 0
+// RISCV64: #define __FLT_EVAL_METHOD__ -1
 // RISCV64: #define __FLT_HAS_DENOR

[PATCH] D112094: Add support for floating-point option `ffp-eval-method` and for `pragma clang fp eval_method`.

2021-10-27 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam added a comment.

In D112094#3087531 , @aaron.ballman 
wrote:

> One thing I think we need additional test coverage for is constant expression 
> evaluation. Should the pragma impact the resulting value stored into `f`:
>
>   constexpr long double whatever(float x, float y) {
>   #pragma clang fp eval_method(extended)
> return x / y;
>   }
>   
>   constexpr long double f = whatever(4.2f, 1.0f/3.0f);
>
> Ping @andrew.w.kaylor on this question. (My intuition is that it should 
> impact constant expression evaluation.)
>
> Also, @zahiraam -- is there a reason this is not a public review? (When you 
> protect the review like this, CI precommit testing doesn't happen and 
> community doesn't know about the proposal.)

@aaron.ballman  thanks for the review.
This is the IR of the test constexpr test case.
With the pragma:

define dso_local i32 @main() #0 {
entry:

  %f = alloca x86_fp80, align 16
  store x86_fp80 0xK4002C89BB266, x86_fp80* %f, align 16
  ret i32 0

}

With no pragma:
define dso_local i32 @main() #0 {
entry:

  %f = alloca x86_fp80, align 16
  store x86_fp80 0xK4002C900, x86_fp80* %f, align 16
  ret i32 0

}
@andrew.w.kaylor your thoughts about this? Thanks.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112094/new/

https://reviews.llvm.org/D112094

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112621: [analyzer][solver] Introduce reasoning for not equal to operator

2021-10-27 Thread Balázs Benics via Phabricator via cfe-commits
steakhal requested changes to this revision.
steakhal added a comment.
This revision now requires changes to proceed.

It seems like the test does not exercise the modified code segment.
Please investigate, and make sure that the code you submit is actually 
exercised by the test you provide.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112621/new/

https://reviews.llvm.org/D112621

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112059: Fix inline builtin handling in case of redefinition

2021-10-27 Thread serge via Phabricator via cfe-commits
serge-sans-paille updated this revision to Diff 382671.
serge-sans-paille added a comment.

- Use a FunctionDecl Attribute to store the shadowed inline redecl status


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112059/new/

https://reviews.llvm.org/D112059

Files:
  clang/include/clang/AST/Decl.h
  clang/include/clang/AST/DeclBase.h
  clang/lib/AST/Decl.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/test/CodeGen/gnu-inline-redecl.c
  clang/test/CodeGen/strlen-inline-builtin-redecl.c

Index: clang/test/CodeGen/strlen-inline-builtin-redecl.c
===
--- /dev/null
+++ clang/test/CodeGen/strlen-inline-builtin-redecl.c
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -triple x86_64 -S -emit-llvm -disable-llvm-passes -o - %s | FileCheck %s
+//
+// Verifies that clang-generated *.inline are removed when shadowed by an external definition
+
+// CHECK-NOT: strlen.inline
+
+unsigned long strnlen(const char *, unsigned long);
+
+extern inline __attribute__((always_inline)) __attribute__((gnu_inline)) unsigned long strlen(const char *p) {
+  return 1;
+}
+unsigned long mystrlen(char const *s) {
+  return strlen(s);
+}
+unsigned long strlen(const char *s) {
+  return 2;
+}
+unsigned long yourstrlen(char const *s) {
+  return strlen(s);
+}
Index: clang/test/CodeGen/gnu-inline-redecl.c
===
--- /dev/null
+++ clang/test/CodeGen/gnu-inline-redecl.c
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -triple x86_64 -S -emit-llvm -O1 -o - %s | FileCheck %s
+//
+// Verifies that the gnu_inline version is ignored in favor of the redecl
+
+extern inline __attribute__((gnu_inline)) unsigned long some_size(int c) {
+  return 1;
+}
+unsigned long mycall(int s) {
+  // CHECK-LABEL: i64 @mycall
+  // CHECK: ret i64 2
+  return some_size(s);
+}
+unsigned long some_size(int c) {
+  return 2;
+}
+unsigned long yourcall(int s) {
+  // CHECK-LABEL: i64 @yourcall
+  // CHECK: ret i64 2
+  return some_size(s);
+}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -10927,6 +10927,11 @@
   }
 
   if (Redeclaration) {
+FunctionDecl *OldFDecl = dyn_cast(OldDecl);
+if (OldFDecl && OldFDecl->isInlineBuiltinDeclaration() &&
+!NewFD->isInlineBuiltinDeclaration())
+  NewFD->setShadowsGNUInlineIntrinsic(true);
+
 // NewFD and OldDecl represent declarations that need to be
 // merged.
 if (MergeFunctionDecl(NewFD, OldDecl, S, MergeTypeWithPrevious)) {
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -1299,18 +1299,34 @@
   // When generating code for a builtin with an inline declaration, use a
   // mangled name to hold the actual body, while keeping an external definition
   // in case the function pointer is referenced somewhere.
-  if (FD->isInlineBuiltinDeclaration() && Fn) {
-std::string FDInlineName = (Fn->getName() + ".inline").str();
-llvm::Module *M = Fn->getParent();
-llvm::Function *Clone = M->getFunction(FDInlineName);
-if (!Clone) {
-  Clone = llvm::Function::Create(Fn->getFunctionType(),
- llvm::GlobalValue::InternalLinkage,
- Fn->getAddressSpace(), FDInlineName, M);
-  Clone->addFnAttr(llvm::Attribute::AlwaysInline);
+  if (Fn) {
+if (FD->isInlineBuiltinDeclaration()) {
+  std::string FDInlineName = (Fn->getName() + ".inline").str();
+  llvm::Module *M = Fn->getParent();
+  llvm::Function *Clone = M->getFunction(FDInlineName);
+  if (!Clone) {
+Clone = llvm::Function::Create(Fn->getFunctionType(),
+   llvm::GlobalValue::InternalLinkage,
+   Fn->getAddressSpace(), FDInlineName, M);
+Clone->addFnAttr(llvm::Attribute::AlwaysInline);
+  }
+  Fn->setLinkage(llvm::GlobalValue::ExternalLinkage);
+  Fn = Clone;
+}
+
+// Detect the unusual situation where an inline version is shadowed by a
+// non-inline version. In that case we should pick the external one
+// everywhere. That's GCC behavior too. Unfortunately, I cannot find a way
+// to detect that situation before we reach codegen, so do some late
+// replacement.
+else if (FD->shadowsGNUInlineIntrinsic()) {
+  std::string FDInlineName = (Fn->getName() + ".inline").str();
+  llvm::Module *M = Fn->getParent();
+  if (llvm::Function *Clone = M->getFunction(FDInlineName)) {
+Clone->replaceAllUsesWith(Fn);
+Clone->eraseFromParent();
+  }
 }
-Fn->setLinkage(llvm::GlobalValue::ExternalLinkage);
-Fn = Clone;
   }
 
   // Check if we should generate debug info for this function.
In

[PATCH] D112600: [ARM] Use hardware TLS register in Thumb2 mode when -mtp=cp15 is passed

2021-10-27 Thread Nathan Chancellor via Phabricator via cfe-commits
nathanchance added a subscriber: peter.smith.
nathanchance added a comment.

I tested this against `next-20211027`, where it resolved the build error and 
boots in QEMU master without any visible issues. Disassembly between GCC and 
clang seems to be good. I'll leave it up to @nickdesaulniers and @peter.smith 
to approve, as I am not very familiar with TableGen.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112600/new/

https://reviews.llvm.org/D112600

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112059: Fix inline builtin handling in case of redefinition

2021-10-27 Thread serge via Phabricator via cfe-commits
serge-sans-paille added inline comments.



Comment at: clang/test/CodeGen/user-func-gnu-inline-redecl.c:20
+  return some_size(s);
+}

nickdesaulniers wrote:
> this test passes before this patch is applied; I wonder if we have existing 
> coverage in tree for this case?
> 
> Surprisingly, I don't think we do. Perhaps `gnu-inline-redecl.c` might be a 
> more concise test name?
> 
> I can't help but shake the feeling that the builtin id stuff is a degenerate 
> case of how GCC treats redeclarations of extern inline (gnu_inline) functions 
> and that perhaps by solving just that, fixing the case of builtins might just 
> "fall out" from that.
Clang indeed naturally handles gnu_inline in a decent way. The problem we're 
trying to solve now is a side effect of the premature renaming of function call 
site when we think it's a direct call to inline builtin. I've updated the 
implementation to avoid walking redecls.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112059/new/

https://reviews.llvm.org/D112059

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 888af47 - [Analyzer][solver] Simplification: reorganize equalities with adjustment

2021-10-27 Thread Gabor Marton via cfe-commits

Author: Gabor Marton
Date: 2021-10-27T16:48:55+02:00
New Revision: 888af47095d5a7121c1d78566df59c292f30ceaf

URL: 
https://github.com/llvm/llvm-project/commit/888af47095d5a7121c1d78566df59c292f30ceaf
DIFF: 
https://github.com/llvm/llvm-project/commit/888af47095d5a7121c1d78566df59c292f30ceaf.diff

LOG: [Analyzer][solver] Simplification: reorganize equalities with adjustment

Initiate the reorganization of the equality information during symbol
simplification. E.g., if we bump into `c + 1 == 0` during simplification
then we'd like to express that `c == -1`. It makes sense to do this only
with `SymIntExpr`s.

Reviewed By: steakhal

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

Added: 
clang/test/Analysis/solver-sym-simplification-adjustment.c

Modified: 
clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp 
b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
index e75a207ee86ab..77f97da4322b3 100644
--- a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -602,10 +602,9 @@ class EquivalenceClass : public llvm::FoldingSetNode {
   areEqual(ProgramStateRef State, SymbolRef First, SymbolRef Second);
 
   /// Iterate over all symbols and try to simplify them.
-  LLVM_NODISCARD static inline ProgramStateRef simplify(SValBuilder &SVB,
-RangeSet::Factory &F,
-ProgramStateRef State,
-EquivalenceClass 
Class);
+  LLVM_NODISCARD static inline ProgramStateRef
+  simplify(SValBuilder &SVB, RangeSet::Factory &F, RangedConstraintManager 
&RCM,
+   ProgramStateRef State, EquivalenceClass Class);
 
   void dumpToStream(ProgramStateRef State, raw_ostream &os) const;
   LLVM_DUMP_METHOD void dump(ProgramStateRef State) const {
@@ -1729,7 +1728,8 @@ bool ConstraintAssignor::assignSymExprToConst(const 
SymExpr *Sym,
   ClassMembersTy Members = State->get();
   for (std::pair ClassToSymbolSet : Members) {
 EquivalenceClass Class = ClassToSymbolSet.first;
-State = EquivalenceClass::simplify(Builder, RangeFactory, State, Class);
+State =
+EquivalenceClass::simplify(Builder, RangeFactory, RCM, State, Class);
 if (!State)
   return false;
 SimplifiedClasses.insert(Class);
@@ -1743,7 +1743,8 @@ bool ConstraintAssignor::assignSymExprToConst(const 
SymExpr *Sym,
 EquivalenceClass Class = ClassConstraint.first;
 if (SimplifiedClasses.count(Class)) // Already simplified.
   continue;
-State = EquivalenceClass::simplify(Builder, RangeFactory, State, Class);
+State =
+EquivalenceClass::simplify(Builder, RangeFactory, RCM, State, Class);
 if (!State)
   return false;
   }
@@ -2126,9 +2127,9 @@ inline Optional 
EquivalenceClass::areEqual(ProgramStateRef State,
 // class to this class. This way, we simplify not just the symbols but the
 // classes as well: we strive to keep the number of the classes to be the
 // absolute minimum.
-LLVM_NODISCARD ProgramStateRef
-EquivalenceClass::simplify(SValBuilder &SVB, RangeSet::Factory &F,
-   ProgramStateRef State, EquivalenceClass Class) {
+LLVM_NODISCARD ProgramStateRef EquivalenceClass::simplify(
+SValBuilder &SVB, RangeSet::Factory &F, RangedConstraintManager &RCM,
+ProgramStateRef State, EquivalenceClass Class) {
   SymbolSet ClassMembers = Class.getClassMembers(State);
   for (const SymbolRef &MemberSym : ClassMembers) {
 
@@ -2149,9 +2150,30 @@ EquivalenceClass::simplify(SValBuilder &SVB, 
RangeSet::Factory &F,
   // The simplified symbol should be the member of the original Class,
   // however, it might be in another existing class at the moment. We
   // have to merge these classes.
+  ProgramStateRef OldState = State;
   State = merge(F, State, MemberSym, SimplifiedMemberSym);
   if (!State)
 return nullptr;
+  // No state change, no merge happened actually.
+  if (OldState == State)
+continue;
+
+  // Initiate the reorganization of the equality information. E.g., if we
+  // have `c + 1 == 0` then we'd like to express that `c == -1`. It makes
+  // sense to do this only with `SymIntExpr`s.
+  // TODO Handle `IntSymExpr` as well, once computeAdjustment can handle
+  // them.
+  if (const SymIntExpr *SIE = dyn_cast(SimplifiedMemberSym)) {
+if (const RangeSet *ClassConstraint = getConstraint(State, Class)) {
+  // Overestimate the individual Ranges with the RangeSet' lowest and
+  // highest values.
+  State = RCM.assumeSymInclusiveRange(
+  State, SIE, ClassConstraint->getMinValue(),
+  ClassConstraint->getMaxValue(), /*InRange=*

[PATCH] D111642: [Analyzer][solver] Simplification: reorganize equalities with adjustment

2021-10-27 Thread Gabor Marton via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG888af47095d5: [Analyzer][solver] Simplification: reorganize 
equalities with adjustment (authored by martong).

Changed prior to commit:
  https://reviews.llvm.org/D111642?vs=381536&id=382674#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D111642/new/

https://reviews.llvm.org/D111642

Files:
  clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
  clang/test/Analysis/solver-sym-simplification-adjustment.c

Index: clang/test/Analysis/solver-sym-simplification-adjustment.c
===
--- /dev/null
+++ clang/test/Analysis/solver-sym-simplification-adjustment.c
@@ -0,0 +1,111 @@
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=false \
+// RUN:   -verify
+
+void clang_analyzer_warnIfReached();
+void clang_analyzer_eval();
+
+void test_simplification_adjustment_concrete_int(int b, int c) {
+  if (b < 0 || b > 1)  // b: [0,1]
+return;
+  if (c < -1 || c > 1) // c: [-1,1]
+return;
+  if (c + b != 0)  // c + b == 0
+return;
+  clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+  if (b != 1)  // b == 1  --> c + 1 == 0 --> c == -1
+return;
+  clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+  clang_analyzer_eval(c == -1);   // expected-warning{{TRUE}}
+
+  // Keep the symbols and the constraints! alive.
+  (void)(b * c);
+  return;
+}
+
+void test_simplification_adjustment_range(int b, int c) {
+  if (b < 0 || b > 1)  // b: [0,1]
+return;
+  if (c < -1 || c > 1) // c: [-1,1]
+return;
+  if (c + b < -1 || c + b > 0) // c + b: [-1,0]
+return;
+  clang_analyzer_warnIfReached();  // expected-warning{{REACHABLE}}
+  if (b != 1)  // b == 1  --> c + 1: [-1,0] --> c: [-2,-1]
+return;
+   // c: [-2,-1] is intersected with the
+   // already associated range which is [-1,1],
+   // thus we get c: [-1,-1]
+  clang_analyzer_warnIfReached();  // expected-warning{{REACHABLE}}
+  clang_analyzer_eval(c == -1);// expected-warning{{TRUE}}
+
+  // Keep the symbols and the constraints! alive.
+  (void)(b * c);
+  return;
+}
+
+void test_simplification_adjustment_to_infeasible_concrete_int(int b, int c) {
+  if (b < 0 || b > 1) // b: [0,1]
+return;
+  if (c < 0 || c > 1) // c: [0,1]
+return;
+  if (c + b != 0) // c + b == 0
+return;
+  clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+  if (b != 1) {   // b == 1  --> c + 1 == 0 --> c == -1 contradiction
+clang_analyzer_eval(b == 0);  // expected-warning{{TRUE}}
+clang_analyzer_eval(c == 0);  // expected-warning{{TRUE}}
+// Keep the symbols and the constraints! alive.
+(void)(b * c);
+return;
+  }
+  clang_analyzer_warnIfReached(); // no warning
+
+  // Keep the symbols and the constraints! alive.
+  (void)(b * c);
+  return;
+}
+
+void test_simplification_adjustment_to_infeassible_range(int b, int c) {
+  if (b < 0 || b > 1)  // b: [0,1]
+return;
+  if (c < 0 || c > 1)  // c: [0,1]
+return;
+  if (c + b < -1 || c + b > 0) // c + b: [-1,0]
+return;
+  clang_analyzer_warnIfReached();  // expected-warning{{REACHABLE}}
+  if (b != 1)  // b == 1  --> c + 1: [-1,0] --> c: [-2,-1] contradiction
+return;
+  clang_analyzer_warnIfReached();  // no warning
+
+  // Keep the symbols and the constraints! alive.
+  (void)(b * c);
+  return;
+}
+
+void test_simplification_adjusment_no_infinite_loop(int a, int b, int c) {
+  if (a == b)// a != b
+return;
+  if (c != 0)// c == 0
+return;
+
+  if (b != 0)// b == 0
+return;
+  // The above simplification of `b == 0` could result in an infinite loop
+  // unless we detect that the State is unchanged.
+  // The loop:
+  // 1) Simplification of the trivial equivalence class
+  //  "symbol": "(reg_$0) == (reg_$1)", "range": "{ [0, 0] }"
+  //results in
+  //  "symbol": "(reg_$0) == 0", "range": "{ [0, 0] }" }
+  //which in turn creates a non-trivial equivalence class
+  //  [ "(reg_$0) == (reg_$1)", "(reg_$0) == 0" ]
+  // 2) We call assumeSymInclusiveRange("(reg_$0) == 0")
+  //and that calls **simplify** on the associated non-trivial equivalence
+  //class. During the simplification the State does not change, we reached
+  //the fixpoint.
+
+  (void)(a * b * c);
+}
Index: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Cor

[PATCH] D111642: [Analyzer][solver] Simplification: reorganize equalities with adjustment

2021-10-27 Thread Gabor Marton via Phabricator via cfe-commits
martong marked an inline comment as done.
martong added a comment.

Thanks for the assiduous review guys!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D111642/new/

https://reviews.llvm.org/D111642

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D107339: [analyzer] Retrieve a character from StringLiteral as an initializer for constant arrays.

2021-10-27 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

It looks good to me. I don't mind that FIXME. That being said, I'm not even 
sure it's a FIXME.
Check my comment inline about this.




Comment at: clang/lib/StaticAnalyzer/Core/RegionStore.cpp:1757-1760
+  // FIXME: Nevertheless, we can't do the same for cases, like:
+  //   const char *str = "123"; // literal length is 4
+  //   char c = str[41];// offset is 41
+  // It should be properly handled before reaching this point.

martong wrote:
> ASDenysPetrov wrote:
> > ASDenysPetrov wrote:
> > > martong wrote:
> > > > Thanks for updating the patch! However, this `FIXME` makes me worried. 
> > > > Do you think you could pass the `Decl` itself to 
> > > > `getSValFromInitListExpr` in order to be able to check whether the type 
> > > > is a pointer or an array? 
> > > This worried me as well. Currently I can't find a way to get the `Decl` 
> > > for `SL`.
> > > 
> > We can load this as is for now with mentioning the known issue.
> This might cause some itchy false positives. Perhaps, we could address this 
> in a follow-up patch and then commit them together?
> Currently I can't find a way to get the Decl for SL.
Why do you need a Decl? The SVal's gotta be an `Element{"123",41 S64b,char}` 
for the example in the comment (*).

(*) With a minor modification: https://godbolt.org/z/7zhGMnf7P
```lang=C++
template  void clang_analyzer_dump(T);
const char * const str = "123";
const char * str2 = "123";
void top() {
  clang_analyzer_dump(&str[41]);  // &Element{"123",41 S64b,char}
  clang_analyzer_dump(&str2[41]); // &Element{SymRegion{reg_$0},41 S64b,char}
}
```



Comment at: clang/lib/StaticAnalyzer/Core/RegionStore.cpp:1784-1786
+  const auto Offset = static_cast(Idx.getExtValue());
+  if (Idx < 0)
 return UndefinedVal();

I think it would be better to have the check before we calculate the `Offset`. 
At least that way I find it easier to follow.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D107339/new/

https://reviews.llvm.org/D107339

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D108696: [Coroutines] [Frontend] Lookup in std namespace first

2021-10-27 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added a comment.

@lewissbaker wrote:

>   #include  // which transitively includes 
>   #include 

Good example! I had not previously been thinking about transitive includes. I 
believe we "obviously" don't need to cater to code that manually includes both 
`` and `` in the same source file; but 
transitive includes are //vastly// more likely to happen in practice, and so if 
we're not going to care about //them//, that's a policy decision. Might still 
be a good tradeoff, to break some code in the short term in exchange for a 
simpler compiler (also in the short term), but its goodness is not //obvious.//

> The only way I can think of making this work is to just make 
> `std::experimental::*` an alias for `std::*`.
> But that only works for `std::experimental::coroutine_handle`. It doesn't 
> work for `std::experimental::coroutine_traits` as you can't add 
> specialisations through an alias.

We //could// use a `using`-declaration to bring `std::coroutine_traits` into 
`namespace std::experimental`. That works, and you can still add 
specializations for `std::experimental::coroutine_traits` because that's 
just a //name// that looks-up-to the same template. 
https://godbolt.org/z/fWGrT5js5 However, as shown in that godbolt, this would 
have the (salutary) effect of breaking users who are out there (in the year of 
our lord 2021!) still reopening `namespace std` just to add a template 
specialization.

But! My understanding is that the only reason we're keeping 
`` alive at all, in 14.x, is to provide continuity for 
its users and not break their existing code right away. If we go changing the 
API of `` (by aliasing it to ``), then we 
//do// break those users right away (because their code depends on the old 
experimental API, not the new conforming one). So "alias it to ``" 
doesn't seem like a viable path forward, anyway. (Also, `` wants to 
use C++20-only features, but `` must continue to work 
in C++14.)  I think we need to start from the premise that 
`` and `` will have different APIs; and if 
that makes it difficult to support Lewis's very reasonable transitive-include 
scenario, then we have to either implement something difficult, or else make a 
policy decision that 14.x simply won't support translation units that 
transitively include both APIs. (15.x certainly will not support such TUs, 
because it won't support //any// TUs that include ``, 
transitively or otherwise.)

IOW, it sounds like we're all (@ChuanqiXu @lewissbaker @Quuxplusone) 
reluctantly OK with the resolution "Do not support translation units that 
transitively include both APIs"; but it would be helpful to have someone more 
authoritative weigh in (with either "yes that's OK policy" or "no we //need// 
to find some other solution"), if such a person is watching.




Comment at: clang/docs/LanguageExtensions.rst:2872
 https://wg21.link/P0057. The following four are intended to be used by the
-standard library to implement `std::experimental::coroutine_handle` type.
+standard library to implement `std::coroutine_handle` type.
 

```
to implement the ``std::coroutine_handle`` type.
```



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:11002
 def err_coroutine_handle_missing_member : Error<
-  "std::experimental::coroutine_handle missing a member named '%0'">;
+  "std::coroutine_handle missing a member named '%0'">;
 def err_malformed_std_coroutine_traits : Error<

Pre-existing: It's weird that the surrounding messages are of the form "foo 
must be bar," and then this one is "foo isn't baz". This message //could// be 
re-worded as `std::coroutine_handle must have a member named '%0'` for 
consistency. (But that might be out of scope for this PR.)



Comment at: clang/include/clang/Sema/Sema.h:10274
+  /// Lookup 'coroutine_traits' in std namespace and std::experimental
+  /// namespace. The namespace found would be recorded in Namespace.
   ClassTemplateDecl *lookupCoroutineTraits(SourceLocation KwLoc,

`s/would be/is/`



Comment at: clang/lib/Sema/SemaCoroutine.cpp:1668
+if (!CoroNamespace || !LookupQualifiedName(Result, CoroNamespace)) {
+  /// TODO: Lookup in std::expeirmental namespace for compability.
+  /// Remove this once users get familiar with coroutine under std

ldionne wrote:
> 
```
/// Look up in namespace std::experimental, for compatibility.
/// TODO: Remove this extra lookup when  is removed.
```
(The extra lookup is done, not TODO. The //removal// is the TODO part. Also, 
grammar nits.)



Comment at: clang/test/AST/coroutine-source-location-crash.cpp:12-14
 #include "Inputs/std-coroutine.h"
 
+using namespace std;

Thanks for adding `-exp-namespace` versions of the Sema tests. I think you 
should do the same for all of these tests as well, for the same reason: we 
don't want to remove test coverage related to `std::

[clang] 749581d - [IR] `IRBuilderBase::CreateAnd()`: fix short-circuiting for constant on LHS

2021-10-27 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2021-10-27T18:01:06+03:00
New Revision: 749581d21f2b3f53e4fca4eb8728c942d646893b

URL: 
https://github.com/llvm/llvm-project/commit/749581d21f2b3f53e4fca4eb8728c942d646893b
DIFF: 
https://github.com/llvm/llvm-project/commit/749581d21f2b3f53e4fca4eb8728c942d646893b.diff

LOG: [IR] `IRBuilderBase::CreateAnd()`: fix short-circuiting for constant on LHS

Refs. https://reviews.llvm.org/D109368#3089809

Added: 


Modified: 
clang/test/CodeGen/arm-mve-intrinsics/vadc.c
clang/test/CodeGen/catch-nullptr-and-nonzero-offset.c
clang/test/CodeGenCXX/ext-vector-type-conditional.cpp
clang/test/CodeGenObjC/ubsan-nullability.m
llvm/include/llvm/IR/IRBuilder.h
llvm/test/Transforms/LoopIdiom/X86/left-shift-until-bittest.ll
llvm/test/Transforms/LoopPredication/basic.ll
llvm/test/Transforms/LoopPredication/basic_widenable_branch_guards.ll
llvm/test/Transforms/LoopPredication/invariant_load.ll
llvm/test/Transforms/LowerTypeTests/import.ll

Removed: 




diff  --git a/clang/test/CodeGen/arm-mve-intrinsics/vadc.c 
b/clang/test/CodeGen/arm-mve-intrinsics/vadc.c
index 5e428efd1b29c..29d17e73eb341 100644
--- a/clang/test/CodeGen/arm-mve-intrinsics/vadc.c
+++ b/clang/test/CodeGen/arm-mve-intrinsics/vadc.c
@@ -9,7 +9,7 @@
 // CHECK-NEXT:[[TMP0:%.*]] = call { <4 x i32>, i32 } 
@llvm.arm.mve.vadc.v4i32(<4 x i32> [[A:%.*]], <4 x i32> [[B:%.*]], i32 0)
 // CHECK-NEXT:[[TMP1:%.*]] = extractvalue { <4 x i32>, i32 } [[TMP0]], 1
 // CHECK-NEXT:[[TMP2:%.*]] = lshr i32 [[TMP1]], 29
-// CHECK-NEXT:[[TMP3:%.*]] = and i32 1, [[TMP2]]
+// CHECK-NEXT:[[TMP3:%.*]] = and i32 [[TMP2]], 1
 // CHECK-NEXT:store i32 [[TMP3]], i32* [[CARRY_OUT:%.*]], align 4
 // CHECK-NEXT:[[TMP4:%.*]] = extractvalue { <4 x i32>, i32 } [[TMP0]], 0
 // CHECK-NEXT:ret <4 x i32> [[TMP4]]
@@ -30,7 +30,7 @@ int32x4_t test_vadciq_s32(int32x4_t a, int32x4_t b, unsigned 
*carry_out)
 // CHECK-NEXT:[[TMP2:%.*]] = call { <4 x i32>, i32 } 
@llvm.arm.mve.vadc.v4i32(<4 x i32> [[A:%.*]], <4 x i32> [[B:%.*]], i32 [[TMP1]])
 // CHECK-NEXT:[[TMP3:%.*]] = extractvalue { <4 x i32>, i32 } [[TMP2]], 1
 // CHECK-NEXT:[[TMP4:%.*]] = lshr i32 [[TMP3]], 29
-// CHECK-NEXT:[[TMP5:%.*]] = and i32 1, [[TMP4]]
+// CHECK-NEXT:[[TMP5:%.*]] = and i32 [[TMP4]], 1
 // CHECK-NEXT:store i32 [[TMP5]], i32* [[CARRY]], align 4
 // CHECK-NEXT:[[TMP6:%.*]] = extractvalue { <4 x i32>, i32 } [[TMP2]], 0
 // CHECK-NEXT:ret <4 x i32> [[TMP6]]
@@ -51,7 +51,7 @@ uint32x4_t test_vadcq_u32(uint32x4_t a, uint32x4_t b, 
unsigned *carry)
 // CHECK-NEXT:[[TMP2:%.*]] = call { <4 x i32>, i32 } 
@llvm.arm.mve.vadc.predicated.v4i32.v4i1(<4 x i32> [[INACTIVE:%.*]], <4 x i32> 
[[A:%.*]], <4 x i32> [[B:%.*]], i32 0, <4 x i1> [[TMP1]])
 // CHECK-NEXT:[[TMP3:%.*]] = extractvalue { <4 x i32>, i32 } [[TMP2]], 1
 // CHECK-NEXT:[[TMP4:%.*]] = lshr i32 [[TMP3]], 29
-// CHECK-NEXT:[[TMP5:%.*]] = and i32 1, [[TMP4]]
+// CHECK-NEXT:[[TMP5:%.*]] = and i32 [[TMP4]], 1
 // CHECK-NEXT:store i32 [[TMP5]], i32* [[CARRY_OUT:%.*]], align 4
 // CHECK-NEXT:[[TMP6:%.*]] = extractvalue { <4 x i32>, i32 } [[TMP2]], 0
 // CHECK-NEXT:ret <4 x i32> [[TMP6]]
@@ -74,7 +74,7 @@ uint32x4_t test_vadciq_m_u32(uint32x4_t inactive, uint32x4_t 
a, uint32x4_t b, un
 // CHECK-NEXT:[[TMP4:%.*]] = call { <4 x i32>, i32 } 
@llvm.arm.mve.vadc.predicated.v4i32.v4i1(<4 x i32> [[INACTIVE:%.*]], <4 x i32> 
[[A:%.*]], <4 x i32> [[B:%.*]], i32 [[TMP1]], <4 x i1> [[TMP3]])
 // CHECK-NEXT:[[TMP5:%.*]] = extractvalue { <4 x i32>, i32 } [[TMP4]], 1
 // CHECK-NEXT:[[TMP6:%.*]] = lshr i32 [[TMP5]], 29
-// CHECK-NEXT:[[TMP7:%.*]] = and i32 1, [[TMP6]]
+// CHECK-NEXT:[[TMP7:%.*]] = and i32 [[TMP6]], 1
 // CHECK-NEXT:store i32 [[TMP7]], i32* [[CARRY]], align 4
 // CHECK-NEXT:[[TMP8:%.*]] = extractvalue { <4 x i32>, i32 } [[TMP4]], 0
 // CHECK-NEXT:ret <4 x i32> [[TMP8]]
@@ -93,7 +93,7 @@ int32x4_t test_vadcq_m_s32(int32x4_t inactive, int32x4_t a, 
int32x4_t b, unsigne
 // CHECK-NEXT:[[TMP0:%.*]] = call { <4 x i32>, i32 } 
@llvm.arm.mve.vsbc.v4i32(<4 x i32> [[A:%.*]], <4 x i32> [[B:%.*]], i32 0)
 // CHECK-NEXT:[[TMP1:%.*]] = extractvalue { <4 x i32>, i32 } [[TMP0]], 1
 // CHECK-NEXT:[[TMP2:%.*]] = lshr i32 [[TMP1]], 29
-// CHECK-NEXT:[[TMP3:%.*]] = and i32 1, [[TMP2]]
+// CHECK-NEXT:[[TMP3:%.*]] = and i32 [[TMP2]], 1
 // CHECK-NEXT:store i32 [[TMP3]], i32* [[CARRY_OUT:%.*]], align 4
 // CHECK-NEXT:[[TMP4:%.*]] = extractvalue { <4 x i32>, i32 } [[TMP0]], 0
 // CHECK-NEXT:ret <4 x i32> [[TMP4]]
@@ -111,7 +111,7 @@ int32x4_t test_vsbciq_s32(int32x4_t a, int32x4_t b, 
unsigned *carry_out) {
 // CHECK-NEXT:[[TMP0:%.*]] = call { <4 x i32>, i32 } 
@llvm.arm.mve.vsbc.v4i32(<4 x i32> [[A:%.*]], <4 x i32> [[B:%.*]], i32 0)
 // CHECK-NEXT:[[TMP1:%.*]] = extractvalue { <4 x i32>, i3

[clang] f3190de - [IR] `IRBuilderBase::CreateAnd()`: short-circuit `x & 0` --> `0`

2021-10-27 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2021-10-27T18:01:06+03:00
New Revision: f3190dedeef9da2109ea57e4cb372f295ff53b88

URL: 
https://github.com/llvm/llvm-project/commit/f3190dedeef9da2109ea57e4cb372f295ff53b88
DIFF: 
https://github.com/llvm/llvm-project/commit/f3190dedeef9da2109ea57e4cb372f295ff53b88.diff

LOG: [IR] `IRBuilderBase::CreateAnd()`: short-circuit `x & 0` --> `0`

https://alive2.llvm.org/ce/z/YzPhSb

Refs. https://reviews.llvm.org/D109368#3089809

Added: 


Modified: 
clang/test/CodeGen/catch-nullptr-and-nonzero-offset.c
llvm/include/llvm/IR/IRBuilder.h
llvm/test/Transforms/LoopPredication/basic.ll
llvm/test/Transforms/LoopPredication/reverse.ll

Removed: 




diff  --git a/clang/test/CodeGen/catch-nullptr-and-nonzero-offset.c 
b/clang/test/CodeGen/catch-nullptr-and-nonzero-offset.c
index 12c4893ae1d1..191a6dac0a6b 100644
--- a/clang/test/CodeGen/catch-nullptr-and-nonzero-offset.c
+++ b/clang/test/CodeGen/catch-nullptr-and-nonzero-offset.c
@@ -172,13 +172,13 @@ char *nullptr_var(unsigned long offset) {
   // CHECK-SANITIZE-NEXT:   %[[COMPUTED_OFFSET:.*]] = extractvalue 
{ i64, i1 } %[[COMPUTED_OFFSET_AGGREGATE]], 0, !nosanitize
   // CHECK-SANITIZE-NEXT:   %[[COMPUTED_GEP:.*]] = add i64 0, 
%[[COMPUTED_OFFSET]], !nosanitize
   // CHECK-SANITIZE-NEXT:   %[[COMPUTED_GEP_IS_NOT_NULL:.*]] = 
icmp ne i64 %[[COMPUTED_GEP]], 0, !nosanitize
-  // CHECK-SANITIZE-C-NEXT: 
%[[BOTH_POINTERS_ARE_NULL_OR_BOTH_ARE_NONNULL:.*]] = and i1 
%[[COMPUTED_GEP_IS_NOT_NULL]], false, !nosanitize
   // CHECK-SANITIZE-CPP-NEXT:   
%[[BOTH_POINTERS_ARE_NULL_OR_BOTH_ARE_NONNULL:.*]] = icmp eq i1 false, 
%[[COMPUTED_GEP_IS_NOT_NULL]], !nosanitize
   // CHECK-SANITIZE-NEXT:   
%[[COMPUTED_OFFSET_DID_NOT_OVERFLOW:.*]] = xor i1 
%[[COMPUTED_OFFSET_OVERFLOWED]], true, !nosanitize
   // CHECK-SANITIZE-NEXT:   %[[COMPUTED_GEP_IS_UGE_BASE:.*]] = 
icmp uge i64 %[[COMPUTED_GEP]], 0, !nosanitize
   // CHECK-SANITIZE-NEXT:   %[[GEP_DID_NOT_OVERFLOW:.*]] = and i1 
%[[COMPUTED_GEP_IS_UGE_BASE]], %[[COMPUTED_OFFSET_DID_NOT_OVERFLOW]], 
!nosanitize
-  // CHECK-SANITIZE-NEXT:   %[[GEP_IS_OKAY:.*]] = and i1 
%[[BOTH_POINTERS_ARE_NULL_OR_BOTH_ARE_NONNULL]], %[[GEP_DID_NOT_OVERFLOW]], 
!nosanitize
-  // CHECK-SANITIZE-NEXT:   br i1 %[[GEP_IS_OKAY]], label 
%[[CONT:.*]], label %[[HANDLER_POINTER_OVERFLOW:[^,]+]],{{.*}} !nosanitize
+  // CHECK-SANITIZE-CPP-NEXT:   %[[GEP_IS_OKAY:.*]] = and i1 
%[[BOTH_POINTERS_ARE_NULL_OR_BOTH_ARE_NONNULL]], %[[GEP_DID_NOT_OVERFLOW]], 
!nosanitize
+  // CHECK-SANITIZE-C-NEXT: br i1 false, label %[[CONT:.*]], label 
%[[HANDLER_POINTER_OVERFLOW:[^,]+]],{{.*}} !nosanitize
+  // CHECK-SANITIZE-CPP-NEXT:   br i1 %[[GEP_IS_OKAY]], label 
%[[CONT:.*]], label %[[HANDLER_POINTER_OVERFLOW:[^,]+]],{{.*}} !nosanitize
   // CHECK-SANITIZE:  [[HANDLER_POINTER_OVERFLOW]]:
   // CHECK-SANITIZE-NORECOVER-NEXT: call void 
@__ubsan_handle_pointer_overflow_abort(i8* bitcast ({ {{{.*}}} }* @[[LINE_500]] 
to i8*), i64 0, i64 %[[COMPUTED_GEP]])
   // CHECK-SANITIZE-RECOVER-NEXT:   call void 
@__ubsan_handle_pointer_overflow(i8* bitcast ({ {{{.*}}} }* @[[LINE_500]] to 
i8*), i64 0, i64 %[[COMPUTED_GEP]])

diff  --git a/llvm/include/llvm/IR/IRBuilder.h 
b/llvm/include/llvm/IR/IRBuilder.h
index 7b3a4c6d714a..c7899681835e 100644
--- a/llvm/include/llvm/IR/IRBuilder.h
+++ b/llvm/include/llvm/IR/IRBuilder.h
@@ -1362,9 +1362,13 @@ class IRBuilderBase {
   Value *CreateAnd(Value *LHS, Value *RHS, const Twine &Name = "") {
 if (!isa(RHS) && isa(LHS))
   std::swap(LHS, RHS);
-if (auto *RC = dyn_cast(RHS)) {
-  if (isa(RC) && cast(RC)->isMinusOne())
+if (auto RCI = dyn_cast(RHS)) {
+  if (RCI->isZero())
+return RHS; // LHS & 0 -> 0
+  if (RCI->isMinusOne())
 return LHS;  // LHS & -1 -> LHS
+}
+if (auto *RC = dyn_cast(RHS)) {
   if (auto *LC = dyn_cast(LHS))
 return Insert(Folder.CreateAnd(LC, RC), Name);
 }

diff  --git a/llvm/test/Transforms/LoopPredication/basic.ll 
b/llvm/test/Transforms/LoopPredication/basic.ll
index 9972caae5713..1f64e4383c51 100644
--- a/llvm/test/Transforms/LoopPredication/basic.ll
+++ b/llvm/test/Transforms/LoopPredication/basic.ll
@@ -1554,12 +1554,11 @@ define i32 @provably_taken(i32* %array, i32* 
%length.ptr) {
 ; CHECK-NEXT:  loop.preheader:
 ; CHECK-NEXT:[[LENGTH:%.*]] = load i32, i32* [[LENGTH_PTR:%.*]], align 4, 
!range [[RNG1:![0-9]+]]
 ; CHECK-NEXT:[[TMP0:%.*]] = icmp ult i32 0, [[LENGTH]]
-; CHECK-NEXT:[[TMP1:%.*]] = and i1 [[TMP0]], false
 ; CHECK-NEXT:br label [[LOOP:%.*]]
 ; CHECK:   loop:
 ; CHECK-NEXT:[[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[LOOP]] 
], [ 0, [[LOOP_PREHEADER:%.*]] ]
 ; CHECK-NEXT:[[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[LOO

[PATCH] D99797: [analyzer] Implemented RangeSet::Factory::unite function to handle intersections and adjacency

2021-10-27 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov updated this revision to Diff 382679.
ASDenysPetrov added a comment.

@martong @steakhal 
Updated according to your comments. Thank you!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99797/new/

https://reviews.llvm.org/D99797

Files:
  
clang/include/clang/StaticAnalyzer/Core/PathSensitive/RangedConstraintManager.h
  clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
  clang/unittests/StaticAnalyzer/RangeSetTest.cpp

Index: clang/unittests/StaticAnalyzer/RangeSetTest.cpp
===
--- clang/unittests/StaticAnalyzer/RangeSetTest.cpp
+++ clang/unittests/StaticAnalyzer/RangeSetTest.cpp
@@ -35,12 +35,34 @@
   const RangeSet &Set) {
   return OS << toString(Set);
 }
+// We need it here for better fail diagnostics from gtest.
+LLVM_ATTRIBUTE_UNUSED static std::ostream &operator<<(std::ostream &OS,
+  const Range &R) {
+  return OS << toString(R);
+}
 
 } // namespace ento
 } // namespace clang
 
 namespace {
 
+template  struct TestValues {
+  static constexpr T MIN = std::numeric_limits::min();
+  static constexpr T MAX = std::numeric_limits::max();
+  // MID is a value in the middle of the range
+  // which unary minus does not affect on,
+  // e.g. int8/int32(0), uint8(128), uint32(2147483648).
+  static constexpr T MID =
+  std::is_signed::value ? 0 : ~(static_cast(-1) / static_cast(2));
+  static constexpr T A = MID - (MAX - MID) / 3 * 2;
+  static constexpr T B = MID - (MAX - MID) / 3;
+  static constexpr T C = -B;
+  static constexpr T D = -A;
+
+  static_assert(MIN < A && A < B && B < MID && MID < C && C < D && D < MAX,
+"Values shall be in an ascending order");
+};
+
 template  class RangeSetTest : public testing::Test {
 public:
   // Init block
@@ -54,25 +76,13 @@
   using Self = RangeSetTest;
   using RawRange = std::pair;
   using RawRangeSet = std::initializer_list;
+  static constexpr size_t BITS_IN_BYTE = 8;
 
-  static constexpr BaseType getMin() {
-return std::numeric_limits::min();
-  }
-  static constexpr BaseType getMax() {
-return std::numeric_limits::max();
-  }
-  static constexpr BaseType getMid() {
-return isSigned() ? 0 : ~(fromInt(-1) / fromInt(2));
-  }
-
-  static constexpr bool isSigned() { return std::is_signed::value; }
-  static constexpr BaseType fromInt(int X) { return static_cast(X); }
-
-  static llvm::APSInt Base;
   const llvm::APSInt &from(BaseType X) {
-llvm::APSInt Dummy = Base;
-Dummy = X;
-return BVF.getValue(Dummy);
+static llvm::APSInt Base{sizeof(BaseType) * BITS_IN_BYTE,
+ std::is_unsigned::value};
+Base = X;
+return BVF.getValue(Base);
   }
 
   Range from(const RawRange &Init) {
@@ -160,7 +170,7 @@
 
   void checkAdd(RawRangeSet RawLHS, RawRangeSet RawRHS,
 RawRangeSet RawExpected) {
-wrap(&Self::checkAddImpl, RawRHS, RawLHS, RawExpected);
+wrap(&Self::checkAddImpl, RawLHS, RawRHS, RawExpected);
   }
 
   void checkAdd(RawRangeSet RawLHS, BaseType RawRHS, RawRangeSet RawExpected) {
@@ -168,6 +178,29 @@
  RawExpected);
   }
 
+  template 
+  void checkUniteImpl(RangeSet LHS, RHSType RHS, RangeSet Expected) {
+RangeSet Result = F.unite(LHS, RHS);
+EXPECT_EQ(Result, Expected)
+<< "while uniting " << toString(LHS) << " and " << toString(RHS);
+  }
+
+  void checkUnite(RawRangeSet RawLHS, RawRange RawRHS,
+  RawRangeSet RawExpected) {
+wrap(&Self::checkUniteImpl, RawLHS, RawRHS, RawExpected);
+  }
+
+  void checkUnite(RawRangeSet RawLHS, RawRangeSet RawRHS,
+  RawRangeSet RawExpected) {
+wrap(&Self::checkUniteImpl, RawLHS, RawRHS, RawExpected);
+  }
+
+  void checkUnite(RawRangeSet RawLHS, BaseType RawRHS,
+  RawRangeSet RawExpected) {
+wrap(&Self::checkUniteImpl, RawLHS, RawRHS,
+ RawExpected);
+  }
+
   void checkDeleteImpl(const llvm::APSInt &Point, RangeSet From,
RangeSet Expected) {
 RangeSet Result = F.deletePoint(From, Point);
@@ -183,29 +216,19 @@
 
 } // namespace
 
-template 
-llvm::APSInt RangeSetTest::Base{sizeof(BaseType) * 8, !isSigned()};
-
 using IntTypes = ::testing::Types;
 TYPED_TEST_SUITE(RangeSetTest, IntTypes, );
 
 TYPED_TEST(RangeSetTest, RangeSetNegateTest) {
-  // Use next values of the range {MIN, A, B, MID, C, D, MAX}.
-
-  constexpr TypeParam MIN = TestFixture::getMin();
-  constexpr TypeParam MAX = TestFixture::getMax();
-  // MID is a value in the middle of the range
-  // which unary minus does not affect on,
-  // e.g. int8/int32(0), uint8(128), uint32(2147483648).
-  constexpr TypeParam MID = TestFixture::getMid();
-  constexpr TypeParam A = MID - TestFixture::fromInt(42 + 42);
-  constexpr TypeParam B = MID - TestFixture::fromInt(42);
-  constexpr TypeParam C = -B;
-  constexpr TypeParam D = -A;
-
-  static_assert(MIN <

[PATCH] D112296: [Analyzer][solver] Handle adjustments in constraint assignor remainder

2021-10-27 Thread Gabor Marton via Phabricator via cfe-commits
martong marked an inline comment as done.
martong added a comment.

@ASDenysPetrov @steakhal Thanks for the assiduous reviews!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112296/new/

https://reviews.llvm.org/D112296

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] a8297ed - [Analyzer][solver] Handle adjustments in constraint assignor remainder

2021-10-27 Thread Gabor Marton via cfe-commits

Author: Gabor Marton
Date: 2021-10-27T17:14:34+02:00
New Revision: a8297ed994301dbf34f259690e9f5fa8fce96ea2

URL: 
https://github.com/llvm/llvm-project/commit/a8297ed994301dbf34f259690e9f5fa8fce96ea2
DIFF: 
https://github.com/llvm/llvm-project/commit/a8297ed994301dbf34f259690e9f5fa8fce96ea2.diff

LOG: [Analyzer][solver] Handle adjustments in constraint assignor remainder

We can reuse the "adjustment" handling logic in the higher level
of the solver by calling `State->assume`.

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

Added: 


Modified: 
clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
clang/test/Analysis/constraint-assignor.c

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp 
b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
index 77f97da4322b3..6e4ee6e337ce5 100644
--- a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -1614,14 +1614,14 @@ class ConstraintAssignor : public 
ConstraintAssignorBase {
   bool handleRemainderOp(const SymT *Sym, RangeSet Constraint) {
 if (Sym->getOpcode() != BO_Rem)
   return true;
-const SymbolRef LHS = Sym->getLHS();
-const llvm::APSInt &Zero =
-Builder.getBasicValueFactory().getValue(0, Sym->getType());
 // a % b != 0 implies that a != 0.
 if (!Constraint.containsZero()) {
-  State = RCM.assumeSymNE(State, LHS, Zero, Zero);
-  if (!State)
-return false;
+  SVal SymSVal = Builder.makeSymbolVal(Sym->getLHS());
+  if (auto NonLocSymSVal = SymSVal.getAs()) {
+State = State->assume(*NonLocSymSVal, true);
+if (!State)
+  return false;
+  }
 }
 return true;
   }

diff  --git a/clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp 
b/clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
index 80f3054a5a37f..892d64ea4e4e2 100644
--- a/clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
@@ -41,7 +41,12 @@ ProgramStateRef 
RangedConstraintManager::assumeSym(ProgramStateRef State,
   return assumeSymRel(State, SIE->getLHS(), op, SIE->getRHS());
 }
 
-  } else if (const SymSymExpr *SSE = dyn_cast(Sym)) {
+// Handle adjustment with non-comparison ops.
+const llvm::APSInt &Zero = getBasicVals().getValue(0, SIE->getType());
+return assumeSymRel(State, SIE, (Assumption ? BO_NE : BO_EQ), Zero);
+  }
+
+  if (const auto *SSE = dyn_cast(Sym)) {
 BinaryOperator::Opcode Op = SSE->getOpcode();
 assert(BinaryOperator::isComparisonOp(Op));
 

diff  --git a/clang/test/Analysis/constraint-assignor.c 
b/clang/test/Analysis/constraint-assignor.c
index 1c041e3e0ce45..1b9e40e6bf649 100644
--- a/clang/test/Analysis/constraint-assignor.c
+++ b/clang/test/Analysis/constraint-assignor.c
@@ -3,9 +3,8 @@
 // RUN:   -analyzer-checker=debug.ExprInspection \
 // RUN:   -verify
 
-// expected-no-diagnostics
-
 void clang_analyzer_warnIfReached();
+void clang_analyzer_eval(int);
 
 void rem_constant_rhs_ne_zero(int x, int y) {
   if (x % 3 == 0) // x % 3 != 0 -> x != 0
@@ -67,3 +66,19 @@ void internal_unsigned_signed_mismatch(unsigned a) {
   if (d % 2 != 0)
 return;
 }
+
+void remainder_with_adjustment(int x) {
+  if ((x + 1) % 3 == 0) // (x + 1) % 3 != 0 -> x + 1 != 0 -> x != -1
+return;
+  clang_analyzer_eval(x + 1 != 0); // expected-warning{{TRUE}}
+  clang_analyzer_eval(x != -1);// expected-warning{{TRUE}}
+  (void)x; // keep the constraints alive.
+}
+
+void remainder_with_adjustment_of_composit_lhs(int x, int y) {
+  if ((x + y + 1) % 3 == 0) // (x + 1) % 3 != 0 -> x + 1 != 0 -> x != -1
+return;
+  clang_analyzer_eval(x + y + 1 != 0); // expected-warning{{TRUE}}
+  clang_analyzer_eval(x + y != -1);// expected-warning{{TRUE}}
+  (void)(x * y); // keep the constraints alive.
+}



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112296: [Analyzer][solver] Handle adjustments in constraint assignor remainder

2021-10-27 Thread Gabor Marton via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa8297ed99430: [Analyzer][solver] Handle adjustments in 
constraint assignor remainder (authored by martong).

Changed prior to commit:
  https://reviews.llvm.org/D112296?vs=382581&id=382681#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112296/new/

https://reviews.llvm.org/D112296

Files:
  clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
  clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
  clang/test/Analysis/constraint-assignor.c


Index: clang/test/Analysis/constraint-assignor.c
===
--- clang/test/Analysis/constraint-assignor.c
+++ clang/test/Analysis/constraint-assignor.c
@@ -3,9 +3,8 @@
 // RUN:   -analyzer-checker=debug.ExprInspection \
 // RUN:   -verify
 
-// expected-no-diagnostics
-
 void clang_analyzer_warnIfReached();
+void clang_analyzer_eval(int);
 
 void rem_constant_rhs_ne_zero(int x, int y) {
   if (x % 3 == 0) // x % 3 != 0 -> x != 0
@@ -67,3 +66,19 @@
   if (d % 2 != 0)
 return;
 }
+
+void remainder_with_adjustment(int x) {
+  if ((x + 1) % 3 == 0) // (x + 1) % 3 != 0 -> x + 1 != 0 -> x != -1
+return;
+  clang_analyzer_eval(x + 1 != 0); // expected-warning{{TRUE}}
+  clang_analyzer_eval(x != -1);// expected-warning{{TRUE}}
+  (void)x; // keep the constraints alive.
+}
+
+void remainder_with_adjustment_of_composit_lhs(int x, int y) {
+  if ((x + y + 1) % 3 == 0) // (x + 1) % 3 != 0 -> x + 1 != 0 -> x != -1
+return;
+  clang_analyzer_eval(x + y + 1 != 0); // expected-warning{{TRUE}}
+  clang_analyzer_eval(x + y != -1);// expected-warning{{TRUE}}
+  (void)(x * y); // keep the constraints alive.
+}
Index: clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
@@ -41,7 +41,12 @@
   return assumeSymRel(State, SIE->getLHS(), op, SIE->getRHS());
 }
 
-  } else if (const SymSymExpr *SSE = dyn_cast(Sym)) {
+// Handle adjustment with non-comparison ops.
+const llvm::APSInt &Zero = getBasicVals().getValue(0, SIE->getType());
+return assumeSymRel(State, SIE, (Assumption ? BO_NE : BO_EQ), Zero);
+  }
+
+  if (const auto *SSE = dyn_cast(Sym)) {
 BinaryOperator::Opcode Op = SSE->getOpcode();
 assert(BinaryOperator::isComparisonOp(Op));
 
Index: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -1614,14 +1614,14 @@
   bool handleRemainderOp(const SymT *Sym, RangeSet Constraint) {
 if (Sym->getOpcode() != BO_Rem)
   return true;
-const SymbolRef LHS = Sym->getLHS();
-const llvm::APSInt &Zero =
-Builder.getBasicValueFactory().getValue(0, Sym->getType());
 // a % b != 0 implies that a != 0.
 if (!Constraint.containsZero()) {
-  State = RCM.assumeSymNE(State, LHS, Zero, Zero);
-  if (!State)
-return false;
+  SVal SymSVal = Builder.makeSymbolVal(Sym->getLHS());
+  if (auto NonLocSymSVal = SymSVal.getAs()) {
+State = State->assume(*NonLocSymSVal, true);
+if (!State)
+  return false;
+  }
 }
 return true;
   }


Index: clang/test/Analysis/constraint-assignor.c
===
--- clang/test/Analysis/constraint-assignor.c
+++ clang/test/Analysis/constraint-assignor.c
@@ -3,9 +3,8 @@
 // RUN:   -analyzer-checker=debug.ExprInspection \
 // RUN:   -verify
 
-// expected-no-diagnostics
-
 void clang_analyzer_warnIfReached();
+void clang_analyzer_eval(int);
 
 void rem_constant_rhs_ne_zero(int x, int y) {
   if (x % 3 == 0) // x % 3 != 0 -> x != 0
@@ -67,3 +66,19 @@
   if (d % 2 != 0)
 return;
 }
+
+void remainder_with_adjustment(int x) {
+  if ((x + 1) % 3 == 0) // (x + 1) % 3 != 0 -> x + 1 != 0 -> x != -1
+return;
+  clang_analyzer_eval(x + 1 != 0); // expected-warning{{TRUE}}
+  clang_analyzer_eval(x != -1);// expected-warning{{TRUE}}
+  (void)x; // keep the constraints alive.
+}
+
+void remainder_with_adjustment_of_composit_lhs(int x, int y) {
+  if ((x + y + 1) % 3 == 0) // (x + 1) % 3 != 0 -> x + 1 != 0 -> x != -1
+return;
+  clang_analyzer_eval(x + y + 1 != 0); // expected-warning{{TRUE}}
+  clang_analyzer_eval(x + y != -1);// expected-warning{{TRUE}}
+  (void)(x * y); // keep the constraints alive.
+}
Index: clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/RangedCons

[clang] 9fcca8b - Fix consteval crash when transforming 'this' expressions

2021-10-27 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2021-10-27T11:25:07-04:00
New Revision: 9fcca8b470fb92466ec4cada9fbeacc90096116d

URL: 
https://github.com/llvm/llvm-project/commit/9fcca8b470fb92466ec4cada9fbeacc90096116d
DIFF: 
https://github.com/llvm/llvm-project/commit/9fcca8b470fb92466ec4cada9fbeacc90096116d.diff

LOG: Fix consteval crash when transforming 'this' expressions

When reaching the end of a function body, we need to ensure that the
ExitFunctionBodyRAII object is destroyed before we pop the declaration context
for the function. Exiting the function body causes us to handle immediate
invocations, which involves template transformations that need to know the
correct type for this.

This addresses PR48235.

Added: 


Modified: 
clang/lib/Sema/SemaDecl.cpp
clang/test/SemaCXX/cxx2a-consteval.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 69d2ef631872d..8228292a3153a 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -14502,333 +14502,340 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt 
*Body,
   if (getLangOpts().Coroutines && FSI->isCoroutine())
 CheckCompletedCoroutineBody(FD, Body);
 
-  // Do not call PopExpressionEvaluationContext() if it is a lambda because one
-  // is already popped when finishing the lambda in BuildLambdaExpr(). This is
-  // meant to pop the context added in ActOnStartOfFunctionDef().
-  ExitFunctionBodyRAII ExitRAII(*this, isLambdaCallOperator(FD));
-
-  if (FD) {
-FD->setBody(Body);
-FD->setWillHaveBody(false);
-
-if (getLangOpts().CPlusPlus14) {
-  if (!FD->isInvalidDecl() && Body && !FD->isDependentContext() &&
-  FD->getReturnType()->isUndeducedType()) {
-// If the function has a deduced result type but contains no 'return'
-// statements, the result type as written must be exactly 'auto', and
-// the deduced result type is 'void'.
-if (!FD->getReturnType()->getAs()) {
-  Diag(dcl->getLocation(), diag::err_auto_fn_no_return_but_not_auto)
-  << FD->getReturnType();
-  FD->setInvalidDecl();
-} else {
-  // Substitute 'void' for the 'auto' in the type.
-  TypeLoc ResultType = getReturnTypeLoc(FD);
-  Context.adjustDeducedFunctionResultType(
-  FD, SubstAutoType(ResultType.getType(), Context.VoidTy));
+  {
+// Do not call PopExpressionEvaluationContext() if it is a lambda because
+// one is already popped when finishing the lambda in BuildLambdaExpr().
+// This is meant to pop the context added in ActOnStartOfFunctionDef().
+ExitFunctionBodyRAII ExitRAII(*this, isLambdaCallOperator(FD));
+
+if (FD) {
+  FD->setBody(Body);
+  FD->setWillHaveBody(false);
+
+  if (getLangOpts().CPlusPlus14) {
+if (!FD->isInvalidDecl() && Body && !FD->isDependentContext() &&
+FD->getReturnType()->isUndeducedType()) {
+  // If the function has a deduced result type but contains no 'return'
+  // statements, the result type as written must be exactly 'auto', and
+  // the deduced result type is 'void'.
+  if (!FD->getReturnType()->getAs()) {
+Diag(dcl->getLocation(), diag::err_auto_fn_no_return_but_not_auto)
+<< FD->getReturnType();
+FD->setInvalidDecl();
+  } else {
+// Substitute 'void' for the 'auto' in the type.
+TypeLoc ResultType = getReturnTypeLoc(FD);
+Context.adjustDeducedFunctionResultType(
+FD, SubstAutoType(ResultType.getType(), Context.VoidTy));
+  }
+}
+  } else if (getLangOpts().CPlusPlus11 && isLambdaCallOperator(FD)) {
+// In C++11, we don't use 'auto' deduction rules for lambda call
+// operators because we don't support return type deduction.
+auto *LSI = getCurLambda();
+if (LSI->HasImplicitReturnType) {
+  deduceClosureReturnType(*LSI);
+
+  // C++11 [expr.prim.lambda]p4:
+  //   [...] if there are no return statements in the 
compound-statement
+  //   [the deduced type is] the type void
+  QualType RetType =
+  LSI->ReturnType.isNull() ? Context.VoidTy : LSI->ReturnType;
+
+  // Update the return type to the deduced type.
+  const auto *Proto = FD->getType()->castAs();
+  FD->setType(Context.getFunctionType(RetType, Proto->getParamTypes(),
+  Proto->getExtProtoInfo()));
 }
   }
-} else if (getLangOpts().CPlusPlus11 && isLambdaCallOperator(FD)) {
-  // In C++11, we don't use 'auto' deduction rules for lambda call
-  // operators because we don't support return type deduction.
-  auto *LSI = getCurLambda();
-  if (LSI->HasImplicitReturnType) {
-deduceClosureReturnType(*LSI);
-
-// C++11 [

[PATCH] D111814: Fix consteval crash when transforming 'this' expressions

2021-10-27 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman closed this revision.
aaron.ballman added a comment.

Thanks for the reviews! I've commit in 9fcca8b470fb92466ec4cada9fbeacc90096116d 
.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D111814/new/

https://reviews.llvm.org/D111814

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112627: [clang] Inclusive language: change error message to use allowlist

2021-10-27 Thread Zarko Todorovski via Phabricator via cfe-commits
ZarkoCA created this revision.
ZarkoCA added reviewers: tuktuk, vitalybuka, MaskRay.
ZarkoCA added a project: clang.
ZarkoCA requested review of this revision.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D112627

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/lib/Driver/SanitizerArgs.cpp


Index: clang/lib/Driver/SanitizerArgs.cpp
===
--- clang/lib/Driver/SanitizerArgs.cpp
+++ clang/lib/Driver/SanitizerArgs.cpp
@@ -755,7 +755,7 @@
 parseSpecialCaseListArg(
 D, Args, CoverageAllowlistFiles,
 options::OPT_fsanitize_coverage_allowlist, OptSpecifier(),
-clang::diag::err_drv_malformed_sanitizer_coverage_whitelist);
+clang::diag::err_drv_malformed_sanitizer_coverage_allowlist);
 parseSpecialCaseListArg(
 D, Args, CoverageIgnorelistFiles,
 options::OPT_fsanitize_coverage_ignorelist, OptSpecifier(),
Index: clang/include/clang/Basic/DiagnosticDriverKinds.td
===
--- clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -187,8 +187,8 @@
   "invalid argument '%0' to -%1">;
 def err_drv_malformed_sanitizer_ignorelist : Error<
   "malformed sanitizer ignorelist: '%0'">;
-def err_drv_malformed_sanitizer_coverage_whitelist : Error<
-  "malformed sanitizer coverage whitelist: '%0'">;
+def err_drv_malformed_sanitizer_coverage_allowlist : Error<
+  "malformed sanitizer coverage allowlist: '%0'">;
 def err_drv_malformed_sanitizer_coverage_ignorelist : Error<
   "malformed sanitizer coverage ignorelist: '%0'">;
 def err_drv_duplicate_config : Error<


Index: clang/lib/Driver/SanitizerArgs.cpp
===
--- clang/lib/Driver/SanitizerArgs.cpp
+++ clang/lib/Driver/SanitizerArgs.cpp
@@ -755,7 +755,7 @@
 parseSpecialCaseListArg(
 D, Args, CoverageAllowlistFiles,
 options::OPT_fsanitize_coverage_allowlist, OptSpecifier(),
-clang::diag::err_drv_malformed_sanitizer_coverage_whitelist);
+clang::diag::err_drv_malformed_sanitizer_coverage_allowlist);
 parseSpecialCaseListArg(
 D, Args, CoverageIgnorelistFiles,
 options::OPT_fsanitize_coverage_ignorelist, OptSpecifier(),
Index: clang/include/clang/Basic/DiagnosticDriverKinds.td
===
--- clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -187,8 +187,8 @@
   "invalid argument '%0' to -%1">;
 def err_drv_malformed_sanitizer_ignorelist : Error<
   "malformed sanitizer ignorelist: '%0'">;
-def err_drv_malformed_sanitizer_coverage_whitelist : Error<
-  "malformed sanitizer coverage whitelist: '%0'">;
+def err_drv_malformed_sanitizer_coverage_allowlist : Error<
+  "malformed sanitizer coverage allowlist: '%0'">;
 def err_drv_malformed_sanitizer_coverage_ignorelist : Error<
   "malformed sanitizer coverage ignorelist: '%0'">;
 def err_drv_duplicate_config : Error<
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112628: NOT READY FOR REVIEW Nothing to see here, just exporting to show this to someone.

2021-10-27 Thread Adam Czachorowski via Phabricator via cfe-commits
adamcz created this revision.
Herald added subscribers: usaxena95, kadircet, arphaman.
adamcz requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D112628

Files:
  clang-tools-extra/clangd/CodeCompletionStrings.cpp
  clang-tools-extra/clangd/CodeCompletionStrings.h
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/Hover.h
  clang-tools-extra/clangd/SourceCode.cpp
  clang-tools-extra/clangd/SourceCode.h
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp

Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -2517,6 +2517,77 @@
   }
 }
 
+TEST(Hover, DocLocation) {
+  const std::string Filename = "main.cpp";
+  const std::string HeaderFilename = "header.h";
+
+  struct {
+const char *const Code;
+const std::function ExpectedBuilder;
+  } Cases[] = {
+  {
+  R"cpp(
+  // main-doc
+  void main_file_fun();
+
+  void foo() { m^ain_file_fun(); }
+  )cpp",
+  [&](HoverInfo &HI) {
+HI.Documentation = "main-doc";
+HI.DocumentationLocation.range.start.line = 1;
+HI.DocumentationLocation.range.start.character = 6;
+HI.DocumentationLocation.range.end.line = 1;
+HI.DocumentationLocation.range.end.character = 17;
+HI.DocumentationLocation.uri =
+URIForFile::canonicalize(testPath(Filename), Filename);
+  }},
+  {
+  R"cpp(
+  void foo() { hea^der_fun(); }
+  )cpp",
+  [&](HoverInfo &HI) {
+HI.Documentation = "main-doc";
+HI.DocumentationLocation.range.start.line = 1;
+HI.DocumentationLocation.range.start.character = 2;
+HI.DocumentationLocation.range.end.line = 1;
+HI.DocumentationLocation.range.end.character = 8;
+HI.DocumentationLocation.uri = URIForFile::canonicalize(
+testPath(HeaderFilename), HeaderFilename);
+  }},
+  };
+
+  const std::string Header = R"cpp(
+  // doc
+  void header_fun();
+  )cpp";
+
+  for (const auto &Case : Cases) {
+SCOPED_TRACE(Case.Code);
+
+Annotations T(Case.Code);
+TestTU TU = TestTU::withCode(T.code());
+TU.HeaderCode = Header;
+TU.Filename = Filename;
+TU.HeaderFilename = HeaderFilename;
+
+auto Index = std::make_unique();
+TU.preamble([&](ASTContext &Ctx, std::shared_ptr PP,
+const CanonicalIncludes &CanonIncludes) {
+  Index->updatePreamble(TU.Filename, "null", Ctx, PP, CanonIncludes);
+});
+
+auto AST = TU.build();
+auto H = getHover(AST, T.point(), format::getLLVMStyle(), Index.get());
+ASSERT_TRUE(H);
+
+HoverInfo Expected;
+Case.ExpectedBuilder(Expected);
+
+EXPECT_EQ(H->Documentation, Expected.Documentation);
+EXPECT_EQ(H->DocumentationLocation, Expected.DocumentationLocation);
+  }
+}
+
 TEST(Hover, NoCrash) {
   Annotations T(R"cpp(
 /* error-ok */
Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -210,29 +210,6 @@
   return Result;
 }
 
-// Expects Loc to be a SpellingLocation, will bail out otherwise as it can't
-// figure out a filename.
-llvm::Optional makeLocation(const ASTContext &AST, SourceLocation Loc,
-  llvm::StringRef TUPath) {
-  const auto &SM = AST.getSourceManager();
-  const FileEntry *F = SM.getFileEntryForID(SM.getFileID(Loc));
-  if (!F)
-return None;
-  auto FilePath = getCanonicalPath(F, SM);
-  if (!FilePath) {
-log("failed to get path!");
-return None;
-  }
-  Location L;
-  L.uri = URIForFile::canonicalize(*FilePath, TUPath);
-  // We call MeasureTokenLength here as TokenBuffer doesn't store spelled tokens
-  // outside the main file.
-  auto TokLen = Lexer::MeasureTokenLength(Loc, SM, AST.getLangOpts());
-  L.range = halfOpenToRange(
-  SM, CharSourceRange::getCharRange(Loc, Loc.getLocWithOffset(TokLen)));
-  return L;
-}
-
 // Treat #included files as symbols, to enable go-to-definition on them.
 llvm::Optional locateFileReferent(const Position &Pos,
  ParsedAST &AST,
Index: clang-tools-extra/clangd/SourceCode.h
===
--- clang-tools-extra/clangd/SourceCode.h
+++ clang-tools-extra/clangd/SourceCode.h
@@ -16,6 +16,7 @@
 #include "Protocol.h"
 #include "support/Context.h"
 #include "support/ThreadsafeFS.h"
+#include "clang/AST/ASTContext.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/SourceLocati

[PATCH] D112059: Fix inline builtin handling in case of redefinition

2021-10-27 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D112059#3090466 , 
@serge-sans-paille wrote:

> - Use a FunctionDecl Attribute to store the shadowed inline redecl status

The downside to this approach is that we can now handle less ctor initializers 
because we need to steal a bit from there. We're going from allowing 2,097,152 
ctor inits to 1,048,576, which is still a pretty large number of ctor inits, so 
I think this new approach is defensible. However, this does make it that much 
harder to add any new bits in the future. I agree that walking the redecl chain 
could potentially cause a performance issue, but that's speculative without 
some measurements. Because we don't have those measurements, I'm actually a bit 
more comfortable with walking the redecl chain than the current approach -- if 
we measure performance and find that walking this chain is a bottleneck, then 
it makes it more obvious that the new approach is worthwhile.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112059/new/

https://reviews.llvm.org/D112059

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   3   >