[clang] [llvm] [X86] Support EGPR for inline assembly. (PR #92338)

2024-05-24 Thread Shengchen Kan via cfe-commits


@@ -58024,15 +58043,22 @@ X86TargetLowering::getRegForInlineAsmConstraint(const 
TargetRegisterInfo *TRI,
 case 'r':   // GENERAL_REGS
 case 'l':   // INDEX_REGS
   if (VT == MVT::i8 || VT == MVT::i1)
-return std::make_pair(0U, &X86::GR8_NOREX2RegClass);
+return std::make_pair(0U, Subtarget.useInlineAsmGPR32()
+  ? &X86::GR8_NOREX2RegClass
+  : &X86::GR8RegClass);
   if (VT == MVT::i16)
-return std::make_pair(0U, &X86::GR16_NOREX2RegClass);
+return std::make_pair(0U, Subtarget.useInlineAsmGPR32()
+  ? &X86::GR16_NOREX2RegClass
+  : &X86::GR16RegClass);
   if (VT == MVT::i32 || VT == MVT::f32 ||
   (!VT.isVector() && !Subtarget.is64Bit()))
-return std::make_pair(0U, &X86::GR32_NOREX2RegClass);
+return std::make_pair(0U, Subtarget.useInlineAsmGPR32()

KanRobert wrote:

Need to check hasEGPR() too

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


[clang] [llvm] [X86] Support EGPR for inline assembly. (PR #92338)

2024-05-24 Thread Shengchen Kan via cfe-commits


@@ -58255,6 +58281,22 @@ X86TargetLowering::getRegForInlineAsmConstraint(const 
TargetRegisterInfo *TRI,
   }
   break;
 }
+  } else if (Constraint.size() == 2 && Constraint[0] == 'j') {
+switch (Constraint[1]) {
+default:
+  break;
+case 'R':
+  if (VT == MVT::i8 || VT == MVT::i1)
+return std::make_pair(0U, &X86::GR8RegClass);
+  if (VT == MVT::i16)
+return std::make_pair(0U, &X86::GR16RegClass);
+  if (VT == MVT::i32 || VT == MVT::f32 ||
+  (!VT.isVector() && !Subtarget.is64Bit()))
+return std::make_pair(0U, &X86::GR32RegClass);

KanRobert wrote:

The predicate is incorrect.  EGPR is not supported in 32-bit mode.

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


[clang] [llvm] [X86] Support EGPR for inline assembly. (PR #92338)

2024-05-24 Thread Shengchen Kan via cfe-commits


@@ -0,0 +1,16 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: not llc -mtriple=x86_64 %s 2>&1 | FileCheck %s --check-prefix=ERR
+; RUN: llc -mtriple=x86_64 -mattr=+egpr < %s | FileCheck %s
+; RUN: llc -mtriple=x86_64 -mattr=+egpr,+inline-asm-use-gpr32 < %s | FileCheck 
%s
+
+; ERR: error: inline assembly requires more registers than available
+
+define void @constraint_jR_test() nounwind "frame-pointer"="all" {

KanRobert wrote:

Remove "frame-pointer"="all"?

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


[clang] [llvm] [X86] Support EGPR for inline assembly. (PR #92338)

2024-05-24 Thread Shengchen Kan via cfe-commits


@@ -0,0 +1,16 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: not llc -mtriple=x86_64 < %s 2>&1 | FileCheck %s --check-prefix=ERR
+; RUN: not llc -mtriple=x86_64 -mattr=+egpr < %s 2>&1 | FileCheck %s 
--check-prefix=ERR
+; RUN: llc -mtriple=x86_64 -mattr=+egpr,+inline-asm-use-gpr32 < %s | FileCheck 
%s
+
+; ERR: error: inline assembly requires more registers than available
+
+define void @constraint_r_test() nounwind "frame-pointer"="all" {

KanRobert wrote:

ditto

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


[clang] b80d982 - [alpha.webkit.UncountedLocalVarsChecker] Detect assignments to uncounted local variable and parameters. (#92639)

2024-05-24 Thread via cfe-commits

Author: Ryosuke Niwa
Date: 2024-05-24T00:06:06-07:00
New Revision: b80d982a62676314ec93dc8881b9f8957217192a

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

LOG: [alpha.webkit.UncountedLocalVarsChecker] Detect assignments to uncounted 
local variable and parameters. (#92639)

This PR updates alpha.webkit.UncountedLocalVarsChecker to emit warnings
for assignments to uncounted local variable and parameters instead of
just the initialization during the declaration.

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp
clang/test/Analysis/Checkers/WebKit/uncounted-local-vars.cpp

Removed: 




diff  --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp
index 0d9710a5e2d83..274da0baf2ce5 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp
@@ -135,7 +135,19 @@ class UncountedLocalVarsChecker
   bool shouldVisitImplicitCode() const { return false; }
 
   bool VisitVarDecl(VarDecl *V) {
-Checker->visitVarDecl(V);
+auto *Init = V->getInit();
+if (Init && V->isLocalVarDecl())
+  Checker->visitVarDecl(V, Init);
+return true;
+  }
+
+  bool VisitBinaryOperator(const BinaryOperator *BO) {
+if (BO->isAssignmentOp()) {
+  if (auto *VarRef = dyn_cast(BO->getLHS())) {
+if (auto *V = dyn_cast(VarRef->getDecl()))
+  Checker->visitVarDecl(V, BO->getRHS());
+  }
+}
 return true;
   }
 
@@ -174,7 +186,7 @@ class UncountedLocalVarsChecker
 visitor.TraverseDecl(const_cast(TUD));
   }
 
-  void visitVarDecl(const VarDecl *V) const {
+  void visitVarDecl(const VarDecl *V, const Expr *Value) const {
 if (shouldSkipVarDecl(V))
   return;
 
@@ -184,12 +196,8 @@ class UncountedLocalVarsChecker
 
 std::optional IsUncountedPtr = isUncountedPtr(ArgType);
 if (IsUncountedPtr && *IsUncountedPtr) {
-  const Expr *const InitExpr = V->getInit();
-  if (!InitExpr)
-return; // FIXME: later on we might warn on uninitialized vars too
-
   if (tryToFindPtrOrigin(
-  InitExpr, /*StopAtFirstRefCountedObj=*/false,
+  Value, /*StopAtFirstRefCountedObj=*/false,
   [&](const clang::Expr *InitArgOrigin, bool IsSafe) {
 if (!InitArgOrigin)
   return true;
@@ -232,34 +240,46 @@ class UncountedLocalVarsChecker
   }))
 return;
 
-  reportBug(V);
+  reportBug(V, Value);
 }
   }
 
   bool shouldSkipVarDecl(const VarDecl *V) const {
 assert(V);
-if (!V->isLocalVarDecl())
-  return true;
-
-if (BR->getSourceManager().isInSystemHeader(V->getLocation()))
-  return true;
-
-return false;
+return BR->getSourceManager().isInSystemHeader(V->getLocation());
   }
 
-  void reportBug(const VarDecl *V) const {
+  void reportBug(const VarDecl *V, const Expr *Value) const {
 assert(V);
 SmallString<100> Buf;
 llvm::raw_svector_ostream Os(Buf);
 
-Os << "Local variable ";
-printQuotedQualifiedName(Os, V);
-Os << " is uncounted and unsafe.";
-
-PathDiagnosticLocation BSLoc(V->getLocation(), BR->getSourceManager());
-auto Report = std::make_unique(Bug, Os.str(), BSLoc);
-Report->addRange(V->getSourceRange());
-BR->emitReport(std::move(Report));
+if (dyn_cast(V)) {
+  Os << "Assignment to an uncounted parameter ";
+  printQuotedQualifiedName(Os, V);
+  Os << " is unsafe.";
+
+  PathDiagnosticLocation BSLoc(Value->getExprLoc(), 
BR->getSourceManager());
+  auto Report = std::make_unique(Bug, Os.str(), BSLoc);
+  Report->addRange(Value->getSourceRange());
+  BR->emitReport(std::move(Report));
+} else {
+  if (V->hasLocalStorage())
+Os << "Local variable ";
+  else if (V->isStaticLocal())
+Os << "Static local variable ";
+  else if (V->hasGlobalStorage())
+Os << "Global variable ";
+  else
+Os << "Variable ";
+  printQuotedQualifiedName(Os, V);
+  Os << " is uncounted and unsafe.";
+
+  PathDiagnosticLocation BSLoc(V->getLocation(), BR->getSourceManager());
+  auto Report = std::make_unique(Bug, Os.str(), BSLoc);
+  Report->addRange(V->getSourceRange());
+  BR->emitReport(std::move(Report));
+}
   }
 };
 } // namespace

diff  --git a/clang/test/Analysis/Checkers/WebKit/uncounted-local-vars.cpp 
b/clang/test/Analysis/Checkers/WebKit/uncounted-local-vars.cpp
index 632a82eb0d8d1..25776870dd3ae 100644
--- a/clang/test/Analysis/Checkers/WebKit/uncounted-local-vars.cpp
+++ b/

[clang] [alpha.webkit.UncountedLocalVarsChecker] Detect assignments to uncounted local variable and parameters. (PR #92639)

2024-05-24 Thread Ryosuke Niwa via cfe-commits

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


[clang] [llvm] [X86] Support EGPR for inline assembly. (PR #92338)

2024-05-24 Thread Freddy Ye via cfe-commits


@@ -5418,6 +5418,8 @@ X86:
   operand will get allocated only to RAX -- if two 32-bit operands are needed,
   you're better off splitting it yourself, before passing it to the asm
   statement.
+- ``jR``: An 8, 16, 32, or 64-bit integer EGPR when EGPR feature is on.
+  Otherwise, same as ``R``.

FreddyLeaf wrote:

`r` is same as `R` for X86 IIUC. jR is to follow gcc

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


[clang] [llvm] [X86] Support EGPR for inline assembly. (PR #92338)

2024-05-24 Thread Freddy Ye via cfe-commits


@@ -0,0 +1,16 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: not llc -mtriple=x86_64 %s 2>&1 | FileCheck %s --check-prefix=ERR
+; RUN: llc -mtriple=x86_64 -mattr=+egpr < %s | FileCheck %s
+; RUN: llc -mtriple=x86_64 -mattr=+egpr,+inline-asm-use-gpr32 < %s | FileCheck 
%s
+
+; ERR: error: inline assembly requires more registers than available
+
+define void @constraint_jR_test() nounwind "frame-pointer"="all" {

FreddyLeaf wrote:

"frame-pointer"="all" helps throw the error here.

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


[clang] [llvm] [X86] Support EGPR for inline assembly. (PR #92338)

2024-05-24 Thread Shengchen Kan via cfe-commits


@@ -0,0 +1,16 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: not llc -mtriple=x86_64 < %s 2>&1 | FileCheck %s --check-prefix=ERR
+; RUN: not llc -mtriple=x86_64 -mattr=+egpr < %s 2>&1 | FileCheck %s 
--check-prefix=ERR
+; RUN: llc -mtriple=x86_64 -mattr=+egpr,+inline-asm-use-gpr32 < %s | FileCheck 
%s

KanRobert wrote:

I find you also extend the `l` constraint. Should we have a test for it? And 
how about `q` https://github.com/llvm/llvm-project/pull/73529 ?

I think it should be extended too.

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


[clang] [llvm] [PowerPC] Diagnose musttail instead of crash inside backend (PR #93267)

2024-05-24 Thread Chen Zheng via cfe-commits

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


[clang] [llvm] [X86] Support EGPR for inline assembly. (PR #92338)

2024-05-24 Thread Shengchen Kan via cfe-commits


@@ -5418,6 +5418,8 @@ X86:
   operand will get allocated only to RAX -- if two 32-bit operands are needed,
   you're better off splitting it yourself, before passing it to the asm
   statement.
+- ``jR``: An 8, 16, 32, or 64-bit integer EGPR when EGPR feature is on.
+  Otherwise, same as ``R``.

KanRobert wrote:

I think no
```
- ``r`` or ``l``: An 8, 16, 32, or 64-bit integer register.
- ``R``: An 8, 16, 32, or 64-bit "legacy" integer register -- one which has
  existed since i386, and can be accessed without the REX prefix.
```

`jR` seems weird by the existing conventions. We can change the design before 
we have the real users.

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


[clang] [llvm] [X86] Support EGPR for inline assembly. (PR #92338)

2024-05-24 Thread Shengchen Kan via cfe-commits


@@ -0,0 +1,16 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: not llc -mtriple=x86_64 %s 2>&1 | FileCheck %s --check-prefix=ERR
+; RUN: llc -mtriple=x86_64 -mattr=+egpr < %s | FileCheck %s
+; RUN: llc -mtriple=x86_64 -mattr=+egpr,+inline-asm-use-gpr32 < %s | FileCheck 
%s
+
+; ERR: error: inline assembly requires more registers than available
+
+define void @constraint_jR_test() nounwind "frame-pointer"="all" {

KanRobert wrote:

How does it help? The error should not be related to frame pointer.

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


[clang] [clang] Add /Zc:__STDC__ flag to clang-cl (PR #68690)

2024-05-24 Thread via cfe-commits

xbjfk wrote:

Hi @MaxEW707 
Yes, I will need someone to commit this for me.
Thanks!

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


[clang] [llvm] [X86] Support EGPR for inline assembly. (PR #92338)

2024-05-24 Thread Freddy Ye via cfe-commits


@@ -5418,6 +5418,8 @@ X86:
   operand will get allocated only to RAX -- if two 32-bit operands are needed,
   you're better off splitting it yourself, before passing it to the asm
   statement.
+- ``jR``: An 8, 16, 32, or 64-bit integer EGPR when EGPR feature is on.
+  Otherwise, same as ``R``.

FreddyLeaf wrote:

> `r` is same as `R` for X86 IIUC.

Sorry, wrong conclusion. I did bad experiment before, making me judge clang 
didn't clarify for 'R' and 'r' for X86. 

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


[clang] [clang][Sema] Fix crash when diagnosing candidates with parameter packs (PR #93079)

2024-05-24 Thread kadir çetinkaya via cfe-commits


@@ -11298,8 +11298,9 @@ static void DiagnoseBadConversion(Sema &S, 
OverloadCandidate *Cand,
   Expr *FromExpr = Conv.Bad.FromExpr;
   QualType FromTy = Conv.Bad.getFromType();
   QualType ToTy = Conv.Bad.getToType();
-  SourceRange ToParamRange =
-  !isObjectArgument ? Fn->getParamDecl(I)->getSourceRange() : 
SourceRange();
+  SourceRange ToParamRange;
+  if (!isObjectArgument && I < Fn->getNumParams())
+ToParamRange = Fn->getParamDecl(I)->getSourceRange();

kadircet wrote:

> Though I don't think solving this is complicated

sorry I guess I didn't convey full context in my previous message when I just 
said "it requires propagating extra information in the bad conversion about the 
parameter location".  `Fn` in this context is the template decl itself, hence 
the packs in the parameters are dependent. hence we can't simply ask how many 
expansions are there.

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


[clang] [clang] [SemaCXX] Implement CWG2627 Bit-fields and narrowing conversions (PR #78112)

2024-05-24 Thread Mital Ashok via cfe-commits

https://github.com/MitalAshok updated 
https://github.com/llvm/llvm-project/pull/78112

>From 92f8720e3d21521b589d5291f086a2f32b87bfe0 Mon Sep 17 00:00:00 2001
From: Mital Ashok 
Date: Sun, 14 Jan 2024 19:52:31 +
Subject: [PATCH 1/3] [clang] [SemaCXX] Implement CWG2627 Bit-fields and
 narrowing conversions

---
 clang/docs/ReleaseNotes.rst   |   5 +
 .../clang/Basic/DiagnosticSemaKinds.td|   3 +
 clang/include/clang/Sema/Overload.h   |   7 +-
 clang/lib/Sema/SemaExpr.cpp   |  10 +-
 clang/lib/Sema/SemaInit.cpp   |  20 ++-
 clang/lib/Sema/SemaOverload.cpp   | 119 +--
 .../dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp |  24 
 clang/test/CXX/drs/dr26xx.cpp | 136 ++
 clang/www/cxx_dr_status.html  |   2 +-
 9 files changed, 278 insertions(+), 48 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 92563262cc673..28202fc604e29 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -157,6 +157,11 @@ Resolutions to C++ Defect Reports
 - Clang now diagnoses declarative nested-name-specifiers with 
pack-index-specifiers.
   (`CWG2858: Declarative nested-name-specifiers and pack-index-specifiers 
`_).
 
+- Casts from a bit-field to an integral type is now not considered narrowing 
if the
+  width of the bit-field means that all potential values are in the range
+  of the target type, even if the type of the bit-field is larger.
+  (`CWG2627. Bit-fields and narrowing conversions  
`_).
+
 C Language Changes
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index fdca82934cb4d..6cdb439be30ae 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6253,6 +6253,9 @@ def ext_init_list_variable_narrowing_const_reference : 
ExtWarn<
 def ext_init_list_constant_narrowing : ExtWarn<
   "constant expression evaluates to %0 which cannot be narrowed to type %1">,
   InGroup, DefaultError, SFINAEFailure;
+def ext_bit_field_narrowing : Extension<
+  "narrowing non-constant-expression from %0 bit-field of width %2 to %1 is a 
C++23 extension">,
+  InGroup, SFINAEFailure;
 def ext_init_list_constant_narrowing_const_reference : ExtWarn<
   ext_init_list_constant_narrowing.Summary>,
   InGroup, DefaultError, SFINAEFailure;
diff --git a/clang/include/clang/Sema/Overload.h 
b/clang/include/clang/Sema/Overload.h
index 76311b00d2fc5..0d94045cc13f7 100644
--- a/clang/include/clang/Sema/Overload.h
+++ b/clang/include/clang/Sema/Overload.h
@@ -244,7 +244,11 @@ class Sema;
 /// Not a narrowing conversion.
 NK_Not_Narrowing,
 
-/// A narrowing conversion by virtue of the source and destination types.
+/// Not a narrowing conversion in C++23 because the source is a bit-field
+/// whose range can fit in the target type
+NK_BitField_Not_Narrowing,
+
+/// A narrowing conversion by virtue of the source and target types.
 NK_Type_Narrowing,
 
 /// A narrowing conversion, because a constant expression got narrowed.
@@ -387,6 +391,7 @@ class Sema;
 NarrowingKind
 getNarrowingKind(ASTContext &Context, const Expr *Converted,
  APValue &ConstantValue, QualType &ConstantType,
+ unsigned &BitFieldWidth,
  bool IgnoreFloatToIntegralConversion = false) const;
 bool isPointerConversionToBool() const;
 bool isPointerConversionToVoidPointer(ASTContext& Context) const;
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 50f92c496a539..4c16fcc60fc77 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -12361,8 +12361,9 @@ static bool checkThreeWayNarrowingConversion(Sema &S, 
QualType ToType, Expr *E,
 
   APValue PreNarrowingValue;
   QualType PreNarrowingType;
+  unsigned BitFieldWidth;
   switch (SCS.getNarrowingKind(S.Context, E, PreNarrowingValue,
-   PreNarrowingType,
+   PreNarrowingType, BitFieldWidth,
/*IgnoreFloatToIntegralConversion*/ true)) {
   case NK_Dependent_Narrowing:
 // Implicit conversion to a narrower type, but the expression is
@@ -12370,6 +12371,13 @@ static bool checkThreeWayNarrowingConversion(Sema &S, 
QualType ToType, Expr *E,
   case NK_Not_Narrowing:
 return false;
 
+  case NK_BitField_Not_Narrowing:
+if (!S.getLangOpts().CPlusPlus23) {
+  return S.Diag(E->getBeginLoc(), diag::ext_bit_field_narrowing)
+ << FromType << ToType << BitFieldWidth;
+}
+return false;
+
   case NK_Constant_Narrowing:
 // Implicit conversion to a narrower type, and the value is not a constant
 // expression.
diff --git a/clan

[clang] [clang][Sema] Fix crash when diagnosing candidates with parameter packs (PR #93079)

2024-05-24 Thread kadir çetinkaya via cfe-commits

https://github.com/kadircet updated 
https://github.com/llvm/llvm-project/pull/93079

From f7bdd39714e21ff31b3c5aa6a3a18967cb6fef2c Mon Sep 17 00:00:00 2001
From: Kadir Cetinkaya 
Date: Wed, 22 May 2024 19:37:18 +0200
Subject: [PATCH 1/2] [clang][Sema] Fix crash when diagnosing candidates with
 parameter packs

Prevent OOB access.

Fixes https://github.com/llvm/llvm-project/issues/93076
---
 clang/lib/Sema/SemaOverload.cpp  | 5 +++--
 clang/test/SemaCXX/overload-template.cpp | 3 +++
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 0c89fca8d38eb..7465d6d96c20f 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -11301,8 +11301,9 @@ static void DiagnoseBadConversion(Sema &S, 
OverloadCandidate *Cand,
   Expr *FromExpr = Conv.Bad.FromExpr;
   QualType FromTy = Conv.Bad.getFromType();
   QualType ToTy = Conv.Bad.getToType();
-  SourceRange ToParamRange =
-  !isObjectArgument ? Fn->getParamDecl(I)->getSourceRange() : 
SourceRange();
+  SourceRange ToParamRange;
+  if (!isObjectArgument && I < Fn->getNumParams())
+ToParamRange = Fn->getParamDecl(I)->getSourceRange();
 
   if (FromTy == S.Context.OverloadTy) {
 assert(FromExpr && "overload set argument came from implicit argument?");
diff --git a/clang/test/SemaCXX/overload-template.cpp 
b/clang/test/SemaCXX/overload-template.cpp
index 0fe13c479cce2..01cfe87a05831 100644
--- a/clang/test/SemaCXX/overload-template.cpp
+++ b/clang/test/SemaCXX/overload-template.cpp
@@ -58,3 +58,6 @@ namespace overloadCheck{
   }
 }
 #endif
+
+template  int b(a...); // expected-note {{candidate function 
template not viable: no known conversion from 'int ()' to 'int' for 2nd 
argument}}
+int d() { return b(0, d); } // expected-error {{no matching function 
for call to 'b'}}

From 7c5716a726fe0c4a2a3e0ddfe8f992491bd0299d Mon Sep 17 00:00:00 2001
From: Kadir Cetinkaya 
Date: Fri, 24 May 2024 10:25:25 +0200
Subject: [PATCH 2/2] add fixme and improve range handling

---
 clang/lib/Sema/SemaOverload.cpp | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 7465d6d96c20f..86e869c7c72ff 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -13,6 +13,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ASTLambda.h"
 #include "clang/AST/CXXInheritance.h"
+#include "clang/AST/Decl.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/DependenceFlags.h"
@@ -11302,7 +11303,12 @@ static void DiagnoseBadConversion(Sema &S, 
OverloadCandidate *Cand,
   QualType FromTy = Conv.Bad.getFromType();
   QualType ToTy = Conv.Bad.getToType();
   SourceRange ToParamRange;
-  if (!isObjectArgument && I < Fn->getNumParams())
+
+  // FIXME: In presence of parameter packs we can't determine parameter range
+  // reliably, as we don't have access to instantiation.
+  bool HasParamPack = llvm::any_of(Fn->parameters().take_front(I),
+   [](const ParmVarDecl *Parm) { return Parm->isParameterPack(); 
});
+  if (!isObjectArgument && !HasParamPack)
 ToParamRange = Fn->getParamDecl(I)->getSourceRange();
 
   if (FromTy == S.Context.OverloadTy) {

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


[clang] [clang][Sema] Fix crash when diagnosing candidates with parameter packs (PR #93079)

2024-05-24 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 a79a0c52885c3a60d6afdda3b125866b8ed75fce 
7c5716a726fe0c4a2a3e0ddfe8f992491bd0299d -- clang/lib/Sema/SemaOverload.cpp 
clang/test/SemaCXX/overload-template.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 86e869c7c7..61d3c1633a 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -11306,8 +11306,10 @@ static void DiagnoseBadConversion(Sema &S, 
OverloadCandidate *Cand,
 
   // FIXME: In presence of parameter packs we can't determine parameter range
   // reliably, as we don't have access to instantiation.
-  bool HasParamPack = llvm::any_of(Fn->parameters().take_front(I),
-   [](const ParmVarDecl *Parm) { return Parm->isParameterPack(); 
});
+  bool HasParamPack =
+  llvm::any_of(Fn->parameters().take_front(I), [](const ParmVarDecl *Parm) 
{
+return Parm->isParameterPack();
+  });
   if (!isObjectArgument && !HasParamPack)
 ToParamRange = Fn->getParamDecl(I)->getSourceRange();
 

``




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


[clang] [clang][Sema] Fix crash when diagnosing candidates with parameter packs (PR #93079)

2024-05-24 Thread kadir çetinkaya via cfe-commits

https://github.com/kadircet updated 
https://github.com/llvm/llvm-project/pull/93079

From 6a057ff4b539045ce81e55b63702892496d18a97 Mon Sep 17 00:00:00 2001
From: Kadir Cetinkaya 
Date: Wed, 22 May 2024 19:37:18 +0200
Subject: [PATCH] [clang][Sema] Fix crash when diagnosing candidates with
 parameter packs

Prevent OOB access.

Fixes https://github.com/llvm/llvm-project/issues/93076.
Fixes https://github.com/llvm/llvm-project/issues/76354.
Fixes https://github.com/llvm/llvm-project/issues/70191.
---
 clang/lib/Sema/SemaOverload.cpp  | 11 +--
 clang/test/SemaCXX/overload-template.cpp |  3 +++
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 0c89fca8d38eb..86e869c7c72ff 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -13,6 +13,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ASTLambda.h"
 #include "clang/AST/CXXInheritance.h"
+#include "clang/AST/Decl.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/DependenceFlags.h"
@@ -11301,8 +11302,14 @@ static void DiagnoseBadConversion(Sema &S, 
OverloadCandidate *Cand,
   Expr *FromExpr = Conv.Bad.FromExpr;
   QualType FromTy = Conv.Bad.getFromType();
   QualType ToTy = Conv.Bad.getToType();
-  SourceRange ToParamRange =
-  !isObjectArgument ? Fn->getParamDecl(I)->getSourceRange() : 
SourceRange();
+  SourceRange ToParamRange;
+
+  // FIXME: In presence of parameter packs we can't determine parameter range
+  // reliably, as we don't have access to instantiation.
+  bool HasParamPack = llvm::any_of(Fn->parameters().take_front(I),
+   [](const ParmVarDecl *Parm) { return Parm->isParameterPack(); 
});
+  if (!isObjectArgument && !HasParamPack)
+ToParamRange = Fn->getParamDecl(I)->getSourceRange();
 
   if (FromTy == S.Context.OverloadTy) {
 assert(FromExpr && "overload set argument came from implicit argument?");
diff --git a/clang/test/SemaCXX/overload-template.cpp 
b/clang/test/SemaCXX/overload-template.cpp
index 0fe13c479cce2..01cfe87a05831 100644
--- a/clang/test/SemaCXX/overload-template.cpp
+++ b/clang/test/SemaCXX/overload-template.cpp
@@ -58,3 +58,6 @@ namespace overloadCheck{
   }
 }
 #endif
+
+template  int b(a...); // expected-note {{candidate function 
template not viable: no known conversion from 'int ()' to 'int' for 2nd 
argument}}
+int d() { return b(0, d); } // expected-error {{no matching function 
for call to 'b'}}

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


[clang] [clang] [SemaCXX] Implement CWG2627 Bit-fields and narrowing conversions (PR #78112)

2024-05-24 Thread Mital Ashok via cfe-commits

https://github.com/MitalAshok updated 
https://github.com/llvm/llvm-project/pull/78112

>From 92f8720e3d21521b589d5291f086a2f32b87bfe0 Mon Sep 17 00:00:00 2001
From: Mital Ashok 
Date: Sun, 14 Jan 2024 19:52:31 +
Subject: [PATCH 1/3] [clang] [SemaCXX] Implement CWG2627 Bit-fields and
 narrowing conversions

---
 clang/docs/ReleaseNotes.rst   |   5 +
 .../clang/Basic/DiagnosticSemaKinds.td|   3 +
 clang/include/clang/Sema/Overload.h   |   7 +-
 clang/lib/Sema/SemaExpr.cpp   |  10 +-
 clang/lib/Sema/SemaInit.cpp   |  20 ++-
 clang/lib/Sema/SemaOverload.cpp   | 119 +--
 .../dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp |  24 
 clang/test/CXX/drs/dr26xx.cpp | 136 ++
 clang/www/cxx_dr_status.html  |   2 +-
 9 files changed, 278 insertions(+), 48 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 92563262cc673..28202fc604e29 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -157,6 +157,11 @@ Resolutions to C++ Defect Reports
 - Clang now diagnoses declarative nested-name-specifiers with 
pack-index-specifiers.
   (`CWG2858: Declarative nested-name-specifiers and pack-index-specifiers 
`_).
 
+- Casts from a bit-field to an integral type is now not considered narrowing 
if the
+  width of the bit-field means that all potential values are in the range
+  of the target type, even if the type of the bit-field is larger.
+  (`CWG2627. Bit-fields and narrowing conversions  
`_).
+
 C Language Changes
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index fdca82934cb4d..6cdb439be30ae 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6253,6 +6253,9 @@ def ext_init_list_variable_narrowing_const_reference : 
ExtWarn<
 def ext_init_list_constant_narrowing : ExtWarn<
   "constant expression evaluates to %0 which cannot be narrowed to type %1">,
   InGroup, DefaultError, SFINAEFailure;
+def ext_bit_field_narrowing : Extension<
+  "narrowing non-constant-expression from %0 bit-field of width %2 to %1 is a 
C++23 extension">,
+  InGroup, SFINAEFailure;
 def ext_init_list_constant_narrowing_const_reference : ExtWarn<
   ext_init_list_constant_narrowing.Summary>,
   InGroup, DefaultError, SFINAEFailure;
diff --git a/clang/include/clang/Sema/Overload.h 
b/clang/include/clang/Sema/Overload.h
index 76311b00d2fc5..0d94045cc13f7 100644
--- a/clang/include/clang/Sema/Overload.h
+++ b/clang/include/clang/Sema/Overload.h
@@ -244,7 +244,11 @@ class Sema;
 /// Not a narrowing conversion.
 NK_Not_Narrowing,
 
-/// A narrowing conversion by virtue of the source and destination types.
+/// Not a narrowing conversion in C++23 because the source is a bit-field
+/// whose range can fit in the target type
+NK_BitField_Not_Narrowing,
+
+/// A narrowing conversion by virtue of the source and target types.
 NK_Type_Narrowing,
 
 /// A narrowing conversion, because a constant expression got narrowed.
@@ -387,6 +391,7 @@ class Sema;
 NarrowingKind
 getNarrowingKind(ASTContext &Context, const Expr *Converted,
  APValue &ConstantValue, QualType &ConstantType,
+ unsigned &BitFieldWidth,
  bool IgnoreFloatToIntegralConversion = false) const;
 bool isPointerConversionToBool() const;
 bool isPointerConversionToVoidPointer(ASTContext& Context) const;
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 50f92c496a539..4c16fcc60fc77 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -12361,8 +12361,9 @@ static bool checkThreeWayNarrowingConversion(Sema &S, 
QualType ToType, Expr *E,
 
   APValue PreNarrowingValue;
   QualType PreNarrowingType;
+  unsigned BitFieldWidth;
   switch (SCS.getNarrowingKind(S.Context, E, PreNarrowingValue,
-   PreNarrowingType,
+   PreNarrowingType, BitFieldWidth,
/*IgnoreFloatToIntegralConversion*/ true)) {
   case NK_Dependent_Narrowing:
 // Implicit conversion to a narrower type, but the expression is
@@ -12370,6 +12371,13 @@ static bool checkThreeWayNarrowingConversion(Sema &S, 
QualType ToType, Expr *E,
   case NK_Not_Narrowing:
 return false;
 
+  case NK_BitField_Not_Narrowing:
+if (!S.getLangOpts().CPlusPlus23) {
+  return S.Diag(E->getBeginLoc(), diag::ext_bit_field_narrowing)
+ << FromType << ToType << BitFieldWidth;
+}
+return false;
+
   case NK_Constant_Narrowing:
 // Implicit conversion to a narrower type, and the value is not a constant
 // expression.
diff --git a/clan

[clang] [clang][Sema] Fix crash when diagnosing candidates with parameter packs (PR #93079)

2024-05-24 Thread kadir çetinkaya via cfe-commits

kadircet wrote:

@shafik thx for the pointers, i didn't know this came up before and even there 
were attempted fixes. I can verify that both of those are also fixed with this 
patch.

@knightXun do you plan to proceed with 
https://github.com/llvm/llvm-project/pull/70280 ? If so I am happy to discard 
this PR in favor of yours.

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


[clang] [llvm] [X86] Support EGPR for inline assembly. (PR #92338)

2024-05-24 Thread Freddy Ye via cfe-commits


@@ -58024,15 +58043,22 @@ X86TargetLowering::getRegForInlineAsmConstraint(const 
TargetRegisterInfo *TRI,
 case 'r':   // GENERAL_REGS
 case 'l':   // INDEX_REGS
   if (VT == MVT::i8 || VT == MVT::i1)
-return std::make_pair(0U, &X86::GR8_NOREX2RegClass);
+return std::make_pair(0U, Subtarget.useInlineAsmGPR32()
+  ? &X86::GR8_NOREX2RegClass
+  : &X86::GR8RegClass);
   if (VT == MVT::i16)
-return std::make_pair(0U, &X86::GR16_NOREX2RegClass);
+return std::make_pair(0U, Subtarget.useInlineAsmGPR32()
+  ? &X86::GR16_NOREX2RegClass
+  : &X86::GR16RegClass);
   if (VT == MVT::i32 || VT == MVT::f32 ||
   (!VT.isVector() && !Subtarget.is64Bit()))
-return std::make_pair(0U, &X86::GR32_NOREX2RegClass);
+return std::make_pair(0U, Subtarget.useInlineAsmGPR32()

FreddyLeaf wrote:

covered by getPreserverdRegister in RA.

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


[clang] [llvm] [X86] Support EGPR for inline assembly. (PR #92338)

2024-05-24 Thread Shengchen Kan via cfe-commits


@@ -58024,15 +58043,22 @@ X86TargetLowering::getRegForInlineAsmConstraint(const 
TargetRegisterInfo *TRI,
 case 'r':   // GENERAL_REGS
 case 'l':   // INDEX_REGS
   if (VT == MVT::i8 || VT == MVT::i1)
-return std::make_pair(0U, &X86::GR8_NOREX2RegClass);
+return std::make_pair(0U, Subtarget.useInlineAsmGPR32()
+  ? &X86::GR8_NOREX2RegClass
+  : &X86::GR8RegClass);
   if (VT == MVT::i16)
-return std::make_pair(0U, &X86::GR16_NOREX2RegClass);
+return std::make_pair(0U, Subtarget.useInlineAsmGPR32()
+  ? &X86::GR16_NOREX2RegClass
+  : &X86::GR16RegClass);
   if (VT == MVT::i32 || VT == MVT::f32 ||
   (!VT.isVector() && !Subtarget.is64Bit()))
-return std::make_pair(0U, &X86::GR32_NOREX2RegClass);
+return std::make_pair(0U, Subtarget.useInlineAsmGPR32()

KanRobert wrote:

The order should be reversed.
Subtarget.useInlineAsmGPR32() ? GR32 : GR32_NOREX2

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


[clang] [clang][Sema] Fix crash when diagnosing candidates with parameter packs (PR #93079)

2024-05-24 Thread kadir çetinkaya via cfe-commits

https://github.com/kadircet updated 
https://github.com/llvm/llvm-project/pull/93079

From 9c691ab41ba500c1962bf9d63de86b65f184f047 Mon Sep 17 00:00:00 2001
From: Kadir Cetinkaya 
Date: Wed, 22 May 2024 19:37:18 +0200
Subject: [PATCH] [clang][Sema] Fix crash when diagnosing candidates with
 parameter packs

Prevent OOB access by not printing target parameter range when there's a
pack in the function parameters.

Fixes https://github.com/llvm/llvm-project/issues/93076.
Fixes https://github.com/llvm/llvm-project/issues/76354.
Fixes https://github.com/llvm/llvm-project/issues/70191.
---
 clang/docs/ReleaseNotes.rst  |  3 ++-
 clang/lib/Sema/SemaOverload.cpp  | 11 +--
 clang/test/SemaCXX/overload-template.cpp |  3 +++
 3 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 45676a02b760b..023af70572306 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -730,7 +730,6 @@ Bug Fixes to C++ Support
   from being explicitly specialized for a given implicit instantiation of the 
class template.
 - Fixed a crash when ``this`` is used in a dependent class scope function 
template specialization
   that instantiates to a static member function.
-
 - Fix crash when inheriting from a cv-qualified type. Fixes #GH35603
 - Fix a crash when the using enum declaration uses an anonymous enumeration. 
Fixes (#GH86790).
 - Handled an edge case in ``getFullyPackExpandedSize`` so that we now avoid a 
false-positive diagnostic. (#GH84220)
@@ -790,6 +789,8 @@ Bug Fixes to C++ Support
   Fixes (#GH87210), (GH89541).
 - Clang no longer tries to check if an expression is immediate-escalating in 
an unevaluated context.
   Fixes (#GH91308).
+- Fixed a crash when diagnosing failed conversions involving template parameter
+  packs. (#GH93076)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 0c89fca8d38eb..86e869c7c72ff 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -13,6 +13,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ASTLambda.h"
 #include "clang/AST/CXXInheritance.h"
+#include "clang/AST/Decl.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/DependenceFlags.h"
@@ -11301,8 +11302,14 @@ static void DiagnoseBadConversion(Sema &S, 
OverloadCandidate *Cand,
   Expr *FromExpr = Conv.Bad.FromExpr;
   QualType FromTy = Conv.Bad.getFromType();
   QualType ToTy = Conv.Bad.getToType();
-  SourceRange ToParamRange =
-  !isObjectArgument ? Fn->getParamDecl(I)->getSourceRange() : 
SourceRange();
+  SourceRange ToParamRange;
+
+  // FIXME: In presence of parameter packs we can't determine parameter range
+  // reliably, as we don't have access to instantiation.
+  bool HasParamPack = llvm::any_of(Fn->parameters().take_front(I),
+   [](const ParmVarDecl *Parm) { return Parm->isParameterPack(); 
});
+  if (!isObjectArgument && !HasParamPack)
+ToParamRange = Fn->getParamDecl(I)->getSourceRange();
 
   if (FromTy == S.Context.OverloadTy) {
 assert(FromExpr && "overload set argument came from implicit argument?");
diff --git a/clang/test/SemaCXX/overload-template.cpp 
b/clang/test/SemaCXX/overload-template.cpp
index 0fe13c479cce2..01cfe87a05831 100644
--- a/clang/test/SemaCXX/overload-template.cpp
+++ b/clang/test/SemaCXX/overload-template.cpp
@@ -58,3 +58,6 @@ namespace overloadCheck{
   }
 }
 #endif
+
+template  int b(a...); // expected-note {{candidate function 
template not viable: no known conversion from 'int ()' to 'int' for 2nd 
argument}}
+int d() { return b(0, d); } // expected-error {{no matching function 
for call to 'b'}}

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


[clang] [analyzer] Fix a test issue in mingw configurations (PR #92737)

2024-05-24 Thread via cfe-commits

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

lgtm

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


[clang] [clang-scan-deps] Expand response files before the argument adjuster (PR #89950)

2024-05-24 Thread Jan Svoboda via cfe-commits


@@ -86,6 +86,8 @@ static bool DeprecatedDriverCommand;
 static ResourceDirRecipeKind ResourceDirRecipe;
 static bool Verbose;
 static bool PrintTiming;
+static llvm::BumpPtrAllocator Alloc;
+static llvm::StringSaver Saver{Alloc};

jansvoboda11 wrote:

Why do these need to be global?

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


[clang] [clang-scan-deps] Expand response files before the argument adjuster (PR #89950)

2024-05-24 Thread Jan Svoboda via cfe-commits


@@ -0,0 +1,36 @@
+// Check that the scanner can adjust arguments by reading .rsp files in 
advance.
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json

jansvoboda11 wrote:

Ok, that makes sense, thanks!

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


[clang] [clang-scan-deps] Expand response files before the argument adjuster (PR #89950)

2024-05-24 Thread Jan Svoboda via cfe-commits

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


[clang] [clang-scan-deps] Expand response files before the argument adjuster (PR #89950)

2024-05-24 Thread Jan Svoboda via cfe-commits

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

LGTM, thanks!

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


[clang-tools-extra] clang-doc switched from using relative to absolute paths (PR #93281)

2024-05-24 Thread via cfe-commits

https://github.com/PeterChou1 created 
https://github.com/llvm/llvm-project/pull/93281

issue: https://github.com/llvm/llvm-project/issues/92867

I solved the problem by making the js use absolute path instead relative I 
think this also makes it more permanent since there is no need to compute 
relative path anymore

>From f5872e7c82d097ae3c141765d3f1d7e3d0b25b82 Mon Sep 17 00:00:00 2001
From: PeterChou1 
Date: Fri, 24 May 2024 04:28:08 -0400
Subject: [PATCH] clang-doc switched from using relative to absolute paths

---
 clang-tools-extra/clang-doc/assets/index.js | 72 ++---
 1 file changed, 35 insertions(+), 37 deletions(-)

diff --git a/clang-tools-extra/clang-doc/assets/index.js 
b/clang-tools-extra/clang-doc/assets/index.js
index a5ac90f2e06e7..fe35e706cc98d 100644
--- a/clang-tools-extra/clang-doc/assets/index.js
+++ b/clang-tools-extra/clang-doc/assets/index.js
@@ -1,48 +1,46 @@
-// Append using posix-style a file name or directory to Base
-function append(Base, New) {
-  if (!New)
-return Base;
-  if (Base)
-Base += "/";
-  Base += New;
-  return Base;
-}
-
-// Get relative path to access FilePath from CurrentDirectory
-function computeRelativePath(FilePath, CurrentDirectory) {
-  var Path = FilePath;
-  while (Path) {
-if (CurrentDirectory == Path)
-  return FilePath.substring(Path.length + 1);
-Path = Path.substring(0, Path.lastIndexOf("/"));
-  }
-
-  var Dir = CurrentDirectory;
-  var Result = "";
-  while (Dir) {
-if (Dir == FilePath)
-  break;
-Dir = Dir.substring(0, Dir.lastIndexOf("/"));
-Result = append(Result, "..")
+function genLink(Ref) {
+  var Path = 
`${window.location.protocol}//${window.location.host}/${Ref.Path}`;
+  if (Ref.RefType !== "namespace") {
+if (Ref.Path === "") {
+  Path = `${Path}${Ref.Name}.html`;
+}
+else {
+  Path = `${Path}/${Ref.Name}.html`;
+}
   }
-  Result = append(Result, FilePath.substring(Dir.length))
-  return Result;
-}
-
-function genLink(Ref, CurrentDirectory) {
-  var Path = computeRelativePath(Ref.Path, CurrentDirectory);
-  if (Ref.RefType == "namespace")
-Path = append(Path, "index.html");
-  else
-Path = append(Path, Ref.Name + ".html")
 
-ANode = document.createElement("a");
+  ANode = document.createElement("a");
   ANode.setAttribute("href", Path);
   var TextNode = document.createTextNode(Ref.Name);
   ANode.appendChild(TextNode);
   return ANode;
 }
 
+function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) {
+  // Out will store the HTML elements that Index requires to be generated
+  var Out = [];
+  if (Index.Name) {
+var SpanNode = document.createElement("span");
+var TextNode = document.createTextNode(Index.Name);
+SpanNode.appendChild(genLink(Index));
+Out.push(SpanNode);
+  }
+  if (Index.Children.length == 0)
+return Out;
+  // Only the outermost list should use ol, the others should use ul
+  var ListNodeName = IsOutermostList ? "ol" : "ul";
+  var ListNode = document.createElement(ListNodeName);
+  for (Child of Index.Children) {
+var LiNode = document.createElement("li");
+ChildNodes = genHTMLOfIndex(Child, CurrentDirectory, false);
+for (Node of ChildNodes)
+  LiNode.appendChild(Node);
+ListNode.appendChild(LiNode);
+  }
+  Out.push(ListNode);
+  return Out;
+}
+
 function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) {
   // Out will store the HTML elements that Index requires to be generated
   var Out = [];

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


[clang-tools-extra] clang-doc switched from using relative to absolute paths (PR #93281)

2024-05-24 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tools-extra

Author: None (PeterChou1)


Changes

issue: https://github.com/llvm/llvm-project/issues/92867

I solved the problem by making the js use absolute path instead relative I 
think this also makes it more permanent since there is no need to compute 
relative path anymore

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


1 Files Affected:

- (modified) clang-tools-extra/clang-doc/assets/index.js (+35-37) 


``diff
diff --git a/clang-tools-extra/clang-doc/assets/index.js 
b/clang-tools-extra/clang-doc/assets/index.js
index a5ac90f2e06e7..fe35e706cc98d 100644
--- a/clang-tools-extra/clang-doc/assets/index.js
+++ b/clang-tools-extra/clang-doc/assets/index.js
@@ -1,48 +1,46 @@
-// Append using posix-style a file name or directory to Base
-function append(Base, New) {
-  if (!New)
-return Base;
-  if (Base)
-Base += "/";
-  Base += New;
-  return Base;
-}
-
-// Get relative path to access FilePath from CurrentDirectory
-function computeRelativePath(FilePath, CurrentDirectory) {
-  var Path = FilePath;
-  while (Path) {
-if (CurrentDirectory == Path)
-  return FilePath.substring(Path.length + 1);
-Path = Path.substring(0, Path.lastIndexOf("/"));
-  }
-
-  var Dir = CurrentDirectory;
-  var Result = "";
-  while (Dir) {
-if (Dir == FilePath)
-  break;
-Dir = Dir.substring(0, Dir.lastIndexOf("/"));
-Result = append(Result, "..")
+function genLink(Ref) {
+  var Path = 
`${window.location.protocol}//${window.location.host}/${Ref.Path}`;
+  if (Ref.RefType !== "namespace") {
+if (Ref.Path === "") {
+  Path = `${Path}${Ref.Name}.html`;
+}
+else {
+  Path = `${Path}/${Ref.Name}.html`;
+}
   }
-  Result = append(Result, FilePath.substring(Dir.length))
-  return Result;
-}
-
-function genLink(Ref, CurrentDirectory) {
-  var Path = computeRelativePath(Ref.Path, CurrentDirectory);
-  if (Ref.RefType == "namespace")
-Path = append(Path, "index.html");
-  else
-Path = append(Path, Ref.Name + ".html")
 
-ANode = document.createElement("a");
+  ANode = document.createElement("a");
   ANode.setAttribute("href", Path);
   var TextNode = document.createTextNode(Ref.Name);
   ANode.appendChild(TextNode);
   return ANode;
 }
 
+function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) {
+  // Out will store the HTML elements that Index requires to be generated
+  var Out = [];
+  if (Index.Name) {
+var SpanNode = document.createElement("span");
+var TextNode = document.createTextNode(Index.Name);
+SpanNode.appendChild(genLink(Index));
+Out.push(SpanNode);
+  }
+  if (Index.Children.length == 0)
+return Out;
+  // Only the outermost list should use ol, the others should use ul
+  var ListNodeName = IsOutermostList ? "ol" : "ul";
+  var ListNode = document.createElement(ListNodeName);
+  for (Child of Index.Children) {
+var LiNode = document.createElement("li");
+ChildNodes = genHTMLOfIndex(Child, CurrentDirectory, false);
+for (Node of ChildNodes)
+  LiNode.appendChild(Node);
+ListNode.appendChild(LiNode);
+  }
+  Out.push(ListNode);
+  return Out;
+}
+
 function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) {
   // Out will store the HTML elements that Index requires to be generated
   var Out = [];

``




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


[clang] [clang][Driver] Fix enabling strict alising by default when the environment is MSVC (PR #91689)

2024-05-24 Thread via cfe-commits

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

lgtm

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


[clang-tools-extra] clang-doc switched from using relative to absolute paths (PR #93281)

2024-05-24 Thread via cfe-commits

https://github.com/PeterChou1 updated 
https://github.com/llvm/llvm-project/pull/93281

>From f5872e7c82d097ae3c141765d3f1d7e3d0b25b82 Mon Sep 17 00:00:00 2001
From: PeterChou1 
Date: Fri, 24 May 2024 04:28:08 -0400
Subject: [PATCH 1/2] clang-doc switched from using relative to absolute paths

---
 clang-tools-extra/clang-doc/assets/index.js | 72 ++---
 1 file changed, 35 insertions(+), 37 deletions(-)

diff --git a/clang-tools-extra/clang-doc/assets/index.js 
b/clang-tools-extra/clang-doc/assets/index.js
index a5ac90f2e06e7..fe35e706cc98d 100644
--- a/clang-tools-extra/clang-doc/assets/index.js
+++ b/clang-tools-extra/clang-doc/assets/index.js
@@ -1,48 +1,46 @@
-// Append using posix-style a file name or directory to Base
-function append(Base, New) {
-  if (!New)
-return Base;
-  if (Base)
-Base += "/";
-  Base += New;
-  return Base;
-}
-
-// Get relative path to access FilePath from CurrentDirectory
-function computeRelativePath(FilePath, CurrentDirectory) {
-  var Path = FilePath;
-  while (Path) {
-if (CurrentDirectory == Path)
-  return FilePath.substring(Path.length + 1);
-Path = Path.substring(0, Path.lastIndexOf("/"));
-  }
-
-  var Dir = CurrentDirectory;
-  var Result = "";
-  while (Dir) {
-if (Dir == FilePath)
-  break;
-Dir = Dir.substring(0, Dir.lastIndexOf("/"));
-Result = append(Result, "..")
+function genLink(Ref) {
+  var Path = 
`${window.location.protocol}//${window.location.host}/${Ref.Path}`;
+  if (Ref.RefType !== "namespace") {
+if (Ref.Path === "") {
+  Path = `${Path}${Ref.Name}.html`;
+}
+else {
+  Path = `${Path}/${Ref.Name}.html`;
+}
   }
-  Result = append(Result, FilePath.substring(Dir.length))
-  return Result;
-}
-
-function genLink(Ref, CurrentDirectory) {
-  var Path = computeRelativePath(Ref.Path, CurrentDirectory);
-  if (Ref.RefType == "namespace")
-Path = append(Path, "index.html");
-  else
-Path = append(Path, Ref.Name + ".html")
 
-ANode = document.createElement("a");
+  ANode = document.createElement("a");
   ANode.setAttribute("href", Path);
   var TextNode = document.createTextNode(Ref.Name);
   ANode.appendChild(TextNode);
   return ANode;
 }
 
+function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) {
+  // Out will store the HTML elements that Index requires to be generated
+  var Out = [];
+  if (Index.Name) {
+var SpanNode = document.createElement("span");
+var TextNode = document.createTextNode(Index.Name);
+SpanNode.appendChild(genLink(Index));
+Out.push(SpanNode);
+  }
+  if (Index.Children.length == 0)
+return Out;
+  // Only the outermost list should use ol, the others should use ul
+  var ListNodeName = IsOutermostList ? "ol" : "ul";
+  var ListNode = document.createElement(ListNodeName);
+  for (Child of Index.Children) {
+var LiNode = document.createElement("li");
+ChildNodes = genHTMLOfIndex(Child, CurrentDirectory, false);
+for (Node of ChildNodes)
+  LiNode.appendChild(Node);
+ListNode.appendChild(LiNode);
+  }
+  Out.push(ListNode);
+  return Out;
+}
+
 function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) {
   // Out will store the HTML elements that Index requires to be generated
   var Out = [];

>From a22609f75064194604e476a12bc8154676dacfb9 Mon Sep 17 00:00:00 2001
From: PeterChou1 
Date: Fri, 24 May 2024 05:10:03 -0400
Subject: [PATCH 2/2] remove duplicate function

---
 clang-tools-extra/clang-doc/assets/index.js | 24 -
 1 file changed, 24 deletions(-)

diff --git a/clang-tools-extra/clang-doc/assets/index.js 
b/clang-tools-extra/clang-doc/assets/index.js
index fe35e706cc98d..b013418c82093 100644
--- a/clang-tools-extra/clang-doc/assets/index.js
+++ b/clang-tools-extra/clang-doc/assets/index.js
@@ -16,30 +16,6 @@ function genLink(Ref) {
   return ANode;
 }
 
-function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) {
-  // Out will store the HTML elements that Index requires to be generated
-  var Out = [];
-  if (Index.Name) {
-var SpanNode = document.createElement("span");
-var TextNode = document.createTextNode(Index.Name);
-SpanNode.appendChild(genLink(Index));
-Out.push(SpanNode);
-  }
-  if (Index.Children.length == 0)
-return Out;
-  // Only the outermost list should use ol, the others should use ul
-  var ListNodeName = IsOutermostList ? "ol" : "ul";
-  var ListNode = document.createElement(ListNodeName);
-  for (Child of Index.Children) {
-var LiNode = document.createElement("li");
-ChildNodes = genHTMLOfIndex(Child, CurrentDirectory, false);
-for (Node of ChildNodes)
-  LiNode.appendChild(Node);
-ListNode.appendChild(LiNode);
-  }
-  Out.push(ListNode);
-  return Out;
-}
 
 function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) {
   // Out will store the HTML elements that Index requires to be generated

___
cfe-commits mailing list
cfe-commits@lists.llvm.or

[clang-tools-extra] clang-doc switched from using relative to absolute paths (PR #93281)

2024-05-24 Thread Florian Hahn via cfe-commits

https://github.com/fhahn updated https://github.com/llvm/llvm-project/pull/93281

>From f5872e7c82d097ae3c141765d3f1d7e3d0b25b82 Mon Sep 17 00:00:00 2001
From: PeterChou1 
Date: Fri, 24 May 2024 04:28:08 -0400
Subject: [PATCH 1/2] clang-doc switched from using relative to absolute paths

---
 clang-tools-extra/clang-doc/assets/index.js | 72 ++---
 1 file changed, 35 insertions(+), 37 deletions(-)

diff --git a/clang-tools-extra/clang-doc/assets/index.js 
b/clang-tools-extra/clang-doc/assets/index.js
index a5ac90f2e06e7..fe35e706cc98d 100644
--- a/clang-tools-extra/clang-doc/assets/index.js
+++ b/clang-tools-extra/clang-doc/assets/index.js
@@ -1,48 +1,46 @@
-// Append using posix-style a file name or directory to Base
-function append(Base, New) {
-  if (!New)
-return Base;
-  if (Base)
-Base += "/";
-  Base += New;
-  return Base;
-}
-
-// Get relative path to access FilePath from CurrentDirectory
-function computeRelativePath(FilePath, CurrentDirectory) {
-  var Path = FilePath;
-  while (Path) {
-if (CurrentDirectory == Path)
-  return FilePath.substring(Path.length + 1);
-Path = Path.substring(0, Path.lastIndexOf("/"));
-  }
-
-  var Dir = CurrentDirectory;
-  var Result = "";
-  while (Dir) {
-if (Dir == FilePath)
-  break;
-Dir = Dir.substring(0, Dir.lastIndexOf("/"));
-Result = append(Result, "..")
+function genLink(Ref) {
+  var Path = 
`${window.location.protocol}//${window.location.host}/${Ref.Path}`;
+  if (Ref.RefType !== "namespace") {
+if (Ref.Path === "") {
+  Path = `${Path}${Ref.Name}.html`;
+}
+else {
+  Path = `${Path}/${Ref.Name}.html`;
+}
   }
-  Result = append(Result, FilePath.substring(Dir.length))
-  return Result;
-}
-
-function genLink(Ref, CurrentDirectory) {
-  var Path = computeRelativePath(Ref.Path, CurrentDirectory);
-  if (Ref.RefType == "namespace")
-Path = append(Path, "index.html");
-  else
-Path = append(Path, Ref.Name + ".html")
 
-ANode = document.createElement("a");
+  ANode = document.createElement("a");
   ANode.setAttribute("href", Path);
   var TextNode = document.createTextNode(Ref.Name);
   ANode.appendChild(TextNode);
   return ANode;
 }
 
+function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) {
+  // Out will store the HTML elements that Index requires to be generated
+  var Out = [];
+  if (Index.Name) {
+var SpanNode = document.createElement("span");
+var TextNode = document.createTextNode(Index.Name);
+SpanNode.appendChild(genLink(Index));
+Out.push(SpanNode);
+  }
+  if (Index.Children.length == 0)
+return Out;
+  // Only the outermost list should use ol, the others should use ul
+  var ListNodeName = IsOutermostList ? "ol" : "ul";
+  var ListNode = document.createElement(ListNodeName);
+  for (Child of Index.Children) {
+var LiNode = document.createElement("li");
+ChildNodes = genHTMLOfIndex(Child, CurrentDirectory, false);
+for (Node of ChildNodes)
+  LiNode.appendChild(Node);
+ListNode.appendChild(LiNode);
+  }
+  Out.push(ListNode);
+  return Out;
+}
+
 function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) {
   // Out will store the HTML elements that Index requires to be generated
   var Out = [];

>From a22609f75064194604e476a12bc8154676dacfb9 Mon Sep 17 00:00:00 2001
From: PeterChou1 
Date: Fri, 24 May 2024 05:10:03 -0400
Subject: [PATCH 2/2] remove duplicate function

---
 clang-tools-extra/clang-doc/assets/index.js | 24 -
 1 file changed, 24 deletions(-)

diff --git a/clang-tools-extra/clang-doc/assets/index.js 
b/clang-tools-extra/clang-doc/assets/index.js
index fe35e706cc98d..b013418c82093 100644
--- a/clang-tools-extra/clang-doc/assets/index.js
+++ b/clang-tools-extra/clang-doc/assets/index.js
@@ -16,30 +16,6 @@ function genLink(Ref) {
   return ANode;
 }
 
-function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) {
-  // Out will store the HTML elements that Index requires to be generated
-  var Out = [];
-  if (Index.Name) {
-var SpanNode = document.createElement("span");
-var TextNode = document.createTextNode(Index.Name);
-SpanNode.appendChild(genLink(Index));
-Out.push(SpanNode);
-  }
-  if (Index.Children.length == 0)
-return Out;
-  // Only the outermost list should use ol, the others should use ul
-  var ListNodeName = IsOutermostList ? "ol" : "ul";
-  var ListNode = document.createElement(ListNodeName);
-  for (Child of Index.Children) {
-var LiNode = document.createElement("li");
-ChildNodes = genHTMLOfIndex(Child, CurrentDirectory, false);
-for (Node of ChildNodes)
-  LiNode.appendChild(Node);
-ListNode.appendChild(LiNode);
-  }
-  Out.push(ListNode);
-  return Out;
-}
 
 function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) {
   // Out will store the HTML elements that Index requires to be generated

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http

[clang-tools-extra] Clang doc async (PR #93276)

2024-05-24 Thread via cfe-commits

https://github.com/PeterChou1 updated 
https://github.com/llvm/llvm-project/pull/93276

>From 0b6d536133f63e078fbde491a8c92c7ec916cb47 Mon Sep 17 00:00:00 2001
From: PeterChou1 
Date: Fri, 24 May 2024 05:18:05 -0400
Subject: [PATCH] [clang-doc] make loading of json side bar async

---
 clang-tools-extra/clang-doc/HTMLGenerator.cpp | 28 +--
 clang-tools-extra/clang-doc/Representation.h  |  1 +
 clang-tools-extra/clang-doc/assets/index.js   |  5 ++--
 .../clang-doc/tool/ClangDocMain.cpp   |  6 +++-
 4 files changed, 23 insertions(+), 17 deletions(-)

diff --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp 
b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
index c0faf5f7e8fd9..fb1a7f94c9094 100644
--- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -964,7 +964,7 @@ static llvm::Error SerializeIndex(ClangDocContext &CDCtx) {
   std::error_code FileErr;
   llvm::SmallString<128> FilePath;
   llvm::sys::path::native(CDCtx.OutDirectory, FilePath);
-  llvm::sys::path::append(FilePath, "index_json.js");
+  llvm::sys::path::append(FilePath, "index.json");
   llvm::raw_fd_ostream OS(FilePath, FileErr, llvm::sys::fs::OF_None);
   if (FileErr != OK) {
 return llvm::createStringError(llvm::inconvertibleErrorCode(),
@@ -985,9 +985,7 @@ static llvm::Error SerializeIndex(ClangDocContext &CDCtx) {
   });
 });
   };
-  OS << "var JsonIndex = `\n";
   IndexToJSON(CDCtx.Idx);
-  OS << "`;\n";
   return llvm::Error::success();
 }
 
@@ -1049,31 +1047,33 @@ static llvm::Error CopyFile(StringRef FilePath, 
StringRef OutDirectory) {
   std::error_code FileErr = llvm::sys::fs::copy_file(PathRead, PathWrite);
   if (FileErr != OK) {
 return llvm::createStringError(llvm::inconvertibleErrorCode(),
-   "error creating file " +
-   llvm::sys::path::filename(FilePath) +
-   ": " + FileErr.message() + "\n");
+   "error creating file " + FilePath + ": " +
+   FileErr.message() + "\n");
   }
   return llvm::Error::success();
 }
 
 llvm::Error HTMLGenerator::createResources(ClangDocContext &CDCtx) {
-  auto Err = SerializeIndex(CDCtx);
-  if (Err)
+  if (auto Err = SerializeIndex(CDCtx)) {
 return Err;
-  Err = GenIndex(CDCtx);
-  if (Err)
+  }
+
+  if (auto Err = GenIndex(CDCtx)) {
 return Err;
+  }
 
   for (const auto &FilePath : CDCtx.UserStylesheets) {
-Err = CopyFile(FilePath, CDCtx.OutDirectory);
-if (Err)
+if (auto Err = CopyFile(FilePath, CDCtx.OutDirectory)) {
   return Err;
+}
   }
+
   for (const auto &FilePath : CDCtx.FilesToCopy) {
-Err = CopyFile(FilePath, CDCtx.OutDirectory);
-if (Err)
+if (auto Err = CopyFile(FilePath, CDCtx.OutDirectory)) {
   return Err;
+}
   }
+
   return llvm::Error::success();
 }
 
diff --git a/clang-tools-extra/clang-doc/Representation.h 
b/clang-tools-extra/clang-doc/Representation.h
index a6b144eb7fa2a..23323f1cbdf46 100644
--- a/clang-tools-extra/clang-doc/Representation.h
+++ b/clang-tools-extra/clang-doc/Representation.h
@@ -491,6 +491,7 @@ struct ClangDocContext {
   std::string SourceRoot;   // Directory where processed files are stored. 
Links
 // to definition locations will only be generated 
if
 // the file is in this dir.
+
   // URL of repository that hosts code used for links to definition locations.
   std::optional RepositoryUrl;
   // Path of CSS stylesheets that will be copied to OutDirectory and used to
diff --git a/clang-tools-extra/clang-doc/assets/index.js 
b/clang-tools-extra/clang-doc/assets/index.js
index a5ac90f2e06e7..379867268527e 100644
--- a/clang-tools-extra/clang-doc/assets/index.js
+++ b/clang-tools-extra/clang-doc/assets/index.js
@@ -82,6 +82,7 @@ function createIndex(Index) {
 document.addEventListener("DOMContentLoaded", function() {
   // JsonIndex is a variable from another file that contains the index
   // in JSON format
-  var Index = JSON.parse(JsonIndex);
-  createIndex(Index);
+  fetch("/index.json")
+  .then((response) => response.json())
+  .then((Index) => { createIndex(Index); });
 });
diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp 
b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
index 21b581fa6df2e..53108a77dab21 100644
--- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -155,6 +155,10 @@ Example usage for a project using a compile commands 
database:
 return 1;
   }
 
+  // add option to customize url fragment
+  // such as
+  // 
https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/clang-doc/ClangDocMain.cpp#L1
+
   // Fail early if an invalid format was provided.
   std::string Format = getFormatString();
   llvm::outs() << "Emiting docs in " << Format << " format.\n";
@@ -179,7 +

[clang] [clang] MangledSymbol: Added move to Names param in init list (PR #87287)

2024-05-24 Thread Braden Helmer via cfe-commits

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


[clang] [Clang][Sema] Tweak tryCaptureVariable for unevaluated lambdas (PR #93206)

2024-05-24 Thread Younan Zhang via cfe-commits

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


[clang] [Clang][Sema] Tweak tryCaptureVariable for unevaluated lambdas (PR #93206)

2024-05-24 Thread Younan Zhang via cfe-commits

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


[clang] [Clang][Sema] Tweak tryCaptureVariable for unevaluated lambdas (PR #93206)

2024-05-24 Thread Younan Zhang via cfe-commits

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

>From 658e9d46adf6dd79aa6aef03a1817444a880348a Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Thu, 23 May 2024 22:35:11 +0800
Subject: [PATCH] [Clang][Sema] Tweak tryCaptureVariable for unevaluated
 lambdas

This patch picks up #78598 with the hope that we can address such
crashes in tryCaptureVariable for unevaluated lambdas.

In addition to tryCaptureVariable, this also contains several other
fixes on e.g. lambda parsing/dependencies.
---
 clang/docs/ReleaseNotes.rst   |   3 +
 clang/include/clang/AST/DeclBase.h|   4 +
 clang/lib/Parse/ParseExprCXX.cpp  |   5 +-
 clang/lib/Sema/SemaExpr.cpp   |  10 ++
 clang/lib/Sema/SemaLambda.cpp |  20 +++
 clang/lib/Sema/TreeTransform.h|   2 +-
 clang/test/SemaCXX/lambda-unevaluated.cpp | 164 ++
 7 files changed, 206 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 49ab222bec405..e06a5cd9536aa 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -710,6 +710,9 @@ Bug Fixes to C++ Support
 - Correctly treat the compound statement of an ``if consteval`` as an 
immediate context. Fixes (#GH91509).
 - When partial ordering alias templates against template template parameters,
   allow pack expansions when the alias has a fixed-size parameter list. Fixes 
(#GH62529).
+- Fixes several bugs in capturing variables within unevaluated contexts. Fixes 
(#GH63845), (#GH67260), (#GH69307), (#GH88081),
+  (#GH89496), (#GH90669) and (#GH91633).
+
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index e43e812cd9455..3a311d4c55916 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -2148,6 +2148,10 @@ class DeclContext {
getDeclKind() <= Decl::lastRecord;
   }
 
+  bool isRequiresExprBody() const {
+return getDeclKind() == Decl::RequiresExprBody;
+  }
+
   bool isNamespace() const { return getDeclKind() == Decl::Namespace; }
 
   bool isStdNamespace() const;
diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index 825031da358ad..73f619a085b04 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -1576,7 +1576,10 @@ ExprResult Parser::ParseLambdaExpressionAfterIntroducer(
   TrailingReturnTypeLoc, &DS),
   std::move(Attributes), DeclEndLoc);
 
-Actions.ActOnLambdaClosureQualifiers(Intro, MutableLoc);
+// We have called ActOnLambdaClosureQualifiers for parentheses-less cases
+// above.
+if (HasParentheses)
+  Actions.ActOnLambdaClosureQualifiers(Intro, MutableLoc);
 
 if (HasParentheses && Tok.is(tok::kw_requires))
   ParseTrailingRequiresClause(D);
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index e6c3fa51d54da..7a4ede9898034 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -18831,6 +18831,10 @@ bool Sema::tryCaptureVariable(
   DeclContext *VarDC = Var->getDeclContext();
   DeclContext *DC = CurContext;
 
+  // Skip past RequiresExprBodys because they don't constitute function scopes.
+  while (DC->isRequiresExprBody())
+DC = DC->getParent();
+
   // tryCaptureVariable is called every time a DeclRef is formed,
   // it can therefore have non-negigible impact on performances.
   // For local variables and when there is no capturing scope,
@@ -18838,6 +18842,12 @@ bool Sema::tryCaptureVariable(
   if (CapturingFunctionScopes == 0 && (!BuildAndDiagnose || VarDC == DC))
 return true;
 
+  // Exception: Function parameters are not tied to the function's DeclContext
+  // until we enter the function definition. Capturing them anyway would result
+  // in an out-of-bounds error while traversing DC and its parents.
+  if (isa(Var) && !VarDC->isFunctionOrMethod())
+return true;
+
   const auto *VD = dyn_cast(Var);
   if (VD) {
 if (VD->isInitCapture())
diff --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index 1743afaf15287..999316e544b91 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -1036,6 +1036,7 @@ void 
Sema::ActOnLambdaExpressionAfterIntroducer(LambdaIntroducer &Intro,
   // be dependent, because there are template parameters in scope.
   CXXRecordDecl::LambdaDependencyKind LambdaDependencyKind =
   CXXRecordDecl::LDK_Unknown;
+
   if (LSI->NumExplicitTemplateParams > 0) {
 Scope *TemplateParamScope = CurScope->getTemplateParamParent();
 assert(TemplateParamScope &&
@@ -1046,6 +1047,25 @@ void 
Sema::ActOnLambdaExpressionAfterIntroducer(LambdaIntroducer &Intro,
   LambdaDependencyKind = CXXRecordDecl::LDK_AlwaysDependent;
   } else if (CurScope->getTemplateParamParent() != nullptr) {
 LambdaDependencyKind = CXXRecord

[clang] [Clang] Only check exprs that might be immediate escalating in evaluated contexts (PR #93187)

2024-05-24 Thread Mariya Podchishchaeva via cfe-commits


@@ -5146,6 +5153,12 @@ class Sema final : public SemaBase {
 return ExprEvalContexts.back();
   };
 
+  const ExpressionEvaluationContextRecord &parentEvaluationContext() const {
+assert(ExprEvalContexts.size() >= 2 &&
+   "Must be in an expression evaluation context");
+return ExprEvalContexts[ExprEvalContexts.size() - 2];

Fznamznon wrote:

Submitted https://github.com/llvm/llvm-project/issues/93284

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


[clang] [llvm] [PowerPC] Support -fpatchable-function-entry (PR #92997)

2024-05-24 Thread Chen Zheng via cfe-commits

https://github.com/chenzheng1030 updated 
https://github.com/llvm/llvm-project/pull/92997

>From 751d80c61f0e42daa3796a8270e186153dd9413f Mon Sep 17 00:00:00 2001
From: Chen Zheng 
Date: Wed, 22 May 2024 02:37:04 -0400
Subject: [PATCH 1/3] [PowerPC] Support -fpatchable-function-entry

For now only PPC big endian Linux is supported.
PPC little endian Linux has XRAY support for 64-bit.
PPC AIX has different patchable function entry implementations.

Fixes #63220
Fixes #57031
---
 clang/include/clang/Basic/Attr.td |  2 +-
 clang/include/clang/Basic/AttrDocs.td |  3 +-
 .../clang/Basic/DiagnosticSemaKinds.td|  2 +-
 clang/lib/Driver/ToolChains/Clang.cpp |  4 +-
 clang/lib/Sema/SemaDeclAttr.cpp   |  4 ++
 clang/test/Driver/fpatchable-function-entry.c |  9 +++-
 .../patchable-function-entry-attr-aix.cpp |  4 ++
 .../Sema/patchable-function-entry-attr.cpp|  2 +
 llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp | 24 -
 .../PowerPC/patchable-function-entry.ll   | 49 +++
 10 files changed, 96 insertions(+), 7 deletions(-)
 create mode 100644 clang/test/Sema/patchable-function-entry-attr-aix.cpp
 create mode 100644 llvm/test/CodeGen/PowerPC/patchable-function-entry.ll

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index a2c8cc42195fd..c05bfa96efe35 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -892,7 +892,7 @@ def PatchableFunctionEntry
 : InheritableAttr,
   TargetSpecificAttr> {
+   "riscv64", "x86", "x86_64", "ppc", "ppc64"]>> {
   let Spellings = [GCC<"patchable_function_entry">];
   let Subjects = SubjectList<[Function, ObjCMethod]>;
   let Args = [UnsignedArgument<"Count">, DefaultIntArgument<"Offset", 0>];
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index a313e811c9d21..b7858a5ce0247 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -5796,7 +5796,8 @@ takes precedence over the command line option 
``-fpatchable-function-entry=N,M``
 ``M`` defaults to 0 if omitted.
 
 This attribute is only supported on
-aarch64/aarch64-be/loongarch32/loongarch64/riscv32/riscv64/i386/x86-64 targets.
+aarch64/aarch64-be/loongarch32/loongarch64/riscv32/riscv64/i386/x86-64/ppc/ppc64
 targets.
+For ppc/ppc64 targets, AIX is still not supported.
 }];
 }
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index cc402182687f3..7e0286890b999 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3470,7 +3470,7 @@ def err_attr_tlsmodel_arg : Error<"tls_model must be 
\"global-dynamic\", "
 
 def err_attr_codemodel_arg : Error<"code model '%0' is not supported on this 
target">;
 
-def err_aix_attr_unsupported_tls_model : Error<"TLS model '%0' is not yet 
supported on AIX">;
+def err_aix_attr_unsupported : Error<"%0 attribute is not yet supported on 
AIX">;
 
 def err_tls_var_aligned_over_maximum : Error<
   "alignment (%0) of thread-local variable %1 is greater than the maximum 
supported "
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 588f0c511cd2e..5bb05d5c3091d 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -6681,7 +6681,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 StringRef S0 = A->getValue(), S = S0;
 unsigned Size, Offset = 0;
 if (!Triple.isAArch64() && !Triple.isLoongArch() && !Triple.isRISCV() &&
-!Triple.isX86())
+!Triple.isX86() &&
+!(!Triple.isOSAIX() && (Triple.getArch() == llvm::Triple::ppc ||
+Triple.getArch() == llvm::Triple::ppc64)))
   D.Diag(diag::err_drv_unsupported_opt_for_target)
   << A->getAsString(Args) << TripleStr;
 else if (S.consumeInteger(10, Size) ||
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index ca5938083917f..17c17032ef96b 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -5922,6 +5922,10 @@ static void handleXRayLogArgsAttr(Sema &S, Decl *D, 
const ParsedAttr &AL) {
 
 static void handlePatchableFunctionEntryAttr(Sema &S, Decl *D,
  const ParsedAttr &AL) {
+  if (S.Context.getTargetInfo().getTriple().isOSAIX()) {
+S.Diag(AL.getLoc(), diag::err_aix_attr_unsupported) << AL;
+return;
+  }
   uint32_t Count = 0, Offset = 0;
   if (!checkUInt32Argument(S, AL, AL.getArgAsExpr(0), Count, 0, true))
 return;
diff --git a/clang/test/Driver/fpatchable-function-entry.c 
b/clang/test/Driver/fpatchable-function-entry.c
index 4d0d609584c8d..8df3311f33b0e 100644
--- a/clang/test/Driver/fpatchable-function-entry.c
+++ b/clang/test/Driver/fpatchable-function-entry.c
@@ -6,6 +6,8 @@
 // RU

[clang] [clang] Avoid crash due to unimplemented StructuralValue support in the template differ (PR #93265)

2024-05-24 Thread Andrey Ali Khan Bolshakov via cfe-commits




bolshakov-a wrote:

I don't see any C++26-specific stuff here, only C++20.

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


[clang] [clang] Avoid crash due to unimplemented StructuralValue support in the template differ (PR #93265)

2024-05-24 Thread Andrey Ali Khan Bolshakov via cfe-commits

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


[clang] [clang] Avoid crash due to unimplemented StructuralValue support in the template differ (PR #93265)

2024-05-24 Thread Andrey Ali Khan Bolshakov via cfe-commits

https://github.com/bolshakov-a approved this pull request.

One question about the version of the C++ standard under testing, otherwise 
LGTM, thanks!

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


[clang] [clang] Avoid crash due to unimplemented StructuralValue support in the template differ (PR #93265)

2024-05-24 Thread Andrey Ali Khan Bolshakov via cfe-commits


@@ -1265,13 +1238,62 @@ class TemplateDiff {
 IsNullPtr = true;
 return;
   case TemplateArgument::Expression:
-// TODO: Sometimes, the desugared template argument Expr differs from
-// the sugared template argument Expr.  It may be useful in the future
-// but for now, it is just discarded.
-if (!E)
-  E = TA.getAsExpr();
-return;
+E = Iter->getAsExpr();
+break;
+  case TemplateArgument::Null:
+  case TemplateArgument::Type:
+  case TemplateArgument::Template:
+  case TemplateArgument::TemplateExpansion:
+llvm_unreachable("TemplateArgument kind is not expected for NTTP");
+  case TemplateArgument::Pack:
+llvm_unreachable("TemplateArgument kind handled elsewhere");

bolshakov-a wrote:

Nit: "... _should be_ handled ..."?

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


[clang] [llvm] [PowerPC] Support -fpatchable-function-entry (PR #92997)

2024-05-24 Thread Chen Zheng via cfe-commits

https://github.com/chenzheng1030 commented:

> So PPC64 can use ELFv2 for Triple::OpenBSD. We probably want to diagnose this 
> OS for PPC64, since with ELFv2 we might emit separate local and global entry 
> points which means only certain values can be passed to 
> -fpatchable-function-entry option.

For targets with ABI elfv2 which means there are dual entries, this patch can 
generate expected patchable entry:
For -mtriple=powerpc64-unknown-freebsd-unknown
```
.Ltmp0:
nop
nop
f3: # @f3
.Lfunc_begin0:
.cfi_startproc
.Lfunc_gep0:
addis 2, 12, .TOC.-.Lfunc_gep0@ha
addi 2, 2, .TOC.-.Lfunc_gep0@l
.Lfunc_lep0:
.localentry f3, .Lfunc_lep0-.Lfunc_gep0
# %bb.0:# %entry
nop
```

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


[clang] [llvm] [PowerPC] Support -fpatchable-function-entry (PR #92997)

2024-05-24 Thread Chen Zheng via cfe-commits


@@ -0,0 +1,49 @@
+; RUN: llc -mtriple=powerpc-unknown-linux-gnu %s -o - | FileCheck %s 
--check-prefixes=CHECK,PPC32

chenzheng1030 wrote:

Thank you, changed the triple. Little endian is not going to be supported in 
this patch.

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


[clang] [llvm] [PowerPC] Support -fpatchable-function-entry (PR #92997)

2024-05-24 Thread Chen Zheng via cfe-commits


@@ -6681,7 +6681,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 StringRef S0 = A->getValue(), S = S0;
 unsigned Size, Offset = 0;
 if (!Triple.isAArch64() && !Triple.isLoongArch() && !Triple.isRISCV() &&
-!Triple.isX86())
+!Triple.isX86() &&
+!(!Triple.isOSAIX() && (Triple.getArch() == llvm::Triple::ppc ||

chenzheng1030 wrote:

Linux little endian targets are this patch's scope. This patch tries to support 
-fpatchable-function-entry for big endian targets but not AIX.

If we are going to support little endian, we first need to check the 
possibility about removal of XRAY. (XRAY also uses backend node 
`PATCHABLE_FUNCTION_ENTER`)

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


[clang] [llvm] [PowerPC] Support -fpatchable-function-entry (PR #92997)

2024-05-24 Thread Chen Zheng via cfe-commits

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


[clang] [llvm] [PowerPC] Support -fpatchable-function-entry (PR #92997)

2024-05-24 Thread Chen Zheng via cfe-commits


@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -fsyntax-only -verify %s
+
+// expected-error@+1 {{'patchable_function_entry' attribute is not yet 
supported on AIX}}
+__attribute__((patchable_function_entry(0))) void f();

chenzheng1030 wrote:

Updated, moved the file to the existing one.

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


[clang] [llvm] [PowerPC] Support -fpatchable-function-entry (PR #92997)

2024-05-24 Thread Chen Zheng via cfe-commits


@@ -6,15 +6,20 @@
 // RUN: %clang -target loongarch64 %s -fpatchable-function-entry=1,0 -c -### 
2>&1 | FileCheck %s
 // RUN: %clang -target riscv32 %s -fpatchable-function-entry=1,0 -c -### 2>&1 
| FileCheck %s
 // RUN: %clang -target riscv64 %s -fpatchable-function-entry=1,0 -c -### 2>&1 
| FileCheck %s
+// RUN: %clang -target powerpc-unknown-linux-gnu %s 
-fpatchable-function-entry=1,0 -c -### 2>&1 | FileCheck %s

chenzheng1030 wrote:

Thank you. Updated.

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


[clang] [llvm] [PowerPC] Support -fpatchable-function-entry (PR #92997)

2024-05-24 Thread Chen Zheng via cfe-commits


@@ -0,0 +1,49 @@
+; RUN: llc -mtriple=powerpc-unknown-linux-gnu %s -o - | FileCheck %s 
--check-prefixes=CHECK,PPC32
+; RUN: llc -mtriple=powerpc64-unknown-linux-gnu %s -o - | FileCheck %s 
--check-prefixes=CHECK,PPC64
+
+define void @f0() {
+; CHECK-LABEL: f0:
+; CHECK-NOT:   nop
+; CHECK:   # %bb.0:
+; CHECK-NEXT:blr
+; CHECK-NOT:   .section__patchable_function_entries
+  ret void
+}
+
+define void @f1() "patchable-function-entry"="0" {
+; CHECK-LABEL: f1:
+; CHECK-NOT:   nop
+; CHECK:   # %bb.0:
+; CHECK-NEXT:blr
+; CHECK-NOT:   .section__patchable_function_entries
+  ret void
+}
+
+define void @f2() "patchable-function-entry"="1" {
+; CHECK-LABEL: f2:
+; CHECK-LABEL-NEXT:  .Lfunc_begin2:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:nop
+; CHECK-NEXT:blr
+; CHECK:   .section__patchable_function_entries
+; PPC32:   .p2align2, 0x0
+; PPC64:   .p2align3, 0x0
+; PPC32-NEXT:  .long   .Lfunc_begin2
+; PPC64-NEXT:  .quad   .Lfunc_begin2
+  ret void
+}
+
+define void @f3() "patchable-function-entry"="1" 
"patchable-function-prefix"="2" {
+; CHECK-LABEL: .Ltmp0:
+; CHECK-COUNT-2: nop
+; CHECK-LABEL: f3:

chenzheng1030 wrote:

Updated.

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


[clang] [llvm] [PowerPC] Support -fpatchable-function-entry (PR #92997)

2024-05-24 Thread Chen Zheng via cfe-commits

https://github.com/chenzheng1030 updated 
https://github.com/llvm/llvm-project/pull/92997

>From 7c1e44455a343cef3c5ab0da22c9971888cf Mon Sep 17 00:00:00 2001
From: Chen Zheng 
Date: Wed, 22 May 2024 02:37:04 -0400
Subject: [PATCH 1/3] [PowerPC] Support -fpatchable-function-entry

For now only PPC big endian Linux is supported.
PPC little endian Linux has XRAY support for 64-bit.
PPC AIX has different patchable function entry implementations.

Fixes #63220
Fixes #57031
---
 clang/include/clang/Basic/Attr.td |  2 +-
 clang/include/clang/Basic/AttrDocs.td |  3 +-
 .../clang/Basic/DiagnosticSemaKinds.td|  2 +-
 clang/lib/Driver/ToolChains/Clang.cpp |  4 +-
 clang/lib/Sema/SemaDeclAttr.cpp   |  4 ++
 clang/test/Driver/fpatchable-function-entry.c |  9 +++-
 .../patchable-function-entry-attr-aix.cpp |  4 ++
 .../Sema/patchable-function-entry-attr.cpp|  2 +
 llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp | 24 -
 .../PowerPC/patchable-function-entry.ll   | 49 +++
 10 files changed, 96 insertions(+), 7 deletions(-)
 create mode 100644 clang/test/Sema/patchable-function-entry-attr-aix.cpp
 create mode 100644 llvm/test/CodeGen/PowerPC/patchable-function-entry.ll

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index e59cdd369..c85a6690d6ad9 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -892,7 +892,7 @@ def PatchableFunctionEntry
 : InheritableAttr,
   TargetSpecificAttr> {
+   "riscv64", "x86", "x86_64", "ppc", "ppc64"]>> {
   let Spellings = [GCC<"patchable_function_entry">];
   let Subjects = SubjectList<[Function, ObjCMethod]>;
   let Args = [UnsignedArgument<"Count">, DefaultIntArgument<"Offset", 0>];
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index a313e811c9d21..b7858a5ce0247 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -5796,7 +5796,8 @@ takes precedence over the command line option 
``-fpatchable-function-entry=N,M``
 ``M`` defaults to 0 if omitted.
 
 This attribute is only supported on
-aarch64/aarch64-be/loongarch32/loongarch64/riscv32/riscv64/i386/x86-64 targets.
+aarch64/aarch64-be/loongarch32/loongarch64/riscv32/riscv64/i386/x86-64/ppc/ppc64
 targets.
+For ppc/ppc64 targets, AIX is still not supported.
 }];
 }
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 270b0a1e01307..31c3a6007a1a1 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3470,7 +3470,7 @@ def err_attr_tlsmodel_arg : Error<"tls_model must be 
\"global-dynamic\", "
 
 def err_attr_codemodel_arg : Error<"code model '%0' is not supported on this 
target">;
 
-def err_aix_attr_unsupported_tls_model : Error<"TLS model '%0' is not yet 
supported on AIX">;
+def err_aix_attr_unsupported : Error<"%0 attribute is not yet supported on 
AIX">;
 
 def err_tls_var_aligned_over_maximum : Error<
   "alignment (%0) of thread-local variable %1 is greater than the maximum 
supported "
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 18de8781e894a..e1023477653b9 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -6681,7 +6681,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 StringRef S0 = A->getValue(), S = S0;
 unsigned Size, Offset = 0;
 if (!Triple.isAArch64() && !Triple.isLoongArch() && !Triple.isRISCV() &&
-!Triple.isX86())
+!Triple.isX86() &&
+!(!Triple.isOSAIX() && (Triple.getArch() == llvm::Triple::ppc ||
+Triple.getArch() == llvm::Triple::ppc64)))
   D.Diag(diag::err_drv_unsupported_opt_for_target)
   << A->getAsString(Args) << TripleStr;
 else if (S.consumeInteger(10, Size) ||
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 5041fd65286fa..5c7cb08060061 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -5922,6 +5922,10 @@ static void handleXRayLogArgsAttr(Sema &S, Decl *D, 
const ParsedAttr &AL) {
 
 static void handlePatchableFunctionEntryAttr(Sema &S, Decl *D,
  const ParsedAttr &AL) {
+  if (S.Context.getTargetInfo().getTriple().isOSAIX()) {
+S.Diag(AL.getLoc(), diag::err_aix_attr_unsupported) << AL;
+return;
+  }
   uint32_t Count = 0, Offset = 0;
   if (!checkUInt32Argument(S, AL, AL.getArgAsExpr(0), Count, 0, true))
 return;
diff --git a/clang/test/Driver/fpatchable-function-entry.c 
b/clang/test/Driver/fpatchable-function-entry.c
index ab04fd39ffa1c..26ec4669ccb77 100644
--- a/clang/test/Driver/fpatchable-function-entry.c
+++ b/clang/test/Driver/fpatchable-function-entry.c
@@ -6,6 +6,8 @@
 // RU

[clang-tools-extra] Enforce SL.con.3: Add check to replace operator[] with at() (PR #90043)

2024-05-24 Thread Sebastian Wolf via cfe-commits

https://github.com/sebwolf-de updated 
https://github.com/llvm/llvm-project/pull/90043

>From 8eb5863305e8f9a1311a540faf35f24fc6f55c6c Mon Sep 17 00:00:00 2001
From: Sebastian Wolf 
Date: Wed, 17 Apr 2024 16:16:35 +0200
Subject: [PATCH 1/3] Enforce SL.con.3: Add check to replace operator[] with
 at() on std containers

---
 .../AvoidBoundsErrorsCheck.cpp| 81 +++
 .../AvoidBoundsErrorsCheck.h  | 32 
 .../cppcoreguidelines/CMakeLists.txt  |  1 +
 .../CppCoreGuidelinesTidyModule.cpp   |  3 +
 clang-tools-extra/docs/ReleaseNotes.rst   |  5 ++
 .../cppcoreguidelines/avoid-bounds-errors.rst | 20 +
 .../docs/clang-tidy/checks/list.rst   |  1 +
 .../cppcoreguidelines/avoid-bounds-errors.cpp | 66 +++
 8 files changed, 209 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-bounds-errors.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-bounds-errors.cpp

diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.cpp 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.cpp
new file mode 100644
index 0..524c21b5bdb81
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.cpp
@@ -0,0 +1,81 @@
+//===--- AvoidBoundsErrorsCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "AvoidBoundsErrorsCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+#include 
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::cppcoreguidelines {
+
+bool isApplicable(const QualType &Type) {
+  const auto TypeStr = Type.getAsString();
+  bool Result = false;
+  // Only check for containers in the std namespace
+  if (TypeStr.find("std::vector") != std::string::npos) {
+Result = true;
+  }
+  if (TypeStr.find("std::array") != std::string::npos) {
+Result = true;
+  }
+  if (TypeStr.find("std::deque") != std::string::npos) {
+Result = true;
+  }
+  if (TypeStr.find("std::map") != std::string::npos) {
+Result = true;
+  }
+  if (TypeStr.find("std::unordered_map") != std::string::npos) {
+Result = true;
+  }
+  if (TypeStr.find("std::flat_map") != std::string::npos) {
+Result = true;
+  }
+  // TODO Add std::span with C++26
+  return Result;
+}
+
+void AvoidBoundsErrorsCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  callExpr(callee(cxxMethodDecl(hasName("operator[]")).bind("f")))
+  .bind("x"),
+  this);
+}
+
+void AvoidBoundsErrorsCheck::check(const MatchFinder::MatchResult &Result) {
+  const ASTContext &Context = *Result.Context;
+  const SourceManager &Source = Context.getSourceManager();
+  const auto *MatchedExpr = Result.Nodes.getNodeAs("x");
+  const auto *MatchedFunction = Result.Nodes.getNodeAs("f");
+  const auto Type = MatchedFunction->getThisType();
+  if (!isApplicable(Type)) {
+return;
+  }
+
+  // Get original code.
+  const SourceLocation b(MatchedExpr->getBeginLoc());
+  const SourceLocation e(MatchedExpr->getEndLoc());
+  const std::string OriginalCode =
+  Lexer::getSourceText(CharSourceRange::getTokenRange(b, e), Source,
+   getLangOpts())
+  .str();
+  const auto Range = SourceRange(b, e);
+
+  // Build replacement.
+  std::string NewCode = OriginalCode;
+  const auto BeginOpen = NewCode.find("[");
+  NewCode.replace(BeginOpen, 1, ".at(");
+  const auto BeginClose = NewCode.find("]");
+  NewCode.replace(BeginClose, 1, ")");
+
+  diag(MatchedExpr->getBeginLoc(), "Do not use operator[], use at() instead.")
+  << FixItHint::CreateReplacement(Range, NewCode);
+}
+
+} // namespace clang::tidy::cppcoreguidelines
diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.h 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.h
new file mode 100644
index 0..f915729cd7bbe
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.h
@@ -0,0 +1,32 @@
+//===--- AvoidBoundsErrorsCheck.h - clang-tidy --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef

[clang] [serialization] no transitive decl change (PR #92083)

2024-05-24 Thread Jan Svoboda via cfe-commits


@@ -124,6 +130,15 @@ class DeclIDBase {
 
   bool isInvalid() const { return ID == PREDEF_DECL_NULL_ID; }
 
+  unsigned getModuleFileIndex() const { return ID >> 32; }
+
+  unsigned getLocalDeclIndex() const {
+// Implement it directly instead of calling `llvm::maskTrailingOnes` since
+// we don't want `MathExtras.h` to be inclued here.

jansvoboda11 wrote:

Why not? Just to keep the amount of code lower? Can't we move the function body 
to an implementation file?

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


[clang] [serialization] no transitive decl change (PR #92083)

2024-05-24 Thread Jan Svoboda via cfe-commits


@@ -255,6 +255,12 @@ class DeclOffset {
   }
 };
 
+// The unaligned decl ID used in the Blobs of bistreams.
+using unalighed_decl_id_t =

jansvoboda11 wrote:

I know this typo isn't introduced by your PR, but since your PR is touching it, 
please fix it in a prep commit.
```suggestion
using unaligned_decl_id_t =
```

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


[clang] [SPIR-V] Prefer llvm-spirv- tool (PR #77897)

2024-05-24 Thread Henry Linjamäki via cfe-commits

linehill wrote:

Thanks for the review. Could you merge this PR on my behalf (I don't have write 
access)?

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


[clang] [clang-format] Don't always break before << between string literals (PR #92214)

2024-05-24 Thread via cfe-commits


@@ -10539,6 +10539,17 @@ TEST_F(FormatTest, KeepStringLabelValuePairsOnALine) {
   "  bbb);");
 }
 
+TEST_F(FormatTest, WrapBeforeInsertionOperatorbetweenStringLiterals) {
+  verifyFormat("QStringList() << \"foo\" << \"bar\";");

Alexolut wrote:

Will `verifyNoChange` here be better suitable?

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


[clang] [clang] Diagnose problematic diagnostic messages (PR #93229)

2024-05-24 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman updated 
https://github.com/llvm/llvm-project/pull/93229

>From 38d6d9b809e1cf9d6a8f577630c838421486cd04 Mon Sep 17 00:00:00 2001
From: Aaron Ballman 
Date: Thu, 23 May 2024 14:55:16 -0400
Subject: [PATCH 1/3] Diagnose problematic diagnostic messages

Clang has some unwritten rules about diagnostic wording regarding
things like punctuation and capitalization. This patch documents those
rules and adds some tablegen support for checking diagnostics follow
the rules.

Specifically: tablegen now checks that a diagnostic does not start with
a capital letter or end with punctuation, except for the usual
exceptions like proper nouns or ending with a question.
---
 clang/docs/InternalsManual.rst|  38 
 clang/test/TableGen/deferred-diag.td  |  10 +-
 clang/test/TableGen/text-substitution.td  |   4 +-
 clang/test/TableGen/wording-errors.td |  55 +
 .../TableGen/ClangDiagnosticsEmitter.cpp  | 191 ++
 5 files changed, 291 insertions(+), 7 deletions(-)
 create mode 100644 clang/test/TableGen/wording-errors.td

diff --git a/clang/docs/InternalsManual.rst b/clang/docs/InternalsManual.rst
index b3e2b870ae5f9..3d21e37784b36 100644
--- a/clang/docs/InternalsManual.rst
+++ b/clang/docs/InternalsManual.rst
@@ -123,6 +123,44 @@ severe that error recovery won't be able to recover 
sensibly from them (thus
 spewing a ton of bogus errors).  One example of this class of error are failure
 to ``#include`` a file.
 
+Diagnostic Wording
+^^
+The wording used for a diagnostic is critical because it is the only way for a
+user to know how to correct their code. Use the following suggestions when
+wording a diagnostic.
+
+* Diagnostics in Clang do not start with a capital letter and do not end with
+  punctuation.
+
+* This does not apply to proper nouns like ``Clang`` or ``OpenMP``, to
+  acronyms like ``GCC`` or ``ARC``, or to language standards like ``C23``
+  or ``C++17``.
+* A trailing question mark is allowed. e.g., ``unknown identifier %0; did
+  you mean %1?``.
+
+* Appropriately capitalize proper nouns like ``Clang``, ``OpenCL``, ``GCC``,
+  ``Objective-C``, etc and language standard versions like ``C11`` or 
``C++11``.
+* The wording should be succinct. If necessary, use a semicolon to combine
+  sentence fragments instead of using complete sentences. e.g., prefer wording
+  like ``'%0' is deprecated; it will be removed in a future release of Clang``
+  over wording like ``'%0' is deprecated. It will be removed in a future 
release
+  of Clang``.
+* The wording should be actionable and avoid using standards terms or grammar
+  productions that a new user would not be familiar with. e.g., prefer wording
+  like ``missing semicolon`` over wording like ``syntax error`` (which is not
+  actionable) or ``expected unqualified-id`` (which uses standards 
terminology).
+* The wording should clearly explain what is wrong with the code rather than
+  restating what the code does. e.g., prefer wording like ``type %0 requires a
+  value in the range %1 to %2`` over wording like ``%0 is invalid``.
+* The wording should have enough contextual information to help the user
+  identify the issue in a complex expression. e.g., prefer wording like
+  ``both sides of the %0 binary operator are identical`` over wording like
+  ``identical operands to binary operator``.
+* Use single quotes to denote syntactic constructs or command line arguments
+  named in a diagnostic message. e.g., prefer wording like ``'this' pointer
+  cannot be null in well-defined C++ code`` over wording like ``this pointer
+  cannot be null in well-defined C++ code``.
+
 The Format String
 ^
 
diff --git a/clang/test/TableGen/deferred-diag.td 
b/clang/test/TableGen/deferred-diag.td
index c1906d4a9e45e..d7e8e694c7b3e 100644
--- a/clang/test/TableGen/deferred-diag.td
+++ b/clang/test/TableGen/deferred-diag.td
@@ -4,24 +4,24 @@ include "DiagnosticBase.inc"
 
 // Test usage of Deferrable and NonDeferrable in diagnostics.
 
-def test_default : Error<"This error is non-deferrable by default">;
+def test_default : Error<"this error is non-deferrable by default">;
 // CHECK-DAG: DIAG(test_default, {{.*}}SFINAE_SubstitutionFailure, false, 
true, true, false, 0)
 
-def test_deferrable : Error<"This error is deferrable">, Deferrable;
+def test_deferrable : Error<"this error is deferrable">, Deferrable;
 // CHECK-DAG: DIAG(test_deferrable, {{.*}} SFINAE_SubstitutionFailure, false, 
true, true, true, 0)
 
-def test_non_deferrable : Error<"This error is non-deferrable">, NonDeferrable;
+def test_non_deferrable : Error<"this error is non-deferrable">, NonDeferrable;
 // CHECK-DAG: DIAG(test_non_deferrable, {{.*}} SFINAE_SubstitutionFailure, 
false, true, true, false, 0)
 
 let Deferrable = 1 in {
 
-def test_let : Error<"This error is deferrable by let">;
+def test_let : Error<"this error is deferrable by let">;
 // CHECK-DAG: DIAG(test_let,

[clang] [SPIR-V] Prefer llvm-spirv- tool (PR #77897)

2024-05-24 Thread Sven van Haastregt via cfe-commits
Henry =?utf-8?q?Linjamäki?= 
Message-ID:
In-Reply-To: 


svenvh wrote:

> Thanks for the review. Could you merge this PR on my behalf (I don't have 
> write access)?

Yes I am happy to do so, but would you mind rebasing this PR onto latest `main` 
first?  Just so that the checks can run again to avoid any potential new 
regressions since the checks ran last.

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


[clang] [clang] Diagnose problematic diagnostic messages (PR #93229)

2024-05-24 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman updated 
https://github.com/llvm/llvm-project/pull/93229

>From 38d6d9b809e1cf9d6a8f577630c838421486cd04 Mon Sep 17 00:00:00 2001
From: Aaron Ballman 
Date: Thu, 23 May 2024 14:55:16 -0400
Subject: [PATCH 1/3] Diagnose problematic diagnostic messages

Clang has some unwritten rules about diagnostic wording regarding
things like punctuation and capitalization. This patch documents those
rules and adds some tablegen support for checking diagnostics follow
the rules.

Specifically: tablegen now checks that a diagnostic does not start with
a capital letter or end with punctuation, except for the usual
exceptions like proper nouns or ending with a question.
---
 clang/docs/InternalsManual.rst|  38 
 clang/test/TableGen/deferred-diag.td  |  10 +-
 clang/test/TableGen/text-substitution.td  |   4 +-
 clang/test/TableGen/wording-errors.td |  55 +
 .../TableGen/ClangDiagnosticsEmitter.cpp  | 191 ++
 5 files changed, 291 insertions(+), 7 deletions(-)
 create mode 100644 clang/test/TableGen/wording-errors.td

diff --git a/clang/docs/InternalsManual.rst b/clang/docs/InternalsManual.rst
index b3e2b870ae5f9..3d21e37784b36 100644
--- a/clang/docs/InternalsManual.rst
+++ b/clang/docs/InternalsManual.rst
@@ -123,6 +123,44 @@ severe that error recovery won't be able to recover 
sensibly from them (thus
 spewing a ton of bogus errors).  One example of this class of error are failure
 to ``#include`` a file.
 
+Diagnostic Wording
+^^
+The wording used for a diagnostic is critical because it is the only way for a
+user to know how to correct their code. Use the following suggestions when
+wording a diagnostic.
+
+* Diagnostics in Clang do not start with a capital letter and do not end with
+  punctuation.
+
+* This does not apply to proper nouns like ``Clang`` or ``OpenMP``, to
+  acronyms like ``GCC`` or ``ARC``, or to language standards like ``C23``
+  or ``C++17``.
+* A trailing question mark is allowed. e.g., ``unknown identifier %0; did
+  you mean %1?``.
+
+* Appropriately capitalize proper nouns like ``Clang``, ``OpenCL``, ``GCC``,
+  ``Objective-C``, etc and language standard versions like ``C11`` or 
``C++11``.
+* The wording should be succinct. If necessary, use a semicolon to combine
+  sentence fragments instead of using complete sentences. e.g., prefer wording
+  like ``'%0' is deprecated; it will be removed in a future release of Clang``
+  over wording like ``'%0' is deprecated. It will be removed in a future 
release
+  of Clang``.
+* The wording should be actionable and avoid using standards terms or grammar
+  productions that a new user would not be familiar with. e.g., prefer wording
+  like ``missing semicolon`` over wording like ``syntax error`` (which is not
+  actionable) or ``expected unqualified-id`` (which uses standards 
terminology).
+* The wording should clearly explain what is wrong with the code rather than
+  restating what the code does. e.g., prefer wording like ``type %0 requires a
+  value in the range %1 to %2`` over wording like ``%0 is invalid``.
+* The wording should have enough contextual information to help the user
+  identify the issue in a complex expression. e.g., prefer wording like
+  ``both sides of the %0 binary operator are identical`` over wording like
+  ``identical operands to binary operator``.
+* Use single quotes to denote syntactic constructs or command line arguments
+  named in a diagnostic message. e.g., prefer wording like ``'this' pointer
+  cannot be null in well-defined C++ code`` over wording like ``this pointer
+  cannot be null in well-defined C++ code``.
+
 The Format String
 ^
 
diff --git a/clang/test/TableGen/deferred-diag.td 
b/clang/test/TableGen/deferred-diag.td
index c1906d4a9e45e..d7e8e694c7b3e 100644
--- a/clang/test/TableGen/deferred-diag.td
+++ b/clang/test/TableGen/deferred-diag.td
@@ -4,24 +4,24 @@ include "DiagnosticBase.inc"
 
 // Test usage of Deferrable and NonDeferrable in diagnostics.
 
-def test_default : Error<"This error is non-deferrable by default">;
+def test_default : Error<"this error is non-deferrable by default">;
 // CHECK-DAG: DIAG(test_default, {{.*}}SFINAE_SubstitutionFailure, false, 
true, true, false, 0)
 
-def test_deferrable : Error<"This error is deferrable">, Deferrable;
+def test_deferrable : Error<"this error is deferrable">, Deferrable;
 // CHECK-DAG: DIAG(test_deferrable, {{.*}} SFINAE_SubstitutionFailure, false, 
true, true, true, 0)
 
-def test_non_deferrable : Error<"This error is non-deferrable">, NonDeferrable;
+def test_non_deferrable : Error<"this error is non-deferrable">, NonDeferrable;
 // CHECK-DAG: DIAG(test_non_deferrable, {{.*}} SFINAE_SubstitutionFailure, 
false, true, true, false, 0)
 
 let Deferrable = 1 in {
 
-def test_let : Error<"This error is deferrable by let">;
+def test_let : Error<"this error is deferrable by let">;
 // CHECK-DAG: DIAG(test_let,

[clang] [serialization] no transitive decl change (PR #92083)

2024-05-24 Thread Jan Svoboda via cfe-commits


@@ -111,6 +109,28 @@ void *Decl::operator new(std::size_t Size, const 
ASTContext &Ctx,
   return ::operator new(Size + Extra, Ctx);
 }
 
+GlobalDeclID Decl::getGlobalID() const {
+  if (!isFromASTFile())
+return GlobalDeclID();
+  uint64_t ID = *((const uint64_t *)this - 1);

jansvoboda11 wrote:

Can you explain what this is doing?

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


[clang] [SPIR-V] Prefer llvm-spirv- tool (PR #77897)

2024-05-24 Thread Henry Linjamäki via cfe-commits

https://github.com/linehill updated 
https://github.com/llvm/llvm-project/pull/77897

From 13609260c7ef2b57751975a6c7847439958978d6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henry=20Linjam=C3=A4ki?= 
Date: Thu, 21 Dec 2023 08:43:16 +0200
Subject: [PATCH 1/2] [SPIR-V] Prefer llvm-spirv- tool

Prefer using `llvm-spirv-` tool
(i.e. `llvm-spirv-18`) over plain `llvm-spirv`. If the versioned tool
is not found in PATH, fall back to use the plain `llvm-spirv`.

An issue with the using `llvm-spirv` is that the one found in PATH
might be compiled against older LLVM version which could lead to
crashes or obscure bugs. For example, `llvm-spirv` distributed by
Ubuntu links against different LLVM version depending on the Ubuntu
release (LLVM-10 in 20.04LTS, LLVM-13 in 22.04LTS).
---
 clang/lib/Driver/ToolChains/SPIRV.cpp  | 12 ++--
 clang/test/Driver/hipspv-toolchain.hip | 13 +
 clang/test/Driver/spirv-toolchain.cl   | 10 ++
 clang/test/lit.site.cfg.py.in  |  1 +
 4 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/SPIRV.cpp 
b/clang/lib/Driver/ToolChains/SPIRV.cpp
index 27de69550853c..ce900600cbee5 100644
--- a/clang/lib/Driver/ToolChains/SPIRV.cpp
+++ b/clang/lib/Driver/ToolChains/SPIRV.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 #include "SPIRV.h"
 #include "CommonArgs.h"
+#include "clang/Basic/Version.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/InputInfo.h"
@@ -32,8 +33,15 @@ void SPIRV::constructTranslateCommand(Compilation &C, const 
Tool &T,
 
   CmdArgs.append({"-o", Output.getFilename()});
 
-  const char *Exec =
-  C.getArgs().MakeArgString(T.getToolChain().GetProgramPath("llvm-spirv"));
+  // Try to find "llvm-spirv-". Otherwise, fall back to
+  // plain "llvm-spirv".
+  using namespace std::string_literals;
+  auto VersionedTool = "llvm-spirv-"s + std::to_string(LLVM_VERSION_MAJOR);
+  std::string ExeCand = T.getToolChain().GetProgramPath(VersionedTool.c_str());
+  if (!llvm::sys::fs::can_execute(ExeCand))
+ExeCand = T.getToolChain().GetProgramPath("llvm-spirv");
+
+  const char *Exec = C.getArgs().MakeArgString(ExeCand);
   C.addCommand(std::make_unique(JA, T, ResponseFileSupport::None(),
  Exec, CmdArgs, Input, Output));
 }
diff --git a/clang/test/Driver/hipspv-toolchain.hip 
b/clang/test/Driver/hipspv-toolchain.hip
index 4602cd3fc8d68..4005d9889051f 100644
--- a/clang/test/Driver/hipspv-toolchain.hip
+++ b/clang/test/Driver/hipspv-toolchain.hip
@@ -34,3 +34,16 @@
 // CHECK-SAME: "-o" [[OBJ_HOST:".*o"]] "-x" "hip"
 
 // CHECK: {{".*ld.*"}} {{.*}}[[OBJ_HOST]]
+
+//-
+// Check llvm-spirv- is used if it is found in PATH.
+// RUN: mkdir -p %t/versioned
+// RUN: touch %t/versioned/llvm-spirv-%llvm-version-major \
+// RUN:   && chmod +x %t/versioned/llvm-spirv-%llvm-version-major
+// RUN: env "PATH=%t/versioned" %clang -### -target x86_64-linux-gnu \
+// RUN:   --offload=spirv64 --hip-path=%S/Inputs/hipspv -nohipwrapperinc \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -DVERSION=%llvm-version-major \
+// RUN:   --check-prefix=VERSIONED %s
+
+// VERSIONED: {{.*}}llvm-spirv-[[VERSION]]
diff --git a/clang/test/Driver/spirv-toolchain.cl 
b/clang/test/Driver/spirv-toolchain.cl
index db3ee4d3fe02f..de818177cb19f 100644
--- a/clang/test/Driver/spirv-toolchain.cl
+++ b/clang/test/Driver/spirv-toolchain.cl
@@ -77,3 +77,13 @@
 
 // XTOR: {{llvm-spirv.*"}}
 // BACKEND-NOT: {{llvm-spirv.*"}}
+
+//-
+// Check llvm-spirv- is used if it is found in PATH.
+// RUN: mkdir -p %t/versioned
+// RUN: touch %t/versioned/llvm-spirv-%llvm-version-major \
+// RUN:   && chmod +x %t/versioned/llvm-spirv-%llvm-version-major
+// RUN: env "PATH=%t/versioned" %clang -### --target=spirv64 -x cl -c %s 2>&1 \
+// RUN:   | FileCheck -DVERSION=%llvm-version-major --check-prefix=VERSIONED %s
+
+// VERSIONED: {{.*}}llvm-spirv-[[VERSION]]
diff --git a/clang/test/lit.site.cfg.py.in b/clang/test/lit.site.cfg.py.in
index ec6d30e6c2203..1cbd876ac5bb9 100644
--- a/clang/test/lit.site.cfg.py.in
+++ b/clang/test/lit.site.cfg.py.in
@@ -43,6 +43,7 @@ config.llvm_external_lit = path(r"@LLVM_EXTERNAL_LIT@")
 config.standalone_build = @CLANG_BUILT_STANDALONE@
 config.ppc_linux_default_ieeelongdouble = @PPC_LINUX_DEFAULT_IEEELONGDOUBLE@
 config.have_llvm_driver = @LLVM_TOOL_LLVM_DRIVER_BUILD@
+config.substitutions.append(("%llvm-version-major", "@LLVM_VERSION_MAJOR@"))
 
 import lit.llvm
 lit.llvm.initialize(lit_config, config)

From 28c8da48fa98b18de1e7f77c4316bb3bfff933e5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henry=20Linjam=C3=A4ki?= 
Date: Mon, 22 Jan 2024 11:25:46 +0200
Subject: [PATCH 2/2] Document llvm-spirv-

---
 clang/docs/UsersManual.rst | 6 +++---
 1 file changed, 3

[libunwind] Use relative includes to allow source-based dependencies without `-I` (PR #80443)

2024-05-24 Thread Yuriy Chernyshov via cfe-commits

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


[clang] [serialization] no transitive decl change (PR #92083)

2024-05-24 Thread Jan Svoboda via cfe-commits


@@ -7802,20 +7800,31 @@ Decl *ASTReader::GetDecl(GlobalDeclID ID) {
 
 LocalDeclID ASTReader::mapGlobalIDToModuleFileGlobalID(ModuleFile &M,
GlobalDeclID GlobalID) {
-  DeclID ID = GlobalID.get();
-  if (ID < NUM_PREDEF_DECL_IDS)
+  if (GlobalID.get() < NUM_PREDEF_DECL_IDS)
+return LocalDeclID(GlobalID.get());
+
+  if (!M.ModuleOffsetMap.empty())
+ReadModuleOffsetMap(M);
+
+  ModuleFile *Owner = getOwningModuleFile(GlobalID);
+  DeclID ID = GlobalID.getLocalDeclIndex();
+
+  if (Owner == &M) {
+ID += NUM_PREDEF_DECL_IDS;
 return LocalDeclID(ID);
+  }
 
-  GlobalDeclMapType::const_iterator I = GlobalDeclMap.find(GlobalID);
-  assert(I != GlobalDeclMap.end() && "Corrupted global declaration map");
-  ModuleFile *Owner = I->second;
+  uint64_t OrignalModuleFileIndex = 0;
+  for (unsigned I = 0; I < M.DependentModules.size(); I++)

jansvoboda11 wrote:

I just now noticed the name `DependentModules` (introduced in #86912) sounds 
like exactly the opposite of what this member represents. Can we rename this to 
`TransitiveImports` (or something similar) in a prep patch to clarify the 
semantics here?

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


[clang] [serialization] no transitive decl change (PR #92083)

2024-05-24 Thread Jan Svoboda via cfe-commits

https://github.com/jansvoboda11 commented:

This looks good conceptually, I left a couple of minor notes.

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


[clang] [clang] Fix PS "selective" DLL import/export of vtable & typeinfo (PR #92579)

2024-05-24 Thread Andrew Ng via cfe-commits

https://github.com/nga888 updated 
https://github.com/llvm/llvm-project/pull/92579

>From 09fbe6bf163680105c42d4ecbb502ea6519e8b7b Mon Sep 17 00:00:00 2001
From: Andrew Ng 
Date: Mon, 22 Apr 2024 19:29:01 +0100
Subject: [PATCH] [clang] Fix PS "selective" DLL import/export of vtable &
 typeinfo

Prior to this patch, for "selective" DLL import/export, the vtable &
typeinfo would be imported/exported on the condition that all non-inline
virtual methods are imported/exported. This condition was based upon MS
guidelines related to "selective" DLL import/export.

However, in reality, this condition is too rigid and can result in
undefined vtable & typeinfo symbols for code that builds fine with
MSVC. Therefore, relax this condition to be if any non-inline method is
imported/exported.
---
 clang/lib/CodeGen/ItaniumCXXABI.cpp   |  91 
 .../CodeGenCXX/ps-dllstorage-vtable-rtti.cpp  | 114 ++
 .../CodeGenCXX/ps4-dllstorage-vtable-rtti.cpp | 211 --
 3 files changed, 156 insertions(+), 260 deletions(-)
 create mode 100644 clang/test/CodeGenCXX/ps-dllstorage-vtable-rtti.cpp
 delete mode 100644 clang/test/CodeGenCXX/ps4-dllstorage-vtable-rtti.cpp

diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp 
b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index 18acf7784f714..8427286dee887 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -1793,6 +1793,37 @@ void ItaniumCXXABI::EmitDestructorCall(CodeGenFunction 
&CGF,
 ThisTy, VTT, VTTTy, nullptr);
 }
 
+// Check if any non-inline method has the specified attribute.
+template 
+static bool CXXRecordNonInlineHasAttr(const CXXRecordDecl *RD) {
+  for (const auto *D : RD->noload_decls()) {
+if (const auto *FD = dyn_cast(D)) {
+  if (FD->isInlined() || FD->doesThisDeclarationHaveABody() ||
+  FD->isPureVirtual())
+continue;
+  if (D->hasAttr())
+return true;
+}
+  }
+
+  return false;
+}
+
+static void setVTableSelectiveDLLImportExport(CodeGenModule &CGM,
+  llvm::GlobalVariable *VTable,
+  const CXXRecordDecl *RD) {
+  if (VTable->getDLLStorageClass() !=
+  llvm::GlobalVariable::DefaultStorageClass ||
+  RD->hasAttr() || RD->hasAttr())
+return;
+
+  if (CGM.getVTables().isVTableExternal(RD)) {
+if (CXXRecordNonInlineHasAttr(RD))
+  VTable->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass);
+  } else if (CXXRecordNonInlineHasAttr(RD))
+VTable->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass);
+}
+
 void ItaniumCXXABI::emitVTableDefinitions(CodeGenVTables &CGVT,
   const CXXRecordDecl *RD) {
   llvm::GlobalVariable *VTable = getAddrOfVTable(RD, CharUnits());
@@ -1818,6 +1849,9 @@ void ItaniumCXXABI::emitVTableDefinitions(CodeGenVTables 
&CGVT,
   if (CGM.supportsCOMDAT() && VTable->isWeakForLinker())
 VTable->setComdat(CGM.getModule().getOrInsertComdat(VTable->getName()));
 
+  if (CGM.getTarget().hasPS4DLLImportExport())
+setVTableSelectiveDLLImportExport(CGM, VTable, RD);
+
   // Set the right visibility.
   CGM.setGVProperties(VTable, RD);
 
@@ -1905,29 +1939,6 @@ ItaniumCXXABI::getVTableAddressPoint(BaseSubobject Base,
   VTable->getValueType(), VTable, Indices, /*InBounds=*/true, InRange);
 }
 
-// Check whether all the non-inline virtual methods for the class have the
-// specified attribute.
-template 
-static bool CXXRecordAllNonInlineVirtualsHaveAttr(const CXXRecordDecl *RD) {
-  bool FoundNonInlineVirtualMethodWithAttr = false;
-  for (const auto *D : RD->noload_decls()) {
-if (const auto *FD = dyn_cast(D)) {
-  if (!FD->isVirtualAsWritten() || FD->isInlineSpecified() ||
-  FD->doesThisDeclarationHaveABody())
-continue;
-  if (!D->hasAttr())
-return false;
-  FoundNonInlineVirtualMethodWithAttr = true;
-}
-  }
-
-  // We didn't find any non-inline virtual methods missing the attribute.  We
-  // will return true when we found at least one non-inline virtual with the
-  // attribute.  (This lets our caller know that the attribute needs to be
-  // propagated up to the vtable.)
-  return FoundNonInlineVirtualMethodWithAttr;
-}
-
 llvm::Value *ItaniumCXXABI::getVTableAddressPointInStructorWithVTT(
 CodeGenFunction &CGF, const CXXRecordDecl *VTableClass, BaseSubobject Base,
 const CXXRecordDecl *NearestVBase) {
@@ -1981,26 +1992,10 @@ llvm::GlobalVariable 
*ItaniumCXXABI::getAddrOfVTable(const CXXRecordDecl *RD,
   getContext().toCharUnitsFromBits(PAlign).getAsAlign());
   VTable->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
 
-  // In MS C++ if you have a class with virtual functions in which you are 
using
-  // selective member import/export, then all virtual functions must be 
exported
-  // unless they are inline, otherwise a link error will result. To match this
-  // behavior, for

[clang] 0ad4c80 - [clang] Fix PS "selective" DLL import/export of vtable & typeinfo (#92579)

2024-05-24 Thread via cfe-commits

Author: Andrew Ng
Date: 2024-05-24T14:04:22+01:00
New Revision: 0ad4c8075985a0b82c01b28750a49e9e46a8c220

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

LOG: [clang] Fix PS "selective" DLL import/export of vtable & typeinfo (#92579)

Prior to this patch, for "selective" DLL import/export, the vtable &
typeinfo would be imported/exported on the condition that all non-inline
virtual methods are imported/exported. This condition was based upon MS
guidelines related to "selective" DLL import/export.

However, in reality, this condition is too rigid and can result in
undefined vtable & typeinfo symbols for code that builds fine with MSVC.
Therefore, relax this condition to be if any non-inline method is
imported/exported.

Added: 
clang/test/CodeGenCXX/ps-dllstorage-vtable-rtti.cpp

Modified: 
clang/lib/CodeGen/ItaniumCXXABI.cpp

Removed: 
clang/test/CodeGenCXX/ps4-dllstorage-vtable-rtti.cpp



diff  --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp 
b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index 18acf7784f714..8427286dee887 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -1793,6 +1793,37 @@ void ItaniumCXXABI::EmitDestructorCall(CodeGenFunction 
&CGF,
 ThisTy, VTT, VTTTy, nullptr);
 }
 
+// Check if any non-inline method has the specified attribute.
+template 
+static bool CXXRecordNonInlineHasAttr(const CXXRecordDecl *RD) {
+  for (const auto *D : RD->noload_decls()) {
+if (const auto *FD = dyn_cast(D)) {
+  if (FD->isInlined() || FD->doesThisDeclarationHaveABody() ||
+  FD->isPureVirtual())
+continue;
+  if (D->hasAttr())
+return true;
+}
+  }
+
+  return false;
+}
+
+static void setVTableSelectiveDLLImportExport(CodeGenModule &CGM,
+  llvm::GlobalVariable *VTable,
+  const CXXRecordDecl *RD) {
+  if (VTable->getDLLStorageClass() !=
+  llvm::GlobalVariable::DefaultStorageClass ||
+  RD->hasAttr() || RD->hasAttr())
+return;
+
+  if (CGM.getVTables().isVTableExternal(RD)) {
+if (CXXRecordNonInlineHasAttr(RD))
+  VTable->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass);
+  } else if (CXXRecordNonInlineHasAttr(RD))
+VTable->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass);
+}
+
 void ItaniumCXXABI::emitVTableDefinitions(CodeGenVTables &CGVT,
   const CXXRecordDecl *RD) {
   llvm::GlobalVariable *VTable = getAddrOfVTable(RD, CharUnits());
@@ -1818,6 +1849,9 @@ void ItaniumCXXABI::emitVTableDefinitions(CodeGenVTables 
&CGVT,
   if (CGM.supportsCOMDAT() && VTable->isWeakForLinker())
 VTable->setComdat(CGM.getModule().getOrInsertComdat(VTable->getName()));
 
+  if (CGM.getTarget().hasPS4DLLImportExport())
+setVTableSelectiveDLLImportExport(CGM, VTable, RD);
+
   // Set the right visibility.
   CGM.setGVProperties(VTable, RD);
 
@@ -1905,29 +1939,6 @@ ItaniumCXXABI::getVTableAddressPoint(BaseSubobject Base,
   VTable->getValueType(), VTable, Indices, /*InBounds=*/true, InRange);
 }
 
-// Check whether all the non-inline virtual methods for the class have the
-// specified attribute.
-template 
-static bool CXXRecordAllNonInlineVirtualsHaveAttr(const CXXRecordDecl *RD) {
-  bool FoundNonInlineVirtualMethodWithAttr = false;
-  for (const auto *D : RD->noload_decls()) {
-if (const auto *FD = dyn_cast(D)) {
-  if (!FD->isVirtualAsWritten() || FD->isInlineSpecified() ||
-  FD->doesThisDeclarationHaveABody())
-continue;
-  if (!D->hasAttr())
-return false;
-  FoundNonInlineVirtualMethodWithAttr = true;
-}
-  }
-
-  // We didn't find any non-inline virtual methods missing the attribute.  We
-  // will return true when we found at least one non-inline virtual with the
-  // attribute.  (This lets our caller know that the attribute needs to be
-  // propagated up to the vtable.)
-  return FoundNonInlineVirtualMethodWithAttr;
-}
-
 llvm::Value *ItaniumCXXABI::getVTableAddressPointInStructorWithVTT(
 CodeGenFunction &CGF, const CXXRecordDecl *VTableClass, BaseSubobject Base,
 const CXXRecordDecl *NearestVBase) {
@@ -1981,26 +1992,10 @@ llvm::GlobalVariable 
*ItaniumCXXABI::getAddrOfVTable(const CXXRecordDecl *RD,
   getContext().toCharUnitsFromBits(PAlign).getAsAlign());
   VTable->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
 
-  // In MS C++ if you have a class with virtual functions in which you are 
using
-  // selective member import/export, then all virtual functions must be 
exported
-  // unless they are inline, otherwise a link error will result. To match this
-  // behavior, for such classes, we dllimport the vtable if it is defin

[clang] [clang] Fix PS "selective" DLL import/export of vtable & typeinfo (PR #92579)

2024-05-24 Thread Andrew Ng via cfe-commits

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


[clang] f35aac6 - [clang][Interp] Fix zero-initializing unions

2024-05-24 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-05-24T15:15:40+02:00
New Revision: f35aac699167ef1046e2f177d2ba899c6975374e

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

LOG: [clang][Interp] Fix zero-initializing unions

Only with primitive fields for now.

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/test/AST/Interp/unions.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index b885cbe2c4b0e..f73eaeebf9fe8 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1053,9 +1053,6 @@ bool 
ByteCodeExprGen::visitInitList(ArrayRef Inits,
 if (Inits.size() == 1 && E->getType() == Inits[0]->getType())
   return this->visitInitializer(Inits[0]);
 
-if (Inits.size() == 0)
-  return this->emitFinishInit(E);
-
 auto initPrimitiveField = [=](const Record::Field *FieldToInit,
   const Expr *Init, PrimType T) -> bool {
   if (!this->visit(Init))
@@ -1083,24 +1080,38 @@ bool 
ByteCodeExprGen::visitInitList(ArrayRef Inits,
 };
 
 if (R->isUnion()) {
-  assert(Inits.size() == 1);
-  const Expr *Init = Inits[0];
-  const FieldDecl *FToInit = nullptr;
-  if (const auto *ILE = dyn_cast(E))
-FToInit = ILE->getInitializedFieldInUnion();
-  else
-FToInit = cast(E)->getInitializedFieldInUnion();
-
-  if (!this->emitDupPtr(E))
-return false;
-
-  const Record::Field *FieldToInit = R->getField(FToInit);
-  if (std::optional T = classify(Init)) {
-if (!initPrimitiveField(FieldToInit, Init, *T))
-  return false;
+  if (Inits.size() == 0) {
+// Zero-initialize the first union field.
+if (R->getNumFields() == 0)
+  return this->emitFinishInit(E);
+const Record::Field *FieldToInit = R->getField(0u);
+QualType FieldType = FieldToInit->Desc->getType();
+if (std::optional T = classify(FieldType)) {
+  if (!this->visitZeroInitializer(*T, FieldType, E))
+return false;
+  if (!this->emitInitField(*T, FieldToInit->Offset, E))
+return false;
+}
+// FIXME: Non-primitive case?
   } else {
-if (!initCompositeField(FieldToInit, Init))
+const Expr *Init = Inits[0];
+const FieldDecl *FToInit = nullptr;
+if (const auto *ILE = dyn_cast(E))
+  FToInit = ILE->getInitializedFieldInUnion();
+else
+  FToInit = 
cast(E)->getInitializedFieldInUnion();
+
+if (!this->emitDupPtr(E))
   return false;
+
+const Record::Field *FieldToInit = R->getField(FToInit);
+if (std::optional T = classify(Init)) {
+  if (!initPrimitiveField(FieldToInit, Init, *T))
+return false;
+} else {
+  if (!initCompositeField(FieldToInit, Init))
+return false;
+}
   }
   return this->emitFinishInit(E);
 }

diff  --git a/clang/test/AST/Interp/unions.cpp 
b/clang/test/AST/Interp/unions.cpp
index b0b1b19617408..293a1981a52f0 100644
--- a/clang/test/AST/Interp/unions.cpp
+++ b/clang/test/AST/Interp/unions.cpp
@@ -31,6 +31,12 @@ static_assert(ab.d == 1.0, "");
 static_assert(ab.a == 1, ""); // both-error {{not an integral constant 
expression}} \
   // both-note {{read of member 'a' of union with 
active member 'd'}}
 
+
+namespace Empty {
+  union E {};
+  constexpr E e{};
+}
+
 namespace SimpleStore {
   union A {
 int a;
@@ -49,3 +55,13 @@ namespace SimpleStore {
   }
   static_assert(empty() == 10, "");
 }
+
+namespace ZeroInit {
+  struct S { int m; };
+  union Z {
+float f;
+  };
+
+  constexpr Z z{};
+  static_assert(z.f == 0.0, "");
+}



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


[clang] [clang] Avoid crash due to unimplemented StructuralValue support in the template differ (PR #93265)

2024-05-24 Thread Matheus Izvekov via cfe-commits




mizvekov wrote:

We usually create new tests under the latest standard.

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


[clang] [clang] Avoid crash due to unimplemented StructuralValue support in the template differ (PR #93265)

2024-05-24 Thread Matheus Izvekov via cfe-commits

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


[clang] [clang][analyzer] PutenvStackArrayChecker: No warning from 'main' (PR #93299)

2024-05-24 Thread Balázs Kéri via cfe-commits

https://github.com/balazske created 
https://github.com/llvm/llvm-project/pull/93299

None

From 9baa8cc3a1a738a43deee811b51593db85d5c88c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bal=C3=A1zs=20K=C3=A9ri?= 
Date: Fri, 24 May 2024 15:22:22 +0200
Subject: [PATCH] [clang][analyzer] PutenvStackArrayChecker: No warning from
 'main'

---
 clang/docs/analyzer/checkers.rst  | 10 ++
 .../Checkers/PutenvStackArrayChecker.cpp  |  9 +++--
 clang/test/Analysis/putenv-stack-array.c  | 20 +++
 3 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst
index ac9f0b06f63ba..3a31708a1e9de 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -2858,6 +2858,16 @@ The check corresponds to CERT rule
 return putenv(env); // putenv function should not be called with 
stack-allocated string
   }
 
+There is one case where the checker can report a false positive. This is when
+the stack-allocated array is used at `putenv` in a function or code branch that
+does not return (calls `fork` or `exec` like function).
+
+Another special case is if the `putenv` is called from function `main`. Here
+the stack is deallocated at the end of the program and it should be no problem
+to use the stack-allocated string (a multi-threaded program may require more
+attention). The checker does not warn for cases when stack space of `main` is
+used at the `putenv` call.
+
 .. _alpha-security-ReturnPtrRange:
 
 alpha.security.ReturnPtrRange (C)
diff --git a/clang/lib/StaticAnalyzer/Checkers/PutenvStackArrayChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/PutenvStackArrayChecker.cpp
index d59cebf0aa5cb..bf81d57bf82fd 100644
--- a/clang/lib/StaticAnalyzer/Checkers/PutenvStackArrayChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/PutenvStackArrayChecker.cpp
@@ -44,9 +44,14 @@ void PutenvStackArrayChecker::checkPostCall(const CallEvent 
&Call,
 
   SVal ArgV = Call.getArgSVal(0);
   const Expr *ArgExpr = Call.getArgExpr(0);
-  const MemSpaceRegion *MSR = ArgV.getAsRegion()->getMemorySpace();
 
-  if (!isa(MSR))
+  const auto *SSR =
+  dyn_cast(ArgV.getAsRegion()->getMemorySpace());
+  if (!SSR)
+return;
+  const auto *StackFrameFuncD =
+  dyn_cast_or_null(SSR->getStackFrame()->getDecl());
+  if (StackFrameFuncD && StackFrameFuncD->isMain())
 return;
 
   StringRef ErrorMsg = "The 'putenv' function should not be called with "
diff --git a/clang/test/Analysis/putenv-stack-array.c 
b/clang/test/Analysis/putenv-stack-array.c
index fbbf93259ab85..f28aed73031d3 100644
--- a/clang/test/Analysis/putenv-stack-array.c
+++ b/clang/test/Analysis/putenv-stack-array.c
@@ -45,6 +45,15 @@ int test_auto_var_subarray() {
   return putenv(env + 100); // expected-warning{{The 'putenv' function should 
not be called with}}
 }
 
+int f_test_auto_var_call(char *env) {
+  return putenv(env); // expected-warning{{The 'putenv' function should not be 
called with}}
+}
+
+int test_auto_var_call() {
+  char env[1024];
+  return f_test_auto_var_call(env);
+}
+
 int test_constant() {
   char *env = "TEST";
   return putenv(env); // no-warning: data is not on the stack
@@ -68,3 +77,14 @@ void test_auto_var_reset() {
   // become invalid.
   putenv((char *)"NAME=anothervalue");
 }
+
+void f_main(char *env) {
+  putenv(env); // no warning: string allocated in stack of 'main'
+}
+
+int main(int argc, char **argv) {
+  char env[] = "NAME=value";
+  putenv(env); // no warning: string allocated in stack of 'main'
+  f_main(env);
+  return 0;
+}

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


[clang] [clang][analyzer] PutenvStackArrayChecker: No warning from 'main' (PR #93299)

2024-05-24 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-static-analyzer-1

Author: Balázs Kéri (balazske)


Changes



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


3 Files Affected:

- (modified) clang/docs/analyzer/checkers.rst (+10) 
- (modified) clang/lib/StaticAnalyzer/Checkers/PutenvStackArrayChecker.cpp 
(+7-2) 
- (modified) clang/test/Analysis/putenv-stack-array.c (+20) 


``diff
diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst
index ac9f0b06f63ba..3a31708a1e9de 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -2858,6 +2858,16 @@ The check corresponds to CERT rule
 return putenv(env); // putenv function should not be called with 
stack-allocated string
   }
 
+There is one case where the checker can report a false positive. This is when
+the stack-allocated array is used at `putenv` in a function or code branch that
+does not return (calls `fork` or `exec` like function).
+
+Another special case is if the `putenv` is called from function `main`. Here
+the stack is deallocated at the end of the program and it should be no problem
+to use the stack-allocated string (a multi-threaded program may require more
+attention). The checker does not warn for cases when stack space of `main` is
+used at the `putenv` call.
+
 .. _alpha-security-ReturnPtrRange:
 
 alpha.security.ReturnPtrRange (C)
diff --git a/clang/lib/StaticAnalyzer/Checkers/PutenvStackArrayChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/PutenvStackArrayChecker.cpp
index d59cebf0aa5cb..bf81d57bf82fd 100644
--- a/clang/lib/StaticAnalyzer/Checkers/PutenvStackArrayChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/PutenvStackArrayChecker.cpp
@@ -44,9 +44,14 @@ void PutenvStackArrayChecker::checkPostCall(const CallEvent 
&Call,
 
   SVal ArgV = Call.getArgSVal(0);
   const Expr *ArgExpr = Call.getArgExpr(0);
-  const MemSpaceRegion *MSR = ArgV.getAsRegion()->getMemorySpace();
 
-  if (!isa(MSR))
+  const auto *SSR =
+  dyn_cast(ArgV.getAsRegion()->getMemorySpace());
+  if (!SSR)
+return;
+  const auto *StackFrameFuncD =
+  dyn_cast_or_null(SSR->getStackFrame()->getDecl());
+  if (StackFrameFuncD && StackFrameFuncD->isMain())
 return;
 
   StringRef ErrorMsg = "The 'putenv' function should not be called with "
diff --git a/clang/test/Analysis/putenv-stack-array.c 
b/clang/test/Analysis/putenv-stack-array.c
index fbbf93259ab85..f28aed73031d3 100644
--- a/clang/test/Analysis/putenv-stack-array.c
+++ b/clang/test/Analysis/putenv-stack-array.c
@@ -45,6 +45,15 @@ int test_auto_var_subarray() {
   return putenv(env + 100); // expected-warning{{The 'putenv' function should 
not be called with}}
 }
 
+int f_test_auto_var_call(char *env) {
+  return putenv(env); // expected-warning{{The 'putenv' function should not be 
called with}}
+}
+
+int test_auto_var_call() {
+  char env[1024];
+  return f_test_auto_var_call(env);
+}
+
 int test_constant() {
   char *env = "TEST";
   return putenv(env); // no-warning: data is not on the stack
@@ -68,3 +77,14 @@ void test_auto_var_reset() {
   // become invalid.
   putenv((char *)"NAME=anothervalue");
 }
+
+void f_main(char *env) {
+  putenv(env); // no warning: string allocated in stack of 'main'
+}
+
+int main(int argc, char **argv) {
+  char env[] = "NAME=value";
+  putenv(env); // no warning: string allocated in stack of 'main'
+  f_main(env);
+  return 0;
+}

``




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


[clang] [clang][Sema] Fix crash when diagnosing candidates with parameter packs (PR #93079)

2024-05-24 Thread Matheus Izvekov via cfe-commits


@@ -11298,8 +11298,9 @@ static void DiagnoseBadConversion(Sema &S, 
OverloadCandidate *Cand,
   Expr *FromExpr = Conv.Bad.FromExpr;
   QualType FromTy = Conv.Bad.getFromType();
   QualType ToTy = Conv.Bad.getToType();
-  SourceRange ToParamRange =
-  !isObjectArgument ? Fn->getParamDecl(I)->getSourceRange() : 
SourceRange();
+  SourceRange ToParamRange;
+  if (!isObjectArgument && I < Fn->getNumParams())
+ToParamRange = Fn->getParamDecl(I)->getSourceRange();

mizvekov wrote:

Okay. Should'nt be a problem to pipe in the specialization, but as I said, just 
leaving the FIXME is fine.

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


[clang] [clang][Sema] Fix crash when diagnosing candidates with parameter packs (PR #93079)

2024-05-24 Thread Matheus Izvekov via cfe-commits

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


[clang] [clang][Sema] Fix crash when diagnosing candidates with parameter packs (PR #93079)

2024-05-24 Thread Matheus Izvekov via cfe-commits

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

Can you also add a test based on my example?

With also a variant on that in which the bad conversion happens on the last 
element of the pack, instead of the last parameter.

Lastly, please namespace the tests with the name of, or add a comment naming, 
the GitHub issue.

Otherwise, LGTM.



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


[clang] [Clang][Sema] Tweak tryCaptureVariable for unevaluated lambdas (PR #93206)

2024-05-24 Thread Erich Keane via cfe-commits

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


[clang] [Clang][Sema] Tweak tryCaptureVariable for unevaluated lambdas (PR #93206)

2024-05-24 Thread Erich Keane via cfe-commits

https://github.com/erichkeane commented:

I hope @cor3ntin comes and checks this out, but it generally looks OK to me.  1 
oddity I'd like to hear about (why we can't do ActOnLambdaClosureQualifiers in 
the same place).

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


[clang] [Clang][Sema] Tweak tryCaptureVariable for unevaluated lambdas (PR #93206)

2024-05-24 Thread Erich Keane via cfe-commits


@@ -1576,7 +1576,10 @@ ExprResult Parser::ParseLambdaExpressionAfterIntroducer(
   TrailingReturnTypeLoc, &DS),
   std::move(Attributes), DeclEndLoc);
 
-Actions.ActOnLambdaClosureQualifiers(Intro, MutableLoc);
+// We have called ActOnLambdaClosureQualifiers for parentheses-less cases

erichkeane wrote:

Is there any good reason to do this in 2 places, rather than just delay the 
above one to here?  @cor3ntin ?

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


[clang] [clang] Avoid crash due to unimplemented StructuralValue support in the template differ (PR #93265)

2024-05-24 Thread Erich Keane via cfe-commits

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


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


[clang] [llvm] [clang] Introduce target-specific `Sema` components (PR #93179)

2024-05-24 Thread Ulrich Weigand via cfe-commits

https://github.com/uweigand commented:

See comment fix - otherwise SystemZ part LGTM.

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


[clang] [llvm] [clang] Introduce target-specific `Sema` components (PR #93179)

2024-05-24 Thread Ulrich Weigand via cfe-commits

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


[clang] [llvm] [clang] Introduce target-specific `Sema` components (PR #93179)

2024-05-24 Thread Ulrich Weigand via cfe-commits


@@ -0,0 +1,94 @@
+//===-- SemaSystemZ.cpp -- SystemZ target-specific routines 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+//  This file implements semantic analysis functions specific to AIX.

uweigand wrote:

Comment should read SystemZ instead of AIX.

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


[clang] [clang] Fix loss of `dllexport` for exported template specialization (PR #93302)

2024-05-24 Thread Andrew Ng via cfe-commits

https://github.com/nga888 created 
https://github.com/llvm/llvm-project/pull/93302

In commit 0a20f541, "Better codegen support for DLL attributes being dropped 
after the first declaration (PR20792)", code was added to enable "dropping" of 
DLL attributes. The specific issue and example given was related to `dllimport` 
and this was the test case that was added in that commit.

However, the code also included the "dropping" of `dllexport` but no test case 
for this was added. This "dropping" of `dllexport` can cause a `dllexport` 
template specialization to incorrectly lose its `dllexport` attribute as shown 
by the test case in this patch.

As there appears to be no need for the "dropping" of `dllexport`, remove this 
code to fix this issue.

>From 0cfd700e604e5ec68856dfa7daca378e71795fb2 Mon Sep 17 00:00:00 2001
From: Andrew Ng 
Date: Mon, 20 May 2024 18:26:32 +0100
Subject: [PATCH] [clang] Fix loss of `dllexport` for exported template
 specialization

In commit 0a20f541, "Better codegen support for DLL attributes being
dropped after the first declaration (PR20792)", code was added to enable
"dropping" of DLL attributes. The specific issue and example given was
related to `dllimport` and this was the test case that was added in that
commit.

However, the code also included the "dropping" of `dllexport` but no
test case for this was added. This "dropping" of `dllexport` can cause a
`dllexport` template specialization to incorrectly lose its `dllexport`
attribute as shown by the test case in this patch.

As there appears to be no need for the "dropping" of `dllexport`, remove
this code to fix this issue.
---
 clang/lib/CodeGen/CodeGenModule.cpp| 16 +++-
 ...tiate-dllexport-template-specialization.cpp | 18 ++
 2 files changed, 29 insertions(+), 5 deletions(-)
 create mode 100644 
clang/test/CodeGenCXX/windows-instantiate-dllexport-template-specialization.cpp

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index e4774a587707a..ae8104fe1c4cb 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4554,8 +4554,11 @@ llvm::Constant *CodeGenModule::GetOrCreateLLVMFunction(
 Entry->setLinkage(llvm::Function::ExternalLinkage);
 }
 
-// Handle dropped DLL attributes.
-if (D && !D->hasAttr() && !D->hasAttr() &&
+// Handle dropped dllimport.
+if (D &&
+(Entry->getDLLStorageClass() ==
+ llvm::GlobalVariable::DLLImportStorageClass) &&
+!D->hasAttr() &&
 !shouldMapVisibilityToDLLExport(cast_or_null(D))) {
   Entry->setDLLStorageClass(llvm::GlobalValue::DefaultStorageClass);
   setDSOLocal(Entry);
@@ -4849,9 +4852,12 @@ CodeGenModule::GetOrCreateLLVMGlobal(StringRef 
MangledName, llvm::Type *Ty,
 Entry->setLinkage(llvm::Function::ExternalLinkage);
 }
 
-// Handle dropped DLL attributes.
-if (D && !D->hasAttr() && !D->hasAttr() &&
-!shouldMapVisibilityToDLLExport(D))
+// Handle dropped dllimport.
+if (D &&
+(Entry->getDLLStorageClass() ==
+ llvm::GlobalVariable::DLLImportStorageClass) &&
+!D->hasAttr() &&
+!shouldMapVisibilityToDLLExport(cast_or_null(D)))
   Entry->setDLLStorageClass(llvm::GlobalValue::DefaultStorageClass);
 
 if (LangOpts.OpenMP && !LangOpts.OpenMPSimd && D)
diff --git 
a/clang/test/CodeGenCXX/windows-instantiate-dllexport-template-specialization.cpp
 
b/clang/test/CodeGenCXX/windows-instantiate-dllexport-template-specialization.cpp
new file mode 100644
index 0..97f341ba1f909
--- /dev/null
+++ 
b/clang/test/CodeGenCXX/windows-instantiate-dllexport-template-specialization.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -triple i686-windows -fdeclspec -emit-llvm %s -o - 
| FileCheck %s -check-prefix CHECK-MS
+// RUN: %clang_cc1 -triple i686-windows-itanium -fdeclspec -emit-llvm %s -o - 
| FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-scei-ps4  -fdeclspec -emit-llvm %s -o - 
| FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-sie-ps5   -fdeclspec -emit-llvm %s -o - 
| FileCheck %s
+
+struct s {
+  template  static bool f();
+};
+
+template  bool template_using_f(T) { return s::f(); }
+
+bool use_template_using_f() { return template_using_f(0); }
+
+template<>
+bool __declspec(dllexport) s::f() { return true; }
+
+// CHECK-MS: dllexport {{.*}} @"??$f@$00@s@@SA_NXZ"
+// CHECK: dllexport {{.*}} @_ZN1s1fILb1EEEbv

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


[clang] [clang] Fix loss of `dllexport` for exported template specialization (PR #93302)

2024-05-24 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Andrew Ng (nga888)


Changes

In commit 0a20f541, "Better codegen support for DLL attributes being dropped 
after the first declaration (PR20792)", code was added to enable "dropping" of 
DLL attributes. The specific issue and example given was related to `dllimport` 
and this was the test case that was added in that commit.

However, the code also included the "dropping" of `dllexport` but no test case 
for this was added. This "dropping" of `dllexport` can cause a `dllexport` 
template specialization to incorrectly lose its `dllexport` attribute as shown 
by the test case in this patch.

As there appears to be no need for the "dropping" of `dllexport`, remove this 
code to fix this issue.

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


2 Files Affected:

- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+11-5) 
- (added) 
clang/test/CodeGenCXX/windows-instantiate-dllexport-template-specialization.cpp 
(+18) 


``diff
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index e4774a587707a..ae8104fe1c4cb 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4554,8 +4554,11 @@ llvm::Constant *CodeGenModule::GetOrCreateLLVMFunction(
 Entry->setLinkage(llvm::Function::ExternalLinkage);
 }
 
-// Handle dropped DLL attributes.
-if (D && !D->hasAttr() && !D->hasAttr() &&
+// Handle dropped dllimport.
+if (D &&
+(Entry->getDLLStorageClass() ==
+ llvm::GlobalVariable::DLLImportStorageClass) &&
+!D->hasAttr() &&
 !shouldMapVisibilityToDLLExport(cast_or_null(D))) {
   Entry->setDLLStorageClass(llvm::GlobalValue::DefaultStorageClass);
   setDSOLocal(Entry);
@@ -4849,9 +4852,12 @@ CodeGenModule::GetOrCreateLLVMGlobal(StringRef 
MangledName, llvm::Type *Ty,
 Entry->setLinkage(llvm::Function::ExternalLinkage);
 }
 
-// Handle dropped DLL attributes.
-if (D && !D->hasAttr() && !D->hasAttr() &&
-!shouldMapVisibilityToDLLExport(D))
+// Handle dropped dllimport.
+if (D &&
+(Entry->getDLLStorageClass() ==
+ llvm::GlobalVariable::DLLImportStorageClass) &&
+!D->hasAttr() &&
+!shouldMapVisibilityToDLLExport(cast_or_null(D)))
   Entry->setDLLStorageClass(llvm::GlobalValue::DefaultStorageClass);
 
 if (LangOpts.OpenMP && !LangOpts.OpenMPSimd && D)
diff --git 
a/clang/test/CodeGenCXX/windows-instantiate-dllexport-template-specialization.cpp
 
b/clang/test/CodeGenCXX/windows-instantiate-dllexport-template-specialization.cpp
new file mode 100644
index 0..97f341ba1f909
--- /dev/null
+++ 
b/clang/test/CodeGenCXX/windows-instantiate-dllexport-template-specialization.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -triple i686-windows -fdeclspec -emit-llvm %s -o - 
| FileCheck %s -check-prefix CHECK-MS
+// RUN: %clang_cc1 -triple i686-windows-itanium -fdeclspec -emit-llvm %s -o - 
| FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-scei-ps4  -fdeclspec -emit-llvm %s -o - 
| FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-sie-ps5   -fdeclspec -emit-llvm %s -o - 
| FileCheck %s
+
+struct s {
+  template  static bool f();
+};
+
+template  bool template_using_f(T) { return s::f(); }
+
+bool use_template_using_f() { return template_using_f(0); }
+
+template<>
+bool __declspec(dllexport) s::f() { return true; }
+
+// CHECK-MS: dllexport {{.*}} @"??$f@$00@s@@SA_NXZ"
+// CHECK: dllexport {{.*}} @_ZN1s1fILb1EEEbv

``




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


[clang] [clang] Fix loss of `dllexport` for exported template specialization (PR #93302)

2024-05-24 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Andrew Ng (nga888)


Changes

In commit 0a20f541, "Better codegen support for DLL attributes being dropped 
after the first declaration (PR20792)", code was added to enable "dropping" of 
DLL attributes. The specific issue and example given was related to `dllimport` 
and this was the test case that was added in that commit.

However, the code also included the "dropping" of `dllexport` but no test case 
for this was added. This "dropping" of `dllexport` can cause a `dllexport` 
template specialization to incorrectly lose its `dllexport` attribute as shown 
by the test case in this patch.

As there appears to be no need for the "dropping" of `dllexport`, remove this 
code to fix this issue.

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


2 Files Affected:

- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+11-5) 
- (added) 
clang/test/CodeGenCXX/windows-instantiate-dllexport-template-specialization.cpp 
(+18) 


``diff
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index e4774a587707a..ae8104fe1c4cb 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4554,8 +4554,11 @@ llvm::Constant *CodeGenModule::GetOrCreateLLVMFunction(
 Entry->setLinkage(llvm::Function::ExternalLinkage);
 }
 
-// Handle dropped DLL attributes.
-if (D && !D->hasAttr() && !D->hasAttr() &&
+// Handle dropped dllimport.
+if (D &&
+(Entry->getDLLStorageClass() ==
+ llvm::GlobalVariable::DLLImportStorageClass) &&
+!D->hasAttr() &&
 !shouldMapVisibilityToDLLExport(cast_or_null(D))) {
   Entry->setDLLStorageClass(llvm::GlobalValue::DefaultStorageClass);
   setDSOLocal(Entry);
@@ -4849,9 +4852,12 @@ CodeGenModule::GetOrCreateLLVMGlobal(StringRef 
MangledName, llvm::Type *Ty,
 Entry->setLinkage(llvm::Function::ExternalLinkage);
 }
 
-// Handle dropped DLL attributes.
-if (D && !D->hasAttr() && !D->hasAttr() &&
-!shouldMapVisibilityToDLLExport(D))
+// Handle dropped dllimport.
+if (D &&
+(Entry->getDLLStorageClass() ==
+ llvm::GlobalVariable::DLLImportStorageClass) &&
+!D->hasAttr() &&
+!shouldMapVisibilityToDLLExport(cast_or_null(D)))
   Entry->setDLLStorageClass(llvm::GlobalValue::DefaultStorageClass);
 
 if (LangOpts.OpenMP && !LangOpts.OpenMPSimd && D)
diff --git 
a/clang/test/CodeGenCXX/windows-instantiate-dllexport-template-specialization.cpp
 
b/clang/test/CodeGenCXX/windows-instantiate-dllexport-template-specialization.cpp
new file mode 100644
index 0..97f341ba1f909
--- /dev/null
+++ 
b/clang/test/CodeGenCXX/windows-instantiate-dllexport-template-specialization.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -triple i686-windows -fdeclspec -emit-llvm %s -o - 
| FileCheck %s -check-prefix CHECK-MS
+// RUN: %clang_cc1 -triple i686-windows-itanium -fdeclspec -emit-llvm %s -o - 
| FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-scei-ps4  -fdeclspec -emit-llvm %s -o - 
| FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-sie-ps5   -fdeclspec -emit-llvm %s -o - 
| FileCheck %s
+
+struct s {
+  template  static bool f();
+};
+
+template  bool template_using_f(T) { return s::f(); }
+
+bool use_template_using_f() { return template_using_f(0); }
+
+template<>
+bool __declspec(dllexport) s::f() { return true; }
+
+// CHECK-MS: dllexport {{.*}} @"??$f@$00@s@@SA_NXZ"
+// CHECK: dllexport {{.*}} @_ZN1s1fILb1EEEbv

``




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


[clang] [Clang] Implement P3034R1 Module Declarations Shouldn’t be Macros (PR #90574)

2024-05-24 Thread via cfe-commits


@@ -1329,6 +1341,100 @@ bool Preprocessor::LexAfterModuleImport(Token &Result) {
   return true;
 }
 
+/// Lex a token following the 'module' contextual keyword.
+///
+/// [cpp.module]/p2:
+/// The pp-tokens, if any, of a pp-module shall be of the form:
+///   pp-module-name pp-module-partition[opt] pp-tokens[opt]
+///
+/// where the pp-tokens (if any) shall not begin with a ( preprocessing token
+/// and the grammar non-terminals are defined as:
+///   pp-module-name:
+/// pp-module-name-qualifierp[opt] identifier
+///   pp-module-partition:
+/// : pp-module-name-qualifier[opt] identifier
+///   pp-module-name-qualifier:
+/// identifier .
+/// pp-module-name-qualifier identifier .
+/// No identifier in the pp-module-name or pp-module-partition shall currently
+/// be defined as an object-like macro.
+///
+/// [cpp.module]/p3:
+/// Any preprocessing tokens after the module preprocessing token in the module
+/// directive are processed just as in normal text.
+bool Preprocessor::LexAfterModuleDecl(Token &Result) {
+  // Figure out what kind of lexer we actually have.
+  recomputeCurLexerKind();
+  LexUnexpandedToken(Result);
+
+  auto EnterTokens = [this](ArrayRef Toks, bool DisableMacroExpansion) {
+auto ToksCopy = std::make_unique(Toks.size());
+std::copy(Toks.begin(), Toks.end(), ToksCopy.get());
+EnterTokenStream(std::move(ToksCopy), Toks.size(), DisableMacroExpansion,
+ /*IsReinject=*/false);
+  };
+
+  // If we don't expect an identifier but got an identifier, it's not a part of
+  // module name.
+  if (!ModuleDeclExpectsIdentifier && Result.is(tok::identifier)) {
+EnterTokens(Result, /*DisableMacroExpansion=*/false);
+return false;
+  }
+
+  // The token sequence
+  //
+  // export[opt] module identifier (. identifier)*
+  //
+  // indicates a module directive. We already saw the 'module'
+  // contextual keyword, so now we're looking for the identifiers.
+  if (ModuleDeclExpectsIdentifier && Result.is(tok::identifier)) {
+auto *MI = getMacroInfo(Result.getIdentifierInfo());
+if (MI && MI->isObjectLike()) {
+  Diag(Result, diag::err_module_decl_cannot_be_macros)
+  << Result.getLocation() << ModuleDeclLexingPartitionName
+  << Result.getIdentifierInfo();
+}
+ModuleDeclExpectsIdentifier = false;
+CurLexerCallback = CLK_LexAfterModuleDecl;
+return true;
+  }
+
+  // If we're expecting a '.', a ':' or a ';', and we got a '.', then wait 
until
+  // we see the next identifier.
+  if (!ModuleDeclExpectsIdentifier && Result.isOneOf(tok::period, tok::colon)) 
{
+ModuleDeclExpectsIdentifier = true;
+ModuleDeclLexingPartitionName = Result.is(tok::colon);
+CurLexerCallback = CLK_LexAfterModuleDecl;
+return true;
+  }
+
+  // [cpp.module]/p2: where the pp-tokens (if any) shall not begin with a (
+  // preprocessing token [...]
+  if (!ModuleDeclExpectsIdentifier && Result.is(tok::l_paren)) {
+ModuleDeclExpectsIdentifier = false;
+Diag(Result, diag::err_unxepected_paren_in_module_decl)
+<< ModuleDeclLexingPartitionName;
+Token Tok;
+// We already have a '('.
+unsigned NumParens = 1;
+while (true) {
+  LexUnexpandedToken(Tok);
+  if (Tok.isOneOf(tok::eod, tok::eof, tok::semi, tok::period, tok::colon)) 
{
+EnterTokens(Tok, /*DisableMacroExpansion=*/true);
+break;
+  }
+  if (Tok.is(tok::l_paren))
+NumParens++;
+  else if (Tok.is(tok::r_paren) && --NumParens == 0)
+break;
+}
+CurLexerCallback = CLK_LexAfterModuleDecl;
+return false;
+  }
+
+  return true;
+}
+

yronglin wrote:

friendly ping~

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


[clang] nonblocking/nonallocating attributes (was: nolock/noalloc) (PR #84983)

2024-05-24 Thread Doug Wyatt via cfe-commits


@@ -4640,6 +4647,306 @@ class FunctionNoProtoType : public FunctionType, public 
llvm::FoldingSetNode {
   }
 };
 
+// 
--
+
+/// Represents an abstract function effect, using just an enumeration 
describing
+/// its kind.
+class FunctionEffect {
+public:
+  /// Identifies the particular effect.
+  enum class Kind : uint8_t {
+None = 0,
+NonBlocking = 1,
+NonAllocating = 2,
+Blocking = 3,
+Allocating = 4
+  };
+
+  /// Flags describing some behaviors of the effect.
+  using Flags = unsigned;
+  enum FlagBit : Flags {
+// Can verification inspect callees' implementations? (e.g. nonblocking:
+// yes, tcb+types: no). This also implies the need for 2nd-pass
+// verification.
+FE_InferrableOnCallees = 0x1,
+
+// Language constructs which effects can diagnose as disallowed.
+FE_ExcludeThrow = 0x2,
+FE_ExcludeCatch = 0x4,
+FE_ExcludeObjCMessageSend = 0x8,
+FE_ExcludeStaticLocalVars = 0x10,
+FE_ExcludeThreadLocalVars = 0x20
+  };
+
+private:
+  LLVM_PREFERRED_TYPE(Kind)
+  unsigned FKind : 3;
+
+  // Expansion: for hypothetical TCB+types, there could be one Kind for TCB,
+  // then ~16(?) bits "SubKind" to map to a specific named TCB. SubKind would
+  // be considered for uniqueness.
+
+public:
+  FunctionEffect() : FKind(unsigned(Kind::None)) {}
+
+  explicit FunctionEffect(Kind K) : FKind(unsigned(K)) {}
+
+  /// The kind of the effect.
+  Kind kind() const { return Kind(FKind); }
+
+  /// Return the opposite kind, for effects which have opposites.
+  Kind oppositeKind() const;
+
+  /// For serialization.
+  uint32_t toOpaqueInt32() const { return FKind; }
+  static FunctionEffect fromOpaqueInt32(uint32_t Value) {
+return FunctionEffect(Kind(Value));
+  }
+
+  /// Flags describing some behaviors of the effect.
+  Flags flags() const {
+switch (kind()) {
+case Kind::NonBlocking:
+  return FE_InferrableOnCallees | FE_ExcludeThrow | FE_ExcludeCatch |
+ FE_ExcludeObjCMessageSend | FE_ExcludeStaticLocalVars |
+ FE_ExcludeThreadLocalVars;
+case Kind::NonAllocating:
+  // Same as NonBlocking, except without FE_ExcludeStaticLocalVars.
+  return FE_InferrableOnCallees | FE_ExcludeThrow | FE_ExcludeCatch |
+ FE_ExcludeObjCMessageSend | FE_ExcludeThreadLocalVars;
+case Kind::Blocking:
+case Kind::Allocating:
+  return 0;
+case Kind::None:
+  break;
+}
+llvm_unreachable("unknown effect kind");
+  }
+
+  /// The description printed in diagnostics, e.g. 'nonblocking'.
+  StringRef name() const;
+
+  /// Return true if the effect is allowed to be inferred on the callee,
+  /// which is either a FunctionDecl or BlockDecl.
+  /// This is only used if the effect has FE_InferrableOnCallees flag set.
+  /// Example: This allows nonblocking(false) to prevent inference for the
+  /// function.
+  bool canInferOnFunction(const Decl &Callee) const;
+
+  // Return false for success. When true is returned for a direct call, then 
the
+  // FE_InferrableOnCallees flag may trigger inference rather than an immediate
+  // diagnostic. Caller should be assumed to have the effect (it may not have 
it
+  // explicitly when inferring).
+  bool shouldDiagnoseFunctionCall(bool Direct,
+  ArrayRef CalleeFX) const;
+
+  friend bool operator==(const FunctionEffect &LHS, const FunctionEffect &RHS) 
{
+return LHS.FKind == RHS.FKind;
+  }
+  friend bool operator!=(const FunctionEffect &LHS, const FunctionEffect &RHS) 
{
+return !(LHS == RHS);
+  }
+  friend bool operator<(const FunctionEffect &LHS, const FunctionEffect &RHS) {
+return LHS.FKind < RHS.FKind;
+  }
+};
+
+/// Wrap a function effect's condition expression in another struct so
+/// that FunctionProtoType's TrailingObjects can treat it separately.
+class FunctionEffectCondition {

dougsonos wrote:

How about
`EffectConditionExpr` : the struct holding an `Expr*` for disambiguation with 
trailing objects
`FunctionEffectWithCondition` : combining `FunctionEffect` and 
`FunctionEffectWithCondition`
?

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


[clang] [clang] Fix loss of `dllexport` for exported template specialization (PR #93302)

2024-05-24 Thread Paul T Robinson via cfe-commits

https://github.com/pogo59 commented:

Does the test exercise both modified paths? I'm guessing it only exercises 
GetOrCreateLLVMFunction, but I'm not a codegen expert.

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


[clang] [clang] Fix loss of `dllexport` for exported template specialization (PR #93302)

2024-05-24 Thread Paul T Robinson via cfe-commits

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


[clang] [clang] Fix loss of `dllexport` for exported template specialization (PR #93302)

2024-05-24 Thread Paul T Robinson via cfe-commits


@@ -4554,8 +4554,11 @@ llvm::Constant *CodeGenModule::GetOrCreateLLVMFunction(
 Entry->setLinkage(llvm::Function::ExternalLinkage);
 }
 
-// Handle dropped DLL attributes.
-if (D && !D->hasAttr() && !D->hasAttr() &&
+// Handle dropped dllimport.
+if (D &&
+(Entry->getDLLStorageClass() ==
+ llvm::GlobalVariable::DLLImportStorageClass) &&
+!D->hasAttr() &&
 !shouldMapVisibilityToDLLExport(cast_or_null(D))) {

pogo59 wrote:

```suggestion
!shouldMapVisibilityToDLLExport(cast(D))) {
```
D is non-null here.

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


[clang] [clang] Fix loss of `dllexport` for exported template specialization (PR #93302)

2024-05-24 Thread Paul T Robinson via cfe-commits


@@ -4849,9 +4852,12 @@ CodeGenModule::GetOrCreateLLVMGlobal(StringRef 
MangledName, llvm::Type *Ty,
 Entry->setLinkage(llvm::Function::ExternalLinkage);
 }
 
-// Handle dropped DLL attributes.
-if (D && !D->hasAttr() && !D->hasAttr() &&
-!shouldMapVisibilityToDLLExport(D))
+// Handle dropped dllimport.
+if (D &&
+(Entry->getDLLStorageClass() ==
+ llvm::GlobalVariable::DLLImportStorageClass) &&
+!D->hasAttr() &&
+!shouldMapVisibilityToDLLExport(cast_or_null(D)))

pogo59 wrote:

```suggestion
!shouldMapVisibilityToDLLExport(cast(D)))
```
D is non-null here.

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


[clang] [clang] Avoid crash due to unimplemented StructuralValue support in the template differ (PR #93265)

2024-05-24 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/93265

>From 2546c2c5d9e1bc6d1d4ddd818b4017073f17cec0 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Thu, 23 May 2024 21:23:21 -0300
Subject: [PATCH] [clang] Avoid crash due to unimplemented StructuralValue
 support in the template differ

This was not implemented in https://github.com/llvm/llvm-project/pull/78041

This patch does not implement this fucntionality, it just falls back to the 
expression
when possible.

Otherwise, such as when dealing with canonical types to begin with,
this will just ignore the argument as if it wasn't even there.

Fixes https://github.com/llvm/llvm-project/issues/93068
---
 clang/docs/ReleaseNotes.rst   |   1 +
 clang/lib/AST/ASTDiagnostic.cpp   | 106 +++---
 ...ng.cpp => diag-template-diffing-cxx11.cpp} |   0
 .../test/Misc/diag-template-diffing-cxx26.cpp |  49 
 4 files changed, 114 insertions(+), 42 deletions(-)
 rename clang/test/Misc/{diag-template-diffing.cpp => 
diag-template-diffing-cxx11.cpp} (100%)
 create mode 100644 clang/test/Misc/diag-template-diffing-cxx26.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7bcdee96e213e..6e8687fadc6f7 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -790,6 +790,7 @@ Miscellaneous Clang Crashes Fixed
 
 - Do not attempt to dump the layout of dependent types or invalid declarations
   when ``-fdump-record-layouts-complete`` is passed. Fixes #GH83684.
+- Unhandled StructuralValues in the template differ (#GH93068).
 
 OpenACC Specific Changes
 
diff --git a/clang/lib/AST/ASTDiagnostic.cpp b/clang/lib/AST/ASTDiagnostic.cpp
index 91bc1b22acfc7..5c7afaaf2ca8f 100644
--- a/clang/lib/AST/ASTDiagnostic.cpp
+++ b/clang/lib/AST/ASTDiagnostic.cpp
@@ -1215,46 +1215,19 @@ class TemplateDiff {
  bool &NeedAddressOf) {
 if (!Iter.isEnd()) {
   switch (Iter->getKind()) {
-default:
-  llvm_unreachable("unknown ArgumentKind");
-case TemplateArgument::Integral:
-  Value = Iter->getAsIntegral();
-  HasInt = true;
-  IntType = Iter->getIntegralType();
-  return;
-case TemplateArgument::Declaration: {
-  VD = Iter->getAsDecl();
-  QualType ArgType = Iter->getParamTypeForDecl();
-  QualType VDType = VD->getType();
-  if (ArgType->isPointerType() &&
-  Context.hasSameType(ArgType->getPointeeType(), VDType))
-NeedAddressOf = true;
-  return;
-}
-case TemplateArgument::NullPtr:
-  IsNullPtr = true;
-  return;
-case TemplateArgument::Expression:
-  E = Iter->getAsExpr();
-  }
-} else if (!Default->isParameterPack()) {
-  E = Default->getDefaultArgument().getArgument().getAsExpr();
-}
-
-if (!Iter.hasDesugaredTA()) return;
-
-const TemplateArgument& TA = Iter.getDesugaredTA();
-switch (TA.getKind()) {
-  default:
-llvm_unreachable("unknown ArgumentKind");
+  case TemplateArgument::StructuralValue:
+// FIXME: Diffing of structural values is not implemented.
+// There is no possible fallback in this case, this will show up
+// as '(no argument)'.
+return;
   case TemplateArgument::Integral:
-Value = TA.getAsIntegral();
+Value = Iter->getAsIntegral();
 HasInt = true;
-IntType = TA.getIntegralType();
+IntType = Iter->getIntegralType();
 return;
   case TemplateArgument::Declaration: {
-VD = TA.getAsDecl();
-QualType ArgType = TA.getParamTypeForDecl();
+VD = Iter->getAsDecl();
+QualType ArgType = Iter->getParamTypeForDecl();
 QualType VDType = VD->getType();
 if (ArgType->isPointerType() &&
 Context.hasSameType(ArgType->getPointeeType(), VDType))
@@ -1265,13 +1238,62 @@ class TemplateDiff {
 IsNullPtr = true;
 return;
   case TemplateArgument::Expression:
-// TODO: Sometimes, the desugared template argument Expr differs from
-// the sugared template argument Expr.  It may be useful in the future
-// but for now, it is just discarded.
-if (!E)
-  E = TA.getAsExpr();
-return;
+E = Iter->getAsExpr();
+break;
+  case TemplateArgument::Null:
+  case TemplateArgument::Type:
+  case TemplateArgument::Template:
+  case TemplateArgument::TemplateExpansion:
+llvm_unreachable("TemplateArgument kind is not expected for NTTP");
+  case TemplateArgument::Pack:
+llvm_unreachable("TemplateArgument kind should be handled elsewhere");
+  }
+} else if (!Default->isParameterPack()) {
+  E = Default->getDefaultArgument().getArgument().getAsExpr();
 }
+
+if (!Iter.hasDesugaredTA())
+  return;
+
+const Templat

[clang] bd851ee - [clang] Avoid crash due to unimplemented StructuralValue support in the template differ (#93265)

2024-05-24 Thread via cfe-commits

Author: Matheus Izvekov
Date: 2024-05-24T11:33:16-03:00
New Revision: bd851eec34749023e5d967c03847df1635bbfa57

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

LOG: [clang] Avoid crash due to unimplemented StructuralValue support in the 
template differ (#93265)

This was not implemented in
https://github.com/llvm/llvm-project/pull/78041 when StructuralValue
TemplateArguments were originally added.

This patch does not implement this functionality, it just falls back to
the expression when possible.

Otherwise, such as when dealing with canonical types to begin with, this
will just ignore the argument as if it wasn't even there.

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

Added: 
clang/test/Misc/diag-template-diffing-cxx11.cpp
clang/test/Misc/diag-template-diffing-cxx26.cpp

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

Removed: 
clang/test/Misc/diag-template-diffing.cpp



diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 45676a02b760b..f612a1fd36859 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -809,6 +809,7 @@ Miscellaneous Clang Crashes Fixed
 
 - Do not attempt to dump the layout of dependent types or invalid declarations
   when ``-fdump-record-layouts-complete`` is passed. Fixes #GH83684.
+- Unhandled StructuralValues in the template 
diff er (#GH93068).
 
 OpenACC Specific Changes
 

diff  --git a/clang/lib/AST/ASTDiagnostic.cpp b/clang/lib/AST/ASTDiagnostic.cpp
index 91bc1b22acfc7..5c7afaaf2ca8f 100644
--- a/clang/lib/AST/ASTDiagnostic.cpp
+++ b/clang/lib/AST/ASTDiagnostic.cpp
@@ -1215,46 +1215,19 @@ class TemplateDiff {
  bool &NeedAddressOf) {
 if (!Iter.isEnd()) {
   switch (Iter->getKind()) {
-default:
-  llvm_unreachable("unknown ArgumentKind");
-case TemplateArgument::Integral:
-  Value = Iter->getAsIntegral();
-  HasInt = true;
-  IntType = Iter->getIntegralType();
-  return;
-case TemplateArgument::Declaration: {
-  VD = Iter->getAsDecl();
-  QualType ArgType = Iter->getParamTypeForDecl();
-  QualType VDType = VD->getType();
-  if (ArgType->isPointerType() &&
-  Context.hasSameType(ArgType->getPointeeType(), VDType))
-NeedAddressOf = true;
-  return;
-}
-case TemplateArgument::NullPtr:
-  IsNullPtr = true;
-  return;
-case TemplateArgument::Expression:
-  E = Iter->getAsExpr();
-  }
-} else if (!Default->isParameterPack()) {
-  E = Default->getDefaultArgument().getArgument().getAsExpr();
-}
-
-if (!Iter.hasDesugaredTA()) return;
-
-const TemplateArgument& TA = Iter.getDesugaredTA();
-switch (TA.getKind()) {
-  default:
-llvm_unreachable("unknown ArgumentKind");
+  case TemplateArgument::StructuralValue:
+// FIXME: Diffing of structural values is not implemented.
+// There is no possible fallback in this case, this will show up
+// as '(no argument)'.
+return;
   case TemplateArgument::Integral:
-Value = TA.getAsIntegral();
+Value = Iter->getAsIntegral();
 HasInt = true;
-IntType = TA.getIntegralType();
+IntType = Iter->getIntegralType();
 return;
   case TemplateArgument::Declaration: {
-VD = TA.getAsDecl();
-QualType ArgType = TA.getParamTypeForDecl();
+VD = Iter->getAsDecl();
+QualType ArgType = Iter->getParamTypeForDecl();
 QualType VDType = VD->getType();
 if (ArgType->isPointerType() &&
 Context.hasSameType(ArgType->getPointeeType(), VDType))
@@ -1265,13 +1238,62 @@ class TemplateDiff {
 IsNullPtr = true;
 return;
   case TemplateArgument::Expression:
-// TODO: Sometimes, the desugared template argument Expr 
diff ers from
-// the sugared template argument Expr.  It may be useful in the future
-// but for now, it is just discarded.
-if (!E)
-  E = TA.getAsExpr();
-return;
+E = Iter->getAsExpr();
+break;
+  case TemplateArgument::Null:
+  case TemplateArgument::Type:
+  case TemplateArgument::Template:
+  case TemplateArgument::TemplateExpansion:
+llvm_unreachable("TemplateArgument kind is not expected for NTTP");
+  case TemplateArgument::Pack:
+llvm_unreachable("TemplateArgument kind should be handled elsewhere");
+  }
+} else if (!Default->isParameterPack()) {
+  E = Default->getDefaultArgument().getArgument().getAsExpr();
 }
+
+if (!Iter.hasDesugaredTA())
+  return;
+
+

[clang] [clang] Avoid crash due to unimplemented StructuralValue support in the template differ (PR #93265)

2024-05-24 Thread Matheus Izvekov via cfe-commits

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


[clang] [clang] add fallback to expr in the template differ when comparing ValueDecl (PR #93266)

2024-05-24 Thread Matheus Izvekov via cfe-commits

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


[clang] [clang] add fallback to expr in the template differ when comparing ValueDecl (PR #93266)

2024-05-24 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/93266

>From 5b592204ddef177d612f8455f4e14ab9cf9c06bd Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Thu, 23 May 2024 23:57:01 -0300
Subject: [PATCH] [clang] add fallback to expr in the template differ when
 comparing ValueDecl

---
 clang/docs/ReleaseNotes.rst | 1 +
 clang/lib/AST/ASTDiagnostic.cpp | 5 +
 clang/test/Misc/diag-template-diffing-cxx26.cpp | 4 ++--
 3 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f612a1fd36859..fd7f3ee13d9ac 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -803,6 +803,7 @@ Miscellaneous Bug Fixes
 - Fixed an infinite recursion in ASTImporter, on return type declared inside
   body of C++11 lambda without trailing return (#GH68775).
 - Fixed declaration name source location of instantiated function definitions 
(GH71161).
+- Improve diagnostic output to print an expression instead of 'no argument` 
when comparing Values as template arguments.
 
 Miscellaneous Clang Crashes Fixed
 ^
diff --git a/clang/lib/AST/ASTDiagnostic.cpp b/clang/lib/AST/ASTDiagnostic.cpp
index 5c7afaaf2ca8f..0680ff5e3a385 100644
--- a/clang/lib/AST/ASTDiagnostic.cpp
+++ b/clang/lib/AST/ASTDiagnostic.cpp
@@ -1936,6 +1936,11 @@ class TemplateDiff {
   return;
 }
 
+if (E) {
+  PrintExpr(E);
+  return;
+}
+
 OS << "(no argument)";
   }
 
diff --git a/clang/test/Misc/diag-template-diffing-cxx26.cpp 
b/clang/test/Misc/diag-template-diffing-cxx26.cpp
index cc174d6c334fb..2b6dd86a9885d 100644
--- a/clang/test/Misc/diag-template-diffing-cxx26.cpp
+++ b/clang/test/Misc/diag-template-diffing-cxx26.cpp
@@ -19,10 +19,10 @@ namespace GH93068 {
 // expected-note@#A {{no known conversion from 'A<0>' to 'const A<&n[1]> 
&' for 1st argument}}
 // expected-note@#A {{no known conversion from 'A<0>' to 'A<&n[1]> &&' for 
1st argument}}
 
-// notree-error@#2 {{no viable conversion from 'A' to 'A<(no 
argument)>'}}
+// notree-error@#2 {{no viable conversion from 'A' to 'A'}}
 /* tree-error@#2 {{no viable conversion
   A<
-[n != (no argument)]>}}*/
+[n != n + 1]>}}*/
 
 A v2 = A(); // #2
 // expected-note@#A {{no known conversion from 'A' to 'const A<&n[1]> 
&' for 1st argument}}

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


[clang] ad190fc - [clang] add fallback to expr in the template differ when comparing ValueDecl (#93266)

2024-05-24 Thread via cfe-commits

Author: Matheus Izvekov
Date: 2024-05-24T11:38:22-03:00
New Revision: ad190fcf15c1d0beea1ba93b4d250e15d2e944f4

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

LOG: [clang] add fallback to expr in the template differ when comparing 
ValueDecl (#93266)

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/AST/ASTDiagnostic.cpp
clang/test/Misc/diag-template-diffing-cxx26.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f612a1fd36859..fd7f3ee13d9ac 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -803,6 +803,7 @@ Miscellaneous Bug Fixes
 - Fixed an infinite recursion in ASTImporter, on return type declared inside
   body of C++11 lambda without trailing return (#GH68775).
 - Fixed declaration name source location of instantiated function definitions 
(GH71161).
+- Improve diagnostic output to print an expression instead of 'no argument` 
when comparing Values as template arguments.
 
 Miscellaneous Clang Crashes Fixed
 ^

diff  --git a/clang/lib/AST/ASTDiagnostic.cpp b/clang/lib/AST/ASTDiagnostic.cpp
index 5c7afaaf2ca8f..0680ff5e3a385 100644
--- a/clang/lib/AST/ASTDiagnostic.cpp
+++ b/clang/lib/AST/ASTDiagnostic.cpp
@@ -1936,6 +1936,11 @@ class TemplateDiff {
   return;
 }
 
+if (E) {
+  PrintExpr(E);
+  return;
+}
+
 OS << "(no argument)";
   }
 

diff  --git a/clang/test/Misc/diag-template-
diff ing-cxx26.cpp b/clang/test/Misc/diag-template-
diff ing-cxx26.cpp
index cc174d6c334fb..2b6dd86a9885d 100644
--- a/clang/test/Misc/diag-template-
diff ing-cxx26.cpp
+++ b/clang/test/Misc/diag-template-
diff ing-cxx26.cpp
@@ -19,10 +19,10 @@ namespace GH93068 {
 // expected-note@#A {{no known conversion from 'A<0>' to 'const A<&n[1]> 
&' for 1st argument}}
 // expected-note@#A {{no known conversion from 'A<0>' to 'A<&n[1]> &&' for 
1st argument}}
 
-// notree-error@#2 {{no viable conversion from 'A' to 'A<(no 
argument)>'}}
+// notree-error@#2 {{no viable conversion from 'A' to 'A'}}
 /* tree-error@#2 {{no viable conversion
   A<
-[n != (no argument)]>}}*/
+[n != n + 1]>}}*/
 
 A v2 = A(); // #2
 // expected-note@#A {{no known conversion from 'A' to 'const A<&n[1]> 
&' for 1st argument}}



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


[clang] [clang] add fallback to expr in the template differ when comparing ValueDecl (PR #93266)

2024-05-24 Thread Matheus Izvekov via cfe-commits

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


  1   2   3   4   >