[PATCH] D117087: [C++20] [Coroutines] Implement return value optimization for get_return_object

2022-02-15 Thread JunMa via Phabricator via cfe-commits
junparser accepted this revision.
junparser added a comment.
This revision is now accepted and ready to land.

LGTM. Thanks!




Comment at: clang/lib/CodeGen/CGCoroutine.cpp:650
 
-  if (Stmt *Ret = S.getReturnStmt())
+  if (Stmt *Ret = S.getReturnStmt()) {
+// Since we already emitted the return value above, so we shouldn't

can we just remove this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117087

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


[PATCH] D119716: [clang][lex] NFC: De-duplicate some #include_next logic

2022-02-15 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 408730.
jansvoboda11 added a comment.

Return `std::pair`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119716

Files:
  clang/include/clang/Lex/Preprocessor.h
  clang/lib/Lex/PPDirectives.cpp
  clang/lib/Lex/PPMacroExpansion.cpp

Index: clang/lib/Lex/PPMacroExpansion.cpp
===
--- clang/lib/Lex/PPMacroExpansion.cpp
+++ clang/lib/Lex/PPMacroExpansion.cpp
@@ -1249,32 +1249,9 @@
 }
 
 bool Preprocessor::EvaluateHasIncludeNext(Token &Tok, IdentifierInfo *II) {
-  // __has_include_next is like __has_include, except that we start
-  // searching after the current found directory.  If we can't do this,
-  // issue a diagnostic.
-  // FIXME: Factor out duplication with
-  // Preprocessor::HandleIncludeNextDirective.
-  const DirectoryLookup *Lookup = CurDirLookup;
-  const FileEntry *LookupFromFile = nullptr;
-  if (isInPrimaryFile() && getLangOpts().IsHeaderFile) {
-// If the main file is a header, then it's either for PCH/AST generation,
-// or libclang opened it. Either way, handle it as a normal include below
-// and do not complain about __has_include_next.
-  } else if (isInPrimaryFile()) {
-Lookup = nullptr;
-Diag(Tok, diag::pp_include_next_in_primary);
-  } else if (getCurrentLexerSubmodule()) {
-// Start looking up in the directory *after* the one in which the current
-// file would be found, if any.
-assert(getCurrentLexer() && "#include_next directive in macro?");
-LookupFromFile = getCurrentLexer()->getFileEntry();
-Lookup = nullptr;
-  } else if (!Lookup) {
-Diag(Tok, diag::pp_include_next_absolute_path);
-  } else {
-// Start looking up in the next directory.
-++Lookup;
-  }
+  const DirectoryLookup *Lookup;
+  const FileEntry *LookupFromFile;
+  std::tie(Lookup, LookupFromFile) = getIncludeNextStart(Tok);
 
   return EvaluateHasIncludeCommon(Tok, II, *this, Lookup, LookupFromFile);
 }
Index: clang/lib/Lex/PPDirectives.cpp
===
--- clang/lib/Lex/PPDirectives.cpp
+++ clang/lib/Lex/PPDirectives.cpp
@@ -1778,6 +1778,41 @@
   return true;
 }
 
+std::pair
+Preprocessor::getIncludeNextStart(const Token &IncludeNextTok) const {
+  // #include_next is like #include, except that we start searching after
+  // the current found directory.  If we can't do this, issue a
+  // diagnostic.
+  const DirectoryLookup *Lookup = CurDirLookup;
+  const FileEntry *LookupFromFile = nullptr;
+
+  if (isInPrimaryFile() && LangOpts.IsHeaderFile) {
+// If the main file is a header, then it's either for PCH/AST generation,
+// or libclang opened it. Either way, handle it as a normal include below
+// and do not complain about include_next.
+  } else if (isInPrimaryFile()) {
+Lookup = nullptr;
+Diag(IncludeNextTok, diag::pp_include_next_in_primary);
+  } else if (CurLexerSubmodule) {
+// Start looking up in the directory *after* the one in which the current
+// file would be found, if any.
+assert(CurPPLexer && "#include_next directive in macro?");
+LookupFromFile = CurPPLexer->getFileEntry();
+Lookup = nullptr;
+  } else if (!Lookup) {
+// The current file was not found by walking the include path. Either it
+// is the primary file (handled above), or it was found by absolute path,
+// or it was found relative to such a file.
+// FIXME: Track enough information so we know which case we're in.
+Diag(IncludeNextTok, diag::pp_include_next_absolute_path);
+  } else {
+// Start looking up in the next directory.
+++Lookup;
+  }
+
+  return {Lookup, LookupFromFile};
+}
+
 /// HandleIncludeDirective - The "\#include" tokens have just been read, read
 /// the file to be included from the lexer, then include it!  This is a common
 /// routine with functionality shared between \#include, \#include_next and
@@ -2375,34 +2410,9 @@
   Token &IncludeNextTok) {
   Diag(IncludeNextTok, diag::ext_pp_include_next_directive);
 
-  // #include_next is like #include, except that we start searching after
-  // the current found directory.  If we can't do this, issue a
-  // diagnostic.
-  const DirectoryLookup *Lookup = CurDirLookup;
-  const FileEntry *LookupFromFile = nullptr;
-  if (isInPrimaryFile() && LangOpts.IsHeaderFile) {
-// If the main file is a header, then it's either for PCH/AST generation,
-// or libclang opened it. Either way, handle it as a normal include below
-// and do not complain about include_next.
-  } else if (isInPrimaryFile()) {
-Lookup = nullptr;
-Diag(IncludeNextTok, diag::pp_include_next_in_primary);
-  } else if (CurLexerSubmodule) {
-// Start looking up in the directory *after* the one in which the current
-// file would be found, if any.
-assert(CurPPLexer && "#include_nex

[clang] 86bde99 - Insert a blurb about the -fzero-call-used-regs feature

2022-02-15 Thread Bill Wendling via cfe-commits

Author: Bill Wendling
Date: 2022-02-15T00:06:58-08:00
New Revision: 86bde99a9027f875383e38bfd3a863abae3d0e75

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

LOG: Insert a blurb about the -fzero-call-used-regs feature

Reviewed By: nickdesaulniers

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d6115e0e4a51c..43a2cf98e7c8b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -47,7 +47,12 @@ sections with improvements to Clang's support for those 
languages.
 Major New Features
 --
 
--  ...
+- Clang now supports the ``-fzero-call-used-regs`` feature for x86. The purpose
+  of this feature is to limit Return-Oriented Programming (ROP) exploits and
+  information leakage. It works by zeroing out a selected class of registers
+  before function return --- e.g., all GPRs that are used within the function.
+  There is an analogous ``zero_call_used_regs`` attribute to allow for finer
+  control of this feature.
 
 Improvements to Clang's diagnostics
 ^^^



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


[PATCH] D119592: Insert a blurb about the -fzero-call-used-regs feature

2022-02-15 Thread Bill Wendling via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG86bde99a9027: Insert a blurb about the -fzero-call-used-regs 
feature (authored by void).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119592

Files:
  clang/docs/ReleaseNotes.rst


Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -47,7 +47,12 @@
 Major New Features
 --
 
--  ...
+- Clang now supports the ``-fzero-call-used-regs`` feature for x86. The purpose
+  of this feature is to limit Return-Oriented Programming (ROP) exploits and
+  information leakage. It works by zeroing out a selected class of registers
+  before function return --- e.g., all GPRs that are used within the function.
+  There is an analogous ``zero_call_used_regs`` attribute to allow for finer
+  control of this feature.
 
 Improvements to Clang's diagnostics
 ^^^


Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -47,7 +47,12 @@
 Major New Features
 --
 
--  ...
+- Clang now supports the ``-fzero-call-used-regs`` feature for x86. The purpose
+  of this feature is to limit Return-Oriented Programming (ROP) exploits and
+  information leakage. It works by zeroing out a selected class of registers
+  before function return --- e.g., all GPRs that are used within the function.
+  There is an analogous ``zero_call_used_regs`` attribute to allow for finer
+  control of this feature.
 
 Improvements to Clang's diagnostics
 ^^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D119721: [clang][lex] Use `ConstSearchDirIterator` in lookup cache

2022-02-15 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added inline comments.



Comment at: clang/lib/Lex/HeaderSearch.cpp:710
+  CacheLookup.HitIt = HitIt;
+  noteLookupUsage(&*HitIt - &*search_dir_begin(), Loc);
 }

ahoppen wrote:
> I haven’t looked into this in total details but `&*` looks a little awkward 
> to me. Dereference a pointer/iteration and then get its pointer value back? 
> 
> Wouldn’t this hit the same issue that we saw before if `serach_dir_begin` is 
> allocated in a different bump allocator begin than `HitIt`?
> 
> If possible, would `std::distance` communicate the intent more clearly?
This should really call to `searchDirIdx()`. That will be updated when we 
switch to different storage type in a follow up commit.

Since we're using forward iterators, calling `std::distance` would be O(n) 
instead of the current O(1).



Comment at: clang/lib/Lex/HeaderSearch.cpp:982
 
+  ConstSearchDirIterator NextIt = [](auto ItCopy) { return ++ItCopy; }(It);
+

ahoppen wrote:
> What’s the reason that this can’t be? The current lambda-based implementation 
> looks a little over-complicated to me. But maybe I’m missing something.
> ```
> ConstSearchDirIterator NextIt = ItCopy;
> ++NextIt;
> ```
> 
> or even something equivalent to 
> ```
> ConstSearchDirIterator NextIt = std::next(ItCopy);
> ```
It can be both. I didn't like the former for its verbosity, but `std::next` 
should do the trick, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119721

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


[PATCH] D119721: [clang][lex] Use `ConstSearchDirIterator` in lookup cache

2022-02-15 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 408733.
jansvoboda11 added a comment.

Use `std::next` and `ConstSearchDirIterator::Idx`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119721

Files:
  clang/include/clang/Lex/HeaderSearch.h
  clang/lib/Lex/HeaderSearch.cpp

Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -704,9 +704,10 @@
 }
 
 void HeaderSearch::cacheLookupSuccess(LookupFileCacheInfo &CacheLookup,
-  unsigned HitIdx, SourceLocation Loc) {
-  CacheLookup.HitIdx = HitIdx;
-  noteLookupUsage(HitIdx, Loc);
+  ConstSearchDirIterator HitIt,
+  SourceLocation Loc) {
+  CacheLookup.HitIt = HitIt;
+  noteLookupUsage(HitIt.Idx, Loc);
 }
 
 void HeaderSearch::noteLookupUsage(unsigned HitIdx, SourceLocation Loc) {
@@ -964,12 +965,13 @@
   CurDir = nullptr;
 
   // If this is a system #include, ignore the user #include locs.
-  unsigned i = isAngled ? AngledDirIdx : 0;
+  ConstSearchDirIterator It =
+  isAngled ? angled_dir_begin() : search_dir_begin();
 
   // If this is a #include_next request, start searching after the directory the
   // file was found in.
   if (FromDir)
-i = FromDir.Idx;
+It = FromDir;
 
   // Cache all of the lookups performed by this method.  Many headers are
   // multiply included, and the "pragma once" optimization prevents them from
@@ -977,12 +979,14 @@
   // (potentially huge) series of SearchDirs to find it.
   LookupFileCacheInfo &CacheLookup = LookupFileCache[Filename];
 
+  ConstSearchDirIterator NextIt = std::next(It);
+
   // If the entry has been previously looked up, the first value will be
   // non-zero.  If the value is equal to i (the start point of our search), then
   // this is a matching hit.
-  if (!SkipCache && CacheLookup.StartIdx == i+1) {
+  if (!SkipCache && CacheLookup.StartIt == NextIt) {
 // Skip querying potentially lots of directories for this lookup.
-i = CacheLookup.HitIdx;
+It = CacheLookup.HitIt;
 if (CacheLookup.MappedName) {
   Filename = CacheLookup.MappedName;
   if (IsMapped)
@@ -992,17 +996,17 @@
 // Otherwise, this is the first query, or the previous query didn't match
 // our search start.  We will fill in our found location below, so prime the
 // start point value.
-CacheLookup.reset(/*StartIdx=*/i+1);
+CacheLookup.reset(/*NewStartIt=*/NextIt);
   }
 
   SmallString<64> MappedName;
 
   // Check each directory in sequence to see if it contains this file.
-  for (; i != SearchDirs.size(); ++i) {
+  for (; It != search_dir_end(); ++It) {
 bool InUserSpecifiedSystemFramework = false;
 bool IsInHeaderMap = false;
 bool IsFrameworkFoundInDir = false;
-Optional File = SearchDirs[i].LookupFile(
+Optional File = It->LookupFile(
 Filename, *this, IncludeLoc, SearchPath, RelativePath, RequestingModule,
 SuggestedModule, InUserSpecifiedSystemFramework, IsFrameworkFoundInDir,
 IsInHeaderMap, MappedName);
@@ -1024,7 +1028,7 @@
 if (!File)
   continue;
 
-CurDir = ConstSearchDirIterator(*this, i);
+CurDir = It;
 
 // This file is a system header or C++ unfriendly if the dir is.
 HeaderFileInfo &HFI = getFileInfo(&File->getFileEntry());
@@ -1077,7 +1081,7 @@
   &File->getFileEntry(), isAngled, FoundByHeaderMap);
 
 // Remember this location for the next lookup we do.
-cacheLookupSuccess(CacheLookup, i, IncludeLoc);
+cacheLookupSuccess(CacheLookup, It, IncludeLoc);
 return File;
   }
 
@@ -1108,7 +1112,7 @@
   }
 
   cacheLookupSuccess(LookupFileCache[Filename],
- LookupFileCache[ScratchFilename].HitIdx, IncludeLoc);
+ LookupFileCache[ScratchFilename].HitIt, IncludeLoc);
   // FIXME: SuggestedModule.
   return File;
 }
@@ -1122,7 +1126,7 @@
   }
 
   // Otherwise, didn't find it. Remember we didn't find this.
-  CacheLookup.HitIdx = SearchDirs.size();
+  CacheLookup.HitIt = search_dir_end();
   return None;
 }
 
Index: clang/include/clang/Lex/HeaderSearch.h
===
--- clang/include/clang/Lex/HeaderSearch.h
+++ clang/include/clang/Lex/HeaderSearch.h
@@ -255,13 +255,13 @@
 
   /// Keeps track of each lookup performed by LookupFile.
   struct LookupFileCacheInfo {
-/// Starting index in SearchDirs that the cached search was performed from.
-/// If there is a hit and this value doesn't match the current query, the
-/// cache has to be ignored.
-unsigned StartIdx = 0;
+/// Starting search directory iterator that the cached search was performed
+/// from. If there is a hit and this value doesn't match the current query,
+/// the cache has

[PATCH] D119721: [clang][lex] Use `ConstSearchDirIterator` in lookup cache

2022-02-15 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added inline comments.



Comment at: clang/lib/Lex/HeaderSearch.cpp:710
+  CacheLookup.HitIt = HitIt;
+  noteLookupUsage(&*HitIt - &*search_dir_begin(), Loc);
 }

jansvoboda11 wrote:
> ahoppen wrote:
> > I haven’t looked into this in total details but `&*` looks a little awkward 
> > to me. Dereference a pointer/iteration and then get its pointer value back? 
> > 
> > Wouldn’t this hit the same issue that we saw before if `serach_dir_begin` 
> > is allocated in a different bump allocator begin than `HitIt`?
> > 
> > If possible, would `std::distance` communicate the intent more clearly?
> This should really call to `searchDirIdx()`. That will be updated when we 
> switch to different storage type in a follow up commit.
> 
> Since we're using forward iterators, calling `std::distance` would be O(n) 
> instead of the current O(1).
(Used `ConstSearchDirIterator::Idx` for now, but will refactor this with the 
new storage layout in a follow-up.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119721

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


[PATCH] D119785: [clang-format] Fix formatting of struct-like records followed by variable declaration.

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

LGTM, I really like the approach of us annotating more like this, it makes the 
token much easier to reason about when there is ambiguity. nice one!




Comment at: clang/lib/Format/UnwrappedLineFormatter.cpp:735
 // We don't merge short records.
-FormatToken *RecordTok = Line.First;
-// Skip record modifiers.
-while (RecordTok->Next &&
-   RecordTok->isOneOf(tok::kw_typedef, tok::kw_export,
-  Keywords.kw_declare, Keywords.kw_abstract,
-  tok::kw_default, Keywords.kw_override,
-  tok::kw_public, tok::kw_private,
-  tok::kw_protected, Keywords.kw_internal))
-  RecordTok = RecordTok->Next;
-if (RecordTok &&
-RecordTok->isOneOf(tok::kw_class, tok::kw_union, tok::kw_struct,
-   Keywords.kw_interface))
+if (isRecordLBrace(*Line.Last))
   return 0;

wow these are equivalent? do we need to worry about trailing comments?

```
public class A { /* comment */
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119785

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


[PATCH] D119785: [clang-format] Fix formatting of struct-like records followed by variable declaration.

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



Comment at: clang/lib/Format/UnwrappedLineFormatter.cpp:470
+ShouldMerge = Style.AllowShortEnumsOnASingleLine;
+  } else if (TheLine->Last->isOneOf(TT_ClassLBrace, TT_StructLBrace)) {
+// NOTE: We use AfterClass (whereas AfterStruct exists) for both 
classes

Why not Union?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119785

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


[PATCH] D118700: Add support to --gcc-toolchain flag for GCC compiled with --enable-version-specific-runtime-libs.

2022-02-15 Thread Raúl Peñacoba via Phabricator via cfe-commits
rpenacob added a comment.

To test that this change does not break anything we built clang trunk with the 
patch. Our stage one looks like this.

-DCMAKE_INSTALL_PREFIX=/path/to/stage-one
-DCMAKE_BUILD_TYPE=Release
-DLLVM_ENABLE_PROJECTS=clang
-DLLVM_ENABLE_RUNTIMES="libcxx;compiler-rt;libcxxabi;libunwind"
-DCLANG_DEFAULT_RTLIB=compiler-rt
-DCLANG_DEFAULT_UNWINDLIB=libunwind
-DCLANG_DEFAULT_CXX_STDLIB=libc++
-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON# We don't have multilib for i386 in 
this test system
-DLLVM_USE_LINKER=lld

Then we built a stage two using the stage one (-DCMAKE_C_COMPILER and 
-DCMAKE_CXX_COMPILER pointing to stage-one's clang and clang++) with only 
-DLLVM_ENABLE_PROJECTS=clang. No test failed.

(We had to set LD_LIBRARY_PATH to 
/path/to/stage-one/lib/x86_64-unknown-linux-gnu so it finds runtime libs like 
libc++ and such.)

Do you think this is enough testing? Perhaps there is something else we could 
try.


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

https://reviews.llvm.org/D118700

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


[PATCH] D119682: [clang-format][docs] Fix incorrect 'clang-format 13' configuration options markers

2022-02-15 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay accepted this revision.
MyDeveloperDay added a subscriber: HazardyKnusperkeks.
MyDeveloperDay added a comment.
This revision is now accepted and ready to land.

@HazardyKnusperkeks could you validate the `IndentRequiresClause` I know I 
added `IndentRequires` in 13 but is this the same option renamed or a new 
option?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119682

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


[PATCH] D119682: [clang-format][docs] Fix incorrect 'clang-format 13' configuration options markers

2022-02-15 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

I understand what you are saying re 'IndentRequiresClause' but this leaves us 
with people with "IndentRequires" in their .clang-format without any 
understanding of what it means? i.e. what about the 14.0 people? if we've 
renamed an option then the documentation should carry something like

'Previously known as IndentRequires'


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119682

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


[PATCH] D119716: [clang][lex] NFC: De-duplicate some #include_next logic

2022-02-15 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added inline comments.



Comment at: clang/include/clang/Lex/Preprocessor.h:2207
+   const FileEntry *&LookupFromFile) const;
+
   /// Install the standard preprocessor pragmas:

ahoppen wrote:
> I there a reason why this uses an out parameter instead of a returning a 
> `std::pair` or something similar? If yes, I think it would be good to 
> document which parameters are out parameters. `IncludeNextTok` looks 
> suspiciously like an out-parameter as well but is not AFAICT.
Not really. Switched to using `std::pair` and `std::tie` in the latest revision.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119716

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


[PATCH] D119722: [clang][lex] Use `SearchDirIterator` types in for loops

2022-02-15 Thread Alex Hoppen via Phabricator via cfe-commits
ahoppen accepted this revision.
ahoppen added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Lex/HeaderSearch.cpp:1450
 Optional HeaderSearch::searchDirIdx(const DirectoryLookup &DL) const 
{
-  for (unsigned I = 0; I < SearchDirs.size(); ++I)
-if (&SearchDirs[I] == &DL)
-  return I;
-  return None;
+  return &DL - &*SearchDirs.begin();
 }

jansvoboda11 wrote:
> ahoppen wrote:
> > Could we change this function to return an `unsigned` instead of 
> > `Optional` now?
> > 
> > Also, is `&DL - &*SearchDirs.begin()` safe and doesn’t trigger the issues 
> > we saw previously if start and end are allocated in different memory 
> > regions, because I don’t know.
> Yes, updating the return type makes sense now, thanks!
> 
> Yes, this should be safe as of this patch, since we're still storing 
> `DirectoryLookup` objects in `std::vector`. I'll be updating 
> this code when we change the storage (separate `std::vector` 
> for quoted, angled and system search paths).
OK, great. Makes sense. :thumbsup:


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119722

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


[clang-tools-extra] 7a124f4 - [clang][lex] Remove `PPCallbacks::FileNotFound()`

2022-02-15 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2022-02-15T09:48:25+01:00
New Revision: 7a124f4859d5c4093467abc2e734f8ab15e78cc6

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

LOG: [clang][lex] Remove `PPCallbacks::FileNotFound()`

The purpose of the `FileNotFound` preprocessor callback was to add the ability 
to recover from failed header lookups. This was to support downstream project.

However, injecting additional search path while performing header search can 
invalidate currently used iterators/references to `DirectoryLookup` in 
`Preprocessor` and `HeaderSearch`.

The downstream project ended up maintaining a separate patch to further tweak 
the functionality. Since we don't have any upstream users nor open source 
downstream users, I'd like to remove this callback for good to prevent future 
misuse. I doubt there are any actual downstream users, since the functionality 
is definitely broken at the moment.

Reviewed By: ahoppen

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

Added: 


Modified: 
clang-tools-extra/clangd/ParsedAST.cpp
clang-tools-extra/pp-trace/PPCallbacksTracker.cpp
clang-tools-extra/pp-trace/PPCallbacksTracker.h
clang/include/clang/Lex/PPCallbacks.h
clang/lib/Lex/PPDirectives.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/ParsedAST.cpp 
b/clang-tools-extra/clangd/ParsedAST.cpp
index 86c4b2151243..199cad8dde44 100644
--- a/clang-tools-extra/clangd/ParsedAST.cpp
+++ b/clang-tools-extra/clangd/ParsedAST.cpp
@@ -226,10 +226,6 @@ class ReplayPreamble : private PPCallbacks {
   /*Imported=*/nullptr, Inc.FileKind);
   if (File)
 Delegate->FileSkipped(*File, SynthesizedFilenameTok, Inc.FileKind);
-  else {
-llvm::SmallString<1> UnusedRecovery;
-Delegate->FileNotFound(WrittenFilename, UnusedRecovery);
-  }
 }
   }
 

diff  --git a/clang-tools-extra/pp-trace/PPCallbacksTracker.cpp 
b/clang-tools-extra/pp-trace/PPCallbacksTracker.cpp
index 63faae651998..785fa9b679bb 100644
--- a/clang-tools-extra/pp-trace/PPCallbacksTracker.cpp
+++ b/clang-tools-extra/pp-trace/PPCallbacksTracker.cpp
@@ -128,16 +128,6 @@ void PPCallbacksTracker::FileSkipped(const FileEntryRef 
&SkippedFile,
   appendArgument("FileType", FileType, CharacteristicKindStrings);
 }
 
-// Callback invoked whenever an inclusion directive results in a
-// file-not-found error.
-bool
-PPCallbacksTracker::FileNotFound(llvm::StringRef FileName,
- llvm::SmallVectorImpl &RecoveryPath) {
-  beginCallback("FileNotFound");
-  appendFilePathArgument("FileName", FileName);
-  return false;
-}
-
 // Callback invoked whenever an inclusion directive of
 // any kind (#include, #import, etc.) has been processed, regardless
 // of whether the inclusion will actually result in an inclusion.

diff  --git a/clang-tools-extra/pp-trace/PPCallbacksTracker.h 
b/clang-tools-extra/pp-trace/PPCallbacksTracker.h
index db5d51b00364..7be31031fe71 100644
--- a/clang-tools-extra/pp-trace/PPCallbacksTracker.h
+++ b/clang-tools-extra/pp-trace/PPCallbacksTracker.h
@@ -91,8 +91,6 @@ class PPCallbacksTracker : public PPCallbacks {
FileID PrevFID = FileID()) override;
   void FileSkipped(const FileEntryRef &SkippedFile, const Token &FilenameTok,
SrcMgr::CharacteristicKind FileType) override;
-  bool FileNotFound(llvm::StringRef FileName,
-llvm::SmallVectorImpl &RecoveryPath) override;
   void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
   llvm::StringRef FileName, bool IsAngled,
   CharSourceRange FilenameRange, const FileEntry *File,

diff  --git a/clang/include/clang/Lex/PPCallbacks.h 
b/clang/include/clang/Lex/PPCallbacks.h
index 76a74f20cc3b..298947836a39 100644
--- a/clang/include/clang/Lex/PPCallbacks.h
+++ b/clang/include/clang/Lex/PPCallbacks.h
@@ -61,23 +61,6 @@ class PPCallbacks {
const Token &FilenameTok,
SrcMgr::CharacteristicKind FileType) {}
 
-  /// Callback invoked whenever an inclusion directive results in a
-  /// file-not-found error.
-  ///
-  /// \param FileName The name of the file being included, as written in the
-  /// source code.
-  ///
-  /// \param RecoveryPath If this client indicates that it can recover from
-  /// this missing file, the client should set this as an additional header
-  /// search patch.
-  ///
-  /// \returns true to indicate that the preprocessor should attempt to recover
-  /// by adding \p RecoveryPath as a header search path.
-  virtual bool FileNotFound(StringRef FileName,
-SmallVectorImpl &RecoveryPath) {
-return false;
-  }
-
   /// Callback invoked whenever an inclusion dire

[clang] edd09bb - [clang][lex] Remove `Preprocessor::GetCurDirLookup()`

2022-02-15 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2022-02-15T09:48:25+01:00
New Revision: edd09bb5a49c6a5dac29714af661d1ddffe50a72

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

LOG: [clang][lex] Remove `Preprocessor::GetCurDirLookup()`

`Preprocessor` exposes the search directory iterator via `GetCurDirLookup()` 
getter, which is only used in two static functions.

To simplify reasoning about search directory iterators/references and to 
simplify the `Preprocessor` API, this patch makes the two static functions 
private member functions and removes the getter entirely.

Depends D119708.

Reviewed By: ahoppen, dexonsmith

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

Added: 


Modified: 
clang/include/clang/Lex/Preprocessor.h
clang/lib/Lex/PPMacroExpansion.cpp

Removed: 




diff  --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index e567f6391531..dbe6aa949a75 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -2077,13 +2077,6 @@ class Preprocessor {
  ModuleMap::KnownHeader *SuggestedModule, bool *IsMapped,
  bool *IsFrameworkFound, bool SkipCache = false);
 
-  /// Get the DirectoryLookup structure used to find the current
-  /// FileEntry, if CurLexer is non-null and if applicable.
-  ///
-  /// This allows us to implement \#include_next and find directory-specific
-  /// properties.
-  const DirectoryLookup *GetCurDirLookup() { return CurDirLookup; }
-
   /// Return true if we're in the top-level file, not in a \#include.
   bool isInPrimaryFile() const;
 
@@ -2197,6 +2190,16 @@ class Preprocessor {
   /// If the expression is equivalent to "!defined(X)" return X in IfNDefMacro.
   DirectiveEvalResult EvaluateDirectiveExpression(IdentifierInfo 
*&IfNDefMacro);
 
+  /// Process a '__has_include("path")' expression.
+  ///
+  /// Returns true if successful.
+  bool EvaluateHasInclude(Token &Tok, IdentifierInfo *II);
+
+  /// Process '__has_include_next("path")' expression.
+  ///
+  /// Returns true if successful.
+  bool EvaluateHasIncludeNext(Token &Tok, IdentifierInfo *II);
+
   /// Install the standard preprocessor pragmas:
   /// \#pragma GCC poison/system_header/dependency and \#pragma once.
   void RegisterBuiltinPragmas();

diff  --git a/clang/lib/Lex/PPMacroExpansion.cpp 
b/clang/lib/Lex/PPMacroExpansion.cpp
index f6c95a8b67c6..a1fde8a149cc 100644
--- a/clang/lib/Lex/PPMacroExpansion.cpp
+++ b/clang/lib/Lex/PPMacroExpansion.cpp
@@ -1244,45 +1244,39 @@ static bool EvaluateHasIncludeCommon(Token &Tok,
   return File.hasValue();
 }
 
-/// EvaluateHasInclude - Process a '__has_include("path")' expression.
-/// Returns true if successful.
-static bool EvaluateHasInclude(Token &Tok, IdentifierInfo *II,
-   Preprocessor &PP) {
-  return EvaluateHasIncludeCommon(Tok, II, PP, nullptr, nullptr);
+bool Preprocessor::EvaluateHasInclude(Token &Tok, IdentifierInfo *II) {
+  return EvaluateHasIncludeCommon(Tok, II, *this, nullptr, nullptr);
 }
 
-/// EvaluateHasIncludeNext - Process '__has_include_next("path")' expression.
-/// Returns true if successful.
-static bool EvaluateHasIncludeNext(Token &Tok,
-   IdentifierInfo *II, Preprocessor &PP) {
+bool Preprocessor::EvaluateHasIncludeNext(Token &Tok, IdentifierInfo *II) {
   // __has_include_next is like __has_include, except that we start
   // searching after the current found directory.  If we can't do this,
   // issue a diagnostic.
   // FIXME: Factor out duplication with
   // Preprocessor::HandleIncludeNextDirective.
-  const DirectoryLookup *Lookup = PP.GetCurDirLookup();
+  const DirectoryLookup *Lookup = CurDirLookup;
   const FileEntry *LookupFromFile = nullptr;
-  if (PP.isInPrimaryFile() && PP.getLangOpts().IsHeaderFile) {
+  if (isInPrimaryFile() && getLangOpts().IsHeaderFile) {
 // If the main file is a header, then it's either for PCH/AST generation,
 // or libclang opened it. Either way, handle it as a normal include below
 // and do not complain about __has_include_next.
-  } else if (PP.isInPrimaryFile()) {
+  } else if (isInPrimaryFile()) {
 Lookup = nullptr;
-PP.Diag(Tok, diag::pp_include_next_in_primary);
-  } else if (PP.getCurrentLexerSubmodule()) {
+Diag(Tok, diag::pp_include_next_in_primary);
+  } else if (getCurrentLexerSubmodule()) {
 // Start looking up in the directory *after* the one in which the current
 // file would be found, if any.
-assert(PP.getCurrentLexer() && "#include_next directive in macro?");
-LookupFromFile = PP.getCurrentLexer()->getFileEntry();
+assert(getCurrentLexer() && "#include_next directive in macro?");
+LookupFromFile = getCurrentLexer()->getFileEntry();
 Lookup 

[PATCH] D119708: [clang][lex] Remove `PPCallbacks::FileNotFound()`

2022-02-15 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7a124f4859d5: [clang][lex] Remove 
`PPCallbacks::FileNotFound()` (authored by jansvoboda11).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119708

Files:
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/pp-trace/PPCallbacksTracker.cpp
  clang-tools-extra/pp-trace/PPCallbacksTracker.h
  clang/include/clang/Lex/PPCallbacks.h
  clang/lib/Lex/PPDirectives.cpp

Index: clang/lib/Lex/PPDirectives.cpp
===
--- clang/lib/Lex/PPDirectives.cpp
+++ clang/lib/Lex/PPDirectives.cpp
@@ -1845,28 +1845,6 @@
   if (File)
 return File;
 
-  if (Callbacks) {
-// Give the clients a chance to recover.
-SmallString<128> RecoveryPath;
-if (Callbacks->FileNotFound(Filename, RecoveryPath)) {
-  if (auto DE = FileMgr.getOptionalDirectoryRef(RecoveryPath)) {
-// Add the recovery path to the list of search paths.
-DirectoryLookup DL(*DE, SrcMgr::C_User, false);
-HeaderInfo.AddSearchPath(DL, isAngled);
-
-// Try the lookup again, skipping the cache.
-Optional File = LookupFile(
-FilenameLoc,
-LookupFilename, isAngled,
-LookupFrom, LookupFromFile, CurDir, nullptr, nullptr,
-&SuggestedModule, &IsMapped, /*IsFrameworkFound=*/nullptr,
-/*SkipCache*/ true);
-if (File)
-  return File;
-  }
-}
-  }
-
   if (SuppressIncludeNotFoundError)
 return None;
 
Index: clang/include/clang/Lex/PPCallbacks.h
===
--- clang/include/clang/Lex/PPCallbacks.h
+++ clang/include/clang/Lex/PPCallbacks.h
@@ -61,23 +61,6 @@
const Token &FilenameTok,
SrcMgr::CharacteristicKind FileType) {}
 
-  /// Callback invoked whenever an inclusion directive results in a
-  /// file-not-found error.
-  ///
-  /// \param FileName The name of the file being included, as written in the
-  /// source code.
-  ///
-  /// \param RecoveryPath If this client indicates that it can recover from
-  /// this missing file, the client should set this as an additional header
-  /// search patch.
-  ///
-  /// \returns true to indicate that the preprocessor should attempt to recover
-  /// by adding \p RecoveryPath as a header search path.
-  virtual bool FileNotFound(StringRef FileName,
-SmallVectorImpl &RecoveryPath) {
-return false;
-  }
-
   /// Callback invoked whenever an inclusion directive of
   /// any kind (\c \#include, \c \#import, etc.) has been processed, regardless
   /// of whether the inclusion will actually result in an inclusion.
@@ -443,12 +426,6 @@
 Second->FileSkipped(SkippedFile, FilenameTok, FileType);
   }
 
-  bool FileNotFound(StringRef FileName,
-SmallVectorImpl &RecoveryPath) override {
-return First->FileNotFound(FileName, RecoveryPath) ||
-   Second->FileNotFound(FileName, RecoveryPath);
-  }
-
   void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
   StringRef FileName, bool IsAngled,
   CharSourceRange FilenameRange, const FileEntry *File,
Index: clang-tools-extra/pp-trace/PPCallbacksTracker.h
===
--- clang-tools-extra/pp-trace/PPCallbacksTracker.h
+++ clang-tools-extra/pp-trace/PPCallbacksTracker.h
@@ -91,8 +91,6 @@
FileID PrevFID = FileID()) override;
   void FileSkipped(const FileEntryRef &SkippedFile, const Token &FilenameTok,
SrcMgr::CharacteristicKind FileType) override;
-  bool FileNotFound(llvm::StringRef FileName,
-llvm::SmallVectorImpl &RecoveryPath) override;
   void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
   llvm::StringRef FileName, bool IsAngled,
   CharSourceRange FilenameRange, const FileEntry *File,
Index: clang-tools-extra/pp-trace/PPCallbacksTracker.cpp
===
--- clang-tools-extra/pp-trace/PPCallbacksTracker.cpp
+++ clang-tools-extra/pp-trace/PPCallbacksTracker.cpp
@@ -128,16 +128,6 @@
   appendArgument("FileType", FileType, CharacteristicKindStrings);
 }
 
-// Callback invoked whenever an inclusion directive results in a
-// file-not-found error.
-bool
-PPCallbacksTracker::FileNotFound(llvm::StringRef FileName,
- llvm::SmallVectorImpl &RecoveryPath) {
-  beginCallback("FileNotFound");
-  appendFilePathArgument("FileName", FileName);
-  return false;
-}
-
 // Callback invoked whenever an inclusion directive of
 // any kind (#include, #import, etc.) has been processed, regardless
 // of whether the inclusion 

[PATCH] D119714: [clang][lex] Remove `Preprocessor::GetCurDirLookup()`

2022-02-15 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGedd09bb5a49c: [clang][lex] Remove 
`Preprocessor::GetCurDirLookup()` (authored by jansvoboda11).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119714

Files:
  clang/include/clang/Lex/Preprocessor.h
  clang/lib/Lex/PPMacroExpansion.cpp

Index: clang/lib/Lex/PPMacroExpansion.cpp
===
--- clang/lib/Lex/PPMacroExpansion.cpp
+++ clang/lib/Lex/PPMacroExpansion.cpp
@@ -1244,45 +1244,39 @@
   return File.hasValue();
 }
 
-/// EvaluateHasInclude - Process a '__has_include("path")' expression.
-/// Returns true if successful.
-static bool EvaluateHasInclude(Token &Tok, IdentifierInfo *II,
-   Preprocessor &PP) {
-  return EvaluateHasIncludeCommon(Tok, II, PP, nullptr, nullptr);
+bool Preprocessor::EvaluateHasInclude(Token &Tok, IdentifierInfo *II) {
+  return EvaluateHasIncludeCommon(Tok, II, *this, nullptr, nullptr);
 }
 
-/// EvaluateHasIncludeNext - Process '__has_include_next("path")' expression.
-/// Returns true if successful.
-static bool EvaluateHasIncludeNext(Token &Tok,
-   IdentifierInfo *II, Preprocessor &PP) {
+bool Preprocessor::EvaluateHasIncludeNext(Token &Tok, IdentifierInfo *II) {
   // __has_include_next is like __has_include, except that we start
   // searching after the current found directory.  If we can't do this,
   // issue a diagnostic.
   // FIXME: Factor out duplication with
   // Preprocessor::HandleIncludeNextDirective.
-  const DirectoryLookup *Lookup = PP.GetCurDirLookup();
+  const DirectoryLookup *Lookup = CurDirLookup;
   const FileEntry *LookupFromFile = nullptr;
-  if (PP.isInPrimaryFile() && PP.getLangOpts().IsHeaderFile) {
+  if (isInPrimaryFile() && getLangOpts().IsHeaderFile) {
 // If the main file is a header, then it's either for PCH/AST generation,
 // or libclang opened it. Either way, handle it as a normal include below
 // and do not complain about __has_include_next.
-  } else if (PP.isInPrimaryFile()) {
+  } else if (isInPrimaryFile()) {
 Lookup = nullptr;
-PP.Diag(Tok, diag::pp_include_next_in_primary);
-  } else if (PP.getCurrentLexerSubmodule()) {
+Diag(Tok, diag::pp_include_next_in_primary);
+  } else if (getCurrentLexerSubmodule()) {
 // Start looking up in the directory *after* the one in which the current
 // file would be found, if any.
-assert(PP.getCurrentLexer() && "#include_next directive in macro?");
-LookupFromFile = PP.getCurrentLexer()->getFileEntry();
+assert(getCurrentLexer() && "#include_next directive in macro?");
+LookupFromFile = getCurrentLexer()->getFileEntry();
 Lookup = nullptr;
   } else if (!Lookup) {
-PP.Diag(Tok, diag::pp_include_next_absolute_path);
+Diag(Tok, diag::pp_include_next_absolute_path);
   } else {
 // Start looking up in the next directory.
 ++Lookup;
   }
 
-  return EvaluateHasIncludeCommon(Tok, II, PP, Lookup, LookupFromFile);
+  return EvaluateHasIncludeCommon(Tok, II, *this, Lookup, LookupFromFile);
 }
 
 /// Process single-argument builtin feature-like macros that return
@@ -1736,9 +1730,9 @@
 // double-quotes ("").
 bool Value;
 if (II == Ident__has_include)
-  Value = EvaluateHasInclude(Tok, II, *this);
+  Value = EvaluateHasInclude(Tok, II);
 else
-  Value = EvaluateHasIncludeNext(Tok, II, *this);
+  Value = EvaluateHasIncludeNext(Tok, II);
 
 if (Tok.isNot(tok::r_paren))
   return;
Index: clang/include/clang/Lex/Preprocessor.h
===
--- clang/include/clang/Lex/Preprocessor.h
+++ clang/include/clang/Lex/Preprocessor.h
@@ -2077,13 +2077,6 @@
  ModuleMap::KnownHeader *SuggestedModule, bool *IsMapped,
  bool *IsFrameworkFound, bool SkipCache = false);
 
-  /// Get the DirectoryLookup structure used to find the current
-  /// FileEntry, if CurLexer is non-null and if applicable.
-  ///
-  /// This allows us to implement \#include_next and find directory-specific
-  /// properties.
-  const DirectoryLookup *GetCurDirLookup() { return CurDirLookup; }
-
   /// Return true if we're in the top-level file, not in a \#include.
   bool isInPrimaryFile() const;
 
@@ -2197,6 +2190,16 @@
   /// If the expression is equivalent to "!defined(X)" return X in IfNDefMacro.
   DirectiveEvalResult EvaluateDirectiveExpression(IdentifierInfo *&IfNDefMacro);
 
+  /// Process a '__has_include("path")' expression.
+  ///
+  /// Returns true if successful.
+  bool EvaluateHasInclude(Token &Tok, IdentifierInfo *II);
+
+  /// Process '__has_include_next("path")' expression.
+  ///
+  /// Returns true if successful.
+  bool EvaluateHasIncludeNext(Token &Tok, IdentifierInfo *II);
+
   /// Install the standard preprocessor pragmas:
   /// \#pragma GCC poison/sy

[clang] fd2dff1 - [clang][lex][minimizer] Ensure whitespace between squashed lines

2022-02-15 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2022-02-15T09:49:03+01:00
New Revision: fd2dff17c53dbfd89789989bedd949c496e7b6b7

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

LOG: [clang][lex][minimizer] Ensure whitespace between squashed lines

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

This means the following code:

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

gets minimized into:

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

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

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

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

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

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

Reviewed By: arphaman

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

Added: 


Modified: 
clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp
clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp

Removed: 




diff  --git a/clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp 
b/clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp
index f597c56837fb..d247e1471cc8 100644
--- a/clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp
+++ b/clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp
@@ -270,6 +270,15 @@ static const char *findLastNonSpace(const char *First, 
const char *Last) {
   return Last;
 }
 
+static const char *findLastNonSpaceNonBackslash(const char *First,
+const char *Last) {
+  assert(First <= Last);
+  while (First != Last &&
+ (isHorizontalWhitespace(Last[-1]) || Last[-1] == '\\'))
+--Last;
+  return Last;
+}
+
 static const char *findFirstTrailingSpace(const char *First,
   const char *Last) {
   const char *LastNonSpace = findLastNonSpace(First, Last);
@@ -434,11 +443,11 @@ void Minimizer::printToNewline(const char *&First, const 
char *const End) {
   return;
 }
 
-// Print up to the backslash, backing up over spaces. Preserve at least one
-// space, as the space matters when tokens are separated by a line
-// continuation.
-append(First, findFirstTrailingSpace(
-  First, LastBeforeTrailingSpace - 1));
+// Print up to the last character that's not a whitespace or backslash.
+// Then print exactly one space, which matters when tokens are separated by
+// a line continuation.
+append(First, findLastNonSpaceNonBackslash(First, Last));
+put(' ');
 
 First = Last;
 skipNewline(First, End);

diff  --git a/clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp 
b/clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp
index d65c8de7f0e1..5fd4f6024bff 100644
--- a/clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp
+++ b/clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp
@@ -713,6 +713,17 @@ TEST(MinimizeSourceToDependencyDirectivesTest,
   Out.data());
 }
 
+TEST(MinimizeSourceToDependencyDirectivesTest,
+ SupportWhitespaceBeforeLineContinuation) {
+  SmallVector Out;
+
+  ASSERT_FALSE(minimizeSourceToDependencyDirectives("#define FOO(BAR) \\\n"
+"  #BAR\\\n"
+"  baz\n",
+Out));
+  EXPECT_STREQ("#define FOO(BAR) #BAR baz\n", Out.data());
+}
+
 TEST(MinimizeSourceToDependencyDirectivesTest,
  SupportWhitespaceBeforeLineContinuationInStringSkipping) {
   SmallVector Out;



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


[PATCH] D119231: [clang][lex][minimizer] Ensure whitespace between squashed lines

2022-02-15 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGfd2dff17c53d: [clang][lex][minimizer] Ensure whitespace 
between squashed lines (authored by jansvoboda11).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119231

Files:
  clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp
  clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp


Index: clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp
===
--- clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp
+++ clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp
@@ -713,6 +713,17 @@
   Out.data());
 }
 
+TEST(MinimizeSourceToDependencyDirectivesTest,
+ SupportWhitespaceBeforeLineContinuation) {
+  SmallVector Out;
+
+  ASSERT_FALSE(minimizeSourceToDependencyDirectives("#define FOO(BAR) \\\n"
+"  #BAR\\\n"
+"  baz\n",
+Out));
+  EXPECT_STREQ("#define FOO(BAR) #BAR baz\n", Out.data());
+}
+
 TEST(MinimizeSourceToDependencyDirectivesTest,
  SupportWhitespaceBeforeLineContinuationInStringSkipping) {
   SmallVector Out;
Index: clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp
===
--- clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp
+++ clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp
@@ -270,6 +270,15 @@
   return Last;
 }
 
+static const char *findLastNonSpaceNonBackslash(const char *First,
+const char *Last) {
+  assert(First <= Last);
+  while (First != Last &&
+ (isHorizontalWhitespace(Last[-1]) || Last[-1] == '\\'))
+--Last;
+  return Last;
+}
+
 static const char *findFirstTrailingSpace(const char *First,
   const char *Last) {
   const char *LastNonSpace = findLastNonSpace(First, Last);
@@ -434,11 +443,11 @@
   return;
 }
 
-// Print up to the backslash, backing up over spaces. Preserve at least one
-// space, as the space matters when tokens are separated by a line
-// continuation.
-append(First, findFirstTrailingSpace(
-  First, LastBeforeTrailingSpace - 1));
+// Print up to the last character that's not a whitespace or backslash.
+// Then print exactly one space, which matters when tokens are separated by
+// a line continuation.
+append(First, findLastNonSpaceNonBackslash(First, Last));
+put(' ');
 
 First = Last;
 skipNewline(First, End);


Index: clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp
===
--- clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp
+++ clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp
@@ -713,6 +713,17 @@
   Out.data());
 }
 
+TEST(MinimizeSourceToDependencyDirectivesTest,
+ SupportWhitespaceBeforeLineContinuation) {
+  SmallVector Out;
+
+  ASSERT_FALSE(minimizeSourceToDependencyDirectives("#define FOO(BAR) \\\n"
+"  #BAR\\\n"
+"  baz\n",
+Out));
+  EXPECT_STREQ("#define FOO(BAR) #BAR baz\n", Out.data());
+}
+
 TEST(MinimizeSourceToDependencyDirectivesTest,
  SupportWhitespaceBeforeLineContinuationInStringSkipping) {
   SmallVector Out;
Index: clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp
===
--- clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp
+++ clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp
@@ -270,6 +270,15 @@
   return Last;
 }
 
+static const char *findLastNonSpaceNonBackslash(const char *First,
+const char *Last) {
+  assert(First <= Last);
+  while (First != Last &&
+ (isHorizontalWhitespace(Last[-1]) || Last[-1] == '\\'))
+--Last;
+  return Last;
+}
+
 static const char *findFirstTrailingSpace(const char *First,
   const char *Last) {
   const char *LastNonSpace = findLastNonSpace(First, Last);
@@ -434,11 +443,11 @@
   return;
 }
 
-// Print up to the backslash, backing up over spaces. Preserve at least one
-// space, as the space matters when tokens are separated by a line
-// continuation.
-append(First, findFirstTrailingSpace(
-  First, LastBeforeTrailingSpace - 1));
+// Print up to the last character that's not a whitespace or backslash.
+// Then print exactly one space, which matters when tokens are separated by
+// a line continuation.
+append(First, findLastNonSpace

[clang] d8298f0 - [clang][lex][minimizer] Avoid treating path separators as comments

2022-02-15 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2022-02-15T09:49:19+01:00
New Revision: d8298f04a9681fcbb16d7fc4872690b5504a0d52

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

LOG: [clang][lex][minimizer] Avoid treating path separators as comments

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

Added: 


Modified: 
clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp
clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp

Removed: 




diff  --git a/clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp 
b/clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp
index d247e1471cc8..10536438e2fc 100644
--- a/clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp
+++ b/clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp
@@ -401,7 +401,7 @@ void Minimizer::printToNewline(const char *&First, const 
char *const End) {
 do {
   // Iterate over strings correctly to avoid comments and newlines.
   if (*Last == '"' || *Last == '\'' ||
-  (*Last == '<' && top() == pp_include)) {
+  (*Last == '<' && (top() == pp_include || top() == pp_import))) {
 if (LLVM_UNLIKELY(isRawStringLiteral(First, Last)))
   skipRawString(Last, End);
 else

diff  --git a/clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp 
b/clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp
index 5fd4f6024bff..f6ef96eaed5c 100644
--- a/clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp
+++ b/clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp
@@ -453,6 +453,14 @@ TEST(MinimizeSourceToDependencyDirectivesTest, Include) {
   ASSERT_FALSE(minimizeSourceToDependencyDirectives("#include \n", Out));
   EXPECT_STREQ("#include \n", Out.data());
 
+  ASSERT_FALSE(
+  minimizeSourceToDependencyDirectives("#include \n", Out));
+  EXPECT_STREQ("#include \n", Out.data());
+
+  ASSERT_FALSE(
+  minimizeSourceToDependencyDirectives("#include \"A//A.h\"\n", Out));
+  EXPECT_STREQ("#include \"A//A.h\"\n", Out.data());
+
   ASSERT_FALSE(
   minimizeSourceToDependencyDirectives("#include_next \n", Out));
   EXPECT_STREQ("#include_next \n", Out.data());
@@ -460,6 +468,13 @@ TEST(MinimizeSourceToDependencyDirectivesTest, Include) {
   ASSERT_FALSE(minimizeSourceToDependencyDirectives("#import \n", Out));
   EXPECT_STREQ("#import \n", Out.data());
 
+  ASSERT_FALSE(minimizeSourceToDependencyDirectives("#import \n", 
Out));
+  EXPECT_STREQ("#import \n", Out.data());
+
+  ASSERT_FALSE(
+  minimizeSourceToDependencyDirectives("#import \"A//A.h\"\n", Out));
+  EXPECT_STREQ("#import \"A//A.h\"\n", Out.data());
+
   ASSERT_FALSE(
   minimizeSourceToDependencyDirectives("#__include_macros \n", Out));
   EXPECT_STREQ("#__include_macros \n", Out.data());



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


[PATCH] D119226: [clang][lex][minimizer] Avoid treating path separators as comments

2022-02-15 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd8298f04a968: [clang][lex][minimizer] Avoid treating path 
separators as comments (authored by jansvoboda11).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119226

Files:
  clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp
  clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp


Index: clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp
===
--- clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp
+++ clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp
@@ -453,6 +453,14 @@
   ASSERT_FALSE(minimizeSourceToDependencyDirectives("#include \n", Out));
   EXPECT_STREQ("#include \n", Out.data());
 
+  ASSERT_FALSE(
+  minimizeSourceToDependencyDirectives("#include \n", Out));
+  EXPECT_STREQ("#include \n", Out.data());
+
+  ASSERT_FALSE(
+  minimizeSourceToDependencyDirectives("#include \"A//A.h\"\n", Out));
+  EXPECT_STREQ("#include \"A//A.h\"\n", Out.data());
+
   ASSERT_FALSE(
   minimizeSourceToDependencyDirectives("#include_next \n", Out));
   EXPECT_STREQ("#include_next \n", Out.data());
@@ -460,6 +468,13 @@
   ASSERT_FALSE(minimizeSourceToDependencyDirectives("#import \n", Out));
   EXPECT_STREQ("#import \n", Out.data());
 
+  ASSERT_FALSE(minimizeSourceToDependencyDirectives("#import \n", 
Out));
+  EXPECT_STREQ("#import \n", Out.data());
+
+  ASSERT_FALSE(
+  minimizeSourceToDependencyDirectives("#import \"A//A.h\"\n", Out));
+  EXPECT_STREQ("#import \"A//A.h\"\n", Out.data());
+
   ASSERT_FALSE(
   minimizeSourceToDependencyDirectives("#__include_macros \n", Out));
   EXPECT_STREQ("#__include_macros \n", Out.data());
Index: clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp
===
--- clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp
+++ clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp
@@ -401,7 +401,7 @@
 do {
   // Iterate over strings correctly to avoid comments and newlines.
   if (*Last == '"' || *Last == '\'' ||
-  (*Last == '<' && top() == pp_include)) {
+  (*Last == '<' && (top() == pp_include || top() == pp_import))) {
 if (LLVM_UNLIKELY(isRawStringLiteral(First, Last)))
   skipRawString(Last, End);
 else


Index: clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp
===
--- clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp
+++ clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp
@@ -453,6 +453,14 @@
   ASSERT_FALSE(minimizeSourceToDependencyDirectives("#include \n", Out));
   EXPECT_STREQ("#include \n", Out.data());
 
+  ASSERT_FALSE(
+  minimizeSourceToDependencyDirectives("#include \n", Out));
+  EXPECT_STREQ("#include \n", Out.data());
+
+  ASSERT_FALSE(
+  minimizeSourceToDependencyDirectives("#include \"A//A.h\"\n", Out));
+  EXPECT_STREQ("#include \"A//A.h\"\n", Out.data());
+
   ASSERT_FALSE(
   minimizeSourceToDependencyDirectives("#include_next \n", Out));
   EXPECT_STREQ("#include_next \n", Out.data());
@@ -460,6 +468,13 @@
   ASSERT_FALSE(minimizeSourceToDependencyDirectives("#import \n", Out));
   EXPECT_STREQ("#import \n", Out.data());
 
+  ASSERT_FALSE(minimizeSourceToDependencyDirectives("#import \n", Out));
+  EXPECT_STREQ("#import \n", Out.data());
+
+  ASSERT_FALSE(
+  minimizeSourceToDependencyDirectives("#import \"A//A.h\"\n", Out));
+  EXPECT_STREQ("#import \"A//A.h\"\n", Out.data());
+
   ASSERT_FALSE(
   minimizeSourceToDependencyDirectives("#__include_macros \n", Out));
   EXPECT_STREQ("#__include_macros \n", Out.data());
Index: clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp
===
--- clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp
+++ clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp
@@ -401,7 +401,7 @@
 do {
   // Iterate over strings correctly to avoid comments and newlines.
   if (*Last == '"' || *Last == '\'' ||
-  (*Last == '<' && top() == pp_include)) {
+  (*Last == '<' && (top() == pp_include || top() == pp_import))) {
 if (LLVM_UNLIKELY(isRawStringLiteral(First, Last)))
   skipRawString(Last, End);
 else
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] c6f8704 - [clang][deps] Disable global module index

2022-02-15 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2022-02-15T09:51:23+01:00
New Revision: c6f8704053ba364cf8cc9a0a966617efeda079f7

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

LOG: [clang][deps] Disable global module index

While scanning dependencies of a TU that depends on a PCH, the scanner 
basically performs mixed implicit/explicit modular compilation. (Explicit 
modules come from the PCH.) This seems to trip up the global module index.

This patch disables global module index in the dependency scanner.

Reviewed By: Bigcheese

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

Added: 


Modified: 
clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp

Removed: 




diff  --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp 
b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
index 70bb6c5caf87..9ae89e87c782 100644
--- a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -177,6 +177,9 @@ class DependencyScanningAction : public tooling::ToolAction 
{
 ScanInstance.getPreprocessorOpts().AllowPCHWithDifferentModulesCachePath =
 true;
 
+ScanInstance.getFrontendOpts().GenerateGlobalModuleIndex = false;
+ScanInstance.getFrontendOpts().UseGlobalModuleIndex = false;
+
 FileMgr->getFileSystemOpts().WorkingDir = std::string(WorkingDirectory);
 ScanInstance.setFileManager(FileMgr);
 ScanInstance.createSourceManager(*FileMgr);



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


[PATCH] D118890: [clang][deps] Disable global module index

2022-02-15 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc6f8704053ba: [clang][deps] Disable global module index 
(authored by jansvoboda11).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118890

Files:
  clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp


Index: clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
===
--- clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -177,6 +177,9 @@
 ScanInstance.getPreprocessorOpts().AllowPCHWithDifferentModulesCachePath =
 true;
 
+ScanInstance.getFrontendOpts().GenerateGlobalModuleIndex = false;
+ScanInstance.getFrontendOpts().UseGlobalModuleIndex = false;
+
 FileMgr->getFileSystemOpts().WorkingDir = std::string(WorkingDirectory);
 ScanInstance.setFileManager(FileMgr);
 ScanInstance.createSourceManager(*FileMgr);


Index: clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
===
--- clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -177,6 +177,9 @@
 ScanInstance.getPreprocessorOpts().AllowPCHWithDifferentModulesCachePath =
 true;
 
+ScanInstance.getFrontendOpts().GenerateGlobalModuleIndex = false;
+ScanInstance.getFrontendOpts().UseGlobalModuleIndex = false;
+
 FileMgr->getFileSystemOpts().WorkingDir = std::string(WorkingDirectory);
 ScanInstance.setFileManager(FileMgr);
 ScanInstance.createSourceManager(*FileMgr);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D119814: [clang-format] Honour PointerAlignment in statements with initializers.

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

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119814

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


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -8417,6 +8417,13 @@
   verifyFormat(
   "/*comment*/ switch (int *p, *q; p != q) {\n  default:\nbreak;\n}",
   Style);
+
+  verifyFormat("if ([](int* p, int* q) {}()) {\n}", Style);
+  verifyFormat("for ([](int* p, int* q) {}();;) {\n}", Style);
+  verifyFormat("for (; [](int* p, int* q) {}();) {\n}", Style);
+  verifyFormat("for (;; [](int* p, int* q) {}()) {\n}", Style);
+  verifyFormat("switch ([](int* p, int* q) {}()) {\n  default:\nbreak;\n}",
+   Style);
 }
 
 TEST_F(FormatTest, ConditionalExpressionsInBrackets) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3142,7 +3142,8 @@
 // initializers.
 if (Line.IsMultiVariableDeclStmt &&
 (Left.NestingLevel == Line.First->NestingLevel ||
- startsWithInitStatement(Line)))
+ ((Left.NestingLevel == Line.First->NestingLevel + 1) &&
+  startsWithInitStatement(Line
   return false;
 return Left.Previous && !Left.Previous->isOneOf(
 tok::l_paren, tok::coloncolon, tok::l_square);


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -8417,6 +8417,13 @@
   verifyFormat(
   "/*comment*/ switch (int *p, *q; p != q) {\n  default:\nbreak;\n}",
   Style);
+
+  verifyFormat("if ([](int* p, int* q) {}()) {\n}", Style);
+  verifyFormat("for ([](int* p, int* q) {}();;) {\n}", Style);
+  verifyFormat("for (; [](int* p, int* q) {}();) {\n}", Style);
+  verifyFormat("for (;; [](int* p, int* q) {}()) {\n}", Style);
+  verifyFormat("switch ([](int* p, int* q) {}()) {\n  default:\nbreak;\n}",
+   Style);
 }
 
 TEST_F(FormatTest, ConditionalExpressionsInBrackets) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3142,7 +3142,8 @@
 // initializers.
 if (Line.IsMultiVariableDeclStmt &&
 (Left.NestingLevel == Line.First->NestingLevel ||
- startsWithInitStatement(Line)))
+ ((Left.NestingLevel == Line.First->NestingLevel + 1) &&
+  startsWithInitStatement(Line
   return false;
 return Left.Previous && !Left.Previous->isOneOf(
 tok::l_paren, tok::coloncolon, tok::l_square);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D115844: [ubsan] Using metadata instead of prologue data for function sanitizer

2022-02-15 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen added inline comments.



Comment at: clang/lib/CodeGen/CGExpr.cpp:5171
   (!TargetDecl || !isa(TargetDecl))) {
+assert((CGM.getCodeGenOpts().CodeModel == "default" ||
+CGM.getCodeGenOpts().CodeModel == "small") &&

pcc wrote:
> What happens when building with other code models? Hopefully we get an error 
> of some sort before hitting this assertion failure, right?
> What happens when building with other code models?

The PCRel offset is 32bit currently regardless of the code model. The proxy 
variable might be out of 32-bit offset from the function (for the large model; 
for the medium model, only if the proxy variable is in `.ldata`,`.lrodata` 
which is further away), then loading some random data may give false positives. 

We could fix this by making the PCRel offset 64 bit for the medium or the large 
model. But since no one complains all these years, I guess it is a real edge 
use case.

> Hopefully we get an error of some sort before hitting this assertion failure, 
> right?

We didn't. I'll add it.




Comment at: llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp:843
+
+  // Emit the function prologue data for the indirect call sanitizer.
+  if (const MDNode *MD = F.getMetadata(LLVMContext::MD_func_sanitize)) {

pcc wrote:
> What if we have both prologue data and this metadata? Should it be an error?
It may or may not be depending on what is in the prologue data (if it just adds 
up a counter in the prologue, it should be fine?). How about clarifying this in 
Langref for this new `MD_func_sanitize`? If being conservative, we could error 
this out in the Verifier. WDYT?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115844

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


[PATCH] D115844: [ubsan] Using metadata instead of prologue data for function sanitizer

2022-02-15 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen updated this revision to Diff 408752.
ychen added a comment.
Herald added subscribers: jdoerfert, pengfei.

- check code model in driver
- document `func_sanitizer` in Langref
- add a codegen test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115844

Files:
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/Driver/SanitizerArgs.cpp
  clang/test/CodeGen/ubsan-function.cpp
  clang/test/CodeGenCXX/catch-undef-behavior.cpp
  clang/test/CodeGenCXX/ubsan-function-noexcept.cpp
  clang/test/Driver/fsanitize.c
  llvm/docs/LangRef.rst
  llvm/include/llvm/IR/FixedMetadataKinds.def
  llvm/include/llvm/IR/MDBuilder.h
  llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
  llvm/lib/IR/MDBuilder.cpp
  llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
  llvm/test/CodeGen/X86/func-sanitizer.ll

Index: llvm/test/CodeGen/X86/func-sanitizer.ll
===
--- /dev/null
+++ llvm/test/CodeGen/X86/func-sanitizer.ll
@@ -0,0 +1,18 @@
+; RUN: llc -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck %s
+
+; CHECK: _Z3funv:
+; CHECK: .cfi_startproc
+; CHECK: .long   846595819
+; CHECK: .long   .L__llvm_rtti_proxy-_Z3funv
+; CHECK: .L__llvm_rtti_proxy:
+; CHECK: .quad   i
+; CHECK: .size   .L__llvm_rtti_proxy, 8
+
+@i = linkonce_odr constant i32 1
+@__llvm_rtti_proxy = private unnamed_addr constant i32* @i
+
+define dso_local void @_Z3funv() !func_sanitize !0 {
+  ret void
+}
+
+!0 = !{i32 846595819, i32** @__llvm_rtti_proxy}
Index: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
===
--- llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -1405,7 +1405,11 @@
 /// Check if \p G has been created by a trusted compiler pass.
 static bool GlobalWasGeneratedByCompiler(GlobalVariable *G) {
   // Do not instrument @llvm.global_ctors, @llvm.used, etc.
-  if (G->getName().startswith("llvm."))
+  if (G->getName().startswith("llvm.") ||
+  // Do not instrument gcov counter arrays.
+  G->getName().startswith("__llvm_gcov_ctr") ||
+  // Do not instrument rtti proxy symbols for function sanitizer.
+  G->getName().startswith("__llvm_rtti_proxy"))
 return true;
 
   // Do not instrument asan globals.
@@ -1414,10 +1418,6 @@
   G->getName().startswith(kODRGenPrefix))
 return true;
 
-  // Do not instrument gcov counter arrays.
-  if (G->getName() == "__llvm_gcov_ctr")
-return true;
-
   return false;
 }
 
Index: llvm/lib/IR/MDBuilder.cpp
===
--- llvm/lib/IR/MDBuilder.cpp
+++ llvm/lib/IR/MDBuilder.cpp
@@ -150,6 +150,14 @@
   return MDNode::get(Context, Ops);
 }
 
+MDNode *MDBuilder::createRTTIPointerPrologue(Constant *PrologueSig,
+ Constant *RTTI) {
+  SmallVector Ops;
+  Ops.push_back(createConstant(PrologueSig));
+  Ops.push_back(createConstant(RTTI));
+  return MDNode::get(Context, Ops);
+}
+
 MDNode *MDBuilder::createAnonymousAARoot(StringRef Name, MDNode *Extra) {
   SmallVector Args(1, nullptr);
   if (Extra)
Index: llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
===
--- llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -844,6 +844,24 @@
   // Emit the prologue data.
   if (F.hasPrologueData())
 emitGlobalConstant(F.getParent()->getDataLayout(), F.getPrologueData());
+
+  // Emit the function prologue data for the indirect call sanitizer.
+  if (const MDNode *MD = F.getMetadata(LLVMContext::MD_func_sanitize)) {
+assert(TM.getTargetTriple().getArch() == Triple::x86 ||
+   TM.getTargetTriple().getArch() == Triple::x86_64);
+assert(MD->getNumOperands() == 2);
+
+auto *PrologueSig = mdconst::extract(MD->getOperand(0));
+auto *FTRTTIProxy = mdconst::extract(MD->getOperand(1));
+assert(PrologueSig && FTRTTIProxy);
+emitGlobalConstant(F.getParent()->getDataLayout(), PrologueSig);
+
+const MCExpr *Proxy = lowerConstant(FTRTTIProxy);
+const MCExpr *FnExp = MCSymbolRefExpr::create(CurrentFnSym, OutContext);
+const MCExpr *PCRel = MCBinaryExpr::createSub(Proxy, FnExp, OutContext);
+// Use 32 bit since only small code model is supported.
+OutStreamer->emitValue(PCRel, 4u);
+  }
 }
 
 /// EmitFunctionEntryLabel - Emit the label that is the entrypoint for the
Index: llvm/include/llvm/IR/MDBuilder.h
===
--- llvm/include/llvm/IR/MDBuilder.h
+++ llvm/include/llvm/IR/MDBuilder.h
@@ -108,6 +108,10 @@
   /// Merge the new callback encoding \p NewCB into \p ExistingCallbacks.
   M

[PATCH] D119716: [clang][lex] NFC: De-duplicate some #include_next logic

2022-02-15 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa081a0654f35: [clang][lex] NFC: De-duplicate some 
#include_next logic (authored by jansvoboda11).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119716

Files:
  clang/include/clang/Lex/Preprocessor.h
  clang/lib/Lex/PPDirectives.cpp
  clang/lib/Lex/PPMacroExpansion.cpp

Index: clang/lib/Lex/PPMacroExpansion.cpp
===
--- clang/lib/Lex/PPMacroExpansion.cpp
+++ clang/lib/Lex/PPMacroExpansion.cpp
@@ -1249,32 +1249,9 @@
 }
 
 bool Preprocessor::EvaluateHasIncludeNext(Token &Tok, IdentifierInfo *II) {
-  // __has_include_next is like __has_include, except that we start
-  // searching after the current found directory.  If we can't do this,
-  // issue a diagnostic.
-  // FIXME: Factor out duplication with
-  // Preprocessor::HandleIncludeNextDirective.
-  const DirectoryLookup *Lookup = CurDirLookup;
-  const FileEntry *LookupFromFile = nullptr;
-  if (isInPrimaryFile() && getLangOpts().IsHeaderFile) {
-// If the main file is a header, then it's either for PCH/AST generation,
-// or libclang opened it. Either way, handle it as a normal include below
-// and do not complain about __has_include_next.
-  } else if (isInPrimaryFile()) {
-Lookup = nullptr;
-Diag(Tok, diag::pp_include_next_in_primary);
-  } else if (getCurrentLexerSubmodule()) {
-// Start looking up in the directory *after* the one in which the current
-// file would be found, if any.
-assert(getCurrentLexer() && "#include_next directive in macro?");
-LookupFromFile = getCurrentLexer()->getFileEntry();
-Lookup = nullptr;
-  } else if (!Lookup) {
-Diag(Tok, diag::pp_include_next_absolute_path);
-  } else {
-// Start looking up in the next directory.
-++Lookup;
-  }
+  const DirectoryLookup *Lookup;
+  const FileEntry *LookupFromFile;
+  std::tie(Lookup, LookupFromFile) = getIncludeNextStart(Tok);
 
   return EvaluateHasIncludeCommon(Tok, II, *this, Lookup, LookupFromFile);
 }
Index: clang/lib/Lex/PPDirectives.cpp
===
--- clang/lib/Lex/PPDirectives.cpp
+++ clang/lib/Lex/PPDirectives.cpp
@@ -1778,6 +1778,41 @@
   return true;
 }
 
+std::pair
+Preprocessor::getIncludeNextStart(const Token &IncludeNextTok) const {
+  // #include_next is like #include, except that we start searching after
+  // the current found directory.  If we can't do this, issue a
+  // diagnostic.
+  const DirectoryLookup *Lookup = CurDirLookup;
+  const FileEntry *LookupFromFile = nullptr;
+
+  if (isInPrimaryFile() && LangOpts.IsHeaderFile) {
+// If the main file is a header, then it's either for PCH/AST generation,
+// or libclang opened it. Either way, handle it as a normal include below
+// and do not complain about include_next.
+  } else if (isInPrimaryFile()) {
+Lookup = nullptr;
+Diag(IncludeNextTok, diag::pp_include_next_in_primary);
+  } else if (CurLexerSubmodule) {
+// Start looking up in the directory *after* the one in which the current
+// file would be found, if any.
+assert(CurPPLexer && "#include_next directive in macro?");
+LookupFromFile = CurPPLexer->getFileEntry();
+Lookup = nullptr;
+  } else if (!Lookup) {
+// The current file was not found by walking the include path. Either it
+// is the primary file (handled above), or it was found by absolute path,
+// or it was found relative to such a file.
+// FIXME: Track enough information so we know which case we're in.
+Diag(IncludeNextTok, diag::pp_include_next_absolute_path);
+  } else {
+// Start looking up in the next directory.
+++Lookup;
+  }
+
+  return {Lookup, LookupFromFile};
+}
+
 /// HandleIncludeDirective - The "\#include" tokens have just been read, read
 /// the file to be included from the lexer, then include it!  This is a common
 /// routine with functionality shared between \#include, \#include_next and
@@ -2375,34 +2410,9 @@
   Token &IncludeNextTok) {
   Diag(IncludeNextTok, diag::ext_pp_include_next_directive);
 
-  // #include_next is like #include, except that we start searching after
-  // the current found directory.  If we can't do this, issue a
-  // diagnostic.
-  const DirectoryLookup *Lookup = CurDirLookup;
-  const FileEntry *LookupFromFile = nullptr;
-  if (isInPrimaryFile() && LangOpts.IsHeaderFile) {
-// If the main file is a header, then it's either for PCH/AST generation,
-// or libclang opened it. Either way, handle it as a normal include below
-// and do not complain about include_next.
-  } else if (isInPrimaryFile()) {
-Lookup = nullptr;
-Diag(IncludeNextTok, diag::pp_include_next_in_primary);
-  } else if (CurLexerSubmodule) {
-// Start looking up in the directory *after* the one in whic

[clang] a081a06 - [clang][lex] NFC: De-duplicate some #include_next logic

2022-02-15 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2022-02-15T09:52:39+01:00
New Revision: a081a0654f35c12ddc2afc072110098404434b6c

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

LOG: [clang][lex] NFC: De-duplicate some #include_next logic

This patch addresses a FIXME and de-duplicates some `#include_next` logic

Depends on D119714.

Reviewed By: ahoppen

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

Added: 


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

Removed: 




diff  --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index dbe6aa949a75..e0a07a850062 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -2200,6 +2200,10 @@ class Preprocessor {
   /// Returns true if successful.
   bool EvaluateHasIncludeNext(Token &Tok, IdentifierInfo *II);
 
+  /// Get the directory and file from which to start \#include_next lookup.
+  std::pair
+  getIncludeNextStart(const Token &IncludeNextTok) const;
+
   /// Install the standard preprocessor pragmas:
   /// \#pragma GCC poison/system_header/dependency and \#pragma once.
   void RegisterBuiltinPragmas();

diff  --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index a7201490e4b1..2e2cdfe3165b 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -1778,6 +1778,41 @@ bool Preprocessor::checkModuleIsAvailable(const 
LangOptions &LangOpts,
   return true;
 }
 
+std::pair
+Preprocessor::getIncludeNextStart(const Token &IncludeNextTok) const {
+  // #include_next is like #include, except that we start searching after
+  // the current found directory.  If we can't do this, issue a
+  // diagnostic.
+  const DirectoryLookup *Lookup = CurDirLookup;
+  const FileEntry *LookupFromFile = nullptr;
+
+  if (isInPrimaryFile() && LangOpts.IsHeaderFile) {
+// If the main file is a header, then it's either for PCH/AST generation,
+// or libclang opened it. Either way, handle it as a normal include below
+// and do not complain about include_next.
+  } else if (isInPrimaryFile()) {
+Lookup = nullptr;
+Diag(IncludeNextTok, diag::pp_include_next_in_primary);
+  } else if (CurLexerSubmodule) {
+// Start looking up in the directory *after* the one in which the current
+// file would be found, if any.
+assert(CurPPLexer && "#include_next directive in macro?");
+LookupFromFile = CurPPLexer->getFileEntry();
+Lookup = nullptr;
+  } else if (!Lookup) {
+// The current file was not found by walking the include path. Either it
+// is the primary file (handled above), or it was found by absolute path,
+// or it was found relative to such a file.
+// FIXME: Track enough information so we know which case we're in.
+Diag(IncludeNextTok, diag::pp_include_next_absolute_path);
+  } else {
+// Start looking up in the next directory.
+++Lookup;
+  }
+
+  return {Lookup, LookupFromFile};
+}
+
 /// HandleIncludeDirective - The "\#include" tokens have just been read, read
 /// the file to be included from the lexer, then include it!  This is a common
 /// routine with functionality shared between \#include, \#include_next and
@@ -2375,34 +2410,9 @@ void 
Preprocessor::HandleIncludeNextDirective(SourceLocation HashLoc,
   Token &IncludeNextTok) {
   Diag(IncludeNextTok, diag::ext_pp_include_next_directive);
 
-  // #include_next is like #include, except that we start searching after
-  // the current found directory.  If we can't do this, issue a
-  // diagnostic.
-  const DirectoryLookup *Lookup = CurDirLookup;
-  const FileEntry *LookupFromFile = nullptr;
-  if (isInPrimaryFile() && LangOpts.IsHeaderFile) {
-// If the main file is a header, then it's either for PCH/AST generation,
-// or libclang opened it. Either way, handle it as a normal include below
-// and do not complain about include_next.
-  } else if (isInPrimaryFile()) {
-Lookup = nullptr;
-Diag(IncludeNextTok, diag::pp_include_next_in_primary);
-  } else if (CurLexerSubmodule) {
-// Start looking up in the directory *after* the one in which the current
-// file would be found, if any.
-assert(CurPPLexer && "#include_next directive in macro?");
-LookupFromFile = CurPPLexer->getFileEntry();
-Lookup = nullptr;
-  } else if (!Lookup) {
-// The current file was not found by walking the include path. Either it
-// is the primary file (handled above), or it was found by absolute path,
-// or it was found relative to such a file.
-// FIXME: Track enough information so we know which case we're in.
-Diag(IncludeNextTok, diag::pp_include_next_absolute

[PATCH] D119682: [clang-format][docs] Fix incorrect 'clang-format 13' configuration options markers

2022-02-15 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added a comment.

In D119682#3321975 , @MyDeveloperDay 
wrote:

> I understand what you are saying re 'IndentRequiresClause' but this leaves us 
> with people with "IndentRequires" in their .clang-format without any 
> understanding of what it means? i.e. what about the 14.0 people? if we've 
> renamed an option then the documentation should carry something like
>
> 'Previously known as IndentRequires'

That's not the first time we renamed something. And most likely not the last 
time.




Comment at: clang/include/clang/Format/Format.h:2540-2541
   ///}
   /// \endcode
-  /// \version 13
+  /// \version 15
   bool IndentRequiresClause;




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119682

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


[PATCH] D119814: [clang-format] Honour PointerAlignment in statements with initializers.

2022-02-15 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks accepted this revision.
HazardyKnusperkeks added a comment.

Creating your own bug and fixing it within 10 minutes. Nice. ;)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119814

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


[PATCH] D119816: Fix not working attribute no_sanitize bounds that affects linux kernel

2022-02-15 Thread Tong Zhang via Phabricator via cfe-commits
ztong0001 created this revision.
Herald added subscribers: ormris, dexonsmith, jdoerfert, steven_wu, hiraditya.
ztong0001 requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

Adding __attribute__((no_sanitize("bounds"))) is not really disabling bounds 
checking, i.e. disable -fsanitize=array-bounds -fsanitize=local-bounds.  or 
-fsanitize=bounds.
We have a potential user in Linux kennel which is currently affected by 
-fsanitize=local-bounds.

Linux kernel(5.17) has a function pskb_expand_head (net/core/skbuff.c) 
currently experiencing false positive when CONFIG_UBSAN_LOCAL_BOUNDS is enabled 
(i.e. supply -fsanitize=array-bounds -fsanitize=local-bounds).

The aforementioned function does the following which will create a false 
positive.

  char* p = kmalloc(M); // allocate buffer, size is M
  int actual_size = ksize(p); // return actual allocated size in the slab 
allocator, this will guaranteed to be larger than M + N
  p[actual_size - N+1] = 0; //Out of bound access

LLVM assume the size of the buffer is M, thus the later p[actual_size-N+1] 
access will be treated as out of bound access.
However, this function deliberately use the actual allocated size instead of M.
Kernel will be unhappy as bounds check fail and it crash hard with the 
following message:

[0.060423] PTP clock support registered
[0.060820] invalid opcode:  [#1] PREEMPT SMP NOPTI
[0.061232] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 
5.17.0-rc3-00247-g83e396641110-dirty #102
[0.061418] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 
1.13.0-1ubuntu1.1 04/01/2014
[0.061418] RIP: 0010:pskb_expand_head+0x38b/0x3b0
[0.061418] Code: 84 fc fd ff ff be 01 00 00 00 b8 01 00 00 00 3e 0f c1 47 
18 85 c0 74 14 8d 48 01 0
9 c1 0f 89 de fd ff ff eb 0c 67 0f b9 40 12 <0f> 0b be 02 00 00 00 48 83 c7 18 
e8 25 b7 cc ff e9 c2 fd
ff ff 0f
[0.061418] RSP: 0018:c900bb60 EFLAGS: 00010287
[0.061418] RAX: 06c0 RBX: 888002e92000 RCX: 
[0.061418] RDX: 06c0 RSI: 888002cebef0 RDI: 0002c800
[0.061418] RBP: 888002cebec0 R08: 888002ceb000 R09: 8174ed1f
[0.061418] R10 : 
ea0b3a00 R11 : 
 R12 : 888002ceb000
[0.061418] R13 :  
R14 : 00012a20 R15 
: 888002e0f000
[0.061418] FS:  () GS:88803ec0() 
knlGS:
[0.061418] CS:  0010 DS:  ES:  CR0: 80050033
[0.061418] CR2: 888002a01000 CR3: 0220c000 CR4: 00350ef0
[0.061418] Call Trace:
[0.061418]  
[0.061418]  netlink_trim+0x83/0xa0
[0.061418]  netlink_broadcast+0x2a/0x5a0
[0.061418]  ? nla_put+0x72/0x90
[0.061418]  genlmsg_multicast_allns+0xcc/0x120
[0.061418]  genl_ctrl_event+0x219/0x370
[0.061418]  genl_register_family+0x5b8/0x660
[0.061418]  ? rtnl_register_internal+0x14d/0x180
[0.061418]  ? tca_get_fill+0x120/0x120
[0.061418]  ? tc_ctl_action+0x5b0/0x5b0
[0.061418]  ? genl_init+0x31/0x31
[0.061418]  ethnl_init+0xd/0x50
[0.061418]  do_one_initcall+0xa5/0x290
[0.061418]  ? alloc_page_interleave+0x5e/0x80
[0.061418]  ? preempt_count_add+0x5e/0xa0
[0.061418]  ? ida_alloc_range+0x3fc/0x440
[0.061418]  ? parse_args+0x254/0x390
[0.061418]  do_initcall_level+0xb4/0x131
[0.061418]  do_initcalls+0x44/0x6b
[0.061418]  kernel_init_freeable+0xd8/0x138
[0.061418]  ? rest_init+0xc0/0xc0
[0.061418]  kernel_init+0x11/0x1a0
[0.061418]  ret_from_fork+0x1f/0x30

The solution here is to add __attribute__((no_sanitize("bounds"))) to this 
function to avoid local bounds checking altogether.

This patch adds __attribute__((no_sanitize("bounds"))) support to LLVM, and in 
linux kernel, we will add this attribute to the function definition.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119816

Files:
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/test/CodeGen/sanitize-coverage.c
  llvm/include/llvm/AsmParser/LLToken.h
  llvm/include/llvm/Bitcode/LLVMBitCodes.h
  llvm/include/llvm/IR/Attributes.td
  llvm/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/Transforms/Instrumentation/BoundsChecking.cpp
  llvm/lib/Transforms/Utils/CodeExtractor.cpp

Index: llvm/lib/Transforms/Utils/CodeExtractor.cpp
===
--- llvm/lib/Transforms/Utils/CodeExtractor.cpp
+++ llvm/lib/Transforms/Utils/CodeExtractor.cpp
@@ -938,6 +938,7 @@
   case Attribute::NonLazyBind:
   case Attribute::NoRedZone:
   case Attribute::NoUnwind:
+  case

[PATCH] D117087: [C++20] [Coroutines] Implement return value optimization for get_return_object

2022-02-15 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu updated this revision to Diff 408761.
ChuanqiXu added a comment.

Update test.


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

https://reviews.llvm.org/D117087

Files:
  clang/include/clang/AST/StmtCXX.h
  clang/lib/AST/StmtCXX.cpp
  clang/lib/CodeGen/CGCoroutine.cpp
  clang/lib/Sema/SemaCoroutine.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/CodeGenCoroutines/coro-alloc-exp-namespace.cpp
  clang/test/CodeGenCoroutines/coro-alloc.cpp
  clang/test/CodeGenCoroutines/coro-gro-exp-namespace.cpp
  clang/test/CodeGenCoroutines/coro-gro-nrvo-exp-namespace.cpp
  clang/test/CodeGenCoroutines/coro-gro-nrvo.cpp
  clang/test/CodeGenCoroutines/coro-gro.cpp
  clang/test/CodeGenCoroutines/coro-gro2-exp-namespace.cpp
  clang/test/CodeGenCoroutines/coro-gro2.cpp
  clang/test/CodeGenCoroutines/coro-promise-dtor-exp-namespace.cpp
  clang/test/CodeGenCoroutines/coro-promise-dtor.cpp
  clang/test/SemaCXX/coroutine-no-move-ctor.cpp
  clang/test/SemaCXX/coroutines-exp-namespace.cpp
  clang/test/SemaCXX/coroutines.cpp

Index: clang/test/SemaCXX/coroutines.cpp
===
--- clang/test/SemaCXX/coroutines.cpp
+++ clang/test/SemaCXX/coroutines.cpp
@@ -929,7 +929,7 @@
 
 extern "C" int f(mismatch_gro_type_tag2) {
   // cxx2b-error@-1 {{cannot initialize return object of type 'int' with an rvalue of type 'void *'}}
-  // cxx14_20-error@-2 {{cannot initialize return object of type 'int' with an lvalue of type 'void *'}}
+  // cxx14_20-error@-2 {{cannot initialize return object of type 'int' with an rvalue of type 'void *'}}
   co_return; //expected-note {{function is a coroutine due to use of 'co_return' here}}
 }
 
Index: clang/test/SemaCXX/coroutines-exp-namespace.cpp
===
--- clang/test/SemaCXX/coroutines-exp-namespace.cpp
+++ clang/test/SemaCXX/coroutines-exp-namespace.cpp
@@ -939,7 +939,7 @@
 
 extern "C" int f(mismatch_gro_type_tag2) {
   // cxx2b-error@-1 {{cannot initialize return object of type 'int' with an rvalue of type 'void *'}}
-  // cxx14_20-error@-2 {{cannot initialize return object of type 'int' with an lvalue of type 'void *'}}
+  // cxx14_20-error@-2 {{cannot initialize return object of type 'int' with an rvalue of type 'void *'}}
   co_return; //expected-note {{function is a coroutine due to use of 'co_return' here}}
 }
 
Index: clang/test/SemaCXX/coroutine-no-move-ctor.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/coroutine-no-move-ctor.cpp
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -std=c++20 -fsyntax-only -verify
+// expected-no-diagnostics
+
+#include "Inputs/std-coroutine.h"
+
+class invoker {
+public:
+  class invoker_promise {
+  public:
+invoker get_return_object() { return invoker{}; }
+auto initial_suspend() { return std::suspend_never{}; }
+auto final_suspend() noexcept { return std::suspend_never{}; }
+void return_void() {}
+void unhandled_exception() {}
+  };
+  using promise_type = invoker_promise;
+  invoker() {}
+  invoker(const invoker &) = delete;
+  invoker &operator=(const invoker &) = delete;
+  invoker(invoker &&) = delete;
+  invoker &operator=(invoker &&) = delete;
+};
+
+invoker f() {
+  co_return;
+}
Index: clang/test/CodeGenCoroutines/coro-promise-dtor.cpp
===
--- clang/test/CodeGenCoroutines/coro-promise-dtor.cpp
+++ clang/test/CodeGenCoroutines/coro-promise-dtor.cpp
@@ -27,19 +27,8 @@
 }
 
 // CHECK-LABEL: define dso_local void @"?f@@YA?AUcoro_t@@XZ"(
-// CHECK:  %gro.active = alloca i1
-// CHECK:  store i1 false, i1* %gro.active
 
 // CHECK:  invoke noundef %"struct.coro_t::promise_type"* @"??0promise_type@coro_t@@QEAA@XZ"(
 // CHECK:  invoke void @"?get_return_object@promise_type@coro_t@@QEAA?AU2@XZ"(
-// CHECK:  store i1 true, i1* %gro.active
 
-// CHECK:  %[[IS_ACTIVE:.+]] = load i1, i1* %gro.active
-// CHECK:  br i1 %[[IS_ACTIVE]], label %[[CLEANUP1:.+]], label
-
-// CHECK: [[CLEANUP1]]:
-// CHECK:  %[[NRVO:.+]] = load i1, i1* %nrvo
-// CHECK:  br i1 %[[NRVO]], label %{{.+}}, label %[[DTOR:.+]]
-
-// CHECK: [[DTOR]]:
-// CHECK:  call void @"??1coro_t@@QEAA@XZ"(
+// CHECK:  call void @"??1promise_type@coro_t@@QEAA@XZ"
Index: clang/test/CodeGenCoroutines/coro-promise-dtor-exp-namespace.cpp
===
--- clang/test/CodeGenCoroutines/coro-promise-dtor-exp-namespace.cpp
+++ clang/test/CodeGenCoroutines/coro-promise-dtor-exp-namespace.cpp
@@ -31,19 +31,8 @@
 }
 
 // CHECK-LABEL: define dso_local void @"?f@@YA?AUcoro_t@@XZ"(
-// CHECK:  %gro.active = alloca i1
-// CHECK:  store i1 false, i1* %gro.active
 
 // CHECK:  invoke noundef %"struct.coro_t::promise_type"* @"??0promise_type@coro_t@@QEAA@XZ"(
 // CHECK:  invoke void @"?get_return_object@promise_type@coro_t@@QEAA?AU2@XZ"(
-// CHECK:  store i1 true, i1* %g

[PATCH] D117087: [C++20] [Coroutines] Implement return value optimization for get_return_object

2022-02-15 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added inline comments.



Comment at: clang/lib/CodeGen/CGCoroutine.cpp:650
 
-  if (Stmt *Ret = S.getReturnStmt())
+  if (Stmt *Ret = S.getReturnStmt()) {
+// Since we already emitted the return value above, so we shouldn't

junparser wrote:
> can we just remove this?
We couldn't. Otherwise it would emit the return expression again.


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

https://reviews.llvm.org/D117087

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


[PATCH] D119719: [Docs][OpenCL] Update OpenCL 3.0 status on release 14

2022-02-15 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added inline comments.



Comment at: clang/docs/OpenCLSupport.rst:395
++--+-+-+--++
+| Feature optionality  | Blocks and Device-side kernel enqueue 
including builtin functions | :part:`worked on`| 
https://reviews.llvm.org/D115640, https://reviews.llvm.org/D118605  
   |
++--+-+-+--++

These two patches are merged. So can blocks and DSE be considered as done?



Comment at: clang/docs/OpenCLSupport.rst:407
++--+-+-+--++
+| New functionality| Subgroup functions
| :part:`worked on`| https://reviews.llvm.org/D105858, 
https://reviews.llvm.org/D118999
 |
++--+-+-+--++

Can this be considered as done as well? These patches were merged as well.


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

https://reviews.llvm.org/D119719

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


[clang] 7631c36 - [clang][lex] Introduce `ConstSearchDirIterator`

2022-02-15 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2022-02-15T10:36:54+01:00
New Revision: 7631c366c8589dda488cb7ff1df26cc134002208

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

LOG: [clang][lex] Introduce `ConstSearchDirIterator`

The `const DirectoryLookup *` out-parameter of 
`{HeaderSearch,Preprocessor}::LookupFile()` is assigned the most recently used 
search directory, which callers use to implement `#include_next`.

>From the function signature it's not obvious the `const DirectoryLookup *` is 
>being used as an iterator. This patch introduces `ConstSearchDirIterator` to 
>make that affordance obvious. This would've prevented a bug that occurred 
>after initially landing D116750.

Reviewed By: ahoppen

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

Added: 


Modified: 
clang/include/clang/Lex/HeaderSearch.h
clang/include/clang/Lex/Preprocessor.h
clang/lib/Lex/HeaderSearch.cpp
clang/lib/Lex/PPDirectives.cpp
clang/lib/Lex/PPLexerChange.cpp
clang/lib/Lex/PPMacroExpansion.cpp

Removed: 




diff  --git a/clang/include/clang/Lex/HeaderSearch.h 
b/clang/include/clang/Lex/HeaderSearch.h
index 74768717470b..b5b856542db6 100644
--- a/clang/include/clang/Lex/HeaderSearch.h
+++ b/clang/include/clang/Lex/HeaderSearch.h
@@ -47,6 +47,7 @@ class DirectoryEntry;
 class ExternalPreprocessorSource;
 class FileEntry;
 class FileManager;
+class HeaderSearch;
 class HeaderSearchOptions;
 class IdentifierInfo;
 class LangOptions;
@@ -162,11 +163,55 @@ struct FrameworkCacheEntry {
   bool IsUserSpecifiedSystemFramework;
 };
 
+/// Forward iterator over the search directories of \c HeaderSearch.
+struct ConstSearchDirIterator
+: llvm::iterator_facade_base {
+  ConstSearchDirIterator(const ConstSearchDirIterator &) = default;
+
+  ConstSearchDirIterator &operator=(const ConstSearchDirIterator &) = default;
+
+  bool operator==(const ConstSearchDirIterator &RHS) const {
+return HS == RHS.HS && Idx == RHS.Idx;
+  }
+
+  ConstSearchDirIterator &operator++() {
+assert(*this && "Invalid iterator.");
+++Idx;
+return *this;
+  }
+
+  const DirectoryLookup &operator*() const;
+
+  /// Creates an invalid iterator.
+  ConstSearchDirIterator(std::nullptr_t) : HS(nullptr), Idx(0) {}
+
+  /// Checks whether the iterator is valid.
+  explicit operator bool() const { return HS != nullptr; }
+
+private:
+  /// The parent \c HeaderSearch. This is \c nullptr for invalid iterator.
+  const HeaderSearch *HS;
+
+  /// The index of the current element.
+  size_t Idx;
+
+  /// The constructor that creates a valid iterator.
+  ConstSearchDirIterator(const HeaderSearch &HS, size_t Idx)
+  : HS(&HS), Idx(Idx) {}
+
+  /// Only HeaderSearch is allowed to instantiate valid iterators.
+  friend HeaderSearch;
+};
+
 /// Encapsulates the information needed to find the file referenced
 /// by a \#include or \#include_next, (sub-)framework lookup, etc.
 class HeaderSearch {
   friend class DirectoryLookup;
 
+  friend ConstSearchDirIterator;
+
   /// Header-search options used to initialize this header search.
   std::shared_ptr HSOpts;
 
@@ -407,7 +452,7 @@ class HeaderSearch {
   /// found.
   Optional LookupFile(
   StringRef Filename, SourceLocation IncludeLoc, bool isAngled,
-  const DirectoryLookup *FromDir, const DirectoryLookup **CurDir,
+  ConstSearchDirIterator FromDir, ConstSearchDirIterator *CurDir,
   ArrayRef> Includers,
   SmallVectorImpl *SearchPath, SmallVectorImpl *RelativePath,
   Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule,
@@ -731,35 +776,26 @@ class HeaderSearch {
   const HeaderFileInfo *getExistingFileInfo(const FileEntry *FE,
 bool WantExternal = true) const;
 
-  // Used by external tools
-  using search_dir_iterator = std::vector::const_iterator;
+  ConstSearchDirIterator search_dir_begin() const { return quoted_dir_begin(); 
}
+  ConstSearchDirIterator search_dir_end() const { return system_dir_end(); }
 
-  search_dir_iterator search_dir_begin() const { return SearchDirs.begin(); }
-  search_dir_iterator search_dir_end() const { return SearchDirs.end(); }
   unsigned search_dir_size() const { return SearchDirs.size(); }
 
-  search_dir_iterator quoted_dir_begin() const {
-return SearchDirs.begin();
-  }
+  ConstSearchDirIterator quoted_dir_begin() const { return {*this, 0}; }
+  ConstSearchDirIterator quoted_dir_end() const { return angled_dir_begin(); }
 
-  search_dir_iterator quoted_dir_end() const {
-return SearchDirs.begin() + AngledDirIdx;
+  ConstSearchDirIterator angled_dir_begin() const {
+return {*this, AngledDirIdx};
   }
+  ConstSearchDirIterator angled_dir_end() const { return system_dir_begin(); }
 
-  search_dir_iterator angled_dir_begin() const {
-

[PATCH] D117566: [clang][lex] Introduce `ConstSearchDirIterator`

2022-02-15 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7631c366c858: [clang][lex] Introduce 
`ConstSearchDirIterator` (authored by jansvoboda11).

Changed prior to commit:
  https://reviews.llvm.org/D117566?vs=408411&id=408767#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117566

Files:
  clang/include/clang/Lex/HeaderSearch.h
  clang/include/clang/Lex/Preprocessor.h
  clang/lib/Lex/HeaderSearch.cpp
  clang/lib/Lex/PPDirectives.cpp
  clang/lib/Lex/PPLexerChange.cpp
  clang/lib/Lex/PPMacroExpansion.cpp

Index: clang/lib/Lex/PPMacroExpansion.cpp
===
--- clang/lib/Lex/PPMacroExpansion.cpp
+++ clang/lib/Lex/PPMacroExpansion.cpp
@@ -1157,9 +1157,9 @@
 /// EvaluateHasIncludeCommon - Process a '__has_include("path")'
 /// or '__has_include_next("path")' expression.
 /// Returns true if successful.
-static bool EvaluateHasIncludeCommon(Token &Tok,
- IdentifierInfo *II, Preprocessor &PP,
- const DirectoryLookup *LookupFrom,
+static bool EvaluateHasIncludeCommon(Token &Tok, IdentifierInfo *II,
+ Preprocessor &PP,
+ ConstSearchDirIterator LookupFrom,
  const FileEntry *LookupFromFile) {
   // Save the location of the current token.  If a '(' is later found, use
   // that location.  If not, use the end of this location instead.
@@ -1249,7 +1249,7 @@
 }
 
 bool Preprocessor::EvaluateHasIncludeNext(Token &Tok, IdentifierInfo *II) {
-  const DirectoryLookup *Lookup;
+  ConstSearchDirIterator Lookup = nullptr;
   const FileEntry *LookupFromFile;
   std::tie(Lookup, LookupFromFile) = getIncludeNextStart(Tok);
 
Index: clang/lib/Lex/PPLexerChange.cpp
===
--- clang/lib/Lex/PPLexerChange.cpp
+++ clang/lib/Lex/PPLexerChange.cpp
@@ -66,7 +66,7 @@
 
 /// EnterSourceFile - Add a source file to the top of the include stack and
 /// start lexing tokens from it instead of the current buffer.
-bool Preprocessor::EnterSourceFile(FileID FID, const DirectoryLookup *CurDir,
+bool Preprocessor::EnterSourceFile(FileID FID, ConstSearchDirIterator CurDir,
SourceLocation Loc,
bool IsFirstIncludeOfFile) {
   assert(!CurTokenLexer && "Cannot #include a file inside a macro!");
@@ -100,7 +100,7 @@
 /// EnterSourceFileWithLexer - Add a source file to the top of the include stack
 ///  and start lexing tokens from it instead of the current buffer.
 void Preprocessor::EnterSourceFileWithLexer(Lexer *TheLexer,
-const DirectoryLookup *CurDir) {
+ConstSearchDirIterator CurDir) {
 
   // Add the current lexer to the include stack.
   if (CurPPLexer || CurTokenLexer)
Index: clang/lib/Lex/PPDirectives.cpp
===
--- clang/lib/Lex/PPDirectives.cpp
+++ clang/lib/Lex/PPDirectives.cpp
@@ -817,13 +817,13 @@
 
 Optional Preprocessor::LookupFile(
 SourceLocation FilenameLoc, StringRef Filename, bool isAngled,
-const DirectoryLookup *FromDir, const FileEntry *FromFile,
-const DirectoryLookup **CurDirArg, SmallVectorImpl *SearchPath,
+ConstSearchDirIterator FromDir, const FileEntry *FromFile,
+ConstSearchDirIterator *CurDirArg, SmallVectorImpl *SearchPath,
 SmallVectorImpl *RelativePath,
 ModuleMap::KnownHeader *SuggestedModule, bool *IsMapped,
 bool *IsFrameworkFound, bool SkipCache) {
-  const DirectoryLookup *CurDirLocal = nullptr;
-  const DirectoryLookup *&CurDir = CurDirArg ? *CurDirArg : CurDirLocal;
+  ConstSearchDirIterator CurDirLocal = nullptr;
+  ConstSearchDirIterator &CurDir = CurDirArg ? *CurDirArg : CurDirLocal;
 
   Module *RequestingModule = getModuleForLocation(FilenameLoc);
   bool RequestingModuleIsModuleInterface = !SourceMgr.isInMainFile(FilenameLoc);
@@ -877,8 +877,8 @@
   if (FromFile) {
 // We're supposed to start looking from after a particular file. Search
 // the include path until we find that file or run out of files.
-const DirectoryLookup *TmpCurDir = CurDir;
-const DirectoryLookup *TmpFromDir = nullptr;
+ConstSearchDirIterator TmpCurDir = CurDir;
+ConstSearchDirIterator TmpFromDir = nullptr;
 while (Optional FE = HeaderInfo.LookupFile(
Filename, FilenameLoc, isAngled, TmpFromDir, &TmpCurDir,
Includers, SearchPath, RelativePath, RequestingModule,
@@ -1778,12 +1778,12 @@
   return true;
 }
 
-std::pair
+std::pair
 Preprocessor::getIncludeNextStart(const Token &IncludeNextTok) const {
   // #include_next is like #include, except that we start

[PATCH] D119788: [AArch64] Add support for -march=native for Apple M1 CPU

2022-02-15 Thread Tim Northover via Phabricator via cfe-commits
t.p.northover added a comment.

Things have moved on since the ARM and (especially) PPC variants of that 
function were written. That field (despite the name) is now more of an ABI tag 
and not going to be updated with each CPU.

I think the modern replacement for it is `hw.cpufamily` obtained from `sysctl` 
(command line or `man 3 sysctl` for programmatically). The potential values 
(`CPUFAMILY_ARM_*` starting with Cyclone) are listed in  
https://opensource.apple.com/source/xnu/xnu-4570.41.2/osfmk/mach/machine.h.auto.html
 (which should be in the SDK under `mach/machine.h`). It warns against 
inferring features from this, which is exactly what we'd be doing, but still 
probably has a better chance of being right long term.

I'd probably default to the latest known one rather than earliest too, since an 
unknown family is more likely to be new than old.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119788

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


[PATCH] D119788: [AArch64] Add support for -march=native for Apple M1 CPU

2022-02-15 Thread Tim Northover via Phabricator via cfe-commits
t.p.northover added a comment.

Sorry, that was an old xnu version, the newest one is 
https://opensource.apple.com/source/xnu/xnu-7195.81.3/osfmk/mach/machine.h.auto.html
 which has

| `CPUFAMILY_ARM_CYCLONE`| 0x37a09642 | `apple-a7`  
 |
| `CPUFAMILY_ARM_TYPHOON`| 0x2c91a47e | `apple-a8`  
 |
| `CPUFAMILY_ARM_TWISTER`| 0x92fb37c8 | `apple-a9`  
 |
| `CPUFAMILY_ARM_HURRICANE`  | 0x67ceee93 | `apple-a10` 
 |
| `CPUFAMILY_ARM_MONSOON_MISTRAL`| 0xe81e7ef6 | `apple-a11` 
 |
| `CPUFAMILY_ARM_VORTEX_TEMPEST` | 0x07d34b9f | `apple-a12` 
 |
| `CPUFAMILY_ARM_LIGHTNING_THUNDER`  | 0x462504d2 | `apple-a13` 
 |
| `CPUFAMILY_ARM_FIRESTORM_ICESTORM` | 0x1b588bb3 | `apple-m1` (and 
`apple-a14`) |
|

We'll probably have to hard-code most of those because we need LLVM to be 
buildable on much older versions of Xcode that don't know about newer CPUs 
(likely Xcode 9.3 soon, but now older even than that).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119788

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


[clang] 17c9fcd - [clang][lex] Use `ConstSearchDirIterator` in lookup cache

2022-02-15 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2022-02-15T10:39:05+01:00
New Revision: 17c9fcd6f6fc0926c1096242a2ddced9b523decd

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

LOG: [clang][lex] Use `ConstSearchDirIterator` in lookup cache

This patch starts using the new iterator type in `LookupFileCacheInfo`.

Depends on D117566.

Reviewed By: ahoppen

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

Added: 


Modified: 
clang/include/clang/Lex/HeaderSearch.h
clang/lib/Lex/HeaderSearch.cpp

Removed: 




diff  --git a/clang/include/clang/Lex/HeaderSearch.h 
b/clang/include/clang/Lex/HeaderSearch.h
index b5b856542db6..9061806e5cd6 100644
--- a/clang/include/clang/Lex/HeaderSearch.h
+++ b/clang/include/clang/Lex/HeaderSearch.h
@@ -255,13 +255,13 @@ class HeaderSearch {
 
   /// Keeps track of each lookup performed by LookupFile.
   struct LookupFileCacheInfo {
-/// Starting index in SearchDirs that the cached search was performed from.
-/// If there is a hit and this value doesn't match the current query, the
-/// cache has to be ignored.
-unsigned StartIdx = 0;
+/// Starting search directory iterator that the cached search was performed
+/// from. If there is a hit and this value doesn't match the current query,
+/// the cache has to be ignored.
+ConstSearchDirIterator StartIt = nullptr;
 
-/// The entry in SearchDirs that satisfied the query.
-unsigned HitIdx = 0;
+/// The search directory iterator that satisfied the query.
+ConstSearchDirIterator HitIt = nullptr;
 
 /// This is non-null if the original filename was mapped to a framework
 /// include via a headermap.
@@ -270,9 +270,9 @@ class HeaderSearch {
 /// Default constructor -- Initialize all members with zero.
 LookupFileCacheInfo() = default;
 
-void reset(unsigned StartIdx) {
-  this->StartIdx = StartIdx;
-  this->MappedName = nullptr;
+void reset(ConstSearchDirIterator NewStartIt) {
+  StartIt = NewStartIt;
+  MappedName = nullptr;
 }
   };
   llvm::StringMap LookupFileCache;
@@ -749,9 +749,11 @@ class HeaderSearch {
   ModuleMap::KnownHeader *SuggestedModule);
 
   /// Cache the result of a successful lookup at the given include location
-  /// using the search path at index `HitIdx`.
-  void cacheLookupSuccess(LookupFileCacheInfo &CacheLookup, unsigned HitIdx,
+  /// using the search path at \c HitIt.
+  void cacheLookupSuccess(LookupFileCacheInfo &CacheLookup,
+  ConstSearchDirIterator HitIt,
   SourceLocation IncludeLoc);
+
   /// Note that a lookup at the given include location was successful using the
   /// search path at index `HitIdx`.
   void noteLookupUsage(unsigned HitIdx, SourceLocation IncludeLoc);

diff  --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp
index 5e22a28bcb42..8187b676975e 100644
--- a/clang/lib/Lex/HeaderSearch.cpp
+++ b/clang/lib/Lex/HeaderSearch.cpp
@@ -704,9 +704,10 @@ Optional DirectoryLookup::DoFrameworkLookup(
 }
 
 void HeaderSearch::cacheLookupSuccess(LookupFileCacheInfo &CacheLookup,
-  unsigned HitIdx, SourceLocation Loc) {
-  CacheLookup.HitIdx = HitIdx;
-  noteLookupUsage(HitIdx, Loc);
+  ConstSearchDirIterator HitIt,
+  SourceLocation Loc) {
+  CacheLookup.HitIt = HitIt;
+  noteLookupUsage(HitIt.Idx, Loc);
 }
 
 void HeaderSearch::noteLookupUsage(unsigned HitIdx, SourceLocation Loc) {
@@ -964,12 +965,13 @@ Optional HeaderSearch::LookupFile(
   CurDir = nullptr;
 
   // If this is a system #include, ignore the user #include locs.
-  unsigned i = isAngled ? AngledDirIdx : 0;
+  ConstSearchDirIterator It =
+  isAngled ? angled_dir_begin() : search_dir_begin();
 
   // If this is a #include_next request, start searching after the directory 
the
   // file was found in.
   if (FromDir)
-i = FromDir.Idx;
+It = FromDir;
 
   // Cache all of the lookups performed by this method.  Many headers are
   // multiply included, and the "pragma once" optimization prevents them from
@@ -977,12 +979,14 @@ Optional HeaderSearch::LookupFile(
   // (potentially huge) series of SearchDirs to find it.
   LookupFileCacheInfo &CacheLookup = LookupFileCache[Filename];
 
+  ConstSearchDirIterator NextIt = std::next(It);
+
   // If the entry has been previously looked up, the first value will be
   // non-zero.  If the value is equal to i (the start point of our search), 
then
   // this is a matching hit.
-  if (!SkipCache && CacheLookup.StartIdx == i+1) {
+  if (!SkipCache && CacheLookup.StartIt == NextIt) {
 // Skip querying potentially lots of directories for this lookup.
-i = CacheLookup.HitIdx;

[clang] e7dcf09 - [clang][lex] Use `SearchDirIterator` types in for loops

2022-02-15 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2022-02-15T11:02:26+01:00
New Revision: e7dcf09fc321010fb012afd270afdef20378dee7

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

LOG: [clang][lex] Use `SearchDirIterator` types in for loops

This patch replaces a lot of index-based loops with iterators and ranges.

Depends on D117566.

Reviewed By: ahoppen

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

Added: 


Modified: 
clang/include/clang/Lex/HeaderSearch.h
clang/lib/Lex/HeaderSearch.cpp

Removed: 




diff  --git a/clang/include/clang/Lex/HeaderSearch.h 
b/clang/include/clang/Lex/HeaderSearch.h
index 9061806e5cd6..bfe3b07caaa8 100644
--- a/clang/include/clang/Lex/HeaderSearch.h
+++ b/clang/include/clang/Lex/HeaderSearch.h
@@ -163,47 +163,71 @@ struct FrameworkCacheEntry {
   bool IsUserSpecifiedSystemFramework;
 };
 
-/// Forward iterator over the search directories of \c HeaderSearch.
-struct ConstSearchDirIterator
-: llvm::iterator_facade_base
+using Qualified = std::conditional_t;
+
+/// Forward iterator over the search directories of HeaderSearch.
+/// Does not get invalidated by \c HeaderSearch::Add{,System}SearchPath.
+template 
+struct SearchDirIteratorImpl
+: llvm::iterator_facade_base,
  std::forward_iterator_tag,
- const DirectoryLookup> {
-  ConstSearchDirIterator(const ConstSearchDirIterator &) = default;
+ Qualified> {
+  /// Const -> non-const iterator conversion.
+  template >
+  SearchDirIteratorImpl(const SearchDirIteratorImpl &Other)
+  : HS(Other.HS), Idx(Other.Idx) {}
 
-  ConstSearchDirIterator &operator=(const ConstSearchDirIterator &) = default;
+  SearchDirIteratorImpl(const SearchDirIteratorImpl &) = default;
 
-  bool operator==(const ConstSearchDirIterator &RHS) const {
+  SearchDirIteratorImpl &operator=(const SearchDirIteratorImpl &) = default;
+
+  bool operator==(const SearchDirIteratorImpl &RHS) const {
 return HS == RHS.HS && Idx == RHS.Idx;
   }
 
-  ConstSearchDirIterator &operator++() {
+  SearchDirIteratorImpl &operator++() {
 assert(*this && "Invalid iterator.");
 ++Idx;
 return *this;
   }
 
-  const DirectoryLookup &operator*() const;
+  Qualified &operator*() const {
+assert(*this && "Invalid iterator.");
+return HS->SearchDirs[Idx];
+  }
 
   /// Creates an invalid iterator.
-  ConstSearchDirIterator(std::nullptr_t) : HS(nullptr), Idx(0) {}
+  SearchDirIteratorImpl(std::nullptr_t) : HS(nullptr), Idx(0) {}
 
   /// Checks whether the iterator is valid.
   explicit operator bool() const { return HS != nullptr; }
 
 private:
   /// The parent \c HeaderSearch. This is \c nullptr for invalid iterator.
-  const HeaderSearch *HS;
+  Qualified *HS;
 
   /// The index of the current element.
   size_t Idx;
 
   /// The constructor that creates a valid iterator.
-  ConstSearchDirIterator(const HeaderSearch &HS, size_t Idx)
+  SearchDirIteratorImpl(Qualified &HS, size_t Idx)
   : HS(&HS), Idx(Idx) {}
 
   /// Only HeaderSearch is allowed to instantiate valid iterators.
   friend HeaderSearch;
+
+  /// Enables const -> non-const conversion.
+  friend SearchDirIteratorImpl;
 };
+} // namespace detail
+
+using ConstSearchDirIterator = detail::SearchDirIteratorImpl;
+using SearchDirIterator = detail::SearchDirIteratorImpl;
+
+using ConstSearchDirRange = llvm::iterator_range;
+using SearchDirRange = llvm::iterator_range;
 
 /// Encapsulates the information needed to find the file referenced
 /// by a \#include or \#include_next, (sub-)framework lookup, etc.
@@ -211,6 +235,7 @@ class HeaderSearch {
   friend class DirectoryLookup;
 
   friend ConstSearchDirIterator;
+  friend SearchDirIterator;
 
   /// Header-search options used to initialize this header search.
   std::shared_ptr HSOpts;
@@ -778,8 +803,17 @@ class HeaderSearch {
   const HeaderFileInfo *getExistingFileInfo(const FileEntry *FE,
 bool WantExternal = true) const;
 
+  SearchDirIterator search_dir_begin() { return {*this, 0}; }
+  SearchDirIterator search_dir_end() { return {*this, SearchDirs.size()}; }
+  SearchDirRange search_dir_range() {
+return {search_dir_begin(), search_dir_end()};
+  }
+
   ConstSearchDirIterator search_dir_begin() const { return quoted_dir_begin(); 
}
   ConstSearchDirIterator search_dir_end() const { return system_dir_end(); }
+  ConstSearchDirRange search_dir_range() const {
+return {search_dir_begin(), search_dir_end()};
+  }
 
   unsigned search_dir_size() const { return SearchDirs.size(); }
 
@@ -799,7 +833,7 @@ class HeaderSearch {
   }
 
   /// Get the index of the given search directory.
-  Optional searchDirIdx(const DirectoryLookup &DL) const;
+  unsigned searchDirIdx(con

[PATCH] D119721: [clang][lex] Use `ConstSearchDirIterator` in lookup cache

2022-02-15 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG17c9fcd6f6fc: [clang][lex] Use `ConstSearchDirIterator` in 
lookup cache (authored by jansvoboda11).

Changed prior to commit:
  https://reviews.llvm.org/D119721?vs=408733&id=408772#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119721

Files:
  clang/include/clang/Lex/HeaderSearch.h
  clang/lib/Lex/HeaderSearch.cpp

Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -704,9 +704,10 @@
 }
 
 void HeaderSearch::cacheLookupSuccess(LookupFileCacheInfo &CacheLookup,
-  unsigned HitIdx, SourceLocation Loc) {
-  CacheLookup.HitIdx = HitIdx;
-  noteLookupUsage(HitIdx, Loc);
+  ConstSearchDirIterator HitIt,
+  SourceLocation Loc) {
+  CacheLookup.HitIt = HitIt;
+  noteLookupUsage(HitIt.Idx, Loc);
 }
 
 void HeaderSearch::noteLookupUsage(unsigned HitIdx, SourceLocation Loc) {
@@ -964,12 +965,13 @@
   CurDir = nullptr;
 
   // If this is a system #include, ignore the user #include locs.
-  unsigned i = isAngled ? AngledDirIdx : 0;
+  ConstSearchDirIterator It =
+  isAngled ? angled_dir_begin() : search_dir_begin();
 
   // If this is a #include_next request, start searching after the directory the
   // file was found in.
   if (FromDir)
-i = FromDir.Idx;
+It = FromDir;
 
   // Cache all of the lookups performed by this method.  Many headers are
   // multiply included, and the "pragma once" optimization prevents them from
@@ -977,12 +979,14 @@
   // (potentially huge) series of SearchDirs to find it.
   LookupFileCacheInfo &CacheLookup = LookupFileCache[Filename];
 
+  ConstSearchDirIterator NextIt = std::next(It);
+
   // If the entry has been previously looked up, the first value will be
   // non-zero.  If the value is equal to i (the start point of our search), then
   // this is a matching hit.
-  if (!SkipCache && CacheLookup.StartIdx == i+1) {
+  if (!SkipCache && CacheLookup.StartIt == NextIt) {
 // Skip querying potentially lots of directories for this lookup.
-i = CacheLookup.HitIdx;
+It = CacheLookup.HitIt;
 if (CacheLookup.MappedName) {
   Filename = CacheLookup.MappedName;
   if (IsMapped)
@@ -992,17 +996,17 @@
 // Otherwise, this is the first query, or the previous query didn't match
 // our search start.  We will fill in our found location below, so prime the
 // start point value.
-CacheLookup.reset(/*StartIdx=*/i+1);
+CacheLookup.reset(/*NewStartIt=*/NextIt);
   }
 
   SmallString<64> MappedName;
 
   // Check each directory in sequence to see if it contains this file.
-  for (; i != SearchDirs.size(); ++i) {
+  for (; It != search_dir_end(); ++It) {
 bool InUserSpecifiedSystemFramework = false;
 bool IsInHeaderMap = false;
 bool IsFrameworkFoundInDir = false;
-Optional File = SearchDirs[i].LookupFile(
+Optional File = It->LookupFile(
 Filename, *this, IncludeLoc, SearchPath, RelativePath, RequestingModule,
 SuggestedModule, InUserSpecifiedSystemFramework, IsFrameworkFoundInDir,
 IsInHeaderMap, MappedName);
@@ -1024,7 +1028,7 @@
 if (!File)
   continue;
 
-CurDir = ConstSearchDirIterator(*this, i);
+CurDir = It;
 
 // This file is a system header or C++ unfriendly if the dir is.
 HeaderFileInfo &HFI = getFileInfo(&File->getFileEntry());
@@ -1077,7 +1081,7 @@
   &File->getFileEntry(), isAngled, FoundByHeaderMap);
 
 // Remember this location for the next lookup we do.
-cacheLookupSuccess(CacheLookup, i, IncludeLoc);
+cacheLookupSuccess(CacheLookup, It, IncludeLoc);
 return File;
   }
 
@@ -1108,7 +1112,7 @@
   }
 
   cacheLookupSuccess(LookupFileCache[Filename],
- LookupFileCache[ScratchFilename].HitIdx, IncludeLoc);
+ LookupFileCache[ScratchFilename].HitIt, IncludeLoc);
   // FIXME: SuggestedModule.
   return File;
 }
@@ -1122,7 +1126,7 @@
   }
 
   // Otherwise, didn't find it. Remember we didn't find this.
-  CacheLookup.HitIdx = SearchDirs.size();
+  CacheLookup.HitIt = search_dir_end();
   return None;
 }
 
Index: clang/include/clang/Lex/HeaderSearch.h
===
--- clang/include/clang/Lex/HeaderSearch.h
+++ clang/include/clang/Lex/HeaderSearch.h
@@ -255,13 +255,13 @@
 
   /// Keeps track of each lookup performed by LookupFile.
   struct LookupFileCacheInfo {
-/// Starting index in SearchDirs that the cached search was performed from.
-/// If there is a hit and this value doesn't match the current query, the
-/// cache has to be ignored.
-unsign

[PATCH] D119722: [clang][lex] Use `SearchDirIterator` types in for loops

2022-02-15 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe7dcf09fc321: [clang][lex] Use `SearchDirIterator` types in 
for loops (authored by jansvoboda11).

Changed prior to commit:
  https://reviews.llvm.org/D119722?vs=408724&id=408773#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119722

Files:
  clang/include/clang/Lex/HeaderSearch.h
  clang/lib/Lex/HeaderSearch.cpp

Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -79,11 +79,6 @@
 
 ExternalHeaderFileInfoSource::~ExternalHeaderFileInfoSource() = default;
 
-const DirectoryLookup &ConstSearchDirIterator::operator*() const {
-  assert(*this && "Invalid iterator.");
-  return HS->SearchDirs[Idx];
-}
-
 HeaderSearch::HeaderSearch(std::shared_ptr HSOpts,
SourceManager &SourceMgr, DiagnosticsEngine &Diags,
const LangOptions &LangOpts,
@@ -304,21 +299,20 @@
SourceLocation ImportLoc,
bool AllowExtraModuleMapSearch) {
   Module *Module = nullptr;
-  unsigned Idx;
+  SearchDirIterator It = nullptr;
 
   // Look through the various header search paths to load any available module
   // maps, searching for a module map that describes this module.
-  for (Idx = 0; Idx != SearchDirs.size(); ++Idx) {
-if (SearchDirs[Idx].isFramework()) {
+  for (It = search_dir_begin(); It != search_dir_end(); ++It) {
+if (It->isFramework()) {
   // Search for or infer a module map for a framework. Here we use
   // SearchName rather than ModuleName, to permit finding private modules
   // named FooPrivate in buggy frameworks named Foo.
   SmallString<128> FrameworkDirName;
-  FrameworkDirName += SearchDirs[Idx].getFrameworkDir()->getName();
+  FrameworkDirName += It->getFrameworkDir()->getName();
   llvm::sys::path::append(FrameworkDirName, SearchName + ".framework");
   if (auto FrameworkDir = FileMgr.getDirectory(FrameworkDirName)) {
-bool IsSystem
-  = SearchDirs[Idx].getDirCharacteristic() != SrcMgr::C_User;
+bool IsSystem = It->getDirCharacteristic() != SrcMgr::C_User;
 Module = loadFrameworkModule(ModuleName, *FrameworkDir, IsSystem);
 if (Module)
   break;
@@ -328,12 +322,12 @@
 // FIXME: Figure out how header maps and module maps will work together.
 
 // Only deal with normal search directories.
-if (!SearchDirs[Idx].isNormalDir())
+if (!It->isNormalDir())
   continue;
 
-bool IsSystem = SearchDirs[Idx].isSystemHeaderDirectory();
+bool IsSystem = It->isSystemHeaderDirectory();
 // Search for a module map file in this directory.
-if (loadModuleMapFile(SearchDirs[Idx].getDir(), IsSystem,
+if (loadModuleMapFile(It->getDir(), IsSystem,
   /*IsFramework*/false) == LMM_NewlyLoaded) {
   // We just loaded a module map file; check whether the module is
   // available now.
@@ -345,7 +339,7 @@
 // Search for a module map in a subdirectory with the same name as the
 // module.
 SmallString<128> NestedModuleMapDirName;
-NestedModuleMapDirName = SearchDirs[Idx].getDir()->getName();
+NestedModuleMapDirName = It->getDir()->getName();
 llvm::sys::path::append(NestedModuleMapDirName, ModuleName);
 if (loadModuleMapFile(NestedModuleMapDirName, IsSystem,
   /*IsFramework*/false) == LMM_NewlyLoaded){
@@ -357,13 +351,13 @@
 
 // If we've already performed the exhaustive search for module maps in this
 // search directory, don't do it again.
-if (SearchDirs[Idx].haveSearchedAllModuleMaps())
+if (It->haveSearchedAllModuleMaps())
   continue;
 
 // Load all module maps in the immediate subdirectories of this search
 // directory if ModuleName was from @import.
 if (AllowExtraModuleMapSearch)
-  loadSubdirectoryModuleMaps(SearchDirs[Idx]);
+  loadSubdirectoryModuleMaps(*It);
 
 // Look again for the module.
 Module = ModMap.findModule(ModuleName);
@@ -372,7 +366,7 @@
   }
 
   if (Module)
-noteLookupUsage(Idx, ImportLoc);
+noteLookupUsage(It.Idx, ImportLoc);
 
   return Module;
 }
@@ -498,7 +492,7 @@
   // The case where the target file **exists** is handled by callee of this
   // function as part of the regular logic that applies to include search paths.
   // The case where the target file **does not exist** is handled here:
-  HS.noteLookupUsage(*HS.searchDirIdx(*this), IncludeLoc);
+  HS.noteLookupUsage(HS.searchDirIdx(*this), IncludeLoc);
   return None;
 }
 
@@ -1452,11 +1446,8 @@
 + FrameworkMap.getAllocator().getTotalMemory();
 }
 
-Optional HeaderSearch::searchDirIdx(const DirectoryLookup

[PATCH] D119785: [clang-format] Fix formatting of struct-like records followed by variable declaration.

2022-02-15 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius added inline comments.



Comment at: clang/lib/Format/UnwrappedLineFormatter.cpp:470
+ShouldMerge = Style.AllowShortEnumsOnASingleLine;
+  } else if (TheLine->Last->isOneOf(TT_ClassLBrace, TT_StructLBrace)) {
+// NOTE: We use AfterClass (whereas AfterStruct exists) for both 
classes

HazardyKnusperkeks wrote:
> Why not Union?
Well, it wasn't handled here before.
I haven't found a case that breaks with unions and didn't want to incorporate 
even more changes.
I'll be happy to do this later though, I'd like to understand first why below 
we need `!Style.BraceWrapping.AfterClass` (there is a dozen of failing tests if 
removed, also, it's equivalent to `!Style.BraceWrapping.AfterStruct` 😵).

Also, as you might guess, unions are handled in the `else` that handles 
functions, which is, yuck, not the best thing to put it mildly.



Comment at: clang/lib/Format/UnwrappedLineFormatter.cpp:735
 // We don't merge short records.
-FormatToken *RecordTok = Line.First;
-// Skip record modifiers.
-while (RecordTok->Next &&
-   RecordTok->isOneOf(tok::kw_typedef, tok::kw_export,
-  Keywords.kw_declare, Keywords.kw_abstract,
-  tok::kw_default, Keywords.kw_override,
-  tok::kw_public, tok::kw_private,
-  tok::kw_protected, Keywords.kw_internal))
-  RecordTok = RecordTok->Next;
-if (RecordTok &&
-RecordTok->isOneOf(tok::kw_class, tok::kw_union, tok::kw_struct,
-   Keywords.kw_interface))
+if (isRecordLBrace(*Line.Last))
   return 0;

MyDeveloperDay wrote:
> wow these are equivalent? do we need to worry about trailing comments?
> 
> ```
> public class A { /* comment */
> ```
Yes, before we were doing a poor man's scan skipping some (but not all) 
keywords (hence the bugs) that could appear before a record.
That was error-prone and redundant w.r.t. the parsing done in 
UnwrappedLineParser.

Anyway, good catch, I'll test what happens with comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119785

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


[PATCH] D119785: [clang-format] Fix formatting of struct-like records followed by variable declaration.

2022-02-15 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius added inline comments.



Comment at: clang/lib/Format/UnwrappedLineFormatter.cpp:718
 
 if (Line.Last->is(tok::l_brace)) {
   FormatToken *Tok = I[1]->First;

@MyDeveloperDay, probably we'll need to check `LastNonComment` similarly to 
what I did with `FirstNonComment` for loops.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119785

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


[PATCH] D119726: [asan] Add support for disable_sanitizer_instrumentation attribute

2022-02-15 Thread Alexander Potapenko via Phabricator via cfe-commits
glider updated this revision to Diff 408780.
glider added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119726

Files:
  clang/docs/AddressSanitizer.rst
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/SanitizerMetadata.cpp
  clang/test/CodeGen/address-safety-attr-flavors.cpp
  clang/test/CodeGen/asan-globals.cpp
  llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
  
llvm/test/Instrumentation/AddressSanitizer/asan-disable-sanitizer-instrumentation.ll

Index: llvm/test/Instrumentation/AddressSanitizer/asan-disable-sanitizer-instrumentation.ll
===
--- /dev/null
+++ llvm/test/Instrumentation/AddressSanitizer/asan-disable-sanitizer-instrumentation.ll
@@ -0,0 +1,47 @@
+; This test checks that we are not instrumenting sanitizer code.
+; RUN: opt < %s -passes='asan-pipeline' -S | FileCheck %s
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+; Function with sanitize_address is instrumented.
+; Function Attrs: nounwind uwtable
+define void @instr_sa(i32* %a) sanitize_address {
+entry:
+  %tmp1 = load i32, i32* %a, align 4
+  %tmp2 = add i32 %tmp1,  1
+  store i32 %tmp2, i32* %a, align 4
+  ret void
+}
+
+; CHECK-LABEL: @instr_sa
+; CHECK: call void @__asan_report_load
+
+
+; Function with disable_sanitizer_instrumentation is not instrumented.
+; Function Attrs: nounwind uwtable
+define void @noinstr_dsi(i32* %a) disable_sanitizer_instrumentation {
+entry:
+  %tmp1 = load i32, i32* %a, align 4
+  %tmp2 = add i32 %tmp1,  1
+  store i32 %tmp2, i32* %a, align 4
+  ret void
+}
+
+; CHECK-LABEL: @noinstr_dsi
+; CHECK-NOT: call void @__asan_report_load
+
+
+; disable_sanitizer_instrumentation takes precedence over sanitize_address.
+; Function Attrs: nounwind uwtable
+define void @noinstr_dsi_sa(i32* %a) disable_sanitizer_instrumentation sanitize_address {
+entry:
+  %tmp1 = load i32, i32* %a, align 4
+  %tmp2 = add i32 %tmp1,  1
+  store i32 %tmp2, i32* %a, align 4
+  ret void
+}
+
+; CHECK-LABEL: @noinstr_dsi_sa
+; CHECK-NOT: call void @__asan_report_load
+
Index: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
===
--- llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -2888,6 +2888,9 @@
   // Leave if the function doesn't need instrumentation.
   if (!F.hasFnAttribute(Attribute::SanitizeAddress)) return FunctionModified;
 
+  if (F.hasFnAttribute(Attribute::DisableSanitizerInstrumentation))
+return FunctionModified;
+
   LLVM_DEBUG(dbgs() << "ASAN instrumenting:\n" << F << "\n");
 
   initializeCallbacks(*F.getParent());
Index: clang/test/CodeGen/asan-globals.cpp
===
--- clang/test/CodeGen/asan-globals.cpp
+++ clang/test/CodeGen/asan-globals.cpp
@@ -10,6 +10,7 @@
 int global;
 int dyn_init_global = global;
 int __attribute__((no_sanitize("address"))) attributed_global;
+int __attribute__((disable_sanitizer_instrumentation)) disable_instrumentation_global;
 int ignorelisted_global;
 
 int __attribute__((section("__DATA, __common"))) sectioned_global; // KASAN - ignore globals in a section
@@ -50,31 +51,33 @@
 // UWTABLE: attributes #[[#ATTR]] = { nounwind uwtable }
 // UWTABLE: ![[#]] = !{i32 7, !"uwtable", i32 2}
 
-// CHECK: !llvm.asan.globals = !{![[EXTRA_GLOBAL:[0-9]+]], ![[GLOBAL:[0-9]+]], ![[DYN_INIT_GLOBAL:[0-9]+]], ![[ATTR_GLOBAL:[0-9]+]], ![[IGNORELISTED_GLOBAL:[0-9]+]], ![[SECTIONED_GLOBAL:[0-9]+]], ![[SPECIAL_GLOBAL:[0-9]+]], ![[STATIC_VAR:[0-9]+]], ![[LITERAL:[0-9]+]]}
+// CHECK: !llvm.asan.globals = !{![[EXTRA_GLOBAL:[0-9]+]], ![[GLOBAL:[0-9]+]], ![[DYN_INIT_GLOBAL:[0-9]+]], ![[ATTR_GLOBAL:[0-9]+]], ![[DISABLE_INSTR_GLOBAL:[0-9]+]], ![[IGNORELISTED_GLOBAL:[0-9]+]], ![[SECTIONED_GLOBAL:[0-9]+]], ![[SPECIAL_GLOBAL:[0-9]+]], ![[STATIC_VAR:[0-9]+]], ![[LITERAL:[0-9]+]]}
 // CHECK: ![[EXTRA_GLOBAL]] = !{{{.*}} ![[EXTRA_GLOBAL_LOC:[0-9]+]], !"extra_global", i1 false, i1 false}
 // CHECK: ![[EXTRA_GLOBAL_LOC]] = !{!"{{.*}}extra-source.cpp", i32 1, i32 5}
 // CHECK: ![[GLOBAL]] = !{{{.*}} ![[GLOBAL_LOC:[0-9]+]], !"global", i1 false, i1 false}
 // CHECK: ![[GLOBAL_LOC]] = !{!"{{.*}}asan-globals.cpp", i32 10, i32 5}
 // CHECK: ![[DYN_INIT_GLOBAL]] = !{{{.*}} ![[DYN_INIT_LOC:[0-9]+]], !"dyn_init_global", i1 true, i1 false}
 // CHECK: ![[DYN_INIT_LOC]] = !{!"{{.*}}asan-globals.cpp", i32 11, i32 5}
-// CHECK: ![[ATTR_GLOBAL]] = !{{{.*}}, null, null, i1 false, i1 true}
-// CHECK: ![[IGNORELISTED_GLOBAL]] = !{{{.*}}, null, null, i1 false, i1 true}
+// CHECK: ![[ATTR_GLOBAL]] = !{{{.*attributed_global.*}}, null, null, i1 false, i1 true}
+// CHECK: ![[DISABLE_INSTR_GLOBAL]] = !{{{.*disable_instrumentation_global.*}}, null, null, i1 false, i1 true}
+// CHECK: ![[IGNORELIST

[PATCH] D119823: [Modules] Add module structure output to -module-file-info.

2022-02-15 Thread Iain Sandoe via Phabricator via cfe-commits
iains created this revision.
iains added reviewers: dblaikie, aprantl, urnathan, ChuanqiXu.
iains published this revision for review.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

It is useful to be able to visualise the C++20 modules content of a PCM file
both for inspection and for testing.  In particular, when adding more module
types to support C++20 Partitions and Header Units, we would like to be able
to confirm that the output PCM has the intended structure.

The existing scheme for dumping data is restricted to the content of the AST
file control block, which does not include structural data beyond imports.

The change here makes use of the AST unit that is set up by BeginSourceFile
to query for the information on the primary and sub-modules.  We can then
inspect each of these in turn, accounting for Global, Private, Imported and
Exported modules/fragments and then showing the sub-stucture of the main
module(s).

The disadvantage of this mechanism is that it has no easy method to control
the granularity of the output.  Perhaps more detailed inspection would be
better handled by a stand-alone module inspection tool.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119823

Files:
  clang/lib/Frontend/FrontendActions.cpp
  clang/test/Modules/module-file-info-cxx20.cpp

Index: clang/test/Modules/module-file-info-cxx20.cpp
===
--- /dev/null
+++ clang/test/Modules/module-file-info-cxx20.cpp
@@ -0,0 +1,71 @@
+// Test output from -module-file-info about C++20 modules.
+
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface -D TU=1 -x c++ %s \
+// RUN:  -o %t/A.pcm
+
+// RUN: %clang_cc1 -std=c++20 -module-file-info %t/A.pcm | FileCheck \
+// RUN:  --check-prefix=CHECK-A %s
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface -D TU=2 -x c++ %s \
+// RUN:  -o %t/B.pcm
+
+// RUN: %clang_cc1 -std=c++20 -module-file-info %t/B.pcm | FileCheck \
+// RUN:  --check-prefix=CHECK-B %s
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface -D TU=3 -x c++ %s \
+// RUN:  -fmodule-file=%t/A.pcm -fmodule-file=%t/B.pcm -o %t/Foo.pcm
+
+// RUN: %clang_cc1 -std=c++20 -module-file-info %t/Foo.pcm | FileCheck \
+// RUN:  --check-prefix=CHECK-FOO %s
+
+// expected-no-diagnostics
+
+#if TU == 1
+
+export module A;
+
+void a();
+
+// CHECK-A: == C++20
+// CHECK-A-NEXT: Interface Unit 'A' is the Primary Module at index #1
+
+#elif TU == 2
+
+export module B;
+
+void b();
+
+// CHECK-B: == C++20
+// CHECK-B-NEXT: Interface Unit 'B' is the Primary Module at index #1
+
+#elif TU == 3
+
+module;
+
+export module Foo;
+
+import A;
+export import B;
+
+namespace hello
+{
+ export void say (const char*);
+}
+
+void foo () {}
+
+// CHECK-FOO: == C++20
+// CHECK-FOO:  Interface Unit 'Foo' is the Primary Module at index #3
+// CHECK-FOO:   Sub Modules:
+// CHECK-FOO:Global Module Fragment '' is at index #4
+// CHECK-FOO:   Imports:
+// CHECK-FOO:Interface Unit 'A' is at index #1
+// CHECK-FOO:   Exports:
+// CHECK-FOO:Interface Unit 'B' is at index #2
+
+#else
+#error "no TU set"
+#endif
Index: clang/lib/Frontend/FrontendActions.cpp
===
--- clang/lib/Frontend/FrontendActions.cpp
+++ clang/lib/Frontend/FrontendActions.cpp
@@ -11,6 +11,7 @@
 #include "clang/AST/Decl.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/LangStandard.h"
+#include "clang/Basic/Module.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Frontend/ASTConsumers.h"
 #include "clang/Frontend/CompilerInstance.h"
@@ -24,6 +25,7 @@
 #include "clang/Sema/TemplateInstCallback.h"
 #include "clang/Serialization/ASTReader.h"
 #include "clang/Serialization/ASTWriter.h"
+#include "clang/Serialization/ModuleFile.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBuffer.h"
@@ -806,7 +808,29 @@
   return true;
 }
 
+static StringRef ModuleKindName(Module::ModuleKind MK) {
+  switch (MK) {
+  case Module::ModuleMapModule:
+return "Module Map Module";
+  case Module::ModuleInterfaceUnit:
+return "Interface Unit";
+#if 0
+  case Module::ModuleHeaderUnit:
+return "Header Unit";
+  case Module::ModulePartitionInterface:
+return "Partition Interface";
+  case Module::ModulePartitionImplementation:
+return "Partition Implementation";
+#endif
+  case Module::GlobalModuleFragment:
+return "Global Module Fragment";
+  case Module::PrivateModuleFragment:
+return "Private Module Fragment";
+  }
+}
+
 void DumpModuleInfoAction::ExecuteAction() {
+  assert (isCurrentFileAST() && "dumping non-AST?");
   // Set up the output file.
   std::unique_ptr OutFile;
   StringRef OutputFileName = getCompilerInstance().getFrontendOpts().OutputFile;
@@ -827,8 +851,88 @@
 
   Preprocessor &PP = getCompilerInstance().getPreprocessor();
   DumpModuleInfoListener Listener(O

[PATCH] D91605: [sanitizers] Implement GetTls on Solaris

2022-02-15 Thread Rainer Orth via Phabricator via cfe-commits
ro added a comment.

In D91605#3321554 , @MaskRay wrote:

> `GetTls` is about the static TLS block size. It consists of the main 
> executable's TLS, and initially loaded shared objects' TLS, `struct pthread`, 
> and padding.
> Solaris should be able to just use the code path like FreeBSD, Linux musl, 
> and various unpopular architectures of Linux glibc:
>
>   #elif SANITIZER_FREEBSD || SANITIZER_LINUX
> uptr align;
> GetStaticTlsBoundary(addr, size, &align);

Not unconditionally, unfortunally: as the comment above `GetSizeFromHdr` 
explains, `dlpi_tls_modid` was only introduced in an update to Solaris 11.4 FCS 
(which is sort of a problem), but isn't present in 11.3 (don't reallly care) 
and Illumos (this would break compilation for them).  OTOH my solution is 
successfully being used in GCC's `libphobos` on Solaris 11.3, 11.4, and most 
likely Illumos, too.  I'd rather not burn the Illumos bridge if it can be 
avoided.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91605

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


[PATCH] D119825: [clang][lex] Introduce `SearchDirIndex` to usage tracking code

2022-02-15 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: ahoppen, Bigcheese, dexonsmith.
Herald added a subscriber: arphaman.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch introduces new `SearchDirIndex` type to the internal `HeaderSearch` 
code that tracks search path usage. The type replaces the current uses of 
`unsigned` to identify `DirectoryLookup` objects.

In a follow-up patch (D116750 ), this type 
will become resilient against insertions "into the middle" of `SearchDirs` as 
done by `HeaderSearch::AddSearchPath()`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119825

Files:
  clang/include/clang/Lex/HeaderSearch.h
  clang/lib/Lex/HeaderSearch.cpp

Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -79,6 +79,14 @@
 
 ExternalHeaderFileInfoSource::~ExternalHeaderFileInfoSource() = default;
 
+const DirectoryLookup &SearchDirIdx::get(const HeaderSearch &HS) const {
+  return HS.SearchDirs[Idx];
+}
+
+DirectoryLookup &SearchDirIdx::get(HeaderSearch &HS) const {
+  return HS.SearchDirs[Idx];
+}
+
 HeaderSearch::HeaderSearch(std::shared_ptr HSOpts,
SourceManager &SourceMgr, DiagnosticsEngine &Diags,
const LangOptions &LangOpts,
@@ -110,18 +118,22 @@
   assert(angledDirIdx <= systemDirIdx && systemDirIdx <= dirs.size() &&
  "Directory indices are unordered");
   SearchDirs = std::move(dirs);
-  SearchDirsUsage.assign(SearchDirs.size(), false);
   AngledDirIdx = angledDirIdx;
   SystemDirIdx = systemDirIdx;
   NoCurDirSearch = noCurDirSearch;
-  SearchDirToHSEntry = std::move(searchDirToHSEntry);
+
+  UsedSearchDirs.clear();
+
+  SearchDirToHSEntry.clear();
+  for (const auto &Entry : searchDirToHSEntry)
+SearchDirToHSEntry.insert({SearchDirIdx(Entry.first), Entry.second});
+
   //LookupFileCache.clear();
 }
 
 void HeaderSearch::AddSearchPath(const DirectoryLookup &dir, bool isAngled) {
   unsigned idx = isAngled ? SystemDirIdx : AngledDirIdx;
   SearchDirs.insert(SearchDirs.begin() + idx, dir);
-  SearchDirsUsage.insert(SearchDirsUsage.begin() + idx, false);
   if (!isAngled)
 AngledDirIdx++;
   SystemDirIdx++;
@@ -129,14 +141,11 @@
 
 std::vector HeaderSearch::computeUserEntryUsage() const {
   std::vector UserEntryUsage(HSOpts->UserEntries.size());
-  for (unsigned I = 0, E = SearchDirsUsage.size(); I < E; ++I) {
-// Check whether this DirectoryLookup has been successfully used.
-if (SearchDirsUsage[I]) {
-  auto UserEntryIdxIt = SearchDirToHSEntry.find(I);
-  // Check whether this DirectoryLookup maps to a HeaderSearch::UserEntry.
-  if (UserEntryIdxIt != SearchDirToHSEntry.end())
-UserEntryUsage[UserEntryIdxIt->second] = true;
-}
+  for (SearchDirIdx Idx : UsedSearchDirs) {
+auto UserEntryIdxIt = SearchDirToHSEntry.find(Idx);
+// Check whether this DirectoryLookup maps to a HeaderSearch::UserEntry.
+if (UserEntryIdxIt != SearchDirToHSEntry.end())
+  UserEntryUsage[UserEntryIdxIt->second] = true;
   }
   return UserEntryUsage;
 }
@@ -704,8 +713,8 @@
   noteLookupUsage(HitIt.Idx, Loc);
 }
 
-void HeaderSearch::noteLookupUsage(unsigned HitIdx, SourceLocation Loc) {
-  SearchDirsUsage[HitIdx] = true;
+void HeaderSearch::noteLookupUsage(SearchDirIdx HitIdx, SourceLocation Loc) {
+  UsedSearchDirs.insert(HitIdx);
 
   auto UserEntryIdxIt = SearchDirToHSEntry.find(HitIdx);
   if (UserEntryIdxIt != SearchDirToHSEntry.end())
@@ -1446,8 +1455,8 @@
 + FrameworkMap.getAllocator().getTotalMemory();
 }
 
-unsigned HeaderSearch::searchDirIdx(const DirectoryLookup &DL) const {
-  return &DL - &*SearchDirs.begin();
+SearchDirIdx HeaderSearch::searchDirIdx(const DirectoryLookup &DL) const {
+  return SearchDirIdx(&DL - &*SearchDirs.begin());
 }
 
 StringRef HeaderSearch::getUniqueFrameworkName(StringRef Framework) {
Index: clang/include/clang/Lex/HeaderSearch.h
===
--- clang/include/clang/Lex/HeaderSearch.h
+++ clang/include/clang/Lex/HeaderSearch.h
@@ -163,6 +163,48 @@
   bool IsUserSpecifiedSystemFramework;
 };
 
+/// Index of a search directory.
+class SearchDirIdx {
+  /// The underlying index.
+  size_t Idx;
+
+  friend HeaderSearch;
+
+public:
+  explicit SearchDirIdx(size_t Idx) : Idx(Idx) {}
+
+  bool operator==(const SearchDirIdx &Other) const { return Idx == Other.Idx; }
+
+  llvm::hash_code hash_value() const { return Idx; }
+
+  void increment() { ++Idx; }
+
+  /// Get search directory stored at the index.
+  const DirectoryLookup &get(const HeaderSearch &HS) const;
+  /// Get search directory stored at the index.
+  DirectoryLookup &get(HeaderSearch &HS) const;
+};
+} // namespace clang
+
+namespace llvm {
+template <> struct DenseMapInfo {
+  st

[PATCH] D119826: [clang] Remove a duplicate action kind table entry.

2022-02-15 Thread Iain Sandoe via Phabricator via cfe-commits
iains created this revision.
iains added a reviewer: jansvoboda11.
iains published this revision for review.
iains added a comment.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

probably trivial - but, in case there's some subtlety I missed...


We have two entries for OPT_emit_codegen_only in the frontend action kind
table, delete one.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119826

Files:
  clang/lib/Frontend/CompilerInvocation.cpp


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -2406,7 +2406,6 @@
   {frontend::EmitLLVM, OPT_emit_llvm},
   {frontend::EmitLLVMOnly, OPT_emit_llvm_only},
   {frontend::EmitCodeGenOnly, OPT_emit_codegen_only},
-  {frontend::EmitCodeGenOnly, OPT_emit_codegen_only},
   {frontend::EmitObj, OPT_emit_obj},
   {frontend::ExtractAPI, OPT_extract_api},
 


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -2406,7 +2406,6 @@
   {frontend::EmitLLVM, OPT_emit_llvm},
   {frontend::EmitLLVMOnly, OPT_emit_llvm_only},
   {frontend::EmitCodeGenOnly, OPT_emit_codegen_only},
-  {frontend::EmitCodeGenOnly, OPT_emit_codegen_only},
   {frontend::EmitObj, OPT_emit_obj},
   {frontend::ExtractAPI, OPT_extract_api},
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D119826: [clang] Remove a duplicate action kind table entry.

2022-02-15 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, must've been a mistake. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119826

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


[clang] 2370977 - [clang] Remove a duplicate action kind table entry.

2022-02-15 Thread Iain Sandoe via cfe-commits

Author: iains
Date: 2022-02-15T11:19:09Z
New Revision: 2370977bdd0254d9d5424713513aeee233c647e4

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

LOG: [clang] Remove a duplicate action kind table entry.

We have two entries for OPT_emit_codegen_only in the frontend action kind
table, delete one.

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

Added: 


Modified: 
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 1b7448feb472b..1014147451091 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -2406,7 +2406,6 @@ static const auto &getFrontendActionTable() {
   {frontend::EmitLLVM, OPT_emit_llvm},
   {frontend::EmitLLVMOnly, OPT_emit_llvm_only},
   {frontend::EmitCodeGenOnly, OPT_emit_codegen_only},
-  {frontend::EmitCodeGenOnly, OPT_emit_codegen_only},
   {frontend::EmitObj, OPT_emit_obj},
   {frontend::ExtractAPI, OPT_extract_api},
 



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


[PATCH] D119826: [clang] Remove a duplicate action kind table entry.

2022-02-15 Thread Iain Sandoe 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 rG2370977bdd02: [clang] Remove a duplicate action kind table 
entry. (authored by iains).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119826

Files:
  clang/lib/Frontend/CompilerInvocation.cpp


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -2406,7 +2406,6 @@
   {frontend::EmitLLVM, OPT_emit_llvm},
   {frontend::EmitLLVMOnly, OPT_emit_llvm_only},
   {frontend::EmitCodeGenOnly, OPT_emit_codegen_only},
-  {frontend::EmitCodeGenOnly, OPT_emit_codegen_only},
   {frontend::EmitObj, OPT_emit_obj},
   {frontend::ExtractAPI, OPT_extract_api},
 


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -2406,7 +2406,6 @@
   {frontend::EmitLLVM, OPT_emit_llvm},
   {frontend::EmitLLVMOnly, OPT_emit_llvm_only},
   {frontend::EmitCodeGenOnly, OPT_emit_codegen_only},
-  {frontend::EmitCodeGenOnly, OPT_emit_codegen_only},
   {frontend::EmitObj, OPT_emit_obj},
   {frontend::ExtractAPI, OPT_extract_api},
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] ef378d7 - [clang][lex] Remove misleading comment

2022-02-15 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2022-02-15T12:39:43+01:00
New Revision: ef378d76b46091abfa548e698e5d7e03571bd5c1

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

LOG: [clang][lex] Remove misleading comment

The resiliency to `HeaderSearch::Add{,System}SearchPath` is implemented in 
later patch (D116750).

Added: 


Modified: 
clang/include/clang/Lex/HeaderSearch.h

Removed: 




diff  --git a/clang/include/clang/Lex/HeaderSearch.h 
b/clang/include/clang/Lex/HeaderSearch.h
index bfe3b07caaa8..2de46d727ece 100644
--- a/clang/include/clang/Lex/HeaderSearch.h
+++ b/clang/include/clang/Lex/HeaderSearch.h
@@ -167,8 +167,7 @@ namespace detail {
 template 
 using Qualified = std::conditional_t;
 
-/// Forward iterator over the search directories of HeaderSearch.
-/// Does not get invalidated by \c HeaderSearch::Add{,System}SearchPath.
+/// Forward iterator over the search directories of \c HeaderSearch.
 template 
 struct SearchDirIteratorImpl
 : llvm::iterator_facade_base,



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


[PATCH] D117087: [C++20] [Coroutines] Implement return value optimization for get_return_object

2022-02-15 Thread JunMa via Phabricator via cfe-commits
junparser added inline comments.



Comment at: clang/lib/CodeGen/CGCoroutine.cpp:654
+cast(Ret)->setRetValue(nullptr);
 EmitStmt(Ret);
+  }

I mean, remove the if statements here since the retuen expr is null.


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

https://reviews.llvm.org/D117087

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


[PATCH] D119719: [Docs][OpenCL] Update OpenCL 3.0 status

2022-02-15 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia updated this revision to Diff 408806.
Anastasia retitled this revision from "[Docs][OpenCL] Update OpenCL 3.0 status 
on release 14" to "[Docs][OpenCL] Update OpenCL 3.0 status".
Anastasia edited the summary of this revision.

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

https://reviews.llvm.org/D119719

Files:
  clang/docs/OpenCLSupport.rst
  clang/docs/UsersManual.rst

Index: clang/docs/UsersManual.rst
===
--- clang/docs/UsersManual.rst
+++ clang/docs/UsersManual.rst
@@ -3060,9 +3060,8 @@
 Starting from clang 9 a C++ mode is available for OpenCL (see
 :ref:`C++ for OpenCL `).
 
-There is ongoing support for OpenCL v3.0 that is documented along with other
-experimental functionality and features in development on :doc:`OpenCLSupport`
-page.
+OpenCL v3.0 support is complete but it remains in experimental state, see more
+details about the experimental features in :doc:`OpenCLSupport` page.
 
 OpenCL Specific Options
 ---
Index: clang/docs/OpenCLSupport.rst
===
--- clang/docs/OpenCLSupport.rst
+++ clang/docs/OpenCLSupport.rst
@@ -17,8 +17,8 @@
 OpenCL Support
 ==
 
-Clang has complete support of OpenCL C versions from 1.0 to 2.0.
-There is an ongoing work to support :ref:`OpenCL 3.0 `.
+Clang has complete support of OpenCL C versions from 1.0 to 3.0.
+Support for OpenCL 3.0 is in experimental phase (:ref:`OpenCL 3.0 `).
 
 Clang also supports :ref:`the C++ for OpenCL kernel language `.
 
@@ -371,43 +371,43 @@
 The following table provides an overview of features in OpenCL C 3.0 and their
 implementation status.
 
-+--+-+-+--+--+
-| Category | Feature   | Status   | Reviews  |
-+==+=+=+==+==+
-| Command line interface   | New value for ``-cl-std`` flag| :good:`done` | https://reviews.llvm.org/D88300  |
-+--+-+-+--+--+
-| Predefined macros| New version macro | :good:`done` | https://reviews.llvm.org/D88300  |
-+--+-+-+--+--+
-| Predefined macros| Feature macros| :good:`done` | https://reviews.llvm.org/D95776  |
-+--+-+-+--+--+
-| Feature optionality  | Generic address space | :good:`done` | https://reviews.llvm.org/D95778 and https://reviews.llvm.org/D103401 |
-+--+-+-+--+--+
-| Feature optionality  | Builtin function overloads with generic address space | :good:`done` | https://reviews.llvm.org/D105526 |
-+--+-+-+--+--+
-| Feature optionality  | Program scope variables in global memory  | :good:`done` | https://reviews.llvm.org/D103191 |
-+--+-+-+--+-

[PATCH] D119710: [Docs][OpenCL] Release 14 notes

2022-02-15 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia updated this revision to Diff 408810.
Anastasia added a comment.

- Fixed review comments
- Updated OpenCL 3 state after backports


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

https://reviews.llvm.org/D119710

Files:
  clang/docs/ReleaseNotes.rst


Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -18,7 +18,7 @@
 Introduction
 
 
-This document contains the release notes for the Clang C/C++/Objective-C
+This document contains the release notes for the Clang C/C++/Objective-C/OpenCL
 frontend, part of the LLVM Compiler Infrastructure, release |release|. Here we
 describe the status of Clang in some detail, including major
 improvements from the previous release and new feature work. For the
@@ -49,6 +49,8 @@
 
 - Added SPIR-V triple and binary generation using external ``llvm-spirv`` tool.
   For more details refer to :ref:`the SPIR-V support section `.
+- Completed support of OpenCL C 3.0 and C++ for OpenCL 2021 at experimental
+  state.
 -  ...
 
 Improvements to Clang's diagnostics
@@ -255,10 +257,37 @@
 Objective-C Language Changes in Clang
 -
 
-OpenCL C Language Changes in Clang
---
+OpenCL Kernel Language Changes in Clang
+---
 
-...
+OpenCL 3.0 is completed, but remains experimental:
+
+- Added parsing support for optionality of device-side enqueue and blocks.
+- Added missing support for optionality of various builtin functions:
+
+  - ``read_write`` images, pipes, collective workgroup in the default header.
+  - ``read_write`` images, named address space atomics in internal 
``opencl-c.h``
+(enabled via ``-finclude-default-header`` frontend flag).
+
+C++ for OpenCL:
+
+- Added experimental support of C++ for OpenCL 2021 as per `the provisional
+  language documentation
+  
`_.
+  Support of all optional features is aligned with OpenCL 3.0.
+- Added ``__remove_address_space`` utility (documentation available in
+  :doc:`LanguageExtensions`).
+- Fixed address space for temporaries (to be ``__private``).
+- Disallowed static kernel functions.
+- Fixed implicit definition of ``__cpp_threadsafe_static_init`` macro.
+
+Misc changes:
+
+- Added generation of SPIR-V binaries via external ``llvm-spirv`` tool.
+  For more details refer to :ref:`the SPIR-V support section `.
+- Added new extensions for ``atomic_half`` and ``cl_ext_float_atomics``.
+- Fixed/improved support of ``vload``/``vstore``.
+- Fixed incorrect ``as_type`` support for 3-element vector types.
 
 ABI Changes in Clang
 


Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -18,7 +18,7 @@
 Introduction
 
 
-This document contains the release notes for the Clang C/C++/Objective-C
+This document contains the release notes for the Clang C/C++/Objective-C/OpenCL
 frontend, part of the LLVM Compiler Infrastructure, release |release|. Here we
 describe the status of Clang in some detail, including major
 improvements from the previous release and new feature work. For the
@@ -49,6 +49,8 @@
 
 - Added SPIR-V triple and binary generation using external ``llvm-spirv`` tool.
   For more details refer to :ref:`the SPIR-V support section `.
+- Completed support of OpenCL C 3.0 and C++ for OpenCL 2021 at experimental
+  state.
 -  ...
 
 Improvements to Clang's diagnostics
@@ -255,10 +257,37 @@
 Objective-C Language Changes in Clang
 -
 
-OpenCL C Language Changes in Clang
---
+OpenCL Kernel Language Changes in Clang
+---
 
-...
+OpenCL 3.0 is completed, but remains experimental:
+
+- Added parsing support for optionality of device-side enqueue and blocks.
+- Added missing support for optionality of various builtin functions:
+
+  - ``read_write`` images, pipes, collective workgroup in the default header.
+  - ``read_write`` images, named address space atomics in internal ``opencl-c.h``
+(enabled via ``-finclude-default-header`` frontend flag).
+
+C++ for OpenCL:
+
+- Added experimental support of C++ for OpenCL 2021 as per `the provisional
+  language documentation
+  `_.
+  Support of all optional features is aligned with OpenCL 3.0.
+- Added ``__remove_address_space`` utility (documentation available in
+  :doc:`LanguageExtensions`).
+- Fixed address space for temporaries (to be ``__private``).
+- Disallowed static kernel functions.
+- Fixed implicit definition of ``__cpp_threadsafe_static_init`` macro.
+
+Misc changes:
+
+- Added generation of SPIR-V binaries v

[clang] 074451b - [OpenCL] opencl-c.h: fix atomic_fetch_max with addrspace

2022-02-15 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-02-15T12:12:03Z
New Revision: 074451bd3352e022d015545e9091002d052daaa3

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

LOG: [OpenCL] opencl-c.h: fix atomic_fetch_max with addrspace

Commit 3c7d2f1b67d1 ("[OpenCL] opencl-c.h: add CL 3.0 non-generic
address space atomics", 2021-07-30) added some atomic_fetch_add/sub
overloads with uintptr_t arguments twice.  Instead, they should have
been atomic_fetch_max overloads with non-generic address spaces.

Added: 


Modified: 
clang/lib/Headers/opencl-c.h

Removed: 




diff  --git a/clang/lib/Headers/opencl-c.h b/clang/lib/Headers/opencl-c.h
index 98c92fd7ef0a3..7a2ddc47c9a1b 100644
--- a/clang/lib/Headers/opencl-c.h
+++ b/clang/lib/Headers/opencl-c.h
@@ -13424,8 +13424,8 @@ long __ovld atomic_fetch_max(volatile __global 
atomic_long *object, long operand
 long __ovld atomic_fetch_max(volatile __local atomic_long *object, long 
operand);
 ulong __ovld atomic_fetch_max(volatile __global atomic_ulong *object, ulong 
operand);
 ulong __ovld atomic_fetch_max(volatile __local atomic_ulong *object, ulong 
operand);
-uintptr_t __ovld atomic_fetch_add(volatile __global atomic_uintptr_t *object, 
ptr
diff _t operand);
-uintptr_t __ovld atomic_fetch_sub(volatile __local atomic_uintptr_t *object, 
ptr
diff _t operand);
+uintptr_t __ovld atomic_fetch_max(volatile __global atomic_uintptr_t *object, 
uintptr_t operand);
+uintptr_t __ovld atomic_fetch_max(volatile __local atomic_uintptr_t *object, 
uintptr_t operand);
 #endif //defined(cl_khr_int64_base_atomics) && 
defined(cl_khr_int64_extended_atomics)
 #endif // (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 || __OPENCL_CPP_VERSION__ >= 
202100)
 #endif
@@ -13543,8 +13543,8 @@ long __ovld atomic_fetch_max_explicit(volatile __global 
atomic_long *object, lon
 long __ovld atomic_fetch_max_explicit(volatile __local atomic_long *object, 
long operand, memory_order order);
 ulong __ovld atomic_fetch_max_explicit(volatile __global atomic_ulong *object, 
ulong operand, memory_order order);
 ulong __ovld atomic_fetch_max_explicit(volatile __local atomic_ulong *object, 
ulong operand, memory_order order);
-uintptr_t __ovld atomic_fetch_add_explicit(volatile __global atomic_uintptr_t 
*object, ptr
diff _t operand, memory_order order);
-uintptr_t __ovld atomic_fetch_sub_explicit(volatile __local atomic_uintptr_t 
*object, ptr
diff _t operand, memory_order order);
+uintptr_t __ovld atomic_fetch_max_explicit(volatile __global atomic_uintptr_t 
*object, uintptr_t operand, memory_order order);
+uintptr_t __ovld atomic_fetch_max_explicit(volatile __local atomic_uintptr_t 
*object, uintptr_t operand, memory_order order);
 #endif //defined(cl_khr_int64_base_atomics) && 
defined(cl_khr_int64_extended_atomics)
 #endif // (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 || __OPENCL_CPP_VERSION__ >= 
202100)
 #endif
@@ -13661,8 +13661,8 @@ long __ovld atomic_fetch_max_explicit(volatile __global 
atomic_long *object, lon
 long __ovld atomic_fetch_max_explicit(volatile __local atomic_long *object, 
long operand, memory_order order, memory_scope scope);
 ulong __ovld atomic_fetch_max_explicit(volatile __global atomic_ulong *object, 
ulong operand, memory_order order, memory_scope scope);
 ulong __ovld atomic_fetch_max_explicit(volatile __local atomic_ulong *object, 
ulong operand, memory_order order, memory_scope scope);
-uintptr_t __ovld atomic_fetch_add_explicit(volatile __global atomic_uintptr_t 
*object, ptr
diff _t operand, memory_order order, memory_scope scope);
-uintptr_t __ovld atomic_fetch_sub_explicit(volatile __local atomic_uintptr_t 
*object, ptr
diff _t operand, memory_order order, memory_scope scope);
+uintptr_t __ovld atomic_fetch_max_explicit(volatile __global atomic_uintptr_t 
*object, uintptr_t operand, memory_order order, memory_scope scope);
+uintptr_t __ovld atomic_fetch_max_explicit(volatile __local atomic_uintptr_t 
*object, uintptr_t operand, memory_order order, memory_scope scope);
 #endif //defined(cl_khr_int64_base_atomics) && 
defined(cl_khr_int64_extended_atomics)
 #endif // (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 || __OPENCL_CPP_VERSION__ >= 
202100)
 



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


[PATCH] D119829: [Driver] Support Solaris/amd64 GetTls

2022-02-15 Thread Rainer Orth via Phabricator via cfe-commits
ro created this revision.
ro added a reviewer: MaskRay.
ro added a project: clang.
Herald added subscribers: fedor.sergeev, jyknight.
ro requested review of this revision.

This is the driver part of D91605 , a 
workaround to allow direct calls to `__tls_get_addr` on Solaris/amd64.

Tested on `amd64-pc-solaris2.11` and `sparcv9-sun-solaris2.11`.

This adds a testcase to the original submission.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119829

Files:
  clang/lib/Driver/ToolChains/Solaris.cpp
  clang/test/Driver/solaris-ld-sanitizer.c

Index: clang/test/Driver/solaris-ld-sanitizer.c
===
--- /dev/null
+++ clang/test/Driver/solaris-ld-sanitizer.c
@@ -0,0 +1,67 @@
+// General tests that the ld -z relax=transtls workaround is only applied
+// on Solaris/amd64. Note that we use sysroot to make these tests
+// independent of the host system.
+
+// Check sparc-sun-solaris2.11, 32bit
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: --target=sparc-sun-solaris2.11 \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/solaris_sparc_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-SPARC32 %s
+// CHECK-LD-SPARC32-NOT: -zrelax=transtls
+
+// Check sparc-sun-solaris2.11, 32bit
+// RUN: %clang -no-canonical-prefixes -fsanitize=undefined %s -### -o %t.o 2>&1 \
+// RUN: --target=sparc-sun-solaris2.11 \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/solaris_sparc_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-SPARC32 %s
+// CHECK-LD-SPARC32-NOT: -zrelax=transtls
+
+// Check sparc-sun-solaris2.11, 64bit
+// RUN: %clang -no-canonical-prefixes -m64 %s -### -o %t.o 2>&1 \
+// RUN: --target=sparc-sun-solaris2.11 \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/solaris_sparc_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-SPARC64 %s
+// CHECK-LD-SPARC64-NOT: -zrelax=transtls
+
+// Check sparc-sun-solaris2.11, 64bit
+// RUN: %clang -no-canonical-prefixes -m64 -fsanitize=undefined %s -### -o %t.o 2>&1 \
+// RUN: --target=sparc-sun-solaris2.11 \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/solaris_sparc_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-SPARC64 %s
+// CHECK-LD-SPARC64-NOT: -zrelax=transtls
+
+// Check i386-pc-solaris2.11, 32bit
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: --target=i386-pc-solaris2.11 \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/solaris_x86_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-X32 %s
+// CHECK-LD-X32-NOT: -zrelax=transtls
+
+// Check i386-pc-solaris2.11, 32bit
+// RUN: %clang -no-canonical-prefixes -fsanitize=undefined %s -### -o %t.o 2>&1 \
+// RUN: --target=i386-pc-solaris2.11 \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/solaris_x86_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-X32 %s
+// CHECK-LD-X32-NOT: -zrelax=transtls
+
+// Check i386-pc-solaris2.11, 64bit
+// RUN: %clang -no-canonical-prefixes -m64 %s -### -o %t.o 2>&1 \
+// RUN: --target=i386-pc-solaris2.11 \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/solaris_x86_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-X64 %s
+// CHECK-LD-X64-NOT: -zrelax=transtls
+
+// Check i386-pc-solaris2.11, 64bit
+// RUN: %clang -no-canonical-prefixes -m64 -fsanitize=undefined %s -### -o %t.o 2>&1 \
+// RUN: --target=i386-pc-solaris2.11 \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/solaris_x86_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-X64-UBSAN %s
+// CHECK-LD-X64-UBSAN: -zrelax=transtls
Index: clang/lib/Driver/ToolChains/Solaris.cpp
===
--- clang/lib/Driver/ToolChains/Solaris.cpp
+++ clang/lib/Driver/ToolChains/Solaris.cpp
@@ -14,6 +14,8 @@
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/Options.h"
+#include "clang/Driver/SanitizerArgs.h"
+#include "clang/Driver/ToolChain.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
@@ -145,8 +147,18 @@
   CmdArgs.push_back("-lgcc");
   CmdArgs.push_back("-lm");
 }
-if (NeedsSanitizerDeps)
+if (NeedsSanitizerDeps) {
   linkSanitizerRuntimeDeps(getToolChain(), CmdArgs);
+
+  // Work around Solaris/amd64 ld bug when calling __tls_get_addr directly.
+  // However, ld -z relax=transtls is available since Solaris 11.2, but not
+  // in Illumos.
+  const SanitizerArgs &SA = getToolChain().getSanitizerArgs(Args);
+  if (getToolChain().getTriple().getArch() == llvm::Triple::x86_64 &&
+  (SA.needsAsanRt() || SA.needsStatsRt() ||
+   (SA.needsUbsanRt() && !SA.requiresMinimalRuntime(
+CmdArgs.push_back("-zrelax=transtls");
+}
   }
 
   if (!Args.hasArg(option

[PATCH] D91605: [sanitizers] Implement GetTls on Solaris

2022-02-15 Thread Rainer Orth via Phabricator via cfe-commits
ro added a comment.

In D91605#3321556 , @MaskRay wrote:

> The Clang driver change should be in a separate patch with clang/test/Driver 
> tests.

Done now: D119829 .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91605

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


[PATCH] D119409: [C++20] [Modules] Remain variable's definition in module interface

2022-02-15 Thread Nathan Sidwell via Phabricator via cfe-commits
urnathan added inline comments.



Comment at: clang/test/CXX/modules-ts/basic/basic.def.odr/p4/module.cpp:5
 // CHECK-DAG: @extern_var_exported = external {{(dso_local )?}}global
-// CHECK-DAG: @inline_var_exported = linkonce_odr {{(dso_local )?}}global
+// CHECK-DAG: @inline_var_exported = available_externally {{(dso_local 
)?}}global
 // CHECK-DAG: @const_var_exported = available_externally {{(dso_local 
)?}}constant i32 3,

ChuanqiXu wrote:
> urnathan wrote:
> > ChuanqiXu wrote:
> > > urnathan wrote:
> > > > I don;t think this is correct.  That should still be a linkonce odr, 
> > > > otherwise you'll get conflicts with other module implementation units.
> > > It is still linkonce_odr in the module it get defined. See the new added 
> > > test case: inline-variable-in-module.cpp for example. The attribute 
> > > `available_externally` is equivalent to external from the perspective of 
> > > linker. See https://llvm.org/docs/LangRef.html#linkage-types. According 
> > > to [dcl.inline]p7, inline variable attached to named module should be 
> > > defined in that domain. Note that the variable attached to global module 
> > > fragment and private module fragment shouldn't be accessed outside the 
> > > module, so it implies that all the variable defined in the module could 
> > > only be defined in the module unit itself.
> > There's a couple of issues with this.  module.cppm is emitting a (linkonce) 
> > definition of inlne_var_exported, but only because it itself is ODR-using 
> > that variable.  If you take out the ODR-use in noninline_exported, there is 
> > no longer a symbol emitted.
> > 
> > But, even if you forced inline vars to be emitted in their 
> > defining-module's interface unit, that would be an ABI change.  inline vars 
> > are emitted whereever ODR-used.  They have no fixed home TU.  Now, we could 
> > alter the ABI and allow interface units to define a home location for 
> > inline vars and similar entities (eg, vtables for keyless classes).  But 
> > we'd need buy-in from other compilers to do that.
> > 
> > FWIW such a discussion did come up early in implementing modules-ts, but we 
> > decided there was enough going on just getting the TS implemented.  I'm 
> > fine with revisiting that, but it is a more significant change.
> > 
> > And it wouldn't apply to (eg) templated variables, which of course could be 
> > instantiated anywhere.
> Oh, now the key point here is what the correct behavior is instead of the 
> patch. Let's discuss it first.
> 
> According to [[ http://eel.is/c++draft/dcl.inline#7 | [dcl.inline]p7 ]], 
> > If an inline function or variable that is attached to a named module is 
> > declared in a definition domain, it shall be defined in that domain.
> 
> I think the intention of the sentence is to define inline variable in the 
> module interface. So if it is required by the standard, I think other 
> compiler need to follow up. As I described in the summary, it might be a 
> difference between C++20 module and ModuleTS. Do you think it is necessary to 
> send the question to WG21? (I get the behavior from reading the words. Maybe 
> I misread or the word is not intentional).
> 
> Maybe the ABI standard group need to discuss what the linkage should be. Now 
> it may be weak_odr or linkonce_odr. It depends on how we compile the file. If 
> we compile the .cppm file directly, it would be linkonce_odr. And if we 
> compile it to *.pcm file first, it would be weak_odr. I have registered an 
> issue for this: https://github.com/llvm/llvm-project/issues/53838.
> Oh, now the key point here is what the correct behavior is instead of the 
> patch. Let's discuss it first.
> 
> According to [[ http://eel.is/c++draft/dcl.inline#7 | [dcl.inline]p7 ]], 
> > If an inline function or variable that is attached to a named module is 
> > declared in a definition domain, it shall be defined in that domain.
> 
> I think the intention of the sentence is to define inline variable in the 
> module interface. So if it is required by the standard, I think other 
> compiler need to follow up. As I described in the summary, it might be a 
> difference between C++20 module and ModuleTS. Do you think it is necessary to 
> send the question to WG21? (I get the behavior from reading the words. Maybe 
> I misread or the word is not intentional).

You are reading more into the std than it says.  The std specifies what /source 
code/ is meaningful.  It says nothing about how a computation system might 
represent the program in another form.  Most of the latter, for ahead-of-time 
translation, is at the discretion of compiler implementors.  Part of that is 
the domain of the ABI, which specifies an interface to which different 
compilers may target, and then have compatibility at the object-file boundary. 

> Maybe the ABI standard group need to discuss what the linkage should be. 

Correct. And right now there is no consensus to do anything different with such 
entities

[PATCH] D119560: [OpenCL] opencl-c.h: remove arg names from atomics

2022-02-15 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.



> also makes the header no longer "claim" the identifiers "success",
> "failure", "desired", "value" (such that you can compile with -Dvalue=...
> when including the header for example, which currently breaks parsing
> of the header).

I don't get what you mean by this. :)

> This is a big patch and it only touches the OpenCL 2 atomics for now. I
> wonder if we should remove argument names from the other builtins too?
> I think it would help unifying the header and tablegen approaches: if we
> gradually move the header into some canonical form, we might be able
> to eventually replace it with a tablegen-ed header, while being able to
> easily confirm equivalence.

The only drawback I see if that we will lose the history a bit in "git blame" 
but:

- The biggest part of the header was committed in one block anyway
- We should drive toward deprecation of the header development and moving it

towards testing only feature.
So I think this is totally justifiable since it is a good step towards the end 
goal.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119560

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


[PATCH] D119560: [OpenCL] opencl-c.h: remove arg names from atomics

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

LGTM! Thanks


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119560

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


[PATCH] D119398: [OpenCL] Guard atomic_double with cl_khr_int64_base_atomics and cl_khr_int64_extended_atomics

2022-02-15 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

Can this be committed now?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119398

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


[clang] 0209390 - [clang][NFC] Remove IgnoreLinkageSpecDecls

2022-02-15 Thread Nathan Sidwell via cfe-commits

Author: Nathan Sidwell
Date: 2022-02-15T04:28:45-08:00
New Revision: 02093906fa0fd5bacc61b2189ea643c78cd02509

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

LOG: [clang][NFC] Remove IgnoreLinkageSpecDecls

The Itanium mangler uses IgnoreLinkageSpecDecls to strip linkage spec
contexts.  It doesn't do this consistently, but there is no need for
it to do it at all.  getEffectiveDeclContext never returns a linkage
spec, as it either recurses, uses getRedeclContext (which itself
removes the specs), or gets the decl context of non-namespace entities.

This patch removes the function and all calls to it.  For safety I add
a couple of asserts to make sure we never get them.

Reviewed By: ChuanqiXu

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

Added: 


Modified: 
clang/lib/AST/ItaniumMangle.cpp

Removed: 




diff  --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index b15669d426bd6..b92a6a07ff1f7 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -862,18 +862,9 @@ void CXXNameMangler::mangleFunctionEncodingBareType(const 
FunctionDecl *FD) {
  MangleReturnType, FD);
 }
 
-static const DeclContext *IgnoreLinkageSpecDecls(const DeclContext *DC) {
-  while (isa(DC)) {
-DC = getEffectiveParentContext(DC);
-  }
-
-  return DC;
-}
-
 /// Return whether a given namespace is the 'std' namespace.
 static bool isStd(const NamespaceDecl *NS) {
-  if (!IgnoreLinkageSpecDecls(getEffectiveParentContext(NS))
-->isTranslationUnit())
+  if (!getEffectiveParentContext(NS)->isTranslationUnit())
 return false;
 
   const IdentifierInfo *II = NS->getOriginalNamespace()->getIdentifier();
@@ -978,7 +969,7 @@ void CXXNameMangler::mangleNameWithAbiTags(GlobalDecl GD,
 return;
   }
 
-  DC = IgnoreLinkageSpecDecls(DC);
+  assert(!isa(DC) && "context cannot be LinkageSpecDecl");
 
   if (isLocalContainerContext(DC)) {
 mangleLocalName(GD, AdditionalAbiTags);
@@ -1054,7 +1045,7 @@ void CXXNameMangler::mangleModuleNamePrefix(StringRef 
Name) {
 void CXXNameMangler::mangleTemplateName(const TemplateDecl *TD,
 const TemplateArgument *TemplateArgs,
 unsigned NumTemplateArgs) {
-  const DeclContext *DC = IgnoreLinkageSpecDecls(getEffectiveDeclContext(TD));
+  const DeclContext *DC = getEffectiveDeclContext(TD);
 
   if (DC->isTranslationUnit() || isStdNamespace(DC)) {
 mangleUnscopedTemplateName(TD, nullptr);
@@ -1070,7 +1061,7 @@ void CXXNameMangler::mangleUnscopedName(GlobalDecl GD,
   //   ::= 
   //  ::= St# ::std::
 
-  if (isStdNamespace(IgnoreLinkageSpecDecls(getEffectiveDeclContext(ND
+  if (isStdNamespace(getEffectiveDeclContext(ND)))
 Out << "St";
 
   mangleUnqualifiedName(GD, AdditionalAbiTags);
@@ -2030,7 +2021,7 @@ void CXXNameMangler::manglePrefix(const DeclContext *DC, 
bool NoFunction) {
   //   ::= # empty
   //   ::= 
 
-  DC = IgnoreLinkageSpecDecls(DC);
+  assert(!isa(DC) && "prefix cannot be LinkageSpecDecl");
 
   if (DC->isTranslationUnit())
 return;



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


[PATCH] D119748: [clang][NFC] Remove IgnoreLinkageSpecDecls

2022-02-15 Thread Nathan Sidwell via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG02093906fa0f: [clang][NFC] Remove IgnoreLinkageSpecDecls 
(authored by urnathan).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119748

Files:
  clang/lib/AST/ItaniumMangle.cpp


Index: clang/lib/AST/ItaniumMangle.cpp
===
--- clang/lib/AST/ItaniumMangle.cpp
+++ clang/lib/AST/ItaniumMangle.cpp
@@ -862,18 +862,9 @@
  MangleReturnType, FD);
 }
 
-static const DeclContext *IgnoreLinkageSpecDecls(const DeclContext *DC) {
-  while (isa(DC)) {
-DC = getEffectiveParentContext(DC);
-  }
-
-  return DC;
-}
-
 /// Return whether a given namespace is the 'std' namespace.
 static bool isStd(const NamespaceDecl *NS) {
-  if (!IgnoreLinkageSpecDecls(getEffectiveParentContext(NS))
-->isTranslationUnit())
+  if (!getEffectiveParentContext(NS)->isTranslationUnit())
 return false;
 
   const IdentifierInfo *II = NS->getOriginalNamespace()->getIdentifier();
@@ -978,7 +969,7 @@
 return;
   }
 
-  DC = IgnoreLinkageSpecDecls(DC);
+  assert(!isa(DC) && "context cannot be LinkageSpecDecl");
 
   if (isLocalContainerContext(DC)) {
 mangleLocalName(GD, AdditionalAbiTags);
@@ -1054,7 +1045,7 @@
 void CXXNameMangler::mangleTemplateName(const TemplateDecl *TD,
 const TemplateArgument *TemplateArgs,
 unsigned NumTemplateArgs) {
-  const DeclContext *DC = IgnoreLinkageSpecDecls(getEffectiveDeclContext(TD));
+  const DeclContext *DC = getEffectiveDeclContext(TD);
 
   if (DC->isTranslationUnit() || isStdNamespace(DC)) {
 mangleUnscopedTemplateName(TD, nullptr);
@@ -1070,7 +1061,7 @@
   //   ::= 
   //  ::= St# ::std::
 
-  if (isStdNamespace(IgnoreLinkageSpecDecls(getEffectiveDeclContext(ND
+  if (isStdNamespace(getEffectiveDeclContext(ND)))
 Out << "St";
 
   mangleUnqualifiedName(GD, AdditionalAbiTags);
@@ -2030,7 +2021,7 @@
   //   ::= # empty
   //   ::= 
 
-  DC = IgnoreLinkageSpecDecls(DC);
+  assert(!isa(DC) && "prefix cannot be LinkageSpecDecl");
 
   if (DC->isTranslationUnit())
 return;


Index: clang/lib/AST/ItaniumMangle.cpp
===
--- clang/lib/AST/ItaniumMangle.cpp
+++ clang/lib/AST/ItaniumMangle.cpp
@@ -862,18 +862,9 @@
  MangleReturnType, FD);
 }
 
-static const DeclContext *IgnoreLinkageSpecDecls(const DeclContext *DC) {
-  while (isa(DC)) {
-DC = getEffectiveParentContext(DC);
-  }
-
-  return DC;
-}
-
 /// Return whether a given namespace is the 'std' namespace.
 static bool isStd(const NamespaceDecl *NS) {
-  if (!IgnoreLinkageSpecDecls(getEffectiveParentContext(NS))
-->isTranslationUnit())
+  if (!getEffectiveParentContext(NS)->isTranslationUnit())
 return false;
 
   const IdentifierInfo *II = NS->getOriginalNamespace()->getIdentifier();
@@ -978,7 +969,7 @@
 return;
   }
 
-  DC = IgnoreLinkageSpecDecls(DC);
+  assert(!isa(DC) && "context cannot be LinkageSpecDecl");
 
   if (isLocalContainerContext(DC)) {
 mangleLocalName(GD, AdditionalAbiTags);
@@ -1054,7 +1045,7 @@
 void CXXNameMangler::mangleTemplateName(const TemplateDecl *TD,
 const TemplateArgument *TemplateArgs,
 unsigned NumTemplateArgs) {
-  const DeclContext *DC = IgnoreLinkageSpecDecls(getEffectiveDeclContext(TD));
+  const DeclContext *DC = getEffectiveDeclContext(TD);
 
   if (DC->isTranslationUnit() || isStdNamespace(DC)) {
 mangleUnscopedTemplateName(TD, nullptr);
@@ -1070,7 +1061,7 @@
   //   ::= 
   //  ::= St# ::std::
 
-  if (isStdNamespace(IgnoreLinkageSpecDecls(getEffectiveDeclContext(ND
+  if (isStdNamespace(getEffectiveDeclContext(ND)))
 Out << "St";
 
   mangleUnqualifiedName(GD, AdditionalAbiTags);
@@ -2030,7 +2021,7 @@
   //   ::= # empty
   //   ::= 
 
-  DC = IgnoreLinkageSpecDecls(DC);
+  assert(!isa(DC) && "prefix cannot be LinkageSpecDecl");
 
   if (DC->isTranslationUnit())
 return;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D119398: [OpenCL] Guard atomic_double with cl_khr_int64_base_atomics and cl_khr_int64_extended_atomics

2022-02-15 Thread Yang Haonan via Phabricator via cfe-commits
haonanya added a comment.

Hi, @Anastasia. Please help to land it, thanks very much.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119398

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


[PATCH] D119560: [OpenCL] opencl-c.h: remove arg names from atomics

2022-02-15 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh added a comment.

In D119560#3322531 , @Anastasia wrote:

>> also makes the header no longer "claim" the identifiers "success",
>> "failure", "desired", "value" (such that you can compile with -Dvalue=...
>> when including the header for example, which currently breaks parsing
>> of the header).
>
> I don't get what you mean by this. :)

Compiling a CL source file with e.g. `clang -cl-std=CL2.0 -Xclang 
-finclude-default-header -cl-no-stdinc -Dvalue=1 
clang/test/CodeGenOpenCL/as_type.cl` gives lots of errors such as the 
following, because defining `value` as a macro (which is not a reserved 
identifier as far as I'm aware) collides with the argument names in the header:

  In file included from :1:
  lib/clang/15.0.0/include/opencl-c.h:13277:58: error: expected ')'
  void __ovld atomic_init(volatile atomic_int *object, int value);
   ^
  :1:15: note: expanded from here
  #define value 1



>> This is a big patch and it only touches the OpenCL 2 atomics for now. I
>> wonder if we should remove argument names from the other builtins too?
>> I think it would help unifying the header and tablegen approaches: if we
>> gradually move the header into some canonical form, we might be able
>> to eventually replace it with a tablegen-ed header, while being able to
>> easily confirm equivalence.
>
> The only drawback I see if that we will lose the history a bit in "git blame" 
> but:

Slight nuance: we will not lose any history, but I understand your concern: 
someone needs to look through this commit to see the previous commit that 
touched the code.

If there are no objections to removing all argument names from the header, I'll 
try to prepare patches for doing so.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119560

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


[PATCH] D119726: [asan] Add support for disable_sanitizer_instrumentation attribute

2022-02-15 Thread Alexander Potapenko via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGdd145f953db3: [asan] Add support for 
disable_sanitizer_instrumentation attribute (authored by glider).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119726

Files:
  clang/docs/AddressSanitizer.rst
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/SanitizerMetadata.cpp
  clang/test/CodeGen/address-safety-attr-flavors.cpp
  clang/test/CodeGen/asan-globals.cpp
  llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
  
llvm/test/Instrumentation/AddressSanitizer/asan-disable-sanitizer-instrumentation.ll

Index: llvm/test/Instrumentation/AddressSanitizer/asan-disable-sanitizer-instrumentation.ll
===
--- /dev/null
+++ llvm/test/Instrumentation/AddressSanitizer/asan-disable-sanitizer-instrumentation.ll
@@ -0,0 +1,47 @@
+; This test checks that we are not instrumenting sanitizer code.
+; RUN: opt < %s -passes='asan-pipeline' -S | FileCheck %s
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+; Function with sanitize_address is instrumented.
+; Function Attrs: nounwind uwtable
+define void @instr_sa(i32* %a) sanitize_address {
+entry:
+  %tmp1 = load i32, i32* %a, align 4
+  %tmp2 = add i32 %tmp1,  1
+  store i32 %tmp2, i32* %a, align 4
+  ret void
+}
+
+; CHECK-LABEL: @instr_sa
+; CHECK: call void @__asan_report_load
+
+
+; Function with disable_sanitizer_instrumentation is not instrumented.
+; Function Attrs: nounwind uwtable
+define void @noinstr_dsi(i32* %a) disable_sanitizer_instrumentation {
+entry:
+  %tmp1 = load i32, i32* %a, align 4
+  %tmp2 = add i32 %tmp1,  1
+  store i32 %tmp2, i32* %a, align 4
+  ret void
+}
+
+; CHECK-LABEL: @noinstr_dsi
+; CHECK-NOT: call void @__asan_report_load
+
+
+; disable_sanitizer_instrumentation takes precedence over sanitize_address.
+; Function Attrs: nounwind uwtable
+define void @noinstr_dsi_sa(i32* %a) disable_sanitizer_instrumentation sanitize_address {
+entry:
+  %tmp1 = load i32, i32* %a, align 4
+  %tmp2 = add i32 %tmp1,  1
+  store i32 %tmp2, i32* %a, align 4
+  ret void
+}
+
+; CHECK-LABEL: @noinstr_dsi_sa
+; CHECK-NOT: call void @__asan_report_load
+
Index: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
===
--- llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -2888,6 +2888,9 @@
   // Leave if the function doesn't need instrumentation.
   if (!F.hasFnAttribute(Attribute::SanitizeAddress)) return FunctionModified;
 
+  if (F.hasFnAttribute(Attribute::DisableSanitizerInstrumentation))
+return FunctionModified;
+
   LLVM_DEBUG(dbgs() << "ASAN instrumenting:\n" << F << "\n");
 
   initializeCallbacks(*F.getParent());
Index: clang/test/CodeGen/asan-globals.cpp
===
--- clang/test/CodeGen/asan-globals.cpp
+++ clang/test/CodeGen/asan-globals.cpp
@@ -10,6 +10,7 @@
 int global;
 int dyn_init_global = global;
 int __attribute__((no_sanitize("address"))) attributed_global;
+int __attribute__((disable_sanitizer_instrumentation)) disable_instrumentation_global;
 int ignorelisted_global;
 
 int __attribute__((section("__DATA, __common"))) sectioned_global; // KASAN - ignore globals in a section
@@ -50,31 +51,33 @@
 // UWTABLE: attributes #[[#ATTR]] = { nounwind uwtable }
 // UWTABLE: ![[#]] = !{i32 7, !"uwtable", i32 2}
 
-// CHECK: !llvm.asan.globals = !{![[EXTRA_GLOBAL:[0-9]+]], ![[GLOBAL:[0-9]+]], ![[DYN_INIT_GLOBAL:[0-9]+]], ![[ATTR_GLOBAL:[0-9]+]], ![[IGNORELISTED_GLOBAL:[0-9]+]], ![[SECTIONED_GLOBAL:[0-9]+]], ![[SPECIAL_GLOBAL:[0-9]+]], ![[STATIC_VAR:[0-9]+]], ![[LITERAL:[0-9]+]]}
+// CHECK: !llvm.asan.globals = !{![[EXTRA_GLOBAL:[0-9]+]], ![[GLOBAL:[0-9]+]], ![[DYN_INIT_GLOBAL:[0-9]+]], ![[ATTR_GLOBAL:[0-9]+]], ![[DISABLE_INSTR_GLOBAL:[0-9]+]], ![[IGNORELISTED_GLOBAL:[0-9]+]], ![[SECTIONED_GLOBAL:[0-9]+]], ![[SPECIAL_GLOBAL:[0-9]+]], ![[STATIC_VAR:[0-9]+]], ![[LITERAL:[0-9]+]]}
 // CHECK: ![[EXTRA_GLOBAL]] = !{{{.*}} ![[EXTRA_GLOBAL_LOC:[0-9]+]], !"extra_global", i1 false, i1 false}
 // CHECK: ![[EXTRA_GLOBAL_LOC]] = !{!"{{.*}}extra-source.cpp", i32 1, i32 5}
 // CHECK: ![[GLOBAL]] = !{{{.*}} ![[GLOBAL_LOC:[0-9]+]], !"global", i1 false, i1 false}
 // CHECK: ![[GLOBAL_LOC]] = !{!"{{.*}}asan-globals.cpp", i32 10, i32 5}
 // CHECK: ![[DYN_INIT_GLOBAL]] = !{{{.*}} ![[DYN_INIT_LOC:[0-9]+]], !"dyn_init_global", i1 true, i1 false}
 // CHECK: ![[DYN_INIT_LOC]] = !{!"{{.*}}asan-globals.cpp", i32 11, i32 5}
-// CHECK: ![[ATTR_GLOBAL]] = !{{{.*}}, null, null, i1 false, i1 true}
-// CHECK: ![[IGNORELISTED_GLOBAL]] = !{{{.*}}, null, null, i1 false, i1 true}
+// CHECK: ![[ATTR_GLOBAL]] = !{{{.*attributed_global.*}}, null, null, i1 false, i1 true}
+// CHECK: ![[DIS

[clang] dd145f9 - [asan] Add support for disable_sanitizer_instrumentation attribute

2022-02-15 Thread Alexander Potapenko via cfe-commits

Author: Alexander Potapenko
Date: 2022-02-15T14:06:12+01:00
New Revision: dd145f953db3dafbc019f1d3783bb4f09a28af92

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

LOG: [asan] Add support for disable_sanitizer_instrumentation attribute

For ASan this will effectively serve as a synonym for
__attribute__((no_sanitize("address")))

This is a reland of https://reviews.llvm.org/D114421

Reviewed By: melver, eugenis

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

Added: 

llvm/test/Instrumentation/AddressSanitizer/asan-disable-sanitizer-instrumentation.ll

Modified: 
clang/docs/AddressSanitizer.rst
clang/lib/CodeGen/CodeGenFunction.cpp
clang/lib/CodeGen/SanitizerMetadata.cpp
clang/test/CodeGen/address-safety-attr-flavors.cpp
clang/test/CodeGen/asan-globals.cpp
llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp

Removed: 




diff  --git a/clang/docs/AddressSanitizer.rst b/clang/docs/AddressSanitizer.rst
index 06b53e2e5da0b..fe5f683580a46 100644
--- a/clang/docs/AddressSanitizer.rst
+++ b/clang/docs/AddressSanitizer.rst
@@ -229,6 +229,12 @@ compilers, so we suggest to use it together with
 The same attribute used on a global variable prevents AddressSanitizer
 from adding redzones around it and detecting out of bounds accesses.
 
+
+AddressSanitizer also supports
+``__attribute__((disable_sanitizer_instrumentation))``. This attribute
+works similar to ``__attribute__((no_sanitize("address")))``, but it also
+prevents instrumentation performed by other sanitizers.
+
 Suppressing Errors in Recompiled Code (Ignorelist)
 --
 

diff  --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index ba077650f237a..bd29842afbaa9 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -383,9 +383,6 @@ void CodeGenFunction::FinishFunction(SourceLocation EndLoc) 
{
"__cyg_profile_func_exit");
   }
 
-  if (ShouldSkipSanitizerInstrumentation())
-CurFn->addFnAttr(llvm::Attribute::DisableSanitizerInstrumentation);
-
   // Emit debug descriptor for function end.
   if (CGDebugInfo *DI = getDebugInfo())
 DI->EmitFunctionEnd(Builder, CurFn);
@@ -767,17 +764,22 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, 
QualType RetTy,
   Fn->addFnAttr(llvm::Attribute::NoSanitizeCoverage);
   }
 
-  // Apply sanitizer attributes to the function.
-  if (SanOpts.hasOneOf(SanitizerKind::Address | SanitizerKind::KernelAddress))
-Fn->addFnAttr(llvm::Attribute::SanitizeAddress);
-  if (SanOpts.hasOneOf(SanitizerKind::HWAddress | 
SanitizerKind::KernelHWAddress))
-Fn->addFnAttr(llvm::Attribute::SanitizeHWAddress);
-  if (SanOpts.has(SanitizerKind::MemTag))
-Fn->addFnAttr(llvm::Attribute::SanitizeMemTag);
-  if (SanOpts.has(SanitizerKind::Thread))
-Fn->addFnAttr(llvm::Attribute::SanitizeThread);
-  if (SanOpts.hasOneOf(SanitizerKind::Memory | SanitizerKind::KernelMemory))
-Fn->addFnAttr(llvm::Attribute::SanitizeMemory);
+  if (ShouldSkipSanitizerInstrumentation()) {
+CurFn->addFnAttr(llvm::Attribute::DisableSanitizerInstrumentation);
+  } else {
+// Apply sanitizer attributes to the function.
+if (SanOpts.hasOneOf(SanitizerKind::Address | 
SanitizerKind::KernelAddress))
+  Fn->addFnAttr(llvm::Attribute::SanitizeAddress);
+if (SanOpts.hasOneOf(SanitizerKind::HWAddress |
+ SanitizerKind::KernelHWAddress))
+  Fn->addFnAttr(llvm::Attribute::SanitizeHWAddress);
+if (SanOpts.has(SanitizerKind::MemTag))
+  Fn->addFnAttr(llvm::Attribute::SanitizeMemTag);
+if (SanOpts.has(SanitizerKind::Thread))
+  Fn->addFnAttr(llvm::Attribute::SanitizeThread);
+if (SanOpts.hasOneOf(SanitizerKind::Memory | SanitizerKind::KernelMemory))
+  Fn->addFnAttr(llvm::Attribute::SanitizeMemory);
+  }
   if (SanOpts.has(SanitizerKind::SafeStack))
 Fn->addFnAttr(llvm::Attribute::SafeStack);
   if (SanOpts.has(SanitizerKind::ShadowCallStack))

diff  --git a/clang/lib/CodeGen/SanitizerMetadata.cpp 
b/clang/lib/CodeGen/SanitizerMetadata.cpp
index 009965a36c396..9e26d242d3a7e 100644
--- a/clang/lib/CodeGen/SanitizerMetadata.cpp
+++ b/clang/lib/CodeGen/SanitizerMetadata.cpp
@@ -73,6 +73,8 @@ void 
SanitizerMetadata::reportGlobalToASan(llvm::GlobalVariable *GV,
   for (auto Attr : D.specific_attrs())
 if (Attr->getMask() & SanitizerKind::Address)
   IsExcluded = true;
+  if (D.hasAttr())
+IsExcluded = true;
   reportGlobalToASan(GV, D.getLocation(), OS.str(), D.getType(), IsDynInit,
  IsExcluded);
 }

diff  --git a/clang/test/CodeGen/address-safety-attr-flavors.cpp 
b/clang/test/CodeGen/address-safety-attr-flavors.cpp
index e6d17ed2da340..ef81

[PATCH] D119823: [Modules] Add module structure output to -module-file-info.

2022-02-15 Thread Nathan Sidwell via Phabricator via cfe-commits
urnathan added inline comments.



Comment at: clang/lib/Frontend/FrontendActions.cpp:817-824
+#if 0
+  case Module::ModuleHeaderUnit:
+return "Header Unit";
+  case Module::ModulePartitionInterface:
+return "Partition Interface";
+  case Module::ModulePartitionImplementation:
+return "Partition Implementation";

belongs in a later patch?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119823

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


[PATCH] D119363: [clang] Add `ObjCProtocolLoc` to represent protocol references

2022-02-15 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan added a comment.

Thank you @dgoldman, this approach looks good to me.
I don't have anything to add other than what @sammccall has already commented.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119363

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


[PATCH] D119713: [Docs] Release 14 notes for SPIR-V in clang

2022-02-15 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh accepted this revision.
svenvh added a comment.
This revision is now accepted and ready to land.

LGTM


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

https://reviews.llvm.org/D119713

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


[PATCH] D119837: [RISCV] Fix the include search path order between sysroot and resource folder

2022-02-15 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng created this revision.
Herald added subscribers: VincentWu, luke957, achieveartificialintelligence, 
vkmr, frasercrmck, evandro, luismarques, apazos, sameer.abuasal, s.egerton, 
Jim, benna, psnobl, abidh, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, 
rogfer01, edward-jones, zzheng, jrtc27, niosHD, sabuasal, simoncook, johnrusso, 
rbar, asb.
kito-cheng requested review of this revision.
Herald added subscribers: cfe-commits, pcwang-thead, eopXD, MaskRay.
Herald added a project: clang.

Resource folder[1] should include before sysroot[2] in general (Linux clang
toolchain, BareMetal clang toolchain, and GCC using that order), and that
prevent sysroot's header file override resource folder's one, this change is
reference from BareMetal::addclangsystemincludea...@baremetal.cpp[3].

And also fix the behavior of `-nobuiltininc`.

[1] Include path from resource folder is something like this: 
`/lib/clang/13.0.0/include/`
[2] Include path from sysroot is something like this: 
`/riscv32-unknown-elf/include`
[3] 
https://github.com/llvm/llvm-project/blob/llvmorg-13.0.1/clang/lib/Driver/ToolChains/BareMetal.cpp#L193


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119837

Files:
  clang/lib/Driver/ToolChains/RISCVToolchain.cpp
  clang/test/Driver/Inputs/resource_dir/include/.keep
  clang/test/Driver/riscv32-toolchain.c
  clang/test/Driver/riscv64-toolchain.c


Index: clang/test/Driver/riscv64-toolchain.c
===
--- clang/test/Driver/riscv64-toolchain.c
+++ clang/test/Driver/riscv64-toolchain.c
@@ -153,6 +153,20 @@
 // C-RV64-RTLIB-COMPILERRT-LP64: "--start-group" "-lc" "-lgloss" "--end-group" 
"{{.*}}libclang_rt.builtins-riscv64.a"
 // C-RV64-RTLIB-COMPILERRT-LP64: "{{.*}}clang_rt.crtend-riscv64.o"
 
+// RUN: %clang %s -### -no-canonical-prefixes -target riscv64 \
+// RUN:   --gcc-toolchain=%S/Inputs/basic_riscv64_tree \
+// RUN:   -resource-dir=%s/Inputs/resource_dir 2>&1 \
+// RUN:   | FileCheck -check-prefix=RESOURCE-INC %s
+// RESOURCE-INC: "-internal-isystem" "{{.*}}/Inputs/resource_dir/include"
+// RESOURCE-INC: "-internal-isystem" 
"{{.*}}/basic_riscv64_tree/{{.*}}/riscv64-unknown-elf/include"
+
+// RUN: %clang %s -### -no-canonical-prefixes -target riscv64 \
+// RUN:   --gcc-toolchain=%S/Inputs/basic_riscv64_tree \
+// RUN:   -resource-dir=%s/Inputs/resource_dir -nobuiltininc 2>&1 \
+// RUN:   | FileCheck -check-prefix=NO-RESOURCE-INC %s
+// NO-RESOURCE-INC-NOT: "-internal-isystem" "{{.*}}Inputs/resource_dir/include"
+// NO-RESOURCE-INC: "-internal-isystem" 
"{{.*}}/basic_riscv64_tree/{{.*}}/riscv64-unknown-elf/include"
+
 // RUN: %clang -target riscv64 %s -emit-llvm -S -o - | FileCheck %s
 
 typedef __builtin_va_list va_list;
Index: clang/test/Driver/riscv32-toolchain.c
===
--- clang/test/Driver/riscv32-toolchain.c
+++ clang/test/Driver/riscv32-toolchain.c
@@ -197,6 +197,20 @@
 // C-RV32-RTLIB-COMPILERRT-ILP32: "--start-group" "-lc" "-lgloss" 
"--end-group" "{{.*}}libclang_rt.builtins-riscv32.a"
 // C-RV32-RTLIB-COMPILERRT-ILP32: "{{.*}}clang_rt.crtend-riscv32.o"
 
+// RUN: %clang %s -### -no-canonical-prefixes -target riscv32 \
+// RUN:   --gcc-toolchain=%S/Inputs/basic_riscv32_tree \
+// RUN:   -resource-dir=%s/Inputs/resource_dir 2>&1 \
+// RUN:   | FileCheck -check-prefix=RESOURCE-INC %s
+// RESOURCE-INC: "-internal-isystem" "{{.*}}/Inputs/resource_dir/include"
+// RESOURCE-INC: "-internal-isystem" 
"{{.*}}/basic_riscv32_tree/{{.*}}/riscv32-unknown-elf/include"
+
+// RUN: %clang %s -### -no-canonical-prefixes -target riscv32 \
+// RUN:   --gcc-toolchain=%S/Inputs/basic_riscv32_tree \
+// RUN:   -resource-dir=%s/Inputs/resource_dir -nobuiltininc 2>&1 \
+// RUN:   | FileCheck -check-prefix=NO-RESOURCE-INC %s
+// NO-RESOURCE-INC-NOT: "-internal-isystem" 
"{{.*}}/Inputs/resource_dir/include"
+// NO-RESOURCE-INC: "-internal-isystem" 
"{{.*}}/basic_riscv32_tree/{{.*}}/riscv32-unknown-elf/include"
+
 // RUN: %clang -target riscv32 %s -emit-llvm -S -o - | FileCheck %s
 
 typedef __builtin_va_list va_list;
Index: clang/lib/Driver/ToolChains/RISCVToolchain.cpp
===
--- clang/lib/Driver/ToolChains/RISCVToolchain.cpp
+++ clang/lib/Driver/ToolChains/RISCVToolchain.cpp
@@ -98,6 +98,12 @@
   if (DriverArgs.hasArg(options::OPT_nostdinc))
 return;
 
+  if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
+SmallString<128> Dir(getDriver().ResourceDir);
+llvm::sys::path::append(Dir, "include");
+addSystemInclude(DriverArgs, CC1Args, Dir.str());
+  }
+
   if (!DriverArgs.hasArg(options::OPT_nostdlibinc)) {
 SmallString<128> Dir(computeSysRoot());
 llvm::sys::path::append(Dir, "include");


Index: clang/test/Driver/riscv64-toolchain.c
===
--- clang/test/Driver/riscv64-toolchain.c
+++ clang/test/Driver/riscv64-toolchain.c
@

[PATCH] D119719: [Docs][OpenCL] Update OpenCL 3.0 status

2022-02-15 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh accepted this revision.
svenvh added a comment.
This revision is now accepted and ready to land.

LGTM, just suggesting a minor textual improvement that can be made at commit 
time.




Comment at: clang/docs/UsersManual.rst:3063
 
-There is ongoing support for OpenCL v3.0 that is documented along with other
-experimental functionality and features in development on :doc:`OpenCLSupport`
-page.
+OpenCL v3.0 support is complete but it remains in experimental state, see more
+details about the experimental features in :doc:`OpenCLSupport` page.

```
OpenCL v3.0 support is complete but it remains in experimental state.
More details about the experimental features are described in 
:doc:`OpenCLSupport`.
```


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

https://reviews.llvm.org/D119719

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


[PATCH] D84225: [CFE] Add nomerge function attribute to inline assembly.

2022-02-15 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Sema/SemaStmtAttr.cpp:186
   void VisitCallExpr(const CallExpr *E) { FoundCallExpr = true; }
+  void VisitAsmStmt(const AsmStmt *S) { FoundCallExpr = true; }
 

xbolva00 wrote:
> pengfei wrote:
> > xbolva00 wrote:
> > > This is totally wrong, just big hack to smuggle it here.
> > Could you explain more? Is there any unexpect sideeffect by this?
> It looks unfortunate to have something like AsmStmt in "CallExprFinder" with 
> CallExpr as reference to clang's CallExpr.
> 
> Kinda surprised that your list of reviewers missed ALL known clang 
> developers/code owner, in this case especially @aaron.ballman .
Yeah, I would have expected that something named `CallExprFinder` would only 
find call expressions, not use of inline assembly. The class now seems to be 
misnamed and that may be surprising to users. This is then being built on top 
of by things like https://reviews.llvm.org/D119061.

I'm not certain what a reasonable name for the class is given that we now want 
to use it for different purposes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84225

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


[PATCH] D119727: [RISCV] Add the policy operand for nomask vector Multiply-Add IR intrinsics.

2022-02-15 Thread Zakk Chen via Phabricator via cfe-commits
khchen updated this revision to Diff 408840.
khchen added a comment.

Rebase and refine code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119727

Files:
  clang/include/clang/Basic/riscv_vector.td
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfmacc.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfmadd.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfmsac.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfmsub.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfnmacc.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfnmadd.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfnmsac.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfnmsub.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfwmacc.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfwmsac.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfwnmacc.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfwnmsac.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmacc.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmadd.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vnmsac.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vnmsub.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vwmacc.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vfmacc.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vfmadd.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vfmsac.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vfmsub.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vfnmacc.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vfnmadd.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vfnmsac.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vfnmsub.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vfwmacc.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vfwmsac.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vfwnmacc.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vfwnmsac.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vmacc.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vmadd.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vnmsac.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vnmsub.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vwmacc.c
  clang/utils/TableGen/RISCVVEmitter.cpp
  llvm/include/llvm/IR/IntrinsicsRISCV.td
  llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td
  llvm/test/CodeGen/RISCV/rvv/memory-args.ll
  llvm/test/CodeGen/RISCV/rvv/unmasked-ta.ll
  llvm/test/CodeGen/RISCV/rvv/vfmacc.ll
  llvm/test/CodeGen/RISCV/rvv/vfmadd.ll
  llvm/test/CodeGen/RISCV/rvv/vfmsac.ll
  llvm/test/CodeGen/RISCV/rvv/vfmsub.ll
  llvm/test/CodeGen/RISCV/rvv/vfnmacc.ll
  llvm/test/CodeGen/RISCV/rvv/vfnmadd.ll
  llvm/test/CodeGen/RISCV/rvv/vfnmsac.ll
  llvm/test/CodeGen/RISCV/rvv/vfnmsub.ll
  llvm/test/CodeGen/RISCV/rvv/vfwmacc.ll
  llvm/test/CodeGen/RISCV/rvv/vfwmsac.ll
  llvm/test/CodeGen/RISCV/rvv/vfwnmacc.ll
  llvm/test/CodeGen/RISCV/rvv/vfwnmsac.ll
  llvm/test/CodeGen/RISCV/rvv/vmacc-rv32.ll
  llvm/test/CodeGen/RISCV/rvv/vmacc-rv64.ll
  llvm/test/CodeGen/RISCV/rvv/vmadd-rv32.ll
  llvm/test/CodeGen/RISCV/rvv/vmadd-rv64.ll
  llvm/test/CodeGen/RISCV/rvv/vnmsac-rv32.ll
  llvm/test/CodeGen/RISCV/rvv/vnmsac-rv64.ll
  llvm/test/CodeGen/RISCV/rvv/vnmsub-rv32.ll
  llvm/test/CodeGen/RISCV/rvv/vnmsub-rv64.ll
  llvm/test/CodeGen/RISCV/rvv/vsetvli-insert-crossbb.ll
  llvm/test/CodeGen/RISCV/rvv/vwmacc-rv32.ll
  llvm/test/CodeGen/RISCV/rvv/vwmacc-rv64.ll
  llvm/test/CodeGen/RISCV/rvv/vwmaccsu-rv32.ll
  llvm/test/CodeGen/RISCV/rvv/vwmaccsu-rv64.ll
  llvm/test/CodeGen/RISCV/rvv/vwmaccu-rv32.ll
  llvm/test/CodeGen/RISCV/rvv/vwmaccu-rv64.ll
  llvm/test/CodeGen/RISCV/rvv/vwmaccus-rv32.ll
  llvm/test/CodeGen/RISCV/rvv/vwmaccus-rv64.ll

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


[PATCH] D116924: [clang-extdef-mapping] Allow clang-extdef-mapping tool to output customized filename for each index entry

2022-02-15 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

I'm not against the idea.
However, the implementation seems to be quite complicated, compared to what 
it's actually doing.
Can't we spare the heap allocation somehow? It doesn't seem necessary to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116924

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


[PATCH] D119838: Revert "[asan] Add support for disable_sanitizer_instrumentation attribute"

2022-02-15 Thread Alexander Potapenko via Phabricator via cfe-commits
glider created this revision.
glider added reviewers: melver, eugenis.
Herald added a subscriber: hiraditya.
glider requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

This reverts commit dd145f953db3dafbc019f1d3783bb4f09a28af92 
.

https://reviews.llvm.org/D119726, like https://reviews.llvm.org/D114421,
still causes TSan to fail, see 
https://lab.llvm.org/buildbot/#/builders/70/builds/18020


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119838

Files:
  clang/docs/AddressSanitizer.rst
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/SanitizerMetadata.cpp
  clang/test/CodeGen/address-safety-attr-flavors.cpp
  clang/test/CodeGen/asan-globals.cpp
  llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
  
llvm/test/Instrumentation/AddressSanitizer/asan-disable-sanitizer-instrumentation.ll

Index: llvm/test/Instrumentation/AddressSanitizer/asan-disable-sanitizer-instrumentation.ll
===
--- llvm/test/Instrumentation/AddressSanitizer/asan-disable-sanitizer-instrumentation.ll
+++ /dev/null
@@ -1,47 +0,0 @@
-; This test checks that we are not instrumenting sanitizer code.
-; RUN: opt < %s -passes='asan-pipeline' -S | FileCheck %s
-
-target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
-target triple = "x86_64-unknown-linux-gnu"
-
-; Function with sanitize_address is instrumented.
-; Function Attrs: nounwind uwtable
-define void @instr_sa(i32* %a) sanitize_address {
-entry:
-  %tmp1 = load i32, i32* %a, align 4
-  %tmp2 = add i32 %tmp1,  1
-  store i32 %tmp2, i32* %a, align 4
-  ret void
-}
-
-; CHECK-LABEL: @instr_sa
-; CHECK: call void @__asan_report_load
-
-
-; Function with disable_sanitizer_instrumentation is not instrumented.
-; Function Attrs: nounwind uwtable
-define void @noinstr_dsi(i32* %a) disable_sanitizer_instrumentation {
-entry:
-  %tmp1 = load i32, i32* %a, align 4
-  %tmp2 = add i32 %tmp1,  1
-  store i32 %tmp2, i32* %a, align 4
-  ret void
-}
-
-; CHECK-LABEL: @noinstr_dsi
-; CHECK-NOT: call void @__asan_report_load
-
-
-; disable_sanitizer_instrumentation takes precedence over sanitize_address.
-; Function Attrs: nounwind uwtable
-define void @noinstr_dsi_sa(i32* %a) disable_sanitizer_instrumentation sanitize_address {
-entry:
-  %tmp1 = load i32, i32* %a, align 4
-  %tmp2 = add i32 %tmp1,  1
-  store i32 %tmp2, i32* %a, align 4
-  ret void
-}
-
-; CHECK-LABEL: @noinstr_dsi_sa
-; CHECK-NOT: call void @__asan_report_load
-
Index: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
===
--- llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -2888,9 +2888,6 @@
   // Leave if the function doesn't need instrumentation.
   if (!F.hasFnAttribute(Attribute::SanitizeAddress)) return FunctionModified;
 
-  if (F.hasFnAttribute(Attribute::DisableSanitizerInstrumentation))
-return FunctionModified;
-
   LLVM_DEBUG(dbgs() << "ASAN instrumenting:\n" << F << "\n");
 
   initializeCallbacks(*F.getParent());
Index: clang/test/CodeGen/asan-globals.cpp
===
--- clang/test/CodeGen/asan-globals.cpp
+++ clang/test/CodeGen/asan-globals.cpp
@@ -10,7 +10,6 @@
 int global;
 int dyn_init_global = global;
 int __attribute__((no_sanitize("address"))) attributed_global;
-int __attribute__((disable_sanitizer_instrumentation)) disable_instrumentation_global;
 int ignorelisted_global;
 
 int __attribute__((section("__DATA, __common"))) sectioned_global; // KASAN - ignore globals in a section
@@ -51,33 +50,31 @@
 // UWTABLE: attributes #[[#ATTR]] = { nounwind uwtable }
 // UWTABLE: ![[#]] = !{i32 7, !"uwtable", i32 2}
 
-// CHECK: !llvm.asan.globals = !{![[EXTRA_GLOBAL:[0-9]+]], ![[GLOBAL:[0-9]+]], ![[DYN_INIT_GLOBAL:[0-9]+]], ![[ATTR_GLOBAL:[0-9]+]], ![[DISABLE_INSTR_GLOBAL:[0-9]+]], ![[IGNORELISTED_GLOBAL:[0-9]+]], ![[SECTIONED_GLOBAL:[0-9]+]], ![[SPECIAL_GLOBAL:[0-9]+]], ![[STATIC_VAR:[0-9]+]], ![[LITERAL:[0-9]+]]}
+// CHECK: !llvm.asan.globals = !{![[EXTRA_GLOBAL:[0-9]+]], ![[GLOBAL:[0-9]+]], ![[DYN_INIT_GLOBAL:[0-9]+]], ![[ATTR_GLOBAL:[0-9]+]], ![[IGNORELISTED_GLOBAL:[0-9]+]], ![[SECTIONED_GLOBAL:[0-9]+]], ![[SPECIAL_GLOBAL:[0-9]+]], ![[STATIC_VAR:[0-9]+]], ![[LITERAL:[0-9]+]]}
 // CHECK: ![[EXTRA_GLOBAL]] = !{{{.*}} ![[EXTRA_GLOBAL_LOC:[0-9]+]], !"extra_global", i1 false, i1 false}
 // CHECK: ![[EXTRA_GLOBAL_LOC]] = !{!"{{.*}}extra-source.cpp", i32 1, i32 5}
 // CHECK: ![[GLOBAL]] = !{{{.*}} ![[GLOBAL_LOC:[0-9]+]], !"global", i1 false, i1 false}
 // CHECK: ![[GLOBAL_LOC]] = !{!"{{.*}}asan-globals.cpp", i32 10, i32 5}
 // CHECK: ![[DYN_INIT_GLOBAL]] = !{{{.*}} ![[DYN_INIT_LOC:[0-9]+]], !"dyn_init_global", i1 true, i1 false}
 // CHECK: ![[DYN_INIT_LOC]] = !{!"{{.*}}asan-globals.cpp"

[clang] 05ee1f4 - Revert "[asan] Add support for disable_sanitizer_instrumentation attribute"

2022-02-15 Thread Alexander Potapenko via cfe-commits

Author: Alexander Potapenko
Date: 2022-02-15T15:04:53+01:00
New Revision: 05ee1f4af8972f021917fb1f96624050fc6268bd

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

LOG: Revert "[asan] Add support for disable_sanitizer_instrumentation attribute"

This reverts commit dd145f953db3dafbc019f1d3783bb4f09a28af92.

https://reviews.llvm.org/D119726, like https://reviews.llvm.org/D114421,
still causes TSan to fail, see 
https://lab.llvm.org/buildbot/#/builders/70/builds/18020

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

Added: 


Modified: 
clang/docs/AddressSanitizer.rst
clang/lib/CodeGen/CodeGenFunction.cpp
clang/lib/CodeGen/SanitizerMetadata.cpp
clang/test/CodeGen/address-safety-attr-flavors.cpp
clang/test/CodeGen/asan-globals.cpp
llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp

Removed: 

llvm/test/Instrumentation/AddressSanitizer/asan-disable-sanitizer-instrumentation.ll



diff  --git a/clang/docs/AddressSanitizer.rst b/clang/docs/AddressSanitizer.rst
index fe5f683580a46..06b53e2e5da0b 100644
--- a/clang/docs/AddressSanitizer.rst
+++ b/clang/docs/AddressSanitizer.rst
@@ -229,12 +229,6 @@ compilers, so we suggest to use it together with
 The same attribute used on a global variable prevents AddressSanitizer
 from adding redzones around it and detecting out of bounds accesses.
 
-
-AddressSanitizer also supports
-``__attribute__((disable_sanitizer_instrumentation))``. This attribute
-works similar to ``__attribute__((no_sanitize("address")))``, but it also
-prevents instrumentation performed by other sanitizers.
-
 Suppressing Errors in Recompiled Code (Ignorelist)
 --
 

diff  --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index bd29842afbaa9..a7f62b4a4e30a 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -383,6 +383,9 @@ void CodeGenFunction::FinishFunction(SourceLocation EndLoc) 
{
"__cyg_profile_func_exit");
   }
 
+  if (ShouldSkipSanitizerInstrumentation())
+CurFn->addFnAttr(llvm::Attribute::DisableSanitizerInstrumentation);
+
   // Emit debug descriptor for function end.
   if (CGDebugInfo *DI = getDebugInfo())
 DI->EmitFunctionEnd(Builder, CurFn);
@@ -764,22 +767,18 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, 
QualType RetTy,
   Fn->addFnAttr(llvm::Attribute::NoSanitizeCoverage);
   }
 
-  if (ShouldSkipSanitizerInstrumentation()) {
-CurFn->addFnAttr(llvm::Attribute::DisableSanitizerInstrumentation);
-  } else {
-// Apply sanitizer attributes to the function.
-if (SanOpts.hasOneOf(SanitizerKind::Address | 
SanitizerKind::KernelAddress))
-  Fn->addFnAttr(llvm::Attribute::SanitizeAddress);
-if (SanOpts.hasOneOf(SanitizerKind::HWAddress |
- SanitizerKind::KernelHWAddress))
-  Fn->addFnAttr(llvm::Attribute::SanitizeHWAddress);
-if (SanOpts.has(SanitizerKind::MemTag))
-  Fn->addFnAttr(llvm::Attribute::SanitizeMemTag);
-if (SanOpts.has(SanitizerKind::Thread))
-  Fn->addFnAttr(llvm::Attribute::SanitizeThread);
-if (SanOpts.hasOneOf(SanitizerKind::Memory | SanitizerKind::KernelMemory))
-  Fn->addFnAttr(llvm::Attribute::SanitizeMemory);
-  }
+  // Apply sanitizer attributes to the function.
+  if (SanOpts.hasOneOf(SanitizerKind::Address | SanitizerKind::KernelAddress))
+Fn->addFnAttr(llvm::Attribute::SanitizeAddress);
+  if (SanOpts.hasOneOf(SanitizerKind::HWAddress |
+   SanitizerKind::KernelHWAddress))
+Fn->addFnAttr(llvm::Attribute::SanitizeHWAddress);
+  if (SanOpts.has(SanitizerKind::MemTag))
+Fn->addFnAttr(llvm::Attribute::SanitizeMemTag);
+  if (SanOpts.has(SanitizerKind::Thread))
+Fn->addFnAttr(llvm::Attribute::SanitizeThread);
+  if (SanOpts.hasOneOf(SanitizerKind::Memory | SanitizerKind::KernelMemory))
+Fn->addFnAttr(llvm::Attribute::SanitizeMemory);
   if (SanOpts.has(SanitizerKind::SafeStack))
 Fn->addFnAttr(llvm::Attribute::SafeStack);
   if (SanOpts.has(SanitizerKind::ShadowCallStack))

diff  --git a/clang/lib/CodeGen/SanitizerMetadata.cpp 
b/clang/lib/CodeGen/SanitizerMetadata.cpp
index 9e26d242d3a7e..009965a36c396 100644
--- a/clang/lib/CodeGen/SanitizerMetadata.cpp
+++ b/clang/lib/CodeGen/SanitizerMetadata.cpp
@@ -73,8 +73,6 @@ void 
SanitizerMetadata::reportGlobalToASan(llvm::GlobalVariable *GV,
   for (auto Attr : D.specific_attrs())
 if (Attr->getMask() & SanitizerKind::Address)
   IsExcluded = true;
-  if (D.hasAttr())
-IsExcluded = true;
   reportGlobalToASan(GV, D.getLocation(), OS.str(), D.getType(), IsDynInit,
  IsExcluded);
 }

diff  --git a/clang/test/CodeGen/address-safety-attr-flavors.cpp 

[PATCH] D119838: Revert "[asan] Add support for disable_sanitizer_instrumentation attribute"

2022-02-15 Thread Alexander Potapenko via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG05ee1f4af897: Revert "[asan] Add support for 
disable_sanitizer_instrumentation attribute" (authored by glider).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119838

Files:
  clang/docs/AddressSanitizer.rst
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/SanitizerMetadata.cpp
  clang/test/CodeGen/address-safety-attr-flavors.cpp
  clang/test/CodeGen/asan-globals.cpp
  llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
  
llvm/test/Instrumentation/AddressSanitizer/asan-disable-sanitizer-instrumentation.ll

Index: llvm/test/Instrumentation/AddressSanitizer/asan-disable-sanitizer-instrumentation.ll
===
--- llvm/test/Instrumentation/AddressSanitizer/asan-disable-sanitizer-instrumentation.ll
+++ /dev/null
@@ -1,47 +0,0 @@
-; This test checks that we are not instrumenting sanitizer code.
-; RUN: opt < %s -passes='asan-pipeline' -S | FileCheck %s
-
-target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
-target triple = "x86_64-unknown-linux-gnu"
-
-; Function with sanitize_address is instrumented.
-; Function Attrs: nounwind uwtable
-define void @instr_sa(i32* %a) sanitize_address {
-entry:
-  %tmp1 = load i32, i32* %a, align 4
-  %tmp2 = add i32 %tmp1,  1
-  store i32 %tmp2, i32* %a, align 4
-  ret void
-}
-
-; CHECK-LABEL: @instr_sa
-; CHECK: call void @__asan_report_load
-
-
-; Function with disable_sanitizer_instrumentation is not instrumented.
-; Function Attrs: nounwind uwtable
-define void @noinstr_dsi(i32* %a) disable_sanitizer_instrumentation {
-entry:
-  %tmp1 = load i32, i32* %a, align 4
-  %tmp2 = add i32 %tmp1,  1
-  store i32 %tmp2, i32* %a, align 4
-  ret void
-}
-
-; CHECK-LABEL: @noinstr_dsi
-; CHECK-NOT: call void @__asan_report_load
-
-
-; disable_sanitizer_instrumentation takes precedence over sanitize_address.
-; Function Attrs: nounwind uwtable
-define void @noinstr_dsi_sa(i32* %a) disable_sanitizer_instrumentation sanitize_address {
-entry:
-  %tmp1 = load i32, i32* %a, align 4
-  %tmp2 = add i32 %tmp1,  1
-  store i32 %tmp2, i32* %a, align 4
-  ret void
-}
-
-; CHECK-LABEL: @noinstr_dsi_sa
-; CHECK-NOT: call void @__asan_report_load
-
Index: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
===
--- llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -2888,9 +2888,6 @@
   // Leave if the function doesn't need instrumentation.
   if (!F.hasFnAttribute(Attribute::SanitizeAddress)) return FunctionModified;
 
-  if (F.hasFnAttribute(Attribute::DisableSanitizerInstrumentation))
-return FunctionModified;
-
   LLVM_DEBUG(dbgs() << "ASAN instrumenting:\n" << F << "\n");
 
   initializeCallbacks(*F.getParent());
Index: clang/test/CodeGen/asan-globals.cpp
===
--- clang/test/CodeGen/asan-globals.cpp
+++ clang/test/CodeGen/asan-globals.cpp
@@ -10,7 +10,6 @@
 int global;
 int dyn_init_global = global;
 int __attribute__((no_sanitize("address"))) attributed_global;
-int __attribute__((disable_sanitizer_instrumentation)) disable_instrumentation_global;
 int ignorelisted_global;
 
 int __attribute__((section("__DATA, __common"))) sectioned_global; // KASAN - ignore globals in a section
@@ -51,33 +50,31 @@
 // UWTABLE: attributes #[[#ATTR]] = { nounwind uwtable }
 // UWTABLE: ![[#]] = !{i32 7, !"uwtable", i32 2}
 
-// CHECK: !llvm.asan.globals = !{![[EXTRA_GLOBAL:[0-9]+]], ![[GLOBAL:[0-9]+]], ![[DYN_INIT_GLOBAL:[0-9]+]], ![[ATTR_GLOBAL:[0-9]+]], ![[DISABLE_INSTR_GLOBAL:[0-9]+]], ![[IGNORELISTED_GLOBAL:[0-9]+]], ![[SECTIONED_GLOBAL:[0-9]+]], ![[SPECIAL_GLOBAL:[0-9]+]], ![[STATIC_VAR:[0-9]+]], ![[LITERAL:[0-9]+]]}
+// CHECK: !llvm.asan.globals = !{![[EXTRA_GLOBAL:[0-9]+]], ![[GLOBAL:[0-9]+]], ![[DYN_INIT_GLOBAL:[0-9]+]], ![[ATTR_GLOBAL:[0-9]+]], ![[IGNORELISTED_GLOBAL:[0-9]+]], ![[SECTIONED_GLOBAL:[0-9]+]], ![[SPECIAL_GLOBAL:[0-9]+]], ![[STATIC_VAR:[0-9]+]], ![[LITERAL:[0-9]+]]}
 // CHECK: ![[EXTRA_GLOBAL]] = !{{{.*}} ![[EXTRA_GLOBAL_LOC:[0-9]+]], !"extra_global", i1 false, i1 false}
 // CHECK: ![[EXTRA_GLOBAL_LOC]] = !{!"{{.*}}extra-source.cpp", i32 1, i32 5}
 // CHECK: ![[GLOBAL]] = !{{{.*}} ![[GLOBAL_LOC:[0-9]+]], !"global", i1 false, i1 false}
 // CHECK: ![[GLOBAL_LOC]] = !{!"{{.*}}asan-globals.cpp", i32 10, i32 5}
 // CHECK: ![[DYN_INIT_GLOBAL]] = !{{{.*}} ![[DYN_INIT_LOC:[0-9]+]], !"dyn_init_global", i1 true, i1 false}
 // CHECK: ![[DYN_INIT_LOC]] = !{!"{{.*}}asan-globals.cpp", i32 11, i32 5}
-// CHECK: ![[ATTR_GLOBAL]] = !{{{.*attributed_global.*}}, null, null, i1 false, i1 true}
-// CHECK: ![[DISAB

[PATCH] D119560: [OpenCL] opencl-c.h: remove arg names from atomics

2022-02-15 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

In D119560#3322582 , @svenvh wrote:

> In D119560#3322531 , @Anastasia 
> wrote:
>
>>> also makes the header no longer "claim" the identifiers "success",
>>> "failure", "desired", "value" (such that you can compile with -Dvalue=...
>>> when including the header for example, which currently breaks parsing
>>> of the header).
>>
>> I don't get what you mean by this. :)
>
> Compiling a CL source file with e.g. `clang -cl-std=CL2.0 -Xclang 
> -finclude-default-header -cl-no-stdinc -Dvalue=1 
> clang/test/CodeGenOpenCL/as_type.cl` gives lots of errors such as the 
> following, because defining `value` as a macro (which is not a reserved 
> identifier as far as I'm aware) collides with the argument names in the 
> header:
>
>   In file included from :1:
>   lib/clang/15.0.0/include/opencl-c.h:13277:58: error: expected ')'
>   void __ovld atomic_init(volatile atomic_int *object, int value);
>^
>   :1:15: note: expanded from here
>   #define value 1

Oh, I see. Thanks! This is bad indeed!!!

>>> This is a big patch and it only touches the OpenCL 2 atomics for now. I
>>> wonder if we should remove argument names from the other builtins too?
>>> I think it would help unifying the header and tablegen approaches: if we
>>> gradually move the header into some canonical form, we might be able
>>> to eventually replace it with a tablegen-ed header, while being able to
>>> easily confirm equivalence.
>>
>> The only drawback I see if that we will lose the history a bit in "git 
>> blame" but:
>
> Slight nuance: we will not lose any history, but I understand your concern: 
> someone needs to look through this commit to see the previous commit that 
> touched the code.

Yeah indeed, we don't lose it, but just make it a bit more complicated to look 
up.

> If there are no objections to removing all argument names from the header, 
> I'll try to prepare patches for doing so.

No, it seems rather good to do since it is fixing a bug with the preprocessor 
macros that you have highlighted.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119560

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


[PATCH] D118370: [clang-tidy] bugprone-signal-handler: Message improvement and code refactoring.

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

ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118370

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


[PATCH] D119398: [OpenCL] Guard atomic_double with cl_khr_int64_base_atomics and cl_khr_int64_extended_atomics

2022-02-15 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

In D119398#3322547 , @haonanya wrote:

> Hi, @Anastasia. Please help to land it, thanks very much.

Sure, I will kindly ask @svenvh since he has some related patches to land too.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119398

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


[PATCH] D119745: [libTooling] Change Tranformer's consumer to take multiple changes

2022-02-15 Thread Eric Li via Phabricator via cfe-commits
li.zhe.hua updated this revision to Diff 408847.
li.zhe.hua added a comment.

Remove old constructor

Not sure how to resolve the ambiguous constructor issue on MSVC. This is
probably SFINAE-able, but not sure how to repro locally to iterate.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119745

Files:
  clang/include/clang/Tooling/Transformer/Transformer.h
  clang/lib/Tooling/Transformer/Transformer.cpp
  clang/unittests/Tooling/TransformerTest.cpp

Index: clang/unittests/Tooling/TransformerTest.cpp
===
--- clang/unittests/Tooling/TransformerTest.cpp
+++ clang/unittests/Tooling/TransformerTest.cpp
@@ -26,6 +26,7 @@
 using ::clang::transformer::before;
 using ::clang::transformer::cat;
 using ::clang::transformer::changeTo;
+using ::clang::transformer::editList;
 using ::clang::transformer::makeRule;
 using ::clang::transformer::member;
 using ::clang::transformer::name;
@@ -36,6 +37,8 @@
 using ::clang::transformer::statement;
 using ::testing::ElementsAre;
 using ::testing::IsEmpty;
+using ::testing::ResultOf;
+using ::testing::UnorderedElementsAre;
 
 constexpr char KHeaderContents[] = R"cc(
   struct string {
@@ -120,10 +123,11 @@
 return *ChangedCode;
   }
 
-  Transformer::ChangeConsumer consumer() {
-return [this](Expected C) {
+  Transformer::ChangeSetConsumer consumer() {
+return [this](Expected> C) {
   if (C) {
-Changes.push_back(std::move(*C));
+Changes.insert(Changes.end(), std::make_move_iterator(C->begin()),
+   std::make_move_iterator(C->end()));
   } else {
 // FIXME: stash this error rather then printing.
 llvm::errs() << "Error generating changes: "
@@ -799,7 +803,6 @@
 }
 
 TEST_F(TransformerTest, EditList) {
-  using clang::transformer::editList;
   std::string Input = R"cc(
 void foo() {
   if (10 > 1.0)
@@ -827,7 +830,6 @@
 }
 
 TEST_F(TransformerTest, Flatten) {
-  using clang::transformer::editList;
   std::string Input = R"cc(
 void foo() {
   if (10 > 1.0)
@@ -1638,4 +1640,46 @@
   << "Could not update code: " << llvm::toString(UpdatedCode.takeError());
   EXPECT_EQ(format(*UpdatedCode), format(Header));
 }
+
+// A single change set can span multiple files.
+TEST_F(TransformerTest, MultiFileEdit) {
+  // NB: The fixture is unused for this test, but kept for the test suite name.
+  std::string Header = R"cc(void Func(int id);)cc";
+  std::string Source = R"cc(#include "input.h"
+void Caller() {
+  int id = 0;
+  Func(id);
+})cc";
+  int ErrorCount = 0;
+  std::vector ChangeSets;
+  clang::ast_matchers::MatchFinder MatchFinder;
+  Transformer T(
+  makeRule(callExpr(callee(functionDecl(hasName("Func"))),
+forEachArgumentWithParam(expr().bind("arg"),
+ parmVarDecl().bind("param"))),
+   editList({changeTo(node("arg"), cat("ARG")),
+ changeTo(node("param"), cat("PARAM"))})),
+  [&](Expected> Changes) {
+if (Changes)
+  ChangeSets.push_back(AtomicChanges(Changes->begin(), Changes->end()));
+else
+  ++ErrorCount;
+  });
+  T.registerMatchers(&MatchFinder);
+  auto Factory = newFrontendActionFactory(&MatchFinder);
+  EXPECT_TRUE(runToolOnCodeWithArgs(
+  Factory->create(), Source, std::vector(), "input.cc",
+  "clang-tool", std::make_shared(),
+  {{"input.h", Header}}));
+
+  EXPECT_EQ(ErrorCount, 0);
+  EXPECT_THAT(
+  ChangeSets,
+  UnorderedElementsAre(UnorderedElementsAre(
+  ResultOf([](const AtomicChange &C) { return C.getFilePath(); },
+   "input.cc"),
+  ResultOf([](const AtomicChange &C) { return C.getFilePath(); },
+   "./input.h";
+}
+
 } // namespace
Index: clang/lib/Tooling/Transformer/Transformer.cpp
===
--- clang/lib/Tooling/Transformer/Transformer.cpp
+++ clang/lib/Tooling/Transformer/Transformer.cpp
@@ -65,6 +65,9 @@
 }
   }
 
+  llvm::SmallVector Changes;
+  Changes.reserve(ChangesByFileID.size());
   for (auto &IDChangePair : ChangesByFileID)
-Consumer(std::move(IDChangePair.second));
+Changes.push_back(std::move(IDChangePair.second));
+  Consumer(llvm::MutableArrayRef(Changes));
 }
Index: clang/include/clang/Tooling/Transformer/Transformer.h
===
--- clang/include/clang/Tooling/Transformer/Transformer.h
+++ clang/include/clang/Tooling/Transformer/Transformer.h
@@ -22,16 +22,25 @@
 /// defined by the arguments of the constructor.
 class Transformer : public ast_matchers::MatchFinder::MatchCallback {
 public:
-  using ChangeConsumer =
-  std::function Change)>

[PATCH] D102669: [analyzer][ctu] Fix wrong 'multiple definitions' errors caused by space characters in lookup names when parsing the ctu index file

2022-02-15 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a subscriber: NoQ.
steakhal added a comment.

Thank you @OikawaKirie for the thorough investigation and explanation, even 
annotations and examples. I really appreciate it.
However, you already surpassed my knowledge regarding the frontend, cc1, and 
other driver magic transformations.

I think it would be great to invite some Apple folks and experts in the driver 
flag stuff. That being said this interesting behavior would be a nice candidate 
for a post on the clang discourse  forum.
@NoQ might also have something to say about this target triple magic.


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

https://reviews.llvm.org/D102669

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


[PATCH] D84225: [CFE] Add nomerge function attribute to inline assembly.

2022-02-15 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei added inline comments.



Comment at: clang/lib/Sema/SemaStmtAttr.cpp:186
   void VisitCallExpr(const CallExpr *E) { FoundCallExpr = true; }
+  void VisitAsmStmt(const AsmStmt *S) { FoundCallExpr = true; }
 

aaron.ballman wrote:
> xbolva00 wrote:
> > pengfei wrote:
> > > xbolva00 wrote:
> > > > This is totally wrong, just big hack to smuggle it here.
> > > Could you explain more? Is there any unexpect sideeffect by this?
> > It looks unfortunate to have something like AsmStmt in "CallExprFinder" 
> > with CallExpr as reference to clang's CallExpr.
> > 
> > Kinda surprised that your list of reviewers missed ALL known clang 
> > developers/code owner, in this case especially @aaron.ballman .
> Yeah, I would have expected that something named `CallExprFinder` would only 
> find call expressions, not use of inline assembly. The class now seems to be 
> misnamed and that may be surprising to users. This is then being built on top 
> of by things like https://reviews.llvm.org/D119061.
> 
> I'm not certain what a reasonable name for the class is given that we now 
> want to use it for different purposes.
Thanks @xbolva00 and @aaron.ballman for the input!
I added it to suppress the diagnosis and it's OK since it's the only use of the 
class at that time. I'm fine with the change on D119061.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84225

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


[PATCH] D119825: [clang][lex] Introduce `SearchDirIndex` to usage tracking code

2022-02-15 Thread Alex Hoppen via Phabricator via cfe-commits
ahoppen added a comment.

Definitely a lot nicer 👍




Comment at: clang/include/clang/Lex/HeaderSearch.h:185
+  /// Get search directory stored at the index.
+  DirectoryLookup &get(HeaderSearch &HS) const;
+};

I would have expected these to be methods on `HeaderSearch`. Is there a 
particular reason why these are methods on `SearchDirIdx`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119825

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


[PATCH] D119841: [OpenMP] Pass AMDGPU math libraries into the linker wrapper

2022-02-15 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 created this revision.
jhuber6 added reviewers: JonChesterfield, jdoerfert.
Herald added subscribers: kerbowa, guansong, t-tye, tpr, dstuttard, yaxunl, 
jvesely, kzhuravl.
jhuber6 requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1, wdng.
Herald added a project: clang.

This patch passes in the AMDPGU math libraries to the linker wrapper.
The wrapper already handles linking OpenMP bitcode libraries via the
`--target-library` option. This should be sufficient to link in math
libraries for the accompanying architecture.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119841

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/amdgpu-openmp-toolchain.c


Index: clang/test/Driver/amdgpu-openmp-toolchain.c
===
--- clang/test/Driver/amdgpu-openmp-toolchain.c
+++ clang/test/Driver/amdgpu-openmp-toolchain.c
@@ -77,3 +77,6 @@
 
 // RUN: %clang -### -target x86_64-pc-linux-gnu -fopenmp 
-fopenmp-targets=amdgcn-amd-amdhsa -Xopenmp-target=amdgcn-amd-amdhsa 
-march=gfx803 -lm --rocm-device-lib-path=%S/Inputs/rocm/amdgcn/bitcode %s 2>&1 
| FileCheck %s --check-prefix=CHECK-LIB-DEVICE
 // CHECK-LIB-DEVICE: 
{{.*}}llvm-link{{.*}}ocml.bc"{{.*}}ockl.bc"{{.*}}oclc_daz_opt_on.bc"{{.*}}oclc_unsafe_math_off.bc"{{.*}}oclc_finite_only_off.bc"{{.*}}oclc_correctly_rounded_sqrt_on.bc"{{.*}}oclc_wavefrontsize64_on.bc"{{.*}}oclc_isa_version_803.bc"
+
+// RUN: %clang -### -target x86_64-pc-linux-gnu -fopenmp 
-fopenmp-targets=amdgcn-amd-amdhsa -Xopenmp-target=amdgcn-amd-amdhsa 
-march=gfx803 -lm --rocm-device-lib-path=%S/Inputs/rocm/amdgcn/bitcode 
-fopenmp-new-driver %s 2>&1 | FileCheck %s --check-prefix=CHECK-LIB-DEVICE-NEW
+// CHECK-LIB-DEVICE-NEW: 
{{.*}}clang-linker-wrapper{{.*}}ocml.bc"{{.*}}ockl.bc"{{.*}}oclc_daz_opt_on.bc"{{.*}}oclc_unsafe_math_off.bc"{{.*}}oclc_finite_only_off.bc"{{.*}}oclc_correctly_rounded_sqrt_on.bc"{{.*}}oclc_wavefrontsize64_on.bc"{{.*}}oclc_isa_version_803.bc"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -8191,6 +8191,33 @@
 }
   }
 
+  // Get the AMDGPU math libraries.
+  // FIXME: This method is bad, remove once AMDGPU has a proper math library.
+  for (auto &I : llvm::make_range(OpenMPTCRange.first, OpenMPTCRange.second)) {
+const ToolChain *TC = I.second;
+
+if (!TC->getTriple().isAMDGPU())
+  continue;
+
+// Don't pass math libraries if this is C and it wasn't specified.
+const auto LibraryArgs = Args.getAllArgValues(options::OPT_l);
+if (llvm::find(LibraryArgs, "m") == LibraryArgs.end() && !D.CCCIsCXX())
+  continue;
+
+const ArgList &TCArgs = C.getArgsForToolChain(TC, "", Action::OFK_OpenMP);
+StringRef Arch = TCArgs.getLastArgValue(options::OPT_march_EQ);
+const toolchains::ROCMToolChain RocmTC(TC->getDriver(), TC->getTriple(),
+   TCArgs);
+
+SmallVector BCLibs =
+RocmTC.getCommonDeviceLibNames(TCArgs, Arch.str());
+
+for (StringRef LibName : BCLibs)
+  CmdArgs.push_back(
+  Args.MakeArgString("-target-library=" + TC->getTripleString() + "-" +
+ Arch + "=" + LibName));
+  }
+
   if (D.isUsingLTO(/* IsOffload */ true)) {
 // Pass in target features for each toolchain.
 for (auto &I :


Index: clang/test/Driver/amdgpu-openmp-toolchain.c
===
--- clang/test/Driver/amdgpu-openmp-toolchain.c
+++ clang/test/Driver/amdgpu-openmp-toolchain.c
@@ -77,3 +77,6 @@
 
 // RUN: %clang -### -target x86_64-pc-linux-gnu -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa -Xopenmp-target=amdgcn-amd-amdhsa -march=gfx803 -lm --rocm-device-lib-path=%S/Inputs/rocm/amdgcn/bitcode %s 2>&1 | FileCheck %s --check-prefix=CHECK-LIB-DEVICE
 // CHECK-LIB-DEVICE: {{.*}}llvm-link{{.*}}ocml.bc"{{.*}}ockl.bc"{{.*}}oclc_daz_opt_on.bc"{{.*}}oclc_unsafe_math_off.bc"{{.*}}oclc_finite_only_off.bc"{{.*}}oclc_correctly_rounded_sqrt_on.bc"{{.*}}oclc_wavefrontsize64_on.bc"{{.*}}oclc_isa_version_803.bc"
+
+// RUN: %clang -### -target x86_64-pc-linux-gnu -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa -Xopenmp-target=amdgcn-amd-amdhsa -march=gfx803 -lm --rocm-device-lib-path=%S/Inputs/rocm/amdgcn/bitcode -fopenmp-new-driver %s 2>&1 | FileCheck %s --check-prefix=CHECK-LIB-DEVICE-NEW
+// CHECK-LIB-DEVICE-NEW: {{.*}}clang-linker-wrapper{{.*}}ocml.bc"{{.*}}ockl.bc"{{.*}}oclc_daz_opt_on.bc"{{.*}}oclc_unsafe_math_off.bc"{{.*}}oclc_finite_only_off.bc"{{.*}}oclc_correctly_rounded_sqrt_on.bc"{{.*}}oclc_wavefrontsize64_on.bc"{{.*}}oclc_isa_version_803.bc"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -8191,6 +8191,33 @@

[PATCH] D119841: [OpenMP] Pass AMDGPU math libraries into the linker wrapper

2022-02-15 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added a comment.

I can't test this yet because the AMDGPU cluster is down for maintenance.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119841

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


[PATCH] D119825: [clang][lex] Introduce `SearchDirIndex` to usage tracking code

2022-02-15 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added inline comments.



Comment at: clang/include/clang/Lex/HeaderSearch.h:185
+  /// Get search directory stored at the index.
+  DirectoryLookup &get(HeaderSearch &HS) const;
+};

ahoppen wrote:
> I would have expected these to be methods on `HeaderSearch`. Is there a 
> particular reason why these are methods on `SearchDirIdx`?
No particular reason. I agree this makes more sense on `HeaderSearch`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119825

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


[PATCH] D119842: [clangd] NFC: Cleanup IncludeCleaner API

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

Make a further improvement to decrease verbosity of the API: ASTContext
provides SourceManager access.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119842

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


Index: clang-tools-extra/clangd/IncludeCleaner.h
===
--- clang-tools-extra/clangd/IncludeCleaner.h
+++ clang-tools-extra/clangd/IncludeCleaner.h
@@ -51,8 +51,7 @@
 /// - don't attempt to describe where symbols were referenced from in
 ///   ambiguous cases (e.g. implicitly used symbols, multiple declarations)
 /// - err on the side of reporting all possible locations
-ReferencedLocations findReferencedLocations(const SourceManager &SM,
-ASTContext &Ctx, Preprocessor &PP,
+ReferencedLocations findReferencedLocations(ASTContext &Ctx, Preprocessor &PP,
 const syntax::TokenBuffer *Tokens);
 ReferencedLocations findReferencedLocations(ParsedAST &AST);
 
Index: clang-tools-extra/clangd/IncludeCleaner.cpp
===
--- clang-tools-extra/clangd/IncludeCleaner.cpp
+++ clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -288,11 +288,11 @@
 
 } // namespace
 
-ReferencedLocations findReferencedLocations(const SourceManager &SM,
-ASTContext &Ctx, Preprocessor &PP,
+ReferencedLocations findReferencedLocations(ASTContext &Ctx, Preprocessor &PP,
 const syntax::TokenBuffer *Tokens) 
{
   trace::Span Tracer("IncludeCleaner::findReferencedLocations");
   ReferencedLocations Result;
+  const auto &SM = Ctx.getSourceManager();
   ReferencedLocationCrawler Crawler(Result, SM);
   Crawler.TraverseAST(Ctx);
   if (Tokens)
@@ -301,8 +301,8 @@
 }
 
 ReferencedLocations findReferencedLocations(ParsedAST &AST) {
-  return findReferencedLocations(AST.getSourceManager(), AST.getASTContext(),
- AST.getPreprocessor(), &AST.getTokens());
+  return findReferencedLocations(AST.getASTContext(), AST.getPreprocessor(),
+ &AST.getTokens());
 }
 
 ReferencedFiles


Index: clang-tools-extra/clangd/IncludeCleaner.h
===
--- clang-tools-extra/clangd/IncludeCleaner.h
+++ clang-tools-extra/clangd/IncludeCleaner.h
@@ -51,8 +51,7 @@
 /// - don't attempt to describe where symbols were referenced from in
 ///   ambiguous cases (e.g. implicitly used symbols, multiple declarations)
 /// - err on the side of reporting all possible locations
-ReferencedLocations findReferencedLocations(const SourceManager &SM,
-ASTContext &Ctx, Preprocessor &PP,
+ReferencedLocations findReferencedLocations(ASTContext &Ctx, Preprocessor &PP,
 const syntax::TokenBuffer *Tokens);
 ReferencedLocations findReferencedLocations(ParsedAST &AST);
 
Index: clang-tools-extra/clangd/IncludeCleaner.cpp
===
--- clang-tools-extra/clangd/IncludeCleaner.cpp
+++ clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -288,11 +288,11 @@
 
 } // namespace
 
-ReferencedLocations findReferencedLocations(const SourceManager &SM,
-ASTContext &Ctx, Preprocessor &PP,
+ReferencedLocations findReferencedLocations(ASTContext &Ctx, Preprocessor &PP,
 const syntax::TokenBuffer *Tokens) {
   trace::Span Tracer("IncludeCleaner::findReferencedLocations");
   ReferencedLocations Result;
+  const auto &SM = Ctx.getSourceManager();
   ReferencedLocationCrawler Crawler(Result, SM);
   Crawler.TraverseAST(Ctx);
   if (Tokens)
@@ -301,8 +301,8 @@
 }
 
 ReferencedLocations findReferencedLocations(ParsedAST &AST) {
-  return findReferencedLocations(AST.getSourceManager(), AST.getASTContext(),
- AST.getPreprocessor(), &AST.getTokens());
+  return findReferencedLocations(AST.getASTContext(), AST.getPreprocessor(),
+ &AST.getTokens());
 }
 
 ReferencedFiles
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D119615: [CUDA][HIP] Do not promote constexpr var with non-constant initializer

2022-02-15 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked an inline comment as done.
yaxunl added inline comments.



Comment at: clang/lib/Sema/SemaCUDA.cpp:148-150
+  if ((Var->isConstexpr() || Var->getType().isConstQualified()) &&
+  Var->hasAttr() &&
   !hasExplicitAttr(Var))

tra wrote:
> So the idea here is that the constexpr vars that have an initializer that may 
> not be static enough for CUDA would not get the implicit __const__ attribute. 
> I.e. it's tied to the change below that checks for allowed initializers.
> We could use a comment about that here.
will add a comment when committing


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

https://reviews.llvm.org/D119615

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


[PATCH] D119825: [clang][lex] Introduce `SearchDirIndex` to usage tracking code

2022-02-15 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 408876.
jansvoboda11 added a comment.

Move `SearchDirIdx::get()` to `HeaderSearch`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119825

Files:
  clang/include/clang/Lex/HeaderSearch.h
  clang/lib/Lex/HeaderSearch.cpp

Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -110,18 +110,22 @@
   assert(angledDirIdx <= systemDirIdx && systemDirIdx <= dirs.size() &&
  "Directory indices are unordered");
   SearchDirs = std::move(dirs);
-  SearchDirsUsage.assign(SearchDirs.size(), false);
   AngledDirIdx = angledDirIdx;
   SystemDirIdx = systemDirIdx;
   NoCurDirSearch = noCurDirSearch;
-  SearchDirToHSEntry = std::move(searchDirToHSEntry);
+
+  UsedSearchDirs.clear();
+
+  SearchDirToHSEntry.clear();
+  for (const auto &Entry : searchDirToHSEntry)
+SearchDirToHSEntry.insert({SearchDirIdx(Entry.first), Entry.second});
+
   //LookupFileCache.clear();
 }
 
 void HeaderSearch::AddSearchPath(const DirectoryLookup &dir, bool isAngled) {
   unsigned idx = isAngled ? SystemDirIdx : AngledDirIdx;
   SearchDirs.insert(SearchDirs.begin() + idx, dir);
-  SearchDirsUsage.insert(SearchDirsUsage.begin() + idx, false);
   if (!isAngled)
 AngledDirIdx++;
   SystemDirIdx++;
@@ -129,14 +133,11 @@
 
 std::vector HeaderSearch::computeUserEntryUsage() const {
   std::vector UserEntryUsage(HSOpts->UserEntries.size());
-  for (unsigned I = 0, E = SearchDirsUsage.size(); I < E; ++I) {
-// Check whether this DirectoryLookup has been successfully used.
-if (SearchDirsUsage[I]) {
-  auto UserEntryIdxIt = SearchDirToHSEntry.find(I);
-  // Check whether this DirectoryLookup maps to a HeaderSearch::UserEntry.
-  if (UserEntryIdxIt != SearchDirToHSEntry.end())
-UserEntryUsage[UserEntryIdxIt->second] = true;
-}
+  for (SearchDirIdx Idx : UsedSearchDirs) {
+auto UserEntryIdxIt = SearchDirToHSEntry.find(Idx);
+// Check whether this DirectoryLookup maps to a HeaderSearch::UserEntry.
+if (UserEntryIdxIt != SearchDirToHSEntry.end())
+  UserEntryUsage[UserEntryIdxIt->second] = true;
   }
   return UserEntryUsage;
 }
@@ -704,8 +705,8 @@
   noteLookupUsage(HitIt.Idx, Loc);
 }
 
-void HeaderSearch::noteLookupUsage(unsigned HitIdx, SourceLocation Loc) {
-  SearchDirsUsage[HitIdx] = true;
+void HeaderSearch::noteLookupUsage(SearchDirIdx HitIdx, SourceLocation Loc) {
+  UsedSearchDirs.insert(HitIdx);
 
   auto UserEntryIdxIt = SearchDirToHSEntry.find(HitIdx);
   if (UserEntryIdxIt != SearchDirToHSEntry.end())
@@ -713,6 +714,14 @@
 << HSOpts->UserEntries[UserEntryIdxIt->second].Path;
 }
 
+const DirectoryLookup &HeaderSearch::getSearchDirAt(SearchDirIdx Idx) const {
+  return SearchDirs[Idx.Idx];
+}
+
+DirectoryLookup &HeaderSearch::getSearchDirAt(SearchDirIdx Idx) {
+  return SearchDirs[Idx.Idx];
+}
+
 void HeaderSearch::setTarget(const TargetInfo &Target) {
   ModMap.setTarget(Target);
 }
@@ -1446,8 +1455,8 @@
 + FrameworkMap.getAllocator().getTotalMemory();
 }
 
-unsigned HeaderSearch::searchDirIdx(const DirectoryLookup &DL) const {
-  return &DL - &*SearchDirs.begin();
+SearchDirIdx HeaderSearch::searchDirIdx(const DirectoryLookup &DL) const {
+  return SearchDirIdx(&DL - &*SearchDirs.begin());
 }
 
 StringRef HeaderSearch::getUniqueFrameworkName(StringRef Framework) {
Index: clang/include/clang/Lex/HeaderSearch.h
===
--- clang/include/clang/Lex/HeaderSearch.h
+++ clang/include/clang/Lex/HeaderSearch.h
@@ -163,6 +163,43 @@
   bool IsUserSpecifiedSystemFramework;
 };
 
+/// Index of a search directory.
+class SearchDirIdx {
+  /// The underlying index.
+  size_t Idx;
+
+  friend HeaderSearch;
+
+public:
+  explicit SearchDirIdx(size_t Idx) : Idx(Idx) {}
+
+  bool operator==(const SearchDirIdx &Other) const { return Idx == Other.Idx; }
+
+  llvm::hash_code hash_value() const { return Idx; }
+
+  void increment() { ++Idx; }
+};
+} // namespace clang
+
+namespace llvm {
+template <> struct DenseMapInfo {
+  static inline clang::SearchDirIdx getEmptyKey() {
+return clang::SearchDirIdx(-1);
+  }
+  static inline clang::SearchDirIdx getTombstoneKey() {
+return clang::SearchDirIdx(-2);
+  }
+  static unsigned getHashValue(const clang::SearchDirIdx &Val) {
+return Val.hash_value();
+  }
+  static bool isEqual(const clang::SearchDirIdx &LHS,
+  const clang::SearchDirIdx &RHS) {
+return LHS == RHS;
+  }
+};
+} // namespace llvm
+
+namespace clang {
 namespace detail {
 template 
 using Qualified = std::conditional_t;
@@ -188,13 +225,13 @@
 
   SearchDirIteratorImpl &operator++() {
 assert(*this && "Invalid iterator.");
-++Idx;
+Idx.increment();
 return *this;
   }
 
   Qualified &operator*() const {
 assert(*this && "

[PATCH] D119591: clang-analyzer plugins require LLVM_ENABLE_PLUGINS also

2022-02-15 Thread Simon Tatham via Phabricator via cfe-commits
simon_tatham added a comment.

I ran another test of this patch, by trying the cross product of the following 
cmake configuration choices (on a build targeting Windows, with 
`LLVM_ENABLE_PROJECTS=clang`):

- `LLVM_EXPORT_SYMBOLS_FOR_PLUGINS` set to each of `ON` and `OFF`
- `CLANG_BUILD_EXAMPLES` set to each of `ON` and `OFF`
- `CLANG_PLUGIN_SUPPORT` set to each of `ON` and `OFF`

3 of those 8 cases failed.

- export-symbols OFF, build-examples ON, plugin-support OFF
- export-symbols OFF, build-examples ON, plugin-support ON
- export-symbols ON, build-examples ON, plugin-support OFF (which is the 
configuration we're currently using downstream)

In all three cases, I saw errors such as this (suggesting that a plugin is 
being added to the list of things to test even though it wasn't built):

  CMake Error at cmake/modules/AddLLVM.cmake:1821 (add_dependencies):
The dependency target "AnnotateFunctions" of target "check-all" does not
exist.
  Call Stack (most recent call first):
CMakeLists.txt:1134 (add_lit_target)

Perhaps not all of the 8 configurations in this cross product are actually 
sensible? But if one of them is not sensible, it would be better to get a clear 
error message saying why, than to have to debug things like the above.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119591

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


[PATCH] D118753: [PowerPC] Fix __builtin_pdepd and __builtin_pextd to be 64-bit and P10 only.

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

LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118753

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


[PATCH] D119841: [OpenMP] Pass AMDGPU math libraries into the linker wrapper

2022-02-15 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added inline comments.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:8195
+  // Get the AMDGPU math libraries.
+  // FIXME: This method is bad, remove once AMDGPU has a proper math library.
+  for (auto &I : llvm::make_range(OpenMPTCRange.first, OpenMPTCRange.second)) {

Can you elaborate on this comment, what's bad, how would the better version look


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119841

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


[PATCH] D119841: [OpenMP] Pass AMDGPU math libraries into the linker wrapper

2022-02-15 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added inline comments.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:8195
+  // Get the AMDGPU math libraries.
+  // FIXME: This method is bad, remove once AMDGPU has a proper math library.
+  for (auto &I : llvm::make_range(OpenMPTCRange.first, OpenMPTCRange.second)) {

jdoerfert wrote:
> Can you elaborate on this comment, what's bad, how would the better version 
> look
It's explained in more detail where this is done for the AMDGPU ToolChain, e.g.
```
  // This is not certain to work. The device libs added here, and passed to 
   
  // llvm-link, are missing attributes that they expect to be inserted when 
   
  // passed to mlink-builtin-bitcode. The amdgpu backend does not generate  
  
  // conservatively correct code when attributes are missing, so this may   
 
  // be the root cause of miscompilations. Passing via 
mlink-builtin-bitcode
  // ultimately hits CodeGenModule::addDefaultFunctionDefinitionAttributes  
  
  // on each function, see D28538 for context.
  // Potential workarounds:
  //  - unconditionally link all of the device libs to every translation
  //unit in clang via mlink-builtin-bitcode
  //  - build a libm bitcode file as part of the DeviceRTL and explictly
  //mlink-builtin-bitcode the rocm device libs components at build time 
   
  //  - drop this llvm-link fork in favour or some calls into LLVM, chosen  
  
  //to do basically the same work as llvm-link but with that call first 
   
  //  - write an opt pass that sets that on every function it sees and pipe 
   
  //the device-libs bitcode through that on the way to this llvm-link
```
Should I copy the gist here?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119841

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


[PATCH] D119846: [NFC][MC] remove unused argument `MCRegisterInfo` in `MCCodeEmitter`

2022-02-15 Thread Shao-Ce SUN via Phabricator via cfe-commits
achieveartificialintelligence created this revision.
achieveartificialintelligence added reviewers: grosbach, Eugene.Zelenko, asb, 
jrtc27, craig.topper.
Herald added subscribers: ayermolo, sdasgup3, wenzhicui, wrengr, Chia-hungDuan, 
dcaballe, cota, teijeong, frasercrmck, rdzhabarov, tatianashp, msifontes, 
jurahul, Kayjukh, grosul1, Joonsoo, liufengdb, aartbik, mgester, arpith-jacob, 
csigg, antiagainst, shauheen, rriddle, mehdi_amini, luismarques, apazos, 
sameer.abuasal, pengfei, s.egerton, Jim, jocewei, PkmX, the_o, brucehoult, 
MartinMosbeck, rogfer01, edward-jones, zzheng, gbedwell, niosHD, sabuasal, 
simoncook, johnrusso, rbar, hiraditya.
Herald added a reviewer: andreadb.
Herald added a reviewer: bondhugula.
Herald added a reviewer: rafauler.
Herald added a reviewer: Amir.
Herald added a reviewer: maksfb.
achieveartificialintelligence requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, pcwang-thead, yota9, 
stephenneuendorffer, nicolasvasilache, MaskRay.
Herald added a reviewer: herhut.
Herald added projects: clang, MLIR, LLVM.

For ten years, it seems that `MCRegisterInfo` is not used by any target.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119846

Files:
  bolt/include/bolt/Core/BinaryContext.h
  bolt/lib/Core/BinaryContext.cpp
  clang/tools/driver/cc1as_main.cpp
  llvm/include/llvm/MC/TargetRegistry.h
  llvm/lib/CodeGen/LLVMTargetMachine.cpp
  llvm/lib/DWARFLinker/DWARFStreamer.cpp
  llvm/lib/Target/Lanai/MCTargetDesc/LanaiMCCodeEmitter.cpp
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCCodeEmitter.cpp
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCTargetDesc.h
  llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
  llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.h
  llvm/lib/Target/X86/X86AsmPrinter.cpp
  llvm/tools/llvm-dwp/llvm-dwp.cpp
  llvm/tools/llvm-exegesis/lib/LlvmState.cpp
  llvm/tools/llvm-mc-assemble-fuzzer/llvm-mc-assemble-fuzzer.cpp
  llvm/tools/llvm-mc/llvm-mc.cpp
  llvm/tools/llvm-mca/llvm-mca.cpp
  llvm/tools/llvm-ml/llvm-ml.cpp
  llvm/unittests/DebugInfo/DWARF/DWARFExpressionCopyBytesTest.cpp
  llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp
  llvm/unittests/MC/DwarfLineTableHeaders.cpp
  mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp

Index: mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp
===
--- mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp
+++ mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp
@@ -376,7 +376,7 @@
   std::unique_ptr mcStreamer;
   std::unique_ptr mcii(target->createMCInstrInfo());
 
-  llvm::MCCodeEmitter *ce = target->createMCCodeEmitter(*mcii, *mri, ctx);
+  llvm::MCCodeEmitter *ce = target->createMCCodeEmitter(*mcii, ctx);
   llvm::MCAsmBackend *mab = target->createMCAsmBackend(*sti, *mri, mcOptions);
   mcStreamer.reset(target->createMCObjectStreamer(
   triple, ctx, std::unique_ptr(mab),
Index: llvm/unittests/MC/DwarfLineTableHeaders.cpp
===
--- llvm/unittests/MC/DwarfLineTableHeaders.cpp
+++ llvm/unittests/MC/DwarfLineTableHeaders.cpp
@@ -77,8 +77,7 @@
 Res.Ctx->setObjectFileInfo(Res.MOFI.get());
 
 Res.MII.reset(TheTarget->createMCInstrInfo());
-MCCodeEmitter *MCE =
-TheTarget->createMCCodeEmitter(*Res.MII, *MRI, *Res.Ctx);
+MCCodeEmitter *MCE = TheTarget->createMCCodeEmitter(*Res.MII, *Res.Ctx);
 MCAsmBackend *MAB =
 TheTarget->createMCAsmBackend(*STI, *MRI, MCTargetOptions());
 std::unique_ptr OW = MAB->createObjectWriter(OS);
Index: llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp
===
--- llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp
+++ llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp
@@ -464,7 +464,7 @@
   TLOF->Initialize(*MC, *TM);
   MC->setObjectFileInfo(TLOF);
 
-  MCE = TheTarget->createMCCodeEmitter(*MII, *MRI, *MC);
+  MCE = TheTarget->createMCCodeEmitter(*MII, *MC);
   if (!MCE)
 return make_error("no code emitter for target " + TripleName,
inconvertibleErrorCode());
Index: llvm/unittests/DebugInfo/DWARF/DWARFExpressionCopyBytesTest.cpp
===
--- llvm/unittests/DebugInfo/DWARF/DWARFExpressionCopyBytesTest.cpp
+++ llvm/unittests/DebugInfo/DWARF/DWARFExpressionCopyBytesTest.cpp
@@ -106,7 +106,7 @@
   Res.Ctx->setObjectFileInfo(Res.MOFI.get());
 
   Res.MII.reset(TheTarget->createMCInstrInfo());
-  MCCodeEmitter *MCE = TheTarget->createMCCodeEmitter(*Res.MII, *MRI, *Res.Ctx);
+  MCCodeEmitter *MCE = TheTarget->createMCCodeEmitter(*Res.MII, *Res.Ctx);
   MCAsmBackend *MAB =
   TheTarget->createMCAsmBackend(*STI, *MRI, MCTargetOptions());
   std::unique_ptr OW = MAB->createObjectWriter(OS);
Index: llvm/tools/llvm-ml/llvm-ml.cpp
===
--- llvm/tools/llvm-ml/llvm-

[PATCH] D119537: [clangd] Treat 'auto' params as deduced if there's a single instantiation.

2022-02-15 Thread Trass3r via Phabricator via cfe-commits
Trass3r added a comment.

Is it intentional that the resolved type is not shown in the variable hover:

  param payload
  Type: const auto &
  
  // In subscribe::(anonymous class)::operator()
  const auto& payload

Only when hovering over `auto`?

  type-alias auto
  struct Foo


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119537

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


  1   2   3   >