[PATCH] D156370: [clang-format] Fix bug with parsing of function/variable names.

2023-10-21 Thread Owen Pan via Phabricator via cfe-commits
owenpan added a comment.

In D156370#4540257 , 
@HazardyKnusperkeks wrote:

> Yes that stuff. Tests are in: 
> https://github.com/llvm/llvm-project/blob/main/clang/unittests/Format/TokenAnnotatorTest.cpp
> If there is none that matches, just create a new one.

@gedare, I think this is the only missing piece for your patch to get accepted. 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156370

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


[clang] [InstCombine] Convert or concat to fshl if opposite or concat exists (PR #68502)

2023-10-21 Thread via cfe-commits


@@ -2840,6 +2841,46 @@ static Instruction *matchFunnelShift(Instruction , 
InstCombinerImpl ) {
   return nullptr;
 
 FShiftArgs = {ShVal0, ShVal1, ShAmt};
+  } else if (isa(Or0) || isa(Or1)) {
+// If there are two 'or' instructions concat variables in opposite order,
+// the latter one can be safely convert to fshl.
+//
+// LowHigh = or (shl (zext Low), Width - ZextHighShlAmt), (zext High)
+// HighLow = or (shl (zext High), ZextHighShlAmt), (zext Low)
+// ->
+// HighLow = fshl LowHigh, LowHigh, ZextHighShlAmt
+if (!isa(Or1))
+  std::swap(Or0, Or1);
+
+Value *High, *ZextHigh, *Low;
+const APInt *ZextHighShlAmt;
+if (!match(Or0,
+   m_OneUse(m_Shl(m_Value(ZextHigh), m_APInt(ZextHighShlAmt)
+  return nullptr;
+
+if (!match(Or1, m_ZExt(m_Value(Low))) ||
+!match(ZextHigh, m_ZExt(m_Value(High

goldsteinn wrote:

Ahh, I see, although could handle masking `and`. Really its just a knownbits 
check though.

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


[clang-tools-extra] [InstCombine] Convert or concat to fshl if opposite or concat exists (PR #68502)

2023-10-21 Thread via cfe-commits


@@ -2840,6 +2841,46 @@ static Instruction *matchFunnelShift(Instruction , 
InstCombinerImpl ) {
   return nullptr;
 
 FShiftArgs = {ShVal0, ShVal1, ShAmt};
+  } else if (isa(Or0) || isa(Or1)) {
+// If there are two 'or' instructions concat variables in opposite order,
+// the latter one can be safely convert to fshl.
+//
+// LowHigh = or (shl (zext Low), Width - ZextHighShlAmt), (zext High)
+// HighLow = or (shl (zext High), ZextHighShlAmt), (zext Low)
+// ->
+// HighLow = fshl LowHigh, LowHigh, ZextHighShlAmt
+if (!isa(Or1))
+  std::swap(Or0, Or1);
+
+Value *High, *ZextHigh, *Low;
+const APInt *ZextHighShlAmt;
+if (!match(Or0,
+   m_OneUse(m_Shl(m_Value(ZextHigh), m_APInt(ZextHighShlAmt)
+  return nullptr;
+
+if (!match(Or1, m_ZExt(m_Value(Low))) ||
+!match(ZextHigh, m_ZExt(m_Value(High

goldsteinn wrote:

Ahh, I see, although could handle masking `and`. Really its just a knownbits 
check though.

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


[clang] a63dc79 - [Clang][OHOS] Keep ARM ABI selection logic in sync between Clang and LLVM (#68656)

2023-10-21 Thread via cfe-commits

Author: Brad Smith
Date: 2023-10-22T08:48:41+03:00
New Revision: a63dc79d113915048c932eca7732838206898e9a

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

LOG: [Clang][OHOS] Keep ARM ABI selection logic in sync between Clang and LLVM 
(#68656)

Added: 


Modified: 
clang/lib/Basic/Targets/ARM.cpp
llvm/lib/TargetParser/ARMTargetParser.cpp

Removed: 




diff  --git a/clang/lib/Basic/Targets/ARM.cpp b/clang/lib/Basic/Targets/ARM.cpp
index 1e809283748b66c..ce7e4d4639ceacb 100644
--- a/clang/lib/Basic/Targets/ARM.cpp
+++ b/clang/lib/Basic/Targets/ARM.cpp
@@ -258,6 +258,7 @@ ARMTargetInfo::ARMTargetInfo(const llvm::Triple ,
   bool IsOpenBSD = Triple.isOSOpenBSD();
   bool IsNetBSD = Triple.isOSNetBSD();
   bool IsHaiku = Triple.isOSHaiku();
+  bool IsOHOS = Triple.isOHOSFamily();
 
   // FIXME: the isOSBinFormatMachO is a workaround for identifying a 
Darwin-like
   // environment where size_t is `unsigned long` rather than `unsigned int`
@@ -324,7 +325,7 @@ ARMTargetInfo::ARMTargetInfo(const llvm::Triple ,
 default:
   if (IsNetBSD)
 setABI("apcs-gnu");
-  else if (IsFreeBSD || IsOpenBSD || IsHaiku)
+  else if (IsFreeBSD || IsOpenBSD || IsHaiku || IsOHOS)
 setABI("aapcs-linux");
   else
 setABI("aapcs");

diff  --git a/llvm/lib/TargetParser/ARMTargetParser.cpp 
b/llvm/lib/TargetParser/ARMTargetParser.cpp
index 4517f714527db15..d09992441909e01 100644
--- a/llvm/lib/TargetParser/ARMTargetParser.cpp
+++ b/llvm/lib/TargetParser/ARMTargetParser.cpp
@@ -559,6 +559,7 @@ StringRef ARM::computeDefaultTargetABI(const Triple , 
StringRef CPU) {
   case Triple::GNUEABIHF:
   case Triple::MuslEABI:
   case Triple::MuslEABIHF:
+  case Triple::OpenHOS:
 return "aapcs-linux";
   case Triple::EABIHF:
   case Triple::EABI:



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


[clang] [Clang][OHOS] Keep ARM ABI selection logic in sync between Clang and LLVM (PR #68656)

2023-10-21 Thread Pavel Kosov via cfe-commits

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


[clang] [Clang][OHOS] Keep ARM ABI selection logic in sync between Clang and LLVM (PR #68656)

2023-10-21 Thread Pavel Kosov via cfe-commits

kpdev wrote:

@brad0 Thank you for the patch, and sorry for late reply - there were wrong 
settings with notifications, won't happen again

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


[clang] [clang-format] Don't align comments over scopes (PR #68743)

2023-10-21 Thread Owen Pan via cfe-commits


@@ -1118,16 +1121,48 @@ void WhitespaceManager::alignTrailingComments() {
   }
 }
 
-// We don't want to align namespace end comments.
-const bool DontAlignThisComment =
-I > 0 && C.NewlinesBefore == 0 &&
-Changes[I - 1].Tok->is(TT_NamespaceRBrace);
-if (Style.AlignTrailingComments.Kind == FormatStyle::TCAS_Never ||
-DontAlignThisComment) {
+// We don't want to align comments which end a scope, which are here
+// identified by most closing braces.
+auto DontAlignThisComment = [](const auto *Tok) {
+  if (Tok->is(tok::semi)) {
+Tok = Tok->getPreviousNonComment();
+if (!Tok)
+  return false;
+  }
+  if (Tok->is(tok::r_paren)) {
+// Back up past the parentheses and a `TT_DoWhile` that may precede.
+Tok = Tok->MatchingParen;
+if (!Tok)
+  return false;
+Tok = Tok->getPreviousNonComment();
+if (!Tok)
+  return false;
+if (Tok->is(TT_DoWhile)) {
+  auto Prev = Tok->getPreviousNonComment();
+  if (!Prev) {
+// A do-while-loop without braces.
+return Tok->NewlinesBefore > 0;
+  }

owenca wrote:

```suggestion
  const auto *Prev = Tok->getPreviousNonComment();
  if (!Prev)
return true;
```
to cover the cases like `/**/ while (i > 0); //`.

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


[clang] [Driver][Solaris][NFC] A little bit of clean up (PR #69867)

2023-10-21 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 0b7ae41b23fc05c2ac3afc8566b8a923d7f76c45 
e2c5b620b7d527dc0ba886122a0a510c058dcd17 -- 
clang/lib/Driver/ToolChains/Solaris.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Driver/ToolChains/Solaris.cpp 
b/clang/lib/Driver/ToolChains/Solaris.cpp
index 0848441c3dbc..cd94616eef3e 100644
--- a/clang/lib/Driver/ToolChains/Solaris.cpp
+++ b/clang/lib/Driver/ToolChains/Solaris.cpp
@@ -168,8 +168,7 @@ void solaris::Linker::ConstructJob(Compilation , const 
JobAction ,
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
options::OPT_r)) {
 if (!Args.hasArg(options::OPT_shared))
-  CmdArgs.push_back(
-  Args.MakeArgString(ToolChain.GetFilePath("crt1.o")));
+  CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crt1.o")));
 
 CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crti.o")));
 
@@ -192,8 +191,7 @@ void solaris::Linker::ConstructJob(Compilation , const 
JobAction ,
 // Use values-xpg4.o for -std=c90, -std=gnu90, -std=iso9899:199409.
 if (LangStd && LangStd->getLanguage() == Language::C && !LangStd->isC99())
   values_xpg = "values-xpg4.o";
-CmdArgs.push_back(
-Args.MakeArgString(ToolChain.GetFilePath(values_xpg)));
+CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(values_xpg)));
 
 const char *crtbegin = nullptr;
 if (Args.hasArg(options::OPT_shared) || IsPIE)
@@ -279,10 +277,8 @@ void solaris::Linker::ConstructJob(Compilation , const 
JobAction ,
   crtend = "crtendS.o";
 else
   crtend = "crtend.o";
-CmdArgs.push_back(
-Args.MakeArgString(ToolChain.GetFilePath(crtend)));
-CmdArgs.push_back(
-Args.MakeArgString(ToolChain.GetFilePath("crtn.o")));
+CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crtend)));
+CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtn.o")));
   }
 
   ToolChain.addProfileRTLibs(Args, CmdArgs);

``




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


[clang] [clang][Interp] Fix scalar inits of void type (PR #69868)

2023-10-21 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/69868

None

>From 537c917cab1fe8bd8dc7dfd849bff9cd5be5efc2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sun, 22 Oct 2023 06:56:46 +0200
Subject: [PATCH] [clang][Interp] Fix scalar inits of void type

---
 clang/lib/AST/Interp/ByteCodeExprGen.cpp | 8 ++--
 clang/test/AST/Interp/literals.cpp   | 9 +
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index ed971fe0f650f22..d7c370cb3efa45c 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1571,8 +1571,12 @@ bool ByteCodeExprGen::VisitOffsetOfExpr(const 
OffsetOfExpr *E) {
 template 
 bool ByteCodeExprGen::VisitCXXScalarValueInitExpr(
 const CXXScalarValueInitExpr *E) {
-  return this->visitZeroInitializer(classifyPrim(E->getType()), E->getType(),
-E);
+  QualType Ty = E->getType();
+
+  if (Ty->isVoidType())
+return true;
+
+  return this->visitZeroInitializer(classifyPrim(Ty), Ty, E);
 }
 
 template  bool ByteCodeExprGen::discard(const Expr *E) 
{
diff --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index a83dcd234111587..fd0123e2ef55115 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -56,6 +56,15 @@ namespace ScalarTypes {
   };
   static_assert(getScalar() == First, "");
   /// FIXME: Member pointers.
+
+#if __cplusplus >= 201402L
+  constexpr void Void(int n) {
+void(n + 1);
+void();
+  }
+  constexpr int void_test = (Void(0), 1);
+  static_assert(void_test == 1, "");
+#endif
 }
 
 namespace IntegralCasts {

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


[clang] [Driver][Solaris][NFC] A little bit of clean up (PR #69867)

2023-10-21 Thread Brad Smith via cfe-commits

https://github.com/brad0 created https://github.com/llvm/llvm-project/pull/69867

None

>From e2c5b620b7d527dc0ba886122a0a510c058dcd17 Mon Sep 17 00:00:00 2001
From: Brad Smith 
Date: Sun, 22 Oct 2023 00:55:07 -0400
Subject: [PATCH] [Driver][Solaris][NFC] A little bit of clean up

---
 clang/lib/Driver/ToolChains/Solaris.cpp | 69 -
 1 file changed, 34 insertions(+), 35 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Solaris.cpp 
b/clang/lib/Driver/ToolChains/Solaris.cpp
index ecff8ddc4ee766f..0848441c3dbc603 100644
--- a/clang/lib/Driver/ToolChains/Solaris.cpp
+++ b/clang/lib/Driver/ToolChains/Solaris.cpp
@@ -87,10 +87,12 @@ void solaris::Linker::ConstructJob(Compilation , const 
JobAction ,
const InputInfoList ,
const ArgList ,
const char *LinkingOutput) const {
-  const Driver  = getToolChain().getDriver();
-  const bool IsPIE = getPIE(Args, getToolChain());
+  const auto  = static_cast(getToolChain());
+  const Driver  = ToolChain.getDriver();
+  const llvm::Triple::ArchType Arch = ToolChain.getArch();
+  const bool IsPIE = getPIE(Args, ToolChain);
+  const bool LinkerIsGnuLd = isLinkerGnuLd(ToolChain, Args);
   ArgStringList CmdArgs;
-  bool LinkerIsGnuLd = isLinkerGnuLd(getToolChain(), Args);
 
   // Demangle C++ names in errors.  GNU ld already defaults to --demangle.
   if (!LinkerIsGnuLd)
@@ -127,10 +129,6 @@ void solaris::Linker::ConstructJob(Compilation , const 
JobAction ,
 
   if (LinkerIsGnuLd) {
 // Set the correct linker emulation for 32- and 64-bit Solaris.
-const toolchains::Solaris  =
-static_cast(getToolChain());
-const llvm::Triple::ArchType Arch = ToolChain.getArch();
-
 switch (Arch) {
 case llvm::Triple::x86:
   CmdArgs.push_back("-m");
@@ -171,9 +169,9 @@ void solaris::Linker::ConstructJob(Compilation , const 
JobAction ,
options::OPT_r)) {
 if (!Args.hasArg(options::OPT_shared))
   CmdArgs.push_back(
-  Args.MakeArgString(getToolChain().GetFilePath("crt1.o")));
+  Args.MakeArgString(ToolChain.GetFilePath("crt1.o")));
 
-
CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crti.o")));
+CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crti.o")));
 
 const Arg *Std = Args.getLastArg(options::OPT_std_EQ, options::OPT_ansi);
 bool HaveAnsi = false;
@@ -188,46 +186,46 @@ void solaris::Linker::ConstructJob(Compilation , const 
JobAction ,
 // Use values-Xc.o for -ansi, -std=c*, -std=iso9899:199409.
 if (HaveAnsi || (LangStd && !LangStd->isGNUMode()))
   values_X = "values-Xc.o";
-
CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(values_X)));
+CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(values_X)));
 
 const char *values_xpg = "values-xpg6.o";
 // Use values-xpg4.o for -std=c90, -std=gnu90, -std=iso9899:199409.
 if (LangStd && LangStd->getLanguage() == Language::C && !LangStd->isC99())
   values_xpg = "values-xpg4.o";
 CmdArgs.push_back(
-Args.MakeArgString(getToolChain().GetFilePath(values_xpg)));
+Args.MakeArgString(ToolChain.GetFilePath(values_xpg)));
 
 const char *crtbegin = nullptr;
 if (Args.hasArg(options::OPT_shared) || IsPIE)
   crtbegin = "crtbeginS.o";
 else
   crtbegin = "crtbegin.o";
-
CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(crtbegin)));
+CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crtbegin)));
 // Add crtfastmath.o if available and fast math is enabled.
-getToolChain().addFastMathRuntimeIfAvailable(Args, CmdArgs);
+ToolChain.addFastMathRuntimeIfAvailable(Args, CmdArgs);
   }
 
-  getToolChain().AddFilePathLibArgs(Args, CmdArgs);
+  ToolChain.AddFilePathLibArgs(Args, CmdArgs);
 
   Args.addAllArgs(CmdArgs,
   {options::OPT_L, options::OPT_T_Group, options::OPT_r});
 
-  bool NeedsSanitizerDeps = addSanitizerRuntimes(getToolChain(), Args, 
CmdArgs);
-  AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
+  bool NeedsSanitizerDeps = addSanitizerRuntimes(ToolChain, Args, CmdArgs);
+  AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs,
options::OPT_r)) {
 if (D.CCCIsCXX()) {
-  if (getToolChain().ShouldLinkCXXStdlib(Args))
-getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
+  if (ToolChain.ShouldLinkCXXStdlib(Args))
+ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs);
   CmdArgs.push_back("-lm");
 }
 // Additional linker set-up and flags for Fortran. This is required in 
order
 // to generate executables. As Fortran runtime depends on the C runtime,
 // these dependencies need to be listed before the C runtime below.
 if (D.IsFlangMode()) {
-  addFortranRuntimeLibraryPath(getToolChain(), Args, 

[clang] [clang][Interp] Implement builtin_expect (PR #69713)

2023-10-21 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/69713

>From 1d60343ec3acb89764ab56a7035e1d7355e741ed Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Fri, 20 Oct 2023 14:16:22 +0200
Subject: [PATCH 1/2] [clang][Interp] Implement builtin_expect

---
 clang/lib/AST/Interp/InterpBuiltin.cpp| 64 +++
 clang/test/AST/Interp/builtin-functions.cpp   |  8 +++
 .../Sema/builtin-expect-with-probability.cpp  |  1 +
 3 files changed, 73 insertions(+)

diff --git a/clang/lib/AST/Interp/InterpBuiltin.cpp 
b/clang/lib/AST/Interp/InterpBuiltin.cpp
index 7552c1b88cff60c..48678b468e82ed5 100644
--- a/clang/lib/AST/Interp/InterpBuiltin.cpp
+++ b/clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -33,6 +33,19 @@ PrimType getIntPrimType(const InterpState ) {
   llvm_unreachable("Int isn't 16 or 32 bit?");
 }
 
+PrimType getLongPrimType(const InterpState ) {
+  const TargetInfo  = S.getCtx().getTargetInfo();
+  unsigned LongWidth = TI.getLongWidth();
+
+  if (LongWidth == 64)
+return PT_Sint64;
+  else if (LongWidth == 32)
+return PT_Sint32;
+  else if (LongWidth == 16)
+return PT_Sint16;
+  llvm_unreachable("long isn't 16, 32 or 64 bit?");
+}
+
 /// Peek an integer value from the stack into an APSInt.
 static APSInt peekToAPSInt(InterpStack , PrimType T, size_t Offset = 0) {
   if (Offset == 0)
@@ -59,6 +72,19 @@ static void pushInt(InterpState , int32_t Val) {
 llvm_unreachable("Int isn't 16 or 32 bit?");
 }
 
+/// Pushes \p Val to the stack, as a target-dependent 'long'.
+static void pushLong(InterpState , int64_t Val) {
+  PrimType LongType = getLongPrimType(S);
+  if (LongType == PT_Sint64)
+S.Stk.push>(Integral<64, true>::from(Val));
+  else if (LongType == PT_Sint32)
+S.Stk.push>(Integral<32, true>::from(Val));
+  else if (LongType == PT_Sint16)
+S.Stk.push>(Integral<16, true>::from(Val));
+  else
+llvm_unreachable("Long isn't 16, 32 or 64 bit?");
+}
+
 static bool retInt(InterpState , CodePtr OpPC, APValue ) {
   PrimType IntType = getIntPrimType(S);
   if (IntType == PT_Sint32)
@@ -68,6 +94,17 @@ static bool retInt(InterpState , CodePtr OpPC, APValue 
) {
   llvm_unreachable("Int isn't 16 or 32 bit?");
 }
 
+static bool retLong(InterpState , CodePtr OpPC, APValue ) {
+  PrimType LongType = getLongPrimType(S);
+  if (LongType == PT_Sint64)
+return Ret(S, OpPC, Result);
+  else if (LongType == PT_Sint32)
+return Ret(S, OpPC, Result);
+  else if (LongType == PT_Sint16)
+return Ret(S, OpPC, Result);
+  llvm_unreachable("Int isn't 16 or 32 bit?");
+}
+
 static void pushSizeT(InterpState , uint64_t Val) {
   const TargetInfo  = S.getCtx().getTargetInfo();
   unsigned SizeTWidth = TI.getTypeWidth(TI.getSizeType());
@@ -409,6 +446,27 @@ static bool interp__builtin_popcount(InterpState , 
CodePtr OpPC,
   return true;
 }
 
+// __builtin_expect(long, long) or
+// __builtin_expect_with_probability(long, long, double)
+static bool interp__builtin_expect(InterpState , CodePtr OpPC,
+   const InterpFrame *Frame,
+   const Function *Func, const CallExpr *Call) 
{
+  // The return value is simply the value of the first parameter.
+  // We ignore the probability.
+  unsigned NumArgs = Call->getNumArgs();
+  PrimType ArgT = *S.getContext().classify(Call->getArg(0)->getType());
+
+  assert(NumArgs == 2 || NumArgs == 3);
+
+  unsigned Offset = align(primSize(getLongPrimType(S))) * 2;
+  if (NumArgs == 3)
+Offset += align(primSize(PT_Float));
+
+  APSInt Val = peekToAPSInt(S.Stk, ArgT, Offset);
+  pushLong(S, Val.getSExtValue());
+  return true;
+}
+
 bool InterpretBuiltin(InterpState , CodePtr OpPC, const Function *F,
   const CallExpr *Call) {
   InterpFrame *Frame = S.Current;
@@ -534,6 +592,12 @@ bool InterpretBuiltin(InterpState , CodePtr OpPC, const 
Function *F,
   return retInt(S, OpPC, Dummy);
 break;
 
+  case Builtin::BI__builtin_expect:
+  case Builtin::BI__builtin_expect_with_probability:
+if (interp__builtin_expect(S, OpPC, Frame, F, Call))
+  return retLong(S, OpPC, Dummy);
+break;
+
   default:
 return false;
   }
diff --git a/clang/test/AST/Interp/builtin-functions.cpp 
b/clang/test/AST/Interp/builtin-functions.cpp
index 65361d67d68d578..d928b494a5204a6 100644
--- a/clang/test/AST/Interp/builtin-functions.cpp
+++ b/clang/test/AST/Interp/builtin-functions.cpp
@@ -282,3 +282,11 @@ namespace popcount {
   char popcount9[__builtin_popcountll(0xF0F0LL) == 8 ? 1 : -1];
   char popcount10[__builtin_popcountll(~0LL) == BITSIZE(long long) ? 1 : -1];
 }
+
+namespace expect {
+  constexpr int a() {
+return 12;
+  }
+  static_assert(__builtin_expect(a(),1) == 12, "");
+  static_assert(__builtin_expect_with_probability(a(), 1, 1.0) == 12, "");
+}
diff --git a/clang/test/Sema/builtin-expect-with-probability.cpp 

[clang] [clang-format] unexpected break after binOp '<<' (PR #69859)

2023-10-21 Thread Tsarkov Maksim via cfe-commits

s1Sharp wrote:

I have no way to link the issues related to the PR issue. I don't know why, but 
add a link to issue to this comment 
https://github.com/llvm/llvm-project/issues/44363 .
So, I want to start a little discussion about the solution.

I'll start with the problem - when using the BreakBeforeBinaryOperators: None 
option, I expect that the code
```C++
std::cout << "hello " << "world!";
```
with binary output operation to stream via token "<<" (tok::lessless)
clang-format output is:
```C++
std::cout << "hello "
 << "world!";
```
This was unexpected for me and unnecessary, as well as for other users who have 
already created issues.
The token '<<' is a binary operator that have link to the 
"BreakBeforeBinaryOperators" option.

1th solution is: Apply the break of the binary operator '<<' only if 
BreakBeforeBinaryOperators is [All | NonAssignment].And npt break if 
BreakBeforeBinaryOperators is None. This solution is very simple, but, in my 
opinion, violates the user api and the user's expectations of the clang-format 
program.

2th solution is: Add new option that allowing specific behaviour, such as 
"BreakAfterStreamOperator" or "BreakAfterLessLessOperator" with options [ Leave 
| NoFitLine | All ].


I am open to discussions


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


[clang] [mlir][DeadCodeAnalysis] Don't Require `RegionBranchTerminatorOpInterface` in `visitRegionTerminator()` (PR #69043)

2023-10-21 Thread Justin Fargnoli via cfe-commits

https://github.com/justinfargnoli updated 
https://github.com/llvm/llvm-project/pull/69043

>From 8f8b644792d5e26f76d98bd8ba45440443f9a260 Mon Sep 17 00:00:00 2001
From: justinfargnoli 
Date: Fri, 13 Oct 2023 18:16:45 -0700
Subject: [PATCH 1/4] Initial commit

---
 .../mlir/Analysis/DataFlow/DeadCodeAnalysis.h|  2 +-
 mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp  | 12 +++-
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/mlir/include/mlir/Analysis/DataFlow/DeadCodeAnalysis.h 
b/mlir/include/mlir/Analysis/DataFlow/DeadCodeAnalysis.h
index 7a6fea8326a58b8..ce262c3ac5291ff 100644
--- a/mlir/include/mlir/Analysis/DataFlow/DeadCodeAnalysis.h
+++ b/mlir/include/mlir/Analysis/DataFlow/DeadCodeAnalysis.h
@@ -208,7 +208,7 @@ class DeadCodeAnalysis : public DataFlowAnalysis {
   /// Visit the given terminator operation that exits a region under an
   /// operation with control-flow semantics. These are terminators with no CFG
   /// successors.
-  void visitRegionTerminator(RegionBranchTerminatorOpInterface op,
+  void visitRegionTerminator(Operation *op,
  RegionBranchOpInterface branch);
 
   /// Visit the given terminator operation that exits a callable region. These
diff --git a/mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp 
b/mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp
index d423d37b9770c69..30a862fa048f97a 100644
--- a/mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp
+++ b/mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp
@@ -259,8 +259,7 @@ LogicalResult DeadCodeAnalysis::visit(ProgramPoint point) {
   if (isRegionOrCallableReturn(op)) {
 if (auto branch = dyn_cast(op->getParentOp())) {
   // Visit the exiting terminator of a region.
-  visitRegionTerminator(cast(op),
-branch);
+  visitRegionTerminator(op, branch);
 } else if (auto callable =
dyn_cast(op->getParentOp())) {
   // Visit the exiting terminator of a callable.
@@ -379,14 +378,17 @@ void DeadCodeAnalysis::visitRegionBranchOperation(
   }
 }
 
-void DeadCodeAnalysis::visitRegionTerminator(
-RegionBranchTerminatorOpInterface op, RegionBranchOpInterface branch) {
+void DeadCodeAnalysis::visitRegionTerminator(Operation *op, 
+ RegionBranchOpInterface branch) {
   std::optional> operands = getOperandValues(op);
   if (!operands)
 return;
 
   SmallVector successors;
-  op.getSuccessorRegions(*operands, successors);
+  if (auto terminator = dyn_cast(op))
+terminator.getSuccessorRegions(*operands, successors);
+  else
+branch.getSuccessorRegions(op->getParentRegion(), successors);
 
   // Mark successor region entry blocks as executable and add this op to the
   // list of predecessors.

>From ec79bc71013c8433a83948a256b313a0f93cf826 Mon Sep 17 00:00:00 2001
From: justinfargnoli 
Date: Fri, 13 Oct 2023 18:34:11 -0700
Subject: [PATCH 2/4] Add test

---
 .../DataFlow/test-dead-code-analysis-regression.mlir | 5 +
 1 file changed, 5 insertions(+)
 create mode 100644 
mlir/test/Analysis/DataFlow/test-dead-code-analysis-regression.mlir

diff --git 
a/mlir/test/Analysis/DataFlow/test-dead-code-analysis-regression.mlir 
b/mlir/test/Analysis/DataFlow/test-dead-code-analysis-regression.mlir
new file mode 100644
index 000..70c44970519cc24
--- /dev/null
+++ b/mlir/test/Analysis/DataFlow/test-dead-code-analysis-regression.mlir
@@ -0,0 +1,5 @@
+// RUN: mlir-opt -int-range-optimizations %s 
+
+%0 = scf.execute_region -> tensor<5x16xi16> {
+  llvm.unreachable
+}

>From 56b7099c7648be1fe22268bbeb311c9773a2f894 Mon Sep 17 00:00:00 2001
From: justinfargnoli 
Date: Sat, 14 Oct 2023 17:20:15 -0400
Subject: [PATCH 3/4] clang-format changes

---
 mlir/include/mlir/Analysis/DataFlow/DeadCodeAnalysis.h | 3 +--
 mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp| 2 +-
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/mlir/include/mlir/Analysis/DataFlow/DeadCodeAnalysis.h 
b/mlir/include/mlir/Analysis/DataFlow/DeadCodeAnalysis.h
index ce262c3ac5291ff..10ef8b6ba5843a9 100644
--- a/mlir/include/mlir/Analysis/DataFlow/DeadCodeAnalysis.h
+++ b/mlir/include/mlir/Analysis/DataFlow/DeadCodeAnalysis.h
@@ -208,8 +208,7 @@ class DeadCodeAnalysis : public DataFlowAnalysis {
   /// Visit the given terminator operation that exits a region under an
   /// operation with control-flow semantics. These are terminators with no CFG
   /// successors.
-  void visitRegionTerminator(Operation *op,
- RegionBranchOpInterface branch);
+  void visitRegionTerminator(Operation *op, RegionBranchOpInterface branch);
 
   /// Visit the given terminator operation that exits a callable region. These
   /// are terminators with no CFG successors.
diff --git a/mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp 
b/mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp
index 30a862fa048f97a..07f9705912260a4 100644
--- 

[clang] [clang] Implement constexpr bit_cast for vectors (PR #66894)

2023-10-21 Thread Richard Smith via cfe-commits


@@ -140,11 +140,12 @@ void g28(void) {
   typedef short v12i16 __attribute((vector_size(24)));
   typedef long double v2f80 __attribute((vector_size(24)));
   // CHECK: @g28.a = internal global <1 x i64> 
-  // CHECK: @g28.b = internal global <12 x i16> 
-  // CHECK: @g28.c = internal global <2 x x86_fp80> , align 32
+  // @g28.b = internal global <12 x i16> 
+  // @g28.c = internal global <2 x x86_fp80> , align 32
   static v1i64 a = (v1i64)10LL;
-  static v12i16 b = (v12i16)(v2f80){1,2};
-  static v2f80 c = (v2f80)(v12i16){0,0,0,-32768,16383,0,0,0,0,-32768,16384,0};
+  //FIXME: support constant bitcast between vectors of x86_fp80
+  //static v12i16 b = (v12i16)(v2f80){1,2};
+  //static v2f80 c = 
(v2f80)(v12i16){0,0,0,-32768,16383,0,0,0,0,-32768,16384,0};

zygoloid wrote:

Perhaps you could add a C++ testcass with the variable declared `constexpr`.

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


[clang] [clang-format] unexpected break after binOp '<<' (PR #69859)

2023-10-21 Thread Tsarkov Maksim via cfe-commits

https://github.com/s1Sharp created 
https://github.com/llvm/llvm-project/pull/69859

the problem occurred while checking for the correctness of the break after 
binary operators. The output statement 'tok::lessless' is then break line every 
possible time, which is not expected with the BreakBeforeBinaryOperators: None

>From 383d1acd4a5726296b09681103874f071529dacc Mon Sep 17 00:00:00 2001
From: Tsarkov Maksim 
Date: Sun, 22 Oct 2023 02:09:21 +0300
Subject: [PATCH] [clang-format] unexpected break after binOp '<<'

the problem occurred while checking for the correctness of the break after 
binary operators.
The output statement 'tok::lessless' is then break line every possible time,
which is not expected with the BreakBeforeBinaryOperators: None
---
 clang/lib/Format/TokenAnnotator.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 7f85f48de2ed2ed..6db1e826e11d234 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -5119,7 +5119,9 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine 
,
   if (Left.IsUnterminatedLiteral)
 return true;
   if (Right.is(tok::lessless) && Right.Next && Left.is(tok::string_literal) &&
-  Right.Next->is(tok::string_literal)) {
+  Right.Next->is(tok::string_literal) &&
+  (Style.BreakBeforeBinaryOperators == FormatStyle::BOS_All ||
+   Style.BreakBeforeBinaryOperators == FormatStyle::BOS_NonAssignment)) {
 return true;
   }
   if (Right.is(TT_RequiresClause)) {

___
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-10-21 Thread via cfe-commits

robozati wrote:

Rewrote the test and now it passes.

Sorry for pinging you @HighCommander4, but I don't know who to ping and you 
participated in that issue.

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] [clang] Bounds checking on unclosed parentheses, brackets or braces in Expanded Tokens (PR #69849)

2023-10-21 Thread via cfe-commits

https://github.com/robozati ready_for_review 
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] [clang] Bounds checking on unclosed parentheses, brackets or braces in Expanded Tokens (PR #69849)

2023-10-21 Thread via cfe-commits

https://github.com/robozati updated 
https://github.com/llvm/llvm-project/pull/69849

>From 239302d66dea74333e27288acbceffdf3f2d3b6b Mon Sep 17 00:00:00 2001
From: Gabriel Pezati 
Date: Sat, 21 Oct 2023 19:28:57 -0300
Subject: [PATCH] Fix UB on unclosed parentheses, brackets or braces in Tokens

---
 clang/lib/Tooling/Syntax/Tokens.cpp   | 25 ++-
 clang/unittests/Tooling/Syntax/TokensTest.cpp | 11 
 2 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/clang/lib/Tooling/Syntax/Tokens.cpp 
b/clang/lib/Tooling/Syntax/Tokens.cpp
index 2f28b9cf286a638..97f794e09cb5590 100644
--- a/clang/lib/Tooling/Syntax/Tokens.cpp
+++ b/clang/lib/Tooling/Syntax/Tokens.cpp
@@ -286,9 +286,13 @@ TokenBuffer::spelledForExpandedToken(const syntax::Token 
*Expanded) const {
   });
   // Our token could only be produced by the previous mapping.
   if (It == File.Mappings.begin()) {
-// No previous mapping, no need to modify offsets.
-return {[ExpandedIndex - File.BeginExpanded],
-/*Mapping=*/nullptr};
+const auto offset = ExpandedIndex - File.BeginExpanded;
+// Bounds check so parsing an unclosed parenthesis, brackets or braces do
+// not result in UB.
+if (offset >= File.SpelledTokens.size()) {
+  return {nullptr, nullptr};
+}
+return {[offset], /*Mapping=*/nullptr};
   }
   --It; // 'It' now points to last mapping that started before our token.
 
@@ -298,9 +302,12 @@ TokenBuffer::spelledForExpandedToken(const syntax::Token 
*Expanded) const {
 
   // Not part of the mapping, use the index from previous mapping to compute 
the
   // corresponding spelled token.
-  return {
-  [It->EndSpelled + (ExpandedIndex - It->EndExpanded)],
-  /*Mapping=*/nullptr};
+  const auto offset = It->EndSpelled + (ExpandedIndex - It->EndExpanded);
+  // This index can also result in UB when parsing unclosed tokens.
+  if (offset >= File.SpelledTokens.size()) {
+return {nullptr, nullptr};
+  }
+  return {[offset], /*Mapping=*/nullptr};
 }
 
 const TokenBuffer::Mapping *
@@ -410,6 +417,12 @@ 
TokenBuffer::spelledForExpanded(llvm::ArrayRef Expanded) const {
   auto [FirstSpelled, FirstMapping] = spelledForExpandedToken(First);
   auto [LastSpelled, LastMapping] = spelledForExpandedToken(Last);
 
+  // If there was an unclosed token, FirstSpelled or LastSpelled is null and 
the
+  // operation shouldn't continue.
+  if (FirstSpelled == nullptr || LastSpelled == nullptr) {
+return std::nullopt;
+  };
+
   FileID FID = SourceMgr->getFileID(FirstSpelled->location());
   // FIXME: Handle multi-file changes by trying to map onto a common root.
   if (FID != SourceMgr->getFileID(LastSpelled->location()))
diff --git a/clang/unittests/Tooling/Syntax/TokensTest.cpp 
b/clang/unittests/Tooling/Syntax/TokensTest.cpp
index 0c08318a637c0b6..e1b053ce45b841b 100644
--- a/clang/unittests/Tooling/Syntax/TokensTest.cpp
+++ b/clang/unittests/Tooling/Syntax/TokensTest.cpp
@@ -585,6 +585,17 @@ TEST_F(TokenCollectorTest, DelayedParsing) {
   EXPECT_THAT(collectAndDump(Code), StartsWith(ExpectedTokens));
 }
 
+TEST_F(TokenCollectorTest, UnclosedToken) {
+  llvm::StringLiteral Code = R"cpp(
+int main() {
+// this should not result in a segfault or UB.
+  )cpp";
+  std::string ExpectedTokens =
+  "expanded tokens:\n  int main ( ) {\nfile './input.cpp'\n  spelled "
+  "tokens:\nint main ( ) {\n  no mappings.\n";
+  EXPECT_THAT(collectAndDump(Code), StartsWith(ExpectedTokens));
+}
+
 TEST_F(TokenCollectorTest, MultiFile) {
   addFile("./foo.h", R"cpp(
 #define ADD(X, Y) X+Y

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


[PATCH] D156565: Diagnose use of VLAs in C++ by default

2023-10-21 Thread Nathan Chancellor via Phabricator via cfe-commits
nathanchance added a comment.

Is it expected that this introduces a warning for C code, as the commit message 
and tests appear to only affect C++? A trivial example from the Linux kernel:

https://elixir.bootlin.com/linux/v6.5.8/source/tools/lib/bpf/btf_dump.c#L1678

  #include 
  #include 
  #include 
  
  void foo(char *orig_name, char **cached_name, size_t dup_cnt)
  {
  const size_t max_len = 256;
  char new_name[max_len];
  
  snprintf(new_name, max_len, "%s___%zu", orig_name, dup_cnt);
  *cached_name = strdup(new_name);
  }



  $ clang -std=gnu89 -Wall -fsyntax-only test.c
  test.c:8:16: warning: variable length arrays are a C99 feature 
[-Wvla-extension]
  8 | char new_name[max_len];
|   ^~~
  1 warning generated.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156565

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


[clang] [clang-format] Add a new style for the clang-format source code (PR #69814)

2023-10-21 Thread Owen Pan via cfe-commits

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

>From 78a2661ba7a18ecf8b09be71f6959fbc9fcf70fe Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Fri, 20 Oct 2023 23:01:38 -0700
Subject: [PATCH 1/2] [clang-format] Add a new style for the clang-format
 source code

---
 clang/include/clang/Format/Format.h|  2 ++
 clang/lib/Format/Format.cpp| 18 +++---
 clang/unittests/Format/ConfigParseTest.cpp |  7 +++
 3 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index ed92ef6fc655522..4c344135d25163c 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4861,6 +4861,8 @@ FormatStyle getGNUStyle();
 /// 
https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference?view=vs-2017
 FormatStyle getMicrosoftStyle(FormatStyle::LanguageKind Language);
 
+FormatStyle getClangFormatStyle();
+
 /// Returns style indicating formatting should be not applied at all.
 FormatStyle getNoStyle();
 
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index acbed56a86e141f..2f988c4eaf35a57 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -834,8 +834,8 @@ template <> struct MappingTraits {
 
 StringRef BasedOnStyle;
 if (IO.outputting()) {
-  StringRef Styles[] = {"LLVM",   "Google", "Chromium", "Mozilla",
-"WebKit", "GNU","Microsoft"};
+  StringRef Styles[] = {"LLVM",   "Google", "Chromium",  "Mozilla",
+"WebKit", "GNU","Microsoft", "clang-format"};
   for (StringRef StyleName : Styles) {
 FormatStyle PredefinedStyle;
 if (getPredefinedStyle(StyleName, Style.Language, ) &&
@@ -1915,6 +1915,16 @@ FormatStyle getMicrosoftStyle(FormatStyle::LanguageKind 
Language) {
   return Style;
 }
 
+FormatStyle getClangFormatStyle() {
+  FormatStyle Style = getLLVMStyle();
+  Style.InsertBraces = true;
+  Style.InsertNewlineAtEOF = true;
+  Style.LineEnding = FormatStyle::LE_LF;
+  Style.RemoveBracesLLVM = true;
+  Style.RemoveParentheses = FormatStyle::RPS_ReturnStatement;
+  return Style;
+}
+
 FormatStyle getNoStyle() {
   FormatStyle NoStyle = getLLVMStyle();
   NoStyle.DisableFormat = true;
@@ -1939,6 +1949,8 @@ bool getPredefinedStyle(StringRef Name, 
FormatStyle::LanguageKind Language,
 *Style = getGNUStyle();
   else if (Name.equals_insensitive("microsoft"))
 *Style = getMicrosoftStyle(Language);
+  else if (Name.equals_insensitive("clang-format"))
+*Style = getClangFormatStyle();
   else if (Name.equals_insensitive("none"))
 *Style = getNoStyle();
   else if (Name.equals_insensitive("inheritparentconfig"))
@@ -3841,7 +3853,7 @@ LangOptions getFormattingLangOpts(const FormatStyle 
) {
 const char *StyleOptionHelpDescription =
 "Set coding style.  can be:\n"
 "1. A preset: LLVM, GNU, Google, Chromium, Microsoft,\n"
-"   Mozilla, WebKit.\n"
+"   Mozilla, WebKit, clang-format.\n"
 "2. 'file' to load style configuration from a\n"
 "   .clang-format file in one of the parent directories\n"
 "   of the source file (for stdin, see --assume-filename).\n"
diff --git a/clang/unittests/Format/ConfigParseTest.cpp 
b/clang/unittests/Format/ConfigParseTest.cpp
index c35c82955f6a558..ba79c8d72f09552 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -63,6 +63,13 @@ TEST(ConfigParseTest, GetsPredefinedStyleByName) {
   EXPECT_TRUE(getPredefinedStyle("gnU", FormatStyle::LK_Cpp, [2]));
   EXPECT_ALL_STYLES_EQUAL(Styles);
 
+  Styles[0] = getClangFormatStyle();
+  EXPECT_TRUE(
+  getPredefinedStyle("clang-format", FormatStyle::LK_Cpp, [1]));
+  EXPECT_TRUE(
+  getPredefinedStyle("Clang-format", FormatStyle::LK_Cpp, [2]));
+  EXPECT_ALL_STYLES_EQUAL(Styles);
+
   EXPECT_FALSE(getPredefinedStyle("qwerty", FormatStyle::LK_Cpp, [0]));
 }
 

>From 614f56310840a87e9a0d9aa2ece3693d375d00b6 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Sat, 21 Oct 2023 14:44:06 -0700
Subject: [PATCH 2/2] Don't show the undocumented clang-format style in help

---
 clang/lib/Format/Format.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 2f988c4eaf35a57..ff7cb097a59d6a0 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -3853,7 +3853,7 @@ LangOptions getFormattingLangOpts(const FormatStyle 
) {
 const char *StyleOptionHelpDescription =
 "Set coding style.  can be:\n"
 "1. A preset: LLVM, GNU, Google, Chromium, Microsoft,\n"
-"   Mozilla, WebKit, clang-format.\n"
+"   Mozilla, WebKit.\n"
 "2. 'file' to load style configuration from a\n"
 "   .clang-format file in one of the parent directories\n"
 "   of the source file (for stdin, see --assume-filename).\n"


[clang] [LLVM] Add IRNormalizer Pass (PR #68176)

2023-10-21 Thread Justin Fargnoli via cfe-commits

https://github.com/justinfargnoli updated 
https://github.com/llvm/llvm-project/pull/68176

>From f792a030ac1761a96176332fea906cd2d1826c7b Mon Sep 17 00:00:00 2001
From: justinfargnoli 
Date: Sat, 12 Aug 2023 10:58:45 -0700
Subject: [PATCH 01/20] Add IRCanonicalizer.cpp

---
 llvm/lib/Transforms/Utils/CMakeLists.txt  |   1 +
 llvm/lib/Transforms/Utils/IRCanonicalizer.cpp | 632 ++
 2 files changed, 633 insertions(+)
 create mode 100644 llvm/lib/Transforms/Utils/IRCanonicalizer.cpp

diff --git a/llvm/lib/Transforms/Utils/CMakeLists.txt 
b/llvm/lib/Transforms/Utils/CMakeLists.txt
index a870071f3f641dc..7866e7a8c09c3be 100644
--- a/llvm/lib/Transforms/Utils/CMakeLists.txt
+++ b/llvm/lib/Transforms/Utils/CMakeLists.txt
@@ -34,6 +34,7 @@ add_llvm_component_library(LLVMTransformUtils
   InjectTLIMappings.cpp
   InstructionNamer.cpp
   IntegerDivision.cpp
+  IRCanonicalizer.cpp
   LCSSA.cpp
   LibCallsShrinkWrap.cpp
   Local.cpp
diff --git a/llvm/lib/Transforms/Utils/IRCanonicalizer.cpp 
b/llvm/lib/Transforms/Utils/IRCanonicalizer.cpp
new file mode 100644
index 000..58e2dce0b96685b
--- /dev/null
+++ b/llvm/lib/Transforms/Utils/IRCanonicalizer.cpp
@@ -0,0 +1,632 @@
+//===--- IRCanonicalizer.cpp - IR Canonicalizer 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+/// \file
+/// This file implements the IRCanonicalizer class which aims to transform LLVM
+/// Modules into a canonical form by reordering and renaming instructions while
+/// preserving the same semantics. The canonicalizer makes it easier to spot
+/// semantic differences while diffing two modules which have undergone
+/// different passes.
+///
+//===--===//
+
+#include "llvm/ADT/SetVector.h"
+#include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/IR/BasicBlock.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/InstIterator.h"
+#include "llvm/IR/Module.h"
+#include "llvm/InitializePasses.h"
+#include "llvm/Pass.h"
+#include "llvm/PassRegistry.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Transforms/Utils.h"
+#include 
+#include 
+
+#define DEBUG_TYPE "canon"
+
+using namespace llvm;
+
+namespace {
+/// IRCanonicalizer aims to transform LLVM IR into canonical form.
+class IRCanonicalizer : public FunctionPass {
+public:
+  static char ID;
+
+  /// \name Canonicalizer flags.
+  /// @{
+  /// Preserves original order of instructions.
+  static cl::opt PreserveOrder;
+  /// Renames all instructions (including user-named).
+  static cl::opt RenameAll;
+  /// Folds all regular instructions (including pre-outputs).
+  static cl::opt FoldPreoutputs;
+  /// Sorts and reorders operands in commutative instructions.
+  static cl::opt ReorderOperands;
+  /// @}
+
+  /// Constructor for the IRCanonicalizer.
+  IRCanonicalizer() : FunctionPass(ID) {}
+
+  bool runOnFunction(Function ) override;
+
+private:
+  // Random constant for hashing, so the state isn't zero.
+  const uint64_t MagicHashConstant = 0x6acaa36bef8325c5ULL;
+
+  /// \name Naming.
+  /// @{
+  void nameFunctionArguments(Function );
+  void nameBasicBlocks(Function );
+  void nameInstruction(Instruction *I);
+  void nameAsInitialInstruction(Instruction *I);
+  void nameAsRegularInstruction(Instruction *I);
+  void foldInstructionName(Instruction *I);
+  /// @}
+
+  /// \name Reordering.
+  /// @{
+  void reorderInstructions(SmallVector );
+  void reorderInstruction(Instruction *Used, Instruction *User,
+  SmallPtrSet );
+  void reorderInstructionOperandsByNames(Instruction *I);
+  void reorderPHIIncomingValues(PHINode *PN);
+  /// @}
+
+  /// \name Utility methods.
+  /// @{
+  SmallVector collectOutputInstructions(Function );
+  bool isOutput(const Instruction *I);
+  bool isInitialInstruction(const Instruction *I);
+  bool hasOnlyImmediateOperands(const Instruction *I);
+  SetVector
+  getOutputFootprint(Instruction *I,
+ SmallPtrSet );
+  /// @}
+};
+} // namespace
+
+char IRCanonicalizer::ID = 0;
+static RegisterPass X("canon", "Canonicalize the IR",
+   false /* Only looks at CFG */,
+   false /* Analysis Pass */);
+
+cl::opt IRCanonicalizer::PreserveOrder(
+"preserve-order", cl::Hidden,
+cl::desc("Preserves original instruction order"));
+cl::opt IRCanonicalizer::RenameAll(
+"rename-all", cl::Hidden,
+cl::desc("Renames all instructions (including user-named)"));
+cl::opt IRCanonicalizer::FoldPreoutputs(
+"fold-all", cl::Hidden,
+cl::desc("Folds all regular instructions 

[clang] ✨ [Sema, Lex, Parse] Preprocessor embed in C and C++ (and Obj-C and Obj-C++ by-proxy) (PR #68620)

2023-10-21 Thread Fangrui Song via cfe-commits

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


[clang] ✨ [Sema, Lex, Parse] Preprocessor embed in C and C++ (and Obj-C and Obj-C++ by-proxy) (PR #68620)

2023-10-21 Thread Fangrui Song via cfe-commits

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


[clang] ✨ [Sema, Lex, Parse] Preprocessor embed in C and C++ (and Obj-C and Obj-C++ by-proxy) (PR #68620)

2023-10-21 Thread Fangrui Song via cfe-commits


@@ -816,6 +821,14 @@ will be ignored}]>;
 def L : JoinedOrSeparate<["-"], "L">, Flags<[RenderJoined]>, Group,
 Visibility<[ClangOption, FlangOption]>,
 MetaVarName<"">, HelpText<"Add directory to library search path">;
+def embed_dir : JoinedOrSeparate<["-"], "embed-dir">,
+Flags<[RenderJoined]>, Group,
+Visibility<[ClangOption, CC1Option, CC1AsOption, FlangOption, FC1Option]>,
+MetaVarName<"">, HelpText<"Add directory to embed search path">;
+def embed_dir_EQ : JoinedOrSeparate<["-"], "embed-dir=">,

MaskRay wrote:

`-e` is a driver option, so `-eembed-dir-with-typo` is recognized. Better to 
use `--embed-dir=`. Please don't support `*Separate<...>` for new options.

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


[clang-tools-extra] [LLVM] Add IRNormalizer Pass (PR #68176)

2023-10-21 Thread Justin Fargnoli via cfe-commits

https://github.com/justinfargnoli updated 
https://github.com/llvm/llvm-project/pull/68176

>From f792a030ac1761a96176332fea906cd2d1826c7b Mon Sep 17 00:00:00 2001
From: justinfargnoli 
Date: Sat, 12 Aug 2023 10:58:45 -0700
Subject: [PATCH 01/20] Add IRCanonicalizer.cpp

---
 llvm/lib/Transforms/Utils/CMakeLists.txt  |   1 +
 llvm/lib/Transforms/Utils/IRCanonicalizer.cpp | 632 ++
 2 files changed, 633 insertions(+)
 create mode 100644 llvm/lib/Transforms/Utils/IRCanonicalizer.cpp

diff --git a/llvm/lib/Transforms/Utils/CMakeLists.txt 
b/llvm/lib/Transforms/Utils/CMakeLists.txt
index a870071f3f641dc..7866e7a8c09c3be 100644
--- a/llvm/lib/Transforms/Utils/CMakeLists.txt
+++ b/llvm/lib/Transforms/Utils/CMakeLists.txt
@@ -34,6 +34,7 @@ add_llvm_component_library(LLVMTransformUtils
   InjectTLIMappings.cpp
   InstructionNamer.cpp
   IntegerDivision.cpp
+  IRCanonicalizer.cpp
   LCSSA.cpp
   LibCallsShrinkWrap.cpp
   Local.cpp
diff --git a/llvm/lib/Transforms/Utils/IRCanonicalizer.cpp 
b/llvm/lib/Transforms/Utils/IRCanonicalizer.cpp
new file mode 100644
index 000..58e2dce0b96685b
--- /dev/null
+++ b/llvm/lib/Transforms/Utils/IRCanonicalizer.cpp
@@ -0,0 +1,632 @@
+//===--- IRCanonicalizer.cpp - IR Canonicalizer 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+/// \file
+/// This file implements the IRCanonicalizer class which aims to transform LLVM
+/// Modules into a canonical form by reordering and renaming instructions while
+/// preserving the same semantics. The canonicalizer makes it easier to spot
+/// semantic differences while diffing two modules which have undergone
+/// different passes.
+///
+//===--===//
+
+#include "llvm/ADT/SetVector.h"
+#include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/IR/BasicBlock.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/InstIterator.h"
+#include "llvm/IR/Module.h"
+#include "llvm/InitializePasses.h"
+#include "llvm/Pass.h"
+#include "llvm/PassRegistry.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Transforms/Utils.h"
+#include 
+#include 
+
+#define DEBUG_TYPE "canon"
+
+using namespace llvm;
+
+namespace {
+/// IRCanonicalizer aims to transform LLVM IR into canonical form.
+class IRCanonicalizer : public FunctionPass {
+public:
+  static char ID;
+
+  /// \name Canonicalizer flags.
+  /// @{
+  /// Preserves original order of instructions.
+  static cl::opt PreserveOrder;
+  /// Renames all instructions (including user-named).
+  static cl::opt RenameAll;
+  /// Folds all regular instructions (including pre-outputs).
+  static cl::opt FoldPreoutputs;
+  /// Sorts and reorders operands in commutative instructions.
+  static cl::opt ReorderOperands;
+  /// @}
+
+  /// Constructor for the IRCanonicalizer.
+  IRCanonicalizer() : FunctionPass(ID) {}
+
+  bool runOnFunction(Function ) override;
+
+private:
+  // Random constant for hashing, so the state isn't zero.
+  const uint64_t MagicHashConstant = 0x6acaa36bef8325c5ULL;
+
+  /// \name Naming.
+  /// @{
+  void nameFunctionArguments(Function );
+  void nameBasicBlocks(Function );
+  void nameInstruction(Instruction *I);
+  void nameAsInitialInstruction(Instruction *I);
+  void nameAsRegularInstruction(Instruction *I);
+  void foldInstructionName(Instruction *I);
+  /// @}
+
+  /// \name Reordering.
+  /// @{
+  void reorderInstructions(SmallVector );
+  void reorderInstruction(Instruction *Used, Instruction *User,
+  SmallPtrSet );
+  void reorderInstructionOperandsByNames(Instruction *I);
+  void reorderPHIIncomingValues(PHINode *PN);
+  /// @}
+
+  /// \name Utility methods.
+  /// @{
+  SmallVector collectOutputInstructions(Function );
+  bool isOutput(const Instruction *I);
+  bool isInitialInstruction(const Instruction *I);
+  bool hasOnlyImmediateOperands(const Instruction *I);
+  SetVector
+  getOutputFootprint(Instruction *I,
+ SmallPtrSet );
+  /// @}
+};
+} // namespace
+
+char IRCanonicalizer::ID = 0;
+static RegisterPass X("canon", "Canonicalize the IR",
+   false /* Only looks at CFG */,
+   false /* Analysis Pass */);
+
+cl::opt IRCanonicalizer::PreserveOrder(
+"preserve-order", cl::Hidden,
+cl::desc("Preserves original instruction order"));
+cl::opt IRCanonicalizer::RenameAll(
+"rename-all", cl::Hidden,
+cl::desc("Renames all instructions (including user-named)"));
+cl::opt IRCanonicalizer::FoldPreoutputs(
+"fold-all", cl::Hidden,
+cl::desc("Folds all regular instructions 

[clang] [LLVM] Add IRNormalizer Pass (PR #68176)

2023-10-21 Thread Justin Fargnoli via cfe-commits

https://github.com/justinfargnoli updated 
https://github.com/llvm/llvm-project/pull/68176

>From f792a030ac1761a96176332fea906cd2d1826c7b Mon Sep 17 00:00:00 2001
From: justinfargnoli 
Date: Sat, 12 Aug 2023 10:58:45 -0700
Subject: [PATCH 01/20] Add IRCanonicalizer.cpp

---
 llvm/lib/Transforms/Utils/CMakeLists.txt  |   1 +
 llvm/lib/Transforms/Utils/IRCanonicalizer.cpp | 632 ++
 2 files changed, 633 insertions(+)
 create mode 100644 llvm/lib/Transforms/Utils/IRCanonicalizer.cpp

diff --git a/llvm/lib/Transforms/Utils/CMakeLists.txt 
b/llvm/lib/Transforms/Utils/CMakeLists.txt
index a870071f3f641dc..7866e7a8c09c3be 100644
--- a/llvm/lib/Transforms/Utils/CMakeLists.txt
+++ b/llvm/lib/Transforms/Utils/CMakeLists.txt
@@ -34,6 +34,7 @@ add_llvm_component_library(LLVMTransformUtils
   InjectTLIMappings.cpp
   InstructionNamer.cpp
   IntegerDivision.cpp
+  IRCanonicalizer.cpp
   LCSSA.cpp
   LibCallsShrinkWrap.cpp
   Local.cpp
diff --git a/llvm/lib/Transforms/Utils/IRCanonicalizer.cpp 
b/llvm/lib/Transforms/Utils/IRCanonicalizer.cpp
new file mode 100644
index 000..58e2dce0b96685b
--- /dev/null
+++ b/llvm/lib/Transforms/Utils/IRCanonicalizer.cpp
@@ -0,0 +1,632 @@
+//===--- IRCanonicalizer.cpp - IR Canonicalizer 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+/// \file
+/// This file implements the IRCanonicalizer class which aims to transform LLVM
+/// Modules into a canonical form by reordering and renaming instructions while
+/// preserving the same semantics. The canonicalizer makes it easier to spot
+/// semantic differences while diffing two modules which have undergone
+/// different passes.
+///
+//===--===//
+
+#include "llvm/ADT/SetVector.h"
+#include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/IR/BasicBlock.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/InstIterator.h"
+#include "llvm/IR/Module.h"
+#include "llvm/InitializePasses.h"
+#include "llvm/Pass.h"
+#include "llvm/PassRegistry.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Transforms/Utils.h"
+#include 
+#include 
+
+#define DEBUG_TYPE "canon"
+
+using namespace llvm;
+
+namespace {
+/// IRCanonicalizer aims to transform LLVM IR into canonical form.
+class IRCanonicalizer : public FunctionPass {
+public:
+  static char ID;
+
+  /// \name Canonicalizer flags.
+  /// @{
+  /// Preserves original order of instructions.
+  static cl::opt PreserveOrder;
+  /// Renames all instructions (including user-named).
+  static cl::opt RenameAll;
+  /// Folds all regular instructions (including pre-outputs).
+  static cl::opt FoldPreoutputs;
+  /// Sorts and reorders operands in commutative instructions.
+  static cl::opt ReorderOperands;
+  /// @}
+
+  /// Constructor for the IRCanonicalizer.
+  IRCanonicalizer() : FunctionPass(ID) {}
+
+  bool runOnFunction(Function ) override;
+
+private:
+  // Random constant for hashing, so the state isn't zero.
+  const uint64_t MagicHashConstant = 0x6acaa36bef8325c5ULL;
+
+  /// \name Naming.
+  /// @{
+  void nameFunctionArguments(Function );
+  void nameBasicBlocks(Function );
+  void nameInstruction(Instruction *I);
+  void nameAsInitialInstruction(Instruction *I);
+  void nameAsRegularInstruction(Instruction *I);
+  void foldInstructionName(Instruction *I);
+  /// @}
+
+  /// \name Reordering.
+  /// @{
+  void reorderInstructions(SmallVector );
+  void reorderInstruction(Instruction *Used, Instruction *User,
+  SmallPtrSet );
+  void reorderInstructionOperandsByNames(Instruction *I);
+  void reorderPHIIncomingValues(PHINode *PN);
+  /// @}
+
+  /// \name Utility methods.
+  /// @{
+  SmallVector collectOutputInstructions(Function );
+  bool isOutput(const Instruction *I);
+  bool isInitialInstruction(const Instruction *I);
+  bool hasOnlyImmediateOperands(const Instruction *I);
+  SetVector
+  getOutputFootprint(Instruction *I,
+ SmallPtrSet );
+  /// @}
+};
+} // namespace
+
+char IRCanonicalizer::ID = 0;
+static RegisterPass X("canon", "Canonicalize the IR",
+   false /* Only looks at CFG */,
+   false /* Analysis Pass */);
+
+cl::opt IRCanonicalizer::PreserveOrder(
+"preserve-order", cl::Hidden,
+cl::desc("Preserves original instruction order"));
+cl::opt IRCanonicalizer::RenameAll(
+"rename-all", cl::Hidden,
+cl::desc("Renames all instructions (including user-named)"));
+cl::opt IRCanonicalizer::FoldPreoutputs(
+"fold-all", cl::Hidden,
+cl::desc("Folds all regular instructions 

[clang] [clang-format] Add a new style for the clang-format source code (PR #69814)

2023-10-21 Thread Owen Pan via cfe-commits

owenca wrote:

Yep. Each file will contain only `BasedOnStyle: clang-format`.

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


[clang] [clang] Improve `_Alignas` on a `struct` declaration diagnostic (PR #65638)

2023-10-21 Thread Jerin Philip via cfe-commits

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


[clang] [clang] Improve `_Alignas` on a `struct` declaration diagnostic (PR #65638)

2023-10-21 Thread Jerin Philip via cfe-commits

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


[clang] [clang] Improve `_Alignas` on a `struct` declaration diagnostic (PR #65638)

2023-10-21 Thread Jerin Philip via cfe-commits

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


[clang-tools-extra] In compilation databases, add support for relative directories (PR #69856)

2023-10-21 Thread via cfe-commits

https://github.com/Overhatted created 
https://github.com/llvm/llvm-project/pull/69856

I haven't finished all of the tests and formatting so it's a bit in a POC stage 
but I would like to know if this change would be accepted.

The change is to support relative paths in the "directory" field in compilation 
databases. At the moment the specification doesn't seem to explicitly dissallow 
it but the implementation doesn't support it.

The use-case is I'm using Buck2 to generate the compilation databases which 
produces them with a "." for the directory field. Of course it could be changed 
on the Buck2 side but I think it would be useful to simply support relative 
paths on the clang side since it allows caching of the compilation database or 
maybe even commiting it to the repository.

Please let me know if this is an acceptable change or not.

>From dcef5e88eb1cdcdf896eebb4773f456ed2d87055 Mon Sep 17 00:00:00 2001
From: Overhatted <15021741+overhat...@users.noreply.github.com>
Date: Sat, 21 Oct 2023 14:16:38 +0100
Subject: [PATCH] In compilation databases, add support for relative
 directories

---
 .../clangd/GlobalCompilationDatabase.cpp  |  2 +-
 clang/docs/JSONCompilationDatabase.rst|  4 +++-
 .../clang/Tooling/JSONCompilationDatabase.h   | 10 
 clang/lib/Tooling/JSONCompilationDatabase.cpp | 24 ++-
 4 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp 
b/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
index d1833759917a30f..3e81308316d55cd 100644
--- a/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
+++ b/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
@@ -243,7 +243,7 @@ 
DirectoryBasedGlobalCompilationDatabase::DirectoryCache::CachedFile::load(
 static std::unique_ptr
 parseJSON(PathRef Path, llvm::StringRef Data, std::string ) {
   if (auto CDB = tooling::JSONCompilationDatabase::loadFromBuffer(
-  Data, Error, tooling::JSONCommandLineSyntax::AutoDetect)) {
+  Path, Data, Error, tooling::JSONCommandLineSyntax::AutoDetect)) {
 return tooling::inferMissingCompileCommands(std::move(CDB));
   }
   return nullptr;
diff --git a/clang/docs/JSONCompilationDatabase.rst 
b/clang/docs/JSONCompilationDatabase.rst
index f5432278bd4d4e4..41219a554dfdeaa 100644
--- a/clang/docs/JSONCompilationDatabase.rst
+++ b/clang/docs/JSONCompilationDatabase.rst
@@ -81,7 +81,9 @@ The contracts for each field in the command object are:
 
 -  **directory:** The working directory of the compilation. All paths
specified in the **command** or **file** fields must be either
-   absolute or relative to this directory.
+   absolute or relative to this directory. This field itself can be a
+   relative path in which case it is evaluated relative to the folder
+   containing the compilation database file.
 -  **file:** The main translation unit source processed by this
compilation step. This is used by tools as the key into the
compilation database. There can be multiple command objects for the
diff --git a/clang/include/clang/Tooling/JSONCompilationDatabase.h 
b/clang/include/clang/Tooling/JSONCompilationDatabase.h
index 96582457c63d588..3ec0e36c196d2e4 100644
--- a/clang/include/clang/Tooling/JSONCompilationDatabase.h
+++ b/clang/include/clang/Tooling/JSONCompilationDatabase.h
@@ -72,8 +72,8 @@ class JSONCompilationDatabase : public CompilationDatabase {
   ///
   /// Returns NULL and sets ErrorMessage if the database could not be loaded.
   static std::unique_ptr
-  loadFromBuffer(StringRef DatabaseString, std::string ,
- JSONCommandLineSyntax Syntax);
+  loadFromBuffer(StringRef FilePath, StringRef DatabaseString,
+ std::string , JSONCommandLineSyntax Syntax);
 
   /// Returns all compile commands in which the specified file was
   /// compiled.
@@ -94,9 +94,10 @@ class JSONCompilationDatabase : public CompilationDatabase {
 
 private:
   /// Constructs a JSON compilation database on a memory buffer.
-  JSONCompilationDatabase(std::unique_ptr Database,
+  JSONCompilationDatabase(SmallString<128> FolderPath,
+  std::unique_ptr Database,
   JSONCommandLineSyntax Syntax)
-  : Database(std::move(Database)), Syntax(Syntax),
+  : FolderPath(FolderPath), Database(std::move(Database)), Syntax(Syntax),
 YAMLStream(this->Database->getBuffer(), SM) {}
 
   /// Parses the database file and creates the index.
@@ -130,6 +131,7 @@ class JSONCompilationDatabase : public CompilationDatabase {
 
   FileMatchTrie MatchTrie;
 
+  SmallString<128> FolderPath;
   std::unique_ptr Database;
   JSONCommandLineSyntax Syntax;
   llvm::SourceMgr SM;
diff --git a/clang/lib/Tooling/JSONCompilationDatabase.cpp 
b/clang/lib/Tooling/JSONCompilationDatabase.cpp
index a77686996879f1d..c8c7f46e1fb3e66 100644
--- a/clang/lib/Tooling/JSONCompilationDatabase.cpp
+++ b/clang/lib/Tooling/JSONCompilationDatabase.cpp
@@ 

[clang] [clang-format] Don't align comments over scopes (PR #68743)

2023-10-21 Thread Björn Schäpers via cfe-commits

https://github.com/HazardyKnusperkeks updated 
https://github.com/llvm/llvm-project/pull/68743

From 8df1b77e223cd5ab5d759ae2d57f4c79306f9149 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Sch=C3=A4pers?= 
Date: Tue, 10 Oct 2023 22:50:43 +0200
Subject: [PATCH] [clang-format] Don't align comments over scopes

We now stop aligning trailing comments on all closing braces, for
classes etc. we even check for the semicolon between the comment and the
brace.

Fixes #67906.
---
 clang/lib/Format/WhitespaceManager.cpp|  53 +-
 clang/unittests/Format/FormatTestComments.cpp | 155 --
 2 files changed, 187 insertions(+), 21 deletions(-)

diff --git a/clang/lib/Format/WhitespaceManager.cpp 
b/clang/lib/Format/WhitespaceManager.cpp
index dc81060671c1712..8165bfff618ab70 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -1048,6 +1048,9 @@ void WhitespaceManager::alignChainedConditionals() {
 }
 
 void WhitespaceManager::alignTrailingComments() {
+  if (Style.AlignTrailingComments.Kind == FormatStyle::TCAS_Never)
+return;
+
   const int Size = Changes.size();
   int MinColumn = 0;
   int StartOfSequence = 0;
@@ -1118,16 +1121,48 @@ void WhitespaceManager::alignTrailingComments() {
   }
 }
 
-// We don't want to align namespace end comments.
-const bool DontAlignThisComment =
-I > 0 && C.NewlinesBefore == 0 &&
-Changes[I - 1].Tok->is(TT_NamespaceRBrace);
-if (Style.AlignTrailingComments.Kind == FormatStyle::TCAS_Never ||
-DontAlignThisComment) {
+// We don't want to align comments which end a scope, which are here
+// identified by most closing braces.
+auto DontAlignThisComment = [](const auto *Tok) {
+  if (Tok->is(tok::semi)) {
+Tok = Tok->getPreviousNonComment();
+if (!Tok)
+  return false;
+  }
+  if (Tok->is(tok::r_paren)) {
+// Back up past the parentheses and a `TT_DoWhile` that may precede.
+Tok = Tok->MatchingParen;
+if (!Tok)
+  return false;
+Tok = Tok->getPreviousNonComment();
+if (!Tok)
+  return false;
+if (Tok->is(TT_DoWhile)) {
+  auto Prev = Tok->getPreviousNonComment();
+  if (!Prev) {
+// A do-while-loop without braces.
+return Tok->NewlinesBefore > 0;
+  }
+  Tok = Prev;
+}
+  }
+
+  if (Tok->isNot(tok::r_brace))
+return false;
+
+  while (Tok->Previous && Tok->Previous->is(tok::r_brace))
+Tok = Tok->Previous;
+  return Tok->NewlinesBefore > 0;
+};
+
+if (I > 0 && C.NewlinesBefore == 0 &&
+DontAlignThisComment(Changes[I - 1].Tok)) {
   alignTrailingComments(StartOfSequence, I, MinColumn);
-  MinColumn = ChangeMinColumn;
-  MaxColumn = ChangeMinColumn;
-  StartOfSequence = I;
+  // Reset to initial values, but skip this change for the next alignment
+  // pass.
+  MinColumn = 0;
+  MaxColumn = INT_MAX;
+  StartOfSequence = I + 1;
 } else if (BreakBeforeNext || Newlines > NewLineThreshold ||
(ChangeMinColumn > MaxColumn || ChangeMaxColumn < MinColumn) ||
// Break the comment sequence if the previous line did not end
diff --git a/clang/unittests/Format/FormatTestComments.cpp 
b/clang/unittests/Format/FormatTestComments.cpp
index 1198329b7b5a8f0..1388361eea5865b 100644
--- a/clang/unittests/Format/FormatTestComments.cpp
+++ b/clang/unittests/Format/FormatTestComments.cpp
@@ -182,7 +182,7 @@ TEST_F(FormatTestComments, UnderstandsSingleLineComments) {
"int   a; // This is unrelated"));
   EXPECT_EQ("class C {\n"
 "  void f() { // This does something ..\n"
-"  }  // awesome..\n"
+"  } // awesome..\n"
 "\n"
 "  int a; // This is unrelated\n"
 "};",
@@ -3102,7 +3102,8 @@ TEST_F(FormatTestComments, DontAlignNamespaceComments) {
   StringRef Input = "namespace A {\n"
 "  TESTSUITE(B) {\n"
 "namespace C {\n"
-"  namespace D {} // namespace D\n"
+"  namespace D { //\n"
+"  } // namespace D\n"
 "  std::string Foo = Bar; // Comment\n"
 "  std::string BazString = Baz;   // C2\n"
 "}  // namespace C\n"
@@ -3114,7 +3115,8 @@ TEST_F(FormatTestComments, DontAlignNamespaceComments) {
   verifyFormat("namespace A {\n"
"  TESTSUITE(B) {\n"
"namespace C {\n"
-   "  namespace D {} // namespace D\n"
+   "  namespace D { //\n"
+   "  } // namespace D\n"
"  std::string Foo = Bar;   // Comment\n"
"  std::string BazString = Baz; // C2\n"
"} // namespace C\n"
@@ -3126,7 

[clang] [clang-format] Add a new style for the clang-format source code (PR #69814)

2023-10-21 Thread Björn Schäpers via cfe-commits

HazardyKnusperkeks wrote:

> > What is your goal with that style?
> 
> It was actually your [idea](https://reviews.llvm.org/D153208#4431239). 

I know, but I thought the thought was dropped. :)

So the intent is to use it on our `.clang-format` files?

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


[clang-tools-extra] [clangd] Show alignment for records and fields decls (PR #67213)

2023-10-21 Thread via cfe-commits

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


[clang-tools-extra] [clangd] Show alignment for records and fields decls (PR #67213)

2023-10-21 Thread via cfe-commits

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


[clang-tools-extra] [clangd] Show alignment for records and fields decls (PR #67213)

2023-10-21 Thread via cfe-commits

sr-tream wrote:

In force-push changed alignment render, to render it in same line with size

![image](https://github.com/llvm/llvm-project/assets/12231048/935beb48-4659-4a56-bc8c-dbea9bf145e2)


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


[clang-tools-extra] [clangd] Show alignment for records and fields decls (PR #67213)

2023-10-21 Thread via cfe-commits

https://github.com/sr-tream updated 
https://github.com/llvm/llvm-project/pull/67213

>From b9b5bc27c7ab8c8faca7f8bf66aead59b817b6b7 Mon Sep 17 00:00:00 2001
From: SR_team 
Date: Sat, 21 Oct 2023 21:24:26 +0300
Subject: [PATCH] [clangd] Show alignment for records and fields decls

---
 clang-tools-extra/clangd/Hover.cpp|  5 +
 clang-tools-extra/clangd/Hover.h  |  2 ++
 clang-tools-extra/clangd/unittests/HoverTests.cpp | 13 +++--
 3 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/clang-tools-extra/clangd/Hover.cpp 
b/clang-tools-extra/clangd/Hover.cpp
index 0ec85fc24df151b..933c69294b40926 100644
--- a/clang-tools-extra/clangd/Hover.cpp
+++ b/clang-tools-extra/clangd/Hover.cpp
@@ -1001,6 +1001,8 @@ void addLayoutInfo(const NamedDecl , HoverInfo ) {
   if (auto *RD = llvm::dyn_cast()) {
 if (auto Size = Ctx.getTypeSizeInCharsIfKnown(RD->getTypeForDecl()))
   HI.Size = Size->getQuantity() * 8;
+if (!RD->isDependentType() && RD->isCompleteDefinition())
+  HI.Align = Ctx.getTypeAlign(RD->getTypeForDecl());
 return;
   }
 
@@ -1009,6 +1011,7 @@ void addLayoutInfo(const NamedDecl , HoverInfo ) {
 if (Record)
   Record = Record->getDefinition();
 if (Record && !Record->isInvalidDecl() && !Record->isDependentType()) {
+  HI.Align = Ctx.getTypeAlign(FD->getType());
   const ASTRecordLayout  = Ctx.getASTRecordLayout(Record);
   HI.Offset = Layout.getFieldOffset(FD->getFieldIndex());
   if (FD->isBitField())
@@ -1487,6 +1490,8 @@ markup::Document HoverInfo::present() const {
   P.appendText(
   llvm::formatv(" (+{0} padding)", formatSize(*Padding)).str());
 }
+if (Align)
+  P.appendText(", alignment " + formatSize(*Align));
   }
 
   if (CalleeArgInfo) {
diff --git a/clang-tools-extra/clangd/Hover.h b/clang-tools-extra/clangd/Hover.h
index 6a61100912918ea..fe689de44732ebe 100644
--- a/clang-tools-extra/clangd/Hover.h
+++ b/clang-tools-extra/clangd/Hover.h
@@ -97,6 +97,8 @@ struct HoverInfo {
   std::optional Offset;
   /// Contains the padding following a field within the enclosing class.
   std::optional Padding;
+  /// Contains the alignment of fields and types where it's interesting.
+  std::optional Align;
   // Set when symbol is inside function call. Contains information extracted
   // from the callee definition about the argument this is passed as.
   std::optional CalleeArgInfo;
diff --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp 
b/clang-tools-extra/clangd/unittests/HoverTests.cpp
index 8c88cd52574536c..063a60db044060e 100644
--- a/clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -92,6 +92,7 @@ TEST(Hover, Structured) {
  HI.Offset = 0;
  HI.Size = 8;
  HI.Padding = 56;
+ HI.Align = 8;
  HI.AccessSpecifier = "private";
}},
   // Union field
@@ -110,6 +111,7 @@ TEST(Hover, Structured) {
  HI.Type = "char";
  HI.Size = 8;
  HI.Padding = 120;
+ HI.Align = 8;
  HI.AccessSpecifier = "public";
}},
   // Bitfield
@@ -128,6 +130,7 @@ TEST(Hover, Structured) {
  HI.Type = "int";
  HI.Offset = 0;
  HI.Size = 1;
+ HI.Align = 32;
  HI.AccessSpecifier = "public";
}},
   // Local to class method.
@@ -192,6 +195,7 @@ TEST(Hover, Structured) {
  HI.Type = "char";
  HI.Offset = 0;
  HI.Size = 8;
+ HI.Align = 8;
  HI.AccessSpecifier = "public";
}},
   // Struct definition shows size.
@@ -204,6 +208,7 @@ TEST(Hover, Structured) {
  HI.Kind = index::SymbolKind::Struct;
  HI.Definition = "struct X {}";
  HI.Size = 8;
+ HI.Align = 8;
}},
   // Variable with template type
   {R"cpp(
@@ -1375,6 +1380,7 @@ class Foo final {})cpp";
  HI.Offset = 8;
  HI.Size = 1;
  HI.Padding = 23;
+ HI.Align = 8;
  HI.AccessSpecifier = "public";
}}};
   for (const auto  : Cases) {
@@ -1411,6 +1417,7 @@ class Foo final {})cpp";
 EXPECT_EQ(H->Value, Expected.Value);
 EXPECT_EQ(H->Size, Expected.Size);
 EXPECT_EQ(H->Offset, Expected.Offset);
+EXPECT_EQ(H->Align, Expected.Align);
 EXPECT_EQ(H->AccessSpecifier, Expected.AccessSpecifier);
 EXPECT_EQ(H->CalleeArgInfo, Expected.CalleeArgInfo);
 EXPECT_EQ(H->CallPassType, Expected.CallPassType);
@@ -3448,13 +3455,14 @@ template  class Foo {})",
 HI.Size = 32;
 HI.Offset = 96;
 HI.Padding = 32;
+HI.Align = 32;
   },
   R"(field foo
 
 Type: type (aka can_type)
 Value = value
 Offset: 12 bytes
-Size: 4 bytes (+4 bytes padding)
+Size: 4 bytes (+4 bytes padding), alignment 4 bytes
 
 // In test::Bar
 def)",
@@ -3470,13 +3478,14 @@ def)",
 HI.Size = 25;
 HI.Offset = 35;
 HI.Padding = 4;
+   

[clang-tools-extra] [clangd] Show alignment for records and fields decls (PR #67213)

2023-10-21 Thread via cfe-commits

https://github.com/sr-tream updated 
https://github.com/llvm/llvm-project/pull/67213

>From bf024310a4fe796a497880c0e2bd6a27c86ce7f5 Mon Sep 17 00:00:00 2001
From: SR_team 
Date: Sat, 21 Oct 2023 21:24:26 +0300
Subject: [PATCH] [clangd] Show alignment for records and fields decls

---
 clang-tools-extra/clangd/Hover.cpp|  5 +
 clang-tools-extra/clangd/Hover.h  |  2 ++
 clang-tools-extra/clangd/unittests/HoverTests.cpp | 11 +++
 3 files changed, 18 insertions(+)

diff --git a/clang-tools-extra/clangd/Hover.cpp 
b/clang-tools-extra/clangd/Hover.cpp
index 0ec85fc24df151b..933c69294b40926 100644
--- a/clang-tools-extra/clangd/Hover.cpp
+++ b/clang-tools-extra/clangd/Hover.cpp
@@ -1001,6 +1001,8 @@ void addLayoutInfo(const NamedDecl , HoverInfo ) {
   if (auto *RD = llvm::dyn_cast()) {
 if (auto Size = Ctx.getTypeSizeInCharsIfKnown(RD->getTypeForDecl()))
   HI.Size = Size->getQuantity() * 8;
+if (!RD->isDependentType() && RD->isCompleteDefinition())
+  HI.Align = Ctx.getTypeAlign(RD->getTypeForDecl());
 return;
   }
 
@@ -1009,6 +1011,7 @@ void addLayoutInfo(const NamedDecl , HoverInfo ) {
 if (Record)
   Record = Record->getDefinition();
 if (Record && !Record->isInvalidDecl() && !Record->isDependentType()) {
+  HI.Align = Ctx.getTypeAlign(FD->getType());
   const ASTRecordLayout  = Ctx.getASTRecordLayout(Record);
   HI.Offset = Layout.getFieldOffset(FD->getFieldIndex());
   if (FD->isBitField())
@@ -1487,6 +1490,8 @@ markup::Document HoverInfo::present() const {
   P.appendText(
   llvm::formatv(" (+{0} padding)", formatSize(*Padding)).str());
 }
+if (Align)
+  P.appendText(", alignment " + formatSize(*Align));
   }
 
   if (CalleeArgInfo) {
diff --git a/clang-tools-extra/clangd/Hover.h b/clang-tools-extra/clangd/Hover.h
index 6a61100912918ea..fe689de44732ebe 100644
--- a/clang-tools-extra/clangd/Hover.h
+++ b/clang-tools-extra/clangd/Hover.h
@@ -97,6 +97,8 @@ struct HoverInfo {
   std::optional Offset;
   /// Contains the padding following a field within the enclosing class.
   std::optional Padding;
+  /// Contains the alignment of fields and types where it's interesting.
+  std::optional Align;
   // Set when symbol is inside function call. Contains information extracted
   // from the callee definition about the argument this is passed as.
   std::optional CalleeArgInfo;
diff --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp 
b/clang-tools-extra/clangd/unittests/HoverTests.cpp
index 8c88cd52574536c..c5623759a7c2041 100644
--- a/clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -92,6 +92,7 @@ TEST(Hover, Structured) {
  HI.Offset = 0;
  HI.Size = 8;
  HI.Padding = 56;
+ HI.Align = 8;
  HI.AccessSpecifier = "private";
}},
   // Union field
@@ -110,6 +111,7 @@ TEST(Hover, Structured) {
  HI.Type = "char";
  HI.Size = 8;
  HI.Padding = 120;
+ HI.Align = 8;
  HI.AccessSpecifier = "public";
}},
   // Bitfield
@@ -128,6 +130,7 @@ TEST(Hover, Structured) {
  HI.Type = "int";
  HI.Offset = 0;
  HI.Size = 1;
+ HI.Align = 32;
  HI.AccessSpecifier = "public";
}},
   // Local to class method.
@@ -192,6 +195,7 @@ TEST(Hover, Structured) {
  HI.Type = "char";
  HI.Offset = 0;
  HI.Size = 8;
+ HI.Align = 8;
  HI.AccessSpecifier = "public";
}},
   // Struct definition shows size.
@@ -204,6 +208,7 @@ TEST(Hover, Structured) {
  HI.Kind = index::SymbolKind::Struct;
  HI.Definition = "struct X {}";
  HI.Size = 8;
+ HI.Align = 8;
}},
   // Variable with template type
   {R"cpp(
@@ -1375,6 +1380,7 @@ class Foo final {})cpp";
  HI.Offset = 8;
  HI.Size = 1;
  HI.Padding = 23;
+ HI.Align = 8;
  HI.AccessSpecifier = "public";
}}};
   for (const auto  : Cases) {
@@ -1411,6 +1417,7 @@ class Foo final {})cpp";
 EXPECT_EQ(H->Value, Expected.Value);
 EXPECT_EQ(H->Size, Expected.Size);
 EXPECT_EQ(H->Offset, Expected.Offset);
+EXPECT_EQ(H->Align, Expected.Align);
 EXPECT_EQ(H->AccessSpecifier, Expected.AccessSpecifier);
 EXPECT_EQ(H->CalleeArgInfo, Expected.CalleeArgInfo);
 EXPECT_EQ(H->CallPassType, Expected.CallPassType);
@@ -3448,6 +3455,7 @@ template  class Foo {})",
 HI.Size = 32;
 HI.Offset = 96;
 HI.Padding = 32;
+HI.Align = 32;
   },
   R"(field foo
 
@@ -3455,6 +3463,7 @@ Type: type (aka can_type)
 Value = value
 Offset: 12 bytes
 Size: 4 bytes (+4 bytes padding)
+Align: 4 bytes
 
 // In test::Bar
 def)",
@@ -3470,6 +3479,7 @@ def)",
 HI.Size = 25;
 HI.Offset = 35;
 HI.Padding = 4;
+HI.Align = 64;
   },

[clang-tools-extra] [clangd] Show alignment for records and fields decls (PR #67213)

2023-10-21 Thread via cfe-commits


@@ -1488,6 +1491,8 @@ markup::Document HoverInfo::present() const {
   llvm::formatv(" (+{0} padding)", formatSize(*Padding)).str());
 }
   }
+  if (Align)
+Output.addParagraph().appendText("Align: " + formatSize(*Align));

sr-tream wrote:

Yeah, it's looks better

![image](https://github.com/llvm/llvm-project/assets/12231048/a58f9b99-f8d4-4cf3-8b24-fb251136791b)
![image](https://github.com/llvm/llvm-project/assets/12231048/ac9d1693-fc65-453a-9160-be466f99d481)


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


[clang] [clang][Interp] Implement builtin_expect (PR #69713)

2023-10-21 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/69713

>From 1d60343ec3acb89764ab56a7035e1d7355e741ed Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Fri, 20 Oct 2023 14:16:22 +0200
Subject: [PATCH] [clang][Interp] Implement builtin_expect

---
 clang/lib/AST/Interp/InterpBuiltin.cpp| 64 +++
 clang/test/AST/Interp/builtin-functions.cpp   |  8 +++
 .../Sema/builtin-expect-with-probability.cpp  |  1 +
 3 files changed, 73 insertions(+)

diff --git a/clang/lib/AST/Interp/InterpBuiltin.cpp 
b/clang/lib/AST/Interp/InterpBuiltin.cpp
index 7552c1b88cff60c..48678b468e82ed5 100644
--- a/clang/lib/AST/Interp/InterpBuiltin.cpp
+++ b/clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -33,6 +33,19 @@ PrimType getIntPrimType(const InterpState ) {
   llvm_unreachable("Int isn't 16 or 32 bit?");
 }
 
+PrimType getLongPrimType(const InterpState ) {
+  const TargetInfo  = S.getCtx().getTargetInfo();
+  unsigned LongWidth = TI.getLongWidth();
+
+  if (LongWidth == 64)
+return PT_Sint64;
+  else if (LongWidth == 32)
+return PT_Sint32;
+  else if (LongWidth == 16)
+return PT_Sint16;
+  llvm_unreachable("long isn't 16, 32 or 64 bit?");
+}
+
 /// Peek an integer value from the stack into an APSInt.
 static APSInt peekToAPSInt(InterpStack , PrimType T, size_t Offset = 0) {
   if (Offset == 0)
@@ -59,6 +72,19 @@ static void pushInt(InterpState , int32_t Val) {
 llvm_unreachable("Int isn't 16 or 32 bit?");
 }
 
+/// Pushes \p Val to the stack, as a target-dependent 'long'.
+static void pushLong(InterpState , int64_t Val) {
+  PrimType LongType = getLongPrimType(S);
+  if (LongType == PT_Sint64)
+S.Stk.push>(Integral<64, true>::from(Val));
+  else if (LongType == PT_Sint32)
+S.Stk.push>(Integral<32, true>::from(Val));
+  else if (LongType == PT_Sint16)
+S.Stk.push>(Integral<16, true>::from(Val));
+  else
+llvm_unreachable("Long isn't 16, 32 or 64 bit?");
+}
+
 static bool retInt(InterpState , CodePtr OpPC, APValue ) {
   PrimType IntType = getIntPrimType(S);
   if (IntType == PT_Sint32)
@@ -68,6 +94,17 @@ static bool retInt(InterpState , CodePtr OpPC, APValue 
) {
   llvm_unreachable("Int isn't 16 or 32 bit?");
 }
 
+static bool retLong(InterpState , CodePtr OpPC, APValue ) {
+  PrimType LongType = getLongPrimType(S);
+  if (LongType == PT_Sint64)
+return Ret(S, OpPC, Result);
+  else if (LongType == PT_Sint32)
+return Ret(S, OpPC, Result);
+  else if (LongType == PT_Sint16)
+return Ret(S, OpPC, Result);
+  llvm_unreachable("Int isn't 16 or 32 bit?");
+}
+
 static void pushSizeT(InterpState , uint64_t Val) {
   const TargetInfo  = S.getCtx().getTargetInfo();
   unsigned SizeTWidth = TI.getTypeWidth(TI.getSizeType());
@@ -409,6 +446,27 @@ static bool interp__builtin_popcount(InterpState , 
CodePtr OpPC,
   return true;
 }
 
+// __builtin_expect(long, long) or
+// __builtin_expect_with_probability(long, long, double)
+static bool interp__builtin_expect(InterpState , CodePtr OpPC,
+   const InterpFrame *Frame,
+   const Function *Func, const CallExpr *Call) 
{
+  // The return value is simply the value of the first parameter.
+  // We ignore the probability.
+  unsigned NumArgs = Call->getNumArgs();
+  PrimType ArgT = *S.getContext().classify(Call->getArg(0)->getType());
+
+  assert(NumArgs == 2 || NumArgs == 3);
+
+  unsigned Offset = align(primSize(getLongPrimType(S))) * 2;
+  if (NumArgs == 3)
+Offset += align(primSize(PT_Float));
+
+  APSInt Val = peekToAPSInt(S.Stk, ArgT, Offset);
+  pushLong(S, Val.getSExtValue());
+  return true;
+}
+
 bool InterpretBuiltin(InterpState , CodePtr OpPC, const Function *F,
   const CallExpr *Call) {
   InterpFrame *Frame = S.Current;
@@ -534,6 +592,12 @@ bool InterpretBuiltin(InterpState , CodePtr OpPC, const 
Function *F,
   return retInt(S, OpPC, Dummy);
 break;
 
+  case Builtin::BI__builtin_expect:
+  case Builtin::BI__builtin_expect_with_probability:
+if (interp__builtin_expect(S, OpPC, Frame, F, Call))
+  return retLong(S, OpPC, Dummy);
+break;
+
   default:
 return false;
   }
diff --git a/clang/test/AST/Interp/builtin-functions.cpp 
b/clang/test/AST/Interp/builtin-functions.cpp
index 65361d67d68d578..d928b494a5204a6 100644
--- a/clang/test/AST/Interp/builtin-functions.cpp
+++ b/clang/test/AST/Interp/builtin-functions.cpp
@@ -282,3 +282,11 @@ namespace popcount {
   char popcount9[__builtin_popcountll(0xF0F0LL) == 8 ? 1 : -1];
   char popcount10[__builtin_popcountll(~0LL) == BITSIZE(long long) ? 1 : -1];
 }
+
+namespace expect {
+  constexpr int a() {
+return 12;
+  }
+  static_assert(__builtin_expect(a(),1) == 12, "");
+  static_assert(__builtin_expect_with_probability(a(), 1, 1.0) == 12, "");
+}
diff --git a/clang/test/Sema/builtin-expect-with-probability.cpp 
b/clang/test/Sema/builtin-expect-with-probability.cpp
index 2b72c7b27ae93e8..c55cde84b254834 100644
--- 

[PATCH] D157252: [clang][ExprConst] Handle 0 type size in builtin_memcpy etc.

2023-10-21 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 557826.

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

https://reviews.llvm.org/D157252

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/test/Sema/builtin-memcpy.c


Index: clang/test/Sema/builtin-memcpy.c
===
--- /dev/null
+++ clang/test/Sema/builtin-memcpy.c
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify=c
+// RUN: %clang_cc1 -x c++ %s -fsyntax-only -verify=cxx
+
+// cxx-no-diagnostics
+
+
+/// Zero-sized structs should not crash.
+int b() {
+  struct {  } a[10];
+  __builtin_memcpy([2], a, 2); // c-warning {{buffer has size 0, but size 
argument is 2}}
+  return 0;
+}
+
+#ifdef __cplusplus
+constexpr int b2() {
+  struct {  } a[10];
+  __builtin_memcpy([2], a, 2);
+  return 0;
+}
+static_assert(b2() == 0, "");
+#endif
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -9545,6 +9545,8 @@
 
 // Figure out how many T's we're copying.
 uint64_t TSize = Info.Ctx.getTypeSizeInChars(T).getQuantity();
+if (TSize == 0)
+  return false;
 if (!WChar) {
   uint64_t Remainder;
   llvm::APInt OrigN = N;


Index: clang/test/Sema/builtin-memcpy.c
===
--- /dev/null
+++ clang/test/Sema/builtin-memcpy.c
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify=c
+// RUN: %clang_cc1 -x c++ %s -fsyntax-only -verify=cxx
+
+// cxx-no-diagnostics
+
+
+/// Zero-sized structs should not crash.
+int b() {
+  struct {  } a[10];
+  __builtin_memcpy([2], a, 2); // c-warning {{buffer has size 0, but size argument is 2}}
+  return 0;
+}
+
+#ifdef __cplusplus
+constexpr int b2() {
+  struct {  } a[10];
+  __builtin_memcpy([2], a, 2);
+  return 0;
+}
+static_assert(b2() == 0, "");
+#endif
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -9545,6 +9545,8 @@
 
 // Figure out how many T's we're copying.
 uint64_t TSize = Info.Ctx.getTypeSizeInChars(T).getQuantity();
+if (TSize == 0)
+  return false;
 if (!WChar) {
   uint64_t Remainder;
   llvm::APInt OrigN = N;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157252: [clang][ExprConst] Handle 0 type size in builtin_memcpy etc.

2023-10-21 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/test/Sema/builtin-memcpy.c:4-8
+int b() {
+  struct {  } a[10];
+  __builtin_memcpy([2], a, 2); // expected-warning {{buffer has size 0, but 
size argument is 2}}
+  return 0;
+}

aaron.ballman wrote:
> The only other test I'd like to see is one like:
> ```
> constexpr int b() {
>   struct {  } a[10];
>   __builtin_memcpy([2], a, 2); // UB here should be caught, right?
>   return 0;
> }
> 
> static_assert(b() == 0, "");
> ```
> (if that's follow-up work, that's fine too, just leave a test with a FIXME 
> comment.)
Nope, clang accepts that and GCC rejects the function when calling.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157252

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


[clang] [NFC] use `StringSet::insert(iter, iter)` instead for loop to insert (PR #69851)

2023-10-21 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 created 
https://github.com/llvm/llvm-project/pull/69851

None

>From 37f6822035845f120d2fb995a607561621c3892e Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Sun, 22 Oct 2023 00:27:04 +0800
Subject: [PATCH] [NFC] use `StringSet::insert(iter, iter)` instead for loop to
 insert elements

---
 clang/lib/ARCMigrate/ObjCMT.cpp | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/clang/lib/ARCMigrate/ObjCMT.cpp b/clang/lib/ARCMigrate/ObjCMT.cpp
index 8458a72d6a2482b..4fa4ab8d42b7d3e 100644
--- a/clang/lib/ARCMigrate/ObjCMT.cpp
+++ b/clang/lib/ARCMigrate/ObjCMT.cpp
@@ -123,9 +123,7 @@ class ObjCMigrateASTConsumer : public ASTConsumer {
 NSIntegerTypedefed(nullptr), NSUIntegerTypedefed(nullptr),
 Remapper(remapper), FileMgr(fileMgr), PPRec(PPRec), PP(PP),
 IsOutputFile(isOutputFile), FoundationIncluded(false) {
-// FIXME: StringSet should have insert(iter, iter) to use here.
-for (const std::string  : AllowList)
-  AllowListFilenames.insert(Val);
+AllowListFilenames.insert(AllowList.begin(), AllowList.end());
   }
 
 protected:

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


[clang] [clang-format] Add a new style for the clang-format source code (PR #69814)

2023-10-21 Thread Owen Pan via cfe-commits

owenca wrote:

I was wondering myself. Will undo it before merging.

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


[clang] [clang]improve diagnosing redefined defaulted constructor with different exception specs (PR #69688)

2023-10-21 Thread Congcong Cai via cfe-commits

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

>From 2629b346123f9838a4fc3d8b6fb6a98508773965 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Fri, 20 Oct 2023 15:45:42 +0800
Subject: [PATCH 1/2] [clang]improve diagnosing redefined defaulted constructor
 with different exception specs

It is misleading when diagnosing 'ExplicitlySpecialMethod' is missing exception 
specification 'noexcept' for
```c++
struct ExplicitlySpecialMethod {
  ExplicitlySpecialMethod() = default;
};
ExplicitlySpecialMethod::ExplicitlySpecialMethod() {}
```
Fixes: #69094
---
 clang/docs/ReleaseNotes.rst   |  3 +++
 clang/lib/Sema/SemaDecl.cpp   | 25 ++-
 ...agnoise-prioritiy-exception-redefining.cpp |  9 +++
 3 files changed, 25 insertions(+), 12 deletions(-)
 create mode 100644 
clang/test/SemaCXX/diagnoise-prioritiy-exception-redefining.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index fc8caf9221b9d29..ae995a12cf0fd7d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -325,6 +325,9 @@ Improvements to Clang's diagnostics
   |   ~^~~~
 - Clang now always diagnoses when using non-standard layout types in 
``offsetof`` .
   (`#64619: `_)
+- Clang now diagnoses redefined defaulted constructor when redefined
+  defaulted constructor with different exception specs.
+  (`#69094: `_)
 
 Bug Fixes in This Version
 -
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index b363b0db79f164d..c4979b51e68f5e2 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -3922,18 +3922,6 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, 
NamedDecl *, Scope *S,
   }
 
   if (getLangOpts().CPlusPlus) {
-// C++1z [over.load]p2
-//   Certain function declarations cannot be overloaded:
-// -- Function declarations that differ only in the return type,
-//the exception specification, or both cannot be overloaded.
-
-// Check the exception specifications match. This may recompute the type of
-// both Old and New if it resolved exception specifications, so grab the
-// types again after this. Because this updates the type, we do this before
-// any of the other checks below, which may update the "de facto" NewQType
-// but do not necessarily update the type of New.
-if (CheckEquivalentExceptionSpec(Old, New))
-  return true;
 OldQType = Context.getCanonicalType(Old->getType());
 NewQType = Context.getCanonicalType(New->getType());
 
@@ -4055,6 +4043,19 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, 
NamedDecl *, Scope *S,
   }
 }
 
+// C++1z [over.load]p2
+//   Certain function declarations cannot be overloaded:
+// -- Function declarations that differ only in the return type,
+//the exception specification, or both cannot be overloaded.
+
+// Check the exception specifications match. This may recompute the type of
+// both Old and New if it resolved exception specifications, so grab the
+// types again after this. Because this updates the type, we do this before
+// any of the other checks below, which may update the "de facto" NewQType
+// but do not necessarily update the type of New.
+if (CheckEquivalentExceptionSpec(Old, New))
+  return true;
+
 // C++11 [dcl.attr.noreturn]p1:
 //   The first declaration of a function shall specify the noreturn
 //   attribute if any declaration of that function specifies the noreturn
diff --git a/clang/test/SemaCXX/diagnoise-prioritiy-exception-redefining.cpp 
b/clang/test/SemaCXX/diagnoise-prioritiy-exception-redefining.cpp
new file mode 100644
index 000..ad025bf041ce519
--- /dev/null
+++ b/clang/test/SemaCXX/diagnoise-prioritiy-exception-redefining.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -fcxx-exceptions -std=c++11 %s
+
+struct ExplicitlySpecialMethod {
+  ExplicitlySpecialMethod() = default;
+};
+ExplicitlySpecialMethod::ExplicitlySpecialMethod() {} // 
expected-error{{definition of explicitly defaulted default constructor}}
+
+struct ImplicitlySpecialMethod {};
+ImplicitlySpecialMethod::ImplicitlySpecialMethod() {} // 
expected-error{{definition of implicitly declared default constructor}}

>From a58d6f45d5c4e09e655fd9d4d6111a9605b8a434 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Sun, 22 Oct 2023 00:14:02 +0800
Subject: [PATCH 2/2] fix typo

---
 ...redefining.cpp => diagnose-prioritiy-exception-redefining.cpp} | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename clang/test/SemaCXX/{diagnoise-prioritiy-exception-redefining.cpp => 
diagnose-prioritiy-exception-redefining.cpp} (100%)

diff --git a/clang/test/SemaCXX/diagnoise-prioritiy-exception-redefining.cpp 

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

2023-10-21 Thread via cfe-commits

https://github.com/robozati converted_to_draft 
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] [clang] Bounds checking on unclosed parentheses, brackets or braces in Expanded Tokens (PR #69849)

2023-10-21 Thread via cfe-commits

robozati wrote:

Tests are failing because of the `findExpanded` function, but it didn’t result 
in UB. Will fix the test later.

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] [clang] Bounds checking on unclosed parentheses, brackets or braces in Expanded Tokens (PR #69849)

2023-10-21 Thread via cfe-commits

https://github.com/robozati updated 
https://github.com/llvm/llvm-project/pull/69849

>From e57657cf296e1e93fa17f021bb8ce591071b2176 Mon Sep 17 00:00:00 2001
From: robozati <139823421+roboz...@users.noreply.github.com>
Date: Sat, 21 Oct 2023 12:04:14 -0300
Subject: [PATCH 1/2] Fix UB on unclosed parentheses, brackets or braces in
 Tokens

---
 clang/lib/Tooling/Syntax/Tokens.cpp   | 23 ++-
 clang/unittests/Tooling/Syntax/TokensTest.cpp |  6 +
 2 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/clang/lib/Tooling/Syntax/Tokens.cpp 
b/clang/lib/Tooling/Syntax/Tokens.cpp
index 2f28b9cf286a638..e4c24aa1ef3fbf0 100644
--- a/clang/lib/Tooling/Syntax/Tokens.cpp
+++ b/clang/lib/Tooling/Syntax/Tokens.cpp
@@ -286,9 +286,13 @@ TokenBuffer::spelledForExpandedToken(const syntax::Token 
*Expanded) const {
   });
   // Our token could only be produced by the previous mapping.
   if (It == File.Mappings.begin()) {
-// No previous mapping, no need to modify offsets.
-return {[ExpandedIndex - File.BeginExpanded],
-/*Mapping=*/nullptr};
+const auto offset = ExpandedIndex - File.BeginExpanded;
+// Bounds check so parsing an unclosed parenthesis, brackets or braces do
+// not result in UB.
+if (offset >= File.SpelledTokens.size()) {
+  return {nullptr, nullptr};
+}
+return {[offset], /*Mapping=*/nullptr};
   }
   --It; // 'It' now points to last mapping that started before our token.
 
@@ -298,9 +302,12 @@ TokenBuffer::spelledForExpandedToken(const syntax::Token 
*Expanded) const {
 
   // Not part of the mapping, use the index from previous mapping to compute 
the
   // corresponding spelled token.
-  return {
-  [It->EndSpelled + (ExpandedIndex - It->EndExpanded)],
-  /*Mapping=*/nullptr};
+  const auto offset = It->EndSpelled + (ExpandedIndex - It->EndExpanded);
+  // This index can also result in UB when parsing unclosed tokens.
+  if (offset >= File.SpelledTokens.size()) {
+return {nullptr, nullptr};
+  }
+  return {[offset], /*Mapping=*/nullptr};
 }
 
 const TokenBuffer::Mapping *
@@ -410,6 +417,10 @@ 
TokenBuffer::spelledForExpanded(llvm::ArrayRef Expanded) const {
   auto [FirstSpelled, FirstMapping] = spelledForExpandedToken(First);
   auto [LastSpelled, LastMapping] = spelledForExpandedToken(Last);
 
+  if (FirstSpelled == nullptr || LastSpelled == nullptr) {
+return std::nullopt;
+  };
+
   FileID FID = SourceMgr->getFileID(FirstSpelled->location());
   // FIXME: Handle multi-file changes by trying to map onto a common root.
   if (FID != SourceMgr->getFileID(LastSpelled->location()))
diff --git a/clang/unittests/Tooling/Syntax/TokensTest.cpp 
b/clang/unittests/Tooling/Syntax/TokensTest.cpp
index 0c08318a637c0b6..44f0c57b3bad875 100644
--- a/clang/unittests/Tooling/Syntax/TokensTest.cpp
+++ b/clang/unittests/Tooling/Syntax/TokensTest.cpp
@@ -814,6 +814,12 @@ TEST_F(TokenBufferTest, SpelledByExpanded) {
   EXPECT_THAT(Buffer.spelledForExpanded(findExpanded("good")),
   ValueIs(SameRange(findSpelled("good";
   EXPECT_EQ(Buffer.spelledForExpanded(findExpanded("prev good")), 
std::nullopt);
+
+  // Unclosed parentheses, brackets or braces do not result in a UB
+  recordTokens(R"cpp(
+foo(x
+  )cpp");
+  EXPECT_EQ(Buffer.spelledForExpanded(findExpanded("x")), std::nullopt);
 }
 
 TEST_F(TokenBufferTest, ExpandedTokensForRange) {

>From 474e43fdf6682f83e4a7839eabe2f4c2f5fc1b92 Mon Sep 17 00:00:00 2001
From: robozati <139823421+roboz...@users.noreply.github.com>
Date: Sat, 21 Oct 2023 12:58:43 -0300
Subject: [PATCH 2/2] Fix failing test

---
 clang/unittests/Tooling/Syntax/TokensTest.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/unittests/Tooling/Syntax/TokensTest.cpp 
b/clang/unittests/Tooling/Syntax/TokensTest.cpp
index 44f0c57b3bad875..2b7b1474228c4d0 100644
--- a/clang/unittests/Tooling/Syntax/TokensTest.cpp
+++ b/clang/unittests/Tooling/Syntax/TokensTest.cpp
@@ -819,7 +819,7 @@ TEST_F(TokenBufferTest, SpelledByExpanded) {
   recordTokens(R"cpp(
 foo(x
   )cpp");
-  EXPECT_EQ(Buffer.spelledForExpanded(findExpanded("x")), std::nullopt);
+  EXPECT_EQ(Buffer.spelledForExpanded(findExpanded("foo(x)")), std::nullopt);
 }
 
 TEST_F(TokenBufferTest, ExpandedTokensForRange) {

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


[clang-tools-extra] [clangd] Show alignment for records and fields decls (PR #67213)

2023-10-21 Thread Vlad Serebrennikov via cfe-commits


@@ -1488,6 +1491,8 @@ markup::Document HoverInfo::present() const {
   llvm::formatv(" (+{0} padding)", formatSize(*Padding)).str());
 }
   }
+  if (Align)
+Output.addParagraph().appendText("Align: " + formatSize(*Align));

Endilll wrote:

That would work, but I'd prefer `Size 24 bytes, alignment 8 bytes` wording. I 
don't think alignment as a property of type is secondary to size to put it in 
parentheses.

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


[clang-tools-extra] [clangd] Show alignment for records and fields decls (PR #67213)

2023-10-21 Thread via cfe-commits


@@ -1488,6 +1491,8 @@ markup::Document HoverInfo::present() const {
   llvm::formatv(" (+{0} padding)", formatSize(*Padding)).str());
 }
   }
+  if (Align)
+Output.addParagraph().appendText("Align: " + formatSize(*Align));

sr-tream wrote:

> My preference would be to have alignment on the same line as size

But size may include padding for member fields. How would you like to see it?

Like this?
```
Size 24 bytes (8 bytes align) // for structs/classes
Size 1 byte (+7 bytes padding, 8 bytes align) // for member fields with padding
```

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


[clang-tools-extra] [clangd] Show alignment for records and fields decls (PR #67213)

2023-10-21 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

On the topic of ABI, Itanium and Microsoft type layouts are not compatible, 
even for standard-layout (POD) types. For 
[example](https://godbolt.org/z/zxfvMa9nE), bit-fields are 
[allowed](http://eel.is/c++draft/class.prop#3) in standard-layout types, but 
only Microsoft ABI mandates that bit-fields of different types can't be 
combined, and have to be padded. That's why almost all bit-fields in Clang are 
`unsigned`, without regards to types of values they hold. So author did the 
right thing asking Clang for alignment of types. 

Triviality is another aspect of what has been known as POD, and has nothing to 
do with layouts: http://eel.is/c++draft/class.prop#2

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


[clang-tools-extra] [clangd] Show alignment for records and fields decls (PR #67213)

2023-10-21 Thread Vlad Serebrennikov via cfe-commits


@@ -1488,6 +1491,8 @@ markup::Document HoverInfo::present() const {
   llvm::formatv(" (+{0} padding)", formatSize(*Padding)).str());
 }
   }
+  if (Align)
+Output.addParagraph().appendText("Align: " + formatSize(*Align));

Endilll wrote:

My preference would be to have alignment on the same line as size, so that less 
vertical space is wasted. The following hover should illustrate why this might 
be more important than it appears on other hovers posted in this PR: 
![image](https://github.com/llvm/llvm-project/assets/12883766/426a6770-3675-46eb-9f33-0d01429f7aa8)

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


[clang-tools-extra] [clangd] Show alignment for records and fields decls (PR #67213)

2023-10-21 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll edited 
https://github.com/llvm/llvm-project/pull/67213
___
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-10-21 Thread via cfe-commits

https://github.com/robozati created 
https://github.com/llvm/llvm-project/pull/69849

When getting the AST from clangd, if there is an unclosed token, a segfault or 
an UB can happen when accessing `File.SpelledTokens` because the supposed 
closing token is not present, so its index is greater than the vec's size.

This fixes the issue by returning a `nullptr` on the function that caused the 
UB and then checking if the spelled token is null, returning `nullopt` for the 
whole expanded token.

Fixes https://github.com/clangd/clangd/issues/1559.

>From e57657cf296e1e93fa17f021bb8ce591071b2176 Mon Sep 17 00:00:00 2001
From: robozati <139823421+roboz...@users.noreply.github.com>
Date: Sat, 21 Oct 2023 12:04:14 -0300
Subject: [PATCH] Fix UB on unclosed parentheses, brackets or braces in Tokens

---
 clang/lib/Tooling/Syntax/Tokens.cpp   | 23 ++-
 clang/unittests/Tooling/Syntax/TokensTest.cpp |  6 +
 2 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/clang/lib/Tooling/Syntax/Tokens.cpp 
b/clang/lib/Tooling/Syntax/Tokens.cpp
index 2f28b9cf286a638..e4c24aa1ef3fbf0 100644
--- a/clang/lib/Tooling/Syntax/Tokens.cpp
+++ b/clang/lib/Tooling/Syntax/Tokens.cpp
@@ -286,9 +286,13 @@ TokenBuffer::spelledForExpandedToken(const syntax::Token 
*Expanded) const {
   });
   // Our token could only be produced by the previous mapping.
   if (It == File.Mappings.begin()) {
-// No previous mapping, no need to modify offsets.
-return {[ExpandedIndex - File.BeginExpanded],
-/*Mapping=*/nullptr};
+const auto offset = ExpandedIndex - File.BeginExpanded;
+// Bounds check so parsing an unclosed parenthesis, brackets or braces do
+// not result in UB.
+if (offset >= File.SpelledTokens.size()) {
+  return {nullptr, nullptr};
+}
+return {[offset], /*Mapping=*/nullptr};
   }
   --It; // 'It' now points to last mapping that started before our token.
 
@@ -298,9 +302,12 @@ TokenBuffer::spelledForExpandedToken(const syntax::Token 
*Expanded) const {
 
   // Not part of the mapping, use the index from previous mapping to compute 
the
   // corresponding spelled token.
-  return {
-  [It->EndSpelled + (ExpandedIndex - It->EndExpanded)],
-  /*Mapping=*/nullptr};
+  const auto offset = It->EndSpelled + (ExpandedIndex - It->EndExpanded);
+  // This index can also result in UB when parsing unclosed tokens.
+  if (offset >= File.SpelledTokens.size()) {
+return {nullptr, nullptr};
+  }
+  return {[offset], /*Mapping=*/nullptr};
 }
 
 const TokenBuffer::Mapping *
@@ -410,6 +417,10 @@ 
TokenBuffer::spelledForExpanded(llvm::ArrayRef Expanded) const {
   auto [FirstSpelled, FirstMapping] = spelledForExpandedToken(First);
   auto [LastSpelled, LastMapping] = spelledForExpandedToken(Last);
 
+  if (FirstSpelled == nullptr || LastSpelled == nullptr) {
+return std::nullopt;
+  };
+
   FileID FID = SourceMgr->getFileID(FirstSpelled->location());
   // FIXME: Handle multi-file changes by trying to map onto a common root.
   if (FID != SourceMgr->getFileID(LastSpelled->location()))
diff --git a/clang/unittests/Tooling/Syntax/TokensTest.cpp 
b/clang/unittests/Tooling/Syntax/TokensTest.cpp
index 0c08318a637c0b6..44f0c57b3bad875 100644
--- a/clang/unittests/Tooling/Syntax/TokensTest.cpp
+++ b/clang/unittests/Tooling/Syntax/TokensTest.cpp
@@ -814,6 +814,12 @@ TEST_F(TokenBufferTest, SpelledByExpanded) {
   EXPECT_THAT(Buffer.spelledForExpanded(findExpanded("good")),
   ValueIs(SameRange(findSpelled("good";
   EXPECT_EQ(Buffer.spelledForExpanded(findExpanded("prev good")), 
std::nullopt);
+
+  // Unclosed parentheses, brackets or braces do not result in a UB
+  recordTokens(R"cpp(
+foo(x
+  )cpp");
+  EXPECT_EQ(Buffer.spelledForExpanded(findExpanded("x")), std::nullopt);
 }
 
 TEST_F(TokenBufferTest, ExpandedTokensForRange) {

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


[clang-tools-extra] [clangd] Show alignment for records and fields decls (PR #67213)

2023-10-21 Thread Vlad Serebrennikov via cfe-commits

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

LGTM, but you should wait for other reviewers before merging.

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


[clang] Pass QualifiedRenameRule strings by reference to reduce copies (PR #69848)

2023-10-21 Thread via cfe-commits

https://github.com/mfdeakin created 
https://github.com/llvm/llvm-project/pull/69848

Fixes #34652

>From 0052d66e15451af47ebf8f2c4b060ea21a75f4a4 Mon Sep 17 00:00:00 2001
From: Michael Deakin 
Date: Thu, 19 Oct 2023 19:28:46 -0700
Subject: [PATCH] Pass QualifiedRenameRule strings by reference to reduce
 copies

Fixes #34652
---
 .../clang/Tooling/Refactoring/Rename/RenamingAction.h| 9 -
 clang/lib/Tooling/Refactoring/Rename/RenamingAction.cpp  | 4 ++--
 2 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/clang/include/clang/Tooling/Refactoring/Rename/RenamingAction.h 
b/clang/include/clang/Tooling/Refactoring/Rename/RenamingAction.h
index 43a8d56e4e71762..1ac3ea1aa6e36d6 100644
--- a/clang/include/clang/Tooling/Refactoring/Rename/RenamingAction.h
+++ b/clang/include/clang/Tooling/Refactoring/Rename/RenamingAction.h
@@ -68,15 +68,14 @@ class RenameOccurrences final : public 
SourceChangeRefactoringRule {
 
 class QualifiedRenameRule final : public SourceChangeRefactoringRule {
 public:
-  static Expected initiate(RefactoringRuleContext 
,
-std::string OldQualifiedName,
-std::string NewQualifiedName);
+  static Expected
+  initiate(RefactoringRuleContext , const std::string 
,
+   std::string &);
 
   static const RefactoringDescriptor ();
 
 private:
-  QualifiedRenameRule(const NamedDecl *ND,
-  std::string NewQualifiedName)
+  QualifiedRenameRule(const NamedDecl *ND, std::string &)
   : ND(ND), NewQualifiedName(std::move(NewQualifiedName)) {}
 
   Expected
diff --git a/clang/lib/Tooling/Refactoring/Rename/RenamingAction.cpp 
b/clang/lib/Tooling/Refactoring/Rename/RenamingAction.cpp
index 72598601d47d679..ba17d0b807a775a 100644
--- a/clang/lib/Tooling/Refactoring/Rename/RenamingAction.cpp
+++ b/clang/lib/Tooling/Refactoring/Rename/RenamingAction.cpp
@@ -89,8 +89,8 @@ 
RenameOccurrences::createSourceReplacements(RefactoringRuleContext ) {
 
 Expected
 QualifiedRenameRule::initiate(RefactoringRuleContext ,
-  std::string OldQualifiedName,
-  std::string NewQualifiedName) {
+  const std::string ,
+  std::string &) {
   const NamedDecl *ND =
   getNamedDeclFor(Context.getASTContext(), OldQualifiedName);
   if (!ND)

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


[clang] [analyzer][NFC] Substitute operator() with lambda in StreamChecker (PR #69844)

2023-10-21 Thread Balazs Benics via cfe-commits

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


[clang] f990650 - [analyzer][NFC] Substitute operator() with lambda in StreamChecker

2023-10-21 Thread via cfe-commits

Author: Ben Shi
Date: 2023-10-21T16:29:14+02:00
New Revision: f9906508bc4f05d3950e2219b4c56f6c078a61ef

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

LOG: [analyzer][NFC] Substitute operator() with lambda in StreamChecker

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index bad86682c91e25f..ef209f64f0c372c 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -407,23 +407,14 @@ class StreamChecker : public Checker std::string {
+  if (BR.isInteresting(StreamSym) && () == _ResourceLeak)
+return Message;
+  return "";
+});
   }
 
   const NoteTag *constructSetEofNoteTag(CheckerContext ,



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


[clang] [analyzer][NFC] Substitute operator() with lambda in StreamChecker (PR #69844)

2023-10-21 Thread Balazs Benics via cfe-commits

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


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


[clang] [analyzer][NFC] Substitute operator() with lambda in StreamChecker (PR #69844)

2023-10-21 Thread Ben Shi via cfe-commits


@@ -407,23 +407,15 @@ class StreamChecker : public Checker std::string {
+  if (BR.isInteresting(StreamSym) &&
+  () == &(this->BT_ResourceLeak))

benshi001 wrote:

Thanks. I fixed it.

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


[clang] [analyzer][NFC] Substitute operator() with lambda in StreamChecker (PR #69844)

2023-10-21 Thread Ben Shi via cfe-commits

https://github.com/benshi001 updated 
https://github.com/llvm/llvm-project/pull/69844

>From 615c6f8ecc4a97eeedc69c04b9a805ee56822c30 Mon Sep 17 00:00:00 2001
From: Ben Shi 
Date: Sat, 21 Oct 2023 21:33:50 +0800
Subject: [PATCH] [analyzer][NFC] Substitute operator() with lambda in
 StreamChecker

---
 .../StaticAnalyzer/Checkers/StreamChecker.cpp | 21 ++-
 1 file changed, 6 insertions(+), 15 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index bad86682c91e25f..ef209f64f0c372c 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -407,23 +407,14 @@ class StreamChecker : public Checker std::string {
+  if (BR.isInteresting(StreamSym) && () == _ResourceLeak)
+return Message;
+  return "";
+});
   }
 
   const NoteTag *constructSetEofNoteTag(CheckerContext ,

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


[clang] [analyzer][NFC] Substitute operator() with lambda in StreamChecker (PR #69844)

2023-10-21 Thread Balazs Benics via cfe-commits

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

Thanks.

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


[clang] [analyzer][NFC] Substitute operator() with lambda in StreamChecker (PR #69844)

2023-10-21 Thread Balazs Benics via cfe-commits


@@ -407,23 +407,15 @@ class StreamChecker : public Checker std::string {
+  if (BR.isInteresting(StreamSym) &&
+  () == &(this->BT_ResourceLeak))

steakhal wrote:

```suggestion
  () == _ResourceLeak)
```

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


[clang] [analyzer][NFC] Substitute operator() with lambda in StreamChecker (PR #69844)

2023-10-21 Thread Balazs Benics via cfe-commits

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


[clang] [analyzer][NFC] Substitute operator() with lambda in StreamChecker (PR #69844)

2023-10-21 Thread Ben Shi via cfe-commits

https://github.com/benshi001 created 
https://github.com/llvm/llvm-project/pull/69844

None

>From 0e8edd8448b0bacfaf35f415a5760d5d1a3aabb7 Mon Sep 17 00:00:00 2001
From: Ben Shi 
Date: Sat, 21 Oct 2023 21:33:50 +0800
Subject: [PATCH] [analyzer][NFC] Substitute operator() with lambda in
 StreamChecker

---
 .../StaticAnalyzer/Checkers/StreamChecker.cpp | 22 ++-
 1 file changed, 7 insertions(+), 15 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index bad86682c91e25f..76df39cb37bd985 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -407,23 +407,15 @@ class StreamChecker : public Checker std::string {
+  if (BR.isInteresting(StreamSym) &&
+  () == &(this->BT_ResourceLeak))
+return Message;
+  return "";
+});
   }
 
   const NoteTag *constructSetEofNoteTag(CheckerContext ,

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


[clang] [clang][Sema] Avoid non-empty unexpanded pack assertion for FunctionParmPackExpr (PR #69224)

2023-10-21 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 updated 
https://github.com/llvm/llvm-project/pull/69224

>From 89e486690f1a28900152d4eef023be6fdfcf296a Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Mon, 16 Oct 2023 22:50:08 +0800
Subject: [PATCH] [clang][Sema] Avoid non-empty unexpanded pack assertion for
 FunctionParmPackExpr

Closes https://github.com/llvm/llvm-project/issues/61460.

We have FunctionParmPackExpr that serves as the unexpanded
expression but from which the visitor collects none, which may
lead to assertion failure during the template instantiation.
---
 clang/docs/ReleaseNotes.rst |  2 ++
 clang/lib/Sema/SemaTemplateVariadic.cpp | 26 +++--
 clang/test/SemaCXX/pr61460.cpp  | 13 +
 3 files changed, 35 insertions(+), 6 deletions(-)
 create mode 100644 clang/test/SemaCXX/pr61460.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3a9a67f7451c092..e05bd9251702964 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -438,6 +438,8 @@ Bug Fixes in This Version
 - Clang no longer permits using the `_BitInt` types as an underlying type for 
an
   enumeration as specified in the C23 Standard.
   Fixes (`#69619 `_)
+- Fixed an issue that a benign assertion might hit when instantiating a pack 
expansion
+  inside a lambda. (`#61460 
`_)
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/Sema/SemaTemplateVariadic.cpp 
b/clang/lib/Sema/SemaTemplateVariadic.cpp
index dfcc78dafdc4c31..521d34dc18d0166 100644
--- a/clang/lib/Sema/SemaTemplateVariadic.cpp
+++ b/clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -388,8 +388,8 @@ bool Sema::DiagnoseUnexpandedParameterPack(SourceLocation 
Loc,
 return false;
 
   SmallVector Unexpanded;
-  CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseTypeLoc(
-  T->getTypeLoc());
+  CollectUnexpandedParameterPacksVisitor(Unexpanded)
+  .TraverseTypeLoc(T->getTypeLoc());
   assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
   return DiagnoseUnexpandedParameterPacks(Loc, UPPC, Unexpanded);
 }
@@ -402,6 +402,20 @@ bool Sema::DiagnoseUnexpandedParameterPack(Expr *E,
   if (!E->containsUnexpandedParameterPack())
 return false;
 
+  // Exception: The `CollectUnexpandedParameterPacksVisitor` collects nothing
+  // from a FunctionParmPackExpr. In the context where the collector is being
+  // used such as `collectUnexpandedParameterPacks`, this type of expression
+  // is not expected to be collected.
+  //
+  // Nonetheless, this function for diagnosis is still called anyway during
+  // template instantiation, with an expression of such a type if we're inside 
a
+  // lambda with unexpanded parameters.
+  //
+  // Rule out this case to prevent the assertion failure.
+  if (auto *Expr = dyn_cast(E);
+  Expr && getEnclosingLambda())
+return false;
+
   SmallVector Unexpanded;
   CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseStmt(E);
   assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
@@ -442,7 +456,7 @@ bool Sema::DiagnoseUnexpandedParameterPack(const 
CXXScopeSpec ,
 
   SmallVector Unexpanded;
   CollectUnexpandedParameterPacksVisitor(Unexpanded)
-.TraverseNestedNameSpecifier(SS.getScopeRep());
+  .TraverseNestedNameSpecifier(SS.getScopeRep());
   assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
   return DiagnoseUnexpandedParameterPacks(SS.getRange().getBegin(),
   UPPC, Unexpanded);
@@ -479,7 +493,7 @@ bool Sema::DiagnoseUnexpandedParameterPack(const 
DeclarationNameInfo ,
 
   SmallVector Unexpanded;
   CollectUnexpandedParameterPacksVisitor(Unexpanded)
-.TraverseType(NameInfo.getName().getCXXNameType());
+  .TraverseType(NameInfo.getName().getCXXNameType());
   assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
   return DiagnoseUnexpandedParameterPacks(NameInfo.getLoc(), UPPC, Unexpanded);
 }
@@ -493,7 +507,7 @@ bool Sema::DiagnoseUnexpandedParameterPack(SourceLocation 
Loc,
 
   SmallVector Unexpanded;
   CollectUnexpandedParameterPacksVisitor(Unexpanded)
-.TraverseTemplateName(Template);
+  .TraverseTemplateName(Template);
   assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
   return DiagnoseUnexpandedParameterPacks(Loc, UPPC, Unexpanded);
 }
@@ -506,7 +520,7 @@ bool 
Sema::DiagnoseUnexpandedParameterPack(TemplateArgumentLoc Arg,
 
   SmallVector Unexpanded;
   CollectUnexpandedParameterPacksVisitor(Unexpanded)
-.TraverseTemplateArgumentLoc(Arg);
+  .TraverseTemplateArgumentLoc(Arg);
   assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
   return DiagnoseUnexpandedParameterPacks(Arg.getLocation(), UPPC, Unexpanded);
 }
diff 

[clang] 7d7e4d2 - [Windows] Add git-clang-format wrapper bat file (#69228)

2023-10-21 Thread via cfe-commits

Author: Chris B
Date: 2023-10-21T08:14:29-05:00
New Revision: 7d7e4d20b077c1f64b0db88ab844ccb9214bd38c

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

LOG: [Windows] Add git-clang-format wrapper bat file (#69228)

This allows git-clang-format to be used on a Windows terminal without
manually needing to find the path and invoke the python interpreter. We
have a similar script for `scan-build`.

Fixes #69643

Added: 
clang/tools/clang-format/git-clang-format.bat

Modified: 
clang/tools/clang-format/CMakeLists.txt

Removed: 




diff  --git a/clang/tools/clang-format/CMakeLists.txt 
b/clang/tools/clang-format/CMakeLists.txt
index 30c93f8667c8359..1c61a3c8fb80368 100644
--- a/clang/tools/clang-format/CMakeLists.txt
+++ b/clang/tools/clang-format/CMakeLists.txt
@@ -38,3 +38,9 @@ install(FILES clang-format.py
 install(PROGRAMS git-clang-format
   DESTINATION "${CMAKE_INSTALL_BINDIR}"
   COMPONENT clang-format)
+
+if (WIN32 AND NOT CYGWIN)
+  install(PROGRAMS git-clang-format.bat
+DESTINATION "${CMAKE_INSTALL_BINDIR}"
+COMPONENT clang-format)
+endif()

diff  --git a/clang/tools/clang-format/git-clang-format.bat 
b/clang/tools/clang-format/git-clang-format.bat
new file mode 100644
index 000..d4bc5172989cb09
--- /dev/null
+++ b/clang/tools/clang-format/git-clang-format.bat
@@ -0,0 +1 @@
+py -3 git-clang-format %*



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


[clang] [Windows] Add git-clang-format wrapper bat file (PR #69228)

2023-10-21 Thread Chris B via cfe-commits

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


[clang] [clang][Sema] Avoid non-empty unexpanded pack assertion for FunctionParmPackExpr (PR #69224)

2023-10-21 Thread Younan Zhang via cfe-commits

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


[clang] [clang][Sema] Avoid non-empty unexpanded pack assertion for FunctionParmPackExpr (PR #69224)

2023-10-21 Thread Younan Zhang via cfe-commits

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


[clang-tools-extra] [clangd] Fix RawStringLiteral being available to C and C++ versions prior to C++11 (PR #69775)

2023-10-21 Thread via cfe-commits

robozati wrote:

@sam-mccall @kadircet Hello! I mentioned this PR in discord, but no one 
assigned themselves to review so I am pinging you.

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


[clang] [clang-format] Add a new style for the clang-format source code (PR #69814)

2023-10-21 Thread Emilia Kond via cfe-commits

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


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


[clang] [clang-format] Add a new style for the clang-format source code (PR #69814)

2023-10-21 Thread Emilia Kond via cfe-commits

rymiel wrote:

> I don't want to "advertise" this new style in the documentation but am 
> willing to be overruled by the majority.

But you added it to the help text?

(I'm fine with this being undocumented)

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


[clang] [clang][Sema] Don't assert non-empty unexpanded packs following Colle… (PR #69224)

2023-10-21 Thread Younan Zhang via cfe-commits

zyn0217 wrote:

Sorry for my late update - I've had a busy week ;)

> I don't think so as they don't have parameter or capture list

+1. and it looks like we don't allow expanding a pack outside a statement 
expression, which more or less prevents the appearance of 
`FunctionParmPackExpr`.

> so i would encouraging researching
> ```cpp
> assert((!Unexpanded.empty() || enclosedInAnOtherExpression()) && "Unable to 
> find unexpanded parameter packs");
> ```
> where enclosedInAnOtherExpression would try to check that we are in a lambda 
> - maybe Sema::getEnclosingLambda() is sufficient - not sure though.

Instead of putting it inside an assertion, how about adding a check for 
FunctionParmPackExpr separately? I mean,
```cpp
if (auto *Expr = dyn_cast(E); Expr && 
getEnclosingLambda())
  return false;
```
to bail out only inside the `Expr` overload of 
`DiagnoseUnexpandedParameterPack`. (since it's the one being called anyways 
during template instantiation.)


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


[clang] [Clang] Add __datasizeof (PR #67805)

2023-10-21 Thread via cfe-commits


@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -fsyntax-only -triple x86_64-linux-gnu -verify %s

philnik777 wrote:

It looks like the VLA test can't be constant evaluated. Should I add a CodeGen 
test for that?

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


[PATCH] D157896: Clang: Define macro _MIPS_SPFPSET

2023-10-21 Thread Brad Smith via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc2f02e3bd6a5: Clang: Define macro _MIPS_SPFPSET (authored by 
brad).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157896

Files:
  clang/lib/Basic/Targets/Mips.cpp
  clang/lib/Basic/Targets/Mips.h
  clang/test/Preprocessor/init-mips.c

Index: clang/test/Preprocessor/init-mips.c
===
--- clang/test/Preprocessor/init-mips.c
+++ clang/test/Preprocessor/init-mips.c
@@ -10,6 +10,7 @@
 // MIPS32BE:#define _MIPS_ARCH_MIPS32R2 1
 // MIPS32BE:#define _MIPS_FPSET 16
 // MIPS32BE:#define _MIPS_SIM _ABIO32
+// MIPS32BE:#define _MIPS_SPFPSET 16
 // MIPS32BE:#define _MIPS_SZINT 32
 // MIPS32BE:#define _MIPS_SZLONG 32
 // MIPS32BE:#define _MIPS_SZPTR 32
@@ -220,6 +221,7 @@
 // MIPS32EL:#define _MIPS_ARCH_MIPS32R2 1
 // MIPS32EL:#define _MIPS_FPSET 16
 // MIPS32EL:#define _MIPS_SIM _ABIO32
+// MIPS32EL:#define _MIPS_SPFPSET 16
 // MIPS32EL:#define _MIPS_SZINT 32
 // MIPS32EL:#define _MIPS_SZLONG 32
 // MIPS32EL:#define _MIPS_SZPTR 32
@@ -432,6 +434,7 @@
 // MIPSN32BE: #define _MIPS_FPSET 32
 // MIPSN32BE: #define _MIPS_ISA _MIPS_ISA_MIPS64
 // MIPSN32BE: #define _MIPS_SIM _ABIN32
+// MIPSN32BE: #define _MIPS_SPFPSET 32
 // MIPSN32BE: #define _MIPS_SZINT 32
 // MIPSN32BE: #define _MIPS_SZLONG 32
 // MIPSN32BE: #define _MIPS_SZPTR 32
@@ -739,6 +742,7 @@
 // MIPSN32EL: #define _MIPS_FPSET 32
 // MIPSN32EL: #define _MIPS_ISA _MIPS_ISA_MIPS64
 // MIPSN32EL: #define _MIPS_SIM _ABIN32
+// MIPSN32EL: #define _MIPS_SPFPSET 32
 // MIPSN32EL: #define _MIPS_SZINT 32
 // MIPSN32EL: #define _MIPS_SZLONG 32
 // MIPSN32EL: #define _MIPS_SZPTR 32
@@ -1043,6 +1047,7 @@
 // MIPS64BE:#define _MIPS_ARCH_MIPS64R2 1
 // MIPS64BE:#define _MIPS_FPSET 32
 // MIPS64BE:#define _MIPS_SIM _ABI64
+// MIPS64BE:#define _MIPS_SPFPSET 32
 // MIPS64BE:#define _MIPS_SZINT 32
 // MIPS64BE:#define _MIPS_SZLONG 64
 // MIPS64BE:#define _MIPS_SZPTR 64
@@ -1253,6 +1258,7 @@
 // MIPS64EL:#define _MIPS_ARCH_MIPS64R2 1
 // MIPS64EL:#define _MIPS_FPSET 32
 // MIPS64EL:#define _MIPS_SIM _ABI64
+// MIPS64EL:#define _MIPS_SPFPSET 32
 // MIPS64EL:#define _MIPS_SZINT 32
 // MIPS64EL:#define _MIPS_SZLONG 64
 // MIPS64EL:#define _MIPS_SZPTR 64
@@ -1506,6 +1512,7 @@
 // MIPS-ARCH-32R6:#define _MIPS_ARCH "mips32r6"
 // MIPS-ARCH-32R6:#define _MIPS_ARCH_MIPS32R6 1
 // MIPS-ARCH-32R6:#define _MIPS_ISA _MIPS_ISA_MIPS32
+// MIPS-ARCH-32R6:#define __mips_fpr 64
 // MIPS-ARCH-32R6:#define __mips_isa_rev 6
 
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=mips64-none-none \
@@ -1682,14 +1689,28 @@
 // RUN:   | FileCheck -match-full-lines -check-prefix MIPS32-NOFP %s
 // MIPS32-NOFP:#define __mips_fpr 0
 
+// RUN: %clang_cc1  -target-feature -nooddspreg \
+// RUN:   -E -dM -triple=mips-none-none < /dev/null \
+// RUN:   | FileCheck -match-full-lines -check-prefix MIPS32-NOFP-ODD %s
+// MIPS32-NOFP-ODD:#define _MIPS_SPFPSET 32
+// MIPS32-NOFP-ODD:#define __mips_fpr 0
+
+// RUN: %clang_cc1  -target-feature +nooddspreg -target-feature -fp64 \
+// RUN:   -E -dM -triple=mips-none-none < /dev/null \
+// RUN:   | FileCheck -match-full-lines -check-prefix MIPS32-FP64-NOODD %s
+// MIPS32-FP64-NOODD:#define _MIPS_SPFPSET 16
+// MIPS32-FP64-NOODD:#define __mips_fpr 32
+
 // RUN: %clang_cc1 -target-feature +fpxx \
 // RUN:   -E -dM -triple=mips-none-none < /dev/null \
 // RUN:   | FileCheck -match-full-lines -check-prefix MIPS32-MFPXX %s
+// MIPS32-MFPXX:#define _MIPS_SPFPSET 16
 // MIPS32-MFPXX:#define __mips_fpr 0
 
 // RUN: %clang_cc1 -target-cpu mips32r6 -target-feature +fpxx \
 // RUN:   -E -dM -triple=mips-none-none < /dev/null \
 // RUN:   | FileCheck -match-full-lines -check-prefix MIPS32R6-MFPXX %s
+// MIPS32R6-MFPXX:#define _MIPS_SPFPSET 16
 // MIPS32R6-MFPXX:#define __mips_fpr 0
 
 // RUN: %clang_cc1  \
@@ -1716,30 +1737,35 @@
 // RUN:   -E -dM -triple=mips-none-none < /dev/null \
 // RUN:   | FileCheck -match-full-lines -check-prefix MIPS32-MFP32 %s
 // MIPS32-MFP32:#define _MIPS_FPSET 16
+// MIPS32-MFP32:#define _MIPS_SPFPSET 32
 // MIPS32-MFP32:#define __mips_fpr 32
 
 // RUN: %clang_cc1 -target-feature +fp64 \
 // RUN:   -E -dM -triple=mips-none-none < /dev/null \
 // RUN:   | FileCheck -match-full-lines -check-prefix MIPS32-MFP64 %s
 // MIPS32-MFP64:#define _MIPS_FPSET 32
+// MIPS32-MFP64:#define _MIPS_SPFPSET 32
 // MIPS32-MFP64:#define __mips_fpr 64
 //
 // RUN: %clang_cc1 -target-feature +single-float \
 // RUN:   -E -dM -triple=mips-none-none < /dev/null \
 // RUN:   | FileCheck -match-full-lines -check-prefix MIPS32-MFP32SF %s
 // MIPS32-MFP32SF:#define _MIPS_FPSET 32
+// MIPS32-MFP32SF:#define _MIPS_SPFPSET 16
 // MIPS32-MFP32SF:#define __mips_fpr 0
 
 // RUN: %clang_cc1 -target-feature +fp64 \
 // RUN:   -E -dM -triple=mips64-none-none < /dev/null \
 // RUN:   | 

[clang] c2f02e3 - Clang: Define macro _MIPS_SPFPSET

2023-10-21 Thread Brad Smith via cfe-commits

Author: Brad Smith
Date: 2023-10-21T07:08:54-04:00
New Revision: c2f02e3bd6a5b287a221ae9038e6727abc3e6652

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

LOG: Clang: Define macro _MIPS_SPFPSET

GCC defines this macro for how many single-precision floating point registers
can be used.

If the -mno-odd-spreg option is given, it will be 16; if either -mno-odd-spreg
nor -modd-spreg are given, we set it to 16 for FPXX.

Reviewed By: theraven

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

Added: 


Modified: 
clang/lib/Basic/Targets/Mips.cpp
clang/lib/Basic/Targets/Mips.h
clang/test/Preprocessor/init-mips.c

Removed: 




diff  --git a/clang/lib/Basic/Targets/Mips.cpp 
b/clang/lib/Basic/Targets/Mips.cpp
index cdf652c49f603e3..bc90d1b93d53f6d 100644
--- a/clang/lib/Basic/Targets/Mips.cpp
+++ b/clang/lib/Basic/Targets/Mips.cpp
@@ -149,6 +149,10 @@ void MipsTargetInfo::getTargetDefines(const LangOptions 
,
 Builder.defineMacro("_MIPS_FPSET", Twine(32));
   else
 Builder.defineMacro("_MIPS_FPSET", Twine(16));
+  if (NoOddSpreg)
+Builder.defineMacro("_MIPS_SPFPSET", Twine(16));
+  else
+Builder.defineMacro("_MIPS_SPFPSET", Twine(32));
 
   if (IsMips16)
 Builder.defineMacro("__mips16", Twine(1));

diff  --git a/clang/lib/Basic/Targets/Mips.h b/clang/lib/Basic/Targets/Mips.h
index 7ecbd8633cb346b..f46b95abfd75c73 100644
--- a/clang/lib/Basic/Targets/Mips.h
+++ b/clang/lib/Basic/Targets/Mips.h
@@ -53,6 +53,7 @@ class LLVM_LIBRARY_VISIBILITY MipsTargetInfo : public 
TargetInfo {
   bool HasMSA;
   bool DisableMadd4;
   bool UseIndirectJumpHazard;
+  bool NoOddSpreg;
 
 protected:
   enum FPModeEnum { FPXX, FP32, FP64 } FPMode;
@@ -313,6 +314,8 @@ class LLVM_LIBRARY_VISIBILITY MipsTargetInfo : public 
TargetInfo {
 FloatABI = HardFloat;
 DspRev = NoDSP;
 FPMode = isFP64Default() ? FP64 : FPXX;
+NoOddSpreg = false;
+bool OddSpregGiven = false;
 
 for (const auto  : Features) {
   if (Feature == "+single-float")
@@ -349,8 +352,18 @@ class LLVM_LIBRARY_VISIBILITY MipsTargetInfo : public 
TargetInfo {
 IsNoABICalls = true;
   else if (Feature == "+use-indirect-jump-hazard")
 UseIndirectJumpHazard = true;
+  else if (Feature == "+nooddspreg") {
+NoOddSpreg = true;
+OddSpregGiven = false;
+  } else if (Feature == "-nooddspreg") {
+NoOddSpreg = false;
+OddSpregGiven = true;
+  }
 }
 
+if (FPMode == FPXX && !OddSpregGiven)
+  NoOddSpreg = true;
+
 setDataLayout();
 
 return true;

diff  --git a/clang/test/Preprocessor/init-mips.c 
b/clang/test/Preprocessor/init-mips.c
index a07cee64e6848d2..34091ea3690dad0 100644
--- a/clang/test/Preprocessor/init-mips.c
+++ b/clang/test/Preprocessor/init-mips.c
@@ -10,6 +10,7 @@
 // MIPS32BE:#define _MIPS_ARCH_MIPS32R2 1
 // MIPS32BE:#define _MIPS_FPSET 16
 // MIPS32BE:#define _MIPS_SIM _ABIO32
+// MIPS32BE:#define _MIPS_SPFPSET 16
 // MIPS32BE:#define _MIPS_SZINT 32
 // MIPS32BE:#define _MIPS_SZLONG 32
 // MIPS32BE:#define _MIPS_SZPTR 32
@@ -220,6 +221,7 @@
 // MIPS32EL:#define _MIPS_ARCH_MIPS32R2 1
 // MIPS32EL:#define _MIPS_FPSET 16
 // MIPS32EL:#define _MIPS_SIM _ABIO32
+// MIPS32EL:#define _MIPS_SPFPSET 16
 // MIPS32EL:#define _MIPS_SZINT 32
 // MIPS32EL:#define _MIPS_SZLONG 32
 // MIPS32EL:#define _MIPS_SZPTR 32
@@ -432,6 +434,7 @@
 // MIPSN32BE: #define _MIPS_FPSET 32
 // MIPSN32BE: #define _MIPS_ISA _MIPS_ISA_MIPS64
 // MIPSN32BE: #define _MIPS_SIM _ABIN32
+// MIPSN32BE: #define _MIPS_SPFPSET 32
 // MIPSN32BE: #define _MIPS_SZINT 32
 // MIPSN32BE: #define _MIPS_SZLONG 32
 // MIPSN32BE: #define _MIPS_SZPTR 32
@@ -739,6 +742,7 @@
 // MIPSN32EL: #define _MIPS_FPSET 32
 // MIPSN32EL: #define _MIPS_ISA _MIPS_ISA_MIPS64
 // MIPSN32EL: #define _MIPS_SIM _ABIN32
+// MIPSN32EL: #define _MIPS_SPFPSET 32
 // MIPSN32EL: #define _MIPS_SZINT 32
 // MIPSN32EL: #define _MIPS_SZLONG 32
 // MIPSN32EL: #define _MIPS_SZPTR 32
@@ -1043,6 +1047,7 @@
 // MIPS64BE:#define _MIPS_ARCH_MIPS64R2 1
 // MIPS64BE:#define _MIPS_FPSET 32
 // MIPS64BE:#define _MIPS_SIM _ABI64
+// MIPS64BE:#define _MIPS_SPFPSET 32
 // MIPS64BE:#define _MIPS_SZINT 32
 // MIPS64BE:#define _MIPS_SZLONG 64
 // MIPS64BE:#define _MIPS_SZPTR 64
@@ -1253,6 +1258,7 @@
 // MIPS64EL:#define _MIPS_ARCH_MIPS64R2 1
 // MIPS64EL:#define _MIPS_FPSET 32
 // MIPS64EL:#define _MIPS_SIM _ABI64
+// MIPS64EL:#define _MIPS_SPFPSET 32
 // MIPS64EL:#define _MIPS_SZINT 32
 // MIPS64EL:#define _MIPS_SZLONG 64
 // MIPS64EL:#define _MIPS_SZPTR 64
@@ -1506,6 +1512,7 @@
 // MIPS-ARCH-32R6:#define _MIPS_ARCH "mips32r6"
 // MIPS-ARCH-32R6:#define _MIPS_ARCH_MIPS32R6 1
 // MIPS-ARCH-32R6:#define _MIPS_ISA _MIPS_ISA_MIPS32
+// MIPS-ARCH-32R6:#define __mips_fpr 64
 // MIPS-ARCH-32R6:#define 

[clang-tools-extra] 9322216 - [clang-tidy][DOC] Fix 'table cell spanning'

2023-10-21 Thread Piotr Zegar via cfe-commits

Author: Piotr Zegar
Date: 2023-10-21T10:30:06Z
New Revision: 9322216021f1d8241b87a81c12321b05aa6d1cfb

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

LOG: [clang-tidy][DOC] Fix 'table cell spanning'

Change current tables to avoid cell spanning.

Added: 


Modified: 
clang-tools-extra/docs/clang-tidy/Integrations.rst
clang-tools-extra/docs/clang-tidy/checks/readability/identifier-naming.rst

Removed: 




diff  --git a/clang-tools-extra/docs/clang-tidy/Integrations.rst 
b/clang-tools-extra/docs/clang-tidy/Integrations.rst
index 8f3f5a31274e8af..7104944120a934e 100644
--- a/clang-tools-extra/docs/clang-tidy/Integrations.rst
+++ b/clang-tools-extra/docs/clang-tidy/Integrations.rst
@@ -15,7 +15,7 @@ The following table shows the most well-known 
:program:`clang-tidy`
 integrations in detail.
 
 
+--++-+--+-+--+
-|  |Feature

   |
+|  |Feature |  
   |  | 
|  |
 
+==++=+==+=+==+
 |  **Tool**| On-the-fly inspection  | Check list 
configuration (GUI)  | Options to checks (GUI)  | Configuration via 
``.clang-tidy`` files | Custom clang-tidy binary |
 
+--++-+--+-+--+

diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/readability/identifier-naming.rst 
b/clang-tools-extra/docs/clang-tidy/checks/readability/identifier-naming.rst
index 467968ce43faea7..608bc2acdc0d5e5 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/readability/identifier-naming.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/readability/identifier-naming.rst
@@ -2526,41 +2526,41 @@ Otherwise the case of this character denotes scope.
 The following table is the default mapping table of Hungarian Notation which
 maps Decl to its prefix string. You can also have your own style in config 
file.
 
-= == == == 
=== ==
-Primitive Types
Microsoft data types
--- 
--
-Type  Prefix Type   Prefix Type
Prefix
-= == == == 
=== ==
-int8_ti8 signed int si BOOL
b
-int16_t   i16signed short   ss BOOLEAN 
b
-int32_t   i32signed short int   ssiBYTE
by
-int64_t   i64signed long long int   slli   CHAR
c
-uint8_t   u8 signed long long   sllUCHAR   
uc
-uint16_t  u16signed long intsliSHORT   
s
-uint32_t  u32signed longsl USHORT  
us
-uint64_t  u64signed s  WORD
w
-char8_t   c8 unsigned long long int ulli   DWORD   
dw
-char16_t  c16unsigned long long ullDWORD32 
dw32
-char32_t  c32unsigned long int  uliDWORD64 
dw64
-float f  unsigned long  ul LONG
l
-doubled  unsigned short int usiULONG   
ul
-char  c  unsigned short us ULONG32 
ul32
-bool  b  unsigned int   ui ULONG64 
ul64
-_Bool b  unsigned char  uc 
ULONGLONG   ull
-int   i  unsigned   u  HANDLE  
h
-size_tn  long long int  lliINT 
i
-short s  long doubleld INT8

[clang-tools-extra] Clang tools docs ci test (PR #69826)

2023-10-21 Thread Aiden Grossman via cfe-commits

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


[clang-tools-extra] Clang tools docs ci test (PR #69826)

2023-10-21 Thread Aiden Grossman via cfe-commits

https://github.com/boomanaiden154 created 
https://github.com/llvm/llvm-project/pull/69826

None

>From f8bd3e5f45e05f68522f41bb0b6ea733095eb7a4 Mon Sep 17 00:00:00 2001
From: Aiden Grossman 
Date: Sat, 21 Oct 2023 02:33:56 -0700
Subject: [PATCH 1/2] [Github] Add clang-tools-extra docs to CI

This patch adds the clang-tools-extra docs to the Github CI job that
builds docs, enabling the ability to easily ensure the docs build
properly without warnings in PRs and at the tip of tree.
---
 .github/workflows/docs.yml | 9 +
 1 file changed, 9 insertions(+)

diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml
index 2900f73c77c5a66..6d91112cca5518f 100644
--- a/.github/workflows/docs.yml
+++ b/.github/workflows/docs.yml
@@ -15,10 +15,12 @@ on:
 paths:
   - 'llvm/docs/**'
   - 'clang/docs/**'
+  - 'clang-tools-extra/docs/**'
   pull_request:
 paths:
   - 'llvm/docs/**'
   - 'clang/docs/**'
+  - 'clang-tools-extra/docs/**'
 
 jobs:
   check-docs-build:
@@ -47,6 +49,8 @@ jobs:
   - 'llvm/docs/**'
 clang:
   - 'clang/docs/**'
+clang-tools-extra:
+  - 'clang-tools-extra/docs/**'
   - name: Setup Python env
 uses: actions/setup-python@v4
 with:
@@ -69,4 +73,9 @@ jobs:
 run: |
   cmake -B clang-build -GNinja -DCMAKE_BUILD_TYPE=Release 
-DLLVM_ENABLE_PROJECTS="clang" -DLLVM_ENABLE_SPHINX=ON ./llvm
   TZ=UTC ninja -C clang-build docs-clang-html docs-clang-man
+  - name: Build clang-tools-extra docs
+if: 
steps.docs-changed-subprojects.outputs.clang-tools-extra_any_changed == 'true'
+run: |
+  cmake -B clang-tools-extra-build -GNinja -DCMAKE_BUILD_TYPE=Release 
-DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" -DLLVM_ENABLE_SPHINX=ON ./llvm
+  TZ=UTC ninja -C clang-tools-extra-build docs-clang-tools-html 
docs-clang-tools-man
 

>From 20afc281b2fdd642fc75fc3a275cb882e2ffd3b6 Mon Sep 17 00:00:00 2001
From: Aiden Grossman 
Date: Sat, 21 Oct 2023 02:35:39 -0700
Subject: [PATCH 2/2] testing

---
 clang-tools-extra/docs/clang-rename.rst | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang-tools-extra/docs/clang-rename.rst 
b/clang-tools-extra/docs/clang-rename.rst
index e13d8c3ad25f98e..513056d06f5744f 100644
--- a/clang-tools-extra/docs/clang-rename.rst
+++ b/clang-tools-extra/docs/clang-rename.rst
@@ -2,6 +2,8 @@
 Clang-Rename
 
 
+This is just a test
+
 .. contents::
 
 See also:

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


[clang-tools-extra] [mlir][tosa] Check for unranked tensors during validation (PR #68509)

2023-10-21 Thread Sarthak Gupta via cfe-commits

gptsarthak wrote:

This patch is ready to be merged.

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


[clang] [mlir][tosa] Check for unranked tensors during validation (PR #68509)

2023-10-21 Thread Sarthak Gupta via cfe-commits

gptsarthak wrote:

This patch is ready to be merged.

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


[clang] [mlir][tosa] Check for unranked tensors during validation (PR #68509)

2023-10-21 Thread Sarthak Gupta via cfe-commits

https://github.com/gptsarthak updated 
https://github.com/llvm/llvm-project/pull/68509

>From cf45b9d2dc8c120b0269992ff6740abbe72f93f3 Mon Sep 17 00:00:00 2001
From: gptsarthak 
Date: Wed, 11 Oct 2023 13:58:59 +0530
Subject: [PATCH] [mlir][tosa] Check for unranked tensors during validation

levelCheckRank ensures that the tensors for tosa operations are not unranked
Fixes https://github.com/llvm/llvm-project/issues/67760
---
 mlir/lib/Dialect/Tosa/Transforms/TosaValidation.cpp | 4 
 mlir/test/Dialect/Tosa/level_check.mlir | 9 +
 2 files changed, 13 insertions(+)

diff --git a/mlir/lib/Dialect/Tosa/Transforms/TosaValidation.cpp 
b/mlir/lib/Dialect/Tosa/Transforms/TosaValidation.cpp
index 52885e69c3924f2..078200844c35b33 100644
--- a/mlir/lib/Dialect/Tosa/Transforms/TosaValidation.cpp
+++ b/mlir/lib/Dialect/Tosa/Transforms/TosaValidation.cpp
@@ -150,6 +150,10 @@ struct TosaValidation : public 
tosa::impl::TosaValidationBase {
   bool levelCheckRank(Operation *op, const Value ,
   const std::string _desc) {
 if (ShapedType type = dyn_cast(v.getType())) {
+  if (!type.hasRank()) {
+op->emitOpError() << "failed level check: unranked tensor";
+return false;
+  }
   if (type.getRank() > tosa_level.MAX_RANK) {
 op->emitOpError() << "failed level check: " << check_desc;
 return false;
diff --git a/mlir/test/Dialect/Tosa/level_check.mlir 
b/mlir/test/Dialect/Tosa/level_check.mlir
index e7fdf8af409b564..839ee4055e7aab9 100644
--- a/mlir/test/Dialect/Tosa/level_check.mlir
+++ b/mlir/test/Dialect/Tosa/level_check.mlir
@@ -695,4 +695,13 @@ func.func @test_custom(%arg0: tensor<1x1x1x1x1x1x10xi32>) 
-> tensor<1x1x1x1x1x1x
   return %0 : tensor<1x1x1x1x1x1x10xi32>
 }
 
+// -
+
+// CHECK-LABEL: unranked_tensor
+func.func @test_unranked_tensor(%arg0: tensor<*xf32>) {
+  // expected-error@+1 {{'tosa.slice' op failed level check: unranked tensor}}
+  %0 = "tosa.slice"(%arg0) {start = array, size = array} :
+  (tensor<*xf32>) -> tensor<*xf32>
+  return
+}
 

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


[clang-tools-extra] [mlir][tosa] Check for unranked tensors during validation (PR #68509)

2023-10-21 Thread Sarthak Gupta via cfe-commits

https://github.com/gptsarthak updated 
https://github.com/llvm/llvm-project/pull/68509

>From cf45b9d2dc8c120b0269992ff6740abbe72f93f3 Mon Sep 17 00:00:00 2001
From: gptsarthak 
Date: Wed, 11 Oct 2023 13:58:59 +0530
Subject: [PATCH] [mlir][tosa] Check for unranked tensors during validation

levelCheckRank ensures that the tensors for tosa operations are not unranked
Fixes https://github.com/llvm/llvm-project/issues/67760
---
 mlir/lib/Dialect/Tosa/Transforms/TosaValidation.cpp | 4 
 mlir/test/Dialect/Tosa/level_check.mlir | 9 +
 2 files changed, 13 insertions(+)

diff --git a/mlir/lib/Dialect/Tosa/Transforms/TosaValidation.cpp 
b/mlir/lib/Dialect/Tosa/Transforms/TosaValidation.cpp
index 52885e69c3924f2..078200844c35b33 100644
--- a/mlir/lib/Dialect/Tosa/Transforms/TosaValidation.cpp
+++ b/mlir/lib/Dialect/Tosa/Transforms/TosaValidation.cpp
@@ -150,6 +150,10 @@ struct TosaValidation : public 
tosa::impl::TosaValidationBase {
   bool levelCheckRank(Operation *op, const Value ,
   const std::string _desc) {
 if (ShapedType type = dyn_cast(v.getType())) {
+  if (!type.hasRank()) {
+op->emitOpError() << "failed level check: unranked tensor";
+return false;
+  }
   if (type.getRank() > tosa_level.MAX_RANK) {
 op->emitOpError() << "failed level check: " << check_desc;
 return false;
diff --git a/mlir/test/Dialect/Tosa/level_check.mlir 
b/mlir/test/Dialect/Tosa/level_check.mlir
index e7fdf8af409b564..839ee4055e7aab9 100644
--- a/mlir/test/Dialect/Tosa/level_check.mlir
+++ b/mlir/test/Dialect/Tosa/level_check.mlir
@@ -695,4 +695,13 @@ func.func @test_custom(%arg0: tensor<1x1x1x1x1x1x10xi32>) 
-> tensor<1x1x1x1x1x1x
   return %0 : tensor<1x1x1x1x1x1x10xi32>
 }
 
+// -
+
+// CHECK-LABEL: unranked_tensor
+func.func @test_unranked_tensor(%arg0: tensor<*xf32>) {
+  // expected-error@+1 {{'tosa.slice' op failed level check: unranked tensor}}
+  %0 = "tosa.slice"(%arg0) {start = array, size = array} :
+  (tensor<*xf32>) -> tensor<*xf32>
+  return
+}
 

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


[clang] [clang][dataflow] Remove `declToLocConsistent()` assertion. (PR #69819)

2023-10-21 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 386f3903910aa1897c424ced8e1af7993a6df5ce 
9508b6fe43730c4ba6568ae2e86cf1807e911727 -- 
clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h 
clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp 
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index c08cb2d7deb2..00e56ce51c53 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -699,9 +699,7 @@ StorageLocation *Environment::getStorageLocation(const 
ValueDecl ) const {
   return Loc;
 }
 
-void Environment::removeDecl(const ValueDecl ) {
-  DeclToLoc.erase();
-}
+void Environment::removeDecl(const ValueDecl ) { DeclToLoc.erase(); }
 
 void Environment::setStorageLocation(const Expr , StorageLocation ) {
   // `DeclRefExpr`s to builtin function types aren't glvalues, for some reason,

``




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


[clang] 09b02f5 - [Driver][NetBSD][NFC] Some cleaning up

2023-10-21 Thread Brad Smith via cfe-commits

Author: Brad Smith
Date: 2023-10-21T04:45:41-04:00
New Revision: 09b02f5d569adbbb29186479953cd55bd6b29402

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

LOG: [Driver][NetBSD][NFC] Some cleaning up

Added: 


Modified: 
clang/lib/Driver/ToolChains/NetBSD.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/NetBSD.cpp 
b/clang/lib/Driver/ToolChains/NetBSD.cpp
index 1c901f70f72ca2e..e643bdf8bcbedb5 100644
--- a/clang/lib/Driver/ToolChains/NetBSD.cpp
+++ b/clang/lib/Driver/ToolChains/NetBSD.cpp
@@ -30,13 +30,12 @@ void netbsd::Assembler::ConstructJob(Compilation , const 
JobAction ,
  const InputInfoList ,
  const ArgList ,
  const char *LinkingOutput) const {
-  const toolchains::NetBSD  =
-static_cast(getToolChain());
+  const auto  = static_cast(getToolChain());
   const Driver  = ToolChain.getDriver();
   const llvm::Triple  = ToolChain.getTriple();
+  ArgStringList CmdArgs;
 
   claimNoWarnArgs(Args);
-  ArgStringList CmdArgs;
 
   // GNU as needs 
diff erent flags for creating the correct output format
   // on architectures with 
diff erent ABIs or optional feature sets.
@@ -118,27 +117,29 @@ void netbsd::Linker::ConstructJob(Compilation , const 
JobAction ,
   const InputInfoList ,
   const ArgList ,
   const char *LinkingOutput) const {
-  const toolchains::NetBSD  =
-static_cast(getToolChain());
+  const auto  = static_cast(getToolChain());
   const Driver  = ToolChain.getDriver();
   const llvm::Triple  = ToolChain.getTriple();
-
+  const llvm::Triple::ArchType Arch = ToolChain.getArch();
+  const bool Static = Args.hasArg(options::OPT_static);
+  const bool Shared = Args.hasArg(options::OPT_shared);
+  const bool Pie = Args.hasArg(options::OPT_pie);
   ArgStringList CmdArgs;
 
   if (!D.SysRoot.empty())
 CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
 
   CmdArgs.push_back("--eh-frame-hdr");
-  if (Args.hasArg(options::OPT_static)) {
+  if (Static) {
 CmdArgs.push_back("-Bstatic");
-if (Args.hasArg(options::OPT_pie)) {
+if (Pie) {
   Args.AddAllArgs(CmdArgs, options::OPT_pie);
   CmdArgs.push_back("--no-dynamic-linker");
 }
   } else {
 if (Args.hasArg(options::OPT_rdynamic))
   CmdArgs.push_back("-export-dynamic");
-if (Args.hasArg(options::OPT_shared)) {
+if (Shared) {
   CmdArgs.push_back("-shared");
 } else if (!Args.hasArg(options::OPT_r)) {
   Args.AddAllArgs(CmdArgs, options::OPT_pie);
@@ -149,7 +150,7 @@ void netbsd::Linker::ConstructJob(Compilation , const 
JobAction ,
 
   // Many NetBSD architectures support more than one ABI.
   // Determine the correct emulation for ld.
-  switch (ToolChain.getArch()) {
+  switch (Arch) {
   case llvm::Triple::x86:
 CmdArgs.push_back("-m");
 CmdArgs.push_back("elf_i386");
@@ -193,13 +194,13 @@ void netbsd::Linker::ConstructJob(Compilation , const 
JobAction ,
   case llvm::Triple::mips64el:
 if (mips::hasMipsAbiArg(Args, "32")) {
   CmdArgs.push_back("-m");
-  if (ToolChain.getArch() == llvm::Triple::mips64)
+  if (Arch == llvm::Triple::mips64)
 CmdArgs.push_back("elf32btsmip");
   else
 CmdArgs.push_back("elf32ltsmip");
 } else if (mips::hasMipsAbiArg(Args, "64")) {
   CmdArgs.push_back("-m");
-  if (ToolChain.getArch() == llvm::Triple::mips64)
+  if (Arch == llvm::Triple::mips64)
 CmdArgs.push_back("elf64btsmip");
   else
 CmdArgs.push_back("elf64ltsmip");
@@ -251,19 +252,20 @@ void netbsd::Linker::ConstructJob(Compilation , const 
JobAction ,
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
options::OPT_r)) {
-if (!Args.hasArg(options::OPT_shared)) {
-  CmdArgs.push_back(
-  Args.MakeArgString(ToolChain.GetFilePath("crt0.o")));
-}
-CmdArgs.push_back(
-Args.MakeArgString(ToolChain.GetFilePath("crti.o")));
-if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_pie)) {
-  CmdArgs.push_back(
-  Args.MakeArgString(ToolChain.GetFilePath("crtbeginS.o")));
-} else {
-  CmdArgs.push_back(
-  Args.MakeArgString(ToolChain.GetFilePath("crtbegin.o")));
-}
+const char *crt0 = nullptr;
+const char *crtbegin = nullptr;
+if (!Shared)
+  crt0 = "crt0.o";
+
+if (Shared || Pie)
+  crtbegin = "crtbeginS.o";
+else
+  crtbegin = "crtbegin.o";
+
+if (crt0)
+  CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crt0)));
+CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crti.o")));
+

[clang] [clang][dataflow] Remove `declToLocConsistent()` assertion. (PR #69819)

2023-10-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-analysis

Author: None (martinboehme)


Changes

As described [here](https://discourse.llvm.org/t/70086/6), there are legitimate
non-bug scenarios where two `DeclToLoc` maps to be joined contain different
storage locations for the same declaration. This patch also adds a test
containing an example of such a situation. (The test fails without the other
changes in this patch.)

With the assertion removed, the existing logic in `intersectDenseMaps()` will
remove the corresponding declaration from the joined DeclToLoc map.

We also remove `removeDecl()`'s precondition (that the declaration must be
associated with a storage location) because this may no longer hold if the
declaration was previously removed during a join, as described above.


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


3 Files Affected:

- (modified) clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h 
(+1-5) 
- (modified) clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp (-16) 
- (modified) clang/unittests/Analysis/FlowSensitive/TransferTest.cpp (+44) 


``diff
diff --git a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h 
b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
index 56d647f35b08430..402f77d6a4ac3f8 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
@@ -260,11 +260,7 @@ class Environment {
   /// if `D` isn't assigned a storage location in the environment.
   StorageLocation *getStorageLocation(const ValueDecl ) const;
 
-  /// Removes the location assigned to `D` in the environment.
-  ///
-  /// Requirements:
-  ///
-  ///  `D` must have a storage location assigned in the environment.
+  /// Removes the location assigned to `D` in the environment (if any).
   void removeDecl(const ValueDecl );
 
   /// Assigns `Loc` as the storage location of the glvalue `E` in the
diff --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index 01c6cc69e2b9fac..c08cb2d7deb2d81 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -35,20 +35,6 @@ namespace dataflow {
 static constexpr int MaxCompositeValueDepth = 3;
 static constexpr int MaxCompositeValueSize = 1000;
 
-/// Returns whether all declarations that `DeclToLoc1` and `DeclToLoc2` have in
-/// common map to the same storage location in both maps.
-bool declToLocConsistent(
-const llvm::DenseMap ,
-const llvm::DenseMap ) {
-  for (auto  : DeclToLoc1) {
-auto It = DeclToLoc2.find(Entry.first);
-if (It != DeclToLoc2.end() && Entry.second != It->second)
-  return false;
-  }
-
-  return true;
-}
-
 /// Returns a map consisting of key-value entries that are present in both 
maps.
 template 
 llvm::DenseMap intersectDenseMaps(const llvm::DenseMap ,
@@ -662,7 +648,6 @@ Environment Environment::join(const Environment , 
const Environment ,
   else
 JoinedEnv.ReturnLoc = nullptr;
 
-  assert(declToLocConsistent(EnvA.DeclToLoc, EnvB.DeclToLoc));
   JoinedEnv.DeclToLoc = intersectDenseMaps(EnvA.DeclToLoc, EnvB.DeclToLoc);
 
   JoinedEnv.ExprToLoc = intersectDenseMaps(EnvA.ExprToLoc, EnvB.ExprToLoc);
@@ -715,7 +700,6 @@ StorageLocation *Environment::getStorageLocation(const 
ValueDecl ) const {
 }
 
 void Environment::removeDecl(const ValueDecl ) {
-  assert(DeclToLoc.contains());
   DeclToLoc.erase();
 }
 
diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index ea36a3f705ee934..33d2fcc8aa69a3c 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -6236,4 +6236,48 @@ TEST(TransferTest, LambdaCaptureThis) {
   });
 }
 
+TEST(TransferTest, DifferentReferenceLocInJoin) {
+  // This test triggers a case where the storage location for a reference-type
+  // variable is different for two states being joined. We used to believe this
+  // could not happen and therefore had an assertion disallowing this; this 
test
+  // exists to demonstrate that we can handle this condition without a failing
+  // assertion. See also the discussion here:
+  // https://discourse.llvm.org/t/70086/6
+  std::string Code = R"(
+namespace std {
+  template  struct initializer_list {
+const T* begin();
+const T* end();
+  };
+}
+
+void target(char* p, char* end) {
+  while (p != end) {
+if (*p == ' ') {
+  p++;
+  continue;
+}
+
+auto && range = {1, 2};
+for (auto b = range.begin(), e = range.end(); b != e; ++b) {
+}
+(void)0;
+// [[p]]
+  }
+}
+  )";
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> ,
+ ASTContext ) {
+

[clang] [clang][dataflow] Remove `declToLocConsistent()` assertion. (PR #69819)

2023-10-21 Thread via cfe-commits

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

As described [here](https://discourse.llvm.org/t/70086/6), there are legitimate
non-bug scenarios where two `DeclToLoc` maps to be joined contain different
storage locations for the same declaration. This patch also adds a test
containing an example of such a situation. (The test fails without the other
changes in this patch.)

With the assertion removed, the existing logic in `intersectDenseMaps()` will
remove the corresponding declaration from the joined DeclToLoc map.

We also remove `removeDecl()`'s precondition (that the declaration must be
associated with a storage location) because this may no longer hold if the
declaration was previously removed during a join, as described above.


>From 9508b6fe43730c4ba6568ae2e86cf1807e911727 Mon Sep 17 00:00:00 2001
From: Martin Braenne 
Date: Sat, 21 Oct 2023 08:38:35 +
Subject: [PATCH] [clang][dataflow] Remove `declToLocConsistent()` assertion.

As described [here](https://discourse.llvm.org/t/70086/6), there are legitimate
non-bug scenarios where two `DeclToLoc` maps to be joined contain different
storage locations for the same declaration. This patch also adds a test
containing an example of such a situation. (The test fails without the other
changes in this patch.)

With the assertion removed, the existing logic in `intersectDenseMaps()` will
remove the corresponding declaration from the joined DeclToLoc map.

We also remove `removeDecl()`'s precondition (that the declaration must be
associated with a storage location) because this may no longer hold if the
declaration was previously removed during a join, as described above.
---
 .../FlowSensitive/DataflowEnvironment.h   |  6 +--
 .../FlowSensitive/DataflowEnvironment.cpp | 16 ---
 .../Analysis/FlowSensitive/TransferTest.cpp   | 44 +++
 3 files changed, 45 insertions(+), 21 deletions(-)

diff --git a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h 
b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
index 56d647f35b08430..402f77d6a4ac3f8 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
@@ -260,11 +260,7 @@ class Environment {
   /// if `D` isn't assigned a storage location in the environment.
   StorageLocation *getStorageLocation(const ValueDecl ) const;
 
-  /// Removes the location assigned to `D` in the environment.
-  ///
-  /// Requirements:
-  ///
-  ///  `D` must have a storage location assigned in the environment.
+  /// Removes the location assigned to `D` in the environment (if any).
   void removeDecl(const ValueDecl );
 
   /// Assigns `Loc` as the storage location of the glvalue `E` in the
diff --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index 01c6cc69e2b9fac..c08cb2d7deb2d81 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -35,20 +35,6 @@ namespace dataflow {
 static constexpr int MaxCompositeValueDepth = 3;
 static constexpr int MaxCompositeValueSize = 1000;
 
-/// Returns whether all declarations that `DeclToLoc1` and `DeclToLoc2` have in
-/// common map to the same storage location in both maps.
-bool declToLocConsistent(
-const llvm::DenseMap ,
-const llvm::DenseMap ) {
-  for (auto  : DeclToLoc1) {
-auto It = DeclToLoc2.find(Entry.first);
-if (It != DeclToLoc2.end() && Entry.second != It->second)
-  return false;
-  }
-
-  return true;
-}
-
 /// Returns a map consisting of key-value entries that are present in both 
maps.
 template 
 llvm::DenseMap intersectDenseMaps(const llvm::DenseMap ,
@@ -662,7 +648,6 @@ Environment Environment::join(const Environment , 
const Environment ,
   else
 JoinedEnv.ReturnLoc = nullptr;
 
-  assert(declToLocConsistent(EnvA.DeclToLoc, EnvB.DeclToLoc));
   JoinedEnv.DeclToLoc = intersectDenseMaps(EnvA.DeclToLoc, EnvB.DeclToLoc);
 
   JoinedEnv.ExprToLoc = intersectDenseMaps(EnvA.ExprToLoc, EnvB.ExprToLoc);
@@ -715,7 +700,6 @@ StorageLocation *Environment::getStorageLocation(const 
ValueDecl ) const {
 }
 
 void Environment::removeDecl(const ValueDecl ) {
-  assert(DeclToLoc.contains());
   DeclToLoc.erase();
 }
 
diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index ea36a3f705ee934..33d2fcc8aa69a3c 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -6236,4 +6236,48 @@ TEST(TransferTest, LambdaCaptureThis) {
   });
 }
 
+TEST(TransferTest, DifferentReferenceLocInJoin) {
+  // This test triggers a case where the storage location for a reference-type
+  // variable is different for two states being joined. We used to believe this
+  // could not happen and 

[clang] [clang-format] Add a new style for the clang-format source code (PR #69814)

2023-10-21 Thread Owen Pan via cfe-commits

owenca wrote:

> What is your goal with that style?

It was actually your [idea](https://reviews.llvm.org/D153208#4431239).  

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


[clang] [clang] Implement constexpr bit_cast for vectors (PR #66894)

2023-10-21 Thread via cfe-commits


@@ -140,11 +140,12 @@ void g28(void) {
   typedef short v12i16 __attribute((vector_size(24)));
   typedef long double v2f80 __attribute((vector_size(24)));
   // CHECK: @g28.a = internal global <1 x i64> 
-  // CHECK: @g28.b = internal global <12 x i16> 
-  // CHECK: @g28.c = internal global <2 x x86_fp80> , align 32
+  // @g28.b = internal global <12 x i16> 
+  // @g28.c = internal global <2 x x86_fp80> , align 32
   static v1i64 a = (v1i64)10LL;
-  static v12i16 b = (v12i16)(v2f80){1,2};
-  static v2f80 c = (v2f80)(v12i16){0,0,0,-32768,16383,0,0,0,0,-32768,16384,0};
+  //FIXME: support constant bitcast between vectors of x86_fp80
+  //static v12i16 b = (v12i16)(v2f80){1,2};
+  //static v2f80 c = 
(v2f80)(v12i16){0,0,0,-32768,16383,0,0,0,0,-32768,16384,0};

DaMatrix wrote:

So, on further investigation, it looks like the diagnostic isn't being emitted 
at all because the constant evaluation code is called with an `EvalInfo` which 
has diagnostics disabled, and is never called again.

https://github.com/llvm/llvm-project/blob/72f63b695c9ebd9c7032c4b754ff7965c28fad5c/clang/lib/AST/Expr.cpp#L3486
https://github.com/llvm/llvm-project/blob/72f63b695c9ebd9c7032c4b754ff7965c28fad5c/clang/lib/AST/ExprConstant.cpp#L15483-L15485

And once it's been evaluted with no diagnostic, an 
`diag::err_init_element_not_constant` is emitted which triggers an error and so 
it never gets evaluated again with diagnostics enabled.

https://github.com/llvm/llvm-project/blob/72f63b695c9ebd9c7032c4b754ff7965c28fad5c/clang/lib/Sema/SemaDecl.cpp#L12510-L12514

What should I do here? This feels like a weakness of the code in Sema; any 
changes I make here are going to break a bunch of tests which expect no 
diagnostics to be output in these cases.

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


[clang] [clang-format] Add a new style for the clang-format source code (PR #69814)

2023-10-21 Thread Björn Schäpers via cfe-commits

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

What is your goal with that style?

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


[clang] [clang] Implement constexpr bit_cast for vectors (PR #66894)

2023-10-21 Thread via cfe-commits


@@ -140,11 +140,12 @@ void g28(void) {
   typedef short v12i16 __attribute((vector_size(24)));
   typedef long double v2f80 __attribute((vector_size(24)));
   // CHECK: @g28.a = internal global <1 x i64> 
-  // CHECK: @g28.b = internal global <12 x i16> 
-  // CHECK: @g28.c = internal global <2 x x86_fp80> , align 32
+  // @g28.b = internal global <12 x i16> 
+  // @g28.c = internal global <2 x x86_fp80> , align 32
   static v1i64 a = (v1i64)10LL;
-  static v12i16 b = (v12i16)(v2f80){1,2};
-  static v2f80 c = (v2f80)(v12i16){0,0,0,-32768,16383,0,0,0,0,-32768,16384,0};
+  //FIXME: support constant bitcast between vectors of x86_fp80
+  //static v12i16 b = (v12i16)(v2f80){1,2};
+  //static v2f80 c = 
(v2f80)(v12i16){0,0,0,-32768,16383,0,0,0,0,-32768,16384,0};

DaMatrix wrote:

Interestingly, uncommenting these lines doesn't cause any diagnostic messages 
to be generated, only an error stating `error: initializer element is not a 
compile-time constant`. I'll see if I can get the diagnostic to be output and 
change the messages as suggested.

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


[clang] [Driver] Link Flang runtime on FreeBSD, NetBSD, OpenBSD, DragonFly and Haiku (PR #69817)

2023-10-21 Thread Brad Smith via cfe-commits

https://github.com/brad0 created https://github.com/llvm/llvm-project/pull/69817

None

>From d84ffa952d5184ff40d55f7cabc1b421cde5abba Mon Sep 17 00:00:00 2001
From: Brad Smith 
Date: Sat, 21 Oct 2023 03:29:29 -0400
Subject: [PATCH] [Driver] Link Flang runtime on FreeBSD, NetBSD, OpenBSD,
 DragonFly and Haiku

---
 clang/lib/Driver/ToolChains/DragonFly.cpp | 10 ++
 clang/lib/Driver/ToolChains/FreeBSD.cpp   | 14 ++
 clang/lib/Driver/ToolChains/Haiku.cpp |  9 +
 clang/lib/Driver/ToolChains/NetBSD.cpp| 11 +++
 clang/lib/Driver/ToolChains/OpenBSD.cpp   | 14 ++
 flang/test/Driver/linker-flags.f90|  9 +
 6 files changed, 67 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/DragonFly.cpp 
b/clang/lib/Driver/ToolChains/DragonFly.cpp
index 9dc8d9d4363bd71..500dd98665075b1 100644
--- a/clang/lib/Driver/ToolChains/DragonFly.cpp
+++ b/clang/lib/Driver/ToolChains/DragonFly.cpp
@@ -144,6 +144,16 @@ void dragonfly::Linker::ConstructJob(Compilation , const 
JobAction ,
   CmdArgs.push_back("-lm");
 }
 
+// Additional linker set-up and flags for Fortran. This is required in 
order
+// to generate executables. As Fortran runtime depends on the C runtime,
+// these dependencies need to be listed before the C runtime below (i.e.
+// AddRuntTimeLibs).
+if (D.IsFlangMode()) {
+  addFortranRuntimeLibraryPath(ToolChain, Args, CmdArgs);
+  addFortranRuntimeLibs(ToolChain, CmdArgs);
+  CmdArgs.push_back("-lm");
+}
+
 if (Args.hasArg(options::OPT_pthread))
   CmdArgs.push_back("-lpthread");
 
diff --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp 
b/clang/lib/Driver/ToolChains/FreeBSD.cpp
index 7a61159ba4a7308..2a6f7c255e04ea7 100644
--- a/clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -293,6 +293,20 @@ void freebsd::Linker::ConstructJob(Compilation , const 
JobAction ,
   else
 CmdArgs.push_back("-lm");
 }
+
+// Additional linker set-up and flags for Fortran. This is required in 
order
+// to generate executables. As Fortran runtime depends on the C runtime,
+// these dependencies need to be listed before the C runtime below (i.e.
+// AddRuntTimeLibs).
+if (D.IsFlangMode()) {
+  addFortranRuntimeLibraryPath(ToolChain, Args, CmdArgs);
+  addFortranRuntimeLibs(ToolChain, CmdArgs);
+  if (Profiling)
+CmdArgs.push_back("-lm_p");
+  else
+CmdArgs.push_back("-lm");
+}
+
 if (NeedsSanitizerDeps)
   linkSanitizerRuntimeDeps(ToolChain, Args, CmdArgs);
 if (NeedsXRayDeps)
diff --git a/clang/lib/Driver/ToolChains/Haiku.cpp 
b/clang/lib/Driver/ToolChains/Haiku.cpp
index 9f56a0ea5d612d0..41df7838a44a0aa 100644
--- a/clang/lib/Driver/ToolChains/Haiku.cpp
+++ b/clang/lib/Driver/ToolChains/Haiku.cpp
@@ -96,6 +96,15 @@ void haiku::Linker::ConstructJob(Compilation , const 
JobAction ,
 if (D.CCCIsCXX() && ToolChain.ShouldLinkCXXStdlib(Args))
   ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs);
 
+// Additional linker set-up and flags for Fortran. This is required in 
order
+// to generate executables. As Fortran runtime depends on the C runtime,
+// these dependencies need to be listed before the C runtime below (i.e.
+// AddRuntTimeLibs).
+if (D.IsFlangMode()) {
+  addFortranRuntimeLibraryPath(ToolChain, Args, CmdArgs);
+  addFortranRuntimeLibs(ToolChain, CmdArgs);
+}
+
 CmdArgs.push_back("-lgcc");
 
 CmdArgs.push_back("--push-state");
diff --git a/clang/lib/Driver/ToolChains/NetBSD.cpp 
b/clang/lib/Driver/ToolChains/NetBSD.cpp
index 1c901f70f72ca2e..58fb0fc40f57f87 100644
--- a/clang/lib/Driver/ToolChains/NetBSD.cpp
+++ b/clang/lib/Driver/ToolChains/NetBSD.cpp
@@ -314,6 +314,17 @@ void netbsd::Linker::ConstructJob(Compilation , const 
JobAction ,
 ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs);
   CmdArgs.push_back("-lm");
 }
+
+// Additional linker set-up and flags for Fortran. This is required in 
order
+// to generate executables. As Fortran runtime depends on the C runtime,
+// these dependencies need to be listed before the C runtime below (i.e.
+// AddRuntTimeLibs).
+if (D.IsFlangMode()) {
+  addFortranRuntimeLibraryPath(ToolChain, Args, CmdArgs);
+  addFortranRuntimeLibs(ToolChain, CmdArgs);
+  CmdArgs.push_back("-lm");
+}
+
 if (NeedsSanitizerDeps)
   linkSanitizerRuntimeDeps(ToolChain, Args, CmdArgs);
 if (NeedsXRayDeps)
diff --git a/clang/lib/Driver/ToolChains/OpenBSD.cpp 
b/clang/lib/Driver/ToolChains/OpenBSD.cpp
index e874f245776c4fc..457cc1fc2949411 100644
--- a/clang/lib/Driver/ToolChains/OpenBSD.cpp
+++ b/clang/lib/Driver/ToolChains/OpenBSD.cpp
@@ -216,6 +216,20 @@ void openbsd::Linker::ConstructJob(Compilation , const 
JobAction ,
   else
 CmdArgs.push_back("-lm");
 }
+
+// Additional linker set-up and flags for Fortran. This is required in 
order
+// 

[clang] af447dd - [Serialization] Use llvm::is_contained (NFC)

2023-10-21 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2023-10-20T23:45:20-07:00
New Revision: af447dde5e723e925b9c8fdc6715b07f0caf6161

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

LOG: [Serialization] Use llvm::is_contained (NFC)

Added: 


Modified: 
clang/lib/Serialization/ASTReader.cpp

Removed: 




diff  --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index 9061efb6511db51..42b48d230af7a97 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -10115,8 +10115,7 @@ void ASTReader::pushExternalDeclIntoScope(NamedDecl *D, 
DeclarationName Name) {
 // Adding the decl to IdResolver may have failed because it was already in
 // (even though it was not added in scope). If it is already in, make sure
 // it gets in the scope as well.
-if (std::find(SemaObj->IdResolver.begin(Name),
-  SemaObj->IdResolver.end(), D) != SemaObj->IdResolver.end())
+if (llvm::is_contained(SemaObj->IdResolver.decls(Name), D))
   SemaObj->TUScope->AddDecl(D);
   }
 }



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


[clang] [clang-format] Add a new style for the clang-format source code (PR #69814)

2023-10-21 Thread Owen Pan via cfe-commits

owenca wrote:

I don't want to "advertise" this new style in the documentation but am willing 
to be overruled by the majority.

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


[PATCH] D123235: [OpenMP] atomic compare fail : Parser & AST support

2023-10-21 Thread Sunil K via Phabricator via cfe-commits
koops updated this revision to Diff 557820.
koops added a comment.

Correcting a git-clang-format error.


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

https://reviews.llvm.org/D123235

Files:
  clang/include/clang/AST/ASTNodeTraverser.h
  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/Parse/Parser.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/OpenMPClause.cpp
  clang/lib/AST/StmtProfile.cpp
  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

Index: llvm/include/llvm/Frontend/OpenMP/OMP.td
===
--- llvm/include/llvm/Frontend/OpenMP/OMP.td
+++ llvm/include/llvm/Frontend/OpenMP/OMP.td
@@ -209,6 +209,7 @@
 def OMPC_Update : Clause<"update"> { let clangClass = "OMPUpdateClause"; }
 def OMPC_Capture : Clause<"capture"> { let clangClass = "OMPCaptureClause"; }
 def OMPC_Compare : Clause<"compare"> { let clangClass = "OMPCompareClause"; }
+def OMPC_Fail : Clause<"fail"> { let clangClass = "OMPFailClause"; }
 def OMPC_SeqCst : Clause<"seq_cst"> { let clangClass = "OMPSeqCstClause"; }
 def OMPC_AcqRel : Clause<"acq_rel"> { let clangClass = "OMPAcqRelClause"; }
 def OMPC_Acquire : Clause<"acquire"> { let clangClass = "OMPAcquireClause"; }
@@ -637,7 +638,8 @@
 VersionedClause,
 VersionedClause,
 VersionedClause,
-VersionedClause
+VersionedClause,
+VersionedClause
   ];
 }
 def OMP_Target : Directive<"target"> {
Index: flang/lib/Semantics/check-omp-structure.cpp
===
--- flang/lib/Semantics/check-omp-structure.cpp
+++ flang/lib/Semantics/check-omp-structure.cpp
@@ -2164,6 +2164,7 @@
 CHECK_SIMPLE_CLAUSE(Doacross, OMPC_doacross)
 CHECK_SIMPLE_CLAUSE(OmpxAttribute, OMPC_ompx_attribute)
 CHECK_SIMPLE_CLAUSE(OmpxBare, OMPC_ompx_bare)
+CHECK_SIMPLE_CLAUSE(Fail, OMPC_fail)
 
 CHECK_REQ_SCALAR_INT_CLAUSE(Grainsize, OMPC_grainsize)
 CHECK_REQ_SCALAR_INT_CLAUSE(NumTasks, OMPC_num_tasks)
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -2402,6 +2402,8 @@
 
 void OMPClauseEnqueue::VisitOMPCompareClause(const OMPCompareClause *) {}
 
+void OMPClauseEnqueue::VisitOMPFailClause(const OMPFailClause *) {}
+
 void OMPClauseEnqueue::VisitOMPSeqCstClause(const OMPSeqCstClause *) {}
 
 void OMPClauseEnqueue::VisitOMPAcqRelClause(const OMPAcqRelClause *) {}
Index: clang/test/OpenMP/atomic_messages.cpp
===
--- clang/test/OpenMP/atomic_messages.cpp
+++ clang/test/OpenMP/atomic_messages.cpp
@@ -958,6 +958,25 @@
 // expected-error@+1 {{directive '#pragma omp atomic' cannot contain more than one 'capture' clause}}
 #pragma omp atomic compare compare capture capture
   { v = a; if (a > b) a = b; }
+// expected-error@+1 {{expected 'compare' clause with the 'fail' modifier}}
+#pragma omp atomic fail(seq_cst)
+  if(v == a) { v = a; }
+// expected-error@+2 {{expected '(' after 'fail'}}
+// expected-error@+1 {{expected a memory order clause}}
+#pragma omp atomic compare fail
+  if(v < a) { v = a; }
+// expected-error@+1 {{expected a memory order clause}}
+#pragma omp atomic compare fail(capture)
+  if(v < a) { v = a; }
+ // expected-error@+2 {{expected ')' after 'atomic compare fail'}}
+ // expected-warning@+1 {{extra tokens at the end of '#pragma omp atomic' are ignored}}
+#pragma omp atomic compare fail(seq_cst | acquire)
+  if(v < a) { v = a; }
+// expected-error@+1 {{directive '#pragma omp atomic' cannot contain more than one 'fail' clause}}
+#pragma omp atomic compare fail(relaxed) fail(seq_cst)
+  if(v < a) { v = a; }
+
+
 #endif
   // expected-note@+1 {{in instantiation of function template specialization 'mixed' requested here}}
   return mixed();
Index: clang/test/OpenMP/atomic_ast_print.cpp
===
--- clang/test/OpenMP/atomic_ast_print.cpp
+++ clang/test/OpenMP/atomic_ast_print.cpp
@@ -226,6 +226,16 @@
   { v = a; if (a < b) { a = b; } }
 #pragma omp atomic compare capture hint(6)
   { v = a == b; if (v) a = c; }
+#pragma omp atomic compare fail(acq_rel)
+  { if (a < c) { a = c; } }
+#pragma omp atomic compare fail(acquire)
+  { if (a < c) { a = c; } }
+#pragma omp atomic compare fail(release)
+  { if (a < c) { a = c; } }
+#pragma omp atomic compare 

[clang] [clang-format] Add a new style for the clang-format source code (PR #69814)

2023-10-21 Thread Owen Pan via cfe-commits

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

None

>From 78a2661ba7a18ecf8b09be71f6959fbc9fcf70fe Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Fri, 20 Oct 2023 23:01:38 -0700
Subject: [PATCH] [clang-format] Add a new style for the clang-format source
 code

---
 clang/include/clang/Format/Format.h|  2 ++
 clang/lib/Format/Format.cpp| 18 +++---
 clang/unittests/Format/ConfigParseTest.cpp |  7 +++
 3 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index ed92ef6fc655522..4c344135d25163c 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4861,6 +4861,8 @@ FormatStyle getGNUStyle();
 /// 
https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference?view=vs-2017
 FormatStyle getMicrosoftStyle(FormatStyle::LanguageKind Language);
 
+FormatStyle getClangFormatStyle();
+
 /// Returns style indicating formatting should be not applied at all.
 FormatStyle getNoStyle();
 
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index acbed56a86e141f..2f988c4eaf35a57 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -834,8 +834,8 @@ template <> struct MappingTraits {
 
 StringRef BasedOnStyle;
 if (IO.outputting()) {
-  StringRef Styles[] = {"LLVM",   "Google", "Chromium", "Mozilla",
-"WebKit", "GNU","Microsoft"};
+  StringRef Styles[] = {"LLVM",   "Google", "Chromium",  "Mozilla",
+"WebKit", "GNU","Microsoft", "clang-format"};
   for (StringRef StyleName : Styles) {
 FormatStyle PredefinedStyle;
 if (getPredefinedStyle(StyleName, Style.Language, ) &&
@@ -1915,6 +1915,16 @@ FormatStyle getMicrosoftStyle(FormatStyle::LanguageKind 
Language) {
   return Style;
 }
 
+FormatStyle getClangFormatStyle() {
+  FormatStyle Style = getLLVMStyle();
+  Style.InsertBraces = true;
+  Style.InsertNewlineAtEOF = true;
+  Style.LineEnding = FormatStyle::LE_LF;
+  Style.RemoveBracesLLVM = true;
+  Style.RemoveParentheses = FormatStyle::RPS_ReturnStatement;
+  return Style;
+}
+
 FormatStyle getNoStyle() {
   FormatStyle NoStyle = getLLVMStyle();
   NoStyle.DisableFormat = true;
@@ -1939,6 +1949,8 @@ bool getPredefinedStyle(StringRef Name, 
FormatStyle::LanguageKind Language,
 *Style = getGNUStyle();
   else if (Name.equals_insensitive("microsoft"))
 *Style = getMicrosoftStyle(Language);
+  else if (Name.equals_insensitive("clang-format"))
+*Style = getClangFormatStyle();
   else if (Name.equals_insensitive("none"))
 *Style = getNoStyle();
   else if (Name.equals_insensitive("inheritparentconfig"))
@@ -3841,7 +3853,7 @@ LangOptions getFormattingLangOpts(const FormatStyle 
) {
 const char *StyleOptionHelpDescription =
 "Set coding style.  can be:\n"
 "1. A preset: LLVM, GNU, Google, Chromium, Microsoft,\n"
-"   Mozilla, WebKit.\n"
+"   Mozilla, WebKit, clang-format.\n"
 "2. 'file' to load style configuration from a\n"
 "   .clang-format file in one of the parent directories\n"
 "   of the source file (for stdin, see --assume-filename).\n"
diff --git a/clang/unittests/Format/ConfigParseTest.cpp 
b/clang/unittests/Format/ConfigParseTest.cpp
index c35c82955f6a558..ba79c8d72f09552 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -63,6 +63,13 @@ TEST(ConfigParseTest, GetsPredefinedStyleByName) {
   EXPECT_TRUE(getPredefinedStyle("gnU", FormatStyle::LK_Cpp, [2]));
   EXPECT_ALL_STYLES_EQUAL(Styles);
 
+  Styles[0] = getClangFormatStyle();
+  EXPECT_TRUE(
+  getPredefinedStyle("clang-format", FormatStyle::LK_Cpp, [1]));
+  EXPECT_TRUE(
+  getPredefinedStyle("Clang-format", FormatStyle::LK_Cpp, [2]));
+  EXPECT_ALL_STYLES_EQUAL(Styles);
+
   EXPECT_FALSE(getPredefinedStyle("qwerty", FormatStyle::LK_Cpp, [0]));
 }
 

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