[PATCH] D129534: [OpenMP] Do not link static library with `-nogpulib`

2022-07-12 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield accepted this revision.
JonChesterfield added a comment.
This revision is now accepted and ready to land.

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129534

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


[clang] d6d0dc1 - [clang-format] Add MacroUnexpander.

2022-07-12 Thread Manuel Klimek via cfe-commits

Author: Manuel Klimek
Date: 2022-07-12T07:11:46Z
New Revision: d6d0dc1f45377ddaf5c10a48d64b09308b71501a

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

LOG: [clang-format] Add MacroUnexpander.

MacroUnexpander applies the structural formatting of expanded lines into
UnwrappedLines to the corresponding unexpanded macro calls, resulting in
UnwrappedLines for the macro calls the user typed.

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

Added: 
clang/lib/Format/MacroCallReconstructor.cpp
clang/unittests/Format/MacroCallReconstructorTest.cpp

Modified: 
clang/lib/Format/CMakeLists.txt
clang/lib/Format/FormatToken.h
clang/lib/Format/Macros.h
clang/lib/Format/UnwrappedLineParser.h
clang/unittests/Format/CMakeLists.txt

Removed: 




diff  --git a/clang/lib/Format/CMakeLists.txt b/clang/lib/Format/CMakeLists.txt
index ca455157ae44a..4ea02ea72bc77 100644
--- a/clang/lib/Format/CMakeLists.txt
+++ b/clang/lib/Format/CMakeLists.txt
@@ -8,6 +8,7 @@ add_clang_library(clangFormat
   Format.cpp
   FormatToken.cpp
   FormatTokenLexer.cpp
+  MacroCallReconstructor.cpp
   MacroExpander.cpp
   NamespaceEndCommentsFixer.cpp
   QualifierAlignmentFixer.cpp

diff  --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index b6cc021affae3..73e32979853f5 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -497,6 +497,15 @@ struct FormatToken {
   // in a configured macro expansion.
   llvm::Optional MacroCtx;
 
+  /// When macro expansion introduces nodes with children, those are marked as
+  /// \c MacroParent.
+  /// FIXME: The formatting code currently hard-codes the assumption that
+  /// child nodes are introduced by blocks following an opening brace.
+  /// This is deeply baked into the code and disentangling this will require
+  /// signficant refactorings. \c MacroParent allows us to special-case the
+  /// cases in which we treat parents as block-openers for now.
+  bool MacroParent = false;
+
   bool is(tok::TokenKind Kind) const { return Tok.is(Kind); }
   bool is(TokenType TT) const { return getType() == TT; }
   bool is(const IdentifierInfo *II) const {

diff  --git a/clang/lib/Format/MacroCallReconstructor.cpp 
b/clang/lib/Format/MacroCallReconstructor.cpp
new file mode 100644
index 0..67711cc91d0b8
--- /dev/null
+++ b/clang/lib/Format/MacroCallReconstructor.cpp
@@ -0,0 +1,569 @@
+//===--- MacroCallReconstructor.cpp - Format C++ code ---*- C++ 
-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+///
+/// \file
+/// This file contains the implementation of MacroCallReconstructor, which fits
+/// an reconstructed macro call to a parsed set of UnwrappedLines.
+///
+//===--===//
+
+#include "Macros.h"
+
+#include "UnwrappedLineParser.h"
+#include "clang/Basic/TokenKinds.h"
+#include "llvm/ADT/DenseSet.h"
+#include "llvm/Support/Debug.h"
+#include 
+
+#define DEBUG_TYPE "format-reconstruct"
+
+namespace clang {
+namespace format {
+
+// Call \p Call for each token in the unwrapped line given, passing
+// the token, its parent and whether it is the first token in the line.
+template 
+void forEachToken(const UnwrappedLine &Line, const T &Call,
+  FormatToken *Parent = nullptr) {
+  bool First = true;
+  for (const auto &N : Line.Tokens) {
+Call(N.Tok, Parent, First);
+First = false;
+for (const auto &Child : N.Children) {
+  forEachToken(Child, Call, N.Tok);
+}
+  }
+}
+
+MacroCallReconstructor::MacroCallReconstructor(
+unsigned Level,
+const llvm::DenseMap>
+&ActiveExpansions)
+: Level(Level), IdToReconstructed(ActiveExpansions) {
+  Result.Tokens.push_back(std::make_unique());
+  ActiveReconstructedLines.push_back(&Result);
+}
+
+void MacroCallReconstructor::addLine(const UnwrappedLine &Line) {
+  assert(State != Finalized);
+  LLVM_DEBUG(llvm::dbgs() << "MCR: new line...\n");
+  forEachToken(Line, [&](FormatToken *Token, FormatToken *Parent, bool First) {
+add(Token, Parent, First);
+  });
+  assert(InProgress || finished());
+}
+
+UnwrappedLine MacroCallReconstructor::takeResult() && {
+  finalize();
+  assert(Result.Tokens.size() == 1 && Result.Tokens.front()->Children.size() 
== 1);
+  UnwrappedLine Final =
+  createUnwrappedLine(*Result.Tokens.front()->Children.front(), Level);
+  assert(!Final.Tokens.empty());
+  return Final;
+}
+
+// Reconstruct the position of the next \p Token, given its parent \p
+// ExpandedParent in the incoming u

[PATCH] D88299: [clang-format] Add MacroUnexpander.

2022-07-12 Thread Manuel Klimek 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 rGd6d0dc1f4537: [clang-format] Add MacroUnexpander. (authored 
by klimek).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88299

Files:
  clang/lib/Format/CMakeLists.txt
  clang/lib/Format/FormatToken.h
  clang/lib/Format/MacroCallReconstructor.cpp
  clang/lib/Format/Macros.h
  clang/lib/Format/UnwrappedLineParser.h
  clang/unittests/Format/CMakeLists.txt
  clang/unittests/Format/MacroCallReconstructorTest.cpp

Index: clang/unittests/Format/MacroCallReconstructorTest.cpp
===
--- /dev/null
+++ clang/unittests/Format/MacroCallReconstructorTest.cpp
@@ -0,0 +1,688 @@
+#include "../../lib/Format/Macros.h"
+#include "../../lib/Format/UnwrappedLineParser.h"
+#include "TestLexer.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
+
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+#include 
+
+namespace clang {
+namespace format {
+namespace {
+
+using UnexpandedMap =
+llvm::DenseMap>;
+
+// Keeps track of a sequence of macro expansions.
+//
+// The expanded tokens are accessible via getTokens(), while a map of macro call
+// identifier token to unexpanded token stream is accessible via
+// getUnexpanded().
+class Expansion {
+public:
+  Expansion(TestLexer &Lex, MacroExpander &Macros) : Lex(Lex), Macros(Macros) {}
+
+  // Appends the token stream obtained from expanding the macro Name given
+  // the provided arguments, to be later retrieved with getTokens().
+  // Returns the list of tokens making up the unexpanded macro call.
+  TokenList
+  expand(llvm::StringRef Name,
+ const SmallVector, 1> &Args) {
+auto *ID = Lex.id(Name);
+auto UnexpandedLine = std::make_unique();
+UnexpandedLine->Tokens.push_back(ID);
+if (!Args.empty()) {
+  UnexpandedLine->Tokens.push_back(Lex.id("("));
+  for (auto I = Args.begin(), E = Args.end(); I != E; ++I) {
+if (I != Args.begin())
+  UnexpandedLine->Tokens.push_back(Lex.id(","));
+UnexpandedLine->Tokens.insert(UnexpandedLine->Tokens.end(), I->begin(),
+  I->end());
+  }
+  UnexpandedLine->Tokens.push_back(Lex.id(")"));
+}
+Unexpanded[ID] = std::move(UnexpandedLine);
+
+auto Expanded = uneof(Macros.expand(ID, Args));
+Tokens.append(Expanded.begin(), Expanded.end());
+
+TokenList UnexpandedTokens;
+for (const UnwrappedLineNode &Node : Unexpanded[ID]->Tokens) {
+  UnexpandedTokens.push_back(Node.Tok);
+}
+return UnexpandedTokens;
+  }
+
+  TokenList expand(llvm::StringRef Name,
+   const std::vector &Args = {}) {
+return expand(Name, lexArgs(Args));
+  }
+
+  const UnexpandedMap &getUnexpanded() const { return Unexpanded; }
+
+  const TokenList &getTokens() const { return Tokens; }
+
+private:
+  llvm::SmallVector
+  lexArgs(const std::vector &Args) {
+llvm::SmallVector Result;
+for (const auto &Arg : Args) {
+  Result.push_back(uneof(Lex.lex(Arg)));
+}
+return Result;
+  }
+  llvm::DenseMap> Unexpanded;
+  llvm::SmallVector Tokens;
+  TestLexer &Lex;
+  MacroExpander &Macros;
+};
+
+struct Chunk {
+  Chunk(llvm::ArrayRef Tokens)
+  : Tokens(Tokens.begin(), Tokens.end()) {}
+  Chunk(llvm::ArrayRef Children)
+  : Children(Children.begin(), Children.end()) {}
+  llvm::SmallVector Tokens;
+  llvm::SmallVector Children;
+};
+
+bool tokenMatches(const FormatToken *Left, const FormatToken *Right) {
+  if (Left->getType() == Right->getType() &&
+  Left->TokenText == Right->TokenText)
+return true;
+  llvm::dbgs() << Left->TokenText << " != " << Right->TokenText << "\n";
+  return false;
+}
+
+// Allows to produce chunks of a token list by typing the code of equal tokens.
+//
+// Created from a list of tokens, users call "consume" to get the next chunk
+// of tokens, checking that they match the written code.
+struct Matcher {
+  Matcher(const TokenList &Tokens, TestLexer &Lex)
+  : Tokens(Tokens), It(this->Tokens.begin()), Lex(Lex) {}
+
+  Chunk consume(StringRef Tokens) {
+TokenList Result;
+for (const FormatToken *Token : uneof(Lex.lex(Tokens))) {
+  assert(tokenMatches(*It, Token));
+  Result.push_back(*It);
+  ++It;
+}
+return Chunk(Result);
+  }
+
+  TokenList Tokens;
+  TokenList::iterator It;
+  TestLexer &Lex;
+};
+
+UnexpandedMap mergeUnexpanded(const UnexpandedMap &M1,
+  const UnexpandedMap &M2) {
+  UnexpandedMap Result;
+  for (const auto &KV : M1) {
+Result[KV.first] = std::make_unique(*KV.second);
+  }
+  for (const auto &KV : M2) {
+Result[KV.first] = std::make_unique(*KV.second);
+  }
+  return Result;
+}
+
+class MacroCallReconstructorTest : publi

[clang] f44d28f - Fix build errors.

2022-07-12 Thread Manuel Klimek via cfe-commits

Author: Manuel Klimek
Date: 2022-07-12T07:43:26Z
New Revision: f44d28f840c0b0877b09d5547fd09e191bbdc90e

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

LOG: Fix build errors.

Added: 


Modified: 
clang/lib/Format/MacroCallReconstructor.cpp
clang/lib/Format/Macros.h

Removed: 




diff  --git a/clang/lib/Format/MacroCallReconstructor.cpp 
b/clang/lib/Format/MacroCallReconstructor.cpp
index 67711cc91d0b8..ccff183cf0da1 100644
--- a/clang/lib/Format/MacroCallReconstructor.cpp
+++ b/clang/lib/Format/MacroCallReconstructor.cpp
@@ -98,7 +98,7 @@ void MacroCallReconstructor::add(FormatToken *Token,
   if (!ActiveExpansions.empty() && Token->MacroCtx &&
   (Token->MacroCtx->Role != MR_Hidden ||
ActiveExpansions.size() != Token->MacroCtx->ExpandedFrom.size())) {
-if (bool PassedMacroComma = reconstructActiveCallUntil(Token))
+if (/*PassedMacroComma = */ reconstructActiveCallUntil(Token))
   First = true;
   }
 
@@ -172,7 +172,7 @@ void MacroCallReconstructor::prepareParent(FormatToken 
*ExpandedParent,
 }
 assert(!ActiveReconstructedLines.empty());
 ActiveReconstructedLines.back()->Tokens.back()->Children.push_back(
-std::make_unique());
+std::make_unique());
 ActiveReconstructedLines.push_back(
 &*ActiveReconstructedLines.back()->Tokens.back()->Children.back());
   } else if (parentLine().Tokens.back()->Tok != Parent) {
@@ -498,14 +498,16 @@ void MacroCallReconstructor::finalize() {
   Top.Children.resize(1);
 }
 
-void MacroCallReconstructor::appendToken(FormatToken *Token, Line *L) {
+void MacroCallReconstructor::appendToken(FormatToken *Token,
+ ReconstructedLine *L) {
   L = L ? L : currentLine();
   LLVM_DEBUG(llvm::dbgs() << "-> " << Token->TokenText << "\n");
   L->Tokens.push_back(std::make_unique(Token));
 }
 
-UnwrappedLine MacroCallReconstructor::createUnwrappedLine(const Line &Line,
-  int Level) {
+UnwrappedLine
+MacroCallReconstructor::createUnwrappedLine(const ReconstructedLine &Line,
+int Level) {
   UnwrappedLine Result;
   Result.Level = Level;
   for (const auto &N : Line.Tokens) {
@@ -526,7 +528,7 @@ UnwrappedLine 
MacroCallReconstructor::createUnwrappedLine(const Line &Line,
   return Result;
 }
 
-void MacroCallReconstructor::debug(const Line &Line, int Level) {
+void MacroCallReconstructor::debug(const ReconstructedLine &Line, int Level) {
   for (int i = 0; i < Level; ++i)
 llvm::dbgs() << " ";
   for (const auto &N : Line.Tokens) {
@@ -544,17 +546,19 @@ void MacroCallReconstructor::debug(const Line &Line, int 
Level) {
   llvm::dbgs() << "\n";
 }
 
-MacroCallReconstructor::Line &MacroCallReconstructor::parentLine() {
+MacroCallReconstructor::ReconstructedLine &
+MacroCallReconstructor::parentLine() {
   return **std::prev(std::prev(ActiveReconstructedLines.end()));
 }
 
-MacroCallReconstructor::Line *MacroCallReconstructor::currentLine() {
+MacroCallReconstructor::ReconstructedLine *
+MacroCallReconstructor::currentLine() {
   return ActiveReconstructedLines.back();
 }
 
 MacroCallReconstructor::MacroCallState::MacroCallState(
-MacroCallReconstructor::Line *Line, FormatToken *ParentLastToken,
-FormatToken *MacroCallLParen)
+MacroCallReconstructor::ReconstructedLine *Line,
+FormatToken *ParentLastToken, FormatToken *MacroCallLParen)
 : Line(Line), ParentLastToken(ParentLastToken),
   MacroCallLParen(MacroCallLParen) {
   LLVM_DEBUG(

diff  --git a/clang/lib/Format/Macros.h b/clang/lib/Format/Macros.h
index 59774647a5694..ded792c628701 100644
--- a/clang/lib/Format/Macros.h
+++ b/clang/lib/Format/Macros.h
@@ -234,13 +234,13 @@ class MacroCallReconstructor {
   bool processNextReconstructed();
   void finalize();
 
-  struct Line;
+  struct ReconstructedLine;
 
-  void appendToken(FormatToken *Token, Line *L = nullptr);
-  UnwrappedLine createUnwrappedLine(const Line &Line, int Level);
-  void debug(const Line &Line, int Level);
-  Line &parentLine();
-  Line *currentLine();
+  void appendToken(FormatToken *Token, ReconstructedLine *L = nullptr);
+  UnwrappedLine createUnwrappedLine(const ReconstructedLine &Line, int Level);
+  void debug(const ReconstructedLine &Line, int Level);
+  ReconstructedLine &parentLine();
+  ReconstructedLine *currentLine();
   void debugParentMap() const;
 
 #ifndef NDEBUG
@@ -258,13 +258,13 @@ class MacroCallReconstructor {
 LineNode() = default;
 LineNode(FormatToken *Tok) : Tok(Tok) {}
 FormatToken *Tok = nullptr;
-llvm::SmallVector> Children;
+llvm::SmallVector> Children;
   };
 
   // Line in which we build up the resulting unwrapped line.
   // FIXME: Investigate changing Unw

[PATCH] D128830: [Pipelines] Introduce DAE after ArgumentPromotion

2022-07-12 Thread Pavel Samolysov via Phabricator via cfe-commits
psamolysov added a comment.

@aeubanks Hmm, if I correctly get your comment, I should revert this patch to 
the state before the proposed solution with moving the 
`PostOrderFunctionAttrsPass` at the end of the `buildInlinerPipeline` function 
regardless of the `readonly` instead of `readnone` regression. Personally along 
with your concern about compilation time, I have a concern about some changing 
in coroutines compilation, the `Clang :: CodeGenCoroutines/coro-elide.cpp` test 
demonstrates them:

  // CHECK-NOT: %_Z5task1v.Frame = type {{.*}}%_Z5task0v.Frame

instead of

  // CHECK: %_Z5task1v.Frame = type {{.*}}%_Z5task0v.Frame

I've reverted the latest changes because they require more investigation and, 
as you said, should be introduced in a separate patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128830

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


[PATCH] D128830: [Pipelines] Introduce DAE after ArgumentPromotion

2022-07-12 Thread Pavel Samolysov via Phabricator via cfe-commits
psamolysov updated this revision to Diff 443860.
psamolysov added a comment.

Return the `PostOrderFunctionAttrsPass` pass back on its original place in the 
pipeline.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128830

Files:
  clang/test/CodeGen/thinlto-distributed-newpm.ll
  llvm/lib/Passes/PassBuilderPipelines.cpp
  llvm/test/Other/new-pm-defaults.ll
  llvm/test/Other/new-pm-lto-defaults.ll
  llvm/test/Other/new-pm-thinlto-defaults.ll
  llvm/test/Other/new-pm-thinlto-postlink-pgo-defaults.ll
  llvm/test/Other/new-pm-thinlto-postlink-samplepgo-defaults.ll
  llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll
  llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll
  llvm/test/Transforms/InstCombine/unused-nonnull.ll
  llvm/test/Transforms/PhaseOrdering/dce-after-argument-promotion.ll

Index: llvm/test/Transforms/PhaseOrdering/dce-after-argument-promotion.ll
===
--- llvm/test/Transforms/PhaseOrdering/dce-after-argument-promotion.ll
+++ llvm/test/Transforms/PhaseOrdering/dce-after-argument-promotion.ll
@@ -9,7 +9,7 @@
 
 define internal void @f(%struct.ss* byval(%struct.ss) align 8 %b, i32* byval(i32) align 4 %X) noinline nounwind  {
 ; CHECK-LABEL: define {{[^@]+}}@f
-; CHECK-SAME: (i32 [[B_0:%.*]], i32 [[X:%.*]]){{[^#]*}} #[[ATTR0:[0-9]+]] {
+; CHECK-SAME: (i32 [[B_0:%.*]]){{[^#]*}} #[[ATTR0:[0-9]+]] {
 ; CHECK-NEXT:  entry:
 ; CHECK-NEXT:[[TEMP:%.*]] = add i32 [[B_0]], 1
 ; CHECK-NEXT:store i32 [[TEMP]], i32* [[DUMMY]], align 4
@@ -28,8 +28,7 @@
 ; CHECK-LABEL: define {{[^@]+}}@test
 ; CHECK-SAME: (i32* {{[^%]*}} [[X:%.*]]){{[^#]*}} #[[ATTR1:[0-9]+]] {
 ; CHECK-NEXT:  entry:
-; CHECK-NEXT:[[X_VAL:%.*]] = load i32, i32* [[X]], align 4
-; CHECK-NEXT:tail call {{.*}}void @f(i32 1, i32 [[X_VAL]])
+; CHECK-NEXT:tail call {{.*}}void @f(i32 1)
 ; CHECK-NEXT:ret i32 0
 ;
 entry:
Index: llvm/test/Transforms/InstCombine/unused-nonnull.ll
===
--- llvm/test/Transforms/InstCombine/unused-nonnull.ll
+++ llvm/test/Transforms/InstCombine/unused-nonnull.ll
@@ -9,7 +9,7 @@
 
 define i32 @main(i32 %argc, i8** %argv) #0 {
 ; CHECK-LABEL: define {{[^@]+}}@main
-; CHECK-SAME: (i32 [[ARGC:%.*]], i8** nocapture readnone [[ARGV:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+; CHECK-SAME: (i32 [[ARGC:%.*]], i8** nocapture readonly [[ARGV:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
 ; CHECK-NEXT:  entry:
 ; CHECK-NEXT:[[TMP0:%.*]] = icmp slt i32 [[ARGC]], 2
 ; CHECK-NEXT:[[SPEC_SELECT:%.*]] = select i1 [[TMP0]], i32 0, i32 [[ARGC]]
@@ -37,7 +37,8 @@
 
 define i32 @compute(i8* noundef nonnull %ptr, i32 %x) #1 {
 ; CHECK-LABEL: define {{[^@]+}}@compute
-; CHECK-SAME: (i8* nocapture nonnull readnone [[PTR:%.*]], i32 returned [[X:%.*]]) local_unnamed_addr #[[ATTR1:[0-9]+]] {
+; CHECK-SAME: (i8* nocapture noundef nonnull readnone [[PTR:%.*]], i32 returned [[X:%.*]])
+; CHECK-SAME:  local_unnamed_addr #[[ATTR1:[0-9]+]] {
 ; CHECK-NEXT:ret i32 [[X]]
 ;
   ret i32 %x
Index: llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll
===
--- llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll
+++ llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll
@@ -58,7 +58,6 @@
 ; CHECK-O-NEXT: Running pass: CalledValuePropagationPass
 ; CHECK-O-NEXT: Running pass: GlobalOptPass
 ; CHECK-O-NEXT: Running pass: PromotePass
-; CHECK-O-NEXT: Running pass: DeadArgumentEliminationPass
 ; CHECK-O-NEXT: Running pass: InstCombinePass
 ; CHECK-O-NEXT: Running analysis: BlockFrequencyAnalysis on foo
 ; These next two can appear in any order since they are accessed as parameters
@@ -162,6 +161,7 @@
 ; CHECK-O3-NEXT: Running analysis: DominanceFrontierAnalysis on foo
 ; CHECK-O-NEXT: Running pass: CoroSplitPass
 ; CHECK-O-NEXT: Invalidating analysis: InlineAdvisorAnalysis
+; CHECK-O-NEXT: Running pass: DeadArgumentEliminationPass
 ; CHECK-O-NEXT: Running pass: CoroCleanupPass
 ; CHECK-O-NEXT: Running pass: GlobalOptPass
 ; CHECK-O-NEXT: Running pass: AnnotationRemarksPass on foo
Index: llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll
===
--- llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll
+++ llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll
@@ -48,7 +48,6 @@
 ; CHECK-O-NEXT: Running pass: CalledValuePropagationPass
 ; CHECK-O-NEXT: Running pass: GlobalOptPass
 ; CHECK-O-NEXT: Running pass: PromotePass
-; CHECK-O-NEXT: Running pass: DeadArgumentEliminationPass
 ; CHECK-O-NEXT: Running pass: InstCombinePass
 ; CHECK-O-NEXT: Running analysis: OptimizationRemarkEmitterAnalysis
 ; CHECK-O-NEXT: Running analysis: AAManager
@@ -197,6 +196,7 @@
 ; CHECK-O3-NEXT: Running analysis: DominanceFrontierAnalysis on foo
 ; CHECK-O-NEXT: Running pass: CoroS

[PATCH] D129546: [clang][dataflow] Refactor boolean creation as a test utility.

2022-07-12 Thread weiyi via Phabricator via cfe-commits
wyt created this revision.
Herald added subscribers: martong, tschuett, xazax.hun.
Herald added a project: All.
wyt requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129546

Files:
  clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
  clang/unittests/Analysis/FlowSensitive/TestingSupport.h

Index: clang/unittests/Analysis/FlowSensitive/TestingSupport.h
===
--- clang/unittests/Analysis/FlowSensitive/TestingSupport.h
+++ clang/unittests/Analysis/FlowSensitive/TestingSupport.h
@@ -220,6 +220,49 @@
 ///  `Name` must be unique in `ASTCtx`.
 const ValueDecl *findValueDecl(ASTContext &ASTCtx, llvm::StringRef Name);
 
+/// Utility class for creating boolean values.
+class BoolValueManager {
+public:
+  // Creates an atomic boolean value.
+  BoolValue *atom() {
+Vals.push_back(std::make_unique());
+return Vals.back().get();
+  }
+
+  // Creates a boolean conjunction value.
+  BoolValue *conj(BoolValue *LeftSubVal, BoolValue *RightSubVal) {
+Vals.push_back(
+std::make_unique(*LeftSubVal, *RightSubVal));
+return Vals.back().get();
+  }
+
+  // Creates a boolean disjunction value.
+  BoolValue *disj(BoolValue *LeftSubVal, BoolValue *RightSubVal) {
+Vals.push_back(
+std::make_unique(*LeftSubVal, *RightSubVal));
+return Vals.back().get();
+  }
+
+  // Creates a boolean negation value.
+  BoolValue *neg(BoolValue *SubVal) {
+Vals.push_back(std::make_unique(*SubVal));
+return Vals.back().get();
+  }
+
+  // Creates a boolean implication value.
+  BoolValue *impl(BoolValue *LeftSubVal, BoolValue *RightSubVal) {
+return disj(neg(LeftSubVal), RightSubVal);
+  }
+
+  // Creates a boolean biconditional value.
+  BoolValue *iff(BoolValue *LeftSubVal, BoolValue *RightSubVal) {
+return conj(impl(LeftSubVal, RightSubVal), impl(RightSubVal, LeftSubVal));
+  }
+
+private:
+  std::vector> Vals;
+};
+
 } // namespace test
 } // namespace dataflow
 } // namespace clang
Index: clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "clang/Analysis/FlowSensitive/Solver.h"
+#include "TestingSupport.h"
 #include "clang/Analysis/FlowSensitive/Value.h"
 #include "clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h"
 #include "gmock/gmock.h"
@@ -34,42 +35,6 @@
 return WatchedLiteralsSolver().solve(std::move(Vals));
   }
 
-  // Creates an atomic boolean value.
-  BoolValue *atom() {
-Vals.push_back(std::make_unique());
-return Vals.back().get();
-  }
-
-  // Creates a boolean conjunction value.
-  BoolValue *conj(BoolValue *LeftSubVal, BoolValue *RightSubVal) {
-Vals.push_back(
-std::make_unique(*LeftSubVal, *RightSubVal));
-return Vals.back().get();
-  }
-
-  // Creates a boolean disjunction value.
-  BoolValue *disj(BoolValue *LeftSubVal, BoolValue *RightSubVal) {
-Vals.push_back(
-std::make_unique(*LeftSubVal, *RightSubVal));
-return Vals.back().get();
-  }
-
-  // Creates a boolean negation value.
-  BoolValue *neg(BoolValue *SubVal) {
-Vals.push_back(std::make_unique(*SubVal));
-return Vals.back().get();
-  }
-
-  // Creates a boolean implication value.
-  BoolValue *impl(BoolValue *LeftSubVal, BoolValue *RightSubVal) {
-return disj(neg(LeftSubVal), RightSubVal);
-  }
-
-  // Creates a boolean biconditional value.
-  BoolValue *iff(BoolValue *LeftSubVal, BoolValue *RightSubVal) {
-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());
@@ -81,12 +46,11 @@
 EXPECT_THAT(Result.getSolution(), Optional(Solution));
   }
 
-private:
-  std::vector> Vals;
+  test::BoolValueManager Bools;
 };
 
 TEST_F(SolverTest, Var) {
-  auto X = atom();
+  auto X = Bools.atom();
 
   // X
   expectSatisfiable(
@@ -95,8 +59,8 @@
 }
 
 TEST_F(SolverTest, NegatedVar) {
-  auto X = atom();
-  auto NotX = neg(X);
+  auto X = Bools.atom();
+  auto NotX = Bools.neg(X);
 
   // !X
   expectSatisfiable(
@@ -105,17 +69,17 @@
 }
 
 TEST_F(SolverTest, UnitConflict) {
-  auto X = atom();
-  auto NotX = neg(X);
+  auto X = Bools.atom();
+  auto NotX = Bools.neg(X);
 
   // X ^ !X
   expectUnsatisfiable(solve({X, NotX}));
 }
 
 TEST_F(SolverTest, DistinctVars) {
-  auto X = atom();
-  auto Y = atom();
-  auto NotY = neg(Y);
+  auto X = Bools.atom();
+  auto Y = Bools.atom();
+  auto NotY = Bools.neg(Y);
 
   // X ^ !Y
   expectSatisfiable(
@@ -125,59 +89,59 @@
 }
 
 TEST_F(Solve

[PATCH] D129547: [clang][dataflow] Generate readable form of boolean values.

2022-07-12 Thread weiyi via Phabricator via cfe-commits
wyt created this revision.
Herald added subscribers: martong, tschuett, xazax.hun, mgorny.
Herald added a reviewer: NoQ.
Herald added a project: All.
wyt requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

Depends On D129546 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129547

Files:
  clang/docs/tools/clang-formatted-files.txt
  clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
  clang/lib/Analysis/FlowSensitive/CMakeLists.txt
  clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
  clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
  llvm/utils/gn/secondary/clang/lib/Analysis/FlowSensitive/BUILD.gn

Index: llvm/utils/gn/secondary/clang/lib/Analysis/FlowSensitive/BUILD.gn
===
--- llvm/utils/gn/secondary/clang/lib/Analysis/FlowSensitive/BUILD.gn
+++ llvm/utils/gn/secondary/clang/lib/Analysis/FlowSensitive/BUILD.gn
@@ -12,5 +12,6 @@
 "Transfer.cpp",
 "TypeErasedDataflowAnalysis.cpp",
 "WatchedLiteralsSolver.cpp",
+"DebugSupport.cpp",
   ]
 }
Index: clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
===
--- /dev/null
+++ clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
@@ -0,0 +1,188 @@
+//===- unittests/Analysis/FlowSensitive/DebugSupportTest.cpp --===//
+//
+// 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
+//
+//===--===//
+
+#include "clang/Analysis/FlowSensitive/DebugSupport.h"
+#include "TestingSupport.h"
+#include "clang/Analysis/FlowSensitive/Value.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+namespace {
+
+using namespace clang;
+using namespace dataflow;
+using testing::StrEq;
+
+class BoolValueDebugStringTest : public ::testing::Test {
+protected:
+  test::BoolValueManager Bools;
+};
+
+TEST_F(BoolValueDebugStringTest, AtomicBoolean) {
+  // B0
+  auto B = Bools.atom();
+
+  auto Expected = R"((B0))";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST_F(BoolValueDebugStringTest, Negation) {
+  // !B0
+  auto B = Bools.neg(Bools.atom());
+
+  auto Expected = R"((not
+(B0)))";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST_F(BoolValueDebugStringTest, Conjunction) {
+  // B0 ^ B1
+  auto B = Bools.conj(Bools.atom(), Bools.atom());
+
+  auto Expected = R"((and
+(B0)
+(B1)))";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST_F(BoolValueDebugStringTest, Disjunction) {
+  // B0 v B1
+  auto B = Bools.disj(Bools.atom(), Bools.atom());
+
+  auto Expected = R"((or
+(B0)
+(B1)))";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST_F(BoolValueDebugStringTest, Implication) {
+  // B0 => B1, implemented as !B0 v B1
+  auto B = Bools.disj(Bools.neg(Bools.atom()), Bools.atom());
+
+  auto Expected = R"((or
+(not
+(B0))
+(B1)))";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST_F(BoolValueDebugStringTest, Iff) {
+  // B0 <=> B1, implemented as (!B0 v B1) ^ (B0 v !B1)
+  auto B0 = Bools.atom();
+  auto B1 = Bools.atom();
+  auto B =
+  Bools.conj(Bools.disj(Bools.neg(B0), B1), Bools.disj(B0, Bools.neg(B1)));
+
+  auto Expected = R"((and
+(or
+(not
+(B0))
+(B1))
+(or
+(B0)
+(not
+(B1)";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST_F(BoolValueDebugStringTest, Xor) {
+  // (B0 ^ !B1) V (!B0 ^ B1)
+  auto B0 = Bools.atom();
+  auto B1 = Bools.atom();
+  auto B =
+  Bools.disj(Bools.conj(B0, Bools.neg(B1)), Bools.conj(Bools.neg(B0), B1));
+
+  auto Expected = R"((or
+(and
+(B0)
+(not
+(B1)))
+(and
+(not
+(B0))
+(B1";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST_F(BoolValueDebugStringTest, NestedBoolean) {
+  // B0 ^ (B1 v (B2 ^ (B3 v B4)))
+  auto B = Bools.conj(
+  Bools.atom(),
+  Bools.disj(
+  Bools.atom(),
+  Bools.conj(Bools.atom(), Bools.disj(Bools.atom(), Bools.atom();
+
+  auto Expected = R"((and
+(B0)
+(or
+(B1)
+(and
+(B2)
+(or
+(B3)
+(B4))";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST_F(BoolValueDebugStringTest, AtomicBooleanWithName) {
+  // True
+  llvm::StringMap NamedBools;
+  auto True = cast(Bools.atom());
+  auto B = True;
+
+  auto Expected = R"((True))";
+  EXPECT_THAT(debugString(*B, {{True, "True"}}), StrEq(Expected));
+}
+
+TEST_F(BoolValueDebugStringTest, ComplexBooleanWithNames) {
+  // (Cond ^ Then ^ !Else) v (!Cond ^ !Then ^ Else)
+  auto Cond = cast(Bools.

[PATCH] D129548: [clang][dataflow] Generate readable form of input and output of satisfiability checking.

2022-07-12 Thread weiyi via Phabricator via cfe-commits
wyt created this revision.
Herald added subscribers: martong, tschuett, mgrang, xazax.hun.
Herald added a reviewer: NoQ.
Herald added a project: All.
wyt requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Depends On D129547 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129548

Files:
  clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
  clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
  clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
@@ -9,6 +9,7 @@
 #include "clang/Analysis/FlowSensitive/DebugSupport.h"
 #include "TestingSupport.h"
 #include "clang/Analysis/FlowSensitive/Value.h"
+#include "clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
@@ -185,4 +186,267 @@
   StrEq(Expected));
 }
 
+class SATCheckDebugStringTest : public ::testing::Test {
+protected:
+  Solver::Result CheckSAT(llvm::DenseSet Constraints) {
+return WatchedLiteralsSolver().solve(std::move(Constraints));
+  }
+  test::BoolValueManager Bools;
+};
+
+TEST_F(SATCheckDebugStringTest, AtomicBoolean) {
+  // B0
+  llvm::DenseSet Constraints({Bools.atom()});
+  auto Result = CheckSAT(Constraints);
+
+  auto Expected = R"(
+Constraints
+
+(B0)
+
+Satisfiable.
++--+---+
+| Atom | Value |
++--+---+
+| B0   | True  |
++--+---+
+)";
+  EXPECT_THAT(debugString(Constraints, Result), StrEq(Expected));
+}
+
+TEST_F(SATCheckDebugStringTest, AtomicBooleanAndNegation) {
+  // B0, !B0
+  auto B0 = Bools.atom();
+  llvm::DenseSet Constraints({B0, Bools.neg(B0)});
+  auto Result = CheckSAT(Constraints);
+
+  auto Expected = R"(
+Constraints
+
+(B0)
+
+(not
+(B0))
+
+Unsatisfiable.
+)";
+  EXPECT_THAT(debugString(Constraints, Result), StrEq(Expected));
+}
+
+TEST_F(SATCheckDebugStringTest, MultipleAtomicBooleans) {
+  // B0, B1
+  llvm::DenseSet Constraints({Bools.atom(), Bools.atom()});
+  auto Result = CheckSAT(Constraints);
+
+  auto Expected = R"(
+Constraints
+
+(B0)
+
+(B1)
+
+Satisfiable.
++--+---+
+| Atom | Value |
++--+---+
+| B0   | True  |
++--+---+
+| B1   | True  |
++--+---+
+)";
+  EXPECT_THAT(debugString(Constraints, Result), StrEq(Expected));
+}
+
+TEST_F(SATCheckDebugStringTest, Implication) {
+  // B0, B0 => B1
+  auto B0 = Bools.atom();
+  auto B1 = Bools.atom();
+  auto Impl = Bools.disj(Bools.neg(B0), B1);
+  llvm::DenseSet Constraints({B0, Impl});
+  auto Result = CheckSAT(Constraints);
+
+  auto Expected = R"(
+Constraints
+
+(B0)
+
+(or
+(not
+(B0))
+(B1))
+
+Satisfiable.
++--+---+
+| Atom | Value |
++--+---+
+| B0   | True  |
++--+---+
+| B1   | True  |
++--+---+
+)";
+  EXPECT_THAT(debugString(Constraints, Result), StrEq(Expected));
+}
+
+TEST_F(SATCheckDebugStringTest, Iff) {
+  // B0, B0 <=> B1
+  auto B0 = Bools.atom();
+  auto B1 = Bools.atom();
+  auto Iff =
+  Bools.conj(Bools.disj(Bools.neg(B0), B1), Bools.disj(B0, Bools.neg(B1)));
+  llvm::DenseSet Constraints({B0, Iff});
+  auto Result = CheckSAT(Constraints);
+
+  auto Expected = R"(
+Constraints
+
+(B0)
+
+(and
+(or
+(not
+(B0))
+(B1))
+(or
+(B0)
+(not
+(B1
+
+Satisfiable.
++--+---+
+| Atom | Value |
++--+---+
+| B0   | True  |
++--+---+
+| B1   | True  |
++--+---+
+)";
+  EXPECT_THAT(debugString(Constraints, Result), StrEq(Expected));
+}
+
+TEST_F(SATCheckDebugStringTest, Xor) {
+  // B0, XOR(B0, B1)
+  auto B0 = Bools.atom();
+  auto B1 = Bools.atom();
+  auto XOR =
+  Bools.disj(Bools.conj(B0, Bools.neg(B1)), Bools.conj(Bools.neg(B0), B1));
+  llvm::DenseSet Constraints({B0, XOR});
+  auto Result = CheckSAT(Constraints);
+
+  auto Expected = R"(
+Constraints
+
+(B0)
+
+(or
+(and
+(B0)
+(not
+(B1)))
+(and
+(not
+(B0))
+(B1)))
+
+Satisfiable.
++--+---+
+| Atom | Value |
++--+---+
+| B0   | True  |
++--+---+
+| B1   | False |
++--+---+
+)";
+  EXPECT_THAT(debugString(Constraints, Result), StrEq(Expected));
+}
+
+TEST_F(SATCheckDebugStringTest, ComplexBooleanWithNames) {
+  // Cond, (Cond ^ Then ^ !Else) v (!Cond ^ !Then ^ Else)
+  auto Cond = cast(Bools.atom());
+  auto Then = cast(Bools.atom());
+  auto Else = cast(Bools.atom());
+  auto B = Bools.disj(
+  Bools.conj(Cond, Bools.conj(Then, Bools.neg(Else))),
+  Bools.conj(Bools.neg(Cond), Bools.conj(Bools

[PATCH] D129547: [clang][dataflow] Generate readable form of boolean values.

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

Update CMakeList for DebugSupportTest.cpp


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129547

Files:
  clang/docs/tools/clang-formatted-files.txt
  clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
  clang/lib/Analysis/FlowSensitive/CMakeLists.txt
  clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
  clang/unittests/Analysis/FlowSensitive/CMakeLists.txt
  clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
  llvm/utils/gn/secondary/clang/lib/Analysis/FlowSensitive/BUILD.gn

Index: llvm/utils/gn/secondary/clang/lib/Analysis/FlowSensitive/BUILD.gn
===
--- llvm/utils/gn/secondary/clang/lib/Analysis/FlowSensitive/BUILD.gn
+++ llvm/utils/gn/secondary/clang/lib/Analysis/FlowSensitive/BUILD.gn
@@ -12,5 +12,6 @@
 "Transfer.cpp",
 "TypeErasedDataflowAnalysis.cpp",
 "WatchedLiteralsSolver.cpp",
+"DebugSupport.cpp",
   ]
 }
Index: clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
===
--- /dev/null
+++ clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
@@ -0,0 +1,188 @@
+//===- unittests/Analysis/FlowSensitive/DebugSupportTest.cpp --===//
+//
+// 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
+//
+//===--===//
+
+#include "clang/Analysis/FlowSensitive/DebugSupport.h"
+#include "TestingSupport.h"
+#include "clang/Analysis/FlowSensitive/Value.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+namespace {
+
+using namespace clang;
+using namespace dataflow;
+using testing::StrEq;
+
+class BoolValueDebugStringTest : public ::testing::Test {
+protected:
+  test::BoolValueManager Bools;
+};
+
+TEST_F(BoolValueDebugStringTest, AtomicBoolean) {
+  // B0
+  auto B = Bools.atom();
+
+  auto Expected = R"((B0))";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST_F(BoolValueDebugStringTest, Negation) {
+  // !B0
+  auto B = Bools.neg(Bools.atom());
+
+  auto Expected = R"((not
+(B0)))";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST_F(BoolValueDebugStringTest, Conjunction) {
+  // B0 ^ B1
+  auto B = Bools.conj(Bools.atom(), Bools.atom());
+
+  auto Expected = R"((and
+(B0)
+(B1)))";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST_F(BoolValueDebugStringTest, Disjunction) {
+  // B0 v B1
+  auto B = Bools.disj(Bools.atom(), Bools.atom());
+
+  auto Expected = R"((or
+(B0)
+(B1)))";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST_F(BoolValueDebugStringTest, Implication) {
+  // B0 => B1, implemented as !B0 v B1
+  auto B = Bools.disj(Bools.neg(Bools.atom()), Bools.atom());
+
+  auto Expected = R"((or
+(not
+(B0))
+(B1)))";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST_F(BoolValueDebugStringTest, Iff) {
+  // B0 <=> B1, implemented as (!B0 v B1) ^ (B0 v !B1)
+  auto B0 = Bools.atom();
+  auto B1 = Bools.atom();
+  auto B =
+  Bools.conj(Bools.disj(Bools.neg(B0), B1), Bools.disj(B0, Bools.neg(B1)));
+
+  auto Expected = R"((and
+(or
+(not
+(B0))
+(B1))
+(or
+(B0)
+(not
+(B1)";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST_F(BoolValueDebugStringTest, Xor) {
+  // (B0 ^ !B1) V (!B0 ^ B1)
+  auto B0 = Bools.atom();
+  auto B1 = Bools.atom();
+  auto B =
+  Bools.disj(Bools.conj(B0, Bools.neg(B1)), Bools.conj(Bools.neg(B0), B1));
+
+  auto Expected = R"((or
+(and
+(B0)
+(not
+(B1)))
+(and
+(not
+(B0))
+(B1";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST_F(BoolValueDebugStringTest, NestedBoolean) {
+  // B0 ^ (B1 v (B2 ^ (B3 v B4)))
+  auto B = Bools.conj(
+  Bools.atom(),
+  Bools.disj(
+  Bools.atom(),
+  Bools.conj(Bools.atom(), Bools.disj(Bools.atom(), Bools.atom();
+
+  auto Expected = R"((and
+(B0)
+(or
+(B1)
+(and
+(B2)
+(or
+(B3)
+(B4))";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST_F(BoolValueDebugStringTest, AtomicBooleanWithName) {
+  // True
+  llvm::StringMap NamedBools;
+  auto True = cast(Bools.atom());
+  auto B = True;
+
+  auto Expected = R"((True))";
+  EXPECT_THAT(debugString(*B, {{True, "True"}}), StrEq(Expected));
+}
+
+TEST_F(BoolValueDebugStringTest, ComplexBooleanWithNames) {
+  // (Cond ^ Then ^ !Else) v (!Cond ^ !Then ^ Else)
+  auto Cond = cast(Bools.atom());
+  auto Then = cast(Bools.atom());
+  auto Else = cast(Bools.atom());
+  auto B = Bools.disj(
+

[PATCH] D129443: [clang-format] Add option for aligning requires clause body

2022-07-12 Thread Danil Sidoruk via Phabricator via cfe-commits
eoanermine added a comment.

In D129443#3641571 , @curdeius wrote:

> Haven't you forgotten to add formatting tests? :)

Yes, I have. Thank you.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129443

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


[PATCH] D129499: [clang] Do not crash on "requires" after a fatal error occurred.

2022-07-12 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

Thanks! The fix LG, just a small nitpick for the test from my side




Comment at: clang/test/SemaCXX/concept-fatal-error.cpp:8
+  // We test that we do not crash in such cases (#55401)
+  int i = requires { { i } f } // expected-error {{expected ';' at end of 
declaration list}}
+

We need want to pass `-verify` to clang for these directives to have an effect.
The fatal error can be matched by `// expected-error@* {{too...}}` (maybe 
that's obvious, but it took me some time to figure it out first time I needed 
it)
And there is no need to run `FileCheck` after that!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129499

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


[PATCH] D129443: [clang-format] Add option for aligning requires clause body

2022-07-12 Thread Danil Sidoruk via Phabricator via cfe-commits
eoanermine updated this revision to Diff 443895.
eoanermine added a comment.

Add tests for AlignRequiresClauseBody option


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129443

Files:
  clang/include/clang/Format/Format.h
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/Format.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -20033,6 +20033,7 @@
 TEST_F(FormatTest, ParsesConfigurationBools) {
   FormatStyle Style = {};
   Style.Language = FormatStyle::LK_Cpp;
+  CHECK_PARSE_BOOL(AlignRequiresClauseBody);
   CHECK_PARSE_BOOL(AlignTrailingComments);
   CHECK_PARSE_BOOL(AllowAllArgumentsOnNextLine);
   CHECK_PARSE_BOOL(AllowAllParametersOfDeclarationOnNextLine);
@@ -24719,6 +24720,74 @@
"bar(requires);");
 }
 
+TEST_F(FormatTest, AlignRequiresClauseBody) {
+  auto Style = getLLVMStyle();
+  EXPECT_EQ(Style.AlignRequiresClauseBody, true);
+
+  verifyFormat("template \n"
+   "concept C = requires(T t) {\n"
+   "  typename T::value;\n"
+   "  requires requires(typename T::value v) {\n"
+   " { t == v } -> std::same_as;\n"
+   "   };\n"
+   "};",
+   Style);
+
+  verifyFormat(
+  "template \n"
+  "void bar(T)\n"
+  "  requires Foo && requires(T t) {\n"
+  "   { t.foo() } -> std::same_as;\n"
+  " } && requires(T t) {\n"
+  "{ t.bar() } -> std::same_as;\n"
+  "--t;\n"
+  "  };",
+  Style);
+
+  verifyFormat("template \n"
+   "  requires Foo &&\n"
+   "   requires(T t) {\n"
+   " { t.foo() } -> std::same_as;\n"
+   "   } && requires(T t) {\n"
+   "  { t.bar() } -> std::same_as;\n"
+   "  --t;\n"
+   "}\n"
+   "void bar(T);",
+   Style);
+
+  Style.AlignRequiresClauseBody = false;
+
+  verifyFormat("template \n"
+   "concept C = requires(T t) {\n"
+   "  typename T::value;\n"
+   "  requires requires(typename T::value v) {\n"
+   "{ t == v } -> std::same_as;\n"
+   "  };\n"
+   "};",
+   Style);
+
+  verifyFormat("template \n"
+   "void bar(T)\n"
+   "  requires Foo && requires(T t) {\n"
+   "{ t.foo() } -> std::same_as;\n"
+   "  } && requires(T t) {\n"
+   "{ t.bar() } -> std::same_as;\n"
+   "--t;\n"
+   "  };",
+   Style);
+
+  verifyFormat("template \n"
+   "  requires Foo &&\n"
+   "   requires(T t) {\n"
+   " { t.foo() } -> std::same_as;\n"
+   "   } && requires(T t) {\n"
+   " { t.bar() } -> std::same_as;\n"
+   " --t;\n"
+   "   }\n"
+   "void bar(T);",
+   Style);
+}
+
 TEST_F(FormatTest, StatementAttributeLikeMacros) {
   FormatStyle Style = getLLVMStyle();
   StringRef Source = "void Foo::slot() {\n"
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -646,6 +646,7 @@
 IO.mapOptional("AlignConsecutiveMacros", Style.AlignConsecutiveMacros);
 IO.mapOptional("AlignEscapedNewlines", Style.AlignEscapedNewlines);
 IO.mapOptional("AlignOperands", Style.AlignOperands);
+IO.mapOptional("AlignRequiresClauseBody", Style.AlignRequiresClauseBody);
 IO.mapOptional("AlignTrailingComments", Style.AlignTrailingComments);
 IO.mapOptional("AllowAllArgumentsOnNextLine",
Style.AllowAllArgumentsOnNextLine);
@@ -1181,6 +1182,7 @@
   LLVMStyle.AlignAfterOpenBracket = FormatStyle::BAS_Align;
   LLVMStyle.AlignArrayOfStructures = FormatStyle::AIAS_None;
   LLVMStyle.AlignOperands = FormatStyle::OAS_Align;
+  LLVMStyle.AlignRequiresClauseBody = true;
   LLVMStyle.AlignTrailingComments = true;
   LLVMStyle.AlignConsecutiveAssignments = {};
   LLVMStyle.AlignConsecutiveAssignments.Enabled = false;
Index: clang/lib/Format/ContinuationIndenter.cpp
===
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -1398,7 +1398,7 @@
 CurrentState.NestedBlockIndent = State.Column + Current.ColumnWidth + 1;
   if (Current.

[PATCH] D129443: [clang-format] Add option for aligning requires clause body

2022-07-12 Thread Danil Sidoruk via Phabricator via cfe-commits
eoanermine added a comment.

In D129443#3644795 , @eoanermine 
wrote:

> Add tests for AlignRequiresClauseBody option

Are these tests fine?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129443

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


[PATCH] D123967: Disable update_cc_test_checks.py tests in stand-alone builds

2022-07-12 Thread H. Vetinari via Phabricator via cfe-commits
h-vetinari added a comment.

Just comments, looks OK otherwise.




Comment at: clang/test/CMakeLists.txt:6
   CLANG_BUILD_EXAMPLES
+  CLANG_BUILT_STANDALONE
   CLANG_DEFAULT_PIE_ON_LINUX

OT for this PR, but it would be nice to eventually rename this to 
`CLANG_BUILD_STANDALONE` in accordance with the present tense used for other 
variables.



Comment at: clang/test/lit.site.cfg.py.in:40
 config.llvm_external_lit = path(r"@LLVM_EXTERNAL_LIT@")
+config.stand_alone_build = @CLANG_BUILT_STANDALONE@
 

I'd use one spelling of standalone / stand-alone, and I think in this case it's 
probably the env var that wins?



Comment at: clang/test/utils/update_cc_test_checks/lit.local.cfg:19
+# for any of the clang source code.
+config.unsupported = True
 else:

I couldn't tell from the diff where this is used (though admittedly I hardly 
know the LLVM infra). I also don't see it in [[ 
https://github.com/llvm/llvm-project/blob/main/clang/test/lit.cfg.py | 
`lit.cfg.py` ]], the respective [[ 
https://github.com/llvm/llvm-project/blob/main/clang/test/CMakeLists.txt | 
`CMakeLists.txt` ]] or [[ 
https://github.com/llvm/llvm-project/blob/llvmorg-14.0.6/llvm/cmake/modules/AddLLVM.cmake#L1616
 | `configure_lit_site_cfg` ]]

I trust that this does what's intended.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123967

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


[PATCH] D129547: [clang][dataflow] Generate readable form of boolean values for debugging purposes.

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

Extract recursion into boolean subvalues into separate statements to enforce 
order of evaluation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129547

Files:
  clang/docs/tools/clang-formatted-files.txt
  clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
  clang/lib/Analysis/FlowSensitive/CMakeLists.txt
  clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
  clang/unittests/Analysis/FlowSensitive/CMakeLists.txt
  clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
  llvm/utils/gn/secondary/clang/lib/Analysis/FlowSensitive/BUILD.gn

Index: llvm/utils/gn/secondary/clang/lib/Analysis/FlowSensitive/BUILD.gn
===
--- llvm/utils/gn/secondary/clang/lib/Analysis/FlowSensitive/BUILD.gn
+++ llvm/utils/gn/secondary/clang/lib/Analysis/FlowSensitive/BUILD.gn
@@ -12,5 +12,6 @@
 "Transfer.cpp",
 "TypeErasedDataflowAnalysis.cpp",
 "WatchedLiteralsSolver.cpp",
+"DebugSupport.cpp",
   ]
 }
Index: clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
===
--- /dev/null
+++ clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
@@ -0,0 +1,188 @@
+//===- unittests/Analysis/FlowSensitive/DebugSupportTest.cpp --===//
+//
+// 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
+//
+//===--===//
+
+#include "clang/Analysis/FlowSensitive/DebugSupport.h"
+#include "TestingSupport.h"
+#include "clang/Analysis/FlowSensitive/Value.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+namespace {
+
+using namespace clang;
+using namespace dataflow;
+using testing::StrEq;
+
+class BoolValueDebugStringTest : public ::testing::Test {
+protected:
+  test::BoolValueManager Bools;
+};
+
+TEST_F(BoolValueDebugStringTest, AtomicBoolean) {
+  // B0
+  auto B = Bools.atom();
+
+  auto Expected = R"((B0))";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST_F(BoolValueDebugStringTest, Negation) {
+  // !B0
+  auto B = Bools.neg(Bools.atom());
+
+  auto Expected = R"((not
+(B0)))";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST_F(BoolValueDebugStringTest, Conjunction) {
+  // B0 ^ B1
+  auto B = Bools.conj(Bools.atom(), Bools.atom());
+
+  auto Expected = R"((and
+(B0)
+(B1)))";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST_F(BoolValueDebugStringTest, Disjunction) {
+  // B0 v B1
+  auto B = Bools.disj(Bools.atom(), Bools.atom());
+
+  auto Expected = R"((or
+(B0)
+(B1)))";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST_F(BoolValueDebugStringTest, Implication) {
+  // B0 => B1, implemented as !B0 v B1
+  auto B = Bools.disj(Bools.neg(Bools.atom()), Bools.atom());
+
+  auto Expected = R"((or
+(not
+(B0))
+(B1)))";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST_F(BoolValueDebugStringTest, Iff) {
+  // B0 <=> B1, implemented as (!B0 v B1) ^ (B0 v !B1)
+  auto B0 = Bools.atom();
+  auto B1 = Bools.atom();
+  auto B =
+  Bools.conj(Bools.disj(Bools.neg(B0), B1), Bools.disj(B0, Bools.neg(B1)));
+
+  auto Expected = R"((and
+(or
+(not
+(B0))
+(B1))
+(or
+(B0)
+(not
+(B1)";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST_F(BoolValueDebugStringTest, Xor) {
+  // (B0 ^ !B1) V (!B0 ^ B1)
+  auto B0 = Bools.atom();
+  auto B1 = Bools.atom();
+  auto B =
+  Bools.disj(Bools.conj(B0, Bools.neg(B1)), Bools.conj(Bools.neg(B0), B1));
+
+  auto Expected = R"((or
+(and
+(B0)
+(not
+(B1)))
+(and
+(not
+(B0))
+(B1";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST_F(BoolValueDebugStringTest, NestedBoolean) {
+  // B0 ^ (B1 v (B2 ^ (B3 v B4)))
+  auto B = Bools.conj(
+  Bools.atom(),
+  Bools.disj(
+  Bools.atom(),
+  Bools.conj(Bools.atom(), Bools.disj(Bools.atom(), Bools.atom();
+
+  auto Expected = R"((and
+(B0)
+(or
+(B1)
+(and
+(B2)
+(or
+(B3)
+(B4))";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST_F(BoolValueDebugStringTest, AtomicBooleanWithName) {
+  // True
+  llvm::StringMap NamedBools;
+  auto True = cast(Bools.atom());
+  auto B = True;
+
+  auto Expected = R"((True))";
+  EXPECT_THAT(debugString(*B, {{True, "True"}}), StrEq(Expected));
+}
+
+TEST_F(BoolValueDebugStringTest, ComplexBooleanWithNames) {
+  // (Cond ^ Then ^ !Else) v (!Cond ^ !Then ^ Else)
+  auto Cond = cast(Bools.atom());
+  auto Then = cast(Bools.atom());
+  

[clang] 3cfa32a - Undeprecate ATOMIC_FLAG_INIT in C++

2022-07-12 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2022-07-12T06:48:31-04:00
New Revision: 3cfa32a71ecfbc1bf993358e32b916cf3483299f

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

LOG: Undeprecate ATOMIC_FLAG_INIT in C++

C++20 deprecated ATOMIC_FLAG_INIT thinking it was deprecated in C when it
wasn't. It is expected to be undeprecated in C++23 as part of LWG3659
(https://wg21.link/LWG3659), which is currently Tentatively Ready.

This handles the case where the user includes  in C++ code in a
freestanding compile mode. The corollary libc++ changes are in
1544d1f9fdb115782202d72ad200c3f93b2c4f5a.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Headers/stdatomic.h
clang/test/Headers/stdatomic-deprecations.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 86b9b7ef471bb..ce76de44e2f0f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -486,6 +486,7 @@ C++2b Feature Support
 - Implemented `P2128R6: Multidimensional subscript operator 
`_.
 - Implemented `P0849R8: auto(x): decay-copy in the language 
`_.
 - Implemented `P2242R3: Non-literal variables (and labels and gotos) in 
constexpr functions`_.
+- Implemented `LWG3659: Consider ATOMIC_FLAG_INIT undeprecation 
`_.
 
 CUDA/HIP Language Changes in Clang
 --

diff  --git a/clang/lib/Headers/stdatomic.h b/clang/lib/Headers/stdatomic.h
index 780bcc2dfea17..3a0b9cc056bef 100644
--- a/clang/lib/Headers/stdatomic.h
+++ b/clang/lib/Headers/stdatomic.h
@@ -158,10 +158,6 @@ typedef _Atomic(uintmax_t)  atomic_uintmax_t;
 typedef struct atomic_flag { atomic_bool _Value; } atomic_flag;
 
 #define ATOMIC_FLAG_INIT { 0 }
-#if __cplusplus >= 202002L && !defined(_CLANG_DISABLE_CRT_DEPRECATION_WARNINGS)
-/* ATOMIC_FLAG_INIT was deprecated in C++20 but is not deprecated in C. */
-#pragma clang deprecated(ATOMIC_FLAG_INIT)
-#endif
 
 /* These should be provided by the libc implementation. */
 #ifdef __cplusplus

diff  --git a/clang/test/Headers/stdatomic-deprecations.c 
b/clang/test/Headers/stdatomic-deprecations.c
index 56ee33e16f51a..b850f7cb4c3f3 100644
--- a/clang/test/Headers/stdatomic-deprecations.c
+++ b/clang/test/Headers/stdatomic-deprecations.c
@@ -12,7 +12,6 @@
 void func(void) {
   _Atomic int i = ATOMIC_VAR_INIT(12); // expected-warning {{macro 
'ATOMIC_VAR_INIT' has been marked as deprecated}} \
// expected-note@stdatomic.h:* {{macro 
marked 'deprecated' here}}
-  #if defined(ATOMIC_FLAG_INIT) // cxx-warning {{macro 'ATOMIC_FLAG_INIT' has 
been marked as deprecated}} \
-// cxx-note@stdatomic.h:* {{macro marked 
'deprecated' here}}
+  #if defined(ATOMIC_FLAG_INIT) // Ok, deprecated in C++20, undeprecated in 
C++23 via LWG4659.
   #endif
 }



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


[PATCH] D129362: Undeprecate ATOMIC_FLAG_INIT in C++

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

Committed in 3cfa32a71ecfbc1bf993358e32b916cf3483299f 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129362

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


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

2022-07-12 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM, thank you!


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] D129547: [clang][dataflow] Generate readable form of boolean values for debugging purposes.

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

Minor fixes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129547

Files:
  clang/docs/tools/clang-formatted-files.txt
  clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
  clang/lib/Analysis/FlowSensitive/CMakeLists.txt
  clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
  clang/unittests/Analysis/FlowSensitive/CMakeLists.txt
  clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
  llvm/utils/gn/secondary/clang/lib/Analysis/FlowSensitive/BUILD.gn

Index: llvm/utils/gn/secondary/clang/lib/Analysis/FlowSensitive/BUILD.gn
===
--- llvm/utils/gn/secondary/clang/lib/Analysis/FlowSensitive/BUILD.gn
+++ llvm/utils/gn/secondary/clang/lib/Analysis/FlowSensitive/BUILD.gn
@@ -12,5 +12,6 @@
 "Transfer.cpp",
 "TypeErasedDataflowAnalysis.cpp",
 "WatchedLiteralsSolver.cpp",
+"DebugSupport.cpp",
   ]
 }
Index: clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
===
--- /dev/null
+++ clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
@@ -0,0 +1,188 @@
+//===- unittests/Analysis/FlowSensitive/DebugSupportTest.cpp --===//
+//
+// 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
+//
+//===--===//
+
+#include "clang/Analysis/FlowSensitive/DebugSupport.h"
+#include "TestingSupport.h"
+#include "clang/Analysis/FlowSensitive/Value.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+namespace {
+
+using namespace clang;
+using namespace dataflow;
+using testing::StrEq;
+
+class BoolValueDebugStringTest : public ::testing::Test {
+protected:
+  test::BoolValueManager Bools;
+};
+
+TEST_F(BoolValueDebugStringTest, AtomicBoolean) {
+  // B0
+  auto B = Bools.atom();
+
+  auto Expected = R"((B0))";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST_F(BoolValueDebugStringTest, Negation) {
+  // !B0
+  auto B = Bools.neg(Bools.atom());
+
+  auto Expected = R"((not
+(B0)))";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST_F(BoolValueDebugStringTest, Conjunction) {
+  // B0 ^ B1
+  auto B = Bools.conj(Bools.atom(), Bools.atom());
+
+  auto Expected = R"((and
+(B0)
+(B1)))";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST_F(BoolValueDebugStringTest, Disjunction) {
+  // B0 v B1
+  auto B = Bools.disj(Bools.atom(), Bools.atom());
+
+  auto Expected = R"((or
+(B0)
+(B1)))";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST_F(BoolValueDebugStringTest, Implication) {
+  // B0 => B1, implemented as !B0 v B1
+  auto B = Bools.disj(Bools.neg(Bools.atom()), Bools.atom());
+
+  auto Expected = R"((or
+(not
+(B0))
+(B1)))";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST_F(BoolValueDebugStringTest, Iff) {
+  // B0 <=> B1, implemented as (!B0 v B1) ^ (B0 v !B1)
+  auto B0 = Bools.atom();
+  auto B1 = Bools.atom();
+  auto B =
+  Bools.conj(Bools.disj(Bools.neg(B0), B1), Bools.disj(B0, Bools.neg(B1)));
+
+  auto Expected = R"((and
+(or
+(not
+(B0))
+(B1))
+(or
+(B0)
+(not
+(B1)";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST_F(BoolValueDebugStringTest, Xor) {
+  // (B0 ^ !B1) V (!B0 ^ B1)
+  auto B0 = Bools.atom();
+  auto B1 = Bools.atom();
+  auto B =
+  Bools.disj(Bools.conj(B0, Bools.neg(B1)), Bools.conj(Bools.neg(B0), B1));
+
+  auto Expected = R"((or
+(and
+(B0)
+(not
+(B1)))
+(and
+(not
+(B0))
+(B1";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST_F(BoolValueDebugStringTest, NestedBoolean) {
+  // B0 ^ (B1 v (B2 ^ (B3 v B4)))
+  auto B = Bools.conj(
+  Bools.atom(),
+  Bools.disj(
+  Bools.atom(),
+  Bools.conj(Bools.atom(), Bools.disj(Bools.atom(), Bools.atom();
+
+  auto Expected = R"((and
+(B0)
+(or
+(B1)
+(and
+(B2)
+(or
+(B3)
+(B4))";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST_F(BoolValueDebugStringTest, AtomicBooleanWithName) {
+  // True
+  llvm::StringMap NamedBools;
+  auto True = cast(Bools.atom());
+  auto B = True;
+
+  auto Expected = R"((True))";
+  EXPECT_THAT(debugString(*B, {{True, "True"}}), StrEq(Expected));
+}
+
+TEST_F(BoolValueDebugStringTest, ComplexBooleanWithNames) {
+  // (Cond ^ Then ^ !Else) v (!Cond ^ !Then ^ Else)
+  auto Cond = cast(Bools.atom());
+  auto Then = cast(Bools.atom());
+  auto Else = cast(Bools.atom());
+  auto B = Bools.disj(
+  Bools.conj(Cond, Bools.

[PATCH] D129548: [clang][dataflow] Generate readable form of input and output of satisfiability checking for debugging purposes.

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

Use std::vector as input to `debugString` to maintain order stability of 
boolean constraints to enable testing. `debugString` which takes a 
`llvm::DenseSet` is now a wrapper around the logic applied to 
std::vector.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129548

Files:
  clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
  clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
  clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
@@ -9,6 +9,7 @@
 #include "clang/Analysis/FlowSensitive/DebugSupport.h"
 #include "TestingSupport.h"
 #include "clang/Analysis/FlowSensitive/Value.h"
+#include "clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
@@ -185,4 +186,269 @@
   StrEq(Expected));
 }
 
+class SATCheckDebugStringTest : public ::testing::Test {
+protected:
+  Solver::Result CheckSAT(std::vector Constraints) {
+llvm::DenseSet ConstraintsSet(Constraints.begin(),
+   Constraints.end());
+return WatchedLiteralsSolver().solve(std::move(ConstraintsSet));
+  }
+  test::BoolValueManager Bools;
+};
+
+TEST_F(SATCheckDebugStringTest, AtomicBoolean) {
+  // B0
+  std::vector Constraints({Bools.atom()});
+  auto Result = CheckSAT(Constraints);
+
+  auto Expected = R"(
+Constraints
+
+(B0)
+
+Satisfiable.
++--+---+
+| Atom | Value |
++--+---+
+| B0   | True  |
++--+---+
+)";
+  EXPECT_THAT(debugString(Constraints, Result), StrEq(Expected));
+}
+
+TEST_F(SATCheckDebugStringTest, AtomicBooleanAndNegation) {
+  // B0, !B0
+  auto B0 = Bools.atom();
+  std::vector Constraints({B0, Bools.neg(B0)});
+  auto Result = CheckSAT(Constraints);
+
+  auto Expected = R"(
+Constraints
+
+(B0)
+
+(not
+(B0))
+
+Unsatisfiable.
+)";
+  EXPECT_THAT(debugString(Constraints, Result), StrEq(Expected));
+}
+
+TEST_F(SATCheckDebugStringTest, MultipleAtomicBooleans) {
+  // B0, B1
+  std::vector Constraints({Bools.atom(), Bools.atom()});
+  auto Result = CheckSAT(Constraints);
+
+  auto Expected = R"(
+Constraints
+
+(B0)
+
+(B1)
+
+Satisfiable.
++--+---+
+| Atom | Value |
++--+---+
+| B0   | True  |
++--+---+
+| B1   | True  |
++--+---+
+)";
+  EXPECT_THAT(debugString(Constraints, Result), StrEq(Expected));
+}
+
+TEST_F(SATCheckDebugStringTest, Implication) {
+  // B0, B0 => B1
+  auto B0 = Bools.atom();
+  auto B1 = Bools.atom();
+  auto Impl = Bools.disj(Bools.neg(B0), B1);
+  std::vector Constraints({B0, Impl});
+  auto Result = CheckSAT(Constraints);
+
+  auto Expected = R"(
+Constraints
+
+(B0)
+
+(or
+(not
+(B0))
+(B1))
+
+Satisfiable.
++--+---+
+| Atom | Value |
++--+---+
+| B0   | True  |
++--+---+
+| B1   | True  |
++--+---+
+)";
+  EXPECT_THAT(debugString(Constraints, Result), StrEq(Expected));
+}
+
+TEST_F(SATCheckDebugStringTest, Iff) {
+  // B0, B0 <=> B1
+  auto B0 = Bools.atom();
+  auto B1 = Bools.atom();
+  auto Iff =
+  Bools.conj(Bools.disj(Bools.neg(B0), B1), Bools.disj(B0, Bools.neg(B1)));
+  std::vector Constraints({B0, Iff});
+  auto Result = CheckSAT(Constraints);
+
+  auto Expected = R"(
+Constraints
+
+(B0)
+
+(and
+(or
+(not
+(B0))
+(B1))
+(or
+(B0)
+(not
+(B1
+
+Satisfiable.
++--+---+
+| Atom | Value |
++--+---+
+| B0   | True  |
++--+---+
+| B1   | True  |
++--+---+
+)";
+  EXPECT_THAT(debugString(Constraints, Result), StrEq(Expected));
+}
+
+TEST_F(SATCheckDebugStringTest, Xor) {
+  // B0, XOR(B0, B1)
+  auto B0 = Bools.atom();
+  auto B1 = Bools.atom();
+  auto XOR =
+  Bools.disj(Bools.conj(B0, Bools.neg(B1)), Bools.conj(Bools.neg(B0), B1));
+  std::vector Constraints({B0, XOR});
+  auto Result = CheckSAT(Constraints);
+
+  auto Expected = R"(
+Constraints
+
+(B0)
+
+(or
+(and
+(B0)
+(not
+(B1)))
+(and
+(not
+(B0))
+(B1)))
+
+Satisfiable.
++--+---+
+| Atom | Value |
++--+---+
+| B0   | True  |
++--+---+
+| B1   | False |
++--+---+
+)";
+  EXPECT_THAT(debugString(Constraints, Result), StrEq(Expected));
+}
+
+TEST_F(SATCheckDebugStringTest, ComplexBooleanWithNames) {
+  // Cond, (Cond ^ Then ^ !Else) v (!Cond ^ !Then ^ Else)
+  auto Cond = cast(Bools.atom());
+  auto Then = cast(Bools.atom());
+  auto Else = cast(Bools.atom

[clang] d214bfe - [OpenMP] Do not link static library with `-nogpulib`

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

Author: Joseph Huber
Date: 2022-07-12T08:15:15-04:00
New Revision: d214bfe78d8d79a9c6bce5a7daf8d70135ebc670

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

LOG: [OpenMP] Do not link static library with `-nogpulib`

Normally we do not link the device libraries if the user passed
`nogpulib` we do this for the standard bitcode library. This behaviour
was not added when using the static library for LTO, causing it to
always be linked in. This patch fixes that.

Reviewed By: JonChesterfield

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/test/Driver/openmp-offload-gpu-new.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 2d53b829b01ce..1d2c085d683e1 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -727,7 +727,8 @@ bool tools::addOpenMPRuntime(ArgStringList &CmdArgs, const 
ToolChain &TC,
   if (IsOffloadingHost)
 CmdArgs.push_back("-lomptarget");
 
-  if (IsOffloadingHost && TC.getDriver().isUsingLTO(/* IsOffload */ true))
+  if (IsOffloadingHost && TC.getDriver().isUsingLTO(/* IsOffload */ true) &&
+  !Args.hasArg(options::OPT_nogpulib))
 CmdArgs.push_back("-lomptarget.devicertl");
 
   addArchSpecificRPath(TC, Args, CmdArgs);

diff  --git a/clang/test/Driver/openmp-offload-gpu-new.c 
b/clang/test/Driver/openmp-offload-gpu-new.c
index 9a421059a68fd..0531af41caeeb 100644
--- a/clang/test/Driver/openmp-offload-gpu-new.c
+++ b/clang/test/Driver/openmp-offload-gpu-new.c
@@ -105,11 +105,16 @@
 // RUN: --offload-device-only -E -nogpulib %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-DEVICE-ONLY-PP
 // CHECK-DEVICE-ONLY-PP: "nvptx64-nvidia-cuda" - "clang", inputs: 
["[[INPUT:.*]]"], output: "-"
 
-// RUN:   %clang -### --target=x86_64-unknown-linux-gnu -fopenmp 
--offload-arch=sm_52 -nogpulib \
+// RUN:   %clang -### --target=x86_64-unknown-linux-gnu -fopenmp 
--offload-arch=sm_52 \
 // RUN: -foffload-lto %s 2>&1 | FileCheck --check-prefix=CHECK-LTO-LIBRARY 
%s
 
 // CHECK-LTO-LIBRARY: {{.*}}-lomptarget{{.*}}-lomptarget.devicertl
 
+// RUN:   %clang -### --target=x86_64-unknown-linux-gnu -fopenmp 
--offload-arch=sm_52 -nogpulib \
+// RUN: -foffload-lto %s 2>&1 | FileCheck --check-prefix=CHECK-NO-LIBRARY 
%s
+
+// CHECK-NO-LIBRARY-NOT: {{.*}}-lomptarget{{.*}}-lomptarget.devicertl
+
 // RUN:   %clang -### --target=x86_64-unknown-linux-gnu -fopenmp 
--offload-arch=sm_52 -nogpulib \
 // RUN: -Xoffload-linker a -Xoffload-linker-nvptx64-nvidia-cuda b 
-Xoffload-linker-nvptx64 c \
 // RUN: %s 2>&1 | FileCheck --check-prefix=CHECK-XLINKER %s



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


[PATCH] D129534: [OpenMP] Do not link static library with `-nogpulib`

2022-07-12 Thread Joseph Huber via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd214bfe78d8d: [OpenMP] Do not link static library with 
`-nogpulib` (authored by jhuber6).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129534

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/openmp-offload-gpu-new.c


Index: clang/test/Driver/openmp-offload-gpu-new.c
===
--- clang/test/Driver/openmp-offload-gpu-new.c
+++ clang/test/Driver/openmp-offload-gpu-new.c
@@ -105,11 +105,16 @@
 // RUN: --offload-device-only -E -nogpulib %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-DEVICE-ONLY-PP
 // CHECK-DEVICE-ONLY-PP: "nvptx64-nvidia-cuda" - "clang", inputs: 
["[[INPUT:.*]]"], output: "-"
 
-// RUN:   %clang -### --target=x86_64-unknown-linux-gnu -fopenmp 
--offload-arch=sm_52 -nogpulib \
+// RUN:   %clang -### --target=x86_64-unknown-linux-gnu -fopenmp 
--offload-arch=sm_52 \
 // RUN: -foffload-lto %s 2>&1 | FileCheck --check-prefix=CHECK-LTO-LIBRARY 
%s
 
 // CHECK-LTO-LIBRARY: {{.*}}-lomptarget{{.*}}-lomptarget.devicertl
 
+// RUN:   %clang -### --target=x86_64-unknown-linux-gnu -fopenmp 
--offload-arch=sm_52 -nogpulib \
+// RUN: -foffload-lto %s 2>&1 | FileCheck --check-prefix=CHECK-NO-LIBRARY 
%s
+
+// CHECK-NO-LIBRARY-NOT: {{.*}}-lomptarget{{.*}}-lomptarget.devicertl
+
 // RUN:   %clang -### --target=x86_64-unknown-linux-gnu -fopenmp 
--offload-arch=sm_52 -nogpulib \
 // RUN: -Xoffload-linker a -Xoffload-linker-nvptx64-nvidia-cuda b 
-Xoffload-linker-nvptx64 c \
 // RUN: %s 2>&1 | FileCheck --check-prefix=CHECK-XLINKER %s
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -727,7 +727,8 @@
   if (IsOffloadingHost)
 CmdArgs.push_back("-lomptarget");
 
-  if (IsOffloadingHost && TC.getDriver().isUsingLTO(/* IsOffload */ true))
+  if (IsOffloadingHost && TC.getDriver().isUsingLTO(/* IsOffload */ true) &&
+  !Args.hasArg(options::OPT_nogpulib))
 CmdArgs.push_back("-lomptarget.devicertl");
 
   addArchSpecificRPath(TC, Args, CmdArgs);


Index: clang/test/Driver/openmp-offload-gpu-new.c
===
--- clang/test/Driver/openmp-offload-gpu-new.c
+++ clang/test/Driver/openmp-offload-gpu-new.c
@@ -105,11 +105,16 @@
 // RUN: --offload-device-only -E -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-DEVICE-ONLY-PP
 // CHECK-DEVICE-ONLY-PP: "nvptx64-nvidia-cuda" - "clang", inputs: ["[[INPUT:.*]]"], output: "-"
 
-// RUN:   %clang -### --target=x86_64-unknown-linux-gnu -fopenmp --offload-arch=sm_52 -nogpulib \
+// RUN:   %clang -### --target=x86_64-unknown-linux-gnu -fopenmp --offload-arch=sm_52 \
 // RUN: -foffload-lto %s 2>&1 | FileCheck --check-prefix=CHECK-LTO-LIBRARY %s
 
 // CHECK-LTO-LIBRARY: {{.*}}-lomptarget{{.*}}-lomptarget.devicertl
 
+// RUN:   %clang -### --target=x86_64-unknown-linux-gnu -fopenmp --offload-arch=sm_52 -nogpulib \
+// RUN: -foffload-lto %s 2>&1 | FileCheck --check-prefix=CHECK-NO-LIBRARY %s
+
+// CHECK-NO-LIBRARY-NOT: {{.*}}-lomptarget{{.*}}-lomptarget.devicertl
+
 // RUN:   %clang -### --target=x86_64-unknown-linux-gnu -fopenmp --offload-arch=sm_52 -nogpulib \
 // RUN: -Xoffload-linker a -Xoffload-linker-nvptx64-nvidia-cuda b -Xoffload-linker-nvptx64 c \
 // RUN: %s 2>&1 | FileCheck --check-prefix=CHECK-XLINKER %s
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -727,7 +727,8 @@
   if (IsOffloadingHost)
 CmdArgs.push_back("-lomptarget");
 
-  if (IsOffloadingHost && TC.getDriver().isUsingLTO(/* IsOffload */ true))
+  if (IsOffloadingHost && TC.getDriver().isUsingLTO(/* IsOffload */ true) &&
+  !Args.hasArg(options::OPT_nogpulib))
 CmdArgs.push_back("-lomptarget.devicertl");
 
   addArchSpecificRPath(TC, Args, CmdArgs);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D128059: [Clang] Add a warning on invalid UTF-8 in comments.

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

In D128059#3643081 , @cor3ntin wrote:

> Fix crash on PowerPC
>
> (I forgot to removed a non-sense line that
> could cause the CurPtr to move incorrectly 
> past a / in the ALTIVEC code path).

Ah, nice catch -- LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128059

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


[PATCH] D128411: [syntax] Introduce a BaseToken class.

2022-07-12 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 443922.
hokein added a comment.

remove all TokenBufferTokenManager cast usage, make it as a contract in the 
APIs.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128411

Files:
  clang/include/clang/Tooling/Syntax/BuildTree.h
  clang/include/clang/Tooling/Syntax/Mutations.h
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/include/clang/Tooling/Syntax/TokenBufferTokenManager.h
  clang/include/clang/Tooling/Syntax/TokenManager.h
  clang/include/clang/Tooling/Syntax/Tokens.h
  clang/include/clang/Tooling/Syntax/Tree.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/CMakeLists.txt
  clang/lib/Tooling/Syntax/ComputeReplacements.cpp
  clang/lib/Tooling/Syntax/Mutations.cpp
  clang/lib/Tooling/Syntax/Synthesis.cpp
  clang/lib/Tooling/Syntax/TokenBufferTokenManager.cpp
  clang/lib/Tooling/Syntax/Tree.cpp
  clang/tools/clang-check/ClangCheck.cpp
  clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
  clang/unittests/Tooling/Syntax/MutationsTest.cpp
  clang/unittests/Tooling/Syntax/SynthesisTest.cpp
  clang/unittests/Tooling/Syntax/TreeTest.cpp
  clang/unittests/Tooling/Syntax/TreeTestBase.cpp
  clang/unittests/Tooling/Syntax/TreeTestBase.h

Index: clang/unittests/Tooling/Syntax/TreeTestBase.h
===
--- clang/unittests/Tooling/Syntax/TreeTestBase.h
+++ clang/unittests/Tooling/Syntax/TreeTestBase.h
@@ -17,6 +17,7 @@
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Testing/TestClangConfig.h"
 #include "clang/Tooling/Syntax/Nodes.h"
+#include "clang/Tooling/Syntax/TokenBufferTokenManager.h"
 #include "clang/Tooling/Syntax/Tokens.h"
 #include "clang/Tooling/Syntax/Tree.h"
 #include "llvm/ADT/StringRef.h"
@@ -51,6 +52,7 @@
   std::shared_ptr Invocation;
   // Set after calling buildTree().
   std::unique_ptr TB;
+  std::unique_ptr TM;
   std::unique_ptr Arena;
 };
 
Index: clang/unittests/Tooling/Syntax/TreeTestBase.cpp
===
--- clang/unittests/Tooling/Syntax/TreeTestBase.cpp
+++ clang/unittests/Tooling/Syntax/TreeTestBase.cpp
@@ -35,13 +35,14 @@
 using namespace clang::syntax;
 
 namespace {
-ArrayRef tokens(syntax::Node *N) {
+ArrayRef tokens(syntax::Node *N,
+   const TokenBufferTokenManager &STM) {
   assert(N->isOriginal() && "tokens of modified nodes are not well-defined");
   if (auto *L = dyn_cast(N))
-return llvm::makeArrayRef(L->getToken(), 1);
+return llvm::makeArrayRef(STM.getToken(L->getTokenKey()), 1);
   auto *T = cast(N);
-  return llvm::makeArrayRef(T->findFirstLeaf()->getToken(),
-T->findLastLeaf()->getToken() + 1);
+  return llvm::makeArrayRef(STM.getToken(T->findFirstLeaf()->getTokenKey()),
+STM.getToken(T->findLastLeaf()->getTokenKey()) + 1);
 }
 } // namespace
 
@@ -70,23 +71,26 @@
   public:
 BuildSyntaxTree(syntax::TranslationUnit *&Root,
 std::unique_ptr &TB,
+std::unique_ptr &TM,
 std::unique_ptr &Arena,
 std::unique_ptr Tokens)
-: Root(Root), TB(TB), Arena(Arena), Tokens(std::move(Tokens)) {
+: Root(Root), TB(TB), TM(TM), Arena(Arena), Tokens(std::move(Tokens)) {
   assert(this->Tokens);
 }
 
 void HandleTranslationUnit(ASTContext &Ctx) override {
   TB = std::make_unique(std::move(*Tokens).consume());
   Tokens = nullptr; // make sure we fail if this gets called twice.
-  Arena = std::make_unique(Ctx.getSourceManager(),
-  Ctx.getLangOpts(), *TB);
-  Root = syntax::buildSyntaxTree(*Arena, Ctx);
+  TM = std::make_unique(
+  *TB, Ctx.getLangOpts(), Ctx.getSourceManager());
+  Arena = std::make_unique();
+  Root = syntax::buildSyntaxTree(*Arena, *TM, Ctx);
 }
 
   private:
 syntax::TranslationUnit *&Root;
 std::unique_ptr &TB;
+std::unique_ptr &TM;
 std::unique_ptr &Arena;
 std::unique_ptr Tokens;
   };
@@ -94,21 +98,23 @@
   class BuildSyntaxTreeAction : public ASTFrontendAction {
   public:
 BuildSyntaxTreeAction(syntax::TranslationUnit *&Root,
+  std::unique_ptr &TM,
   std::unique_ptr &TB,
   std::unique_ptr &Arena)
-: Root(Root), TB(TB), Arena(Arena) {}
+: Root(Root), TM(TM), TB(TB), Arena(Arena) {}
 
 std::unique_ptr CreateASTConsumer(CompilerInstance &CI,
StringRef InFile) override {
   // We start recording the tokens, ast consumer will take on the result.
   auto Tokens =
   std::make_unique(CI.getPreprocessor());
-  return std::make_unique(Root, TB, Arena,
+  return std::make_unique(Root, TB, TM, Arena,
   

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

2022-07-12 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Bot's happy again. Thanks for the quick fix!


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


[clang] cc30972 - [Clang] Add a warning on invalid UTF-8 in comments.

2022-07-12 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-07-12T14:34:30+02:00
New Revision: cc309721d20c8e544ae7a10a66735ccf4981a11c

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

LOG: [Clang] Add a warning on invalid UTF-8 in comments.

Introduce an off-by default `-Winvalid-utf8` warning
that detects invalid UTF-8 code units sequences in comments.

Invalid UTF-8 in other places is already diagnosed,
as that cannot appear in identifiers and other grammar constructs.

The warning is off by default as its likely to be somewhat disruptive
otherwise.

This warning allows clang to conform to the yet-to be approved WG21
"P2295R5 Support for UTF-8 as a portable source file encoding"
paper.

Reviewed By: aaron.ballman, #clang-language-wg

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

Added: 
clang/test/Lexer/comment-invalid-utf8.c
clang/test/Lexer/comment-utf8.c

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticLexKinds.td
clang/lib/Lex/Lexer.cpp
clang/test/SemaCXX/static-assert.cpp
llvm/include/llvm/Support/ConvertUTF.h
llvm/lib/Support/ConvertUTF.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ce76de44e2f0f..f5aecff0d2647 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -281,9 +281,11 @@ Improvements to Clang's diagnostics
   unevaluated operands of a ``typeid`` expression, as they are now
   modeled correctly in the CFG. This fixes
   `Issue 21668 `_.
-- ``-Wself-assign``, ``-Wself-assign-overloaded`` and ``-Wself-move`` will 
+- ``-Wself-assign``, ``-Wself-assign-overloaded`` and ``-Wself-move`` will
   suggest a fix if the decl being assigned is a parameter that shadows a data
   member of the contained class.
+- Added ``-Winvalid-utf8`` which diagnoses invalid UTF-8 code unit sequences in
+  comments.
 
 Non-comprehensive list of changes in this release
 -
@@ -597,7 +599,7 @@ AST Matchers
 
 - Added ``forEachTemplateArgument`` matcher which creates a match every
   time a ``templateArgument`` matches the matcher supplied to it.
-  
+
 - Added ``objcStringLiteral`` matcher which matches ObjectiveC String
   literal expressions.
 

diff  --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index ac86076140c58..38ee022e5f04c 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -113,6 +113,8 @@ def warn_four_char_character_literal : Warning<
 // Unicode and UCNs
 def err_invalid_utf8 : Error<
   "source file is not valid UTF-8">;
+def warn_invalid_utf8_in_comment : Extension<
+  "invalid UTF-8 in comment">, InGroup>;
 def err_character_not_allowed : Error<
   "unexpected character ">;
 def err_character_not_allowed_identifier : Error<

diff  --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index 6820057642bea..221ec2721fe00 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -2392,13 +2392,37 @@ bool Lexer::SkipLineComment(Token &Result, const char 
*CurPtr,
   //
   // This loop terminates with CurPtr pointing at the newline (or end of 
buffer)
   // character that ends the line comment.
+
+  // C++23 [lex.phases] p1
+  // Diagnose invalid UTF-8 if the corresponding warning is enabled, emitting a
+  // diagnostic only once per entire ill-formed subsequence to avoid
+  // emiting to many diagnostics (see http://unicode.org/review/pr-121.html).
+  bool UnicodeDecodingAlreadyDiagnosed = false;
+
   char C;
   while (true) {
 C = *CurPtr;
 // Skip over characters in the fast loop.
-while (C != 0 &&// Potentially EOF.
-   C != '\n' && C != '\r')  // Newline or DOS-style newline.
+while (isASCII(C) && C != 0 &&   // Potentially EOF.
+   C != '\n' && C != '\r') { // Newline or DOS-style newline.
   C = *++CurPtr;
+  UnicodeDecodingAlreadyDiagnosed = false;
+}
+
+if (!isASCII(C)) {
+  unsigned Length = llvm::getUTF8SequenceSize(
+  (const llvm::UTF8 *)CurPtr, (const llvm::UTF8 *)BufferEnd);
+  if (Length == 0) {
+if (!UnicodeDecodingAlreadyDiagnosed && !isLexingRawMode())
+  Diag(CurPtr, diag::warn_invalid_utf8_in_comment);
+UnicodeDecodingAlreadyDiagnosed = true;
+++CurPtr;
+  } else {
+UnicodeDecodingAlreadyDiagnosed = false;
+CurPtr += Length;
+  }
+  continue;
+}
 
 const char *NextLine = CurPtr;
 if (C != 0) {
@@ -2665,6 +2689,12 @@ bool Lexer::SkipBlockComment(Token &Result, const char 
*CurPtr,
   if (C == '/')
 C = *CurPtr++;
 
+  // C++23 [lex.phases] p1
+  // Diagnose i

[PATCH] D128059: [Clang] Add a warning on invalid UTF-8 in comments.

2022-07-12 Thread Corentin Jabot 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 rGcc309721d20c: [Clang] Add a warning on invalid UTF-8 in 
comments. (authored by cor3ntin).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128059

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticLexKinds.td
  clang/lib/Lex/Lexer.cpp
  clang/test/Lexer/comment-invalid-utf8.c
  clang/test/Lexer/comment-utf8.c
  clang/test/SemaCXX/static-assert.cpp
  llvm/include/llvm/Support/ConvertUTF.h
  llvm/lib/Support/ConvertUTF.cpp

Index: llvm/lib/Support/ConvertUTF.cpp
===
--- llvm/lib/Support/ConvertUTF.cpp
+++ llvm/lib/Support/ConvertUTF.cpp
@@ -417,6 +417,16 @@
 return isLegalUTF8(source, length);
 }
 
+/*
+ * Exported function to return the size of the first utf-8 code unit sequence,
+ * Or 0 if the sequence is not valid;
+ */
+unsigned getUTF8SequenceSize(const UTF8 *source, const UTF8 *sourceEnd) {
+  int length = trailingBytesForUTF8[*source] + 1;
+  return (length <= sourceEnd - source && isLegalUTF8(source, length)) ? length
+   : 0;
+}
+
 /* - */
 
 static unsigned
Index: llvm/include/llvm/Support/ConvertUTF.h
===
--- llvm/include/llvm/Support/ConvertUTF.h
+++ llvm/include/llvm/Support/ConvertUTF.h
@@ -181,6 +181,8 @@
 
 Boolean isLegalUTF8String(const UTF8 **source, const UTF8 *sourceEnd);
 
+unsigned getUTF8SequenceSize(const UTF8 *source, const UTF8 *sourceEnd);
+
 unsigned getNumBytesForUTF8(UTF8 firstByte);
 
 /*/
Index: clang/test/SemaCXX/static-assert.cpp
===
--- clang/test/SemaCXX/static-assert.cpp
+++ clang/test/SemaCXX/static-assert.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11 -pedantic -triple=x86_64-linux-gnu
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11 -pedantic -triple=x86_64-linux-gnu -Wno-invalid-utf8
 
 int f(); // expected-note {{declared here}}
 
Index: clang/test/Lexer/comment-utf8.c
===
--- /dev/null
+++ clang/test/Lexer/comment-utf8.c
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -fsyntax-only %s -Winvalid-utf8 -verify
+// expected-no-diagnostics
+
+
+//§ § § 😀 你好 ©
+
+/*§ § § 😀 你好 ©*/
+
+/*
+§ § § 😀 你好 ©©©
+*/
+
+/* § § § 😀 你好 © */
+/*
+a longer comment to exerce the vectorized code path
+
+αααααααααααααααααααααα  // here is some unicode
+
+
+*/
Index: clang/test/Lexer/comment-invalid-utf8.c
===
--- /dev/null
+++ clang/test/Lexer/comment-invalid-utf8.c
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -fsyntax-only %s -Winvalid-utf8 -verify=expected
+// RUN: %clang_cc1 -fsyntax-only %s -verify=nowarn
+// nowarn-no-diagnostics
+
+// This file is purposefully encoded as windows-1252
+// be careful when modifying.
+
+//€
+// expected-warning@-1 {{invalid UTF-8 in comment}}
+
+// € ‚ƒ„…†‡ˆ‰ Š ‹ Œ Ž
+// expected-warning@-1 6{{invalid UTF-8 in comment}}
+
+/*€*/
+// expected-warning@-1 {{invalid UTF-8 in comment}}
+
+/*€ ‚ƒ„…†‡ˆ‰ Š ‹ Œ Ž*/
+// expected-warning@-1 6{{invalid UTF-8 in comment}}
+
+/*
+€
+*/
+// expected-warning@-2 {{invalid UTF-8 in comment}}
+
+// abcd
+// €abcd
+// expected-warning@-1 {{invalid UTF-8 in comment}}
Index: clang/lib/Lex/Lexer.cpp
===
--- clang/lib/Lex/Lexer.cpp
+++ clang/lib/Lex/Lexer.cpp
@@ -2392,13 +2392,37 @@
   //
   // This loop terminates with CurPtr pointing at the newline (or end of buffer)
   // character that ends the line comment.
+
+  // C++23 [lex.phases] p1
+  // Diagnose invalid UTF-8 if the corresponding warning is enabled, emitting a
+  // diagnostic only once per entire ill-formed subsequence to avoid
+  // emiting to many diagnostics (see http://unicode.org/review/pr-121.html).
+  bool UnicodeDecodingAlreadyDiagnosed = false;
+
   char C;
   while (true) {
 C = *CurPtr;
 // Skip over characters in the fast loop.
-while (C != 0 &&// Potentially EOF.
-   C != '\n' && C != '\r')  // Newline or DOS-style newline.
+while (isASCII(C) && C != 0 &&   // Potentially EOF.
+   C != '\n' && C != '\r') { // Newline or DOS-style newline.
   C = *++CurPtr;
+  UnicodeDe

[PATCH] D128621: [clangd] Do not try to use $0 as a placeholder in completion snippets

2022-07-12 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

Another alternative that I think should give the best UX is to replace 
`${0:named}` with `$0`.
The items will look different, but will behave identically to the old behavior 
before VSCode change, i.e. won't "eat" an extra tab press at the end of 
completion session.
I feel that's the trade-off we should pick.

What do others think?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128621

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


[PATCH] D126742: [RISCV][Clang] Support RVV policy functions.

2022-07-12 Thread luxufan via Phabricator via cfe-commits
StephenFan added inline comments.
Herald added a subscriber: nlopes.



Comment at: clang/lib/Sema/SemaRVVLookup.cpp:378-388
+} else {
+  if (IsPrototypeDefaultTU) {
+DefaultPolicy = Policy::TU;
+if (HasPolicy)
+  BuiltinName += "_tu";
+  } else {
+DefaultPolicy = Policy::TA;

Reduce indentation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126742

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


[PATCH] D129514: Thread safety analysis: Support builtin pointer-to-member operators

2022-07-12 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

Good catch, LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129514

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


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

2022-07-12 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

Serge, this diagnostic doesn't handle non-type template parameters correctly in 
some cases. Here's an example derived from a real code: 
https://gcc.godbolt.org/z/cvP8od5c6

  template
  struct T {
static void F(int a[8 * K]);
  };
  template
  void T::F(int a[8 * K]) {}



  :6:18: warning: argument 'a' of type 'int[8 * K]' with mismatched 
bound [-Warray-parameter]
  void T::F(int a[8 * K]) {}
   ^
  :3:21: note: previously declared as 'int[8 * K]' here
static void F(int a[8 * K]);
  ^

Do you see an obvious fix? If not, please revert while investigating.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128449

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


[PATCH] D129546: [clang][dataflow] Refactor boolean creation as a test utility.

2022-07-12 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/unittests/Analysis/FlowSensitive/TestingSupport.h:223
 
+/// Utility class for creating boolean values.
+class BoolValueManager {





Comment at: clang/unittests/Analysis/FlowSensitive/TestingSupport.h:224
+/// Utility class for creating boolean values.
+class BoolValueManager {
+public:

ConstraintContext, to match other ~Context types whose purpose is to own things.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129546

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


[PATCH] D124244: [analyzer] add StoreToImmutable and ModelConstQualifiedReturn checkers

2022-07-12 Thread Zurab Tsinadze via Phabricator via cfe-commits
zukatsinadze added a comment.

In D124244#3588671 , @steakhal wrote:

> Sorry for my late reply.
>
> It feels like we have some serious obstacles.
> The `check::PostCall` handler wants to mark some memory region immutable. 
> Currently, the checker creates a new //symbolic// memregion, spawned into the 
> //immutable// memory space. After this it simply re-binds the return value.
> However, only `eval::Call` handler is supposed (**must**) to bind the return 
> value, so the current implementation cannot land.
>
> I played with the trait idea, which was this:
>
> 1. Introduce a new program state trait with the 
> `REGISTER_SET_WITH_PROGRAMSTATE(ImmutableRegions, const ento::MemRegion *)`. 
> One should not bind values to these regions. (*)
> 2. The `check::PostCall` would simply insert into this set.
> 3. The `StoreToImmutableChecker`, at the `check::Bind` handler, would verify 
> that the region is not contained by the set - otherwise emit a report...
> 4. Surface this new trait to be reachable by the `Core` infrastructure.
> 5. Refactor all the `Core` functions introducing or expecting 
> `MemRegionManager::getGlobalsRegion`s to insert the region in question into 
> this `ImmutableRegions` set associated with the current `State`, producing 
> some new `State`.
>
> The last point is the most critical. Now, by design, `MemRegionManager` does 
> not refer to the `ProgramState`, hence we don't have one that we could mutate 
> by inserting into the `ImmutableRegions` set. Passing a `ProgramStateRef` 
> along all the functions is a nightmare. Trust me, I've tried it.
> That being said, eradicating `GlobalImmutableSpaceRegion` seems to be 
> challenging.
>
> I've settled on using the custom trait, and the `GlobalImmutableSpaceRegion` 
> memspace kind to detect if the store (bind) should be allowed or not.
> F23475561: UsingTraitsForTrackingImmutability.patch 
> 
>
> WDYT @NoQ, how could we get rid of the `GlobalImmutableSpaceRegion`?
>
> ---
>
> (*): Originally I wanted a set of `const MemSpaceRegion *`, but it turns out 
> a default eval called function which returns a plain old mutable pointer is 
> of `SymRegion{conj{}}` at the `UnknownSpaceRegion`. And we probably don't 
> want to mark immutable the whole `UnknownSpaceRegion` xD.

@NoQ what do you think about steakhal's proposal?


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

https://reviews.llvm.org/D124244

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


[PATCH] D129547: [clang][dataflow] Generate readable form of boolean values for debugging purposes.

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



Comment at: clang/include/clang/Analysis/FlowSensitive/DebugSupport.h:24-25
+namespace dataflow {
+/// Utility functions which return a string representation for a boolean value
+/// `B`.
+///





Comment at: clang/include/clang/Analysis/FlowSensitive/DebugSupport.h:35-36
+debugString(BoolValue &B,
+llvm::DenseMap AtomNames);
+inline std::string debugString(BoolValue &B) { return debugString(B, {{}}); }
+

Does a default argument work?



Comment at: clang/lib/Analysis/FlowSensitive/DebugSupport.cpp:30-39
+  explicit DebugStringGenerator(
+  llvm::DenseMap AtomNames)
+  : Counter(0), AtomNames(AtomNames) {
+llvm::StringSet<> Names;
+for (auto &N : AtomNames) {
+  (void)N;
+  assert(Names.insert(N.second).second &&

To avoid even creating a set in the release mode.



Comment at: clang/lib/Analysis/FlowSensitive/DebugSupport.cpp:32
+  llvm::DenseMap AtomNames)
+  : Counter(0), AtomNames(AtomNames) {
+llvm::StringSet<> Names;





Comment at: clang/lib/Analysis/FlowSensitive/DebugSupport.cpp:46
+case Value::Kind::AtomicBool: {
+  S = formatv("({0})", getAtomName(&cast(B)));
+  break;





Comment at: clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp:21-32
+class BoolValueDebugStringTest : public ::testing::Test {
+protected:
+  test::BoolValueManager Bools;
+};
+
+TEST_F(BoolValueDebugStringTest, AtomicBoolean) {
+  // B0

It is usually better to avoid fixtures, to keep each test self-contained.

Please apply to the whole file.



Comment at: clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp:30
+
+  auto Expected = R"((B0))";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));

This should be just `B0` without parentheses.



Comment at: clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp:39
+  auto Expected = R"((not
+(B0)))";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));

Here we should also have `B0` without parentheses. So `(not B0)`.

Please apply everywhere in the file.



Comment at: clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp:134
+  // True
+  llvm::StringMap NamedBools;
+  auto True = cast(Bools.atom());

`NamedBools` seems to be not used?..



Comment at: clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp:171
+  // (False && B0) v (True v B1)
+  llvm::StringMap NamedBools;
+  auto True = cast(Bools.atom());

`NamedBools` seems to be not used?..


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129547

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


[PATCH] D127304: [LinkerWrapper] Embed OffloadBinaries for OpenMP offloading images

2022-07-12 Thread Saiyedul Islam via Phabricator via cfe-commits
saiislam accepted this revision.
saiislam added a comment.
This revision is now accepted and ready to land.

Thanks, LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127304

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


[PATCH] D129499: [clang] Do not crash on "requires" after a fatal error occurred.

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

This patch makes sense to me, but please clean up the test as @ilya-biryukov  
suggested.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129499

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


[PATCH] D129548: [clang][dataflow] Generate readable form of input and output of satisfiability checking for debugging purposes.

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



Comment at: clang/lib/Analysis/FlowSensitive/DebugSupport.cpp:143
+
+return formatv("{0:$[\n]}", llvm::make_range(Lines.begin(), Lines.end()));
+  }

I appreciate the table, but it looks quite bulky... Could we switch to a simple 
`atom=value\natom2=value2\n` format?



Comment at: clang/lib/Analysis/FlowSensitive/DebugSupport.cpp:147-156
+  std::string debugString(Solver::Result::Assignment &Assignment) {
+switch (Assignment) {
+case Solver::Result::Assignment::AssignedFalse:
+  return "False";
+case Solver::Result::Assignment::AssignedTrue:
+  return "True";
+default:

We put the llvm_unreachable after the switch, so that clang can warn us if we 
add a new enumerator but forget to update the switch. Please apply everywhere 
in this patch stack.



Comment at: clang/lib/Analysis/FlowSensitive/DebugSupport.cpp:159
+  /// Returns a string representation of the result status of a SAT check.
+  std::string debugString(enum Solver::Result::Status Status) {
+switch (Status) {




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129548

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


[PATCH] D124447: [clang-tidy] Add infrastructure support for running on project-level information

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

In D124447#3608747 , @aaron.ballman 
wrote:

> In general, I think this is looking pretty close to good. Whether clang-tidy 
> should get this functionality in this form or not is a bit less clear to me. 
> *I* think it's helpful functionality and the current approach is reasonable, 
> but I think it might be worthwhile to have a community RFC to see if others 
> agree. CC @alexfh in case he wants to make a code owner decision instead.

+1 to a need for the RFC here, there are ecosystem questions that I think 
should be addressed first but aren't in scope of this patch.
Changing the "plugin signature" of checks in a widely-used plugin system like 
clang-tidy shouldn't be taken lightly.

In particular:

- what is a motivating example of the problem you're solving? (sorry if I 
missed this)
- which checks do you plan to contribute/modify that will make use of this 
functionality?
- for existing users of clang-tidy that don't adopt the new workflow 
(clang-tidy without `--multipass-phase`, code review systems, clangd and other 
IDEs), how do they interact with such checks?
- will you be maintaining/extending the framework functionality & design 
long-term, or for a particular time span?
- do you have plans for how to deploy this to users? (e.g. running the CLI 
commands by hand, or integration into a code review tool)
- what are the expectations on check owners for understanding/supporting this 
mode?
- is this extensible to distributed execution like clang-tidy currently is? 
(this patch appears to assume coordination through a shared local filesystem, 
and "compact" appears to be a large monolithic step)
- what alternative designs were considered?

I really would like to see these addressed in an RFC rather than here - I think 
it will attract wider discussion.
(I'm sure I'll have an opinion, but mostly hoping to flesh out the plan to 
evolve clang-tidy so others can react)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124447

___
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-12 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

In D126907#3644127 , @ChuanqiXu wrote:

> In D126907#3642530 , @erichkeane 
> wrote:
>
>> This version passes check-runtimes, so libc++ is fine, and it passes 
>> everything I have available.  @ChuanqiXu : Would you be able to do 1 more 
>> run over this to make sure it won't break something?  Thanks in advance 
>> either way!
>
> I've tested some our internal workloads and all of them looks fine. But it is 
> expected since we don't use concept heavily. I had tried to run libcxx before 
> but it looks like my previous config is wrong...

Ok, thanks!  I DID test the libcxx test suite on the above, I figured it out 
through check-runtimes.  If you were able to take a quick look at the diff and 
make sure I'm not doing anything horrible, it would be appreciated.


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


[PATCH] D129226: [clang/mac] Make -mmacos-version-min the canonical spelling over -mmacosx-version-min

2022-07-12 Thread Hans Wennborg via Phabricator via cfe-commits
hans accepted this revision.
hans added a comment.
This revision is now accepted and ready to land.

lgtm, but maybe wait a few more days in case the apple folks want to chime in


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

https://reviews.llvm.org/D129226

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


[PATCH] D128845: [HLSL]Add -O and -Od option for dxc mode.

2022-07-12 Thread Chris Bieneman via Phabricator via cfe-commits
beanz added inline comments.



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:575
 
+  if (IK.getLanguage() == Language::HLSL)
+DefaultOpt = llvm::CodeGenOpt::Aggressive;

Is there a way to tie this to using the DXC driver instead of the language 
option?

It would be nice in the future to have a more clang-conformant driver mode.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128845

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


[PATCH] D128745: [c++] implements DR692, DR1395 and tentatively DR1432, about partial ordering of variadic template partial specialization or function template

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

I admit that I'm feeling a bit out of my element with all the template 
machinery involved, so I've reviewed as best I'm able (so if any of my 
questions seem odd to you, push back on them if you want).




Comment at: clang/lib/Sema/SemaTemplateDeduction.cpp:5184
 
-  // FIXME: This mimics what GCC implements, but doesn't match up with the
-  // proposed resolution for core issue 692. This area needs to be sorted out,

ychen wrote:
> ychen wrote:
> > aaron.ballman wrote:
> > > ychen wrote:
> > > > aaron.ballman wrote:
> > > > > aaron.ballman wrote:
> > > > > > We tend not to use top-level const on locals in the project as a 
> > > > > > matter of style.
> > > > > Does GCC still implement it this way?
> > > > > 
> > > > > One concern I have is that this will be an ABI breaking change, and 
> > > > > I'm not certain how disruptive it will be. If GCC already made that 
> > > > > change, it may be reasonable for us to also break it without having 
> > > > > to add ABI tags or something special. But if these changes diverge us 
> > > > > from GCC, that may require some extra effort to mitigate.
> > > > Unfortunately, GCC is still using the old/non-conforming behavior. 
> > > > https://clang.godbolt.org/z/5K4916W71. What is the usual way to 
> > > > mitigate this?
> > > You would use the `ClangABI` enumeration to alter behavior between ABI 
> > > versions: 
> > > https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Basic/LangOptions.h#L174
> > >  like done in: 
> > > https://github.com/llvm/llvm-project/blob/main/clang/lib/AST/DeclCXX.cpp#L929
> > Looking at how `ClangABI` is currently used, it looks like it is for 
> > low-level object layout ABI compatibility. For library/language ABI 
> > compatibility, maybe we should not use `ClangABI`? Looking at 
> > https://reviews.llvm.org/rG86a1b135f0c67a022ef628f092c6691892752876, I 
> > guess the practice is just committed and see? If it breaks important or 
> > many existing libraries, just revert or add compiler options?
> > I guess the practice is just committed and see? If it breaks important or 
> > many existing libraries, just revert or add compiler options?
> 
> I'm fairly optimistic considering `check-runtimes` passes. 
> Looking at how ClangABI is currently used, it looks like it is for low-level 
> object layout ABI compatibility. For library/language ABI compatibility, 
> maybe we should not use ClangABI? 

I don't know that there's any specific guidance that we only use it for object 
layout ABI compatibility; we have used it for behavior beyond layout in the 
past: 
https://github.com/llvm/llvm-project/blob/main/clang/lib/Sema/SemaDeclCXX.cpp#L9786

> I guess the practice is just committed and see? If it breaks important or 
> many existing libraries, just revert or add compiler options?

Somewhat, yes. We aim for full ABI compatibility with GCC and consider ABI 
differences to be bugs (generally speaking). If we break some important 
existing library, that bug is critical to get fixed ASAP, but any ABI different 
can potentially bite users.

I would say: if matching the old ABI requires convoluting the implementation 
too much, we can skip it; otherwise, we should probably match GCC's ABI just to 
avoid concerns.

CC @rsmith in case he has different opinions as code owner.



Comment at: clang/lib/Sema/SemaTemplateDeduction.cpp:1110
+  //   Ai is ignored;
+  if (PartialOrdering && ArgIdx + 1 == NumArgs &&
+  isa(Args[ArgIdx]))

Why are you checking `ArgIdx + 1 == NumArgs` here? It looks like you're only 
handling the case where the pack is the last argument, but packs can appear 
anywhere, right?



Comment at: clang/lib/Sema/SemaTemplateDeduction.cpp:2488
+bool XHasMoreArg = X.pack_size() > Y.pack_size();
+if (!(XHasMoreArg && X.pack_elements().back().isPackExpansion()) &&
+!(!XHasMoreArg && Y.pack_elements().back().isPackExpansion()))

ychen wrote:
> FYI: `isSameTemplateArg` is for class/variable partial ordering deduction. 
> The corresponding check for function template deduction is skipped by 
> intention. See 
> https://reviews.llvm.org/rG86a1b135f0c67a022ef628f092c6691892752876 and 
> https://github.com/llvm/llvm-project/blob/e6f1f062457c928c18a88c612f39d9e168f65a85/clang/lib/Sema/SemaTemplateDeduction.cpp#L5064-L5066.
Same question here about looking at just the last element.



Comment at: clang/lib/Sema/SemaTemplateDeduction.cpp:5399
+};
+
+/// Returns the more specialized template specialization between T1/P1 and

You should end the anonymous namespace here per our coding style guidelines.



Comment at: clang/lib/Sema/SemaTemplateDeduction.cpp:5423-5424
+template ::value>
+static TemplateLikeDecl *

Can't this be a local constexpr variable instead of an NTTP, or are there 
reasons you want to allow callers

[PATCH] D129476: [AArch64][SVE] Prefer SIMD&FP variant of clast[ab]

2022-07-12 Thread Cullen Rhodes via Phabricator via cfe-commits
c-rhodes added a comment.

In D129476#3643382 , @efriedma wrote:

> Are you saying that it's faster to use clasta targeting a float register, 
> then move the result to an integer register, rather than use the integer form 
> directly?  Or is the issue just that we want to split the operations in case 
> we can simplify the resulting bitcast?

The former, for the most part. If clast[ab] is inside a loop and is a 
loop-carried dependency it's considerably faster. If it's a straight 
bitcast-to-fp + clast[ab] + bitcast-to-int then that costs a cycle or two more 
depending on the micro-architecture, but in slightly more complicated code from 
what I've observed the SIMD&FP with bitcasts is as fast as the integer variant, 
if not faster.

> Do we expect SelectionDAG to combine a clasta+bitcast to a single 
> instruction?  Do we have test coverage for that?

No, there'll be a mov to an integer register.


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

https://reviews.llvm.org/D129476

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


[PATCH] D128462: [HLSL] add -I option for dxc mode.

2022-07-12 Thread Chris Bieneman via Phabricator via cfe-commits
beanz added inline comments.



Comment at: clang/include/clang/Driver/Options.td:6851
   Group, Flags<[DXCOption, NoXarchOption]>, Alias;
+def dxc_I : DXCJoinedOrSeparateConflict<"I">,
+  HelpText<"Add directory to include search path">,

This option has the same behavior between DXC and clang, is there a reason we 
need to define a new option value instead of reusing the existing one?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128462

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


[PATCH] D129389: [clang][deps] Override dependency and serialized diag files for modules

2022-07-12 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 accepted this revision.
jansvoboda11 added a comment.
This revision is now accepted and ready to land.

LGTM! Thanks.




Comment at: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp:341-342
+  !MDC.OriginalInvocation.getDependencyOutputOpts().OutputFile.empty();
+  // FIXME: HadSerializedDiagnostics and HadDependencyFile should be included 
in
+  // the context hash since it can affect the command-line.
   MD.ID.ContextHash = MD.BuildInvocation.getModuleHash();

This is a bit unfortunate but I don't see a better alternative.

Ideally, we would compute the hash with the `.d` and `.dia` paths already 
filled in. That would ensure the command line we end up reporting to the build 
system really **does** have the context hash associated with the module. (We'd 
need to include every field set in `getCanonicalCommandLine()` too.) But for 
the path lookup, we already need some kind of (currently partial) context hash.


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

https://reviews.llvm.org/D129389

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


[PATCH] D129104: [Modules] Add ODR Check for concepts

2022-07-12 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added a comment.
This revision is now accepted and ready to land.

LGTM, thanks!


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

https://reviews.llvm.org/D129104

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


[PATCH] D129226: [clang/mac] Make -mmacos-version-min the canonical spelling over -mmacosx-version-min

2022-07-12 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added a reviewer: akyrtzi.
dexonsmith added a subscriber: akyrtzi.
dexonsmith added a comment.

LGTM too, but I’m not at Apple these days.

@akyrtzi, can you help find someone appropriate to take a quick look since 
@arphaman seems busy?


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

https://reviews.llvm.org/D129226

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


[PATCH] D128621: [clangd] Do not try to use $0 as a placeholder in completion snippets

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

In D128621#3645123 , @ilya-biryukov 
wrote:

> Another alternative that I think should give the best UX is to replace 
> `${0:named}` with `$0`.
> The items will look different, but will behave identically to the old 
> behavior before VSCode change, i.e. won't "eat" an extra tab press at the end 
> of completion session.
> I feel that's the trade-off we should pick.
>
> What do others think?

Put some thoughts in https://github.com/clangd/clangd/issues/1190
TL;DR:

- I think fixing this only in the server for future releases (and not touching 
vscode-clangd) is OK
- Of the ideas we've heard, I like `${0:named}` => `$0` best, but can certainly 
live with the one in this patch
- (I think we could refine behavior further, but let's not block on it)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128621

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


[PATCH] D129104: [Modules] Add ODR Check for concepts

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

Should have a release note on commit!


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

https://reviews.llvm.org/D129104

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


[PATCH] D128745: [c++] implements DR692, DR1395 and tentatively DR1432, about partial ordering of variadic template partial specialization or function template

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



Comment at: clang/lib/Sema/SemaTemplateDeduction.cpp:1110
+  //   Ai is ignored;
+  if (PartialOrdering && ArgIdx + 1 == NumArgs &&
+  isa(Args[ArgIdx]))

aaron.ballman wrote:
> Why are you checking `ArgIdx + 1 == NumArgs` here? It looks like you're only 
> handling the case where the pack is the last argument, but packs can appear 
> anywhere, right?
This is definitely a concern to me as well, we probably have to check ALL packs 
and figure out what was deduced.



Comment at: clang/lib/Sema/SemaTemplateDeduction.cpp:5198
+  unsigned NumParams2 = FD2->getNumParams();
+  bool Variadic1 = NumParams1 && FD1->parameters().back()->isParameterPack();
+  bool Variadic2 = NumParams2 && FD2->parameters().back()->isParameterPack();

This is still the same issue I think?  This should probably be a 'parameters 
contains pack', not just checking the last.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128745

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


[PATCH] D128462: [HLSL] add -I option for dxc mode.

2022-07-12 Thread Chris Bieneman via Phabricator via cfe-commits
beanz added inline comments.



Comment at: clang/include/clang/Driver/Options.td:6851
   Group, Flags<[DXCOption, NoXarchOption]>, Alias;
+def dxc_I : DXCJoinedOrSeparateConflict<"I">,
+  HelpText<"Add directory to include search path">,

beanz wrote:
> This option has the same behavior between DXC and clang, is there a reason we 
> need to define a new option value instead of reusing the existing one?
As a note, the `I_Group` only has the `-I` flag, so we probably can just make 
`I_Group` valid for DXC.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128462

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


[PATCH] D129546: [clang][dataflow] Refactor boolean creation as a test utility.

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

Address comments on renaming. Removed test fixture class, replacing TEST_F with 
TEST.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129546

Files:
  clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
  clang/unittests/Analysis/FlowSensitive/TestingSupport.h

Index: clang/unittests/Analysis/FlowSensitive/TestingSupport.h
===
--- clang/unittests/Analysis/FlowSensitive/TestingSupport.h
+++ clang/unittests/Analysis/FlowSensitive/TestingSupport.h
@@ -220,6 +220,49 @@
 ///  `Name` must be unique in `ASTCtx`.
 const ValueDecl *findValueDecl(ASTContext &ASTCtx, llvm::StringRef Name);
 
+/// Creates and owns constraints which are boolean values.
+class ConstraintContext {
+public:
+  // Creates an atomic boolean value.
+  BoolValue *atom() {
+Vals.push_back(std::make_unique());
+return Vals.back().get();
+  }
+
+  // Creates a boolean conjunction value.
+  BoolValue *conj(BoolValue *LeftSubVal, BoolValue *RightSubVal) {
+Vals.push_back(
+std::make_unique(*LeftSubVal, *RightSubVal));
+return Vals.back().get();
+  }
+
+  // Creates a boolean disjunction value.
+  BoolValue *disj(BoolValue *LeftSubVal, BoolValue *RightSubVal) {
+Vals.push_back(
+std::make_unique(*LeftSubVal, *RightSubVal));
+return Vals.back().get();
+  }
+
+  // Creates a boolean negation value.
+  BoolValue *neg(BoolValue *SubVal) {
+Vals.push_back(std::make_unique(*SubVal));
+return Vals.back().get();
+  }
+
+  // Creates a boolean implication value.
+  BoolValue *impl(BoolValue *LeftSubVal, BoolValue *RightSubVal) {
+return disj(neg(LeftSubVal), RightSubVal);
+  }
+
+  // Creates a boolean biconditional value.
+  BoolValue *iff(BoolValue *LeftSubVal, BoolValue *RightSubVal) {
+return conj(impl(LeftSubVal, RightSubVal), impl(RightSubVal, LeftSubVal));
+  }
+
+private:
+  std::vector> Vals;
+};
+
 } // namespace test
 } // namespace dataflow
 } // namespace clang
Index: clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "clang/Analysis/FlowSensitive/Solver.h"
+#include "TestingSupport.h"
 #include "clang/Analysis/FlowSensitive/Value.h"
 #include "clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h"
 #include "gmock/gmock.h"
@@ -20,73 +21,33 @@
 using namespace clang;
 using namespace dataflow;
 
+using test::ConstraintContext;
 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
-  // corresponding result.
-  Solver::Result solve(llvm::DenseSet Vals) {
-return WatchedLiteralsSolver().solve(std::move(Vals));
-  }
-
-  // Creates an atomic boolean value.
-  BoolValue *atom() {
-Vals.push_back(std::make_unique());
-return Vals.back().get();
-  }
-
-  // Creates a boolean conjunction value.
-  BoolValue *conj(BoolValue *LeftSubVal, BoolValue *RightSubVal) {
-Vals.push_back(
-std::make_unique(*LeftSubVal, *RightSubVal));
-return Vals.back().get();
-  }
-
-  // Creates a boolean disjunction value.
-  BoolValue *disj(BoolValue *LeftSubVal, BoolValue *RightSubVal) {
-Vals.push_back(
-std::make_unique(*LeftSubVal, *RightSubVal));
-return Vals.back().get();
-  }
-
-  // Creates a boolean negation value.
-  BoolValue *neg(BoolValue *SubVal) {
-Vals.push_back(std::make_unique(*SubVal));
-return Vals.back().get();
-  }
-
-  // Creates a boolean implication value.
-  BoolValue *impl(BoolValue *LeftSubVal, BoolValue *RightSubVal) {
-return disj(neg(LeftSubVal), RightSubVal);
-  }
-
-  // Creates a boolean biconditional value.
-  BoolValue *iff(BoolValue *LeftSubVal, BoolValue *RightSubVal) {
-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;
-};
-
-TEST_F(SolverTest, Var) {
-  auto X = atom();
+// Checks if the conjunction of `Vals` is satisfiable and returns the
+// corresponding result.
+Solver::Result solve(llvm::DenseSet Vals) {
+  r

[PATCH] D129547: [clang][dataflow] Generate readable form of boolean values for debugging purposes.

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

Address comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129547

Files:
  clang/docs/tools/clang-formatted-files.txt
  clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
  clang/lib/Analysis/FlowSensitive/CMakeLists.txt
  clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
  clang/unittests/Analysis/FlowSensitive/CMakeLists.txt
  clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
  llvm/utils/gn/secondary/clang/lib/Analysis/FlowSensitive/BUILD.gn

Index: llvm/utils/gn/secondary/clang/lib/Analysis/FlowSensitive/BUILD.gn
===
--- llvm/utils/gn/secondary/clang/lib/Analysis/FlowSensitive/BUILD.gn
+++ llvm/utils/gn/secondary/clang/lib/Analysis/FlowSensitive/BUILD.gn
@@ -12,5 +12,6 @@
 "Transfer.cpp",
 "TypeErasedDataflowAnalysis.cpp",
 "WatchedLiteralsSolver.cpp",
+"DebugSupport.cpp",
   ]
 }
Index: clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
===
--- /dev/null
+++ clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
@@ -0,0 +1,190 @@
+//===- unittests/Analysis/FlowSensitive/DebugSupportTest.cpp --===//
+//
+// 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
+//
+//===--===//
+
+#include "clang/Analysis/FlowSensitive/DebugSupport.h"
+#include "TestingSupport.h"
+#include "clang/Analysis/FlowSensitive/Value.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+namespace {
+
+using namespace clang;
+using namespace dataflow;
+
+using test::ConstraintContext;
+using testing::StrEq;
+
+TEST(BoolValueDebugStringTest, AtomicBoolean) {
+  // B0
+  ConstraintContext Ctx;
+  auto B = Ctx.atom();
+
+  auto Expected = R"(B0)";
+  debugString(*B);
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST(BoolValueDebugStringTest, Negation) {
+  // !B0
+  ConstraintContext Ctx;
+  auto B = Ctx.neg(Ctx.atom());
+
+  auto Expected = R"((not
+B0))";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST(BoolValueDebugStringTest, Conjunction) {
+  // B0 ^ B1
+  ConstraintContext Ctx;
+  auto B = Ctx.conj(Ctx.atom(), Ctx.atom());
+
+  auto Expected = R"((and
+B0
+B1))";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST(BoolValueDebugStringTest, Disjunction) {
+  // B0 v B1
+  ConstraintContext Ctx;
+  auto B = Ctx.disj(Ctx.atom(), Ctx.atom());
+
+  auto Expected = R"((or
+B0
+B1))";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST(BoolValueDebugStringTest, Implication) {
+  // B0 => B1, implemented as !B0 v B1
+  ConstraintContext Ctx;
+  auto B = Ctx.disj(Ctx.neg(Ctx.atom()), Ctx.atom());
+
+  auto Expected = R"((or
+(not
+B0)
+B1))";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST(BoolValueDebugStringTest, Iff) {
+  // B0 <=> B1, implemented as (!B0 v B1) ^ (B0 v !B1)
+  ConstraintContext Ctx;
+  auto B0 = Ctx.atom();
+  auto B1 = Ctx.atom();
+  auto B = Ctx.conj(Ctx.disj(Ctx.neg(B0), B1), Ctx.disj(B0, Ctx.neg(B1)));
+
+  auto Expected = R"((and
+(or
+(not
+B0)
+B1)
+(or
+B0
+(not
+B1";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST(BoolValueDebugStringTest, Xor) {
+  // (B0 ^ !B1) V (!B0 ^ B1)
+  ConstraintContext Ctx;
+  auto B0 = Ctx.atom();
+  auto B1 = Ctx.atom();
+  auto B = Ctx.disj(Ctx.conj(B0, Ctx.neg(B1)), Ctx.conj(Ctx.neg(B0), B1));
+
+  auto Expected = R"((or
+(and
+B0
+(not
+B1))
+(and
+(not
+B0)
+B1)))";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST(BoolValueDebugStringTest, NestedBoolean) {
+  // B0 ^ (B1 v (B2 ^ (B3 v B4)))
+  ConstraintContext Ctx;
+  auto B = Ctx.conj(
+  Ctx.atom(),
+  Ctx.disj(Ctx.atom(),
+   Ctx.conj(Ctx.atom(), Ctx.disj(Ctx.atom(), Ctx.atom();
+
+  auto Expected = R"((and
+B0
+(or
+B1
+(and
+B2
+(or
+B3
+B4)";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST(BoolValueDebugStringTest, AtomicBooleanWithName) {
+  // True
+  ConstraintContext Ctx;
+  auto True = cast(Ctx.atom());
+  auto B = True;
+
+  auto Expected = R"(True)";
+  EXPECT_THAT(debugString(*B, {{True, "True"}}), StrEq(Expected));
+}
+
+TEST(BoolValueDebugStringTest, ComplexBooleanWithNames) {
+  // (Cond ^ Then ^ !Else) v (!Cond ^ !Then ^ Else)
+  ConstraintContext Ctx;
+  auto Cond = cast(Ctx.atom());
+  auto Then = cast(Ctx.atom());
+  auto Else = cast(Ctx.atom());
+ 

[PATCH] D129548: [clang][dataflow] Generate readable form of input and output of satisfiability checking for debugging purposes.

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

Address comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129548

Files:
  clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
  clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
  clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
@@ -9,6 +9,7 @@
 #include "clang/Analysis/FlowSensitive/DebugSupport.h"
 #include "TestingSupport.h"
 #include "clang/Analysis/FlowSensitive/Value.h"
+#include "clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
@@ -187,4 +188,242 @@
   StrEq(Expected));
 }
 
+Solver::Result CheckSAT(std::vector Constraints) {
+  llvm::DenseSet ConstraintsSet(Constraints.begin(),
+ Constraints.end());
+  return WatchedLiteralsSolver().solve(std::move(ConstraintsSet));
+}
+
+TEST(SATCheckDebugStringTest, AtomicBoolean) {
+  // B0
+  ConstraintContext Ctx;
+  std::vector Constraints({Ctx.atom()});
+  auto Result = CheckSAT(Constraints);
+
+  auto Expected = R"(
+Constraints
+
+B0
+
+Satisfiable.
+
+B0=True
+)";
+  EXPECT_THAT(debugString(Constraints, Result), StrEq(Expected));
+}
+
+TEST(SATCheckDebugStringTest, AtomicBooleanAndNegation) {
+  // B0, !B0
+  ConstraintContext Ctx;
+  auto B0 = Ctx.atom();
+  std::vector Constraints({B0, Ctx.neg(B0)});
+  auto Result = CheckSAT(Constraints);
+
+  auto Expected = R"(
+Constraints
+
+B0
+
+(not
+B0)
+
+Unsatisfiable.
+
+)";
+  EXPECT_THAT(debugString(Constraints, Result), StrEq(Expected));
+}
+
+TEST(SATCheckDebugStringTest, MultipleAtomicBooleans) {
+  // B0, B1
+  ConstraintContext Ctx;
+  std::vector Constraints({Ctx.atom(), Ctx.atom()});
+  auto Result = CheckSAT(Constraints);
+
+  auto Expected = R"(
+Constraints
+
+B0
+
+B1
+
+Satisfiable.
+
+B0=True
+B1=True
+)";
+  EXPECT_THAT(debugString(Constraints, Result), StrEq(Expected));
+}
+
+TEST(SATCheckDebugStringTest, Implication) {
+  // B0, B0 => B1
+  ConstraintContext Ctx;
+  auto B0 = Ctx.atom();
+  auto B1 = Ctx.atom();
+  auto Impl = Ctx.disj(Ctx.neg(B0), B1);
+  std::vector Constraints({B0, Impl});
+  auto Result = CheckSAT(Constraints);
+
+  auto Expected = R"(
+Constraints
+
+B0
+
+(or
+(not
+B0)
+B1)
+
+Satisfiable.
+
+B0=True
+B1=True
+)";
+  EXPECT_THAT(debugString(Constraints, Result), StrEq(Expected));
+}
+
+TEST(SATCheckDebugStringTest, Iff) {
+  // B0, B0 <=> B1
+  ConstraintContext Ctx;
+  auto B0 = Ctx.atom();
+  auto B1 = Ctx.atom();
+  auto Iff = Ctx.conj(Ctx.disj(Ctx.neg(B0), B1), Ctx.disj(B0, Ctx.neg(B1)));
+  std::vector Constraints({B0, Iff});
+  auto Result = CheckSAT(Constraints);
+
+  auto Expected = R"(
+Constraints
+
+B0
+
+(and
+(or
+(not
+B0)
+B1)
+(or
+B0
+(not
+B1)))
+
+Satisfiable.
+
+B0=True
+B1=True
+)";
+  EXPECT_THAT(debugString(Constraints, Result), StrEq(Expected));
+}
+
+TEST(SATCheckDebugStringTest, Xor) {
+  // B0, XOR(B0, B1)
+  ConstraintContext Ctx;
+  auto B0 = Ctx.atom();
+  auto B1 = Ctx.atom();
+  auto XOR = Ctx.disj(Ctx.conj(B0, Ctx.neg(B1)), Ctx.conj(Ctx.neg(B0), B1));
+  std::vector Constraints({B0, XOR});
+  auto Result = CheckSAT(Constraints);
+
+  auto Expected = R"(
+Constraints
+
+B0
+
+(or
+(and
+B0
+(not
+B1))
+(and
+(not
+B0)
+B1))
+
+Satisfiable.
+
+B0=True
+B1=False
+)";
+  EXPECT_THAT(debugString(Constraints, Result), StrEq(Expected));
+}
+
+TEST(SATCheckDebugStringTest, ComplexBooleanWithNames) {
+  // Cond, (Cond ^ Then ^ !Else) v (!Cond ^ !Then ^ Else)
+  ConstraintContext Ctx;
+  auto Cond = cast(Ctx.atom());
+  auto Then = cast(Ctx.atom());
+  auto Else = cast(Ctx.atom());
+  auto B = Ctx.disj(Ctx.conj(Cond, Ctx.conj(Then, Ctx.neg(Else))),
+Ctx.conj(Ctx.neg(Cond), Ctx.conj(Ctx.neg(Then), Else)));
+  std::vector Constraints({Cond, B});
+  auto Result = CheckSAT(Constraints);
+
+  auto Expected = R"(
+Constraints
+
+Cond
+
+(or
+(and
+Cond
+(and
+Then
+(not
+Else)))
+(and
+(not
+Cond)
+(and
+(not
+Then)
+Else)))
+
+Satisfiable.
+
+Cond=True
+Else=False
+Then=True
+)";
+  EXPECT_THAT(debugString(Constraints, Result,
+  {{Cond, "Cond"}, {Then, "Then"}, {Else, "Else"}}),
+

[PATCH] D129562: [SystemZ] Enable `-mtune=` option in clang.

2022-07-12 Thread Kai Nacke via Phabricator via cfe-commits
Kai created this revision.
Kai added reviewers: uweigand, jnspaulsson, yusra.syeda, Everybody0523.
Herald added subscribers: luke957, s.egerton, simoncook.
Herald added a project: All.
Kai requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

D128910  enabled handling of attribute 
`"tune-cpu"` .
This PR now enables option `-mtune` option, which then generates the
new attribute in clang.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129562

Files:
  clang/docs/ClangCommandLineReference.rst
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/Targets/SystemZ.h
  clang/lib/Driver/ToolChains/Clang.cpp


Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -2228,8 +2228,23 @@
 
 void Clang::AddSystemZTargetArgs(const ArgList &Args,
  ArgStringList &CmdArgs) const {
-  bool HasBackchain = Args.hasFlag(options::OPT_mbackchain,
-   options::OPT_mno_backchain, false);
+  if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_mtune_EQ)) {
+StringRef Name = A->getValue();
+
+std::string TuneCPU;
+if (Name == "native")
+  TuneCPU = std::string(llvm::sys::getHostCPUName());
+else
+  TuneCPU = std::string(Name);
+
+if (!TuneCPU.empty()) {
+  CmdArgs.push_back("-tune-cpu");
+  CmdArgs.push_back(Args.MakeArgString(TuneCPU));
+}
+  }
+
+  bool HasBackchain =
+  Args.hasFlag(options::OPT_mbackchain, options::OPT_mno_backchain, false);
   bool HasPackedStack = Args.hasFlag(options::OPT_mpacked_stack,
  options::OPT_mno_packed_stack, false);
   systemz::FloatABI FloatABI =
Index: clang/lib/Basic/Targets/SystemZ.h
===
--- clang/lib/Basic/Targets/SystemZ.h
+++ clang/lib/Basic/Targets/SystemZ.h
@@ -123,6 +123,14 @@
 
   void fillValidCPUList(SmallVectorImpl &Values) const override;
 
+  bool isValidTuneCPUName(StringRef Name) const override {
+return isValidCPUName(Name);
+  }
+
+  void fillValidTuneCPUList(SmallVectorImpl &Values) const override 
{
+fillValidCPUList(Values);
+  }
+
   bool setCPU(const std::string &Name) override {
 CPU = Name;
 ISARevision = getISARevision(CPU);
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -3942,7 +3942,7 @@
   HelpText<"Provide information about a particular module file">;
 def mthumb : Flag<["-"], "mthumb">, Group;
 def mtune_EQ : Joined<["-"], "mtune=">, Group,
-  HelpText<"Only supported on X86 and RISC-V. Otherwise accepted for 
compatibility with GCC.">;
+  HelpText<"Only supported on X86, RISC-V and SystemZ. Otherwise accepted for 
compatibility with GCC.">;
 def multi__module : Flag<["-"], "multi_module">;
 def multiply__defined__unused : Separate<["-"], "multiply_defined_unused">;
 def multiply__defined : Separate<["-"], "multiply_defined">;
Index: clang/docs/ClangCommandLineReference.rst
===
--- clang/docs/ClangCommandLineReference.rst
+++ clang/docs/ClangCommandLineReference.rst
@@ -3325,7 +3325,7 @@
 .. option:: -mtune=
 .. program:: clang
 
-Only supported on X86 and RISC-V. Otherwise accepted for compatibility with 
GCC.
+Only supported on X86, RISC-V and SystemZ. Otherwise accepted for 
compatibility with GCC.
 
 .. option:: -mtvos-version-min=, -mappletvos-version-min=
 


Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -2228,8 +2228,23 @@
 
 void Clang::AddSystemZTargetArgs(const ArgList &Args,
  ArgStringList &CmdArgs) const {
-  bool HasBackchain = Args.hasFlag(options::OPT_mbackchain,
-   options::OPT_mno_backchain, false);
+  if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_mtune_EQ)) {
+StringRef Name = A->getValue();
+
+std::string TuneCPU;
+if (Name == "native")
+  TuneCPU = std::string(llvm::sys::getHostCPUName());
+else
+  TuneCPU = std::string(Name);
+
+if (!TuneCPU.empty()) {
+  CmdArgs.push_back("-tune-cpu");
+  CmdArgs.push_back(Args.MakeArgString(TuneCPU));
+}
+  }
+
+  bool HasBackchain =
+  Args.hasFlag(options::OPT_mbackchain, options::OPT_mno_backchain, false);
   bool HasPackedStack = Args.hasFlag(options::OPT_mpacked_stack,
  options::OPT_mno_packed_stack, false);
   systemz::FloatABI FloatABI =
Index: clang/lib/Basic/Targets/SystemZ.h
===

[PATCH] D129461: [PowerPC] Support x86 compatible intrinsics on AIX

2022-07-12 Thread ChenZheng via Phabricator via cfe-commits
shchenz added inline comments.



Comment at: clang/lib/Driver/ToolChains/AIX.cpp:226
+  // Add the PowerPC intrinsic headers (/include/ppc_wrappers)
+  if (!DriverArgs.hasArg(clang::driver::options::OPT_nostdinc) &&
+  !DriverArgs.hasArg(options::OPT_nobuiltininc)) {

`clang::driver::options::OPT_nostdinc` is not same with `options::OPT_nostdinc` 
in line 219?



Comment at: clang/test/CodeGen/PowerPC/ppc-emmintrin.c:631
 // CHECK: %[[ADDR:[0-9a-zA-Z_.]+]] = load double*, double** 
%{{[0-9a-zA-Z_.]+}}, align 8
-// CHECK: %[[VAL:[0-9a-zA-Z_.]+]] = load double, double* %[[ADDR]], align 8
+// CHECK: %[[VAL:[0-9a-zA-Z_.]+]] = load double, double* %[[ADDR]]
 // CHECK: call <2 x double> @vec_splats(double)(double noundef %[[VAL]])

Maybe worth investigating here why loading a double on AIX64 is not aligned to 
8. This should be separated from this patch


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129461

___
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-12 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

In D126907#3645198 , @erichkeane 
wrote:

> In D126907#3644127 , @ChuanqiXu 
> wrote:
>
>> In D126907#3642530 , @erichkeane 
>> wrote:
>>
>>> This version passes check-runtimes, so libc++ is fine, and it passes 
>>> everything I have available.  @ChuanqiXu : Would you be able to do 1 more 
>>> run over this to make sure it won't break something?  Thanks in advance 
>>> either way!
>>
>> I've tested some our internal workloads and all of them looks fine. But it 
>> is expected since we don't use concept heavily. I had tried to run libcxx 
>> before but it looks like my previous config is wrong...
>
> Ok, thanks!  I DID test the libcxx test suite on the above, I figured it out 
> through check-runtimes.  If you were able to take a quick look at the diff 
> and make sure I'm not doing anything horrible, it would be appreciated.

Yeah, things looks good to me basically.




Comment at: clang/lib/Sema/SemaTemplateInstantiate.cpp:963-964
+  Entity(Entity),
+  EvaluatingAConstraint(EvaluatingConstraint ||
+!SemaRef.CurContext->isDependentContext()) {}
 

I would like to see this in call site and a comment to tell us that we don't 
want to evaluate constraints in dependent context.


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


[PATCH] D129104: [Modules] Add ODR Check for concepts

2022-07-12 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

Thanks for reviewing and noting!


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

https://reviews.llvm.org/D129104

___
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-12 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/lib/Sema/SemaTemplateInstantiate.cpp:963-964
+  Entity(Entity),
+  EvaluatingAConstraint(EvaluatingConstraint ||
+!SemaRef.CurContext->isDependentContext()) {}
 

ChuanqiXu wrote:
> I would like to see this in call site and a comment to tell us that we don't 
> want to evaluate constraints in dependent context.
So you want this logic moved to the call-sites?  Or am I misinterpreting that?


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


[PATCH] D129563: [docs] Document git-clang-format

2022-07-12 Thread Nico Weber via Phabricator via cfe-commits
thakis created this revision.
thakis added reviewers: curdeius, MyDeveloperDay.
Herald added a project: All.
thakis requested review of this revision.

clang-format's documentation documented the more general clang-format-diff.py
script. Add documentation for the less general but arguably easier-to-use
git integration as well.


https://reviews.llvm.org/D129563

Files:
  clang/docs/ClangFormat.rst


Index: clang/docs/ClangFormat.rst
===
--- clang/docs/ClangFormat.rst
+++ clang/docs/ClangFormat.rst
@@ -229,6 +229,59 @@
 
 Get the latest Visual Studio Code extension from the `Visual Studio 
Marketplace 
`_. The 
default key-binding is Alt-Shift-F.
 
+Git integration
+===
+
+The script `clang/tools/clang-format/git-clang-format` can be used to
+format just the lines touched in git commits:
+
+.. code-block:: console
+
+  % git clang-format -h
+  usage: git clang-format [OPTIONS] [] [|--staged] [--] 
[...]
+
+  If zero or one commits are given, run clang-format on all lines that differ
+  between the working directory and , which defaults to HEAD.  Changes 
are
+  only applied to the working directory, or in the stage/index.
+
+  Examples:
+To format staged changes, i.e everything that's been `git add`ed:
+  git clang-format
+
+To also format everything touched in the most recent commit:
+  git clang-format HEAD~1
+
+If you're on a branch off main, to format everything touched on your 
branch:
+  git clang-format main
+
+  If two commits are given (requires --diff), run clang-format on all lines in 
the
+  second  that differ from the first .
+
+  The following git-config settings set the default of the corresponding 
option:
+clangFormat.binary
+clangFormat.commit
+clangFormat.extensions
+clangFormat.style
+
+  positional arguments:
+  revision from which to compute the diff
+... if specified, only consider differences in these 
files
+
+  optional arguments:
+-h, --helpshow this help message and exit
+--binary BINARY   path to clang-format
+--commit COMMIT   default commit to use if none is specified
+--diffprint a diff instead of applying the changes
+--diffstatprint a diffstat instead of applying the changes
+--extensions EXTENSIONS
+  comma-separated list of file extensions to format, 
excluding the period and case-insensitive
+-f, --force   allow changes to unstaged files
+-p, --patch   select hunks interactively
+-q, --quiet   print less information
+--staged, --cachedformat lines in the stage instead of the working dir
+--style STYLE passed to clang-format
+-v, --verbose print extra information
+
 
 Script for patch reformatting
 =


Index: clang/docs/ClangFormat.rst
===
--- clang/docs/ClangFormat.rst
+++ clang/docs/ClangFormat.rst
@@ -229,6 +229,59 @@
 
 Get the latest Visual Studio Code extension from the `Visual Studio Marketplace `_. The default key-binding is Alt-Shift-F.
 
+Git integration
+===
+
+The script `clang/tools/clang-format/git-clang-format` can be used to
+format just the lines touched in git commits:
+
+.. code-block:: console
+
+  % git clang-format -h
+  usage: git clang-format [OPTIONS] [] [|--staged] [--] [...]
+
+  If zero or one commits are given, run clang-format on all lines that differ
+  between the working directory and , which defaults to HEAD.  Changes are
+  only applied to the working directory, or in the stage/index.
+
+  Examples:
+To format staged changes, i.e everything that's been `git add`ed:
+  git clang-format
+
+To also format everything touched in the most recent commit:
+  git clang-format HEAD~1
+
+If you're on a branch off main, to format everything touched on your branch:
+  git clang-format main
+
+  If two commits are given (requires --diff), run clang-format on all lines in the
+  second  that differ from the first .
+
+  The following git-config settings set the default of the corresponding option:
+clangFormat.binary
+clangFormat.commit
+clangFormat.extensions
+clangFormat.style
+
+  positional arguments:
+  revision from which to compute the diff
+... if specified, only consider differences in these files
+
+  optional arguments:
+-h, --helpshow this help message and exit
+--binary BINARY   path to clang-format
+--commit COMMIT   default commit to use if none is specified
+--diffprint a diff instead of applying the changes
+--diffstatprint a diffstat instead of ap

[PATCH] D129563: [docs] Document git-clang-format

2022-07-12 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

(does anyone know why git-clang-format isn't implemented in terms of 
clang-format-diff.py? I suppose it's easier to use if it's standalone?)


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

https://reviews.llvm.org/D129563

___
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-12 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added inline comments.



Comment at: clang/lib/Sema/SemaTemplateInstantiate.cpp:963-964
+  Entity(Entity),
+  EvaluatingAConstraint(EvaluatingConstraint ||
+!SemaRef.CurContext->isDependentContext()) {}
 

erichkeane wrote:
> ChuanqiXu wrote:
> > I would like to see this in call site and a comment to tell us that we 
> > don't want to evaluate constraints in dependent context.
> So you want this logic moved to the call-sites?  Or am I misinterpreting that?
Yes. It is odd **for me** to do logic operations in the initialization list.


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


[PATCH] D129548: [clang][dataflow] Generate readable form of input and output of satisfiability checking for debugging purposes.

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

Fix comment, remove unused import.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129548

Files:
  clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
  clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
  clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
@@ -9,6 +9,7 @@
 #include "clang/Analysis/FlowSensitive/DebugSupport.h"
 #include "TestingSupport.h"
 #include "clang/Analysis/FlowSensitive/Value.h"
+#include "clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
@@ -187,4 +188,242 @@
   StrEq(Expected));
 }
 
+Solver::Result CheckSAT(std::vector Constraints) {
+  llvm::DenseSet ConstraintsSet(Constraints.begin(),
+ Constraints.end());
+  return WatchedLiteralsSolver().solve(std::move(ConstraintsSet));
+}
+
+TEST(SATCheckDebugStringTest, AtomicBoolean) {
+  // B0
+  ConstraintContext Ctx;
+  std::vector Constraints({Ctx.atom()});
+  auto Result = CheckSAT(Constraints);
+
+  auto Expected = R"(
+Constraints
+
+B0
+
+Satisfiable.
+
+B0=True
+)";
+  EXPECT_THAT(debugString(Constraints, Result), StrEq(Expected));
+}
+
+TEST(SATCheckDebugStringTest, AtomicBooleanAndNegation) {
+  // B0, !B0
+  ConstraintContext Ctx;
+  auto B0 = Ctx.atom();
+  std::vector Constraints({B0, Ctx.neg(B0)});
+  auto Result = CheckSAT(Constraints);
+
+  auto Expected = R"(
+Constraints
+
+B0
+
+(not
+B0)
+
+Unsatisfiable.
+
+)";
+  EXPECT_THAT(debugString(Constraints, Result), StrEq(Expected));
+}
+
+TEST(SATCheckDebugStringTest, MultipleAtomicBooleans) {
+  // B0, B1
+  ConstraintContext Ctx;
+  std::vector Constraints({Ctx.atom(), Ctx.atom()});
+  auto Result = CheckSAT(Constraints);
+
+  auto Expected = R"(
+Constraints
+
+B0
+
+B1
+
+Satisfiable.
+
+B0=True
+B1=True
+)";
+  EXPECT_THAT(debugString(Constraints, Result), StrEq(Expected));
+}
+
+TEST(SATCheckDebugStringTest, Implication) {
+  // B0, B0 => B1
+  ConstraintContext Ctx;
+  auto B0 = Ctx.atom();
+  auto B1 = Ctx.atom();
+  auto Impl = Ctx.disj(Ctx.neg(B0), B1);
+  std::vector Constraints({B0, Impl});
+  auto Result = CheckSAT(Constraints);
+
+  auto Expected = R"(
+Constraints
+
+B0
+
+(or
+(not
+B0)
+B1)
+
+Satisfiable.
+
+B0=True
+B1=True
+)";
+  EXPECT_THAT(debugString(Constraints, Result), StrEq(Expected));
+}
+
+TEST(SATCheckDebugStringTest, Iff) {
+  // B0, B0 <=> B1
+  ConstraintContext Ctx;
+  auto B0 = Ctx.atom();
+  auto B1 = Ctx.atom();
+  auto Iff = Ctx.conj(Ctx.disj(Ctx.neg(B0), B1), Ctx.disj(B0, Ctx.neg(B1)));
+  std::vector Constraints({B0, Iff});
+  auto Result = CheckSAT(Constraints);
+
+  auto Expected = R"(
+Constraints
+
+B0
+
+(and
+(or
+(not
+B0)
+B1)
+(or
+B0
+(not
+B1)))
+
+Satisfiable.
+
+B0=True
+B1=True
+)";
+  EXPECT_THAT(debugString(Constraints, Result), StrEq(Expected));
+}
+
+TEST(SATCheckDebugStringTest, Xor) {
+  // B0, XOR(B0, B1)
+  ConstraintContext Ctx;
+  auto B0 = Ctx.atom();
+  auto B1 = Ctx.atom();
+  auto XOR = Ctx.disj(Ctx.conj(B0, Ctx.neg(B1)), Ctx.conj(Ctx.neg(B0), B1));
+  std::vector Constraints({B0, XOR});
+  auto Result = CheckSAT(Constraints);
+
+  auto Expected = R"(
+Constraints
+
+B0
+
+(or
+(and
+B0
+(not
+B1))
+(and
+(not
+B0)
+B1))
+
+Satisfiable.
+
+B0=True
+B1=False
+)";
+  EXPECT_THAT(debugString(Constraints, Result), StrEq(Expected));
+}
+
+TEST(SATCheckDebugStringTest, ComplexBooleanWithNames) {
+  // Cond, (Cond ^ Then ^ !Else) v (!Cond ^ !Then ^ Else)
+  ConstraintContext Ctx;
+  auto Cond = cast(Ctx.atom());
+  auto Then = cast(Ctx.atom());
+  auto Else = cast(Ctx.atom());
+  auto B = Ctx.disj(Ctx.conj(Cond, Ctx.conj(Then, Ctx.neg(Else))),
+Ctx.conj(Ctx.neg(Cond), Ctx.conj(Ctx.neg(Then), Else)));
+  std::vector Constraints({Cond, B});
+  auto Result = CheckSAT(Constraints);
+
+  auto Expected = R"(
+Constraints
+
+Cond
+
+(or
+(and
+Cond
+(and
+Then
+(not
+Else)))
+(and
+(not
+Cond)
+(and
+(not
+Then)
+Else)))
+
+Satisfiable.
+
+Cond=True
+Else=False
+Then=True
+)";
+  EXPECT_THAT(debugString(Constraints, Result,
+  {{Cond, "Cond"}, {Then, "Then"}, {Else, "Else"}}),
+  StrEq(Expec

[clang] d489268 - [clang/mac] Make -mmacos-version-min the canonical spelling over -mmacosx-version-min

2022-07-12 Thread Nico Weber via cfe-commits

Author: Nico Weber
Date: 2022-07-12T11:03:51-04:00
New Revision: d489268392d231492827c5b0a3be88b707e1fd31

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

LOG: [clang/mac] Make -mmacos-version-min the canonical spelling over 
-mmacosx-version-min

This was promised 5 years ago in https://reviews.llvm.org/D32796,
let's do it.

Both flags are still accepted. No behavior change except for which
form shows up in --help output and in dumps of internal state
(such as with RC_DEBUG_OPTIONS).

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

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Darwin.cpp
clang/test/Driver/darwin-debug-flags.c

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index a1329e7532540..f15c282bafef6 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3354,10 +3354,10 @@ def mmlir : Separate<["-"], "mmlir">, 
Flags<[CoreOption,FC1Option,FlangOption]>,
 def ffuchsia_api_level_EQ : Joined<["-"], "ffuchsia-api-level=">,
   Group, Flags<[CC1Option]>, HelpText<"Set Fuchsia API level">,
   MarshallingInfoInt>;
-def mmacosx_version_min_EQ : Joined<["-"], "mmacosx-version-min=">,
-  Group, HelpText<"Set Mac OS X deployment target">;
 def mmacos_version_min_EQ : Joined<["-"], "mmacos-version-min=">,
-  Group, Alias;
+  Group, HelpText<"Set macOS deployment target">;
+def : Joined<["-"], "mmacosx-version-min=">,
+  Group, Alias;
 def mms_bitfields : Flag<["-"], "mms-bitfields">, Group, 
Flags<[CC1Option]>,
   HelpText<"Set the default structure layout to be compatible with the 
Microsoft compiler standard">,
   MarshallingInfoFlag>;

diff  --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index 0a8a9c6eb6ff0..5f0764d53b327 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1551,7 +1551,7 @@ struct DarwinPlatform {
 options::ID Opt;
 switch (Platform) {
 case DarwinPlatformKind::MacOS:
-  Opt = options::OPT_mmacosx_version_min_EQ;
+  Opt = options::OPT_mmacos_version_min_EQ;
   break;
 case DarwinPlatformKind::IPhoneOS:
   Opt = options::OPT_miphoneos_version_min_EQ;
@@ -1727,7 +1727,7 @@ struct DarwinPlatform {
 Optional
 getDeploymentTargetFromOSVersionArg(DerivedArgList &Args,
 const Driver &TheDriver) {
-  Arg *OSXVersion = Args.getLastArg(options::OPT_mmacosx_version_min_EQ);
+  Arg *macOSVersion = Args.getLastArg(options::OPT_mmacos_version_min_EQ);
   Arg *iOSVersion = Args.getLastArg(options::OPT_miphoneos_version_min_EQ,
 
options::OPT_mios_simulator_version_min_EQ);
   Arg *TvOSVersion =
@@ -1736,15 +1736,15 @@ getDeploymentTargetFromOSVersionArg(DerivedArgList 
&Args,
   Arg *WatchOSVersion =
   Args.getLastArg(options::OPT_mwatchos_version_min_EQ,
   options::OPT_mwatchos_simulator_version_min_EQ);
-  if (OSXVersion) {
+  if (macOSVersion) {
 if (iOSVersion || TvOSVersion || WatchOSVersion) {
   TheDriver.Diag(diag::err_drv_argument_not_allowed_with)
-  << OSXVersion->getAsString(Args)
+  << macOSVersion->getAsString(Args)
   << (iOSVersion ? iOSVersion
  : TvOSVersion ? TvOSVersion : WatchOSVersion)
  ->getAsString(Args);
 }
-return DarwinPlatform::createOSVersionArg(Darwin::MacOS, OSXVersion);
+return DarwinPlatform::createOSVersionArg(Darwin::MacOS, macOSVersion);
   } else if (iOSVersion) {
 if (TvOSVersion || WatchOSVersion) {
   TheDriver.Diag(diag::err_drv_argument_not_allowed_with)

diff  --git a/clang/test/Driver/darwin-debug-flags.c 
b/clang/test/Driver/darwin-debug-flags.c
index 79a7f48350f5c..7b76f97453bfe 100644
--- a/clang/test/Driver/darwin-debug-flags.c
+++ b/clang/test/Driver/darwin-debug-flags.c
@@ -9,7 +9,7 @@
 // CHECK-SAME:flags:
 // CHECK-SAME:-I path\\ with\\ spaces
 // CHECK-SAME:-g -Os
-// CHECK-SAME:-mmacosx-version-min=10.5.0
+// CHECK-SAME:-mmacos-version-min=10.5.0
 
 int x;
 



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


[PATCH] D129226: [clang/mac] Make -mmacos-version-min the canonical spelling over -mmacosx-version-min

2022-07-12 Thread Nico Weber 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 rGd489268392d2: [clang/mac] Make -mmacos-version-min the 
canonical spelling over -mmacosx… (authored by thakis).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129226

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/darwin-debug-flags.c


Index: clang/test/Driver/darwin-debug-flags.c
===
--- clang/test/Driver/darwin-debug-flags.c
+++ clang/test/Driver/darwin-debug-flags.c
@@ -9,7 +9,7 @@
 // CHECK-SAME:flags:
 // CHECK-SAME:-I path\\ with\\ spaces
 // CHECK-SAME:-g -Os
-// CHECK-SAME:-mmacosx-version-min=10.5.0
+// CHECK-SAME:-mmacos-version-min=10.5.0
 
 int x;
 
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1551,7 +1551,7 @@
 options::ID Opt;
 switch (Platform) {
 case DarwinPlatformKind::MacOS:
-  Opt = options::OPT_mmacosx_version_min_EQ;
+  Opt = options::OPT_mmacos_version_min_EQ;
   break;
 case DarwinPlatformKind::IPhoneOS:
   Opt = options::OPT_miphoneos_version_min_EQ;
@@ -1727,7 +1727,7 @@
 Optional
 getDeploymentTargetFromOSVersionArg(DerivedArgList &Args,
 const Driver &TheDriver) {
-  Arg *OSXVersion = Args.getLastArg(options::OPT_mmacosx_version_min_EQ);
+  Arg *macOSVersion = Args.getLastArg(options::OPT_mmacos_version_min_EQ);
   Arg *iOSVersion = Args.getLastArg(options::OPT_miphoneos_version_min_EQ,
 
options::OPT_mios_simulator_version_min_EQ);
   Arg *TvOSVersion =
@@ -1736,15 +1736,15 @@
   Arg *WatchOSVersion =
   Args.getLastArg(options::OPT_mwatchos_version_min_EQ,
   options::OPT_mwatchos_simulator_version_min_EQ);
-  if (OSXVersion) {
+  if (macOSVersion) {
 if (iOSVersion || TvOSVersion || WatchOSVersion) {
   TheDriver.Diag(diag::err_drv_argument_not_allowed_with)
-  << OSXVersion->getAsString(Args)
+  << macOSVersion->getAsString(Args)
   << (iOSVersion ? iOSVersion
  : TvOSVersion ? TvOSVersion : WatchOSVersion)
  ->getAsString(Args);
 }
-return DarwinPlatform::createOSVersionArg(Darwin::MacOS, OSXVersion);
+return DarwinPlatform::createOSVersionArg(Darwin::MacOS, macOSVersion);
   } else if (iOSVersion) {
 if (TvOSVersion || WatchOSVersion) {
   TheDriver.Diag(diag::err_drv_argument_not_allowed_with)
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -3354,10 +3354,10 @@
 def ffuchsia_api_level_EQ : Joined<["-"], "ffuchsia-api-level=">,
   Group, Flags<[CC1Option]>, HelpText<"Set Fuchsia API level">,
   MarshallingInfoInt>;
-def mmacosx_version_min_EQ : Joined<["-"], "mmacosx-version-min=">,
-  Group, HelpText<"Set Mac OS X deployment target">;
 def mmacos_version_min_EQ : Joined<["-"], "mmacos-version-min=">,
-  Group, Alias;
+  Group, HelpText<"Set macOS deployment target">;
+def : Joined<["-"], "mmacosx-version-min=">,
+  Group, Alias;
 def mms_bitfields : Flag<["-"], "mms-bitfields">, Group, 
Flags<[CC1Option]>,
   HelpText<"Set the default structure layout to be compatible with the 
Microsoft compiler standard">,
   MarshallingInfoFlag>;


Index: clang/test/Driver/darwin-debug-flags.c
===
--- clang/test/Driver/darwin-debug-flags.c
+++ clang/test/Driver/darwin-debug-flags.c
@@ -9,7 +9,7 @@
 // CHECK-SAME:flags:
 // CHECK-SAME:-I path\\ with\\ spaces
 // CHECK-SAME:-g -Os
-// CHECK-SAME:-mmacosx-version-min=10.5.0
+// CHECK-SAME:-mmacos-version-min=10.5.0
 
 int x;
 
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1551,7 +1551,7 @@
 options::ID Opt;
 switch (Platform) {
 case DarwinPlatformKind::MacOS:
-  Opt = options::OPT_mmacosx_version_min_EQ;
+  Opt = options::OPT_mmacos_version_min_EQ;
   break;
 case DarwinPlatformKind::IPhoneOS:
   Opt = options::OPT_miphoneos_version_min_EQ;
@@ -1727,7 +1727,7 @@
 Optional
 getDeploymentTargetFromOSVersionArg(DerivedArgList &Args,
 const Driver &TheDriver) {
-  Arg *OSXVersion = Args.

[PATCH] D129068: [AST] Accept identical TypeConstraint referring to other template parameters.

2022-07-12 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai accepted this revision as: vsapsai.
vsapsai added a comment.
This revision is now accepted and ready to land.

My comments are addressed, thanks for making the changes!

Please wait for @ilya-biryukov's approval to confirm he has nothing else to add.


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

https://reviews.llvm.org/D129068

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


[PATCH] D129068: [AST] Accept identical TypeConstraint referring to other template parameters.

2022-07-12 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov accepted this revision.
ilya-biryukov added a comment.

LGTM, thanks!


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

https://reviews.llvm.org/D129068

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


[clang] 2b9055c - [PS4/PS5] NFC: Use preferred predicate in a triple check

2022-07-12 Thread Paul Robinson via cfe-commits

Author: Paul Robinson
Date: 2022-07-12T08:10:25-07:00
New Revision: 2b9055cee657fbec1afa93da3751bb923649fbde

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

LOG: [PS4/PS5] NFC: Use preferred predicate in a triple check

Also add a test to verify this difference in the PS4/PS5 ABIs,
now that we have identified it.

Added: 


Modified: 
clang/lib/Basic/TargetInfo.cpp
clang/test/CodeGenCXX/uncopyable-args.cpp

Removed: 




diff  --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp
index e22ed34e7da46..6685145ea6d2e 100644
--- a/clang/lib/Basic/TargetInfo.cpp
+++ b/clang/lib/Basic/TargetInfo.cpp
@@ -503,7 +503,7 @@ bool TargetInfo::initFeatureMap(
 TargetInfo::CallingConvKind
 TargetInfo::getCallingConvKind(bool ClangABICompat4) const {
   if (getCXXABI() != TargetCXXABI::Microsoft &&
-  (ClangABICompat4 || getTriple().getOS() == llvm::Triple::PS4))
+  (ClangABICompat4 || getTriple().isPS4()))
 return CCK_ClangABI4OrPS4;
   return CCK_Default;
 }

diff  --git a/clang/test/CodeGenCXX/uncopyable-args.cpp 
b/clang/test/CodeGenCXX/uncopyable-args.cpp
index 529bc3baf798d..e03c9970747a5 100644
--- a/clang/test/CodeGenCXX/uncopyable-args.cpp
+++ b/clang/test/CodeGenCXX/uncopyable-args.cpp
@@ -1,6 +1,7 @@
 // RUN: %clang_cc1 -no-opaque-pointers -std=c++11 -triple 
x86_64-unknown-unknown -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK 
--check-prefix=NEWABI
 // RUN: %clang_cc1 -no-opaque-pointers -std=c++11 -triple 
x86_64-unknown-unknown -fclang-abi-compat=4.0 -emit-llvm -o - %s | FileCheck %s 
--check-prefix=CHECK --check-prefix=OLDABI
 // RUN: %clang_cc1 -no-opaque-pointers -std=c++11 -triple x86_64-scei-ps4 
-emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK --check-prefix=OLDABI
+// RUN: %clang_cc1 -no-opaque-pointers -std=c++11 -triple x86_64-sie-ps5  
-emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK --check-prefix=NEWABI
 // RUN: %clang_cc1 -no-opaque-pointers -std=c++11 -triple x86_64-windows-msvc 
-emit-llvm -o - %s -fms-compatibility -fms-compatibility-version=18 | FileCheck 
%s -check-prefix=WIN64 -check-prefix=WIN64-18
 // RUN: %clang_cc1 -no-opaque-pointers -std=c++11 -triple x86_64-windows-msvc 
-emit-llvm -o - %s -fms-compatibility -fms-compatibility-version=19 | FileCheck 
%s -check-prefix=WIN64 -check-prefix=WIN64-19
 



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


[PATCH] D112374: [clang] Implement ElaboratedType sugaring for types written bare

2022-07-12 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov marked 7 inline comments as done.
mizvekov added a subscriber: sammccall.
mizvekov added a comment.
Herald added a subscriber: steakhal.
Herald added a reviewer: NoQ.

In D112374#3535949 , @rsmith wrote:

> I've not looked at the test changes in any detail; please let me know if 
> there's anything in there that deserves special attention.

The new (since last rebase) change in 
`clang-tools-extra/test/clang-tidy/checkers/bugprone/shared-ptr-array-mismatch.cpp`
 might be worth a look.
I think this is a fix, and the pre-existing code missed it by pure accident.

I am not sure there are any scenarios where we might want to avoid suggesting 
this fix in dependent contexts, if there were we should throw a FIXME in there.

There are a couple of minor significant changes since the last diff, might be 
worth an extra look, but mainly some minor conflicts with the introduction of 
UsingType by @sammccall .




Comment at: llvm/include/llvm/Support/SizeOf.h:20-23
+/// A sizeof operator stand-in which supports `sizeof(void) == 0`.
+///
+template  struct SizeOf { static constexpr size_t value = sizeof(T); 
};
+template <> struct SizeOf { static constexpr size_t value = 0; };

rsmith wrote:
> I think it's too surprising to call this simply `SizeOf`, especially given 
> that under 
> https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0146r1.html we 
> might eventually see C++ defining `sizeof(void)` as some non-zero value.
The author merely suggests the two issues are independent :)

If this paper ever gets followed up on, leaving `sizeof(void) != 0` would be a 
riot!



Comment at: llvm/include/llvm/Support/SizeOf.h:25-32
+/// An alignof operator stand-in which supports `alignof(void) == 1`.
+///
+template  struct AlignOf {
+  static constexpr size_t value = alignof(T);
+};
+template <> struct AlignOf { static constexpr size_t value = 1; };
+

rsmith wrote:
> There's already a (different!) `llvm::AlignOf` in `llvm/Support/AlignOf.h`.
Well that is the one which is surprising to simply call `AlignOf` =)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112374

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


[PATCH] D112374: [clang] Implement ElaboratedType sugaring for types written bare

2022-07-12 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov edited the summary of this revision.
mizvekov updated this revision to Diff 443951.
mizvekov marked 2 inline comments as done.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112374

Files:
  clang-tools-extra/clang-change-namespace/ChangeNamespace.cpp
  clang-tools-extra/clang-include-fixer/find-all-symbols/FindAllSymbols.cpp
  clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SmartPtrArrayMismatchCheck.cpp
  clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
  clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp
  clang-tools-extra/clang-tidy/misc/MisplacedConstCheck.cpp
  clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
  clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
  clang-tools-extra/clangd/FindTarget.cpp
  clang-tools-extra/clangd/unittests/ASTTests.cpp
  clang-tools-extra/clangd/unittests/DumpASTTests.cpp
  clang-tools-extra/clangd/unittests/FindTargetTests.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone/copy-constructor-init.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone/shared-ptr-array-mismatch.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-memory-comparison-32bits.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-memory-comparison.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability/const-return-type.cpp
  clang-tools-extra/unittests/clang-change-namespace/ChangeNamespaceTests.cpp
  clang/bindings/python/tests/cindex/test_type.py
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeLoc.h
  clang/lib/ARCMigrate/ObjCMT.cpp
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTDiagnostic.cpp
  clang/lib/AST/DeclCXX.cpp
  clang/lib/AST/ExprCXX.cpp
  clang/lib/AST/FormatString.cpp
  clang/lib/AST/PrintfFormatString.cpp
  clang/lib/AST/QualTypeNames.cpp
  clang/lib/AST/ScanfFormatString.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypeLoc.cpp
  clang/lib/Analysis/RetainSummaryManager.cpp
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaExprObjC.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Sema/TypeLocBuilder.cpp
  clang/lib/Sema/TypeLocBuilder.h
  clang/lib/StaticAnalyzer/Checkers/NonnullGlobalConstantsChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/NumberObjectConversionChecker.cpp
  clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.cpp
  clang/test/AST/ast-dump-APValue-anon-union.cpp
  clang/test/AST/ast-dump-APValue-struct.cpp
  clang/test/AST/ast-dump-APValue-union.cpp
  clang/test/AST/ast-dump-decl.cpp
  clang/test/AST/ast-dump-expr-json.cpp
  clang/test/AST/ast-dump-expr.cpp
  clang/test/AST/ast-dump-funcs.cpp
  clang/test/AST/ast-dump-openmp-begin-declare-variant_template_3.cpp
  clang/test/AST/ast-dump-overloaded-operators.cpp
  clang/test/AST/ast-dump-records-json.cpp
  clang/test/AST/ast-dump-recovery.cpp
  clang/test/AST/ast-dump-stmt-json.cpp
  clang/test/AST/ast-dump-stmt.cpp
  clang/test/AST/ast-dump-template-decls-json.cpp
  clang/test/AST/ast-dump-temporaries-json.cpp
  clang/test/AST/ast-dump-using-template.cpp
  clang/test/AST/ast-dump-using.cpp
  clang/test/AST/coroutine-locals-cleanup-exp-namespace.cpp
  clang/test/AST/coroutine-locals-cleanup.cpp
  clang/test/AST/float16.cpp
  clang/test/AST/sourceranges.cpp
  clang/test/Analysis/Inputs/expected-plists/NewDelete-path-notes.cpp.plist
  clang/test/Analysis/Inputs/expected-plists/cxx-for-range.cpp.plist
  clang/test/Analysis/Inputs/expected-plists/method-call-path-notes.cpp.plist
  clang/test/Analysis/analyzer-display-progress.cpp
  clang/test/Analysis/auto-obj-dtors-cfg-output.cpp
  clang/test/Analysis/blocks.mm
  clang/test/Analysis/bug_hash_test.cpp
  clang/test/Analysis/cast-value-notes.cpp
  clang/test/Analysis/cast-value-state-dump.cpp
  clang/test/Analysis/cfg-rich-constructors.cpp
  clang/test/Analysis/cfg-rich-constructors.mm
  clang/test/Analysis/cfg.cpp
  clang/test/Analysis/copy-elision.cpp
  clang/test/Analysis/cxx-uninitialized-object-inheritance.cpp
  clang/test/Analysis/dump_egraph.cpp
  clang/test/Analysis/exploded-graph-rewriter/dynamic_types.cpp
  clang/test/Analysis/initializers-cfg-output.cpp
  clang/test/Analysis/inlining/I

[PATCH] D129389: [clang][deps] Override dependency and serialized diag files for modules

2022-07-12 Thread Ben Langmuir via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6626f6fec3d3: [clang][deps] Override dependency and 
serialized diag files for modules (authored by benlangmuir).

Changed prior to commit:
  https://reviews.llvm.org/D129389?vs=443755&id=443955#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129389

Files:
  clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h
  clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
  clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/test/ClangScanDeps/Inputs/preserved-args/cdb.json.template
  clang/test/ClangScanDeps/Inputs/preserved-args/mod.h
  clang/test/ClangScanDeps/Inputs/preserved-args/module.modulemap
  clang/test/ClangScanDeps/Inputs/preserved-args/tu.c
  clang/test/ClangScanDeps/Inputs/removed-args/cdb.json.template
  clang/test/ClangScanDeps/generate-modules-path-args.c
  clang/test/ClangScanDeps/preserved-args.c
  clang/test/ClangScanDeps/removed-args.c
  clang/tools/clang-scan-deps/ClangScanDeps.cpp

Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp
===
--- clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -288,11 +288,12 @@
   Modules.insert(I, {{MD.ID, InputIndex}, std::move(MD)});
 }
 
-ID.CommandLine = GenerateModulesPathArgs
- ? FD.getCommandLine(
-   [&](ModuleID MID) { return lookupPCMPath(MID); })
- : FD.getCommandLineWithoutModulePaths();
-
+ID.CommandLine =
+GenerateModulesPathArgs
+? FD.getCommandLine([&](const ModuleID &MID, ModuleOutputKind MOK) {
+return lookupModuleOutput(MID, MOK);
+  })
+: FD.getCommandLineWithoutModulePaths();
 Inputs.push_back(std::move(ID));
   }
 
@@ -325,7 +326,9 @@
   {"command-line",
GenerateModulesPathArgs
? MD.getCanonicalCommandLine(
- [&](ModuleID MID) { return lookupPCMPath(MID); })
+ [&](const ModuleID &MID, ModuleOutputKind MOK) {
+   return lookupModuleOutput(MID, MOK);
+ })
: MD.getCanonicalCommandLineWithoutModulePaths()},
   };
   OutModules.push_back(std::move(O));
@@ -352,11 +355,22 @@
   }
 
 private:
-  StringRef lookupPCMPath(ModuleID MID) {
+  std::string lookupModuleOutput(const ModuleID &MID, ModuleOutputKind MOK) {
+// Cache the PCM path, since it will be queried repeatedly for each module.
+// The other outputs are only queried once during getCanonicalCommandLine.
 auto PCMPath = PCMPaths.insert({MID, ""});
 if (PCMPath.second)
   PCMPath.first->second = constructPCMPath(MID);
-return PCMPath.first->second;
+switch (MOK) {
+case ModuleOutputKind::ModuleFile:
+  return PCMPath.first->second;
+case ModuleOutputKind::DependencyFile:
+  return PCMPath.first->second + ".d";
+case ModuleOutputKind::DependencyTargets:
+  return ""; // Will get the default target name.
+case ModuleOutputKind::DiagnosticSerializationFile:
+  return PCMPath.first->second + ".diag";
+}
   }
 
   /// Construct a path for the explicitly built PCM.
Index: clang/test/ClangScanDeps/removed-args.c
===
--- clang/test/ClangScanDeps/removed-args.c
+++ clang/test/ClangScanDeps/removed-args.c
@@ -29,6 +29,9 @@
 // CHECK-NOT:  "-fbuild-session-timestamp=
 // CHECK-NOT:  "-fmodules-prune-interval=
 // CHECK-NOT:  "-fmodules-prune-after=
+// CHECK-NOT:  "-dependency-file"
+// CHECK-NOT:  "-MT"
+// CHECK-NOT:  "-serialize-diagnostic-file"
 // CHECK:],
 // CHECK-NEXT:   "context-hash": "[[HASH_MOD_HEADER:.*]]",
 // CHECK-NEXT:   "file-deps": [
@@ -50,6 +53,9 @@
 // CHECK-NOT:  "-fbuild-session-timestamp=
 // CHECK-NOT:  "-fmodules-prune-interval=
 // CHECK-NOT:  "-fmodules-prune-after=
+// CHECK-NOT:  "-dependency-file"
+// CHECK-NOT:  "-MT"
+// CHECK-NOT:  "-serialize-diagnostic-file"
 // CHECK:],
 // CHECK-NEXT:   "context-hash": "[[HASH_MOD_TU:.*]]",
 // CHECK-NEXT:   "file-deps": [
Index: clang/test/ClangScanDeps/preserved-args.c
===
--- clang/test/ClangScanDeps/preserved-args.c
+++ /dev/null
@@ -1,24 +0,0 @@
-// RUN: rm -rf %t && mkdir %t
-// RUN: cp -r %S/Inputs/preserved-args/* %t
-// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
-
-// RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full > %t/result.json
-// RUN: cat %t/res

[clang] 6626f6f - [clang][deps] Override dependency and serialized diag files for modules

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

Author: Ben Langmuir
Date: 2022-07-12T08:19:52-07:00
New Revision: 6626f6fec3d37b78b628b858bdadbbb8301e1a2f

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

LOG: [clang][deps] Override dependency and serialized diag files for modules

When building modules, override secondary outputs (dependency file,
dependency targets, serialized diagnostic file) in addition to the pcm
file path. This avoids inheriting per-TU command-line options that
cause non-determinism in the results (non-deterministic command-line for
the module build, non-determinism in which TU's .diag and .d files will
contain the module outputs). In clang-scan-deps we infer whether to
generate dependency or serialized diagnostic files based on an original
command-line. In a real build system this should be modeled explicitly.

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

Added: 
clang/test/ClangScanDeps/generate-modules-path-args.c

Modified: 
clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h
clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
clang/test/ClangScanDeps/Inputs/removed-args/cdb.json.template
clang/test/ClangScanDeps/removed-args.c
clang/tools/clang-scan-deps/ClangScanDeps.cpp

Removed: 
clang/test/ClangScanDeps/Inputs/preserved-args/cdb.json.template
clang/test/ClangScanDeps/Inputs/preserved-args/mod.h
clang/test/ClangScanDeps/Inputs/preserved-args/module.modulemap
clang/test/ClangScanDeps/Inputs/preserved-args/tu.c
clang/test/ClangScanDeps/preserved-args.c



diff  --git 
a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h 
b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h
index 3bb44e44187ba..a85d333ba6b18 100644
--- a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h
+++ b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h
@@ -47,12 +47,12 @@ struct FullDependencies {
 
   /// Get the full command line.
   ///
-  /// \param LookupPCMPath This function is called to fill in "-fmodule-file="
-  ///  arguments and the "-o" argument. It needs to return
-  ///  a path for where the PCM for the given module is to
-  ///  be located.
-  std::vector
-  getCommandLine(std::function LookupPCMPath) const;
+  /// \param LookupModuleOutput This function is called to fill in
+  ///   "-fmodule-file=", "-o" and other output
+  ///   arguments for dependencies.
+  std::vector getCommandLine(
+  llvm::function_ref
+  LookupOutput) const;
 
   /// Get the full command line, excluding -fmodule-file=" arguments.
   std::vector getCommandLineWithoutModulePaths() const;

diff  --git 
a/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h 
b/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
index e0a4d6a554eb2..cb68df8314da1 100644
--- a/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
+++ b/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
@@ -65,6 +65,19 @@ struct ModuleIDHasher {
   }
 };
 
+/// An output from a module compilation, such as the path of the module file.
+enum class ModuleOutputKind {
+  /// The module file (.pcm). Required.
+  ModuleFile,
+  /// The path of the dependency file (.d), if any.
+  DependencyFile,
+  /// The null-separated list of names to use as the targets in the dependency
+  /// file, if any.
+  DependencyTargets,
+  /// The path of the serialized diagnostic file (.dia), if any.
+  DiagnosticSerializationFile,
+};
+
 struct ModuleDeps {
   /// The identifier of the module.
   ModuleID ID;
@@ -104,17 +117,25 @@ struct ModuleDeps {
   // the primary TU.
   bool ImportedByMainFile = false;
 
+  /// Whether the TU had a dependency file. The path in \c BuildInvocation is
+  /// cleared to avoid leaking the specific path from the TU into the module.
+  bool HadDependencyFile = false;
+
+  /// Whether the TU had serialized diagnostics. The path in \c BuildInvocation
+  /// is cleared to avoid leaking the specific path from the TU into the 
module.
+  bool HadSerializedDiagnostics = false;
+
   /// Compiler invocation that can be used to build this module (without 
paths).
   CompilerInvocation BuildInvocation;
 
   /// Gets the canonical command line suitable for passing to clang.
   ///
-  /// \param LookupPCMPath This function is called to fill in "-fmodule-file="
-  ///  arguments and the "-o" argument. It needs to return
-  ///  a path for where the PCM for the given mo

[PATCH] D128974: [RFC] [AST] [Modules] Handle full cases of DefaultArgStorage::setInherited

2022-07-12 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev accepted this revision.
v.g.vassilev added a comment.
This revision is now accepted and ready to land.

LGTM!


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

https://reviews.llvm.org/D128974

___
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-12 Thread Krzysztof Drewniak 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 rGd6ef3d20b4e3: [mlir] Remove VectorToROCDL (authored by 
krzysz00).

Repository:
  rG LLVM Github Monorepo

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

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",
 ],
@@ -3804,30 +3803,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([
@@ -3895,7 +3870,6 @@
 ":Transforms",
 ":VectorDialect",
 ":VectorToLLVM",
-":VectorToROCDL",
 ":VectorToSCF",
 "//llvm:Support",
 ],
@@ -6348,7 +6322,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
-{permutation_map = affine_map<(d0) -> (d0)>} :
-  memref, vector<2xf32>
+%base = arith.constant 0 : i32
+%f = amdgpu.raw_buffer_load {boundsCheck = true } %arg0[%base]
+  : memref, i32 -> vector<2xf32>
 
 %c = arith.addf %f, %f : vector<2xf32>
 
-%base1 = arith.constant 1 : index
-vector.transfer_write %c, %arg1[%base1]
-{permutation_map = affine_map<(d0) -> (d0)>} :
-  vector<2xf32>, memref
+%base1 = arith.constant 1 : i32
+amdgpu.raw_buffer_store { boundsCheck = false } %c -> %arg1[%base1]
+  : vector<2xf32> -> memref, i32
 
 gpu.terminator
   }
@@ -36,16 +35,14 @@
   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
-{permutation_map = affine_map<(d0) -> (d0)>} :
-  memref, vector<4xf32>
+%base = arith.constant 0 : i32
+%f = amdgpu.raw_buffer_load { boundsCheck = false } %arg0[%base]
+  : memref, i32 -> vector<4xf32>
 
 %c = arith.addf %

[clang] d6ef3d2 - [mlir] Remove VectorToROCDL

2022-07-12 Thread Krzysztof Drewniak via cfe-commits

Author: Krzysztof Drewniak
Date: 2022-07-12T15:21:22Z
New Revision: d6ef3d20b4e3768dc30fb229dfa938d8059fffef

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

LOG: [mlir] Remove VectorToROCDL

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.

Reviewed By: ThomasRaoux

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

Added: 


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

Removed: 
mlir/include/mlir/Conversion/VectorToROCDL/VectorToROCDL.h
mlir/lib/Conversion/VectorToROCDL/CMakeLists.txt
mlir/lib/Conversion/VectorToROCDL/VectorToROCDL.cpp
mlir/test/Conversion/VectorToROCDL/vector-to-rocdl.mlir



diff  --git a/clang/docs/ClangFormattedStatus.rst 
b/clang/docs/ClangFormattedStatus.rst
index 7e714f67ffe3c..6f62c97f85ba9 100644
--- a/clang/docs/ClangFormattedStatus.rst
+++ b/clang/docs/ClangFormattedStatus.rst
@@ -6829,11 +6829,6 @@ tree in terms of conformance to :doc:`ClangFormat` as 
of: March 06, 2022 17:32:2
  - `1`
  - `0`
  - :good:`100%`
-   * - mlir/include/mlir/Conversion/VectorToROCDL
- - `1`
- - `1`
- - `0`
- - :good:`100%`
* - mlir/include/mlir/Conversion/VectorToSCF
  - `1`
  - `1`
@@ -7609,11 +7604,6 @@ tree in terms of conformance to :doc:`ClangFormat` as 
of: March 06, 2022 17:32:2
  - `2`
  - `0`
  - :good:`100%`
-   * - mlir/lib/Conversion/VectorToROCDL
- - `1`
- - `1`
- - `0`
- - :good:`100%`
* - mlir/lib/Conversion/VectorToSCF
  - `1`
  - `1`

diff  --git a/clang/docs/tools/clang-formatted-files.txt 
b/clang/docs/tools/clang-formatted-files.txt
index 5e1c6f130a0e4..cc55f9b4d85f4 100644
--- a/clang/docs/tools/clang-formatted-files.txt
+++ b/clang/docs/tools/clang-formatted-files.txt
@@ -7627,7 +7627,6 @@ mlir/include/mlir/Conversion/TosaToSCF/TosaToSCF.h
 mlir/include/mlir/Conversion/TosaToStandard/TosaToStandard.h
 mlir/include/mlir/Conversion/VectorToGPU/VectorToGPU.h
 mlir/include/mlir/Conversion/VectorToLLVM/ConvertVectorToLLVM.h
-mlir/include/mlir/Conversion/VectorToROCDL/VectorToROCDL.h
 mlir/include/mlir/Conversion/VectorToSCF/VectorToSCF.h
 mlir/include/mlir/Conversion/VectorToSPIRV/VectorToSPIRV.h
 mlir/include/mlir/Conversion/VectorToSPIRV/VectorToSPIRVPass.h
@@ -8068,7 +8067,6 @@ mlir/lib/Conversion/TosaToStandard/TosaToStandard.cpp
 mlir/lib/Conversion/TosaToStandard/TosaToStandardPass.cpp
 mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp
 mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVMPass.cpp
-mlir/lib/Conversion/VectorToROCDL/VectorToROCDL.cpp
 mlir/lib/Conversion/VectorToSCF/VectorToSCF.cpp
 mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRVPass.cpp
 mlir/lib/Dialect/Traits.cpp

diff  --git a/mlir/include/mlir/Conversion/Passes.h 
b/mlir/include/mlir/Conversion/Passes.h
index 5ffdc2d3e5af7..9f10e9459f450 100644
--- a/mlir/include/mlir/Conversion/Passes.h
+++ b/mlir/include/mlir/Conversion/Passes.h
@@ -57,7 +57,6 @@
 #include "mlir/Conversion/TosaToTensor/TosaToTensor.h"
 #include "mlir/Conversion/VectorToGPU/VectorToGPU.h"
 #include "mlir/Conversion/VectorToLLVM/ConvertVectorToLLVM.h"
-#include "mlir/Conversion/VectorToROCDL/VectorToROCDL.h"
 #include "mlir/Conversion/VectorToSCF/VectorToSCF.h"
 #include "mlir/Conversion/VectorToSPIRV/VectorToSPIRVPass.h"
 

diff  --git a/mlir/include/mlir/Conversion/Passes.td 
b/mlir/include/mlir/Conversion/Passes.td
index 3098e7a73be44..d2a076f21ac2d 100644
--- a/mlir/include/mlir/Conversion/Passes.td
+++ b/mlir/include/mlir/Conversion/Passes.td
@@ -854,12 +854,12 @@ def ConvertVectorToGPU : Pass<"convert-vector-to-gpu"> {
 

[PATCH] D126907: Deferred Concept Instantiation Implementation Take 2

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



Comment at: clang/lib/Sema/SemaTemplateInstantiate.cpp:963-964
+  Entity(Entity),
+  EvaluatingAConstraint(EvaluatingConstraint ||
+!SemaRef.CurContext->isDependentContext()) {}
 

ChuanqiXu wrote:
> erichkeane wrote:
> > ChuanqiXu wrote:
> > > I would like to see this in call site and a comment to tell us that we 
> > > don't want to evaluate constraints in dependent context.
> > So you want this logic moved to the call-sites?  Or am I misinterpreting 
> > that?
> Yes. It is odd **for me** to do logic operations in the initialization list.
Got it, that makes sense.

Though when looking at it, I found myself wondering why I did this change, it 
seems to 'undo' a lot of the deferred concepts work :/


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


[PATCH] D129104: [Modules] Add ODR Check for concepts

2022-07-12 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu updated this revision to Diff 443957.
ChuanqiXu added a comment.

Add ReleaseNotes.


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

https://reviews.llvm.org/D129104

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/ASTContext.cpp
  clang/test/Modules/concept_differ.cpp
  clang/test/Modules/concept_differ.cppm

Index: clang/test/Modules/concept_differ.cppm
===
--- /dev/null
+++ clang/test/Modules/concept_differ.cppm
@@ -0,0 +1,39 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -x c++ -std=c++20 %t/A.cppm -I%t -emit-module-interface -o %t/A.pcm
+// RUN: %clang_cc1 -x c++ -std=c++20 %t/B.cppm -I%t -emit-module-interface -o %t/B.pcm
+// RUN: %clang_cc1 -x c++ -std=c++20 -fprebuilt-module-path=%t %t/foo.cpp -verify
+
+//--- foo.h
+template 
+concept A = true;
+
+//--- bar.h
+template 
+concept A = false;
+
+//--- A.cppm
+module;
+#include "foo.h"
+export module A;
+export using ::A;
+
+//--- B.cppm
+module;
+#include "bar.h"
+export module B;
+export using ::A;
+
+//--- foo.cpp
+import A;
+import B;
+
+template  void foo() requires A {}  // expected-error 1+{{reference to 'A' is ambiguous}}
+// expected-note@* 1+{{candidate found by name lookup}}
+
+int main() {
+  foo();
+  return 0;
+}
Index: clang/test/Modules/concept_differ.cpp
===
--- /dev/null
+++ clang/test/Modules/concept_differ.cpp
@@ -0,0 +1,35 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -x c++ -std=c++20 -fmodules -fmodules-cache-path=%t -fmodule-map-file=%t/module.map %t/foo.cpp -verify
+
+//--- module.map
+module "foo" {
+  export * 
+  header "foo.h"
+}
+module "bar" {
+  export * 
+  header "bar.h"
+}
+
+//--- foo.h
+template 
+concept A = true;
+
+//--- bar.h
+template 
+concept A = false;
+
+//--- foo.cpp
+#include "bar.h"
+#include "foo.h"
+
+template  void foo() requires A {}  // expected-error 1+{{reference to 'A' is ambiguous}}
+// expected-note@* 1+{{candidate found by name lookup}}
+
+int main() {
+  foo();
+  return 0;
+}
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -6561,6 +6561,20 @@
   // and patterns match.
   if (const auto *TemplateX = dyn_cast(X)) {
 const auto *TemplateY = cast(Y);
+
+// ConceptDecl wouldn't be the same if their constraint expression differs.
+if (const auto *ConceptX = dyn_cast(X)) {
+  const auto *ConceptY = cast(Y);
+  const Expr *XCE = ConceptX->getConstraintExpr();
+  const Expr *YCE = ConceptY->getConstraintExpr();
+  assert(XCE && YCE && "ConceptDecl without constraint expression?");
+  llvm::FoldingSetNodeID XID, YID;
+  XCE->Profile(XID, *this, /*Canonical=*/true);
+  YCE->Profile(YID, *this, /*Canonical=*/true);
+  if (XID != YID)
+return false;
+}
+
 return isSameEntity(TemplateX->getTemplatedDecl(),
 TemplateY->getTemplatedDecl()) &&
isSameTemplateParameterList(TemplateX->getTemplateParameters(),
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -183,6 +183,9 @@
   initializer is not allowed this is now diagnosed as an error.
 - Clang now correctly emits symbols for implicitly instantiated constexpr
   template function. Fixes `Issue 55560 `_.
+- Clang now would check ODR violations when merging concepts from different modules.
+  Note that it may break existing codes and the behavior is intended.
+  Fixes `Issue 56310 `_.
 
 Improvements to Clang's diagnostics
 ^^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129104: [Modules] Add ODR Check for concepts

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



Comment at: clang/docs/ReleaseNotes.rst:186
   template function. Fixes `Issue 55560 
`_.
+- Clang now would check ODR violations when merging concepts from different 
modules.
+  Note that it may break existing codes and the behavior is intended.





Comment at: clang/docs/ReleaseNotes.rst:187
+- Clang now would check ODR violations when merging concepts from different 
modules.
+  Note that it may break existing codes and the behavior is intended.
+  Fixes `Issue 56310 `_.




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

https://reviews.llvm.org/D129104

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


[PATCH] D129104: [Modules] Add ODR Check for concepts

2022-07-12 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu updated this revision to Diff 443958.
ChuanqiXu added a comment.

Address comments.


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

https://reviews.llvm.org/D129104

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/ASTContext.cpp
  clang/test/Modules/concept_differ.cpp
  clang/test/Modules/concept_differ.cppm

Index: clang/test/Modules/concept_differ.cppm
===
--- /dev/null
+++ clang/test/Modules/concept_differ.cppm
@@ -0,0 +1,39 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -x c++ -std=c++20 %t/A.cppm -I%t -emit-module-interface -o %t/A.pcm
+// RUN: %clang_cc1 -x c++ -std=c++20 %t/B.cppm -I%t -emit-module-interface -o %t/B.pcm
+// RUN: %clang_cc1 -x c++ -std=c++20 -fprebuilt-module-path=%t %t/foo.cpp -verify
+
+//--- foo.h
+template 
+concept A = true;
+
+//--- bar.h
+template 
+concept A = false;
+
+//--- A.cppm
+module;
+#include "foo.h"
+export module A;
+export using ::A;
+
+//--- B.cppm
+module;
+#include "bar.h"
+export module B;
+export using ::A;
+
+//--- foo.cpp
+import A;
+import B;
+
+template  void foo() requires A {}  // expected-error 1+{{reference to 'A' is ambiguous}}
+// expected-note@* 1+{{candidate found by name lookup}}
+
+int main() {
+  foo();
+  return 0;
+}
Index: clang/test/Modules/concept_differ.cpp
===
--- /dev/null
+++ clang/test/Modules/concept_differ.cpp
@@ -0,0 +1,35 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -x c++ -std=c++20 -fmodules -fmodules-cache-path=%t -fmodule-map-file=%t/module.map %t/foo.cpp -verify
+
+//--- module.map
+module "foo" {
+  export * 
+  header "foo.h"
+}
+module "bar" {
+  export * 
+  header "bar.h"
+}
+
+//--- foo.h
+template 
+concept A = true;
+
+//--- bar.h
+template 
+concept A = false;
+
+//--- foo.cpp
+#include "bar.h"
+#include "foo.h"
+
+template  void foo() requires A {}  // expected-error 1+{{reference to 'A' is ambiguous}}
+// expected-note@* 1+{{candidate found by name lookup}}
+
+int main() {
+  foo();
+  return 0;
+}
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -6561,6 +6561,20 @@
   // and patterns match.
   if (const auto *TemplateX = dyn_cast(X)) {
 const auto *TemplateY = cast(Y);
+
+// ConceptDecl wouldn't be the same if their constraint expression differs.
+if (const auto *ConceptX = dyn_cast(X)) {
+  const auto *ConceptY = cast(Y);
+  const Expr *XCE = ConceptX->getConstraintExpr();
+  const Expr *YCE = ConceptY->getConstraintExpr();
+  assert(XCE && YCE && "ConceptDecl without constraint expression?");
+  llvm::FoldingSetNodeID XID, YID;
+  XCE->Profile(XID, *this, /*Canonical=*/true);
+  YCE->Profile(YID, *this, /*Canonical=*/true);
+  if (XID != YID)
+return false;
+}
+
 return isSameEntity(TemplateX->getTemplatedDecl(),
 TemplateY->getTemplatedDecl()) &&
isSameTemplateParameterList(TemplateX->getTemplateParameters(),
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -183,6 +183,9 @@
   initializer is not allowed this is now diagnosed as an error.
 - Clang now correctly emits symbols for implicitly instantiated constexpr
   template function. Fixes `Issue 55560 `_.
+- Clang now checks ODR violations when merging concepts from different modules.
+  Note that this is expected to break existing code, and is done so intentionally.
+  Fixes `Issue 56310 `_.
 
 Improvements to Clang's diagnostics
 ^^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129104: [Modules] Add ODR Check for concepts

2022-07-12 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu marked 2 inline comments as done.
ChuanqiXu added inline comments.



Comment at: clang/docs/ReleaseNotes.rst:187
+- Clang now would check ODR violations when merging concepts from different 
modules.
+  Note that it may break existing codes and the behavior is intended.
+  Fixes `Issue 56310 `_.

erichkeane wrote:
> 
Although as a non-native speaker, the current wording looks like the new clang 
is going to break existing code and what I want to say it is only **possible**.

I followed your suggestion since I feel it might not be meaningful to argue 
English with a native speaker : )


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

https://reviews.llvm.org/D129104

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


[PATCH] D129068: [AST] Accept identical TypeConstraint referring to other template parameters.

2022-07-12 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu marked an inline comment as done.
ChuanqiXu added a comment.

Thanks for reviewing!


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

https://reviews.llvm.org/D129068

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


[PATCH] D129389: [clang][deps] Override dependency and serialized diag files for modules

2022-07-12 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir added inline comments.



Comment at: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp:341-342
+  !MDC.OriginalInvocation.getDependencyOutputOpts().OutputFile.empty();
+  // FIXME: HadSerializedDiagnostics and HadDependencyFile should be included 
in
+  // the context hash since it can affect the command-line.
   MD.ID.ContextHash = MD.BuildInvocation.getModuleHash();

jansvoboda11 wrote:
> This is a bit unfortunate but I don't see a better alternative.
> 
> Ideally, we would compute the hash with the `.d` and `.dia` paths already 
> filled in. That would ensure the command line we end up reporting to the 
> build system really **does** have the context hash associated with the 
> module. (We'd need to include every field set in `getCanonicalCommandLine()` 
> too.) But for the path lookup, we already need some kind of (currently 
> partial) context hash.
The other things added in getCanonicalCommandLine are currently:
* module map path - I'm planning to include this in my changes to the context 
hash since it is significant exactly how the path is spelled. This is already 
part of the implicit module build's notion of identity.
* pcm paths - these are sound as long as we always get the same paths returned 
in the callback during a build (across separate builds it would be fine to 
change them as long as you're going to rebuild anything whose path changed, and 
anything downstream of that).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129389

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


[PATCH] D129104: [Modules] Add ODR Check for concepts

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



Comment at: clang/docs/ReleaseNotes.rst:187
+- Clang now would check ODR violations when merging concepts from different 
modules.
+  Note that it may break existing codes and the behavior is intended.
+  Fixes `Issue 56310 `_.

ChuanqiXu wrote:
> erichkeane wrote:
> > 
> Although as a non-native speaker, the current wording looks like the new 
> clang is going to break existing code and what I want to say it is only 
> **possible**.
> 
> I followed your suggestion since I feel it might not be meaningful to argue 
> English with a native speaker : )
Hmm, you're right about that being a subtlety that I didn't pick up.

We could consider changing 'expected to' to 'likely to', or replace 'is 
expected to' could be 'may' (or even 'may possibly') depending on your 
confidence :)


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

https://reviews.llvm.org/D129104

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


[PATCH] D129104: [Modules] Add ODR Check for concepts

2022-07-12 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu updated this revision to Diff 443961.
ChuanqiXu marked an inline comment as done.
ChuanqiXu added a comment.

Address comments.


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

https://reviews.llvm.org/D129104

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/ASTContext.cpp
  clang/test/Modules/concept_differ.cpp
  clang/test/Modules/concept_differ.cppm

Index: clang/test/Modules/concept_differ.cppm
===
--- /dev/null
+++ clang/test/Modules/concept_differ.cppm
@@ -0,0 +1,39 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -x c++ -std=c++20 %t/A.cppm -I%t -emit-module-interface -o %t/A.pcm
+// RUN: %clang_cc1 -x c++ -std=c++20 %t/B.cppm -I%t -emit-module-interface -o %t/B.pcm
+// RUN: %clang_cc1 -x c++ -std=c++20 -fprebuilt-module-path=%t %t/foo.cpp -verify
+
+//--- foo.h
+template 
+concept A = true;
+
+//--- bar.h
+template 
+concept A = false;
+
+//--- A.cppm
+module;
+#include "foo.h"
+export module A;
+export using ::A;
+
+//--- B.cppm
+module;
+#include "bar.h"
+export module B;
+export using ::A;
+
+//--- foo.cpp
+import A;
+import B;
+
+template  void foo() requires A {}  // expected-error 1+{{reference to 'A' is ambiguous}}
+// expected-note@* 1+{{candidate found by name lookup}}
+
+int main() {
+  foo();
+  return 0;
+}
Index: clang/test/Modules/concept_differ.cpp
===
--- /dev/null
+++ clang/test/Modules/concept_differ.cpp
@@ -0,0 +1,35 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -x c++ -std=c++20 -fmodules -fmodules-cache-path=%t -fmodule-map-file=%t/module.map %t/foo.cpp -verify
+
+//--- module.map
+module "foo" {
+  export * 
+  header "foo.h"
+}
+module "bar" {
+  export * 
+  header "bar.h"
+}
+
+//--- foo.h
+template 
+concept A = true;
+
+//--- bar.h
+template 
+concept A = false;
+
+//--- foo.cpp
+#include "bar.h"
+#include "foo.h"
+
+template  void foo() requires A {}  // expected-error 1+{{reference to 'A' is ambiguous}}
+// expected-note@* 1+{{candidate found by name lookup}}
+
+int main() {
+  foo();
+  return 0;
+}
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -6561,6 +6561,20 @@
   // and patterns match.
   if (const auto *TemplateX = dyn_cast(X)) {
 const auto *TemplateY = cast(Y);
+
+// ConceptDecl wouldn't be the same if their constraint expression differs.
+if (const auto *ConceptX = dyn_cast(X)) {
+  const auto *ConceptY = cast(Y);
+  const Expr *XCE = ConceptX->getConstraintExpr();
+  const Expr *YCE = ConceptY->getConstraintExpr();
+  assert(XCE && YCE && "ConceptDecl without constraint expression?");
+  llvm::FoldingSetNodeID XID, YID;
+  XCE->Profile(XID, *this, /*Canonical=*/true);
+  YCE->Profile(YID, *this, /*Canonical=*/true);
+  if (XID != YID)
+return false;
+}
+
 return isSameEntity(TemplateX->getTemplatedDecl(),
 TemplateY->getTemplatedDecl()) &&
isSameTemplateParameterList(TemplateX->getTemplateParameters(),
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -183,6 +183,9 @@
   initializer is not allowed this is now diagnosed as an error.
 - Clang now correctly emits symbols for implicitly instantiated constexpr
   template function. Fixes `Issue 55560 `_.
+- Clang now checks ODR violations when merging concepts from different modules.
+  Note that this may possibly break existing code, and is done so intentionally.
+  Fixes `Issue 56310 `_.
 
 Improvements to Clang's diagnostics
 ^^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 4b95a5a - [Modules] Add ODR Check for concepts

2022-07-12 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2022-07-12T23:45:53+08:00
New Revision: 4b95a5a772530f78326941f26e5cb2c33212460f

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

LOG: [Modules] Add ODR Check for concepts

Closing https://github.com/llvm/llvm-project/issues/56310

Previously we don't check the contents of concept so it might merge
inconsistent results.

Important Note: this patch might break existing code but the behavior
might be right.

Reviewed By: erichkeane

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

Added: 
clang/test/Modules/concept_differ.cpp
clang/test/Modules/concept_differ.cppm

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/AST/ASTContext.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f5aecff0d2647..2898a6c1d9339 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -183,6 +183,9 @@ Bug Fixes
   initializer is not allowed this is now diagnosed as an error.
 - Clang now correctly emits symbols for implicitly instantiated constexpr
   template function. Fixes `Issue 55560 
`_.
+- Clang now checks ODR violations when merging concepts from 
diff erent modules.
+  Note that this may possibly break existing code, and is done so 
intentionally.
+  Fixes `Issue 56310 `_.
 
 Improvements to Clang's diagnostics
 ^^^

diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 748fa6ebf1d6c..aa29ce7f13840 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -6561,6 +6561,20 @@ bool ASTContext::isSameEntity(const NamedDecl *X, const 
NamedDecl *Y) const {
   // and patterns match.
   if (const auto *TemplateX = dyn_cast(X)) {
 const auto *TemplateY = cast(Y);
+
+// ConceptDecl wouldn't be the same if their constraint expression 
diff ers.
+if (const auto *ConceptX = dyn_cast(X)) {
+  const auto *ConceptY = cast(Y);
+  const Expr *XCE = ConceptX->getConstraintExpr();
+  const Expr *YCE = ConceptY->getConstraintExpr();
+  assert(XCE && YCE && "ConceptDecl without constraint expression?");
+  llvm::FoldingSetNodeID XID, YID;
+  XCE->Profile(XID, *this, /*Canonical=*/true);
+  YCE->Profile(YID, *this, /*Canonical=*/true);
+  if (XID != YID)
+return false;
+}
+
 return isSameEntity(TemplateX->getTemplatedDecl(),
 TemplateY->getTemplatedDecl()) &&
isSameTemplateParameterList(TemplateX->getTemplateParameters(),

diff  --git a/clang/test/Modules/concept_
diff er.cpp b/clang/test/Modules/concept_
diff er.cpp
new file mode 100644
index 0..23c7d4c5ecf9a
--- /dev/null
+++ b/clang/test/Modules/concept_
diff er.cpp
@@ -0,0 +1,35 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -x c++ -std=c++20 -fmodules -fmodules-cache-path=%t 
-fmodule-map-file=%t/module.map %t/foo.cpp -verify
+
+//--- module.map
+module "foo" {
+  export * 
+  header "foo.h"
+}
+module "bar" {
+  export * 
+  header "bar.h"
+}
+
+//--- foo.h
+template 
+concept A = true;
+
+//--- bar.h
+template 
+concept A = false;
+
+//--- foo.cpp
+#include "bar.h"
+#include "foo.h"
+
+template  void foo() requires A {}  // expected-error 
1+{{reference to 'A' is ambiguous}}
+// expected-note@* 
1+{{candidate found by name lookup}}
+
+int main() {
+  foo();
+  return 0;
+}

diff  --git a/clang/test/Modules/concept_
diff er.cppm b/clang/test/Modules/concept_
diff er.cppm
new file mode 100644
index 0..ccb29d26e53d1
--- /dev/null
+++ b/clang/test/Modules/concept_
diff er.cppm
@@ -0,0 +1,39 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -x c++ -std=c++20 %t/A.cppm -I%t -emit-module-interface -o 
%t/A.pcm
+// RUN: %clang_cc1 -x c++ -std=c++20 %t/B.cppm -I%t -emit-module-interface -o 
%t/B.pcm
+// RUN: %clang_cc1 -x c++ -std=c++20 -fprebuilt-module-path=%t %t/foo.cpp 
-verify
+
+//--- foo.h
+template 
+concept A = true;
+
+//--- bar.h
+template 
+concept A = false;
+
+//--- A.cppm
+module;
+#include "foo.h"
+export module A;
+export using ::A;
+
+//--- B.cppm
+module;
+#include "bar.h"
+export module B;
+export using ::A;
+
+//--- foo.cpp
+import A;
+import B;
+
+template  void foo() requires A {}  // expected-error 
1+{{reference to 'A' is ambiguous}}
+// expected-note@* 
1+{{candidate found by name lookup}}
+
+int main() {
+  foo();
+  return 0;
+}



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org

[PATCH] D129104: [Modules] Add ODR Check for concepts

2022-07-12 Thread Chuanqi Xu 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 rG4b95a5a77253: [Modules] Add ODR Check for concepts (authored 
by ChuanqiXu).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129104

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/ASTContext.cpp
  clang/test/Modules/concept_differ.cpp
  clang/test/Modules/concept_differ.cppm

Index: clang/test/Modules/concept_differ.cppm
===
--- /dev/null
+++ clang/test/Modules/concept_differ.cppm
@@ -0,0 +1,39 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -x c++ -std=c++20 %t/A.cppm -I%t -emit-module-interface -o %t/A.pcm
+// RUN: %clang_cc1 -x c++ -std=c++20 %t/B.cppm -I%t -emit-module-interface -o %t/B.pcm
+// RUN: %clang_cc1 -x c++ -std=c++20 -fprebuilt-module-path=%t %t/foo.cpp -verify
+
+//--- foo.h
+template 
+concept A = true;
+
+//--- bar.h
+template 
+concept A = false;
+
+//--- A.cppm
+module;
+#include "foo.h"
+export module A;
+export using ::A;
+
+//--- B.cppm
+module;
+#include "bar.h"
+export module B;
+export using ::A;
+
+//--- foo.cpp
+import A;
+import B;
+
+template  void foo() requires A {}  // expected-error 1+{{reference to 'A' is ambiguous}}
+// expected-note@* 1+{{candidate found by name lookup}}
+
+int main() {
+  foo();
+  return 0;
+}
Index: clang/test/Modules/concept_differ.cpp
===
--- /dev/null
+++ clang/test/Modules/concept_differ.cpp
@@ -0,0 +1,35 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -x c++ -std=c++20 -fmodules -fmodules-cache-path=%t -fmodule-map-file=%t/module.map %t/foo.cpp -verify
+
+//--- module.map
+module "foo" {
+  export * 
+  header "foo.h"
+}
+module "bar" {
+  export * 
+  header "bar.h"
+}
+
+//--- foo.h
+template 
+concept A = true;
+
+//--- bar.h
+template 
+concept A = false;
+
+//--- foo.cpp
+#include "bar.h"
+#include "foo.h"
+
+template  void foo() requires A {}  // expected-error 1+{{reference to 'A' is ambiguous}}
+// expected-note@* 1+{{candidate found by name lookup}}
+
+int main() {
+  foo();
+  return 0;
+}
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -6561,6 +6561,20 @@
   // and patterns match.
   if (const auto *TemplateX = dyn_cast(X)) {
 const auto *TemplateY = cast(Y);
+
+// ConceptDecl wouldn't be the same if their constraint expression differs.
+if (const auto *ConceptX = dyn_cast(X)) {
+  const auto *ConceptY = cast(Y);
+  const Expr *XCE = ConceptX->getConstraintExpr();
+  const Expr *YCE = ConceptY->getConstraintExpr();
+  assert(XCE && YCE && "ConceptDecl without constraint expression?");
+  llvm::FoldingSetNodeID XID, YID;
+  XCE->Profile(XID, *this, /*Canonical=*/true);
+  YCE->Profile(YID, *this, /*Canonical=*/true);
+  if (XID != YID)
+return false;
+}
+
 return isSameEntity(TemplateX->getTemplatedDecl(),
 TemplateY->getTemplatedDecl()) &&
isSameTemplateParameterList(TemplateX->getTemplateParameters(),
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -183,6 +183,9 @@
   initializer is not allowed this is now diagnosed as an error.
 - Clang now correctly emits symbols for implicitly instantiated constexpr
   template function. Fixes `Issue 55560 `_.
+- Clang now checks ODR violations when merging concepts from different modules.
+  Note that this may possibly break existing code, and is done so intentionally.
+  Fixes `Issue 56310 `_.
 
 Improvements to Clang's diagnostics
 ^^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 86a49a4 - [LinkerWrapper] Make ThinLTO work inside the linker wrapper

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

Author: Joseph Huber
Date: 2022-07-12T11:46:46-04:00
New Revision: 86a49a4f4f50c2590716bdc440a97e89f5858a4f

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

LOG: [LinkerWrapper] Make ThinLTO work inside the linker wrapper

Summary:
Previous assumptions held that the LTO stage would only have a single
output. This is incorrect when using thinLTO which outputs multiple
files. Additionally there were some bugs with how we hanlded input that
cause problems when performing thinLTO. This patch addresses these
issues.

The performance of Thin-LTO is currently pretty bad. But I am content to
leave it that way as long as it compiles.

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 11a6a4da991da..13c0a7e362a33 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -134,6 +134,7 @@ template <> struct DenseMapInfo {
 } // namespace llvm
 
 namespace {
+using std::error_code;
 
 /// Must not overlap with llvm::opt::DriverFlag.
 enum WrapperFlags {
@@ -427,7 +428,8 @@ Error extractFromBuffer(std::unique_ptr 
Buffer,
 }
 
 namespace nvptx {
-Expected assemble(StringRef InputFile, const ArgList &Args) {
+Expected assemble(StringRef InputFile, const ArgList &Args,
+ bool RDC = true) {
   // NVPTX uses the ptxas binary to create device object files.
   Expected PtxasPath = findProgram("ptxas", {CudaBinaryPath});
   if (!PtxasPath)
@@ -435,11 +437,9 @@ Expected assemble(StringRef InputFile, const 
ArgList &Args) {
 
   const llvm::Triple Triple(Args.getLastArgValue(OPT_triple_EQ));
   StringRef Arch = Args.getLastArgValue(OPT_arch_EQ);
-  // Create a new file to write the linked device image to.
-  auto TempFileOrErr =
-  createOutputFile(sys::path::filename(ExecutableName) + "-device-" +
-   Triple.getArchName() + "-" + Arch,
-   "cubin");
+  // Create a new file to write the linked device image to. Assume that the
+  // input filename already has the device and architecture.
+  auto TempFileOrErr = createOutputFile(sys::path::stem(InputFile), "cubin");
   if (!TempFileOrErr)
 return TempFileOrErr.takeError();
 
@@ -458,7 +458,7 @@ Expected assemble(StringRef InputFile, const 
ArgList &Args) {
   CmdArgs.push_back(Arch);
   if (Args.hasArg(OPT_debug))
 CmdArgs.push_back("-g");
-  if (!Args.hasArg(OPT_whole_program))
+  if (RDC)
 CmdArgs.push_back("-c");
 
   CmdArgs.push_back(InputFile);
@@ -821,11 +821,12 @@ std::unique_ptr createLTO(
 
   if (SaveTemps) {
 std::string TempName = (sys::path::filename(ExecutableName) + "-" +
-Triple.getTriple() + "-" + Arch + ".bc")
+Triple.getTriple() + "-" + Arch)
.str();
-Conf.PostInternalizeModuleHook = [=](size_t, const Module &M) {
-  std::error_code EC;
-  raw_fd_ostream LinkedBitcode(TempName, EC, sys::fs::OF_None);
+Conf.PostInternalizeModuleHook = [=](size_t Task, const Module &M) {
+  std::string Output = TempName + "." + std::to_string(Task) + ".bc";
+  error_code EC;
+  raw_fd_ostream LinkedBitcode(Output, EC, sys::fs::OF_None);
   if (EC)
 reportError(errorCodeToError(EC));
   WriteBitcodeToFile(M, LinkedBitcode);
@@ -932,7 +933,6 @@ Error linkBitcodeFiles(SmallVectorImpl 
&InputFiles,
 
   // We assume visibility of the whole program if every input file was bitcode.
   auto Features = getTargetFeatures(BitcodeInputFiles);
-  bool WholeProgram = InputFiles.empty();
   auto LTOBackend = Args.hasArg(OPT_embed_bitcode)
 ? createLTO(Args, Features, OutputBitcode)
 : createLTO(Args, Features);
@@ -940,10 +940,15 @@ Error linkBitcodeFiles(SmallVectorImpl 
&InputFiles,
   // We need to resolve the symbols so the LTO backend knows which symbols need
   // to be kept or can be internalized. This is a simplified symbol resolution
   // scheme to approximate the full resolution a linker would do.
+  uint64_t Idx = 0;
   DenseSet PrevailingSymbols;
   for (auto &BitcodeInput : BitcodeInputFiles) {
+// Get a semi-unique buffer identifier for Thin-LTO.
+StringRef Identifier = Saver.save(
+std::to_string(Idx++) + "." +
+BitcodeInput.getBinary()->getMemoryBufferRef().getBufferIdentifier());
 MemoryBufferRef Buffer =
-MemoryBufferRef(BitcodeInput.getBinary()->getImage(), "");
+MemoryBufferRef(BitcodeInput.getBinary()->getImage(), Identifier);
 Expected> BitcodeFileOrErr =
 llvm::lto::Inpu

[clang] 1586b59 - [LinkerWrapper] Clean-up unused definitions

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

Author: Joseph Huber
Date: 2022-07-12T11:46:46-04:00
New Revision: 1586b5952894c9ba1941fd38a1f7a6b8ca4ee8df

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

LOG: [LinkerWrapper] Clean-up unused definitions

Summary:

There are a few definitions that are unused or unnecessary after
previous changes, clean them up.

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 13c0a7e362a3..c1990abe0eaf 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -56,8 +56,8 @@ using namespace llvm;
 using namespace llvm::opt;
 using namespace llvm::object;
 
-/// TODO: We use the command line parser only to forward `-pass-remarks` 
options
-/// to the LTO backend. This should be replaced when there is a better way.
+/// We use the command line parser only to forward options like `-pass-remarks`
+/// to the LLVM tools.
 static cl::OptionCategory
 ClangLinkerWrapperCategory("clang-linker-wrapper options");
 static cl::opt Help("h", cl::desc("Alias for -help"), cl::Hidden,
@@ -92,14 +92,6 @@ static codegen::RegisterCodeGenFlags CodeGenFlags;
 /// Global flag to indicate that the LTO pipeline threw an error.
 static std::atomic LTOError;
 
-/// Magic section string that marks the existence of offloading data. The
-/// section will contain one or more offloading binaries stored contiguously.
-#define OFFLOAD_SECTION_MAGIC_STR ".llvm.offloading"
-
-/// The magic offset for the first object inside CUDA's fatbinary. This can be
-/// 
diff erent but it should work for what is passed here.
-static constexpr unsigned FatbinaryOffset = 0x50;
-
 using OffloadingImage = OffloadBinary::OffloadingImage;
 
 /// A class to contain the binary information for a single OffloadBinary.
@@ -353,7 +345,7 @@ Error extractFromBitcode(std::unique_ptr 
Buffer,
   continue;
 
 MDString *SectionID = dyn_cast(Op->getOperand(1));
-if (!SectionID || SectionID->getString() != OFFLOAD_SECTION_MAGIC_STR)
+if (!SectionID || SectionID->getString() != ".llvm.offloading")
   continue;
 
 GlobalVariable *GV =
@@ -872,24 +864,14 @@ Error linkBitcodeFiles(SmallVectorImpl 
&InputFiles,
   BitcodeInputFiles.emplace_back(std::move(File));
   continue;
 }
-case file_magic::cuda_fatbinary: {
-  // Cuda fatbinaries made by Clang almost almost have an object eighty
-  // bytes from the beginning. This should be sufficient to identify the
-  // symbols.
-  Buffer =
-  MemoryBufferRef(Buffer.getBuffer().drop_front(FatbinaryOffset), "");
-  LLVM_FALLTHROUGH;
-}
 case file_magic::elf_relocatable:
-case file_magic::elf_shared_object:
-case file_magic::macho_object:
-case file_magic::coff_object: {
+case file_magic::elf_shared_object: {
   Expected> ObjFile =
   ObjectFile::createObjectFile(Buffer);
   if (!ObjFile)
 continue;
 
-  for (auto &Sym : (*ObjFile)->symbols()) {
+  for (SymbolRef Sym : (*ObjFile)->symbols()) {
 Expected Name = Sym.getName();
 if (!Name)
   return Name.takeError();



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


[PATCH] D129547: [clang][dataflow] Generate readable form of boolean values for debugging purposes.

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

Fix use after move.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129547

Files:
  clang/docs/tools/clang-formatted-files.txt
  clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
  clang/lib/Analysis/FlowSensitive/CMakeLists.txt
  clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
  clang/unittests/Analysis/FlowSensitive/CMakeLists.txt
  clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
  llvm/utils/gn/secondary/clang/lib/Analysis/FlowSensitive/BUILD.gn

Index: llvm/utils/gn/secondary/clang/lib/Analysis/FlowSensitive/BUILD.gn
===
--- llvm/utils/gn/secondary/clang/lib/Analysis/FlowSensitive/BUILD.gn
+++ llvm/utils/gn/secondary/clang/lib/Analysis/FlowSensitive/BUILD.gn
@@ -12,5 +12,6 @@
 "Transfer.cpp",
 "TypeErasedDataflowAnalysis.cpp",
 "WatchedLiteralsSolver.cpp",
+"DebugSupport.cpp",
   ]
 }
Index: clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
===
--- /dev/null
+++ clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
@@ -0,0 +1,190 @@
+//===- unittests/Analysis/FlowSensitive/DebugSupportTest.cpp --===//
+//
+// 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
+//
+//===--===//
+
+#include "clang/Analysis/FlowSensitive/DebugSupport.h"
+#include "TestingSupport.h"
+#include "clang/Analysis/FlowSensitive/Value.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+namespace {
+
+using namespace clang;
+using namespace dataflow;
+
+using test::ConstraintContext;
+using testing::StrEq;
+
+TEST(BoolValueDebugStringTest, AtomicBoolean) {
+  // B0
+  ConstraintContext Ctx;
+  auto B = Ctx.atom();
+
+  auto Expected = R"(B0)";
+  debugString(*B);
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST(BoolValueDebugStringTest, Negation) {
+  // !B0
+  ConstraintContext Ctx;
+  auto B = Ctx.neg(Ctx.atom());
+
+  auto Expected = R"((not
+B0))";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST(BoolValueDebugStringTest, Conjunction) {
+  // B0 ^ B1
+  ConstraintContext Ctx;
+  auto B = Ctx.conj(Ctx.atom(), Ctx.atom());
+
+  auto Expected = R"((and
+B0
+B1))";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST(BoolValueDebugStringTest, Disjunction) {
+  // B0 v B1
+  ConstraintContext Ctx;
+  auto B = Ctx.disj(Ctx.atom(), Ctx.atom());
+
+  auto Expected = R"((or
+B0
+B1))";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST(BoolValueDebugStringTest, Implication) {
+  // B0 => B1, implemented as !B0 v B1
+  ConstraintContext Ctx;
+  auto B = Ctx.disj(Ctx.neg(Ctx.atom()), Ctx.atom());
+
+  auto Expected = R"((or
+(not
+B0)
+B1))";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST(BoolValueDebugStringTest, Iff) {
+  // B0 <=> B1, implemented as (!B0 v B1) ^ (B0 v !B1)
+  ConstraintContext Ctx;
+  auto B0 = Ctx.atom();
+  auto B1 = Ctx.atom();
+  auto B = Ctx.conj(Ctx.disj(Ctx.neg(B0), B1), Ctx.disj(B0, Ctx.neg(B1)));
+
+  auto Expected = R"((and
+(or
+(not
+B0)
+B1)
+(or
+B0
+(not
+B1";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST(BoolValueDebugStringTest, Xor) {
+  // (B0 ^ !B1) V (!B0 ^ B1)
+  ConstraintContext Ctx;
+  auto B0 = Ctx.atom();
+  auto B1 = Ctx.atom();
+  auto B = Ctx.disj(Ctx.conj(B0, Ctx.neg(B1)), Ctx.conj(Ctx.neg(B0), B1));
+
+  auto Expected = R"((or
+(and
+B0
+(not
+B1))
+(and
+(not
+B0)
+B1)))";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST(BoolValueDebugStringTest, NestedBoolean) {
+  // B0 ^ (B1 v (B2 ^ (B3 v B4)))
+  ConstraintContext Ctx;
+  auto B = Ctx.conj(
+  Ctx.atom(),
+  Ctx.disj(Ctx.atom(),
+   Ctx.conj(Ctx.atom(), Ctx.disj(Ctx.atom(), Ctx.atom();
+
+  auto Expected = R"((and
+B0
+(or
+B1
+(and
+B2
+(or
+B3
+B4)";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST(BoolValueDebugStringTest, AtomicBooleanWithName) {
+  // True
+  ConstraintContext Ctx;
+  auto True = cast(Ctx.atom());
+  auto B = True;
+
+  auto Expected = R"(True)";
+  EXPECT_THAT(debugString(*B, {{True, "True"}}), StrEq(Expected));
+}
+
+TEST(BoolValueDebugStringTest, ComplexBooleanWithNames) {
+  // (Cond ^ Then ^ !Else) v (!Cond ^ !Then ^ Else)
+  ConstraintContext Ctx;
+  auto Cond = cast(Ctx.atom());
+  auto Then = cast(Ctx.atom());
+  auto Else = cast(Ctx.atom());
+  auto B = Ctx.disj(Ctx.conj(Cond, Ctx

[PATCH] D129568: [clang][dataflow] Rename `Status` field in a `Solver::Result` struct to `SATCheckStatus`.

2022-07-12 Thread weiyi via Phabricator via cfe-commits
wyt created this revision.
Herald added subscribers: martong, tschuett, xazax.hun.
Herald added a reviewer: NoQ.
Herald added a project: All.
wyt requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Previously, `Status` was named after the enum type `Status` which caused the 
enum to be hidden by the non-type declaration of the `Status` field. This patch 
fixes this issue by using different names for the field and type.

Depends On D129547 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129568

Files:
  clang/include/clang/Analysis/FlowSensitive/Solver.h


Index: clang/include/clang/Analysis/FlowSensitive/Solver.h
===
--- clang/include/clang/Analysis/FlowSensitive/Solver.h
+++ clang/include/clang/Analysis/FlowSensitive/Solver.h
@@ -60,7 +60,7 @@
 
 /// Returns the status of satisfiability checking on the queried boolean
 /// formula.
-Status getStatus() const { return Status; }
+Status getStatus() const { return SATCheckStatus; }
 
 /// Returns a truth assignment to boolean values that satisfies the queried
 /// boolean formula if available. Otherwise, an empty optional is returned.
@@ -71,11 +71,11 @@
 
   private:
 Result(
-enum Status Status,
+enum Status SATCheckStatus,
 llvm::Optional> Solution)
-: Status(Status), Solution(std::move(Solution)) {}
+: SATCheckStatus(SATCheckStatus), Solution(std::move(Solution)) {}
 
-Status Status;
+Status SATCheckStatus;
 llvm::Optional> Solution;
   };
 


Index: clang/include/clang/Analysis/FlowSensitive/Solver.h
===
--- clang/include/clang/Analysis/FlowSensitive/Solver.h
+++ clang/include/clang/Analysis/FlowSensitive/Solver.h
@@ -60,7 +60,7 @@
 
 /// Returns the status of satisfiability checking on the queried boolean
 /// formula.
-Status getStatus() const { return Status; }
+Status getStatus() const { return SATCheckStatus; }
 
 /// Returns a truth assignment to boolean values that satisfies the queried
 /// boolean formula if available. Otherwise, an empty optional is returned.
@@ -71,11 +71,11 @@
 
   private:
 Result(
-enum Status Status,
+enum Status SATCheckStatus,
 llvm::Optional> Solution)
-: Status(Status), Solution(std::move(Solution)) {}
+: SATCheckStatus(SATCheckStatus), Solution(std::move(Solution)) {}
 
-Status Status;
+Status SATCheckStatus;
 llvm::Optional> Solution;
   };
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129548: [clang][dataflow] Generate readable form of input and output of satisfiability checking for debugging purposes.

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

Remove unnecessary enum keyword.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129548

Files:
  clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
  clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
  clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
@@ -9,6 +9,7 @@
 #include "clang/Analysis/FlowSensitive/DebugSupport.h"
 #include "TestingSupport.h"
 #include "clang/Analysis/FlowSensitive/Value.h"
+#include "clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
@@ -187,4 +188,242 @@
   StrEq(Expected));
 }
 
+Solver::Result CheckSAT(std::vector Constraints) {
+  llvm::DenseSet ConstraintsSet(Constraints.begin(),
+ Constraints.end());
+  return WatchedLiteralsSolver().solve(std::move(ConstraintsSet));
+}
+
+TEST(SATCheckDebugStringTest, AtomicBoolean) {
+  // B0
+  ConstraintContext Ctx;
+  std::vector Constraints({Ctx.atom()});
+  auto Result = CheckSAT(Constraints);
+
+  auto Expected = R"(
+Constraints
+
+B0
+
+Satisfiable.
+
+B0=True
+)";
+  EXPECT_THAT(debugString(Constraints, Result), StrEq(Expected));
+}
+
+TEST(SATCheckDebugStringTest, AtomicBooleanAndNegation) {
+  // B0, !B0
+  ConstraintContext Ctx;
+  auto B0 = Ctx.atom();
+  std::vector Constraints({B0, Ctx.neg(B0)});
+  auto Result = CheckSAT(Constraints);
+
+  auto Expected = R"(
+Constraints
+
+B0
+
+(not
+B0)
+
+Unsatisfiable.
+
+)";
+  EXPECT_THAT(debugString(Constraints, Result), StrEq(Expected));
+}
+
+TEST(SATCheckDebugStringTest, MultipleAtomicBooleans) {
+  // B0, B1
+  ConstraintContext Ctx;
+  std::vector Constraints({Ctx.atom(), Ctx.atom()});
+  auto Result = CheckSAT(Constraints);
+
+  auto Expected = R"(
+Constraints
+
+B0
+
+B1
+
+Satisfiable.
+
+B0=True
+B1=True
+)";
+  EXPECT_THAT(debugString(Constraints, Result), StrEq(Expected));
+}
+
+TEST(SATCheckDebugStringTest, Implication) {
+  // B0, B0 => B1
+  ConstraintContext Ctx;
+  auto B0 = Ctx.atom();
+  auto B1 = Ctx.atom();
+  auto Impl = Ctx.disj(Ctx.neg(B0), B1);
+  std::vector Constraints({B0, Impl});
+  auto Result = CheckSAT(Constraints);
+
+  auto Expected = R"(
+Constraints
+
+B0
+
+(or
+(not
+B0)
+B1)
+
+Satisfiable.
+
+B0=True
+B1=True
+)";
+  EXPECT_THAT(debugString(Constraints, Result), StrEq(Expected));
+}
+
+TEST(SATCheckDebugStringTest, Iff) {
+  // B0, B0 <=> B1
+  ConstraintContext Ctx;
+  auto B0 = Ctx.atom();
+  auto B1 = Ctx.atom();
+  auto Iff = Ctx.conj(Ctx.disj(Ctx.neg(B0), B1), Ctx.disj(B0, Ctx.neg(B1)));
+  std::vector Constraints({B0, Iff});
+  auto Result = CheckSAT(Constraints);
+
+  auto Expected = R"(
+Constraints
+
+B0
+
+(and
+(or
+(not
+B0)
+B1)
+(or
+B0
+(not
+B1)))
+
+Satisfiable.
+
+B0=True
+B1=True
+)";
+  EXPECT_THAT(debugString(Constraints, Result), StrEq(Expected));
+}
+
+TEST(SATCheckDebugStringTest, Xor) {
+  // B0, XOR(B0, B1)
+  ConstraintContext Ctx;
+  auto B0 = Ctx.atom();
+  auto B1 = Ctx.atom();
+  auto XOR = Ctx.disj(Ctx.conj(B0, Ctx.neg(B1)), Ctx.conj(Ctx.neg(B0), B1));
+  std::vector Constraints({B0, XOR});
+  auto Result = CheckSAT(Constraints);
+
+  auto Expected = R"(
+Constraints
+
+B0
+
+(or
+(and
+B0
+(not
+B1))
+(and
+(not
+B0)
+B1))
+
+Satisfiable.
+
+B0=True
+B1=False
+)";
+  EXPECT_THAT(debugString(Constraints, Result), StrEq(Expected));
+}
+
+TEST(SATCheckDebugStringTest, ComplexBooleanWithNames) {
+  // Cond, (Cond ^ Then ^ !Else) v (!Cond ^ !Then ^ Else)
+  ConstraintContext Ctx;
+  auto Cond = cast(Ctx.atom());
+  auto Then = cast(Ctx.atom());
+  auto Else = cast(Ctx.atom());
+  auto B = Ctx.disj(Ctx.conj(Cond, Ctx.conj(Then, Ctx.neg(Else))),
+Ctx.conj(Ctx.neg(Cond), Ctx.conj(Ctx.neg(Then), Else)));
+  std::vector Constraints({Cond, B});
+  auto Result = CheckSAT(Constraints);
+
+  auto Expected = R"(
+Constraints
+
+Cond
+
+(or
+(and
+Cond
+(and
+Then
+(not
+Else)))
+(and
+(not
+Cond)
+(and
+(not
+Then)
+Else)))
+
+Satisfiable.
+
+Cond=True
+Else=False
+Then=True
+)";
+  EXPECT_THAT(debugString(Constraints, Result,
+  {{Cond, "Cond"}, {Then, "Then"}, {Else, "Else"}}),
+  StrEq(Expecte

[PATCH] D129569: [clang/ios] Make -mios-version-min the canonical spelling over -miphoneos-version-min

2022-07-12 Thread Nico Weber via Phabricator via cfe-commits
thakis created this revision.
thakis added a reviewer: akyrtzi.
Herald added a project: All.
thakis requested review of this revision.
Herald added a subscriber: MaskRay.

Like https://reviews.llvm.org/D129226, but for iOS.

No behavior change.


https://reviews.llvm.org/D129569

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Darwin.cpp


Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1554,7 +1554,7 @@
   Opt = options::OPT_mmacos_version_min_EQ;
   break;
 case DarwinPlatformKind::IPhoneOS:
-  Opt = options::OPT_miphoneos_version_min_EQ;
+  Opt = options::OPT_mios_version_min_EQ;
   break;
 case DarwinPlatformKind::TvOS:
   Opt = options::OPT_mtvos_version_min_EQ;
@@ -1728,7 +1728,7 @@
 getDeploymentTargetFromOSVersionArg(DerivedArgList &Args,
 const Driver &TheDriver) {
   Arg *macOSVersion = Args.getLastArg(options::OPT_mmacos_version_min_EQ);
-  Arg *iOSVersion = Args.getLastArg(options::OPT_miphoneos_version_min_EQ,
+  Arg *iOSVersion = Args.getLastArg(options::OPT_mios_version_min_EQ,
 
options::OPT_mios_simulator_version_min_EQ);
   Arg *TvOSVersion =
   Args.getLastArg(options::OPT_mtvos_version_min_EQ,
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -3338,11 +3338,12 @@
 def mglobal_merge : Flag<["-"], "mglobal-merge">, Group, 
Flags<[CC1Option]>,
   HelpText<"Enable merging of globals">;
 def mhard_float : Flag<["-"], "mhard-float">, Group;
-def miphoneos_version_min_EQ : Joined<["-"], "miphoneos-version-min=">, 
Group;
 def mios_version_min_EQ : Joined<["-"], "mios-version-min=">,
-  Alias, HelpText<"Set iOS deployment target">;
+  Group, HelpText<"Set iOS deployment target">;
+def : Joined<["-"], "miphoneos-version-min=">,
+  Group, Alias;
 def mios_simulator_version_min_EQ : Joined<["-"], 
"mios-simulator-version-min=">;
-def miphonesimulator_version_min_EQ : Joined<["-"], 
"miphonesimulator-version-min=">, Alias;
+def : Joined<["-"], "miphonesimulator-version-min=">, 
Alias;
 def mkernel : Flag<["-"], "mkernel">, Group;
 def mlinker_version_EQ : Joined<["-"], "mlinker-version=">,
   Flags<[NoXarchOption]>;


Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1554,7 +1554,7 @@
   Opt = options::OPT_mmacos_version_min_EQ;
   break;
 case DarwinPlatformKind::IPhoneOS:
-  Opt = options::OPT_miphoneos_version_min_EQ;
+  Opt = options::OPT_mios_version_min_EQ;
   break;
 case DarwinPlatformKind::TvOS:
   Opt = options::OPT_mtvos_version_min_EQ;
@@ -1728,7 +1728,7 @@
 getDeploymentTargetFromOSVersionArg(DerivedArgList &Args,
 const Driver &TheDriver) {
   Arg *macOSVersion = Args.getLastArg(options::OPT_mmacos_version_min_EQ);
-  Arg *iOSVersion = Args.getLastArg(options::OPT_miphoneos_version_min_EQ,
+  Arg *iOSVersion = Args.getLastArg(options::OPT_mios_version_min_EQ,
 options::OPT_mios_simulator_version_min_EQ);
   Arg *TvOSVersion =
   Args.getLastArg(options::OPT_mtvos_version_min_EQ,
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -3338,11 +3338,12 @@
 def mglobal_merge : Flag<["-"], "mglobal-merge">, Group, Flags<[CC1Option]>,
   HelpText<"Enable merging of globals">;
 def mhard_float : Flag<["-"], "mhard-float">, Group;
-def miphoneos_version_min_EQ : Joined<["-"], "miphoneos-version-min=">, Group;
 def mios_version_min_EQ : Joined<["-"], "mios-version-min=">,
-  Alias, HelpText<"Set iOS deployment target">;
+  Group, HelpText<"Set iOS deployment target">;
+def : Joined<["-"], "miphoneos-version-min=">,
+  Group, Alias;
 def mios_simulator_version_min_EQ : Joined<["-"], "mios-simulator-version-min=">;
-def miphonesimulator_version_min_EQ : Joined<["-"], "miphonesimulator-version-min=">, Alias;
+def : Joined<["-"], "miphonesimulator-version-min=">, Alias;
 def mkernel : Flag<["-"], "mkernel">, Group;
 def mlinker_version_EQ : Joined<["-"], "mlinker-version=">,
   Flags<[NoXarchOption]>;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129547: [clang][dataflow] Generate readable form of boolean values for debugging purposes.

2022-07-12 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun accepted this revision.
xazax.hun added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Analysis/FlowSensitive/DebugSupport.cpp:28
+
+class DebugStringGenerator {
+public:

This class could be in anonymous namespace.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129547

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


[PATCH] D129373: [NFC] Minor cleanup of usage of FloatModeKind with bitmask enums

2022-07-12 Thread Jolanta Jensen via Phabricator via cfe-commits
jolanta.jensen added inline comments.



Comment at: clang/include/clang/Basic/TargetInfo.h:894
   bool useObjCFPRetForRealType(FloatModeKind T) const {
-return RealTypeUsesObjCFPRetMask & llvm::BitmaskEnumDetail::Underlying(T);
+return (int)((FloatModeKind)RealTypeUsesObjCFPRetMask & T);
   }

shafik wrote:
> Why not just cast directly to `bool`? 
Yes, it will work. But as int is the underlying type I find this way a bit 
clearer. I hope to be forgiven if I keep it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129373

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


[clang] f6b0ae1 - [AST] Accept identical TypeConstraint referring to other template

2022-07-12 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2022-07-12T23:57:44+08:00
New Revision: f6b0ae144ed8085618c12ba83d95affd786e6a49

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

LOG: [AST] Accept identical TypeConstraint referring to other template
parameters.

The current implementation to judge the similarity of TypeConstraint in
ASTContext::isSameTemplateParameter is problematic, it couldn't handle
the following case:

```C++
template <__integer_like _Tp, C<_Tp> Sentinel>
constexpr _Tp operator()(_Tp &&__t, Sentinel &&last) const {
return __t;
}
```

When we see 2 such declarations from different modules, we would judge
their similarity by `ASTContext::isSame*` methods. But problems come for
the TypeConstraint. Originally, we would profile each argument one by
one. But it is not right. Since the profiling result of `_Tp` would
refer to two different template type declarations. So it would get
different results. It is right since the `_Tp` in different modules
refers to different declarations indeed. So the same declaration in
different modules would meet incorrect our-checking results.

It is not the thing we want. We want to know if the TypeConstraint have
the same expression.

Reviewer: vsapsai, ilya-biryukov

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

Added: 


Modified: 
clang/include/clang/AST/ASTContext.h
clang/lib/AST/ASTContext.cpp
clang/test/Modules/concept.cppm

Removed: 




diff  --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 87b5a6053f1f2..85eba45e4de6e 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -130,6 +130,7 @@ class TemplateDecl;
 class TemplateParameterList;
 class TemplateTemplateParmDecl;
 class TemplateTypeParmDecl;
+class TypeConstraint;
 class UnresolvedSetIterator;
 class UsingShadowDecl;
 class VarTemplateDecl;
@@ -2664,6 +2665,18 @@ class ASTContext : public RefCountedBase {
   /// that they may be used in declarations of the same template.
   bool isSameTemplateParameter(const NamedDecl *X, const NamedDecl *Y) const;
 
+  /// Determine whether two 'requires' expressions are similar enough that they
+  /// may be used in re-declarations.
+  ///
+  /// Use of 'requires' isn't mandatory, works with constraints expressed in
+  /// other ways too.
+  bool isSameConstraintExpr(const Expr *XCE, const Expr *YCE) const;
+
+  /// Determine whether two type contraint are similar enough that they could
+  /// used in declarations of the same template.
+  bool isSameTypeConstraint(const TypeConstraint *XTC,
+const TypeConstraint *YTC) const;
+
   /// Determine whether two default template arguments are similar enough
   /// that they may be used in declarations of the same template.
   bool isSameDefaultTemplateArgument(const NamedDecl *X,

diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index aa29ce7f13840..cfd7bf6045422 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -6218,6 +6218,57 @@ bool ASTContext::hasSameTemplateName(const TemplateName 
&X,
  getCanonicalTemplateName(Y).getAsVoidPointer();
 }
 
+bool ASTContext::isSameConstraintExpr(const Expr *XCE, const Expr *YCE) const {
+  if (!XCE != !YCE)
+return false;
+
+  if (!XCE)
+return true;
+
+  llvm::FoldingSetNodeID XCEID, YCEID;
+  XCE->Profile(XCEID, *this, /*Canonical=*/true);
+  YCE->Profile(YCEID, *this, /*Canonical=*/true);
+  return XCEID == YCEID;
+}
+
+bool ASTContext::isSameTypeConstraint(const TypeConstraint *XTC,
+  const TypeConstraint *YTC) const {
+  if (!XTC != !YTC)
+return false;
+
+  if (!XTC)
+return true;
+
+  auto *NCX = XTC->getNamedConcept();
+  auto *NCY = YTC->getNamedConcept();
+  if (!NCX || !NCY || !isSameEntity(NCX, NCY))
+return false;
+  if (XTC->hasExplicitTemplateArgs() != YTC->hasExplicitTemplateArgs())
+return false;
+  if (XTC->hasExplicitTemplateArgs())
+if (XTC->getTemplateArgsAsWritten()->NumTemplateArgs !=
+YTC->getTemplateArgsAsWritten()->NumTemplateArgs)
+  return false;
+
+  // Compare slowly by profiling.
+  //
+  // We couldn't compare the profiling result for the template
+  // args here. Consider the following example in 
diff erent modules:
+  //
+  // template <__integer_like _Tp, C<_Tp> Sentinel>
+  // constexpr _Tp operator()(_Tp &&__t, Sentinel &&last) const {
+  //   return __t;
+  // }
+  //
+  // When we compare the profiling result for `C<_Tp>` in 
diff erent
+  // modules, it will compare the type of `_Tp` in 
diff erent modules.
+  // However, the type of `_Tp` in 
diff erent modules refer to 
diff erent
+  // types here naturally. So we couldn't compare the profiling result
+  // f

[PATCH] D129068: [AST] Accept identical TypeConstraint referring to other template parameters.

2022-07-12 Thread Chuanqi Xu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf6b0ae144ed8: [AST] Accept identical TypeConstraint 
referring to other template (authored by ChuanqiXu).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129068

Files:
  clang/include/clang/AST/ASTContext.h
  clang/lib/AST/ASTContext.cpp
  clang/test/Modules/concept.cppm

Index: clang/test/Modules/concept.cppm
===
--- clang/test/Modules/concept.cppm
+++ clang/test/Modules/concept.cppm
@@ -3,6 +3,7 @@
 // RUN: split-file %s %t
 //
 // RUN: %clang_cc1 -std=c++20 %t/A.cppm -emit-module-interface -o %t/A.pcm
+// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t -I%t -DDIFFERENT %t/B.cppm -verify
 // RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t -I%t %t/B.cppm -verify
 
 //--- foo.h
@@ -18,6 +19,9 @@
 template 
 concept __member_size = requires(_Tp &&t) { t.size(); };
 
+template 
+concept C = requires(First x, Second y) { x + y; };
+
 struct A {
 public:
   template 
@@ -29,6 +33,29 @@
   constexpr __integer_like auto operator()(_Tp&& __t) const {
 return __t.size();
   }
+
+  template <__integer_like _Tp, C<_Tp> Sentinel>
+  constexpr _Tp operator()(_Tp &&__t, Sentinel &&last) const {
+return __t;
+  }
+
+  template  class H, class S, C> Sentinel>
+  constexpr H operator()(H &&__s, Sentinel &&last) const {
+return __s;
+  }
+
+// Tests that we could find different concept definition indeed.
+#ifndef DIFFERENT
+  template <__integer_like _Tp, __integer_like _Up, C<_Tp> Sentinel>
+  constexpr _Tp operator()(_Tp &&__t, _Up _u, Sentinel &&last) const {
+return __t;
+  }
+#else
+  template <__integer_like _Tp, __integer_like _Up, C<_Up> Sentinel>
+  constexpr _Tp operator()(_Tp &&__t, _Up _u, Sentinel &&last) const {
+return __t;
+  }
+#endif
 };
 #endif
 
@@ -38,12 +65,23 @@
 export module A;
 
 //--- B.cppm
-// expected-no-diagnostics
 module;
 #include "foo.h"
 export module B;
 import A;
 
+#ifdef DIFFERENT
+// expected-error@foo.h:41 {{'__fn::operator()' from module 'A.' is not present in definition of '__fn' provided earlier}}
+// expected-note@* 1+{{declaration of 'operator()' does not match}}
+#else
+// expected-no-diagnostics
+#endif
+
+template 
+struct U {
+  auto operator+(U) { return 0; }
+};
+
 void foo() {
 A a;
 struct S {
@@ -51,4 +89,8 @@
 auto operator+(S s) { return 0; }
 };
 __fn{}(S());
+__fn{}(S(), S());
+__fn{}(S(), S(), S());
+
+__fn{}(U(), U());
 }
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -6218,6 +6218,57 @@
  getCanonicalTemplateName(Y).getAsVoidPointer();
 }
 
+bool ASTContext::isSameConstraintExpr(const Expr *XCE, const Expr *YCE) const {
+  if (!XCE != !YCE)
+return false;
+
+  if (!XCE)
+return true;
+
+  llvm::FoldingSetNodeID XCEID, YCEID;
+  XCE->Profile(XCEID, *this, /*Canonical=*/true);
+  YCE->Profile(YCEID, *this, /*Canonical=*/true);
+  return XCEID == YCEID;
+}
+
+bool ASTContext::isSameTypeConstraint(const TypeConstraint *XTC,
+  const TypeConstraint *YTC) const {
+  if (!XTC != !YTC)
+return false;
+
+  if (!XTC)
+return true;
+
+  auto *NCX = XTC->getNamedConcept();
+  auto *NCY = YTC->getNamedConcept();
+  if (!NCX || !NCY || !isSameEntity(NCX, NCY))
+return false;
+  if (XTC->hasExplicitTemplateArgs() != YTC->hasExplicitTemplateArgs())
+return false;
+  if (XTC->hasExplicitTemplateArgs())
+if (XTC->getTemplateArgsAsWritten()->NumTemplateArgs !=
+YTC->getTemplateArgsAsWritten()->NumTemplateArgs)
+  return false;
+
+  // Compare slowly by profiling.
+  //
+  // We couldn't compare the profiling result for the template
+  // args here. Consider the following example in different modules:
+  //
+  // template <__integer_like _Tp, C<_Tp> Sentinel>
+  // constexpr _Tp operator()(_Tp &&__t, Sentinel &&last) const {
+  //   return __t;
+  // }
+  //
+  // When we compare the profiling result for `C<_Tp>` in different
+  // modules, it will compare the type of `_Tp` in different modules.
+  // However, the type of `_Tp` in different modules refer to different
+  // types here naturally. So we couldn't compare the profiling result
+  // for the template args directly.
+  return isSameConstraintExpr(XTC->getImmediatelyDeclaredConstraint(),
+  YTC->getImmediatelyDeclaredConstraint());
+}
+
 bool ASTContext::isSameTemplateParameter(const NamedDecl *X,
  const NamedDecl *Y) const {
   if (X->getKind() != Y->getKind())
@@ -6229,32 +6280,8 @@
   return false;
 if (TX->hasTypeConstraint() != TY->hasTypeConstraint())
   return false;
-const TypeConstraint *TXTC = TX->getTypeConstraint();
- 

[PATCH] D129570: Add new clang-tidy check to find implicit conversions from enum to integer.

2022-07-12 Thread Paul Fultz II via Phabricator via cfe-commits
pfultz2 created this revision.
pfultz2 added reviewers: aaron.ballman, alexfh.
pfultz2 added a project: clang-tools-extra.
Herald added subscribers: carlosgalvezp, mgorny.
Herald added a project: All.
pfultz2 requested review of this revision.
Herald added a subscriber: cfe-commits.

This check diagnoses instances where an enum is implicitly converted to an
integer. In C++11, enums can be defined as `enum class` which will prevent
such implicit conversion, however, `enum` provides no such guarantees to
prevent bugs. There can be many reasons why `enum` cannot be replaced with
`enum class` such as compatibility with C or legacy libraries.

This check will diagnose similar implicit conversions when using `enum` to
find the same class of bugs. Currently it will only warn on function or
constructor calls as such conversions are not clear to the user, but this
could be expanded in the future.

  void foo(int i);
  void f() {
  foo(e1); // e1 is implictly converted to an int
  }


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129570

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/EnumToIntCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/EnumToIntCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone/enum-to-int.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone/enum-to-int.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/enum-to-int.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/enum-to-int.cpp
@@ -0,0 +1,28 @@
+// RUN: %check_clang_tidy %s bugprone-enum-to-int %t
+
+enum A { e1,
+ e2 };
+
+struct bar {
+  bar(int);
+};
+void foo(int i);
+void f1() {
+  foo(e1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: Enum is implictly converted to an integral. [bugprone-enum-to-int]
+}
+void f2() {
+  foo(static_cast(e1));
+}
+void f3() {
+  int i = e1;
+  foo(i);
+}
+void f4() {
+  bar a(e1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: Enum is implictly converted to an integral. [bugprone-enum-to-int]
+}
+void f5() {
+  auto a = bar{e1};
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: Enum is implictly converted to an integral. [bugprone-enum-to-int]
+}
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -85,6 +85,7 @@
`bugprone-dangling-handle `_,
`bugprone-dynamic-static-initializers `_,
`bugprone-easily-swappable-parameters `_,
+   `bugprone-enum-to-int `_,
`bugprone-exception-escape `_,
`bugprone-fold-init-type `_,
`bugprone-forward-declaration-namespace `_,
Index: clang-tools-extra/docs/clang-tidy/checks/bugprone/enum-to-int.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone/enum-to-int.rst
@@ -0,0 +1,24 @@
+.. title:: clang-tidy - bugprone-enum-to-int
+
+bugprone-enum-to-int
+
+
+This check diagnoses instances where an enum is implicitly converted to an
+integer. In C++11, enums can be defined as ``enum class`` which will prevent
+such implicit conversion, however, ``enum`` provides no such guarantess to
+prevent bugs. There can be many reasons why ``enum`` cannot be replaced with
+``enum class`` such as compatibility with C or legacy libraries.
+
+This check will diagnose similiar implicit conversions whne using ``enum`` to
+find the same class of bugs. Currently it will only warn on function or
+constructor calls as such conversions are not clear to the usr, but this
+could be expanded in the future.
+
+Examples:
+
+.. code-block:: c++
+
+void foo(int i);
+void f() {
+foo(e1); // e1 is implictly converted to an int
+}
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -118,6 +118,11 @@
 New checks
 ^^
 
+- New :doc:`bugprone-enum-to-int
+  ` check.
+
+  Finds implicit conversion of enum to an integral type.
+
 - New :doc:`bugprone-shared-ptr-array-mismatch ` check.
 
   Finds initializations of C++ shared pointers to non-array type that are initialized with an array.
Index: clang-tools-extra/clang-tidy/bugprone/EnumToIntCheck.h
===
--- /dev/null
+++ clang-tools-extra/clang-tidy/bugprone/EnumToIntCheck.h
@@ -0,0 +1,34 @@
+//===--- EnumToIntCheck.h - clang-tidy --*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See htt

[PATCH] D129572: [X86] initial -mfunction-return=thunk-extern support

2022-07-12 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers created this revision.
Herald added subscribers: jsji, jdoerfert, pengfei, hiraditya, mgorny.
Herald added a reviewer: aaron.ballman.
Herald added a project: All.
nickdesaulniers requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, MaskRay.
Herald added projects: clang, LLVM.

Adds support for:

- `-mfunction-return=` command line flag, and
- `__attribute__((function_return("")))` function attribute

Where the supported s are:

- keep (disable)
- thunk-extern (enable)

thunk-extern enables clang to change ret instructions into jmps to an
external symbol named __x86_return_thunk, implemented as a new
MachineFunctionPass named "x86-return-thunks", keyed off the new IR
attribute fn_ret_thunk_extern.

The symbol __x86_return_thunk is expected to be provided by the runtime
the compiled code is linked against and is not defined by the compiler.
Enabling this option alone doesn't provide mitigations without
corresponding definitions of __x86_return_thunk!

This new MachineFunctionPass is very similar to "x86-lvi-ret".

The s "thunk" and "thunk-inline" are currently unsupported. It's
not clear yet that they are necessary: whether the thunk pattern they
would emit is beneficial or used anywhere.

Should the s "thunk" and "thunk-inline" become necessary,
x86-return-thunks could probably be merged into x86-retpoline-thunks
which has pre-existing machinery for emitting thunks (which could be
used to implement the  "thunk").

Has been found to build+boot with corresponding Linux
kernel patches. This helps the Linux kernel mitigate RETBLEED.

- CVE-2022-23816
- CVE-2022-28693
- CVE-2022-29901

See also:

- "RETBLEED: Arbitrary Speculative Code Execution with Return

Instructions."

- AMD SECURITY NOTICE AMD-SN-1037: AMD CPU Branch Type Confusion
- TECHNICAL GUIDANCE FOR MITIGATING BRANCH TYPE CONFUSION REVISION 1.0 
2022-07-12
- Return Stack Buffer Underflow / Return Stack Buffer Underflow / 
CVE-2022-29901, CVE-2022-28693 / INTEL-SA-00702

SystemZ may eventually want to support "thunk-extern" and "thunk"; both
options are used by the Linux kernel's CONFIG_EXPOLINE.

This functionality has been available in GCC since the 8.1 release, and
was backported to the 7.3 release.

Many thanks for folks that provided discrete review off list due to the
embargoed nature of this hardware vulnerability. Many Bothans died to
bring us this information.

Link: https://www.youtube.com/watch?v=IF6HbCKQHK8
Link: https://github.com/llvm/llvm-project/issues/54404
Link: https://gcc.gnu.org/legacy-ml/gcc-patches/2018-01/msg01197.html
Link: 
https://www.intel.com/content/www/us/en/developer/articles/technical/software-security-guidance/advisory-guidance/return-stack-buffer-underflow.html
Link: 
https://arstechnica.com/information-technology/2022/07/intel-and-amd-cpus-vulnerable-to-a-new-speculative-execution-attack/?comments=1
Link: 
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ce114c866860aa9eae3f50974efc68241186ba60


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129572

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/CodeGen/attr-function-return.c
  clang/test/CodeGen/attr-function-return.cpp
  clang/test/Driver/mfunction-return.c
  clang/test/Frontend/mfunction-return.c
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/Sema/attr-function-return-unsupported-target.c
  clang/test/Sema/attr-function-return.c
  llvm/docs/LangRef.rst
  llvm/include/llvm/Bitcode/LLVMBitCodes.h
  llvm/include/llvm/IR/Attributes.td
  llvm/include/llvm/Support/CodeGen.h
  llvm/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/Target/X86/CMakeLists.txt
  llvm/lib/Target/X86/X86.h
  llvm/lib/Target/X86/X86ReturnThunks.cpp
  llvm/lib/Target/X86/X86TargetMachine.cpp
  llvm/lib/Transforms/Utils/CodeExtractor.cpp
  llvm/test/Bitcode/attributes.ll
  llvm/test/CodeGen/X86/O0-pipeline.ll
  llvm/test/CodeGen/X86/attr-function-return.ll
  llvm/test/CodeGen/X86/attr-function-return.mir
  llvm/test/CodeGen/X86/opt-pipeline.ll
  llvm/test/Transforms/Inline/attributes.ll

Index: llvm/test/Transforms/Inline/attributes.ll
===
--- llvm/test/Transforms/Inline/attributes.ll
+++ llvm/test/Transforms/Inline/attributes.ll
@@ -600,6 +600,33 @@
 ; CHECK-NEXT: ret i32
 }
 
+; Test that fn_ret_thunk_extern has no CompatRule; inlining is permitted.
+; Test that fn_ret_thunk_extern has no MergeRule; fn_ret_thunk_extern is not
+; propagated or dropped on the caller after inlining.
+define i32 @thunk_extern_callee() fn_ret_thunk_extern {
+; CHE

[PATCH] D129572: [X86] initial -mfunction-return=thunk-extern support

2022-07-12 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

> Many thanks for folks that provided discrete review off list due to the 
> embargoed nature of this hardware vulnerability.

I was one of those off-list reviewers, and the Clang parts LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129572

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


  1   2   3   >