[PATCH] D89276: Support ObjC in IncludeInserter

2020-10-14 Thread Joe Turner via Phabricator via cfe-commits
compositeprimes added a comment.

clang-format is complaining about my ordering of headers in my test case in 
IncludeInserterTest (but that's correct objc formatting). Not sure if there's a 
way to disable that on those lines


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89276

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


[clang] 9dbb088 - Perform lvalue conversions on the left of a pseudo-destructor call 'p->~T()'.

2020-10-14 Thread Richard Smith via cfe-commits

Author: Richard Smith
Date: 2020-10-14T22:09:01-07:00
New Revision: 9dbb0886ea799061baf79d4dce3203524a8468cc

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

LOG: Perform lvalue conversions on the left of a pseudo-destructor call 
'p->~T()'.

Previously we failed to convert 'p' from array/function to pointer type,
and to represent the load of 'p' in the AST. The latter causes problems
for constant evaluation.

Added: 


Modified: 
clang/lib/Sema/SemaExprCXX.cpp
clang/test/SemaCXX/constant-expression-cxx2a.cpp
clang/test/SemaCXX/pseudo-destructors.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index d39820fb483d..8d5dccc19726 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -7249,8 +7249,8 @@ ExprResult Sema::ActOnStartCXXMemberReference(Scope *S, 
Expr *Base,
   return Base;
 }
 
-static bool CheckArrow(Sema& S, QualType& ObjectType, Expr *,
-   tok::TokenKind& OpKind, SourceLocation OpLoc) {
+static bool CheckArrow(Sema , QualType , Expr *,
+   tok::TokenKind , SourceLocation OpLoc) {
   if (Base->hasPlaceholderType()) {
 ExprResult result = S.CheckPlaceholderExpr(Base);
 if (result.isInvalid()) return true;
@@ -7265,6 +7265,18 @@ static bool CheckArrow(Sema& S, QualType& ObjectType, 
Expr *,
   // Note that this is rather 
diff erent from the normal handling for the
   // arrow operator.
   if (OpKind == tok::arrow) {
+// The operator requires a prvalue, so perform lvalue conversions.
+// Only do this if we might plausibly end with a pointer, as otherwise
+// this was likely to be intended to be a '.'.
+if (ObjectType->isPointerType() || ObjectType->isArrayType() ||
+ObjectType->isFunctionType()) {
+  ExprResult BaseResult = S.DefaultFunctionArrayLvalueConversion(Base);
+  if (BaseResult.isInvalid())
+return true;
+  Base = BaseResult.get();
+  ObjectType = Base->getType();
+}
+
 if (const PointerType *Ptr = ObjectType->getAs()) {
   ObjectType = Ptr->getPointeeType();
 } else if (!Base->isTypeDependent()) {

diff  --git a/clang/test/SemaCXX/constant-expression-cxx2a.cpp 
b/clang/test/SemaCXX/constant-expression-cxx2a.cpp
index 2aea2577d972..4adadc9988ab 100644
--- a/clang/test/SemaCXX/constant-expression-cxx2a.cpp
+++ b/clang/test/SemaCXX/constant-expression-cxx2a.cpp
@@ -1061,9 +1061,10 @@ namespace memory_leaks {
   static_assert(h({new bool(true)})); // ok
 }
 
-void *operator new(std::size_t, void*);
+constexpr void *operator new(std::size_t, void *p) { return p; }
 namespace std {
   template constexpr T *construct(T *p) { return new (p) T; }
+  template constexpr void destroy(T *p) { p->~T(); }
 }
 
 namespace dtor_call {
@@ -1428,3 +1429,11 @@ namespace PR47805 {
   constexpr bool g(B b) { return  == b.p; }
   static_assert(g({}));
 }
+
+constexpr bool destroy_at_test() {
+  int n = 0;
+  std::destroy();
+  std::construct();
+  return true;
+}
+static_assert(destroy_at_test());

diff  --git a/clang/test/SemaCXX/pseudo-destructors.cpp 
b/clang/test/SemaCXX/pseudo-destructors.cpp
index 7a5c540794e2..f214f5226ee2 100644
--- a/clang/test/SemaCXX/pseudo-destructors.cpp
+++ b/clang/test/SemaCXX/pseudo-destructors.cpp
@@ -183,3 +183,14 @@ namespace TwoPhaseLookup {
 template void f6(int *p) { 
p->TemplateNamesNonTemplate::C::~C(); } // expected-error {{'C' does not 
refer to a template}}
   }
 }
+
+void destroy_array_element() {
+  int arr[5];
+  using T = int;
+  arr->~T(); // ok, destroy arr[0].
+}
+
+void destroy_function() {
+  using T = void();
+  destroy_function->~T(); // expected-error {{object expression of non-scalar 
type 'void ()' cannot be used in a pseudo-destructor expression}}
+}



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


[clang] 0065198 - clang-{tools,unittests}: Stop using SourceManager::getBuffer, NFC

2020-10-14 Thread Duncan P . N . Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-10-15T00:35:16-04:00
New Revision: 006519816689acef5fd971955e21b7ab17ae65d9

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

LOG: clang-{tools,unittests}: Stop using SourceManager::getBuffer, NFC

Update clang-tools-extra, clang/tools, clang/unittests to migrate from
`SourceManager::getBuffer`, which returns an always dereferenceable
`MemoryBuffer*`, to `getBufferOrNone` or `getBufferOrFake`, both of
which return a `MemoryBufferRef`, depending on whether the call site was
checking for validity of the buffer. No functionality change intended.

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp
clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp
clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp
clang-tools-extra/clangd/ParsedAST.cpp
clang-tools-extra/clangd/SemanticHighlighting.cpp
clang-tools-extra/clangd/SourceCode.cpp
clang-tools-extra/modularize/PreprocessorTracker.cpp
clang/tools/clang-diff/ClangDiff.cpp
clang/tools/clang-import-test/clang-import-test.cpp
clang/tools/libclang/CIndex.cpp
clang/unittests/AST/ASTImporterTest.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp
index 9b34f5ab55a7..3874a52e7e20 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp
@@ -54,10 +54,10 @@ void SuspiciousSemicolonCheck::check(const 
MatchFinder::MatchResult ) {
 
   SourceLocation LocEnd = Semicolon->getEndLoc();
   FileID FID = SM.getFileID(LocEnd);
-  const llvm::MemoryBuffer *Buffer = SM.getBuffer(FID, LocEnd);
+  llvm::MemoryBufferRef Buffer = SM.getBufferOrFake(FID, LocEnd);
   Lexer Lexer(SM.getLocForStartOfFile(FID), Ctxt.getLangOpts(),
-  Buffer->getBufferStart(), SM.getCharacterData(LocEnd) + 1,
-  Buffer->getBufferEnd());
+  Buffer.getBufferStart(), SM.getCharacterData(LocEnd) + 1,
+  Buffer.getBufferEnd());
   if (Lexer.LexFromRawLexer(Token))
 return;
 

diff  --git a/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
index b84e4d525d8c..5d3d3c46edb4 100644
--- a/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
@@ -794,14 +794,14 @@ static bool areExprsFromDifferentMacros(const Expr 
*LhsExpr,
   SM.getDecomposedLoc(SM.getExpansionLoc(Lsr.getBegin()));
   std::pair RsrLocInfo =
   SM.getDecomposedLoc(SM.getExpansionLoc(Rsr.getBegin()));
-  const llvm::MemoryBuffer *MB = SM.getBuffer(LsrLocInfo.first);
+  llvm::MemoryBufferRef MB = SM.getBufferOrFake(LsrLocInfo.first);
 
-  const char *LTokenPos = MB->getBufferStart() + LsrLocInfo.second;
-  const char *RTokenPos = MB->getBufferStart() + RsrLocInfo.second;
+  const char *LTokenPos = MB.getBufferStart() + LsrLocInfo.second;
+  const char *RTokenPos = MB.getBufferStart() + RsrLocInfo.second;
   Lexer LRawLex(SM.getLocForStartOfFile(LsrLocInfo.first), LO,
-MB->getBufferStart(), LTokenPos, MB->getBufferEnd());
+MB.getBufferStart(), LTokenPos, MB.getBufferEnd());
   Lexer RRawLex(SM.getLocForStartOfFile(RsrLocInfo.first), LO,
-MB->getBufferStart(), RTokenPos, MB->getBufferEnd());
+MB.getBufferStart(), RTokenPos, MB.getBufferEnd());
 
   Token LTok, RTok;
   do { // Compare the expressions token-by-token.

diff  --git a/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp
index 53cebc32bb38..3e3f8dbf02ff 100644
--- a/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp
@@ -140,7 +140,8 @@ SourceLocation StaticAssertCheck::getLastParenLoc(const 
ASTContext *ASTCtx,
   const LangOptions  = ASTCtx->getLangOpts();
   const SourceManager  = ASTCtx->getSourceManager();
 
-  const llvm::MemoryBuffer *Buffer = SM.getBuffer(SM.getFileID(AssertLoc));
+  llvm::Optional Buffer =
+  SM.getBufferOrNone(SM.getFileID(AssertLoc));
   if (!Buffer)
 return SourceLocation();
 

diff  --git a/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp
index 1cecfa31da34..18165a619adf 100644
--- a/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp
+++ 

[PATCH] D89416: clang-{tools,unittests}: Stop using SourceManager::getBuffer, NFC

2020-10-14 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG006519816689: clang-{tools,unittests}: Stop using 
SourceManager::getBuffer, NFC (authored by dexonsmith).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89416

Files:
  clang-tools-extra/clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp
  clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
  clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp
  clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/SemanticHighlighting.cpp
  clang-tools-extra/clangd/SourceCode.cpp
  clang-tools-extra/modularize/PreprocessorTracker.cpp
  clang/tools/clang-diff/ClangDiff.cpp
  clang/tools/clang-import-test/clang-import-test.cpp
  clang/tools/libclang/CIndex.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -5695,7 +5695,8 @@
   // Make sure the imported buffer has the original contents.
   SourceManager  = ToAST->getSourceManager();
   FileID ImportedID = ToSM.getFileID(ImportedLoc);
-  EXPECT_EQ(Source, ToSM.getBuffer(ImportedID, SourceLocation())->getBuffer());
+  EXPECT_EQ(Source,
+ToSM.getBufferOrFake(ImportedID, SourceLocation()).getBuffer());
 }
 
 TEST_P(ImportSourceLocations, OverwrittenFileBuffer) {
@@ -5729,7 +5730,7 @@
   SourceManager  = ToAST->getSourceManager();
   FileID ImportedID = ToSM.getFileID(ImportedLoc);
   EXPECT_EQ(Contents,
-ToSM.getBuffer(ImportedID, SourceLocation())->getBuffer());
+ToSM.getBufferOrFake(ImportedID, SourceLocation()).getBuffer());
 }
 
 TEST_P(ASTImporterOptionSpecificTestBase, ImportExprOfAlignmentAttr) {
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -4362,9 +4362,8 @@
 
   const SourceManager  = cxtu::getASTUnit(TU)->getSourceManager();
   FileID fid = SM.translateFile(static_cast(file));
-  bool Invalid = true;
-  const llvm::MemoryBuffer *buf = SM.getBuffer(fid, );
-  if (Invalid) {
+  llvm::Optional buf = SM.getBufferOrNone(fid);
+  if (!buf) {
 if (size)
   *size = 0;
 return nullptr;
Index: clang/tools/clang-import-test/clang-import-test.cpp
===
--- clang/tools/clang-import-test/clang-import-test.cpp
+++ clang/tools/clang-import-test/clang-import-test.cpp
@@ -106,20 +106,19 @@
 unsigned LocColumn =
 SM.getSpellingColumnNumber(Loc, /*Invalid=*/nullptr) - 1;
 FileID FID = SM.getFileID(Loc);
-const llvm::MemoryBuffer *Buffer =
-SM.getBuffer(FID, Loc, /*Invalid=*/nullptr);
+llvm::MemoryBufferRef Buffer = SM.getBufferOrFake(FID, Loc);
 
-assert(LocData >= Buffer->getBufferStart() &&
-   LocData < Buffer->getBufferEnd());
+assert(LocData >= Buffer.getBufferStart() &&
+   LocData < Buffer.getBufferEnd());
 
 const char *LineBegin = LocData - LocColumn;
 
-assert(LineBegin >= Buffer->getBufferStart());
+assert(LineBegin >= Buffer.getBufferStart());
 
 const char *LineEnd = nullptr;
 
 for (LineEnd = LineBegin; *LineEnd != '\n' && *LineEnd != '\r' &&
-  LineEnd < Buffer->getBufferEnd();
+  LineEnd < Buffer.getBufferEnd();
  ++LineEnd)
   ;
 
Index: clang/tools/clang-diff/ClangDiff.cpp
===
--- clang/tools/clang-diff/ClangDiff.cpp
+++ clang/tools/clang-diff/ClangDiff.cpp
@@ -284,7 +284,7 @@
   unsigned Begin, End;
   std::tie(Begin, End) = Tree.getSourceRangeOffsets(Node);
   const SourceManager  = Tree.getASTContext().getSourceManager();
-  auto Code = SrcMgr.getBuffer(SrcMgr.getMainFileID())->getBuffer();
+  auto Code = SrcMgr.getBufferOrFake(SrcMgr.getMainFileID()).getBuffer();
   for (; Offset < Begin; ++Offset)
 printHtml(OS, Code[Offset]);
   OS << "getBufferStart();
-  const char *BufferEnd = MemBuffer->getBufferEnd();
+  llvm::MemoryBufferRef MemBuffer = PP.getSourceManager().getBufferOrFake(
+  PP.getSourceManager().getFileID(Loc));
+  const char *Buffer = MemBuffer.getBufferStart();
+  const char *BufferEnd = MemBuffer.getBufferEnd();
   const char *BeginPtr = PP.getSourceManager().getCharacterData(Loc);
   const char *EndPtr = BeginPtr;
   while (BeginPtr > Buffer) {
@@ -338,9 +338,10 @@
 // Retrieve source line from file image given a file ID and line number.
 static std::string getSourceLine(clang::Preprocessor , clang::FileID FileID,
  int Line) {
-  const llvm::MemoryBuffer *MemBuffer = 

Re: [Lldb-commits] Upcoming upgrade of LLVM buildbot

2020-10-14 Thread Galina Kistanova via cfe-commits
Thanks everyone!

I would like to keep the bots in the staging till Friday. And if everything
is good, then apply the changes to the production and let you move all the
green bots back there.

Thanks

Galina


On Tue, Oct 13, 2020 at 10:43 PM Vitaly Buka  wrote:

> They do on staging.
> http://lab.llvm.org:8014/#/builders/sanitizer-windows
> http://lab.llvm.org:8014/#/builders/clang-x64-windows-msvc
>
> Galina, when do you plan to push this to the primary server?
> If it's a few days, I'd rather keep bots on staging to have colors.
>
>
>
> On Tue, 13 Oct 2020 at 11:11, Reid Kleckner  wrote:
>
>> FWIW, I don't see any issues with my two bots that use buildbot annotated
>> commands:
>> http://lab.llvm.org:8011/#/builders/sanitizer-windows
>> http://lab.llvm.org:8011/#/builders/clang-x64-windows-msvc
>> The individual steps don't highlight as green or red, but that's OK for
>> now.
>>
>> On Mon, Oct 12, 2020 at 7:19 PM Galina Kistanova 
>> wrote:
>>
>>> We have a better version of AnnotatedCommand on the staging. It should
>>> be a functional equivalent of the old one.
>>> We need to stress test it well before moving to the production build bot.
>>>
>>> For that we need all sanitizer + other bots which use the
>>> AnnotatedCommand directly or indirectly moved temporarily to the staging.
>>>
>>> Please let me know when that could be arranged.
>>>
>>> Thanks
>>>
>>> Galina
>>>
>>> On Mon, Oct 12, 2020 at 11:39 AM Reid Kleckner  wrote:
>>>
 On Wed, Oct 7, 2020 at 4:32 PM Galina Kistanova via lldb-commits <
 lldb-comm...@lists.llvm.org> wrote:

> They are online now -
> http://lab.llvm.org:8011/#/waterfall?tags=sanitizer
>
> AnnotatedCommand has severe design conflict with the new buildbot.
> We have changed it to be safe and still do something useful, but it
> will need more love and care.
>
> Please let me know if you have some spare time to work on porting
> AnnotatedCommand.
>

 That's unfortunate, it would've been good to know that earlier. I and
 another team member have spent a fair amount of time porting things to use
 more AnnotatedCommand steps, because it gives us the flexibility to test
 steps locally and make changes to the steps without restarting the buildbot
 master. IMO that is the Right Way to define steps: a script that you can
 run locally on a machine that satisfies the OS and dep requirements of the
 script.

 I am restarting the two bots that I am responsible for, and may need
 some help debugging further issues soon. I'll let you know.

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


[clang] af4fb41 - clang/StaticAnalyzer: Stop using SourceManager::getBuffer

2020-10-14 Thread Duncan P . N . Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-10-15T00:34:24-04:00
New Revision: af4fb416bd355960ce93f271a0591f24f58d25ec

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

LOG: clang/StaticAnalyzer: Stop using SourceManager::getBuffer

Update clang/lib/StaticAnalyzer to stop relying on a `MemoryBuffer*`,
using the `MemoryBufferRef` from `getBufferOrNone` or the
`Optional` from `getBufferOrFake`, depending on whether
there's logic for checking validity of the buffer. The change to
clang/lib/StaticAnalyzer/Core/IssueHash.cpp is potentially a
functionality change, since the logic was wrong (it checked for
`nullptr`, which was never returned by the old API), but if that was
reachable the new behaviour should be better.

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

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
clang/lib/StaticAnalyzer/Core/BugReporter.cpp
clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
clang/lib/StaticAnalyzer/Core/IssueHash.cpp
clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
index 252377f24bd7..28d3e058fee2 100644
--- a/clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
@@ -1141,10 +1141,9 @@ void 
EmptyLocalizationContextChecker::MethodCrawler::VisitObjCMessageExpr(
 SE = Mgr.getSourceManager().getSLocEntry(SLInfo.first);
   }
 
-  bool Invalid = false;
-  const llvm::MemoryBuffer *BF =
-  Mgr.getSourceManager().getBuffer(SLInfo.first, SL, );
-  if (Invalid)
+  llvm::Optional BF =
+  Mgr.getSourceManager().getBufferOrNone(SLInfo.first, SL);
+  if (!BF)
 return;
 
   Lexer TheLexer(SL, LangOptions(), BF->getBufferStart(),

diff  --git a/clang/lib/StaticAnalyzer/Core/BugReporter.cpp 
b/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
index 72be4e81c83d..ebad1d1b67b4 100644
--- a/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
+++ b/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
@@ -1570,9 +1570,8 @@ static Optional getLengthOnSingleLine(const 
SourceManager ,
   if (FID != SM.getFileID(ExpansionRange.getEnd()))
 return None;
 
-  bool Invalid;
-  const llvm::MemoryBuffer *Buffer = SM.getBuffer(FID, );
-  if (Invalid)
+  Optional Buffer = SM.getBufferOrNone(FID);
+  if (!Buffer)
 return None;
 
   unsigned BeginOffset = SM.getFileOffset(ExpansionRange.getBegin());

diff  --git a/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp 
b/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
index bc7c41d039c4..68f1007569cd 100644
--- a/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
+++ b/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
@@ -786,8 +786,8 @@ void HTMLDiagnostics::HandlePiece(Rewriter , FileID 
BugFileID,
   if (LPosInfo.first != BugFileID)
 return;
 
-  const llvm::MemoryBuffer *Buf = SM.getBuffer(LPosInfo.first);
-  const char* FileStart = Buf->getBufferStart();
+  llvm::MemoryBufferRef Buf = SM.getBufferOrFake(LPosInfo.first);
+  const char *FileStart = Buf.getBufferStart();
 
   // Compute the column number.  Rewind from the current position to the start
   // of the line.
@@ -797,7 +797,7 @@ void HTMLDiagnostics::HandlePiece(Rewriter , FileID 
BugFileID,
 
   // Compute LineEnd.
   const char *LineEnd = TokInstantiationPtr;
-  const char* FileEnd = Buf->getBufferEnd();
+  const char *FileEnd = Buf.getBufferEnd();
   while (*LineEnd != '\n' && LineEnd != FileEnd)
 ++LineEnd;
 

diff  --git a/clang/lib/StaticAnalyzer/Core/IssueHash.cpp 
b/clang/lib/StaticAnalyzer/Core/IssueHash.cpp
index e7497f3fbdaa..2bea1593110a 100644
--- a/clang/lib/StaticAnalyzer/Core/IssueHash.cpp
+++ b/clang/lib/StaticAnalyzer/Core/IssueHash.cpp
@@ -120,7 +120,8 @@ static std::string GetEnclosingDeclContextSignature(const 
Decl *D) {
   return "";
 }
 
-static StringRef GetNthLineOfFile(const llvm::MemoryBuffer *Buffer, int Line) {
+static StringRef GetNthLineOfFile(llvm::Optional Buffer,
+  int Line) {
   if (!Buffer)
 return "";
 
@@ -135,7 +136,7 @@ static std::string NormalizeLine(const SourceManager , 
FullSourceLoc ,
  const LangOptions ) {
   static StringRef Whitespaces = " \t\n";
 
-  StringRef Str = GetNthLineOfFile(SM.getBuffer(L.getFileID(), L),
+  StringRef Str = GetNthLineOfFile(SM.getBufferOrNone(L.getFileID(), L),
L.getExpansionLineNumber());
   StringRef::size_type col = Str.find_first_not_of(Whitespaces);
   if (col == StringRef::npos)
@@ -144,8 

[PATCH] D89414: clang/StaticAnalyzer: Stop using SourceManager::getBuffer

2020-10-14 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGaf4fb416bd35: clang/StaticAnalyzer: Stop using 
SourceManager::getBuffer (authored by dexonsmith).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89414

Files:
  clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
  clang/lib/StaticAnalyzer/Core/BugReporter.cpp
  clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
  clang/lib/StaticAnalyzer/Core/IssueHash.cpp
  clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
  clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
  clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp

Index: clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
===
--- clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
+++ clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
@@ -476,7 +476,7 @@
 static bool isBisonFile(ASTContext ) {
   const SourceManager  = C.getSourceManager();
   FileID FID = SM.getMainFileID();
-  StringRef Buffer = SM.getBuffer(FID)->getBuffer();
+  StringRef Buffer = SM.getBufferOrFake(FID).getBuffer();
   if (Buffer.startswith("/* A Bison parser, made by"))
 return true;
   return false;
Index: clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
===
--- clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
+++ clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
@@ -160,9 +160,8 @@
   assert(LocInfo.second > SM.getExpansionColumnNumber(Loc) &&
  "position in file is before column number?");
 
-  bool InvalidBuffer = false;
-  const MemoryBuffer *Buf = SM.getBuffer(LocInfo.first, );
-  assert(!InvalidBuffer && "got an invalid buffer for the location's file");
+  Optional Buf = SM.getBufferOrNone(LocInfo.first);
+  assert(Buf && "got an invalid buffer for the location's file");
   assert(Buf->getBufferSize() >= (LocInfo.second + TokenLen) &&
  "token extends past end of buffer?");
 
Index: clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
===
--- clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
+++ clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
@@ -887,12 +887,12 @@
 FileID File;
 unsigned Offset;
 std::tie(File, Offset) = SM.getDecomposedLoc(ExpanLoc);
-const llvm::MemoryBuffer *MB = SM.getBuffer(File);
-const char *MacroNameTokenPos = MB->getBufferStart() + Offset;
+llvm::MemoryBufferRef MB = SM.getBufferOrFake(File);
+const char *MacroNameTokenPos = MB.getBufferStart() + Offset;
 
 RawLexer = std::make_unique(SM.getLocForStartOfFile(File), LangOpts,
-   MB->getBufferStart(), MacroNameTokenPos,
-   MB->getBufferEnd());
+   MB.getBufferStart(), MacroNameTokenPos,
+   MB.getBufferEnd());
   }
 
   void next(Token ) {
Index: clang/lib/StaticAnalyzer/Core/IssueHash.cpp
===
--- clang/lib/StaticAnalyzer/Core/IssueHash.cpp
+++ clang/lib/StaticAnalyzer/Core/IssueHash.cpp
@@ -120,7 +120,8 @@
   return "";
 }
 
-static StringRef GetNthLineOfFile(const llvm::MemoryBuffer *Buffer, int Line) {
+static StringRef GetNthLineOfFile(llvm::Optional Buffer,
+  int Line) {
   if (!Buffer)
 return "";
 
@@ -135,7 +136,7 @@
  const LangOptions ) {
   static StringRef Whitespaces = " \t\n";
 
-  StringRef Str = GetNthLineOfFile(SM.getBuffer(L.getFileID(), L),
+  StringRef Str = GetNthLineOfFile(SM.getBufferOrNone(L.getFileID(), L),
L.getExpansionLineNumber());
   StringRef::size_type col = Str.find_first_not_of(Whitespaces);
   if (col == StringRef::npos)
@@ -144,8 +145,8 @@
 col++;
   SourceLocation StartOfLine =
   SM.translateLineCol(SM.getFileID(L), L.getExpansionLineNumber(), col);
-  const llvm::MemoryBuffer *Buffer =
-  SM.getBuffer(SM.getFileID(StartOfLine), StartOfLine);
+  Optional Buffer =
+  SM.getBufferOrNone(SM.getFileID(StartOfLine), StartOfLine);
   if (!Buffer)
 return {};
 
Index: clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
===
--- clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
+++ clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
@@ -786,8 +786,8 @@
   if (LPosInfo.first != BugFileID)
 return;
 
-  const llvm::MemoryBuffer *Buf = SM.getBuffer(LPosInfo.first);
-  const char* FileStart = Buf->getBufferStart();
+  llvm::MemoryBufferRef Buf = SM.getBufferOrFake(LPosInfo.first);
+  const char *FileStart = Buf.getBufferStart();
 
   // Compute the column number.  Rewind from the current position to the start
   // 

[PATCH] D89441: RFC: Potential fixes to function-instrument=xray-never

2020-10-14 Thread Dean Michael Berris via Phabricator via cfe-commits
dberris added a comment.

> Do you think we should fix this by handling the xray-never attribute in 
> XRayInstrumentation, or having CodeGenFunction remove the threshold if 
> xray-never is set?

Good catch, thanks!

I think we should go with the former (handling the case in XRayInstrumentation) 
-- the rationale here is that when we apply the file-based always-instrument 
case, we ignore the "never" attribute (i.e. the "always" case overrides the 
"never" case). We should make sure that this case still works (if we don't have 
cases for that, then we should add those too).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89441

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


[clang] dde4e03 - clang/CodeGen: Stop using SourceManager::getBuffer, NFC

2020-10-14 Thread Duncan P . N . Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-10-14T23:32:43-04:00
New Revision: dde4e0318c4cd2054ed241bf248fdddb8d1973e3

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

LOG: clang/CodeGen: Stop using SourceManager::getBuffer, NFC

Update `clang/lib/CodeGen` to use a `MemoryBufferRef` from
`getBufferOrNone` instead of `MemoryBuffer*` from `getBuffer`. No
functionality change here.

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

Added: 


Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp
clang/lib/CodeGen/CodeGenAction.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 71ebd268f630..8280fe718f26 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -374,9 +374,8 @@ CGDebugInfo::computeChecksum(FileID FID, SmallString<32> 
) const {
 return None;
 
   SourceManager  = CGM.getContext().getSourceManager();
-  bool Invalid;
-  const llvm::MemoryBuffer *MemBuffer = SM.getBuffer(FID, );
-  if (Invalid)
+  Optional MemBuffer = SM.getBufferOrNone(FID);
+  if (!MemBuffer)
 return None;
 
   llvm::MD5 Hash;

diff  --git a/clang/lib/CodeGen/CodeGenAction.cpp 
b/clang/lib/CodeGen/CodeGenAction.cpp
index 5ea2fc23ee11..871cdb7dac3b 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -1122,11 +1122,10 @@ void CodeGenAction::ExecuteAction() {
 if (BA != Backend_EmitNothing && !OS)
   return;
 
-bool Invalid;
 SourceManager  = CI.getSourceManager();
 FileID FID = SM.getMainFileID();
-const llvm::MemoryBuffer *MainFile = SM.getBuffer(FID, );
-if (Invalid)
+Optional MainFile = SM.getBufferOrNone(FID);
+if (!MainFile)
   return;
 
 TheModule = loadModule(*MainFile);
@@ -1141,8 +1140,7 @@ void CodeGenAction::ExecuteAction() {
   TheModule->setTargetTriple(TargetOpts.Triple);
 }
 
-EmbedBitcode(TheModule.get(), CodeGenOpts,
- MainFile->getMemBufferRef());
+EmbedBitcode(TheModule.get(), CodeGenOpts, *MainFile);
 
 LLVMContext  = TheModule->getContext();
 Ctx.setInlineAsmDiagnosticHandler(BitcodeInlineAsmDiagHandler,



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


[PATCH] D89411: clang/CodeGen: Stop using SourceManager::getBuffer, NFC

2020-10-14 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGdde4e0318c4c: clang/CodeGen: Stop using 
SourceManager::getBuffer, NFC (authored by dexonsmith).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89411

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CodeGenAction.cpp


Index: clang/lib/CodeGen/CodeGenAction.cpp
===
--- clang/lib/CodeGen/CodeGenAction.cpp
+++ clang/lib/CodeGen/CodeGenAction.cpp
@@ -1122,11 +1122,10 @@
 if (BA != Backend_EmitNothing && !OS)
   return;
 
-bool Invalid;
 SourceManager  = CI.getSourceManager();
 FileID FID = SM.getMainFileID();
-const llvm::MemoryBuffer *MainFile = SM.getBuffer(FID, );
-if (Invalid)
+Optional MainFile = SM.getBufferOrNone(FID);
+if (!MainFile)
   return;
 
 TheModule = loadModule(*MainFile);
@@ -1141,8 +1140,7 @@
   TheModule->setTargetTriple(TargetOpts.Triple);
 }
 
-EmbedBitcode(TheModule.get(), CodeGenOpts,
- MainFile->getMemBufferRef());
+EmbedBitcode(TheModule.get(), CodeGenOpts, *MainFile);
 
 LLVMContext  = TheModule->getContext();
 Ctx.setInlineAsmDiagnosticHandler(BitcodeInlineAsmDiagHandler,
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -374,9 +374,8 @@
 return None;
 
   SourceManager  = CGM.getContext().getSourceManager();
-  bool Invalid;
-  const llvm::MemoryBuffer *MemBuffer = SM.getBuffer(FID, );
-  if (Invalid)
+  Optional MemBuffer = SM.getBufferOrNone(FID);
+  if (!MemBuffer)
 return None;
 
   llvm::MD5 Hash;


Index: clang/lib/CodeGen/CodeGenAction.cpp
===
--- clang/lib/CodeGen/CodeGenAction.cpp
+++ clang/lib/CodeGen/CodeGenAction.cpp
@@ -1122,11 +1122,10 @@
 if (BA != Backend_EmitNothing && !OS)
   return;
 
-bool Invalid;
 SourceManager  = CI.getSourceManager();
 FileID FID = SM.getMainFileID();
-const llvm::MemoryBuffer *MainFile = SM.getBuffer(FID, );
-if (Invalid)
+Optional MainFile = SM.getBufferOrNone(FID);
+if (!MainFile)
   return;
 
 TheModule = loadModule(*MainFile);
@@ -1141,8 +1140,7 @@
   TheModule->setTargetTriple(TargetOpts.Triple);
 }
 
-EmbedBitcode(TheModule.get(), CodeGenOpts,
- MainFile->getMemBufferRef());
+EmbedBitcode(TheModule.get(), CodeGenOpts, *MainFile);
 
 LLVMContext  = TheModule->getContext();
 Ctx.setInlineAsmDiagnosticHandler(BitcodeInlineAsmDiagHandler,
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -374,9 +374,8 @@
 return None;
 
   SourceManager  = CGM.getContext().getSourceManager();
-  bool Invalid;
-  const llvm::MemoryBuffer *MemBuffer = SM.getBuffer(FID, );
-  if (Invalid)
+  Optional MemBuffer = SM.getBufferOrNone(FID);
+  if (!MemBuffer)
 return None;
 
   llvm::MD5 Hash;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D89025: [RISCV] Add -mtune support

2020-10-14 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng marked an inline comment as done.
kito-cheng added a comment.

@MaskRay Thanks, that's first time I know the suffix `-SAME`  :P


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

https://reviews.llvm.org/D89025

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


[PATCH] D89025: [RISCV] Add -mtune support

2020-10-14 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng updated this revision to Diff 298293.
kito-cheng added a comment.

ChangeLog:

- Update testcase according to MaskRay's suggestion.


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

https://reviews.llvm.org/D89025

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/Targets/RISCV.cpp
  clang/lib/Basic/Targets/RISCV.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/riscv-cpus.c
  clang/test/Misc/target-invalid-cpu-note.c
  llvm/include/llvm/Support/RISCVTargetParser.def
  llvm/include/llvm/Support/TargetParser.h
  llvm/lib/Support/TargetParser.cpp
  llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp
  llvm/lib/Target/RISCV/RISCVSubtarget.cpp
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/lib/Target/RISCV/RISCVTargetMachine.cpp

Index: llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
===
--- llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
+++ llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
@@ -75,13 +75,16 @@
 const RISCVSubtarget *
 RISCVTargetMachine::getSubtargetImpl(const Function ) const {
   Attribute CPUAttr = F.getFnAttribute("target-cpu");
+  Attribute TuneAttr = F.getFnAttribute("tune-cpu");
   Attribute FSAttr = F.getFnAttribute("target-features");
 
   std::string CPU =
   CPUAttr.isValid() ? CPUAttr.getValueAsString().str() : TargetCPU;
+  std::string TuneCPU =
+  TuneAttr.isValid() ? TuneAttr.getValueAsString().str() : CPU;
   std::string FS =
   FSAttr.isValid() ? FSAttr.getValueAsString().str() : TargetFS;
-  std::string Key = CPU + FS;
+  std::string Key = CPU + TuneCPU + FS;
   auto  = SubtargetMap[Key];
   if (!I) {
 // This needs to be done before we create a new subtarget since any
@@ -98,7 +101,7 @@
   }
   ABIName = ModuleTargetABI->getString();
 }
-I = std::make_unique(TargetTriple, CPU, FS, ABIName, *this);
+I = std::make_unique(TargetTriple, CPU, TuneCPU, FS, ABIName, *this);
   }
   return I.get();
 }
Index: llvm/lib/Target/RISCV/RISCVSubtarget.h
===
--- llvm/lib/Target/RISCV/RISCVSubtarget.h
+++ llvm/lib/Target/RISCV/RISCVSubtarget.h
@@ -71,13 +71,15 @@
   /// Initializes using the passed in CPU and feature strings so that we can
   /// use initializer lists for subtarget initialization.
   RISCVSubtarget (const Triple ,
-  StringRef CPU, StringRef FS,
+  StringRef CPU,
+  StringRef TuneCPU,
+  StringRef FS,
   StringRef ABIName);
 
 public:
   // Initializes the data members to match that of the specified triple.
-  RISCVSubtarget(const Triple , StringRef CPU, StringRef FS,
- StringRef ABIName, const TargetMachine );
+  RISCVSubtarget(const Triple , StringRef CPU, StringRef TuneCPU,
+ StringRef FS, StringRef ABIName, const TargetMachine );
 
   // Parses features string setting specified subtarget options. The
   // definition of this function is auto-generated by tblgen.
Index: llvm/lib/Target/RISCV/RISCVSubtarget.cpp
===
--- llvm/lib/Target/RISCV/RISCVSubtarget.cpp
+++ llvm/lib/Target/RISCV/RISCVSubtarget.cpp
@@ -30,13 +30,16 @@
 void RISCVSubtarget::anchor() {}
 
 RISCVSubtarget ::initializeSubtargetDependencies(
-const Triple , StringRef CPU, StringRef FS, StringRef ABIName) {
+const Triple , StringRef CPU, StringRef TuneCPU, StringRef FS, StringRef ABIName) {
   // Determine default and user-specified characteristics
   bool Is64Bit = TT.isArch64Bit();
   std::string CPUName = std::string(CPU);
+  std::string TuneCPUName = std::string(TuneCPU);
   if (CPUName.empty())
 CPUName = Is64Bit ? "generic-rv64" : "generic-rv32";
-  ParseSubtargetFeatures(CPUName, /*TuneCPU*/ CPUName, FS);
+  if (TuneCPUName.empty())
+TuneCPUName = CPUName;
+  ParseSubtargetFeatures(CPUName, TuneCPUName, FS);
   if (Is64Bit) {
 XLenVT = MVT::i64;
 XLen = 64;
@@ -47,11 +50,12 @@
   return *this;
 }
 
-RISCVSubtarget::RISCVSubtarget(const Triple , StringRef CPU, StringRef FS,
+RISCVSubtarget::RISCVSubtarget(const Triple , StringRef CPU,
+   StringRef TuneCPU, StringRef FS,
StringRef ABIName, const TargetMachine )
-: RISCVGenSubtargetInfo(TT, CPU, /*TuneCPU*/ CPU, FS),
+: RISCVGenSubtargetInfo(TT, CPU, TuneCPU, FS),
   UserReservedRegister(RISCV::NUM_TARGET_REGS),
-  FrameLowering(initializeSubtargetDependencies(TT, CPU, FS, ABIName)),
+  FrameLowering(initializeSubtargetDependencies(TT, CPU, TuneCPU, FS, ABIName)),
   InstrInfo(*this), RegInfo(getHwMode()), TLInfo(TM, *this) {
   CallLoweringInfo.reset(new RISCVCallLowering(*getTargetLowering()));
   Legalizer.reset(new 

Re: [Lldb-commits] Upcoming upgrade of LLVM buildbot

2020-10-14 Thread Vitaly Buka via cfe-commits
I switched sanitizers and two rnk@ bots back to the primary server.
http://lab.llvm.org:8011/#/waterfall?tags=sanitizer

On Tue, 13 Oct 2020 at 22:42, Vitaly Buka  wrote:

> They do on staging.
> http://lab.llvm.org:8014/#/builders/sanitizer-windows
> http://lab.llvm.org:8014/#/builders/clang-x64-windows-msvc
>
> Galina, when do you plan to push this to the primary server?
> If it's a few days, I'd rather keep bots on staging to have colors.
>
>
>
> On Tue, 13 Oct 2020 at 11:11, Reid Kleckner  wrote:
>
>> FWIW, I don't see any issues with my two bots that use buildbot annotated
>> commands:
>> http://lab.llvm.org:8011/#/builders/sanitizer-windows
>> http://lab.llvm.org:8011/#/builders/clang-x64-windows-msvc
>> The individual steps don't highlight as green or red, but that's OK for
>> now.
>>
>> On Mon, Oct 12, 2020 at 7:19 PM Galina Kistanova 
>> wrote:
>>
>>> We have a better version of AnnotatedCommand on the staging. It should
>>> be a functional equivalent of the old one.
>>> We need to stress test it well before moving to the production build bot.
>>>
>>> For that we need all sanitizer + other bots which use the
>>> AnnotatedCommand directly or indirectly moved temporarily to the staging.
>>>
>>> Please let me know when that could be arranged.
>>>
>>> Thanks
>>>
>>> Galina
>>>
>>> On Mon, Oct 12, 2020 at 11:39 AM Reid Kleckner  wrote:
>>>
 On Wed, Oct 7, 2020 at 4:32 PM Galina Kistanova via lldb-commits <
 lldb-comm...@lists.llvm.org> wrote:

> They are online now -
> http://lab.llvm.org:8011/#/waterfall?tags=sanitizer
>
> AnnotatedCommand has severe design conflict with the new buildbot.
> We have changed it to be safe and still do something useful, but it
> will need more love and care.
>
> Please let me know if you have some spare time to work on porting
> AnnotatedCommand.
>

 That's unfortunate, it would've been good to know that earlier. I and
 another team member have spent a fair amount of time porting things to use
 more AnnotatedCommand steps, because it gives us the flexibility to test
 steps locally and make changes to the steps without restarting the buildbot
 master. IMO that is the Right Way to define steps: a script that you can
 run locally on a machine that satisfies the OS and dep requirements of the
 script.

 I am restarting the two bots that I am responsible for, and may need
 some help debugging further issues soon. I'll let you know.

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


[PATCH] D89446: [WebAssembly] Prototype i8x16.popcnt

2020-10-14 Thread Thomas Lively via Phabricator via cfe-commits
tlively created this revision.
tlively added a reviewer: aheejin.
Herald added subscribers: llvm-commits, cfe-commits, ecnelises, sunfish, 
hiraditya, jgravelle-google, sbc100, dschuff.
Herald added projects: clang, LLVM.
tlively requested review of this revision.

As proposed at https://github.com/WebAssembly/simd/pull/379. Use a target
builtin and intrinsic rather than normal codegen patterns to make the
instruction opt-in until it is merged to the proposal and stabilized in engines.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D89446

Files:
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/builtins-wasm.c
  llvm/include/llvm/IR/IntrinsicsWebAssembly.td
  llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
  llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll
  llvm/test/MC/WebAssembly/simd-encodings.s

Index: llvm/test/MC/WebAssembly/simd-encodings.s
===
--- llvm/test/MC/WebAssembly/simd-encodings.s
+++ llvm/test/MC/WebAssembly/simd-encodings.s
@@ -367,6 +367,9 @@
 # CHECK: i8x16.avgr_u # encoding: [0xfd,0x7b]
 i8x16.avgr_u
 
+# CHECK: i8x16.popcnt # encoding: [0xfd,0x7c]
+i8x16.popcnt
+
 # CHECK: i16x8.abs # encoding: [0xfd,0x80,0x01]
 i16x8.abs
 
Index: llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll
===
--- llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll
+++ llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll
@@ -75,6 +75,16 @@
   ret <16 x i8> %a
 }
 
+; CHECK-LABEL: popcnt_v16i8:
+; SIMD128-NEXT: .functype popcnt_v16i8 (v128) -> (v128){{$}}
+; SIMD128-NEXT: i8x16.popcnt $push[[R:[0-9]+]]=, $0{{$}}
+; SIMD128-NEXT: return $pop[[R]]{{$}}
+declare <16 x i8> @llvm.wasm.popcnt(<16 x i8>)
+define <16 x i8> @popcnt_v16i8(<16 x i8> %x) {
+ %a = call <16 x i8> @llvm.wasm.popcnt(<16 x i8> %x)
+ ret <16 x i8> %a
+}
+
 ; CHECK-LABEL: any_v16i8:
 ; SIMD128-NEXT: .functype any_v16i8 (v128) -> (i32){{$}}
 ; SIMD128-NEXT: i8x16.any_true $push[[R:[0-9]+]]=, $0{{$}}
Index: llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
===
--- llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
+++ llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
@@ -785,6 +785,9 @@
 // All lanes true: all_true
 defm ALLTRUE : SIMDReduce;
 
+// Population count: popcnt
+defm POPCNT : SIMDUnary;
+
 // Reductions already return 0 or 1, so and 1, setne 0, and seteq 1
 // can be folded out
 foreach reduction =
Index: llvm/include/llvm/IR/IntrinsicsWebAssembly.td
===
--- llvm/include/llvm/IR/IntrinsicsWebAssembly.td
+++ llvm/include/llvm/IR/IntrinsicsWebAssembly.td
@@ -254,6 +254,11 @@
 [IntrWriteMem, IntrArgMemOnly],
 "", [SDNPMemOperand]>;
 
+// TODO: Replace this intrinsic with normal ISel patterns once popcnt is merged
+// to the proposal.
+def int_wasm_popcnt :
+  Intrinsic<[llvm_v16i8_ty], [llvm_v16i8_ty], [IntrNoMem, IntrSpeculatable]>;
+
 //===--===//
 // Thread-local storage intrinsics
 //===--===//
Index: clang/test/CodeGen/builtins-wasm.c
===
--- clang/test/CodeGen/builtins-wasm.c
+++ clang/test/CodeGen/builtins-wasm.c
@@ -538,6 +538,12 @@
   // WEBASSEMBLY-NEXT: ret
 }
 
+i8x16 popcnt(i8x16 x) {
+  return __builtin_wasm_popcnt(x);
+  // WEBASSEMBLY: call <16 x i8> @llvm.wasm.popcnt(<16 x i8> %x)
+  // WEBASSEMBLY-NEXT: ret
+}
+
 int any_true_i8x16(i8x16 x) {
   return __builtin_wasm_any_true_i8x16(x);
   // WEBASSEMBLY: call i32 @llvm.wasm.anytrue.v16i8(<16 x i8> %x)
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -16616,6 +16616,11 @@
 Function *Callee = CGM.getIntrinsic(Intrinsic::wasm_dot);
 return Builder.CreateCall(Callee, {LHS, RHS});
   }
+  case WebAssembly::BI__builtin_wasm_popcnt: {
+Value *Vec = EmitScalarExpr(E->getArg(0));
+Function *Callee = CGM.getIntrinsic(Intrinsic::wasm_popcnt);
+return Builder.CreateCall(Callee, {Vec});
+  }
   case WebAssembly::BI__builtin_wasm_any_true_i8x16:
   case WebAssembly::BI__builtin_wasm_any_true_i16x8:
   case WebAssembly::BI__builtin_wasm_any_true_i32x4:
Index: clang/include/clang/Basic/BuiltinsWebAssembly.def
===
--- clang/include/clang/Basic/BuiltinsWebAssembly.def
+++ clang/include/clang/Basic/BuiltinsWebAssembly.def
@@ -114,6 +114,8 @@
 TARGET_BUILTIN(__builtin_wasm_avgr_u_i8x16, "V16UcV16UcV16Uc", "nc", "simd128")
 TARGET_BUILTIN(__builtin_wasm_avgr_u_i16x8, "V8UsV8UsV8Us", "nc", "simd128")
 

[PATCH] D89366: [WebAssembly] v128.load{8, 16, 32, 64}_lane instructions

2020-10-14 Thread Thomas Lively via Phabricator via cfe-commits
tlively updated this revision to Diff 298291.
tlively added a comment.

- Remove "Pure" from load builtins


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89366

Files:
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/builtins-wasm.c
  llvm/include/llvm/IR/IntrinsicsWebAssembly.td
  llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
  llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h
  llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
  llvm/test/CodeGen/WebAssembly/simd-load-lane-offset.ll
  llvm/test/MC/WebAssembly/simd-encodings.s

Index: llvm/test/MC/WebAssembly/simd-encodings.s
===
--- llvm/test/MC/WebAssembly/simd-encodings.s
+++ llvm/test/MC/WebAssembly/simd-encodings.s
@@ -280,6 +280,30 @@
 # CHECK: v128.bitselect # encoding: [0xfd,0x52]
 v128.bitselect
 
+# CHECK: v128.load8_lane 32, 1 # encoding: [0xfd,0x58,0x00,0x20,0x01]
+v128.load8_lane 32, 1
+
+# CHECK: v128.load16_lane 32, 1 # encoding: [0xfd,0x59,0x01,0x20,0x01]
+v128.load16_lane 32, 1
+
+# CHECK: v128.load32_lane 32, 1 # encoding: [0xfd,0x5a,0x02,0x20,0x01]
+v128.load32_lane 32, 1
+
+# CHECK: v128.load64_lane 32, 1 # encoding: [0xfd,0x5b,0x03,0x20,0x01]
+v128.load64_lane 32, 1
+
+# CHECK: v128.store8_lane 32, 1 # encoding: [0xfd,0x5c,0x00,0x20,0x01]
+v128.store8_lane 32, 1
+
+# CHECK: v128.store16_lane 32, 1 # encoding: [0xfd,0x5d,0x01,0x20,0x01]
+v128.store16_lane 32, 1
+
+# CHECK: v128.store32_lane 32, 1 # encoding: [0xfd,0x5e,0x02,0x20,0x01]
+v128.store32_lane 32, 1
+
+# CHECK: v128.store64_lane 32, 1 # encoding: [0xfd,0x5f,0x03,0x20,0x01]
+v128.store64_lane 32, 1
+
 # CHECK: i8x16.abs # encoding: [0xfd,0x60]
 i8x16.abs
 
Index: llvm/test/CodeGen/WebAssembly/simd-load-lane-offset.ll
===
--- /dev/null
+++ llvm/test/CodeGen/WebAssembly/simd-load-lane-offset.ll
@@ -0,0 +1,968 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s -verify-machineinstrs -mattr=+simd128 | FileCheck %s
+
+; Test SIMD v128.load{8,16,32,64}_lane instructions.
+
+; TODO: Use the offset field by supporting more patterns. Right now only the
+; equivalents of LoadPatNoOffset/StorePatNoOffset are supported.
+
+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
+target triple = "wasm32-unknown-unknown"
+
+declare <16 x i8> @llvm.wasm.load8.lane(i8*, <16 x i8>, i32)
+declare <8 x i16> @llvm.wasm.load16.lane(i16*, <8 x i16>, i32)
+declare <4 x i32> @llvm.wasm.load32.lane(i32*, <4 x i32>, i32)
+declare <2 x i64> @llvm.wasm.load64.lane(i64*, <2 x i64>, i32)
+
+declare void @llvm.wasm.store8.lane(i8*, <16 x i8>, i32)
+declare void @llvm.wasm.store16.lane(i16*, <8 x i16>, i32)
+declare void @llvm.wasm.store32.lane(i32*, <4 x i32>, i32)
+declare void @llvm.wasm.store64.lane(i64*, <2 x i64>, i32)
+
+;===
+; v128.load8_lane / v128.store8_lane
+;===
+
+define <16 x i8> @load_lane_i8_no_offset(i8* %p, <16 x i8> %v) {
+; CHECK-LABEL: load_lane_i8_no_offset:
+; CHECK: .functype load_lane_i8_no_offset (i32, v128) -> (v128)
+; CHECK-NEXT:  # %bb.0:
+; CHECK-NEXT:local.get 0
+; CHECK-NEXT:local.get 1
+; CHECK-NEXT:v128.load8_lane 0, 0
+; CHECK-NEXT:# fallthrough-return
+  %t = tail call <16 x i8> @llvm.wasm.load8.lane(i8* %p, <16 x i8> %v, i32 0)
+  ret <16 x i8> %t
+}
+
+define <16 x i8> @load_lane_i8_with_folded_offset(i8* %p, <16 x i8> %v) {
+; CHECK-LABEL: load_lane_i8_with_folded_offset:
+; CHECK: .functype load_lane_i8_with_folded_offset (i32, v128) -> (v128)
+; CHECK-NEXT:  # %bb.0:
+; CHECK-NEXT:local.get 0
+; CHECK-NEXT:i32.const 24
+; CHECK-NEXT:i32.add
+; CHECK-NEXT:local.get 1
+; CHECK-NEXT:v128.load8_lane 0, 0
+; CHECK-NEXT:# fallthrough-return
+  %q = ptrtoint i8* %p to i32
+  %r = add nuw i32 %q, 24
+  %s = inttoptr i32 %r to i8*
+  %t = tail call <16 x i8> @llvm.wasm.load8.lane(i8* %s, <16 x i8> %v, i32 0)
+  ret <16 x i8> %t
+}
+
+define <16 x i8> @load_lane_i8_with_folded_gep_offset(i8* %p, <16 x i8> %v) {
+; CHECK-LABEL: load_lane_i8_with_folded_gep_offset:
+; CHECK: .functype load_lane_i8_with_folded_gep_offset (i32, v128) -> (v128)
+; CHECK-NEXT:  # %bb.0:
+; CHECK-NEXT:local.get 0
+; CHECK-NEXT:i32.const 6
+; CHECK-NEXT:i32.add
+; CHECK-NEXT:local.get 1
+; CHECK-NEXT:v128.load8_lane 0, 0
+; CHECK-NEXT:# fallthrough-return
+  %s = getelementptr inbounds i8, i8* %p, i32 6
+  %t = tail call <16 x i8> @llvm.wasm.load8.lane(i8* %s, <16 x i8> %v, i32 0)

[PATCH] D89445: clang/Basic: Remove ContentCache::getRawBuffer, NFC

2020-10-14 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith created this revision.
dexonsmith added a reviewer: arphaman.
Herald added subscribers: ributzka, kbarton, nemanjai.
dexonsmith requested review of this revision.

Replace `ContentCache::getRawBuffer` with `getBufferDataIfLoaded` and
`getBufferIfLoaded`, excising another accessor for the underlying
`MemoryBuffer*` in favour of `StringRef` and `MemoryBufferRef`.


https://reviews.llvm.org/D89445

Files:
  clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
  clang/include/clang/Basic/SourceManager.h
  clang/lib/Basic/SourceManager.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp

Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -1468,7 +1468,7 @@
 if (PP->getHeaderSearchInfo()
 .getHeaderSearchOpts()
 .ValidateASTInputFilesContent) {
-  auto *MemBuff = Cache->getRawBuffer();
+  auto MemBuff = Cache->getBufferIfLoaded();
   if (MemBuff)
 ContentHash = hash_value(MemBuff->getBuffer());
   else
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -1542,7 +1542,7 @@
   = SourceMgr.getOrCreateContentCache(File, isSystem(FileCharacter));
 if (OverriddenBuffer && !ContentCache->BufferOverridden &&
 ContentCache->ContentsEntry == ContentCache->OrigEntry &&
-!ContentCache->getRawBuffer()) {
+!ContentCache->getBufferIfLoaded()) {
   auto Buffer = ReadBuffer(SLocEntryCursor, File->getName());
   if (!Buffer)
 return true;
Index: clang/lib/Basic/SourceManager.cpp
===
--- clang/lib/Basic/SourceManager.cpp
+++ clang/lib/Basic/SourceManager.cpp
@@ -153,7 +153,7 @@
 
   // Check that the file's size is the same as in the file entry (which may
   // have come from a stat cache).
-  if (getRawBuffer()->getBufferSize() != (size_t)ContentsEntry->getSize()) {
+  if (Buffer->getBufferSize() != (size_t)ContentsEntry->getSize()) {
 if (Diag.isDiagnosticInFlight())
   Diag.SetDelayedDiagnostic(diag::err_file_modified,
 ContentsEntry->getName());
@@ -361,7 +361,7 @@
 Clone->BufferOverridden = Cache->BufferOverridden;
 Clone->IsFileVolatile = Cache->IsFileVolatile;
 Clone->IsTransient = Cache->IsTransient;
-Clone->setUnownedBuffer(Cache->getRawBuffer());
+Clone->setUnownedBuffer(Cache->getBufferIfLoaded());
 return Clone;
   };
 
@@ -474,7 +474,8 @@
 SourceManager::getFakeContentCacheForRecovery() const {
   if (!FakeContentCacheForRecovery) {
 FakeContentCacheForRecovery = std::make_unique();
-FakeContentCacheForRecovery->setUnownedBuffer(getFakeBufferForRecovery());
+FakeContentCacheForRecovery->setUnownedBuffer(
+getFakeBufferForRecovery()->getMemBufferRef());
   }
   return FakeContentCacheForRecovery.get();
 }
@@ -749,10 +750,7 @@
   if (!SLoc.isFile() || MyInvalid)
 return None;
 
-  if (const llvm::MemoryBuffer *Buf =
-  SLoc.getFile().getContentCache()->getRawBuffer())
-return Buf->getBuffer();
-  return None;
+  return SLoc.getFile().getContentCache()->getBufferDataIfLoaded();
 }
 
 llvm::Optional SourceManager::getBufferDataOrNone(FileID FID) const {
Index: clang/include/clang/Basic/SourceManager.h
===
--- clang/include/clang/Basic/SourceManager.h
+++ clang/include/clang/Basic/SourceManager.h
@@ -194,9 +194,23 @@
 /// this content cache.  This is used for performance analysis.
 llvm::MemoryBuffer::BufferKind getMemoryBufferKind() const;
 
-/// Get the underlying buffer, returning NULL if the buffer is not
-/// yet available.
-const llvm::MemoryBuffer *getRawBuffer() const { return Buffer.get(); }
+/// Return the buffer, only if it has been loaded.
+/// specified FileID, returning None if it's not yet loaded.
+///
+/// \param FID The file ID whose contents will be returned.
+llvm::Optional getBufferIfLoaded() const {
+  if (Buffer)
+return Buffer->getMemBufferRef();
+  return None;
+}
+
+/// Return a StringRef to the source buffer data, only if it has already
+/// been loaded.
+llvm::Optional getBufferDataIfLoaded() const {
+  if (Buffer)
+return Buffer->getBuffer();
+  return None;
+}
 
 /// Set the buffer.
 void setBuffer(std::unique_ptr B) {
@@ -207,10 +221,10 @@
 /// Set the buffer to one that's not owned (or to nullptr).
 ///
 /// \pre Buffer cannot already be set.
-void setUnownedBuffer(const llvm::MemoryBuffer *B) {
+void setUnownedBuffer(llvm::Optional B) {
   assert(!Buffer && "Expected to be called right after 

[PATCH] D89409: clang/Frontend: Mostly stop using SourceManager::getBuffer, NFC

2020-10-14 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG63af24227981: clang/Frontend: Mostly stop using 
SourceManager::getBuffer, NFC (authored by dexonsmith).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89409

Files:
  clang/lib/Frontend/FrontendAction.cpp
  clang/lib/Frontend/FrontendActions.cpp
  clang/lib/Frontend/Rewrite/HTMLPrint.cpp
  clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
  clang/lib/Frontend/Rewrite/RewriteObjC.cpp


Index: clang/lib/Frontend/Rewrite/RewriteObjC.cpp
===
--- clang/lib/Frontend/Rewrite/RewriteObjC.cpp
+++ clang/lib/Frontend/Rewrite/RewriteObjC.cpp
@@ -631,9 +631,9 @@
 
   // Get the ID and start/end of the main file.
   MainFileID = SM->getMainFileID();
-  const llvm::MemoryBuffer *MainBuf = SM->getBuffer(MainFileID);
-  MainFileStart = MainBuf->getBufferStart();
-  MainFileEnd = MainBuf->getBufferEnd();
+  llvm::MemoryBufferRef MainBuf = SM->getBufferOrFake(MainFileID);
+  MainFileStart = MainBuf.getBufferStart();
+  MainFileEnd = MainBuf.getBufferEnd();
 
   Rewrite.setSourceMgr(Context->getSourceManager(), Context->getLangOpts());
 }
Index: clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
===
--- clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
+++ clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
@@ -702,9 +702,9 @@
 
   // Get the ID and start/end of the main file.
   MainFileID = SM->getMainFileID();
-  const llvm::MemoryBuffer *MainBuf = SM->getBuffer(MainFileID);
-  MainFileStart = MainBuf->getBufferStart();
-  MainFileEnd = MainBuf->getBufferEnd();
+  llvm::MemoryBufferRef MainBuf = SM->getBufferOrFake(MainFileID);
+  MainFileStart = MainBuf.getBufferStart();
+  MainFileEnd = MainBuf.getBufferEnd();
 
   Rewrite.setSourceMgr(Context->getSourceManager(), Context->getLangOpts());
 }
Index: clang/lib/Frontend/Rewrite/HTMLPrint.cpp
===
--- clang/lib/Frontend/Rewrite/HTMLPrint.cpp
+++ clang/lib/Frontend/Rewrite/HTMLPrint.cpp
@@ -70,7 +70,7 @@
   if (Entry)
 Name = Entry->getName();
   else
-Name = R.getSourceMgr().getBuffer(FID)->getBufferIdentifier();
+Name = R.getSourceMgr().getBufferOrFake(FID).getBufferIdentifier();
 
   html::AddLineNumbers(R, FID);
   html::AddHeaderFooterInternalBuiltinCSS(R, FID, Name);
Index: clang/lib/Frontend/FrontendActions.cpp
===
--- clang/lib/Frontend/FrontendActions.cpp
+++ clang/lib/Frontend/FrontendActions.cpp
@@ -805,11 +805,9 @@
   // concern, so if we scan for too long, we'll just assume the file should
   // be opened in binary mode.
   bool BinaryMode = true;
-  bool InvalidFile = false;
   const SourceManager& SM = CI.getSourceManager();
-  const llvm::MemoryBuffer *Buffer = SM.getBuffer(SM.getMainFileID(),
- );
-  if (!InvalidFile) {
+  if (llvm::Optional Buffer =
+  SM.getBufferOrNone(SM.getMainFileID())) {
 const char *cur = Buffer->getBufferStart();
 const char *end = Buffer->getBufferEnd();
 const char *next = (cur != end) ? cur + 1 : end;
@@ -937,12 +935,12 @@
 void PrintDependencyDirectivesSourceMinimizerAction::ExecuteAction() {
   CompilerInstance  = getCompilerInstance();
   SourceManager  = CI.getPreprocessor().getSourceManager();
-  const llvm::MemoryBuffer *FromFile = SM.getBuffer(SM.getMainFileID());
+  llvm::MemoryBufferRef FromFile = SM.getBufferOrFake(SM.getMainFileID());
 
   llvm::SmallString<1024> Output;
   llvm::SmallVector Toks;
   if (minimizeSourceToDependencyDirectives(
-  FromFile->getBuffer(), Output, Toks, (),
+  FromFile.getBuffer(), Output, Toks, (),
   SM.getLocForStartOfFile(SM.getMainFileID( {
 assert(CI.getDiagnostics().hasErrorOccurred() &&
"no errors reported for failure");
Index: clang/lib/Frontend/FrontendAction.cpp
===
--- clang/lib/Frontend/FrontendAction.cpp
+++ clang/lib/Frontend/FrontendAction.cpp
@@ -450,7 +450,7 @@
PresumedModuleMapFile))
 return true;
 
-  if (SrcMgr.getBuffer(ModuleMapID)->getBufferSize() == Offset)
+  if (SrcMgr.getBufferOrFake(ModuleMapID).getBufferSize() == Offset)
 Offset = 0;
 
   return false;


Index: clang/lib/Frontend/Rewrite/RewriteObjC.cpp
===
--- clang/lib/Frontend/Rewrite/RewriteObjC.cpp
+++ clang/lib/Frontend/Rewrite/RewriteObjC.cpp
@@ -631,9 +631,9 @@
 
   // Get the ID and start/end of the main file.
   MainFileID = SM->getMainFileID();
-  const llvm::MemoryBuffer *MainBuf = SM->getBuffer(MainFileID);
-  MainFileStart = MainBuf->getBufferStart();
-  

[clang] 63af242 - clang/Frontend: Mostly stop using SourceManager::getBuffer, NFC

2020-10-14 Thread Duncan P . N . Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-10-14T23:31:28-04:00
New Revision: 63af2422798188d70a411f76b0f06ab63a783a0d

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

LOG: clang/Frontend: Mostly stop using SourceManager::getBuffer, NFC

Update clang/lib/Frontend to use a `MemoryBufferRef` from
`getBufferOrFake` instead of `MemoryBuffer*` from `getBuffer`, with the
exception of `FrontendInputFile`, which I'm leaving for later.

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

Added: 


Modified: 
clang/lib/Frontend/FrontendAction.cpp
clang/lib/Frontend/FrontendActions.cpp
clang/lib/Frontend/Rewrite/HTMLPrint.cpp
clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
clang/lib/Frontend/Rewrite/RewriteObjC.cpp

Removed: 




diff  --git a/clang/lib/Frontend/FrontendAction.cpp 
b/clang/lib/Frontend/FrontendAction.cpp
index 92654dbe8a10..9a806d7c9af8 100644
--- a/clang/lib/Frontend/FrontendAction.cpp
+++ b/clang/lib/Frontend/FrontendAction.cpp
@@ -450,7 +450,7 @@ static bool loadModuleMapForModuleBuild(CompilerInstance 
, bool IsSystem,
PresumedModuleMapFile))
 return true;
 
-  if (SrcMgr.getBuffer(ModuleMapID)->getBufferSize() == Offset)
+  if (SrcMgr.getBufferOrFake(ModuleMapID).getBufferSize() == Offset)
 Offset = 0;
 
   return false;

diff  --git a/clang/lib/Frontend/FrontendActions.cpp 
b/clang/lib/Frontend/FrontendActions.cpp
index 77a88f696abc..ec5caceba207 100644
--- a/clang/lib/Frontend/FrontendActions.cpp
+++ b/clang/lib/Frontend/FrontendActions.cpp
@@ -805,11 +805,9 @@ void PrintPreprocessedAction::ExecuteAction() {
   // concern, so if we scan for too long, we'll just assume the file should
   // be opened in binary mode.
   bool BinaryMode = true;
-  bool InvalidFile = false;
   const SourceManager& SM = CI.getSourceManager();
-  const llvm::MemoryBuffer *Buffer = SM.getBuffer(SM.getMainFileID(),
- );
-  if (!InvalidFile) {
+  if (llvm::Optional Buffer =
+  SM.getBufferOrNone(SM.getMainFileID())) {
 const char *cur = Buffer->getBufferStart();
 const char *end = Buffer->getBufferEnd();
 const char *next = (cur != end) ? cur + 1 : end;
@@ -937,12 +935,12 @@ void DumpCompilerOptionsAction::ExecuteAction() {
 void PrintDependencyDirectivesSourceMinimizerAction::ExecuteAction() {
   CompilerInstance  = getCompilerInstance();
   SourceManager  = CI.getPreprocessor().getSourceManager();
-  const llvm::MemoryBuffer *FromFile = SM.getBuffer(SM.getMainFileID());
+  llvm::MemoryBufferRef FromFile = SM.getBufferOrFake(SM.getMainFileID());
 
   llvm::SmallString<1024> Output;
   llvm::SmallVector Toks;
   if (minimizeSourceToDependencyDirectives(
-  FromFile->getBuffer(), Output, Toks, (),
+  FromFile.getBuffer(), Output, Toks, (),
   SM.getLocForStartOfFile(SM.getMainFileID( {
 assert(CI.getDiagnostics().hasErrorOccurred() &&
"no errors reported for failure");

diff  --git a/clang/lib/Frontend/Rewrite/HTMLPrint.cpp 
b/clang/lib/Frontend/Rewrite/HTMLPrint.cpp
index 982e56cebbca..1388c2e1faab 100644
--- a/clang/lib/Frontend/Rewrite/HTMLPrint.cpp
+++ b/clang/lib/Frontend/Rewrite/HTMLPrint.cpp
@@ -70,7 +70,7 @@ void HTMLPrinter::HandleTranslationUnit(ASTContext ) {
   if (Entry)
 Name = Entry->getName();
   else
-Name = R.getSourceMgr().getBuffer(FID)->getBufferIdentifier();
+Name = R.getSourceMgr().getBufferOrFake(FID).getBufferIdentifier();
 
   html::AddLineNumbers(R, FID);
   html::AddHeaderFooterInternalBuiltinCSS(R, FID, Name);

diff  --git a/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp 
b/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
index c0c81221b234..9d5366bb161e 100644
--- a/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
+++ b/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
@@ -702,9 +702,9 @@ void RewriteModernObjC::InitializeCommon(ASTContext 
) {
 
   // Get the ID and start/end of the main file.
   MainFileID = SM->getMainFileID();
-  const llvm::MemoryBuffer *MainBuf = SM->getBuffer(MainFileID);
-  MainFileStart = MainBuf->getBufferStart();
-  MainFileEnd = MainBuf->getBufferEnd();
+  llvm::MemoryBufferRef MainBuf = SM->getBufferOrFake(MainFileID);
+  MainFileStart = MainBuf.getBufferStart();
+  MainFileEnd = MainBuf.getBufferEnd();
 
   Rewrite.setSourceMgr(Context->getSourceManager(), Context->getLangOpts());
 }

diff  --git a/clang/lib/Frontend/Rewrite/RewriteObjC.cpp 
b/clang/lib/Frontend/Rewrite/RewriteObjC.cpp
index 990509a84b06..3caf9a672062 100644
--- a/clang/lib/Frontend/Rewrite/RewriteObjC.cpp
+++ b/clang/lib/Frontend/Rewrite/RewriteObjC.cpp
@@ -631,9 +631,9 @@ void RewriteObjC::InitializeCommon(ASTContext ) {
 
   // Get the ID and start/end of the main file.
   

[PATCH] D89443: [PowerPC][AIX] Make `__vector [un]signed long` an error

2020-10-14 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast created this revision.
hubert.reinterpretcast added reviewers: nemanjai, ZarkoCA, cebowleratibm.
Herald added a subscriber: shchenz.
Herald added a project: clang.
hubert.reinterpretcast requested review of this revision.

The semantics associated with `__vector [un]signed long` are neither 
consistently specified nor consistently implemented. The IBM XL compilers on 
AIX traditionally treated these as deprecated aliases for the corresponding 
`__vector int` type in both 32-bit and 64-bit modes. The newer, Clang-based, 
IBM XL compilers on AIX make usage of the previously deprecated types an error. 
This is also consistent with IBM XL C/C++ for Linux on Power (on little endian 
distributions).

In line with the above, this patch upgrades (on AIX) the deprecation of 
`__vector long` to become removal.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D89443

Files:
  clang/lib/Sema/DeclSpec.cpp
  clang/test/Parser/altivec.c
  clang/test/Parser/cxx-altivec.cpp

Index: clang/test/Parser/cxx-altivec.cpp
===
--- clang/test/Parser/cxx-altivec.cpp
+++ clang/test/Parser/cxx-altivec.cpp
@@ -1,6 +1,8 @@
-// RUN: %clang_cc1 -triple=powerpc-apple-darwin8 -target-feature +altivec -fsyntax-only -verify -std=c++11 %s
-// RUN: %clang_cc1 -triple=powerpc64-unknown-linux-gnu -target-feature +altivec -fsyntax-only -verify -std=c++11 %s
-// RUN: %clang_cc1 -triple=powerpc64le-unknown-linux-gnu -target-feature +altivec -fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -triple=powerpc-apple-darwin8 -target-feature +altivec -fsyntax-only -verify=expected,nonaix -std=c++11 %s
+// RUN: %clang_cc1 -triple=powerpc64-unknown-linux-gnu -target-feature +altivec -fsyntax-only -verify=expected,nonaix -std=c++11 %s
+// RUN: %clang_cc1 -triple=powerpc64le-unknown-linux-gnu -target-feature +altivec -fsyntax-only -verify=expected,nonaix -std=c++11 %s
+// RUN: %clang_cc1 -triple=powerpc-ibm-aix -target-feature +altivec -fsyntax-only -verify=expected,aix -std=c++11 %s
+// RUN: %clang_cc1 -triple=powerpc64-ibm-aix -target-feature +altivec -fsyntax-only -verify=expected,aix -std=c++11 %s
 #include 
 
 __vector char vv_c;
@@ -55,19 +57,33 @@
 
 vector int v = (vector int)(-1);
 
+// These should have errors on AIX and warnings otherwise.
+__vector long vv_l; // nonaix-warning {{Use of 'long' with '__vector' is deprecated}}
+// aix-error@-1 {{cannot use 'long' with '__vector'}}
+__vector signed long vv_sl; // nonaix-warning {{Use of 'long' with '__vector' is deprecated}}
+// aix-error@-1 {{cannot use 'long' with '__vector'}}
+__vector unsigned long vv_ul;   // nonaix-warning {{Use of 'long' with '__vector' is deprecated}}
+// aix-error@-1 {{cannot use 'long' with '__vector'}}
+__vector long int vv_li;// nonaix-warning {{Use of 'long' with '__vector' is deprecated}}
+// aix-error@-1 {{cannot use 'long' with '__vector'}}
+__vector signed long int vv_sli;// nonaix-warning {{Use of 'long' with '__vector' is deprecated}}
+// aix-error@-1 {{cannot use 'long' with '__vector'}}
+__vector unsigned long int vv_uli;  // nonaix-warning {{Use of 'long' with '__vector' is deprecated}}
+// aix-error@-1 {{cannot use 'long' with '__vector'}}
+vector long v_l;// nonaix-warning {{Use of 'long' with '__vector' is deprecated}}
+// aix-error@-1 {{cannot use 'long' with '__vector'}}
+vector signed long v_sl;// nonaix-warning {{Use of 'long' with '__vector' is deprecated}}
+// aix-error@-1 {{cannot use 'long' with '__vector'}}
+vector unsigned long v_ul;  // nonaix-warning {{Use of 'long' with '__vector' is deprecated}}
+// aix-error@-1 {{cannot use 'long' with '__vector'}}
+vector long int v_li;   // nonaix-warning {{Use of 'long' with '__vector' is deprecated}}
+// aix-error@-1 {{cannot use 'long' with '__vector'}}
+vector signed long int v_sli;   // nonaix-warning {{Use of 'long' with '__vector' is deprecated}}
+// aix-error@-1 {{cannot use 'long' with '__vector'}}
+vector unsigned long int v_uli; // nonaix-warning {{Use of 'long' with '__vector' is deprecated}}
+// aix-error@-1 {{cannot use 'long' with '__vector'}}
+
 // These should have warnings.
-__vector long vv_l; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
-__vector signed long vv_sl; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
-__vector unsigned long vv_ul;   // expected-warning {{Use of 'long' with 

[clang] 54c1bca - clang/Basic: Stop using SourceManager::getBuffer, NFC

2020-10-14 Thread Duncan P . N . Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-10-14T22:42:56-04:00
New Revision: 54c1bcab90102481fe43b73f8547d47446ba2163

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

LOG: clang/Basic: Stop using SourceManager::getBuffer, NFC

Update clang/lib/Basic to stop relying on a `MemoryBuffer*`, using the
`MemoryBufferRef` from `getBufferOrNone` or `getBufferOrFake` instead of
`getBuffer`.

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

Added: 


Modified: 
clang/include/clang/Basic/SourceManager.h
clang/lib/Basic/Diagnostic.cpp
clang/lib/Basic/SourceLocation.cpp
clang/lib/Basic/SourceManager.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/SourceManager.h 
b/clang/include/clang/Basic/SourceManager.h
index e34fe4577aae..2156a013e53b 100644
--- a/clang/include/clang/Basic/SourceManager.h
+++ b/clang/include/clang/Basic/SourceManager.h
@@ -980,6 +980,17 @@ class SourceManager : public RefCountedBase 
{
 Diag, getFileManager(), Loc);
   }
 
+  /// Return the buffer for the specified FileID.
+  ///
+  /// If there is an error opening this buffer the first time, this
+  /// manufactures a temporary buffer and returns it.
+  llvm::MemoryBufferRef
+  getBufferOrFake(FileID FID, SourceLocation Loc = SourceLocation()) const {
+if (auto B = getBufferOrNone(FID, Loc))
+  return *B;
+return getFakeBufferForRecovery()->getMemBufferRef();
+  }
+
   /// Return the buffer for the specified FileID.
   ///
   /// If there is an error opening this buffer the first time, this

diff  --git a/clang/lib/Basic/Diagnostic.cpp b/clang/lib/Basic/Diagnostic.cpp
index 661eabf9bc7c..ba8c2fb4731d 100644
--- a/clang/lib/Basic/Diagnostic.cpp
+++ b/clang/lib/Basic/Diagnostic.cpp
@@ -265,7 +265,8 @@ void DiagnosticsEngine::DiagStateMap::dump(SourceManager 
,
   PrintedOuterHeading = true;
 
   llvm::errs() << "File " <<  << " : " << SrcMgr.getBuffer(ID)->getBufferIdentifier();
+   << ">: " << 
SrcMgr.getBufferOrFake(ID).getBufferIdentifier();
+
   if (F.second.Parent) {
 std::pair Decomp =
 SrcMgr.getDecomposedIncludedLoc(ID);

diff  --git a/clang/lib/Basic/SourceLocation.cpp 
b/clang/lib/Basic/SourceLocation.cpp
index c1fa406909fe..8cb0899ea39d 100644
--- a/clang/lib/Basic/SourceLocation.cpp
+++ b/clang/lib/Basic/SourceLocation.cpp
@@ -245,7 +245,7 @@ const char *FullSourceLoc::getCharacterData(bool *Invalid) 
const {
 
 StringRef FullSourceLoc::getBufferData(bool *Invalid) const {
   assert(isValid());
-  return SrcMgr->getBuffer(SrcMgr->getFileID(*this), Invalid)->getBuffer();
+  return SrcMgr->getBufferData(SrcMgr->getFileID(*this), Invalid);
 }
 
 std::pair FullSourceLoc::getDecomposedLoc() const {

diff  --git a/clang/lib/Basic/SourceManager.cpp 
b/clang/lib/Basic/SourceManager.cpp
index 1e1915198cd0..61e186e6aa48 100644
--- a/clang/lib/Basic/SourceManager.cpp
+++ b/clang/lib/Basic/SourceManager.cpp
@@ -1228,12 +1228,11 @@ const char 
*SourceManager::getCharacterData(SourceLocation SL,
 /// this is significantly cheaper to compute than the line number.
 unsigned SourceManager::getColumnNumber(FileID FID, unsigned FilePos,
 bool *Invalid) const {
-  bool MyInvalid = false;
-  const llvm::MemoryBuffer *MemBuf = getBuffer(FID, );
+  llvm::Optional MemBuf = getBufferOrNone(FID);
   if (Invalid)
-*Invalid = MyInvalid;
+*Invalid = !MemBuf;
 
-  if (MyInvalid)
+  if (!MemBuf)
 return 1;
 
   // It is okay to request a position just past the end of the buffer.
@@ -1509,7 +1508,10 @@ StringRef SourceManager::getBufferName(SourceLocation 
Loc,
bool *Invalid) const {
   if (isInvalid(Loc, Invalid)) return "";
 
-  return getBuffer(getFileID(Loc), Invalid)->getBufferIdentifier();
+  auto B = getBufferOrNone(getFileID(Loc));
+  if (Invalid)
+*Invalid = !B;
+  return B ? B->getBufferIdentifier() : "";
 }
 
 /// getPresumedLoc - This method returns the "presumed" location of a
@@ -2047,8 +2049,8 @@ bool 
SourceManager::isBeforeInTranslationUnit(SourceLocation LHS,
   // If we arrived here, the location is either in a built-ins buffer or
   // associated with global inline asm. PR5662 and PR22576 are examples.
 
-  StringRef LB = getBuffer(LOffs.first)->getBufferIdentifier();
-  StringRef RB = getBuffer(ROffs.first)->getBufferIdentifier();
+  StringRef LB = getBufferOrFake(LOffs.first).getBufferIdentifier();
+  StringRef RB = getBufferOrFake(ROffs.first).getBufferIdentifier();
   bool LIsBuiltins = LB == "";
   bool RIsBuiltins = RB == "";
   // Sort built-in before non-built-in.



___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[PATCH] D89394: clang/Basic: Stop using SourceManager::getBuffer, NFC

2020-10-14 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG54c1bcab9010: clang/Basic: Stop using 
SourceManager::getBuffer, NFC (authored by dexonsmith).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89394

Files:
  clang/include/clang/Basic/SourceManager.h
  clang/lib/Basic/Diagnostic.cpp
  clang/lib/Basic/SourceLocation.cpp
  clang/lib/Basic/SourceManager.cpp


Index: clang/lib/Basic/SourceManager.cpp
===
--- clang/lib/Basic/SourceManager.cpp
+++ clang/lib/Basic/SourceManager.cpp
@@ -1228,12 +1228,11 @@
 /// this is significantly cheaper to compute than the line number.
 unsigned SourceManager::getColumnNumber(FileID FID, unsigned FilePos,
 bool *Invalid) const {
-  bool MyInvalid = false;
-  const llvm::MemoryBuffer *MemBuf = getBuffer(FID, );
+  llvm::Optional MemBuf = getBufferOrNone(FID);
   if (Invalid)
-*Invalid = MyInvalid;
+*Invalid = !MemBuf;
 
-  if (MyInvalid)
+  if (!MemBuf)
 return 1;
 
   // It is okay to request a position just past the end of the buffer.
@@ -1509,7 +1508,10 @@
bool *Invalid) const {
   if (isInvalid(Loc, Invalid)) return "";
 
-  return getBuffer(getFileID(Loc), Invalid)->getBufferIdentifier();
+  auto B = getBufferOrNone(getFileID(Loc));
+  if (Invalid)
+*Invalid = !B;
+  return B ? B->getBufferIdentifier() : "";
 }
 
 /// getPresumedLoc - This method returns the "presumed" location of a
@@ -2047,8 +2049,8 @@
   // If we arrived here, the location is either in a built-ins buffer or
   // associated with global inline asm. PR5662 and PR22576 are examples.
 
-  StringRef LB = getBuffer(LOffs.first)->getBufferIdentifier();
-  StringRef RB = getBuffer(ROffs.first)->getBufferIdentifier();
+  StringRef LB = getBufferOrFake(LOffs.first).getBufferIdentifier();
+  StringRef RB = getBufferOrFake(ROffs.first).getBufferIdentifier();
   bool LIsBuiltins = LB == "";
   bool RIsBuiltins = RB == "";
   // Sort built-in before non-built-in.
Index: clang/lib/Basic/SourceLocation.cpp
===
--- clang/lib/Basic/SourceLocation.cpp
+++ clang/lib/Basic/SourceLocation.cpp
@@ -245,7 +245,7 @@
 
 StringRef FullSourceLoc::getBufferData(bool *Invalid) const {
   assert(isValid());
-  return SrcMgr->getBuffer(SrcMgr->getFileID(*this), Invalid)->getBuffer();
+  return SrcMgr->getBufferData(SrcMgr->getFileID(*this), Invalid);
 }
 
 std::pair FullSourceLoc::getDecomposedLoc() const {
Index: clang/lib/Basic/Diagnostic.cpp
===
--- clang/lib/Basic/Diagnostic.cpp
+++ clang/lib/Basic/Diagnostic.cpp
@@ -265,7 +265,8 @@
   PrintedOuterHeading = true;
 
   llvm::errs() << "File " <<  << " : " << SrcMgr.getBuffer(ID)->getBufferIdentifier();
+   << ">: " << 
SrcMgr.getBufferOrFake(ID).getBufferIdentifier();
+
   if (F.second.Parent) {
 std::pair Decomp =
 SrcMgr.getDecomposedIncludedLoc(ID);
Index: clang/include/clang/Basic/SourceManager.h
===
--- clang/include/clang/Basic/SourceManager.h
+++ clang/include/clang/Basic/SourceManager.h
@@ -980,6 +980,17 @@
 Diag, getFileManager(), Loc);
   }
 
+  /// Return the buffer for the specified FileID.
+  ///
+  /// If there is an error opening this buffer the first time, this
+  /// manufactures a temporary buffer and returns it.
+  llvm::MemoryBufferRef
+  getBufferOrFake(FileID FID, SourceLocation Loc = SourceLocation()) const {
+if (auto B = getBufferOrNone(FID, Loc))
+  return *B;
+return getFakeBufferForRecovery()->getMemBufferRef();
+  }
+
   /// Return the buffer for the specified FileID.
   ///
   /// If there is an error opening this buffer the first time, this


Index: clang/lib/Basic/SourceManager.cpp
===
--- clang/lib/Basic/SourceManager.cpp
+++ clang/lib/Basic/SourceManager.cpp
@@ -1228,12 +1228,11 @@
 /// this is significantly cheaper to compute than the line number.
 unsigned SourceManager::getColumnNumber(FileID FID, unsigned FilePos,
 bool *Invalid) const {
-  bool MyInvalid = false;
-  const llvm::MemoryBuffer *MemBuf = getBuffer(FID, );
+  llvm::Optional MemBuf = getBufferOrNone(FID);
   if (Invalid)
-*Invalid = MyInvalid;
+*Invalid = !MemBuf;
 
-  if (MyInvalid)
+  if (!MemBuf)
 return 1;
 
   // It is okay to request a position just past the end of the buffer.
@@ -1509,7 +1508,10 @@
bool *Invalid) const {
   if (isInvalid(Loc, Invalid)) return "";
 
-  return getBuffer(getFileID(Loc), Invalid)->getBufferIdentifier();
+  auto B = 

[PATCH] D89441: RFC: Potential fixes to function-instrument=xray-never

2020-10-14 Thread Ian Levesque via Phabricator via cfe-commits
ianlevesque created this revision.
ianlevesque added reviewers: dberris, MaskRay.
Herald added subscribers: llvm-commits, cfe-commits, hiraditya.
Herald added projects: clang, LLVM.
ianlevesque requested review of this revision.

When using https://reviews.llvm.org/D87953 I discovered that the 
function-instrument="xray-never" attribute doesn't actually do anything. The 
only reason [[clang::xray_never_instrument]] ever worked was that the code path 
that parses it coincidentally doesn't set the xray-instruction-threshold 
attribute on annotated functions. Do you think we should fix this by handling 
the xray-never attribute in XRayInstrumentation, or having CodeGenFunction 
remove the threshold if xray-never is set? Or something else? I included both 
possible fixes in this diff. I can code up either one with tests if we agree on 
an approach.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D89441

Files:
  clang/lib/CodeGen/CodeGenFunction.cpp
  llvm/lib/CodeGen/XRayInstrumentation.cpp


Index: llvm/lib/CodeGen/XRayInstrumentation.cpp
===
--- llvm/lib/CodeGen/XRayInstrumentation.cpp
+++ llvm/lib/CodeGen/XRayInstrumentation.cpp
@@ -145,6 +145,10 @@
 bool XRayInstrumentation::runOnMachineFunction(MachineFunction ) {
   auto  = MF.getFunction();
   auto InstrAttr = F.getFnAttribute("function-instrument");
+  bool NeverInstrument = InstrAttr.isStringAttribute() &&
+ InstrAttr.getValueAsString() == "xray-never";
+  if (NeverInstrument)
+return false;
   bool AlwaysInstrument = InstrAttr.isStringAttribute() &&
   InstrAttr.getValueAsString() == "xray-always";
   auto ThresholdAttr = F.getFnAttribute("xray-instruction-threshold");
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -817,8 +817,10 @@
   CurFn->getName().bytes_begin(), CurFn->getName().bytes_end());
   auto Group = crc32(FuncName) % FuncGroups;
   if (Group != CGM.getCodeGenOpts().XRaySelectedFunctionGroup &&
-  !AlwaysXRayAttr)
+  !AlwaysXRayAttr) {
+Fn->removeFnAttr("xray-instruction-threshold");
 Fn->addFnAttr("function-instrument", "xray-never");
+  }
 }
   }
 


Index: llvm/lib/CodeGen/XRayInstrumentation.cpp
===
--- llvm/lib/CodeGen/XRayInstrumentation.cpp
+++ llvm/lib/CodeGen/XRayInstrumentation.cpp
@@ -145,6 +145,10 @@
 bool XRayInstrumentation::runOnMachineFunction(MachineFunction ) {
   auto  = MF.getFunction();
   auto InstrAttr = F.getFnAttribute("function-instrument");
+  bool NeverInstrument = InstrAttr.isStringAttribute() &&
+ InstrAttr.getValueAsString() == "xray-never";
+  if (NeverInstrument)
+return false;
   bool AlwaysInstrument = InstrAttr.isStringAttribute() &&
   InstrAttr.getValueAsString() == "xray-always";
   auto ThresholdAttr = F.getFnAttribute("xray-instruction-threshold");
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -817,8 +817,10 @@
   CurFn->getName().bytes_begin(), CurFn->getName().bytes_end());
   auto Group = crc32(FuncName) % FuncGroups;
   if (Group != CGM.getCodeGenOpts().XRaySelectedFunctionGroup &&
-  !AlwaysXRayAttr)
+  !AlwaysXRayAttr) {
+Fn->removeFnAttr("xray-instruction-threshold");
 Fn->addFnAttr("function-instrument", "xray-never");
+  }
 }
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D89366: [WebAssembly] v128.load{8, 16, 32, 64}_lane instructions

2020-10-14 Thread Thomas Lively via Phabricator via cfe-commits
tlively added inline comments.



Comment at: clang/include/clang/Basic/BuiltinsWebAssembly.def:180
+TARGET_BUILTIN(__builtin_wasm_load32_lane, "V4iIii*", "nU", "simd128")
+TARGET_BUILTIN(__builtin_wasm_load64_lane, "V2LLiIiLLi*", "nU", "simd128")
+TARGET_BUILTIN(__builtin_wasm_store8_lane, "vV16ScIiSc*", "n", "simd128")

aheejin wrote:
> tlively wrote:
> > aheejin wrote:
> > > `U` in the third argument [[ 
> > > https://github.com/llvm/llvm-project/blob/72732acade77d5ee55a818e2da77a2c5b7033ccb/clang/include/clang/Basic/Builtins.def#L75
> > >  | means ]] pure. Can we say loads are pure? (The same for existing 
> > > `__builtin_wasm_load32_zero` and `__builtin_wasm_load64_zero`)
> > Yes, this is the difference between "pure" and "const." 
> > 
> > https://github.com/llvm/llvm-project/blob/master/clang/include/clang/Basic/Builtins.h#L97-L106
> Can't SIMD loads trap? (Normal loads can AFAIK, right?)
Hmm yes, good point. I suppose that counts as a side effect so neither these 
nor the load_zero builtins should be pure?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89366

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


[PATCH] D87565: [Sema] Improve const_cast conformance to N4261

2020-10-14 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/lib/Sema/SemaCast.cpp:1817-1819
+  NeedToMaterializeTemporary =
+  SrcType->isRecordType() || SrcType->isArrayType() ||
+  SrcType->isFunctionPointerType() || SrcType->isMemberPointerType();

It looks like GCC allowing a cast from `T*` to `T*&&` is just a bug in their 
implementation. Consider:

```
using T = int*;
T & = const_cast(T{}); // GCC accepts
T & = const_cast(T()); // GCC rejects
```

... and the same behavior seems to show up for all scalar types: they permit 
`const_cast` from `T{}` but not from `T()` when `T` is `int`, `int*`,  This 
doesn't seem like good behavior to follow. I think we should either implement 
the current direction of 1965 (that is, only allow classes and arrays here) or 
leave the current behavior (following the standard as-is) alone.


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

https://reviews.llvm.org/D87565

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


[PATCH] D84362: [NFC] Refactor DiagnosticBuilder and PartialDiagnostic

2020-10-14 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Thanks, this looks a lot better.




Comment at: clang/include/clang/Basic/Diagnostic.h:1065
+///
+class StreamableDiagnosticBase {
+public:

I think I would prefer `StreamingDiagnostic` as the class name here.



Comment at: clang/include/clang/Basic/PartialDiagnostic.h:66
+return *this;
+  }
+

Why are these template operators necessary?  The LHS of the `<<` should convert 
to a base reference type just fine.


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

https://reviews.llvm.org/D84362

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


[PATCH] D89366: [WebAssembly] v128.load{8, 16, 32, 64}_lane instructions

2020-10-14 Thread Thomas Lively via Phabricator via cfe-commits
tlively added a comment.

In D89366#2331154 , @aheejin wrote:

> Do loads need the vector argument? The proposal has that but I'm wondering 
> why... Can that possibly be an error from the author's side?

Oops, I meant to answer that before but I did not. This is not a mistake 
because the purpose of the load_lane instructions is to replace just one lane 
of a vector. The vector to be be modified needs to be taken as an argument.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89366

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


[clang] f7f2e42 - PR47805: Use a single object for a function parameter in the caller and

2020-10-14 Thread Richard Smith via cfe-commits

Author: Richard Smith
Date: 2020-10-14T17:43:51-07:00
New Revision: f7f2e4261a98b2da519d58e7f6794b013cda7a4b

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

LOG: PR47805: Use a single object for a function parameter in the caller and
callee in constant evaluation.

We previously made a deep copy of function parameters of class type when
passing them, resulting in the destructor for the parameter applying to
the original argument value, ignoring any modifications made in the
function body. This also meant that the 'this' pointer of the function
parameter could be observed changing between the caller and the callee.

This change completely reimplements how we model function parameters
during constant evaluation. We now model them roughly as if they were
variables living in the caller, albeit with an artificially reduced
scope that covers only the duration of the function call, instead of
modeling them as temporaries in the caller that we partially "reparent"
into the callee at the point of the call. This brings some minor
diagnostic improvements, as well as significantly reduced stack usage
during constant evaluation.

Added: 


Modified: 
clang/lib/AST/ExprConstant.cpp
clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p6.cpp
clang/test/CXX/except/except.spec/p1.cpp
clang/test/CXX/expr/expr.const/p2-0x.cpp
clang/test/OpenMP/critical_messages.cpp
clang/test/OpenMP/distribute_parallel_for_simd_safelen_messages.cpp
clang/test/OpenMP/distribute_simd_safelen_messages.cpp
clang/test/OpenMP/distribute_simd_simdlen_messages.cpp

clang/test/OpenMP/target_teams_distribute_parallel_for_simd_safelen_messages.cpp

clang/test/OpenMP/target_teams_distribute_parallel_for_simd_simdlen_messages.cpp
clang/test/OpenMP/target_teams_distribute_simd_safelen_messages.cpp
clang/test/OpenMP/target_teams_distribute_simd_simdlen_messages.cpp
clang/test/OpenMP/teams_distribute_parallel_for_simd_safelen_messages.cpp
clang/test/OpenMP/teams_distribute_parallel_for_simd_simdlen_messages.cpp
clang/test/OpenMP/teams_distribute_simd_safelen_messages.cpp
clang/test/OpenMP/teams_distribute_simd_simdlen_messages.cpp
clang/test/Sema/builtin-expect-with-probability-avr.cpp
clang/test/Sema/builtin-expect-with-probability.cpp
clang/test/Sema/c89.c
clang/test/SemaCUDA/constexpr-variables.cu
clang/test/SemaCXX/c99-variable-length-array-cxx11.cpp
clang/test/SemaCXX/c99-variable-length-array.cpp
clang/test/SemaCXX/constant-expression-cxx11.cpp
clang/test/SemaCXX/constant-expression-cxx2a.cpp
clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp
clang/test/SemaCXX/cxx2a-consteval.cpp
clang/test/SemaCXX/integer-overflow.cpp
clang/test/SemaCXX/vla-construct.cpp
clang/test/SemaCXX/warn-vla.cpp

Removed: 




diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 1327aa6876e4..20eb9f77ca52 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -490,6 +490,39 @@ namespace {
 }
   };
 
+  /// A scope at the end of which an object can need to be destroyed.
+  enum class ScopeKind {
+Block,
+FullExpression,
+Call
+  };
+
+  /// A reference to a particular call and its arguments.
+  struct CallRef {
+CallRef() : OrigCallee(), CallIndex(0), Version() {}
+CallRef(const FunctionDecl *Callee, unsigned CallIndex, unsigned Version)
+: OrigCallee(Callee), CallIndex(CallIndex), Version(Version) {}
+
+explicit operator bool() const { return OrigCallee; }
+
+/// Get the parameter that the caller initialized, corresponding to the
+/// given parameter in the callee.
+const ParmVarDecl *getOrigParam(const ParmVarDecl *PVD) const {
+  return OrigCallee ? 
OrigCallee->getParamDecl(PVD->getFunctionScopeIndex())
+: PVD;
+}
+
+/// The callee at the point where the arguments were evaluated. This might
+/// be 
diff erent from the actual callee (a 
diff erent redeclaration, or a
+/// virtual override), but this function's parameters are the ones that
+/// appear in the parameter map.
+const FunctionDecl *OrigCallee;
+/// The call index of the frame that holds the argument values.
+unsigned CallIndex;
+/// The version of the parameters corresponding to this call.
+unsigned Version;
+  };
+
   /// A stack frame in the constexpr call stack.
   class CallStackFrame : public interp::Frame {
   public:
@@ -504,9 +537,10 @@ namespace {
 /// This - The binding for the this pointer in this call, if any.
 const LValue *This;
 
-/// Arguments - Parameter bindings for this function call, indexed by
-/// parameters' function scope indices.
-APValue 

[PATCH] D63640: [clang] Improve Serialization/Imporing of APValues

2020-10-14 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

Reverse ping: I have a patch implementing class type non-type template 
parameters that's blocked on this landing. If you won't have time to address 
@martong's comments soon, do you mind if I take this over and land it?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63640

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


[PATCH] D89212: PR47663: Warn if an entity becomes weak after its first use.

2020-10-14 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith updated this revision to Diff 298268.
rsmith marked 3 inline comments as done.
rsmith added a comment.

- Addressing review feedback from @aaron.ballman.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89212

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/AST/DeclBase.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/Sema/attr-weak.c
  clang/test/Sema/init.c

Index: clang/test/Sema/init.c
===
--- clang/test/Sema/init.c
+++ clang/test/Sema/init.c
@@ -155,7 +155,7 @@
 int PR4386_a = ((void *) PR4386_bar) != 0;
 int PR4386_b = ((void *) PR4386_foo) != 0; // expected-error{{initializer element is not a compile-time constant}}
 int PR4386_c = ((void *) PR4386_zed) != 0;
-int PR4386_zed() __attribute((weak));
+int PR4386_zed() __attribute((weak)); // expected-warning{{'PR4386_zed' declared weak after its first use}} expected-note {{attribute}}
 
 //  (derived from SPEC vortex benchmark)
 typedef char strty[10];
Index: clang/test/Sema/attr-weak.c
===
--- clang/test/Sema/attr-weak.c
+++ clang/test/Sema/attr-weak.c
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -verify -fsyntax-only %s
+// RUN: %clang_cc1 -verify -fsyntax-only %s -triple x86_64-unknown-macosx10.3.0 -DMACOS
+// RUN: %clang_cc1 -verify -fsyntax-only %s -triple x86_64-linux-gnu -DLINUX
 
 extern int f0() __attribute__((weak));
 extern int g0 __attribute__((weak));
@@ -25,3 +26,55 @@
 
 static void pr14946_f();
 void pr14946_f() __attribute__((weak)); // expected-error {{weak declaration cannot have internal linkage}}
+
+void some_function();
+
+void pr47663_a();
+void pr47663_b();
+static void pr47663_c();
+void pr47663_d();
+void pr47663_e(); // expected-warning {{declared weak after its first use}}
+void pr47663_f(); // expected-note {{possible target}}
+void pr47663_g();
+int pr47663_h;
+void pr47663_z() __attribute__((weak));
+void use() {
+  int arr_a[_a ? 1 : -1];
+  int arr_b[_b ? 1 : -1];
+  int arr_c[_c ? 1 : -1];
+  int arr_d[_d ? 1 : -1];
+  int arr_e[_e ? 1 : -1];
+  int arr_f[_f ? 1 : -1];
+  int arr_g[_g ? 1 : -1];
+  int arr_h[_h ? 1 : -1]; // expected-warning {{will always evaluate to 'true'}}
+  int arr_z[_z ? -1 : 1];
+}
+void pr47663_a() __attribute__((weak)); // expected-warning {{declared weak after its first use}} expected-note {{'weak' attribute here}}
+void pr47663_b() __attribute__((weak_import)); // expected-warning {{declared weak after its first use}} expected-note {{'weak_import' attribute here}}
+#ifdef LINUX
+static void pr47663_c() __attribute__((weakref, alias("might_not_exist"))); // expected-warning {{declared weak after its first use}} expected-note {{'weakref' attribute here}}
+#endif
+#ifdef MACOS
+void pr47663_d() __attribute__((availability(macos, introduced=10.4))); // expected-warning {{declared weak after its first use}} expected-note {{'availability' attribute here}}
+#endif
+#pragma weak pr47663_e // expected-note {{pragma 'weak' here}}
+
+// FIXME: This should warn; see PR47796. But it actually creates a bogus
+// overload set. When this is fixed, ensure we produce the 'declared weak after
+// its first use' warning.
+#pragma weak pr47663_f = some_function // expected-note {{possible target}}
+void q() { pr47663_f; } // expected-error {{overloaded}}
+
+#pragma clang attribute push (__attribute__((weak)), apply_to = function) // expected-note {{'weak' attribute here}}
+void pr47663_g(); // expected-warning {{declared weak after its first use}}
+#pragma clang attribute pop
+extern int pr47663_h __attribute__((weak)); // expected-warning {{declared weak after its first use}} expected-note {{'weak' attribute here}}
+void pr47663_z() __attribute__((weak_import));
+
+// 'weak' on a definition means something different from 'weak' on a
+// declaration. Don't warn in that case.
+void weak_def_after_use();
+extern int weak_def_after_use_v;
+void use_wdau() { weak_def_after_use(); weak_def_after_use_v = 0; }
+__attribute__((weak)) void weak_def_after_use() {}
+__attribute__((weak)) int weak_def_after_use_v;
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -8154,6 +8154,9 @@
   W.setUsed(true);
   if (W.getAlias()) { // clone decl, impersonate __attribute(weak,alias(...))
 IdentifierInfo *NDId = ND->getIdentifier();
+// FIXME (PR47796): Check for a previous declaration with the target name
+// here, and build a redeclaration of it. Check whether the previous
+// declaration is used and warn if so.
 NamedDecl *NewD = DeclClonePragmaWeak(ND, W.getAlias(), W.getLocation());
 NewD->addAttr(
 AliasAttr::CreateImplicit(Context, NDId->getName(), W.getLocation()));

[PATCH] D89212: PR47663: Warn if an entity becomes weak after its first use.

2020-10-14 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith marked an inline comment as done.
rsmith added inline comments.



Comment at: clang/lib/Sema/SemaDecl.cpp:6435-6436
+Attr *WeakA = nullptr;
+for (Attr *A : VD->getAttrs()) {
+  if (!isa(A))
+continue;

aaron.ballman wrote:
> Ah, it's too bad that `Decl::specific_attrs()` doesn't accept a pack of 
> attributes...
I took a brief look at fixing that, but it's not a completely natural extension 
because we would want to use a different `value_type` for the iterator if 
there's more than one kind under consideration. Probably not worth it for only 
one user.



Comment at: clang/lib/Sema/SemaDecl.cpp:18288
 
-  if (PrevDecl) {
-PrevDecl->addAttr(WeakAttr::CreateImplicit(Context, PragmaLoc, 
AttributeCommonInfo::AS_Pragma));
+  if (NamedDecl *PrevDecl =
+  LookupSingleName(TUScope, Name, NameLoc, LookupOrdinaryName)) {

aaron.ballman wrote:
> Same request for `const` here as above.
Can't make this `const`; this function modifies the declaration by adding an 
attribute :) But I can make `VD` below const.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89212

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


[PATCH] D85802: [clang] Add -fc++-abi= flag for specifying which C++ ABI to use

2020-10-14 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan added a comment.

In D85802#2331290 , @rnk wrote:

> I'd like to point out that we used to have a very similar flag, but we 
> removed it back in 2014: http://reviews.llvm.org/D2545
>
> Are you sure you need all the flexibility that this flag allows? For example, 
> this will let users ask for the MSVC C++ ABI on Linux. I really don't want to 
> support the mips, wasm, microsoft, or ios C++ ABI on arbitrary targets, and I 
> don't want to have to teach clang to diagnose all the unsupported ways users 
> can use this flag. The smaller we can make the space of options, the better, 
> and the less conditional soup we'll have in the future.

Yeah I see how this can lead to a lot of complexity. Perhaps we can add some 
mechanism in Clang that determines which ABIs are supported for specific 
platforms? That is, when targetting Linux, Clang will diagnose an error if 
using `-fc++-abi=microsoft`. This could cover the case where a specific 
platform can support multiple ABIs, but those ABIs won't be supported by other 
platforms.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85802

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


[PATCH] D89318: [ASTImporter] Fix crash caused by unset AttributeSpellingListIndex

2020-10-14 Thread Dave Lee via Phabricator via cfe-commits
kastiglione added a comment.

Reverted here: 4cb4db11ee1323c5d4bf66d21deb046970f4e516 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89318

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


[clang] 4cb4db1 - Revert "[ASTImporter] Fix crash caused by unset AttributeSpellingListIndex"

2020-10-14 Thread Dave Lee via cfe-commits

Author: Dave Lee
Date: 2020-10-14T17:21:56-07:00
New Revision: 4cb4db11ee1323c5d4bf66d21deb046970f4e516

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

LOG: Revert "[ASTImporter] Fix crash caused by unset AttributeSpellingListIndex"

This broke the GreenDragon build, due to the following error while running
TestImportBuiltinFileID:

```
Ignored/unknown shouldn't get here
UNREACHABLE executed at 
tools/clang/include/clang/Sema/AttrSpellingListIndex.inc:13!
```

See http://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/24213/

This reverts commit 73c6beb2f7053fe8b5150072c2b5cd930de38a22.
This reverts https://reviews.llvm.org/D89318

Added: 


Modified: 
clang/lib/AST/ASTImporter.cpp
clang/unittests/AST/ASTImporterTest.cpp

Removed: 
clang/test/ASTMerge/attr/Inputs/RestrictAttr.cpp
clang/test/ASTMerge/attr/testRestrictAttr.cpp



diff  --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index a5c3a5eadb48..9efbcf757e99 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -8094,6 +8094,9 @@ Expected ASTImporter::Import(const Attr 
*FromAttr) {
   else
 return ToTOrErr.takeError();
 }
+To->setInherited(From->isInherited());
+To->setPackExpansion(From->isPackExpansion());
+To->setImplicit(From->isImplicit());
 ToAttr = To;
 break;
   }
@@ -8103,6 +8106,7 @@ Expected ASTImporter::Import(const Attr 
*FromAttr) {
 IdentifierInfo *ToAttrType = Import(From->getType());
 To = FormatAttr::Create(ToContext, ToAttrType, From->getFormatIdx(),
 From->getFirstArg(), ToRange, From->getSyntax());
+To->setInherited(From->isInherited());
 ToAttr = To;
 break;
   }
@@ -8113,15 +8117,8 @@ Expected ASTImporter::Import(const Attr 
*FromAttr) {
 ToAttr->setRange(ToRange);
 break;
   }
-
   assert(ToAttr && "Attribute should be created.");
-  if (const auto *InheritableFromAttr = dyn_cast(FromAttr))
-cast(ToAttr)->setInherited(
-InheritableFromAttr->isInherited());
-  ToAttr->setAttributeSpellingListIndex(
-  FromAttr->getAttributeSpellingListIndex());
-  ToAttr->setPackExpansion(FromAttr->isPackExpansion());
-  ToAttr->setImplicit(FromAttr->isImplicit());
+  
   return ToAttr;
 }
 

diff  --git a/clang/test/ASTMerge/attr/Inputs/RestrictAttr.cpp 
b/clang/test/ASTMerge/attr/Inputs/RestrictAttr.cpp
deleted file mode 100644
index 2055a23b7c3c..
--- a/clang/test/ASTMerge/attr/Inputs/RestrictAttr.cpp
+++ /dev/null
@@ -1 +0,0 @@
-void *foo(unsigned, unsigned) __attribute__((__malloc__));

diff  --git a/clang/test/ASTMerge/attr/testRestrictAttr.cpp 
b/clang/test/ASTMerge/attr/testRestrictAttr.cpp
deleted file mode 100644
index 65903d8f66ca..
--- a/clang/test/ASTMerge/attr/testRestrictAttr.cpp
+++ /dev/null
@@ -1,2 +0,0 @@
-// RUN: %clang -x c++-header -o %t.a.ast %S/Inputs/RestrictAttr.cpp
-// RUN: %clang_cc1 -x c++ -ast-merge %t.a.ast /dev/null -ast-dump

diff  --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittests/AST/ASTImporterTest.cpp
index 209374dd7048..967dc035d11f 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -5767,35 +5767,11 @@ TEST_P(ASTImporterOptionSpecificTestBase, 
ImportExprOfAlignmentAttr) {
   EXPECT_TRUE(ToA);
 }
 
-TEST_P(ASTImporterOptionSpecificTestBase, ImportRestrictAttr) {
-  Decl *FromTU = getTuDecl(
-  R"(
-  void *foo(unsigned, unsigned) __attribute__((__malloc__));
-  )",
-  Lang_CXX03, "input.cc");
-  auto *FromD = FirstDeclMatcher().match(
-  FromTU, functionDecl(hasName("foo")));
-  ASSERT_TRUE(FromD);
-
-  auto *ToD = Import(FromD, Lang_CXX03);
-  ASSERT_TRUE(ToD);
-  ToD->dump(); // Should not crash!
-
-  auto *FromAttr = FromD->getAttr();
-  auto *ToAttr = ToD->getAttr();
-  EXPECT_EQ(FromAttr->isInherited(), ToAttr->isInherited());
-  EXPECT_EQ(FromAttr->isPackExpansion(), ToAttr->isPackExpansion());
-  EXPECT_EQ(FromAttr->isImplicit(), ToAttr->isImplicit());
-  EXPECT_EQ(FromAttr->getSyntax(), ToAttr->getSyntax());
-  EXPECT_EQ(FromAttr->getAttributeSpellingListIndex(),
-ToAttr->getAttributeSpellingListIndex());
-}
-
 TEST_P(ASTImporterOptionSpecificTestBase, ImportFormatAttr) {
   Decl *FromTU = getTuDecl(
   R"(
   int foo(const char * fmt, ...)
-  __attribute__ ((__format__ (__scanf__, 1, 2)));
+  __attribute__ ((__format__ (__scanf__, 1, 2)));
   )",
   Lang_CXX03, "input.cc");
   auto *FromD = FirstDeclMatcher().match(
@@ -5816,7 +5792,6 @@ TEST_P(ASTImporterOptionSpecificTestBase, 
ImportFormatAttr) {
 ToAttr->getAttributeSpellingListIndex());
   EXPECT_EQ(FromAttr->getType()->getName(), ToAttr->getType()->getName());
 }
-
 template 
 auto 

[PATCH] D89276: Support ObjC in IncludeInserter

2020-10-14 Thread Joe Turner via Phabricator via cfe-commits
compositeprimes updated this revision to Diff 298264.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89276

Files:
  clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp
  clang-tools-extra/clang-tidy/utils/IncludeSorter.h
  clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp
@@ -28,8 +28,10 @@
 
 class IncludeInserterCheckBase : public ClangTidyCheck {
 public:
-  IncludeInserterCheckBase(StringRef CheckName, ClangTidyContext *Context)
-  : ClangTidyCheck(CheckName, Context) {}
+  IncludeInserterCheckBase(StringRef CheckName, ClangTidyContext *Context,
+   utils::IncludeSorter::IncludeStyle Style =
+   utils::IncludeSorter::IS_Google)
+  : ClangTidyCheck(CheckName, Context), Inserter(Style) {}
 
   void registerPPCallbacks(const SourceManager , Preprocessor *PP,
Preprocessor *ModuleExpanderPP) override {
@@ -50,7 +52,7 @@
 
   virtual std::vector headersToInclude() const = 0;
 
-  utils::IncludeInserter Inserter{utils::IncludeSorter::IS_Google};
+  utils::IncludeInserter Inserter;
 };
 
 class NonSystemHeaderInserterCheck : public IncludeInserterCheckBase {
@@ -111,6 +113,42 @@
   }
 };
 
+class ObjCEarlyInAlphabetHeaderInserterCheck : public IncludeInserterCheckBase {
+public:
+  ObjCEarlyInAlphabetHeaderInserterCheck(StringRef CheckName,
+ ClangTidyContext *Context)
+  : IncludeInserterCheckBase(CheckName, Context,
+ utils::IncludeSorter::IS_Google_ObjC) {}
+
+  std::vector headersToInclude() const override {
+return {"a/header.h"};
+  }
+};
+
+class ObjCCategoryHeaderInserterCheck : public IncludeInserterCheckBase {
+public:
+  ObjCCategoryHeaderInserterCheck(StringRef CheckName,
+  ClangTidyContext *Context)
+  : IncludeInserterCheckBase(CheckName, Context,
+ utils::IncludeSorter::IS_Google_ObjC) {}
+
+  std::vector headersToInclude() const override {
+return {"clang_tidy/tests/insert_includes_test_header+foo.h"};
+  }
+};
+
+class ObjCGeneratedHeaderInserterCheck : public IncludeInserterCheckBase {
+public:
+  ObjCGeneratedHeaderInserterCheck(StringRef CheckName,
+   ClangTidyContext *Context)
+  : IncludeInserterCheckBase(CheckName, Context,
+ utils::IncludeSorter::IS_Google_ObjC) {}
+
+  std::vector headersToInclude() const override {
+return {"clang_tidy/tests/generated_file.proto.h"};
+  }
+};
+
 template 
 std::string runCheckOnCode(StringRef Code, StringRef Filename) {
   std::vector Errors;
@@ -120,12 +158,20 @@
   {"clang_tidy/tests/"
"insert_includes_test_header.h",
"\n"},
+  // ObjC category.
+  {"clang_tidy/tests/"
+   "insert_includes_test_header+foo.h",
+   "\n"},
   // Non system headers
   {"a/header.h", "\n"},
   {"path/to/a/header.h", "\n"},
   {"path/to/z/header.h", "\n"},
   {"path/to/header.h", "\n"},
   {"path/to/header2.h", "\n"},
+  // Generated headers
+  {"clang_tidy/tests/"
+   "generated_file.proto.h",
+   "\n"},
   // Fake system headers.
   {"stdlib.h", "\n"},
   {"unistd.h", "\n"},
@@ -160,9 +206,9 @@
   int a = 0;
 })";
 
-  EXPECT_EQ(PostCode, runCheckOnCode(
-  PreCode, "clang_tidy/tests/"
-   "insert_includes_test_input2.cc"));
+  EXPECT_EQ(PostCode,
+runCheckOnCode(
+PreCode, "clang_tidy/tests/insert_includes_test_input2.cc"));
 }
 
 TEST(IncludeInserterTest, InsertMultipleIncludesAndDeduplicate) {
@@ -191,9 +237,9 @@
   int a = 0;
 })";
 
-  EXPECT_EQ(PostCode, runCheckOnCode(
-  PreCode, "clang_tidy/tests/"
-   "insert_includes_test_input2.cc"));
+  EXPECT_EQ(PostCode,
+runCheckOnCode(
+PreCode, 

[PATCH] D88498: [FPEnv] Evaluate initializers in constant rounding mode

2020-10-14 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith requested changes to this revision.
rsmith added a comment.
This revision now requires changes to proceed.

In D88498#2329845 , @sepavloff wrote:

> - Reverted check to the previous version, in which it applied to C++ file 
> level variables also.

This presumably reintroduces the misbehavior for

  double d;
  double e = (fesetround(...), d = some calculation, fesetround(...default...), 
d);

in which `some calculation` will be treated as being in the default rounding 
mode, right?

> - Added workaround for constexpr functions. Now they are parsed with constant 
> rounding mode, which allows to use them with option `-frounding-math`.

This is inappropriate. When a `constexpr` function is invoked at runtime, it 
should behave exactly like any other function. Marking a function as 
`constexpr` should not cause it to round differently when used outside of 
constant expressions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88498

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


[PATCH] D89212: PR47663: Warn if an entity becomes weak after its first use.

2020-10-14 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

In D89212#2326771 , @rjmccall wrote:

> Patch looks good to me.  I think we're running some internal tests; do you 
> want to wait for those?

More testing and validation would be nice; I don't think this patch is urgent 
so I'm happy to wait.

In my internal testing, I found one more false positive: the protocol buffer 
compiler's support for weak imports results in code like this:

  // generated .h file
  extern T foo;
  inline T *get() { return  }



  // generated .cc file
  __attribute__((weak)) extern T foo;
  // more uses of foo

This is intentional: the idea is that if someone includes the `.h` file and 
invokes the inline function, they get a strong link-time dependency on the 
symbol `foo` and need to link against that proto library. But if not, then 
there is no such dependency, and the library is optional. However, this 
functionality of the protocol buffer compiler is deprecated and being phased 
out (and suppressing the warning in this one case should be straightforward) so 
I'm not worried about it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89212

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


[PATCH] D89360: Treat constant contexts as being in the default rounding mode.

2020-10-14 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/test/SemaCXX/rounding-math.cpp:9
+
+constexpr int f(int n) { return int(n * (1.0 / 3.0)); }
+

rsmith wrote:
> sepavloff wrote:
> > This code requires additional solution. The function body is built using 
> > dynamic rounding mode, which breaks its constexprness. We can avoid this 
> > kind of errors if we assume that body of a constexpr function is parsed 
> > using constant rounding mode (in this example it is the default mode). It 
> > makes parsing constexpr function different from non-constexpr ones, but 
> > enables convenient use:
> > ```
> > constexpr int add(float x, float y) { return x + y; }
> > 
> > #pragma STDC FENV_ROUND FE_UPWARD
> > int a2 = add(2.0F, 0x1.02p0F);
> > 
> > #pragma STDC FENV_ROUND FE_DOWNWARD
> > int a3 = add(2.0F, 0x1.02p0F);
> > ```
> > If calls of constexpr functions are processes with FP options acting in the 
> > call site, a call to constexpr function becomes equivalent to execution of 
> > statements of its body.
> I don't understand what you mean by "breaks its constexprness". Using a 
> dynamic rounding mode for the body of the function is exactly what we want 
> here. When the function is called in a manifestly constant evaluated context, 
> we should use the default rounding mode, and when it's called at runtime, we 
> use the appropriate dynamic rounding mode; if we try to constant evaluate it 
> outside of a manifestly constant evaluated constant, we deem it non-constant.
> 
> When `constexpr` function is called at runtime, it's a completely normal 
> function with normal semantics. It would be wrong to use the default rounding 
> mode when parsing its body.
To be clear: in your example with `add`, both `a2` and `a3` should be 
initialized to the same value, which should be rounded with the default 
rounding mode. Per ISO18661, `FENV_ROUND` only affects operations in its 
lexical scope, not functions called within those operations, and per the 
regular C++ rules, `constexpr` functions behave like regular functions, not 
like macros.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89360

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


[PATCH] D89318: [ASTImporter] Fix crash caused by unset AttributeSpellingListIndex

2020-10-14 Thread Dave Lee via Phabricator via cfe-commits
kastiglione added a comment.

@martong here's a partial backtrace:

  3: LLDB`llvm::llvm_unreachable_internal(char const*, char const*, unsigned 
int)
  4: LLDB`clang::AttributeCommonInfo::calculateAttributeSpellingListIndex() 
const
  5: LLDB`clang::ASTImporter::Import(clang::Attr const*)
  6: LLDB`llvm::Expected 
clang::ASTNodeImporter::import(clang::Attr*)
  7: LLDB`clang::ASTNodeImporter::InitializeImportedDecl(clang::Decl*, 
clang::Decl*)
  8: LLDB`bool 
clang::ASTNodeImporter::GetImportedOrCreateSpecialDecl, 
clang::FunctionDecl, clang::ASTContext&, clang::DeclContext*&, 
clang::SourceLocation&, clang::DeclarationNameInfo&, clang::QualType&, 
clang::TypeSourceInfo*&, clang::StorageClass, bool, bool, 
clang::ConstexprSpecKind, clang::Expr*&>(clang::FunctionDecl*&, 
clang::ASTNodeImporter::CallOverloadedCreateFun, 
clang::FunctionDecl*, clang::ASTContext&, clang::DeclContext*&, 
clang::SourceLocation&, clang::DeclarationNameInfo&, clang::QualType&, 
clang::TypeSourceInfo*&, clang::StorageClass&&, bool&&, bool&&, 
clang::ConstexprSpecKind&&, clang::Expr*&)
  9: LLDB`clang::ASTNodeImporter::VisitFunctionDecl(clang::FunctionDecl*)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89318

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


[clang] 8b6d1c0 - [ADT] Use alignas + sizeof for inline storage, NFC

2020-10-14 Thread Reid Kleckner via cfe-commits

Author: Reid Kleckner
Date: 2020-10-14T16:16:02-07:00
New Revision: 8b6d1c0467b2dfa14cb2d2dec7637bf95c78364b

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

LOG: [ADT] Use alignas + sizeof for inline storage, NFC

AlignedCharArrayUnion is really only needed to handle the "union" case
when we need memory of suitable size and alignment for multiple types.
SmallVector only needs storage for one type, so use that directly.

Added: 


Modified: 
clang/include/clang/AST/APValue.h
llvm/include/llvm/ADT/SmallVector.h
llvm/include/llvm/ADT/iterator_range.h

Removed: 




diff  --git a/clang/include/clang/AST/APValue.h 
b/clang/include/clang/AST/APValue.h
index ac8ed0818af0..5eb1f68f7690 100644
--- a/clang/include/clang/AST/APValue.h
+++ b/clang/include/clang/AST/APValue.h
@@ -17,9 +17,10 @@
 #include "llvm/ADT/APFixedPoint.h"
 #include "llvm/ADT/APFloat.h"
 #include "llvm/ADT/APSInt.h"
+#include "llvm/ADT/FoldingSet.h"
 #include "llvm/ADT/PointerIntPair.h"
 #include "llvm/ADT/PointerUnion.h"
-#include "llvm/ADT/FoldingSet.h"
+#include "llvm/Support/AlignOf.h"
 
 namespace clang {
   class AddrLabelExpr;

diff  --git a/llvm/include/llvm/ADT/SmallVector.h 
b/llvm/include/llvm/ADT/SmallVector.h
index c3c6a366dab2..dd5cd9531ded 100644
--- a/llvm/include/llvm/ADT/SmallVector.h
+++ b/llvm/include/llvm/ADT/SmallVector.h
@@ -14,7 +14,6 @@
 #define LLVM_ADT_SMALLVECTOR_H
 
 #include "llvm/ADT/iterator_range.h"
-#include "llvm/Support/AlignOf.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/MathExtras.h"
@@ -97,8 +96,9 @@ using SmallVectorSizeType =
 
 /// Figure out the offset of the first element.
 template  struct SmallVectorAlignmentAndSize {
-  AlignedCharArrayUnion>> Base;
-  AlignedCharArrayUnion FirstEl;
+  alignas(SmallVectorBase>) char Base[sizeof(
+  SmallVectorBase>)];
+  alignas(T) char FirstEl[sizeof(T)];
 };
 
 /// This is the part of SmallVectorTemplateBase which does not depend on 
whether
@@ -870,13 +870,13 @@ SmallVectorImpl 
::operator=(SmallVectorImpl &) {
 /// to avoid allocating unnecessary storage.
 template 
 struct SmallVectorStorage {
-  AlignedCharArrayUnion InlineElts[N];
+  alignas(T) char InlineElts[N * sizeof(T)];
 };
 
 /// We need the storage to be properly aligned even for small-size of 0 so that
 /// the pointer math in \a SmallVectorTemplateCommon::getFirstEl() is
 /// well-defined.
-template  struct alignas(alignof(T)) SmallVectorStorage {};
+template  struct alignas(T) SmallVectorStorage {};
 
 /// This is a 'vector' (really, a variable-sized array), optimized
 /// for the case when the array is small.  It contains some number of elements

diff  --git a/llvm/include/llvm/ADT/iterator_range.h 
b/llvm/include/llvm/ADT/iterator_range.h
index f038f6bf2128..a9b46a3aa45b 100644
--- a/llvm/include/llvm/ADT/iterator_range.h
+++ b/llvm/include/llvm/ADT/iterator_range.h
@@ -18,7 +18,6 @@
 #ifndef LLVM_ADT_ITERATOR_RANGE_H
 #define LLVM_ADT_ITERATOR_RANGE_H
 
-#include 
 #include 
 
 namespace llvm {



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


[PATCH] D89318: [ASTImporter] Fix crash caused by unset AttributeSpellingListIndex

2020-10-14 Thread Dave Lee via Phabricator via cfe-commits
kastiglione added a comment.

@martong hi, this caused a test regression. In `TestImportBuiltinFileID.py`, 
this unreachable assertion is hit:

  Ignored/unknown shouldn't get here
  UNREACHABLE executed at 
tools/clang/include/clang/Sema/AttrSpellingListIndex.inc:13!

See http://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/24213/ for more on 
the failure.

I will revert shortly if you're not available.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89318

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


[PATCH] D66782: SourceManager: Prefer Optional over MemoryBuffer*

2020-10-14 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith abandoned this revision.
dexonsmith added a comment.

I finished reimplementing this patch mostly as discussed, culminating in 
https://reviews.llvm.org/D89431. I've rebased https://reviews.llvm.org/D89431 
on top of that. Abandoning this revision.


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

https://reviews.llvm.org/D66782

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


[PATCH] D85802: [clang] Add -fc++-abi= flag for specifying which C++ ABI to use

2020-10-14 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

I'd like to point out that we used to have a very similar flag, but we removed 
it back in 2014: http://reviews.llvm.org/D2545

Are you sure you need all the flexibility that this flag allows? For example, 
this will let users ask for the MSVC C++ ABI on Linux. I really don't want to 
support the mips, wasm, microsoft, or ios C++ ABI on arbitrary targets, and I 
don't want to have to teach clang to diagnose all the unsupported ways users 
can use this flag. The smaller we can make the space of options, the better, 
and the less conditional soup we'll have in the future.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85802

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


[PATCH] D67030: ContentCache: Simplify by always owning the MemoryBuffer

2020-10-14 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith updated this revision to Diff 298257.
dexonsmith edited the summary of this revision.
dexonsmith added a comment.

Rebased on top of https://reviews.llvm.org/D89431 (the tests haven't finished 
yet; I'll update if necessary, but this is pretty straightforward).


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

https://reviews.llvm.org/D67030

Files:
  clang/include/clang/Basic/SourceManager.h
  clang/lib/Basic/SourceManager.cpp
  clang/lib/Frontend/CompilerInstance.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp
  lldb/source/Plugins/Language/ClangCommon/ClangHighlighter.cpp

Index: lldb/source/Plugins/Language/ClangCommon/ClangHighlighter.cpp
===
--- lldb/source/Plugins/Language/ClangCommon/ClangHighlighter.cpp
+++ lldb/source/Plugins/Language/ClangCommon/ClangHighlighter.cpp
@@ -168,7 +168,7 @@
   clang::SourceManager SM(diags, file_mgr);
   auto buf = llvm::MemoryBuffer::getMemBuffer(full_source);
 
-  FileID FID = SM.createFileID(clang::SourceManager::Unowned, buf.get());
+  FileID FID = SM.createFileID(buf->getMemBufferRef());
 
   // Let's just enable the latest ObjC and C++ which should get most tokens
   // right.
Index: lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp
===
--- lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp
@@ -221,7 +221,7 @@
   clang::SourceManager SM(diags, file_mgr);
   auto buf = llvm::MemoryBuffer::getMemBuffer(body);
 
-  FileID FID = SM.createFileID(clang::SourceManager::Unowned, buf.get());
+  FileID FID = SM.createFileID(buf->getMemBufferRef());
 
   // Let's just enable the latest ObjC and C++ which should get most tokens
   // right.
Index: clang/lib/Frontend/CompilerInstance.cpp
===
--- clang/lib/Frontend/CompilerInstance.cpp
+++ clang/lib/Frontend/CompilerInstance.cpp
@@ -346,10 +346,16 @@
   continue;
 }
 
-// Override the contents of the "from" file with the contents of
-// the "to" file.
-SourceMgr.overrideFileContents(FromFile, RB.second,
-   InitOpts.RetainRemappedFileBuffers);
+// Override the contents of the "from" file with the contents of the
+// "to" file. If the caller owns the buffers, then pass a MemoryBufferRef;
+// otherwise, pass as a std::unique_ptr to transfer ownership
+// to the SourceManager.
+if (InitOpts.RetainRemappedFileBuffers)
+  SourceMgr.overrideFileContents(FromFile, RB.second->getMemBufferRef());
+else
+  SourceMgr.overrideFileContents(
+  FromFile, std::unique_ptr(
+const_cast(RB.second)));
   }
 
   // Remap files in the source manager (with other files).
Index: clang/lib/Basic/SourceManager.cpp
===
--- clang/lib/Basic/SourceManager.cpp
+++ clang/lib/Basic/SourceManager.cpp
@@ -49,28 +49,22 @@
 // SourceManager Helper Classes
 //===--===//
 
-ContentCache::~ContentCache() {
-  if (shouldFreeBuffer())
-delete Buffer.getPointer();
-}
-
 /// getSizeBytesMapped - Returns the number of bytes actually mapped for this
 /// ContentCache. This can be 0 if the MemBuffer was not actually expanded.
 unsigned ContentCache::getSizeBytesMapped() const {
-  return Buffer.getPointer() ? Buffer.getPointer()->getBufferSize() : 0;
+  return Buffer ? Buffer->getBufferSize() : 0;
 }
 
 /// Returns the kind of memory used to back the memory buffer for
 /// this content cache.  This is used for performance analysis.
 llvm::MemoryBuffer::BufferKind ContentCache::getMemoryBufferKind() const {
-  assert(Buffer.getPointer());
+  assert(Buffer);
 
   // Should be unreachable, but keep for sanity.
-  if (!Buffer.getPointer())
+  if (!Buffer)
 return llvm::MemoryBuffer::MemoryBuffer_Malloc;
 
-  const llvm::MemoryBuffer *buf = Buffer.getPointer();
-  return buf->getBufferKind();
+  return Buffer->getBufferKind();
 }
 
 /// getSize - Returns the size of the content encapsulated by this ContentCache.
@@ -78,21 +72,8 @@
 ///  scratch buffer.  If the ContentCache encapsulates a source file, that
 ///  file is not lazily brought in from disk to satisfy this query.
 unsigned ContentCache::getSize() const {
-  return Buffer.getPointer() ? (unsigned) Buffer.getPointer()->getBufferSize()
- : (unsigned) ContentsEntry->getSize();
-}
-
-void ContentCache::replaceBuffer(const llvm::MemoryBuffer *B, bool DoNotFree) {
-  if (B && B == Buffer.getPointer()) {
-assert(0 && "Replacing with the same buffer");
-Buffer.setInt(DoNotFree? DoNotFreeFlag : 0);
-return;
-  }
-
-  if (shouldFreeBuffer())
-delete 

[PATCH] D89072: [CodeView] Emit static data members as S_CONSTANTs.

2020-10-14 Thread Amy Huang via Phabricator via cfe-commits
akhuang marked an inline comment as done.
akhuang added inline comments.



Comment at: clang/test/CodeGenCXX/debug-info-static-member.cpp:144-147
+// For some reason, const_va is not emitted when the target is MS.
+// NOT-MS: !DIDerivedType(tag: DW_TAG_member, name: "const_va",
+// NOT-MS-SAME:   line: [[@LINE-3]]
+// NOT-MS-SAME:   extraData: i32 42

rnk wrote:
> dblaikie wrote:
> > Bug or feature? If it's a bug, probably should at least make this comment a 
> > "FIXME"
> Feature. The easiest way to understand it is to hallucinate the C++17 
> `inline` keyword on MSVC static const integer data members with inline 
> initializers. This metadata is probably emitted in MS mode, but it probably 
> comes later on.
Oh, ok. I don't think the metadata for `const_va` is emitted anywhere in MS 
mode though. I guess it should be.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89072

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


[PATCH] D89072: [CodeView] Emit static data members as S_CONSTANTs.

2020-10-14 Thread Amy Huang via Phabricator via cfe-commits
akhuang updated this revision to Diff 298258.
akhuang marked an inline comment as done.
akhuang added a comment.

address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89072

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenCXX/debug-info-static-member.cpp
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h
  llvm/test/DebugInfo/COFF/global-constants.ll
  llvm/test/DebugInfo/COFF/types-array-unsized.ll

Index: llvm/test/DebugInfo/COFF/types-array-unsized.ll
===
--- llvm/test/DebugInfo/COFF/types-array-unsized.ll
+++ llvm/test/DebugInfo/COFF/types-array-unsized.ll
@@ -12,14 +12,22 @@
 ; Foo f; // FIXME: only needed to force emit 'Foo'
 
 ; CHECK:  CodeViewTypes [
+; CHECK:Array ([[ARRAY_COMPLETE:0x.*]]) {
+; CHECK-NEXT: TypeLeafKind: LF_ARRAY (0x1503)
+; CHECK-NEXT: ElementType: const char ({{.*}})
+; CHECK-NEXT: IndexType: unsigned __int64 (0x23)
+; CHECK-NEXT: SizeOf: 5
+; CHECK-NEXT: Name:
+; CHECK-NEXT:   }
+; CHECK:  ]
 ; CHECK:Array ([[ARRAY_FWD:0x.*]]) {
 ; CHECK-NEXT: TypeLeafKind: LF_ARRAY (0x1503)
 ; CHECK-NEXT: ElementType: const char ({{.*}})
 ; CHECK-NEXT: IndexType: unsigned __int64 (0x23)
 ; CHECK-NEXT: SizeOf: 0
-; CHECK-NEXT: Name: 
+; CHECK-NEXT: Name:
 ; CHECK-NEXT:   }
-; CHECK:FieldList (0x1003) {
+; CHECK:FieldList (0x1004) {
 ; CHECK-NEXT: TypeLeafKind: LF_FIELDLIST (0x1203)
 ; CHECK-NEXT: StaticDataMember {
 ; CHECK-NEXT:   TypeLeafKind: LF_STMEMBER (0x150E)
@@ -28,14 +36,6 @@
 ; CHECK-NEXT:   Name: str
 ; CHECK-NEXT: }
 ; CHECK-NEXT:   }
-; CHECK:Array ([[ARRAY_COMPLETE:0x.*]]) {
-; CHECK-NEXT: TypeLeafKind: LF_ARRAY (0x1503)
-; CHECK-NEXT: ElementType: const char ({{.*}})
-; CHECK-NEXT: IndexType: unsigned __int64 (0x23)
-; CHECK-NEXT: SizeOf: 5
-; CHECK-NEXT: Name: 
-; CHECK-NEXT:   }
-; CHECK:  ]
 
 ; CHECK:  GlobalData {
 ; CHECK-NEXT:   Kind: S_GDATA32 (0x110D)
Index: llvm/test/DebugInfo/COFF/global-constants.ll
===
--- llvm/test/DebugInfo/COFF/global-constants.ll
+++ llvm/test/DebugInfo/COFF/global-constants.ll
@@ -7,6 +7,9 @@
 ; }
 ; struct S {
 ;   static const int TestConst2 = -10;
+;   // Unused static consts should still be emitted.
+;   static const int TestConst3 = 3;
+;   static constexpr int TestConst 4 = 4;
 ;   enum { SEnum = 42 };
 ; };
 ; enum TestEnum : int {
@@ -34,14 +37,6 @@
 
 ; ASM:	  .short	4359# Record kind: S_CONSTANT
 ; ASM-NEXT:	  .long	4101# Type
-; ASM-NEXT:	  .byte	0x0a, 0x80, 0xf6, 0xff  # Value
-; ASM-NEXT:	  .byte	0xff, 0xff, 0xff, 0xff
-; ASM-NEXT:	  .byte	0xff, 0xff
-; ASM-NEXT:	  .asciz	"S::TestConst2" # Name
-; ASM-NEXT:	  .p2align	2
-
-; ASM:	  .short	4359# Record kind: S_CONSTANT
-; ASM-NEXT:	  .long	4110# Type
 ; ASM-NEXT:	  .byte	0x0a, 0x80, 0x40, 0x61  # Value
 ; ASM-NEXT:	  .byte	0x07, 0x80, 0xff, 0xff
 ; ASM-NEXT:	  .byte	0xff, 0xff
@@ -49,6 +44,12 @@
 ; ASM-NEXT:	  .p2align	2
 ; ASM-NOT:.asciz "S::SEnum" # Name
 
+; ASM:	  .short	4359# Record kind: S_CONSTANT
+; ASM-NEXT:	  .long	4105# Type
+; ASM-NEXT:	  .byte	0x00, 0x80, 0xf6# Value
+; ASM-NEXT:	  .asciz	"S::TestConst2" # Name
+; ASM-NEXT:	  .p2align	2
+
 ; OBJ:CodeViewDebugInfo [
 ; OBJ:  Section: .debug$S
 ; OBJ:  Magic: 0x4
@@ -62,17 +63,17 @@
 ; OBJ-NEXT:   }
 ; OBJ-NEXT:   ConstantSym {
 ; OBJ-NEXT: Kind: S_CONSTANT (0x1107)
-; OBJ-NEXT: Type: const int (0x1005)
-; OBJ-NEXT: Value: 18446744073709551606
-; OBJ-NEXT: Name: S::TestConst2
-; OBJ-NEXT:   }
-; OBJ-NEXT:   ConstantSym {
-; OBJ-NEXT: Kind: S_CONSTANT (0x1107)
-; OBJ-NEXT: Type: TestEnum (0x100E)
+; OBJ-NEXT: Type: TestEnum (0x1005)
 ; OBJ-NEXT: Value: 18446744071562551616
 ; OBJ-NEXT: Name: ENUM_B
 ; OBJ-NEXT:   }
 ; OBJ-NOT:  Name: S::SEnum
+; OBJ-NEXT:   ConstantSym {
+; OBJ-NEXT: Kind: S_CONSTANT (0x1107)
+; OBJ-NEXT: Type: const int (0x1009)
+; OBJ-NEXT: Value: -10
+; OBJ-NEXT: Name: S::TestConst2
+; OBJ-NEXT:   }
 
 ; ModuleID = 'a.cpp'
 source_filename = "a.cpp"
@@ -98,43 +99,43 @@
 !llvm.module.flags = !{!26, !27, !28, !29}
 !llvm.ident = !{!30}
 
-!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 11.0.0 (https://github.com/llvm/llvm-project.git 202f144bffd0be254a829924195e1b8ebabcbb79)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !15, globals: !16, nameTableKind: None)

Re: [clang] 683b308 - [clang] Add -fc++-abi= flag for specifying which C++ ABI to use

2020-10-14 Thread Leonard Chan via cfe-commits
Updated with 8487bfd4e9ae186f9f588ef989d27a96cc2438c9

On Wed, Oct 14, 2020 at 1:53 PM Richard Smith  wrote:

> On Wed, 14 Oct 2020 at 12:31, Leonard Chan via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>>
>> Author: Leonard Chan
>> Date: 2020-10-14T12:31:21-07:00
>> New Revision: 683b308c07bf827255fe1403056413f790e03729
>>
>> URL:
>> https://github.com/llvm/llvm-project/commit/683b308c07bf827255fe1403056413f790e03729
>> DIFF:
>> https://github.com/llvm/llvm-project/commit/683b308c07bf827255fe1403056413f790e03729.diff
>>
>> LOG: [clang] Add -fc++-abi= flag for specifying which C++ ABI to use
>>
>> This implements the flag proposed in RFC
>> http://lists.llvm.org/pipermail/cfe-dev/2020-August/066437.html.
>>
>> The goal is to add a way to override the default target C++ ABI through
>> a compiler flag. This makes it easier to test and transition between
>> different
>> C++ ABIs through compile flags rather than build flags.
>>
>> In this patch:
>> - Store `-fc++-abi=` in a LangOpt. This isn't stored in a
>>   CodeGenOpt because there are instances outside of codegen where Clang
>>   needs to know what the ABI is (particularly through
>>   ASTContext::createCXXABI), and we should be able to override the
>>   target default if the flag is provided at that point.
>> - Expose the existing ABIs in TargetCXXABI as values that can be passed
>>   through this flag.
>>   - Create a .def file for these ABIs to make it easier to check flag
>> values.
>>   - Add an error for diagnosing bad ABI flag values.
>>
>> Differential Revision: https://reviews.llvm.org/D85802
>>
>> Added:
>> clang/include/clang/Basic/TargetCXXABI.def
>> clang/test/Frontend/invalid-cxx-abi.cpp
>>
>> Modified:
>> clang/include/clang/AST/ASTContext.h
>> clang/include/clang/Basic/DiagnosticDriverKinds.td
>> clang/include/clang/Basic/LangOptions.h
>> clang/include/clang/Basic/TargetCXXABI.h
>> clang/include/clang/Driver/Options.td
>> clang/lib/AST/ASTContext.cpp
>> clang/lib/CodeGen/CodeGenModule.cpp
>> clang/lib/CodeGen/ItaniumCXXABI.cpp
>> clang/lib/Driver/ToolChains/Clang.cpp
>> clang/lib/Frontend/CompilerInvocation.cpp
>>
>> Removed:
>>
>>
>>
>>
>> 
>> diff  --git a/clang/include/clang/AST/ASTContext.h
>> b/clang/include/clang/AST/ASTContext.h
>> index 3f4079e2569b..e5c80866a0a9 100644
>> --- a/clang/include/clang/AST/ASTContext.h
>> +++ b/clang/include/clang/AST/ASTContext.h
>> @@ -39,6 +39,7 @@
>>  #include "clang/Basic/SanitizerBlacklist.h"
>>  #include "clang/Basic/SourceLocation.h"
>>  #include "clang/Basic/Specifiers.h"
>> +#include "clang/Basic/TargetCXXABI.h"
>>  #include "clang/Basic/XRayLists.h"
>>  #include "llvm/ADT/APSInt.h"
>>  #include "llvm/ADT/ArrayRef.h"
>> @@ -697,6 +698,11 @@ class ASTContext : public RefCountedBase
>> {
>>  return FullSourceLoc(Loc,SourceMgr);
>>}
>>
>> +  /// Return the C++ ABI kind that should be used. The C++ ABI can be
>> overriden
>> +  /// at compile time with `-fc++-abi=`. If this is not provided, we
>> instead use
>> +  /// the default ABI set by the target.
>> +  TargetCXXABI::Kind getCXXABIKind() const;
>> +
>>/// All comments in this translation unit.
>>RawCommentList Comments;
>>
>>
>> diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td
>> b/clang/include/clang/Basic/DiagnosticDriverKinds.td
>> index 29bc19e5a84e..f1b3d4d9087e 100644
>> --- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
>> +++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
>> @@ -524,4 +524,6 @@ def err_drv_invalid_object_mode : Error<"OBJECT_MODE
>> setting %0 is not recognize
>>
>>  def err_drv_invalid_sve_vector_bits : Error<
>>"'-msve-vector-bits' is not supported without SVE enabled">;
>> +
>> +def err_invalid_cxx_abi : Error<"Invalid C++ ABI name '%0'">;
>>
>
> Diagnostics should start with a lowercase letter.
>
>
>>  }
>>
>> diff  --git a/clang/include/clang/Basic/LangOptions.h
>> b/clang/include/clang/Basic/LangOptions.h
>> index 84d25c359c55..147fab614308 100644
>> --- a/clang/include/clang/Basic/LangOptions.h
>> +++ b/clang/include/clang/Basic/LangOptions.h
>> @@ -18,6 +18,7 @@
>>  #include "clang/Basic/LLVM.h"
>>  #include "clang/Basic/ObjCRuntime.h"
>>  #include "clang/Basic/Sanitizers.h"
>> +#include "clang/Basic/TargetCXXABI.h"
>>  #include "clang/Basic/Visibility.h"
>>  #include "llvm/ADT/FloatingPointMode.h"
>>  #include "llvm/ADT/StringRef.h"
>> @@ -294,6 +295,10 @@ class LangOptions : public LangOptionsBase {
>>/// host code generation.
>>std::string OMPHostIRFile;
>>
>> +  /// C++ ABI to compile with, if specified by the frontend through
>> -fc++-abi=.
>> +  /// This overrides the default ABI used by the target.
>> +  llvm::Optional CXXABI;
>> +
>>/// Indicates whether the front-end is explicitly told that the
>>/// input is a header file (i.e. -x c-header).
>>bool IsHeaderFile = false;
>>
>> diff  --git 

[clang] 8487bfd - [clang][NFC] Change diagnostic to start with lowercase letter

2020-10-14 Thread Leonard Chan via cfe-commits

Author: Leonard Chan
Date: 2020-10-14T15:48:29-07:00
New Revision: 8487bfd4e9ae186f9f588ef989d27a96cc2438c9

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

LOG: [clang][NFC] Change diagnostic to start with lowercase letter

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/test/Frontend/invalid-cxx-abi.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index f1b3d4d9087e..d87983ef5249 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -525,5 +525,5 @@ def err_drv_invalid_object_mode : Error<"OBJECT_MODE 
setting %0 is not recognize
 def err_drv_invalid_sve_vector_bits : Error<
   "'-msve-vector-bits' is not supported without SVE enabled">;
 
-def err_invalid_cxx_abi : Error<"Invalid C++ ABI name '%0'">;
+def err_invalid_cxx_abi : Error<"invalid C++ ABI name '%0'">;
 }

diff  --git a/clang/test/Frontend/invalid-cxx-abi.cpp 
b/clang/test/Frontend/invalid-cxx-abi.cpp
index 20c6d7bde22c..02a5f3a4e368 100644
--- a/clang/test/Frontend/invalid-cxx-abi.cpp
+++ b/clang/test/Frontend/invalid-cxx-abi.cpp
@@ -12,5 +12,5 @@
 
 // RUN: not %clang_cc1 -fc++-abi=InvalidABI %s 2>&1 | FileCheck %s 
-check-prefix=INVALID
 // RUN: not %clang_cc1 -fc++-abi=Fuchsia %s 2>&1 | FileCheck %s 
-check-prefix=CASE-SENSITIVE
-// INVALID: error: Invalid C++ ABI name 'InvalidABI'
-// CASE-SENSITIVE: error: Invalid C++ ABI name 'Fuchsia'
+// INVALID: error: invalid C++ ABI name 'InvalidABI'
+// CASE-SENSITIVE: error: invalid C++ ABI name 'Fuchsia'



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


[PATCH] D89177: [cmake] Add support for multiple distributions

2020-10-14 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added a subscriber: ldionne.
smeenai added a comment.

In D89177#2326875 , @phosek wrote:

> In D89177#2326832 , @smeenai wrote:
>
>> In D89177#2325566 , @phosek wrote:
>>
>>> We've already considered introducing a similar mechanism so thank you for 
>>> working on this! There's one issue that I haven't figured out how to 
>>> resolve and I'd be interested in your thoughts: building executables and 
>>> libraries in the most optimal may require incompatible flags. For example, 
>>> when building a shared library you have to use `-fPIC` but for executables 
>>> that's suboptimal; similarly, when building executables you may want to use 
>>> LTO but if you also want to create a distribution that contains static 
>>> libraries, that's a problem because those will contain bitcode. So far our 
>>> solution has been to simply do multiple builds with different flags (in GN 
>>> this can be done in a single build by leveraging the "toolchain" concept 
>>> that also allows sharing as much work as possible, but I haven't figured 
>>> out how to do anything like that in CMake).
>>
>> Good question. We need something similar as well, where some clients of the 
>> libraries want them built with RTTI (because their programs rely on RTTI and 
>> you can get link errors when linking them against non-RTTI LLVM libraries), 
>> but we don't wanna build the executables with RTTI because of the size 
>> increases.
>
> We recently ran into this as well where we need RTTI for LLVM libraries but 
> don't want to enable it for the toolchain.
>
>> I don't know of any way to do this in CMake other than just configuring 
>> multiple times with the different flags, like you said. Maybe we could 
>> implement some logic for that in the build system, but I'm not sure if it's 
>> worth it. (I'm wondering if the Ninja multi-config generator added in CMake 
>> 3.17 could be useful for this, although I haven't played around with that at 
>> all yet.) I do recognize it limits the usefulness of this approach quite a 
>> bit (since if you're doing separate configurations you can just do different 
>> `LLVM_DISTRIBUTION_COMPONENT` settings), but I'm hoping it can still be 
>> valuable for simpler scenarios.
>
> One idea I had would be to eliminate the use of global variables like 
> `CMAKE_C_FLAGS` and `CMAKE_CXX_FLAGS` and always set these via 
> `target_compile_options` (which is something we should do in any case to move 
> towards more modern CMake); since we always use functions like 
> `add_llvm_component_library` to create targets in LLVM, we could then have 
> these create multiple targets that would differ in flags like `-fPIC` or 
> `-frtti` and set up dependencies among these appropriately. It means you'd 
> have to build files multiple times (I don't think there's any way around 
> that) but you'd save time on things like tablegen.

Yeah, we should definitely be moving away from global flag manipulation (and I 
know @ldionne has been doing a bunch of cleanups for that in libc++). Being 
able to have as much commonality as possible would be nice, although CMake 
seems to be more in the "different configurations/build types for different 
build settings" camp.

Reading up on the Ninja multi-config generator more, it seems pretty well 
suited to handling things like PIC vs. non-PIC and LTO vs. non-LTO (although I 
haven't thought a lot about how those configs would interact with the 
multi-stage bootstrapping setups). RTTI vs. non-RTTI is more complicated (see 
my previous comment), but should be achievable by tweaking how LLVM's build 
system manipulates those flags. (Strawman proposal: have `LLVM_ENABLE_RTTI` 
accept a `default` argument in addition to the regular booleans to denote that 
you want LLVM to respect your config's flag settings for RTTI instead of trying 
to enforce its own.)

>> Out of curiosity, with GN, how would you specify that you want binaries to 
>> be built with one toolchain (e.g. LTO and non-PIC) and libraries with 
>> another (e.g. non-LTO and PIC)?
>
> In GN there's no global concept of tools like `CC` or `LD`, instead these are 
> scoped inside a `toolchain` which in GN is a first class concept, and 
> dependencies can be parametrized by toolchains (for example you can have 
> `deps = [ "//path/to/dependency(//path/to/toolchain)" ]`. These toolchains 
> can be also parametrized and templated. A common use case is to have a 
> variety of toolchains that have the same tools but differ in flags like 
> `-fPIC`. In Ninja this is represented as subninjas where each child Ninja 
> file defines its own set of rules.
>
> You can see an example of this even in LLVM GN build where we define a set of 
> toolchains in 
> https://github.com/llvm/llvm-project/blob/1687a8d83b702332c4aae4f2a95d27c16688418d/llvm/utils/gn/build/toolchain/BUILD.gn#L179
>  and then use them to built runtimes in 
> 

[PATCH] D89431: clang/Basic: ContentCache::InvalidFlag => ContentCache::IsBufferInvalid, NFC

2020-10-14 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith updated this revision to Diff 298252.
dexonsmith added a comment.

Add missing constructor initializations for the new bitfield member...


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

https://reviews.llvm.org/D89431

Files:
  clang/include/clang/Basic/SourceManager.h
  clang/lib/Basic/SourceManager.cpp


Index: clang/lib/Basic/SourceManager.cpp
===
--- clang/lib/Basic/SourceManager.cpp
+++ clang/lib/Basic/SourceManager.cpp
@@ -123,7 +123,7 @@
   SourceLocation Loc) const {
   // Lazily create the Buffer for ContentCaches that wrap files.  If we already
   // computed it, just return what we have.
-  if (isBufferInvalid())
+  if (IsBufferInvalid)
 return None;
   if (auto *B = Buffer.getPointer())
 return B->getMemBufferRef();
@@ -144,7 +144,7 @@
   Diag.Report(Loc, diag::err_file_too_large)
 << ContentsEntry->getName();
 
-Buffer.setInt(Buffer.getInt() | InvalidFlag);
+IsBufferInvalid = true;
 return None;
   }
 
@@ -164,7 +164,7 @@
   Diag.Report(Loc, diag::err_cannot_open_file)
   << ContentsEntry->getName() << BufferOrError.getError().message();
 
-Buffer.setInt(Buffer.getInt() | InvalidFlag);
+IsBufferInvalid = true;
 return None;
   }
 
@@ -180,7 +180,7 @@
   Diag.Report(Loc, diag::err_file_modified)
 << ContentsEntry->getName();
 
-Buffer.setInt(Buffer.getInt() | InvalidFlag);
+IsBufferInvalid = true;
 return None;
   }
 
@@ -193,7 +193,7 @@
   if (InvalidBOM) {
 Diag.Report(Loc, diag::err_unsupported_bom)
   << InvalidBOM << ContentsEntry->getName();
-Buffer.setInt(Buffer.getInt() | InvalidFlag);
+IsBufferInvalid = true;
 return None;
   }
 
Index: clang/include/clang/Basic/SourceManager.h
===
--- clang/include/clang/Basic/SourceManager.h
+++ clang/include/clang/Basic/SourceManager.h
@@ -95,9 +95,6 @@
   /// This object owns the MemoryBuffer object.
   class alignas(8) ContentCache {
 enum CCFlags {
-  /// Whether the buffer is invalid.
-  InvalidFlag = 0x01,
-
   /// Whether the buffer should not be freed on destruction.
   DoNotFreeFlag = 0x02
 };
@@ -151,18 +148,21 @@
 /// after serialization and deserialization.
 unsigned IsTransient : 1;
 
+mutable unsigned IsBufferInvalid : 1;
+
 ContentCache(const FileEntry *Ent = nullptr) : ContentCache(Ent, Ent) {}
 
 ContentCache(const FileEntry *Ent, const FileEntry *contentEnt)
 : Buffer(nullptr, false), OrigEntry(Ent), ContentsEntry(contentEnt),
-  BufferOverridden(false), IsFileVolatile(false), IsTransient(false) {}
+  BufferOverridden(false), IsFileVolatile(false), IsTransient(false),
+  IsBufferInvalid(false) {}
 
 /// The copy ctor does not allow copies where source object has either
 /// a non-NULL Buffer or SourceLineCache.  Ownership of allocated memory
 /// is not transferred, so this is a logical error.
 ContentCache(const ContentCache )
 : Buffer(nullptr, false), BufferOverridden(false),
-  IsFileVolatile(false), IsTransient(false) {
+  IsFileVolatile(false), IsTransient(false), IsBufferInvalid(false) {
   OrigEntry = RHS.OrigEntry;
   ContentsEntry = RHS.ContentsEntry;
 
@@ -216,11 +216,6 @@
 /// with the given buffer.
 void replaceBuffer(const llvm::MemoryBuffer *B, bool DoNotFree = false);
 
-/// Determine whether the buffer itself is invalid.
-bool isBufferInvalid() const {
-  return Buffer.getInt() & InvalidFlag;
-}
-
 /// Determine whether the buffer should be freed.
 bool shouldFreeBuffer() const {
   return (Buffer.getInt() & DoNotFreeFlag) == 0;


Index: clang/lib/Basic/SourceManager.cpp
===
--- clang/lib/Basic/SourceManager.cpp
+++ clang/lib/Basic/SourceManager.cpp
@@ -123,7 +123,7 @@
   SourceLocation Loc) const {
   // Lazily create the Buffer for ContentCaches that wrap files.  If we already
   // computed it, just return what we have.
-  if (isBufferInvalid())
+  if (IsBufferInvalid)
 return None;
   if (auto *B = Buffer.getPointer())
 return B->getMemBufferRef();
@@ -144,7 +144,7 @@
   Diag.Report(Loc, diag::err_file_too_large)
 << ContentsEntry->getName();
 
-Buffer.setInt(Buffer.getInt() | InvalidFlag);
+IsBufferInvalid = true;
 return None;
   }
 
@@ -164,7 +164,7 @@
   Diag.Report(Loc, diag::err_cannot_open_file)
   << ContentsEntry->getName() << BufferOrError.getError().message();
 
-Buffer.setInt(Buffer.getInt() | InvalidFlag);
+IsBufferInvalid = true;
 return None;
   }
 
@@ -180,7 +180,7 @@
   Diag.Report(Loc, diag::err_file_modified)
 << ContentsEntry->getName();
 
-Buffer.setInt(Buffer.getInt() | InvalidFlag);
+

[PATCH] D89177: [cmake] Add support for multiple distributions

2020-10-14 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai updated this revision to Diff 298251.
smeenai added a comment.

Address review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89177

Files:
  clang/cmake/caches/MultiDistributionExample.cmake
  clang/cmake/modules/AddClang.cmake
  clang/cmake/modules/CMakeLists.txt
  clang/cmake/modules/ClangConfig.cmake.in
  flang/cmake/modules/AddFlang.cmake
  flang/cmake/modules/CMakeLists.txt
  flang/cmake/modules/FlangConfig.cmake.in
  lld/cmake/modules/AddLLD.cmake
  lld/cmake/modules/CMakeLists.txt
  lld/cmake/modules/LLDConfig.cmake.in
  llvm/cmake/modules/AddLLVM.cmake
  llvm/cmake/modules/CMakeLists.txt
  llvm/cmake/modules/LLVMConfig.cmake.in
  llvm/cmake/modules/LLVMDistributionSupport.cmake
  llvm/docs/BuildingADistribution.rst
  mlir/cmake/modules/AddMLIR.cmake
  mlir/cmake/modules/CMakeLists.txt
  mlir/cmake/modules/MLIRConfig.cmake.in

Index: mlir/cmake/modules/MLIRConfig.cmake.in
===
--- mlir/cmake/modules/MLIRConfig.cmake.in
+++ mlir/cmake/modules/MLIRConfig.cmake.in
@@ -20,7 +20,7 @@
 set_property(GLOBAL PROPERTY MLIR_TRANSLATION_LIBS "@MLIR_TRANSLATION_LIBS@")
 
 # Provide all our library targets to users.
-include("@MLIR_CONFIG_EXPORTS_FILE@")
+@mlir_config_include_exports@
 
 # By creating these targets here, subprojects that depend on MLIR's
 # tablegen-generated headers can always depend on these targets whether building
Index: mlir/cmake/modules/CMakeLists.txt
===
--- mlir/cmake/modules/CMakeLists.txt
+++ mlir/cmake/modules/CMakeLists.txt
@@ -1,3 +1,5 @@
+include(LLVMDistributionSupport)
+
 # Generate a list of CMake library targets so that other CMake projects can
 # link against them. LLVM calls its version of this file LLVMExports.cmake, but
 # the usual CMake convention seems to be ${Project}Targets.cmake.
@@ -19,7 +21,7 @@
 # Generate MlirConfig.cmake for the build tree.
 set(MLIR_CONFIG_CMAKE_DIR "${mlir_cmake_builddir}")
 set(MLIR_CONFIG_LLVM_CMAKE_DIR "${llvm_cmake_builddir}")
-set(MLIR_CONFIG_EXPORTS_FILE "\${MLIR_CMAKE_DIR}/MLIRTargets.cmake")
+set(mlir_config_include_exports "include(\"\${MLIR_CMAKE_DIR}/MLIRTargets.cmake\")")
 set(MLIR_CONFIG_INCLUDE_DIRS
   "${MLIR_SOURCE_DIR}/include"
   "${MLIR_BINARY_DIR}/include"
@@ -30,7 +32,6 @@
   @ONLY)
 set(MLIR_CONFIG_CMAKE_DIR)
 set(MLIR_CONFIG_LLVM_CMAKE_DIR)
-set(MLIR_CONFIG_EXPORTS_FILE)
 set(MLIR_CONFIG_INCLUDE_DIRS)
 
 # For compatibility with projects that include(MLIRConfig)
@@ -55,7 +56,7 @@
 endforeach(p)
 set(MLIR_CONFIG_CMAKE_DIR "\${MLIR_INSTALL_PREFIX}/${MLIR_INSTALL_PACKAGE_DIR}")
 set(MLIR_CONFIG_LLVM_CMAKE_DIR "\${MLIR_INSTALL_PREFIX}/${LLVM_INSTALL_PACKAGE_DIR}")
-set(MLIR_CONFIG_EXPORTS_FILE "\${MLIR_CMAKE_DIR}/MLIRTargets.cmake")
+get_config_exports_includes(MLIR mlir_config_include_exports)
 set(MLIR_CONFIG_INCLUDE_DIRS
   "\${MLIR_INSTALL_PREFIX}/include"
   )
@@ -66,17 +67,12 @@
 set(MLIR_CONFIG_CODE)
 set(MLIR_CONFIG_CMAKE_DIR)
 set(MLIR_CONFIG_LLVM_CMAKE_DIR)
-set(MLIR_CONFIG_EXPORTS_FILE)
 set(MLIR_CONFIG_INCLUDE_DIRS)
 
 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
   # Not TOOLCHAIN ONLY, so install the MLIR parts as well
   # Include the cmake files so other tools can use mlir-tblgen, etc.
-  get_property(mlir_has_exports GLOBAL PROPERTY MLIR_HAS_EXPORTS)
-  if(mlir_has_exports)
-install(EXPORT MLIRTargets DESTINATION ${MLIR_INSTALL_PACKAGE_DIR}
-COMPONENT mlir-cmake-exports)
-  endif()
+  install_distribution_exports(MLIR)
 
   install(FILES
 ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/MLIRConfig.cmake
Index: mlir/cmake/modules/AddMLIR.cmake
===
--- mlir/cmake/modules/AddMLIR.cmake
+++ mlir/cmake/modules/AddMLIR.cmake
@@ -1,3 +1,5 @@
+include(LLVMDistributionSupport)
+
 function(mlir_tablegen ofn)
   tablegen(MLIR ${ARGV})
   set(TABLEGEN_OUTPUT ${TABLEGEN_OUTPUT} ${CMAKE_CURRENT_BINARY_DIR}/${ofn}
@@ -141,11 +143,10 @@
 function(add_mlir_library_install name)
   if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
   set(export_to_mlirtargets)
-  if (${name} IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR
-  "mlir-libraries" IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR
-  NOT LLVM_DISTRIBUTION_COMPONENTS)
-  set(export_to_mlirtargets EXPORT MLIRTargets)
-set_property(GLOBAL PROPERTY MLIR_HAS_EXPORTS True)
+  get_llvm_distribution(${name} in_distribution distribution UMBRELLA mlir-libraries)
+  if (in_distribution)
+  set(export_to_mlirtargets EXPORT MLIR${distribution}Targets)
+set_property(GLOBAL PROPERTY MLIR${distribution}_HAS_EXPORTS True)
   endif()
 
   install(TARGETS ${name}
Index: llvm/docs/BuildingADistribution.rst
===
--- llvm/docs/BuildingADistribution.rst
+++ llvm/docs/BuildingADistribution.rst
@@ -87,6 +87,40 @@
 the list. This is a 

[PATCH] D89431: clang/Basic: ContentCache::InvalidFlag => ContentCache::IsBufferInvalid, NFC

2020-10-14 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith created this revision.
dexonsmith added a reviewer: arphaman.
Herald added a subscriber: ributzka.
dexonsmith requested review of this revision.

Move a flag out of the `MemoryBuffer*` to unblock changing it to a
`unique_ptr`. There are plenty of bits available in the bitfield below.


https://reviews.llvm.org/D89431

Files:
  clang/include/clang/Basic/SourceManager.h
  clang/lib/Basic/SourceManager.cpp


Index: clang/lib/Basic/SourceManager.cpp
===
--- clang/lib/Basic/SourceManager.cpp
+++ clang/lib/Basic/SourceManager.cpp
@@ -123,7 +123,7 @@
   SourceLocation Loc) const {
   // Lazily create the Buffer for ContentCaches that wrap files.  If we already
   // computed it, just return what we have.
-  if (isBufferInvalid())
+  if (IsBufferInvalid)
 return None;
   if (auto *B = Buffer.getPointer())
 return B->getMemBufferRef();
@@ -144,7 +144,7 @@
   Diag.Report(Loc, diag::err_file_too_large)
 << ContentsEntry->getName();
 
-Buffer.setInt(Buffer.getInt() | InvalidFlag);
+IsBufferInvalid = true;
 return None;
   }
 
@@ -164,7 +164,7 @@
   Diag.Report(Loc, diag::err_cannot_open_file)
   << ContentsEntry->getName() << BufferOrError.getError().message();
 
-Buffer.setInt(Buffer.getInt() | InvalidFlag);
+IsBufferInvalid = true;
 return None;
   }
 
@@ -180,7 +180,7 @@
   Diag.Report(Loc, diag::err_file_modified)
 << ContentsEntry->getName();
 
-Buffer.setInt(Buffer.getInt() | InvalidFlag);
+IsBufferInvalid = true;
 return None;
   }
 
@@ -193,7 +193,7 @@
   if (InvalidBOM) {
 Diag.Report(Loc, diag::err_unsupported_bom)
   << InvalidBOM << ContentsEntry->getName();
-Buffer.setInt(Buffer.getInt() | InvalidFlag);
+IsBufferInvalid = true;
 return None;
   }
 
Index: clang/include/clang/Basic/SourceManager.h
===
--- clang/include/clang/Basic/SourceManager.h
+++ clang/include/clang/Basic/SourceManager.h
@@ -95,9 +95,6 @@
   /// This object owns the MemoryBuffer object.
   class alignas(8) ContentCache {
 enum CCFlags {
-  /// Whether the buffer is invalid.
-  InvalidFlag = 0x01,
-
   /// Whether the buffer should not be freed on destruction.
   DoNotFreeFlag = 0x02
 };
@@ -151,6 +148,8 @@
 /// after serialization and deserialization.
 unsigned IsTransient : 1;
 
+mutable unsigned IsBufferInvalid : 1;
+
 ContentCache(const FileEntry *Ent = nullptr) : ContentCache(Ent, Ent) {}
 
 ContentCache(const FileEntry *Ent, const FileEntry *contentEnt)
@@ -216,11 +215,6 @@
 /// with the given buffer.
 void replaceBuffer(const llvm::MemoryBuffer *B, bool DoNotFree = false);
 
-/// Determine whether the buffer itself is invalid.
-bool isBufferInvalid() const {
-  return Buffer.getInt() & InvalidFlag;
-}
-
 /// Determine whether the buffer should be freed.
 bool shouldFreeBuffer() const {
   return (Buffer.getInt() & DoNotFreeFlag) == 0;


Index: clang/lib/Basic/SourceManager.cpp
===
--- clang/lib/Basic/SourceManager.cpp
+++ clang/lib/Basic/SourceManager.cpp
@@ -123,7 +123,7 @@
   SourceLocation Loc) const {
   // Lazily create the Buffer for ContentCaches that wrap files.  If we already
   // computed it, just return what we have.
-  if (isBufferInvalid())
+  if (IsBufferInvalid)
 return None;
   if (auto *B = Buffer.getPointer())
 return B->getMemBufferRef();
@@ -144,7 +144,7 @@
   Diag.Report(Loc, diag::err_file_too_large)
 << ContentsEntry->getName();
 
-Buffer.setInt(Buffer.getInt() | InvalidFlag);
+IsBufferInvalid = true;
 return None;
   }
 
@@ -164,7 +164,7 @@
   Diag.Report(Loc, diag::err_cannot_open_file)
   << ContentsEntry->getName() << BufferOrError.getError().message();
 
-Buffer.setInt(Buffer.getInt() | InvalidFlag);
+IsBufferInvalid = true;
 return None;
   }
 
@@ -180,7 +180,7 @@
   Diag.Report(Loc, diag::err_file_modified)
 << ContentsEntry->getName();
 
-Buffer.setInt(Buffer.getInt() | InvalidFlag);
+IsBufferInvalid = true;
 return None;
   }
 
@@ -193,7 +193,7 @@
   if (InvalidBOM) {
 Diag.Report(Loc, diag::err_unsupported_bom)
   << InvalidBOM << ContentsEntry->getName();
-Buffer.setInt(Buffer.getInt() | InvalidFlag);
+IsBufferInvalid = true;
 return None;
   }
 
Index: clang/include/clang/Basic/SourceManager.h
===
--- clang/include/clang/Basic/SourceManager.h
+++ clang/include/clang/Basic/SourceManager.h
@@ -95,9 +95,6 @@
   /// This object owns the MemoryBuffer object.
   class alignas(8) ContentCache {
 enum CCFlags {
-  /// Whether the buffer is invalid.
-  InvalidFlag = 0x01,
-
   /// Whether the 

[PATCH] D89430: clang/Basic: Remove SourceManager::getBufferPointer, NFC

2020-10-14 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith created this revision.
dexonsmith added a reviewer: arphaman.
Herald added a subscriber: ributzka.
dexonsmith requested review of this revision.

Inline `Source::getBufferPointer` into its only remaining caller,
`getBufferOrNone`. No functionality change.


https://reviews.llvm.org/D89430

Files:
  clang/include/clang/Basic/SourceManager.h
  clang/lib/Basic/SourceManager.cpp


Index: clang/lib/Basic/SourceManager.cpp
===
--- clang/lib/Basic/SourceManager.cpp
+++ clang/lib/Basic/SourceManager.cpp
@@ -121,22 +121,14 @@
 llvm::Optional
 ContentCache::getBufferOrNone(DiagnosticsEngine , FileManager ,
   SourceLocation Loc) const {
-  if (auto *B = getBufferPointer(Diag, FM, Loc))
-return B->getMemBufferRef();
-  return None;
-}
-
-const llvm::MemoryBuffer *
-ContentCache::getBufferPointer(DiagnosticsEngine , FileManager ,
-   SourceLocation Loc) const {
   // Lazily create the Buffer for ContentCaches that wrap files.  If we already
   // computed it, just return what we have.
   if (isBufferInvalid())
-return nullptr;
+return None;
   if (auto *B = Buffer.getPointer())
-return B;
+return B->getMemBufferRef();
   if (!ContentsEntry)
-return nullptr;
+return None;
 
   // Check that the file's size fits in an 'unsigned' (with room for a
   // past-the-end value). This is deeply regrettable, but various parts of
@@ -153,7 +145,7 @@
 << ContentsEntry->getName();
 
 Buffer.setInt(Buffer.getInt() | InvalidFlag);
-return nullptr;
+return None;
   }
 
   auto BufferOrError = FM.getBufferForFile(ContentsEntry, IsFileVolatile);
@@ -173,7 +165,7 @@
   << ContentsEntry->getName() << BufferOrError.getError().message();
 
 Buffer.setInt(Buffer.getInt() | InvalidFlag);
-return nullptr;
+return None;
   }
 
   Buffer.setPointer(BufferOrError->release());
@@ -189,7 +181,7 @@
 << ContentsEntry->getName();
 
 Buffer.setInt(Buffer.getInt() | InvalidFlag);
-return nullptr;
+return None;
   }
 
   // If the buffer is valid, check to see if it has a UTF Byte Order Mark
@@ -202,10 +194,10 @@
 Diag.Report(Loc, diag::err_unsupported_bom)
   << InvalidBOM << ContentsEntry->getName();
 Buffer.setInt(Buffer.getInt() | InvalidFlag);
-return nullptr;
+return None;
   }
 
-  return Buffer.getPointer();
+  return Buffer.getPointer()->getMemBufferRef();
 }
 
 unsigned LineTableInfo::getLineTableFilenameID(StringRef Name) {
Index: clang/include/clang/Basic/SourceManager.h
===
--- clang/include/clang/Basic/SourceManager.h
+++ clang/include/clang/Basic/SourceManager.h
@@ -188,17 +188,6 @@
 getBufferOrNone(DiagnosticsEngine , FileManager ,
 SourceLocation Loc = SourceLocation()) const;
 
-  private:
-/// Returns pointer to memory buffer.
-///
-/// TODO: SourceManager needs access to this for now, but once that's done
-/// we should remove this API.
-const llvm::MemoryBuffer *getBufferPointer(DiagnosticsEngine ,
-   FileManager ,
-   SourceLocation Loc) const;
-friend class clang::SourceManager;
-
-  public:
 /// Returns the size of the content encapsulated by this
 /// ContentCache.
 ///


Index: clang/lib/Basic/SourceManager.cpp
===
--- clang/lib/Basic/SourceManager.cpp
+++ clang/lib/Basic/SourceManager.cpp
@@ -121,22 +121,14 @@
 llvm::Optional
 ContentCache::getBufferOrNone(DiagnosticsEngine , FileManager ,
   SourceLocation Loc) const {
-  if (auto *B = getBufferPointer(Diag, FM, Loc))
-return B->getMemBufferRef();
-  return None;
-}
-
-const llvm::MemoryBuffer *
-ContentCache::getBufferPointer(DiagnosticsEngine , FileManager ,
-   SourceLocation Loc) const {
   // Lazily create the Buffer for ContentCaches that wrap files.  If we already
   // computed it, just return what we have.
   if (isBufferInvalid())
-return nullptr;
+return None;
   if (auto *B = Buffer.getPointer())
-return B;
+return B->getMemBufferRef();
   if (!ContentsEntry)
-return nullptr;
+return None;
 
   // Check that the file's size fits in an 'unsigned' (with room for a
   // past-the-end value). This is deeply regrettable, but various parts of
@@ -153,7 +145,7 @@
 << ContentsEntry->getName();
 
 Buffer.setInt(Buffer.getInt() | InvalidFlag);
-return nullptr;
+return None;
   }
 
   auto BufferOrError = FM.getBufferForFile(ContentsEntry, IsFileVolatile);
@@ -173,7 +165,7 @@
   << ContentsEntry->getName() << BufferOrError.getError().message();
 
 Buffer.setInt(Buffer.getInt() | InvalidFlag);
-return nullptr;
+return None;
   }
 
   

[PATCH] D89429: clang/Basic: Replace SourceManager::getMemoryBufferForFile, NFC

2020-10-14 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith created this revision.
dexonsmith added a reviewer: arphaman.
Herald added a subscriber: ributzka.
dexonsmith requested review of this revision.

Replace `SourceManager::getMemoryBufferForFile`, which returned a
dereferenceable `MemoryBuffer*` and had a `bool*Invalid` out parameter,
with `getMemoryBufferForFileOrNone` (returning
`Optional`) and `getMemoryBufferForFileOrFake`
(returning `MemoryBufferRef`).


https://reviews.llvm.org/D89429

Files:
  clang/include/clang/Basic/SourceManager.h
  clang/include/clang/Frontend/PrecompiledPreamble.h
  clang/lib/Basic/SourceManager.cpp
  clang/lib/Frontend/PrecompiledPreamble.cpp
  clang/lib/Lex/Preprocessor.cpp

Index: clang/lib/Lex/Preprocessor.cpp
===
--- clang/lib/Lex/Preprocessor.cpp
+++ clang/lib/Lex/Preprocessor.cpp
@@ -395,12 +395,10 @@
   assert(CompleteLine && CompleteColumn && "Starts from 1:1");
   assert(!CodeCompletionFile && "Already set");
 
-  using llvm::MemoryBuffer;
-
   // Load the actual file's contents.
-  bool Invalid = false;
-  const MemoryBuffer *Buffer = SourceMgr.getMemoryBufferForFile(File, );
-  if (Invalid)
+  Optional Buffer =
+  SourceMgr.getMemoryBufferForFileOrNone(File);
+  if (!Buffer)
 return true;
 
   // Find the byte position of the truncation point.
Index: clang/lib/Frontend/PrecompiledPreamble.cpp
===
--- clang/lib/Frontend/PrecompiledPreamble.cpp
+++ clang/lib/Frontend/PrecompiledPreamble.cpp
@@ -463,7 +463,8 @@
   PrecompiledPreamble::PreambleFileHash::createForFile(File->getSize(),
ModTime);
 } else {
-  const llvm::MemoryBuffer *Buffer = SourceMgr.getMemoryBufferForFile(File);
+  llvm::MemoryBufferRef Buffer =
+  SourceMgr.getMemoryBufferForFileOrFake(File);
   FilesInPreamble[File->getName()] =
   PrecompiledPreamble::PreambleFileHash::createForMemoryBuffer(Buffer);
 }
@@ -549,7 +550,7 @@
   llvm::StringMap OverridenFileBuffers;
   for (const auto  : PreprocessorOpts.RemappedFileBuffers) {
 const PrecompiledPreamble::PreambleFileHash PreambleHash =
-PreambleFileHash::createForMemoryBuffer(RB.second);
+PreambleFileHash::createForMemoryBuffer(RB.second->getMemBufferRef());
 llvm::vfs::Status Status;
 if (moveOnNoError(VFS->status(RB.first), Status))
   OverriddenFiles[Status.getUniqueID()] = PreambleHash;
@@ -783,13 +784,13 @@
 
 PrecompiledPreamble::PreambleFileHash
 PrecompiledPreamble::PreambleFileHash::createForMemoryBuffer(
-const llvm::MemoryBuffer *Buffer) {
+const llvm::MemoryBufferRef ) {
   PreambleFileHash Result;
-  Result.Size = Buffer->getBufferSize();
+  Result.Size = Buffer.getBufferSize();
   Result.ModTime = 0;
 
   llvm::MD5 MD5Ctx;
-  MD5Ctx.update(Buffer->getBuffer().data());
+  MD5Ctx.update(Buffer.getBuffer().data());
   MD5Ctx.final(Result.MD5);
 
   return Result;
Index: clang/lib/Basic/SourceManager.cpp
===
--- clang/lib/Basic/SourceManager.cpp
+++ clang/lib/Basic/SourceManager.cpp
@@ -701,14 +701,11 @@
   return SourceLocation::getMacroLoc(NextLocalOffset - (TokLength + 1));
 }
 
-const llvm::MemoryBuffer *
-SourceManager::getMemoryBufferForFile(const FileEntry *File, bool *Invalid) {
+llvm::Optional
+SourceManager::getMemoryBufferForFileOrNone(const FileEntry *File) {
   const SrcMgr::ContentCache *IR = getOrCreateContentCache(File);
   assert(IR && "getOrCreateContentCache() cannot return NULL");
-  auto *B = IR->getBufferPointer(Diag, getFileManager(), SourceLocation());
-  if (Invalid)
-*Invalid = !B;
-  return B ? B : getFakeBufferForRecovery();
+  return IR->getBufferOrNone(Diag, getFileManager(), SourceLocation());
 }
 
 void SourceManager::overrideFileContents(const FileEntry *SourceFile,
Index: clang/include/clang/Frontend/PrecompiledPreamble.h
===
--- clang/include/clang/Frontend/PrecompiledPreamble.h
+++ clang/include/clang/Frontend/PrecompiledPreamble.h
@@ -26,6 +26,7 @@
 
 namespace llvm {
 class MemoryBuffer;
+class MemoryBufferRef;
 namespace vfs {
 class FileSystem;
 }
@@ -216,7 +217,7 @@
 
 static PreambleFileHash createForFile(off_t Size, time_t ModTime);
 static PreambleFileHash
-createForMemoryBuffer(const llvm::MemoryBuffer *Buffer);
+createForMemoryBuffer(const llvm::MemoryBufferRef );
 
 friend bool operator==(const PreambleFileHash ,
const PreambleFileHash ) {
Index: clang/include/clang/Basic/SourceManager.h
===
--- clang/include/clang/Basic/SourceManager.h
+++ clang/include/clang/Basic/SourceManager.h
@@ -895,10 +895,18 @@
 
   /// Retrieve the memory buffer associated with the given file.
   ///
-  /// \param Invalid If non-NULL, will be 

[PATCH] D89366: [WebAssembly] v128.load{8, 16, 32, 64}_lane instructions

2020-10-14 Thread Heejin Ahn via Phabricator via cfe-commits
aheejin added a comment.

Do loads need the vector argument? The proposal has that but I'm wondering 
why... Can that possibly be an error from the author's side?




Comment at: clang/include/clang/Basic/BuiltinsWebAssembly.def:180
+TARGET_BUILTIN(__builtin_wasm_load32_lane, "V4iIii*", "nU", "simd128")
+TARGET_BUILTIN(__builtin_wasm_load64_lane, "V2LLiIiLLi*", "nU", "simd128")
+TARGET_BUILTIN(__builtin_wasm_store8_lane, "vV16ScIiSc*", "n", "simd128")

tlively wrote:
> aheejin wrote:
> > `U` in the third argument [[ 
> > https://github.com/llvm/llvm-project/blob/72732acade77d5ee55a818e2da77a2c5b7033ccb/clang/include/clang/Basic/Builtins.def#L75
> >  | means ]] pure. Can we say loads are pure? (The same for existing 
> > `__builtin_wasm_load32_zero` and `__builtin_wasm_load64_zero`)
> Yes, this is the difference between "pure" and "const." 
> 
> https://github.com/llvm/llvm-project/blob/master/clang/include/clang/Basic/Builtins.h#L97-L106
Can't SIMD loads trap? (Normal loads can AFAIK, right?)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89366

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


Re: [PATCH] D89277: [clangd] Add $/dumpMemoryTree LSP extension

2020-10-14 Thread Sam McCall via cfe-commits
On Wed, Oct 14, 2020 at 6:10 PM Kadir Cetinkaya via Phabricator <
revi...@reviews.llvm.org> wrote:

> kadircet added a comment.
>
> In D89277#2329947 , @sammccall
> wrote:
>
> > (sorry out today and haven't looked at code yet)
>
> no worries it is a prototype, I wouldn't spend time looking at the
> implementation until we agree on the interaction :D
> OTHO, checking out the lit test for output would probably be useful.
>
> > If it's a custom method, I think it should return the data as a json
> structure - the client already has to have custom support to invoke it,
> displaying the result isn't much extra work.
>
> SGTM. WDYT about a json object in the form of:
>
>   interface MemoryTreeNode {
> name: string;
> totalSize: int;
>
I'd also include self-size.


> children?: Node[];
>   };
>
This looks like:
{
  "name": "root"
  "totalSize": 100,
  "children": [
{
  "name": "component1",
  "totalSize": 25,
},
{
  "name": "component2",
  "totalSize": 75,
}
  ]
}

A couple of alternatives: I think making "children" an object and moving
the name up to the edge is more natural.
We no longer name the root, which I don't think is a bad thing.
{
  "totalSize": 100,
  "children": {
"component1": {
  "totalSize": 25,
},
"component2": {
  "totalSize": 75,
}
  ]
}

A more-compact alternative folds the child attributes into the node itself.
This is probably more awkward to query directly (e.g. "does a node have
children") and might end up being marshalled into a struct.
On the other hand, I think it's easier to read directly e.g. in logs, esp
when deeply nested.
{
  "_total": 100,
  "component1": {
"_total": 25
  }
  "component2": {
"_total": 25
  }
}

> And I would really love to add a tree view to vscode, I think it wouldn't
> be hard (vs call hierarchy: no laziness and no direction-flipping) and
> could be reused for an AST viewer.
>
> right, vscode already has APIs for it,
> https://code.visualstudio.com/api/extension-guides/tree-view.
>
I found some time today and have a prototype of AST dump... nearly working
:-)
The complexity of the treeview API does indeed mostly disappear when you
have simple tree-shaped data and it's all available at once.
Just the annoying extension-point boilerplate remains...
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D89372: [OpenCL] Remove unused extensions

2020-10-14 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: clang/include/clang/Basic/OpenCLExtensions.def:16
 //
 // If the extensions are to be enumerated without the supported OpenCL version,
 // define OPENCLEXT(ext) where ext is the name of the extension.

yaxunl wrote:
> Can you add a comment here referring the spec about "Every extension which 
> affects the OpenCL language semantics, syntax or adds built-in functions to 
> the language must create a preprocessor #define that matches the extension 
> name string." and therefore only extensions "which affects the OpenCL 
> language semantics, syntax or adds built-in functions to the language" are 
> defined in this file. Thanks.
Good idea! I also suggest we add clarifications regarding pragmas, that those 
are to be added only when the compiler needs to change the compilation flow 
i.e. if there is a difference in the language semantic from what is defined in 
a standard.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89372

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


[PATCH] D88603: [WebAssembly] Add support for DWARF type units

2020-10-14 Thread Derek Schuff via Phabricator via cfe-commits
dschuff added inline comments.



Comment at: llvm/lib/MC/MCObjectFileInfo.cpp:962
+  case Triple::Wasm:
+return Ctx->getWasmSection(Name, SectionKind::getMetadata(), utostr(Hash),
+   ~0);

dblaikie wrote:
> dschuff wrote:
> > dblaikie wrote:
> > > dschuff wrote:
> > > > dschuff wrote:
> > > > > I may add a couple more tests to this, but I did want to ask @sbc100 
> > > > > about this, since I'm not 100% sure at the uniqueID field is for.
> > > > also let me be more clear about the question here: what is `UniqueID` 
> > > > for, and is it bad that I'm just passing it a number that is totally 
> > > > not unique?
> > > For ELF, at least, I believe the unique ID is used to know which elements 
> > > are to be treated as part of the same deduplication set.
> > > 
> > > If Wasm support in lld does the same thing, then using the same number 
> > > for every type unit would mean the linked binary would end up with only 
> > > one type definition - even when the input has many varied/independent 
> > > type definitions. Likely not what's intended.
> > For wasm I had thought that was what the 3rd argument (Group) was for. So 
> > if that's what `UniqueID` is for, then I have the same question about Group 
> > :)
> Oh, fair enough - I hadn't read closely. Yeah, guess it's up to you folks/how 
> the wasm object format works... - so I'm with you on the "what is the 
> uniqueID field for" (& what's the other field that's taking the hash?) & I'll 
> leave it to you folks to... hash out.
@sbc100 ping, is this what we want here?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88603

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


[clang] e7b4fee - [Format/ObjC] Add NS_SWIFT_NAME() and CF_SWIFT_NAME() to WhitespaceSensitiveMacros

2020-10-14 Thread Ben Hamilton via cfe-commits

Author: Ben Hamilton
Date: 2020-10-14T15:42:51-06:00
New Revision: e7b4feea8e1bf520b34ad8c116abab6677344b74

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

LOG: [Format/ObjC] Add NS_SWIFT_NAME() and CF_SWIFT_NAME() to 
WhitespaceSensitiveMacros

The argument passed to the preprocessor macros `NS_SWIFT_NAME(x)` and
`CF_SWIFT_NAME(x)` is stringified before passing to
`__attribute__((swift_name("x")))`.

ClangFormat didn't know about this stringification, so its custom parser
tried to parse the argument(s) passed to the macro as if they were
normal function arguments.

That means ClangFormat currently incorrectly inserts whitespace
between `NS_SWIFT_NAME` arguments with colons and dots, so:

```
extern UIWindow *MainWindow(void) NS_SWIFT_NAME(getter:MyHelper.mainWindow());
```

becomes:

```
extern UIWindow *MainWindow(void) NS_SWIFT_NAME(getter : MyHelper.mainWindow());
```

which clang treats as a parser error:

```
error: 'swift_name' attribute has invalid identifier for context name 
[-Werror,-Wswift-name-attribute]
```

Thankfully, D82620 recently added the ability to treat specific macros
as "whitespace sensitive", meaning their arguments are implicitly
treated as strings (so whitespace is not added anywhere inside).

This diff adds `NS_SWIFT_NAME` and `CF_SWIFT_NAME` to
`WhitespaceSensitiveMacros` so their arguments are implicitly treated
as whitespace-sensitive.

Test Plan:
  New tests added. Ran tests with:
  % ninja FormatTests && ./tools/clang/unittests/Format/FormatTests

Reviewed By: sammccall

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

Added: 


Modified: 
clang/lib/Format/Format.cpp
clang/unittests/Format/FormatTestObjC.cpp

Removed: 




diff  --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 8e4f65ace3f0..f2215e255c2b 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -964,6 +964,8 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind 
Language) {
   LLVMStyle.WhitespaceSensitiveMacros.push_back("STRINGIZE");
   LLVMStyle.WhitespaceSensitiveMacros.push_back("PP_STRINGIZE");
   LLVMStyle.WhitespaceSensitiveMacros.push_back("BOOST_PP_STRINGIZE");
+  LLVMStyle.WhitespaceSensitiveMacros.push_back("NS_SWIFT_NAME");
+  LLVMStyle.WhitespaceSensitiveMacros.push_back("CF_SWIFT_NAME");
 
   // Defaults that 
diff er when not C++.
   if (Language == FormatStyle::LK_TableGen) {

diff  --git a/clang/unittests/Format/FormatTestObjC.cpp 
b/clang/unittests/Format/FormatTestObjC.cpp
index 28d33dcdaa54..f3be942ab913 100644
--- a/clang/unittests/Format/FormatTestObjC.cpp
+++ b/clang/unittests/Format/FormatTestObjC.cpp
@@ -1024,6 +1024,12 @@ TEST_F(FormatTestObjC, ObjCSnippets) {
   verifyFormat("@property(assign, nonatomic) CGFloat hoverAlpha;");
   verifyFormat("@property(assign, getter=isEditable) BOOL editable;");
 
+  verifyFormat("extern UIWindow *MainWindow(void) "
+   "NS_SWIFT_NAME(getter:MyHelper.mainWindow());");
+
+  verifyFormat("extern UIWindow *MainWindow(void) "
+   "CF_SWIFT_NAME(getter:MyHelper.mainWindow());");
+
   Style.ColumnLimit = 50;
   verifyFormat("@interface Foo\n"
"- (void)doStuffWithFoo:(id)name\n"



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


[PATCH] D89425: [Format/ObjC] Add NS_SWIFT_NAME() and CF_SWIFT_NAME() to WhitespaceSensitiveMacros

2020-10-14 Thread Ben Hamilton via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe7b4feea8e1b: [Format/ObjC] Add NS_SWIFT_NAME() and 
CF_SWIFT_NAME() to… (authored by benhamilton).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89425

Files:
  clang/lib/Format/Format.cpp
  clang/unittests/Format/FormatTestObjC.cpp


Index: clang/unittests/Format/FormatTestObjC.cpp
===
--- clang/unittests/Format/FormatTestObjC.cpp
+++ clang/unittests/Format/FormatTestObjC.cpp
@@ -1024,6 +1024,12 @@
   verifyFormat("@property(assign, nonatomic) CGFloat hoverAlpha;");
   verifyFormat("@property(assign, getter=isEditable) BOOL editable;");
 
+  verifyFormat("extern UIWindow *MainWindow(void) "
+   "NS_SWIFT_NAME(getter:MyHelper.mainWindow());");
+
+  verifyFormat("extern UIWindow *MainWindow(void) "
+   "CF_SWIFT_NAME(getter:MyHelper.mainWindow());");
+
   Style.ColumnLimit = 50;
   verifyFormat("@interface Foo\n"
"- (void)doStuffWithFoo:(id)name\n"
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -964,6 +964,8 @@
   LLVMStyle.WhitespaceSensitiveMacros.push_back("STRINGIZE");
   LLVMStyle.WhitespaceSensitiveMacros.push_back("PP_STRINGIZE");
   LLVMStyle.WhitespaceSensitiveMacros.push_back("BOOST_PP_STRINGIZE");
+  LLVMStyle.WhitespaceSensitiveMacros.push_back("NS_SWIFT_NAME");
+  LLVMStyle.WhitespaceSensitiveMacros.push_back("CF_SWIFT_NAME");
 
   // Defaults that differ when not C++.
   if (Language == FormatStyle::LK_TableGen) {


Index: clang/unittests/Format/FormatTestObjC.cpp
===
--- clang/unittests/Format/FormatTestObjC.cpp
+++ clang/unittests/Format/FormatTestObjC.cpp
@@ -1024,6 +1024,12 @@
   verifyFormat("@property(assign, nonatomic) CGFloat hoverAlpha;");
   verifyFormat("@property(assign, getter=isEditable) BOOL editable;");
 
+  verifyFormat("extern UIWindow *MainWindow(void) "
+   "NS_SWIFT_NAME(getter:MyHelper.mainWindow());");
+
+  verifyFormat("extern UIWindow *MainWindow(void) "
+   "CF_SWIFT_NAME(getter:MyHelper.mainWindow());");
+
   Style.ColumnLimit = 50;
   verifyFormat("@interface Foo\n"
"- (void)doStuffWithFoo:(id)name\n"
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -964,6 +964,8 @@
   LLVMStyle.WhitespaceSensitiveMacros.push_back("STRINGIZE");
   LLVMStyle.WhitespaceSensitiveMacros.push_back("PP_STRINGIZE");
   LLVMStyle.WhitespaceSensitiveMacros.push_back("BOOST_PP_STRINGIZE");
+  LLVMStyle.WhitespaceSensitiveMacros.push_back("NS_SWIFT_NAME");
+  LLVMStyle.WhitespaceSensitiveMacros.push_back("CF_SWIFT_NAME");
 
   // Defaults that differ when not C++.
   if (Language == FormatStyle::LK_TableGen) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D89286: [DebugInfo] Check for templated static data member when adding constant to record static fields

2020-10-14 Thread Amy Huang via Phabricator via cfe-commits
akhuang updated this revision to Diff 298243.
akhuang added a comment.

update test case and add check for dependent values


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89286

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenCXX/debug-info-static-member.cpp


Index: clang/test/CodeGenCXX/debug-info-static-member.cpp
===
--- clang/test/CodeGenCXX/debug-info-static-member.cpp
+++ clang/test/CodeGenCXX/debug-info-static-member.cpp
@@ -1,6 +1,7 @@
 // RUN: %clangxx -target x86_64-unknown-unknown -g %s -emit-llvm -S -o - | 
FileCheck %s
 // RUN: %clangxx -target x86_64-unknown-unknown -g -std=c++98 %s -emit-llvm -S 
-o - | FileCheck %s
 // RUN: %clangxx -target x86_64-unknown-unknown -g -std=c++11 %s -emit-llvm -S 
-o - | FileCheck %s
+// RUN: %clangxx -target x86_64-unknown-unknown -g -std=c++17 %s -emit-llvm -S 
-o - | FileCheck %s --check-prefix=CXX17
 // RUN: %clang_cc1 -triple x86_64-windows-msvc -gcodeview 
-debug-info-kind=limited %s -emit-llvm -o - | FileCheck --check-prefix MSVC %s
 // PR14471
 
@@ -45,6 +46,9 @@
 // CHECK-NOT:  DIFlagFwdDecl
 // CHECK-SAME: ){{$}}
 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "static_decl_templ_var"
+// CHECK-SAME:   extraData: i32 7
+// CXX17: !DIDerivedType(tag: DW_TAG_member, name: 
"static_constexpr_decl_templ_var"
+// CXX17-SAME:   extraData: i32 8
 
 int C::a = 4;
 // CHECK: [[B]] = !DIGlobalVariableExpression(var: [[BV:.*]], expr: 
!DIExpression())
@@ -133,6 +137,9 @@
 template
 struct static_decl_templ {
   static const int static_decl_templ_var = 7;
+#if __cplusplus >= 201703L
+  static constexpr int static_constexpr_decl_templ_var = 8;
+#endif
 };
 
 template
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1415,14 +1415,22 @@
   unsigned LineNumber = getLineNumber(Var->getLocation());
   StringRef VName = Var->getName();
   llvm::Constant *C = nullptr;
-  if (Var->getInit()) {
-const APValue *Value = Var->evaluateValue();
-if (Value) {
-  if (Value->isInt())
-C = llvm::ConstantInt::get(CGM.getLLVMContext(), Value->getInt());
-  if (Value->isFloat())
-C = llvm::ConstantFP::get(CGM.getLLVMContext(), Value->getFloat());
-}
+  APValue *Value = nullptr;
+  if (Var->getInit())
+Value = Var->evaluateValue();
+  else if (auto *TemplateDecl = Var->getInstantiatedFromStaticDataMember()) {
+// Inline static data members might not have an initialization.
+// FIXME: Still doesn't get a value if the initialization is dependent.
+auto *TemplateInit = TemplateDecl->getInit();
+if (TemplateInit && !TemplateInit->isValueDependent())
+  Value = TemplateDecl->evaluateValue();
+  }
+
+  if (Value) {
+if (Value->isInt())
+  C = llvm::ConstantInt::get(CGM.getLLVMContext(), Value->getInt());
+if (Value->isFloat())
+  C = llvm::ConstantFP::get(CGM.getLLVMContext(), Value->getFloat());
   }
 
   llvm::DINode::DIFlags Flags = getAccessFlag(Var->getAccess(), RD);


Index: clang/test/CodeGenCXX/debug-info-static-member.cpp
===
--- clang/test/CodeGenCXX/debug-info-static-member.cpp
+++ clang/test/CodeGenCXX/debug-info-static-member.cpp
@@ -1,6 +1,7 @@
 // RUN: %clangxx -target x86_64-unknown-unknown -g %s -emit-llvm -S -o - | FileCheck %s
 // RUN: %clangxx -target x86_64-unknown-unknown -g -std=c++98 %s -emit-llvm -S -o - | FileCheck %s
 // RUN: %clangxx -target x86_64-unknown-unknown -g -std=c++11 %s -emit-llvm -S -o - | FileCheck %s
+// RUN: %clangxx -target x86_64-unknown-unknown -g -std=c++17 %s -emit-llvm -S -o - | FileCheck %s --check-prefix=CXX17
 // RUN: %clang_cc1 -triple x86_64-windows-msvc -gcodeview -debug-info-kind=limited %s -emit-llvm -o - | FileCheck --check-prefix MSVC %s
 // PR14471
 
@@ -45,6 +46,9 @@
 // CHECK-NOT:  DIFlagFwdDecl
 // CHECK-SAME: ){{$}}
 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "static_decl_templ_var"
+// CHECK-SAME:   extraData: i32 7
+// CXX17: !DIDerivedType(tag: DW_TAG_member, name: "static_constexpr_decl_templ_var"
+// CXX17-SAME:   extraData: i32 8
 
 int C::a = 4;
 // CHECK: [[B]] = !DIGlobalVariableExpression(var: [[BV:.*]], expr: !DIExpression())
@@ -133,6 +137,9 @@
 template
 struct static_decl_templ {
   static const int static_decl_templ_var = 7;
+#if __cplusplus >= 201703L
+  static constexpr int static_constexpr_decl_templ_var = 8;
+#endif
 };
 
 template
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1415,14 +1415,22 @@
   unsigned LineNumber = 

[PATCH] D89427: clang/Frontend: Use MemoryBufferRef in FrontendInputFile (and remove SourceManager::getBuffer)

2020-10-14 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith updated this revision to Diff 298242.
dexonsmith added a comment.

Adding a couple of changes I forgot to stage (remove now-unused `UnownedTag` 
and a minor simplification to `createFileID`).


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

https://reviews.llvm.org/D89427

Files:
  clang/include/clang/Basic/SourceManager.h
  clang/include/clang/Frontend/FrontendAction.h
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/Basic/SourceManager.cpp
  clang/lib/Format/MacroExpander.cpp
  clang/lib/Frontend/ASTUnit.cpp
  clang/lib/Frontend/CompilerInstance.cpp
  clang/lib/Frontend/FrontendAction.cpp
  clang/lib/Frontend/FrontendActions.cpp
  clang/unittests/Format/TestLexer.h

Index: clang/unittests/Format/TestLexer.h
===
--- clang/unittests/Format/TestLexer.h
+++ clang/unittests/Format/TestLexer.h
@@ -62,8 +62,8 @@
   TokenList lex(llvm::StringRef Code) {
 Buffers.push_back(
 llvm::MemoryBuffer::getMemBufferCopy(Code, ""));
-clang::FileID FID = SourceMgr.get().createFileID(SourceManager::Unowned,
- Buffers.back().get());
+clang::FileID FID =
+SourceMgr.get().createFileID(Buffers.back()->getMemBufferRef());
 FormatTokenLexer Lex(SourceMgr.get(), FID, 0, Style, Encoding, Allocator,
  IdentTable);
 auto Result = Lex.lex();
Index: clang/lib/Frontend/FrontendActions.cpp
===
--- clang/lib/Frontend/FrontendActions.cpp
+++ clang/lib/Frontend/FrontendActions.cpp
@@ -261,7 +261,7 @@
 if (FIF.getKind().getFormat() != InputKind::Source || !FIF.isFile()) {
   CI.getDiagnostics().Report(diag::err_module_header_file_not_found)
   << (FIF.isFile() ? FIF.getFile()
-   : FIF.getBuffer()->getBufferIdentifier());
+   : FIF.getBuffer().getBufferIdentifier());
   return true;
 }
 
@@ -275,7 +275,8 @@
 
   // Set that buffer up as our "real" input.
   Inputs.clear();
-  Inputs.push_back(FrontendInputFile(Buffer.get(), Kind, /*IsSystem*/false));
+  Inputs.push_back(
+  FrontendInputFile(Buffer->getMemBufferRef(), Kind, /*IsSystem*/ false));
 
   return GenerateModuleAction::PrepareToExecuteAction(CI);
 }
Index: clang/lib/Frontend/FrontendAction.cpp
===
--- clang/lib/Frontend/FrontendAction.cpp
+++ clang/lib/Frontend/FrontendAction.cpp
@@ -624,7 +624,7 @@
   if (auto *File = OldSM.getFileEntryForID(ID))
 Input = FrontendInputFile(File->getName(), Kind);
   else
-Input = FrontendInputFile(OldSM.getBuffer(ID), Kind);
+Input = FrontendInputFile(OldSM.getBufferOrFake(ID), Kind);
 }
 setCurrentInput(Input, std::move(AST));
   }
Index: clang/lib/Frontend/CompilerInstance.cpp
===
--- clang/lib/Frontend/CompilerInstance.cpp
+++ clang/lib/Frontend/CompilerInstance.cpp
@@ -831,8 +831,7 @@
   : Input.isSystem() ? SrcMgr::C_System : SrcMgr::C_User;
 
   if (Input.isBuffer()) {
-SourceMgr.setMainFileID(SourceMgr.createFileID(SourceManager::Unowned,
-   Input.getBuffer(), Kind));
+SourceMgr.setMainFileID(SourceMgr.createFileID(Input.getBuffer(), Kind));
 assert(SourceMgr.getMainFileID().isValid() &&
"Couldn't establish MainFileID!");
 return true;
Index: clang/lib/Frontend/ASTUnit.cpp
===
--- clang/lib/Frontend/ASTUnit.cpp
+++ clang/lib/Frontend/ASTUnit.cpp
@@ -1468,7 +1468,7 @@
 if (Input.isFile())
   return Input.getFile();
 else
-  return Input.getBuffer()->getBufferIdentifier();
+  return Input.getBuffer().getBufferIdentifier();
   }
 
   if (SourceMgr) {
Index: clang/lib/Format/MacroExpander.cpp
===
--- clang/lib/Format/MacroExpander.cpp
+++ clang/lib/Format/MacroExpander.cpp
@@ -136,8 +136,7 @@
 void MacroExpander::parseDefinition(const std::string ) {
   Buffers.push_back(
   llvm::MemoryBuffer::getMemBufferCopy(Macro, ""));
-  clang::FileID FID =
-  SourceMgr.createFileID(SourceManager::Unowned, Buffers.back().get());
+  clang::FileID FID = SourceMgr.createFileID(Buffers.back()->getMemBufferRef());
   FormatTokenLexer Lex(SourceMgr, FID, 0, Style, encoding::Encoding_UTF8,
Allocator, IdentTable);
   const auto Tokens = Lex.lex();
Index: clang/lib/Basic/SourceManager.cpp
===
--- clang/lib/Basic/SourceManager.cpp
+++ clang/lib/Basic/SourceManager.cpp
@@ -443,14 +443,13 @@
 
 /// Create a new ContentCache for the specified memory buffer.
 /// This does no caching.
-const ContentCache *

[PATCH] D89276: Support ObjC in IncludeInserter

2020-10-14 Thread Joe Turner via Phabricator via cfe-commits
compositeprimes updated this revision to Diff 298241.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89276

Files:
  clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp
  clang-tools-extra/clang-tidy/utils/IncludeSorter.h
  clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp
@@ -28,8 +28,10 @@
 
 class IncludeInserterCheckBase : public ClangTidyCheck {
 public:
-  IncludeInserterCheckBase(StringRef CheckName, ClangTidyContext *Context)
-  : ClangTidyCheck(CheckName, Context) {}
+  IncludeInserterCheckBase(StringRef CheckName, ClangTidyContext *Context,
+   utils::IncludeSorter::IncludeStyle Style =
+   utils::IncludeSorter::IS_Google)
+  : ClangTidyCheck(CheckName, Context), Inserter(Style) {}
 
   void registerPPCallbacks(const SourceManager , Preprocessor *PP,
Preprocessor *ModuleExpanderPP) override {
@@ -50,7 +52,7 @@
 
   virtual std::vector headersToInclude() const = 0;
 
-  utils::IncludeInserter Inserter{utils::IncludeSorter::IS_Google};
+  utils::IncludeInserter Inserter;
 };
 
 class NonSystemHeaderInserterCheck : public IncludeInserterCheckBase {
@@ -111,6 +113,42 @@
   }
 };
 
+class ObjCEarlyInAlphabetHeaderInserterCheck : public IncludeInserterCheckBase {
+public:
+  ObjCEarlyInAlphabetHeaderInserterCheck(StringRef CheckName,
+ ClangTidyContext *Context)
+  : IncludeInserterCheckBase(CheckName, Context,
+ utils::IncludeSorter::IS_Google_ObjC) {}
+
+  std::vector headersToInclude() const override {
+return {"a/header.h"};
+  }
+};
+
+class ObjCCategoryHeaderInserterCheck : public IncludeInserterCheckBase {
+public:
+  ObjCCategoryHeaderInserterCheck(StringRef CheckName,
+  ClangTidyContext *Context)
+  : IncludeInserterCheckBase(CheckName, Context,
+ utils::IncludeSorter::IS_Google_ObjC) {}
+
+  std::vector headersToInclude() const override {
+return {"clang_tidy/tests/insert_includes_test_header+foo.h"};
+  }
+};
+
+class ObjCGeneratedHeaderInserterCheck : public IncludeInserterCheckBase {
+public:
+  ObjCGeneratedHeaderInserterCheck(StringRef CheckName,
+   ClangTidyContext *Context)
+  : IncludeInserterCheckBase(CheckName, Context,
+ utils::IncludeSorter::IS_Google_ObjC) {}
+
+  std::vector headersToInclude() const override {
+return {"clang_tidy/tests/generated_file.proto.h"};
+  }
+};
+
 template 
 std::string runCheckOnCode(StringRef Code, StringRef Filename) {
   std::vector Errors;
@@ -120,12 +158,20 @@
   {"clang_tidy/tests/"
"insert_includes_test_header.h",
"\n"},
+  // ObjC category.
+  {"clang_tidy/tests/"
+   "insert_includes_test_header+foo.h",
+   "\n"},
   // Non system headers
   {"a/header.h", "\n"},
   {"path/to/a/header.h", "\n"},
   {"path/to/z/header.h", "\n"},
   {"path/to/header.h", "\n"},
   {"path/to/header2.h", "\n"},
+  // Generated headers
+  {"clang_tidy/tests/"
+   "generated_file.proto.h",
+   "\n"},
   // Fake system headers.
   {"stdlib.h", "\n"},
   {"unistd.h", "\n"},
@@ -160,9 +206,9 @@
   int a = 0;
 })";
 
-  EXPECT_EQ(PostCode, runCheckOnCode(
-  PreCode, "clang_tidy/tests/"
-   "insert_includes_test_input2.cc"));
+  EXPECT_EQ(PostCode,
+runCheckOnCode(
+PreCode, "clang_tidy/tests/insert_includes_test_input2.cc"));
 }
 
 TEST(IncludeInserterTest, InsertMultipleIncludesAndDeduplicate) {
@@ -191,9 +237,9 @@
   int a = 0;
 })";
 
-  EXPECT_EQ(PostCode, runCheckOnCode(
-  PreCode, "clang_tidy/tests/"
-   "insert_includes_test_input2.cc"));
+  EXPECT_EQ(PostCode,
+runCheckOnCode(
+PreCode, 

[PATCH] D89414: clang/StaticAnalyzer: Stop using SourceManager::getBuffer

2020-10-14 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus accepted this revision.
Szelethus added a comment.
This revision is now accepted and ready to land.

Sounds good! Thanks!


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

https://reviews.llvm.org/D89414

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


[PATCH] D89427: clang/Frontend: Use MemoryBufferRef in FrontendInputFile (and remove SourceManager::getBuffer)

2020-10-14 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith created this revision.
dexonsmith added a reviewer: arphaman.
Herald added a subscriber: ributzka.
dexonsmith requested review of this revision.

In order to drop the final callers to `SourceManager::getBuffer`, change
`FrontendInputFile` to use `Optional`. Also updated
the "unowned" version of `SourceManager::createFileID` to take a
`MemoryBufferRef` (it now calls `MemoryBuffer::getMemBuffer`, which
creates a `MemoryBuffer` that does not own the buffer data).


https://reviews.llvm.org/D89427

Files:
  clang/include/clang/Basic/SourceManager.h
  clang/include/clang/Frontend/FrontendAction.h
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/Basic/SourceManager.cpp
  clang/lib/Format/MacroExpander.cpp
  clang/lib/Frontend/ASTUnit.cpp
  clang/lib/Frontend/CompilerInstance.cpp
  clang/lib/Frontend/FrontendAction.cpp
  clang/lib/Frontend/FrontendActions.cpp
  clang/unittests/Format/TestLexer.h

Index: clang/unittests/Format/TestLexer.h
===
--- clang/unittests/Format/TestLexer.h
+++ clang/unittests/Format/TestLexer.h
@@ -62,8 +62,8 @@
   TokenList lex(llvm::StringRef Code) {
 Buffers.push_back(
 llvm::MemoryBuffer::getMemBufferCopy(Code, ""));
-clang::FileID FID = SourceMgr.get().createFileID(SourceManager::Unowned,
- Buffers.back().get());
+clang::FileID FID =
+SourceMgr.get().createFileID(Buffers.back()->getMemBufferRef());
 FormatTokenLexer Lex(SourceMgr.get(), FID, 0, Style, Encoding, Allocator,
  IdentTable);
 auto Result = Lex.lex();
Index: clang/lib/Frontend/FrontendActions.cpp
===
--- clang/lib/Frontend/FrontendActions.cpp
+++ clang/lib/Frontend/FrontendActions.cpp
@@ -261,7 +261,7 @@
 if (FIF.getKind().getFormat() != InputKind::Source || !FIF.isFile()) {
   CI.getDiagnostics().Report(diag::err_module_header_file_not_found)
   << (FIF.isFile() ? FIF.getFile()
-   : FIF.getBuffer()->getBufferIdentifier());
+   : FIF.getBuffer().getBufferIdentifier());
   return true;
 }
 
@@ -275,7 +275,8 @@
 
   // Set that buffer up as our "real" input.
   Inputs.clear();
-  Inputs.push_back(FrontendInputFile(Buffer.get(), Kind, /*IsSystem*/false));
+  Inputs.push_back(
+  FrontendInputFile(Buffer->getMemBufferRef(), Kind, /*IsSystem*/ false));
 
   return GenerateModuleAction::PrepareToExecuteAction(CI);
 }
Index: clang/lib/Frontend/FrontendAction.cpp
===
--- clang/lib/Frontend/FrontendAction.cpp
+++ clang/lib/Frontend/FrontendAction.cpp
@@ -624,7 +624,7 @@
   if (auto *File = OldSM.getFileEntryForID(ID))
 Input = FrontendInputFile(File->getName(), Kind);
   else
-Input = FrontendInputFile(OldSM.getBuffer(ID), Kind);
+Input = FrontendInputFile(OldSM.getBufferOrFake(ID), Kind);
 }
 setCurrentInput(Input, std::move(AST));
   }
Index: clang/lib/Frontend/CompilerInstance.cpp
===
--- clang/lib/Frontend/CompilerInstance.cpp
+++ clang/lib/Frontend/CompilerInstance.cpp
@@ -831,8 +831,7 @@
   : Input.isSystem() ? SrcMgr::C_System : SrcMgr::C_User;
 
   if (Input.isBuffer()) {
-SourceMgr.setMainFileID(SourceMgr.createFileID(SourceManager::Unowned,
-   Input.getBuffer(), Kind));
+SourceMgr.setMainFileID(SourceMgr.createFileID(Input.getBuffer(), Kind));
 assert(SourceMgr.getMainFileID().isValid() &&
"Couldn't establish MainFileID!");
 return true;
Index: clang/lib/Frontend/ASTUnit.cpp
===
--- clang/lib/Frontend/ASTUnit.cpp
+++ clang/lib/Frontend/ASTUnit.cpp
@@ -1468,7 +1468,7 @@
 if (Input.isFile())
   return Input.getFile();
 else
-  return Input.getBuffer()->getBufferIdentifier();
+  return Input.getBuffer().getBufferIdentifier();
   }
 
   if (SourceMgr) {
Index: clang/lib/Format/MacroExpander.cpp
===
--- clang/lib/Format/MacroExpander.cpp
+++ clang/lib/Format/MacroExpander.cpp
@@ -136,8 +136,7 @@
 void MacroExpander::parseDefinition(const std::string ) {
   Buffers.push_back(
   llvm::MemoryBuffer::getMemBufferCopy(Macro, ""));
-  clang::FileID FID =
-  SourceMgr.createFileID(SourceManager::Unowned, Buffers.back().get());
+  clang::FileID FID = SourceMgr.createFileID(Buffers.back()->getMemBufferRef());
   FormatTokenLexer Lex(SourceMgr, FID, 0, Style, encoding::Encoding_UTF8,
Allocator, IdentTable);
   const auto Tokens = Lex.lex();
Index: clang/lib/Basic/SourceManager.cpp
===
--- 

[clang] 0ff9116 - Register TargetCXXABI.def as a textual header

2020-10-14 Thread Adrian Prantl via cfe-commits

Author: Adrian Prantl
Date: 2020-10-14T14:20:39-07:00
New Revision: 0ff9116b36781d6fa61c25841edd53dc8f366bec

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

LOG: Register TargetCXXABI.def as a textual header

Added: 


Modified: 
clang/include/clang/module.modulemap

Removed: 




diff  --git a/clang/include/clang/module.modulemap 
b/clang/include/clang/module.modulemap
index 13d4dbf9dc2e..cee7ed3d7de3 100644
--- a/clang/include/clang/module.modulemap
+++ b/clang/include/clang/module.modulemap
@@ -63,6 +63,7 @@ module Clang_Basic {
   textual header "Basic/OpenMPKinds.def"
   textual header "Basic/OperatorKinds.def"
   textual header "Basic/Sanitizers.def"
+  textual header "Basic/TargetCXXABI.def"
   textual header "Basic/TokenKinds.def"
   textual header "Basic/X86Target.def"
 



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


[PATCH] D85576: [clang][Fuchsia] Add relative-vtables multilib

2020-10-14 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan added a comment.

> This change implement a slightly different approach from what we discussed, 
> which is providing an Itanium-compatible (that is `-fc++abi=itanium`) 
> multilib for compatibility with other compilers, and then enabling relative 
> vtables by default. Unless there's a strong reason not to take that approach, 
> that's the direction I'd prefer.

Ah, yeah I just forgot about that. Will update accoringly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85576

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


Re: [clang] 683b308 - [clang] Add -fc++-abi= flag for specifying which C++ ABI to use

2020-10-14 Thread Richard Smith via cfe-commits
On Wed, 14 Oct 2020 at 12:31, Leonard Chan via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

>
> Author: Leonard Chan
> Date: 2020-10-14T12:31:21-07:00
> New Revision: 683b308c07bf827255fe1403056413f790e03729
>
> URL:
> https://github.com/llvm/llvm-project/commit/683b308c07bf827255fe1403056413f790e03729
> DIFF:
> https://github.com/llvm/llvm-project/commit/683b308c07bf827255fe1403056413f790e03729.diff
>
> LOG: [clang] Add -fc++-abi= flag for specifying which C++ ABI to use
>
> This implements the flag proposed in RFC
> http://lists.llvm.org/pipermail/cfe-dev/2020-August/066437.html.
>
> The goal is to add a way to override the default target C++ ABI through
> a compiler flag. This makes it easier to test and transition between
> different
> C++ ABIs through compile flags rather than build flags.
>
> In this patch:
> - Store `-fc++-abi=` in a LangOpt. This isn't stored in a
>   CodeGenOpt because there are instances outside of codegen where Clang
>   needs to know what the ABI is (particularly through
>   ASTContext::createCXXABI), and we should be able to override the
>   target default if the flag is provided at that point.
> - Expose the existing ABIs in TargetCXXABI as values that can be passed
>   through this flag.
>   - Create a .def file for these ABIs to make it easier to check flag
> values.
>   - Add an error for diagnosing bad ABI flag values.
>
> Differential Revision: https://reviews.llvm.org/D85802
>
> Added:
> clang/include/clang/Basic/TargetCXXABI.def
> clang/test/Frontend/invalid-cxx-abi.cpp
>
> Modified:
> clang/include/clang/AST/ASTContext.h
> clang/include/clang/Basic/DiagnosticDriverKinds.td
> clang/include/clang/Basic/LangOptions.h
> clang/include/clang/Basic/TargetCXXABI.h
> clang/include/clang/Driver/Options.td
> clang/lib/AST/ASTContext.cpp
> clang/lib/CodeGen/CodeGenModule.cpp
> clang/lib/CodeGen/ItaniumCXXABI.cpp
> clang/lib/Driver/ToolChains/Clang.cpp
> clang/lib/Frontend/CompilerInvocation.cpp
>
> Removed:
>
>
>
>
> 
> diff  --git a/clang/include/clang/AST/ASTContext.h
> b/clang/include/clang/AST/ASTContext.h
> index 3f4079e2569b..e5c80866a0a9 100644
> --- a/clang/include/clang/AST/ASTContext.h
> +++ b/clang/include/clang/AST/ASTContext.h
> @@ -39,6 +39,7 @@
>  #include "clang/Basic/SanitizerBlacklist.h"
>  #include "clang/Basic/SourceLocation.h"
>  #include "clang/Basic/Specifiers.h"
> +#include "clang/Basic/TargetCXXABI.h"
>  #include "clang/Basic/XRayLists.h"
>  #include "llvm/ADT/APSInt.h"
>  #include "llvm/ADT/ArrayRef.h"
> @@ -697,6 +698,11 @@ class ASTContext : public RefCountedBase {
>  return FullSourceLoc(Loc,SourceMgr);
>}
>
> +  /// Return the C++ ABI kind that should be used. The C++ ABI can be
> overriden
> +  /// at compile time with `-fc++-abi=`. If this is not provided, we
> instead use
> +  /// the default ABI set by the target.
> +  TargetCXXABI::Kind getCXXABIKind() const;
> +
>/// All comments in this translation unit.
>RawCommentList Comments;
>
>
> diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td
> b/clang/include/clang/Basic/DiagnosticDriverKinds.td
> index 29bc19e5a84e..f1b3d4d9087e 100644
> --- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
> +++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
> @@ -524,4 +524,6 @@ def err_drv_invalid_object_mode : Error<"OBJECT_MODE
> setting %0 is not recognize
>
>  def err_drv_invalid_sve_vector_bits : Error<
>"'-msve-vector-bits' is not supported without SVE enabled">;
> +
> +def err_invalid_cxx_abi : Error<"Invalid C++ ABI name '%0'">;
>

Diagnostics should start with a lowercase letter.


>  }
>
> diff  --git a/clang/include/clang/Basic/LangOptions.h
> b/clang/include/clang/Basic/LangOptions.h
> index 84d25c359c55..147fab614308 100644
> --- a/clang/include/clang/Basic/LangOptions.h
> +++ b/clang/include/clang/Basic/LangOptions.h
> @@ -18,6 +18,7 @@
>  #include "clang/Basic/LLVM.h"
>  #include "clang/Basic/ObjCRuntime.h"
>  #include "clang/Basic/Sanitizers.h"
> +#include "clang/Basic/TargetCXXABI.h"
>  #include "clang/Basic/Visibility.h"
>  #include "llvm/ADT/FloatingPointMode.h"
>  #include "llvm/ADT/StringRef.h"
> @@ -294,6 +295,10 @@ class LangOptions : public LangOptionsBase {
>/// host code generation.
>std::string OMPHostIRFile;
>
> +  /// C++ ABI to compile with, if specified by the frontend through
> -fc++-abi=.
> +  /// This overrides the default ABI used by the target.
> +  llvm::Optional CXXABI;
> +
>/// Indicates whether the front-end is explicitly told that the
>/// input is a header file (i.e. -x c-header).
>bool IsHeaderFile = false;
>
> diff  --git a/clang/include/clang/Basic/TargetCXXABI.def
> b/clang/include/clang/Basic/TargetCXXABI.def
> new file mode 100644
> index ..0ae0bb555f60
> --- /dev/null
> +++ b/clang/include/clang/Basic/TargetCXXABI.def
> @@ -0,0 +1,129 @@
> +//===--- 

[PATCH] D89425: [Format/ObjC] Add NS_SWIFT_NAME() and CF_SWIFT_NAME() to WhitespaceSensitiveMacros

2020-10-14 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton created this revision.
benhamilton added reviewers: sammccall, JakeMerdichAMD, curdeius.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
benhamilton requested review of this revision.

The argument passed to the preprocessor macros `NS_SWIFT_NAME(x)` and
`CF_SWIFT_NAME(x)` is stringified before passing to
`__attribute__((swift_name("x")))`.

ClangFormat didn't know about this stringification, so its custom parser
tried to parse the argument(s) passed to the macro as if they were
normal function arguments.

That means ClangFormat currently incorrectly inserts whitespace
between `NS_SWIFT_NAME` arguments with colons and dots, so:

  extern UIWindow *MainWindow(void) NS_SWIFT_NAME(getter:MyHelper.mainWindow());

becomes:

  extern UIWindow *MainWindow(void) NS_SWIFT_NAME(getter : 
MyHelper.mainWindow());

which clang treats as a parser error:

  error: 'swift_name' attribute has invalid identifier for context name 
[-Werror,-Wswift-name-attribute]

Thankfully, D82620  recently added the ability 
to treat specific macros
as "whitespace sensitive", meaning their arguments are implicitly
treated as strings (so whitespace is not added anywhere inside).

This diff adds `NS_SWIFT_NAME` and `CF_SWIFT_NAME` to
`WhitespaceSensitiveMacros` so their arguments are implicitly treated
as whitespace-sensitive.

Test Plan:

  New tests added. Ran tests with:
  % ninja FormatTests && ./tools/clang/unittests/Format/FormatTests


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D89425

Files:
  clang/lib/Format/Format.cpp
  clang/unittests/Format/FormatTestObjC.cpp


Index: clang/unittests/Format/FormatTestObjC.cpp
===
--- clang/unittests/Format/FormatTestObjC.cpp
+++ clang/unittests/Format/FormatTestObjC.cpp
@@ -1024,6 +1024,12 @@
   verifyFormat("@property(assign, nonatomic) CGFloat hoverAlpha;");
   verifyFormat("@property(assign, getter=isEditable) BOOL editable;");
 
+  verifyFormat("extern UIWindow *MainWindow(void) "
+   "NS_SWIFT_NAME(getter:MyHelper.mainWindow());");
+
+  verifyFormat("extern UIWindow *MainWindow(void) "
+   "CF_SWIFT_NAME(getter:MyHelper.mainWindow());");
+
   Style.ColumnLimit = 50;
   verifyFormat("@interface Foo\n"
"- (void)doStuffWithFoo:(id)name\n"
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -964,6 +964,8 @@
   LLVMStyle.WhitespaceSensitiveMacros.push_back("STRINGIZE");
   LLVMStyle.WhitespaceSensitiveMacros.push_back("PP_STRINGIZE");
   LLVMStyle.WhitespaceSensitiveMacros.push_back("BOOST_PP_STRINGIZE");
+  LLVMStyle.WhitespaceSensitiveMacros.push_back("NS_SWIFT_NAME");
+  LLVMStyle.WhitespaceSensitiveMacros.push_back("CF_SWIFT_NAME");
 
   // Defaults that differ when not C++.
   if (Language == FormatStyle::LK_TableGen) {


Index: clang/unittests/Format/FormatTestObjC.cpp
===
--- clang/unittests/Format/FormatTestObjC.cpp
+++ clang/unittests/Format/FormatTestObjC.cpp
@@ -1024,6 +1024,12 @@
   verifyFormat("@property(assign, nonatomic) CGFloat hoverAlpha;");
   verifyFormat("@property(assign, getter=isEditable) BOOL editable;");
 
+  verifyFormat("extern UIWindow *MainWindow(void) "
+   "NS_SWIFT_NAME(getter:MyHelper.mainWindow());");
+
+  verifyFormat("extern UIWindow *MainWindow(void) "
+   "CF_SWIFT_NAME(getter:MyHelper.mainWindow());");
+
   Style.ColumnLimit = 50;
   verifyFormat("@interface Foo\n"
"- (void)doStuffWithFoo:(id)name\n"
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -964,6 +964,8 @@
   LLVMStyle.WhitespaceSensitiveMacros.push_back("STRINGIZE");
   LLVMStyle.WhitespaceSensitiveMacros.push_back("PP_STRINGIZE");
   LLVMStyle.WhitespaceSensitiveMacros.push_back("BOOST_PP_STRINGIZE");
+  LLVMStyle.WhitespaceSensitiveMacros.push_back("NS_SWIFT_NAME");
+  LLVMStyle.WhitespaceSensitiveMacros.push_back("CF_SWIFT_NAME");
 
   // Defaults that differ when not C++.
   if (Language == FormatStyle::LK_TableGen) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D89372: [OpenCL] Remove unused extensions

2020-10-14 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added inline comments.



Comment at: clang/include/clang/Basic/OpenCLExtensions.def:16
 //
 // If the extensions are to be enumerated without the supported OpenCL version,
 // define OPENCLEXT(ext) where ext is the name of the extension.

Can you add a comment here referring the spec about "Every extension which 
affects the OpenCL language semantics, syntax or adds built-in functions to the 
language must create a preprocessor #define that matches the extension name 
string." and therefore only extensions "which affects the OpenCL language 
semantics, syntax or adds built-in functions to the language" are defined in 
this file. Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89372

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


[PATCH] D89221: [clang-rename] Fix rename on function template specializations.

2020-10-14 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev requested changes to this revision.
kbobyrev added a comment.
This revision now requires changes to proceed.

And indeed I did miss that :( Thank you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89221

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


[PATCH] D89372: [OpenCL] Remove unused extensions

2020-10-14 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

In D89372#2330868 , @Anastasia wrote:

>> Does the spec requires cl_* macro to be defined if an extension is enabled?
>
> The extension spec currently has:
>
>   Every extension which affects the OpenCL language semantics, syntax or adds 
> built-in functions to the language must create a preprocessor #define that 
> matches the extension name string. This #define would be available in the 
> language if and only if the extension is supported on a given implementation.
>
> Those extensions don't affect the language or add any BIFs so my reading from 
> this the macro shouldn't be available.

Thanks. That sounds reasonable.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89372

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


[PATCH] D89286: [DebugInfo] Check for templated static data member when adding constant to record static fields

2020-10-14 Thread Amy Huang via Phabricator via cfe-commits
akhuang added a subscriber: rsmith.
akhuang added inline comments.



Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:1421-1425
+  else if (auto *TemplateDecl = Var->getInstantiatedFromStaticDataMember()) {
+// Inline static data members might not have an initialization.
+if (TemplateDecl->getInit())
+  Value = TemplateDecl->evaluateValue();
+  }

dblaikie wrote:
> I'd suspect this might not be the most general solution - because it's 
> retrieving the value from the original template static member. Two issues 
> come to mind:
> 1) If the initialization is dependent or otherwise not knowable at 
> compile-time, does this code at least not crash (I assume "evaluateValue" 
> returns nullptr if the value can't be evaluated for whatever reason)
> 2) If the initialization is dependent, it might still be knowable, eg:
> 
> ```
> template
> struct static_decl_templ {
>   static constexpr int static_constexpr_decl_templ_var = sizeof(T);
> };
> ```
> 
> I'm guessing this patch as-is doesn't provide a value in this case, but it 
> should be achievable, I would guess/hope/imagine - but don't really know 
> exactly how to do that off-hand. (@zygoloid would know - but maybe a bit of 
> looking around will find it if/before he has a chance to weigh in here)
> 
> 
@rsmith 

Actually, can we just instantiate the initializer for static constexpr data 
members? 

currently 
[[https://github.com/llvm/llvm-project/blob/683b308c07bf827255fe1403056413f790e03729/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp#L5062|
 it delays creating the initializer for inline static data members ]]; can we 
not do that if it's a constexpr?



Comment at: clang/test/CodeGenCXX/debug-info-static-member.cpp:140-144
+#if __cplusplus >= 201103L
+  static constexpr int static_constexpr_decl_templ_var = 8;
+#else
+  static const int static_constexpr_decl_templ_var = 8;
+#endif

dblaikie wrote:
> I guess the non-11 version of this variable is intended as a stub to make the 
> test across different language levels simpler?
> 
> I think it might be better to make that more explicit - rather than having a 
> variable with "constexpr" in the name that isn't actually constexpr. I'd say 
> only add the variable under that macro condition - but change the test to use 
> multiple --check-prefixes, and the check for this variable to use a CPP11 
> prefix or something like that.
> 
> Hmm, I'm slightly confused now that I Think about it - it looks like the 
> macro is about testing if the version is >= 11. But the change also adds a 
> test for C++17? Is C++17 likely to be any different than C++11 for any of 
> this? (or C++20 for that matter) if it's not any different, I'd probably 
> leave the 17 case out & expect the 11 case is sufficient coverage.
Yeah, it was intended as a stub, but I can remove that part.

I added c++17 because it appears that in c++17 (and for MS targets) we make 
constexpr data members implicitly inline, which is why the initializer is not 
being instantiated.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89286

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


[PATCH] D85576: [clang][Fuchsia] Add relative-vtables multilib

2020-10-14 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

In D85576#2330923 , @leonardchan wrote:

> This should also be ready now that https://reviews.llvm.org/D85802 landed, 
> unless we don't want to submit this *right* now so the clang builders don't 
> build these multilibs that won't be used yet?

This change implement a slightly different approach from what we discussed, 
which is providing an Itanium-compatible (that is `-fc++abi=itanium`) multilib 
for compatibility with other compilers, and then enabling relative vtables by 
default. Unless there's a strong reason not to take that approach, that's the 
direction I'd prefer.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85576

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


[clang] 633f9fc - Make header self-contained. NFC.

2020-10-14 Thread Benjamin Kramer via cfe-commits

Author: Benjamin Kramer
Date: 2020-10-14T22:03:19+02:00
New Revision: 633f9fcb820bf01d59cdcdd8038889eec61cf2f2

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

LOG: Make header self-contained. NFC.

Added: 


Modified: 
clang/include/clang/Basic/TargetCXXABI.h

Removed: 




diff  --git a/clang/include/clang/Basic/TargetCXXABI.h 
b/clang/include/clang/Basic/TargetCXXABI.h
index ed6438a9b236..d987d1b0eda0 100644
--- a/clang/include/clang/Basic/TargetCXXABI.h
+++ b/clang/include/clang/Basic/TargetCXXABI.h
@@ -15,6 +15,7 @@
 #ifndef LLVM_CLANG_BASIC_TARGETCXXABI_H
 #define LLVM_CLANG_BASIC_TARGETCXXABI_H
 
+#include "clang/Basic/LLVM.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/Support/ErrorHandling.h"
 



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


[PATCH] D89348: clang/Basic: Replace ContentCache::getBuffer with Optional semantics

2020-10-14 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd758f79e5d38: clang/Basic: Replace ContentCache::getBuffer 
with Optional semantics (authored by dexonsmith).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D89348?vs=298145=298227#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89348

Files:
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang/include/clang/Basic/SourceManager.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/Basic/SourceManager.cpp
  clang/lib/Serialization/ASTWriter.cpp

Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -2002,9 +2002,9 @@
 // We add one to the size so that we capture the trailing NULL
 // that is required by llvm::MemoryBuffer::getMemBuffer (on
 // the reader side).
-const llvm::MemoryBuffer *Buffer =
-Content->getBuffer(PP.getDiagnostics(), PP.getFileManager());
-StringRef Name = Buffer->getBufferIdentifier();
+llvm::Optional Buffer =
+Content->getBufferOrNone(PP.getDiagnostics(), PP.getFileManager());
+StringRef Name = Buffer ? Buffer->getBufferIdentifier() : "";
 Stream.EmitRecordWithBlob(SLocBufferAbbrv, Record,
   StringRef(Name.data(), Name.size() + 1));
 EmitBlob = true;
@@ -2016,8 +2016,10 @@
   if (EmitBlob) {
 // Include the implicit terminating null character in the on-disk buffer
 // if we're writing it uncompressed.
-const llvm::MemoryBuffer *Buffer =
-Content->getBuffer(PP.getDiagnostics(), PP.getFileManager());
+llvm::Optional Buffer =
+Content->getBufferOrNone(PP.getDiagnostics(), PP.getFileManager());
+if (!Buffer)
+  Buffer = llvm::MemoryBufferRef("<<>>", "");
 StringRef Blob(Buffer->getBufferStart(), Buffer->getBufferSize() + 1);
 emitBlob(Stream, Blob, SLocBufferBlobCompressedAbbrv,
  SLocBufferBlobAbbrv);
Index: clang/lib/Basic/SourceManager.cpp
===
--- clang/lib/Basic/SourceManager.cpp
+++ clang/lib/Basic/SourceManager.cpp
@@ -118,18 +118,25 @@
   return InvalidBOM;
 }
 
-const llvm::MemoryBuffer *ContentCache::getBuffer(DiagnosticsEngine ,
-  FileManager ,
-  SourceLocation Loc,
-  bool *Invalid) const {
+llvm::Optional
+ContentCache::getBufferOrNone(DiagnosticsEngine , FileManager ,
+  SourceLocation Loc) const {
+  if (auto *B = getBufferPointer(Diag, FM, Loc))
+return B->getMemBufferRef();
+  return None;
+}
+
+const llvm::MemoryBuffer *
+ContentCache::getBufferPointer(DiagnosticsEngine , FileManager ,
+   SourceLocation Loc) const {
   // Lazily create the Buffer for ContentCaches that wrap files.  If we already
   // computed it, just return what we have.
-  if (Buffer.getPointer() || !ContentsEntry) {
-if (Invalid)
-  *Invalid = isBufferInvalid();
-
-return Buffer.getPointer();
-  }
+  if (isBufferInvalid())
+return nullptr;
+  if (auto *B = Buffer.getPointer())
+return B;
+  if (!ContentsEntry)
+return nullptr;
 
   // Check that the file's size fits in an 'unsigned' (with room for a
   // past-the-end value). This is deeply regrettable, but various parts of
@@ -138,13 +145,6 @@
   // miserably on large source files.
   if ((uint64_t)ContentsEntry->getSize() >=
   std::numeric_limits::max()) {
-// We can't make a memory buffer of the required size, so just make a small
-// one. We should never hit a situation where we've already parsed to a
-// later offset of the file, so it shouldn't matter that the buffer is
-// smaller than the file.
-Buffer.setPointer(
-llvm::MemoryBuffer::getMemBuffer("", ContentsEntry->getName())
-.release());
 if (Diag.isDiagnosticInFlight())
   Diag.SetDelayedDiagnostic(diag::err_file_too_large,
 ContentsEntry->getName());
@@ -153,8 +153,7 @@
 << ContentsEntry->getName();
 
 Buffer.setInt(Buffer.getInt() | InvalidFlag);
-if (Invalid) *Invalid = true;
-return Buffer.getPointer();
+return nullptr;
   }
 
   auto BufferOrError = FM.getBufferForFile(ContentsEntry, IsFileVolatile);
@@ -164,20 +163,7 @@
   // exists. Most likely, we were using a stat cache with an invalid entry but
   // the file could also have been removed during processing. Since we can't
   // really deal with this situation, just create an empty buffer.
-  //
-  // FIXME: This is definitely not 

[clang] d758f79 - clang/Basic: Replace ContentCache::getBuffer with Optional semantics

2020-10-14 Thread Duncan P . N . Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-10-14T15:55:18-04:00
New Revision: d758f79e5d381bd4f5122193a9538d89c907c812

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

LOG: clang/Basic: Replace ContentCache::getBuffer with Optional semantics

Remove `ContentCache::getBuffer`, which always returned a
dereferenceable `MemoryBuffer*` and had a `bool*Invalid` out parameter,
and replace it with:

- `ContentCache::getBufferOrNone`, which returns
  `Optional`. This is the new API that consumers should
  use. Later it could be renamed to `getBuffer`, but intentionally using
  a different name to root out any unexpected callers.
- `ContentCache::getBufferPointer`, which returns `MemoryBuffer*` with
  "optional" semantics. This is `private` to avoid growing callers and
  `SourceManager` has temporarily been made a `friend` to access it.
  Later paches will update the transitive callers to not need a raw
  pointer, and eventually this will be deleted.

No functionality change intended here.

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
clang/include/clang/Basic/SourceManager.h
clang/lib/AST/ASTImporter.cpp
clang/lib/Basic/SourceManager.cpp
clang/lib/Serialization/ASTWriter.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp 
b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
index 079d57477216..2b137d0b5113 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -305,22 +305,8 @@ static bool IsNOLINTFound(StringRef NolintDirectiveText, 
StringRef Line,
 
 static llvm::Optional getBuffer(const SourceManager , FileID 
File,
bool AllowIO) {
-  // This is similar to the implementation of SourceManager::getBufferData(),
-  // but uses ContentCache::getRawBuffer() rather than getBuffer() if
-  // AllowIO=false, to avoid triggering file I/O if the file contents aren't
-  // already mapped.
-  bool CharDataInvalid = false;
-  const SrcMgr::SLocEntry  = SM.getSLocEntry(File, );
-  if (CharDataInvalid || !Entry.isFile())
-return llvm::None;
-  const SrcMgr::ContentCache *Cache = Entry.getFile().getContentCache();
-  const llvm::MemoryBuffer *Buffer =
-  AllowIO ? Cache->getBuffer(SM.getDiagnostics(), SM.getFileManager(),
- SourceLocation(), )
-  : Cache->getRawBuffer();
-  if (!Buffer || CharDataInvalid)
-return llvm::None;
-  return Buffer->getBuffer();
+  return AllowIO ? SM.getBufferDataOrNone(File)
+ : SM.getBufferDataIfLoaded(File);
 }
 
 static bool LineIsMarkedWithNOLINT(const SourceManager , SourceLocation Loc,

diff  --git a/clang/include/clang/Basic/SourceManager.h 
b/clang/include/clang/Basic/SourceManager.h
index 1e6a800f1d55..e34fe4577aae 100644
--- a/clang/include/clang/Basic/SourceManager.h
+++ b/clang/include/clang/Basic/SourceManager.h
@@ -184,13 +184,21 @@ namespace SrcMgr {
 ///
 /// \param Loc If specified, is the location that invalid file diagnostics
 ///   will be emitted at.
+llvm::Optional
+getBufferOrNone(DiagnosticsEngine , FileManager ,
+SourceLocation Loc = SourceLocation()) const;
+
+  private:
+/// Returns pointer to memory buffer.
 ///
-/// \param Invalid If non-NULL, will be set \c true if an error occurred.
-const llvm::MemoryBuffer *getBuffer(DiagnosticsEngine ,
-FileManager ,
-SourceLocation Loc = SourceLocation(),
-bool *Invalid = nullptr) const;
+/// TODO: SourceManager needs access to this for now, but once that's done
+/// we should remove this API.
+const llvm::MemoryBuffer *getBufferPointer(DiagnosticsEngine ,
+   FileManager ,
+   SourceLocation Loc) const;
+friend class clang::SourceManager;
 
+  public:
 /// Returns the size of the content encapsulated by this
 /// ContentCache.
 ///
@@ -958,10 +966,27 @@ class SourceManager : public 
RefCountedBase {
   // FileID manipulation methods.
   
//======//
 
+  /// Return the buffer for the specified FileID.
+  ///
+  /// If there is an error opening this buffer the first time, return None.
+  llvm::Optional
+  getBufferOrNone(FileID FID, SourceLocation Loc = SourceLocation()) const {
+bool MyInvalid = false;
+const SrcMgr::SLocEntry  = getSLocEntry(FID, );
+if (MyInvalid || 

[PATCH] D85576: [clang][Fuchsia] Add relative-vtables multilib

2020-10-14 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan added a comment.

This should also be ready now that https://reviews.llvm.org/D85802 landed, 
unless we don't want to submit this *right* now so the clang builders don't 
build these multilibs that won't be used yet?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85576

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


[PATCH] D89414: clang/StaticAnalyzer: Stop using SourceManager::getBuffer

2020-10-14 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith updated this revision to Diff 298223.
dexonsmith added a comment.

Fix a warning about an unused `Invalid` flag.


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

https://reviews.llvm.org/D89414

Files:
  clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
  clang/lib/StaticAnalyzer/Core/BugReporter.cpp
  clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
  clang/lib/StaticAnalyzer/Core/IssueHash.cpp
  clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
  clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
  clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp

Index: clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
===
--- clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
+++ clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
@@ -476,7 +476,7 @@
 static bool isBisonFile(ASTContext ) {
   const SourceManager  = C.getSourceManager();
   FileID FID = SM.getMainFileID();
-  StringRef Buffer = SM.getBuffer(FID)->getBuffer();
+  StringRef Buffer = SM.getBufferOrFake(FID).getBuffer();
   if (Buffer.startswith("/* A Bison parser, made by"))
 return true;
   return false;
Index: clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
===
--- clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
+++ clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
@@ -160,9 +160,8 @@
   assert(LocInfo.second > SM.getExpansionColumnNumber(Loc) &&
  "position in file is before column number?");
 
-  bool InvalidBuffer = false;
-  const MemoryBuffer *Buf = SM.getBuffer(LocInfo.first, );
-  assert(!InvalidBuffer && "got an invalid buffer for the location's file");
+  Optional Buf = SM.getBufferOrNone(LocInfo.first);
+  assert(Buf && "got an invalid buffer for the location's file");
   assert(Buf->getBufferSize() >= (LocInfo.second + TokenLen) &&
  "token extends past end of buffer?");
 
Index: clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
===
--- clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
+++ clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
@@ -887,12 +887,12 @@
 FileID File;
 unsigned Offset;
 std::tie(File, Offset) = SM.getDecomposedLoc(ExpanLoc);
-const llvm::MemoryBuffer *MB = SM.getBuffer(File);
-const char *MacroNameTokenPos = MB->getBufferStart() + Offset;
+llvm::MemoryBufferRef MB = SM.getBufferOrFake(File);
+const char *MacroNameTokenPos = MB.getBufferStart() + Offset;
 
 RawLexer = std::make_unique(SM.getLocForStartOfFile(File), LangOpts,
-   MB->getBufferStart(), MacroNameTokenPos,
-   MB->getBufferEnd());
+   MB.getBufferStart(), MacroNameTokenPos,
+   MB.getBufferEnd());
   }
 
   void next(Token ) {
Index: clang/lib/StaticAnalyzer/Core/IssueHash.cpp
===
--- clang/lib/StaticAnalyzer/Core/IssueHash.cpp
+++ clang/lib/StaticAnalyzer/Core/IssueHash.cpp
@@ -120,7 +120,8 @@
   return "";
 }
 
-static StringRef GetNthLineOfFile(const llvm::MemoryBuffer *Buffer, int Line) {
+static StringRef GetNthLineOfFile(llvm::Optional Buffer,
+  int Line) {
   if (!Buffer)
 return "";
 
@@ -135,7 +136,7 @@
  const LangOptions ) {
   static StringRef Whitespaces = " \t\n";
 
-  StringRef Str = GetNthLineOfFile(SM.getBuffer(L.getFileID(), L),
+  StringRef Str = GetNthLineOfFile(SM.getBufferOrNone(L.getFileID(), L),
L.getExpansionLineNumber());
   StringRef::size_type col = Str.find_first_not_of(Whitespaces);
   if (col == StringRef::npos)
@@ -144,8 +145,8 @@
 col++;
   SourceLocation StartOfLine =
   SM.translateLineCol(SM.getFileID(L), L.getExpansionLineNumber(), col);
-  const llvm::MemoryBuffer *Buffer =
-  SM.getBuffer(SM.getFileID(StartOfLine), StartOfLine);
+  Optional Buffer =
+  SM.getBufferOrNone(SM.getFileID(StartOfLine), StartOfLine);
   if (!Buffer)
 return {};
 
Index: clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
===
--- clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
+++ clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
@@ -786,8 +786,8 @@
   if (LPosInfo.first != BugFileID)
 return;
 
-  const llvm::MemoryBuffer *Buf = SM.getBuffer(LPosInfo.first);
-  const char* FileStart = Buf->getBufferStart();
+  llvm::MemoryBufferRef Buf = SM.getBufferOrFake(LPosInfo.first);
+  const char *FileStart = Buf.getBufferStart();
 
   // Compute the column number.  Rewind from the current position to the start
   // of the line.
@@ -797,7 +797,7 @@
 
   // Compute LineEnd.
   const char *LineEnd = TokInstantiationPtr;
-  const char* FileEnd = 

[PATCH] D89372: [OpenCL] Remove unused extensions

2020-10-14 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

In D89372#2330822 , @yaxunl wrote:

> In D89372#2330362 , @Anastasia wrote:
>
>> In D89372#2330217 , @yaxunl wrote:
>>
>>> With this change, clang basically will have no knowledge about the removed 
>>> extensions, i.e., it will not know which extension is supported in which 
>>> version of OpenCL and have no way to enable/disable those extensions. There 
>>> will be no way to define corresponding macros in clang.
>>>
>>> Basically the responsibility of defining those macros will be shifted to 
>>> OpenCL runtime for JIT and shifted to users for offline compilation. They 
>>> need to have knowledge about which extensions are supported in which 
>>> version of OpenCL and which cpu/platform supports them. I am not sure 
>>> whether this is the direction we want to move to.
>>
>> But why do you think anyone would need to use those macros in OpenCL C?
>>
>> Let's take `cl_khr_icd` as an exmaple: 
>> https://www.khronos.org/registry/OpenCL//sdk/2.2/docs/man/html/cl_khr_icd.html
>>
>> `cl_khr_icd - Extension through which the Khronos OpenCL installable client 
>> driver loader (ICD Loader) may expose multiple separate vendor installable 
>> client drivers (Vendor ICDs) for OpenCL.`
>>
>> Why would anyone need any macro while compiling OpenCL C code for this 
>> functionality? It is dialing with the driver loader that runs on the host 
>> before compiling anything.
>>
>> I believe that the addition of such extensions into the kernel language is 
>> accidental and we should try to improve this. There is no need to have 
>> something that isn't needed. We have enough code and complexity to maintain 
>> that is useful. Let's try to simplify by at least removing what is not 
>> needed.
>>
>> On a separate note, the extensions that need macro definition and don't 
>> require the functionality in the clang parsing also doesn't have to be in 
>> the clang source code. I have mentioned it in my RFC as well: 
>> http://lists.llvm.org/pipermail/cfe-dev/2020-September/066911.html
>
> Does the spec requires cl_* macro to be defined if an extension is enabled?

The extension spec currently has:

  Every extension which affects the OpenCL language semantics, syntax or adds 
built-in functions to the language must create a preprocessor #define that 
matches the extension name string. This #define would be available in the 
language if and only if the extension is supported on a given implementation.

Those extensions don't affect the language or add any BIFs so my reading from 
this the macro shouldn't be available.

> If it is not useful, shouldn't the spec be fixed first? Otherwise, how do we 
> make sure users are not using those macros?

I have first attemted to resolve this with Khonos but there was slow progress 
so it got stalled several times 
https://github.com/KhronosGroup/OpenCL-Docs/issues/82 (see also PR). I gather 
we are the main affected stakeholders so perhaps it is up to us to improve this.

As for the spec I would like to point out that clang doesn't implement spec 
presicely from very early standards. The issue is that it has never been 
documented but we plan to improve at least from the documentation side in the 
course of OpenCL 3.0 development.

http://lists.llvm.org/pipermail/cfe-dev/2020-September/066912.html


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89372

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


[PATCH] D85802: [clang] Add -fc++-abi= flag for specifying which C++ ABI to use

2020-10-14 Thread Leonard Chan 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 rG683b308c07bf: [clang] Add -fc++-abi= flag for specifying 
which C++ ABI to use (authored by leonardchan).

Changed prior to commit:
  https://reviews.llvm.org/D85802?vs=285488=298215#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85802

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Basic/TargetCXXABI.def
  clang/include/clang/Basic/TargetCXXABI.h
  clang/include/clang/Driver/Options.td
  clang/lib/AST/ASTContext.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/Frontend/invalid-cxx-abi.cpp

Index: clang/test/Frontend/invalid-cxx-abi.cpp
===
--- /dev/null
+++ clang/test/Frontend/invalid-cxx-abi.cpp
@@ -0,0 +1,16 @@
+// These should succeed.
+// RUN: %clang_cc1 -fc++-abi=itanium %s
+// RUN: %clang_cc1 -fc++-abi=arm %s
+// RUN: %clang_cc1 -fc++-abi=ios %s
+// RUN: %clang_cc1 -fc++-abi=ios64 %s
+// RUN: %clang_cc1 -fc++-abi=aarch64 %s
+// RUN: %clang_cc1 -fc++-abi=mips %s
+// RUN: %clang_cc1 -fc++-abi=webassembly %s
+// RUN: %clang_cc1 -fc++-abi=fuchsia %s
+// RUN: %clang_cc1 -fc++-abi=xl %s
+// RUN: %clang_cc1 -fc++-abi=microsoft %s
+
+// RUN: not %clang_cc1 -fc++-abi=InvalidABI %s 2>&1 | FileCheck %s -check-prefix=INVALID
+// RUN: not %clang_cc1 -fc++-abi=Fuchsia %s 2>&1 | FileCheck %s -check-prefix=CASE-SENSITIVE
+// INVALID: error: Invalid C++ ABI name 'InvalidABI'
+// CASE-SENSITIVE: error: Invalid C++ ABI name 'Fuchsia'
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -3513,6 +3513,15 @@
   Args.hasFlag(OPT_fexperimental_relative_cxx_abi_vtables,
OPT_fno_experimental_relative_cxx_abi_vtables,
/*default=*/false);
+
+  // The value can be empty, which indicates the system default should be used.
+  StringRef CXXABI = Args.getLastArgValue(OPT_fcxx_abi_EQ);
+  if (!CXXABI.empty()) {
+if (!TargetCXXABI::isABI(CXXABI))
+  Diags.Report(diag::err_invalid_cxx_abi) << CXXABI;
+else
+  Opts.CXXABI = TargetCXXABI::getKind(CXXABI);
+  }
 }
 
 static bool isStrictlyPreprocessorAction(frontend::ActionKind Action) {
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -5029,6 +5029,9 @@
/*Default=*/false))
 Args.AddLastArg(CmdArgs, options::OPT_ffixed_point);
 
+  if (Arg *A = Args.getLastArg(options::OPT_fcxx_abi_EQ))
+A->render(Args, CmdArgs);
+
   // Handle -{std, ansi, trigraphs} -- take the last of -{std, ansi}
   // (-ansi is equivalent to -std=c89 or -std=c++98).
   //
Index: clang/lib/CodeGen/ItaniumCXXABI.cpp
===
--- clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -542,7 +542,7 @@
 }
 
 CodeGen::CGCXXABI *CodeGen::CreateItaniumCXXABI(CodeGenModule ) {
-  switch (CGM.getTarget().getCXXABI().getKind()) {
+  switch (CGM.getContext().getCXXABIKind()) {
   // For IR-generation purposes, there's no significant difference
   // between the ARM and iOS ABIs.
   case TargetCXXABI::GenericARM:
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -75,19 +75,14 @@
 static const char AnnotationSection[] = "llvm.metadata";
 
 static CGCXXABI *createCXXABI(CodeGenModule ) {
-  switch (CGM.getTarget().getCXXABI().getKind()) {
-  case TargetCXXABI::Fuchsia:
-  case TargetCXXABI::GenericAArch64:
-  case TargetCXXABI::GenericARM:
-  case TargetCXXABI::iOS:
-  case TargetCXXABI::iOS64:
-  case TargetCXXABI::WatchOS:
-  case TargetCXXABI::GenericMIPS:
-  case TargetCXXABI::GenericItanium:
-  case TargetCXXABI::WebAssembly:
-  case TargetCXXABI::XL:
+  switch (CGM.getContext().getCXXABIKind()) {
+#define ITANIUM_CXXABI(Name, Str) case TargetCXXABI::Name:
+#define CXXABI(Name, Str)
+#include "clang/Basic/TargetCXXABI.def"
 return CreateItaniumCXXABI(CGM);
-  case TargetCXXABI::Microsoft:
+#define MICROSOFT_CXXABI(Name, Str) case TargetCXXABI::Name:
+#define CXXABI(Name, Str)
+#include "clang/Basic/TargetCXXABI.def"
 return CreateMicrosoftCXXABI(CGM);
   }
 
Index: clang/lib/AST/ASTContext.cpp
===
--- 

[clang] 683b308 - [clang] Add -fc++-abi= flag for specifying which C++ ABI to use

2020-10-14 Thread Leonard Chan via cfe-commits

Author: Leonard Chan
Date: 2020-10-14T12:31:21-07:00
New Revision: 683b308c07bf827255fe1403056413f790e03729

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

LOG: [clang] Add -fc++-abi= flag for specifying which C++ ABI to use

This implements the flag proposed in RFC 
http://lists.llvm.org/pipermail/cfe-dev/2020-August/066437.html.

The goal is to add a way to override the default target C++ ABI through
a compiler flag. This makes it easier to test and transition between different
C++ ABIs through compile flags rather than build flags.

In this patch:
- Store `-fc++-abi=` in a LangOpt. This isn't stored in a
  CodeGenOpt because there are instances outside of codegen where Clang
  needs to know what the ABI is (particularly through
  ASTContext::createCXXABI), and we should be able to override the
  target default if the flag is provided at that point.
- Expose the existing ABIs in TargetCXXABI as values that can be passed
  through this flag.
  - Create a .def file for these ABIs to make it easier to check flag
values.
  - Add an error for diagnosing bad ABI flag values.

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

Added: 
clang/include/clang/Basic/TargetCXXABI.def
clang/test/Frontend/invalid-cxx-abi.cpp

Modified: 
clang/include/clang/AST/ASTContext.h
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/include/clang/Basic/LangOptions.h
clang/include/clang/Basic/TargetCXXABI.h
clang/include/clang/Driver/Options.td
clang/lib/AST/ASTContext.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/CodeGen/ItaniumCXXABI.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 3f4079e2569b..e5c80866a0a9 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -39,6 +39,7 @@
 #include "clang/Basic/SanitizerBlacklist.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/Specifiers.h"
+#include "clang/Basic/TargetCXXABI.h"
 #include "clang/Basic/XRayLists.h"
 #include "llvm/ADT/APSInt.h"
 #include "llvm/ADT/ArrayRef.h"
@@ -697,6 +698,11 @@ class ASTContext : public RefCountedBase {
 return FullSourceLoc(Loc,SourceMgr);
   }
 
+  /// Return the C++ ABI kind that should be used. The C++ ABI can be overriden
+  /// at compile time with `-fc++-abi=`. If this is not provided, we instead 
use
+  /// the default ABI set by the target.
+  TargetCXXABI::Kind getCXXABIKind() const;
+
   /// All comments in this translation unit.
   RawCommentList Comments;
 

diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 29bc19e5a84e..f1b3d4d9087e 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -524,4 +524,6 @@ def err_drv_invalid_object_mode : Error<"OBJECT_MODE 
setting %0 is not recognize
 
 def err_drv_invalid_sve_vector_bits : Error<
   "'-msve-vector-bits' is not supported without SVE enabled">;
+
+def err_invalid_cxx_abi : Error<"Invalid C++ ABI name '%0'">;
 }

diff  --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index 84d25c359c55..147fab614308 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -18,6 +18,7 @@
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/ObjCRuntime.h"
 #include "clang/Basic/Sanitizers.h"
+#include "clang/Basic/TargetCXXABI.h"
 #include "clang/Basic/Visibility.h"
 #include "llvm/ADT/FloatingPointMode.h"
 #include "llvm/ADT/StringRef.h"
@@ -294,6 +295,10 @@ class LangOptions : public LangOptionsBase {
   /// host code generation.
   std::string OMPHostIRFile;
 
+  /// C++ ABI to compile with, if specified by the frontend through -fc++-abi=.
+  /// This overrides the default ABI used by the target.
+  llvm::Optional CXXABI;
+
   /// Indicates whether the front-end is explicitly told that the
   /// input is a header file (i.e. -x c-header).
   bool IsHeaderFile = false;

diff  --git a/clang/include/clang/Basic/TargetCXXABI.def 
b/clang/include/clang/Basic/TargetCXXABI.def
new file mode 100644
index ..0ae0bb555f60
--- /dev/null
+++ b/clang/include/clang/Basic/TargetCXXABI.def
@@ -0,0 +1,129 @@
+//===--- TargetCXXABI.def - Target C++ ABI database --- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This 

[PATCH] D89372: [OpenCL] Remove unused extensions

2020-10-14 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: clang/include/clang/Basic/OpenCLExtensions.def:74
 OPENCLEXT_INTERNAL(cl_khr_mipmap_image_writes, 200, ~0U)
-OPENCLEXT_INTERNAL(cl_khr_srgb_image_writes, 200, ~0U)
 OPENCLEXT_INTERNAL(cl_khr_subgroups, 200, ~0U)

azabaznov wrote:
> mantognini wrote:
> > azabaznov wrote:
> > > cl_khr_srgb_image_writes - Extension allowing writes to sRGB images from 
> > > a kernel. This extension enables write_imagef built-in function as it 
> > > described [[ 
> > > https://www.khronos.org/registry/OpenCL/specs/2.2/html/OpenCL_Ext.html#cl_khr_srgb_image_writes
> > >  | here]]. So I think we shouldn't remove it. Do I miss something?
> > On second reading, this one is slightly ambiguous. On the language side, 
> > the extension doesn't add an overload; it only specifies that existing 
> > overload can be used with a different kind of image. On the API side, it 
> > does extend the set of features. But at the same time if the extended API 
> > is not supported, it's not possible to create an image in the first place 
> > and therefore impossible to call write_imagef. So I question the usefulness 
> > of such macro on the device side. Does this argument convince you it should 
> > be removed?
> > it's not possible to create an image in the first place and therefore 
> > impossible
> Not quite that right. Referring to [[ 
> https://www.khronos.org/registry/OpenCL/specs/2.2/html/OpenCL_C.html#conversion-rules-for-srgba-and-sbgra-images
>  | this ]]:
> 
> read_imagef built-in functions for OpenCL C 2.0 devices do implicit 
> conversions to RGB for sRGB images. However, implicit conversion from sRGB to 
> RGB is done on write_imagef only if corresponding extension is supported. 
> Otherwise, explicit conversions inside a kernel may be required.
> 
> I'm agree that this one is kind of confusing and requires some extra 
> investigation. But I think now we should remove only those extensions which 
> are only API related for sure.
Ok, thanks for providing extra information. I agree this deserves extra 
clarifications.

I am not sure whether the frontend will be able to perform such conversions 
since it doesn't have information regarding the channels. The image types are 
completely opaque. That means that potentially the BIFs can handle the 
conversion internally. However, I am unclear whether the macro can be useful 
i.e. whether there is anything that can be done differently at the source level 
based on its availability in OpenCL kernel code.

It should be ok to leave this out for now from the clean up unless someone else 
can help quickly with some more insights.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89372

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


[PATCH] D89372: [OpenCL] Remove unused extensions

2020-10-14 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

In D89372#2330362 , @Anastasia wrote:

> In D89372#2330217 , @yaxunl wrote:
>
>> With this change, clang basically will have no knowledge about the removed 
>> extensions, i.e., it will not know which extension is supported in which 
>> version of OpenCL and have no way to enable/disable those extensions. There 
>> will be no way to define corresponding macros in clang.
>>
>> Basically the responsibility of defining those macros will be shifted to 
>> OpenCL runtime for JIT and shifted to users for offline compilation. They 
>> need to have knowledge about which extensions are supported in which version 
>> of OpenCL and which cpu/platform supports them. I am not sure whether this 
>> is the direction we want to move to.
>
> But why do you think anyone would need to use those macros in OpenCL C?
>
> Let's take `cl_khr_icd` as an exmaple: 
> https://www.khronos.org/registry/OpenCL//sdk/2.2/docs/man/html/cl_khr_icd.html
>
> `cl_khr_icd - Extension through which the Khronos OpenCL installable client 
> driver loader (ICD Loader) may expose multiple separate vendor installable 
> client drivers (Vendor ICDs) for OpenCL.`
>
> Why would anyone need any macro while compiling OpenCL C code for this 
> functionality? It is dialing with the driver loader that runs on the host 
> before compiling anything.
>
> I believe that the addition of such extensions into the kernel language is 
> accidental and we should try to improve this. There is no need to have 
> something that isn't needed. We have enough code and complexity to maintain 
> that is useful. Let's try to simplify by at least removing what is not needed.
>
> On a separate note, the extensions that need macro definition and don't 
> require the functionality in the clang parsing also doesn't have to be in the 
> clang source code. I have mentioned it in my RFC as well: 
> http://lists.llvm.org/pipermail/cfe-dev/2020-September/066911.html

Does the spec requires cl_* macro to be defined if an extension is enabled? If 
it is not useful, shouldn't the spec be fixed first? Otherwise, how do we make 
sure users are not using those macros?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89372

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


[PATCH] D88976: [clang] Use correct address space for global variable debug info

2020-10-14 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added inline comments.



Comment at: clang/lib/Basic/Targets/NVPTX.h:47
 -1, // Default, opencl_private or opencl_generic - not defined
-5,  // opencl_global
+-1, // opencl_global
 -1,

Does anyone have any thoughts on this change specifically? Is someone more 
familiar with NVPTX willing to weigh in on whether it makes more sense to carry 
the address space throughout the compiler explicitly and "drop" it late in the 
DWARF emission, or to do what I did in the current patch (drop it early).

I would lean towards updating the patch to do the latter, but I wanted to get 
feedback before plunging off to do it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88976

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


[PATCH] D89366: [WebAssembly] v128.load{8, 16, 32, 64}_lane instructions

2020-10-14 Thread Thomas Lively via Phabricator via cfe-commits
tlively requested review of this revision.
tlively added a comment.

The structure is the same, but I would appreciate a review of the diff since a 
lot of things had to change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89366

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


[PATCH] D89366: [WebAssembly] v128.load{8, 16, 32, 64}_lane instructions

2020-10-14 Thread Thomas Lively via Phabricator via cfe-commits
tlively updated this revision to Diff 298209.
tlively marked 2 inline comments as done.
tlively added a comment.
This revision is now accepted and ready to land.

- Add missing vec argument to loads and fix argument order
- Add comments and fix formatting


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89366

Files:
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/builtins-wasm.c
  llvm/include/llvm/IR/IntrinsicsWebAssembly.td
  llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
  llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h
  llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
  llvm/test/CodeGen/WebAssembly/simd-load-lane-offset.ll
  llvm/test/MC/WebAssembly/simd-encodings.s

Index: llvm/test/MC/WebAssembly/simd-encodings.s
===
--- llvm/test/MC/WebAssembly/simd-encodings.s
+++ llvm/test/MC/WebAssembly/simd-encodings.s
@@ -280,6 +280,30 @@
 # CHECK: v128.bitselect # encoding: [0xfd,0x52]
 v128.bitselect
 
+# CHECK: v128.load8_lane 32, 1 # encoding: [0xfd,0x58,0x00,0x20,0x01]
+v128.load8_lane 32, 1
+
+# CHECK: v128.load16_lane 32, 1 # encoding: [0xfd,0x59,0x01,0x20,0x01]
+v128.load16_lane 32, 1
+
+# CHECK: v128.load32_lane 32, 1 # encoding: [0xfd,0x5a,0x02,0x20,0x01]
+v128.load32_lane 32, 1
+
+# CHECK: v128.load64_lane 32, 1 # encoding: [0xfd,0x5b,0x03,0x20,0x01]
+v128.load64_lane 32, 1
+
+# CHECK: v128.store8_lane 32, 1 # encoding: [0xfd,0x5c,0x00,0x20,0x01]
+v128.store8_lane 32, 1
+
+# CHECK: v128.store16_lane 32, 1 # encoding: [0xfd,0x5d,0x01,0x20,0x01]
+v128.store16_lane 32, 1
+
+# CHECK: v128.store32_lane 32, 1 # encoding: [0xfd,0x5e,0x02,0x20,0x01]
+v128.store32_lane 32, 1
+
+# CHECK: v128.store64_lane 32, 1 # encoding: [0xfd,0x5f,0x03,0x20,0x01]
+v128.store64_lane 32, 1
+
 # CHECK: i8x16.abs # encoding: [0xfd,0x60]
 i8x16.abs
 
Index: llvm/test/CodeGen/WebAssembly/simd-load-lane-offset.ll
===
--- /dev/null
+++ llvm/test/CodeGen/WebAssembly/simd-load-lane-offset.ll
@@ -0,0 +1,968 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s -verify-machineinstrs -mattr=+simd128 | FileCheck %s
+
+; Test SIMD v128.load{8,16,32,64}_lane instructions.
+
+; TODO: Use the offset field by supporting more patterns. Right now only the
+; equivalents of LoadPatNoOffset/StorePatNoOffset are supported.
+
+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
+target triple = "wasm32-unknown-unknown"
+
+declare <16 x i8> @llvm.wasm.load8.lane(i8*, <16 x i8>, i32)
+declare <8 x i16> @llvm.wasm.load16.lane(i16*, <8 x i16>, i32)
+declare <4 x i32> @llvm.wasm.load32.lane(i32*, <4 x i32>, i32)
+declare <2 x i64> @llvm.wasm.load64.lane(i64*, <2 x i64>, i32)
+
+declare void @llvm.wasm.store8.lane(i8*, <16 x i8>, i32)
+declare void @llvm.wasm.store16.lane(i16*, <8 x i16>, i32)
+declare void @llvm.wasm.store32.lane(i32*, <4 x i32>, i32)
+declare void @llvm.wasm.store64.lane(i64*, <2 x i64>, i32)
+
+;===
+; v128.load8_lane / v128.store8_lane
+;===
+
+define <16 x i8> @load_lane_i8_no_offset(i8* %p, <16 x i8> %v) {
+; CHECK-LABEL: load_lane_i8_no_offset:
+; CHECK: .functype load_lane_i8_no_offset (i32, v128) -> (v128)
+; CHECK-NEXT:  # %bb.0:
+; CHECK-NEXT:local.get 0
+; CHECK-NEXT:local.get 1
+; CHECK-NEXT:v128.load8_lane 0, 0
+; CHECK-NEXT:# fallthrough-return
+  %t = tail call <16 x i8> @llvm.wasm.load8.lane(i8* %p, <16 x i8> %v, i32 0)
+  ret <16 x i8> %t
+}
+
+define <16 x i8> @load_lane_i8_with_folded_offset(i8* %p, <16 x i8> %v) {
+; CHECK-LABEL: load_lane_i8_with_folded_offset:
+; CHECK: .functype load_lane_i8_with_folded_offset (i32, v128) -> (v128)
+; CHECK-NEXT:  # %bb.0:
+; CHECK-NEXT:local.get 0
+; CHECK-NEXT:i32.const 24
+; CHECK-NEXT:i32.add
+; CHECK-NEXT:local.get 1
+; CHECK-NEXT:v128.load8_lane 0, 0
+; CHECK-NEXT:# fallthrough-return
+  %q = ptrtoint i8* %p to i32
+  %r = add nuw i32 %q, 24
+  %s = inttoptr i32 %r to i8*
+  %t = tail call <16 x i8> @llvm.wasm.load8.lane(i8* %s, <16 x i8> %v, i32 0)
+  ret <16 x i8> %t
+}
+
+define <16 x i8> @load_lane_i8_with_folded_gep_offset(i8* %p, <16 x i8> %v) {
+; CHECK-LABEL: load_lane_i8_with_folded_gep_offset:
+; CHECK: .functype load_lane_i8_with_folded_gep_offset (i32, v128) -> (v128)
+; CHECK-NEXT:  # %bb.0:
+; CHECK-NEXT:local.get 0
+; CHECK-NEXT:i32.const 6
+; CHECK-NEXT:i32.add
+; CHECK-NEXT:local.get 1
+; CHECK-NEXT:v128.load8_lane 0, 0
+; CHECK-NEXT:

[PATCH] D88227: [clang-format] Add a SpaceAroundPointerQualifiers style option

2020-10-14 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay accepted this revision.
MyDeveloperDay added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88227

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


[PATCH] D89416: clang-{tools,unittests}: Stop using SourceManager::getBuffer, NFC

2020-10-14 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith updated this revision to Diff 298206.
dexonsmith added a comment.

Removed the now-unused `Invalid` local variable from the libclang change; not 
sure how I missed the warning before.


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

https://reviews.llvm.org/D89416

Files:
  clang-tools-extra/clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp
  clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
  clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp
  clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/SemanticHighlighting.cpp
  clang-tools-extra/clangd/SourceCode.cpp
  clang-tools-extra/modularize/PreprocessorTracker.cpp
  clang/tools/clang-diff/ClangDiff.cpp
  clang/tools/clang-import-test/clang-import-test.cpp
  clang/tools/libclang/CIndex.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -5695,7 +5695,8 @@
   // Make sure the imported buffer has the original contents.
   SourceManager  = ToAST->getSourceManager();
   FileID ImportedID = ToSM.getFileID(ImportedLoc);
-  EXPECT_EQ(Source, ToSM.getBuffer(ImportedID, SourceLocation())->getBuffer());
+  EXPECT_EQ(Source,
+ToSM.getBufferOrFake(ImportedID, SourceLocation()).getBuffer());
 }
 
 TEST_P(ImportSourceLocations, OverwrittenFileBuffer) {
@@ -5729,7 +5730,7 @@
   SourceManager  = ToAST->getSourceManager();
   FileID ImportedID = ToSM.getFileID(ImportedLoc);
   EXPECT_EQ(Contents,
-ToSM.getBuffer(ImportedID, SourceLocation())->getBuffer());
+ToSM.getBufferOrFake(ImportedID, SourceLocation()).getBuffer());
 }
 
 TEST_P(ASTImporterOptionSpecificTestBase, ImportExprOfAlignmentAttr) {
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -4362,9 +4362,8 @@
 
   const SourceManager  = cxtu::getASTUnit(TU)->getSourceManager();
   FileID fid = SM.translateFile(static_cast(file));
-  bool Invalid = true;
-  const llvm::MemoryBuffer *buf = SM.getBuffer(fid, );
-  if (Invalid) {
+  llvm::Optional buf = SM.getBufferOrNone(fid);
+  if (!buf) {
 if (size)
   *size = 0;
 return nullptr;
Index: clang/tools/clang-import-test/clang-import-test.cpp
===
--- clang/tools/clang-import-test/clang-import-test.cpp
+++ clang/tools/clang-import-test/clang-import-test.cpp
@@ -106,20 +106,19 @@
 unsigned LocColumn =
 SM.getSpellingColumnNumber(Loc, /*Invalid=*/nullptr) - 1;
 FileID FID = SM.getFileID(Loc);
-const llvm::MemoryBuffer *Buffer =
-SM.getBuffer(FID, Loc, /*Invalid=*/nullptr);
+llvm::MemoryBufferRef Buffer = SM.getBufferOrFake(FID, Loc);
 
-assert(LocData >= Buffer->getBufferStart() &&
-   LocData < Buffer->getBufferEnd());
+assert(LocData >= Buffer.getBufferStart() &&
+   LocData < Buffer.getBufferEnd());
 
 const char *LineBegin = LocData - LocColumn;
 
-assert(LineBegin >= Buffer->getBufferStart());
+assert(LineBegin >= Buffer.getBufferStart());
 
 const char *LineEnd = nullptr;
 
 for (LineEnd = LineBegin; *LineEnd != '\n' && *LineEnd != '\r' &&
-  LineEnd < Buffer->getBufferEnd();
+  LineEnd < Buffer.getBufferEnd();
  ++LineEnd)
   ;
 
Index: clang/tools/clang-diff/ClangDiff.cpp
===
--- clang/tools/clang-diff/ClangDiff.cpp
+++ clang/tools/clang-diff/ClangDiff.cpp
@@ -284,7 +284,7 @@
   unsigned Begin, End;
   std::tie(Begin, End) = Tree.getSourceRangeOffsets(Node);
   const SourceManager  = Tree.getASTContext().getSourceManager();
-  auto Code = SrcMgr.getBuffer(SrcMgr.getMainFileID())->getBuffer();
+  auto Code = SrcMgr.getBufferOrFake(SrcMgr.getMainFileID()).getBuffer();
   for (; Offset < Begin; ++Offset)
 printHtml(OS, Code[Offset]);
   OS << "getBufferStart();
-  const char *BufferEnd = MemBuffer->getBufferEnd();
+  llvm::MemoryBufferRef MemBuffer = PP.getSourceManager().getBufferOrFake(
+  PP.getSourceManager().getFileID(Loc));
+  const char *Buffer = MemBuffer.getBufferStart();
+  const char *BufferEnd = MemBuffer.getBufferEnd();
   const char *BeginPtr = PP.getSourceManager().getCharacterData(Loc);
   const char *EndPtr = BeginPtr;
   while (BeginPtr > Buffer) {
@@ -338,9 +338,10 @@
 // Retrieve source line from file image given a file ID and line number.
 static std::string getSourceLine(clang::Preprocessor , clang::FileID FileID,
  int Line) {
-  const llvm::MemoryBuffer *MemBuffer = PP.getSourceManager().getBuffer(FileID);
-  const char *Buffer = 

[PATCH] D89276: Support ObjC in IncludeInserter

2020-10-14 Thread Joe Turner via Phabricator via cfe-commits
compositeprimes updated this revision to Diff 298203.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89276

Files:
  clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp
  clang-tools-extra/clang-tidy/utils/IncludeSorter.h
  clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp
@@ -28,8 +28,10 @@
 
 class IncludeInserterCheckBase : public ClangTidyCheck {
 public:
-  IncludeInserterCheckBase(StringRef CheckName, ClangTidyContext *Context)
-  : ClangTidyCheck(CheckName, Context) {}
+  IncludeInserterCheckBase(StringRef CheckName, ClangTidyContext *Context,
+   utils::IncludeSorter::IncludeStyle Style =
+   utils::IncludeSorter::IS_Google)
+  : ClangTidyCheck(CheckName, Context), Inserter(Style) {}
 
   void registerPPCallbacks(const SourceManager , Preprocessor *PP,
Preprocessor *ModuleExpanderPP) override {
@@ -50,7 +52,7 @@
 
   virtual std::vector headersToInclude() const = 0;
 
-  utils::IncludeInserter Inserter{utils::IncludeSorter::IS_Google};
+  utils::IncludeInserter Inserter;
 };
 
 class NonSystemHeaderInserterCheck : public IncludeInserterCheckBase {
@@ -111,6 +113,42 @@
   }
 };
 
+class ObjCEarlyInAlphabetHeaderInserterCheck : public IncludeInserterCheckBase {
+public:
+  ObjCEarlyInAlphabetHeaderInserterCheck(StringRef CheckName,
+ ClangTidyContext *Context)
+  : IncludeInserterCheckBase(CheckName, Context,
+ utils::IncludeSorter::IS_Google_ObjC) {}
+
+  std::vector headersToInclude() const override {
+return {"a/header.h"};
+  }
+};
+
+class ObjCCategoryHeaderInserterCheck : public IncludeInserterCheckBase {
+public:
+  ObjCCategoryHeaderInserterCheck(StringRef CheckName,
+  ClangTidyContext *Context)
+  : IncludeInserterCheckBase(CheckName, Context,
+ utils::IncludeSorter::IS_Google_ObjC) {}
+
+  std::vector headersToInclude() const override {
+return {"clang_tidy/tests/insert_includes_test_header+foo.h"};
+  }
+};
+
+class ObjCGeneratedHeaderInserterCheck : public IncludeInserterCheckBase {
+public:
+  ObjCGeneratedHeaderInserterCheck(StringRef CheckName,
+   ClangTidyContext *Context)
+  : IncludeInserterCheckBase(CheckName, Context,
+ utils::IncludeSorter::IS_Google_ObjC) {}
+
+  std::vector headersToInclude() const override {
+return {"clang_tidy/tests/generated_file.proto.h"};
+  }
+};
+
 template 
 std::string runCheckOnCode(StringRef Code, StringRef Filename) {
   std::vector Errors;
@@ -120,12 +158,20 @@
   {"clang_tidy/tests/"
"insert_includes_test_header.h",
"\n"},
+  // ObjC category.
+  {"clang_tidy/tests/"
+   "insert_includes_test_header+foo.h",
+   "\n"},
   // Non system headers
   {"a/header.h", "\n"},
   {"path/to/a/header.h", "\n"},
   {"path/to/z/header.h", "\n"},
   {"path/to/header.h", "\n"},
   {"path/to/header2.h", "\n"},
+  // Generated headers
+  {"clang_tidy/tests/"
+   "generated_file.proto.h",
+   "\n"},
   // Fake system headers.
   {"stdlib.h", "\n"},
   {"unistd.h", "\n"},
@@ -160,9 +206,9 @@
   int a = 0;
 })";
 
-  EXPECT_EQ(PostCode, runCheckOnCode(
-  PreCode, "clang_tidy/tests/"
-   "insert_includes_test_input2.cc"));
+  EXPECT_EQ(PostCode,
+runCheckOnCode(
+PreCode, "clang_tidy/tests/insert_includes_test_input2.cc"));
 }
 
 TEST(IncludeInserterTest, InsertMultipleIncludesAndDeduplicate) {
@@ -191,9 +237,9 @@
   int a = 0;
 })";
 
-  EXPECT_EQ(PostCode, runCheckOnCode(
-  PreCode, "clang_tidy/tests/"
-   "insert_includes_test_input2.cc"));
+  EXPECT_EQ(PostCode,
+runCheckOnCode(
+PreCode, 

[PATCH] D17993: [CodeGen] Apply 'nonnull' to 'this' pointer arguments.

2020-10-14 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/lib/CodeGen/CGCall.cpp:2165
+assert(getContext().getTargetAddressSpace(FI.arg_begin()->type) == 0 &&
+   "Expected `this` pointer without address space attribute.");
+

jdoerfert wrote:
> I'm unsure why this assertion has to hold and more importantly why we need 
> it. @arsenm do you?
Even if the `this` pointer is always an address-space-0 pointer for now, it 
would be more consistent with how we handle `Attribute::NonNull` elsewhere to 
skip adding the `NonNull` attribute for non-address-space-0 pointers rather 
than asserting here.



Comment at: clang/lib/CodeGen/CGCall.cpp:2174
+  }
+
   unsigned ArgNo = 0;

jdoerfert wrote:
> rsmith wrote:
> > CJ-Johnson wrote:
> > > jdoerfert wrote:
> > > > Even if null pointer is valid we should place dereferenceable.
> > > > 
> > > > We also could never place nonnull and let the middle-end make the 
> > > > dereferenceable -> nonnull deduction, though I don't see why we can't 
> > > > just add nonnull here.
> > > I re-ran ninja check after making this fix and addressed the 
> > > newly-affected tests. So the patch is fully up to date :)
> > The LLVM LangRef says that in address space 0, `dereferenceable` implies 
> > `nonnull`, so I don't think we can emit `dereferenceable` in 
> > `NullPointerIsValid` mode, and we'd need to use `dereferenceable_or_null` 
> > instead. (Perhaps the LangRef is wrong, though, and the 
> > `null_pointer_is_valid` function attribute overrides that determination.)
> > (Perhaps the LangRef is wrong, though, and the null_pointer_is_valid 
> > function attribute overrides that determination.)
> 
> This is the case. IMHO, dereferenceable has to be correct here, regardless of 
> the mode. You could access the object in the function entry, which we would 
> use to deduce dereferenceable, and if the `NullPointerIsValid` is not 
> translated to the function attribute also to `nonnull`. 
OK, if the LangRef is wrong about this, then I agree we should emit 
`dereferenceable` unconditionally. Thanks for clarifying.


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

https://reviews.llvm.org/D17993

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


[PATCH] D89416: clang-{tools,unittests}: Stop using SourceManager::getBuffer, NFC

2020-10-14 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith created this revision.
dexonsmith added a reviewer: arphaman.
Herald added subscribers: usaxena95, ributzka, kadircet.
Herald added a reviewer: shafik.
dexonsmith requested review of this revision.

Update clang-tools-extra, clang/tools, clang/unittests to migrate from
`SourceManager::getBuffer`, which returns an always dereferenceable
`MemoryBuffer*`, to `getBufferOrNone` or `getBufferOrFake`, both of
which return a `MemoryBufferRef`, depending on whether the call site was
checking for validity of the buffer. No functionality change intended.


https://reviews.llvm.org/D89416

Files:
  clang-tools-extra/clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp
  clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
  clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp
  clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/SemanticHighlighting.cpp
  clang-tools-extra/clangd/SourceCode.cpp
  clang-tools-extra/modularize/PreprocessorTracker.cpp
  clang/tools/clang-diff/ClangDiff.cpp
  clang/tools/clang-import-test/clang-import-test.cpp
  clang/tools/libclang/CIndex.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -5695,7 +5695,8 @@
   // Make sure the imported buffer has the original contents.
   SourceManager  = ToAST->getSourceManager();
   FileID ImportedID = ToSM.getFileID(ImportedLoc);
-  EXPECT_EQ(Source, ToSM.getBuffer(ImportedID, SourceLocation())->getBuffer());
+  EXPECT_EQ(Source,
+ToSM.getBufferOrFake(ImportedID, SourceLocation()).getBuffer());
 }
 
 TEST_P(ImportSourceLocations, OverwrittenFileBuffer) {
@@ -5729,7 +5730,7 @@
   SourceManager  = ToAST->getSourceManager();
   FileID ImportedID = ToSM.getFileID(ImportedLoc);
   EXPECT_EQ(Contents,
-ToSM.getBuffer(ImportedID, SourceLocation())->getBuffer());
+ToSM.getBufferOrFake(ImportedID, SourceLocation()).getBuffer());
 }
 
 TEST_P(ASTImporterOptionSpecificTestBase, ImportExprOfAlignmentAttr) {
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -4363,8 +4363,8 @@
   const SourceManager  = cxtu::getASTUnit(TU)->getSourceManager();
   FileID fid = SM.translateFile(static_cast(file));
   bool Invalid = true;
-  const llvm::MemoryBuffer *buf = SM.getBuffer(fid, );
-  if (Invalid) {
+  llvm::Optional buf = SM.getBufferOrNone(fid);
+  if (!buf) {
 if (size)
   *size = 0;
 return nullptr;
Index: clang/tools/clang-import-test/clang-import-test.cpp
===
--- clang/tools/clang-import-test/clang-import-test.cpp
+++ clang/tools/clang-import-test/clang-import-test.cpp
@@ -106,20 +106,19 @@
 unsigned LocColumn =
 SM.getSpellingColumnNumber(Loc, /*Invalid=*/nullptr) - 1;
 FileID FID = SM.getFileID(Loc);
-const llvm::MemoryBuffer *Buffer =
-SM.getBuffer(FID, Loc, /*Invalid=*/nullptr);
+llvm::MemoryBufferRef Buffer = SM.getBufferOrFake(FID, Loc);
 
-assert(LocData >= Buffer->getBufferStart() &&
-   LocData < Buffer->getBufferEnd());
+assert(LocData >= Buffer.getBufferStart() &&
+   LocData < Buffer.getBufferEnd());
 
 const char *LineBegin = LocData - LocColumn;
 
-assert(LineBegin >= Buffer->getBufferStart());
+assert(LineBegin >= Buffer.getBufferStart());
 
 const char *LineEnd = nullptr;
 
 for (LineEnd = LineBegin; *LineEnd != '\n' && *LineEnd != '\r' &&
-  LineEnd < Buffer->getBufferEnd();
+  LineEnd < Buffer.getBufferEnd();
  ++LineEnd)
   ;
 
Index: clang/tools/clang-diff/ClangDiff.cpp
===
--- clang/tools/clang-diff/ClangDiff.cpp
+++ clang/tools/clang-diff/ClangDiff.cpp
@@ -284,7 +284,7 @@
   unsigned Begin, End;
   std::tie(Begin, End) = Tree.getSourceRangeOffsets(Node);
   const SourceManager  = Tree.getASTContext().getSourceManager();
-  auto Code = SrcMgr.getBuffer(SrcMgr.getMainFileID())->getBuffer();
+  auto Code = SrcMgr.getBufferOrFake(SrcMgr.getMainFileID()).getBuffer();
   for (; Offset < Begin; ++Offset)
 printHtml(OS, Code[Offset]);
   OS << "getBufferStart();
-  const char *BufferEnd = MemBuffer->getBufferEnd();
+  llvm::MemoryBufferRef MemBuffer = PP.getSourceManager().getBufferOrFake(
+  PP.getSourceManager().getFileID(Loc));
+  const char *Buffer = MemBuffer.getBufferStart();
+  const char *BufferEnd = MemBuffer.getBufferEnd();
   const char *BeginPtr = PP.getSourceManager().getCharacterData(Loc);
   const char *EndPtr = BeginPtr;
   while (BeginPtr > Buffer) {
@@ -338,9 +338,10 @@
 // Retrieve 

[PATCH] D84362: [NFC] Refactor DiagnosticBuilder and PartialDiagnostic

2020-10-14 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked an inline comment as done.
yaxunl added inline comments.



Comment at: clang/include/clang/Basic/PartialDiagnostic.h:51
+  : DiagID(DiagID) {
+Allocator = _;
+  }

tra wrote:
> Is there a particular reason to move field initialization into the body here 
> and in other constructors?
Allocator is now a member of the base class, therefore needs to be initialized 
directly. I could add ctor to the base class but I did not see too much benefit 
of doing that.


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

https://reviews.llvm.org/D84362

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


[PATCH] D89407: [clang-tidy] Add scoped enum constants to identifier naming check

2020-10-14 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 298200.
njames93 added a comment.

Small tweak to the docs


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89407

Files:
  clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/readability-identifier-naming.rst
  clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming.cpp
@@ -18,6 +18,7 @@
 // RUN: {key: readability-identifier-naming.ConstexprVariableCase, value: lower_case}, \
 // RUN: {key: readability-identifier-naming.EnumCase, value: CamelCase}, \
 // RUN: {key: readability-identifier-naming.EnumPrefix, value: 'E'}, \
+// RUN: {key: readability-identifier-naming.ScopedEnumConstantCase, value: CamelCase}, \
 // RUN: {key: readability-identifier-naming.EnumConstantCase, value: UPPER_CASE}, \
 // RUN: {key: readability-identifier-naming.FunctionCase, value: camelBack}, \
 // RUN: {key: readability-identifier-naming.GlobalConstantCase, value: UPPER_CASE}, \
@@ -160,6 +161,18 @@
 // CHECK-FIXES: {{^}}THIS_CONST_VALUE = 1,{{$}}
 };
 
+enum class EMyEnumeration {
+myConstant = 1,
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for scoped enum constant 'myConstant'
+// CHECK-FIXES: {{^}}MyConstant = 1,{{$}}
+your_CONST = 1,
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for scoped enum constant 'your_CONST'
+// CHECK-FIXES: {{^}}YourConst = 1,{{$}}
+THIS_ConstValue = 1,
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for scoped enum constant 'THIS_ConstValue'
+// CHECK-FIXES: {{^}}ThisConstValue = 1,{{$}}
+};
+
 constexpr int ConstExpr_variable = MyConstant;
 // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: invalid case style for constexpr variable 'ConstExpr_variable'
 // CHECK-FIXES: {{^}}constexpr int const_expr_variable = MY_CONSTANT;{{$}}
Index: clang-tools-extra/docs/clang-tidy/checks/readability-identifier-naming.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/readability-identifier-naming.rst
+++ clang-tools-extra/docs/clang-tidy/checks/readability-identifier-naming.rst
@@ -76,6 +76,7 @@
  - :option:`ProtectedMethodCase`, :option:`ProtectedMethodPrefix`, :option:`ProtectedMethodSuffix`
  - :option:`PublicMemberCase`, :option:`PublicMemberPrefix`, :option:`PublicMemberSuffix`
  - :option:`PublicMethodCase`, :option:`PublicMethodPrefix`, :option:`PublicMethodSuffix`
+ - :option:`ScopedEnumConstantCase`, :option:`ScopedEnumConstantPrefix`, :option:`ScopedEnumConstantSuffix`
  - :option:`StaticConstantCase`, :option:`StaticConstantPrefix`, :option:`StaticConstantSuffix`
  - :option:`StaticVariableCase`, :option:`StaticVariablePrefix`, :option:`StaticVariableSuffix`
  - :option:`StructCase`, :option:`StructPrefix`, :option:`StructSuffix`
@@ -1595,6 +1596,41 @@
   int pre_member_method_post();
 }
 
+.. option:: ScopedEnumConstantCase
+
+When defined, the check will ensure scoped enum constant names conform to 
+the selected casing.
+
+.. option:: ScopedEnumConstantPrefix
+
+When defined, the check will ensure scoped enum constant names will add the
+prefixed with the given value (regardless of casing).
+
+.. option:: ScopedEnumConstantSuffix
+
+When defined, the check will ensure scoped enum constant names will add the
+suffix with the given value (regardless of casing).
+
+For example using values of:
+
+   - ScopedEnumConstantCase of ``lower_case``
+   - ScopedEnumConstantPrefix of ``pre_``
+   - ScopedEnumConstantSuffix of ``_post``
+
+Identifies and/or transforms enumeration constant names as follows:
+
+Before:
+
+.. code-block:: c++
+
+enum class FOO { One, Two, Three };
+
+After:
+
+.. code-block:: c++
+
+enum class FOO { pre_One_post, pre_Two_post, pre_Three_post };
+
 .. option:: StaticConstantCase
 
 When defined, the check will ensure static constant names conform to the
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -120,6 +120,9 @@
   Added an option `GetConfigPerFile` to support including files which use
   different naming styles.
 
+  Added support for specifying the style of scoped ``enum`` constants. If 
+  unspecified, will fall back to the style for regular ``enum`` constants.
+
 - Removed `google-runtime-references` check because the rule it checks does
   not exist in the 

[PATCH] D89372: [OpenCL] Remove unused extensions

2020-10-14 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added inline comments.



Comment at: clang/include/clang/Basic/OpenCLExtensions.def:74
 OPENCLEXT_INTERNAL(cl_khr_mipmap_image_writes, 200, ~0U)
-OPENCLEXT_INTERNAL(cl_khr_srgb_image_writes, 200, ~0U)
 OPENCLEXT_INTERNAL(cl_khr_subgroups, 200, ~0U)

mantognini wrote:
> azabaznov wrote:
> > cl_khr_srgb_image_writes - Extension allowing writes to sRGB images from a 
> > kernel. This extension enables write_imagef built-in function as it 
> > described [[ 
> > https://www.khronos.org/registry/OpenCL/specs/2.2/html/OpenCL_Ext.html#cl_khr_srgb_image_writes
> >  | here]]. So I think we shouldn't remove it. Do I miss something?
> On second reading, this one is slightly ambiguous. On the language side, the 
> extension doesn't add an overload; it only specifies that existing overload 
> can be used with a different kind of image. On the API side, it does extend 
> the set of features. But at the same time if the extended API is not 
> supported, it's not possible to create an image in the first place and 
> therefore impossible to call write_imagef. So I question the usefulness of 
> such macro on the device side. Does this argument convince you it should be 
> removed?
> it's not possible to create an image in the first place and therefore 
> impossible
Not quite that right. Referring to [[ 
https://www.khronos.org/registry/OpenCL/specs/2.2/html/OpenCL_C.html#conversion-rules-for-srgba-and-sbgra-images
 | this ]]:

read_imagef built-in functions for OpenCL C 2.0 devices do implicit conversions 
to RGB for sRGB images. However, implicit conversion from sRGB to RGB is done 
on write_imagef only if corresponding extension is supported. Otherwise, 
explicit conversions inside a kernel may be required.

I'm agree that this one is kind of confusing and requires some extra 
investigation. But I think now we should remove only those extensions which are 
only API related for sure.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89372

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


[PATCH] D86671: [clang-tidy] Add new case type to check variables with Hungarian notation

2020-10-14 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

Is this diff been created incorrectly again?

Taking a step back, Is Hungarian notation really a case style, Seems to me its 
mainly about the prefix and a user may want `DWORD dwUPPER_CASE`, Right now 
there is no way of adopting that.
Maybe extend the options for hungarian type decls to

  Case
  Prefix
  Suffix
  HungarianPrefix

`HungarianPrefix` would likely be a bool and if enabled, it would be 
prepended to `Prefix`
I could see a situation like this

  [Options]
  // VariableCase: UPPER_CASE
  // VariablePrefix: PRE_
  // VariableSuffix: _POST
  // VariableHungarianPrefix: true
  
  DWORD MyVariable; -> DWORD dwPRE_MY_VARIABLE_POST;

This would give users full control of exactly how they want their declarations 
with no hidden surprises.

Granted this approach would require a little rework but it would satisfy more 
users.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86671

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


[PATCH] D89414: clang/StaticAnalyzer: Stop using SourceManager::getBuffer

2020-10-14 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith created this revision.
dexonsmith added a reviewer: arphaman.
Herald added subscribers: steakhal, ASDenysPetrov, martong, ributzka, dkrupp, 
donat.nagy, Szelethus, a.sidorin, baloghadamsoftware.
dexonsmith requested review of this revision.

Update clang/lib/StaticAnalyzer to stop relying on a `MemoryBuffer*`, using the 
`MemoryBufferRef` from `getBufferOrNone` or the `Optional` 
from `getBufferOrFake`, depending on whether there's logic for checking 
validity of the buffer. The change to 
clang/lib/StaticAnalyzer/Core/IssueHash.cpp is potentially a functionality 
change, since the logic was wrong (it checked for `nullptr`, which was never 
returned by the old API), but if that was reachable the new behaviour should be 
better.


https://reviews.llvm.org/D89414

Files:
  clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
  clang/lib/StaticAnalyzer/Core/BugReporter.cpp
  clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
  clang/lib/StaticAnalyzer/Core/IssueHash.cpp
  clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
  clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
  clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp

Index: clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
===
--- clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
+++ clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
@@ -476,7 +476,7 @@
 static bool isBisonFile(ASTContext ) {
   const SourceManager  = C.getSourceManager();
   FileID FID = SM.getMainFileID();
-  StringRef Buffer = SM.getBuffer(FID)->getBuffer();
+  StringRef Buffer = SM.getBufferOrFake(FID).getBuffer();
   if (Buffer.startswith("/* A Bison parser, made by"))
 return true;
   return false;
Index: clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
===
--- clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
+++ clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
@@ -160,9 +160,8 @@
   assert(LocInfo.second > SM.getExpansionColumnNumber(Loc) &&
  "position in file is before column number?");
 
-  bool InvalidBuffer = false;
-  const MemoryBuffer *Buf = SM.getBuffer(LocInfo.first, );
-  assert(!InvalidBuffer && "got an invalid buffer for the location's file");
+  Optional Buf = SM.getBufferOrNone(LocInfo.first);
+  assert(Buf && "got an invalid buffer for the location's file");
   assert(Buf->getBufferSize() >= (LocInfo.second + TokenLen) &&
  "token extends past end of buffer?");
 
Index: clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
===
--- clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
+++ clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
@@ -887,12 +887,12 @@
 FileID File;
 unsigned Offset;
 std::tie(File, Offset) = SM.getDecomposedLoc(ExpanLoc);
-const llvm::MemoryBuffer *MB = SM.getBuffer(File);
-const char *MacroNameTokenPos = MB->getBufferStart() + Offset;
+llvm::MemoryBufferRef MB = SM.getBufferOrFake(File);
+const char *MacroNameTokenPos = MB.getBufferStart() + Offset;
 
 RawLexer = std::make_unique(SM.getLocForStartOfFile(File), LangOpts,
-   MB->getBufferStart(), MacroNameTokenPos,
-   MB->getBufferEnd());
+   MB.getBufferStart(), MacroNameTokenPos,
+   MB.getBufferEnd());
   }
 
   void next(Token ) {
Index: clang/lib/StaticAnalyzer/Core/IssueHash.cpp
===
--- clang/lib/StaticAnalyzer/Core/IssueHash.cpp
+++ clang/lib/StaticAnalyzer/Core/IssueHash.cpp
@@ -120,7 +120,8 @@
   return "";
 }
 
-static StringRef GetNthLineOfFile(const llvm::MemoryBuffer *Buffer, int Line) {
+static StringRef GetNthLineOfFile(llvm::Optional Buffer,
+  int Line) {
   if (!Buffer)
 return "";
 
@@ -135,7 +136,7 @@
  const LangOptions ) {
   static StringRef Whitespaces = " \t\n";
 
-  StringRef Str = GetNthLineOfFile(SM.getBuffer(L.getFileID(), L),
+  StringRef Str = GetNthLineOfFile(SM.getBufferOrNone(L.getFileID(), L),
L.getExpansionLineNumber());
   StringRef::size_type col = Str.find_first_not_of(Whitespaces);
   if (col == StringRef::npos)
@@ -144,8 +145,8 @@
 col++;
   SourceLocation StartOfLine =
   SM.translateLineCol(SM.getFileID(L), L.getExpansionLineNumber(), col);
-  const llvm::MemoryBuffer *Buffer =
-  SM.getBuffer(SM.getFileID(StartOfLine), StartOfLine);
+  Optional Buffer =
+  SM.getBufferOrNone(SM.getFileID(StartOfLine), StartOfLine);
   if (!Buffer)
 return {};
 
Index: clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
===
--- clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
+++ 

[PATCH] D84362: [NFC] Refactor DiagnosticBuilder and PartialDiagnostic

2020-10-14 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: clang/include/clang/Basic/PartialDiagnostic.h:51
+  : DiagID(DiagID) {
+Allocator = _;
+  }

Is there a particular reason to move field initialization into the body here 
and in other constructors?


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

https://reviews.llvm.org/D84362

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


[PATCH] D88712: [CGBuiltin] Respect asm labels and redefine_extname for builtins with specialized emitting

2020-10-14 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In case my previous comment is not clear: we can do renaming in LLVM, but the 
benefit is small (for a few libcalls (only some really simple libcalls) with 
custom code emitting, if they have `asm(...)`, they are now optimizable). We 
will require a renaming infrastructure in LLVM IR, which is a large 
undertaking. The patch as is is the most practical approach.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88712

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


[PATCH] D86119: [OPENMP50]Allow overlapping mapping in target constrcuts.

2020-10-14 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

In D86119#2330601 , @jdenny wrote:

> In D86119#2330339 , @ABataev wrote:
>
>> In D86119#2330310 , @jdenny wrote:
>>
>>> Thanks for working on this.  Sorry to take so long to review.  Before I try 
>>> to digest the code, I have a few high-level questions.
>>>
>>> Based on the test suite changes, `TARGET_PARAM` is disappearing from many 
>>> cases.  Can you explain a bit how that supports overlapping and reordering?
>>
>> `TARGET_PARAM` is used only for marking the data that should be passed to 
>> the kernel function as an argument. We just generate it in many cases but 
>> the runtime actually does not use them. Thу patch relies on this thing, 
>> otherwise, we may pass an incorrect number of arguments to the kernel 
>> functions.
>
> Is it reasonable to extract that change into a parent patch?  That would at 
> least make the test suite changes easier to follow.

I'll see what I can do about it.

>>> Have you considered issue 2337 for the OpenMP spec and how your 
>>> implementation handles the ambiguous cases cited there?
>>
>> Can you provide the details about this issue?
>
> It discusses ambiguities in the way the spec describes map clause ordering.  
> Here's one example relevant to `present`:
>
>   #pragma omp target exit data map(from: x) map(present, release: x)
>
> One statement in the spec says a map clause with `from` is effectively 
> ordered before one with `release`.  Another statement says a map clause with 
> `present` is effectively ordered before one without.  Which applies in the 
> above example?  In some discussions, people agreed the statement about 
> `present` was intended to have precedence, but the spec doesn't say that.  
> That resolution probably makes sense at entry to a region, but does it make 
> sense at exit?  Would it suppress `from` in this example?  (Actually, should 
> there be two reference counter decrements in this example or just one?)
>
> These ambiguities are the reason I punted on this issue when implementing 
> `present`.  If we can come up with a reasonable implementation for all cases, 
> perhaps we can propose a new wording for the spec.

In tgis implementation, the mapping withthe present modifier will be ordered to 
be the first.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86119

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


[PATCH] D86119: [OPENMP50]Allow overlapping mapping in target constrcuts.

2020-10-14 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

In D86119#2330339 , @ABataev wrote:

> In D86119#2330310 , @jdenny wrote:
>
>> Thanks for working on this.  Sorry to take so long to review.  Before I try 
>> to digest the code, I have a few high-level questions.
>>
>> Based on the test suite changes, `TARGET_PARAM` is disappearing from many 
>> cases.  Can you explain a bit how that supports overlapping and reordering?
>
> `TARGET_PARAM` is used only for marking the data that should be passed to the 
> kernel function as an argument. We just generate it in many cases but the 
> runtime actually does not use them. Thу patch relies on this thing, 
> otherwise, we may pass an incorrect number of arguments to the kernel 
> functions.

Is it reasonable to extract that change into a parent patch?  That would at 
least make the test suite changes easier to follow.

>> Have you considered issue 2337 for the OpenMP spec and how your 
>> implementation handles the ambiguous cases cited there?
>
> Can you provide the details about this issue?

It discusses ambiguities in the way the spec describes map clause ordering.  
Here's one example relevant to `present`:

  #pragma omp target exit data map(from: x) map(present, release: x)

One statement in the spec says a map clause with `from` is effectively ordered 
before one with `release`.  Another statement says a map clause with `present` 
is effectively ordered before one without.  Which applies in the above example? 
 In some discussions, people agreed the statement about `present` was intended 
to have precedence, but the spec doesn't say that.  That resolution probably 
makes sense at entry to a region, but does it make sense at exit?  Would it 
suppress `from` in this example?  (Actually, should there be two reference 
counter decrements in this example or just one?)

These ambiguities are the reason I punted on this issue when implementing 
`present`.  If we can come up with a reasonable implementation for all cases, 
perhaps we can propose a new wording for the spec.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86119

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


  1   2   >