[PATCH] D105457: [clang] Refactor AST printing tests to share more infrastructure

2021-07-12 Thread Nathan Ridge 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 rG20176bc7dd3f: [clang] Refactor AST printing tests to share 
more infrastructure (authored by nridge).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105457

Files:
  clang/unittests/AST/ASTPrint.h
  clang/unittests/AST/DeclPrinterTest.cpp
  clang/unittests/AST/NamedDeclPrinterTest.cpp
  clang/unittests/AST/StmtPrinterTest.cpp

Index: clang/unittests/AST/StmtPrinterTest.cpp
===
--- clang/unittests/AST/StmtPrinterTest.cpp
+++ clang/unittests/AST/StmtPrinterTest.cpp
@@ -38,11 +38,29 @@
   has(compoundStmt(has(stmt().bind("id");
 }
 
+static void PrintStmt(raw_ostream , const ASTContext *Context,
+  const Stmt *S, PrintingPolicyAdjuster PolicyAdjuster) {
+  assert(S != nullptr && "Expected non-null Stmt");
+  PrintingPolicy Policy = Context->getPrintingPolicy();
+  if (PolicyAdjuster)
+PolicyAdjuster(Policy);
+  S->printPretty(Out, /*Helper*/ nullptr, Policy);
+}
+
+template 
+::testing::AssertionResult
+PrintedStmtMatches(StringRef Code, const std::vector ,
+   const Matcher , StringRef ExpectedPrinted,
+   PrintingPolicyAdjuster PolicyAdjuster = nullptr) {
+  return PrintedNodeMatches(Code, Args, NodeMatch, ExpectedPrinted, "",
+  PrintStmt, PolicyAdjuster);
+}
+
 template 
 ::testing::AssertionResult
 PrintedStmtCXXMatches(StdVer Standard, StringRef Code, const T ,
   StringRef ExpectedPrinted,
-  PolicyAdjusterType PolicyAdjuster = None) {
+  PrintingPolicyAdjuster PolicyAdjuster = nullptr) {
   const char *StdOpt;
   switch (Standard) {
   case StdVer::CXX98: StdOpt = "-std=c++98"; break;
@@ -64,7 +82,7 @@
 ::testing::AssertionResult
 PrintedStmtMSMatches(StringRef Code, const T ,
  StringRef ExpectedPrinted,
- PolicyAdjusterType PolicyAdjuster = None) {
+ PrintingPolicyAdjuster PolicyAdjuster = nullptr) {
   std::vector Args = {
 "-std=c++98",
 "-target", "i686-pc-win32",
@@ -79,7 +97,7 @@
 ::testing::AssertionResult
 PrintedStmtObjCMatches(StringRef Code, const T ,
StringRef ExpectedPrinted,
-   PolicyAdjusterType PolicyAdjuster = None) {
+   PrintingPolicyAdjuster PolicyAdjuster = nullptr) {
   std::vector Args = {
 "-ObjC",
 "-fobjc-runtime=macosx-10.12.0",
@@ -202,10 +220,10 @@
 };
 )";
   // No implicit 'this'.
-  ASSERT_TRUE(PrintedStmtCXXMatches(StdVer::CXX11,
-  CPPSource, memberExpr(anything()).bind("id"), "field",
-  PolicyAdjusterType(
-  [](PrintingPolicy ) { PP.SuppressImplicitBase = true; })));
+  ASSERT_TRUE(PrintedStmtCXXMatches(
+  StdVer::CXX11, CPPSource, memberExpr(anything()).bind("id"), "field",
+
+  [](PrintingPolicy ) { PP.SuppressImplicitBase = true; }));
   // Print implicit 'this'.
   ASSERT_TRUE(PrintedStmtCXXMatches(StdVer::CXX11,
   CPPSource, memberExpr(anything()).bind("id"), "this->field"));
@@ -222,11 +240,10 @@
 @end
   )";
   // No implicit 'self'.
-  ASSERT_TRUE(PrintedStmtObjCMatches(ObjCSource, returnStmt().bind("id"),
- "return ivar;\n",
- PolicyAdjusterType([](PrintingPolicy ) {
-   PP.SuppressImplicitBase = true;
- })));
+  ASSERT_TRUE(PrintedStmtObjCMatches(
+  ObjCSource, returnStmt().bind("id"), "return ivar;\n",
+
+  [](PrintingPolicy ) { PP.SuppressImplicitBase = true; }));
   // Print implicit 'self'.
   ASSERT_TRUE(PrintedStmtObjCMatches(ObjCSource, returnStmt().bind("id"),
  "return self->ivar;\n"));
@@ -243,5 +260,6 @@
   // body not printed when TerseOutput is on.
   ASSERT_TRUE(PrintedStmtCXXMatches(
   StdVer::CXX11, CPPSource, lambdaExpr(anything()).bind("id"), "[] {}",
-  PolicyAdjusterType([](PrintingPolicy ) { PP.TerseOutput = true; })));
+
+  [](PrintingPolicy ) { PP.TerseOutput = true; }));
 }
Index: clang/unittests/AST/NamedDeclPrinterTest.cpp
===
--- clang/unittests/AST/NamedDeclPrinterTest.cpp
+++ clang/unittests/AST/NamedDeclPrinterTest.cpp
@@ -15,6 +15,7 @@
 //
 //===--===//
 
+#include "ASTPrint.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/PrettyPrinter.h"
@@ -66,31 +67,11 @@
 const DeclarationMatcher , StringRef ExpectedPrinted,
 StringRef FileName,
 std::function Print) {
-  PrintMatch Printer(std::move(Print));
-  MatchFinder 

[clang] 20176bc - [clang] Refactor AST printing tests to share more infrastructure

2021-07-12 Thread Nathan Ridge via cfe-commits

Author: Nathan Ridge
Date: 2021-07-13T01:48:30-04:00
New Revision: 20176bc7dd3f431db4c3d59b51a9f53d52190c82

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

LOG: [clang] Refactor AST printing tests to share more infrastructure

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

Added: 


Modified: 
clang/unittests/AST/ASTPrint.h
clang/unittests/AST/DeclPrinterTest.cpp
clang/unittests/AST/NamedDeclPrinterTest.cpp
clang/unittests/AST/StmtPrinterTest.cpp

Removed: 




diff  --git a/clang/unittests/AST/ASTPrint.h b/clang/unittests/AST/ASTPrint.h
index c3b6b842316d..0e35846c86f4 100644
--- a/clang/unittests/AST/ASTPrint.h
+++ b/clang/unittests/AST/ASTPrint.h
@@ -19,72 +19,88 @@
 
 namespace clang {
 
-using PolicyAdjusterType =
-Optional>;
-
-static void PrintStmt(raw_ostream , const ASTContext *Context,
-  const Stmt *S, PolicyAdjusterType PolicyAdjuster) {
-  assert(S != nullptr && "Expected non-null Stmt");
-  PrintingPolicy Policy = Context->getPrintingPolicy();
-  if (PolicyAdjuster)
-(*PolicyAdjuster)(Policy);
-  S->printPretty(Out, /*Helper*/ nullptr, Policy);
-}
+using PrintingPolicyAdjuster = llvm::function_ref;
+
+template 
+using NodePrinter =
+std::function;
+
+template 
+using NodeFilter = std::function;
 
+template 
 class PrintMatch : public ast_matchers::MatchFinder::MatchCallback {
+  using PrinterT = NodePrinter;
+  using FilterT = NodeFilter;
+
   SmallString<1024> Printed;
-  unsigned NumFoundStmts;
-  PolicyAdjusterType PolicyAdjuster;
+  unsigned NumFoundNodes;
+  PrinterT Printer;
+  FilterT Filter;
+  PrintingPolicyAdjuster PolicyAdjuster;
 
 public:
-  PrintMatch(PolicyAdjusterType PolicyAdjuster)
-  : NumFoundStmts(0), PolicyAdjuster(PolicyAdjuster) {}
+  PrintMatch(PrinterT Printer, PrintingPolicyAdjuster PolicyAdjuster,
+ FilterT Filter)
+  : NumFoundNodes(0), Printer(std::move(Printer)),
+Filter(std::move(Filter)), PolicyAdjuster(PolicyAdjuster) {}
 
   void run(const ast_matchers::MatchFinder::MatchResult ) override {
-const Stmt *S = Result.Nodes.getNodeAs("id");
-if (!S)
+const NodeType *N = Result.Nodes.getNodeAs("id");
+if (!N || !Filter(N))
   return;
-NumFoundStmts++;
-if (NumFoundStmts > 1)
+NumFoundNodes++;
+if (NumFoundNodes > 1)
   return;
 
 llvm::raw_svector_ostream Out(Printed);
-PrintStmt(Out, Result.Context, S, PolicyAdjuster);
+Printer(Out, Result.Context, N, PolicyAdjuster);
   }
 
   StringRef getPrinted() const { return Printed; }
 
-  unsigned getNumFoundStmts() const { return NumFoundStmts; }
+  unsigned getNumFoundNodes() const { return NumFoundNodes; }
 };
 
-template 
-::testing::AssertionResult
-PrintedStmtMatches(StringRef Code, const std::vector ,
-   const T , StringRef ExpectedPrinted,
-   PolicyAdjusterType PolicyAdjuster = None) {
+template 
+::testing::AssertionResult PrintedNodeMatches(
+StringRef Code, const std::vector ,
+const Matcher , StringRef ExpectedPrinted, StringRef FileName,
+NodePrinter Printer,
+PrintingPolicyAdjuster PolicyAdjuster = nullptr, bool AllowError = false,
+NodeFilter Filter = [](const NodeType *) { return true; }) {
 
-  PrintMatch Printer(PolicyAdjuster);
+  PrintMatch Callback(Printer, PolicyAdjuster, Filter);
   ast_matchers::MatchFinder Finder;
-  Finder.addMatcher(NodeMatch, );
+  Finder.addMatcher(NodeMatch, );
   std::unique_ptr Factory(
   tooling::newFrontendActionFactory());
 
-  if (!tooling::runToolOnCodeWithArgs(Factory->create(), Code, Args))
+  bool ToolResult;
+  if (FileName.empty()) {
+ToolResult = tooling::runToolOnCodeWithArgs(Factory->create(), Code, Args);
+  } else {
+ToolResult =
+tooling::runToolOnCodeWithArgs(Factory->create(), Code, Args, 
FileName);
+  }
+  if (!ToolResult && !AllowError)
 return testing::AssertionFailure()
<< "Parsing error in \"" << Code.str() << "\"";
 
-  if (Printer.getNumFoundStmts() == 0)
-return testing::AssertionFailure() << "Matcher didn't find any statements";
+  if (Callback.getNumFoundNodes() == 0)
+return testing::AssertionFailure() << "Matcher didn't find any nodes";
 
-  if (Printer.getNumFoundStmts() > 1)
+  if (Callback.getNumFoundNodes() > 1)
 return testing::AssertionFailure()
-   << "Matcher should match only one statement (found "
-   << Printer.getNumFoundStmts() << ")";
+   << "Matcher should match only one node (found "
+   << Callback.getNumFoundNodes() << ")";
 
-  if (Printer.getPrinted() != ExpectedPrinted)
+  if (Callback.getPrinted() != ExpectedPrinted)
 return ::testing::AssertionFailure()
<< "Expected \"" << ExpectedPrinted.str() << "\", got 

[PATCH] D105679: [clangd] Add CMake option to (not) link in clang-tidy checks

2021-07-12 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

Will building with this option just prevent linking the clang-tidy checks into 
clangd, or will it also prevent building them in the first place?

In my experience, it's the building that's the primary compile time expense, so 
if the intention is to address https://github.com/clangd/clangd/issues/233, we 
would want to avoid building them as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105679

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


[PATCH] D95588: [RISCV] Implement the MC layer support of P extension

2021-07-12 Thread Jim Lin via Phabricator via cfe-commits
Jim added inline comments.



Comment at: llvm/lib/Target/RISCV/RISCVRegisterInfo.td:69
 
+def sub_lo : SubRegIndex<32>;
+def sub_hi : SubRegIndex<32, 32>;

luismarques wrote:
> jrtc27 wrote:
> > This assumes RV32, and is not clear it applies to register pairs
> What's the best way to address this?
sub_lo and sub_hi are only used for GPRPair register class to extract a 
register from pair registers on RV32.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95588

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


[PATCH] D105869: [Driver] fix PowerPC SPE musl dynamic linker name

2021-07-12 Thread Patrick Oppenlander via Phabricator via cfe-commits
pattop created this revision.
Herald added subscribers: steven.zhang, shchenz, nemanjai.
pattop requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Musl treats PowerPC SPE as a soft-float target (as the PowerPC SPE ABI
is soft-float compatible).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105869

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


Index: clang/lib/Driver/ToolChains/Linux.cpp
===
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -410,6 +410,9 @@
 (Triple.getEnvironment() == llvm::Triple::MuslEABIHF ||
  tools::arm::getARMFloatABI(*this, Args) == 
tools::arm::FloatABI::Hard))
   ArchName += "hf";
+if (Arch == llvm::Triple::ppc &&
+Triple.getSubArch() == llvm::Triple::PPCSubArch_spe)
+  ArchName = "powerpc-sf";
 
 return "/lib/ld-musl-" + ArchName + ".so.1";
   }


Index: clang/lib/Driver/ToolChains/Linux.cpp
===
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -410,6 +410,9 @@
 (Triple.getEnvironment() == llvm::Triple::MuslEABIHF ||
  tools::arm::getARMFloatABI(*this, Args) == tools::arm::FloatABI::Hard))
   ArchName += "hf";
+if (Arch == llvm::Triple::ppc &&
+Triple.getSubArch() == llvm::Triple::PPCSubArch_spe)
+  ArchName = "powerpc-sf";
 
 return "/lib/ld-musl-" + ArchName + ".so.1";
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104420: thread_local support for AIX

2021-07-12 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added inline comments.



Comment at: clang/lib/CodeGen/ItaniumCXXABI.cpp:3004
+} else if (CGM.getTriple().isOSAIX())
+  // On AIX, all thread_local vars will have init routines regardless of
+  // whether they are const-initialized or not.  Since the routine is

Clarify that this statement does not apply if the type is not a class type or 
(possibly multi-dimenional) array of class type and the variable is also 
`constinit`.


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

https://reviews.llvm.org/D104420

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


[PATCH] D105168: [RISCV] Unify the arch string parsing logic to RISCVISAInfo.

2021-07-12 Thread Zakk Chen via Phabricator via cfe-commits
khchen added inline comments.



Comment at: clang/test/Driver/riscv-abi.c:68
 
-// RUN: %clang -target riscv64-unknown-elf %s -### -o %t.o -march=rv64d 
-mabi=lp64d 2>&1 \
+// RUN: %clang -target riscv64-unknown-elf %s -### -o %t.o -march=rv64ifd 
-mabi=lp64d 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-LP64D %s

Why do we need to modify here?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105168

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


[PATCH] D105565: [analyzer] Print time taken to analyze each function

2021-07-12 Thread rithik sharma via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcad9b7f708e2: [analyzer] Print time taken to analyze each 
function (authored by RithikSharma).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D105565?vs=357525=358142#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105565

Files:
  clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
  clang/test/Analysis/analyzer-display-progress.cpp

Index: clang/test/Analysis/analyzer-display-progress.cpp
===
--- clang/test/Analysis/analyzer-display-progress.cpp
+++ clang/test/Analysis/analyzer-display-progress.cpp
@@ -20,11 +20,11 @@
   };
 }
 
-// CHECK: analyzer-display-progress.cpp f()
-// CHECK: analyzer-display-progress.cpp g()
-// CHECK: analyzer-display-progress.cpp h()
-// CHECK: analyzer-display-progress.cpp SomeStruct::f()
-// CHECK: analyzer-display-progress.cpp SomeOtherStruct::f()
-// CHECK: analyzer-display-progress.cpp ns::SomeStruct::f(int)
-// CHECK: analyzer-display-progress.cpp ns::SomeStruct::f(float, ::SomeStruct)
-// CHECK: analyzer-display-progress.cpp ns::SomeStruct::f(float, struct ns::SomeStruct)
+// CHECK: analyzer-display-progress.cpp f() : {{[0-9]+}}
+// CHECK: analyzer-display-progress.cpp g() : {{[0-9]+}}
+// CHECK: analyzer-display-progress.cpp h() : {{[0-9]+}}
+// CHECK: analyzer-display-progress.cpp SomeStruct::f() : {{[0-9]+}}
+// CHECK: analyzer-display-progress.cpp SomeOtherStruct::f() : {{[0-9]+}}
+// CHECK: analyzer-display-progress.cpp ns::SomeStruct::f(int) : {{[0-9]+}}
+// CHECK: analyzer-display-progress.cpp ns::SomeStruct::f(float, ::SomeStruct) : {{[0-9]+}}
+// CHECK: analyzer-display-progress.cpp ns::SomeStruct::f(float, struct ns::SomeStruct) : {{[0-9]+}}
Index: clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
===
--- clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
+++ clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
@@ -128,7 +128,8 @@
 Plugins(plugins), Injector(injector), CTU(CI),
 MacroExpansions(CI.getLangOpts()) {
 DigestAnalyzerOptions();
-if (Opts->PrintStats || Opts->ShouldSerializeStats) {
+if (Opts->AnalyzerDisplayProgress || Opts->PrintStats ||
+Opts->ShouldSerializeStats) {
   AnalyzerTimers = std::make_unique(
   "analyzer", "Analyzer timers");
   SyntaxCheckTimer = std::make_unique(
@@ -138,6 +139,9 @@
   BugReporterTimer = std::make_unique(
   "bugreporter", "Path-sensitive report post-processing time",
   *AnalyzerTimers);
+}
+
+if (Opts->PrintStats || Opts->ShouldSerializeStats) {
   llvm::EnableStatistics(/* PrintOnExit= */ false);
 }
 
@@ -183,6 +187,14 @@
 }
   }
 
+  void DisplayTime(llvm::TimeRecord ) {
+if (!Opts->AnalyzerDisplayProgress) {
+  return;
+}
+llvm::errs() << " : " << llvm::format("%1.1f", Time.getWallTime() * 1000)
+ << " ms\n";
+  }
+
   void DisplayFunction(const Decl *D, AnalysisMode Mode,
ExprEngine::InliningModes IMode) {
 if (!Opts->AnalyzerDisplayProgress)
@@ -210,7 +222,7 @@
 assert(Mode == (AM_Syntax | AM_Path) && "Unexpected mode!");
 
   llvm::errs() << ": " << Loc.getFilename() << ' '
-   << AnalysisDeclContext::getFunctionName(D) << '\n';
+   << AnalysisDeclContext::getFunctionName(D);
 }
   }
 
@@ -608,19 +620,26 @@
   if (Mgr->getAnalysisDeclContext(D)->isBodyAutosynthesized())
 return;
 
-  DisplayFunction(D, Mode, IMode);
   CFG *DeclCFG = Mgr->getCFG(D);
   if (DeclCFG)
 MaxCFGSize.updateMax(DeclCFG->size());
 
+  DisplayFunction(D, Mode, IMode);
   BugReporter BR(*Mgr);
 
   if (Mode & AM_Syntax) {
-if (SyntaxCheckTimer)
+llvm::TimeRecord CheckerStartTime;
+if (SyntaxCheckTimer) {
+  CheckerStartTime = SyntaxCheckTimer->getTotalTime();
   SyntaxCheckTimer->startTimer();
+}
 checkerMgr->runCheckersOnASTBody(D, *Mgr, BR);
-if (SyntaxCheckTimer)
+if (SyntaxCheckTimer) {
   SyntaxCheckTimer->stopTimer();
+  llvm::TimeRecord CheckerEndTime = SyntaxCheckTimer->getTotalTime();
+  CheckerEndTime -= CheckerStartTime;
+  DisplayTime(CheckerEndTime);
+}
   }
 
   BR.FlushReports();
@@ -651,12 +670,19 @@
   ExprEngine Eng(CTU, *Mgr, VisitedCallees, , IMode);
 
   // Execute the worklist algorithm.
-  if (ExprEngineTimer)
+  llvm::TimeRecord ExprEngineStartTime;
+  if (ExprEngineTimer) {
+ExprEngineStartTime = ExprEngineTimer->getTotalTime();
 ExprEngineTimer->startTimer();
+  }
   Eng.ExecuteWorkList(Mgr->getAnalysisDeclContextManager().getStackFrame(D),
   Mgr->options.MaxNodesPerTopLevelFunction);
-  if (ExprEngineTimer)
+  if 

[clang] cad9b7f - [analyzer] Print time taken to analyze each function

2021-07-12 Thread via cfe-commits

Author: SharmaRithik
Date: 2021-07-13T04:52:47Z
New Revision: cad9b7f708e2b2d19d7890494980c5e427d6d4ea

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

LOG: [analyzer] Print time taken to analyze each function
Summary: This patch is a part of an attempt to obtain more
timer data from the analyzer. In this patch, we try to use
LLVM::TimeRecord to save time before starting the analysis
and to print the time that a specific function takes while
getting analyzed.

The timer data is printed along with the
-analyzer-display-progress outputs.

ANALYZE (Syntax): test.c functionName : 0.4 ms
ANALYZE (Path,  Inline_Regular): test.c functionName : 2.6 ms
Authored By: RithikSharma
Reviewer: NoQ, xazax.hun, teemperor, vsavchenko
Reviewed By: NoQ
Differential Revision: https://reviews.llvm.org/D105565

Added: 


Modified: 
clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
clang/test/Analysis/analyzer-display-progress.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp 
b/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
index 03b5c04f553f..31de49033ac2 100644
--- a/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
+++ b/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
@@ -128,7 +128,8 @@ class AnalysisConsumer : public AnalysisASTConsumer,
 Plugins(plugins), Injector(injector), CTU(CI),
 MacroExpansions(CI.getLangOpts()) {
 DigestAnalyzerOptions();
-if (Opts->PrintStats || Opts->ShouldSerializeStats) {
+if (Opts->AnalyzerDisplayProgress || Opts->PrintStats ||
+Opts->ShouldSerializeStats) {
   AnalyzerTimers = std::make_unique(
   "analyzer", "Analyzer timers");
   SyntaxCheckTimer = std::make_unique(
@@ -138,6 +139,9 @@ class AnalysisConsumer : public AnalysisASTConsumer,
   BugReporterTimer = std::make_unique(
   "bugreporter", "Path-sensitive report post-processing time",
   *AnalyzerTimers);
+}
+
+if (Opts->PrintStats || Opts->ShouldSerializeStats) {
   llvm::EnableStatistics(/* PrintOnExit= */ false);
 }
 
@@ -183,6 +187,14 @@ class AnalysisConsumer : public AnalysisASTConsumer,
 }
   }
 
+  void DisplayTime(llvm::TimeRecord ) {
+if (!Opts->AnalyzerDisplayProgress) {
+  return;
+}
+llvm::errs() << " : " << llvm::format("%1.1f", Time.getWallTime() * 1000)
+ << " ms\n";
+  }
+
   void DisplayFunction(const Decl *D, AnalysisMode Mode,
ExprEngine::InliningModes IMode) {
 if (!Opts->AnalyzerDisplayProgress)
@@ -210,7 +222,7 @@ class AnalysisConsumer : public AnalysisASTConsumer,
 assert(Mode == (AM_Syntax | AM_Path) && "Unexpected mode!");
 
   llvm::errs() << ": " << Loc.getFilename() << ' '
-   << AnalysisDeclContext::getFunctionName(D) << '\n';
+   << AnalysisDeclContext::getFunctionName(D);
 }
   }
 
@@ -608,19 +620,26 @@ void AnalysisConsumer::HandleCode(Decl *D, AnalysisMode 
Mode,
   if (Mgr->getAnalysisDeclContext(D)->isBodyAutosynthesized())
 return;
 
-  DisplayFunction(D, Mode, IMode);
   CFG *DeclCFG = Mgr->getCFG(D);
   if (DeclCFG)
 MaxCFGSize.updateMax(DeclCFG->size());
 
+  DisplayFunction(D, Mode, IMode);
   BugReporter BR(*Mgr);
 
   if (Mode & AM_Syntax) {
-if (SyntaxCheckTimer)
+llvm::TimeRecord CheckerStartTime;
+if (SyntaxCheckTimer) {
+  CheckerStartTime = SyntaxCheckTimer->getTotalTime();
   SyntaxCheckTimer->startTimer();
+}
 checkerMgr->runCheckersOnASTBody(D, *Mgr, BR);
-if (SyntaxCheckTimer)
+if (SyntaxCheckTimer) {
   SyntaxCheckTimer->stopTimer();
+  llvm::TimeRecord CheckerEndTime = SyntaxCheckTimer->getTotalTime();
+  CheckerEndTime -= CheckerStartTime;
+  DisplayTime(CheckerEndTime);
+}
   }
 
   BR.FlushReports();
@@ -651,12 +670,19 @@ void AnalysisConsumer::RunPathSensitiveChecks(Decl *D,
   ExprEngine Eng(CTU, *Mgr, VisitedCallees, , IMode);
 
   // Execute the worklist algorithm.
-  if (ExprEngineTimer)
+  llvm::TimeRecord ExprEngineStartTime;
+  if (ExprEngineTimer) {
+ExprEngineStartTime = ExprEngineTimer->getTotalTime();
 ExprEngineTimer->startTimer();
+  }
   Eng.ExecuteWorkList(Mgr->getAnalysisDeclContextManager().getStackFrame(D),
   Mgr->options.MaxNodesPerTopLevelFunction);
-  if (ExprEngineTimer)
+  if (ExprEngineTimer) {
 ExprEngineTimer->stopTimer();
+llvm::TimeRecord ExprEngineEndTime = ExprEngineTimer->getTotalTime();
+ExprEngineEndTime -= ExprEngineStartTime;
+DisplayTime(ExprEngineEndTime);
+  }
 
   if (!Mgr->options.DumpExplodedGraphTo.empty())
 Eng.DumpGraph(Mgr->options.TrimGraph, Mgr->options.DumpExplodedGraphTo);

diff  --git 

[PATCH] D105168: [RISCV] Unify the arch string parsing logic to RISCVISAInfo.

2021-07-12 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng added inline comments.



Comment at: llvm/include/llvm/Support/RISCVISAInfo.h:42
+  // keep entries in canonical order of extension.
+  typedef std::map
+  OrderedExtensionMap;

craig.topper wrote:
> Could this be a sorted vector? Would require a good spot to sort it after all 
> extensions have been added. Are all the extensions added from the parse 
> functions?
All extension are added in parse function, but there might require a lookup and 
add if not found loop when implementing (more complete*) implied extension rule 
in future, so using ordered container would make this easier.

* We don't implement full implied extension rule, like f implied zicsr, d 
implied f...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105168

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


[PATCH] D105637: [clang][Analyzer] Add symbol uninterestingness to bug report.

2021-07-12 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Looks great, thanks for reusing the reusables!




Comment at: clang/lib/StaticAnalyzer/Core/BugReporter.cpp:2260-2261
+  InterestingSymbols.erase(sym);
+  if (const auto *meta = dyn_cast(sym))
+markNotInteresting(meta->getRegion());
+}

You're saying, e.g., "If string length is not interesting then neither is the 
string itself". Or, dunno, "If the raw pointer value is not interesting then 
neither is a smart pointer that was holding it".

I'm not sure about that. I'm pretty sure that no checkers are currently 
affected by this code but I still don't understand your point.

I don't understand the original code in `markInteresting()` either; do we have 
even one test to cover it?

Also note that what you've written is not a correct negation of the original 
code. The correct negation (that would keep the region-metadata relationship in 
sync as originally intended) would be "if the region loses interestingness, so 
does the metadata". Or it has to go both ways. I'm still not sure if any of 
this matters though.

Maybe we should eliminate these extra clauses entirely. If you're not willing 
to investigate whether this is all dead code or it actually does something, I'd 
like to suggest a "FIXME: Is this necessary?" (or something like that) both 
here and in the original code.



Comment at: clang/unittests/StaticAnalyzer/Reusables.h:132
+// A consumer to verify the generated diagnostics.
+class DiagnosticVerifyConsumer : public PathDiagnosticConsumer {
+  ExpectedDiagsTy ExpectedDiags;

We already have [[ 
https://clang.llvm.org/doxygen/classclang_1_1VerifyDiagnosticConsumer.html | 
VerifyDiagnosticConsumer ]]. Maybe `VerifyPathDiagnosticConsumer` to put 
emphasis on path-sensitivity (which implies usefulness in unittests because 
`VerifyDiagnosticConsumer` operates when all diagnostics are already 
indistinguishably flattened) and on its similarity to 
`VerifyDiagnosticConsumer`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105637

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


[PATCH] D105168: [RISCV] Unify the arch string parsing logic to RISCVISAInfo.

2021-07-12 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng updated this revision to Diff 358130.
kito-cheng added a comment.

Changes:

- Using RISCVISAInfo in riscv::getRISCVABI
- Allow rv32e for -march.
- Address review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105168

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  clang/lib/Basic/Targets/RISCV.h
  clang/lib/Driver/ToolChains/Arch/RISCV.cpp
  clang/test/Driver/riscv-abi.c
  clang/test/Driver/riscv-arch.c
  llvm/include/llvm/Support/RISCVISAInfo.h
  llvm/lib/Support/CMakeLists.txt
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
  llvm/test/MC/RISCV/attribute-arch.s
  llvm/test/MC/RISCV/attribute-with-insts.s
  llvm/test/MC/RISCV/invalid-attribute.s

Index: llvm/test/MC/RISCV/invalid-attribute.s
===
--- llvm/test/MC/RISCV/invalid-attribute.s
+++ llvm/test/MC/RISCV/invalid-attribute.s
@@ -7,10 +7,10 @@
 # RUN: not llvm-mc %s -triple=riscv64 -filetype=asm 2>&1 | FileCheck %s
 
 .attribute arch, "foo"
-# CHECK: [[@LINE-1]]:18: error: bad arch string foo
+# CHECK: [[@LINE-1]]:18: error: invalid arch name 'foo', string must begin with rv32{i,e,g} or rv64{i,g}
 
 .attribute arch, "rv32i2p0_y2p0"
-# CHECK: [[@LINE-1]]:18: error: bad arch string y2p0
+# CHECK: [[@LINE-1]]:18: error: invalid arch name 'rv32i2p0_y2p0', invalid standard user-level extension 'y'
 
 .attribute stack_align, "16"
 # CHECK: [[@LINE-1]]:25: error: expected numeric constant
Index: llvm/test/MC/RISCV/attribute-with-insts.s
===
--- llvm/test/MC/RISCV/attribute-with-insts.s
+++ llvm/test/MC/RISCV/attribute-with-insts.s
@@ -10,7 +10,7 @@
 # RUN:   | llvm-objdump --triple=riscv64 -d -M no-aliases - \
 # RUN:   | FileCheck -check-prefix=CHECK-INST %s
 
-.attribute arch, "rv64i2p0_m2p0_a2p0_d2p0_c2p0"
+.attribute arch, "rv64i2p0_m2p0_a2p0_f2p0_d2p0_c2p0"
 
 # CHECK-INST: lr.w t0, (t1)
 lr.w t0, (t1)
Index: llvm/test/MC/RISCV/attribute-arch.s
===
--- llvm/test/MC/RISCV/attribute-arch.s
+++ llvm/test/MC/RISCV/attribute-arch.s
@@ -9,9 +9,6 @@
 .attribute arch, "rv32i2"
 # CHECK: attribute  5, "rv32i2p0"
 
-.attribute arch, "rv32i2p"
-# CHECK: attribute  5, "rv32i2p0"
-
 .attribute arch, "rv32i2p0"
 # CHECK: attribute  5, "rv32i2p0"
 
@@ -33,14 +30,14 @@
 .attribute arch, "rv32ima2p0_fdc"
 # CHECK: attribute  5, "rv32i2p0_m2p0_a2p0_f2p0_d2p0_c2p0"
 
-.attribute arch, "rv32ima2p_fdc"
+.attribute arch, "rv32ima2p0_fdc"
 # CHECK: attribute  5, "rv32i2p0_m2p0_a2p0_f2p0_d2p0_c2p0"
 
 .attribute arch, "rv32ib"
 # CHECK: attribute  5, "rv32i2p0_b0p93_zba0p93_zbb0p93_zbc0p93_zbe0p93_zbf0p93_zbm0p93_zbp0p93_zbr0p93_zbs0p93_zbt0p93"
 
 .attribute arch, "rv32iv"
-# CHECK: attribute  5, "rv32i2p0_v0p10"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvlsseg0p10"
 
 .attribute arch, "rv32izba"
 # CHECK: attribute  5, "rv32i2p0_zba0p93"
Index: llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
===
--- llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
+++ llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
@@ -35,6 +35,7 @@
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Support/RISCVAttributes.h"
+#include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/Support/TargetRegistry.h"
 
 #include 
@@ -50,6 +51,10 @@
 STATISTIC(RISCVNumInstrsCompressed,
   "Number of RISC-V Compressed instructions emitted");
 
+namespace llvm {
+extern const SubtargetFeatureKV RISCVFeatureKV[RISCV::NumSubtargetFeatures];
+}
+
 namespace {
 struct RISCVOperand;
 
@@ -2027,113 +2032,39 @@
 
   if (Tag == RISCVAttrs::ARCH) {
 StringRef Arch = StringValue;
-if (Arch.consume_front("rv32"))
+for (auto Feature : RISCVFeatureKV) {
+  if (llvm::RISCVISAInfo::isSupportedExtension(
+  Feature.Key, /* CheckExperimental */ true)) {
+clearFeatureBits(Feature.Value, Feature.Key);
+  }
+}
+
+llvm::RISCVISAInfo ISAInfo;
+if (auto E =
+ISAInfo.parse(StringValue, /* EnableExperimentalExtension */ true,
+  /* ExperimentalExtensionVersionCheck */ false)) {
+  std::string Buffer;
+  raw_string_ostream OutputErrMsg(Buffer);
+  handleAllErrors(std::move(E), [&](llvm::StringError ) {
+OutputErrMsg << "invalid arch name '" << Arch << "', "
+ << ErrMsg.getMessage();
+  });
+
+  return Error(ValueExprLoc, OutputErrMsg.str());
+}
+
+for (auto Feature : RISCVFeatureKV) {
+  if (ISAInfo.hasExtension(Feature.Key)) {
+setFeatureBits(Feature.Value, Feature.Key);
+  }
+}
+
+if (ISAInfo.getXLen() == 32)
   clearFeatureBits(RISCV::Feature64Bit, "64bit");
-else if 

[PATCH] D105819: [analyzer] MallocChecker: Add a visitor to leave a note on functions that could have, but did not change ownership on leaked memory

2021-07-12 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

This is amazing, great progress!

I added the parent revision because it didn't compile on pre-merge checks 
otherwise.




Comment at: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp:801
+// must be a superset of, but not necessarily equal to ExitOwners.
+return !llvm::set_is_subset(ExitOwners, CurrOwners);
+  }

Can you also comment on what's, generally, the default scenario / motivating 
example where this is necessary? What makes you hunt down store bindings that 
didn't cause an escape to happen (given that an escape would have been a state 
change)? IIUC this is for the situation when the callee stores the pointer in a 
caller-local variable and in this case you don't want to claim that ownership 
didn't change?



Comment at: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp:809-810
+return std::make_shared(
+L, "Returning without changing the ownership status of allocated "
+   "memory");
+  }

I suggest: `"Returning without deallocating memory or storing the pointer for 
later deallocation"`. Still a bit flimsy but less jargony.



Comment at: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp:832-833
+  ArrayRef Parameters, unsigned ParamIdx) override {
+// TODO: Check whether the allocated memory was actually passed into the
+// function.
+return emitNote(N);

How difficult would it be to re-use this part as well?



Comment at: clang/test/Analysis/NewDeleteLeaks.cpp:104-106
+// TODO: We don't want a note here. sink() doesn't seem like a function that
+// even attempts to take care of any memory ownership problems.
+namespace memory_passed_into_fn_that_doesnt_intend_to_free {

How do you think this is different from the very first test, 
`memory_allocated_in_fn_call()`? Is this just because of how the pointer is put 
into a variable first? This function is kinda still the only place that could 
free memory.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105819

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


[PATCH] D102728: [clang][Sema] removes -Wfree-nonheap-object reference param false positive

2021-07-12 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb updated this revision to Diff 358127.
cjdb marked 6 inline comments as done.
cjdb added a comment.

responds to feedback


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102728

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/warn-free-nonheap-object.cpp
  mlir/lib/IR/OperationSupport.cpp

Index: mlir/lib/IR/OperationSupport.cpp
===
--- mlir/lib/IR/OperationSupport.cpp
+++ mlir/lib/IR/OperationSupport.cpp
@@ -237,9 +237,7 @@
   if (isDynamicStorage()) {
 TrailingOperandStorage  = getDynamicStorage();
 storage.~TrailingOperandStorage();
-// Workaround false positive in -Wfree-nonheap-object
-auto *mem = 
-free(mem);
+free();
   } else {
 getInlineStorage().~TrailingOperandStorage();
   }
@@ -373,11 +371,8 @@
 new ([numOperands]) OpOperand(owner);
 
   // If the current storage is also dynamic, free it.
-  if (isDynamicStorage()) {
-// Workaround false positive in -Wfree-nonheap-object
-auto *mem = 
-free(mem);
-  }
+  if (isDynamicStorage())
+free();
 
   // Update the storage representation to use the new dynamic storage.
   dynamicStorage.setPointerAndInt(newStorage, true);
Index: clang/test/Sema/warn-free-nonheap-object.cpp
===
--- clang/test/Sema/warn-free-nonheap-object.cpp
+++ clang/test/Sema/warn-free-nonheap-object.cpp
@@ -10,23 +10,34 @@
 
 int GI;
 
+void free_reference(char ) { ::free(); }
+void free_reference(char &) { ::free(); }
+void std_free_reference(char ) { std::free(); }
+void std_free_reference(char &) { std::free(); }
+
 struct S {
-  operator char *() { return ptr; }
+  operator char *() { return ptr1; }
 
   void CFree() {
-::free(); // expected-warning {{attempt to call free on non-heap object 'ptr'}}
-::free();   // expected-warning {{attempt to call free on non-heap object 'I'}}
-::free(ptr);
+::free(); // expected-warning {{attempt to call free on non-heap object 'ptr1'}}
+::free();// expected-warning {{attempt to call free on non-heap object 'I'}}
+::free(ptr1);
+free_reference(*ptr2);
+free_reference(static_cast(*ptr3));
   }
 
   void CXXFree() {
-std::free(); // expected-warning {{attempt to call std::free on non-heap object 'ptr'}}
-std::free();   // expected-warning {{attempt to call std::free on non-heap object 'I'}}
-std::free(ptr);
+std::free(); // expected-warning {{attempt to call std::free on non-heap object 'ptr1'}}
+std::free();// expected-warning {{attempt to call std::free on non-heap object 'I'}}
+std::free(ptr1);
+std_free_reference(*ptr2);
+std_free_reference(static_cast(*ptr3));
   }
 
 private:
-  char *ptr = (char *)std::malloc(10);
+  char *ptr1 = (char *)std::malloc(10);
+  char *ptr2 = (char *)std::malloc(10);
+  char *ptr3 = (char *)std::malloc(10);
   static int I;
 };
 
@@ -93,6 +104,14 @@
 void *P = std::malloc(8);
 std::free(P);
   }
+  {
+char* P = (char *)std::malloc(2);
+std_free_reference(*P);
+  }
+  {
+char* P = (char *)std::malloc(2);
+std_free_reference(static_cast(*P));
+  }
   {
 int A[] = {0, 1, 2, 3};
 std::free(A); // expected-warning {{attempt to call std::free on non-heap object 'A'}}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -10637,8 +10637,9 @@
  const UnaryOperator *UnaryExpr) {
   if (const auto *Lvalue = dyn_cast(UnaryExpr->getSubExpr())) {
 const Decl *D = Lvalue->getDecl();
-if (isa(D))
-  return CheckFreeArgumentsOnLvalue(S, CalleeName, UnaryExpr, D);
+if (isa(D))
+  if (!dyn_cast(D)->getType()->isReferenceType())
+return CheckFreeArgumentsOnLvalue(S, CalleeName, UnaryExpr, D);
   }
 
   if (const auto *Lvalue = dyn_cast(UnaryExpr->getSubExpr()))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D105360: [PowerPC] Fix popcntb XL Compat Builtin for 32bit

2021-07-12 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai accepted this revision.
nemanjai added a comment.
This revision is now accepted and ready to land.

LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105360

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


[PATCH] D105001: [Clang][RISCV] Support half-precision floating point for RVV intrinsics.

2021-07-12 Thread Zakk Chen via Phabricator via cfe-commits
khchen added inline comments.



Comment at: clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfadd.c:13
 
+// ASM-NOT: warning
 #include 

HsiangKai wrote:
> craig.topper wrote:
> > Do you plan to bring back the ASM check for all tests?
> No, I will remove it. This is the first patch to enable half-precision for 
> RVV intrinsics. I just added it to ensure the backend could handle it 
> correctly.
I think you will remove riscv32 tests too, right?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105001

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


[PATCH] D103527: [Clang][RISCV] Implement vlseg and vlsegff.

2021-07-12 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: clang/include/clang/Basic/riscv_vector.td:836
+  clang::CharUnits Align =
+  CGM.getNaturalTypeAlignment(getContext().getSizeType());
+  llvm::Value *V;

I don't think this alignment is correct. A vint16mf4_t creates an alloca with 
align of 2 and vint8mf4_t creates an alloca with an align of 1. So I think the 
store here needs to match the alignment you would get for the type we're 
storing. This is an issue in the earlier vlseg patch as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103527

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


[PATCH] D104714: [UpdateCCTestChecks] Support --check-globals

2021-07-12 Thread Tom Stellard via Phabricator via cfe-commits
tstellar added a comment.

It looks like this patch breaks the 
utils/update_cc_test_checks/check-globals.test on stand-alone builds of clang, 
because it hard codes lit to lit.py in the llvm source tree.  I think it should 
using the lit passed to -DLLVM_EXTERNAL_LIT= (if that option was specified).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104714

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


[PATCH] D104601: [Preprocessor] Implement -fnormalize-whitespace.

2021-07-12 Thread Michael Kruse via Phabricator via cfe-commits
Meinersbur added a comment.

ping

It would be nice if we could get this into clang 13 since the ccache part 
detects support for `-fnormalize-whitespace` when detecting clang 13+. Probing 
the compiler for whether it supports `-fnormalize-whitespace` on every run 
would be prohibitively expensive.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104601

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


[PATCH] D98798: Produce warning for performing pointer arithmetic on a null pointer.

2021-07-12 Thread Kelvin Li via Phabricator via cfe-commits
kkwli0 added a comment.

Is the diff from HEAD?


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

https://reviews.llvm.org/D98798

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


[PATCH] D105014: added some example code for llvm::Expected

2021-07-12 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added subscribers: lhames, dblaikie.
dblaikie added a comment.

+@lhames for context as the author/owner of `llvm::Error` and associated things.

Perhaps it'd be handy to have some descriptions of the problems you 
encountered, @kuhnel, and how you went about trying to resolve them, to help 
understand where things are lacking.

> @sammccall 
> I agree Error is confusing and better docs might help.
> (Not as much as removing the confusing part of the design, but I that seems 
> hard at this point!)

Maybe in this review, or maybe elsewhere: might be good to have some details on 
your perspective here?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105014

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


[PATCH] D105858: opencl-c.h: add 3.0 optional extension support for a few more bits

2021-07-12 Thread Dave Airlie via Phabricator via cfe-commits
airlied created this revision.
airlied added a project: clang.
Herald added subscribers: ldrumm, Anastasia, yaxunl.
airlied requested review of this revision.
Herald added a subscriber: cfe-commits.

These 3 are fairly simple, pipes, workgroups and subgroups.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105858

Files:
  clang/lib/Headers/opencl-c-base.h
  clang/lib/Headers/opencl-c.h


Index: clang/lib/Headers/opencl-c.h
===
--- clang/lib/Headers/opencl-c.h
+++ clang/lib/Headers/opencl-c.h
@@ -15142,7 +15142,7 @@
 
 // OpenCL v2.0 s6.13.15 - Work-group Functions
 
-#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
+#if defined(__opencl_c_work_group_collective_functions)
 int __ovld __conv work_group_all(int predicate);
 int __ovld __conv work_group_any(int predicate);
 
@@ -15240,12 +15240,12 @@
 double __ovld __conv work_group_scan_inclusive_max(double x);
 #endif //cl_khr_fp64
 
-#endif //defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= 
CL_VERSION_2_0)
+#endif //defined(__opencl_c_work_group_collective_functions)
 
 // OpenCL v2.0 s6.13.16 - Pipe Functions
-#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
+#if defined(__opencl_c_pipes)
 bool __ovld is_valid_reserve_id(reserve_id_t reserve_id);
-#endif //defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= 
CL_VERSION_2_0)
+#endif //defined(__opencl_c_pipes)
 
 
 // OpenCL v2.0 s6.13.17 - Enqueue Kernels
@@ -15282,21 +15282,21 @@
 
 // OpenCL Extension v2.0 s9.17 - Sub-groups
 
-#if defined(cl_intel_subgroups) || defined(cl_khr_subgroups)
+#if defined(cl_intel_subgroups) || defined(cl_khr_subgroups) || 
defined(__opencl_c_subgroups)
 // Shared Sub Group Functions
 uint__ovld get_sub_group_size(void);
 uint__ovld get_max_sub_group_size(void);
 uint__ovld get_num_sub_groups(void);
-#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
+#if defined(__opencl_c_subgroups)
 uint__ovld get_enqueued_num_sub_groups(void);
-#endif //defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= 
CL_VERSION_2_0)
+#endif //defined(__opencl_c_subgroups)
 uint__ovld get_sub_group_id(void);
 uint__ovld get_sub_group_local_id(void);
 
 void__ovld __conv sub_group_barrier(cl_mem_fence_flags flags);
-#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
+#if defined(__opencl_c_subgroups)
 void__ovld __conv sub_group_barrier(cl_mem_fence_flags flags, memory_scope 
scope);
-#endif //defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= 
CL_VERSION_2_0)
+#endif //defined(__opencl_c_subgroups)
 
 int __ovld __conv sub_group_all(int predicate);
 int __ovld __conv sub_group_any(int predicate);
@@ -15381,7 +15381,7 @@
 double  __ovld __conv sub_group_scan_inclusive_max(double x);
 #endif //cl_khr_fp64
 
-#endif //cl_khr_subgroups cl_intel_subgroups
+#endif //cl_khr_subgroups cl_intel_subgroups __opencl_c_subgroups
 
 #if defined(cl_khr_subgroup_extended_types)
 char __ovld __conv sub_group_broadcast( char value, uint index );
Index: clang/lib/Headers/opencl-c-base.h
===
--- clang/lib/Headers/opencl-c-base.h
+++ clang/lib/Headers/opencl-c-base.h
@@ -326,7 +326,7 @@
   memory_scope_all_devices = memory_scope_all_svm_devices,
 #endif // __OPENCL_C_VERSION__ >= CL_VERSION_3_0
 #endif // defined(__opencl_c_atomic_scope_all_devices)
-#if defined(cl_intel_subgroups) || defined(cl_khr_subgroups)
+#if defined(cl_intel_subgroups) || defined(cl_khr_subgroups) || 
defined(__opencl_c_subgroups)
   memory_scope_sub_group = __OPENCL_MEMORY_SCOPE_SUB_GROUP
 #endif
 } memory_scope;


Index: clang/lib/Headers/opencl-c.h
===
--- clang/lib/Headers/opencl-c.h
+++ clang/lib/Headers/opencl-c.h
@@ -15142,7 +15142,7 @@
 
 // OpenCL v2.0 s6.13.15 - Work-group Functions
 
-#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
+#if defined(__opencl_c_work_group_collective_functions)
 int __ovld __conv work_group_all(int predicate);
 int __ovld __conv work_group_any(int predicate);
 
@@ -15240,12 +15240,12 @@
 double __ovld __conv work_group_scan_inclusive_max(double x);
 #endif //cl_khr_fp64
 
-#endif //defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
+#endif //defined(__opencl_c_work_group_collective_functions)
 
 // OpenCL v2.0 s6.13.16 - Pipe Functions
-#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
+#if defined(__opencl_c_pipes)
 bool __ovld is_valid_reserve_id(reserve_id_t reserve_id);
-#endif //defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
+#endif //defined(__opencl_c_pipes)
 
 
 // OpenCL v2.0 s6.13.17 - Enqueue Kernels
@@ -15282,21 +15282,21 @@
 
 // OpenCL Extension v2.0 s9.17 - Sub-groups
 
-#if 

[PATCH] D105660: [PowerPC][AIX] Add warning when alignment is incompatible with XL

2021-07-12 Thread Zarko Todorovski via Phabricator via cfe-commits
ZarkoCA marked an inline comment as done.
ZarkoCA added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:3255-3256
+def warn_not_xl_compatible
+: Warning<"requested alignment of arguments 16 bytes or greater is not"
+  " compatible with previous versions of the AIX XL compiler">,
+  InGroup>;

aaron.ballman wrote:
> Should we be talking about the AIX XL compiler in a Clang diagnostic?
I see your point. Sorry if this isn't what is supposed to be done or if it 
doesn't a good precedent.

The reasons for adding this warning is that our back end implementation isn't 
totally compatible with XL now and, while buggy, users on AIX may expect clang 
and xlclang to be compatible since AIX is the reference compiler.  The xlclang 
name implies it's clang based and it's possible for users to expect some sort 
of binary compatibility.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105660

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


[PATCH] D104420: thread_local support for AIX

2021-07-12 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added inline comments.



Comment at: clang/lib/CodeGen/ItaniumCXXABI.cpp:3003-3010
+} else if (CGM.getTriple().isOSAIX())
+  // On AIX, all thread_local vars will have init routines regardless of
+  // whether they are const-initialized or not.  Since the routine is
+  // guaranteed to exist, we can unconditionally call it without testing
+  // for its existance.  This avoids potentially unresolved weak symbols
+  // which the AIX linker isn't happy with.
+  Builder.CreateCall(InitFnTy, Init);

Minor nit: The coding guidelines have been updated for some time to discourage 
mixed bracing on if/else chains (see example
```
// Use braces for the `if` block to keep it uniform with the else block.
```
).



Comment at: clang/lib/CodeGen/ItaniumCXXABI.cpp:4790
+llvm::Value *Arg2 = llvm::ConstantExpr::getBitCast(
+cast(dtor.getCallee()), FpTy);
+CGF.EmitNounwindRuntimeCall(AtExit, {Arg1, Arg2});

hubert.reinterpretcast wrote:
> The function registered needs to be something more like what 
> `createAtExitStub` stub creates. Otherwise, the destructor will not be able 
> to reference `*this` correctly.
> 
> As it is, the registered function is currently just the destructor itself:
> ```
> $ clang++ -target powerpc64-ibm-aix -emit-llvm -S -o - -xc++ -<<<$'struct A { 
> ~A(); }; thread_local A a;' | grep -C2 __pt_atexit_np
> define internal void @__cxx_global_var_init() #0 {
> entry:
>   %0 = call i32 (i32, i32 (i32, ...)*, ...) @__pt_atexit_np(i32 0, i32 (i32, 
> ...)* bitcast (void (%struct.A*)* @_ZN1AD1Ev to i32 (i32, ...)*)) #3
>   ret void
> }
> --
> declare void @_ZN1AD1Ev(%struct.A* nonnull align 1 dereferenceable(1)) 
> unnamed_addr #1
> 
> declare i32 @__pt_atexit_np(i32, i32 (i32, ...)*, ...)
> 
> ; Function Attrs: noinline
> Return:  0x00:0   Mon Jul 12 15:24:15 2021 EDT
> ```
Just noting that the callback function registered by the IBM XL compiler does 
not make an effort to return 0 (but the documentation says the handler "must" 
return 0: 
https://www.ibm.com/docs/en/aix/7.2?topic=p-pthread-atexit-np-subroutine).


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

https://reviews.llvm.org/D104420

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


[PATCH] D105835: [Driver] Let -fno-integrated-as -gdwarf-5 use -fdwarf-directory-asm

2021-07-12 Thread Fangrui Song 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 rG51fc742ce716: [Driver] Let -fno-integrated-as -gdwarf-5 use 
-fdwarf-directory-asm (authored by MaskRay).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105835

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/debug-options.c


Index: clang/test/Driver/debug-options.c
===
--- clang/test/Driver/debug-options.c
+++ clang/test/Driver/debug-options.c
@@ -424,3 +424,14 @@
 // GDWARF64_VER:  error: invalid argument '-gdwarf64' only allowed with 
'DWARFv3 or greater'
 // GDWARF64_32ARCH: error: invalid argument '-gdwarf64' only allowed with '64 
bit architecture'
 // GDWARF64_ELF: error: invalid argument '-gdwarf64' only allowed with 'ELF 
platforms'
+
+/// Default to -fno-dwarf-directory-asm for -fno-integrated-as before DWARF v5.
+// RUN: %clang -### -target x86_64 -c -gdwarf-2 %s 2>&1 | FileCheck 
--check-prefix=DIRECTORY %s
+// RUN: %clang -### -target x86_64 -c -gdwarf-5 %s 2>&1 | FileCheck 
--check-prefix=DIRECTORY %s
+// RUN: %clang -### -target x86_64 -c -gdwarf-4 -fno-integrated-as %s 2>&1 | 
FileCheck --check-prefix=NODIRECTORY %s
+// RUN: %clang -### -target x86_64 -c -gdwarf-5 -fno-integrated-as %s 2>&1 | 
FileCheck --check-prefix=DIRECTORY %s
+
+// RUN: %clang -### -target x86_64 -c -gdwarf-4 -fno-dwarf-directory-asm %s 
2>&1 | FileCheck --check-prefix=NODIRECTORY %s
+
+// DIRECTORY-NOT: "-fno-dwarf-directory-asm"
+// NODIRECTORY: "-fno-dwarf-directory-asm"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -490,14 +490,6 @@
   Default);
 }
 
-static bool ShouldDisableDwarfDirectory(const ArgList ,
-const ToolChain ) {
-  bool UseDwarfDirectory =
-  Args.hasFlag(options::OPT_fdwarf_directory_asm,
-   options::OPT_fno_dwarf_directory_asm, TC.useIntegratedAs());
-  return !UseDwarfDirectory;
-}
-
 // Convert an arg of the form "-gN" or "-ggdbN" or one of their aliases
 // to the corresponding DebugInfoKind.
 static codegenoptions::DebugInfoKind DebugLevelToInfoKind(const Arg ) {
@@ -4175,6 +4167,14 @@
 }
   }
 
+  // To avoid join/split of directory+filename, the integrated assembler 
prefers
+  // the directory form of .file on all DWARF versions. GNU as doesn't allow 
the
+  // form before DWARF v5.
+  if (!Args.hasFlag(options::OPT_fdwarf_directory_asm,
+options::OPT_fno_dwarf_directory_asm,
+TC.useIntegratedAs() || EffectiveDWARFVersion >= 5))
+CmdArgs.push_back("-fno-dwarf-directory-asm");
+
   // Decide how to render forward declarations of template instantiations.
   // SCE wants full descriptions, others just get them in the name.
   if (DebuggerTuning == llvm::DebuggerKind::SCE)
@@ -5506,9 +5506,6 @@
   CmdArgs.push_back("-fno-gnu-keywords");
   }
 
-  if (ShouldDisableDwarfDirectory(Args, TC))
-CmdArgs.push_back("-fno-dwarf-directory-asm");
-
   if (!ShouldEnableAutolink(Args, TC, JA))
 CmdArgs.push_back("-fno-autolink");
 


Index: clang/test/Driver/debug-options.c
===
--- clang/test/Driver/debug-options.c
+++ clang/test/Driver/debug-options.c
@@ -424,3 +424,14 @@
 // GDWARF64_VER:  error: invalid argument '-gdwarf64' only allowed with 'DWARFv3 or greater'
 // GDWARF64_32ARCH: error: invalid argument '-gdwarf64' only allowed with '64 bit architecture'
 // GDWARF64_ELF: error: invalid argument '-gdwarf64' only allowed with 'ELF platforms'
+
+/// Default to -fno-dwarf-directory-asm for -fno-integrated-as before DWARF v5.
+// RUN: %clang -### -target x86_64 -c -gdwarf-2 %s 2>&1 | FileCheck --check-prefix=DIRECTORY %s
+// RUN: %clang -### -target x86_64 -c -gdwarf-5 %s 2>&1 | FileCheck --check-prefix=DIRECTORY %s
+// RUN: %clang -### -target x86_64 -c -gdwarf-4 -fno-integrated-as %s 2>&1 | FileCheck --check-prefix=NODIRECTORY %s
+// RUN: %clang -### -target x86_64 -c -gdwarf-5 -fno-integrated-as %s 2>&1 | FileCheck --check-prefix=DIRECTORY %s
+
+// RUN: %clang -### -target x86_64 -c -gdwarf-4 -fno-dwarf-directory-asm %s 2>&1 | FileCheck --check-prefix=NODIRECTORY %s
+
+// DIRECTORY-NOT: "-fno-dwarf-directory-asm"
+// NODIRECTORY: "-fno-dwarf-directory-asm"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -490,14 +490,6 @@
   Default);
 }
 
-static bool ShouldDisableDwarfDirectory(const ArgList ,
-const ToolChain ) {
-  bool 

[clang] 51fc742 - [Driver] Let -fno-integrated-as -gdwarf-5 use -fdwarf-directory-asm

2021-07-12 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2021-07-12T15:46:20-07:00
New Revision: 51fc742ce716a09359f4f87ffe3876cb7ff9479d

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

LOG: [Driver] Let -fno-integrated-as -gdwarf-5 use -fdwarf-directory-asm

While GNU as only allows the directory form of the .file directive for DWARF v5,
the integrated assembler prefers the directory form on all DWARF versions
(-fdwarf-directory-asm).

We currently set CC1 -fno-dwarf-directory-asm for -fno-integrated-as -gdwarf-5
which may cause the directory entry 0 and the filename entry 0 to be incorrect
(see D105662 and the example below). This patch makes -fno-integrated-as 
-gdwarf-5 use
-fdwarf-directory-asm as well.

```
cd /tmp/c

before
% clang -g -gdwarf-5 -fno-integrated-as e/a.c -S -o - | grep '\.file.*0'
.file   0 "/tmp/c/e/a.c" md5 0x97e31cee64b4e58a4af8787512d735b6
% clang -g -gdwarf-5 -fno-integrated-as e/a.c -c
% llvm-dwarfdump a.o | grep include_directories
include_directories[  0] = "/tmp/c/e"

after
% clang -g -gdwarf-5 -fno-integrated-as e/a.c -S -o - | grep '\.file.*0'
.file   0 "/tmp/c" "e/a.c" md5 0x97e31cee64b4e58a4af8787512d735b6
% clang -g -gdwarf-5 -fno-integrated-as e/a.c -c
% llvm-dwarfdump a.o | grep include_directories
include_directories[  0] = "/tmp/c"
```

Reviewed By: #debug-info, dblaikie, osandov

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/debug-options.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 85204ceaa49a2..4336a25f091c4 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -490,14 +490,6 @@ static bool ShouldEnableAutolink(const ArgList , 
const ToolChain ,
   Default);
 }
 
-static bool ShouldDisableDwarfDirectory(const ArgList ,
-const ToolChain ) {
-  bool UseDwarfDirectory =
-  Args.hasFlag(options::OPT_fdwarf_directory_asm,
-   options::OPT_fno_dwarf_directory_asm, TC.useIntegratedAs());
-  return !UseDwarfDirectory;
-}
-
 // Convert an arg of the form "-gN" or "-ggdbN" or one of their aliases
 // to the corresponding DebugInfoKind.
 static codegenoptions::DebugInfoKind DebugLevelToInfoKind(const Arg ) {
@@ -4175,6 +4167,14 @@ static void renderDebugOptions(const ToolChain , 
const Driver ,
 }
   }
 
+  // To avoid join/split of directory+filename, the integrated assembler 
prefers
+  // the directory form of .file on all DWARF versions. GNU as doesn't allow 
the
+  // form before DWARF v5.
+  if (!Args.hasFlag(options::OPT_fdwarf_directory_asm,
+options::OPT_fno_dwarf_directory_asm,
+TC.useIntegratedAs() || EffectiveDWARFVersion >= 5))
+CmdArgs.push_back("-fno-dwarf-directory-asm");
+
   // Decide how to render forward declarations of template instantiations.
   // SCE wants full descriptions, others just get them in the name.
   if (DebuggerTuning == llvm::DebuggerKind::SCE)
@@ -5506,9 +5506,6 @@ void Clang::ConstructJob(Compilation , const JobAction 
,
   CmdArgs.push_back("-fno-gnu-keywords");
   }
 
-  if (ShouldDisableDwarfDirectory(Args, TC))
-CmdArgs.push_back("-fno-dwarf-directory-asm");
-
   if (!ShouldEnableAutolink(Args, TC, JA))
 CmdArgs.push_back("-fno-autolink");
 

diff  --git a/clang/test/Driver/debug-options.c 
b/clang/test/Driver/debug-options.c
index 54a8a6a3f74a9..3b1f1d555bbc7 100644
--- a/clang/test/Driver/debug-options.c
+++ b/clang/test/Driver/debug-options.c
@@ -424,3 +424,14 @@
 // GDWARF64_VER:  error: invalid argument '-gdwarf64' only allowed with 
'DWARFv3 or greater'
 // GDWARF64_32ARCH: error: invalid argument '-gdwarf64' only allowed with '64 
bit architecture'
 // GDWARF64_ELF: error: invalid argument '-gdwarf64' only allowed with 'ELF 
platforms'
+
+/// Default to -fno-dwarf-directory-asm for -fno-integrated-as before DWARF v5.
+// RUN: %clang -### -target x86_64 -c -gdwarf-2 %s 2>&1 | FileCheck 
--check-prefix=DIRECTORY %s
+// RUN: %clang -### -target x86_64 -c -gdwarf-5 %s 2>&1 | FileCheck 
--check-prefix=DIRECTORY %s
+// RUN: %clang -### -target x86_64 -c -gdwarf-4 -fno-integrated-as %s 2>&1 | 
FileCheck --check-prefix=NODIRECTORY %s
+// RUN: %clang -### -target x86_64 -c -gdwarf-5 -fno-integrated-as %s 2>&1 | 
FileCheck --check-prefix=DIRECTORY %s
+
+// RUN: %clang -### -target x86_64 -c -gdwarf-4 -fno-dwarf-directory-asm %s 
2>&1 | FileCheck --check-prefix=NODIRECTORY %s
+
+// DIRECTORY-NOT: "-fno-dwarf-directory-asm"
+// NODIRECTORY: "-fno-dwarf-directory-asm"



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

[PATCH] D105660: [PowerPC][AIX] Add warning when alignment is incompatible with XL

2021-07-12 Thread Zarko Todorovski via Phabricator via cfe-commits
ZarkoCA updated this revision to Diff 358087.
ZarkoCA added a comment.

- Warning should only apply to members of struct
- Re-word warning slightly


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105660

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/Sema/aix-attr-align.c


Index: clang/test/Sema/aix-attr-align.c
===
--- /dev/null
+++ clang/test/Sema/aix-attr-align.c
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -verify -fsyntax-only %s
+// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -verify -fsyntax-only %s
+
+struct S {
+  int a[8] __attribute__((aligned(8)));  // no-warning
+};
+
+struct T {
+  int a[4] __attribute__((aligned(16))); // expected-warning {{requested 
alignment of arguments 16 bytes or greater is not compatible with previous 
versions of the AIX XL compiler}}
+};
+
+struct U {
+  int a[2] __attribute__((aligned(32))); // expected-warning {{requested 
alignment of arguments 16 bytes or greater is not compatible with previous 
versions of the AIX XL compiler}}
+};
+  int a[8] __attribute__((aligned(8)));  // no-warning
+  int b[4] __attribute__((aligned(16))); // no-warning 
+  int c[2] __attribute__((aligned(32))); // no-warning
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -3953,6 +3953,13 @@
 return;
 
   uint64_t AlignVal = Alignment.getZExtValue();
+  // 16 byte ByVal alignment not due to a vector member is not honoured by XL
+  // on AIX. Emit a warning here that users are generating binary incompatible
+  // code to be safe.
+  if (const auto *FD = dyn_cast(D)) {
+if (Context.getTargetInfo().getTriple().isOSAIX() && AlignVal >= 16)
+  Diag(AttrLoc, diag::warn_not_xl_compatible) << E->getSourceRange();
+  }
 
   // C++11 [dcl.align]p2:
   //   -- if the constant expression evaluates to zero, the alignment
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3251,6 +3251,9 @@
 : Warning<"requested alignment must be %0 bytes or smaller; maximum "
   "alignment assumed">,
   InGroup>;
+def warn_not_xl_compatible
+: Warning<"requesting an alignment of arguments 16 bytes or greater is not"
+  " binary compatible with AIX XL 16.1 and older">;
 def warn_redeclaration_without_attribute_prev_attribute_ignored : Warning<
   "%q0 redeclared without %1 attribute: previous %1 ignored">,
   InGroup;


Index: clang/test/Sema/aix-attr-align.c
===
--- /dev/null
+++ clang/test/Sema/aix-attr-align.c
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -verify -fsyntax-only %s
+// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -verify -fsyntax-only %s
+
+struct S {
+  int a[8] __attribute__((aligned(8)));  // no-warning
+};
+
+struct T {
+  int a[4] __attribute__((aligned(16))); // expected-warning {{requested alignment of arguments 16 bytes or greater is not compatible with previous versions of the AIX XL compiler}}
+};
+
+struct U {
+  int a[2] __attribute__((aligned(32))); // expected-warning {{requested alignment of arguments 16 bytes or greater is not compatible with previous versions of the AIX XL compiler}}
+};
+  int a[8] __attribute__((aligned(8)));  // no-warning
+  int b[4] __attribute__((aligned(16))); // no-warning 
+  int c[2] __attribute__((aligned(32))); // no-warning
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -3953,6 +3953,13 @@
 return;
 
   uint64_t AlignVal = Alignment.getZExtValue();
+  // 16 byte ByVal alignment not due to a vector member is not honoured by XL
+  // on AIX. Emit a warning here that users are generating binary incompatible
+  // code to be safe.
+  if (const auto *FD = dyn_cast(D)) {
+if (Context.getTargetInfo().getTriple().isOSAIX() && AlignVal >= 16)
+  Diag(AttrLoc, diag::warn_not_xl_compatible) << E->getSourceRange();
+  }
 
   // C++11 [dcl.align]p2:
   //   -- if the constant expression evaluates to zero, the alignment
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3251,6 +3251,9 @@
 : Warning<"requested alignment must be %0 bytes or smaller; maximum "
   "alignment assumed">,
   InGroup>;
+def warn_not_xl_compatible
+: Warning<"requesting an 

[PATCH] D105835: [Driver] Let -fno-integrated-as -gdwarf-5 use -fdwarf-directory-asm

2021-07-12 Thread David Blaikie via Phabricator via cfe-commits
dblaikie accepted this revision.
dblaikie added a comment.

Sure, sounds OK. Please make the corresponding change to llc and revert the 
other patch after this one & the llc one are done.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105835

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


[PATCH] D98113: [Driver] Also search FilePaths for compiler-rt before falling back

2021-07-12 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 added a comment.

In D98113#2872080 , @jroelofs wrote:

>> compiler-rt depends on a libc, typically newlib, which then depends on your 
>> compiler
>
> The builtins should only depend on compiler-provided headers, and not on the 
> rest of libc. Agreed re: the rest of compiler-rt.

Until recently builtins required libc headers, though we upstreamed a patch to 
remove that dependency.

In D98113#2872079 , @jroelofs wrote:

> Why do you want to ship the builtins as part of your sysroot?

Several reasons off the top of my head:

1. There's no general way to have multiple ABIs/ISA variants co-exist for the 
same base ISA. We have aarch64, mips64, riscv32 and riscv64 as architectures we 
support, and each of those has three different variants we need (two with 
different ISA baselines, one with a whole different ABI).

2. We build LLVM once and then use that same toolchain for multiple 
architectures. Whilst, with sufficient general multilib/multiarch support 
across all architectures, that could be supported, it means that either you 
need to provide a toolchain that has binaries built for all architectures 
(despite the fact that most of our users only want one or two), or you need to 
provide multiple copies of LLVM with different sets of libs bundled in the same 
directory. Moreover, your toolchain might be in a shared read-only directory 
(NFS or similar), installed by your sysadmin or who knows what else, with you 
unable to modify it. This allows you to use that toolchain to build whatever 
software you like, as you can point it at whatever sysroot you've created with 
whatever compiler-rt you want, rather than having to ask your sysadmin to 
install a specific version of compiler-rt in a global namespace.

3. If people hard-code -lgcc in their Makefiles then distributing the run-time 
support library (be it a renamed compiler-rt or libgcc) in a sysroot works out 
of the box. If you want to then give libclang_rt.builtins its "proper" name, 
and switch the Makefile to use -print-libgcc-file-name rather than hard-coding 
-lgcc, this suddenly breaks, as -print-libgcc-file-name falls back on giving 
you the absolute path to where the builtins library would live in the resources 
directory. This incentivises people to do the wrong thing (hard-code -lgcc and 
rename their libclang_rt.builtins to libgcc) in order to make things work.

4. If -lclang_rt.builtins-riscv64 works just fine, finding the library as 
normal in the library search path, why shouldn't -print-libgcc-file-name? 
Hard-coding -lclang_rt.builtins-ARCH in your Makefile is bad practice just like 
hard-coding -lgcc (maybe it's fine in your internal project, but not if it's 
general open-source software that needs to support GCC and Clang in a wide 
variety of configurations), yet also works, so again incentivises bad practices 
/ penalises doing the right thing.

5. When targeting FreeBSD, compiler-rt lives in the sysroot (FreeBSD's base 
system vendors it), this allows the same model to be used for bare-metal 
sysroots.

Overall, my view is this provides flexibility that aligns much more nicely with 
our build system and software distribution model with little added complexity 
to Clang and should not break any existing uses.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98113

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


[PATCH] D105835: [Driver] Let -fno-integrated-as -gdwarf-5 use -fdwarf-directory-asm

2021-07-12 Thread Omar Sandoval via Phabricator via cfe-commits
osandov accepted this revision.
osandov added a comment.
This revision is now accepted and ready to land.

That's fair enough. I don't know if I'm qualified to review this, but this I 
think this is a better solution than my fix.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105835

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


[PATCH] D98113: [Driver] Also search FilePaths for compiler-rt before falling back

2021-07-12 Thread Alexander Richardson via Phabricator via cfe-commits
arichardson added a comment.

In D98113#2872080 , @jroelofs wrote:

>> compiler-rt depends on a libc, typically newlib, which then depends on your 
>> compiler
>
> The builtins should only depend on compiler-provided headers, and not on the 
> rest of libc. Agreed re: the rest of compiler-rt.

As of https://reviews.llvm.org/D103876 that should be true for baremetal 
targets, but clear_cache.c might still need libc/OS headers.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98113

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


[PATCH] D105835: [Driver] Let -fno-integrated-as -gdwarf-5 use -fdwarf-directory-asm

2021-07-12 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D105835#2872393 , @osandov wrote:

> I tested my reproducer and it also fixes it, thanks. Should it be an error to 
> specify `-fno-dwarf-directory-asm` together with `-gdwarf-5`, since that 
> produces incorrect results?

I thought about this, but did not add the code because I think the option 
`-fno-dwarf-directory-asm` is so obscure that probably nobody will use...
Not sure why it became a driver option...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105835

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


[PATCH] D105835: [Driver] Let -fno-integrated-as -gdwarf-5 use -fdwarf-directory-asm

2021-07-12 Thread Omar Sandoval via Phabricator via cfe-commits
osandov added a comment.

I tested my reproducer and it also fixes it, thanks. Should it be an error to 
specify `-fno-dwarf-directory-asm` together with `-gdwarf-5`, since that 
produces incorrect results?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105835

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


[PATCH] D105835: [Driver] Let -fno-integrated-as -gdwarf-5 use -fdwarf-directory-asm

2021-07-12 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D105835#2872362 , @dblaikie wrote:

> Not sure I quite follow - is this an alternative to/replacement for D105662 
> ? Is the intent to revert D105662 
>  after this (D105835 
> ) (& some corresponding change to llc?) 
> lands?

It is an alternative to D105662 .

This fixes the root cause: `UseDwarfDirectory` should be true with 
`-fno-integrated-as -gdwarf-5`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105835

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


[PATCH] D105835: [Driver] Let -fno-integrated-as -gdwarf-5 use -fdwarf-directory-asm

2021-07-12 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

Not sure I quite follow - is this an alternative to/replacement for D105662 
? Is the intent to revert D105662 
 after this (D105835 
) (& some corresponding change to llc?) lands?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105835

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


[PATCH] D105834: [PowerPC] Semachecking for XL compat builtin icbt

2021-07-12 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai added inline comments.



Comment at: clang/test/CodeGen/builtins-ppc-xlcompat-pwr8.c:1
+// RUN: %clang_cc1 -triple powerpc64-unknown-unknown -emit-llvm %s \
+// RUN:   -target-cpu pwr8 -o - | FileCheck %s -check-prefix=CHECK-PWR8

Oh, I believe you're missing `REQUIRES: powerpc-registered-target` in this test 
case (please look at the requirements in the other builtins tests).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105834

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


[PATCH] D105834: [PowerPC] Semachecking for XL compat builtin icbt

2021-07-12 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai accepted this revision.
nemanjai added a comment.
This revision is now accepted and ready to land.

LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105834

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


[PATCH] D105501: [PowerPC] Power ISA features for Semachecking

2021-07-12 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai accepted this revision.
nemanjai added a comment.
This revision is now accepted and ready to land.

LGTM. Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105501

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


[PATCH] D105457: [clang] Refactor AST printing tests to share more infrastructure

2021-07-12 Thread David Blaikie via Phabricator via cfe-commits
dblaikie accepted this revision.
dblaikie added a comment.
This revision is now accepted and ready to land.

Looks reasonable to me, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105457

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


[PATCH] D105035: [clang] Document llvm options controlling pragma unroll

2021-07-12 Thread Yaxun Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8fe058dbe49b: [clang] Document llvm options controlling 
pragma unroll (authored by yaxunl).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105035

Files:
  clang/docs/LanguageExtensions.rst


Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -3410,6 +3410,9 @@
 
 Unrolling of a loop can be prevented by specifying ``unroll(disable)``.
 
+Loop unroll parameters can be controlled by options
+`-mllvm -unroll-count=n` and `-mllvm -pragma-unroll-threshold=n`.
+
 Loop Distribution
 -
 


Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -3410,6 +3410,9 @@
 
 Unrolling of a loop can be prevented by specifying ``unroll(disable)``.
 
+Loop unroll parameters can be controlled by options
+`-mllvm -unroll-count=n` and `-mllvm -pragma-unroll-threshold=n`.
+
 Loop Distribution
 -
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 8fe058d - [clang] Document llvm options controlling pragma unroll

2021-07-12 Thread Yaxun Liu via cfe-commits

Author: Yaxun (Sam) Liu
Date: 2021-07-12T16:42:50-04:00
New Revision: 8fe058dbe49b060c85f490ece2268c32b0fad7c8

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

LOG: [clang] Document llvm options controlling pragma unroll

Reviewed by: Artem Belevich

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

Added: 


Modified: 
clang/docs/LanguageExtensions.rst

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index d638121eecd80..f14f986c646a4 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -3410,6 +3410,9 @@ to the same code size limit as with ``unroll(enable)``.
 
 Unrolling of a loop can be prevented by specifying ``unroll(disable)``.
 
+Loop unroll parameters can be controlled by options
+`-mllvm -unroll-count=n` and `-mllvm -pragma-unroll-threshold=n`.
+
 Loop Distribution
 -
 



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


[PATCH] D105365: [Lexer] Fix bug in `makeFileCharRange` called on split tokens.

2021-07-12 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel added a comment.

Gentle ping...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105365

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


[PATCH] D105564: Fix for DWARF parsing to better handle auto return type for member functions

2021-07-12 Thread Greg Clayton via Phabricator via cfe-commits
clayborg requested changes to this revision.
clayborg added inline comments.



Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp:1305
+
+  // If a function has an auto return type we need to find the defintion since
+  // that will have the deduced return type and adjust the FunctionDecl to

s/defintion/definition/



Comment at: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp:2677
+
+  Symbol *defintion_class_symbol = nullptr;
+  if (m_objfile_sp) {

type



Comment at: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp:2689
+  DWARFUnit *unit = die.GetCU();
+  DWARFCompileUnit *dcu = llvm::cast_or_null(unit);
+  DWARFDIE other_die =

check dcu to ensure it isn't NULL


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

https://reviews.llvm.org/D105564

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


[PATCH] D105703: [hwasan] Use stack safety analysis.

2021-07-12 Thread Evgenii Stepanov via Phabricator via cfe-commits
eugenis added a comment.

The analysis should not run at -O0.
Otherwise, LGTM.
What kind of code size improvement do you see?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105703

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


[PATCH] D98798: Produce warning for performing pointer arithmetic on a null pointer.

2021-07-12 Thread Jamie Schmeiser via Phabricator via cfe-commits
jamieschmeiser added a comment.

ping


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

https://reviews.llvm.org/D98798

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


[PATCH] D105734: [clang-tidy] performance-unnecessary-copy-initialization: Do not remove comments on new lines.

2021-07-12 Thread Felix Berger via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0ec812023b43: [clang-tidy] 
performance-unnecessary-copy-initialization: Do not remove… (authored by flx).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105734

Files:
  clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
  
clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
@@ -596,8 +596,15 @@
   // CHECK-FIXES: int i = 0; // Foo bar.
   auto TrailingCommentRemoved = ExpensiveTypeReference(); // Trailing comment.
   // CHECK-MESSAGES: [[@LINE-1]]:8: warning: the variable 
'TrailingCommentRemoved' is copy-constructed from a const reference but is 
never used;
-  // CHECK-FIXES-NOT: auto TrailingCommentRemoved = ExpensiveTypeReference(); 
// Trailing comment.
+  // CHECK-FIXES-NOT: auto TrailingCommentRemoved = ExpensiveTypeReference();
+  // CHECK-FIXES-NOT: // Trailing comment.
   // clang-format on
+
+  auto UnusedAndUnnecessary = ExpensiveTypeReference();
+  // Comments on a new line should not be deleted.
+  // CHECK-MESSAGES: [[@LINE-2]]:8: warning: the variable 
'UnusedAndUnnecessary' is copy-constructed
+  // CHECK-FIXES-NOT: auto UnusedAndUnnecessary = ExpensiveTypeReference();
+  // CHECK-FIXES: // Comments on a new line should not be deleted.
 }
 
 void negativeloopedOverObjectIsModified() {
Index: 
clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
===
--- clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
+++ clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
@@ -39,14 +39,35 @@
   }
 }
 
+llvm::Optional firstLocAfterNewLine(SourceLocation Loc,
+SourceManager ) {
+  bool Invalid;
+  const char *TextAfter = SM.getCharacterData(Loc, );
+  if (Invalid) {
+return llvm::None;
+  }
+  size_t Offset = std::strcspn(TextAfter, "\n");
+  return Loc.getLocWithOffset(TextAfter[Offset] == '\0' ? Offset : Offset + 1);
+}
+
 void recordRemoval(const DeclStmt , ASTContext ,
DiagnosticBuilder ) {
-  // Attempt to remove the whole line until the next non-comment token.
-  auto Tok = utils::lexer::findNextTokenSkippingComments(
-  Stmt.getEndLoc(), Context.getSourceManager(), Context.getLangOpts());
-  if (Tok) {
-Diagnostic << FixItHint::CreateRemoval(SourceRange(
-Stmt.getBeginLoc(), Tok->getLocation().getLocWithOffset(-1)));
+  auto  = Context.getSourceManager();
+  // Attempt to remove trailing comments as well.
+  auto Tok = utils::lexer::findNextTokenSkippingComments(Stmt.getEndLoc(), SM,
+ 
Context.getLangOpts());
+  llvm::Optional PastNewLine =
+  firstLocAfterNewLine(Stmt.getEndLoc(), SM);
+  if (Tok && PastNewLine) {
+auto BeforeFirstTokenAfterComment = 
Tok->getLocation().getLocWithOffset(-1);
+// Remove until the end of the line or the end of a trailing comment which
+// ever comes first.
+auto End =
+SM.isBeforeInTranslationUnit(*PastNewLine, 
BeforeFirstTokenAfterComment)
+? *PastNewLine
+: BeforeFirstTokenAfterComment;
+Diagnostic << FixItHint::CreateRemoval(
+SourceRange(Stmt.getBeginLoc(), End));
   } else {
 Diagnostic << FixItHint::CreateRemoval(Stmt.getSourceRange());
   }


Index: clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
@@ -596,8 +596,15 @@
   // CHECK-FIXES: int i = 0; // Foo bar.
   auto TrailingCommentRemoved = ExpensiveTypeReference(); // Trailing comment.
   // CHECK-MESSAGES: [[@LINE-1]]:8: warning: the variable 'TrailingCommentRemoved' is copy-constructed from a const reference but is never used;
-  // CHECK-FIXES-NOT: auto TrailingCommentRemoved = ExpensiveTypeReference(); // Trailing comment.
+  // CHECK-FIXES-NOT: auto TrailingCommentRemoved = ExpensiveTypeReference();
+  // CHECK-FIXES-NOT: // Trailing comment.
   // clang-format on
+
+  auto UnusedAndUnnecessary = ExpensiveTypeReference();
+  // Comments on a new line should not be deleted.
+  // CHECK-MESSAGES: [[@LINE-2]]:8: warning: the variable 'UnusedAndUnnecessary' is 

[clang-tools-extra] 0ec8120 - [clang-tidy] performance-unnecessary-copy-initialization: Do not remove comments on new lines.

2021-07-12 Thread Felix Berger via cfe-commits

Author: Felix Berger
Date: 2021-07-12T16:23:04-04:00
New Revision: 0ec812023b43992810499b04222348fdbdb41ef2

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

LOG: [clang-tidy] performance-unnecessary-copy-initialization: Do not remove 
comments on new lines.

When deleting the copy assignment statement because copied variable is not used
only remove trailing comments on the same line.

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

Reviewed-by: ymandel

Added: 


Modified: 
clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp

clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp 
b/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
index f69a2079e4ba1..f6b8e44785b5f 100644
--- a/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
+++ b/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
@@ -39,14 +39,35 @@ void recordFixes(const VarDecl , ASTContext ,
   }
 }
 
+llvm::Optional firstLocAfterNewLine(SourceLocation Loc,
+SourceManager ) {
+  bool Invalid;
+  const char *TextAfter = SM.getCharacterData(Loc, );
+  if (Invalid) {
+return llvm::None;
+  }
+  size_t Offset = std::strcspn(TextAfter, "\n");
+  return Loc.getLocWithOffset(TextAfter[Offset] == '\0' ? Offset : Offset + 1);
+}
+
 void recordRemoval(const DeclStmt , ASTContext ,
DiagnosticBuilder ) {
-  // Attempt to remove the whole line until the next non-comment token.
-  auto Tok = utils::lexer::findNextTokenSkippingComments(
-  Stmt.getEndLoc(), Context.getSourceManager(), Context.getLangOpts());
-  if (Tok) {
-Diagnostic << FixItHint::CreateRemoval(SourceRange(
-Stmt.getBeginLoc(), Tok->getLocation().getLocWithOffset(-1)));
+  auto  = Context.getSourceManager();
+  // Attempt to remove trailing comments as well.
+  auto Tok = utils::lexer::findNextTokenSkippingComments(Stmt.getEndLoc(), SM,
+ 
Context.getLangOpts());
+  llvm::Optional PastNewLine =
+  firstLocAfterNewLine(Stmt.getEndLoc(), SM);
+  if (Tok && PastNewLine) {
+auto BeforeFirstTokenAfterComment = 
Tok->getLocation().getLocWithOffset(-1);
+// Remove until the end of the line or the end of a trailing comment which
+// ever comes first.
+auto End =
+SM.isBeforeInTranslationUnit(*PastNewLine, 
BeforeFirstTokenAfterComment)
+? *PastNewLine
+: BeforeFirstTokenAfterComment;
+Diagnostic << FixItHint::CreateRemoval(
+SourceRange(Stmt.getBeginLoc(), End));
   } else {
 Diagnostic << FixItHint::CreateRemoval(Stmt.getSourceRange());
   }

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
index b66a88e5cf81f..3ce151035d5be 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
@@ -596,8 +596,15 @@ void positiveUnusedReferenceIsRemoved() {
   // CHECK-FIXES: int i = 0; // Foo bar.
   auto TrailingCommentRemoved = ExpensiveTypeReference(); // Trailing comment.
   // CHECK-MESSAGES: [[@LINE-1]]:8: warning: the variable 
'TrailingCommentRemoved' is copy-constructed from a const reference but is 
never used;
-  // CHECK-FIXES-NOT: auto TrailingCommentRemoved = ExpensiveTypeReference(); 
// Trailing comment.
+  // CHECK-FIXES-NOT: auto TrailingCommentRemoved = ExpensiveTypeReference();
+  // CHECK-FIXES-NOT: // Trailing comment.
   // clang-format on
+
+  auto UnusedAndUnnecessary = ExpensiveTypeReference();
+  // Comments on a new line should not be deleted.
+  // CHECK-MESSAGES: [[@LINE-2]]:8: warning: the variable 
'UnusedAndUnnecessary' is copy-constructed
+  // CHECK-FIXES-NOT: auto UnusedAndUnnecessary = ExpensiveTypeReference();
+  // CHECK-FIXES: // Comments on a new line should not be deleted.
 }
 
 void negativeloopedOverObjectIsModified() {



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


[PATCH] D105501: [PowerPC] Power ISA features for Semachecking

2021-07-12 Thread Quinn Pham via Phabricator via cfe-commits
quinnp updated this revision to Diff 358049.
quinnp added a comment.

Addressing review comments.

Using an early exit for SemaFeatureCheck and combining the 3 test cases into 1.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105501

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Basic/Targets/PPC.cpp
  clang/lib/Basic/Targets/PPC.h
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Driver/ppc-isa-features.cpp
  llvm/lib/Target/PowerPC/PPC.td
  llvm/lib/Target/PowerPC/PPCInstrInfo.td
  llvm/lib/Target/PowerPC/PPCSubtarget.cpp
  llvm/lib/Target/PowerPC/PPCSubtarget.h

Index: llvm/lib/Target/PowerPC/PPCSubtarget.h
===
--- llvm/lib/Target/PowerPC/PPCSubtarget.h
+++ llvm/lib/Target/PowerPC/PPCSubtarget.h
@@ -146,6 +146,7 @@
   bool HasStoreFusion;
   bool HasAddiLoadFusion;
   bool HasAddisLoadFusion;
+  bool IsISA2_07;
   bool IsISA3_0;
   bool IsISA3_1;
   bool UseLongCalls;
@@ -319,6 +320,7 @@
 
   bool hasHTM() const { return HasHTM; }
   bool hasFloat128() const { return HasFloat128; }
+  bool isISA2_07() const { return IsISA2_07; }
   bool isISA3_0() const { return IsISA3_0; }
   bool isISA3_1() const { return IsISA3_1; }
   bool useLongCalls() const { return UseLongCalls; }
Index: llvm/lib/Target/PowerPC/PPCSubtarget.cpp
===
--- llvm/lib/Target/PowerPC/PPCSubtarget.cpp
+++ llvm/lib/Target/PowerPC/PPCSubtarget.cpp
@@ -126,6 +126,7 @@
   HasStoreFusion = false;
   HasAddiLoadFusion = false;
   HasAddisLoadFusion = false;
+  IsISA2_07 = false;
   IsISA3_0 = false;
   IsISA3_1 = false;
   UseLongCalls = false;
Index: llvm/lib/Target/PowerPC/PPCInstrInfo.td
===
--- llvm/lib/Target/PowerPC/PPCInstrInfo.td
+++ llvm/lib/Target/PowerPC/PPCInstrInfo.td
@@ -1176,6 +1176,7 @@
 : Predicate<"!Subtarget->getTargetMachine().Options.NoNaNsFPMath">;
 def HasBPERMD : Predicate<"Subtarget->hasBPERMD()">;
 def HasExtDiv : Predicate<"Subtarget->hasExtDiv()">;
+def IsISA2_07 : Predicate<"Subtarget->isISA2_07()">;
 def IsISA3_0 : Predicate<"Subtarget->isISA3_0()">;
 def HasFPU : Predicate<"Subtarget->hasFPU()">;
 def PCRelativeMemops : Predicate<"Subtarget->hasPCRelativeMemops()">;
Index: llvm/lib/Target/PowerPC/PPC.td
===
--- llvm/lib/Target/PowerPC/PPC.td
+++ llvm/lib/Target/PowerPC/PPC.td
@@ -210,9 +210,13 @@
 def DeprecatedDST: SubtargetFeature<"", "DeprecatedDST", "true",
   "Treat vector data stream cache control instructions as deprecated">;
 
+def FeatureISA2_07 : SubtargetFeature<"isa-v207-instructions", "IsISA2_07",
+  "true",
+  "Enable instructions in ISA 2.07.">;
 def FeatureISA3_0 : SubtargetFeature<"isa-v30-instructions", "IsISA3_0",
  "true",
- "Enable instructions in ISA 3.0.">;
+ "Enable instructions in ISA 3.0.",
+ [FeatureISA2_07]>;
 def FeatureISA3_1 : SubtargetFeature<"isa-v31-instructions", "IsISA3_1",
  "true",
  "Enable instructions in ISA 3.1.",
Index: clang/test/Driver/ppc-isa-features.cpp
===
--- /dev/null
+++ clang/test/Driver/ppc-isa-features.cpp
@@ -0,0 +1,21 @@
+// RUN: %clang -target powerpc64-unknown-unknown -mcpu=pwr7 -S -emit-llvm %s -o - | FileCheck %s -check-prefix=CHECK-PWR7
+// RUN: %clang -target powerpc64le-unknown-unknown -mcpu=pwr8 -S -emit-llvm %s -o - | FileCheck %s -check-prefix=CHECK-PWR8
+// RUN: %clang -target powerpc64-unknown-aix -mcpu=pwr9 -S -emit-llvm %s -o - | FileCheck %s -check-prefix=CHECK-PWR9
+// RUN: %clang -target powerpc-unknown-aix -mcpu=pwr10 -S -emit-llvm %s -o - | FileCheck %s -check-prefix=CHECK-PWR10
+
+// CHECK-PWR7: -isa-v207-instructions
+// CHECK-PWR7: -isa-v30-instructions
+
+// CHECK-PWR8: +isa-v207-instructions
+// CHECK-PWR8: -isa-v30-instructions
+
+// CHECK-PWR9: +isa-v207-instructions
+// CHECK-PWR9: +isa-v30-instructions
+
+// CHECK-PWR10: +isa-v207-instructions
+// CHECK-PWR10: +isa-v30-instructions
+// CHECK-PWR10: +isa-v31-instructions
+
+int main(int argc, char *argv[]) {
+  return 0;
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -3273,10 +3273,18 @@
 }
 
 static bool SemaFeatureCheck(Sema , CallExpr *TheCall,
- StringRef FeatureToCheck, unsigned DiagID) {
-  if (!S.Context.getTargetInfo().hasFeature(FeatureToCheck))
-return S.Diag(TheCall->getBeginLoc(), DiagID) << 

[PATCH] D98113: [Driver] Also search FilePaths for compiler-rt before falling back

2021-07-12 Thread Jon Roelofs via Phabricator via cfe-commits
jroelofs added a comment.

> compiler-rt depends on a libc, typically newlib, which then depends on your 
> compiler

The builtins should only depend on compiler-provided headers, and not on the 
rest of libc. Agreed re: the rest of compiler-rt.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98113

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


[PATCH] D98113: [Driver] Also search FilePaths for compiler-rt before falling back

2021-07-12 Thread Jon Roelofs via Phabricator via cfe-commits
jroelofs added a comment.

Why do you want to ship the builtins as part of your sysroot?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98113

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


[PATCH] D105703: [hwasan] Use stack safety analysis.

2021-07-12 Thread Florian Mayer via Phabricator via cfe-commits
fmayer updated this revision to Diff 358043.
fmayer added a comment.

update


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105703

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/test/CodeGen/hwasan-stack-safety-analysis-asm.c
  clang/test/CodeGen/hwasan-stack-safety-analysis.c
  llvm/include/llvm/Transforms/Instrumentation/HWAddressSanitizer.h
  llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp

Index: llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
===
--- llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
@@ -17,6 +17,7 @@
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/Triple.h"
+#include "llvm/Analysis/StackSafetyAnalysis.h"
 #include "llvm/BinaryFormat/ELF.h"
 #include "llvm/IR/Attributes.h"
 #include "llvm/IR/BasicBlock.h"
@@ -109,6 +110,10 @@
cl::desc("instrument stack (allocas)"),
cl::Hidden, cl::init(true));
 
+static cl::opt
+ClUseStackSafety("hwasan-use-stack-safety", cl::Hidden, cl::init(true),
+ cl::Hidden, cl::desc("Use Stack Safety analysis results"));
+
 static cl::opt ClUARRetagToZero(
 "hwasan-uar-retag-to-zero",
 cl::desc("Clear alloca tags before returning from the function to allow "
@@ -192,13 +197,31 @@
 
 namespace {
 
+bool shouldUsePageAliases(const Triple ) {
+  return ClUsePageAliases && TargetTriple.getArch() == Triple::x86_64;
+// No one should use the option directly.
+#pragma GCC poison ClUsePageAliases
+}
+
+bool shouldInstrumentStack(const Triple ) {
+  return shouldUsePageAliases(TargetTriple) ? false : ClInstrumentStack;
+// No one should use the option directly.
+#pragma GCC poison ClInstrumentStack
+}
+
+bool shouldUseStackSafetyAnalysis(const Triple ) {
+  return shouldInstrumentStack(TargetTriple) && ClUseStackSafety;
+// No one should use the option directly.
+#pragma GCC poison ClUseStackSafety
+}
 /// An instrumentation pass implementing detection of addressability bugs
 /// using tagged pointers.
 class HWAddressSanitizer {
 public:
   explicit HWAddressSanitizer(Module , bool CompileKernel = false,
-  bool Recover = false)
-  : M(M) {
+  bool Recover = false,
+  const StackSafetyGlobalInfo *SSI = nullptr)
+  : M(M), SSI(SSI) {
 this->Recover = ClRecover.getNumOccurrences() > 0 ? ClRecover : Recover;
 this->CompileKernel = ClEnableKhwasan.getNumOccurrences() > 0
   ? ClEnableKhwasan
@@ -207,6 +230,8 @@
 initializeModule();
   }
 
+  void setSSI(const StackSafetyGlobalInfo *S) { SSI = S; }
+
   bool sanitizeFunction(Function );
   void initializeModule();
   void createHwasanCtorComdat();
@@ -259,6 +284,7 @@
 private:
   LLVMContext *C;
   Module 
+  const StackSafetyGlobalInfo *SSI;
   Triple TargetTriple;
   FunctionCallee HWAsanMemmove, HWAsanMemcpy, HWAsanMemset;
   FunctionCallee HWAsanHandleVfork;
@@ -329,8 +355,10 @@
   static char ID;
 
   explicit HWAddressSanitizerLegacyPass(bool CompileKernel = false,
-bool Recover = false)
-  : FunctionPass(ID), CompileKernel(CompileKernel), Recover(Recover) {
+bool Recover = false,
+Triple TargetTriple = {})
+  : FunctionPass(ID), CompileKernel(CompileKernel), Recover(Recover),
+TargetTriple(TargetTriple) {
 initializeHWAddressSanitizerLegacyPassPass(
 *PassRegistry::getPassRegistry());
   }
@@ -338,11 +366,18 @@
   StringRef getPassName() const override { return "HWAddressSanitizer"; }
 
   bool doInitialization(Module ) override {
-HWASan = std::make_unique(M, CompileKernel, Recover);
+HWASan = std::make_unique(M, CompileKernel, Recover,
+  /*SSI=*/nullptr);
 return true;
   }
 
   bool runOnFunction(Function ) override {
+if (shouldUseStackSafetyAnalysis(TargetTriple)) {
+  // We cannot call getAnalysis in doInitialization, that would cause a
+  // crash as the required analyses are not initialized yet.
+  HWASan->setSSI(
+  ().getResult());
+}
 return HWASan->sanitizeFunction(F);
   }
 
@@ -351,10 +386,17 @@
 return false;
   }
 
+  void getAnalysisUsage(AnalysisUsage ) const override {
+if (shouldUseStackSafetyAnalysis(TargetTriple)) {
+  AU.addRequired();
+}
+  }
+
 private:
   std::unique_ptr HWASan;
   bool CompileKernel;
   bool Recover;
+  Triple TargetTriple;
 };
 
 } // end anonymous namespace
@@ -370,18 +412,25 @@
 "HWAddressSanitizer: detect memory bugs using tagged addressing.", false,
 false)
 
-FunctionPass 

[PATCH] D105384: [NVPTX, CUDA] Add .and.popc variant of the b1 MMA instruction.

2021-07-12 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: clang/test/CodeGen/builtins-nvptx-mma.py:35-38
+def make_mma_ops(geoms, types_a, types_b, types_c, types_d, b1ops=None):
   ops = []
+  if b1ops is None:
+b1ops = [""]

steffenlarsen wrote:
> 
Default initializers that use objects in python are one of the common gotchas.
https://docs.python-guide.org/writing/gotchas/#mutable-default-arguments

It probably does not make much of a difference in this case as we do not modify 
it, but I'd prefer to avoid it nevertheless.



Comment at: clang/test/CodeGen/builtins-nvptx-mma.py:84
+  # It uses __mma_tf32_m16n16k8_ld_c but __mma_m16n16k8_st_c_f32.
+  make_ldst_ops(["m16n16k8"], ["a", "b", "c", "d"], ["tf32", "f32"]))
 

steffenlarsen wrote:
> The following changes would remove the need for the `m16n16k8` cases in 
> `is_ldst_variant_supported`.
This was done deliberately. I did have that in an earlier variant of the patch, 
but eventually settled on the current version.

My thinking is that `make_ldst_ops(m16n16k8)` would create whatever is 
necessary for `m16n16k8`, and we'd keep the decision of what to produce in one 
place in `is_ldst_variant_supported`. Splitting one make_ldst_ops into two here 
makes this decision implicit which would need additional explanations. Code 
that needs less explanations  wins. :-)



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105384

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


[PATCH] D102875: [PowerPC] Add PowerPC compare and multiply related builtins and instrinsics for XL compatibility

2021-07-12 Thread Victor Huang via Phabricator via cfe-commits
NeHuang added inline comments.



Comment at: llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-multiply.ll:9
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-aix \
+; RUN:   -mcpu=pwr9 < %s | FileCheck %s --check-prefix=CHECK-64
+

amyk wrote:
> Does it make sense to add pre-P9 for these instructions that existed prior to 
> P9?
Will merge in Power ISA features Sema checking patch 
https://reviews.llvm.org/D105501 for pwr9+ only sema checking once approved.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102875

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


[PATCH] D105384: [NVPTX, CUDA] Add .and.popc variant of the b1 MMA instruction.

2021-07-12 Thread Artem Belevich via Phabricator via cfe-commits
tra updated this revision to Diff 358041.
tra marked an inline comment as done.
tra edited the summary of this revision.
tra added a comment.

Addressed review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105384

Files:
  clang/include/clang/Basic/BuiltinsNVPTX.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/builtins-nvptx-mma.cu
  clang/test/CodeGen/builtins-nvptx-mma.py
  llvm/include/llvm/IR/IntrinsicsNVVM.td
  llvm/lib/Target/NVPTX/NVPTXInstrInfo.td
  llvm/lib/Target/NVPTX/NVPTXIntrinsics.td
  llvm/test/CodeGen/NVPTX/wmma.py

Index: llvm/test/CodeGen/NVPTX/wmma.py
===
--- llvm/test/CodeGen/NVPTX/wmma.py
+++ llvm/test/CodeGen/NVPTX/wmma.py
@@ -55,14 +55,14 @@
 # RUN: llc < %t-ptx65-sm_75.ll -march=nvptx64 -mcpu=sm_75 -mattr=+ptx65 \
 # RUN:   | FileCheck %t-ptx65-sm_75.ll
 
-# Check all variants of instructions supported by PTX70 on SM80+
-# RUN: %python %s --ptx=70 --gpu-arch=80 > %t-ptx70-sm_80.ll
-# RUN: FileCheck %t-ptx70-sm_80.ll < %t-ptx70-sm_80.ll \
-# RUN:   --check-prefixes=INTRINSICS,M16N16,EXTGEOM,INT,SUBINT,MMA,ALTFLOAT,DOUBLE,PTX65MMA,PTX70MMA
-# RUN: FileCheck %t-ptx70-sm_80.ll < %t-ptx70-sm_80.ll \
+# Check all variants of instructions supported by PTX71 on SM80+
+# RUN: %python %s --ptx=71 --gpu-arch=80 > %t-ptx71-sm_80.ll
+# RUN: FileCheck %t-ptx71-sm_80.ll < %t-ptx71-sm_80.ll \
+# RUN:   --check-prefixes=INTRINSICS,M16N16,EXTGEOM,INT,SUBINT,MMA,ALTFLOAT,DOUBLE,PTX65MMA,PTX71MMA
+# RUN: FileCheck %t-ptx71-sm_80.ll < %t-ptx71-sm_80.ll \
 # RUN:   --check-prefixes=INTRINSICS
-# RUN: llc < %t-ptx70-sm_80.ll -march=nvptx64 -mcpu=sm_80 -mattr=+ptx70 \
-# RUN:   | FileCheck %t-ptx70-sm_80.ll
+# RUN: llc < %t-ptx71-sm_80.ll -march=nvptx64 -mcpu=sm_80 -mattr=+ptx71 \
+# RUN:   | FileCheck %t-ptx71-sm_80.ll
 
 from __future__ import print_function
 
@@ -649,9 +649,16 @@
   print(Template(mma_template).substitute(test_params))
   return (test_params["intrinsic"], test_params["instruction"])
 
+def get_b1_ops(ptx_type):
+  if ptx_type != "b1":
+return [""]
+  if ptx_version >= 71:
+return [".xor.popc", ".and.popc"]
+  return [".xor.popc"]
+
 def gen_wmma_mma_tests():
-  wmma_intrinsic_template = "llvm.nvvm.wmma.${geom}.mma.${alayout}.${blayout}${rnd}.${intrinsic_signature}${satf}"
-  wmma_instruction_template = "wmma.mma${mma_variant}.sync${aligned}.${alayout}.${blayout}.${geom}${rnd}.${ptx_signature}${satf}"
+  wmma_intrinsic_template = "llvm.nvvm.wmma.${geom}.mma${b1op}.${alayout}.${blayout}${rnd}.${intrinsic_signature}${satf}"
+  wmma_instruction_template = "wmma.mma${b1op}.sync${aligned}.${alayout}.${blayout}.${geom}${rnd}.${ptx_signature}${satf}"
 
   generated_items=[]
 
@@ -665,29 +672,30 @@
 if not is_wmma_variant_supported(op, alayout, blayout, rnd, satf):
   continue
 
-params = {
-"aligned" : ".aligned" if ptx_version >= 63 else "",
-"alayout" : alayout,
-"blayout" : blayout,
-"intrinsic_signature" : wmma_signature(op),
-"ptx_signature" : wmma_ptx_signature(op),
-"satf"  : satf,
-"rnd"   : rnd,
-"geom"  : op.a.geom,
-"mma_variant" : ".xor.popc" if op.a.mma_type.ptx_type == "b1" else "",
-}
+for b1op in get_b1_ops(op.a.mma_type.ptx_type):
+  params = {
+  "aligned" : ".aligned" if ptx_version >= 63 else "",
+  "alayout" : alayout,
+  "blayout" : blayout,
+  "intrinsic_signature" : wmma_signature(op),
+  "ptx_signature" : wmma_ptx_signature(op),
+  "satf"  : satf,
+  "rnd"   : rnd,
+  "geom"  : op.a.geom,
+  "b1op"  : b1op
+  }
 
-intrinsic_template = wmma_intrinsic_template
-instruction_template = wmma_instruction_template
+  intrinsic_template = wmma_intrinsic_template
+  instruction_template = wmma_instruction_template
 
-generated_items.append(common_mma_test_gen(params, op,
-  intrinsic_template, instruction_template))
+  generated_items.append(common_mma_test_gen(params, op,
+ intrinsic_template, instruction_template))
 
   return generated_items
 
 def gen_mma_tests():
-  mma_intrinsic_template = "llvm.nvvm.mma.${geom}.${alayout}.${blayout}${satf}.${intrinsic_signature}"
-  mma_instruction_template = "mma.sync${aligned}.${geom}.${alayout}.${blayout}${satf}.${ptx_signature}${mma_variant}"
+  mma_intrinsic_template = "llvm.nvvm.mma${b1op}.${geom}.${alayout}.${blayout}${satf}.${intrinsic_signature}"
+  mma_instruction_template = "mma.sync${aligned}.${geom}.${alayout}.${blayout}${satf}.${ptx_signature}${b1op}"
 
   generated_items=[]
 
@@ -700,22 +708,23 @@
 if not is_mma_variant_supported(op, alayout, blayout, satf):
   continue
 
-params = {
-"aligned" : ".aligned" if ptx_version >= 63 else "",

[PATCH] D102875: [PowerPC] Add PowerPC compare and multiply related builtins and instrinsics for XL compatibility

2021-07-12 Thread Victor Huang via Phabricator via cfe-commits
NeHuang added a comment.

Need to merge with https://reviews.llvm.org/D105501 changes once approved for 
pwr9 (or later processor) only sema checking.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102875

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


[PATCH] D105635: [PowerPC][AIX] Fix Zero-width bit fields wrt MaxFieldAlign.

2021-07-12 Thread Steven Wan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG798fe3c774a1: [PowerPC][AIX] Fix Zero-width bit fields wrt 
MaxFieldAlign. (authored by stevewan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105635

Files:
  clang/lib/AST/RecordLayoutBuilder.cpp
  clang/test/Layout/aix-bitfield-alignment.c
  clang/test/Layout/aix-packed-bitfields.c

Index: clang/test/Layout/aix-packed-bitfields.c
===
--- /dev/null
+++ clang/test/Layout/aix-packed-bitfields.c
@@ -0,0 +1,77 @@
+// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -fdump-record-layouts \
+// RUN: -fsyntax-only -fxl-pragma-pack -x c %s | FileCheck  %s
+
+// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -fdump-record-layouts \
+// RUN: -fsyntax-only -fxl-pragma-pack -x c++ %s | FileCheck %s
+//
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -fdump-record-layouts \
+// RUN: -fsyntax-only -fxl-pragma-pack -x c %s | FileCheck  %s
+//
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -fdump-record-layouts \
+// RUN: -fsyntax-only -fxl-pragma-pack -x c++ %s | FileCheck %s
+
+struct A {
+  int a1 : 30;
+  int a2 : 30;
+  int a3 : 4;
+};
+
+int a = sizeof(struct A);
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct A
+// CHECK-NEXT: 0:0-29 |   int a1
+// CHECK-NEXT: 4:0-29 |   int a2
+// CHECK-NEXT:  8:0-3 |   int a3
+// CHECK-NEXT:  sizeof=12, {{(dsize=12, )?}}align=4, preferredalign=4
+
+#pragma align(packed)
+struct AlignPacked {
+  int a1 : 30;
+  int a2 : 30;
+  int a3 : 4;
+};
+#pragma align(reset)
+
+int b = sizeof(struct AlignPacked);
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct AlignPacked
+// CHECK-NEXT: 0:0-29 |   int a1
+// CHECK-NEXT: 3:6-35 |   int a2
+// CHECK-NEXT:  7:4-7 |   int a3
+// CHECK-NEXT:  sizeof=8, {{(dsize=8, )?}}align=1, preferredalign=1
+
+#pragma pack(1)
+struct Pack1 {
+  int a1 : 30;
+  int a2 : 30;
+  int a3 : 4;
+};
+#pragma pack(pop)
+
+int c = sizeof(struct Pack1);
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct Pack1
+// CHECK-NEXT: 0:0-29 |   int a1
+// CHECK-NEXT: 3:6-35 |   int a2
+// CHECK-NEXT:  7:4-7 |   int a3
+// CHECK-NEXT:  sizeof=8, {{(dsize=8, )?}}align=1, preferredalign=1
+
+#pragma pack(2)
+struct Pack2 {
+  int a1 : 30;
+  int a2 : 30;
+  int a3 : 4;
+};
+#pragma pack(pop)
+
+int d = sizeof(struct Pack2);
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct Pack2
+// CHECK-NEXT: 0:0-29 |   int a1
+// CHECK-NEXT: 3:6-35 |   int a2
+// CHECK-NEXT:  7:4-7 |   int a3
+// CHECK-NEXT:  sizeof=8, {{(dsize=8, )?}}align=2, preferredalign=2
Index: clang/test/Layout/aix-bitfield-alignment.c
===
--- clang/test/Layout/aix-bitfield-alignment.c
+++ clang/test/Layout/aix-bitfield-alignment.c
@@ -232,3 +232,37 @@
 // CHECK-NEXT:  0 | struct G
 // CHECK-NEXT: 0:0-44 |   long long ll
 // CHECK-NEXT:   sizeof=8, {{(dsize=8, )?}}align=8, preferredalign=8
+
+#pragma align(packed)
+struct H {
+   char c;
+   int : 0;
+   int i;
+} H;
+#pragma align(reset)
+
+int h = sizeof(H);
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct H
+// CHECK-NEXT:  0 |   char c
+// CHECK-NEXT:4:- |   int
+// CHECK-NEXT:  4 |   int i
+// CHECK-NEXT:  sizeof=8, {{(dsize=8, )?}}align=1, preferredalign=1
+
+#pragma pack(2)
+struct I {
+   char c;
+   int : 0;
+   int i;
+} I;
+#pragma pack(pop)
+
+int i = sizeof(I);
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct I
+// CHECK-NEXT:  0 |   char c
+// CHECK-NEXT:4:- |   int
+// CHECK-NEXT:  4 |   int i
+// CHECK-NEXT:  sizeof=8, {{(dsize=8, )?}}align=2, preferredalign=2
Index: clang/lib/AST/RecordLayoutBuilder.cpp
===
--- clang/lib/AST/RecordLayoutBuilder.cpp
+++ clang/lib/AST/RecordLayoutBuilder.cpp
@@ -1775,6 +1775,12 @@
   !D->getIdentifier())
 FieldAlign = UnpackedFieldAlign = 1;
 
+  // On AIX, zero-width bitfields pad out to the alignment boundary, but then
+  // do not affect overall record alignment if there is a pragma pack or
+  // pragma align(packed).
+  if (isAIXLayout(Context) && !MaxFieldAlignment.isZero() && !FieldSize)
+FieldAlign = std::min(FieldAlign, MaxFieldAlignmentInBits);
+
   // Diagnose differences in layout due to padding or packing.
   if (!UseExternalLayout)
 CheckFieldPadding(FieldOffset, UnpaddedFieldOffset, UnpackedFieldOffset,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 798fe3c - [PowerPC][AIX] Fix Zero-width bit fields wrt MaxFieldAlign.

2021-07-12 Thread Steven Wan via cfe-commits

Author: Steven Wan
Date: 2021-07-12T15:31:15-04:00
New Revision: 798fe3c774a1af75c8735933ded749fa62f39594

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

LOG: [PowerPC][AIX] Fix Zero-width bit fields wrt MaxFieldAlign.

On AIX when there is a pragma pack, or pragma align in effect then zero-width 
bitfields should pad out to the end of the bitfield container but not increase 
the alignment requirements of the struct greater then the max field align.

Reviewed By: ZarkoCA

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

Added: 
clang/test/Layout/aix-packed-bitfields.c

Modified: 
clang/lib/AST/RecordLayoutBuilder.cpp
clang/test/Layout/aix-bitfield-alignment.c

Removed: 




diff  --git a/clang/lib/AST/RecordLayoutBuilder.cpp 
b/clang/lib/AST/RecordLayoutBuilder.cpp
index 6ee4178248b92..972690becf9ec 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -1775,6 +1775,12 @@ void ItaniumRecordLayoutBuilder::LayoutBitField(const 
FieldDecl *D) {
   !D->getIdentifier())
 FieldAlign = UnpackedFieldAlign = 1;
 
+  // On AIX, zero-width bitfields pad out to the alignment boundary, but then
+  // do not affect overall record alignment if there is a pragma pack or
+  // pragma align(packed).
+  if (isAIXLayout(Context) && !MaxFieldAlignment.isZero() && !FieldSize)
+FieldAlign = std::min(FieldAlign, MaxFieldAlignmentInBits);
+
   // Diagnose 
diff erences in layout due to padding or packing.
   if (!UseExternalLayout)
 CheckFieldPadding(FieldOffset, UnpaddedFieldOffset, UnpackedFieldOffset,

diff  --git a/clang/test/Layout/aix-bitfield-alignment.c 
b/clang/test/Layout/aix-bitfield-alignment.c
index a736695cc6030..d47b3d7a0c7d8 100644
--- a/clang/test/Layout/aix-bitfield-alignment.c
+++ b/clang/test/Layout/aix-bitfield-alignment.c
@@ -232,3 +232,37 @@ int s = sizeof(G);
 // CHECK-NEXT:  0 | struct G
 // CHECK-NEXT: 0:0-44 |   long long ll
 // CHECK-NEXT:   sizeof=8, {{(dsize=8, )?}}align=8, 
preferredalign=8
+
+#pragma align(packed)
+struct H {
+   char c;
+   int : 0;
+   int i;
+} H;
+#pragma align(reset)
+
+int h = sizeof(H);
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct H
+// CHECK-NEXT:  0 |   char c
+// CHECK-NEXT:4:- |   int
+// CHECK-NEXT:  4 |   int i
+// CHECK-NEXT:  sizeof=8, {{(dsize=8, )?}}align=1, preferredalign=1
+
+#pragma pack(2)
+struct I {
+   char c;
+   int : 0;
+   int i;
+} I;
+#pragma pack(pop)
+
+int i = sizeof(I);
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct I
+// CHECK-NEXT:  0 |   char c
+// CHECK-NEXT:4:- |   int
+// CHECK-NEXT:  4 |   int i
+// CHECK-NEXT:  sizeof=8, {{(dsize=8, )?}}align=2, preferredalign=2

diff  --git a/clang/test/Layout/aix-packed-bitfields.c 
b/clang/test/Layout/aix-packed-bitfields.c
new file mode 100644
index 0..9bc907af0f596
--- /dev/null
+++ b/clang/test/Layout/aix-packed-bitfields.c
@@ -0,0 +1,77 @@
+// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -fdump-record-layouts \
+// RUN: -fsyntax-only -fxl-pragma-pack -x c %s | FileCheck  %s
+
+// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -fdump-record-layouts \
+// RUN: -fsyntax-only -fxl-pragma-pack -x c++ %s | FileCheck %s
+//
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -fdump-record-layouts \
+// RUN: -fsyntax-only -fxl-pragma-pack -x c %s | FileCheck  %s
+//
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -fdump-record-layouts \
+// RUN: -fsyntax-only -fxl-pragma-pack -x c++ %s | FileCheck %s
+
+struct A {
+  int a1 : 30;
+  int a2 : 30;
+  int a3 : 4;
+};
+
+int a = sizeof(struct A);
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct A
+// CHECK-NEXT: 0:0-29 |   int a1
+// CHECK-NEXT: 4:0-29 |   int a2
+// CHECK-NEXT:  8:0-3 |   int a3
+// CHECK-NEXT:  sizeof=12, {{(dsize=12, )?}}align=4, preferredalign=4
+
+#pragma align(packed)
+struct AlignPacked {
+  int a1 : 30;
+  int a2 : 30;
+  int a3 : 4;
+};
+#pragma align(reset)
+
+int b = sizeof(struct AlignPacked);
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct AlignPacked
+// CHECK-NEXT: 0:0-29 |   int a1
+// CHECK-NEXT: 3:6-35 |   int a2
+// CHECK-NEXT:  7:4-7 |   int a3
+// CHECK-NEXT:  sizeof=8, {{(dsize=8, )?}}align=1, preferredalign=1
+
+#pragma pack(1)
+struct Pack1 {
+  int a1 : 30;
+  int a2 : 30;
+  int a3 : 4;
+};
+#pragma pack(pop)
+
+int c = sizeof(struct Pack1);
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct Pack1
+// CHECK-NEXT: 0:0-29 |   int a1
+// CHECK-NEXT: 3:6-35 |   int a2
+// CHECK-NEXT:  7:4-7 |   int a3
+// CHECK-NEXT: 

[PATCH] D104420: thread_local support for AIX

2021-07-12 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added inline comments.



Comment at: clang/lib/CodeGen/ItaniumCXXABI.cpp:4790
+llvm::Value *Arg2 = llvm::ConstantExpr::getBitCast(
+cast(dtor.getCallee()), FpTy);
+CGF.EmitNounwindRuntimeCall(AtExit, {Arg1, Arg2});

The function registered needs to be something more like what `createAtExitStub` 
stub creates. Otherwise, the destructor will not be able to reference `*this` 
correctly.

As it is, the registered function is currently just the destructor itself:
```
$ clang++ -target powerpc64-ibm-aix -emit-llvm -S -o - -xc++ -<<<$'struct A { 
~A(); }; thread_local A a;' | grep -C2 __pt_atexit_np
define internal void @__cxx_global_var_init() #0 {
entry:
  %0 = call i32 (i32, i32 (i32, ...)*, ...) @__pt_atexit_np(i32 0, i32 (i32, 
...)* bitcast (void (%struct.A*)* @_ZN1AD1Ev to i32 (i32, ...)*)) #3
  ret void
}
--
declare void @_ZN1AD1Ev(%struct.A* nonnull align 1 dereferenceable(1)) 
unnamed_addr #1

declare i32 @__pt_atexit_np(i32, i32 (i32, ...)*, ...)

; Function Attrs: noinline
Return:  0x00:0   Mon Jul 12 15:24:15 2021 EDT
```


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

https://reviews.llvm.org/D104420

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


[PATCH] D105501: [PowerPC] Power ISA features for Semachecking

2021-07-12 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai added a comment.

The testing is a bit overkill. A single test case with run lines for 
`-mcpu=pwr7-10` and a single prefix for each should suffice. For each prefix, 
just check for `+/-` for all the features you expect. The triples can be 
randomly distributed across the 4 run lines.
And yes, please use early exit as Lei pointed out.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105501

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


[PATCH] D105835: [Driver] Let -fno-integrated-as -gdwarf-5 use -fdwarf-directory-asm

2021-07-12 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
MaskRay added reviewers: debug-info, dblaikie, osandov.
MaskRay requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

While GNU as only allows the directory form of the .file directive for DWARF v5,
the integrated prefers the directory form on all DWARF versions 
(-fdwarf-directory-asm).

We currently set -fno-dwarf-directory-asm for -fno-integrated-as -gdwarf-5
which will cause the directory entry 0 and the filename entry 0 to be incorrect
(see D105662 ). This patch makes 
-fno-integrated-as -gdwarf-5 use -fdwarf-directory-asm as well.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105835

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/debug-options.c


Index: clang/test/Driver/debug-options.c
===
--- clang/test/Driver/debug-options.c
+++ clang/test/Driver/debug-options.c
@@ -424,3 +424,14 @@
 // GDWARF64_VER:  error: invalid argument '-gdwarf64' only allowed with 
'DWARFv3 or greater'
 // GDWARF64_32ARCH: error: invalid argument '-gdwarf64' only allowed with '64 
bit architecture'
 // GDWARF64_ELF: error: invalid argument '-gdwarf64' only allowed with 'ELF 
platforms'
+
+/// Default to -fno-dwarf-directory-asm for -fno-integrated-as before DWARF v5.
+// RUN: %clang -### -target x86_64 -c -gdwarf-2 %s 2>&1 | FileCheck 
--check-prefix=DIRECTORY %s
+// RUN: %clang -### -target x86_64 -c -gdwarf-5 %s 2>&1 | FileCheck 
--check-prefix=DIRECTORY %s
+// RUN: %clang -### -target x86_64 -c -gdwarf-4 -fno-integrated-as %s 2>&1 | 
FileCheck --check-prefix=NODIRECTORY %s
+// RUN: %clang -### -target x86_64 -c -gdwarf-5 -fno-integrated-as %s 2>&1 | 
FileCheck --check-prefix=DIRECTORY %s
+
+// RUN: %clang -### -target x86_64 -c -gdwarf-4 -fno-dwarf-directory-asm %s 
2>&1 | FileCheck --check-prefix=NODIRECTORY %s
+
+// DIRECTORY-NOT: "-fno-dwarf-directory-asm"
+// NODIRECTORY: "-fno-dwarf-directory-asm"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -490,14 +490,6 @@
   Default);
 }
 
-static bool ShouldDisableDwarfDirectory(const ArgList ,
-const ToolChain ) {
-  bool UseDwarfDirectory =
-  Args.hasFlag(options::OPT_fdwarf_directory_asm,
-   options::OPT_fno_dwarf_directory_asm, TC.useIntegratedAs());
-  return !UseDwarfDirectory;
-}
-
 // Convert an arg of the form "-gN" or "-ggdbN" or one of their aliases
 // to the corresponding DebugInfoKind.
 static codegenoptions::DebugInfoKind DebugLevelToInfoKind(const Arg ) {
@@ -4175,6 +4167,14 @@
 }
   }
 
+  // To avoid join/split of directory+filename, the integrated assembler 
prefers
+  // the directory form of .file on all DWARF versions. GNU as doesn't allow 
the
+  // form before DWARF v5.
+  if (!Args.hasFlag(options::OPT_fdwarf_directory_asm,
+options::OPT_fno_dwarf_directory_asm,
+TC.useIntegratedAs() || EffectiveDWARFVersion >= 5))
+CmdArgs.push_back("-fno-dwarf-directory-asm");
+
   // Decide how to render forward declarations of template instantiations.
   // SCE wants full descriptions, others just get them in the name.
   if (DebuggerTuning == llvm::DebuggerKind::SCE)
@@ -5506,9 +5506,6 @@
   CmdArgs.push_back("-fno-gnu-keywords");
   }
 
-  if (ShouldDisableDwarfDirectory(Args, TC))
-CmdArgs.push_back("-fno-dwarf-directory-asm");
-
   if (!ShouldEnableAutolink(Args, TC, JA))
 CmdArgs.push_back("-fno-autolink");
 


Index: clang/test/Driver/debug-options.c
===
--- clang/test/Driver/debug-options.c
+++ clang/test/Driver/debug-options.c
@@ -424,3 +424,14 @@
 // GDWARF64_VER:  error: invalid argument '-gdwarf64' only allowed with 'DWARFv3 or greater'
 // GDWARF64_32ARCH: error: invalid argument '-gdwarf64' only allowed with '64 bit architecture'
 // GDWARF64_ELF: error: invalid argument '-gdwarf64' only allowed with 'ELF platforms'
+
+/// Default to -fno-dwarf-directory-asm for -fno-integrated-as before DWARF v5.
+// RUN: %clang -### -target x86_64 -c -gdwarf-2 %s 2>&1 | FileCheck --check-prefix=DIRECTORY %s
+// RUN: %clang -### -target x86_64 -c -gdwarf-5 %s 2>&1 | FileCheck --check-prefix=DIRECTORY %s
+// RUN: %clang -### -target x86_64 -c -gdwarf-4 -fno-integrated-as %s 2>&1 | FileCheck --check-prefix=NODIRECTORY %s
+// RUN: %clang -### -target x86_64 -c -gdwarf-5 -fno-integrated-as %s 2>&1 | FileCheck --check-prefix=DIRECTORY %s
+
+// RUN: %clang -### -target x86_64 -c -gdwarf-4 -fno-dwarf-directory-asm %s 2>&1 | FileCheck --check-prefix=NODIRECTORY %s
+
+// DIRECTORY-NOT: "-fno-dwarf-directory-asm"
+// NODIRECTORY: "-fno-dwarf-directory-asm"
Index: clang/lib/Driver/ToolChains/Clang.cpp

[PATCH] D105834: [PowerPC] Semachecking for XL compat builtin icbt

2021-07-12 Thread Quinn Pham via Phabricator via cfe-commits
quinnp created this revision.
Herald added subscribers: shchenz, kbarton, nemanjai.
quinnp requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch is in a series of patches to provide builtins for compatibility with 
the XL compiler. This patch adds semachecking for an already implemented 
builtin, __icbt. __icbt is only valid fore Power8 and up.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105834

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtins-ppc-xlcompat-pwr8.c


Index: clang/test/CodeGen/builtins-ppc-xlcompat-pwr8.c
===
--- /dev/null
+++ clang/test/CodeGen/builtins-ppc-xlcompat-pwr8.c
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 -triple powerpc64-unknown-unknown -emit-llvm %s \
+// RUN:   -target-cpu pwr8 -o - | FileCheck %s -check-prefix=CHECK-PWR8
+// RUN: %clang_cc1 -triple powerpc64le-unknown-unknown -emit-llvm %s \
+// RUN:   -target-cpu pwr8 -o - | FileCheck %s -check-prefix=CHECK-PWR8
+// RUN: %clang_cc1 -triple powerpc64-unknown-aix -emit-llvm %s \
+// RUN:   -target-cpu pwr8 -o - | FileCheck %s -check-prefix=CHECK-PWR8
+// RUN: %clang_cc1 -triple powerpc-unknown-aix %s -emit-llvm %s \
+// RUN:   -target-cpu pwr8 -o - | FileCheck %s -check-prefix=CHECK-PWR8
+// RUN: not %clang_cc1 -triple powerpc64-unknown-unknown -emit-llvm %s \
+// RUN:   -target-cpu pwr7 2>&1 | FileCheck %s -check-prefix=CHECK-NOPWR8
+// RUN: not %clang_cc1 -triple powerpc64-unknown-aix -emit-llvm %s \
+// RUN:   -target-cpu pwr7 2>&1 | FileCheck %s -check-prefix=CHECK-NOPWR8
+// RUN: not %clang_cc1 -triple powerpc-unknown-aix %s -emit-llvm %s \
+// RUN:   -target-cpu pwr7 2>&1 | FileCheck %s -check-prefix=CHECK-NOPWR8
+
+extern void *a;
+
+void test_icbt() {
+// CHECK-LABEL: @test_icbt(
+
+  __icbt(a);
+// CHECK-PWR8: call void @llvm.ppc.icbt(i8* %0)
+// CHECK-NOPWR8: error: this builtin is only valid on POWER8 or later CPUs
+}
+
+void test_builtin_ppc_icbt() {
+// CHECK-LABEL: @test_builtin_ppc_icbt(
+
+  __builtin_ppc_icbt(a);
+// CHECK-PWR8: call void @llvm.ppc.icbt(i8* %0)
+// CHECK-NOPWR8: error: this builtin is only valid on POWER8 or later CPUs
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -3355,6 +3355,9 @@
  return SemaBuiltinConstantArgRange(TheCall, 2, 0, 7);
   case PPC::BI__builtin_vsx_xxpermx:
  return SemaBuiltinConstantArgRange(TheCall, 3, 0, 7);
+  case PPC::BI__builtin_ppc_icbt:
+return SemaFeatureCheck(*this, TheCall, "isa-v207-instructions",
+diag::err_ppc_builtin_only_on_arch, "8");
 #define CUSTOM_BUILTIN(Name, Intr, Types, Acc) \
   case PPC::BI__builtin_##Name: \
 return SemaBuiltinPPCMMACall(TheCall, Types);


Index: clang/test/CodeGen/builtins-ppc-xlcompat-pwr8.c
===
--- /dev/null
+++ clang/test/CodeGen/builtins-ppc-xlcompat-pwr8.c
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 -triple powerpc64-unknown-unknown -emit-llvm %s \
+// RUN:   -target-cpu pwr8 -o - | FileCheck %s -check-prefix=CHECK-PWR8
+// RUN: %clang_cc1 -triple powerpc64le-unknown-unknown -emit-llvm %s \
+// RUN:   -target-cpu pwr8 -o - | FileCheck %s -check-prefix=CHECK-PWR8
+// RUN: %clang_cc1 -triple powerpc64-unknown-aix -emit-llvm %s \
+// RUN:   -target-cpu pwr8 -o - | FileCheck %s -check-prefix=CHECK-PWR8
+// RUN: %clang_cc1 -triple powerpc-unknown-aix %s -emit-llvm %s \
+// RUN:   -target-cpu pwr8 -o - | FileCheck %s -check-prefix=CHECK-PWR8
+// RUN: not %clang_cc1 -triple powerpc64-unknown-unknown -emit-llvm %s \
+// RUN:   -target-cpu pwr7 2>&1 | FileCheck %s -check-prefix=CHECK-NOPWR8
+// RUN: not %clang_cc1 -triple powerpc64-unknown-aix -emit-llvm %s \
+// RUN:   -target-cpu pwr7 2>&1 | FileCheck %s -check-prefix=CHECK-NOPWR8
+// RUN: not %clang_cc1 -triple powerpc-unknown-aix %s -emit-llvm %s \
+// RUN:   -target-cpu pwr7 2>&1 | FileCheck %s -check-prefix=CHECK-NOPWR8
+
+extern void *a;
+
+void test_icbt() {
+// CHECK-LABEL: @test_icbt(
+
+  __icbt(a);
+// CHECK-PWR8: call void @llvm.ppc.icbt(i8* %0)
+// CHECK-NOPWR8: error: this builtin is only valid on POWER8 or later CPUs
+}
+
+void test_builtin_ppc_icbt() {
+// CHECK-LABEL: @test_builtin_ppc_icbt(
+
+  __builtin_ppc_icbt(a);
+// CHECK-PWR8: call void @llvm.ppc.icbt(i8* %0)
+// CHECK-NOPWR8: error: this builtin is only valid on POWER8 or later CPUs
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -3355,6 +3355,9 @@
  return SemaBuiltinConstantArgRange(TheCall, 2, 0, 7);
   case PPC::BI__builtin_vsx_xxpermx:
  return SemaBuiltinConstantArgRange(TheCall, 3, 0, 7);
+  case PPC::BI__builtin_ppc_icbt:
+return SemaFeatureCheck(*this, 

[PATCH] D105734: [clang-tidy] performance-unnecessary-copy-initialization: Do not remove comments on new lines.

2021-07-12 Thread Felix Berger via Phabricator via cfe-commits
flx updated this revision to Diff 358010.
flx marked 2 inline comments as done.
flx added a comment.

Invert end of string logic.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105734

Files:
  clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
  
clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
@@ -596,8 +596,15 @@
   // CHECK-FIXES: int i = 0; // Foo bar.
   auto TrailingCommentRemoved = ExpensiveTypeReference(); // Trailing comment.
   // CHECK-MESSAGES: [[@LINE-1]]:8: warning: the variable 
'TrailingCommentRemoved' is copy-constructed from a const reference but is 
never used;
-  // CHECK-FIXES-NOT: auto TrailingCommentRemoved = ExpensiveTypeReference(); 
// Trailing comment.
+  // CHECK-FIXES-NOT: auto TrailingCommentRemoved = ExpensiveTypeReference();
+  // CHECK-FIXES-NOT: // Trailing comment.
   // clang-format on
+
+  auto UnusedAndUnnecessary = ExpensiveTypeReference();
+  // Comments on a new line should not be deleted.
+  // CHECK-MESSAGES: [[@LINE-2]]:8: warning: the variable 
'UnusedAndUnnecessary' is copy-constructed
+  // CHECK-FIXES-NOT: auto UnusedAndUnnecessary = ExpensiveTypeReference();
+  // CHECK-FIXES: // Comments on a new line should not be deleted.
 }
 
 void negativeloopedOverObjectIsModified() {
Index: 
clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
===
--- clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
+++ clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
@@ -39,14 +39,35 @@
   }
 }
 
+llvm::Optional firstLocAfterNewLine(SourceLocation Loc,
+SourceManager ) {
+  bool Invalid;
+  const char *TextAfter = SM.getCharacterData(Loc, );
+  if (Invalid) {
+return llvm::None;
+  }
+  size_t Offset = std::strcspn(TextAfter, "\n");
+  return Loc.getLocWithOffset(TextAfter[Offset] == '\0' ? Offset : Offset + 1);
+}
+
 void recordRemoval(const DeclStmt , ASTContext ,
DiagnosticBuilder ) {
-  // Attempt to remove the whole line until the next non-comment token.
-  auto Tok = utils::lexer::findNextTokenSkippingComments(
-  Stmt.getEndLoc(), Context.getSourceManager(), Context.getLangOpts());
-  if (Tok) {
-Diagnostic << FixItHint::CreateRemoval(SourceRange(
-Stmt.getBeginLoc(), Tok->getLocation().getLocWithOffset(-1)));
+  auto  = Context.getSourceManager();
+  // Attempt to remove trailing comments as well.
+  auto Tok = utils::lexer::findNextTokenSkippingComments(Stmt.getEndLoc(), SM,
+ 
Context.getLangOpts());
+  llvm::Optional PastNewLine =
+  firstLocAfterNewLine(Stmt.getEndLoc(), SM);
+  if (Tok && PastNewLine) {
+auto BeforeFirstTokenAfterComment = 
Tok->getLocation().getLocWithOffset(-1);
+// Remove until the end of the line or the end of a trailing comment which
+// ever comes first.
+auto End =
+SM.isBeforeInTranslationUnit(*PastNewLine, 
BeforeFirstTokenAfterComment)
+? *PastNewLine
+: BeforeFirstTokenAfterComment;
+Diagnostic << FixItHint::CreateRemoval(
+SourceRange(Stmt.getBeginLoc(), End));
   } else {
 Diagnostic << FixItHint::CreateRemoval(Stmt.getSourceRange());
   }


Index: clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
@@ -596,8 +596,15 @@
   // CHECK-FIXES: int i = 0; // Foo bar.
   auto TrailingCommentRemoved = ExpensiveTypeReference(); // Trailing comment.
   // CHECK-MESSAGES: [[@LINE-1]]:8: warning: the variable 'TrailingCommentRemoved' is copy-constructed from a const reference but is never used;
-  // CHECK-FIXES-NOT: auto TrailingCommentRemoved = ExpensiveTypeReference(); // Trailing comment.
+  // CHECK-FIXES-NOT: auto TrailingCommentRemoved = ExpensiveTypeReference();
+  // CHECK-FIXES-NOT: // Trailing comment.
   // clang-format on
+
+  auto UnusedAndUnnecessary = ExpensiveTypeReference();
+  // Comments on a new line should not be deleted.
+  // CHECK-MESSAGES: [[@LINE-2]]:8: warning: the variable 'UnusedAndUnnecessary' is copy-constructed
+  // CHECK-FIXES-NOT: auto UnusedAndUnnecessary = 

[PATCH] D105755: [WebAssembly] Custom combines for f32x4.demote_zero_f64x2

2021-07-12 Thread Thomas Lively via Phabricator via cfe-commits
tlively added inline comments.



Comment at: clang/include/clang/Basic/BuiltinsWebAssembly.def:192-193
 
 TARGET_BUILTIN(__builtin_wasm_trunc_sat_zero_s_f64x2_i32x4, "V4iV2d", "nc", 
"simd128")
 TARGET_BUILTIN(__builtin_wasm_trunc_sat_zero_u_f64x2_i32x4, "V4UiV2d", "nc", 
"simd128")
-TARGET_BUILTIN(__builtin_wasm_demote_zero_f64x2_f32x4, "V4fV2d", "nc", 
"simd128")

tlively wrote:
> aheejin wrote:
> > If these share the same pattern, do we need these builtins?
> Hmm, good point. Maybe not. I'll investigate that in a follow up.
Ah, the reason we can't remove these builtins is because there is no good 
target-independent way to represent the saturating behavior of the float-to-int 
conversion.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105755

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


[PATCH] D105501: [PowerPC] Power ISA features for Semachecking

2021-07-12 Thread Lei Huang via Phabricator via cfe-commits
lei added inline comments.



Comment at: clang/lib/Sema/SemaChecking.cpp:3278
+ StringRef DiagArg = "") {
+  if (!S.Context.getTargetInfo().hasFeature(FeatureToCheck)) {
+if (!DiagArg.empty()) {

may I suggest early exit instead?

```
if (S.Context.getTargetInfo().hasFeature(FeatureToCheck))
  return false;

if (DiagArg.empty()) 
  S.Diag(TheCall->getBeginLoc(), DiagID) << TheCall->getSourceRange();
else
  S.Diag(TheCall->getBeginLoc(), DiagID) << DiagArg << 
TheCall->getSourceRange();

return true;
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105501

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


[PATCH] D105526: opencl-c.h: CL3.0 generic address space

2021-07-12 Thread Dave Airlie via Phabricator via cfe-commits
airlied updated this revision to Diff 358005.
airlied added a comment.

full diff.


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

https://reviews.llvm.org/D105526

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

Index: clang/lib/Headers/opencl-c.h
===
--- clang/lib/Headers/opencl-c.h
+++ clang/lib/Headers/opencl-c.h
@@ -7259,7 +7259,7 @@
  * Returns fmin(x - floor (x), 0x1.fep-1f ).
  * floor(x) is returned in iptr.
  */
-#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
+#if defined(__opencl_c_generic_address_space)
 float __ovld fract(float x, float *iptr);
 float2 __ovld fract(float2 x, float2 *iptr);
 float3 __ovld fract(float3 x, float3 *iptr);
@@ -7341,7 +7341,7 @@
 half8 __ovld fract(half8 x, __private half8 *iptr);
 half16 __ovld fract(half16 x, __private half16 *iptr);
 #endif //cl_khr_fp16
-#endif //defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
+#endif //defined(__opencl_c_generic_address_space)
 
 /**
  * Extract mantissa and exponent from x. For each
@@ -7349,7 +7349,7 @@
  * magnitude in the interval [1/2, 1) or 0. Each
  * component of x equals mantissa returned * 2^exp.
  */
-#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
+#if defined(__opencl_c_generic_address_space)
 float __ovld frexp(float x, int *exp);
 float2 __ovld frexp(float2 x, int2 *exp);
 float3 __ovld frexp(float3 x, int3 *exp);
@@ -7431,7 +7431,7 @@
 half8 __ovld frexp(half8 x, __private int8 *exp);
 half16 __ovld frexp(half16 x, __private int16 *exp);
 #endif //cl_khr_fp16
-#endif //defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
+#endif //defined(__opencl_c_generic_address_space)
 
 /**
  * Compute the value of the square root of x^2 + y^2
@@ -7556,7 +7556,7 @@
 half16 __ovld __cnfn lgamma(half16 x);
 #endif //cl_khr_fp16
 
-#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
+#if defined(__opencl_c_generic_address_space)
 float __ovld lgamma_r(float x, int *signp);
 float2 __ovld lgamma_r(float2 x, int2 *signp);
 float3 __ovld lgamma_r(float3 x, int3 *signp);
@@ -7638,7 +7638,7 @@
 half8 __ovld lgamma_r(half8 x, __private int8 *signp);
 half16 __ovld lgamma_r(half16 x, __private int16 *signp);
 #endif //cl_khr_fp16
-#endif //defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
+#endif //defined(__opencl_c_generic_address_space)
 
 /**
  * Compute natural logarithm.
@@ -7862,7 +7862,7 @@
  * the argument. It stores the integral part in the object
  * pointed to by iptr.
  */
-#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
+#if defined(__opencl_c_generic_address_space)
 float __ovld modf(float x, float *iptr);
 float2 __ovld modf(float2 x, float2 *iptr);
 float3 __ovld modf(float3 x, float3 *iptr);
@@ -7944,7 +7944,7 @@
 half8 __ovld modf(half8 x, __private half8 *iptr);
 half16 __ovld modf(half16 x, __private half16 *iptr);
 #endif //cl_khr_fp16
-#endif //defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
+#endif //defined(__opencl_c_generic_address_space)
 
 /**
  * Returns a quiet NaN. The nancode may be placed
@@ -8122,7 +8122,7 @@
  * sign as x/y. It stores this signed value in the object
  * pointed to by quo.
  */
-#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
+#if defined(__opencl_c_generic_address_space)
 float __ovld remquo(float x, float y, int *quo);
 float2 __ovld remquo(float2 x, float2 y, int2 *quo);
 float3 __ovld remquo(float3 x, float3 y, int3 *quo);
@@ -8205,7 +8205,7 @@
 half8 __ovld remquo(half8 x, half8 y, __private int8 *quo);
 half16 __ovld remquo(half16 x, half16 y, __private int16 *quo);
 #endif //cl_khr_fp16
-#endif //defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
+#endif //defined(__opencl_c_generic_address_space)
 /**
  * Round to integral value (using round to nearest
  * even rounding mode) in floating-point format.
@@ -8346,7 +8346,7 @@
  * is the return value and computed cosine is returned
  * in cosval.
  */
-#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
+#if defined(__opencl_c_generic_address_space)
 float __ovld sincos(float x, float *cosval);
 float2 __ovld sincos(float2 x, float2 *cosval);
 float3 __ovld sincos(float3 x, float3 *cosval);
@@ -8428,7 +8428,7 @@
 half8 __ovld sincos(half8 x, __private half8 *cosval);
 half16 __ovld sincos(half16 x, __private half16 *cosval);
 #endif //cl_khr_fp16
-#endif //defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
+#endif //defined(__opencl_c_generic_address_space)
 
 /**
  * Compute hyperbolic sine.
@@ -11249,7 +11249,7 @@
 half16 __ovld vload16(size_t offset, const __constant half *p);
 #endif //cl_khr_fp16
 
-#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
+#if 

[PATCH] D105564: Fix for DWARF parsing to better handle auto return type for member functions

2021-07-12 Thread Raphael Isemann via Phabricator via cfe-commits
teemperor requested changes to this revision.
teemperor added a comment.
This revision now requires changes to proceed.

I think this looks good, thanks for fixing this! I believe there should be a 
few more tests for all the corner cases we can run into here (those tests can 
all be just Python API tests, no need for having them all in assembly format). 
Also I think lambdas where triggering the original issue, so that would also be 
nice to have in a test.

I started writing some example tests but this is crashing for me with:

  Unexpected undeduced type!
  UNREACHABLE executed at 
/home/teemperor/work/ci/llvm-project/clang/lib/CodeGen/CodeGenTypes.cpp:624!
  PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash 
backtrace.
  Stack dump:
  0.Program arguments: ./bin/lldb 
././lldb-test-build.noindex/lang/cpp/auto_return/TestCppAutoReturn.test_dwarf/a.out
   #0 0x55f540b5e611 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) 
(./bin/lldb+0x34611)
   #1 0x55f540b5c6b0 llvm::sys::RunSignalHandlers() (./bin/lldb+0x326b0)
   #2 0x55f540b5efb6 SignalHandler(int) (./bin/lldb+0x34fb6)
   #3 0x7fe3c3484870 __restore_rt (/usr/lib/libpthread.so.0+0x13870)
   #4 0x7fe3bd2e3d22 raise (/usr/lib/libc.so.6+0x3cd22)
   #5 0x7fe3bd2cd862 abort (/usr/lib/libc.so.6+0x26862)
   #6 0x7fe3becf0df1 
(/home/teemperor/work/ci/build/bin/../lib/liblldb.so.13git+0x146adf1)
   #7 0x7fe3bf7cbdda 
clang::CodeGen::CodeGenTypes::ConvertType(clang::QualType) 
(/home/teemperor/work/ci/build/bin/../lib/liblldb.so.13git+0x1f45dda)
   #8 0x7fe3bf7caf7e 
clang::CodeGen::CodeGenTypes::ConvertTypeForMem(clang::QualType, bool) 
(/home/teemperor/work/ci/build/bin/../lib/liblldb.so.13git+0x1f44f7e)
   #9 0x7fe3bf951dd8 
clang::CodeGen::CodeGenModule::getOrCreateStaticVarDecl(clang::VarDecl const&, 
llvm::GlobalValue::LinkageTypes) 
(/home/teemperor/work/ci/build/bin/../lib/liblldb.so.13git+0x20cbdd8)
  #10 0x7fe3bf950b10 
clang::CodeGen::CodeGenFunction::EmitStaticVarDecl(clang::VarDecl const&, 
llvm::GlobalValue::LinkageTypes) 
(/home/teemperor/work/ci/build/bin/../lib/liblldb.so.13git+0x20cab10)
  #11 0x7fe3bf9508f3 
clang::CodeGen::CodeGenFunction::EmitVarDecl(clang::VarDecl const&) 
(/home/teemperor/work/ci/build/bin/../lib/liblldb.so.13git+0x20ca8f3)
  #12 0x7fe3bf950458 clang::CodeGen::CodeGenFunction::EmitDecl(clang::Decl 
const&) (/home/teemperor/work/ci/build/bin/../lib/liblldb.so.13git+0x20ca458)
  #13 0x7fe3bf6f887c 
clang::CodeGen::CodeGenFunction::EmitDeclStmt(clang::DeclStmt const&) 
(/home/teemperor/work/ci/build/bin/../lib/liblldb.so.13git+0x1e7287c)
  #14 0x7fe3bf6ee2d8 
clang::CodeGen::CodeGenFunction::EmitSimpleStmt(clang::Stmt const*, 
llvm::ArrayRef) 
(/home/teemperor/work/ci/build/bin/../lib/liblldb.so.13git+0x1e682d8)
  #15 0x7fe3bf6eda89 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt 
const*, llvm::ArrayRef) 
(/home/teemperor/work/ci/build/bin/../lib/liblldb.so.13git+0x1e67a89)
  #16 0x7fe3bf6f96b0 
clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt
 const&, bool, clang::CodeGen::AggValueSlot) 
(/home/teemperor/work/ci/build/bin/../lib/liblldb.so.13git+0x1e736b0)
  #17 0x7fe3bf7585b4 
clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) 
(/home/teemperor/work/ci/build/bin/../lib/liblldb.so.13git+0x1ed25b4)
  #18 0x7fe3bf7591de 
clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, 
llvm::Function*, clang::CodeGen::CGFunctionInfo const&) 
(/home/teemperor/work/ci/build/bin/../lib/liblldb.so.13git+0x1ed31de)
  #19 0x7fe3bf77a51f 
clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, 
llvm::GlobalValue*) 
(/home/teemperor/work/ci/build/bin/../lib/liblldb.so.13git+0x1ef451f)
  #20 0x7fe3bf77222d 
clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, 
llvm::GlobalValue*) 
(/home/teemperor/work/ci/build/bin/../lib/liblldb.so.13git+0x1eec22d)
  #21 0x7fe3bf7773bb 
clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) 
(/home/teemperor/work/ci/build/bin/../lib/liblldb.so.13git+0x1ef13bb)
  #22 0x7fe3bf77e039 
clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) 
(/home/teemperor/work/ci/build/bin/../lib/liblldb.so.13git+0x1ef8039)
  #23 0x7fe3bf6ab280 (anonymous 
namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) 
(/home/teemperor/work/ci/build/bin/../lib/liblldb.so.13git+0x1e25280)
  #24 0x7fe3bf549632 
lldb_private::ASTResultSynthesizer::HandleTopLevelDecl(clang::DeclGroupRef) 
(/home/teemperor/work/ci/build/bin/../lib/liblldb.so.13git+0x1cc3632)
  #25 0x7fe3c018a558 clang::ParseAST(clang::Sema&, bool, bool) 
(/home/teemperor/work/ci/build/bin/../lib/liblldb.so.13git+0x2904558)
  #26 0x7fe3bf55d493 
lldb_private::ClangExpressionParser::ParseInternal(lldb_private::DiagnosticManager&,
 clang::CodeCompleteConsumer*, unsigned int, unsigned int) 

[PATCH] D105501: [PowerPC] Power ISA features for Semachecking

2021-07-12 Thread Quinn Pham via Phabricator via cfe-commits
quinnp updated this revision to Diff 358004.
quinnp added a comment.

Adding tests for each of the features


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105501

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Basic/Targets/PPC.cpp
  clang/lib/Basic/Targets/PPC.h
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Driver/ppc-isa207-instructions.cpp
  clang/test/Driver/ppc-isa30-instructions.cpp
  clang/test/Driver/ppc-isa31-instructions.cpp
  llvm/lib/Target/PowerPC/PPC.td
  llvm/lib/Target/PowerPC/PPCInstrInfo.td
  llvm/lib/Target/PowerPC/PPCSubtarget.cpp
  llvm/lib/Target/PowerPC/PPCSubtarget.h

Index: llvm/lib/Target/PowerPC/PPCSubtarget.h
===
--- llvm/lib/Target/PowerPC/PPCSubtarget.h
+++ llvm/lib/Target/PowerPC/PPCSubtarget.h
@@ -146,6 +146,7 @@
   bool HasStoreFusion;
   bool HasAddiLoadFusion;
   bool HasAddisLoadFusion;
+  bool IsISA2_07;
   bool IsISA3_0;
   bool IsISA3_1;
   bool UseLongCalls;
@@ -319,6 +320,7 @@
 
   bool hasHTM() const { return HasHTM; }
   bool hasFloat128() const { return HasFloat128; }
+  bool isISA2_07() const { return IsISA2_07; }
   bool isISA3_0() const { return IsISA3_0; }
   bool isISA3_1() const { return IsISA3_1; }
   bool useLongCalls() const { return UseLongCalls; }
Index: llvm/lib/Target/PowerPC/PPCSubtarget.cpp
===
--- llvm/lib/Target/PowerPC/PPCSubtarget.cpp
+++ llvm/lib/Target/PowerPC/PPCSubtarget.cpp
@@ -126,6 +126,7 @@
   HasStoreFusion = false;
   HasAddiLoadFusion = false;
   HasAddisLoadFusion = false;
+  IsISA2_07 = false;
   IsISA3_0 = false;
   IsISA3_1 = false;
   UseLongCalls = false;
Index: llvm/lib/Target/PowerPC/PPCInstrInfo.td
===
--- llvm/lib/Target/PowerPC/PPCInstrInfo.td
+++ llvm/lib/Target/PowerPC/PPCInstrInfo.td
@@ -1176,6 +1176,7 @@
 : Predicate<"!Subtarget->getTargetMachine().Options.NoNaNsFPMath">;
 def HasBPERMD : Predicate<"Subtarget->hasBPERMD()">;
 def HasExtDiv : Predicate<"Subtarget->hasExtDiv()">;
+def IsISA2_07 : Predicate<"Subtarget->isISA2_07()">;
 def IsISA3_0 : Predicate<"Subtarget->isISA3_0()">;
 def HasFPU : Predicate<"Subtarget->hasFPU()">;
 def PCRelativeMemops : Predicate<"Subtarget->hasPCRelativeMemops()">;
Index: llvm/lib/Target/PowerPC/PPC.td
===
--- llvm/lib/Target/PowerPC/PPC.td
+++ llvm/lib/Target/PowerPC/PPC.td
@@ -210,9 +210,13 @@
 def DeprecatedDST: SubtargetFeature<"", "DeprecatedDST", "true",
   "Treat vector data stream cache control instructions as deprecated">;
 
+def FeatureISA2_07 : SubtargetFeature<"isa-v207-instructions", "IsISA2_07",
+  "true",
+  "Enable instructions in ISA 2.07.">;
 def FeatureISA3_0 : SubtargetFeature<"isa-v30-instructions", "IsISA3_0",
  "true",
- "Enable instructions in ISA 3.0.">;
+ "Enable instructions in ISA 3.0.",
+ [FeatureISA2_07]>;
 def FeatureISA3_1 : SubtargetFeature<"isa-v31-instructions", "IsISA3_1",
  "true",
  "Enable instructions in ISA 3.1.",
Index: clang/test/Driver/ppc-isa31-instructions.cpp
===
--- /dev/null
+++ clang/test/Driver/ppc-isa31-instructions.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang -target powerpc64-unknown-unknown -mcpu=pwr10 -S -emit-llvm %s -o - | FileCheck %s -check-prefix=CHECK-ISA31
+// RUN: %clang -target powerpc64le-unknown-unknown -mcpu=pwr10 -S -emit-llvm %s -o - | FileCheck %s -check-prefix=CHECK-ISA31
+// RUN: %clang -target powerpc64-unknown-aix -mcpu=pwr10 -S -emit-llvm %s -o - | FileCheck %s -check-prefix=CHECK-ISA31
+// RUN: %clang -target powerpc-unknown-aix -mcpu=pwr10 -S -emit-llvm %s -o - | FileCheck %s -check-prefix=CHECK-ISA31
+
+// CHECK-ISA31: +isa-v31-instructions
+
+int main(int argc, char *argv[]) {
+  return 0;
+}
Index: clang/test/Driver/ppc-isa30-instructions.cpp
===
--- /dev/null
+++ clang/test/Driver/ppc-isa30-instructions.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang -target powerpc64-unknown-unknown -mcpu=pwr7 -S -emit-llvm %s -o - | FileCheck %s -check-prefix=CHECK-NOISA30
+// RUN: %clang -target powerpc64-unknown-unknown -mcpu=pwr8 -S -emit-llvm %s -o - | FileCheck %s -check-prefix=CHECK-NOISA30
+// RUN: %clang -target powerpc64-unknown-unknown -mcpu=pwr9 -S -emit-llvm %s -o - | FileCheck %s -check-prefix=CHECK-ISA30
+// RUN: %clang -target powerpc64-unknown-unknown -mcpu=pwr10 -S -emit-llvm %s -o - | FileCheck %s -check-prefix=CHECK-ISA30
+// RUN: %clang 

[PATCH] D105734: [clang-tidy] performance-unnecessary-copy-initialization: Do not remove comments on new lines.

2021-07-12 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel accepted this revision.
ymandel added inline comments.
This revision is now accepted and ready to land.



Comment at: 
clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp:50
+  size_t Offset = std::strcspn(TextAfter, "\n");
+  return Loc.getLocWithOffset(TextAfter[Offset] != '\0' ? Offset + 1 : Offset);
+}

optional nit: invert the condition and the branches. i just find it a little 
easier to read positive predicates. So, when i have both branches, I try for 
the condition to be positive (or, in other words, I try not to not the 
condition. ;) )


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105734

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


[PATCH] D105734: [clang-tidy] performance-unnecessary-copy-initialization: Do not remove comments on new lines.

2021-07-12 Thread Felix Berger via Phabricator via cfe-commits
flx marked 2 inline comments as done.
flx added a comment.

Thanks for the review!




Comment at: 
clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp:51
+  if (Tok && !Invalid) {
+size_t Offset = std::strcspn(TextAfter, "\n");
+auto PastNewLine = Stmt.getEndLoc().getLocWithOffset(Offset + 1);

ymandel wrote:
> what happens for the last line in the file? I think the `Offset + 1` below 
> will be sketchy (because PastNewLine will be invalid). It might work, but 
> seems best avoided.
I added a check to not go past the end of the string. 



Comment at: 
clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp:56
+// ever comes first.
+auto End = std::min(PastNewLine, BeforeFirstTokenAfterComment);
+Diagnostic << FixItHint::CreateRemoval(

ymandel wrote:
> I suspect this could get tripped up by macros and other expansions. Instead 
> of `std::min`, consider using `SourceManager::isBeforeInTranslationUnit`
> (clang/include/clang/Basic/SourceManager.h;l=1616)? Alternatively, check that 
> both locations are file ids before calling `std::min`.
We don't apply any fixes when the decl statement is inside of a macro, but 
switched to using SourceManager::isBeforeInTranslationUnit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105734

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


[PATCH] D105734: [clang-tidy] performance-unnecessary-copy-initialization: Do not remove comments on new lines.

2021-07-12 Thread Felix Berger via Phabricator via cfe-commits
flx updated this revision to Diff 357993.
flx added a comment.

Make offset operations safer.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105734

Files:
  clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
  
clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
@@ -596,8 +596,15 @@
   // CHECK-FIXES: int i = 0; // Foo bar.
   auto TrailingCommentRemoved = ExpensiveTypeReference(); // Trailing comment.
   // CHECK-MESSAGES: [[@LINE-1]]:8: warning: the variable 
'TrailingCommentRemoved' is copy-constructed from a const reference but is 
never used;
-  // CHECK-FIXES-NOT: auto TrailingCommentRemoved = ExpensiveTypeReference(); 
// Trailing comment.
+  // CHECK-FIXES-NOT: auto TrailingCommentRemoved = ExpensiveTypeReference();
+  // CHECK-FIXES-NOT: // Trailing comment.
   // clang-format on
+
+  auto UnusedAndUnnecessary = ExpensiveTypeReference();
+  // Comments on a new line should not be deleted.
+  // CHECK-MESSAGES: [[@LINE-2]]:8: warning: the variable 
'UnusedAndUnnecessary' is copy-constructed
+  // CHECK-FIXES-NOT: auto UnusedAndUnnecessary = ExpensiveTypeReference();
+  // CHECK-FIXES: // Comments on a new line should not be deleted.
 }
 
 void negativeloopedOverObjectIsModified() {
Index: 
clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
===
--- clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
+++ clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
@@ -39,14 +39,35 @@
   }
 }
 
+llvm::Optional firstLocAfterNewLine(SourceLocation Loc,
+SourceManager ) {
+  bool Invalid;
+  const char *TextAfter = SM.getCharacterData(Loc, );
+  if (Invalid) {
+return llvm::None;
+  }
+  size_t Offset = std::strcspn(TextAfter, "\n");
+  return Loc.getLocWithOffset(TextAfter[Offset] != '\0' ? Offset + 1 : Offset);
+}
+
 void recordRemoval(const DeclStmt , ASTContext ,
DiagnosticBuilder ) {
-  // Attempt to remove the whole line until the next non-comment token.
-  auto Tok = utils::lexer::findNextTokenSkippingComments(
-  Stmt.getEndLoc(), Context.getSourceManager(), Context.getLangOpts());
-  if (Tok) {
-Diagnostic << FixItHint::CreateRemoval(SourceRange(
-Stmt.getBeginLoc(), Tok->getLocation().getLocWithOffset(-1)));
+  auto  = Context.getSourceManager();
+  // Attempt to remove trailing comments as well.
+  auto Tok = utils::lexer::findNextTokenSkippingComments(Stmt.getEndLoc(), SM,
+ 
Context.getLangOpts());
+  llvm::Optional PastNewLine =
+  firstLocAfterNewLine(Stmt.getEndLoc(), SM);
+  if (Tok && PastNewLine) {
+auto BeforeFirstTokenAfterComment = 
Tok->getLocation().getLocWithOffset(-1);
+// Remove until the end of the line or the end of a trailing comment which
+// ever comes first.
+auto End =
+SM.isBeforeInTranslationUnit(*PastNewLine, 
BeforeFirstTokenAfterComment)
+? *PastNewLine
+: BeforeFirstTokenAfterComment;
+Diagnostic << FixItHint::CreateRemoval(
+SourceRange(Stmt.getBeginLoc(), End));
   } else {
 Diagnostic << FixItHint::CreateRemoval(Stmt.getSourceRange());
   }


Index: clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
@@ -596,8 +596,15 @@
   // CHECK-FIXES: int i = 0; // Foo bar.
   auto TrailingCommentRemoved = ExpensiveTypeReference(); // Trailing comment.
   // CHECK-MESSAGES: [[@LINE-1]]:8: warning: the variable 'TrailingCommentRemoved' is copy-constructed from a const reference but is never used;
-  // CHECK-FIXES-NOT: auto TrailingCommentRemoved = ExpensiveTypeReference(); // Trailing comment.
+  // CHECK-FIXES-NOT: auto TrailingCommentRemoved = ExpensiveTypeReference();
+  // CHECK-FIXES-NOT: // Trailing comment.
   // clang-format on
+
+  auto UnusedAndUnnecessary = ExpensiveTypeReference();
+  // Comments on a new line should not be deleted.
+  // CHECK-MESSAGES: [[@LINE-2]]:8: warning: the variable 'UnusedAndUnnecessary' is copy-constructed
+  // CHECK-FIXES-NOT: auto UnusedAndUnnecessary = ExpensiveTypeReference();
+  // CHECK-FIXES: // 

[PATCH] D103395: PR45879: Keep evaluated expression in LValue object

2021-07-12 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff updated this revision to Diff 357988.
sepavloff added a comment.

Rebased patch


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103395

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/test/SemaCXX/constant-expression-cxx2a.cpp


Index: clang/test/SemaCXX/constant-expression-cxx2a.cpp
===
--- clang/test/SemaCXX/constant-expression-cxx2a.cpp
+++ clang/test/SemaCXX/constant-expression-cxx2a.cpp
@@ -1447,3 +1447,11 @@
   constexpr bool b = [a = S(), b = S()] { return a.p == b.p; }();
   static_assert(!b);
 }
+
+namespace PR45879 {
+struct Base {
+  int m;
+};
+struct Derived : Base {};
+constexpr int k = ((Base{} = Derived{}), 0);
+} // namespace PR45879
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -1534,6 +1534,7 @@
 APValue::LValueBase Base;
 CharUnits Offset;
 SubobjectDesignator Designator;
+const Expr *LExpr = nullptr;
 bool IsNullPtr : 1;
 bool InvalidBase : 1;
 
@@ -1542,6 +1543,7 @@
 const CharUnits () const { return Offset; }
 SubobjectDesignator () { return Designator; }
 const SubobjectDesignator () const { return 
Designator;}
+const Expr *getExpr() const { return LExpr; }
 bool isNullPointer() const { return IsNullPtr;}
 
 unsigned getLValueCallIndex() const { return Base.getCallIndex(); }
@@ -1579,6 +1581,8 @@
   Offset = CharUnits::fromQuantity(0);
   InvalidBase = BInvalid;
   Designator = SubobjectDesignator(getType(B));
+  if (!LExpr)
+LExpr = B.dyn_cast();
   IsNullPtr = false;
 }
 
@@ -6077,8 +6081,11 @@
 if (!handleTrivialCopy(Info, MD->getParamDecl(0), Args[0], RHSValue,
MD->getParent()->isUnion()))
   return false;
+const Expr *LHS = This->getExpr();
+if (!LHS)
+  return false;
 if (Info.getLangOpts().CPlusPlus20 && MD->isTrivial() &&
-!HandleUnionActiveMemberChange(Info, Args[0], *This))
+!HandleUnionActiveMemberChange(Info, LHS, *This))
   return false;
 if (!handleAssignment(Info, Args[0], *This, MD->getThisType(),
   RHSValue))
@@ -8039,6 +8046,11 @@
   LValueExprEvaluator(EvalInfo , LValue , bool InvalidBaseOK) :
 LValueExprEvaluatorBaseTy(Info, Result, InvalidBaseOK) {}
 
+  bool evaluate(const Expr *E) {
+Result.LExpr = E;
+return Visit(E);
+  }
+
   bool VisitVarDecl(const Expr *E, const VarDecl *VD);
   bool VisitUnaryPreIncDec(const UnaryOperator *UO);
 
@@ -8100,7 +8112,7 @@
   assert(!E->isValueDependent());
   assert(E->isGLValue() || E->getType()->isFunctionType() ||
  E->getType()->isVoidType() || isa(E));
-  return LValueExprEvaluator(Info, Result, InvalidBaseOK).Visit(E);
+  return LValueExprEvaluator(Info, Result, InvalidBaseOK).evaluate(E);
 }
 
 bool LValueExprEvaluator::VisitDeclRefExpr(const DeclRefExpr *E) {
@@ -8571,6 +8583,8 @@
   : ExprEvaluatorBaseTy(info), Result(Result),
 InvalidBaseOK(InvalidBaseOK) {}
 
+  bool evaluate(const Expr *E) { return Visit(E); }
+
   bool Success(const APValue , const Expr *E) {
 Result.setFrom(Info.Ctx, V);
 return true;
@@ -8680,7 +8694,7 @@
 bool InvalidBaseOK) {
   assert(!E->isValueDependent());
   assert(E->isPRValue() && E->getType()->hasPointerRepresentation());
-  return PointerExprEvaluator(Info, Result, InvalidBaseOK).Visit(E);
+  return PointerExprEvaluator(Info, Result, InvalidBaseOK).evaluate(E);
 }
 
 bool PointerExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) {


Index: clang/test/SemaCXX/constant-expression-cxx2a.cpp
===
--- clang/test/SemaCXX/constant-expression-cxx2a.cpp
+++ clang/test/SemaCXX/constant-expression-cxx2a.cpp
@@ -1447,3 +1447,11 @@
   constexpr bool b = [a = S(), b = S()] { return a.p == b.p; }();
   static_assert(!b);
 }
+
+namespace PR45879 {
+struct Base {
+  int m;
+};
+struct Derived : Base {};
+constexpr int k = ((Base{} = Derived{}), 0);
+} // namespace PR45879
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -1534,6 +1534,7 @@
 APValue::LValueBase Base;
 CharUnits Offset;
 SubobjectDesignator Designator;
+const Expr *LExpr = nullptr;
 bool IsNullPtr : 1;
 bool InvalidBase : 1;
 
@@ -1542,6 +1543,7 @@
 const CharUnits () const { return Offset; }
 SubobjectDesignator () { return Designator; }
 const SubobjectDesignator () const { return Designator;}
+const Expr *getExpr() const { return LExpr; }
 bool isNullPointer() const { return IsNullPtr;}
 
 unsigned getLValueCallIndex() const { return Base.getCallIndex(); 

[clang] cbabfc6 - [WebAssembly] Custom combines for f32x4.demote_zero_f64x2

2021-07-12 Thread Thomas Lively via cfe-commits

Author: Thomas Lively
Date: 2021-07-12T10:32:18-07:00
New Revision: cbabfc63b1be274316552d3eaaf7b2ad88c4c073

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

LOG: [WebAssembly] Custom combines for f32x4.demote_zero_f64x2

Replace the clang builtin function and LLVM intrinsic for
f32x4.demote_zero_f64x2 with combines from normal SDNodes. Also add missing
combines for i32x4.trunc_sat_zero_f64x2_{s,u}, which share the same pattern.

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

Added: 


Modified: 
clang/include/clang/Basic/BuiltinsWebAssembly.def
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/Headers/wasm_simd128.h
clang/test/CodeGen/builtins-wasm.c
clang/test/Headers/wasm.c
llvm/include/llvm/IR/IntrinsicsWebAssembly.td
llvm/lib/Target/WebAssembly/WebAssemblyISD.def
llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
llvm/test/CodeGen/WebAssembly/simd-conversions.ll
llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsWebAssembly.def 
b/clang/include/clang/Basic/BuiltinsWebAssembly.def
index cdaaa5d81f6df..58d10ea1012e1 100644
--- a/clang/include/clang/Basic/BuiltinsWebAssembly.def
+++ b/clang/include/clang/Basic/BuiltinsWebAssembly.def
@@ -191,7 +191,6 @@ TARGET_BUILTIN(__builtin_wasm_narrow_u_i16x8_i32x4, 
"V8UsV4iV4i", "nc", "simd128
 
 TARGET_BUILTIN(__builtin_wasm_trunc_sat_zero_s_f64x2_i32x4, "V4iV2d", "nc", 
"simd128")
 TARGET_BUILTIN(__builtin_wasm_trunc_sat_zero_u_f64x2_i32x4, "V4UiV2d", "nc", 
"simd128")
-TARGET_BUILTIN(__builtin_wasm_demote_zero_f64x2_f32x4, "V4fV2d", "nc", 
"simd128")
 
 TARGET_BUILTIN(__builtin_wasm_load32_zero, "V4iiC*", "n", "simd128")
 TARGET_BUILTIN(__builtin_wasm_load64_zero, "V2LLiLLiC*", "n", "simd128")

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 41ea2bf5f43a2..355ed8ffbfea1 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -17723,11 +17723,6 @@ Value 
*CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
Builder.getInt32(2), Builder.getInt32(3)});
 return Builder.CreateShuffleVector(Trunc, Splat, ConcatMask);
   }
-  case WebAssembly::BI__builtin_wasm_demote_zero_f64x2_f32x4: {
-Value *Vec = EmitScalarExpr(E->getArg(0));
-Function *Callee = CGM.getIntrinsic(Intrinsic::wasm_demote_zero);
-return Builder.CreateCall(Callee, Vec);
-  }
   case WebAssembly::BI__builtin_wasm_load32_zero: {
 Value *Ptr = EmitScalarExpr(E->getArg(0));
 Function *Callee = CGM.getIntrinsic(Intrinsic::wasm_load32_zero);

diff  --git a/clang/lib/Headers/wasm_simd128.h 
b/clang/lib/Headers/wasm_simd128.h
index 4869f7de6c7f3..dc54bb91e135b 100644
--- a/clang/lib/Headers/wasm_simd128.h
+++ b/clang/lib/Headers/wasm_simd128.h
@@ -1151,7 +1151,9 @@ wasm_u32x4_trunc_sat_f64x2_zero(v128_t __a) {
 
 static __inline__ v128_t __DEFAULT_FN_ATTRS
 wasm_f32x4_demote_f64x2_zero(v128_t __a) {
-  return (v128_t)__builtin_wasm_demote_zero_f64x2_f32x4((__f64x2)__a);
+  return (v128_t) __builtin_convertvector(
+  __builtin_shufflevector((__f64x2)__a, (__f64x2){0, 0}, 0, 1, 2, 3),
+  __f32x4);
 }
 
 static __inline__ v128_t __DEFAULT_FN_ATTRS

diff  --git a/clang/test/CodeGen/builtins-wasm.c 
b/clang/test/CodeGen/builtins-wasm.c
index 61130922241cd..8999d391fdeba 100644
--- a/clang/test/CodeGen/builtins-wasm.c
+++ b/clang/test/CodeGen/builtins-wasm.c
@@ -892,12 +892,6 @@ u32x4 trunc_sat_zero_u_f64x2_i32x4(f64x2 x) {
   // WEBASSEMBLY: ret <4 x i32> %1
 }
 
-f32x4 wasm_demote_zero_f64x2_f32x4(f64x2 x) {
-  return __builtin_wasm_demote_zero_f64x2_f32x4(x);
-  // WEBASSEMBLY: call <4 x float> @llvm.wasm.demote.zero(<2 x double> %x)
-  // WEBASSEMBLY: ret
-}
-
 i32x4 load32_zero(const int *p) {
   return __builtin_wasm_load32_zero(p);
   // WEBASSEMBLY: call <4 x i32> @llvm.wasm.load32.zero(i32* %p)

diff  --git a/clang/test/Headers/wasm.c b/clang/test/Headers/wasm.c
index 1cf87b4bb786a..cc2f2b65ca126 100644
--- a/clang/test/Headers/wasm.c
+++ b/clang/test/Headers/wasm.c
@@ -2465,9 +2465,10 @@ v128_t test_u32x4_trunc_sat_f64x2_zero(v128_t a) {
 // CHECK-LABEL: @test_f32x4_demote_f64x2_zero(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[TMP0:%.*]] = bitcast <4 x i32> [[A:%.*]] to <2 x double>
-// CHECK-NEXT:[[TMP1:%.*]] = tail call <4 x float> 
@llvm.wasm.demote.zero(<2 x double> [[TMP0]]) #[[ATTR10]]
-// CHECK-NEXT:[[TMP2:%.*]] = bitcast <4 x float> [[TMP1]] to <4 x i32>
-// CHECK-NEXT:ret <4 x i32> [[TMP2]]
+// CHECK-NEXT:[[SHUFFLE_I:%.*]] = shufflevector <2 x double> [[TMP0]], <2 
x double> zeroinitializer, <4 x i32> 
+// CHECK-NEXT:[[CONV_I:%.*]] = fptrunc <4 

[PATCH] D105755: [WebAssembly] Custom combines for f32x4.demote_zero_f64x2

2021-07-12 Thread Thomas Lively 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 rGcbabfc63b1be: [WebAssembly] Custom combines for 
f32x4.demote_zero_f64x2 (authored by tlively).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105755

Files:
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Headers/wasm_simd128.h
  clang/test/CodeGen/builtins-wasm.c
  clang/test/Headers/wasm.c
  llvm/include/llvm/IR/IntrinsicsWebAssembly.td
  llvm/lib/Target/WebAssembly/WebAssemblyISD.def
  llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
  llvm/test/CodeGen/WebAssembly/simd-conversions.ll
  llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll

Index: llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll
===
--- llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll
+++ llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll
@@ -1,4 +1,4 @@
-; RUN: llc < %s -asm-verbose=false -verify-machineinstrs -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -mattr=+simd128 | FileCheck %s
+; RUN: llc < %s -asm-verbose=false -verify-machineinstrs -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -mattr=+simd128 | FileCheck %s --check-prefixes=CHECK,SLOW
 ; RUN: llc < %s -asm-verbose=false -verify-machineinstrs -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -mattr=+simd128 -fast-isel | FileCheck %s
 
 ; Test that SIMD128 intrinsics lower as expected. These intrinsics are
@@ -542,6 +542,18 @@
   ret <4 x i32> %a
 }
 
+; CHECK-LABEL: trunc_sat_zero_s_v4i32_2:
+; CHECK-NEXT: .functype trunc_sat_zero_s_v4i32_2 (v128) -> (v128){{$}}
+; SLOW-NEXT: i32x4.trunc_sat_zero_f64x2_s $push[[R:[0-9]+]]=, $0{{$}}
+; SLOW-NEXT: return $pop[[R]]{{$}}
+declare <4 x i32> @llvm.fptosi.sat.v4i32.v4f64(<4 x double>)
+define <4 x i32> @trunc_sat_zero_s_v4i32_2(<2 x double> %x) {
+  %v = shufflevector <2 x double> %x, <2 x double> zeroinitializer,
+   <4 x i32> 
+  %a = call <4 x i32> @llvm.fptosi.sat.v4i32.v4f64(<4 x double> %v)
+  ret <4 x i32> %a
+}
+
 ; CHECK-LABEL: trunc_sat_zero_u_v4i32:
 ; CHECK-NEXT: .functype trunc_sat_zero_u_v4i32 (v128) -> (v128){{$}}
 ; CHECK-NEXT: i32x4.trunc_sat_zero_f64x2_u $push[[R:[0-9]+]]=, $0{{$}}
@@ -554,6 +566,18 @@
   ret <4 x i32> %a
 }
 
+; CHECK-LABEL: trunc_sat_zero_u_v4i32_2:
+; CHECK-NEXT: .functype trunc_sat_zero_u_v4i32_2 (v128) -> (v128){{$}}
+; SLOW-NEXT: i32x4.trunc_sat_zero_f64x2_u $push[[R:[0-9]+]]=, $0{{$}}
+; SLOW-NEXT: return $pop[[R]]{{$}}
+declare <4 x i32> @llvm.fptoui.sat.v4i32.v4f64(<4 x double>)
+define <4 x i32> @trunc_sat_zero_u_v4i32_2(<2 x double> %x) {
+  %v = shufflevector <2 x double> %x, <2 x double> zeroinitializer,
+   <4 x i32> 
+  %a = call <4 x i32> @llvm.fptoui.sat.v4i32.v4f64(<4 x double> %v)
+  ret <4 x i32> %a
+}
+
 ; ==
 ; 2 x i64
 ; ==
@@ -722,16 +746,6 @@
   ret <4 x float> %v
 }
 
-; CHECK-LABEL: demote_zero_v4f32:
-; CHECK-NEXT: .functype demote_zero_v4f32 (v128) -> (v128){{$}}
-; CHECK-NEXT: f32x4.demote_zero_f64x2 $push[[R:[0-9]+]]=, $0{{$}}
-; CHECK-NEXT: return $pop[[R]]{{$}}
-declare <4 x float> @llvm.wasm.demote.zero(<2 x double>)
-define <4 x float> @demote_zero_v4f32(<2 x double> %a) {
-  %v = call <4 x float> @llvm.wasm.demote.zero(<2 x double> %a)
-  ret <4 x float> %v
-}
-
 ; ==
 ; 2 x f64
 ; ==
Index: llvm/test/CodeGen/WebAssembly/simd-conversions.ll
===
--- llvm/test/CodeGen/WebAssembly/simd-conversions.ll
+++ llvm/test/CodeGen/WebAssembly/simd-conversions.ll
@@ -82,6 +82,30 @@
   ret <2 x i64> %a
 }
 
+; CHECK-LABEL: demote_zero_v4f32:
+; NO-SIMD128-NOT: f32x4
+; SIMD128-NEXT: .functype demote_zero_v4f32 (v128) -> (v128){{$}}
+; SIMD128-NEXT: f32x4.demote_zero_f64x2 $push[[R:[0-9]+]]=, $0
+; SIMD128-NEXT: return $pop[[R]]
+define <4 x float> @demote_zero_v4f32(<2 x double> %x) {
+  %v = shufflevector <2 x double> %x, <2 x double> zeroinitializer,
+ <4 x i32> 
+  %a = fptrunc <4 x double> %v to <4 x float>
+  ret <4 x float> %a
+}
+
+; CHECK-LABEL: demote_zero_v4f32_2:
+; NO-SIMD128-NOT: f32x4
+; SIMD128-NEXT: .functype demote_zero_v4f32_2 (v128) -> (v128){{$}}
+; SIMD128-NEXT: f32x4.demote_zero_f64x2 $push[[R:[0-9]+]]=, $0
+; SIMD128-NEXT: return $pop[[R]]
+define <4 x float> @demote_zero_v4f32_2(<2 x double> %x) {
+  %v = fptrunc <2 x double> %x to <2 x float>
+  %a = 

[PATCH] D105755: [WebAssembly] Custom combines for f32x4.demote_zero_f64x2

2021-07-12 Thread Thomas Lively via Phabricator via cfe-commits
tlively added inline comments.



Comment at: clang/include/clang/Basic/BuiltinsWebAssembly.def:192-193
 
 TARGET_BUILTIN(__builtin_wasm_trunc_sat_zero_s_f64x2_i32x4, "V4iV2d", "nc", 
"simd128")
 TARGET_BUILTIN(__builtin_wasm_trunc_sat_zero_u_f64x2_i32x4, "V4UiV2d", "nc", 
"simd128")
-TARGET_BUILTIN(__builtin_wasm_demote_zero_f64x2_f32x4, "V4fV2d", "nc", 
"simd128")

aheejin wrote:
> If these share the same pattern, do we need these builtins?
Hmm, good point. Maybe not. I'll investigate that in a follow up.



Comment at: llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp:2367
+
+if (!IsZeroSplat(N->getOperand(1)))
+  return SDValue();

aheejin wrote:
> Do we not need to check if `N->getOpernad(1)` is a specific type, such as 
> `v2f32` or `v2i32`?
I think that the concat_vectors node ensures that the two sides have the same 
type, but I'll explicitly check to be safe.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105755

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


[PATCH] D105755: [WebAssembly] Custom combines for f32x4.demote_zero_f64x2

2021-07-12 Thread Thomas Lively via Phabricator via cfe-commits
tlively updated this revision to Diff 357983.
tlively added a comment.

- Check types of splats as well


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105755

Files:
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Headers/wasm_simd128.h
  clang/test/CodeGen/builtins-wasm.c
  clang/test/Headers/wasm.c
  llvm/include/llvm/IR/IntrinsicsWebAssembly.td
  llvm/lib/Target/WebAssembly/WebAssemblyISD.def
  llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
  llvm/test/CodeGen/WebAssembly/simd-conversions.ll
  llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll

Index: llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll
===
--- llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll
+++ llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll
@@ -1,4 +1,4 @@
-; RUN: llc < %s -asm-verbose=false -verify-machineinstrs -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -mattr=+simd128 | FileCheck %s
+; RUN: llc < %s -asm-verbose=false -verify-machineinstrs -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -mattr=+simd128 | FileCheck %s --check-prefixes=CHECK,SLOW
 ; RUN: llc < %s -asm-verbose=false -verify-machineinstrs -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -mattr=+simd128 -fast-isel | FileCheck %s
 
 ; Test that SIMD128 intrinsics lower as expected. These intrinsics are
@@ -542,6 +542,18 @@
   ret <4 x i32> %a
 }
 
+; CHECK-LABEL: trunc_sat_zero_s_v4i32_2:
+; CHECK-NEXT: .functype trunc_sat_zero_s_v4i32_2 (v128) -> (v128){{$}}
+; SLOW-NEXT: i32x4.trunc_sat_zero_f64x2_s $push[[R:[0-9]+]]=, $0{{$}}
+; SLOW-NEXT: return $pop[[R]]{{$}}
+declare <4 x i32> @llvm.fptosi.sat.v4i32.v4f64(<4 x double>)
+define <4 x i32> @trunc_sat_zero_s_v4i32_2(<2 x double> %x) {
+  %v = shufflevector <2 x double> %x, <2 x double> zeroinitializer,
+   <4 x i32> 
+  %a = call <4 x i32> @llvm.fptosi.sat.v4i32.v4f64(<4 x double> %v)
+  ret <4 x i32> %a
+}
+
 ; CHECK-LABEL: trunc_sat_zero_u_v4i32:
 ; CHECK-NEXT: .functype trunc_sat_zero_u_v4i32 (v128) -> (v128){{$}}
 ; CHECK-NEXT: i32x4.trunc_sat_zero_f64x2_u $push[[R:[0-9]+]]=, $0{{$}}
@@ -554,6 +566,18 @@
   ret <4 x i32> %a
 }
 
+; CHECK-LABEL: trunc_sat_zero_u_v4i32_2:
+; CHECK-NEXT: .functype trunc_sat_zero_u_v4i32_2 (v128) -> (v128){{$}}
+; SLOW-NEXT: i32x4.trunc_sat_zero_f64x2_u $push[[R:[0-9]+]]=, $0{{$}}
+; SLOW-NEXT: return $pop[[R]]{{$}}
+declare <4 x i32> @llvm.fptoui.sat.v4i32.v4f64(<4 x double>)
+define <4 x i32> @trunc_sat_zero_u_v4i32_2(<2 x double> %x) {
+  %v = shufflevector <2 x double> %x, <2 x double> zeroinitializer,
+   <4 x i32> 
+  %a = call <4 x i32> @llvm.fptoui.sat.v4i32.v4f64(<4 x double> %v)
+  ret <4 x i32> %a
+}
+
 ; ==
 ; 2 x i64
 ; ==
@@ -722,16 +746,6 @@
   ret <4 x float> %v
 }
 
-; CHECK-LABEL: demote_zero_v4f32:
-; CHECK-NEXT: .functype demote_zero_v4f32 (v128) -> (v128){{$}}
-; CHECK-NEXT: f32x4.demote_zero_f64x2 $push[[R:[0-9]+]]=, $0{{$}}
-; CHECK-NEXT: return $pop[[R]]{{$}}
-declare <4 x float> @llvm.wasm.demote.zero(<2 x double>)
-define <4 x float> @demote_zero_v4f32(<2 x double> %a) {
-  %v = call <4 x float> @llvm.wasm.demote.zero(<2 x double> %a)
-  ret <4 x float> %v
-}
-
 ; ==
 ; 2 x f64
 ; ==
Index: llvm/test/CodeGen/WebAssembly/simd-conversions.ll
===
--- llvm/test/CodeGen/WebAssembly/simd-conversions.ll
+++ llvm/test/CodeGen/WebAssembly/simd-conversions.ll
@@ -82,6 +82,30 @@
   ret <2 x i64> %a
 }
 
+; CHECK-LABEL: demote_zero_v4f32:
+; NO-SIMD128-NOT: f32x4
+; SIMD128-NEXT: .functype demote_zero_v4f32 (v128) -> (v128){{$}}
+; SIMD128-NEXT: f32x4.demote_zero_f64x2 $push[[R:[0-9]+]]=, $0
+; SIMD128-NEXT: return $pop[[R]]
+define <4 x float> @demote_zero_v4f32(<2 x double> %x) {
+  %v = shufflevector <2 x double> %x, <2 x double> zeroinitializer,
+ <4 x i32> 
+  %a = fptrunc <4 x double> %v to <4 x float>
+  ret <4 x float> %a
+}
+
+; CHECK-LABEL: demote_zero_v4f32_2:
+; NO-SIMD128-NOT: f32x4
+; SIMD128-NEXT: .functype demote_zero_v4f32_2 (v128) -> (v128){{$}}
+; SIMD128-NEXT: f32x4.demote_zero_f64x2 $push[[R:[0-9]+]]=, $0
+; SIMD128-NEXT: return $pop[[R]]
+define <4 x float> @demote_zero_v4f32_2(<2 x double> %x) {
+  %v = fptrunc <2 x double> %x to <2 x float>
+  %a = shufflevector <2 x float> %v, <2 x float> zeroinitializer,
+ <4 x i32> 
+  ret <4 x float> %a
+}
+
 ; CHECK-LABEL: 

[PATCH] D105254: [RISCV] Support machine constraint "S"

2021-07-12 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D105254#2871278 , @luismarques 
wrote:

> In D105254#2852489 , @luismarques 
> wrote:
>
>> Makes sense. Let's wait for the GCC Bugzilla feedback.
>
> With 'S' now documented on the GNU side, I think this can be merged.
>
> Would we keep this constraint forever regardless of how discussions of [1] 
> might evolve?
>
> [1] https://github.com/riscv/riscv-elf-psabi-doc/issues/197

'S' will be kept forever, independent of issue/197. 'S' is useful on its own, 
for explicitly specifying the access modes by inline asm (I can image that the 
Linux kernel will use 'S' someday).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105254

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


[PATCH] D104381: [analyzer] Added a test case for PR46264

2021-07-12 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added a comment.

@NoQ Just a ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104381

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


[PATCH] D104420: thread_local support for AIX

2021-07-12 Thread Jamie Schmeiser via Phabricator via cfe-commits
jamieschmeiser updated this revision to Diff 357970.
jamieschmeiser added a comment.

Respond to review comments:  Update to tests to create common LINUX/AIX 
portions.


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

https://reviews.llvm.org/D104420

Files:
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/test/CodeGenCXX/cxx11-thread-local-reference.cpp
  clang/test/CodeGenCXX/cxx11-thread-local-visibility.cpp
  clang/test/CodeGenCXX/cxx11-thread-local.cpp

Index: clang/test/CodeGenCXX/cxx11-thread-local.cpp
===
--- clang/test/CodeGenCXX/cxx11-thread-local.cpp
+++ clang/test/CodeGenCXX/cxx11-thread-local.cpp
@@ -1,19 +1,20 @@
-// RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck --check-prefix=CHECK --check-prefix=LINUX %s
-// RUN: %clang_cc1 -std=c++11 -emit-llvm %s -O2 -disable-llvm-passes -o - -triple x86_64-linux-gnu | FileCheck --check-prefix=CHECK --check-prefix=LINUX --check-prefix=CHECK-OPT %s
+// RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck --check-prefixes=CHECK,LINUX,LINUX_AIX %s
+// RUN: %clang_cc1 -std=c++11 -emit-llvm %s -O2 -disable-llvm-passes -o - -triple x86_64-linux-gnu | FileCheck --check-prefixes=CHECK,LINUX,LINUX_AIX,CHECK-OPT %s
 // RUN: %clang_cc1 -std=c++11 -femulated-tls -emit-llvm %s -o - \
-// RUN: -triple x86_64-linux-gnu 2>&1 | FileCheck --check-prefix=CHECK --check-prefix=LINUX %s
+// RUN: -triple x86_64-linux-gnu 2>&1 | FileCheck --check-prefixes=CHECK,LINUX,LINUX_AIX %s
 // RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple x86_64-apple-darwin12 | FileCheck --check-prefix=CHECK --check-prefix=DARWIN %s
+// RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple powerpc64-unknown-aix-xcoff | FileCheck --check-prefixes=CHECK,AIX,LINUX_AIX %s
 
-// RUN: %clang_cc1 -std=c++11 -fno-use-cxa-atexit -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck --check-prefix=CHECK --check-prefix=LINUX %s
-// RUN: %clang_cc1 -std=c++11 -fno-use-cxa-atexit -emit-llvm %s -O2 -disable-llvm-passes -o - -triple x86_64-linux-gnu | FileCheck --check-prefix=CHECK --check-prefix=LINUX --check-prefix=CHECK-OPT %s
+// RUN: %clang_cc1 -std=c++11 -fno-use-cxa-atexit -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck --check-prefixes=CHECK,LINUX,LINUX_AIX %s
+// RUN: %clang_cc1 -std=c++11 -fno-use-cxa-atexit -emit-llvm %s -O2 -disable-llvm-passes -o - -triple x86_64-linux-gnu | FileCheck --check-prefixes=CHECK,LINUX,LINUX_AIX,CHECK-OPT %s
 // RUN: %clang_cc1 -std=c++11 -fno-use-cxa-atexit -femulated-tls -emit-llvm %s -o - \
-// RUN: -triple x86_64-linux-gnu 2>&1 | FileCheck --check-prefix=CHECK --check-prefix=LINUX %s
+// RUN: -triple x86_64-linux-gnu 2>&1 | FileCheck --check-prefixes=CHECK,LINUX,LINUX_AIX %s
 // RUN: %clang_cc1 -std=c++11 -fno-use-cxa-atexit -emit-llvm %s -o - -triple x86_64-apple-darwin12 | FileCheck --check-prefix=CHECK --check-prefix=DARWIN %s
 
 int f();
 int g();
 
-// LINUX-DAG: @a ={{.*}} thread_local global i32 0
+// LINUX_AIX-DAG: @a ={{.*}} thread_local global i32 0
 // DARWIN-DAG: @a = internal thread_local global i32 0
 thread_local int a = f();
 extern thread_local int b;
@@ -23,7 +24,7 @@
 static thread_local int d = g();
 
 struct U { static thread_local int m; };
-// LINUX-DAG: @_ZN1U1mE ={{.*}} thread_local global i32 0
+// LINUX_AIX-DAG: @_ZN1U1mE ={{.*}} thread_local global i32 0
 // DARWIN-DAG: @_ZN1U1mE = internal thread_local global i32 0
 thread_local int U::m = f();
 
@@ -89,9 +90,9 @@
 
 // CHECK-DAG: @llvm.global_ctors = appending global {{.*}} @[[GLOBAL_INIT:[^ ]*]]
 
-// LINUX-DAG: @_ZTH1a ={{.*}} alias void (), void ()* @__tls_init
+// LINUX_AIX-DAG: @_ZTH1a ={{.*}} alias void (), void ()* @__tls_init
 // DARWIN-DAG: @_ZTH1a = internal alias void (), void ()* @__tls_init
-// LINUX-DAG: @_ZTHN1U1mE ={{.*}} alias void (), void ()* @__tls_init
+// LINUX_AIX-DAG: @_ZTHN1U1mE ={{.*}} alias void (), void ()* @__tls_init
 // DARWIN-DAG: @_ZTHN1U1mE = internal alias void (), void ()* @__tls_init
 // CHECK-DAG: @_ZTHN1VIiE1mE = linkonce_odr alias void (), void ()* @[[V_M_INIT:[^, ]*]]
 // CHECK-DAG: @_ZTHN1XIiE1mE = linkonce_odr alias void (), void ()* @[[X_M_INIT:[^, ]*]]
@@ -106,16 +107,16 @@
 // Individual variable initialization functions:
 
 // CHECK: define {{.*}} @[[A_INIT:.*]]()
-// CHECK: call i32 @_Z1fv()
+// CHECK: call{{.*}} i32 @_Z1fv()
 // CHECK-NEXT: store i32 {{.*}}, i32* @a, align 4
 
 // CHECK-LABEL: define{{.*}} i32 @_Z1fv()
 int f() {
   // CHECK: %[[GUARD:.*]] = load i8, i8* @_ZGVZ1fvE1n, align 1
   // CHECK: %[[NEED_INIT:.*]] = icmp eq i8 %[[GUARD]], 0
-  // CHECK: br i1 %[[NEED_INIT]]
+  // CHECK: br i1 %[[NEED_INIT]]{{.*}}
 
-  // CHECK: %[[CALL:.*]] = call i32 @_Z1gv()
+  // CHECK: %[[CALL:.*]] = call{{.*}} i32 @_Z1gv()
   // CHECK: store i32 %[[CALL]], i32* @_ZZ1fvE1n, align 4
   // CHECK: store i8 1, i8* @_ZGVZ1fvE1n
   // CHECK: br label
@@ -126,55 +127,57 @@
 }
 
 

[PATCH] D105765: Prepare Compiler-RT for GnuInstallDirs, matching libcxx, document all

2021-07-12 Thread John Ericson via Phabricator via cfe-commits
Ericson2314 marked an inline comment as done.
Ericson2314 added inline comments.



Comment at: compiler-rt/docs/BuildingCompilerRT.rst:12-22
+The instructions on this page are aimed at vendors who ship Compiler-RT as 
part of an
+operating system distribution, a toolchain or similar shipping vehicules. If 
you
+are a user merely trying to use Compiler-RT in your program, you most likely 
want to
+refer to your vendor's documentation, or to the general documentation for using
+Compiler-RT :ref:`here `.
+
+.. warning::

Modeled this file off libc++'s, including taking these two paragraphs. They 
seem appropriate enough here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105765

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


[PATCH] D105765: Prepare Compiler-RT for GnuInstallDirs, matching libcxx, document all

2021-07-12 Thread John Ericson via Phabricator via cfe-commits
Ericson2314 marked an inline comment as done.
Ericson2314 added inline comments.



Comment at: compiler-rt/cmake/base-config-ix.cmake:97
+  else()
+set(temp_path "${temp_path}/${current_segment}")
+  endif()

phosek wrote:
> This isn't set before so it should be always empty in which case you'll end 
> up with an absolute path (that is `/${current_segment}`) right? Isn't that a 
> bug?
Eek! that's embarrassing. Turns out that testing with `-D` is more fraught than 
I thought, and I wasn't hitting that case. Fixed the bug and documented the 
`-D` subtlety too.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105765

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


[PATCH] D105765: Prepare Compiler-RT for GnuInstallDirs, matching libcxx

2021-07-12 Thread John Ericson via Phabricator via cfe-commits
Ericson2314 updated this revision to Diff 357969.
Ericson2314 added a comment.
Herald added projects: clang, libc++, libc++abi, libunwind.
Herald added subscribers: libcxx-commits, cfe-commits.
Herald added a reviewer: libc++.
Herald added a reviewer: libc++abi.
Herald added a reviewer: libunwind.

Fix bugs, add lots of docs


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105765

Files:
  clang/runtime/CMakeLists.txt
  compiler-rt/cmake/Modules/AddCompilerRT.cmake
  compiler-rt/cmake/Modules/CompilerRTDarwinUtils.cmake
  compiler-rt/cmake/Modules/CompilerRTUtils.cmake
  compiler-rt/cmake/base-config-ix.cmake
  compiler-rt/docs/BuildingCompilerRT.rst
  compiler-rt/include/CMakeLists.txt
  compiler-rt/lib/dfsan/CMakeLists.txt
  libcxx/CMakeLists.txt
  libcxx/docs/BuildingLibcxx.rst
  libcxxabi/CMakeLists.txt
  libunwind/CMakeLists.txt
  libunwind/docs/BuildingLibunwind.rst

Index: libunwind/docs/BuildingLibunwind.rst
===
--- libunwind/docs/BuildingLibunwind.rst
+++ libunwind/docs/BuildingLibunwind.rst
@@ -159,3 +159,10 @@
 .. option:: LIBUNWIND_SYSROOT
 
   Sysroot for cross compiling
+
+.. option:: LIBUNWIND_INSTALL_LIBRARY_DIR:PATH
+
+  **Default**: ``lib${LIBUNWIND_LIBDIR_SUFFIX}``
+
+  Path where built libunwind libraries should be installed. If a relative path,
+  relative to ``CMAKE_INSTALL_PREFIX``.
Index: libunwind/CMakeLists.txt
===
--- libunwind/CMakeLists.txt
+++ libunwind/CMakeLists.txt
@@ -116,17 +116,20 @@
 
 if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
   set(LIBUNWIND_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE})
-  set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE})
+  set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE PATH
+  "Path where built libunwind libraries should be installed.")
   if(LIBCXX_LIBDIR_SUBDIR)
 string(APPEND LIBUNWIND_LIBRARY_DIR /${LIBUNWIND_LIBDIR_SUBDIR})
 string(APPEND LIBUNWIND_INSTALL_LIBRARY_DIR /${LIBUNWIND_LIBDIR_SUBDIR})
   endif()
 elseif(LLVM_LIBRARY_OUTPUT_INTDIR)
   set(LIBUNWIND_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
-  set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LIBUNWIND_LIBDIR_SUFFIX})
+  set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LIBUNWIND_LIBDIR_SUFFIX} CACHE PATH
+  "Path where built libunwind libraries should be installed.")
 else()
   set(LIBUNWIND_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBUNWIND_LIBDIR_SUFFIX})
-  set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LIBUNWIND_LIBDIR_SUFFIX})
+  set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LIBUNWIND_LIBDIR_SUFFIX} CACHE PATH
+  "Path where built libunwind libraries should be installed.")
 endif()
 
 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBUNWIND_LIBRARY_DIR})
Index: libcxxabi/CMakeLists.txt
===
--- libcxxabi/CMakeLists.txt
+++ libcxxabi/CMakeLists.txt
@@ -195,7 +195,8 @@
 if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
   set(LIBCXXABI_HEADER_DIR ${LLVM_BINARY_DIR})
   set(LIBCXXABI_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE})
-  set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE})
+  set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE PATH
+  "Path where built libc++abi libraries should be installed.")
   if(LIBCXX_LIBDIR_SUBDIR)
 string(APPEND LIBCXXABI_LIBRARY_DIR /${LIBCXXABI_LIBDIR_SUBDIR})
 string(APPEND LIBCXXABI_INSTALL_LIBRARY_DIR /${LIBCXXABI_LIBDIR_SUBDIR})
@@ -203,11 +204,13 @@
 elseif(LLVM_LIBRARY_OUTPUT_INTDIR)
   set(LIBCXXABI_HEADER_DIR ${LLVM_BINARY_DIR})
   set(LIBCXXABI_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
-  set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LIBCXXABI_LIBDIR_SUFFIX})
+  set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LIBCXXABI_LIBDIR_SUFFIX} CACHE PATH
+  "Path where built libc++abi libraries should be installed.")
 else()
   set(LIBCXXABI_HEADER_DIR ${CMAKE_BINARY_DIR})
   set(LIBCXXABI_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXXABI_LIBDIR_SUFFIX})
-  set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LIBCXXABI_LIBDIR_SUFFIX})
+  set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LIBCXXABI_LIBDIR_SUFFIX} CACHE PATH
+  "Path where built libc++abi libraries should be installed.")
 endif()
 
 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBCXXABI_LIBRARY_DIR})
Index: libcxx/docs/BuildingLibcxx.rst
===
--- libcxx/docs/BuildingLibcxx.rst
+++ libcxx/docs/BuildingLibcxx.rst
@@ -251,6 +251,28 @@
This option can be used to enable or disable the filesystem components on
platforms that may not support them. For example on Windows.
 
+.. option:: LIBCXX_INSTALL_LIBRARY_DIR:PATH
+
+  **Default**: ``lib${LIBCXX_LIBDIR_SUFFIX}``
+
+  Path 

[PATCH] D103096: [analyzer] Implement cast for ranges of symbolic integers.

2021-07-12 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added a comment.

@vsavchenko I've updated the summary. I hope, I addressed your question. 
Currently, this patch has some issues and may not fully reflect the summary. 
I'll update it soon(not without your suggestions). Thanks.


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

https://reviews.llvm.org/D103096

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


[PATCH] D105439: [clang] protects users from relying on libc++ detail headers

2021-07-12 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb added a comment.

In D105439#2871429 , @Quuxplusone 
wrote:

> Given that the goal is to get `include-what-you-use` to stop suggesting that 
> users `#include <__detail/fooimpl.h>` when what they want is spelled 
> ``, I think what's desired here (if anything) would be a pragma 
> targeted at `include-what-you-use` (and other tools). Basically
>
>   // in __detail/fooimpl.h
>   #pragma clang public_header "foo.h"
>
> This pragma can mostly be ignored by Clang; it's just up to those other tools 
> to consume these pragmas and report the correct public header.

Thank you for your opinion. That is not the purpose of this patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105439

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


[PATCH] D105439: [clang] protects users from relying on libc++ detail headers

2021-07-12 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added a comment.

Given that the goal is to get `include-what-you-use` to stop suggesting that 
users `#include <__detail/fooimpl.h>` when what they want is spelled ``, 
I think what's desired here (if anything) would be a pragma targeted at 
`include-what-you-use` (and other tools). Basically

  // in __detail/fooimpl.h
  #pragma clang public_header "foo.h"

This pragma can mostly be ignored by Clang; it's just up to those other tools 
to consume these pragmas and report the correct public header.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105439

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


[PATCH] D103668: [PowerPC] Implement trap and conversion builtins for XL compatibility

2021-07-12 Thread Albion Fung via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGef49d925e2a7: [PowerPC] Implement trap and conversion 
builtins for XL compatibility (authored by Conanap).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103668

Files:
  clang/include/clang/Basic/BuiltinsPPC.def
  clang/lib/Basic/Targets/PPC.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtins-ppc-xlcompat-conversionfunc.c
  clang/test/CodeGen/builtins-ppc-xlcompat-error.c
  clang/test/CodeGen/builtins-ppc-xlcompat-trap-64bit-only.c
  clang/test/CodeGen/builtins-ppc-xlcompat-trap.c
  llvm/include/llvm/IR/IntrinsicsPowerPC.td
  llvm/lib/Target/PowerPC/PPCInstr64Bit.td
  llvm/lib/Target/PowerPC/PPCInstrInfo.td
  llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-conversionfunc.ll
  llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-trap-64bit-only.ll
  llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-trap.ll

Index: llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-trap.ll
===
--- /dev/null
+++ llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-trap.ll
@@ -0,0 +1,139 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu \
+; RUN:   -mcpu=pwr8 < %s | FileCheck %s
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-linux-gnu \
+; RUN:   -mcpu=pwr7 < %s | FileCheck %s
+; RUN: llc -verify-machineinstrs -mtriple=powerpc-unknown-aix \
+; RUN:   -mcpu=pwr8 < %s | FileCheck %s
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-aix \
+; RUN:   -mcpu=pwr8 < %s | FileCheck %s
+
+; tw
+declare void @llvm.ppc.tw(i32 %a, i32 %b, i32 %c)
+define dso_local void @test__twlgt(i32 %a, i32 %b) {
+; CHECK-LABEL: test__twlgt:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:twlgt 3, 4
+; CHECK-NEXT:blr
+  call void @llvm.ppc.tw(i32 %a, i32 %b, i32 1)
+  ret void
+}
+
+define dso_local void @test__twllt(i32 %a, i32 %b) {
+; CHECK-LABEL: test__twllt:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:twllt 3, 4
+; CHECK-NEXT:blr
+  call void @llvm.ppc.tw(i32 %a, i32 %b, i32 2)
+  ret void
+}
+
+define dso_local void @test__tw3(i32 %a, i32 %b) {
+; CHECK-LABEL: test__tw3:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:tw 3, 3, 4
+; CHECK-NEXT:blr
+  call void @llvm.ppc.tw(i32 %a, i32 %b, i32 3)
+  ret void
+}
+
+define dso_local void @test__tweq(i32 %a, i32 %b) {
+; CHECK-LABEL: test__tweq:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:tweq 3, 4
+; CHECK-NEXT:blr
+  call void @llvm.ppc.tw(i32 %a, i32 %b, i32 4)
+  ret void
+}
+
+define dso_local void @test__twlge(i32 %a, i32 %b) {
+; CHECK-LABEL: test__twlge:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:tw 5, 3, 4
+; CHECK-NEXT:blr
+  call void @llvm.ppc.tw(i32 %a, i32 %b, i32 5)
+  ret void
+}
+
+define dso_local void @test__twlle(i32 %a, i32 %b) {
+; CHECK-LABEL: test__twlle:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:tw 6, 3, 4
+; CHECK-NEXT:blr
+  call void @llvm.ppc.tw(i32 %a, i32 %b, i32 6)
+  ret void
+}
+
+define dso_local void @test__twgt(i32 %a, i32 %b) {
+; CHECK-LABEL: test__twgt:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:twgt 3, 4
+; CHECK-NEXT:blr
+  call void @llvm.ppc.tw(i32 %a, i32 %b, i32 8)
+  ret void
+}
+
+define dso_local void @test__twge(i32 %a, i32 %b) {
+; CHECK-LABEL: test__twge:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:tw 12, 3, 4
+; CHECK-NEXT:blr
+  call void @llvm.ppc.tw(i32 %a, i32 %b, i32 12)
+  ret void
+}
+
+define dso_local void @test__twlt(i32 %a, i32 %b) {
+; CHECK-LABEL: test__twlt:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:twlt 3, 4
+; CHECK-NEXT:blr
+  call void @llvm.ppc.tw(i32 %a, i32 %b, i32 16)
+  ret void
+}
+
+define dso_local void @test__twle(i32 %a, i32 %b) {
+; CHECK-LABEL: test__twle:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:tw 20, 3, 4
+; CHECK-NEXT:blr
+  call void @llvm.ppc.tw(i32 %a, i32 %b, i32 20)
+  ret void
+}
+
+define dso_local void @test__twne24(i32 %a, i32 %b) {
+; CHECK-LABEL: test__twne24:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:twne 3, 4
+; CHECK-NEXT:blr
+  call void @llvm.ppc.tw(i32 %a, i32 %b, i32 24)
+  ret void
+}
+
+define dso_local void @test__twu(i32 %a, i32 %b) {
+; CHECK-LABEL: test__twu:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:twu 3, 4
+; CHECK-NEXT:blr
+  call void @llvm.ppc.tw(i32 %a, i32 %b, i32 31)
+  ret void
+}
+
+define dso_local void @test__tw_no_match(i32 %a, i32 %b) {
+; CHECK-LABEL: test__tw_no_match:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:tw 13, 3, 4
+; CHECK-NEXT:blr
+  call void @llvm.ppc.tw(i32 %a, i32 %b, i32 13)
+  ret void
+}
+
+; trap
+declare void @llvm.ppc.trap(i32 %a)
+define dso_local void @test__trap(i32 %a) {
+; CHECK-LABEL: test__trap:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:twnei 3, 0
+; CHECK-NEXT:blr
+  call void @llvm.ppc.trap(i32 %a)
+  ret void
+}
Index: 

[clang] ef49d92 - [PowerPC] Implement trap and conversion builtins for XL compatibility

2021-07-12 Thread Albion Fung via cfe-commits

Author: Albion Fung
Date: 2021-07-12T11:04:17-05:00
New Revision: ef49d925e2a788248473b847a0e51835c6ca854f

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

LOG: [PowerPC] Implement trap and conversion builtins for XL compatibility

This patch implements trap and FP to and from double conversions. The builtins
generate code that mirror what is generated from the XL compiler. Intrinsics
are named conventionally with builtin_ppc, but are aliased to provide the same
builtin names as the XL compiler.

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

Added: 
clang/test/CodeGen/builtins-ppc-xlcompat-conversionfunc.c
clang/test/CodeGen/builtins-ppc-xlcompat-error.c
clang/test/CodeGen/builtins-ppc-xlcompat-trap-64bit-only.c
clang/test/CodeGen/builtins-ppc-xlcompat-trap.c
llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-conversionfunc.ll
llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-trap-64bit-only.ll
llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-trap.ll

Modified: 
clang/include/clang/Basic/BuiltinsPPC.def
clang/lib/Basic/Targets/PPC.cpp
clang/lib/Sema/SemaChecking.cpp
llvm/include/llvm/IR/IntrinsicsPowerPC.td
llvm/lib/Target/PowerPC/PPCInstr64Bit.td
llvm/lib/Target/PowerPC/PPCInstrInfo.td

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsPPC.def 
b/clang/include/clang/Basic/BuiltinsPPC.def
index baaf5db9d1453..6a72cc089df7e 100644
--- a/clang/include/clang/Basic/BuiltinsPPC.def
+++ b/clang/include/clang/Basic/BuiltinsPPC.def
@@ -59,6 +59,18 @@ BUILTIN(__builtin_ppc_ldarx, "LiLiD*", "")
 BUILTIN(__builtin_ppc_lwarx, "iiD*", "")
 BUILTIN(__builtin_ppc_stdcx, "iLiD*Li", "")
 BUILTIN(__builtin_ppc_stwcx, "iiD*i", "")
+BUILTIN(__builtin_ppc_tdw, "vLLiLLiIUi", "")
+BUILTIN(__builtin_ppc_tw, "viiIUi", "")
+BUILTIN(__builtin_ppc_trap, "vi", "")
+BUILTIN(__builtin_ppc_trapd, "vLi", "")
+BUILTIN(__builtin_ppc_fcfid, "dd", "")
+BUILTIN(__builtin_ppc_fcfud, "dd", "")
+BUILTIN(__builtin_ppc_fctid, "dd", "")
+BUILTIN(__builtin_ppc_fctidz, "dd", "")
+BUILTIN(__builtin_ppc_fctiw, "dd", "")
+BUILTIN(__builtin_ppc_fctiwz, "dd", "")
+BUILTIN(__builtin_ppc_fctudz, "dd", "")
+BUILTIN(__builtin_ppc_fctuwz, "dd", "")
 
 BUILTIN(__builtin_ppc_get_timebase, "ULLi", "n")
 

diff  --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index e3c77b2e4450b..b77b4a38bc46f 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -112,6 +112,18 @@ static void defineXLCompatMacros(MacroBuilder ) {
   Builder.defineMacro("__lwarx", "__builtin_ppc_lwarx");
   Builder.defineMacro("__stdcx", "__builtin_ppc_stdcx");
   Builder.defineMacro("__stwcx", "__builtin_ppc_stwcx");
+  Builder.defineMacro("__tdw", "__builtin_ppc_tdw");
+  Builder.defineMacro("__tw", "__builtin_ppc_tw");
+  Builder.defineMacro("__trap", "__builtin_ppc_trap");
+  Builder.defineMacro("__trapd", "__builtin_ppc_trapd");
+  Builder.defineMacro("__fcfid", "__builtin_ppc_fcfid");
+  Builder.defineMacro("__fcfud", "__builtin_ppc_fcfud");
+  Builder.defineMacro("__fctid", "__builtin_ppc_fctid");
+  Builder.defineMacro("__fctidz", "__builtin_ppc_fctidz");
+  Builder.defineMacro("__fctiw", "__builtin_ppc_fctiw");
+  Builder.defineMacro("__fctiwz", "__builtin_ppc_fctiwz");
+  Builder.defineMacro("__fctudz", "__builtin_ppc_fctudz");
+  Builder.defineMacro("__fctuwz", "__builtin_ppc_fctuwz");
 }
 
 /// PPCTargetInfo::getTargetDefines - Return a set of the PowerPC-specific

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 64d838d2cd74f..99621a226dea6 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -3267,6 +3267,8 @@ static bool isPPC_64Builtin(unsigned BuiltinID) {
   case PPC::BI__builtin_bpermd:
   case PPC::BI__builtin_ppc_ldarx:
   case PPC::BI__builtin_ppc_stdcx:
+  case PPC::BI__builtin_ppc_tdw:
+  case PPC::BI__builtin_ppc_trapd:
 return true;
   }
   return false;
@@ -3347,6 +3349,9 @@ bool Sema::CheckPPCBuiltinFunctionCall(const TargetInfo 
, unsigned BuiltinID,
  return SemaBuiltinConstantArgRange(TheCall, 2, 0, 7);
   case PPC::BI__builtin_vsx_xxpermx:
  return SemaBuiltinConstantArgRange(TheCall, 3, 0, 7);
+  case PPC::BI__builtin_ppc_tw:
+  case PPC::BI__builtin_ppc_tdw:
+return SemaBuiltinConstantArgRange(TheCall, 2, 0, 31);
 #define CUSTOM_BUILTIN(Name, Intr, Types, Acc) \
   case PPC::BI__builtin_##Name: \
 return SemaBuiltinPPCMMACall(TheCall, Types);

diff  --git a/clang/test/CodeGen/builtins-ppc-xlcompat-conversionfunc.c 
b/clang/test/CodeGen/builtins-ppc-xlcompat-conversionfunc.c
new file mode 100644
index 0..babc16fcd3a7e
--- /dev/null
+++ b/clang/test/CodeGen/builtins-ppc-xlcompat-conversionfunc.c
@@ -0,0 +1,121 @@
+// 

[PATCH] D105439: [clang] protects users from relying on libc++ detail headers

2021-07-12 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb added a comment.

Ping @aaron.ballman and @ldionne


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105439

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


[PATCH] D105666: [PowerPC] [Altivec] Use signed comparison for vec_all_* and vec_any_* interfaces that compare vector bool types with vector signed types

2021-07-12 Thread Bardia Mahjour 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 rG2071ce9d4559: [Altivec] Use signed comparison for vec_all_* 
and vec_any_* interfaces (authored by bmahjour).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105666

Files:
  clang/lib/Headers/altivec.h
  clang/test/CodeGen/builtins-ppc-altivec.c
  clang/test/CodeGen/builtins-ppc-vsx.c

Index: clang/test/CodeGen/builtins-ppc-vsx.c
===
--- clang/test/CodeGen/builtins-ppc-vsx.c
+++ clang/test/CodeGen/builtins-ppc-vsx.c
@@ -2724,8 +2724,8 @@
   // CHECK-LE: @llvm.ppc.altivec.vcmpgtud.p
 
   res_i = vec_all_ge(vbll, vsll);
-  // CHECK: @llvm.ppc.altivec.vcmpgtud.p
-  // CHECK-LE: @llvm.ppc.altivec.vcmpgtud.p
+  // CHECK: @llvm.ppc.altivec.vcmpgtsd.p
+  // CHECK-LE: @llvm.ppc.altivec.vcmpgtsd.p
 
   res_i = vec_all_ge(vbll, vull);
   // CHECK: @llvm.ppc.altivec.vcmpgtud.p
@@ -2753,8 +2753,8 @@
   // CHECK-LE: @llvm.ppc.altivec.vcmpgtud.p
 
   res_i = vec_all_gt(vbll, vsll);
-  // CHECK: @llvm.ppc.altivec.vcmpgtud.p
-  // CHECK-LE: @llvm.ppc.altivec.vcmpgtud.p
+  // CHECK: @llvm.ppc.altivec.vcmpgtsd.p
+  // CHECK-LE: @llvm.ppc.altivec.vcmpgtsd.p
 
   res_i = vec_all_gt(vbll, vull);
   // CHECK: @llvm.ppc.altivec.vcmpgtud.p
@@ -2782,8 +2782,8 @@
   // CHECK-LE: @llvm.ppc.altivec.vcmpgtud.p
 
   res_i = vec_all_le(vbll, vsll);
-  // CHECK: @llvm.ppc.altivec.vcmpgtud.p
-  // CHECK-LE: @llvm.ppc.altivec.vcmpgtud.p
+  // CHECK: @llvm.ppc.altivec.vcmpgtsd.p
+  // CHECK-LE: @llvm.ppc.altivec.vcmpgtsd.p
 
   res_i = vec_all_le(vbll, vull);
   // CHECK: @llvm.ppc.altivec.vcmpgtud.p
@@ -2811,8 +2811,8 @@
   // CHECK-LE: @llvm.ppc.altivec.vcmpgtud.p
 
   res_i = vec_all_lt(vbll, vsll);
-  // CHECK: @llvm.ppc.altivec.vcmpgtud.p
-  // CHECK-LE: @llvm.ppc.altivec.vcmpgtud.p
+  // CHECK: @llvm.ppc.altivec.vcmpgtsd.p
+  // CHECK-LE: @llvm.ppc.altivec.vcmpgtsd.p
 
   res_i = vec_all_lt(vbll, vull);
   // CHECK: @llvm.ppc.altivec.vcmpgtud.p
@@ -2840,8 +2840,8 @@
   // CHECK-LE: @llvm.ppc.altivec.vcmpgtud.p
 
   res_i = vec_any_ge(vbll, vsll);
-  // CHECK: @llvm.ppc.altivec.vcmpgtud.p
-  // CHECK-LE: @llvm.ppc.altivec.vcmpgtud.p
+  // CHECK: @llvm.ppc.altivec.vcmpgtsd.p
+  // CHECK-LE: @llvm.ppc.altivec.vcmpgtsd.p
 
   res_i = vec_any_ge(vbll, vull);
   // CHECK: @llvm.ppc.altivec.vcmpgtud.p
@@ -2869,8 +2869,8 @@
   // CHECK-LE: @llvm.ppc.altivec.vcmpgtud.p
 
   res_i = vec_any_gt(vbll, vsll);
-  // CHECK: @llvm.ppc.altivec.vcmpgtud.p
-  // CHECK-LE: @llvm.ppc.altivec.vcmpgtud.p
+  // CHECK: @llvm.ppc.altivec.vcmpgtsd.p
+  // CHECK-LE: @llvm.ppc.altivec.vcmpgtsd.p
 
   res_i = vec_any_gt(vbll, vull);
   // CHECK: @llvm.ppc.altivec.vcmpgtud.p
@@ -2898,8 +2898,8 @@
   // CHECK-LE: @llvm.ppc.altivec.vcmpgtud.p
 
   res_i = vec_any_le(vbll, vsll);
-  // CHECK: @llvm.ppc.altivec.vcmpgtud.p
-  // CHECK-LE: @llvm.ppc.altivec.vcmpgtud.p
+  // CHECK: @llvm.ppc.altivec.vcmpgtsd.p
+  // CHECK-LE: @llvm.ppc.altivec.vcmpgtsd.p
 
   res_i = vec_any_le(vbll, vull);
   // CHECK: @llvm.ppc.altivec.vcmpgtud.p
@@ -2927,8 +2927,8 @@
   // CHECK-LE: @llvm.ppc.altivec.vcmpgtud.p
 
   res_i = vec_any_lt(vbll, vsll);
-  // CHECK: @llvm.ppc.altivec.vcmpgtud.p
-  // CHECK-LE: @llvm.ppc.altivec.vcmpgtud.p
+  // CHECK: @llvm.ppc.altivec.vcmpgtsd.p
+  // CHECK-LE: @llvm.ppc.altivec.vcmpgtsd.p
 
   res_i = vec_any_lt(vbll, vull);
   // CHECK: @llvm.ppc.altivec.vcmpgtud.p
Index: clang/test/CodeGen/builtins-ppc-altivec.c
===
--- clang/test/CodeGen/builtins-ppc-altivec.c
+++ clang/test/CodeGen/builtins-ppc-altivec.c
@@ -8097,8 +8097,8 @@
 // CHECK-LE: @llvm.ppc.altivec.vcmpgtub.p
 
   res_i = vec_all_ge(vbc, vsc);
-// CHECK: @llvm.ppc.altivec.vcmpgtub.p
-// CHECK-LE: @llvm.ppc.altivec.vcmpgtub.p
+// CHECK: @llvm.ppc.altivec.vcmpgtsb.p
+// CHECK-LE: @llvm.ppc.altivec.vcmpgtsb.p
 
   res_i = vec_all_ge(vbc, vuc);
 // CHECK: @llvm.ppc.altivec.vcmpgtub.p
@@ -8125,8 +8125,8 @@
 // CHECK-LE: @llvm.ppc.altivec.vcmpgtuh.p
 
   res_i = vec_all_ge(vbs, vs);
-// CHECK: @llvm.ppc.altivec.vcmpgtuh.p
-// CHECK-LE: @llvm.ppc.altivec.vcmpgtuh.p
+// CHECK: @llvm.ppc.altivec.vcmpgtsh.p
+// CHECK-LE: @llvm.ppc.altivec.vcmpgtsh.p
 
   res_i = vec_all_ge(vbs, vus);
 // CHECK: @llvm.ppc.altivec.vcmpgtuh.p
@@ -8153,8 +8153,8 @@
 // CHECK-LE: @llvm.ppc.altivec.vcmpgtuw.p
 
   res_i = vec_all_ge(vbi, vi);
-// CHECK: @llvm.ppc.altivec.vcmpgtuw.p
-// CHECK-LE: @llvm.ppc.altivec.vcmpgtuw.p
+// CHECK: @llvm.ppc.altivec.vcmpgtsw.p
+// CHECK-LE: @llvm.ppc.altivec.vcmpgtsw.p
 
   res_i = vec_all_ge(vbi, vui);
 // CHECK: @llvm.ppc.altivec.vcmpgtuw.p
@@ -8186,8 +8186,8 @@
 // CHECK-LE: @llvm.ppc.altivec.vcmpgtub.p
 
   res_i = vec_all_gt(vbc, vsc);
-// CHECK: @llvm.ppc.altivec.vcmpgtub.p
-// CHECK-LE: @llvm.ppc.altivec.vcmpgtub.p
+// CHECK: 

[clang] 2071ce9 - [Altivec] Use signed comparison for vec_all_* and vec_any_* interfaces

2021-07-12 Thread Bardia Mahjour via cfe-commits

Author: Bardia Mahjour
Date: 2021-07-12T11:41:16-04:00
New Revision: 2071ce9d4559d444a065d78248a7381bf121b766

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

LOG: [Altivec] Use signed comparison for vec_all_* and vec_any_* interfaces

We are currently being inconsistent in using signed vs unsigned comparisons for
vec_all_* and vec_any_* interfaces that use vector bool types. For example we
use signed comparison for vec_all_ge(vector signed char, vector bool char) but
unsigned comparison for when the arguments are swapped. GCC and XL use signed
comparison instead. This patch makes clang consistent with itself and with XL
and GCC.

Reviewed By: nemanjai

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

Added: 


Modified: 
clang/lib/Headers/altivec.h
clang/test/CodeGen/builtins-ppc-altivec.c
clang/test/CodeGen/builtins-ppc-vsx.c

Removed: 




diff  --git a/clang/lib/Headers/altivec.h b/clang/lib/Headers/altivec.h
index 35dde8203b7f..862ec290e1c9 100644
--- a/clang/lib/Headers/altivec.h
+++ b/clang/lib/Headers/altivec.h
@@ -14894,8 +14894,7 @@ static __inline__ int __ATTRS_o_ai vec_all_ge(vector 
unsigned char __a,
 
 static __inline__ int __ATTRS_o_ai vec_all_ge(vector bool char __a,
   vector signed char __b) {
-  return __builtin_altivec_vcmpgtub_p(__CR6_EQ, (vector unsigned char)__b,
-  (vector unsigned char)__a);
+  return __builtin_altivec_vcmpgtsb_p(__CR6_EQ, __b, (vector signed char)__a);
 }
 
 static __inline__ int __ATTRS_o_ai vec_all_ge(vector bool char __a,
@@ -14932,8 +14931,7 @@ static __inline__ int __ATTRS_o_ai vec_all_ge(vector 
unsigned short __a,
 
 static __inline__ int __ATTRS_o_ai vec_all_ge(vector bool short __a,
   vector short __b) {
-  return __builtin_altivec_vcmpgtuh_p(__CR6_EQ, (vector unsigned short)__b,
-  (vector unsigned short)__a);
+  return __builtin_altivec_vcmpgtsh_p(__CR6_EQ, __b, (vector signed short)__a);
 }
 
 static __inline__ int __ATTRS_o_ai vec_all_ge(vector bool short __a,
@@ -14969,8 +14967,7 @@ static __inline__ int __ATTRS_o_ai vec_all_ge(vector 
unsigned int __a,
 
 static __inline__ int __ATTRS_o_ai vec_all_ge(vector bool int __a,
   vector int __b) {
-  return __builtin_altivec_vcmpgtuw_p(__CR6_EQ, (vector unsigned int)__b,
-  (vector unsigned int)__a);
+  return __builtin_altivec_vcmpgtsw_p(__CR6_EQ, __b, (vector signed int)__a);
 }
 
 static __inline__ int __ATTRS_o_ai vec_all_ge(vector bool int __a,
@@ -15008,8 +15005,8 @@ static __inline__ int __ATTRS_o_ai vec_all_ge(vector 
unsigned long long __a,
 
 static __inline__ int __ATTRS_o_ai vec_all_ge(vector bool long long __a,
   vector signed long long __b) {
-  return __builtin_altivec_vcmpgtud_p(__CR6_EQ, (vector unsigned long long)__b,
-  (vector unsigned long long)__a);
+  return __builtin_altivec_vcmpgtsd_p(__CR6_EQ, __b,
+  (vector signed long long)__a);
 }
 
 static __inline__ int __ATTRS_o_ai vec_all_ge(vector bool long long __a,
@@ -15077,8 +15074,7 @@ static __inline__ int __ATTRS_o_ai vec_all_gt(vector 
unsigned char __a,
 
 static __inline__ int __ATTRS_o_ai vec_all_gt(vector bool char __a,
   vector signed char __b) {
-  return __builtin_altivec_vcmpgtub_p(__CR6_LT, (vector unsigned char)__a,
-  (vector unsigned char)__b);
+  return __builtin_altivec_vcmpgtsb_p(__CR6_LT, (vector signed char)__a, __b);
 }
 
 static __inline__ int __ATTRS_o_ai vec_all_gt(vector bool char __a,
@@ -15115,8 +15111,7 @@ static __inline__ int __ATTRS_o_ai vec_all_gt(vector 
unsigned short __a,
 
 static __inline__ int __ATTRS_o_ai vec_all_gt(vector bool short __a,
   vector short __b) {
-  return __builtin_altivec_vcmpgtuh_p(__CR6_LT, (vector unsigned short)__a,
-  (vector unsigned short)__b);
+  return __builtin_altivec_vcmpgtsh_p(__CR6_LT, (vector signed short)__a, __b);
 }
 
 static __inline__ int __ATTRS_o_ai vec_all_gt(vector bool short __a,
@@ -15152,8 +15147,7 @@ static __inline__ int __ATTRS_o_ai vec_all_gt(vector 
unsigned int __a,
 
 static __inline__ int __ATTRS_o_ai vec_all_gt(vector bool int __a,
   vector int __b) {
-  return __builtin_altivec_vcmpgtuw_p(__CR6_LT, (vector unsigned int)__a,
-  (vector unsigned int)__b);
+  return __builtin_altivec_vcmpgtsw_p(__CR6_LT, 

[PATCH] D105821: [analyzer] [WIP] Model destructor for std::unique_ptr

2021-07-12 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD created this revision.
RedDocMD added reviewers: NoQ, vsavchenko, xazax.hun, teemperor.
Herald added subscribers: manas, steakhal, ASDenysPetrov, martong, dkrupp, 
donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, rnkovacs, szepet, 
baloghadamsoftware.
RedDocMD requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This is probably a "throw-away" patch which attempts
to model automatic implicit destructor calls.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105821

Files:
  clang/include/clang/Analysis/ProgramPoint.h
  clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
  clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
  clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp

Index: clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
@@ -19,6 +19,7 @@
 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
+#include "llvm/Support/raw_ostream.h"
 
 using namespace clang;
 using namespace ento;
@@ -757,6 +758,7 @@
   for (ExplodedNodeSet::iterator I = DstPreCall.begin(), E = DstPreCall.end();
I != E; ++I)
 defaultEvalCall(Bldr, *I, *Call, CallOpts);
+  // getCheckerManager().runCheckersForEvalCall(DstInvalidated, DstPreCall, *Call, *this, CallOpts);
 
   getCheckerManager().runCheckersForPostCall(Dst, DstInvalidated,
  *Call, *this);
Index: clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
===
--- clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
+++ clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
@@ -181,6 +181,10 @@
   dispatchWorkItem(Pred, PNode->getLocation(), WU);
   break;
 }
+case ProgramPoint::DestructorCallKind:
+  // Literally do nothing, since there is no real statement
+  // So there is nothing to be done.
+  break;
 default:
   assert(Loc.getAs() ||
  Loc.getAs() ||
Index: clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
+++ clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
@@ -664,14 +664,20 @@
 for (const auto  : EvalCallCheckers) {
   // TODO: Support the situation when the call doesn't correspond
   // to any Expr.
-  ProgramPoint L = ProgramPoint::getProgramPoint(
-  Call.getOriginExpr(), ProgramPoint::PostStmtKind,
+  llvm::Optional LOpt;
+  const Expr *OriginExpr = Call.getOriginExpr();
+  if (OriginExpr) {
+LOpt = ProgramPoint::getProgramPoint(
+  OriginExpr, ProgramPoint::PostStmtKind,
   Pred->getLocationContext(), EvalCallChecker.Checker);
+  } else {
+LOpt = DestructorCallPoint(Pred->getLocationContext(), EvalCallChecker.Checker);
+  }
   bool evaluated = false;
   { // CheckerContext generates transitions(populates checkDest) on
 // destruction, so introduce the scope to make sure it gets properly
 // populated.
-CheckerContext C(B, Eng, Pred, L);
+CheckerContext C(B, Eng, Pred, *LOpt);
 evaluated = EvalCallChecker(Call, C);
   }
   assert(!(evaluated && anyEvaluated)
Index: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
+++ clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
@@ -29,6 +29,7 @@
 #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/SymExpr.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h"
+#include "llvm/Support/raw_ostream.h"
 #include 
 
 using namespace clang;
@@ -177,7 +178,9 @@
 
 bool SmartPtrModeling::evalCall(const CallEvent ,
 CheckerContext ) const {
+
   ProgramStateRef State = C.getState();
+  Call.dump();
   if (!smartptr::isStdSmartPtrCall(Call))
 return false;
 
@@ -261,6 +264,11 @@
 return true;
   }
 
+  if (const auto *DC = dyn_cast()) {
+llvm::errs() << "Wohoo\n";
+return true;
+  }
+
   if (handleAssignOp(Call, C))
 return true;
 
Index: clang/include/clang/Analysis/ProgramPoint.h
===
--- clang/include/clang/Analysis/ProgramPoint.h
+++ clang/include/clang/Analysis/ProgramPoint.h
@@ -84,7 +84,8 @@
   MinImplicitCallKind = PreImplicitCallKind,
   MaxImplicitCallKind = PostImplicitCallKind,
   LoopExitKind,
-  EpsilonKind};
+  EpsilonKind,
+  

[PATCH] D105254: [RISCV] Support machine constraint "S"

2021-07-12 Thread Luís Marques via Phabricator via cfe-commits
luismarques accepted this revision.
luismarques added a comment.
This revision is now accepted and ready to land.

In D105254#2852489 , @luismarques 
wrote:

> Makes sense. Let's wait for the GCC Bugzilla feedback.

With 'S' now documented on the GNU side, I think this can be merged.

Would we keep this constraint forever regardless of how discussions of [1] 
might evolve?

[1] https://github.com/riscv/riscv-elf-psabi-doc/issues/197


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105254

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


[PATCH] D105819: [analyzer] MallocChecker: Add a visitor to leave a note on functions that could have, but did not change ownership on leaked memory

2021-07-12 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus created this revision.
Szelethus added reviewers: NoQ, vsavchenko, steakhal, martong, ASDenysPetrov.
Szelethus added a project: clang.
Herald added subscribers: manas, gamesh411, dkrupp, donat.nagy, 
mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware, xazax.hun, 
whisperity, yaxunl.
Szelethus requested review of this revision.
Herald added subscribers: cfe-commits, aheejin.

This is a rather common feedback we get from out leak checkers: bug reports are 
really short, and are contain barely any usable information on what the 
analyzer did to conclude that a leak actually happened.

This happens because of our bug report minimizing effort. We construct bug 
reports by inspecting the `ExplodedNode`s that lead to the error from the 
bottom up (from the error node all the way to the root of the exploded graph), 
and mark entities that were the cause of a bug, or have interacted with it as 
interesting. In order to make the bug report a bit less verbose, whenever we 
find an entire function call (from `CallEnter` to `CallExitEnd`) that didn't 
talk about any interesting entity, we prune it (click here 
 for more info on 
bug report generation). Even if the event to highlight is exactly this lack of 
interaction with interesting entities.

D105553  generalized the visitor that creates 
notes for these cases. This patch adds a new kind of `NoStateChangeVisitor` 
that leaves notes in functions that took a piece of dynamically allocated 
memory that later leaked as parameter, and didn't change its ownership status.

While there is some code to talk over in MallocChecker.cpp, the main thing to 
discuss in my mind are the test cases, where I display where I want to see this 
visitor end up. I hope to be able to reach a point sometime soon when I can run 
on this on some real projects and post screenshots about it!


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105819

Files:
  clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  clang/test/Analysis/NewDeleteLeaks.cpp
  clang/test/Analysis/self-assign.cpp

Index: clang/test/Analysis/self-assign.cpp
===
--- clang/test/Analysis/self-assign.cpp
+++ clang/test/Analysis/self-assign.cpp
@@ -1,4 +1,9 @@
-// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,cplusplus,unix.Malloc,debug.ExprInspection -analyzer-config eagerly-assume=false %s -verify -analyzer-output=text
+// RUN: %clang_analyze_cc1 -std=c++11 %s -verify -analyzer-output=text \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=cplusplus \
+// RUN:   -analyzer-checker=unix.Malloc \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=false
 
 extern "C" char *strdup(const char* s);
 extern "C" void free(void* ptr);
@@ -28,18 +33,31 @@
   free(str);
 }
 
-StringUsed& StringUsed::operator=(const StringUsed ) { // expected-note{{Assuming rhs == *this}} expected-note{{Assuming rhs == *this}} expected-note{{Assuming rhs != *this}}
-  clang_analyzer_eval(*this == rhs); // expected-warning{{TRUE}} expected-warning{{UNKNOWN}} expected-note{{TRUE}} expected-note{{UNKNOWN}}
+StringUsed ::operator=(const StringUsed ) {
+  // expected-note@-1{{Assuming rhs == *this}}
+  // expected-note@-2{{Assuming rhs == *this}}
+  // expected-note@-3{{Assuming rhs != *this}}
+  clang_analyzer_eval(*this == rhs); // expected-warning{{TRUE}}
+ // expected-warning@-1{{UNKNOWN}}
+ // expected-note@-2{{TRUE}}
+ // expected-note@-3{{UNKNOWN}}
   free(str); // expected-note{{Memory is released}}
-  str = strdup(rhs.str); // expected-warning{{Use of memory after it is freed}}  expected-note{{Use of memory after it is freed}}
-// expected-note@-1{{Memory is allocated}}
+  str = strdup(rhs.str); // expected-warning{{Use of memory after it is freed}}
+ // expected-note@-1{{Use of memory after it is freed}}
+ // expected-note@-2{{Memory is allocated}}
   return *this;
 }
 
-StringUsed& StringUsed::operator=(StringUsed &) { // expected-note{{Assuming rhs == *this}} expected-note{{Assuming rhs != *this}}
-  clang_analyzer_eval(*this == rhs); // expected-warning{{TRUE}} expected-warning{{UNKNOWN}} expected-note{{TRUE}} expected-note{{UNKNOWN}}
+StringUsed ::operator=(StringUsed &) {
+  // expected-note@-1{{Assuming rhs == *this}}
+  // expected-note@-2{{Assuming rhs != *this}}
+  clang_analyzer_eval(*this == rhs); // expected-warning{{TRUE}}
+ // expected-warning@-1{{UNKNOWN}}
+ // expected-note@-2{{TRUE}}
+ // expected-note@-3{{UNKNOWN}}
   str = rhs.str;
-  rhs.str = nullptr; // expected-warning{{Potential memory leak}} 

[clang] 11b47c1 - Reland "[clang-repl] Implement partial translation units and error recovery."

2021-07-12 Thread Vassil Vassilev via cfe-commits

Author: Vassil Vassilev
Date: 2021-07-12T15:21:22Z
New Revision: 11b47c103a36371576711cae1f7527c26f78efb5

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

LOG: Reland "[clang-repl] Implement partial translation units and error 
recovery."

Original commit message:

[clang-repl] Implement partial translation units and error recovery.

https://reviews.llvm.org/D96033 contained a discussion regarding efficient
modeling of error recovery. @rjmccall has outlined the key ideas:

Conceptually, we can split the translation unit into a sequence of partial
translation units (PTUs). Every declaration will be associated with a unique PTU
that owns it.

The first key insight here is that the owning PTU isn't always the "active"
(most recent) PTU, and it isn't always the PTU that the declaration
"comes from". A new declaration (that isn't a redeclaration or specialization of
anything) does belong to the active PTU. A template specialization, however,
belongs to the most recent PTU of all the declarations in its signature - mostly
that means that it can be pulled into a more recent PTU by its template
arguments.

The second key insight is that processing a PTU might extend an earlier PTU.
Rolling back the later PTU shouldn't throw that extension away. For example, if
the second PTU defines a template, and the third PTU requires that template to
be instantiated at float, that template specialization is still part of the
second PTU. Similarly, if the fifth PTU uses an inline function belonging to the
fourth, that definition still belongs to the fourth. When we go to emit code in
a new PTU, we map each declaration we have to emit back to its owning PTU and
emit it in a new module for just the extensions to that PTU. We keep track of
all the modules we've emitted for a PTU so that we can unload them all if we
decide to roll it back.

Most declarations/definitions will only refer to entities from the same or
earlier PTUs. However, it is possible (primarily by defining a
previously-declared entity, but also through templates or ADL) for an entity
that belongs to one PTU to refer to something from a later PTU. We will have to
keep track of this and prevent unwinding to later PTU when we recognize it.
Fortunately, this should be very rare; and crucially, we don't have to do the
bookkeeping for this if we've only got one PTU, e.g. in normal compilation.
Otherwise, PTUs after the first just need to record enough metadata to be able
to revert any changes they've made to declarations belonging to earlier PTUs,
e.g. to redeclaration chains or template specialization lists.

It should even eventually be possible for PTUs to provide their own slab
allocators which can be thrown away as part of rolling back the PTU. We can
maintain a notion of the active allocator and allocate things like Stmt/Expr
nodes in it, temporarily changing it to the appropriate PTU whenever we go to do
something like instantiate a function template. More care will be required when
allocating declarations and types, though.

We would want the PTU to be efficiently recoverable from a Decl; I'm not sure
how best to do that. An easy option that would cover most declarations would be
to make multiple TranslationUnitDecls and parent the declarations appropriately,
but I don't think that's good enough for things like member function templates,
since an instantiation of that would still be parented by its original class.
Maybe we can work this into the DC chain somehow, like how lexical DCs are.

We add a different kind of translation unit `TU_Incremental` which is a
complete translation unit that we might nonetheless incrementally extend later.
Because it is complete (and we might want to generate code for it), we do
perform template instantiation, but because it might be extended later, we don't
warn if it declares or uses undefined internal-linkage symbols.

This patch teaches clang-repl how to recover from errors by disconnecting the
most recent PTU and update the primary PTU lookup tables. For instance:

```./clang-repl
clang-repl> int i = 12; error;
In file included from <<< inputs >>>:1:
input_line_0:1:13: error: C++ requires a type specifier for all declarations
int i = 12; error;
^
error: Parsing failed.
clang-repl> int i = 13; extern "C" int printf(const char*,...);
clang-repl> auto r1 = printf("i=%d\n", i);
i=13
clang-repl> quit
```

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

Added: 
clang/include/clang/Interpreter/PartialTranslationUnit.h

Modified: 
clang/include/clang/AST/ASTContext.h
clang/include/clang/AST/Decl.h
clang/include/clang/AST/Redeclarable.h
clang/include/clang/Basic/LangOptions.h
clang/include/clang/Interpreter/Interpreter.h
clang/include/clang/Lex/Preprocessor.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/ASTContext.cpp

[PATCH] D104925: [Analyzer] Improve report of file read at end-of-file condition.

2021-07-12 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 357947.
balazske added a comment.

Using the new symbol "uninterestingness" feature.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104925

Files:
  clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
  clang/test/Analysis/stream-note.c

Index: clang/test/Analysis/stream-note.c
===
--- clang/test/Analysis/stream-note.c
+++ clang/test/Analysis/stream-note.c
@@ -88,3 +88,60 @@
   fclose(F); // expected-warning {{Stream pointer might be NULL}}
   // expected-note@-1 {{Stream pointer might be NULL}}
 }
+
+void check_eof_notes_feof_after_feof() {
+  FILE *F;
+  char Buf[10];
+  F = fopen("foo1.c", "r");
+  if (F == NULL) { // expected-note {{Taking false branch}} expected-note {{'F' is not equal to NULL}}
+return;
+  }
+  fread(Buf, 1, 1, F);
+  if (feof(F)) { // expected-note {{Taking true branch}}
+clearerr(F);
+fread(Buf, 1, 1, F);   // expected-note {{Assuming that stream reaches end-of-file here}}
+if (feof(F)) { // expected-note {{Taking true branch}}
+  fread(Buf, 1, 1, F); // expected-warning {{Read function called when stream is in EOF state. Function has no effect}}
+  // expected-note@-1 {{Read function called when stream is in EOF state. Function has no effect}}
+}
+  }
+  fclose(F);
+}
+
+void check_eof_notes_feof_after_no_feof() {
+  FILE *F;
+  char Buf[10];
+  F = fopen("foo1.c", "r");
+  if (F == NULL) { // expected-note {{Taking false branch}} expected-note {{'F' is not equal to NULL}}
+return;
+  }
+  fread(Buf, 1, 1, F);
+  if (feof(F)) { // expected-note {{Taking false branch}}
+fclose(F);
+return;
+  } else if (ferror(F)) { // expected-note {{Taking false branch}}
+fclose(F);
+return;
+  }
+  fread(Buf, 1, 1, F);   // expected-note {{Assuming that stream reaches end-of-file here}}
+  if (feof(F)) { // expected-note {{Taking true branch}}
+fread(Buf, 1, 1, F); // expected-warning {{Read function called when stream is in EOF state. Function has no effect}}
+// expected-note@-1 {{Read function called when stream is in EOF state. Function has no effect}}
+  }
+  fclose(F);
+}
+
+void check_eof_notes_feof_or_no_error() {
+  FILE *F;
+  char Buf[10];
+  F = fopen("foo1.c", "r");
+  if (F == NULL) // expected-note {{Taking false branch}} expected-note {{'F' is not equal to NULL}}
+return;
+  int RRet = fread(Buf, 1, 1, F); // expected-note {{Assuming that stream reaches end-of-file here}}
+  if (ferror(F)) {// expected-note {{Taking false branch}}
+  } else {
+fread(Buf, 1, 1, F); // expected-warning {{Read function called when stream is in EOF state. Function has no effect}}
+// expected-note@-1 {{Read function called when stream is in EOF state. Function has no effect}}
+  }
+  fclose(F);
+}
Index: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -25,8 +25,15 @@
 using namespace ento;
 using namespace std::placeholders;
 
+//===--===//
+// Definition of state data structures.
+//===--===//
+
 namespace {
 
+const char *Desc_StreamEof = "Stream already in EOF";
+const char *Desc_ResourceLeak = "Resource leak";
+
 struct FnDescription;
 
 /// State of the stream error flags.
@@ -146,6 +153,14 @@
   }
 };
 
+} // namespace
+
+//===--===//
+// StreamChecker class and utility functions.
+//===--===//
+
+namespace {
+
 class StreamChecker;
 using FnCheck = std::function;
@@ -203,11 +218,18 @@
"Stream handling error"};
   BugType BT_IllegalWhence{this, "Illegal whence argument",
"Stream handling error"};
-  BugType BT_StreamEof{this, "Stream already in EOF", "Stream handling error"};
-  BugType BT_ResourceLeak{this, "Resource leak", "Stream handling error",
+  BugType BT_StreamEof{this, Desc_StreamEof, "Stream handling error"};
+  BugType BT_ResourceLeak{this, Desc_ResourceLeak, "Stream handling error",
   /*SuppressOnSink =*/true};
 
 public:
+  static const StreamChecker *Instance;
+
+  static const BugType *getBT_StreamEof() { return >BT_StreamEof; }
+  static const BugType *getBT_ResourceLeak() {
+return >BT_ResourceLeak;
+  }
+
   void checkPreCall(const CallEvent , CheckerContext ) const;
   bool evalCall(const CallEvent , CheckerContext ) const;
   void checkDeadSymbols(SymbolReaper , CheckerContext ) const;
@@ -337,7 +359,8 @@
   /// There will be always a state 

[PATCH] D77491: [Sema] Introduce BuiltinAttr, per-declaration builtin-ness

2021-07-12 Thread Raul Tambre via Phabricator via cfe-commits
tambre added a comment.

In D77491#2870291 , @jdoerfert wrote:

> First:
> Do I assume right this this feature was simply disabled without any plan to:
>
> - inform the authors (me)
> - update the documentation
> - re-enable support eventually or provide alternatives
>
> XFAILing a test and calling it a day seems inadequate IMHO.
>
> Second:
> Would an approach like this still work: https://reviews.llvm.org/D58531 ?

Informing you would've probably been appropriate in hindsight.
I'm not aware of any relevant documentation that would've been appropriate to 
update.

Re-enabling the support depends on someone taking up the work to correctly 
implement the prototype recognition, which seems to be done in D58531 
 and would work as-is.
However, at the time it seemed to me that the whole builtin declaration 
recognition could use a rewrite to be able to this support this case without 
hacks and require less manual C++ type juggling.
I considered that work beyond my experience with the codebase and the benefits 
of this work easily seemed to outweigh the lack of additional annotations for 
this single function. I received no further feedback on the disabling of that 
test after explaining the reason.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77491

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


[PATCH] D105501: [PowerPC] Power ISA features for Semachecking

2021-07-12 Thread Quinn Pham via Phabricator via cfe-commits
quinnp updated this revision to Diff 357942.
quinnp added a comment.

Addressing some review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105501

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Basic/Targets/PPC.cpp
  clang/lib/Basic/Targets/PPC.h
  clang/lib/Sema/SemaChecking.cpp
  llvm/lib/Target/PowerPC/PPC.td
  llvm/lib/Target/PowerPC/PPCInstrInfo.td
  llvm/lib/Target/PowerPC/PPCSubtarget.cpp
  llvm/lib/Target/PowerPC/PPCSubtarget.h

Index: llvm/lib/Target/PowerPC/PPCSubtarget.h
===
--- llvm/lib/Target/PowerPC/PPCSubtarget.h
+++ llvm/lib/Target/PowerPC/PPCSubtarget.h
@@ -146,6 +146,7 @@
   bool HasStoreFusion;
   bool HasAddiLoadFusion;
   bool HasAddisLoadFusion;
+  bool IsISA2_07;
   bool IsISA3_0;
   bool IsISA3_1;
   bool UseLongCalls;
@@ -319,6 +320,7 @@
 
   bool hasHTM() const { return HasHTM; }
   bool hasFloat128() const { return HasFloat128; }
+  bool isISA2_07() const { return IsISA2_07; }
   bool isISA3_0() const { return IsISA3_0; }
   bool isISA3_1() const { return IsISA3_1; }
   bool useLongCalls() const { return UseLongCalls; }
Index: llvm/lib/Target/PowerPC/PPCSubtarget.cpp
===
--- llvm/lib/Target/PowerPC/PPCSubtarget.cpp
+++ llvm/lib/Target/PowerPC/PPCSubtarget.cpp
@@ -126,6 +126,7 @@
   HasStoreFusion = false;
   HasAddiLoadFusion = false;
   HasAddisLoadFusion = false;
+  IsISA2_07 = false;
   IsISA3_0 = false;
   IsISA3_1 = false;
   UseLongCalls = false;
Index: llvm/lib/Target/PowerPC/PPCInstrInfo.td
===
--- llvm/lib/Target/PowerPC/PPCInstrInfo.td
+++ llvm/lib/Target/PowerPC/PPCInstrInfo.td
@@ -1176,6 +1176,7 @@
 : Predicate<"!Subtarget->getTargetMachine().Options.NoNaNsFPMath">;
 def HasBPERMD : Predicate<"Subtarget->hasBPERMD()">;
 def HasExtDiv : Predicate<"Subtarget->hasExtDiv()">;
+def IsISA2_07 : Predicate<"Subtarget->isISA2_07()">;
 def IsISA3_0 : Predicate<"Subtarget->isISA3_0()">;
 def HasFPU : Predicate<"Subtarget->hasFPU()">;
 def PCRelativeMemops : Predicate<"Subtarget->hasPCRelativeMemops()">;
Index: llvm/lib/Target/PowerPC/PPC.td
===
--- llvm/lib/Target/PowerPC/PPC.td
+++ llvm/lib/Target/PowerPC/PPC.td
@@ -210,9 +210,13 @@
 def DeprecatedDST: SubtargetFeature<"", "DeprecatedDST", "true",
   "Treat vector data stream cache control instructions as deprecated">;
 
+def FeatureISA2_07 : SubtargetFeature<"isa-v207-instructions", "IsISA2_07",
+  "true",
+  "Enable instructions in ISA 2.07.">;
 def FeatureISA3_0 : SubtargetFeature<"isa-v30-instructions", "IsISA3_0",
  "true",
- "Enable instructions in ISA 3.0.">;
+ "Enable instructions in ISA 3.0.",
+ [FeatureISA2_07]>;
 def FeatureISA3_1 : SubtargetFeature<"isa-v31-instructions", "IsISA3_1",
  "true",
  "Enable instructions in ISA 3.1.",
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -3273,9 +3273,17 @@
 }
 
 static bool SemaFeatureCheck(Sema , CallExpr *TheCall,
- StringRef FeatureToCheck, unsigned DiagID) {
-  if (!S.Context.getTargetInfo().hasFeature(FeatureToCheck))
-return S.Diag(TheCall->getBeginLoc(), DiagID) << TheCall->getSourceRange();
+ StringRef FeatureToCheck, unsigned DiagID,
+ StringRef DiagArg = "") {
+  if (!S.Context.getTargetInfo().hasFeature(FeatureToCheck)) {
+if (!DiagArg.empty()) {
+  S.Diag(TheCall->getBeginLoc(), DiagID)
+  << DiagArg << TheCall->getSourceRange();
+} else {
+  S.Diag(TheCall->getBeginLoc(), DiagID) << TheCall->getSourceRange();
+}
+return true;
+  }
   return false;
 }
 
@@ -3318,17 +3326,17 @@
   case PPC::BI__builtin_divde:
   case PPC::BI__builtin_divdeu:
 return SemaFeatureCheck(*this, TheCall, "extdiv",
-diag::err_ppc_builtin_only_on_pwr7);
+diag::err_ppc_builtin_only_on_arch, "7");
   case PPC::BI__builtin_bpermd:
 return SemaFeatureCheck(*this, TheCall, "bpermd",
-diag::err_ppc_builtin_only_on_pwr7);
+diag::err_ppc_builtin_only_on_arch, "7");
   case PPC::BI__builtin_unpack_vector_int128:
 return SemaFeatureCheck(*this, TheCall, "vsx",
-diag::err_ppc_builtin_only_on_pwr7) ||
+

[PATCH] D105490: Remove unused parameter from parseMSInlineAsm.

2021-07-12 Thread Simon Tatham 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 rGe49985bb6065: Remove unused parameter from parseMSInlineAsm. 
(authored by simon_tatham).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105490

Files:
  clang/lib/Parse/ParseStmtAsm.cpp
  llvm/include/llvm/MC/MCParser/MCAsmParser.h
  llvm/lib/MC/MCParser/AsmParser.cpp
  llvm/lib/MC/MCParser/MasmParser.cpp


Index: llvm/lib/MC/MCParser/MasmParser.cpp
===
--- llvm/lib/MC/MCParser/MasmParser.cpp
+++ llvm/lib/MC/MCParser/MasmParser.cpp
@@ -514,9 +514,9 @@
 
   bool lookUpType(StringRef Name, AsmTypeInfo ) const override;
 
-  bool parseMSInlineAsm(void *AsmLoc, std::string ,
-unsigned , unsigned ,
-SmallVectorImpl> ,
+  bool parseMSInlineAsm(std::string , unsigned ,
+unsigned ,
+SmallVectorImpl> ,
 SmallVectorImpl ,
 SmallVectorImpl ,
 const MCInstrInfo *MII, const MCInstPrinter *IP,
@@ -7257,8 +7257,8 @@
 }
 
 bool MasmParser::parseMSInlineAsm(
-void *AsmLoc, std::string , unsigned ,
-unsigned , SmallVectorImpl> ,
+std::string , unsigned , unsigned ,
+SmallVectorImpl> ,
 SmallVectorImpl ,
 SmallVectorImpl , const MCInstrInfo *MII,
 const MCInstPrinter *IP, MCAsmParserSemaCallback ) {
Index: llvm/lib/MC/MCParser/AsmParser.cpp
===
--- llvm/lib/MC/MCParser/AsmParser.cpp
+++ llvm/lib/MC/MCParser/AsmParser.cpp
@@ -258,9 +258,9 @@
 return LTODiscardSymbols.contains(Name);
   }
 
-  bool parseMSInlineAsm(void *AsmLoc, std::string ,
-unsigned , unsigned ,
-SmallVectorImpl> ,
+  bool parseMSInlineAsm(std::string , unsigned ,
+unsigned ,
+SmallVectorImpl> ,
 SmallVectorImpl ,
 SmallVectorImpl ,
 const MCInstrInfo *MII, const MCInstPrinter *IP,
@@ -5927,8 +5927,8 @@
 }
 
 bool AsmParser::parseMSInlineAsm(
-void *AsmLoc, std::string , unsigned ,
-unsigned , SmallVectorImpl> ,
+std::string , unsigned , unsigned ,
+SmallVectorImpl> ,
 SmallVectorImpl ,
 SmallVectorImpl , const MCInstrInfo *MII,
 const MCInstPrinter *IP, MCAsmParserSemaCallback ) {
Index: llvm/include/llvm/MC/MCParser/MCAsmParser.h
===
--- llvm/include/llvm/MC/MCParser/MCAsmParser.h
+++ llvm/include/llvm/MC/MCParser/MCAsmParser.h
@@ -202,8 +202,8 @@
 
   /// Parse MS-style inline assembly.
   virtual bool parseMSInlineAsm(
-  void *AsmLoc, std::string , unsigned ,
-  unsigned , SmallVectorImpl> ,
+  std::string , unsigned , unsigned ,
+  SmallVectorImpl> ,
   SmallVectorImpl ,
   SmallVectorImpl , const MCInstrInfo *MII,
   const MCInstPrinter *IP, MCAsmParserSemaCallback ) = 0;
Index: clang/lib/Parse/ParseStmtAsm.cpp
===
--- clang/lib/Parse/ParseStmtAsm.cpp
+++ clang/lib/Parse/ParseStmtAsm.cpp
@@ -633,9 +633,9 @@
   SmallVector, 4> OpExprs;
   SmallVector Constraints;
   SmallVector Clobbers;
-  if (Parser->parseMSInlineAsm(AsmLoc.getPtrEncoding(), AsmStringIR, 
NumOutputs,
-   NumInputs, OpExprs, Constraints, Clobbers,
-   MII.get(), IP.get(), Callback))
+  if (Parser->parseMSInlineAsm(AsmStringIR, NumOutputs, NumInputs, OpExprs,
+   Constraints, Clobbers, MII.get(), IP.get(),
+   Callback))
 return StmtError();
 
   // Filter out "fpsw" and "mxcsr". They aren't valid GCC asm clobber


Index: llvm/lib/MC/MCParser/MasmParser.cpp
===
--- llvm/lib/MC/MCParser/MasmParser.cpp
+++ llvm/lib/MC/MCParser/MasmParser.cpp
@@ -514,9 +514,9 @@
 
   bool lookUpType(StringRef Name, AsmTypeInfo ) const override;
 
-  bool parseMSInlineAsm(void *AsmLoc, std::string ,
-unsigned , unsigned ,
-SmallVectorImpl> ,
+  bool parseMSInlineAsm(std::string , unsigned ,
+unsigned ,
+SmallVectorImpl> ,
 SmallVectorImpl ,
 SmallVectorImpl ,
 const MCInstrInfo *MII, const MCInstPrinter *IP,
@@ -7257,8 +7257,8 @@
 }
 
 bool MasmParser::parseMSInlineAsm(
-void *AsmLoc, std::string , unsigned ,
-unsigned , SmallVectorImpl> ,
+std::string , unsigned , unsigned ,
+SmallVectorImpl> ,
 SmallVectorImpl ,
 SmallVectorImpl , const 

[clang] e49985b - Remove unused parameter from parseMSInlineAsm.

2021-07-12 Thread Simon Tatham via cfe-commits

Author: Simon Tatham
Date: 2021-07-12T15:07:03+01:00
New Revision: e49985bb6065d4f5ea69fe578e326ec6d43a6b24

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

LOG: Remove unused parameter from parseMSInlineAsm.

No implementation uses the `LocCookie` parameter at all. Errors are
reported from inside that function by `llvm::SourceMgr`, and the
instance of that at the clang call site arranges to pass the error
messages back to a `ClangAsmParserCallback`, which is where the clang
SourceLocation for the error is computed.

(This is part of a patch series working towards the ability to make
SourceLocation into a 64-bit type to handle larger translation units.
But this particular change seems beneficial in its own right.)

Reviewed By: miyuki

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

Added: 


Modified: 
clang/lib/Parse/ParseStmtAsm.cpp
llvm/include/llvm/MC/MCParser/MCAsmParser.h
llvm/lib/MC/MCParser/AsmParser.cpp
llvm/lib/MC/MCParser/MasmParser.cpp

Removed: 




diff  --git a/clang/lib/Parse/ParseStmtAsm.cpp 
b/clang/lib/Parse/ParseStmtAsm.cpp
index 9037895a3bbfc..e520151dcad76 100644
--- a/clang/lib/Parse/ParseStmtAsm.cpp
+++ b/clang/lib/Parse/ParseStmtAsm.cpp
@@ -633,9 +633,9 @@ StmtResult 
Parser::ParseMicrosoftAsmStatement(SourceLocation AsmLoc) {
   SmallVector, 4> OpExprs;
   SmallVector Constraints;
   SmallVector Clobbers;
-  if (Parser->parseMSInlineAsm(AsmLoc.getPtrEncoding(), AsmStringIR, 
NumOutputs,
-   NumInputs, OpExprs, Constraints, Clobbers,
-   MII.get(), IP.get(), Callback))
+  if (Parser->parseMSInlineAsm(AsmStringIR, NumOutputs, NumInputs, OpExprs,
+   Constraints, Clobbers, MII.get(), IP.get(),
+   Callback))
 return StmtError();
 
   // Filter out "fpsw" and "mxcsr". They aren't valid GCC asm clobber

diff  --git a/llvm/include/llvm/MC/MCParser/MCAsmParser.h 
b/llvm/include/llvm/MC/MCParser/MCAsmParser.h
index 56188b7ebaec7..c9b3ab3256da8 100644
--- a/llvm/include/llvm/MC/MCParser/MCAsmParser.h
+++ b/llvm/include/llvm/MC/MCParser/MCAsmParser.h
@@ -202,8 +202,8 @@ class MCAsmParser {
 
   /// Parse MS-style inline assembly.
   virtual bool parseMSInlineAsm(
-  void *AsmLoc, std::string , unsigned ,
-  unsigned , SmallVectorImpl> ,
+  std::string , unsigned , unsigned ,
+  SmallVectorImpl> ,
   SmallVectorImpl ,
   SmallVectorImpl , const MCInstrInfo *MII,
   const MCInstPrinter *IP, MCAsmParserSemaCallback ) = 0;

diff  --git a/llvm/lib/MC/MCParser/AsmParser.cpp 
b/llvm/lib/MC/MCParser/AsmParser.cpp
index 3bc668e699cbc..45e6dfee4ca4b 100644
--- a/llvm/lib/MC/MCParser/AsmParser.cpp
+++ b/llvm/lib/MC/MCParser/AsmParser.cpp
@@ -258,9 +258,9 @@ class AsmParser : public MCAsmParser {
 return LTODiscardSymbols.contains(Name);
   }
 
-  bool parseMSInlineAsm(void *AsmLoc, std::string ,
-unsigned , unsigned ,
-SmallVectorImpl> ,
+  bool parseMSInlineAsm(std::string , unsigned ,
+unsigned ,
+SmallVectorImpl> ,
 SmallVectorImpl ,
 SmallVectorImpl ,
 const MCInstrInfo *MII, const MCInstPrinter *IP,
@@ -5927,8 +5927,8 @@ static int rewritesSort(const AsmRewrite *AsmRewriteA,
 }
 
 bool AsmParser::parseMSInlineAsm(
-void *AsmLoc, std::string , unsigned ,
-unsigned , SmallVectorImpl> ,
+std::string , unsigned , unsigned ,
+SmallVectorImpl> ,
 SmallVectorImpl ,
 SmallVectorImpl , const MCInstrInfo *MII,
 const MCInstPrinter *IP, MCAsmParserSemaCallback ) {

diff  --git a/llvm/lib/MC/MCParser/MasmParser.cpp 
b/llvm/lib/MC/MCParser/MasmParser.cpp
index a91623770116a..a5a48d4b1e9d8 100644
--- a/llvm/lib/MC/MCParser/MasmParser.cpp
+++ b/llvm/lib/MC/MCParser/MasmParser.cpp
@@ -514,9 +514,9 @@ class MasmParser : public MCAsmParser {
 
   bool lookUpType(StringRef Name, AsmTypeInfo ) const override;
 
-  bool parseMSInlineAsm(void *AsmLoc, std::string ,
-unsigned , unsigned ,
-SmallVectorImpl> ,
+  bool parseMSInlineAsm(std::string , unsigned ,
+unsigned ,
+SmallVectorImpl> ,
 SmallVectorImpl ,
 SmallVectorImpl ,
 const MCInstrInfo *MII, const MCInstPrinter *IP,
@@ -7257,8 +7257,8 @@ bool MasmParser::lookUpType(StringRef Name, AsmTypeInfo 
) const {
 }
 
 bool MasmParser::parseMSInlineAsm(
-void *AsmLoc, std::string , unsigned ,
-unsigned , SmallVectorImpl> ,
+std::string , unsigned , unsigned ,
+SmallVectorImpl> ,
 SmallVectorImpl 

[PATCH] D102273: [analyzer] LoopUnrolling: fix crash when a loop counter is captured in a lambda by reference

2021-07-12 Thread Valeriy Savchenko 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 rG1af97c9d0b02: [analyzer] LoopUnrolling: fix crash when a 
loop counter is captured in a lambda… (authored by AbbasSabra, committed by 
vsavchenko).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102273

Files:
  clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
  clang/test/Analysis/loop-unrolling.cpp

Index: clang/test/Analysis/loop-unrolling.cpp
===
--- clang/test/Analysis/loop-unrolling.cpp
+++ clang/test/Analysis/loop-unrolling.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-config unroll-loops=true,cfg-loopexit=true -verify -std=c++11 -analyzer-config exploration_strategy=unexplored_first_queue %s
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-config unroll-loops=true,cfg-loopexit=true,exploration_strategy=dfs -verify -std=c++11 -DDFS=1 %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-config unroll-loops=true,cfg-loopexit=true -verify -std=c++14 -analyzer-config exploration_strategy=unexplored_first_queue %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-config unroll-loops=true,cfg-loopexit=true,exploration_strategy=dfs -verify -std=c++14 -DDFS=1 %s
 
 void clang_analyzer_numTimesReached();
 void clang_analyzer_warnIfReached();
@@ -511,3 +511,39 @@
 clang_analyzer_numTimesReached(); // expected-warning {{4}}
   }
 }
+
+void capture_by_value_as_loop_counter() {
+  int out = 0;
+  auto l = [i = out]() mutable {
+for (i = 0; i < 10; ++i) {
+  clang_analyzer_numTimesReached(); // expected-warning {{10}}
+}
+  };
+}
+
+void capture_by_ref_as_loop_counter() {
+  int out = 0;
+  auto l = [ = out]() {
+for (i = 0; i < 10; ++i) {
+  clang_analyzer_numTimesReached(); // expected-warning {{4}}
+}
+  };
+}
+
+void capture_implicitly_by_value_as_loop_counter() {
+  int i = 0;
+  auto l = [=]() mutable {
+for (i = 0; i < 10; ++i) {
+  clang_analyzer_numTimesReached(); // expected-warning {{10}}
+}
+  };
+}
+
+void capture_implicitly_by_ref_as_loop_counter() {
+  int i = 0;
+  auto l = [&]() mutable {
+for (i = 0; i < 10; ++i) {
+  clang_analyzer_numTimesReached(); // expected-warning {{4}}
+}
+  };
+}
Index: clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
===
--- clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
+++ clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
@@ -79,14 +79,17 @@
   return State;
 }
 
-static internal::Matcher simpleCondition(StringRef BindName) {
-  return binaryOperator(anyOf(hasOperatorName("<"), hasOperatorName(">"),
-  hasOperatorName("<="), hasOperatorName(">="),
-  hasOperatorName("!=")),
-hasEitherOperand(ignoringParenImpCasts(declRefExpr(
-to(varDecl(hasType(isInteger())).bind(BindName),
-hasEitherOperand(ignoringParenImpCasts(
-integerLiteral().bind("boundNum"
+static internal::Matcher simpleCondition(StringRef BindName,
+   StringRef RefName) {
+  return binaryOperator(
+ anyOf(hasOperatorName("<"), hasOperatorName(">"),
+   hasOperatorName("<="), hasOperatorName(">="),
+   hasOperatorName("!=")),
+ hasEitherOperand(ignoringParenImpCasts(
+ declRefExpr(to(varDecl(hasType(isInteger())).bind(BindName)))
+ .bind(RefName))),
+ hasEitherOperand(
+ ignoringParenImpCasts(integerLiteral().bind("boundNum"
   .bind("conditionOperator");
 }
 
@@ -138,7 +141,7 @@
 
 static internal::Matcher forLoopMatcher() {
   return forStmt(
- hasCondition(simpleCondition("initVarName")),
+ hasCondition(simpleCondition("initVarName", "initVarRef")),
  // Initialization should match the form: 'int i = 6' or 'i = 42'.
  hasLoopInit(
  anyOf(declStmt(hasSingleDecl(
@@ -156,17 +159,52 @@
  hasUnaryOperand(declRefExpr(
  to(varDecl(allOf(equalsBoundNode("initVarName"),
   hasType(isInteger(),
- unless(hasBody(hasSuspiciousStmt("initVarName".bind("forLoop");
+ unless(hasBody(hasSuspiciousStmt("initVarName"
+  .bind("forLoop");
 }
 
-static bool isPossiblyEscaped(const VarDecl *VD, ExplodedNode *N) {
-  // Global variables assumed as escaped variables.
+static bool isCapturedByReference(ExplodedNode *N, const DeclRefExpr *DR) {
+
+  // Get the 

[clang] 1af97c9 - [analyzer] LoopUnrolling: fix crash when a loop counter is captured in a lambda by reference

2021-07-12 Thread Valeriy Savchenko via cfe-commits

Author: Abbas Sabra
Date: 2021-07-12T17:06:07+03:00
New Revision: 1af97c9d0b02002586473b4b9845b0c390504a27

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

LOG: [analyzer] LoopUnrolling: fix crash when a loop counter is captured in a 
lambda by reference

Reviewed By: vsavchenko

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

Added: 


Modified: 
clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
clang/test/Analysis/loop-unrolling.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp 
b/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
index dc268e562237f..e5f4e9ea30c97 100644
--- a/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
+++ b/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
@@ -79,14 +79,17 @@ ProgramStateRef processLoopEnd(const Stmt *LoopStmt, 
ProgramStateRef State) {
   return State;
 }
 
-static internal::Matcher simpleCondition(StringRef BindName) {
-  return binaryOperator(anyOf(hasOperatorName("<"), hasOperatorName(">"),
-  hasOperatorName("<="), hasOperatorName(">="),
-  hasOperatorName("!=")),
-hasEitherOperand(ignoringParenImpCasts(declRefExpr(
-
to(varDecl(hasType(isInteger())).bind(BindName),
-hasEitherOperand(ignoringParenImpCasts(
-integerLiteral().bind("boundNum"
+static internal::Matcher simpleCondition(StringRef BindName,
+   StringRef RefName) {
+  return binaryOperator(
+ anyOf(hasOperatorName("<"), hasOperatorName(">"),
+   hasOperatorName("<="), hasOperatorName(">="),
+   hasOperatorName("!=")),
+ hasEitherOperand(ignoringParenImpCasts(
+ declRefExpr(to(varDecl(hasType(isInteger())).bind(BindName)))
+ .bind(RefName))),
+ hasEitherOperand(
+ ignoringParenImpCasts(integerLiteral().bind("boundNum"
   .bind("conditionOperator");
 }
 
@@ -138,7 +141,7 @@ static internal::Matcher hasSuspiciousStmt(StringRef 
NodeName) {
 
 static internal::Matcher forLoopMatcher() {
   return forStmt(
- hasCondition(simpleCondition("initVarName")),
+ hasCondition(simpleCondition("initVarName", "initVarRef")),
  // Initialization should match the form: 'int i = 6' or 'i = 42'.
  hasLoopInit(
  anyOf(declStmt(hasSingleDecl(
@@ -156,17 +159,52 @@ static internal::Matcher forLoopMatcher() {
  hasUnaryOperand(declRefExpr(
  to(varDecl(allOf(equalsBoundNode("initVarName"),
   hasType(isInteger(),
- 
unless(hasBody(hasSuspiciousStmt("initVarName".bind("forLoop");
+ unless(hasBody(hasSuspiciousStmt("initVarName"
+  .bind("forLoop");
 }
 
-static bool isPossiblyEscaped(const VarDecl *VD, ExplodedNode *N) {
-  // Global variables assumed as escaped variables.
+static bool isCapturedByReference(ExplodedNode *N, const DeclRefExpr *DR) {
+
+  // Get the lambda CXXRecordDecl
+  assert(DR->refersToEnclosingVariableOrCapture());
+  const LocationContext *LocCtxt = N->getLocationContext();
+  const Decl *D = LocCtxt->getDecl();
+  const auto *MD = cast(D);
+  assert(MD && MD->getParent()->isLambda() &&
+ "Captured variable should only be seen while evaluating a lambda");
+  const CXXRecordDecl *LambdaCXXRec = MD->getParent();
+
+  // Lookup the fields of the lambda
+  llvm::DenseMap LambdaCaptureFields;
+  FieldDecl *LambdaThisCaptureField;
+  LambdaCXXRec->getCaptureFields(LambdaCaptureFields, LambdaThisCaptureField);
+
+  // Check if the counter is captured by reference
+  const VarDecl *VD = cast(DR->getDecl()->getCanonicalDecl());
+  assert(VD);
+  const FieldDecl *FD = LambdaCaptureFields[VD];
+  assert(FD && "Captured variable without a corresponding field");
+  return FD->getType()->isReferenceType();
+}
+
+// A loop counter is considered escaped if:
+// case 1: It is a global variable.
+// case 2: It is a reference parameter or a reference capture.
+// case 3: It is assigned to a non-const reference variable or parameter.
+// case 4: Has its address taken.
+static bool isPossiblyEscaped(ExplodedNode *N, const DeclRefExpr *DR) {
+  const VarDecl *VD = cast(DR->getDecl()->getCanonicalDecl());
+  assert(VD);
+  // Case 1:
   if (VD->hasGlobalStorage())
 return true;
 
-  const bool isParm = isa(VD);
-  // Reference parameters are assumed as escaped variables.
-  if (isParm && VD->getType()->isReferenceType())
+  const bool IsRefParamOrCapture =
+  isa(VD) || DR->refersToEnclosingVariableOrCapture();
+  // Case 2:
+  if 

  1   2   >