[clang] [Clang] Handle consteval expression in array bounds expressions (PR #66222)

2023-09-14 Thread Takuya Shimizu via cfe-commits

hazohelet wrote:

> Where do you think it matters? I can't this of cases where ConstantEvaluated 
> context are nested in one another without some intertwined potentially 
> evaluated context

I was mostly thinking about cases where the array-bound expression appears 
inside immediate function context.
The current checks for "Is this always constant-evaluated?" only see the 
innermost evaluation context (e.g. `Sema::isConstantEvaluated`, and 
`Sema::DiagRuntimeBehavior`), so I hope the newly pushed evaluation contexts on 
`ExprEvalContexts` be strict about whether it's always-constant-evaluated or 
not.
Although this PR is not relevant, for the same reason, I don't think it's ideal 
that potentially-evaluated-contexts appear inside constant-evaluated context.

https://github.com/llvm/llvm-project/pull/66222
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D155572: [clang][Interp] Start implementing binary operators for complex types

2023-09-14 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 556825.

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

https://reviews.llvm.org/D155572

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/test/AST/Interp/complex.cpp

Index: clang/test/AST/Interp/complex.cpp
===
--- clang/test/AST/Interp/complex.cpp
+++ clang/test/AST/Interp/complex.cpp
@@ -78,3 +78,48 @@
   constexpr _Complex double F9 = {0, 0};
   static_assert(!F9, "");
 }
+
+namespace BinOps {
+namespace Add {
+  constexpr _Complex float A = { 13.0, 2.0 };
+  constexpr _Complex float B = { 2.0, 1.0  };
+  constexpr _Complex float C = A + B;
+  static_assert(__real(C) == 15.0, "");
+  static_assert(__imag(C) == 3.0, "");
+
+  constexpr _Complex float D = B + A;
+  static_assert(__real(D) == 15.0, "");
+  static_assert(__imag(D) == 3.0, "");
+
+  constexpr _Complex unsigned int I1 = { 5,  10 };
+  constexpr _Complex unsigned int I2 = { 40, 2  };
+  constexpr _Complex unsigned int I3 = I1 + I2;
+  static_assert(__real(I3) == 45, "");
+  static_assert(__imag(I3) == 12, "");
+}
+
+namespace Sub {
+  constexpr _Complex float A = { 13.0, 2.0 };
+  constexpr _Complex float B = { 2.0, 1.0  };
+  constexpr _Complex float C = A - B;
+  static_assert(__real(C) == 11.0, "");
+  static_assert(__imag(C) == 1.0, "");
+
+  constexpr _Complex float D = B - A;
+  static_assert(__real(D) == -11.0, "");
+  static_assert(__imag(D) == -1.0, "");
+
+  constexpr _Complex unsigned int I1 = { 5,  10 };
+  constexpr _Complex unsigned int I2 = { 40, 2  };
+  constexpr _Complex unsigned int I3 = I1 - I2;
+  static_assert(__real(I3) == -35, "");
+  static_assert(__imag(I3) == 8, "");
+}
+
+  using Bobble = _Complex float;
+  constexpr _Complex float A = { 13.0, 2.0 };
+  constexpr Bobble B = { 2.0, 1.0  };
+  constexpr _Complex float D = A - B;
+  static_assert(__real(D) == 11.0, "");
+  static_assert(__imag(D) == 1.0, "");
+}
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -65,6 +65,7 @@
   bool VisitBinaryOperator(const BinaryOperator *E);
   bool VisitLogicalBinOp(const BinaryOperator *E);
   bool VisitPointerArithBinOp(const BinaryOperator *E);
+  bool VisitComplexBinOp(const BinaryOperator *E);
   bool VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *E);
   bool VisitCallExpr(const CallExpr *E);
   bool VisitBuiltinCallExpr(const CallExpr *E);
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -290,6 +290,9 @@
   if (BO->isLogicalOp())
 return this->VisitLogicalBinOp(BO);
 
+  if (BO->getType()->isAnyComplexType())
+return this->VisitComplexBinOp(BO);
+
   const Expr *LHS = BO->getLHS();
   const Expr *RHS = BO->getRHS();
 
@@ -505,6 +508,107 @@
   return true;
 }
 
+template 
+bool ByteCodeExprGen::VisitComplexBinOp(const BinaryOperator *E) {
+  // FIXME: We expect a pointer on the stack here.
+  //   we should not do that, but that's part of a bigger rework.
+  const Expr *LHS = E->getLHS();
+  const Expr *RHS = E->getRHS();
+  PrimType LHSElemT = *this->classifyComplexElementType(LHS->getType());
+  PrimType RHSElemT = *this->classifyComplexElementType(RHS->getType());
+
+  unsigned LHSOffset = this->allocateLocalPrimitive(LHS, PT_Ptr, true, false);
+  unsigned RHSOffset = this->allocateLocalPrimitive(RHS, PT_Ptr, true, false);
+  unsigned ResultOffset = ~0u;
+  if (!this->DiscardResult)
+ResultOffset = this->allocateLocalPrimitive(E, PT_Ptr, true, false);
+
+  assert(LHSElemT == RHSElemT);
+
+  // Save result pointer in ResultOffset
+  if (!this->DiscardResult) {
+if (!this->emitDupPtr(E))
+  return false;
+if (!this->emitSetLocal(PT_Ptr, ResultOffset, E))
+  return false;
+  }
+
+  // Evaluate LHS and save value to LHSOffset.
+  if (!this->visit(LHS))
+return false;
+  if (!this->emitSetLocal(PT_Ptr, LHSOffset, E))
+return false;
+
+  // Same with RHS.
+  if (!this->visit(RHS))
+return false;
+  if (!this->emitSetLocal(PT_Ptr, RHSOffset, E))
+return false;
+
+  // Now we can get pointers to the LHS and RHS from the offsets above.
+  BinaryOperatorKind Op = E->getOpcode();
+  for (unsigned ElemIndex = 0; ElemIndex != 2; ++ElemIndex) {
+// Result pointer for the store later.
+if (!this->DiscardResult) {
+  if (!this->emitGetLocal(PT_Ptr, ResultOffset, E))
+return false;
+}
+
+if (!this->emitGetLocal(PT_Ptr, LHSOffset, E))
+  return false;
+if (!this->emitConstUint8(ElemIndex, E))
+  return false;
+if (!this->emitArrayElemPtrPopUint8(E))
+  return false;
+if (!this->emitLoadPop(LHSElemT, E))
+  return false;
+
+if (!this->emitGetLocal(PT_Ptr, 

[PATCH] D155572: [clang][Interp] Start implementing binary operators for complex types

2023-09-14 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

In D155572#4645997 , @aaron.ballman 
wrote:

> Hmmm, I think the answer is "no"... and "maybe." `_Complex` can only be 
> followed by `float`, `double`, or `long double` specifically per the C 
> standard. However, we also support `_Complex int` (and others) as an 
> extension, which starts to make `_Complex` look more like `_Atomic` in that 
> it augments an existing type, and so typedefs seem quite reasonable.

I know that much, I guess I was confused by the diagnostics:

  ../clang/test/AST/Interp/complex.cpp:121:18: warning: plain '_Complex' 
requires a type specifier; assuming '_Complex double'
121 |   using Gobble = _Complex Frobble;
|  ^
|   double




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155572

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


[PATCH] D152914: [Draft] Make __builtin_cpu builtins target-independent

2023-09-14 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai added a comment.

In D152914#4602914 , @ilinpv wrote:

> Friendly ping, are there any questions remained to proceed with 
> target-independent __builtin_cpu_supports ?

Sorry, I have not gotten back to this review in quite some time as I have been 
relocating to a different country. I'll try to post an updated version of this 
on GitHub this weekend.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152914

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


[clang] [Driver] Implement ToolChain on Haiku (PR #66038)

2023-09-14 Thread Brad Smith via cfe-commits

https://github.com/brad0 updated 
https://github.com/llvm/llvm-project/pull/66038:

>From ac7c3555bd703e789ff3020cea2e11cb9dc054df Mon Sep 17 00:00:00 2001
From: X512 
Date: Mon, 11 Sep 2023 20:56:02 -0400
Subject: [PATCH] [Driver] Implement ToolChain on Haiku

Co-authored-by: David Karoly 
Co-authored-by: Brad Smith 
---
 clang/lib/Driver/ToolChains/Gnu.cpp   |  31 
 clang/lib/Driver/ToolChains/Haiku.cpp | 139 +-
 clang/lib/Driver/ToolChains/Haiku.h   |  34 -
 .../boot/system/develop/lib/crti.o|   0
 .../boot/system/develop/lib/crtn.o|   0
 .../boot/system/develop/lib/init_term_dyn.o   |   0
 .../boot/system/develop/lib/start_dyn.o   |   0
 .../x86_64-unknown-haiku/13.2.0/crtbegin.o|   0
 .../x86_64-unknown-haiku/13.2.0/crtbeginS.o   |   0
 .../gcc/x86_64-unknown-haiku/13.2.0/crtend.o  |   0
 .../gcc/x86_64-unknown-haiku/13.2.0/crtendS.o |   0
 clang/test/Driver/haiku.c |  44 ++
 12 files changed, 241 insertions(+), 7 deletions(-)
 create mode 100644 
clang/test/Driver/Inputs/haiku_x86_64_tree/boot/system/develop/lib/crti.o
 create mode 100644 
clang/test/Driver/Inputs/haiku_x86_64_tree/boot/system/develop/lib/crtn.o
 create mode 100644 
clang/test/Driver/Inputs/haiku_x86_64_tree/boot/system/develop/lib/init_term_dyn.o
 create mode 100644 
clang/test/Driver/Inputs/haiku_x86_64_tree/boot/system/develop/lib/start_dyn.o
 create mode 100644 
clang/test/Driver/Inputs/haiku_x86_64_tree/boot/system/develop/tools/lib/gcc/x86_64-unknown-haiku/13.2.0/crtbegin.o
 create mode 100644 
clang/test/Driver/Inputs/haiku_x86_64_tree/boot/system/develop/tools/lib/gcc/x86_64-unknown-haiku/13.2.0/crtbeginS.o
 create mode 100644 
clang/test/Driver/Inputs/haiku_x86_64_tree/boot/system/develop/tools/lib/gcc/x86_64-unknown-haiku/13.2.0/crtend.o
 create mode 100644 
clang/test/Driver/Inputs/haiku_x86_64_tree/boot/system/develop/tools/lib/gcc/x86_64-unknown-haiku/13.2.0/crtendS.o

diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index 7aeb8e29ebc5574..cd6713ab52d926d 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -2224,6 +2224,12 @@ bool 
Generic_GCC::GCCInstallationDetector::getBiarchSibling(Multilib ) const {
 void Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
 const llvm::Triple , SmallVectorImpl ,
 StringRef SysRoot) {
+
+  if (TargetTriple.isOSHaiku()) {
+Prefixes.push_back(concat(SysRoot, "/boot/system/develop/tools"));
+return;
+  }
+
   if (TargetTriple.isOSSolaris()) {
 // Solaris is a special case.
 // The GCC installation is under
@@ -2426,6 +2432,31 @@ void 
Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
   using std::begin;
   using std::end;
 
+  if (TargetTriple.isOSHaiku()) {
+static const char *const HaikuLibDirs[] = {"/lib"};
+static const char *const HaikuAArch64Triples[] = {"aarch64-unknown-haiku"};
+static const char *const HaikuRISCV64Triples[] = {"riscv64-unknown-haiku"};
+static const char *const HaikuX86Triples[] = {"i586-unknown-haiku"};
+static const char *const HaikuX86_64Triples[] = {"x86_64-unknown-haiku"};
+LibDirs.append(begin(HaikuLibDirs), end(HaikuLibDirs));
+switch (TargetTriple.getArch()) {
+case llvm::Triple::aarch64:
+  TripleAliases.append(begin(HaikuAArch64Triples), 
end(HaikuAArch64Triples));
+  break;
+case llvm::Triple::riscv64:
+  TripleAliases.append(begin(HaikuRISCV64Triples), 
end(HaikuRISCV64Triples));
+  break;
+case llvm::Triple::x86:
+  TripleAliases.append(begin(HaikuX86Triples), end(HaikuX86Triples));
+  break;
+case llvm::Triple::x86_64:
+  TripleAliases.append(begin(HaikuX86_64Triples), end(HaikuX86_64Triples));
+  break;
+default:
+  break;
+}
+  }
+
   if (TargetTriple.isOSSolaris()) {
 static const char *const SolarisLibDirs[] = {"/lib"};
 static const char *const SolarisSparcV8Triples[] = {
diff --git a/clang/lib/Driver/ToolChains/Haiku.cpp 
b/clang/lib/Driver/ToolChains/Haiku.cpp
index 55fc0533f699fab..d5c94c80a722014 100644
--- a/clang/lib/Driver/ToolChains/Haiku.cpp
+++ b/clang/lib/Driver/ToolChains/Haiku.cpp
@@ -9,20 +9,145 @@
 #include "Haiku.h"
 #include "CommonArgs.h"
 #include "clang/Config/config.h"
+#include "clang/Driver/Compilation.h"
 #include "llvm/Support/Path.h"
 
 using namespace clang::driver;
+using namespace clang::driver::tools;
 using namespace clang::driver::toolchains;
 using namespace clang;
 using namespace llvm::opt;
 
+void haiku::Linker::ConstructJob(Compilation , const JobAction ,
+   const InputInfo ,
+   const InputInfoList ,
+   const ArgList ,
+   const char *LinkingOutput) const {
+  const toolchains::Haiku  =
+  static_cast(getToolChain());
+  const Driver  = 

[PATCH] D159064: [Modules] Make clang modules for the C standard library headers

2023-09-14 Thread Ian Anderson via Phabricator via cfe-commits
iana added inline comments.



Comment at: clang/lib/Headers/module.modulemap:269
+  explicit module wint_t {
+header "__stddef_wint_t.h"
+export *

iana wrote:
> Arguably this should be textual since stddef.h shouldn't own wint_t and it's 
> just here for compatibility. Otherwise I think the ODR would force wchar.h to 
> define need_wint and include stddef.h which is kind of weird?
wint_t doesn't need to be textual, it can just be split out of stddef so that 
it doesn't get precompiled, and won't be see at all normally.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159064

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


[clang] Extend `retcon.once` coroutines lowering to optionally produce a normal result (PR #66333)

2023-09-14 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

Got it. Thanks for the explanation : )

https://github.com/llvm/llvm-project/pull/66333
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Extend `retcon.once` coroutines lowering to optionally produce a normal result (PR #66333)

2023-09-14 Thread Anton Korobeynikov via cfe-commits

asl wrote:

> Got it. Thanks. Then I am wondering how about the `retcon` ABI? I am confused 
> since the doc said the last continuation of `retcon` ABI will return a 
> nullptr to indicate it has finished. Don't we have the same problem? Or we 
> can't solve the problem in `retcon` ABI? Or we just don't want to solve that 
> in the current PR?

Ah, ok. The current PR is only for `retcon.once` coroutines. I do not have a 
good use-case for `retcon` ones and they are lowered differently enough, so I 
decided not to touch them. If / when there will be a viable usecase, I will try 
to generalize the present implementation to generic `retcon` coroutines.

https://github.com/llvm/llvm-project/pull/66333
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Extend `retcon.once` coroutines lowering to optionally produce a normal result (PR #66333)

2023-09-14 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

Got it. Thanks. Then I am wondering how about the `retcon` ABI? I am confused 
since the doc said the last continuation of `retcon` ABI will return a nullptr 
to indicate it has finished. Don't we have the same problem? Or we can't solve 
the problem in `retcon` ABI? Or we just don't want to solve that in the current 
PR?

https://github.com/llvm/llvm-project/pull/66333
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NFC][CodeGen] Change CodeGenOpt::Level/CodeGenFileType into enum classes (PR #66295)

2023-09-14 Thread Arthur Eubanks via cfe-commits


@@ -661,27 +661,27 @@ static bool FixupInvocation(CompilerInvocation 
,
 
 static unsigned getOptimizationLevel(ArgList , InputKind IK,
  DiagnosticsEngine ) {
-  unsigned DefaultOpt = llvm::CodeGenOpt::None;
+  unsigned DefaultOpt = 0;
   if ((IK.getLanguage() == Language::OpenCL ||
IK.getLanguage() == Language::OpenCLCXX) &&
   !Args.hasArg(OPT_cl_opt_disable))
-DefaultOpt = llvm::CodeGenOpt::Default;
+DefaultOpt = 2;

aeubanks wrote:

We do eventually map the opt level here to a `CodeGenOpt` via 
`CodeGenOpt::getLevel()`, but we also use the opt level here for a bunch of 
other things in the clang codegen process. So whatever the "default" llvm 
codegen pipeline opt level is shouldn't be tied to a clang frontend opt level 
default.

Maybe I'm not understanding your comment.

https://github.com/llvm/llvm-project/pull/66295
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Extend `retcon.once` coroutines lowering to optionally produce a normal result (PR #66333)

2023-09-14 Thread Anton Korobeynikov via cfe-commits

asl wrote:

> What make me curious is the motivation case of the PR. I mean what can be 
> presented in retcon.once ABI after the PR which is impossible/hard before. 
> And how do we handle that in retcon ABI.

Well, the PR allows `recon.once` coroutines to have normal results in addition 
to yields. While it might be possible to "emulate" this functionality returning 
the value indirectly, it is not very convenient for producer (instead of just 
returning the value we'd need to allocate stack slot, pass the address, etc.) 
and might incur some overhead, as we'd essentially will need to capture both 
value to be returned and return address in the coroutine frame only to emit the 
store in the continuation part.

The particular usecase from Swift is as follows:
 - Yield pointer to some internals of an object
 - Allow the caller to modify the object via exposed pointer as necessary
 - In the coroutine continuation perform some "finalization" and return e.g. a 
pointer to a closure object with modified object being captured

https://github.com/llvm/llvm-project/pull/66333
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [ASTImport]improve ast comparation (PR #66110)

2023-09-14 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky closed https://github.com/llvm/llvm-project/pull/66110
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D159519: [clang][ASTImport] improve ast comparation

2023-09-14 Thread Qizhi Hu via Phabricator via cfe-commits
jcsxky created this revision.
jcsxky added reviewers: donat.nagy, steakhal, balazske.
jcsxky added projects: clang, clang-c.
Herald added subscribers: ChuanqiXu, martong.
Herald added a project: All.
jcsxky requested review of this revision.
Herald added a subscriber: cfe-commits.

1. VarDecl should not be ignored.
2. GotoStmt has no children, it should be handle explicitly.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D159519

Files:
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/unittests/AST/StructuralEquivalenceTest.cpp

Index: clang/unittests/AST/StructuralEquivalenceTest.cpp
===
--- clang/unittests/AST/StructuralEquivalenceTest.cpp
+++ clang/unittests/AST/StructuralEquivalenceTest.cpp
@@ -1,5 +1,6 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ASTStructuralEquivalence.h"
+#include "clang/AST/Decl.h"
 #include "clang/AST/DeclTemplate.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Frontend/ASTUnit.h"
@@ -1801,10 +1802,10 @@
 TEST_F(StructuralEquivalenceCacheTest, ReturnStmtNonEq) {
   auto TU = makeTuDecls(
   R"(
-  bool x(){ return true; }
+  bool x() { return true; }
   )",
   R"(
-  bool x(){ return false; }
+  bool x() { return false; }
   )",
   Lang_CXX03);
 
@@ -1817,6 +1818,60 @@
 
 }
 
+TEST_F(StructuralEquivalenceCacheTest, VarDeclNoEq) {
+  auto TU = makeTuDecls(
+  R"(
+  int p;
+  )",
+  R"(
+  int q;
+  )",
+  Lang_CXX03);
+
+  StructuralEquivalenceContext Ctx(
+  get<0>(TU)->getASTContext(), get<1>(TU)->getASTContext(),
+  NonEquivalentDecls, StructuralEquivalenceKind::Default, false, false);
+
+  auto X = findDeclPair(TU, varDecl());
+  EXPECT_FALSE(Ctx.IsEquivalent(X.first, X.second));
+}
+
+TEST_F(StructuralEquivalenceCacheTest, VarDeclWithDifferentStorageClassNoEq) {
+  auto TU = makeTuDecls(
+  R"(
+  int p;
+  )",
+  R"(
+  static int p;
+  )",
+  Lang_CXX03);
+
+  StructuralEquivalenceContext Ctx(
+  get<0>(TU)->getASTContext(), get<1>(TU)->getASTContext(),
+  NonEquivalentDecls, StructuralEquivalenceKind::Default, false, false);
+
+  auto X = findDeclPair(TU, varDecl());
+  EXPECT_FALSE(Ctx.IsEquivalent(X.first, X.second));
+}
+
+TEST_F(StructuralEquivalenceCacheTest, VarDeclWithInitNoEq) {
+  auto TU = makeTuDecls(
+  R"(
+  int p = 1;
+  )",
+  R"(
+  int p = 2;
+  )",
+  Lang_CXX03);
+
+  StructuralEquivalenceContext Ctx(
+  get<0>(TU)->getASTContext(), get<1>(TU)->getASTContext(),
+  NonEquivalentDecls, StructuralEquivalenceKind::Default, false, false);
+
+  auto X = findDeclPair(TU, varDecl());
+  EXPECT_FALSE(Ctx.IsEquivalent(X.first, X.second));
+}
+
 TEST_F(StructuralEquivalenceCacheTest, SpecialNonEq) {
   auto TU = makeTuDecls(
   R"(
@@ -2320,5 +2375,23 @@
   EXPECT_TRUE(testStructuralMatch(t));
 }
 
+TEST_F(StructuralEquivalenceCacheTest, GotoStmtNoEq) {
+  auto t = makeStmts(
+  R"(
+  void foo() {
+goto L1;
+L1: foo();
+  }
+  )",
+  R"(
+  void foo() {
+goto L2;
+L2: foo();
+  }
+  )",
+  Lang_CXX03, gotoStmt());
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
 } // end namespace ast_matchers
 } // end namespace clang
Index: clang/lib/AST/ASTStructuralEquivalence.cpp
===
--- clang/lib/AST/ASTStructuralEquivalence.cpp
+++ clang/lib/AST/ASTStructuralEquivalence.cpp
@@ -277,6 +277,17 @@
 
   bool IsStmtEquivalent(const Stmt *S1, const Stmt *S2) { return true; }
 
+  bool IsStmtEquivalent(const GotoStmt *S1, const GotoStmt *S2) {
+auto *L1 = S1->getLabel();
+auto *L2 = S2->getLabel();
+if (!L1 || !L2) {
+  return L1 == L2;
+}
+IdentifierInfo *Name1 = L1->getIdentifier();
+IdentifierInfo *Name2 = L2->getIdentifier();
+return ::IsStructurallyEquivalent(Name1, Name2);
+  }
+
   bool IsStmtEquivalent(const SourceLocExpr *E1, const SourceLocExpr *E2) {
 return E1->getIdentKind() == E2->getIdentKind();
   }
@@ -1295,6 +1306,24 @@
   return true;
 }
 
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext ,
+ VarDecl *D1, VarDecl *D2) {
+  if (D1->getStorageClass() != D2->getStorageClass()) {
+return false;
+  }
+  IdentifierInfo *Name1 = D1->getIdentifier();
+  IdentifierInfo *Name2 = D2->getIdentifier();
+  if (!::IsStructurallyEquivalent(Name1, Name2)) {
+return false;
+  }
+
+  if (!IsStructurallyEquivalent(Context, D1->getType(), D2->getType())) {
+return false;
+  }
+
+  return IsStructurallyEquivalent(Context, D1->getInit(), D2->getInit());
+}
+
 static bool IsStructurallyEquivalent(StructuralEquivalenceContext ,
  FieldDecl *Field1, FieldDecl *Field2,
  QualType Owner2Type) {

[clang] Extend `retcon.once` coroutines lowering to optionally produce a normal result (PR #66333)

2023-09-14 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

Oh, I am wondering if we have misunderstandings. I am not asking the reason why 
we don't have the problem which is discussing in  the change of CoroFrame.cpp 
in return continuation ABI. I understand that fully. 

What make me curious is the motivation case of the PR. I mean what can be 
presented in retcon.once ABI after the PR which is impossible/hard before. And 
how do we handle that in retcon ABI.

Sorry for confusion.

https://github.com/llvm/llvm-project/pull/66333
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Extend `retcon.once` coroutines lowering to optionally produce a normal result (PR #66333)

2023-09-14 Thread Anton Korobeynikov via cfe-commits

asl wrote:

> > > Out of curiousity, why don't we have the problem in the normal return 
> > > continuation ABI?
> > 
> > 
> > The problem happens when the value is directly used in `coro.end` 
> > intrinsic. For example, when we're forwarding coroutine argument as a 
> > result. Or, when the value itself is computed before the suspend. 
> > Everything else is correctly handled by the present code due to BB split 
> > (the corresponding instructions appear in `Cleanup` block for example and 
> > correctly spilled).
> 
> I still don't understand the motivation fully. Do you say we don't have the 
> problem naturally? Or could you show some motivation examples? (In LLVM IR?)

This one is problematic:
```llvm
define {ptr, ptr} @g(ptr %buffer, ptr %ptr, i8 %val) presplitcoroutine {
entry:
  %temp = alloca i32, align 4
  %id = call token @llvm.coro.id.retcon.once(i32 8, i32 8, ptr %buffer, ptr 
@prototype2, ptr @allocate, ptr @deallocate)
  %hdl = call ptr @llvm.coro.begin(token %id, ptr null)
  %oldvalue = load i32, ptr %ptr
  store i32 %oldvalue, ptr %temp
  %unwind = call i1 (...) @llvm.coro.suspend.retcon.i1(ptr %temp)
  br i1 %unwind, label %cleanup, label %cont

cont:
  %newvalue = load i32, ptr %temp
  store i32 %newvalue, ptr %ptr
  br label %cleanup

cleanup:
  call i1 (ptr, i1, ...) @llvm.coro.end(ptr %hdl, i1 0, i8 %val)
  unreachable
}
```

but this one is not:
```llvm
define {ptr, ptr} @g(ptr %buffer, ptr %ptr, i8 %val) presplitcoroutine {
entry:
  %temp = alloca i32, align 4
  %id = call token @llvm.coro.id.retcon.once(i32 8, i32 8, ptr %buffer, ptr 
@prototype2, ptr @allocate, ptr @deallocate)
  %hdl = call ptr @llvm.coro.begin(token %id, ptr null)
  %oldvalue = load i32, ptr %ptr
  store i32 %oldvalue, ptr %temp
  %unwind = call i1 (...) @llvm.coro.suspend.retcon.i1(ptr %temp)
  br i1 %unwind, label %cleanup, label %cont

cont:
  %newvalue = load i32, ptr %temp
  store i32 %newvalue, ptr %ptr
  br label %cleanup

cleanup:
  %newval = add i8 %val, 42
  call i1 (ptr, i1, ...) @llvm.coro.end(ptr %hdl, i1 0, i8 %newval)
  unreachable
}
```

This one is problematic as well:
```llvm
define {ptr, ptr} @g(ptr %buffer, ptr %ptr, i8 %val) presplitcoroutine {
entry:
  %temp = alloca i32, align 4
  %id = call token @llvm.coro.id.retcon.once(i32 8, i32 8, ptr %buffer, ptr 
@prototype2, ptr @allocate, ptr @deallocate)
  %hdl = call ptr @llvm.coro.begin(token %id, ptr null)
  %oldvalue = load i32, ptr %ptr
  store i32 %oldvalue, ptr %temp
  %newval = add i8 %val, 42
  %unwind = call i1 (...) @llvm.coro.suspend.retcon.i1(ptr %temp)
  br i1 %unwind, label %cleanup, label %cont

cont:
  %newvalue = load i32, ptr %temp
  store i32 %newvalue, ptr %ptr
  br label %cleanup

cleanup:
  call i1 (ptr, i1, ...) @llvm.coro.end(ptr %hdl, i1 0, i8 %newval)
  unreachable
}
```

All these are "new" cases I would say, everything else is handled via current 
split approach.

https://github.com/llvm/llvm-project/pull/66333
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [RISCV] Install sifive_vector.h to riscv-resource-headers (PR #66330)

2023-09-14 Thread Brandon Wu via cfe-commits


@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -triple riscv64 -target-feature +v %s
+// REQUIRES: riscv-registered-target
+
+// expected-no-diagnostics
+
+#include 

4vtomat wrote:

Lit test is run before install, how can we check it's properly installed?

https://github.com/llvm/llvm-project/pull/66330
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [Sema] add cast from IncompleteArrayType to ConstantArrayType in TryReferenceListInitialization (PR #65918)

2023-09-14 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 updated 
https://github.com/llvm/llvm-project/pull/65918:

>From cfedbe3fb2f2f331b3f9ee1f4f3e2fcd348797e2 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Mon, 11 Sep 2023 09:15:41 +0800
Subject: [PATCH 1/4] [Sema] add cast from IncompleteArrayType to
 ConstantArrayType in TryReferenceListInitialization

Fixed: https://github.com/llvm/llvm-project/issues/62945
c++20 supports "Permit conversions to arrays of unknown bound".
This need additional cast from IncompleteArrayType to ConstantArrayType
in TryReferenceListInitialization
---
 clang/lib/Sema/SemaInit.cpp   | 9 +
 clang/test/CodeGenCXX/cxx20-p0388-unbound-ary.cpp | 9 +
 2 files changed, 18 insertions(+)

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 93f05e2e47285e4..966d35226eec748 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -4532,6 +4532,15 @@ static void TryReferenceListInitialization(Sema ,
   if (T1Quals.hasAddressSpace())
 Sequence.AddQualificationConversionStep(
 cv1T1, DestType->isRValueReferenceType() ? VK_XValue : VK_LValue);
+  else if (S.getLangOpts().CPlusPlus20 &&
+   isa(T1->getUnqualifiedDesugaredType()) &&
+   DestType->isRValueReferenceType()) {
+// [dcl.init.list] p3.10
+// unless T is “reference to array of unknown bound of U”, in which 
case
+// the type of the prvalue is the type of x in the declaration U x[] H,
+// where H is the initializer list.
+Sequence.AddQualificationConversionStep(cv1T1, VK_XValue);
+  }
 } else
   Sequence.SetFailed(
   
InitializationSequence::FK_NonConstLValueReferenceBindingToTemporary);
diff --git a/clang/test/CodeGenCXX/cxx20-p0388-unbound-ary.cpp 
b/clang/test/CodeGenCXX/cxx20-p0388-unbound-ary.cpp
index 78f35a024a54014..a29f4d720c1de4e 100644
--- a/clang/test/CodeGenCXX/cxx20-p0388-unbound-ary.cpp
+++ b/clang/test/CodeGenCXX/cxx20-p0388-unbound-ary.cpp
@@ -23,4 +23,13 @@ auto (int ()[1]) {
 
   return r2;
 }
+
+// CHECK-LABEL: @_ZN3One3fooEi
+// CHECK-NEXT: entry:
+// CHECK-NEXT: ret void
+void foo(int a) {
+  auto f = [](int(&&)[]) {};
+  f({a});
+}
+
 } // namespace One

>From 0d149d1e07783d2cf7b869623c6c055b9184ce8e Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Thu, 14 Sep 2023 00:28:28 +0800
Subject: [PATCH 2/4] Update clang/lib/Sema/SemaInit.cpp

Co-authored-by: Mariya Podchishchaeva 
---
 clang/lib/Sema/SemaInit.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 966d35226eec748..d8a035b60dcb6e5 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -4535,7 +4535,7 @@ static void TryReferenceListInitialization(Sema ,
   else if (S.getLangOpts().CPlusPlus20 &&
isa(T1->getUnqualifiedDesugaredType()) &&
DestType->isRValueReferenceType()) {
-// [dcl.init.list] p3.10
+// C++20 [dcl.init.list]p3.10:
 // unless T is “reference to array of unknown bound of U”, in which 
case
 // the type of the prvalue is the type of x in the declaration U x[] H,
 // where H is the initializer list.

>From fecee704039f5c9cb964a646f0d5f27edd6101f6 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Fri, 15 Sep 2023 09:46:52 +0800
Subject: [PATCH 3/4] fix

---
 clang/lib/Sema/SemaInit.cpp | 21 -
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index d8a035b60dcb6e5..da006e98e81b99a 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -18,6 +18,7 @@
 #include "clang/AST/TypeLoc.h"
 #include "clang/Basic/CharInfo.h"
 #include "clang/Basic/SourceManager.h"
+#include "clang/Basic/Specifiers.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Sema/Designator.h"
 #include "clang/Sema/EnterExpressionEvaluationContext.h"
@@ -4527,20 +4528,22 @@ static void TryReferenceListInitialization(Sema ,
   if (Sequence) {
 if (DestType->isRValueReferenceType() ||
 (T1Quals.hasConst() && !T1Quals.hasVolatile())) {
+  if (S.getLangOpts().CPlusPlus20 &&
+  isa(T1->getUnqualifiedDesugaredType()) &&
+  DestType->isRValueReferenceType()) {
+// C++20 [dcl.init.list]p3.10:
+// List-initialization of an object or reference of type T is defined 
as
+// follows:
+// ..., unless T is “reference to array of unknown bound of U”, in 
which
+// case the type of the prvalue is the type of x in the declaration U
+// x[] H, where H is the initializer list.
+Sequence.AddQualificationConversionStep(cv1T1, clang::VK_PRValue);
+  }
   Sequence.AddReferenceBindingStep(cv1T1IgnoreAS,
/*BindingTemporary=*/true);
   if (T1Quals.hasAddressSpace())
 

[clang] [Sema] add cast from IncompleteArrayType to ConstantArrayType in TryReferenceListInitialization (PR #65918)

2023-09-14 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 updated 
https://github.com/llvm/llvm-project/pull/65918:

>From cfedbe3fb2f2f331b3f9ee1f4f3e2fcd348797e2 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Mon, 11 Sep 2023 09:15:41 +0800
Subject: [PATCH 1/4] [Sema] add cast from IncompleteArrayType to
 ConstantArrayType in TryReferenceListInitialization

Fixed: https://github.com/llvm/llvm-project/issues/62945
c++20 supports "Permit conversions to arrays of unknown bound".
This need additional cast from IncompleteArrayType to ConstantArrayType
in TryReferenceListInitialization
---
 clang/lib/Sema/SemaInit.cpp   | 9 +
 clang/test/CodeGenCXX/cxx20-p0388-unbound-ary.cpp | 9 +
 2 files changed, 18 insertions(+)

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 93f05e2e47285e4..966d35226eec748 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -4532,6 +4532,15 @@ static void TryReferenceListInitialization(Sema ,
   if (T1Quals.hasAddressSpace())
 Sequence.AddQualificationConversionStep(
 cv1T1, DestType->isRValueReferenceType() ? VK_XValue : VK_LValue);
+  else if (S.getLangOpts().CPlusPlus20 &&
+   isa(T1->getUnqualifiedDesugaredType()) &&
+   DestType->isRValueReferenceType()) {
+// [dcl.init.list] p3.10
+// unless T is “reference to array of unknown bound of U”, in which 
case
+// the type of the prvalue is the type of x in the declaration U x[] H,
+// where H is the initializer list.
+Sequence.AddQualificationConversionStep(cv1T1, VK_XValue);
+  }
 } else
   Sequence.SetFailed(
   
InitializationSequence::FK_NonConstLValueReferenceBindingToTemporary);
diff --git a/clang/test/CodeGenCXX/cxx20-p0388-unbound-ary.cpp 
b/clang/test/CodeGenCXX/cxx20-p0388-unbound-ary.cpp
index 78f35a024a54014..a29f4d720c1de4e 100644
--- a/clang/test/CodeGenCXX/cxx20-p0388-unbound-ary.cpp
+++ b/clang/test/CodeGenCXX/cxx20-p0388-unbound-ary.cpp
@@ -23,4 +23,13 @@ auto (int ()[1]) {
 
   return r2;
 }
+
+// CHECK-LABEL: @_ZN3One3fooEi
+// CHECK-NEXT: entry:
+// CHECK-NEXT: ret void
+void foo(int a) {
+  auto f = [](int(&&)[]) {};
+  f({a});
+}
+
 } // namespace One

>From 0d149d1e07783d2cf7b869623c6c055b9184ce8e Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Thu, 14 Sep 2023 00:28:28 +0800
Subject: [PATCH 2/4] Update clang/lib/Sema/SemaInit.cpp

Co-authored-by: Mariya Podchishchaeva 
---
 clang/lib/Sema/SemaInit.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 966d35226eec748..d8a035b60dcb6e5 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -4535,7 +4535,7 @@ static void TryReferenceListInitialization(Sema ,
   else if (S.getLangOpts().CPlusPlus20 &&
isa(T1->getUnqualifiedDesugaredType()) &&
DestType->isRValueReferenceType()) {
-// [dcl.init.list] p3.10
+// C++20 [dcl.init.list]p3.10:
 // unless T is “reference to array of unknown bound of U”, in which 
case
 // the type of the prvalue is the type of x in the declaration U x[] H,
 // where H is the initializer list.

>From fecee704039f5c9cb964a646f0d5f27edd6101f6 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Fri, 15 Sep 2023 09:46:52 +0800
Subject: [PATCH 3/4] fix

---
 clang/lib/Sema/SemaInit.cpp | 21 -
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index d8a035b60dcb6e5..da006e98e81b99a 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -18,6 +18,7 @@
 #include "clang/AST/TypeLoc.h"
 #include "clang/Basic/CharInfo.h"
 #include "clang/Basic/SourceManager.h"
+#include "clang/Basic/Specifiers.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Sema/Designator.h"
 #include "clang/Sema/EnterExpressionEvaluationContext.h"
@@ -4527,20 +4528,22 @@ static void TryReferenceListInitialization(Sema ,
   if (Sequence) {
 if (DestType->isRValueReferenceType() ||
 (T1Quals.hasConst() && !T1Quals.hasVolatile())) {
+  if (S.getLangOpts().CPlusPlus20 &&
+  isa(T1->getUnqualifiedDesugaredType()) &&
+  DestType->isRValueReferenceType()) {
+// C++20 [dcl.init.list]p3.10:
+// List-initialization of an object or reference of type T is defined 
as
+// follows:
+// ..., unless T is “reference to array of unknown bound of U”, in 
which
+// case the type of the prvalue is the type of x in the declaration U
+// x[] H, where H is the initializer list.
+Sequence.AddQualificationConversionStep(cv1T1, clang::VK_PRValue);
+  }
   Sequence.AddReferenceBindingStep(cv1T1IgnoreAS,
/*BindingTemporary=*/true);
   if (T1Quals.hasAddressSpace())
 

[clang] Extend `retcon.once` coroutines lowering to optionally produce a normal result (PR #66333)

2023-09-14 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

> > Out of curiousity, why don't we have the problem in the normal return 
> > continuation ABI?
> 
> The problem happens when the value is directly used in `coro.end` intrinsic. 
> For example, when we're forwarding coroutine argument as a result. Or, when 
> the value itself is computed before the suspend. Everything else is correctly 
> handled by the present code due to BB split (the corresponding instructions 
> appear in `Cleanup` block for example and correctly spilled).

I still don't understand the motivation fully. Do you say we don't have the 
problem naturally? Or could you show some motivation examples? (In LLVM IR?)

https://github.com/llvm/llvm-project/pull/66333
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [Sema] add cast from IncompleteArrayType to ConstantArrayType in TryReferenceListInitialization (PR #65918)

2023-09-14 Thread Congcong Cai via cfe-commits


@@ -4532,6 +4532,15 @@ static void TryReferenceListInitialization(Sema ,
   if (T1Quals.hasAddressSpace())
 Sequence.AddQualificationConversionStep(
 cv1T1, DestType->isRValueReferenceType() ? VK_XValue : VK_LValue);
+  else if (S.getLangOpts().CPlusPlus20 &&
+   isa(T1->getUnqualifiedDesugaredType()) &&
+   DestType->isRValueReferenceType()) {
+// [dcl.init.list] p3.10
+// unless T is “reference to array of unknown bound of U”, in which 
case
+// the type of the prvalue is the type of x in the declaration U x[] H,
+// where H is the initializer list.
+Sequence.AddQualificationConversionStep(cv1T1, VK_XValue);

HerrCai0907 wrote:

I have changed sequence in the latest commit.
The reason to qualification conversion is that in cpp 20, spec. requires 
support cast from `initializer list` to `reference to array of unknown bound`.

for example: 
```
void foo(int a) {
  auto f = [](int(&&)[]) {};
  f({a});
}
```

`{a}` should be casted from int[1] to int[].


ast will look like:
```
  `-CXXOperatorCallExpr 0x12b904d18  'void':'void' '()'
|-ImplicitCastExpr 0x12b904c58  'void (*)(int (&&)[]) 
const' 
| `-DeclRefExpr 0x12b904bd8  'void (int (&&)[]) const' 
lvalue CXXMethod 0x12b904008 'operator()' 'void (int (&&)[]) const'
|-ImplicitCastExpr 0x12b904c70  'const (lambda at 
ID/test.cpp:2:12)' lvalue 
| `-DeclRefExpr 0x12b904b10  '(lambda at 
ID/test.cpp:2:12)':'(lambda at ID/test.cpp:2:12)' lvalue Var 0x12b8ee210 'f' 
'(lambda at ID/test.cpp:2:12)':'(lambda at ID/test.cpp:2:12)'
`-MaterializeTemporaryExpr 0x12b904d00  'int[]':'int[]' 
xvalue
  `-ImplicitCastExpr 0x12b904ce8  'int[]':'int[]' 
`-InitListExpr 0x12b904c88  'int[1]'
  `-ImplicitCastExpr 0x12b904cc8  'int' 
`-DeclRefExpr 0x12b904b30  'int' lvalue ParmVar 
0x12b8edfb8 'a' 'int'
```


https://github.com/llvm/llvm-project/pull/65918
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Sema] add cast from IncompleteArrayType to ConstantArrayType in TryReferenceListInitialization (PR #65918)

2023-09-14 Thread Congcong Cai via cfe-commits


@@ -4532,6 +4532,15 @@ static void TryReferenceListInitialization(Sema ,
   if (T1Quals.hasAddressSpace())
 Sequence.AddQualificationConversionStep(
 cv1T1, DestType->isRValueReferenceType() ? VK_XValue : VK_LValue);
+  else if (S.getLangOpts().CPlusPlus20 &&
+   isa(T1->getUnqualifiedDesugaredType()) &&
+   DestType->isRValueReferenceType()) {
+// [dcl.init.list] p3.10
+// unless T is “reference to array of unknown bound of U”, in which 
case
+// the type of the prvalue is the type of x in the declaration U x[] H,
+// where H is the initializer list.
+Sequence.AddQualificationConversionStep(cv1T1, VK_XValue);

HerrCai0907 wrote:

I have changed sequence in the latest commit.
The reason to qualification conversion is that in cpp 20, spec. requires 
support cast from `initializer list` to `reference to array of unknown bound`.

for example: 
```
void foo(int a) {
  auto f = [](int(&&)[]) {};
  f({a});
}
```

`{a}` should be casted from int[1] to int[].


ast will look like:
```
  `-CXXOperatorCallExpr 0x12b904d18  'void':'void' '()'
|-ImplicitCastExpr 0x12b904c58  'void (*)(int (&&)[]) 
const' 
| `-DeclRefExpr 0x12b904bd8  'void (int (&&)[]) const' 
lvalue CXXMethod 0x12b904008 'operator()' 'void (int (&&)[]) const'
|-ImplicitCastExpr 0x12b904c70  'const (lambda at 
ID/test.cpp:2:12)' lvalue 
| `-DeclRefExpr 0x12b904b10  '(lambda at 
ID/test.cpp:2:12)':'(lambda at ID/test.cpp:2:12)' lvalue Var 0x12b8ee210 'f' 
'(lambda at ID/test.cpp:2:12)':'(lambda at ID/test.cpp:2:12)'
`-MaterializeTemporaryExpr 0x12b904d00  'int[]':'int[]' 
xvalue
  `-ImplicitCastExpr 0x12b904ce8  'int[]':'int[]' 
`-InitListExpr 0x12b904c88  'int[1]'
  `-ImplicitCastExpr 0x12b904cc8  'int' 
`-DeclRefExpr 0x12b904b30  'int' lvalue ParmVar 
0x12b8edfb8 'a' 'int'
```


https://github.com/llvm/llvm-project/pull/65918
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Extend `retcon.once` coroutines lowering to optionally produce a normal result (PR #66333)

2023-09-14 Thread Chuanqi Xu via cfe-commits


@@ -3046,7 +3046,8 @@ void coro::buildCoroutineFrame(
   // Collect the spills for arguments and other not-materializable values.
   for (Argument  : F.args())
 for (User *U : A.users())
-  if (Checker.isDefinitionAcrossSuspend(A, U))
+  if (Checker.isDefinitionAcrossSuspend(A, U) ||
+  isa(U))

ChuanqiXu9 wrote:

Thanks. The API breaking is relatively acceptable since generally we don't have 
requirement for backport compatibility. 

https://github.com/llvm/llvm-project/pull/66333
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [Sema] add cast from IncompleteArrayType to ConstantArrayType in TryReferenceListInitialization (PR #65918)

2023-09-14 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 updated 
https://github.com/llvm/llvm-project/pull/65918:

>From cfedbe3fb2f2f331b3f9ee1f4f3e2fcd348797e2 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Mon, 11 Sep 2023 09:15:41 +0800
Subject: [PATCH 1/3] [Sema] add cast from IncompleteArrayType to
 ConstantArrayType in TryReferenceListInitialization

Fixed: https://github.com/llvm/llvm-project/issues/62945
c++20 supports "Permit conversions to arrays of unknown bound".
This need additional cast from IncompleteArrayType to ConstantArrayType
in TryReferenceListInitialization
---
 clang/lib/Sema/SemaInit.cpp   | 9 +
 clang/test/CodeGenCXX/cxx20-p0388-unbound-ary.cpp | 9 +
 2 files changed, 18 insertions(+)

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 93f05e2e47285e4..966d35226eec748 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -4532,6 +4532,15 @@ static void TryReferenceListInitialization(Sema ,
   if (T1Quals.hasAddressSpace())
 Sequence.AddQualificationConversionStep(
 cv1T1, DestType->isRValueReferenceType() ? VK_XValue : VK_LValue);
+  else if (S.getLangOpts().CPlusPlus20 &&
+   isa(T1->getUnqualifiedDesugaredType()) &&
+   DestType->isRValueReferenceType()) {
+// [dcl.init.list] p3.10
+// unless T is “reference to array of unknown bound of U”, in which 
case
+// the type of the prvalue is the type of x in the declaration U x[] H,
+// where H is the initializer list.
+Sequence.AddQualificationConversionStep(cv1T1, VK_XValue);
+  }
 } else
   Sequence.SetFailed(
   
InitializationSequence::FK_NonConstLValueReferenceBindingToTemporary);
diff --git a/clang/test/CodeGenCXX/cxx20-p0388-unbound-ary.cpp 
b/clang/test/CodeGenCXX/cxx20-p0388-unbound-ary.cpp
index 78f35a024a54014..a29f4d720c1de4e 100644
--- a/clang/test/CodeGenCXX/cxx20-p0388-unbound-ary.cpp
+++ b/clang/test/CodeGenCXX/cxx20-p0388-unbound-ary.cpp
@@ -23,4 +23,13 @@ auto (int ()[1]) {
 
   return r2;
 }
+
+// CHECK-LABEL: @_ZN3One3fooEi
+// CHECK-NEXT: entry:
+// CHECK-NEXT: ret void
+void foo(int a) {
+  auto f = [](int(&&)[]) {};
+  f({a});
+}
+
 } // namespace One

>From 0d149d1e07783d2cf7b869623c6c055b9184ce8e Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Thu, 14 Sep 2023 00:28:28 +0800
Subject: [PATCH 2/3] Update clang/lib/Sema/SemaInit.cpp

Co-authored-by: Mariya Podchishchaeva 
---
 clang/lib/Sema/SemaInit.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 966d35226eec748..d8a035b60dcb6e5 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -4535,7 +4535,7 @@ static void TryReferenceListInitialization(Sema ,
   else if (S.getLangOpts().CPlusPlus20 &&
isa(T1->getUnqualifiedDesugaredType()) &&
DestType->isRValueReferenceType()) {
-// [dcl.init.list] p3.10
+// C++20 [dcl.init.list]p3.10:
 // unless T is “reference to array of unknown bound of U”, in which 
case
 // the type of the prvalue is the type of x in the declaration U x[] H,
 // where H is the initializer list.

>From fecee704039f5c9cb964a646f0d5f27edd6101f6 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Fri, 15 Sep 2023 09:46:52 +0800
Subject: [PATCH 3/3] fix

---
 clang/lib/Sema/SemaInit.cpp | 21 -
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index d8a035b60dcb6e5..da006e98e81b99a 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -18,6 +18,7 @@
 #include "clang/AST/TypeLoc.h"
 #include "clang/Basic/CharInfo.h"
 #include "clang/Basic/SourceManager.h"
+#include "clang/Basic/Specifiers.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Sema/Designator.h"
 #include "clang/Sema/EnterExpressionEvaluationContext.h"
@@ -4527,20 +4528,22 @@ static void TryReferenceListInitialization(Sema ,
   if (Sequence) {
 if (DestType->isRValueReferenceType() ||
 (T1Quals.hasConst() && !T1Quals.hasVolatile())) {
+  if (S.getLangOpts().CPlusPlus20 &&
+  isa(T1->getUnqualifiedDesugaredType()) &&
+  DestType->isRValueReferenceType()) {
+// C++20 [dcl.init.list]p3.10:
+// List-initialization of an object or reference of type T is defined 
as
+// follows:
+// ..., unless T is “reference to array of unknown bound of U”, in 
which
+// case the type of the prvalue is the type of x in the declaration U
+// x[] H, where H is the initializer list.
+Sequence.AddQualificationConversionStep(cv1T1, clang::VK_PRValue);
+  }
   Sequence.AddReferenceBindingStep(cv1T1IgnoreAS,
/*BindingTemporary=*/true);
   if (T1Quals.hasAddressSpace())
 

[clang] [Sema] add cast from IncompleteArrayType to ConstantArrayType in TryReferenceListInitialization (PR #65918)

2023-09-14 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 updated 
https://github.com/llvm/llvm-project/pull/65918:

>From cfedbe3fb2f2f331b3f9ee1f4f3e2fcd348797e2 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Mon, 11 Sep 2023 09:15:41 +0800
Subject: [PATCH 1/3] [Sema] add cast from IncompleteArrayType to
 ConstantArrayType in TryReferenceListInitialization

Fixed: https://github.com/llvm/llvm-project/issues/62945
c++20 supports "Permit conversions to arrays of unknown bound".
This need additional cast from IncompleteArrayType to ConstantArrayType
in TryReferenceListInitialization
---
 clang/lib/Sema/SemaInit.cpp   | 9 +
 clang/test/CodeGenCXX/cxx20-p0388-unbound-ary.cpp | 9 +
 2 files changed, 18 insertions(+)

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 93f05e2e47285e4..966d35226eec748 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -4532,6 +4532,15 @@ static void TryReferenceListInitialization(Sema ,
   if (T1Quals.hasAddressSpace())
 Sequence.AddQualificationConversionStep(
 cv1T1, DestType->isRValueReferenceType() ? VK_XValue : VK_LValue);
+  else if (S.getLangOpts().CPlusPlus20 &&
+   isa(T1->getUnqualifiedDesugaredType()) &&
+   DestType->isRValueReferenceType()) {
+// [dcl.init.list] p3.10
+// unless T is “reference to array of unknown bound of U”, in which 
case
+// the type of the prvalue is the type of x in the declaration U x[] H,
+// where H is the initializer list.
+Sequence.AddQualificationConversionStep(cv1T1, VK_XValue);
+  }
 } else
   Sequence.SetFailed(
   
InitializationSequence::FK_NonConstLValueReferenceBindingToTemporary);
diff --git a/clang/test/CodeGenCXX/cxx20-p0388-unbound-ary.cpp 
b/clang/test/CodeGenCXX/cxx20-p0388-unbound-ary.cpp
index 78f35a024a54014..a29f4d720c1de4e 100644
--- a/clang/test/CodeGenCXX/cxx20-p0388-unbound-ary.cpp
+++ b/clang/test/CodeGenCXX/cxx20-p0388-unbound-ary.cpp
@@ -23,4 +23,13 @@ auto (int ()[1]) {
 
   return r2;
 }
+
+// CHECK-LABEL: @_ZN3One3fooEi
+// CHECK-NEXT: entry:
+// CHECK-NEXT: ret void
+void foo(int a) {
+  auto f = [](int(&&)[]) {};
+  f({a});
+}
+
 } // namespace One

>From 0d149d1e07783d2cf7b869623c6c055b9184ce8e Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Thu, 14 Sep 2023 00:28:28 +0800
Subject: [PATCH 2/3] Update clang/lib/Sema/SemaInit.cpp

Co-authored-by: Mariya Podchishchaeva 
---
 clang/lib/Sema/SemaInit.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 966d35226eec748..d8a035b60dcb6e5 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -4535,7 +4535,7 @@ static void TryReferenceListInitialization(Sema ,
   else if (S.getLangOpts().CPlusPlus20 &&
isa(T1->getUnqualifiedDesugaredType()) &&
DestType->isRValueReferenceType()) {
-// [dcl.init.list] p3.10
+// C++20 [dcl.init.list]p3.10:
 // unless T is “reference to array of unknown bound of U”, in which 
case
 // the type of the prvalue is the type of x in the declaration U x[] H,
 // where H is the initializer list.

>From fecee704039f5c9cb964a646f0d5f27edd6101f6 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Fri, 15 Sep 2023 09:46:52 +0800
Subject: [PATCH 3/3] fix

---
 clang/lib/Sema/SemaInit.cpp | 21 -
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index d8a035b60dcb6e5..da006e98e81b99a 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -18,6 +18,7 @@
 #include "clang/AST/TypeLoc.h"
 #include "clang/Basic/CharInfo.h"
 #include "clang/Basic/SourceManager.h"
+#include "clang/Basic/Specifiers.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Sema/Designator.h"
 #include "clang/Sema/EnterExpressionEvaluationContext.h"
@@ -4527,20 +4528,22 @@ static void TryReferenceListInitialization(Sema ,
   if (Sequence) {
 if (DestType->isRValueReferenceType() ||
 (T1Quals.hasConst() && !T1Quals.hasVolatile())) {
+  if (S.getLangOpts().CPlusPlus20 &&
+  isa(T1->getUnqualifiedDesugaredType()) &&
+  DestType->isRValueReferenceType()) {
+// C++20 [dcl.init.list]p3.10:
+// List-initialization of an object or reference of type T is defined 
as
+// follows:
+// ..., unless T is “reference to array of unknown bound of U”, in 
which
+// case the type of the prvalue is the type of x in the declaration U
+// x[] H, where H is the initializer list.
+Sequence.AddQualificationConversionStep(cv1T1, clang::VK_PRValue);
+  }
   Sequence.AddReferenceBindingStep(cv1T1IgnoreAS,
/*BindingTemporary=*/true);
   if (T1Quals.hasAddressSpace())
 

[clang] Introduce paged vector (PR #66430)

2023-09-14 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

I feel like it looks better to touch https://llvm.org/docs/LangRef.html to 
introduce new ADT and tell what is the benefit (pros and cons) of the new data 
structure.

https://github.com/llvm/llvm-project/pull/66430
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Also respect SysRoot for the system library paths on DragonFly (PR #66056)

2023-09-14 Thread Brad Smith via cfe-commits

https://github.com/brad0 closed https://github.com/llvm/llvm-project/pull/66056
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 1e40dfc - [Driver] Also respect SysRoot for the system library paths on DragonFly (#66056)

2023-09-14 Thread via cfe-commits

Author: Brad Smith
Date: 2023-09-14T21:18:37-04:00
New Revision: 1e40dfc5d4e099715dcf2d5b96f2f08b9718ed24

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

LOG: [Driver] Also respect SysRoot for the system library paths on DragonFly 
(#66056)

Added: 
clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/crt1.o
clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/crti.o
clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/crtn.o
clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/gcc80/crtbegin.o
clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/gcc80/crtbeginS.o
clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/gcc80/crtend.o
clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/gcc80/crtendS.o

Modified: 
clang/lib/Driver/ToolChains/DragonFly.cpp
clang/test/Driver/dragonfly.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/DragonFly.cpp 
b/clang/lib/Driver/ToolChains/DragonFly.cpp
index 46f98f9efca2330..82c975990a32511 100644
--- a/clang/lib/Driver/ToolChains/DragonFly.cpp
+++ b/clang/lib/Driver/ToolChains/DragonFly.cpp
@@ -123,7 +123,9 @@ void dragonfly::Linker::ConstructJob(Compilation , const 
JobAction ,
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs,
options::OPT_r)) {
-CmdArgs.push_back("-L/usr/lib/gcc80");
+SmallString<128> Dir(D.SysRoot);
+llvm::sys::path::append(Dir, "/usr/lib/gcc80");
+CmdArgs.push_back(Args.MakeArgString("-L" + Dir));
 
 if (!Args.hasArg(options::OPT_static)) {
   CmdArgs.push_back("-rpath");
@@ -192,8 +194,8 @@ DragonFly::DragonFly(const Driver , const llvm::Triple 
,
 getProgramPaths().push_back(getDriver().Dir);
 
   getFilePaths().push_back(getDriver().Dir + "/../lib");
-  getFilePaths().push_back("/usr/lib");
-  getFilePaths().push_back("/usr/lib/gcc80");
+  getFilePaths().push_back(concat(getDriver().SysRoot, "/usr/lib"));
+  getFilePaths().push_back(concat(getDriver().SysRoot, "/usr/lib/gcc80"));
 }
 
 void DragonFly::AddClangSystemIncludeArgs(

diff  --git a/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/crt1.o 
b/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/crt1.o
new file mode 100644
index 000..e69de29bb2d1d64

diff  --git a/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/crti.o 
b/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/crti.o
new file mode 100644
index 000..e69de29bb2d1d64

diff  --git a/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/crtn.o 
b/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/crtn.o
new file mode 100644
index 000..e69de29bb2d1d64

diff  --git 
a/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/gcc80/crtbegin.o 
b/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/gcc80/crtbegin.o
new file mode 100644
index 000..e69de29bb2d1d64

diff  --git 
a/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/gcc80/crtbeginS.o 
b/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/gcc80/crtbeginS.o
new file mode 100644
index 000..e69de29bb2d1d64

diff  --git 
a/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/gcc80/crtend.o 
b/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/gcc80/crtend.o
new file mode 100644
index 000..e69de29bb2d1d64

diff  --git 
a/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/gcc80/crtendS.o 
b/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/gcc80/crtendS.o
new file mode 100644
index 000..e69de29bb2d1d64

diff  --git a/clang/test/Driver/dragonfly.c b/clang/test/Driver/dragonfly.c
index 477dbfe6abf43fa..8ba13c41d632c20 100644
--- a/clang/test/Driver/dragonfly.c
+++ b/clang/test/Driver/dragonfly.c
@@ -4,6 +4,21 @@
 // CHECK: "-cc1" "-triple" "x86_64-pc-dragonfly"
 // CHECK: ld{{.*}}" "--eh-frame-hdr" "-dynamic-linker" 
"/usr/libexec/ld-elf.so.{{.*}}" "--hash-style=gnu" "--enable-new-dtags" "-o" 
"a.out" "{{.*}}crt1.o" "{{.*}}crti.o" "{{.*}}crtbegin.o" "{{.*}}.o" 
"-L{{.*}}gcc{{.*}}" "-rpath" "{{.*}}gcc{{.*}}" "-lc" "-lgcc" "{{.*}}crtend.o" 
"{{.*}}crtn.o"
 
+// Check x86_64-unknown-dragonfly, X86_64
+// RUN: %clang -### %s 2>&1 --target=x86_64-unknown-dragonfly \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/basic_dragonfly_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-X86_64 %s
+// CHECK-LD-X86_64: "-cc1" "-triple" "x86_64-unknown-dragonfly"
+// CHECK-LD-X86_64-SAME: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-LD-X86_64: "{{.*}}ld{{(.exe)?}}"
+// CHECK-LD-X86_64-SAME: 
"[[SYSROOT]]{{/|}}usr{{/|}}lib{{/|}}crt1.o"
+// CHECK-LD-X86_64-SAME: 
"[[SYSROOT]]{{/|}}usr{{/|}}lib{{/|}}crti.o"
+// CHECK-LD-X86_64-SAME: 

[clang] [Driver] Also respect SysRoot for the system library paths on DragonFly (PR #66056)

2023-09-14 Thread Brad Smith via cfe-commits

brad0 wrote:

Fixed the tests so they also pass on Windows.

https://github.com/llvm/llvm-project/pull/66056
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Also respect SysRoot for the system library paths on DragonFly (PR #66056)

2023-09-14 Thread Brad Smith via cfe-commits

https://github.com/brad0 updated 
https://github.com/llvm/llvm-project/pull/66056:

>From 91ee01975c2c59b6349ee4ac310ee7b2c3dfe7af Mon Sep 17 00:00:00 2001
From: Brad Smith 
Date: Tue, 12 Sep 2023 04:43:49 -0400
Subject: [PATCH] [Driver] Also respect SysRoot for the system library paths on
 DragonFly

---
 clang/lib/Driver/ToolChains/DragonFly.cpp |  8 +---
 .../Inputs/basic_dragonfly_tree/usr/lib/crt1.o|  0
 .../Inputs/basic_dragonfly_tree/usr/lib/crti.o|  0
 .../Inputs/basic_dragonfly_tree/usr/lib/crtn.o|  0
 .../basic_dragonfly_tree/usr/lib/gcc80/crtbegin.o |  0
 .../usr/lib/gcc80/crtbeginS.o |  0
 .../basic_dragonfly_tree/usr/lib/gcc80/crtend.o   |  0
 .../basic_dragonfly_tree/usr/lib/gcc80/crtendS.o  |  0
 clang/test/Driver/dragonfly.c | 15 +++
 9 files changed, 20 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/crt1.o
 create mode 100644 clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/crti.o
 create mode 100644 clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/crtn.o
 create mode 100644 
clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/gcc80/crtbegin.o
 create mode 100644 
clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/gcc80/crtbeginS.o
 create mode 100644 
clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/gcc80/crtend.o
 create mode 100644 
clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/gcc80/crtendS.o

diff --git a/clang/lib/Driver/ToolChains/DragonFly.cpp 
b/clang/lib/Driver/ToolChains/DragonFly.cpp
index 46f98f9efca2330..82c975990a32511 100644
--- a/clang/lib/Driver/ToolChains/DragonFly.cpp
+++ b/clang/lib/Driver/ToolChains/DragonFly.cpp
@@ -123,7 +123,9 @@ void dragonfly::Linker::ConstructJob(Compilation , const 
JobAction ,
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs,
options::OPT_r)) {
-CmdArgs.push_back("-L/usr/lib/gcc80");
+SmallString<128> Dir(D.SysRoot);
+llvm::sys::path::append(Dir, "/usr/lib/gcc80");
+CmdArgs.push_back(Args.MakeArgString("-L" + Dir));
 
 if (!Args.hasArg(options::OPT_static)) {
   CmdArgs.push_back("-rpath");
@@ -192,8 +194,8 @@ DragonFly::DragonFly(const Driver , const llvm::Triple 
,
 getProgramPaths().push_back(getDriver().Dir);
 
   getFilePaths().push_back(getDriver().Dir + "/../lib");
-  getFilePaths().push_back("/usr/lib");
-  getFilePaths().push_back("/usr/lib/gcc80");
+  getFilePaths().push_back(concat(getDriver().SysRoot, "/usr/lib"));
+  getFilePaths().push_back(concat(getDriver().SysRoot, "/usr/lib/gcc80"));
 }
 
 void DragonFly::AddClangSystemIncludeArgs(
diff --git a/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/crt1.o 
b/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/crt1.o
new file mode 100644
index 000..e69de29bb2d1d64
diff --git a/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/crti.o 
b/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/crti.o
new file mode 100644
index 000..e69de29bb2d1d64
diff --git a/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/crtn.o 
b/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/crtn.o
new file mode 100644
index 000..e69de29bb2d1d64
diff --git 
a/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/gcc80/crtbegin.o 
b/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/gcc80/crtbegin.o
new file mode 100644
index 000..e69de29bb2d1d64
diff --git 
a/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/gcc80/crtbeginS.o 
b/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/gcc80/crtbeginS.o
new file mode 100644
index 000..e69de29bb2d1d64
diff --git 
a/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/gcc80/crtend.o 
b/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/gcc80/crtend.o
new file mode 100644
index 000..e69de29bb2d1d64
diff --git 
a/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/gcc80/crtendS.o 
b/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/gcc80/crtendS.o
new file mode 100644
index 000..e69de29bb2d1d64
diff --git a/clang/test/Driver/dragonfly.c b/clang/test/Driver/dragonfly.c
index 477dbfe6abf43fa..8ba13c41d632c20 100644
--- a/clang/test/Driver/dragonfly.c
+++ b/clang/test/Driver/dragonfly.c
@@ -4,6 +4,21 @@
 // CHECK: "-cc1" "-triple" "x86_64-pc-dragonfly"
 // CHECK: ld{{.*}}" "--eh-frame-hdr" "-dynamic-linker" 
"/usr/libexec/ld-elf.so.{{.*}}" "--hash-style=gnu" "--enable-new-dtags" "-o" 
"a.out" "{{.*}}crt1.o" "{{.*}}crti.o" "{{.*}}crtbegin.o" "{{.*}}.o" 
"-L{{.*}}gcc{{.*}}" "-rpath" "{{.*}}gcc{{.*}}" "-lc" "-lgcc" "{{.*}}crtend.o" 
"{{.*}}crtn.o"
 
+// Check x86_64-unknown-dragonfly, X86_64
+// RUN: %clang -### %s 2>&1 --target=x86_64-unknown-dragonfly \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/basic_dragonfly_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-X86_64 %s
+// CHECK-LD-X86_64: "-cc1" 

[clang] [clang][CodeGen] Use byval for SystemZ indirect arguments (PR #66404)

2023-09-14 Thread Eli Friedman via cfe-commits

efriedma-quic wrote:

There's a special case in the msan handling precisely because byval makes the 
ABI different.  (If you look at the x86 code, you'll see that the generated 
code with byval is significantly different.)

I don't think I know enough about dfsan to follow that argument.

https://github.com/llvm/llvm-project/pull/66404
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Disable string breaking in JS for now (PR #66372)

2023-09-14 Thread Owen Pan via cfe-commits

https://github.com/owenca approved this pull request.


https://github.com/llvm/llvm-project/pull/66372
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Disable string breaking in JS for now (PR #66372)

2023-09-14 Thread Owen Pan via cfe-commits


@@ -2237,15 +2237,10 @@ ContinuationIndenter::createBreakableToken(const 
FormatToken ,
LineState , bool AllowBreak) {
   unsigned StartColumn = State.Column - Current.ColumnWidth;
   if (Current.isStringLiteral()) {
-// Strings in JSON can not be broken.
-if (Style.isJson() || !Style.BreakStringLiterals || !AllowBreak)
-  return nullptr;
-
-// Strings in TypeScript types and dictionary keys can not be broken.
-if (Style.isJavaScript() &&
-(Current.is(TT_SelectorName) ||
- State.Line->startsWith(Keywords.kw_type) ||
- State.Line->startsWith(tok::kw_export, Keywords.kw_type))) {
+// Strings in JSON can not be broken. Breaking strings in JavaScript is

owenca wrote:

```suggestion
// Strings in JSON cannot be broken. Breaking strings in JavaScript is
```

https://github.com/llvm/llvm-project/pull/66372
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Disable string breaking in JS for now (PR #66372)

2023-09-14 Thread Owen Pan via cfe-commits

https://github.com/owenca edited https://github.com/llvm/llvm-project/pull/66372
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Disable string breaking in JS for now (PR #66372)

2023-09-14 Thread Owen Pan via cfe-commits


@@ -2783,17 +2783,17 @@ the configuration (without a prefix: ``Auto``).
  const char* x =
  "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
 
-  In C#, Java, and JavaScript:
+  In C# and Java:
 
   .. code-block:: c++
 
  true:
- var x = "veryVeryVeryVeryVeryVe" +
- "ryVeryVeryVeryVeryVery" +
- "VeryLongString";
+ string x = "veryVeryVeryVeryVeryVe" +
+"ryVeryVeryVeryVeryVery" +
+"VeryLongString";
 
  false:
- var x =
+ string x =
  "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
 
   C# and JavaScript interpolated strings are not broken.

owenca wrote:

```suggestion
  C# interpolated strings are not broken.
```

https://github.com/llvm/llvm-project/pull/66372
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NFC][CodeGen] Change CodeGenOpt::Level/CodeGenFileType into enum classes (PR #66295)

2023-09-14 Thread Paul T Robinson via cfe-commits


@@ -661,27 +661,27 @@ static bool FixupInvocation(CompilerInvocation 
,
 
 static unsigned getOptimizationLevel(ArgList , InputKind IK,
  DiagnosticsEngine ) {
-  unsigned DefaultOpt = llvm::CodeGenOpt::None;
+  unsigned DefaultOpt = 0;
   if ((IK.getLanguage() == Language::OpenCL ||
IK.getLanguage() == Language::OpenCLCXX) &&
   !Args.hasArg(OPT_cl_opt_disable))
-DefaultOpt = llvm::CodeGenOpt::Default;
+DefaultOpt = 2;

pogo59 wrote:

Not that different; `CodeGenOpt::getLevel()` just uses a static_cast to 
implement the inverse mapping. This direction of the conversion should be 
consistent IMO.

https://github.com/llvm/llvm-project/pull/66295
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [DependencyScanningFilesystem] Make sure the local/shared cache filename lookups use only absolute paths (PR #66122)

2023-09-14 Thread Argyrios Kyrtzidis via cfe-commits


@@ -330,3 +353,20 @@ DependencyScanningWorkerFilesystem::openFileForRead(const 
Twine ) {
 return Result.getError();
   return DepScanFile::create(Result.get());
 }
+
+std::error_code DependencyScanningWorkerFilesystem::setCurrentWorkingDirectory(
+const Twine ) {
+  updateWorkingDirForCacheLookup(Path.str());
+  return ProxyFileSystem::setCurrentWorkingDirectory(Path);
+}
+
+void DependencyScanningWorkerFilesystem::updateWorkingDirForCacheLookup(
+llvm::ErrorOr CWD) {
+  if (CWD && !CWD->empty()) {
+WorkingDirForCacheLookup = *CWD;
+  } else {
+// The cache lookup functions will not accept relative paths for safety, so
+// at least make it absolute from a "root".
+WorkingDirForCacheLookup = "/";

akyrtzi wrote:

> For the setCurrentWorkingDirectory() call, I think it'd be reasonable to 
> clear our CWD if the new one is empty or relative, return an error code and 
> assume the VFS doesn't get used in that state. If it does, hitting one of the 
> "is file path absolute" assertions is fair game.

This would be fine for a command-line compiler invocation where you can emit an 
error and then "abort", but this is undesirable in the context of a libclang 
client, like an IDE, where some recovery in the presence of errors is useful; 
for example, clang could still try to create an AST even in the presence of 
such kind of errors in order to support the editor, instead of providing no 
functionality.

https://github.com/llvm/llvm-project/pull/66122
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Disable string breaking in JS for now (PR #66372)

2023-09-14 Thread via cfe-commits

https://github.com/alexfh approved this pull request.

This is the right call for now. There are multiple contexts in JS, TS and 
libraries like Closure, where simple string literals are expected. Getting all 
of these right may require some back-and-forths, during which clang-format will 
continue producing invalid code. Let's get back to a good state and figure out 
details after that.

https://github.com/llvm/llvm-project/pull/66372
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Stop breaking unbreakable strings in JS (PR #66168)

2023-09-14 Thread via cfe-commits

alexfh wrote:

> > Another thing is that we need to get this fixed really soon. Another (safer 
> > and actually preferred) alternative is to revert the change and address 
> > problematic use cases before recommitting it, but I'm also fine with 
> > forward-fixing this as long as fixes don't require major changes that have 
> > potential for other problems to appear.
> 
> I see. In that case, I added #66372.

I think, disabling the functionality for JS/TS is the right choice until all 
wrinkles are ironed.

> However, why do you need it fixed so soon? The latest release is version 16. 
> And the string breaking stuff isn't even in the version 17 branch.

In general, "as a community, we strongly value having the tip of tree in a good 
state while allowing rapid iterative development" (as opposed to allowing to 
break stuff after a release cut and trying to glue the pieces together before 
the next release, see 
https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy). Some LLVM 
users (toolchain teams at Google, for example) strongly rely on the ToT LLVM 
being close to (that is, at most a few patches away from) production quality. 
We are updating our toolchain ~weekly and expect all tools (including 
clang-format) to be free from critical defects (if you're interested, there's a 
talk about this: https://www.youtube.com/watch?v=zh91if43QLM). Other users 
(including multiple open-source projects) may take various parts of LLVM at 
arbitrary moments of time with similar expectations to the code quality. This 
particular problem happens to be critical, since it makes clang-format generate 
invalid code. Leaving this state for weeks after it was detected (or requiring 
users to modify their configuration just to work around the problem) is 
unacceptable, thus I think we should proceed with #66372 (or a revert of the 
original patch) for now.

https://github.com/llvm/llvm-project/pull/66168
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][CodeGen] Use byval for SystemZ indirect arguments (PR #66404)

2023-09-14 Thread Ilya Leoshkevich via cfe-commits

iii-i wrote:

There is special byval handling in MSan:

```
  void visitCallBase(CallBase , IRBuilder<> ) override {
...
for (const auto &[ArgNo, A] : llvm::enumerate(CB.args())) {
...
  bool IsByVal = CB.paramHasAttr(ArgNo, Attribute::ByVal);
```

If a target does not make use of byval, I would argue that this part of MSan is 
broken there.
Unfortunately this applies to SystemZ at the moment: `param_tls_limit.cpp` is 
marked as XFAIL because of this (the rationale that is written there, which 
says that the test is not applicable, is not correct).

A quick experiment shows that x86_64 uses byval:

```
$ uname -m
x86_64

$ clang --version
clang version 16.0.6 (Fedora 16.0.6-2.fc38)

$ cat 1.c
struct foo { char x[800]; };
void bar(struct foo) {};

$ clang -mllvm -print-after-all -c 1.c
[...]
define dso_local void @bar(ptr noundef byval(%struct.foo) align 8 %0) #0 {
[...]
```

As for the reasons why this all is the case, I think this is because of how 
arguments' shadow TLS is defined: it contains shadows of all argument values, 
where arguments are understood in terms of C, and not in terms of the ABI. This 
definition is then used in the runtime. See, for example, the handling of long 
doubles in `dfsan_custom.cpp`:

```
static int format_buffer(char *str, size_t size, const char *fmt,
 dfsan_label *va_labels, dfsan_label *ret_label,
 dfsan_origin *va_origins, dfsan_origin *ret_origin,
 va_list ap) {
[...]
case 'G':
  if (*(formatter.fmt_cur - 1) == 'L') {
retval = formatter.format(va_arg(ap, long double));
  } else {
retval = formatter.format(va_arg(ap, double));
  }
  if (va_origins == nullptr)
dfsan_set_label(*va_labels++, formatter.str_cur(),
formatter.num_written_bytes(retval));
  else
dfsan_set_label_origin(*va_labels++, *va_origins++,
   formatter.str_cur(),
   formatter.num_written_bytes(retval));
  end_fmt = true;
  break;
```

Here is wants the shadow of the long double itself, even if the target ABI 
requires passing it through a pointer.

https://github.com/llvm/llvm-project/pull/66404
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157913: [Coverage] Allow Clang coverage to be used with debug info correlation.

2023-09-14 Thread Ellis Hoag via Phabricator via cfe-commits
ellis accepted this revision.
ellis added a comment.
This revision is now accepted and ready to land.

In D157913#4646201 , @zequanwu wrote:

> In D157913#4646184 , @ellis wrote:
>
>> It looks like `debug-info-correlate-coverage.ll` was renamed twice. Is this 
>> intended?
>
> I just moved 
> `llvm/test/Instrumentation/InstrProfiling/debug-info-correlate-coverage.ll.` 
> to 
> `llvm/test/Instrumentation/InstrProfiling/debug-info-correlate-byte-coverage.ll`
>  and created a new test file 
> `llvm/test/Instrumentation/InstrProfiling/debug-info-correlate-clang-coverage.ll.`

Got it! Sorry I got confused by the UI.

Sounds good to me! I'm excited to see clang instrumentation can take full 
advantage of debug info correlation!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157913

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


[PATCH] D157385: [clang][CFG] Cleanup functions

2023-09-14 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert added inline comments.



Comment at: clang/test/Analysis/scopes-cfg-output.cpp:1472
+// CHECK-NEXT:2:  (CXXConstructExpr, [B1.3], F)
+// CHECK-NEXT:3: F f __attribute__((cleanup(cleanup_F)));
+// CHECK-NEXT:4: CleanupFunction (cleanup_F)

The test failure in D152504 suggests that this needs to be written as
```
__attribute__((cleanup(cleanup_F))) F f
```
Maybe something changed upstream?


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

https://reviews.llvm.org/D157385

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


[PATCH] D152504: [clang][ThreadSafety] Analyze cleanup functions

2023-09-14 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert added a comment.

Side note: I hope you've seen the failing test 
`Analysis/scopes-cfg-output.cpp`, but since that belongs to the predecessor 
change I assume it's an issue there.


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

https://reviews.llvm.org/D152504

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


[clang] Re-apply "[Parse] Split incremental-extensions" (PR #66446)

2023-09-14 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang


Changes
Re-applies #65683 with a fix to always run
`Actions.ActOnEndOfTranslationUnit` regardless of incremental processing.
--
Full diff: https://github.com/llvm/llvm-project/pull/66446.diff

4 Files Affected:

- (modified) clang/include/clang/Lex/Preprocessor.h (+5-5) 
- (modified) clang/lib/Lex/PPLexerChange.cpp (+1-1) 
- (modified) clang/lib/Lex/Preprocessor.cpp (+4) 
- (modified) clang/lib/Parse/Parser.cpp (+6-1) 



diff --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index bc1d94a61508d8d..575d08b83fd3a02 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -277,6 +277,9 @@ class Preprocessor {
   /// Empty line handler.
   EmptylineHandler *Emptyline = nullptr;
 
+  /// True to avoid tearing down the lexer etc on EOF
+  bool IncrementalProcessing = false;
+
 public:
   /// The kind of translation unit we are processing.
   const TranslationUnitKind TUKind;
@@ -1910,14 +1913,11 @@ class Preprocessor {
   void recomputeCurLexerKind();
 
   /// Returns true if incremental processing is enabled
-  bool isIncrementalProcessingEnabled() const {
-return getLangOpts().IncrementalExtensions;
-  }
+  bool isIncrementalProcessingEnabled() const { return IncrementalProcessing; }
 
   /// Enables the incremental processing
   void enableIncrementalProcessing(bool value = true) {
-// FIXME: Drop this interface.
-const_castlt;LangOptions 
amp;gt;(getLangOpts()).IncrementalExtensions = value;
+IncrementalProcessing = value;
   }
 
   /// Specify the point at which code-completion will be performed.
diff --git a/clang/lib/Lex/PPLexerChange.cpp b/clang/lib/Lex/PPLexerChange.cpp
index ab005381adfaf2c..811a760420e0a2d 100644
--- a/clang/lib/Lex/PPLexerChange.cpp
+++ b/clang/lib/Lex/PPLexerChange.cpp
@@ -541,7 +541,7 @@ bool Preprocessor::HandleEndOfFile(Token amp;Result, 
bool isEndOfMacro) {
   Result.startToken();
   CurLexer-gt;BufferPtr = EndPos;
 
-  if (isIncrementalProcessingEnabled()) {
+  if (getLangOpts().IncrementalExtensions) {
 CurLexer-gt;FormTokenWithChars(Result, EndPos, 
tok::annot_repl_input_end);
 Result.setAnnotationEndLoc(Result.getLocation());
 Result.setAnnotationValue(nullptr);
diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp
index 8de78a13930ed62..f0381c18a8b6f77 100644
--- a/clang/lib/Lex/Preprocessor.cpp
+++ b/clang/lib/Lex/Preprocessor.cpp
@@ -146,6 +146,10 @@ 
Preprocessor::Preprocessor(std::shared_ptrlt;PreprocessorOptionsgt; 
PPOpts,
 Ident_AbnormalTermination = nullptr;
   }
 
+  // Default incremental processing to -fincremental-extensions, clients can
+  // override with `enableIncrementalProcessing` if desired.
+  IncrementalProcessing = LangOpts.IncrementalExtensions;
+
   // If using a PCH where a #pragma hdrstop is expected, start skipping tokens.
   if (usingPCHWithPragmaHdrStop())
 SkippingUntilPragmaHdrStop = true;
diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index 09215b8303ecf9c..dda1dbaa0c21aa9 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -615,6 +615,11 @@ bool Parser::ParseTopLevelDecl(DeclGroupPtrTy 
amp;Result,
Sema::ModuleImportState amp;ImportState) {
   DestroyTemplateIdAnnotationsRAIIObj CleanupRAII(*this);
 
+  // Skip over the EOF token, flagging end of previous input for incremental
+  // processing
+  if (PP.isIncrementalProcessingEnabled() amp;amp; Tok.is(tok::eof))
+ConsumeToken();
+
   Result = nullptr;
   switch (Tok.getKind()) {
   case tok::annot_pragma_unused:
@@ -1038,7 +1043,7 @@ Parser::ParseExternalDeclaration(ParsedAttributes 
amp;Attrs,
   ConsumeToken();
   return nullptr;
 }
-if (PP.isIncrementalProcessingEnabled() amp;amp;
+if (getLangOpts().IncrementalExtensions amp;amp;
 !isDeclarationStatement(/*DisambiguatingWithExpression=*/true))
   return ParseTopLevelStmtDecl();
 




https://github.com/llvm/llvm-project/pull/66446
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D152504: [clang][ThreadSafety] Analyze cleanup functions

2023-09-14 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert accepted this revision.
aaronpuchert added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Analysis/ThreadSafety.cpp:1776
 /// \param D The callee declaration.
 /// \param Self  If \p Exp = nullptr, the implicit this argument.
 /// \param Loc   If \p Exp = nullptr, the location.

aaronpuchert wrote:
> We should relax this like "the implicit this argument or the argument to an 
> implicitly called cleanup function".
Would be nice if you could also adapt the comment as stated.


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

https://reviews.llvm.org/D152504

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


[clang] Re-apply "[Parse] Split incremental-extensions" (PR #66446)

2023-09-14 Thread via cfe-commits

https://github.com/llvmbot labeled 
https://github.com/llvm/llvm-project/pull/66446
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Re-apply "[Parse] Split incremental-extensions" (PR #66446)

2023-09-14 Thread via cfe-commits

https://github.com/llvmbot labeled 
https://github.com/llvm/llvm-project/pull/66446
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Re-apply "[Parse] Split incremental-extensions" (PR #66446)

2023-09-14 Thread Ben Barham via cfe-commits

https://github.com/bnbarham review_requested 
https://github.com/llvm/llvm-project/pull/66446
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Re-apply "[Parse] Split incremental-extensions" (PR #66446)

2023-09-14 Thread Ben Barham via cfe-commits

https://github.com/bnbarham created 
https://github.com/llvm/llvm-project/pull/66446:

Re-applies #65683 with a fix to always run
`Actions.ActOnEndOfTranslationUnit` regardless of incremental processing.

>From 9063bb14660836507ccf1b5c36256bd5f9d1d21c Mon Sep 17 00:00:00 2001
From: Ben Barham 
Date: Tue, 22 Aug 2023 16:58:00 -0700
Subject: [PATCH] Re-apply "[Parse] Split incremental-extensions"

Re-applies #65683 with a fix to always run
`Actions.ActOnEndOfTranslationUnit` regardless of incremental
processing.
---
 clang/include/clang/Lex/Preprocessor.h | 10 +-
 clang/lib/Lex/PPLexerChange.cpp|  2 +-
 clang/lib/Lex/Preprocessor.cpp |  4 
 clang/lib/Parse/Parser.cpp |  7 ++-
 4 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index bc1d94a61508d8d..575d08b83fd3a02 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -277,6 +277,9 @@ class Preprocessor {
   /// Empty line handler.
   EmptylineHandler *Emptyline = nullptr;
 
+  /// True to avoid tearing down the lexer etc on EOF
+  bool IncrementalProcessing = false;
+
 public:
   /// The kind of translation unit we are processing.
   const TranslationUnitKind TUKind;
@@ -1910,14 +1913,11 @@ class Preprocessor {
   void recomputeCurLexerKind();
 
   /// Returns true if incremental processing is enabled
-  bool isIncrementalProcessingEnabled() const {
-return getLangOpts().IncrementalExtensions;
-  }
+  bool isIncrementalProcessingEnabled() const { return IncrementalProcessing; }
 
   /// Enables the incremental processing
   void enableIncrementalProcessing(bool value = true) {
-// FIXME: Drop this interface.
-const_cast(getLangOpts()).IncrementalExtensions = value;
+IncrementalProcessing = value;
   }
 
   /// Specify the point at which code-completion will be performed.
diff --git a/clang/lib/Lex/PPLexerChange.cpp b/clang/lib/Lex/PPLexerChange.cpp
index ab005381adfaf2c..811a760420e0a2d 100644
--- a/clang/lib/Lex/PPLexerChange.cpp
+++ b/clang/lib/Lex/PPLexerChange.cpp
@@ -541,7 +541,7 @@ bool Preprocessor::HandleEndOfFile(Token , bool 
isEndOfMacro) {
   Result.startToken();
   CurLexer->BufferPtr = EndPos;
 
-  if (isIncrementalProcessingEnabled()) {
+  if (getLangOpts().IncrementalExtensions) {
 CurLexer->FormTokenWithChars(Result, EndPos, tok::annot_repl_input_end);
 Result.setAnnotationEndLoc(Result.getLocation());
 Result.setAnnotationValue(nullptr);
diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp
index 8de78a13930ed62..f0381c18a8b6f77 100644
--- a/clang/lib/Lex/Preprocessor.cpp
+++ b/clang/lib/Lex/Preprocessor.cpp
@@ -146,6 +146,10 @@ 
Preprocessor::Preprocessor(std::shared_ptr PPOpts,
 Ident_AbnormalTermination = nullptr;
   }
 
+  // Default incremental processing to -fincremental-extensions, clients can
+  // override with `enableIncrementalProcessing` if desired.
+  IncrementalProcessing = LangOpts.IncrementalExtensions;
+
   // If using a PCH where a #pragma hdrstop is expected, start skipping tokens.
   if (usingPCHWithPragmaHdrStop())
 SkippingUntilPragmaHdrStop = true;
diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index 09215b8303ecf9c..dda1dbaa0c21aa9 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -615,6 +615,11 @@ bool Parser::ParseTopLevelDecl(DeclGroupPtrTy ,
Sema::ModuleImportState ) {
   DestroyTemplateIdAnnotationsRAIIObj CleanupRAII(*this);
 
+  // Skip over the EOF token, flagging end of previous input for incremental
+  // processing
+  if (PP.isIncrementalProcessingEnabled() && Tok.is(tok::eof))
+ConsumeToken();
+
   Result = nullptr;
   switch (Tok.getKind()) {
   case tok::annot_pragma_unused:
@@ -1038,7 +1043,7 @@ Parser::ParseExternalDeclaration(ParsedAttributes ,
   ConsumeToken();
   return nullptr;
 }
-if (PP.isIncrementalProcessingEnabled() &&
+if (getLangOpts().IncrementalExtensions &&
 !isDeclarationStatement(/*DisambiguatingWithExpression=*/true))
   return ParseTopLevelStmtDecl();
 

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


[clang] [clang][CodeGen] Use byval for SystemZ indirect arguments (PR #66404)

2023-09-14 Thread Eli Friedman via cfe-commits

efriedma-quic wrote:

> I just checked with a few small examples, and while the ABI does not seem to 
> change, the code generation looks broken for tail recursion:

I'd guess the SystemZ backend doesn't implement byval properly (since it's not 
required for the C calling convention, probably nobody would notice any issues).

> Regarding MSan/DFSan, they need to know whether to copy value's or pointer's 
> shadow into arguments' TLS

I don't see why you'd need to distinguish between two cases that generate 
identical IR, unless you think the additional information can somehow lead to 
more accurate diagnostics.  Other targets emit struct arguments in a similar 
way without any special handling in msan.

https://github.com/llvm/llvm-project/pull/66404
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [MLIR] Enabling Intel GPU Integration. (PR #65539)

2023-09-14 Thread Sang Ik Lee via cfe-commits


@@ -71,7 +71,8 @@ void GPUToSPIRVPass::runOnOperation() {
   std::unique_ptr target =
   spirv::getMemorySpaceToStorageClassTarget(*context);
   spirv::MemorySpaceToStorageClassMap memorySpaceMap =
-  spirv::mapMemorySpaceToVulkanStorageClass;
+  this->useOpenCL ? spirv::mapMemorySpaceToOpenCLStorageClass :
+  spirv::mapMemorySpaceToVulkanStorageClass;

silee2 wrote:

Created #66445 which includes the code change and unit-test for covering.

https://github.com/llvm/llvm-project/pull/65539
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [MLIR] Enabling Intel GPU Integration. (PR #65539)

2023-09-14 Thread Sang Ik Lee via cfe-commits


@@ -71,7 +71,8 @@ void GPUToSPIRVPass::runOnOperation() {
   std::unique_ptr target =
   spirv::getMemorySpaceToStorageClassTarget(*context);
   spirv::MemorySpaceToStorageClassMap memorySpaceMap =
-  spirv::mapMemorySpaceToVulkanStorageClass;
+  this->useOpenCL ? spirv::mapMemorySpaceToOpenCLStorageClass :
+  spirv::mapMemorySpaceToVulkanStorageClass;

silee2 wrote:

Created #66445 which includes the code change and unit-test for covering.

https://github.com/llvm/llvm-project/pull/65539
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D74094: Reapply: [IRGen] Emit lifetime intrinsics around temporary aggregate argument allocas

2023-09-14 Thread David Tellenbach via Phabricator via cfe-commits
tellenbach added a comment.

No real comment on the issue itself but on the example as a former Eigen 
maintainer (sorry for the noise if that's all obvious for you):

  auto round (Tensor m) {
  return (m + 0.5f).cast().cast();
  }

does not return a Tensor but an expression encoding the computation which is 
evaluated during the assignment `const Tensor t3 = round(a.log().exp());` using 
an overloaded `operator=`. With "evaluation" I mean evaluation the in the sense 
of performing the intended mathematical computation.

Many things can go wrong when using `auto` in such cases, of which two seem to 
be relevant here:

1. Eigen can (this is an implementation detail(!)) decide to evaluate 
subexpressions into temporaries. The returned expression would then reference 
the result of such an evaluation beyond its lifetime.
2. If 1. does not happen, the unevaluated expression would reference its 
arguments. The immediate `0.5f` is copied since that's cheap, but the tensor 
would be referenced. Your example function `round` takes its parameter by-value 
and the returned expression would reference it. I'm unsure if the lifetime 
would be extended in this case (again, the exact details of C++ lifetime rules 
are not my area of expertise). I think if the lifetime would be extended, ASAN 
complaining after applying this patch is wrong, if the lifetime is not extended 
ASAN should complain and the example is wrong.

Btw, these issues are so common that Eigen documents the recommendation to 
avoid using `auto` with Eigen types all together: 
https://eigen.tuxfamily.org/dox/TopicPitfalls.html#title3


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74094

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


[clang] [clang][CodeGen] Use byval for SystemZ indirect arguments (PR #66404)

2023-09-14 Thread Ilya Leoshkevich via cfe-commits

iii-i wrote:

I just checked with a few small examples, and while the ABI does not seem to 
change, the code generation looks broken for tail recursion:

```
$ cat 1.c
void baz(long double);
void quux(void) { baz((long double)1); }

$ ./bin/clang -O3 -S 1.c

$ cat 1.s
[...]
aghi%r15, -176  # stack frame
larl%r1, .LCPI0_0   # address of (long double)1 in the literal pool
lxeb%f0, 0(%r1) # f0:f2=(long double)1
la  %r2, 160(%r15)  # r2=_160
std %f0, 160(%r15)  # var_160=(long double)1
std %f2, 168(%r15)
aghi%r15, 176   # var_160 is above the stack pointer now!
jg  baz@PLT # baz(_160)
[...]
```

Regarding MSan/DFSan, they need to know whether to copy value's or pointer's 
shadow into arguments' TLS. MSan already has checks for that 
(`CB.paramHasAttr(ArgNo, Attribute::ByVal)`), and for DFSan I've added them in 
my local branch.

https://github.com/llvm/llvm-project/pull/66404
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][doc] Add documentation for the ASTs used to represent C++ templates (PR #66436)

2023-09-14 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik review_requested 
https://github.com/llvm/llvm-project/pull/66436
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][doc] Add documentation for the ASTs used to represent C++ templates (PR #66436)

2023-09-14 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik review_requested 
https://github.com/llvm/llvm-project/pull/66436
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][doc] Add documentation for the ASTs used to represent C++ templates (PR #66436)

2023-09-14 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik review_requested 
https://github.com/llvm/llvm-project/pull/66436
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][deps] Load module map file from PCM (PR #66389)

2023-09-14 Thread Ben Langmuir via cfe-commits


@@ -1307,6 +1307,9 @@ void ModuleMap::setInferredModuleAllowedBy(Module *M,
 
 std::error_code
 ModuleMap::canonicalizeModuleMapPath(SmallVectorImpl ) {
+  FileManager  = SourceMgr.getFileManager();
+  FM.makeAbsolutePath(Path);

benlangmuir wrote:

This would also impact explicit module invocations.  I didn't realize the 
impact on path hash; good point that also seems like a concern.  I didn't 
consider ASTWriter would make it relative, so at least that case wouldn't be an 
issue.

https://github.com/llvm/llvm-project/pull/66389
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Support target names with dots in more utilities (PR #65812)

2023-09-14 Thread via cfe-commits




dankm wrote:

Hm. I'm happy with this file, but I also discovered a bunch of other 
`tool-name` tests that can be updated. I'll add those too.

https://github.com/llvm/llvm-project/pull/65812
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Support target names with dots in more utilities (PR #65812)

2023-09-14 Thread via cfe-commits

https://github.com/llvmbot labeled 
https://github.com/llvm/llvm-project/pull/65812
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Support target names with dots in more utilities (PR #65812)

2023-09-14 Thread via cfe-commits

https://github.com/llvmbot labeled 
https://github.com/llvm/llvm-project/pull/65812
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Support target names with dots in more utilities (PR #65812)

2023-09-14 Thread via cfe-commits

https://github.com/llvmbot labeled 
https://github.com/llvm/llvm-project/pull/65812
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Coverage] Add coverage for constructor member initializers. (PR #66441)

2023-09-14 Thread Zequan Wu via cfe-commits

https://github.com/ZequanWu review_requested 
https://github.com/llvm/llvm-project/pull/66441
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Coverage] Add coverage for constructor member initializers. (PR #66441)

2023-09-14 Thread Zequan Wu via cfe-commits

https://github.com/ZequanWu review_requested 
https://github.com/llvm/llvm-project/pull/66441
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Coverage] Add coverage for constructor member initializers. (PR #66441)

2023-09-14 Thread Zequan Wu via cfe-commits

https://github.com/ZequanWu review_requested 
https://github.com/llvm/llvm-project/pull/66441
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Support target names with dots in more utilities (PR #65812)

2023-09-14 Thread via cfe-commits

https://github.com/dankm updated 
https://github.com/llvm/llvm-project/pull/65812:

>From 416d75e617cc87b6e497815ce6ad1da630eb14a1 Mon Sep 17 00:00:00 2001
From: Dan McGregor 
Date: Mon, 14 Aug 2023 18:44:08 -0600
Subject: [PATCH 1/2] Support: hoist lld's executable name code to Path

Instead of using custom code to find the program name throughout
the codebase, write one function as a path helper to consistently
determine the program name. This globally correctly finds target
names with dots in them (ie freebsd13.2).
---
 lld/COFF/Driver.cpp|  2 +-
 lld/Common/Args.cpp|  6 --
 lld/ELF/Driver.cpp |  2 +-
 lld/MachO/Driver.cpp   |  2 +-
 lld/include/lld/Common/Args.h  |  2 --
 lld/wasm/Driver.cpp|  2 +-
 lldb/tools/driver/Driver.cpp   |  2 +-
 llvm/include/llvm/Support/Path.h   | 15 +++
 llvm/lib/Support/Path.cpp  |  8 
 llvm/tools/llvm-ar/llvm-ar.cpp |  3 ++-
 llvm/tools/llvm-cov/llvm-cov.cpp   |  2 +-
 llvm/tools/llvm-driver/llvm-driver.cpp |  2 +-
 llvm/tools/llvm-objcopy/llvm-objcopy.cpp   |  2 +-
 llvm/tools/llvm-objdump/llvm-objdump.cpp   |  2 +-
 llvm/tools/llvm-rc/llvm-rc.cpp |  2 +-
 llvm/tools/llvm-readobj/llvm-readobj.cpp   |  2 +-
 llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp |  2 +-
 17 files changed, 37 insertions(+), 21 deletions(-)

diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index d7476e91e03e384..03a63bf3a306b4d 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -68,7 +68,7 @@ bool link(ArrayRef args, llvm::raw_ostream 
,
   auto *ctx = new COFFLinkerContext;
 
   ctx->e.initialize(stdoutOS, stderrOS, exitEarly, disableOutput);
-  ctx->e.logName = args::getFilenameWithoutExe(args[0]);
+  ctx->e.logName = sys::path::program_name(args[0]);
   ctx->e.errorLimitExceededMsg = "too many errors emitted, stopping now"
  " (use /errorlimit:0 to see all errors)";
 
diff --git a/lld/Common/Args.cpp b/lld/Common/Args.cpp
index 48c934df3a2c931..b02d023fe19aeb5 100644
--- a/lld/Common/Args.cpp
+++ b/lld/Common/Args.cpp
@@ -85,9 +85,3 @@ std::vector lld::args::getLines(MemoryBufferRef 
mb) {
   }
   return ret;
 }
-
-StringRef lld::args::getFilenameWithoutExe(StringRef path) {
-  if (path.ends_with_insensitive(".exe"))
-return sys::path::stem(path);
-  return sys::path::filename(path);
-}
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 9d167293574fa64..957d0da1589caf8 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -143,7 +143,7 @@ bool link(ArrayRef args, llvm::raw_ostream 
,
 
 SharedFile::vernauxNum = 0;
   };
-  ctx->e.logName = args::getFilenameWithoutExe(args[0]);
+  ctx->e.logName = sys::path::program_name(args[0]);
   ctx->e.errorLimitExceededMsg = "too many errors emitted, stopping now (use "
  "--error-limit=0 to see all errors)";
 
diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp
index 00ff3439a043be9..ed0b66d4b2ec6ba 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -1428,7 +1428,7 @@ bool link(ArrayRef argsArr, 
llvm::raw_ostream ,
 InputFile::resetIdCount();
   };
 
-  ctx->e.logName = args::getFilenameWithoutExe(argsArr[0]);
+  ctx->e.logName = sys::path::program_name(argsArr[0]);
 
   MachOOptTable parser;
   InputArgList args = parser.parse(argsArr.slice(1));
diff --git a/lld/include/lld/Common/Args.h b/lld/include/lld/Common/Args.h
index 60f83fbbbf1a3c9..8822707a6a1f212 100644
--- a/lld/include/lld/Common/Args.h
+++ b/lld/include/lld/Common/Args.h
@@ -38,8 +38,6 @@ uint64_t getZOptionValue(llvm::opt::InputArgList , int 
id, StringRef key,
 
 std::vector getLines(MemoryBufferRef mb);
 
-StringRef getFilenameWithoutExe(StringRef path);
-
 } // namespace args
 } // namespace lld
 
diff --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp
index c2f5f0185781f36..f13aa520f35b100 100644
--- a/lld/wasm/Driver.cpp
+++ b/lld/wasm/Driver.cpp
@@ -89,7 +89,7 @@ bool link(ArrayRef args, llvm::raw_ostream 
,
   auto *ctx = new CommonLinkerContext;
 
   ctx->e.initialize(stdoutOS, stderrOS, exitEarly, disableOutput);
-  ctx->e.logName = args::getFilenameWithoutExe(args[0]);
+  ctx->e.logName = sys::path::program_name(args[0]);
   ctx->e.errorLimitExceededMsg = "too many errors emitted, stopping now (use "
  "-error-limit=0 to see all errors)";
 
diff --git a/lldb/tools/driver/Driver.cpp b/lldb/tools/driver/Driver.cpp
index f8058f868d53ffe..2fb760ca97a001d 100644
--- a/lldb/tools/driver/Driver.cpp
+++ b/lldb/tools/driver/Driver.cpp
@@ -754,7 +754,7 @@ int main(int argc, char const *argv[]) {
   ArrayRef arg_arr = ArrayRef(argv + 1, argc - 1);
   opt::InputArgList input_args =
   T.ParseArgs(arg_arr, MissingArgIndex, MissingArgCount);
-  

[clang] [Coverage] Add coverage for constructor member initializers. (PR #66441)

2023-09-14 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang


Changes
Before, constructor member initializers are shown as not covered. This adds 
coverage info for them.
--
Full diff: https://github.com/llvm/llvm-project/pull/66441.diff

2 Files Affected:

- (modified) clang/lib/CodeGen/CoverageMappingGen.cpp (+10-1) 
- (added) clang/test/CoverageMapping/ctor.cpp (+34) 



diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index dd81be6d96c6ee9..dbdb638d8774d4c 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -1032,11 +1032,20 @@ struct CounterCoverageMappingBuilder
 // lexer may not be able to report back precise token end locations for
 // these children nodes (llvm.org/PR39822), and moreover users will not be
 // able to see coverage for them.
+Counter BodyCounter = getRegionCounter(Body);
 bool Defaulted = false;
 if (auto *Method = dyn_castlt;CXXMethodDeclgt;(D))
   Defaulted = Method-gt;isDefaulted();
+if (auto *Ctor = dyn_castlt;CXXConstructorDeclgt;(D)) {
+  for (auto *Initializer : Ctor-gt;inits()) {
+if (Initializer-gt;isWritten()) {
+  auto *Init = Initializer-gt;getInit();
+  propagateCounts(BodyCounter, Init);
+}
+  }
+}
 
-propagateCounts(getRegionCounter(Body), Body,
+propagateCounts(BodyCounter, Body,
 /*VisitChildren=*/!Defaulted);
 assert(RegionStack.empty() amp;amp; quot;Regions entered 
but never exitedquot;);
   }
diff --git a/clang/test/CoverageMapping/ctor.cpp 
b/clang/test/CoverageMapping/ctor.cpp
new file mode 100644
index 000..26debb43c4b5875
--- /dev/null
+++ b/clang/test/CoverageMapping/ctor.cpp
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false 
-fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping 
-emit-llvm-only -main-file-name continue.c %s | FileCheck %s
+
+class A {
+public:
+int a;
+A(int a): a(a) {}
+};
+class B: public A {
+public:
+int b;
+int c;
+B(int x, int y) // CHECK:  _ZN1BC2Eii:
+: A(x), // CHECK-NEXT: File 0, [[@LINE]]:7 -gt; 
[[@LINE]]:11 = #0
+// CHECK-NEXT: File 0, [[@LINE+1]]:7 -gt; 
[[@LINE+1]]:13 = #0
+b(x == 0? 1: 2),// CHECK-NEXT: File 0, [[@LINE]]:7 -gt; 
[[@LINE]]:19 = #0
+// CHECK-NEXT: Branch,File 0, [[@LINE-1]]:7 
-gt; [[@LINE-1]]:13 = #1, (#0 - #1)
+// CHECK-NEXT: Gap,File 0, [[@LINE-2]]:14 
-gt; [[@LINE-2]]:15 = #1
+// CHECK-NEXT: File 0, [[@LINE-3]]:15 -gt; 
[[@LINE-3]]:16 = #1
+// CHECK-NEXT: File 0, [[@LINE-4]]:18 -gt; 
[[@LINE-4]]:19 = (#0 - #1)
+// CHECK-NEXT: File 0, [[@LINE+2]]:7 -gt; 
[[@LINE+8]]:8 = #0
+// CHECK-NEXT: File 0, [[@LINE+7]]:10 -gt; 
[[@LINE+7]]:12 = #0
+c([amp;]() {   // CHECK:  _ZZN1BC1EiiENKUlvE_clEv:
+// CHECK-NEXT: File 0, [[@LINE-1]]:13 -gt; 
[[@LINE+5]]:6 = #0
+// CHECK-NEXT: File 0, [[@LINE+1]]:13 -gt; 
[[@LINE+1]]:19 = #0
+if (y == 0) // CHECK-NEXT: Branch,File 0, [[@LINE]]:13 
-gt; [[@LINE]]:19 = #1, (#0 - #1)
+return 1;   // CHECK-NEXT: Gap,File 0, [[@LINE-1]]:20 
-gt; [[@LINE]]:13 = #1
+return 2;   // CHECK-NEXT: File 0, [[@LINE-1]]:13 -gt; 
[[@LINE-1]]:21 = #1
+}()) {} // CHECK-NEXT: Gap,File 0, [[@LINE-2]]:22 
-gt; [[@LINE-1]]:9 = (#0 - #1)
+};  // CHECK-NEXT: File 0, [[@LINE-2]]:9 -gt; 
[[@LINE-2]]:17 = (#0 - #1)
+
+int main() {
+B b(1,2);
+return 0;
+}




https://github.com/llvm/llvm-project/pull/66441
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Coverage] Add coverage for constructor member initializers. (PR #66441)

2023-09-14 Thread via cfe-commits

https://github.com/llvmbot labeled 
https://github.com/llvm/llvm-project/pull/66441
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Coverage] Add coverage for constructor member initializers. (PR #66441)

2023-09-14 Thread via cfe-commits

https://github.com/llvmbot labeled 
https://github.com/llvm/llvm-project/pull/66441
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Coverage] Add coverage for constructor member initializers. (PR #66441)

2023-09-14 Thread Zequan Wu via cfe-commits

https://github.com/ZequanWu created 
https://github.com/llvm/llvm-project/pull/66441:

Before, constructor member initializers are shown as not covered. This adds 
coverage info for them.

>From be614f6412f0ddd9e4fea8842fbf0ddc389e6be6 Mon Sep 17 00:00:00 2001
From: Zequan Wu 
Date: Thu, 14 Sep 2023 18:07:31 -0400
Subject: [PATCH] [Coverage] Add coverage for constructor member initializers.

Before, constructor member initializers are shown as not covered. This adds 
coverage info for them.
---
 clang/lib/CodeGen/CoverageMappingGen.cpp | 11 +++-
 clang/test/CoverageMapping/ctor.cpp  | 34 
 2 files changed, 44 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CoverageMapping/ctor.cpp

diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index dd81be6d96c6ee9..dbdb638d8774d4c 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -1032,11 +1032,20 @@ struct CounterCoverageMappingBuilder
 // lexer may not be able to report back precise token end locations for
 // these children nodes (llvm.org/PR39822), and moreover users will not be
 // able to see coverage for them.
+Counter BodyCounter = getRegionCounter(Body);
 bool Defaulted = false;
 if (auto *Method = dyn_cast(D))
   Defaulted = Method->isDefaulted();
+if (auto *Ctor = dyn_cast(D)) {
+  for (auto *Initializer : Ctor->inits()) {
+if (Initializer->isWritten()) {
+  auto *Init = Initializer->getInit();
+  propagateCounts(BodyCounter, Init);
+}
+  }
+}
 
-propagateCounts(getRegionCounter(Body), Body,
+propagateCounts(BodyCounter, Body,
 /*VisitChildren=*/!Defaulted);
 assert(RegionStack.empty() && "Regions entered but never exited");
   }
diff --git a/clang/test/CoverageMapping/ctor.cpp 
b/clang/test/CoverageMapping/ctor.cpp
new file mode 100644
index 000..26debb43c4b5875
--- /dev/null
+++ b/clang/test/CoverageMapping/ctor.cpp
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false 
-fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping 
-emit-llvm-only -main-file-name continue.c %s | FileCheck %s
+
+class A {
+public:
+int a;
+A(int a): a(a) {}
+};
+class B: public A {
+public:
+int b;
+int c;
+B(int x, int y) // CHECK:  _ZN1BC2Eii:
+: A(x), // CHECK-NEXT: File 0, [[@LINE]]:7 -> [[@LINE]]:11 
= #0
+// CHECK-NEXT: File 0, [[@LINE+1]]:7 -> 
[[@LINE+1]]:13 = #0
+b(x == 0? 1: 2),// CHECK-NEXT: File 0, [[@LINE]]:7 -> [[@LINE]]:19 
= #0
+// CHECK-NEXT: Branch,File 0, [[@LINE-1]]:7 -> 
[[@LINE-1]]:13 = #1, (#0 - #1)
+// CHECK-NEXT: Gap,File 0, [[@LINE-2]]:14 -> 
[[@LINE-2]]:15 = #1
+// CHECK-NEXT: File 0, [[@LINE-3]]:15 -> 
[[@LINE-3]]:16 = #1
+// CHECK-NEXT: File 0, [[@LINE-4]]:18 -> 
[[@LINE-4]]:19 = (#0 - #1)
+// CHECK-NEXT: File 0, [[@LINE+2]]:7 -> 
[[@LINE+8]]:8 = #0
+// CHECK-NEXT: File 0, [[@LINE+7]]:10 -> 
[[@LINE+7]]:12 = #0
+c([&]() {   // CHECK:  _ZZN1BC1EiiENKUlvE_clEv:
+// CHECK-NEXT: File 0, [[@LINE-1]]:13 -> 
[[@LINE+5]]:6 = #0
+// CHECK-NEXT: File 0, [[@LINE+1]]:13 -> 
[[@LINE+1]]:19 = #0
+if (y == 0) // CHECK-NEXT: Branch,File 0, [[@LINE]]:13 -> 
[[@LINE]]:19 = #1, (#0 - #1)
+return 1;   // CHECK-NEXT: Gap,File 0, [[@LINE-1]]:20 -> 
[[@LINE]]:13 = #1
+return 2;   // CHECK-NEXT: File 0, [[@LINE-1]]:13 -> 
[[@LINE-1]]:21 = #1
+}()) {} // CHECK-NEXT: Gap,File 0, [[@LINE-2]]:22 -> 
[[@LINE-1]]:9 = (#0 - #1)
+};  // CHECK-NEXT: File 0, [[@LINE-2]]:9 -> 
[[@LINE-2]]:17 = (#0 - #1)
+
+int main() {
+B b(1,2);
+return 0;
+}

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


[PATCH] D152206: [Basic] Support 64-bit x86 target for UEFI

2023-09-14 Thread Prabhu Karthikeyan Rajasekaran via Phabricator via cfe-commits
Prabhuk updated this revision to Diff 556813.
Prabhuk marked 2 inline comments as done.
Prabhuk added a comment.

Addressed review comments.
Added "-dll" and "-tsaware:no" linker flags for UEFI.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152206

Files:
  clang/lib/Basic/Targets.cpp
  clang/lib/Basic/Targets/OSTargets.h
  clang/lib/Basic/Targets/X86.h
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/UEFI.cpp
  clang/lib/Driver/ToolChains/UEFI.h
  clang/test/Driver/uefi.c
  llvm/lib/TargetParser/Triple.cpp
  llvm/unittests/TargetParser/TripleTest.cpp

Index: llvm/unittests/TargetParser/TripleTest.cpp
===
--- llvm/unittests/TargetParser/TripleTest.cpp
+++ llvm/unittests/TargetParser/TripleTest.cpp
@@ -462,6 +462,7 @@
   EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
   EXPECT_EQ(Triple::UEFI, T.getOS());
   EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
+  EXPECT_EQ(Triple::COFF, T.getObjectFormat());
 
   T = Triple("wasm32-unknown-unknown");
   EXPECT_EQ(Triple::wasm32, T.getArch());
Index: llvm/lib/TargetParser/Triple.cpp
===
--- llvm/lib/TargetParser/Triple.cpp
+++ llvm/lib/TargetParser/Triple.cpp
@@ -799,6 +799,8 @@
   case Triple::x86_64:
 if (T.isOSWindows())
   return Triple::COFF;
+else if (T.isUEFI())
+  return Triple::COFF;
 return Triple::ELF;
 
   case Triple::aarch64_be:
Index: clang/test/Driver/uefi.c
===
--- /dev/null
+++ clang/test/Driver/uefi.c
@@ -0,0 +1,10 @@
+// RUN: %clang -### %s --target=x86_64-unknown-uefi \
+// RUN: --sysroot=%S/platform -fuse-ld=lld 2>&1 \
+// RUN: | FileCheck -check-prefixes=CHECK %s
+// RUN: %clang -### %s --target=x86_64-uefi \
+// RUN: --sysroot=%S/platform -fuse-ld=lld 2>&1 \
+// RUN: | FileCheck -check-prefixes=CHECK %s
+// CHECK: "-cc1"
+// CHECK-SAME: "-triple" "x86_64-unknown-uefi"
+// CHECK-SAME: "-mrelocation-model" "pic" "-pic-level" "2"
+// CHECK-SAME: "-mframe-pointer=all"
Index: clang/lib/Driver/ToolChains/UEFI.h
===
--- /dev/null
+++ clang/lib/Driver/ToolChains/UEFI.h
@@ -0,0 +1,62 @@
+//===--- UEFI.h - UEFI ToolChain Implementations --*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_UEFI_H
+#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_UEFI_H
+
+#include "clang/Driver/Tool.h"
+#include "clang/Driver/ToolChain.h"
+
+namespace clang {
+namespace driver {
+namespace tools {
+namespace uefi {
+class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
+public:
+  Linker(const ToolChain ) : Tool("uefi::Linker", "lld-link", TC) {}
+
+  bool hasIntegratedCPP() const override { return false; }
+  bool isLinkJob() const override { return true; }
+
+  void ConstructJob(Compilation , const JobAction ,
+const InputInfo , const InputInfoList ,
+const llvm::opt::ArgList ,
+const char *LinkingOutput) const override;
+};
+} // end namespace uefi
+} // end namespace tools
+
+namespace toolchains {
+
+class LLVM_LIBRARY_VISIBILITY UEFI : public ToolChain {
+public:
+  UEFI(const Driver , const llvm::Triple ,
+   const llvm::opt::ArgList );
+
+protected:
+  Tool *buildLinker() const override;
+
+public:
+  bool HasNativeLLVMSupport() const override { return true; }
+  bool IsIntegratedAssemblerDefault() const override { return true; }
+  UnwindTableLevel
+  getDefaultUnwindTableLevel(const llvm::opt::ArgList ) const override {
+return UnwindTableLevel::Asynchronous;
+  }
+  bool isPICDefault() const override { return true; }
+  bool isPIEDefault(const llvm::opt::ArgList ) const override {
+return false;
+  }
+  bool isPICDefaultForced() const override { return true; }
+};
+
+} // namespace toolchains
+} // namespace driver
+} // namespace clang
+
+#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_UEFI_H
Index: clang/lib/Driver/ToolChains/UEFI.cpp
===
--- /dev/null
+++ clang/lib/Driver/ToolChains/UEFI.cpp
@@ -0,0 +1,115 @@
+//===--- UEFI.h - UEFI ToolChain Implementations --*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UEFI.h"

[clang] Fix math-errno issue (PR #66381)

2023-09-14 Thread Zahira Ammarguellat via cfe-commits

https://github.com/zahiraam edited 
https://github.com/llvm/llvm-project/pull/66381
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix math-errno issue (PR #66381)

2023-09-14 Thread Zahira Ammarguellat via cfe-commits

https://github.com/zahiraam ready_for_review 
https://github.com/llvm/llvm-project/pull/66381
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix math-errno issue (PR #66381)

2023-09-14 Thread Zahira Ammarguellat via cfe-commits

https://github.com/zahiraam updated 
https://github.com/llvm/llvm-project/pull/66381:

>From 997e3b69ac5c20a9130b957c86c08b16d23af07c Mon Sep 17 00:00:00 2001
From: Zahira Ammarguellat 
Date: Thu, 14 Sep 2023 06:27:35 -0700
Subject: [PATCH 1/3] Fix math-errno issue

---
 clang/lib/CodeGen/CGBuiltin.cpp| 41 +-
 clang/test/CodeGen/math-builtins.c |  2 ++
 clang/test/CodeGen/math-libcalls.c |  2 ++
 3 files changed, 39 insertions(+), 6 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 8b19bf85d47a19f..c69ccdb0eb522bf 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -2313,14 +2313,18 @@ RValue CodeGenFunction::EmitBuiltinExpr(const 
GlobalDecl GD, unsigned BuiltinID,
   FD->hasAttr() ? 0 : BuiltinID;
 
   bool ErrnoOverriden = false;
+  bool ErrnoOverrideValue = false;
   // True if math-errno is overriden via the
   // '#pragma float_control(precise, on)'. This pragma disables fast-math,
   // which implies math-errno.
   if (E->hasStoredFPFeatures()) {
 FPOptionsOverride OP = E->getFPFeatures();
-if (OP.hasMathErrnoOverride())
-  ErrnoOverriden = OP.getMathErrnoOverride();
+if (OP.hasMathErrnoOverride()) {
+  ErrnoOverriden = true;
+  ErrnoOverrideValue = OP.getMathErrnoOverride();
+}
   }
+
   // True if 'atttibute__((optnone)) is used. This attibute overrides
   // fast-math which implies math-errno.
   bool OptNone = CurFuncDecl && CurFuncDecl->hasAttr();
@@ -2329,8 +2333,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   // using the '#pragma float_control(precise, off)', and
   // attribute opt-none hasn't been seen.
   bool ErrnoOverridenToFalseWithOpt =
-  !ErrnoOverriden && !OptNone &&
-  CGM.getCodeGenOpts().OptimizationLevel != 0;
+   ErrnoOverriden && !ErrnoOverrideValue && !OptNone &&
+   CGM.getCodeGenOpts().OptimizationLevel != 0;
 
   // There are LLVM math intrinsics/instructions corresponding to math library
   // functions except the LLVM op will never set errno while the math library
@@ -2339,6 +2343,28 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   // LLVM counterparts if the call is marked 'const' (known to never set 
errno).
   // In case FP exceptions are enabled, the experimental versions of the
   // intrinsics model those.
+  bool ConstAlways =
+  getContext().BuiltinInfo.isConst(BuiltinID);
+
+  // There's a special case with the fma builtins where they are always const
+  // if the target environment is GNU or the target is OS is Windows and we're
+  // targeting the MSVCRT.dll environment.
+  switch (BuiltinID) {
+  case Builtin::BI__builtin_fma:
+  case Builtin::BI__builtin_fmaf:
+  case Builtin::BI__builtin_fmal:
+  case Builtin::BIfma:
+  case Builtin::BIfmaf:
+  case Builtin::BIfmal: {
+auto  = CGM.getTriple();
+if (Trip.isGNUEnvironment() || Trip.isOSMSVCRT())
+  ConstAlways = true;
+break;
+}
+  default:
+break;
+  }  
+
   bool ConstWithoutErrnoAndExceptions =
   getContext().BuiltinInfo.isConstWithoutErrnoAndExceptions(BuiltinID);
   bool ConstWithoutExceptions =
@@ -2362,14 +2388,17 @@ RValue CodeGenFunction::EmitBuiltinExpr(const 
GlobalDecl GD, unsigned BuiltinID,
   bool ConstWithoutErrnoOrExceptions =
   ConstWithoutErrnoAndExceptions || ConstWithoutExceptions;
   bool GenerateIntrinsics =
-  FD->hasAttr() && !ErrnoOverriden && !OptNone;
+   (ConstAlways && !OptNone) ||
+   (!getLangOpts().MathErrno && !(ErrnoOverriden && ErrnoOverrideValue) &&
+   !OptNone);
   if (!GenerateIntrinsics) {
 GenerateIntrinsics =
 ConstWithoutErrnoOrExceptions && !ConstWithoutErrnoAndExceptions;
 if (!GenerateIntrinsics)
   GenerateIntrinsics =
   ConstWithoutErrnoOrExceptions &&
-  (!getLangOpts().MathErrno && !ErrnoOverriden && !OptNone);
+ (!getLangOpts().MathErrno &&
+   !(ErrnoOverriden && ErrnoOverrideValue) && !OptNone);
 if (!GenerateIntrinsics)
   GenerateIntrinsics =
   ConstWithoutErrnoOrExceptions && ErrnoOverridenToFalseWithOpt;
diff --git a/clang/test/CodeGen/math-builtins.c 
b/clang/test/CodeGen/math-builtins.c
index 962e311698f5755..554c604219957ca 100644
--- a/clang/test/CodeGen/math-builtins.c
+++ b/clang/test/CodeGen/math-builtins.c
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -w -S -o - -emit-llvm
  %s | FileCheck %s -check-prefix=NO__ERRNO
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -w -S -o - -emit-llvm 
-fmath-errno %s | FileCheck %s -check-prefix=HAS_ERRNO
+//  RUN: %clang_cc1 -triple x86_64-unknown-unknown -w -S -o - -emit-llvm 
-disable-llvm-passes -O2  %s | FileCheck %s -check-prefix=NO__ERRNO
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -w -S -o - -emit-llvm 
-disable-llvm-passes -O2 -fmath-errno %s | FileCheck %s -check-prefix=HAS_ERRNO
 

[clang] Introduce paged vector (PR #66430)

2023-09-14 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-modules


Changes
None
--
Full diff: https://github.com/llvm/llvm-project/pull/66430.diff

5 Files Affected:

- (modified) clang/include/clang/Basic/SourceManager.h (+2-1) 
- (modified) clang/include/clang/Serialization/ASTReader.h (+3-2) 
- (modified) clang/lib/Basic/SourceManager.cpp (+6-6) 
- (modified) clang/lib/Serialization/ASTReader.cpp (+5-4) 
- (added) llvm/include/llvm/ADT/PagedVector.h (+96) 



diff --git a/clang/include/clang/Basic/SourceManager.h 
b/clang/include/clang/Basic/SourceManager.h
index 2f846502d6f3327..b1942a3d86afc37 100644
--- a/clang/include/clang/Basic/SourceManager.h
+++ b/clang/include/clang/Basic/SourceManager.h
@@ -43,6 +43,7 @@
 #include quot;llvm/ADT/DenseMap.hquot;
 #include quot;llvm/ADT/DenseSet.hquot;
 #include quot;llvm/ADT/IntrusiveRefCntPtr.hquot;
+#include quot;llvm/ADT/PagedVector.hquot;
 #include quot;llvm/ADT/PointerIntPair.hquot;
 #include quot;llvm/ADT/SmallVector.hquot;
 #include quot;llvm/ADT/StringRef.hquot;
@@ -699,7 +700,7 @@ class SourceManager : public 
RefCountedBaselt;SourceManagergt; {
   ///
   /// Negative FileIDs are indexes into this table. To get from ID to an index,
   /// use (-ID - 2).
-  SmallVectorlt;SrcMgr::SLocEntry, 0gt; LoadedSLocEntryTable;
+  PagedVectorlt;SrcMgr::SLocEntrygt; LoadedSLocEntryTable;
 
   /// The starting offset of the next local SLocEntry.
   ///
diff --git a/clang/include/clang/Serialization/ASTReader.h 
b/clang/include/clang/Serialization/ASTReader.h
index dc1eb21c27801fe..567aecc8246e761 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -38,6 +38,7 @@
 #include quot;llvm/ADT/DenseSet.hquot;
 #include quot;llvm/ADT/IntrusiveRefCntPtr.hquot;
 #include quot;llvm/ADT/MapVector.hquot;
+#include quot;llvm/ADT/PagedVector.hquot;
 #include quot;llvm/ADT/STLExtras.hquot;
 #include quot;llvm/ADT/SetVector.hquot;
 #include quot;llvm/ADT/SmallPtrSet.hquot;
@@ -487,7 +488,7 @@ class ASTReader
   ///
   /// When the pointer at index I is non-NULL, the type with
   /// ID = (I + 1) lt;lt; FastQual::Width has already been loaded
-  std::vectorlt;QualTypegt; TypesLoaded;
+  PagedVectorlt;QualTypegt; TypesLoaded;
 
   using GlobalTypeMapType =
   ContinuousRangeMaplt;serialization::TypeID, ModuleFile *, 4gt;;
@@ -501,7 +502,7 @@ class ASTReader
   ///
   /// When the pointer at index I is non-NULL, the declaration with ID
   /// = I + 1 has already been loaded.
-  std::vectorlt;Decl *gt; DeclsLoaded;
+  PagedVectorlt;Decl *gt; DeclsLoaded;
 
   using GlobalDeclMapType =
   ContinuousRangeMaplt;serialization::DeclID, ModuleFile *, 4gt;;
diff --git a/clang/lib/Basic/SourceManager.cpp 
b/clang/lib/Basic/SourceManager.cpp
index 0521ac7b30339ab..c028afe63ac85ad 100644
--- a/clang/lib/Basic/SourceManager.cpp
+++ b/clang/lib/Basic/SourceManager.cpp
@@ -458,7 +458,7 @@ SourceManager::AllocateLoadedSLocEntries(unsigned 
NumSLocEntries,
   CurrentLoadedOffset - TotalSize lt; NextLocalOffset) {
 return std::make_pair(0, 0);
   }
-  LoadedSLocEntryTable.resize(LoadedSLocEntryTable.size() + NumSLocEntries);
+  LoadedSLocEntryTable.expand(LoadedSLocEntryTable.size() + NumSLocEntries);
   SLocEntryLoaded.resize(LoadedSLocEntryTable.size());
   CurrentLoadedOffset -= TotalSize;
   int ID = LoadedSLocEntryTable.size();
@@ -2344,11 +2344,11 @@ SourceManager::MemoryBufferSizes 
SourceManager::getMemoryBufferSizes() const {
 }
 
 size_t SourceManager::getDataStructureSizes() const {
-  size_t size = llvm::capacity_in_bytes(MemBufferInfos)
-+ llvm::capacity_in_bytes(LocalSLocEntryTable)
-+ llvm::capacity_in_bytes(LoadedSLocEntryTable)
-+ llvm::capacity_in_bytes(SLocEntryLoaded)
-+ llvm::capacity_in_bytes(FileInfos);
+  size_t size = llvm::capacity_in_bytes(MemBufferInfos) +
+llvm::capacity_in_bytes(LocalSLocEntryTable) +
+llvm::capacity_in_bytes(LoadedSLocEntryTable.materialised()) +
+llvm::capacity_in_bytes(SLocEntryLoaded) +
+llvm::capacity_in_bytes(FileInfos);
 
   if (OverriddenFilesInfo)
 size += 
llvm::capacity_in_bytes(OverriddenFilesInfo-gt;OverriddenFiles);
diff --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index 0952244d037a77c..18b1a9a2480a73e 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -3260,7 +3260,7 @@ llvm::Error ASTReader::ReadASTBlock(ModuleFile amp;F,
   std::make_pair(LocalBaseTypeIndex,
  F.BaseTypeIndex - LocalBaseTypeIndex));
 
-TypesLoaded.resize(TypesLoaded.size() + F.LocalNumTypes);
+TypesLoaded.expand(TypesLoaded.size() + F.LocalNumTypes);
   }
   break;
 }
@@ -3290,7 +3290,7 @@ llvm::Error ASTReader::ReadASTBlock(ModuleFile amp;F,
 // module.
 F.GlobalToLocalDeclIDs[amp;F] = LocalBaseDeclID;
 
-DeclsLoaded.resize(DeclsLoaded.size() 

[clang] [clang][doc] Add documentation for the ASTs used to represent C++ templates (PR #66436)

2023-09-14 Thread via cfe-commits

https://github.com/llvmbot labeled 
https://github.com/llvm/llvm-project/pull/66436
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NFC][CodeGen] Change CodeGenOpt::Level/CodeGenFileType into enum classes (PR #66295)

2023-09-14 Thread Arthur Eubanks via cfe-commits

https://github.com/aeubanks closed 
https://github.com/llvm/llvm-project/pull/66295
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D74094: Reapply: [IRGen] Emit lifetime intrinsics around temporary aggregate argument allocas

2023-09-14 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment.

In D74094#4646152 , @nickdesaulniers 
wrote:

> In D74094#4645998 , @dexonsmith 
> wrote:
>
>> In D74094#4645562 , 
>> @nickdesaulniers wrote:
>>
>>> I don't yet fully comprehend yet what's going wrong, and probably need to 
>>> familiarize myself with the language rules around `auto`'s type deduction.
>>
>> For reduction purposes, it might be useful to factor out the auto type 
>> deduction on the return. I think you can do that with the help of `-Xclang 
>> -ast-dump`.
>
> Heh, yeah I tried that, and hit an assertion before we were able to dump the 
> full AST.
>
>   | | | | `-TypedefDecl 0x7f4a5cf03fb0  col:106 
> referenced SegmentWrapper 'std::conditional_t Matrix, 
> internal::evaluator::Alignment>, typename 
> VectorTypeCopyClean::ConstSegmentReturnType>':'clang-18: 
> /android0/llvm-project/clang/lib/AST/NestedNameSpecifier.cpp:309: void 
> clang::NestedNameSpecifier::print(raw_ostream &, const PrintingPolicy &, 
> bool) const: Assertion `!isa(T) && "Elaborated type in 
> nested-name-specifier"' failed.

That can be worked around by adding `-Xclang -ast-dump-filter=`, in 
this case `-Xclang -ast-dump -Xclang -ast-dump-filter=round`:
https://gist.github.com/nickdesaulniers/4ea4b46f112f1b3bc440020f3a2a01e1


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74094

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


[clang] Introduce paged vector (PR #66430)

2023-09-14 Thread via cfe-commits

https://github.com/llvmbot labeled 
https://github.com/llvm/llvm-project/pull/66430
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Introduce paged vector (PR #66430)

2023-09-14 Thread via cfe-commits

https://github.com/llvmbot labeled 
https://github.com/llvm/llvm-project/pull/66430
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Introduce paged vector (PR #66430)

2023-09-14 Thread via cfe-commits

https://github.com/llvmbot labeled 
https://github.com/llvm/llvm-project/pull/66430
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Introduce paged vector (PR #66430)

2023-09-14 Thread Giulio Eulisse via cfe-commits

https://github.com/ktf created https://github.com/llvm/llvm-project/pull/66430:

None

>From b952f0577dfe8112f394bd5392212f843c0cc86e Mon Sep 17 00:00:00 2001
From: Giulio Eulisse <10544+...@users.noreply.github.com>
Date: Thu, 14 Sep 2023 21:58:21 +0200
Subject: [PATCH 1/2] Introduce PagedVector class

The goal of the class is to be an (almost) drop in replacement for
SmallVector and std::vector when those are presized and filled later,
as it happens in SourceManager and ASTReader.

By splitting the actual vector in pages of the same size and allocating
the pages only when they are needed, using this containers reduces the
memory usage by a factor 4 for the cases relevant to the ALICE
experiment ROOT / cling usage.
---
 llvm/include/llvm/ADT/PagedVector.h | 96 +
 1 file changed, 96 insertions(+)
 create mode 100644 llvm/include/llvm/ADT/PagedVector.h

diff --git a/llvm/include/llvm/ADT/PagedVector.h 
b/llvm/include/llvm/ADT/PagedVector.h
new file mode 100644
index 000..dab0d249aa706e4
--- /dev/null
+++ b/llvm/include/llvm/ADT/PagedVector.h
@@ -0,0 +1,96 @@
+//===- llvm/ADT/PagedVector.h - 'Lazyly allocated' vectors *- C++
+//-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file defines the PagedVector class.
+//
+//===--===//
+#ifndef LLVM_ADT_PAGEDVECTOR_H
+#define LLVM_ADT_PAGEDVECTOR_H
+
+#include 
+
+// Notice that this does not have iterators, because if you
+// have iterators it probably means you are going to touch
+// all the memory in any case, so better use a std::vector in
+// the first place.
+template  class PagedVector {
+  size_t Size = 0;
+  // Index of where to find a given page in the data
+  mutable std::vector Lookup;
+  // Actual data
+  mutable std::vector Data;
+
+public:
+  // Add a range to the vector.
+  // When vector is accessed, it will call the callback to fill the range
+  // with data.
+
+  // Lookup an element at position i.
+  // If the given range is not filled, it will be filled.
+  // If the given range is filled, return the element.
+  T [](int Index) const { return at(Index); }
+
+  T (int Index) const {
+auto  = Lookup[Index / PAGE_SIZE];
+// If the range is not filled, fill it
+if (PageId == -1) {
+  int OldSize = Data.size();
+  PageId = OldSize / PAGE_SIZE;
+  // Allocate the memory
+  Data.resize(OldSize + PAGE_SIZE);
+  // Fill the whole capacity with empty elements
+  for (int I = 0; I < PAGE_SIZE; ++I) {
+Data[I + OldSize] = T();
+  }
+}
+// Return the element
+return Data[Index % PAGE_SIZE + PAGE_SIZE * PageId];
+  }
+
+  // Return the size of the vector
+  size_t capacity() const { return Lookup.size() * PAGE_SIZE; }
+
+  size_t size() const { return Size; }
+
+  // Expands the vector to the given size.
+  // If the vector is already bigger, does nothing.
+  void expand(size_t NewSize) {
+// You cannot shrink the vector, otherwise
+// you would have to invalidate
+assert(NewSize >= Size);
+if (NewSize <= Size) {
+  return;
+}
+if (NewSize <= capacity()) {
+  Size = NewSize;
+  return;
+}
+auto Pages = NewSize / PAGE_SIZE;
+auto Remainder = NewSize % PAGE_SIZE;
+if (Remainder) {
+  Pages += 1;
+}
+assert(Pages > Lookup.size());
+Lookup.resize(Pages, -1);
+Size = NewSize;
+  }
+
+  // Return true if the vector is empty
+  bool empty() const { return Size == 0; }
+  /// Clear the vector
+  void clear() {
+Size = 0;
+Lookup.clear();
+Data.clear();
+  }
+
+  std::vector const () const { return Data; }
+};
+
+#endif // LLVM_ADT_PAGEDVECTOR_H

>From f0c75c8af0fea27b5b758e2e5775787f33595de3 Mon Sep 17 00:00:00 2001
From: Giulio Eulisse <10544+...@users.noreply.github.com>
Date: Thu, 14 Sep 2023 22:20:29 +0200
Subject: [PATCH 2/2] Use PagedVector to reduce memory usage of sparsely
 populated vectors

---
 clang/include/clang/Basic/SourceManager.h |  3 ++-
 clang/include/clang/Serialization/ASTReader.h |  5 +++--
 clang/lib/Basic/SourceManager.cpp | 12 ++--
 clang/lib/Serialization/ASTReader.cpp |  9 +
 4 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/clang/include/clang/Basic/SourceManager.h 
b/clang/include/clang/Basic/SourceManager.h
index 2f846502d6f3327..b1942a3d86afc37 100644
--- a/clang/include/clang/Basic/SourceManager.h
+++ b/clang/include/clang/Basic/SourceManager.h
@@ -43,6 +43,7 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/ADT/PagedVector.h"
 #include "llvm/ADT/PointerIntPair.h"
 #include 

[PATCH] D69062: Resolve LWG issue 2426

2023-09-14 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF commandeered this revision.
EricWF edited reviewers, added: zoecarver; removed: EricWF.
EricWF added a comment.
Herald added a reviewer: libc++.
Herald added a project: All.

In D69062#1711610 , @ldionne wrote:

> If we want to mark the LWG issue as being resolved for libc++, I think the 
> test should be moved to the libc++ test suite. Otherwise, we're only 
> assessing that libc++ implements LWG2426 __on Clang__.

I don't agree. Clang implements this behavior, the fact that C++ chose to put 
std::atomic in the library rather than the language has more to do with C++ and 
less to do with implementation responsibility.
If making changes to libc++ won't change the output of this test, then having 
the test doesn't matter.

I've marked the LWG issue as complete in a separate commit, and I'm going to 
close this now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69062

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


[PATCH] D61364: [libcxx] [test] Fix incorrect allocator::construct assertions in associative container tests

2023-09-14 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF commandeered this revision.
EricWF edited reviewers, added: BillyONeal; removed: EricWF.
EricWF added a comment.
Herald added a project: All.

Fixing this requires a bunch of container overall in the containers that I 
don't have the time for right now.
So I'm going to go ahead and close this for being inactive.


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

https://reviews.llvm.org/D61364

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


[PATCH] D148381: [Clang] Implement the 'counted_by' attribute

2023-09-14 Thread Bill Wendling via Phabricator via cfe-commits
void added inline comments.



Comment at: clang/include/clang/Basic/Attr.td:4246
+private:
+  SourceRange countedByFieldLoc;
+public:

aaron.ballman wrote:
> void wrote:
> > erichkeane wrote:
> > > aaron.ballman wrote:
> > > > Teeny tiniest of coding style nits :-D
> > > Should we instead be capturing the field itself, rather than its 
> > > location?  It seems to me that would be more useful?
> > I tried that before and it didn't work. The issue is that at the time of 
> > parsing we don't yet have the full definition of the structure / union. So 
> > the `Decl`'s aren't really available to us yet. There may be a way to 
> > massage the parsing code to allow this to happen, but I'd like to do it as 
> > a separate patch. I'll document it with a `FIXME`.
> I think at some point we're going to want this to take an `Expr` argument 
> instead of an identifier argument, so we can support `foo.bar` and `baz[0]`, 
> etc as arguments for more complicated situations. But I believe the current 
> form is reasonable as-is (we can start taking an expression and all of these 
> identifiers should become a `MemberExpr`, so users don't have to change their 
> code).
I think that GCC may not be able to use expressions (apart from simple, 
resolvable integer arithmetic). But yeah, those types of expansions would be 
nice. There are many issues to resolve with them first---such as how to 
reference a field in a sub-struct when the fam is in another substruct:

```
struct S {
  struct A {
int count;
  } a;
  struct C {
int count;
struct X {
  int count;
} x;
  } c;
  struct F {
int fam[] __counted_by(/* how to refer to p->c.x.count? */);
  } f;
};
```



Comment at: clang/lib/Sema/SemaDecl.cpp:18029
+
+S.LookupName(Result, Scope);
+if (Result.getResultKind() == LookupResult::Found) {

aaron.ballman wrote:
> When the lookup result is not found, I think you should call 
> `Sema::DiagnoseEmptyLookup()`. This will handle giving you the error about 
> the member not being found, but it should also give you typo correction for 
> free, and if typo correction happens, you should then already know what new 
> declaration was found via the correction, so you can continue to check for 
> the other cases from there.
> 
> https://github.com/llvm/llvm-project/blob/b57df9fe9a1a230f277d671bfa0884bbda9fc1c5/clang/lib/Sema/SemaLambda.cpp#L1151
>  is an example of this being called elsewhere.
G! It's just like the rest of Clang: There are a million ways to do 
something, but none of them are documented and only one of them works for your 
particular case...kind of...and it takes a ton of arguments which seem 
counter-intuitive (`CXXScopeSpec` instead of `DeclSpec`?). All of Clang has 
been over-engineered from the beginning and it shows in how hard it is to do 
even the most basic things. So hard that people write the same things over and 
over with only small changes (see the two designated initializers 
implementations) leading to a nightmare.

The example you pointed to doesn't work. And none of the other forms seem to 
fit well enough. There are apparently many ways to "correct" a typo, but none 
of them seemed appropriate or like they'd do what I want. Is it really 
necessary to have this?



Comment at: clang/lib/Sema/SemaDecl.cpp:18035
+<< ECA->getCountedByField() << SR;
+  } else if (!Field->getType()->isIntegerType()) {
+// The "counted_by" field must have an integer type.

aaron.ballman wrote:
> void wrote:
> > aaron.ballman wrote:
> > > Errr any integer type?
> > > ```
> > > struct S {
> > >   bool HerpADerp;
> > >   int FAM[] __attribute__((counted_by(HerpADerp)));
> > > };
> > > ```
> > > seems like something we don't want, but I also wonder about enumeration 
> > > types and more interestingly, plain `char` where it could be treated as 
> > > signed or unsigned depending on compiler flags.
> > Yeah...unless they want just 1 element. ;-) I can rule a `bool` out. (Done)
> > 
> > A `char` should be fine. Dunno about signed vs. unsigned...
> The `char` situation I'm thinking about is morally: 
> https://godbolt.org/z/377WPYojz
> 
> With `-fsigned-char`, accessing `Idx` means you get the value `-1` and with 
> `-funsigned-char`, you get the value `255`. If that was used to index into 
> `FAM`, the `signed char` version would become a bounds access issue whereas 
> the `unsigned char` version works fine, so it's hard to write a portable 
> attribute that refers to a `char` member.
> 
> Then again, the `counted_by` attribute is intended to catch exactly this kind 
> of issue, so perhaps it's fine on `char`?
True. But we technically have that issue with every type. Maybe it'd be best to 
make sure we don't have a negative result?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148381


[PATCH] D157913: [Coverage] Allow Clang coverage to be used with debug info correlation.

2023-09-14 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added a comment.

In D157913#4646184 , @ellis wrote:

> It looks like `debug-info-correlate-coverage.ll` was renamed twice. Is this 
> intended?

I just moved 
`llvm/test/Instrumentation/InstrProfiling/debug-info-correlate-coverage.ll.` to 
`llvm/test/Instrumentation/InstrProfiling/debug-info-correlate-byte-coverage.ll`
 and created a new test file 
`llvm/test/Instrumentation/InstrProfiling/debug-info-correlate-clang-coverage.ll.`




Comment at: compiler-rt/lib/profile/InstrProfilingWriter.c:276-277
   __llvm_profile_get_num_counters(CountersBegin, CountersEnd);
-  const uint64_t NamesSize = DebugInfoCorrelate ? 0 : NamesEnd - NamesBegin;
+  const uint64_t NamesSize =
+  DebugInfoCorrelate && IRLevelProfile ? 0 : NamesEnd - NamesBegin;
 

ellis wrote:
> Can we remove changes to this file now that we are stripping the names 
> section?
Reverted all changes in this file.



Comment at: llvm/lib/ProfileData/InstrProfCorrelator.cpp:423
+  }
+  return;
+}

ellis wrote:
> I think this return should be on the line above to break out of the for loop 
> early. Or did I miscount the brackets?
Removed that if. It's already checked inside `IsDIEOfCovName`.



Comment at: llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp:769
   }
+  if (DebugInfoCorrelate && !ReferencedNames.empty()) {
+MDNode *Node = *M->debug_compile_units_begin();

ellis wrote:
> Just so that I understand. Does this code run only for names of unused 
> functions? Or will we store all function names with 
> `CovFunctionNameAnnotation`?
Just the names of unused functions. All instrumented functions names will still 
be stored at the same place as before.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157913

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


[PATCH] D157913: [Coverage] Allow Clang coverage to be used with debug info correlation.

2023-09-14 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu updated this revision to Diff 556809.
zequanwu marked 3 inline comments as done.
zequanwu added a comment.

Address comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157913

Files:
  clang/lib/CodeGen/CoverageMappingGen.cpp
  clang/test/CodeGen/coverage-profile-raw-version.c
  compiler-rt/lib/profile/InstrProfilingWriter.c
  compiler-rt/test/profile/Darwin/coverage-debug-info-correlate.cpp
  compiler-rt/test/profile/Linux/coverage-debug-info-correlate.cpp
  llvm/include/llvm/ProfileData/Coverage/CoverageMappingReader.h
  llvm/include/llvm/ProfileData/InstrProf.h
  llvm/include/llvm/ProfileData/InstrProfCorrelator.h
  llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
  llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
  llvm/lib/ProfileData/InstrProfCorrelator.cpp
  llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
  llvm/test/Instrumentation/InstrProfiling/debug-info-correlate-byte-coverage.ll
  
llvm/test/Instrumentation/InstrProfiling/debug-info-correlate-clang-coverage.ll
  llvm/test/Instrumentation/InstrProfiling/debug-info-correlate-coverage.ll

Index: llvm/test/Instrumentation/InstrProfiling/debug-info-correlate-clang-coverage.ll
===
--- /dev/null
+++ llvm/test/Instrumentation/InstrProfiling/debug-info-correlate-clang-coverage.ll
@@ -0,0 +1,66 @@
+; Test if unused function names are correctly emitted as dwarf variable debug info under DW_TAG_compile_unit
+
+; RUN: opt < %s -passes=instrprof -debug-info-correlate -S > %t.ll
+; RUN: FileCheck < %t.ll --implicit-check-not "{{__llvm_prf_data|__llvm_prf_names}}" %s
+; RUN: %llc_dwarf -O0 -filetype=obj < %t.ll | llvm-dwarfdump - | FileCheck %s --check-prefix=CHECK-DWARF
+
+; REQUIRES: system-linux, object-emission
+
+
+
+@__profn_foo = private constant [3 x i8] c"foo"
+@__profn_bar = private constant [3 x i8] c"bar"
+@__profn_baz = private constant [3 x i8] c"baz"
+@__llvm_coverage_names = internal constant [2 x ptr] [ptr @__profn_bar, ptr @__profn_baz]
+; CHECK: @__llvm_coverage_names = internal constant [2 x ptr] [ptr @__profn_bar, ptr @__profn_baz], !dbg ![[DBG:[0-9]+]]
+; CHECK: ![[DBG]] = !DIGlobalVariableExpression(var: ![[VAR:[0-9]+]], expr: !DIExpression())
+; CHECK: ![[VAR]] = {{.*}} !DIGlobalVariable(name: "__llvm_coverage_names"
+; CHECK-SAME: scope: ![[SCOPE:[0-9]+]]
+; CHECK-SAME: annotations: ![[ANNOTATIONS:[0-9]+]]
+; CHECK: ![[SCOPE]] = {{.*}} !DICompileUnit(
+; CHECK: ![[ANNOTATIONS]] = !{![[FUNC_NAME1:[0-9]+]], ![[FUNC_NAME2:[0-9]+]]}
+; CHECK: ![[FUNC_NAME1]] = !{!"Cov Function Name", !"bar"}
+; CHECK: ![[FUNC_NAME2]] = !{!"Cov Function Name", !"baz"}
+
+define void @_Z3foov() !dbg !12 {
+  call void @llvm.instrprof.increment(ptr @__profn_foo, i64 12345678, i32 2, i32 0)
+  ret void
+}
+
+declare void @llvm.instrprof.increment(ptr, i64, i32, i32)
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!2, !3, !4, !5, !6, !7, !8, !9, !10}
+!llvm.ident = !{!11}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 14.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
+!1 = !DIFile(filename: "debug-info-correlate.cpp", directory: "")
+!2 = !{i32 7, !"Dwarf Version", i32 4}
+!3 = !{i32 2, !"Debug Info Version", i32 3}
+!4 = !{i32 1, !"wchar_size", i32 4}
+!5 = !{i32 8, !"branch-target-enforcement", i32 0}
+!6 = !{i32 8, !"sign-return-address", i32 0}
+!7 = !{i32 8, !"sign-return-address-all", i32 0}
+!8 = !{i32 8, !"sign-return-address-with-bkey", i32 0}
+!9 = !{i32 7, !"uwtable", i32 1}
+!10 = !{i32 7, !"frame-pointer", i32 1}
+!11 = !{!"clang version 14.0.0"}
+!12 = distinct !DISubprogram(name: "foo", linkageName: "_Z3foov", scope: !13, file: !13, line: 1, type: !14, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !16)
+!13 = !DIFile(filename: "debug-info-correlate.cpp", directory: "")
+!14 = !DISubroutineType(types: !15)
+!15 = !{null}
+!16 = !{}
+
+; CHECK-DWARF: DW_TAG_compile_unit
+; CHECK-DWARF:   DW_TAG_variable
+; CHECK-DWARF: DW_AT_name	("__llvm_coverage_names")
+; CHECK-DWARF: DW_AT_type	({{.*}} "Coverage Type")
+; CHECK-DWARF: DW_TAG_LLVM_annotation
+; CHECK-DWARF:   DW_AT_name	("Cov Function Name")
+; CHECK-DWARF:   DW_AT_const_value	("bar")
+; CHECK-DWARF: DW_TAG_LLVM_annotation
+; CHECK-DWARF:   DW_AT_name	("Cov Function Name")
+; CHECK-DWARF:   DW_AT_const_value	("baz")
+; CHECK-DWARF:   DW_TAG_unspecified_type
+; CHECK-DWARF: DW_AT_name ("Coverage Type")
+; CHECK-DWARF:   NULL
Index: llvm/test/Instrumentation/InstrProfiling/debug-info-correlate-coverage.ll
===
--- /dev/null
+++ llvm/test/Instrumentation/InstrProfiling/debug-info-correlate-coverage.ll
@@ -1,34 +0,0 @@
-; RUN: opt < %s -passes=instrprof 

[clang] [NFC][CodeGen] Change CodeGenOpt::Level/CodeGenFileType into enum classes (PR #66295)

2023-09-14 Thread Reid Kleckner via cfe-commits

https://github.com/rnk approved this pull request.


https://github.com/llvm/llvm-project/pull/66295
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157913: [Coverage] Allow Clang coverage to be used with debug info correlation.

2023-09-14 Thread Ellis Hoag via Phabricator via cfe-commits
ellis added a comment.

It looks like `debug-info-correlate-coverage.ll` was renamed twice. Is this 
intended?




Comment at: compiler-rt/lib/profile/InstrProfilingWriter.c:276-277
   __llvm_profile_get_num_counters(CountersBegin, CountersEnd);
-  const uint64_t NamesSize = DebugInfoCorrelate ? 0 : NamesEnd - NamesBegin;
+  const uint64_t NamesSize =
+  DebugInfoCorrelate && IRLevelProfile ? 0 : NamesEnd - NamesBegin;
 

Can we remove changes to this file now that we are stripping the names section?



Comment at: llvm/lib/ProfileData/InstrProfCorrelator.cpp:423
+  }
+  return;
+}

I think this return should be on the line above to break out of the for loop 
early. Or did I miscount the brackets?



Comment at: llvm/lib/ProfileData/InstrProfReader.cpp:577-578
 // Correlator.
-assert(DataSize == 0 && NamesSize == 0);
-assert(CountersDelta == 0 && NamesDelta == 0);
+assert(DataSize == 0 && (!isIRLevelProfile() || NamesSize == 0));
+assert(CountersDelta == 0 && (!isIRLevelProfile() || NamesDelta == 0));
 Data = Correlator->getDataPointer();

I think these changes can also be removed



Comment at: llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp:769
   }
+  if (DebugInfoCorrelate && !ReferencedNames.empty()) {
+MDNode *Node = *M->debug_compile_units_begin();

Just so that I understand. Does this code run only for names of unused 
functions? Or will we store all function names with `CovFunctionNameAnnotation`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157913

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


[clang] [clang-format] Fix a bug in ContinuationIndenter (PR #66354)

2023-09-14 Thread Owen Pan via cfe-commits

https://github.com/owenca updated 
https://github.com/llvm/llvm-project/pull/66354:

>From 73669f7d04070feade2282384478e96b8bc6d727 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Thu, 14 Sep 2023 02:59:43 -0700
Subject: [PATCH] [clang-format] Fix a bug in ContinuationIndenter

See https://reviews.llvm.org/D136154#3890747 for context.

Fixes part of #58592.
---
 clang/lib/Format/ContinuationIndenter.cpp |  8 
 clang/unittests/Format/FormatTest.cpp | 23 +++
 2 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 75ab08de42ea0e8..65a7c1e26f57d06 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -876,15 +876,15 @@ void 
ContinuationIndenter::addTokenOnCurrentLine(LineState , bool DryRun,
  FormatStyle::BCIS_AfterColon) {
 CurrentState.Indent = State.Column;
 CurrentState.LastSpace = State.Column;
-  } else if ((Previous.isOneOf(TT_BinaryOperator, TT_ConditionalExpr,
-   TT_CtorInitializerColon)) &&
+  } else if (Previous.isOneOf(TT_ConditionalExpr, TT_CtorInitializerColon)) {
+CurrentState.LastSpace = State.Column;
+  } else if (Previous.is(TT_BinaryOperator) &&
  ((Previous.getPrecedence() != prec::Assignment &&
(Previous.isNot(tok::lessless) || Previous.OperatorIndex != 0 ||
 Previous.NextOperator)) ||
   Current.StartsBinaryExpression)) {
 // Indent relative to the RHS of the expression unless this is a simple
-// assignment without binary expression on the RHS. Also indent relative to
-// unary operators and the colons of constructor initializers.
+// assignment without binary expression on the RHS.
 if (Style.BreakBeforeBinaryOperators == FormatStyle::BOS_None)
   CurrentState.LastSpace = State.Column;
   } else if (Previous.is(TT_InheritanceColon)) {
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 4f72166bdce2d73..0d0fbdb84e3271b 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -7108,6 +7108,29 @@ TEST_F(FormatTest, 
ExpressionIndentationBreakingBeforeOperators) {
"(someOtherLongishConditionPart1 || "
"someOtherEvenLongerNestedConditionPart2);",
Style);
+
+  Style = getLLVMStyleWithColumns(20);
+  Style.AlignAfterOpenBracket = FormatStyle::BAS_AlwaysBreak;
+  Style.BinPackParameters = false;
+  Style.BreakBeforeBinaryOperators = FormatStyle::BOS_NonAssignment;
+  Style.ContinuationIndentWidth = 2;
+  verifyFormat("struct Foo {\n"
+   "  Foo(\n"
+   "int arg1,\n"
+   "int arg2)\n"
+   "  : Base(\n"
+   "  arg1,\n"
+   "  arg2) {}\n"
+   "};",
+   Style);
+  verifyFormat("return abc\n"
+   " ? foo(\n"
+   " a,\n"
+   " b,\n"
+   " bar(\n"
+   "   abc))\n"
+   " : g(abc);",
+   Style);
 }
 
 TEST_F(FormatTest, ExpressionIndentationStrictAlign) {

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


[clang] [HIP] Fix comdat of template kernel handle (PR #66283)

2023-09-14 Thread Yaxun Liu via cfe-commits

https://github.com/yxsamliu closed 
https://github.com/llvm/llvm-project/pull/66283
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] d7e1932 - [HIP] Fix comdat of template kernel handle (#66283)

2023-09-14 Thread via cfe-commits

Author: Yaxun (Sam) Liu
Date: 2023-09-14T15:56:02-04:00
New Revision: d7e1932f857986df039b222619623428dc4ffe30

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

LOG: [HIP] Fix comdat of template kernel handle (#66283)

Currently, clang emits LLVM IR that fails verifier for the following
code:

```
template
__global__ void foo(T x);

void bar() {
  foo<<<1, 1>>>(0);
}
```
This is due to clang putting the kernel handle for foo into comdat,
which is not allowed, since the kernel handle is a declaration.

The siutation is similar to calling a declaration-only template
function. The callee will be a declaration in LLVM IR and won't be put
into comdat. This is in contrast to calling a template function with
body, which will be put into comdat.

Fixes: SWDEV-419769

Added: 


Modified: 
clang/lib/CodeGen/CGCUDANV.cpp
clang/test/CodeGenCUDA/kernel-stub-name.cu

Removed: 




diff  --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp
index 08769c98dc298a0..0efe7e8db0183fe 100644
--- a/clang/lib/CodeGen/CGCUDANV.cpp
+++ b/clang/lib/CodeGen/CGCUDANV.cpp
@@ -1234,7 +1234,10 @@ llvm::GlobalValue 
*CGNVCUDARuntime::getKernelHandle(llvm::Function *F,
   Var->setAlignment(CGM.getPointerAlign().getAsAlign());
   Var->setDSOLocal(F->isDSOLocal());
   Var->setVisibility(F->getVisibility());
-  CGM.maybeSetTrivialComdat(*GD.getDecl(), *Var);
+  auto *FD = cast(GD.getDecl());
+  auto *FT = FD->getPrimaryTemplate();
+  if (!FT || FT->isThisDeclarationADefinition())
+CGM.maybeSetTrivialComdat(*FD, *Var);
   KernelHandles[F->getName()] = Var;
   KernelStubs[Var] = F;
   return Var;

diff  --git a/clang/test/CodeGenCUDA/kernel-stub-name.cu 
b/clang/test/CodeGenCUDA/kernel-stub-name.cu
index 9884046fcd0fd0c..23df7f5d721b569 100644
--- a/clang/test/CodeGenCUDA/kernel-stub-name.cu
+++ b/clang/test/CodeGenCUDA/kernel-stub-name.cu
@@ -26,12 +26,13 @@
 // GNU: @[[HNSKERN:_ZN2ns8nskernelEv]] = constant ptr 
@[[NSSTUB:_ZN2ns23__device_stub__nskernelEv]], align 8
 // GNU: @[[HTKERN:_Z10kernelfuncIiEvv]] = linkonce_odr constant ptr 
@[[TSTUB:_Z25__device_stub__kernelfuncIiEvv]], comdat, align 8
 // GNU: @[[HDKERN:_Z11kernel_declv]] = external constant ptr, align 8
+// GNU: @[[HTDKERN:_Z20template_kernel_declIiEvT_]] = external constant ptr, 
align 8
 
 // MSVC: @[[HCKERN:ckernel]] = dso_local constant ptr 
@[[CSTUB:__device_stub__ckernel]], align 8
 // MSVC: @[[HNSKERN:"\?nskernel@ns@@YAXXZ.*"]] = dso_local constant ptr 
@[[NSSTUB:"\?__device_stub__nskernel@ns@@YAXXZ"]], align 8
 // MSVC: @[[HTKERN:"\?\?\$kernelfunc@H@@YAXXZ.*"]] = linkonce_odr dso_local 
constant ptr @[[TSTUB:"\?\?\$__device_stub__kernelfunc@H@@YAXXZ.*"]], comdat, 
align 8
 // MSVC: @[[HDKERN:"\?kernel_decl@@YAXXZ.*"]] = external dso_local constant 
ptr, align 8
-
+// MSVC: @[[HTDKERN:"\?\?\$template_kernel_decl@H@@YAXH.*"]] = external 
dso_local constant ptr, align 8
 extern "C" __global__ void ckernel() {}
 
 namespace ns {
@@ -43,6 +44,9 @@ __global__ void kernelfunc() {}
 
 __global__ void kernel_decl();
 
+template
+__global__ void template_kernel_decl(T x);
+
 extern "C" void (*kernel_ptr)();
 extern "C" void *void_ptr;
 
@@ -69,13 +73,16 @@ extern "C" void launch(void *kern);
 // CHECK: call void @[[NSSTUB]]()
 // CHECK: call void @[[TSTUB]]()
 // GNU: call void @[[DSTUB:_Z26__device_stub__kernel_declv]]()
+// GNU: call void @[[TDSTUB:_Z35__device_stub__template_kernel_declIiEvT_]](
 // MSVC: call void @[[DSTUB:"\?__device_stub__kernel_decl@@YAXXZ"]]()
+// MSVC: call void 
@[[TDSTUB:"\?\?\$__device_stub__template_kernel_decl@H@@YAXH@Z"]](
 
 extern "C" void fun1(void) {
   ckernel<<<1, 1>>>();
   ns::nskernel<<<1, 1>>>();
   kernelfunc<<<1, 1>>>();
   kernel_decl<<<1, 1>>>();
+  template_kernel_decl<<<1, 1>>>(1);
 }
 
 // Template kernel stub functions
@@ -86,6 +93,7 @@ extern "C" void fun1(void) {
 // Check declaration of stub function for external kernel.
 
 // CHECK: declare{{.*}}@[[DSTUB]]
+// CHECK: declare{{.*}}@[[TDSTUB]]
 
 // Check kernel handle is used for passing the kernel as a function pointer.
 
@@ -94,11 +102,13 @@ extern "C" void fun1(void) {
 // CHECK: call void @launch({{.*}}[[HNSKERN]]
 // CHECK: call void @launch({{.*}}[[HTKERN]]
 // CHECK: call void @launch({{.*}}[[HDKERN]]
+// CHECK: call void @launch({{.*}}[[HTDKERN]]
 extern "C" void fun2() {
   launch((void *)ckernel);
   launch((void *)ns::nskernel);
   launch((void *)kernelfunc);
   launch((void *)kernel_decl);
+  launch((void *)template_kernel_decl);
 }
 
 // Check kernel handle is used for assigning a kernel to a function pointer.
@@ -148,3 +158,4 @@ extern "C" void fun5() {
 // CHECK: call{{.*}}@__hipRegisterFunction{{.*}}@[[HTKERN]]{{.*}}@[[TKERN]]
 // NEG-NOT: call{{.*}}@__hipRegisterFunction{{.*}}__device_stub
 // NEG-NOT: 

[clang] [clang][CodeGen] Use byval for SystemZ indirect arguments (PR #66404)

2023-09-14 Thread Eli Friedman via cfe-commits

efriedma-quic wrote:

byval changes the calling convention: instead of passing a pointer, it copies 
the pointed-to value into the argument list.

It's not clear to me why msan cares about whether a pointer is an implicit or 
explicit value... but if it does, we'd want to use an attribute that doesn't 
have an existing ABI impact.

https://github.com/llvm/llvm-project/pull/66404
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] TaintPropagation checker strlen() should not propagate (PR #66086)

2023-09-14 Thread Balazs Benics via cfe-commits

steakhal wrote:

Request another round of review once you are happy with the content and 
addressed the open comments.
On the grand scheme we are aligned.

https://github.com/llvm/llvm-project/pull/66086
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Update GoogleTest to v1.14.0 (PR #65823)

2023-09-14 Thread Björn Pettersson via cfe-commits

bjope wrote:

> > Ok, seems like the only problem is the MemProf unit test 
> > compiler-rt/lib/memprof/tests/
> > So if I manually disable that I don't see any other failures with this 
> > patch.
> 
> I think any components that uses freshly built clang (stage1) could 
> potentially run into this problem again, the correct way to solve it is to 
> provide a compatible C++ Library to the freshly built clang when it built 
> compiler-rt and related tests. For example, use -D with 
> `RUNTIMES_${target}_CMAKE_CXX_FLAGS` and `RUNTIMES_${target}_CMAKE_CXX_FLAGS` 
> to pass `--gcc-toolchain` (it might be deprecated and there is an updated 
> flag for it) to the runtimes build. This will probably allow stage1 clang to 
> use gcc's stdlib like your bootstrap clang.

Thanks! Yes, I think we hadn't considered that some things we set up for the 
regular build wasn't forwarded to the compiler-rt test.
When setting
  
`-DRUNTIMES_${target}_COMPILER_RT_TEST_COMPILER_CFLAGS=--gcc-toolchain=`
the problem @mikaelholmen mentioned disappeared. I haven't tried adding it to 
CMAKE_CXX_FLAGS, but maybe that is a better option.

https://github.com/llvm/llvm-project/pull/65823
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [DependencyScanningFilesystem] Make sure the local/shared cache filename lookups use only absolute paths (PR #66122)

2023-09-14 Thread Jan Svoboda via cfe-commits


@@ -330,3 +353,20 @@ DependencyScanningWorkerFilesystem::openFileForRead(const 
Twine ) {
 return Result.getError();
   return DepScanFile::create(Result.get());
 }
+
+std::error_code DependencyScanningWorkerFilesystem::setCurrentWorkingDirectory(
+const Twine ) {
+  updateWorkingDirForCacheLookup(Path.str());
+  return ProxyFileSystem::setCurrentWorkingDirectory(Path);
+}
+
+void DependencyScanningWorkerFilesystem::updateWorkingDirForCacheLookup(
+llvm::ErrorOr CWD) {
+  if (CWD && !CWD->empty()) {
+WorkingDirForCacheLookup = *CWD;
+  } else {
+// The cache lookup functions will not accept relative paths for safety, so
+// at least make it absolute from a "root".
+WorkingDirForCacheLookup = "/";

jansvoboda11 wrote:

I would prefer if we avoided inventing a dummy value.

What do you think about enforcing that `DependencyScanningWorkerFilesystem` 
never gets constructed from a VFS that either does not have a working 
directory, or has one that's relative? We could do that by creating a factory 
function that returns `llvm::Expected` 
instead of using the constructor.

For the `setCurrentWorkingDirectory()` call, I think it'd be reasonable to 
clear our CWD if the new one is empty or relative, return an error code and 
assume the VFS doesn't get used in that state. If it does, hitting one of the 
"is file path absolute" assertions is fair game.

https://github.com/llvm/llvm-project/pull/66122
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [dataflow] Parse formulas from text (PR #66424)

2023-09-14 Thread Sam McCall via cfe-commits

sam-mccall wrote:

Not sure if this is really important to have checked in, but I've wanted to 
investigate/reproduce flow condition slowness a few times now, so thought I 
should send the patch in case others think it's useful.

https://github.com/llvm/llvm-project/pull/66424
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [dataflow] Parse formulas from text (PR #66424)

2023-09-14 Thread Sam McCall via cfe-commits

https://github.com/sam-mccall review_requested 
https://github.com/llvm/llvm-project/pull/66424
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [dataflow] Parse formulas from text (PR #66424)

2023-09-14 Thread Sam McCall via cfe-commits

https://github.com/sam-mccall review_requested 
https://github.com/llvm/llvm-project/pull/66424
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [dataflow] Parse formulas from text (PR #66424)

2023-09-14 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-analysis


Changes
My immediate use for this is not in checked-in code, but rather the
ability to plug printed flow conditions (from analysis logs) back into
sat solver unittests to reproduce slowness.

It does allow simplifying some of the existing solver tests, though.

--
Full diff: https://github.com/llvm/llvm-project/pull/66424.diff

6 Files Affected:

- (modified) clang/include/clang/Analysis/FlowSensitive/Arena.h (+5) 
- (modified) clang/include/clang/Analysis/FlowSensitive/Formula.h (+3) 
- (modified) clang/lib/Analysis/FlowSensitive/Arena.cpp (+93) 
- (modified) clang/lib/Analysis/FlowSensitive/Formula.cpp (+1) 
- (modified) clang/unittests/Analysis/FlowSensitive/ArenaTest.cpp (+44) 
- (modified) clang/unittests/Analysis/FlowSensitive/SolverTest.cpp (+64-89) 



diff --git a/clang/include/clang/Analysis/FlowSensitive/Arena.h 
b/clang/include/clang/Analysis/FlowSensitive/Arena.h
index 373697dc7379c53..4e07053aae1af53 100644
--- a/clang/include/clang/Analysis/FlowSensitive/Arena.h
+++ b/clang/include/clang/Analysis/FlowSensitive/Arena.h
@@ -11,6 +11,7 @@
 #include quot;clang/Analysis/FlowSensitive/Formula.hquot;
 #include quot;clang/Analysis/FlowSensitive/StorageLocation.hquot;
 #include quot;clang/Analysis/FlowSensitive/Value.hquot;
+#include quot;llvm/ADT/StringRef.hquot;
 #include lt;vectorgt;
 
 namespace clang::dataflow {
@@ -109,6 +110,10 @@ class Arena {
 return makeAtomRef(Value ? True : False);
   }
 
+  // Parses a formula from its textual representation.
+  // This may refer to atoms that were not produced by makeAtom() yet!
+  llvm::Expectedlt;const Formula amp;gt; 
parseFormula(llvm::StringRef);
+
   /// Returns a new atomic boolean variable, distinct from any other.
   Atom makeAtom() { return static_castlt;Atomgt;(NextAtom++); };
 
diff --git a/clang/include/clang/Analysis/FlowSensitive/Formula.h 
b/clang/include/clang/Analysis/FlowSensitive/Formula.h
index 64fe8f5b630a0f7..ac95a9ac7d50a1c 100644
--- a/clang/include/clang/Analysis/FlowSensitive/Formula.h
+++ b/clang/include/clang/Analysis/FlowSensitive/Formula.h
@@ -87,6 +87,9 @@ class alignas(const Formula *) Formula {
  ArrayReflt;const Formula *gt; Operands,
  unsigned Value = 0);
 
+  // Parse Formulas using Arena rather than caling this function directly.
+  static Formula *parse(llvm::BumpPtrAllocator amp;Alloc, llvm::StringRef 
amp;);
+
 private:
   Formula() = default;
   Formula(const Formula amp;) = delete;
diff --git a/clang/lib/Analysis/FlowSensitive/Arena.cpp 
b/clang/lib/Analysis/FlowSensitive/Arena.cpp
index a12da2d9b555eb7..557feb373287632 100644
--- a/clang/lib/Analysis/FlowSensitive/Arena.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Arena.cpp
@@ -7,7 +7,10 @@
 
//===--===//
 
 #include quot;clang/Analysis/FlowSensitive/Arena.hquot;
+#include quot;clang/Analysis/FlowSensitive/Formula.hquot;
 #include quot;clang/Analysis/FlowSensitive/Value.hquot;
+#include quot;llvm/Support/Error.hquot;
+#include lt;stringgt;
 
 namespace clang::dataflow {
 
@@ -95,4 +98,94 @@ BoolValue amp;Arena::makeBoolValue(const Formula 
amp;F) {
   return *It-gt;second;
 }
 
+namespace {
+const Formula *parse(Arena amp;A, llvm::StringRef amp;In) {
+  auto EatWhitespace = [amp;] { In = In.ltrim(#x27; #x27;); };
+  EatWhitespace();
+
+  if (In.consume_front(quot;!quot;)) {
+if (auto *Arg = parse(A, In))
+  return amp;A.makeNot(*Arg);
+return nullptr;
+  }
+
+  if (In.consume_front(quot;(quot;)) {
+auto *Arg1 = parse(A, In);
+if (!Arg1)
+  return nullptr;
+
+EatWhitespace();
+decltype(amp;Arena::makeOr) Op;
+if (In.consume_front(quot;|quot;))
+  Op = amp;Arena::makeOr;
+else if (In.consume_front(quot;amp;quot;))
+  Op = amp;Arena::makeAnd;
+else if (In.consume_front(quot;=gt;quot;))
+  Op = amp;Arena::makeImplies;
+else if (In.consume_front(quot;=quot;))
+  Op = amp;Arena::makeEquals;
+else
+  return nullptr;
+
+auto *Arg2 = parse(A, In);
+if (!Arg2)
+  return nullptr;
+
+EatWhitespace();
+if (!In.consume_front(quot;)quot;))
+  return nullptr;
+
+return amp;(A.*Op)(*Arg1, *Arg2);
+  }
+
+  if (In.consume_front(quot;Vquot;)) {
+std::underlying_type_tlt;Atomgt; At;
+if (In.consumeInteger(10, At))
+  return nullptr;
+return amp;A.makeAtomRef(static_castlt;Atomgt;(At));
+  }
+
+  if (In.consume_front(quot;truequot;))
+return amp;A.makeLiteral(true);
+  if (In.consume_front(quot;falsequot;))
+return amp;A.makeLiteral(false);
+
+  return nullptr;
+}
+
+class FormulaParseError : public 
llvm::ErrorInfolt;FormulaParseErrorgt; {
+  unsigned Offset;
+  std::string Formula;
+
+public:
+  static char ID;
+  FormulaParseError(llvm::StringRef Formula, unsigned Offset)
+  : Offset(Offset), Formula(Formula) {}
+
+  void log(raw_ostream amp;OS) const override {
+   

[clang] [dataflow] Parse formulas from text (PR #66424)

2023-09-14 Thread via cfe-commits

https://github.com/llvmbot labeled 
https://github.com/llvm/llvm-project/pull/66424
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   3   4   >