[PATCH] D129258: [clang-offload-bundler][NFC] Library-ize ClangOffloadBundler (4/4)

2022-07-07 Thread Jacob Lambert via Phabricator via cfe-commits
lamb-j created this revision.
Herald added a subscriber: mgorny.
Herald added a project: All.
lamb-j requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

Lifting the core functionalities of the clang-offload-bundler into a
user-facing library/API.

This NFC patch (4/4) moves the API files from
clang/tools/clang-offload-bundler into clang/lib/Driver and
clang/include/clang/Driver.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129258

Files:
  clang/include/clang/Driver/OffloadBundler.h
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/OffloadBundler.cpp
  clang/tools/clang-offload-bundler/CMakeLists.txt
  clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
  clang/tools/clang-offload-bundler/OffloadBundler.cpp
  clang/tools/clang-offload-bundler/OffloadBundler.h

Index: clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
===
--- clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
+++ clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
@@ -7,15 +7,14 @@
 //===--===//
 ///
 /// \file
-/// This file implements a clang-offload-bundler that bundles different
-/// files that relate with the same source code but different targets into a
-/// single one. Also the implements the opposite functionality, i.e. unbundle
-/// files previous created by this tool.
+/// This file implements a stand-alone clang-offload-bundler tool using the
+/// OffloadBundler API.
 ///
 //===--===//
 
 #include "clang/Basic/Cuda.h"
 #include "clang/Basic/Version.h"
+#include "clang/Driver/OffloadBundler.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
@@ -52,7 +51,6 @@
 #include 
 #include 
 #include 
-#include "OffloadBundler.h"
 
 using namespace llvm;
 using namespace llvm::object;
Index: clang/tools/clang-offload-bundler/CMakeLists.txt
===
--- clang/tools/clang-offload-bundler/CMakeLists.txt
+++ clang/tools/clang-offload-bundler/CMakeLists.txt
@@ -2,7 +2,6 @@
 
 add_clang_tool(clang-offload-bundler
   ClangOffloadBundler.cpp
-  OffloadBundler.cpp
 
   DEPENDS
   intrinsics_gen
@@ -10,6 +9,7 @@
 
 set(CLANG_OFFLOAD_BUNDLER_LIB_DEPS
   clangBasic
+  clangDriver
   )
 
 add_dependencies(clang clang-offload-bundler)
Index: clang/lib/Driver/OffloadBundler.cpp
===
--- clang/lib/Driver/OffloadBundler.cpp
+++ clang/lib/Driver/OffloadBundler.cpp
@@ -1,4 +1,4 @@
-//===-- clang-offload-bundler/ClangOffloadBundler.cpp -===//
+//===- OffloadBundler.cpp - File Bundling and Unbundling --===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -7,15 +7,16 @@
 //===--===//
 ///
 /// \file
-/// This file implements a clang-offload-bundler that bundles different
-/// files that relate with the same source code but different targets into a
-/// single one. Also the implements the opposite functionality, i.e. unbundle
-/// files previous created by this tool.
+/// This file implements an offload bundling API that bundles different files
+/// that relate with the same source code but different targets into a single
+/// one. Also the implements the opposite functionality, i.e. unbundle files
+/// previous created by this API.
 ///
 //===--===//
 
 #include "clang/Basic/Cuda.h"
 #include "clang/Basic/Version.h"
+#include "clang/Driver/OffloadBundler.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
@@ -53,8 +54,6 @@
 #include 
 #include 
 
-#include "OffloadBundler.h"
-
 using namespace llvm;
 using namespace llvm::object;
 
Index: clang/lib/Driver/CMakeLists.txt
===
--- clang/lib/Driver/CMakeLists.txt
+++ clang/lib/Driver/CMakeLists.txt
@@ -20,6 +20,7 @@
   DriverOptions.cpp
   Job.cpp
   Multilib.cpp
+  OffloadBundler.cpp
   OptionUtils.cpp
   Phases.cpp
   SanitizerArgs.cpp
Index: clang/include/clang/Driver/OffloadBundler.h
===
--- clang/include/clang/Driver/OffloadBundler.h
+++ clang/include/clang/Driver/OffloadBundler.h
@@ -1,4 +1,4 @@
-//===-- clang-offload-bundler/OffloadBundler.h ===//
+//=== -OffloadBundler.h - File Bundling and Unbundling --*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for l

[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs

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

I feel obliged to point out that the sheer number of updates is too large. 
Every update triggers an email to all reviewers and subscribers, so please be 
mindful. Personally I don't mind how many updates I receive, but others may do.
It's usually not too bad to have too many reviewers (having too few reviewers 
can be more of a problem at times).
I don't know how you added reviewers or whether you got upset after I clicked 
"Request Changes".

https://llvm.org/docs/CodeReview.html#lgtm-how-a-patch-is-accepted "Please also 
be mindful of weekends and major holidays."
July 4 is a federal holiday in the United States, so many folks may not be 
responsive during the long weekend.
(For my case I just finished my trip mode.)

I haven't taken a second deep look at this patch but the 
`applyAlongResolverPath` change looks too intrusive to me. One previous version 
seems more favorable to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129009

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


[clang] 14c30c7 - [clang-format] Avoid crash in LevelIndentTracker.

2022-07-07 Thread Marek Kurdej via cfe-commits

Author: Marek Kurdej
Date: 2022-07-07T10:15:45+02:00
New Revision: 14c30c70c4595d8f410c74a72357a5a31fdd5507

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

LOG: [clang-format] Avoid crash in LevelIndentTracker.

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

Reviewed By: HazardyKnusperkeks, owenpan, MyDeveloperDay

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

Added: 


Modified: 
clang/lib/Format/UnwrappedLineFormatter.cpp
clang/unittests/Format/FormatTestSelective.cpp

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineFormatter.cpp 
b/clang/lib/Format/UnwrappedLineFormatter.cpp
index 22509a5042465..9a6f8884fcec3 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -66,7 +66,6 @@ class LevelIndentTracker {
   (Style.PPIndentWidth >= 0) ? Style.PPIndentWidth : Style.IndentWidth;
   Indent = Line.Level * IndentWidth + AdditionalIndent;
 } else {
-  IndentForLevel.resize(Line.Level + 1);
   Indent = getIndent(Line.Level);
 }
 if (static_cast(Indent) + Offset >= 0)
@@ -91,6 +90,7 @@ class LevelIndentTracker {
 unsigned LevelIndent = Line.First->OriginalColumn;
 if (static_cast(LevelIndent) - Offset >= 0)
   LevelIndent -= Offset;
+assert(Line.Level < IndentForLevel.size());
 if ((!Line.First->is(tok::comment) || IndentForLevel[Line.Level] == -1) &&
 !Line.InPPDirective) {
   IndentForLevel[Line.Level] = LevelIndent;

diff  --git a/clang/unittests/Format/FormatTestSelective.cpp 
b/clang/unittests/Format/FormatTestSelective.cpp
index 2725e4cf776f6..86ed7aba1913d 100644
--- a/clang/unittests/Format/FormatTestSelective.cpp
+++ b/clang/unittests/Format/FormatTestSelective.cpp
@@ -609,6 +609,14 @@ TEST_F(FormatTestSelective, DontAssert) {
  "  return a == 8 ? 32 : 16;\n"
  "}\n";
   EXPECT_EQ(Code, format(Code, 40, 0));
+
+  // https://llvm.org/PR56352
+  Style.CompactNamespaces = true;
+  Style.NamespaceIndentation = FormatStyle::NI_All;
+  Code = "\n"
+ "namespace ns1 { namespace ns2 {\n"
+ "}}";
+  EXPECT_EQ(Code, format(Code, 0, 0));
 }
 
 } // end namespace



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


[PATCH] D129064: [clang-format] Avoid crash in LevelIndentTracker.

2022-07-07 Thread Marek Kurdej via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG14c30c70c459: [clang-format] Avoid crash in 
LevelIndentTracker. (authored by curdeius).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129064

Files:
  clang/lib/Format/UnwrappedLineFormatter.cpp
  clang/unittests/Format/FormatTestSelective.cpp


Index: clang/unittests/Format/FormatTestSelective.cpp
===
--- clang/unittests/Format/FormatTestSelective.cpp
+++ clang/unittests/Format/FormatTestSelective.cpp
@@ -609,6 +609,14 @@
  "  return a == 8 ? 32 : 16;\n"
  "}\n";
   EXPECT_EQ(Code, format(Code, 40, 0));
+
+  // https://llvm.org/PR56352
+  Style.CompactNamespaces = true;
+  Style.NamespaceIndentation = FormatStyle::NI_All;
+  Code = "\n"
+ "namespace ns1 { namespace ns2 {\n"
+ "}}";
+  EXPECT_EQ(Code, format(Code, 0, 0));
 }
 
 } // end namespace
Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -66,7 +66,6 @@
   (Style.PPIndentWidth >= 0) ? Style.PPIndentWidth : Style.IndentWidth;
   Indent = Line.Level * IndentWidth + AdditionalIndent;
 } else {
-  IndentForLevel.resize(Line.Level + 1);
   Indent = getIndent(Line.Level);
 }
 if (static_cast(Indent) + Offset >= 0)
@@ -91,6 +90,7 @@
 unsigned LevelIndent = Line.First->OriginalColumn;
 if (static_cast(LevelIndent) - Offset >= 0)
   LevelIndent -= Offset;
+assert(Line.Level < IndentForLevel.size());
 if ((!Line.First->is(tok::comment) || IndentForLevel[Line.Level] == -1) &&
 !Line.InPPDirective) {
   IndentForLevel[Line.Level] = LevelIndent;


Index: clang/unittests/Format/FormatTestSelective.cpp
===
--- clang/unittests/Format/FormatTestSelective.cpp
+++ clang/unittests/Format/FormatTestSelective.cpp
@@ -609,6 +609,14 @@
  "  return a == 8 ? 32 : 16;\n"
  "}\n";
   EXPECT_EQ(Code, format(Code, 40, 0));
+
+  // https://llvm.org/PR56352
+  Style.CompactNamespaces = true;
+  Style.NamespaceIndentation = FormatStyle::NI_All;
+  Code = "\n"
+ "namespace ns1 { namespace ns2 {\n"
+ "}}";
+  EXPECT_EQ(Code, format(Code, 0, 0));
 }
 
 } // end namespace
Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -66,7 +66,6 @@
   (Style.PPIndentWidth >= 0) ? Style.PPIndentWidth : Style.IndentWidth;
   Indent = Line.Level * IndentWidth + AdditionalIndent;
 } else {
-  IndentForLevel.resize(Line.Level + 1);
   Indent = getIndent(Line.Level);
 }
 if (static_cast(Indent) + Offset >= 0)
@@ -91,6 +90,7 @@
 unsigned LevelIndent = Line.First->OriginalColumn;
 if (static_cast(LevelIndent) - Offset >= 0)
   LevelIndent -= Offset;
+assert(Line.Level < IndentForLevel.size());
 if ((!Line.First->is(tok::comment) || IndentForLevel[Line.Level] == -1) &&
 !Line.InPPDirective) {
   IndentForLevel[Line.Level] = LevelIndent;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129180: [clang][dataflow] Return a solution from the solver when `Constraints` are `Satisfiable`.

2022-07-07 Thread weiyi via Phabricator via cfe-commits
wyt updated this revision to Diff 442824.
wyt added a comment.

Address comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129180

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
  clang/include/clang/Analysis/FlowSensitive/Solver.h
  clang/lib/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp
  clang/unittests/Analysis/FlowSensitive/SolverTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
@@ -20,6 +20,12 @@
 using namespace clang;
 using namespace dataflow;
 
+using testing::_;
+using testing::AnyOf;
+using testing::Optional;
+using testing::Pair;
+using testing::UnorderedElementsAre;
+
 class SolverTest : public ::testing::Test {
 protected:
   // Checks if the conjunction of `Vals` is satisfiable and returns the
@@ -64,6 +70,17 @@
 return conj(impl(LeftSubVal, RightSubVal), impl(RightSubVal, LeftSubVal));
   }
 
+  void expectUnsatisfiable(Solver::Result Result) {
+EXPECT_EQ(Result.getStatus(), Solver::Result::Status::Unsatisfiable);
+EXPECT_FALSE(Result.getSolution().has_value());
+  }
+
+  template 
+  void expectSatisfiable(Solver::Result Result, Matcher Solution) {
+EXPECT_EQ(Result.getStatus(), Solver::Result::Status::Satisfiable);
+EXPECT_THAT(Result.getSolution(), Optional(Solution));
+  }
+
 private:
   std::vector> Vals;
 };
@@ -72,7 +89,9 @@
   auto X = atom();
 
   // X
-  EXPECT_EQ(solve({X}), Solver::Result::Satisfiable);
+  expectSatisfiable(
+  solve({X}),
+  UnorderedElementsAre(Pair(X, Solver::Result::Assignment::AssignedTrue)));
 }
 
 TEST_F(SolverTest, NegatedVar) {
@@ -80,7 +99,9 @@
   auto NotX = neg(X);
 
   // !X
-  EXPECT_EQ(solve({NotX}), Solver::Result::Satisfiable);
+  expectSatisfiable(
+  solve({NotX}),
+  UnorderedElementsAre(Pair(X, Solver::Result::Assignment::AssignedFalse)));
 }
 
 TEST_F(SolverTest, UnitConflict) {
@@ -88,7 +109,7 @@
   auto NotX = neg(X);
 
   // X ^ !X
-  EXPECT_EQ(solve({X, NotX}), Solver::Result::Unsatisfiable);
+  expectUnsatisfiable(solve({X, NotX}));
 }
 
 TEST_F(SolverTest, DistinctVars) {
@@ -97,7 +118,10 @@
   auto NotY = neg(Y);
 
   // X ^ !Y
-  EXPECT_EQ(solve({X, NotY}), Solver::Result::Satisfiable);
+  expectSatisfiable(
+  solve({X, NotY}),
+  UnorderedElementsAre(Pair(X, Solver::Result::Assignment::AssignedTrue),
+   Pair(Y, Solver::Result::Assignment::AssignedFalse)));
 }
 
 TEST_F(SolverTest, DoubleNegation) {
@@ -106,7 +130,7 @@
   auto NotNotX = neg(NotX);
 
   // !!X ^ !X
-  EXPECT_EQ(solve({NotNotX, NotX}), Solver::Result::Unsatisfiable);
+  expectUnsatisfiable(solve({NotNotX, NotX}));
 }
 
 TEST_F(SolverTest, NegatedDisjunction) {
@@ -116,7 +140,7 @@
   auto NotXOrY = neg(XOrY);
 
   // !(X v Y) ^ (X v Y)
-  EXPECT_EQ(solve({NotXOrY, XOrY}), Solver::Result::Unsatisfiable);
+  expectUnsatisfiable(solve({NotXOrY, XOrY}));
 }
 
 TEST_F(SolverTest, NegatedConjunction) {
@@ -126,7 +150,7 @@
   auto NotXAndY = neg(XAndY);
 
   // !(X ^ Y) ^ (X ^ Y)
-  EXPECT_EQ(solve({NotXAndY, XAndY}), Solver::Result::Unsatisfiable);
+  expectUnsatisfiable(solve({NotXAndY, XAndY}));
 }
 
 TEST_F(SolverTest, DisjunctionSameVars) {
@@ -135,7 +159,7 @@
   auto XOrNotX = disj(X, NotX);
 
   // X v !X
-  EXPECT_EQ(solve({XOrNotX}), Solver::Result::Satisfiable);
+  expectSatisfiable(solve({XOrNotX}), _);
 }
 
 TEST_F(SolverTest, ConjunctionSameVarsConflict) {
@@ -144,7 +168,7 @@
   auto XAndNotX = conj(X, NotX);
 
   // X ^ !X
-  EXPECT_EQ(solve({XAndNotX}), Solver::Result::Unsatisfiable);
+  expectUnsatisfiable(solve({XAndNotX}));
 }
 
 TEST_F(SolverTest, PureVar) {
@@ -156,7 +180,10 @@
   auto NotXOrNotY = disj(NotX, NotY);
 
   // (!X v Y) ^ (!X v !Y)
-  EXPECT_EQ(solve({NotXOrY, NotXOrNotY}), Solver::Result::Satisfiable);
+  expectSatisfiable(
+  solve({NotXOrY, NotXOrNotY}),
+  UnorderedElementsAre(Pair(X, Solver::Result::Assignment::AssignedFalse),
+   Pair(Y, _)));
 }
 
 TEST_F(SolverTest, MustAssumeVarIsFalse) {
@@ -169,7 +196,10 @@
   auto NotXOrNotY = disj(NotX, NotY);
 
   // (X v Y) ^ (!X v Y) ^ (!X v !Y)
-  EXPECT_EQ(solve({XOrY, NotXOrY, NotXOrNotY}), Solver::Result::Satisfiable);
+  expectSatisfiable(
+  solve({XOrY, NotXOrY, NotXOrNotY}),
+  UnorderedElementsAre(Pair(X, Solver::Result::Assignment::AssignedFalse),
+   Pair(Y, Solver::Result::Assignment::AssignedTrue)));
 }
 
 TEST_F(SolverTest, DeepConflict) {
@@ -183,8 +213,7 @@
   auto XOrNotY = disj(X, NotY);
 
   // (X v Y) ^ (!X v Y) ^ (!X v !Y) ^ (X v !Y)
-  EXPECT_EQ(solve({XOrY, NotXOrY, NotXOrNotY, XOrNotY}),
-Solver::Result::Unsatisfiable);
+  expectUnsatisfiable(solve({XOrY, NotXOrY, NotXOrNotY, XOrNotY}));
 }
 
 TEST_F(

[PATCH] D129170: [Sema] Add deprecation warnings for some compiler provided __has_* type traits

2022-07-07 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson marked 3 inline comments as done.
royjacobson added inline comments.



Comment at: clang/lib/Sema/SemaExprCXX.cpp:5400-5401
+SourceLocation KWLoc) {
+  if (!S.getLangOpts().CPlusPlus11)
+return;
+

erichkeane wrote:
> royjacobson wrote:
> > aaron.ballman wrote:
> > > I think we should always warn on these, not just in C++11.
> > I'm not convinced we should. My reasoning is that we need a pretty good 
> > reason to start issuing warnings for 20 years old code. The usage of those 
> > builtins with deleted functions after C++11 is pretty broken which is a 
> > pretty good reason, but for earlier language versions they work 'fine' and 
> > if people want to use C++03 I prefer leaving them at peace :)
> > 
> > People on C++03 are also probably using pretty old versions of libstdc++ 
> > and/or boost type_traits, so this could have some impact.
> > 
> > WDYT?
> > 
> warnings don't get emitted for code in header files, so at least that part 
> isn't a concern.  
Any header files, or just system headers?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129170

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


[PATCH] D129180: [clang][dataflow] Return a solution from the solver when `Constraints` are `Satisfiable`.

2022-07-07 Thread weiyi via Phabricator via cfe-commits
wyt updated this revision to Diff 442825.
wyt marked 3 inline comments as done.
wyt added a comment.

Typo fix.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129180

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
  clang/include/clang/Analysis/FlowSensitive/Solver.h
  clang/lib/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp
  clang/unittests/Analysis/FlowSensitive/SolverTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
@@ -20,6 +20,12 @@
 using namespace clang;
 using namespace dataflow;
 
+using testing::_;
+using testing::AnyOf;
+using testing::Optional;
+using testing::Pair;
+using testing::UnorderedElementsAre;
+
 class SolverTest : public ::testing::Test {
 protected:
   // Checks if the conjunction of `Vals` is satisfiable and returns the
@@ -64,6 +70,17 @@
 return conj(impl(LeftSubVal, RightSubVal), impl(RightSubVal, LeftSubVal));
   }
 
+  void expectUnsatisfiable(Solver::Result Result) {
+EXPECT_EQ(Result.getStatus(), Solver::Result::Status::Unsatisfiable);
+EXPECT_FALSE(Result.getSolution().has_value());
+  }
+
+  template 
+  void expectSatisfiable(Solver::Result Result, Matcher Solution) {
+EXPECT_EQ(Result.getStatus(), Solver::Result::Status::Satisfiable);
+EXPECT_THAT(Result.getSolution(), Optional(Solution));
+  }
+
 private:
   std::vector> Vals;
 };
@@ -72,7 +89,9 @@
   auto X = atom();
 
   // X
-  EXPECT_EQ(solve({X}), Solver::Result::Satisfiable);
+  expectSatisfiable(
+  solve({X}),
+  UnorderedElementsAre(Pair(X, Solver::Result::Assignment::AssignedTrue)));
 }
 
 TEST_F(SolverTest, NegatedVar) {
@@ -80,7 +99,9 @@
   auto NotX = neg(X);
 
   // !X
-  EXPECT_EQ(solve({NotX}), Solver::Result::Satisfiable);
+  expectSatisfiable(
+  solve({NotX}),
+  UnorderedElementsAre(Pair(X, Solver::Result::Assignment::AssignedFalse)));
 }
 
 TEST_F(SolverTest, UnitConflict) {
@@ -88,7 +109,7 @@
   auto NotX = neg(X);
 
   // X ^ !X
-  EXPECT_EQ(solve({X, NotX}), Solver::Result::Unsatisfiable);
+  expectUnsatisfiable(solve({X, NotX}));
 }
 
 TEST_F(SolverTest, DistinctVars) {
@@ -97,7 +118,10 @@
   auto NotY = neg(Y);
 
   // X ^ !Y
-  EXPECT_EQ(solve({X, NotY}), Solver::Result::Satisfiable);
+  expectSatisfiable(
+  solve({X, NotY}),
+  UnorderedElementsAre(Pair(X, Solver::Result::Assignment::AssignedTrue),
+   Pair(Y, Solver::Result::Assignment::AssignedFalse)));
 }
 
 TEST_F(SolverTest, DoubleNegation) {
@@ -106,7 +130,7 @@
   auto NotNotX = neg(NotX);
 
   // !!X ^ !X
-  EXPECT_EQ(solve({NotNotX, NotX}), Solver::Result::Unsatisfiable);
+  expectUnsatisfiable(solve({NotNotX, NotX}));
 }
 
 TEST_F(SolverTest, NegatedDisjunction) {
@@ -116,7 +140,7 @@
   auto NotXOrY = neg(XOrY);
 
   // !(X v Y) ^ (X v Y)
-  EXPECT_EQ(solve({NotXOrY, XOrY}), Solver::Result::Unsatisfiable);
+  expectUnsatisfiable(solve({NotXOrY, XOrY}));
 }
 
 TEST_F(SolverTest, NegatedConjunction) {
@@ -126,7 +150,7 @@
   auto NotXAndY = neg(XAndY);
 
   // !(X ^ Y) ^ (X ^ Y)
-  EXPECT_EQ(solve({NotXAndY, XAndY}), Solver::Result::Unsatisfiable);
+  expectUnsatisfiable(solve({NotXAndY, XAndY}));
 }
 
 TEST_F(SolverTest, DisjunctionSameVars) {
@@ -135,7 +159,7 @@
   auto XOrNotX = disj(X, NotX);
 
   // X v !X
-  EXPECT_EQ(solve({XOrNotX}), Solver::Result::Satisfiable);
+  expectSatisfiable(solve({XOrNotX}), _);
 }
 
 TEST_F(SolverTest, ConjunctionSameVarsConflict) {
@@ -144,7 +168,7 @@
   auto XAndNotX = conj(X, NotX);
 
   // X ^ !X
-  EXPECT_EQ(solve({XAndNotX}), Solver::Result::Unsatisfiable);
+  expectUnsatisfiable(solve({XAndNotX}));
 }
 
 TEST_F(SolverTest, PureVar) {
@@ -156,7 +180,10 @@
   auto NotXOrNotY = disj(NotX, NotY);
 
   // (!X v Y) ^ (!X v !Y)
-  EXPECT_EQ(solve({NotXOrY, NotXOrNotY}), Solver::Result::Satisfiable);
+  expectSatisfiable(
+  solve({NotXOrY, NotXOrNotY}),
+  UnorderedElementsAre(Pair(X, Solver::Result::Assignment::AssignedFalse),
+   Pair(Y, _)));
 }
 
 TEST_F(SolverTest, MustAssumeVarIsFalse) {
@@ -169,7 +196,10 @@
   auto NotXOrNotY = disj(NotX, NotY);
 
   // (X v Y) ^ (!X v Y) ^ (!X v !Y)
-  EXPECT_EQ(solve({XOrY, NotXOrY, NotXOrNotY}), Solver::Result::Satisfiable);
+  expectSatisfiable(
+  solve({XOrY, NotXOrY, NotXOrNotY}),
+  UnorderedElementsAre(Pair(X, Solver::Result::Assignment::AssignedFalse),
+   Pair(Y, Solver::Result::Assignment::AssignedTrue)));
 }
 
 TEST_F(SolverTest, DeepConflict) {
@@ -183,8 +213,7 @@
   auto XOrNotY = disj(X, NotY);
 
   // (X v Y) ^ (!X v Y) ^ (!X v !Y) ^ (X v !Y)
-  EXPECT_EQ(solve({XOrY, NotXOrY, NotXOrNotY, XOrNotY}),
-Solver::Result::Unsatisfiable);
+  expectUnsatisfiable(solve({XOrY, NotXOrY, NotXOrN

[PATCH] D129008: [Clang][OpenMP] Fix the issue that globalization doesn't work with byval struct function argument

2022-07-07 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

In D129008#3634073 , @jdoerfert wrote:

> cleanup/destructor test missing.
>
> @ABataev WDYT?

Looks good in general, extra tests would be good


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129008

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


[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs

2022-07-07 Thread Schrodinger ZHU Yifan via Phabricator via cfe-commits
SchrodingerZhu added a comment.

First of all, I am really sorry about the noise and the misbehavior here. I 
have to admit that some of the changes here are because I am still in the way 
of getting familiar with the patch system. I apologize for being careless in 
the progress.

> I don't know how you added reviewers or whether you got upset after I clicked 
> "Request Changes".

I am very glad to recieve any review from you and any other member from the 
team! It is just that I saw you push some commits to the monorepo recently, so 
I thought that you were too busy to review the patch. Again, I am sorry for the 
confusion.

> I haven't taken a second deep look at this patch but the 
> applyAlongResolverPath change looks too intrusive to me. One previous version 
> seems more favorable to me.

Back to the patch itself, I made the changes because in the previous version, I 
assumed that, along the de-aliasing path to the `resolver` object, the 
immediate instance of `Constant*` need to be `GlobalObject` or `GlobalAlias`; 
but the `resolver` is stored as a `Constant *`, behind which, according to the 
implementation of `findBaseObject`, can also be instantiated as `Expr`.

I am looking forward to your suggestions, on the code and on how to follow the 
community conventions better!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129009

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


[PATCH] D129180: [clang][dataflow] Return a solution from the solver when `Constraints` are `Satisfiable`.

2022-07-07 Thread weiyi via Phabricator via cfe-commits
wyt updated this revision to Diff 442828.
wyt added a comment.

Make scope resolution consistent (Solver:: instead of WatchedLiteralsSolver::).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129180

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
  clang/include/clang/Analysis/FlowSensitive/Solver.h
  clang/lib/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp
  clang/unittests/Analysis/FlowSensitive/SolverTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
@@ -20,6 +20,12 @@
 using namespace clang;
 using namespace dataflow;
 
+using testing::_;
+using testing::AnyOf;
+using testing::Optional;
+using testing::Pair;
+using testing::UnorderedElementsAre;
+
 class SolverTest : public ::testing::Test {
 protected:
   // Checks if the conjunction of `Vals` is satisfiable and returns the
@@ -64,6 +70,17 @@
 return conj(impl(LeftSubVal, RightSubVal), impl(RightSubVal, LeftSubVal));
   }
 
+  void expectUnsatisfiable(Solver::Result Result) {
+EXPECT_EQ(Result.getStatus(), Solver::Result::Status::Unsatisfiable);
+EXPECT_FALSE(Result.getSolution().has_value());
+  }
+
+  template 
+  void expectSatisfiable(Solver::Result Result, Matcher Solution) {
+EXPECT_EQ(Result.getStatus(), Solver::Result::Status::Satisfiable);
+EXPECT_THAT(Result.getSolution(), Optional(Solution));
+  }
+
 private:
   std::vector> Vals;
 };
@@ -72,7 +89,9 @@
   auto X = atom();
 
   // X
-  EXPECT_EQ(solve({X}), Solver::Result::Satisfiable);
+  expectSatisfiable(
+  solve({X}),
+  UnorderedElementsAre(Pair(X, Solver::Result::Assignment::AssignedTrue)));
 }
 
 TEST_F(SolverTest, NegatedVar) {
@@ -80,7 +99,9 @@
   auto NotX = neg(X);
 
   // !X
-  EXPECT_EQ(solve({NotX}), Solver::Result::Satisfiable);
+  expectSatisfiable(
+  solve({NotX}),
+  UnorderedElementsAre(Pair(X, Solver::Result::Assignment::AssignedFalse)));
 }
 
 TEST_F(SolverTest, UnitConflict) {
@@ -88,7 +109,7 @@
   auto NotX = neg(X);
 
   // X ^ !X
-  EXPECT_EQ(solve({X, NotX}), Solver::Result::Unsatisfiable);
+  expectUnsatisfiable(solve({X, NotX}));
 }
 
 TEST_F(SolverTest, DistinctVars) {
@@ -97,7 +118,10 @@
   auto NotY = neg(Y);
 
   // X ^ !Y
-  EXPECT_EQ(solve({X, NotY}), Solver::Result::Satisfiable);
+  expectSatisfiable(
+  solve({X, NotY}),
+  UnorderedElementsAre(Pair(X, Solver::Result::Assignment::AssignedTrue),
+   Pair(Y, Solver::Result::Assignment::AssignedFalse)));
 }
 
 TEST_F(SolverTest, DoubleNegation) {
@@ -106,7 +130,7 @@
   auto NotNotX = neg(NotX);
 
   // !!X ^ !X
-  EXPECT_EQ(solve({NotNotX, NotX}), Solver::Result::Unsatisfiable);
+  expectUnsatisfiable(solve({NotNotX, NotX}));
 }
 
 TEST_F(SolverTest, NegatedDisjunction) {
@@ -116,7 +140,7 @@
   auto NotXOrY = neg(XOrY);
 
   // !(X v Y) ^ (X v Y)
-  EXPECT_EQ(solve({NotXOrY, XOrY}), Solver::Result::Unsatisfiable);
+  expectUnsatisfiable(solve({NotXOrY, XOrY}));
 }
 
 TEST_F(SolverTest, NegatedConjunction) {
@@ -126,7 +150,7 @@
   auto NotXAndY = neg(XAndY);
 
   // !(X ^ Y) ^ (X ^ Y)
-  EXPECT_EQ(solve({NotXAndY, XAndY}), Solver::Result::Unsatisfiable);
+  expectUnsatisfiable(solve({NotXAndY, XAndY}));
 }
 
 TEST_F(SolverTest, DisjunctionSameVars) {
@@ -135,7 +159,7 @@
   auto XOrNotX = disj(X, NotX);
 
   // X v !X
-  EXPECT_EQ(solve({XOrNotX}), Solver::Result::Satisfiable);
+  expectSatisfiable(solve({XOrNotX}), _);
 }
 
 TEST_F(SolverTest, ConjunctionSameVarsConflict) {
@@ -144,7 +168,7 @@
   auto XAndNotX = conj(X, NotX);
 
   // X ^ !X
-  EXPECT_EQ(solve({XAndNotX}), Solver::Result::Unsatisfiable);
+  expectUnsatisfiable(solve({XAndNotX}));
 }
 
 TEST_F(SolverTest, PureVar) {
@@ -156,7 +180,10 @@
   auto NotXOrNotY = disj(NotX, NotY);
 
   // (!X v Y) ^ (!X v !Y)
-  EXPECT_EQ(solve({NotXOrY, NotXOrNotY}), Solver::Result::Satisfiable);
+  expectSatisfiable(
+  solve({NotXOrY, NotXOrNotY}),
+  UnorderedElementsAre(Pair(X, Solver::Result::Assignment::AssignedFalse),
+   Pair(Y, _)));
 }
 
 TEST_F(SolverTest, MustAssumeVarIsFalse) {
@@ -169,7 +196,10 @@
   auto NotXOrNotY = disj(NotX, NotY);
 
   // (X v Y) ^ (!X v Y) ^ (!X v !Y)
-  EXPECT_EQ(solve({XOrY, NotXOrY, NotXOrNotY}), Solver::Result::Satisfiable);
+  expectSatisfiable(
+  solve({XOrY, NotXOrY, NotXOrNotY}),
+  UnorderedElementsAre(Pair(X, Solver::Result::Assignment::AssignedFalse),
+   Pair(Y, Solver::Result::Assignment::AssignedTrue)));
 }
 
 TEST_F(SolverTest, DeepConflict) {
@@ -183,8 +213,7 @@
   auto XOrNotY = disj(X, NotY);
 
   // (X v Y) ^ (!X v Y) ^ (!X v !Y) ^ (X v !Y)
-  EXPECT_EQ(solve({XOrY, NotXOrY, NotXOrNotY, XOrNotY}),
-Solver::Result::Unsatisfiable);
+  expectUnsatisfiab

[PATCH] D129180: [clang][dataflow] Return a solution from the solver when `Constraints` are `Satisfiable`.

2022-07-07 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 accepted this revision.
gribozavr2 added inline comments.
This revision is now accepted and ready to land.



Comment at: 
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h:266
+  /// - `Unsatisfiable`: A satisfying assignment does not exist.
+  /// - `TimedOut`: The search for a satisfying assignment was uncompleted.
   Solver::Result querySolver(llvm::DenseSet Constraints);




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129180

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


[PATCH] D129180: [clang][dataflow] Return a solution from the solver when `Constraints` are `Satisfiable`.

2022-07-07 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev accepted this revision.
sgatev added inline comments.



Comment at: clang/include/clang/Analysis/FlowSensitive/Solver.h:78
+Status Status;
+std::optional> Solution;
   };

`#include "llvm/ADT/DenseMap.h"`



Comment at: clang/lib/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp:200
 
   if (!SubValsToVar.try_emplace(Val, NextVar).second)
 continue;

Let's create a local `Var` variable initialized to `NextVar` and use that here 
and below, where `NextVar - 1` is currently used.



Comment at: clang/lib/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp:471-472
 private:
+  // Returns a satisfying truth assignment to the atomic values in the boolean
+  // formula.
+  llvm::DenseMap




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129180

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


[PATCH] D129180: [clang][dataflow] Return a solution from the solver when `Constraints` are `Satisfiable`.

2022-07-07 Thread weiyi via Phabricator via cfe-commits
wyt updated this revision to Diff 442840.
wyt marked 3 inline comments as done.
wyt added a comment.

Address comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129180

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
  clang/include/clang/Analysis/FlowSensitive/Solver.h
  clang/lib/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp
  clang/unittests/Analysis/FlowSensitive/SolverTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
@@ -20,6 +20,12 @@
 using namespace clang;
 using namespace dataflow;
 
+using testing::_;
+using testing::AnyOf;
+using testing::Optional;
+using testing::Pair;
+using testing::UnorderedElementsAre;
+
 class SolverTest : public ::testing::Test {
 protected:
   // Checks if the conjunction of `Vals` is satisfiable and returns the
@@ -64,6 +70,17 @@
 return conj(impl(LeftSubVal, RightSubVal), impl(RightSubVal, LeftSubVal));
   }
 
+  void expectUnsatisfiable(Solver::Result Result) {
+EXPECT_EQ(Result.getStatus(), Solver::Result::Status::Unsatisfiable);
+EXPECT_FALSE(Result.getSolution().has_value());
+  }
+
+  template 
+  void expectSatisfiable(Solver::Result Result, Matcher Solution) {
+EXPECT_EQ(Result.getStatus(), Solver::Result::Status::Satisfiable);
+EXPECT_THAT(Result.getSolution(), Optional(Solution));
+  }
+
 private:
   std::vector> Vals;
 };
@@ -72,7 +89,9 @@
   auto X = atom();
 
   // X
-  EXPECT_EQ(solve({X}), Solver::Result::Satisfiable);
+  expectSatisfiable(
+  solve({X}),
+  UnorderedElementsAre(Pair(X, Solver::Result::Assignment::AssignedTrue)));
 }
 
 TEST_F(SolverTest, NegatedVar) {
@@ -80,7 +99,9 @@
   auto NotX = neg(X);
 
   // !X
-  EXPECT_EQ(solve({NotX}), Solver::Result::Satisfiable);
+  expectSatisfiable(
+  solve({NotX}),
+  UnorderedElementsAre(Pair(X, Solver::Result::Assignment::AssignedFalse)));
 }
 
 TEST_F(SolverTest, UnitConflict) {
@@ -88,7 +109,7 @@
   auto NotX = neg(X);
 
   // X ^ !X
-  EXPECT_EQ(solve({X, NotX}), Solver::Result::Unsatisfiable);
+  expectUnsatisfiable(solve({X, NotX}));
 }
 
 TEST_F(SolverTest, DistinctVars) {
@@ -97,7 +118,10 @@
   auto NotY = neg(Y);
 
   // X ^ !Y
-  EXPECT_EQ(solve({X, NotY}), Solver::Result::Satisfiable);
+  expectSatisfiable(
+  solve({X, NotY}),
+  UnorderedElementsAre(Pair(X, Solver::Result::Assignment::AssignedTrue),
+   Pair(Y, Solver::Result::Assignment::AssignedFalse)));
 }
 
 TEST_F(SolverTest, DoubleNegation) {
@@ -106,7 +130,7 @@
   auto NotNotX = neg(NotX);
 
   // !!X ^ !X
-  EXPECT_EQ(solve({NotNotX, NotX}), Solver::Result::Unsatisfiable);
+  expectUnsatisfiable(solve({NotNotX, NotX}));
 }
 
 TEST_F(SolverTest, NegatedDisjunction) {
@@ -116,7 +140,7 @@
   auto NotXOrY = neg(XOrY);
 
   // !(X v Y) ^ (X v Y)
-  EXPECT_EQ(solve({NotXOrY, XOrY}), Solver::Result::Unsatisfiable);
+  expectUnsatisfiable(solve({NotXOrY, XOrY}));
 }
 
 TEST_F(SolverTest, NegatedConjunction) {
@@ -126,7 +150,7 @@
   auto NotXAndY = neg(XAndY);
 
   // !(X ^ Y) ^ (X ^ Y)
-  EXPECT_EQ(solve({NotXAndY, XAndY}), Solver::Result::Unsatisfiable);
+  expectUnsatisfiable(solve({NotXAndY, XAndY}));
 }
 
 TEST_F(SolverTest, DisjunctionSameVars) {
@@ -135,7 +159,7 @@
   auto XOrNotX = disj(X, NotX);
 
   // X v !X
-  EXPECT_EQ(solve({XOrNotX}), Solver::Result::Satisfiable);
+  expectSatisfiable(solve({XOrNotX}), _);
 }
 
 TEST_F(SolverTest, ConjunctionSameVarsConflict) {
@@ -144,7 +168,7 @@
   auto XAndNotX = conj(X, NotX);
 
   // X ^ !X
-  EXPECT_EQ(solve({XAndNotX}), Solver::Result::Unsatisfiable);
+  expectUnsatisfiable(solve({XAndNotX}));
 }
 
 TEST_F(SolverTest, PureVar) {
@@ -156,7 +180,10 @@
   auto NotXOrNotY = disj(NotX, NotY);
 
   // (!X v Y) ^ (!X v !Y)
-  EXPECT_EQ(solve({NotXOrY, NotXOrNotY}), Solver::Result::Satisfiable);
+  expectSatisfiable(
+  solve({NotXOrY, NotXOrNotY}),
+  UnorderedElementsAre(Pair(X, Solver::Result::Assignment::AssignedFalse),
+   Pair(Y, _)));
 }
 
 TEST_F(SolverTest, MustAssumeVarIsFalse) {
@@ -169,7 +196,10 @@
   auto NotXOrNotY = disj(NotX, NotY);
 
   // (X v Y) ^ (!X v Y) ^ (!X v !Y)
-  EXPECT_EQ(solve({XOrY, NotXOrY, NotXOrNotY}), Solver::Result::Satisfiable);
+  expectSatisfiable(
+  solve({XOrY, NotXOrY, NotXOrNotY}),
+  UnorderedElementsAre(Pair(X, Solver::Result::Assignment::AssignedFalse),
+   Pair(Y, Solver::Result::Assignment::AssignedTrue)));
 }
 
 TEST_F(SolverTest, DeepConflict) {
@@ -183,8 +213,7 @@
   auto XOrNotY = disj(X, NotY);
 
   // (X v Y) ^ (!X v Y) ^ (!X v !Y) ^ (X v !Y)
-  EXPECT_EQ(solve({XOrY, NotXOrY, NotXOrNotY, XOrNotY}),
-Solver::Result::Unsatisfiable);
+  expectUnsatisfiable(solve({XOrY, NotXOrY,

[PATCH] D129269: [analyzer] Fix use of length in CStringChecker

2022-07-07 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers created this revision.
vabridgers added reviewers: martong, steakhal.
Herald added subscribers: manas, ASDenysPetrov, dkrupp, donat.nagy, Szelethus, 
mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware, xazax.hun.
Herald added a reviewer: NoQ.
Herald added a project: All.
vabridgers requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

CStringChecker is using getByteLength to get the length of a string
literal. For targets where a "char" is 8-bits, getByteLength() and
getLength() will be equal for a C string, but for targets where a "char"
is 16-bits getByteLength() returns the size in octets.

This is verified in our downstream target, but we have no way to add a
test case for this case since there is no target supporting 16-bit
"char" upstream. Since this cannot have a test case, I'm asserted this
change is "correct by construction", and visually inspected to be
correct by way of the following example where this was found.

The case that shows this fails using a target with 16-bit chars is here.
getByteLength() for the string literal returns 4, which fails when
checked against "char x[4]". With the change, the string literal is
evaluated to a size of 2 which is a correct number of "char"'s for a
16-bit target.

void strcpy_no_overflow_2(char *y) {

  char x[4];
  strcpy(x, "12"); // with getByteLength(), returns 4 using 16-bit chars

}


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129269

Files:
  clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp


Index: clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
@@ -848,7 +848,7 @@
 SValBuilder &svalBuilder = C.getSValBuilder();
 QualType sizeTy = svalBuilder.getContext().getSizeType();
 const StringLiteral *strLit = cast(MR)->getStringLiteral();
-return svalBuilder.makeIntVal(strLit->getByteLength(), sizeTy);
+return svalBuilder.makeIntVal(strLit->getLength(), sizeTy);
   }
   case MemRegion::SymbolicRegionKind:
   case MemRegion::AllocaRegionKind:


Index: clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
@@ -848,7 +848,7 @@
 SValBuilder &svalBuilder = C.getSValBuilder();
 QualType sizeTy = svalBuilder.getContext().getSizeType();
 const StringLiteral *strLit = cast(MR)->getStringLiteral();
-return svalBuilder.makeIntVal(strLit->getByteLength(), sizeTy);
+return svalBuilder.makeIntVal(strLit->getLength(), sizeTy);
   }
   case MemRegion::SymbolicRegionKind:
   case MemRegion::AllocaRegionKind:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129180: [clang][dataflow] Return a solution from the solver when `Constraints` are `Satisfiable`.

2022-07-07 Thread weiyi via Phabricator via cfe-commits
wyt updated this revision to Diff 442845.
wyt added a comment.

Fix comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129180

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
  clang/include/clang/Analysis/FlowSensitive/Solver.h
  clang/lib/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp
  clang/unittests/Analysis/FlowSensitive/SolverTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
@@ -20,6 +20,12 @@
 using namespace clang;
 using namespace dataflow;
 
+using testing::_;
+using testing::AnyOf;
+using testing::Optional;
+using testing::Pair;
+using testing::UnorderedElementsAre;
+
 class SolverTest : public ::testing::Test {
 protected:
   // Checks if the conjunction of `Vals` is satisfiable and returns the
@@ -64,6 +70,17 @@
 return conj(impl(LeftSubVal, RightSubVal), impl(RightSubVal, LeftSubVal));
   }
 
+  void expectUnsatisfiable(Solver::Result Result) {
+EXPECT_EQ(Result.getStatus(), Solver::Result::Status::Unsatisfiable);
+EXPECT_FALSE(Result.getSolution().has_value());
+  }
+
+  template 
+  void expectSatisfiable(Solver::Result Result, Matcher Solution) {
+EXPECT_EQ(Result.getStatus(), Solver::Result::Status::Satisfiable);
+EXPECT_THAT(Result.getSolution(), Optional(Solution));
+  }
+
 private:
   std::vector> Vals;
 };
@@ -72,7 +89,9 @@
   auto X = atom();
 
   // X
-  EXPECT_EQ(solve({X}), Solver::Result::Satisfiable);
+  expectSatisfiable(
+  solve({X}),
+  UnorderedElementsAre(Pair(X, Solver::Result::Assignment::AssignedTrue)));
 }
 
 TEST_F(SolverTest, NegatedVar) {
@@ -80,7 +99,9 @@
   auto NotX = neg(X);
 
   // !X
-  EXPECT_EQ(solve({NotX}), Solver::Result::Satisfiable);
+  expectSatisfiable(
+  solve({NotX}),
+  UnorderedElementsAre(Pair(X, Solver::Result::Assignment::AssignedFalse)));
 }
 
 TEST_F(SolverTest, UnitConflict) {
@@ -88,7 +109,7 @@
   auto NotX = neg(X);
 
   // X ^ !X
-  EXPECT_EQ(solve({X, NotX}), Solver::Result::Unsatisfiable);
+  expectUnsatisfiable(solve({X, NotX}));
 }
 
 TEST_F(SolverTest, DistinctVars) {
@@ -97,7 +118,10 @@
   auto NotY = neg(Y);
 
   // X ^ !Y
-  EXPECT_EQ(solve({X, NotY}), Solver::Result::Satisfiable);
+  expectSatisfiable(
+  solve({X, NotY}),
+  UnorderedElementsAre(Pair(X, Solver::Result::Assignment::AssignedTrue),
+   Pair(Y, Solver::Result::Assignment::AssignedFalse)));
 }
 
 TEST_F(SolverTest, DoubleNegation) {
@@ -106,7 +130,7 @@
   auto NotNotX = neg(NotX);
 
   // !!X ^ !X
-  EXPECT_EQ(solve({NotNotX, NotX}), Solver::Result::Unsatisfiable);
+  expectUnsatisfiable(solve({NotNotX, NotX}));
 }
 
 TEST_F(SolverTest, NegatedDisjunction) {
@@ -116,7 +140,7 @@
   auto NotXOrY = neg(XOrY);
 
   // !(X v Y) ^ (X v Y)
-  EXPECT_EQ(solve({NotXOrY, XOrY}), Solver::Result::Unsatisfiable);
+  expectUnsatisfiable(solve({NotXOrY, XOrY}));
 }
 
 TEST_F(SolverTest, NegatedConjunction) {
@@ -126,7 +150,7 @@
   auto NotXAndY = neg(XAndY);
 
   // !(X ^ Y) ^ (X ^ Y)
-  EXPECT_EQ(solve({NotXAndY, XAndY}), Solver::Result::Unsatisfiable);
+  expectUnsatisfiable(solve({NotXAndY, XAndY}));
 }
 
 TEST_F(SolverTest, DisjunctionSameVars) {
@@ -135,7 +159,7 @@
   auto XOrNotX = disj(X, NotX);
 
   // X v !X
-  EXPECT_EQ(solve({XOrNotX}), Solver::Result::Satisfiable);
+  expectSatisfiable(solve({XOrNotX}), _);
 }
 
 TEST_F(SolverTest, ConjunctionSameVarsConflict) {
@@ -144,7 +168,7 @@
   auto XAndNotX = conj(X, NotX);
 
   // X ^ !X
-  EXPECT_EQ(solve({XAndNotX}), Solver::Result::Unsatisfiable);
+  expectUnsatisfiable(solve({XAndNotX}));
 }
 
 TEST_F(SolverTest, PureVar) {
@@ -156,7 +180,10 @@
   auto NotXOrNotY = disj(NotX, NotY);
 
   // (!X v Y) ^ (!X v !Y)
-  EXPECT_EQ(solve({NotXOrY, NotXOrNotY}), Solver::Result::Satisfiable);
+  expectSatisfiable(
+  solve({NotXOrY, NotXOrNotY}),
+  UnorderedElementsAre(Pair(X, Solver::Result::Assignment::AssignedFalse),
+   Pair(Y, _)));
 }
 
 TEST_F(SolverTest, MustAssumeVarIsFalse) {
@@ -169,7 +196,10 @@
   auto NotXOrNotY = disj(NotX, NotY);
 
   // (X v Y) ^ (!X v Y) ^ (!X v !Y)
-  EXPECT_EQ(solve({XOrY, NotXOrY, NotXOrNotY}), Solver::Result::Satisfiable);
+  expectSatisfiable(
+  solve({XOrY, NotXOrY, NotXOrNotY}),
+  UnorderedElementsAre(Pair(X, Solver::Result::Assignment::AssignedFalse),
+   Pair(Y, Solver::Result::Assignment::AssignedTrue)));
 }
 
 TEST_F(SolverTest, DeepConflict) {
@@ -183,8 +213,7 @@
   auto XOrNotY = disj(X, NotY);
 
   // (X v Y) ^ (!X v Y) ^ (!X v !Y) ^ (X v !Y)
-  EXPECT_EQ(solve({XOrY, NotXOrY, NotXOrNotY, XOrNotY}),
-Solver::Result::Unsatisfiable);
+  expectUnsatisfiable(solve({XOrY, NotXOrY, NotXOrNotY, XOrNotY}));
 }
 
 TEST_F(Solve

[PATCH] D128449: [clang] Introduce -Warray-parameter

2022-07-07 Thread serge via Phabricator via cfe-commits
serge-sans-paille updated this revision to Diff 442844.
serge-sans-paille marked an inline comment as done.
serge-sans-paille added a comment.

Take review into account.


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

https://reviews.llvm.org/D128449

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDecl.cpp
  clang/test/Misc/warning-wall.c
  clang/test/Sema/array-parameter.c
  clang/test/Sema/array-parameter.cpp

Index: clang/test/Sema/array-parameter.cpp
===
--- /dev/null
+++ clang/test/Sema/array-parameter.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fsyntax-only -Warray-parameter -verify %s
+
+template 
+void func(int i[10]); // expected-note {{previously declared as 'int[10]' here}}
+
+template 
+void func(int i[N]); // expected-warning {{argument 'i' of type 'int[N]' with mismatched bound}}
+
+template 
+void func(int (&Val)[N]);
+
+template <>
+void func<10>(int (&Val)[10]) {
+}
+
+static constexpr int Extent = 10;
+void funk(int i[10]);
+void funk(int i[Extent]); // no-warning
Index: clang/test/Sema/array-parameter.c
===
--- /dev/null
+++ clang/test/Sema/array-parameter.c
@@ -0,0 +1,35 @@
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fsyntax-only -Warray-parameter -verify %s
+void f0(int a[]);
+void f0(int *a); // no warning
+
+void f1(int a[]);  // expected-note {{previously declared as 'int[]' here}}
+void f1(int a[2]); // expected-warning {{argument 'a' of type 'int[2]' with mismatched bound}}
+
+void f2(int a[3]); // expected-note {{previously declared as 'int[3]' here}}
+void f2(int a[2]); // expected-warning {{argument 'a' of type 'int[2]' with mismatched bound}}
+
+void f3(int a[const 2]);
+void f3(int a[2]); // no warning
+
+void f4(int a[static 2]);
+void f4(int a[2]); // no warning
+
+void f5(int a[restrict 2]);
+void f5(int a[2]); // no warning
+
+void f6(int a[volatile 2]);
+void f6(int a[2]); // no warning
+
+void f7(int a[*]);
+void f7(int a[]); // no warning
+
+void f8(int n, int a[*]); // expected-note {{previously declared as 'int[*]' here}}
+void f8(int n, int a[n]); // expected-warning {{argument 'a' of type 'int[n]' with mismatched bound}}
+
+void f9(int *a);
+void f9(int a[2]);
+void f9(int a[]); // expected-warning {{argument 'a' of type 'int[]' with mismatched bound}}
+  // expected-note@-2 {{previously declared as 'int[2]' here}}
+void f9(int a[2]) // expected-warning {{argument 'a' of type 'int[2]' with mismatched bound}}
+  // expected-note@-3 {{previously declared as 'int[]' here}}
+{}
Index: clang/test/Misc/warning-wall.c
===
--- clang/test/Misc/warning-wall.c
+++ clang/test/Misc/warning-wall.c
@@ -3,6 +3,7 @@
 
  CHECK:-Wall
 CHECK-NEXT:  -Wmost
+CHECK-NEXT:-Warray-parameter
 CHECK-NEXT:-Wbool-operation
 CHECK-NEXT:-Wbitwise-instead-of-logical
 CHECK-NEXT:-Wchar-subscripts
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -3209,6 +3209,39 @@
   if (!foundAny) newDecl->dropAttrs();
 }
 
+static bool EquivalentArrayTypes(QualType Old, QualType New,
+ ASTContext const &Ctx) {
+
+  auto NoSizeInfo = [&Ctx](QualType Ty) {
+if (Ty->isIncompleteArrayType() || Ty->isPointerType())
+  return true;
+if (const auto *VAT = Ctx.getAsVariableArrayType(Ty))
+  return VAT->getSizeModifier() == ArrayType::ArraySizeModifier::Star;
+return false;
+  };
+
+  // `type[]` is equivalent to `type *` and `type[*]`.
+  if (NoSizeInfo(Old) && NoSizeInfo(New))
+return true;
+
+  // Don't try to compare VLA sizes, unless one of them has the star modifier.
+  if (Old->isVariableArrayType() && New->isVariableArrayType()) {
+const auto *OldVAT = Ctx.getAsVariableArrayType(Old);
+const auto *NewVAT = Ctx.getAsVariableArrayType(New);
+if ((OldVAT->getSizeModifier() == ArrayType::ArraySizeModifier::Star) ^
+(NewVAT->getSizeModifier() == ArrayType::ArraySizeModifier::Star))
+  return false;
+return true;
+  }
+
+  // Only compare size, ignore Size modifiers and CVR.
+  if (Old->isConstantArrayType() && New->isConstantArrayType())
+return Ctx.getAsConstantArrayType(Old)->getSize() ==
+   Ctx.getAsConstantArrayType(New)->getSize();
+
+  return Old == New;
+}
+
 static void mergeParamDeclTypes(ParmVarDecl *NewParam,
 const ParmVarDecl *OldParam,
 Sema &S) {
@@ -3234,6 +3267,19 @@
   NewParam->setType(NewT);
 }
   }
+  const auto *OldParamDT = dyn_cast(OldParam->getType());
+  const auto *NewParamDT = dyn_cast(NewParam->getType());
+

[PATCH] D129180: [clang][dataflow] Return a solution from the solver when `Constraints` are `Satisfiable`.

2022-07-07 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 added inline comments.



Comment at: clang/include/clang/Analysis/FlowSensitive/Solver.h:67
+/// boolean formula if available. Otherwise, an empty optional is returned.
+std::optional>
+getSolution() const {

Please use llvm::Optional, we can't use std::optional in LLVM/Clang code yet.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129180

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


[PATCH] D129180: [clang][dataflow] Return a solution from the solver when `Constraints` are `Satisfiable`.

2022-07-07 Thread weiyi via Phabricator via cfe-commits
wyt updated this revision to Diff 442848.
wyt added a comment.

Replace std::optional with llvm::Optional


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129180

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
  clang/include/clang/Analysis/FlowSensitive/Solver.h
  clang/lib/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp
  clang/unittests/Analysis/FlowSensitive/SolverTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
@@ -20,6 +20,12 @@
 using namespace clang;
 using namespace dataflow;
 
+using testing::_;
+using testing::AnyOf;
+using testing::Optional;
+using testing::Pair;
+using testing::UnorderedElementsAre;
+
 class SolverTest : public ::testing::Test {
 protected:
   // Checks if the conjunction of `Vals` is satisfiable and returns the
@@ -64,6 +70,17 @@
 return conj(impl(LeftSubVal, RightSubVal), impl(RightSubVal, LeftSubVal));
   }
 
+  void expectUnsatisfiable(Solver::Result Result) {
+EXPECT_EQ(Result.getStatus(), Solver::Result::Status::Unsatisfiable);
+EXPECT_FALSE(Result.getSolution().has_value());
+  }
+
+  template 
+  void expectSatisfiable(Solver::Result Result, Matcher Solution) {
+EXPECT_EQ(Result.getStatus(), Solver::Result::Status::Satisfiable);
+EXPECT_THAT(Result.getSolution(), Optional(Solution));
+  }
+
 private:
   std::vector> Vals;
 };
@@ -72,7 +89,9 @@
   auto X = atom();
 
   // X
-  EXPECT_EQ(solve({X}), Solver::Result::Satisfiable);
+  expectSatisfiable(
+  solve({X}),
+  UnorderedElementsAre(Pair(X, Solver::Result::Assignment::AssignedTrue)));
 }
 
 TEST_F(SolverTest, NegatedVar) {
@@ -80,7 +99,9 @@
   auto NotX = neg(X);
 
   // !X
-  EXPECT_EQ(solve({NotX}), Solver::Result::Satisfiable);
+  expectSatisfiable(
+  solve({NotX}),
+  UnorderedElementsAre(Pair(X, Solver::Result::Assignment::AssignedFalse)));
 }
 
 TEST_F(SolverTest, UnitConflict) {
@@ -88,7 +109,7 @@
   auto NotX = neg(X);
 
   // X ^ !X
-  EXPECT_EQ(solve({X, NotX}), Solver::Result::Unsatisfiable);
+  expectUnsatisfiable(solve({X, NotX}));
 }
 
 TEST_F(SolverTest, DistinctVars) {
@@ -97,7 +118,10 @@
   auto NotY = neg(Y);
 
   // X ^ !Y
-  EXPECT_EQ(solve({X, NotY}), Solver::Result::Satisfiable);
+  expectSatisfiable(
+  solve({X, NotY}),
+  UnorderedElementsAre(Pair(X, Solver::Result::Assignment::AssignedTrue),
+   Pair(Y, Solver::Result::Assignment::AssignedFalse)));
 }
 
 TEST_F(SolverTest, DoubleNegation) {
@@ -106,7 +130,7 @@
   auto NotNotX = neg(NotX);
 
   // !!X ^ !X
-  EXPECT_EQ(solve({NotNotX, NotX}), Solver::Result::Unsatisfiable);
+  expectUnsatisfiable(solve({NotNotX, NotX}));
 }
 
 TEST_F(SolverTest, NegatedDisjunction) {
@@ -116,7 +140,7 @@
   auto NotXOrY = neg(XOrY);
 
   // !(X v Y) ^ (X v Y)
-  EXPECT_EQ(solve({NotXOrY, XOrY}), Solver::Result::Unsatisfiable);
+  expectUnsatisfiable(solve({NotXOrY, XOrY}));
 }
 
 TEST_F(SolverTest, NegatedConjunction) {
@@ -126,7 +150,7 @@
   auto NotXAndY = neg(XAndY);
 
   // !(X ^ Y) ^ (X ^ Y)
-  EXPECT_EQ(solve({NotXAndY, XAndY}), Solver::Result::Unsatisfiable);
+  expectUnsatisfiable(solve({NotXAndY, XAndY}));
 }
 
 TEST_F(SolverTest, DisjunctionSameVars) {
@@ -135,7 +159,7 @@
   auto XOrNotX = disj(X, NotX);
 
   // X v !X
-  EXPECT_EQ(solve({XOrNotX}), Solver::Result::Satisfiable);
+  expectSatisfiable(solve({XOrNotX}), _);
 }
 
 TEST_F(SolverTest, ConjunctionSameVarsConflict) {
@@ -144,7 +168,7 @@
   auto XAndNotX = conj(X, NotX);
 
   // X ^ !X
-  EXPECT_EQ(solve({XAndNotX}), Solver::Result::Unsatisfiable);
+  expectUnsatisfiable(solve({XAndNotX}));
 }
 
 TEST_F(SolverTest, PureVar) {
@@ -156,7 +180,10 @@
   auto NotXOrNotY = disj(NotX, NotY);
 
   // (!X v Y) ^ (!X v !Y)
-  EXPECT_EQ(solve({NotXOrY, NotXOrNotY}), Solver::Result::Satisfiable);
+  expectSatisfiable(
+  solve({NotXOrY, NotXOrNotY}),
+  UnorderedElementsAre(Pair(X, Solver::Result::Assignment::AssignedFalse),
+   Pair(Y, _)));
 }
 
 TEST_F(SolverTest, MustAssumeVarIsFalse) {
@@ -169,7 +196,10 @@
   auto NotXOrNotY = disj(NotX, NotY);
 
   // (X v Y) ^ (!X v Y) ^ (!X v !Y)
-  EXPECT_EQ(solve({XOrY, NotXOrY, NotXOrNotY}), Solver::Result::Satisfiable);
+  expectSatisfiable(
+  solve({XOrY, NotXOrY, NotXOrNotY}),
+  UnorderedElementsAre(Pair(X, Solver::Result::Assignment::AssignedFalse),
+   Pair(Y, Solver::Result::Assignment::AssignedTrue)));
 }
 
 TEST_F(SolverTest, DeepConflict) {
@@ -183,8 +213,7 @@
   auto XOrNotY = disj(X, NotY);
 
   // (X v Y) ^ (!X v Y) ^ (!X v !Y) ^ (X v !Y)
-  EXPECT_EQ(solve({XOrY, NotXOrY, NotXOrNotY, XOrNotY}),
-Solver::Result::Unsatisfiable);
+  expectUnsatisfiable(solve({XOrY, NotXOrY, NotXOrNotY, X

[PATCH] D126694: [C++20][Modules] Implementation of GMF decl elision.

2022-07-07 Thread Iain Sandoe via Phabricator via cfe-commits
iains updated this revision to Diff 442849.
iains marked 25 inline comments as done.
iains added a comment.

rebased, addressed review comments, added another test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126694

Files:
  clang/include/clang/AST/DeclBase.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Decl.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/SemaModule.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaStmtAsm.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/test/AST/ast-dump-decl.c
  clang/test/CXX/basic/basic.scope/basic.scope.namespace/p2.cpp
  clang/test/CXX/module/module.global.frag/cxx20-10-4-ex2.cpp
  clang/test/CXX/module/module.global.frag/p3-p4.cpp
  clang/test/Modules/cxx-templates.cpp

Index: clang/test/Modules/cxx-templates.cpp
===
--- clang/test/Modules/cxx-templates.cpp
+++ clang/test/Modules/cxx-templates.cpp
@@ -252,7 +252,7 @@
 // CHECK-DUMP:  ClassTemplateDecl {{.*}} <{{.*[/\\]}}cxx-templates-common.h:1:1, {{.*}}>  col:{{.*}} in cxx_templates_common SomeTemplate
 // CHECK-DUMP:ClassTemplateSpecializationDecl {{.*}} prev {{.*}} SomeTemplate
 // CHECK-DUMP-NEXT: TemplateArgument type 'char[2]'
-// CHECK-DUMP:ClassTemplateSpecializationDecl {{.*}} SomeTemplate definition
+// CHECK-DUMP:ClassTemplateSpecializationDecl {{.*}} SomeTemplate Visible definition
 // CHECK-DUMP-NEXT: DefinitionData
 // CHECK-DUMP-NEXT:   DefaultConstructor
 // CHECK-DUMP-NEXT:   CopyConstructor
@@ -263,7 +263,7 @@
 // CHECK-DUMP-NEXT: TemplateArgument type 'char[2]'
 // CHECK-DUMP:ClassTemplateSpecializationDecl {{.*}} prev {{.*}} SomeTemplate
 // CHECK-DUMP-NEXT: TemplateArgument type 'char[1]'
-// CHECK-DUMP:ClassTemplateSpecializationDecl {{.*}} SomeTemplate definition
+// CHECK-DUMP:ClassTemplateSpecializationDecl {{.*}} SomeTemplate Visible definition
 // CHECK-DUMP-NEXT: DefinitionData
 // CHECK-DUMP-NEXT:   DefaultConstructor
 // CHECK-DUMP-NEXT:   CopyConstructor
Index: clang/test/CXX/module/module.global.frag/p3-p4.cpp
===
--- /dev/null
+++ clang/test/CXX/module/module.global.frag/p3-p4.cpp
@@ -0,0 +1,54 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: cd %t
+
+// RUN: %clang_cc1 -std=c++20 M.cpp -emit-module-interface -o M.pcm
+// RUN: %clang_cc1 -std=c++20 M.cpp -ast-dump | FileCheck --match-full-lines %s
+// RUN: %clang_cc1 -std=c++20 M-impl.cpp -fmodule-file=M.pcm -fsyntax-only -verify
+
+//--- p3-p4.h
+int f();
+int g();
+int h();
+int j();
+typedef int GMFInt;
+
+//--- M.cpp
+module;
+#include "p3-p4.h"
+
+export module M;
+
+export int use_f() { return f(); }
+
+export using ::h;
+
+namespace N {
+export using ::j;
+}
+
+GMFInt k(int);
+
+// CHECK: |-FunctionDecl {{.*}} <./p3-p4.h:1:1, col:7> col:5 in M. hidden used f 'int ()' ReachableWhenImported
+// CHECK: |-FunctionDecl {{.*}}  col:5 in M. hidden g 'int ()' ModuleDiscardable
+// CHECK: |-FunctionDecl {{.*}}  col:5 in M. hidden h 'int ()' ReachableWhenImported
+// CHECK: |-FunctionDecl {{.*}}  col:5 in M. hidden j 'int ()' ReachableWhenImported
+// CHECK: |-TypedefDecl {{.*}}  col:13 in M. hidden referenced GMFInt 'int' ReachableWhenImported
+
+// CHECK: |-ExportDecl {{.*}}  col:1 in M
+// CHECK-NEXT: | `-FunctionDecl {{.*}}  col:12 in M hidden use_f 'int ()' VisibleWhenImported
+
+// CHECK: |-ExportDecl {{.*}}  col:1 in M
+// CHECK-NEXT: | |-UsingDecl {{.*}}  col:16 in M hidden ::h VisibleWhenImported
+// CHECK-NEXT: | `-UsingShadowDecl {{.*}}  col:16 in M hidden implicit Function {{.*}} 'h' 'int ()' VisibleWhenImported
+
+// CHECK: |-NamespaceDecl {{.*}}  line:10:11 in M hidden N
+// CHECK-NEXT: | `-ExportDecl {{.*}}  col:1 in M
+// CHECK-NEXT: |   |-UsingDecl {{.*}}  col:16 in M hidden ::j VisibleWhenImported
+// CHECK-NEXT: |   `-UsingShadowDecl {{.*}}  col:16 in M hidden implicit Function {{.*}} 'j' 'int ()' VisibleWhenImported
+
+//--- M-impl.cpp
+import M;
+int a = j();// expected-error {{missing '#include'; 'j' must be declared before it is used}}
+// expected-note@p3-p4.h:4 {{declaration here is not visible}}
+int b = N::j(); // should be OK, UsingShadowDecl is visible
Index: clang/test/CXX/module/module.global.frag/cxx20-10-4-ex2.cpp
===
--- /dev/null
+++ clang/test/CXX/module/module.global.frag/cxx20-10-4-ex2.cpp
@@ -0,0 +1,60 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: cd %t
+
+// RUN: %clang_cc1 -std=c

[PATCH] D126694: [C++20][Modules] Implementation of GMF decl elision.

2022-07-07 Thread Iain Sandoe via Phabricator via cfe-commits
iains added a comment.

@rsmith, @ChuanqiXu apologies for the multiple revisions, this has turned out 
to be much more involved than I imagined from the standard's text.

In D126694#3629254 , @ChuanqiXu wrote:

> In D126694#3629251 , @iains wrote:
>
>> In D126694#3629094 , @ChuanqiXu 
>> wrote:
>>
>>> BTW, after I applied the patch, the compiler crashes at 
>>> https://github.com/ChuanqiXu9/stdmodules.
>>
>> That link points to a project - is there (say) a gist of the crash 
>> information?
>
> Here is the crash log:

this code now compiles without error,




Comment at: clang/include/clang/AST/DeclBase.h:624
   bool isModulePrivate() const {
 return getModuleOwnershipKind() == ModuleOwnershipKind::ModulePrivate;
   }

iains wrote:
> ChuanqiXu wrote:
> > According to the opinion from @rsmith, the discarded declaration is private 
> > too.
> I guess you mean `>=`  ... however Discardable is a stronger constraint than 
> Private 
> 
> If a decl remains marked Discardable (after the processing to determine 
> reachable ones) that means it is both unreachable and invisible.
> So it must not participate in any processing (with the one exception of 
> diagnostic output).  I would be concerned that the change you suggest above 
> could cause a  Discardable decl to be considered in merging  or lookup and we 
> would then need (maybe a lot) of logic like:
> 
> ```
>  if (D->isModulePrivate() && !D->isModuleDiscardable())
> ...
> ```
> 
> I will take a look on the next iteration.
> 
I did try this and there are a number of regressions - when I looked into these 
there is some interaction with the changes made in D113545, so I think we 
should make these changes in a follow-one patch to avoid having two purposes in 
this one.



Comment at: clang/include/clang/Sema/Sema.h:2275-2276
 
+  llvm::SmallPtrSet SeenDecls;
+  llvm::SmallPtrSet SeenTypes;
+

rsmith wrote:
> These names seem too general to live directly in `Sema`.
(revised we only need to track the type pointers)

On the basis that the name is poor, for its intended purpose, I revised. 



Comment at: clang/include/clang/Sema/Sema.h:2273
+  void HandleGMFReachability(Decl *D) {
+if (D->isModuleUnreachable() && isCurrentModulePurview()) {
+  
D->setModuleOwnershipKind(Decl::ModuleOwnershipKind::ReachableWhenImported);

ChuanqiXu wrote:
> iains wrote:
> > ChuanqiXu wrote:
> > > I feel better if we would check if D lives in GMF. (We need to insert a 
> > > check in isDiscardedInGlobalModuleFragment)
> > If the consensus is to add an extra test, OK.
> > 
> > However, as above, specifically to avoid making more and more tests in code 
> > that is executed very frequently - as the design currently stands, the only 
> > place that  `ModuleUnreachable` is set is in the GMF.
> Yeah, my opinion is the same as above. Although it is the design, it is more 
> semantically clear and robust to add a additional check. I am just afraid it 
> would confuse and block other readers or contributors.
this has now been revised and a check is applied before any change is made to 
discardable decls.



Comment at: clang/lib/AST/TextNodeDumper.cpp:1622
+  if (D->isModuleUnreachable())
+OS << " ModuleUnreachable";
 }

ChuanqiXu wrote:
> iains wrote:
> > ChuanqiXu wrote:
> > > It may be better to keep the consistent style.
> > I don't think that is a matter of style `__module_private__` is a keyword 
> > used elsewhere?
> > 
> > If you look though the file you will see mostly that the printed output 
> > does not prepend or append underscores.
> > 
> > BTW, similar changes are probably needed in other node printers, this was 
> > done early to add debug.
> Oh, I found `__module_private__ ` is a keyword in clang modules. I didn't 
> recognize it. Even in this case, I still prefer to keep the style 
> consistently. I think users would be more comfortable to read consistent 
> symbols. Also I think it is acceptable to keep `ModuleUnreachable` since it 
> doesn't matter a lot to me.
OK we now have more fine-grained output for the module ownership in the dumps 
which allows specific tests to be constructed.  At present, the naming is as 
per decl.h (with the single exception of __module_private__ which has a 
user-facing representation).



Comment at: clang/lib/Sema/Sema.cpp:1130
 DiagnoseUseOfUnimplementedSelectors();
 
+// For C++20 modules, we are permitted to elide decls in the Global

ChuanqiXu wrote:
> I prefer to wrap this logic to a function to make it easier to read.
I think the comment refers to an older version of the changes.



Comment at: clang/lib/Sema/Sema.cpp:1131-1133
+// For C++20 modules, we are permitted to elide decls in the Global
+// Mo

[PATCH] D129269: [analyzer] Fix use of length in CStringChecker

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

Actually, there is one more bug there. If the string has an embedded 
null-terminator; a wrong length will be returned.
Please add tests to demonstrate the wrong behavior. Try different target 
triples for having irregular char sizes and pin that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129269

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


[clang] 2db2a4e - [doc][ReleaseNotes] Document AArch64 SVE ABI fix from D127209

2022-07-07 Thread Peter Waller via cfe-commits

Author: Peter Waller
Date: 2022-07-07T10:55:40Z
New Revision: 2db2a4e112406e97bad82b8e78492a472c13588e

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

LOG: [doc][ReleaseNotes] Document AArch64 SVE ABI fix from D127209

D127209 fixed LLVM to bring it in line with the AAPCS. The fix affects
functions where the first SVE parameter appears in the 9th or later
arguments, and the function does not return an SVE type.

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0f542e08b841c..93d4ed58d4de5 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -503,6 +503,14 @@ ABI Changes in Clang
   (e.g. ``int : 0``) no longer prevents the structure from being considered a
   homogeneous floating-point or vector aggregate. The new behavior agrees with
   the AAPCS specification, and matches the similar bug fix in GCC 12.1.
+- Targeting AArch64, since D127209 LLVM now only preserves the z8-z23
+  and p4-p15 registers across a call if the registers z0-z7 or p0-p3 are
+  used to pass data into or out of a subroutine. The new behavior
+  matches the AAPCS. Previously LLVM preserved z8-z23 and p4-p15 across
+  a call if the callee had an SVE type anywhere in its signature. This
+  would cause an incorrect use of the caller-preserved z8-z23 and p4-p15
+  ABI for example if the 9th argument or greater were the first SVE type
+  in the signature of a function.
 - All copy constructors can now be trivial if they are not user-provided,
   regardless of the type qualifiers of the argument of the defaulted 
constructor,
   fixing dr2171.



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


[PATCH] D129135: [doc][ReleaseNotes] Document AArch64 SVE ABI fix from D127209

2022-07-07 Thread Peter Waller 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 rG2db2a4e11240: [doc][ReleaseNotes] Document AArch64 SVE ABI 
fix from D127209 (authored by peterwaller-arm).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129135

Files:
  clang/docs/ReleaseNotes.rst


Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -503,6 +503,14 @@
   (e.g. ``int : 0``) no longer prevents the structure from being considered a
   homogeneous floating-point or vector aggregate. The new behavior agrees with
   the AAPCS specification, and matches the similar bug fix in GCC 12.1.
+- Targeting AArch64, since D127209 LLVM now only preserves the z8-z23
+  and p4-p15 registers across a call if the registers z0-z7 or p0-p3 are
+  used to pass data into or out of a subroutine. The new behavior
+  matches the AAPCS. Previously LLVM preserved z8-z23 and p4-p15 across
+  a call if the callee had an SVE type anywhere in its signature. This
+  would cause an incorrect use of the caller-preserved z8-z23 and p4-p15
+  ABI for example if the 9th argument or greater were the first SVE type
+  in the signature of a function.
 - All copy constructors can now be trivial if they are not user-provided,
   regardless of the type qualifiers of the argument of the defaulted 
constructor,
   fixing dr2171.


Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -503,6 +503,14 @@
   (e.g. ``int : 0``) no longer prevents the structure from being considered a
   homogeneous floating-point or vector aggregate. The new behavior agrees with
   the AAPCS specification, and matches the similar bug fix in GCC 12.1.
+- Targeting AArch64, since D127209 LLVM now only preserves the z8-z23
+  and p4-p15 registers across a call if the registers z0-z7 or p0-p3 are
+  used to pass data into or out of a subroutine. The new behavior
+  matches the AAPCS. Previously LLVM preserved z8-z23 and p4-p15 across
+  a call if the callee had an SVE type anywhere in its signature. This
+  would cause an incorrect use of the caller-preserved z8-z23 and p4-p15
+  ABI for example if the 9th argument or greater were the first SVE type
+  in the signature of a function.
 - All copy constructors can now be trivial if they are not user-provided,
   regardless of the type qualifiers of the argument of the defaulted constructor,
   fixing dr2171.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D128535: [analyzer] Improve loads from reinterpret-cast fields

2022-07-07 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/RegionStore.cpp:1897
+  QualType Ty = SubReg->getValueType();
+  if (BaseTy->isScalarType() && Ty->isScalarType()) {
+if (Ctx.getTypeSizeInChars(BaseTy) >= Ctx.getTypeSizeInChars(Ty)) {

BTW I'm not sure why this check is here. I would expect this to work eve 
without this.
OOh, I think I know why. `getTypeSizeInChars` can only be called on //scalars//?



Comment at: clang/lib/StaticAnalyzer/Core/RegionStore.cpp:2014-2017
+  // FIXME: This is a hack, and doesn't do anything really intelligent yet.
+  // FIXME: This hack is analogous with the one present in
+  // `getBindingForElement`, maybe we should handle both in
+  // `getBindingForFieldOrElementCommon`.

martong wrote:
> Could you please elaborate why this is a hack? What should be done and where 
> to solve it properly? (Disclaimer, I did not look into 
> `getBindingForFieldOrElementCommon`.)
I'm not sure what Jordan was actually referring to. IMO hardcoding to look for 
a highly specific scenario (a typed memregion, and a symbol to be exact) could 
be thought about implementing a 'hack'. IMO this fits in the current ecosystem, 
so for me it doesn't look like a hack; hence IMO this is the way of 
implementing this.

To make it clear, I simply hoisted the nested `dyn_cast`s and checks into a 
function, while preserved the 'hack' comment at the callsite; so it's not added 
by me.

One additional note. We relay on the type information embedded into the 
memregion - which we know might not always be present and even accurate. That 
could be another reason why this should be considered as a 'hack'. IDK


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128535

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


[PATCH] D127874: [analyzer] Reimplement UnreachableCodeChecker using worklists

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

In D127874#3628112 , @martong wrote:

>> I don't think any of the issues mentioned in this patch relates to strongly 
>> connected components, thus I don't think I can answer to this question.
>
> In your example above, repeated here:
>
>   #6(entry)  #2(goto a;)
>|  |^
>   #5(goto end;)   | \
>| #4(goto b;) |
>   #1(end:)|  |
>| #3(goto c;) |
>   #0(exit) \/
>
> [#2, #4, #3] is a strongly connected (and unreachable) component  of the CFG, 
> isn't it?

Right; those three blocks are unreachable in the CFG.

Let me clarify that this (previous) example has nothing to do with the 
visitation order. For that, yes either BFS and DFS order would work.
The `magic_clamp` example supposed to underpin the rationale behind choosing 
BFS instead of DFS.
In the summary, you will find a step-by-step playthrough how the DFS visitation 
worked previously, and resulted in falsely leaving `B3` and `B5` unreachable 
due to the order in which their predecessor nodes were visited. Let me know if 
it helped.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127874

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


[PATCH] D129277: [clang] [Serialization] Fix swapped PPOpts/ExistingPPOpts parameters. NFC.

2022-07-07 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo created this revision.
mstorsjo added reviewers: aaron.ballman, rnk, shafik.
Herald added a project: All.
mstorsjo requested review of this revision.
Herald added a project: clang.

The two first parameters of checkPreprocessorOptions are "PPOpts, 
ExistingPPOpts".
All other callers of the function pass them consistently.

This avoids confusion when working on the code.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129277

Files:
  clang/lib/Serialization/ASTReader.cpp


Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -5171,7 +5171,7 @@
 bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts,
  bool Complain,
  std::string &SuggestedPredefines) override {
-  return checkPreprocessorOptions(ExistingPPOpts, PPOpts, nullptr, FileMgr,
+  return checkPreprocessorOptions(PPOpts, ExistingPPOpts, nullptr, FileMgr,
   SuggestedPredefines, ExistingLangOpts);
 }
   };


Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -5171,7 +5171,7 @@
 bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts,
  bool Complain,
  std::string &SuggestedPredefines) override {
-  return checkPreprocessorOptions(ExistingPPOpts, PPOpts, nullptr, FileMgr,
+  return checkPreprocessorOptions(PPOpts, ExistingPPOpts, nullptr, FileMgr,
   SuggestedPredefines, ExistingLangOpts);
 }
   };
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D128704: [clang-extdef-mapping] Directly process .ast files

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

Sorry about my delayed response. I was busy.
I've left a couple comments inline. Nothing serious.
Thanks for the patch!




Comment at: clang/docs/ReleaseNotes.rst:593
+
+- clang-extdef-mapping now accepts .ast files as input. This is faster than to
+  recompile the files from sources when extracting method definitons. This can

I think we need to use double back ticks for preformatted/code texts.



Comment at: clang/docs/ReleaseNotes.rst:595
+  recompile the files from sources when extracting method definitons. This can
+  be really beneficial when creating .ast files for input to the 
clang-static-analyzer.
+





Comment at: clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp:42
+  : Ctx(Context), SM(Context.getSourceManager()) {
+CurrentFileName = astFilePath.str();
+  }

Why is this not initialized in the //initialized-list// like the rest of the 
members?



Comment at: clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp:149
+  if (!CI)
+CI = new CompilerInstance();
+

What takes the ownership of `CI`? When is it deleted?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128704

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


[PATCH] D128704: [clang-extdef-mapping] Directly process .ast files

2022-07-07 Thread Tobias Hieta via Phabricator via cfe-commits
thieta added inline comments.



Comment at: clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp:42
+  : Ctx(Context), SM(Context.getSourceManager()) {
+CurrentFileName = astFilePath.str();
+  }

steakhal wrote:
> Why is this not initialized in the //initialized-list// like the rest of the 
> members?
Ah no reason - I think I moved this around a few times so it just happened to 
end up here. I will push a NFC with that.



Comment at: clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp:149
+  if (!CI)
+CI = new CompilerInstance();
+

steakhal wrote:
> What takes the ownership of `CI`? When is it deleted?
I don't think anyone takes ownership and it's never properly deleted. I don't 
think we really need to since this application just runs and exits and never 
really keep any state. Do you see a problem with it never being deleted?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128704

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


[PATCH] D129279: [NFC] [Coroutines] Add regression test for heap allocation elision optimization

2022-07-07 Thread Dawid Jurczak via Phabricator via cfe-commits
yurai007 created this revision.
yurai007 added reviewers: nikic, ChuanqiXu, lxfind, GorNishanov.
Herald added a project: All.
yurai007 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Recently C++ snippet included in this patch popped up at least twice in 
different regression contexts:
https://github.com/llvm/llvm-project/issues/56262 and 
https://reviews.llvm.org/D123300
It appears that Clang users rely on HALO so adding C++ example coming 
originally from Gor Nishanov to tests
should help in avoiding similar regressions in future.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129279

Files:
  clang/test/CodeGenCoroutines/Inputs/numeric.h
  clang/test/CodeGenCoroutines/coro-halo.cpp

Index: clang/test/CodeGenCoroutines/coro-halo.cpp
===
--- /dev/null
+++ clang/test/CodeGenCoroutines/coro-halo.cpp
@@ -0,0 +1,102 @@
+// This tests that the coroutine heap allocation elision optimization could happen succesfully.
+// RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-unknown-linux-gnu -std=c++20 -O2 -emit-llvm %s -o - | FileCheck %s
+
+#include "Inputs/coroutine.h"
+#include "Inputs/numeric.h"
+
+template  struct generator {
+  struct promise_type {
+T current_value;
+std::suspend_always yield_value(T value) {
+  this->current_value = value;
+  return {};
+}
+std::suspend_always initial_suspend() { return {}; }
+std::suspend_always final_suspend() noexcept { return {}; }
+generator get_return_object() { return generator{this}; };
+void unhandled_exception() {}
+void return_void() {}
+  };
+
+  struct iterator {
+std::coroutine_handle _Coro;
+bool _Done;
+
+iterator(std::coroutine_handle Coro, bool Done)
+: _Coro(Coro), _Done(Done) {}
+
+iterator &operator++() {
+  _Coro.resume();
+  _Done = _Coro.done();
+  return *this;
+}
+
+bool operator==(iterator const &_Right) const {
+  return _Done == _Right._Done;
+}
+
+bool operator!=(iterator const &_Right) const { return !(*this == _Right); }
+T const &operator*() const { return _Coro.promise().current_value; }
+T const *operator->() const { return &(operator*()); }
+  };
+
+  iterator begin() {
+p.resume();
+return {p, p.done()};
+  }
+
+  iterator end() { return {p, true}; }
+
+  generator(generator const &) = delete;
+  generator(generator &&rhs) : p(rhs.p) { rhs.p = nullptr; }
+
+  ~generator() {
+if (p)
+  p.destroy();
+  }
+
+private:
+  explicit generator(promise_type *p)
+  : p(std::coroutine_handle::from_promise(*p)) {}
+
+  std::coroutine_handle p;
+};
+
+template 
+generator seq() {
+  for (T i = {};; ++i)
+co_yield i;
+}
+
+template 
+generator take_until(generator &g, T limit) {
+  for (auto &&v : g)
+if (v < limit)
+  co_yield v;
+else
+  break;
+}
+
+template 
+generator multiply(generator &g, T factor) {
+  for (auto &&v : g)
+co_yield v *factor;
+}
+
+template 
+generator add(generator &g, T adder) {
+  for (auto &&v : g)
+co_yield v + adder;
+}
+
+int main() {
+  auto s = seq();
+  auto t = take_until(s, 10);
+  auto m = multiply(t, 2);
+  auto a = add(m, 110);
+  return std::accumulate(a.begin(), a.end(), 0);
+}
+
+// CHECK-LABEL: define{{.*}} i32 @main(
+//   CHECK: ret i32 1190
+//   CHECK-NOT: call{{.*}}_Znwm
Index: clang/test/CodeGenCoroutines/Inputs/numeric.h
===
--- /dev/null
+++ clang/test/CodeGenCoroutines/Inputs/numeric.h
@@ -0,0 +1,10 @@
+#pragma once
+
+namespace std {
+template 
+T accumulate(InputIterator first, InputIterator last, T init) {
+  for (; first != last; ++first)
+init = init + *first;
+  return init;
+}
+} // namespace std
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129280: [analyzer] PlacementNewChecker, properly handle array overhead (cookie)

2022-07-07 Thread Gabor Marton via Phabricator via cfe-commits
martong created this revision.
martong added reviewers: isuckatcs, NoQ, bruntib, steakhal.
Herald added subscribers: manas, ASDenysPetrov, gamesh411, dkrupp, donat.nagy, 
Szelethus, mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware, 
xazax.hun.
Herald added a reviewer: Szelethus.
Herald added a project: All.
martong requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Currently, we warn if the given place is not enough to hold an extra
data for the array allocation overhead (cookie). I.e. if the size of the
place is equal to the size of the target. Also, we warn even if the size
of the place is greater than the size of the target. The current logic
does not know the size of the overhead(cookie), thus we just simply
warn and this is clearly wrong as it leads to false reports. This patch
eliminates the false reports and handles C++20 with special care.

Fixes #56264

C++17 and earlier standards state that:

  new(2, f) T[5] results in a call of operator new[](sizeof(T) * 5 +
  y, 2, f). Here, ... and y are non-negative unspecified values
  representing array allocation overhead; the result of the
  new-expression will be offset by this amount from the value returned
  by operator new[]. This overhead may be applied in all array
  new-expressions, including those referencing the library function
  operator new[](std::size_t, void*) and other placement allocation
  functions. The amount of overhead may vary from one invocation of
  new to another.

Since the array overhead is an *unspecified* value, it makes sense to
warn only if the size of the Place is equal to the size of the Target.
Otherwise, e.g if we assumed that the overhead is sizeof(size_t),
then we might report a false positive.

Checking for array cookie does not makes sense if the standard is
C++20 or later. C++20 states that array overhead(cookie) is not
created if the new expression calls the non-allocating (placement)
form of the allocation function.
C++20, section 7.6.2.7 [expr.new], paragraph 15:

  That argument shall be no less than the size of the object being
  created; it may be greater than the size of the object being created
  only if the object is an array and the allocation function is not a
  non-allocating form (17.6.2.3).

C++20, section 7.6.2.7 [expr.new], paragraph 19:

  This overhead may be applied in all array new-expressions, including
  those referencing a placement allocation function, except when
  referencing the library function operator new[](std::size_t, void*).

Related Defect Report:

2382. Array allocation overhead for non-allocating placement new

https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#2382


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129280

Files:
  clang/lib/StaticAnalyzer/Checkers/CheckPlacementNew.cpp
  clang/test/Analysis/placement-new.cpp

Index: clang/test/Analysis/placement-new.cpp
===
--- clang/test/Analysis/placement-new.cpp
+++ clang/test/Analysis/placement-new.cpp
@@ -2,7 +2,14 @@
 // RUN:   -analyzer-checker=core \
 // RUN:   -analyzer-checker=cplusplus.NewDelete \
 // RUN:   -analyzer-checker=cplusplus.PlacementNew \
-// RUN:   -analyzer-output=text -verify \
+// RUN:   -analyzer-output=text -verify=expected,cpp11 \
+// RUN:   -triple x86_64-unknown-linux-gnu
+
+// RUN: %clang_analyze_cc1 -std=c++20 %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=cplusplus.NewDelete \
+// RUN:   -analyzer-checker=cplusplus.PlacementNew \
+// RUN:   -analyzer-output=text -verify=expected \
 // RUN:   -triple x86_64-unknown-linux-gnu
 
 #include "Inputs/system-header-simulator-cxx.h"
@@ -157,27 +164,51 @@
 } // namespace testHierarchy
 
 namespace testArrayTypesAllocation {
-void f1() {
+void test_less() {
   struct S {
 short a;
   };
-
-  // bad (not enough space).
   const unsigned N = 32;
-  alignas(S) unsigned char buffer1[sizeof(S) * N]; // expected-note {{'buffer1' initialized here}}
-  ::new (buffer1) S[N];// expected-warning{{Storage provided to placement new is only 64 bytes, whereas the allocated array type requires more space for internal needs}} expected-note 1 {{}}
+  alignas(S) unsigned char buffer1[sizeof(S) * N/2]; // expected-note {{'buffer1' initialized here}}
+  ::new (buffer1) S[N];  // expected-warning{{Storage provided to placement new is only 32 bytes, whereas the allocated type requires 64 bytes}} expected-note 1 {{}}
 }
 
-void f2() {
+void test_equal() {
   struct S {
 short a;
   };
+  // Bad (not enough space).
+  // This should not appear if the standard is >= C++20.
+  // C++20 states that array overhead(cookie) is not created if the new
+  // expression calls the non-allocating (placement) form of the allocation
+  // function.
+  // C++20, section 7.6.2.7 [expr.new], paragraph 15:
+  //   That argument shall be no less than t

[clang-tools-extra] cd3aa33 - [pseudo] NFC, fix the header guard for Language.h

2022-07-07 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2022-07-07T14:42:26+02:00
New Revision: cd3aa338c720b9ee296348e3670c284cfead969d

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

LOG: [pseudo] NFC, fix the header guard for Language.h

Added: 


Modified: 
clang-tools-extra/pseudo/include/clang-pseudo/Language.h

Removed: 




diff  --git a/clang-tools-extra/pseudo/include/clang-pseudo/Language.h 
b/clang-tools-extra/pseudo/include/clang-pseudo/Language.h
index 24267c429a965..410ca075a5da4 100644
--- a/clang-tools-extra/pseudo/include/clang-pseudo/Language.h
+++ b/clang-tools-extra/pseudo/include/clang-pseudo/Language.h
@@ -6,8 +6,8 @@
 //
 
//===--===//
 
-#ifndef CLANG_PSEUDO_GRAMMAR_LANGUAGE_H
-#define CLANG_PSEUDO_GRAMMAR_LANGUAGE_H
+#ifndef CLANG_PSEUDO_LANGUAGE_H
+#define CLANG_PSEUDO_LANGUAGE_H
 
 #include "clang-pseudo/Token.h"
 #include "clang-pseudo/grammar/Grammar.h"
@@ -56,4 +56,4 @@ struct Language {
 } // namespace pseudo
 } // namespace clang
 
-#endif // CLANG_PSEUDO_GRAMMAR_LANGUAGE_H
+#endif // CLANG_PSEUDO_LANGUAGE_H



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


[PATCH] D129180: [clang][dataflow] Return a solution from the solver when `Constraints` are `Satisfiable`.

2022-07-07 Thread weiyi via Phabricator via cfe-commits
wyt updated this revision to Diff 442874.
wyt added a comment.

Remove decomposing declarations which are not available in llvm.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129180

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
  clang/include/clang/Analysis/FlowSensitive/Solver.h
  clang/lib/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp
  clang/unittests/Analysis/FlowSensitive/SolverTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
@@ -20,6 +20,12 @@
 using namespace clang;
 using namespace dataflow;
 
+using testing::_;
+using testing::AnyOf;
+using testing::Optional;
+using testing::Pair;
+using testing::UnorderedElementsAre;
+
 class SolverTest : public ::testing::Test {
 protected:
   // Checks if the conjunction of `Vals` is satisfiable and returns the
@@ -64,6 +70,17 @@
 return conj(impl(LeftSubVal, RightSubVal), impl(RightSubVal, LeftSubVal));
   }
 
+  void expectUnsatisfiable(Solver::Result Result) {
+EXPECT_EQ(Result.getStatus(), Solver::Result::Status::Unsatisfiable);
+EXPECT_FALSE(Result.getSolution().has_value());
+  }
+
+  template 
+  void expectSatisfiable(Solver::Result Result, Matcher Solution) {
+EXPECT_EQ(Result.getStatus(), Solver::Result::Status::Satisfiable);
+EXPECT_THAT(Result.getSolution(), Optional(Solution));
+  }
+
 private:
   std::vector> Vals;
 };
@@ -72,7 +89,9 @@
   auto X = atom();
 
   // X
-  EXPECT_EQ(solve({X}), Solver::Result::Satisfiable);
+  expectSatisfiable(
+  solve({X}),
+  UnorderedElementsAre(Pair(X, Solver::Result::Assignment::AssignedTrue)));
 }
 
 TEST_F(SolverTest, NegatedVar) {
@@ -80,7 +99,9 @@
   auto NotX = neg(X);
 
   // !X
-  EXPECT_EQ(solve({NotX}), Solver::Result::Satisfiable);
+  expectSatisfiable(
+  solve({NotX}),
+  UnorderedElementsAre(Pair(X, Solver::Result::Assignment::AssignedFalse)));
 }
 
 TEST_F(SolverTest, UnitConflict) {
@@ -88,7 +109,7 @@
   auto NotX = neg(X);
 
   // X ^ !X
-  EXPECT_EQ(solve({X, NotX}), Solver::Result::Unsatisfiable);
+  expectUnsatisfiable(solve({X, NotX}));
 }
 
 TEST_F(SolverTest, DistinctVars) {
@@ -97,7 +118,10 @@
   auto NotY = neg(Y);
 
   // X ^ !Y
-  EXPECT_EQ(solve({X, NotY}), Solver::Result::Satisfiable);
+  expectSatisfiable(
+  solve({X, NotY}),
+  UnorderedElementsAre(Pair(X, Solver::Result::Assignment::AssignedTrue),
+   Pair(Y, Solver::Result::Assignment::AssignedFalse)));
 }
 
 TEST_F(SolverTest, DoubleNegation) {
@@ -106,7 +130,7 @@
   auto NotNotX = neg(NotX);
 
   // !!X ^ !X
-  EXPECT_EQ(solve({NotNotX, NotX}), Solver::Result::Unsatisfiable);
+  expectUnsatisfiable(solve({NotNotX, NotX}));
 }
 
 TEST_F(SolverTest, NegatedDisjunction) {
@@ -116,7 +140,7 @@
   auto NotXOrY = neg(XOrY);
 
   // !(X v Y) ^ (X v Y)
-  EXPECT_EQ(solve({NotXOrY, XOrY}), Solver::Result::Unsatisfiable);
+  expectUnsatisfiable(solve({NotXOrY, XOrY}));
 }
 
 TEST_F(SolverTest, NegatedConjunction) {
@@ -126,7 +150,7 @@
   auto NotXAndY = neg(XAndY);
 
   // !(X ^ Y) ^ (X ^ Y)
-  EXPECT_EQ(solve({NotXAndY, XAndY}), Solver::Result::Unsatisfiable);
+  expectUnsatisfiable(solve({NotXAndY, XAndY}));
 }
 
 TEST_F(SolverTest, DisjunctionSameVars) {
@@ -135,7 +159,7 @@
   auto XOrNotX = disj(X, NotX);
 
   // X v !X
-  EXPECT_EQ(solve({XOrNotX}), Solver::Result::Satisfiable);
+  expectSatisfiable(solve({XOrNotX}), _);
 }
 
 TEST_F(SolverTest, ConjunctionSameVarsConflict) {
@@ -144,7 +168,7 @@
   auto XAndNotX = conj(X, NotX);
 
   // X ^ !X
-  EXPECT_EQ(solve({XAndNotX}), Solver::Result::Unsatisfiable);
+  expectUnsatisfiable(solve({XAndNotX}));
 }
 
 TEST_F(SolverTest, PureVar) {
@@ -156,7 +180,10 @@
   auto NotXOrNotY = disj(NotX, NotY);
 
   // (!X v Y) ^ (!X v !Y)
-  EXPECT_EQ(solve({NotXOrY, NotXOrNotY}), Solver::Result::Satisfiable);
+  expectSatisfiable(
+  solve({NotXOrY, NotXOrNotY}),
+  UnorderedElementsAre(Pair(X, Solver::Result::Assignment::AssignedFalse),
+   Pair(Y, _)));
 }
 
 TEST_F(SolverTest, MustAssumeVarIsFalse) {
@@ -169,7 +196,10 @@
   auto NotXOrNotY = disj(NotX, NotY);
 
   // (X v Y) ^ (!X v Y) ^ (!X v !Y)
-  EXPECT_EQ(solve({XOrY, NotXOrY, NotXOrNotY}), Solver::Result::Satisfiable);
+  expectSatisfiable(
+  solve({XOrY, NotXOrY, NotXOrNotY}),
+  UnorderedElementsAre(Pair(X, Solver::Result::Assignment::AssignedFalse),
+   Pair(Y, Solver::Result::Assignment::AssignedTrue)));
 }
 
 TEST_F(SolverTest, DeepConflict) {
@@ -183,8 +213,7 @@
   auto XOrNotY = disj(X, NotY);
 
   // (X v Y) ^ (!X v Y) ^ (!X v !Y) ^ (X v !Y)
-  EXPECT_EQ(solve({XOrY, NotXOrY, NotXOrNotY, XOrNotY}),
-Solver::Result::Unsatisfiable);
+  expectUnsatisfiable(solve({XOrY,

[PATCH] D129170: [Sema] Add deprecation warnings for some compiler provided __has_* type traits

2022-07-07 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/lib/Sema/SemaExprCXX.cpp:5400-5401
+SourceLocation KWLoc) {
+  if (!S.getLangOpts().CPlusPlus11)
+return;
+

royjacobson wrote:
> erichkeane wrote:
> > royjacobson wrote:
> > > aaron.ballman wrote:
> > > > I think we should always warn on these, not just in C++11.
> > > I'm not convinced we should. My reasoning is that we need a pretty good 
> > > reason to start issuing warnings for 20 years old code. The usage of 
> > > those builtins with deleted functions after C++11 is pretty broken which 
> > > is a pretty good reason, but for earlier language versions they work 
> > > 'fine' and if people want to use C++03 I prefer leaving them at peace :)
> > > 
> > > People on C++03 are also probably using pretty old versions of libstdc++ 
> > > and/or boost type_traits, so this could have some impact.
> > > 
> > > WDYT?
> > > 
> > warnings don't get emitted for code in header files, so at least that part 
> > isn't a concern.  
> Any header files, or just system headers?
Sorry, yes, Phab is a mess on a cell phone... in things included as System 
Headers.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129170

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


[PATCH] D129250: [clang-repl][NFC] Split weak symbol test to a new test

2022-07-07 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 442879.
junaire added a comment.

Correct copy paster error


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129250

Files:
  clang/test/Interpreter/execute-weak.cpp
  clang/test/Interpreter/execute.cpp


Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -3,7 +3,6 @@
 // RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck 
--check-prefix=CHECK-DRIVER %s
 // REQUIRES: host-supports-jit
 // UNSUPPORTED: system-aix
-// XFAIL: system-windows
 // CHECK-DRIVER: i = 10
 // RUN: cat %s | clang-repl | FileCheck %s
 extern "C" int printf(const char *, ...);
@@ -19,8 +18,4 @@
 inline int foo() { return 42; }
 int r3 = foo();
 
-int __attribute__((weak)) bar() { return 1; }
-auto r4 = printf("bar() = %d\n", bar());
-// CHECK-NEXT: bar() = 1
-
 %quit
Index: clang/test/Interpreter/execute-weak.cpp
===
--- clang/test/Interpreter/execute-weak.cpp
+++ clang/test/Interpreter/execute-weak.cpp
@@ -6,21 +6,9 @@
 // XFAIL: system-windows
 // CHECK-DRIVER: i = 10
 // RUN: cat %s | clang-repl | FileCheck %s
-extern "C" int printf(const char *, ...);
-int i = 42;
-auto r1 = printf("i = %d\n", i);
-// CHECK: i = 42
-
-struct S { float f = 1.0; S *m = nullptr;} s;
-
-auto r2 = printf("S[f=%f, m=0x%llx]\n", s.f, reinterpret_cast(s.m));
-// CHECK-NEXT: S[f=1.00, m=0x0]
-
-inline int foo() { return 42; }
-int r3 = foo();
 
 int __attribute__((weak)) bar() { return 1; }
 auto r4 = printf("bar() = %d\n", bar());
-// CHECK-NEXT: bar() = 1
+// CHECK: bar() = 1
 
 %quit


Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -3,7 +3,6 @@
 // RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck --check-prefix=CHECK-DRIVER %s
 // REQUIRES: host-supports-jit
 // UNSUPPORTED: system-aix
-// XFAIL: system-windows
 // CHECK-DRIVER: i = 10
 // RUN: cat %s | clang-repl | FileCheck %s
 extern "C" int printf(const char *, ...);
@@ -19,8 +18,4 @@
 inline int foo() { return 42; }
 int r3 = foo();
 
-int __attribute__((weak)) bar() { return 1; }
-auto r4 = printf("bar() = %d\n", bar());
-// CHECK-NEXT: bar() = 1
-
 %quit
Index: clang/test/Interpreter/execute-weak.cpp
===
--- clang/test/Interpreter/execute-weak.cpp
+++ clang/test/Interpreter/execute-weak.cpp
@@ -6,21 +6,9 @@
 // XFAIL: system-windows
 // CHECK-DRIVER: i = 10
 // RUN: cat %s | clang-repl | FileCheck %s
-extern "C" int printf(const char *, ...);
-int i = 42;
-auto r1 = printf("i = %d\n", i);
-// CHECK: i = 42
-
-struct S { float f = 1.0; S *m = nullptr;} s;
-
-auto r2 = printf("S[f=%f, m=0x%llx]\n", s.f, reinterpret_cast(s.m));
-// CHECK-NEXT: S[f=1.00, m=0x0]
-
-inline int foo() { return 42; }
-int r3 = foo();
 
 int __attribute__((weak)) bar() { return 1; }
 auto r4 = printf("bar() = %d\n", bar());
-// CHECK-NEXT: bar() = 1
+// CHECK: bar() = 1
 
 %quit
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D128914: [HIP] Add support for handling HIP in the linker wrapper

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

ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128914

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


[PATCH] D107082: [X86][RFC] Enable `_Float16` type support on X86 following the psABI

2022-07-07 Thread Valentin Clement via Phabricator via cfe-commits
clementval added a comment.

@pengfei We are also hitting the following assertion with this patch. Do you 
have any idea why?

  /llvm-project/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:4333: void 
{anonymous}::SelectionDAGLegalize::ConvertNodeToLibcall(llvm::SDNode*): 
Assertion `cast(Node->getOperand(IsStrict ? 2 : 1))->isZero() 
&& "Unable to expand as libcall if it is not normal rounding"' failed.

LLVM IR triggering the assertion.

  ; ModuleID = 'FIRModule'
  source_filename = "FIRModule"
  target triple = "x86_64-unknown-linux-gnu"
  
  @_QMhp237Ea11 = global half 0xH3D00
  @_QMhp237Eb1a = global half 0xH5640
  @_QMf90_kindECascii = external constant i32
  @_QMf90_kindECbyte = external constant i32
  @_QMf90_kindECdouble = external constant i32
  @_QMiso_fortran_envECint16 = external constant i32
  @_QMiso_fortran_envECint32 = external constant i32
  @_QMiso_fortran_envECint64 = external constant i32
  @_QMiso_fortran_envECint8 = external constant i32
  @_QMf90_kindECjis = external constant i32
  @_QMiso_fortran_envEClogical16 = external constant i32
  @_QMiso_fortran_envEClogical32 = external constant i32
  @_QMiso_fortran_envEClogical64 = external constant i32
  @_QMiso_fortran_envEClogical8 = external constant i32
  @_QMf90_kindECnot_available = external constant i32
  @_QMf90_kindECquad = external constant i32
  @_QMiso_fortran_envECreal128 = external constant i32
  @_QMf90_kindECreal16 = external constant i32
  @_QMiso_fortran_envECreal32 = external constant i32
  @_QMiso_fortran_envECreal64 = external constant i32
  @_QMf90_kindECreal64x2 = external constant i32
  @_QMf90_kindECsingle = external constant i32
  @_QMf90_kindECtwobyte = external constant i32
  @_QMf90_kindECucs2 = external constant i32
  @_QMf90_kindECucs4 = external constant i32
  @_QMf90_kindECword = external constant i32
  @_QQcl.2E2F627567312E66393000 = linkonce constant [11 x i8] c"./bug1.f90\00"
  @_QQcl.2831362C313629 = linkonce constant [7 x i8] c"(16,16)"
  @_QQcl.28346631302E3329 = linkonce constant [8 x i8] c"(4f10.3)"
  
  declare ptr @malloc(i64)
  
  declare void @free(ptr)
  
  define void @_QQmain() !dbg !3 {
%1 = alloca { ptr, i64, i32, i8, i8, i8, i8 }, align 8, !dbg !7
%2 = alloca half, i64 1, align 2, !dbg !9
%3 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr 
@_QQcl.2E2F627567312E66393000, i32 9), !dbg !10
%4 = call i1 @_FortranAioOutputAscii(ptr %3, ptr @_QQcl.2831362C313629, i64 
7), !dbg !11
%5 = call i32 @_FortranAioEndIoStatement(ptr %3), !dbg !12
%6 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr 
@_QQcl.28346631302E3329, i64 8, i32 -1, ptr @_QQcl.2E2F627567312E66393000, i32 
10), !dbg !13
%7 = load half, ptr @_QMhp237Ea11, align 2, !dbg !14
%8 = load half, ptr @_QMhp237Eb1a, align 2, !dbg !15
%9 = fpext half %7 to float, !dbg !16
%10 = fpext half %8 to float, !dbg !17
%11 = call float @llvm.copysign.f32(float %9, float %10), !dbg !18
%12 = fptrunc float %11 to half, !dbg !19
store half %12, ptr %2, align 2, !dbg !20
%13 = insertvalue { ptr, i64, i32, i8, i8, i8, i8 } { ptr undef, i64 2, i32 
20180515, i8 0, i8 25, i8 0, i8 0 }, ptr %2, 0, !dbg !7
store { ptr, i64, i32, i8, i8, i8, i8 } %13, ptr %1, align 8, !dbg !7
%14 = call i1 @_FortranAioOutputDescriptor(ptr %6, ptr %1), !dbg !21
%15 = call i32 @_FortranAioEndIoStatement(ptr %6), !dbg !22
ret void, !dbg !23
  }
  
  declare ptr @_FortranAioBeginExternalListOutput(i32, ptr, i32)
  
  declare i1 @_FortranAioOutputAscii(ptr, ptr, i64)
  
  declare i32 @_FortranAioEndIoStatement(ptr)
  
  declare ptr @_FortranAioBeginExternalFormattedOutput(ptr, i64, i32, ptr, i32)
  
  declare i1 @_FortranAioOutputDescriptor(ptr, ptr)
  
  ; Function Attrs: nocallback nofree nosync nounwind readnone speculatable 
willreturn
  declare float @llvm.copysign.f32(float, float) #0
  
  attributes #0 = { nocallback nofree nosync nounwind readnone speculatable 
willreturn }
  
  !llvm.dbg.cu = !{!0}
  !llvm.module.flags = !{!2}
  
  !0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "mlir", 
isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
  !1 = !DIFile(filename: "FIRModule", directory: "/")
  !2 = !{i32 2, !"Debug Info Version", i32 3}
  !3 = distinct !DISubprogram(name: "_QQmain", linkageName: "_QQmain", scope: 
null, file: !4, line: 9, type: !5, scopeLine: 9, spFlags: DISPFlagDefinition | 
DISPFlagOptimized, unit: !0, retainedNodes: !6)
  !4 = !DIFile(filename: "", directory: 
"/local/home/vclement/llvm-project/build")
  !5 = !DISubroutineType(types: !6)
  !6 = !{}
  !7 = !DILocation(line: 39, column: 9, scope: !8)
  !8 = !DILexicalBlockFile(scope: !3, file: !4, discriminator: 0)
  !9 = !DILocation(line: 10, column: 8, scope: !8)
  !10 = !DILocation(line: 17, column: 8, scope: !8)
  !11 = !DILocation(line: 22, column: 8, scope: !8)
  !12 = !DILocation(line: 23, column: 9, scope: !8)
  !13 = !DILocation(line: 31, column: 9, scope: !8)
  !14 = !DILoc

[PATCH] D129222: [pseudo] Implement a guard to determine function declarator.

2022-07-07 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/pseudo/gen/Main.cpp:60
+
+std::string symbolName(clang::pseudo::SymbolID SID,
+   const clang::pseudo::Grammar &G) {

This code is copied right?



Comment at: clang-tools-extra/pseudo/gen/Main.cpp:62
+   const clang::pseudo::Grammar &G) {
+  static const char *const TokNames[] = {
+#define TOK(X) #X,

this deserves a comment: "Compared to in the grammar, ; becomes semi and goto 
becomes kw_goto"?



Comment at: clang-tools-extra/pseudo/gen/Main.cpp:113
+for (clang::pseudo::RuleID RID = 0; RID < G.table().Rules.size(); ++RID) {
+  const clang::pseudo::Rule &R = G.table().Rules[RID];
+  // lhs$$rhs$rhs$rhs

pull out a ruleName() too?

or mangleSymbol()/mangleRule() by analogy with linker name mangling



Comment at: clang-tools-extra/pseudo/include/clang-pseudo/Language.h:29
 // Return true if the guard is satisfied.
 using RuleGuard = llvm::function_ref RHS, const TokenStream &)>;

This allows/encourages guards that dynamically consider multiple rules, which 
increases the amount of coupling between rules and grammar.

Can we express this as
function-declarator := declarator [guard=FunctionDeclarator]?

This does mangle the grammar a bit to our implementation, and introduces two 
names for the same concept (guard & nonterminal).
If this feels ugly and redundant, another option would be to change the guard 
to be specified by the rule ID instead of an extension ID:
```
function-declarator := declarator [guard]

DenseMap Guards;
```



Comment at: clang-tools-extra/pseudo/lib/cxx/CXX.cpp:58
+  //  2) walkup the stack, find the first rule that can determine the kind
+  auto DFS = [&Kind](const ForestNode *Declarator, auto DFS) {
+// !! The declarator defined in the cxx.bnf should be unambiguous.

The "dfs" doesn't actually branch anywhere, so it's just a linear walk, and I 
think replacing the recursion with iteration is actually more readable here.

Also, the first known kind on the walk up == the last known kind on the walk 
down.

So I think this can be written as:

```
bool IsFunction = false;
// Walk down the declarator chain, innermost one wins.
// e.g. (*x)() is a non function, but *(x()) is a function.
for (;;) {
  if (Declarator->kind() != Sequence) // not well-formed, guess
return IsFunction;

  switch (Declarator->rule()) {
case noptr_declarator$$declarator_id: // reached the bottom
  return IsFunction;
 // *X is a nonfunction (unless X is a function).
case ptr_declarator$$ptr_operator$ptr_declarator:
  Declarator = Declarator->elements()[1];
  IsFunction = false;
  continue;
 // X() is a function (unless X is a pointer or similar)
case declarator$$noptr_declarator$parameters_and_qualifiers$...:
  Declarator = Declarator->elements()[0];
  IsFunction = true;
  continue;
// (X) is whatever X is.
case declarator$$l_paren$ptr_declarator$r_paren:
  Declarator = Declarator->elements()[1];
  continue;
// ... more cases ...
default:
  assert(false && "unhandled declarator for IsFunction");
  return IsFunction; 
  }
}
```



Comment at: clang-tools-extra/pseudo/lib/cxx/CXX.cpp:60
+// !! The declarator defined in the cxx.bnf should be unambiguous.
+// FIXME: should we consider opaque node?
+assert(Declarator->kind() == ForestNode::Sequence);

yes, we should. We can't descend, so I think we should just treat it as if it 
were an identifier.



Comment at: clang-tools-extra/pseudo/lib/cxx/CXX.cpp:108
+}
+  };
+  DFS(DeclaratorFN, DFS);

if you haven't handled all rule kinds, you're just falling off the end here?
We should have an assertion in debug mode and probably treat it as opaque in 
production I think


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129222

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


[PATCH] D129250: [clang-repl][NFC] Split weak symbol test to a new test

2022-07-07 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 442902.
junaire added a comment.

extern printf so we can use, another copy paster mistake...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129250

Files:
  clang/test/Interpreter/execute-weak.cpp
  clang/test/Interpreter/execute.cpp


Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -3,7 +3,6 @@
 // RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck 
--check-prefix=CHECK-DRIVER %s
 // REQUIRES: host-supports-jit
 // UNSUPPORTED: system-aix
-// XFAIL: system-windows
 // CHECK-DRIVER: i = 10
 // RUN: cat %s | clang-repl | FileCheck %s
 extern "C" int printf(const char *, ...);
@@ -19,8 +18,4 @@
 inline int foo() { return 42; }
 int r3 = foo();
 
-int __attribute__((weak)) bar() { return 1; }
-auto r4 = printf("bar() = %d\n", bar());
-// CHECK-NEXT: bar() = 1
-
 %quit
Index: clang/test/Interpreter/execute-weak.cpp
===
--- clang/test/Interpreter/execute-weak.cpp
+++ clang/test/Interpreter/execute-weak.cpp
@@ -7,20 +7,8 @@
 // CHECK-DRIVER: i = 10
 // RUN: cat %s | clang-repl | FileCheck %s
 extern "C" int printf(const char *, ...);
-int i = 42;
-auto r1 = printf("i = %d\n", i);
-// CHECK: i = 42
-
-struct S { float f = 1.0; S *m = nullptr;} s;
-
-auto r2 = printf("S[f=%f, m=0x%llx]\n", s.f, reinterpret_cast(s.m));
-// CHECK-NEXT: S[f=1.00, m=0x0]
-
-inline int foo() { return 42; }
-int r3 = foo();
-
-int __attribute__((weak)) bar() { return 1; }
+int __attribute__((weak)) bar() { return 42; }
 auto r4 = printf("bar() = %d\n", bar());
-// CHECK-NEXT: bar() = 1
+// CHECK: bar() = 42
 
 %quit


Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -3,7 +3,6 @@
 // RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck --check-prefix=CHECK-DRIVER %s
 // REQUIRES: host-supports-jit
 // UNSUPPORTED: system-aix
-// XFAIL: system-windows
 // CHECK-DRIVER: i = 10
 // RUN: cat %s | clang-repl | FileCheck %s
 extern "C" int printf(const char *, ...);
@@ -19,8 +18,4 @@
 inline int foo() { return 42; }
 int r3 = foo();
 
-int __attribute__((weak)) bar() { return 1; }
-auto r4 = printf("bar() = %d\n", bar());
-// CHECK-NEXT: bar() = 1
-
 %quit
Index: clang/test/Interpreter/execute-weak.cpp
===
--- clang/test/Interpreter/execute-weak.cpp
+++ clang/test/Interpreter/execute-weak.cpp
@@ -7,20 +7,8 @@
 // CHECK-DRIVER: i = 10
 // RUN: cat %s | clang-repl | FileCheck %s
 extern "C" int printf(const char *, ...);
-int i = 42;
-auto r1 = printf("i = %d\n", i);
-// CHECK: i = 42
-
-struct S { float f = 1.0; S *m = nullptr;} s;
-
-auto r2 = printf("S[f=%f, m=0x%llx]\n", s.f, reinterpret_cast(s.m));
-// CHECK-NEXT: S[f=1.00, m=0x0]
-
-inline int foo() { return 42; }
-int r3 = foo();
-
-int __attribute__((weak)) bar() { return 1; }
+int __attribute__((weak)) bar() { return 42; }
 auto r4 = printf("bar() = %d\n", bar());
-// CHECK-NEXT: bar() = 1
+// CHECK: bar() = 42
 
 %quit
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D128704: [clang-extdef-mapping] Directly process .ast files

2022-07-07 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added inline comments.



Comment at: clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp:149
+  if (!CI)
+CI = new CompilerInstance();
+

thieta wrote:
> steakhal wrote:
> > What takes the ownership of `CI`? When is it deleted?
> I don't think anyone takes ownership and it's never properly deleted. I don't 
> think we really need to since this application just runs and exits and never 
> really keep any state. Do you see a problem with it never being deleted?
Not a big deal. I just think that in general, leak suggests bad software design.
On the other hand, one should not have non-primitive global variables, such as 
smart-pointers. I mean, it's still bad, but let's not touch it xD


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128704

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


[clang] 2d01a85 - [Driver] Improve linking options for target AVR

2022-07-07 Thread Ben Shi via cfe-commits

Author: KOLANICH
Date: 2022-07-07T22:45:21+08:00
New Revision: 2d01a8572076a93fa40c4af934e78a859f3096ee

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

LOG: [Driver] Improve linking options for target AVR

Move user specified inputs to the linking group in case
they and the stardard libraries have mutual reference.

Reviewed By: benshi001

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/AVR.cpp
clang/test/Driver/avr-ld.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/AVR.cpp 
b/clang/lib/Driver/ToolChains/AVR.cpp
index 1e866553d8268..1faefc1148e64 100644
--- a/clang/lib/Driver/ToolChains/AVR.cpp
+++ b/clang/lib/Driver/ToolChains/AVR.cpp
@@ -437,7 +437,6 @@ void AVR::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
  : getToolChain().GetProgramPath(getShortName());
 
   ArgStringList CmdArgs;
-  AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
 
   CmdArgs.push_back("-o");
   CmdArgs.push_back(Output.getFilename());
@@ -503,6 +502,7 @@ void AVR::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 // Add the link library specific to the MCU.
 CmdArgs.push_back(Args.MakeArgString(std::string("-l") + CPU));
 
+AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
 CmdArgs.push_back("--end-group");
 
 // Add user specified linker script.
@@ -514,6 +514,8 @@ void AVR::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 // than the bare minimum supports.
 if (Linker.find("avr-ld") != std::string::npos)
   CmdArgs.push_back(Args.MakeArgString(std::string("-m") + *FamilyName));
+  } else {
+AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
   }
 
   C.addCommand(std::make_unique(

diff  --git a/clang/test/Driver/avr-ld.c b/clang/test/Driver/avr-ld.c
index aa530651152c4..cc98805c7ec27 100644
--- a/clang/test/Driver/avr-ld.c
+++ b/clang/test/Driver/avr-ld.c
@@ -1,44 +1,44 @@
 // RUN: %clang -### --target=avr -mmcu=at90s2313 --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKA %s
-// LINKA: {{".*ld.*"}} {{.*}} {{"-L.*tiny-stack"}} {{.*}} "-Tdata=0x800060" 
"--start-group" {{.*}} "-lat90s2313" "--end-group" "-mavr2"
+// LINKA: {{".*ld.*"}} {{.*}} {{"-L.*tiny-stack"}} {{.*}} "-Tdata=0x800060" 
"--start-group" {{.*}} "-lat90s2313" {{.*}} "--end-group" "-mavr2"
 
 // RUN: %clang -### --target=avr -mmcu=at90s8515 --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKB %s
-// LINKB: {{".*ld.*"}} {{.*}} "-Tdata=0x800060" "--start-group" {{.*}} 
"-lat90s8515" "--end-group" "-mavr2"
+// LINKB: {{".*ld.*"}} {{.*}} "-Tdata=0x800060" "--start-group" {{.*}} 
"-lat90s8515" {{.*}} "--end-group" "-mavr2"
 
 // RUN: %clang -### --target=avr -mmcu=attiny13 --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKC %s
-// LINKC: {{".*ld.*"}} {{.*}} {{"-L.*avr25/tiny-stack"}} {{.*}} 
"-Tdata=0x800060" "--start-group" {{.*}} "-lattiny13" "--end-group" "-mavr25"
+// LINKC: {{".*ld.*"}} {{.*}} {{"-L.*avr25/tiny-stack"}} {{.*}} 
"-Tdata=0x800060" "--start-group" {{.*}} "-lattiny13" {{.*}} "--end-group" 
"-mavr25"
 
 // RUN: %clang -### --target=avr -mmcu=attiny44 --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKD %s
-// LINKD: {{".*ld.*"}} {{.*}} {{"-L.*avr25"}} {{.*}} "-Tdata=0x800060" 
"--start-group" {{.*}} "-lattiny44" "--end-group" "-mavr25"
+// LINKD: {{".*ld.*"}} {{.*}} {{"-L.*avr25"}} {{.*}} "-Tdata=0x800060" 
"--start-group" {{.*}} "-lattiny44" {{.*}} "--end-group" "-mavr25"
 
 // RUN: %clang -### --target=avr -mmcu=atmega103 --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKE %s
-// LINKE: {{".*ld.*"}} {{.*}} {{"-L.*avr31"}} {{.*}} "-Tdata=0x800060" 
"--start-group" {{.*}} "-latmega103" "--end-group" "-mavr31"
+// LINKE: {{".*ld.*"}} {{.*}} {{"-L.*avr31"}} {{.*}} "-Tdata=0x800060" 
"--start-group" {{.*}} "-latmega103" {{.*}} "--end-group" "-mavr31"
 
 // RUN: %clang -### --target=avr -mmcu=atmega8u2 --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKF %s
-// LINKF: {{".*ld.*"}} {{.*}} {{"-L.*avr35"}} {{.*}} "-Tdata=0x800100" 
"--start-group" {{.*}} "-latmega8u2" "--end-group" "-mavr35"
+// LINKF: {{".*ld.*"}} {{.*}} {{"-L.*avr35"}} {{.*}} "-Tdata=0x800100" 
"--start-group" {{.*}} "-latmega8u2" {{.*}} "--end-group" "-mavr35"
 
 // RUN: %clang -### --target=avr -mmcu=atmega48pa --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKG %s
-// LINKG: {{".*ld.*"}} {{.*}} {{"-L.*avr4"}} {{.*}} "-Tdata=0x800100" 
"--start-group" {{.*}} "-latmega48pa" "--end-group" "-mavr4"
+// LINKG: {{".*ld.*"}} {{.*}} {{"-L.*avr4"}} {{.*}} "-Tdata=0x800100" 
"--start-group" {{.*}} "-latmega48pa

[PATCH] D127501: [AVR] Fixed broken linking using `avr-gcc`.

2022-07-07 Thread Ben Shi via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2d01a8572076: [Driver] Improve linking options for target 
AVR (authored by KOLANICH, committed by benshi001).
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127501

Files:
  clang/lib/Driver/ToolChains/AVR.cpp
  clang/test/Driver/avr-ld.c


Index: clang/test/Driver/avr-ld.c
===
--- clang/test/Driver/avr-ld.c
+++ clang/test/Driver/avr-ld.c
@@ -1,44 +1,44 @@
 // RUN: %clang -### --target=avr -mmcu=at90s2313 --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKA %s
-// LINKA: {{".*ld.*"}} {{.*}} {{"-L.*tiny-stack"}} {{.*}} "-Tdata=0x800060" 
"--start-group" {{.*}} "-lat90s2313" "--end-group" "-mavr2"
+// LINKA: {{".*ld.*"}} {{.*}} {{"-L.*tiny-stack"}} {{.*}} "-Tdata=0x800060" 
"--start-group" {{.*}} "-lat90s2313" {{.*}} "--end-group" "-mavr2"
 
 // RUN: %clang -### --target=avr -mmcu=at90s8515 --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKB %s
-// LINKB: {{".*ld.*"}} {{.*}} "-Tdata=0x800060" "--start-group" {{.*}} 
"-lat90s8515" "--end-group" "-mavr2"
+// LINKB: {{".*ld.*"}} {{.*}} "-Tdata=0x800060" "--start-group" {{.*}} 
"-lat90s8515" {{.*}} "--end-group" "-mavr2"
 
 // RUN: %clang -### --target=avr -mmcu=attiny13 --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKC %s
-// LINKC: {{".*ld.*"}} {{.*}} {{"-L.*avr25/tiny-stack"}} {{.*}} 
"-Tdata=0x800060" "--start-group" {{.*}} "-lattiny13" "--end-group" "-mavr25"
+// LINKC: {{".*ld.*"}} {{.*}} {{"-L.*avr25/tiny-stack"}} {{.*}} 
"-Tdata=0x800060" "--start-group" {{.*}} "-lattiny13" {{.*}} "--end-group" 
"-mavr25"
 
 // RUN: %clang -### --target=avr -mmcu=attiny44 --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKD %s
-// LINKD: {{".*ld.*"}} {{.*}} {{"-L.*avr25"}} {{.*}} "-Tdata=0x800060" 
"--start-group" {{.*}} "-lattiny44" "--end-group" "-mavr25"
+// LINKD: {{".*ld.*"}} {{.*}} {{"-L.*avr25"}} {{.*}} "-Tdata=0x800060" 
"--start-group" {{.*}} "-lattiny44" {{.*}} "--end-group" "-mavr25"
 
 // RUN: %clang -### --target=avr -mmcu=atmega103 --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKE %s
-// LINKE: {{".*ld.*"}} {{.*}} {{"-L.*avr31"}} {{.*}} "-Tdata=0x800060" 
"--start-group" {{.*}} "-latmega103" "--end-group" "-mavr31"
+// LINKE: {{".*ld.*"}} {{.*}} {{"-L.*avr31"}} {{.*}} "-Tdata=0x800060" 
"--start-group" {{.*}} "-latmega103" {{.*}} "--end-group" "-mavr31"
 
 // RUN: %clang -### --target=avr -mmcu=atmega8u2 --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKF %s
-// LINKF: {{".*ld.*"}} {{.*}} {{"-L.*avr35"}} {{.*}} "-Tdata=0x800100" 
"--start-group" {{.*}} "-latmega8u2" "--end-group" "-mavr35"
+// LINKF: {{".*ld.*"}} {{.*}} {{"-L.*avr35"}} {{.*}} "-Tdata=0x800100" 
"--start-group" {{.*}} "-latmega8u2" {{.*}} "--end-group" "-mavr35"
 
 // RUN: %clang -### --target=avr -mmcu=atmega48pa --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKG %s
-// LINKG: {{".*ld.*"}} {{.*}} {{"-L.*avr4"}} {{.*}} "-Tdata=0x800100" 
"--start-group" {{.*}} "-latmega48pa" "--end-group" "-mavr4"
+// LINKG: {{".*ld.*"}} {{.*}} {{"-L.*avr4"}} {{.*}} "-Tdata=0x800100" 
"--start-group" {{.*}} "-latmega48pa" {{.*}} "--end-group" "-mavr4"
 
 // RUN: %clang -### --target=avr -mmcu=atmega328 --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKH %s
-// LINKH: {{".*ld.*"}} {{.*}} {{"-L.*avr5"}} {{.*}} "-Tdata=0x800100" 
"--start-group" {{.*}} "-latmega328" "--end-group" "-mavr5"
+// LINKH: {{".*ld.*"}} {{.*}} {{"-L.*avr5"}} {{.*}} "-Tdata=0x800100" 
"--start-group" {{.*}} "-latmega328" {{.*}} "--end-group" "-mavr5"
 
 // RUN: %clang -### --target=avr -mmcu=atmega1281 --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKI %s
-// LINKI: {{".*ld.*"}} {{.*}} {{"-L.*avr51"}} {{.*}} "-Tdata=0x800200" 
"--start-group" {{.*}} "-latmega1281" "--end-group" "-mavr51"
+// LINKI: {{".*ld.*"}} {{.*}} {{"-L.*avr51"}} {{.*}} "-Tdata=0x800200" 
"--start-group" {{.*}} "-latmega1281" {{.*}} "--end-group" "-mavr51"
 
 // RUN: %clang -### --target=avr -mmcu=atmega2560 --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKJ %s
-// LINKJ: {{".*ld.*"}} {{.*}} {{"-L.*avr6"}} {{.*}} "-Tdata=0x800200" 
"--start-group" {{.*}} "-latmega2560" "--end-group" "-mavr6"
+// LINKJ: {{".*ld.*"}} {{.*}} {{"-L.*avr6"}} {{.*}} "-Tdata=0x800200" 
"--start-group" {{.*}} "-latmega2560" {{.*}} "--end-group" "-mavr6"
 
 // RUN: %clang -### --target=avr -mmcu=attiny10 --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKK %s
-// LINKK: {{".*ld.*"}} {{.*}} {{"-L.*avrtiny"}} {{.*}} "-Tdata=0x800040" 
"--start-group" {{.*}} "-lattiny10" "--end-group" "-mavrtiny"
+// LINKK: {{".*ld.*"}} {{.*}} {{"-L.*avrtiny"}} {{.*}} "

[PATCH] D129033: [Clang] Use metadata to make identifying embedded objects easier

2022-07-07 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

Generally makes sense, some notes though




Comment at: clang/test/Frontend/embed-object.ll:17
+
+; CHECK: !llvm.embedded.object = !{![[METADATA_1:[0-9]+]], 
![[METADATA_2:[0-9]+]]}
+; CHECK: ![[METADATA_1]] = !{ptr @[[OBJECT_1]], !".llvm.offloading"}

shouldn't it be objects?

The metadata should be defined somewhere (lang ref?)



Comment at: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp:371
+  // `llvm.embedded.object` metadata with the `.llvm.offloading` section.
+  auto MD = M->getNamedMetadata("llvm.embedded.object");
+  for (const MDNode *Op : MD->operands()) {

Handle nullptr


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129033

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


[PATCH] D128314: [Clang-tidy] Fixing a bug in clang-tidy infinite-loop checker

2022-07-07 Thread Nathan James via Phabricator via cfe-commits
njames93 added a subscriber: klimek.
njames93 added a comment.

Sorry to do this again, but could this be split up again, one patch for the new 
matcher and the tests associated with it, then another for the actual bug fix.
Also cc @klimek as he is the code owner of ASTMatchers


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128314

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


[PATCH] D129033: [Clang] Use metadata to make identifying embedded objects easier

2022-07-07 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 updated this revision to Diff 442926.
jhuber6 added a comment.

Updating to use `objects` and adding documentation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129033

Files:
  clang/test/Frontend/embed-object.c
  clang/test/Frontend/embed-object.ll
  clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
  llvm/docs/LangRef.rst
  llvm/include/llvm/Transforms/Utils/ModuleUtils.h
  llvm/lib/Transforms/Utils/ModuleUtils.cpp

Index: llvm/lib/Transforms/Utils/ModuleUtils.cpp
===
--- llvm/lib/Transforms/Utils/ModuleUtils.cpp
+++ llvm/lib/Transforms/Utils/ModuleUtils.cpp
@@ -275,5 +275,12 @@
   GV->setSection(SectionName);
   GV->setAlignment(Alignment);
 
+  LLVMContext &Ctx = M.getContext();
+  NamedMDNode *MD = M.getOrInsertNamedMetadata("llvm.embedded.objects");
+  Metadata *MDVals[] = {ConstantAsMetadata::get(GV),
+MDString::get(Ctx, SectionName)};
+
+  MD->addOperand(llvm::MDNode::get(Ctx, MDVals));
+
   appendToCompilerUsed(M, GV);
 }
Index: llvm/include/llvm/Transforms/Utils/ModuleUtils.h
===
--- llvm/include/llvm/Transforms/Utils/ModuleUtils.h
+++ llvm/include/llvm/Transforms/Utils/ModuleUtils.h
@@ -109,7 +109,8 @@
 std::string getUniqueModuleId(Module *M);
 
 /// Embed the memory buffer \p Buf into the module \p M as a global using the
-/// specified section name.
+/// specified section name. Also provide metadata entry to identify it in the
+/// module using the same section name.
 void embedBufferInModule(Module &M, MemoryBufferRef Buf, StringRef SectionName,
  Align Alignment = Align(1));
 
Index: llvm/docs/LangRef.rst
===
--- llvm/docs/LangRef.rst
+++ llvm/docs/LangRef.rst
@@ -7429,6 +7429,19 @@
 module. This is represented by the ``LTOPostLink`` module flags metadata, which
 will be created with a value of ``1`` when LTO linking occurs.
 
+Embedded Objects Names Metadata
+===
+
+Offloading compilations need to embed device code into the host section table to
+create a fat binary. This metadata node references each global that will be
+embedded in the module. The primary use for this is to make referencing these
+globals more efficient in the IR. The metadata references nodes containing
+pointers to the global to be embedded followed by the section name it will be
+stored at::
+
+!llvm.embedded.objects = !{!0}
+!0 = !{ptr @object, !".section"}
+
 Automatic Linker Flags Named Metadata
 =
 
Index: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
===
--- clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -366,12 +366,26 @@
 return createStringError(inconvertibleErrorCode(),
  "Failed to create module");
 
-  // Extract offloading data from globals with the `.llvm.offloading` section.
-  for (GlobalVariable &GV : M->globals()) {
-if (!GV.hasSection() || !GV.getSection().equals(OFFLOAD_SECTION_MAGIC_STR))
+  // Extract offloading data from globals referenced by the
+  // `llvm.embedded.object` metadata with the `.llvm.offloading` section.
+  auto MD = M->getNamedMetadata("llvm.embedded.object");
+  if (!MD)
+return Error::success();
+
+  for (const MDNode *Op : MD->operands()) {
+if (Op->getNumOperands() < 2)
+  continue;
+
+MDString *SectionID = dyn_cast(Op->getOperand(1));
+if (!SectionID || SectionID->getString() != OFFLOAD_SECTION_MAGIC_STR)
+  continue;
+
+GlobalVariable *GV =
+mdconst::dyn_extract_or_null(Op->getOperand(0));
+if (!GV)
   continue;
 
-auto *CDS = dyn_cast(GV.getInitializer());
+auto *CDS = dyn_cast(GV->getInitializer());
 if (!CDS)
   continue;
 
Index: clang/test/Frontend/embed-object.ll
===
--- clang/test/Frontend/embed-object.ll
+++ clang/test/Frontend/embed-object.ll
@@ -13,3 +13,7 @@
 define i32 @foo() {
   ret i32 0
 }
+
+; CHECK: !llvm.embedded.objects = !{![[METADATA_1:[0-9]+]], ![[METADATA_2:[0-9]+]]}
+; CHECK: ![[METADATA_1]] = !{ptr @[[OBJECT_1]], !".llvm.offloading"}
+; CHECK: ![[METADATA_2]] = !{ptr @[[OBJECT_2]], !".llvm.offloading"}
Index: clang/test/Frontend/embed-object.c
===
--- clang/test/Frontend/embed-object.c
+++ clang/test/Frontend/embed-object.c
@@ -4,3 +4,6 @@
 // CHECK: @llvm.compiler.used = appending global [1 x ptr] [ptr @[[OBJECT]]], section "llvm.metadata"
 
 void foo(void) {}
+
+// CHECK: !llvm.embedded.objects = !{![[METADATA:[0-9]+]]}
+// CHECK: ![[METADATA]] = !{ptr @[[OBJECT]], !".llvm.of

[PATCH] D107082: [X86][RFC] Enable `_Float16` type support on X86 following the psABI

2022-07-07 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei added a comment.

Thanks @clementval for reporting it and the reproducer. Put a patch D129294 
 to address it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107082

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


[PATCH] D128977: [clangd] Support "usedAsMutableReference" in member initializations

2022-07-07 Thread Christian Kandeler via Phabricator via cfe-commits
ckandeler added a comment.

Note that the build failure seems unrelated, as it's due to a failing 
clang-tidy test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128977

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


[PATCH] D128612: RISC-V big-endian support implementation

2022-07-07 Thread Alex Bradbury via Phabricator via cfe-commits
asb added a comment.

Thanks for this patch Guy. As just discussed in the RISC-V sync-up call, it 
would be helpful from a review perspective to write down at least a simple 
plain-text description of the changes to the psABI doc needed to reflect the BE 
ABI implemented by GCC (and soon LLVM), perhaps in an issue.

I think this patch is lacking some test coverage around things like fixup 
handling (e.g. the logic to swap fixups).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128612

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


[PATCH] D129298: Add denormal-fp-math attribute for f16

2022-07-07 Thread David Candler via Phabricator via cfe-commits
dcandler created this revision.
dcandler added reviewers: arsenm, spatel, echristo, andrew.w.kaylor, 
cameron.mcinally.
Herald added subscribers: jsji, kosarev, jdoerfert, pengfei, hiraditya, 
kristof.beyls, tpr.
Herald added a project: All.
dcandler requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, MaskRay, wdng.
Herald added projects: clang, LLVM.

Denormal flushing behavior is currently controlled with the
denormal-fp-math attribute, with a denormal-fp-math-f32 variant for
targets such as AMDGPU where f32 denormals are controlled separately
from f16/f64. However there are other targets such as Arm (and I
think x86) where f16 denormals can be distinct from f32/f64. As the
attributes are now used for constant folding, this can lead to
incorrect folded values for half precision floats on those targets.

This patch adds a denormal-fp-math-f16 attribute, which functions
identically to denormal-fp-math-f32, but overrides the denormal
handling mode for f16 only. Constant folding tests have been
expanded to include half floats, and check both f16 and f32
variants of the attribute.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129298

Files:
  clang/docs/UsersManual.rst
  clang/include/clang/Basic/CodeGenOptions.h
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  llvm/docs/LangRef.rst
  llvm/include/llvm/CodeGen/CommandFlags.h
  llvm/include/llvm/Target/TargetOptions.h
  llvm/lib/CodeGen/CommandFlags.cpp
  llvm/lib/IR/Function.cpp
  llvm/test/Transforms/InstSimplify/constant-fold-fp-denormal.ll

Index: llvm/test/Transforms/InstSimplify/constant-fold-fp-denormal.ll
===
--- llvm/test/Transforms/InstSimplify/constant-fold-fp-denormal.ll
+++ llvm/test/Transforms/InstSimplify/constant-fold-fp-denormal.ll
@@ -12,6 +12,73 @@
 ; normal operand (a number plus zero is the same number).
 ;  ;
 
+define half @test_half_fadd_ieee() #0 {
+; CHECK-LABEL: @test_half_fadd_ieee(
+; CHECK-NEXT:ret half 0xH8200
+;
+; default ieee mode leaves result as a denormal
+  %result = fadd half 0xH8400, 0xH0200
+  ret half %result
+}
+
+define half @test_half_fadd_pzero_out() #1 {
+; CHECK-LABEL: @test_half_fadd_pzero_out(
+; CHECK-NEXT:ret half 0xH
+;
+; denormal result is flushed to positive zero
+  %result = fadd half 0xH8400, 0xH0200
+  ret half %result
+}
+
+define half @test_half_fadd_psign_out() #2 {
+; CHECK-LABEL: @test_half_fadd_psign_out(
+; CHECK-NEXT:ret half 0xH8000
+;
+; denormal result is flushed to sign preserved zero
+  %result = fadd half 0xH8400, 0xH0200
+  ret half %result
+}
+
+define half @test_half_fadd_pzero_in() #3 {
+; CHECK-LABEL: @test_half_fadd_pzero_in(
+; CHECK-NEXT:ret half 0xH8400
+;
+; denormal operand is treated as zero
+; normal operand added to zero results in the same operand as a result
+  %result = fadd half 0xH8400, 0xH0200
+  ret half %result
+}
+
+define half @test_half_fadd_psign_in() #4 {
+; CHECK-LABEL: @test_half_fadd_psign_in(
+; CHECK-NEXT:ret half 0xH8400
+;
+; denormal operand is treated as zero
+; normal operand added to zero results in the same operand as a result
+  %result = fadd half 0xH8400, 0xH0200
+  ret half %result
+}
+
+define half @test_half_fadd_pzero_f16_pzero_out() #9 {
+; CHECK-LABEL: @test_half_fadd_pzero_f16_pzero_out(
+; CHECK-NEXT:ret half 0xH
+;
+; f16 only attribute should flush half float output
+; same as pzero_out above
+  %result = fadd half 0xH8400, 0xH0200
+  ret half %result
+}
+
+define half @test_half_fadd_pzero_f32_pzero_out() #5 {
+; CHECK-LABEL: @test_half_fadd_pzero_f32_pzero_out(
+; CHECK-NEXT:ret half 0xH8200
+;
+; f32 only attribute should not flush half float output
+; default ieee mode leaves result as a denormal
+  %result = fadd half 0xH8400, 0xH0200
+  ret half %result
+}
+
 define float @test_float_fadd_ieee() #0 {
 ; CHECK-LABEL: @test_float_fadd_ieee(
 ; CHECK-NEXT:ret float 0xB800
@@ -59,12 +126,22 @@
   ret float %result
 }
 
-define float @test_float_fadd_pzero_f32_out() #5 {
-; CHECK-LABEL: @test_float_fadd_pzero_f32_out(
+define float @test_float_fadd_pzero_f16_pzero_out() #9 {
+; CHECK-LABEL: @test_float_fadd_pzero_f16_pzero_out(
+; CHECK-NEXT:ret float 0xB800
+;
+; f16 only attribute should not flush float output
+; default ieee mode leaves result as a denormal
+  %result = fadd float 0xB810, 0x3800
+  ret float %result
+}
+
+define float @test_float_fadd_pzero_f32_pzero_out() #5 {
+; CHECK-LABEL: @test_float_fadd_pzero_f32_pzero_out(
 ; CHECK-NEXT:ret float 0.00e+00
 ;
 ; f32 only attribute should flush float output
-; default ieee mode leaves result as a denormal
+; same as pzero_out above
   %result = fadd float 0xB810, 0x380

[PATCH] D129151: [Metadata] Add 'exclude' metadata to add the exclude flags on globals

2022-07-07 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 updated this revision to Diff 442941.
jhuber6 added a comment.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Addressing comments. Metadata is now empty and must be empty for the flag to be 
emitted.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129151

Files:
  clang/test/Frontend/embed-object.c
  clang/test/Frontend/embed-object.ll
  llvm/docs/LangRef.rst
  llvm/include/llvm/IR/FixedMetadataKinds.def
  llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
  llvm/lib/Target/TargetLoweringObjectFile.cpp
  llvm/lib/Transforms/Utils/ModuleUtils.cpp
  llvm/test/CodeGen/X86/coff-exclude.ll
  llvm/test/CodeGen/X86/elf-exclude.ll
  llvm/test/CodeGen/X86/offload_sections.ll

Index: llvm/test/CodeGen/X86/offload_sections.ll
===
--- llvm/test/CodeGen/X86/offload_sections.ll
+++ llvm/test/CodeGen/X86/offload_sections.ll
@@ -1,8 +1,10 @@
 ; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu | FileCheck %s --check-prefix=CHECK-ELF
 ; RUN: llc < %s -mtriple=x86_64-win32-gnu | FileCheck %s --check-prefix=CHECK-COFF
 
-@llvm.embedded.object = private constant [1 x i8] c"\00", section ".llvm.offloading"
+@llvm.embedded.object = private constant [1 x i8] c"\00", section ".llvm.offloading", align 8, !exclude !0
 @llvm.compiler.used = appending global [1 x ptr] [ptr @llvm.embedded.object], section "llvm.metadata"
 
+!0 = !{}
+
 ; CHECK-ELF: .section	.llvm.offloading,"e",@llvm_offloading
-; CHECK-COFF: .section	.llvm.offloading,"dr"
+; CHECK-COFF: .section	.llvm.offloading,"ynD"
Index: llvm/test/CodeGen/X86/elf-exclude.ll
===
--- /dev/null
+++ llvm/test/CodeGen/X86/elf-exclude.ll
@@ -0,0 +1,18 @@
+; RUN: llc -mtriple x86_64-pc-linux-gnu < %s | FileCheck %s
+
+@a = global i32 1
+@b = global i32 1, !exclude !0
+@c = global i32 1, section "aaa"
+; CHECK-DAG: .type	c,@object
+; CHECK-DAG: 	.section	aaa,"aw",@progbits
+@d = global i32 1, section "bbb", !exclude !0
+; CHECK-DAG: .type	d,@object
+; CHECK-DAG: 	.section	bbb,"e",@progbits
+@e = global i32 1, section "bbb", !exclude !0
+; CHECK-DAG: .type	e,@object
+@f = global i32 1, section "ccc", !exclude !0
+@g = global i32 1, section "ccc"
+; CHECK-DAG:	.type	f,@object
+; CHECK-DAG:	.section	ccc,"e",@progbits
+
+!0 = !{}
Index: llvm/test/CodeGen/X86/coff-exclude.ll
===
--- /dev/null
+++ llvm/test/CodeGen/X86/coff-exclude.ll
@@ -0,0 +1,18 @@
+; RUN: llc -mtriple x86_64-win32-gnu < %s | FileCheck %s
+
+@a = global i32 1
+@b = global i32 1, !exclude !0
+@c = global i32 1, section "aaa"
+; CHECK-DAG: c
+; CHECK-DAG: 	.section	aaa,"dw"
+@d = global i32 1, section "bbb", !exclude !0
+; CHECK-DAG: d
+; CHECK-DAG: 	.section	bbb,"ynD"
+@e = global i32 1, section "bbb", !exclude !0
+; CHECK-DAG: e
+@f = global i32 1, section "ccc", !exclude !0
+@g = global i32 1, section "ccc"
+; CHECK-DAG: f
+; CHECK-DAG:	.section	ccc,"ynD"
+
+!0 = !{}
Index: llvm/lib/Transforms/Utils/ModuleUtils.cpp
===
--- llvm/lib/Transforms/Utils/ModuleUtils.cpp
+++ llvm/lib/Transforms/Utils/ModuleUtils.cpp
@@ -281,6 +281,7 @@
 MDString::get(Ctx, SectionName)};
 
   MD->addOperand(llvm::MDNode::get(Ctx, MDVals));
+  GV->setMetadata(LLVMContext::MD_exclude, llvm::MDNode::get(Ctx, {}));
 
   appendToCompilerUsed(M, GV);
 }
Index: llvm/lib/Target/TargetLoweringObjectFile.cpp
===
--- llvm/lib/Target/TargetLoweringObjectFile.cpp
+++ llvm/lib/Target/TargetLoweringObjectFile.cpp
@@ -240,6 +240,13 @@
 return SectionKind::getBSS();
   }
 
+  // Global variables with '!exclude' should get the exclude section kind if
+  // they have an explicit section and no other metadata.
+  if (GVar->hasSection())
+if (MDNode *MD = GVar->getMetadata(LLVMContext::MD_exclude))
+  if (!MD->getNumOperands())
+return SectionKind::getExclude();
+
   // If the global is marked constant, we can put it into a mergable section,
   // a mergable string section, or general .data if it contains relocations.
   if (GVar->isConstant()) {
Index: llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
===
--- llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -449,9 +449,6 @@
   Name == ".llvmbc" || Name == ".llvmcmd")
 return SectionKind::getMetadata();
 
-  if (Name == ".llvm.offloading")
-return SectionKind::getExclude();
-
   if (Name.empty() || Name[0] != '.') return K;
 
   // Default implementation based on some magic section names.
Index: llvm/include/llvm/IR/FixedMetadataKinds.def
===
--- llvm/i

[PATCH] D129033: [Clang] Use metadata to make identifying embedded objects easier

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

LG


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129033

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


[PATCH] D129151: [Metadata] Add 'exclude' metadata to add the exclude flags on globals

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

LG


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129151

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


[PATCH] D128328: [C++20][Modules] Improve handing of Private Module Fragment diagnostics.

2022-07-07 Thread Iain Sandoe via Phabricator via cfe-commits
iains updated this revision to Diff 442942.
iains marked 3 inline comments as done.
iains added a comment.

rebased, reworked

- to follow the changes proposed by core
- to make the diagnostics follow that and a compromise for the proposed 
revision before the core amendment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128328

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaLookup.cpp
  clang/lib/Sema/SemaModule.cpp
  clang/test/Modules/Reachability-Private.cpp
  clang/test/Modules/cxx20-10-5-ex1.cpp

Index: clang/test/Modules/cxx20-10-5-ex1.cpp
===
--- /dev/null
+++ clang/test/Modules/cxx20-10-5-ex1.cpp
@@ -0,0 +1,53 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: cd %t
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface std-10-5-ex1-interface.cpp \
+// RUN: -DBAD_FWD_DECL  -fsyntax-only -verify
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface std-10-5-ex1-interface.cpp \
+// RUN: -o A.pcm
+
+// RUN: %clang_cc1 -std=c++20 std-10-5-ex1-use.cpp  -fmodule-file=A.pcm \
+// RUN:-fsyntax-only -verify
+
+//--- std-10-5-ex1-interface.cpp
+
+export module A;
+#ifdef BAD_FWD_DECL
+export inline void fn_e(); // expected-error {{exported inline function not defined before the private module fragment}}
+   // expected-n...@std-10-5-ex1-interface.cpp:21 {{private module fragment begins here}}
+#endif
+export inline void ok_fn() {}
+export inline void ok_fn2();
+#ifdef BAD_FWD_DECL
+inline void fn_m(); // expected-error {{un-exported inline function not defined before the private module fragment}}
+// expected-n...@std-10-5-ex1-interface.cpp:21 {{private module fragment begins here}}
+#endif
+static void fn_s();
+export struct X;
+export void g(X *x) {
+  fn_s();
+}
+export X *factory();
+void ok_fn2() {}
+
+module :private;
+struct X {};
+X *factory() {
+  return new X();
+}
+
+void fn_e() {}
+void fn_m() {}
+void fn_s() {}
+
+//--- std-10-5-ex1-use.cpp
+
+import A;
+
+void foo() {
+  X x; // expected-error 1+{{missing '#include'; 'X' must be defined before it is used}}
+   // expected-n...@std-10-5-ex1-interface.cpp:22 1+{{definition here is not reachable}}
+  X *p = factory();
+}
Index: clang/test/Modules/Reachability-Private.cpp
===
--- clang/test/Modules/Reachability-Private.cpp
+++ clang/test/Modules/Reachability-Private.cpp
@@ -4,18 +4,25 @@
 // RUN: mkdir -p %t
 // RUN: split-file %s %t
 //
-// RUN: %clang_cc1 -std=c++20 %t/Private.cppm -emit-module-interface -o %t/Private.pcm
-// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t %t/Use.cpp -verify -fsyntax-only
+// RUN: %clang_cc1 -std=c++20 %t/Private.cppm -emit-module-interface \
+// RUN: -o %t/Private.pcm
+// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t %t/Use.cpp \
+// RUN: -DTEST_BADINLINE -verify -fsyntax-only
 
 //--- Private.cppm
 export module Private;
-inline void fn_m(); // OK, module-linkage inline function
+#ifdef TEST_BADINLINE
+inline void fn_m(); // expected-error {{un-exported inline function not defined before the private module fragment}}
+// expected-n...@private.cppm:13 {{private module fragment begins here}}
+#endif
 static void fn_s();
 export struct X;
 
 export void g(X *x) {
   fn_s(); // OK, call to static function in same translation unit
-  fn_m(); // OK, call to module-linkage inline function
+#ifdef TEST_BADINLINE
+  fn_m(); // fn_m is not OK.
+#endif
 }
 export X *factory(); // OK
 
@@ -30,10 +37,8 @@
 //--- Use.cpp
 import Private;
 void foo() {
-  X x; // expected-error {{definition of 'X' must be imported from module 'Private.' before it is required}}
-   // expected-error@-1 {{definition of 'X' must be imported from module 'Private.' before it is required}}
-   // expected-note@* {{definition here is not reachable}}
-   // expected-note@* {{definition here is not reachable}}
+  X x; // expected-error 1+{{missing '#include'; 'X' must be defined before it is used}}
+   // expected-n...@private.cppm:18 1+{{definition here is not reachable}}
   auto _ = factory();
   auto *__ = factory();
   X *___ = factory();
Index: clang/lib/Sema/SemaModule.cpp
===
--- clang/lib/Sema/SemaModule.cpp
+++ clang/lib/Sema/SemaModule.cpp
@@ -901,6 +901,17 @@
 diagExportedUnnamedDecl(*this, UnnamedDeclKind::Context, Child,
 BlockStart);
   }
+  if (auto *FD = dyn_cast(Child)) {
+// [dcl.inline]/7
+// If an inline function or variable that is attached to a named module
+// is declared in a definition domain, it shall be defined in that
+// domain.
+// S

[PATCH] D128328: [C++20][Modules] Improve handing of Private Module Fragment diagnostics.

2022-07-07 Thread Iain Sandoe via Phabricator via cfe-commits
iains added a comment.

the revised diagnostics look like this:

` error: {un-}exported inline function not defined before the private module 
fragment`

with 
` note: private module fragment begins here` pointing to the start of the PMF

If there is no PMF then we just say:

` error: {un-}exported inline function not defined `




Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:11155
+def err_export_inline_not_defined : Error<
+  "exported inline functions must be defined within the module purview"
+  " and before any private module fragment">;

iains wrote:
> ChuanqiXu wrote:
> > iains wrote:
> > > iains wrote:
> > > > ChuanqiXu wrote:
> > > > > From my reading, 'exported' is not emphasized.
> > > > it is here:
> > > > https://eel.is/c++draft/module#private.frag-2.1
> > > > ( I agree it is somewhat confusing, but the export makes the linkage 
> > > > external, which the example treats differently from the fn_m() case 
> > > > which has module linkage).
> > > > 
> > > > It is possible that we might need to pull together several pieces of 
> > > > the std and maybe ask core for clarification?
> > > > it is here:
> > > > https://eel.is/c++draft/module#private.frag-2.1
> > > > ( I agree it is somewhat confusing, but the export makes the linkage 
> > > > external, which the example treats differently from the fn_m() case 
> > > > which has module linkage).
> > > 
> > > hmm... my linkage comment is wrong - however the distinction between 
> > > exported and odr-used seems to be made here (fn_m() and fn_e()).
> > > > 
> > > > It is possible that we might need to pull together several pieces of 
> > > > the std and maybe ask core for clarification?
> > > 
> > > 
> > What I read is:
> > > [dcl.inline]p7: https://eel.is/c++draft/dcl.inline#7
> > > If an inline function or variable that is attached to a named module 
> > > is declared in a definition domain, it shall be defined in that domain.
> > 
> > and the definition of `definition domain` is:
> > > [basic.def.odr]p12: https://eel.is/c++draft/basic#def.odr-12
> > >   A definition domain is a private-module-fragment or the portion of 
> > > a translation unit excluding its private-module-fragment (if any).
> > 
> > The definition of "attached to a named module" is:
> > > [module.unit]p7: https://eel.is/c++draft/module.unit#7
> > >  A module is either a named module or the global module. A 
> > > declaration is attached to a module as follows: ...
> > 
> > So it is clearly not consistency with [module.private.frag]p2.1. I would 
> > send this to WG21.
> Yes, that was what I found - maybe we are  missing something about the export 
> that changes those rules.
> .
I think that we can consider this closed by the question to the ext reflector 
and the amendment proposed by core.



Comment at: clang/test/Modules/cxx20-10-5-ex1.cpp:25-28
+export void g(X *x) {
+  fn_s();
+  fn_m();
+}

ChuanqiXu wrote:
> vsapsai wrote:
> > Can `export inline` function call other non-`export inline` functions? 
> > Sorry if it is tested somewhere else. Curious what are the transitive 
> > restrictions, so we test edge cases.
> I guess it is not tested. But a non-export function wouldn't be exported if 
> it is called by export function from the perspective of std. Although more 
> tests should be fine all the time, the current test case should come from the 
> example in the standard. We could send another test if we want.
I've changed the example to match the proposed amendment to the standard.

If you think we should have some other test case (additional to 
Modules/Reachability-Private), that's fine - would you like to propose one (or 
maybe add to an existing)?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128328

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


[clang-tools-extra] eb64dbd - [clangd] Fix flaky throttler test

2022-07-07 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2022-07-07T18:09:54+02:00
New Revision: eb64dbd6e0e617298579d32372fb92e595816d45

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

LOG: [clangd] Fix flaky throttler test

The production code doesn't depend on the relative destruction order of
the throttle request and the main request, but the test does.

Added: 


Modified: 
clang-tools-extra/clangd/TUScheduler.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/TUScheduler.cpp 
b/clang-tools-extra/clangd/TUScheduler.cpp
index a112b666e9ab..4c6c8c679be3 100644
--- a/clang-tools-extra/clangd/TUScheduler.cpp
+++ b/clang-tools-extra/clangd/TUScheduler.cpp
@@ -498,6 +498,8 @@ class PreambleThread {
 // Build the preamble and let the waiters know about it.
 build(std::move(*CurrentReq));
   }
+  // Releasing the throttle before destroying the request assists testing.
+  Throttle.reset();
   bool IsEmpty = false;
   {
 std::lock_guard Lock(Mutex);



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


[PATCH] D129300: [clang-offload-bundler][NFC] Library-ize ClangOffloadBundler (4/4)

2022-07-07 Thread Jacob Lambert via Phabricator via cfe-commits
lamb-j created this revision.
lamb-j added reviewers: kzhuravl, scott.linder, yaxunl.
Herald added a subscriber: mgorny.
Herald added a project: All.
lamb-j requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

Lifting the core functionalities of the clang-offload-bundler into a
user-facing library/API.

This NFC patch (4/4) moves the API files from
clang/tools/clang-offload-bundler into clang/lib/Driver and
clang/include/clang/Driver.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129300

Files:
  clang/include/clang/Driver/OffloadBundler.h
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/OffloadBundler.cpp
  clang/tools/clang-offload-bundler/CMakeLists.txt
  clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
  clang/tools/clang-offload-bundler/OffloadBundler.cpp
  clang/tools/clang-offload-bundler/OffloadBundler.h

Index: clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
===
--- clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
+++ clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
@@ -7,15 +7,14 @@
 //===--===//
 ///
 /// \file
-/// This file implements a clang-offload-bundler that bundles different
-/// files that relate with the same source code but different targets into a
-/// single one. Also the implements the opposite functionality, i.e. unbundle
-/// files previous created by this tool.
+/// This file implements a stand-alone clang-offload-bundler tool using the
+/// OffloadBundler API.
 ///
 //===--===//
 
 #include "clang/Basic/Cuda.h"
 #include "clang/Basic/Version.h"
+#include "clang/Driver/OffloadBundler.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
@@ -52,7 +51,6 @@
 #include 
 #include 
 #include 
-#include "OffloadBundler.h"
 
 using namespace llvm;
 using namespace llvm::object;
Index: clang/tools/clang-offload-bundler/CMakeLists.txt
===
--- clang/tools/clang-offload-bundler/CMakeLists.txt
+++ clang/tools/clang-offload-bundler/CMakeLists.txt
@@ -2,7 +2,6 @@
 
 add_clang_tool(clang-offload-bundler
   ClangOffloadBundler.cpp
-  OffloadBundler.cpp
 
   DEPENDS
   intrinsics_gen
@@ -10,6 +9,7 @@
 
 set(CLANG_OFFLOAD_BUNDLER_LIB_DEPS
   clangBasic
+  clangDriver
   )
 
 add_dependencies(clang clang-offload-bundler)
Index: clang/lib/Driver/OffloadBundler.cpp
===
--- clang/lib/Driver/OffloadBundler.cpp
+++ clang/lib/Driver/OffloadBundler.cpp
@@ -1,4 +1,4 @@
-//===-- clang-offload-bundler/ClangOffloadBundler.cpp -===//
+//===- OffloadBundler.cpp - File Bundling and Unbundling --===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -7,15 +7,16 @@
 //===--===//
 ///
 /// \file
-/// This file implements a clang-offload-bundler that bundles different
-/// files that relate with the same source code but different targets into a
-/// single one. Also the implements the opposite functionality, i.e. unbundle
-/// files previous created by this tool.
+/// This file implements an offload bundling API that bundles different files
+/// that relate with the same source code but different targets into a single
+/// one. Also the implements the opposite functionality, i.e. unbundle files
+/// previous created by this API.
 ///
 //===--===//
 
 #include "clang/Basic/Cuda.h"
 #include "clang/Basic/Version.h"
+#include "clang/Driver/OffloadBundler.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
@@ -53,8 +54,6 @@
 #include 
 #include 
 
-#include "OffloadBundler.h"
-
 using namespace llvm;
 using namespace llvm::object;
 
Index: clang/lib/Driver/CMakeLists.txt
===
--- clang/lib/Driver/CMakeLists.txt
+++ clang/lib/Driver/CMakeLists.txt
@@ -20,6 +20,7 @@
   DriverOptions.cpp
   Job.cpp
   Multilib.cpp
+  OffloadBundler.cpp
   OptionUtils.cpp
   Phases.cpp
   SanitizerArgs.cpp
Index: clang/include/clang/Driver/OffloadBundler.h
===
--- clang/include/clang/Driver/OffloadBundler.h
+++ clang/include/clang/Driver/OffloadBundler.h
@@ -1,4 +1,4 @@
-//===-- clang-offload-bundler/OffloadBundler.h ===//
+//=== -OffloadBundler.h - File Bundling and Unbundling --*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLV

[PATCH] D129298: Add denormal-fp-math attribute for f16

2022-07-07 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.

Missing ARM changes that demonstrate the use of the control?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129298

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


[PATCH] D129301: [clang-offload-bundler][NFC] Library-ize ClangOffloadBundler (1/4)

2022-07-07 Thread Jacob Lambert via Phabricator via cfe-commits
lamb-j created this revision.
lamb-j added reviewers: kzhuravl, scott.linder, yaxunl.
Herald added a subscriber: mgorny.
Herald added a reviewer: alexander-shaposhnikov.
Herald added a project: All.
lamb-j requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

Lifting the core functionalities of the clang-offload-bundler into a
user-facing library/API. This will allow online and JIT compilers to
bundle and unbundle files without spawning a new process.

This NFC patch (1/4) lifts the classes and functions used to
implement the clang-offload-bundler into a separate
OffloadBundler.cpp, and defines three top-level API functions in
OfflaodBundler.h

  BundleFiles()
  UnbundleFiles()
  UnbundleArchives()

In successive patches, we aim to:

1. Refactor global command-line option variables (cl::opt, cl::list, cl::bool, 
etc.) out of the API and into a Config class that can be passed as a local 
argument.
2. Refactor dependence on the bundler executable path into an optional parameter
3. Move OffloadBundler.cpp and OffloadBundler.h into clang/lib/Driver and 
clang/include/clang/Driver


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129301

Files:
  clang/tools/clang-offload-bundler/CMakeLists.txt
  clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
  clang/tools/clang-offload-bundler/OffloadBundler.cpp
  clang/tools/clang-offload-bundler/OffloadBundler.h

Index: clang/tools/clang-offload-bundler/OffloadBundler.h
===
--- /dev/null
+++ clang/tools/clang-offload-bundler/OffloadBundler.h
@@ -0,0 +1,45 @@
+//===-- clang-offload-bundler/OffloadBundler.h ===//
+//
+// 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 defines a clang-offload-bundler library that bundles different
+/// files that relate with the same source code but different targets into a
+/// single one. Also the implements the opposite functionality, i.e. unbundle
+/// files previous created by this tool.
+///
+//===--===//
+
+using namespace llvm;
+using namespace llvm::object;
+
+Error BundleFiles();
+Error UnbundleFiles();
+Error UnbundleArchive();
+
+/// Obtain the offload kind, real machine triple, and an optional GPUArch
+/// out of the target information specified by the user.
+/// Bundle Entry ID (or, Offload Target String) has following components:
+///  * Offload Kind - Host, OpenMP, or HIP
+///  * Triple - Standard LLVM Triple
+///  * GPUArch (Optional) - Processor name, followed by set of ON/OFF features
+struct OffloadTargetInfo {
+  StringRef OffloadKind;
+  llvm::Triple Triple;
+  StringRef GPUArch;
+
+  OffloadTargetInfo(const StringRef Target);
+  bool hasHostKind() const;
+  bool isOffloadKindValid() const;
+  bool isOffloadKindCompatible(const StringRef TargetOffloadKind) const;
+  bool isTripleValid() const;
+  bool operator==(const OffloadTargetInfo &Target) const;
+  std::string str();
+};
+
+// List bundle IDs. Return true if an error was found.
+Error ListBundleIDsInFile(StringRef InputFileName);
Index: clang/tools/clang-offload-bundler/OffloadBundler.cpp
===
--- clang/tools/clang-offload-bundler/OffloadBundler.cpp
+++ clang/tools/clang-offload-bundler/OffloadBundler.cpp
@@ -53,164 +53,84 @@
 #include 
 #include 
 
+#include "OffloadBundler.h"
+
 using namespace llvm;
 using namespace llvm::object;
 
-static cl::opt Help("h", cl::desc("Alias for -help"), cl::Hidden);
-
-// Mark all our options with this category, everything else (except for -version
-// and -help) will be hidden.
-static cl::OptionCategory
-ClangOffloadBundlerCategory("clang-offload-bundler options");
-static cl::list
-InputFileNames("input",
-   cl::desc("Input file."
-" Can be specified multiple times "
-"for multiple input files."),
-   cl::cat(ClangOffloadBundlerCategory));
-static cl::list
-InputFileNamesDeprecatedOpt("inputs", cl::CommaSeparated,
-cl::desc("[,...] (deprecated)"),
-cl::cat(ClangOffloadBundlerCategory));
-static cl::list
-OutputFileNames("output",
-cl::desc("Output file."
- " Can be specified multiple times "
- "for multiple output files."),
-cl::cat(ClangOffloadBundlerCategory));
-static cl::list
-OutputFileNamesDeprecatedOpt("outputs", cl::CommaSeparated,
-  

[PATCH] D129100: [clangd] Support external throttler for preamble builds

2022-07-07 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

In D129100#3634548 , @vitalybuka 
wrote:

> This looks flaky https://lab.llvm.org/buildbot/#/builders/5/builds/25929

Sorry about that, I believe this is fixed in 
eb64dbd6e0e617298579d32372fb92e595816d45 
.
(The flake symptoms I was able to see locally are different, but I would guess 
the same cause)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129100

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


[PATCH] D129301: [clang-offload-bundler][NFC] Library-ize ClangOffloadBundler (1/4)

2022-07-07 Thread Jacob Lambert via Phabricator via cfe-commits
lamb-j updated this revision to Diff 442945.
lamb-j added a comment.

Adding clang-format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129301

Files:
  clang/tools/clang-offload-bundler/CMakeLists.txt
  clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
  clang/tools/clang-offload-bundler/OffloadBundler.cpp
  clang/tools/clang-offload-bundler/OffloadBundler.h

Index: clang/tools/clang-offload-bundler/OffloadBundler.h
===
--- /dev/null
+++ clang/tools/clang-offload-bundler/OffloadBundler.h
@@ -0,0 +1,45 @@
+//===-- clang-offload-bundler/OffloadBundler.h ===//
+//
+// 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 defines a clang-offload-bundler library that bundles different
+/// files that relate with the same source code but different targets into a
+/// single one. Also the implements the opposite functionality, i.e. unbundle
+/// files previous created by this tool.
+///
+//===--===//
+
+using namespace llvm;
+using namespace llvm::object;
+
+Error BundleFiles();
+Error UnbundleFiles();
+Error UnbundleArchive();
+
+/// Obtain the offload kind, real machine triple, and an optional GPUArch
+/// out of the target information specified by the user.
+/// Bundle Entry ID (or, Offload Target String) has following components:
+///  * Offload Kind - Host, OpenMP, or HIP
+///  * Triple - Standard LLVM Triple
+///  * GPUArch (Optional) - Processor name, followed by set of ON/OFF features
+struct OffloadTargetInfo {
+  StringRef OffloadKind;
+  llvm::Triple Triple;
+  StringRef GPUArch;
+
+  OffloadTargetInfo(const StringRef Target);
+  bool hasHostKind() const;
+  bool isOffloadKindValid() const;
+  bool isOffloadKindCompatible(const StringRef TargetOffloadKind) const;
+  bool isTripleValid() const;
+  bool operator==(const OffloadTargetInfo &Target) const;
+  std::string str();
+};
+
+// List bundle IDs. Return true if an error was found.
+Error ListBundleIDsInFile(StringRef InputFileName);
Index: clang/tools/clang-offload-bundler/OffloadBundler.cpp
===
--- clang/tools/clang-offload-bundler/OffloadBundler.cpp
+++ clang/tools/clang-offload-bundler/OffloadBundler.cpp
@@ -53,164 +53,84 @@
 #include 
 #include 
 
+#include "OffloadBundler.h"
+
 using namespace llvm;
 using namespace llvm::object;
 
-static cl::opt Help("h", cl::desc("Alias for -help"), cl::Hidden);
-
-// Mark all our options with this category, everything else (except for -version
-// and -help) will be hidden.
-static cl::OptionCategory
-ClangOffloadBundlerCategory("clang-offload-bundler options");
-static cl::list
-InputFileNames("input",
-   cl::desc("Input file."
-" Can be specified multiple times "
-"for multiple input files."),
-   cl::cat(ClangOffloadBundlerCategory));
-static cl::list
-InputFileNamesDeprecatedOpt("inputs", cl::CommaSeparated,
-cl::desc("[,...] (deprecated)"),
-cl::cat(ClangOffloadBundlerCategory));
-static cl::list
-OutputFileNames("output",
-cl::desc("Output file."
- " Can be specified multiple times "
- "for multiple output files."),
-cl::cat(ClangOffloadBundlerCategory));
-static cl::list
-OutputFileNamesDeprecatedOpt("outputs", cl::CommaSeparated,
- cl::desc("[,...] (deprecated)"),
- cl::cat(ClangOffloadBundlerCategory));
-static cl::list
-TargetNames("targets", cl::CommaSeparated,
-cl::desc("[-,...]"),
-cl::cat(ClangOffloadBundlerCategory));
-static cl::opt
-FilesType("type", cl::Required,
-  cl::desc("Type of the files to be bundled/unbundled.\n"
-   "Current supported types are:\n"
-   "  i   - cpp-output\n"
-   "  ii  - c++-cpp-output\n"
-   "  cui - cuda/hip-output\n"
-   "  d   - dependency\n"
-   "  ll  - llvm\n"
-   "  bc  - llvm-bc\n"
-   "  s   - assembler\n"
-   "  o   - object\n"
-   "  a   - archive of objects\n"
-   "  gch - precompiled-header\n"
-   "  ast - clang AST file"),
-  cl::cat(ClangOffloadBundle

[PATCH] D129303: [clang-offload-bundler] Library-ize ClangOffloadBundler (2/4)

2022-07-07 Thread Jacob Lambert via Phabricator via cfe-commits
lamb-j created this revision.
lamb-j added reviewers: kzhuravl, scott.linder, yaxunl.
Herald added a reviewer: alexander-shaposhnikov.
Herald added a project: All.
lamb-j requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Lifting the core functionalities of the clang-offload-bundler into a
user-facing library/API.

This patch (2/4) introduces a Config class that locally stores the
previously global cl::opt options and arrays. This localization
will allow users to call the APIs in a multi-threaded context. This
patch also introduces an OffloadBundler class to encapsulate the
top-level API functions.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129303

Files:
  clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
  clang/tools/clang-offload-bundler/OffloadBundler.cpp
  clang/tools/clang-offload-bundler/OffloadBundler.h

Index: clang/tools/clang-offload-bundler/OffloadBundler.h
===
--- clang/tools/clang-offload-bundler/OffloadBundler.h
+++ clang/tools/clang-offload-bundler/OffloadBundler.h
@@ -17,9 +17,37 @@
 using namespace llvm;
 using namespace llvm::object;
 
-Error BundleFiles();
-Error UnbundleFiles();
-Error UnbundleArchive();
+class Config {
+public:
+  bool AllowNoHost = false;
+  bool AllowMissingBundles = false;
+  bool CheckInputArchive = false;
+  bool PrintExternalCommands = false;
+  bool HipOpenmpCompatible = false;
+
+  unsigned BundleAlignment = 1;
+  unsigned HostInputIndex = ~0u;
+
+  std::string FilesType;
+  std::string BundlerExecutable;
+
+  // TODO: Convert these to llvm::SmallVector
+  std::vector TargetNames;
+  std::vector InputFileNames;
+  std::vector OutputFileNames;
+};
+
+class OffloadBundler {
+public:
+  Config *BundlerConfig;
+
+  // TODO: Add error checking from ClangOffloadBundler.cpp
+  OffloadBundler(Config *BC) : BundlerConfig(BC) {}
+
+  Error BundleFiles();
+  Error UnbundleFiles();
+  Error UnbundleArchive();
+};
 
 /// Obtain the offload kind, real machine triple, and an optional GPUArch
 /// out of the target information specified by the user.
@@ -31,8 +59,9 @@
   StringRef OffloadKind;
   llvm::Triple Triple;
   StringRef GPUArch;
+  Config *BundlerConfig;
 
-  OffloadTargetInfo(const StringRef Target);
+  OffloadTargetInfo(const StringRef Target, Config *BC);
   bool hasHostKind() const;
   bool isOffloadKindValid() const;
   bool isOffloadKindCompatible(const StringRef TargetOffloadKind) const;
@@ -42,4 +71,4 @@
 };
 
 // List bundle IDs. Return true if an error was found.
-Error ListBundleIDsInFile(StringRef InputFileName);
+Error ListBundleIDsInFile(StringRef InputFileName, Config *BundlerConfig);
Index: clang/tools/clang-offload-bundler/OffloadBundler.cpp
===
--- clang/tools/clang-offload-bundler/OffloadBundler.cpp
+++ clang/tools/clang-offload-bundler/OffloadBundler.cpp
@@ -58,28 +58,12 @@
 using namespace llvm;
 using namespace llvm::object;
 
-extern cl::list InputFileNames;
-extern cl::list OutputFileNames;
-extern cl::list TargetNames;
-extern cl::opt FilesType;
-extern cl::opt PrintExternalCommands;
-extern cl::opt AllowMissingBundles;
-extern cl::opt BundleAlignment;
-extern cl::opt HipOpenmpCompatible;
-
 /// Magic string that marks the existence of offloading data.
 #define OFFLOAD_BUNDLER_MAGIC_STR "__CLANG_OFFLOAD_BUNDLE__"
 
-/// The index of the host input in the list of inputs.
-extern unsigned HostInputIndex;
-
-/// Whether not having host target is allowed.
-extern bool AllowNoHost;
-
-/// Path to the current binary.
-extern std::string BundlerExecutable;
-
-OffloadTargetInfo::OffloadTargetInfo(const StringRef Target) {
+OffloadTargetInfo::OffloadTargetInfo(const StringRef Target, Config *BC) {
+  // TODO: Add error checking from ClangOffloadBundler.cpp
+  BundlerConfig = BC;
   auto TargetFeatures = Target.split(':');
   auto TripleOrGPU = TargetFeatures.first.rsplit('-');
 
@@ -107,7 +91,7 @@
 bool OffloadTargetInfo::isOffloadKindCompatible(const StringRef TargetOffloadKind) const {
   if (OffloadKind == TargetOffloadKind)
 return true;
-  if (HipOpenmpCompatible) {
+  if (BundlerConfig->HipOpenmpCompatible) {
 bool HIPCompatibleWithOpenMP =
   OffloadKind.startswith_insensitive("hip") &&
   TargetOffloadKind == "openmp";
@@ -306,8 +290,12 @@
   /// Current bundle target to be written.
   std::string CurWriteBundleTarget;
 
+  /// Configuration options and arrays for this bundler job
+  Config *BundlerConfig;
+
 public:
-  BinaryFileHandler() {}
+  // TODO: Add error checking from ClangOffloadBundler.cpp
+  BinaryFileHandler(Config *BC) : BundlerConfig(BC) {}
 
   ~BinaryFileHandler() final {}
 
@@ -407,7 +395,7 @@
 HeaderSize += sizeof(OFFLOAD_BUNDLER_MAGIC_STR) - 1;
 HeaderSize += 8; // Number of Bundles
 
-for (auto &T : TargetNames) {
+for (auto &T : BundlerConfig->TargetNames) {
   HeaderSize 

[clang] ed801ad - [Clang] Use metadata to make identifying embedded objects easier

2022-07-07 Thread Joseph Huber via cfe-commits

Author: Joseph Huber
Date: 2022-07-07T12:20:25-04:00
New Revision: ed801ad5e5fef76c4303d04fd8de21662b428bee

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

LOG: [Clang] Use metadata to make identifying embedded objects easier

Currently we use the `embedBufferInModule` function to store binary
strings containing device offloading data inside the host object to
create a fatbinary. In the case of LTO, we need to extract this object
from the LLVM-IR. This patch adds a metadata node for the embedded
objects containing the embedded pointers and the sections they were
stored at. This should create a cleaner interface for identifying these
values.

In the future it may be worthwhile to also encode an `ID` in the
metadata corresponding to the object's special section type if relevant.
This would allow us to extract the data from an object file and LLVM-IR
using the same ID.

Reviewed By: jdoerfert

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

Added: 


Modified: 
clang/test/Frontend/embed-object.c
clang/test/Frontend/embed-object.ll
clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
llvm/docs/LangRef.rst
llvm/include/llvm/Transforms/Utils/ModuleUtils.h
llvm/lib/Transforms/Utils/ModuleUtils.cpp

Removed: 




diff  --git a/clang/test/Frontend/embed-object.c 
b/clang/test/Frontend/embed-object.c
index ceb3378a60ab..364cb8aad193 100644
--- a/clang/test/Frontend/embed-object.c
+++ b/clang/test/Frontend/embed-object.c
@@ -4,3 +4,6 @@
 // CHECK: @llvm.compiler.used = appending global [1 x ptr] [ptr @[[OBJECT]]], 
section "llvm.metadata"
 
 void foo(void) {}
+
+// CHECK: !llvm.embedded.objects = !{![[METADATA:[0-9]+]]}
+// CHECK: ![[METADATA]] = !{ptr @[[OBJECT]], !".llvm.offloading"}

diff  --git a/clang/test/Frontend/embed-object.ll 
b/clang/test/Frontend/embed-object.ll
index 177ecdf7f8a3..bcb56fd55c73 100644
--- a/clang/test/Frontend/embed-object.ll
+++ b/clang/test/Frontend/embed-object.ll
@@ -13,3 +13,7 @@
 define i32 @foo() {
   ret i32 0
 }
+
+; CHECK: !llvm.embedded.objects = !{![[METADATA_1:[0-9]+]], 
![[METADATA_2:[0-9]+]]}
+; CHECK: ![[METADATA_1]] = !{ptr @[[OBJECT_1]], !".llvm.offloading"}
+; CHECK: ![[METADATA_2]] = !{ptr @[[OBJECT_2]], !".llvm.offloading"}

diff  --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp 
b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index 3e935bcbd30a..e7214ebfde37 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -366,12 +366,26 @@ Error extractFromBitcode(std::unique_ptr 
Buffer,
 return createStringError(inconvertibleErrorCode(),
  "Failed to create module");
 
-  // Extract offloading data from globals with the `.llvm.offloading` section.
-  for (GlobalVariable &GV : M->globals()) {
-if (!GV.hasSection() || !GV.getSection().equals(OFFLOAD_SECTION_MAGIC_STR))
+  // Extract offloading data from globals referenced by the
+  // `llvm.embedded.object` metadata with the `.llvm.offloading` section.
+  auto MD = M->getNamedMetadata("llvm.embedded.object");
+  if (!MD)
+return Error::success();
+
+  for (const MDNode *Op : MD->operands()) {
+if (Op->getNumOperands() < 2)
+  continue;
+
+MDString *SectionID = dyn_cast(Op->getOperand(1));
+if (!SectionID || SectionID->getString() != OFFLOAD_SECTION_MAGIC_STR)
+  continue;
+
+GlobalVariable *GV =
+mdconst::dyn_extract_or_null(Op->getOperand(0));
+if (!GV)
   continue;
 
-auto *CDS = dyn_cast(GV.getInitializer());
+auto *CDS = dyn_cast(GV->getInitializer());
 if (!CDS)
   continue;
 

diff  --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 889eca2f438b..e74aaa8d77cf 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -7429,6 +7429,19 @@ Some optimisations are only when the entire LTO unit is 
present in the current
 module. This is represented by the ``LTOPostLink`` module flags metadata, which
 will be created with a value of ``1`` when LTO linking occurs.
 
+Embedded Objects Names Metadata
+===
+
+Offloading compilations need to embed device code into the host section table 
to
+create a fat binary. This metadata node references each global that will be
+embedded in the module. The primary use for this is to make referencing these
+globals more efficient in the IR. The metadata references nodes containing
+pointers to the global to be embedded followed by the section name it will be
+stored at::
+
+!llvm.embedded.objects = !{!0}
+!0 = !{ptr @object, !".section"}
+
 Automatic Linker Flags Named Metadata
 =
 

diff  --git a/llvm/include/llvm/Transforms/Utils/ModuleUtils.h 
b/

[clang] 41fba3c - [Metadata] Add 'exclude' metadata to add the exclude flags on globals

2022-07-07 Thread Joseph Huber via cfe-commits

Author: Joseph Huber
Date: 2022-07-07T12:20:40-04:00
New Revision: 41fba3c107a5bc99065f3bf8b9f5b9d52eab2d98

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

LOG: [Metadata] Add 'exclude' metadata to add the exclude flags on globals

This patchs adds a new metadata kind `exclude` which implies that the
global variable should be given the necessary flags during code
generation to not be included in the final executable. This is done
using the ``SHF_EXCLUDE`` flag on ELF for example. This should make it
easier to specify this flag on a variable without needing to explicitly
check the section name in the target backend.

Depends on D129053 D129052

Reviewed By: jdoerfert

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

Added: 
llvm/test/CodeGen/X86/coff-exclude.ll
llvm/test/CodeGen/X86/elf-exclude.ll

Modified: 
clang/test/Frontend/embed-object.c
clang/test/Frontend/embed-object.ll
llvm/docs/LangRef.rst
llvm/include/llvm/IR/FixedMetadataKinds.def
llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
llvm/lib/Target/TargetLoweringObjectFile.cpp
llvm/lib/Transforms/Utils/ModuleUtils.cpp
llvm/test/CodeGen/X86/offload_sections.ll

Removed: 




diff  --git a/clang/test/Frontend/embed-object.c 
b/clang/test/Frontend/embed-object.c
index 364cb8aad193..febac4272ff8 100644
--- a/clang/test/Frontend/embed-object.c
+++ b/clang/test/Frontend/embed-object.c
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -x c -triple x86_64-unknown-linux-gnu -emit-llvm 
-fembed-offload-object=%S/Inputs/empty.h -o - %s | FileCheck %s
 
-// CHECK: @[[OBJECT:.+]] = private constant [0 x i8] zeroinitializer, section 
".llvm.offloading", align 8
+// CHECK: @[[OBJECT:.+]] = private constant [0 x i8] zeroinitializer, section 
".llvm.offloading", align 8, !exclude
 // CHECK: @llvm.compiler.used = appending global [1 x ptr] [ptr @[[OBJECT]]], 
section "llvm.metadata"
 
 void foo(void) {}

diff  --git a/clang/test/Frontend/embed-object.ll 
b/clang/test/Frontend/embed-object.ll
index bcb56fd55c73..9165d903b975 100644
--- a/clang/test/Frontend/embed-object.ll
+++ b/clang/test/Frontend/embed-object.ll
@@ -3,8 +3,8 @@
 ; RUN:-fembed-offload-object=%S/Inputs/empty.h -x ir %s -o - \
 ; RUN:| FileCheck %s -check-prefix=CHECK
 
-; CHECK: @[[OBJECT_1:.+]] = private constant [0 x i8] zeroinitializer, section 
".llvm.offloading", align 8
-; CHECK: @[[OBJECT_2:.+]] = private constant [0 x i8] zeroinitializer, section 
".llvm.offloading", align 8
+; CHECK: @[[OBJECT_1:.+]] = private constant [0 x i8] zeroinitializer, section 
".llvm.offloading", align 8, !exclude
+; CHECK: @[[OBJECT_2:.+]] = private constant [0 x i8] zeroinitializer, section 
".llvm.offloading", align 8, !exclude
 ; CHECK: @llvm.compiler.used = appending global [3 x ptr] [ptr @x, ptr 
@[[OBJECT_1]], ptr @[[OBJECT_2]]], section "llvm.metadata"
 
 @x = private constant i8 1

diff  --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index e74aaa8d77cf..a333c6f7a3da 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -6396,6 +6396,24 @@ final ``i1 true``).
 !1 = !{i64 2, i64 -1, i64 -1, i1 true}
 !0 = !{!1}
 
+'``exclude``' Metadata
+^^
+
+``exclude`` metadata may be attached to a global variable to signify that its
+section should not be included in the final executable or shared library. This
+option is only valid for global variables with an explicit section targeting 
ELF
+or COFF. This is done using the ``SHF_EXCLUDE`` flag on ELF targets and the
+``IMAGE_SCN_LNK_REMOVE`` and ``IMAGE_SCN_MEM_DISCARDABLE`` flags for COFF
+targets. Additionally, this metadata is only used as a flag, so the associated
+node must be empty. The explicit section should not conflict with any other
+sections that the user does not want removed after linking.
+
+.. code-block:: text
+
+  @object = private constant [1 x i8] c"\00", section ".foo" !exclude !0
+
+  ...
+  !0 = !{}
 
 '``unpredictable``' Metadata
 

diff  --git a/llvm/include/llvm/IR/FixedMetadataKinds.def 
b/llvm/include/llvm/IR/FixedMetadataKinds.def
index 7c32c5d13760..1d24f527df7b 100644
--- a/llvm/include/llvm/IR/FixedMetadataKinds.def
+++ b/llvm/include/llvm/IR/FixedMetadataKinds.def
@@ -44,3 +44,4 @@ LLVM_FIXED_MD_KIND(MD_noundef, "noundef", 29)
 LLVM_FIXED_MD_KIND(MD_annotation, "annotation", 30)
 LLVM_FIXED_MD_KIND(MD_nosanitize, "nosanitize", 31)
 LLVM_FIXED_MD_KIND(MD_func_sanitize, "func_sanitize", 32)
+LLVM_FIXED_MD_KIND(MD_exclude, "exclude", 33)

diff  --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp 
b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index dbac47495ea2..2badbe34ae6a 100644
--- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cp

[PATCH] D129033: [Clang] Use metadata to make identifying embedded objects easier

2022-07-07 Thread Joseph Huber 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 rGed801ad5e5fe: [Clang] Use metadata to make identifying 
embedded objects easier (authored by jhuber6).

Changed prior to commit:
  https://reviews.llvm.org/D129033?vs=442926&id=442950#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129033

Files:
  clang/test/Frontend/embed-object.c
  clang/test/Frontend/embed-object.ll
  clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
  llvm/docs/LangRef.rst
  llvm/include/llvm/Transforms/Utils/ModuleUtils.h
  llvm/lib/Transforms/Utils/ModuleUtils.cpp

Index: llvm/lib/Transforms/Utils/ModuleUtils.cpp
===
--- llvm/lib/Transforms/Utils/ModuleUtils.cpp
+++ llvm/lib/Transforms/Utils/ModuleUtils.cpp
@@ -275,5 +275,12 @@
   GV->setSection(SectionName);
   GV->setAlignment(Alignment);
 
+  LLVMContext &Ctx = M.getContext();
+  NamedMDNode *MD = M.getOrInsertNamedMetadata("llvm.embedded.objects");
+  Metadata *MDVals[] = {ConstantAsMetadata::get(GV),
+MDString::get(Ctx, SectionName)};
+
+  MD->addOperand(llvm::MDNode::get(Ctx, MDVals));
+
   appendToCompilerUsed(M, GV);
 }
Index: llvm/include/llvm/Transforms/Utils/ModuleUtils.h
===
--- llvm/include/llvm/Transforms/Utils/ModuleUtils.h
+++ llvm/include/llvm/Transforms/Utils/ModuleUtils.h
@@ -109,7 +109,8 @@
 std::string getUniqueModuleId(Module *M);
 
 /// Embed the memory buffer \p Buf into the module \p M as a global using the
-/// specified section name.
+/// specified section name. Also provide a metadata entry to identify it in the
+/// module using the same section name.
 void embedBufferInModule(Module &M, MemoryBufferRef Buf, StringRef SectionName,
  Align Alignment = Align(1));
 
Index: llvm/docs/LangRef.rst
===
--- llvm/docs/LangRef.rst
+++ llvm/docs/LangRef.rst
@@ -7429,6 +7429,19 @@
 module. This is represented by the ``LTOPostLink`` module flags metadata, which
 will be created with a value of ``1`` when LTO linking occurs.
 
+Embedded Objects Names Metadata
+===
+
+Offloading compilations need to embed device code into the host section table to
+create a fat binary. This metadata node references each global that will be
+embedded in the module. The primary use for this is to make referencing these
+globals more efficient in the IR. The metadata references nodes containing
+pointers to the global to be embedded followed by the section name it will be
+stored at::
+
+!llvm.embedded.objects = !{!0}
+!0 = !{ptr @object, !".section"}
+
 Automatic Linker Flags Named Metadata
 =
 
Index: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
===
--- clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -366,12 +366,26 @@
 return createStringError(inconvertibleErrorCode(),
  "Failed to create module");
 
-  // Extract offloading data from globals with the `.llvm.offloading` section.
-  for (GlobalVariable &GV : M->globals()) {
-if (!GV.hasSection() || !GV.getSection().equals(OFFLOAD_SECTION_MAGIC_STR))
+  // Extract offloading data from globals referenced by the
+  // `llvm.embedded.object` metadata with the `.llvm.offloading` section.
+  auto MD = M->getNamedMetadata("llvm.embedded.object");
+  if (!MD)
+return Error::success();
+
+  for (const MDNode *Op : MD->operands()) {
+if (Op->getNumOperands() < 2)
+  continue;
+
+MDString *SectionID = dyn_cast(Op->getOperand(1));
+if (!SectionID || SectionID->getString() != OFFLOAD_SECTION_MAGIC_STR)
+  continue;
+
+GlobalVariable *GV =
+mdconst::dyn_extract_or_null(Op->getOperand(0));
+if (!GV)
   continue;
 
-auto *CDS = dyn_cast(GV.getInitializer());
+auto *CDS = dyn_cast(GV->getInitializer());
 if (!CDS)
   continue;
 
Index: clang/test/Frontend/embed-object.ll
===
--- clang/test/Frontend/embed-object.ll
+++ clang/test/Frontend/embed-object.ll
@@ -13,3 +13,7 @@
 define i32 @foo() {
   ret i32 0
 }
+
+; CHECK: !llvm.embedded.objects = !{![[METADATA_1:[0-9]+]], ![[METADATA_2:[0-9]+]]}
+; CHECK: ![[METADATA_1]] = !{ptr @[[OBJECT_1]], !".llvm.offloading"}
+; CHECK: ![[METADATA_2]] = !{ptr @[[OBJECT_2]], !".llvm.offloading"}
Index: clang/test/Frontend/embed-object.c
===
--- clang/test/Frontend/embed-object.c
+++ clang/test/Frontend/embed-object.c
@@ -4,3 +4,6 @@
 // CHECK: @llvm.compiler.us

[PATCH] D129151: [Metadata] Add 'exclude' metadata to add the exclude flags on globals

2022-07-07 Thread Joseph Huber 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 rG41fba3c107a5: [Metadata] Add 'exclude' metadata to 
add the exclude flags on globals (authored by jhuber6).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129151

Files:
  clang/test/Frontend/embed-object.c
  clang/test/Frontend/embed-object.ll
  llvm/docs/LangRef.rst
  llvm/include/llvm/IR/FixedMetadataKinds.def
  llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
  llvm/lib/Target/TargetLoweringObjectFile.cpp
  llvm/lib/Transforms/Utils/ModuleUtils.cpp
  llvm/test/CodeGen/X86/coff-exclude.ll
  llvm/test/CodeGen/X86/elf-exclude.ll
  llvm/test/CodeGen/X86/offload_sections.ll

Index: llvm/test/CodeGen/X86/offload_sections.ll
===
--- llvm/test/CodeGen/X86/offload_sections.ll
+++ llvm/test/CodeGen/X86/offload_sections.ll
@@ -1,8 +1,10 @@
 ; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu | FileCheck %s --check-prefix=CHECK-ELF
 ; RUN: llc < %s -mtriple=x86_64-win32-gnu | FileCheck %s --check-prefix=CHECK-COFF
 
-@llvm.embedded.object = private constant [1 x i8] c"\00", section ".llvm.offloading"
+@llvm.embedded.object = private constant [1 x i8] c"\00", section ".llvm.offloading", align 8, !exclude !0
 @llvm.compiler.used = appending global [1 x ptr] [ptr @llvm.embedded.object], section "llvm.metadata"
 
+!0 = !{}
+
 ; CHECK-ELF: .section	.llvm.offloading,"e",@llvm_offloading
-; CHECK-COFF: .section	.llvm.offloading,"dr"
+; CHECK-COFF: .section	.llvm.offloading,"ynD"
Index: llvm/test/CodeGen/X86/elf-exclude.ll
===
--- /dev/null
+++ llvm/test/CodeGen/X86/elf-exclude.ll
@@ -0,0 +1,18 @@
+; RUN: llc -mtriple x86_64-pc-linux-gnu < %s | FileCheck %s
+
+@a = global i32 1
+@b = global i32 1, !exclude !0
+@c = global i32 1, section "aaa"
+; CHECK-DAG: .type	c,@object
+; CHECK-DAG: 	.section	aaa,"aw",@progbits
+@d = global i32 1, section "bbb", !exclude !0
+; CHECK-DAG: .type	d,@object
+; CHECK-DAG: 	.section	bbb,"e",@progbits
+@e = global i32 1, section "bbb", !exclude !0
+; CHECK-DAG: .type	e,@object
+@f = global i32 1, section "ccc", !exclude !0
+@g = global i32 1, section "ccc"
+; CHECK-DAG:	.type	f,@object
+; CHECK-DAG:	.section	ccc,"e",@progbits
+
+!0 = !{}
Index: llvm/test/CodeGen/X86/coff-exclude.ll
===
--- /dev/null
+++ llvm/test/CodeGen/X86/coff-exclude.ll
@@ -0,0 +1,18 @@
+; RUN: llc -mtriple x86_64-win32-gnu < %s | FileCheck %s
+
+@a = global i32 1
+@b = global i32 1, !exclude !0
+@c = global i32 1, section "aaa"
+; CHECK-DAG: c
+; CHECK-DAG: 	.section	aaa,"dw"
+@d = global i32 1, section "bbb", !exclude !0
+; CHECK-DAG: d
+; CHECK-DAG: 	.section	bbb,"ynD"
+@e = global i32 1, section "bbb", !exclude !0
+; CHECK-DAG: e
+@f = global i32 1, section "ccc", !exclude !0
+@g = global i32 1, section "ccc"
+; CHECK-DAG: f
+; CHECK-DAG:	.section	ccc,"ynD"
+
+!0 = !{}
Index: llvm/lib/Transforms/Utils/ModuleUtils.cpp
===
--- llvm/lib/Transforms/Utils/ModuleUtils.cpp
+++ llvm/lib/Transforms/Utils/ModuleUtils.cpp
@@ -281,6 +281,7 @@
 MDString::get(Ctx, SectionName)};
 
   MD->addOperand(llvm::MDNode::get(Ctx, MDVals));
+  GV->setMetadata(LLVMContext::MD_exclude, llvm::MDNode::get(Ctx, {}));
 
   appendToCompilerUsed(M, GV);
 }
Index: llvm/lib/Target/TargetLoweringObjectFile.cpp
===
--- llvm/lib/Target/TargetLoweringObjectFile.cpp
+++ llvm/lib/Target/TargetLoweringObjectFile.cpp
@@ -240,6 +240,13 @@
 return SectionKind::getBSS();
   }
 
+  // Global variables with '!exclude' should get the exclude section kind if
+  // they have an explicit section and no other metadata.
+  if (GVar->hasSection())
+if (MDNode *MD = GVar->getMetadata(LLVMContext::MD_exclude))
+  if (!MD->getNumOperands())
+return SectionKind::getExclude();
+
   // If the global is marked constant, we can put it into a mergable section,
   // a mergable string section, or general .data if it contains relocations.
   if (GVar->isConstant()) {
Index: llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
===
--- llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -449,9 +449,6 @@
   Name == ".llvmbc" || Name == ".llvmcmd")
 return SectionKind::getMetadata();
 
-  if (Name == ".llvm.offloading")
-return SectionKind::getExclude();
-
   if (Name.empty() || Name[0] != '.') return K;
 
   // Default implementation based on some magic section names.
Index: llvm/include/llvm/IR/FixedMetadataKinds.def
===

[PATCH] D129304: [clang-offload-bundler] Library-ize ClangOffloadBundler (3/4)

2022-07-07 Thread Jacob Lambert via Phabricator via cfe-commits
lamb-j created this revision.
lamb-j added reviewers: kzhuravl, scott.linder, yaxunl.
Herald added a reviewer: alexander-shaposhnikov.
Herald added a project: All.
lamb-j requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Lifting the core functionalities of the clang-offload-bundler into a
user-facing library/API.

This patch (3/4) lifts the BundlerExecutable variable, which is
specific to the clang-offload-bundler tool, from the API, and
replaces its use with an ObjcopyPath variable. This variable
must be set in order to internally call llvm-objcopy.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129304

Files:
  clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
  clang/tools/clang-offload-bundler/OffloadBundler.cpp
  clang/tools/clang-offload-bundler/OffloadBundler.h


Index: clang/tools/clang-offload-bundler/OffloadBundler.h
===
--- clang/tools/clang-offload-bundler/OffloadBundler.h
+++ clang/tools/clang-offload-bundler/OffloadBundler.h
@@ -29,7 +29,7 @@
   unsigned HostInputIndex = ~0u;
 
   std::string FilesType;
-  std::string BundlerExecutable;
+  std::string ObjcopyPath;
 
   // TODO: Convert these to llvm::SmallVector
   std::vector TargetNames;
Index: clang/tools/clang-offload-bundler/OffloadBundler.cpp
===
--- clang/tools/clang-offload-bundler/OffloadBundler.cpp
+++ clang/tools/clang-offload-bundler/OffloadBundler.cpp
@@ -587,15 +587,8 @@
 // link editor to remove them from linker inputs when linking executable or
 // shared library.
 
-// Find llvm-objcopy in order to create the bundle binary.
-ErrorOr Objcopy = sys::findProgramByName(
-"llvm-objcopy",
-   sys::path::parent_path(BundlerConfig->BundlerExecutable));
-if (!Objcopy)
-  Objcopy = sys::findProgramByName("llvm-objcopy");
-if (!Objcopy)
-  return createStringError(Objcopy.getError(),
-   "unable to find 'llvm-objcopy' in path");
+assert(BundlerConfig->ObjcopyPath != "" &&
+   "llvm-objcopy path not specified");
 
 // We write to the output file directly. So, we close it and use the name
 // to pass down to llvm-objcopy.
@@ -636,7 +629,7 @@
   BundlerConfig->InputFileNames[BundlerConfig->HostInputIndex]);
 ObjcopyArgs.push_back(BundlerConfig->OutputFileNames.front());
 
-if (Error Err = executeObjcopy(*Objcopy, ObjcopyArgs))
+if (Error Err = executeObjcopy(BundlerConfig->ObjcopyPath, ObjcopyArgs))
   return Err;
 
 return Error::success();
Index: clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
===
--- clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
+++ clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
@@ -182,6 +182,16 @@
 BundlerExecutable =
   sys::fs::getMainExecutable(argv[0], &BundlerExecutable);
 
+  // Find llvm-objcopy in order to create the bundle binary.
+  ErrorOr Objcopy = sys::findProgramByName(
+"llvm-objcopy",
+sys::path::parent_path(BundlerExecutable));
+  if (!Objcopy)
+Objcopy = sys::findProgramByName("llvm-objcopy");
+  if (!Objcopy)
+reportError(createStringError(Objcopy.getError(),
+ "unable to find 'llvm-objcopy' in path"));
+
   if (InputFileNames.getNumOccurrences() != 0 &&
   InputFileNamesDeprecatedOpt.getNumOccurrences() != 0) {
 reportError(createStringError(
@@ -233,7 +243,7 @@
 
 Config BundlerPrint;
 BundlerPrint.PrintExternalCommands = PrintExternalCommands;
-BundlerPrint.BundlerExecutable = BundlerExecutable;
+BundlerPrint.ObjcopyPath = *Objcopy;
 doWork([&]() { return ListBundleIDsInFile(InputFileNames.front(),
  &BundlerPrint); });
 return 0;
@@ -294,7 +304,7 @@
 
 Config BundlerOpenmp;
 BundlerOpenmp.HipOpenmpCompatible = HipOpenmpCompatible;
-BundlerOpenmp.BundlerExecutable = BundlerExecutable;
+BundlerOpenmp.ObjcopyPath = *Objcopy;
 auto OffloadInfo = OffloadTargetInfo(Target, &BundlerOpenmp);
 bool KindIsValid = OffloadInfo.isOffloadKindValid();
 bool TripleIsValid = OffloadInfo.isTripleValid();
@@ -344,7 +354,7 @@
   BundlerConfig.BundleAlignment = BundleAlignment;
   BundlerConfig.HostInputIndex = HostInputIndex;
   BundlerConfig.FilesType = FilesType;
-  BundlerConfig.BundlerExecutable = BundlerExecutable;
+  BundlerConfig.ObjcopyPath = *Objcopy;
 
   BundlerConfig.TargetNames = TargetNames;
   BundlerConfig.InputFileNames = InputFileNames;


Index: clang/tools/clang-offload-bundler/OffloadBundler.h
===
--- clang/tools/clang-offload-bundler/OffloadBundler.h
+++ clang/tools/clang-offload-bundler/OffloadBundler.h
@@ -29,7 +29,7 @@
   unsigned HostInputIndex = ~0u;
 
   

[PATCH] D129305: [clang-offload-bundler][NFC] Library-ize ClangOffloadBundler (4/4)

2022-07-07 Thread Jacob Lambert via Phabricator via cfe-commits
lamb-j created this revision.
lamb-j added reviewers: kzhuravl, scott.linder, yaxunl.
Herald added a subscriber: mgorny.
Herald added a project: All.
lamb-j requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

Lifting the core functionalities of the clang-offload-bundler into a
user-facing library/API.

This NFC patch (4/4) moves the API files from
clang/tools/clang-offload-bundler into clang/lib/Driver and
clang/include/clang/Driver.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129305

Files:
  clang/include/clang/Driver/OffloadBundler.h
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/OffloadBundler.cpp
  clang/tools/clang-offload-bundler/CMakeLists.txt
  clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
  clang/tools/clang-offload-bundler/OffloadBundler.cpp
  clang/tools/clang-offload-bundler/OffloadBundler.h

Index: clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
===
--- clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
+++ clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
@@ -7,15 +7,14 @@
 //===--===//
 ///
 /// \file
-/// This file implements a clang-offload-bundler that bundles different
-/// files that relate with the same source code but different targets into a
-/// single one. Also the implements the opposite functionality, i.e. unbundle
-/// files previous created by this tool.
+/// This file implements a stand-alone clang-offload-bundler tool using the
+/// OffloadBundler API.
 ///
 //===--===//
 
 #include "clang/Basic/Cuda.h"
 #include "clang/Basic/Version.h"
+#include "clang/Driver/OffloadBundler.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
@@ -52,7 +51,6 @@
 #include 
 #include 
 #include 
-#include "OffloadBundler.h"
 
 using namespace llvm;
 using namespace llvm::object;
Index: clang/tools/clang-offload-bundler/CMakeLists.txt
===
--- clang/tools/clang-offload-bundler/CMakeLists.txt
+++ clang/tools/clang-offload-bundler/CMakeLists.txt
@@ -2,7 +2,6 @@
 
 add_clang_tool(clang-offload-bundler
   ClangOffloadBundler.cpp
-  OffloadBundler.cpp
 
   DEPENDS
   intrinsics_gen
@@ -10,6 +9,7 @@
 
 set(CLANG_OFFLOAD_BUNDLER_LIB_DEPS
   clangBasic
+  clangDriver
   )
 
 add_dependencies(clang clang-offload-bundler)
Index: clang/lib/Driver/OffloadBundler.cpp
===
--- clang/lib/Driver/OffloadBundler.cpp
+++ clang/lib/Driver/OffloadBundler.cpp
@@ -1,4 +1,4 @@
-//===-- clang-offload-bundler/ClangOffloadBundler.cpp -===//
+//===- OffloadBundler.cpp - File Bundling and Unbundling --===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -7,15 +7,16 @@
 //===--===//
 ///
 /// \file
-/// This file implements a clang-offload-bundler that bundles different
-/// files that relate with the same source code but different targets into a
-/// single one. Also the implements the opposite functionality, i.e. unbundle
-/// files previous created by this tool.
+/// This file implements an offload bundling API that bundles different files
+/// that relate with the same source code but different targets into a single
+/// one. Also the implements the opposite functionality, i.e. unbundle files
+/// previous created by this API.
 ///
 //===--===//
 
 #include "clang/Basic/Cuda.h"
 #include "clang/Basic/Version.h"
+#include "clang/Driver/OffloadBundler.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
@@ -53,8 +54,6 @@
 #include 
 #include 
 
-#include "OffloadBundler.h"
-
 using namespace llvm;
 using namespace llvm::object;
 
Index: clang/lib/Driver/CMakeLists.txt
===
--- clang/lib/Driver/CMakeLists.txt
+++ clang/lib/Driver/CMakeLists.txt
@@ -20,6 +20,7 @@
   DriverOptions.cpp
   Job.cpp
   Multilib.cpp
+  OffloadBundler.cpp
   OptionUtils.cpp
   Phases.cpp
   SanitizerArgs.cpp
Index: clang/include/clang/Driver/OffloadBundler.h
===
--- clang/include/clang/Driver/OffloadBundler.h
+++ clang/include/clang/Driver/OffloadBundler.h
@@ -1,4 +1,4 @@
-//===-- clang-offload-bundler/OffloadBundler.h ===//
+//=== -OffloadBundler.h - File Bundling and Unbundling --*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLV

[clang] 6c3990a - [OpenMP][NFC] Claim order clause modifiers (reproducible and unconstrained)

2022-07-07 Thread Chi Chun Chen via cfe-commits

Author: Chi Chun Chen
Date: 2022-07-07T11:30:03-05:00
New Revision: 6c3990acfbb933a61e2c74332bb252121c06bd14

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

LOG: [OpenMP][NFC] Claim order clause modifiers (reproducible and unconstrained)

Added: 


Modified: 
clang/docs/OpenMPSupport.rst

Removed: 




diff  --git a/clang/docs/OpenMPSupport.rst b/clang/docs/OpenMPSupport.rst
index 336d8e597522a..c94bc0b0de362 100644
--- a/clang/docs/OpenMPSupport.rst
+++ b/clang/docs/OpenMPSupport.rst
@@ -302,7 +302,7 @@ want to help with the implementation.
 
+--+--+--+---+
 | loop | Loop unrolling transformation 
   | :good:`done` | D99459  
  |
 
+--+--+--+---+
-| loop | 'reproducible'/'unconstrained' modifiers in 
'order' clause   | :none:`unclaimed`|   
|
+| loop | 'reproducible'/'unconstrained' modifiers in 
'order' clause   | :part:`partial`  | D127855   
|
 
+--+--+--+---+
 | memory management| alignment for allocate directive and clause   
   | :part:`worked on`| 
  |
 
+--+--+--+---+



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


[clang] 42e1035 - [LinkerWrapper] Identify offloading sections using ELF type

2022-07-07 Thread Joseph Huber via cfe-commits

Author: Joseph Huber
Date: 2022-07-07T12:38:00-04:00
New Revision: 42e10354d4553cdce131add80a4bf135f01d40db

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

LOG: [LinkerWrapper] Identify offloading sections using ELF type

Summary:
A previous patch added a new ELF section type for LLVM offloading. We
should use this when extracting the offloading sections rather than
checking the string. This pach also removes the implicit support for
COFF and MACH-O because we don't support those currently and should not
be included.

Added: 


Modified: 
clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Removed: 




diff  --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp 
b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index e7214ebfde37f..8f98bb8be08c1 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -28,6 +28,7 @@
 #include "llvm/Object/Archive.h"
 #include "llvm/Object/ArchiveWriter.h"
 #include "llvm/Object/Binary.h"
+#include "llvm/Object/ELFObjectFile.h"
 #include "llvm/Object/IRObjectFile.h"
 #include "llvm/Object/ObjectFile.h"
 #include "llvm/Object/OffloadBinary.h"
@@ -339,9 +340,8 @@ Error extractOffloadFiles(MemoryBufferRef Contents,
 // Extract offloading binaries from an Object file \p Obj.
 Error extractFromBinary(const ObjectFile &Obj,
 SmallVectorImpl &DeviceFiles) {
-  for (const SectionRef &Sec : Obj.sections()) {
-Expected Name = Sec.getName();
-if (!Name || !Name->equals(OFFLOAD_SECTION_MAGIC_STR))
+  for (ELFSectionRef Sec : Obj.sections()) {
+if (Sec.getType() != ELF::SHT_LLVM_OFFLOADING)
   continue;
 
 Expected Buffer = Sec.getContents();
@@ -433,9 +433,7 @@ Error extractFromBuffer(std::unique_ptr 
Buffer,
   switch (Type) {
   case file_magic::bitcode:
 return extractFromBitcode(std::move(Buffer), DeviceFiles);
-  case file_magic::elf_relocatable:
-  case file_magic::macho_object:
-  case file_magic::coff_object: {
+  case file_magic::elf_relocatable: {
 Expected> ObjFile =
 ObjectFile::createObjectFile(*Buffer, Type);
 if (!ObjFile)



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


[PATCH] D129301: [clang-offload-bundler][NFC] Library-ize ClangOffloadBundler (1/4)

2022-07-07 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

I feel it is better to do the refactoring in one patch, since it is difficult 
to maintain the integrity of 4 patches. It would be easier to revert or 
cherry-pick the change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129301

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


[PATCH] D129220: [clang] Cleanup ASTContext before output files in crash recovery for modules

2022-07-07 Thread Steven Wu via Phabricator via cfe-commits
steven_wu accepted this revision.
steven_wu added a comment.

LGTM. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129220

___
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

2022-07-07 Thread Dhruva Chakrabarti via Phabricator via cfe-commits
dhruvachak added a comment.

In D102107#3633705 , @jdoerfert wrote:

> Also, make sure to remove all deviceRTL files and probably reset the 
> autogenerated tests to upstream (and re-generate) before you merge (or 
> reupload).
>
> In D102107#3633678 , @dhruvachak 
> wrote:
>
>> I rebased and resolved conflicts just now and got the compiler built. I did 
>> not update the tests, hence not updating this review. I see the following 
>> outstanding issues:
>>
>> (1) make check-libomptarget produces a bunch of failures with the following 
>> compile-time assertion. So my rebased patch is not interacting correctly 
>> with opaque pointers. It is the same assertion for all the failures.
>> llvm-project/llvm/include/llvm/IR/Type.h:384: llvm::Type* 
>> llvm::Type::getNonOpaquePointerElementType() const: Assertion 
>> `NumContainedTys && "Attempting to get element type of opaque pointer"' 
>> failed.
>
> See my comment below. I think that's the issue.
>
>> (2) From earlier investigation a couple of months back, this patch uses 
>> device alloc and will fail if device allocation is not implemented (e.g. in 
>> main branch of amdgpu). Most of these failures are seen at -O0, OpenMPOpt is 
>> able to optimize them away at higher opt levels. Are we ok with these 
>> failures at -O0?
>
> It used __kmpc_alloc_shared, which should in theory work with O0 (also for 
> AMDGPU) but in practice might not, especially if it has to fallback to 
> malloc. We are working on malloc support right now. This should not stop us. 
> No reasonable code runs with O0 (on AMDGPU) right now.
>
>> (3) There were a few issues found regarding SPDMization, NoCaptureAttrs, 
>> alignment that should be applied to this patch. I have those changes on a 
>> local branch.
>
> Apply them, I can look over everything again.

Yes, I will apply the changes, refresh the tests, and re-upload.




Comment at: clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp:1540
+
+llvm::Type *PtrElemTy = AggregateV->getType()->getPointerElementType();
+auto &DL = CGM.getDataLayout();

jdoerfert wrote:
> This doesn't work anymore with opaque pointers, IIRC. We should remember the 
> type and pass to this place.
Thanks. Changing this fixed the assertions. 


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


[clang-tools-extra] b15127d - [clangd] Disable flaky test

2022-07-07 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2022-07-07T19:17:09+02:00
New Revision: b15127d0562cd6e1fc65abc1e967c56fa18391a7

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

LOG: [clangd] Disable flaky test

Added: 


Modified: 
clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp 
b/clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
index 995ad992d51be..8cb1ba93a5929 100644
--- a/clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
+++ b/clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
@@ -1409,10 +1409,10 @@ TEST_F(TUSchedulerTests, PreambleThrottle) {
 }
 
 void release(RequestID ID) override {
-  Releases.push_back(ID);
   Callback SatisfyNext;
   {
 std::lock_guard Lock(Mu);
+Releases.push_back(ID);
 if (ID > 0 && Acquires.size() == NumRequests)
   SatisfyNext = std::move(Callbacks[ID - 1]);
   }
@@ -1497,6 +1497,9 @@ TEST_F(TUSchedulerTests, PreambleThrottle) {
 // We haven't released anything yet, we're still waiting.
 EXPECT_THAT(Throttler.Releases, testing::IsEmpty());
 
+// FIXME: This is flaky, becaues the request can be destroyed after 
shutdown
+// if it hasn't been dequeued yet (stop() resets NextRequest).
+#if 0
 // Now close file A, which will shut down its AST worker.
 S.remove(A);
 // Request is destroyed after the queue shutdown, so release() has 
happened.
@@ -1505,6 +1508,7 @@ TEST_F(TUSchedulerTests, PreambleThrottle) {
 EXPECT_THAT(BuiltFilenames, testing::IsEmpty());
 // But we've cancelled the request to build A (not sure which its ID is).
 EXPECT_THAT(Throttler.Releases, ElementsAre(AnyOf(1, 0)));
+#endif
 
 // Now shut down the TU Scheduler.
   }



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


[PATCH] D129100: [clangd] Support external throttler for preamble builds

2022-07-07 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp:1499
+
+S.remove(Filenames.back());
+// Now shut down the TU Scheduler.

kadircet wrote:
> sequencing is hard here but it'd be nice to ensure release is actually seen.
So this turned out to be the cause of the test flakiness: the mechanism we 
discussed offline (context destruction) doesn't work.

The problem is that the context lives in the request, and we haven't moved the 
request from NextReq into CurrentReq yet (we're still throttling).
NextReq is destroyed when stop() is called. So S.remove(A) actually triggers 
`AfterFinishA` already, and then the following assertions race against the 
release() call.

I probably could have gotten this out of our tsan bot, but it's not producing 
any sanitizer logs (I suspect D122251).

In any case, this particular race is definitely only in the test, so disabling 
it until we have a real fix next week.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129100

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


[clang] 67a84ec - [clang] Cleanup ASTContext before output files in crash recovery for modules

2022-07-07 Thread Ben Langmuir via cfe-commits

Author: Ben Langmuir
Date: 2022-07-07T10:23:57-07:00
New Revision: 67a84ec8105e590159b6303a1f0e3cb77c02b5fe

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

LOG: [clang] Cleanup ASTContext before output files in crash recovery for 
modules

When we recover from a crash in a module compilation thread, we need to
ensure any output streams owned by the ASTConsumer (e.g. in
RawPCHContainerGenerator) are deleted before we call clearOutputFiles().
This has the same theoretical issues with proxy streams that Duncan
discusses in the commit 2d133867833fe8eb. In practice, this was observed
as a use-after-free crash on a downstream branch that uses such a proxy
stream in this code path. Add an assertion so it won't regress.

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

rdar://96525032

Added: 


Modified: 
clang/lib/Frontend/CompilerInstance.cpp
clang/lib/Frontend/FrontendAction.cpp

Removed: 




diff  --git a/clang/lib/Frontend/CompilerInstance.cpp 
b/clang/lib/Frontend/CompilerInstance.cpp
index b982ca72c78ce..ba006b5d49f87 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -757,6 +757,8 @@ void CompilerInstance::createSema(TranslationUnitKind 
TUKind,
 // Output Files
 
 void CompilerInstance::clearOutputFiles(bool EraseFiles) {
+  // The ASTConsumer can own streams that write to the output files.
+  assert(!hasASTConsumer() && "ASTConsumer should be reset");
   // Ignore errors that occur when trying to discard the temp file.
   for (OutputFile &OF : OutputFiles) {
 if (EraseFiles) {
@@ -1235,8 +1237,7 @@ compileModuleImpl(CompilerInstance &ImportingInstance, 
SourceLocation ImportLoc,
 
   // Execute the action to actually build the module in-place. Use a separate
   // thread so that we get a stack large enough.
-  llvm::CrashRecoveryContext CRC;
-  CRC.RunSafelyOnThread(
+  bool Crashed = !llvm::CrashRecoveryContext().RunSafelyOnThread(
   [&]() {
 GenerateModuleFromModuleMapAction Action;
 Instance.ExecuteAction(Action);
@@ -1249,9 +1250,15 @@ compileModuleImpl(CompilerInstance &ImportingInstance, 
SourceLocation ImportLoc,
 diag::remark_module_build_done)
 << ModuleName;
 
-  // Delete any remaining temporary files related to Instance, in case the
-  // module generation thread crashed.
-  Instance.clearOutputFiles(/*EraseFiles=*/true);
+  if (Crashed) {
+// Clear the ASTConsumer if it hasn't been already, in case it owns streams
+// that must be closed before clearing output files.
+Instance.setSema(nullptr);
+Instance.setASTConsumer(nullptr);
+
+// Delete any remaining temporary files related to Instance.
+Instance.clearOutputFiles(/*EraseFiles=*/true);
+  }
 
   // If \p AllowPCMWithCompilerErrors is set return 'success' even if errors
   // occurred.

diff  --git a/clang/lib/Frontend/FrontendAction.cpp 
b/clang/lib/Frontend/FrontendAction.cpp
index 81915e6330b03..ed3e314cc73bb 100644
--- a/clang/lib/Frontend/FrontendAction.cpp
+++ b/clang/lib/Frontend/FrontendAction.cpp
@@ -581,6 +581,7 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
   auto FailureCleanup = llvm::make_scope_exit([&]() {
 if (HasBegunSourceFile)
   CI.getDiagnosticClient().EndSourceFile();
+CI.setASTConsumer(nullptr);
 CI.clearOutputFiles(/*EraseFiles=*/true);
 CI.getLangOpts().setCompilingModule(LangOptions::CMK_None);
 setCurrentInput(FrontendInputFile());



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


[PATCH] D129220: [clang] Cleanup ASTContext before output files in crash recovery for modules

2022-07-07 Thread Ben Langmuir via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG67a84ec8105e: [clang] Cleanup ASTContext before output files 
in crash recovery for modules (authored by benlangmuir).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129220

Files:
  clang/lib/Frontend/CompilerInstance.cpp
  clang/lib/Frontend/FrontendAction.cpp


Index: clang/lib/Frontend/FrontendAction.cpp
===
--- clang/lib/Frontend/FrontendAction.cpp
+++ clang/lib/Frontend/FrontendAction.cpp
@@ -581,6 +581,7 @@
   auto FailureCleanup = llvm::make_scope_exit([&]() {
 if (HasBegunSourceFile)
   CI.getDiagnosticClient().EndSourceFile();
+CI.setASTConsumer(nullptr);
 CI.clearOutputFiles(/*EraseFiles=*/true);
 CI.getLangOpts().setCompilingModule(LangOptions::CMK_None);
 setCurrentInput(FrontendInputFile());
Index: clang/lib/Frontend/CompilerInstance.cpp
===
--- clang/lib/Frontend/CompilerInstance.cpp
+++ clang/lib/Frontend/CompilerInstance.cpp
@@ -757,6 +757,8 @@
 // Output Files
 
 void CompilerInstance::clearOutputFiles(bool EraseFiles) {
+  // The ASTConsumer can own streams that write to the output files.
+  assert(!hasASTConsumer() && "ASTConsumer should be reset");
   // Ignore errors that occur when trying to discard the temp file.
   for (OutputFile &OF : OutputFiles) {
 if (EraseFiles) {
@@ -1235,8 +1237,7 @@
 
   // Execute the action to actually build the module in-place. Use a separate
   // thread so that we get a stack large enough.
-  llvm::CrashRecoveryContext CRC;
-  CRC.RunSafelyOnThread(
+  bool Crashed = !llvm::CrashRecoveryContext().RunSafelyOnThread(
   [&]() {
 GenerateModuleFromModuleMapAction Action;
 Instance.ExecuteAction(Action);
@@ -1249,9 +1250,15 @@
 diag::remark_module_build_done)
 << ModuleName;
 
-  // Delete any remaining temporary files related to Instance, in case the
-  // module generation thread crashed.
-  Instance.clearOutputFiles(/*EraseFiles=*/true);
+  if (Crashed) {
+// Clear the ASTConsumer if it hasn't been already, in case it owns streams
+// that must be closed before clearing output files.
+Instance.setSema(nullptr);
+Instance.setASTConsumer(nullptr);
+
+// Delete any remaining temporary files related to Instance.
+Instance.clearOutputFiles(/*EraseFiles=*/true);
+  }
 
   // If \p AllowPCMWithCompilerErrors is set return 'success' even if errors
   // occurred.


Index: clang/lib/Frontend/FrontendAction.cpp
===
--- clang/lib/Frontend/FrontendAction.cpp
+++ clang/lib/Frontend/FrontendAction.cpp
@@ -581,6 +581,7 @@
   auto FailureCleanup = llvm::make_scope_exit([&]() {
 if (HasBegunSourceFile)
   CI.getDiagnosticClient().EndSourceFile();
+CI.setASTConsumer(nullptr);
 CI.clearOutputFiles(/*EraseFiles=*/true);
 CI.getLangOpts().setCompilingModule(LangOptions::CMK_None);
 setCurrentInput(FrontendInputFile());
Index: clang/lib/Frontend/CompilerInstance.cpp
===
--- clang/lib/Frontend/CompilerInstance.cpp
+++ clang/lib/Frontend/CompilerInstance.cpp
@@ -757,6 +757,8 @@
 // Output Files
 
 void CompilerInstance::clearOutputFiles(bool EraseFiles) {
+  // The ASTConsumer can own streams that write to the output files.
+  assert(!hasASTConsumer() && "ASTConsumer should be reset");
   // Ignore errors that occur when trying to discard the temp file.
   for (OutputFile &OF : OutputFiles) {
 if (EraseFiles) {
@@ -1235,8 +1237,7 @@
 
   // Execute the action to actually build the module in-place. Use a separate
   // thread so that we get a stack large enough.
-  llvm::CrashRecoveryContext CRC;
-  CRC.RunSafelyOnThread(
+  bool Crashed = !llvm::CrashRecoveryContext().RunSafelyOnThread(
   [&]() {
 GenerateModuleFromModuleMapAction Action;
 Instance.ExecuteAction(Action);
@@ -1249,9 +1250,15 @@
 diag::remark_module_build_done)
 << ModuleName;
 
-  // Delete any remaining temporary files related to Instance, in case the
-  // module generation thread crashed.
-  Instance.clearOutputFiles(/*EraseFiles=*/true);
+  if (Crashed) {
+// Clear the ASTConsumer if it hasn't been already, in case it owns streams
+// that must be closed before clearing output files.
+Instance.setSema(nullptr);
+Instance.setASTConsumer(nullptr);
+
+// Delete any remaining temporary files related to Instance.
+Instance.clearOutputFiles(/*EraseFiles=*/true);
+  }
 
   // If \p AllowPCMWithCompilerErrors is set return 'success' even if errors
   // occurred.
_

[PATCH] D129222: [pseudo] Implement a guard to determine function declarator.

2022-07-07 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/pseudo/gen/Main.cpp:114
+  const clang::pseudo::Rule &R = G.table().Rules[RID];
+  // lhs$$rhs$rhs$rhs
+  std::string EnumName = symbolName(R.Target, G) + "$";

so the dollar signs are a practical problem: at least on my machine the warning 
is on by default, so we emit thousands of warnings and it's impossible to find 
the error among them.

At *minimum* we need to use pragmas or something to suppress the warning.

But using nonstandard C++ seems likely to cause other problems and limit 
portability for not-great reasons.

Some ideas:
 -`Rule::ptr_declarator__EQUALS__ptr_operator__ptr_declarator` (this violates 
the internal `__` rule, though that one is widely ignored)
 - `Rule::ptr_declarator_0ptr_operator_1ptr_declarator`
 - `Rule::PtrDeclarator_EQ_PtrOperator_PtrDeclarator` (yet another spelling 
variation, but quite readable. We could even change the spellings in the BNF 
file...)



Comment at: clang-tools-extra/pseudo/include/clang-pseudo/Language.h:29
 // Return true if the guard is satisfied.
 using RuleGuard = llvm::function_ref RHS, const TokenStream &)>;

sammccall wrote:
> This allows/encourages guards that dynamically consider multiple rules, which 
> increases the amount of coupling between rules and grammar.
> 
> Can we express this as
> function-declarator := declarator [guard=FunctionDeclarator]?
> 
> This does mangle the grammar a bit to our implementation, and introduces two 
> names for the same concept (guard & nonterminal).
> If this feels ugly and redundant, another option would be to change the guard 
> to be specified by the rule ID instead of an extension ID:
> ```
> function-declarator := declarator [guard]
> 
> DenseMap Guards;
> ```
Having played with this idea a bit, I do think we should strongly consider 
dispatching on the rule ID rather than a named extension. I went to add some 
more guards (on NUMERIC_CONSTANT etc) and they really are 1:1 with rules.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129222

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


[PATCH] D128953: [NFC] Refactor llvm::zlib namespace

2022-07-07 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added inline comments.



Comment at: llvm/unittests/Support/CompressionTest.cpp:21
 using namespace llvm;
 
+using namespace llvm::compression;

Delete blank line between two `using`


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

https://reviews.llvm.org/D128953

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


[PATCH] D128953: [NFC] Refactor llvm::zlib namespace

2022-07-07 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: llvm/include/llvm/Support/Compression.h:27
 
+static constexpr std::string AlgorithmName = "zlib";
 static constexpr int NoCompression = 0;

Is it still used?

Prefer StringRef if the string is backed from some storage.


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

https://reviews.llvm.org/D128953

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


[PATCH] D129308: [mlir] Remove VectorToROCDL

2022-07-07 Thread Krzysztof Drewniak via Phabricator via cfe-commits
krzysz00 created this revision.
Herald added subscribers: bzcheeseman, kosarev, sdasgup3, wenzhicui, wrengr, 
dcaballe, cota, teijeong, rdzhabarov, tatianashp, msifontes, jurahul, Kayjukh, 
grosul1, Joonsoo, liufengdb, aartbik, mgester, arpith-jacob, csigg, 
antiagainst, shauheen, rriddle, mehdi_amini, tpr, mgorny.
Herald added a reviewer: aartbik.
Herald added a reviewer: ThomasRaoux.
Herald added a project: All.
krzysz00 requested review of this revision.
Herald added subscribers: cfe-commits, stephenneuendorffer, nicolasvasilache.
Herald added a reviewer: herhut.
Herald added projects: clang, MLIR.

Between issues such as
https://github.com/llvm/llvm-project/issues/56323, the fact that this
lowering (unlike the code in amdgpu-to-rocdl) does not correctly set
up bounds checks (and thus will cause page faults on reads that might
need to be padded instead), and that fixing these problems would,
essentially, involve replicating amdgpu-to-rocdl, remove
--vector-to-rocdl for being broken. In addition, the lowering does not
support many aspects of transfer_{read,write}, like supervectors, and
may not work correctly in their presence.

We (the MLIR-based convolution generator at AMD) do not use this
conversion pass, nor are we aware of any other clients.

Migration strategies:

- Use VectorToLLVM
- If buffer ops are particularly needed in your application, use

amdgpu.raw_buffer_{load,store}

A VectorToAMDGPU pass may be introduced in the future.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129308

Files:
  clang/docs/ClangFormattedStatus.rst
  clang/docs/tools/clang-formatted-files.txt
  mlir/include/mlir/Conversion/Passes.h
  mlir/include/mlir/Conversion/Passes.td
  mlir/include/mlir/Conversion/VectorToROCDL/VectorToROCDL.h
  mlir/lib/Conversion/CMakeLists.txt
  mlir/lib/Conversion/GPUToROCDL/CMakeLists.txt
  mlir/lib/Conversion/GPUToROCDL/LowerGpuOpsToROCDLOps.cpp
  mlir/lib/Conversion/VectorToROCDL/CMakeLists.txt
  mlir/lib/Conversion/VectorToROCDL/VectorToROCDL.cpp
  mlir/test/Conversion/VectorToROCDL/vector-to-rocdl.mlir
  mlir/test/Integration/GPU/ROCM/vector-transferops.mlir
  utils/bazel/llvm-project-overlay/mlir/BUILD.bazel

Index: utils/bazel/llvm-project-overlay/mlir/BUILD.bazel
===
--- utils/bazel/llvm-project-overlay/mlir/BUILD.bazel
+++ utils/bazel/llvm-project-overlay/mlir/BUILD.bazel
@@ -2614,7 +2614,6 @@
 ":TosaToTensor",
 ":VectorToGPU",
 ":VectorToLLVM",
-":VectorToROCDL",
 ":VectorToSCF",
 ":VectorToSPIRV",
 ],
@@ -3803,30 +3802,6 @@
 ],
 )
 
-cc_library(
-name = "VectorToROCDL",
-srcs = [
-"lib/Conversion/VectorToROCDL/VectorToROCDL.cpp",
-":ConversionPassDetail",
-],
-hdrs = ["include/mlir/Conversion/VectorToROCDL/VectorToROCDL.h"],
-includes = ["include"],
-deps = [
-":ConversionPassIncGen",
-":FuncDialect",
-":FuncToLLVM",
-":GPUDialect",
-":IR",
-":LLVMCommonConversion",
-":LLVMDialect",
-":MemRefToLLVM",
-":Pass",
-":ROCDLDialect",
-":Transforms",
-":VectorDialect",
-],
-)
-
 cc_library(
 name = "VectorToSPIRV",
 srcs = glob([
@@ -3894,7 +3869,6 @@
 ":Transforms",
 ":VectorDialect",
 ":VectorToLLVM",
-":VectorToROCDL",
 ":VectorToSCF",
 "//llvm:Support",
 ],
@@ -6347,7 +6321,6 @@
 ":TransformsPassIncGen",
 ":VectorDialect",
 ":VectorToLLVM",
-":VectorToROCDL",
 ":VectorToSCF",
 ":VectorToSPIRV",
 ":VectorTransforms",
Index: mlir/test/Integration/GPU/ROCM/vector-transferops.mlir
===
--- mlir/test/Integration/GPU/ROCM/vector-transferops.mlir
+++ mlir/test/Integration/GPU/ROCM/vector-transferops.mlir
@@ -1,7 +1,7 @@
 // RUN: mlir-opt %s \
 // RUN:   -convert-scf-to-cf \
 // RUN:   -gpu-kernel-outlining \
-// RUN:   -pass-pipeline='gpu.module(strip-debuginfo,convert-gpu-to-rocdl,gpu-to-hsaco{chip=%chip})' \
+// RUN:   -pass-pipeline='gpu.module(strip-debuginfo,convert-gpu-to-rocdl{chipset=%chip index-bitwidth=32},gpu-to-hsaco{chip=%chip})' \
 // RUN:   -gpu-to-llvm \
 // RUN: | mlir-cpu-runner \
 // RUN:   --shared-libs=%linalg_test_lib_dir/libmlir_rocm_runtime%shlibext \
@@ -9,22 +9,21 @@
 // RUN:   --entry-point-result=void \
 // RUN: | FileCheck %s
 
+// TODO: swap for vector transfer reads if we ever create a --vector-to-amdgpu
 func.func @vectransferx2(%arg0 : memref, %arg1 : memref) {
   %cst = arith.constant 1 : index
   gpu.launch blocks(%bx, %by, %bz) in (%grid_x = %cst, %grid_y = %cst, %grid_z = %cst)
  threads(%tx, %ty, %tz) in (%block_x = %cst, %block_y = %cst, %block_z = %cst) {
 %f0 = arith.constant 0.0: f32
-%base = arith.constant 0 : index
-%f = vector.transfer_read %arg0[%base], %f0
-{pe

[PATCH] D129149: [OMPIRBuilder] Add support for simdlen clause

2022-07-07 Thread Michael Kruse via Phabricator via cfe-commits
Meinersbur accepted this revision.
Meinersbur added a comment.

LGTM


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

https://reviews.llvm.org/D129149

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


[PATCH] D129277: [clang] [Serialization] Fix swapped PPOpts/ExistingPPOpts parameters. NFC.

2022-07-07 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Thanks for catching this! Is it really an NFC change though (it seems like it 
would change some of the diagnostic behavior and the list of suggested 
predefines)? Can you add test coverage for the change?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129277

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


[PATCH] D129311: [clang-format] Update return code

2022-07-07 Thread Sridhar Gopinath via Phabricator via cfe-commits
sridhar_gopinath created this revision.
sridhar_gopinath added reviewers: curdeius, owenpan.
Herald added a project: All.
sridhar_gopinath requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

In diff and diffstat modes, the return code is != 0 even when there are no
changes between commits. This issue can be fixed by passing `--exit-code` to
`git diff` command that returns 0 when there are no changes and using that as
the return code for clang-format.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129311

Files:
  clang/tools/clang-format/git-clang-format


Index: clang/tools/clang-format/git-clang-format
===
--- clang/tools/clang-format/git-clang-format
+++ clang/tools/clang-format/git-clang-format
@@ -198,9 +198,9 @@
 return 0
 
   if opts.diff:
-print_diff(old_tree, new_tree)
+return print_diff(old_tree, new_tree)
   elif opts.diffstat:
-print_diffstat(old_tree, new_tree)
+return print_diffstat(old_tree, new_tree)
   else:
 changed_files = apply_changes(old_tree, new_tree, force=opts.force,
   patch_mode=opts.patch)
@@ -209,7 +209,7 @@
   for filename in changed_files:
 print('%s' % filename)
 
-  return 1
+return 1
 
 
 def load_git_config(non_string_options=None):
@@ -536,8 +536,8 @@
   # We also only print modified files since `new_tree` only contains the files
   # that were modified, so unmodified files would show as deleted without the
   # filter.
-  subprocess.check_call(['git', 'diff', '--diff-filter=M', old_tree, new_tree,
- '--'])
+  subprocess.check_call(['git', 'diff', '--diff-filter=M',
+old_tree, new_tree, '--exit-code', '--'])
 
 def print_diffstat(old_tree, new_tree):
   """Print the diffstat between the two trees to stdout."""
@@ -548,7 +548,13 @@
   # We also only print modified files since `new_tree` only contains the files
   # that were modified, so unmodified files would show as deleted without the
   # filter.
-  subprocess.check_call(['git', 'diff', '--diff-filter=M', '--stat', old_tree, 
new_tree,
+  subprocess.check_call(['git',
+ 'diff',
+ '--diff-filter=M',
+ '--stat',
+ old_tree,
+ new_tree,
+ '--exit-code',
  '--'])
 
 def apply_changes(old_tree, new_tree, force=False, patch_mode=False):


Index: clang/tools/clang-format/git-clang-format
===
--- clang/tools/clang-format/git-clang-format
+++ clang/tools/clang-format/git-clang-format
@@ -198,9 +198,9 @@
 return 0
 
   if opts.diff:
-print_diff(old_tree, new_tree)
+return print_diff(old_tree, new_tree)
   elif opts.diffstat:
-print_diffstat(old_tree, new_tree)
+return print_diffstat(old_tree, new_tree)
   else:
 changed_files = apply_changes(old_tree, new_tree, force=opts.force,
   patch_mode=opts.patch)
@@ -209,7 +209,7 @@
   for filename in changed_files:
 print('%s' % filename)
 
-  return 1
+return 1
 
 
 def load_git_config(non_string_options=None):
@@ -536,8 +536,8 @@
   # We also only print modified files since `new_tree` only contains the files
   # that were modified, so unmodified files would show as deleted without the
   # filter.
-  subprocess.check_call(['git', 'diff', '--diff-filter=M', old_tree, new_tree,
- '--'])
+  subprocess.check_call(['git', 'diff', '--diff-filter=M',
+old_tree, new_tree, '--exit-code', '--'])
 
 def print_diffstat(old_tree, new_tree):
   """Print the diffstat between the two trees to stdout."""
@@ -548,7 +548,13 @@
   # We also only print modified files since `new_tree` only contains the files
   # that were modified, so unmodified files would show as deleted without the
   # filter.
-  subprocess.check_call(['git', 'diff', '--diff-filter=M', '--stat', old_tree, new_tree,
+  subprocess.check_call(['git',
+ 'diff',
+ '--diff-filter=M',
+ '--stat',
+ old_tree,
+ new_tree,
+ '--exit-code',
  '--'])
 
 def apply_changes(old_tree, new_tree, force=False, patch_mode=False):
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D128953: [NFC] Refactor llvm::zlib namespace

2022-07-07 Thread Cole Kissane via Phabricator via cfe-commits
ckissane added inline comments.



Comment at: llvm/include/llvm/Support/Compression.h:27
 
+static constexpr std::string AlgorithmName = "zlib";
 static constexpr int NoCompression = 0;

MaskRay wrote:
> Is it still used?
> 
> Prefer StringRef if the string is backed from some storage.
No it is not, I will remove it and reintroduce it in the first patch that adds 
zstd



Comment at: llvm/unittests/Support/CompressionTest.cpp:21
 using namespace llvm;
 
+using namespace llvm::compression;

MaskRay wrote:
> Delete blank line between two `using`
will do


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

https://reviews.llvm.org/D128953

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


[PATCH] D129277: [clang] [Serialization] Fix swapped PPOpts/ExistingPPOpts parameters. NFC.

2022-07-07 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

In D129277#3636567 , @aaron.ballman 
wrote:

> Thanks for catching this! Is it really an NFC change though (it seems like it 
> would change some of the diagnostic behavior and the list of suggested 
> predefines)? Can you add test coverage for the change?

TBH I haven’t tried to follow exactly where this case would matter in the 
current state of affairs - the function is called in three places, and maybe 
the individual roles of the parameters currently only make a difference in the 
other callers. As it didn’t break any tests I presumed it’s NFC.

Alternatively I can keep this change folded into D126676 
 (although I’m not sure if the parameter 
change will end up visible in the final form of that patch though, so maybe I I 
might end up dropping the change from there too if it’s not testable there 
either?).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129277

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


[PATCH] D128953: [NFC] Refactor llvm::zlib namespace

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

I think this can be pushed now. You need to remove the variable

> In file included from 
> /var/lib/buildkite-agent/builds/llvm-project/llvm/lib/MC/ELFObjectWriter.cpp:41:
> /var/lib/buildkite-agent/builds/llvm-project/llvm/include/llvm/Support/Compression.h:27:30:
>  error: constexpr variable cannot have non-literal type 'const std::string' 
> (aka 'const basic_string')
> static constexpr std::string AlgorithmName = "zlib";

You likely need to run `ninja check-llvm check-clang check-clang-tools 
check-lld check-lldb` to ensure all relevant targets still build.
(You can use `check-all` if your lists of 
LLVM_ENABLED_PROJECTS/LLVM_ENABLE_RUNTIMES are appropriate.)




Comment at: llvm/include/llvm/Support/Compression.h:48
+} // End of namespace zlib
+
+} // End of namespace compression

No need to add blank line between two namespace `}`.



Comment at: llvm/lib/Support/Compression.cpp:25
 using namespace llvm;
 
+using namespace llvm::compression;

delete the excess blank line


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

https://reviews.llvm.org/D128953

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


[PATCH] D128953: [NFC] Refactor llvm::zlib namespace

2022-07-07 Thread Cole Kissane via Phabricator via cfe-commits
ckissane updated this revision to Diff 443005.
ckissane added a comment.

- Merge branch 'ckissane.refactor-compression.part-0' of 
github.com:ckissane/llvm-project into ckissane.refactor-compression.part-0
- Merge branch 'main' into ckissane.refactor-compression.part-0
- compression refactor: undo string subs
- Merge branch 'ckissane.refactor-compression.part-0' into 
ckissane.refactor-compression.part-0.no-string-sub
- remove compression namespaace aliases
- update release notes to reflect no compression aliases
- chore: fmt and remove AlgorithmName from zlib namespace
- Merge remote-tracking branch 'origin/main' into 
ckissane.refactor-compression.part-0.no-string-sub


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128953

Files:
  clang-tools-extra/clangd/index/Serialization.cpp
  clang-tools-extra/clangd/unittests/SerializationTests.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  lld/ELF/Driver.cpp
  lld/ELF/InputSection.cpp
  llvm/docs/ReleaseNotes.rst
  llvm/include/llvm/Support/Compression.h
  llvm/lib/MC/ELFObjectWriter.cpp
  llvm/lib/ObjCopy/ELF/ELFObject.cpp
  llvm/lib/Object/Decompressor.cpp
  llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
  llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp
  llvm/lib/ProfileData/InstrProf.cpp
  llvm/lib/ProfileData/SampleProfReader.cpp
  llvm/lib/ProfileData/SampleProfWriter.cpp
  llvm/lib/Support/Compression.cpp
  llvm/tools/llvm-mc/llvm-mc.cpp
  llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
  llvm/unittests/ProfileData/InstrProfTest.cpp
  llvm/unittests/Support/CompressionTest.cpp

Index: llvm/unittests/Support/CompressionTest.cpp
===
--- llvm/unittests/Support/CompressionTest.cpp
+++ llvm/unittests/Support/CompressionTest.cpp
@@ -18,6 +18,7 @@
 #include "gtest/gtest.h"
 
 using namespace llvm;
+using namespace llvm::compression;
 
 namespace {
 
Index: llvm/unittests/ProfileData/InstrProfTest.cpp
===
--- llvm/unittests/ProfileData/InstrProfTest.cpp
+++ llvm/unittests/ProfileData/InstrProfTest.cpp
@@ -1147,14 +1147,16 @@
 // Compressing:
 std::string FuncNameStrings1;
 EXPECT_THAT_ERROR(collectPGOFuncNameStrings(
-  FuncNames1, (DoCompression && zlib::isAvailable()),
+  FuncNames1,
+  (DoCompression && compression::zlib::isAvailable()),
   FuncNameStrings1),
   Succeeded());
 
 // Compressing:
 std::string FuncNameStrings2;
 EXPECT_THAT_ERROR(collectPGOFuncNameStrings(
-  FuncNames2, (DoCompression && zlib::isAvailable()),
+  FuncNames2,
+  (DoCompression && compression::zlib::isAvailable()),
   FuncNameStrings2),
   Succeeded());
 
Index: llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
===
--- llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
+++ llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
@@ -739,7 +739,7 @@
 .str()
 .c_str());
 }
-if (!zlib::isAvailable())
+if (!compression::zlib::isAvailable())
   return createStringError(
   errc::invalid_argument,
   "LLVM was not compiled with LLVM_ENABLE_ZLIB: can not compress");
@@ -998,7 +998,7 @@
 "--decompress-debug-sections");
   }
 
-  if (Config.DecompressDebugSections && !zlib::isAvailable())
+  if (Config.DecompressDebugSections && !compression::zlib::isAvailable())
 return createStringError(
 errc::invalid_argument,
 "LLVM was not compiled with LLVM_ENABLE_ZLIB: cannot decompress");
Index: llvm/tools/llvm-mc/llvm-mc.cpp
===
--- llvm/tools/llvm-mc/llvm-mc.cpp
+++ llvm/tools/llvm-mc/llvm-mc.cpp
@@ -403,7 +403,7 @@
   MAI->setRelaxELFRelocations(RelaxELFRel);
 
   if (CompressDebugSections != DebugCompressionType::None) {
-if (!zlib::isAvailable()) {
+if (!compression::zlib::isAvailable()) {
   WithColor::error(errs(), ProgName)
   << "build tools with zlib to enable -compress-debug-sections";
   return 1;
Index: llvm/lib/Support/Compression.cpp
===
--- llvm/lib/Support/Compression.cpp
+++ llvm/lib/Support/Compression.cpp
@@ -23,10 +23,9 @@
 
 using namespace llvm;
 
+using namespace llvm::compression;
+
 #if LLVM_ENABLE_ZLIB
-static Error createError(StringRef Err) {
-  return make_error(Err, inconvertibleErrorCode());
-}
 
 static StringRef convertZlibCodeToString(int Code) {
   switch (Code) {
@@ -70,15 +69,17 @@
   // Tell MemorySanitizer that zlib output buffer is fu

[PATCH] D128953: [NFC] Refactor llvm::zlib namespace

2022-07-07 Thread Cole Kissane via Phabricator via cfe-commits
ckissane updated this revision to Diff 443006.
ckissane added a comment.

- chore: delete an excess blank line


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128953

Files:
  clang-tools-extra/clangd/index/Serialization.cpp
  clang-tools-extra/clangd/unittests/SerializationTests.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  lld/ELF/Driver.cpp
  lld/ELF/InputSection.cpp
  llvm/docs/ReleaseNotes.rst
  llvm/include/llvm/Support/Compression.h
  llvm/lib/MC/ELFObjectWriter.cpp
  llvm/lib/ObjCopy/ELF/ELFObject.cpp
  llvm/lib/Object/Decompressor.cpp
  llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
  llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp
  llvm/lib/ProfileData/InstrProf.cpp
  llvm/lib/ProfileData/SampleProfReader.cpp
  llvm/lib/ProfileData/SampleProfWriter.cpp
  llvm/lib/Support/Compression.cpp
  llvm/tools/llvm-mc/llvm-mc.cpp
  llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
  llvm/unittests/ProfileData/InstrProfTest.cpp
  llvm/unittests/Support/CompressionTest.cpp

Index: llvm/unittests/Support/CompressionTest.cpp
===
--- llvm/unittests/Support/CompressionTest.cpp
+++ llvm/unittests/Support/CompressionTest.cpp
@@ -18,6 +18,7 @@
 #include "gtest/gtest.h"
 
 using namespace llvm;
+using namespace llvm::compression;
 
 namespace {
 
Index: llvm/unittests/ProfileData/InstrProfTest.cpp
===
--- llvm/unittests/ProfileData/InstrProfTest.cpp
+++ llvm/unittests/ProfileData/InstrProfTest.cpp
@@ -1147,14 +1147,16 @@
 // Compressing:
 std::string FuncNameStrings1;
 EXPECT_THAT_ERROR(collectPGOFuncNameStrings(
-  FuncNames1, (DoCompression && zlib::isAvailable()),
+  FuncNames1,
+  (DoCompression && compression::zlib::isAvailable()),
   FuncNameStrings1),
   Succeeded());
 
 // Compressing:
 std::string FuncNameStrings2;
 EXPECT_THAT_ERROR(collectPGOFuncNameStrings(
-  FuncNames2, (DoCompression && zlib::isAvailable()),
+  FuncNames2,
+  (DoCompression && compression::zlib::isAvailable()),
   FuncNameStrings2),
   Succeeded());
 
Index: llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
===
--- llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
+++ llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
@@ -739,7 +739,7 @@
 .str()
 .c_str());
 }
-if (!zlib::isAvailable())
+if (!compression::zlib::isAvailable())
   return createStringError(
   errc::invalid_argument,
   "LLVM was not compiled with LLVM_ENABLE_ZLIB: can not compress");
@@ -998,7 +998,7 @@
 "--decompress-debug-sections");
   }
 
-  if (Config.DecompressDebugSections && !zlib::isAvailable())
+  if (Config.DecompressDebugSections && !compression::zlib::isAvailable())
 return createStringError(
 errc::invalid_argument,
 "LLVM was not compiled with LLVM_ENABLE_ZLIB: cannot decompress");
Index: llvm/tools/llvm-mc/llvm-mc.cpp
===
--- llvm/tools/llvm-mc/llvm-mc.cpp
+++ llvm/tools/llvm-mc/llvm-mc.cpp
@@ -403,7 +403,7 @@
   MAI->setRelaxELFRelocations(RelaxELFRel);
 
   if (CompressDebugSections != DebugCompressionType::None) {
-if (!zlib::isAvailable()) {
+if (!compression::zlib::isAvailable()) {
   WithColor::error(errs(), ProgName)
   << "build tools with zlib to enable -compress-debug-sections";
   return 1;
Index: llvm/lib/Support/Compression.cpp
===
--- llvm/lib/Support/Compression.cpp
+++ llvm/lib/Support/Compression.cpp
@@ -22,11 +22,9 @@
 #endif
 
 using namespace llvm;
+using namespace llvm::compression;
 
 #if LLVM_ENABLE_ZLIB
-static Error createError(StringRef Err) {
-  return make_error(Err, inconvertibleErrorCode());
-}
 
 static StringRef convertZlibCodeToString(int Code) {
   switch (Code) {
@@ -70,15 +68,17 @@
   // Tell MemorySanitizer that zlib output buffer is fully initialized.
   // This avoids a false report when running LLVM with uninstrumented ZLib.
   __msan_unpoison(UncompressedBuffer, UncompressedSize);
-  return Res ? createError(convertZlibCodeToString(Res)) : Error::success();
+  return Res ? make_error(convertZlibCodeToString(Res),
+   inconvertibleErrorCode())
+ : Error::success();
 }
 
 Error zlib::uncompress(StringRef InputBuffer,
SmallVectorImpl &UncompressedBuffer,
size_t UncompressedSize) {
   Uncompres

[PATCH] D128953: [NFC] Refactor llvm::zlib namespace

2022-07-07 Thread Cole Kissane via Phabricator via cfe-commits
ckissane marked 5 inline comments as done.
ckissane added a comment.

mark some handled comments done


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128953

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


[PATCH] D128754: [llvm] Remove unused and redundant crc32 funcction from llvm::compression::zlib namespace

2022-07-07 Thread Cole Kissane via Phabricator via cfe-commits
ckissane updated this revision to Diff 443009.
ckissane edited the summary of this revision.
ckissane added a comment.

- remove crc32 from zlib compression namespace
- Merge branch 'ckissane.refactor-compression.part-0' into 
ckissane.refactor-compression.part-1
- Merge branch 'ckissane.refactor-compression.part-0.no-string-sub' into 
ckissane.refactor-compression.part-1
- Merge remote-tracking branch 
'origin/ckissane.refactor-compression.part-0.no-string-sub' into 
ckissane.refactor-compression.part-1


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128754

Files:
  llvm/docs/ReleaseNotes.rst
  llvm/include/llvm/Support/Compression.h
  llvm/lib/Support/Compression.cpp
  llvm/unittests/Support/CompressionTest.cpp


Index: llvm/unittests/Support/CompressionTest.cpp
===
--- llvm/unittests/Support/CompressionTest.cpp
+++ llvm/unittests/Support/CompressionTest.cpp
@@ -63,12 +63,6 @@
   TestZlibCompression(BinaryDataStr, zlib::DefaultCompression);
 }
 
-TEST(CompressionTest, ZlibCRC32) {
-  EXPECT_EQ(
-  0x414FA339U,
-  zlib::crc32(StringRef("The quick brown fox jumps over the lazy dog")));
-}
-
 #endif
 
 }
Index: llvm/lib/Support/Compression.cpp
===
--- llvm/lib/Support/Compression.cpp
+++ llvm/lib/Support/Compression.cpp
@@ -83,10 +83,6 @@
   return E;
 }
 
-uint32_t zlib::crc32(StringRef Buffer) {
-  return ::crc32(0, (const Bytef *)Buffer.data(), Buffer.size());
-}
-
 #else
 bool zlib::isAvailable() { return false; }
 void zlib::compress(StringRef InputBuffer,
@@ -102,7 +98,4 @@
size_t UncompressedSize) {
   llvm_unreachable("zlib::uncompress is unavailable");
 }
-uint32_t zlib::crc32(StringRef Buffer) {
-  llvm_unreachable("zlib::crc32 is unavailable");
-}
 #endif
Index: llvm/include/llvm/Support/Compression.h
===
--- llvm/include/llvm/Support/Compression.h
+++ llvm/include/llvm/Support/Compression.h
@@ -41,8 +41,6 @@
  SmallVectorImpl &UncompressedBuffer,
  size_t UncompressedSize);
 
-uint32_t crc32(StringRef Buffer);
-
 } // End of namespace zlib
 
 } // End of namespace compression
Index: llvm/docs/ReleaseNotes.rst
===
--- llvm/docs/ReleaseNotes.rst
+++ llvm/docs/ReleaseNotes.rst
@@ -206,6 +206,7 @@
   introduction of alternatives to zlib compression in the llvm toolchain.
   Changes are as follows:
   * Relocate the ``llvm::zlib`` namespace to ``llvm::compression::zlib``.
+  * Remove crc32 from zlib compression namespace, people should use the 
``llvm::crc32`` instead.
 
 Changes to the Go bindings
 --


Index: llvm/unittests/Support/CompressionTest.cpp
===
--- llvm/unittests/Support/CompressionTest.cpp
+++ llvm/unittests/Support/CompressionTest.cpp
@@ -63,12 +63,6 @@
   TestZlibCompression(BinaryDataStr, zlib::DefaultCompression);
 }
 
-TEST(CompressionTest, ZlibCRC32) {
-  EXPECT_EQ(
-  0x414FA339U,
-  zlib::crc32(StringRef("The quick brown fox jumps over the lazy dog")));
-}
-
 #endif
 
 }
Index: llvm/lib/Support/Compression.cpp
===
--- llvm/lib/Support/Compression.cpp
+++ llvm/lib/Support/Compression.cpp
@@ -83,10 +83,6 @@
   return E;
 }
 
-uint32_t zlib::crc32(StringRef Buffer) {
-  return ::crc32(0, (const Bytef *)Buffer.data(), Buffer.size());
-}
-
 #else
 bool zlib::isAvailable() { return false; }
 void zlib::compress(StringRef InputBuffer,
@@ -102,7 +98,4 @@
size_t UncompressedSize) {
   llvm_unreachable("zlib::uncompress is unavailable");
 }
-uint32_t zlib::crc32(StringRef Buffer) {
-  llvm_unreachable("zlib::crc32 is unavailable");
-}
 #endif
Index: llvm/include/llvm/Support/Compression.h
===
--- llvm/include/llvm/Support/Compression.h
+++ llvm/include/llvm/Support/Compression.h
@@ -41,8 +41,6 @@
  SmallVectorImpl &UncompressedBuffer,
  size_t UncompressedSize);
 
-uint32_t crc32(StringRef Buffer);
-
 } // End of namespace zlib
 
 } // End of namespace compression
Index: llvm/docs/ReleaseNotes.rst
===
--- llvm/docs/ReleaseNotes.rst
+++ llvm/docs/ReleaseNotes.rst
@@ -206,6 +206,7 @@
   introduction of alternatives to zlib compression in the llvm toolchain.
   Changes are as follows:
   * Relocate the ``llvm::zlib`` namespace to ``llvm::compression::zlib``.
+  * Remove crc32 from zlib compression namespace, people should use the ``llvm::crc32`` instead.
 
 Changes to the Go bindings
 --

[PATCH] D128754: [llvm] Remove unused and redundant crc32 funcction from llvm::compression::zlib namespace

2022-07-07 Thread Cole Kissane via Phabricator via cfe-commits
ckissane marked 4 inline comments as done.
ckissane added a comment.

mark handled comments as done


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128754

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


[PATCH] D128550: [OpenMP] Change OpenMP code generation for target region entries

2022-07-07 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 updated this revision to Diff 443011.
jhuber6 added a comment.

Moving version field to struct


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128550

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/capturing_in_templates.cpp
  clang/test/OpenMP/declare_mapper_codegen.cpp
  clang/test/OpenMP/declare_target_link_codegen.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_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/nvptx_lambda_capturing.cpp
  clang/test/OpenMP/nvptx_lambda_pointer_capturing.cpp
  clang/test/OpenMP/nvptx_target_requires_unified_shared_memory.cpp
  clang/test/OpenMP/openmp_offload_codegen.cpp
  clang/test/OpenMP/reduction_implicit_map.cpp
  clang/test/OpenMP/target_codegen.cpp
  clang/test/OpenMP/target_codegen_global_capture.cpp
  clang/test/OpenMP/target_data_member_codegen.cpp
  clang/test/OpenMP/target_data_use_device_ptr_if_codegen.cpp
  clang/test/OpenMP/target_defaultmap_codegen_01.cpp
  clang/test/OpenMP/target_defaultmap_codegen_02.cpp
  clang/test/OpenMP/target_depend_codegen.cpp
  clang/test/OpenMP/target_device_codegen.cpp
  clang/test/OpenMP/target_firstprivate_codegen.cpp
  clang/test/OpenMP/target_is_device_ptr_codegen.cpp
  clang/test/OpenMP/target_map_codegen_00.cpp
  clang/test/OpenMP/target_map_codegen_01.cpp
  clang/test/OpenMP/target_map_codegen_02.cpp
  clang/test/OpenMP/target_map_codegen_03.cpp
  clang/test/OpenMP/target_map_codegen_04.cpp
  clang/test/OpenMP/target_map_codegen_05.cpp
  clang/test/OpenMP/target_map_codegen_06.cpp
  clang/test/OpenMP/target_map_codegen_07.cpp
  clang/test/OpenMP/target_map_codegen_08.cpp
  clang/test/OpenMP/target_map_codegen_09.cpp
  clang/test/OpenMP/target_map_codegen_10.cpp
  clang/test/OpenMP/target_map_codegen_11.cpp
  clang/test/OpenMP/target_map_codegen_12.cpp
  clang/test/OpenMP/target_map_codegen_13.cpp
  clang/test/OpenMP/target_map_codegen_14.cpp
  clang/test/OpenMP/target_map_codegen_15.cpp
  clang/test/OpenMP/target_map_codegen_16.cpp
  clang/test/OpenMP/target_map_codegen_17.cpp
  clang/test/OpenMP/target_map_codegen_18.inc
  clang/test/OpenMP/target_map_codegen_19.cpp
  clang/test/OpenMP/target_map_codegen_20.cpp
  clang/test/OpenMP/target_map_codegen_21.cpp
  clang/test/OpenMP/target_map_codegen_22.cpp
  clang/test/OpenMP/target_map_codegen_23.cpp
  clang/test/OpenMP/target_map_codegen_24.cpp
  clang/test/OpenMP/target_map_codegen_25.cpp
  clang/test/OpenMP/target_map_codegen_26.cpp
  clang/test/OpenMP/target_map_codegen_27.cpp
  clang/test/OpenMP/target_map_codegen_28.cpp
  clang/test/OpenMP/target_map_codegen_29.cpp
  clang/test/OpenMP/target_map_codegen_30.cpp
  clang/test/OpenMP/target_map_codegen_31.cpp
  clang/test/OpenMP/target_map_codegen_32.cpp
  clang/test/OpenMP/target_map_codegen_33.cpp
  clang/test/OpenMP/target_map_codegen_34.cpp
  clang/test/OpenMP/target_map_codegen_35.cpp
  clang/test/OpenMP/target_map_codegen_hold.cpp
  clang/test/OpenMP/target_map_names.cpp
  clang/test/OpenMP/target_map_names_attr.cpp
  clang/test/OpenMP/target_offload_mandatory_codegen.cpp
  clang/test/OpenMP/target_parallel_codegen.cpp
  clang/test/OpenMP/target_parallel_depend_codegen.cpp
  clang/test/OpenMP/target_parallel_for_codegen.cpp
  clang/test/OpenMP/target_parallel_for_depend_codegen.cpp
  clang/test/OpenMP/target_parallel_for_simd_codegen.cpp
  clang/test/OpenMP/target_parallel_for_simd_depend_codegen.cpp
  clang/test/OpenMP/target_parallel_for_simd_uses_allocators_codegen.cpp
  clang/test/OpenMP/target_parallel_for_use

[PATCH] D128816: [OpenMP] Add loop tripcount argument to kernel launch and remove push function

2022-07-07 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 updated this revision to Diff 443013.
jhuber6 added a comment.

Rebasing


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128816

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  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_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/nvptx_lambda_capturing.cpp
  clang/test/OpenMP/reduction_implicit_map.cpp
  clang/test/OpenMP/target_codegen_global_capture.cpp
  clang/test/OpenMP/target_map_codegen_03.cpp
  clang/test/OpenMP/target_map_codegen_hold.cpp
  clang/test/OpenMP/target_offload_mandatory_codegen.cpp
  clang/test/OpenMP/target_parallel_codegen.cpp
  clang/test/OpenMP/target_parallel_for_codegen.cpp
  clang/test/OpenMP/target_parallel_for_simd_codegen.cpp
  clang/test/OpenMP/target_parallel_if_codegen.cpp
  clang/test/OpenMP/target_parallel_num_threads_codegen.cpp
  clang/test/OpenMP/target_teams_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_collapse_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_dist_schedule_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_firstprivate_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_lastprivate_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_collapse_codegen.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_dist_schedule_codegen.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_firstprivate_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_if_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_lastprivate_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_order_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_private_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_proc_bind_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_reduction_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_schedule_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_simd_codegen.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_collapse_codegen.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_dist_schedule_codegen.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_firstprivate_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_simd_if_codegen.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_lastprivate_codegen.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_private_codegen.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_proc_bind_codegen.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_reduction_codegen.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_schedule_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_private_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_reduction_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_simd_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_simd_collapse_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_simd_dist_schedule_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_simd_firstprivate_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_simd_lastprivate_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_simd_private_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_simd_reduction_codegen.cpp
  clang/test/O

[clang] 19e2188 - [clang][dataflow] Return a solution from the solver when `Constraints` are `Satisfiable`.

2022-07-07 Thread Dmitri Gribenko via cfe-commits

Author: Wei Yi Tee
Date: 2022-07-07T20:53:47+02:00
New Revision: 19e21887eb18aa019000c2384ea7f2c91d937489

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

LOG: [clang][dataflow] Return a solution from the solver when `Constraints` are 
`Satisfiable`.

A truth assignment to atomic boolean values which satisfy `Constraints` will be 
returned if found by the solver.
This gives us more information which can be helpful for debugging or 
constructing warning messages.

Reviewed By: hlopko, gribozavr2, sgatev

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

Added: 


Modified: 
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
clang/include/clang/Analysis/FlowSensitive/Solver.h
clang/lib/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp
clang/unittests/Analysis/FlowSensitive/SolverTest.cpp

Removed: 




diff  --git 
a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h 
b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
index d87b9cc37b996..358ace0430f62 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
@@ -271,17 +271,18 @@ class DataflowAnalysisContext {
   AtomicBoolValue &Token, llvm::DenseSet &Constraints,
   llvm::DenseSet &VisitedTokens);
 
-  /// Returns the result of satisfiability checking on `Constraints`.
-  /// Possible return values are:
-  /// - `Satisfiable`: There exists a satisfying assignment for `Constraints`.
-  /// - `Unsatisfiable`: There is no satisfying assignment for `Constraints`.
-  /// - `TimedOut`: The solver gives up on finding a satisfying assignment.
+  /// Returns the outcome of satisfiability checking on `Constraints`.
+  /// Possible outcomes are:
+  /// - `Satisfiable`: A satisfying assignment exists and is returned.
+  /// - `Unsatisfiable`: A satisfying assignment does not exist.
+  /// - `TimedOut`: The search for a satisfying assignment was not completed.
   Solver::Result querySolver(llvm::DenseSet Constraints);
 
   /// Returns true if the solver is able to prove that there is no satisfying
   /// assignment for `Constraints`
   bool isUnsatisfiable(llvm::DenseSet Constraints) {
-return querySolver(std::move(Constraints)) == 
Solver::Result::Unsatisfiable;
+return querySolver(std::move(Constraints)).getStatus() ==
+   Solver::Result::Status::Unsatisfiable;
   }
 
   /// Returns a boolean value as a result of substituting `Val` and its sub

diff  --git a/clang/include/clang/Analysis/FlowSensitive/Solver.h 
b/clang/include/clang/Analysis/FlowSensitive/Solver.h
index 6b685b9b3c9a7..b7a14f3484e42 100644
--- a/clang/include/clang/Analysis/FlowSensitive/Solver.h
+++ b/clang/include/clang/Analysis/FlowSensitive/Solver.h
@@ -15,7 +15,9 @@
 #define LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_SOLVER_H
 
 #include "clang/Analysis/FlowSensitive/Value.h"
+#include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/Optional.h"
 
 namespace clang {
 namespace dataflow {
@@ -23,17 +25,58 @@ namespace dataflow {
 /// An interface for a SAT solver that can be used by dataflow analyses.
 class Solver {
 public:
-  enum class Result {
-/// Indicates that there exists a satisfying assignment for a boolean
+  struct Result {
+enum class Status {
+  /// Indicates that there exists a satisfying assignment for a boolean
+  /// formula.
+  Satisfiable,
+
+  /// Indicates that there is no satisfying assignment for a boolean
+  /// formula.
+  Unsatisfiable,
+
+  /// Indicates that the solver gave up trying to find a satisfying
+  /// assignment for a boolean formula.
+  TimedOut,
+};
+
+/// A boolean value is set to true or false in a truth assignment.
+enum class Assignment : uint8_t { AssignedFalse = 0, AssignedTrue = 1 };
+
+/// Constructs a result indicating that the queried boolean formula is
+/// satisfiable. The result will hold a solution found by the solver.
+static Result
+Satisfiable(llvm::DenseMap Solution) {
+  return Result(Status::Satisfiable, std::move(Solution));
+}
+
+/// Constructs a result indicating that the queried boolean formula is
+/// unsatisfiable.
+static Result Unsatisfiable() { return Result(Status::Unsatisfiable, {}); }
+
+/// Constructs a result indicating that satisfiability checking on the
+/// queried boolean formula was not completed.
+static Result TimedOut() { return Result(Status::TimedOut, {}); }
+
+/// Returns the status of satisfiability checking on the queried boolean
 /// formula.
-Satisfiable,
+Status getStatus() const { return Status; }
 
-/// Indicates that there is no satisfying ass

[PATCH] D129180: [clang][dataflow] Return a solution from the solver when `Constraints` are `Satisfiable`.

2022-07-07 Thread Dmitri Gribenko 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 rG19e21887eb18: [clang][dataflow] Return a solution from the 
solver when `Constraints` are… (authored by wyt, committed by gribozavr).

Changed prior to commit:
  https://reviews.llvm.org/D129180?vs=442874&id=443016#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129180

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
  clang/include/clang/Analysis/FlowSensitive/Solver.h
  clang/lib/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp
  clang/unittests/Analysis/FlowSensitive/SolverTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
@@ -20,6 +20,12 @@
 using namespace clang;
 using namespace dataflow;
 
+using testing::_;
+using testing::AnyOf;
+using testing::Optional;
+using testing::Pair;
+using testing::UnorderedElementsAre;
+
 class SolverTest : public ::testing::Test {
 protected:
   // Checks if the conjunction of `Vals` is satisfiable and returns the
@@ -64,6 +70,17 @@
 return conj(impl(LeftSubVal, RightSubVal), impl(RightSubVal, LeftSubVal));
   }
 
+  void expectUnsatisfiable(Solver::Result Result) {
+EXPECT_EQ(Result.getStatus(), Solver::Result::Status::Unsatisfiable);
+EXPECT_FALSE(Result.getSolution().has_value());
+  }
+
+  template 
+  void expectSatisfiable(Solver::Result Result, Matcher Solution) {
+EXPECT_EQ(Result.getStatus(), Solver::Result::Status::Satisfiable);
+EXPECT_THAT(Result.getSolution(), Optional(Solution));
+  }
+
 private:
   std::vector> Vals;
 };
@@ -72,7 +89,9 @@
   auto X = atom();
 
   // X
-  EXPECT_EQ(solve({X}), Solver::Result::Satisfiable);
+  expectSatisfiable(
+  solve({X}),
+  UnorderedElementsAre(Pair(X, Solver::Result::Assignment::AssignedTrue)));
 }
 
 TEST_F(SolverTest, NegatedVar) {
@@ -80,7 +99,9 @@
   auto NotX = neg(X);
 
   // !X
-  EXPECT_EQ(solve({NotX}), Solver::Result::Satisfiable);
+  expectSatisfiable(
+  solve({NotX}),
+  UnorderedElementsAre(Pair(X, Solver::Result::Assignment::AssignedFalse)));
 }
 
 TEST_F(SolverTest, UnitConflict) {
@@ -88,7 +109,7 @@
   auto NotX = neg(X);
 
   // X ^ !X
-  EXPECT_EQ(solve({X, NotX}), Solver::Result::Unsatisfiable);
+  expectUnsatisfiable(solve({X, NotX}));
 }
 
 TEST_F(SolverTest, DistinctVars) {
@@ -97,7 +118,10 @@
   auto NotY = neg(Y);
 
   // X ^ !Y
-  EXPECT_EQ(solve({X, NotY}), Solver::Result::Satisfiable);
+  expectSatisfiable(
+  solve({X, NotY}),
+  UnorderedElementsAre(Pair(X, Solver::Result::Assignment::AssignedTrue),
+   Pair(Y, Solver::Result::Assignment::AssignedFalse)));
 }
 
 TEST_F(SolverTest, DoubleNegation) {
@@ -106,7 +130,7 @@
   auto NotNotX = neg(NotX);
 
   // !!X ^ !X
-  EXPECT_EQ(solve({NotNotX, NotX}), Solver::Result::Unsatisfiable);
+  expectUnsatisfiable(solve({NotNotX, NotX}));
 }
 
 TEST_F(SolverTest, NegatedDisjunction) {
@@ -116,7 +140,7 @@
   auto NotXOrY = neg(XOrY);
 
   // !(X v Y) ^ (X v Y)
-  EXPECT_EQ(solve({NotXOrY, XOrY}), Solver::Result::Unsatisfiable);
+  expectUnsatisfiable(solve({NotXOrY, XOrY}));
 }
 
 TEST_F(SolverTest, NegatedConjunction) {
@@ -126,7 +150,7 @@
   auto NotXAndY = neg(XAndY);
 
   // !(X ^ Y) ^ (X ^ Y)
-  EXPECT_EQ(solve({NotXAndY, XAndY}), Solver::Result::Unsatisfiable);
+  expectUnsatisfiable(solve({NotXAndY, XAndY}));
 }
 
 TEST_F(SolverTest, DisjunctionSameVars) {
@@ -135,7 +159,7 @@
   auto XOrNotX = disj(X, NotX);
 
   // X v !X
-  EXPECT_EQ(solve({XOrNotX}), Solver::Result::Satisfiable);
+  expectSatisfiable(solve({XOrNotX}), _);
 }
 
 TEST_F(SolverTest, ConjunctionSameVarsConflict) {
@@ -144,7 +168,7 @@
   auto XAndNotX = conj(X, NotX);
 
   // X ^ !X
-  EXPECT_EQ(solve({XAndNotX}), Solver::Result::Unsatisfiable);
+  expectUnsatisfiable(solve({XAndNotX}));
 }
 
 TEST_F(SolverTest, PureVar) {
@@ -156,7 +180,10 @@
   auto NotXOrNotY = disj(NotX, NotY);
 
   // (!X v Y) ^ (!X v !Y)
-  EXPECT_EQ(solve({NotXOrY, NotXOrNotY}), Solver::Result::Satisfiable);
+  expectSatisfiable(
+  solve({NotXOrY, NotXOrNotY}),
+  UnorderedElementsAre(Pair(X, Solver::Result::Assignment::AssignedFalse),
+   Pair(Y, _)));
 }
 
 TEST_F(SolverTest, MustAssumeVarIsFalse) {
@@ -169,7 +196,10 @@
   auto NotXOrNotY = disj(NotX, NotY);
 
   // (X v Y) ^ (!X v Y) ^ (!X v !Y)
-  EXPECT_EQ(solve({XOrY, NotXOrY, NotXOrNotY}), Solver::Result::Satisfiable);
+  expectSatisfiable(
+  solve({XOrY, NotXOrY, NotXOrNotY}),
+  UnorderedElementsAre(Pair(X, Solver::Result::Assignment::AssignedFalse),
+   Pair(Y, Solver::Result::Assignment::AssignedTrue)));
 }
 
 TEST_F(SolverTest, DeepConflict) {
@@ 

[PATCH] D128372: [Clang-Tidy] Empty Check

2022-07-07 Thread Abraham Corea Diaz via Phabricator via cfe-commits
abrahamcd updated this revision to Diff 443017.
abrahamcd edited the summary of this revision.
abrahamcd added a comment.

Adds functionality for only warning on the case of unused return value
of the call to `empty()` and removes using-directive.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128372

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone/standalone-empty.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone/standalone-empty.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/standalone-empty.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/standalone-empty.cpp
@@ -0,0 +1,313 @@
+// RUN: %check_clang_tidy %s bugprone-standalone-empty %t
+
+namespace std {
+template 
+struct vector {
+  bool empty();
+};
+
+template 
+struct vector_with_clear {
+  bool empty();
+  void clear();
+};
+
+template 
+struct vector_with_void_empty {
+  void empty();
+  void clear();
+};
+
+template 
+struct vector_with_int_empty {
+  int empty();
+  void clear();
+};
+
+template 
+bool empty(T &&);
+
+} // namespace std
+
+namespace absl {
+struct string {
+  bool empty();
+};
+
+struct string_with_clear {
+  bool empty();
+  void clear();
+};
+
+struct string_with_void_empty {
+  void empty();
+  void clear();
+};
+
+struct string_with_int_empty {
+  int empty();
+  void clear();
+};
+
+template 
+bool empty(T &&);
+} // namespace absl
+
+namespace test {
+template 
+void empty(T &&);
+} // namespace test
+
+int test_member_empty() {
+  {
+std::vector v;
+
+v.empty();
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: ignoring the result of 'empty()' [bugprone-standalone-empty]
+  }
+
+  {
+std::vector_with_void_empty v;
+
+v.empty();
+// no-warning
+  }
+
+  {
+std::vector_with_clear v;
+
+v.empty();
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: ignoring the result of 'empty()', did you mean 'clear()'? [bugprone-standalone-empty]
+// CHECK-FIXES: {{^  }}  v.clear();{{$}}
+  }
+
+  {
+std::vector_with_int_empty v;
+
+v.empty();
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: ignoring the result of 'empty()', did you mean 'clear()'? [bugprone-standalone-empty]
+// CHECK-FIXES: {{^  }}  v.clear();{{$}}
+  }
+
+  {
+absl::string s;
+
+s.empty();
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: ignoring the result of 'empty()' [bugprone-standalone-empty]
+  }
+
+  {
+absl::string_with_void_empty s;
+
+s.empty();
+// no-warning
+  }
+
+  {
+absl::string_with_clear s;
+
+s.empty();
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: ignoring the result of 'empty()', did you mean 'clear()'? [bugprone-standalone-empty]
+// CHECK-FIXES: {{^  }}  s.clear();{{$}}
+  }
+
+  {
+absl::string_with_int_empty s;
+
+s.empty();
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: ignoring the result of 'empty()', did you mean 'clear()'? [bugprone-standalone-empty]
+// CHECK-FIXES: {{^  }}  s.clear();{{$}}
+  }
+}
+
+int test_qualified_empty() {
+  {
+absl::string_with_clear v;
+
+std::empty(v);
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: ignoring the result of 'std::empty', did you mean 'clear()'? [bugprone-standalone-empty]
+// CHECK-FIXES: {{^  }}  v.clear();{{$}}
+
+absl::empty(v);
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: ignoring the result of 'absl::empty', did you mean 'clear()'? [bugprone-standalone-empty]
+// CHECK-FIXES: {{^  }}  v.clear();{{$}}
+
+test::empty(v);
+// no-warning
+  }
+
+  {
+absl::string s;
+
+std::empty(s);
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: ignoring the result of 'std::empty' [bugprone-standalone-empty]
+  }
+}
+
+int test_unqualified_empty() {
+  {
+std::vector v;
+
+empty(v);
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: ignoring the result of 'std::empty' [bugprone-standalone-empty]
+  }
+
+  {
+std::vector_with_void_empty v;
+
+empty(v);
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: ignoring the result of 'std::empty', did you mean 'clear()'? [bugprone-standalone-empty]
+// CHECK-FIXES: {{^  }}  v.clear();{{$}}
+  }
+
+  {
+std::vector_with_clear v;
+
+empty(v);
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: ignoring the result of 'std::empty', did you mean 'clear()'? [bugprone-standalone-empty]
+// CHECK-FIXES: {{^  }}  v.clear();{{$}}
+  }
+
+  {
+std::vector_with_int_empty v;
+
+empty(v);
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: ignoring the result of 'std::empty', did

[PATCH] D128372: [Clang-Tidy] Empty Check

2022-07-07 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.cpp:146
+CXXRecordDecl *ArgRecordDecl = Arg->getType()->getAsCXXRecordDecl();
+if (ArgRecordDecl == NULL)
+  return;

`nullptr`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128372

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


[PATCH] D129277: [clang] [Serialization] Fix swapped PPOpts/ExistingPPOpts parameters. NFC.

2022-07-07 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D129277#3636596 , @mstorsjo wrote:

> In D129277#3636567 , @aaron.ballman 
> wrote:
>
>> Thanks for catching this! Is it really an NFC change though (it seems like 
>> it would change some of the diagnostic behavior and the list of suggested 
>> predefines)? Can you add test coverage for the change?
>
> TBH I haven’t tried to follow exactly where this case would matter in the 
> current state of affairs - the function is called in three places, and maybe 
> the individual roles of the parameters currently only make a difference in 
> the other callers. As it didn’t break any tests I presumed it’s NFC.

Heh, I presumed we just lacked test coverage. :-) But I also don't know enough 
about this interface to know exactly how to test it. I would imagine that this 
would be caught through using a PCH that was compiled with different 
preprocessor options than the code consuming the header. I'm not certain if 
`-D` or `-U` is sufficient to demonstrate the issue or not, but maybe 
`-fallow-editor-placeholders` and `-fno-allow-editor-placeholders` would work?

> Alternatively I can keep this change folded into D126676 
>  (although I’m not sure if the parameter 
> change will end up visible in the final form of that patch though, so maybe I 
> I might end up dropping the change from there too if it’s not testable there 
> either?).

I think the changes are good, so I'd like to see them go in. It's mostly that 
I'd like a regression test so we don't break this again.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129277

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


[PATCH] D128372: [Clang-Tidy] Empty Check

2022-07-07 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb added inline comments.



Comment at: clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.cpp:128
+  << FixItHint::CreateReplacement(ReplacementRange, "clear");
+} else {
+  diag(MemberLoc, "ignoring the result of 'empty()'");

Let's eliminate some of these else-clauses by using early exits.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128372

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


[PATCH] D119296: KCFI sanitizer

2022-07-07 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/lib/Driver/SanitizerArgs.cpp:63
 SanitizerKind::Unreachable | SanitizerKind::Return;
-static const SanitizerMask AlwaysRecoverable =
-SanitizerKind::KernelAddress | SanitizerKind::KernelHWAddress;
+static const SanitizerMask AlwaysRecoverable = SanitizerKind::KernelAddress |
+   SanitizerKind::KernelHWAddress |

samitolvanen wrote:
> MaskRay wrote:
> > This is incorrect.
> > 
> > If a violation is found, ud2 is executed. ud2 is not followed by normal 
> > control flow so I don't think recovery from the error is supported.
> > 
> > This seems like `Unrecoverable`
> This variable is only used to indicate whether `-fno-sanitize-recover` 
> command line parameter can be used with the sanitizer. It makes no sense to 
> allow this with KCFI as we always emit a recoverable instruction sequence, 
> hence it's included here.
> 
> Also, ud2 absolutely is recoverable in the kernel, and Linux specifically 
> uses ud2 to trigger warnings in assembly code.
ud2 being recoverable in the kernel is insufficient. The IR should consider 
this recoverable. In the presence of a failure, the control flow should be 
transferred as if no failure happens. E.g. for an asan out-of-bounds failure, 
the code should behave as if the failure is ignored.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119296

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


[PATCH] D126907: Deferred Concept Instantiation Implementation Take 2

2022-07-07 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

SO I've been playing with this for a while and all the libcxx issues. I THINK 
we really need to just bit the bullet and figure out how to correctly re-add 
things to the instantiation scope (after making the CheckFunctionConstraints 
LocalInstantiationScope 'false' for the 2nd param).  I can do it well enough 
with functions since we have a function for it, but likely need to do the same 
for at least RecordDecl.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126907

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


  1   2   >