[PATCH] D127082: [clangd] Add Macro Expansion to Hover

2022-07-10 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

I would like to apply the updated patch to try it some more, but `arc patch` is 
failing for me.

Applying the raw diff manually with `patch` also fails with the following 
errors:

  $ patch -p1 < ../patches/macro-hover.patch
  patching file clang-tools-extra/clangd/Hover.h
  Hunk #1 FAILED at 71 (different line endings).
  1 out of 1 hunk FAILED -- saving rejects to file 
clang-tools-extra/clangd/Hover.h.rej
  patching file clang-tools-extra/clangd/Hover.cpp
  Hunk #1 FAILED at 641 (different line endings).
  Hunk #2 FAILED at 670 (different line endings).
  Hunk #3 FAILED at 1004 (different line endings).
  Hunk #4 FAILED at 1055 (different line endings).
  Hunk #5 FAILED at 1175 (different line endings).
  5 out of 5 hunks FAILED -- saving rejects to file 
clang-tools-extra/clangd/Hover.cpp.rej
  patching file clang-tools-extra/clangd/unittests/HoverTests.cpp
  Hunk #1 FAILED at 478 (different line endings).
  Hunk #2 FAILED at 1070 (different line endings).
  Hunk #3 FAILED at 1567 (different line endings).
  Hunk #4 FAILED at 1577 (different line endings).
  Hunk #5 FAILED at 1591 (different line endings).
  Hunk #6 FAILED at 2625 (different line endings).
  6 out of 6 hunks FAILED -- saving rejects to file 
clang-tools-extra/clangd/unittests/HoverTests.cpp.rej

I'm guessing related to Windows line endings?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127082

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


[PATCH] D127082: [clangd] Add Macro Expansion to Hover

2022-07-10 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

I fixed it locally by running `dos2unix` on the patch before applying.

However, if you're able to, please update the patch to remove the Windows line 
endings so it can be applied with `arc patch`, otherwise the patch metadata is 
lost during manual application.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127082

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


[PATCH] D54943: [clang-tidy] implement new check 'misc-const-correctness' to add 'const' to unmodified variables

2022-07-10 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth updated this revision to Diff 443484.
JonasToth marked 4 inline comments as done.
JonasToth added a comment.
Herald added a reviewer: jdoerfert.
Herald added subscribers: abrachet, sstefan1, phosek.

- test: move tests into group specific directory
- refactor: use more idiomatic c++ for scope-based analyzer creation/access
- feat: provide config validation if analysis if completely configured off
- refactor: move documentation as well
- test: add test for incorrect configurations


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D54943

Files:
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
  clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.h
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/const-correctness.rst
  clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-cxx17.cpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-pointer-as-values.cpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-templates.cpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-transform-pointer-as-values.cpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-transform-values.cpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-unaligned.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-wrong-config.cpp
  clang/lib/Analysis/ExprMutationAnalyzer.cpp
  clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp

Index: clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
===
--- clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
+++ clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
@@ -1251,13 +1251,13 @@
   AST =
   buildASTFromCode("void f() { int* x[2]; for (int* e : x) e = nullptr; }");
   Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
-  EXPECT_FALSE(isMutated(Results, AST.get()));
+  EXPECT_TRUE(isMutated(Results, AST.get()));
 
   AST = buildASTFromCode(
   "typedef int* IntPtr;"
   "void f() { int* x[2]; for (IntPtr e : x) e = nullptr; }");
   Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
-  EXPECT_FALSE(isMutated(Results, AST.get()));
+  EXPECT_TRUE(isMutated(Results, AST.get()));
 }
 
 TEST(ExprMutationAnalyzerTest, RangeForArrayByConstRef) {
Index: clang/lib/Analysis/ExprMutationAnalyzer.cpp
===
--- clang/lib/Analysis/ExprMutationAnalyzer.cpp
+++ clang/lib/Analysis/ExprMutationAnalyzer.cpp
@@ -455,14 +455,16 @@
   // array is considered modified if the loop-variable is a non-const reference.
   const auto DeclStmtToNonRefToArray = declStmt(hasSingleDecl(varDecl(hasType(
   hasUnqualifiedDesugaredType(referenceType(pointee(arrayType(;
-  const auto RefToArrayRefToElements = match(
-  findAll(stmt(cxxForRangeStmt(
-   hasLoopVariable(varDecl(hasType(nonConstReferenceType()))
-   .bind(NodeID::value)),
-   hasRangeStmt(DeclStmtToNonRefToArray),
-   hasRangeInit(canResolveToExpr(equalsNode(Exp)
-  .bind("stmt")),
-  Stm, Context);
+  const auto RefToArrayRefToElements =
+  match(findAll(stmt(cxxForRangeStmt(
+ hasLoopVariable(
+ varDecl(anyOf(hasType(nonConstReferenceType()),
+   hasType(nonConstPointerType(
+ .bind(NodeID::value)),
+ hasRangeStmt(DeclStmtToNonRefToArray),
+ hasRangeInit(canResolveToExpr(equalsNode(Exp)
+.bind("stmt")),
+Stm, Context);
 
   if (const auto *BadRangeInitFromArray =
   selectFirst("stmt", RefToArrayRefToElements))
Index: clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-wrong-config.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-wrong-config.cpp
@@ -0,0 +1,12 @@
+// RUN: %check_clang_tidy %s misc-const-correctness %t \
+// RUN: -config='{CheckOptions: \
+// RUN:  [{key: "misc-const-correctness.AnalyzeValues", value: false},\
+// RUN:   {key: "misc-const-correctness.AnalyzeReferences", value: false},\
+// RUN:  ]}' -- -fno-delayed-template-parsing
+
+// CHECK-MESSAGES: warning: The check will not perform any analysis because both 'AnalyzeValues' and 'AnalyzeReferences' ar

[PATCH] D54943: [clang-tidy] implement new check 'misc-const-correctness' to add 'const' to unmodified variables

2022-07-10 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added inline comments.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/misc-const-correctness.rst:10
+`CppCoreGuidelines ES.25 
`_
+and `AUTOSAR C++14 Rule A7-1-1 (6.7.1 Specifiers) 
`_.
+

carlosgalvezp wrote:
> AUTOSAR mentions should be removed as per previous comment from 
> @aaron.ballman 
Why? I dont think its wrong to hint that there are coding standards that 
require `const` to be used consistently.
The check does not run under `cppcoreguidelines-` because the guidelines are 
not exact on their requirements. But "the spirit" is still the same. I would 
like to keep the references.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D54943

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


[PATCH] D54943: [clang-tidy] implement new check 'misc-const-correctness' to add 'const' to unmodified variables

2022-07-10 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

In D54943#3619333 , @LegalizeAdulthood 
wrote:

> Clang-tidy tests and docs have been moved to subdirectories by module, please 
> rebase to `main:HEAD`

I moved the tests and the documentation as well.
tests + documentation do build/pass


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D54943

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


[PATCH] D54943: [clang-tidy] implement new check 'misc-const-correctness' to add 'const' to unmodified variables

2022-07-10 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth updated this revision to Diff 443485.
JonasToth added a comment.

- fix: doc list and release-notes reference


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D54943

Files:
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
  clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.h
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/const-correctness.rst
  clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-cxx17.cpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-pointer-as-values.cpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-templates.cpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-transform-pointer-as-values.cpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-transform-values.cpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-unaligned.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-wrong-config.cpp
  clang/lib/Analysis/ExprMutationAnalyzer.cpp
  clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp

Index: clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
===
--- clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
+++ clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
@@ -1251,13 +1251,13 @@
   AST =
   buildASTFromCode("void f() { int* x[2]; for (int* e : x) e = nullptr; }");
   Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
-  EXPECT_FALSE(isMutated(Results, AST.get()));
+  EXPECT_TRUE(isMutated(Results, AST.get()));
 
   AST = buildASTFromCode(
   "typedef int* IntPtr;"
   "void f() { int* x[2]; for (IntPtr e : x) e = nullptr; }");
   Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
-  EXPECT_FALSE(isMutated(Results, AST.get()));
+  EXPECT_TRUE(isMutated(Results, AST.get()));
 }
 
 TEST(ExprMutationAnalyzerTest, RangeForArrayByConstRef) {
Index: clang/lib/Analysis/ExprMutationAnalyzer.cpp
===
--- clang/lib/Analysis/ExprMutationAnalyzer.cpp
+++ clang/lib/Analysis/ExprMutationAnalyzer.cpp
@@ -455,14 +455,16 @@
   // array is considered modified if the loop-variable is a non-const reference.
   const auto DeclStmtToNonRefToArray = declStmt(hasSingleDecl(varDecl(hasType(
   hasUnqualifiedDesugaredType(referenceType(pointee(arrayType(;
-  const auto RefToArrayRefToElements = match(
-  findAll(stmt(cxxForRangeStmt(
-   hasLoopVariable(varDecl(hasType(nonConstReferenceType()))
-   .bind(NodeID::value)),
-   hasRangeStmt(DeclStmtToNonRefToArray),
-   hasRangeInit(canResolveToExpr(equalsNode(Exp)
-  .bind("stmt")),
-  Stm, Context);
+  const auto RefToArrayRefToElements =
+  match(findAll(stmt(cxxForRangeStmt(
+ hasLoopVariable(
+ varDecl(anyOf(hasType(nonConstReferenceType()),
+   hasType(nonConstPointerType(
+ .bind(NodeID::value)),
+ hasRangeStmt(DeclStmtToNonRefToArray),
+ hasRangeInit(canResolveToExpr(equalsNode(Exp)
+.bind("stmt")),
+Stm, Context);
 
   if (const auto *BadRangeInitFromArray =
   selectFirst("stmt", RefToArrayRefToElements))
Index: clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-wrong-config.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-wrong-config.cpp
@@ -0,0 +1,12 @@
+// RUN: %check_clang_tidy %s misc-const-correctness %t \
+// RUN: -config='{CheckOptions: \
+// RUN:  [{key: "misc-const-correctness.AnalyzeValues", value: false},\
+// RUN:   {key: "misc-const-correctness.AnalyzeReferences", value: false},\
+// RUN:  ]}' -- -fno-delayed-template-parsing
+
+// CHECK-MESSAGES: warning: The check will not perform any analysis because both 'AnalyzeValues' and 'AnalyzeReferences' are false. [clang-tidy-config]
+
+void g() {
+  int p_local0 = 42;
+  // CHECK-FIXES-NOT: int const p_local0 = 42;
+}
Index: clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
@@ -0,0 +1,1

[PATCH] D54943: [clang-tidy] implement new check 'misc-const-correctness' to add 'const' to unmodified variables

2022-07-10 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth updated this revision to Diff 443486.
JonasToth added a comment.

- refactor: adjust warning message for mis-configuration to show which check is 
configured wrong


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D54943

Files:
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
  clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.h
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/const-correctness.rst
  clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-cxx17.cpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-pointer-as-values.cpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-templates.cpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-transform-pointer-as-values.cpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-transform-values.cpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-unaligned.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-wrong-config.cpp
  clang/lib/Analysis/ExprMutationAnalyzer.cpp
  clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp

Index: clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
===
--- clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
+++ clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
@@ -1251,13 +1251,13 @@
   AST =
   buildASTFromCode("void f() { int* x[2]; for (int* e : x) e = nullptr; }");
   Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
-  EXPECT_FALSE(isMutated(Results, AST.get()));
+  EXPECT_TRUE(isMutated(Results, AST.get()));
 
   AST = buildASTFromCode(
   "typedef int* IntPtr;"
   "void f() { int* x[2]; for (IntPtr e : x) e = nullptr; }");
   Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
-  EXPECT_FALSE(isMutated(Results, AST.get()));
+  EXPECT_TRUE(isMutated(Results, AST.get()));
 }
 
 TEST(ExprMutationAnalyzerTest, RangeForArrayByConstRef) {
Index: clang/lib/Analysis/ExprMutationAnalyzer.cpp
===
--- clang/lib/Analysis/ExprMutationAnalyzer.cpp
+++ clang/lib/Analysis/ExprMutationAnalyzer.cpp
@@ -455,14 +455,16 @@
   // array is considered modified if the loop-variable is a non-const reference.
   const auto DeclStmtToNonRefToArray = declStmt(hasSingleDecl(varDecl(hasType(
   hasUnqualifiedDesugaredType(referenceType(pointee(arrayType(;
-  const auto RefToArrayRefToElements = match(
-  findAll(stmt(cxxForRangeStmt(
-   hasLoopVariable(varDecl(hasType(nonConstReferenceType()))
-   .bind(NodeID::value)),
-   hasRangeStmt(DeclStmtToNonRefToArray),
-   hasRangeInit(canResolveToExpr(equalsNode(Exp)
-  .bind("stmt")),
-  Stm, Context);
+  const auto RefToArrayRefToElements =
+  match(findAll(stmt(cxxForRangeStmt(
+ hasLoopVariable(
+ varDecl(anyOf(hasType(nonConstReferenceType()),
+   hasType(nonConstPointerType(
+ .bind(NodeID::value)),
+ hasRangeStmt(DeclStmtToNonRefToArray),
+ hasRangeInit(canResolveToExpr(equalsNode(Exp)
+.bind("stmt")),
+Stm, Context);
 
   if (const auto *BadRangeInitFromArray =
   selectFirst("stmt", RefToArrayRefToElements))
Index: clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-wrong-config.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-wrong-config.cpp
@@ -0,0 +1,12 @@
+// RUN: %check_clang_tidy %s misc-const-correctness %t \
+// RUN: -config='{CheckOptions: \
+// RUN:  [{key: "misc-const-correctness.AnalyzeValues", value: false},\
+// RUN:   {key: "misc-const-correctness.AnalyzeReferences", value: false},\
+// RUN:  ]}' -- -fno-delayed-template-parsing
+
+// CHECK-MESSAGES: warning: The check 'misc-const-correctness' will not perform any analysis because both 'AnalyzeValues' and 'AnalyzeReferences' are false. [clang-tidy-config]
+
+void g() {
+  int p_local0 = 42;
+  // CHECK-FIXES-NOT: int const p_local0 = 42;
+}
Index: clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
===
--- /dev/null
+++ clang-tool

[clang] af2d11b - [C++20][Modules] Implement include translation.

2022-07-10 Thread Iain Sandoe via cfe-commits

Author: Iain Sandoe
Date: 2022-07-10T11:06:51+01:00
New Revision: af2d11b1d5c1508b506825df460656e0151cd3b0

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

LOG: [C++20][Modules] Implement include translation.

This addresses [cpp.include]/7

(when encountering #include header-name)

If the header identified by the header-name denotes an importable header, it
is implementation-defined whether the #include preprocessing directive is
instead replaced by an import directive.

In this implementation, include translation is performed _only_ for headers
in the Global Module fragment, so:
```
module;
 #include "will-be-translated.h" // IFF the header unit is available.

export module M;
 #include "will-not-be-translated.h" // even if the header unit is available
```
The reasoning is that, in general, includes in the module purview would not
be validly translatable (they would have to immediately follow the module
decl and without any other intervening decls).  Otherwise that would violate
the rules on contiguous import directives.

This would be quite complex to track in the preprocessor, and for relatively
little gain (the user can 'import "will-not-be-translated.h";' instead.)

TODO: This is one area where it becomes increasingly difficult to disambiguate
clang modules in C++ from C++ standard modules.  That needs to be addressed in
both the driver and the FE.

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

Added: 
clang/test/Modules/cxx20-include-translation.cpp

Modified: 
clang/include/clang/Lex/Preprocessor.h
clang/lib/Lex/PPDirectives.cpp
clang/lib/Lex/Preprocessor.cpp
clang/lib/Parse/Parser.cpp

Removed: 




diff  --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index d130aba3ee3a2..8fc24c7310358 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -385,6 +385,7 @@ class Preprocessor {
 
 bool atTopLevel() { return S <= 0; }
 bool afterImportSeq() { return S == AfterImportSeq; }
+bool afterTopLevelSeq() { return S == AfterTopLevelTokenSeq; }
 
   private:
 State S;
@@ -397,6 +398,67 @@ class Preprocessor {
   /// Our current position within a C++20 import-seq.
   ImportSeq ImportSeqState = ImportSeq::AfterTopLevelTokenSeq;
 
+  /// Track whether we are in a Global Module Fragment
+  class TrackGMF {
+  public:
+enum GMFState : int {
+  GMFActive = 1,
+  MaybeGMF = 0,
+  BeforeGMFIntroducer = -1,
+  GMFAbsentOrEnded = -2,
+};
+
+TrackGMF(GMFState S) : S(S) {}
+
+/// Saw a semicolon.
+void handleSemi() {
+  // If it is immediately after the first instance of the module keyword,
+  // then that introduces the GMF.
+  if (S == MaybeGMF)
+S = GMFActive;
+}
+
+/// Saw an 'export' identifier.
+void handleExport() {
+  // The presence of an 'export' keyword always ends or excludes a GMF.
+  S = GMFAbsentOrEnded;
+}
+
+/// Saw an 'import' identifier.
+void handleImport(bool AfterTopLevelTokenSeq) {
+  // If we see this before any 'module' kw, then we have no GMF.
+  if (AfterTopLevelTokenSeq && S == BeforeGMFIntroducer)
+S = GMFAbsentOrEnded;
+}
+
+/// Saw a 'module' identifier.
+void handleModule(bool AfterTopLevelTokenSeq) {
+  // This was the first module identifier and not preceded by any token
+  // that would exclude a GMF.  It could begin a GMF, but only if directly
+  // followed by a semicolon.
+  if (AfterTopLevelTokenSeq && S == BeforeGMFIntroducer)
+S = MaybeGMF;
+  else
+S = GMFAbsentOrEnded;
+}
+
+/// Saw any other token.
+void handleMisc() {
+  // We saw something other than ; after the 'module' kw, so not a GMF.
+  if (S == MaybeGMF)
+S = GMFAbsentOrEnded;
+}
+
+bool inGMF() { return S == GMFActive; }
+
+  private:
+/// Track the transitions into and out of a Global Module Fragment,
+/// if one is present.
+GMFState S;
+  };
+
+  TrackGMF TrackGMFState = TrackGMF::BeforeGMFIntroducer;
+
   /// Whether the module import expects an identifier next. Otherwise,
   /// it expects a '.' or ';'.
   bool ModuleImportExpectsIdentifier = false;
@@ -2414,6 +2476,7 @@ class Preprocessor {
   None,
   ModuleBegin,
   ModuleImport,
+  HeaderUnitImport,
   SkippedModuleImport,
   Failure,
 } Kind;

diff  --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index 4dcef01e3e4c4..352e1f2178193 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -1983,6 +1983,10 @@ void Preprocessor::HandleIncludeDirective(SourceLocation 
HashLoc,
 EnterAnnotationToken(SourceRange(HashLoc, EndLoc),
 

[PATCH] D128981: [C++20][Modules] Implement include translation.

2022-07-10 Thread Iain Sandoe via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGaf2d11b1d5c1: [C++20][Modules] Implement include 
translation. (authored by iains).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128981

Files:
  clang/include/clang/Lex/Preprocessor.h
  clang/lib/Lex/PPDirectives.cpp
  clang/lib/Lex/Preprocessor.cpp
  clang/lib/Parse/Parser.cpp
  clang/test/Modules/cxx20-include-translation.cpp

Index: clang/test/Modules/cxx20-include-translation.cpp
===
--- /dev/null
+++ clang/test/Modules/cxx20-include-translation.cpp
@@ -0,0 +1,109 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+// RUN: cd %t
+//
+// RUN: %clang_cc1 -std=c++20 -xc++-user-header h1.h -emit-header-unit -o h1.pcm
+// RUN: %clang_cc1 -std=c++20 -xc++-user-header h2.h -emit-header-unit -o h2.pcm
+// RUN: %clang_cc1 -std=c++20 -xc++-user-header h3.h -emit-header-unit -o h3.pcm
+// RUN: %clang_cc1 -std=c++20 -xc++-user-header h4.h -emit-header-unit -o h4.pcm
+
+// RUN: %clang_cc1 -std=c++20 Xlate.cpp -emit-module-interface -o Xlate.pcm \
+// RUN: -fmodule-file=h1.pcm -fmodule-file=h2.pcm -fmodule-file=h3.pcm \
+// RUN: -fmodule-file=h4.pcm -fsyntax-only -Wauto-import -verify
+
+// Check that we do the intended translation and not more.
+// RUN: %clang_cc1 -std=c++20 Xlate.cpp \
+// RUN: -fmodule-file=h1.pcm -fmodule-file=h2.pcm -fmodule-file=h3.pcm \
+// RUN: -fmodule-file=h4.pcm  -E -undef | FileCheck %s
+
+// We expect no diagnostics here, the used functions should all be available.
+// RUN: %clang_cc1 -std=c++20 Xlate.cpp -emit-module-interface \
+// RUN: -fmodule-file=h1.pcm -fmodule-file=h2.pcm -fmodule-file=h3.pcm \
+// RUN: -fmodule-file=h4.pcm -fsyntax-only
+
+// The content of the headers is not terribly important, we just want to check
+// whether they are textually included or include-translated.
+//--- h1.h
+#ifndef H1_GUARD
+#define H1_GUARD
+
+#define ONE 1
+
+void foo();
+
+#endif // H1_GUARD
+
+//--- h2.h
+#ifndef H2_GUARD
+#define H2_GUARD
+
+#define TWO 2
+
+void bar();
+
+#endif // H2_GUARD
+
+//--- h3.h
+#ifndef H3_GUARD
+#define H3_GUARD
+
+#define THREE 3
+
+void baz();
+
+#endif // H3_GUARD
+
+//--- h4.h
+#ifndef H4_GUARD
+#define H4_GUARD
+
+#define FOUR 4
+
+void boo();
+
+#endif // H4_GUARD
+
+//--- h5.h
+#ifndef H5_GUARD
+#define H5_GUARD
+
+#define FIVE 5
+
+void five();
+
+#endif // H4_GUARD
+
+//--- Xlate.cpp
+/* some comment ...
+  ... */
+module /*nothing here*/;
+
+// This should be include-translated, when the header unit for h1 is available.
+#include "h1.h" // expected-warning {{treating #include as an import of module './h1.h'}}
+// Import of a header unit is allowed, named modules are not.
+import "h2.h";
+// A regular, untranslated, header
+#include "h5.h"
+
+export module Xlate;
+
+// This is OK, the import immediately follows the module decl.
+import "h3.h";
+
+// This should *not* be include-translated, even if header unit for h4 is
+// available.
+#include "h4.h"
+
+export void charlie() {
+  foo();
+  bar();
+  baz();
+  boo();
+  five();
+}
+
+// CHECK: #pragma clang module import "./h1.h"
+// CHECK: import ./h2.h
+// CHECK: import ./h3.h
+// CHECK-NOT: #pragma clang module import "./h4.h"
Index: clang/lib/Parse/Parser.cpp
===
--- clang/lib/Parse/Parser.cpp
+++ clang/lib/Parse/Parser.cpp
@@ -663,12 +663,22 @@
 return false;
   }
 
-  case tok::annot_module_include:
-Actions.ActOnModuleInclude(Tok.getLocation(),
-   reinterpret_cast(
-   Tok.getAnnotationValue()));
+  case tok::annot_module_include: {
+auto Loc = Tok.getLocation();
+Module *Mod = reinterpret_cast(Tok.getAnnotationValue());
+// FIXME: We need a better way to disambiguate C++ clang modules and
+// standard C++ modules.
+if (!getLangOpts().CPlusPlusModules || !Mod->isHeaderUnit())
+  Actions.ActOnModuleInclude(Loc, Mod);
+else {
+  DeclResult Import =
+  Actions.ActOnModuleImport(Loc, SourceLocation(), Loc, Mod);
+  Decl *ImportDecl = Import.isInvalid() ? nullptr : Import.get();
+  Result = Actions.ConvertDeclToDeclGroup(ImportDecl);
+}
 ConsumeAnnotationToken();
 return false;
+  }
 
   case tok::annot_module_begin:
 Actions.ActOnModuleBegin(Tok.getLocation(), reinterpret_cast(
Index: clang/lib/Lex/Preprocessor.cpp
===
--- clang/lib/Lex/Preprocessor.cpp
+++ clang/lib/Lex/Preprocessor.cpp
@@ -941,6 +941,9 @@
 
   // Update ImportSeqState to track our position within a C++20 import-seq
   // if this token is being produced as a result of phase 4 of translation.
+  // Update TrackGMFState to decide if we are currently in a Global Module
+  // Fragment. GMF state updates should precede Im

[PATCH] D54943: [clang-tidy] implement new check 'misc-const-correctness' to add 'const' to unmodified variables

2022-07-10 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

@njames93 @LegalizeAdulthood I did integrate the requested changes regarding 
warning for bad configs, refactoring of map-access and the directory structure 
of test-files and documentation.

given the high interest in the patch and the need to iron out potential 
false-positives that will only be spotted on diverse code bases, i would like 
to commit now and address outstanding issues in follow ups, that are much 
smaller and easier to manage.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D54943

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


[PATCH] D129443: [clang-format] Add option for aligning requires clause body

2022-07-10 Thread Danil Sidoruk via Phabricator via cfe-commits
eoanermine created this revision.
eoanermine added projects: clang, clang-format.
Herald added a project: All.
eoanermine requested review of this revision.
Herald added a subscriber: cfe-commits.

- Add an option whether requires clause body should be aligned with `requires` 
keyword

Fixes https://github.com/llvm/llvm-project/issues/56283


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129443

Files:
  clang/include/clang/Format/Format.h
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/Format.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -20033,6 +20033,7 @@
 TEST_F(FormatTest, ParsesConfigurationBools) {
   FormatStyle Style = {};
   Style.Language = FormatStyle::LK_Cpp;
+  CHECK_PARSE_BOOL(AlignRequiresClauseBody);
   CHECK_PARSE_BOOL(AlignTrailingComments);
   CHECK_PARSE_BOOL(AllowAllArgumentsOnNextLine);
   CHECK_PARSE_BOOL(AllowAllParametersOfDeclarationOnNextLine);
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -646,6 +646,7 @@
 IO.mapOptional("AlignConsecutiveMacros", Style.AlignConsecutiveMacros);
 IO.mapOptional("AlignEscapedNewlines", Style.AlignEscapedNewlines);
 IO.mapOptional("AlignOperands", Style.AlignOperands);
+IO.mapOptional("AlignRequiresClauseBody", Style.AlignRequiresClauseBody);
 IO.mapOptional("AlignTrailingComments", Style.AlignTrailingComments);
 IO.mapOptional("AllowAllArgumentsOnNextLine",
Style.AllowAllArgumentsOnNextLine);
@@ -1181,6 +1182,7 @@
   LLVMStyle.AlignAfterOpenBracket = FormatStyle::BAS_Align;
   LLVMStyle.AlignArrayOfStructures = FormatStyle::AIAS_None;
   LLVMStyle.AlignOperands = FormatStyle::OAS_Align;
+  LLVMStyle.AlignRequiresClauseBody = true;
   LLVMStyle.AlignTrailingComments = true;
   LLVMStyle.AlignConsecutiveAssignments = {};
   LLVMStyle.AlignConsecutiveAssignments.Enabled = false;
Index: clang/lib/Format/ContinuationIndenter.cpp
===
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -1398,7 +1398,7 @@
 CurrentState.NestedBlockIndent = State.Column + Current.ColumnWidth + 1;
   if (Current.isOneOf(TT_LambdaLSquare, TT_LambdaArrow))
 CurrentState.LastSpace = State.Column;
-  if (Current.is(TT_RequiresExpression))
+  if (Current.is(TT_RequiresExpression) && Style.AlignRequiresClauseBody)
 CurrentState.NestedBlockIndent = State.Column;
 
   // Insert scopes created by fake parenthesis.
Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -369,6 +369,17 @@
   /// \version 3.5
   OperandAlignmentStyle AlignOperands;
 
+  /// If ``true``, aligns requires clause bodies with `requires` keyword.
+  /// \code
+  ///   true:   false:
+  ///   templatetemplate 
+  ///   concept C = requires(T t) {  vs.concept C = requires(T t) {
+  /// ... ...
+  ///   }   }
+  /// \endcode
+  /// \version 15
+  bool AlignRequiresClauseBody;
+
   /// If ``true``, aligns trailing comments.
   /// \code
   ///   true:   false:
@@ -3856,6 +3867,7 @@
AlignConsecutiveMacros == R.AlignConsecutiveMacros &&
AlignEscapedNewlines == R.AlignEscapedNewlines &&
AlignOperands == R.AlignOperands &&
+   AlignRequiresClauseBody == R.AlignRequiresClauseBody &&
AlignTrailingComments == R.AlignTrailingComments &&
AllowAllArgumentsOnNextLine == R.AllowAllArgumentsOnNextLine &&
AllowAllParametersOfDeclarationOnNextLine ==


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -20033,6 +20033,7 @@
 TEST_F(FormatTest, ParsesConfigurationBools) {
   FormatStyle Style = {};
   Style.Language = FormatStyle::LK_Cpp;
+  CHECK_PARSE_BOOL(AlignRequiresClauseBody);
   CHECK_PARSE_BOOL(AlignTrailingComments);
   CHECK_PARSE_BOOL(AllowAllArgumentsOnNextLine);
   CHECK_PARSE_BOOL(AllowAllParametersOfDeclarationOnNextLine);
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -646,6 +646,7 @@
 IO.mapOptional("AlignConsecutiveMacros", Style.AlignConsecutiveMacros);
 IO.mapOptional("AlignEscapedNewlines", Style.AlignEscapedNewlines);
 IO.mapOptional("Ali

[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs

2022-07-10 Thread Schrodinger ZHU Yifan via Phabricator via cfe-commits
SchrodingerZhu updated this revision to Diff 443503.
SchrodingerZhu marked 5 inline comments as done.
SchrodingerZhu added a comment.

This commit addresses problems mentioned in code reviews:

- Fix format and wording for comments
- Add more checks with llvm-dis
- Adjust code styles for function references, and auto inference.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129009

Files:
  llvm/include/llvm/IR/GlobalIFunc.h
  llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/IR/Globals.cpp
  llvm/lib/Transforms/IPO/FunctionImport.cpp
  llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
  llvm/test/ThinLTO/X86/alias-ifunc.ll

Index: llvm/test/ThinLTO/X86/alias-ifunc.ll
===
--- /dev/null
+++ llvm/test/ThinLTO/X86/alias-ifunc.ll
@@ -0,0 +1,51 @@
+; RUN: opt -module-summary -o %t.bc %s
+; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-BAR
+; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-BAZ
+; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-QUX
+; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-RESOLVER
+; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-QUUX
+; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-CORGE
+; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-GRAULT
+; RUN: llvm-lto2 run %t.bc -r %t.bc,foo,px -r %t.bc,bar,px -r %t.bc,baz,px -r %t.bc,qux,px -r %t.bc,grault,px -o %t2
+; RUN: llvm-nm %t2.1 | FileCheck %s --check-prefix=CHECK-SYMBOL
+; CHECK-SYMBOL: i bar
+; CHECK-SYMBOL: i baz
+; CHECK-SYMBOL: i foo
+; CHECK-SYMBOL: t foo_resolver
+; CHECK-SYMBOL: i grault
+; CHECK-SYMBOL: i quuz
+; CHECK-SYMBOL: i qux
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+@foo = ifunc i32 (i32), ptr @foo_resolver
+; CHECK-RESOLVER: (name: "foo_resolver"
+; CHECK-RESOLVER-SAME: live: 1
+define internal i32 (i32)* @foo_resolver() {
+entry:
+  ret i32 (i32)* null
+}
+; CHECK-BAR: (name: "bar"
+; CHECK-BAR-NOT: summaries: ( 
+; CHECK-BAR-SAME: ; guid = {{[0-9]+}}
+@bar = alias i32 (i32), ptr @foo
+; CHECK-BAZ: (name: "baz"
+; CHECK-BAZ-NOT: summaries: ( 
+; CHECK-BAZ-SAME: ; guid = {{[0-9]+}}
+@baz = weak alias i32 (i32), ptr @foo
+; CHECK-QUX: (name: "qux"
+; CHECK-QUX-NOT: summaries: ( 
+; CHECK-QUX-SAME: ; guid = {{[0-9]+}}
+@qux = alias i32 (i32), ptr @bar
+; CHECK-QUUX: (name: "quux"
+; CHECK-QUUX-SAME: live: 1
+@quux = internal alias i32 (i32)* (), ptr @foo_resolver
+@quuz = internal ifunc i32 (i32), ptr @quux
+; CHECK-CORGE: (name: "corge"
+; CHECK-CORGE-NOT: summaries: ( 
+; CHECK-CORGE-SAME: ; guid = {{[0-9]+}}
+@corge = internal alias i32 (i32), ptr @quuz
+; CHECK-GRAULT: (name: "grault"
+; CHECK-GRAULT-NOT: summaries: ( 
+; CHECK-GRAULT-SAME: ; guid = {{[0-9]+}}
+@grault = alias i32 (i32), ptr @corge
Index: llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
===
--- llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
+++ llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
@@ -35,6 +35,13 @@
 bool FunctionImportGlobalProcessing::shouldPromoteLocalToGlobal(
 const GlobalValue *SGV, ValueInfo VI) {
   assert(SGV->hasLocalLinkage());
+
+  // Ifuncs and ifunc alias does not have summary.
+  if (isa(SGV) ||
+  (isa(SGV) &&
+   isa(cast(SGV)->getAliaseeObject(
+return false;
+
   // Both the imported references and the original local variable must
   // be promoted.
   if (!isPerformingImport() && !isModuleExporting())
Index: llvm/lib/Transforms/IPO/FunctionImport.cpp
===
--- llvm/lib/Transforms/IPO/FunctionImport.cpp
+++ llvm/lib/Transforms/IPO/FunctionImport.cpp
@@ -1147,6 +1147,14 @@
   // Declare a callback for the internalize pass that will ask for every
   // candidate GlobalValue if it can be internalized or not.
   auto MustPreserveGV = [&](const GlobalValue &GV) -> bool {
+// It may be the case that GV is on a chain of an ifunc, its alias and
+// subsequent aliases. In this case, the summary for the value is not
+// available.
+if (isa(&GV) ||
+(isa(&GV) &&
+ isa(cast(&GV)->getAliaseeObject(
+  return true;
+
 // Lookup the linkage recorded in the summaries during global analysis.
 auto GS = DefinedGlobals.find(GV.getGUID());
 if (GS == DefinedGlobals.end()) {
@@ -1277,7 +1285,7 @@
   }
 }
 for (GlobalAlias &GA : SrcModule->aliases()) {
-  if (!GA.hasName())
+  if (!GA.hasName() || isa(GA.getAliaseeObject()))
 continue;
   auto GUID = GA.getGUID();
   auto Import = ImportGUIDs.count(GUID);
Index: llvm/lib/IR/Globals.cpp
===
--- llvm/lib/IR/Globals.cpp
+++ ll

[PATCH] D128826: Go-to-type on smart_ptr now also shows Foo

2022-07-10 Thread Tom Praschan via Phabricator via cfe-commits
tom-anders added a comment.

@sammccall I think you can merge this for me now (and also 
https://reviews.llvm.org/D128202)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128826

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


[PATCH] D126880: [clang-tidy] Add cppcoreguidelines-avoid-const-or-ref-data-members check

2022-07-10 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

@LegalizeAdulthood I've addressed your comments, is there anything that should 
be fixed before landing the patch?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126880

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


[PATCH] D129446: [clang][driver] Find Apple default SDK path

2022-07-10 Thread Tobias Hieta via Phabricator via cfe-commits
thieta created this revision.
thieta added reviewers: egorzhdan, t.p.northover, dexonsmith, ldionne.
Herald added a project: All.
thieta requested review of this revision.
Herald added a subscriber: MaskRay.
Herald added a project: clang.

Currently if you download clang and install it on macOS it will
not be able to compile C++ applications out of the box. The
driver can't find the SDK path without help of SDKROOT or -isysroot.

For the Xcode toolchain this is always supplied with xcrun or
the wrapper binary that sets the correct SDKROOT.

But for new users this might be very confusing and since the
path for the SDKs is stable unless the user decide to install
Xcode to an alternative path we can try a naive search for it.

Currently this patch fails a bunch of tests that seems to assume
that no SDK is found and then the macosx-min stuff is set to
something very low. This changes when you have a real SDK.

I also haven't added any new tests to test this since I am didn't
want to assume that Xcode is installed on the system running the
tests. Does anyone have a good idea for testing this?

Tagged a bunch of apple people that have touched the driver
recently - but feel free to add more in here if needed.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129446

Files:
  clang/lib/Driver/ToolChains/Darwin.cpp


Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -18,7 +18,9 @@
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/Options.h"
 #include "clang/Driver/SanitizerArgs.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
+#include "llvm/ADT/Triple.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/ProfileData/InstrProf.h"
 #include "llvm/Support/Path.h"
@@ -2039,6 +2041,30 @@
 
 } // namespace
 
+static const std::string guessSDKPath(const llvm::Triple::OSType OSType) {
+  std::string Platform;
+
+  if (OSType == llvm::Triple::OSType::MacOSX || OSType == 
llvm::Triple::OSType::Darwin) {
+// Assume macOS when nothing specific is specified.
+Platform = "MacOSX";
+  } else if (OSType == llvm::Triple::OSType::IOS) {
+Platform = "IPhoneOS";
+  } else if (OSType == llvm::Triple::OSType::TvOS) {
+Platform = "AppleTVOS";
+  } else if (OSType == llvm::Triple::OSType::WatchOS) {
+Platform = "WatchOS";
+  }
+
+  std::string GuessPath = (
+"/Applications/Xcode.app/Contents/Developer/Platforms/"
++ Platform
++ ".platform/Developer/SDKs/"
++ Platform
++ ".sdk");
+
+  return GuessPath;
+}
+
 void Darwin::AddDeploymentTarget(DerivedArgList &Args) const {
   const OptTable &Opts = getDriver().getOpts();
 
@@ -2058,6 +2084,14 @@
 Args.append(Args.MakeSeparateArg(
 nullptr, Opts.getOption(options::OPT_isysroot), env));
   }
+} else {
+  // If the user doesn't pass -isysroot nor SDKROOT we will try to guess
+  // the standard path of the SDK (in /Applications/Xcode.app ...)
+  const std::string GuessPath = guessSDKPath(getTriple().getOS());
+  if (getVFS().exists(GuessPath)) {
+Args.append(Args.MakeSeparateArg(
+  nullptr, Opts.getOption(options::OPT_isysroot), GuessPath));
+  }
 }
   }
 
@@ -2251,6 +2285,7 @@
 return DriverArgs.getLastArgValue(options::OPT_isysroot);
   if (!getDriver().SysRoot.empty())
 return getDriver().SysRoot;
+
   return "/";
 }
 


Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -18,7 +18,9 @@
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/Options.h"
 #include "clang/Driver/SanitizerArgs.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
+#include "llvm/ADT/Triple.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/ProfileData/InstrProf.h"
 #include "llvm/Support/Path.h"
@@ -2039,6 +2041,30 @@
 
 } // namespace
 
+static const std::string guessSDKPath(const llvm::Triple::OSType OSType) {
+  std::string Platform;
+
+  if (OSType == llvm::Triple::OSType::MacOSX || OSType == llvm::Triple::OSType::Darwin) {
+// Assume macOS when nothing specific is specified.
+Platform = "MacOSX";
+  } else if (OSType == llvm::Triple::OSType::IOS) {
+Platform = "IPhoneOS";
+  } else if (OSType == llvm::Triple::OSType::TvOS) {
+Platform = "AppleTVOS";
+  } else if (OSType == llvm::Triple::OSType::WatchOS) {
+Platform = "WatchOS";
+  }
+
+  std::string GuessPath = (
+"/Applications/Xcode.app/Contents/Developer/Platforms/"
++ Platform
++ ".platform/Developer/SDKs/"
++ Platform
++ ".sdk");
+
+  return GuessPath;
+}
+
 void Darwin::AddDeploymentTarget(DerivedArgList &Args) const {
   const OptTable &Opts = getDriver().getOpts();
 
@@ -2058,6 +2084,14 @@
 Args.append(

[PATCH] D129448: [CodeGen][Asan] Emit lifetime intrinsic for bypassed label

2022-07-10 Thread luxufan via Phabricator via cfe-commits
StephenFan created this revision.
StephenFan added reviewers: MaskRay, vitalybuka, rsmith.
Herald added a project: All.
StephenFan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fix https://github.com/llvm/llvm-project/issues/56356
For following test case:

  extern int bar(char *A, int n);
  void goto_bypass(void) {
{
  char x;
l1:
  bar(&x, 1);
}
goto l1;
  }

And using `clang -cc1 -O2 -S -emit-llvm` to compile it.

  In the past, due to the existence of bypassed label, the lifetime

intrinsic would not be generated. This was also the cause of pr56356.

  In this patch, if the variable is bypassed, we do variable

allocation, emit lifetime-start intrinsic and record the lifetime-start
intrinsic in LexicalScope. Then When emitting the bypass label, we emit
the lifetime instrinsic again to make sure the lifetime of the bypassed
variable is start again. Address sanitizer will capture these lifetime
intrinsics and instrument poison and unpoison code. Finally pr56356 can
be resolved.

Here is the new llvm-ir of the test case above.

  define dso_local void @goto_bypass() local_unnamed_addr #0 {
  entry:
%x = alloca i8, align 1
call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %x) #3
br label %l1
  
  l1:   ; preds = %l1, %entry
call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %x) #3
%call = call i32 @bar(ptr noundef nonnull %x, i32 noundef 1) #3
call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %x) #3
br label %l1
  }


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129448

Files:
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/test/CodeGen/lifetime2.c

Index: clang/test/CodeGen/lifetime2.c
===
--- clang/test/CodeGen/lifetime2.c
+++ clang/test/CodeGen/lifetime2.c
@@ -35,11 +35,12 @@
 // CHECK-LABEL: @goto_bypass
 void goto_bypass(void) {
   {
-// O2-NOT: @llvm.lifetime.start.p0i8(i64 1
-// O2-NOT: @llvm.lifetime.end.p0i8(i64 1
+// O2: @llvm.lifetime.start.p0i8(i64 1
 char x;
   l1:
+// O2: @llvm.lifetime.start.p0i8(i64 1
 bar(&x, 1);
+// O2: @llvm.lifetime.end.p0i8(i64 1
   }
   goto l1;
 }
@@ -69,8 +70,8 @@
   switch (n) {
   case 1:
 n = n;
-// O2-NOT: @llvm.lifetime.start.p0i8(i64 1
-// O2-NOT: @llvm.lifetime.end.p0i8(i64 1
+// O2: @llvm.lifetime.start.p0i8(i64 1
+// O2: @llvm.lifetime.end.p0i8(i64 1
 char x;
 bar(&x, 1);
 break;
@@ -83,7 +84,7 @@
 // CHECK-LABEL: @indirect_jump
 void indirect_jump(int n) {
   char x;
-  // O2-NOT: @llvm.lifetime
+  // O2: @llvm.lifetime
   void *T[] = {&&L};
   goto *T[n];
 L:
Index: clang/lib/CodeGen/CodeGenFunction.h
===
--- clang/lib/CodeGen/CodeGenFunction.h
+++ clang/lib/CodeGen/CodeGenFunction.h
@@ -38,6 +38,7 @@
 #include "llvm/ADT/MapVector.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Frontend/OpenMP/OMPIRBuilder.h"
+#include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/ValueHandle.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Transforms/Utils/SanitizerStats.h"
@@ -931,6 +932,7 @@
   class LexicalScope : public RunCleanupsScope {
 SourceRange Range;
 SmallVector Labels;
+SmallVector LifetimeStartMarkers;
 LexicalScope *ParentScope;
 
 LexicalScope(const LexicalScope &) = delete;
@@ -950,6 +952,19 @@
   Labels.push_back(label);
 }
 
+void addLifetimeStartMarker(const llvm::CallInst *LifetimeStartMarker) {
+  assert(isa(LifetimeStartMarker) &&
+ cast(LifetimeStartMarker)->getIntrinsicID() ==
+ llvm::Intrinsic::lifetime_start &&
+ "LifetimeStartMarker Is not a lifetime start intrinsic");
+  LifetimeStartMarkers.push_back(LifetimeStartMarker);
+}
+
+const SmallVector &
+getLifetimeStartMarkers() const {
+  return LifetimeStartMarkers;
+}
+
 /// Exit this cleanup scope, emitting any accumulated
 /// cleanups.
 ~LexicalScope() {
@@ -2922,7 +2937,8 @@
   void EmitSehTryScopeBegin();
   void EmitSehTryScopeEnd();
 
-  llvm::Value *EmitLifetimeStart(llvm::TypeSize Size, llvm::Value *Addr);
+  llvm::Value *EmitLifetimeStart(llvm::TypeSize Size, llvm::Value *Addr,
+ bool isBypassed = false);
   void EmitLifetimeEnd(llvm::Value *Size, llvm::Value *Addr);
 
   llvm::Value *EmitCXXNewExpr(const CXXNewExpr *E);
Index: clang/lib/CodeGen/CGStmt.cpp
===
--- clang/lib/CodeGen/CGStmt.cpp
+++ clang/lib/CodeGen/CGStmt.cpp
@@ -647,6 +647,12 @@
 
   EmitBlock(Dest.getBlock());
 
+  if (CurLexicalScope)
+llvm::for_each(CurLexicalScope->getLifetimeStartMarkers(),
+   [this](const llvm::CallInst *LifetimeStartMarker) {
+  

[PATCH] D129061: [Lex] Diagnose macro in command lines

2022-07-10 Thread Jack Huang via Phabricator via cfe-commits
jackhong12 updated this revision to Diff 443516.
jackhong12 added a comment.

- modify option names
- only allow driver-defined macros used in cc1


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

https://reviews.llvm.org/D129061

Files:
  clang-tools-extra/test/pp-trace/pp-trace-include.cpp
  clang/include/clang/Driver/Options.td
  clang/include/clang/Lex/PreprocessorOptions.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Lex/PPDirectives.cpp
  clang/test/Driver/cl-runtime-flags.c
  clang/test/Driver/mingw.cpp
  clang/test/Preprocessor/macro-command-line-diagnosis.c

Index: clang/test/Preprocessor/macro-command-line-diagnosis.c
===
--- /dev/null
+++ clang/test/Preprocessor/macro-command-line-diagnosis.c
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -Wreserved-identifier -D__WHY_NOT_ME__ -U__STDC__ %s -o - 2>&1 | FileCheck %s
+
+// CHECK:  warning: macro name is a reserved identifier [-Wreserved-macro-identifier]
+// CHECK-NEXT: #define __WHY_NOT_ME__ 1
+// CHECK:  warning: macro name is a reserved identifier [-Wreserved-macro-identifier]
+// CHECK-NEXT: #undef __STDC__
Index: clang/test/Driver/mingw.cpp
===
--- clang/test/Driver/mingw.cpp
+++ clang/test/Driver/mingw.cpp
@@ -61,7 +61,7 @@
 // RUN: %clang -target i686-windows-gnu -E -### %s 2>&1 | FileCheck -check-prefix=CHECK_MINGW_NO_UNICODE %s
 // RUN: %clang -target i686-windows-gnu -E -### %s -municode 2>&1 | FileCheck -check-prefix=CHECK_MINGW_UNICODE %s
 // CHECK_MINGW_NO_UNICODE-NOT: "-DUNICODE"
-// CHECK_MINGW_UNICODE: "-DUNICODE"
+// CHECK_MINGW_UNICODE: "-driver-define=UNICODE"
 
 // RUN: %clang -target i686-windows-gnu -### %s 2>&1 | FileCheck -check-prefix=CHECK_NO_SUBSYS %s
 // RUN: %clang -target i686-windows-gnu -### %s -mwindows -mconsole 2>&1 | FileCheck -check-prefix=CHECK_SUBSYS_CONSOLE %s
Index: clang/test/Driver/cl-runtime-flags.c
===
--- clang/test/Driver/cl-runtime-flags.c
+++ clang/test/Driver/cl-runtime-flags.c
@@ -3,85 +3,85 @@
 
 // First check that regular clang doesn't do any of this stuff.
 // RUN: %clang -### %s 2>&1 | FileCheck -check-prefix=CHECK-CLANG %s
-// CHECK-CLANG-NOT: "-D_DEBUG"
-// CHECK-CLANG-NOT: "-D_MT"
-// CHECK-CLANG-NOT: "-D_DLL"
+// CHECK-CLANG-NOT: "-driver-define=_DEBUG"
+// CHECK-CLANG-NOT: "-driver-define=_MT"
+// CHECK-CLANG-NOT: "-driver-define=_DLL"
 // CHECK-CLANG-NOT: --dependent-lib
 
 // RUN: %clang_cl -### -- %s 2>&1 | FileCheck -check-prefix=CHECK-MT %s
 // RUN: %clang_cl -### /MT -- %s 2>&1 | FileCheck -check-prefix=CHECK-MT %s
-// CHECK-MT-NOT: "-D_DEBUG"
-// CHECK-MT: "-D_MT"
-// CHECK-MT-NOT: "-D_DLL"
+// CHECK-MT-NOT: "-driver-define=_DEBUG"
+// CHECK-MT: "-driver-define=_MT"
+// CHECK-MT-NOT: "-driver-define=_DLL"
 // CHECK-MT: "-flto-visibility-public-std"
 // CHECK-MT: "--dependent-lib=libcmt"
 // CHECK-MT: "--dependent-lib=oldnames"
 
 // RUN: %clang_cl -### /MTd -- %s 2>&1 | FileCheck -check-prefix=CHECK-MTd %s
 // RUN: %clang_cl -### /LD /MTd -- %s 2>&1 | FileCheck -check-prefix=CHECK-MTd %s
-// CHECK-MTd: "-D_DEBUG"
-// CHECK-MTd: "-D_MT"
-// CHECK-MTd-NOT: "-D_DLL"
+// CHECK-MTd: "-driver-define=_DEBUG"
+// CHECK-MTd: "-driver-define=_MT"
+// CHECK-MTd-NOT: "-driver-define=_DLL"
 // CHECK-MTd: "-flto-visibility-public-std"
 // CHECK-MTd: "--dependent-lib=libcmtd"
 // CHECK-MTd: "--dependent-lib=oldnames"
 
 // RUN: %clang_cl -### /MD -- %s 2>&1 | FileCheck -check-prefix=CHECK-MD %s
-// CHECK-MD-NOT: "-D_DEBUG"
-// CHECK-MD: "-D_MT"
-// CHECK-MD: "-D_DLL"
+// CHECK-MD-NOT: "-driver-define=_DEBUG"
+// CHECK-MD: "-driver-define=_MT"
+// CHECK-MD: "-driver-define=_DLL"
 // CHECK-MD: "--dependent-lib=msvcrt"
 // CHECK-MD: "--dependent-lib=oldnames"
 
 // RUN: %clang_cl -### /MDd -- %s 2>&1 | FileCheck -check-prefix=CHECK-MDd %s
-// CHECK-MDd: "-D_DEBUG"
-// CHECK-MDd: "-D_MT"
-// CHECK-MDd: "-D_DLL"
+// CHECK-MDd: "-driver-define=_DEBUG"
+// CHECK-MDd: "-driver-define=_MT"
+// CHECK-MDd: "-driver-define=_DLL"
 // CHECK-MDd: "--dependent-lib=msvcrtd"
 // CHECK-MDd: "--dependent-lib=oldnames"
 
 // RUN: %clang_cl -### /LD -- %s 2>&1 | FileCheck -check-prefix=CHECK-LD %s
 // RUN: %clang_cl -### /LD /MT -- %s 2>&1 | FileCheck -check-prefix=CHECK-LD %s
-// CHECK-LD-NOT: "-D_DEBUG"
-// CHECK-LD: "-D_MT"
-// CHECK-LD-NOT: "-D_DLL"
+// CHECK-LD-NOT: "-driver-define=_DEBUG"
+// CHECK-LD: "-driver-define=_MT"
+// CHECK-LD-NOT: "-driver-define=_DLL"
 // CHECK-LD: "--dependent-lib=libcmt"
 
 // RUN: %clang_cl -### /LDd -- %s 2>&1 | FileCheck -check-prefix=CHECK-LDd %s
 // RUN: %clang_cl -### /LDd /MTd -- %s 2>&1 | FileCheck -check-prefix=CHECK-LDd %s
-// CHECK-LDd: "-D_DEBUG"
-// CHECK-LDd: "-D_MT"
-// CHECK-LDd-NOT: "-D_DLL"
+// CHECK-LDd: "-driver-define=_DEBUG"
+// CHECK-LDd: "-driver-define=_MT"
+// 

[PATCH] D129061: [Lex] Diagnose macro in command lines

2022-07-10 Thread Jack Huang via Phabricator via cfe-commits
jackhong12 added inline comments.



Comment at: clang/include/clang/Driver/Options.td:664
 HelpText<"Define  to  (or 1 if  omitted)">;
+def DriverDefine : JoinedOrSeparate<["-"], "driver-define">, 
Group,
+Flags<[CC1Option, FlangOption, FC1Option]>, MetaVarName<"=">,

MaskRay wrote:
> Make this CC1 only  option `NoDriverOption` by moving it somewhere under `let 
> Flags = [CC1Option, NoDriverOption] in {`
> 
> Don't add new `Separate` or `JoinedOrSeparate` options. They are legacy.
I tried to add `=` behind `driver-define`. But I got the following error 
messages when I ran `ninja check-all`.
```
[416/433] cd /home/zhenhong/ssd/zhenhong/llvm-project/clang/bindings/python && 
/usr/bin/cmake -E env 
CLANG_LIBRARY_PATH=/home/zhenhong/ssd/zhenhong/llvm-project/release/lib 
/usr/bin/python3.8 -m unittest discover  
FAILED: tools/clang/bindings/python/tests/CMakeFiles/check-clang-python 

  
cd /home/zhenhong/ssd/zhenhong/llvm-project/clang/bindings/python && 
/usr/bin/cmake -E env 
CLANG_LIBRARY_PATH=/home/zhenhong/ssd/zhenhong/llvm-project/release/lib 
/usr/bin/python3.8 -m unittest discover
E..EE...EE.E....EE


==  

  
ERROR: test_access_specifiers 
(tests.cindex.test_access_specifiers.TestAccessSpecifiers)  


Ensure that C++ access specifiers are available on cursors  

  
--  

  
Traceback (most recent call last):  

  
  File 
"/home/zhenhong/ssd/zhenhong/llvm-project/clang/bindings/python/tests/cindex/test_access_specifiers.py",
 line 20, in test_access_specifiers 
   
tu = get_tu(""" 

  
  File 
"/home/zhenhong/ssd/zhenhong/llvm-project/clang/bindings/python/tests/cindex/util.py",
 line 40, in get_tu 
 
return TranslationUnit.from_source(name, args, unsaved_files=[(name,

  
  File 
"/home/zhenhong/ssd/zhenhong/llvm-project/clang/bindings/python/clang/cindex.py",
 line 2837, in from_source  
  
raise TranslationUnitLoadError("Error parsing translation unit.")   

  
clang.cindex.TranslationUnitLoadError: Error parsing translation unit.

...
```

I don't know what triggers the crash.


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

https://reviews.llvm.org/D129061

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


[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs

2022-07-10 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added a comment.
This revision is now accepted and ready to land.

  As https://github.com/llvm/llvm-project/issues/56290 indicates, when an ifunc 
is aliased in LTO, clang will attempt to create an alias summary; however, as 
ifunc is not included in the module summary, doing so will lead to problems.
  
  Fixes https://github.com/llvm/llvm-project/issues/56290

Don't repeat the link. You can use :

  Fixes https://github.com/llvm/llvm-project/issues/56290: when an ifunc ...




Comment at: llvm/include/llvm/IR/GlobalIFunc.h:102
+  /// aliases along the path.
+  void applyAlongResolverPath(function_ref Op) 
const;
 };

Prefer `const GlobalValue &` if not-nullable.



Comment at: llvm/test/ThinLTO/X86/alias-ifunc.ll:22
+@foo = ifunc i32 (i32), ptr @foo_resolver
+; CHECK-RESOLVER: (name: "foo_resolver"
+; CHECK-RESOLVER-SAME: live: 1

For the same check prefix, align the content.

```
; CHECK-RESOLVER:  (name: "foo_resolver"
; CHECK-RESOLVER-SAME: live: 1



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129009

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


[PATCH] D122931: [CMake][compiler-rt] Support for using in-tree libc++

2022-07-10 Thread Petr Hosek via Phabricator via cfe-commits
phosek abandoned this revision.
phosek added a comment.

This was broken up into a series of smaller changes which landed separately.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122931

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


[PATCH] D129456: [lldb] Add image dump pcm command

2022-07-10 Thread Dave Lee via Phabricator via cfe-commits
kastiglione created this revision.
kastiglione added reviewers: JDevlieghere, mib, augusto2112.
Herald added subscribers: kbarton, nemanjai.
Herald added a project: All.
kastiglione requested review of this revision.
Herald added projects: clang, LLDB.
Herald added subscribers: lldb-commits, cfe-commits.

Add `pcm-info` to the `target module dump` subcommands.

This dump command shows information about clang .pcm files. This command
effectively runs `clang -module-file-info` and produces identical output.

The .pcm file format is tightly coupled to the clang version. The clang
embedded in lldb is not guaranteed to match the version of the clang executable
available on the local system.

There have been times when I've needed to view the details about a .pcm file
produced by lldb's embedded clang, but because the clang executable was a
slightly different version, the `-module-file-info` invocation failed. With
this command, users can inspect .pcm files generated by lldb too.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129456

Files:
  clang/include/clang/Frontend/FrontendActions.h
  clang/lib/Frontend/FrontendActions.cpp
  lldb/source/Commands/CommandObjectTarget.cpp
  lldb/test/API/commands/target/dump-pcm-info/Makefile
  lldb/test/API/commands/target/dump-pcm-info/TestDumpPCMInfo.py
  lldb/test/API/commands/target/dump-pcm-info/main.m

Index: lldb/test/API/commands/target/dump-pcm-info/main.m
===
--- /dev/null
+++ lldb/test/API/commands/target/dump-pcm-info/main.m
@@ -0,0 +1 @@
+int main() { return 0; }
Index: lldb/test/API/commands/target/dump-pcm-info/TestDumpPCMInfo.py
===
--- /dev/null
+++ lldb/test/API/commands/target/dump-pcm-info/TestDumpPCMInfo.py
@@ -0,0 +1,40 @@
+"""
+Test 'target modules dump pcm-info'.
+"""
+
+import os
+import shutil
+import glob
+
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class TestCase(TestBase):
+@no_debug_info_test
+def test(self):
+self.build()
+
+# lldbutil.run_break_set_by_symbol(self, "main")
+lldbutil.run_to_source_breakpoint(
+self, "return", lldb.SBFileSpec("main.m"))
+
+mod_cache = self.getBuildArtifact("private-module-cache")
+if os.path.isdir(mod_cache):
+shutil.rmtree(mod_cache)
+
+self.runCmd(f"settings set symbols.clang-modules-cache-path '{mod_cache}'")
+
+# Cause lldb to generate a Darwin-*.pcm
+self.runCmd("p @import Darwin")
+
+# root//-.pcm
+pcm_paths = glob.glob(os.path.join(mod_cache, '*', 'Darwin-*.pcm'))
+self.assertEqual(len(pcm_paths), 1, "Expected one Darwin pcm")
+pcm_path = pcm_paths[0]
+
+self.expect(
+f"target modules dump pcm-info '{pcm_path}'",
+startstr=f"Information for module file '{pcm_path}'",
+substrs=["Module name: Darwin"])
Index: lldb/test/API/commands/target/dump-pcm-info/Makefile
===
--- /dev/null
+++ lldb/test/API/commands/target/dump-pcm-info/Makefile
@@ -0,0 +1,4 @@
+OBJC_SOURCES := main.m
+USE_PRIVATE_MODULE_CACHE = YES
+include Makefile.rules
+
Index: lldb/source/Commands/CommandObjectTarget.cpp
===
--- lldb/source/Commands/CommandObjectTarget.cpp
+++ lldb/source/Commands/CommandObjectTarget.cpp
@@ -53,6 +53,10 @@
 #include "lldb/lldb-enumerations.h"
 #include "lldb/lldb-private-enumerations.h"
 
+#include "clang/CodeGen/ObjectFilePCHContainerOperations.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/CompilerInvocation.h"
+#include "clang/Frontend/FrontendActions.h"
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/FormatAdapters.h"
@@ -2155,6 +2159,41 @@
   }
 };
 
+class CommandObjectTargetModulesDumpClangPCMInfo : public CommandObjectParsed {
+public:
+  CommandObjectTargetModulesDumpClangPCMInfo(CommandInterpreter &interpreter)
+  : CommandObjectParsed(
+interpreter, "target modules dump pcm-info",
+"Dump information about the given clang module (pcm).") {
+// Take a single file argument.
+CommandArgumentData arg{eArgTypeFilename, eArgRepeatPlain};
+m_arguments.push_back({arg});
+  }
+
+  ~CommandObjectTargetModulesDumpClangPCMInfo() override = default;
+
+protected:
+  bool DoExecute(Args &command, CommandReturnObject &result) override {
+clang::CompilerInstance compiler;
+compiler.createDiagnostics();
+
+const char *pcm_path = command.GetArgumentAtIndex(0);
+const char *clang_args[] = {"clang", pcm_path};
+compiler.setInvocation(clang::createInvocation(clang_args));
+
+clang::DumpModuleInfoAction dump_module_info;
+dump_module_info.OutputStream = &result.GetOutp

[PATCH] D129456: [lldb] Add image dump pcm command

2022-07-10 Thread Dave Lee via Phabricator via cfe-commits
kastiglione updated this revision to Diff 443531.
kastiglione added a comment.

add @skipUnlessDarwin


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129456

Files:
  clang/include/clang/Frontend/FrontendActions.h
  clang/lib/Frontend/FrontendActions.cpp
  lldb/source/Commands/CommandObjectTarget.cpp
  lldb/test/API/commands/target/dump-pcm-info/Makefile
  lldb/test/API/commands/target/dump-pcm-info/TestDumpPCMInfo.py
  lldb/test/API/commands/target/dump-pcm-info/main.m

Index: lldb/test/API/commands/target/dump-pcm-info/main.m
===
--- /dev/null
+++ lldb/test/API/commands/target/dump-pcm-info/main.m
@@ -0,0 +1 @@
+int main() { return 0; }
Index: lldb/test/API/commands/target/dump-pcm-info/TestDumpPCMInfo.py
===
--- /dev/null
+++ lldb/test/API/commands/target/dump-pcm-info/TestDumpPCMInfo.py
@@ -0,0 +1,41 @@
+"""
+Test 'target modules dump pcm-info'.
+"""
+
+import os
+import shutil
+import glob
+
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class TestCase(TestBase):
+@no_debug_info_test
+@skipUnlessDarwin
+def test(self):
+self.build()
+
+# lldbutil.run_break_set_by_symbol(self, "main")
+lldbutil.run_to_source_breakpoint(
+self, "return", lldb.SBFileSpec("main.m"))
+
+mod_cache = self.getBuildArtifact("private-module-cache")
+if os.path.isdir(mod_cache):
+shutil.rmtree(mod_cache)
+
+self.runCmd(f"settings set symbols.clang-modules-cache-path '{mod_cache}'")
+
+# Cause lldb to generate a Darwin-*.pcm
+self.runCmd("p @import Darwin")
+
+# root//-.pcm
+pcm_paths = glob.glob(os.path.join(mod_cache, '*', 'Darwin-*.pcm'))
+self.assertEqual(len(pcm_paths), 1, "Expected one Darwin pcm")
+pcm_path = pcm_paths[0]
+
+self.expect(
+f"target modules dump pcm-info '{pcm_path}'",
+startstr=f"Information for module file '{pcm_path}'",
+substrs=["Module name: Darwin"])
Index: lldb/test/API/commands/target/dump-pcm-info/Makefile
===
--- /dev/null
+++ lldb/test/API/commands/target/dump-pcm-info/Makefile
@@ -0,0 +1,4 @@
+OBJC_SOURCES := main.m
+USE_PRIVATE_MODULE_CACHE = YES
+include Makefile.rules
+
Index: lldb/source/Commands/CommandObjectTarget.cpp
===
--- lldb/source/Commands/CommandObjectTarget.cpp
+++ lldb/source/Commands/CommandObjectTarget.cpp
@@ -53,6 +53,10 @@
 #include "lldb/lldb-enumerations.h"
 #include "lldb/lldb-private-enumerations.h"
 
+#include "clang/CodeGen/ObjectFilePCHContainerOperations.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/CompilerInvocation.h"
+#include "clang/Frontend/FrontendActions.h"
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/FormatAdapters.h"
@@ -2155,6 +2159,41 @@
   }
 };
 
+class CommandObjectTargetModulesDumpClangPCMInfo : public CommandObjectParsed {
+public:
+  CommandObjectTargetModulesDumpClangPCMInfo(CommandInterpreter &interpreter)
+  : CommandObjectParsed(
+interpreter, "target modules dump pcm-info",
+"Dump information about the given clang module (pcm).") {
+// Take a single file argument.
+CommandArgumentData arg{eArgTypeFilename, eArgRepeatPlain};
+m_arguments.push_back({arg});
+  }
+
+  ~CommandObjectTargetModulesDumpClangPCMInfo() override = default;
+
+protected:
+  bool DoExecute(Args &command, CommandReturnObject &result) override {
+clang::CompilerInstance compiler;
+compiler.createDiagnostics();
+
+const char *pcm_path = command.GetArgumentAtIndex(0);
+const char *clang_args[] = {"clang", pcm_path};
+compiler.setInvocation(clang::createInvocation(clang_args));
+
+clang::DumpModuleInfoAction dump_module_info;
+dump_module_info.OutputStream = &result.GetOutputStream().AsRawOstream();
+// DumpModuleInfoAction requires ObjectFilePCHContainerReader.
+compiler.getPCHContainerOperations()->registerReader(
+std::make_unique());
+
+if (compiler.ExecuteAction(dump_module_info))
+  result.SetStatus(eReturnStatusSuccessFinishResult);
+
+return result.Succeeded();
+  }
+};
+
 #pragma mark CommandObjectTargetModulesDumpClangAST
 
 // Clang AST dumping command
@@ -2406,10 +2445,10 @@
   CommandObjectTargetModulesDump(CommandInterpreter &interpreter)
   : CommandObjectMultiword(
 interpreter, "target modules dump",
-"Commands for dumping information about one or "
-"more target modules.",
+"Commands for dumping information about one or more target "
+"modules.",

[PATCH] D129456: [lldb] Add image dump pcm command

2022-07-10 Thread Dave Lee via Phabricator via cfe-commits
kastiglione updated this revision to Diff 443532.
kastiglione added a comment.

remove commented-out code in test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129456

Files:
  clang/include/clang/Frontend/FrontendActions.h
  clang/lib/Frontend/FrontendActions.cpp
  lldb/source/Commands/CommandObjectTarget.cpp
  lldb/test/API/commands/target/dump-pcm-info/Makefile
  lldb/test/API/commands/target/dump-pcm-info/TestDumpPCMInfo.py
  lldb/test/API/commands/target/dump-pcm-info/main.m

Index: lldb/test/API/commands/target/dump-pcm-info/main.m
===
--- /dev/null
+++ lldb/test/API/commands/target/dump-pcm-info/main.m
@@ -0,0 +1 @@
+int main() { return 0; }
Index: lldb/test/API/commands/target/dump-pcm-info/TestDumpPCMInfo.py
===
--- /dev/null
+++ lldb/test/API/commands/target/dump-pcm-info/TestDumpPCMInfo.py
@@ -0,0 +1,41 @@
+"""
+Test 'target modules dump pcm-info'.
+"""
+
+import os
+import shutil
+import glob
+
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class TestCase(TestBase):
+@no_debug_info_test
+@skipUnlessDarwin
+def test(self):
+self.build()
+
+lldbutil.run_to_source_breakpoint(
+self, "return", lldb.SBFileSpec("main.m"))
+
+mod_cache = self.getBuildArtifact("private-module-cache")
+if os.path.isdir(mod_cache):
+shutil.rmtree(mod_cache)
+
+self.runCmd(f"settings set symbols.clang-modules-cache-path '{mod_cache}'")
+
+# Cause lldb to generate a Darwin-*.pcm
+self.runCmd("p @import Darwin")
+
+# root//-.pcm
+pcm_paths = glob.glob(os.path.join(mod_cache, '*', 'Darwin-*.pcm'))
+self.assertEqual(len(pcm_paths), 1, "Expected one Darwin pcm")
+pcm_path = pcm_paths[0]
+
+breakpoint()
+self.expect(
+f"target modules dump pcm-info '{pcm_path}'",
+startstr=f"Information for module file '{pcm_path}'",
+substrs=["Module name: Darwin"])
Index: lldb/test/API/commands/target/dump-pcm-info/Makefile
===
--- /dev/null
+++ lldb/test/API/commands/target/dump-pcm-info/Makefile
@@ -0,0 +1,4 @@
+OBJC_SOURCES := main.m
+USE_PRIVATE_MODULE_CACHE = YES
+include Makefile.rules
+
Index: lldb/source/Commands/CommandObjectTarget.cpp
===
--- lldb/source/Commands/CommandObjectTarget.cpp
+++ lldb/source/Commands/CommandObjectTarget.cpp
@@ -53,6 +53,10 @@
 #include "lldb/lldb-enumerations.h"
 #include "lldb/lldb-private-enumerations.h"
 
+#include "clang/CodeGen/ObjectFilePCHContainerOperations.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/CompilerInvocation.h"
+#include "clang/Frontend/FrontendActions.h"
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/FormatAdapters.h"
@@ -2155,6 +2159,41 @@
   }
 };
 
+class CommandObjectTargetModulesDumpClangPCMInfo : public CommandObjectParsed {
+public:
+  CommandObjectTargetModulesDumpClangPCMInfo(CommandInterpreter &interpreter)
+  : CommandObjectParsed(
+interpreter, "target modules dump pcm-info",
+"Dump information about the given clang module (pcm).") {
+// Take a single file argument.
+CommandArgumentData arg{eArgTypeFilename, eArgRepeatPlain};
+m_arguments.push_back({arg});
+  }
+
+  ~CommandObjectTargetModulesDumpClangPCMInfo() override = default;
+
+protected:
+  bool DoExecute(Args &command, CommandReturnObject &result) override {
+clang::CompilerInstance compiler;
+compiler.createDiagnostics();
+
+const char *pcm_path = command.GetArgumentAtIndex(0);
+const char *clang_args[] = {"clang", pcm_path};
+compiler.setInvocation(clang::createInvocation(clang_args));
+
+clang::DumpModuleInfoAction dump_module_info;
+dump_module_info.OutputStream = &result.GetOutputStream().AsRawOstream();
+// DumpModuleInfoAction requires ObjectFilePCHContainerReader.
+compiler.getPCHContainerOperations()->registerReader(
+std::make_unique());
+
+if (compiler.ExecuteAction(dump_module_info))
+  result.SetStatus(eReturnStatusSuccessFinishResult);
+
+return result.Succeeded();
+  }
+};
+
 #pragma mark CommandObjectTargetModulesDumpClangAST
 
 // Clang AST dumping command
@@ -2406,10 +2445,10 @@
   CommandObjectTargetModulesDump(CommandInterpreter &interpreter)
   : CommandObjectMultiword(
 interpreter, "target modules dump",
-"Commands for dumping information about one or "
-"more target modules.",
+"Commands for dumping information about one or more target "
+"modules.",
 "target mod

[PATCH] D129398: [ASTMatchers] Add a new matcher for callee declarations of Obj-C message expressions

2022-07-10 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:3841
 
+/// matches if ObjCMessageExpr's callee declaration matches
+///

Nitpick carryover: needs capital letter and `.`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129398

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


[PATCH] D128314: [Clang-tidy] Fixing a bug in clang-tidy infinite-loop checker

2022-07-10 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.

Thanks! Good to go after the matchers patch is committed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128314

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


[PATCH] D119407: [PowerPC] [Clang] Add SSE4 and BMI compatible intrinsics implementation for PowerPC

2022-07-10 Thread ChenZheng via Phabricator via cfe-commits
shchenz added inline comments.



Comment at: clang/lib/Headers/CMakeLists.txt:170
+  ppc_wrappers/immintrin.h
+  ppc_wrappers/tmmintrin.h
+  ppc_wrappers/x86intrin.h

chapuni wrote:
> It doesn't contain , forgot?
@qiucf Looks like an error here?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119407

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


[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs

2022-07-10 Thread Schrodinger ZHU Yifan via Phabricator via cfe-commits
SchrodingerZhu updated this revision to Diff 443536.
SchrodingerZhu added a comment.

This commit addresses issues mentioned in code reviews:

- change applyAlongResolverPath to use reference since the pointer is supposed 
to be non-null.
- update test format to align check rules under the same prefix.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129009

Files:
  llvm/include/llvm/IR/GlobalIFunc.h
  llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/IR/Globals.cpp
  llvm/lib/Transforms/IPO/FunctionImport.cpp
  llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
  llvm/test/ThinLTO/X86/alias-ifunc.ll

Index: llvm/test/ThinLTO/X86/alias-ifunc.ll
===
--- /dev/null
+++ llvm/test/ThinLTO/X86/alias-ifunc.ll
@@ -0,0 +1,51 @@
+; RUN: opt -module-summary -o %t.bc %s
+; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-BAR
+; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-BAZ
+; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-QUX
+; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-RESOLVER
+; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-QUUX
+; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-CORGE
+; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-GRAULT
+; RUN: llvm-lto2 run %t.bc -r %t.bc,foo,px -r %t.bc,bar,px -r %t.bc,baz,px -r %t.bc,qux,px -r %t.bc,grault,px -o %t2
+; RUN: llvm-nm %t2.1 | FileCheck %s --check-prefix=CHECK-SYMBOL
+; CHECK-SYMBOL: i bar
+; CHECK-SYMBOL: i baz
+; CHECK-SYMBOL: i foo
+; CHECK-SYMBOL: t foo_resolver
+; CHECK-SYMBOL: i grault
+; CHECK-SYMBOL: i quuz
+; CHECK-SYMBOL: i qux
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+@foo = ifunc i32 (i32), ptr @foo_resolver
+; CHECK-RESOLVER:  (name: "foo_resolver"
+; CHECK-RESOLVER-SAME: live: 1
+define internal i32 (i32)* @foo_resolver() {
+entry:
+  ret i32 (i32)* null
+}
+; CHECK-BAR:  (name: "bar"
+; CHECK-BAR-NOT:  summaries: ( 
+; CHECK-BAR-SAME: ; guid = {{[0-9]+}}
+@bar = alias i32 (i32), ptr @foo
+; CHECK-BAZ:  (name: "baz"
+; CHECK-BAZ-NOT:  summaries: ( 
+; CHECK-BAZ-SAME: ; guid = {{[0-9]+}}
+@baz = weak alias i32 (i32), ptr @foo
+; CHECK-QUX:  (name: "qux"
+; CHECK-QUX-NOT:  summaries: ( 
+; CHECK-QUX-SAME: ; guid = {{[0-9]+}}
+@qux = alias i32 (i32), ptr @bar
+; CHECK-QUUX:  (name: "quux"
+; CHECK-QUUX-SAME: live: 1
+@quux = internal alias i32 (i32)* (), ptr @foo_resolver
+@quuz = internal ifunc i32 (i32), ptr @quux
+; CHECK-CORGE:  (name: "corge"
+; CHECK-CORGE-NOT:  summaries: ( 
+; CHECK-CORGE-SAME: ; guid = {{[0-9]+}}
+@corge = internal alias i32 (i32), ptr @quuz
+; CHECK-GRAULT:  (name: "grault"
+; CHECK-GRAULT-NOT:  summaries: ( 
+; CHECK-GRAULT-SAME: ; guid = {{[0-9]+}}
+@grault = alias i32 (i32), ptr @corge
Index: llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
===
--- llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
+++ llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
@@ -35,6 +35,13 @@
 bool FunctionImportGlobalProcessing::shouldPromoteLocalToGlobal(
 const GlobalValue *SGV, ValueInfo VI) {
   assert(SGV->hasLocalLinkage());
+
+  // Ifuncs and ifunc alias does not have summary.
+  if (isa(SGV) ||
+  (isa(SGV) &&
+   isa(cast(SGV)->getAliaseeObject(
+return false;
+
   // Both the imported references and the original local variable must
   // be promoted.
   if (!isPerformingImport() && !isModuleExporting())
Index: llvm/lib/Transforms/IPO/FunctionImport.cpp
===
--- llvm/lib/Transforms/IPO/FunctionImport.cpp
+++ llvm/lib/Transforms/IPO/FunctionImport.cpp
@@ -1147,6 +1147,14 @@
   // Declare a callback for the internalize pass that will ask for every
   // candidate GlobalValue if it can be internalized or not.
   auto MustPreserveGV = [&](const GlobalValue &GV) -> bool {
+// It may be the case that GV is on a chain of an ifunc, its alias and
+// subsequent aliases. In this case, the summary for the value is not
+// available.
+if (isa(&GV) ||
+(isa(&GV) &&
+ isa(cast(&GV)->getAliaseeObject(
+  return true;
+
 // Lookup the linkage recorded in the summaries during global analysis.
 auto GS = DefinedGlobals.find(GV.getGUID());
 if (GS == DefinedGlobals.end()) {
@@ -1277,7 +1285,7 @@
   }
 }
 for (GlobalAlias &GA : SrcModule->aliases()) {
-  if (!GA.hasName())
+  if (!GA.hasName() || isa(GA.getAliaseeObject()))
 continue;
   auto GUID = GA.getGUID();
   auto Import = ImportGUIDs.count(GUID);
Index: llvm/lib/IR/Globals.cpp
===
--- llvm/lib/IR/Glob

[PATCH] D128690: [ODRHash diagnostics] Preparation to minimize subsequent diffs. NFC.

2022-07-10 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu accepted this revision.
ChuanqiXu added a comment.
This revision is now accepted and ready to land.

LGTM basically.




Comment at: clang/lib/Serialization/ASTReader.cpp:10621-10626
 // Compute the hash of the method as if it has no body.
-auto ComputeCXXMethodODRHash = [&Hash](const CXXMethodDecl *D) {
-  Hash.clear();
-  Hash.AddFunctionDecl(D, true /*SkipBody*/);
-  return Hash.CalculateHash();
+auto ComputeCXXMethodODRHash = [](const CXXMethodDecl *D) {
+  ODRHash Hasher;
+  Hasher.AddFunctionDecl(D, true /*SkipBody*/);
+  return Hasher.CalculateHash();
 };

Couldn't we hoist this like others?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128690

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


[PATCH] D129174: [C++20][Modules] Update ADL to handle basic.lookup.argdep p4 [P1815R2 part 1]

2022-07-10 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added inline comments.



Comment at: clang/lib/Sema/SemaLookup.cpp:3859
+// C++20 [basic.lookup.argdep] p4.3 .. are exported
+Module *FM = D->getOwningModule();
+// .. are attached to a named module M, do not appear in the

nit: Although it should be true due to D is ExportDeclContext, it looks better 
to add an assertion at the first sight.



Comment at: clang/lib/Sema/SemaLookup.cpp:3862-3863
+// translation unit containing the point of the lookup..
+if (FM->isModulePurview() &&
+(ModuleScopes.empty() || FM != ModuleScopes.back().Module)) {
+  for (auto *E : AssociatedClasses) {





Comment at: clang/lib/Sema/SemaLookup.cpp:3864-3878
+  for (auto *E : AssociatedClasses) {
+// and have the same innermost enclosing non-inline namespace
+// scope as a declaration of an associated entity attached to M
+if (!E->hasOwningModule() || E->getOwningModule() != FM)
+  continue;
+// TODO: maybe this could be cached when generating the
+// associated namespaces / entities.

nit: how do you think about the suggested style? (not required)



Comment at: clang/lib/Sema/SemaLookup.cpp:3867
+// scope as a declaration of an associated entity attached to M
+if (!E->hasOwningModule() || E->getOwningModule() != FM)
+  continue;

The std says `module` instead of `module unit`. So I think we should consider 
partition unit here. So:
- We need to add a test about partition in the revision.
- We need to add `isInSameModule` methods in other revisions. I know we've 
talked this several times before... I'll take a look.



Comment at: clang/lib/Sema/SemaLookup.cpp:3871-3873
+DeclContext *Ctx = E->getDeclContext();
+while (!Ctx->isFileContext() || Ctx->isInlineNamespace())
+  Ctx = Ctx->getParent();

Maybe it is worth to implement `getNonInlineEnclosingNamespaceContext` and we 
could simplify the code here:



Comment at: clang/lib/Sema/SemaOverload.cpp:6407
+getLangOpts().CPlusPlusModules &&
+MF->getTopLevelModule() != getCurrentModule()->getTopLevelModule()) {
+  Candidate.Viable = false;

I introduced `isModuleUnitOfCurrentTU` to simplify the code a little bit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129174

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


[PATCH] D129448: [CodeGen][Asan] Emit lifetime intrinsic for bypassed label

2022-07-10 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added a comment.

looks like check-asan tests fail


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129448

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


[PATCH] D129068: [AST] Accept identical TypeConstraint referring to other template parameters.

2022-07-10 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu updated this revision to Diff 443548.
ChuanqiXu added a comment.

Address comments.


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

https://reviews.llvm.org/D129068

Files:
  clang/include/clang/AST/ASTContext.h
  clang/lib/AST/ASTContext.cpp
  clang/test/Modules/concept.cppm

Index: clang/test/Modules/concept.cppm
===
--- clang/test/Modules/concept.cppm
+++ clang/test/Modules/concept.cppm
@@ -3,6 +3,7 @@
 // RUN: split-file %s %t
 //
 // RUN: %clang_cc1 -std=c++20 %t/A.cppm -emit-module-interface -o %t/A.pcm
+// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t -I%t -DDIFFERENT %t/B.cppm -verify
 // RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t -I%t %t/B.cppm -verify
 
 //--- foo.h
@@ -18,6 +19,9 @@
 template 
 concept __member_size = requires(_Tp &&t) { t.size(); };
 
+template 
+concept C = requires(First x, Second y) { x + y; };
+
 struct A {
 public:
   template 
@@ -29,6 +33,29 @@
   constexpr __integer_like auto operator()(_Tp&& __t) const {
 return __t.size();
   }
+
+  template <__integer_like _Tp, C<_Tp> Sentinel>
+  constexpr _Tp operator()(_Tp &&__t, Sentinel &&last) const {
+return __t;
+  }
+
+  template  class H, class S, C> Sentinel>
+  constexpr H operator()(H &&__s, Sentinel &&last) const {
+return __s;
+  }
+
+// Tests that we could find different concept definition indeed.
+#ifndef DIFFERENT
+  template <__integer_like _Tp, __integer_like _Up, C<_Tp> Sentinel>
+  constexpr _Tp operator()(_Tp &&__t, _Up _u, Sentinel &&last) const {
+return __t;
+  }
+#else
+  template <__integer_like _Tp, __integer_like _Up, C<_Up> Sentinel>
+  constexpr _Tp operator()(_Tp &&__t, _Up _u, Sentinel &&last) const {
+return __t;
+  }
+#endif
 };
 #endif
 
@@ -38,12 +65,23 @@
 export module A;
 
 //--- B.cppm
-// expected-no-diagnostics
 module;
 #include "foo.h"
 export module B;
 import A;
 
+#ifdef DIFFERENT
+// expected-error@foo.h:41 {{'__fn::operator()' from module 'A.' is not present in definition of '__fn' provided earlier}}
+// expected-note@* 1+{{declaration of 'operator()' does not match}}
+#else
+// expected-no-diagnostics
+#endif
+
+template 
+struct U {
+  auto operator+(U) { return 0; }
+};
+
 void foo() {
 A a;
 struct S {
@@ -51,4 +89,8 @@
 auto operator+(S s) { return 0; }
 };
 __fn{}(S());
+__fn{}(S(), S());
+__fn{}(S(), S(), S());
+
+__fn{}(U(), U());
 }
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -6218,6 +6218,19 @@
  getCanonicalTemplateName(Y).getAsVoidPointer();
 }
 
+bool ASTContext::isSameConstraintExpr(const Expr *XCE, const Expr *YCE) const {
+  if (!XCE != !YCE)
+return false;
+
+  if (!XCE)
+return true;
+
+  llvm::FoldingSetNodeID XCEID, YCEID;
+  XCE->Profile(XCEID, *this, /*Canonical=*/true);
+  YCE->Profile(YCEID, *this, /*Canonical=*/true);
+  return XCEID == YCEID;
+}
+
 bool ASTContext::isSameTemplateParameter(const NamedDecl *X,
  const NamedDecl *Y) const {
   if (X->getKind() != Y->getKind())
@@ -6245,14 +6258,23 @@
 auto *TYTCArgs = TYTC->getTemplateArgsAsWritten();
 if (TXTCArgs->NumTemplateArgs != TYTCArgs->NumTemplateArgs)
   return false;
-llvm::FoldingSetNodeID XID, YID;
-for (auto &ArgLoc : TXTCArgs->arguments())
-  ArgLoc.getArgument().Profile(XID, X->getASTContext());
-for (auto &ArgLoc : TYTCArgs->arguments())
-  ArgLoc.getArgument().Profile(YID, Y->getASTContext());
-if (XID != YID)
-  return false;
+// We couldn't compare the profiling result for the template
+// args here. Consider the following example in different modules:
+//
+// template <__integer_like _Tp, C<_Tp> Sentinel>
+// constexpr _Tp operator()(_Tp &&__t, Sentinel &&last) const {
+//   return __t;
+// }
+//
+// When we compare the profiling result for `C<_Tp>` in different
+// modules, it will compare the type of `_Tp` in different modules.
+// However, the type of `_Tp` in different modules refer to different
+// types here naturally. So we couldn't compare the profiling result
+// for the template args directly.
   }
+  if (!isSameConstraintExpr(TXTC->getImmediatelyDeclaredConstraint(),
+TYTC->getImmediatelyDeclaredConstraint()))
+return false;
 }
 return true;
   }
@@ -6279,19 +6301,7 @@
 if (!isSameTemplateParameter(X->getParam(I), Y->getParam(I)))
   return false;
 
-  const Expr *XRC = X->getRequiresClause();
-  const Expr *YRC = Y->getRequiresClause();
-  if (!XRC != !YRC)
-return false;
-  if (XRC) {
-llvm::FoldingSetNodeID XRCID, YRCID;
-XRC->Profile(XRCID, *this, /*Canonical=*/true);
-Y

[PATCH] D129068: [AST] Accept identical TypeConstraint referring to other template parameters.

2022-07-10 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

In D129068#3640249 , @vsapsai wrote:

> Thanks for the changes, they look good! While I was looking how we handle 
> "requires" constraints in other cases, I've noticed that they are 
> suspiciously similar. That's why I offer the following change to unify 
> comparison of the constraint expressions
>
>   diff --git a/clang/include/clang/AST/ASTContext.h 
> b/clang/include/clang/AST/ASTContext.h
>   index 92293622cc3d..555669f027a7 100644
>   --- a/clang/include/clang/AST/ASTContext.h
>   +++ b/clang/include/clang/AST/ASTContext.h
>   @@ -2664,6 +2664,11 @@ public:
>  /// that they may be used in declarations of the same template.
>  bool isSameTemplateParameter(const NamedDecl *X, const NamedDecl *Y) 
> const;
>
>   +  /// Determine whether two 'requires' expressions are similar enough.
>   +  /// Use of 'requires' isn't mandatory, works with constraints expressed 
> in
>   +  /// other ways too.
>   +  bool isSameConstraintExpr(const Expr *XCE, const Expr *YCE) const;
>   +
>  /// Retrieve the "canonical" template argument.
>  ///
>  /// The canonical template argument is the simplest template argument
>   diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
>   index aced0ab39ace..f3937d6304f9 100644
>   --- a/clang/lib/AST/ASTContext.cpp
>   +++ b/clang/lib/AST/ASTContext.cpp
>   @@ -6245,14 +6245,10 @@ bool ASTContext::isSameTemplateParameter(const 
> NamedDecl *X,
>auto *TYTCArgs = TYTC->getTemplateArgsAsWritten();
>if (TXTCArgs->NumTemplateArgs != TYTCArgs->NumTemplateArgs)
>  return false;
>   -llvm::FoldingSetNodeID XID, YID;
>   -for (auto &ArgLoc : TXTCArgs->arguments())
>   -  ArgLoc.getArgument().Profile(XID, X->getASTContext());
>   -for (auto &ArgLoc : TYTCArgs->arguments())
>   -  ArgLoc.getArgument().Profile(YID, Y->getASTContext());
>   -if (XID != YID)
>   -  return false;
>  }
>   +  if (!isSameConstraintExpr(TXTC->getImmediatelyDeclaredConstraint(),
>   +TYTC->getImmediatelyDeclaredConstraint()))
>   +return false;
>}
>return true;
>  }
>   @@ -6279,15 +6275,20 @@ bool ASTContext::isSameTemplateParameterList(
>if (!isSameTemplateParameter(X->getParam(I), Y->getParam(I)))
>  return false;
>
>   -  const Expr *XRC = X->getRequiresClause();
>   -  const Expr *YRC = Y->getRequiresClause();
>   -  if (!XRC != !YRC)
>   +  if (!isSameConstraintExpr(X->getRequiresClause(), 
> Y->getRequiresClause()))
>return false;
>   -  if (XRC) {
>   -llvm::FoldingSetNodeID XRCID, YRCID;
>   -XRC->Profile(XRCID, *this, /*Canonical=*/true);
>   -YRC->Profile(YRCID, *this, /*Canonical=*/true);
>   -if (XRCID != YRCID)
>   +
>   +  return true;
>   +}
>   +
>   +bool ASTContext::isSameConstraintExpr(const Expr *XCE, const Expr *YCE) 
> const {
>   +  if (!XCE != !YCE)
>   +return false;
>   +  if (XCE) {
>   +llvm::FoldingSetNodeID XCEID, YCEID;
>   +XCE->Profile(XCEID, *this, /*Canonical=*/true);
>   +YCE->Profile(YCEID, *this, /*Canonical=*/true);
>   +if (XCEID != YCEID)
>  return false;
>  }
>
>   @@ -6450,17 +6451,9 @@ bool ASTContext::isSameEntity(const NamedDecl *X, 
> const NamedDecl *Y) const {
>return false;
>}
>
>   -const Expr *XRC = FuncX->getTrailingRequiresClause();
>   -const Expr *YRC = FuncY->getTrailingRequiresClause();
>   -if (!XRC != !YRC)
>   +if (!isSameConstraintExpr(FuncX->getTrailingRequiresClause(),
>   +  FuncY->getTrailingRequiresClause()))
>  return false;
>   -if (XRC) {
>   -  llvm::FoldingSetNodeID XRCID, YRCID;
>   -  XRC->Profile(XRCID, *this, /*Canonical=*/true);
>   -  YRC->Profile(YRCID, *this, /*Canonical=*/true);
>   -  if (XRCID != YRCID)
>   -return false;
>   -}
>
>auto GetTypeAsWritten = [](const FunctionDecl *FD) {
>  // Map to the first declaration that we've already merged into this 
> one.
>
> In `ASTContext::isSameTemplateParameter` it is exactly the same change as 
> yours modulo comments.

Thanks for the detailed suggestion! Done!




Comment at: clang/test/Modules/concept.cppm:38
+  template <__integer_like _Tp, C<_Tp> Sentinel>
+  constexpr _Tp operator()(_Tp &&__t, Sentinel &&last) const {
+return __t;

vsapsai wrote:
> In what cases `operator()` is critical for the test? I was thinking about 
> replacing with something like "funcA", "funcB", "funcC", so that diagnostic 
> verification is easier because it is tricky to understand which method 
> "__fn::operator()" refers to.
The `operator()` is not critical for the test. It is reduced from the actual 
testing. But I prefer to remain `operator()` here. Since tests are rarely read 
and the curre

[PATCH] D129448: [CodeGen][Asan] Emit lifetime intrinsic for bypassed label

2022-07-10 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added inline comments.



Comment at: clang/lib/CodeGen/CodeGenFunction.h:935
 SmallVector Labels;
+SmallVector LifetimeStartMarkers;
 LexicalScope *ParentScope;

LifetimeStartMarkers -> BypassedLifetimeStartMarkers
and below

if I read this correctly this is not any start marker



Comment at: clang/test/CodeGen/lifetime2.c:42
+// O2: @llvm.lifetime.start.p0i8(i64 1
 bar(&x, 1);
+// O2: @llvm.lifetime.end.p0i8(i64 1

It assume this will break Msan 
Transforms/Instrumentation/MemorySanitizer.cpp:1298 as it assume variable is 
not initialized on start

```
void goto_bypass(void) {
  {
char x;
  l1:
bar(&x, 1);
   if (x)
 goto l1
  }
  goto l1;
}
```



Comment at: clang/test/CodeGen/lifetime2.c:78
 break;
   case 2:
 bar(&x, 1);

Please check for lifetime markers, I assume case 2 will have a new one


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129448

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


[PATCH] D129138: [clang] [docs] Update the changes of C++20 Modules in clang15

2022-07-10 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu updated this revision to Diff 443549.
ChuanqiXu marked an inline comment as done.
ChuanqiXu added a comment.

Address comments.


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

https://reviews.llvm.org/D129138

Files:
  clang/docs/ReleaseNotes.rst
  clang/www/cxx_status.html


Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1164,7 +1164,7 @@
 
   Modules
   https://wg21.link/p1103r3";>P1103R3
-  Partial
+  Clang 15
 

 https://wg21.link/p1766r1";>P1766R1 (DR)
@@ -1180,17 +1180,19 @@
   

 https://wg21.link/p1874r1";>P1874R1
-Partial
+Clang 15
   

 https://wg21.link/p1979r0";>P1979R0
-No
+No
   

 https://wg21.link/p1779r3";>P1779R3
+Clang 15
   
   
 https://wg21.link/p1857r3";>P1857R3
+No
   
   
 https://wg21.link/p2115r0";>P2115R0
@@ -1198,7 +1200,7 @@
   
   
 https://wg21.link/p1815r2";>P1815R2
-No
+Partial
   
 
   Coroutines
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -476,6 +476,14 @@
   that can be used for such compatibility. The demangler now demangles
   symbols with named module attachment.
 
+- Enhanced the support for C++20 Modules, including: Partitions,
+  Reachability, Header Unit and ``extern "C++"`` semantics.
+
+- Implemented `P1103R3: Merging Modules `_.
+- Implemented `P1779R3: ABI isolation for member functions 
`_.
+- Implemented `P1874R1: Dynamic Initialization Order of Non-Local Variables in 
Modules `_.
+- Partially implemented `P1815R2: Translation-unit-local entities 
`_.
+
 - As per "Conditionally Trivial Special Member Functions" (P0848), it is
   now possible to overload destructors using concepts. Note that the rest
   of the paper about other special member functions is not yet implemented.


Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1164,7 +1164,7 @@
 
   Modules
   https://wg21.link/p1103r3";>P1103R3
-  Partial
+  Clang 15
 

 https://wg21.link/p1766r1";>P1766R1 (DR)
@@ -1180,17 +1180,19 @@
   

 https://wg21.link/p1874r1";>P1874R1
-Partial
+Clang 15
   

 https://wg21.link/p1979r0";>P1979R0
-No
+No
   

 https://wg21.link/p1779r3";>P1779R3
+Clang 15
   
   
 https://wg21.link/p1857r3";>P1857R3
+No
   
   
 https://wg21.link/p2115r0";>P2115R0
@@ -1198,7 +1200,7 @@
   
   
 https://wg21.link/p1815r2";>P1815R2
-No
+Partial
   
 
   Coroutines
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -476,6 +476,14 @@
   that can be used for such compatibility. The demangler now demangles
   symbols with named module attachment.
 
+- Enhanced the support for C++20 Modules, including: Partitions,
+  Reachability, Header Unit and ``extern "C++"`` semantics.
+
+- Implemented `P1103R3: Merging Modules `_.
+- Implemented `P1779R3: ABI isolation for member functions `_.
+- Implemented `P1874R1: Dynamic Initialization Order of Non-Local Variables in Modules `_.
+- Partially implemented `P1815R2: Translation-unit-local entities `_.
+
 - As per "Conditionally Trivial Special Member Functions" (P0848), it is
   now possible to overload destructors using concepts. Note that the rest
   of the paper about other special member functions is not yet implemented.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129138: [clang] [docs] Update the changes of C++20 Modules in clang15

2022-07-10 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added inline comments.



Comment at: clang/www/cxx_status.html:1183
 https://wg21.link/p1874r1";>P1874R1
-Partial
+Clang 15
   

avogelsgesang wrote:
> should this be `class="unreleased"` instead of `class="full"`? At least this 
> is what other places in this document use when mentioning clang 15
Oh, you're right. Thanks for reporting!


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

https://reviews.llvm.org/D129138

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


[PATCH] D127082: [clangd] Add Macro Expansion to Hover

2022-07-10 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added inline comments.



Comment at: clang-tools-extra/clangd/Hover.cpp:1091
+
+  // Reformat Macro Expansion
+  if (!HI->MacroExpansion.empty()) {

nridge wrote:
> daiyousei-qz wrote:
> > nridge wrote:
> > > It would be interesting to have a couple of test cases that exercise the 
> > > reformatting in non-trivial ways, e.g. long expansions that need to be 
> > > wrapped onto multiple lines
> > > 
> > > I would suggest two such test cases, one with the expansion being in a 
> > > declaration context, and the second an expression context (for this one, 
> > > to make it long enough, the expansion could contain e.g. an `a ? b : c` 
> > > expression)
> > > 
> > > (I'm suggesting the expression-context testcase in part as a sanity check 
> > > to make sure that `format::reformat()` handles such code reasonably in 
> > > the first place)
> > Somehow, this comment goes out of the position. 
> > 
> > In my opinion, such test should be written against `format::reformat()` 
> > directly instead of hover message in clangd. One problem is that we are 
> > using the current style in users' workspace to reformat the 
> > definition/expansion, which means the same tokens might present differently 
> > given different `.clang-format` or fallback style that the user has 
> > specified. I do agree that, if tokens don't conform a regular c++ 
> > expression, like `) . field`, the presentation could be bad. But I suppose 
> > there's no obvious solution for that.
> Phabricator's inter-diff seems to be broken, but glancing through the new 
> revision, it seems like this comment about adding a couple of more test cases 
> hasn't been addressed yet, are you planning to do that in another update?
> In my opinion, such test should be written against format::reformat() 
> directly instead of hover message in clangd. One problem is that we are using 
> the current style in users' workspace to reformat the definition/expansion, 
> which means the same tokens might present differently given different 
> .clang-format or fallback style that the user has specified. I do agree that, 
> if tokens don't conform a regular c++ expression, like ) . field, the 
> presentation could be bad. But I suppose there's no obvious solution for that.

Ok, fair enough. I did some manual testing of the updated patch and reformat() 
seems to have sane behaviour for expressions.

From my point of view, this patch is good to go (with the line endings fixed).  
However, I will defer approval to @sammccall in case he has additional feedback.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127082

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


[PATCH] D108189: [RISCV] Support experimental 'P' extension 0.9.11

2022-07-10 Thread Shao-Ce SUN via Phabricator via cfe-commits
sunshaoce updated this revision to Diff 443552.
sunshaoce added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108189

Files:
  clang/test/Driver/riscv-arch.c
  clang/test/Preprocessor/riscv-target-features.c
  llvm/lib/Support/RISCVISAInfo.cpp
  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
@@ -187,3 +187,15 @@
 
 .attribute arch, "rv32if_zkt1p0_zve32f1p0_zve32x1p0_zvl32b1p0"
 # CHECK: attribute  5, "rv32i2p0_f2p0_zkt1p0_zve32f1p0_zve32x1p0_zvl32b1p0"
+
+.attribute arch, "rv32ip0p911"
+# CHECK: attribute  5, "rv32i2p0_p0p911_zbpbo0p911_zpn0p911_zpsfoperand0p911"
+
+.attribute arch, "rv32izbpbo0p911"
+# CHECK: attribute  5, "rv32i2p0_zbpbo0p911"
+
+.attribute arch, "rv32izpn0p911"
+# CHECK: attribute  5, "rv32i2p0_zpn0p911"
+
+.attribute arch, "rv32izpsfoperand0p911"
+# CHECK: attribute  5, "rv32i2p0_zpsfoperand0p911"
Index: llvm/lib/Support/RISCVISAInfo.cpp
===
--- llvm/lib/Support/RISCVISAInfo.cpp
+++ llvm/lib/Support/RISCVISAInfo.cpp
@@ -109,6 +109,11 @@
 {"zbr", RISCVExtensionVersion{0, 93}},
 {"zbt", RISCVExtensionVersion{0, 93}},
 {"zvfh", RISCVExtensionVersion{0, 1}},
+
+{"p", RISCVExtensionVersion{0, 911}},
+{"zbpbo", RISCVExtensionVersion{0, 911}},
+{"zpn", RISCVExtensionVersion{0, 911}},
+{"zpsfoperand", RISCVExtensionVersion{0, 911}},
 };
 
 static bool stripExperimentalPrefix(StringRef &Ext) {
@@ -598,8 +603,8 @@
 
 // The order is OK, then push it into features.
 // TODO: Use version number when setting target features
-// Currently LLVM supports only "mafdcbv".
-StringRef SupportedStandardExtension = "mafdcbv";
+// Currently LLVM supports only "mafdcbpv".
+StringRef SupportedStandardExtension = "mafdcbpv";
 if (!SupportedStandardExtension.contains(C))
   return createStringError(errc::invalid_argument,
"unsupported standard user-level extension '%c'",
@@ -773,6 +778,7 @@
 static const char *ImpliedExtsZkn[] = {"zbkb", "zbkc", "zbkx", "zkne", "zknd", "zknh"};
 static const char *ImpliedExtsZks[] = {"zbkb", "zbkc", "zbkx", "zksed", "zksh"};
 static const char *ImpliedExtsZvfh[] = {"zve32f"};
+static const char *ImpliedExtsP[] = {"zbpbo", "zpn", "zpsfoperand"};
 
 struct ImpliedExtsEntry {
   StringLiteral Name;
@@ -787,6 +793,7 @@
 
 // Note: The table needs to be sorted by name.
 static constexpr ImpliedExtsEntry ImpliedExts[] = {
+{{"p"}, {ImpliedExtsP}},
 {{"v"}, {ImpliedExtsV}},
 {{"zdinx"}, {ImpliedExtsZdinx}},
 {{"zfh"}, {ImpliedExtsZfh}},
Index: clang/test/Preprocessor/riscv-target-features.c
===
--- clang/test/Preprocessor/riscv-target-features.c
+++ clang/test/Preprocessor/riscv-target-features.c
@@ -42,6 +42,10 @@
 // CHECK-NOT: __riscv_zkr
 // CHECK-NOT: __riscv_zkt
 // CHECK-NOT: __riscv_zk
+// CHECK-NOT: __riscv_p
+// CHECK-NOT: __riscv_zbpbo
+// CHECK-NOT: __riscv_zpn
+// CHECK-NOT: __riscv_zpsfoperand
 // CHECK-NOT: __riscv_zicbom
 // CHECK-NOT: __riscv_zicboz
 
@@ -224,6 +228,44 @@
 // CHECK-ZBT-NOT: __riscv_b
 // CHECK-ZBT-EXT: __riscv_zbt 93000{{$}}
 
+// RUN: %clang -target riscv32-unknown-linux-gnu -menable-experimental-extensions \
+// RUN: -march=rv32ip0p911 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-P-EXT %s
+// RUN: %clang -target riscv64-unknown-linux-gnu -menable-experimental-extensions \
+// RUN: -march=rv64ip0p911 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-P-EXT %s
+// CHECK-P-EXT: __riscv_p 911000{{$}}
+// CHECK-P-EXT: __riscv_zbpbo 911000{{$}}
+// CHECK-P-EXT: __riscv_zpn 911000{{$}}
+// CHECK-P-EXT: __riscv_zpsfoperand 911000{{$}}
+
+// RUN: %clang -target riscv32-unknown-linux-gnu -menable-experimental-extensions \
+// RUN: -march=rv32izbpbo0p911 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZBPBO-EXT %s
+// RUN: %clang -target riscv64-unknown-linux-gnu -menable-experimental-extensions \
+// RUN: -march=rv64izbpbo0p911 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZBPBO-EXT %s
+// CHECK-ZBPBO-NOT: __riscv_p
+// CHECK-ZBPBO-EXT: __riscv_zbpbo 911000{{$}}
+
+// RUN: %clang -target riscv32-unknown-linux-gnu -menable-experimental-extensions \
+// RUN: -march=rv32izpn0p911 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZPN-EXT %s
+// RUN: %clang -target riscv64-unknown-linux-gnu -menable-experimental-extensions \
+// RUN: -march=rv64izpn0p911 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZPN-EXT %s
+// CHECK-ZPN-NOT: __riscv_p
+// CHECK-ZPN-EXT: __riscv_zpn 911000{{$}}
+
+// RUN: %clang -target riscv32-unknown-linux-gnu -me

[PATCH] D128604: [RISCV] Support Zbpbo extension v0.9.11

2022-07-10 Thread Shao-Ce SUN via Phabricator via cfe-commits
sunshaoce updated this revision to Diff 443555.
sunshaoce added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128604

Files:
  clang/include/clang/Basic/BuiltinsRISCV.def
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/RISCV/rvp-intrinsics/riscv32-zbpbo.c
  clang/test/CodeGen/RISCV/rvp-intrinsics/riscv64-zbpbo.c
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVISelLowering.cpp
  llvm/lib/Target/RISCV/RISCVInstrInfoZb.td
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/CodeGen/RISCV/rv32zbpbo-intrinsics.ll
  llvm/test/CodeGen/RISCV/rv32zbpbo.ll
  llvm/test/CodeGen/RISCV/rv64zbpbo-intrinsics.ll
  llvm/test/CodeGen/RISCV/rv64zbpbo.ll
  llvm/test/MC/RISCV/rv32zbpbo-aliases-valid.s
  llvm/test/MC/RISCV/rv32zbpbo-valid.s
  llvm/test/MC/RISCV/rv64zbpbo-aliases-valid.s
  llvm/test/MC/RISCV/rv64zbpbo-valid.s

Index: llvm/test/MC/RISCV/rv64zbpbo-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv64zbpbo-valid.s
@@ -0,0 +1,29 @@
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+experimental-zbpbo -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+experimental-zbpbo < %s \
+# RUN: | llvm-objdump --mattr=+experimental-zbpbo -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
+
+# CHECK-ASM-AND-OBJ: pack t0, t1, t2
+# CHECK-ASM: encoding: [0xb3,0x42,0x73,0x08]
+pack t0, t1, t2
+
+# CHECK-ASM-AND-OBJ: packu t0, t1, t2
+# CHECK-ASM: encoding: [0xb3,0x42,0x73,0x48]
+packu t0, t1, t2
+
+# CHECK-ASM-AND-OBJ: fsrw t0, t1, t2, t3
+# CHECK-ASM: encoding: [0xbb,0x52,0xc3,0x3d]
+fsrw t0, t1, t2, t3
+
+# CHECK-ASM-AND-OBJ: max t0, t1, t2
+# CHECK-ASM: encoding: [0xb3,0x62,0x73,0x0a]
+max t0, t1, t2
+
+# CHECK-ASM-AND-OBJ: min t0, t1, t2
+# CHECK-ASM: encoding: [0xb3,0x42,0x73,0x0a]
+min t0, t1, t2
+
+# CHECK-ASM-AND-OBJ: cmix t0, t1, t2, t3
+# CHECK-ASM: encoding: [0xb3,0x92,0x63,0xe6]
+cmix t0, t1, t2, t3
Index: llvm/test/MC/RISCV/rv64zbpbo-aliases-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv64zbpbo-aliases-valid.s
@@ -0,0 +1,18 @@
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+experimental-zbpbo -riscv-no-aliases \
+# RUN: | FileCheck -check-prefixes=CHECK-S-OBJ-NOALIAS %s
+# RUN: llvm-mc %s  -triple=riscv64 -mattr=+experimental-zbpbo \
+# RUN: | FileCheck -check-prefixes=CHECK-S-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple riscv64 -mattr=+experimental-zbpbo < %s \
+# RUN: | llvm-objdump -d -r -M no-aliases --mattr=+experimental-zbpbo - \
+# RUN: | FileCheck -check-prefixes=CHECK-S-OBJ-NOALIAS %s
+# RUN: llvm-mc -filetype=obj -triple riscv64 -mattr=+experimental-zbpbo < %s \
+# RUN: | llvm-objdump -d -r --mattr=+experimental-zbpbo - \
+# RUN: | FileCheck -check-prefixes=CHECK-S-OBJ %s
+
+# CHECK-S-OBJ-NOALIAS: grevi t0, t1, 8
+# CHECK-S-OBJ: rev8.h t0, t1
+rev8.h x5, x6
+
+# CHECK-S-OBJ-NOALIAS: grevi t0, t1, 63
+# CHECK-S-OBJ: rev t0, t1
+rev x5, x6
Index: llvm/test/MC/RISCV/rv32zbpbo-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv32zbpbo-valid.s
@@ -0,0 +1,37 @@
+# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-zbpbo -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv32 -mattr=+experimental-zbpbo < %s \
+# RUN: | llvm-objdump --mattr=+experimental-zbpbo -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
+
+# CHECK-ASM-AND-OBJ: clz t0, t1
+# CHECK-ASM: encoding: [0x93,0x12,0x03,0x60]
+clz t0, t1
+
+# CHECK-ASM-AND-OBJ: pack t0, t1, t2
+# CHECK-ASM: encoding: [0xb3,0x42,0x73,0x08]
+pack t0, t1, t2
+
+# CHECK-ASM-AND-OBJ: packu t0, t1, t2
+# CHECK-ASM: encoding: [0xb3,0x42,0x73,0x48]
+packu t0, t1, t2
+
+# CHECK-ASM-AND-OBJ: fsr t0, t1, t2, t3
+# CHECK-ASM: encoding: [0xb3,0x52,0xc3,0x3d]
+fsr t0, t1, t2, t3
+
+# CHECK-ASM-AND-OBJ: fsri t0, t1, t2, 0
+# CHECK-ASM: encoding: [0x93,0x52,0x03,0x3c]
+fsri t0, t1, t2, 0
+
+# CHECK-ASM-AND-OBJ: max t0, t1, t2
+# CHECK-ASM: encoding: [0xb3,0x62,0x73,0x0a]
+max t0, t1, t2
+
+# CHECK-ASM-AND-OBJ: min t0, t1, t2
+# CHECK-ASM: encoding: [0xb3,0x42,0x73,0x0a]
+min t0, t1, t2
+
+# CHECK-ASM-AND-OBJ: cmix t0, t1, t2, t3
+# CHECK-ASM: encoding: [0xb3,0x92,0x63,0xe6]
+cmix t0, t1, t2, t3
Index: llvm/test/MC/RISCV/rv32zbpbo-aliases-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv32zbpbo-aliases-valid.s
@@ -0,0 +1,26 @@
+# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-zbpbo -riscv-no-aliases \
+# RUN: | FileCheck -check-prefi

[PATCH] D129443: [clang-format] Add option for aligning requires clause body

2022-07-10 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius requested changes to this revision.
curdeius added a comment.
This revision now requires changes to proceed.

Haven't you forgotten to add formatting tests? :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129443

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


[PATCH] D129461: [PowerPC] Support x86 compatible intrinsics on AIX

2022-07-10 Thread Qiu Chaofan via Phabricator via cfe-commits
qiucf created this revision.
qiucf added reviewers: nemanjai, shchenz, hubert.reinterpretcast, PowerPC.
Herald added subscribers: jsji, steven.zhang, kbarton, krytarowski, 
arichardson, emaste.
Herald added a project: All.
qiucf requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

These headers used to be guarded only on PowerPC64 Linux or FreeBSD.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129461

Files:
  clang/lib/Driver/ToolChains/AIX.cpp
  clang/lib/Headers/ppc_wrappers/emmintrin.h
  clang/lib/Headers/ppc_wrappers/mm_malloc.h
  clang/lib/Headers/ppc_wrappers/mmintrin.h
  clang/lib/Headers/ppc_wrappers/pmmintrin.h
  clang/lib/Headers/ppc_wrappers/smmintrin.h
  clang/lib/Headers/ppc_wrappers/tmmintrin.h
  clang/lib/Headers/ppc_wrappers/xmmintrin.h
  clang/test/CodeGen/PowerPC/ppc-emmintrin.c
  clang/test/CodeGen/PowerPC/ppc-mm-malloc.c
  clang/test/CodeGen/PowerPC/ppc-mmintrin.c
  clang/test/CodeGen/PowerPC/ppc-pmmintrin.c
  clang/test/CodeGen/PowerPC/ppc-smmintrin.c
  clang/test/CodeGen/PowerPC/ppc-tmmintrin.c
  clang/test/CodeGen/PowerPC/ppc-x86gprintrin.c
  clang/test/CodeGen/PowerPC/ppc-xmmintrin.c

Index: clang/test/CodeGen/PowerPC/ppc-xmmintrin.c
===
--- clang/test/CodeGen/PowerPC/ppc-xmmintrin.c
+++ clang/test/CodeGen/PowerPC/ppc-xmmintrin.c
@@ -10,7 +10,7 @@
 // RUN:   -fno-discard-value-names -mllvm -disable-llvm-optzns
 
 // RUN: %clang -Xclang -no-opaque-pointers -S -emit-llvm -target powerpc64le-unknown-linux-gnu -mcpu=pwr10 -ffreestanding -DNO_WARN_X86_INTRINSICS %s \
-// RUN:   -ffp-contract=off -fno-discard-value-names -mllvm -disable-llvm-optzns -o - | llvm-cxxfilt -n | FileCheck %s --check-prefixes=CHECK,CHECK-P10
+// RUN:   -ffp-contract=off -fno-discard-value-names -mllvm -disable-llvm-optzns -o - | llvm-cxxfilt -n | FileCheck %s --check-prefixes=CHECK,CHECK-P10-LE
 
 // RUN: %clang -Xclang -no-opaque-pointers -S -emit-llvm -target powerpc64-unknown-freebsd13.0 -mcpu=pwr8 -ffreestanding -nostdlibinc -DNO_WARN_X86_INTRINSICS %s \
 // RUN:   -fno-discard-value-names -mllvm -disable-llvm-optzns -o - | llvm-cxxfilt -n | FileCheck %s --check-prefixes=CHECK,CHECK-BE
@@ -21,6 +21,13 @@
 // RUN: %clang -Xclang -no-opaque-pointers -x c++ -fsyntax-only -target powerpc64le-unknown-freebsd13.0 -mcpu=pwr8 -ffreestanding -nostdlibinc -DNO_WARN_X86_INTRINSICS %s \
 // RUN:   -fno-discard-value-names -mllvm -disable-llvm-optzns
 
+// RUN: %clang -Xclang -no-opaque-pointers -S -emit-llvm -target powerpc64-ibm-aix -mcpu=pwr8 -ffreestanding -DNO_WARN_X86_INTRINSICS %s \
+// RUN:   -ffp-contract=off -fno-discard-value-names -mllvm -disable-llvm-optzns -o - | llvm-cxxfilt -n | FileCheck %s --check-prefixes=CHECK,CHECK-BE
+// RUN: %clang -Xclang -no-opaque-pointers -x c++ -fsyntax-only -target powerpc64-ibm-aix -mcpu=pwr8 -ffreestanding -DNO_WARN_X86_INTRINSICS %s \
+// RUN:   -fno-discard-value-names -mllvm -disable-llvm-optzns
+// RUN: %clang -Xclang -no-opaque-pointers -S -emit-llvm -target powerpc64-ibm-aix -mcpu=pwr10 -ffreestanding -DNO_WARN_X86_INTRINSICS %s \
+// RUN:   -ffp-contract=off -fno-discard-value-names -mllvm -disable-llvm-optzns -o - | llvm-cxxfilt -n | FileCheck %s --check-prefixes=CHECK,CHECK-P10-BE
+
 #include 
 
 __m128 res, m1, m2;
@@ -388,7 +395,8 @@
 // CHECK-LABEL: define available_externally signext i32 @_mm_cvtss_si32
 // CHECK-LE: %[[VEC:[0-9a-zA-Z_.]+]] = call { <4 x float>, i32, double } asm "xxsldwi ${0:x},${0:x},${0:x},3;\0Axscvspdp ${2:x},${0:x};\0Afctiw  $2,$2;\0Amfvsrd  $1,${2:x};\0A", "=^wa,=r,=f,0"
 // CHECK-BE: %[[VEC:[0-9a-zA-Z_.]+]] = call { <4 x float>, i32, double } asm "xscvspdp ${2:x},${0:x};\0Afctiw  $2,$2;\0Amfvsrd  $1,${2:x};\0A", "=^wa,=r,=f,0"
-// CHECK-P10: %[[VEC:[0-9a-zA-Z_.]+]] = call { <4 x float>, i32, double } asm "xxsldwi ${0:x},${0:x},${0:x},3;\0Axscvspdp ${2:x},${0:x};\0Afctiw  $2,$2;\0Amfvsrd  $1,${2:x};\0A", "=^wa,=r,=f,0"
+// CHECK-P10-LE: %[[VEC:[0-9a-zA-Z_.]+]] = call { <4 x float>, i32, double } asm "xxsldwi ${0:x},${0:x},${0:x},3;\0Axscvspdp ${2:x},${0:x};\0Afctiw  $2,$2;\0Amfvsrd  $1,${2:x};\0A", "=^wa,=r,=f,0"
+// CHECK-P10-BE: %[[VEC:[0-9a-zA-Z_.]+]] = call { <4 x float>, i32, double } asm "xscvspdp ${2:x},${0:x};\0Afctiw  $2,$2;\0Amfvsrd  $1,${2:x};\0A", "=^wa,=r,=f,0"
 // CHECK: extractvalue { <4 x float>, i32, double } %[[VEC]], 0
 // CHECK: extractvalue { <4 x float>, i32, double } %[[VEC]], 1
 // CHECK: extractvalue { <4 x float>, i32, double } %[[VEC]], 2
@@ -688,7 +696,8 @@
 // CHECK-BE: call <2 x i64> @vec_vbpermq(unsigned char vector[16], unsigned char vector[16])(<16 x i8> noundef %{{[0-9a-zA-Z_.]+}}, <16 x i8> noundef bitcast (<4 x i32>  to <16 x i8>))
 // CHECK-BE: %[[EXT:[0-9a-zA-Z_.]+]] = extractelement <2 x i64> %{{[0-9a-zA-Z_.]+}}, i32 0
 // CHECK-BE: trunc i64 %[[EXT]] to i32
-// CHECK-P10: call zeroext i32 @vec_extractm(unsigned int vector[4])(<4 x i32> noundef %{{[0-9a-z

[PATCH] D105255: [MLIR][OpenMP] Added target data, exit data, and enter data operation definition for MLIR.

2022-07-10 Thread Raghu via Phabricator via cfe-commits
raghavendhra added a comment.

@abidmalikwaterloo ninja check-mlir is failing with your most upto date patch. 
Can you please double check?

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105255

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


[PATCH] D129464: [Clang][CodeGen] Set FP options of builder at entry to compound statement

2022-07-10 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff created this revision.
sepavloff added reviewers: kpn, rjmccall, aaron.ballman.
Herald added subscribers: jsji, pengfei.
Herald added a project: All.
sepavloff requested review of this revision.
Herald added a project: clang.

Previously compilation of a few tests produced incorrect code. In them FP
pragmas were ignored and the resulting code contained constrained intrinsics
with rounding mode and/or exception behavior determined by command line
options only. Compiler creates correct AST for this tests, but FP options
were ignored in code generator because builder object was not set up properly.
To fix code generation builder object now is updated according to FP options
stored in CompoundStmt.

This change elucidated an issue in template instantiations, - it occured
with FP options taken from the point of instantiation. The issue is also
fixed.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129464

Files:
  clang/include/clang/AST/Stmt.h
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/CodeGen/X86/avx512dq-builtins-constrained.c
  clang/test/CodeGen/aarch64-v8.2a-neon-intrinsics-constrained.c
  clang/test/CodeGen/complex-strictfp.c
  clang/test/CodeGen/pragma-fenv_access.cpp

Index: clang/test/CodeGen/pragma-fenv_access.cpp
===
--- /dev/null
+++ clang/test/CodeGen/pragma-fenv_access.cpp
@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 -S -triple x86_64-linux-gnu -emit-llvm %s -o - | FileCheck %s
+
+template 
+T templ_01(T a, T b) {
+  return a * b;
+}
+
+#pragma STDC FENV_ACCESS ON
+
+float func_02(float a, float b) {
+  return 1.0f + templ_01(a, b);
+}
+
+// CHECK-LABEL: define {{.*}} @_Z7func_02ff
+// CHECK: call noundef float @_Z8templ_01IfET_S0_S0_
+// CHECK: call float @llvm.experimental.constrained.fadd.f32({{.*}}, metadata !"round.dynamic", metadata !"fpexcept.strict")
+
+// CHECK-LABEL: define {{.*}} @_Z8templ_01IfET_S0_S0_
+// CHECK: fmul float
+
+
+#pragma STDC FENV_ACCESS OFF
+#pragma STDC FENV_ROUND FE_UPWARD
+
+template 
+T templ_03(T a, T b) {
+  return a * b;
+}
+
+#pragma STDC FENV_ACCESS ON
+
+float func_04(float a, float b) {
+  return 1.0f + templ_03(a, b);
+}
+
+
+// CHECK-LABEL: define {{.*}} @_Z7func_04ff
+// CHECK: call noundef float @_Z8templ_03IfET_S0_S0_
+// CHECK: call float @llvm.experimental.constrained.fadd.f32({{.*}}, metadata !"round.upward", metadata !"fpexcept.strict")
+
+// CHECK-LABEL: define {{.*}} @_Z8templ_03IfET_S0_S0_
+// CHECK: call float @llvm.experimental.constrained.fmul.f32({{.*}}, metadata !"round.upward", metadata !"fpexcept.ignore")
Index: clang/test/CodeGen/complex-strictfp.c
===
--- clang/test/CodeGen/complex-strictfp.c
+++ clang/test/CodeGen/complex-strictfp.c
@@ -5,8 +5,6 @@
 // Test that the constrained intrinsics are picking up the exception
 // metadata from the AST instead of the global default from the command line.
 // Include rounding metadata in the testing.
-// FIXME: All cases of "fpexcept.maytrap" in this test are wrong.
-// FIXME: All cases of "round.tonearest" in this test are wrong.
 
 #pragma float_control(except, on)
 #pragma STDC FENV_ROUND FE_UPWARD
@@ -74,7 +72,7 @@
 // CHECK-NEXT:[[G1_REAL:%.*]] = load double, double* getelementptr inbounds ({ double, double }, { double, double }* @g1, i32 0, i32 0), align 8
 // CHECK-NEXT:[[G1_IMAG:%.*]] = load double, double* getelementptr inbounds ({ double, double }, { double, double }* @g1, i32 0, i32 1), align 8
 // CHECK-NEXT:[[TMP0:%.*]] = load double, double* @D, align 8
-// CHECK-NEXT:[[ADD_R:%.*]] = call double @llvm.experimental.constrained.fadd.f64(double [[G1_REAL]], double [[TMP0]], metadata !"round.tonearest", metadata !"fpexcept.maytrap") #[[ATTR2]]
+// CHECK-NEXT:[[ADD_R:%.*]] = call double @llvm.experimental.constrained.fadd.f64(double [[G1_REAL]], double [[TMP0]], metadata !"round.upward", metadata !"fpexcept.strict") #[[ATTR2]]
 // CHECK-NEXT:store double [[ADD_R]], double* getelementptr inbounds ({ double, double }, { double, double }* @g1, i32 0, i32 0), align 8
 // CHECK-NEXT:store double [[G1_IMAG]], double* getelementptr inbounds ({ double, double }, { double, double }* @g1, i32 0, i32 1), align 8
 // CHECK-NEXT:ret void
@@ -88,7 +86,7 @@
 // CHECK-NEXT:[[TMP0:%.*]] = load double, double* @D, align 8
 // CHECK-NEXT:[[G1_REAL:%.*]] = load double, double* getelementptr inbounds ({ double, double }, { double, double }* @g1, i32 0, i32 0), align 8
 // CHECK-NEXT:[[G1_IMAG:%.*]] = load double, double* getelementptr inbounds ({ double, double }, { double, double }* @g1, i32 0, i32 1), align 8
-// CHECK-NEXT:[[ADD_R:%.*]] = call double @llvm.experimental.constrained.fadd.f64(double [[TMP0]], double [[G1_REAL]], metadata !"round.tonearest", metadata !"fpexcept.maytrap") #[[ATTR2]]
+// CHECK-NEXT:[[ADD_R:%.*]] = call double @llvm.experimental.con

[PATCH] D129466: [clang-format][NFC] Replace most of std::vector with SmallVector

2022-07-10 Thread Owen Pan via Phabricator via cfe-commits
owenpan created this revision.
owenpan added reviewers: curdeius, HazardyKnusperkeks, MyDeveloperDay.
owenpan added a project: clang-format.
Herald added a project: All.
owenpan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129466

Files:
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/ContinuationIndenter.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/FormatToken.cpp
  clang/lib/Format/Macros.h
  clang/lib/Format/UnwrappedLineFormatter.cpp


Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -1132,7 +1132,7 @@
   typedef std::pair QueueItem;
 
   /// The BFS queue type.
-  typedef std::priority_queue,
+  typedef std::priority_queue,
   std::greater>
   QueueType;
 
Index: clang/lib/Format/Macros.h
===
--- clang/lib/Format/Macros.h
+++ clang/lib/Format/Macros.h
@@ -130,7 +130,7 @@
   const FormatStyle &Style;
   llvm::SpecificBumpPtrAllocator &Allocator;
   IdentifierTable &IdentTable;
-  std::vector> Buffers;
+  SmallVector> Buffers;
   llvm::StringMap Definitions;
 };
 
Index: clang/lib/Format/FormatToken.cpp
===
--- clang/lib/Format/FormatToken.cpp
+++ clang/lib/Format/FormatToken.cpp
@@ -264,7 +264,7 @@
   // We can never place more than ColumnLimit / 3 items in a row (because of 
the
   // spaces and the comma).
   unsigned MaxItems = Style.ColumnLimit / 3;
-  std::vector MinSizeInColumn;
+  SmallVector MinSizeInColumn;
   MinSizeInColumn.reserve(MaxItems);
   for (unsigned Columns = 1; Columns <= MaxItems; ++Columns) {
 ColumnFormat Format;
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -2386,7 +2386,7 @@
 
   tooling::Replacements generateFixes() {
 tooling::Replacements Fixes;
-std::vector Tokens;
+SmallVector Tokens;
 std::copy(DeletedTokens.begin(), DeletedTokens.end(),
   std::back_inserter(Tokens));
 
@@ -2580,7 +2580,7 @@
   StringRef Identifier;
   StringRef Text;
   unsigned Offset;
-  std::vector AssociatedCommentLines;
+  SmallVector AssociatedCommentLines;
   bool IsStatic;
 };
 
@@ -2983,7 +2983,7 @@
   llvm::Regex ImportRegex(JavaImportRegexPattern);
   SmallVector Matches;
   SmallVector ImportsInBlock;
-  std::vector AssociatedCommentLines;
+  SmallVector AssociatedCommentLines;
 
   bool FormattingOff = false;
 
Index: clang/lib/Format/ContinuationIndenter.h
===
--- clang/lib/Format/ContinuationIndenter.h
+++ clang/lib/Format/ContinuationIndenter.h
@@ -434,7 +434,7 @@
 
   /// A stack keeping track of properties applying to parenthesis
   /// levels.
-  std::vector Stack;
+  SmallVector Stack;
 
   /// Ignore the stack of \c ParenStates for state comparison.
   ///
Index: clang/lib/Format/ContinuationIndenter.cpp
===
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -37,7 +37,7 @@
 // Returns the length of everything up to the first possible line break after
 // the ), ], } or > matching \c Tok.
 static unsigned getLengthToMatchingParen(const FormatToken &Tok,
- const std::vector &Stack) 
{
+ const SmallVector &Stack) 
{
   // Normally whether or not a break before T is possible is calculated and
   // stored in T.CanBreakBefore. Braces, array initializers and text proto
   // messages like `key: < ... >` are an exception: a break is possible


Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -1132,7 +1132,7 @@
   typedef std::pair QueueItem;
 
   /// The BFS queue type.
-  typedef std::priority_queue,
+  typedef std::priority_queue,
   std::greater>
   QueueType;
 
Index: clang/lib/Format/Macros.h
===
--- clang/lib/Format/Macros.h
+++ clang/lib/Format/Macros.h
@@ -130,7 +130,7 @@
   const FormatStyle &Style;
   llvm::SpecificBumpPtrAllocator &Allocator;
   IdentifierTable &IdentTable;
-  std::vector> Buffers;
+  SmallVector> Buffers;
   llvm::StringMap Definitions;
 };
 
Index: clang/lib/Format/FormatToken.cpp
===
--- clang/lib/Format/FormatToken.cpp
+++ clang/lib/Format/FormatToken.cpp
@@ -264,7