[PATCH] D104044: [clang-format] Fix the issue that empty lines being removed at the beginning of namespace

2021-06-15 Thread Darwin Xu via Phabricator via cfe-commits
darwin added a comment.

In D104044#2816397 , @MyDeveloperDay 
wrote:

> I think we can agree its complicated, how about you take your unit tests and 
> show us what the "code change" looks like to fix the bug
>
> If that gets overly convoluted then perhaps we can bring the idea forward of 
> a more generalised approach.

Thanks, I can do that.


Repository:
  rZORG LLVM Github Zorg

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

https://reviews.llvm.org/D104044

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


[clang] 54bd95c - [clang-format] distinguish function type casts after 21c18d5a04316891110cecc2bf37ce51533decba

2021-06-15 Thread Krasimir Georgiev via cfe-commits

Author: Krasimir Georgiev
Date: 2021-06-15T10:28:36+02:00
New Revision: 54bd95cd96bc7305219b594f95d7d1f447ee4c94

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

LOG: [clang-format] distinguish function type casts after 
21c18d5a04316891110cecc2bf37ce51533decba

https://github.com/llvm/llvm-project/commit/21c18d5a04316891110cecc2bf37ce51533decba
improved the detection of multiplication in function call argument lists,
but unintentionally regressed the handling of function type casts (there
were no tests covering those).
This patch improves the detection of function type casts and adds a few tests.

Reviewed By: HazardyKnusperkeks

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

Added: 


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

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 750839c57c162..a3d8637452978 100755
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -397,9 +397,13 @@ class AnnotatingParser {
   !CurrentToken->Next->HasUnescapedNewline &&
   !CurrentToken->Next->isTrailingComment())
 HasMultipleParametersOnALine = true;
+  bool ProbablyFunctionTypeLParen =
+  (CurrentToken->is(tok::l_paren) && CurrentToken->Next &&
+   CurrentToken->Next->isOneOf(tok::star, tok::amp, tok::caret));
   if ((CurrentToken->Previous->isOneOf(tok::kw_const, tok::kw_auto) ||
CurrentToken->Previous->isSimpleTypeSpecifier()) &&
-  !CurrentToken->isOneOf(tok::l_brace, tok::l_paren))
+  !(CurrentToken->is(tok::l_brace) ||
+(CurrentToken->is(tok::l_paren) && !ProbablyFunctionTypeLParen)))
 Contexts.back().IsExpression = false;
   if (CurrentToken->isOneOf(tok::semi, tok::colon)) {
 MightBeObjCForRangeLoop = false;

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 279f2b3119fc9..3df5d23a930f1 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -8707,6 +8707,11 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
   verifyIndependentOfContext("MACRO('0' <= c && c <= '9');");
   verifyFormat("void f() { f(float{1}, a * a); }");
   verifyFormat("void f() { f(float(1), a * a); }");
+
+  verifyFormat("f((void (*)(int))g);");
+  verifyFormat("f((void (&)(int))g);");
+  verifyFormat("f((void (^)(int))g);");
+
   // FIXME: Is there a way to make this work?
   // verifyIndependentOfContext("MACRO(A *a);");
   verifyFormat("MACRO(A &B);");



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


[PATCH] D104209: [clang-format] distinguish function type casts after 21c18d5a04316891110cecc2bf37ce51533decba

2021-06-15 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG54bd95cd96bc: [clang-format] distinguish function type casts 
after… (authored by krasimir).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104209

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


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -8707,6 +8707,11 @@
   verifyIndependentOfContext("MACRO('0' <= c && c <= '9');");
   verifyFormat("void f() { f(float{1}, a * a); }");
   verifyFormat("void f() { f(float(1), a * a); }");
+
+  verifyFormat("f((void (*)(int))g);");
+  verifyFormat("f((void (&)(int))g);");
+  verifyFormat("f((void (^)(int))g);");
+
   // FIXME: Is there a way to make this work?
   // verifyIndependentOfContext("MACRO(A *a);");
   verifyFormat("MACRO(A &B);");
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -397,9 +397,13 @@
   !CurrentToken->Next->HasUnescapedNewline &&
   !CurrentToken->Next->isTrailingComment())
 HasMultipleParametersOnALine = true;
+  bool ProbablyFunctionTypeLParen =
+  (CurrentToken->is(tok::l_paren) && CurrentToken->Next &&
+   CurrentToken->Next->isOneOf(tok::star, tok::amp, tok::caret));
   if ((CurrentToken->Previous->isOneOf(tok::kw_const, tok::kw_auto) ||
CurrentToken->Previous->isSimpleTypeSpecifier()) &&
-  !CurrentToken->isOneOf(tok::l_brace, tok::l_paren))
+  !(CurrentToken->is(tok::l_brace) ||
+(CurrentToken->is(tok::l_paren) && !ProbablyFunctionTypeLParen)))
 Contexts.back().IsExpression = false;
   if (CurrentToken->isOneOf(tok::semi, tok::colon)) {
 MightBeObjCForRangeLoop = false;


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -8707,6 +8707,11 @@
   verifyIndependentOfContext("MACRO('0' <= c && c <= '9');");
   verifyFormat("void f() { f(float{1}, a * a); }");
   verifyFormat("void f() { f(float(1), a * a); }");
+
+  verifyFormat("f((void (*)(int))g);");
+  verifyFormat("f((void (&)(int))g);");
+  verifyFormat("f((void (^)(int))g);");
+
   // FIXME: Is there a way to make this work?
   // verifyIndependentOfContext("MACRO(A *a);");
   verifyFormat("MACRO(A &B);");
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -397,9 +397,13 @@
   !CurrentToken->Next->HasUnescapedNewline &&
   !CurrentToken->Next->isTrailingComment())
 HasMultipleParametersOnALine = true;
+  bool ProbablyFunctionTypeLParen =
+  (CurrentToken->is(tok::l_paren) && CurrentToken->Next &&
+   CurrentToken->Next->isOneOf(tok::star, tok::amp, tok::caret));
   if ((CurrentToken->Previous->isOneOf(tok::kw_const, tok::kw_auto) ||
CurrentToken->Previous->isSimpleTypeSpecifier()) &&
-  !CurrentToken->isOneOf(tok::l_brace, tok::l_paren))
+  !(CurrentToken->is(tok::l_brace) ||
+(CurrentToken->is(tok::l_paren) && !ProbablyFunctionTypeLParen)))
 Contexts.back().IsExpression = false;
   if (CurrentToken->isOneOf(tok::semi, tok::colon)) {
 MightBeObjCForRangeLoop = false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] bbebf38 - [analyzer] Refactor StoreSiteFinder and extract DefaultStoreHandler

2021-06-15 Thread Valeriy Savchenko via cfe-commits

Author: Valeriy Savchenko
Date: 2021-06-15T11:37:35+03:00
New Revision: bbebf38b736a12c9582f9ae59c8e245a6ed68cb8

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

LOG: [analyzer] Refactor StoreSiteFinder and extract DefaultStoreHandler

After this patch, custom StoreHandlers will also work as expected.

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

Added: 


Modified: 
clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp

Removed: 




diff  --git 
a/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h 
b/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
index 047b2072bbcd9..8e39229ab1fd6 100644
--- a/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
+++ b/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
@@ -125,6 +125,9 @@ struct StoreInfo {
 ///   int x;
 ///   x = 42;
 Assignment,
+/// The value got stored into the parameter region as the result
+/// of a call.
+CallArgument,
 /// The value got stored into the region as block capture.
 /// Block data is modeled as a separate region, thus whenever
 /// the analyzer sees a captured variable, its value is copied
@@ -138,7 +141,7 @@ struct StoreInfo {
   const ExplodedNode *StoreSite;
   /// The expression where the value comes from.
   /// NOTE: might be null.
-  Expr *SourceOfTheValue;
+  const Expr *SourceOfTheValue;
   /// Symbolic value that is being stored.
   SVal Value;
   /// Memory regions involved in the store operation.
@@ -230,7 +233,8 @@ class Tracker : public llvm::RefCountedBase {
   /// \param Opts Tracking options specifying how we got to it.
   ///
   /// NOTE: this method is designed for sub-trackers and visitors.
-  virtual PathDiagnosticPieceRef handle(StoreInfo SI, TrackingOptions Opts);
+  virtual PathDiagnosticPieceRef handle(StoreInfo SI, BugReporterContext &BRC,
+TrackingOptions Opts);
 
   /// Add custom expression handler with the highest priority.
   ///
@@ -322,7 +326,8 @@ class StoreHandler {
   ///
   /// \return the produced note, null if the handler doesn't support this kind
   /// of stores.
-  virtual PathDiagnosticPieceRef handle(StoreInfo SI, TrackingOptions Opts) = 
0;
+  virtual PathDiagnosticPieceRef handle(StoreInfo SI, BugReporterContext &BRC,
+TrackingOptions Opts) = 0;
 
   Tracker &getParentTracker() { return ParentTracker; }
 };

diff  --git a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp 
b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
index c51b7db2b2f3c..0d0b34d7782a0 100644
--- a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -1232,12 +1232,7 @@ class StoreSiteFinder final : public 
TrackingBugReporterVisitor {
   SVal V;
   bool Satisfied = false;
 
-  /// If the visitor is tracking the value directly responsible for the
-  /// bug, we are going to employ false positive suppression.
-  bool EnableNullFPSuppression;
-
-  using TrackingKind = bugreporter::TrackingKind;
-  TrackingKind TKind;
+  TrackingOptions Options;
   const StackFrameContext *OriginSFC;
 
 public:
@@ -1252,11 +1247,9 @@ class StoreSiteFinder final : public 
TrackingBugReporterVisitor {
   ///this visitor can prevent that without polluting the bugpath too
   ///much.
   StoreSiteFinder(bugreporter::TrackerRef ParentTracker, KnownSVal V,
-  const MemRegion *R, bool InEnableNullFPSuppression,
-  TrackingKind TKind,
+  const MemRegion *R, TrackingOptions Options,
   const StackFrameContext *OriginSFC = nullptr)
-  : TrackingBugReporterVisitor(ParentTracker), R(R), V(V),
-EnableNullFPSuppression(InEnableNullFPSuppression), TKind(TKind),
+  : TrackingBugReporterVisitor(ParentTracker), R(R), V(V), 
Options(Options),
 OriginSFC(OriginSFC) {
 assert(R);
   }
@@ -1273,8 +1266,8 @@ void StoreSiteFinder::Profile(llvm::FoldingSetNodeID &ID) 
const {
   ID.AddPointer(&tag);
   ID.AddPointer(R);
   ID.Add(V);
-  ID.AddInteger(static_cast(TKind));
-  ID.AddBoolean(EnableNullFPSuppression);
+  ID.AddInteger(static_cast(Options.Kind));
+  ID.AddBoolean(Options.EnableNullFPSuppression);
 }
 
 /// Returns true if \p N represents the DeclStmt declaring and initializing
@@ -1533,8 +1526,7 @@ PathDiagnosticPieceRef StoreSiteFinder::VisitNode(const 
ExplodedNode *Succ,
 if (!IsParam)
   InitE = InitE->IgnoreParenCasts();
 
-getParentTracker().track(InitE, StoreSite,
- {TKind, EnableNullFPSuppression}

[clang] 85f475c - [analyzer] Extract ControlDependencyHandler

2021-06-15 Thread Valeriy Savchenko via cfe-commits

Author: Valeriy Savchenko
Date: 2021-06-15T11:37:36+03:00
New Revision: 85f475c979aa49b1b833c9e66af9cb35eafd02c7

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

LOG: [analyzer] Extract ControlDependencyHandler

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

Added: 


Modified: 
clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp 
b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
index 0d0b34d7782a..10b674be4972 100644
--- a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -2088,17 +2088,14 @@ class DefaultStoreHandler final : public StoreHandler {
   }
 };
 
-class DefaultExpressionHandler final : public ExpressionHandler {
+class ControlDependencyHandler final : public ExpressionHandler {
 public:
   using ExpressionHandler::ExpressionHandler;
 
   Tracker::Result handle(const Expr *Inner, const ExplodedNode *InputNode,
  const ExplodedNode *LVNode,
  TrackingOptions Opts) override {
-ProgramStateRef LVState = LVNode->getState();
-const StackFrameContext *SFC = LVNode->getStackFrame();
 PathSensitiveBugReport &Report = getParentTracker().getReport();
-Tracker::Result Result;
 
 // We only track expressions if we believe that they are important. Chances
 // are good that control dependencies to the tracking point are also
@@ -2106,14 +2103,31 @@ class DefaultExpressionHandler final : public 
ExpressionHandler {
 // this point.
 // TODO: Shouldn't we track control dependencies of every bug location,
 // rather than only tracked expressions?
-if (LVState->getAnalysisManager()
+if (LVNode->getState()
+->getAnalysisManager()
 .getAnalyzerOptions()
 .ShouldTrackConditions) {
   Report.addVisitor(
   &getParentTracker(), InputNode);
-  Result.FoundSomethingToTrack = true;
+  return {/*FoundSomethingToTrack=*/true};
 }
 
+return {};
+  }
+};
+
+class DefaultExpressionHandler final : public ExpressionHandler {
+public:
+  using ExpressionHandler::ExpressionHandler;
+
+  Tracker::Result handle(const Expr *Inner, const ExplodedNode *InputNode,
+ const ExplodedNode *LVNode,
+ TrackingOptions Opts) override {
+ProgramStateRef LVState = LVNode->getState();
+const StackFrameContext *SFC = LVNode->getStackFrame();
+PathSensitiveBugReport &Report = getParentTracker().getReport();
+Tracker::Result Result;
+
 // The message send could be nil due to the receiver being nil.
 // At this point in the path, the receiver should be live since we are at
 // the message send expr. If it is nil, start tracking it.
@@ -2293,7 +2307,8 @@ class PRValueHandler final : public ExpressionHandler {
 
 Tracker::Tracker(PathSensitiveBugReport &Report) : Report(Report) {
   // Default expression handlers.
-  addHighPriorityHandler();
+  addLowPriorityHandler();
+  addLowPriorityHandler();
   addLowPriorityHandler();
   // Default store handlers.
   addHighPriorityHandler();



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


[clang] 1639dcb - [analyzer] Extract NilReceiverHandler

2021-06-15 Thread Valeriy Savchenko via cfe-commits

Author: Valeriy Savchenko
Date: 2021-06-15T11:37:36+03:00
New Revision: 1639dcb2798469c4372e50bcb6b4cf36ecffd9ce

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

LOG: [analyzer] Extract NilReceiverHandler

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

Added: 


Modified: 
clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp 
b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
index 10b674be4972..29768f79c5dd 100644
--- a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -2116,24 +2116,35 @@ class ControlDependencyHandler final : public 
ExpressionHandler {
   }
 };
 
-class DefaultExpressionHandler final : public ExpressionHandler {
+class NilReceiverHandler final : public ExpressionHandler {
 public:
   using ExpressionHandler::ExpressionHandler;
 
   Tracker::Result handle(const Expr *Inner, const ExplodedNode *InputNode,
  const ExplodedNode *LVNode,
  TrackingOptions Opts) override {
-ProgramStateRef LVState = LVNode->getState();
-const StackFrameContext *SFC = LVNode->getStackFrame();
-PathSensitiveBugReport &Report = getParentTracker().getReport();
-Tracker::Result Result;
-
 // The message send could be nil due to the receiver being nil.
 // At this point in the path, the receiver should be live since we are at
 // the message send expr. If it is nil, start tracking it.
 if (const Expr *Receiver =
 NilReceiverBRVisitor::getNilReceiver(Inner, LVNode))
-  Result.combineWith(getParentTracker().track(Receiver, LVNode, Opts));
+  return getParentTracker().track(Receiver, LVNode, Opts);
+
+return {};
+  }
+};
+
+class DefaultExpressionHandler final : public ExpressionHandler {
+public:
+  using ExpressionHandler::ExpressionHandler;
+
+  Tracker::Result handle(const Expr *Inner, const ExplodedNode *InputNode,
+ const ExplodedNode *LVNode,
+ TrackingOptions Opts) override {
+ProgramStateRef LVState = LVNode->getState();
+const StackFrameContext *SFC = LVNode->getStackFrame();
+PathSensitiveBugReport &Report = getParentTracker().getReport();
+Tracker::Result Result;
 
 // Track the index if this is an array subscript.
 if (const auto *Arr = dyn_cast(Inner))
@@ -2308,6 +2319,7 @@ class PRValueHandler final : public ExpressionHandler {
 Tracker::Tracker(PathSensitiveBugReport &Report) : Report(Report) {
   // Default expression handlers.
   addLowPriorityHandler();
+  addLowPriorityHandler();
   addLowPriorityHandler();
   addLowPriorityHandler();
   // Default store handlers.



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


[clang] 40cb73b - [analyzer] Extract ArrayIndexHandler

2021-06-15 Thread Valeriy Savchenko via cfe-commits

Author: Valeriy Savchenko
Date: 2021-06-15T11:37:36+03:00
New Revision: 40cb73bd20735051eb8f2d43735097d2ff46f0a7

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

LOG: [analyzer] Extract ArrayIndexHandler

One interesting problem was discovered here.  When we do interrupt
Tracker's track flow, we want to interrupt only it and not all the
other flows recursively.

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

Added: 


Modified: 
clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp 
b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
index 29768f79c5dd..23f925e49b15 100644
--- a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -2134,6 +2134,23 @@ class NilReceiverHandler final : public 
ExpressionHandler {
   }
 };
 
+class ArrayIndexHandler final : public ExpressionHandler {
+public:
+  using ExpressionHandler::ExpressionHandler;
+
+  Tracker::Result handle(const Expr *Inner, const ExplodedNode *InputNode,
+ const ExplodedNode *LVNode,
+ TrackingOptions Opts) override {
+// Track the index if this is an array subscript.
+if (const auto *Arr = dyn_cast(Inner))
+  return getParentTracker().track(
+  Arr->getIdx(), LVNode,
+  {Opts.Kind, /*EnableNullFPSuppression*/ false});
+
+return {};
+  }
+};
+
 class DefaultExpressionHandler final : public ExpressionHandler {
 public:
   using ExpressionHandler::ExpressionHandler;
@@ -2146,12 +2163,6 @@ class DefaultExpressionHandler final : public 
ExpressionHandler {
 PathSensitiveBugReport &Report = getParentTracker().getReport();
 Tracker::Result Result;
 
-// Track the index if this is an array subscript.
-if (const auto *Arr = dyn_cast(Inner))
-  Result.combineWith(getParentTracker().track(
-  Arr->getIdx(), LVNode,
-  {Opts.Kind, /*EnableNullFPSuppression*/ false}));
-
 // See if the expression we're interested refers to a variable.
 // If so, we can track both its contents and constraints on its value.
 if (ExplodedGraph::isInterestingLValueExpr(Inner)) {
@@ -2320,6 +2331,7 @@ Tracker::Tracker(PathSensitiveBugReport &Report) : 
Report(Report) {
   // Default expression handlers.
   addLowPriorityHandler();
   addLowPriorityHandler();
+  addLowPriorityHandler();
   addLowPriorityHandler();
   addLowPriorityHandler();
   // Default store handlers.
@@ -2340,8 +2352,12 @@ Tracker::Result Tracker::track(const Expr *E, const 
ExplodedNode *N,
   // Iterate through the handlers in the order according to their priorities.
   for (ExpressionHandlerPtr &Handler : ExpressionHandlers) {
 CombinedResult.combineWith(Handler->handle(Inner, N, LVNode, Opts));
-if (CombinedResult.WasInterrupted)
+if (CombinedResult.WasInterrupted) {
+  // There is no need to confuse our users here.
+  // We got interrupted, but our users don't need to know about it.
+  CombinedResult.WasInterrupted = false;
   break;
+}
   }
 
   return CombinedResult;



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


[PATCH] D103644: [analyzer] Refactor StoreSiteFinder and extract DefaultStoreHandler

2021-06-15 Thread Valeriy Savchenko via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbbebf38b736a: [analyzer] Refactor StoreSiteFinder and 
extract DefaultStoreHandler (authored by vsavchenko).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103644

Files:
  clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
  clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp

Index: clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
===
--- clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -1232,12 +1232,7 @@
   SVal V;
   bool Satisfied = false;
 
-  /// If the visitor is tracking the value directly responsible for the
-  /// bug, we are going to employ false positive suppression.
-  bool EnableNullFPSuppression;
-
-  using TrackingKind = bugreporter::TrackingKind;
-  TrackingKind TKind;
+  TrackingOptions Options;
   const StackFrameContext *OriginSFC;
 
 public:
@@ -1252,11 +1247,9 @@
   ///this visitor can prevent that without polluting the bugpath too
   ///much.
   StoreSiteFinder(bugreporter::TrackerRef ParentTracker, KnownSVal V,
-  const MemRegion *R, bool InEnableNullFPSuppression,
-  TrackingKind TKind,
+  const MemRegion *R, TrackingOptions Options,
   const StackFrameContext *OriginSFC = nullptr)
-  : TrackingBugReporterVisitor(ParentTracker), R(R), V(V),
-EnableNullFPSuppression(InEnableNullFPSuppression), TKind(TKind),
+  : TrackingBugReporterVisitor(ParentTracker), R(R), V(V), Options(Options),
 OriginSFC(OriginSFC) {
 assert(R);
   }
@@ -1273,8 +1266,8 @@
   ID.AddPointer(&tag);
   ID.AddPointer(R);
   ID.Add(V);
-  ID.AddInteger(static_cast(TKind));
-  ID.AddBoolean(EnableNullFPSuppression);
+  ID.AddInteger(static_cast(Options.Kind));
+  ID.AddBoolean(Options.EnableNullFPSuppression);
 }
 
 /// Returns true if \p N represents the DeclStmt declaring and initializing
@@ -1533,8 +1526,7 @@
 if (!IsParam)
   InitE = InitE->IgnoreParenCasts();
 
-getParentTracker().track(InitE, StoreSite,
- {TKind, EnableNullFPSuppression});
+getParentTracker().track(InitE, StoreSite, Options);
   }
 
   // Let's try to find the region where the value came from.
@@ -1605,7 +1597,7 @@
 }
   }
 
-  if (TKind == TrackingKind::Condition &&
+  if (Options.Kind == TrackingKind::Condition && OriginSFC &&
   !OriginSFC->isParentOf(StoreSite->getStackFrame()))
 return nullptr;
 
@@ -1613,60 +1605,41 @@
   SmallString<256> sbuf;
   llvm::raw_svector_ostream os(sbuf);
 
+  StoreInfo SI = {StoreInfo::Assignment, // default kind
+  StoreSite,
+  InitE,
+  V,
+  R,
+  OldRegion};
+
   if (Optional PS = StoreSite->getLocationAs()) {
 const Stmt *S = PS->getStmt();
-const char *action = nullptr;
 const auto *DS = dyn_cast(S);
 const auto *VR = dyn_cast(R);
 
 if (DS) {
-  action = R->canPrintPretty() ? "initialized to " :
- "Initializing to ";
+  SI.StoreKind = StoreInfo::Initialization;
 } else if (isa(S)) {
-  action = R->canPrintPretty() ? "captured by block as " :
- "Captured by block as ";
+  SI.StoreKind = StoreInfo::BlockCapture;
   if (VR) {
 // See if we can get the BlockVarRegion.
 ProgramStateRef State = StoreSite->getState();
 SVal V = StoreSite->getSVal(S);
 if (const auto *BDR =
-  dyn_cast_or_null(V.getAsRegion())) {
+dyn_cast_or_null(V.getAsRegion())) {
   if (const VarRegion *OriginalR = BDR->getOriginalRegion(VR)) {
-if (auto KV = State->getSVal(OriginalR).getAs())
-  getParentTracker().track(
-  *KV, OriginalR, {TKind, EnableNullFPSuppression}, OriginSFC);
+getParentTracker().track(State->getSVal(OriginalR), OriginalR,
+ Options, OriginSFC);
   }
 }
   }
 }
-if (action)
-  showBRDiagnostics(action, os, R, V, OldRegion, DS);
-
-  } else if (StoreSite->getLocation().getAs()) {
-if (const auto *VR = dyn_cast(R))
-  showBRParamDiagnostics(os, VR, V, OldRegion);
+  } else if (SI.StoreSite->getLocation().getAs() &&
+ isa(SI.Dest)) {
+SI.StoreKind = StoreInfo::CallArgument;
   }
 
-  if (os.str().empty())
-showBRDefaultDiagnostics(os, R, V, OldRegion);
-
-  if (TKind == bugreporter::TrackingKind::Condition)
-os << WillBeUsedForACondition;
-
-  // Construct a new PathDiagnosticPiece.
-  ProgramPoint P = StoreSite->getLocation();
-  PathDiagnosticLocation L;
-  if (P.getAs() && InitE)
-L = PathDiagnosticLocatio

[clang] 2e49067 - [analyzer] Extract InterestingLValueHandler

2021-06-15 Thread Valeriy Savchenko via cfe-commits

Author: Valeriy Savchenko
Date: 2021-06-15T11:37:36+03:00
New Revision: 2e490676ea2eb419e7b2f54e1e2e537d5244ebbc

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

LOG: [analyzer] Extract InterestingLValueHandler

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

Added: 


Modified: 
clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp 
b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
index 23f925e49b15..835c54ef5f68 100644
--- a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -2151,7 +2151,8 @@ class ArrayIndexHandler final : public ExpressionHandler {
   }
 };
 
-class DefaultExpressionHandler final : public ExpressionHandler {
+// TODO: extract it into more handlers
+class InterestingLValueHandler final : public ExpressionHandler {
 public:
   using ExpressionHandler::ExpressionHandler;
 
@@ -2219,13 +2220,26 @@ class DefaultExpressionHandler final : public 
ExpressionHandler {
 // previously.
 Report.addVisitor(*DV,
 InputNode);
-
 getParentTracker().track(V, R, Opts, SFC);
-
-return Result;
   }
 }
 
+return Result;
+  }
+};
+
+class DefaultExpressionHandler final : public ExpressionHandler {
+public:
+  using ExpressionHandler::ExpressionHandler;
+
+  Tracker::Result handle(const Expr *Inner, const ExplodedNode *InputNode,
+ const ExplodedNode *LVNode,
+ TrackingOptions Opts) override {
+ProgramStateRef LVState = LVNode->getState();
+const StackFrameContext *SFC = LVNode->getStackFrame();
+PathSensitiveBugReport &Report = getParentTracker().getReport();
+Tracker::Result Result;
+
 // If the expression is not an "lvalue expression", we can still
 // track the constraints on its contents.
 SVal V = LVState->getSValAsScalarOrLoc(Inner, 
LVNode->getLocationContext());
@@ -2332,6 +2346,7 @@ Tracker::Tracker(PathSensitiveBugReport &Report) : 
Report(Report) {
   addLowPriorityHandler();
   addLowPriorityHandler();
   addLowPriorityHandler();
+  addLowPriorityHandler();
   addLowPriorityHandler();
   addLowPriorityHandler();
   // Default store handlers.



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


[clang] 6e6a26b - [analyzer] Extract InlinedFunctionCallHandler

2021-06-15 Thread Valeriy Savchenko via cfe-commits

Author: Valeriy Savchenko
Date: 2021-06-15T11:37:36+03:00
New Revision: 6e6a26b8f0ea8300d5a814e4150e225c33ec25de

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

LOG: [analyzer] Extract InlinedFunctionCallHandler

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

Added: 


Modified: 
clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp 
b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
index 835c54ef5f68..dab1ba0a9d50 100644
--- a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -937,91 +937,6 @@ class ReturnVisitor : public TrackingBugReporterVisitor {
 ID.AddBoolean(EnableNullFPSuppression);
   }
 
-  /// Adds a ReturnVisitor if the given statement represents a call that was
-  /// inlined.
-  ///
-  /// This will search back through the ExplodedGraph, starting from the given
-  /// node, looking for when the given statement was processed. If it turns out
-  /// the statement is a call that was inlined, we add the visitor to the
-  /// bug report, so it can print a note later.
-  static void addVisitorIfNecessary(TrackerRef ParentTracker,
-const ExplodedNode *Node, const Stmt *S,
-PathSensitiveBugReport &BR,
-bool InEnableNullFPSuppression,
-bugreporter::TrackingKind TKind) {
-if (!CallEvent::isCallStmt(S))
-  return;
-
-// First, find when we processed the statement.
-// If we work with a 'CXXNewExpr' that is going to be purged away before
-// its call take place. We would catch that purge in the last condition
-// as a 'StmtPoint' so we have to bypass it.
-const bool BypassCXXNewExprEval = isa(S);
-
-// This is moving forward when we enter into another context.
-const StackFrameContext *CurrentSFC = Node->getStackFrame();
-
-do {
-  // If that is satisfied we found our statement as an inlined call.
-  if (Optional CEE = Node->getLocationAs())
-if (CEE->getCalleeContext()->getCallSite() == S)
-  break;
-
-  // Try to move forward to the end of the call-chain.
-  Node = Node->getFirstPred();
-  if (!Node)
-break;
-
-  const StackFrameContext *PredSFC = Node->getStackFrame();
-
-  // If that is satisfied we found our statement.
-  // FIXME: This code currently bypasses the call site for the
-  //conservatively evaluated allocator.
-  if (!BypassCXXNewExprEval)
-if (Optional SP = Node->getLocationAs())
-  // See if we do not enter into another context.
-  if (SP->getStmt() == S && CurrentSFC == PredSFC)
-break;
-
-  CurrentSFC = PredSFC;
-} while (Node->getStackFrame() == CurrentSFC);
-
-// Next, step over any post-statement checks.
-while (Node && Node->getLocation().getAs())
-  Node = Node->getFirstPred();
-if (!Node)
-  return;
-
-// Finally, see if we inlined the call.
-Optional CEE = Node->getLocationAs();
-if (!CEE)
-  return;
-
-const StackFrameContext *CalleeContext = CEE->getCalleeContext();
-if (CalleeContext->getCallSite() != S)
-  return;
-
-// Check the return value.
-ProgramStateRef State = Node->getState();
-SVal RetVal = Node->getSVal(S);
-
-// Handle cases where a reference is returned and then immediately used.
-if (cast(S)->isGLValue())
-  if (Optional LValue = RetVal.getAs())
-RetVal = State->getSVal(*LValue);
-
-// See if the return value is NULL. If so, suppress the report.
-AnalyzerOptions &Options = State->getAnalysisManager().options;
-
-bool EnableNullFPSuppression = false;
-if (InEnableNullFPSuppression && Options.ShouldSuppressNullReturnPaths)
-  if (Optional RetLoc = RetVal.getAs())
-EnableNullFPSuppression = State->isNull(*RetLoc).isConstrainedTrue();
-
-BR.addVisitor(ParentTracker, CalleeContext,
- EnableNullFPSuppression, Options, TKind);
-  }
-
   PathDiagnosticPieceRef visitNodeInitial(const ExplodedNode *N,
   BugReporterContext &BRC,
   PathSensitiveBugReport &BR) {
@@ -2228,6 +2143,96 @@ class InterestingLValueHandler final : public 
ExpressionHandler {
   }
 };
 
+/// Adds a ReturnVisitor if the given statement represents a call that was
+/// inlined.
+///
+/// This will search back through the ExplodedGraph, starting from the given
+/// node, looking for when the given statement was processed. If it turns out
+/// the statement is a call that was inlined, we 

[PATCH] D103677: [analyzer] Extract ControlDependencyHandler

2021-06-15 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 rG85f475c979aa: [analyzer] Extract ControlDependencyHandler 
(authored by vsavchenko).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103677

Files:
  clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp


Index: clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
===
--- clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -2088,17 +2088,14 @@
   }
 };
 
-class DefaultExpressionHandler final : public ExpressionHandler {
+class ControlDependencyHandler final : public ExpressionHandler {
 public:
   using ExpressionHandler::ExpressionHandler;
 
   Tracker::Result handle(const Expr *Inner, const ExplodedNode *InputNode,
  const ExplodedNode *LVNode,
  TrackingOptions Opts) override {
-ProgramStateRef LVState = LVNode->getState();
-const StackFrameContext *SFC = LVNode->getStackFrame();
 PathSensitiveBugReport &Report = getParentTracker().getReport();
-Tracker::Result Result;
 
 // We only track expressions if we believe that they are important. Chances
 // are good that control dependencies to the tracking point are also
@@ -2106,14 +2103,31 @@
 // this point.
 // TODO: Shouldn't we track control dependencies of every bug location,
 // rather than only tracked expressions?
-if (LVState->getAnalysisManager()
+if (LVNode->getState()
+->getAnalysisManager()
 .getAnalyzerOptions()
 .ShouldTrackConditions) {
   Report.addVisitor(
   &getParentTracker(), InputNode);
-  Result.FoundSomethingToTrack = true;
+  return {/*FoundSomethingToTrack=*/true};
 }
 
+return {};
+  }
+};
+
+class DefaultExpressionHandler final : public ExpressionHandler {
+public:
+  using ExpressionHandler::ExpressionHandler;
+
+  Tracker::Result handle(const Expr *Inner, const ExplodedNode *InputNode,
+ const ExplodedNode *LVNode,
+ TrackingOptions Opts) override {
+ProgramStateRef LVState = LVNode->getState();
+const StackFrameContext *SFC = LVNode->getStackFrame();
+PathSensitiveBugReport &Report = getParentTracker().getReport();
+Tracker::Result Result;
+
 // The message send could be nil due to the receiver being nil.
 // At this point in the path, the receiver should be live since we are at
 // the message send expr. If it is nil, start tracking it.
@@ -2293,7 +2307,8 @@
 
 Tracker::Tracker(PathSensitiveBugReport &Report) : Report(Report) {
   // Default expression handlers.
-  addHighPriorityHandler();
+  addLowPriorityHandler();
+  addLowPriorityHandler();
   addLowPriorityHandler();
   // Default store handlers.
   addHighPriorityHandler();


Index: clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
===
--- clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -2088,17 +2088,14 @@
   }
 };
 
-class DefaultExpressionHandler final : public ExpressionHandler {
+class ControlDependencyHandler final : public ExpressionHandler {
 public:
   using ExpressionHandler::ExpressionHandler;
 
   Tracker::Result handle(const Expr *Inner, const ExplodedNode *InputNode,
  const ExplodedNode *LVNode,
  TrackingOptions Opts) override {
-ProgramStateRef LVState = LVNode->getState();
-const StackFrameContext *SFC = LVNode->getStackFrame();
 PathSensitiveBugReport &Report = getParentTracker().getReport();
-Tracker::Result Result;
 
 // We only track expressions if we believe that they are important. Chances
 // are good that control dependencies to the tracking point are also
@@ -2106,14 +2103,31 @@
 // this point.
 // TODO: Shouldn't we track control dependencies of every bug location,
 // rather than only tracked expressions?
-if (LVState->getAnalysisManager()
+if (LVNode->getState()
+->getAnalysisManager()
 .getAnalyzerOptions()
 .ShouldTrackConditions) {
   Report.addVisitor(
   &getParentTracker(), InputNode);
-  Result.FoundSomethingToTrack = true;
+  return {/*FoundSomethingToTrack=*/true};
 }
 
+return {};
+  }
+};
+
+class DefaultExpressionHandler final : public ExpressionHandler {
+public:
+  using ExpressionHandler::ExpressionHandler;
+
+  Tracker::Result handle(const Expr *Inner, const ExplodedNode *InputNode,
+ const ExplodedNode *LVNode,
+ TrackingOptions Opts) override {
+ProgramStateRef LVState = LVNode->getState();
+const 

[clang] 16f7a95 - [analyzer] Simplify the process of producing notes for stores

2021-06-15 Thread Valeriy Savchenko via cfe-commits

Author: Valeriy Savchenko
Date: 2021-06-15T11:37:36+03:00
New Revision: 16f7a952ec3e0f362690c6449951866100c6f76c

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

LOG: [analyzer] Simplify the process of producing notes for stores

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

Added: 


Modified: 
clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp

Removed: 




diff  --git 
a/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h 
b/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
index 8e39229ab1fd6..24cae12af24a1 100644
--- a/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
+++ b/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
@@ -330,6 +330,10 @@ class StoreHandler {
 TrackingOptions Opts) = 0;
 
   Tracker &getParentTracker() { return ParentTracker; }
+
+protected:
+  PathDiagnosticPieceRef constructNote(StoreInfo SI, BugReporterContext &BRC,
+   StringRef NodeText);
 };
 
 /// Visitor that tracks expressions and values.

diff  --git a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp 
b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
index dab1ba0a9d50f..d06a2d4933038 100644
--- a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -1214,136 +1214,146 @@ static bool isInitializationOfVar(const ExplodedNode 
*N, const VarRegion *VR) {
   return FrameSpace->getStackFrame() == LCtx->getStackFrame();
 }
 
+static bool isObjCPointer(const MemRegion *R) {
+  if (R->isBoundable())
+if (const auto *TR = dyn_cast(R))
+  return TR->getValueType()->isObjCObjectPointerType();
+
+  return false;
+}
+
+static bool isObjCPointer(const ValueDecl *D) {
+  return D->getType()->isObjCObjectPointerType();
+}
+
 /// Show diagnostics for initializing or declaring a region \p R with a bad 
value.
-static void showBRDiagnostics(const char *action, llvm::raw_svector_ostream 
&os,
-  const MemRegion *NewR, SVal V,
-  const MemRegion *OldR, const DeclStmt *DS) {
-  if (NewR->canPrintPretty()) {
-NewR->printPretty(os);
-os << " ";
-  }
-
-  if (V.getAs()) {
-bool b = false;
-if (NewR->isBoundable()) {
-  if (const auto *TR = dyn_cast(NewR)) {
-if (TR->getValueType()->isObjCObjectPointerType()) {
-  os << action << "nil";
-  b = true;
-}
-  }
-}
-if (!b)
-  os << action << "a null pointer value";
-
-  } else if (auto CVal = V.getAs()) {
-os << action << CVal->getValue();
-  } else if (OldR && OldR->canPrintPretty()) {
-os << action << "the value of ";
-OldR->printPretty(os);
-  } else if (DS) {
-if (V.isUndef()) {
-  if (isa(NewR)) {
+static void showBRDiagnostics(llvm::raw_svector_ostream &OS, StoreInfo SI) {
+  const bool HasPrefix = SI.Dest->canPrintPretty();
+
+  if (HasPrefix) {
+SI.Dest->printPretty(OS);
+OS << " ";
+  }
+
+  const char *Action = nullptr;
+
+  switch (SI.StoreKind) {
+  case StoreInfo::Initialization:
+Action = HasPrefix ? "initialized to " : "Initializing to ";
+break;
+  case StoreInfo::BlockCapture:
+Action = HasPrefix ? "captured by block as " : "Captured by block as ";
+break;
+  default:
+llvm_unreachable("Unexpected store kind");
+  }
+
+  if (SI.Value.getAs()) {
+OS << Action << (isObjCPointer(SI.Dest) ? "nil" : "a null pointer value");
+
+  } else if (auto CVal = SI.Value.getAs()) {
+OS << Action << CVal->getValue();
+
+  } else if (SI.Origin && SI.Origin->canPrintPretty()) {
+OS << Action << "the value of ";
+SI.Origin->printPretty(OS);
+
+  } else if (SI.StoreKind == StoreInfo::Initialization) {
+// We don't need to check here, all these conditions were
+// checked by StoreSiteFinder, when it figured out that it is
+// initialization.
+const auto *DS =
+cast(SI.StoreSite->getLocationAs()->getStmt());
+
+if (SI.Value.isUndef()) {
+  if (isa(SI.Dest)) {
 const auto *VD = cast(DS->getSingleDecl());
+
 if (VD->getInit()) {
-  os << (NewR->canPrintPretty() ? "initialized" : "Initializing")
+  OS << (HasPrefix ? "initialized" : "Initializing")
  << " to a garbage value";
 } else {
-  os << (NewR->canPrintPretty() ? "declared" : "Declaring")
+  OS << (HasPrefix ? "declared" : "Declaring")
  << " without an initial value";
 }
   }
 } else {
-  os << (NewR->canPrintPretty() ? "initialized" : "Initialized") << " 
here";
+   

[PATCH] D103902: [analyzer] Extract NilReceiverHandler

2021-06-15 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 rG1639dcb27984: [analyzer] Extract NilReceiverHandler 
(authored by vsavchenko).

Changed prior to commit:
  https://reviews.llvm.org/D103902?vs=35&id=352067#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103902

Files:
  clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp


Index: clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
===
--- clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -2116,24 +2116,35 @@
   }
 };
 
-class DefaultExpressionHandler final : public ExpressionHandler {
+class NilReceiverHandler final : public ExpressionHandler {
 public:
   using ExpressionHandler::ExpressionHandler;
 
   Tracker::Result handle(const Expr *Inner, const ExplodedNode *InputNode,
  const ExplodedNode *LVNode,
  TrackingOptions Opts) override {
-ProgramStateRef LVState = LVNode->getState();
-const StackFrameContext *SFC = LVNode->getStackFrame();
-PathSensitiveBugReport &Report = getParentTracker().getReport();
-Tracker::Result Result;
-
 // The message send could be nil due to the receiver being nil.
 // At this point in the path, the receiver should be live since we are at
 // the message send expr. If it is nil, start tracking it.
 if (const Expr *Receiver =
 NilReceiverBRVisitor::getNilReceiver(Inner, LVNode))
-  Result.combineWith(getParentTracker().track(Receiver, LVNode, Opts));
+  return getParentTracker().track(Receiver, LVNode, Opts);
+
+return {};
+  }
+};
+
+class DefaultExpressionHandler final : public ExpressionHandler {
+public:
+  using ExpressionHandler::ExpressionHandler;
+
+  Tracker::Result handle(const Expr *Inner, const ExplodedNode *InputNode,
+ const ExplodedNode *LVNode,
+ TrackingOptions Opts) override {
+ProgramStateRef LVState = LVNode->getState();
+const StackFrameContext *SFC = LVNode->getStackFrame();
+PathSensitiveBugReport &Report = getParentTracker().getReport();
+Tracker::Result Result;
 
 // Track the index if this is an array subscript.
 if (const auto *Arr = dyn_cast(Inner))
@@ -2308,6 +2319,7 @@
 Tracker::Tracker(PathSensitiveBugReport &Report) : Report(Report) {
   // Default expression handlers.
   addLowPriorityHandler();
+  addLowPriorityHandler();
   addLowPriorityHandler();
   addLowPriorityHandler();
   // Default store handlers.


Index: clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
===
--- clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -2116,24 +2116,35 @@
   }
 };
 
-class DefaultExpressionHandler final : public ExpressionHandler {
+class NilReceiverHandler final : public ExpressionHandler {
 public:
   using ExpressionHandler::ExpressionHandler;
 
   Tracker::Result handle(const Expr *Inner, const ExplodedNode *InputNode,
  const ExplodedNode *LVNode,
  TrackingOptions Opts) override {
-ProgramStateRef LVState = LVNode->getState();
-const StackFrameContext *SFC = LVNode->getStackFrame();
-PathSensitiveBugReport &Report = getParentTracker().getReport();
-Tracker::Result Result;
-
 // The message send could be nil due to the receiver being nil.
 // At this point in the path, the receiver should be live since we are at
 // the message send expr. If it is nil, start tracking it.
 if (const Expr *Receiver =
 NilReceiverBRVisitor::getNilReceiver(Inner, LVNode))
-  Result.combineWith(getParentTracker().track(Receiver, LVNode, Opts));
+  return getParentTracker().track(Receiver, LVNode, Opts);
+
+return {};
+  }
+};
+
+class DefaultExpressionHandler final : public ExpressionHandler {
+public:
+  using ExpressionHandler::ExpressionHandler;
+
+  Tracker::Result handle(const Expr *Inner, const ExplodedNode *InputNode,
+ const ExplodedNode *LVNode,
+ TrackingOptions Opts) override {
+ProgramStateRef LVState = LVNode->getState();
+const StackFrameContext *SFC = LVNode->getStackFrame();
+PathSensitiveBugReport &Report = getParentTracker().getReport();
+Tracker::Result Result;
 
 // Track the index if this is an array subscript.
 if (const auto *Arr = dyn_cast(Inner))
@@ -2308,6 +2319,7 @@
 Tracker::Tracker(PathSensitiveBugReport &Report) : Report(Report) {
   // Default expression handlers.
   addLowPriorityHandler();
+  addLowPriorityHandler();
   addLowPriorityHandler();
   addLowPriorityHandler();
   // Default store hand

[PATCH] D103914: [analyzer] Extract ArrayIndexHandler

2021-06-15 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 rG40cb73bd2073: [analyzer] Extract ArrayIndexHandler (authored 
by vsavchenko).

Changed prior to commit:
  https://reviews.llvm.org/D103914?vs=351113&id=352068#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103914

Files:
  clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp


Index: clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
===
--- clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -2134,6 +2134,23 @@
   }
 };
 
+class ArrayIndexHandler final : public ExpressionHandler {
+public:
+  using ExpressionHandler::ExpressionHandler;
+
+  Tracker::Result handle(const Expr *Inner, const ExplodedNode *InputNode,
+ const ExplodedNode *LVNode,
+ TrackingOptions Opts) override {
+// Track the index if this is an array subscript.
+if (const auto *Arr = dyn_cast(Inner))
+  return getParentTracker().track(
+  Arr->getIdx(), LVNode,
+  {Opts.Kind, /*EnableNullFPSuppression*/ false});
+
+return {};
+  }
+};
+
 class DefaultExpressionHandler final : public ExpressionHandler {
 public:
   using ExpressionHandler::ExpressionHandler;
@@ -2146,12 +2163,6 @@
 PathSensitiveBugReport &Report = getParentTracker().getReport();
 Tracker::Result Result;
 
-// Track the index if this is an array subscript.
-if (const auto *Arr = dyn_cast(Inner))
-  Result.combineWith(getParentTracker().track(
-  Arr->getIdx(), LVNode,
-  {Opts.Kind, /*EnableNullFPSuppression*/ false}));
-
 // See if the expression we're interested refers to a variable.
 // If so, we can track both its contents and constraints on its value.
 if (ExplodedGraph::isInterestingLValueExpr(Inner)) {
@@ -2320,6 +2331,7 @@
   // Default expression handlers.
   addLowPriorityHandler();
   addLowPriorityHandler();
+  addLowPriorityHandler();
   addLowPriorityHandler();
   addLowPriorityHandler();
   // Default store handlers.
@@ -2340,8 +2352,12 @@
   // Iterate through the handlers in the order according to their priorities.
   for (ExpressionHandlerPtr &Handler : ExpressionHandlers) {
 CombinedResult.combineWith(Handler->handle(Inner, N, LVNode, Opts));
-if (CombinedResult.WasInterrupted)
+if (CombinedResult.WasInterrupted) {
+  // There is no need to confuse our users here.
+  // We got interrupted, but our users don't need to know about it.
+  CombinedResult.WasInterrupted = false;
   break;
+}
   }
 
   return CombinedResult;


Index: clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
===
--- clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -2134,6 +2134,23 @@
   }
 };
 
+class ArrayIndexHandler final : public ExpressionHandler {
+public:
+  using ExpressionHandler::ExpressionHandler;
+
+  Tracker::Result handle(const Expr *Inner, const ExplodedNode *InputNode,
+ const ExplodedNode *LVNode,
+ TrackingOptions Opts) override {
+// Track the index if this is an array subscript.
+if (const auto *Arr = dyn_cast(Inner))
+  return getParentTracker().track(
+  Arr->getIdx(), LVNode,
+  {Opts.Kind, /*EnableNullFPSuppression*/ false});
+
+return {};
+  }
+};
+
 class DefaultExpressionHandler final : public ExpressionHandler {
 public:
   using ExpressionHandler::ExpressionHandler;
@@ -2146,12 +2163,6 @@
 PathSensitiveBugReport &Report = getParentTracker().getReport();
 Tracker::Result Result;
 
-// Track the index if this is an array subscript.
-if (const auto *Arr = dyn_cast(Inner))
-  Result.combineWith(getParentTracker().track(
-  Arr->getIdx(), LVNode,
-  {Opts.Kind, /*EnableNullFPSuppression*/ false}));
-
 // See if the expression we're interested refers to a variable.
 // If so, we can track both its contents and constraints on its value.
 if (ExplodedGraph::isInterestingLValueExpr(Inner)) {
@@ -2320,6 +2331,7 @@
   // Default expression handlers.
   addLowPriorityHandler();
   addLowPriorityHandler();
+  addLowPriorityHandler();
   addLowPriorityHandler();
   addLowPriorityHandler();
   // Default store handlers.
@@ -2340,8 +2352,12 @@
   // Iterate through the handlers in the order according to their priorities.
   for (ExpressionHandlerPtr &Handler : ExpressionHandlers) {
 CombinedResult.combineWith(Handler->handle(Inner, N, LVNode, Opts));
-if (CombinedResult.WasInterrupted)
+if (CombinedResult.WasInterrupted) {
+  // There is no need to confuse our users here.
+  // We

[PATCH] D103917: [analyzer] Extract InterestingLValueHandler

2021-06-15 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 rG2e490676ea2e: [analyzer] Extract InterestingLValueHandler 
(authored by vsavchenko).

Changed prior to commit:
  https://reviews.llvm.org/D103917?vs=350663&id=352069#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103917

Files:
  clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp


Index: clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
===
--- clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -2151,7 +2151,8 @@
   }
 };
 
-class DefaultExpressionHandler final : public ExpressionHandler {
+// TODO: extract it into more handlers
+class InterestingLValueHandler final : public ExpressionHandler {
 public:
   using ExpressionHandler::ExpressionHandler;
 
@@ -2219,13 +2220,26 @@
 // previously.
 Report.addVisitor(*DV,
 InputNode);
-
 getParentTracker().track(V, R, Opts, SFC);
-
-return Result;
   }
 }
 
+return Result;
+  }
+};
+
+class DefaultExpressionHandler final : public ExpressionHandler {
+public:
+  using ExpressionHandler::ExpressionHandler;
+
+  Tracker::Result handle(const Expr *Inner, const ExplodedNode *InputNode,
+ const ExplodedNode *LVNode,
+ TrackingOptions Opts) override {
+ProgramStateRef LVState = LVNode->getState();
+const StackFrameContext *SFC = LVNode->getStackFrame();
+PathSensitiveBugReport &Report = getParentTracker().getReport();
+Tracker::Result Result;
+
 // If the expression is not an "lvalue expression", we can still
 // track the constraints on its contents.
 SVal V = LVState->getSValAsScalarOrLoc(Inner, 
LVNode->getLocationContext());
@@ -2332,6 +2346,7 @@
   addLowPriorityHandler();
   addLowPriorityHandler();
   addLowPriorityHandler();
+  addLowPriorityHandler();
   addLowPriorityHandler();
   addLowPriorityHandler();
   // Default store handlers.


Index: clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
===
--- clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -2151,7 +2151,8 @@
   }
 };
 
-class DefaultExpressionHandler final : public ExpressionHandler {
+// TODO: extract it into more handlers
+class InterestingLValueHandler final : public ExpressionHandler {
 public:
   using ExpressionHandler::ExpressionHandler;
 
@@ -2219,13 +2220,26 @@
 // previously.
 Report.addVisitor(*DV,
 InputNode);
-
 getParentTracker().track(V, R, Opts, SFC);
-
-return Result;
   }
 }
 
+return Result;
+  }
+};
+
+class DefaultExpressionHandler final : public ExpressionHandler {
+public:
+  using ExpressionHandler::ExpressionHandler;
+
+  Tracker::Result handle(const Expr *Inner, const ExplodedNode *InputNode,
+ const ExplodedNode *LVNode,
+ TrackingOptions Opts) override {
+ProgramStateRef LVState = LVNode->getState();
+const StackFrameContext *SFC = LVNode->getStackFrame();
+PathSensitiveBugReport &Report = getParentTracker().getReport();
+Tracker::Result Result;
+
 // If the expression is not an "lvalue expression", we can still
 // track the constraints on its contents.
 SVal V = LVState->getSValAsScalarOrLoc(Inner, LVNode->getLocationContext());
@@ -2332,6 +2346,7 @@
   addLowPriorityHandler();
   addLowPriorityHandler();
   addLowPriorityHandler();
+  addLowPriorityHandler();
   addLowPriorityHandler();
   addLowPriorityHandler();
   // Default store handlers.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D103961: [analyzer] Extract InlinedFunctionCallHandler

2021-06-15 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 rG6e6a26b8f0ea: [analyzer] Extract InlinedFunctionCallHandler 
(authored by vsavchenko).

Changed prior to commit:
  https://reviews.llvm.org/D103961?vs=351115&id=352070#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103961

Files:
  clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp

Index: clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
===
--- clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -937,91 +937,6 @@
 ID.AddBoolean(EnableNullFPSuppression);
   }
 
-  /// Adds a ReturnVisitor if the given statement represents a call that was
-  /// inlined.
-  ///
-  /// This will search back through the ExplodedGraph, starting from the given
-  /// node, looking for when the given statement was processed. If it turns out
-  /// the statement is a call that was inlined, we add the visitor to the
-  /// bug report, so it can print a note later.
-  static void addVisitorIfNecessary(TrackerRef ParentTracker,
-const ExplodedNode *Node, const Stmt *S,
-PathSensitiveBugReport &BR,
-bool InEnableNullFPSuppression,
-bugreporter::TrackingKind TKind) {
-if (!CallEvent::isCallStmt(S))
-  return;
-
-// First, find when we processed the statement.
-// If we work with a 'CXXNewExpr' that is going to be purged away before
-// its call take place. We would catch that purge in the last condition
-// as a 'StmtPoint' so we have to bypass it.
-const bool BypassCXXNewExprEval = isa(S);
-
-// This is moving forward when we enter into another context.
-const StackFrameContext *CurrentSFC = Node->getStackFrame();
-
-do {
-  // If that is satisfied we found our statement as an inlined call.
-  if (Optional CEE = Node->getLocationAs())
-if (CEE->getCalleeContext()->getCallSite() == S)
-  break;
-
-  // Try to move forward to the end of the call-chain.
-  Node = Node->getFirstPred();
-  if (!Node)
-break;
-
-  const StackFrameContext *PredSFC = Node->getStackFrame();
-
-  // If that is satisfied we found our statement.
-  // FIXME: This code currently bypasses the call site for the
-  //conservatively evaluated allocator.
-  if (!BypassCXXNewExprEval)
-if (Optional SP = Node->getLocationAs())
-  // See if we do not enter into another context.
-  if (SP->getStmt() == S && CurrentSFC == PredSFC)
-break;
-
-  CurrentSFC = PredSFC;
-} while (Node->getStackFrame() == CurrentSFC);
-
-// Next, step over any post-statement checks.
-while (Node && Node->getLocation().getAs())
-  Node = Node->getFirstPred();
-if (!Node)
-  return;
-
-// Finally, see if we inlined the call.
-Optional CEE = Node->getLocationAs();
-if (!CEE)
-  return;
-
-const StackFrameContext *CalleeContext = CEE->getCalleeContext();
-if (CalleeContext->getCallSite() != S)
-  return;
-
-// Check the return value.
-ProgramStateRef State = Node->getState();
-SVal RetVal = Node->getSVal(S);
-
-// Handle cases where a reference is returned and then immediately used.
-if (cast(S)->isGLValue())
-  if (Optional LValue = RetVal.getAs())
-RetVal = State->getSVal(*LValue);
-
-// See if the return value is NULL. If so, suppress the report.
-AnalyzerOptions &Options = State->getAnalysisManager().options;
-
-bool EnableNullFPSuppression = false;
-if (InEnableNullFPSuppression && Options.ShouldSuppressNullReturnPaths)
-  if (Optional RetLoc = RetVal.getAs())
-EnableNullFPSuppression = State->isNull(*RetLoc).isConstrainedTrue();
-
-BR.addVisitor(ParentTracker, CalleeContext,
- EnableNullFPSuppression, Options, TKind);
-  }
-
   PathDiagnosticPieceRef visitNodeInitial(const ExplodedNode *N,
   BugReporterContext &BRC,
   PathSensitiveBugReport &BR) {
@@ -2228,6 +2143,96 @@
   }
 };
 
+/// Adds a ReturnVisitor if the given statement represents a call that was
+/// inlined.
+///
+/// This will search back through the ExplodedGraph, starting from the given
+/// node, looking for when the given statement was processed. If it turns out
+/// the statement is a call that was inlined, we add the visitor to the
+/// bug report, so it can print a note later.
+class InlinedFunctionCallHandler final : public ExpressionHandler {
+  using ExpressionHandler::ExpressionHandler;
+
+  Tracker::Result handle(const Expr *E, const

[PATCH] D104046: [analyzer] Simplify the process of producing notes for stores

2021-06-15 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 rG16f7a952ec3e: [analyzer] Simplify the process of producing 
notes for stores (authored by vsavchenko).

Changed prior to commit:
  https://reviews.llvm.org/D104046?vs=351515&id=352071#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104046

Files:
  clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
  clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp

Index: clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
===
--- clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -1214,136 +1214,146 @@
   return FrameSpace->getStackFrame() == LCtx->getStackFrame();
 }
 
+static bool isObjCPointer(const MemRegion *R) {
+  if (R->isBoundable())
+if (const auto *TR = dyn_cast(R))
+  return TR->getValueType()->isObjCObjectPointerType();
+
+  return false;
+}
+
+static bool isObjCPointer(const ValueDecl *D) {
+  return D->getType()->isObjCObjectPointerType();
+}
+
 /// Show diagnostics for initializing or declaring a region \p R with a bad value.
-static void showBRDiagnostics(const char *action, llvm::raw_svector_ostream &os,
-  const MemRegion *NewR, SVal V,
-  const MemRegion *OldR, const DeclStmt *DS) {
-  if (NewR->canPrintPretty()) {
-NewR->printPretty(os);
-os << " ";
-  }
-
-  if (V.getAs()) {
-bool b = false;
-if (NewR->isBoundable()) {
-  if (const auto *TR = dyn_cast(NewR)) {
-if (TR->getValueType()->isObjCObjectPointerType()) {
-  os << action << "nil";
-  b = true;
-}
-  }
-}
-if (!b)
-  os << action << "a null pointer value";
-
-  } else if (auto CVal = V.getAs()) {
-os << action << CVal->getValue();
-  } else if (OldR && OldR->canPrintPretty()) {
-os << action << "the value of ";
-OldR->printPretty(os);
-  } else if (DS) {
-if (V.isUndef()) {
-  if (isa(NewR)) {
+static void showBRDiagnostics(llvm::raw_svector_ostream &OS, StoreInfo SI) {
+  const bool HasPrefix = SI.Dest->canPrintPretty();
+
+  if (HasPrefix) {
+SI.Dest->printPretty(OS);
+OS << " ";
+  }
+
+  const char *Action = nullptr;
+
+  switch (SI.StoreKind) {
+  case StoreInfo::Initialization:
+Action = HasPrefix ? "initialized to " : "Initializing to ";
+break;
+  case StoreInfo::BlockCapture:
+Action = HasPrefix ? "captured by block as " : "Captured by block as ";
+break;
+  default:
+llvm_unreachable("Unexpected store kind");
+  }
+
+  if (SI.Value.getAs()) {
+OS << Action << (isObjCPointer(SI.Dest) ? "nil" : "a null pointer value");
+
+  } else if (auto CVal = SI.Value.getAs()) {
+OS << Action << CVal->getValue();
+
+  } else if (SI.Origin && SI.Origin->canPrintPretty()) {
+OS << Action << "the value of ";
+SI.Origin->printPretty(OS);
+
+  } else if (SI.StoreKind == StoreInfo::Initialization) {
+// We don't need to check here, all these conditions were
+// checked by StoreSiteFinder, when it figured out that it is
+// initialization.
+const auto *DS =
+cast(SI.StoreSite->getLocationAs()->getStmt());
+
+if (SI.Value.isUndef()) {
+  if (isa(SI.Dest)) {
 const auto *VD = cast(DS->getSingleDecl());
+
 if (VD->getInit()) {
-  os << (NewR->canPrintPretty() ? "initialized" : "Initializing")
+  OS << (HasPrefix ? "initialized" : "Initializing")
  << " to a garbage value";
 } else {
-  os << (NewR->canPrintPretty() ? "declared" : "Declaring")
+  OS << (HasPrefix ? "declared" : "Declaring")
  << " without an initial value";
 }
   }
 } else {
-  os << (NewR->canPrintPretty() ? "initialized" : "Initialized") << " here";
+  OS << (HasPrefix ? "initialized" : "Initialized") << " here";
 }
   }
 }
 
 /// Display diagnostics for passing bad region as a parameter.
-static void showBRParamDiagnostics(llvm::raw_svector_ostream &os,
-   const VarRegion *VR, SVal V,
-   const MemRegion *ValueR) {
+static void showBRParamDiagnostics(llvm::raw_svector_ostream &OS,
+   StoreInfo SI) {
+  const auto *VR = cast(SI.Dest);
   const auto *Param = cast(VR->getDecl());
 
-  os << "Passing ";
+  OS << "Passing ";
+
+  if (SI.Value.getAs()) {
+OS << (isObjCPointer(Param) ? "nil object reference"
+: "null pointer value");
+
+  } else if (SI.Value.isUndef()) {
+OS << "uninitialized value";
+
+  } else if (auto CI = SI.Value.getAs()) {
+OS << "the value " << CI->getValue();
+
+  } else if (SI.Origin && SI.Origin->canPrintPretty(

[clang] eadd54f - [analyzer] Decouple NoteTag from its Factory

2021-06-15 Thread Valeriy Savchenko via cfe-commits

Author: Valeriy Savchenko
Date: 2021-06-15T11:58:13+03:00
New Revision: eadd54f2741f9dc7307512382a7c8fb49aa840d0

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

LOG: [analyzer] Decouple NoteTag from its Factory

This allows us to create other types of tags that carry useful
bits of information alongside.

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

Added: 


Modified: 
clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
clang/lib/StaticAnalyzer/Core/CoreEngine.cpp

Removed: 




diff  --git a/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h 
b/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
index 0b12ff7075780..99cd24a52f2df 100644
--- a/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
+++ b/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
@@ -725,14 +725,43 @@ class BugReporterContext {
   }
 };
 
+/// The tag that carries some information with it.
+///
+/// It can be valuable to produce tags with some bits of information and later
+/// reuse them for a better diagnostic.
+///
+/// Please make sure that derived class' constuctor is private and that the 
user
+/// can only create objects using DataTag::Factory.  This also means that
+/// DataTag::Factory should be friend for every derived class.
+class DataTag : public ProgramPointTag {
+public:
+  StringRef getTagDescription() const override { return "Data Tag"; }
+
+  // Manage memory for DataTag objects.
+  class Factory {
+std::vector> Tags;
+
+  public:
+template 
+const DataTagType *make(Args &&... ConstructorArgs) {
+  // We cannot use std::make_unique because we cannot access the private
+  // constructor from inside it.
+  Tags.emplace_back(
+  new DataTagType(std::forward(ConstructorArgs)...));
+  return static_cast(Tags.back().get());
+}
+  };
+
+protected:
+  DataTag(void *TagKind) : ProgramPointTag(TagKind) {}
+};
 
 /// The tag upon which the TagVisitor reacts. Add these in order to display
 /// additional PathDiagnosticEventPieces along the path.
-class NoteTag : public ProgramPointTag {
+class NoteTag : public DataTag {
 public:
-  using Callback =
-  std::function;
+  using Callback = std::function;
 
 private:
   static int Kind;
@@ -741,7 +770,7 @@ class NoteTag : public ProgramPointTag {
   const bool IsPrunable;
 
   NoteTag(Callback &&Cb, bool IsPrunable)
-  : ProgramPointTag(&Kind), Cb(std::move(Cb)), IsPrunable(IsPrunable) {}
+  : DataTag(&Kind), Cb(std::move(Cb)), IsPrunable(IsPrunable) {}
 
 public:
   static bool classof(const ProgramPointTag *T) {
@@ -766,20 +795,7 @@ class NoteTag : public ProgramPointTag {
 
   bool isPrunable() const { return IsPrunable; }
 
-  // Manage memory for NoteTag objects.
-  class Factory {
-std::vector> Tags;
-
-  public:
-const NoteTag *makeNoteTag(Callback &&Cb, bool IsPrunable = false) {
-  // We cannot use std::make_unique because we cannot access the private
-  // constructor from inside it.
-  std::unique_ptr T(new NoteTag(std::move(Cb), IsPrunable));
-  Tags.push_back(std::move(T));
-  return Tags.back().get();
-}
-  };
-
+  friend class Factory;
   friend class TagVisitor;
 };
 

diff  --git 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
index 54572bd81f20f..a383012dc3516 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
@@ -255,7 +255,7 @@ class CheckerContext {
   ///to omit the note from the report if it would make the displayed
   ///bug path significantly shorter.
   const NoteTag *getNoteTag(NoteTag::Callback &&Cb, bool IsPrunable = false) {
-return Eng.getNoteTags().makeNoteTag(std::move(Cb), IsPrunable);
+return Eng.getDataTags().make(std::move(Cb), IsPrunable);
   }
 
   /// A shorthand version of getNoteTag that doesn't require you to accept

diff  --git 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
index 2aca2c99ef4fd..9898b9b42f4b2 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
@@ -96,9 +96,10 @@ class CoreEngine {
   /// (This data is owned by AnalysisConsumer.)
   FunctionSummariesTy *FunctionSummaries;
 
-  /// Add path note

[PATCH] D104135: [analyzer] Decouple NoteTag from its Factory

2021-06-15 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 rGeadd54f2741f: [analyzer] Decouple NoteTag from its Factory 
(authored by vsavchenko).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104135

Files:
  clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
  clang/lib/StaticAnalyzer/Core/CoreEngine.cpp

Index: clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
===
--- clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
+++ clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
@@ -219,13 +219,14 @@
   // and we're taking the path that skips virtual base constructors.
   if (L.getSrc()->getTerminator().isVirtualBaseBranch() &&
   L.getDst() == *L.getSrc()->succ_begin()) {
-ProgramPoint P = L.withTag(getNoteTags().makeNoteTag(
+ProgramPoint P = L.withTag(getDataTags().make(
 [](BugReporterContext &, PathSensitiveBugReport &) -> std::string {
   // TODO: Just call out the name of the most derived class
   // when we know it.
   return "Virtual base initialization skipped because "
  "it has already been handled by the most derived class";
-}, /*IsPrunable=*/true));
+},
+/*IsPrunable=*/true));
 // Perform the transition.
 ExplodedNodeSet Dst;
 NodeBuilder Bldr(Pred, Dst, BuilderCtx);
Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
@@ -428,8 +428,7 @@
   SymbolManager &getSymbolManager() { return SymMgr; }
   MemRegionManager &getRegionManager() { return MRMgr; }
 
-  NoteTag::Factory &getNoteTags() { return Engine.getNoteTags(); }
-
+  DataTag::Factory &getDataTags() { return Engine.getDataTags(); }
 
   // Functions for external checking of whether we have unfinished work
   bool wasBlocksExhausted() const { return Engine.wasBlocksExhausted(); }
Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
@@ -96,9 +96,10 @@
   /// (This data is owned by AnalysisConsumer.)
   FunctionSummariesTy *FunctionSummaries;
 
-  /// Add path note tags along the path when we see that something interesting
-  /// is happening. This field is the allocator for such tags.
-  NoteTag::Factory NoteTags;
+  /// Add path tags with some useful data along the path when we see that
+  /// something interesting is happening. This field is the allocator for such
+  /// tags.
+  DataTag::Factory DataTags;
 
   void generateNode(const ProgramPoint &Loc,
 ProgramStateRef State,
@@ -200,7 +201,7 @@
   /// Enqueue a single node created as a result of statement processing.
   void enqueueStmtNode(ExplodedNode *N, const CFGBlock *Block, unsigned Idx);
 
-  NoteTag::Factory &getNoteTags() { return NoteTags; }
+  DataTag::Factory &getDataTags() { return DataTags; }
 };
 
 // TODO: Turn into a class.
Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
@@ -255,7 +255,7 @@
   ///to omit the note from the report if it would make the displayed
   ///bug path significantly shorter.
   const NoteTag *getNoteTag(NoteTag::Callback &&Cb, bool IsPrunable = false) {
-return Eng.getNoteTags().makeNoteTag(std::move(Cb), IsPrunable);
+return Eng.getDataTags().make(std::move(Cb), IsPrunable);
   }
 
   /// A shorthand version of getNoteTag that doesn't require you to accept
Index: clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
===
--- clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
+++ clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
@@ -725,14 +725,43 @@
   }
 };
 
+/// The tag that carries some information with it.
+///
+/// It can be valuable to produce tags with some bits of information and later
+/// reuse them for a better diagnostic.
+///
+/// Please make sure that derived class' constuctor is private and that the user
+/// can only create objects using DataTag::Factory.

[PATCH] D104135: [analyzer] Decouple NoteTag from its Factory

2021-06-15 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko added inline comments.



Comment at: 
clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h:777
   static bool classof(const ProgramPointTag *T) {
 return T->getTagKind() == &Kind;
   }

NoQ wrote:
> vsavchenko wrote:
> > NoQ wrote:
> > > NoQ wrote:
> > > > It sounds like `NoteTag` `isn't` despite inheriting from it.
> > > Wait nvm, `DataTag` doesn't provide a `classof` at all. This means we 
> > > can't write `isa` at all, right?
> > Yes, it's purely abstract.  `ProgramPointTag` also doesn't have `classof`
> Something being purely abstract isn't a problem on its own; there are a lot 
> of abstract classes that implement `classof()`, such as `Expr`. It's more of 
> an artifact of the current implementation strategy.
> 
> Ok np though, this doesn't seem to be a real problem.
That's true.  And considering that we want different checkers to implement this 
on their own, we probably don't want to have one central enum listing all 
possible subtypes so that we can `isa` non-leaf types.
But unlike `Expr`, `DataTag` doesn't provide any information, so it's useless 
for people to check if something is a data tag or cast to it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104135

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


[PATCH] D68891: Remove unnecessary triple from test

2021-06-15 Thread Yuki Okushi via Phabricator via cfe-commits
JohnTitor added a subscriber: rnk.
JohnTitor added a comment.

ping @rnk Seems you added this.


Repository:
  rC Clang

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

https://reviews.llvm.org/D68891

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


[PATCH] D101868: [clang-format] Adds a formatter for aligning arrays of structs

2021-06-15 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

The test is still intermittently failing on bots.
Is there some non-determinism in the change?
It may be a good idea to revert this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101868

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


[PATCH] D104136: [analyzer] Add better tracking for RetainCountChecker leak warnings

2021-06-15 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko updated this revision to Diff 352075.
vsavchenko added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104136

Files:
  clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.h
  
clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
  clang/test/Analysis/Inputs/expected-plists/retain-release.m.objc.plist
  clang/test/Analysis/Inputs/expected-plists/retain-release.m.objcpp.plist
  clang/test/Analysis/osobject-retain-release.cpp

Index: clang/test/Analysis/osobject-retain-release.cpp
===
--- clang/test/Analysis/osobject-retain-release.cpp
+++ clang/test/Analysis/osobject-retain-release.cpp
@@ -536,6 +536,7 @@
 
 void check_dynamic_cast_alias() {
   OSObject *originalPtr = OSObject::generateObject(1);   // expected-note {{Call to method 'OSObject::generateObject' returns an OSObject}}
+ // expected-note@-1 {{'originalPtr' initialized here}}
   OSArray *newPtr = OSDynamicCast(OSArray, originalPtr); // expected-note {{'newPtr' initialized to the value of 'originalPtr'}}
   if (newPtr) {  // expected-note {{'newPtr' is non-null}}
  // expected-note@-1 {{Taking true branch}}
@@ -548,6 +549,7 @@
 
 void check_dynamic_cast_alias_cond() {
   OSObject *originalPtr = OSObject::generateObject(1); // expected-note {{Call to method 'OSObject::generateObject' returns an OSObject}}
+   // expected-note@-1 {{'originalPtr' initialized here}}
   OSArray *newPtr = 0;
   if ((newPtr = OSDynamicCast(OSArray, originalPtr))) { // expected-note {{The value of 'originalPtr' is assigned to 'newPtr'}}
 // expected-note@-1 {{'newPtr' is non-null}}
@@ -561,7 +563,8 @@
 
 void check_dynamic_cast_alias_intermediate() {
   OSObject *originalPtr = OSObject::generateObject(1); // expected-note {{Call to method 'OSObject::generateObject' returns an OSObject of type 'OSObject' with a +1 retain count}}
-  OSObject *intermediate = originalPtr;// TODO: add note here as well
+   // expected-note@-1 {{'originalPtr' initialized here}}
+  OSObject *intermediate = originalPtr;// expected-note {{'intermediate' initialized to the value of 'originalPtr'}}
   OSArray *newPtr = 0;
   if ((newPtr = OSDynamicCast(OSArray, intermediate))) { // expected-note {{The value of 'intermediate' is assigned to 'newPtr'}}
  // expected-note@-1 {{'newPtr' is non-null}}
@@ -575,7 +578,8 @@
 
 void check_dynamic_cast_alias_intermediate_2() {
   OSObject *originalPtr = OSObject::generateObject(1); // expected-note {{Call to method 'OSObject::generateObject' returns an OSObject of type 'OSObject' with a +1 retain count}}
-  OSObject *intermediate = originalPtr;// TODO: add note here as well
+   // expected-note@-1 {{'originalPtr' initialized here}}
+  OSObject *intermediate = originalPtr;// expected-note {{'intermediate' initialized to the value of 'originalPtr'}}
   OSArray *newPtr = 0;
   if ((newPtr = OSDynamicCast(OSArray, intermediate))) { // expected-note {{Value assigned to 'newPtr'}}
  // expected-note@-1 {{'newPtr' is non-null}}
Index: clang/test/Analysis/Inputs/expected-plists/retain-release.m.objcpp.plist
===
--- clang/test/Analysis/Inputs/expected-plists/retain-release.m.objcpp.plist
+++ clang/test/Analysis/Inputs/expected-plists/retain-release.m.objcpp.plist
@@ -25282,6 +25282,35 @@
  message
  Call to function 'CFCreateSomething' returns a Core Foundation object of type 'CFTypeRef' with a +1 retain count
 
+
+ kindevent
+ location
+ 
+  line2285
+  col3
+  file0
+ 
+ ranges
+ 
+   
+
+ line2285
+ col3
+ file0
+
+
+ line2285
+ col15
+ file0
+
+   
+ 
+ depth0
+ extended_message
+ 'obj' initialized here
+ message
+ 'obj' initialized here
+
 
  kindcontrol
  edges
@@ -25569,6 +25598,35 @@
  message
  Call to function 'CFArrayCreateMutable' returns a Core Foundation object of type 'CFMutableArrayRef' with a +1 retain count
 
+
+ kindevent
+ location
+ 
+  line2305
+  col3
+  file0
+ 
+ ranges
+ 
+   
+
+ line2305
+ col3

[PATCH] D104136: [analyzer] Add better tracking for RetainCountChecker leak warnings

2021-06-15 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko added inline comments.



Comment at: 
clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp:953-957
+  // Let's traverse...
+  for (const ExplodedNode *N = ExprNode;
+   // ...all the nodes corresponding to the given expression...
+   N != nullptr && N->getStmtForDiagnostics() == E;
+   N = N->getFirstPred()) {

NoQ wrote:
> I guess this part should ultimately be written in one place, eg. 
> `ExplodedNode::findTag()` or something like that.
> 
> I'd also really like to explore the possibility to further limit the variety 
> of nodes traversed here. What nodes are typically traversed here? Is it 
> checker-tagged nodes or is it purge dead symbol nodes or something else?
Yes, `ExplodedNode::findTag()` sounds like a great idea!

I mean it is hard to tell without calculating statistics right here and running 
it on a bunch of projects.  However, it is always possible to write the code 
that will have it the other way.  My take on it is that it is probably a mix of 
things.

I'd also prefer to traverse less, do you have any specific ideas here?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104136

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


[PATCH] D104118: [OpenCL] Use DW_LANG_OpenCL language tag for OpenCL C

2021-06-15 Thread Stuart Brady via Phabricator via cfe-commits
stuart added inline comments.



Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:579
 LangTag = llvm::dwarf::DW_LANG_ObjC;
+  } else if (LO.OpenCL && CGM.getCodeGenOpts().DwarfVersion >= 5) {
+LangTag = llvm::dwarf::DW_LANG_OpenCL;

shchenz wrote:
> I think for non-strict DWARF mode, we still can generate `DW_LANG_OpenCL` for 
> the DWARF version lower than 5? Seems we also need to fix above 
> `DW_LANG_C_plus_plus_14` and `DW_LANG_C_plus_plus_11`
If we have a `-gstrict-dwarf` option for this, then it would seem better to add 
`DW_LANG_C_plus_plus_17` and `DW_LANG_C_plus_plus_20` definitions and generate 
those for the `!CGM.getCodeGenOpts().DebugStrictDwarf` case. //C++ for OpenCL// 
would then use one of the more recent language tag values for the time being 
(without any special logic).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104118

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


[PATCH] D104285: [analyzer] Retrieve value by direct index from list initialization of constant array declaration.

2021-06-15 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov created this revision.
ASDenysPetrov added reviewers: NoQ, xazax.hun, r.stahl.
ASDenysPetrov added a project: clang.
Herald added subscribers: manas, steakhal, martong, dkrupp, donat.nagy, 
Szelethus, arphaman, mikhail.ramalho, a.sidorin, rnkovacs, szepet, 
baloghadamsoftware.
ASDenysPetrov requested review of this revision.
Herald added a subscriber: cfe-commits.

We can use direct index to retrieve a value from multi-dimensional array 
relying on a fact that static constant array is a solid block of memory. 
Iterate through a list initialization using a raw index to get the value.

Example:

  const int arr[2][2] = {{1}, {3, 4}};
  const int *ptr = (int *)arr;
  ptr[0]; // 1
  ptr[1]; // 0
  ptr[2]; // 3
  ptr[3]; // 4

Fixes: https://bugs.llvm.org/show_bug.cgi?id=50604


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104285

Files:
  clang/include/clang/AST/Expr.h
  clang/include/clang/AST/Type.h
  clang/lib/AST/Expr.cpp
  clang/lib/AST/Type.cpp
  clang/lib/StaticAnalyzer/Core/RegionStore.cpp
  clang/test/Analysis/initialization.cpp

Index: clang/test/Analysis/initialization.cpp
===
--- clang/test/Analysis/initialization.cpp
+++ clang/test/Analysis/initialization.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -std=c++14 -triple i386-apple-darwin10 -analyze -analyzer-checker=core.builtin,debug.ExprInspection -verify %s
+// RUN: %clang_cc1 -std=c++14 -triple i386-apple-darwin10 -analyze -analyzer-checker=core.uninitialized.Assign,core.builtin,debug.ExprInspection -verify %s
 
 void clang_analyzer_eval(int);
 
@@ -18,3 +18,108 @@
   // FIXME: Should recognize that it is 0.
   clang_analyzer_eval(arr[i][0]); // expected-warning{{UNKNOWN}}
 }
+
+void direct_index1() {
+  int const arr[2][2][3] = {};
+  int const *ptr = (int const *)arr;
+  clang_analyzer_eval(ptr[0] == 0);  // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[1] == 0);  // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[2] == 0);  // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[3] == 0);  // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[4] == 0);  // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[5] == 0);  // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[6] == 0);  // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[7] == 0);  // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[8] == 0);  // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[9] == 0);  // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[10] == 0); // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[11] == 0); // expected-warning{{TRUE}}
+}
+
+void direct_index2() {
+  int const arr[2][2][3] = {{{1, 2, 3}, {4, 5, 6}}, {{7, 8, 9}, {10, 11, 12}}};
+  int const *ptr = arr[0][0];
+  clang_analyzer_eval(ptr[0] == 1);   // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[1] == 2);   // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[2] == 3);   // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[3] == 4);   // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[4] == 5);   // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[5] == 6);   // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[6] == 7);   // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[7] == 8);   // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[8] == 9);   // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[9] == 10);  // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[10] == 11); // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[11] == 12); // expected-warning{{TRUE}}
+}
+
+void direct_index3() {
+  int const arr[2][2][3] = {{{}, {}}, {{}, {}}};
+  int const *ptr = &(arr[0][0][0]);
+  clang_analyzer_eval(ptr[0] == 0);  // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[1] == 0);  // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[2] == 0);  // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[3] == 0);  // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[4] == 0);  // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[5] == 0);  // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[6] == 0);  // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[7] == 0);  // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[8] == 0);  // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[9] == 0);  // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[10] == 0); // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[11] == 0); // expected-warning{{TRUE}}
+}
+
+void direct_index4() {
+  int const arr[2][2][3] = {{{1, 2}, {}}, {{7, 8}, {10, 11, 12}}};
+  int const *ptr = (int const *)arr[0];
+  clang_analyzer_eval(ptr[0] == 1);   // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[1] == 2);   // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[2] == 0);   // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[3] == 0);   // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[4] == 0);   // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[

[PATCH] D101868: [clang-format] Adds a formatter for aligning arrays of structs

2021-06-15 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

Do we actually need this lit test? Mostly we only add lit tests when we add a 
new command line argument, I feel your are just testing what we also test in 
the unittests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101868

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


[PATCH] D104222: [clang-format] [PR50702] Lamdba processing does not respect AfterClass and AfterNamespace

2021-06-15 Thread Francois JEAN via Phabricator via cfe-commits
Wawha added a comment.

In D104222#2817147 , @MyDeveloperDay 
wrote:

> @Wawha do you have a project that perhaps uses this work your did? I would 
> like to ensure I didn't break anything

@MyDeveloperDay Good idea!
I just test on my code, and I see 2 types of regressions due to that patch.
This code:

auto select = [this]() -> const Library::Object*
{
return MyAssignment::SelectFromList(this);
};

Become:

auto select = [this]() -> const Library::Object* {
return MyAssignment::SelectFromList(this);
};

And this code,

auto Items()
{
return iter::imap(
[this](const std::unique_ptr& iItem) -> T&
{
return *GetItem(*iItem)->Item;
},
m_Root->Items());
}

Become:

auto Items()
{
return iter::imap(
[this](const std::unique_ptr& iItem) -> T& {
return *GetItem(*iItem)->Item;
},
m_Root->Items());
}

I'm surprise, because the both cases, should be present inside the UnitTest.


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

https://reviews.llvm.org/D104222

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


[PATCH] D99005: [clang] Implement P2266 Simpler implicit move

2021-06-15 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

In D99005#2818606 , @sberg wrote:

> (In a build prior to 
> https://reviews.llvm.org/rGc60dd3b2626a4d9eefd9f82f9a406b0d28d3fd72 "Revert 
> '[clang] NRVO: Improvements and handling of more cases.'") I see the 
> following (reduced from 
> https://git.libreoffice.org/core/+/649313625b94e6b879848fc19b607b74375100bf/o3tl/qa/compile-temporary.cxx)
>  started to fail under `-std=c++2b` with this change (and continues to 
> compile fine with `-std=c++20`):
> It is not clear to me whether that is an intended change in behavior 
> according to 
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2266r1.html "Simpler 
> implicit move", or whether it is a bug in this implementation.

Yeah that one is intentional, under P2266  as 
far as implicit move is concerned, that code behaves similarly to this code 
under C++20 (which is diagnosed for the same reason):

  template  constexpr T& temporary(T&& x) { return 
static_cast(x); }

If you want this semantics with P2266 , you 
could write:

  template  constexpr T& temporary(T&& x) { return 
static_cast(x); }

And the above also works on C++20.

Thank you for reporting this, it's the kind of feedback we needed about real 
world usage of code that would break under these new rules.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99005

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


[clang] 69cfa17 - Clearly specify that these are partially implemented features

2021-06-15 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2021-06-15T07:28:29-04:00
New Revision: 69cfa178b77d91205cf8cf45fa00e28b1730d0a1

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

LOG: Clearly specify that these are partially implemented features

Added: 


Modified: 
clang/www/c_status.html

Removed: 




diff  --git a/clang/www/c_status.html b/clang/www/c_status.html
index 73321a930620..595419f8790c 100644
--- a/clang/www/c_status.html
+++ b/clang/www/c_status.html
@@ -456,7 +456,7 @@ C2x implementation status
 
   What we think we reserve
   http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2572.pdf";>N2572
-  Yes
+  Partial
 
 
   Decimal floating-point triples
@@ -476,7 +476,7 @@ C2x implementation status
 
   Compatibility of Pointers to Arrays with Qualifiers
   http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2607.pdf";>N2607
-  Yes
+  Partial
 
 
 



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


[PATCH] D104118: [OpenCL] Use DW_LANG_OpenCL language tag for OpenCL C

2021-06-15 Thread ChenZheng via Phabricator via cfe-commits
shchenz added inline comments.



Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:579
 LangTag = llvm::dwarf::DW_LANG_ObjC;
+  } else if (LO.OpenCL && CGM.getCodeGenOpts().DwarfVersion >= 5) {
+LangTag = llvm::dwarf::DW_LANG_OpenCL;

stuart wrote:
> shchenz wrote:
> > I think for non-strict DWARF mode, we still can generate `DW_LANG_OpenCL` 
> > for the DWARF version lower than 5? Seems we also need to fix above 
> > `DW_LANG_C_plus_plus_14` and `DW_LANG_C_plus_plus_11`
> If we have a `-gstrict-dwarf` option for this, then it would seem better to 
> add `DW_LANG_C_plus_plus_17` and `DW_LANG_C_plus_plus_20` definitions and 
> generate those for the `!CGM.getCodeGenOpts().DebugStrictDwarf` case. //C++ 
> for OpenCL// would then use one of the more recent language tag values for 
> the time being (without any special logic).
I added a patch https://reviews.llvm.org/D104291 for `DW_LANG_C_plus_plus_14` 
and `DW_LANG_C_plus_plus_11`.
I think `DW_LANG_OpenCL` should be in the same situation?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104118

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


[PATCH] D104291: [Debug-Info] strict dwarf for DW_LANG_C_plus_plus_14

2021-06-15 Thread ChenZheng via Phabricator via cfe-commits
shchenz created this revision.
shchenz added reviewers: dblaikie, aprantl, Esme, stuart, PowerPC.
shchenz added a project: debug-info.
shchenz requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This partially reverts the change in https://reviews.llvm.org/D99250.
Now we also generate `DW_LANG_C_plus_plus_14` or `DW_LANG_C_plus_plus_11` for 
non-strict mode.

We can provide more accurate language info for consumers which does not require 
strict DWARF.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104291

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenCXX/debug-info-programming-language.cpp


Index: clang/test/CodeGenCXX/debug-info-programming-language.cpp
===
--- clang/test/CodeGenCXX/debug-info-programming-language.cpp
+++ clang/test/CodeGenCXX/debug-info-programming-language.cpp
@@ -1,13 +1,18 @@
-// RUN: %clang_cc1 -dwarf-version=5  -emit-llvm -triple %itanium_abi_triple %s 
-o - \
+// RUN: %clang_cc1 -dwarf-version=5 -emit-llvm -triple %itanium_abi_triple %s 
-o - \
 // RUN:   -x c++ -std=c++14 -O0 -disable-llvm-passes -debug-info-kind=limited \
-// RUN: | FileCheck --check-prefix=CHECK-DWARF5 %s
-// RUN: %clang_cc1 -dwarf-version=3  -emit-llvm -triple %itanium_abi_triple %s 
-o - \
+// RUN:   | FileCheck --check-prefix=CHECK-CPP14 %s
+// RUN: %clang_cc1 -dwarf-version=3 -emit-llvm -triple %itanium_abi_triple %s 
-o - \
 // RUN:   -x c++ -std=c++14 -O0 -disable-llvm-passes -debug-info-kind=limited \
-// RUN: | FileCheck --check-prefix=CHECK-DWARF3 %s
+// RUN:   | FileCheck --check-prefix=CHECK-CPP14 %s
+// RUN: %clang_cc1 -dwarf-version=3 -gstrict-dwarf -emit-llvm -triple 
%itanium_abi_triple %s -o - \
+// RUN:   -x c++ -std=c++14 -O0 -disable-llvm-passes -debug-info-kind=limited 
| FileCheck %s
+// RUN: %clang_cc1 -dwarf-version=5 -gstrict-dwarf -emit-llvm -triple 
%itanium_abi_triple %s -o - \
+// RUN:   -x c++ -std=c++14 -O0 -disable-llvm-passes -debug-info-kind=limited \
+// RUN:   | FileCheck --check-prefix=CHECK-CPP14 %s
 
 int main() {
   return 0;
 }
 
-// CHECK-DWARF5: distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14,
-// CHECK-DWARF3: distinct !DICompileUnit(language: DW_LANG_C_plus_plus,
+// CHECK-CPP14: distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14,
+// CHECK: distinct !DICompileUnit(language: DW_LANG_C_plus_plus,
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -568,9 +568,11 @@
   if (LO.CPlusPlus) {
 if (LO.ObjC)
   LangTag = llvm::dwarf::DW_LANG_ObjC_plus_plus;
-else if (LO.CPlusPlus14 && CGM.getCodeGenOpts().DwarfVersion >= 5)
+else if (LO.CPlusPlus14 && (!CGM.getCodeGenOpts().DebugStrictDwarf ||
+CGM.getCodeGenOpts().DwarfVersion >= 5))
   LangTag = llvm::dwarf::DW_LANG_C_plus_plus_14;
-else if (LO.CPlusPlus11 && CGM.getCodeGenOpts().DwarfVersion >= 5)
+else if (LO.CPlusPlus11 && (!CGM.getCodeGenOpts().DebugStrictDwarf ||
+CGM.getCodeGenOpts().DwarfVersion >= 5))
   LangTag = llvm::dwarf::DW_LANG_C_plus_plus_11;
 else
   LangTag = llvm::dwarf::DW_LANG_C_plus_plus;


Index: clang/test/CodeGenCXX/debug-info-programming-language.cpp
===
--- clang/test/CodeGenCXX/debug-info-programming-language.cpp
+++ clang/test/CodeGenCXX/debug-info-programming-language.cpp
@@ -1,13 +1,18 @@
-// RUN: %clang_cc1 -dwarf-version=5  -emit-llvm -triple %itanium_abi_triple %s -o - \
+// RUN: %clang_cc1 -dwarf-version=5 -emit-llvm -triple %itanium_abi_triple %s -o - \
 // RUN:   -x c++ -std=c++14 -O0 -disable-llvm-passes -debug-info-kind=limited \
-// RUN: | FileCheck --check-prefix=CHECK-DWARF5 %s
-// RUN: %clang_cc1 -dwarf-version=3  -emit-llvm -triple %itanium_abi_triple %s -o - \
+// RUN:   | FileCheck --check-prefix=CHECK-CPP14 %s
+// RUN: %clang_cc1 -dwarf-version=3 -emit-llvm -triple %itanium_abi_triple %s -o - \
 // RUN:   -x c++ -std=c++14 -O0 -disable-llvm-passes -debug-info-kind=limited \
-// RUN: | FileCheck --check-prefix=CHECK-DWARF3 %s
+// RUN:   | FileCheck --check-prefix=CHECK-CPP14 %s
+// RUN: %clang_cc1 -dwarf-version=3 -gstrict-dwarf -emit-llvm -triple %itanium_abi_triple %s -o - \
+// RUN:   -x c++ -std=c++14 -O0 -disable-llvm-passes -debug-info-kind=limited | FileCheck %s
+// RUN: %clang_cc1 -dwarf-version=5 -gstrict-dwarf -emit-llvm -triple %itanium_abi_triple %s -o - \
+// RUN:   -x c++ -std=c++14 -O0 -disable-llvm-passes -debug-info-kind=limited \
+// RUN:   | FileCheck --check-prefix=CHECK-CPP14 %s
 
 int main() {
   return 0;
 }
 
-// CHECK-DWARF5: distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14,
-// CHECK-DWARF3: distinct !DICompileUnit(language: DW_LANG_C_plus_plus,
+// CHECK-CPP14: distinct !DIComp

[PATCH] D104258: [OPENMP]Fix PR50699: capture locals in combine directrives for aligned clause.

2021-06-15 Thread Alexey Bataev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG45ae766e78e0: [OPENMP]Fix PR50699: capture locals in combine 
directrives for aligned clause. (authored by ABataev).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104258

Files:
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/parallel_for_simd_aligned_codegen.cpp

Index: clang/test/OpenMP/parallel_for_simd_aligned_codegen.cpp
===
--- /dev/null
+++ clang/test/OpenMP/parallel_for_simd_aligned_codegen.cpp
@@ -0,0 +1,346 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --function-signature --include-generated-funcs --replace-value-regex "__omp_offloading_[0-9a-z]+_[0-9a-z]+" "reduction_size[.].+[.]" "pl_cond[.].+[.|,]" --prefix-filecheck-ir-name _
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK1
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-unknown-unknown -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix=CHECK2
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -std=c++11 -DLAMBDA -triple x86_64-unknown-linux -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK3
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -fblocks -DBLOCKS -triple x86_64-unknown-linux -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK4
+
+// RUN: %clang_cc1 -verify -fopenmp-simd -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s --implicit-check-not="{{__kmpc|__tgt}}"
+// RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -triple x86_64-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp-simd -x c++ -triple x86_64-unknown-unknown -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --implicit-check-not="{{__kmpc|__tgt}}"
+// RUN: %clang_cc1 -verify -fopenmp-simd -x c++ -std=c++11 -DLAMBDA -triple x86_64-unknown-linux -emit-llvm %s -o - | FileCheck %s --implicit-check-not="{{__kmpc|__tgt}}"
+// RUN: %clang_cc1 -verify -fopenmp-simd -x c++ -fblocks -DBLOCKS -triple x86_64-unknown-linux -emit-llvm %s -o - | FileCheck %s --implicit-check-not="{{__kmpc|__tgt}}"
+// expected-no-diagnostics
+#ifndef HEADER
+#define HEADER
+
+void foo(float *c) {
+#pragma omp parallel for simd aligned(c)
+  for (int i = 0; i < 10; ++i);
+}
+
+#endif
+
+// CHECK1-LABEL: define {{[^@]+}}@_Z3fooPf
+// CHECK1-SAME: (float* [[C:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK1-NEXT:  entry:
+// CHECK1-NEXT:[[C_ADDR:%.*]] = alloca float*, align 8
+// CHECK1-NEXT:store float* [[C]], float** [[C_ADDR]], align 8
+// CHECK1-NEXT:call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(%struct.ident_t* @[[GLOB2:[0-9]+]], i32 1, void (i32*, i32*, ...)* bitcast (void (i32*, i32*, float**)* @.omp_outlined. to void (i32*, i32*, ...)*), float** [[C_ADDR]])
+// CHECK1-NEXT:ret void
+//
+//
+// CHECK1-LABEL: define {{[^@]+}}@.omp_outlined.
+// CHECK1-SAME: (i32* noalias [[DOTGLOBAL_TID_:%.*]], i32* noalias [[DOTBOUND_TID_:%.*]], float** nonnull align 8 dereferenceable(8) [[C:%.*]]) #[[ATTR1:[0-9]+]] {
+// CHECK1-NEXT:  entry:
+// CHECK1-NEXT:[[DOTGLOBAL_TID__ADDR:%.*]] = alloca i32*, align 8
+// CHECK1-NEXT:[[DOTBOUND_TID__ADDR:%.*]] = alloca i32*, align 8
+// CHECK1-NEXT:[[C_ADDR:%.*]] = alloca float**, align 8
+// CHECK1-NEXT:[[DOTOMP_IV:%.*]] = alloca i32, align 4
+// CHECK1-NEXT:[[TMP:%.*]] = alloca i32, align 4
+// CHECK1-NEXT:[[DOTOMP_LB:%.*]] = alloca i32, align 4
+// CHECK1-NEXT:[[DOTOMP_UB:%.*]] = alloca i32, align 4
+// CHECK1-NEXT:[[DOTOMP_STRIDE:%.*]] = alloca i32, align 4
+// CHECK1-NEXT:[[DOTOMP_IS_LAST:%.*]] = alloca i32, align 4
+// CHECK1-NEXT:[[I:%.*]] = alloca i32, align 4
+// CHECK1-NEXT:store i32* [[DOTGLOBAL_TID_]], i32** [[DOTGLOBAL_TID__ADDR]], align 8
+// CHECK1-NEXT:store i32* [[DOTBOUND_TID_]], i32** [[DOTBOUND_TID__ADDR]], align 8
+// CHECK1-NEXT:store float** [[C]], float*** [[C_ADDR]], align 8
+// CHECK1-NEXT:[[TMP0:%.*]] = load float**, float*** [[C_ADDR]], align 8
+// CHECK1-NEXT:[[TMP1:%.*]] = load float*, float** [[TMP0]], align 8
+// CHECK1-NEXT:call void @llvm.assume(i1 true) [ "align"(float* [[TMP1]], i64 16) ]
+// CHECK1-NEXT:store i32 0, i32* [[DOTOMP_LB]], align 4
+// CHECK1-NEXT:store i32 9, i32* [[DOTOMP_UB]], align 4
+// CHECK1-NEXT:store i32 1, i32* [[DOTOMP_STRIDE]], align 4
+// CHECK1-NEXT:store i32 0, i32* [[DOTOMP_IS_LAST]], align 4
+// CHECK1-NEXT:[[TMP2:%.*]] = load i32*, i32** [[DOTGLOBAL_TID__ADDR]], align 8
+// CHECK1-NEXT:[[TMP3:%.*]] = load i32, i32* [[TMP2]], align 4
+// CHECK1-NEXT:call void @__kmpc_for_static_init_4(%struct.ident_t* @[[GLOB1:[0-9]+]], i32 [[TMP3]], 

[clang] 45ae766 - [OPENMP]Fix PR50699: capture locals in combine directrives for aligned clause.

2021-06-15 Thread Alexey Bataev via cfe-commits

Author: Alexey Bataev
Date: 2021-06-15T04:58:02-07:00
New Revision: 45ae766e78e07434f68305d1b56bf3ee65ebbcef

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

LOG: [OPENMP]Fix PR50699: capture locals in combine directrives for aligned 
clause.

Need to capture locals in aligned clauses for the combined directives to
be fix the crash in the codegen.

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

Added: 
clang/test/OpenMP/parallel_for_simd_aligned_codegen.cpp

Modified: 
clang/lib/Sema/SemaOpenMP.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 0e39b8ef572d..44acb570885b 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -4608,7 +4608,8 @@ StmtResult Sema::ActOnOpenMPRegionEnd(StmtResult S,
   }
 }
 if (ThisCaptureRegion == OMPD_parallel) {
-  // Capture temp arrays for inscan reductions.
+  // Capture temp arrays for inscan reductions and locals in aligned
+  // clauses.
   for (OMPClause *C : Clauses) {
 if (auto *RC = dyn_cast(C)) {
   if (RC->getModifier() != OMPC_REDUCTION_inscan)
@@ -4616,6 +4617,10 @@ StmtResult Sema::ActOnOpenMPRegionEnd(StmtResult S,
   for (Expr *E : RC->copy_array_temps())
 MarkDeclarationsReferencedInExpr(E);
 }
+if (auto *AC = dyn_cast(C)) {
+  for (Expr *E : AC->varlists())
+MarkDeclarationsReferencedInExpr(E);
+}
   }
 }
 if (++CompletedRegions == CaptureRegions.size())

diff  --git a/clang/test/OpenMP/parallel_for_simd_aligned_codegen.cpp 
b/clang/test/OpenMP/parallel_for_simd_aligned_codegen.cpp
new file mode 100644
index ..5e8756d37d91
--- /dev/null
+++ b/clang/test/OpenMP/parallel_for_simd_aligned_codegen.cpp
@@ -0,0 +1,346 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --function-signature --include-generated-funcs --replace-value-regex 
"__omp_offloading_[0-9a-z]+_[0-9a-z]+" "reduction_size[.].+[.]" 
"pl_cond[.].+[.|,]" --prefix-filecheck-ir-name _
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple x86_64-unknown-unknown 
-emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK1
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown 
-emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-unknown-unknown -std=c++11 
-include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix=CHECK2
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -std=c++11 -DLAMBDA -triple 
x86_64-unknown-linux -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK3
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -fblocks -DBLOCKS -triple 
x86_64-unknown-linux -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK4
+
+// RUN: %clang_cc1 -verify -fopenmp-simd -x c++ -triple x86_64-unknown-unknown 
-emit-llvm %s -o - | FileCheck %s --implicit-check-not="{{__kmpc|__tgt}}"
+// RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -triple 
x86_64-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp-simd -x c++ -triple x86_64-unknown-unknown 
-std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s 
--implicit-check-not="{{__kmpc|__tgt}}"
+// RUN: %clang_cc1 -verify -fopenmp-simd -x c++ -std=c++11 -DLAMBDA -triple 
x86_64-unknown-linux -emit-llvm %s -o - | FileCheck %s 
--implicit-check-not="{{__kmpc|__tgt}}"
+// RUN: %clang_cc1 -verify -fopenmp-simd -x c++ -fblocks -DBLOCKS -triple 
x86_64-unknown-linux -emit-llvm %s -o - | FileCheck %s 
--implicit-check-not="{{__kmpc|__tgt}}"
+// expected-no-diagnostics
+#ifndef HEADER
+#define HEADER
+
+void foo(float *c) {
+#pragma omp parallel for simd aligned(c)
+  for (int i = 0; i < 10; ++i);
+}
+
+#endif
+
+// CHECK1-LABEL: define {{[^@]+}}@_Z3fooPf
+// CHECK1-SAME: (float* [[C:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK1-NEXT:  entry:
+// CHECK1-NEXT:[[C_ADDR:%.*]] = alloca float*, align 8
+// CHECK1-NEXT:store float* [[C]], float** [[C_ADDR]], align 8
+// CHECK1-NEXT:call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, 
...) @__kmpc_fork_call(%struct.ident_t* @[[GLOB2:[0-9]+]], i32 1, void (i32*, 
i32*, ...)* bitcast (void (i32*, i32*, float**)* @.omp_outlined. to void (i32*, 
i32*, ...)*), float** [[C_ADDR]])
+// CHECK1-NEXT:ret void
+//
+//
+// CHECK1-LABEL: define {{[^@]+}}@.omp_outlined.
+// CHECK1-SAME: (i32* noalias [[DOTGLOBAL_TID_:%.*]], i32* noalias 
[[DOTBOUND_TID_:%.*]], float** nonnull align 8 dereferenceable(8) [[C:%.*]]) 
#[[ATTR1:[0-9]+]] {
+// CHECK1-NEXT:  entry:
+// CHECK1-NEXT:[[DOTGLOBAL_TID__ADDR:%.*]] = alloca i32*, align 8
+// CHECK1-NEXT:[[DOTBOUND_TID__ADDR:%.*]] = alloca i32*, align 8
+// CHECK1-NEXT:[[C_ADDR:%.*]] = alloca float**, align 8
+// CHECK1-NEXT:[

[PATCH] D103702: [AArch64][SVE] Wire up vscale_range attribute to SVE min/max vector queries

2021-06-15 Thread Bradley Smith via Phabricator via cfe-commits
bsmith updated this revision to Diff 352101.
bsmith marked an inline comment as done.
bsmith added a comment.

- Ensure user input is sanitized for when asserts are not enabled
- Fix clang format issues


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103702

Files:
  clang/test/CodeGen/aarch64-sve-vector-bits-codegen.c
  llvm/lib/Target/AArch64/AArch64Subtarget.cpp
  llvm/lib/Target/AArch64/AArch64Subtarget.h
  llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
  llvm/test/CodeGen/AArch64/sve-vscale-attr.ll

Index: llvm/test/CodeGen/AArch64/sve-vscale-attr.ll
===
--- /dev/null
+++ llvm/test/CodeGen/AArch64/sve-vscale-attr.ll
@@ -0,0 +1,144 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s | FileCheck %s --check-prefixes=CHECK,CHECK-NOARG
+; RUN: llc -aarch64-sve-vector-bits-min=512 < %s | FileCheck %s --check-prefixes=CHECK,CHECK-ARG
+
+target triple = "aarch64-unknown-linux-gnu"
+
+define void @func_vscale_none(<16 x i32>* %a, <16 x i32>* %b) #0 {
+; CHECK-NOARG-LABEL: func_vscale_none:
+; CHECK-NOARG:   // %bb.0:
+; CHECK-NOARG-NEXT:ldp q0, q1, [x0]
+; CHECK-NOARG-NEXT:ldp q2, q3, [x1]
+; CHECK-NOARG-NEXT:ldp q4, q5, [x0, #32]
+; CHECK-NOARG-NEXT:ldp q7, q6, [x1, #32]
+; CHECK-NOARG-NEXT:add v1.4s, v1.4s, v3.4s
+; CHECK-NOARG-NEXT:add v0.4s, v0.4s, v2.4s
+; CHECK-NOARG-NEXT:add v2.4s, v5.4s, v6.4s
+; CHECK-NOARG-NEXT:add v3.4s, v4.4s, v7.4s
+; CHECK-NOARG-NEXT:stp q3, q2, [x0, #32]
+; CHECK-NOARG-NEXT:stp q0, q1, [x0]
+; CHECK-NOARG-NEXT:ret
+;
+; CHECK-ARG-LABEL: func_vscale_none:
+; CHECK-ARG:   // %bb.0:
+; CHECK-ARG-NEXT:ptrue p0.s, vl16
+; CHECK-ARG-NEXT:ld1w { z0.s }, p0/z, [x0]
+; CHECK-ARG-NEXT:ld1w { z1.s }, p0/z, [x1]
+; CHECK-ARG-NEXT:add z0.s, p0/m, z0.s, z1.s
+; CHECK-ARG-NEXT:st1w { z0.s }, p0, [x0]
+; CHECK-ARG-NEXT:ret
+  %op1 = load <16 x i32>, <16 x i32>* %a
+  %op2 = load <16 x i32>, <16 x i32>* %b
+  %res = add <16 x i32> %op1, %op2
+  store <16 x i32> %res, <16 x i32>* %a
+  ret void
+}
+
+attributes #0 = { "target-features"="+sve" }
+
+define void @func_vscale1_1(<16 x i32>* %a, <16 x i32>* %b) #1 {
+; CHECK-LABEL: func_vscale1_1:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:ldp q0, q1, [x0]
+; CHECK-NEXT:ldp q2, q3, [x1]
+; CHECK-NEXT:ldp q4, q5, [x0, #32]
+; CHECK-NEXT:ldp q7, q6, [x1, #32]
+; CHECK-NEXT:add v1.4s, v1.4s, v3.4s
+; CHECK-NEXT:add v0.4s, v0.4s, v2.4s
+; CHECK-NEXT:add v2.4s, v5.4s, v6.4s
+; CHECK-NEXT:add v3.4s, v4.4s, v7.4s
+; CHECK-NEXT:stp q3, q2, [x0, #32]
+; CHECK-NEXT:stp q0, q1, [x0]
+; CHECK-NEXT:ret
+  %op1 = load <16 x i32>, <16 x i32>* %a
+  %op2 = load <16 x i32>, <16 x i32>* %b
+  %res = add <16 x i32> %op1, %op2
+  store <16 x i32> %res, <16 x i32>* %a
+  ret void
+}
+
+attributes #1 = { "target-features"="+sve" vscale_range(1,1) }
+
+define void @func_vscale2_2(<16 x i32>* %a, <16 x i32>* %b) #2 {
+; CHECK-LABEL: func_vscale2_2:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:ptrue p0.s, vl8
+; CHECK-NEXT:add x8, x0, #32 // =32
+; CHECK-NEXT:add x9, x1, #32 // =32
+; CHECK-NEXT:ld1w { z0.s }, p0/z, [x0]
+; CHECK-NEXT:ld1w { z1.s }, p0/z, [x8]
+; CHECK-NEXT:ld1w { z2.s }, p0/z, [x1]
+; CHECK-NEXT:ld1w { z3.s }, p0/z, [x9]
+; CHECK-NEXT:add z0.s, p0/m, z0.s, z2.s
+; CHECK-NEXT:add z1.s, p0/m, z1.s, z3.s
+; CHECK-NEXT:st1w { z0.s }, p0, [x0]
+; CHECK-NEXT:st1w { z1.s }, p0, [x8]
+; CHECK-NEXT:ret
+  %op1 = load <16 x i32>, <16 x i32>* %a
+  %op2 = load <16 x i32>, <16 x i32>* %b
+  %res = add <16 x i32> %op1, %op2
+  store <16 x i32> %res, <16 x i32>* %a
+  ret void
+}
+
+attributes #2 = { "target-features"="+sve" vscale_range(2,2) }
+
+define void @func_vscale2_4(<16 x i32>* %a, <16 x i32>* %b) #3 {
+; CHECK-LABEL: func_vscale2_4:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:ptrue p0.s, vl8
+; CHECK-NEXT:add x8, x0, #32 // =32
+; CHECK-NEXT:add x9, x1, #32 // =32
+; CHECK-NEXT:ld1w { z0.s }, p0/z, [x0]
+; CHECK-NEXT:ld1w { z1.s }, p0/z, [x8]
+; CHECK-NEXT:ld1w { z2.s }, p0/z, [x1]
+; CHECK-NEXT:ld1w { z3.s }, p0/z, [x9]
+; CHECK-NEXT:add z0.s, p0/m, z0.s, z2.s
+; CHECK-NEXT:add z1.s, p0/m, z1.s, z3.s
+; CHECK-NEXT:st1w { z0.s }, p0, [x0]
+; CHECK-NEXT:st1w { z1.s }, p0, [x8]
+; CHECK-NEXT:ret
+  %op1 = load <16 x i32>, <16 x i32>* %a
+  %op2 = load <16 x i32>, <16 x i32>* %b
+  %res = add <16 x i32> %op1, %op2
+  store <16 x i32> %res, <16 x i32>* %a
+  ret void
+}
+
+attributes #3 = { "target-features"="+sve" vscale_range(2,4) }
+
+define void @func_vscale4_4(<16 x i32>* %a, <16 x i32>* %b) #4 {
+; CHECK-LABEL: func_vscale4_4:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:ptrue p0.s, vl16
+; CHECK-NEXT:ld1w { z0.s }, p0/z, [x0]
+; CHECK-NEXT:ld1w { z1.s }, p0

[PATCH] D103702: [AArch64][SVE] Wire up vscale_range attribute to SVE min/max vector queries

2021-06-15 Thread Bradley Smith via Phabricator via cfe-commits
bsmith added inline comments.



Comment at: llvm/lib/Target/AArch64/AArch64Subtarget.h:298-299
+   bool LittleEndian,
+   unsigned MinSVEVectorSizeInBitsOverride = 0,
+   unsigned MaxSVEVectorSizeInBitsOverride = 0);
 

paulwalker-arm wrote:
> Out of interest are these defaults ever relied upon?
Only in the case of manual construction of a subtarget, for example a unit test 
etc. For normal cases this will always be passed in based on the attribute or 
command line options.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103702

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


[PATCH] D104222: [clang-format] [PR50702] Lamdba processing does not respect AfterClass and AfterNamespace

2021-06-15 Thread Christophe Calmejane via Phabricator via cfe-commits
christophe-calmejane added a comment.

Hi,

Due to the pandemic, I wasn't able to look at https://reviews.llvm.org/D44609 
which got broken since it was pushed to LLVM. Nevertheless I commented in that 
post with a rather complete unit tests that should pass if any changes are to 
be pushed to that part of the code.

Here is the test suite:

  noOtherParams([](int x){call();});
  paramBeforeLambda(8,[](int x){call();});
  paramAfterLambda([](int x){call();},5);
  paramBeforeAndAfterLambda(8,[](int x){call();},5);
  doubleLambda(8,[](int x){call();},6,[](float f){return f*2;},5);
  nestedLambda1([](int x){return [](float f){return f*2;};});
  nestedLambda2([](int x){ call([](float f){return f*2;});});
  noExceptCall([](int x) noexcept {call();});
  mutableCall([](int x) mutable{call();});
  
  funcCallFunc(call(),[](int x){call();});
  
  auto const l=[](char v){if(v)call();};
  void f() { return [](char v){ if(v) return v++;}; }

And here is how it should be formatted:

  noOtherParams(
  [](int x)
  {
  call();
  });
  paramBeforeLambda(8,
  [](int x)
  {
  call();
  });
  paramAfterLambda(
  [](int x)
  {
  call();
  },
  5);
  paramBeforeAndAfterLambda(8,
  [](int x)
  {
  call();
  },
  5);
  doubleLambda(8,
  [](int x)
  {
  call();
  },
  6,
  [](float f)
  {
  return f * 2;
  },
  5);
  nestedLambda1(
  [](int x)
  {
  return [](float f)
  {
  return f * 2;
  };
  });
  nestedLambda2(
  [](int x)
  {
  call(
  [](float f)
  {
  return f * 2;
  });
  });
  noExceptCall(
  [](int x) noexcept
  {
  call();
  });
  mutableCall(
  [](int x) mutable
  {
  call();
  });
  
  funcCallFunc(call(),
  [](int x)
  {
  call();
  });
  
  auto const l = [](char v)
  {
  if (v)
  call();
  };
  void f()
  {
  return [](char v)
  {
  if (v)
  return v++;
  };
  }

I couldn't find the time to test this case with the latest clang-format 
release, but I guess it's still broken and doesn't match the expected output.
Anyway, this test suite is helpful as it covers most cases, and if someone with 
enough knowledge of LLVM is willing to add this to the unit tests it would help 
a lot.

Best regards,
Chris


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

https://reviews.llvm.org/D104222

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


[clang] 304b9c2 - [Matrix] Add tests for fast-math flags & matrix codegen.

2021-06-15 Thread Florian Hahn via cfe-commits

Author: Florian Hahn
Date: 2021-06-15T13:22:34+01:00
New Revision: 304b9c25d58d611287c51c50cc0fe4a8c16f6f0d

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

LOG: [Matrix] Add tests for fast-math flags & matrix codegen.

This has already been implemented in be2277fbf233 which adds
pragma fp support. This patch just adds test coverage for
regular fast-math flags (PR46165).

Added: 
clang/test/CodeGen/matrix-type-operators-fast-math.c

Modified: 


Removed: 




diff  --git a/clang/test/CodeGen/matrix-type-operators-fast-math.c 
b/clang/test/CodeGen/matrix-type-operators-fast-math.c
new file mode 100644
index ..33b9a51a736a
--- /dev/null
+++ b/clang/test/CodeGen/matrix-type-operators-fast-math.c
@@ -0,0 +1,145 @@
+// RUN: %clang_cc1 -ffast-math -fenable-matrix -triple x86_64-apple-darwin %s 
-emit-llvm -disable-llvm-passes -o - | FileCheck %s
+
+typedef double dx5x5_t __attribute__((matrix_type(5, 5)));
+typedef float fx2x3_t __attribute__((matrix_type(2, 3)));
+typedef int ix9x3_t __attribute__((matrix_type(9, 3)));
+typedef unsigned long long ullx4x2_t __attribute__((matrix_type(4, 2)));
+
+// Floating point matrix/scalar additions.
+
+void add_matrix_matrix_double(dx5x5_t a, dx5x5_t b, dx5x5_t c) {
+  // CHECK-LABEL: define{{.*}} void @add_matrix_matrix_double(<25 x double> 
%a, <25 x double> %b, <25 x double> %c)
+  // CHECK:   [[B:%.*]] = load <25 x double>, <25 x double>* {{.*}}, align 
8
+  // CHECK-NEXT:  [[C:%.*]] = load <25 x double>, <25 x double>* {{.*}}, align 
8
+  // CHECK-NEXT:  [[RES:%.*]] = fadd reassoc nnan ninf nsz arcp afn <25 x 
double> [[B]], [[C]]
+  // CHECK-NEXT:  store <25 x double> [[RES]], <25 x double>* {{.*}}, align 8
+
+  a = b + c;
+}
+
+void add_compound_assign_matrix_double(dx5x5_t a, dx5x5_t b) {
+  // CHECK-LABEL: define{{.*}} void @add_compound_assign_matrix_double(<25 x 
double> %a, <25 x double> %b)
+  // CHECK:   [[B:%.*]] = load <25 x double>, <25 x double>* {{.*}}, align 
8
+  // CHECK-NEXT:  [[A:%.*]] = load <25 x double>, <25 x double>* {{.*}}, align 
8
+  // CHECK-NEXT:  [[RES:%.*]] = fadd reassoc nnan ninf nsz arcp afn <25 x 
double> [[A]], [[B]]
+  // CHECK-NEXT:  store <25 x double> [[RES]], <25 x double>* {{.*}}, align 8
+
+  a += b;
+}
+
+void subtract_compound_assign_matrix_double(dx5x5_t a, dx5x5_t b) {
+  // CHECK-LABEL: define{{.*}} void 
@subtract_compound_assign_matrix_double(<25 x double> %a, <25 x double> %b)
+  // CHECK:   [[B:%.*]] = load <25 x double>, <25 x double>* {{.*}}, align 
8
+  // CHECK-NEXT:  [[A:%.*]] = load <25 x double>, <25 x double>* {{.*}}, align 
8
+  // CHECK-NEXT:  [[RES:%.*]] = fsub reassoc nnan ninf nsz arcp afn <25 x 
double> [[A]], [[B]]
+  // CHECK-NEXT:  store <25 x double> [[RES]], <25 x double>* {{.*}}, align 8
+
+  a -= b;
+}
+
+void add_matrix_scalar_double_float(dx5x5_t a, float vf) {
+  // CHECK-LABEL: define{{.*}} void @add_matrix_scalar_double_float(<25 x 
double> %a, float %vf)
+  // CHECK:   [[MATRIX:%.*]] = load <25 x double>, <25 x double>* {{.*}}, 
align 8
+  // CHECK-NEXT:  [[SCALAR:%.*]] = load float, float* %vf.addr, align 4
+  // CHECK-NEXT:  [[SCALAR_EXT:%.*]] = fpext float [[SCALAR]] to double
+  // CHECK-NEXT:  [[SCALAR_EMBED:%.*]] = insertelement <25 x double> poison, 
double [[SCALAR_EXT]], i32 0
+  // CHECK-NEXT:  [[SCALAR_EMBED1:%.*]] = shufflevector <25 x double> 
[[SCALAR_EMBED]], <25 x double> poison, <25 x i32> zeroinitializer
+  // CHECK-NEXT:  [[RES:%.*]] = fadd reassoc nnan ninf nsz arcp afn <25 x 
double> [[MATRIX]], [[SCALAR_EMBED1]]
+  // CHECK-NEXT:  store <25 x double> [[RES]], <25 x double>* {{.*}}, align 8
+
+  a = a + vf;
+}
+
+void add_compound_matrix_scalar_double_float(dx5x5_t a, float vf) {
+  // CHECK-LABEL: define{{.*}} void 
@add_compound_matrix_scalar_double_float(<25 x double> %a, float %vf)
+  // CHECK:  [[SCALAR:%.*]] = load float, float* %vf.addr, align 4
+  // CHECK-NEXT:  [[SCALAR_EXT:%.*]] = fpext float [[SCALAR]] to double
+  // CHECK-NEXT:  [[MATRIX:%.*]] = load <25 x double>, <25 x double>* {{.*}}, 
align 8
+  // CHECK-NEXT:  [[SCALAR_EMBED:%.*]] = insertelement <25 x double> poison, 
double [[SCALAR_EXT]], i32 0
+  // CHECK-NEXT:  [[SCALAR_EMBED1:%.*]] = shufflevector <25 x double> 
[[SCALAR_EMBED]], <25 x double> poison, <25 x i32> zeroinitializer
+  // CHECK-NEXT:  [[RES:%.*]] = fadd reassoc nnan ninf nsz arcp afn <25 x 
double> [[MATRIX]], [[SCALAR_EMBED1]]
+  // CHECK-NEXT:  store <25 x double> [[RES]], <25 x double>* {{.*}}, align 8
+
+  a += vf;
+}
+
+void subtract_compound_matrix_scalar_double_float(dx5x5_t a, float vf) {
+  // CHECK-LABEL: define{{.*}} void 
@subtract_compound_matrix_scalar_double_float(<25 x double> %a, float %vf)
+  // CHECK:  [[SCALAR:%.*]] = load float, float* %vf.addr, align 4
+  

[PATCH] D103792: [clang][AST] Set correct DeclContext in ASTImporter lookup table for template params.

2021-06-15 Thread Gabor Marton via Phabricator via cfe-commits
martong accepted this revision.
martong added a comment.
This revision is now accepted and ready to land.

Ok, looks good to me! Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103792

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


[PATCH] D102478: [Matrix] Emit assumption that matrix indices are valid.

2021-06-15 Thread Florian Hahn via Phabricator via cfe-commits
fhahn updated this revision to Diff 352108.
fhahn added a comment.

In D102478#2817768 , @erichkeane 
wrote:

> Just a couple of nits here, basically see how much we can put in the 'cheap 
> to check' branch.

Thanks! I moved the suggested bits inside the then branch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102478

Files:
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/test/CodeGen/matrix-type-operators.c
  clang/test/CodeGenCXX/matrix-type-operators.cpp
  clang/test/CodeGenObjC/matrix-type-operators.m
  llvm/include/llvm/IR/MatrixBuilder.h

Index: llvm/include/llvm/IR/MatrixBuilder.h
===
--- llvm/include/llvm/IR/MatrixBuilder.h
+++ llvm/include/llvm/IR/MatrixBuilder.h
@@ -231,9 +231,23 @@
: (IsUnsigned ? B.CreateUDiv(LHS, RHS) : B.CreateSDiv(LHS, RHS));
   }
 
-  /// Extracts the element at (\p RowIdx, \p ColumnIdx) from \p Matrix.
-  Value *CreateExtractElement(Value *Matrix, Value *RowIdx, Value *ColumnIdx,
-  unsigned NumRows, Twine const &Name = "") {
+  /// Create an assumption that \p Idx is less than \p NumElements.
+  void CreateIndexAssumption(Value *Idx, unsigned NumElements,
+ Twine const &Name = "") {
+
+Value *NumElts =
+B.getIntN(Idx->getType()->getScalarSizeInBits(), NumElements);
+auto *Cmp = B.CreateICmpULT(Idx, NumElts);
+if (auto *ConstCond = dyn_cast(Cmp))
+  assert(ConstCond->isOne() && "Index must be valid!");
+else
+  B.CreateAssumption(Cmp);
+  }
+
+  /// Compute the index to access the element at (\p RowIdx, \p ColumnIdx) from
+  /// a matrix with \p NumRows embedded in a vector.
+  Value *CreateIndex(Value *RowIdx, Value *ColumnIdx, unsigned NumRows,
+ Twine const &Name = "") {
 
 unsigned MaxWidth = std::max(RowIdx->getType()->getScalarSizeInBits(),
  ColumnIdx->getType()->getScalarSizeInBits());
@@ -241,9 +255,7 @@
 RowIdx = B.CreateZExt(RowIdx, IntTy);
 ColumnIdx = B.CreateZExt(ColumnIdx, IntTy);
 Value *NumRowsV = B.getIntN(MaxWidth, NumRows);
-return B.CreateExtractElement(
-Matrix, B.CreateAdd(B.CreateMul(ColumnIdx, NumRowsV), RowIdx),
-"matext");
+return B.CreateAdd(B.CreateMul(ColumnIdx, NumRowsV), RowIdx);
   }
 };
 
Index: clang/test/CodeGenObjC/matrix-type-operators.m
===
--- clang/test/CodeGenObjC/matrix-type-operators.m
+++ clang/test/CodeGenObjC/matrix-type-operators.m
@@ -22,9 +22,9 @@
 // CHECK-NEXT:[[IV2_PTR:%.*]] = bitcast %0* [[IV2]] to i8*
 // CHECK-NEXT:[[CALL1:%.*]] = call i32 bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i32 (i8*, i8*)*)(i8* [[IV2_PTR]], i8* [[SEL2]])
 // CHECK-NEXT:[[CONV2:%.*]] = sext i32 [[CALL1]] to i64
-// CHECK-NEXT:[[MAT:%.*]] = load <16 x double>, <16 x double>* {{.*}} align 8
 // CHECK-NEXT:[[IDX1:%.*]] = mul i64 [[CONV2]], 4
 // CHECK-NEXT:[[IDX2:%.*]] = add i64 [[IDX1]], [[CONV]]
+// CHECK-NEXT:[[MAT:%.*]] = load <16 x double>, <16 x double>* {{.*}} align 8
 // CHECK-NEXT:[[MATEXT:%.*]] = extractelement <16 x double> [[MAT]], i64 [[IDX2]]
 // CHECK-NEXT:ret double [[MATEXT]]
 //
@@ -49,12 +49,12 @@
 // CHECK-NEXT:[[IV2_PTR:%.*]] = bitcast %0* [[IV2]] to i8*
 // CHECK-NEXT:[[CALL1:%.*]] = call i32 bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i32 (i8*, i8*)*)(i8* [[IV2_PTR]], i8* [[SEL2]])
 // CHECK-NEXT:[[CONV2:%.*]] = sext i32 [[CALL1]] to i64
+// CHECK-NEXT:[[IDX1:%.*]] = mul i64 [[CONV2]], 4
+// CHECK-NEXT:[[IDX2:%.*]] = add i64 [[IDX1]], [[CONV]]
 // CHECK-NEXT:[[M:%.*]] = load %1*, %1** %m.addr, align 8
 // CHECK-NEXT:[[SEL3:%.*]] = load i8*, i8** @OBJC_SELECTOR_REFERENCES_, align 8, !invariant.load !7
 // CHECK-NEXT:[[M_PTR:%.*]] = bitcast %1* [[M]] to i8*
 // CHECK-NEXT:[[MAT:%.*]] = call <16 x double> bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to <16 x double> (i8*, i8*)*)(i8* [[M_PTR]], i8* [[SEL3]])
-// CHECK-NEXT:[[IDX1:%.*]] = mul i64 [[CONV2]], 4
-// CHECK-NEXT:[[IDX2:%.*]] = add i64 [[IDX1]], [[CONV]]
 // CHECK-NEXT:[[MATEXT:%.*]] = extractelement <16 x double> [[MAT]], i64 [[IDX2]]
 // CHECK-NEXT:ret double [[MATEXT]]
 //
Index: clang/test/CodeGenCXX/matrix-type-operators.cpp
===
--- clang/test/CodeGenCXX/matrix-type-operators.cpp
+++ clang/test/CodeGenCXX/matrix-type-operators.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -fenable-matrix -triple x86_64-apple-darwin %s -emit-llvm -disable-llvm-passes -o - -std=c++11 | FileCheck %s
+// RUN: %clang_cc1 -O0 -fenable-matrix -triple x86_64-apple-darwin %s -emit-llvm -disable-llvm-passes -o - -std=c++11 | FileCheck %s
+// RUN: %clang_cc1 -O1 -fen

[PATCH] D101868: [clang-format] Adds a formatter for aligning arrays of structs

2021-06-15 Thread Fred Grim via Phabricator via cfe-commits
feg208 added a comment.

I think, at this point, the sensible thing to do is to pull the test. As 
@MyDeveloperDay points out it isn't really adding any value above and beyond 
the unit tests. If it were non-determinism in the change itself the unit tests 
would catch it. They test the same formatting and test for non-determinism 
explicitly. Yet they've never failed. And there are quite a few of them.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101868

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


[PATCH] D104295: removes redundant test

2021-06-15 Thread Fred Grim via Phabricator via cfe-commits
feg208 created this revision.
feg208 added reviewers: MyDeveloperDay, HazardyKnusperkeks, vitalybuka.
feg208 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This lit test is causing intermittent failures on buildbots. It isn't testing 
anything
the unittests don't.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104295

Files:
  clang/test/Format/struct-array-initializer.cpp


Index: clang/test/Format/struct-array-initializer.cpp
===
--- clang/test/Format/struct-array-initializer.cpp
+++ /dev/null
@@ -1,60 +0,0 @@
-// RUN: grep -Ev "// *[A-Z-]+:" %s \
-// RUN:   | clang-format -style="{BasedOnStyle: LLVM, AlignArrayOfStructures: 
Right}" %s \
-// RUN:   | FileCheck -strict-whitespace -check-prefix=CHECK1 %s
-// RUN: grep -Ev "// *[A-Z-]+:" %s \
-// RUN:   | clang-format -style="{BasedOnStyle: LLVM, AlignArrayOfStructures: 
Left}" %s \
-// RUN:   | FileCheck -strict-whitespace -check-prefix=CHECK2 %s
-struct test {
-  int a;
-  int b;
-  const char *c;
-};
-
-struct toast {
-  int a;
-  const char *b;
-  int c;
-  float d;
-};
-
-void f() {
-  struct test demo[] = {{56, 23, "hello"}, {-1, 93463, "world"}, {7, 5, "!!"}};
-  // CHECK1: {{^[[:space:]]{2}struct test demo\[\] = \{$}}
-  // CHECK1-NEXT: {{([[:space:]]{4})}}{56,23, "hello"},
-  // CHECK1-NEXT: {{([[:space:]]{4})}}{-1, 93463, "world"},
-  // CHECK1-NEXT: {{([[:space:]]{4})}}{ 7, 5,"!!"}
-  // CHECK1-NEXT: {{^[[:space:]]{2}\};$}}
-}
-
-void g() {
-  struct toast demo[] = {
-  {56, "hello world I have some things to say", 30, 4.2},
-  {93463, "those things are really comments", 1, 3.1},
-  {7, "about a wide range of topics", 789, .112233}};
-  // CHECK1: {{^[[:space:]]{2}struct toast demo\[\] = \{$}}
-  // CHECK1-NEXT: {{([[:space:]]{4})}}{   56, "hello world I have some things 
to say",  30, 4.2},
-  // CHECK1-NEXT: {{([[:space:]]{4})}}{93463,  "those things are really 
comments",   1, 3.1},
-  // CHECK1-NEXT: {{([[:space:]]{4})}}{7,  "about a wide range of 
topics", 789, .112233}
-  // CHECK1-NEXT: {{^[[:space:]]{2}\};$}}
-}
-
-void h() {
-  struct test demo[] = {{56, 23, "hello"}, {-1, 93463, "world"}, {7, 5, "!!"}};
-  // CHECK2: {{^[[:space:]]{2}struct test demo\[\] = \{$}}
-  // CHECK2-NEXT: {{([[:space:]]{4})}}{56, 23,"hello"},
-  // CHECK2-NEXT: {{([[:space:]]{4})}}{-1, 93463, "world"},
-  // CHECK2-NEXT: {{([[:space:]]{4})}}{7,  5, "!!"   }
-  // CHECK2-NEXT: {{^[[:space:]]{2}\};$}}
-}
-
-void i() {
-  struct toast demo[] = {
-  {56, "hello world I have some things to say", 30, 4.2},
-  {93463, "those things are really comments", 1, 3.1},
-  {7, "about a wide range of topics", 789, .112233}};
-  // CHECK2: {{^[[:space:]]{2}struct toast demo\[\] = \{$}}
-  // CHECK2-NEXT: {{([[:space:]]{4})}}{56,"hello world I have some things 
to say", 30,  4.2},
-  // CHECK2-NEXT: {{([[:space:]]{4})}}{93463, "those things are really 
comments",  1,   3.1},
-  // CHECK2-NEXT: {{([[:space:]]{4})}}{7, "about a wide range of topics",  
789, .112233}
-  // CHECK2-NEXT: {{^[[:space:]]{2}\};$}}
-}


Index: clang/test/Format/struct-array-initializer.cpp
===
--- clang/test/Format/struct-array-initializer.cpp
+++ /dev/null
@@ -1,60 +0,0 @@
-// RUN: grep -Ev "// *[A-Z-]+:" %s \
-// RUN:   | clang-format -style="{BasedOnStyle: LLVM, AlignArrayOfStructures: Right}" %s \
-// RUN:   | FileCheck -strict-whitespace -check-prefix=CHECK1 %s
-// RUN: grep -Ev "// *[A-Z-]+:" %s \
-// RUN:   | clang-format -style="{BasedOnStyle: LLVM, AlignArrayOfStructures: Left}" %s \
-// RUN:   | FileCheck -strict-whitespace -check-prefix=CHECK2 %s
-struct test {
-  int a;
-  int b;
-  const char *c;
-};
-
-struct toast {
-  int a;
-  const char *b;
-  int c;
-  float d;
-};
-
-void f() {
-  struct test demo[] = {{56, 23, "hello"}, {-1, 93463, "world"}, {7, 5, "!!"}};
-  // CHECK1: {{^[[:space:]]{2}struct test demo\[\] = \{$}}
-  // CHECK1-NEXT: {{([[:space:]]{4})}}{56,23, "hello"},
-  // CHECK1-NEXT: {{([[:space:]]{4})}}{-1, 93463, "world"},
-  // CHECK1-NEXT: {{([[:space:]]{4})}}{ 7, 5,"!!"}
-  // CHECK1-NEXT: {{^[[:space:]]{2}\};$}}
-}
-
-void g() {
-  struct toast demo[] = {
-  {56, "hello world I have some things to say", 30, 4.2},
-  {93463, "those things are really comments", 1, 3.1},
-  {7, "about a wide range of topics", 789, .112233}};
-  // CHECK1: {{^[[:space:]]{2}struct toast demo\[\] = \{$}}
-  // CHECK1-NEXT: {{([[:space:]]{4})}}{   56, "hello world I have some things to say",  30, 4.2},
-  // CHECK1-NEXT: {{([[:space:]]{4})}}{93463,  "those things are really comments",   1, 3.1},
-  // CHECK1-NEXT: {{([[:space:]]{4})}}{7,  "about a wide range of topics", 789, .112233}
-  // CHECK1-NEXT: {{^[[:space:]]{2}\};$}}
-}
-
-void h() {
-  str

[PATCH] D104242: Alters a lit test to simplify and avoid a buildbot error

2021-06-15 Thread Fred Grim via Phabricator via cfe-commits
feg208 added a comment.

I put up a separate commit that just removes the test. I think this would 
resolve the builder issues but I don't think its worth even trying. We should 
abandon this (I think)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104242

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


[PATCH] D103750: [analyzer] Handle std::make_unique for SmartPtrModeling

2021-06-15 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD marked an inline comment as done.
RedDocMD added inline comments.



Comment at: clang/test/Analysis/smart-ptr-text-output.cpp:339
+void makeUniqueForOverwriteReturnsNullUniquePtr() {
+  auto P = std::make_unique_for_overwrite(); // expected-note 
{{std::unique_ptr 'P' constructed by std::make_unique_for_overwrite is null}}
+  *P;   // expected-warning 
{{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}

NoQ wrote:
> Mmm wait a sec, that doesn't look like what the spec says.
> 
> https://en.cppreference.com/w/cpp/memory/unique_ptr/make_unique:
> > Same as (1), except that the object is default-initialized. This overload 
> > participates in overload resolution only if T is not an array type. The 
> > function is equivalent to `unique_ptr(new T)`
> 
> It zero-initializes the //pointee//, not the //pointer//.
> 
> The difference between `std::make_unique()` and 
> `std::make_unique_for_overwrite()` is the difference between 
> value-initialization (invoking the default constructor) and 
> zero-initialization (simply filling the buffer with `0`s).
Oops! Look like I completely misunderstood the spec.
So basically, the inner pointer is //not// null, and we have the same 
assumptions that apply for `std::make_unique`. Only problem is that, for 
primitive types, the value obtained on de-referencing is undefined.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103750

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


[PATCH] D103750: [analyzer] Handle std::make_unique for SmartPtrModeling

2021-06-15 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD updated this revision to Diff 352127.
RedDocMD added a comment.

Fixed up meaning of make_unique_for_overwrite, use `getConjuredHeapSymbolVal`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103750

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
  clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
  clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
  clang/test/Analysis/Inputs/system-header-simulator-cxx.h
  clang/test/Analysis/smart-ptr-text-output.cpp

Index: clang/test/Analysis/smart-ptr-text-output.cpp
===
--- clang/test/Analysis/smart-ptr-text-output.cpp
+++ clang/test/Analysis/smart-ptr-text-output.cpp
@@ -1,3 +1,8 @@
+// RUN: %clang_analyze_cc1\
+// RUN:  -analyzer-checker=core,cplusplus.Move,alpha.cplusplus.SmartPtr\
+// RUN:  -analyzer-config cplusplus.SmartPtrModeling:ModelSmartPtrDereference=true\
+// RUN:  -analyzer-output=text -std=c++20 %s -verify=expected
+
 // RUN: %clang_analyze_cc1\
 // RUN:  -analyzer-checker=core,cplusplus.Move,alpha.cplusplus.SmartPtr\
 // RUN:  -analyzer-config cplusplus.SmartPtrModeling:ModelSmartPtrDereference=true\
@@ -313,3 +318,35 @@
 // expected-note@-1{{Dereference of null smart pointer 'P'}}
   }
 }
+
+void makeUniqueReturnsNonNullUniquePtr() {
+  auto P = std::make_unique();
+  if (!P) {   // expected-note {{Taking false branch}}
+P->foo(); // should have no warning here, path is impossible
+  }
+  P.reset(); // expected-note {{Smart pointer 'P' reset using a null value}}
+  // Now P is null
+  if (!P) {
+// expected-note@-1 {{Taking true branch}}
+P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+  }
+}
+
+#if __cplusplus >= 202002L
+
+void makeUniqueForOverwriteReturnsNullUniquePtr() {
+  auto P = std::make_unique_for_overwrite();
+  if (!P) {   // expected-note {{Taking false branch}}
+P->foo(); // should have no warning here, path is impossible
+  }
+  P.reset(); // expected-note {{Smart pointer 'P' reset using a null value}}
+  // Now P is null
+  if (!P) {
+// expected-note@-1 {{Taking true branch}}
+P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+  }
+}
+
+#endif
Index: clang/test/Analysis/Inputs/system-header-simulator-cxx.h
===
--- clang/test/Analysis/Inputs/system-header-simulator-cxx.h
+++ clang/test/Analysis/Inputs/system-header-simulator-cxx.h
@@ -978,6 +978,17 @@
 void swap(unique_ptr &x, unique_ptr &y) noexcept {
   x.swap(y);
 }
+
+template 
+unique_ptr make_unique(Args &&...args);
+
+#if __cplusplus >= 202002L
+
+template 
+unique_ptr make_unique_for_overwrite();
+
+#endif
+
 } // namespace std
 #endif
 
Index: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -192,12 +192,19 @@
   const LocationContext *LCtx,
   unsigned VisitCount) {
   QualType T = E->getType();
-  assert(Loc::isLocType(T));
-  assert(SymbolManager::canSymbolicate(T));
-  if (T->isNullPtrType())
-return makeZeroVal(T);
+  return getConjuredHeapSymbolVal(E, LCtx, T, VisitCount);
+}
+
+DefinedOrUnknownSVal
+SValBuilder::getConjuredHeapSymbolVal(const Expr *E,
+  const LocationContext *LCtx,
+  QualType type, unsigned VisitCount) {
+  assert(Loc::isLocType(type));
+  assert(SymbolManager::canSymbolicate(type));
+  if (type->isNullPtrType())
+return makeZeroVal(type);
 
-  SymbolRef sym = SymMgr.conjureSymbol(E, LCtx, T, VisitCount);
+  SymbolRef sym = SymMgr.conjureSymbol(E, LCtx, type, VisitCount);
   return loc::MemRegionVal(MemMgr.getSymbolicHeapRegion(sym));
 }
 
Index: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
+++ clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
@@ -35,6 +35,7 @@
 using namespace ento;
 
 namespace {
+
 class SmartPtrModeling
 : public Checker {
@@ -76,6 +77,9 @@
   {{"release"}, &SmartPtrModeling::handleRelease},
   {{"swap", 1}, &SmartPtrModeling::handleSwap},
   {{"get"}, &SmartPtrModeling::handleGet}};
+  const CallDescription StdMakeUniqueCall{{"std", "make_unique"}};
+  const CallDescription StdMakeUniqueForOverwriteCall{
+  {"std", "make_unique_for_overwrite"}};
 };
 } // end of anonymous namespace
 
@@ -135,6 +139,21 @@
   return State;
 }
 
+// This is for use wit

[PATCH] D97085: [OpenMP] libomp: implement OpenMP 5.1 inoutset task dependence type

2021-06-15 Thread Jonathan Peyton via Phabricator via cfe-commits
jlpeyton accepted this revision.
jlpeyton added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97085

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


[PATCH] D104222: [clang-format] [PR50702] Lamdba processing does not respect AfterClass and AfterNamespace

2021-06-15 Thread Francois JEAN via Phabricator via cfe-commits
Wawha added a comment.

Hi @christophe-calmejane.
I test your code with a old version (few time after the merge of 
https://reviews.llvm.org/D44609), and the latest version (commit: e0c382a9d5a0 
), and in 
both cases I have the same result, which is near your output:

  noOtherParams(
[](int x)
{
call();
});
  paramBeforeLambda(
8,
[](int x)
{
call();
});
  paramAfterLambda(
[](int x)
{
call();
},
5);
  paramBeforeAndAfterLambda(
8,
[](int x)
{
call();
},
5);
  doubleLambda(
8,
[](int x)
{
call();
},
6,
[](float f)
{
return f * 2;
},
5);
  nestedLambda1(
[](int x)
{
return [](float f)
{
return f * 2;
};
});
  nestedLambda2(
[](int x)
{
call(
[](float f)
{
return f * 2;
});
});
  noExceptCall(
[](int x) noexcept
{
call();
});
  mutableCall(
[](int x) mutable
{
call();
});
  
  funcCallFunc(
call(),
[](int x)
{
call();
});
  
  auto const l = [](char v)
  {
if(v)
call();
  };
  void f()
  {
return [](char v)
{
if(v)
return v++;
};
  }

The only different is for cases with multiples parameters.

  paramBeforeLambda(
8,
[](int x)
{
call();
}

I though I add multiples cases, but looking at UnitTests with inline lambda 
"None", I see only few tests, perhaps some are missing.


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

https://reviews.llvm.org/D104222

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


[PATCH] D104222: [clang-format] [PR50702] Lamdba processing does not respect AfterClass and AfterNamespace

2021-06-15 Thread Christophe Calmejane via Phabricator via cfe-commits
christophe-calmejane added a comment.

In D104222#2819324 , @Wawha wrote:

> Hi @christophe-calmejane.
> I test your code with a old version (few time after the merge of 
> https://reviews.llvm.org/D44609), and the latest version (commit: 
> e0c382a9d5a0 
> ), and 
> in both cases I have the same result, which is near your output:
>
> I though I add multiples cases, but looking at UnitTests with inline lambda 
> "None", I see only few tests, perhaps some are missing.

I posted a fix for the incorrect formatting you have in your output (in your 
original review post), but like I said back then, I thought the fix was not 
clean enough to be included. Nevertheless it did fix all cases and formatting 
was perfect for my whole test suite.
I using this "patched" version since then as it's the only one with the correct 
lambda formatting. I tried to reapply my patch on a recent version.. of course 
it failed as there were too many changes in clang-format. I don't have enough 
knowledge on this project to be able to clearly understand how it works and fix 
the formatting on the latest version (but I wish I could)... at least not 
without having to spend too much time on it :(
For the record, my patch over clang-format 7.0 can be found here: 
https://www.kikisoft.com/Hive/clang-format/


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

https://reviews.llvm.org/D104222

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


[PATCH] D103750: [analyzer] Handle std::make_unique for SmartPtrModeling

2021-06-15 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:216-220
+// TODO: ExprEngine should do this for us.
+auto &Engine = State->getStateManager().getOwningEngine();
+State = Engine.updateObjectsUnderConstruction(
+*ThisRegionOpt, nullptr, State, C.getLocationContext(),
+Call.getConstructionContext(), {});

I think it's fine to have it here in this commit and change it in one of the 
future commits.  But I think we should add a bit more description of 1) what's 
the problem, 2) how is this a solution, 3) how should it look when moved to the 
engine.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103750

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


[PATCH] D104222: [clang-format] [PR50702] Lamdba processing does not respect AfterClass and AfterNamespace

2021-06-15 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

@Wawha your cases could be covered by the following (in mustBreakBefore)

  if (Style.BraceWrapping.BeforeLambdaBody && Right.is(TT_LambdaLBrace) &&
  Left.isOneOf(tok::star, tok::amp, tok::ampamp)) {
return true;
  }

As I think  its the presence of & and * that causes it to not wrap.

By all means if you would prefer to commandeer the patch I'm ok with that. I 
was just on a bug fixing day. If you'd like to take this over and add the unit 
tests @christophe-calmejane suggest, I'm happy to be the reviewer


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

https://reviews.llvm.org/D104222

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


[PATCH] D104118: [OpenCL] Use DW_LANG_OpenCL language tag for OpenCL C

2021-06-15 Thread Stuart Brady via Phabricator via cfe-commits
stuart marked an inline comment as done.
stuart added inline comments.



Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:579
 LangTag = llvm::dwarf::DW_LANG_ObjC;
+  } else if (LO.OpenCL && CGM.getCodeGenOpts().DwarfVersion >= 5) {
+LangTag = llvm::dwarf::DW_LANG_OpenCL;

shchenz wrote:
> stuart wrote:
> > shchenz wrote:
> > > I think for non-strict DWARF mode, we still can generate `DW_LANG_OpenCL` 
> > > for the DWARF version lower than 5? Seems we also need to fix above 
> > > `DW_LANG_C_plus_plus_14` and `DW_LANG_C_plus_plus_11`
> > If we have a `-gstrict-dwarf` option for this, then it would seem better to 
> > add `DW_LANG_C_plus_plus_17` and `DW_LANG_C_plus_plus_20` definitions and 
> > generate those for the `!CGM.getCodeGenOpts().DebugStrictDwarf` case. //C++ 
> > for OpenCL// would then use one of the more recent language tag values for 
> > the time being (without any special logic).
> I added a patch https://reviews.llvm.org/D104291 for `DW_LANG_C_plus_plus_14` 
> and `DW_LANG_C_plus_plus_11`.
> I think `DW_LANG_OpenCL` should be in the same situation?
Thanks. I will wait until D104291 is accepted, and then update this change 
correspondingly. Yes, I believe `DW_LANG_OpenCL` is in the same situation.

Looking more closely, I notice that `DW_LANG_RenderScript` was also introduced 
in DWARF 5, and we don't use it (at all) in Clang, but instead use the 
vendor-specific `DW_LANG_GOOGLE_RenderScript` value. It should probably fall 
back to the vendor-specific value if the DWARF 5 value is not available, 
instead.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104118

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


[PATCH] D104222: [clang-format] [PR50702] Lamdba processing does not respect AfterClass and AfterNamespace

2021-06-15 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

@christophe-calmejane are you able to post your .clang-format styles that you 
are using, I'm struggling to see where its not matching your style (other than 
brace styles on the function and argument placing)


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

https://reviews.llvm.org/D104222

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


[PATCH] D104291: [Debug-Info] strict dwarf for DW_LANG_C_plus_plus_14

2021-06-15 Thread Stuart Brady via Phabricator via cfe-commits
stuart added a comment.

This looks good to me.

@jzzheng22 informs me there was a comment in D99250 
 to the effect that DW_LANG_C_plus_plus_03 is 
not emitted, at all - it too was introduced in DWARF 5.  I wonder if this 
should be addressed in a separate commit?

As mentioned in D104118 , there are language 
codes of DW_LANG_C_plus_plus_17 and DW_LANG_C_plus_plus_20 that will be 
introduced in DWARF 6, which it would be good to use in non-strict mode.  This 
would allow us to emit the more proper code of DW_LANG_C_plus_plus_17 (instead 
of DW_LANG_C_plus_plus_14) for //C++ for OpenCL//, while we wait for 
DW_LANG_CPP_for_OpenCL to get added, as requested at 
http://dwarfstd.org/ShowIssue.php?issue=210514.1.  Should this be addressed in 
a third commit?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104291

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


[PATCH] D104222: [clang-format] [PR50702] Lamdba processing does not respect AfterClass and AfterNamespace

2021-06-15 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay updated this revision to Diff 352136.
MyDeveloperDay added a comment.

Add some of the failing cases identified by @Wawha


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

https://reviews.llvm.org/D104222

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

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -18856,8 +18856,7 @@
"  });\n"
"});",
LLVMWithBeforeLambdaBody);
-  verifyFormat("void Fct()\n"
-   "{\n"
+  verifyFormat("void Fct() {\n"
"  return {[]()\n"
"  {\n"
"return 17;\n"
@@ -19061,6 +19060,29 @@
"  });\n"
"});",
LLVMWithBeforeLambdaBody);
+
+  LLVMWithBeforeLambdaBody.AllowShortLambdasOnASingleLine =
+  FormatStyle::ShortLambdaStyle::SLS_None;
+
+  verifyFormat("auto select = [this]() -> const Library::Object *\n"
+   "{\n"
+   "  return MyAssignment::SelectFromList(this);\n"
+   "};\n",
+   LLVMWithBeforeLambdaBody);
+
+  verifyFormat("auto select = [this]() -> const Library::Object &\n"
+   "{\n"
+   "  return MyAssignment::SelectFromList(this);\n"
+   "};\n",
+   LLVMWithBeforeLambdaBody);
+
+  verifyFormat("namespace test {\n"
+   "class Test {\n"
+   "public:\n"
+   "  Test() = default;\n"
+   "};\n"
+   "} // namespace test",
+   LLVMWithBeforeLambdaBody);
 }
 
 TEST_F(FormatTest, LambdaWithLineComments) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3557,42 +3557,11 @@
   return Tok.Children.empty() && ShortLambdaOption != FormatStyle::SLS_None;
 }
 
-static bool
-isItAInlineLambdaAllowed(const FormatToken &Tok,
- FormatStyle::ShortLambdaStyle ShortLambdaOption) {
-  return (ShortLambdaOption == FormatStyle::SLS_Inline &&
-  IsFunctionArgument(Tok)) ||
- (ShortLambdaOption == FormatStyle::SLS_All);
-}
-
-static bool isOneChildWithoutMustBreakBefore(const FormatToken &Tok) {
-  if (Tok.Children.size() != 1)
-return false;
-  FormatToken *curElt = Tok.Children[0]->First;
-  while (curElt) {
-if (curElt->MustBreakBefore)
-  return false;
-curElt = curElt->Next;
-  }
-  return true;
-}
 static bool isAllmanLambdaBrace(const FormatToken &Tok) {
   return (Tok.is(tok::l_brace) && Tok.is(BK_Block) &&
   !Tok.isOneOf(TT_ObjCBlockLBrace, TT_DictLiteral));
 }
 
-static bool isAllmanBraceIncludedBreakableLambda(
-const FormatToken &Tok, FormatStyle::ShortLambdaStyle ShortLambdaOption) {
-  if (!isAllmanLambdaBrace(Tok))
-return false;
-
-  if (isItAnEmptyLambdaAllowed(Tok, ShortLambdaOption))
-return false;
-
-  return !isItAInlineLambdaAllowed(Tok, ShortLambdaOption) ||
- !isOneChildWithoutMustBreakBefore(Tok);
-}
-
 bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
  const FormatToken &Right) {
   const FormatToken &Left = *Right.Previous;
@@ -3754,13 +3723,6 @@
   if (Right.is(TT_InlineASMBrace))
 return Right.HasUnescapedNewline;
 
-  auto ShortLambdaOption = Style.AllowShortLambdasOnASingleLine;
-  if (Style.BraceWrapping.BeforeLambdaBody &&
-  (isAllmanBraceIncludedBreakableLambda(Left, ShortLambdaOption) ||
-   isAllmanBraceIncludedBreakableLambda(Right, ShortLambdaOption))) {
-return true;
-  }
-
   if (isAllmanBrace(Left) || isAllmanBrace(Right))
 return (Line.startsWith(tok::kw_enum) && Style.BraceWrapping.AfterEnum) ||
(Line.startsWith(tok::kw_typedef, tok::kw_enum) &&
@@ -3783,6 +3745,11 @@
   return true;
   }
 
+  if (Style.BraceWrapping.BeforeLambdaBody && Right.is(TT_LambdaLBrace) &&
+  Left.isOneOf(tok::star, tok::amp, tok::ampamp)) {
+return true;
+  }
+
   // Put multiple Java annotation on a new line.
   if ((Style.Language == FormatStyle::LK_Java ||
Style.Language == FormatStyle::LK_JavaScript) &&
@@ -4186,7 +4153,7 @@
 return false;
 
   auto ShortLambdaOption = Style.AllowShortLambdasOnASingleLine;
-  if (Style.BraceWrapping.BeforeLambdaBody) {
+  if (Style.BraceWrapping.BeforeLambdaBody && Right.is(TT_LambdaLBrace)) {
 if (isAllmanLambdaBrace(Left))
   return !isItAnEmptyLambdaAllowed(Left, ShortLambdaOption);
 if (isAllmanLambdaBrace(Right))
@@ -4198,7 +4165,6 @@
  Right.isMemberAccess() ||
  Right.isOneOf(TT_TrailingReturnArrow, TT_LambdaArrow, tok::lessless,
tok::colon, tok::l_square, tok::at) ||
- (

[PATCH] D104118: [OpenCL] Use DW_LANG_OpenCL language tag for OpenCL C

2021-06-15 Thread Stuart Brady via Phabricator via cfe-commits
stuart planned changes to this revision.
stuart added a comment.

Changes will be required to align this with D104291 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104118

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


[PATCH] D104222: [clang-format] [PR50702] Lamdba processing does not respect AfterClass and AfterNamespace

2021-06-15 Thread Francois JEAN via Phabricator via cfe-commits
Wawha added a comment.

In D104222#2819358 , @MyDeveloperDay 
wrote:

> @Wawha your cases could be covered by the following (in mustBreakBefore)
>
>   if (Style.BraceWrapping.BeforeLambdaBody && Right.is(TT_LambdaLBrace) &&
>   Left.isOneOf(tok::star, tok::amp, tok::ampamp)) {
> return true;
>   }
>
> As I think  its the presence of & and * that causes it to not wrap.
>
> By all means if you would prefer to commandeer the patch I'm ok with that. I 
> was just on a bug fixing day. If you'd like to take this over and add the 
> unit tests @christophe-calmejane suggest, I'm happy to be the reviewer

Indeed, & and * could be the root cause.
About fixing that, I won't have the time in the next days. It will take time 
for me to re-read and re-understand that code.
But I could find time to test patch or modification in my code to check that 
there is no regression.


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

https://reviews.llvm.org/D104222

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


[PATCH] D104299: Handle interactions between reserved identifier and user-defined suffixes

2021-06-15 Thread serge via Phabricator via cfe-commits
serge-sans-paille created this revision.
serge-sans-paille added reviewers: aaron.ballman, rsmith.
Herald added a subscriber: dexonsmith.
serge-sans-paille requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

According to https://eel.is/c++draft/over.literal

> double operator""_Bq(long double);  // OK: does not use the reserved 
> identifier _­Bq ([lex.name])
> double operator"" _Bq(long double); // ill-formed, no diagnostic required: 
> uses the reserved identifier _­Bq ([lex.name])

Obey that rule by keeping track of the operator literal name status wrt. 
leading whitespace.

Fix: https://bugs.llvm.org/show_bug.cgi?id=50644


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104299

Files:
  clang/include/clang/Basic/IdentifierTable.h
  clang/lib/Basic/IdentifierTable.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/test/Sema/reserved-identifier.cpp


Index: clang/test/Sema/reserved-identifier.cpp
===
--- clang/test/Sema/reserved-identifier.cpp
+++ clang/test/Sema/reserved-identifier.cpp
@@ -81,6 +81,11 @@
   return 0.;
 }
 
+long double operator""_SacreBleue(long double) // no-warning
+{
+  return 0.;
+}
+
 struct _BarbeRouge { // expected-warning {{identifier '_BarbeRouge' is 
reserved because it starts with '_' followed by a capital letter}}
 } p;
 struct _BarbeNoire { // expected-warning {{identifier '_BarbeNoire' is 
reserved because it starts with '_' followed by a capital letter}}
Index: clang/lib/Parse/ParseExprCXX.cpp
===
--- clang/lib/Parse/ParseExprCXX.cpp
+++ clang/lib/Parse/ParseExprCXX.cpp
@@ -2644,6 +2644,7 @@
 Lexer::AdvanceToTokenCharacter(TokLocs[Literal.getUDSuffixToken()],
Literal.getUDSuffixOffset(),
PP.getSourceManager(), getLangOpts());
+  II->setLiteralOperatorWithoutWhitespace(true);
 } else if (Tok.is(tok::identifier)) {
   II = Tok.getIdentifierInfo();
   SuffixLoc = ConsumeToken();
Index: clang/lib/Basic/IdentifierTable.cpp
===
--- clang/lib/Basic/IdentifierTable.cpp
+++ clang/lib/Basic/IdentifierTable.cpp
@@ -285,6 +285,11 @@
   if (Name.size() <= 1)
 return ReservedIdentifierStatus::NotReserved;
 
+  // [over.literal] p8
+  llvm::errs() << Name << " isLiteralOperatorWithoutWhitespace: " << 
isLiteralOperatorWithoutWhitespace() << "\n";
+  if(isLiteralOperatorWithoutWhitespace())
+return ReservedIdentifierStatus::NotReserved;
+
   // [lex.name] p3
   if (Name[0] == '_') {
 
Index: clang/include/clang/Basic/IdentifierTable.h
===
--- clang/include/clang/Basic/IdentifierTable.h
+++ clang/include/clang/Basic/IdentifierTable.h
@@ -121,7 +121,10 @@
   // True if this is a mangled OpenMP variant name.
   unsigned IsMangledOpenMPVariantName : 1;
 
-  // 28 bits left in a 64-bit word.
+  // True if this identifier is a literal operator without whitespace.
+  unsigned IsLiteralOperatorWithoutWhitespace : 1;
+
+  // 27 bits left in a 64-bit word.
 
   // Managed by the language front-end.
   void *FETokenInfo = nullptr;
@@ -134,7 +137,8 @@
 IsPoisoned(false), IsCPPOperatorKeyword(false),
 NeedsHandleIdentifier(false), IsFromAST(false), 
ChangedAfterLoad(false),
 FEChangedAfterLoad(false), RevertedTokenID(false), OutOfDate(false),
-IsModulesImport(false), IsMangledOpenMPVariantName(false) {}
+IsModulesImport(false), IsMangledOpenMPVariantName(false),
+IsLiteralOperatorWithoutWhitespace(false) {}
 
 public:
   IdentifierInfo(const IdentifierInfo &) = delete;
@@ -378,6 +382,16 @@
   /// Set whether this is the mangled name of an OpenMP variant.
   void setMangledOpenMPVariantName(bool I) { IsMangledOpenMPVariantName = I; }
 
+  /// Determine whether this is a literal operator without whitespace
+  bool isLiteralOperatorWithoutWhitespace() const {
+return IsLiteralOperatorWithoutWhitespace;
+  }
+
+  /// Set whether this is a literal operator without whitespace.
+  void setLiteralOperatorWithoutWhitespace(bool I) {
+IsLiteralOperatorWithoutWhitespace = I;
+  }
+
   /// Return true if this identifier is an editor placeholder.
   ///
   /// Editor placeholders are produced by the code-completion engine and are


Index: clang/test/Sema/reserved-identifier.cpp
===
--- clang/test/Sema/reserved-identifier.cpp
+++ clang/test/Sema/reserved-identifier.cpp
@@ -81,6 +81,11 @@
   return 0.;
 }
 
+long double operator""_SacreBleue(long double) // no-warning
+{
+  return 0.;
+}
+
 struct _BarbeRouge { // expected-warning {{identifier '_BarbeRouge' is reserved because it starts with '_' followed by a capital letter}

[PATCH] D104300: [analyzer] Handle `std::swap`

2021-06-15 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD created this revision.
RedDocMD added reviewers: NoQ, vsavchenko, teemperor, xazax.hun.
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 patch handles the `std::swap` function specialization
for `std::unique_ptr`. Implemented to be very similar to
how `swap` method is handled


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104300

Files:
  clang/lib/StaticAnalyzer/Checkers/SmartPtr.h
  clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
  clang/test/Analysis/smart-ptr-text-output.cpp

Index: clang/test/Analysis/smart-ptr-text-output.cpp
===
--- clang/test/Analysis/smart-ptr-text-output.cpp
+++ clang/test/Analysis/smart-ptr-text-output.cpp
@@ -76,13 +76,10 @@
   // expected-note@-1{{Dereference of null smart pointer 'P'}}
 }
 
-// FIXME: Fix this test when "std::swap" is modeled seperately.
 void derefOnStdSwappedNullPtr() {
   std::unique_ptr P; // expected-note {{Default constructed smart pointer 'P' is null}}
   std::unique_ptr PNull; // expected-note {{Default constructed smart pointer 'PNull' is null}}
-  std::swap(P, PNull); // expected-note@Inputs/system-header-simulator-cxx.h:979 {{Swapped null smart pointer 'PNull' with smart pointer 'P'}}
-  // expected-note@-1 {{Calling 'swap'}}
-  // expected-note@-2 {{Returning from 'swap'}}
+  std::swap(P, PNull);  // expected-note {{Swapped null smart pointer 'PNull' with smart pointer 'P'}}
   P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
   // expected-note@-1{{Dereference of null smart pointer 'P'}}
 }
Index: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
+++ clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
@@ -76,6 +76,7 @@
   {{"release"}, &SmartPtrModeling::handleRelease},
   {{"swap", 1}, &SmartPtrModeling::handleSwap},
   {{"get"}, &SmartPtrModeling::handleGet}};
+  const CallDescription StdSwapCall{{"std", "swap"}, 2};
 };
 } // end of anonymous namespace
 
@@ -91,11 +92,15 @@
 return false;
 
   const auto *RecordDecl = MethodDecl->getParent();
-  if (!RecordDecl || !RecordDecl->getDeclContext()->isStdNamespace())
+  return isStdSmartPtr(RecordDecl);
+}
+
+bool isStdSmartPtr(const CXXRecordDecl *RD) {
+  if (!RD || !RD->getDeclContext()->isStdNamespace())
 return false;
 
-  if (RecordDecl->getDeclName().isIdentifier()) {
-StringRef Name = RecordDecl->getName();
+  if (RD->getDeclName().isIdentifier()) {
+StringRef Name = RD->getName();
 return Name == "shared_ptr" || Name == "unique_ptr" || Name == "weak_ptr";
   }
   return false;
@@ -178,6 +183,49 @@
 bool SmartPtrModeling::evalCall(const CallEvent &Call,
 CheckerContext &C) const {
   ProgramStateRef State = C.getState();
+
+  if (Call.isCalled(StdSwapCall)) {
+// Check the first arg, if it is of std::unique_ptr type.
+assert(Call.getNumArgs() == 2 && "std::swap should have two arguments");
+const Expr *FirstArg = Call.getArgExpr(0);
+if (!smartptr::isStdSmartPtr(FirstArg->getType()->getAsCXXRecordDecl())) {
+  return false;
+}
+const MemRegion *FirstArgThisRegion = Call.getArgSVal(0).getAsRegion();
+if (!FirstArgThisRegion)
+  return false;
+const MemRegion *SecondArgThisRegion = Call.getArgSVal(1).getAsRegion();
+if (!SecondArgThisRegion)
+  return false;
+
+const auto *FirstArgInnerPtrVal =
+State->get(FirstArgThisRegion);
+const auto *SecondArgInnerPtrVal =
+State->get(SecondArgThisRegion);
+
+State =
+updateSwappedRegion(State, FirstArgThisRegion, SecondArgInnerPtrVal);
+State =
+updateSwappedRegion(State, SecondArgThisRegion, FirstArgInnerPtrVal);
+
+// TODO: This thing needs a proper note!!
+C.addTransition(
+State,
+C.getNoteTag([FirstArgThisRegion, SecondArgThisRegion](
+ PathSensitiveBugReport &BR, llvm::raw_ostream &OS) {
+  if (&BR.getBugType() != smartptr::getNullDereferenceBugType() ||
+  !BR.isInteresting(FirstArgThisRegion))
+return;
+  BR.markInteresting(SecondArgThisRegion);
+  OS << "Swapped null smart pointer";
+  checkAndPrettyPrintRegion(OS, SecondArgThisRegion);
+  OS << " with smart pointer";
+  checkAndPrettyPrintRegion(OS, FirstArgThisRegion);
+}));
+
+return true;
+  }
+
   if (!smartptr::isStdSmartPtrCall(Call))
 return false;
 
Index: clang/lib/StaticAnalyzer/Checkers/SmartPtr.h
===
--- clang/

[PATCH] D104299: Handle interactions between reserved identifier and user-defined suffixes

2021-06-15 Thread serge via Phabricator via cfe-commits
serge-sans-paille updated this revision to Diff 352146.

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

https://reviews.llvm.org/D104299

Files:
  clang/include/clang/Basic/IdentifierTable.h
  clang/lib/Basic/IdentifierTable.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/test/Sema/reserved-identifier.cpp


Index: clang/test/Sema/reserved-identifier.cpp
===
--- clang/test/Sema/reserved-identifier.cpp
+++ clang/test/Sema/reserved-identifier.cpp
@@ -81,6 +81,11 @@
   return 0.;
 }
 
+long double operator""_SacreBleue(long double) // no-warning
+{
+  return 0.;
+}
+
 struct _BarbeRouge { // expected-warning {{identifier '_BarbeRouge' is 
reserved because it starts with '_' followed by a capital letter}}
 } p;
 struct _BarbeNoire { // expected-warning {{identifier '_BarbeNoire' is 
reserved because it starts with '_' followed by a capital letter}}
Index: clang/lib/Parse/ParseExprCXX.cpp
===
--- clang/lib/Parse/ParseExprCXX.cpp
+++ clang/lib/Parse/ParseExprCXX.cpp
@@ -2644,6 +2644,7 @@
 Lexer::AdvanceToTokenCharacter(TokLocs[Literal.getUDSuffixToken()],
Literal.getUDSuffixOffset(),
PP.getSourceManager(), getLangOpts());
+  II->setLiteralOperatorWithoutWhitespace(true);
 } else if (Tok.is(tok::identifier)) {
   II = Tok.getIdentifierInfo();
   SuffixLoc = ConsumeToken();
Index: clang/lib/Basic/IdentifierTable.cpp
===
--- clang/lib/Basic/IdentifierTable.cpp
+++ clang/lib/Basic/IdentifierTable.cpp
@@ -285,6 +285,10 @@
   if (Name.size() <= 1)
 return ReservedIdentifierStatus::NotReserved;
 
+  // [over.literal] p8
+  if(isLiteralOperatorWithoutWhitespace())
+return ReservedIdentifierStatus::NotReserved;
+
   // [lex.name] p3
   if (Name[0] == '_') {
 
Index: clang/include/clang/Basic/IdentifierTable.h
===
--- clang/include/clang/Basic/IdentifierTable.h
+++ clang/include/clang/Basic/IdentifierTable.h
@@ -121,7 +121,10 @@
   // True if this is a mangled OpenMP variant name.
   unsigned IsMangledOpenMPVariantName : 1;
 
-  // 28 bits left in a 64-bit word.
+  // True if this identifier is a literal operator without whitespace.
+  unsigned IsLiteralOperatorWithoutWhitespace : 1;
+
+  // 27 bits left in a 64-bit word.
 
   // Managed by the language front-end.
   void *FETokenInfo = nullptr;
@@ -134,7 +137,8 @@
 IsPoisoned(false), IsCPPOperatorKeyword(false),
 NeedsHandleIdentifier(false), IsFromAST(false), 
ChangedAfterLoad(false),
 FEChangedAfterLoad(false), RevertedTokenID(false), OutOfDate(false),
-IsModulesImport(false), IsMangledOpenMPVariantName(false) {}
+IsModulesImport(false), IsMangledOpenMPVariantName(false),
+IsLiteralOperatorWithoutWhitespace(false) {}
 
 public:
   IdentifierInfo(const IdentifierInfo &) = delete;
@@ -378,6 +382,16 @@
   /// Set whether this is the mangled name of an OpenMP variant.
   void setMangledOpenMPVariantName(bool I) { IsMangledOpenMPVariantName = I; }
 
+  /// Determine whether this is a literal operator without whitespace
+  bool isLiteralOperatorWithoutWhitespace() const {
+return IsLiteralOperatorWithoutWhitespace;
+  }
+
+  /// Set whether this is a literal operator without whitespace.
+  void setLiteralOperatorWithoutWhitespace(bool I) {
+IsLiteralOperatorWithoutWhitespace = I;
+  }
+
   /// Return true if this identifier is an editor placeholder.
   ///
   /// Editor placeholders are produced by the code-completion engine and are


Index: clang/test/Sema/reserved-identifier.cpp
===
--- clang/test/Sema/reserved-identifier.cpp
+++ clang/test/Sema/reserved-identifier.cpp
@@ -81,6 +81,11 @@
   return 0.;
 }
 
+long double operator""_SacreBleue(long double) // no-warning
+{
+  return 0.;
+}
+
 struct _BarbeRouge { // expected-warning {{identifier '_BarbeRouge' is reserved because it starts with '_' followed by a capital letter}}
 } p;
 struct _BarbeNoire { // expected-warning {{identifier '_BarbeNoire' is reserved because it starts with '_' followed by a capital letter}}
Index: clang/lib/Parse/ParseExprCXX.cpp
===
--- clang/lib/Parse/ParseExprCXX.cpp
+++ clang/lib/Parse/ParseExprCXX.cpp
@@ -2644,6 +2644,7 @@
 Lexer::AdvanceToTokenCharacter(TokLocs[Literal.getUDSuffixToken()],
Literal.getUDSuffixOffset(),
PP.getSourceManager(), getLangOpts());
+  II->setLiteralOperatorWithoutWhitespace(true);
 } else if (Tok.is(tok::identifier)) {
   II = Tok.getIdentifierInfo();
   SuffixLoc = ConsumeToken();
Index: clang/lib/Basic/

[PATCH] D104300: [analyzer] Handle `std::swap`

2021-06-15 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD added a comment.

I am not entirely satisfied with the note that is being emitted currently from 
the `std::swap` handling (its ripped off from the note emitted for 
`std::unique_ptr::swap`).
Any suggestions?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104300

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


[PATCH] D104300: [analyzer] Handle `std::swap`

2021-06-15 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:94-103
   const auto *RecordDecl = MethodDecl->getParent();
-  if (!RecordDecl || !RecordDecl->getDeclContext()->isStdNamespace())
+  return isStdSmartPtr(RecordDecl);
+}
+
+bool isStdSmartPtr(const CXXRecordDecl *RD) {
+  if (!RD || !RD->getDeclContext()->isStdNamespace())
 return false;

That's great!



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:188-226
+// Check the first arg, if it is of std::unique_ptr type.
+assert(Call.getNumArgs() == 2 && "std::swap should have two arguments");
+const Expr *FirstArg = Call.getArgExpr(0);
+if (!smartptr::isStdSmartPtr(FirstArg->getType()->getAsCXXRecordDecl())) {
+  return false;
+}
+const MemRegion *FirstArgThisRegion = Call.getArgSVal(0).getAsRegion();

Maybe a separate method then?



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:217
+  if (&BR.getBugType() != smartptr::getNullDereferenceBugType() ||
+  !BR.isInteresting(FirstArgThisRegion))
+return;

Wait, and what if the second argument is interesting?



Comment at: clang/test/Analysis/smart-ptr-text-output.cpp:80
 void derefOnStdSwappedNullPtr() {
   std::unique_ptr P; // expected-note {{Default constructed smart pointer 
'P' is null}}
   std::unique_ptr PNull; // expected-note {{Default constructed smart 
pointer 'PNull' is null}}

I know that this case existed before, but can we initialize `P` with non-null, 
so that the warning is a bit more life-like?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104300

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


[PATCH] D104300: [analyzer] Handle `std::swap`

2021-06-15 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko added a comment.

It looks like new functionality is VERY much like `handleSwap`, and we should 
definitely merge common parts.

Also, I think that commit title should be more specific than "Handle 
std::swap".  It should at least mention the checker.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104300

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


[PATCH] D104155: Add documentation for -fsanitize-address-use-after-return.

2021-06-15 Thread Kevin Athey via Phabricator via cfe-commits
kda updated this revision to Diff 352153.
kda added a comment.

- attempting to make documentation pretty.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104155

Files:
  clang/docs/AddressSanitizer.rst
  clang/docs/ClangCommandLineReference.rst


Index: clang/docs/ClangCommandLineReference.rst
===
--- clang/docs/ClangCommandLineReference.rst
+++ clang/docs/ClangCommandLineReference.rst
@@ -881,6 +881,15 @@
 * ``global`` - Emit module destructors that are called via a platform specific 
array (see `llvm.global_dtors`).
 * ``none`` - Do not emit module destructors.
 
+.. option:: -fsanitize-address-use-after-return=
+
+Select the enabling method of detecting stack use-after-return in 
AddressSanitizer.
+
+Valid options are:
+* ``always`` - Detect use-after-return.
+* ``runtime`` - Detect use-after-return with runtime ON/OFF switch 
(environment variable `ASAN_OPTIONS=detect_stack_use_after_return=1`, default: 
0)
+* ``never`` - Do not detect use-after-return.
+
 .. option:: -fsanitize-ignorelist=
 
 Path to ignorelist file for sanitizers
Index: clang/docs/AddressSanitizer.rst
===
--- clang/docs/AddressSanitizer.rst
+++ clang/docs/AddressSanitizer.rst
@@ -14,8 +14,9 @@
 
 * Out-of-bounds accesses to heap, stack and globals
 * Use-after-free
-* Use-after-return (runtime flag 
`ASAN_OPTIONS=detect_stack_use_after_return=1`)
-* Use-after-scope (clang flag `-fsanitize-address-use-after-scope`)
+* Use-after-return (clang flag 
``-fsanitize-address-use-after-return=(always|runtime|never)`` default: 
``runtime``)
+* Enable ``runtime`` with: ``ASAN_OPTIONS=detect_stack_use_after_return=1``
+* Use-after-scope (clang flag ``-fsanitize-address-use-after-scope``)
 * Double-free, invalid free
 * Memory leaks (experimental)
 


Index: clang/docs/ClangCommandLineReference.rst
===
--- clang/docs/ClangCommandLineReference.rst
+++ clang/docs/ClangCommandLineReference.rst
@@ -881,6 +881,15 @@
 * ``global`` - Emit module destructors that are called via a platform specific array (see `llvm.global_dtors`).
 * ``none`` - Do not emit module destructors.
 
+.. option:: -fsanitize-address-use-after-return=
+
+Select the enabling method of detecting stack use-after-return in AddressSanitizer.
+
+Valid options are:
+* ``always`` - Detect use-after-return.
+* ``runtime`` - Detect use-after-return with runtime ON/OFF switch (environment variable `ASAN_OPTIONS=detect_stack_use_after_return=1`, default: 0)
+* ``never`` - Do not detect use-after-return.
+
 .. option:: -fsanitize-ignorelist=
 
 Path to ignorelist file for sanitizers
Index: clang/docs/AddressSanitizer.rst
===
--- clang/docs/AddressSanitizer.rst
+++ clang/docs/AddressSanitizer.rst
@@ -14,8 +14,9 @@
 
 * Out-of-bounds accesses to heap, stack and globals
 * Use-after-free
-* Use-after-return (runtime flag `ASAN_OPTIONS=detect_stack_use_after_return=1`)
-* Use-after-scope (clang flag `-fsanitize-address-use-after-scope`)
+* Use-after-return (clang flag ``-fsanitize-address-use-after-return=(always|runtime|never)`` default: ``runtime``)
+* Enable ``runtime`` with: ``ASAN_OPTIONS=detect_stack_use_after_return=1``
+* Use-after-scope (clang flag ``-fsanitize-address-use-after-scope``)
 * Double-free, invalid free
 * Memory leaks (experimental)
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104295: removes redundant test

2021-06-15 Thread Fred Grim via Phabricator via cfe-commits
feg208 added a comment.

If I could get someone to land this commit on my behalf I'd be obliged. I am 
working on the getting commit rights since that seems to be a pretty 
significant impediment to developing in llvm land but as of now I can't land 
this myself.

name: Fred Grim
email: fg...@apple.com


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104295

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


[PATCH] D104305: [flang][driver] Add `-fdebug-dump-all`

2021-06-15 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski created this revision.
Herald added a reviewer: sscalpone.
Herald added a subscriber: dang.
awarzynski requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The new option will run the semantic checks and then dump the parse tree
and all the symbols. This is equivalent to running the driver twice,
once with `-fdebug-dump-parse-tree` and then with
the `-fdebug-dump-symbols` action flag.

Currently we wouldn't be able to achieve the same by simply running:

  flang-new -fc1 -fdebug-dump-parse-tree -fdebug-dump-symbols 

That's because the new driver will only run one frontend action per
invocation (both of the flags used here are action flags). Diverging
from this design would lead to costly compromises and it's best avoided.

We may want to consider re-designing our debugging actions (and action
options) in the future so that there's more code re-use. For now, I'm
focusing on making sure that we support all the major cases requested by
our users.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104305

Files:
  clang/include/clang/Driver/Options.td
  flang/include/flang/Frontend/FrontendActions.h
  flang/include/flang/Frontend/FrontendOptions.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  flang/test/Driver/driver-help.f90

Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -69,6 +69,7 @@
 ! HELP-FC1-NEXT: -falternative-parameter-statement
 ! HELP-FC1-NEXT: Enable the old style PARAMETER statement
 ! HELP-FC1-NEXT: -fbackslashSpecify that backslash in string introduces an escape character
+! HELP-FC1-NEXT: -fdebug-dump-all   Dump symbols and the parse tree after the semantic checks
 ! HELP-FC1-NEXT: -fdebug-dump-parse-tree-no-sema
 ! HELP-FC1-NEXT:Dump the parse tree (skips the semantic checks)
 ! HELP-FC1-NEXT: -fdebug-dump-parse-tree Dump the parse tree
Index: flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
===
--- flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -55,6 +55,9 @@
   case DebugDumpParseTreeNoSema:
 return std::make_unique();
 break;
+  case DebugDumpAll:
+return std::make_unique();
+break;
   case DebugDumpProvenance:
 return std::make_unique();
 break;
Index: flang/lib/Frontend/FrontendActions.cpp
===
--- flang/lib/Frontend/FrontendActions.cpp
+++ flang/lib/Frontend/FrontendActions.cpp
@@ -305,6 +305,42 @@
   semantics.DumpSymbols(llvm::outs());
 }
 
+void DebugDumpAllAction::ExecuteAction() {
+  CompilerInstance &ci = this->instance();
+
+  // Dump parse tree
+  auto &parseTree{instance().parsing().parseTree()};
+  Fortran::parser::AnalyzedObjectsAsFortran asFortran =
+  Fortran::frontend::getBasicAsFortran();
+  llvm::outs() << "";
+  llvm::outs() << " Flang: parse tree dump ";
+  llvm::outs() << "\n";
+  Fortran::parser::DumpTree(llvm::outs(), parseTree, &asFortran);
+
+  auto &semantics = this->semantics();
+  auto tables{Fortran::semantics::BuildRuntimeDerivedTypeTables(
+  instance().invocation().semanticsContext())};
+  // The runtime derived type information table builder may find and report
+  // semantic errors. So it is important that we report them _after_
+  // BuildRuntimeDerivedTypeTables is run.
+  reportFatalSemanticErrors(
+  semantics, this->instance().diagnostics(), GetCurrentFileOrBufferName());
+
+  if (!tables.schemata) {
+unsigned DiagID =
+ci.diagnostics().getCustomDiagID(clang::DiagnosticsEngine::Error,
+"could not find module file for __fortran_type_info");
+ci.diagnostics().Report(DiagID);
+llvm::errs() << "\n";
+  }
+
+  // Dump symbols
+  llvm::outs() << "=";
+  llvm::outs() << " Flang: symbols dump ";
+  llvm::outs() << "=\n";
+  semantics.DumpSymbols(llvm::outs());
+}
+
 void DebugDumpParseTreeNoSemaAction::ExecuteAction() {
   auto &parseTree{instance().parsing().parseTree()};
   Fortran::parser::AnalyzedObjectsAsFortran asFortran =
Index: flang/lib/Frontend/CompilerInvocation.cpp
===
--- flang/lib/Frontend/CompilerInvocation.cpp
+++ flang/lib/Frontend/CompilerInvocation.cpp
@@ -141,6 +141,9 @@
 case clang::driver::options::OPT_fdebug_dump_parse_tree:
   opts.programAction_ = DebugDumpParseTree;
   break;
+case clang::driver::options::OPT_fdebug_dump_all:
+  opts.programAction_ = DebugDumpAll;
+  break;
 case clang::driver::options::OPT_fdebug_dump_parse_tree_no_sema:
 

[PATCH] D104222: [clang-format] [PR50702] Lamdba processing does not respect AfterClass and AfterNamespace

2021-06-15 Thread Francois JEAN via Phabricator via cfe-commits
Wawha added a comment.

In D104222#2819422 , @MyDeveloperDay 
wrote:

> Add some of the failing cases identified by @Wawha

Thank for the fix. I test and discover a new case with a regression:

auto createObj = [this] -> std::unique_ptr
{
  return std::make_unique();
};

Like & and * a template return ending with > is not handle.


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

https://reviews.llvm.org/D104222

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


[PATCH] D99005: [clang] Implement P2266 Simpler implicit move

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

@sberg: Thanks for the example! @mizvekov's comments are correct, but I wanted 
to put some more comments here for posterity. (I'll also try to find a place 
for this real-world example in the next revision of p2266 
.)

The code in question is `o3tl::temporary`, documented as "Cast an rvalue to an 
lvalue." and implemented as `template T& temporary(T&& x) { return x; 
}`
https://docs.libreoffice.org/o3tl/html/temporary_8hxx_source.html
p2266 proposes to break this code in C++23, by making the expression `x` an 
xvalue. EWG was well aware that p2266 would break this exact kind of 
"laundering" function, which takes an rvalue and launders it into an lvalue 
without a cast. This breakage was generally (though I'm sure not universally) 
seen as a good thing. We weren't aware of any specific real-world examples of 
such "laundering" functions, though, so this is very useful info.
As Matheus says, the best way to fix the code is to add an explicit cast: 
`return static_cast(x);`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99005

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


[clang] a6948da - DirectoryWatcher: close a possible window of race on Windows

2021-06-15 Thread Saleem Abdulrasool via cfe-commits

Author: Saleem Abdulrasool
Date: 2021-06-15T09:15:17-07:00
New Revision: a6948da86ad7e78d66b26263c2681ef6385cc234

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

LOG: DirectoryWatcher: close a possible window of race on Windows

The initial scan occurring before the watcher is ready allows a race
condition where a change occurs before the initial scan completes.
Ensure that we wait for the watcher to begin executing the initial scan.

Addresses some feedback from Adrian McCarthy in post-commit review.

Added: 


Modified: 
clang/lib/DirectoryWatcher/windows/DirectoryWatcher-windows.cpp

Removed: 




diff  --git a/clang/lib/DirectoryWatcher/windows/DirectoryWatcher-windows.cpp 
b/clang/lib/DirectoryWatcher/windows/DirectoryWatcher-windows.cpp
index 847d20bfbb6f..8a4f5a87d967 100644
--- a/clang/lib/DirectoryWatcher/windows/DirectoryWatcher-windows.cpp
+++ b/clang/lib/DirectoryWatcher/windows/DirectoryWatcher-windows.cpp
@@ -133,6 +133,9 @@ DirectoryWatcherWindows::~DirectoryWatcherWindows() {
 }
 
 void DirectoryWatcherWindows::InitialScan() {
+  std::unique_lock lock(Mutex);
+  Ready.wait(lock, [this] { return this->WatcherActive; });
+
   Callback(getAsFileEvents(scanDirectory(Path.data())), /*IsInitial=*/true);
 }
 



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


[clang] e32a92c - Remove unnecessary triple from test

2021-06-15 Thread Reid Kleckner via cfe-commits

Author: Yuki Okushi
Date: 2021-06-15T09:49:45-07:00
New Revision: e32a92c6fe8e6dd8ca08b44be12eda6d88c2eaed

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

LOG: Remove unnecessary triple from test

PR27098(https://bugs.llvm.org/show_bug.cgi?id=27098) has been fixed so
the avoidance seems unnecessary.

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

Added: 


Modified: 
clang/test/CXX/dcl.decl/dcl.init/dcl.init.list/p3.cpp

Removed: 




diff  --git a/clang/test/CXX/dcl.decl/dcl.init/dcl.init.list/p3.cpp 
b/clang/test/CXX/dcl.decl/dcl.init/dcl.init.list/p3.cpp
index e185e8fc12263..6e39bdd2429dd 100644
--- a/clang/test/CXX/dcl.decl/dcl.init/dcl.init.list/p3.cpp
+++ b/clang/test/CXX/dcl.decl/dcl.init/dcl.init.list/p3.cpp
@@ -1,7 +1,6 @@
 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
 // RUN: %clang_cc1 -std=c++14 -fsyntax-only -verify %s
-// FIXME: Remove the triple when PR27098 is fixed.
-// RUN: %clang_cc1 -std=c++1z -fsyntax-only -verify %s -triple 
%itanium_abi_triple
+// RUN: %clang_cc1 -std=c++1z -fsyntax-only -verify %s
 
 namespace std {
   typedef decltype(sizeof(int)) size_t;



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


[PATCH] D68891: Remove unnecessary triple from test

2021-06-15 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

lgtm


Repository:
  rC Clang

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

https://reviews.llvm.org/D68891

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


[PATCH] D68891: Remove unnecessary triple from test

2021-06-15 Thread Reid Kleckner via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe32a92c6fe8e: Remove unnecessary triple from test (authored 
by JohnTitor, committed by rnk).

Changed prior to commit:
  https://reviews.llvm.org/D68891?vs=224680&id=352167#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68891

Files:
  clang/test/CXX/dcl.decl/dcl.init/dcl.init.list/p3.cpp


Index: clang/test/CXX/dcl.decl/dcl.init/dcl.init.list/p3.cpp
===
--- clang/test/CXX/dcl.decl/dcl.init/dcl.init.list/p3.cpp
+++ clang/test/CXX/dcl.decl/dcl.init/dcl.init.list/p3.cpp
@@ -1,7 +1,6 @@
 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
 // RUN: %clang_cc1 -std=c++14 -fsyntax-only -verify %s
-// FIXME: Remove the triple when PR27098 is fixed.
-// RUN: %clang_cc1 -std=c++1z -fsyntax-only -verify %s -triple 
%itanium_abi_triple
+// RUN: %clang_cc1 -std=c++1z -fsyntax-only -verify %s
 
 namespace std {
   typedef decltype(sizeof(int)) size_t;


Index: clang/test/CXX/dcl.decl/dcl.init/dcl.init.list/p3.cpp
===
--- clang/test/CXX/dcl.decl/dcl.init/dcl.init.list/p3.cpp
+++ clang/test/CXX/dcl.decl/dcl.init/dcl.init.list/p3.cpp
@@ -1,7 +1,6 @@
 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
 // RUN: %clang_cc1 -std=c++14 -fsyntax-only -verify %s
-// FIXME: Remove the triple when PR27098 is fixed.
-// RUN: %clang_cc1 -std=c++1z -fsyntax-only -verify %s -triple %itanium_abi_triple
+// RUN: %clang_cc1 -std=c++1z -fsyntax-only -verify %s
 
 namespace std {
   typedef decltype(sizeof(int)) size_t;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104279: [asan] Remove Asan, Ubsan support of RTEMS and Myriad

2021-06-15 Thread Matt Morehouse via Phabricator via cfe-commits
morehouse accepted this revision.
morehouse 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/D104279/new/

https://reviews.llvm.org/D104279

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


[PATCH] D104311: [clang] Fix a race condition in the build of clangInterpreter

2021-06-15 Thread Stella Stamenova via Phabricator via cfe-commits
stella.stamenova created this revision.
stella.stamenova added a reviewer: v.g.vassilev.
Herald added a subscriber: mgorny.
stella.stamenova requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The library depends on Attributes.inc, so it has to depend on the 
intrinsics_gen target


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104311

Files:
  clang/lib/Interpreter/CMakeLists.txt


Index: clang/lib/Interpreter/CMakeLists.txt
===
--- clang/lib/Interpreter/CMakeLists.txt
+++ clang/lib/Interpreter/CMakeLists.txt
@@ -12,6 +12,9 @@
   IncrementalParser.cpp
   Interpreter.cpp
 
+  DEPENDS
+  intrinsics_gen
+
   LINK_LIBS
   clangAST
   clangAnalysis


Index: clang/lib/Interpreter/CMakeLists.txt
===
--- clang/lib/Interpreter/CMakeLists.txt
+++ clang/lib/Interpreter/CMakeLists.txt
@@ -12,6 +12,9 @@
   IncrementalParser.cpp
   Interpreter.cpp
 
+  DEPENDS
+  intrinsics_gen
+
   LINK_LIBS
   clangAST
   clangAnalysis
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D104099: [NewPM] Remove SpeculateAroundPHIs pass from pipeline

2021-06-15 Thread Wei Mi via cfe-commits
On Mon, Jun 14, 2021 at 4:52 PM Wei Mi  wrote:

>
>
> On Mon, Jun 14, 2021 at 4:04 PM Xinliang David Li 
> wrote:
>
>>
>>
>> On Mon, Jun 14, 2021 at 3:59 PM Roman Lebedev via Phabricator <
>> revi...@reviews.llvm.org> wrote:
>>
>>> lebedev.ri added a subscriber: MaskRay.
>>> lebedev.ri added a comment.
>>>
>>> In D104099#2815531 , @wenlei
>>> wrote:
>>>
>>> > In D104099#2814167 ,
>>> @davidxl wrote:
>>> >
>>> >> Adding Wei to help measure performance impact on our internal
>>> workloads.  Also add Wenlei to help measure impact with FB's workloads.
>>> >
>>> > Measured perf using FB internal workload w/ and w/o this pass, result
>>> is neutral.
>>>
>>> Thank you for checking!
>>>
>>> So far, it seems the reaction to this proposal has been overwhelmingly
>>> positive.
>>> Does anyone else wish to chime in? Should i land this? @asbirlea
>>> @MaskRay ?
>>>
>>
>> Wei is doing more measurement @google. Please wait for the response.
>>
>> David
>>
>
> Start doing the test. Will report back.
>
> Wei.
>

No performance change found in google internal benchmarks.

 Wei.


>
>
>>
>>
>>>
>>> Repository:
>>>   rG LLVM Github Monorepo
>>>
>>> CHANGES SINCE LAST ACTION
>>>   https://reviews.llvm.org/D104099/new/
>>>
>>> https://reviews.llvm.org/D104099
>>>
>>>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104279: [asan] Remove Asan, Ubsan support of RTEMS and Myriad

2021-06-15 Thread Walter Lee via Phabricator via cfe-commits
waltl added inline comments.



Comment at: clang/lib/Driver/ToolChains/CommonArgs.cpp:761
+  // There's no libpthread or librt on Android.
+  if (!TC.getTriple().isAndroid()) {
 CmdArgs.push_back("-lpthread");

Just to be super cautious, can be keep this line and the one below in regard to 
libdl below?  RTEMS is an open source project so it's conceivable that someone 
may be using clang for it.




Comment at: clang/lib/Driver/ToolChains/CommonArgs.cpp:769
   if (!TC.getTriple().isOSFreeBSD() && !TC.getTriple().isOSNetBSD() &&
-  !TC.getTriple().isOSOpenBSD() &&
-  TC.getTriple().getOS() != llvm::Triple::RTEMS)
+  !TC.getTriple().isOSOpenBSD())
 CmdArgs.push_back("-ldl");

Ditto.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104279

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


[PATCH] D104305: [flang][driver] Add `-fdebug-dump-all`

2021-06-15 Thread Pete Steinfeld via Phabricator via cfe-commits
PeteSteinfeld added a comment.

Thanks for doing this.  These changes look good, but I can't get them to build 
successfully.  I'm using the GNU 9.3 C++ compiler.  My build fails to link the 
bin/flang-new executable.  Here's an excerpt of the error messages:

  [4436/4439] Generating ../../../../include/flang/iso_fortran_env.f18.mod
  [4437/4439] Linking CXX executable bin/flang-new
  FAILED: bin/flang-new 
  : && /home/sw/thirdparty/gcc/gcc-9.3.0/linux86-64/bin/g++ -fPIC 
-fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Wall 
-Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual 
-Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough 
-Wno-maybe-uninitialized -Wno-class-memaccess -Wno-redundant-move 
-Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor 
-Wsuggest-override -Wno-comment -Wmisleading-indentation -fdiagnostics-color 
-ffunction-sections -fdata-sections -Werror -Wno-deprecated-copy 
-fno-strict-aliasing -fno-semantic-interposition -O3 -DNDEBUG 
-Wl,-rpath,/home/sw/thirdparty/gcc/gcc-9.3.0/linux86-64/lib64:/usr/local/lib:/home/sw/envmod/modules/linux86-64/latest/lib:
 -Wl,-rpath-link,/local/home/psteinfeld/main/tot/build/./lib  -Wl,-O3 
-Wl,--gc-sections 
tools/flang/tools/flang-driver/CMakeFiles/flang-new.dir/driver.cpp.o 
tools/flang/tools/flang-driver/CMakeFiles/flang-new.dir/fc1_main.cpp.o -o 
bin/flang-new -L/local/home/psteinfeld/main/tot/build/./lib 
-Wl,-rpath,"\$ORIGIN/../lib"  lib/libLLVMX86CodeGen.a  
lib/libLLVMX86AsmParser.a  lib/libLLVMX86Desc.a  lib/libLLVMX86Disassembler.a  
lib/libLLVMX86Info.a  lib/libLLVMOption.a  lib/libLLVMSupport.a  -lpthread  
lib/libflangFrontend.a  lib/libflangFrontendTool.a  lib/libclangDriver.a  
lib/libclangBasic.a  lib/libLLVMGlobalISel.a  lib/libLLVMSelectionDAG.a  
lib/libLLVMCFGuard.a  lib/libLLVMMCDisassembler.a  lib/libflangFrontend.a  
lib/libFortranLower.a  lib/libFortranSemantics.a  lib/libFortranEvaluate.a  
lib/libFortranParser.a  lib/libFortranDecimal.a  lib/libFortranCommon.a  
lib/libFIROptimizer.a  lib/libLLVMAsmPrinter.a  lib/libLLVMCodeGen.a  
lib/libLLVMScalarOpts.a  lib/libLLVMAggressiveInstCombine.a  
lib/libLLVMInstCombine.a  lib/libLLVMTarget.a  lib/libLLVMDebugInfoDWARF.a  
lib/libLLVMDebugInfoMSF.a  lib/libMLIRAffineTransforms.a  
lib/libMLIRAsyncTransforms.a  lib/libMLIRGPU.a  lib/libMLIRAsync.a  
lib/libMLIRDLTI.a  lib/libMLIRLLVMToLLVMIRTranslation.a  lib/libMLIRNVVMIR.a  
lib/libMLIRROCDLIR.a  lib/libMLIRVectorToLLVM.a  lib/libMLIRArmNeon.a  
lib/libMLIRArmSVETransforms.a  lib/libMLIRArmSVE.a  lib/libMLIRAMXTransforms.a  
lib/libMLIRAMX.a  lib/libMLIRTargetLLVMIRExport.a  
lib/libMLIRLLVMIRTransforms.a  lib/libMLIRTranslation.a  
lib/libMLIRMathTransforms.a  lib/libMLIRMemRefTransforms.a  
lib/libMLIROpenACC.a  lib/libMLIROpenMP.a  lib/libMLIRSDBM.a  
lib/libMLIRShapeOpsTransforms.a  lib/libMLIRShape.a  
lib/libMLIRSparseTensorTransforms.a  lib/libMLIRLinalgTransforms.a  
lib/libMLIRComplex.a  lib/libMLIRLinalgAnalysis.a  lib/libMLIRLinalgUtils.a  
lib/libMLIRSCFTransforms.a  lib/libMLIRVectorToSCF.a  lib/libMLIRSparseTensor.a 
 lib/libMLIRSPIRVModuleCombiner.a  lib/libMLIRSPIRVTransforms.a  
lib/libMLIRSPIRVConversion.a  lib/libMLIRSPIRVUtils.a  lib/libMLIRSPIRV.a  
lib/libMLIRStandardOpsTransforms.a  lib/libMLIRTensorTransforms.a  
lib/libMLIRTosaTransforms.a  lib/libMLIRX86VectorTransforms.a  
lib/libMLIRX86Vector.a  lib/libMLIRStandardToLLVM.a  lib/libMLIRLLVMIR.a  
lib/libLLVMBitWriter.a  lib/libLLVMAsmParser.a  lib/libMLIRMath.a  
lib/libMLIRTosaTestPasses.a  lib/libMLIRTosa.a  lib/libMLIRQuant.a  
lib/libMLIRAffineToStandard.a  lib/libMLIRSCFToStandard.a  
lib/libMLIRTransforms.a  lib/libMLIRVector.a  lib/libMLIRAffineUtils.a  
lib/libMLIRTransformUtils.a  lib/libMLIRLoopAnalysis.a  lib/libMLIRPresburger.a 
 lib/libMLIRRewrite.a  lib/libMLIRPDLToPDLInterp.a  lib/libMLIRPDLInterp.a  
lib/libMLIRPDL.a  lib/libMLIRPass.a  lib/libMLIRAnalysis.a  lib/libMLIRLinalg.a 
 lib/libMLIRAffine.a  lib/libMLIRDialectUtils.a  lib/libMLIRParser.a  
lib/libMLIRSCF.a  lib/libMLIRMemRef.a  lib/libMLIRMemRefUtils.a  
lib/libMLIRDialect.a  lib/libMLIRStandard.a  lib/libMLIRTensor.a  
lib/libMLIRViewLikeInterface.a  lib/libMLIRCastInterfaces.a  
lib/libMLIRVectorInterfaces.a  lib/libMLIRLoopLikeInterface.a  
lib/libMLIRSideEffectInterfaces.a  lib/libMLIRDataLayoutInterfaces.a  
lib/libMLIRInferTypeOpInterface.a  lib/libMLIRCallInterfaces.a  
lib/libMLIRControlFlowInterfaces.a  lib/libMLIRCopyOpInterface.a  
lib/libMLIRIR.a  lib/libMLIRSupport.a  lib/libLLVMFrontendOpenACC.a  
lib/libLLVMFrontendOpenMP.a  lib/libLLVMTransformUtils.a  lib/libLLVMAnalysis.a 
 lib/libLLVMObject.a  lib/libLLVMMCParser.a  lib/libLLVMMC.a  
lib/libLLVMDebugInfoCodeView.a  lib/libLLVMBitReader.a  lib/libLLVMTextAPI.a  
lib/libclangDriver.a  lib/libLLVMOption.a  lib/libLLVMProfileData.a  
lib/libLLVMCore.a  lib/libLLVMRemarks.a  lib/libLLVMBitstreamReader.a  
lib/libLLVMBinaryFormat.a  lib/libcl

[PATCH] D104099: [NewPM] Remove SpeculateAroundPHIs pass

2021-06-15 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri updated this revision to Diff 352176.
lebedev.ri retitled this revision from "[NewPM] Remove SpeculateAroundPHIs pass 
from pipeline" to "[NewPM] Remove SpeculateAroundPHIs pass".
lebedev.ri added a comment.
Herald added a subscriber: mgorny.

On Tue, Jun 15, 2021 at 8:14 PM Wei Mi  wrote:

> On Mon, Jun 14, 2021 at 4:52 PM Wei Mi  wrote:
>
>> On Mon, Jun 14, 2021 at 4:04 PM Xinliang David Li  wrote:
>>
>>> On Mon, Jun 14, 2021 at 3:59 PM Roman Lebedev via Phabricator 
>>>  wrote:
>>>
 lebedev.ri added a subscriber: MaskRay.
 lebedev.ri added a comment.

 In D104099#2815531  
 https://reviews.llvm.org/D104099#2815531, @wenlei wrote:

> In D104099#2814167  
> https://reviews.llvm.org/D104099#2814167, @davidxl wrote:
>
>> Adding Wei to help measure performance impact on our internal workloads. 
>>  Also add Wenlei to help measure impact with FB's workloads.
>
> Measured perf using FB internal workload w/ and w/o this pass, result is 
> neutral.

 Thank you for checking!

 So far, it seems the reaction to this proposal has been overwhelmingly 
 positive.
 Does anyone else wish to chime in? Should i land this? @asbirlea @MaskRay ?
>>>
>>> Wei is doing more measurement @google. Please wait for the response.
>>>
>>> David
>>
>> Start doing the test. Will report back.
>>
>> Wei.
>
> No performance change found in google internal benchmarks.
>
>  Wei.

Thanks for checking.
So, so far no one can point out why this pass is beneficial? :]

How about this then?

>>  
>>
 Repository:
   rG  LLVM Github Monorepo

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

 https://reviews.llvm.org/D104099


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104099

Files:
  clang/test/CodeGen/thinlto-distributed-newpm.ll
  llvm/include/llvm/Transforms/Scalar/SpeculateAroundPHIs.h
  llvm/lib/Passes/PassBuilder.cpp
  llvm/lib/Passes/PassRegistry.def
  llvm/lib/Transforms/Scalar/CMakeLists.txt
  llvm/lib/Transforms/Scalar/SpeculateAroundPHIs.cpp
  llvm/test/Other/new-pm-defaults.ll
  llvm/test/Other/new-pm-thinlto-defaults.ll
  llvm/test/Other/new-pm-thinlto-postlink-pgo-defaults.ll
  llvm/test/Other/new-pm-thinlto-postlink-samplepgo-defaults.ll
  llvm/test/Transforms/LoopUnroll/AArch64/runtime-unroll-generic.ll
  
llvm/test/Transforms/PhaseOrdering/AArch64/hoisting-sinking-required-for-vectorization.ll
  llvm/test/Transforms/PhaseOrdering/loop-rotation-vs-common-code-hoisting.ll
  llvm/test/Transforms/SpeculateAroundPHIs/basic-x86.ll
  llvm/test/Transforms/SpeculateAroundPHIs/convergent.ll
  llvm/test/Transforms/SpeculateAroundPHIs/pr42991.ll
  llvm/utils/gn/secondary/llvm/lib/Transforms/Scalar/BUILD.gn

Index: llvm/utils/gn/secondary/llvm/lib/Transforms/Scalar/BUILD.gn
===
--- llvm/utils/gn/secondary/llvm/lib/Transforms/Scalar/BUILD.gn
+++ llvm/utils/gn/secondary/llvm/lib/Transforms/Scalar/BUILD.gn
@@ -83,7 +83,6 @@
 "SimpleLoopUnswitch.cpp",
 "SimplifyCFGPass.cpp",
 "Sink.cpp",
-"SpeculateAroundPHIs.cpp",
 "SpeculativeExecution.cpp",
 "StraightLineStrengthReduce.cpp",
 "StructurizeCFG.cpp",
Index: llvm/test/Transforms/SpeculateAroundPHIs/pr42991.ll
===
--- llvm/test/Transforms/SpeculateAroundPHIs/pr42991.ll
+++ /dev/null
@@ -1,44 +0,0 @@
-; RUN: opt -S -passes=spec-phis %s
-
-; This testcase crashes during the speculate around PHIs pass. The pass however
-; results in no changes.
-
-define i32 @test1() {
-entry:
-  callbr void asm sideeffect "", "X,X,~{dirflag},~{fpsr},~{flags}"(i8* blockaddress(@test1, %return), i8* blockaddress(@test1, %f))
-  to label %asm.fallthrough [label %return, label %f]
-
-asm.fallthrough:
-  br label %return
-
-f:
-  br label %return
-
-return:
-  %retval.0 = phi i32 [ 0, %f ], [ 1, %asm.fallthrough ], [ 1, %entry ]
-  ret i32 %retval.0
-}
-
-define void @test2() {
-entry:
-  br label %tailrecurse
-
-tailrecurse:
-  %call = tail call i32 @test3()
-  %tobool1 = icmp eq i32 %call, 0
-  callbr void asm sideeffect "", "X,X,~{dirflag},~{fpsr},~{flags}"(i8* blockaddress(@test2, %test1.exit), i8* blockaddress(@test2, %f.i))
-  to label %if.end6 [label %test1.exit, label %f.i]
-
-f.i:
-  br label %test1.exit
-
-test1.exit:
-  %retval.0.i = phi i1 [ false, %f.i ], [ true, %tailrecurse ]
-  %brmerge = or i1 %tobool1, %retval.0.i
-  br i1 %brmerge, label %if.end6, label %tailrecurse
-
-if.end6:
-  ret void
-}
-
-declare i32 @test3()
Index: llvm/test/Transforms/SpeculateAroundPHIs/convergent.ll
===
--- llvm/test/Transforms/SpeculateAroundPH

[PATCH] D104099: [NewPM] Remove SpeculateAroundPHIs pass

2021-06-15 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks accepted this revision.
aeubanks added a comment.

looks good, we can always revive the pass later if somebody wants it for some 
reason


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104099

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


[PATCH] D102107: [OpenMP] Codegen aggregate for outlined function captures

2021-06-15 Thread Giorgis Georgakoudis via Phabricator via cfe-commits
ggeorgakoudis updated this revision to Diff 352178.
ggeorgakoudis added a comment.
Herald added a project: OpenMP.
Herald added a subscriber: openmp-commits.

Rebase to NewGlobalization and amend


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102107

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/test/CodeGenCXX/observe-noexcept.cpp
  clang/test/OpenMP/cancel_codegen.cpp
  clang/test/OpenMP/cancellation_point_codegen.cpp
  clang/test/OpenMP/debug-info-complex-byval.cpp
  clang/test/OpenMP/debug-info-openmp-array.cpp
  clang/test/OpenMP/declare_target_codegen_globalization.cpp
  clang/test/OpenMP/distribute_codegen.cpp
  clang/test/OpenMP/distribute_firstprivate_codegen.cpp
  clang/test/OpenMP/distribute_lastprivate_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_firstprivate_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_if_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_lastprivate_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_num_threads_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_private_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_proc_bind_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_reduction_task_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_firstprivate_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_if_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_lastprivate_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_num_threads_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_private_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_proc_bind_codegen.cpp
  clang/test/OpenMP/distribute_private_codegen.cpp
  clang/test/OpenMP/distribute_simd_codegen.cpp
  clang/test/OpenMP/distribute_simd_firstprivate_codegen.cpp
  clang/test/OpenMP/distribute_simd_lastprivate_codegen.cpp
  clang/test/OpenMP/distribute_simd_private_codegen.cpp
  clang/test/OpenMP/distribute_simd_reduction_codegen.cpp
  clang/test/OpenMP/for_firstprivate_codegen.cpp
  clang/test/OpenMP/for_lastprivate_codegen.cpp
  clang/test/OpenMP/for_linear_codegen.cpp
  clang/test/OpenMP/for_private_codegen.cpp
  clang/test/OpenMP/for_reduction_codegen.cpp
  clang/test/OpenMP/for_reduction_codegen_UDR.cpp
  clang/test/OpenMP/for_reduction_task_codegen.cpp
  clang/test/OpenMP/master_taskloop_in_reduction_codegen.cpp
  clang/test/OpenMP/master_taskloop_simd_in_reduction_codegen.cpp
  clang/test/OpenMP/nvptx_allocate_codegen.cpp
  clang/test/OpenMP/nvptx_data_sharing.cpp
  clang/test/OpenMP/nvptx_distribute_parallel_generic_mode_codegen.cpp
  clang/test/OpenMP/nvptx_lambda_capturing.cpp
  clang/test/OpenMP/nvptx_multi_target_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_nested_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_parallel_for_codegen.cpp
  clang/test/OpenMP/nvptx_target_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_num_threads_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_reduction_codegen_tbaa_PR46146.cpp
  clang/test/OpenMP/nvptx_target_teams_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_codegen.cpp
  
clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_generic_mode_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_simd_codegen.cpp
  clang/test/OpenMP/nvptx_teams_codegen.cpp
  clang/test/OpenMP/nvptx_teams_reduction_codegen.cpp
  clang/test/OpenMP/openmp_win_codegen.cpp
  clang/test/OpenMP/parallel_codegen.cpp
  clang/test/OpenMP/parallel_copyin_codegen.cpp
  clang/test/OpenMP/parallel_firstprivate_codegen.cpp
  clang/test/OpenMP/parallel_for_codegen.cpp
  clang/test/OpenMP/parallel_for_lastprivate_conditional.cpp
  clang/test/OpenMP/parallel_for_linear_codegen.cpp
  clang/test/OpenMP/parallel_for_reduction_task_codegen.cpp
  clang/test/OpenMP/parallel_if_codegen.cpp
  clang/test/OpenMP/parallel_master_codegen.cpp
  clang/test/OpenMP/parallel_master_reduction_task_codegen.cpp
  clang/test/OpenMP/parallel_master_taskloop_codegen.cpp
  clang/test/OpenMP/parallel_master_taskloop_lastprivate_codegen.cpp
  clang/test/OpenMP/parallel_master_taskloop_simd_codegen.cpp
  clang/test/OpenMP/parallel_master_taskloop_simd_lastprivate_codegen.cpp
  clang/test/OpenMP/parallel_private_codegen.cpp
  clang/test/OpenMP/parallel_reduction_codegen.cpp
  clang/test/OpenMP/parallel_reduction_task_codegen.cpp
  clang/test/OpenMP/parallel_sections_codegen.cpp
  clang/test/OpenMP/parallel_sections_reduction_task_codegen.cpp
  clang/test/OpenMP/reduction_compound_op.

[PATCH] D104099: [NewPM] Remove SpeculateAroundPHIs pass

2021-06-15 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

I see. Going to land this now. Thanks for looking!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104099

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


[clang] e523645 - [NewPM] Remove SpeculateAroundPHIs pass

2021-06-15 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2021-06-15T20:35:55+03:00
New Revision: e52364532afb2748c324f360bc1cc12605d314f3

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

LOG: [NewPM] Remove SpeculateAroundPHIs pass

Addition of this pass has been botched.
There is no particular reason why it had to be sold as an inseparable part
of new-pm transition. It was added when old-pm was still the default,
and very *very* few users were actually tracking new-pm,
so it's effects weren't measured.

Which means, some of the turnoil of the new-pm transition
are actually likely regressions due to this pass.

Likewise, there has been a number of post-commit feedback
(post new-pm switch), namely
* https://reviews.llvm.org/D37467#2787157 (regresses HW-loops)
* https://reviews.llvm.org/D37467#2787259 (should not be in middle-end, should 
run after LSR, not before)
* https://reviews.llvm.org/D95789 (an attempt to fix bad loop backedge metadata)
and in the half year past, the pass authors (google) still haven't found time 
to respond to any of that.

Hereby it is proposed to backout the pass from the pipeline,
until someone who cares about it can address the issues reported,
and properly start the process of adding a new pass into the pipeline,
with proper performance evaluation.

Furthermore, neither google nor facebook reports any perf changes
from this change, so i'm dropping the pass completely.
It can always be re-reverted should/if anyone want to pick it up again.

Reviewed By: aeubanks

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

Added: 


Modified: 
clang/test/CodeGen/thinlto-distributed-newpm.ll
llvm/lib/Passes/PassBuilder.cpp
llvm/lib/Passes/PassRegistry.def
llvm/lib/Transforms/Scalar/CMakeLists.txt
llvm/test/Other/new-pm-defaults.ll
llvm/test/Other/new-pm-thinlto-defaults.ll
llvm/test/Other/new-pm-thinlto-postlink-pgo-defaults.ll
llvm/test/Other/new-pm-thinlto-postlink-samplepgo-defaults.ll
llvm/test/Transforms/LoopUnroll/AArch64/runtime-unroll-generic.ll

llvm/test/Transforms/PhaseOrdering/AArch64/hoisting-sinking-required-for-vectorization.ll
llvm/test/Transforms/PhaseOrdering/loop-rotation-vs-common-code-hoisting.ll
llvm/utils/gn/secondary/llvm/lib/Transforms/Scalar/BUILD.gn

Removed: 
llvm/include/llvm/Transforms/Scalar/SpeculateAroundPHIs.h
llvm/lib/Transforms/Scalar/SpeculateAroundPHIs.cpp
llvm/test/Transforms/SpeculateAroundPHIs/basic-x86.ll
llvm/test/Transforms/SpeculateAroundPHIs/convergent.ll
llvm/test/Transforms/SpeculateAroundPHIs/pr42991.ll



diff  --git a/clang/test/CodeGen/thinlto-distributed-newpm.ll 
b/clang/test/CodeGen/thinlto-distributed-newpm.ll
index e20f781915726..c61a6ff7fbeb5 100644
--- a/clang/test/CodeGen/thinlto-distributed-newpm.ll
+++ b/clang/test/CodeGen/thinlto-distributed-newpm.ll
@@ -165,7 +165,6 @@
 ; CHECK-O: Running pass: InstSimplifyPass on main
 ; CHECK-O: Running pass: DivRemPairsPass on main
 ; CHECK-O: Running pass: SimplifyCFGPass on main
-; CHECK-O: Running pass: SpeculateAroundPHIsPass on main
 ; CHECK-O: Running pass: CGProfilePass
 ; CHECK-O: Running pass: GlobalDCEPass
 ; CHECK-O: Running pass: ConstantMergePass

diff  --git a/llvm/include/llvm/Transforms/Scalar/SpeculateAroundPHIs.h 
b/llvm/include/llvm/Transforms/Scalar/SpeculateAroundPHIs.h
deleted file mode 100644
index 2104daff44abe..0
--- a/llvm/include/llvm/Transforms/Scalar/SpeculateAroundPHIs.h
+++ /dev/null
@@ -1,109 +0,0 @@
-//===- SpeculateAroundPHIs.h - Speculate around PHIs *- C++ 
-*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-
-#ifndef LLVM_TRANSFORMS_SCALAR_SPECULATEAROUNDPHIS_H
-#define LLVM_TRANSFORMS_SCALAR_SPECULATEAROUNDPHIS_H
-
-#include "llvm/ADT/SetVector.h"
-#include "llvm/Analysis/AssumptionCache.h"
-#include "llvm/IR/Dominators.h"
-#include "llvm/IR/Function.h"
-#include "llvm/IR/PassManager.h"
-#include "llvm/Support/Compiler.h"
-
-namespace llvm {
-
-/// This pass handles simple speculating of  instructions around PHIs when
-/// doing so is profitable for a particular target despite duplicated
-/// instructions.
-///
-/// The motivating example are PHIs of constants which will require
-/// materializing the constants along each edge. If the PHI is used by an
-/// instruction where the target can materialize the constant as part of the
-/// instruction, it is profitable to speculate those instructions around the
-/// PHI node. This can reduce dynamic instruction count as well as decrease
-/// register pressure.
-///
-/// C

[PATCH] D104099: [NewPM] Remove SpeculateAroundPHIs pass

2021-06-15 Thread Roman Lebedev 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 rGe52364532afb: [NewPM] Remove SpeculateAroundPHIs pass 
(authored by lebedev.ri).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104099

Files:
  clang/test/CodeGen/thinlto-distributed-newpm.ll
  llvm/include/llvm/Transforms/Scalar/SpeculateAroundPHIs.h
  llvm/lib/Passes/PassBuilder.cpp
  llvm/lib/Passes/PassRegistry.def
  llvm/lib/Transforms/Scalar/CMakeLists.txt
  llvm/lib/Transforms/Scalar/SpeculateAroundPHIs.cpp
  llvm/test/Other/new-pm-defaults.ll
  llvm/test/Other/new-pm-thinlto-defaults.ll
  llvm/test/Other/new-pm-thinlto-postlink-pgo-defaults.ll
  llvm/test/Other/new-pm-thinlto-postlink-samplepgo-defaults.ll
  llvm/test/Transforms/LoopUnroll/AArch64/runtime-unroll-generic.ll
  
llvm/test/Transforms/PhaseOrdering/AArch64/hoisting-sinking-required-for-vectorization.ll
  llvm/test/Transforms/PhaseOrdering/loop-rotation-vs-common-code-hoisting.ll
  llvm/test/Transforms/SpeculateAroundPHIs/basic-x86.ll
  llvm/test/Transforms/SpeculateAroundPHIs/convergent.ll
  llvm/test/Transforms/SpeculateAroundPHIs/pr42991.ll
  llvm/utils/gn/secondary/llvm/lib/Transforms/Scalar/BUILD.gn

Index: llvm/utils/gn/secondary/llvm/lib/Transforms/Scalar/BUILD.gn
===
--- llvm/utils/gn/secondary/llvm/lib/Transforms/Scalar/BUILD.gn
+++ llvm/utils/gn/secondary/llvm/lib/Transforms/Scalar/BUILD.gn
@@ -83,7 +83,6 @@
 "SimpleLoopUnswitch.cpp",
 "SimplifyCFGPass.cpp",
 "Sink.cpp",
-"SpeculateAroundPHIs.cpp",
 "SpeculativeExecution.cpp",
 "StraightLineStrengthReduce.cpp",
 "StructurizeCFG.cpp",
Index: llvm/test/Transforms/SpeculateAroundPHIs/pr42991.ll
===
--- llvm/test/Transforms/SpeculateAroundPHIs/pr42991.ll
+++ /dev/null
@@ -1,44 +0,0 @@
-; RUN: opt -S -passes=spec-phis %s
-
-; This testcase crashes during the speculate around PHIs pass. The pass however
-; results in no changes.
-
-define i32 @test1() {
-entry:
-  callbr void asm sideeffect "", "X,X,~{dirflag},~{fpsr},~{flags}"(i8* blockaddress(@test1, %return), i8* blockaddress(@test1, %f))
-  to label %asm.fallthrough [label %return, label %f]
-
-asm.fallthrough:
-  br label %return
-
-f:
-  br label %return
-
-return:
-  %retval.0 = phi i32 [ 0, %f ], [ 1, %asm.fallthrough ], [ 1, %entry ]
-  ret i32 %retval.0
-}
-
-define void @test2() {
-entry:
-  br label %tailrecurse
-
-tailrecurse:
-  %call = tail call i32 @test3()
-  %tobool1 = icmp eq i32 %call, 0
-  callbr void asm sideeffect "", "X,X,~{dirflag},~{fpsr},~{flags}"(i8* blockaddress(@test2, %test1.exit), i8* blockaddress(@test2, %f.i))
-  to label %if.end6 [label %test1.exit, label %f.i]
-
-f.i:
-  br label %test1.exit
-
-test1.exit:
-  %retval.0.i = phi i1 [ false, %f.i ], [ true, %tailrecurse ]
-  %brmerge = or i1 %tobool1, %retval.0.i
-  br i1 %brmerge, label %if.end6, label %tailrecurse
-
-if.end6:
-  ret void
-}
-
-declare i32 @test3()
Index: llvm/test/Transforms/SpeculateAroundPHIs/convergent.ll
===
--- llvm/test/Transforms/SpeculateAroundPHIs/convergent.ll
+++ /dev/null
@@ -1,98 +0,0 @@
-; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
-; RUN: opt -S -passes=spec-phis < %s | FileCheck %s
-; Make sure convergent and noduplicate calls aren't duplicated.
-
-declare i32 @llvm.convergent(i32) #0
-declare i32 @llvm.noduplicate(i32) #1
-declare i32 @llvm.regular(i32) #2
-
-define i32 @test_convergent(i1 %flag, i32 %arg) #0 {
-; CHECK-LABEL: @test_convergent(
-; CHECK-NEXT:  entry:
-; CHECK-NEXT:br i1 [[FLAG:%.*]], label [[A:%.*]], label [[B:%.*]]
-; CHECK:   a:
-; CHECK-NEXT:br label [[EXIT:%.*]]
-; CHECK:   b:
-; CHECK-NEXT:br label [[EXIT]]
-; CHECK:   exit:
-; CHECK-NEXT:[[P:%.*]] = phi i32 [ 7, [[A]] ], [ 11, [[B]] ]
-; CHECK-NEXT:[[SUM:%.*]] = call i32 @llvm.convergent(i32 [[P]])
-; CHECK-NEXT:ret i32 [[SUM]]
-;
-entry:
-  br i1 %flag, label %a, label %b
-
-a:
-  br label %exit
-
-b:
-  br label %exit
-
-exit:
-  %p = phi i32 [ 7, %a ], [ 11, %b ]
-  %sum = call i32 @llvm.convergent(i32 %p)
-  ret i32 %sum
-}
-
-define i32 @test_noduplicate(i1 %flag, i32 %arg) #1 {
-; CHECK-LABEL: @test_noduplicate(
-; CHECK-NEXT:  entry:
-; CHECK-NEXT:br i1 [[FLAG:%.*]], label [[A:%.*]], label [[B:%.*]]
-; CHECK:   a:
-; CHECK-NEXT:br label [[EXIT:%.*]]
-; CHECK:   b:
-; CHECK-NEXT:br label [[EXIT]]
-; CHECK:   exit:
-; CHECK-NEXT:[[P:%.*]] = phi i32 [ 7, [[A]] ], [ 11, [[B]] ]
-; CHECK-NEXT:[[SUM:%.*]] = call i32 @llvm.noduplicate(i32 [[P]])
-; CHECK-NEXT:ret i32 [[SUM]]
-;
-entry:
-  br i1 %flag, label %a, label %b
-
-a:
-  br label %exit
-
-b:
-  br label %exit
-
-exit:
-  %p

[PATCH] D104305: [flang][driver] Add `-fdebug-dump-all`

2021-06-15 Thread Pete Steinfeld via Phabricator via cfe-commits
PeteSteinfeld added a comment.

Stay tuned a little, I think I spotted the problem ...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104305

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


[PATCH] D104305: [flang][driver] Add `-fdebug-dump-all`

2021-06-15 Thread Pete Steinfeld via Phabricator via cfe-commits
PeteSteinfeld accepted this revision.
PeteSteinfeld added a comment.
This revision is now accepted and ready to land.

Looks great!  Thanks for doing this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104305

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


[PATCH] D104275: [compiler-rt][hwasan] Add GetShadowOffset function

2021-06-15 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan updated this revision to Diff 352186.
leonardchan marked 2 inline comments as done.
leonardchan retitled this revision from "[compiler-rt][hwasan] Add 
SHADOW_OFFSET macro" to "[compiler-rt][hwasan] Add GetShadowOffset function".

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104275

Files:
  compiler-rt/lib/hwasan/hwasan_allocator.h
  compiler-rt/lib/hwasan/hwasan_mapping.h


Index: compiler-rt/lib/hwasan/hwasan_mapping.h
===
--- compiler-rt/lib/hwasan/hwasan_mapping.h
+++ compiler-rt/lib/hwasan/hwasan_mapping.h
@@ -50,12 +50,14 @@
 
 extern uptr kAliasRegionStart;
 
+inline uptr GetShadowOffset() {
+  return SANITIZER_FUCHSIA ? 0 : __hwasan_shadow_memory_dynamic_address;
+}
 inline uptr MemToShadow(uptr untagged_addr) {
-  return (untagged_addr >> kShadowScale) +
- __hwasan_shadow_memory_dynamic_address;
+  return (untagged_addr >> kShadowScale) + GetShadowOffset();
 }
 inline uptr ShadowToMem(uptr shadow_addr) {
-  return (shadow_addr - __hwasan_shadow_memory_dynamic_address) << 
kShadowScale;
+  return (shadow_addr - GetShadowOffset()) << kShadowScale;
 }
 inline uptr MemToShadowSize(uptr size) {
   return size >> kShadowScale;
Index: compiler-rt/lib/hwasan/hwasan_allocator.h
===
--- compiler-rt/lib/hwasan/hwasan_allocator.h
+++ compiler-rt/lib/hwasan/hwasan_allocator.h
@@ -15,6 +15,7 @@
 
 #include "hwasan.h"
 #include "hwasan_interface_internal.h"
+#include "hwasan_mapping.h"
 #include "hwasan_poisoning.h"
 #include "sanitizer_common/sanitizer_allocator.h"
 #include "sanitizer_common/sanitizer_allocator_checks.h"
@@ -114,7 +115,7 @@
   // Aliases are mapped next to shadow so that the upper bits match the shadow
   // base.
   return (addr >> kTaggableRegionCheckShift) ==
- (__hwasan_shadow_memory_dynamic_address >> kTaggableRegionCheckShift);
+ (GetShadowOffset() >> kTaggableRegionCheckShift);
 #endif
   return true;
 }


Index: compiler-rt/lib/hwasan/hwasan_mapping.h
===
--- compiler-rt/lib/hwasan/hwasan_mapping.h
+++ compiler-rt/lib/hwasan/hwasan_mapping.h
@@ -50,12 +50,14 @@
 
 extern uptr kAliasRegionStart;
 
+inline uptr GetShadowOffset() {
+  return SANITIZER_FUCHSIA ? 0 : __hwasan_shadow_memory_dynamic_address;
+}
 inline uptr MemToShadow(uptr untagged_addr) {
-  return (untagged_addr >> kShadowScale) +
- __hwasan_shadow_memory_dynamic_address;
+  return (untagged_addr >> kShadowScale) + GetShadowOffset();
 }
 inline uptr ShadowToMem(uptr shadow_addr) {
-  return (shadow_addr - __hwasan_shadow_memory_dynamic_address) << kShadowScale;
+  return (shadow_addr - GetShadowOffset()) << kShadowScale;
 }
 inline uptr MemToShadowSize(uptr size) {
   return size >> kShadowScale;
Index: compiler-rt/lib/hwasan/hwasan_allocator.h
===
--- compiler-rt/lib/hwasan/hwasan_allocator.h
+++ compiler-rt/lib/hwasan/hwasan_allocator.h
@@ -15,6 +15,7 @@
 
 #include "hwasan.h"
 #include "hwasan_interface_internal.h"
+#include "hwasan_mapping.h"
 #include "hwasan_poisoning.h"
 #include "sanitizer_common/sanitizer_allocator.h"
 #include "sanitizer_common/sanitizer_allocator_checks.h"
@@ -114,7 +115,7 @@
   // Aliases are mapped next to shadow so that the upper bits match the shadow
   // base.
   return (addr >> kTaggableRegionCheckShift) ==
- (__hwasan_shadow_memory_dynamic_address >> kTaggableRegionCheckShift);
+ (GetShadowOffset() >> kTaggableRegionCheckShift);
 #endif
   return true;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D102107: [OpenMP] Codegen aggregate for outlined function captures

2021-06-15 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

(This is not offload-specific, right?)
This does not bring any compatibility issues, right?
Does this bring any compatibility issues?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102107

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


[PATCH] D97915: [Coroutines] Handle overaligned frame allocation

2021-06-15 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen updated this revision to Diff 352189.
ychen added a comment.

- Merge D102145  by @ChuanqiXu's request.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97915

Files:
  clang/include/clang/AST/StmtCXX.h
  clang/lib/AST/StmtCXX.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGCoroutine.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/Sema/SemaCoroutine.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/CodeGenCoroutines/coro-alloc.cpp
  clang/test/CodeGenCoroutines/coro-cleanup.cpp
  clang/test/CodeGenCoroutines/coro-gro.cpp
  llvm/docs/Coroutines.rst
  llvm/include/llvm/IR/Intrinsics.td
  llvm/lib/Transforms/Coroutines/CoroFrame.cpp
  llvm/lib/Transforms/Coroutines/CoroInstr.h
  llvm/lib/Transforms/Coroutines/CoroInternal.h
  llvm/lib/Transforms/Coroutines/CoroSplit.cpp
  llvm/lib/Transforms/Coroutines/Coroutines.cpp
  llvm/test/Transforms/Coroutines/coro-frame-overalign.ll

Index: llvm/test/Transforms/Coroutines/coro-frame-overalign.ll
===
--- /dev/null
+++ llvm/test/Transforms/Coroutines/coro-frame-overalign.ll
@@ -0,0 +1,78 @@
+; Check that `llvm.coro.align`, `llvm.coro.raw.frame.ptr.offset` and
+; `@llvm.coro.raw.frame.ptr.alloca` are lowered correctly.
+; RUN: opt < %s -passes=coro-split -S | FileCheck %s
+
+%PackedStruct = type <{ i64 }>
+
+declare void @consume(%PackedStruct*, i32, i32, i8**)
+declare void @consume2(i32, i32)
+
+define i8* @f() "coroutine.presplit"="1" {
+entry:
+  %data = alloca %PackedStruct, align 32
+  %id = call token @llvm.coro.id(i32 16, i8* null, i8* null, i8* null)
+  %size = call i32 @llvm.coro.size.i32()
+  %alloc = call i8* @malloc(i32 %size)
+  %hdl = call i8* @llvm.coro.begin(token %id, i8* %alloc)
+  %align = call i32 @llvm.coro.align.i32()
+  %offset = call i32 @llvm.coro.raw.frame.ptr.offset.i32()
+  %addr = call i8** @llvm.coro.raw.frame.ptr.addr()
+  call void @consume(%PackedStruct* %data, i32 %align, i32 %offset, i8** %addr)
+  %0 = call i8 @llvm.coro.suspend(token none, i1 false)
+  switch i8 %0, label %suspend [i8 0, label %resume
+i8 1, label %cleanup]
+resume:
+  br label %cleanup
+
+cleanup:
+  %align2 = call i32 @llvm.coro.align.i32()
+  %offset2 = call i32 @llvm.coro.raw.frame.ptr.offset.i32()
+  call void @consume2(i32 %align2, i32 %offset2)
+  %mem = call i8* @llvm.coro.free(token %id, i8* %hdl)
+  call void @free(i8* %mem)
+  br label %suspend
+suspend:
+  call i1 @llvm.coro.end(i8* %hdl, i1 0)
+  ret i8* %hdl
+}
+
+; See if the raw frame address was inserted into the frame.
+; CHECK-LABEL: %f.Frame = type { void (%f.Frame*)*, void (%f.Frame*)*, i8*, i1, [7 x i8], %PackedStruct }
+
+; See if we used correct index to access frame addr field (field 2).
+; CHECK-LABEL: @f(
+; CHECK: %alloc.frame.ptr = alloca i8*, align 8
+; CHECK: %[[FIELD:.+]] = getelementptr inbounds %f.Frame, %f.Frame* %FramePtr, i32 0, i32 2
+; CHECK: %[[ADDR:.+]] = load i8*, i8** %alloc.frame.ptr, align 8
+; CHECK: store i8* %[[ADDR]], i8** %[[FIELD]], align 8
+; CHECK: %[[DATA:.+]] = getelementptr inbounds %f.Frame, %f.Frame* %FramePtr, i32 0, i32 5
+; CHECK: call void @consume(%PackedStruct* %[[DATA]], i32 32, i32 16, i8** %[[FIELD]])
+; CHECK: ret i8*
+
+; See if `llvm.coro.align` and `llvm.coro.raw.frame.ptr.offset` are lowered
+; correctly during deallocation.
+; CHECK-LABEL: @f.destroy(
+; CHECK: call void @consume2(i32 32, i32 16)
+; CHECK: call void @free(i8* %{{.*}})
+
+; CHECK-LABEL: @f.cleanup(
+; CHECK: call void @consume2(i32 32, i32 16)
+; CHECK: call void @free(i8*
+
+declare i8* @llvm.coro.free(token, i8*)
+declare i32 @llvm.coro.size.i32()
+declare i32 @llvm.coro.align.i32()
+declare i32 @llvm.coro.raw.frame.ptr.offset.i32()
+declare i8** @llvm.coro.raw.frame.ptr.addr()
+declare i8  @llvm.coro.suspend(token, i1)
+declare void @llvm.coro.resume(i8*)
+declare void @llvm.coro.destroy(i8*)
+
+declare token @llvm.coro.id(i32, i8*, i8*, i8*)
+declare i1 @llvm.coro.alloc(token)
+declare i8* @llvm.coro.begin(token, i8*)
+declare i1 @llvm.coro.end(i8*, i1)
+
+declare noalias i8* @malloc(i32)
+declare double @print(double)
+declare void @free(i8*)
Index: llvm/lib/Transforms/Coroutines/Coroutines.cpp
===
--- llvm/lib/Transforms/Coroutines/Coroutines.cpp
+++ llvm/lib/Transforms/Coroutines/Coroutines.cpp
@@ -234,6 +234,9 @@
   Shape.CoroBegin = nullptr;
   Shape.CoroEnds.clear();
   Shape.CoroSizes.clear();
+  Shape.CoroAligns.clear();
+  Shape.CoroRawFramePtrOffsets.clear();
+  Shape.CoroRawFramePtrAddrs.clear();
   Shape.CoroSuspends.clear();
 
   Shape.FrameTy = nullptr;
@@ -268,6 +271,15 @@
   case Intrinsic::coro_size:
 CoroSizes.push_back(cast(II));
 break;
+  case Intrinsic::coro_align:
+CoroAligns.push_back(cast(II));
+break;
+  case I

[PATCH] D104275: [compiler-rt][hwasan] Add GetShadowOffset function

2021-06-15 Thread Leonard Chan via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGfc006b3e5dc3: [compiler-rt][hwasan] Add GetShadowOffset 
function (authored by leonardchan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104275

Files:
  compiler-rt/lib/hwasan/hwasan_allocator.h
  compiler-rt/lib/hwasan/hwasan_mapping.h


Index: compiler-rt/lib/hwasan/hwasan_mapping.h
===
--- compiler-rt/lib/hwasan/hwasan_mapping.h
+++ compiler-rt/lib/hwasan/hwasan_mapping.h
@@ -50,12 +50,14 @@
 
 extern uptr kAliasRegionStart;
 
+inline uptr GetShadowOffset() {
+  return SANITIZER_FUCHSIA ? 0 : __hwasan_shadow_memory_dynamic_address;
+}
 inline uptr MemToShadow(uptr untagged_addr) {
-  return (untagged_addr >> kShadowScale) +
- __hwasan_shadow_memory_dynamic_address;
+  return (untagged_addr >> kShadowScale) + GetShadowOffset();
 }
 inline uptr ShadowToMem(uptr shadow_addr) {
-  return (shadow_addr - __hwasan_shadow_memory_dynamic_address) << 
kShadowScale;
+  return (shadow_addr - GetShadowOffset()) << kShadowScale;
 }
 inline uptr MemToShadowSize(uptr size) {
   return size >> kShadowScale;
Index: compiler-rt/lib/hwasan/hwasan_allocator.h
===
--- compiler-rt/lib/hwasan/hwasan_allocator.h
+++ compiler-rt/lib/hwasan/hwasan_allocator.h
@@ -15,6 +15,7 @@
 
 #include "hwasan.h"
 #include "hwasan_interface_internal.h"
+#include "hwasan_mapping.h"
 #include "hwasan_poisoning.h"
 #include "sanitizer_common/sanitizer_allocator.h"
 #include "sanitizer_common/sanitizer_allocator_checks.h"
@@ -114,7 +115,7 @@
   // Aliases are mapped next to shadow so that the upper bits match the shadow
   // base.
   return (addr >> kTaggableRegionCheckShift) ==
- (__hwasan_shadow_memory_dynamic_address >> kTaggableRegionCheckShift);
+ (GetShadowOffset() >> kTaggableRegionCheckShift);
 #endif
   return true;
 }


Index: compiler-rt/lib/hwasan/hwasan_mapping.h
===
--- compiler-rt/lib/hwasan/hwasan_mapping.h
+++ compiler-rt/lib/hwasan/hwasan_mapping.h
@@ -50,12 +50,14 @@
 
 extern uptr kAliasRegionStart;
 
+inline uptr GetShadowOffset() {
+  return SANITIZER_FUCHSIA ? 0 : __hwasan_shadow_memory_dynamic_address;
+}
 inline uptr MemToShadow(uptr untagged_addr) {
-  return (untagged_addr >> kShadowScale) +
- __hwasan_shadow_memory_dynamic_address;
+  return (untagged_addr >> kShadowScale) + GetShadowOffset();
 }
 inline uptr ShadowToMem(uptr shadow_addr) {
-  return (shadow_addr - __hwasan_shadow_memory_dynamic_address) << kShadowScale;
+  return (shadow_addr - GetShadowOffset()) << kShadowScale;
 }
 inline uptr MemToShadowSize(uptr size) {
   return size >> kShadowScale;
Index: compiler-rt/lib/hwasan/hwasan_allocator.h
===
--- compiler-rt/lib/hwasan/hwasan_allocator.h
+++ compiler-rt/lib/hwasan/hwasan_allocator.h
@@ -15,6 +15,7 @@
 
 #include "hwasan.h"
 #include "hwasan_interface_internal.h"
+#include "hwasan_mapping.h"
 #include "hwasan_poisoning.h"
 #include "sanitizer_common/sanitizer_allocator.h"
 #include "sanitizer_common/sanitizer_allocator_checks.h"
@@ -114,7 +115,7 @@
   // Aliases are mapped next to shadow so that the upper bits match the shadow
   // base.
   return (addr >> kTaggableRegionCheckShift) ==
- (__hwasan_shadow_memory_dynamic_address >> kTaggableRegionCheckShift);
+ (GetShadowOffset() >> kTaggableRegionCheckShift);
 #endif
   return true;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104198: [Matrix] Add documentation for compound assignment and type conversion of matrix types

2021-06-15 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha updated this revision to Diff 352191.
SaurabhJha added a comment.

Address review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104198

Files:
  clang/docs/LanguageExtensions.rst


Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -523,6 +523,60 @@
 return a + b * c;
   }
 
+The matrix type extension also supports operations between a matrix and a 
scalar.
+
+.. code-block:: c++
+
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a) {
+  int c = 23;
+  int d = 12;
+  a = a + c;
+  return a * d;
+  }
+
+The matrix type extension supports compound assignments for addition, 
subtraction, and multiplication between matrices
+and between a matrix and a scalar, provided their types are consistent.
+
+.. code-block:: c++
+
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a, m4x4_t b) {
+int c = 23;
+int d = 12;
+a += b;
+a -= b;
+a *= b;
+a += c;
+a -= d;
+return a;
+  }
+
+The matrix type extension supports explicit casts. The casts we support are 
C-style casts in C and C++ and
+static casts. Implicit type conversion between matrix types is not allowed.
+
+.. code-block:: c++
+
+  typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+  typedef float fx5x5 __attribute__((matrix_type(5, 5)));
+
+  fx5x5 f1(ix5x5 i, fx5x5 f) {
+f = (fx5x5)i;
+return f;
+  }
+
+
+  template 
+  using matrix_4_4 = X __attribute__((matrix_type(4, 4)));
+
+  void f2() {
+matrix_5_5 d;
+matrix_5_5 i;
+i = (matrix_5_5)d;
+i = static_cast>(d);
+  }
 
 Half-Precision Floating Point
 =


Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -523,6 +523,60 @@
 return a + b * c;
   }
 
+The matrix type extension also supports operations between a matrix and a scalar.
+
+.. code-block:: c++
+
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a) {
+  int c = 23;
+  int d = 12;
+  a = a + c;
+  return a * d;
+  }
+
+The matrix type extension supports compound assignments for addition, subtraction, and multiplication between matrices
+and between a matrix and a scalar, provided their types are consistent.
+
+.. code-block:: c++
+
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a, m4x4_t b) {
+int c = 23;
+int d = 12;
+a += b;
+a -= b;
+a *= b;
+a += c;
+a -= d;
+return a;
+  }
+
+The matrix type extension supports explicit casts. The casts we support are C-style casts in C and C++ and
+static casts. Implicit type conversion between matrix types is not allowed.
+
+.. code-block:: c++
+
+  typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+  typedef float fx5x5 __attribute__((matrix_type(5, 5)));
+
+  fx5x5 f1(ix5x5 i, fx5x5 f) {
+f = (fx5x5)i;
+return f;
+  }
+
+
+  template 
+  using matrix_4_4 = X __attribute__((matrix_type(4, 4)));
+
+  void f2() {
+matrix_5_5 d;
+matrix_5_5 i;
+i = (matrix_5_5)d;
+i = static_cast>(d);
+  }
 
 Half-Precision Floating Point
 =
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104198: [Matrix] Add documentation for compound assignment and type conversion of matrix types

2021-06-15 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha updated this revision to Diff 352192.
SaurabhJha added a comment.

Document matrix scalar division


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104198

Files:
  clang/docs/LanguageExtensions.rst


Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -523,6 +523,71 @@
 return a + b * c;
   }
 
+The matrix type extension also supports operations between a matrix and a 
scalar.
+
+.. code-block:: c++
+
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a) {
+  int c = 23;
+  int d = 12;
+  a = a + c;
+  return a * d;
+  }
+
+The matrix type extension supports division between a matrix and a scalar but 
not between a matrix and a matrix.
+
+.. code-block:: c++
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a) {
+float s = 3;
+a = a / s;
+return a;
+  }
+
+The matrix type extension supports compound assignments for addition, 
subtraction, and multiplication between matrices
+and between a matrix and a scalar, provided their types are consistent.
+
+.. code-block:: c++
+
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a, m4x4_t b) {
+int c = 23;
+int d = 12;
+a += b;
+a -= b;
+a *= b;
+a += c;
+a -= d;
+return a;
+  }
+
+The matrix type extension supports explicit casts. The casts we support are 
C-style casts in C and C++ and
+static casts. Implicit type conversion between matrix types is not allowed.
+
+.. code-block:: c++
+
+  typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+  typedef float fx5x5 __attribute__((matrix_type(5, 5)));
+
+  fx5x5 f1(ix5x5 i, fx5x5 f) {
+f = (fx5x5)i;
+return f;
+  }
+
+
+  template 
+  using matrix_4_4 = X __attribute__((matrix_type(4, 4)));
+
+  void f2() {
+matrix_5_5 d;
+matrix_5_5 i;
+i = (matrix_5_5)d;
+i = static_cast>(d);
+  }
 
 Half-Precision Floating Point
 =


Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -523,6 +523,71 @@
 return a + b * c;
   }
 
+The matrix type extension also supports operations between a matrix and a scalar.
+
+.. code-block:: c++
+
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a) {
+  int c = 23;
+  int d = 12;
+  a = a + c;
+  return a * d;
+  }
+
+The matrix type extension supports division between a matrix and a scalar but not between a matrix and a matrix.
+
+.. code-block:: c++
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a) {
+float s = 3;
+a = a / s;
+return a;
+  }
+
+The matrix type extension supports compound assignments for addition, subtraction, and multiplication between matrices
+and between a matrix and a scalar, provided their types are consistent.
+
+.. code-block:: c++
+
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a, m4x4_t b) {
+int c = 23;
+int d = 12;
+a += b;
+a -= b;
+a *= b;
+a += c;
+a -= d;
+return a;
+  }
+
+The matrix type extension supports explicit casts. The casts we support are C-style casts in C and C++ and
+static casts. Implicit type conversion between matrix types is not allowed.
+
+.. code-block:: c++
+
+  typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+  typedef float fx5x5 __attribute__((matrix_type(5, 5)));
+
+  fx5x5 f1(ix5x5 i, fx5x5 f) {
+f = (fx5x5)i;
+return f;
+  }
+
+
+  template 
+  using matrix_4_4 = X __attribute__((matrix_type(4, 4)));
+
+  void f2() {
+matrix_5_5 d;
+matrix_5_5 i;
+i = (matrix_5_5)d;
+i = static_cast>(d);
+  }
 
 Half-Precision Floating Point
 =
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104222: [clang-format] [PR50702] Lamdba processing does not respect AfterClass and AfterNamespace

2021-06-15 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay updated this revision to Diff 352193.
MyDeveloperDay added a comment.

Add support for TemplateCloser before LambdaBrace


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

https://reviews.llvm.org/D104222

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

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -18856,8 +18856,7 @@
"  });\n"
"});",
LLVMWithBeforeLambdaBody);
-  verifyFormat("void Fct()\n"
-   "{\n"
+  verifyFormat("void Fct() {\n"
"  return {[]()\n"
"  {\n"
"return 17;\n"
@@ -19061,6 +19060,35 @@
"  });\n"
"});",
LLVMWithBeforeLambdaBody);
+
+  LLVMWithBeforeLambdaBody.AllowShortLambdasOnASingleLine =
+  FormatStyle::ShortLambdaStyle::SLS_None;
+
+  verifyFormat("auto select = [this]() -> const Library::Object *\n"
+   "{\n"
+   "  return MyAssignment::SelectFromList(this);\n"
+   "};\n",
+   LLVMWithBeforeLambdaBody);
+
+  verifyFormat("auto select = [this]() -> const Library::Object &\n"
+   "{\n"
+   "  return MyAssignment::SelectFromList(this);\n"
+   "};\n",
+   LLVMWithBeforeLambdaBody);
+
+  verifyFormat("auto select = [this]() -> std::unique_ptr\n"
+   "{\n"
+   "  return MyAssignment::SelectFromList(this);\n"
+   "};\n",
+   LLVMWithBeforeLambdaBody);
+
+  verifyFormat("namespace test {\n"
+   "class Test {\n"
+   "public:\n"
+   "  Test() = default;\n"
+   "};\n"
+   "} // namespace test",
+   LLVMWithBeforeLambdaBody);
 }
 
 TEST_F(FormatTest, LambdaWithLineComments) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3557,42 +3557,11 @@
   return Tok.Children.empty() && ShortLambdaOption != FormatStyle::SLS_None;
 }
 
-static bool
-isItAInlineLambdaAllowed(const FormatToken &Tok,
- FormatStyle::ShortLambdaStyle ShortLambdaOption) {
-  return (ShortLambdaOption == FormatStyle::SLS_Inline &&
-  IsFunctionArgument(Tok)) ||
- (ShortLambdaOption == FormatStyle::SLS_All);
-}
-
-static bool isOneChildWithoutMustBreakBefore(const FormatToken &Tok) {
-  if (Tok.Children.size() != 1)
-return false;
-  FormatToken *curElt = Tok.Children[0]->First;
-  while (curElt) {
-if (curElt->MustBreakBefore)
-  return false;
-curElt = curElt->Next;
-  }
-  return true;
-}
 static bool isAllmanLambdaBrace(const FormatToken &Tok) {
   return (Tok.is(tok::l_brace) && Tok.is(BK_Block) &&
   !Tok.isOneOf(TT_ObjCBlockLBrace, TT_DictLiteral));
 }
 
-static bool isAllmanBraceIncludedBreakableLambda(
-const FormatToken &Tok, FormatStyle::ShortLambdaStyle ShortLambdaOption) {
-  if (!isAllmanLambdaBrace(Tok))
-return false;
-
-  if (isItAnEmptyLambdaAllowed(Tok, ShortLambdaOption))
-return false;
-
-  return !isItAInlineLambdaAllowed(Tok, ShortLambdaOption) ||
- !isOneChildWithoutMustBreakBefore(Tok);
-}
-
 bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
  const FormatToken &Right) {
   const FormatToken &Left = *Right.Previous;
@@ -3754,13 +3723,6 @@
   if (Right.is(TT_InlineASMBrace))
 return Right.HasUnescapedNewline;
 
-  auto ShortLambdaOption = Style.AllowShortLambdasOnASingleLine;
-  if (Style.BraceWrapping.BeforeLambdaBody &&
-  (isAllmanBraceIncludedBreakableLambda(Left, ShortLambdaOption) ||
-   isAllmanBraceIncludedBreakableLambda(Right, ShortLambdaOption))) {
-return true;
-  }
-
   if (isAllmanBrace(Left) || isAllmanBrace(Right))
 return (Line.startsWith(tok::kw_enum) && Style.BraceWrapping.AfterEnum) ||
(Line.startsWith(tok::kw_typedef, tok::kw_enum) &&
@@ -3783,6 +3745,11 @@
   return true;
   }
 
+  if (Style.BraceWrapping.BeforeLambdaBody && Right.is(TT_LambdaLBrace) &&
+  Left.isOneOf(tok::star, tok::amp, tok::ampamp, TT_TemplateCloser)) {
+return true;
+  }
+
   // Put multiple Java annotation on a new line.
   if ((Style.Language == FormatStyle::LK_Java ||
Style.Language == FormatStyle::LK_JavaScript) &&
@@ -4186,7 +4153,7 @@
 return false;
 
   auto ShortLambdaOption = Style.AllowShortLambdasOnASingleLine;
-  if (Style.BraceWrapping.BeforeLambdaBody) {
+  if (Style.BraceWrapping.BeforeLambdaBody && Right.is(TT_LambdaLBrace)) {
 if (isAllmanLambdaBrace(Left))
   return !isItAnEmptyLambdaAllowed(Left, ShortLambdaOption);
 if (isA

[PATCH] D103936: [compiler-rt][hwasan] Define fuchsia implementations of required hwasan functions

2021-06-15 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan updated this revision to Diff 352194.
leonardchan added a comment.

Rebase and remove `__hwasan_shadow_memory_dynamic_address`. We don't need to 
set it anymore.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103936

Files:
  compiler-rt/lib/hwasan/CMakeLists.txt
  compiler-rt/lib/hwasan/hwasan_fuchsia.cpp


Index: compiler-rt/lib/hwasan/hwasan_fuchsia.cpp
===
--- /dev/null
+++ compiler-rt/lib/hwasan/hwasan_fuchsia.cpp
@@ -0,0 +1,63 @@
+//===-- hwasan_fuchsia.cpp --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+///
+/// \file
+/// This file is a part of HWAddressSanitizer and contains Fuchsia-specific
+/// code.
+///
+//===--===//
+
+#include "sanitizer_common/sanitizer_fuchsia.h"
+#if SANITIZER_FUCHSIA
+
+#include "hwasan.h"
+#include "hwasan_interface_internal.h"
+#include "hwasan_report.h"
+#include "hwasan_thread.h"
+#include "hwasan_thread_list.h"
+
+namespace __hwasan {
+
+bool InitShadow() {
+  // Call this explicitly to set the ShadowBounds global so we can reference it
+  // now. Otherwise, ShadowBounds will be a zero-initialized global.
+  ShadowBounds = __sanitizer_shadow_bounds();
+  CHECK_NE(__sanitizer::ShadowBounds.shadow_limit, 0);
+
+  return true;
+}
+
+bool MemIsApp(uptr p) {
+  CHECK(GetTagFromPointer(p) == 0);
+  return __sanitizer::ShadowBounds.shadow_limit <= p &&
+ p <= __sanitizer::GetMaxUserVirtualAddress();
+}
+
+// Not implemented because Fuchsia does not use signal handlers.
+void HwasanOnDeadlySignal(int signo, void *info, void *context) {}
+
+// Not implemented because Fuchsia does not use interceptors.
+void InitializeInterceptors() {}
+
+// Not implemented because this is only relevant for Android.
+void AndroidTestTlsSlot() {}
+
+// TSD was normally used on linux as a means of calling the hwasan thread exit
+// handler passed to pthread_key_create. This is not needed on Fuchsia because
+// we will be using __sanitizer_thread_exit_hook.
+void HwasanTSDInit() {}
+void HwasanTSDThreadInit() {}
+
+// On linux, this just would call `atexit(HwasanAtExit)`. The functions in
+// HwasanAtExit are unimplemented for Fuchsia and effectively no-ops, so this
+// function is unneeded.
+void InstallAtExitHandler() {}
+
+}  // namespace __hwasan
+
+#endif  // SANITIZER_FUCHSIA
Index: compiler-rt/lib/hwasan/CMakeLists.txt
===
--- compiler-rt/lib/hwasan/CMakeLists.txt
+++ compiler-rt/lib/hwasan/CMakeLists.txt
@@ -7,6 +7,7 @@
   hwasan_allocation_functions.cpp
   hwasan_dynamic_shadow.cpp
   hwasan_exceptions.cpp
+  hwasan_fuchsia.cpp
   hwasan_globals.cpp
   hwasan_interceptors.cpp
   hwasan_interceptors_vfork.S


Index: compiler-rt/lib/hwasan/hwasan_fuchsia.cpp
===
--- /dev/null
+++ compiler-rt/lib/hwasan/hwasan_fuchsia.cpp
@@ -0,0 +1,63 @@
+//===-- hwasan_fuchsia.cpp --*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+///
+/// \file
+/// This file is a part of HWAddressSanitizer and contains Fuchsia-specific
+/// code.
+///
+//===--===//
+
+#include "sanitizer_common/sanitizer_fuchsia.h"
+#if SANITIZER_FUCHSIA
+
+#include "hwasan.h"
+#include "hwasan_interface_internal.h"
+#include "hwasan_report.h"
+#include "hwasan_thread.h"
+#include "hwasan_thread_list.h"
+
+namespace __hwasan {
+
+bool InitShadow() {
+  // Call this explicitly to set the ShadowBounds global so we can reference it
+  // now. Otherwise, ShadowBounds will be a zero-initialized global.
+  ShadowBounds = __sanitizer_shadow_bounds();
+  CHECK_NE(__sanitizer::ShadowBounds.shadow_limit, 0);
+
+  return true;
+}
+
+bool MemIsApp(uptr p) {
+  CHECK(GetTagFromPointer(p) == 0);
+  return __sanitizer::ShadowBounds.shadow_limit <= p &&
+ p <= __sanitizer::GetMaxUserVirtualAddress();
+}
+
+// Not implemented because Fuchsia does not use signal handlers.
+void HwasanOnDeadlySignal(int signo, void *info, void *context) {}
+
+// Not implemented because Fuchsia does not use interceptors.
+void InitializeInterceptors() {}
+
+// Not implemented because this is only relevant for Android.
+void AndroidTestTlsSlot() {}

[PATCH] D104082: [CodeGen] Don't create a fake FunctionDecl when generating block/block_byref copy/dispose helper functions

2021-06-15 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.

In D104082#2818281 , @ahatanak wrote:

> C++ non-virtual thunks and global initialization functions 
> (`_GLOBAL__sub_I_*`) have only linkage names.

Works for me - and the debug info codegen looks like it does handle this 
situation intentionally: 
https://github.com/llvm/llvm-project/blob/a11880468e556d20ad9b0d43a1ff43daf62d49b2/clang/lib/CodeGen/CGDebugInfo.cpp#L3896.

Maybe give it a few days (or directly ask) to see if @aprantl has further 
thoughts, since I'm not especially familiar with Objective C things, but it 
looks pretty right/good enough for me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104082

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


[PATCH] D104300: [analyzer] Handle std::swap for std::unique_ptr

2021-06-15 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:217
+  if (&BR.getBugType() != smartptr::getNullDereferenceBugType() ||
+  !BR.isInteresting(FirstArgThisRegion))
+return;

vsavchenko wrote:
> Wait, and what if the second argument is interesting?
I know. That's why I said that the note is crappy.
The question I have in mind is - what if we swap null with null? Do we want a 
note in that case?
IMO, we should have a note for every case of swapping a //confirmed// null with 
something that is //not// confirmed to be null.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104300

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


[PATCH] D104300: [analyzer] Handle std::swap for std::unique_ptr

2021-06-15 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD added a comment.

The current implementation of how notes are emitted in `handleSwap` is broken. 
Consider the following code:

  #include 
  
  void foo() {
auto ptr1 = std::unique_ptr(new int(10));
auto ptr2 = std::unique_ptr(new int(13));
ptr1.swap(ptr2);
ptr1.reset();
*ptr1;
  }

This yields the following  warning and notes:

  swap-and-reset.cpp:8:3: warning: Dereference of null smart pointer 'ptr1' 
[alpha.cplusplus.SmartPtr]
*ptr1;
^
  swap-and-reset.cpp:4:36: note: Assigning 10
auto ptr1 = std::unique_ptr(new int(10));
 ^~~
  swap-and-reset.cpp:4:15: note: Smart pointer 'ptr1' is constructed
auto ptr1 = std::unique_ptr(new int(10));
^
  swap-and-reset.cpp:5:36: note: Assigning 13
auto ptr2 = std::unique_ptr(new int(13));
 ^~~
  swap-and-reset.cpp:5:15: note: Smart pointer 'ptr2' is constructed
auto ptr2 = std::unique_ptr(new int(13));
^
  swap-and-reset.cpp:6:3: note: Swapped null smart pointer 'ptr2' with smart 
pointer 'ptr1'
ptr1.swap(ptr2);
^~~
  swap-and-reset.cpp:7:3: note: Smart pointer 'ptr1' reset using a null value
ptr1.reset();
^~~~
  swap-and-reset.cpp:8:3: note: Dereference of null smart pointer 'ptr1'
*ptr1;
^

But clearly, `ptr2` is not null.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104300

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


[PATCH] D104300: [analyzer] Handle std::swap for std::unique_ptr

2021-06-15 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD updated this revision to Diff 352201.
RedDocMD added a comment.

Refactored common code, removed note emission


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104300

Files:
  clang/lib/StaticAnalyzer/Checkers/SmartPtr.h
  clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
  clang/test/Analysis/smart-ptr-text-output.cpp

Index: clang/test/Analysis/smart-ptr-text-output.cpp
===
--- clang/test/Analysis/smart-ptr-text-output.cpp
+++ clang/test/Analysis/smart-ptr-text-output.cpp
@@ -69,20 +69,17 @@
 
 void derefOnSwappedNullPtr() {
   std::unique_ptr P(new A()); // expected-note {{Smart pointer 'P' is constructed}}
-  std::unique_ptr PNull; // expected-note {{Default constructed smart pointer 'PNull' is null}}
-  P.swap(PNull); // expected-note {{Swapped null smart pointer 'PNull' with smart pointer 'P'}}
+  std::unique_ptr PNull;
+  P.swap(PNull);
   PNull->foo(); // No warning.
   (*P).foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
   // expected-note@-1{{Dereference of null smart pointer 'P'}}
 }
 
-// FIXME: Fix this test when "std::swap" is modeled seperately.
 void derefOnStdSwappedNullPtr() {
   std::unique_ptr P; // expected-note {{Default constructed smart pointer 'P' is null}}
-  std::unique_ptr PNull; // expected-note {{Default constructed smart pointer 'PNull' is null}}
-  std::swap(P, PNull); // expected-note@Inputs/system-header-simulator-cxx.h:979 {{Swapped null smart pointer 'PNull' with smart pointer 'P'}}
-  // expected-note@-1 {{Calling 'swap'}}
-  // expected-note@-2 {{Returning from 'swap'}}
+  std::unique_ptr PNull;
+  std::swap(P, PNull);
   P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
   // expected-note@-1{{Dereference of null smart pointer 'P'}}
 }
Index: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
+++ clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
@@ -60,7 +60,7 @@
 private:
   void handleReset(const CallEvent &Call, CheckerContext &C) const;
   void handleRelease(const CallEvent &Call, CheckerContext &C) const;
-  void handleSwap(const CallEvent &Call, CheckerContext &C) const;
+  void handleSwapMethod(const CallEvent &Call, CheckerContext &C) const;
   void handleGet(const CallEvent &Call, CheckerContext &C) const;
   bool handleAssignOp(const CallEvent &Call, CheckerContext &C) const;
   bool handleMoveCtr(const CallEvent &Call, CheckerContext &C,
@@ -68,14 +68,17 @@
   bool updateMovedSmartPointers(CheckerContext &C, const MemRegion *ThisRegion,
 const MemRegion *OtherSmartPtrRegion) const;
   void handleBoolConversion(const CallEvent &Call, CheckerContext &C) const;
+  bool handleSwap(ProgramStateRef State, const MemRegion *FirstRegion,
+  const MemRegion *SecondRegion, CheckerContext &C) const;
 
   using SmartPtrMethodHandlerFn =
   void (SmartPtrModeling::*)(const CallEvent &Call, CheckerContext &) const;
   CallDescriptionMap SmartPtrMethodHandlers{
   {{"reset"}, &SmartPtrModeling::handleReset},
   {{"release"}, &SmartPtrModeling::handleRelease},
-  {{"swap", 1}, &SmartPtrModeling::handleSwap},
+  {{"swap", 1}, &SmartPtrModeling::handleSwapMethod},
   {{"get"}, &SmartPtrModeling::handleGet}};
+  const CallDescription StdSwapCall{{"std", "swap"}, 2};
 };
 } // end of anonymous namespace
 
@@ -91,11 +94,15 @@
 return false;
 
   const auto *RecordDecl = MethodDecl->getParent();
-  if (!RecordDecl || !RecordDecl->getDeclContext()->isStdNamespace())
+  return isStdSmartPtr(RecordDecl);
+}
+
+bool isStdSmartPtr(const CXXRecordDecl *RD) {
+  if (!RD || !RD->getDeclContext()->isStdNamespace())
 return false;
 
-  if (RecordDecl->getDeclName().isIdentifier()) {
-StringRef Name = RecordDecl->getName();
+  if (RD->getDeclName().isIdentifier()) {
+StringRef Name = RD->getName();
 return Name == "shared_ptr" || Name == "unique_ptr" || Name == "weak_ptr";
   }
   return false;
@@ -178,6 +185,24 @@
 bool SmartPtrModeling::evalCall(const CallEvent &Call,
 CheckerContext &C) const {
   ProgramStateRef State = C.getState();
+
+  if (Call.isCalled(StdSwapCall)) {
+// Check the first arg, if it is of std::unique_ptr type.
+assert(Call.getNumArgs() == 2 && "std::swap should have two arguments");
+const Expr *FirstArg = Call.getArgExpr(0);
+if (!smartptr::isStdSmartPtr(FirstArg->getType()->getAsCXXRecordDecl())) {
+  return false;
+}
+const MemRegion *FirstArgThisRegion = Call.getArgSVal(0).getAsRegion();
+if (!FirstArgThisRegion)
+  return false;
+const MemRegion *SecondArgThisRegion = Call.getArgSVal(1).getAsRegion();
+if (

[PATCH] D104300: [analyzer] Handle std::swap for std::unique_ptr

2021-06-15 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD added a comment.

I have gotten rid of notes for the time being.
The trouble is that, we were not figuring out whether the null-pointer 
de-reference was occurring due to the null value being swapped with the current 
pointer.
We just //assumed// that. So I am guessing we would need a visitor to figure 
that out? (Hooray for Valeriy!)
Or is there a simpler solution?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104300

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


[PATCH] D104253: [Clang][Codegen] emit noprofile IR Fn Attr for no_instrument_function Fn Attr

2021-06-15 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

For the function attributing disabling instrumentation of 
-fprofile-generate/-fprofile-instr-generate/-fcs-profile-generate/-fprofile-arcs,
 how about `no_profile`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104253

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


[PATCH] D104253: [Clang][Codegen] emit noprofile IR Fn Attr for no_instrument_function Fn Attr

2021-06-15 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers updated this revision to Diff 352208.
nickdesaulniers added a comment.

- fixup double fn attr in test as per @melver.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104253

Files:
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/test/CodeGen/fprofile-instrument.c


Index: clang/test/CodeGen/fprofile-instrument.c
===
--- /dev/null
+++ clang/test/CodeGen/fprofile-instrument.c
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -fprofile-instrument=llvm -disable-llvm-passes \
+// RUN:   -emit-llvm -o - %s | FileCheck %s
+int g(int);
+
+int __attribute__((no_instrument_function)) no_instr(int a) {
+// CHECK: define {{.*}} i32 @no_instr(i32 %a) [[ATTR:#[0-9]+]]
+  int sum = 0;
+  for (int i = 0; i < a; i++)
+sum += g(i);
+  return sum;
+}
+
+int instr(int a) {
+// CHECK: define {{.*}} i32 @instr(i32 %a) [[ATTR2:#[0-9]+]]
+  int sum = 0;
+  for (int i = 0; i < a; i++)
+sum += g(i);
+  return sum;
+}
+// CHECK: attributes [[ATTR]] = {{.*}} noprofile
+// CHECK-NOT: attributes [[ATTR2]] = {{.*}} noprofile
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -893,6 +893,9 @@
   if (D && D->hasAttr())
 Fn->addFnAttr("cfi-canonical-jump-table");
 
+  if (D && D->hasAttr())
+Fn->addFnAttr(llvm::Attribute::NoProfile);
+
   if (getLangOpts().OpenCL) {
 // Add metadata for a kernel function.
 if (const FunctionDecl *FD = dyn_cast_or_null(D))


Index: clang/test/CodeGen/fprofile-instrument.c
===
--- /dev/null
+++ clang/test/CodeGen/fprofile-instrument.c
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -fprofile-instrument=llvm -disable-llvm-passes \
+// RUN:   -emit-llvm -o - %s | FileCheck %s
+int g(int);
+
+int __attribute__((no_instrument_function)) no_instr(int a) {
+// CHECK: define {{.*}} i32 @no_instr(i32 %a) [[ATTR:#[0-9]+]]
+  int sum = 0;
+  for (int i = 0; i < a; i++)
+sum += g(i);
+  return sum;
+}
+
+int instr(int a) {
+// CHECK: define {{.*}} i32 @instr(i32 %a) [[ATTR2:#[0-9]+]]
+  int sum = 0;
+  for (int i = 0; i < a; i++)
+sum += g(i);
+  return sum;
+}
+// CHECK: attributes [[ATTR]] = {{.*}} noprofile
+// CHECK-NOT: attributes [[ATTR2]] = {{.*}} noprofile
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -893,6 +893,9 @@
   if (D && D->hasAttr())
 Fn->addFnAttr("cfi-canonical-jump-table");
 
+  if (D && D->hasAttr())
+Fn->addFnAttr(llvm::Attribute::NoProfile);
+
   if (getLangOpts().OpenCL) {
 // Add metadata for a kernel function.
 if (const FunctionDecl *FD = dyn_cast_or_null(D))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104222: [clang-format] [PR50702] Lamdba processing does not respect AfterClass and AfterNamespace

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

Just asking: Would it be different if there is `auto`, `decltype(auto)`, 
`decltype(a+b)`, `typename` or `template` as trailing return type?


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

https://reviews.llvm.org/D104222

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


  1   2   >