[PATCH] D141910: [OpenMP][OMPIRBuilder]Move SIMD alignment calculation to LLVM Frontend

2023-02-08 Thread Dominik Adamski via Phabricator via cfe-commits
domada added a comment.

@akyrtzi Thank you for your feedback. Can I land the patch?


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

https://reviews.llvm.org/D141910

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


[PATCH] D143096: [clangd] Provide patched diagnostics with preamble patch

2023-02-08 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/ParsedAST.cpp:678
+if (Preamble) {
+  auto PDiags = Patch->patchedDiags();
+  Diags->insert(Diags->end(), PDiags.begin(), PDiags.end());

llvm::append_range(Diags, Patch->patchedDiags()) ?



Comment at: clang-tools-extra/clangd/Preamble.cpp:373
   SP.Includes = std::move(Includes.MainFileIncludes);
+  for (auto Pos = Contents.find('\n'); Pos != Contents.npos;
+   Contents = Contents.substr(Pos + 1), Pos = Contents.find('\n')) {

llvm::append_range(SP.Lines, llvm::split(Contents, "\n")) ?



Comment at: clang-tools-extra/clangd/Preamble.cpp:639
 
+// Checks if all pointers in \p D are for the same line of the main file.
+static bool diagReferencesMultipleLines(const Diag &D) {

nit: comment sense is the opposite of the function name

maybe say why this is an important property, or give the function a 
higher-level name?



Comment at: clang-tools-extra/clangd/Preamble.cpp:640
+// Checks if all pointers in \p D are for the same line of the main file.
+static bool diagReferencesMultipleLines(const Diag &D) {
+  int Line = D.Range.start.line;

this function + translateDiag look like a validate/parse pair that need to be 
kept in sync.

they could be a single `translateDiag()` function that could fail, instead.



Comment at: clang-tools-extra/clangd/Preamble.cpp:645
+  bool NotePointsToOutside = llvm::any_of(D.Notes, [&](const Note &N) {
+return N.File == D.File &&
+   (N.Range.start.line != Line || N.Range.end.line != Line);

this check looks dubious to me:
 - `File` is a human-readable string with ill-defined format, comparing them 
for equality isn't safe, you want InsideMainFile instead
 - if the note points to another file, then it's not that translation is 
impossible, but rather no translation is needed
 - if the note points to the same file, then why can't we apply the same 
translation?

I think this should rather be something like:
```
bool translateDiag(DiagBase& D, bool IsMainDiag) {
  if (IsMainDiag) {
for (const auto& N : cast(D).Notes) {
  if (!translateDiag(N, /*IsMainDiag=*/false))
return false;
}
  }
  if (D.InsideMainFile) {
// attempt patching range of D itself
  }
}
```




Comment at: clang-tools-extra/clangd/Preamble.cpp:680
+static llvm::DenseMap>
+mapDiagsToLines(llvm::ArrayRef Diags) {
+  llvm::DenseMap> LineToDiags;

nit: name seems backwards (but as noted below I think this function can go away 
entirely)



Comment at: clang-tools-extra/clangd/Preamble.cpp:705
+// same spelling.
+static std::vector patchDiags(llvm::ArrayRef BaselineDiags,
+const ScannedPreamble &BaselineScan,

If I'm understanding the algorithm right:
 - we make a map of line content => original line number
 - we iterate through each line of the modified preamble, and:
- find the corresponding original line
- look for diagnostics to translate

Why not loop over diagnostics instead of lines in the modified preamble? There 
should be a lot fewer, and you avoid the lines-to-diags map.



Comment at: clang-tools-extra/clangd/Preamble.cpp:707
+const ScannedPreamble &BaselineScan,
+const ScannedPreamble &ModifiedScan) {
+  std::vector PatchedDiags;

large preamble with no diagnostics seems pretty plausible, maybe bail out early 
to avoid building the content map?



Comment at: clang-tools-extra/clangd/Preamble.cpp:795
 // Baseline for exclusion.
-llvm::DenseMap,
-   const Inclusion *>
-ExistingIncludes;
-for (const auto &Inc : Baseline.Includes.MainFileIncludes)
-  ExistingIncludes[{Inc.Directive, Inc.Written}] = &Inc;
-// There might be includes coming from disabled regions, record these for
-// exclusion too. note that we don't have resolved paths for those.
-for (const auto &Inc : BaselineScan->Includes)
-  ExistingIncludes.try_emplace({Inc.Directive, Inc.Written});
+auto ExistingIncludes =
+getExistingIncludes(*BaselineScan, Baseline.Includes.MainFileIncludes);

I think this change and the IncludeKey class can be reverted now?



Comment at: clang-tools-extra/clangd/Preamble.h:161
 
+  /// Returns diag locations for Modified contents, only contains diags 
attached
+  /// to an #include or #define directive.

the stuff about `#include`/`#define` doesn't seem to correspond to anything in 
the code (obsolete?)
and below



Comment at: clang-tools-extra/clangd/Preamble.h:175
   std::string PatchFileName;
-  /// Includes that are present in both \p Baseline and \p Modified. Used for
-  /

[PATCH] D141910: [OpenMP][OMPIRBuilder]Move SIMD alignment calculation to LLVM Frontend

2023-02-08 Thread Thorsten via Phabricator via cfe-commits
tschuett added a comment.

For AArch64 the default alignment is 0? I would have expected 128.


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

https://reviews.llvm.org/D141910

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


[PATCH] D142932: [NFC] Multilib YAML parsing

2023-02-08 Thread Michael Platings via Phabricator via cfe-commits
michaelplatings added a comment.

In D142932#4111925 , @phosek wrote:

> Do you know if regular expressions are necessary to cover the existing use 
> cases?

Yes. One use case is mapping later architecture versions to the last 
architecture version supported by the multilib. For example, this would map 
armv8 versions after 8.5 to 8.5:

  - regex: target=armv8\.([6-9]|[1-9][0-9]+)-none-eabi
matchFlags: [target=armv8.5-none-eabi]


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142932

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


[clang] 1782e8f - [C++20] [Modules] Allow -fmodule-file== for implementation unit and document the behavior

2023-02-08 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2023-02-08T16:45:00+08:00
New Revision: 1782e8f9e882e8f4fb59968ff555c8c93827ea02

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

LOG: [C++20] [Modules] Allow -fmodule-file== for 
implementation unit and document the behavior

Close https://github.com/llvm/llvm-project/issues/57293.

Previsouly we can't use `-fmodule-file==` for
implementation units, it is a bug. Also the behavior of the above option
is not tested nor documented for C++20 Modules. This patch addresses the
2 problems.

Added: 
clang/test/Modules/cxx20-impl-module-conditionally-load.cppm
clang/test/Modules/cxx20-named-conditionally-load.cppm

Modified: 
clang/docs/StandardCPlusPlusModules.rst
clang/lib/Frontend/CompilerInstance.cpp
clang/lib/Sema/SemaModule.cpp
clang/test/CXX/modules-ts/basic/basic.link/module-declaration.cpp
clang/test/CXX/modules-ts/dcl.dcl/dcl.module/p2.cpp

Removed: 




diff  --git a/clang/docs/StandardCPlusPlusModules.rst 
b/clang/docs/StandardCPlusPlusModules.rst
index 44762fa6b3153..c8dbaa89bbfe1 100644
--- a/clang/docs/StandardCPlusPlusModules.rst
+++ b/clang/docs/StandardCPlusPlusModules.rst
@@ -329,6 +329,12 @@ https://gcc.gnu.org/onlinedocs/gcc-3.0.2/cpp_9.html.
 How to specify the dependent BMIs
 ~
 
+There are 3 methods to specify the dependent BMIs:
+
+* (1) ``-fprebuilt-module-path=``.
+* (2) ``-fmodule-file=``.
+* (3) ``-fmodule-file==``.
+
 The option ``-fprebuilt-module-path`` tells the compiler the path where to 
search for dependent BMIs.
 It may be used multiple times just like ``-I`` for specifying paths for header 
files. The look up rule here is:
 
@@ -337,16 +343,21 @@ It may be used multiple times just like ``-I`` for 
specifying paths for header f
 * (2) When we import partition module unit M:P. The compiler would look up 
M-P.pcm in the
   directories specified by ``-fprebuilt-module-path``.
 
-Another way to specify the dependent BMIs is to use ``-fmodule-file``. The 
main 
diff erence
-is that ``-fprebuilt-module-path`` takes a directory, whereas 
``-fmodule-file`` requires a
-specific file. In case both the ``-fprebuilt-module-path`` and 
``-fmodule-file`` exist, the 
-``-fmodule-file`` option takes higher precedence. In another word, if the 
compiler finds the wanted
-BMI specified by ``-fmodule-file``, the compiler wouldn't look up again in the 
directories specified
-by ``-fprebuilt-module-path``.
-
-When we compile a ``module implementation unit``, we must pass the BMI of the 
corresponding
-``primary module interface unit`` by ``-fmodule-file``
-since the language specification says a module implementation unit implicitly 
imports
+The option ``-fmodule-file=`` tells the compiler to load the 
specified BMI directly.
+The option ``-fmodule-file==`` tells the compiler to 
load the specified BMI
+for the module specified by  when necessary. The main 
diff erence is that
+``-fmodule-file=`` will load the BMI eagerly, whereas
+``-fmodule-file==`` will only load the BMI lazily, 
which is similar
+with ``-fprebuilt-module-path``.
+
+In case all ``-fprebuilt-module-path=``, 
``-fmodule-file=`` and
+``-fmodule-file==`` exist, the 
``-fmodule-file=`` option
+takes highest precedence and ``-fmodule-file==`` 
will take the second
+highest precedence.
+
+When we compile a ``module implementation unit``, we must specify the BMI of 
the corresponding
+``primary module interface unit``.
+Since the language specification says a module implementation unit implicitly 
imports
 the primary module interface unit.
 
   [module.unit]p8
@@ -354,13 +365,15 @@ the primary module interface unit.
   A module-declaration that contains neither an export-keyword nor a 
module-partition implicitly
   imports the primary module interface unit of the module as if by a 
module-import-declaration.
 
-Again, the option ``-fmodule-file`` may occur multiple times.
+All of the 3 options ``-fprebuilt-module-path=``, 
``-fmodule-file=``
+and ``-fmodule-file==`` may occur multiple times.
 For example, the command line to compile ``M.cppm`` in
 the above example could be rewritten into:
 
 .. code-block:: console
 
   $ clang++ -std=c++20 M.cppm --precompile -fmodule-file=M-interface_part.pcm 
-fmodule-file=M-impl_part.pcm -o M.pcm
+  $ clang++ -std=c++20 M.cppm --precompile 
-fmodule-file=M:interface_part=M-interface_part.pcm 
-fmodule-file=M:impl_part=M-impl_part.pcm -o M.pcm
 
 ``-fprebuilt-module-path`` is more convenient and ``-fmodule-file`` is faster 
since
 it saves time for file lookup.

diff  --git a/clang/lib/Frontend/CompilerInstance.cpp 
b/clang/lib/Frontend/CompilerInstance.cpp
index 9c79e856dad4f..4a8a6b607dd75 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp

[PATCH] D143096: [clangd] Provide patched diagnostics with preamble patch

2023-02-08 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/Preamble.cpp:648
+  });
+  if (NotePointsToOutside)
+return true;

Oh yeah, one more thing :-)

Currently if the note/fix aren't at this line we're bailing out of the 
diagnostic entirely.

We have three behaviors available:

1. patch the note/fix range as best we can and emit it
2. drop the note/fix but keep the diagnostic
3. drop the diagnostic entirely

I think we should generally prefer 1 when we can, maybe there's a case for 
choosing 2 sometimes (heuristics about when diagnostics have probably been 
invalidated, with comments), and we should ~never do 3.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143096

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


[PATCH] D143559: [Tooling/Inclusion] Use the StdSpecialSymbolMap.inc in the stdlib

2023-02-08 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: kadircet.
Herald added a subscriber: arphaman.
Herald added a project: All.
hokein requested review of this revision.
Herald added a subscriber: ilya-biryukov.
Herald added projects: clang, clang-tools-extra.

Remove a special-case in clangd.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143559

Files:
  clang-tools-extra/clangd/index/CanonicalIncludes.cpp
  clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
  clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
  clang/unittests/Tooling/StandardLibraryTest.cpp


Index: clang/unittests/Tooling/StandardLibraryTest.cpp
===
--- clang/unittests/Tooling/StandardLibraryTest.cpp
+++ clang/unittests/Tooling/StandardLibraryTest.cpp
@@ -62,6 +62,14 @@
   ElementsAre(stdlib::Header::named(""),
   stdlib::Header::named(""),
   stdlib::Header::named("")));
+  EXPECT_THAT(stdlib::Symbol::named("std::", "size_t")->headers(),
+  ElementsAre(stdlib::Header::named(""),
+  stdlib::Header::named(""),
+  stdlib::Header::named(""),
+  stdlib::Header::named(""),
+  stdlib::Header::named(""),
+  stdlib::Header::named(""),
+  stdlib::Header::named("")));
 
   EXPECT_THAT(stdlib::Header::all(), Contains(*VectorH));
   EXPECT_THAT(stdlib::Symbol::all(), Contains(*Vector));
Index: clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
===
--- clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
+++ clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
@@ -62,6 +62,7 @@
 break;
   case Lang::CXX:
 #include "StdSymbolMap.inc"
+#include "StdSpecialSymbolMap.inc"
 break;
   }
 #undef SYMBOL
@@ -130,6 +131,7 @@
 break;
   case Lang::CXX:
 #include "StdSymbolMap.inc"
+#include "StdSpecialSymbolMap.inc"
 break;
   }
 #undef SYMBOL
Index: clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
===
--- clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
+++ clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
@@ -51,6 +51,7 @@
   EXPECT_EQ("", CI.mapSymbol("std::", "printf", Language));
   // std::move is ambiguous, currently always mapped to 
   EXPECT_EQ("", CI.mapSymbol("std::", "move", Language));
+  EXPECT_EQ("", CI.mapSymbol("std::", "size_t", Language));
   // Unknown std symbols aren't mapped.
   EXPECT_EQ("", CI.mapSymbol("std::", "notathing", Language));
   // iosfwd declares some symbols it doesn't own.
Index: clang-tools-extra/clangd/index/CanonicalIncludes.cpp
===
--- clang-tools-extra/clangd/index/CanonicalIncludes.cpp
+++ clang-tools-extra/clangd/index/CanonicalIncludes.cpp
@@ -716,8 +716,6 @@
   // There are two std::move()s, this is by far the most common.
   if (Scope == "std::" && Name == "move")
 return "";
-  if (Scope == "std::" && Name == "size_t")
-return "";
   if (auto StdSym = tooling::stdlib::Symbol::named(Scope, Name, Lang))
 return StdSym->header().name();
   return "";


Index: clang/unittests/Tooling/StandardLibraryTest.cpp
===
--- clang/unittests/Tooling/StandardLibraryTest.cpp
+++ clang/unittests/Tooling/StandardLibraryTest.cpp
@@ -62,6 +62,14 @@
   ElementsAre(stdlib::Header::named(""),
   stdlib::Header::named(""),
   stdlib::Header::named("")));
+  EXPECT_THAT(stdlib::Symbol::named("std::", "size_t")->headers(),
+  ElementsAre(stdlib::Header::named(""),
+  stdlib::Header::named(""),
+  stdlib::Header::named(""),
+  stdlib::Header::named(""),
+  stdlib::Header::named(""),
+  stdlib::Header::named(""),
+  stdlib::Header::named("")));
 
   EXPECT_THAT(stdlib::Header::all(), Contains(*VectorH));
   EXPECT_THAT(stdlib::Symbol::all(), Contains(*Vector));
Index: clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
===
--- clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
+++ clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
@@ -62,6 +62,7 @@
 break;
   case Lang::CXX:
 #include "StdSymbolMap.inc"
+#include "StdSpecialSymbolMap.inc"
 break;
   }
 #undef SYMBOL
@@ -130,6 +131,7 @@
 break;
   case Lang::CXX:
 #include "StdSymbolMap.inc"
+#include "StdSpecialSymbolMap.inc"
 break;
   }
 #undef SYMBOL
Index: clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
==

[PATCH] D143093: [clangd] #undef macros inside preamble patch

2023-02-08 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/clangd/Preamble.cpp:216
   unsigned Offset;
+  tok::PPKeywordKind Directive;
+  // Name of the macro being defined in the case of a #define directive.

initialize to pp_unknown



Comment at: clang-tools-extra/clangd/unittests/PreambleTests.cpp:678
 // Check ranges for notes.
-Annotations NewCode(("#define [[BARXYZ]] 1\n" + BaselinePreamble +
+Annotations NewCode(("#define BARXYZ 1\n" + BaselinePreamble +
  "void foo();\n#define [[FOO]] 2")

as elsewhere, I think this writing this as a single raw string without reusing 
BaselinePreamble is easier to follow



Comment at: clang-tools-extra/clangd/unittests/PreambleTests.cpp:684
 EXPECT_THAT(mainFileDiagRanges(*AST),
-UnorderedElementsAre(NewCode.ranges()[0], 
NewCode.ranges()[2]));
+UnorderedElementsAre(NewCode.ranges()[1]));
   }

named ranges


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143093

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


[PATCH] D143095: [clangd] Respect preamble-patch when handling diags

2023-02-08 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/clangd/Diagnostics.cpp:102
+  auto PatchedRange = [&M](CharSourceRange &R) {
+// FIXME: Should we handle all presumed locations?
+R.setBegin(translatePreamblePatchLocation(R.getBegin(), M));

I think we answered this in the negative?



Comment at: clang-tools-extra/clangd/Diagnostics.cpp:715
 
-D.InsideMainFile = isInsideMainFile(Info);
+auto PLoc = translatePreamblePatchLocation(Info.getLocation(), SM);
+D.InsideMainFile = isInsideMainFile(PLoc, SM);

PLoc is a confusing name for something that interacts with but is not a 
PresumedLoc

I'd prefer avoiding auto here, too



Comment at: clang-tools-extra/clangd/SourceCode.cpp:1225
+  // Checks whether \p FileName is a valid spelling of main file.
+  auto IsMainFile = [](llvm::StringRef FileName, const SourceManager &SM) {
+auto FE = SM.getFileManager().getFile(FileName);

just make it a function? it captures nothing


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143095

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


[PATCH] D143549: [clang][AIX] Remove test for the default OpenMP runtime

2023-02-08 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert accepted this revision.
jdoerfert added a comment.
This revision is now accepted and ready to land.

LG


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143549

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


[PATCH] D143560: clang-format.el: fix warnings

2023-02-08 Thread Augustin Fabre via Phabricator via cfe-commits
augfab created this revision.
augfab added reviewers: sammccall, phst, djasper.
augfab added a project: clang-format.
Herald added a project: All.
augfab requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Emacs trunk complained about:

  Warning (comp): clang-format.el:87:15: Warning: Case 'replacement will match 
‘quote’.  If that’s intended, write (replacement quote) instead.  Otherwise, 
don’t quote ‘replacement’.
  Warning (comp): clang-format.el:98:15: Warning: Case 'cursor will match 
‘quote’.  If that’s intended, write (cursor quote) instead.  Otherwise, don’t 
quote ‘cursor’. 

Fixed the syntax by applying the suggestion.

Checked that the code works like before the change by stepping through the 
execution of the function.

Ran tests with Emacs 26.3 and Emacs trunk with:

  $ emacs -Q -batch -l clang/tools/clang-format/clang-format.el -l 
clang/tools/clang-format/clang-format-test.el -f ert-run-tests-batch-and-exit


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143560

Files:
  clang/tools/clang-format/clang-format.el


Index: clang/tools/clang-format/clang-format.el
===
--- clang/tools/clang-format/clang-format.el
+++ clang/tools/clang-format/clang-format.el
@@ -82,29 +82,29 @@
 (let* ((children (xml-node-children node))
(text (car children)))
   (cl-case (xml-node-name node)
-('replacement
+((replacement quote)
  (let* ((offset (xml-get-attribute-or-nil node 'offset))
 (length (xml-get-attribute-or-nil node 'length)))
(when (or (null offset) (null length))
  (error " node does not have offset and length 
attributes"))
(when (cdr children)
  (error "More than one child node in  node"))

(setq offset (string-to-number offset))
(setq length (string-to-number length))
(push (list offset length text) replacements)))
-('cursor
+((cursor quote)
  (setq cursor (string-to-number text)))

 ;; Sort by decreasing offset, length.
 (setq replacements (sort (delq nil replacements)
  (lambda (a b)
(or (> (car a) (car b))
(and (= (car a) (car b))
 (> (cadr a) (cadr b)))

 (list replacements cursor (string= incomplete-format "true"

 (defun clang-format--replace (offset length &optional text)
   "Replace the region defined by OFFSET and LENGTH with TEXT.
 OFFSET and LENGTH are measured in bytes, not characters.  OFFSET


Index: clang/tools/clang-format/clang-format.el
===
--- clang/tools/clang-format/clang-format.el
+++ clang/tools/clang-format/clang-format.el
@@ -82,29 +82,29 @@
 (let* ((children (xml-node-children node))
(text (car children)))
   (cl-case (xml-node-name node)
-('replacement
+((replacement quote)
  (let* ((offset (xml-get-attribute-or-nil node 'offset))
 (length (xml-get-attribute-or-nil node 'length)))
(when (or (null offset) (null length))
  (error " node does not have offset and length attributes"))
(when (cdr children)
  (error "More than one child node in  node"))

(setq offset (string-to-number offset))
(setq length (string-to-number length))
(push (list offset length text) replacements)))
-('cursor
+((cursor quote)
  (setq cursor (string-to-number text)))

 ;; Sort by decreasing offset, length.
 (setq replacements (sort (delq nil replacements)
  (lambda (a b)
(or (> (car a) (car b))
(and (= (car a) (car b))
 (> (cadr a) (cadr b)))

 (list replacements cursor (string= incomplete-format "true"

 (defun clang-format--replace (offset length &optional text)
   "Replace the region defined by OFFSET and LENGTH with TEXT.
 OFFSET and LENGTH are measured in bytes, not characters.  OFFSET
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D143070: [clang-format] Enable FormatTokenSource to insert tokens.

2023-02-08 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Only serious concern is `getPreviousToken()`.




Comment at: clang/lib/Format/FormatTokenSource.h:74
 public:
-  IndexedTokenSource(ArrayRef Tokens)
+  IndexedTokenSource(SmallVectorImpl &Tokens)
   : Tokens(Tokens), Position(-1) {}

As I understand it, this parameter is used:
 - to provide the initial set of input tokens the source will iterate over
 - as a common address space for input + synthesized tokens, to allow the jump 
mechanism to work
 - to make the caller responsible for ownership/lifetime of the synthesized 
tokens too

This simplifies the implementation, my only problem with this is it seems 
unusual and confusing.
A comment explaining the roles of this `Tokens` param would help a bit.

Alternatively you could consider slightly different data structures just for 
the purpose of making interfaces more obvious: e.g. pass in a 
`BumpPtrAllocator&`, allocate scratch tokens there, and use pointers instead of 
indices (jumps become a ptr->ptr map etc)



Comment at: clang/lib/Format/FormatTokenSource.h:94
   FormatToken *getPreviousToken() override {
 return Position > 0 ? Tokens[Position - 1] : nullptr;
   }

this no longer seems valid, immediately after calling insertTokens(), Position 
is at the start of a jump range, and Tokens[Position - 1] will be the EOF at 
the end of the main stream or previous jump range.

if this is never going to happen, you can detect it (I don't think 
Tokens[Position - 1] can be EOF in any other way)



Comment at: clang/lib/Format/FormatTokenSource.h:115
 
   unsigned getPosition() override {
 LLVM_DEBUG(llvm::dbgs() << "Getting Position: " << Position << "\n");

maybe add a comment that positions don't have meaningful order and this is only 
useful to restore the position?

(All the callsites look good, it just feels like a trap)



Comment at: clang/lib/Format/FormatTokenSource.h:130
+assert((*New.rbegin())->Tok.is(tok::eof));
+LLVM_DEBUG(llvm::dbgs() << "Inserting:\n");
+int Next = Tokens.size();

nit: move into the LLVM_DEBUG block below? or are you worried about a crash?



Comment at: clang/lib/Format/FormatTokenSource.h:151
 private:
+  int next(int Current) {
+int Next = Current + 1;

nit: const

I wasn't sure if this method advanced or not. "successor" might be clearer in 
this respect



Comment at: clang/lib/Format/FormatTokenSource.h:173
+  // stream continues at position b instead.
+  std::map Jumps;
 };

DenseMap?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143070

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


[PATCH] D143560: clang-format.el: fix warnings

2023-02-08 Thread Philipp via Phabricator via cfe-commits
phst requested changes to this revision.
phst added inline comments.
This revision now requires changes to proceed.



Comment at: clang/tools/clang-format/clang-format.el:70
   (cl-case (xml-node-name node)
-('replacement
+((replacement quote)
  (let* ((offset (xml-get-attribute-or-nil node 'offset))

what's the change here?



Comment at: clang/tools/clang-format/clang-format.el:80
(push (list offset length text) replacements)))
-('cursor
+((cursor quote)
  (setq cursor (string-to-number text)))

same here, what is being changed?



Comment at: clang/tools/clang-format/clang-format.el:85
  (lambda (a b)
(or (> (car a) (car b))
(and (= (car a) (car b))

The intention here is that this should be just `replacement' since I'm pretty 
sure we don't have XML tags like 



Comment at: clang/tools/clang-format/clang-format.el:96
  'utf-8-unix)))
 (goto-char start)
 (delete-region start end)

same here, AIUI this should just be `quote'


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143560

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


[clang] 5ae99be - [clang][AIX] Remove test for the default OpenMP runtime

2023-02-08 Thread via cfe-commits

Author: wangpc
Date: 2023-02-08T17:47:52+08:00
New Revision: 5ae99be0377248c74346096dc475af254a3fc799

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

LOG: [clang][AIX] Remove test for the default OpenMP runtime

The default OpenMP runtime may not be libomp since it can be changed
by specified `CLANG_DEFAULT_OPENMP_RUNTIME`. This test will fail if
we change the default OpenMP runtime.

This patch removes test for the default OpenMP runtime and moves the
CHECKs downward.

Reviewed By: jdoerfert

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

Added: 


Modified: 
clang/test/Driver/aix-ld.c

Removed: 




diff  --git a/clang/test/Driver/aix-ld.c b/clang/test/Driver/aix-ld.c
index ddf3ae7a2ecb4..8f0125c272a69 100644
--- a/clang/test/Driver/aix-ld.c
+++ b/clang/test/Driver/aix-ld.c
@@ -1017,14 +1017,33 @@
 // CHECK-LD64-SHARED-EXPFULL: "-lm"
 // CHECK-LD64-SHARED-EXPFULL: "-lc"
 
-// Check powerpc-ibm-aix7.1.0.0. -fopenmp to use default OpenMP runtime libomp.
+// Check powerpc-ibm-aix7.1.0.0. -fopenmp=libomp to specify libomp explicitly.
 // RUN: %clang %s -### 2>&1 \
 // RUN:-resource-dir=%S/Inputs/resource_dir \
 // RUN:--target=powerpc-ibm-aix7.1.0.0 \
 // RUN:--sysroot %S/Inputs/aix_ppc_tree \
 // RUN:--unwindlib=libunwind \
-// RUN:-fopenmp \
+// RUN:-fopenmp=libomp \
 // RUN:   | FileCheck --check-prefixes=CHECK-FOPENMP,CHECK-FOPENMP-OMP %s
+
+// Check powerpc-ibm-aix7.1.0.0. -fopenmp=libiomp5 to specify libgomp 
explicitly.
+// RUN: %clang %s -### 2>&1 \
+// RUN:-resource-dir=%S/Inputs/resource_dir \
+// RUN:--target=powerpc-ibm-aix7.1.0.0 \
+// RUN:--sysroot %S/Inputs/aix_ppc_tree \
+// RUN:--unwindlib=libunwind \
+// RUN:-fopenmp=libiomp5 \
+// RUN:   | FileCheck --check-prefixes=CHECK-FOPENMP,CHECK-FOPENMP-IOMP5 %s
+
+// Check powerpc-ibm-aix7.1.0.0. -fopenmp=libgomp to specify libgomp 
explicitly.
+// RUN: %clang %s -### 2>&1 \
+// RUN:-resource-dir=%S/Inputs/resource_dir \
+// RUN:--target=powerpc-ibm-aix7.1.0.0 \
+// RUN:--sysroot %S/Inputs/aix_ppc_tree \
+// RUN:--unwindlib=libunwind \
+// RUN:-fopenmp=libgomp \
+// RUN:   | FileCheck --check-prefixes=CHECK-FOPENMP,CHECK-FOPENMP-GOMP %s
+
 // CHECK-FOPENMP-NOT: warning:
 // CHECK-FOPENMP: "-cc1" "-triple" "powerpc-ibm-aix7.1.0.0"
 // CHECK-FOPENMP: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
@@ -1047,33 +1066,6 @@
 // CHECK-FOPENMP-GOMP:"-lgomp"
 // CHECK-FOPENMP: "-lc"
 
-// Check powerpc-ibm-aix7.1.0.0. -fopenmp=libomp to specify libomp explicitly.
-// RUN: %clang %s -### 2>&1 \
-// RUN:-resource-dir=%S/Inputs/resource_dir \
-// RUN:--target=powerpc-ibm-aix7.1.0.0 \
-// RUN:--sysroot %S/Inputs/aix_ppc_tree \
-// RUN:--unwindlib=libunwind \
-// RUN:-fopenmp=libomp \
-// RUN:   | FileCheck --check-prefixes=CHECK-FOPENMP,CHECK-FOPENMP-OMP %s
-
-// Check powerpc-ibm-aix7.1.0.0. -fopenmp=libiomp5 to specify libgomp 
explicitly.
-// RUN: %clang %s -### 2>&1 \
-// RUN:-resource-dir=%S/Inputs/resource_dir \
-// RUN:--target=powerpc-ibm-aix7.1.0.0 \
-// RUN:--sysroot %S/Inputs/aix_ppc_tree \
-// RUN:--unwindlib=libunwind \
-// RUN:-fopenmp=libiomp5 \
-// RUN:   | FileCheck --check-prefixes=CHECK-FOPENMP,CHECK-FOPENMP-IOMP5 %s
-
-// Check powerpc-ibm-aix7.1.0.0. -fopenmp=libgomp to specify libgomp 
explicitly.
-// RUN: %clang %s -### 2>&1 \
-// RUN:-resource-dir=%S/Inputs/resource_dir \
-// RUN:--target=powerpc-ibm-aix7.1.0.0 \
-// RUN:--sysroot %S/Inputs/aix_ppc_tree \
-// RUN:--unwindlib=libunwind \
-// RUN:-fopenmp=libgomp \
-// RUN:   | FileCheck --check-prefixes=CHECK-FOPENMP,CHECK-FOPENMP-GOMP %s
-
 // Check powerpc-ibm-aix7.1.0.0, 32-bit. -fopenmp=libfoo results an error.
 // RUN: %clang %s 2>&1 -### \
 // RUN:--target=powerpc-ibm-aix7.1.0.0 \



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


[PATCH] D143549: [clang][AIX] Remove test for the default OpenMP runtime

2023-02-08 Thread Wang Pengcheng via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5ae99be03772: [clang][AIX] Remove test for the default 
OpenMP runtime (authored by pcwang-thead).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143549

Files:
  clang/test/Driver/aix-ld.c


Index: clang/test/Driver/aix-ld.c
===
--- clang/test/Driver/aix-ld.c
+++ clang/test/Driver/aix-ld.c
@@ -1017,14 +1017,33 @@
 // CHECK-LD64-SHARED-EXPFULL: "-lm"
 // CHECK-LD64-SHARED-EXPFULL: "-lc"
 
-// Check powerpc-ibm-aix7.1.0.0. -fopenmp to use default OpenMP runtime libomp.
+// Check powerpc-ibm-aix7.1.0.0. -fopenmp=libomp to specify libomp explicitly.
 // RUN: %clang %s -### 2>&1 \
 // RUN:-resource-dir=%S/Inputs/resource_dir \
 // RUN:--target=powerpc-ibm-aix7.1.0.0 \
 // RUN:--sysroot %S/Inputs/aix_ppc_tree \
 // RUN:--unwindlib=libunwind \
-// RUN:-fopenmp \
+// RUN:-fopenmp=libomp \
 // RUN:   | FileCheck --check-prefixes=CHECK-FOPENMP,CHECK-FOPENMP-OMP %s
+
+// Check powerpc-ibm-aix7.1.0.0. -fopenmp=libiomp5 to specify libgomp 
explicitly.
+// RUN: %clang %s -### 2>&1 \
+// RUN:-resource-dir=%S/Inputs/resource_dir \
+// RUN:--target=powerpc-ibm-aix7.1.0.0 \
+// RUN:--sysroot %S/Inputs/aix_ppc_tree \
+// RUN:--unwindlib=libunwind \
+// RUN:-fopenmp=libiomp5 \
+// RUN:   | FileCheck --check-prefixes=CHECK-FOPENMP,CHECK-FOPENMP-IOMP5 %s
+
+// Check powerpc-ibm-aix7.1.0.0. -fopenmp=libgomp to specify libgomp 
explicitly.
+// RUN: %clang %s -### 2>&1 \
+// RUN:-resource-dir=%S/Inputs/resource_dir \
+// RUN:--target=powerpc-ibm-aix7.1.0.0 \
+// RUN:--sysroot %S/Inputs/aix_ppc_tree \
+// RUN:--unwindlib=libunwind \
+// RUN:-fopenmp=libgomp \
+// RUN:   | FileCheck --check-prefixes=CHECK-FOPENMP,CHECK-FOPENMP-GOMP %s
+
 // CHECK-FOPENMP-NOT: warning:
 // CHECK-FOPENMP: "-cc1" "-triple" "powerpc-ibm-aix7.1.0.0"
 // CHECK-FOPENMP: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
@@ -1047,33 +1066,6 @@
 // CHECK-FOPENMP-GOMP:"-lgomp"
 // CHECK-FOPENMP: "-lc"
 
-// Check powerpc-ibm-aix7.1.0.0. -fopenmp=libomp to specify libomp explicitly.
-// RUN: %clang %s -### 2>&1 \
-// RUN:-resource-dir=%S/Inputs/resource_dir \
-// RUN:--target=powerpc-ibm-aix7.1.0.0 \
-// RUN:--sysroot %S/Inputs/aix_ppc_tree \
-// RUN:--unwindlib=libunwind \
-// RUN:-fopenmp=libomp \
-// RUN:   | FileCheck --check-prefixes=CHECK-FOPENMP,CHECK-FOPENMP-OMP %s
-
-// Check powerpc-ibm-aix7.1.0.0. -fopenmp=libiomp5 to specify libgomp 
explicitly.
-// RUN: %clang %s -### 2>&1 \
-// RUN:-resource-dir=%S/Inputs/resource_dir \
-// RUN:--target=powerpc-ibm-aix7.1.0.0 \
-// RUN:--sysroot %S/Inputs/aix_ppc_tree \
-// RUN:--unwindlib=libunwind \
-// RUN:-fopenmp=libiomp5 \
-// RUN:   | FileCheck --check-prefixes=CHECK-FOPENMP,CHECK-FOPENMP-IOMP5 %s
-
-// Check powerpc-ibm-aix7.1.0.0. -fopenmp=libgomp to specify libgomp 
explicitly.
-// RUN: %clang %s -### 2>&1 \
-// RUN:-resource-dir=%S/Inputs/resource_dir \
-// RUN:--target=powerpc-ibm-aix7.1.0.0 \
-// RUN:--sysroot %S/Inputs/aix_ppc_tree \
-// RUN:--unwindlib=libunwind \
-// RUN:-fopenmp=libgomp \
-// RUN:   | FileCheck --check-prefixes=CHECK-FOPENMP,CHECK-FOPENMP-GOMP %s
-
 // Check powerpc-ibm-aix7.1.0.0, 32-bit. -fopenmp=libfoo results an error.
 // RUN: %clang %s 2>&1 -### \
 // RUN:--target=powerpc-ibm-aix7.1.0.0 \


Index: clang/test/Driver/aix-ld.c
===
--- clang/test/Driver/aix-ld.c
+++ clang/test/Driver/aix-ld.c
@@ -1017,14 +1017,33 @@
 // CHECK-LD64-SHARED-EXPFULL: "-lm"
 // CHECK-LD64-SHARED-EXPFULL: "-lc"
 
-// Check powerpc-ibm-aix7.1.0.0. -fopenmp to use default OpenMP runtime libomp.
+// Check powerpc-ibm-aix7.1.0.0. -fopenmp=libomp to specify libomp explicitly.
 // RUN: %clang %s -### 2>&1 \
 // RUN:-resource-dir=%S/Inputs/resource_dir \
 // RUN:--target=powerpc-ibm-aix7.1.0.0 \
 // RUN:--sysroot %S/Inputs/aix_ppc_tree \
 // RUN:--unwindlib=libunwind \
-// RUN:-fopenmp \
+// RUN:-fopenmp=libomp \
 // RUN:   | FileCheck --check-prefixes=CHECK-FOPENMP,CHECK-FOPENMP-OMP %s
+
+// Check powerpc-ibm-aix7.1.0.0. -fopenmp=libiomp5 to specify libgomp explicitly.
+// RUN: %clang %s -### 2>&1 \
+// RUN:-resource-dir=%S/Inputs/resource_dir \
+// RUN:--target=powerpc-ibm-aix7.1.0.0 \
+// RUN:--sysroot %S/Inputs/aix_ppc_tree \
+// RUN:--unwindlib=libunwind \
+// RUN:-fopenmp=libiomp5 \
+// RUN:   | FileCheck --check-prefixes=CHECK-FOPENMP,CHECK-FOPENMP-IOMP5 %s
+
+// Check powerpc-ibm-aix7.1.0.0. -fopenmp=libgomp to specify libgomp explicitly.

[PATCH] D143482: [SanitizerBinaryMetadata] Optimize used space for features and UAR stack args

2023-02-08 Thread Dmitry Vyukov via Phabricator via cfe-commits
dvyukov accepted this revision.
dvyukov added a comment.
This revision is now accepted and ready to land.

Nice!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143482

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


[PATCH] D143214: [include-mapping] Add C-compatibility symbol entries.

2023-02-08 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 495771.
hokein added a comment.

update the standard-library tests, and fix a bug.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143214

Files:
  clang/include/clang/Tooling/Inclusions/StandardLibrary.h
  clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
  clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc
  clang/tools/include-mapping/cppreference_parser.py
  clang/tools/include-mapping/gen_std.py
  clang/unittests/Tooling/StandardLibraryTest.cpp

Index: clang/unittests/Tooling/StandardLibraryTest.cpp
===
--- clang/unittests/Tooling/StandardLibraryTest.cpp
+++ clang/unittests/Tooling/StandardLibraryTest.cpp
@@ -65,12 +65,10 @@
 
   EXPECT_THAT(stdlib::Header::all(), Contains(*VectorH));
   EXPECT_THAT(stdlib::Symbol::all(), Contains(*Vector));
-  EXPECT_FALSE(stdlib::Header::named(""));
-  EXPECT_FALSE(stdlib::Header::named("", stdlib::Lang::CXX));
+  EXPECT_TRUE(stdlib::Header::named("", stdlib::Lang::CXX));
   EXPECT_TRUE(stdlib::Header::named("", stdlib::Lang::C));
 
-  EXPECT_FALSE(stdlib::Symbol::named("", "int16_t"));
-  EXPECT_FALSE(stdlib::Symbol::named("", "int16_t", stdlib::Lang::CXX));
+  EXPECT_TRUE(stdlib::Symbol::named("", "int16_t", stdlib::Lang::CXX));
   EXPECT_TRUE(stdlib::Symbol::named("", "int16_t", stdlib::Lang::C));
 }
 
@@ -127,9 +125,9 @@
   EXPECT_EQ(Recognizer(Nest), stdlib::Symbol::named("std::", "vector"));
   EXPECT_EQ(Recognizer(Clock),
 stdlib::Symbol::named("std::chrono::", "system_clock"));
-  EXPECT_EQ(Recognizer(CDivT), stdlib::Symbol::named("", "div_t"));
-  EXPECT_EQ(Recognizer(CDivT),
-stdlib::Symbol::named("", "div_t", stdlib::Lang::C));
+  auto DivT = stdlib::Symbol::named("", "div_t", stdlib::Lang::CXX);
+  EXPECT_TRUE(DivT);
+  EXPECT_EQ(Recognizer(CDivT), DivT);
   EXPECT_EQ(Recognizer(Sec), std::nullopt);
 }
 
Index: clang/tools/include-mapping/gen_std.py
===
--- clang/tools/include-mapping/gen_std.py
+++ clang/tools/include-mapping/gen_std.py
@@ -39,6 +39,7 @@
 import datetime
 import os
 import sys
+import re
 
 
 CODE_PREFIX = """\
@@ -170,6 +171,69 @@
   return headers
 
 
+def GetCCompatibilitySymbols(symbol):
+   # C++ form of the C standard headers.
+  c_compat_headers = {
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+  }
+  # C++ [support.c.headers.other] 17.14.7
+  #..., behaves as if each name placed in the standard library namespace by
+  #the corresponding  header is placed within the global namespace
+  #scope, except for the functions described in [sf.cmath], the
+  #std​::​lerp function overloads ([c.math.lerp]), the declaration of
+  #std​::​byte ([cstddef.syn]), and the functions and function templates
+  #described in [support.types.byteops].
+  exception_symbols = {
+"(assoc_)?laguerre[f|l]?",
+"(assoc_|sph_)?legendre[f|l]?",
+"beta[f|l]?",
+"(comp_)?ellint_[1-3][f|l]?",
+"(cyl_|sph_)?bessel_[i-k][f|l]?",
+"(cyl_|sph_)?neumann[f|l]?",
+"expint[f|l]?",
+"hermite[f|l]?",
+"riemann_zeta[f|l]?",
+"lerp",
+"byte",
+  }
+  assert(len(symbol.headers) == 1)
+  header = symbol.headers[0]
+  if header not in c_compat_headers:
+return []
+  if any(re.fullmatch(x, symbol.name) for x in exception_symbols):
+return []
+
+  # Introduce two more entries, both in the global namespace, one using the
+  # C++-compat header and another using the C header.
+  results = []
+  if symbol.namespace != None:
+# avoid printing duplicated entries, for C macros!
+results.append(cppreference_parser.Symbol(symbol.name, None, [header]))
+  c_header = "<" + header[2:-1] +  ".h>" #  => 
+  results.append(cppreference_parser.Symbol(symbol.name, None, [c_header]))
+  return results
+
+
 def main():
   args = ParseArg()
   if args.symbols == 'cpp':
@@ -192,6 +256,7 @@
   # Zombie symbols that were available from the Standard Library, but are
   # removed in the following standards.
   (symbol_index_root, "zombie_names.html", "std::"),
+  (symbol_index_root, "macro.html", None),
 ]
   elif args.symbols == 'c':
 page_root = os.path.join(args.cppreference, "en", "c")
@@ -211,11 +276,14 @@
   print(CODE_PREFIX % (args.symbols.upper(), cppreference_modified_date))
   for symbol in symbols:
 if len(symbol.headers) == 1:
-  # SYMBOL(unqualified_name, namespace, header)
-  symbol.headers.extend(AdditionalHeadersForIOSymbols(symbol))
-  for header in symbol.headers:
-print("SYMBOL(%s, %s, %s)" % (symbol.name, symbol.namespace,
-  header))
+  augmented_symbols = [symbol]
+  augmented_symb

[PATCH] D143214: [include-mapping] Add C-compatibility symbol entries.

2023-02-08 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 495776.
hokein added a comment.
Herald added a subscriber: arphaman.
Herald added a project: clang-tools-extra.

fix the clangd unittest


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143214

Files:
  clang-tools-extra/clangd/unittests/StdLibTests.cpp
  clang/include/clang/Tooling/Inclusions/StandardLibrary.h
  clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
  clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc
  clang/tools/include-mapping/cppreference_parser.py
  clang/tools/include-mapping/gen_std.py
  clang/unittests/Tooling/StandardLibraryTest.cpp

Index: clang/unittests/Tooling/StandardLibraryTest.cpp
===
--- clang/unittests/Tooling/StandardLibraryTest.cpp
+++ clang/unittests/Tooling/StandardLibraryTest.cpp
@@ -65,12 +65,10 @@
 
   EXPECT_THAT(stdlib::Header::all(), Contains(*VectorH));
   EXPECT_THAT(stdlib::Symbol::all(), Contains(*Vector));
-  EXPECT_FALSE(stdlib::Header::named(""));
-  EXPECT_FALSE(stdlib::Header::named("", stdlib::Lang::CXX));
+  EXPECT_TRUE(stdlib::Header::named("", stdlib::Lang::CXX));
   EXPECT_TRUE(stdlib::Header::named("", stdlib::Lang::C));
 
-  EXPECT_FALSE(stdlib::Symbol::named("", "int16_t"));
-  EXPECT_FALSE(stdlib::Symbol::named("", "int16_t", stdlib::Lang::CXX));
+  EXPECT_TRUE(stdlib::Symbol::named("", "int16_t", stdlib::Lang::CXX));
   EXPECT_TRUE(stdlib::Symbol::named("", "int16_t", stdlib::Lang::C));
 }
 
@@ -127,9 +125,9 @@
   EXPECT_EQ(Recognizer(Nest), stdlib::Symbol::named("std::", "vector"));
   EXPECT_EQ(Recognizer(Clock),
 stdlib::Symbol::named("std::chrono::", "system_clock"));
-  EXPECT_EQ(Recognizer(CDivT), stdlib::Symbol::named("", "div_t"));
-  EXPECT_EQ(Recognizer(CDivT),
-stdlib::Symbol::named("", "div_t", stdlib::Lang::C));
+  auto DivT = stdlib::Symbol::named("", "div_t", stdlib::Lang::CXX);
+  EXPECT_TRUE(DivT);
+  EXPECT_EQ(Recognizer(CDivT), DivT);
   EXPECT_EQ(Recognizer(Sec), std::nullopt);
 }
 
Index: clang/tools/include-mapping/gen_std.py
===
--- clang/tools/include-mapping/gen_std.py
+++ clang/tools/include-mapping/gen_std.py
@@ -39,6 +39,7 @@
 import datetime
 import os
 import sys
+import re
 
 
 CODE_PREFIX = """\
@@ -170,6 +171,69 @@
   return headers
 
 
+def GetCCompatibilitySymbols(symbol):
+   # C++ form of the C standard headers.
+  c_compat_headers = {
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+  }
+  # C++ [support.c.headers.other] 17.14.7
+  #..., behaves as if each name placed in the standard library namespace by
+  #the corresponding  header is placed within the global namespace
+  #scope, except for the functions described in [sf.cmath], the
+  #std​::​lerp function overloads ([c.math.lerp]), the declaration of
+  #std​::​byte ([cstddef.syn]), and the functions and function templates
+  #described in [support.types.byteops].
+  exception_symbols = {
+"(assoc_)?laguerre[f|l]?",
+"(assoc_|sph_)?legendre[f|l]?",
+"beta[f|l]?",
+"(comp_)?ellint_[1-3][f|l]?",
+"(cyl_|sph_)?bessel_[i-k][f|l]?",
+"(cyl_|sph_)?neumann[f|l]?",
+"expint[f|l]?",
+"hermite[f|l]?",
+"riemann_zeta[f|l]?",
+"lerp",
+"byte",
+  }
+  assert(len(symbol.headers) == 1)
+  header = symbol.headers[0]
+  if header not in c_compat_headers:
+return []
+  if any(re.fullmatch(x, symbol.name) for x in exception_symbols):
+return []
+
+  # Introduce two more entries, both in the global namespace, one using the
+  # C++-compat header and another using the C header.
+  results = []
+  if symbol.namespace != None:
+# avoid printing duplicated entries, for C macros!
+results.append(cppreference_parser.Symbol(symbol.name, None, [header]))
+  c_header = "<" + header[2:-1] +  ".h>" #  => 
+  results.append(cppreference_parser.Symbol(symbol.name, None, [c_header]))
+  return results
+
+
 def main():
   args = ParseArg()
   if args.symbols == 'cpp':
@@ -192,6 +256,7 @@
   # Zombie symbols that were available from the Standard Library, but are
   # removed in the following standards.
   (symbol_index_root, "zombie_names.html", "std::"),
+  (symbol_index_root, "macro.html", None),
 ]
   elif args.symbols == 'c':
 page_root = os.path.join(args.cppreference, "en", "c")
@@ -211,11 +276,14 @@
   print(CODE_PREFIX % (args.symbols.upper(), cppreference_modified_date))
   for symbol in symbols:
 if len(symbol.headers) == 1:
-  # SYMBOL(unqualified_name, namespace, header)
-  symbol.headers.extend(AdditionalHeadersForIOSymbols(symbol))
-  for header in symbol.headers:
-print("SYMBOL(%s, %s, %s)" % (symbol.name, symbol.namespace

[PATCH] D143214: [include-mapping] Add C-compatibility symbol entries.

2023-02-08 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang-tools-extra/clangd/unittests/StdLibTests.cpp:37
   EXPECT_THAT(CXX, HasSubstr("#include "));
-  EXPECT_THAT(CXX, Not(HasSubstr("#include ")));
+  EXPECT_THAT(CXX, HasSubstr("#include "));
 

This is a behavior change, I think it is probably fine. Would be nice to have a 
second look.



Comment at: clang/unittests/Tooling/StandardLibraryTest.cpp:130
 stdlib::Symbol::named("std::chrono::", "system_clock"));
-  EXPECT_EQ(Recognizer(CDivT), stdlib::Symbol::named("", "div_t"));
-  EXPECT_EQ(Recognizer(CDivT),

this patch exposed a regression caused by 
1285172c21ef4867d9f895c0b2ab0f338c46e36f. The test was passed accidentally 
(both return a `nullopt`). This patch contains the fix (in 
`StandardLibrary.cpp`). 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143214

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


[PATCH] D143194: [clang][analyzer] Make messages of StdCLibraryFunctionsChecker user-friendly

2023-02-08 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added a comment.

Probably it is not always useful to explain why the argument is wrong. In cases 
when we can find out that the value is exactly between two consecutive valid 
ranges we can display a note, or when the exact value is known. Otherwise it 
may end up in something like "the value should be between 1 and 4 or between 6 
and 10, but it is less than 1 or exactly 5 or greater than 10". The "good" 
cases are (when more information is available): "the value is less than 1", 
"the value is 5", "the value is greater than 10". If two bad ranges are known 
it may be OK too: "the value is less than 1 or it is exactly 5". The 
explanation may be possible to implement by test assumes for the negated ranges.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143194

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


[PATCH] D143569: [Tooling/Inclusions] Add more multi-header symbols to StdSpecialSymbolMap.inc

2023-02-08 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: kadircet.
Herald added a project: All.
hokein requested review of this revision.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143569

Files:
  clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc


Index: clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
===
--- clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
+++ clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
@@ -30,6 +30,22 @@
 SYMBOL(unwrap_ref_decay_t, std::, )
 SYMBOL(wint_t, std::, )
 SYMBOL(wint_t, std::, )
+SYMBOL(swap, std::, )
+// C++ [string.view.synop 23.3.2]: The function templates defined in
+// [utility.swap] ... are available when  is included.
+SYMBOL(swap, std::, ) // since C++17
+SYMBOL(swap, std::, ) // until C++11
+// C++ [tuple.helper 22.4.7]: In addition to being available via inclusion of
+// the  header, ... any of the headers , , or 
+// are included.
+SYMBOL(tuple_size, std::, )
+SYMBOL(tuple_size, std::, )
+SYMBOL(tuple_size, std::, )
+SYMBOL(tuple_size, std::, )
+SYMBOL(tuple_element, std::, )
+SYMBOL(tuple_element, std::, )
+SYMBOL(tuple_element, std::, )
+SYMBOL(tuple_element, std::, )
 // C++ [iterator.range 25.7]: In addition to being available via inclusion of
 // the  header, the function templates in [iterator.range] are
 // available when any of the following headers are included: , ,


Index: clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
===
--- clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
+++ clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
@@ -30,6 +30,22 @@
 SYMBOL(unwrap_ref_decay_t, std::, )
 SYMBOL(wint_t, std::, )
 SYMBOL(wint_t, std::, )
+SYMBOL(swap, std::, )
+// C++ [string.view.synop 23.3.2]: The function templates defined in
+// [utility.swap] ... are available when  is included.
+SYMBOL(swap, std::, ) // since C++17
+SYMBOL(swap, std::, ) // until C++11
+// C++ [tuple.helper 22.4.7]: In addition to being available via inclusion of
+// the  header, ... any of the headers , , or 
+// are included.
+SYMBOL(tuple_size, std::, )
+SYMBOL(tuple_size, std::, )
+SYMBOL(tuple_size, std::, )
+SYMBOL(tuple_size, std::, )
+SYMBOL(tuple_element, std::, )
+SYMBOL(tuple_element, std::, )
+SYMBOL(tuple_element, std::, )
+SYMBOL(tuple_element, std::, )
 // C++ [iterator.range 25.7]: In addition to being available via inclusion of
 // the  header, the function templates in [iterator.range] are
 // available when any of the following headers are included: , ,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D141472: [clang][Interp] Add function pointers

2023-02-08 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 495786.

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

https://reviews.llvm.org/D141472

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/Context.cpp
  clang/lib/AST/Interp/Descriptor.cpp
  clang/lib/AST/Interp/FunctionPointer.h
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/InterpStack.h
  clang/lib/AST/Interp/Opcodes.td
  clang/lib/AST/Interp/PrimType.cpp
  clang/lib/AST/Interp/PrimType.h
  clang/test/AST/Interp/functions.cpp

Index: clang/test/AST/Interp/functions.cpp
===
--- clang/test/AST/Interp/functions.cpp
+++ clang/test/AST/Interp/functions.cpp
@@ -99,3 +99,58 @@
   huh(); // expected-error {{use of undeclared identifier}} \
  // ref-error {{use of undeclared identifier}}
 }
+
+namespace FunctionPointers {
+  constexpr int add(int a, int b) {
+return a + b;
+  }
+
+  struct S { int a; };
+  constexpr S getS() {
+return S{12};
+  }
+
+  constexpr int applyBinOp(int a, int b, int (*op)(int, int)) {
+return op(a, b);
+  }
+  static_assert(applyBinOp(1, 2, add) == 3, "");
+
+  constexpr int ignoreReturnValue() {
+int (*foo)(int, int) = add;
+
+foo(1, 2);
+return 1;
+  }
+  static_assert(ignoreReturnValue() == 1, "");
+
+  constexpr int createS(S (*gimme)()) {
+gimme(); // Ignored return value
+return gimme().a;
+  }
+  static_assert(createS(getS) == 12, "");
+
+namespace FunctionReturnType {
+  typedef int (*ptr)(int*);
+  typedef ptr (*pm)();
+
+  constexpr int fun1(int* y) {
+  return *y + 10;
+  }
+  constexpr ptr fun() {
+  return &fun1;
+  }
+  static_assert(fun() == nullptr, ""); // expected-error {{static assertion failed}} \
+   // ref-error {{static assertion failed}}
+
+  constexpr int foo() {
+int (*f)(int *) = fun();
+int m = 0;
+
+m = f(&m);
+
+return m;
+  }
+  static_assert(foo() == 10);
+}
+
+}
Index: clang/lib/AST/Interp/PrimType.h
===
--- clang/lib/AST/Interp/PrimType.h
+++ clang/lib/AST/Interp/PrimType.h
@@ -24,6 +24,7 @@
 class Pointer;
 class Boolean;
 class Floating;
+class FunctionPointer;
 
 /// Enumeration of the primitive types of the VM.
 enum PrimType : unsigned {
@@ -38,6 +39,7 @@
   PT_Bool,
   PT_Float,
   PT_Ptr,
+  PT_FnPtr,
 };
 
 /// Mapping from primitive types to their representation.
@@ -53,6 +55,7 @@
 template <> struct PrimConv { using T = Floating; };
 template <> struct PrimConv { using T = Boolean; };
 template <> struct PrimConv { using T = Pointer; };
+template <> struct PrimConv { using T = FunctionPointer; };
 
 /// Returns the size of a primitive type in bytes.
 size_t primSize(PrimType Type);
@@ -90,6 +93,7 @@
   TYPE_SWITCH_CASE(PT_Float, B)\
   TYPE_SWITCH_CASE(PT_Bool, B) \
   TYPE_SWITCH_CASE(PT_Ptr, B)  \
+  TYPE_SWITCH_CASE(PT_FnPtr, B)\
 }  \
   } while (0)
 #define COMPOSITE_TYPE_SWITCH(Expr, B, D)  \
Index: clang/lib/AST/Interp/PrimType.cpp
===
--- clang/lib/AST/Interp/PrimType.cpp
+++ clang/lib/AST/Interp/PrimType.cpp
@@ -9,6 +9,7 @@
 #include "PrimType.h"
 #include "Boolean.h"
 #include "Floating.h"
+#include "FunctionPointer.h"
 #include "Pointer.h"
 
 using namespace clang;
Index: clang/lib/AST/Interp/Opcodes.td
===
--- clang/lib/AST/Interp/Opcodes.td
+++ clang/lib/AST/Interp/Opcodes.td
@@ -27,6 +27,7 @@
 def Uint64 : Type;
 def Float : Type;
 def Ptr : Type;
+def FnPtr : Type;
 
 //===--===//
 // Types transferred to the interpreter.
@@ -77,7 +78,7 @@
 }
 
 def PtrTypeClass : TypeClass {
-  let Types = [Ptr];
+  let Types = [Ptr, FnPtr];
 }
 
 def BoolTypeClass : TypeClass {
@@ -187,6 +188,12 @@
   let ChangesPC = 1;
 }
 
+def CallPtr : Opcode {
+  let Args = [];
+  let Types = [];
+  let ChangesPC = 1;
+}
+
 //===--===//
 // Frame management
 //===--===//
@@ -228,6 +235,7 @@
 // [] -> [Pointer]
 def Null : Opcode {
   let Types = [PtrTypeClass];
+  let HasGroup = 1;
 }
 
 //===--===//
@@ -447,6 +455,14 @@
   let HasGroup = 0;
 }
 
+//===--===//
+// Function pointers.
+//===--===//
+def GetFnPtr : Opcod

[PATCH] D142630: [clang][Interp] Implement virtual function calls

2023-02-08 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 495789.
tbaeder set the repository for this revision to rG LLVM Github Monorepo.
tbaeder added a comment.

Fixed all the new test cases by adding a new `CallVirt` opcode and only using 
that if appropriate.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142630

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/Context.cpp
  clang/lib/AST/Interp/Context.h
  clang/lib/AST/Interp/Function.h
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/InterpState.h
  clang/lib/AST/Interp/Opcodes.td
  clang/test/AST/Interp/records.cpp

Index: clang/test/AST/Interp/records.cpp
===
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -1,8 +1,10 @@
 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify %s
 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -std=c++14 -verify %s
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -std=c++20 -verify %s
 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -triple i686 -verify %s
 // RUN: %clang_cc1 -verify=ref %s
 // RUN: %clang_cc1 -verify=ref -std=c++14 %s
+// RUN: %clang_cc1 -verify=ref -std=c++20 %s
 // RUN: %clang_cc1 -verify=ref -triple i686 %s
 
 struct BoolPair {
@@ -286,6 +288,7 @@
 };
 
 namespace DeriveFailures {
+#if __cplusplus < 202002L
   struct Base { // ref-note 2{{declared here}}
 int Val;
   };
@@ -301,10 +304,12 @@
// ref-note {{in call to 'Derived(12)'}} \
// ref-note {{declared here}} \
// expected-error {{must be initialized by a constant expression}}
+
   static_assert(D.Val == 0, ""); // ref-error {{not an integral constant expression}} \
  // ref-note {{initializer of 'D' is not a constant expression}} \
  // expected-error {{not an integral constant expression}} \
  // expected-note {{read of object outside its lifetime}}
+#endif
 
   struct AnotherBase {
 int Val;
@@ -354,3 +359,121 @@
   static_assert(getS(true).a == 12, "");
   static_assert(getS(false).a == 13, "");
 };
+
+#if __cplusplus >= 202002L
+namespace VirtualCalls {
+namespace Obvious {
+
+  class A {
+  public:
+constexpr A(){}
+constexpr virtual int foo() {
+  return 3;
+}
+  };
+  class B : public A {
+  public:
+constexpr int foo() override {
+  return 6;
+}
+  };
+
+  constexpr int getFooB(bool b) {
+A *a;
+A myA;
+B myB;
+
+if (b)
+  a = &myA;
+else
+  a = &myB;
+
+return a->foo();
+  }
+  static_assert(getFooB(true) == 3, "");
+  static_assert(getFooB(false) == 6, "");
+}
+
+namespace MultipleBases {
+  class A {
+  public:
+constexpr virtual int getInt() const { return 10; }
+  };
+  class B {
+  public:
+  };
+  class C : public A, public B {
+  public:
+constexpr int getInt() const override { return 20; }
+  };
+
+  constexpr int callGetInt(const A& a) { return a.getInt(); }
+  static_assert(callGetInt(C()) == 20, "");
+  static_assert(callGetInt(A()) == 10, "");
+}
+
+namespace Destructors {
+  class Base {
+  public:
+int i;
+constexpr Base(int &i) : i(i) {i++;}
+constexpr virtual ~Base() {i--;}
+  };
+
+  class Derived : public Base {
+  public:
+constexpr Derived(int &i) : Base(i) {}
+constexpr virtual ~Derived() {i--;}
+  };
+
+  constexpr int test() {
+int i = 0;
+Derived d(i);
+return i;
+  }
+  static_assert(test() == 1);
+}
+
+
+namespace QualifiedCalls {
+  class A {
+  public:
+  constexpr virtual int foo() const {
+  return 5;
+  }
+  };
+  class B : public A {};
+  class C : public B {
+  public:
+  constexpr int foo() const override {
+  return B::foo(); // B doesn't have a foo(), so this should call A::foo().
+  }
+  constexpr int foo2() const {
+return this->A::foo();
+  }
+  };
+  constexpr C c;
+  static_assert(c.foo() == 5);
+  static_assert(c.foo2() == 5);
+
+
+  struct S {
+int _c = 0;
+virtual constexpr int foo() const { return 1; }
+  };
+
+  struct SS : S {
+int a;
+constexpr SS() {
+  a = S::foo();
+}
+constexpr int foo() const override {
+  return S::foo();
+}
+  };
+
+  constexpr SS ss;
+  static_assert(ss.a == 1);
+}
+};
+#endif
Index: clang/lib/AST/Interp/Opcodes.td
===
--- clang/lib/AST/Interp/Opcodes.td
+++ clang/lib/AST/Interp/Opcodes.td
@@ -182,6 +182,11 @@
   let ChangesPC = 1;
 }
 
+def CallVirt : Opcode {
+  let Args = [ArgFunction];
+  let Types = [];
+}
+
 def CallBI : Opcode {
   let Args = [ArgFunction];
   let Types = [];
Index: clang/lib/AST/Interp/InterpState.h
===

[PATCH] D143197: [clangd] Fix bugs in main-file include patching for stale preambles

2023-02-08 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 495790.
kadircet marked 4 inline comments as done.
kadircet retitled this revision from "[clangd] Patch includes even without any 
changes" to "[clangd] Fix bugs in main-file include patching for stale 
preambles".
kadircet edited the summary of this revision.
kadircet added a comment.

- Address comments & update commit message


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143197

Files:
  clang-tools-extra/clangd/Preamble.cpp
  clang-tools-extra/clangd/unittests/PreambleTests.cpp

Index: clang-tools-extra/clangd/unittests/PreambleTests.cpp
===
--- clang-tools-extra/clangd/unittests/PreambleTests.cpp
+++ clang-tools-extra/clangd/unittests/PreambleTests.cpp
@@ -15,6 +15,7 @@
 #include "TestFS.h"
 #include "TestTU.h"
 #include "XRefs.h"
+#include "clang/Basic/SourceManager.h"
 #include "clang/Format/Format.h"
 #include "clang/Frontend/FrontendActions.h"
 #include "clang/Frontend/PrecompiledPreamble.h"
@@ -23,6 +24,7 @@
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include "gmock/gmock.h"
+#include "gtest/gtest-matchers.h"
 #include "gtest/gtest.h"
 #include 
 #include 
@@ -166,7 +168,7 @@
   MockFS FS;
   IgnoreDiagnostics Diags;
   auto TU = TestTU::withCode(R"cpp(
-#include "a.h"
+#include "a.h" // IWYU pragma: keep
 #include "c.h"
   )cpp");
   TU.AdditionalFiles["a.h"] = "#include \"b.h\"";
@@ -185,9 +187,14 @@
*BaselinePreamble);
   // Only a.h should exists in the preamble, as c.h has been dropped and b.h was
   // newly introduced.
-  EXPECT_THAT(PP.preambleIncludes(),
-  ElementsAre(AllOf(Field(&Inclusion::Written, "\"a.h\""),
-Field(&Inclusion::Resolved, testPath("a.h");
+  EXPECT_THAT(
+  PP.preambleIncludes(),
+  ElementsAre(AllOf(
+  Field(&Inclusion::Written, "\"a.h\""),
+  Field(&Inclusion::Resolved, testPath("a.h")),
+  Field(&Inclusion::HeaderID, testing::Not(testing::Eq(std::nullopt))),
+  Field(&Inclusion::BehindPragmaKeep, true),
+  Field(&Inclusion::FileKind, SrcMgr::CharacteristicKind::C_User;
 }
 
 std::optional createPatchedAST(llvm::StringRef Baseline,
@@ -225,6 +232,20 @@
   .str();
 }
 
+TEST(PreamblePatchTest, IncludesArePreserved) {
+  llvm::StringLiteral Baseline = "//error-ok\n#include \n#include \n";
+  auto Modified = Baseline + "#define FOO\n";
+
+  auto Includes = createPatchedAST(Baseline, Modified.str())
+  ->getIncludeStructure()
+  .MainFileIncludes;
+  EXPECT_TRUE(!Includes.empty());
+  EXPECT_EQ(Includes, TestTU::withCode(Baseline)
+  .build()
+  .getIncludeStructure()
+  .MainFileIncludes);
+}
+
 TEST(PreamblePatchTest, Define) {
   // BAR should be defined while parsing the AST.
   struct {
Index: clang-tools-extra/clangd/Preamble.cpp
===
--- clang-tools-extra/clangd/Preamble.cpp
+++ clang-tools-extra/clangd/Preamble.cpp
@@ -671,10 +671,10 @@
 // We are only interested in newly added includes, record the ones in
 // Baseline for exclusion.
 llvm::DenseMap,
-   /*Resolved=*/llvm::StringRef>
+   const Inclusion *>
 ExistingIncludes;
 for (const auto &Inc : Baseline.Includes.MainFileIncludes)
-  ExistingIncludes[{Inc.Directive, Inc.Written}] = Inc.Resolved;
+  ExistingIncludes[{Inc.Directive, Inc.Written}] = &Inc;
 // There might be includes coming from disabled regions, record these for
 // exclusion too. note that we don't have resolved paths for those.
 for (const auto &Inc : BaselineScan->Includes)
@@ -685,8 +685,13 @@
   // Include already present in the baseline preamble. Set resolved path and
   // put into preamble includes.
   if (It != ExistingIncludes.end()) {
-Inc.Resolved = It->second.str();
-PP.PreambleIncludes.push_back(Inc);
+auto &PatchedInc = PP.PreambleIncludes.emplace_back();
+// Copy everything from existing include, apart from the location, when
+// it's coming from baseline preamble.
+if (It->second)
+  PatchedInc = *It->second;
+PatchedInc.HashLine = Inc.HashLine;
+PatchedInc.HashOffset = Inc.HashOffset;
 continue;
   }
   // Include is new in the modified preamble. Inject it into the patch and
@@ -696,6 +701,11 @@
   Patch << llvm::formatv(
   "#{0} {1}\n", spellingForIncDirective(Inc.Directive), Inc.Written);
 }
+  } else {
+// Make sure we have the full set of includes available even when we're not
+// patching. As these are used by features we provide afterwards like hover,
+// go-to-

[PATCH] D143197: [clangd] Fix bugs in main-file include patching for stale preambles

2023-02-08 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/Preamble.cpp:690
+// it's coming from baseline preamble.
+if (It->second) {
+  Inc.Resolved = It->second->Resolved;

sammccall wrote:
> why the null check?
as discussed offline, we might have includes coming from scanned contents whose 
are not part of the preamble, e.g. because they're in a disabled PP region.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143197

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


[PATCH] D143560: clang-format.el: fix warnings

2023-02-08 Thread David Truby via Phabricator via cfe-commits
DavidTruby added a comment.

I think the other suggestion from the warning should be applied, as I don't 
think it _is_ intended that "quote" is matched by either of these. It would 
actually be odd if it did as you'd have two matches.




Comment at: clang/tools/clang-format/clang-format.el:96
  'utf-8-unix)))
 (goto-char start)
 (delete-region start end)

phst wrote:
> same here, AIUI this should just be `quote'
I think you mean "just cursor" here


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143560

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


[PATCH] D142893: [NFC] Class for building MultilibSet

2023-02-08 Thread Michael Platings via Phabricator via cfe-commits
michaelplatings updated this revision to Diff 495798.
michaelplatings added a comment.

Replace makeMultilibBuilder() with a MultilibBuilder constructor that 
initializes all suffixes to the same value.

In the case of AndroidMipsMultilibs it was apparently intended that only the 
GCC suffix was set, and the other suffixes were left empty. This is now 
explicit in the code.

Comments about Multilib being "immutable" were overstated so I've now removed 
them. The intention is merely to remove the requirement to support mutation. 
The code is simpler when you don't need to keep checking invariants.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142893

Files:
  clang/include/clang/Driver/Multilib.h
  clang/include/clang/Driver/MultilibBuilder.h
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/Multilib.cpp
  clang/lib/Driver/MultilibBuilder.cpp
  clang/lib/Driver/ToolChains/BareMetal.cpp
  clang/lib/Driver/ToolChains/Fuchsia.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/unittests/Driver/CMakeLists.txt
  clang/unittests/Driver/MultilibBuilderTest.cpp
  clang/unittests/Driver/MultilibTest.cpp

Index: clang/unittests/Driver/MultilibTest.cpp
===
--- clang/unittests/Driver/MultilibTest.cpp
+++ clang/unittests/Driver/MultilibTest.cpp
@@ -11,34 +11,17 @@
 //===--===//
 
 #include "clang/Driver/Multilib.h"
+#include "../../lib/Driver/ToolChains/CommonArgs.h"
 #include "clang/Basic/LLVM.h"
+#include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
+#include "llvm/Support/SourceMgr.h"
 #include "gtest/gtest.h"
 
 using namespace clang::driver;
 using namespace clang;
 
-TEST(MultilibTest, MultilibValidity) {
-
-  ASSERT_TRUE(Multilib().isValid()) << "Empty multilib is not valid";
-
-  ASSERT_TRUE(Multilib().flag("+foo").isValid())
-  << "Single indicative flag is not valid";
-
-  ASSERT_TRUE(Multilib().flag("-foo").isValid())
-  << "Single contraindicative flag is not valid";
-
-  ASSERT_FALSE(Multilib().flag("+foo").flag("-foo").isValid())
-  << "Conflicting flags should invalidate the Multilib";
-
-  ASSERT_TRUE(Multilib().flag("+foo").flag("+foo").isValid())
-  << "Multilib should be valid even if it has the same flag twice";
-
-  ASSERT_TRUE(Multilib().flag("+foo").flag("-foobar").isValid())
-  << "Seemingly conflicting prefixes shouldn't actually conflict";
-}
-
 TEST(MultilibTest, OpEqReflexivity1) {
   Multilib M;
   ASSERT_TRUE(M == M) << "Multilib::operator==() is not reflexive";
@@ -50,40 +33,28 @@
 }
 
 TEST(MultilibTest, OpEqReflexivity3) {
-  Multilib M1, M2;
-  M1.flag("+foo");
-  M2.flag("+foo");
+  Multilib M1({}, {}, {}, 0, {"+foo"});
+  Multilib M2({}, {}, {}, 0, {"+foo"});
   ASSERT_TRUE(M1 == M2) << "Multilibs with the same flag should be the same";
 }
 
 TEST(MultilibTest, OpEqInequivalence1) {
-  Multilib M1, M2;
-  M1.flag("+foo");
-  M2.flag("-foo");
+  Multilib M1({}, {}, {}, 0, {"+foo"});
+  Multilib M2({}, {}, {}, 0, {"-foo"});
   ASSERT_FALSE(M1 == M2) << "Multilibs with conflicting flags are not the same";
   ASSERT_FALSE(M2 == M1)
   << "Multilibs with conflicting flags are not the same (commuted)";
 }
 
 TEST(MultilibTest, OpEqInequivalence2) {
-  Multilib M1, M2;
-  M2.flag("+foo");
+  Multilib M1;
+  Multilib M2({}, {}, {}, 0, {"+foo"});
   ASSERT_FALSE(M1 == M2) << "Flags make Multilibs different";
 }
 
-TEST(MultilibTest, OpEqEquivalence1) {
-  Multilib M1, M2;
-  M1.flag("+foo");
-  M2.flag("+foo").flag("+foo");
-  ASSERT_TRUE(M1 == M2) << "Flag duplication shouldn't affect equivalence";
-  ASSERT_TRUE(M2 == M1)
-  << "Flag duplication shouldn't affect equivalence (commuted)";
-}
-
 TEST(MultilibTest, OpEqEquivalence2) {
-  Multilib M1("64");
-  Multilib M2;
-  M2.gccSuffix("/64");
+  Multilib M1("/64");
+  Multilib M2("/64");
   ASSERT_TRUE(M1 == M2)
   << "Constructor argument must match Multilib::gccSuffix()";
   ASSERT_TRUE(M2 == M1)
@@ -91,9 +62,8 @@
 }
 
 TEST(MultilibTest, OpEqEquivalence3) {
-  Multilib M1("", "32");
-  Multilib M2;
-  M2.osSuffix("/32");
+  Multilib M1("", "/32");
+  Multilib M2("", "/32");
   ASSERT_TRUE(M1 == M2)
   << "Constructor argument must match Multilib::osSuffix()";
   ASSERT_TRUE(M2 == M1)
@@ -101,9 +71,8 @@
 }
 
 TEST(MultilibTest, OpEqEquivalence4) {
-  Multilib M1("", "", "16");
-  Multilib M2;
-  M2.includeSuffix("/16");
+  Multilib M1("", "", "/16");
+  Multilib M2("", "", "/16");
   ASSERT_TRUE(M1 == M2)
   << "Constructor argument must match Multilib::includeSuffix()";
   ASSERT_TRUE(M2 == M1)
@@ -111,31 +80,31 @@
 }
 
 TEST(MultilibTest, OpEqInequivalence3) {
-  Multilib M1("foo");
-  Multilib M2("bar");
+  Multilib M1("/foo");
+  Multilib M2("/bar");
   ASSERT_FALSE(M1 == M2) << "Differing gccSuffixes should be different";
   ASSERT_FA

[PATCH] D142534: [clang][codegen] Fix emission of consteval constructor of derived type

2023-02-08 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added a comment.

Ping.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142534

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


[PATCH] D142534: [clang][codegen] Fix emission of consteval constructor of derived type

2023-02-08 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added a comment.

I discovered that this patch also helps to fix crash reported in 
https://github.com/llvm/llvm-project/issues/59223 .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142534

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


[PATCH] D142905: Change multilib selection algorithm

2023-02-08 Thread Michael Platings via Phabricator via cfe-commits
michaelplatings updated this revision to Diff 495800.
michaelplatings added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142905

Files:
  clang/include/clang/Driver/Multilib.h
  clang/include/clang/Driver/MultilibBuilder.h
  clang/lib/Driver/Multilib.cpp
  clang/lib/Driver/MultilibBuilder.cpp
  clang/lib/Driver/ToolChains/BareMetal.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.h
  clang/lib/Driver/ToolChains/Fuchsia.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/unittests/Driver/MultilibBuilderTest.cpp
  clang/unittests/Driver/MultilibTest.cpp

Index: clang/unittests/Driver/MultilibTest.cpp
===
--- clang/unittests/Driver/MultilibTest.cpp
+++ clang/unittests/Driver/MultilibTest.cpp
@@ -33,14 +33,14 @@
 }
 
 TEST(MultilibTest, OpEqReflexivity3) {
-  Multilib M1({}, {}, {}, 0, {"+foo"});
-  Multilib M2({}, {}, {}, 0, {"+foo"});
+  Multilib M1({}, {}, {}, {"+foo"});
+  Multilib M2({}, {}, {}, {"+foo"});
   ASSERT_TRUE(M1 == M2) << "Multilibs with the same flag should be the same";
 }
 
 TEST(MultilibTest, OpEqInequivalence1) {
-  Multilib M1({}, {}, {}, 0, {"+foo"});
-  Multilib M2({}, {}, {}, 0, {"-foo"});
+  Multilib M1({}, {}, {}, {"+foo"});
+  Multilib M2({}, {}, {}, {"-foo"});
   ASSERT_FALSE(M1 == M2) << "Multilibs with conflicting flags are not the same";
   ASSERT_FALSE(M2 == M1)
   << "Multilibs with conflicting flags are not the same (commuted)";
@@ -48,7 +48,7 @@
 
 TEST(MultilibTest, OpEqInequivalence2) {
   Multilib M1;
-  Multilib M2({}, {}, {}, 0, {"+foo"});
+  Multilib M2({}, {}, {}, {"+foo"});
   ASSERT_FALSE(M1 == M2) << "Flags make Multilibs different";
 }
 
@@ -124,9 +124,9 @@
 }
 
 TEST(MultilibTest, Construction3) {
-  Multilib M({}, {}, {}, 0, {"+f1", "+f2", "-f3"});
-  for (Multilib::flags_list::const_iterator I = M.flags().begin(),
-E = M.flags().end();
+  Multilib M({}, {}, {}, {"+f1", "+f2", "-f3"});
+  for (Multilib::flag_set::const_iterator I = M.flags().begin(),
+  E = M.flags().end();
I != E; ++I) {
 ASSERT_TRUE(llvm::StringSwitch(*I)
 .Cases("+f1", "+f2", "-f3", true)
@@ -149,20 +149,41 @@
 
 TEST(MultilibTest, SetPriority) {
   MultilibSet MS({
-  Multilib("/foo", {}, {}, 1, {"+foo"}),
-  Multilib("/bar", {}, {}, 2, {"+bar"}),
+  Multilib("/foo", {}, {}, {"+foo"}),
+  Multilib("/bar", {}, {}, {"+bar"}),
   });
-  Multilib::flags_list Flags1 = {"+foo", "-bar"};
+  Multilib::flag_set Flags1 = {"+foo", "-bar"};
   Multilib Selection1;
   ASSERT_TRUE(MS.select(Flags1, Selection1))
   << "Flag set was {\"+foo\"}, but selection not found";
   ASSERT_TRUE(Selection1.gccSuffix() == "/foo")
   << "Selection picked " << Selection1 << " which was not expected";
 
-  Multilib::flags_list Flags2 = {"+foo", "+bar"};
+  Multilib::flag_set Flags2 = {"+foo", "+bar"};
   Multilib Selection2;
   ASSERT_TRUE(MS.select(Flags2, Selection2))
   << "Flag set was {\"+bar\"}, but selection not found";
   ASSERT_TRUE(Selection2.gccSuffix() == "/bar")
   << "Selection picked " << Selection2 << " which was not expected";
 }
+
+TEST(MultilibTest, SelectMultiple) {
+  MultilibSet MS({
+  Multilib("/a", {}, {}, {"x"}),
+  Multilib("/b", {}, {}, {"y"}),
+  });
+  std::vector Selection;
+
+  Selection = MS.select({"x"});
+  ASSERT_EQ(1u, Selection.size());
+  EXPECT_EQ("/a", Selection[0].gccSuffix());
+
+  Selection = MS.select({"y"});
+  ASSERT_EQ(1u, Selection.size());
+  EXPECT_EQ("/b", Selection[0].gccSuffix());
+
+  Selection = MS.select({"y", "x"});
+  ASSERT_EQ(2u, Selection.size());
+  EXPECT_EQ("/a", Selection[0].gccSuffix());
+  EXPECT_EQ("/b", Selection[1].gccSuffix());
+}
Index: clang/unittests/Driver/MultilibBuilderTest.cpp
===
--- clang/unittests/Driver/MultilibBuilderTest.cpp
+++ clang/unittests/Driver/MultilibBuilderTest.cpp
@@ -157,14 +157,14 @@
 .Maybe(MultilibBuilder("64").flag("+m64"))
 .makeMultilibSet();
 
-  Multilib::flags_list FlagM64 = {"+m64"};
+  Multilib::flag_set FlagM64 = {"+m64"};
   Multilib SelectionM64;
   ASSERT_TRUE(MS1.select(FlagM64, SelectionM64))
   << "Flag set was {\"+m64\"}, but selection not found";
   ASSERT_TRUE(SelectionM64.gccSuffix() == "/64")
   << "Selection picked " << SelectionM64 << " which was not expected";
 
-  Multilib::flags_list FlagNoM64 = {"-m64"};
+  Multilib::flag_set FlagNoM64 = {"-m64"};
   Multilib SelectionNoM64;
   ASSERT_TRUE(MS1.select(FlagNoM64, SelectionNoM64))
   << "Flag set was {\"-m64\"}, but selection not found";
@@ -181,16 +181,16 @@
   for (unsigned I = 0; I < 4; ++I) {
 bool IsEL = I & 0x1;
 bool IsSF = I & 0x2;
-Multilib::fl

[PATCH] D143482: [SanitizerBinaryMetadata] Optimize used space for features and UAR stack args

2023-02-08 Thread Marco Elver via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3d53b5273003: [SanitizerBinaryMetadata] Optimize used space 
for features and UAR stack args (authored by melver).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143482

Files:
  clang/test/CodeGen/sanitize-metadata.c
  compiler-rt/test/metadata/common.h
  compiler-rt/test/metadata/covered.cpp
  compiler-rt/test/metadata/lit.site.cfg.py.in
  compiler-rt/test/metadata/uar.cpp
  llvm/include/llvm/Transforms/Instrumentation/SanitizerBinaryMetadata.h
  llvm/lib/CodeGen/SanitizerBinaryMetadata.cpp
  llvm/lib/Transforms/Instrumentation/SanitizerBinaryMetadata.cpp
  llvm/test/Instrumentation/SanitizerBinaryMetadata/atomics.ll

Index: llvm/test/Instrumentation/SanitizerBinaryMetadata/atomics.ll
===
--- llvm/test/Instrumentation/SanitizerBinaryMetadata/atomics.ll
+++ llvm/test/Instrumentation/SanitizerBinaryMetadata/atomics.ll
@@ -2039,7 +2039,7 @@
 ; CHECK-DAG: entry:
 ; CHECK-NEXT:  br i1 icmp ne (ptr @__sanitizer_metadata_atomics_add, ptr null), label %callfunc, label %ret
 ; CHECK-DAG: callfunc:
-; CHECK-NEXT:  call void @__sanitizer_metadata_atomics_add(i32 1, ptr @__start_sanmd_atomics, ptr @__stop_sanmd_atomics)
+; CHECK-NEXT:  call void @__sanitizer_metadata_atomics_add(i32 2, ptr @__start_sanmd_atomics, ptr @__stop_sanmd_atomics)
 ; CHECK-NEXT:  br label %ret
 ; CHECK-DAG: ret:
 ; CHECK-NEXT:  ret void
@@ -2048,7 +2048,7 @@
 ; CHECK-DAG: entry:
 ; CHECK-NEXT:  br i1 icmp ne (ptr @__sanitizer_metadata_atomics_del, ptr null), label %callfunc, label %ret
 ; CHECK-DAG: callfunc:
-; CHECK-NEXT:  call void @__sanitizer_metadata_atomics_del(i32 1, ptr @__start_sanmd_atomics, ptr @__stop_sanmd_atomics)
+; CHECK-NEXT:  call void @__sanitizer_metadata_atomics_del(i32 2, ptr @__start_sanmd_atomics, ptr @__stop_sanmd_atomics)
 ; CHECK-NEXT:  br label %ret
 ; CHECK-DAG: ret:
 ; CHECK-NEXT:  ret void
@@ -2057,7 +2057,7 @@
 ; CHECK-DAG: entry:
 ; CHECK-NEXT:  br i1 icmp ne (ptr @__sanitizer_metadata_covered_add, ptr null), label %callfunc, label %ret
 ; CHECK-DAG: callfunc:
-; CHECK-NEXT:  call void @__sanitizer_metadata_covered_add(i32 1, ptr @__start_sanmd_covered, ptr @__stop_sanmd_covered)
+; CHECK-NEXT:  call void @__sanitizer_metadata_covered_add(i32 2, ptr @__start_sanmd_covered, ptr @__stop_sanmd_covered)
 ; CHECK-NEXT:  br label %ret
 ; CHECK-DAG: ret:
 ; CHECK-NEXT:  ret void
@@ -2066,11 +2066,11 @@
 ; CHECK-DAG: entry:
 ; CHECK-NEXT:  br i1 icmp ne (ptr @__sanitizer_metadata_covered_del, ptr null), label %callfunc, label %ret
 ; CHECK-DAG: callfunc:
-; CHECK-NEXT:  call void @__sanitizer_metadata_covered_del(i32 1, ptr @__start_sanmd_covered, ptr @__stop_sanmd_covered)
+; CHECK-NEXT:  call void @__sanitizer_metadata_covered_del(i32 2, ptr @__start_sanmd_covered, ptr @__stop_sanmd_covered)
 ; CHECK-NEXT:  br label %ret
 ; CHECK-DAG: ret:
 ; CHECK-NEXT:  ret void
 
 ; CHECK: !0 = !{!"sanmd_covered", !1}
-; CHECK: !1 = !{i32 1}
+; CHECK: !1 = !{i8 1}
 ; CHECK: !2 = !{!"sanmd_atomics"}
Index: llvm/lib/Transforms/Instrumentation/SanitizerBinaryMetadata.cpp
===
--- llvm/lib/Transforms/Instrumentation/SanitizerBinaryMetadata.cpp
+++ llvm/lib/Transforms/Instrumentation/SanitizerBinaryMetadata.cpp
@@ -43,6 +43,7 @@
 
 #include 
 #include 
+#include 
 
 using namespace llvm;
 
@@ -52,7 +53,7 @@
 
 //===--- Constants ===//
 
-constexpr uint32_t kVersionBase = 1;// occupies lower 16 bits
+constexpr uint32_t kVersionBase = 2;// occupies lower 16 bits
 constexpr uint32_t kVersionPtrSizeRel = (1u << 16); // offsets are pointer-sized
 constexpr int kCtorDtorPriority = 2;
 
@@ -269,9 +270,10 @@
 const auto *MI = &MetadataInfo::Covered;
 MIS.insert(MI);
 const StringRef Section = getSectionName(MI->SectionSuffix);
-// The feature mask will be placed after the size (32 bit) of the function,
-// so in total one covered entry will use `sizeof(void*) + 4 + 4`.
-Constant *CFM = IRB.getInt32(FeatureMask);
+// The feature mask will be placed after the size of the function.
+assert(FeatureMask <= std::numeric_limits::max() &&
+   "Increase feature mask bytes and bump version");
+Constant *CFM = IRB.getInt8(FeatureMask);
 F.setMetadata(LLVMContext::MD_pcsections,
   MDB.createPCSections({{Section, {CFM}}}));
   }
Index: llvm/lib/CodeGen/SanitizerBinaryMetadata.cpp
===
--- llvm/lib/CodeGen/SanitizerBinaryMetadata.cpp
+++ llvm/lib/CodeGen/SanitizerBinaryMetadata.cpp
@@ -57,7 +57,8 @@
   auto &AuxMDs = *cast(MD->getOperand(1));
   // Assume it currently only has features.
   assert(AuxMDs.getNumOperands() == 1);
-  auto *Featu

[PATCH] D143484: [SanitizerBinaryMetadata] Emit constants as ULEB128

2023-02-08 Thread Marco Elver via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbf9814b70560: [SanitizerBinaryMetadata] Emit constants as 
ULEB128 (authored by melver).

Changed prior to commit:
  https://reviews.llvm.org/D143484?vs=495442&id=495802#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143484

Files:
  clang/test/CodeGen/sanitize-metadata.c
  compiler-rt/test/metadata/common.h
  llvm/docs/PCSectionsMetadata.rst
  llvm/include/llvm/CodeGen/AsmPrinter.h
  llvm/include/llvm/Transforms/Instrumentation/SanitizerBinaryMetadata.h
  llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
  llvm/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp
  llvm/lib/CodeGen/SanitizerBinaryMetadata.cpp
  llvm/lib/Transforms/Instrumentation/SanitizerBinaryMetadata.cpp
  llvm/test/CodeGen/X86/pcsections.ll
  llvm/test/Instrumentation/SanitizerBinaryMetadata/atomics.ll

Index: llvm/test/Instrumentation/SanitizerBinaryMetadata/atomics.ll
===
--- llvm/test/Instrumentation/SanitizerBinaryMetadata/atomics.ll
+++ llvm/test/Instrumentation/SanitizerBinaryMetadata/atomics.ll
@@ -2071,6 +2071,6 @@
 ; CHECK-DAG: ret:
 ; CHECK-NEXT:  ret void
 
-; CHECK: !0 = !{!"sanmd_covered", !1}
-; CHECK: !1 = !{i8 1}
-; CHECK: !2 = !{!"sanmd_atomics"}
+; CHECK: !0 = !{!"sanmd_covered!C", !1}
+; CHECK: !1 = !{i64 1}
+; CHECK: !2 = !{!"sanmd_atomics!C"}
Index: llvm/test/CodeGen/X86/pcsections.ll
===
--- llvm/test/CodeGen/X86/pcsections.ll
+++ llvm/test/CodeGen/X86/pcsections.ll
@@ -137,9 +137,32 @@
   ret void
 }
 
+define void @multiple_uleb128() !pcsections !6 {
+; CHECK-LABEL: multiple_uleb128:
+; CHECK:   .section	section_aux,"awo",@progbits,.text
+; CHECK-NEXT:  .Lpcsection_base8:
+; DEFCM-NEXT:  .long	.Lfunc_begin3-.Lpcsection_base8
+; LARGE-NEXT:  .quad	.Lfunc_begin3-.Lpcsection_base8
+; CHECK-NEXT:  .uleb128	.Lfunc_end6-.Lfunc_begin3
+; CHECK-NEXT:  .byte	42
+; CHECK-NEXT:  .ascii	"\345\216&"
+; CHECK-NEXT:  .byte	255
+; CHECK-NEXT:  .section	section_aux_21264,"awo",@progbits,.text
+; CHECK-NEXT:  .Lpcsection_base9:
+; DEFCM-NEXT:  .long	.Lfunc_begin3-.Lpcsection_base9
+; LARGE-NEXT:  .quad	.Lfunc_begin3-.Lpcsection_base9
+; CHECK-NEXT:  .long	.Lfunc_end6-.Lfunc_begin3
+; CHECK-NEXT:  .long	21264
+; CHECK-NEXT:  .text
+entry:
+  ret void
+}
+
 !0 = !{!"section_no_aux"}
 !1 = !{!"section_aux", !3}
 !2 = !{!"section_aux_42", !4, !"section_aux_21264", !5}
 !3 = !{i32 10, i32 20, i32 30}
 !4 = !{i32 42}
 !5 = !{i32 21264}
+!6 = !{!"section_aux!C", !7, !"section_aux_21264", !5}
+!7 = !{i64 42, i32 624485, i8 255}
Index: llvm/lib/Transforms/Instrumentation/SanitizerBinaryMetadata.cpp
===
--- llvm/lib/Transforms/Instrumentation/SanitizerBinaryMetadata.cpp
+++ llvm/lib/Transforms/Instrumentation/SanitizerBinaryMetadata.cpp
@@ -35,15 +35,16 @@
 #include "llvm/InitializePasses.h"
 #include "llvm/Pass.h"
 #include "llvm/ProfileData/InstrProf.h"
+#include "llvm/Support/Allocator.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
+#include "llvm/Support/StringSaver.h"
 #include "llvm/TargetParser/Triple.h"
 #include "llvm/Transforms/Instrumentation.h"
 #include "llvm/Transforms/Utils/ModuleUtils.h"
 
 #include 
 #include 
-#include 
 
 using namespace llvm;
 
@@ -148,7 +149,7 @@
   // to determine if a memory operation is atomic or not in modules compiled
   // with SanitizerBinaryMetadata.
   bool runOn(Instruction &I, MetadataInfoSet &MIS, MDBuilder &MDB,
- uint32_t &FeatureMask);
+ uint64_t &FeatureMask);
 
   // Get start/end section marker pointer.
   GlobalVariable *getSectionMarker(const Twine &MarkerName, Type *Ty);
@@ -169,6 +170,8 @@
   const SanitizerBinaryMetadataOptions Options;
   const Triple TargetTriple;
   IRBuilder<> IRB;
+  BumpPtrAllocator Alloc;
+  UniqueStringSaver StringPool{Alloc};
 };
 
 bool SanitizerBinaryMetadata::run() {
@@ -245,7 +248,7 @@
 
   // The metadata features enabled for this function, stored along covered
   // metadata (if enabled).
-  uint32_t FeatureMask = 0;
+  uint64_t FeatureMask = 0;
   // Don't emit unnecessary covered metadata for all functions to save space.
   bool RequiresCovered = false;
 
@@ -270,10 +273,8 @@
 const auto *MI = &MetadataInfo::Covered;
 MIS.insert(MI);
 const StringRef Section = getSectionName(MI->SectionSuffix);
-// The feature mask will be placed after the size of the function.
-assert(FeatureMask <= std::numeric_limits::max() &&
-   "Increase feature mask bytes and bump version");
-Constant *CFM = IRB.getInt8(FeatureMask);
+// The feature mask will be placed after the function size.
+Constant *CFM = IRB.getInt64(FeatureMask);
 F.setMetadata(LLVMContext::MD_pcsections,
   MDB.createPCSections({{Se

[PATCH] D142893: [NFC] Class for building MultilibSet

2023-02-08 Thread Michael Platings via Phabricator via cfe-commits
michaelplatings marked 4 inline comments as done.
michaelplatings added inline comments.



Comment at: clang/include/clang/Driver/Multilib.h:35-39
   std::string GCCSuffix;
   std::string OSSuffix;
   std::string IncludeSuffix;
   flags_list Flags;
   int Priority;

phosek wrote:
> Since this class is intended to be immutable, we should also consider marking 
> all fields as `const`. This can be done in a future refactoring, but it might 
> be worth leaving a `TODO` here.
Immutable was overstating it. I won't rule out that there may be a good reason 
to mutate it in future, but there's no need to actively support mutation now. I 
removed "immutable" from the comment.



Comment at: clang/include/clang/Driver/Multilib.h:85
 public:
   using multilib_list = std::vector;
   using const_iterator = multilib_list::const_iterator;

phosek wrote:
> Since this class is intended to be immutable, and the number of `Multilib`s 
> is known at construction time, we could use `llvm::TrailingObjects` instead 
> of `std::vector` which would be more efficient. This can be done in a future 
> refactoring, but it might be worth leaving a `TODO` here.
Immutable was overstating it, and wasn't intended to apply to this class - a 
later change adds a parse() method which mutates in-place. I'm also sceptical 
of TODOs ever getting done - there are over 3,000 of them in `llvm/lib` alone :(



Comment at: clang/include/clang/Driver/Multilib.h:105-106
 
-  /// Filter out those Multilibs whose gccSuffix matches the given expression
-  MultilibSet &FilterOut(const char *Regex);
-
   /// Add a completed Multilib to the set
   void push_back(const Multilib &M);
 

phosek wrote:
> I don't think we should expose this method to maintain the invariant that 
> `MultilibSet` is immutable post construction, instead this method should be 
> provided by `MultilibSetBuilder`.
Immutable was overstating it, and wasn't intended to apply to this class - a 
later change adds a `parse()` method which mutates in-place. I did start off by 
removing push_back() but found it made the class less convenient to use.



Comment at: clang/lib/Driver/ToolChains/BareMetal.cpp:32
 
-static Multilib makeMultilib(StringRef commonSuffix) {
-  return Multilib(commonSuffix, commonSuffix, commonSuffix);
+static MultilibBuilderVariant makeMultilib(StringRef commonSuffix) {
+  return MultilibBuilderVariant(commonSuffix, commonSuffix, commonSuffix);

phosek wrote:
> michaelplatings wrote:
> > peter.smith wrote:
> > > Worth making this a lambda in findRISCVMultilibs? Purely subjective 
> > > opinion here as there could be an attempt to limit changes.
> > > there could be an attempt to limit changes.
> > Indeed. I'd rather leave this in place for that reason.
> I'd suggest adding a single argument constructor to `MultilibBuilder` since 
> this pattern is replicated across different files and so it makes sense to 
> generalize but I agree that we can do that in a follow up change as a 
> cleanup/refactor.
I've gone ahead and added the constructor in this patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142893

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


[PATCH] D143214: [include-mapping] Add C-compatibility symbol entries.

2023-02-08 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/unittests/StdLibTests.cpp:37
   EXPECT_THAT(CXX, HasSubstr("#include "));
-  EXPECT_THAT(CXX, Not(HasSubstr("#include ")));
+  EXPECT_THAT(CXX, HasSubstr("#include "));
 

hokein wrote:
> This is a behavior change, I think it is probably fine. Would be nice to have 
> a second look.
let's change it to `stdatomic.h` instead.



Comment at: clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp:217
+NSSymbolMap *Recognizer::namespaceSymbols(const NamespaceDecl *D, Lang L) {
+  // D could be nullptr!
   auto It = NamespaceCache.find(D);

nit: i think it's better to early-exit when D is nullptr rather than thinking 
about that in the rest of the logic.



Comment at: clang/unittests/Tooling/StandardLibraryTest.cpp:68
   EXPECT_THAT(stdlib::Symbol::all(), Contains(*Vector));
-  EXPECT_FALSE(stdlib::Header::named(""));
-  EXPECT_FALSE(stdlib::Header::named("", stdlib::Lang::CXX));
+  EXPECT_TRUE(stdlib::Header::named("", stdlib::Lang::CXX));
   EXPECT_TRUE(stdlib::Header::named("", stdlib::Lang::C));

as mentioned above, you can use `stdatomic.h` instead



Comment at: clang/unittests/Tooling/StandardLibraryTest.cpp:68
   EXPECT_THAT(stdlib::Symbol::all(), Contains(*Vector));
-  EXPECT_FALSE(stdlib::Header::named(""));
-  EXPECT_FALSE(stdlib::Header::named("", stdlib::Lang::CXX));
+  EXPECT_TRUE(stdlib::Header::named("", stdlib::Lang::CXX));
   EXPECT_TRUE(stdlib::Header::named("", stdlib::Lang::C));

kadircet wrote:
> as mentioned above, you can use `stdatomic.h` instead
maybe put everything below into a separate test for CCompat?



Comment at: clang/unittests/Tooling/StandardLibraryTest.cpp:71
 
-  EXPECT_FALSE(stdlib::Symbol::named("", "int16_t"));
-  EXPECT_FALSE(stdlib::Symbol::named("", "int16_t", stdlib::Lang::CXX));
+  EXPECT_TRUE(stdlib::Symbol::named("", "int16_t", stdlib::Lang::CXX));
   EXPECT_TRUE(stdlib::Symbol::named("", "int16_t", stdlib::Lang::C));

having a more comprehensive test here might be useful, e.g. check that 
`std::int16_t` only exists in C++ and just has  as a provider. 
`int16_t` exists both in C and C++ with relevant providers


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143214

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


[PATCH] D143569: [Tooling/Inclusions] Add more multi-header symbols to StdSpecialSymbolMap.inc

2023-02-08 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc:37
+SYMBOL(swap, std::, ) // since C++17
+SYMBOL(swap, std::, ) // until C++11
+// C++ [tuple.helper 22.4.7]: In addition to being available via inclusion of

i'd put this right after ``


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143569

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


[PATCH] D143559: [Tooling/Inclusion] Use the StdSpecialSymbolMap.inc in the stdlib

2023-02-08 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/unittests/Tooling/StandardLibraryTest.cpp:65
   stdlib::Header::named("")));
+  EXPECT_THAT(stdlib::Symbol::named("std::", "size_t")->headers(),
+  ElementsAre(stdlib::Header::named(""),

can you also have a test checking `header()` is ``


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143559

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


[PATCH] D143560: clang-format.el: fix warnings

2023-02-08 Thread Augustin Fabre via Phabricator via cfe-commits
augfab added inline comments.



Comment at: clang/tools/clang-format/clang-format.el:70
   (cl-case (xml-node-name node)
-('replacement
+((replacement quote)
  (let* ((offset (xml-get-attribute-or-nil node 'offset))

phst wrote:
> what's the change here?
There is no change here, nor on line 80.
I don't understand why Phabricator highlights these two lines in red/green.
The raw diff doesn't show these two lines: 
https://reviews.llvm.org/file/data/u6j4564axwglt6pu42ff/PHID-FILE-fa54axif3rocku7zfmix/D143560.diff



Comment at: clang/tools/clang-format/clang-format.el:80
(push (list offset length text) replacements)))
-('cursor
+((cursor quote)
  (setq cursor (string-to-number text)))

phst wrote:
> same here, what is being changed?
Same as above, no change, no idea why it's highlighted 😕



Comment at: clang/tools/clang-format/clang-format.el:85
  (lambda (a b)
(or (> (car a) (car b))
(and (= (car a) (car b))

phst wrote:
> The intention here is that this should be just `replacement' since I'm pretty 
> sure we don't have XML tags like 
You are right, thanks. I misunderstood what `cl-case` does.




Comment at: clang/tools/clang-format/clang-format.el:96
  'utf-8-unix)))
 (goto-char start)
 (delete-region start end)

DavidTruby wrote:
> phst wrote:
> > same here, AIUI this should just be `quote'
> I think you mean "just cursor" here
You are right.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143560

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


[PATCH] D141472: [clang][Interp] Add function pointers

2023-02-08 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

In D141472#4107008 , @aaron.ballman 
wrote:

> In D141472#4106091 , @tbaeder wrote:
>
>>> Member pointers (for functions or for data) are weird in that they're not 
>>> the typical pointer width. They're actually a pointer and between 
>>> one-to-three other fields in a trenchcoat, depending on the circumstances. 
>>> You generally need the function pointer, but you also may need various 
>>> offsets (to this, to the vtable, etc). There's some more information about 
>>> how it's done in MSVC (which is different from Itanium ABI, but we can do 
>>> what we want for the constant expression interpreter): 
>>> https://rants.vastheman.com/2021/09/21/msvc/
>>>
>>> I don't think there's a problem with `FunctionPointer` per se, I'm more 
>>> wondering are you planning to also add a `MemberPointer` type or are you 
>>> planning to reuse `FunctionPointer` to handle function members (and 
>>> presumably something else for data members)?
>>>
>>> As for virtual functions in general, the standard has rules: 
>>> http://eel.is/c++draft/expr.const#5.6 and 
>>> http://eel.is/c++draft/expr.const#7
>>
>> I was thinking that the `dynamicDispatch` in https://godbolt.org/z/rf9Ks77Wo 
>> would be a good reproducer since the actual function to call is only known 
>> when calling `dynamicDispatch()`, but that example already works when doing 
>> a few changes to `classify()` the right types and adding a `if 
>> (BO->isPtrMemOP()) { return visit(RHS); }` to `VisitBinaryOperator()`.
>
> That is a reasonable test, but probably not sufficient as nothing is really 
> testing the layout of those objects (the calls return a constant). How about 
> a test like: https://godbolt.org/z/rhhhvxYxf where there are offsets to 
> member variables involved?

Ah I get what you mean now.

The pointer we have on the stack is of type `S` but then we end up calling a 
function expecting a `S2` pointer, and which one we're calling is not known at 
compile time.

I'm not sure what to do about this right now. I was wondering about 
restructuring pointers so all the metadata is before all the actual data, but 
that would be a large refactoring.


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

https://reviews.llvm.org/D141472

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


[PATCH] D143560: clang-format.el: fix warnings

2023-02-08 Thread Augustin Fabre via Phabricator via cfe-commits
augfab updated this revision to Diff 495815.
augfab edited the summary of this revision.
augfab added a comment.

Applied suggestions.


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

https://reviews.llvm.org/D143560

Files:
  clang/tools/clang-format/clang-format.el


Index: clang/tools/clang-format/clang-format.el
===
--- clang/tools/clang-format/clang-format.el
+++ clang/tools/clang-format/clang-format.el
@@ -82,7 +82,7 @@
 (let* ((children (xml-node-children node))
(text (car children)))
   (cl-case (xml-node-name node)
-('replacement
+(replacement
  (let* ((offset (xml-get-attribute-or-nil node 'offset))
 (length (xml-get-attribute-or-nil node 'length)))
(when (or (null offset) (null length))
@@ -93,7 +93,7 @@
(setq offset (string-to-number offset))
(setq length (string-to-number length))
(push (list offset length text) replacements)))
-('cursor
+(cursor
  (setq cursor (string-to-number text)))
 
 ;; Sort by decreasing offset, length.


Index: clang/tools/clang-format/clang-format.el
===
--- clang/tools/clang-format/clang-format.el
+++ clang/tools/clang-format/clang-format.el
@@ -82,7 +82,7 @@
 (let* ((children (xml-node-children node))
(text (car children)))
   (cl-case (xml-node-name node)
-('replacement
+(replacement
  (let* ((offset (xml-get-attribute-or-nil node 'offset))
 (length (xml-get-attribute-or-nil node 'length)))
(when (or (null offset) (null length))
@@ -93,7 +93,7 @@
(setq offset (string-to-number offset))
(setq length (string-to-number length))
(push (list offset length text) replacements)))
-('cursor
+(cursor
  (setq cursor (string-to-number text)))
 
 ;; Sort by decreasing offset, length.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140745: Generate Config {Fragment structure, json schema, docs, YAML parser} from schema spec

2023-02-08 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Based on offline discussion, doubling down on checking in generated files to 
make these easy/possible to consume where they're needed.

rebased and addressed high level comments (I think!)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140745

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


[PATCH] D143414: [clang] refactor FileManager::GetUniqueIDMapping

2023-02-08 Thread Richard Howell via Phabricator via cfe-commits
rmaz added a comment.

In D143414#4110461 , @benlangmuir 
wrote:

>> This should allow the path serialization of input files to use the paths 
>> used when looking up a file entry, instead of the last reference.
>
> Isn't this at odds with not having the VFS-mapped paths?
>
> It's not obvious to me why we want these specific semantics.  Elsewhere we 
> have tried to preserve the virtual paths as well as the vfsoverlay files 
> needed to interpret them.  Is there a reason the current approach is better? 
> I feel like there may be context here I'm lacking

My understanding for why we were dropping the virtual paths is that we would 
already have the on-disk path entries anyway, but @jansvoboda11 may know more.

The reason for the change from FileEntry to FileEntryRef is so we can produce 
deterministic pcm output regardless of if the files are regular files or hard 
links pointing to the same inode. Currently this can result in varying paths 
and numbers of inputs being serialized.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143414

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


[PATCH] D142534: [clang][codegen] Fix emission of consteval constructor of derived type

2023-02-08 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.

LGTM, but please add a release note about the issues this fixes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142534

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


[PATCH] D143478: [RFC][Flang][driver] Try to support `flang -fc1as`

2023-02-08 Thread Shao-Ce SUN via Phabricator via cfe-commits
sunshaoce abandoned this revision.
sunshaoce added a comment.

A better implementation is in D143572 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143478

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


[PATCH] D143287: [Clang][x86] Change x86 cast intrinsics to use __builtin_nondeterministic_value

2023-02-08 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added inline comments.



Comment at: clang/test/CodeGen/X86/avx-builtins.c:146
   // CHECK-LABEL: test_mm256_castpd128_pd256
-  // CHECK: shufflevector <2 x double> %{{.*}}, <2 x double> %{{.*}}, <4 x 
i32> 
+  // CHECK: shufflevector <2 x double> %{{.*}}, <2 x double> %{{.*}}, <4 x 
i32> 
   return _mm256_castpd128_pd256(A);

Would it be useful to add a check for a "freeze <2 x double> poison" (or 
similar) to each cast test?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143287

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


[PATCH] D143197: [clangd] Fix bugs in main-file include patching for stale preambles

2023-02-08 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/clangd/Preamble.cpp:691
+// it's coming from baseline preamble.
+if (It->second)
+  PatchedInc = *It->second;

if It->second is null, then all the `#includes` of this header from the 
baseline preamble were in disabled sections, so it's *very* likely this one is 
too.

I think we're better not pushing onto PP.PreambleIncludes at all in this case, 
rather than pushing an unresolved one - this is how the MainFileIncludes looks 
like when an `#include` is in a disabled section and there's no patching 
happening.



Comment at: clang-tools-extra/clangd/unittests/PreambleTests.cpp:236
+TEST(PreamblePatchTest, IncludesArePreserved) {
+  llvm::StringLiteral Baseline = "//error-ok\n#include \n#include 
\n";
+  auto Modified = Baseline + "#define FOO\n";

rawstrings?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143197

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


[PATCH] D143587: [Docs] Multilib design

2023-02-08 Thread Michael Platings via Phabricator via cfe-commits
michaelplatings created this revision.
michaelplatings added reviewers: peter.smith, phosek.
Herald added a subscriber: arphaman.
Herald added a project: All.
michaelplatings requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143587

Files:
  clang/docs/Multilib.rst
  clang/docs/index.rst

Index: clang/docs/index.rst
===
--- clang/docs/index.rst
+++ clang/docs/index.rst
@@ -100,6 +100,7 @@
CodeOwners
InternalsManual
DriverInternals
+   Multilib
OffloadingDesign
PCHInternals
ItaniumMangleAbiTags
Index: clang/docs/Multilib.rst
===
--- /dev/null
+++ clang/docs/Multilib.rst
@@ -0,0 +1,170 @@
+
+Multilib
+
+
+Introduction
+
+
+This document describes how multilib is implemented in Clang.
+
+What is multilib and why might you care?
+If you're :doc:`cross compiling` then you can't use native
+system headers and libraries. To address this, you can use a combination of
+``--sysroot``, ``-isystem`` and ``-L`` options to point clang at suitable
+directories for your target.
+However, when there are many possible directories to choose from, it's not
+necessarily obvious which one to pick.
+Multilib allows a toolchain designer to imbue the toolchain with the ability to
+pick a suitable directory automatically, based on the options the user provides
+to clang. For example, if the user specifies
+``--target=arm-none-eabi -mcpu=cortex-m4`` the toolchain can choose a directory
+containing headers and libraries suitable for Armv7E-M, because it knows that's
+a suitable architecture for Arm Cortex-M4.
+Multilib can also choose between libraries for the same architecture based on
+other options. For example if the user specifies ``-fno-exceptions`` then a
+toolchain could select libraries built without exception support, thereby
+reducing the size of the resulting binary.
+
+Design
+==
+
+Clang supports GCC's ``-print-multi-lib`` and ``-print-multi-directory``
+options. These are described in
+`GCC Developer Options `_.
+
+There are two ways to configure multilib in Clang: hard-coded or via a
+configuration file.
+
+Hard-coded Multilib
+===
+
+The available libraries can be hard-coded in clang. Typically this is done
+using the ``MultilibBuilder`` interface. There are many examples of this in
+``Gnu.cpp``.
+The remainder of this document will not focus on this type of multilib.
+
+Multilib via configuration file
+===
+
+Some clang toolchains support loading multilib configuration from a
+``multilib.yaml`` configuration file.
+
+A ``multilib.yaml`` configuration file specifies which multilib variants are
+available, their relative location, what compilation options were used to build
+them, and the criteria by which they are selected.
+
+Multilib processing
+===
+
+Clang goes through the following steps to use multilib from a configuration
+file:
+#. Convert command line arguments to flags. Clang can accept the same
+   information via different arguments - for example,
+   ``--target=arm-none-eabi -march=armv7-m`` and
+   ``--target=armv7m-none-eabi`` are equivalent. Clang can also accept many
+   independent pieces of information within a single flag - for example
+   ``-march=armv8.1m.main+fp+mve`` specifies the architecture and two
+   extensions in a single command line argument.
+   To make it easier for the multilib system, clang converts the command line
+   arguments into a standard set of simpler "flags". In many cases these flags
+   will look like a command line argument with the leading ``-`` stripped off,
+   but where a suitable form for the flag doesn't exist in command line
+   arguments then its form will be different. For example, an Arm architecture
+   extension is represented like ``march=+mve`` since there's no way to specify
+   it in isolation in a command line argument.
+   To see what flags are emitted for a given set of command line arguments, use
+   the ``-print-multi-selection-flags-experimental`` command line argument
+   along with the rest of the arguments you want to use.
+#. Load ``multilib.yaml`` from sysroot.
+#. Generate additional flags. ``multilib.yaml`` contains a ``flagMap`` section,
+   which specifies how to generate additional flags based on the flags derived
+   from command line arguments. Flags are matched using regular expressions.
+   These regular expressions shall use the POSIX extended regular expression
+   syntax.
+#. Match flags against multilib variants. If the generated flags are a superset
+   of the flags specified for a multilib variant then the variant is considered
+   a match.
+   If more than one variant matches then a toolchain may op

[PATCH] D142534: [clang][codegen] Fix emission of consteval constructor of derived type

2023-02-08 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon updated this revision to Diff 495851.
Fznamznon added a comment.

Rebase and add a release note


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142534

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/test/CodeGenCXX/cxx20-consteval-crash.cpp


Index: clang/test/CodeGenCXX/cxx20-consteval-crash.cpp
===
--- clang/test/CodeGenCXX/cxx20-consteval-crash.cpp
+++ clang/test/CodeGenCXX/cxx20-consteval-crash.cpp
@@ -92,3 +92,27 @@
 }
 } // namespace Issue55065
 
+namespace GH60166 {
+
+struct Base {
+   void* one = nullptr;
+   void* two = nullptr;
+};
+
+struct Derived : Base {
+   void* three = nullptr;
+   consteval Derived() = default;
+};
+
+void method() {
+  // CHECK: %agg.tmp.ensured = alloca %"struct.GH60166::Derived"
+  // CHECK: %0 = getelementptr inbounds { ptr, ptr, ptr }, ptr 
%agg.tmp.ensured, i32 0, i32 0
+  // CHECK: store ptr null, ptr %0, align 8
+  // CHECK: %1 = getelementptr inbounds { ptr, ptr, ptr }, ptr 
%agg.tmp.ensured, i32 0, i32 1
+  // CHECK: store ptr null, ptr %1, align 8
+  // CHECK: %2 = getelementptr inbounds { ptr, ptr, ptr }, ptr 
%agg.tmp.ensured, i32 0, i32 2
+  // CHECK: store ptr null, ptr %2, align 8
+   (void)Derived();
+}
+
+} // namespace GH60166
Index: clang/lib/CodeGen/CGExprAgg.cpp
===
--- clang/lib/CodeGen/CGExprAgg.cpp
+++ clang/lib/CodeGen/CGExprAgg.cpp
@@ -131,7 +131,14 @@
 EnsureDest(E->getType());
 
 if (llvm::Value *Result = ConstantEmitter(CGF).tryEmitConstantExpr(E)) {
-  CGF.EmitAggregateStore(Result, Dest.getAddress(),
+  Address StoreDest = Dest.getAddress();
+  // The emitted value is guaranteed to have the same size as the
+  // destination but can have a different type. Just do a bitcast in this
+  // case to avoid incorrect GEPs.
+  if (Result->getType() != StoreDest.getType())
+StoreDest =
+CGF.Builder.CreateElementBitCast(StoreDest, Result->getType());
+  CGF.EmitAggregateStore(Result, StoreDest,
  E->getType().isVolatileQualified());
   return;
 }
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -64,6 +64,9 @@
   driver mode and emit an error which suggests using ``/TC`` or ``/TP``
   ``clang-cl`` options instead. This fixes
   `Issue 59307 `_.
+- Fix crash when evaluating consteval constructor of derived class whose base
+  has more than one field. This fixes
+  `Issue 60166 `_.
 
 Improvements to Clang's diagnostics
 ^^^


Index: clang/test/CodeGenCXX/cxx20-consteval-crash.cpp
===
--- clang/test/CodeGenCXX/cxx20-consteval-crash.cpp
+++ clang/test/CodeGenCXX/cxx20-consteval-crash.cpp
@@ -92,3 +92,27 @@
 }
 } // namespace Issue55065
 
+namespace GH60166 {
+
+struct Base {
+   void* one = nullptr;
+   void* two = nullptr;
+};
+
+struct Derived : Base {
+   void* three = nullptr;
+   consteval Derived() = default;
+};
+
+void method() {
+  // CHECK: %agg.tmp.ensured = alloca %"struct.GH60166::Derived"
+  // CHECK: %0 = getelementptr inbounds { ptr, ptr, ptr }, ptr %agg.tmp.ensured, i32 0, i32 0
+  // CHECK: store ptr null, ptr %0, align 8
+  // CHECK: %1 = getelementptr inbounds { ptr, ptr, ptr }, ptr %agg.tmp.ensured, i32 0, i32 1
+  // CHECK: store ptr null, ptr %1, align 8
+  // CHECK: %2 = getelementptr inbounds { ptr, ptr, ptr }, ptr %agg.tmp.ensured, i32 0, i32 2
+  // CHECK: store ptr null, ptr %2, align 8
+   (void)Derived();
+}
+
+} // namespace GH60166
Index: clang/lib/CodeGen/CGExprAgg.cpp
===
--- clang/lib/CodeGen/CGExprAgg.cpp
+++ clang/lib/CodeGen/CGExprAgg.cpp
@@ -131,7 +131,14 @@
 EnsureDest(E->getType());
 
 if (llvm::Value *Result = ConstantEmitter(CGF).tryEmitConstantExpr(E)) {
-  CGF.EmitAggregateStore(Result, Dest.getAddress(),
+  Address StoreDest = Dest.getAddress();
+  // The emitted value is guaranteed to have the same size as the
+  // destination but can have a different type. Just do a bitcast in this
+  // case to avoid incorrect GEPs.
+  if (Result->getType() != StoreDest.getType())
+StoreDest =
+CGF.Builder.CreateElementBitCast(StoreDest, Result->getType());
+  CGF.EmitAggregateStore(Result, StoreDest,
  E->getType().isVolatileQualified());
   return;
 }
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.

[PATCH] D143507: [RISCV][MC] Mark Zawrs extension as non-experimental

2023-02-08 Thread Philip Reames via Phabricator via cfe-commits
reames accepted this revision.
reames 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/D143507/new/

https://reviews.llvm.org/D143507

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


[clang] 37eb9d1 - Revert "[Support] change StringMap hash function from djbHash to xxHash"

2023-02-08 Thread Erik Desjardins via cfe-commits

Author: Erik Desjardins
Date: 2023-02-08T10:41:51-05:00
New Revision: 37eb9d13f891f7656f811516e765b929b169afe0

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

LOG: Revert "[Support] change StringMap hash function from djbHash to xxHash"

This reverts commit d768b97424f9e1a0aae45440a18b99f21c4027ce.

Causes sanitizer failure: 
https://lab.llvm.org/buildbot/#/builders/238/builds/1114

```
/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/llvm/lib/Support/xxhash.cpp:107:12:
 runtime error: applying non-zero offset 8 to null pointer
#0 0xb28ec6c8 in llvm::xxHash64(llvm::StringRef) 
/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/llvm/lib/Support/xxhash.cpp:107:12
#1 0xb28cbd38 in llvm::StringMapImpl::LookupBucketFor(llvm::StringRef) 
/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/llvm/lib/Support/StringMap.cpp:87:28
```

Probably causes test failure in 
`warn-unsafe-buffer-usage-fixits-local-var-span.cpp`: 
https://lab.llvm.org/buildbot/#/builders/60/builds/10619

Probably causes reverse-iteration test failure in `test-output-format.ll`: 
https://lab.llvm.org/buildbot/#/builders/54/builds/3545

Added: 


Modified: 
clang-tools-extra/test/modularize/ProblemsDisplayLists.modularize
clang/unittests/Basic/SarifTest.cpp
compiler-rt/test/profile/Linux/instrprof-show-debug-info-correlation.c
lldb/test/API/functionalities/gdb_remote_client/TestGDBRemoteClient.py
llvm/lib/Support/StringMap.cpp
llvm/test/DebugInfo/Generic/accel-table-hash-collisions.ll
llvm/test/DebugInfo/Generic/debug-names-hash-collisions.ll
llvm/test/DebugInfo/X86/debug-pubtables-dwarf64.ll
llvm/test/DebugInfo/X86/gnu-public-names-gmlt.ll
llvm/test/DebugInfo/X86/gnu-public-names.ll
llvm/test/tools/dsymutil/ARM/extern-alias.test
llvm/test/tools/llvm-profdata/suppl-instr-with-sample.test
mlir/test/mlir-lsp-server/completion.test

Removed: 




diff  --git a/clang-tools-extra/test/modularize/ProblemsDisplayLists.modularize 
b/clang-tools-extra/test/modularize/ProblemsDisplayLists.modularize
index afe1ece5eec08..31be95c6b6b3c 100644
--- a/clang-tools-extra/test/modularize/ProblemsDisplayLists.modularize
+++ b/clang-tools-extra/test/modularize/ProblemsDisplayLists.modularize
@@ -12,5 +12,5 @@
 
 # CHECK: These are the combined files, with problem files preceded by #:
 
-# CHECK: Inputs/CompileError/Level1A.h
 # CHECK: {{.*}}Inputs/CompileError/HasError.h
+# CHECK: Inputs/CompileError/Level1A.h

diff  --git a/clang/unittests/Basic/SarifTest.cpp 
b/clang/unittests/Basic/SarifTest.cpp
index 33bccf56babb7..06ad4e7a63091 100644
--- a/clang/unittests/Basic/SarifTest.cpp
+++ b/clang/unittests/Basic/SarifTest.cpp
@@ -332,7 +332,7 @@ TEST_F(SarifDocumentWriterTest, checkSerializingArtifacts) {
 TEST_F(SarifDocumentWriterTest, checkSerializingCodeflows) {
   // GIVEN:
   const std::string ExpectedOutput =
-  
R"({"$schema":"https://docs.oasis-open.org/sarif/sarif/v2.1.0/cos02/schemas/sarif-schema-2.1.0.json","runs":[{"artifacts":[{"length":28,"location":{"index":3,"uri":"file:///test-header-3.h"},"mimeType":"text/plain","roles":["resultFile"]},{"length":41,"location":{"index":0,"uri":"file:///main.cpp"},"mimeType":"text/plain","roles":["resultFile"]},{"length":30,"location":{"index":2,"uri":"file:///test-header-2.h"},"mimeType":"text/plain","roles":["resultFile"]},{"length":27,"location":{"index":1,"uri":"file:///test-header-1.h"},"mimeType":"text/plain","roles":["resultFile"]}],"columnKind":"unicodeCodePoints","results":[{"codeFlows":[{"threadFlows":[{"locations":[{"importance":"essential","location":{"message":{"text":"Message
 
#1"},"physicalLocation":{"artifactLocation":{"index":1,"uri":"file:///test-header-1.h"},"region":{"endColumn":8,"endLine":2,"startColumn":1,"startLine":1,{"importance":"important","location":{"message":{"text":"Message
 
#2"},"physicalLocation":{"artifactLocation":{"index":2,"uri":"file:///test-header-2.h"},"region":{"endColumn":8,"endLine":2,"startColumn":1,"startLine":1,{"importance":"unimportant","location":{"message":{"text":"Message
 
#3"},"physicalLocation":{"artifactLocation":{"index":3,"uri":"file:///test-header-3.h"},"region":{"endColumn":8,"endLine":2,"startColumn":1,"startLine":1]}]}],"level":"warning","locations":[{"physicalLocation":{"artifactLocation":{"index":0,"uri":"file:///main.cpp"},"region":{"endColumn":8,"endLine":2,"startColumn":5,"startLine":2}}}],"message":{"text":"Redefinition
 of 
'foo'"},"ruleId":"clang.unittest","ruleIndex":0}],"tool":{"driver":{"fullName":"sarif
 test 
runner","informationUri":"https://clang.llvm.org/docs/UsersManual.html","language":"en-US","name":"sarif
 
test","rules":[{"defaultConfiguration":{"enabled":true,"level":"warning","rank":-1},"ful

[PATCH] D141910: [OpenMP][OMPIRBuilder]Move SIMD alignment calculation to LLVM Frontend

2023-02-08 Thread Dominik Adamski via Phabricator via cfe-commits
domada added a comment.

In D141910#4112164 , @tschuett wrote:

> For AArch64 the default alignment is 0? I would have expected 128.

The refactored function `TargetInfo::getSimdDefaultAlign` is used only for 
calculation of default alignment for `#pragma omp simd aligned(A)`. If user 
does not specify any alignment in OpenMP simd pragma, then we will assume that 
the alignment of `A` is equal to 128 for PPC, WebAssembly or for some X86 
targets and we insert proper assumptions into LLVM IR (please refer to: clang 
test for more details 
.
 For other targets like AArch64 we don't insert any assumptions into LLVM IR 
code.

I just refactored the code and I return the same values as previous function.


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

https://reviews.llvm.org/D141910

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


[PATCH] D141910: [OpenMP][OMPIRBuilder]Move SIMD alignment calculation to LLVM Frontend

2023-02-08 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi added a comment.

In D141910#4112144 , @domada wrote:

> @akyrtzi Thank you for your feedback. Can I land the patch?

Fine be me.


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

https://reviews.llvm.org/D141910

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


[PATCH] D139395: Add CFI integer types normalization

2023-02-08 Thread Ramon de C Valle via Phabricator via cfe-commits
rcvalle updated this revision to Diff 495860.
rcvalle added a comment.

Fixed initialization order warning


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139395

Files:
  clang/docs/ControlFlowIntegrity.rst
  clang/docs/UsersManual.rst
  clang/include/clang/AST/Mangle.h
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/SanitizerArgs.h
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/MicrosoftMangle.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Driver/SanitizerArgs.cpp
  clang/test/CodeGen/cfi-icall-normalize.c
  clang/test/CodeGen/cfi-icall-normalize2.c
  clang/test/CodeGen/kcfi-normalize.c

Index: clang/test/CodeGen/kcfi-normalize.c
===
--- /dev/null
+++ clang/test/CodeGen/kcfi-normalize.c
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -fsanitize=kcfi -fsanitize-cfi-icall-experimental-normalize-integers -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -fsanitize=kcfi -fsanitize-cfi-icall-experimental-normalize-integers -x c++ -o - %s | FileCheck %s
+#if !__has_feature(kcfi)
+#error Missing kcfi?
+#endif
+
+// Test that normalized type metadata for functions are emitted for cross-language KCFI support with
+// other languages that can't represent and encode C/C++ integer types.
+
+void foo(void (*fn)(int), int arg) {
+// CHECK-LABEL: define{{.*}}foo
+// CHECK-SAME: {{.*}}!kcfi_type ![[TYPE1:[0-9]+]]
+// CHECK: call void %0(i32 noundef %1){{.*}}[ "kcfi"(i32 1162514891) ]
+fn(arg);
+}
+
+void bar(void (*fn)(int, int), int arg1, int arg2) {
+// CHECK-LABEL: define{{.*}}bar
+// CHECK-SAME: {{.*}}!kcfi_type ![[TYPE2:[0-9]+]]
+// CHECK: call void %0(i32 noundef %1, i32 noundef %2){{.*}}[ "kcfi"(i32 448046469) ]
+fn(arg1, arg2);
+}
+
+void baz(void (*fn)(int, int, int), int arg1, int arg2, int arg3) {
+// CHECK-LABEL: define{{.*}}baz
+// CHECK-SAME: {{.*}}!kcfi_type ![[TYPE3:[0-9]+]]
+// CHECK: call void %0(i32 noundef %1, i32 noundef %2, i32 noundef %3){{.*}}[ "kcfi"(i32 -2049681433) ]
+fn(arg1, arg2, arg3);
+}
+
+// CHECK: ![[TYPE1]] = !{i32 -1143117868}
+// CHECK: ![[TYPE2]] = !{i32 -460921415}
+// CHECK: ![[TYPE3]] = !{i32 -333839615}
Index: clang/test/CodeGen/cfi-icall-normalize2.c
===
--- /dev/null
+++ clang/test/CodeGen/cfi-icall-normalize2.c
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -fsanitize=cfi-icall -fsanitize-trap=cfi-icall -fsanitize-cfi-icall-experimental-normalize-integers -emit-llvm -o - %s | FileCheck %s
+
+// Test that normalized type metadata for functions are emitted for cross-language CFI support with
+// other languages that can't represent and encode C/C++ integer types.
+
+void foo(void (*fn)(int), int arg) {
+// CHECK-LABEL: define{{.*}}foo
+// CHECK-SAME: {{.*}}!type ![[TYPE1:[0-9]+]] !type !{{[0-9]+}}
+// CHECK: call i1 @llvm.type.test({{i8\*|ptr}} {{%f|%0}}, metadata !"_ZTSFvu3i32E.normalized")
+fn(arg);
+}
+
+void bar(void (*fn)(int, int), int arg1, int arg2) {
+// CHECK-LABEL: define{{.*}}bar
+// CHECK-SAME: {{.*}}!type ![[TYPE2:[0-9]+]] !type !{{[0-9]+}}
+// CHECK: call i1 @llvm.type.test({{i8\*|ptr}} {{%f|%0}}, metadata !"_ZTSFvu3i32S_E.normalized")
+fn(arg1, arg2);
+}
+
+void baz(void (*fn)(int, int, int), int arg1, int arg2, int arg3) {
+// CHECK-LABEL: define{{.*}}baz
+// CHECK-SAME: {{.*}}!type ![[TYPE3:[0-9]+]] !type !{{[0-9]+}}
+// CHECK: call i1 @llvm.type.test({{i8\*|ptr}} {{%f|%0}}, metadata !"_ZTSFvu3i32S_S_E.normalized")
+fn(arg1, arg2, arg3);
+}
+
+// CHECK: ![[TYPE1]] = !{i64 0, !"_ZTSFvPFvu3i32ES_E.normalized"}
+// CHECK: ![[TYPE2]] = !{i64 0, !"_ZTSFvPFvu3i32S_ES_S_E.normalized"}
+// CHECK: ![[TYPE3]] = !{i64 0, !"_ZTSFvPFvu3i32S_S_ES_S_S_E.normalized"}
Index: clang/test/CodeGen/cfi-icall-normalize.c
===
--- /dev/null
+++ clang/test/CodeGen/cfi-icall-normalize.c
@@ -0,0 +1,78 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -fsanitize=cfi-icall -fsanitize-trap=cfi-icall -fsanitize-cfi-icall-experimental-normalize-integers -emit-llvm -o - %s | FileCheck %s
+
+// Test that integer types are normalized for cross-language CFI support with
+// other languages that can't represent and encode C/C++ integer types.
+
+void foo0(char arg) { }
+// CHECK: define{{.*}}foo0{{.*}}!type ![[TYPE0:[0-9]+]] !type !{{[0-9]+}}
+void foo1(char arg1, signed char arg2) { }
+// CHECK: define{{.*}}foo1{{.*}}!type ![[TYPE1:[0-9]+]] !type !{{[0-9]+}}
+void foo2(char arg1, signed char arg2, signed char arg3) { }
+// CHECK: define{{.*}}foo2{{.*}}!type ![[TYPE2:[0-9]+]] !type !{{[0-9]+}}
+void foo3(int arg) { }
+// CHECK: define{{.*}}foo3{{.*}}!type ![[TYPE3

[PATCH] D142914: [MLIR][OpenMP] Added OMPIRBuilder support for Target Data directives.

2023-02-08 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 495864.
TIFitis marked 5 inline comments as done.
TIFitis added a comment.

Addressed reviewer comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142914

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
  mlir/include/mlir/Target/LLVMIR/Dialect/Utils.h
  mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp

Index: mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
===
--- mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
+++ mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
@@ -15,10 +15,12 @@
 #include "mlir/IR/IRMapping.h"
 #include "mlir/IR/Operation.h"
 #include "mlir/Support/LLVM.h"
+#include "mlir/Target/LLVMIR/Dialect/Utils.h"
 #include "mlir/Target/LLVMIR/ModuleTranslation.h"
 
 #include "llvm/ADT/SetVector.h"
 #include "llvm/ADT/TypeSwitch.h"
+#include "llvm/Frontend/OpenMP/OMPConstants.h"
 #include "llvm/Frontend/OpenMP/OMPIRBuilder.h"
 #include "llvm/IR/DebugInfoMetadata.h"
 #include "llvm/IR/IRBuilder.h"
@@ -1338,6 +1340,191 @@
   return success();
 }
 
+/// Process MapOperands for Target Data directives.
+static LogicalResult processMapOperand(
+llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation,
+const SmallVector &mapOperands, const ArrayAttr &mapTypes,
+SmallVector &mapTypeFlags,
+SmallVectorImpl &mapNames,
+struct llvm::OpenMPIRBuilder::MapperAllocas &mapperAllocas) {
+  auto numMapOperands = mapOperands.size();
+  llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+  llvm::PointerType *i8PtrTy = builder.getInt8PtrTy();
+  llvm::ArrayType *arrI8PtrTy = llvm::ArrayType::get(i8PtrTy, numMapOperands);
+  llvm::IntegerType *i64Ty = builder.getInt64Ty();
+  llvm::ArrayType *arrI64Ty = llvm::ArrayType::get(i64Ty, numMapOperands);
+
+  unsigned index = 0;
+  for (const auto &mapOp : mapOperands) {
+const auto &mapTypeOp = mapTypes[index];
+
+llvm::Value *mapOpValue = moduleTranslation.lookupValue(mapOp);
+llvm::Value *mapOpPtrBase;
+llvm::Value *mapOpPtr;
+llvm::Value *mapOpSize;
+
+if (mapOp.getType().isa()) {
+  mapOpPtrBase = mapOpValue;
+  mapOpPtr = mapOpValue;
+  mapOpSize = ompBuilder->getSizeInBytes(mapOpValue);
+} else {
+  return failure();
+}
+
+// Store base pointer extracted from operand into the i-th position of
+// argBase.
+llvm::Value *ptrBaseGEP = builder.CreateInBoundsGEP(
+arrI8PtrTy, mapperAllocas.ArgsBase,
+{builder.getInt32(0), builder.getInt32(index)});
+llvm::Value *ptrBaseCast = builder.CreateBitCast(
+ptrBaseGEP, mapOpPtrBase->getType()->getPointerTo());
+builder.CreateStore(mapOpPtrBase, ptrBaseCast);
+
+// Store pointer extracted from operand into the i-th position of args.
+llvm::Value *ptrGEP = builder.CreateInBoundsGEP(
+arrI8PtrTy, mapperAllocas.Args,
+{builder.getInt32(0), builder.getInt32(index)});
+llvm::Value *ptrCast =
+builder.CreateBitCast(ptrGEP, mapOpPtr->getType()->getPointerTo());
+builder.CreateStore(mapOpPtr, ptrCast);
+
+// Store size extracted from operand into the i-th position of argSizes.
+llvm::Value *sizeGEP = builder.CreateInBoundsGEP(
+arrI64Ty, mapperAllocas.ArgSizes,
+{builder.getInt32(0), builder.getInt32(index)});
+builder.CreateStore(mapOpSize, sizeGEP);
+
+mapTypeFlags.push_back(mapTypeOp.dyn_cast().getInt());
+llvm::Constant *mapName =
+mlir::LLVM::createMappingInformation(mapOp.getLoc(), *ompBuilder);
+mapNames.push_back(mapName);
+++index;
+  }
+
+  return success();
+}
+
+static LogicalResult
+convertOmpTargetData(Operation *op, llvm::IRBuilderBase &builder,
+ LLVM::ModuleTranslation &moduleTranslation) {
+  unsigned numMapOperands;
+  llvm::Function *mapperFunc;
+  llvm::Value *ifCond = nullptr;
+  int64_t deviceID = llvm::omp::OMP_DEVICEID_UNDEF;
+  SmallVector mapOperands;
+  ArrayAttr mapTypes;
+
+  llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+
+  LogicalResult result =
+  llvm::TypeSwitch(op)
+  .Case([&](omp::DataOp dataOp) {
+if (dataOp.getUseDeviceAddr().size() ||
+dataOp.getUseDevicePtr().size())
+  return failure();
+
+if (auto ifExprVar = dataOp.getIfExpr())
+  ifCond = moduleTranslation.lookupValue(ifExprVar);
+
+if (auto devId = dataOp.getDevice())
+  if (auto constOp = mlir::dyn_cast(
+  de

[PATCH] D141008: [Clang][SPIR-V] Emit target extension types for OpenCL types on SPIR-V.

2023-02-08 Thread Joshua Cranmer via Phabricator via cfe-commits
jcranmer-intel updated this revision to Diff 495866.
jcranmer-intel marked 2 inline comments as done.
jcranmer-intel added a comment.
Herald added a subscriber: jdoerfert.

This updates code, and rebases tests on top of trunk.

Note: test issues still haven't been fixed, will fix that likely in the next
revision of the patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141008

Files:
  clang/include/clang-c/Index.h
  clang/include/clang/Basic/OpenCLExtensionTypes.def
  clang/lib/CodeGen/CGOpenCLRuntime.cpp
  clang/lib/CodeGen/CGOpenCLRuntime.h
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/CodeGen/TargetInfo.h
  clang/test/CodeGenOpenCL/cast_image.cl
  clang/test/CodeGenOpenCL/cl20-device-side-enqueue-attributes.cl
  clang/test/CodeGenOpenCL/cl20-device-side-enqueue.cl
  clang/test/CodeGenOpenCL/intel-subgroups-avc-ext-types.cl
  clang/test/CodeGenOpenCL/opencl_types.cl
  clang/test/CodeGenOpenCL/sampler.cl
  clang/test/Index/pipe-size.cl
  llvm/docs/SPIRVUsage.rst

Index: llvm/docs/SPIRVUsage.rst
===
--- llvm/docs/SPIRVUsage.rst
+++ llvm/docs/SPIRVUsage.rst
@@ -75,3 +75,36 @@
 Example:
 
 ``-target spirv64v1.0`` can be used to compile for SPIR-V version 1.0 with 64-bit pointer width.
+
+.. _spirv-types:
+
+Representing special types in SPIR-V
+
+
+SPIR-V specifies several kinds of opaque types. These types are represented
+using target extension types. These types are represented as follows:
+
+  .. table:: SPIR-V Opaque Types
+
+ == == =
+ SPIR-V TypeLLVM type name LLVM type arguments
+ == == =
+ OpTypeImage``spirv.Image``sampled type, dimensionality, depth, arrayed, MS, sampled, image format, access qualifier
+ OpTypeSampler  ``spirv.Sampler``  (none)
+ OpTypeSampledImage ``spirv.SampledImage`` sampled type, dimensionality, depth, arrayed, MS, sampled, image format, access qualifier
+ OpTypeEvent``spirv.Event``(none)
+ OpTypeDeviceEvent  ``spirv.DeviceEvent``  (none)
+ OpTypeReserveId``spirv.ReserveId``(none)
+ OpTypeQueue``spirv.Queue``(none)
+ OpTypePipe ``spirv.Pipe`` access qualifier
+ OpTypePipeStorage  ``spirv.PipeStorage``  (none)
+ == == =
+
+All integer arguments take the same value as they do in their `corresponding
+SPIR-V instruction `_.
+For example, the OpenCL type ``image2d_depth_ro_t`` would be represented in
+SPIR-V IR as ``target("spirv.Image", void, 1, 1, 0, 0, 0, 0, 0)``, with its
+dimensionality parameter as ``1`` meaning 2D. Sampled image types include the
+parameters of its underlying image type, so that a sampled image for the
+previous type has the representation
+``target("spirv.SampledImage, void, 1, 1, 0, 0, 0, 0, 0)``.
Index: clang/test/Index/pipe-size.cl
===
--- clang/test/Index/pipe-size.cl
+++ clang/test/Index/pipe-size.cl
@@ -1,16 +1,16 @@
 // RUN: %clang_cc1 -no-opaque-pointers -x cl -O0 -cl-std=CL2.0 -emit-llvm -triple x86_64-unknown-linux-gnu %s -o - | FileCheck %s --check-prefix=X86
-// RUN: %clang_cc1 -no-opaque-pointers -x cl -O0 -cl-std=CL2.0 -emit-llvm -triple spir-unknown-unknown %s -o - | FileCheck %s --check-prefix=SPIR
-// RUN: %clang_cc1 -no-opaque-pointers -x cl -O0 -cl-std=CL2.0 -emit-llvm -triple spir64-unknown-unknown %s -o - | FileCheck %s --check-prefix=SPIR64
+// RUN: %clang_cc1 -x cl -O0 -cl-std=CL2.0 -emit-llvm -triple spir-unknown-unknown %s -o - | FileCheck %s --check-prefix=SPIR
+// RUN: %clang_cc1 -x cl -O0 -cl-std=CL2.0 -emit-llvm -triple spir64-unknown-unknown %s -o - | FileCheck %s --check-prefix=SPIR64
 // RUN: %clang_cc1 -no-opaque-pointers -x cl -O0 -cl-std=CL2.0 -emit-llvm -triple amdgcn-amd-amdhsa %s -o - | FileCheck %s --check-prefix=AMDGCN
 __kernel void testPipe( pipe int test )
 {
 int s = sizeof(test);
 // X86: store %opencl.pipe_ro_t* %test, %opencl.pipe_ro_t** %test.addr, align 8
 // X86: store i32 8, i32* %s, align 4
-// SPIR: store %opencl.pipe_ro_t addrspace(1)* %test, %opencl.pipe_ro_t addrspace(1)** %test.addr, align 4
-// SPIR: store i32 4, i32* %s, align 4
-// SPIR64: store %opencl.pipe_ro_t addrspace(1)* %test, %opencl.pipe_ro_t addrspace(1)** %test.addr, align 8
-// SPIR64: store i32 8, i32* %s, align 4
+// SPIR: store target("spirv.Pipe",

[PATCH] D141008: [Clang][SPIR-V] Emit target extension types for OpenCL types on SPIR-V.

2023-02-08 Thread Joshua Cranmer via Phabricator via cfe-commits
jcranmer-intel marked an inline comment as done.
jcranmer-intel added inline comments.



Comment at: clang/lib/CodeGen/CGExprScalar.cpp:2260
 
-return CGF.CGM.getNullPointer(cast(ConvertType(DestTy)),
-  DestTy);
+// The type may be a target extension type instead of a pointer type
+// (e.g., OpenCL types mapped for SPIR-V). In the former case, emit a

Anastasia wrote:
> Ok, yet this looks strange to me... do you have an example that hits this 
> code?
> 
> At some point we added `CK_ZeroToOCLOpaqueType`   so I wonder if we 
> should be using this instead of `CK_NullToPointer` here i.e. ideally clang 
> should not assume too early how type are mapped into target specific 
> representation.
> 
I thought I had a test case that caused this code to be executed it, but after 
removing it and trying out the entire testsuite with it disabled, it never 
fired. So these changes are indeed unnecessary.



Comment at: clang/lib/CodeGen/CGOpenCLRuntime.cpp:200
+
+  // Choose the dimension of the image--this corresponds to the Dim parameter,
+  // so (e.g.) a 2D image has value 1, not 2.

Anastasia wrote:
> Any reason for this? Can we create a `constexpr` map or enum type that would 
> contain those numbers instead of using hard coded ones scattered around?
There are constants in the SPIR-V backend that could conceivably be reused 
(generated from tablegen), but there's no guarantee that we're being compiled 
with the LLVM SPIR-V backend enabled, which makes it hard to reuse them.

I can add some more comments to explicitly give the references that specify 
what the values mean, but I'm not entirely certain it's worth building enums 
just for this one function to use.



Comment at: clang/lib/CodeGen/CodeGenModule.cpp:239
+  // extension types.
+  if (getTriple().isSPIRV() || getTriple().isSPIR())
+OpenCLRuntime.reset(new CGSpirVOpenCLRuntime(*this));

Anastasia wrote:
> Do we want to change old SPIR representation or keep it as is? It seems that 
> SPIR spec defined them as LLVM's opaque pointer types... but I appreciate 
> that for maintenance purposes it's easier to keep those in sync.
From what I can observe, SPIR and SPIRV seem to be used interchangeably as far 
as the toolchains are concerned--anything targetting SPIR ends up going through 
the SPIRV toolchain. This is why I've triggered it for both of the toolchains.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141008

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


[PATCH] D143590: [NFC] Simplify test from change D73904

2023-02-08 Thread Michael Platings via Phabricator via cfe-commits
michaelplatings created this revision.
Herald added a subscriber: kristof.beyls.
Herald added a project: All.
michaelplatings requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This part of the test can break if multilib is enabled, and isn't
important to testing the change with which is was added.

The relevant part of the test is
ARM-EABI: "-lclang_rt.builtins-arm"
which remains.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143590

Files:
  clang/test/Driver/arm-compiler-rt.c


Index: clang/test/Driver/arm-compiler-rt.c
===
--- clang/test/Driver/arm-compiler-rt.c
+++ clang/test/Driver/arm-compiler-rt.c
@@ -2,7 +2,6 @@
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -rtlib=compiler-rt -### %s 2>&1 \
 // RUN:   | FileCheck %s -check-prefix ARM-EABI
-// ARM-EABI: 
"-L{{.*[/\\]}}Inputs/resource_dir_with_arch_subdir{{/|}}lib{{/|}}baremetal"
 // ARM-EABI: "-lclang_rt.builtins-arm"
 
 // RUN: %clang -target arm-linux-gnueabi \


Index: clang/test/Driver/arm-compiler-rt.c
===
--- clang/test/Driver/arm-compiler-rt.c
+++ clang/test/Driver/arm-compiler-rt.c
@@ -2,7 +2,6 @@
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -rtlib=compiler-rt -### %s 2>&1 \
 // RUN:   | FileCheck %s -check-prefix ARM-EABI
-// ARM-EABI: "-L{{.*[/\\]}}Inputs/resource_dir_with_arch_subdir{{/|}}lib{{/|}}baremetal"
 // ARM-EABI: "-lclang_rt.builtins-arm"
 
 // RUN: %clang -target arm-linux-gnueabi \
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127855: [OpenMP] Basic parse and sema support for modifiers in order clause

2023-02-08 Thread Sandeep via Phabricator via cfe-commits
sandeepkosuri added a comment.

In D127855#4048642 , @jyu2 wrote:

> In D127855#3956014 , @sandeepkosuri 
> wrote:
>
>> As I do not have commit access, can someone commit this patch, now that it 
>> passes the pre-merge tests ?
>
> I see some tests failed after this patch.  Failed only with -fopenmp-vesion=51
>
> https://www.godbolt.org/z/3oxWTcxn7

Hey @jyu2 , this error is not reproducible anymore, I think the issue is 
solved, by someone else's patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127855

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


[PATCH] D143590: [NFC] Simplify test from change D73904

2023-02-08 Thread Amilendra Kodithuwakku via Phabricator via cfe-commits
amilendra accepted this revision.
amilendra 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/D143590/new/

https://reviews.llvm.org/D143590

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


[PATCH] D143592: [flang][driver] Rename `flang-new -flang-experimental-exec` to `flang`

2023-02-08 Thread Brad Richardson via Phabricator via cfe-commits
everythingfunctional created this revision.
everythingfunctional added reviewers: ktras, rouson, awarzynski, 
CarolineConcatto, rovka, stuartellis, tarunprabhu, mnadeem, PeteSteinfeld, 
peixin, clementval, jpenix-quic, ekieri, FarisRehman, arnamoy10, DavidTruby, 
mstorsjo, Ericson2314, klausler, sscalpone, kiranchandramohan, kiranktp, 
richard.barton.arm, jdoerfert, Leporacanthicus, dpalermo, schweitz, shraiysh, 
h-vetinari, DavidSpickett, pmccormick, hussainjk.
everythingfunctional added projects: Flang, LLVM.
Herald added a subscriber: sunshaoce.
Herald added a project: All.
everythingfunctional requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1, MaskRay.
Herald added a project: clang.

This patch renames the `flang-new` executable to just `flang`, and drops the 
need for the special flag `-flang-experimental-exec`. Thus, building flang 
makes the executable `flang` available as a usable compiler.

For reference, this was proposed nearly a year ago in 
https://reviews.llvm.org/D125788 and has received some new discussion and 
support in 
https://discourse.llvm.org/t/reviving-rename-flang-new-to-flang/68130.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143592

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/Flang.cpp
  clang/test/Driver/flang/flang.f90
  clang/test/Driver/flang/flang_ucase.F90
  clang/test/Driver/flang/multiple-inputs-mixed.f90
  clang/test/Driver/flang/multiple-inputs.f90
  flang/docs/FlangDriver.md
  flang/docs/ImplementingASemanticCheck.md
  flang/docs/Overview.md
  flang/examples/FlangOmpReport/FlangOmpReport.cpp
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  flang/test/CMakeLists.txt
  flang/test/Driver/color-diagnostics-forwarding.f90
  flang/test/Driver/convert.f90
  flang/test/Driver/disable-ext-name-interop.f90
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-version.f90
  flang/test/Driver/escaped-backslash.f90
  flang/test/Driver/fdefault.f90
  flang/test/Driver/flarge-sizes.f90
  flang/test/Driver/frontend-forwarding.f90
  flang/test/Driver/intrinsic-module-path.f90
  flang/test/Driver/linker-flags.f90
  flang/test/Driver/macro-def-undef.F90
  flang/test/Driver/missing-input.f90
  flang/test/Driver/multiple-input-files.f90
  flang/test/Driver/predefined-macros-compiler-version.F90
  flang/test/Driver/std2018-wrong.f90
  flang/test/Driver/std2018.f90
  flang/test/Driver/use-module-error.f90
  flang/test/Driver/use-module.f90
  flang/test/Lower/Intrinsics/command_argument_count.f90
  flang/test/Lower/Intrinsics/exit.f90
  flang/test/Lower/Intrinsics/get_command_argument.f90
  flang/test/Lower/Intrinsics/get_environment_variable.f90
  flang/test/Lower/Intrinsics/move_alloc.f90
  flang/test/Lower/OpenACC/Todo/acc-declare.f90
  flang/test/Lower/OpenACC/Todo/acc-routine.f90
  flang/test/Lower/OpenMP/Todo/omp-declarative-allocate.f90
  flang/test/Lower/OpenMP/Todo/omp-declare-reduction.f90
  flang/test/Lower/OpenMP/Todo/omp-declare-simd.f90
  flang/test/Lower/OpenMP/Todo/omp-declare-target.f90
  flang/test/Lower/OpenMP/omp-parallel-lastprivate-clause-scalar.f90
  flang/test/lit.cfg.py
  flang/tools/f18/CMakeLists.txt
  flang/tools/f18/flang-to-external-fc.in
  flang/tools/flang-driver/CMakeLists.txt
  flang/tools/flang-driver/driver.cpp

Index: flang/tools/flang-driver/driver.cpp
===
--- flang/tools/flang-driver/driver.cpp
+++ flang/tools/flang-driver/driver.cpp
@@ -88,14 +88,15 @@
   llvm::InitLLVM x(argc, argv);
   llvm::SmallVector args(argv, argv + argc);
 
-  clang::driver::ParsedClangName targetandMode("flang", "--driver-mode=flang");
+  clang::driver::ParsedClangName targetandMode =
+  clang::driver::ToolChain::getTargetAndModeFromProgramName(argv[0]);
   std::string driverPath = getExecutablePath(args[0]);
 
   llvm::BumpPtrAllocator a;
   llvm::StringSaver saver(a);
   ExpandResponseFiles(saver, args);
 
-  // Check if flang-new is in the frontend mode
+  // Check if flang is in the frontend mode
   auto firstArg = std::find_if(args.begin() + 1, args.end(),
[](const char *a) { return a != nullptr; });
   if (firstArg != args.end()) {
@@ -104,7 +105,7 @@
<< "Valid tools include '-fc1'.\n";
   return 1;
 }
-// Call flang-new frontend
+// Call flang frontend
 if (llvm::StringRef(args[1]).startswith("-fc1")) {
   return executeFC1Tool(args);
 }
Index: flang/tools/flang-driver/CMakeLists.txt
===
--- flang/tools/flang-driver/CMakeLists.txt
+++ flang/tools/flang-driver/CMakeLists.txt
@@ -11,7 +11,7 @@
   TargetParser
 )
 
-add_flang_tool(flang-new
+add_flang_tool(flang
   driver.cpp
   fc1_main.cpp
 
@@ -

[PATCH] D143501: [WIP][clang][DebugInfo] lldb: Use preferred name's type when emitting DW_AT_names

2023-02-08 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl added a comment.

Nice! Does `expr -- std::basic_string s` still work after this change? 
Not that anyone would want to type this over `std::string` ...




Comment at: clang/test/CodeGen/debug-info-preferred-names.cpp:1
+// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited %s -o - 
-debugger-tuning=lldb | FileCheck --check-prefixes=COMMON,LLDB %s
+// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited %s -o - 
-debugger-tuning=gdb | FileCheck --check-prefixes=COMMON,GDB %s

Is `-debug-info-kind=limited` needed here? Using it here is odd since LLDB 
doesn't really support it and favors `=standalone` instead.



Comment at: 
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/TestDataFormatterLibcxxSharedPtr.py:61
 
 if self.expectedCompilerVersion(['>', '16.0']):
+string_type = "std::string"

Out of curiosity: How does this function work when building the testsuite with 
a compiler that isn't Clang?
I vaguely recall there was someone in the community running a bot that built 
the LLDB testsuite against GCC.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143501

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


[PATCH] D142890: [clangd] Add config option for fast diagnostics mode

2023-02-08 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/unittests/PreambleTests.cpp:624
+
+  llvm::StringLiteral BaselinePreamble = "#define FOO\n";
+  {

sammccall wrote:
> nit: "preamble" vs "code" is a confusing distinction when we're using both as 
> code.
> Spelling out the inputs would be IMO clearer than pasting strings together, 
> tests don't need to be DRY
>Spelling out the inputs would be IMO clearer than pasting strings together, 
>tests don't need to be DRY

Done.



Comment at: clang-tools-extra/clangd/unittests/PreambleTests.cpp:655
+  {
+// Check with removals from preamble.
+Annotations NewCode("[[#  include \"foo.h\"]]");

sammccall wrote:
> what exactly is being tested here?
> "removals" suggests we're dropping includes but think we're not.
> Is the comment change significant, or the whitespace change in the directive, 
> or both?
> The code looks OK, what's the diagnostic being emitted?
> what exactly is being tested here?

so this test is all about diagnostics that are emitted as part of the main file 
AST built, specifically the ones that are emitted on ranges inside the preamble.
the particular diagnostics on include directives are coming from 
include-cleaner.

> "removals" suggests we're dropping includes but think we're not.

idea is checking that translation logic works as intended when the preamble 
bounds got smaller.

> Is the comment change significant, or the whitespace change in the directive, 
> or both?

comment change is insignificant, it's just to make sure we are making preamble 
bounds smaller, could as well be another include.
whitespace change is insignificant since we're moving the whole directive 
around (2nd line to 0th line). it was to make it more explicit. happy to hide 
if you think that's confusing.

> The code looks OK, what's the diagnostic being emitted?

unused-include diag as mentioned above. couldn't really find any diagnostics 
that are emitted (or contain notes that are pointing) to an include directive.



Comment at: clang-tools-extra/clangd/unittests/PreambleTests.cpp:677
+auto AST = createPatchedAST(Code.code(), NewCode.code(), AdditionalFiles);
+// FIXME: We shouldn't be warning for BARXYZ, and pointing at the FOO 
inside
+// the baselinepreamble.

sammccall wrote:
> what is the warning for BARXYZ?
> 
> This comment says the diagnostic shouldn't be pointing at FOO inside 
> baselinepreamble (which I assume means the first FOO) but it already isn't - 
> did you mean "should"? This is probably just two FIXMEs.
> what is the warning for BARXYZ?

`redefinition of FOO`, it's emitted at location of `B` then we turn it into a 
range inside clangd by lexing the token. hence it's expanded into the full 
token range.

> This comment says the diagnostic shouldn't be pointing at FOO inside 
> baselinepreamble (which I assume means the first FOO) but it already isn't - 
> did you mean "should"? This is probably just two FIXMEs.

sorry that's my bad english. i was trying to say it shouldn't point at `BARXYZ` 
and **should** point at `FOO` instead.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142890

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


[PATCH] D142890: [clangd] Add config option for fast diagnostics mode

2023-02-08 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 495879.
kadircet marked 10 inline comments as done.
kadircet added a comment.

- Use raw string literals
- Make tests more expressive by mentioning diagnostic names


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142890

Files:
  clang-tools-extra/clangd/Config.h
  clang-tools-extra/clangd/ConfigCompile.cpp
  clang-tools-extra/clangd/ConfigFragment.h
  clang-tools-extra/clangd/ConfigYAML.cpp
  clang-tools-extra/clangd/Preamble.cpp
  clang-tools-extra/clangd/Preamble.h
  clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
  clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
  clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
  clang-tools-extra/clangd/unittests/PreambleTests.cpp

Index: clang-tools-extra/clangd/unittests/PreambleTests.cpp
===
--- clang-tools-extra/clangd/unittests/PreambleTests.cpp
+++ clang-tools-extra/clangd/unittests/PreambleTests.cpp
@@ -8,9 +8,13 @@
 
 #include "Annotations.h"
 #include "Compiler.h"
+#include "Config.h"
+#include "Diagnostics.h"
 #include "Headers.h"
 #include "Hover.h"
+#include "ParsedAST.h"
 #include "Preamble.h"
+#include "Protocol.h"
 #include "SourceCode.h"
 #include "TestFS.h"
 #include "TestTU.h"
@@ -19,10 +23,12 @@
 #include "clang/Format/Format.h"
 #include "clang/Frontend/FrontendActions.h"
 #include "clang/Frontend/PrecompiledPreamble.h"
+#include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/VirtualFileSystem.h"
+#include "llvm/Testing/Support/SupportHelpers.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest-matchers.h"
 #include "gtest/gtest.h"
@@ -31,10 +37,18 @@
 #include 
 #include 
 
+using testing::AllOf;
 using testing::Contains;
+using testing::ElementsAre;
+using testing::Eq;
 using testing::Field;
+using testing::HasSubstr;
+using testing::IsEmpty;
 using testing::Matcher;
 using testing::MatchesRegex;
+using testing::Not;
+using testing::UnorderedElementsAre;
+using testing::UnorderedElementsAreArray;
 
 namespace clang {
 namespace clangd {
@@ -197,9 +211,12 @@
   Field(&Inclusion::FileKind, SrcMgr::CharacteristicKind::C_User;
 }
 
-std::optional createPatchedAST(llvm::StringRef Baseline,
-  llvm::StringRef Modified) {
-  auto BaselinePreamble = TestTU::withCode(Baseline).preamble();
+std::optional
+createPatchedAST(llvm::StringRef Baseline, llvm::StringRef Modified,
+ llvm::StringMap AdditionalFiles = {}) {
+  auto PreambleTU = TestTU::withCode(Baseline);
+  PreambleTU.AdditionalFiles = std::move(AdditionalFiles);
+  auto BaselinePreamble = PreambleTU.preamble();
   if (!BaselinePreamble) {
 ADD_FAILURE() << "Failed to build baseline preamble";
 return std::nullopt;
@@ -207,7 +224,8 @@
 
   IgnoreDiagnostics Diags;
   MockFS FS;
-  auto TU = TestTU::withCode(Modified);
+  auto &TU = PreambleTU;
+  TU.Code = Modified.str();
   auto CI = buildCompilerInvocation(TU.inputs(FS), Diags);
   if (!CI) {
 ADD_FAILURE() << "Failed to build compiler invocation";
@@ -586,6 +604,161 @@
 TU.inputs(FS), *BaselinePreamble);
   EXPECT_TRUE(PP.text().empty());
 }
+
+::testing::Matcher
+withNote(::testing::Matcher NoteMatcher) {
+  return Field(&Diag::Notes, ElementsAre(NoteMatcher));
+}
+MATCHER_P(Diag, Range, "Diag at " + llvm::to_string(Range)) {
+  return arg.Range == Range;
+}
+MATCHER_P2(Diag, Range, Name,
+   "Diag at " + llvm::to_string(Range) + " = [" + Name + "]") {
+  return arg.Range == Range && arg.Name == Name;
+}
+
+TEST(PreamblePatch, DiagnosticsFromMainASTAreInRightPlace) {
+  Config Cfg;
+  Cfg.Diagnostics.AllowStalePreamble = true;
+  WithContextValue WithCfg(Config::Key, std::move(Cfg));
+
+  {
+Annotations Code("#define FOO");
+// Check with removals from preamble.
+Annotations NewCode("[[x]];/* error-ok */");
+auto AST = createPatchedAST(Code.code(), NewCode.code());
+EXPECT_THAT(*AST->getDiagnostics(),
+ElementsAre(Diag(NewCode.range(), "missing_type_specifier")));
+  }
+  {
+// Check with additions to preamble.
+Annotations Code("#define FOO");
+Annotations NewCode(R"(
+#define FOO
+#define BAR
+[[x]];/* error-ok */)");
+auto AST = createPatchedAST(Code.code(), NewCode.code());
+EXPECT_THAT(*AST->getDiagnostics(),
+ElementsAre(Diag(NewCode.range(), "missing_type_specifier")));
+  }
+}
+
+TEST(PreamblePatch, DiagnosticsToPreamble) {
+  Config Cfg;
+  Cfg.Diagnostics.AllowStalePreamble = true;
+  Cfg.Diagnostics.UnusedIncludes = Config::UnusedIncludesPolicy::Strict;
+  WithContextValue WithCfg(Config::Key, std::move(Cfg));
+
+  llvm::StringMap AdditionalFiles;
+  AdditionalFiles["foo.h"] = "#pragma once";
+  AdditionalFiles["bar.h

[PATCH] D143414: [clang] refactor FileManager::GetUniqueIDMapping

2023-02-08 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir added a comment.

+1 for determinism.  Okay I spent some time trying to understand how this code 
is used and the non-virtual paths make some sense now.  I am a bit skeptical 
about this on-disk-hash-table by filepath but that's separate from this patch.




Comment at: clang/lib/Serialization/ASTWriter.cpp:175
-
-  if (FilesByUID.size() > HS.header_file_size())
-FilesByUID.resize(HS.header_file_size());

I think you can remove `header_file_size`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143414

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


[clang] 5d07e04 - [TLS]: Clamp the alignment of TLS global variables if required by the target

2023-02-08 Thread Wolfgang Pieb via cfe-commits

Author: Wolfgang Pieb
Date: 2023-02-08T10:34:56-08:00
New Revision: 5d07e0448e38d4be0cc7b1079d72b5e3644e941c

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

LOG: [TLS]: Clamp the alignment of TLS global variables if required by the 
target

Adding a module flag 'MaxTLSAlign' describing the maximum alignment a global TLS
variable can have. Optimizers are prevented from increasing the alignment of 
such
variables beyond this threshold.

Reviewed By: probinson

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

Added: 
clang/test/CodeGen/tls-maxalign-modflag.c
llvm/test/CodeGen/X86/tls-align.ll

Modified: 
clang/lib/CodeGen/CodeGenModule.cpp
llvm/include/llvm/IR/Module.h
llvm/lib/IR/Module.cpp
llvm/lib/Transforms/Utils/Local.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 57c9e589be3ba..0f93c33194353 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -947,6 +947,10 @@ void CodeGenModule::Release() {
   if (getCodeGenOpts().SkipRaxSetup)
 getModule().addModuleFlag(llvm::Module::Override, "SkipRaxSetup", 1);
 
+  if (getContext().getTargetInfo().getMaxTLSAlign())
+getModule().addModuleFlag(llvm::Module::Error, "MaxTLSAlign",
+  getContext().getTargetInfo().getMaxTLSAlign());
+
   getTargetCodeGenInfo().emitTargetMetadata(*this, MangledDeclNames);
 
   EmitBackendOptionsMetadata(getCodeGenOpts());

diff  --git a/clang/test/CodeGen/tls-maxalign-modflag.c 
b/clang/test/CodeGen/tls-maxalign-modflag.c
new file mode 100644
index 0..d2936b66eda6d
--- /dev/null
+++ b/clang/test/CodeGen/tls-maxalign-modflag.c
@@ -0,0 +1,12 @@
+// REQUIRES: x86-registered-target
+
+// Test that we get the module flag TLSMaxAlign on the PS platforms.
+// RUN: %clang_cc1 -triple x86_64-scei-ps4 -S -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-scei-ps5 -S -emit-llvm -o - %s | FileCheck %s
+
+int main(void) {
+  return 0;
+}
+
+// CHECK-DAG: ![[MDID:[0-9]+]] = !{i32 1, !"MaxTLSAlign", i32 256}
+// CHECK-DAG: llvm.module.flags = {{.*}}![[MDID]]

diff  --git a/llvm/include/llvm/IR/Module.h b/llvm/include/llvm/IR/Module.h
index cd71a848addbb..e86880406b7ea 100644
--- a/llvm/include/llvm/IR/Module.h
+++ b/llvm/include/llvm/IR/Module.h
@@ -923,6 +923,8 @@ class LLVM_EXTERNAL_VISIBILITY Module {
   unsigned getOverrideStackAlignment() const;
   void setOverrideStackAlignment(unsigned Align);
 
+  unsigned getMaxTLSAlignment() const;
+
   /// @name Utility functions for querying and setting the build SDK version
   /// @{
 

diff  --git a/llvm/lib/IR/Module.cpp b/llvm/lib/IR/Module.cpp
index 49fadc9ed7e63..3df1e7b23625a 100644
--- a/llvm/lib/IR/Module.cpp
+++ b/llvm/lib/IR/Module.cpp
@@ -746,6 +746,13 @@ unsigned Module::getOverrideStackAlignment() const {
   return 0;
 }
 
+unsigned Module::getMaxTLSAlignment() const {
+  Metadata *MD = getModuleFlag("MaxTLSAlign");
+  if (auto *CI = mdconst::dyn_extract_or_null(MD))
+return CI->getZExtValue();
+  return 0;
+}
+
 void Module::setOverrideStackAlignment(unsigned Align) {
   addModuleFlag(ModFlagBehavior::Error, "override-stack-alignment", Align);
 }

diff  --git a/llvm/lib/Transforms/Utils/Local.cpp 
b/llvm/lib/Transforms/Utils/Local.cpp
index 624907a691de1..ddef654ca73cc 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -1423,6 +1423,12 @@ static Align tryEnforceAlignment(Value *V, Align 
PrefAlign,
 if (!GO->canIncreaseAlignment())
   return CurrentAlign;
 
+if (GO->isThreadLocal()) {
+  unsigned MaxTLSAlign = GO->getParent()->getMaxTLSAlignment() / CHAR_BIT;
+  if (MaxTLSAlign && PrefAlign > Align(MaxTLSAlign))
+PrefAlign = Align(MaxTLSAlign);
+}
+
 GO->setAlignment(PrefAlign);
 return PrefAlign;
   }

diff  --git a/llvm/test/CodeGen/X86/tls-align.ll 
b/llvm/test/CodeGen/X86/tls-align.ll
new file mode 100644
index 0..3c8ee6b3f8ab2
--- /dev/null
+++ b/llvm/test/CodeGen/X86/tls-align.ll
@@ -0,0 +1,20 @@
+; REQUIRES: x86-registered-target
+; RUN: opt -passes=instcombine -S < %s | FileCheck %s
+
+%class.Arr = type <{ [160 x %class.Derived], i32, [4 x i8] }>
+%class.Derived = type { %class.Base, ptr }
+%class.Base = type { ptr }
+
+@array = hidden thread_local global %class.Arr zeroinitializer, align 32
+; CHECK: @array{{.*}}align 32
+
+@_ZTV7Derived = constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr null, ptr 
null, ptr null] }, align 8
+
+define internal fastcc void @foo() unnamed_addr {
+entry:
+  store <8 x ptr> , ptr @array, align 32
+  ret void
+}
+
+!llvm.module.flags = !{!0}
+!0 = !{i32 1, !"MaxTLSAlign", i32 256}



_

[PATCH] D143501: [WIP][clang][DebugInfo] lldb: Use preferred name's type when emitting DW_AT_names

2023-02-08 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added inline comments.



Comment at: 
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/TestDataFormatterLibcxxSharedPtr.py:61
 
 if self.expectedCompilerVersion(['>', '16.0']):
+string_type = "std::string"

aprantl wrote:
> Out of curiosity: How does this function work when building the testsuite 
> with a compiler that isn't Clang?
> I vaguely recall there was someone in the community running a bot that built 
> the LLDB testsuite against GCC.
Good point, this should also check for the compiler really. I assume because 
GCC isn't at that version yet it just works on that GCC buildbot

Will change in a different patch since there's other tests with this condition


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143501

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


[PATCH] D140123: [TLS] Clamp the alignment of TLS global variables if required by the target

2023-02-08 Thread Wolfgang Pieb 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 rG5d07e0448e38: [TLS]: Clamp the alignment of TLS global 
variables if required by the target (authored by wolfgangp).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140123

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/tls-maxalign-modflag.c
  llvm/include/llvm/IR/Module.h
  llvm/lib/IR/Module.cpp
  llvm/lib/Transforms/Utils/Local.cpp
  llvm/test/CodeGen/X86/tls-align.ll

Index: llvm/test/CodeGen/X86/tls-align.ll
===
--- /dev/null
+++ llvm/test/CodeGen/X86/tls-align.ll
@@ -0,0 +1,20 @@
+; REQUIRES: x86-registered-target
+; RUN: opt -passes=instcombine -S < %s | FileCheck %s
+
+%class.Arr = type <{ [160 x %class.Derived], i32, [4 x i8] }>
+%class.Derived = type { %class.Base, ptr }
+%class.Base = type { ptr }
+
+@array = hidden thread_local global %class.Arr zeroinitializer, align 32
+; CHECK: @array{{.*}}align 32
+
+@_ZTV7Derived = constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr null, ptr null, ptr null] }, align 8
+
+define internal fastcc void @foo() unnamed_addr {
+entry:
+  store <8 x ptr> , ptr @array, align 32
+  ret void
+}
+
+!llvm.module.flags = !{!0}
+!0 = !{i32 1, !"MaxTLSAlign", i32 256}
Index: llvm/lib/Transforms/Utils/Local.cpp
===
--- llvm/lib/Transforms/Utils/Local.cpp
+++ llvm/lib/Transforms/Utils/Local.cpp
@@ -1423,6 +1423,12 @@
 if (!GO->canIncreaseAlignment())
   return CurrentAlign;
 
+if (GO->isThreadLocal()) {
+  unsigned MaxTLSAlign = GO->getParent()->getMaxTLSAlignment() / CHAR_BIT;
+  if (MaxTLSAlign && PrefAlign > Align(MaxTLSAlign))
+PrefAlign = Align(MaxTLSAlign);
+}
+
 GO->setAlignment(PrefAlign);
 return PrefAlign;
   }
Index: llvm/lib/IR/Module.cpp
===
--- llvm/lib/IR/Module.cpp
+++ llvm/lib/IR/Module.cpp
@@ -746,6 +746,13 @@
   return 0;
 }
 
+unsigned Module::getMaxTLSAlignment() const {
+  Metadata *MD = getModuleFlag("MaxTLSAlign");
+  if (auto *CI = mdconst::dyn_extract_or_null(MD))
+return CI->getZExtValue();
+  return 0;
+}
+
 void Module::setOverrideStackAlignment(unsigned Align) {
   addModuleFlag(ModFlagBehavior::Error, "override-stack-alignment", Align);
 }
Index: llvm/include/llvm/IR/Module.h
===
--- llvm/include/llvm/IR/Module.h
+++ llvm/include/llvm/IR/Module.h
@@ -923,6 +923,8 @@
   unsigned getOverrideStackAlignment() const;
   void setOverrideStackAlignment(unsigned Align);
 
+  unsigned getMaxTLSAlignment() const;
+
   /// @name Utility functions for querying and setting the build SDK version
   /// @{
 
Index: clang/test/CodeGen/tls-maxalign-modflag.c
===
--- /dev/null
+++ clang/test/CodeGen/tls-maxalign-modflag.c
@@ -0,0 +1,12 @@
+// REQUIRES: x86-registered-target
+
+// Test that we get the module flag TLSMaxAlign on the PS platforms.
+// RUN: %clang_cc1 -triple x86_64-scei-ps4 -S -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-scei-ps5 -S -emit-llvm -o - %s | FileCheck %s
+
+int main(void) {
+  return 0;
+}
+
+// CHECK-DAG: ![[MDID:[0-9]+]] = !{i32 1, !"MaxTLSAlign", i32 256}
+// CHECK-DAG: llvm.module.flags = {{.*}}![[MDID]]
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -947,6 +947,10 @@
   if (getCodeGenOpts().SkipRaxSetup)
 getModule().addModuleFlag(llvm::Module::Override, "SkipRaxSetup", 1);
 
+  if (getContext().getTargetInfo().getMaxTLSAlign())
+getModule().addModuleFlag(llvm::Module::Error, "MaxTLSAlign",
+  getContext().getTargetInfo().getMaxTLSAlign());
+
   getTargetCodeGenInfo().emitTargetMetadata(*this, MangledDeclNames);
 
   EmitBackendOptionsMetadata(getCodeGenOpts());
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D143501: [WIP][clang][DebugInfo] lldb: Use preferred name's type when emitting DW_AT_names

2023-02-08 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added inline comments.



Comment at: clang/test/CodeGen/debug-info-preferred-names.cpp:1
+// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited %s -o - 
-debugger-tuning=lldb | FileCheck --check-prefixes=COMMON,LLDB %s
+// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited %s -o - 
-debugger-tuning=gdb | FileCheck --check-prefixes=COMMON,GDB %s

aprantl wrote:
> Is `-debug-info-kind=limited` needed here? Using it here is odd since LLDB 
> doesn't really support it and favors `=standalone` instead.
Not needed, just leftover from different test. Will change


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143501

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


[PATCH] D143501: [WIP][clang][DebugInfo] lldb: Use preferred name's type when emitting DW_AT_names

2023-02-08 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

In D143501#4113347 , @aprantl wrote:

> Nice! Does `expr -- std::basic_string s` still work after this change? 
> Not that anyone would want to type this over `std::string` ...

Yup that still works. We would still emit it as `basic_string` if that was 
typed out in the source and that's how LLDB would show it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143501

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


[PATCH] D143197: [clangd] Fix bugs in main-file include patching for stale preambles

2023-02-08 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 495884.
kadircet marked 2 inline comments as done.
kadircet added a comment.

- use rawstrings in test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143197

Files:
  clang-tools-extra/clangd/Preamble.cpp
  clang-tools-extra/clangd/unittests/PreambleTests.cpp

Index: clang-tools-extra/clangd/unittests/PreambleTests.cpp
===
--- clang-tools-extra/clangd/unittests/PreambleTests.cpp
+++ clang-tools-extra/clangd/unittests/PreambleTests.cpp
@@ -15,6 +15,7 @@
 #include "TestFS.h"
 #include "TestTU.h"
 #include "XRefs.h"
+#include "clang/Basic/SourceManager.h"
 #include "clang/Format/Format.h"
 #include "clang/Frontend/FrontendActions.h"
 #include "clang/Frontend/PrecompiledPreamble.h"
@@ -23,6 +24,7 @@
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include "gmock/gmock.h"
+#include "gtest/gtest-matchers.h"
 #include "gtest/gtest.h"
 #include 
 #include 
@@ -166,7 +168,7 @@
   MockFS FS;
   IgnoreDiagnostics Diags;
   auto TU = TestTU::withCode(R"cpp(
-#include "a.h"
+#include "a.h" // IWYU pragma: keep
 #include "c.h"
   )cpp");
   TU.AdditionalFiles["a.h"] = "#include \"b.h\"";
@@ -185,9 +187,14 @@
*BaselinePreamble);
   // Only a.h should exists in the preamble, as c.h has been dropped and b.h was
   // newly introduced.
-  EXPECT_THAT(PP.preambleIncludes(),
-  ElementsAre(AllOf(Field(&Inclusion::Written, "\"a.h\""),
-Field(&Inclusion::Resolved, testPath("a.h");
+  EXPECT_THAT(
+  PP.preambleIncludes(),
+  ElementsAre(AllOf(
+  Field(&Inclusion::Written, "\"a.h\""),
+  Field(&Inclusion::Resolved, testPath("a.h")),
+  Field(&Inclusion::HeaderID, testing::Not(testing::Eq(std::nullopt))),
+  Field(&Inclusion::BehindPragmaKeep, true),
+  Field(&Inclusion::FileKind, SrcMgr::CharacteristicKind::C_User;
 }
 
 std::optional createPatchedAST(llvm::StringRef Baseline,
@@ -225,6 +232,26 @@
   .str();
 }
 
+TEST(PreamblePatchTest, IncludesArePreserved) {
+  llvm::StringLiteral Baseline = R"(//error-ok
+#include 
+#include 
+)";
+  llvm::StringLiteral Modified = R"(//error-ok
+#include 
+#include 
+#define FOO)";
+
+  auto Includes = createPatchedAST(Baseline, Modified.str())
+  ->getIncludeStructure()
+  .MainFileIncludes;
+  EXPECT_TRUE(!Includes.empty());
+  EXPECT_EQ(Includes, TestTU::withCode(Baseline)
+  .build()
+  .getIncludeStructure()
+  .MainFileIncludes);
+}
+
 TEST(PreamblePatchTest, Define) {
   // BAR should be defined while parsing the AST.
   struct {
Index: clang-tools-extra/clangd/Preamble.cpp
===
--- clang-tools-extra/clangd/Preamble.cpp
+++ clang-tools-extra/clangd/Preamble.cpp
@@ -671,10 +671,10 @@
 // We are only interested in newly added includes, record the ones in
 // Baseline for exclusion.
 llvm::DenseMap,
-   /*Resolved=*/llvm::StringRef>
+   const Inclusion *>
 ExistingIncludes;
 for (const auto &Inc : Baseline.Includes.MainFileIncludes)
-  ExistingIncludes[{Inc.Directive, Inc.Written}] = Inc.Resolved;
+  ExistingIncludes[{Inc.Directive, Inc.Written}] = &Inc;
 // There might be includes coming from disabled regions, record these for
 // exclusion too. note that we don't have resolved paths for those.
 for (const auto &Inc : BaselineScan->Includes)
@@ -685,8 +685,13 @@
   // Include already present in the baseline preamble. Set resolved path and
   // put into preamble includes.
   if (It != ExistingIncludes.end()) {
-Inc.Resolved = It->second.str();
-PP.PreambleIncludes.push_back(Inc);
+auto &PatchedInc = PP.PreambleIncludes.emplace_back();
+// Copy everything from existing include, apart from the location, when
+// it's coming from baseline preamble.
+if (It->second)
+  PatchedInc = *It->second;
+PatchedInc.HashLine = Inc.HashLine;
+PatchedInc.HashOffset = Inc.HashOffset;
 continue;
   }
   // Include is new in the modified preamble. Inject it into the patch and
@@ -696,6 +701,11 @@
   Patch << llvm::formatv(
   "#{0} {1}\n", spellingForIncDirective(Inc.Directive), Inc.Written);
 }
+  } else {
+// Make sure we have the full set of includes available even when we're not
+// patching. As these are used by features we provide afterwards like hover,
+// go-to-def or include-cleaner when preamble is stale.
+PP.PreambleIncludes = Baseline.Includes.MainFileIncludes;
   }
 
   if (DirectivesChanged) {
_

[PATCH] D143597: [clangd] Drop includes from disabled PP regions in preamble patch

2023-02-08 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: sammccall.
Herald added a subscriber: arphaman.
Herald added a project: All.
kadircet requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

In rest of the clangd functionality we treat these includes as
non-existent. Do so under preamble patching.

Depends on D143197 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143597

Files:
  clang-tools-extra/clangd/Preamble.cpp
  clang-tools-extra/clangd/unittests/PreambleTests.cpp


Index: clang-tools-extra/clangd/unittests/PreambleTests.cpp
===
--- clang-tools-extra/clangd/unittests/PreambleTests.cpp
+++ clang-tools-extra/clangd/unittests/PreambleTests.cpp
@@ -170,6 +170,9 @@
   auto TU = TestTU::withCode(R"cpp(
 #include "a.h" // IWYU pragma: keep
 #include "c.h"
+#ifdef FOO
+#include "d.h"
+#endif
   )cpp");
   TU.AdditionalFiles["a.h"] = "#include \"b.h\"";
   TU.AdditionalFiles["b.h"] = "";
@@ -178,10 +181,14 @@
   auto BaselinePreamble = buildPreamble(
   TU.Filename, *buildCompilerInvocation(PI, Diags), PI, true, nullptr);
   // We drop c.h from modified and add a new header. Since the latter is 
patched
-  // we should only get a.h in preamble includes.
+  // we should only get a.h in preamble includes. d.h shouldn't be part of the
+  // preamble, as it's coming from a disabled region.
   TU.Code = R"cpp(
 #include "a.h"
 #include "b.h"
+#ifdef FOO
+#include "d.h"
+#endif
   )cpp";
   auto PP = PreamblePatch::createFullPatch(testPath(TU.Filename), 
TU.inputs(FS),
*BaselinePreamble);
Index: clang-tools-extra/clangd/Preamble.cpp
===
--- clang-tools-extra/clangd/Preamble.cpp
+++ clang-tools-extra/clangd/Preamble.cpp
@@ -685,13 +685,16 @@
   // Include already present in the baseline preamble. Set resolved path 
and
   // put into preamble includes.
   if (It != ExistingIncludes.end()) {
-auto &PatchedInc = PP.PreambleIncludes.emplace_back();
-// Copy everything from existing include, apart from the location, when
-// it's coming from baseline preamble.
-if (It->second)
+if (It->second) {
+  // If this header is included in an active region of the baseline
+  // preamble, preserve it.
+  auto &PatchedInc = PP.PreambleIncludes.emplace_back();
+  // Copy everything from existing include, apart from the location,
+  // when it's coming from baseline preamble.
   PatchedInc = *It->second;
-PatchedInc.HashLine = Inc.HashLine;
-PatchedInc.HashOffset = Inc.HashOffset;
+  PatchedInc.HashLine = Inc.HashLine;
+  PatchedInc.HashOffset = Inc.HashOffset;
+}
 continue;
   }
   // Include is new in the modified preamble. Inject it into the patch and


Index: clang-tools-extra/clangd/unittests/PreambleTests.cpp
===
--- clang-tools-extra/clangd/unittests/PreambleTests.cpp
+++ clang-tools-extra/clangd/unittests/PreambleTests.cpp
@@ -170,6 +170,9 @@
   auto TU = TestTU::withCode(R"cpp(
 #include "a.h" // IWYU pragma: keep
 #include "c.h"
+#ifdef FOO
+#include "d.h"
+#endif
   )cpp");
   TU.AdditionalFiles["a.h"] = "#include \"b.h\"";
   TU.AdditionalFiles["b.h"] = "";
@@ -178,10 +181,14 @@
   auto BaselinePreamble = buildPreamble(
   TU.Filename, *buildCompilerInvocation(PI, Diags), PI, true, nullptr);
   // We drop c.h from modified and add a new header. Since the latter is patched
-  // we should only get a.h in preamble includes.
+  // we should only get a.h in preamble includes. d.h shouldn't be part of the
+  // preamble, as it's coming from a disabled region.
   TU.Code = R"cpp(
 #include "a.h"
 #include "b.h"
+#ifdef FOO
+#include "d.h"
+#endif
   )cpp";
   auto PP = PreamblePatch::createFullPatch(testPath(TU.Filename), TU.inputs(FS),
*BaselinePreamble);
Index: clang-tools-extra/clangd/Preamble.cpp
===
--- clang-tools-extra/clangd/Preamble.cpp
+++ clang-tools-extra/clangd/Preamble.cpp
@@ -685,13 +685,16 @@
   // Include already present in the baseline preamble. Set resolved path and
   // put into preamble includes.
   if (It != ExistingIncludes.end()) {
-auto &PatchedInc = PP.PreambleIncludes.emplace_back();
-// Copy everything from existing include, apart from the location, when
-// it's coming from baseline preamble.
-if (It->second)
+if (It->second) {
+  // If this header is included in an active region of the baseline
+  // pre

[PATCH] D143197: [clangd] Fix bugs in main-file include patching for stale preambles

2023-02-08 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/Preamble.cpp:691
+// it's coming from baseline preamble.
+if (It->second)
+  PatchedInc = *It->second;

sammccall wrote:
> if It->second is null, then all the `#includes` of this header from the 
> baseline preamble were in disabled sections, so it's *very* likely this one 
> is too.
> 
> I think we're better not pushing onto PP.PreambleIncludes at all in this 
> case, rather than pushing an unresolved one - this is how the 
> MainFileIncludes looks like when an `#include` is in a disabled section and 
> there's no patching happening.
agreed. as discussed sent out D143597


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143197

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


[PATCH] D142890: [clangd] Add config option for fast diagnostics mode

2023-02-08 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 495889.
kadircet added a comment.

- Insert missing include


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142890

Files:
  clang-tools-extra/clangd/Config.h
  clang-tools-extra/clangd/ConfigCompile.cpp
  clang-tools-extra/clangd/ConfigFragment.h
  clang-tools-extra/clangd/ConfigYAML.cpp
  clang-tools-extra/clangd/Preamble.cpp
  clang-tools-extra/clangd/Preamble.h
  clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
  clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
  clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
  clang-tools-extra/clangd/unittests/PreambleTests.cpp

Index: clang-tools-extra/clangd/unittests/PreambleTests.cpp
===
--- clang-tools-extra/clangd/unittests/PreambleTests.cpp
+++ clang-tools-extra/clangd/unittests/PreambleTests.cpp
@@ -8,9 +8,13 @@
 
 #include "Annotations.h"
 #include "Compiler.h"
+#include "Config.h"
+#include "Diagnostics.h"
 #include "Headers.h"
 #include "Hover.h"
+#include "ParsedAST.h"
 #include "Preamble.h"
+#include "Protocol.h"
 #include "SourceCode.h"
 #include "TestFS.h"
 #include "TestTU.h"
@@ -19,10 +23,13 @@
 #include "clang/Format/Format.h"
 #include "clang/Frontend/FrontendActions.h"
 #include "clang/Frontend/PrecompiledPreamble.h"
+#include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/VirtualFileSystem.h"
+#include "llvm/Testing/Support/SupportHelpers.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest-matchers.h"
 #include "gtest/gtest.h"
@@ -31,10 +38,18 @@
 #include 
 #include 
 
+using testing::AllOf;
 using testing::Contains;
+using testing::ElementsAre;
+using testing::Eq;
 using testing::Field;
+using testing::HasSubstr;
+using testing::IsEmpty;
 using testing::Matcher;
 using testing::MatchesRegex;
+using testing::Not;
+using testing::UnorderedElementsAre;
+using testing::UnorderedElementsAreArray;
 
 namespace clang {
 namespace clangd {
@@ -204,9 +219,12 @@
   Field(&Inclusion::FileKind, SrcMgr::CharacteristicKind::C_User;
 }
 
-std::optional createPatchedAST(llvm::StringRef Baseline,
-  llvm::StringRef Modified) {
-  auto BaselinePreamble = TestTU::withCode(Baseline).preamble();
+std::optional
+createPatchedAST(llvm::StringRef Baseline, llvm::StringRef Modified,
+ llvm::StringMap AdditionalFiles = {}) {
+  auto PreambleTU = TestTU::withCode(Baseline);
+  PreambleTU.AdditionalFiles = std::move(AdditionalFiles);
+  auto BaselinePreamble = PreambleTU.preamble();
   if (!BaselinePreamble) {
 ADD_FAILURE() << "Failed to build baseline preamble";
 return std::nullopt;
@@ -214,7 +232,8 @@
 
   IgnoreDiagnostics Diags;
   MockFS FS;
-  auto TU = TestTU::withCode(Modified);
+  auto &TU = PreambleTU;
+  TU.Code = Modified.str();
   auto CI = buildCompilerInvocation(TU.inputs(FS), Diags);
   if (!CI) {
 ADD_FAILURE() << "Failed to build compiler invocation";
@@ -599,6 +618,161 @@
 TU.inputs(FS), *BaselinePreamble);
   EXPECT_TRUE(PP.text().empty());
 }
+
+::testing::Matcher
+withNote(::testing::Matcher NoteMatcher) {
+  return Field(&Diag::Notes, ElementsAre(NoteMatcher));
+}
+MATCHER_P(Diag, Range, "Diag at " + llvm::to_string(Range)) {
+  return arg.Range == Range;
+}
+MATCHER_P2(Diag, Range, Name,
+   "Diag at " + llvm::to_string(Range) + " = [" + Name + "]") {
+  return arg.Range == Range && arg.Name == Name;
+}
+
+TEST(PreamblePatch, DiagnosticsFromMainASTAreInRightPlace) {
+  Config Cfg;
+  Cfg.Diagnostics.AllowStalePreamble = true;
+  WithContextValue WithCfg(Config::Key, std::move(Cfg));
+
+  {
+Annotations Code("#define FOO");
+// Check with removals from preamble.
+Annotations NewCode("[[x]];/* error-ok */");
+auto AST = createPatchedAST(Code.code(), NewCode.code());
+EXPECT_THAT(*AST->getDiagnostics(),
+ElementsAre(Diag(NewCode.range(), "missing_type_specifier")));
+  }
+  {
+// Check with additions to preamble.
+Annotations Code("#define FOO");
+Annotations NewCode(R"(
+#define FOO
+#define BAR
+[[x]];/* error-ok */)");
+auto AST = createPatchedAST(Code.code(), NewCode.code());
+EXPECT_THAT(*AST->getDiagnostics(),
+ElementsAre(Diag(NewCode.range(), "missing_type_specifier")));
+  }
+}
+
+TEST(PreamblePatch, DiagnosticsToPreamble) {
+  Config Cfg;
+  Cfg.Diagnostics.AllowStalePreamble = true;
+  Cfg.Diagnostics.UnusedIncludes = Config::UnusedIncludesPolicy::Strict;
+  WithContextValue WithCfg(Config::Key, std::move(Cfg));
+
+  llvm::StringMap AdditionalFiles;
+  AdditionalFiles["foo.h"] = "#pragma once";
+  AdditionalFiles["bar.h"] = "#pragma once";
+  {
+Annotations Code(R"(
+// Test com

[PATCH] D143093: [clangd] #undef macros inside preamble patch

2023-02-08 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 495891.
kadircet marked 3 inline comments as done.
kadircet added a comment.

- Use raw strings
- Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143093

Files:
  clang-tools-extra/clangd/Preamble.cpp
  clang-tools-extra/clangd/unittests/PreambleTests.cpp

Index: clang-tools-extra/clangd/unittests/PreambleTests.cpp
===
--- clang-tools-extra/clangd/unittests/PreambleTests.cpp
+++ clang-tools-extra/clangd/unittests/PreambleTests.cpp
@@ -289,6 +289,7 @@
 #define BAR
 [[BAR]])cpp",
   R"cpp(#line 0 ".*main.cpp"
+#undef BAR
 #line 2
 #define BAR
 )cpp",
@@ -300,6 +301,7 @@
 
 [[BAR]])cpp",
   R"cpp(#line 0 ".*main.cpp"
+#undef BAR
 #line 2
 #define BAR
 )cpp",
@@ -311,6 +313,7 @@
 BAR
 [[BAR]])cpp",
   R"cpp(#line 0 ".*main.cpp"
+#undef BAR
 #line 3
 #define BAR
 )cpp",
@@ -343,8 +346,10 @@
   )cpp");
 
   llvm::StringLiteral ExpectedPatch(R"cpp(#line 0 ".*main.cpp"
+#undef BAR
 #line 2
 #define BAR\(X, Y\) X Y
+#undef BAR
 #line 3
 #define BAR\(X\) X
 )cpp");
@@ -694,23 +699,17 @@
   {
 Annotations Code("#define [[FOO]] 1\n");
 // Check ranges for notes.
-Annotations NewCode(R"(#define $barxyz[[BARXYZ]] 1
+Annotations NewCode(R"(#define BARXYZ 1
 #define $foo1[[FOO]] 1
 void foo();
 #define $foo2[[FOO]] 2)");
 auto AST = createPatchedAST(Code.code(), NewCode.code(), AdditionalFiles);
 EXPECT_THAT(
 *AST->getDiagnostics(),
-ElementsAre(
-// FIXME: This diagnostics shouldn't exist. It's emitted from the
-// preamble patch to the stale location inside preamble.
-AllOf(Field(&Diag::Name, Eq("-Wmacro-redefined")),
-  Field(&Diag::File, HasSubstr("_preamble_patch_")),
-  withNote(Diag(NewCode.range("barxyz",
-AllOf(
-Diag(NewCode.range("foo2"), "-Wmacro-redefined"),
-// FIXME: This should be translated into main file.
-withNote(Field(&Note::File, HasSubstr("_preamble_patch_"));
+ElementsAre(AllOf(
+Diag(NewCode.range("foo2"), "-Wmacro-redefined"),
+// FIXME: This should be translated into main file.
+withNote(Field(&Note::File, HasSubstr("_preamble_patch_"));
   }
 }
 
Index: clang-tools-extra/clangd/Preamble.cpp
===
--- clang-tools-extra/clangd/Preamble.cpp
+++ clang-tools-extra/clangd/Preamble.cpp
@@ -213,6 +213,9 @@
   // Full text that's representing the directive, including the `#`.
   std::string Text;
   unsigned Offset;
+  tok::PPKeywordKind Directive = tok::PPKeywordKind::pp_not_keyword;
+  // Name of the macro being defined in the case of a #define directive.
+  std::string MacroName;
 
   bool operator==(const TextualPPDirective &RHS) const {
 return std::tie(DirectiveLine, Offset, Text) ==
@@ -283,6 +286,8 @@
   return;
 TextualDirectives.emplace_back();
 TextualPPDirective &TD = TextualDirectives.back();
+TD.Directive = tok::pp_define;
+TD.MacroName = MacroNameTok.getIdentifierInfo()->getName().str();
 
 const auto *MI = MD->getMacroInfo();
 TD.Text =
@@ -560,8 +565,8 @@
 
   if (BuiltPreamble) {
 log("Built preamble of size {0} for file {1} version {2} in {3} seconds",
- BuiltPreamble->getSize(), FileName, Inputs.Version,
- PreambleTimer.getTime());
+BuiltPreamble->getSize(), FileName, Inputs.Version,
+PreambleTimer.getTime());
 std::vector Diags = PreambleDiagnostics.take();
 auto Result = std::make_shared(std::move(*BuiltPreamble));
 Result->Version = Inputs.Version;
@@ -724,6 +729,10 @@
 // reduce complexity. The former might cause problems because scanning is
 // imprecise and might pick directives from disabled regions.
 for (const auto &TD : ModifiedScan->TextualDirectives) {
+  // Introduce an #undef directive before #defines to suppress any
+  // re-definition warnings.
+  if (TD.Directive == tok::pp_define)
+Patch << "#undef " << TD.MacroName << '\n';
   Patch << "#line " << TD.DirectiveLine << '\n';
   Patch << TD.Text << '\n';
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D143095: [clangd] Respect preamble-patch when handling diags

2023-02-08 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 495893.
kadircet marked 3 inline comments as done.
kadircet added a comment.

- Drop FIXME for respecting all presumed locations
- Use PatchLoc instead of PLoc
- Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143095

Files:
  clang-tools-extra/clangd/Diagnostics.cpp
  clang-tools-extra/clangd/Preamble.cpp
  clang-tools-extra/clangd/Preamble.h
  clang-tools-extra/clangd/SourceCode.cpp
  clang-tools-extra/clangd/SourceCode.h
  clang-tools-extra/clangd/unittests/PreambleTests.cpp

Index: clang-tools-extra/clangd/unittests/PreambleTests.cpp
===
--- clang-tools-extra/clangd/unittests/PreambleTests.cpp
+++ clang-tools-extra/clangd/unittests/PreambleTests.cpp
@@ -41,6 +41,7 @@
 using testing::AllOf;
 using testing::Contains;
 using testing::ElementsAre;
+using testing::ElementsAreArray;
 using testing::Eq;
 using testing::Field;
 using testing::HasSubstr;
@@ -706,10 +707,8 @@
 auto AST = createPatchedAST(Code.code(), NewCode.code(), AdditionalFiles);
 EXPECT_THAT(
 *AST->getDiagnostics(),
-ElementsAre(AllOf(
-Diag(NewCode.range("foo2"), "-Wmacro-redefined"),
-// FIXME: This should be translated into main file.
-withNote(Field(&Note::File, HasSubstr("_preamble_patch_"));
+ElementsAre(AllOf(Diag(NewCode.range("foo2"), "-Wmacro-redefined"),
+  withNote(Diag(NewCode.range("foo1"));
   }
 }
 
Index: clang-tools-extra/clangd/SourceCode.h
===
--- clang-tools-extra/clangd/SourceCode.h
+++ clang-tools-extra/clangd/SourceCode.h
@@ -333,6 +333,10 @@
  (isUppercase(Name[1]) || Name[1] == '_');
 }
 
+/// Translates locations inside preamble patch to their main-file equivalent
+/// using presumed locations. Returns \p Loc if it isn't inside preamble patch.
+SourceLocation translatePreamblePatchLocation(SourceLocation Loc,
+  const SourceManager &SM);
 } // namespace clangd
 } // namespace clang
 #endif
Index: clang-tools-extra/clangd/SourceCode.cpp
===
--- clang-tools-extra/clangd/SourceCode.cpp
+++ clang-tools-extra/clangd/SourceCode.cpp
@@ -796,6 +796,12 @@
   return Results;
 }
 
+// Checks whether \p FileName is a valid spelling of main file.
+bool isMainFile(llvm::StringRef FileName, const SourceManager &SM) {
+  auto FE = SM.getFileManager().getFile(FileName);
+  return FE && *FE == SM.getFileEntryForID(SM.getMainFileID());
+}
+
 } // namespace
 
 std::vector visibleNamespaces(llvm::StringRef Code,
@@ -1219,5 +1225,24 @@
   return SM.getBufferData(FID).startswith(ProtoHeaderComment);
 }
 
+SourceLocation translatePreamblePatchLocation(SourceLocation Loc,
+  const SourceManager &SM) {
+  auto DefFile = SM.getFileID(Loc);
+  if (auto FE = SM.getFileEntryRefForID(DefFile)) {
+auto IncludeLoc = SM.getIncludeLoc(DefFile);
+// Preamble patch is included inside the builtin file.
+if (IncludeLoc.isValid() && SM.isWrittenInBuiltinFile(IncludeLoc) &&
+FE->getName().endswith(PreamblePatch::HeaderName)) {
+  auto Presumed = SM.getPresumedLoc(Loc);
+  // Check that line directive is pointing at main file.
+  if (Presumed.isValid() && Presumed.getFileID().isInvalid() &&
+  isMainFile(Presumed.getFilename(), SM)) {
+Loc = SM.translateLineCol(SM.getMainFileID(), Presumed.getLine(),
+  Presumed.getColumn());
+  }
+}
+  }
+  return Loc;
+}
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/Preamble.h
===
--- clang-tools-extra/clangd/Preamble.h
+++ clang-tools-extra/clangd/Preamble.h
@@ -157,6 +157,8 @@
   /// Whether diagnostics generated using this patch are trustable.
   bool preserveDiagnostics() const;
 
+  static constexpr llvm::StringLiteral HeaderName = "__preamble_patch__.h";
+
 private:
   static PreamblePatch create(llvm::StringRef FileName,
   const ParseInputs &Modified,
@@ -172,11 +174,6 @@
   PreambleBounds ModifiedBounds = {0, false};
 };
 
-/// Translates locations inside preamble patch to their main-file equivalent
-/// using presumed locations. Returns \p Loc if it isn't inside preamble patch.
-SourceLocation translatePreamblePatchLocation(SourceLocation Loc,
-  const SourceManager &SM);
-
 } // namespace clangd
 } // namespace clang
 
Index: clang-tools-extra/clangd/Preamble.cpp
===
--- clang-tools-extra/clangd/Preamble.cpp
+++ clang-tools-extra/clangd/Preamble.cpp
@@ -53,7 +53,6 @@
 namespace clang {

[PATCH] D140123: [TLS] Clamp the alignment of TLS global variables if required by the target

2023-02-08 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

Missing LangRef change?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140123

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


[clang] 98e7670 - [Tooling/Inclusion] Add more multi-header symbols to StdSpecialSymbolMap.inc

2023-02-08 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2023-02-08T20:15:47+01:00
New Revision: 98e7670b64d8b5bbb12432945b476cc9634b6358

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

LOG: [Tooling/Inclusion] Add more multi-header symbols to 
StdSpecialSymbolMap.inc

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

Added: 


Modified: 
clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc

Removed: 




diff  --git a/clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc 
b/clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
index 21cadd3c190bc..3d2ea91a94d36 100644
--- a/clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
+++ b/clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
@@ -30,6 +30,22 @@ SYMBOL(unwrap_ref_decay_t, std::, )
 SYMBOL(unwrap_ref_decay_t, std::, )
 SYMBOL(wint_t, std::, )
 SYMBOL(wint_t, std::, )
+SYMBOL(swap, std::, )
+SYMBOL(swap, std::, ) // until C++11
+// C++ [string.view.synop 23.3.2]: The function templates defined in
+// [utility.swap] ... are available when  is included.
+SYMBOL(swap, std::, ) // since C++17
+// C++ [tuple.helper 22.4.7]: In addition to being available via inclusion of
+// the  header, ... any of the headers , , or 
+// are included.
+SYMBOL(tuple_size, std::, )
+SYMBOL(tuple_size, std::, )
+SYMBOL(tuple_size, std::, )
+SYMBOL(tuple_size, std::, )
+SYMBOL(tuple_element, std::, )
+SYMBOL(tuple_element, std::, )
+SYMBOL(tuple_element, std::, )
+SYMBOL(tuple_element, std::, )
 // C++ [iterator.range 25.7]: In addition to being available via inclusion of
 // the  header, the function templates in [iterator.range] are
 // available when any of the following headers are included: , ,



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


[PATCH] D143569: [Tooling/Inclusions] Add more multi-header symbols to StdSpecialSymbolMap.inc

2023-02-08 Thread Haojian Wu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
hokein marked an inline comment as done.
Closed by commit rG98e7670b64d8: [Tooling/Inclusion] Add more multi-header 
symbols to StdSpecialSymbolMap.inc (authored by hokein).

Changed prior to commit:
  https://reviews.llvm.org/D143569?vs=495787&id=495898#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143569

Files:
  clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc


Index: clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
===
--- clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
+++ clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
@@ -30,6 +30,22 @@
 SYMBOL(unwrap_ref_decay_t, std::, )
 SYMBOL(wint_t, std::, )
 SYMBOL(wint_t, std::, )
+SYMBOL(swap, std::, )
+SYMBOL(swap, std::, ) // until C++11
+// C++ [string.view.synop 23.3.2]: The function templates defined in
+// [utility.swap] ... are available when  is included.
+SYMBOL(swap, std::, ) // since C++17
+// C++ [tuple.helper 22.4.7]: In addition to being available via inclusion of
+// the  header, ... any of the headers , , or 
+// are included.
+SYMBOL(tuple_size, std::, )
+SYMBOL(tuple_size, std::, )
+SYMBOL(tuple_size, std::, )
+SYMBOL(tuple_size, std::, )
+SYMBOL(tuple_element, std::, )
+SYMBOL(tuple_element, std::, )
+SYMBOL(tuple_element, std::, )
+SYMBOL(tuple_element, std::, )
 // C++ [iterator.range 25.7]: In addition to being available via inclusion of
 // the  header, the function templates in [iterator.range] are
 // available when any of the following headers are included: , ,


Index: clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
===
--- clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
+++ clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
@@ -30,6 +30,22 @@
 SYMBOL(unwrap_ref_decay_t, std::, )
 SYMBOL(wint_t, std::, )
 SYMBOL(wint_t, std::, )
+SYMBOL(swap, std::, )
+SYMBOL(swap, std::, ) // until C++11
+// C++ [string.view.synop 23.3.2]: The function templates defined in
+// [utility.swap] ... are available when  is included.
+SYMBOL(swap, std::, ) // since C++17
+// C++ [tuple.helper 22.4.7]: In addition to being available via inclusion of
+// the  header, ... any of the headers , , or 
+// are included.
+SYMBOL(tuple_size, std::, )
+SYMBOL(tuple_size, std::, )
+SYMBOL(tuple_size, std::, )
+SYMBOL(tuple_size, std::, )
+SYMBOL(tuple_element, std::, )
+SYMBOL(tuple_element, std::, )
+SYMBOL(tuple_element, std::, )
+SYMBOL(tuple_element, std::, )
 // C++ [iterator.range 25.7]: In addition to being available via inclusion of
 // the  header, the function templates in [iterator.range] are
 // available when any of the following headers are included: , ,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D143446: [clang][deps] Ensure module invocation can be serialized

2023-02-08 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

Having this check is great! Left some nits in-line.




Comment at: clang/lib/Frontend/CompilerInvocation.cpp:644-650
 // May perform round-trip of command line arguments. By default, the round-trip
 // is enabled in assert builds. This can be overwritten at run-time via the
 // "-round-trip-args" and "-no-round-trip-args" command line flags.
 // During round-trip, the command line arguments are parsed into a dummy
 // instance of CompilerInvocation which is used to generate the command line
 // arguments again. The real CompilerInvocation instance is then created by
 // parsing the generated arguments, not the original ones.

The logic is getting a bit complicated here. I think it'd be good to break down 
what the `CheckAgainstOriginalInvocation` flag does. Feel free to come up with 
your own description.



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:746
 
-  // Generate arguments again, this time from the options we will end up using
-  // for the rest of the compilation.
   SmallVector GeneratedArgs2;
+  if (CheckAgainstOriginalInvocation)

This name is now not accurate (along with the comment below). Can you make sure 
these still make sense with the new logic?



Comment at: clang/tools/clang-scan-deps/ClangScanDeps.cpp:658
+#endif
+  if (RoundTripArgs.getNumOccurrences() ? RoundTripArgs : DoRoundTripDefault)
+if (FD.roundTripCommands(llvm::errs()))

The call to `getNumOccurrences()` is a bit odd. Can you drop that if you add 
`llvm::cl::init(false)` to the option definition?


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

https://reviews.llvm.org/D143446

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


[PATCH] D141098: [clang-format][NFC] Set LineEnding to LF in config files

2023-02-08 Thread Owen Pan via Phabricator via cfe-commits
owenpan added a comment.

In D141098#4111890 , @sunho wrote:

> I think it makes more sense to use stable version of clang-format for that 
> purpose but I'm not in a postion to decide as I don't work with format. Can 
> you change the script to use latest clang-format for format codebase and 
> revert this patch in the meantime?

We don't want to change git-clang-format on a whim. If you think there is an 
issue, please file a bug report.

> Currently, all patches that touch format part will see format verifiaction ci 
> faliure with this patch.

That's not true. We've had several clang-format commits since this patch 
landed. We don't want to defeat the purpose (or delay the effect) of this patch 
and should let the premerge check fail if the patch to the current format 
source is not formatted by the latest clang-format.

This is the only buildbot reported to be impacted by this patch. Can we fix the 
bot instead? In addition to using `--binary` of git-clang-format as I suggested 
before, another way would be to format a patch to files outside the format 
directory?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141098

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


[PATCH] D143214: [include-mapping] Add C-compatibility symbol entries.

2023-02-08 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 495910.
hokein marked 3 inline comments as done.
hokein added a comment.

address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143214

Files:
  clang-tools-extra/clangd/unittests/StdLibTests.cpp
  clang/include/clang/Tooling/Inclusions/StandardLibrary.h
  clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
  clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc
  clang/tools/include-mapping/cppreference_parser.py
  clang/tools/include-mapping/gen_std.py
  clang/unittests/Tooling/StandardLibraryTest.cpp

Index: clang/unittests/Tooling/StandardLibraryTest.cpp
===
--- clang/unittests/Tooling/StandardLibraryTest.cpp
+++ clang/unittests/Tooling/StandardLibraryTest.cpp
@@ -65,13 +65,24 @@
 
   EXPECT_THAT(stdlib::Header::all(), Contains(*VectorH));
   EXPECT_THAT(stdlib::Symbol::all(), Contains(*Vector));
-  EXPECT_FALSE(stdlib::Header::named(""));
-  EXPECT_FALSE(stdlib::Header::named("", stdlib::Lang::CXX));
-  EXPECT_TRUE(stdlib::Header::named("", stdlib::Lang::C));
+  EXPECT_TRUE(stdlib::Header::named("", stdlib::Lang::CXX));
+  EXPECT_FALSE(stdlib::Header::named("", stdlib::Lang::CXX));
+}
 
-  EXPECT_FALSE(stdlib::Symbol::named("", "int16_t"));
-  EXPECT_FALSE(stdlib::Symbol::named("", "int16_t", stdlib::Lang::CXX));
-  EXPECT_TRUE(stdlib::Symbol::named("", "int16_t", stdlib::Lang::C));
+TEST(StdlibTest, CCompat) {
+  EXPECT_THAT(
+  stdlib::Symbol::named("", "int16_t", stdlib::Lang::CXX)->headers(),
+  ElementsAre(stdlib::Header::named(""),
+  stdlib::Header::named("")));
+  EXPECT_THAT(
+  stdlib::Symbol::named("std::", "int16_t", stdlib::Lang::CXX)->headers(),
+  ElementsAre(stdlib::Header::named("")));
+
+  EXPECT_TRUE(stdlib::Header::named("", stdlib::Lang::C));
+  EXPECT_THAT(
+  stdlib::Symbol::named("", "int16_t", stdlib::Lang::C)->headers(),
+  ElementsAre(stdlib::Header::named("", stdlib::Lang::C)));
+  EXPECT_FALSE(stdlib::Symbol::named("std::", "int16_t", stdlib::Lang::C));
 }
 
 TEST(StdlibTest, Recognizer) {
@@ -127,9 +138,9 @@
   EXPECT_EQ(Recognizer(Nest), stdlib::Symbol::named("std::", "vector"));
   EXPECT_EQ(Recognizer(Clock),
 stdlib::Symbol::named("std::chrono::", "system_clock"));
-  EXPECT_EQ(Recognizer(CDivT), stdlib::Symbol::named("", "div_t"));
-  EXPECT_EQ(Recognizer(CDivT),
-stdlib::Symbol::named("", "div_t", stdlib::Lang::C));
+  auto DivT = stdlib::Symbol::named("", "div_t", stdlib::Lang::CXX);
+  EXPECT_TRUE(DivT);
+  EXPECT_EQ(Recognizer(CDivT), DivT);
   EXPECT_EQ(Recognizer(Sec), std::nullopt);
 }
 
Index: clang/tools/include-mapping/gen_std.py
===
--- clang/tools/include-mapping/gen_std.py
+++ clang/tools/include-mapping/gen_std.py
@@ -39,6 +39,7 @@
 import datetime
 import os
 import sys
+import re
 
 
 CODE_PREFIX = """\
@@ -170,6 +171,69 @@
   return headers
 
 
+def GetCCompatibilitySymbols(symbol):
+   # C++ form of the C standard headers.
+  c_compat_headers = {
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+  }
+  # C++ [support.c.headers.other] 17.14.7
+  #..., behaves as if each name placed in the standard library namespace by
+  #the corresponding  header is placed within the global namespace
+  #scope, except for the functions described in [sf.cmath], the
+  #std​::​lerp function overloads ([c.math.lerp]), the declaration of
+  #std​::​byte ([cstddef.syn]), and the functions and function templates
+  #described in [support.types.byteops].
+  exception_symbols = {
+"(assoc_)?laguerre[f|l]?",
+"(assoc_|sph_)?legendre[f|l]?",
+"beta[f|l]?",
+"(comp_)?ellint_[1-3][f|l]?",
+"(cyl_|sph_)?bessel_[i-k][f|l]?",
+"(cyl_|sph_)?neumann[f|l]?",
+"expint[f|l]?",
+"hermite[f|l]?",
+"riemann_zeta[f|l]?",
+"lerp",
+"byte",
+  }
+  assert(len(symbol.headers) == 1)
+  header = symbol.headers[0]
+  if header not in c_compat_headers:
+return []
+  if any(re.fullmatch(x, symbol.name) for x in exception_symbols):
+return []
+
+  # Introduce two more entries, both in the global namespace, one using the
+  # C++-compat header and another using the C header.
+  results = []
+  if symbol.namespace != None:
+# avoid printing duplicated entries, for C macros!
+results.append(cppreference_parser.Symbol(symbol.name, None, [header]))
+  c_header = "<" + header[2:-1] +  ".h>" #  => 
+  results.append(cppreference_parser.Symbol(symbol.name, None, [c_header]))
+  return results
+
+
 def main():
   args = ParseArg()
   if args.symbols == 'cpp':
@@ -192,6 +256,7 @@
   # Zombie symbols that were available from the Standard Library, but are

[PATCH] D143214: [include-mapping] Add C-compatibility symbol entries.

2023-02-08 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang-tools-extra/clangd/unittests/StdLibTests.cpp:37
   EXPECT_THAT(CXX, HasSubstr("#include "));
-  EXPECT_THAT(CXX, Not(HasSubstr("#include ")));
+  EXPECT_THAT(CXX, HasSubstr("#include "));
 

kadircet wrote:
> hokein wrote:
> > This is a behavior change, I think it is probably fine. Would be nice to 
> > have a second look.
> let's change it to `stdatomic.h` instead.
`stdatomic.h` is still a c-compa header (though we don't have a entry in the 
StdSymbolMap.inc now). `` might be better, it is empty file in C++ 
per C++ [standard](https://eel.is/c++draft/iso646.h.syn), so we never have a 
symbol for this header in C++ symbol map.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143214

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


[PATCH] D143553: [Clang][CMake] Add BOLT perf-training (WIP)

2023-02-08 Thread Amir Ayupov via Phabricator via cfe-commits
Amir updated this revision to Diff 495915.
Amir added a comment.

Fixes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143553

Files:
  clang/CMakeLists.txt
  clang/cmake/caches/BOLT.cmake
  clang/utils/perf-training/CMakeLists.txt
  clang/utils/perf-training/bolt.lit.cfg
  clang/utils/perf-training/bolt.lit.site.cfg.in

Index: clang/utils/perf-training/bolt.lit.site.cfg.in
===
--- /dev/null
+++ clang/utils/perf-training/bolt.lit.site.cfg.in
@@ -0,0 +1,14 @@
+@LIT_SITE_CFG_IN_HEADER@
+
+import sys
+
+config.clang_tools_dir = lit_config.substitute("@CURRENT_TOOLS_DIR@")
+config.perf_helper_dir = "@CMAKE_CURRENT_SOURCE_DIR@"
+config.test_exec_root = "@CMAKE_CURRENT_BINARY_DIR@"
+config.test_source_root = "@CLANG_PGO_TRAINING_DATA@"
+config.target_triple = "@LLVM_TARGET_TRIPLE@"
+config.python_exe = "@Python3_EXECUTABLE@"
+config.clang_obj_root = path(r"@CLANG_BINARY_DIR@")
+
+# Let the main config do the real work.
+lit_config.load_config(config, "@CLANG_SOURCE_DIR@/utils/perf-training/bolt.lit.cfg")
Index: clang/utils/perf-training/bolt.lit.cfg
===
--- /dev/null
+++ clang/utils/perf-training/bolt.lit.cfg
@@ -0,0 +1,21 @@
+# -*- Python -*-
+
+from lit import Test
+import lit.formats
+import lit.util
+import os
+import subprocess
+
+config.clang = os.path.realpath(lit.util.which('clang-bolt.inst', config.clang_tools_dir)).replace('\\', '/')
+sysroot_flags = ''
+
+config.name = 'Clang Perf Training'
+config.suffixes = ['.c', '.cc', '.cpp', '.m', '.mm', '.cu', '.ll', '.cl', '.s', '.S', '.modulemap', '.test']
+
+use_lit_shell = os.environ.get("LIT_USE_INTERNAL_SHELL")
+config.test_format = lit.formats.ShTest(use_lit_shell == "0")
+config.substitutions.append( ('%clang_cpp_skip_driver', ' %s --driver-mode=g++ %s ' % (config.clang, sysroot_flags)))
+config.substitutions.append( ('%clang_cpp', ' %s --driver-mode=g++ %s ' % (config.clang, sysroot_flags)))
+config.substitutions.append( ('%clang_skip_driver', ' %s %s ' % (config.clang, sysroot_flags)))
+config.substitutions.append( ('%clang', ' %s %s ' % (config.clang, sysroot_flags) ) )
+config.substitutions.append( ('%test_root', config.test_exec_root ) )
Index: clang/utils/perf-training/CMakeLists.txt
===
--- clang/utils/perf-training/CMakeLists.txt
+++ clang/utils/perf-training/CMakeLists.txt
@@ -59,3 +59,27 @@
 COMMENT "Generating order file"
 DEPENDS generate-dtrace-logs)
 endif()
+
+if(CLANG_BOLT_INSTRUMENT)
+  configure_lit_site_cfg(
+${CMAKE_CURRENT_SOURCE_DIR}/bolt.lit.site.cfg.in
+${CMAKE_CURRENT_BINARY_DIR}/bolt-fdata/lit.site.cfg
+)
+
+  add_lit_testsuite(generate-bolt-fdata "Generating BOLT profile for Clang"
+${CMAKE_CURRENT_BINARY_DIR}/bolt-fdata/
+EXCLUDE_FROM_CHECK_ALL
+DEPENDS clang-instrumented clear-bolt-fdata
+)
+
+  add_custom_target(clear-bolt-fdata
+COMMAND "${Python3_EXECUTABLE}" ${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py clean ${CMAKE_CURRENT_BINARY_DIR} fdata
+COMMENT "Clearing old BOLT fdata")
+
+  # Merge profiles into one using merge-fdata
+  add_custom_target(merge-bolt-fdata
+COMMAND "${Python3_EXECUTABLE}" ${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py
+merge-fdata $ ${CMAKE_CURRENT_BINARY_DIR}/prof.fdata ${CMAKE_CURRENT_BINARY_DIR}
+COMMENT "Merging BOLT fdata"
+DEPENDS merge-fdata generate-bolt-fdata)
+endif()
Index: clang/cmake/caches/BOLT.cmake
===
--- clang/cmake/caches/BOLT.cmake
+++ clang/cmake/caches/BOLT.cmake
@@ -1,9 +1,6 @@
 set(CMAKE_BUILD_TYPE Release CACHE STRING "")
 set(CLANG_BOLT_INSTRUMENT ON CACHE BOOL "")
-set(CLANG_BOLT_INSTRUMENT_PROJECTS "llvm" CACHE STRING "")
-set(CLANG_BOLT_INSTRUMENT_TARGETS "count" CACHE STRING "")
 set(CMAKE_EXE_LINKER_FLAGS "-Wl,--emit-relocs,-znow" CACHE STRING "")
-set(CLANG_BOLT_INSTRUMENT_EXTRA_CMAKE_FLAGS "" CACHE STRING "")
 
 set(LLVM_ENABLE_PROJECTS "bolt;clang" CACHE STRING "")
 set(LLVM_TARGETS_TO_BUILD Native CACHE STRING "")
Index: clang/CMakeLists.txt
===
--- clang/CMakeLists.txt
+++ clang/CMakeLists.txt
@@ -853,95 +853,29 @@
 
 if (CLANG_BOLT_INSTRUMENT AND NOT LLVM_BUILD_INSTRUMENTED)
   set(CLANG_PATH ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang)
-  set(CLANGXX_PATH ${CLANG_PATH}++)
   set(CLANG_INSTRUMENTED ${CLANG_PATH}-bolt.inst)
-  set(CLANGXX_INSTRUMENTED ${CLANGXX_PATH}-bolt.inst)
 
   # Instrument clang with BOLT
   add_custom_target(clang-instrumented
 DEPENDS ${CLANG_INSTRUMENTED}
   )
+  set(BOLT_FDATA ${CMAKE_CURRENT_BINARY_DIR}/utils/perf-training/prof.fdata)
   add_custom_command(OUTPUT ${CLANG_INSTRUMENTED}
 DEPENDS clang llvm-bolt
 COMMAND llvm-bolt ${CLANG_PATH} -o ${CLANG_INSTRUMENTED}
   -instr

[PATCH] D143546: [clang-format] Insert a space between a numeric UDL and a dot

2023-02-08 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks accepted this revision.
HazardyKnusperkeks added inline comments.



Comment at: clang/lib/Format/TokenAnnotator.cpp:3884
   if (Style.isCpp()) {
+if (Right.is(tok::period) && Left.is(tok::numeric_constant))
+  return true;

Add a comment what that is? Without the bug report I'd not know what that 
sequence would be.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143546

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


[PATCH] D143546: [clang-format] Insert a space between a numeric UDL and a dot

2023-02-08 Thread Owen Pan via Phabricator via cfe-commits
owenpan added inline comments.



Comment at: clang/lib/Format/TokenAnnotator.cpp:3884
   if (Style.isCpp()) {
+if (Right.is(tok::period) && Left.is(tok::numeric_constant))
+  return true;

HazardyKnusperkeks wrote:
> Add a comment what that is? Without the bug report I'd not know what that 
> sequence would be.
I could do that, but the github issue is linked in the summary above and will 
be in the commit message. In general, I don't like unnecessary comments 
littered in the source. They can become outdated, out of place, misleading, and 
even wrong. How about giving an example as shown above?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143546

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


[PATCH] D139496: [CMake] Add perf profiling for clang-bolt

2023-02-08 Thread Amir Ayupov via Phabricator via cfe-commits
Amir abandoned this revision.
Amir added a comment.

Abandon in favor of D143553 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139496

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


[PATCH] D143546: [clang-format] Insert a space between a numeric UDL and a dot

2023-02-08 Thread Emilia Dreamer via Phabricator via cfe-commits
rymiel added a comment.

In D143546#4112077 , @owenpan wrote:

> As this one is an invalid-code-generation bug, I wanted it fixed ASAP.

Do you intend to backport it to the 16 release branch then?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143546

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


[PATCH] D143546: [clang-format] Insert a space between a numeric UDL and a dot

2023-02-08 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

I wonder if this can be fixed more generally by using 
`TokenConcatenation::AvoidConcat` to determine whether `clang-format` should 
require a space between two tokens. This is the logic that `clang -E` uses when 
printing preprocessed tokens to avoid token splices. For example, that should 
also stop `clang-format` breaking the last line of this:

  struct A;
  void operator<=(A, A);
  template
  struct B {};
  B b;




Comment at: clang/lib/Format/TokenAnnotator.cpp:3884
   if (Style.isCpp()) {
+if (Right.is(tok::period) && Left.is(tok::numeric_constant))
+  return true;

owenpan wrote:
> HazardyKnusperkeks wrote:
> > Add a comment what that is? Without the bug report I'd not know what that 
> > sequence would be.
> I could do that, but the github issue is linked in the summary above and will 
> be in the commit message. In general, I don't like unnecessary comments 
> littered in the source. They can become outdated, out of place, misleading, 
> and even wrong. How about giving an example as shown above?
Does `clang-format` have any formatting modes where it would leave out spaces 
around `+` or `-`? The same issue arises with things like `0xe + n`, where 
removing the space between the `0xe` and the `+` results in a token splice.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143546

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


[PATCH] D122255: Meta directive runtime support

2023-02-08 Thread Abid via Phabricator via cfe-commits
abidmalikwaterloo updated this revision to Diff 495925.
abidmalikwaterloo added a comment.

Rebase the patch to origin/main with all updates. Made changes 
to make it buildable using the new changes. 
(WIP).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122255

Files:
  clang/include/clang/AST/OpenMPClause.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/AST/StmtOpenMP.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/OpenMPClause.cpp
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/test/OpenMP/metadirective_ast_print_new_1.cpp
  clang/test/OpenMP/metadirective_ast_print_new_2.cpp
  clang/test/OpenMP/metadirective_ast_print_new_3.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPContext.h
  llvm/lib/Frontend/OpenMP/OMPContext.cpp

Index: llvm/lib/Frontend/OpenMP/OMPContext.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPContext.cpp
+++ llvm/lib/Frontend/OpenMP/OMPContext.cpp
@@ -19,6 +19,7 @@
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/raw_ostream.h"
 
+#include 
 #define DEBUG_TYPE "openmp-ir-builder"
 
 using namespace llvm;
@@ -336,6 +337,44 @@
   return Score;
 }
 
+/// Takes \p VMI and \p Ctx and sort the
+/// scores using \p VectorOfClauses
+void llvm::omp::getArrayVariantMatchForContext(
+const SmallVectorImpl &VMIs, const OMPContext &Ctx,
+SmallVector> &VectorOfClauses) {
+
+  // APInt BestScore(64, 0);
+  APInt Score(64, 0);
+  // The MapOfClauses will contain the index of the cluase and its context socre
+  llvm::DenseMap MapOfCluases;
+
+  for (unsigned u = 0, e = VMIs.size(); u < e; ++u) {
+const VariantMatchInfo &VMI = VMIs[u];
+
+SmallVector ConstructMatches;
+// If the variant is not applicable its not the best.
+if (!isVariantApplicableInContextHelper(VMI, Ctx, &ConstructMatches,
+/* DeviceSetOnly */ false)) {
+  Score = 0;
+  // adding index and its corresdoning score
+  MapOfCluases.insert({u, Score});
+  continue;
+}
+// Else get the score
+Score = getVariantMatchScore(VMI, Ctx, ConstructMatches);
+MapOfCluases.insert({u, Score});
+  }
+
+  for (auto &it : MapOfCluases)
+VectorOfClauses.push_back(it);
+
+  // The following Lamda will sort the VectorOfClauses based on the score
+  std::sort(VectorOfClauses.begin(), VectorOfClauses.end(),
+[](std::pair &a, std::pair &b) {
+  return a.second.ugt(b.second);
+});
+}
+
 int llvm::omp::getBestVariantMatchForContext(
 const SmallVectorImpl &VMIs, const OMPContext &Ctx) {
 
Index: llvm/include/llvm/Frontend/OpenMP/OMPContext.h
===
--- llvm/include/llvm/Frontend/OpenMP/OMPContext.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPContext.h
@@ -189,6 +189,15 @@
 int getBestVariantMatchForContext(const SmallVectorImpl &VMIs,
   const OMPContext &Ctx);
 
+/// Sort array \p A of clause index  with score
+/// This will be used to produce AST clauses
+/// in a sorted order with the clause with the highiest order
+/// on the top and default clause at the bottom
+void getArrayVariantMatchForContext(
+const SmallVectorImpl &VMIs, const OMPContext &Ctx,
+SmallVector> &A);
+
+// new--
 } // namespace omp
 
 template <> struct DenseMapInfo {
Index: clang/test/OpenMP/metadirective_ast_print_new_3.cpp
===
--- /dev/null
+++ clang/test/OpenMP/metadirective_ast_print_new_3.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -verify  -fopenmp  -ast-print %s -o - | FileCheck %s
+// expected-no-diagnostics
+
+int main() {
+  int N = 15;
+#pragma omp metadirective when(user = {condition(N > 10)} : parallel for)\
+ default(target teams) 
+  for (int i = 0; i < N; i++)
+;
+
+
+#pragma omp metadirective when(device = {arch("nvptx64")}, user = {condition(N >= 100)} : parallel for)\
+  default(target parallel for)
+  for (int i = 0; i < N; i++)
+;
+  return 0;
+}
+
+
+
+// CHECK: #pragma omp metadirective when(user={condition(N > 10)}: parallel for) default(target teams)
+// CHECK: #pragma omp metadirective when(device={arch(nvptx64)}, user={condition(N >= 100)}: parallel for) default(target parallel for)
Index: clang/test/OpenMP/metadirective_ast_print_new_2.cpp
===
--- /dev/null
+++ clang/test/OpenMP/metadirective_ast_print_new_2.cpp
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -verify  -fopenmp  -ast-print %s -o - | FileCheck %s
+// expected-no-diagnostics
+
+void bar(){
+	int i=0;	
+}
+
+void myfoo(void){
+
+	int N = 13;
+	int b,n;
+	int a[100];
+
+	
+	#pragma omp  me

[PATCH] D143446: [clang][deps] Ensure module invocation can be serialized

2023-02-08 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir updated this revision to Diff 495935.
benlangmuir added a comment.

- Improved doc comment for RoundTrip (mostly followed the suggested text; also 
converted from // to ///).
- Renamed variables
- Moved default value for RoundTripArgs


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

https://reviews.llvm.org/D143446

Files:
  clang/include/clang/Frontend/CompilerInvocation.h
  clang/lib/Basic/LangOptions.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/ClangScanDeps/modules-implied-args.c
  clang/tools/clang-scan-deps/ClangScanDeps.cpp

Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp
===
--- clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -8,6 +8,7 @@
 
 #include "clang/Driver/Driver.h"
 #include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/TextDiagnosticPrinter.h"
 #include "clang/Tooling/CommonOptionsParser.h"
 #include "clang/Tooling/DependencyScanning/DependencyScanningService.h"
 #include "clang/Tooling/DependencyScanning/DependencyScanningTool.h"
@@ -197,6 +198,19 @@
 llvm::cl::init(RDRK_ModifyCompilerPath),
 llvm::cl::cat(DependencyScannerCategory));
 
+#ifndef NDEBUG
+static constexpr bool DoRoundTripDefault = true;
+#else
+static constexpr bool DoRoundTripDefault = false;
+#endif
+
+llvm::cl::opt
+RoundTripArgs("round-trip-args", llvm::cl::Optional,
+  llvm::cl::desc("verify that command-line arguments are "
+ "canonical by parsing and re-serializing"),
+  llvm::cl::init(DoRoundTripDefault),
+  llvm::cl::cat(DependencyScannerCategory));
+
 llvm::cl::opt Verbose("v", llvm::cl::Optional,
 llvm::cl::desc("Use verbose output."),
 llvm::cl::init(false),
@@ -278,6 +292,37 @@
 }
   }
 
+  bool roundTripCommand(ArrayRef ArgStrs,
+DiagnosticsEngine &Diags) {
+if (ArgStrs.empty() || ArgStrs[0] != "-cc1")
+  return false;
+SmallVector Args;
+for (const std::string &Arg : ArgStrs)
+  Args.push_back(Arg.c_str());
+return !CompilerInvocation::checkCC1RoundTrip(Args, Diags);
+  }
+
+  // Returns \c true if any command lines fail to round-trip. We expect
+  // commands already be canonical when output by the scanner.
+  bool roundTripCommands(raw_ostream &ErrOS) {
+IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions{};
+TextDiagnosticPrinter DiagConsumer(ErrOS, &*DiagOpts);
+IntrusiveRefCntPtr Diags =
+CompilerInstance::createDiagnostics(&*DiagOpts, &DiagConsumer,
+/*ShouldOwnClient=*/false);
+
+for (auto &&M : Modules)
+  if (roundTripCommand(M.second.BuildArguments, *Diags))
+return true;
+
+for (auto &&I : Inputs)
+  for (const auto &Cmd : I.Commands)
+if (roundTripCommand(Cmd.Arguments, *Diags))
+  return true;
+
+return false;
+  }
+
   void printFullOutput(raw_ostream &OS) {
 // Sort the modules by name to get a deterministic order.
 std::vector ModuleIDs;
@@ -615,6 +660,10 @@
   }
   Pool.wait();
 
+  if (RoundTripArgs)
+if (FD.roundTripCommands(llvm::errs()))
+  HadErrors = true;
+
   if (Format == ScanningOutputFormat::Full)
 FD.printFullOutput(llvm::outs());
 
Index: clang/test/ClangScanDeps/modules-implied-args.c
===
--- /dev/null
+++ clang/test/ClangScanDeps/modules-implied-args.c
@@ -0,0 +1,46 @@
+// Check that we get canonical round-trippable command-lines, in particular
+// for the options modified for modules.
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+
+// RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full -round-trip-args > %t/result.json
+// RUN: cat %t/result.json  | sed 's:\?:/:g' | FileCheck %s -DPREFIX=%/t --check-prefixes=CHECK,NEGATIVE
+
+// -ffast-math implies -menable-no-infs, -menable-no-nans, and -mreassociate;
+// those options are modified by resetNonModularOptions.
+
+// NEGATIVE-NOT: "-menable-no-infs"
+// NEGATIVE-NOT: "-menable-no-nans"
+// NEGATIVE-NOT: "-mreassociate"
+
+// CHECK:  "modules": [
+// CHECK-NEXT:   {
+// CHECK:  "clang-module-deps": []
+// CHECK:  "command-line": [
+// CHECK:"-ffast-math"
+// CHECK:  ]
+// CHECK:  "name": "Mod"
+// CHECK:}
+// CHECK-NEXT: ]
+// CHECK:  "translation-units": [
+// CHECK-NEXT:   {
+// CHECK-NEXT: "commands": [
+// CHECK:{
+// CHECK:  "command-line": [
+// CHECK:"-ffast-math"
+// CHECK:  ]
+
+//--- cdb.json.template
+[{
+  "file": "DIR/tu.c",
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/tu.c -fmodules -fmodules-cache-path=DIR/cache -ffast-m

[PATCH] D143446: [clang][deps] Ensure module invocation can be serialized

2023-02-08 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir marked 3 inline comments as done.
benlangmuir added inline comments.



Comment at: clang/tools/clang-scan-deps/ClangScanDeps.cpp:658
+#endif
+  if (RoundTripArgs.getNumOccurrences() ? RoundTripArgs : DoRoundTripDefault)
+if (FD.roundTripCommands(llvm::errs()))

jansvoboda11 wrote:
> The call to `getNumOccurrences()` is a bit odd. Can you drop that if you add 
> `llvm::cl::init(false)` to the option definition?
I did this so that you can do `-round-trip-args=false` even if the default is 
true.  But I simplified it by doing `lvm::cl::init(DoRoundTripDefault)` instead.


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

https://reviews.llvm.org/D143446

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


[PATCH] D143592: [flang][driver] Rename `flang-new -flang-experimental-exec` to `flang`

2023-02-08 Thread Brad Richardson via Phabricator via cfe-commits
everythingfunctional updated this revision to Diff 495940.
everythingfunctional added a comment.

Fix the flang program path


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

https://reviews.llvm.org/D143592

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/Flang.cpp
  clang/test/Driver/flang/flang.f90
  clang/test/Driver/flang/flang_ucase.F90
  clang/test/Driver/flang/multiple-inputs-mixed.f90
  clang/test/Driver/flang/multiple-inputs.f90
  flang/docs/FlangDriver.md
  flang/docs/ImplementingASemanticCheck.md
  flang/docs/Overview.md
  flang/examples/FlangOmpReport/FlangOmpReport.cpp
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  flang/test/CMakeLists.txt
  flang/test/Driver/color-diagnostics-forwarding.f90
  flang/test/Driver/convert.f90
  flang/test/Driver/disable-ext-name-interop.f90
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-version.f90
  flang/test/Driver/escaped-backslash.f90
  flang/test/Driver/fdefault.f90
  flang/test/Driver/flarge-sizes.f90
  flang/test/Driver/frontend-forwarding.f90
  flang/test/Driver/intrinsic-module-path.f90
  flang/test/Driver/linker-flags.f90
  flang/test/Driver/macro-def-undef.F90
  flang/test/Driver/missing-input.f90
  flang/test/Driver/multiple-input-files.f90
  flang/test/Driver/predefined-macros-compiler-version.F90
  flang/test/Driver/std2018-wrong.f90
  flang/test/Driver/std2018.f90
  flang/test/Driver/use-module-error.f90
  flang/test/Driver/use-module.f90
  flang/test/Lower/Intrinsics/command_argument_count.f90
  flang/test/Lower/Intrinsics/exit.f90
  flang/test/Lower/Intrinsics/get_command_argument.f90
  flang/test/Lower/Intrinsics/get_environment_variable.f90
  flang/test/Lower/Intrinsics/move_alloc.f90
  flang/test/Lower/OpenACC/Todo/acc-declare.f90
  flang/test/Lower/OpenACC/Todo/acc-routine.f90
  flang/test/Lower/OpenMP/Todo/omp-declarative-allocate.f90
  flang/test/Lower/OpenMP/Todo/omp-declare-reduction.f90
  flang/test/Lower/OpenMP/Todo/omp-declare-simd.f90
  flang/test/Lower/OpenMP/Todo/omp-declare-target.f90
  flang/test/Lower/OpenMP/omp-parallel-lastprivate-clause-scalar.f90
  flang/test/lit.cfg.py
  flang/tools/f18/CMakeLists.txt
  flang/tools/f18/flang-to-external-fc.in
  flang/tools/flang-driver/CMakeLists.txt
  flang/tools/flang-driver/driver.cpp

Index: flang/tools/flang-driver/driver.cpp
===
--- flang/tools/flang-driver/driver.cpp
+++ flang/tools/flang-driver/driver.cpp
@@ -88,14 +88,15 @@
   llvm::InitLLVM x(argc, argv);
   llvm::SmallVector args(argv, argv + argc);
 
-  clang::driver::ParsedClangName targetandMode("flang", "--driver-mode=flang");
+  clang::driver::ParsedClangName targetandMode =
+  clang::driver::ToolChain::getTargetAndModeFromProgramName(argv[0]);
   std::string driverPath = getExecutablePath(args[0]);
 
   llvm::BumpPtrAllocator a;
   llvm::StringSaver saver(a);
   ExpandResponseFiles(saver, args);
 
-  // Check if flang-new is in the frontend mode
+  // Check if flang is in the frontend mode
   auto firstArg = std::find_if(args.begin() + 1, args.end(),
[](const char *a) { return a != nullptr; });
   if (firstArg != args.end()) {
@@ -104,7 +105,7 @@
<< "Valid tools include '-fc1'.\n";
   return 1;
 }
-// Call flang-new frontend
+// Call flang frontend
 if (llvm::StringRef(args[1]).startswith("-fc1")) {
   return executeFC1Tool(args);
 }
Index: flang/tools/flang-driver/CMakeLists.txt
===
--- flang/tools/flang-driver/CMakeLists.txt
+++ flang/tools/flang-driver/CMakeLists.txt
@@ -11,7 +11,7 @@
   TargetParser
 )
 
-add_flang_tool(flang-new
+add_flang_tool(flang
   driver.cpp
   fc1_main.cpp
 
@@ -24,13 +24,13 @@
   Fortran_main
 )
 
-target_link_libraries(flang-new
+target_link_libraries(flang
   PRIVATE
   flangFrontend
   flangFrontendTool
 )
 
-clang_target_link_libraries(flang-new
+clang_target_link_libraries(flang
   PRIVATE
   clangDriver
   clangBasic
@@ -38,9 +38,9 @@
 
 option(FLANG_PLUGIN_SUPPORT "Build Flang with plugin support." ON)
 
-# Enable support for plugins, which need access to symbols from flang-new
+# Enable support for plugins, which need access to symbols from flang
 if(FLANG_PLUGIN_SUPPORT)
-  export_executable_symbols_for_plugins(flang-new)
+  export_executable_symbols_for_plugins(flang)
 endif()
 
-install(TARGETS flang-new DESTINATION "${CMAKE_INSTALL_BINDIR}")
+install(TARGETS flang DESTINATION "${CMAKE_INSTALL_BINDIR}")
Index: flang/tools/f18/flang-to-external-fc.in
===
--- flang/tools/f18/flang-to-external-fc.in
+++ flang/tools/f18/flang-to-external-fc.in
@@ -205,7 +205,7 @@
 
 if
 

[PATCH] D143553: [Clang][CMake] Add BOLT perf-training

2023-02-08 Thread Amir Ayupov via Phabricator via cfe-commits
Amir updated this revision to Diff 495941.
Amir added a comment.

Fixed BOLT-PGO build


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143553

Files:
  clang/CMakeLists.txt
  clang/cmake/caches/BOLT.cmake
  clang/utils/perf-training/CMakeLists.txt
  clang/utils/perf-training/bolt.lit.cfg
  clang/utils/perf-training/bolt.lit.site.cfg.in

Index: clang/utils/perf-training/bolt.lit.site.cfg.in
===
--- /dev/null
+++ clang/utils/perf-training/bolt.lit.site.cfg.in
@@ -0,0 +1,14 @@
+@LIT_SITE_CFG_IN_HEADER@
+
+import sys
+
+config.clang_tools_dir = lit_config.substitute("@CURRENT_TOOLS_DIR@")
+config.perf_helper_dir = "@CMAKE_CURRENT_SOURCE_DIR@"
+config.test_exec_root = "@CMAKE_CURRENT_BINARY_DIR@"
+config.test_source_root = "@CLANG_PGO_TRAINING_DATA@"
+config.target_triple = "@LLVM_TARGET_TRIPLE@"
+config.python_exe = "@Python3_EXECUTABLE@"
+config.clang_obj_root = path(r"@CLANG_BINARY_DIR@")
+
+# Let the main config do the real work.
+lit_config.load_config(config, "@CLANG_SOURCE_DIR@/utils/perf-training/bolt.lit.cfg")
Index: clang/utils/perf-training/bolt.lit.cfg
===
--- /dev/null
+++ clang/utils/perf-training/bolt.lit.cfg
@@ -0,0 +1,21 @@
+# -*- Python -*-
+
+from lit import Test
+import lit.formats
+import lit.util
+import os
+import subprocess
+
+config.clang = os.path.realpath(lit.util.which('clang-bolt.inst', config.clang_tools_dir)).replace('\\', '/')
+sysroot_flags = ''
+
+config.name = 'Clang Perf Training'
+config.suffixes = ['.c', '.cc', '.cpp', '.m', '.mm', '.cu', '.ll', '.cl', '.s', '.S', '.modulemap', '.test']
+
+use_lit_shell = os.environ.get("LIT_USE_INTERNAL_SHELL")
+config.test_format = lit.formats.ShTest(use_lit_shell == "0")
+config.substitutions.append( ('%clang_cpp_skip_driver', ' %s --driver-mode=g++ %s ' % (config.clang, sysroot_flags)))
+config.substitutions.append( ('%clang_cpp', ' %s --driver-mode=g++ %s ' % (config.clang, sysroot_flags)))
+config.substitutions.append( ('%clang_skip_driver', ' %s %s ' % (config.clang, sysroot_flags)))
+config.substitutions.append( ('%clang', ' %s %s ' % (config.clang, sysroot_flags) ) )
+config.substitutions.append( ('%test_root', config.test_exec_root ) )
Index: clang/utils/perf-training/CMakeLists.txt
===
--- clang/utils/perf-training/CMakeLists.txt
+++ clang/utils/perf-training/CMakeLists.txt
@@ -59,3 +59,26 @@
 COMMENT "Generating order file"
 DEPENDS generate-dtrace-logs)
 endif()
+
+if(CLANG_BOLT_INSTRUMENT AND NOT LLVM_BUILD_INSTRUMENTED)
+  configure_lit_site_cfg(
+${CMAKE_CURRENT_SOURCE_DIR}/bolt.lit.site.cfg.in
+${CMAKE_CURRENT_BINARY_DIR}/bolt-fdata/lit.site.cfg
+)
+
+  add_lit_testsuite(generate-bolt-fdata "Generating BOLT profile for Clang"
+${CMAKE_CURRENT_BINARY_DIR}/bolt-fdata/
+EXCLUDE_FROM_CHECK_ALL
+DEPENDS clang-instrumented clear-bolt-fdata
+)
+
+  add_custom_target(clear-bolt-fdata
+COMMAND "${Python3_EXECUTABLE}" ${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py clean ${CMAKE_CURRENT_BINARY_DIR} fdata
+COMMENT "Clearing old BOLT fdata")
+
+  # Merge profiles into one using merge-fdata
+  add_custom_target(merge-bolt-fdata
+COMMAND "${Python3_EXECUTABLE}" ${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py merge-fdata $ ${CMAKE_CURRENT_BINARY_DIR}/prof.fdata ${CMAKE_CURRENT_BINARY_DIR}
+COMMENT "Merging BOLT fdata"
+DEPENDS merge-fdata generate-bolt-fdata)
+endif()
Index: clang/cmake/caches/BOLT.cmake
===
--- clang/cmake/caches/BOLT.cmake
+++ clang/cmake/caches/BOLT.cmake
@@ -1,9 +1,6 @@
 set(CMAKE_BUILD_TYPE Release CACHE STRING "")
 set(CLANG_BOLT_INSTRUMENT ON CACHE BOOL "")
-set(CLANG_BOLT_INSTRUMENT_PROJECTS "llvm" CACHE STRING "")
-set(CLANG_BOLT_INSTRUMENT_TARGETS "count" CACHE STRING "")
 set(CMAKE_EXE_LINKER_FLAGS "-Wl,--emit-relocs,-znow" CACHE STRING "")
-set(CLANG_BOLT_INSTRUMENT_EXTRA_CMAKE_FLAGS "" CACHE STRING "")
 
 set(LLVM_ENABLE_PROJECTS "bolt;clang" CACHE STRING "")
 set(LLVM_TARGETS_TO_BUILD Native CACHE STRING "")
Index: clang/CMakeLists.txt
===
--- clang/CMakeLists.txt
+++ clang/CMakeLists.txt
@@ -853,95 +853,29 @@
 
 if (CLANG_BOLT_INSTRUMENT AND NOT LLVM_BUILD_INSTRUMENTED)
   set(CLANG_PATH ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang)
-  set(CLANGXX_PATH ${CLANG_PATH}++)
   set(CLANG_INSTRUMENTED ${CLANG_PATH}-bolt.inst)
-  set(CLANGXX_INSTRUMENTED ${CLANGXX_PATH}-bolt.inst)
 
   # Instrument clang with BOLT
   add_custom_target(clang-instrumented
 DEPENDS ${CLANG_INSTRUMENTED}
   )
+  set(BOLT_FDATA ${CMAKE_CURRENT_BINARY_DIR}/utils/perf-training/prof.fdata)
   add_custom_command(OUTPUT ${CLANG_INSTRUMENTED}
 DEPENDS clang llvm-bolt
 COMMAND llvm-bolt ${CLANG_PA

[PATCH] D143446: [clang][deps] Ensure module invocation can be serialized

2023-02-08 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 accepted this revision.
jansvoboda11 added a comment.
This revision is now accepted and ready to land.

LGTM, thanks!


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

https://reviews.llvm.org/D143446

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


[clang] 829bcb0 - [-Wunsafe-buffer-usage] Add unsafe buffer checking opt-out pragmas

2023-02-08 Thread Ziqing Luo via cfe-commits

Author: Ziqing Luo
Date: 2023-02-08T14:12:03-08:00
New Revision: 829bcb06ec43ab4b56b95ff040ec9d36feeaf06a

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

LOG: [-Wunsafe-buffer-usage] Add unsafe buffer checking opt-out pragmas

Add a pair of clang pragmas:
- `#pragma clang unsafe_buffer_usage begin` and
- `#pragma clang unsafe_buffer_usage end`,
which specify the start and end of an (unsafe buffer checking) opt-out
region, respectively.

Behaviors of opt-out regions conform to the following rules:

- No nested nor overlapped opt-out regions are allowed. One cannot
  start an opt-out region with `... unsafe_buffer_usage begin` but never
  close it with `... unsafe_buffer_usage end`. Mis-use of the pragmas
  will be warned.
- Warnings raised from unsafe buffer operations inside such an opt-out
  region will always be suppressed. This behavior CANNOT be changed by
  `clang diagnostic` pragmas or command-line flags.
- Warnings raised from unsafe operations outside of such opt-out
  regions may be reported on declarations inside opt-out
  regions. These warnings are NOT suppressed.
- An un-suppressed unsafe operation warning may be attached with
  notes. These notes are NOT suppressed as well regardless of whether
  they are in opt-out regions.

The implementation maintains a separate sequence of location pairs
representing opt-out regions in `Preprocessor`.  The `UnsafeBufferUsage`
analyzer reads the region sequence to check if an unsafe operation is
in an opt-out region. If it is, discard the warning raised from the
operation immediately.

This is a re-land after I reverting it at 
9aa00c8a306561c4e3ddb09058e66bae322a0769.
The compilation error should be resolved.

Reviewed by: NoQ

Differential revision: https://reviews.llvm.org/D140179

Added: 
clang/test/SemaCXX/warn-unsafe-buffer-usage-pragma-fixit.cpp
clang/test/SemaCXX/warn-unsafe-buffer-usage-pragma-misuse.cpp
clang/test/SemaCXX/warn-unsafe-buffer-usage-pragma.cpp
clang/test/SemaCXX/warn-unsafe-buffer-usage-pragma.h

Modified: 
clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
clang/include/clang/Basic/DiagnosticLexKinds.td
clang/include/clang/Lex/Preprocessor.h
clang/lib/Analysis/UnsafeBufferUsage.cpp
clang/lib/Lex/PPLexerChange.cpp
clang/lib/Lex/Pragma.cpp
clang/lib/Lex/Preprocessor.cpp
clang/lib/Sema/AnalysisBasedWarnings.cpp

Removed: 




diff  --git a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h 
b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
index 3ac4def0429bf..926a4fce3ae74 100644
--- a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
+++ b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
@@ -38,6 +38,9 @@ class UnsafeBufferUsageHandler {
   virtual void handleFixableVariable(const VarDecl *Variable,
  FixItList &&List) = 0;
 
+  /// Returns a reference to the `Preprocessor`:
+  virtual bool isSafeBufferOptOut(const SourceLocation &Loc) const = 0;
+
   /// Returns the text indicating that the user needs to provide input there:
   virtual std::string
   getUserFillPlaceHolder(StringRef HintTextToUser = "placeholder") {

diff  --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index 0fb8d196dd6a5..fbb08a6f761be 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -945,4 +945,15 @@ def err_dep_source_scanner_unexpected_tokens_at_import : 
Error<
 
 }
 
+def err_pp_double_begin_pragma_unsafe_buffer_usage :
+Error<"already inside '#pragma unsafe_buffer_usage'">;
+
+def err_pp_unmatched_end_begin_pragma_unsafe_buffer_usage :
+Error<"not currently inside '#pragma unsafe_buffer_usage'">;
+
+def err_pp_unclosed_pragma_unsafe_buffer_usage :
+Error<"'#pragma unsafe_buffer_usage' was not ended">;
+
+def err_pp_pragma_unsafe_buffer_usage_syntax :
+Error<"Expected 'begin' or 'end'">;
 }

diff  --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index f383a2e5b5301..81deef21ca684 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -2688,6 +2688,51 @@ class Preprocessor {
   void emitMacroDeprecationWarning(const Token &Identifier) const;
   void emitRestrictExpansionWarning(const Token &Identifier) const;
   void emitFinalMacroWarning(const Token &Identifier, bool IsUndef) const;
+
+  /// This boolean state keeps track if the current scanned token (by this PP)
+  /// is in an "-Wunsafe-buffer-usage" opt-out region. Assuming PP scans a
+  /// translation unit in a linear order.
+  bool InSafeBufferOptOutRegion = 0;
+
+  /// Hold the start location of the current "-Wunsafe-buffer-usage" opt-out
+  /// r

[PATCH] D131939: [clang-tidy] Add performance-expensive-flat-container-operation check

2023-02-08 Thread Nicolas van Kempen via Phabricator via cfe-commits
nicovank added a comment.

Ping :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131939

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


[PATCH] D139395: Add CFI integer types normalization

2023-02-08 Thread Sami Tolvanen via Phabricator via cfe-commits
samitolvanen accepted this revision.
samitolvanen added a comment.

Thanks for fixing the MSan issue, Ramon. There's still a clang-format error 
that trips the Debian build above, but it's trivial so I can fix it when 
relanding the patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139395

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


[clang] cf73d3f - [clang][deps] Ensure module invocation can be serialized

2023-02-08 Thread Ben Langmuir via cfe-commits

Author: Ben Langmuir
Date: 2023-02-08T14:23:39-08:00
New Revision: cf73d3f07b5b0ff83a852dfdf8857500e86f9952

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

LOG: [clang][deps] Ensure module invocation can be serialized

When reseting modular options, propagate the values from certain options
that have ImpliedBy relations instead of setting to the default. Also,
verify in clang-scan-deps that the command line produced round trips
exactly.

Ideally we would automatically derive the set of options that need this
kind of propagation, but for now there aren't very many impacted.

rdar://105148590

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

Added: 
clang/test/ClangScanDeps/modules-implied-args.c

Modified: 
clang/include/clang/Frontend/CompilerInvocation.h
clang/lib/Basic/LangOptions.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/tools/clang-scan-deps/ClangScanDeps.cpp

Removed: 




diff  --git a/clang/include/clang/Frontend/CompilerInvocation.h 
b/clang/include/clang/Frontend/CompilerInvocation.h
index 254f048ed3c7e..1dbd1eda62b3f 100644
--- a/clang/include/clang/Frontend/CompilerInvocation.h
+++ b/clang/include/clang/Frontend/CompilerInvocation.h
@@ -241,6 +241,17 @@ class CompilerInvocation : public 
CompilerInvocationRefBase,
   /// This is a (less-efficient) wrapper over generateCC1CommandLine().
   std::vector getCC1CommandLine() const;
 
+  /// Check that \p Args can be parsed and re-serialized without change,
+  /// emiting diagnostics for any 
diff erences.
+  ///
+  /// This check is only suitable for command-lines that are expected to 
already
+  /// be canonical.
+  ///
+  /// \return false if there are any errors.
+  static bool checkCC1RoundTrip(ArrayRef Args,
+DiagnosticsEngine &Diags,
+const char *Argv0 = nullptr);
+
   /// Reset all of the options that are not considered when building a
   /// module.
   void resetNonModularOptions();

diff  --git a/clang/lib/Basic/LangOptions.cpp b/clang/lib/Basic/LangOptions.cpp
index 753b6bfe18a37..f22fe9a82bda4 100644
--- a/clang/lib/Basic/LangOptions.cpp
+++ b/clang/lib/Basic/LangOptions.cpp
@@ -29,6 +29,14 @@ void LangOptions::resetNonModularOptions() {
   Name = static_cast(Default);
 #include "clang/Basic/LangOptions.def"
 
+  // Reset "benign" options with implied values (Options.td ImpliedBy 
relations)
+  // rather than their defaults. This avoids unexpected combinations and
+  // invocations that cannot be round-tripped to arguments.
+  // FIXME: we should derive this automatically from ImpliedBy in tablegen.
+  AllowFPReassoc = UnsafeFPMath;
+  NoHonorNaNs = FiniteMathOnly;
+  NoHonorInfs = FiniteMathOnly;
+
   // These options do not affect AST generation.
   NoSanitizeFiles.clear();
   XRayAlwaysInstrumentFiles.clear();

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index f456d47ed1009..4bf77ec4d0782 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -641,18 +641,31 @@ using GenerateFn = llvm::function_ref &,
 CompilerInvocation::StringAllocator)>;
 
-// May perform round-trip of command line arguments. By default, the round-trip
-// is enabled in assert builds. This can be overwritten at run-time via the
-// "-round-trip-args" and "-no-round-trip-args" command line flags.
-// During round-trip, the command line arguments are parsed into a dummy
-// instance of CompilerInvocation which is used to generate the command line
-// arguments again. The real CompilerInvocation instance is then created by
-// parsing the generated arguments, not the original ones.
+/// May perform round-trip of command line arguments. By default, the 
round-trip
+/// is enabled in assert builds. This can be overwritten at run-time via the
+/// "-round-trip-args" and "-no-round-trip-args" command line flags, or via the
+/// ForceRoundTrip parameter.
+///
+/// During round-trip, the command line arguments are parsed into a dummy
+/// CompilerInvocation, which is used to generate the command line arguments
+/// again. The real CompilerInvocation is then created by parsing the generated
+/// arguments, not the original ones. This (in combination with tests covering
+/// argument behavior) ensures the generated command line is complete (doesn't
+/// drop/mangle any arguments).
+///
+/// Finally, we check the command line that was used to create the real
+/// CompilerInvocation instance. By default, we compare it to the command line
+/// the real CompilerInvocation generates. This checks whether the generator is
+/// deterministic. If \p CheckAgainstOriginalInvocation is enabled, we instead
+/// compare it to the original command line to veri

[PATCH] D143446: [clang][deps] Ensure module invocation can be serialized

2023-02-08 Thread Ben Langmuir via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
benlangmuir marked an inline comment as done.
Closed by commit rGcf73d3f07b5b: [clang][deps] Ensure module invocation can be 
serialized (authored by benlangmuir).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143446

Files:
  clang/include/clang/Frontend/CompilerInvocation.h
  clang/lib/Basic/LangOptions.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/ClangScanDeps/modules-implied-args.c
  clang/tools/clang-scan-deps/ClangScanDeps.cpp

Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp
===
--- clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -8,6 +8,7 @@
 
 #include "clang/Driver/Driver.h"
 #include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/TextDiagnosticPrinter.h"
 #include "clang/Tooling/CommonOptionsParser.h"
 #include "clang/Tooling/DependencyScanning/DependencyScanningService.h"
 #include "clang/Tooling/DependencyScanning/DependencyScanningTool.h"
@@ -197,6 +198,19 @@
 llvm::cl::init(RDRK_ModifyCompilerPath),
 llvm::cl::cat(DependencyScannerCategory));
 
+#ifndef NDEBUG
+static constexpr bool DoRoundTripDefault = true;
+#else
+static constexpr bool DoRoundTripDefault = false;
+#endif
+
+llvm::cl::opt
+RoundTripArgs("round-trip-args", llvm::cl::Optional,
+  llvm::cl::desc("verify that command-line arguments are "
+ "canonical by parsing and re-serializing"),
+  llvm::cl::init(DoRoundTripDefault),
+  llvm::cl::cat(DependencyScannerCategory));
+
 llvm::cl::opt Verbose("v", llvm::cl::Optional,
 llvm::cl::desc("Use verbose output."),
 llvm::cl::init(false),
@@ -278,6 +292,37 @@
 }
   }
 
+  bool roundTripCommand(ArrayRef ArgStrs,
+DiagnosticsEngine &Diags) {
+if (ArgStrs.empty() || ArgStrs[0] != "-cc1")
+  return false;
+SmallVector Args;
+for (const std::string &Arg : ArgStrs)
+  Args.push_back(Arg.c_str());
+return !CompilerInvocation::checkCC1RoundTrip(Args, Diags);
+  }
+
+  // Returns \c true if any command lines fail to round-trip. We expect
+  // commands already be canonical when output by the scanner.
+  bool roundTripCommands(raw_ostream &ErrOS) {
+IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions{};
+TextDiagnosticPrinter DiagConsumer(ErrOS, &*DiagOpts);
+IntrusiveRefCntPtr Diags =
+CompilerInstance::createDiagnostics(&*DiagOpts, &DiagConsumer,
+/*ShouldOwnClient=*/false);
+
+for (auto &&M : Modules)
+  if (roundTripCommand(M.second.BuildArguments, *Diags))
+return true;
+
+for (auto &&I : Inputs)
+  for (const auto &Cmd : I.Commands)
+if (roundTripCommand(Cmd.Arguments, *Diags))
+  return true;
+
+return false;
+  }
+
   void printFullOutput(raw_ostream &OS) {
 // Sort the modules by name to get a deterministic order.
 std::vector ModuleIDs;
@@ -615,6 +660,10 @@
   }
   Pool.wait();
 
+  if (RoundTripArgs)
+if (FD.roundTripCommands(llvm::errs()))
+  HadErrors = true;
+
   if (Format == ScanningOutputFormat::Full)
 FD.printFullOutput(llvm::outs());
 
Index: clang/test/ClangScanDeps/modules-implied-args.c
===
--- /dev/null
+++ clang/test/ClangScanDeps/modules-implied-args.c
@@ -0,0 +1,46 @@
+// Check that we get canonical round-trippable command-lines, in particular
+// for the options modified for modules.
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+
+// RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full -round-trip-args > %t/result.json
+// RUN: cat %t/result.json  | sed 's:\?:/:g' | FileCheck %s -DPREFIX=%/t --check-prefixes=CHECK,NEGATIVE
+
+// -ffast-math implies -menable-no-infs, -menable-no-nans, and -mreassociate;
+// those options are modified by resetNonModularOptions.
+
+// NEGATIVE-NOT: "-menable-no-infs"
+// NEGATIVE-NOT: "-menable-no-nans"
+// NEGATIVE-NOT: "-mreassociate"
+
+// CHECK:  "modules": [
+// CHECK-NEXT:   {
+// CHECK:  "clang-module-deps": []
+// CHECK:  "command-line": [
+// CHECK:"-ffast-math"
+// CHECK:  ]
+// CHECK:  "name": "Mod"
+// CHECK:}
+// CHECK-NEXT: ]
+// CHECK:  "translation-units": [
+// CHECK-NEXT:   {
+// CHECK-NEXT: "commands": [
+// CHECK:{
+// CHECK:  "command-line": [
+// CHECK:"-ffast-math"
+// CHECK:  ]
+
+//--- cdb.json.template
+[{
+  "file": "DIR/tu.c",
+  "directory": "DIR",
+  "comm

[clang] 71c7313 - Add CFI integer types normalization

2023-02-08 Thread Sami Tolvanen via cfe-commits

Author: Ramon de C Valle
Date: 2023-02-08T22:24:19Z
New Revision: 71c7313f42d2b6063fea09854cf4fc46fd0627e1

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

LOG: Add CFI integer types normalization

This commit adds a new option (i.e.,
`-fsanitize-cfi-icall-normalize-integers`) for normalizing integer types
as vendor extended types for cross-language LLVM CFI/KCFI support with
other languages that can't represent and encode C/C++ integer types.

Specifically, integer types are encoded as their defined representations
(e.g., 8-bit signed integer, 16-bit signed integer, 32-bit signed
integer, ...) for compatibility with languages that define
explicitly-sized integer types (e.g., i8, i16, i32, ..., in Rust).

``-fsanitize-cfi-icall-normalize-integers`` is compatible with
``-fsanitize-cfi-icall-generalize-pointers``.

This helps with providing cross-language CFI support with the Rust
compiler and is an alternative solution for the issue described and
alternatives proposed in the RFC
https://github.com/rust-lang/rfcs/pull/3296.

For more information about LLVM CFI/KCFI and cross-language LLVM
CFI/KCFI support for the Rust compiler, see the design document in the
tracking issue https://github.com/rust-lang/rust/issues/89653.

Relands b1e9ab7438a098a18fecda88fc87ef4ccadfcf1e with fixes.

Reviewed By: pcc, samitolvanen

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

Added: 
clang/test/CodeGen/cfi-icall-normalize.c
clang/test/CodeGen/cfi-icall-normalize2.c
clang/test/CodeGen/kcfi-normalize.c

Modified: 
clang/docs/ControlFlowIntegrity.rst
clang/docs/UsersManual.rst
clang/include/clang/AST/Mangle.h
clang/include/clang/Basic/CodeGenOptions.def
clang/include/clang/Driver/Options.td
clang/include/clang/Driver/SanitizerArgs.h
clang/lib/AST/ItaniumMangle.cpp
clang/lib/AST/MicrosoftMangle.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/Driver/SanitizerArgs.cpp

Removed: 




diff  --git a/clang/docs/ControlFlowIntegrity.rst 
b/clang/docs/ControlFlowIntegrity.rst
index ef47b1c5b4b2b..f375199f40617 100644
--- a/clang/docs/ControlFlowIntegrity.rst
+++ b/clang/docs/ControlFlowIntegrity.rst
@@ -236,6 +236,25 @@ long as the qualifiers for the type they point to match. 
For example, ``char*``,
 ``-fsanitize-cfi-icall-generalize-pointers`` is not compatible with
 ``-fsanitize-cfi-cross-dso``.
 
+.. _cfi-icall-experimental-normalize-integers:
+
+``-fsanitize-cfi-icall-experimental-normalize-integers``
+
+
+This option enables normalizing integer types as vendor extended types for
+cross-language LLVM CFI/KCFI support with other languages that can't represent
+and encode C/C++ integer types.
+
+Specifically, integer types are encoded as their defined representations (e.g.,
+8-bit signed integer, 16-bit signed integer, 32-bit signed integer, ...) for
+compatibility with languages that define explicitly-sized integer types (e.g.,
+i8, i16, i32, ..., in Rust).
+
+``-fsanitize-cfi-icall-experimental-normalize-integers`` is compatible with
+``-fsanitize-cfi-icall-generalize-pointers``.
+
+This option is currently experimental.
+
 .. _cfi-canonical-jump-tables:
 
 ``-fsanitize-cfi-canonical-jump-tables``

diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 18e1e9aaca2c4..0d5e960050c25 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -1992,6 +1992,14 @@ are listed below.
checked by Control Flow Integrity indirect call checking. See
:doc:`ControlFlowIntegrity` for more details.
 
+.. option:: -fsanitize-cfi-icall-experimental-normalize-integers
+
+   Normalize integers in return and argument types in function type signatures
+   checked by Control Flow Integrity indirect call checking. See
+   :doc:`ControlFlowIntegrity` for more details.
+
+   This option is currently experimental.
+
 .. option:: -fstrict-vtable-pointers
 
Enable optimizations based on the strict rules for overwriting polymorphic

diff  --git a/clang/include/clang/AST/Mangle.h 
b/clang/include/clang/AST/Mangle.h
index 9662a33c61cb7..c04bcc7f01cb4 100644
--- a/clang/include/clang/AST/Mangle.h
+++ b/clang/include/clang/AST/Mangle.h
@@ -140,7 +140,8 @@ class MangleContext {
 unsigned ManglingNumber,
 raw_ostream &) = 0;
   virtual void mangleCXXRTTI(QualType T, raw_ostream &) = 0;
-  virtual void mangleCXXRTTIName(QualType T, raw_ostream &) = 0;
+  virtual void mangleCXXRTTIName(QualType T, raw_ostream &,
+ bool NormalizeIntegers = false) = 0;
   virtual void mangleStringLiteral(const StringLiteral *SL, raw_ostream &) = 0;
   virtual void mangleMSGuidDecl(const MSG

[PATCH] D139395: Add CFI integer types normalization

2023-02-08 Thread Sami Tolvanen 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 rG71c7313f42d2: Add CFI integer types normalization (authored 
by rcvalle, committed by samitolvanen).

Changed prior to commit:
  https://reviews.llvm.org/D139395?vs=495860&id=495951#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139395

Files:
  clang/docs/ControlFlowIntegrity.rst
  clang/docs/UsersManual.rst
  clang/include/clang/AST/Mangle.h
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/SanitizerArgs.h
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/MicrosoftMangle.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Driver/SanitizerArgs.cpp
  clang/test/CodeGen/cfi-icall-normalize.c
  clang/test/CodeGen/cfi-icall-normalize2.c
  clang/test/CodeGen/kcfi-normalize.c

Index: clang/test/CodeGen/kcfi-normalize.c
===
--- /dev/null
+++ clang/test/CodeGen/kcfi-normalize.c
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -fsanitize=kcfi -fsanitize-cfi-icall-experimental-normalize-integers -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -fsanitize=kcfi -fsanitize-cfi-icall-experimental-normalize-integers -x c++ -o - %s | FileCheck %s
+#if !__has_feature(kcfi)
+#error Missing kcfi?
+#endif
+
+// Test that normalized type metadata for functions are emitted for cross-language KCFI support with
+// other languages that can't represent and encode C/C++ integer types.
+
+void foo(void (*fn)(int), int arg) {
+// CHECK-LABEL: define{{.*}}foo
+// CHECK-SAME: {{.*}}!kcfi_type ![[TYPE1:[0-9]+]]
+// CHECK: call void %0(i32 noundef %1){{.*}}[ "kcfi"(i32 1162514891) ]
+fn(arg);
+}
+
+void bar(void (*fn)(int, int), int arg1, int arg2) {
+// CHECK-LABEL: define{{.*}}bar
+// CHECK-SAME: {{.*}}!kcfi_type ![[TYPE2:[0-9]+]]
+// CHECK: call void %0(i32 noundef %1, i32 noundef %2){{.*}}[ "kcfi"(i32 448046469) ]
+fn(arg1, arg2);
+}
+
+void baz(void (*fn)(int, int, int), int arg1, int arg2, int arg3) {
+// CHECK-LABEL: define{{.*}}baz
+// CHECK-SAME: {{.*}}!kcfi_type ![[TYPE3:[0-9]+]]
+// CHECK: call void %0(i32 noundef %1, i32 noundef %2, i32 noundef %3){{.*}}[ "kcfi"(i32 -2049681433) ]
+fn(arg1, arg2, arg3);
+}
+
+// CHECK: ![[TYPE1]] = !{i32 -1143117868}
+// CHECK: ![[TYPE2]] = !{i32 -460921415}
+// CHECK: ![[TYPE3]] = !{i32 -333839615}
Index: clang/test/CodeGen/cfi-icall-normalize2.c
===
--- /dev/null
+++ clang/test/CodeGen/cfi-icall-normalize2.c
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -fsanitize=cfi-icall -fsanitize-trap=cfi-icall -fsanitize-cfi-icall-experimental-normalize-integers -emit-llvm -o - %s | FileCheck %s
+
+// Test that normalized type metadata for functions are emitted for cross-language CFI support with
+// other languages that can't represent and encode C/C++ integer types.
+
+void foo(void (*fn)(int), int arg) {
+// CHECK-LABEL: define{{.*}}foo
+// CHECK-SAME: {{.*}}!type ![[TYPE1:[0-9]+]] !type !{{[0-9]+}}
+// CHECK: call i1 @llvm.type.test({{i8\*|ptr}} {{%f|%0}}, metadata !"_ZTSFvu3i32E.normalized")
+fn(arg);
+}
+
+void bar(void (*fn)(int, int), int arg1, int arg2) {
+// CHECK-LABEL: define{{.*}}bar
+// CHECK-SAME: {{.*}}!type ![[TYPE2:[0-9]+]] !type !{{[0-9]+}}
+// CHECK: call i1 @llvm.type.test({{i8\*|ptr}} {{%f|%0}}, metadata !"_ZTSFvu3i32S_E.normalized")
+fn(arg1, arg2);
+}
+
+void baz(void (*fn)(int, int, int), int arg1, int arg2, int arg3) {
+// CHECK-LABEL: define{{.*}}baz
+// CHECK-SAME: {{.*}}!type ![[TYPE3:[0-9]+]] !type !{{[0-9]+}}
+// CHECK: call i1 @llvm.type.test({{i8\*|ptr}} {{%f|%0}}, metadata !"_ZTSFvu3i32S_S_E.normalized")
+fn(arg1, arg2, arg3);
+}
+
+// CHECK: ![[TYPE1]] = !{i64 0, !"_ZTSFvPFvu3i32ES_E.normalized"}
+// CHECK: ![[TYPE2]] = !{i64 0, !"_ZTSFvPFvu3i32S_ES_S_E.normalized"}
+// CHECK: ![[TYPE3]] = !{i64 0, !"_ZTSFvPFvu3i32S_S_ES_S_S_E.normalized"}
Index: clang/test/CodeGen/cfi-icall-normalize.c
===
--- /dev/null
+++ clang/test/CodeGen/cfi-icall-normalize.c
@@ -0,0 +1,78 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -fsanitize=cfi-icall -fsanitize-trap=cfi-icall -fsanitize-cfi-icall-experimental-normalize-integers -emit-llvm -o - %s | FileCheck %s
+
+// Test that integer types are normalized for cross-language CFI support with
+// other languages that can't represent and encode C/C++ integer types.
+
+void foo0(char arg) { }
+// CHECK: define{{.*}}foo0{{.*}}!type ![[TYPE0:[0-9]+]] !type !{{[0-9]+}}
+void foo1(char arg1, signed char arg2) { }
+// CHECK: define{{.*}}foo1{{.*}}!type ![[TYPE1:[0-9]+]]

  1   2   >