[clang-tools-extra] [clangd] Introduce reusable modules builder (PR #73483)

2023-11-26 Thread Chuanqi Xu via cfe-commits

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


[flang] [llvm] [libcxx] [libc] [clang] [compiler-rt] [Clang] Use correct base expression for counted_by field (#73168) (PR #73465)

2023-11-26 Thread Bill Wendling via cfe-commits

https://github.com/bwendling updated 
https://github.com/llvm/llvm-project/pull/73465

>From 3aa35a39184ff8d4ff11b9f41b4551bec78bdca5 Mon Sep 17 00:00:00 2001
From: Bill Wendling 
Date: Wed, 22 Nov 2023 15:16:19 -0800
Subject: [PATCH 1/2] [Clang] Use correct base expression for counted_by field

The base expression of the counted_by field may not be the outermost
enclosing struct, but could be a sub-struct. Use the latter in those
cases.

Closes #73168
---
 clang/lib/CodeGen/CGBuiltin.cpp  |   4 +-
 clang/lib/CodeGen/CGExpr.cpp |  52 ++---
 clang/lib/CodeGen/CodeGenFunction.h  |   3 +-
 clang/test/CodeGen/attr-counted-by.c | 164 +--
 4 files changed, 120 insertions(+), 103 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 710e4c162103b41..43bf1218b70d781 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -916,7 +916,7 @@ CodeGenFunction::emitFlexibleArrayMemberSize(const Expr *E, 
unsigned Type,
 
   // Build a load of the counted_by field.
   bool IsSigned = CountedByFD->getType()->isSignedIntegerType();
-  const Expr *CountedByExpr = BuildCountedByFieldExpr(Base, CountedByFD);
+  Expr *CountedByExpr = BuildCountedByFieldExpr(Base, CountedByFD);
   Value *CountedByInst = EmitAnyExprToTemp(CountedByExpr).getScalarVal();
   llvm::Type *CountedByTy = CountedByInst->getType();
 
@@ -945,7 +945,7 @@ CodeGenFunction::emitFlexibleArrayMemberSize(const Expr *E, 
unsigned Type,
  : Builder.CreateZExtOrTrunc(FAMSize, ResType);
   Value *Res = FAMSize;
 
-  if (const auto *DRE = dyn_cast(Base)) {
+  if (isa(Base)) {
 // The whole struct is specificed in the __bdos.
 const RecordDecl *OuterRD =
 CountedByFD->getDeclContext()->getOuterLexicalRecordContext();
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index a75f630e1a4c767..60dc5d68a223dd8 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -940,7 +940,7 @@ static llvm::Value *getArrayIndexingBound(CodeGenFunction 
,
 
 if (const ValueDecl *VD = CGF.FindCountedByField(Base)) {
   IndexedType = Base->getType();
-  const Expr *E = CGF.BuildCountedByFieldExpr(Base, VD);
+  Expr *E = CGF.BuildCountedByFieldExpr(Base, VD);
   return CGF.EmitAnyExprToTemp(E).getScalarVal();
 }
   }
@@ -956,21 +956,41 @@ static llvm::Value *getArrayIndexingBound(CodeGenFunction 
,
   return nullptr;
 }
 
-const Expr *
-CodeGenFunction::BuildCountedByFieldExpr(const Expr *Base,
- const ValueDecl *CountedByVD) {
+Expr *CodeGenFunction::BuildCountedByFieldExpr(const Expr *Base,
+   const ValueDecl *CountedByVD) {
   // Find the outer struct expr (i.e. p in p->a.b.c.d).
   Expr *CountedByExpr = const_cast(Base)->IgnoreParenImpCasts();
 
+  // Get the enclosing struct, but not the outermost enclosing struct.
+  const DeclContext *DC = CountedByVD->getLexicalDeclContext();
+  const RecordDecl *CountedByRD = dyn_cast(DC);
+  if (!CountedByRD)
+return nullptr;
+
   // Work our way up the expression until we reach the DeclRefExpr.
-  while (!isa(CountedByExpr))
-if (const auto *ME = dyn_cast(CountedByExpr))
-  CountedByExpr = ME->getBase()->IgnoreParenImpCasts();
+  while (auto *ME = dyn_cast(CountedByExpr)) {
+CountedByExpr = ME->getBase()->IgnoreImpCasts();
+
+// Use the base of an ArraySubscriptExpr.
+while (auto *ASE = dyn_cast(CountedByExpr))
+  CountedByExpr = ASE->getBase()->IgnoreImpCasts();
+
+QualType Ty = CountedByExpr->getType();
+if (Ty->isPointerType())
+  Ty = Ty->getPointeeType();
+
+// Stop when we reach the struct containing the counted_by field.
+if (CountedByRD == Ty->getAsRecordDecl())
+  break;
+  }
+
+  ASTContext  = getContext();
 
-  // Add back an implicit cast to create the required pr-value.
-  CountedByExpr = ImplicitCastExpr::Create(
-  getContext(), CountedByExpr->getType(), CK_LValueToRValue, CountedByExpr,
-  nullptr, VK_PRValue, FPOptionsOverride());
+  if (!CountedByExpr->isPRValue())
+// Add an implicit cast to create the required pr-value.
+CountedByExpr = ImplicitCastExpr::Create(
+Ctx, CountedByExpr->getType(), CK_LValueToRValue, CountedByExpr,
+nullptr, VK_PRValue, FPOptionsOverride());
 
   if (const auto *IFD = dyn_cast(CountedByVD)) {
 // The counted_by field is inside an anonymous struct / union. The
@@ -978,15 +998,13 @@ CodeGenFunction::BuildCountedByFieldExpr(const Expr *Base,
 // easily. (Yay!)
 for (NamedDecl *ND : IFD->chain()) {
   auto *VD = cast(ND);
-  CountedByExpr =
-  MemberExpr::CreateImplicit(getContext(), CountedByExpr,
- CountedByExpr->getType()->isPointerType(),
- VD, VD->getType(), VK_LValue, 
OK_Ordinary);
+  CountedByExpr = 

[clang] [clang][dataflow] Strengthen widening of boolean values. (PR #73484)

2023-11-26 Thread Gábor Horváth via cfe-commits

https://github.com/Xazax-hun approved this pull request.


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


[flang] [clang] [flang] Add MSC_VER and target arch defines when targeting the MSVC ABI (PR #73250)

2023-11-26 Thread مهدي شينون via cfe-commits


@@ -204,6 +204,29 @@ void Flang::AddAArch64TargetArgs(const ArgList ,
   }
 }
 
+static void addVSDefines(const ToolChain , const ArgList ,
+ ArgStringList ) {
+
+  unsigned ver = 0;
+  const VersionTuple vt = TC.computeMSVCVersion(nullptr, Args);
+  ver = vt.getMajor() * 1000 + vt.getMinor().value_or(0) * 10 +
+vt.getSubminor().value_or(0);
+  CmdArgs.push_back(Args.MakeArgString("-D_MSC_VER=" + Twine(ver / 10)));
+  CmdArgs.push_back(Args.MakeArgString("-D_MSC_FULL_VER=" + Twine(ver)));
+
+  llvm::Triple triple = TC.getTriple();
+  if (triple.isAArch64()) {
+CmdArgs.push_back("-D_M_ARM64=1");
+  } else if (triple.isX86() && triple.isArch32Bit()) {
+CmdArgs.push_back("-D_M_IX86=600");
+  } else if (triple.isX86() && triple.isArch64Bit()) {
+CmdArgs.push_back("-D_M_X64=100");
+  } else {
+llvm_unreachable(
+"Flang on Windows only supports X86_32, X86_64 and AArch64");
+  }

MehdiChinoune wrote:

Flang doesn't support 32bit 
https://github.com/llvm/llvm-project/blob/659e4017b7371efa8ce97da2d87270c60a93d03d/flang/CMakeLists.txt#L60

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


[llvm] [clang] [InstCombine] Set disjoint flag when turning Add into Or. (PR #72702)

2023-11-26 Thread Nicolai Hähnle via cfe-commits

nhaehnle wrote:

Time to rebase this on main, I think...

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


[clang] 659e401 - [clang-format][NFC] Improve an `if` conditional in the annotator

2023-11-26 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2023-11-26T22:54:44-08:00
New Revision: 659e4017b7371efa8ce97da2d87270c60a93d03d

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

LOG: [clang-format][NFC] Improve an `if` conditional in the annotator

Added: 


Modified: 
clang/lib/Format/TokenAnnotator.cpp

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index cfca7c00312aab3..6ae83de40113126 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2391,9 +2391,8 @@ class AnnotatingParser {
   return true;
 
 // If a (non-string) literal follows, this is likely a cast.
-if (Tok.Next->isNot(tok::string_literal) &&
-(Tok.Next->Tok.isLiteral() ||
- Tok.Next->isOneOf(tok::kw_sizeof, tok::kw_alignof))) {
+if (Tok.Next->isOneOf(tok::kw_sizeof, tok::kw_alignof) ||
+(Tok.Next->Tok.isLiteral() && Tok.Next->isNot(tok::string_literal))) {
   return true;
 }
 



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


[clang] [clang][dataflow] Strengthen widening of boolean values. (PR #73484)

2023-11-26 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (martinboehme)


Changes

Before we widen to top, we now check if both values can be proved either true or
false in their respective environments; if so, widening returns a true or false
literal. The idea is that we avoid losing information if posssible.

This patch includes a test that fails without this change to widening.

This change does mean that we call the SAT solver in more places, but this seems
acceptable given the additional precision we gain.

In tests on an internal codebase, the number of SAT solver timeouts we observe
with Crubit's nullability checker does increase by about 25%. They can be
brought back to the previous level by doubling the SAT solver work limit.


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


2 Files Affected:

- (modified) clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp (+17-4) 
- (modified) clang/unittests/Analysis/FlowSensitive/TransferTest.cpp (+28) 


``diff
diff --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index 1a38be9c1374f65..525ab188b01b8aa 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -157,12 +157,25 @@ static Value (QualType Type, Value 
,
   Environment ,
   Environment::ValueModel ) {
   // Boolean-model widening.
-  if (isa()) {
-assert(isa(Current));
-// Widen to Top, because we know they are different values. If previous was
-// already Top, re-use that to (implicitly) indicate that no change 
occured.
+  if (auto *PrevBool = dyn_cast()) {
+// If previous value was already Top, re-use that to (implicitly) indicate
+// that no change occurred.
 if (isa(Prev))
   return Prev;
+
+// We may need to widen to Top, but before we do so, check whether both
+// values are implied to be either true or false in the current 
environment.
+// In that case, we can simply return a literal instead.
+auto  = cast(Current);
+bool TruePrev = PrevEnv.proves(PrevBool->formula());
+bool TrueCur = CurrentEnv.proves(CurBool.formula());
+if (TruePrev && TrueCur)
+  return CurrentEnv.getBoolLiteralValue(true);
+if (!TruePrev && !TrueCur &&
+PrevEnv.proves(PrevEnv.arena().makeNot(PrevBool->formula())) &&
+CurrentEnv.proves(CurrentEnv.arena().makeNot(CurBool.formula(
+  return CurrentEnv.getBoolLiteralValue(false);
+
 return CurrentEnv.makeTopBoolValue();
   }
 
diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index ade0d202ced2f37..8da55953a329869 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -4167,6 +4167,34 @@ TEST(TransferTest, 
LoopWithShortCircuitedConditionConverges) {
   ASSERT_THAT_ERROR(checkDataflowWithNoopAnalysis(Code), llvm::Succeeded());
 }
 
+TEST(TransferTest, LoopCanProveInvariantForBoolean) {
+  // Check that we can prove `b` is always false in the loop.
+  // This test exercises the logic in `widenDistinctValues()` that preserves
+  // information if the boolean can be proved to be either true or false in 
both
+  // the previous and current iteration.
+  std::string Code = R"cc(
+int return_int();
+void target() {
+  bool b = return_int() == 0;
+  if (b) return;
+  while (true) {
+b;
+// [[p]]
+b = return_int() == 0;
+if (b) return;
+  }
+}
+  )cc";
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> ,
+ ASTContext ) {
+const Environment  = getEnvironmentAtAnnotation(Results, "p");
+auto  = getValueForDecl(ASTCtx, Env, "b");
+EXPECT_TRUE(Env.proves(Env.arena().makeNot(BVal.formula(;
+  });
+}
+
 TEST(TransferTest, DoesNotCrashOnUnionThisExpr) {
   std::string Code = R"(
 union Union {

``




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


[clang] [clang][dataflow] Strengthen widening of boolean values. (PR #73484)

2023-11-26 Thread via cfe-commits

https://github.com/martinboehme created 
https://github.com/llvm/llvm-project/pull/73484

Before we widen to top, we now check if both values can be proved either true or
false in their respective environments; if so, widening returns a true or false
literal. The idea is that we avoid losing information if posssible.

This patch includes a test that fails without this change to widening.

This change does mean that we call the SAT solver in more places, but this seems
acceptable given the additional precision we gain.

In tests on an internal codebase, the number of SAT solver timeouts we observe
with Crubit's nullability checker does increase by about 25%. They can be
brought back to the previous level by doubling the SAT solver work limit.


>From 85a807a81251f4609087f37e62ded03274df0736 Mon Sep 17 00:00:00 2001
From: Martin Braenne 
Date: Mon, 27 Nov 2023 06:31:46 +
Subject: [PATCH] [clang][dataflow] Strengthen widening of boolean values.

Before we widen to top, we now check if both values can be proved either true or
false in their respective environments; if so, widening returns a true or false
literal. The idea is that we avoid losing information if posssible.

This patch includes a test that fails without this change to widening.

This change does mean that we call the SAT solver in more places, but this seems
acceptable given the additional precision we gain.

In tests on an internal codebase, the number of SAT solver timeouts we observe
with Crubit's nullability checker does increase by about 25%. They can be
brought back to the previous level by doubling the SAT solver work limit.
---
 .../FlowSensitive/DataflowEnvironment.cpp | 21 +++---
 .../Analysis/FlowSensitive/TransferTest.cpp   | 28 +++
 2 files changed, 45 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index 1a38be9c1374f65..525ab188b01b8aa 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -157,12 +157,25 @@ static Value (QualType Type, Value 
,
   Environment ,
   Environment::ValueModel ) {
   // Boolean-model widening.
-  if (isa()) {
-assert(isa(Current));
-// Widen to Top, because we know they are different values. If previous was
-// already Top, re-use that to (implicitly) indicate that no change 
occured.
+  if (auto *PrevBool = dyn_cast()) {
+// If previous value was already Top, re-use that to (implicitly) indicate
+// that no change occurred.
 if (isa(Prev))
   return Prev;
+
+// We may need to widen to Top, but before we do so, check whether both
+// values are implied to be either true or false in the current 
environment.
+// In that case, we can simply return a literal instead.
+auto  = cast(Current);
+bool TruePrev = PrevEnv.proves(PrevBool->formula());
+bool TrueCur = CurrentEnv.proves(CurBool.formula());
+if (TruePrev && TrueCur)
+  return CurrentEnv.getBoolLiteralValue(true);
+if (!TruePrev && !TrueCur &&
+PrevEnv.proves(PrevEnv.arena().makeNot(PrevBool->formula())) &&
+CurrentEnv.proves(CurrentEnv.arena().makeNot(CurBool.formula(
+  return CurrentEnv.getBoolLiteralValue(false);
+
 return CurrentEnv.makeTopBoolValue();
   }
 
diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index ade0d202ced2f37..8da55953a329869 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -4167,6 +4167,34 @@ TEST(TransferTest, 
LoopWithShortCircuitedConditionConverges) {
   ASSERT_THAT_ERROR(checkDataflowWithNoopAnalysis(Code), llvm::Succeeded());
 }
 
+TEST(TransferTest, LoopCanProveInvariantForBoolean) {
+  // Check that we can prove `b` is always false in the loop.
+  // This test exercises the logic in `widenDistinctValues()` that preserves
+  // information if the boolean can be proved to be either true or false in 
both
+  // the previous and current iteration.
+  std::string Code = R"cc(
+int return_int();
+void target() {
+  bool b = return_int() == 0;
+  if (b) return;
+  while (true) {
+b;
+// [[p]]
+b = return_int() == 0;
+if (b) return;
+  }
+}
+  )cc";
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> ,
+ ASTContext ) {
+const Environment  = getEnvironmentAtAnnotation(Results, "p");
+auto  = getValueForDecl(ASTCtx, Env, "b");
+EXPECT_TRUE(Env.proves(Env.arena().makeNot(BVal.formula(;
+  });
+}
+
 TEST(TransferTest, DoesNotCrashOnUnionThisExpr) {
   std::string Code = R"(
 union Union {

___
cfe-commits mailing list

[clang] [Driver][MachineOutliner] Support -moutline option for aarch64_be (PR #73223)

2023-11-26 Thread dong jianqiang via cfe-commits

https://github.com/dongjianqiang2 updated 
https://github.com/llvm/llvm-project/pull/73223

>From b58489a05f97dcb6cf31ce9527ff0e7a16a9f56e Mon Sep 17 00:00:00 2001
From: dong jianqiang 
Date: Thu, 23 Nov 2023 16:58:11 +0800
Subject: [PATCH] [Driver][MachineOutliner] Support outlining option with LTO
 for aarch64_be

This patch propagates the -moutline option when target is aarch64_be,
fix warning: 'aarch64_be' does not support '-moutline'; flag ignored 
[-Woption-ignored]
---
 clang/lib/Driver/ToolChains/CommonArgs.cpp | 3 ++-
 clang/test/Driver/aarch64-outliner.c   | 2 ++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 1f31c6395206ee8..fb92a6dfbc0e26d 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -2400,7 +2400,8 @@ void tools::addMachineOutlinerArgs(const Driver ,
   // Otherwise, add the proper mllvm flags.
   if (!(Triple.isARM() || Triple.isThumb() ||
 Triple.getArch() == llvm::Triple::aarch64 ||
-Triple.getArch() == llvm::Triple::aarch64_32)) {
+Triple.getArch() == llvm::Triple::aarch64_32 ||
+Triple.getArch() == llvm::Triple::aarch64_be)) {
 D.Diag(diag::warn_drv_moutline_unsupported_opt) << 
Triple.getArchName();
   } else {
 addArg(Twine("-enable-machine-outliner"));
diff --git a/clang/test/Driver/aarch64-outliner.c 
b/clang/test/Driver/aarch64-outliner.c
index 42e43b433e282d3..06e5de11ec49ecd 100644
--- a/clang/test/Driver/aarch64-outliner.c
+++ b/clang/test/Driver/aarch64-outliner.c
@@ -1,7 +1,9 @@
 // REQUIRES: aarch64-registered-target
 // RUN: %clang --target=aarch64 -moutline -S %s -### 2>&1 | FileCheck %s 
-check-prefix=ON
+// RUN: %clang --target=aarch64_be -moutline -S %s -### 2>&1 | FileCheck %s 
-check-prefix=ON
 // ON: "-mllvm" "-enable-machine-outliner"
 // RUN: %clang --target=aarch64 -moutline -mno-outline -S %s -### 2>&1 | 
FileCheck %s -check-prefix=OFF
+// RUN: %clang --target=aarch64_be -moutline -mno-outline -S %s -### 2>&1 | 
FileCheck %s -check-prefix=OFF
 // OFF: "-mllvm" "-enable-machine-outliner=never"
 // RUN: %clang --target=x86_64 -moutline -S %s -### 2>&1 | FileCheck %s 
-check-prefix=WARN
 // WARN: warning: 'x86_64' does not support '-moutline'; flag ignored 
[-Woption-ignored]

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


[clang-tools-extra] [clangd] Introduce reusable modules builder (PR #73483)

2023-11-26 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff e89324219acf3d799a86fed5651e492bbab4867c 
052e2da0ede8cc72e22ad9ba75ddf2868e5fffe1 -- 
clang-tools-extra/clangd/ModuleDependencyScanner.cpp 
clang-tools-extra/clangd/ModuleDependencyScanner.h 
clang-tools-extra/clangd/ModulesBuilder.cpp 
clang-tools-extra/clangd/ModulesBuilder.h 
clang-tools-extra/clangd/PrerequisiteModules.h 
clang-tools-extra/clangd/ProjectModules.cpp 
clang-tools-extra/clangd/ProjectModules.h 
clang-tools-extra/clangd/unittests/ModuleDependencyScannerTest.cpp 
clang-tools-extra/clangd/unittests/ModulesTestSetup.h 
clang-tools-extra/clangd/unittests/PrerequisiteModulesTest.cpp 
clang-tools-extra/clangd/ClangdServer.cpp 
clang-tools-extra/clangd/ClangdServer.h 
clang-tools-extra/clangd/GlobalCompilationDatabase.cpp 
clang-tools-extra/clangd/GlobalCompilationDatabase.h 
clang-tools-extra/clangd/ParsedAST.cpp clang-tools-extra/clangd/Preamble.cpp 
clang-tools-extra/clangd/Preamble.h clang-tools-extra/clangd/TUScheduler.cpp 
clang-tools-extra/clangd/TUScheduler.h clang-tools-extra/clangd/tool/Check.cpp 
clang-tools-extra/clangd/tool/ClangdMain.cpp 
clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp 
clang-tools-extra/clangd/unittests/FileIndexTests.cpp 
clang-tools-extra/clangd/unittests/ParsedASTTests.cpp 
clang-tools-extra/clangd/unittests/PreambleTests.cpp 
clang-tools-extra/clangd/unittests/TestTU.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang-tools-extra/clangd/ModulesBuilder.cpp 
b/clang-tools-extra/clangd/ModulesBuilder.cpp
index c3a2ba89e9..b7c71bb31e 100644
--- a/clang-tools-extra/clangd/ModulesBuilder.cpp
+++ b/clang-tools-extra/clangd/ModulesBuilder.cpp
@@ -100,9 +100,9 @@ struct ModuleFile {
   ModuleFile(ModuleFile &)
   : ModuleName(std::move(Other.ModuleName)),
 ModuleFilePath(std::move(Other.ModuleFilePath)) {
-  Other.ModuleName.clear();
-  Other.ModuleFilePath.clear();
-}
+Other.ModuleName.clear();
+Other.ModuleFilePath.clear();
+  }
 
   ModuleFile =(ModuleFile &) = delete;
 
@@ -140,7 +140,8 @@ buildModuleFile(StringRef ModuleName, PathRef 
ModuleUnitFile,
   IgnoreDiagnostics IgnoreDiags;
   auto CI = buildCompilerInvocation(Inputs, IgnoreDiags);
   if (!CI) {
-log("Failed to build module {0} since build Compiler invocation failed", 
ModuleName);
+log("Failed to build module {0} since build Compiler invocation failed",
+ModuleName);
 return std::nullopt;
   }
 
@@ -151,7 +152,7 @@ buildModuleFile(StringRef ModuleName, PathRef 
ModuleUnitFile,
 log("Failed to build module {0} since get buffer failed", ModuleName);
 return std::nullopt;
   }
-  
+
   // Try to use the built module files from clangd first.
   BuiltModuleFiles.adjustHeaderSearchOptions(CI->getHeaderSearchOpts());
 
@@ -167,7 +168,8 @@ buildModuleFile(StringRef ModuleName, PathRef 
ModuleUnitFile,
   prepareCompilerInstance(std::move(CI), /*Preamble=*/nullptr,
   std::move(*Buf), std::move(FS), IgnoreDiags);
   if (!Clang) {
-log("Failed to build module {0} since build compiler instance failed", 
ModuleName);
+log("Failed to build module {0} since build compiler instance failed",
+ModuleName);
 return std::nullopt;
   }
 
@@ -192,8 +194,7 @@ public:
 
   /// We shouldn't adjust the compilation commands based on
   /// FailedPrerequisiteModules.
-  void adjustHeaderSearchOptions(HeaderSearchOptions ) const override {
-  }
+  void adjustHeaderSearchOptions(HeaderSearchOptions ) const override 
{}
   /// FailedPrerequisiteModules can never be reused.
   bool
   canReuse(const CompilerInvocation ,
@@ -492,8 +493,8 @@ private:
   std::shared_ptr ,
   ReusableModulesBuilder )
 : ModuleName(ModuleName), Mutex(Mutex), CV(CV), Builder(Builder) {
-  IsFirstTask = (Mutex.use_count() == 2);
-}
+  IsFirstTask = (Mutex.use_count() == 2);
+}
 
 ~ModuleBuildingSharedOwner();
 
@@ -641,7 +642,8 @@ bool ReusableModulesBuilder::getOrBuildModuleFile(
 
   if (std::shared_ptr Cached =
   getValidModuleFile(ModuleName, MDB)) {
-log("Reusing Built Module {0} with {1}", Cached->ModuleName, 
Cached->ModuleFilePath);
+log("Reusing Built Module {0} with {1}", Cached->ModuleName,
+Cached->ModuleFilePath);
 BuiltModuleFiles.addModuleFile(Cached);
 return true;
   }
diff --git a/clang-tools-extra/clangd/ProjectModules.h 
b/clang-tools-extra/clangd/ProjectModules.h
index 3c47863cf8..5a3ca3a05f 100644
--- a/clang-tools-extra/clangd/ProjectModules.h
+++ b/clang-tools-extra/clangd/ProjectModules.h
@@ -46,7 +46,7 @@ public:
   virtual PathRef
   getSourceForModuleName(StringRef ModuleName,
  PathRef RequiredSrcFile = 

[clang-tools-extra] [clangd] [C++20] [Modules] Introduce initial support for C++20 Modules (PR #66462)

2023-11-26 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

@sam-mccall I created https://github.com/llvm/llvm-project/pull/73483 as the 
following patches to reuse built module files. I think that patch should be 
necessary since the current patch may waste too many time and space since it 
won't reuse the module files across source files. I am wondering if we can land 
the current patch if it doesn't have big issues. Then we can turn into the next 
iterations.

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


[clang] [Docs][Clang] Missing DR status for C++23-era papers in cxx_status.html (PR #68846)

2023-11-26 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

@frederick-vs-ja Just to be clear, are you waiting for anyone to merge this?

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


[clang-tools-extra] [clangd] Introduce reusable modules builder (PR #73483)

2023-11-26 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-modules

@llvm/pr-subscribers-clangd

Author: Chuanqi Xu (ChuanqiXu9)


Changes

This is a draft based on https://github.com/llvm/llvm-project/pull/66462. 

The main goal of the patch is to implement the TODO step 1: "reuse module 
files" across source files. In my mind, the modules in clangd will become 
relatively usable after this patch. I hope we can land this in clang18 too.

A big assumption for this patch is that there is exactly one source file 
declaring the same module (unit) in the project. This is not technically true 
since we can multiple unrelated modules in the same project. I think this is a 
understandable assumption for users too. To fully address the underlying issue, 
we need input from build systems as @mathstuf mentioned in 
https://github.com/llvm/llvm-project/pull/66462#discussion_r1350209248.  But I 
don't  think we have to wait for that.

The core ideas for this patch are:
- We reuse the ASTWorker thread to build the modules as we did in the previous 
patch.
- We store the built module files in the modules builder. Then the other 
ASTWorker which needs the module files can get it quickly.
- If the module unit file get changed, the modules builder needs to make sure 
other ASTWorkers don't get the outdated module files.
- The built module files are shared by ASTWorkers. So that even if the modules 
builder remove the module files in its own state, the actual module files won't 
be deleted until they are released by the ASTWorkers.
- When multiple ASTWorkers need the same module file, only one of the workers 
will build that module file actually and the rest of them will wait for the 
built result.

The model can be improved in future by introducing a thread pool for building 
modules. The difference is that now when we only open a source file which 
imports a lot of modules (indirectly), we would only build the modules one by 
one. However, if we have a thread pool for building modules specially, we can 
try to build the modules in parallel. To achieve this, we need an explicit 
module graph. I did this in the first patch: https://reviews.llvm.org/D153114. 
I think we can try to introduce that thread pool later than sooner since it may 
be better to keep the changes small instead of large. (This is what required in 
the first review page.)

I tested this patch with real workloads. I'll add in-tree test once 
https://github.com/llvm/llvm-project/pull/66462 landed (Otherwise refactoring 
interfaces may be painful)


---

Patch is 92.78 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/73483.diff


31 Files Affected:

- (modified) clang-tools-extra/clangd/CMakeLists.txt (+4) 
- (modified) clang-tools-extra/clangd/ClangdServer.cpp (+2) 
- (modified) clang-tools-extra/clangd/ClangdServer.h (+3) 
- (modified) clang-tools-extra/clangd/GlobalCompilationDatabase.cpp (+23) 
- (modified) clang-tools-extra/clangd/GlobalCompilationDatabase.h (+14) 
- (added) clang-tools-extra/clangd/ModuleDependencyScanner.cpp (+90) 
- (added) clang-tools-extra/clangd/ModuleDependencyScanner.h (+108) 
- (added) clang-tools-extra/clangd/ModulesBuilder.cpp (+706) 
- (added) clang-tools-extra/clangd/ModulesBuilder.h (+61) 
- (modified) clang-tools-extra/clangd/ParsedAST.cpp (+7) 
- (modified) clang-tools-extra/clangd/Preamble.cpp (+22-6) 
- (modified) clang-tools-extra/clangd/Preamble.h (+10) 
- (added) clang-tools-extra/clangd/PrerequisiteModules.h (+83) 
- (added) clang-tools-extra/clangd/ProjectModules.cpp (+66) 
- (added) clang-tools-extra/clangd/ProjectModules.h (+56) 
- (modified) clang-tools-extra/clangd/TUScheduler.cpp (+33-18) 
- (modified) clang-tools-extra/clangd/TUScheduler.h (+7) 
- (modified) clang-tools-extra/clangd/test/CMakeLists.txt (+1) 
- (added) clang-tools-extra/clangd/test/modules.test (+83) 
- (modified) clang-tools-extra/clangd/tool/Check.cpp (+13-2) 
- (modified) clang-tools-extra/clangd/tool/ClangdMain.cpp (+8) 
- (modified) clang-tools-extra/clangd/unittests/CMakeLists.txt (+2) 
- (modified) clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp (+17-5) 
- (modified) clang-tools-extra/clangd/unittests/FileIndexTests.cpp (+3-1) 
- (added) clang-tools-extra/clangd/unittests/ModuleDependencyScannerTest.cpp 
(+176) 
- (added) clang-tools-extra/clangd/unittests/ModulesTestSetup.h (+103) 
- (modified) clang-tools-extra/clangd/unittests/ParsedASTTests.cpp (+6-2) 
- (modified) clang-tools-extra/clangd/unittests/PreambleTests.cpp (+4-2) 
- (added) clang-tools-extra/clangd/unittests/PrerequisiteModulesTest.cpp (+227) 
- (modified) clang-tools-extra/clangd/unittests/TestTU.cpp (+10-4) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+3) 


``diff
diff --git a/clang-tools-extra/clangd/CMakeLists.txt 
b/clang-tools-extra/clangd/CMakeLists.txt
index 3911fb6c6c746a8..242a8ad2e350be7 100644
--- a/clang-tools-extra/clangd/CMakeLists.txt
+++ b/clang-tools-extra/clangd/CMakeLists.txt
@@ -97,7 +97,10 

[clang-tools-extra] [clangd] Introduce reusable modules builder (PR #73483)

2023-11-26 Thread Chuanqi Xu via cfe-commits

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


[clang-tools-extra] [clangd] [C++20] [Modules] Introduce initial support for C++20 Modules (PR #66462)

2023-11-26 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 updated 
https://github.com/llvm/llvm-project/pull/66462

>From 32010ae7e0a47cd4a70a9401980b32ed1d3e10f6 Mon Sep 17 00:00:00 2001
From: Chuanqi Xu 
Date: Fri, 15 Sep 2023 11:33:53 +0800
Subject: [PATCH] [clangd] [C++20] [Modules] Introduce initial support for
 C++20 Modules

Alternatives to https://reviews.llvm.org/D153114.

Try to address https://github.com/clangd/clangd/issues/1293.

See the links for design ideas. We want to have some initial support in
clang18.

This is the initial support for C++20 Modules in clangd.
As suggested by sammccall in https://reviews.llvm.org/D153114,
we should minimize the scope of the initial patch to make it easier
to review and understand so that every one are in the same page:

> Don't attempt any cross-file or cross-version coordination: i.e. don't
> try to reuse BMIs between different files, don't try to reuse BMIs
> between (preamble) reparses of the same file, don't try to persist the
> module graph. Instead, when building a preamble, synchronously scan
> for the module graph, build the required PCMs on the single preamble
> thread with filenames private to that preamble, and then proceed to
> build the preamble.

And this patch reflects the above opinions.
---
 clang-tools-extra/clangd/CMakeLists.txt   |   4 +
 clang-tools-extra/clangd/ClangdServer.cpp |   2 +
 clang-tools-extra/clangd/ClangdServer.h   |   3 +
 .../clangd/GlobalCompilationDatabase.cpp  |  23 ++
 .../clangd/GlobalCompilationDatabase.h|  14 +
 .../clangd/ModuleDependencyScanner.cpp|  81 +
 .../clangd/ModuleDependencyScanner.h  | 106 ++
 clang-tools-extra/clangd/ModulesBuilder.cpp   | 339 ++
 clang-tools-extra/clangd/ModulesBuilder.h |  71 
 clang-tools-extra/clangd/ParsedAST.cpp|   7 +
 clang-tools-extra/clangd/Preamble.cpp |  28 +-
 clang-tools-extra/clangd/Preamble.h   |  10 +
 .../clangd/PrerequisiteModules.h  |  87 +
 clang-tools-extra/clangd/ProjectModules.cpp   |  62 
 clang-tools-extra/clangd/ProjectModules.h |  55 +++
 clang-tools-extra/clangd/TUScheduler.cpp  |  50 ++-
 clang-tools-extra/clangd/TUScheduler.h|   7 +
 clang-tools-extra/clangd/test/CMakeLists.txt  |   1 +
 clang-tools-extra/clangd/test/modules.test|  83 +
 clang-tools-extra/clangd/tool/Check.cpp   |  13 +-
 clang-tools-extra/clangd/tool/ClangdMain.cpp  |   8 +
 .../clangd/unittests/CMakeLists.txt   |   2 +
 .../clangd/unittests/CodeCompleteTests.cpp|  22 +-
 .../clangd/unittests/FileIndexTests.cpp   |   4 +-
 .../unittests/ModuleDependencyScannerTest.cpp | 176 +
 .../clangd/unittests/ModulesTestSetup.h   | 103 ++
 .../clangd/unittests/ParsedASTTests.cpp   |   8 +-
 .../clangd/unittests/PreambleTests.cpp|   6 +-
 .../unittests/PrerequisiteModulesTest.cpp | 224 
 clang-tools-extra/clangd/unittests/TestTU.cpp |  14 +-
 clang-tools-extra/docs/ReleaseNotes.rst   |   3 +
 31 files changed, 1576 insertions(+), 40 deletions(-)
 create mode 100644 clang-tools-extra/clangd/ModuleDependencyScanner.cpp
 create mode 100644 clang-tools-extra/clangd/ModuleDependencyScanner.h
 create mode 100644 clang-tools-extra/clangd/ModulesBuilder.cpp
 create mode 100644 clang-tools-extra/clangd/ModulesBuilder.h
 create mode 100644 clang-tools-extra/clangd/PrerequisiteModules.h
 create mode 100644 clang-tools-extra/clangd/ProjectModules.cpp
 create mode 100644 clang-tools-extra/clangd/ProjectModules.h
 create mode 100644 clang-tools-extra/clangd/test/modules.test
 create mode 100644 
clang-tools-extra/clangd/unittests/ModuleDependencyScannerTest.cpp
 create mode 100644 clang-tools-extra/clangd/unittests/ModulesTestSetup.h
 create mode 100644 
clang-tools-extra/clangd/unittests/PrerequisiteModulesTest.cpp

diff --git a/clang-tools-extra/clangd/CMakeLists.txt 
b/clang-tools-extra/clangd/CMakeLists.txt
index 3911fb6c6c746a8..242a8ad2e350be7 100644
--- a/clang-tools-extra/clangd/CMakeLists.txt
+++ b/clang-tools-extra/clangd/CMakeLists.txt
@@ -97,7 +97,10 @@ add_clang_library(clangDaemon
   IncludeFixer.cpp
   InlayHints.cpp
   JSONTransport.cpp
+  ModuleDependencyScanner.cpp
+  ModulesBuilder.cpp
   PathMapping.cpp
+  ProjectModules.cpp
   Protocol.cpp
   Quality.cpp
   ParsedAST.cpp
@@ -161,6 +164,7 @@ clang_target_link_libraries(clangDaemon
   clangAST
   clangASTMatchers
   clangBasic
+  clangDependencyScanning
   clangDriver
   clangFormat
   clangFrontend
diff --git a/clang-tools-extra/clangd/ClangdServer.cpp 
b/clang-tools-extra/clangd/ClangdServer.cpp
index 13d788162817fb4..8ba4b38c420ab6a 100644
--- a/clang-tools-extra/clangd/ClangdServer.cpp
+++ b/clang-tools-extra/clangd/ClangdServer.cpp
@@ -202,6 +202,7 @@ ClangdServer::Options::operator TUScheduler::Options() 
const {
   Opts.UpdateDebounce = UpdateDebounce;
   Opts.ContextProvider = ContextProvider;
   Opts.PreambleThrottler = PreambleThrottler;
+  

[clang] [Driver][MachineOutliner] Support -moutline option for aarch64_be (PR #73223)

2023-11-26 Thread dong jianqiang via cfe-commits

https://github.com/dongjianqiang2 updated 
https://github.com/llvm/llvm-project/pull/73223

>From 2a90faa84bd4a47a291f0631f26b87e7ee60ce63 Mon Sep 17 00:00:00 2001
From: dong jianqiang 
Date: Thu, 23 Nov 2023 16:58:11 +0800
Subject: [PATCH] [Driver][MachineOutliner] Support outlining option with LTO
 for aarch64_be

This patch propagates the -moutline option when target is aarch64_be,
fix warning: 'aarch64_be' does not support '-moutline'; flag ignored 
[-Woption-ignored]
---
 clang/lib/Driver/ToolChains/CommonArgs.cpp | 3 ++-
 clang/test/Driver/aarch64-outliner.c   | 2 ++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 5d2cd1959b06925..078f2ff80a21939 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -2436,7 +2436,8 @@ void tools::addMachineOutlinerArgs(const Driver ,
   // Otherwise, add the proper mllvm flags.
   if (!(Triple.isARM() || Triple.isThumb() ||
 Triple.getArch() == llvm::Triple::aarch64 ||
-Triple.getArch() == llvm::Triple::aarch64_32)) {
+Triple.getArch() == llvm::Triple::aarch64_32 ||
+Triple.getArch() == llvm::Triple::aarch64_be)) {
 D.Diag(diag::warn_drv_moutline_unsupported_opt) << 
Triple.getArchName();
   } else {
 addArg(Twine("-enable-machine-outliner"));
diff --git a/clang/test/Driver/aarch64-outliner.c 
b/clang/test/Driver/aarch64-outliner.c
index 42e43b433e282d3..06e5de11ec49ecd 100644
--- a/clang/test/Driver/aarch64-outliner.c
+++ b/clang/test/Driver/aarch64-outliner.c
@@ -1,7 +1,9 @@
 // REQUIRES: aarch64-registered-target
 // RUN: %clang --target=aarch64 -moutline -S %s -### 2>&1 | FileCheck %s 
-check-prefix=ON
+// RUN: %clang --target=aarch64_be -moutline -S %s -### 2>&1 | FileCheck %s 
-check-prefix=ON
 // ON: "-mllvm" "-enable-machine-outliner"
 // RUN: %clang --target=aarch64 -moutline -mno-outline -S %s -### 2>&1 | 
FileCheck %s -check-prefix=OFF
+// RUN: %clang --target=aarch64_be -moutline -mno-outline -S %s -### 2>&1 | 
FileCheck %s -check-prefix=OFF
 // OFF: "-mllvm" "-enable-machine-outliner=never"
 // RUN: %clang --target=x86_64 -moutline -S %s -### 2>&1 | FileCheck %s 
-check-prefix=WARN
 // WARN: warning: 'x86_64' does not support '-moutline'; flag ignored 
[-Woption-ignored]

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


[clang] [Driver] Allow -e entry but reject -eentry (PR #72804)

2023-11-26 Thread dong jianqiang via cfe-commits

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


[clang] 282201d - [Driver] Allow -e entry but reject -eentry (#72804)

2023-11-26 Thread via cfe-commits

Author: Fangrui Song
Date: 2023-11-27T11:04:29+08:00
New Revision: 282201dc633e164042df0ae726a804c0aad46e50

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

LOG: [Driver] Allow -e entry but reject -eentry (#72804)

This short option taking an argument is unfortunate.

* If a cc1-only option starts with `-e`, using it for driver will not be
  reported as an error (e.g. commit
  6cd9886c88d16d288c74846495d89f2fe84ff827).
* If another `-e` driver option is intended but a typo is made, the
  option will be recognized as a `-e`.

`gcc -export-dynamic` passes `-export-dynamic` to ld. It's not clear
whether some options behave this way.

It seems `-Wl,-eentry` and `-Wl,--entry=entry` are primarily used. There
may also be a few `gcc -e entry`, but `gcc -eentry` is extremely rare or
not used at all. Therefore, we probably should reject the Joined form of
`-e`.

Added: 
clang/test/Driver/entry.s

Modified: 
clang/include/clang/Driver/Options.td

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 9191ccd2a66ac4a..9689f12fd01417b 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1452,7 +1452,7 @@ def extract_api_ignores_EQ: CommaJoined<["--"], 
"extract-api-ignores=">,
   Visibility<[ClangOption, CC1Option]>,
 HelpText<"Comma separated list of files containing a new line separated 
list of API symbols to ignore when extracting API information.">,
 MarshallingInfoStringVector>;
-def e : JoinedOrSeparate<["-"], "e">, Flags<[LinkerInput]>, Group;
+def e : Separate<["-"], "e">, Flags<[LinkerInput]>, Group;
 def fmax_tokens_EQ : Joined<["-"], "fmax-tokens=">, Group,
   Visibility<[ClangOption, CC1Option]>,
   HelpText<"Max total number of preprocessed tokens for -Wmax-tokens.">,

diff  --git a/clang/test/Driver/entry.s b/clang/test/Driver/entry.s
new file mode 100644
index 000..60ab89704c35462
--- /dev/null
+++ b/clang/test/Driver/entry.s
@@ -0,0 +1,5 @@
+/// To prevent mistaking -exxx as --entry=xxx, we allow -e xxx but reject 
-exxx.
+/// GCC -export-dynamic is rejected as well.
+// RUN: not %clang -### --target=x86_64-linux-gnu -export-dynamic %s 2>&1 | 
FileCheck %s
+
+// CHECK: error: unknown argument: '-export-dynamic'



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


[clang] [clang] Bounds checking on unclosed parentheses, brackets or braces in Expanded Tokens (PR #69849)

2023-11-26 Thread Nathan Ridge via cfe-commits


@@ -585,6 +585,17 @@ TEST_F(TokenCollectorTest, DelayedParsing) {
   EXPECT_THAT(collectAndDump(Code), StartsWith(ExpectedTokens));
 }
 
+TEST_F(TokenCollectorTest, UnclosedToken) {

HighCommander4 wrote:

I started looking at this to try and make some progress towards getting this 
landed. However, when running this test locally, I'm not seeing either of the 
branches added to `spelledForExpandedToken()` being taken.

Am I missing something, or is this test not exercising the intended codepath?

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


[clang] [Docs][Clang] Missing DR status for C++23-era papers in cxx_status.html (PR #68846)

2023-11-26 Thread A. Jiang via cfe-commits

https://github.com/frederick-vs-ja updated 
https://github.com/llvm/llvm-project/pull/68846

>From 9ef23f11f52735976a05080227bb880af3b9cbb6 Mon Sep 17 00:00:00 2001
From: "A. Jiang" 
Date: Tue, 17 Oct 2023 10:41:18 +0800
Subject: [PATCH] [Docs][Clang] DR status in cxx_status.html

---
 clang/www/cxx_status.html | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/clang/www/cxx_status.html b/clang/www/cxx_status.html
index 621439d0bae9666..a1e9b51c25905b9 100755
--- a/clang/www/cxx_status.html
+++ b/clang/www/cxx_status.html
@@ -207,7 +207,7 @@ C++23 implementation status
 
 
   Allow duplicate attributes
-  https://wg21.link/P2156R1;>P2156R1
+  https://wg21.link/P2156R1;>P2156R1 (DR)
   Clang 13
 
 
@@ -227,7 +227,7 @@ C++23 implementation status
 
 
   C++ identifier syntax using UAX 31
-  https://wg21.link/P1949R7;>P1949R7
+  https://wg21.link/P1949R7;>P1949R7 (DR)
   Clang 14
 
 
@@ -247,11 +247,11 @@ C++23 implementation status
 
 
   Change scope of lambda trailing-return-type
-  https://wg21.link/P2036R3;>P2036R3
+  https://wg21.link/P2036R3;>P2036R3 (DR)
   Clang 17
 
 
-  https://wg21.link/P2579R0;>P2579R0
+  https://wg21.link/P2579R0;>P2579R0 (DR)
 
 
   Multidimensional subscript operator
@@ -320,12 +320,12 @@ C++23 implementation status
 
 
   The Equality Operator You Are Looking For
-  https://wg21.link/P2468R2;>P2468R2
+  https://wg21.link/P2468R2;>P2468R2 (DR)
   Clang 16
 
 
   De-deprecating volatile compound operations
-  https://wg21.link/P2327R1;>P2327R1
+  https://wg21.link/P2327R1;>P2327R1 (DR)
   Clang 15
 
 
@@ -397,7 +397,7 @@ C++23 implementation status
 
 
   char8_t Compatibility and Portability Fix
-  https://wg21.link/P2513R3;>P2513R3
+  https://wg21.link/P2513R3;>P2513R3 (DR)
   Clang 16
 
 
@@ -539,7 +539,7 @@ C++20 implementation status
 https://wg21.link/p2103r0;>P2103R0
   

-https://wg21.link/p2493r0;>P2493R0
+https://wg21.link/p2493r0;>P2493R0 (DR)
   
   
 https://wg21.link/p2092r0;>P2092R0

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


[clang-tools-extra] [clangd] Improve BlockEnd inlay hints presentation (PR #72345)

2023-11-26 Thread Nathan Ridge via cfe-commits

https://github.com/HighCommander4 requested changes to this pull request.

(see previous comment)

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


[clang-tools-extra] [clangd] Improve BlockEnd inlay hints presentation (PR #72345)

2023-11-26 Thread Nathan Ridge via cfe-commits

HighCommander4 wrote:

Thanks, the behaviour changes look reasonable to me.

> I haven't update the test because the hard-coded limit 10 makes it hard to 
> write the tests. Any opinion of how to structure this?

I would suggest running most tests with `HintMinLineLimit = 2` (and then have 
one test for the behaviour with `HintMinLineLimit = 10`).

To allow the tests to change `HintMinLineLimit`, we could give the 
`inlayHints()` function an optional parameter to specify it (could wrap it in 
an `InlayHintOptions` class for adding other options in the future).

https://github.com/llvm/llvm-project/pull/72345
___
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 formating `#define A x:` (PR #73220)

2023-11-26 Thread Owen Pan via cfe-commits

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


[clang] a369a59 - [clang-format] Fix a bug in formating `#define A x:` (#73220)

2023-11-26 Thread via cfe-commits

Author: Owen Pan
Date: 2023-11-26T16:20:19-08:00
New Revision: a369a5946f99254d56455f3deb0031199562c1dd

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

LOG: [clang-format] Fix a bug in formating `#define A x:` (#73220)

Fixed #70789.

Added: 


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

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index c870ff01605e725..7b4ec25a8938fc0 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -1171,6 +1171,12 @@ void UnwrappedLineParser::parsePPDefine() {
   assert((int)Line->PPLevel >= 0);
   Line->InMacroBody = true;
 
+  if (FormatTok->is(tok::identifier) &&
+  Tokens->peekNextToken()->is(tok::colon)) {
+nextToken();
+nextToken();
+  }
+
   // Errors during a preprocessor directive can only affect the layout of the
   // preprocessor directive, and thus we ignore them. An alternative approach
   // would be to use the same approach we use on the file level (no

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 67423f9b06fbc37..d095a2b751defe3 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -1863,6 +1863,8 @@ TEST_F(FormatTest, UnderstandsMacros) {
   verifyFormat("MACRO(something##something)");
   verifyFormat("MACRO(return##something)");
   verifyFormat("MACRO(co_return##something)");
+
+  verifyFormat("#define A x:");
 }
 
 TEST_F(FormatTest, ShortBlocksInMacrosDontMergeWithCodeAfterMacro) {



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


[libc] [libcxx] [clang] [llvm] [compiler-rt] [flang] [Clang] Use correct base expression for counted_by field (#73168) (PR #73465)

2023-11-26 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Bill Wendling (bwendling)


Changes

I'll add some testcases later today.

---

Patch is 31.10 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/73465.diff


4 Files Affected:

- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+2-2) 
- (modified) clang/lib/CodeGen/CGExpr.cpp (+35-17) 
- (modified) clang/lib/CodeGen/CodeGenFunction.h (+1-2) 
- (modified) clang/test/CodeGen/attr-counted-by.c (+82-82) 


``diff
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index c83ea966fdeadc6..1d02b0fc59b9b0e 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -916,7 +916,7 @@ CodeGenFunction::emitFlexibleArrayMemberSize(const Expr *E, 
unsigned Type,
 
   // Build a load of the counted_by field.
   bool IsSigned = CountedByFD->getType()->isSignedIntegerType();
-  const Expr *CountedByExpr = BuildCountedByFieldExpr(Base, CountedByFD);
+  Expr *CountedByExpr = BuildCountedByFieldExpr(Base, CountedByFD);
   Value *CountedByInst = EmitAnyExprToTemp(CountedByExpr).getScalarVal();
   llvm::Type *CountedByTy = CountedByInst->getType();
 
@@ -945,7 +945,7 @@ CodeGenFunction::emitFlexibleArrayMemberSize(const Expr *E, 
unsigned Type,
  : Builder.CreateZExtOrTrunc(FAMSize, ResType);
   Value *Res = FAMSize;
 
-  if (const auto *DRE = dyn_cast(Base)) {
+  if (isa(Base)) {
 // The whole struct is specificed in the __bdos.
 const RecordDecl *OuterRD =
 CountedByFD->getDeclContext()->getOuterLexicalRecordContext();
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index a75f630e1a4c767..60dc5d68a223dd8 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -940,7 +940,7 @@ static llvm::Value *getArrayIndexingBound(CodeGenFunction 
,
 
 if (const ValueDecl *VD = CGF.FindCountedByField(Base)) {
   IndexedType = Base->getType();
-  const Expr *E = CGF.BuildCountedByFieldExpr(Base, VD);
+  Expr *E = CGF.BuildCountedByFieldExpr(Base, VD);
   return CGF.EmitAnyExprToTemp(E).getScalarVal();
 }
   }
@@ -956,21 +956,41 @@ static llvm::Value *getArrayIndexingBound(CodeGenFunction 
,
   return nullptr;
 }
 
-const Expr *
-CodeGenFunction::BuildCountedByFieldExpr(const Expr *Base,
- const ValueDecl *CountedByVD) {
+Expr *CodeGenFunction::BuildCountedByFieldExpr(const Expr *Base,
+   const ValueDecl *CountedByVD) {
   // Find the outer struct expr (i.e. p in p->a.b.c.d).
   Expr *CountedByExpr = const_cast(Base)->IgnoreParenImpCasts();
 
+  // Get the enclosing struct, but not the outermost enclosing struct.
+  const DeclContext *DC = CountedByVD->getLexicalDeclContext();
+  const RecordDecl *CountedByRD = dyn_cast(DC);
+  if (!CountedByRD)
+return nullptr;
+
   // Work our way up the expression until we reach the DeclRefExpr.
-  while (!isa(CountedByExpr))
-if (const auto *ME = dyn_cast(CountedByExpr))
-  CountedByExpr = ME->getBase()->IgnoreParenImpCasts();
+  while (auto *ME = dyn_cast(CountedByExpr)) {
+CountedByExpr = ME->getBase()->IgnoreImpCasts();
+
+// Use the base of an ArraySubscriptExpr.
+while (auto *ASE = dyn_cast(CountedByExpr))
+  CountedByExpr = ASE->getBase()->IgnoreImpCasts();
+
+QualType Ty = CountedByExpr->getType();
+if (Ty->isPointerType())
+  Ty = Ty->getPointeeType();
+
+// Stop when we reach the struct containing the counted_by field.
+if (CountedByRD == Ty->getAsRecordDecl())
+  break;
+  }
+
+  ASTContext  = getContext();
 
-  // Add back an implicit cast to create the required pr-value.
-  CountedByExpr = ImplicitCastExpr::Create(
-  getContext(), CountedByExpr->getType(), CK_LValueToRValue, CountedByExpr,
-  nullptr, VK_PRValue, FPOptionsOverride());
+  if (!CountedByExpr->isPRValue())
+// Add an implicit cast to create the required pr-value.
+CountedByExpr = ImplicitCastExpr::Create(
+Ctx, CountedByExpr->getType(), CK_LValueToRValue, CountedByExpr,
+nullptr, VK_PRValue, FPOptionsOverride());
 
   if (const auto *IFD = dyn_cast(CountedByVD)) {
 // The counted_by field is inside an anonymous struct / union. The
@@ -978,15 +998,13 @@ CodeGenFunction::BuildCountedByFieldExpr(const Expr *Base,
 // easily. (Yay!)
 for (NamedDecl *ND : IFD->chain()) {
   auto *VD = cast(ND);
-  CountedByExpr =
-  MemberExpr::CreateImplicit(getContext(), CountedByExpr,
- CountedByExpr->getType()->isPointerType(),
- VD, VD->getType(), VK_LValue, 
OK_Ordinary);
+  CountedByExpr = MemberExpr::CreateImplicit(
+  Ctx, CountedByExpr, CountedByExpr->getType()->isPointerType(), VD,
+  VD->getType(), VK_LValue, OK_Ordinary);
 }
   } else {
 CountedByExpr = 

[libc] [libcxx] [clang] [llvm] [compiler-rt] [flang] [Clang] Use correct base expression for counted_by field (#73168) (PR #73465)

2023-11-26 Thread Bill Wendling via cfe-commits

https://github.com/bwendling created 
https://github.com/llvm/llvm-project/pull/73465

I'll add some testcases later today.

>From 3aa35a39184ff8d4ff11b9f41b4551bec78bdca5 Mon Sep 17 00:00:00 2001
From: Bill Wendling 
Date: Wed, 22 Nov 2023 15:16:19 -0800
Subject: [PATCH] [Clang] Use correct base expression for counted_by field

The base expression of the counted_by field may not be the outermost
enclosing struct, but could be a sub-struct. Use the latter in those
cases.

Closes #73168
---
 clang/lib/CodeGen/CGBuiltin.cpp  |   4 +-
 clang/lib/CodeGen/CGExpr.cpp |  52 ++---
 clang/lib/CodeGen/CodeGenFunction.h  |   3 +-
 clang/test/CodeGen/attr-counted-by.c | 164 +--
 4 files changed, 120 insertions(+), 103 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 710e4c162103b41..43bf1218b70d781 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -916,7 +916,7 @@ CodeGenFunction::emitFlexibleArrayMemberSize(const Expr *E, 
unsigned Type,
 
   // Build a load of the counted_by field.
   bool IsSigned = CountedByFD->getType()->isSignedIntegerType();
-  const Expr *CountedByExpr = BuildCountedByFieldExpr(Base, CountedByFD);
+  Expr *CountedByExpr = BuildCountedByFieldExpr(Base, CountedByFD);
   Value *CountedByInst = EmitAnyExprToTemp(CountedByExpr).getScalarVal();
   llvm::Type *CountedByTy = CountedByInst->getType();
 
@@ -945,7 +945,7 @@ CodeGenFunction::emitFlexibleArrayMemberSize(const Expr *E, 
unsigned Type,
  : Builder.CreateZExtOrTrunc(FAMSize, ResType);
   Value *Res = FAMSize;
 
-  if (const auto *DRE = dyn_cast(Base)) {
+  if (isa(Base)) {
 // The whole struct is specificed in the __bdos.
 const RecordDecl *OuterRD =
 CountedByFD->getDeclContext()->getOuterLexicalRecordContext();
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index a75f630e1a4c767..60dc5d68a223dd8 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -940,7 +940,7 @@ static llvm::Value *getArrayIndexingBound(CodeGenFunction 
,
 
 if (const ValueDecl *VD = CGF.FindCountedByField(Base)) {
   IndexedType = Base->getType();
-  const Expr *E = CGF.BuildCountedByFieldExpr(Base, VD);
+  Expr *E = CGF.BuildCountedByFieldExpr(Base, VD);
   return CGF.EmitAnyExprToTemp(E).getScalarVal();
 }
   }
@@ -956,21 +956,41 @@ static llvm::Value *getArrayIndexingBound(CodeGenFunction 
,
   return nullptr;
 }
 
-const Expr *
-CodeGenFunction::BuildCountedByFieldExpr(const Expr *Base,
- const ValueDecl *CountedByVD) {
+Expr *CodeGenFunction::BuildCountedByFieldExpr(const Expr *Base,
+   const ValueDecl *CountedByVD) {
   // Find the outer struct expr (i.e. p in p->a.b.c.d).
   Expr *CountedByExpr = const_cast(Base)->IgnoreParenImpCasts();
 
+  // Get the enclosing struct, but not the outermost enclosing struct.
+  const DeclContext *DC = CountedByVD->getLexicalDeclContext();
+  const RecordDecl *CountedByRD = dyn_cast(DC);
+  if (!CountedByRD)
+return nullptr;
+
   // Work our way up the expression until we reach the DeclRefExpr.
-  while (!isa(CountedByExpr))
-if (const auto *ME = dyn_cast(CountedByExpr))
-  CountedByExpr = ME->getBase()->IgnoreParenImpCasts();
+  while (auto *ME = dyn_cast(CountedByExpr)) {
+CountedByExpr = ME->getBase()->IgnoreImpCasts();
+
+// Use the base of an ArraySubscriptExpr.
+while (auto *ASE = dyn_cast(CountedByExpr))
+  CountedByExpr = ASE->getBase()->IgnoreImpCasts();
+
+QualType Ty = CountedByExpr->getType();
+if (Ty->isPointerType())
+  Ty = Ty->getPointeeType();
+
+// Stop when we reach the struct containing the counted_by field.
+if (CountedByRD == Ty->getAsRecordDecl())
+  break;
+  }
+
+  ASTContext  = getContext();
 
-  // Add back an implicit cast to create the required pr-value.
-  CountedByExpr = ImplicitCastExpr::Create(
-  getContext(), CountedByExpr->getType(), CK_LValueToRValue, CountedByExpr,
-  nullptr, VK_PRValue, FPOptionsOverride());
+  if (!CountedByExpr->isPRValue())
+// Add an implicit cast to create the required pr-value.
+CountedByExpr = ImplicitCastExpr::Create(
+Ctx, CountedByExpr->getType(), CK_LValueToRValue, CountedByExpr,
+nullptr, VK_PRValue, FPOptionsOverride());
 
   if (const auto *IFD = dyn_cast(CountedByVD)) {
 // The counted_by field is inside an anonymous struct / union. The
@@ -978,15 +998,13 @@ CodeGenFunction::BuildCountedByFieldExpr(const Expr *Base,
 // easily. (Yay!)
 for (NamedDecl *ND : IFD->chain()) {
   auto *VD = cast(ND);
-  CountedByExpr =
-  MemberExpr::CreateImplicit(getContext(), CountedByExpr,
- CountedByExpr->getType()->isPointerType(),
- VD, VD->getType(), VK_LValue, 

[clang] [Clang] Eagerly instantiate used constexpr function upon definition. (PR #73463)

2023-11-26 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: cor3ntin (cor3ntin)


Changes

Despite CWG2497 not being resolved, it is reasonable to expect the following 
code to compile (and which is supported by other compilers)

```cpp
  templatetypename T constexpr T f();
  constexpr int g() { return fint(); } // #1
  templatetypename T constexpr T f() { return 123; }
  int k[g()];
  // #2
```

To that end, we eagerly instantiate all referenced specializations of constexpr 
functions when they are defined.

We maintain a map of (pattern, [instantiations]) independant of 
`PendingInstantiations` to avoid having to iterate that list after each 
function definition.

We should apply the same logic to constexpr variables, but I wanted to keep the 
PR small.

Fixes #73232

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


7 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+5) 
- (modified) clang/include/clang/Sema/Sema.h (+11) 
- (modified) clang/lib/Sema/SemaDecl.cpp (+3) 
- (modified) clang/lib/Sema/SemaExpr.cpp (+7-2) 
- (modified) clang/lib/Sema/SemaTemplateInstantiateDecl.cpp (+17) 
- (modified) clang/test/SemaCXX/cxx2b-consteval-propagate.cpp (+5-3) 
- (added) clang/test/SemaTemplate/instantiate-used-constexpr-function.cpp (+30) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 29a06d0f713f588..b34b66ec7dcabc2 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -762,6 +762,11 @@ Bug Fixes to C++ Support
   completes (except deduction guides). Fixes:
   (`#59827 `_)
 
+- Clang now immediately instantiates function template specializations
+  at the end of the definition of the corresponding function template
+  when the definition appears after the first point of instantiation.
+  (`#73232 `_)
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index f7c9d0e2e6412b7..091e1e3b4c1fd64 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -59,6 +59,7 @@
 #include "clang/Sema/TypoCorrection.h"
 #include "clang/Sema/Weak.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/SetVector.h"
 #include "llvm/ADT/SmallBitVector.h"
 #include "llvm/ADT/SmallPtrSet.h"
@@ -10078,6 +10079,12 @@ class Sema final {
   /// but have not yet been performed.
   std::deque PendingInstantiations;
 
+  /// Track constexpr functions referenced before they are (lexically) defined.
+  /// The key is the pattern, associated with a list of specialisations that
+  /// need to be instantiated when the pattern is defined.
+  llvm::DenseMap>
+  PendingInstantiationsOfConstexprEntities;
+
   /// Queue of implicit template instantiations that cannot be performed
   /// eagerly.
   SmallVector LateParsedInstantiations;
@@ -10396,6 +10403,10 @@ class Sema final {
  bool Recursive = false,
  bool DefinitionRequired = false,
  bool AtEndOfTU = false);
+
+  void InstantiateFunctionTemplateSpecializations(
+  SourceLocation PointOfInstantiation, FunctionDecl *Template);
+
   VarTemplateSpecializationDecl *BuildVarTemplateInstantiation(
   VarTemplateDecl *VarTemplate, VarDecl *FromVar,
   const TemplateArgumentList ,
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 23dd8ae15c16583..1030ba0d21b1906 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -16255,6 +16255,9 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt 
*Body,
   if (FD && !FD->isDeleted())
 checkTypeSupport(FD->getType(), FD->getLocation(), FD);
 
+  if (FD && FD->isConstexpr() && FD->isTemplated())
+InstantiateFunctionTemplateSpecializations(FD->getEndLoc(), FD);
+
   return dcl;
 }
 
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index fc39d6149c1cc65..37b0d0eed35845c 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -19047,12 +19047,17 @@ void Sema::MarkFunctionReferenced(SourceLocation Loc, 
FunctionDecl *Func,
   CodeSynthesisContexts.size())
 PendingLocalImplicitInstantiations.push_back(
 std::make_pair(Func, PointOfInstantiation));
-  else if (Func->isConstexpr())
+  else if (Func->isConstexpr()) {
 // Do not defer instantiations of constexpr functions, to avoid the
 // expression evaluator needing to call back into Sema if it sees a
 // call to such a function.
 InstantiateFunctionDefinition(PointOfInstantiation, Func);
-  else {
+if (!Func->isDefined()) {
+  PendingInstantiationsOfConstexprEntities

[clang] [Clang] Eagerly instantiate used constexpr function upon definition. (PR #73463)

2023-11-26 Thread via cfe-commits

https://github.com/cor3ntin created 
https://github.com/llvm/llvm-project/pull/73463

Despite CWG2497 not being resolved, it is reasonable to expect the following 
code to compile (and which is supported by other compilers)

```cpp
  template constexpr T f();
  constexpr int g() { return f(); } // #1
  template constexpr T f() { return 123; }
  int k[g()];
  // #2
```

To that end, we eagerly instantiate all referenced specializations of constexpr 
functions when they are defined.

We maintain a map of (pattern, [instantiations]) independant of 
`PendingInstantiations` to avoid having to iterate that list after each 
function definition.

We should apply the same logic to constexpr variables, but I wanted to keep the 
PR small.

Fixes #73232

>From ea676509938a3260eaef0963099e2299a787e58b Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Sun, 26 Nov 2023 22:47:51 +0100
Subject: [PATCH] [Clang] Eagerly instantiate used constexpr function upon
 definition.

Despite CWG2497 not being resolved, it is reasonable to expect the following
code to compile (and which is supported by other compilers)

```cpp
  template constexpr T f();
  constexpr int g() { return f(); } // #1
  template constexpr T f() { return 123; }
  int k[g()];
  // #2
```

To that end, we eagerly instantiate all referenced
specializations of constexpr functions when they are defined.

We maintain a map of (pattern, [instantiations]) independant of
`PendingInstantiations` to avoid having to iterate that list after
each function definition.

We should apply the same logic to constexpr variables,
but I wanted to keep the PR small.

Fixes #73232
---
 clang/docs/ReleaseNotes.rst   |  5 
 clang/include/clang/Sema/Sema.h   | 11 +++
 clang/lib/Sema/SemaDecl.cpp   |  3 ++
 clang/lib/Sema/SemaExpr.cpp   |  9 --
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  | 17 +++
 .../SemaCXX/cxx2b-consteval-propagate.cpp |  8 +++--
 .../instantiate-used-constexpr-function.cpp   | 30 +++
 7 files changed, 78 insertions(+), 5 deletions(-)
 create mode 100644 
clang/test/SemaTemplate/instantiate-used-constexpr-function.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 29a06d0f713f588..b34b66ec7dcabc2 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -762,6 +762,11 @@ Bug Fixes to C++ Support
   completes (except deduction guides). Fixes:
   (`#59827 `_)
 
+- Clang now immediately instantiates function template specializations
+  at the end of the definition of the corresponding function template
+  when the definition appears after the first point of instantiation.
+  (`#73232 `_)
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index f7c9d0e2e6412b7..091e1e3b4c1fd64 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -59,6 +59,7 @@
 #include "clang/Sema/TypoCorrection.h"
 #include "clang/Sema/Weak.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/SetVector.h"
 #include "llvm/ADT/SmallBitVector.h"
 #include "llvm/ADT/SmallPtrSet.h"
@@ -10078,6 +10079,12 @@ class Sema final {
   /// but have not yet been performed.
   std::deque PendingInstantiations;
 
+  /// Track constexpr functions referenced before they are (lexically) defined.
+  /// The key is the pattern, associated with a list of specialisations that
+  /// need to be instantiated when the pattern is defined.
+  llvm::DenseMap>
+  PendingInstantiationsOfConstexprEntities;
+
   /// Queue of implicit template instantiations that cannot be performed
   /// eagerly.
   SmallVector LateParsedInstantiations;
@@ -10396,6 +10403,10 @@ class Sema final {
  bool Recursive = false,
  bool DefinitionRequired = false,
  bool AtEndOfTU = false);
+
+  void InstantiateFunctionTemplateSpecializations(
+  SourceLocation PointOfInstantiation, FunctionDecl *Template);
+
   VarTemplateSpecializationDecl *BuildVarTemplateInstantiation(
   VarTemplateDecl *VarTemplate, VarDecl *FromVar,
   const TemplateArgumentList ,
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 23dd8ae15c16583..1030ba0d21b1906 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -16255,6 +16255,9 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt 
*Body,
   if (FD && !FD->isDeleted())
 checkTypeSupport(FD->getType(), FD->getLocation(), FD);
 
+  if (FD && FD->isConstexpr() && FD->isTemplated())
+InstantiateFunctionTemplateSpecializations(FD->getEndLoc(), FD);
+
   return dcl;
 }
 
diff --git 

[clang] [compiler-rt] [llvm] [flang] [clang-tools-extra] [Bazel][Clang Tidy] Include builtin headers with clang-tidy (PR #67626)

2023-11-26 Thread via cfe-commits

jathu wrote:

@chapuni can you help my understand what you mean by those two suggestions by 
providing some examples?

> construct the symlink-ed tree for one's convenience

Isn't that what we are doing in this diff? We are producing the symlinked tree 
for the tool.

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


[libc] [compiler-rt] [llvm] [lldb] [lld] [clang-tools-extra] [mlir] [clang] [openmp] [libcxx] [flang] [MLIR] Enabling Intel GPU Integration. (PR #65539)

2023-11-26 Thread Lei Zhang via cfe-commits

antiagainst wrote:

Thanks for breaking down this pull request into various smaller pieces to make 
it easier for review. I looked at various pieces; LGTM. Looking forward to see 
this being supported! :)

from @joker-eph:
> Vulkan and Spirv still have dedicated runners on the model of the original 
> cuda-runner, but I suspect this is just legacy?

from @Jianhui-Li:
> The current way of mlir-cpu-runner using the share library name to indicate 
> target-platform looks good to me: Cuda, Rocm, and SYCL with this PR. Vulkan 
> could be added same way. mlir-cpu-spirv-runner could be refactored to be 
> mlir-opt passes generating spirv binary and feed to mlir-cpu-runner.

Yup; it's legacy. +1 to the idea of unifying! I've created 
https://github.com/llvm/llvm-project/issues/73457 to track this issue to make 
it more visible. I might not have the bandwidth to work on this; if somebody 
else is interested that'd be nice! So maked it as "good first issue" (not sure 
whether I'm pushing the limit of "good first issue" but hoping to get traction 
there).


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] d033f51 - [OpenMP] atomic compare fail : Parser & AST support

2023-11-26 Thread Sandeep Kosuri via cfe-commits

Author: Sunil Kuravinakop
Date: 2023-11-26T13:34:34-06:00
New Revision: d033f51a0aafd8149f5059bc0f89ffd300093356

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

LOG: [OpenMP] atomic compare fail : Parser & AST support

Diff Revision: https://reviews.llvm.org/D123235

Added: 


Modified: 
clang/include/clang/AST/OpenMPClause.h
clang/include/clang/AST/RecursiveASTVisitor.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Basic/OpenMPKinds.def
clang/include/clang/Basic/OpenMPKinds.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/OpenMPClause.cpp
clang/lib/AST/StmtProfile.cpp
clang/lib/Basic/CMakeLists.txt
clang/lib/Basic/OpenMPKinds.cpp
clang/lib/CodeGen/CGStmtOpenMP.cpp
clang/lib/Parse/ParseOpenMP.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/test/OpenMP/atomic_ast_print.cpp
clang/test/OpenMP/atomic_messages.cpp
clang/tools/libclang/CIndex.cpp
flang/lib/Semantics/check-omp-structure.cpp
llvm/include/llvm/Frontend/OpenMP/OMP.td

Removed: 




diff  --git a/clang/include/clang/AST/OpenMPClause.h 
b/clang/include/clang/AST/OpenMPClause.h
index 51155e63dcb8f7d..924ca189381ba86 100644
--- a/clang/include/clang/AST/OpenMPClause.h
+++ b/clang/include/clang/AST/OpenMPClause.h
@@ -2513,6 +2513,89 @@ class OMPRelaxedClause final : public OMPClause {
   }
 };
 
+/// This represents 'fail' clause in the '#pragma omp atomic'
+/// directive.
+///
+/// \code
+/// #pragma omp atomic compare fail
+/// \endcode
+/// In this example directive '#pragma omp atomic compare' has 'fail' clause.
+class OMPFailClause final : public OMPClause {
+
+  // FailParameter is a memory-order-clause. Storing the ClauseKind is
+  // sufficient for our purpose.
+  OpenMPClauseKind FailParameter = llvm::omp::Clause::OMPC_unknown;
+  SourceLocation FailParameterLoc;
+  SourceLocation LParenLoc;
+
+  friend class OMPClauseReader;
+
+  /// Sets the location of '(' in fail clause.
+  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
+
+  /// Sets the location of memoryOrder clause argument in fail clause.
+  void setFailParameterLoc(SourceLocation Loc) { FailParameterLoc = Loc; }
+
+  /// Sets the mem_order clause for 'atomic compare fail' directive.
+  void setFailParameter(OpenMPClauseKind FailParameter) {
+this->FailParameter = FailParameter;
+assert(checkFailClauseParameter(FailParameter) &&
+   "Invalid fail clause parameter");
+  }
+
+public:
+  /// Build 'fail' clause.
+  ///
+  /// \param StartLoc Starting location of the clause.
+  /// \param EndLoc Ending location of the clause.
+  OMPFailClause(SourceLocation StartLoc, SourceLocation EndLoc)
+  : OMPClause(llvm::omp::OMPC_fail, StartLoc, EndLoc) {}
+
+  OMPFailClause(OpenMPClauseKind FailParameter, SourceLocation 
FailParameterLoc,
+SourceLocation StartLoc, SourceLocation LParenLoc,
+SourceLocation EndLoc)
+  : OMPClause(llvm::omp::OMPC_fail, StartLoc, EndLoc),
+FailParameterLoc(FailParameterLoc), LParenLoc(LParenLoc) {
+
+setFailParameter(FailParameter);
+  }
+
+  /// Build an empty clause.
+  OMPFailClause()
+  : OMPClause(llvm::omp::OMPC_fail, SourceLocation(), SourceLocation()) {}
+
+  child_range children() {
+return child_range(child_iterator(), child_iterator());
+  }
+
+  const_child_range children() const {
+return const_child_range(const_child_iterator(), const_child_iterator());
+  }
+
+  child_range used_children() {
+return child_range(child_iterator(), child_iterator());
+  }
+  const_child_range used_children() const {
+return const_child_range(const_child_iterator(), const_child_iterator());
+  }
+
+  static bool classof(const OMPClause *T) {
+return T->getClauseKind() == llvm::omp::OMPC_fail;
+  }
+
+  /// Gets the location of '(' (for the parameter) in fail clause.
+  SourceLocation getLParenLoc() const {
+return LParenLoc;
+  }
+
+  /// Gets the location of Fail Parameter (type memory-order-clause) in
+  /// fail clause.
+  SourceLocation getFailParameterLoc() const { return FailParameterLoc; }
+
+  /// Gets the parameter (type memory-order-clause) in Fail clause.
+  OpenMPClauseKind getFailParameter() const { return FailParameter; }
+};
+
 /// This represents clause 'private' in the '#pragma omp ...' directives.
 ///
 /// \code

diff  --git a/clang/include/clang/AST/RecursiveASTVisitor.h 
b/clang/include/clang/AST/RecursiveASTVisitor.h
index 53bc15e1b19f668..c501801b95bd955 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -3398,6 +3398,11 @@ bool 

[mlir] [flang] [clang-tools-extra] [lldb] [llvm] [libc] [lld] [compiler-rt] [libcxx] [clang] [MLIR] Enable GPU Dialect to SYCL runtime integration (PR #71430)

2023-11-26 Thread Lei Zhang via cfe-commits

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

LGTM regarding SPIR-V. But please address comments from others. :)

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


[clang] [clang-format] Add BreakConcatenatedStrings option (PR #73432)

2023-11-26 Thread Björn Schäpers via cfe-commits

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


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


[clang] [clang-format] Add BreakConcatenatedStrings option (PR #73432)

2023-11-26 Thread Björn Schäpers via cfe-commits


@@ -2088,6 +2088,19 @@ struct FormatStyle {
   /// \version 3.7
   bool BreakBeforeTernaryOperators;
 
+  /// Break between concatenated string literals in C, C++, and Objective-C.

HazardyKnusperkeks wrote:

Why limited to that languages?

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


[clang] [clang-format] Add BreakConcatenatedStrings option (PR #73432)

2023-11-26 Thread Björn Schäpers via cfe-commits

https://github.com/HazardyKnusperkeks edited 
https://github.com/llvm/llvm-project/pull/73432
___
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 formating `#define A x:` (PR #73220)

2023-11-26 Thread Björn Schäpers via cfe-commits

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


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


[clang] [Driver] Allow -e entry but reject -eentry (PR #72804)

2023-11-26 Thread Brad Smith via cfe-commits

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


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


[clang] [flang] [flang][Driver] Let the linker fail on multiple definitions of main() (PR #73124)

2023-11-26 Thread Andrzej Warzyński via cfe-commits

banach-space wrote:

> > LGTM, thank you for taking care of this 
> > Dare I ask - what's "dupes"? I only found 
> > [dupe](https://dictionary.cambridge.org/dictionary/english/dupe). Also, 
> > please wait for @kiranchandramohan to approve before merging this :)
> 
> I used "dupes" in the sense of being fooled. I can of course still change the 
> name to something like "main_linktime_duplicate.f90" or the likes.

Right, "dupes" wasn't that obvious to me :) I would probably go for your other 
suggestion or just plain "duplicate_main.f90". Either would be a bit more 
descriptive IMHO  .

Thanks again for addressing my comments and for this contribution!

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


[clang] [flang] [flang][Driver] Let the linker fail on multiple definitions of main() (PR #73124)

2023-11-26 Thread Andrzej Warzyński via cfe-commits


@@ -0,0 +1,15 @@
+! UNSUPPORTED: system-windows
+
+! RUN: %flang -x ir -o %t.c-object -c %S/Inputs/main_dupes.ll
+! RUN: %flang -o %t -c %s
+! RUN: not %flang -o %t.exe %t %t.c-object 2>&1

banach-space wrote:

That was just a nit - I am happy if you keep things as is  !

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


[clang] [flang] [flang][Driver] Let the linker fail on multiple definitions of main() (PR #73124)

2023-11-26 Thread Andrzej Warzyński via cfe-commits

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


[clang] [clang] Non-object types are non-trivially relocatable (PR #69734)

2023-11-26 Thread Amirreza Ashouri via cfe-commits

AMP999 wrote:

> LGTM, thanks!

You're welcome!

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


[clang] [clang-format] Add BreakConcatenatedStrings option (PR #73432)

2023-11-26 Thread via cfe-commits

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


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


[clang] fix: C++ empty record with align lead to va_list out of sync (PR #72197)

2023-11-26 Thread via cfe-commits

hstk30-hw wrote:

OK, just delete the 

`return ABIArgInfo::getDirect(llvm::Type::getInt8Ty(getVMContext()));` 

from the empty struct codepath, let it fall through to the main path.
Check it again, plz.



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


[clang] [Driver] Add the --gcc-triple option (PR #73214)

2023-11-26 Thread Tom Stellard via cfe-commits

https://github.com/tstellar updated 
https://github.com/llvm/llvm-project/pull/73214

>From 72f6f3a611f237f71ce02cfb79620257a9e2d827 Mon Sep 17 00:00:00 2001
From: Tom Stellard 
Date: Thu, 16 Nov 2023 05:11:04 +
Subject: [PATCH 1/2] [Driver] Add the --gcc-triple option

When --gcc-triple is used, the driver will search for the 'best' gcc
installation that has the given triple.  This is useful for
distributions that want clang to use a specific gcc triple, but do
not want to pin to a specific version as would be required by
using --gcc-install-dir.  Having clang linked to a specific gcc version
can cause clang to stop working when the version of gcc installed on
the system gets updated.
---
 clang/include/clang/Driver/Options.td | 2 ++
 clang/lib/Driver/ToolChains/Gnu.cpp   | 8 
 .../usr/lib/gcc/x86_64-linux-gnu/13/crtbegin.o| 0
 .../usr/lib/gcc/x86_64-linux-gnu/13/crtend.o  | 0
 .../fedora_39_tree/usr/lib/gcc/x86_64-linux-gnu/13/crti.o | 0
 .../fedora_39_tree/usr/lib/gcc/x86_64-linux-gnu/13/crtn.o | 0
 .../usr/lib/gcc/x86_64-redhat-linux/13/crtbegin.o | 0
 .../usr/lib/gcc/x86_64-redhat-linux/13/crtend.o   | 0
 .../usr/lib/gcc/x86_64-redhat-linux/13/crti.o | 0
 .../usr/lib/gcc/x86_64-redhat-linux/13/crtn.o | 0
 clang/test/Driver/gcc-prefix.cpp  | 8 
 11 files changed, 18 insertions(+)
 create mode 100644 
clang/test/Driver/Inputs/fedora_39_tree/usr/lib/gcc/x86_64-linux-gnu/13/crtbegin.o
 create mode 100644 
clang/test/Driver/Inputs/fedora_39_tree/usr/lib/gcc/x86_64-linux-gnu/13/crtend.o
 create mode 100644 
clang/test/Driver/Inputs/fedora_39_tree/usr/lib/gcc/x86_64-linux-gnu/13/crti.o
 create mode 100644 
clang/test/Driver/Inputs/fedora_39_tree/usr/lib/gcc/x86_64-linux-gnu/13/crtn.o
 create mode 100644 
clang/test/Driver/Inputs/fedora_39_tree/usr/lib/gcc/x86_64-redhat-linux/13/crtbegin.o
 create mode 100644 
clang/test/Driver/Inputs/fedora_39_tree/usr/lib/gcc/x86_64-redhat-linux/13/crtend.o
 create mode 100644 
clang/test/Driver/Inputs/fedora_39_tree/usr/lib/gcc/x86_64-redhat-linux/13/crti.o
 create mode 100644 
clang/test/Driver/Inputs/fedora_39_tree/usr/lib/gcc/x86_64-redhat-linux/13/crtn.o
 create mode 100644 clang/test/Driver/gcc-prefix.cpp

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index b2f2bcb6ac37910..79ced47150b455d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -773,6 +773,8 @@ def gcc_install_dir_EQ : Joined<["--"], "gcc-install-dir=">,
 def gcc_toolchain : Joined<["--"], "gcc-toolchain=">, Flags<[NoXarchOption]>,
   HelpText<"Specify a directory where Clang can find 'include' and 
'lib{,32,64}/gcc{,-cross}/$triple/$version'. "
   "Clang will use the GCC installation with the largest version">;
+def gcc_triple_EQ : Joined<["--"], "gcc-triple=">,
+  HelpText<"Search for the GCC installation with the specified triple.">;
 def CC : Flag<["-"], "CC">, Visibility<[ClangOption, CC1Option]>,
   Group,
 HelpText<"Include comments from within macros in preprocessed output">,
diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index 9fb99145d3b909e..44b92a879a3a8c1 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -2130,6 +2130,14 @@ void Generic_GCC::GCCInstallationDetector::init(
 return;
   }
 
+  // If --gcc-triple is specified use this instead of trying to
+  // auto-detect a triple.
+  if (const Arg *A = 
Args.getLastArg(clang::driver::options::OPT_gcc_triple_EQ)) {
+StringRef GCCTriple = A->getValue();
+CandidateTripleAliases.clear();
+CandidateTripleAliases.push_back(GCCTriple);
+  }
+
   // Compute the set of prefixes for our search.
   SmallVector Prefixes;
   StringRef GCCToolchainDir = getGCCToolchainDir(Args, D.SysRoot);
diff --git 
a/clang/test/Driver/Inputs/fedora_39_tree/usr/lib/gcc/x86_64-linux-gnu/13/crtbegin.o
 
b/clang/test/Driver/Inputs/fedora_39_tree/usr/lib/gcc/x86_64-linux-gnu/13/crtbegin.o
new file mode 100644
index 000..e69de29bb2d1d64
diff --git 
a/clang/test/Driver/Inputs/fedora_39_tree/usr/lib/gcc/x86_64-linux-gnu/13/crtend.o
 
b/clang/test/Driver/Inputs/fedora_39_tree/usr/lib/gcc/x86_64-linux-gnu/13/crtend.o
new file mode 100644
index 000..e69de29bb2d1d64
diff --git 
a/clang/test/Driver/Inputs/fedora_39_tree/usr/lib/gcc/x86_64-linux-gnu/13/crti.o
 
b/clang/test/Driver/Inputs/fedora_39_tree/usr/lib/gcc/x86_64-linux-gnu/13/crti.o
new file mode 100644
index 000..e69de29bb2d1d64
diff --git 
a/clang/test/Driver/Inputs/fedora_39_tree/usr/lib/gcc/x86_64-linux-gnu/13/crtn.o
 
b/clang/test/Driver/Inputs/fedora_39_tree/usr/lib/gcc/x86_64-linux-gnu/13/crtn.o
new file mode 100644
index 000..e69de29bb2d1d64
diff --git 

[clang] [clang] Non-object types are non-trivially relocatable (PR #69734)

2023-11-26 Thread via cfe-commits

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

LGTM, thanks!

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


[clang-tools-extra] [llvm] [clang] Fix #41439: Update the documentation with the correct information. (PR #69377)

2023-11-26 Thread via cfe-commits

https://github.com/Da-Viper updated 
https://github.com/llvm/llvm-project/pull/69377

>From 0e0a3e7ad1a0a7098e05a5164413369eaa58c55b Mon Sep 17 00:00:00 2001
From: Ezike Ebuka 
Date: Tue, 17 Oct 2023 20:49:47 +0100
Subject: [PATCH 1/4] Fix #41439: Update the documentation with the correct
 information.

---
 .../clang-tidy/checks/readability/named-parameter.rst| 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/readability/named-parameter.rst 
b/clang-tools-extra/docs/clang-tidy/checks/readability/named-parameter.rst
index 8d28c0aa02169a7..7e7099b3df251d1 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/readability/named-parameter.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/readability/named-parameter.rst
@@ -10,7 +10,12 @@ Guide:
 
 
https://google.github.io/styleguide/cppguide.html#Function_Declarations_and_Definitions
 
-All parameters should be named, with identical names in the declaration and
-implementation.
+A parameter name may be omitted only if the parameter is not used in the
+function's definition.
+
+.. code-block:: c++
+int doingSomething(int a, int b, int) {  // Ok: the third paramet is not used
+return a + b;
+}
 
 Corresponding cpplint.py check name: `readability/function`.

>From 9c6bb278d10264d3a47752062e754dba5a372cec Mon Sep 17 00:00:00 2001
From: Ezike Ebuka 
Date: Sat, 11 Nov 2023 20:27:05 +
Subject: [PATCH 2/4] Fix: Add the recommended explanation

---
 .../docs/clang-tidy/checks/readability/named-parameter.rst| 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/readability/named-parameter.rst 
b/clang-tools-extra/docs/clang-tidy/checks/readability/named-parameter.rst
index 7e7099b3df251d1..603a186862451be 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/readability/named-parameter.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/readability/named-parameter.rst
@@ -10,8 +10,8 @@ Guide:
 
 
https://google.github.io/styleguide/cppguide.html#Function_Declarations_and_Definitions
 
-A parameter name may be omitted only if the parameter is not used in the
-function's definition.
+All parameters should have the same name in both the function declaration and 
definition.
+If a parameter is not utilized, its name can be commented out in a function 
definition.
 
 .. code-block:: c++
 int doingSomething(int a, int b, int) {  // Ok: the third paramet is not used

>From 5a2d5b844958b2e503d634a162d6fb9589ddaa4c Mon Sep 17 00:00:00 2001
From: Ezike Ebuka 
Date: Sun, 26 Nov 2023 13:16:10 +
Subject: [PATCH 4/4] Update: the documentation with the correct information

---
 .../clang-tidy/checks/readability/named-parameter.rst  | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/readability/named-parameter.rst 
b/clang-tools-extra/docs/clang-tidy/checks/readability/named-parameter.rst
index 603a186862451be..73677a48605f495 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/readability/named-parameter.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/readability/named-parameter.rst
@@ -14,8 +14,12 @@ All parameters should have the same name in both the 
function declaration and de
 If a parameter is not utilized, its name can be commented out in a function 
definition.
 
 .. code-block:: c++
-int doingSomething(int a, int b, int) {  // Ok: the third paramet is not used
-return a + b;
-}
+
+int doingSomething(int a, int b, int c);
+
+int doingSomething(int a, int b, int /*c*/) {
+// Ok: the third param is not used
+return a + b;
+}
 
 Corresponding cpplint.py check name: `readability/function`.

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


[clang] [clang] Non-object types are non-trivially relocatable (PR #69734)

2023-11-26 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/69734

>From befa9931fb8c9e52bb05a9075dfbea7116ff14ea Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sun, 26 Nov 2023 15:06:32 +0330
Subject: [PATCH] [clang] Non-object types are non-trivially relocatable

Both active C++ proposals (P1144 and P2786) agree that
`is_trivially_relocatable_v` and `is_trivially_relocatable_v`
should be false, not true. Only complete object types
can be trivially relocatable.

Fixes #67498
---
 clang/docs/ReleaseNotes.rst   |  3 +++
 clang/lib/AST/Type.cpp|  2 ++
 clang/test/SemaCXX/type-traits-incomplete.cpp |  8 +++-
 clang/test/SemaCXX/type-traits-nonobject.cpp  | 16 
 4 files changed, 28 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/type-traits-nonobject.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 29a06d0f713f588..3de99618158c94a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -617,6 +617,9 @@ Bug Fixes in This Version
 - Fix crash during code generation of C++ coroutine initial suspend when the 
return
   type of await_resume is not trivially destructible.
   Fixes (`#63803 `_)
+- ``__is_trivially_relocatable`` no longer returns true for non-object types
+  such as references and functions.
+  Fixes (`#67498 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index c8e452e2feab0bf..160a725939ccd4c 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2649,6 +2649,8 @@ bool QualType::isTriviallyRelocatableType(const 
ASTContext ) const {
 
   if (BaseElementType->isIncompleteType()) {
 return false;
+  } else if (!BaseElementType->isObjectType()) {
+return false;
   } else if (const auto *RD = BaseElementType->getAsRecordDecl()) {
 return RD->canPassInRegisters();
   } else {
diff --git a/clang/test/SemaCXX/type-traits-incomplete.cpp 
b/clang/test/SemaCXX/type-traits-incomplete.cpp
index c0a520e167698af..3e341d648244075 100644
--- a/clang/test/SemaCXX/type-traits-incomplete.cpp
+++ b/clang/test/SemaCXX/type-traits-incomplete.cpp
@@ -1,8 +1,14 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s 
 
-struct S; // expected-note 2 {{forward declaration of 'S'}}
+struct S; // expected-note 6 {{forward declaration of 'S'}}
 
 void f() {
   __is_pod(S); // expected-error{{incomplete type 'S' used in type trait 
expression}}
   __is_pod(S[]); // expected-error{{incomplete type 'S' used in type trait 
expression}}
+
+  __is_trivially_copyable(S); // expected-error{{incomplete type 'S' used in 
type trait expression}}
+  __is_trivially_copyable(S[]); // expected-error{{incomplete type 'S' used in 
type trait expression}}
+
+  __is_trivially_relocatable(S); // expected-error{{incomplete type 'S' used 
in type trait expression}}
+  __is_trivially_relocatable(S[]); // expected-error{{incomplete type 'S' used 
in type trait expression}}
 }
diff --git a/clang/test/SemaCXX/type-traits-nonobject.cpp 
b/clang/test/SemaCXX/type-traits-nonobject.cpp
new file mode 100644
index 000..c9e3c30e5533d48
--- /dev/null
+++ b/clang/test/SemaCXX/type-traits-nonobject.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
+
+// expected-no-diagnostics
+
+static_assert(!__is_pod(void), "");
+static_assert(!__is_pod(int&), "");
+static_assert(!__is_pod(int()), "");
+
+static_assert(!__is_trivially_copyable(void), "");
+static_assert(!__is_trivially_copyable(int&), "");
+static_assert(!__is_trivially_copyable(int()), "");
+
+static_assert(!__is_trivially_relocatable(void), "");
+static_assert(!__is_trivially_relocatable(int&), "");
+static_assert(!__is_trivially_relocatable(int()), "");

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


[flang] [clang-tools-extra] [llvm] [clang] [compiler-rt] [Bazel][Clang Tidy] Include builtin headers with clang-tidy (PR #67626)

2023-11-26 Thread NAKAMURA Takumi via cfe-commits

chapuni wrote:

I still think this is not a right way to control Bazel's build directory tree.

IMO, we should publish the tree with the archive (with filegroup), or produce 
the utility shell script to construct the symlink-ed tree for one's convenience.

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


[clang-tools-extra] [clangd] Resolve the dependent type from its single instantiation. Take 1 (PR #71279)

2023-11-26 Thread Younan Zhang via cfe-commits

zyn0217 wrote:

> I also discovered some complications related to nested templates, and I have 
> some thoughts on how to resolve them, but I'm going to suggest that we start 
> with getting a simple case (e.g. just one level of templates, no nested 
> templates) to work, and then tackle nested templates as a next step.

Oops, I replied too quickly and I should have noticed this paragraph. Does my 
previous comment elaborate on the same issue you've encountered? Could you 
kindly share your thoughts more?

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


[clang-tools-extra] [clangd] Resolve the dependent type from its single instantiation. Take 1 (PR #71279)

2023-11-26 Thread Younan Zhang via cfe-commits

zyn0217 wrote:

Thank you again for bothering with this, and sorry for not responding for over 
a week.

Just now, I replicated the experimentation

> I've done some local experimentation, and what I'm seeing is that 
> `TemplateTypeParmDecl::getDeclContext()` does return the FunctionDecl or 
> CXXRecordDecl which owns the template parameter.

 and had to admit that I was wrong previously. Something must be wrong with my 
recollection, but I could clearly remember that I'd run into the same pitfall 
my first time. (I was about to write the comment to highlight this, but soon, I 
gave up taking this approach since it looks more constricted than I thought. 
And here I'm explaining it.)

> One tricky thing I found is that when starting from a template parameter 
> type, it's important to use dyn_cast(T) rather than 
> T->getAs(); the latter does more than just cast, it 
> returns the canonical type whose associated Decl is null.

The contrived example involving template template parameter is one obstruction; 
Another more common example could be such. (Which is simplified from the test 
case):

```cpp
template 
struct Outer {
  template 
  void foo(U arg) {
 arg.fo^o();
  }
};

struct Widget {
  void foo();
};

Outer().foo(Widget());
```

Here, we want to find the only instantiation before locating `foo().` Which is 
`Outer::foo.` To locate that, we shall find the templated Decl for 
`foo`, which could be done by conducting the `ParmVarDecl -> 
TemplateParmVarDecl -> getDeclContext -> FunctionTemplateDecl` dance. 
Everything goes well until the specialization set for the 
`FunctionTemplateDecl` is **empty**. Hence, our `getOnlyInstantiation` returns 
null, which is crazy!

This is because when clang performs the instantiation for member templates, it 
creates a new `FunctionTemplateDecl` from the primary template (i.e. where we 
start from) and links the instantiation declaration to that new `Decl`.

https://github.com/llvm/llvm-project/blob/1449b349ac4072adb1f593234c1d6f67986d3b6a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp#L2184-L2203

And what makes it worse is, as of now, we don't have any approach to retrieve 
the new templated `Decl` from the primary `Decl`:

https://github.com/llvm/llvm-project/blob/1449b349ac4072adb1f593234c1d6f67986d3b6a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp#L4789-L4803

("// FIXME: New needs a pointer to Tmpl", I was quite frustrated when I read 
it!)

(This patch first walks up the `DeclContext` to collect the very outer `Decl` 
for templates; then, the visitor could access the later-created template decl 
and its instantiation from the enclosing template. Again, I didn't realize the 
visitor resolved this issue this way (by accident), so I'm sorry for not being 
so straightforward.)

> The implementation of "Approach 2" could look similar to the current 
> InstantiatedDeclVisitor in the patch, except the node type we are searching 
> for is not limited to a Decl, it can also be other node types like Stmt etc.

Exactly. And this is why the patch is marked as "Take 1" :)

> However, the entry point to the check can be the same (e.g. for resolving a 
> dependent member expr, we'd want to do the "only instantiation" check in the 
> same cases where we call HeuristicResolver::resolveMemberExpr() from external 
> code), so the functionality could still live in HeuristicResolver for 
> organizational purposes.

Yeah, I'd love to extend the HeuristicResolver to make it more accurate and not 
just dependent on the mere name lookup.

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


[clang] [clang-format] Add BreakConcatenatedStrings option (PR #73432)

2023-11-26 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: Owen Pan (owenca)


Changes

Closes #70451.

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


7 Files Affected:

- (modified) clang/docs/ClangFormatStyleOptions.rst (+15) 
- (modified) clang/docs/ReleaseNotes.rst (+1) 
- (modified) clang/include/clang/Format/Format.h (+14) 
- (modified) clang/lib/Format/Format.cpp (+2) 
- (modified) clang/lib/Format/TokenAnnotator.cpp (+1-2) 
- (modified) clang/unittests/Format/ConfigParseTest.cpp (+1) 
- (modified) clang/unittests/Format/FormatTest.cpp (+14) 


``diff
diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index ff424828ff63cdb..4ff9293b3de7a03 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -2761,6 +2761,21 @@ the configuration (without a prefix: ``Auto``).
  firstValue :
  SecondValueVeryVeryVeryVeryLong;
 
+.. _BreakConcatenatedStrings:
+
+**BreakConcatenatedStrings** (``Boolean``) :versionbadge:`clang-format 18` 
:ref:`¶ `
+  Break between concatenated string literals in C, C++, and Objective-C.
+
+  .. code-block:: c++
+
+ true:
+ return "Code"
+"\0\52\26\55\55\0"
+"x013"
+"\02\xBA";
+ false:
+ return "Code" "\0\52\26\55\55\0" "x013" "\02\xBA";
+
 .. _BreakConstructorInitializers:
 
 **BreakConstructorInitializers** (``BreakConstructorInitializersStyle``) 
:versionbadge:`clang-format 5` :ref:`¶ `
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 52c9d6eb69617b0..3aa408496101ad3 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -884,6 +884,7 @@ clang-format
 - Add ``AllowBreakBeforeNoexceptSpecifier`` option.
 - Add ``AllowShortCompoundRequirementOnASingleLine`` option.
 - Change ``BreakAfterAttributes`` from ``Never`` to ``Leave`` in LLVM style.
+- Add ``BreakConcatenatedStrings`` option.
 
 libclang
 
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index bc412611ef62493..b5f7c16774cd96e 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2088,6 +2088,19 @@ struct FormatStyle {
   /// \version 3.7
   bool BreakBeforeTernaryOperators;
 
+  /// Break between concatenated string literals in C, C++, and Objective-C.
+  /// \code
+  ///true:
+  ///return "Code"
+  ///   "\0\52\26\55\55\0"
+  ///   "x013"
+  ///   "\02\xBA";
+  ///false:
+  ///return "Code" "\0\52\26\55\55\0" "x013" "\02\xBA";
+  /// \endcode
+  /// \version 18
+  bool BreakConcatenatedStrings;
+
   /// Different ways to break initializers.
   enum BreakConstructorInitializersStyle : int8_t {
 /// Break constructor initializers before the colon and after the commas.
@@ -4753,6 +4766,7 @@ struct FormatStyle {
BreakBeforeConceptDeclarations == R.BreakBeforeConceptDeclarations 
&&
BreakBeforeInlineASMColon == R.BreakBeforeInlineASMColon &&
BreakBeforeTernaryOperators == R.BreakBeforeTernaryOperators &&
+   BreakConcatenatedStrings == R.BreakConcatenatedStrings &&
BreakConstructorInitializers == R.BreakConstructorInitializers &&
BreakInheritanceList == R.BreakInheritanceList &&
BreakStringLiterals == R.BreakStringLiterals &&
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index e1abcac5604a410..025bca2ea9f7365 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -978,6 +978,7 @@ template <> struct MappingTraits {
Style.BreakBeforeInlineASMColon);
 IO.mapOptional("BreakBeforeTernaryOperators",
Style.BreakBeforeTernaryOperators);
+IO.mapOptional("BreakConcatenatedStrings", Style.BreakConcatenatedStrings);
 IO.mapOptional("BreakConstructorInitializers",
Style.BreakConstructorInitializers);
 IO.mapOptional("BreakInheritanceList", Style.BreakInheritanceList);
@@ -1485,6 +1486,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind 
Language) {
   LLVMStyle.BreakBeforeInlineASMColon = FormatStyle::BBIAS_OnlyMultiline;
   LLVMStyle.AllowBreakBeforeNoexceptSpecifier = FormatStyle::BBNSS_Never;
   LLVMStyle.BreakBeforeTernaryOperators = true;
+  LLVMStyle.BreakConcatenatedStrings = true;
   LLVMStyle.BreakConstructorInitializers = FormatStyle::BCIS_BeforeColon;
   LLVMStyle.BreakInheritanceList = FormatStyle::BILS_BeforeColon;
   LLVMStyle.BreakStringLiterals = true;
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index cfca7c00312aab3..17d3b48e0af8332 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -5078,8 +5078,7 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine 
,
 // it is hard to identify them in UnwrappedLineParser.
 if (!Keywords.isVerilogBegin(Right) && 

[clang] [clang-format] Add BreakConcatenatedStrings option (PR #73432)

2023-11-26 Thread Owen Pan via cfe-commits

https://github.com/owenca created 
https://github.com/llvm/llvm-project/pull/73432

Closes #70451.

>From def7bbb22cdd9269aa927d8dcf4247c88877503b Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Sat, 25 Nov 2023 23:55:11 -0800
Subject: [PATCH] [clang-format] Add BreakConcatenatedStrings option

Closes #70451.
---
 clang/docs/ClangFormatStyleOptions.rst | 15 +++
 clang/docs/ReleaseNotes.rst|  1 +
 clang/include/clang/Format/Format.h| 14 ++
 clang/lib/Format/Format.cpp|  2 ++
 clang/lib/Format/TokenAnnotator.cpp|  3 +--
 clang/unittests/Format/ConfigParseTest.cpp |  1 +
 clang/unittests/Format/FormatTest.cpp  | 14 ++
 7 files changed, 48 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index ff424828ff63cdb..4ff9293b3de7a03 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -2761,6 +2761,21 @@ the configuration (without a prefix: ``Auto``).
  firstValue :
  SecondValueVeryVeryVeryVeryLong;
 
+.. _BreakConcatenatedStrings:
+
+**BreakConcatenatedStrings** (``Boolean``) :versionbadge:`clang-format 18` 
:ref:`¶ `
+  Break between concatenated string literals in C, C++, and Objective-C.
+
+  .. code-block:: c++
+
+ true:
+ return "Code"
+"\0\52\26\55\55\0"
+"x013"
+"\02\xBA";
+ false:
+ return "Code" "\0\52\26\55\55\0" "x013" "\02\xBA";
+
 .. _BreakConstructorInitializers:
 
 **BreakConstructorInitializers** (``BreakConstructorInitializersStyle``) 
:versionbadge:`clang-format 5` :ref:`¶ `
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 52c9d6eb69617b0..3aa408496101ad3 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -884,6 +884,7 @@ clang-format
 - Add ``AllowBreakBeforeNoexceptSpecifier`` option.
 - Add ``AllowShortCompoundRequirementOnASingleLine`` option.
 - Change ``BreakAfterAttributes`` from ``Never`` to ``Leave`` in LLVM style.
+- Add ``BreakConcatenatedStrings`` option.
 
 libclang
 
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index bc412611ef62493..b5f7c16774cd96e 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2088,6 +2088,19 @@ struct FormatStyle {
   /// \version 3.7
   bool BreakBeforeTernaryOperators;
 
+  /// Break between concatenated string literals in C, C++, and Objective-C.
+  /// \code
+  ///true:
+  ///return "Code"
+  ///   "\0\52\26\55\55\0"
+  ///   "x013"
+  ///   "\02\xBA";
+  ///false:
+  ///return "Code" "\0\52\26\55\55\0" "x013" "\02\xBA";
+  /// \endcode
+  /// \version 18
+  bool BreakConcatenatedStrings;
+
   /// Different ways to break initializers.
   enum BreakConstructorInitializersStyle : int8_t {
 /// Break constructor initializers before the colon and after the commas.
@@ -4753,6 +4766,7 @@ struct FormatStyle {
BreakBeforeConceptDeclarations == R.BreakBeforeConceptDeclarations 
&&
BreakBeforeInlineASMColon == R.BreakBeforeInlineASMColon &&
BreakBeforeTernaryOperators == R.BreakBeforeTernaryOperators &&
+   BreakConcatenatedStrings == R.BreakConcatenatedStrings &&
BreakConstructorInitializers == R.BreakConstructorInitializers &&
BreakInheritanceList == R.BreakInheritanceList &&
BreakStringLiterals == R.BreakStringLiterals &&
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index e1abcac5604a410..025bca2ea9f7365 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -978,6 +978,7 @@ template <> struct MappingTraits {
Style.BreakBeforeInlineASMColon);
 IO.mapOptional("BreakBeforeTernaryOperators",
Style.BreakBeforeTernaryOperators);
+IO.mapOptional("BreakConcatenatedStrings", Style.BreakConcatenatedStrings);
 IO.mapOptional("BreakConstructorInitializers",
Style.BreakConstructorInitializers);
 IO.mapOptional("BreakInheritanceList", Style.BreakInheritanceList);
@@ -1485,6 +1486,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind 
Language) {
   LLVMStyle.BreakBeforeInlineASMColon = FormatStyle::BBIAS_OnlyMultiline;
   LLVMStyle.AllowBreakBeforeNoexceptSpecifier = FormatStyle::BBNSS_Never;
   LLVMStyle.BreakBeforeTernaryOperators = true;
+  LLVMStyle.BreakConcatenatedStrings = true;
   LLVMStyle.BreakConstructorInitializers = FormatStyle::BCIS_BeforeColon;
   LLVMStyle.BreakInheritanceList = FormatStyle::BILS_BeforeColon;
   LLVMStyle.BreakStringLiterals = true;
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index cfca7c00312aab3..17d3b48e0af8332 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -5078,8 +5078,7 @@