[clang] c816be2 - Add release note for aarch64-none-elf driver change.

2022-01-26 Thread Kristof Beyls via cfe-commits

Author: Kristof Beyls
Date: 2022-01-26T09:13:22+01:00
New Revision: c816be2026af3641f9b648482c48dd1f18a73dd1

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

LOG: Add release note for aarch64-none-elf driver change.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2272d7197ac57..6a9b046a1427d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -275,6 +275,9 @@ Arm and AArch64 Support in Clang
   architecture features, but will enable certain optimizations specific to
   Cortex-A57 CPUs and enable the use of a more accurate scheduling model.
 
+- The --aarch64-none-elf target now uses the BareMetal driver rather than the
+  GNU driver. Programs that depend on clang invoking GCC as the linker driver
+  should use GCC as the linker in the build system.
 
 Floating Point Support in Clang
 ---



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


[clang] 72e29ca - [clang-format] Fix regression in parsing pointers to arrays.

2022-01-26 Thread Marek Kurdej via cfe-commits

Author: Marek Kurdej
Date: 2022-01-26T09:27:38+01:00
New Revision: 72e29caf039fd81bc6948e16d6f71d1581615469

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

LOG: [clang-format] Fix regression in parsing pointers to arrays.

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

After commit 5c2e7c9, the code:
```
template <> struct S : Template {};
```
was misformatted as:
```
template <> struct S : Template{};
```

Reviewed By: MyDeveloperDay, HazardyKnusperkeks, owenpan

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

Added: 


Modified: 
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 96d227b7fe763..ff3e791822c47 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -3081,8 +3081,15 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
 if (!tryToParseBracedList())
   break;
   }
-  if (FormatTok->is(tok::l_square) && !tryToParseLambda())
-break;
+  if (FormatTok->is(tok::l_square)) {
+FormatToken *Previous = FormatTok->Previous;
+if (!Previous || Previous->isNot(tok::r_paren)) {
+  // Don't try parsing a lambda if we had a closing parenthesis before,
+  // it was probably a pointer to an array: int (*)[].
+  if (!tryToParseLambda())
+break;
+}
+  }
   if (FormatTok->Tok.is(tok::semi))
 return;
   if (Style.isCSharp() && FormatTok->is(Keywords.kw_where)) {

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index c4e0e14ce5bcd..c45869f16ad29 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -23483,6 +23483,8 @@ TEST_F(FormatTest, EmptyShortBlock) {
 TEST_F(FormatTest, ShortTemplatedArgumentLists) {
   auto Style = getLLVMStyle();
 
+  verifyFormat("template <> struct S : Template {};\n", Style);
+  verifyFormat("template <> struct S : Template {};\n", Style);
   verifyFormat("struct Y : X<[] { return 0; }> {};", Style);
   verifyFormat("struct Y<[] { return 0; }> {};", Style);
 



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


[PATCH] D118106: [clang-format] Fix regression in parsing pointers to arrays.

2022-01-26 Thread Marek Kurdej via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG72e29caf039f: [clang-format] Fix regression in parsing 
pointers to arrays. (authored by curdeius).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118106

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -23483,6 +23483,8 @@
 TEST_F(FormatTest, ShortTemplatedArgumentLists) {
   auto Style = getLLVMStyle();
 
+  verifyFormat("template <> struct S : Template {};\n", Style);
+  verifyFormat("template <> struct S : Template {};\n", Style);
   verifyFormat("struct Y : X<[] { return 0; }> {};", Style);
   verifyFormat("struct Y<[] { return 0; }> {};", Style);
 
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -3081,8 +3081,15 @@
 if (!tryToParseBracedList())
   break;
   }
-  if (FormatTok->is(tok::l_square) && !tryToParseLambda())
-break;
+  if (FormatTok->is(tok::l_square)) {
+FormatToken *Previous = FormatTok->Previous;
+if (!Previous || Previous->isNot(tok::r_paren)) {
+  // Don't try parsing a lambda if we had a closing parenthesis before,
+  // it was probably a pointer to an array: int (*)[].
+  if (!tryToParseLambda())
+break;
+}
+  }
   if (FormatTok->Tok.is(tok::semi))
 return;
   if (Style.isCSharp() && FormatTok->is(Keywords.kw_where)) {


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -23483,6 +23483,8 @@
 TEST_F(FormatTest, ShortTemplatedArgumentLists) {
   auto Style = getLLVMStyle();
 
+  verifyFormat("template <> struct S : Template {};\n", Style);
+  verifyFormat("template <> struct S : Template {};\n", Style);
   verifyFormat("struct Y : X<[] { return 0; }> {};", Style);
   verifyFormat("struct Y<[] { return 0; }> {};", Style);
 
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -3081,8 +3081,15 @@
 if (!tryToParseBracedList())
   break;
   }
-  if (FormatTok->is(tok::l_square) && !tryToParseLambda())
-break;
+  if (FormatTok->is(tok::l_square)) {
+FormatToken *Previous = FormatTok->Previous;
+if (!Previous || Previous->isNot(tok::r_paren)) {
+  // Don't try parsing a lambda if we had a closing parenthesis before,
+  // it was probably a pointer to an array: int (*)[].
+  if (!tryToParseLambda())
+break;
+}
+  }
   if (FormatTok->Tok.is(tok::semi))
 return;
   if (Style.isCSharp() && FormatTok->is(Keywords.kw_where)) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D117056: [clangd] Properly compute framework-style include spelling

2022-01-26 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

Thanks! LG with a couple of optional nits.
Cut should be on 2022-02-01 or thereabouts, best to land after that if it's not 
a problem.




Comment at: clang-tools-extra/clangd/index/SymbolCollector.cpp:315
+}
+llvm::vfs::Status Status;
+bool IsSystem = isSystem(HeadersDirKind);

nit: move next to first use



Comment at: clang-tools-extra/clangd/index/SymbolCollector.cpp:320
+
+auto StatErr = HS.getFileMgr().getNoncachedStatValue(UmbrellaPath, Status);
+if (!StatErr) {

now that we're filling in a couple of fields for a whole cache entry, probably 
worth pulling out a function just for that. That will also naturally eliminate 
the duplicate returns here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117056

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


[PATCH] D118220: [clang-format] Correctly format lambdas with variadic template parameters.

2022-01-26 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius created this revision.
curdeius added reviewers: MyDeveloperDay, HazardyKnusperkeks, owenpan.
curdeius requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118220

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -20560,6 +20560,36 @@
   // Lambdas with explicit template argument lists.
   verifyFormat(
   "auto L = [] class T, class U>(T &&a) {};\n");
+  verifyFormat("auto L = [](T) {\n"
+   "  {\n"
+   "f();\n"
+   "g();\n"
+   "  }\n"
+   "};\n");
+  verifyFormat("auto L = [](T...) {\n"
+   "  {\n"
+   "f();\n"
+   "g();\n"
+   "  }\n"
+   "};\n");
+  verifyFormat("auto L = [](T...) {\n"
+   "  {\n"
+   "f();\n"
+   "g();\n"
+   "  }\n"
+   "};\n");
+  verifyFormat("auto L = [] class T>(T...) {\n"
+   "  {\n"
+   "f();\n"
+   "g();\n"
+   "  }\n"
+   "};\n");
+  verifyFormat("auto L = [](T...) {\n"
+   "  {\n"
+   "f();\n"
+   "g();\n"
+   "  }\n"
+   "};\n");
 
   // Multiple lambdas in the same parentheses change indentation rules. These
   // lambdas are forced to start on new lines.
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1856,6 +1856,7 @@
 return false;
 
   bool SeenArrow = false;
+  bool InTemplateParameterList = false;
 
   while (FormatTok->isNot(tok::l_brace)) {
 if (FormatTok->isSimpleTypeSpecifier()) {
@@ -1871,6 +1872,14 @@
 case tok::l_square:
   parseSquare();
   break;
+case tok::kw_class:
+case tok::kw_template:
+case tok::kw_typename:
+  assert(FormatTok->Previous);
+  if (FormatTok->Previous->is(tok::less))
+InTemplateParameterList = true;
+  nextToken();
+  break;
 case tok::amp:
 case tok::star:
 case tok::kw_const:
@@ -1880,11 +1889,8 @@
 case tok::identifier:
 case tok::numeric_constant:
 case tok::coloncolon:
-case tok::kw_class:
 case tok::kw_mutable:
 case tok::kw_noexcept:
-case tok::kw_template:
-case tok::kw_typename:
   nextToken();
   break;
 // Specialization of a template with an integer parameter can contain
@@ -1921,7 +1927,7 @@
 case tok::ellipsis:
 case tok::kw_true:
 case tok::kw_false:
-  if (SeenArrow) {
+  if (SeenArrow || InTemplateParameterList) {
 nextToken();
 break;
   }


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -20560,6 +20560,36 @@
   // Lambdas with explicit template argument lists.
   verifyFormat(
   "auto L = [] class T, class U>(T &&a) {};\n");
+  verifyFormat("auto L = [](T) {\n"
+   "  {\n"
+   "f();\n"
+   "g();\n"
+   "  }\n"
+   "};\n");
+  verifyFormat("auto L = [](T...) {\n"
+   "  {\n"
+   "f();\n"
+   "g();\n"
+   "  }\n"
+   "};\n");
+  verifyFormat("auto L = [](T...) {\n"
+   "  {\n"
+   "f();\n"
+   "g();\n"
+   "  }\n"
+   "};\n");
+  verifyFormat("auto L = [] class T>(T...) {\n"
+   "  {\n"
+   "f();\n"
+   "g();\n"
+   "  }\n"
+   "};\n");
+  verifyFormat("auto L = [](T...) {\n"
+   "  {\n"
+   "f();\n"
+   "g();\n"
+   "  }\n"
+   "};\n");
 
   // Multiple lambdas in the same parentheses change indentation rules. These
   // lambdas are forced to start on new lines.
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1856,6 +1856,7 @@
 return false;
 
   bool SeenArrow = false;
+  bool InTemplateParameterList = false;
 
   while (FormatTok->isNot(tok::l_brace)) {
 if (FormatTok->isSimpleTypeSpecifier()) {
@@ -1871,6 +1872,14 @@
 case tok::l_square:
   parseSquare();
   break;
+case tok::k

[PATCH] D118220: [clang-format] Correctly format lambdas with variadic template parameters.

2022-01-26 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay accepted this revision.
MyDeveloperDay added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118220

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


[PATCH] D118223: [NFC] [AST] Move isSame* check in ASTReader to ASTContext

2022-01-26 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu created this revision.
ChuanqiXu added reviewers: rsmith, aaron.ballman, urnathan, erichkeane.
ChuanqiXu added a project: clang.
ChuanqiXu requested review of this revision.
Herald added a subscriber: cfe-commits.

Currently we are trying to implement the semantics of C++ Modules. A big 
challenge would be the ODR checking. Previously we did this in ASTReader, it 
would handle the case for something like:

  C++
  module;
  #include "something"
  export module a_module;
  import another_module; //  check the ODR consistency here

or

  C++
  export module m;
  import a_module;
  import another_module; // check the ODR consistency here

However, it wouldn't handle the case:

  import another_module; // check ODR here, everything looks fine.
  #include "something" // Oops, we don't check for ODR now

In the case, the read process is ended. But we need to check the ODR still. To 
reuse the facility we do in ASTReader, this patch moves the corresponding codes 
into ASTContext. This should be good since there were facilities like 
`hasSameTemplateName` and `hasSameType`.

Although the patch is a little bit big, all of the change should be trivial.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118223

Files:
  clang/include/clang/AST/ASTContext.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp

Index: clang/lib/Serialization/ASTReaderDecl.cpp
===
--- clang/lib/Serialization/ASTReaderDecl.cpp
+++ clang/lib/Serialization/ASTReaderDecl.cpp
@@ -2945,391 +2945,6 @@
   return LocalOffset + M.GlobalBitOffset;
 }
 
-static bool isSameTemplateParameterList(const ASTContext &C,
-const TemplateParameterList *X,
-const TemplateParameterList *Y);
-static bool isSameEntity(NamedDecl *X, NamedDecl *Y);
-
-/// Determine whether two template parameters are similar enough
-/// that they may be used in declarations of the same template.
-static bool isSameTemplateParameter(const NamedDecl *X,
-const NamedDecl *Y) {
-  if (X->getKind() != Y->getKind())
-return false;
-
-  if (const auto *TX = dyn_cast(X)) {
-const auto *TY = cast(Y);
-if (TX->isParameterPack() != TY->isParameterPack())
-  return false;
-if (TX->hasTypeConstraint() != TY->hasTypeConstraint())
-  return false;
-const TypeConstraint *TXTC = TX->getTypeConstraint();
-const TypeConstraint *TYTC = TY->getTypeConstraint();
-if (!TXTC != !TYTC)
-  return false;
-if (TXTC && TYTC) {
-  auto *NCX = TXTC->getNamedConcept();
-  auto *NCY = TYTC->getNamedConcept();
-  if (!NCX || !NCY || !isSameEntity(NCX, NCY))
-return false;
-  if (TXTC->hasExplicitTemplateArgs() != TYTC->hasExplicitTemplateArgs())
-return false;
-  if (TXTC->hasExplicitTemplateArgs()) {
-const auto *TXTCArgs = TXTC->getTemplateArgsAsWritten();
-const auto *TYTCArgs = TYTC->getTemplateArgsAsWritten();
-if (TXTCArgs->NumTemplateArgs != TYTCArgs->NumTemplateArgs)
-  return false;
-llvm::FoldingSetNodeID XID, YID;
-for (const auto &ArgLoc : TXTCArgs->arguments())
-  ArgLoc.getArgument().Profile(XID, X->getASTContext());
-for (const auto &ArgLoc : TYTCArgs->arguments())
-  ArgLoc.getArgument().Profile(YID, Y->getASTContext());
-if (XID != YID)
-  return false;
-  }
-}
-return true;
-  }
-
-  if (const auto *TX = dyn_cast(X)) {
-const auto *TY = cast(Y);
-return TX->isParameterPack() == TY->isParameterPack() &&
-   TX->getASTContext().hasSameType(TX->getType(), TY->getType());
-  }
-
-  const auto *TX = cast(X);
-  const auto *TY = cast(Y);
-  return TX->isParameterPack() == TY->isParameterPack() &&
- isSameTemplateParameterList(TX->getASTContext(),
- TX->getTemplateParameters(),
- TY->getTemplateParameters());
-}
-
-static NamespaceDecl *getNamespace(const NestedNameSpecifier *X) {
-  if (auto *NS = X->getAsNamespace())
-return NS;
-  if (auto *NAS = X->getAsNamespaceAlias())
-return NAS->getNamespace();
-  return nullptr;
-}
-
-static bool isSameQualifier(const NestedNameSpecifier *X,
-const NestedNameSpecifier *Y) {
-  if (auto *NSX = getNamespace(X)) {
-auto *NSY = getNamespace(Y);
-if (!NSY || NSX->getCanonicalDecl() != NSY->getCanonicalDecl())
-  return false;
-  } else if (X->getKind() != Y->getKind())
-return false;
-
-  // FIXME: For namespaces and types, we're permitted to check that the entity
-  // is named via the same tokens. We should probably do so.
-  switch (X->getKind()) {
-  case NestedNameSpecifier::Identifier:
-if (X->getAsIdentifier() != Y->getAsIdentifier())
-  return false;
-break;
-  case NestedNameSpecifier::Namespace:
-

[PATCH] D118034: [C++20] [Modules] Don't complain about duplicated default template argument across modules

2022-01-26 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu planned changes to this revision.
ChuanqiXu added inline comments.



Comment at: clang/lib/Sema/SemaTemplate.cpp:2852
 
-if (RedundantDefaultArg) {
+if (RedundantDefaultArg && !IsOldParamFromModule) {
   // C++ [temp.param]p12:

urnathan wrote:
> Yes, I think this is a better place for the comment.  If there are duplicates 
> we need to check they are the same -- pedantically the same tokens, but at 
> least AST equivalence?
Yeah, it should be necessary to check the ODR. I found it is not trivial to do 
so. It needs more work. I sent https://reviews.llvm.org/D118223 as a forward 
patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118034

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


[PATCH] D118224: [clang-tidy] bugprone-signal-handler improvements: display call chain

2022-01-26 Thread Balázs Kéri via Phabricator via cfe-commits
balazske created this revision.
Herald added subscribers: carlosgalvezp, steakhal, martong, gamesh411, 
Szelethus, dkrupp, xazax.hun.
balazske requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Display notes for a possible call chain if an unsafe function is found to be
called (maybe indirectly) from a signal handler.
The call chain displayed this way includes probably not the first calls of
the functions, but it is a valid possible (in non path-sensitive way) one.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118224

Files:
  clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.h
  clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler.c

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler.c
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler.c
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler.c
@@ -13,62 +13,121 @@
 typedef void (*sighandler_t)(int);
 sighandler_t signal(int signum, sighandler_t handler);
 
-void handler_abort(int) {
-  abort();
-}
+void f_extern();
 
-void handler_other(int) {
+void handler_printf(int) {
   printf("1234");
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'printf' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
+  // CHECK-NOTES: :[[@LINE-1]]:3: warning: 'printf' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
+  // CHECK-NOTES: :[[@LINE-2]]:3: note: function 'printf' called here from 'handler_printf'
+  // CHECK-NOTES: :[[@LINE+4]]:18: note: function 'handler_printf' registered here as signal handler
 }
 
-void handler_signal(int) {
-  // FIXME: It is only OK to call signal with the current signal number.
-  signal(0, SIG_DFL);
+void test_printf() {
+  signal(SIGINT, handler_printf);
 }
 
-void f_ok() {
-  abort();
+void handler_extern(int) {
+  f_extern();
+  // CHECK-NOTES: :[[@LINE-1]]:3: warning: 'f_extern' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
+  // CHECK-NOTES: :[[@LINE-2]]:3: note: function 'f_extern' called here from 'handler_extern'
+  // CHECK-NOTES: :[[@LINE+4]]:18: note: function 'handler_extern' registered here as signal handler
 }
 
-void f_bad() {
-  printf("1234");
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'printf' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
+void test_extern() {
+  signal(SIGINT, handler_extern);
 }
 
-void f_extern();
+void f_ok() {
+  abort();
+}
 
 void handler_ok(int) {
   f_ok();
 }
 
+void test_ok() {
+  signal(SIGINT, handler_ok);
+}
+
+void f_bad() {
+  printf("1234");
+  // CHECK-NOTES: :[[@LINE-1]]:3: warning: 'printf' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
+  // CHECK-NOTES: :[[@LINE-2]]:3: note: function 'printf' called here from 'f_bad'
+  // CHECK-NOTES: :[[@LINE+5]]:3: note: function 'f_bad' called here from 'handler_bad'
+  // CHECK-NOTES: :[[@LINE+8]]:18: note: function 'handler_bad' registered here as signal handler
+}
+
 void handler_bad(int) {
   f_bad();
 }
 
-void handler_extern(int) {
-  f_extern();
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'f_extern' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
+void test_bad() {
+  signal(SIGINT, handler_bad);
+}
+
+void f_bad1() {
+  printf("1234");
+  // CHECK-NOTES: :[[@LINE-1]]:3: warning: 'printf' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
+  // CHECK-NOTES: :[[@LINE-2]]:3: note: function 'printf' called here from 'f_bad1'
+  // CHECK-NOTES: :[[@LINE+6]]:3: note: function 'f_bad1' called here from 'f_bad2'
+  // CHECK-NOTES: :[[@LINE+9]]:3: note: function 'f_bad2' called here from 'handler_bad1'
+  // CHECK-NOTES: :[[@LINE+13]]:18: note: function 'handler_bad1' registered here as signal handler
+}
+
+void f_bad2() {
+  f_bad1();
+}
+
+void handler_bad1(int) {
+  f_bad2();
+  f_bad1();
+}
+
+void test_bad1() {
+  signal(SIGINT, handler_bad1);
+}
+
+void handler_abort(int) {
+  abort();
+}
+
+void handler_signal(int) {
+  // FIXME: It is only OK to call signal with the current signal number.
+  signal(0, SIG_DFL);
 }
 
-void test_false_condition(int) {
+void handler_false_condition(int) {
   if (0)
 printf("1234");
-  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'printf' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
+  // CHECK-NOTES: :[[@LINE-1]]:5: warning: 'printf' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
+  // CHECK-N

[PATCH] D118225: [RISCV] Decouple Zve* extensions.

2022-01-26 Thread Jianjian Guan via Phabricator via cfe-commits
jacquesguan created this revision.
jacquesguan added reviewers: craig.topper, eopXD, asb, luismarques, 
frasercrmck, HsiangKai, khchen, benshi001.
Herald added subscribers: VincentWu, luke957, achieveartificialintelligence, 
vkmr, evandro, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, 
PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, 
kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, hiraditya.
jacquesguan requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, pcwang-thead, MaskRay.
Herald added projects: clang, LLVM.

According to the v spec, there is no include relationship or dependency among 
the Zve* extensions. For exmaple, we do not need to implement Zve64x for 
Zve64f, these two are indepedent extensions. This patch decouple all Zve* 
extensions.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118225

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  clang/test/CodeGen/RISCV/rvv-intrinsics/rvv-error.c
  clang/test/Preprocessor/riscv-target-features.c
  clang/utils/TableGen/RISCVVEmitter.cpp
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  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
@@ -76,16 +76,16 @@
 # CHECK: attribute  5, "rv32i2p0_zve32x1p0_zvl32b1p0"
 
 .attribute arch, "rv32ifzve32f"
-# CHECK: attribute  5, "rv32i2p0_f2p0_zve32f1p0_zve32x1p0_zvl32b1p0"
+# CHECK: attribute  5, "rv32i2p0_f2p0_zve32f1p0_zvl32b1p0"
 
 .attribute arch, "rv32izve64x"
-# CHECK: attribute  5, "rv32i2p0_zve32x1p0_zve64x1p0_zvl32b1p0_zvl64b1p0"
+# CHECK: attribute  5, "rv32i2p0_zve64x1p0_zvl32b1p0_zvl64b1p0"
 
 .attribute arch, "rv32ifzve64f"
-# CHECK: attribute  5, "rv32i2p0_f2p0_zve32f1p0_zve32x1p0_zve64f1p0_zve64x1p0_zvl32b1p0_zvl64b1p0"
+# CHECK: attribute  5, "rv32i2p0_f2p0_zve64f1p0_zvl32b1p0_zvl64b1p0"
 
 .attribute arch, "rv32ifdzve64d"
-# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_zve32f1p0_zve32x1p0_zve64d1p0_zve64f1p0_zve64x1p0_zvl32b1p0_zvl64b1p0"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_zve64d1p0_zvl32b1p0_zvl64b1p0"
 
 ## Experimental extensions require version string to be explicitly specified
 
Index: llvm/lib/Target/RISCV/RISCVSubtarget.h
===
--- llvm/lib/Target/RISCV/RISCVSubtarget.h
+++ llvm/lib/Target/RISCV/RISCVSubtarget.h
@@ -202,18 +202,29 @@
   }
 
   // Vector codegen related methods.
-  bool hasVInstructions() const { return HasStdExtV || HasStdExtZve32x; }
-  bool hasVInstructionsI64() const { return HasStdExtV || HasStdExtZve64x; }
+  bool hasZve() const {
+return HasStdExtZve32x || HasStdExtZve32f || HasStdExtZve64x ||
+   HasStdExtZve64f || HasStdExtZve64d;
+  }
+  bool hasZve64() const {
+return HasStdExtZve64x || HasStdExtZve64f || HasStdExtZve64d;
+  }
+  bool hasZvef() const {
+return HasStdExtZve32f || HasStdExtZve64f || HasStdExtZve64d;
+  }
+  bool hasZved() const { return HasStdExtZve64d; }
+  bool hasVInstructions() const { return HasStdExtV || hasZve(); }
+  bool hasVInstructionsI64() const { return HasStdExtV || hasZve64(); }
   bool hasVInstructionsF16() const {
-return (HasStdExtV || HasStdExtZve32f) && HasStdExtZfh;
+return HasStdExtZfh && (HasStdExtV || hasZvef());
   }
   // FIXME: Consider Zfinx in the future
   bool hasVInstructionsF32() const {
-return HasStdExtV || (HasStdExtZve32f && HasStdExtF);
+return HasStdExtV || (hasZvef() && HasStdExtF);
   }
   // FIXME: Consider Zdinx in the future
   bool hasVInstructionsF64() const {
-return HasStdExtV || (HasStdExtZve64d && HasStdExtD);
+return HasStdExtV || (hasZved() && HasStdExtD);
   }
   // F16 and F64 both require F32.
   bool hasVInstructionsAnyF() const { return hasVInstructionsF32(); }
Index: llvm/lib/Target/RISCV/RISCV.td
===
--- llvm/lib/Target/RISCV/RISCV.td
+++ llvm/lib/Target/RISCV/RISCV.td
@@ -299,24 +299,24 @@
 : SubtargetFeature<"zve32f", "HasStdExtZve32f", "true",
"'Zve32f' (Vector Extensions for Embedded Processors "
"with maximal 32 EEW and F extension)",
-   [FeatureStdExtZve32x]>;
+   [FeatureStdExtZvl32b]>;
 
 def FeatureStdExtZve64x
 : SubtargetFeature<"zve64x", "HasStdExtZve64x", "true",
"'Zve64x' (Vector Extensions for Embedded Processors "
-   "with maximal 64 EEW)", [FeatureStdExtZve32x, FeatureStdExtZvl64b]>;
+   "with maximal 64 EEW)", [FeatureStdExtZvl64b]>;
 
 def FeatureStdExtZve64f
 : SubtargetFeature<"zve64f", "HasStdExtZve64f", "true",
"'Zve64f' (Vector E

[PATCH] D118226: [clang][dataflow] Assign aggregate storage locations to union stmts

2022-01-26 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev created this revision.
sgatev added reviewers: ymandel, xazax.hun, gribozavr2.
Herald added subscribers: tschuett, steakhal, rnkovacs.
sgatev requested review of this revision.
Herald added a project: clang.

This patch ensures that the dataflow analysis framework does not crash
when it encounters access to members of union types.

This is part of the implementation of the dataflow analysis framework.
See "[RFC] A dataflow analysis framework for Clang AST" on cfe-dev.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118226

Files:
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp


Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -1952,4 +1952,37 @@
   }
 }
 
+TEST_F(TransferTest, AssignToUnionMember) {
+  std::string Code = R"(
+union A {
+  int Foo;
+};
+
+void target(int Bar) {
+  A Baz;
+  Baz.Foo = Bar;
+  // [[p]]
+}
+  )";
+  runDataflow(Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
+
+const ValueDecl *BazDecl = findValueDecl(ASTCtx, "Baz");
+ASSERT_THAT(BazDecl, NotNull());
+ASSERT_TRUE(BazDecl->getType()->isUnionType());
+
+const auto *BazLoc = 
dyn_cast_or_null(
+Env.getStorageLocation(*BazDecl, SkipPast::None));
+ASSERT_THAT(BazLoc, NotNull());
+
+// FIXME: Add support for union types.
+EXPECT_THAT(Env.getValue(*BazLoc), IsNull());
+  });
+}
+
 } // namespace
Index: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -100,7 +100,7 @@
 
 StorageLocation &Environment::createStorageLocation(QualType Type) {
   assert(!Type.isNull());
-  if (Type->isStructureOrClassType()) {
+  if (Type->isStructureOrClassType() || Type->isUnionType()) {
 // FIXME: Explore options to avoid eager initialization of fields as some 
of
 // them might not be needed for a particular analysis.
 llvm::DenseMap FieldLocs;


Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -1952,4 +1952,37 @@
   }
 }
 
+TEST_F(TransferTest, AssignToUnionMember) {
+  std::string Code = R"(
+union A {
+  int Foo;
+};
+
+void target(int Bar) {
+  A Baz;
+  Baz.Foo = Bar;
+  // [[p]]
+}
+  )";
+  runDataflow(Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
+
+const ValueDecl *BazDecl = findValueDecl(ASTCtx, "Baz");
+ASSERT_THAT(BazDecl, NotNull());
+ASSERT_TRUE(BazDecl->getType()->isUnionType());
+
+const auto *BazLoc = dyn_cast_or_null(
+Env.getStorageLocation(*BazDecl, SkipPast::None));
+ASSERT_THAT(BazLoc, NotNull());
+
+// FIXME: Add support for union types.
+EXPECT_THAT(Env.getValue(*BazLoc), IsNull());
+  });
+}
+
 } // namespace
Index: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -100,7 +100,7 @@
 
 StorageLocation &Environment::createStorageLocation(QualType Type) {
   assert(!Type.isNull());
-  if (Type->isStructureOrClassType()) {
+  if (Type->isStructureOrClassType() || Type->isUnionType()) {
 // FIXME: Explore options to avoid eager initialization of fields as some of
 // them might not be needed for a particular analysis.
 llvm::DenseMap FieldLocs;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D118211: Add missing namespace to PPCLinux.cpp

2022-01-26 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai accepted this revision.
nemanjai added a comment.
This revision is now accepted and ready to land.

LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118211

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


[clang] 600c671 - [clang][syntax] Replace `std::vector` use

2022-01-26 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2022-01-26T11:20:18+01:00
New Revision: 600c6714ac77915b7b656b860cf71494a7c9ec7f

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

LOG: [clang][syntax] Replace `std::vector` use

LLVM Programmer’s Manual strongly discourages the use of `std::vector` 
and suggests `llvm::BitVector` as a possible replacement.

This patch replaces `std::vector` with `llvm::BitVector` in the Syntax 
library and replaces range-based for loop with regular for loop. This is 
necessary due to `llvm::BitVector` not having `begin()` and `end()` (D117116).

Reviewed By: dexonsmith, dblaikie

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

Added: 


Modified: 
clang/lib/Tooling/Syntax/Tree.cpp

Removed: 




diff  --git a/clang/lib/Tooling/Syntax/Tree.cpp 
b/clang/lib/Tooling/Syntax/Tree.cpp
index c813865e95cd8..981bac508f733 100644
--- a/clang/lib/Tooling/Syntax/Tree.cpp
+++ b/clang/lib/Tooling/Syntax/Tree.cpp
@@ -9,6 +9,7 @@
 #include "clang/Basic/TokenKinds.h"
 #include "clang/Tooling/Syntax/Nodes.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/BitVector.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/Casting.h"
 #include 
@@ -202,7 +203,7 @@ static void dumpLeaf(raw_ostream &OS, const syntax::Leaf *L,
 }
 
 static void dumpNode(raw_ostream &OS, const syntax::Node *N,
- const SourceManager &SM, std::vector IndentMask) {
+ const SourceManager &SM, llvm::BitVector IndentMask) {
   auto DumpExtraInfo = [&OS](const syntax::Node *N) {
 if (N->getRole() != syntax::NodeRole::Unknown)
   OS << " " << N->getRole();
@@ -228,8 +229,8 @@ static void dumpNode(raw_ostream &OS, const syntax::Node *N,
   OS << "\n";
 
   for (const syntax::Node &It : T->getChildren()) {
-for (bool Filled : IndentMask) {
-  if (Filled)
+for (unsigned Idx = 0; Idx < IndentMask.size(); ++Idx) {
+  if (IndentMask[Idx])
 OS << "| ";
   else
 OS << "  ";



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


[PATCH] D118109: [clang][syntax] Replace `std::vector` use

2022-01-26 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG600c6714ac77: [clang][syntax] Replace 
`std::vector` use (authored by jansvoboda11).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118109

Files:
  clang/lib/Tooling/Syntax/Tree.cpp


Index: clang/lib/Tooling/Syntax/Tree.cpp
===
--- clang/lib/Tooling/Syntax/Tree.cpp
+++ clang/lib/Tooling/Syntax/Tree.cpp
@@ -9,6 +9,7 @@
 #include "clang/Basic/TokenKinds.h"
 #include "clang/Tooling/Syntax/Nodes.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/BitVector.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/Casting.h"
 #include 
@@ -202,7 +203,7 @@
 }
 
 static void dumpNode(raw_ostream &OS, const syntax::Node *N,
- const SourceManager &SM, std::vector IndentMask) {
+ const SourceManager &SM, llvm::BitVector IndentMask) {
   auto DumpExtraInfo = [&OS](const syntax::Node *N) {
 if (N->getRole() != syntax::NodeRole::Unknown)
   OS << " " << N->getRole();
@@ -228,8 +229,8 @@
   OS << "\n";
 
   for (const syntax::Node &It : T->getChildren()) {
-for (bool Filled : IndentMask) {
-  if (Filled)
+for (unsigned Idx = 0; Idx < IndentMask.size(); ++Idx) {
+  if (IndentMask[Idx])
 OS << "| ";
   else
 OS << "  ";


Index: clang/lib/Tooling/Syntax/Tree.cpp
===
--- clang/lib/Tooling/Syntax/Tree.cpp
+++ clang/lib/Tooling/Syntax/Tree.cpp
@@ -9,6 +9,7 @@
 #include "clang/Basic/TokenKinds.h"
 #include "clang/Tooling/Syntax/Nodes.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/BitVector.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/Casting.h"
 #include 
@@ -202,7 +203,7 @@
 }
 
 static void dumpNode(raw_ostream &OS, const syntax::Node *N,
- const SourceManager &SM, std::vector IndentMask) {
+ const SourceManager &SM, llvm::BitVector IndentMask) {
   auto DumpExtraInfo = [&OS](const syntax::Node *N) {
 if (N->getRole() != syntax::NodeRole::Unknown)
   OS << " " << N->getRole();
@@ -228,8 +229,8 @@
   OS << "\n";
 
   for (const syntax::Node &It : T->getChildren()) {
-for (bool Filled : IndentMask) {
-  if (Filled)
+for (unsigned Idx = 0; Idx < IndentMask.size(); ++Idx) {
+  if (IndentMask[Idx])
 OS << "| ";
   else
 OS << "  ";
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 76cb4cd - [clang] Fix serialized diagnostics edge-cases

2022-01-26 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2022-01-26T11:21:51+01:00
New Revision: 76cb4cd074a6816f3801fd4a2bd8854597748239

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

LOG: [clang] Fix serialized diagnostics edge-cases

The Clang frontend sometimes fails on the following assertion when launched 
with `-serialize-diagnostic-file `:

```
Assertion failed: (BlockScope.empty() && CurAbbrevs.empty() && "Block 
imbalance"), function ~BitstreamWriter, file BitstreamWriter.h, line 125.
```

This was first noticed when passing an unknown command-line argument to `-cc1`.

It turns out the `DiagnosticConsumer::finish()` function should be called as 
soon as processing of all source files ends, but there are some code paths 
where that doesn't happen:

1. when command line parsing fails in `cc1_main()`,
2. when `!Act.PrepareToExecute(*this)` or `!createTarget()` evaluate to `true` 
in `CompilerInstance::ExecuteAction` and the function returns early.

This patch ensures `finish()` is called in all those code paths.

Reviewed By: Bigcheese

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

Added: 
clang/test/Misc/serialized-diags-emit-header-module-misconfig.c
clang/test/Misc/serialized-diags-unknown-argument.c
clang/test/Misc/serialized-diags-unknown-target.c

Modified: 
clang/lib/Frontend/CompilerInstance.cpp
clang/tools/driver/cc1_main.cpp

Removed: 




diff  --git a/clang/lib/Frontend/CompilerInstance.cpp 
b/clang/lib/Frontend/CompilerInstance.cpp
index 4ef5094931329..2465a7e2453be 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -37,6 +37,7 @@
 #include "clang/Serialization/ASTReader.h"
 #include "clang/Serialization/GlobalModuleIndex.h"
 #include "clang/Serialization/InMemoryModuleCache.h"
+#include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Support/BuryPointer.h"
 #include "llvm/Support/CrashRecoveryContext.h"
@@ -996,6 +997,11 @@ bool CompilerInstance::ExecuteAction(FrontendAction &Act) {
   // DesiredStackSpace available.
   noteBottomOfStack();
 
+  auto FinishDiagnosticClient = llvm::make_scope_exit([&]() {
+// Notify the diagnostic client that all files were processed.
+getDiagnosticClient().finish();
+  });
+
   raw_ostream &OS = getVerboseOutputStream();
 
   if (!Act.PrepareToExecute(*this))
@@ -1034,9 +1040,6 @@ bool CompilerInstance::ExecuteAction(FrontendAction &Act) 
{
 }
   }
 
-  // Notify the diagnostic client that all files were processed.
-  getDiagnostics().getClient()->finish();
-
   if (getDiagnosticOpts().ShowCarets) {
 // We can have multiple diagnostics sharing one diagnostic client.
 // Get the total number of warnings/errors from the client.

diff  --git a/clang/test/Misc/serialized-diags-emit-header-module-misconfig.c 
b/clang/test/Misc/serialized-diags-emit-header-module-misconfig.c
new file mode 100644
index 0..8629f293b18b9
--- /dev/null
+++ b/clang/test/Misc/serialized-diags-emit-header-module-misconfig.c
@@ -0,0 +1,4 @@
+// RUN: rm -rf %t && mkdir %t
+// RUN: not %clang_cc1 -emit-header-module %s -o %t/out.pcm 
-serialize-diagnostic-file %t/diag 2>&1 | FileCheck %s
+
+// CHECK: error: header module compilation requires '-fmodules', '-std=c++20', 
or '-fmodules-ts'

diff  --git a/clang/test/Misc/serialized-diags-unknown-argument.c 
b/clang/test/Misc/serialized-diags-unknown-argument.c
new file mode 100644
index 0..7d788e11a51b1
--- /dev/null
+++ b/clang/test/Misc/serialized-diags-unknown-argument.c
@@ -0,0 +1,4 @@
+// RUN: rm -rf %t && mkdir %t
+// RUN: not %clang_cc1 %s -unknown-argument -serialize-diagnostic-file %t/diag 
-o /dev/null 2>&1 | FileCheck %s
+
+// CHECK: error: unknown argument: '-unknown-argument'

diff  --git a/clang/test/Misc/serialized-diags-unknown-target.c 
b/clang/test/Misc/serialized-diags-unknown-target.c
new file mode 100644
index 0..040dfa4b2849e
--- /dev/null
+++ b/clang/test/Misc/serialized-diags-unknown-target.c
@@ -0,0 +1,4 @@
+// RUN: rm -rf %t && mkdir %t
+// RUN: not %clang_cc1 %s -triple blah-unknown-unknown 
-serialize-diagnostic-file %t/diag -o /dev/null 2>&1 | FileCheck %s
+
+// CHECK: error: unknown target triple 'blah-unknown-unknown', please use 
-triple or -arch

diff  --git a/clang/tools/driver/cc1_main.cpp b/clang/tools/driver/cc1_main.cpp
index fd3b25ccb3cb1..f648adeba4834 100644
--- a/clang/tools/driver/cc1_main.cpp
+++ b/clang/tools/driver/cc1_main.cpp
@@ -237,8 +237,10 @@ int cc1_main(ArrayRef Argv, const char 
*Argv0, void *MainAddr) {
   
static_cast(&Clang->getDiagnostics()));
 
   DiagsBuffer->FlushDiagnostics(Clang->getDiagnostics());
-  if (!Success)
+  if (!Success) {
+Clang->getDiagnosticClient().finish();
 return 1;

[PATCH] D118150: [clang] Fix serialized diagnostics edge-cases

2022-01-26 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG76cb4cd074a6: [clang] Fix serialized diagnostics edge-cases 
(authored by jansvoboda11).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118150

Files:
  clang/lib/Frontend/CompilerInstance.cpp
  clang/test/Misc/serialized-diags-emit-header-module-misconfig.c
  clang/test/Misc/serialized-diags-unknown-argument.c
  clang/test/Misc/serialized-diags-unknown-target.c
  clang/tools/driver/cc1_main.cpp


Index: clang/tools/driver/cc1_main.cpp
===
--- clang/tools/driver/cc1_main.cpp
+++ clang/tools/driver/cc1_main.cpp
@@ -237,8 +237,10 @@
   
static_cast(&Clang->getDiagnostics()));
 
   DiagsBuffer->FlushDiagnostics(Clang->getDiagnostics());
-  if (!Success)
+  if (!Success) {
+Clang->getDiagnosticClient().finish();
 return 1;
+  }
 
   // Execute the frontend actions.
   {
Index: clang/test/Misc/serialized-diags-unknown-target.c
===
--- /dev/null
+++ clang/test/Misc/serialized-diags-unknown-target.c
@@ -0,0 +1,4 @@
+// RUN: rm -rf %t && mkdir %t
+// RUN: not %clang_cc1 %s -triple blah-unknown-unknown 
-serialize-diagnostic-file %t/diag -o /dev/null 2>&1 | FileCheck %s
+
+// CHECK: error: unknown target triple 'blah-unknown-unknown', please use 
-triple or -arch
Index: clang/test/Misc/serialized-diags-unknown-argument.c
===
--- /dev/null
+++ clang/test/Misc/serialized-diags-unknown-argument.c
@@ -0,0 +1,4 @@
+// RUN: rm -rf %t && mkdir %t
+// RUN: not %clang_cc1 %s -unknown-argument -serialize-diagnostic-file %t/diag 
-o /dev/null 2>&1 | FileCheck %s
+
+// CHECK: error: unknown argument: '-unknown-argument'
Index: clang/test/Misc/serialized-diags-emit-header-module-misconfig.c
===
--- /dev/null
+++ clang/test/Misc/serialized-diags-emit-header-module-misconfig.c
@@ -0,0 +1,4 @@
+// RUN: rm -rf %t && mkdir %t
+// RUN: not %clang_cc1 -emit-header-module %s -o %t/out.pcm 
-serialize-diagnostic-file %t/diag 2>&1 | FileCheck %s
+
+// CHECK: error: header module compilation requires '-fmodules', '-std=c++20', 
or '-fmodules-ts'
Index: clang/lib/Frontend/CompilerInstance.cpp
===
--- clang/lib/Frontend/CompilerInstance.cpp
+++ clang/lib/Frontend/CompilerInstance.cpp
@@ -37,6 +37,7 @@
 #include "clang/Serialization/ASTReader.h"
 #include "clang/Serialization/GlobalModuleIndex.h"
 #include "clang/Serialization/InMemoryModuleCache.h"
+#include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Support/BuryPointer.h"
 #include "llvm/Support/CrashRecoveryContext.h"
@@ -996,6 +997,11 @@
   // DesiredStackSpace available.
   noteBottomOfStack();
 
+  auto FinishDiagnosticClient = llvm::make_scope_exit([&]() {
+// Notify the diagnostic client that all files were processed.
+getDiagnosticClient().finish();
+  });
+
   raw_ostream &OS = getVerboseOutputStream();
 
   if (!Act.PrepareToExecute(*this))
@@ -1034,9 +1040,6 @@
 }
   }
 
-  // Notify the diagnostic client that all files were processed.
-  getDiagnostics().getClient()->finish();
-
   if (getDiagnosticOpts().ShowCarets) {
 // We can have multiple diagnostics sharing one diagnostic client.
 // Get the total number of warnings/errors from the client.


Index: clang/tools/driver/cc1_main.cpp
===
--- clang/tools/driver/cc1_main.cpp
+++ clang/tools/driver/cc1_main.cpp
@@ -237,8 +237,10 @@
   static_cast(&Clang->getDiagnostics()));
 
   DiagsBuffer->FlushDiagnostics(Clang->getDiagnostics());
-  if (!Success)
+  if (!Success) {
+Clang->getDiagnosticClient().finish();
 return 1;
+  }
 
   // Execute the frontend actions.
   {
Index: clang/test/Misc/serialized-diags-unknown-target.c
===
--- /dev/null
+++ clang/test/Misc/serialized-diags-unknown-target.c
@@ -0,0 +1,4 @@
+// RUN: rm -rf %t && mkdir %t
+// RUN: not %clang_cc1 %s -triple blah-unknown-unknown -serialize-diagnostic-file %t/diag -o /dev/null 2>&1 | FileCheck %s
+
+// CHECK: error: unknown target triple 'blah-unknown-unknown', please use -triple or -arch
Index: clang/test/Misc/serialized-diags-unknown-argument.c
===
--- /dev/null
+++ clang/test/Misc/serialized-diags-unknown-argument.c
@@ -0,0 +1,4 @@
+// RUN: rm -rf %t && mkdir %t
+// RUN: not %clang_cc1 %s -unknown-argument -serialize-diagnostic-file %t/diag -o /dev/null 2>&1 | FileCheck %s
+
+// CHECK: error: unknown arg

[PATCH] D97960: [clang-tidy] bugprone-signal-handler improvements: display call chain

2022-01-26 Thread Balázs Kéri via Phabricator via cfe-commits
balazske abandoned this revision.
balazske added a comment.
Herald added subscribers: carlosgalvezp, steakhal.

A new implementation is in D118224 .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97960

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


[clang] 188d28f - [clang][dataflow] Assign aggregate storage locations to union stmts

2022-01-26 Thread Stanislav Gatev via cfe-commits

Author: Stanislav Gatev
Date: 2022-01-26T10:36:49Z
New Revision: 188d28f73cc7b7891c182a85fdb6e274123b5b69

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

LOG: [clang][dataflow] Assign aggregate storage locations to union stmts

This patch ensures that the dataflow analysis framework does not crash
when it encounters access to members of union types.

This is part of the implementation of the dataflow analysis framework.
See "[RFC] A dataflow analysis framework for Clang AST" on cfe-dev.

Reviewed-by: xazax.hun

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

Added: 


Modified: 
clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Removed: 




diff  --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index 6fbc3ec42465c..512e3d991df20 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -100,7 +100,7 @@ LatticeJoinEffect Environment::join(const Environment 
&Other) {
 
 StorageLocation &Environment::createStorageLocation(QualType Type) {
   assert(!Type.isNull());
-  if (Type->isStructureOrClassType()) {
+  if (Type->isStructureOrClassType() || Type->isUnionType()) {
 // FIXME: Explore options to avoid eager initialization of fields as some 
of
 // them might not be needed for a particular analysis.
 llvm::DenseMap FieldLocs;

diff  --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index cd3e58207680a..0f7ac3af74edd 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -1952,4 +1952,37 @@ TEST_F(TransferTest, AggregateInitialization) {
   }
 }
 
+TEST_F(TransferTest, AssignToUnionMember) {
+  std::string Code = R"(
+union A {
+  int Foo;
+};
+
+void target(int Bar) {
+  A Baz;
+  Baz.Foo = Bar;
+  // [[p]]
+}
+  )";
+  runDataflow(Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
+
+const ValueDecl *BazDecl = findValueDecl(ASTCtx, "Baz");
+ASSERT_THAT(BazDecl, NotNull());
+ASSERT_TRUE(BazDecl->getType()->isUnionType());
+
+const auto *BazLoc = 
dyn_cast_or_null(
+Env.getStorageLocation(*BazDecl, SkipPast::None));
+ASSERT_THAT(BazLoc, NotNull());
+
+// FIXME: Add support for union types.
+EXPECT_THAT(Env.getValue(*BazLoc), IsNull());
+  });
+}
+
 } // namespace



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


[PATCH] D118226: [clang][dataflow] Assign aggregate storage locations to union stmts

2022-01-26 Thread Stanislav Gatev via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG188d28f73cc7: [clang][dataflow] Assign aggregate storage 
locations to union stmts (authored by sgatev).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118226

Files:
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp


Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -1952,4 +1952,37 @@
   }
 }
 
+TEST_F(TransferTest, AssignToUnionMember) {
+  std::string Code = R"(
+union A {
+  int Foo;
+};
+
+void target(int Bar) {
+  A Baz;
+  Baz.Foo = Bar;
+  // [[p]]
+}
+  )";
+  runDataflow(Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
+
+const ValueDecl *BazDecl = findValueDecl(ASTCtx, "Baz");
+ASSERT_THAT(BazDecl, NotNull());
+ASSERT_TRUE(BazDecl->getType()->isUnionType());
+
+const auto *BazLoc = 
dyn_cast_or_null(
+Env.getStorageLocation(*BazDecl, SkipPast::None));
+ASSERT_THAT(BazLoc, NotNull());
+
+// FIXME: Add support for union types.
+EXPECT_THAT(Env.getValue(*BazLoc), IsNull());
+  });
+}
+
 } // namespace
Index: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -100,7 +100,7 @@
 
 StorageLocation &Environment::createStorageLocation(QualType Type) {
   assert(!Type.isNull());
-  if (Type->isStructureOrClassType()) {
+  if (Type->isStructureOrClassType() || Type->isUnionType()) {
 // FIXME: Explore options to avoid eager initialization of fields as some 
of
 // them might not be needed for a particular analysis.
 llvm::DenseMap FieldLocs;


Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -1952,4 +1952,37 @@
   }
 }
 
+TEST_F(TransferTest, AssignToUnionMember) {
+  std::string Code = R"(
+union A {
+  int Foo;
+};
+
+void target(int Bar) {
+  A Baz;
+  Baz.Foo = Bar;
+  // [[p]]
+}
+  )";
+  runDataflow(Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
+
+const ValueDecl *BazDecl = findValueDecl(ASTCtx, "Baz");
+ASSERT_THAT(BazDecl, NotNull());
+ASSERT_TRUE(BazDecl->getType()->isUnionType());
+
+const auto *BazLoc = dyn_cast_or_null(
+Env.getStorageLocation(*BazDecl, SkipPast::None));
+ASSERT_THAT(BazLoc, NotNull());
+
+// FIXME: Add support for union types.
+EXPECT_THAT(Env.getValue(*BazLoc), IsNull());
+  });
+}
+
 } // namespace
Index: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -100,7 +100,7 @@
 
 StorageLocation &Environment::createStorageLocation(QualType Type) {
   assert(!Type.isNull());
-  if (Type->isStructureOrClassType()) {
+  if (Type->isStructureOrClassType() || Type->isUnionType()) {
 // FIXME: Explore options to avoid eager initialization of fields as some of
 // them might not be needed for a particular analysis.
 llvm::DenseMap FieldLocs;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D117137: [Driver] Add CUDA support for --offload param

2022-01-26 Thread Henry Linjamäki via Phabricator via cfe-commits
linjamaki added a comment.

In D117137#3269365 , @yaxunl wrote:

> Does that mean only "spirv{64}-unknown-unknown" is acceptable, or 
> "spirv{64}-amd-unknown-unknown" is also acceptable?

Having a vendor component in the triple seems to be acceptable for the SPIR-V 
target.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117137

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


[PATCH] D114439: [Annotation] Allow parameter pack expansions in annotate attribute

2022-01-26 Thread Steffen Larsen via Phabricator via cfe-commits
steffenlarsen updated this revision to Diff 403187.
steffenlarsen marked an inline comment as done.
steffenlarsen added a comment.

Removing top-level `const` and adjusting style.


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

https://reviews.llvm.org/D114439

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Parse/Parser.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/Parser/cxx0x-attributes.cpp
  clang/test/SemaTemplate/attributes.cpp
  clang/utils/TableGen/ClangAttrEmitter.cpp

Index: clang/utils/TableGen/ClangAttrEmitter.cpp
===
--- clang/utils/TableGen/ClangAttrEmitter.cpp
+++ clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -1164,10 +1164,12 @@
   };
 
   class VariadicExprArgument : public VariadicArgument {
+bool AllowPack = false;
+
   public:
 VariadicExprArgument(const Record &Arg, StringRef Attr)
-  : VariadicArgument(Arg, Attr, "Expr *")
-{}
+: VariadicArgument(Arg, Attr, "Expr *"),
+  AllowPack(Arg.getValueAsBit("AllowPack")) {}
 
 void writeASTVisitorTraversal(raw_ostream &OS) const override {
   OS << "  {\n";
@@ -2264,6 +2266,47 @@
   OS << "#endif // CLANG_ATTR_THIS_ISA_IDENTIFIER_ARG_LIST\n\n";
 }
 
+static void emitClangAttrNumArgs(RecordKeeper &Records, raw_ostream &OS) {
+  OS << "#if defined(CLANG_ATTR_NUM_ARGS)\n";
+  std::vector Attrs = Records.getAllDerivedDefinitions("Attr");
+  for (const auto *A : Attrs) {
+std::vector Args = A->getValueAsListOfDefs("Args");
+forEachUniqueSpelling(*A, [&](const FlattenedSpelling &S) {
+  OS << ".Case(\"" << S.name() << "\", " << Args.size() << ")\n";
+});
+  }
+  OS << "#endif // CLANG_ATTR_NUM_ARGS\n\n";
+}
+
+static bool argSupportsParmPack(const Record *Arg) {
+  return !Arg->getSuperClasses().empty() &&
+ llvm::StringSwitch(
+ Arg->getSuperClasses().back().first->getName())
+ .Case("VariadicExprArgument", true)
+ .Default(false) &&
+ Arg->getValueAsBit("AllowPack");
+}
+
+static void emitClangAttrLastArgParmPackSupport(RecordKeeper &Records,
+raw_ostream &OS) {
+  OS << "#if defined(CLANG_ATTR_LAST_ARG_PARM_PACK_SUPPORT)\n";
+  std::vector Attrs = Records.getAllDerivedDefinitions("Attr");
+  for (const auto *A : Attrs) {
+std::vector Args = A->getValueAsListOfDefs("Args");
+bool LastArgSupportsParmPack =
+!Args.empty() && argSupportsParmPack(Args.back());
+forEachUniqueSpelling(*A, [&](const FlattenedSpelling &S) {
+  OS << ".Case(\"" << S.name() << "\", " << LastArgSupportsParmPack
+ << ")\n";
+});
+  }
+  OS << "#endif // CLANG_ATTR_LAST_ARG_PARM_PACK_SUPPORT\n\n";
+}
+
+static bool isArgVariadic(const Record &R, StringRef AttrName) {
+  return createArgument(R, AttrName)->isVariadic();
+}
+
 static void emitAttributes(RecordKeeper &Records, raw_ostream &OS,
bool Header) {
   std::vector Attrs = Records.getAllDerivedDefinitions("Attr");
@@ -2320,6 +2363,18 @@
 std::vector> Args;
 Args.reserve(ArgRecords.size());
 
+if (!ArgRecords.empty()) {
+  const bool LastArgSupportsPack = argSupportsParmPack(ArgRecords.back());
+  for (size_t I = 0; I < ArgRecords.size() - 1; ++I) {
+assert((!LastArgSupportsPack ||
+!isArgVariadic(*ArgRecords[I], R.getName())) &&
+   "Attributes supporting packs can only have the last "
+   "argument as variadic");
+assert(!argSupportsParmPack(ArgRecords[I]) &&
+   "Only the last argument can allow packs");
+  }
+}
+
 bool HasOptArg = false;
 bool HasFakeArg = false;
 for (const auto *ArgRecord : ArgRecords) {
@@ -3382,10 +3437,6 @@
   }
 }
 
-static bool isArgVariadic(const Record &R, StringRef AttrName) {
-  return createArgument(R, AttrName)->isVariadic();
-}
-
 static void emitArgInfo(const Record &R, raw_ostream &OS) {
   // This function will count the number of arguments specified for the
   // attribute and emit the number of required arguments followed by the
@@ -4219,6 +4270,8 @@
   emitClangAttrIdentifierArgList(Records, OS);
   emitClangAttrVariadicIdentifierArgList(Records, OS);
   emitClangAttrThisIsaIdentifierArgList(Records, OS);
+  emitClangAttrNumArgs(Records, OS);
+  emitClangAttrLastArgParmPackSupport(Records, OS);
   emitClangAttrTypeArgList(Records, OS);
   emitClangAttrLateParsedList(Records, OS);
 }
Index: clang/test/SemaTemplate/attributes.cpp
===
--- clang/test/SemaTemplate/attributes.cpp
+++ clang/test/SemaTemplate/attributes.cpp
@@ -64,6 +64,23 @@
 template [[clang::annotate("ANNOTATE_FOO"), clang::annotate("ANNOTATE_BAR")]] void HasAnnotations();
 void UseAnnotations() { HasAnnot

[PATCH] D117753: [AArch64] Support for memset tagged intrinsic

2022-01-26 Thread Sjoerd Meijer via Phabricator via cfe-commits
SjoerdMeijer accepted this revision.
SjoerdMeijer added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117753

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


[PATCH] D114439: [Annotation] Allow parameter pack expansions in annotate attribute

2022-01-26 Thread Steffen Larsen via Phabricator via cfe-commits
steffenlarsen marked 2 inline comments as done.
steffenlarsen added inline comments.



Comment at: clang/lib/Parse/ParseDecl.cpp:497
+// Pack expansion is only allowed in the variadic argument at the end.
+const size_t attrNumArgs = attributeNumberOfArguments(*AttrName);
+if (ArgExprs.size() + I + 1 < attrNumArgs) {

aaron.ballman wrote:
> aaron.ballman wrote:
> > Coding style nits.
> We don't typically use top-level `const`, so that should go as well.
Completely missed that. My bad!



Comment at: clang/lib/Parse/ParseExpr.cpp:3374-3375
 
+if (EarlyTypoCorrection)
+  Expr = Actions.CorrectDelayedTyposInExpr(Expr);
+

aaron.ballman wrote:
> steffenlarsen wrote:
> > aaron.ballman wrote:
> > > steffenlarsen wrote:
> > > > aaron.ballman wrote:
> > > > > Not that I think this is a bad change, but it seems unrelated to the 
> > > > > patch. Can you explain why you made the change?
> > > > Admittedly I am not sure why it is needed, but in the previous version 
> > > > of the parsing for attribute parameters it does the typo-correction 
> > > > immediately after parsing the expression and if this isn't added a 
> > > > handful of tests fail.
> > > Ah, thanks for the info! So this is basically doing the same work as 
> > > what's done on line 3410 in the late failure case -- I wonder if this 
> > > should actually be tied to the `FailImmediatelyOnInvalidExpr` parameter 
> > > instead of having its own parameter?
> > They could be unified in the current version, but I don't think there is an 
> > actual relation between them.
> Do we fail tests if this isn't conditionalized at all (we always do the early 
> typo correction)? (I'd like to avoid adding the new parameter because I'm not 
> certain how a caller would determine whether they do or do not want that 
> behavior. If we need the parameter, then so be it, but it seems like this is 
> something generally useful.)
11 tests fail if we don't make it conditional. The most telling one is probably 
`SemaCXX/typo-correction-delayed.cpp` which will have more errors if we do typo 
correction early, so it seems that the delay is intentional. 



Comment at: clang/test/Parser/cxx0x-attributes.cpp:262
 
-template void variadic() {
+template  void variadic() {
   void bar [[noreturn...]] (); // expected-error {{attribute 'noreturn' cannot 
be used as an attribute pack}}

aaron.ballman wrote:
> You can back out the whitespace changes for an ever-so-slightly smaller 
> patch. :-D
Absolutely. Clang-format was very insistent, but since it isn't added by this 
patch I shouldn't worry. 😄 



Comment at: clang/test/Parser/cxx0x-attributes.cpp:276-277
+  void foz [[clang::annotate("E", 1, 2, 3, Is...)]] ();
+  void fiz [[clang::annotate("F", Is..., 1, 2, 3)]] ();
+  void fir [[clang::annotate("G", 1, Is..., 2, 3)]] ();
+}

aaron.ballman wrote:
> Shouldn't these cases also give the `// expected-error {{pack expansion in 
> 'annotate' may only be applied to the last argument}}` diagnostic?
These should preferably pass. They are part of the "last" argument as 
`annotate` has one non-variadic argument and one variadic argument. I agree 
though that the error message is a little vague. Originally the error did 
specify that it had to be "argument %1 or later" to try and convey this intent, 
but maybe you have an idea for a clearer error message?


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

https://reviews.llvm.org/D114439

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


[clang-tools-extra] 19eaad9 - [clang-tidy] Cache the locations of NOLINTBEGIN/END blocks

2022-01-26 Thread Salman Javed via cfe-commits

Author: Salman Javed
Date: 2022-01-27T00:12:16+13:00
New Revision: 19eaad94c47f92dd23989b0b6832bb6751dde979

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

LOG: [clang-tidy] Cache the locations of NOLINTBEGIN/END blocks

Support for NOLINT(BEGIN/END) blocks (implemented in D108560) is
currently costly. This patch aims to improve the performance with the
following changes:

- The use of tokenized NOLINTs instead of a series of repetitive ad-hoc
string operations (`find()`, `split()`, `slice()`, regex matching etc).
- The caching of NOLINT(BEGIN/END) block locations. Determining these
locations each time a new diagnostic is raised is wasteful as it
requires reading and parsing the entire source file.

Move NOLINT-specific code from `ClangTidyDiagnosticConsumer` to new
purpose-built class `NoLintDirectiveHandler`.

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

Added: 
clang-tools-extra/clang-tidy/NoLintDirectiveHandler.cpp
clang-tools-extra/clang-tidy/NoLintDirectiveHandler.h

clang-tools-extra/test/clang-tidy/infrastructure/Inputs/nolintbeginend/1st-translation-unit.cpp

clang-tools-extra/test/clang-tidy/infrastructure/Inputs/nolintbeginend/2nd-translation-unit.cpp
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-LIFO.cpp

clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-all-end-glob.cpp

clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-all-end-specific.cpp

clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-glob-end-all.cpp

clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-glob-end-specific.cpp

clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-multiple-end-single.cpp

clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-single-end-multiple.cpp

clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-specific-end-all.cpp

clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-specific-end-glob.cpp

clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-multiple-TUs.cpp

Modified: 
clang-tools-extra/clang-tidy/CMakeLists.txt
clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
clang-tools-extra/clangd/ParsedAST.cpp
clang-tools-extra/test/clang-tidy/infrastructure/nolint.cpp

clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-mismatched-check-names.cpp

clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-mismatched-delims.cpp

clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-typo-in-check-name.cpp
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend.cpp

Removed: 

clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-global-end-specific.cpp

clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-specific-end-global.cpp



diff  --git a/clang-tools-extra/clang-tidy/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/CMakeLists.txt
index 075e9f9909d6..8a953eeea275 100644
--- a/clang-tools-extra/clang-tidy/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/CMakeLists.txt
@@ -17,6 +17,7 @@ add_clang_library(clangTidy
   ClangTidyProfiling.cpp
   ExpandModularHeadersPPCallbacks.cpp
   GlobList.cpp
+  NoLintDirectiveHandler.cpp
 
   DEPENDS
   ClangSACheckers

diff  --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp 
b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
index 66f60ec60b60..04721a2d3a02 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -18,6 +18,7 @@
 #include "ClangTidyDiagnosticConsumer.h"
 #include "ClangTidyOptions.h"
 #include "GlobList.h"
+#include "NoLintDirectiveHandler.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ASTDiagnostic.h"
 #include "clang/AST/Attr.h"
@@ -188,7 +189,7 @@ DiagnosticBuilder ClangTidyContext::diag(
   return DiagEngine->Report(ID);
 }
 
-DiagnosticBuilder ClangTidyContext::diag(const ClangTidyError &Error) {
+DiagnosticBuilder ClangTidyContext::diag(const tooling::Diagnostic &Error) {
   SourceManager &SM = DiagEngine->getSourceManager();
   llvm::ErrorOr File =
   SM.getFileManager().getFile(Error.Message.FilePath);
@@ -206,6 +207,15 @@ DiagnosticBuilder ClangTidyContext::configurationDiag(
   return diag("clang-tidy-config", Message, Level);
 }
 
+bool ClangTidyContext::shouldSuppressDiagnostic(
+DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info,
+SmallVectorImpl &NoLintErrors, bool AllowIO,
+bool EnableNoLintBlocks) {
+  std::string CheckName = getCheckName(Info.getID());

[PATCH] D116085: [clang-tidy] Performance improvements for NOLINTBEGIN/END blocks

2022-01-26 Thread Salman Javed via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG19eaad94c47f: [clang-tidy] Cache the locations of 
NOLINTBEGIN/END blocks (authored by salman-javed-nz).

Changed prior to commit:
  https://reviews.llvm.org/D116085?vs=402818&id=403196#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116085

Files:
  clang-tools-extra/clang-tidy/CMakeLists.txt
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
  clang-tools-extra/clang-tidy/NoLintDirectiveHandler.cpp
  clang-tools-extra/clang-tidy/NoLintDirectiveHandler.h
  clang-tools-extra/clangd/ParsedAST.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/Inputs/nolintbeginend/1st-translation-unit.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/Inputs/nolintbeginend/2nd-translation-unit.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/nolint.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-LIFO.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-all-end-glob.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-all-end-specific.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-glob-end-all.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-glob-end-specific.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-global-end-specific.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-multiple-end-single.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-single-end-multiple.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-specific-end-all.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-specific-end-glob.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-specific-end-global.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-mismatched-check-names.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-mismatched-delims.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-multiple-TUs.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-typo-in-check-name.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend.cpp

Index: clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend.cpp
===
--- clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend.cpp
+++ clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend.cpp
@@ -58,30 +58,24 @@
 // NOLINTEND(some-other-check)
 // NOLINTEND(google-explicit-constructor)
 
-// NOLINTBEGIN(google-explicit-constructor)
-// NOLINTBEGIN(some-other-check)
-class C7 { C7(int i); };
-// NOLINTEND(google-explicit-constructor)
-// NOLINTEND(some-other-check)
-
 // NOLINTBEGIN(google-explicit-constructor)
 // NOLINTBEGIN
-class C8 { C8(int i); };
+class C7 { C7(int i); };
 // NOLINTEND
 // NOLINTEND(google-explicit-constructor)
 
 // NOLINTBEGIN
 // NOLINTBEGIN(google-explicit-constructor)
-class C9 { C9(int i); };
+class C8 { C8(int i); };
 // NOLINTEND(google-explicit-constructor)
 // NOLINTEND
 
 // NOLINTBEGIN(not-closed-bracket-is-treated-as-skip-all
-class C10 { C10(int i); };
+class C9 { C9(int i); };
 // NOLINTEND(not-closed-bracket-is-treated-as-skip-all
 
 // NOLINTBEGIN without-brackets-skip-all, another-check
-class C11 { C11(int i); };
+class C10 { C10(int i); };
 // NOLINTEND without-brackets-skip-all, another-check
 
 #define MACRO(X) class X { X(int i); };
@@ -114,28 +108,28 @@
 MACRO_NO_LINT_INSIDE_MACRO
 
 // NOLINTBEGIN(google*)
-class C12 { C12(int i); };
+class C11 { C11(int i); };
 // NOLINTEND(google*)
 
 // NOLINTBEGIN(*explicit-constructor)
-class C15 { C15(int i); };
+class C12 { C12(int i); };
 // NOLINTEND(*explicit-constructor)
 
 // NOLINTBEGIN(*explicit*)
-class C16 { C16(int i); };
+class C13 { C13(int i); };
 // NOLINTEND(*explicit*)
 
 // NOLINTBEGIN(-explicit-constructor)
-class C17 { C17(int x); };
+class C14 { C14(int x); };
 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: single-argument constructors must be marked explicit
 // NOLINTEND(-explicit-constructor)
 
 // NOLINTBEGIN(google*,-google*)
-class C18 { C18(int x); };
+class C15 { C15(int x); };
 // NOLINTEND(google*,-google*)
 
 // NOLINTBEGIN(*,-google*)
-class C19 { C19(int x); };
+class C16 { C16(int x); };
 // NOLINTEND(*,-google*)
 
 int array1[10];
@@ -154,4 +148,4 @@
 int array4[10];
 // NOLINTEND(*-avoid-c-arrays)
 
-// CHECK-MESSAGES: Suppressed 27 warnings (27 NOLINT).
+// CHECK-MESSAGES: Suppressed 26 warnings (26 NOLINT).
Index: clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-multiple-TUs.cpp
==

[clang] 04754af - Fix MSVC 'not all control paths return a value' warning. NFC.

2022-01-26 Thread Simon Pilgrim via cfe-commits

Author: Simon Pilgrim
Date: 2022-01-26T11:33:37Z
New Revision: 04754af925053efdc91fd0cbe045feb7578ad1ae

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

LOG: Fix MSVC 'not all control paths return a value' warning. NFC.

Added: 


Modified: 
clang/lib/Tooling/Transformer/SourceCodeBuilders.cpp

Removed: 




diff  --git a/clang/lib/Tooling/Transformer/SourceCodeBuilders.cpp 
b/clang/lib/Tooling/Transformer/SourceCodeBuilders.cpp
index 65ade4387a5e..7496e968469c 100644
--- a/clang/lib/Tooling/Transformer/SourceCodeBuilders.cpp
+++ b/clang/lib/Tooling/Transformer/SourceCodeBuilders.cpp
@@ -205,6 +205,7 @@ static bool treatLikePointer(QualType Ty, PLTClass C, 
ASTContext &Context) {
   case PLTClass::Pointer:
 return isKnownPointerLikeType(Ty, Context);
   }
+  llvm_unreachable("Unknown PLTClass enum");
 }
 
 // FIXME: move over the other `maybe` functionality from Stencil. Should all be



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


[clang] d3597ec - [clang][dataflow] Enable merging distinct values in Environment::join

2022-01-26 Thread Stanislav Gatev via cfe-commits

Author: Stanislav Gatev
Date: 2022-01-26T11:40:51Z
New Revision: d3597ec0aaad11a670f45b42428628531d4b2c05

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

LOG: [clang][dataflow] Enable merging distinct values in Environment::join

Make specializations of `DataflowAnalysis` extendable with domain-specific
logic for merging distinct values when joining environments. This could be
a strict lattice join or a more general widening operation.

This is part of the implementation of the dataflow analysis framework.
See "[RFC] A dataflow analysis framework for Clang AST" on cfe-dev.

Reviewed-by: xazax.hun

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

Added: 


Modified: 
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h
clang/include/clang/Analysis/FlowSensitive/Value.h
clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
clang/unittests/Analysis/FlowSensitive/TestingSupport.cpp
clang/unittests/Analysis/FlowSensitive/TestingSupport.h
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp

Removed: 




diff  --git a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h 
b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
index 7402e42749ee2..38a64a277412b 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
@@ -42,6 +42,11 @@ namespace dataflow {
 ///   * `void transfer(const Stmt *, LatticeT &, Environment &)` - applies the
 /// analysis transfer function for a given statement and lattice element.
 ///
+///  `Derived` can optionally override the following members:
+///   * `bool merge(QualType, const Value &, const Value &, Value &,
+/// Environment &)` -  joins distinct values. This could be a strict
+/// lattice join or a more general widening operation.
+///
 ///  `LatticeT` is a bounded join-semilattice that is used by `Derived` and 
must
 ///  provide the following public members:
 ///   * `LatticeJoinEffect join(const LatticeT &)` - joins the object and the

diff  --git 
a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h 
b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
index d1a06f7ef8d3a..5c1b41d538921 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
@@ -22,6 +22,7 @@
 #include "llvm/ADT/DenseMap.h"
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -32,15 +33,21 @@ namespace dataflow {
 /// is used during dataflow analysis.
 class DataflowAnalysisContext {
 public:
+  DataflowAnalysisContext()
+  : TrueVal(&takeOwnership(std::make_unique())),
+FalseVal(&takeOwnership(std::make_unique())) {}
+
   /// Takes ownership of `Loc` and returns a reference to it.
   ///
   /// Requirements:
   ///
   ///  `Loc` must not be null.
-  StorageLocation &takeOwnership(std::unique_ptr Loc) {
+  template 
+  typename std::enable_if::value, T 
&>::type
+  takeOwnership(std::unique_ptr Loc) {
 assert(Loc != nullptr);
 Locs.push_back(std::move(Loc));
-return *Locs.back().get();
+return *cast(Locs.back().get());
   }
 
   /// Takes ownership of `Val` and returns a reference to it.
@@ -48,10 +55,12 @@ class DataflowAnalysisContext {
   /// Requirements:
   ///
   ///  `Val` must not be null.
-  Value &takeOwnership(std::unique_ptr Val) {
+  template 
+  typename std::enable_if::value, T &>::type
+  takeOwnership(std::unique_ptr Val) {
 assert(Val != nullptr);
 Vals.push_back(std::move(Val));
-return *Vals.back().get();
+return *cast(Vals.back().get());
   }
 
   /// Assigns `Loc` as the storage location of `D`.
@@ -104,6 +113,12 @@ class DataflowAnalysisContext {
 return ThisPointeeLoc;
   }
 
+  /// Returns a symbolic boolean value that models a boolean literal equal to
+  /// `Value`.
+  BoolValue &getBoolLiteralValue(bool Value) const {
+return Value ? *TrueVal : *FalseVal;
+  }
+
 private:
   // Storage for the state of a program.
   std::vector> Locs;
@@ -120,6 +135,8 @@ class DataflowAnalysisContext {
   StorageLocation *ThisPointeeLoc = nullptr;
 
   // FIXME: Add support for boolean expressions.
+  BoolValue *TrueVal;
+  BoolValue *FalseVal;
 };
 
 } // namespace dataflow

diff  --git a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h 
b/cla

[PATCH] D118038: [clang][dataflow] Enable merging distinct values in Environment::join

2022-01-26 Thread Stanislav Gatev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd3597ec0aaad: [clang][dataflow] Enable merging distinct 
values in Environment::join (authored by sgatev).

Changed prior to commit:
  https://reviews.llvm.org/D118038?vs=402550&id=403201#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118038

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
  clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h
  clang/include/clang/Analysis/FlowSensitive/Value.h
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
  clang/unittests/Analysis/FlowSensitive/TestingSupport.cpp
  clang/unittests/Analysis/FlowSensitive/TestingSupport.h
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
  clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -9,6 +9,7 @@
 #include "NoopAnalysis.h"
 #include "TestingSupport.h"
 #include "clang/AST/Decl.h"
+#include "clang/AST/ExprCXX.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Analysis/CFG.h"
@@ -16,6 +17,7 @@
 #include "clang/Analysis/FlowSensitive/DataflowAnalysisContext.h"
 #include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
 #include "clang/Analysis/FlowSensitive/DataflowLattice.h"
+#include "clang/Analysis/FlowSensitive/Value.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallSet.h"
@@ -35,8 +37,15 @@
 
 using namespace clang;
 using namespace dataflow;
+using namespace test;
+using namespace ast_matchers;
+using ::testing::_;
+using ::testing::ElementsAre;
 using ::testing::IsEmpty;
+using ::testing::IsNull;
+using ::testing::NotNull;
 using ::testing::Pair;
+using ::testing::Test;
 using ::testing::UnorderedElementsAre;
 
 template 
@@ -174,7 +183,7 @@
   }
 };
 
-class NoreturnDestructorTest : public ::testing::Test {
+class NoreturnDestructorTest : public Test {
 protected:
   template 
   void runDataflow(llvm::StringRef Code, Matcher Expectations) {
@@ -300,4 +309,184 @@
   // FIXME: Called functions at point `p` should contain only "foo".
 }
 
+class OptionalIntAnalysis
+: public DataflowAnalysis {
+public:
+  explicit OptionalIntAnalysis(ASTContext &Context)
+  : DataflowAnalysis(Context) {}
+
+  static NoopLattice initialElement() { return {}; }
+
+  void transfer(const Stmt *S, NoopLattice &, Environment &Env) {
+auto OptionalIntRecordDecl = recordDecl(hasName("OptionalInt"));
+auto HasOptionalIntType = hasType(OptionalIntRecordDecl);
+
+if (const auto *E = selectFirst(
+"call", match(cxxConstructExpr(HasOptionalIntType).bind("call"), *S,
+  getASTContext( {
+  auto &ConstructorVal = *cast(Env.createValue(E->getType()));
+  ConstructorVal.setProperty("has_value", Env.getBoolLiteralValue(false));
+  Env.setValue(*Env.getStorageLocation(*E, SkipPast::None), ConstructorVal);
+} else if (const auto *E = selectFirst(
+   "call",
+   match(cxxOperatorCallExpr(callee(cxxMethodDecl(ofClass(
+ OptionalIntRecordDecl
+ .bind("call"),
+ *S, getASTContext( {
+  assert(E->getNumArgs() > 0);
+  auto *Object = E->getArg(0);
+  assert(Object != nullptr);
+
+  auto *ObjectLoc =
+  Env.getStorageLocation(*Object, SkipPast::ReferenceThenPointer);
+  assert(ObjectLoc != nullptr);
+
+  auto &ConstructorVal =
+  *cast(Env.createValue(Object->getType()));
+  ConstructorVal.setProperty("has_value", Env.getBoolLiteralValue(true));
+  Env.setValue(*ObjectLoc, ConstructorVal);
+}
+  }
+
+  bool merge(QualType Type, const Value &Val1, const Value &Val2,
+ Value &MergedVal, Environment &Env) final {
+if (!Type->isRecordType() ||
+Type->getAsCXXRecordDecl()->getQualifiedNameAsString() != "OptionalInt")
+  return false;
+
+auto *HasValue1 = cast_or_null(
+cast(&Val1)->getProperty("has_value"));
+if (HasValue1 == nullptr)
+  return false;
+
+auto *HasValue2 = cast_or_null(
+cast(&Val2)->getProperty("has_value"));
+if (HasValue2 == nullptr)
+  return false;
+
+if (HasValue1 != HasValue2)
+  return false;
+
+cast(&MergedVal)->setProperty("has_value"

[PATCH] D115501: [clang][ARM] Emit warnings when PACBTI-M is used with unsupported architectures

2022-01-26 Thread Momchil Velikov via Phabricator via cfe-commits
chill accepted this revision.
chill added a comment.
This revision is now accepted and ready to land.

LGTM, cheers!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115501

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


[clang-tools-extra] 8e29d19 - Revert "[clang-tidy] Cache the locations of NOLINTBEGIN/END blocks"

2022-01-26 Thread Salman Javed via cfe-commits

Author: Salman Javed
Date: 2022-01-27T00:52:44+13:00
New Revision: 8e29d19b8d29db1ad60af3a8921aad7bbfc24435

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

LOG: Revert "[clang-tidy] Cache the locations of NOLINTBEGIN/END blocks"

Build warning here:
https://lab.llvm.org/buildbot/#/builders/57/builds/14322

Added: 

clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-global-end-specific.cpp

clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-specific-end-global.cpp

Modified: 
clang-tools-extra/clang-tidy/CMakeLists.txt
clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
clang-tools-extra/clangd/ParsedAST.cpp
clang-tools-extra/test/clang-tidy/infrastructure/nolint.cpp

clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-mismatched-check-names.cpp

clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-mismatched-delims.cpp

clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-typo-in-check-name.cpp
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend.cpp

Removed: 
clang-tools-extra/clang-tidy/NoLintDirectiveHandler.cpp
clang-tools-extra/clang-tidy/NoLintDirectiveHandler.h

clang-tools-extra/test/clang-tidy/infrastructure/Inputs/nolintbeginend/1st-translation-unit.cpp

clang-tools-extra/test/clang-tidy/infrastructure/Inputs/nolintbeginend/2nd-translation-unit.cpp
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-LIFO.cpp

clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-all-end-glob.cpp

clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-all-end-specific.cpp

clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-glob-end-all.cpp

clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-glob-end-specific.cpp

clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-multiple-end-single.cpp

clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-single-end-multiple.cpp

clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-specific-end-all.cpp

clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-specific-end-glob.cpp

clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-multiple-TUs.cpp



diff  --git a/clang-tools-extra/clang-tidy/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/CMakeLists.txt
index 8a953eeea2759..075e9f9909d65 100644
--- a/clang-tools-extra/clang-tidy/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/CMakeLists.txt
@@ -17,7 +17,6 @@ add_clang_library(clangTidy
   ClangTidyProfiling.cpp
   ExpandModularHeadersPPCallbacks.cpp
   GlobList.cpp
-  NoLintDirectiveHandler.cpp
 
   DEPENDS
   ClangSACheckers

diff  --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp 
b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
index 04721a2d3a020..66f60ec60b605 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -18,7 +18,6 @@
 #include "ClangTidyDiagnosticConsumer.h"
 #include "ClangTidyOptions.h"
 #include "GlobList.h"
-#include "NoLintDirectiveHandler.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ASTDiagnostic.h"
 #include "clang/AST/Attr.h"
@@ -189,7 +188,7 @@ DiagnosticBuilder ClangTidyContext::diag(
   return DiagEngine->Report(ID);
 }
 
-DiagnosticBuilder ClangTidyContext::diag(const tooling::Diagnostic &Error) {
+DiagnosticBuilder ClangTidyContext::diag(const ClangTidyError &Error) {
   SourceManager &SM = DiagEngine->getSourceManager();
   llvm::ErrorOr File =
   SM.getFileManager().getFile(Error.Message.FilePath);
@@ -207,15 +206,6 @@ DiagnosticBuilder ClangTidyContext::configurationDiag(
   return diag("clang-tidy-config", Message, Level);
 }
 
-bool ClangTidyContext::shouldSuppressDiagnostic(
-DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info,
-SmallVectorImpl &NoLintErrors, bool AllowIO,
-bool EnableNoLintBlocks) {
-  std::string CheckName = getCheckName(Info.getID());
-  return NoLintHandler.shouldSuppress(DiagLevel, Info, CheckName, NoLintErrors,
-  AllowIO, EnableNoLintBlocks);
-}
-
 void ClangTidyContext::setSourceManager(SourceManager *SourceMgr) {
   DiagEngine->setSourceManager(SourceMgr);
 }
@@ -317,9 +307,218 @@ void ClangTidyDiagnosticConsumer::finalizeLastError() {
   LastErrorPassesLineFilter = false;
 }
 
+static bool isNOLINTFound(StringRef NolintDirectiveText, StringRef CheckName,
+  StringRef Line, size_t *FoundNolintIndex = nullptr,
+  

[PATCH] D118223: [NFC] [AST] Move isSame* check in ASTReader to ASTContext

2022-01-26 Thread Nathan Sidwell via Phabricator via cfe-commits
urnathan added a comment.

I'm insufficiently confident to review this kind of code motion.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118223

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


[clang-tools-extra] 5da7c04 - Re-land "Cache the locations of NOLINTBEGIN/END blocks" with fix for build bot

2022-01-26 Thread Salman Javed via cfe-commits

Author: Salman Javed
Date: 2022-01-27T01:03:27+13:00
New Revision: 5da7c040030c4af72dcc21220f579098469c554e

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

LOG: Re-land "Cache the locations of NOLINTBEGIN/END blocks" with fix for build 
bot

Added: 
clang-tools-extra/clang-tidy/NoLintDirectiveHandler.cpp
clang-tools-extra/clang-tidy/NoLintDirectiveHandler.h

clang-tools-extra/test/clang-tidy/infrastructure/Inputs/nolintbeginend/1st-translation-unit.cpp

clang-tools-extra/test/clang-tidy/infrastructure/Inputs/nolintbeginend/2nd-translation-unit.cpp
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-LIFO.cpp

clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-all-end-glob.cpp

clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-all-end-specific.cpp

clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-glob-end-all.cpp

clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-glob-end-specific.cpp

clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-multiple-end-single.cpp

clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-single-end-multiple.cpp

clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-specific-end-all.cpp

clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-specific-end-glob.cpp

clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-multiple-TUs.cpp

Modified: 
clang-tools-extra/clang-tidy/CMakeLists.txt
clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
clang-tools-extra/clangd/ParsedAST.cpp
clang-tools-extra/test/clang-tidy/infrastructure/nolint.cpp

clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-mismatched-check-names.cpp

clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-mismatched-delims.cpp

clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-typo-in-check-name.cpp
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend.cpp

Removed: 

clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-global-end-specific.cpp

clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-specific-end-global.cpp



diff  --git a/clang-tools-extra/clang-tidy/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/CMakeLists.txt
index 075e9f9909d65..8a953eeea2759 100644
--- a/clang-tools-extra/clang-tidy/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/CMakeLists.txt
@@ -17,6 +17,7 @@ add_clang_library(clangTidy
   ClangTidyProfiling.cpp
   ExpandModularHeadersPPCallbacks.cpp
   GlobList.cpp
+  NoLintDirectiveHandler.cpp
 
   DEPENDS
   ClangSACheckers

diff  --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp 
b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
index 66f60ec60b605..04721a2d3a020 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -18,6 +18,7 @@
 #include "ClangTidyDiagnosticConsumer.h"
 #include "ClangTidyOptions.h"
 #include "GlobList.h"
+#include "NoLintDirectiveHandler.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ASTDiagnostic.h"
 #include "clang/AST/Attr.h"
@@ -188,7 +189,7 @@ DiagnosticBuilder ClangTidyContext::diag(
   return DiagEngine->Report(ID);
 }
 
-DiagnosticBuilder ClangTidyContext::diag(const ClangTidyError &Error) {
+DiagnosticBuilder ClangTidyContext::diag(const tooling::Diagnostic &Error) {
   SourceManager &SM = DiagEngine->getSourceManager();
   llvm::ErrorOr File =
   SM.getFileManager().getFile(Error.Message.FilePath);
@@ -206,6 +207,15 @@ DiagnosticBuilder ClangTidyContext::configurationDiag(
   return diag("clang-tidy-config", Message, Level);
 }
 
+bool ClangTidyContext::shouldSuppressDiagnostic(
+DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info,
+SmallVectorImpl &NoLintErrors, bool AllowIO,
+bool EnableNoLintBlocks) {
+  std::string CheckName = getCheckName(Info.getID());
+  return NoLintHandler.shouldSuppress(DiagLevel, Info, CheckName, NoLintErrors,
+  AllowIO, EnableNoLintBlocks);
+}
+
 void ClangTidyContext::setSourceManager(SourceManager *SourceMgr) {
   DiagEngine->setSourceManager(SourceMgr);
 }
@@ -307,218 +317,9 @@ void ClangTidyDiagnosticConsumer::finalizeLastError() {
   LastErrorPassesLineFilter = false;
 }
 
-static bool isNOLINTFound(StringRef NolintDirectiveText, StringRef CheckName,
-  StringRef Line, size_t *FoundNolintIndex = nullptr,
-  StringRef *FoundNolintChecksStr = nullptr) {
-  if (FoundN

[PATCH] D118225: [RISCV] Decouple Zve* extensions.

2022-01-26 Thread Yueh-Ting Chen via Phabricator via cfe-commits
eopXD added a comment.

Not sure if this simplifies things. Users and the compiler  can use the macro 
__riscv_v_elen and __riscv_v_elen_fp to do things to the vector-related target 
feature.

Other than that I dont hold any strong objection to this refactoring.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118225

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


[PATCH] D118236: [clang][dataflow] Add a transfer function for CXXBoolLiteralExpr

2022-01-26 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev created this revision.
sgatev added reviewers: ymandel, xazax.hun, gribozavr2.
Herald added subscribers: tschuett, steakhal, rnkovacs.
sgatev requested review of this revision.
Herald added a project: clang.

This is part of the implementation of the dataflow analysis framework.
See "[RFC] A dataflow analysis framework for Clang AST" on cfe-dev.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118236

Files:
  clang/lib/Analysis/FlowSensitive/Transfer.cpp
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp


Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -1970,4 +1970,39 @@
   });
 }
 
+TEST_F(TransferTest, AssignFromBoolLiteral) {
+  std::string Code = R"(
+void target() {
+  bool Foo = true;
+  bool Bar = false;
+  // [[p]]
+}
+  )";
+  runDataflow(
+  Code, [](llvm::ArrayRef<
+   std::pair>>
+   Results,
+   ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
+
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+const auto *FooVal =
+dyn_cast_or_null(Env.getValue(*FooDecl, 
SkipPast::None));
+ASSERT_THAT(FooVal, NotNull());
+
+const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+ASSERT_THAT(BarDecl, NotNull());
+
+const auto *BarVal =
+dyn_cast_or_null(Env.getValue(*BarDecl, 
SkipPast::None));
+ASSERT_THAT(BarVal, NotNull());
+
+EXPECT_EQ(FooVal, &Env.getBoolLiteralValue(true));
+EXPECT_EQ(BarVal, &Env.getBoolLiteralValue(false));
+  });
+}
+
 } // namespace
Index: clang/lib/Analysis/FlowSensitive/Transfer.cpp
===
--- clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -443,8 +443,11 @@
 // FIXME: Implement array initialization.
   }
 
-  // FIXME: Add support for:
-  // - CXXBoolLiteralExpr
+  void VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *S) {
+auto &Loc = Env.createStorageLocation(*S);
+Env.setStorageLocation(*S, Loc);
+Env.setValue(Loc, Env.getBoolLiteralValue(S->getValue()));
+  }
 
 private:
   Environment &Env;


Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -1970,4 +1970,39 @@
   });
 }
 
+TEST_F(TransferTest, AssignFromBoolLiteral) {
+  std::string Code = R"(
+void target() {
+  bool Foo = true;
+  bool Bar = false;
+  // [[p]]
+}
+  )";
+  runDataflow(
+  Code, [](llvm::ArrayRef<
+   std::pair>>
+   Results,
+   ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
+
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+const auto *FooVal =
+dyn_cast_or_null(Env.getValue(*FooDecl, SkipPast::None));
+ASSERT_THAT(FooVal, NotNull());
+
+const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+ASSERT_THAT(BarDecl, NotNull());
+
+const auto *BarVal =
+dyn_cast_or_null(Env.getValue(*BarDecl, SkipPast::None));
+ASSERT_THAT(BarVal, NotNull());
+
+EXPECT_EQ(FooVal, &Env.getBoolLiteralValue(true));
+EXPECT_EQ(BarVal, &Env.getBoolLiteralValue(false));
+  });
+}
+
 } // namespace
Index: clang/lib/Analysis/FlowSensitive/Transfer.cpp
===
--- clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -443,8 +443,11 @@
 // FIXME: Implement array initialization.
   }
 
-  // FIXME: Add support for:
-  // - CXXBoolLiteralExpr
+  void VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *S) {
+auto &Loc = Env.createStorageLocation(*S);
+Env.setStorageLocation(*S, Loc);
+Env.setValue(Loc, Env.getBoolLiteralValue(S->getValue()));
+  }
 
 private:
   Environment &Env;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D118084: [CUDA, NVPTX] Pass byval aggregates directly

2022-01-26 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

In D118084#3271110 , @tra wrote:

> In D118084#3271073 , @jdoerfert 
> wrote:
>
>> @lebedev.ri wanted to teach SROA how to deal with dynamic indices before, 
>> IIRC. It seems to be generally useful.
>
> Interesting. I'd like to hear more.

I guess i, too, would like to hear more about the problem.
My last idea was about allowing splitting

  struct {
int a;
int b[2];
  } a;

into

  // not in a struct anymore!
  int a;
  int b[2]

But given just the `int b[2];` i'm not sure what can be done.

>> This patch can wait till then?
>
> Yes.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118084

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


[PATCH] D116085: [clang-tidy] Performance improvements for NOLINTBEGIN/END blocks

2022-01-26 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai added a comment.

This is causing buildbot failures with `-Werror` (i.e. 
https://lab.llvm.org/buildbot/#/builders/57/builds/14322/steps/5/logs/stdio). 
Please fix or revert. The failure is:

  
.../llvm-project/clang-tools-extra/clang-tidy/NoLintDirectiveHandler.cpp:204:38:
 error: moving a temporary object prevents copy elision 
[-Werror,-Wpessimizing-move]
  CompletedBlocks.emplace_back(std::move(Stack.pop_back_val()), NoLint);


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116085

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


[PATCH] D116085: [clang-tidy] Performance improvements for NOLINTBEGIN/END blocks

2022-01-26 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai added a comment.

In D116085#3272200 , @nemanjai wrote:

> This is causing buildbot failures with `-Werror` (i.e. 
> https://lab.llvm.org/buildbot/#/builders/57/builds/14322/steps/5/logs/stdio). 
> Please fix or revert. The failure is:
>
>   
> .../llvm-project/clang-tools-extra/clang-tidy/NoLintDirectiveHandler.cpp:204:38:
>  error: moving a temporary object prevents copy elision 
> [-Werror,-Wpessimizing-move]
>   CompletedBlocks.emplace_back(std::move(Stack.pop_back_val()), 
> NoLint);

Sorry, I didn't realize you already reverted as there was no mention in the 
revert of the original commit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116085

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


[PATCH] D116085: [clang-tidy] Performance improvements for NOLINTBEGIN/END blocks

2022-01-26 Thread Salman Javed via Phabricator via cfe-commits
salman-javed-nz added a comment.

In D116085#3272200 , @nemanjai wrote:

> This is causing buildbot failures with `-Werror` (i.e. 
> https://lab.llvm.org/buildbot/#/builders/57/builds/14322/steps/5/logs/stdio). 
> Please fix or revert.

Thanks for the heads up. I have reverted in 
8e29d19b8d29db1ad60af3a8921aad7bbfc24435 
 while I 
investigate.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116085

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


[PATCH] D116753: Default to -fno-math-errno for musl too

2022-01-26 Thread Alex Xu (Hello71) via Phabricator via cfe-commits
alxu added subscribers: MaskRay, pirama, srhines.
alxu added a comment.

Hi, can someone take a look at this? @MaskRay, @pirama, @srhines? Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116753

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


[PATCH] D117262: [NFC] Store Address's alignment into PointerIntPairs

2022-01-26 Thread Nikita Popov via Phabricator via cfe-commits
nikic added a comment.

Approach looks reasonable to me.




Comment at: clang/lib/CodeGen/Address.h:29
+// so we fallback to storing the alignment separately.
+template = 8> class AddressImpl {};
+

Why do we need the extra T parameter?



Comment at: clang/lib/CodeGen/Address.h:70
+unsigned AlignLog = (Pointer.getInt() << 3) | ElementType.getInt();
+return CharUnits::fromQuantity(1 << AlignLog);
+  }

This should probably be `1UL` to avoid UB for large alignments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117262

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


[clang-tools-extra] c283c8d - Rewrite Doxygen comment to resolve -Wdocumentation warning (NFC)

2022-01-26 Thread Salman Javed via cfe-commits

Author: Salman Javed
Date: 2022-01-27T02:21:05+13:00
New Revision: c283c8dfb5a9770126f06f55644c6208b5582c19

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

LOG: Rewrite Doxygen comment to resolve -Wdocumentation warning (NFC)

Comment change only, no functional change intended.
Example of warning:
https://lab.llvm.org/buildbot/#/builders/188/builds/8696/steps/4/logs/warnings__2_

Added: 


Modified: 
clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h 
b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
index e41003262ccc..3b5f82033d25 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
@@ -110,8 +110,8 @@ class ClangTidyContext {
   /// This does not handle suppression of notes following a suppressed
   /// diagnostic; that is left to the caller as it requires maintaining state 
in
   /// between calls to this function.
-  /// If any NOLINT is malformed, e.g. a BEGIN without a subsequent END, an
-  /// error about it will be returned in output \param NoLintErrors.
+  /// If any NOLINT is malformed, e.g. a BEGIN without a subsequent END, output
+  /// \param NoLintErrors will return an error about it.
   /// If \param AllowIO is false, the function does not attempt to read source
   /// files from disk which are not already mapped into memory; such files are
   /// treated as not containing a suppression comment.



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


[PATCH] D118110: [CMake] [Clang] Add CMake build option to specify long double format on PowerPC

2022-01-26 Thread Jinsong Ji via Phabricator via cfe-commits
jsji accepted this revision as: jsji.
jsji added a comment.
This revision is now accepted and ready to land.

LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118110

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


[PATCH] D118224: [clang-tidy] bugprone-signal-handler improvements: display call chain

2022-01-26 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp:199-200
+const FunctionDecl *HandlerDecl, const Expr *HandlerRef) {
+  int CallLevel = Itr.getPathLength() - 2;
+  const CallGraphNode *Caller = Itr.getPath(CallLevel + 1), *Callee = nullptr;
+  while (CallLevel >= 0) {

Do we have to worry about `CallLevel + 1` being negative here? (Is there a need 
for an assert?)



Comment at: clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp:207-208
+ DiagnosticIDs::Note)
+<< cast(Callee->getDecl())
+<< cast(Caller->getDecl());
+--CallLevel;

Do we have to worry about call expressions for which we cannot find the 
declaration (like a call through a function pointer)? (Should we add some test 
coverage involving a call stack with a call through a function pointer?)



Comment at: clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.h:39
   void reportBug(const FunctionDecl *CalledFunction, const Expr *CallOrRef,
- const CallExpr *SignalCall, const FunctionDecl *HandlerDecl);
+ bool DirectHandler = false);
+  void reportHandlerCommon(llvm::df_iterator Itr,

Might as well not make this an optional parameter -- no real benefit from it 
(there's only two call sites).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118224

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


[PATCH] D118223: [NFC] [AST] Move isSame* check in ASTReader to ASTContext

2022-01-26 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added a comment.
This revision is now accepted and ready to land.

This seems fine to me, no reason it cannot live in ASTContext if it makes 
future code easier.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118223

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


[PATCH] D117864: [clangd] Enable hover on character literal.

2022-01-26 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

friendly ping, I think it would be nice to get it in before 14 release.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117864

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


[PATCH] D118245: [clang][DeclPrinter] Fix printing for noexcept expressions

2022-01-26 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: kbobyrev.
Herald added a subscriber: usaxena95.
kadircet requested review of this revision.
Herald added subscribers: cfe-commits, ilya-biryukov.
Herald added a project: clang.

We are already building into the final result, no need to append it
again.

Fixes https://github.com/clangd/vscode-clangd/issues/290.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118245

Files:
  clang/lib/AST/DeclPrinter.cpp
  clang/unittests/AST/DeclPrinterTest.cpp


Index: clang/unittests/AST/DeclPrinterTest.cpp
===
--- clang/unittests/AST/DeclPrinterTest.cpp
+++ clang/unittests/AST/DeclPrinterTest.cpp
@@ -909,8 +909,7 @@
 "  void A(int a) noexcept(true);"
 "};",
 "A",
-"void A(int a) noexcept(trueA(int a) noexcept(true)"));
-// WRONG; Should be: "void A(int a) noexcept(true);"
+"void A(int a) noexcept(true)"));
 }
 
 TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification6) {
@@ -919,8 +918,7 @@
 "  void A(int a) noexcept(1 < 2);"
 "};",
 "A",
-"void A(int a) noexcept(1 < 2A(int a) noexcept(1 < 2)"));
-// WRONG; Should be: "void A(int a) noexcept(1 < 2);"
+"void A(int a) noexcept(1 < 2)"));
 }
 
 TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification7) {
@@ -930,8 +928,7 @@
 "  void A(int a) noexcept(N < 2);"
 "};",
 "A",
-"void A(int a) noexcept(N < 2A(int a) noexcept(N < 2)"));
-// WRONG; Should be: "void A(int a) noexcept(N < 2);"
+"void A(int a) noexcept(N < 2)"));
 }
 
 TEST(DeclPrinter, TestVarDecl1) {
Index: clang/lib/AST/DeclPrinter.cpp
===
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -731,7 +731,6 @@
 FT->getNoexceptExpr()->printPretty(EOut, nullptr, SubPolicy,
Indentation, "\n", &Context);
 EOut.flush();
-Proto += EOut.str();
 Proto += ")";
   }
 }


Index: clang/unittests/AST/DeclPrinterTest.cpp
===
--- clang/unittests/AST/DeclPrinterTest.cpp
+++ clang/unittests/AST/DeclPrinterTest.cpp
@@ -909,8 +909,7 @@
 "  void A(int a) noexcept(true);"
 "};",
 "A",
-"void A(int a) noexcept(trueA(int a) noexcept(true)"));
-// WRONG; Should be: "void A(int a) noexcept(true);"
+"void A(int a) noexcept(true)"));
 }
 
 TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification6) {
@@ -919,8 +918,7 @@
 "  void A(int a) noexcept(1 < 2);"
 "};",
 "A",
-"void A(int a) noexcept(1 < 2A(int a) noexcept(1 < 2)"));
-// WRONG; Should be: "void A(int a) noexcept(1 < 2);"
+"void A(int a) noexcept(1 < 2)"));
 }
 
 TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification7) {
@@ -930,8 +928,7 @@
 "  void A(int a) noexcept(N < 2);"
 "};",
 "A",
-"void A(int a) noexcept(N < 2A(int a) noexcept(N < 2)"));
-// WRONG; Should be: "void A(int a) noexcept(N < 2);"
+"void A(int a) noexcept(N < 2)"));
 }
 
 TEST(DeclPrinter, TestVarDecl1) {
Index: clang/lib/AST/DeclPrinter.cpp
===
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -731,7 +731,6 @@
 FT->getNoexceptExpr()->printPretty(EOut, nullptr, SubPolicy,
Indentation, "\n", &Context);
 EOut.flush();
-Proto += EOut.str();
 Proto += ")";
   }
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D118104: Make run-clang-tidy.py print the configured checks correctly

2022-01-26 Thread Jesko Appelfeller via Phabricator via cfe-commits
JesApp updated this revision to Diff 403244.
JesApp added a comment.

As requested by @carlosgalvezp, this update uses the get_tidy_invocation 
function, rather than building it's own test invocation.

I chose to pass all arguments of the script, in case any of them ever have an 
impact on what is being printed. The exception is the tmpdir argument, since 
this directory would get created even if the test invocation then failed.


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

https://reviews.llvm.org/D118104

Files:
  clang-tools-extra/clang-tidy/tool/run-clang-tidy.py


Index: clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
===
--- clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
+++ clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
@@ -254,14 +254,12 @@
 build_path = find_compilation_database(db_path)
 
   try:
-invocation = [args.clang_tidy_binary, '-list-checks']
-if args.allow_enabling_alpha_checkers:
-  invocation.append('-allow-enabling-analyzer-alpha-checkers')
-invocation.append('-p=' + build_path)
-if args.checks:
-  invocation.append('-checks=' + args.checks)
-if args.config:
-  invocation.append('-config=' + args.config)
+invocation = get_tidy_invocation("", args.clang_tidy_binary, args.checks,
+ None, build_path, args.header_filter,
+ args.allow_enabling_alpha_checkers,
+ args.extra_arg, args.extra_arg_before,
+ args.quiet, args.config, args.line_filter)
+invocation.append('-list-checks')
 invocation.append('-')
 if args.quiet:
   # Even with -quiet we still want to check if we can call clang-tidy.


Index: clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
===
--- clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
+++ clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
@@ -254,14 +254,12 @@
 build_path = find_compilation_database(db_path)
 
   try:
-invocation = [args.clang_tidy_binary, '-list-checks']
-if args.allow_enabling_alpha_checkers:
-  invocation.append('-allow-enabling-analyzer-alpha-checkers')
-invocation.append('-p=' + build_path)
-if args.checks:
-  invocation.append('-checks=' + args.checks)
-if args.config:
-  invocation.append('-config=' + args.config)
+invocation = get_tidy_invocation("", args.clang_tidy_binary, args.checks,
+ None, build_path, args.header_filter,
+ args.allow_enabling_alpha_checkers,
+ args.extra_arg, args.extra_arg_before,
+ args.quiet, args.config, args.line_filter)
+invocation.append('-list-checks')
 invocation.append('-')
 if args.quiet:
   # Even with -quiet we still want to check if we can call clang-tidy.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D118224: [clang-tidy] bugprone-signal-handler improvements: display call chain

2022-01-26 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added inline comments.



Comment at: clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp:199-200
+const FunctionDecl *HandlerDecl, const Expr *HandlerRef) {
+  int CallLevel = Itr.getPathLength() - 2;
+  const CallGraphNode *Caller = Itr.getPath(CallLevel + 1), *Callee = nullptr;
+  while (CallLevel >= 0) {

aaron.ballman wrote:
> Do we have to worry about `CallLevel + 1` being negative here? (Is there a 
> need for an assert?)
Really yes, but here is no assert because it is on line 161 and the function is 
called only there. A `df_iterator` path contains the start and end node, and 
there should be at least one function if we have any report do show, the path 
length should be at least 1 (make assert for that?). (Later there could be 
cases when the function is called with path length 1.)



Comment at: clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp:207-208
+ DiagnosticIDs::Note)
+<< cast(Callee->getDecl())
+<< cast(Caller->getDecl());
+--CallLevel;

aaron.ballman wrote:
> Do we have to worry about call expressions for which we cannot find the 
> declaration (like a call through a function pointer)? (Should we add some 
> test coverage involving a call stack with a call through a function pointer?)
A declaration should always be there in the `CallGraphNode`, probably not a 
definition. The call graph does not insert nodes for function pointer calls.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118224

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


[PATCH] D118245: [clang][DeclPrinter] Fix printing for noexcept expressions

2022-01-26 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev accepted this revision.
kbobyrev added a comment.
This revision is now accepted and ready to land.

LG, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118245

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


[PATCH] D117864: [clangd] Enable hover on character literal.

2022-01-26 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added a comment.
This revision is now accepted and ready to land.

thanks, lgtm!




Comment at: clang-tools-extra/clangd/unittests/HoverTests.cpp:1254
+   [](HoverInfo &HI) {
+ HI.Name = "expression", HI.Type = "char";
+ HI.Value = "65 (0x41)";

s/,/;


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117864

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


[PATCH] D116387: [CodeCompletion][clangd] Clean __uglified parameter names in completion & hover

2022-01-26 Thread Sam McCall via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG33c3ef2fbeec: [CodeCompletion][clangd] Clean __uglified 
parameter names in completion & hover (authored by sammccall).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116387

Files:
  clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
  clang/include/clang/AST/PrettyPrinter.h
  clang/include/clang/Basic/IdentifierTable.h
  clang/lib/AST/DeclPrinter.cpp
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/AST/TemplateName.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Basic/IdentifierTable.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/CodeCompletion/deuglify.cpp
  clang/unittests/AST/DeclPrinterTest.cpp
  clang/unittests/AST/StmtPrinterTest.cpp
  clang/unittests/AST/TypePrinterTest.cpp

Index: clang/unittests/AST/TypePrinterTest.cpp
===
--- clang/unittests/AST/TypePrinterTest.cpp
+++ clang/unittests/AST/TypePrinterTest.cpp
@@ -62,4 +62,21 @@
   ASSERT_TRUE(PrintedTypeMatches(
   Code, {}, Matcher, "const N::Type &",
   [](PrintingPolicy &Policy) { Policy.FullyQualifiedName = true; }));
-}
\ No newline at end of file
+}
+
+TEST(TypePrinter, ParamsUglified) {
+  llvm::StringLiteral Code = R"cpp(
+template  class __f>
+const __f<_Tp&> *A = nullptr;
+  )cpp";
+  auto Clean = [](PrintingPolicy &Policy) {
+Policy.CleanUglifiedParameters = true;
+  };
+
+  ASSERT_TRUE(PrintedTypeMatches(Code, {},
+ varDecl(hasType(qualType().bind("id"))),
+ "const __f<_Tp &> *", nullptr));
+  ASSERT_TRUE(PrintedTypeMatches(Code, {},
+ varDecl(hasType(qualType().bind("id"))),
+ "const f *", Clean));
+}
Index: clang/unittests/AST/StmtPrinterTest.cpp
===
--- clang/unittests/AST/StmtPrinterTest.cpp
+++ clang/unittests/AST/StmtPrinterTest.cpp
@@ -263,3 +263,22 @@
 
   [](PrintingPolicy &PP) { PP.TerseOutput = true; }));
 }
+
+TEST(StmtPrinter, ParamsUglified) {
+  llvm::StringLiteral Code = R"cpp(
+template  class _C>
+auto foo(int __j) {
+  return typename _C<_T>::_F(_I, __j);
+}
+  )cpp";
+  auto Clean = [](PrintingPolicy &Policy) {
+Policy.CleanUglifiedParameters = true;
+  };
+
+  ASSERT_TRUE(PrintedStmtCXXMatches(StdVer::CXX14, Code,
+returnStmt().bind("id"),
+"return typename _C<_T>::_F(_I, __j);\n"));
+  ASSERT_TRUE(
+  PrintedStmtCXXMatches(StdVer::CXX14, Code, returnStmt().bind("id"),
+"return typename C::_F(I, j);\n", Clean));
+}
Index: clang/unittests/AST/DeclPrinterTest.cpp
===
--- clang/unittests/AST/DeclPrinterTest.cpp
+++ clang/unittests/AST/DeclPrinterTest.cpp
@@ -1336,6 +1336,41 @@
   ASSERT_TRUE(PrintedDeclCXX11Matches(Code, "NT2", "int NT2 = 5"));
 }
 
+TEST(DeclPrinter, TestFunctionParamUglified) {
+  llvm::StringLiteral Code = R"cpp(
+class __c;
+void _A(__c *__param);
+  )cpp";
+  auto Clean = [](PrintingPolicy &Policy) {
+Policy.CleanUglifiedParameters = true;
+  };
+
+  ASSERT_TRUE(PrintedDeclCXX17Matches(Code, namedDecl(hasName("_A")).bind("id"),
+  "void _A(__c *__param)"));
+  ASSERT_TRUE(PrintedDeclCXX17Matches(Code, namedDecl(hasName("_A")).bind("id"),
+  "void _A(__c *param)", Clean));
+}
+
+TEST(DeclPrinter, TestTemplateParamUglified) {
+  llvm::StringLiteral Code = R"cpp(
+template  class _Container>
+struct _A{};
+  )cpp";
+  auto Clean = [](PrintingPolicy &Policy) {
+Policy.CleanUglifiedParameters = true;
+  };
+
+  ASSERT_TRUE(PrintedDeclCXX17Matches(
+  Code, classTemplateDecl(hasName("_A")).bind("id"),
+  "template  class _Container> "
+  "struct _A {}"));
+  ASSERT_TRUE(PrintedDeclCXX17Matches(
+  Code, classTemplateDecl(hasName("_A")).bind("id"),
+  "template  class Container> "
+  "struct _A {}",
+  Clean));
+}
+
 TEST(DeclPrinter, TestStaticAssert1) {
   ASSERT_TRUE(PrintedDeclCXX17Matches("static_assert(true);",
   staticAssertDecl().bind("id"),
Index: clang/test/CodeCompletion/deuglify.cpp
===
--- /dev/null
+++ clang/test/CodeCompletion/deuglify.cpp
@@ -0,0 +1,25 @@
+// Fake standard library with uglified names.
+// Parameters (including template params) get ugliness stripped.
+namespace std {
+
+template 
+class __vector_base {};
+
+template 
+class vector : private __vector_base<_Tp> {
+public:
+  _Tp &at(unsigned __index) const;
+  int __stays_ugly();
+};
+
+} // namespac

[clang] 33c3ef2 - [CodeCompletion][clangd] Clean __uglified parameter names in completion & hover

2022-01-26 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2022-01-26T15:51:17+01:00
New Revision: 33c3ef2fbeec4ede5fc303b09cdca99ae2c0522a

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

LOG: [CodeCompletion][clangd] Clean __uglified parameter names in completion & 
hover

Underscore-uglified identifiers are used in standard library implementations to
guard against collisions with macros, and they hurt readability considerably.
(Consider `push_back(Tp_ &&__value)` vs `push_back(Tp value)`.
When we're describing an interface, the exact names of parameters are not
critical so we can drop these prefixes.

This patch adds a new PrintingPolicy flag that can applies this stripping
when recursively printing pieces of AST.
We set it in code completion/signature help, and in clangd's hover display.
All three features also do a bit of manual poking at names, so fix up those too.

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

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

Added: 
clang/test/CodeCompletion/deuglify.cpp

Modified: 
clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
clang/include/clang/AST/PrettyPrinter.h
clang/include/clang/Basic/IdentifierTable.h
clang/lib/AST/DeclPrinter.cpp
clang/lib/AST/StmtPrinter.cpp
clang/lib/AST/TemplateName.cpp
clang/lib/AST/TypePrinter.cpp
clang/lib/Basic/IdentifierTable.cpp
clang/lib/Sema/SemaCodeComplete.cpp
clang/unittests/AST/DeclPrinterTest.cpp
clang/unittests/AST/StmtPrinterTest.cpp
clang/unittests/AST/TypePrinterTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp 
b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
index 24cd8b7313bd3..a21c085299b2f 100644
--- a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -1457,8 +1457,8 @@ TEST_F(SymbolCollectorTest, CanonicalSTLHeader) {
   namespace std {
 class string {};
 // Move overloads have special handling.
-template  T&& move(T&&);
-template  O move(I, I, O);
+template  T&& move(_T&& __value);
+template  _O move(_I, _I, _O);
   }
   )cpp",
   /*Main=*/"");
@@ -1468,7 +1468,8 @@ TEST_F(SymbolCollectorTest, CanonicalSTLHeader) {
   QName("std"),
   AllOf(QName("std::string"), DeclURI(TestHeaderURI),
 IncludeHeader("")),
-  AllOf(Labeled("move(T &&)"), IncludeHeader("")),
+  // Parameter names are demangled.
+  AllOf(Labeled("move(T &&value)"), IncludeHeader("")),
   AllOf(Labeled("move(I, I, O)"), IncludeHeader("";
 }
 

diff  --git a/clang/include/clang/AST/PrettyPrinter.h 
b/clang/include/clang/AST/PrettyPrinter.h
index 01dc8e0002703..fd40328d8dcf7 100644
--- a/clang/include/clang/AST/PrettyPrinter.h
+++ b/clang/include/clang/AST/PrettyPrinter.h
@@ -73,7 +73,8 @@ struct PrintingPolicy {
 MSVCFormatting(false), ConstantsAsWritten(false),
 SuppressImplicitBase(false), FullyQualifiedName(false),
 PrintCanonicalTypes(false), PrintInjectedClassNameWithArguments(true),
-UsePreferredNames(true), AlwaysIncludeTypeForTemplateArgument(false) {}
+UsePreferredNames(true), AlwaysIncludeTypeForTemplateArgument(false),
+CleanUglifiedParameters(false) {}
 
   /// Adjust this printing policy for cases where it's known that we're
   /// printing C++ code (for instance, if AST dumping reaches a C++-only
@@ -280,6 +281,11 @@ struct PrintingPolicy {
   /// parameters.
   unsigned AlwaysIncludeTypeForTemplateArgument : 1;
 
+  /// Whether to strip underscores when printing reserved parameter names.
+  /// e.g. std::vector becomes std::vector.
+  /// This only affects parameter names, and so describes a compatible API.
+  unsigned CleanUglifiedParameters : 1;
+
   /// Callbacks to use to allow the behavior of printing to be customized.
   const PrintingCallbacks *Callbacks = nullptr;
 };

diff  --git a/clang/include/clang/Basic/IdentifierTable.h 
b/clang/include/clang/Basic/IdentifierTable.h
index 19c967efcc424..aaf1297c1a648 100644
--- a/clang/include/clang/Basic/IdentifierTable.h
+++ b/clang/include/clang/Basic/IdentifierTable.h
@@ -458,6 +458,10 @@ class alignas(IdentifierInfoAlignment) IdentifierInfo {
   /// 7.1.3, C++ [lib.global.names]).
   ReservedIdentifierStatus isReserved(const LangOptions &LangOpts) const;
 
+  /// If the identifier is an "uglified" reserved name, return a cleaned form.
+  /// e.g. _Foo => Foo. Otherwise, just returns the name.
+  StringRef deuglifiedName() const;
+
   /// Provide less than operator for lexicographical sorting.
   bool operator<(const IdentifierInfo &RHS) const {
 return getName() < RHS.getName();

diff  --git a/clang/

[clang] f720272 - [clang][lex] Include tracking: simplify and move to preprocessor

2022-01-26 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2022-01-26T15:56:26+01:00
New Revision: f7202723304461c4f94399b906333d6ede85579a

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

LOG: [clang][lex] Include tracking: simplify and move to preprocessor

This patch replaces the exact include count of each file in `HeaderFileInfo` 
with a set of included files in `Preprocessor`.

The number of includes isn't a property of a header file but rather a 
preprocessor state. The exact number of includes is not used anywhere except 
statistic tracking.

Reviewed By: vsapsai

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

Added: 


Modified: 
clang/include/clang/Lex/HeaderSearch.h
clang/include/clang/Lex/Preprocessor.h
clang/include/clang/Serialization/ASTBitCodes.h
clang/include/clang/Serialization/ASTReader.h
clang/include/clang/Serialization/ASTWriter.h
clang/lib/Lex/HeaderSearch.cpp
clang/lib/Lex/PPDirectives.cpp
clang/lib/Lex/Preprocessor.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp

Removed: 




diff  --git a/clang/include/clang/Lex/HeaderSearch.h 
b/clang/include/clang/Lex/HeaderSearch.h
index 9b9d28433c080..74768717470bf 100644
--- a/clang/include/clang/Lex/HeaderSearch.h
+++ b/clang/include/clang/Lex/HeaderSearch.h
@@ -57,6 +57,8 @@ class TargetInfo;
 /// The preprocessor keeps track of this information for each
 /// file that is \#included.
 struct HeaderFileInfo {
+  // TODO: Whether the file was imported is not a property of the file itself.
+  // It's a preprocessor state, move it there.
   /// True if this is a \#import'd file.
   unsigned isImport : 1;
 
@@ -95,9 +97,6 @@ struct HeaderFileInfo {
   /// Whether this file has been looked up as a header.
   unsigned IsValid : 1;
 
-  /// The number of times the file has been included already.
-  unsigned short NumIncludes = 0;
-
   /// The ID number of the controlling macro.
   ///
   /// This ID number will be non-zero when there is a controlling
@@ -469,12 +468,6 @@ class HeaderSearch {
 ModuleMap::ModuleHeaderRole Role,
 bool isCompilingModuleHeader);
 
-  /// Increment the count for the number of times the specified
-  /// FileEntry has been entered.
-  void IncrementIncludeCount(const FileEntry *File) {
-++getFileInfo(File).NumIncludes;
-  }
-
   /// Mark the specified file as having a controlling macro.
   ///
   /// This is used by the multiple-include optimization to eliminate

diff  --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index c62bf0c4ceb6f..e567f6391531d 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -450,6 +450,8 @@ class Preprocessor {
   ElseLoc(ElseLoc) {}
   };
 
+  using IncludedFilesSet = llvm::DenseSet;
+
 private:
   friend class ASTReader;
   friend class MacroArgs;
@@ -765,6 +767,9 @@ class Preprocessor {
   /// in a submodule.
   SubmoduleState *CurSubmoduleState;
 
+  /// The files that have been included.
+  IncludedFilesSet IncludedFiles;
+
   /// The set of known macros exported from modules.
   llvm::FoldingSet ModuleMacros;
 
@@ -1224,6 +1229,22 @@ class Preprocessor {
 
   /// \}
 
+  /// Mark the file as included.
+  /// Returns true if this is the first time the file was included.
+  bool markIncluded(const FileEntry *File) {
+HeaderInfo.getFileInfo(File);
+return IncludedFiles.insert(File).second;
+  }
+
+  /// Return true if this header has already been included.
+  bool alreadyIncluded(const FileEntry *File) const {
+return IncludedFiles.count(File);
+  }
+
+  /// Get the set of included files.
+  IncludedFilesSet &getIncludedFiles() { return IncludedFiles; }
+  const IncludedFilesSet &getIncludedFiles() const { return IncludedFiles; }
+
   /// Return the name of the macro defined before \p Loc that has
   /// spelling \p Tokens.  If there are multiple macros with same spelling,
   /// return the last one defined.

diff  --git a/clang/include/clang/Serialization/ASTBitCodes.h 
b/clang/include/clang/Serialization/ASTBitCodes.h
index 341da5bd1d62e..f98e173b158c1 100644
--- a/clang/include/clang/Serialization/ASTBitCodes.h
+++ b/clang/include/clang/Serialization/ASTBitCodes.h
@@ -695,6 +695,9 @@ enum ASTRecordTypes {
 
   /// Record code for \#pragma float_control options.
   FLOAT_CONTROL_PRAGMA_OPTIONS = 65,
+
+  /// Record code for included files.
+  PP_INCLUDED_FILES = 66,
 };
 
 /// Record types used within a source manager block.

diff  --git a/clang/include/clang/Serialization/ASTReader.h 
b/clang/include/clang/Serialization/ASTReader.h
index a36c8ba20a10a..d46a6c4500f4e 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang

[PATCH] D114095: [clang][lex] Include tracking: simplify and move to preprocessor

2022-01-26 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf72027233044: [clang][lex] Include tracking: simplify and 
move to preprocessor (authored by jansvoboda11).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114095

Files:
  clang/include/clang/Lex/HeaderSearch.h
  clang/include/clang/Lex/Preprocessor.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/include/clang/Serialization/ASTReader.h
  clang/include/clang/Serialization/ASTWriter.h
  clang/lib/Lex/HeaderSearch.cpp
  clang/lib/Lex/PPDirectives.cpp
  clang/lib/Lex/Preprocessor.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp

Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -862,6 +862,7 @@
   RECORD(CUDA_PRAGMA_FORCE_HOST_DEVICE_DEPTH);
   RECORD(PP_CONDITIONAL_STACK);
   RECORD(DECLS_TO_CHECK_FOR_DEFERRED_DIAGS);
+  RECORD(PP_INCLUDED_FILES);
 
   // SourceManager Block.
   BLOCK(SOURCE_MANAGER_BLOCK);
@@ -1773,7 +1774,7 @@
 std::pair
 EmitKeyDataLength(raw_ostream& Out, key_type_ref key, data_type_ref Data) {
   unsigned KeyLen = key.Filename.size() + 1 + 8 + 8;
-  unsigned DataLen = 1 + 2 + 4 + 4;
+  unsigned DataLen = 1 + 4 + 4;
   for (auto ModInfo : Data.KnownHeaders)
 if (Writer.getLocalOrImportedSubmoduleID(ModInfo.getModule()))
   DataLen += 4;
@@ -1805,7 +1806,6 @@
   | (Data.HFI.DirInfo << 1)
   | Data.HFI.IndexHeaderMapHeader;
   LE.write(Flags);
-  LE.write(Data.HFI.NumIncludes);
 
   if (!Data.HFI.ControllingMacro)
 LE.write(Data.HFI.ControllingMacroID);
@@ -2254,6 +2254,29 @@
   return false;
 }
 
+void ASTWriter::writeIncludedFiles(raw_ostream &Out, const Preprocessor &PP) {
+  using namespace llvm::support;
+
+  const Preprocessor::IncludedFilesSet &IncludedFiles = PP.getIncludedFiles();
+
+  std::vector IncludedInputFileIDs;
+  IncludedInputFileIDs.reserve(IncludedFiles.size());
+
+  for (const FileEntry *File : IncludedFiles) {
+auto InputFileIt = InputFileIDs.find(File);
+if (InputFileIt == InputFileIDs.end())
+  continue;
+IncludedInputFileIDs.push_back(InputFileIt->second);
+  }
+
+  llvm::sort(IncludedInputFileIDs);
+
+  endian::Writer LE(Out, little);
+  LE.write(IncludedInputFileIDs.size());
+  for (uint32_t ID : IncludedInputFileIDs)
+LE.write(ID);
+}
+
 /// Writes the block containing the serialized form of the
 /// preprocessor.
 void ASTWriter::WritePreprocessor(const Preprocessor &PP, bool IsModule) {
@@ -2462,6 +2485,20 @@
MacroOffsetsBase - ASTBlockStartOffset};
 Stream.EmitRecordWithBlob(MacroOffsetAbbrev, Record, bytes(MacroOffsets));
   }
+
+  {
+auto Abbrev = std::make_shared();
+Abbrev->Add(BitCodeAbbrevOp(PP_INCLUDED_FILES));
+Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
+unsigned IncludedFilesAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
+
+SmallString<2048> Buffer;
+raw_svector_ostream Out(Buffer);
+writeIncludedFiles(Out, PP);
+RecordData::value_type Record[] = {PP_INCLUDED_FILES};
+Stream.EmitRecordWithBlob(IncludedFilesAbbrev, Record, Buffer.data(),
+  Buffer.size());
+  }
 }
 
 void ASTWriter::WritePreprocessorDetail(PreprocessingRecord &PPRec,
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -1887,10 +1887,6 @@
   HFI.isPragmaOnce |= (Flags >> 4) & 0x01;
   HFI.DirInfo = (Flags >> 1) & 0x07;
   HFI.IndexHeaderMapHeader = Flags & 0x01;
-  // FIXME: Find a better way to handle this. Maybe just store a
-  // "has been included" flag?
-  HFI.NumIncludes = std::max(endian::readNext(d),
- HFI.NumIncludes);
   HFI.ControllingMacroID = Reader.getGlobalIdentifierID(
   M, endian::readNext(d));
   if (unsigned FrameworkOffset =
@@ -2962,6 +2958,22 @@
   }
 }
 
+void ASTReader::readIncludedFiles(ModuleFile &F, StringRef Blob,
+  Preprocessor &PP) {
+  using namespace llvm::support;
+
+  const unsigned char *D = (const unsigned char *)Blob.data();
+  unsigned FileCount = endian::readNext(D);
+
+  for (unsigned I = 0; I < FileCount; ++I) {
+size_t ID = endian::readNext(D);
+InputFileInfo IFI = readInputFileInfo(F, ID);
+if (llvm::ErrorOr File =
+PP.getFileManager().getFile(IFI.Filename))
+  PP.getIncludedFiles().insert(*File);
+  }
+}
+
 llvm::Error ASTReader::ReadASTBlock(ModuleFile &F,
 unsigned ClientLoadCapabilities) {
   BitstreamC

[PATCH] D118247: [clang] NFC: Use flush() idiomatically

2022-01-26 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev created this revision.
kbobyrev added a reviewer: kadircet.
kbobyrev requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Using both `raw_ostream::flush()` and `raw_ostream::str()` consecutively is
redundant. The alternatives are:

- Use `raw_ostream::str()` without `raw_ostream::flush()`
- Use `raw_ostream::flush()` and then use the destination for `raw_ostream` 
writer

The latter is more idiomatic, so the fix resolves this particular case in its
favor.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118247

Files:
  clang/lib/AST/DeclPrinter.cpp


Index: clang/lib/AST/DeclPrinter.cpp
===
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -588,7 +588,7 @@
   }
   EOut << " ";
   EOut.flush();
-  Out << EOut.str();
+  Out << Proto;
 }
 
 void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) {


Index: clang/lib/AST/DeclPrinter.cpp
===
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -588,7 +588,7 @@
   }
   EOut << " ";
   EOut.flush();
-  Out << EOut.str();
+  Out << Proto;
 }
 
 void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D117939: [clang-tidy] Add more documentation about check development

2022-01-26 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang-tools-extra/docs/clang-tidy/Contributing.rst:362
+Private custom matchers are a good example of auxiliary support code for your 
check
+that is best tested with a unit test.  It will be easier to test your matchers 
or
+other support classes by writing a unit test than by writing a ``FileCheck`` 
integration

LegalizeAdulthood wrote:
> If I change the wording from "is best tested with a unit test" to "can be 
> tested with a unit test",
> would that alleviate the concern?  I want to encourage appropriate testing 
> and unit testing
> complex helper code is better than integration testing helper code.
> 
> I find it easier to have confidence in private matchers if they are unit 
> tested and I've recently
> had a few situations where I had to write relatively complex helper functions 
> to analyze raw
> text that I felt would have been better tested with a unit test than an 
> integration test.
> If I change the wording from "is best tested with a unit test" to "can be 
> tested with a unit test", would that alleviate the concern?

I largely addresses mine -- saying it can be done is great, saying it should be 
done is what gave me pause.



Comment at: clang-tools-extra/docs/clang-tidy/Contributing.rst:389-390
+- Test your check under both Windows and Linux environments.
+- Watch out for high false positive rates; ideally there should be none, but a
+  small number may be tolerable.  High false positive rates prevent adoption.
+- Consider configurable options for your check to deal with false positives.

LegalizeAdulthood wrote:
> ymandel wrote:
> > Is it worth giving a rule-of-thumb? Personally I'd go with < 10%, all 
> > things being equal.  A check for a serious bug may reasonably have a higher 
> > false positive rate, and trivial checks might not justify *any* false 
> > positives. But, if neither of these apply, I'd recommend 10% as the default.
> I'm OK with rule-of-thumb 10% advice.
FWIW, I think 10% is pretty arbitrary and I'd rather not see us try to nail it 
down to a concrete number. In practical terms, it really depends on the check.

Also, clang-tidy is where we put things with a "high" false positive rate 
already, so this statement has implications on what an acceptable false 
positive rate is for Clang or the static analyzer.

How about something along these lines:
```
- Watch out for high false positive rates. Ideally, a check would have no false 
positives, but given that matching against an AST is not control- or data 
flow-sensitive, a number of false positives are expected. The higher the false 
positive rate, the less likely the check will be adopted in practice. 
Mechanisms should be put in place to help the user manage false positives.
- There are two primary mechanisms for managing false positives: supporting a 
code pattern which allows the programmer to silence the diagnostic in an ad hoc 
manner and check configuration options to control the behavior of the check.
- Consider supporting a code pattern to allow the programmer to silence the 
diagnostic whenever such a code pattern can clearly express the programmer's 
intent. For example, allowing an explicit cast to `void` to silence an unused 
variable diagnostic.
- Consider adding check configuration options to allow the user to opt into 
more aggressive checking behavior without burdening users for the common 
high-confidence cases.
```
(or something along those lines). The basic idea I have there is: false 
positives are expected, try to keep them to a minimum, and here are the two 
most common ways code reviewers will ask you to handle false positives when 
they're a concern.


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

https://reviews.llvm.org/D117939

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


[clang] b777d35 - [clang][DeclPrinter] Fix printing for noexcept expressions

2022-01-26 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2022-01-26T16:04:24+01:00
New Revision: b777d354f6703afd58b1803fdfb6d43a607d8fd6

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

LOG: [clang][DeclPrinter] Fix printing for noexcept expressions

We are already building into the final result, no need to append it
again.

Fixes https://github.com/clangd/vscode-clangd/issues/290.

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

Added: 


Modified: 
clang/lib/AST/DeclPrinter.cpp
clang/unittests/AST/DeclPrinterTest.cpp

Removed: 




diff  --git a/clang/lib/AST/DeclPrinter.cpp b/clang/lib/AST/DeclPrinter.cpp
index 698b1c3ffd348..715da7e0d90c5 100644
--- a/clang/lib/AST/DeclPrinter.cpp
+++ b/clang/lib/AST/DeclPrinter.cpp
@@ -731,7 +731,6 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) {
 FT->getNoexceptExpr()->printPretty(EOut, nullptr, SubPolicy,
Indentation, "\n", &Context);
 EOut.flush();
-Proto += EOut.str();
 Proto += ")";
   }
 }

diff  --git a/clang/unittests/AST/DeclPrinterTest.cpp 
b/clang/unittests/AST/DeclPrinterTest.cpp
index 0b579565f5b4a..c2d7d78738f96 100644
--- a/clang/unittests/AST/DeclPrinterTest.cpp
+++ b/clang/unittests/AST/DeclPrinterTest.cpp
@@ -909,8 +909,7 @@ TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification5) 
{
 "  void A(int a) noexcept(true);"
 "};",
 "A",
-"void A(int a) noexcept(trueA(int a) noexcept(true)"));
-// WRONG; Should be: "void A(int a) noexcept(true);"
+"void A(int a) noexcept(true)"));
 }
 
 TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification6) {
@@ -919,8 +918,7 @@ TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification6) 
{
 "  void A(int a) noexcept(1 < 2);"
 "};",
 "A",
-"void A(int a) noexcept(1 < 2A(int a) noexcept(1 < 2)"));
-// WRONG; Should be: "void A(int a) noexcept(1 < 2);"
+"void A(int a) noexcept(1 < 2)"));
 }
 
 TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification7) {
@@ -930,8 +928,7 @@ TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification7) 
{
 "  void A(int a) noexcept(N < 2);"
 "};",
 "A",
-"void A(int a) noexcept(N < 2A(int a) noexcept(N < 2)"));
-// WRONG; Should be: "void A(int a) noexcept(N < 2);"
+"void A(int a) noexcept(N < 2)"));
 }
 
 TEST(DeclPrinter, TestVarDecl1) {



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


[PATCH] D118245: [clang][DeclPrinter] Fix printing for noexcept expressions

2022-01-26 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb777d354f670: [clang][DeclPrinter] Fix printing for noexcept 
expressions (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118245

Files:
  clang/lib/AST/DeclPrinter.cpp
  clang/unittests/AST/DeclPrinterTest.cpp


Index: clang/unittests/AST/DeclPrinterTest.cpp
===
--- clang/unittests/AST/DeclPrinterTest.cpp
+++ clang/unittests/AST/DeclPrinterTest.cpp
@@ -909,8 +909,7 @@
 "  void A(int a) noexcept(true);"
 "};",
 "A",
-"void A(int a) noexcept(trueA(int a) noexcept(true)"));
-// WRONG; Should be: "void A(int a) noexcept(true);"
+"void A(int a) noexcept(true)"));
 }
 
 TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification6) {
@@ -919,8 +918,7 @@
 "  void A(int a) noexcept(1 < 2);"
 "};",
 "A",
-"void A(int a) noexcept(1 < 2A(int a) noexcept(1 < 2)"));
-// WRONG; Should be: "void A(int a) noexcept(1 < 2);"
+"void A(int a) noexcept(1 < 2)"));
 }
 
 TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification7) {
@@ -930,8 +928,7 @@
 "  void A(int a) noexcept(N < 2);"
 "};",
 "A",
-"void A(int a) noexcept(N < 2A(int a) noexcept(N < 2)"));
-// WRONG; Should be: "void A(int a) noexcept(N < 2);"
+"void A(int a) noexcept(N < 2)"));
 }
 
 TEST(DeclPrinter, TestVarDecl1) {
Index: clang/lib/AST/DeclPrinter.cpp
===
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -731,7 +731,6 @@
 FT->getNoexceptExpr()->printPretty(EOut, nullptr, SubPolicy,
Indentation, "\n", &Context);
 EOut.flush();
-Proto += EOut.str();
 Proto += ")";
   }
 }


Index: clang/unittests/AST/DeclPrinterTest.cpp
===
--- clang/unittests/AST/DeclPrinterTest.cpp
+++ clang/unittests/AST/DeclPrinterTest.cpp
@@ -909,8 +909,7 @@
 "  void A(int a) noexcept(true);"
 "};",
 "A",
-"void A(int a) noexcept(trueA(int a) noexcept(true)"));
-// WRONG; Should be: "void A(int a) noexcept(true);"
+"void A(int a) noexcept(true)"));
 }
 
 TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification6) {
@@ -919,8 +918,7 @@
 "  void A(int a) noexcept(1 < 2);"
 "};",
 "A",
-"void A(int a) noexcept(1 < 2A(int a) noexcept(1 < 2)"));
-// WRONG; Should be: "void A(int a) noexcept(1 < 2);"
+"void A(int a) noexcept(1 < 2)"));
 }
 
 TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification7) {
@@ -930,8 +928,7 @@
 "  void A(int a) noexcept(N < 2);"
 "};",
 "A",
-"void A(int a) noexcept(N < 2A(int a) noexcept(N < 2)"));
-// WRONG; Should be: "void A(int a) noexcept(N < 2);"
+"void A(int a) noexcept(N < 2)"));
 }
 
 TEST(DeclPrinter, TestVarDecl1) {
Index: clang/lib/AST/DeclPrinter.cpp
===
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -731,7 +731,6 @@
 FT->getNoexceptExpr()->printPretty(EOut, nullptr, SubPolicy,
Indentation, "\n", &Context);
 EOut.flush();
-Proto += EOut.str();
 Proto += ")";
   }
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D118224: [clang-tidy] bugprone-signal-handler improvements: display call chain

2022-01-26 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp:199-200
+const FunctionDecl *HandlerDecl, const Expr *HandlerRef) {
+  int CallLevel = Itr.getPathLength() - 2;
+  const CallGraphNode *Caller = Itr.getPath(CallLevel + 1), *Callee = nullptr;
+  while (CallLevel >= 0) {

balazske wrote:
> aaron.ballman wrote:
> > Do we have to worry about `CallLevel + 1` being negative here? (Is there a 
> > need for an assert?)
> Really yes, but here is no assert because it is on line 161 and the function 
> is called only there. A `df_iterator` path contains the start and end node, 
> and there should be at least one function if we have any report do show, the 
> path length should be at least 1 (make assert for that?). (Later there could 
> be cases when the function is called with path length 1.)
Thanks for the explanation -- an assert that the path has at least 1 element 
wouldn't be awful, but also doesn't seem like something we'd get a lot of value 
from here. It's up to you if you want to add an assert or not.



Comment at: clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp:207-208
+ DiagnosticIDs::Note)
+<< cast(Callee->getDecl())
+<< cast(Caller->getDecl());
+--CallLevel;

balazske wrote:
> aaron.ballman wrote:
> > Do we have to worry about call expressions for which we cannot find the 
> > declaration (like a call through a function pointer)? (Should we add some 
> > test coverage involving a call stack with a call through a function 
> > pointer?)
> A declaration should always be there in the `CallGraphNode`, probably not a 
> definition. The call graph does not insert nodes for function pointer calls.
Oh! I didn't know the CallGraph didn't model calls through function pointers (I 
had assumed we would model that because there's still a `CallExpr` involved.)

Can you add a test case involving a call stack with a call through a function 
pointer (with comments), just to demonstrate the behavior?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118224

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


[PATCH] D118104: Make run-clang-tidy.py print the configured checks correctly

2022-01-26 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

Looks good to me! A general comment not related to this patch is that the 
`get_tidy_invocation` is very error prone when called like that, since all 
arguments are strings. It would be better to specify the arguments:

  get_tidy_invocation(name="", clang_tidy_binary=args.clang_tidy_binary,...)

I haven't reviewed this file much and I'm quite new as reviewer so perhaps it's 
good that someone else takes another look and agrees with the change.


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

https://reviews.llvm.org/D118104

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


[clang] 93948c5 - [clang-format] Correctly format lambdas with variadic template parameters.

2022-01-26 Thread Marek Kurdej via cfe-commits

Author: Marek Kurdej
Date: 2022-01-26T16:10:52+01:00
New Revision: 93948c5299d7ee446aa707221751a0af2b87c12b

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

LOG: [clang-format] Correctly format lambdas with variadic template parameters.

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

Reviewed By: MyDeveloperDay, owenpan

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

Added: 


Modified: 
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index ff3e791822c47..b0588d92ab001 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -1856,6 +1856,7 @@ bool UnwrappedLineParser::tryToParseLambda() {
 return false;
 
   bool SeenArrow = false;
+  bool InTemplateParameterList = false;
 
   while (FormatTok->isNot(tok::l_brace)) {
 if (FormatTok->isSimpleTypeSpecifier()) {
@@ -1871,6 +1872,14 @@ bool UnwrappedLineParser::tryToParseLambda() {
 case tok::l_square:
   parseSquare();
   break;
+case tok::kw_class:
+case tok::kw_template:
+case tok::kw_typename:
+  assert(FormatTok->Previous);
+  if (FormatTok->Previous->is(tok::less))
+InTemplateParameterList = true;
+  nextToken();
+  break;
 case tok::amp:
 case tok::star:
 case tok::kw_const:
@@ -1880,11 +1889,8 @@ bool UnwrappedLineParser::tryToParseLambda() {
 case tok::identifier:
 case tok::numeric_constant:
 case tok::coloncolon:
-case tok::kw_class:
 case tok::kw_mutable:
 case tok::kw_noexcept:
-case tok::kw_template:
-case tok::kw_typename:
   nextToken();
   break;
 // Specialization of a template with an integer parameter can contain
@@ -1921,7 +1927,7 @@ bool UnwrappedLineParser::tryToParseLambda() {
 case tok::ellipsis:
 case tok::kw_true:
 case tok::kw_false:
-  if (SeenArrow) {
+  if (SeenArrow || InTemplateParameterList) {
 nextToken();
 break;
   }

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index c45869f16ad29..9185de023ccf9 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -20560,6 +20560,36 @@ TEST_F(FormatTest, FormatsLambdas) {
   // Lambdas with explicit template argument lists.
   verifyFormat(
   "auto L = [] class T, class U>(T &&a) {};\n");
+  verifyFormat("auto L = [](T) {\n"
+   "  {\n"
+   "f();\n"
+   "g();\n"
+   "  }\n"
+   "};\n");
+  verifyFormat("auto L = [](T...) {\n"
+   "  {\n"
+   "f();\n"
+   "g();\n"
+   "  }\n"
+   "};\n");
+  verifyFormat("auto L = [](T...) {\n"
+   "  {\n"
+   "f();\n"
+   "g();\n"
+   "  }\n"
+   "};\n");
+  verifyFormat("auto L = [] class T>(T...) {\n"
+   "  {\n"
+   "f();\n"
+   "g();\n"
+   "  }\n"
+   "};\n");
+  verifyFormat("auto L = [](T...) {\n"
+   "  {\n"
+   "f();\n"
+   "g();\n"
+   "  }\n"
+   "};\n");
 
   // Multiple lambdas in the same parentheses change indentation rules. These
   // lambdas are forced to start on new lines.



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


[PATCH] D118220: [clang-format] Correctly format lambdas with variadic template parameters.

2022-01-26 Thread Marek Kurdej via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG93948c5299d7: [clang-format] Correctly format lambdas with 
variadic template parameters. (authored by curdeius).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118220

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -20560,6 +20560,36 @@
   // Lambdas with explicit template argument lists.
   verifyFormat(
   "auto L = [] class T, class U>(T &&a) {};\n");
+  verifyFormat("auto L = [](T) {\n"
+   "  {\n"
+   "f();\n"
+   "g();\n"
+   "  }\n"
+   "};\n");
+  verifyFormat("auto L = [](T...) {\n"
+   "  {\n"
+   "f();\n"
+   "g();\n"
+   "  }\n"
+   "};\n");
+  verifyFormat("auto L = [](T...) {\n"
+   "  {\n"
+   "f();\n"
+   "g();\n"
+   "  }\n"
+   "};\n");
+  verifyFormat("auto L = [] class T>(T...) {\n"
+   "  {\n"
+   "f();\n"
+   "g();\n"
+   "  }\n"
+   "};\n");
+  verifyFormat("auto L = [](T...) {\n"
+   "  {\n"
+   "f();\n"
+   "g();\n"
+   "  }\n"
+   "};\n");
 
   // Multiple lambdas in the same parentheses change indentation rules. These
   // lambdas are forced to start on new lines.
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1856,6 +1856,7 @@
 return false;
 
   bool SeenArrow = false;
+  bool InTemplateParameterList = false;
 
   while (FormatTok->isNot(tok::l_brace)) {
 if (FormatTok->isSimpleTypeSpecifier()) {
@@ -1871,6 +1872,14 @@
 case tok::l_square:
   parseSquare();
   break;
+case tok::kw_class:
+case tok::kw_template:
+case tok::kw_typename:
+  assert(FormatTok->Previous);
+  if (FormatTok->Previous->is(tok::less))
+InTemplateParameterList = true;
+  nextToken();
+  break;
 case tok::amp:
 case tok::star:
 case tok::kw_const:
@@ -1880,11 +1889,8 @@
 case tok::identifier:
 case tok::numeric_constant:
 case tok::coloncolon:
-case tok::kw_class:
 case tok::kw_mutable:
 case tok::kw_noexcept:
-case tok::kw_template:
-case tok::kw_typename:
   nextToken();
   break;
 // Specialization of a template with an integer parameter can contain
@@ -1921,7 +1927,7 @@
 case tok::ellipsis:
 case tok::kw_true:
 case tok::kw_false:
-  if (SeenArrow) {
+  if (SeenArrow || InTemplateParameterList) {
 nextToken();
 break;
   }


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -20560,6 +20560,36 @@
   // Lambdas with explicit template argument lists.
   verifyFormat(
   "auto L = [] class T, class U>(T &&a) {};\n");
+  verifyFormat("auto L = [](T) {\n"
+   "  {\n"
+   "f();\n"
+   "g();\n"
+   "  }\n"
+   "};\n");
+  verifyFormat("auto L = [](T...) {\n"
+   "  {\n"
+   "f();\n"
+   "g();\n"
+   "  }\n"
+   "};\n");
+  verifyFormat("auto L = [](T...) {\n"
+   "  {\n"
+   "f();\n"
+   "g();\n"
+   "  }\n"
+   "};\n");
+  verifyFormat("auto L = [] class T>(T...) {\n"
+   "  {\n"
+   "f();\n"
+   "g();\n"
+   "  }\n"
+   "};\n");
+  verifyFormat("auto L = [](T...) {\n"
+   "  {\n"
+   "f();\n"
+   "g();\n"
+   "  }\n"
+   "};\n");
 
   // Multiple lambdas in the same parentheses change indentation rules. These
   // lambdas are forced to start on new lines.
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1856,6 +1856,7 @@
 return false;
 
   bool SeenArrow = false;
+  bool InTemplateParameterList = false;
 
   while (FormatTok->isNot(tok::l_brace)) {
 if (FormatTok->isSimpleTypeSpecifier()) {
@@ -1871,6 +1872,14 @@
 case tok::l_square:

[PATCH] D118178: [clang][dataflow] Allow clients to disable built-in transfer functions.

2022-01-26 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev accepted this revision.
sgatev added inline comments.
This revision is now accepted and ready to land.



Comment at: 
clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h:44
 class TypeErasedDataflowAnalysis {
+  // Determines whether to apply the built-in transfer functions.
+  bool ApplyBuiltinTransfer;

We use `///` to start a doc comment.



Comment at: 
clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h:45
+  // Determines whether to apply the built-in transfer functions.
+  bool ApplyBuiltinTransfer;
+

Let's add a FIXME to consider removing this if the framework gains support for 
composite analyses.



Comment at: 
clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h:77
+
+  // Determines whether to apply the built-in transfer functions, which model
+  // the heap and stack in the `Environment`.

We use `///` to start a doc comment.



Comment at: 
clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h:79
+  // the heap and stack in the `Environment`.
+  bool applyBuiltinTransfer() { return ApplyBuiltinTransfer; }
 };

Make this member const?



Comment at: clang/unittests/Analysis/FlowSensitive/NoopAnalysis.h:42
 public:
-  NoopAnalysis(ASTContext &Context)
-  : DataflowAnalysis(Context) {}
+  // `ApplyBuiltinTransfer` controls whether to run the built-in transfer
+  // functions that model memory during the analysis.

We use `///` to start a doc comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118178

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


[PATCH] D118104: Make run-clang-tidy.py print the configured checks correctly

2022-01-26 Thread Jesko Appelfeller via Phabricator via cfe-commits
JesApp added a comment.

I'm new to phabricator, buildkite, your whole setup. Any idea why the patch 
fails?


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

https://reviews.llvm.org/D118104

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


[PATCH] D118104: Make run-clang-tidy.py print the configured checks correctly

2022-01-26 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

Perhaps the patch was applied on a too old baseline, could you try rebasing on 
top of latest main?


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

https://reviews.llvm.org/D118104

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


[PATCH] D112915: [clang][modules] Track included files per submodule

2022-01-26 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 403263.
jansvoboda11 added a comment.

Rebase, update unnecessary `auto`, run `clang-format`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112915

Files:
  clang/include/clang/Lex/ExternalPreprocessorSource.h
  clang/include/clang/Lex/Preprocessor.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/include/clang/Serialization/ASTReader.h
  clang/include/clang/Serialization/ASTWriter.h
  clang/include/clang/Serialization/ModuleFile.h
  clang/lib/Basic/Module.cpp
  clang/lib/Lex/PPLexerChange.cpp
  clang/lib/Lex/Preprocessor.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/Modules/import-submodule-visibility.c

Index: clang/test/Modules/import-submodule-visibility.c
===
--- /dev/null
+++ clang/test/Modules/import-submodule-visibility.c
@@ -0,0 +1,99 @@
+// This test checks that imports of headers that appeared in a different submodule than
+// what is imported by the current TU don't affect the compilation.
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+//--- A.framework/Headers/A.h
+#include "Textual.h"
+//--- A.framework/Modules/module.modulemap
+framework module A { header "A.h" }
+
+//--- B.framework/Headers/B1.h
+#include "Textual.h"
+//--- B.framework/Headers/B2.h
+//--- B.framework/Modules/module.modulemap
+framework module B {
+  module B1 { header "B1.h" }
+  module B2 { header "B2.h" }
+}
+
+//--- C/C.h
+#include "Textual.h"
+//--- C/module.modulemap
+module C { header "C.h" }
+
+//--- D/D1.h
+#include "Textual.h"
+//--- D/D2.h
+//--- D/module.modulemap
+module D {
+  module D1 { header "D1.h" }
+  module D2 { header "D2.h" }
+}
+
+//--- E/E1.h
+#include "E2.h"
+//--- E/E2.h
+#include "Textual.h"
+//--- E/module.modulemap
+module E {
+  module E1 { header "E1.h" }
+  module E2 { header "E2.h" }
+}
+
+//--- Textual.h
+#define MACRO_TEXTUAL 1
+
+//--- test.c
+
+#ifdef A
+//
+#endif
+
+#ifdef B
+#import 
+#endif
+
+#ifdef C
+//
+#endif
+
+#ifdef D
+#import "D/D2.h"
+#endif
+
+#ifdef E
+#import "E/E1.h"
+#endif
+
+#import "Textual.h"
+
+static int x = MACRO_TEXTUAL;
+
+// Specifying the PCM file on the command line (without actually importing "A") should not
+// prevent "Textual.h" to be included in the TU.
+//
+// RUN: %clang_cc1 -fmodules -I %t -emit-module %t/A.framework/Modules/module.modulemap -fmodule-name=A -o %t/A.pcm
+// RUN: %clang_cc1 -fmodules -I %t -fsyntax-only %t/test.c -DA -fmodule-file=%t/A.pcm
+
+// Specifying the PCM file on the command line and importing "B2" in the source does not
+// prevent "Textual.h" to be included in the TU.
+//
+// RUN: %clang_cc1 -fmodules -I %t -emit-module %t/B.framework/Modules/module.modulemap -fmodule-name=B -o %t/B.pcm
+// RUN: %clang_cc1 -fmodules -I %t -fsyntax-only %t/test.c -DB -iframework %t -fmodule-file=%t/B.pcm
+
+// Module-only version of the test with framework A.
+//
+// RUN: %clang_cc1 -fmodules -I %t -emit-module %t/C/module.modulemap -fmodule-name=C -o %t/C.pcm
+// RUN: %clang_cc1 -fmodules -I %t -fsyntax-only %t/test.c -DC -fmodule-file=%t/C.pcm
+
+// Module-only version of the test with framework B.
+//
+// RUN: %clang_cc1 -fmodules -I %t -emit-module %t/D/module.modulemap -fmodule-name=D -o %t/D.pcm
+// RUN: %clang_cc1 -fmodules -I %t -fsyntax-only %t/test.c -DD -fmodule-file=%t/D.pcm
+
+// Transitively imported, but not exported.
+//
+// RUN: %clang_cc1 -fmodules -I %t -emit-module %t/E/module.modulemap -fmodule-name=E -o %t/E.pcm
+// RUN: %clang_cc1 -fmodules -I %t -fsyntax-only %t/test.c -DE -fmodule-file=%t/E.pcm
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -2254,15 +2254,14 @@
   return false;
 }
 
-void ASTWriter::writeIncludedFiles(raw_ostream &Out, const Preprocessor &PP) {
+void ASTWriter::writeIncludedFiles(
+raw_ostream &Out, const Preprocessor::IncludedFilesSet &Files) {
   using namespace llvm::support;
 
-  const Preprocessor::IncludedFilesSet &IncludedFiles = PP.getIncludedFiles();
-
   std::vector IncludedInputFileIDs;
-  IncludedInputFileIDs.reserve(IncludedFiles.size());
+  IncludedInputFileIDs.reserve(Files.size());
 
-  for (const FileEntry *File : IncludedFiles) {
+  for (const FileEntry *File : Files) {
 auto InputFileIt = InputFileIDs.find(File);
 if (InputFileIt == InputFileIDs.end())
   continue;
@@ -2486,7 +2485,8 @@
 Stream.EmitRecordWithBlob(MacroOffsetAbbrev, Record, bytes(MacroOffsets));
   }
 
-  {
+  if (const Preprocessor::IncludedFilesSet *Includes =
+  PP.getNullSubmoduleIncludes()) {
 auto Abbrev = std::make_shared();
 Abbrev->Add(BitCodeAbbrevOp(PP_INCLUDED_FILES));
 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
@@ -2494,7 +2494,7 @@
 
 SmallString

[clang] 75c22b3 - [clang][dataflow] Add a transfer function for CXXBoolLiteralExpr

2022-01-26 Thread Stanislav Gatev via cfe-commits

Author: Stanislav Gatev
Date: 2022-01-26T15:33:00Z
New Revision: 75c22b382f2a7b0bb9499215a3d64e146e3f02cc

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

LOG: [clang][dataflow] Add a transfer function for CXXBoolLiteralExpr

This is part of the implementation of the dataflow analysis framework.
See "[RFC] A dataflow analysis framework for Clang AST" on cfe-dev.

Reviewed-by: xazax.hun

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

Added: 


Modified: 
clang/lib/Analysis/FlowSensitive/Transfer.cpp
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Removed: 




diff  --git a/clang/lib/Analysis/FlowSensitive/Transfer.cpp 
b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
index 7c5e063278d78..51a86b727e339 100644
--- a/clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -443,8 +443,11 @@ class TransferVisitor : public 
ConstStmtVisitor {
 // FIXME: Implement array initialization.
   }
 
-  // FIXME: Add support for:
-  // - CXXBoolLiteralExpr
+  void VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *S) {
+auto &Loc = Env.createStorageLocation(*S);
+Env.setStorageLocation(*S, Loc);
+Env.setValue(Loc, Env.getBoolLiteralValue(S->getValue()));
+  }
 
 private:
   Environment &Env;

diff  --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index dc365d5bfe75f..30238a40fec59 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -1970,4 +1970,39 @@ TEST_F(TransferTest, AssignToUnionMember) {
   });
 }
 
+TEST_F(TransferTest, AssignFromBoolLiteral) {
+  std::string Code = R"(
+void target() {
+  bool Foo = true;
+  bool Bar = false;
+  // [[p]]
+}
+  )";
+  runDataflow(
+  Code, [](llvm::ArrayRef<
+   std::pair>>
+   Results,
+   ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
+
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+const auto *FooVal =
+dyn_cast_or_null(Env.getValue(*FooDecl, 
SkipPast::None));
+ASSERT_THAT(FooVal, NotNull());
+
+const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+ASSERT_THAT(BarDecl, NotNull());
+
+const auto *BarVal =
+dyn_cast_or_null(Env.getValue(*BarDecl, 
SkipPast::None));
+ASSERT_THAT(BarVal, NotNull());
+
+EXPECT_EQ(FooVal, &Env.getBoolLiteralValue(true));
+EXPECT_EQ(BarVal, &Env.getBoolLiteralValue(false));
+  });
+}
+
 } // namespace



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


[PATCH] D118236: [clang][dataflow] Add a transfer function for CXXBoolLiteralExpr

2022-01-26 Thread Stanislav Gatev via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG75c22b382f2a: [clang][dataflow] Add a transfer function for 
CXXBoolLiteralExpr (authored by sgatev).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118236

Files:
  clang/lib/Analysis/FlowSensitive/Transfer.cpp
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp


Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -1970,4 +1970,39 @@
   });
 }
 
+TEST_F(TransferTest, AssignFromBoolLiteral) {
+  std::string Code = R"(
+void target() {
+  bool Foo = true;
+  bool Bar = false;
+  // [[p]]
+}
+  )";
+  runDataflow(
+  Code, [](llvm::ArrayRef<
+   std::pair>>
+   Results,
+   ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
+
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+const auto *FooVal =
+dyn_cast_or_null(Env.getValue(*FooDecl, 
SkipPast::None));
+ASSERT_THAT(FooVal, NotNull());
+
+const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+ASSERT_THAT(BarDecl, NotNull());
+
+const auto *BarVal =
+dyn_cast_or_null(Env.getValue(*BarDecl, 
SkipPast::None));
+ASSERT_THAT(BarVal, NotNull());
+
+EXPECT_EQ(FooVal, &Env.getBoolLiteralValue(true));
+EXPECT_EQ(BarVal, &Env.getBoolLiteralValue(false));
+  });
+}
+
 } // namespace
Index: clang/lib/Analysis/FlowSensitive/Transfer.cpp
===
--- clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -443,8 +443,11 @@
 // FIXME: Implement array initialization.
   }
 
-  // FIXME: Add support for:
-  // - CXXBoolLiteralExpr
+  void VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *S) {
+auto &Loc = Env.createStorageLocation(*S);
+Env.setStorageLocation(*S, Loc);
+Env.setValue(Loc, Env.getBoolLiteralValue(S->getValue()));
+  }
 
 private:
   Environment &Env;


Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -1970,4 +1970,39 @@
   });
 }
 
+TEST_F(TransferTest, AssignFromBoolLiteral) {
+  std::string Code = R"(
+void target() {
+  bool Foo = true;
+  bool Bar = false;
+  // [[p]]
+}
+  )";
+  runDataflow(
+  Code, [](llvm::ArrayRef<
+   std::pair>>
+   Results,
+   ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
+
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+const auto *FooVal =
+dyn_cast_or_null(Env.getValue(*FooDecl, SkipPast::None));
+ASSERT_THAT(FooVal, NotNull());
+
+const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+ASSERT_THAT(BarDecl, NotNull());
+
+const auto *BarVal =
+dyn_cast_or_null(Env.getValue(*BarDecl, SkipPast::None));
+ASSERT_THAT(BarVal, NotNull());
+
+EXPECT_EQ(FooVal, &Env.getBoolLiteralValue(true));
+EXPECT_EQ(BarVal, &Env.getBoolLiteralValue(false));
+  });
+}
+
 } // namespace
Index: clang/lib/Analysis/FlowSensitive/Transfer.cpp
===
--- clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -443,8 +443,11 @@
 // FIXME: Implement array initialization.
   }
 
-  // FIXME: Add support for:
-  // - CXXBoolLiteralExpr
+  void VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *S) {
+auto &Loc = Env.createStorageLocation(*S);
+Env.setStorageLocation(*S, Loc);
+Env.setValue(Loc, Env.getBoolLiteralValue(S->getValue()));
+  }
 
 private:
   Environment &Env;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D118070: Add /winsysroot support to lld

2022-01-26 Thread Peter Kasting via Phabricator via cfe-commits
pkasting updated this revision to Diff 403265.
pkasting added a comment.
Herald added subscribers: cfe-commits, dexonsmith, mstorsjo.
Herald added a project: clang.

Adds autodetection and full support for other clang-cl switches, but doesn't 
work: config->machine is not set this early, so it's always UNKNOWN.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118070

Files:
  clang/docs/tools/clang-formatted-files.txt
  clang/lib/Driver/ToolChains/MSVC.cpp
  clang/lib/Driver/ToolChains/MSVCSetupApi.h
  lld/COFF/Driver.cpp
  lld/COFF/Driver.h
  lld/COFF/Options.td
  llvm/include/llvm/Support/MSVCSetupApi.h
  utils/bazel/llvm-project-overlay/clang/BUILD.bazel

Index: utils/bazel/llvm-project-overlay/clang/BUILD.bazel
===
--- utils/bazel/llvm-project-overlay/clang/BUILD.bazel
+++ utils/bazel/llvm-project-overlay/clang/BUILD.bazel
@@ -1309,9 +1309,6 @@
 "lib/Driver/ToolChains/Arch/*.cpp",
 "lib/Driver/ToolChains/Arch/*.h",
 ],
-exclude = [
-"lib/Driver/ToolChains/MSVCSetupApi.h",
-],
 ),
 hdrs = glob([
 "include/clang/Driver/*.h",
Index: lld/COFF/Options.td
===
--- lld/COFF/Options.td
+++ lld/COFF/Options.td
@@ -41,6 +41,7 @@
 MetaVarName<"[auto,always,never]">;
 def defaultlib : P<"defaultlib", "Add the library to the list of input files">;
 def delayload : P<"delayload", "Delay loaded DLL name">;
+def diasdkdir : P<"diasdkdir", "Set the location of the DIA SDK">;
 def entry   : P<"entry", "Name of entry point symbol">;
 def errorlimit : P<"errorlimit",
 "Maximum number of errors to emit before stopping (0 = no limit)">;
@@ -89,9 +90,16 @@
 def stub: P<"stub", "Specify DOS stub file">;
 def subsystem : P<"subsystem", "Specify subsystem">;
 def timestamp : P<"timestamp", "Specify the PE header timestamp">;
+def vctoolsdir : P<"vctoolsdir", "Set the location of the VC tools">;
+def vctoolsversion : P<"vctoolsversion",
+"Specify which VC tools version to use">;
 def version : P<"version", "Specify a version number in the PE header">;
 def wholearchive_file : P<"wholearchive",
 "Include all object files from this library">;
+def winsdkdir : P<"winsdkdir", "Set the location of the Windows SDK">;
+def winsdkversion : P<"winsdkversion", "Specify which SDK version to use">;
+def winsysroot : P<"winsysroot",
+"Adds several subdirectories to the library search paths">;
 
 def disallowlib : Joined<["/", "-", "/?", "-?"], "disallowlib:">,
 Alias;
Index: lld/COFF/Driver.h
===
--- lld/COFF/Driver.h
+++ lld/COFF/Driver.h
@@ -107,6 +107,9 @@
 
   bool findUnderscoreMangle(StringRef sym);
 
+  // Adds appropriate search paths from `sysroot`.
+  void addWinSysRootLibSearchPaths(const llvm::opt::InputArgList &args);
+
   // Parses LIB environment which contains a list of search paths.
   void addLibSearchPaths();
 
Index: lld/COFF/Driver.cpp
===
--- lld/COFF/Driver.cpp
+++ lld/COFF/Driver.cpp
@@ -37,6 +37,7 @@
 #include "llvm/Support/BinaryStreamReader.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
+#include "llvm/Support/Host.h"
 #include "llvm/Support/LEB128.h"
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Support/Parallel.h"
@@ -50,6 +51,44 @@
 #include 
 #include 
 
+#ifdef _WIN32
+#define WIN32_LEAN_AND_MEAN
+#define NOGDI
+#ifndef NOMINMAX
+#define NOMINMAX
+#endif
+#include 
+#endif
+
+#ifdef _MSC_VER
+// Don't support SetupApi on MinGW.
+#define USE_MSVC_SETUP_API
+
+// Make sure this comes before MSVCSetupApi.h
+#include 
+
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wnon-virtual-dtor"
+#endif
+#include "llvm/Support/MSVCSetupApi.h"
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
+#include "llvm/Support/COM.h"
+_COM_SMARTPTR_TYPEDEF(ISetupConfiguration, __uuidof(ISetupConfiguration));
+_COM_SMARTPTR_TYPEDEF(ISetupConfiguration2, __uuidof(ISetupConfiguration2));
+_COM_SMARTPTR_TYPEDEF(ISetupHelper, __uuidof(ISetupHelper));
+_COM_SMARTPTR_TYPEDEF(IEnumSetupInstances, __uuidof(IEnumSetupInstances));
+_COM_SMARTPTR_TYPEDEF(ISetupInstance, __uuidof(ISetupInstance));
+_COM_SMARTPTR_TYPEDEF(ISetupInstance2, __uuidof(ISetupInstance2));
+
+// TODO(pkasting): Remove
+#undef IMAGE_SUBSYSTEM_UNKNOWN
+#undef IMAGE_SUBSYSTEM_WINDOWS_GUI
+#undef IMAGE_SUBSYSTEM_WINDOWS_CUI
+#endif
+
 using namespace llvm;
 using namespace llvm::object;
 using namespace llvm::COFF;
@@ -102,7 +141,7 @@
   else if (config->driver)
 ext = ".sys";
 
-  return (sys::path::stem(path) + ext).str();
+  return (path::stem(path) + ext).str();
 }
 
 // Returns true if S matches /crtend.?\.o$/.
@@ -150,6 +189,704 @@
   return sym;
 }
 
+st

[PATCH] D117091: [Clang] Add attributes alloc_size and alloc_align to mm_malloc

2022-01-26 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

There's a testing issue on Windows:

   TEST 'Clang :: Headers/mm_malloc.c' FAILED 

  Script:
  --
  : 'RUN: at line 1';   
c:\ws\w2\llvm-project\premerge-checks\build\bin\clang.exe -emit-llvm -std=c11 
-x c C:\ws\w2\llvm-project\premerge-checks\clang\test\Headers\mm_malloc.c -O1 
--target=x86_64-linux-gnu -S -o - | 
c:\ws\w2\llvm-project\premerge-checks\build\bin\filecheck.exe 
C:\ws\w2\llvm-project\premerge-checks\clang\test\Headers\mm_malloc.c
  --
  Exit Code: 2
  
  Command Output (stdout):
  --
  $ ":" "RUN: at line 1"
  $ "c:\ws\w2\llvm-project\premerge-checks\build\bin\clang.exe" "-emit-llvm" 
"-std=c11" "-x" "c" 
"C:\ws\w2\llvm-project\premerge-checks\clang\test\Headers\mm_malloc.c" "-O1" 
"--target=x86_64-linux-gnu" "-S" "-o" "-"
  # command stderr:
  In file included from 
C:\ws\w2\llvm-project\premerge-checks\clang\test\Headers\mm_malloc.c:2:
  
  
c:\ws\w2\llvm-project\premerge-checks\build\lib\clang\14.0.0\include\mm_malloc.h:13:10:
 fatal error: 'stdlib.h' file not found
  
  #include 
  
   ^~
  
  1 error generated.
  
  
  error: command failed with exit status: 1
  $ "c:\ws\w2\llvm-project\premerge-checks\build\bin\filecheck.exe" 
"C:\ws\w2\llvm-project\premerge-checks\clang\test\Headers\mm_malloc.c"
  # command stderr:
  FileCheck error: '' is empty.
  
  FileCheck command line:  
c:\ws\w2\llvm-project\premerge-checks\build\bin\filecheck.exe 
C:\ws\w2\llvm-project\premerge-checks\clang\test\Headers\mm_malloc.c
  
  
  error: command failed with exit status: 2

This one is neat because `stdlib.h` is not a header provided by the compiler 
but is instead provided by whatever CRT happens to be used. Normally, we 
require those headers to be mocked, but the goal here is to test the header the 
compiler does provide.


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

https://reviews.llvm.org/D117091

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


[PATCH] D117091: [Clang] Add attributes alloc_size and alloc_align to mm_malloc

2022-01-26 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert requested changes to this revision.
jdoerfert added a comment.
This revision now requires changes to proceed.

Don't test with O1 , add the dummy 
include folder to the include path (`clang/test/Headers/Inputs/include`), 
stdlib.h is already there, malloc.h is not and needs to be created.


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

https://reviews.llvm.org/D117091

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


[PATCH] D117616: GCC ABI Compatibility: Preserve alignment of non-pod members in packed structs

2022-01-26 Thread Paul Robinson via Phabricator via cfe-commits
probinson added a comment.

> I think we should assume that PS4 will as well.

Yes, please.  We are essentially locked to the ABI as of clang 3.2.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117616

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


[PATCH] D118253: [RISCV] Add the passthru operand for some RVV nomask unary and nullary intrinsics.

2022-01-26 Thread Zakk Chen via Phabricator via cfe-commits
khchen created this revision.
khchen added reviewers: craig.topper, rogfer01, frasercrmck, kito-cheng, 
arcbbb, monkchiang, eopXD.
Herald added subscribers: VincentWu, luke957, achieveartificialintelligence, 
vkmr, evandro, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, 
psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, edward-jones, zzheng, 
jrtc27, niosHD, sabuasal, simoncook, johnrusso, rbar, asb, hiraditya.
khchen requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, pcwang-thead, MaskRay.
Herald added projects: clang, LLVM.

The goal is support tail and mask policy in RVV builtins.
We focus on IR part first.
If the passthru operand is undef, we use tail agnostic, otherwise
use tail undisturbed.

My plan is to handle more complex operations in follow-up patches.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118253

Files:
  clang/include/clang/Basic/riscv_vector.td
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfclass.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfcvt.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfncvt.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfrec7.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfrsqrt7.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfsqrt.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfwcvt.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vsext.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vzext.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vfclass.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vfcvt.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vfncvt.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vfrec7.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vfrsqrt7.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vfsqrt.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vfwcvt.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vid.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/viota.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vsext.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vzext.c
  llvm/include/llvm/IR/IntrinsicsRISCV.td
  llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td
  llvm/test/CodeGen/RISCV/rvv/unmasked-tu.ll
  llvm/test/CodeGen/RISCV/rvv/vfclass.ll
  llvm/test/CodeGen/RISCV/rvv/vfcvt-f-x.ll
  llvm/test/CodeGen/RISCV/rvv/vfcvt-f-xu.ll
  llvm/test/CodeGen/RISCV/rvv/vfcvt-rtz-x-f.ll
  llvm/test/CodeGen/RISCV/rvv/vfcvt-rtz-xu-f.ll
  llvm/test/CodeGen/RISCV/rvv/vfcvt-x-f.ll
  llvm/test/CodeGen/RISCV/rvv/vfcvt-xu-f.ll
  llvm/test/CodeGen/RISCV/rvv/vfncvt-f-f.ll
  llvm/test/CodeGen/RISCV/rvv/vfncvt-f-x.ll
  llvm/test/CodeGen/RISCV/rvv/vfncvt-f-xu.ll
  llvm/test/CodeGen/RISCV/rvv/vfncvt-rod-f-f.ll
  llvm/test/CodeGen/RISCV/rvv/vfncvt-rtz-x-f.ll
  llvm/test/CodeGen/RISCV/rvv/vfncvt-rtz-xu-f.ll
  llvm/test/CodeGen/RISCV/rvv/vfncvt-x-f.ll
  llvm/test/CodeGen/RISCV/rvv/vfncvt-xu-f.ll
  llvm/test/CodeGen/RISCV/rvv/vfrec7.ll
  llvm/test/CodeGen/RISCV/rvv/vfrsqrt7.ll
  llvm/test/CodeGen/RISCV/rvv/vfsqrt.ll
  llvm/test/CodeGen/RISCV/rvv/vfwcvt-f-f.ll
  llvm/test/CodeGen/RISCV/rvv/vfwcvt-f-x.ll
  llvm/test/CodeGen/RISCV/rvv/vfwcvt-f-xu.ll
  llvm/test/CodeGen/RISCV/rvv/vfwcvt-rtz-x-f.ll
  llvm/test/CodeGen/RISCV/rvv/vfwcvt-rtz-xu-f.ll
  llvm/test/CodeGen/RISCV/rvv/vfwcvt-x-f.ll
  llvm/test/CodeGen/RISCV/rvv/vfwcvt-xu-f.ll
  llvm/test/CodeGen/RISCV/rvv/vid.ll
  llvm/test/CodeGen/RISCV/rvv/viota.ll
  llvm/test/CodeGen/RISCV/rvv/vsetvli-insert-crossbb.mir
  llvm/test/CodeGen/RISCV/rvv/vsetvli-insert.mir
  llvm/test/CodeGen/RISCV/rvv/vsext-rv32.ll
  llvm/test/CodeGen/RISCV/rvv/vsext-rv64.ll
  llvm/test/CodeGen/RISCV/rvv/vzext-rv32.ll
  llvm/test/CodeGen/RISCV/rvv/vzext-rv64.ll

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


[PATCH] D118050: [analyzer] Different address spaces cannot overlap

2022-01-26 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 403276.
vabridgers added a comment.

- update test case
- add initial Loc bitwidth check for evalBinOpLL for review


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118050

Files:
  clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
  clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
  clang/test/Analysis/cstring-checker-addressspace.c

Index: clang/test/Analysis/cstring-checker-addressspace.c
===
--- /dev/null
+++ clang/test/Analysis/cstring-checker-addressspace.c
@@ -0,0 +1,27 @@
+// RUN: %clang_analyze_cc1 -triple amdgcn-unknown-unknown \
+// RUN: -analyze -analyzer-checker=core,alpha.unix.cstring \
+// RUN: -analyze -analyzer-checker=debug.ExprInspection \
+// RUN: -analyzer-config crosscheck-with-z3=true -verify %s \
+// RUN: -Wno-incompatible-library-redeclaration
+// REQUIRES: z3
+
+void clang_analyzer_warnIfReached();
+
+// From https://llvm.org/docs/AMDGPUUsage.html#address-spaces,
+// select address space 3 (local), since the pointer size is
+// different than Generic.
+#define DEVICE __attribute__((address_space(3)))
+_Static_assert(sizeof(int *) == 8, "");
+_Static_assert(sizeof(DEVICE int *) == 4, "");
+
+DEVICE void *memcpy(DEVICE void *, const void *, unsigned long);
+
+// Copy from host to device memory.
+DEVICE void *memcpy(DEVICE void *dst, const void *src, unsigned long len);
+
+void top(DEVICE int *dst, int *src, int len) {
+  memcpy(dst, src, len);
+
+  // Create a bugreport for triggering Z3 refutation.
+  clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+}
Index: clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -715,11 +715,57 @@
   llvm_unreachable("Fields not found in parent record's definition");
 }
 
+static uint64_t getLocBitwidth(ProgramStateRef State, Loc loc) {
+  uint64_t LocBitwidth = 0;
+  ASTContext &Ctx = State->getStateManager().getContext();
+
+  switch (loc.getSubKind()) {
+  default:
+llvm_unreachable("Unhandled loc subkind in getLocBitwidth");
+break;
+  case loc::MemRegionValKind: {
+const MemRegion *R = loc.castAs().getRegion();
+if (const auto *SR = dyn_cast(R)) {
+  QualType Ty = SR->getSymbol()->getType();
+  if (!Ty.isNull())
+LocBitwidth = Ctx.getTypeSize(Ty);
+}
+  } break;
+  case loc::ConcreteIntKind: {
+SVal V = State->getSVal(loc);
+QualType Ty = V.getType(Ctx);
+if (!Ty.isNull())
+  LocBitwidth = Ctx.getTypeSize(Ty);
+  } break;
+  case loc::GotoLabelKind:
+break;
+  }
+  return LocBitwidth;
+}
+
+static bool compareLocBitWidth(ProgramStateRef State, Loc RhsLoc, Loc LhsLoc) {
+  uint64_t RhsBitwidth = getLocBitwidth(State, RhsLoc);
+  uint64_t LhsBitwidth = getLocBitwidth(State, LhsLoc);
+  if (RhsBitwidth && LhsBitwidth) {
+assert(RhsBitwidth == LhsBitwidth &&
+   "RhsLoc bitwidth must be same as LhsLoc bitwidth!");
+return RhsBitwidth == LhsBitwidth;
+  }
+  return false;
+}
+
 // FIXME: all this logic will change if/when we have MemRegion::getLocation().
 SVal SimpleSValBuilder::evalBinOpLL(ProgramStateRef state,
   BinaryOperator::Opcode op,
   Loc lhs, Loc rhs,
   QualType resultTy) {
+
+  // Assert that bitwidth of lhs and rhs are the same.
+  // This can happen if two different address spaces are used,
+  // and the bitwidths of the address spaces are different.
+  // See LIT case clang/test/Analysis/cstring-checker-addressspace.c
+  compareLocBitWidth(state, rhs, lhs);
+
   // Only comparisons and subtractions are valid operations on two pointers.
   // See [C99 6.5.5 through 6.5.14] or [C++0x 5.6 through 5.15].
   // However, if a pointer is casted to an integer, evalBinOpNN may end up
Index: clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
@@ -449,6 +449,11 @@
 
   ProgramStateRef stateTrue, stateFalse;
 
+  // Assume different address spaces cannot overlap.
+  if (First.Expression->getType()->getPointeeType().getAddressSpace() !=
+  Second.Expression->getType()->getPointeeType().getAddressSpace())
+return state;
+
   // Get the buffer values and make sure they're known locations.
   const LocationContext *LCtx = C.getLocationContext();
   SVal firstVal = state->getSVal(First.Expression, LCtx);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D118050: [analyzer] Different address spaces cannot overlap

2022-01-26 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a comment.

I updated the test case after verifying I can reproduce the crash without the 
fix. I also experimented with adding a bitwidth check for the lhs and rhs loc 
parameters to evalBinOpLL, and verified this assert catches the negative 
(crash) case.

I explored adding a 'memcpy_special' case, but this memcpy function must be a 
builtin for the checker to hit on it, so I could not repro.

I realize the bitwidth check may not be ideal, but it's a start. Thanks in 
advance for comments. Best!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118050

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


[PATCH] D118050: [analyzer] Different address spaces cannot overlap

2022-01-26 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers marked an inline comment as done.
vabridgers added inline comments.



Comment at: clang/test/Analysis/cstring-checker-addressspace.c:14
+// Copy from host to device memory.
+DEVICE void *memcpy(DEVICE void *dst, const void *src, unsigned long len);
+

steakhal wrote:
> Please try to trigger the test using some suffix for the `memcpy`.
> E.g.: `memcpy_host2device` or something similar.
Please see latest comment. I tried this, but found a memcpy name with some 
suffix must be builtin. I could not find a way to repro this, but I was able to 
repro the negative case with the changes I just uploaded amending this review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118050

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


[PATCH] D118224: [clang-tidy] bugprone-signal-handler improvements: display call chain

2022-01-26 Thread Nathan James via Phabricator via cfe-commits
njames93 added inline comments.



Comment at: clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp:192-193
   diag(CallOrRef->getBeginLoc(),
-   "%0 may not be asynchronous-safe; "
-   "calling it from a signal handler may be dangerous")
-  << CalledFunction;
-  diag(SignalCall->getSourceRange().getBegin(),
-   "signal handler registered here", DiagnosticIDs::Note);
-  diag(HandlerDecl->getBeginLoc(), "handler function declared here",
-   DiagnosticIDs::Note);
+   "%0 may not be asynchronous-safe; %1 a signal handler may be dangerous")
+  << CalledFunction << (DirectHandler ? "using it as" : "calling it from");
+}

Small nit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118224

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


[PATCH] D56303: [clang-tidy] Recognize labelled statements when simplifying boolean exprs

2022-01-26 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D56303#3270090 , @LegalizeAdulthood 
wrote:

> In D56303#3266252 , @njames93 wrote:
>
>> A large portion of the changes, especially in the checks implementation 
>> file, appear to be NFC stylistic or formatting only fixes. While these 
>> changes are generally good, they shouldn't be a part of this patch. Instead 
>> they should be committed in their own NFC patch.
>> This makes it much easier to review the relevant changes needed to implement 
>> this new behaviour.
>
> It's going to be a significant amount of work to tease everything
> apart and this patch has already been waiting literally for years.

I don't think you need to tease it apart for this patch, but FWIW, I agree that 
this is much harder to review in this state.

> Every time I put something up for review I get told "do this because
> the style guide says so", so I anticipated those things and fixed them
> pre-emptively.

The rule of thumb is: if you have significant NFC changes, do them first and 
push the changes (often doesn't even require a review because it's NFC, but 
that depends on what comfort level you have about the changes being NFC), and 
then do the functional changes on top of the improved code. Reviewers will ask 
you to update style for the lines of code you're touching when appropriate, but 
we (generally) shouldn't be asking you to fix style issues in code you're not 
touching. (Oddly, we touch on this in #2 at 
https://llvm.org/docs/DeveloperPolicy.html#obtaining-commit-access which is not 
where I'd expect that information to live.)

FWIW, I looked through the changes and don't have major concerns. A second set 
of eyes approving this would be appreciated, but this LGTM.




Comment at: 
clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp:72-73
 
-const Expr *getBoolLiteral(const MatchFinder::MatchResult &Result,
-   StringRef Id) {
+static const Expr *getBoolLiteral(const MatchFinder::MatchResult &Result,
+  StringRef Id) {
   if (const Expr *Literal = Result.Nodes.getNodeAs(Id))

LegalizeAdulthood wrote:
> LegalizeAdulthood wrote:
> > FYI
> > 
> > These tabs here (and elsewhere) are phantoms somehow
> > introduced into the diff by Phabricator.  My local diff file
> > that I uploaded has zero tabs in it anywhere.
> > 
> When I look more carefully, I see it's one column to the left of the
> first column in the file so it's trying to somehow say that this line
> had increased indent in the diff?
> 
> I thought it was a TAB indicator and another reviewer thought so as well.
> 
> But it isn't a TAB at all `:)`
Yeah, that's caught me a few times as well. The `>>` seems to mean "indentation 
changed" not "tab inserted".



Comment at: 
clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp:422
 
-  switch (Op->getOpcode()) {
-case BO_LAnd:
-  if (BoolValue) {
-// expr && true -> expr
-ReplaceWithExpression(Other, /*Negated=*/false);
-  } else {
-// expr && false -> false
-ReplaceWithExpression(Bool, /*Negated=*/false);
-  }
-  break;
-case BO_LOr:
-  if (BoolValue) {
-// expr || true -> true
-ReplaceWithExpression(Bool, /*Negated=*/false);
-  } else {
-// expr || false -> expr
-ReplaceWithExpression(Other, /*Negated=*/false);
-  }
-  break;
-case BO_EQ:
-  // expr == true -> expr, expr == false -> !expr
-  ReplaceWithExpression(Other, /*Negated=*/!BoolValue);
-  break;
-case BO_NE:
-  // expr != true -> !expr, expr != false -> expr
-  ReplaceWithExpression(Other, /*Negated=*/BoolValue);
-  break;
-default:
-  break;
+  switch (Op->getOpcode()) { // NOLINT(clang-diagnostic-switch-enum)
+  case BO_LAnd:

I'd prefer the `NOLINT` comment be removed (we don't typically add those, same 
as clang-format comments or other special markings).


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

https://reviews.llvm.org/D56303

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


[PATCH] D111100: enable plugins for clang-tidy

2022-01-26 Thread Jameson Nash via Phabricator via cfe-commits
vtjnash added a comment.

@aaron.ballman I think I incorporated all of your feedback. Is this okay for me 
to merge to main? I would like to get it in before the feature branch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D00

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


[PATCH] D118257: [AArch64] Generate fcmps when appropriate for neon intrinsics

2022-01-26 Thread John Brawn via Phabricator via cfe-commits
john.brawn created this revision.
john.brawn added reviewers: kpn, cameron.mcinally, dmgreen, t.p.northover.
Herald added a subscriber: kristof.beyls.
john.brawn requested review of this revision.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118257

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c

Index: clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c
===
--- clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c
+++ clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c
@@ -585,7 +585,7 @@
 
 // COMMON-LABEL: test_vcges_f32
 // UNCONSTRAINED: [[TMP0:%.*]] = fcmp oge float %a, %b
-// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f32(float %a, float %b, metadata !"oge", metadata !"fpexcept.strict")
+// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmps.f32(float %a, float %b, metadata !"oge", metadata !"fpexcept.strict")
 // CHECK-ASM: fcmp s{{[0-9]+}}, s{{[0-9]+}}
 // CHECK-ASM-NEXT:cset {{w[0-9]+}}, ge
 // COMMONIR:  [[VCMPD_I:%.*]] = sext i1 [[TMP0]] to i32
@@ -596,7 +596,7 @@
 
 // COMMON-LABEL: test_vcged_f64
 // UNCONSTRAINED: [[TMP0:%.*]] = fcmp oge double %a, %b
-// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f64(double %a, double %b, metadata !"oge", metadata !"fpexcept.strict")
+// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmps.f64(double %a, double %b, metadata !"oge", metadata !"fpexcept.strict")
 // CHECK-ASM: fcmp d{{[0-9]+}}, d{{[0-9]+}}
 // CHECK-ASM-NEXT:cset {{w[0-9]+}}, ge
 // COMMONIR:  [[VCMPD_I:%.*]] = sext i1 [[TMP0]] to i64
@@ -607,7 +607,7 @@
 
 // COMMON-LABEL: test_vcgezs_f32
 // UNCONSTRAINED: [[TMP0:%.*]] = fcmp oge float %a, 0.00e+00
-// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f32(float %a, float 0.00e+00, metadata !"oge", metadata !"fpexcept.strict")
+// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmps.f32(float %a, float 0.00e+00, metadata !"oge", metadata !"fpexcept.strict")
 // CHECK-ASM: fcmp s{{[0-9]+}}, #0.0
 // CHECK-ASM-NEXT:cset {{w[0-9]+}}, ge
 // COMMONIR:  [[VCGEZ_I:%.*]] = sext i1 [[TMP0]] to i32
@@ -618,7 +618,7 @@
 
 // COMMON-LABEL: test_vcgezd_f64
 // UNCONSTRAINED: [[TMP0:%.*]] = fcmp oge double %a, 0.00e+00
-// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f64(double %a, double 0.00e+00, metadata !"oge", metadata !"fpexcept.strict")
+// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmps.f64(double %a, double 0.00e+00, metadata !"oge", metadata !"fpexcept.strict")
 // CHECK-ASM: fcmp d{{[0-9]+}}, #0.0
 // CHECK-ASM-NEXT:cset {{w[0-9]+}}, ge
 // COMMONIR:  [[VCGEZ_I:%.*]] = sext i1 [[TMP0]] to i64
@@ -629,7 +629,7 @@
 
 // COMMON-LABEL: test_vcgts_f32
 // UNCONSTRAINED: [[TMP0:%.*]] = fcmp ogt float %a, %b
-// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f32(float %a, float %b, metadata !"ogt", metadata !"fpexcept.strict")
+// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmps.f32(float %a, float %b, metadata !"ogt", metadata !"fpexcept.strict")
 // CHECK-ASM: fcmp s{{[0-9]+}}, s{{[0-9]+}}
 // CHECK-ASM-NEXT:cset {{w[0-9]+}}, gt
 // COMMONIR:  [[VCMPD_I:%.*]] = sext i1 [[TMP0]] to i32
@@ -640,7 +640,7 @@
 
 // COMMON-LABEL: test_vcgtd_f64
 // UNCONSTRAINED: [[TMP0:%.*]] = fcmp ogt double %a, %b
-// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f64(double %a, double %b, metadata !"ogt", metadata !"fpexcept.strict")
+// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmps.f64(double %a, double %b, metadata !"ogt", metadata !"fpexcept.strict")
 // CHECK-ASM: fcmp d{{[0-9]+}}, d{{[0-9]+}}
 // CHECK-ASM-NEXT:cset {{w[0-9]+}}, gt
 // COMMONIR:  [[VCMPD_I:%.*]] = sext i1 [[TMP0]] to i64
@@ -651,7 +651,7 @@
 
 // COMMON-LABEL: test_vcgtzs_f32
 // UNCONSTRAINED: [[TMP0:%.*]] = fcmp ogt float %a, 0.00e+00
-// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f32(float %a, float 0.00e+00, metadata !"ogt", metadata !"fpexcept.strict")
+// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmps.f32(float %a, float 0.00e+00, metadata !"ogt", metadata !"fpexcept.strict")
 // CHECK-ASM: fcmp s{{[0-9]+}}, #0.0
 // CHECK-ASM-NEXT:cset {{w[0-9]+}}, gt
 // COMMONIR:  [[VCGTZ_I:%.*]] = sext i1 [[TMP0]] to i32
@@ -662,7 +662,7 @@
 
 // COMMON-LABEL: test_vcgtzd_f64
 // UNCONSTRAINED: [[TMP0:%.*]] = fcmp ogt double %a, 0.00e+00
-// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f64(double %a, double 0.00e+00, metadata !"ogt", metadata !"fpexcept.strict")
+// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.const

[PATCH] D118225: [RISCV] Decouple Zve* extensions.

2022-01-26 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: llvm/lib/Support/RISCVISAInfo.cpp:747
   // Could not implement Zve* extension and the V extension at the same time.
-  if (HasZve32x && HasV)
+  if (HasZve && HasV)
 return createStringError(

Now we need to check if multiple Zve extensions are specified at the same time?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118225

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


[PATCH] D111100: enable plugins for clang-tidy

2022-01-26 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

Thanks for the fixes, this LGTM! However, if @alexfh can sign off as well as 
code owner, I'd appreciate it; this is a pretty big directional change and I 
think he should be on board for it. (If we don't hear back by Fri Jan 28, then 
I think this is okay to land.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D00

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


[clang] b797d5e - [CMake] [Clang] Add option to specify PowerPC long double format

2022-01-26 Thread Qiu Chaofan via cfe-commits

Author: Qiu Chaofan
Date: 2022-01-27T00:50:53+08:00
New Revision: b797d5e6b21b3af3d581642c9a535327aa0764a7

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

LOG: [CMake] [Clang] Add option to specify PowerPC long double format

This method introduces new CMake variable
PPC_LINUX_DEFAULT_IEEELONGDOUBLE (false by default) to enable fp128 as
default long double format.

Reviewed By: jsji

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

Added: 


Modified: 
clang/CMakeLists.txt
clang/include/clang/Config/config.h.cmake
clang/include/clang/Driver/ToolChain.h
clang/lib/Driver/ToolChain.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Analysis/builtin_signbit.cpp
clang/test/Driver/ppc-abi.c

Removed: 




diff  --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
index 49150fa7c5612..2bb395ffece53 100644
--- a/clang/CMakeLists.txt
+++ b/clang/CMakeLists.txt
@@ -237,6 +237,9 @@ set(ENABLE_LINKER_BUILD_ID OFF CACHE BOOL "pass --build-id 
to ld")
 set(ENABLE_X86_RELAX_RELOCATIONS ON CACHE BOOL
 "enable x86 relax relocations by default")
 
+set(PPC_LINUX_DEFAULT_IEEELONGDOUBLE OFF CACHE BOOL
+"Enable IEEE binary128 as default long double format on PowerPC Linux.")
+
 set(CLANG_SPAWN_CC1 OFF CACHE BOOL
 "Whether clang should use a new process for the CC1 invocation")
 

diff  --git a/clang/include/clang/Config/config.h.cmake 
b/clang/include/clang/Config/config.h.cmake
index 53386ef94129b..10a93293c0512 100644
--- a/clang/include/clang/Config/config.h.cmake
+++ b/clang/include/clang/Config/config.h.cmake
@@ -78,6 +78,9 @@
 /* enable x86 relax relocations by default */
 #cmakedefine01 ENABLE_X86_RELAX_RELOCATIONS
 
+/* Enable IEEE binary128 as default long double format on PowerPC Linux. */
+#cmakedefine01 PPC_LINUX_DEFAULT_IEEELONGDOUBLE
+
 /* Enable each functionality of modules */
 #cmakedefine01 CLANG_ENABLE_ARCMT
 #cmakedefine01 CLANG_ENABLE_OBJC_REWRITER

diff  --git a/clang/include/clang/Driver/ToolChain.h 
b/clang/include/clang/Driver/ToolChain.h
index 37011de6bd6d7..329833bb13be7 100644
--- a/clang/include/clang/Driver/ToolChain.h
+++ b/clang/include/clang/Driver/ToolChain.h
@@ -409,6 +409,9 @@ class ToolChain {
   /// Check whether to enable x86 relax relocations by default.
   virtual bool useRelaxRelocations() const;
 
+  /// Check whether use IEEE binary128 as long double format by default.
+  bool defaultToIEEELongDouble() const;
+
   /// GetDefaultStackProtectorLevel - Get the default stack protector level for
   /// this tool chain.
   virtual LangOptions::StackProtectorMode

diff  --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 7551ee4aeb79f..5fef1fb2ee5af 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -109,6 +109,10 @@ bool ToolChain::useRelaxRelocations() const {
   return ENABLE_X86_RELAX_RELOCATIONS;
 }
 
+bool ToolChain::defaultToIEEELongDouble() const {
+  return PPC_LINUX_DEFAULT_IEEELONGDOUBLE && getTriple().isOSLinux();
+}
+
 SanitizerArgs
 ToolChain::getSanitizerArgs(const llvm::opt::ArgList &JobArgs) const {
   SanitizerArgs SanArgs(*this, JobArgs, !SanitizerArgsChecked);

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 52d576345c027..9e10d6d890747 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -2061,7 +2061,7 @@ void Clang::AddPPCTargetArgs(const ArgList &Args,
 }
   }
 
-  bool IEEELongDouble = false;
+  bool IEEELongDouble = getToolChain().defaultToIEEELongDouble();
   for (const Arg *A : Args.filtered(options::OPT_mabi_EQ)) {
 StringRef V = A->getValue();
 if (V == "ieeelongdouble")

diff  --git a/clang/test/Analysis/builtin_signbit.cpp 
b/clang/test/Analysis/builtin_signbit.cpp
index bf91511c43ce8..251391952f9c5 100644
--- a/clang/test/Analysis/builtin_signbit.cpp
+++ b/clang/test/Analysis/builtin_signbit.cpp
@@ -1,6 +1,9 @@
-// RUN: %clang -target powerpc-linux-gnu -emit-llvm -S -O0 %s -o - | 
FileCheck %s --check-prefix=CHECK-BE --check-prefix=CHECK
-// RUN: %clang -target powerpc64-linux-gnu   -emit-llvm -S -O0 %s -o - | 
FileCheck %s --check-prefix=CHECK-BE --check-prefix=CHECK
-// RUN: %clang -target powerpc64le-linux-gnu -emit-llvm -S -O0 %s -o - | 
FileCheck %s --check-prefix=CHECK-LE --check-prefix=CHECK
+// RUN: %clang -target powerpc-linux-gnu -emit-llvm -S -mabi=ibmlongdouble \
+// RUN:   -O0 %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-BE
+// RUN: %clang -target powerpc64-linux-gnu -emit-llvm -S -mabi=ibmlongdouble \
+// RUN:   -O0 %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-BE
+// RUN: %clang -target powerpc64le-linux-gnu -emit-llvm -S -mabi=ibmlongdouble 
\
+// RUN:   -O0 %s -o - | FileCheck %s --chec

[PATCH] D118110: [CMake] [Clang] Add CMake build option to specify long double format on PowerPC

2022-01-26 Thread Qiu Chaofan via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb797d5e6b21b: [CMake] [Clang] Add option to specify PowerPC 
long double format (authored by qiucf).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118110

Files:
  clang/CMakeLists.txt
  clang/include/clang/Config/config.h.cmake
  clang/include/clang/Driver/ToolChain.h
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Analysis/builtin_signbit.cpp
  clang/test/Driver/ppc-abi.c

Index: clang/test/Driver/ppc-abi.c
===
--- clang/test/Driver/ppc-abi.c
+++ clang/test/Driver/ppc-abi.c
@@ -63,9 +63,6 @@
 // CHECK-ELFv1-IEEE: "-mabi=ieeelongdouble"
 // CHECK-ELFv1-IEEE: "-target-abi" "elfv1"
 
-// Check -mabi=ibmlongdouble is the default.
-// RUN: %clang -target powerpc64le-linux-gnu %s -### 2>&1 \
-// RUN:   | FileCheck -check-prefix=CHECK-ELFv2-IBM128 %s
 // RUN: %clang -target powerpc64le-linux-gnu %s -mabi=ibmlongdouble -### 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-ELFv2-IBM128 %s
 
Index: clang/test/Analysis/builtin_signbit.cpp
===
--- clang/test/Analysis/builtin_signbit.cpp
+++ clang/test/Analysis/builtin_signbit.cpp
@@ -1,6 +1,9 @@
-// RUN: %clang -target powerpc-linux-gnu -emit-llvm -S -O0 %s -o - | FileCheck %s --check-prefix=CHECK-BE --check-prefix=CHECK
-// RUN: %clang -target powerpc64-linux-gnu   -emit-llvm -S -O0 %s -o - | FileCheck %s --check-prefix=CHECK-BE --check-prefix=CHECK
-// RUN: %clang -target powerpc64le-linux-gnu -emit-llvm -S -O0 %s -o - | FileCheck %s --check-prefix=CHECK-LE --check-prefix=CHECK
+// RUN: %clang -target powerpc-linux-gnu -emit-llvm -S -mabi=ibmlongdouble \
+// RUN:   -O0 %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-BE
+// RUN: %clang -target powerpc64-linux-gnu -emit-llvm -S -mabi=ibmlongdouble \
+// RUN:   -O0 %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-BE
+// RUN: %clang -target powerpc64le-linux-gnu -emit-llvm -S -mabi=ibmlongdouble \
+// RUN:   -O0 %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-LE
 
 bool b;
 double d = -1.0;
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -2061,7 +2061,7 @@
 }
   }
 
-  bool IEEELongDouble = false;
+  bool IEEELongDouble = getToolChain().defaultToIEEELongDouble();
   for (const Arg *A : Args.filtered(options::OPT_mabi_EQ)) {
 StringRef V = A->getValue();
 if (V == "ieeelongdouble")
Index: clang/lib/Driver/ToolChain.cpp
===
--- clang/lib/Driver/ToolChain.cpp
+++ clang/lib/Driver/ToolChain.cpp
@@ -109,6 +109,10 @@
   return ENABLE_X86_RELAX_RELOCATIONS;
 }
 
+bool ToolChain::defaultToIEEELongDouble() const {
+  return PPC_LINUX_DEFAULT_IEEELONGDOUBLE && getTriple().isOSLinux();
+}
+
 SanitizerArgs
 ToolChain::getSanitizerArgs(const llvm::opt::ArgList &JobArgs) const {
   SanitizerArgs SanArgs(*this, JobArgs, !SanitizerArgsChecked);
Index: clang/include/clang/Driver/ToolChain.h
===
--- clang/include/clang/Driver/ToolChain.h
+++ clang/include/clang/Driver/ToolChain.h
@@ -409,6 +409,9 @@
   /// Check whether to enable x86 relax relocations by default.
   virtual bool useRelaxRelocations() const;
 
+  /// Check whether use IEEE binary128 as long double format by default.
+  bool defaultToIEEELongDouble() const;
+
   /// GetDefaultStackProtectorLevel - Get the default stack protector level for
   /// this tool chain.
   virtual LangOptions::StackProtectorMode
Index: clang/include/clang/Config/config.h.cmake
===
--- clang/include/clang/Config/config.h.cmake
+++ clang/include/clang/Config/config.h.cmake
@@ -78,6 +78,9 @@
 /* enable x86 relax relocations by default */
 #cmakedefine01 ENABLE_X86_RELAX_RELOCATIONS
 
+/* Enable IEEE binary128 as default long double format on PowerPC Linux. */
+#cmakedefine01 PPC_LINUX_DEFAULT_IEEELONGDOUBLE
+
 /* Enable each functionality of modules */
 #cmakedefine01 CLANG_ENABLE_ARCMT
 #cmakedefine01 CLANG_ENABLE_OBJC_REWRITER
Index: clang/CMakeLists.txt
===
--- clang/CMakeLists.txt
+++ clang/CMakeLists.txt
@@ -237,6 +237,9 @@
 set(ENABLE_X86_RELAX_RELOCATIONS ON CACHE BOOL
 "enable x86 relax relocations by default")
 
+set(PPC_LINUX_DEFAULT_IEEELONGDOUBLE OFF CACHE BOOL
+"Enable IEEE binary128 as default long double format on PowerPC Linux.")
+
 set(CLANG_SPAWN_CC1 OFF CACHE BOOL
 "Whether clang should use a new process for the CC1 invocation")
 
___

[PATCH] D118178: [clang][dataflow] Allow clients to disable built-in transfer functions.

2022-01-26 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel updated this revision to Diff 403296.
ymandel added a comment.

addressed comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118178

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
  clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h
  clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
  clang/unittests/Analysis/FlowSensitive/NoopAnalysis.h
  clang/unittests/Analysis/FlowSensitive/TestingSupportTest.cpp
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
  clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -42,6 +42,8 @@
 template 
 class AnalysisCallback : public ast_matchers::MatchFinder::MatchCallback {
 public:
+  AnalysisCallback(AnalysisT (*MakeAnalysis)(ASTContext &))
+  : MakeAnalysis(MakeAnalysis) {}
   void run(const ast_matchers::MatchFinder::MatchResult &Result) override {
 assert(BlockStates.empty());
 
@@ -54,12 +56,13 @@
 auto CFCtx = llvm::cantFail(
 ControlFlowContext::build(nullptr, Body, Result.Context));
 
-AnalysisT Analysis(*Result.Context);
+AnalysisT Analysis = MakeAnalysis(*Result.Context);
 DataflowAnalysisContext DACtx;
 Environment Env(DACtx);
 BlockStates = runDataflowAnalysis(CFCtx, Analysis, Env);
   }
 
+  AnalysisT (*MakeAnalysis)(ASTContext &);
   std::vector<
   llvm::Optional>>
   BlockStates;
@@ -67,11 +70,11 @@
 
 template 
 std::vector>>
-runAnalysis(llvm::StringRef Code) {
+runAnalysis(llvm::StringRef Code, AnalysisT (*MakeAnalysis)(ASTContext &)) {
   std::unique_ptr AST =
   tooling::buildASTFromCodeWithArgs(Code, {"-std=c++11"});
 
-  AnalysisCallback Callback;
+  AnalysisCallback Callback(MakeAnalysis);
   ast_matchers::MatchFinder Finder;
   Finder.addMatcher(
   ast_matchers::functionDecl(ast_matchers::hasName("target")).bind("func"),
@@ -82,9 +85,8 @@
 }
 
 TEST(DataflowAnalysisTest, NoopAnalysis) {
-  auto BlockStates = runAnalysis(R"(
-void target() {}
-  )");
+  auto BlockStates = runAnalysis(
+  "void target() {}", [](ASTContext &C) { return NoopAnalysis(C, false); });
   EXPECT_EQ(BlockStates.size(), 2u);
   EXPECT_TRUE(BlockStates[0].hasValue());
   EXPECT_TRUE(BlockStates[1].hasValue());
@@ -109,8 +111,9 @@
 : public DataflowAnalysis {
 public:
   explicit NonConvergingAnalysis(ASTContext &Context)
-  : DataflowAnalysis(Context) {
-  }
+  : DataflowAnalysis(
+Context,
+/*ApplyBuiltinTransfer=*/false) {}
 
   static NonConvergingLattice initialElement() { return {0}; }
 
@@ -120,11 +123,13 @@
 };
 
 TEST(DataflowAnalysisTest, NonConvergingAnalysis) {
-  auto BlockStates = runAnalysis(R"(
+  auto BlockStates = runAnalysis(
+  R"(
 void target() {
   while(true) {}
 }
-  )");
+  )",
+  [](ASTContext &C) { return NonConvergingAnalysis(C); });
   EXPECT_EQ(BlockStates.size(), 4u);
   EXPECT_TRUE(BlockStates[0].hasValue());
   EXPECT_TRUE(BlockStates[1].hasValue());
Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -40,11 +40,14 @@
 protected:
   template 
   void runDataflow(llvm::StringRef Code, Matcher Match,
-   LangStandard::Kind Std = LangStandard::lang_cxx17) {
+   LangStandard::Kind Std = LangStandard::lang_cxx17,
+   bool ApplyBuiltinTransfer = true) {
 ASSERT_THAT_ERROR(
 test::checkDataflow(
 Code, "target",
-[](ASTContext &C, Environment &) { return NoopAnalysis(C); },
+[ApplyBuiltinTransfer](ASTContext &C, Environment &) {
+  return NoopAnalysis(C, ApplyBuiltinTransfer);
+},
 [&Match](
 llvm::ArrayRef<
 std::pair>>
@@ -73,6 +76,31 @@
   return Result;
 }
 
+TEST_F(TransferTest, IntVarDeclNotTrackedWhenTransferDisabled) {
+  std::string Code = R"(
+void target() {
+  int Foo;
+  // [[p]]
+}
+  )";
+  runDataflow(
+  Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
+
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+EXPECT_EQ(Env.getStorageLocation(*FooDecl, SkipPast::None), nullptr);
+  },
+  LangStandard::la

[PATCH] D118259: [AArch64] Adjust aarch64-neon-intrinsics-constrained test and un-XFAIL

2022-01-26 Thread John Brawn via Phabricator via cfe-commits
john.brawn created this revision.
john.brawn added reviewers: kpn, cameron.mcinally, dmgreen, t.p.northover.
Herald added a subscriber: kristof.beyls.
john.brawn requested review of this revision.
Herald added a project: clang.

This test no longer fails during isel, but does need the expected output to be 
adjusted to match the actual output.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118259

Files:
  clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c

Index: clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c
===
--- clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c
+++ clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c
@@ -1,27 +1,24 @@
 // RUN: %clang_cc1 -triple arm64-none-linux-gnu -target-feature +neon \
 // RUN: -fallow-half-arguments-and-returns -S -disable-O0-optnone \
 // RUN:  -flax-vector-conversions=none -emit-llvm -o - %s | opt -S -mem2reg \
-// RUN: | FileCheck --check-prefix=COMMON --check-prefix=COMMONIR --check-prefix=UNCONSTRAINED %s
+// RUN: | FileCheck --check-prefixes=COMMON,COMMONIR,UNCONSTRAINED %s
 // RUN: %clang_cc1 -triple arm64-none-linux-gnu -target-feature +neon \
 // RUN: -fallow-half-arguments-and-returns -S -disable-O0-optnone \
-// RUN:  -ffp-exception-behavior=strict \
+// RUN:  -ffp-exception-behavior=strict -fexperimental-strict-floating-point \
 // RUN:  -flax-vector-conversions=none -emit-llvm -o - %s | opt -S -mem2reg \
-// RUN: | FileCheck --check-prefix=COMMON --check-prefix=COMMONIR --check-prefix=CONSTRAINED %s
+// RUN: | FileCheck --check-prefixes=COMMON,COMMONIR,CONSTRAINED %s
 // RUN: %clang_cc1 -triple arm64-none-linux-gnu -target-feature +neon \
 // RUN: -fallow-half-arguments-and-returns -S -disable-O0-optnone \
 // RUN:  -flax-vector-conversions=none -o - %s \
-// RUN: | FileCheck --check-prefix=COMMON --check-prefix=CHECK-ASM %s
+// RUN: | FileCheck --check-prefixes=COMMON,CHECK-ASM,CHECK-ASM-UNCONSTRAINED %s
 // RUN: %clang_cc1 -triple arm64-none-linux-gnu -target-feature +neon \
 // RUN: -fallow-half-arguments-and-returns -S -disable-O0-optnone \
-// RUN:  -ffp-exception-behavior=strict \
+// RUN:  -ffp-exception-behavior=strict -fexperimental-strict-floating-point \
 // RUN:  -flax-vector-conversions=none -o - %s \
-// RUN: | FileCheck --check-prefix=COMMON --check-prefix=CHECK-ASM %s
+// RUN: | FileCheck --check-prefixes=COMMON,CHECK-ASM,CHECK-ASM-CONSTRAINED %s
 
 // REQUIRES: aarch64-registered-target
 
-// Fails during instruction selection:
-// XFAIL: *
-
 // Test new aarch64 intrinsics and types but constrained
 
 #include 
@@ -278,7 +275,9 @@
 // COMMON-LABEL: test_vceq_f32
 // UNCONSTRAINED: [[CMP_I:%.*]] = fcmp oeq <2 x float> %v1, %v2
 // CONSTRAINED:   [[CMP_I:%.*]] = call <2 x i1> @llvm.experimental.constrained.fcmp.v2f32(<2 x float> %v1, <2 x float> %v2, metadata !"oeq", metadata !"fpexcept.strict")
-// CHECK-ASM: fcmeq v{{[0-9]+}}.2s, v{{[0-9]+}}.2s, v{{[0-9]+}}.2s
+// CHECK-ASM-UNCONSTRAINED: fcmeq v{{[0-9]+}}.2s, v{{[0-9]+}}.2s, v{{[0-9]+}}.2s
+// CHECK-ASM-CONSTRAINED: fcmp s{{[0-9]+}}, s{{[0-9]+}}
+// CHECK-ASM-CONSTRAINED: fcmp s{{[0-9]+}}, s{{[0-9]+}}
 // COMMONIR:  [[SEXT_I:%.*]] = sext <2 x i1> [[CMP_I]] to <2 x i32>
 // COMMONIR:  ret <2 x i32> [[SEXT_I]]
 uint32x2_t test_vceq_f32(float32x2_t v1, float32x2_t v2) {
@@ -299,7 +298,11 @@
 // COMMON-LABEL: test_vceqq_f32
 // UNCONSTRAINED: [[CMP_I:%.*]] = fcmp oeq <4 x float> %v1, %v2
 // CONSTRAINED:   [[CMP_I:%.*]] = call <4 x i1> @llvm.experimental.constrained.fcmp.v4f32(<4 x float> %v1, <4 x float> %v2, metadata !"oeq", metadata !"fpexcept.strict")
-// CHECK-ASM: fcmeq v{{[0-9]+}}.4s, v{{[0-9]+}}.4s, v{{[0-9]+}}.4s
+// CHECK-ASM-UNCONSTRAINED: fcmeq v{{[0-9]+}}.4s, v{{[0-9]+}}.4s, v{{[0-9]+}}.4s
+// CHECK-ASM-CONSTRAINED: fcmp s{{[0-9]+}}, s{{[0-9]+}}
+// CHECK-ASM-CONSTRAINED: fcmp s{{[0-9]+}}, s{{[0-9]+}}
+// CHECK-ASM-CONSTRAINED: fcmp s{{[0-9]+}}, s{{[0-9]+}}
+// CHECK-ASM-CONSTRAINED: fcmp s{{[0-9]+}}, s{{[0-9]+}}
 // COMMONIR:  [[SEXT_I:%.*]] = sext <4 x i1> [[CMP_I]] to <4 x i32>
 // COMMONIR:  ret <4 x i32> [[SEXT_I]]
 uint32x4_t test_vceqq_f32(float32x4_t v1, float32x4_t v2) {
@@ -309,7 +312,9 @@
 // COMMON-LABEL: test_vceqq_f64
 // UNCONSTRAINED: [[CMP_I:%.*]] = fcmp oeq <2 x double> %v1, %v2
 // CONSTRAINED:   [[CMP_I:%.*]] = call <2 x i1> @llvm.experimental.constrained.fcmp.v2f64(<2 x double> %v1, <2 x double> %v2, metadata !"oeq", metadata !"fpexcept.strict")
-// CHECK-ASM: fcmeq v{{[0-9]+}}.2d, v{{[0-9]+}}.2d, v{{[0-9]+}}.2d
+// CHECK-ASM-UNCONSTRAINED: fcmeq v{{[0-9]+}}.2d, v{{[0-9]+}}.2d, v{{[0-9]+}}.2d
+// CHECK-ASM-CONSTRAINED: fcmp d{{[0-9]+}}, d{{[0-9]+}}
+// CHECK-ASM-CONSTRAINED: fcmp d{{[0-9]+}}, d{{[0-9]+}}
 // COMMONIR:  [[SEXT_I:%.*]] = sext <2 x i1> [[CMP_I]] to <2 x i64>
 // COMMONIR:  ret <2 x i64> [[SEXT_I]]
 uint64x2_t test_vceqq_f64(float64x2_t v1, float64x2_t v2) {
@@ -319,7 +324,9 @@

[PATCH] D118260: [clangd][Hover] Suppress initializers with many tokens

2022-01-26 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: sammccall.
Herald added subscribers: usaxena95, arphaman.
kadircet requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

This results in excessive memory usage and eats a lot of screen estate.
Especially in the cases with lots of nested macro calls.

This patch tries to remedy it before the release cut by suppressing the
initializers. For better UX we should probably update the expression printer to
truncate those (behind some policy).

Related: https://github.com/clangd/clangd/issues/917


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118260

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -3172,6 +3172,20 @@
   EXPECT_EQ(H->Type, HoverInfo::PrintedType("m_int"));
 }
 
+TEST(Hover, HideBigInitializers) {
+  Annotations T(R"cpp(
+  #define A(x) x, x, x, x
+  #define B(x) A(A(A(A(x
+  int a^rr[] = {B(0)};
+  )cpp");
+
+  TestTU TU = TestTU::withCode(T.code());
+  auto AST = TU.build();
+  auto H = getHover(AST, T.point(), format::getLLVMStyle(), nullptr);
+
+  ASSERT_TRUE(H);
+  EXPECT_EQ(H->Definition, "int arr[]");
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -126,7 +126,14 @@
   return "";
 }
 
-std::string printDefinition(const Decl *D, const PrintingPolicy &PP) {
+std::string printDefinition(const Decl *D, PrintingPolicy PP,
+const syntax::TokenBuffer &TB) {
+  if (auto *VD = llvm::dyn_cast(D)) {
+if (auto *IE = VD->getInit()) {
+  if (200 < TB.expandedTokens(IE->getSourceRange()).size())
+PP.SuppressInitializers = true;
+}
+  }
   std::string Definition;
   llvm::raw_string_ostream OS(Definition);
   D->print(OS, PP);
@@ -568,7 +575,8 @@
 
 /// Generate a \p Hover object given the declaration \p D.
 HoverInfo getHoverContents(const NamedDecl *D, const PrintingPolicy &PP,
-   const SymbolIndex *Index) {
+   const SymbolIndex *Index,
+   const syntax::TokenBuffer &TB) {
   HoverInfo HI;
   const ASTContext &Ctx = D->getASTContext();
 
@@ -630,7 +638,7 @@
   HI.Value = toString(ECD->getInitVal(), 10);
   }
 
-  HI.Definition = printDefinition(D, PP);
+  HI.Definition = printDefinition(D, PP, TB);
   return HI;
 }
 
@@ -1029,7 +1037,7 @@
   auto Decls = explicitReferenceTargets(N->ASTNode, DeclRelation::Alias,
 AST.getHeuristicResolver());
   if (!Decls.empty()) {
-HI = getHoverContents(Decls.front(), PP, Index);
+HI = getHoverContents(Decls.front(), PP, Index, TB);
 // Layout info only shown when hovering on the field/class itself.
 if (Decls.front() == N->ASTNode.get())
   addLayoutInfo(*Decls.front(), *HI);


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -3172,6 +3172,20 @@
   EXPECT_EQ(H->Type, HoverInfo::PrintedType("m_int"));
 }
 
+TEST(Hover, HideBigInitializers) {
+  Annotations T(R"cpp(
+  #define A(x) x, x, x, x
+  #define B(x) A(A(A(A(x
+  int a^rr[] = {B(0)};
+  )cpp");
+
+  TestTU TU = TestTU::withCode(T.code());
+  auto AST = TU.build();
+  auto H = getHover(AST, T.point(), format::getLLVMStyle(), nullptr);
+
+  ASSERT_TRUE(H);
+  EXPECT_EQ(H->Definition, "int arr[]");
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -126,7 +126,14 @@
   return "";
 }
 
-std::string printDefinition(const Decl *D, const PrintingPolicy &PP) {
+std::string printDefinition(const Decl *D, PrintingPolicy PP,
+const syntax::TokenBuffer &TB) {
+  if (auto *VD = llvm::dyn_cast(D)) {
+if (auto *IE = VD->getInit()) {
+  if (200 < TB.expandedTokens(IE->getSourceRange()).size())
+PP.SuppressInitializers = true;
+}
+  }
   std::string Definition;
   llvm::raw_string_ostream OS(Definition);
   D->print(OS, PP);
@@ -568,7 +575,8 @@
 
 /// Generate a \p Hover object given the declaration \p D.
 HoverInfo getHoverContents(const NamedDecl *D, const PrintingPolicy &PP,
-   const SymbolIndex *Index) {

[PATCH] D118158: [OpenCL] opencl-c.h: refactor named addrspace builtins

2022-01-26 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia accepted this revision.
Anastasia added a comment.
This revision is now accepted and ready to land.

LGTM, aside from the name that can be fixed on a final commit!




Comment at: clang/lib/Headers/opencl-c-base.h:78
+// space overloads for builtin functions that take a pointer argument.
+#define __opencl_c_named_addrsp_builtins 1
+#endif // !defined(__opencl_c_generic_address_space)

I think for consistency it's better to spell `addrsp` -> `address_space` as we 
don't gain much space anyway...

Or maybe we could use `__opencl_c_builtins_with_named_address_spaces`?



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118158

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


[clang] a2fe81f - [clang] NFC: Use flush() idiomatically

2022-01-26 Thread Kirill Bobyrev via cfe-commits

Author: Kirill Bobyrev
Date: 2022-01-26T18:24:38+01:00
New Revision: a2fe81f32c3a2772e49cbd5978db4e5812a3

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

LOG: [clang] NFC: Use flush() idiomatically

Using both `raw_ostream::flush()` and `raw_ostream::str()` consecutively is
redundant. The alternatives are:

- Use `raw_ostream::str()` without `raw_ostream::flush()`
- Use `raw_ostream::flush()` and then use the destination for `raw_ostream`
  writer

The latter is more idiomatic, so the fix resolves this particular case in its
favor.

Reviewed By: kadircet

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

Added: 


Modified: 
clang/lib/AST/DeclPrinter.cpp

Removed: 




diff  --git a/clang/lib/AST/DeclPrinter.cpp b/clang/lib/AST/DeclPrinter.cpp
index 715da7e0d90c5..c3f1d1544f79a 100644
--- a/clang/lib/AST/DeclPrinter.cpp
+++ b/clang/lib/AST/DeclPrinter.cpp
@@ -588,7 +588,7 @@ static void printExplicitSpecifier(ExplicitSpecifier ES, 
llvm::raw_ostream &Out,
   }
   EOut << " ";
   EOut.flush();
-  Out << EOut.str();
+  Out << Proto;
 }
 
 void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) {



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


[PATCH] D118247: [clang] NFC: Use flush() idiomatically

2022-01-26 Thread Kirill Bobyrev via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa2fe81f32c3a: [clang] NFC: Use flush() idiomatically 
(authored by kbobyrev).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118247

Files:
  clang/lib/AST/DeclPrinter.cpp


Index: clang/lib/AST/DeclPrinter.cpp
===
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -588,7 +588,7 @@
   }
   EOut << " ";
   EOut.flush();
-  Out << EOut.str();
+  Out << Proto;
 }
 
 void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) {


Index: clang/lib/AST/DeclPrinter.cpp
===
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -588,7 +588,7 @@
   }
   EOut << " ";
   EOut.flush();
-  Out << EOut.str();
+  Out << Proto;
 }
 
 void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 3595189 - [clang][dataflow] Allow clients to disable built-in transfer functions.

2022-01-26 Thread Yitzhak Mandelbaum via cfe-commits

Author: Yitzhak Mandelbaum
Date: 2022-01-26T17:24:59Z
New Revision: 3595189217e684fcdaa87a78077d97f29549f560

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

LOG: [clang][dataflow] Allow clients to disable built-in transfer functions.

These built-in functions build the (sophisticated) model of the code's
memory. This model isn't used by all analyses, so we provide for disabling it to
avoid incurring the costs associated with its construction.

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

Added: 


Modified: 
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h
clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
clang/unittests/Analysis/FlowSensitive/NoopAnalysis.h
clang/unittests/Analysis/FlowSensitive/TestingSupportTest.cpp
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp

Removed: 




diff  --git a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h 
b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
index 38a64a277412b..f327abe63751f 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
@@ -62,6 +62,8 @@ class DataflowAnalysis : public TypeErasedDataflowAnalysis {
   using Lattice = LatticeT;
 
   explicit DataflowAnalysis(ASTContext &Context) : Context(Context) {}
+  explicit DataflowAnalysis(ASTContext &Context, bool ApplyBuiltinTransfer)
+  : TypeErasedDataflowAnalysis(ApplyBuiltinTransfer), Context(Context) {}
 
   ASTContext &getASTContext() final { return Context; }
 

diff  --git 
a/clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h 
b/clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h
index 3c25c8fc2f28f..9f44475b14ba1 100644
--- a/clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h
+++ b/clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h
@@ -41,7 +41,17 @@ struct TypeErasedLattice {
 
 /// Type-erased base class for dataflow analyses built on a single lattice 
type.
 class TypeErasedDataflowAnalysis : public Environment::Merger {
+  /// Determines whether to apply the built-in transfer functions.
+  // FIXME: Remove this option once the framework supports composing analyses
+  // (at which point the built-in transfer functions can be simply a standalone
+  // analysis).
+  bool ApplyBuiltinTransfer;
+
 public:
+  TypeErasedDataflowAnalysis() : ApplyBuiltinTransfer(true) {}
+  TypeErasedDataflowAnalysis(bool ApplyBuiltinTransfer)
+  : ApplyBuiltinTransfer(ApplyBuiltinTransfer) {}
+
   virtual ~TypeErasedDataflowAnalysis() {}
 
   /// Returns the `ASTContext` that is used by the analysis.
@@ -66,6 +76,10 @@ class TypeErasedDataflowAnalysis : public 
Environment::Merger {
   /// type-erased lattice element.
   virtual void transferTypeErased(const Stmt *, TypeErasedLattice &,
   Environment &) = 0;
+
+  /// Determines whether to apply the built-in transfer functions, which model
+  /// the heap and stack in the `Environment`.
+  bool applyBuiltinTransfer() const { return ApplyBuiltinTransfer; }
 };
 
 /// Type-erased model of the program at a given program point.

diff  --git a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp 
b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
index 0a5f89ce41ad2..aaf6a834f5b3a 100644
--- a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -119,7 +119,8 @@ transferCFGStmt(const CFGStmt &CfgStmt, 
TypeErasedDataflowAnalysis &Analysis,
   const Stmt *S = CfgStmt.getStmt();
   assert(S != nullptr);
 
-  transfer(*S, State.Env);
+  if (Analysis.applyBuiltinTransfer())
+transfer(*S, State.Env);
   Analysis.transferTypeErased(S, State.Lattice, State.Env);
 
   if (HandleTransferredStmt != nullptr)
@@ -178,7 +179,8 @@ TypeErasedDataflowAnalysisState transferBlock(
   HandleTransferredStmt);
   break;
 case CFGElement::Initializer:
-  transferCFGInitializer(*Element.getAs(), State);
+  if (Analysis.applyBuiltinTransfer())
+transferCFGInitializer(*Element.getAs(), State);
   break;
 default:
   // FIXME: Evaluate other kinds of `CFGElement`.

diff  --git a/clang/unittests/Analysis/FlowSensitive/NoopAnalysis.h 
b/clang/unittests/Analysis/FlowSensitive/NoopAnalysis.h
index fc24a2b71421b..eab5782095bbc 100644
--- a/clang/unittests/Analysis/FlowSensitive/NoopAnalysis.h
+++ b/clang/unittests/Analysis/FlowSensitive/NoopAnalysis.h
@@ -39,

[PATCH] D118178: [clang][dataflow] Allow clients to disable built-in transfer functions.

2022-01-26 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3595189217e6: [clang][dataflow] Allow clients to disable 
built-in transfer functions. (authored by ymandel).

Changed prior to commit:
  https://reviews.llvm.org/D118178?vs=403296&id=403314#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118178

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
  clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h
  clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
  clang/unittests/Analysis/FlowSensitive/NoopAnalysis.h
  clang/unittests/Analysis/FlowSensitive/TestingSupportTest.cpp
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
  clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -51,6 +51,8 @@
 template 
 class AnalysisCallback : public ast_matchers::MatchFinder::MatchCallback {
 public:
+  AnalysisCallback(AnalysisT (*MakeAnalysis)(ASTContext &))
+  : MakeAnalysis(MakeAnalysis) {}
   void run(const ast_matchers::MatchFinder::MatchResult &Result) override {
 assert(BlockStates.empty());
 
@@ -63,12 +65,13 @@
 auto CFCtx = llvm::cantFail(
 ControlFlowContext::build(nullptr, Body, Result.Context));
 
-AnalysisT Analysis(*Result.Context);
+AnalysisT Analysis = MakeAnalysis(*Result.Context);
 DataflowAnalysisContext DACtx;
 Environment Env(DACtx);
 BlockStates = runDataflowAnalysis(CFCtx, Analysis, Env);
   }
 
+  AnalysisT (*MakeAnalysis)(ASTContext &);
   std::vector<
   llvm::Optional>>
   BlockStates;
@@ -76,11 +79,11 @@
 
 template 
 std::vector>>
-runAnalysis(llvm::StringRef Code) {
+runAnalysis(llvm::StringRef Code, AnalysisT (*MakeAnalysis)(ASTContext &)) {
   std::unique_ptr AST =
   tooling::buildASTFromCodeWithArgs(Code, {"-std=c++11"});
 
-  AnalysisCallback Callback;
+  AnalysisCallback Callback(MakeAnalysis);
   ast_matchers::MatchFinder Finder;
   Finder.addMatcher(
   ast_matchers::functionDecl(ast_matchers::hasName("target")).bind("func"),
@@ -91,9 +94,8 @@
 }
 
 TEST(DataflowAnalysisTest, NoopAnalysis) {
-  auto BlockStates = runAnalysis(R"(
-void target() {}
-  )");
+  auto BlockStates = runAnalysis(
+  "void target() {}", [](ASTContext &C) { return NoopAnalysis(C, false); });
   EXPECT_EQ(BlockStates.size(), 2u);
   EXPECT_TRUE(BlockStates[0].hasValue());
   EXPECT_TRUE(BlockStates[1].hasValue());
@@ -118,8 +120,9 @@
 : public DataflowAnalysis {
 public:
   explicit NonConvergingAnalysis(ASTContext &Context)
-  : DataflowAnalysis(Context) {
-  }
+  : DataflowAnalysis(
+Context,
+/*ApplyBuiltinTransfer=*/false) {}
 
   static NonConvergingLattice initialElement() { return {0}; }
 
@@ -129,11 +132,13 @@
 };
 
 TEST(DataflowAnalysisTest, NonConvergingAnalysis) {
-  auto BlockStates = runAnalysis(R"(
+  auto BlockStates = runAnalysis(
+  R"(
 void target() {
   while(true) {}
 }
-  )");
+  )",
+  [](ASTContext &C) { return NonConvergingAnalysis(C); });
   EXPECT_EQ(BlockStates.size(), 4u);
   EXPECT_TRUE(BlockStates[0].hasValue());
   EXPECT_TRUE(BlockStates[1].hasValue());
Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -40,11 +40,14 @@
 protected:
   template 
   void runDataflow(llvm::StringRef Code, Matcher Match,
-   LangStandard::Kind Std = LangStandard::lang_cxx17) {
+   LangStandard::Kind Std = LangStandard::lang_cxx17,
+   bool ApplyBuiltinTransfer = true) {
 ASSERT_THAT_ERROR(
 test::checkDataflow(
 Code, "target",
-[](ASTContext &C, Environment &) { return NoopAnalysis(C); },
+[ApplyBuiltinTransfer](ASTContext &C, Environment &) {
+  return NoopAnalysis(C, ApplyBuiltinTransfer);
+},
 [&Match](
 llvm::ArrayRef<
 std::pair>>
@@ -58,6 +61,31 @@
   }
 };
 
+TEST_F(TransferTest, IntVarDeclNotTrackedWhenTransferDisabled) {
+  std::string Code = R"(
+void target() {
+  int Foo;
+  // [[p]]
+}
+  )";
+  runDataflow(
+  Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results

[PATCH] D118070: Add /winsysroot support to lld

2022-01-26 Thread Peter Kasting via Phabricator via cfe-commits
pkasting updated this revision to Diff 403316.
pkasting edited the summary of this revision.
pkasting added a comment.

Functional, but not yet refactored to share code with clang-cl.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118070

Files:
  clang/docs/tools/clang-formatted-files.txt
  clang/lib/Driver/ToolChains/MSVC.cpp
  clang/lib/Driver/ToolChains/MSVCSetupApi.h
  lld/COFF/Driver.cpp
  lld/COFF/Driver.h
  lld/COFF/Options.td
  lld/COFF/SymbolTable.cpp
  llvm/include/llvm/Support/MSVCSetupApi.h
  utils/bazel/llvm-project-overlay/clang/BUILD.bazel

Index: utils/bazel/llvm-project-overlay/clang/BUILD.bazel
===
--- utils/bazel/llvm-project-overlay/clang/BUILD.bazel
+++ utils/bazel/llvm-project-overlay/clang/BUILD.bazel
@@ -1309,9 +1309,6 @@
 "lib/Driver/ToolChains/Arch/*.cpp",
 "lib/Driver/ToolChains/Arch/*.h",
 ],
-exclude = [
-"lib/Driver/ToolChains/MSVCSetupApi.h",
-],
 ),
 hdrs = glob([
 "include/clang/Driver/*.h",
Index: lld/COFF/SymbolTable.cpp
===
--- lld/COFF/SymbolTable.cpp
+++ lld/COFF/SymbolTable.cpp
@@ -56,6 +56,7 @@
   MachineTypes mt = file->getMachineType();
   if (config->machine == IMAGE_FILE_MACHINE_UNKNOWN) {
 config->machine = mt;
+driver->addWinSysRootLibSearchPaths();
   } else if (mt != IMAGE_FILE_MACHINE_UNKNOWN && config->machine != mt) {
 error(toString(file) + ": machine type " + machineToStr(mt) +
   " conflicts with " + machineToStr(config->machine));
Index: lld/COFF/Options.td
===
--- lld/COFF/Options.td
+++ lld/COFF/Options.td
@@ -41,6 +41,7 @@
 MetaVarName<"[auto,always,never]">;
 def defaultlib : P<"defaultlib", "Add the library to the list of input files">;
 def delayload : P<"delayload", "Delay loaded DLL name">;
+def diasdkdir : P<"diasdkdir", "Set the location of the DIA SDK">;
 def entry   : P<"entry", "Name of entry point symbol">;
 def errorlimit : P<"errorlimit",
 "Maximum number of errors to emit before stopping (0 = no limit)">;
@@ -89,9 +90,16 @@
 def stub: P<"stub", "Specify DOS stub file">;
 def subsystem : P<"subsystem", "Specify subsystem">;
 def timestamp : P<"timestamp", "Specify the PE header timestamp">;
+def vctoolsdir : P<"vctoolsdir", "Set the location of the VC tools">;
+def vctoolsversion : P<"vctoolsversion",
+"Specify which VC tools version to use">;
 def version : P<"version", "Specify a version number in the PE header">;
 def wholearchive_file : P<"wholearchive",
 "Include all object files from this library">;
+def winsdkdir : P<"winsdkdir", "Set the location of the Windows SDK">;
+def winsdkversion : P<"winsdkversion", "Specify which SDK version to use">;
+def winsysroot : P<"winsysroot",
+"Adds several subdirectories to the library search paths">;
 
 def disallowlib : Joined<["/", "-", "/?", "-?"], "disallowlib:">,
 Alias;
Index: lld/COFF/Driver.h
===
--- lld/COFF/Driver.h
+++ lld/COFF/Driver.h
@@ -36,6 +36,12 @@
 using llvm::COFF::WindowsSubsystem;
 using llvm::Optional;
 
+enum class ToolsetLayout {
+  OlderVS,
+  VS2017OrNewer,
+  DevDivInternal,
+};
+
 class COFFOptTable : public llvm::opt::OptTable {
 public:
   COFFOptTable();
@@ -82,6 +88,10 @@
 
   void linkerMain(llvm::ArrayRef args);
 
+  // Adds various search paths based on the sysroot.  Must only be called once
+  // config->machine has been set.
+  void addWinSysRootLibSearchPaths();
+
   // Used by the resolver to parse .drectve section contents.
   void parseDirectives(InputFile *file);
 
@@ -107,11 +117,17 @@
 
   bool findUnderscoreMangle(StringRef sym);
 
+  // Determines the location of the sysroot based on `args`, environment, etc.
+  void detectWinSysRoot(const llvm::opt::InputArgList &args);
+
+  void getUniversalCRTLibraryPath(const llvm::opt::InputArgList &Args);
+  void getWindowsSDKLibraryPath(const llvm::opt::InputArgList &Args);
+
   // Parses LIB environment which contains a list of search paths.
   void addLibSearchPaths();
 
   // Library search path. The first element is always "" (current directory).
-  std::vector searchPaths;
+  std::vector searchPaths;
 
   // Convert resource files and potentially merge input resource object
   // trees into one resource tree.
@@ -154,6 +170,14 @@
   llvm::StringSet<> directivesExports;
 
   COFFLinkerContext &ctx;
+
+  ToolsetLayout vsLayout = ToolsetLayout::OlderVS;
+  std::string vcToolChainPath;
+  llvm::SmallString<128> diaPath;
+  bool useWinSysRootLibPath = false;
+  llvm::SmallString<128> universalCRTLibPath;
+  int sdkMajor = 0;
+  llvm::SmallString<128> windowsSdkLibPath;
 };
 
 // Functions below this line are defined in DriverUtils.cpp.
Index: lld/

[PATCH] D116753: Default to -fno-math-errno for musl too

2022-01-26 Thread Stephen Hines via Phabricator via cfe-commits
srhines accepted this revision.
srhines added a comment.
This revision is now accepted and ready to land.

Verified with the docs from musl.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116753

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


[PATCH] D115415: [clang][macho] add clang frontend support for emitting macho files with two build version load commands

2022-01-26 Thread Zhaoyang Li via Phabricator via cfe-commits
zhaoyangli added a comment.

I saw another change trying to add a separate runtime for Mac Catalyst in 
compiler-rt: https://reviews.llvm.org/D117924. I patched that one in and it 
looks worked for us.

Also friendly pinging for this change (and catalyst support in compiler-rt). We 
were kind of blocked by this in chromium :)


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

https://reviews.llvm.org/D115415

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


[PATCH] D116541: [OpenMP] Introduce new flag to change offloading driver pipeline

2022-01-26 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield accepted this revision.
JonChesterfield added a comment.
This revision is now accepted and ready to land.

This looks reasonable to me, though I'd prefer we keep the forward declare. The 
scalar->vector transform is mechanical and the `if 
(Args.hasArg(options::OPT_fopenmp_new_driver))` cruft will disappear when we 
return to a single driver implementation.




Comment at: clang/include/clang/Driver/Driver.h:45
+class Command;
+class Compilation;
+class JobList;

This looks like it should be a breaking change - InputInfo is no longer forward 
declared. Would it be reasonable to keep the forward declaration and put the 
typedef between class statements and the LTOKind enum?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116541

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


[PATCH] D117262: [NFC] Store Address's alignment into PointerIntPairs

2022-01-26 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks updated this revision to Diff 403323.
aeubanks added a comment.

address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117262

Files:
  clang/lib/CodeGen/Address.h

Index: clang/lib/CodeGen/Address.h
===
--- clang/lib/CodeGen/Address.h
+++ clang/lib/CodeGen/Address.h
@@ -14,30 +14,79 @@
 #ifndef LLVM_CLANG_LIB_CODEGEN_ADDRESS_H
 #define LLVM_CLANG_LIB_CODEGEN_ADDRESS_H
 
-#include "llvm/IR/Constants.h"
 #include "clang/AST/CharUnits.h"
+#include "llvm/ADT/PointerIntPair.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/Support/MathExtras.h"
 
 namespace clang {
 namespace CodeGen {
 
-/// An aligned address.
-class Address {
+namespace {
+// We try to save some space by using 6 bits over two PointerIntPairs to store
+// the alignment. However, some arches don't support 3 bits in a PointerIntPair
+// so we fallback to storing the alignment separately.
+template = 8> class AddressImpl {};
+
+template  class AddressImpl {
   llvm::Value *Pointer;
   llvm::Type *ElementType;
   CharUnits Alignment;
 
+public:
+  AddressImpl(llvm::Value *Pointer, llvm::Type *ElementType,
+  CharUnits Alignment)
+  : Pointer(Pointer), ElementType(ElementType), Alignment(Alignment) {}
+  llvm::Value *getPointer() const { return Pointer; }
+  llvm::Type *getElementType() const { return ElementType; }
+  CharUnits getAlignment() const { return Alignment; }
+};
+
+template  class AddressImpl {
+  // Int portion stores upper 3 bits of the log of the alignment.
+  llvm::PointerIntPair Pointer;
+  // Int portion stores lower 3 bits of the log of the alignment.
+  llvm::PointerIntPair ElementType;
+
+public:
+  AddressImpl(llvm::Value *Pointer, llvm::Type *ElementType,
+  CharUnits Alignment)
+  : Pointer(Pointer), ElementType(ElementType) {
+if (Alignment.isZero())
+  return;
+// Currently the max supported alignment is much less than 1 << 63 and is
+// guaranteed to be a power of 2, so we can store the log of the alignment
+// into 6 bits.
+assert(Alignment.isPowerOfTwo() && "Alignment cannot be zero");
+auto AlignLog = llvm::Log2_64(Alignment.getQuantity());
+assert(AlignLog < (1 << 6) && "cannot fit alignment into 6 bits");
+this->Pointer.setInt(AlignLog >> 3);
+this->ElementType.setInt(AlignLog & 7);
+  }
+  llvm::Value *getPointer() const { return Pointer.getPointer(); }
+  llvm::Type *getElementType() const { return ElementType.getPointer(); }
+  CharUnits getAlignment() const {
+unsigned AlignLog = (Pointer.getInt() << 3) | ElementType.getInt();
+return CharUnits::fromQuantity(1UL << AlignLog);
+  }
+};
+} // namespace
+
+/// An aligned address.
+class Address {
+  AddressImpl A;
+
 protected:
-  Address(std::nullptr_t) : Pointer(nullptr), ElementType(nullptr) {}
+  Address(std::nullptr_t) : A(nullptr, nullptr, CharUnits::Zero()) {}
 
 public:
-  Address(llvm::Value *pointer, llvm::Type *elementType, CharUnits alignment)
-  : Pointer(pointer), ElementType(elementType), Alignment(alignment) {
-assert(pointer != nullptr && "Pointer cannot be null");
-assert(elementType != nullptr && "Element type cannot be null");
-assert(llvm::cast(pointer->getType())
-   ->isOpaqueOrPointeeTypeMatches(elementType) &&
+  Address(llvm::Value *Pointer, llvm::Type *ElementType, CharUnits Alignment)
+  : A(Pointer, ElementType, Alignment) {
+assert(Pointer != nullptr && "Pointer cannot be null");
+assert(ElementType != nullptr && "Element type cannot be null");
+assert(llvm::cast(Pointer->getType())
+   ->isOpaqueOrPointeeTypeMatches(ElementType) &&
"Incorrect pointer element type");
-assert(!alignment.isZero() && "Alignment cannot be zero");
   }
 
   // Deprecated: Use constructor with explicit element type instead.
@@ -46,11 +95,11 @@
 Alignment) {}
 
   static Address invalid() { return Address(nullptr); }
-  bool isValid() const { return Pointer != nullptr; }
+  bool isValid() const { return A.getPointer() != nullptr; }
 
   llvm::Value *getPointer() const {
 assert(isValid());
-return Pointer;
+return A.getPointer();
   }
 
   /// Return the type of the pointer value.
@@ -61,7 +110,7 @@
   /// Return the type of the values stored in this address.
   llvm::Type *getElementType() const {
 assert(isValid());
-return ElementType;
+return A.getElementType();
   }
 
   /// Return the address space that this address resides in.
@@ -77,19 +126,19 @@
   /// Return the alignment of this pointer.
   CharUnits getAlignment() const {
 assert(isValid());
-return Alignment;
+return A.getAlignment();
   }
 
   /// Return address with different pointer, but same element type and
   /// alignment.
   Address withPointer(llvm::Value *NewPointer) const {
-return Address(NewPointer, ElementTyp

[PATCH] D117262: [NFC] Store Address's alignment into PointerIntPairs

2022-01-26 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks added inline comments.



Comment at: clang/lib/CodeGen/Address.h:29
+// so we fallback to storing the alignment separately.
+template = 8> class AddressImpl {};
+

nikic wrote:
> Why do we need the extra T parameter?
without it we end up instantiating `AddressImpl` unconditionally (because 
all template parameters are known?) which static_asserts in 32 bit builds


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117262

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


[PATCH] D117262: [NFC] Store Address's alignment into PointerIntPairs

2022-01-26 Thread Nikita Popov via Phabricator via cfe-commits
nikic accepted this revision.
nikic added a comment.
This revision is now accepted and ready to land.

LG from my side


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117262

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


[PATCH] D116542: [OpenMP] Add a flag for embedding a file into the module

2022-01-26 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield requested changes to this revision.
JonChesterfield added a comment.
This revision now requires changes to proceed.

I don't think this works for multiple files. The test only tries one and misses 
all the parsing handling.




Comment at: clang/include/clang/Basic/CodeGenOptions.h:279
 
+  /// List of file passed with -fembed-offload-binary option to embed
+  /// device-side offloading binaries in the host object file.

This is unclear. List in what sense? It's a std::string, which suggests it's a 
freeform argument that gets parsed somewhere else.

The relation between the two strings is also unclear. Are the lists meant to be 
the same length, implying a one to one mapping? If there is a strong relation 
between the two we can probably remove a bunch of error handling by taking one 
argument instead of two.

Perhaps the variable should be something like a vector>?



Comment at: clang/lib/CodeGen/BackendUtil.cpp:1757
+
+  assert(BinaryFilenames.size() == BinarySections.size() &&
+ "Different number of filenames and section names in embedding");

Definitely don't want to assert on invalid commandline argument



Comment at: clang/lib/CodeGen/BackendUtil.cpp:1774
+  SectionName += ".";
+  SectionName += *BinarySection;
+}

This looks lossy - if two files use the same section name, they'll end up 
appended in an order that is probably an implementation quirk of llvm-link, and 
I think we've thrown away the filename info so can't get back to where we were.

Would .llvm.offloading.filename be a reasonable name for each section, with 
either error on duplicates or warning + discard?



Comment at: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp:4982
+  Type *UsedElementType = Type::getInt8Ty(M.getContext())->getPointerTo(0);
+  GlobalVariable *Used = collectUsedGlobalVariables(M, UsedGlobals, true);
+  for (auto *GV : UsedGlobals) {

I think I've written some handling very like this in an LDS pass that I meant 
to factor out for reuse but haven't got around to - we're removing a value from 
compiler.used?



Comment at: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp:4983
+  GlobalVariable *Used = collectUsedGlobalVariables(M, UsedGlobals, true);
+  for (auto *GV : UsedGlobals) {
+if (!GV->getName().startswith("llvm.embedded.object"))

This removes all variables with that prefix



Comment at: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp:4994
+
+  // Embed the data in the
+  llvm::Constant *ModuleConstant =

missing end of comment



Comment at: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp:5003
+  // sections after linking.
+  GV->setAlignment(Align(1));
+  UsedArray.push_back(

Is this necessary? 1 seems a likely default for a uint8_t array



Comment at: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp:5007
+
+  // Recreate llvm.compiler.used.
+  ArrayType *ATy = ArrayType::get(UsedElementType, UsedArray.size());

And this pushes one global back into that array

So this looks like it'll mark the last embedded file as .used and none of the 
others


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116542

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


  1   2   >