[clang] 3c2638d - Revert "[Serialization] Read the initializer for interesting static variables before consuming it (#92218)"

2024-05-15 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2024-05-16T13:59:11+08:00
New Revision: 3c2638dae58466f7eb4384bb7f26c9af904bf94c

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

LOG: Revert "[Serialization] Read the initializer for interesting static 
variables before consuming it (#92218)"

This reverts commit 3a4c1b9b4428b08d4475decf74c11e0d328c5842.

This breaks a bot on clang-s390x-linux

Added: 


Modified: 
clang/lib/Serialization/ASTReaderDecl.cpp
clang/test/OpenMP/nvptx_lambda_capturing.cpp

Removed: 
clang/test/Modules/pr91418.cppm



diff  --git a/clang/lib/Serialization/ASTReaderDecl.cpp 
b/clang/lib/Serialization/ASTReaderDecl.cpp
index a6254b70560c3..0c647086e304a 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -4186,35 +4186,12 @@ void ASTReader::PassInterestingDeclsToConsumer() {
 GetDecl(ID);
   EagerlyDeserializedDecls.clear();
 
-  auto ConsumingPotentialInterestingDecls = [this]() {
-while (!PotentiallyInterestingDecls.empty()) {
-  Decl *D = PotentiallyInterestingDecls.front();
-  PotentiallyInterestingDecls.pop_front();
-  if (isConsumerInterestedIn(D))
-PassInterestingDeclToConsumer(D);
-}
-  };
-  std::deque MaybeInterestingDecls =
-  std::move(PotentiallyInterestingDecls);
-  assert(PotentiallyInterestingDecls.empty());
-  while (!MaybeInterestingDecls.empty()) {
-Decl *D = MaybeInterestingDecls.front();
-MaybeInterestingDecls.pop_front();
-// Since we load the variable's initializers lazily, it'd be problematic
-// if the initializers dependent on each other. So here we try to load the
-// initializers of static variables to make sure they are passed to code
-// generator by order. If we read anything interesting, we would consume
-// that before emitting the current declaration.
-if (auto *VD = dyn_cast(D);
-VD && VD->isFileVarDecl() && !VD->isExternallyVisible())
-  VD->getInit();
-ConsumingPotentialInterestingDecls();
+  while (!PotentiallyInterestingDecls.empty()) {
+Decl *D = PotentiallyInterestingDecls.front();
+PotentiallyInterestingDecls.pop_front();
 if (isConsumerInterestedIn(D))
   PassInterestingDeclToConsumer(D);
   }
-
-  // If we add any new potential interesting decl in the last call, consume it.
-  ConsumingPotentialInterestingDecls();
 }
 
 void ASTReader::loadDeclUpdateRecords(PendingUpdateRecord ) {

diff  --git a/clang/test/Modules/pr91418.cppm b/clang/test/Modules/pr91418.cppm
deleted file mode 100644
index 33fec992439d6..0
--- a/clang/test/Modules/pr91418.cppm
+++ /dev/null
@@ -1,67 +0,0 @@
-// RUN: rm -rf %t
-// RUN: mkdir -p %t
-// RUN: split-file %s %t
-//
-// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 -x c++-header 
%t/foo.h \
-// RUN: -emit-pch -o %t/foo.pch
-// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 %t/use.cpp 
-include-pch \
-// RUN: %t/foo.pch -emit-llvm -o - | FileCheck %t/use.cpp
-
-//--- foo.h
-#ifndef FOO_H
-#define FOO_H
-typedef float __m128 __attribute__((__vector_size__(16), __aligned__(16)));
-
-static __inline__ __m128 __attribute__((__always_inline__, 
__min_vector_width__(128)))
-_mm_setr_ps(float __z, float __y, float __x, float __w)
-{
-  return __extension__ (__m128){ __z, __y, __x, __w };
-}
-
-typedef __m128 VR;
-
-inline VR MakeVR( float X, float Y, float Z, float W )
-{
- return _mm_setr_ps( X, Y, Z, W );
-}
-
-extern "C" float sqrtf(float);
-
-namespace VectorSinConstantsSSE
-{
-  float a = (16 * sqrtf(0.225f));
-  VR A = MakeVR(a, a, a, a);
-  static const float b = (16 * sqrtf(0.225f));
-  static const VR B = MakeVR(b, b, b, b);
-}
-
-#endif // FOO_H
-
-//--- use.cpp
-#include "foo.h"
-float use() {
-return VectorSinConstantsSSE::A[0] + VectorSinConstantsSSE::A[1] +
-   VectorSinConstantsSSE::A[2] + VectorSinConstantsSSE::A[3] +
-   VectorSinConstantsSSE::B[0] + VectorSinConstantsSSE::B[1] +
-   VectorSinConstantsSSE::B[2] + VectorSinConstantsSSE::B[3];
-}
-
-// CHECK: define{{.*}}@__cxx_global_var_init(
-// CHECK: store{{.*}}[[a_RESULT:%[a-zA-Z0-9]+]], ptr 
@_ZN21VectorSinConstantsSSE1aE
-
-// CHECK: define{{.*}}@__cxx_global_var_init.1(
-// CHECK: [[A_CALL:%[a-zA-Z0-9]+]] = call{{.*}}@_Z6MakeVR(
-// CHECK: store{{.*}}[[A_CALL]], ptr @_ZN21VectorSinConstantsSSE1AE
-
-// CHECK: define{{.*}}@__cxx_global_var_init.2(
-// CHECK: [[B_CALL:%[a-zA-Z0-9]+]] = call{{.*}}@_Z6MakeVR(
-// CHECK: store{{.*}}[[B_CALL]], ptr @_ZN21VectorSinConstantsSSEL1BE
-
-// CHECK: define{{.*}}@__cxx_global_var_init.3(
-// CHECK: store{{.*}}[[b_RESULT:%[a-zA-Z0-9]+]], ptr 
@_ZN21VectorSinConstantsSSEL1bE
-
-// CHECK: @_GLOBAL__sub_I_use.cpp
-// CHECK: call{{.*}}@__cxx_global_var_init(
-// CHECK: 

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

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


@@ -450,6 +450,8 @@ bool 
X86TargetInfo::handleTargetFeatures(std::vector ,
   HasFullBFloat16 = true;
 } else if (Feature == "+egpr") {
   HasEGPR = true;
+} else if (Feature == "+inline-asm-use-gpr32") {

KanRobert wrote:

```
  std::string CodeModel = getTargetOpts().CodeModel;
  if (CodeModel == "default")
CodeModel = "small";
  Builder.defineMacro("__code_model_" + CodeModel + "__");
```


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] Implement provisional wording for CWG2398 regarding packs (PR #90820)

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

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


[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

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

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


[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

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

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


[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

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

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

>From 39e0af93163068f8de190649eccf91fda84178b6 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Wed, 1 May 2024 22:29:45 -0300
Subject: [PATCH] [clang] Implement provisional wording for CWG2398 regarding
 packs

This solves some ambuguity introduced in P0522 regarding how
template template parameters are partially ordered, and should reduce
the negative impact of enabling `-frelaxed-template-template-args`
by default.

When performing template argument deduction, a template template parameter
containing no packs should be more specialized than one that does.

Given the following example:
```C++
template struct A;
template class TT1, class T4> struct A>; // #1
template class TT2, class T6> struct A>; // #2

template struct B;
template struct A>;
```

Prior to P0522, candidate #2 would be more specialized.
After P0522, neither is more specialized, so this becomes ambiguous.
With this change, #2 becomes more specialized again,
maintaining compatibility with pre-P0522 implementations.

The problem is that in P0522, candidates are at least as specialized
when matching packs to fixed-size lists both ways, whereas before,
a fixed-size list is more specialized.

This patch keeps the original behavior when checking template arguments
outside deduction, but restores this aspect of pre-P0522 matching
during deduction.

---

Since this changes provisional implementation of CWG2398 which has
not been released yet, and already contains a changelog entry,
we don't provide a changelog entry here.
---
 clang/include/clang/Sema/Sema.h  |  5 +-
 clang/lib/Sema/SemaTemplate.cpp  | 10 ++--
 clang/lib/Sema/SemaTemplateDeduction.cpp | 67 +++-
 clang/test/SemaTemplate/cwg2398.cpp  | 15 ++
 4 files changed, 65 insertions(+), 32 deletions(-)

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 6a414aa57f32b..7d7eb6c559110 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -9133,7 +9133,7 @@ class Sema final : public SemaBase {
CheckTemplateArgumentKind CTAK);
   bool CheckTemplateTemplateArgument(TemplateTemplateParmDecl *Param,
  TemplateParameterList *Params,
- TemplateArgumentLoc );
+ TemplateArgumentLoc , bool IsDeduced);
 
   void NoteTemplateLocation(const NamedDecl ,
 std::optional ParamRange = {});
@@ -9603,7 +9603,8 @@ class Sema final : public SemaBase {
 sema::TemplateDeductionInfo );
 
   bool isTemplateTemplateParameterAtLeastAsSpecializedAs(
-  TemplateParameterList *PParam, TemplateDecl *AArg, SourceLocation Loc);
+  TemplateParameterList *PParam, TemplateDecl *AArg, SourceLocation Loc,
+  bool IsDeduced);
 
   void MarkUsedTemplateParameters(const Expr *E, bool OnlyDeduced,
   unsigned Depth, llvm::SmallBitVector );
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index c7aac068e264b..116d1ac077b29 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -6484,7 +6484,8 @@ bool Sema::CheckTemplateArgument(
 
   case TemplateArgument::Template:
   case TemplateArgument::TemplateExpansion:
-if (CheckTemplateTemplateArgument(TempParm, Params, Arg))
+if (CheckTemplateTemplateArgument(TempParm, Params, Arg,
+  /*IsDeduced=*/CTAK != CTAK_Specified))
   return true;
 
 SugaredConverted.push_back(Arg.getArgument());
@@ -8402,7 +8403,8 @@ static void DiagnoseTemplateParameterListArityMismatch(
 /// It returns true if an error occurred, and false otherwise.
 bool Sema::CheckTemplateTemplateArgument(TemplateTemplateParmDecl *Param,
  TemplateParameterList *Params,
- TemplateArgumentLoc ) {
+ TemplateArgumentLoc ,
+ bool IsDeduced) {
   TemplateName Name = Arg.getArgument().getAsTemplateOrTemplatePattern();
   TemplateDecl *Template = Name.getAsTemplateDecl();
   if (!Template) {
@@ -8454,8 +8456,8 @@ bool 
Sema::CheckTemplateTemplateArgument(TemplateTemplateParmDecl *Param,
 !Template->hasAssociatedConstraints())
   return false;
 
-if (isTemplateTemplateParameterAtLeastAsSpecializedAs(Params, Template,
-  Arg.getLocation())) {
+if (isTemplateTemplateParameterAtLeastAsSpecializedAs(
+Params, Template, Arg.getLocation(), IsDeduced)) {
   // P2113
   // C++20[temp.func.order]p2
   //   [...] If both deductions succeed, the partial ordering selects the
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 

[clang] [clang-format] Fix a regression in annotating struct braces (PR #92352)

2024-05-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: Owen Pan (owenca)


Changes

Fixes #92350.

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


2 Files Affected:

- (modified) clang/lib/Format/UnwrappedLineParser.cpp (+7-5) 
- (modified) clang/unittests/Format/TokenAnnotatorTest.cpp (+5) 


``diff
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 2236a49e4b765..b15a87327240b 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -4008,8 +4008,6 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
   };
 
   if (FormatTok->isOneOf(tok::colon, tok::less)) {
-if (FormatTok->is(tok::colon))
-  IsDerived = true;
 int AngleNestingLevel = 0;
 do {
   if (FormatTok->is(tok::less))
@@ -4017,9 +4015,13 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
   else if (FormatTok->is(tok::greater))
 --AngleNestingLevel;
 
-  if (AngleNestingLevel == 0 && FormatTok->is(tok::l_paren) &&
-  IsNonMacroIdentifier(FormatTok->Previous)) {
-break;
+  if (AngleNestingLevel == 0) {
+if (FormatTok->is(tok::colon)) {
+  IsDerived = true;
+} else if (FormatTok->is(tok::l_paren) &&
+   IsNonMacroIdentifier(FormatTok->Previous)) {
+  break;
+}
   }
   if (FormatTok->is(tok::l_brace)) {
 if (AngleNestingLevel == 0 && IsListInitialization())
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 51b475d37977e..aadfa6dc0165c 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -2903,6 +2903,11 @@ TEST_F(TokenAnnotatorTest, BraceKind) {
   EXPECT_BRACE_KIND(Tokens[5], BK_Block);
   EXPECT_BRACE_KIND(Tokens[6], BK_Block);
 
+  Tokens = annotate("struct Foo : Base {};");
+  ASSERT_EQ(Tokens.size(), 11u) << Tokens;
+  EXPECT_BRACE_KIND(Tokens[7], BK_Block);
+  EXPECT_BRACE_KIND(Tokens[8], BK_Block);
+
   Tokens = annotate("struct Foo final {};");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
   EXPECT_BRACE_KIND(Tokens[3], BK_Block);

``




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


[clang] [clang-format] Fix a regression in annotating struct braces (PR #92352)

2024-05-15 Thread Owen Pan via cfe-commits

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

Fixes #92350.

>From d6f338d050bba640e90da983cac34111cdbf56c2 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Wed, 15 May 2024 22:38:29 -0700
Subject: [PATCH] [clang-format] Fix a regression in annotating struct braces

Fixes #92350.
---
 clang/lib/Format/UnwrappedLineParser.cpp  | 12 +++-
 clang/unittests/Format/TokenAnnotatorTest.cpp |  5 +
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 2236a49e4b765..b15a87327240b 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -4008,8 +4008,6 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
   };
 
   if (FormatTok->isOneOf(tok::colon, tok::less)) {
-if (FormatTok->is(tok::colon))
-  IsDerived = true;
 int AngleNestingLevel = 0;
 do {
   if (FormatTok->is(tok::less))
@@ -4017,9 +4015,13 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
   else if (FormatTok->is(tok::greater))
 --AngleNestingLevel;
 
-  if (AngleNestingLevel == 0 && FormatTok->is(tok::l_paren) &&
-  IsNonMacroIdentifier(FormatTok->Previous)) {
-break;
+  if (AngleNestingLevel == 0) {
+if (FormatTok->is(tok::colon)) {
+  IsDerived = true;
+} else if (FormatTok->is(tok::l_paren) &&
+   IsNonMacroIdentifier(FormatTok->Previous)) {
+  break;
+}
   }
   if (FormatTok->is(tok::l_brace)) {
 if (AngleNestingLevel == 0 && IsListInitialization())
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 51b475d37977e..aadfa6dc0165c 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -2903,6 +2903,11 @@ TEST_F(TokenAnnotatorTest, BraceKind) {
   EXPECT_BRACE_KIND(Tokens[5], BK_Block);
   EXPECT_BRACE_KIND(Tokens[6], BK_Block);
 
+  Tokens = annotate("struct Foo : Base {};");
+  ASSERT_EQ(Tokens.size(), 11u) << Tokens;
+  EXPECT_BRACE_KIND(Tokens[7], BK_Block);
+  EXPECT_BRACE_KIND(Tokens[8], BK_Block);
+
   Tokens = annotate("struct Foo final {};");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
   EXPECT_BRACE_KIND(Tokens[3], BK_Block);

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


[clang] 70a926c - [clang] NFC: Add a few more interesting test cases for CWG2398

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

Author: Matheus Izvekov
Date: 2024-05-16T02:45:50-03:00
New Revision: 70a926cfb1d4af326be5afe6419991aeff8f44b2

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

LOG: [clang] NFC: Add a few more interesting test cases for CWG2398

Added: 


Modified: 
clang/test/SemaTemplate/cwg2398.cpp

Removed: 




diff  --git a/clang/test/SemaTemplate/cwg2398.cpp 
b/clang/test/SemaTemplate/cwg2398.cpp
index a20155486b123..d163354b2e5fe 100644
--- a/clang/test/SemaTemplate/cwg2398.cpp
+++ b/clang/test/SemaTemplate/cwg2398.cpp
@@ -137,3 +137,61 @@ namespace ttp_defaults {
   // old-error@-2 {{template template argument has 
diff erent template parameters}}
   // old-error@-3 {{explicit instantiation of 'f' does not refer to a function 
template}}
 } // namespace ttp_defaults
+
+namespace ttp_only {
+  template  class TT1> struct A  { static 
constexpr int V = 0; };
+  // new-note@-1 2{{template is declared here}}
+  template  class TT2> struct A { static 
constexpr int V = 1; };
+  // new-error@-1 {{not more specialized than the primary template}}
+  // new-note@-2 {{partial specialization matches}}
+  template  class TT3> struct A { static 
constexpr int V = 2; };
+  // new-error@-1 {{not more specialized than the primary template}}
+  // new-note@-2 {{partial specialization matches}}
+
+  template  struct B;
+  template  struct C;
+  template  struct D;
+  template  struct E;
+
+  static_assert(A::V == 0); // new-error {{ambiguous partial 
specializations}}
+  static_assert(A::V == 1);
+  static_assert(A::V == 2);
+  static_assert(A::V == 0);
+} // namespace ttp_only
+
+namespace consistency {
+  template struct nondeduced { using type = T; };
+  template struct B;
+
+  namespace t1 {
+template struct A;
+
+template class TT1,
+ class T1, class T2, class T3, class T4>
+struct A, TT1, typename nondeduced>::type> 
{};
+
+template class UU1,
+ template class UU2,
+ class U1, class U2>
+struct A, UU2, typename nondeduced>::type>;
+
+template struct A, B, B>;
+  } // namespace t1
+  namespace t2 {
+template struct A;
+
+template class TT1,
+ class T1, class T2, class T3, class T4>
+struct A, TT1, typename nondeduced>::type> 
{};
+// new-note@-1 {{partial specialization matches}}
+
+template class UU1,
+ template class UU2,
+ class U1, class U2>
+struct A, UU2, typename nondeduced>::type>;
+// new-note@-1 {{partial specialization matches}}
+
+template struct A, B, B>;
+// new-error@-1 {{ambiguous partial specializations}}
+  } // namespace t1
+} // namespace consistency



___
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-15 Thread Freddy Ye via cfe-commits


@@ -450,6 +450,8 @@ bool 
X86TargetInfo::handleTargetFeatures(std::vector ,
   HasFullBFloat16 = true;
 } else if (Feature == "+egpr") {
   HasEGPR = true;
+} else if (Feature == "+inline-asm-use-gpr32") {

FreddyLeaf wrote:

I want to use `HasInlineAsmUseGPR32` to define a MACRO, Do you know any other 
reference to implement so?

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] [AMDGPU][WIP] Extend readlane, writelane and readfirstlane intrinsic lowering for generic types (PR #89217)

2024-05-15 Thread Vikram Hegde via cfe-commits

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


[clang] [llvm] [AMDGPU][WIP] Extend readlane, writelane and readfirstlane intrinsic lowering for generic types (PR #89217)

2024-05-15 Thread Vikram Hegde via cfe-commits


@@ -5387,6 +5387,212 @@ bool 
AMDGPULegalizerInfo::legalizeDSAtomicFPIntrinsic(LegalizerHelper ,
   return true;
 }
 
+bool AMDGPULegalizerInfo::legalizeLaneOp(LegalizerHelper ,
+ MachineInstr ,
+ Intrinsic::ID IID) const {
+
+  MachineIRBuilder  = Helper.MIRBuilder;
+  MachineRegisterInfo  = *B.getMRI();
+
+  Register DstReg = MI.getOperand(0).getReg();
+  Register Src0 = MI.getOperand(2).getReg();
+
+  auto createLaneOp = [&](Register Src0, Register Src1,
+  Register Src2) -> Register {
+auto LaneOp = B.buildIntrinsic(IID, {S32}).addUse(Src0);
+switch (IID) {
+case Intrinsic::amdgcn_readfirstlane:
+  return LaneOp.getReg(0);
+case Intrinsic::amdgcn_readlane:
+  return LaneOp.addUse(Src1).getReg(0);
+case Intrinsic::amdgcn_writelane:
+  return LaneOp.addUse(Src1).addUse(Src2).getReg(0);
+default:
+  llvm_unreachable("unhandled lane op");
+}
+  };
+
+  Register Src1, Src2;
+  if (IID == Intrinsic::amdgcn_readlane || IID == Intrinsic::amdgcn_writelane) 
{
+Src1 = MI.getOperand(3).getReg();
+if (IID == Intrinsic::amdgcn_writelane) {
+  Src2 = MI.getOperand(4).getReg();
+}
+  }
+
+  LLT Ty = MRI.getType(DstReg);
+  unsigned Size = Ty.getSizeInBits();
+
+  if (Size == 32) {
+if (Ty.isScalar())
+  // Already legal

vikramRH wrote:

Also the issue is only for pointer types, float, v2i16 etc work just fine

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


[clang] [llvm] [C++23] [CLANG] Adding C++23 constexpr math functions: fmin, fmax and frexp. (PR #88978)

2024-05-15 Thread Hubert Tong via cfe-commits


@@ -14574,9 +14574,17 @@ bool FloatExprEvaluator::VisitCallExpr(const CallExpr 
*E) {
   default:
 return false;
 
+  case Builtin::BI__builtin_frexpl:
+// AIX library function `frexpl` has 'long double' type and not
+// PPCDoubleDouble type. To make sure we generate the right value, don't
+// constant evaluate it and instead defer to a libcall.
+if (Info.Ctx.getTargetInfo().getTriple().isPPC() &&
+(().getLongDoubleFormat() !=
+ ::APFloat::PPCDoubleDouble()))
+  return false;
+LLVM_FALLTHROUGH;
   case Builtin::BI__builtin_frexp:
-  case Builtin::BI__builtin_frexpf:
-  case Builtin::BI__builtin_frexpl: {
+  case Builtin::BI__builtin_frexpf: {

hubert-reinterpretcast wrote:

The comment is incorrect. The _actual_ AIX library function `frexpl` has (some 
version of) `PPCDoubleDouble` type. Because of that, Clang (which only supports 
64-bit `long double` on AIX) has to map calls to `__builtin_frexpl` to `frexp`.

For compile-time evaluation, the `APFloat`s associated with `long double` on 
AIX have the IEEE double format (and the evaluation works fine).

The solution to the failing test is to change it. The problem with the test is 
that the first input argument is a constant; changing it to refer to a global 
variable should work.
https://github.com/llvm/llvm-project/blob/566fbb450092bf8c9f966a6ab1b0381626e3e535/clang/test/CodeGen/aix-builtin-mapping.c#L16

https://github.com/llvm/llvm-project/pull/88978
___
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-15 Thread Owen Pan via cfe-commits

owenca wrote:

> This is interesting.. I like it in that its a "Leave" ... but part of me 
> would like this choice of default behind an option. As with the previous 
> changes in this area I'm uncomfortable about us changing how it behaves, but 
> would like the extra capability to choose.. I'm going to say Approve, but I'm 
> interested in your opinion about if we SHOULD have an option or not?

I don't think it warrants an option. (If an option is to be added in the 
future, the default should be `Leave`.) This is because whether to break before 
a `<<` that is between two string literals depends on what the string literals 
are. If you have code like the following in the same directory, no option value 
(other than `Leave`) would help:
```
// Don't break:
QTest::newRow("test") << "" << "" << "" << "" << "" << 1 << 1 << 1 << 1 << 1;

// Break:
OS << I->Tok->Tok.getName() << "["
   << "T=" << (unsigned)I->Tok->getType()
   << ", OC=" << I->Tok->OriginalColumn << ", \"" << I->Tok->TokenText
   << "\"] ";
```
Like some of the comments from  https://reviews.llvm.org/D80950, I'm still of 
the opinion that the (undocumented) behavior of "always breaking" is a bug, 
even though the fix should be "leave" instead of "always merging" as done in 
d68826dfbd98.

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] [llvm] [AArch64] Add support for Qualcomm Oryon processor (PR #91022)

2024-05-15 Thread Alex Bradbury via cfe-commits

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


[clang] [llvm] [AArch64] Add support for Qualcomm Oryon processor (PR #91022)

2024-05-15 Thread Alex Bradbury via cfe-commits

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


[clang] [llvm] [AArch64] Add support for Qualcomm Oryon processor (PR #91022)

2024-05-15 Thread Alex Bradbury via cfe-commits


@@ -0,0 +1,1664 @@
+//=- AArch64SchedOryon.td - Nuvia Inc Oryon CPU 001 ---*- tablegen -*-=//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file defines the scheduling model for Nuvia Inc Oryon
+// family of processors.
+//
+//===--===//
+
+//===--===//
+// Pipeline Description.
+
+def OryonModel : SchedMachineModel {
+  let IssueWidth=  14; // 14 micro-ops dispatched at a time. 
IXU=6, LSU=4, VXU=4
+  let MicroOpBufferSize = 376; // 192 (48x4) entries in micro-op re-order 
buffer in VXU.
+   // 120 ((20+20)x3) entries in micro-op 
re-order buffer in IXU
+   // 64  (16+16)x2 re-order buffer in LSU
+   // total 373
+  let LoadLatency   =   4; // 4 cycle Load-to-use from L1D$
+   // LSU=5 NEON load
+  let MispredictPenalty =  13; // 13 cycles for mispredicted branch.
+  // Determined via a mix of micro-arch details and experimentation.
+  let LoopMicroOpBufferSize =   0; // Do not have a LoopMicroOpBuffer

asb wrote:

Although it may not be microarchitecturally accurate, I wonder if you've 
benchmarked setting LoopMicroOpBufferSize to a non-zero value. Unless targets 
override it, partial and runtime loop unrolling aren't enabled unless 
LoopMicroOpBufferSize is non-zero (and this is the only way it's currently 
queried and used). In AArch64's case, they only override that decision f or 
in-order scheduling models. If you look at other models that set this value 
in-tree you'll see it's become somewhat divorced from microarchitectual reality 
- e.g. a number of the AArch64 models setting it based on instruction queue 
size or noting they just copied the value from the A57 model. On the X86 side, 
it's set to 50-72 for the modern Intel X86 and even up to 512 for Zen (noting 
it should be higher, but compile time impact is too high).

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


[clang] [ARM][clang] Fix warning for VFP function calls from interrupts. (PR #91870)

2024-05-15 Thread Chris Copeland via cfe-commits

chrisnc wrote:

ping @ostannard @smithp35 

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


[clang] [Clang][Sema] Fix last argument not being used when comparing function template specializations when one has an explicit object argument (PR #92263)

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


@@ -5591,7 +5592,11 @@ FunctionTemplateDecl *Sema::getMoreSpecializedTemplate(
   IsRValRef1);
   Args2.push_back(Obj2Ty);
 }
-size_t NumComparedArguments = NumCallArguments1 + ShouldConvert1;
+size_t NumComparedArguments = NumCallArguments1;
+// Either added an argument above or the prototype includes an explicit
+// object argument we need to count
+if (Method1)
+  ++NumComparedArguments;

mizvekov wrote:

It seems like changing the `ExplicitCallArguments` member of 
`OverloadCandidate` into just `CallArguments` might simplify this whole thing.

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


[clang] [clang] Use constant rounding mode for floating literals (PR #90877)

2024-05-15 Thread Serge Pavlov via cfe-commits

spavloff wrote:

Are there any other comments? Can this PR be considered as approved?

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


[clang] 526553b - [flang] Add nsw flag to do-variable increment with a new option (#91579)

2024-05-15 Thread via cfe-commits

Author: Yusuke MINATO
Date: 2024-05-16T13:16:07+09:00
New Revision: 526553b25131a69d9d6426e17c7b69c2ba27144f

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

LOG: [flang] Add nsw flag to do-variable increment with a new option (#91579)

This patch adds nsw flag to the increment of do-variables when a new
option is enabled.
NOTE 11.10 in the Fortran 2018 standard says they never overflow.

See also the discussion in #74709 and the following discourse post.
https://discourse.llvm.org/t/rfc-add-nsw-flags-to-arithmetic-integer-operations-using-the-option-fno-wrapv/77584/5

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Flang.cpp
flang/include/flang/Lower/LoweringOptions.def
flang/include/flang/Optimizer/Transforms/Passes.h
flang/include/flang/Optimizer/Transforms/Passes.td
flang/include/flang/Tools/CLOptions.inc
flang/include/flang/Tools/CrossToolHelpers.h
flang/lib/Frontend/CompilerInvocation.cpp
flang/lib/Frontend/FrontendActions.cpp
flang/lib/Lower/Bridge.cpp
flang/lib/Lower/IO.cpp
flang/lib/Optimizer/Transforms/ControlFlowConverter.cpp
flang/test/Driver/frontend-forwarding.f90
flang/test/Fir/loop01.fir
flang/test/Lower/array-substring.f90
flang/test/Lower/do_loop.f90
flang/test/Lower/do_loop_unstructured.f90
flang/test/Lower/infinite_loop.f90
flang/test/Lower/io-implied-do-fixes.f90
flang/tools/bbc/bbc.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index e579f1a0a3665..7bb781667e926 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -6550,6 +6550,10 @@ def flang_deprecated_no_hlfir : Flag<["-"], 
"flang-deprecated-no-hlfir">,
   Flags<[HelpHidden]>, Visibility<[FlangOption, FC1Option]>,
   HelpText<"Do not use HLFIR lowering (deprecated)">;
 
+def flang_experimental_integer_overflow : Flag<["-"], 
"flang-experimental-integer-overflow">,
+  Flags<[HelpHidden]>, Visibility<[FlangOption, FC1Option]>,
+  HelpText<"Add nsw flag to internal operations such as do-variable increment 
(experimental)">;
+
 
//===--===//
 // FLangOption + CoreOption + NoXarchOption
 
//===--===//

diff  --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index d275528b69051..42ca060186fd8 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -139,6 +139,7 @@ void Flang::addCodegenOptions(const ArgList ,
 
   Args.addAllArgs(CmdArgs, {options::OPT_flang_experimental_hlfir,
 options::OPT_flang_deprecated_no_hlfir,
+options::OPT_flang_experimental_integer_overflow,
 options::OPT_fno_ppc_native_vec_elem_order,
 options::OPT_fppc_native_vec_elem_order});
 }

diff  --git a/flang/include/flang/Lower/LoweringOptions.def 
b/flang/include/flang/Lower/LoweringOptions.def
index be080a4d29d73..7594a57a26291 100644
--- a/flang/include/flang/Lower/LoweringOptions.def
+++ b/flang/include/flang/Lower/LoweringOptions.def
@@ -34,5 +34,9 @@ ENUM_LOWERINGOPT(NoPPCNativeVecElemOrder, unsigned, 1, 0)
 /// On by default.
 ENUM_LOWERINGOPT(Underscoring, unsigned, 1, 1)
 
+/// If true, add nsw flags to loop variable increments.
+/// Off by default.
+ENUM_LOWERINGOPT(NSWOnLoopVarInc, unsigned, 1, 0)
+
 #undef LOWERINGOPT
 #undef ENUM_LOWERINGOPT

diff  --git a/flang/include/flang/Optimizer/Transforms/Passes.h 
b/flang/include/flang/Optimizer/Transforms/Passes.h
index ae1d72a3526bf..25fe61488f4f6 100644
--- a/flang/include/flang/Optimizer/Transforms/Passes.h
+++ b/flang/include/flang/Optimizer/Transforms/Passes.h
@@ -54,6 +54,7 @@ namespace fir {
 std::unique_ptr createAffineDemotionPass();
 std::unique_ptr
 createArrayValueCopyPass(fir::ArrayValueCopyOptions options = {});
+std::unique_ptr createCFGConversionPassWithNSW();
 std::unique_ptr createExternalNameConversionPass();
 std::unique_ptr
 createExternalNameConversionPass(bool appendUnderscore);
@@ -89,7 +90,8 @@ createFunctionAttrPass(FunctionAttrTypes , bool 
noInfsFPMath,
bool noSignedZerosFPMath, bool unsafeFPMath);
 
 void populateCfgConversionRewrites(mlir::RewritePatternSet ,
-   bool forceLoopToExecuteOnce = false);
+   bool forceLoopToExecuteOnce = false,
+   bool setNSW = false);
 
 // declarative passes
 #define GEN_PASS_REGISTRATION

diff  --git a/flang/include/flang/Optimizer/Transforms/Passes.td 

[clang] [flang] [flang] Add nsw flag to do-variable increment with a new option (PR #91579)

2024-05-15 Thread Yusuke MINATO via cfe-commits

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


[clang] b11a660 - [clang-format][NFC] Reformat with 18.1.5

2024-05-15 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2024-05-15T21:04:46-07:00
New Revision: b11a6607cb6522c58dfbd5f54239e7daa281368e

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

LOG: [clang-format][NFC] Reformat with 18.1.5

Added: 


Modified: 
clang/lib/Format/UnwrappedLineParser.cpp
clang/tools/clang-format/ClangFormat.cpp

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 4f1c2c5114e93..2236a49e4b765 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -47,7 +47,8 @@ void printLine(llvm::raw_ostream , const UnwrappedLine 
,
   OS << Prefix;
   NewLine = false;
 }
-OS << I->Tok->Tok.getName() << "[" << "T=" << (unsigned)I->Tok->getType()
+OS << I->Tok->Tok.getName() << "["
+   << "T=" << (unsigned)I->Tok->getType()
<< ", OC=" << I->Tok->OriginalColumn << ", \"" << I->Tok->TokenText
<< "\"] ";
 for (SmallVectorImpl::const_iterator

diff  --git a/clang/tools/clang-format/ClangFormat.cpp 
b/clang/tools/clang-format/ClangFormat.cpp
index 01f7c6047726e..3fa5f81a35768 100644
--- a/clang/tools/clang-format/ClangFormat.cpp
+++ b/clang/tools/clang-format/ClangFormat.cpp
@@ -336,7 +336,8 @@ static void outputReplacementXML(StringRef Text) {
 
 static void outputReplacementsXML(const Replacements ) {
   for (const auto  : Replaces) {
-outs() << "";
 outputReplacementXML(R.getReplacementText());
 outs() << "\n";



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


[clang] [clang] Disallow VLA type compound literals (PR #91891)

2024-05-15 Thread via cfe-commits
Jim M. R. =?utf-8?q?Teichgräber?=,Jim M. R. =?utf-8?q?Teichgräber?=,
Jim M. R. =?utf-8?q?Teichgräber?=,Jim M. R. =?utf-8?q?Teichgräber?Message-ID:
In-Reply-To: 


github-actions[bot] wrote:



@J-MR-T Congratulations on having your first Pull Request (PR) merged into the 
LLVM Project!

Your changes will be combined with recent changes from other authors, then 
tested
by our [build bots](https://lab.llvm.org/buildbot/). If there is a problem with 
a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as
the builds can include changes from many authors. It is not uncommon for your
change to be included in a build that fails due to someone else's changes, or
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail 
[here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr).

If your change does cause a problem, it may be reverted, or you can revert it 
yourself.
This is a normal part of [LLVM 
development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy).
 You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are 
working as expected, well done!


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


[clang] e91ea1b - [Clang] Disallow VLA type compound literals (#91891)

2024-05-15 Thread via cfe-commits

Author: Jim M. R. Teichgräber
Date: 2024-05-16T05:38:15+02:00
New Revision: e91ea1b5d88805ebf7657da57ca6a7577374e4ad

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

LOG: [Clang] Disallow VLA type compound literals (#91891)

C99-C23 6.5.2.5 says: The type name shall specify an object type or an
array of unknown size, but not a variable length array type.

Fixes #89835.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaExpr.cpp
clang/test/C/C2x/n2900_n3011.c
clang/test/C/C2x/n2900_n3011_2.c
clang/test/Sema/compound-literal.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 11812c355f8d1..be4cded276321 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -570,6 +570,9 @@ Bug Fixes in This Version
 - Clang will no longer emit a duplicate -Wunused-value warning for an 
expression
   `(A, B)` which evaluates to glvalue `B` that can be converted to non 
ODR-use. (#GH45783)
 
+- Clang now correctly disallows VLA type compound literals, e.g. 
``(int[size]){}``,
+  as the C standard mandates. (#GH89835)
+
 Bug Fixes to Compiler Builtins
 ^^
 

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 6100fba510059..e648b503ac034 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3371,6 +3371,8 @@ def err_field_with_address_space : Error<
   "field may not be qualified with an address space">;
 def err_compound_literal_with_address_space : Error<
   "compound literal in function scope may not be qualified with an address 
space">;
+def err_compound_literal_with_vla_type : Error<
+  "compound literal cannot be of variable-length array type">;
 def err_address_space_mismatch_templ_inst : Error<
   "conflicting address space qualifiers are provided between types %0 and %1">;
 def err_attr_objc_ownership_redundant : Error<

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 50569c1cd5367..cc507524e2fc2 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -7130,12 +7130,19 @@ Sema::BuildCompoundLiteralExpr(SourceLocation 
LParenLoc, TypeSourceInfo *TInfo,
   // init a VLA in C++ in all cases (such as with non-trivial 
constructors).
   // FIXME: should we allow this construct in C++ when it makes sense to do
   // so?
-  std::optional NumInits;
-  if (const auto *ILE = dyn_cast(LiteralExpr))
-NumInits = ILE->getNumInits();
-  if ((LangOpts.CPlusPlus || NumInits.value_or(0)) &&
-  !tryToFixVariablyModifiedVarType(TInfo, literalType, LParenLoc,
-   diag::err_variable_object_no_init))
+  //
+  // But: C99-C23 6.5.2.5 Compound literals constraint 1: The type name
+  // shall specify an object type or an array of unknown size, but not a
+  // variable length array type. This seems odd, as it allows int a[size] =
+  // {}; but forbids int a[size] = (int[size]){}; As this is what the
+  // standard says, this is what's implemented here for C (except for the
+  // extension that permits constant foldable size arrays)
+
+  auto diagID = LangOpts.CPlusPlus
+? diag::err_variable_object_no_init
+: diag::err_compound_literal_with_vla_type;
+  if (!tryToFixVariablyModifiedVarType(TInfo, literalType, LParenLoc,
+   diagID))
 return ExprError();
 }
   } else if (!literalType->isDependentType() &&

diff  --git a/clang/test/C/C2x/n2900_n3011.c b/clang/test/C/C2x/n2900_n3011.c
index 4350aa140691b..82a3b16c8acda 100644
--- a/clang/test/C/C2x/n2900_n3011.c
+++ b/clang/test/C/C2x/n2900_n3011.c
@@ -27,8 +27,14 @@ void test(void) {
   compat-warning {{use of an empty initializer is 
incompatible with C standards before C23}}
   int vla[i] = {}; // compat-warning {{use of an empty initializer is 
incompatible with C standards before C23}} \
   pedantic-warning {{use of an empty initializer is a C23 
extension}}
+  // C99 6.5.2.5 Compound literals constraint 1: The type name shall specify an
+  // object type or an array of unknown size, but not a variable length array
+  // type.
   int *compound_literal_vla = (int[i]){}; // compat-warning {{use of an empty 
initializer is incompatible with C standards before C23}} \
- pedantic-warning {{use of an 
empty initializer is a C23 extension}}
+ pedantic-warning 

[clang] [clang] Disallow VLA type compound literals (PR #91891)

2024-05-15 Thread via cfe-commits
Jim M. R. =?utf-8?q?Teichgräber?=,Jim M. R. =?utf-8?q?Teichgräber?=,
Jim M. R. =?utf-8?q?Teichgräber?=,Jim M. R. =?utf-8?q?Teichgräber?Message-ID:
In-Reply-To: 


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


[clang] [clang] Disallow VLA type compound literals (PR #91891)

2024-05-15 Thread via cfe-commits
Jim M. R. =?utf-8?q?Teichgr=C3=A4ber?=,Jim M. R. =?utf-8?q?Teichgr=C3=A4ber?=,
Jim M. R. =?utf-8?q?Teichgr=C3=A4ber?=,Jim M. R. =?utf-8?q?Teichgr=C3=A4ber?=
Message-ID:
In-Reply-To: 


Sirraide wrote:

Merging this for you since you don’t appear to have commit perms.

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


[clang] [clang] Disallow VLA type compound literals (PR #91891)

2024-05-15 Thread via cfe-commits
Jim M. R. =?utf-8?q?Teichgr=C3=A4ber?=,Jim M. R. =?utf-8?q?Teichgr=C3=A4ber?=,
Jim M. R. =?utf-8?q?Teichgr=C3=A4ber?=,Jim M. R. =?utf-8?q?Teichgr=C3=A4ber?=
Message-ID:
In-Reply-To: 


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

LGTM

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


[clang] [Clang][Sema] Fix last argument not being used when comparing function template specializations when one has an explicit object argument (PR #92263)

2024-05-15 Thread via cfe-commits

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

Fix seems reasonable to me.

https://github.com/llvm/llvm-project/pull/92263
___
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-15 Thread Shengchen Kan via cfe-commits


@@ -450,6 +450,8 @@ bool 
X86TargetInfo::handleTargetFeatures(std::vector ,
   HasFullBFloat16 = true;
 } else if (Feature == "+egpr") {
   HasEGPR = true;
+} else if (Feature == "+inline-asm-use-gpr32") {

KanRobert wrote:

This should not be implemented as a feature.

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-15 Thread Shengchen Kan via cfe-commits

KanRobert wrote:

Please put the corresponding GCC links for your description

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-15 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 23b673e5b4b73b42864fcd7d63c1e974317ed4d6 
41fbc18c7a4a26b11bc4b772bbe2e384ad9d9dbc -- 
clang/test/Driver/x86-apx-inline-asm-use-gpr32.cpp 
clang/lib/Basic/Targets/X86.cpp clang/lib/Basic/Targets/X86.h 
clang/lib/Driver/ToolChains/Arch/X86.cpp 
clang/test/Preprocessor/x86_target_features.c 
llvm/lib/Target/X86/X86ISelLowering.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp 
b/llvm/lib/Target/X86/X86ISelLowering.cpp
index 2f381a3fc1..45cc92a904 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -58281,19 +58281,19 @@ X86TargetLowering::getRegForInlineAsmConstraint(const 
TargetRegisterInfo *TRI,
 }
   } 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, ::GR8RegClass);
-if (VT == MVT::i16)
-  return std::make_pair(0U, ::GR16RegClass);
-if (VT == MVT::i32 || VT == MVT::f32 ||
-(!VT.isVector() && !Subtarget.is64Bit()))
-  return std::make_pair(0U, ::GR32RegClass);
-if (VT != MVT::f80 && !VT.isVector())
-  return std::make_pair(0U, ::GR64RegClass);
-break;
+default:
+  break;
+case 'R':
+  if (VT == MVT::i8 || VT == MVT::i1)
+return std::make_pair(0U, ::GR8RegClass);
+  if (VT == MVT::i16)
+return std::make_pair(0U, ::GR16RegClass);
+  if (VT == MVT::i32 || VT == MVT::f32 ||
+  (!VT.isVector() && !Subtarget.is64Bit()))
+return std::make_pair(0U, ::GR32RegClass);
+  if (VT != MVT::f80 && !VT.isVector())
+return std::make_pair(0U, ::GR64RegClass);
+  break;
 }
   }
 

``




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-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Freddy Ye (FreddyLeaf)


Changes

"jR": explictly enables EGPR
"r": enables/disables EGPR w/wo -mapx-inline-asm-use-gpr32
-mapx-inline-asm-use-gpr32 will also define a new Macro:
__APX_INLINE_ASM_USE_GPR32__


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


10 Files Affected:

- (modified) clang/include/clang/Driver/Options.td (+2) 
- (modified) clang/lib/Basic/Targets/X86.cpp (+26) 
- (modified) clang/lib/Basic/Targets/X86.h (+1) 
- (modified) clang/lib/Driver/ToolChains/Arch/X86.cpp (+2) 
- (added) clang/test/Driver/x86-apx-inline-asm-use-gpr32.cpp (+3) 
- (modified) clang/test/Preprocessor/x86_target_features.c (+3) 
- (modified) llvm/lib/Target/X86/X86.td (+3) 
- (modified) llvm/lib/Target/X86/X86ISelLowering.cpp (+52-5) 
- (added) llvm/test/CodeGen/X86/inline-asm-jR-constraint.ll (+19) 
- (added) llvm/test/CodeGen/X86/inline-asm-r-constraint.ll (+16) 


``diff
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 73a2518480e9b..20a7c482bbf06 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -6281,6 +6281,8 @@ def mno_apx_features_EQ : CommaJoined<["-"], 
"mno-apx-features=">, Group, Alias, 
AliasArgs<["egpr","push2pop2","ppx", "ndd"]>;
 def mno_apxf : Flag<["-"], "mno-apxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx","ndd"]>;
+def mapx_inline_asm_use_gpr32 : Flag<["-"], "mapx-inline-asm-use-gpr32">, 
Group,
+HelpText<"Enable use of GPR32 in inline 
assembly for APX">;
 } // let Flags = [TargetSpecific]
 
 // VE feature flags
diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index 67e2126cf766b..9e61b6e6d6441 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -450,6 +450,8 @@ bool 
X86TargetInfo::handleTargetFeatures(std::vector ,
   HasFullBFloat16 = true;
 } else if (Feature == "+egpr") {
   HasEGPR = true;
+} else if (Feature == "+inline-asm-use-gpr32") {
+  HasInlineAsmUseGPR32 = true;
 } else if (Feature == "+push2pop2") {
   HasPush2Pop2 = true;
 } else if (Feature == "+ppx") {
@@ -974,6 +976,8 @@ void X86TargetInfo::getTargetDefines(const LangOptions 
,
   // Condition here is aligned with the feature set of mapxf in Options.td
   if (HasEGPR && HasPush2Pop2 && HasPPX && HasNDD)
 Builder.defineMacro("__APX_F__");
+  if (HasInlineAsmUseGPR32)
+Builder.defineMacro("__APX_INLINE_ASM_USE_GPR32__");
 
   // Each case falls through to the previous one here.
   switch (SSELevel) {
@@ -1493,6 +1497,15 @@ bool X86TargetInfo::validateAsmConstraint(
   case 'C': // SSE floating point constant.
   case 'G': // x87 floating point constant.
 return true;
+  case 'j':
+Name++;
+switch (*Name) {
+default:
+  return false;
+case 'R':
+  Info.setAllowsRegister();
+  return true;
+}
   case '@':
 // CC condition changes.
 if (auto Len = matchAsmCCConstraint(Name)) {
@@ -1764,6 +1777,19 @@ std::string X86TargetInfo::convertConstraint(const char 
*) const {
   // to the next constraint.
   return std::string("^") + std::string(Constraint++, 2);
 }
+  case 'j':
+switch (Constraint[1]) {
+default:
+  // Break from inner switch and fall through (copy single char),
+  // continue parsing after copying the current constraint into
+  // the return string.
+  break;
+case 'R':
+  // "^" hints llvm that this is a 2 letter constraint.
+  // "Constraint++" is used to promote the string iterator
+  // to the next constraint.
+  return std::string("^") + std::string(Constraint++, 2);
+}
 [[fallthrough]];
   default:
 return std::string(1, *Constraint);
diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h
index c14e4d5f433d8..69c68ee80f3ba 100644
--- a/clang/lib/Basic/Targets/X86.h
+++ b/clang/lib/Basic/Targets/X86.h
@@ -174,6 +174,7 @@ class LLVM_LIBRARY_VISIBILITY X86TargetInfo : public 
TargetInfo {
   bool HasNDD = false;
   bool HasCCMP = false;
   bool HasCF = false;
+  bool HasInlineAsmUseGPR32 = false;
 
 protected:
   llvm::X86::CPUKind CPU = llvm::X86::CK_None;
diff --git a/clang/lib/Driver/ToolChains/Arch/X86.cpp 
b/clang/lib/Driver/ToolChains/Arch/X86.cpp
index 53e26a9f8e229..085ff4824a9b0 100644
--- a/clang/lib/Driver/ToolChains/Arch/X86.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/X86.cpp
@@ -309,4 +309,6 @@ void x86::getX86TargetFeatures(const Driver , const 
llvm::Triple ,
 Features.push_back("+prefer-no-gather");
   if (Args.hasArg(options::OPT_mno_scatter))
 Features.push_back("+prefer-no-scatter");
+  if (Args.hasArg(options::OPT_mapx_inline_asm_use_gpr32))
+Features.push_back("+inline-asm-use-gpr32");
 }
diff --git a/clang/test/Driver/x86-apx-inline-asm-use-gpr32.cpp 
b/clang/test/Driver/x86-apx-inline-asm-use-gpr32.cpp
new file mode 100644
index 

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

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

https://github.com/FreddyLeaf created 
https://github.com/llvm/llvm-project/pull/92338

"jR": explictly enables EGPR
"r": enables/disables EGPR w/wo -mapx-inline-asm-use-gpr32
-mapx-inline-asm-use-gpr32 will also define a new Macro:
__APX_INLINE_ASM_USE_GPR32__


>From 41fbc18c7a4a26b11bc4b772bbe2e384ad9d9dbc Mon Sep 17 00:00:00 2001
From: Freddy Ye 
Date: Fri, 10 May 2024 16:29:55 +0800
Subject: [PATCH] [X86] Support EGPR for inline assembly.

"jR": explictly enables EGPR
"r": enables/disables EGPR w/wo -mapx-inline-asm-use-gpr32
-mapx-inline-asm-use-gpr32 will also define a new Macro:
__APX_INLINE_ASM_USE_GPR32__
---
 clang/include/clang/Driver/Options.td |  2 +
 clang/lib/Basic/Targets/X86.cpp   | 26 +
 clang/lib/Basic/Targets/X86.h |  1 +
 clang/lib/Driver/ToolChains/Arch/X86.cpp  |  2 +
 .../Driver/x86-apx-inline-asm-use-gpr32.cpp   |  3 +
 clang/test/Preprocessor/x86_target_features.c |  3 +
 llvm/lib/Target/X86/X86.td|  3 +
 llvm/lib/Target/X86/X86ISelLowering.cpp   | 57 +--
 .../CodeGen/X86/inline-asm-jR-constraint.ll   | 19 +++
 .../CodeGen/X86/inline-asm-r-constraint.ll| 16 ++
 10 files changed, 127 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/Driver/x86-apx-inline-asm-use-gpr32.cpp
 create mode 100644 llvm/test/CodeGen/X86/inline-asm-jR-constraint.ll
 create mode 100644 llvm/test/CodeGen/X86/inline-asm-r-constraint.ll

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 73a2518480e9b..20a7c482bbf06 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -6281,6 +6281,8 @@ def mno_apx_features_EQ : CommaJoined<["-"], 
"mno-apx-features=">, Group, Alias, 
AliasArgs<["egpr","push2pop2","ppx", "ndd"]>;
 def mno_apxf : Flag<["-"], "mno-apxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx","ndd"]>;
+def mapx_inline_asm_use_gpr32 : Flag<["-"], "mapx-inline-asm-use-gpr32">, 
Group,
+HelpText<"Enable use of GPR32 in inline 
assembly for APX">;
 } // let Flags = [TargetSpecific]
 
 // VE feature flags
diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index 67e2126cf766b..9e61b6e6d6441 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -450,6 +450,8 @@ bool 
X86TargetInfo::handleTargetFeatures(std::vector ,
   HasFullBFloat16 = true;
 } else if (Feature == "+egpr") {
   HasEGPR = true;
+} else if (Feature == "+inline-asm-use-gpr32") {
+  HasInlineAsmUseGPR32 = true;
 } else if (Feature == "+push2pop2") {
   HasPush2Pop2 = true;
 } else if (Feature == "+ppx") {
@@ -974,6 +976,8 @@ void X86TargetInfo::getTargetDefines(const LangOptions 
,
   // Condition here is aligned with the feature set of mapxf in Options.td
   if (HasEGPR && HasPush2Pop2 && HasPPX && HasNDD)
 Builder.defineMacro("__APX_F__");
+  if (HasInlineAsmUseGPR32)
+Builder.defineMacro("__APX_INLINE_ASM_USE_GPR32__");
 
   // Each case falls through to the previous one here.
   switch (SSELevel) {
@@ -1493,6 +1497,15 @@ bool X86TargetInfo::validateAsmConstraint(
   case 'C': // SSE floating point constant.
   case 'G': // x87 floating point constant.
 return true;
+  case 'j':
+Name++;
+switch (*Name) {
+default:
+  return false;
+case 'R':
+  Info.setAllowsRegister();
+  return true;
+}
   case '@':
 // CC condition changes.
 if (auto Len = matchAsmCCConstraint(Name)) {
@@ -1764,6 +1777,19 @@ std::string X86TargetInfo::convertConstraint(const char 
*) const {
   // to the next constraint.
   return std::string("^") + std::string(Constraint++, 2);
 }
+  case 'j':
+switch (Constraint[1]) {
+default:
+  // Break from inner switch and fall through (copy single char),
+  // continue parsing after copying the current constraint into
+  // the return string.
+  break;
+case 'R':
+  // "^" hints llvm that this is a 2 letter constraint.
+  // "Constraint++" is used to promote the string iterator
+  // to the next constraint.
+  return std::string("^") + std::string(Constraint++, 2);
+}
 [[fallthrough]];
   default:
 return std::string(1, *Constraint);
diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h
index c14e4d5f433d8..69c68ee80f3ba 100644
--- a/clang/lib/Basic/Targets/X86.h
+++ b/clang/lib/Basic/Targets/X86.h
@@ -174,6 +174,7 @@ class LLVM_LIBRARY_VISIBILITY X86TargetInfo : public 
TargetInfo {
   bool HasNDD = false;
   bool HasCCMP = false;
   bool HasCF = false;
+  bool HasInlineAsmUseGPR32 = false;
 
 protected:
   llvm::X86::CPUKind CPU = llvm::X86::CK_None;
diff --git a/clang/lib/Driver/ToolChains/Arch/X86.cpp 
b/clang/lib/Driver/ToolChains/Arch/X86.cpp
index 53e26a9f8e229..085ff4824a9b0 100644
--- a/clang/lib/Driver/ToolChains/Arch/X86.cpp
+++ 

[clang] [analyzer] Allow recursive functions to be trivial. (PR #91876)

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

https://github.com/rniwa updated https://github.com/llvm/llvm-project/pull/91876

>From e40017a2750ee39bfd1a87b5ddea620076bc4419 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Sat, 11 May 2024 20:18:52 -0700
Subject: [PATCH 1/5] [analyzer] Allow recursive functions to be trivial.

---
 .../Checkers/WebKit/PtrTypesSemantics.cpp  | 18 +-
 .../Checkers/WebKit/uncounted-obj-arg.cpp  |  6 ++
 2 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 5c797d5233089..2a4da9eeaee6d 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -517,11 +517,9 @@ class TrivialFunctionAnalysisVisitor
 
 bool TrivialFunctionAnalysis::isTrivialImpl(
 const Decl *D, TrivialFunctionAnalysis::CacheTy ) {
-  // If the function isn't in the cache, conservatively assume that
-  // it's not trivial until analysis completes. This makes every recursive
-  // function non-trivial. This also guarantees that each function
-  // will be scanned at most once.
-  auto [It, IsNew] = Cache.insert(std::make_pair(D, false));
+  // Treat every recursive function as trivial until otherwise proven.
+  // This guarantees each function is evaluated at most once.
+  auto [It, IsNew] = Cache.insert(std::make_pair(D, true));
   if (!IsNew)
 return It->second;
 
@@ -535,12 +533,14 @@ bool TrivialFunctionAnalysis::isTrivialImpl(
   }
 
   const Stmt *Body = D->getBody();
-  if (!Body)
-return false;
+  if (!Body) {
+Cache[D] = false;
+return false;
+  }
 
   bool Result = V.Visit(Body);
-  if (Result)
-Cache[D] = true;
+  if (!Result)
+Cache[D] = false;
 
   return Result;
 }
diff --git a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp 
b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
index 96986631726fe..18af9e17f78b0 100644
--- a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
@@ -231,6 +231,8 @@ class RefCounted {
   void method();
   void someFunction();
   int otherFunction();
+  unsigned recursiveFunction(int n) { return !n ? 1 : recursiveFunction(n - 
1);  }
+  unsigned recursiveComplexFunction(int n) { return !n ? otherFunction() : 
recursiveComplexFunction(n - 1);  }
 
   int trivial1() { return 123; }
   float trivial2() { return 0.3; }
@@ -498,6 +500,10 @@ class UnrelatedClass {
 RefCounted::singleton().trivial18(); // no-warning
 RefCounted::singleton().someFunction(); // no-warning
 
+getFieldTrivial().recursiveFunction(7); // no-warning
+getFieldTrivial().recursiveComplexFunction(9);
+// expected-warning@-1{{Call argument for 'this' parameter is uncounted 
and unsafe}}
+
 getFieldTrivial().someFunction();
 // expected-warning@-1{{Call argument for 'this' parameter is uncounted 
and unsafe}}
 getFieldTrivial().nonTrivial1();

>From 5d7a259c0209a8cbb70c2718518905669db2a885 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Sat, 11 May 2024 20:24:10 -0700
Subject: [PATCH 2/5] Fix formatting.

---
 clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 2a4da9eeaee6d..449e56be9984d 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -535,7 +535,7 @@ bool TrivialFunctionAnalysis::isTrivialImpl(
   const Stmt *Body = D->getBody();
   if (!Body) {
 Cache[D] = false;
-return false;
+return false;
   }
 
   bool Result = V.Visit(Body);

>From 9971dcdebc160acb708b548bf67ef5efa76d4fe0 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Sun, 12 May 2024 15:15:33 -0700
Subject: [PATCH 3/5] Fix the TrivialFunctionAnalysis::isTrivialImpl for
 mutually recursive functions.

Instead of assuming every function to be initially trivial, we explicitly track
the set of functions that we're currently visting. When one of the currently 
visited
function is determined to be not trivial, we clear this set to signal that all
mutually recursive functions are non-trivial. We conclude that a function is 
trivial
when Visit() call on the function body returned true **AND** the set still 
contains
the function.

To implement this new algorithm, a new public function, IsFunctionTrivial,
is introduced to TrivialFunctionAnalysisVisitor, and various Visit functions in
TrivialFunctionAnalysisVisitor has been updated to use this function instead of
TrivialFunctionAnalysis::isTrivialImpl, which is now a wrapper for the function.
---
 .../Checkers/WebKit/PtrTypesSemantics.cpp | 69 +++
 .../Checkers/WebKit/uncounted-obj-arg.cpp   

[clang] [llvm] [PowerPC][AIX] 64-bit large code-model support for toc-data (PR #90619)

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

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


[clang] [llvm] [PowerPC][AIX] 64-bit large code-model support for toc-data (PR #90619)

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

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


[clang] [llvm] [PowerPC][AIX] 64-bit large code-model support for toc-data (PR #90619)

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


@@ -479,14 +479,6 @@ static void addTocDataOptions(const llvm::opt::ArgList 
,
   return false;
   }();
 
-  // Currently only supported for small code model.
-  if (TOCDataGloballyinEffect &&
-  (Args.getLastArgValue(options::OPT_mcmodel_EQ).equals("large") ||
-   Args.getLastArgValue(options::OPT_mcmodel_EQ).equals("medium"))) {
-D.Diag(clang::diag::warn_drv_unsupported_tocdata);

chenzheng1030 wrote:

AIX does not have medium model.

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


[clang] [llvm] [PowerPC][AIX] 64-bit large code-model support for toc-data (PR #90619)

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


@@ -6167,16 +6166,12 @@ void PPCDAGToDAGISel::Select(SDNode *N) {
 SDNode *Tmp = CurDAG->getMachineNode(
 isPPC64 ? PPC::ADDIStocHA8 : PPC::ADDIStocHA, dl, VT, TOCbase, GA);
 
-// On AIX if the symbol has the toc-data attribute it will be defined
-// in the TOC entry, so we use an ADDItocL similar to the medium code
-// model ELF abi.
+// On AIX, if the symbol has the toc-data attribute it will be defined
+// in the TOC entry, so we use an ADDItocL/ADDItocL8.
 if (isAIXABI && hasTocDataAttr(GA)) {
-  if (isPPC64)
-report_fatal_error(
-"64-bit large code model toc-data not yet supported");
-
-  ReplaceNode(N, CurDAG->getMachineNode(PPC::ADDItocL, dl, VT,
-SDValue(Tmp, 0), GA));
+  ReplaceNode(
+  N, CurDAG->getMachineNode(isPPC64 ? PPC::ADDItocL8 : PPC::ADDItocL,
+dl, VT, SDValue(Tmp, 0), GA));

chenzheng1030 wrote:

nit: I suggest to add an assert like `assert(!isPPC64 && ...)` before line 6188 
which assumes 32-bit linux/aix are already handled, so it uses `ADDItocL8` 
directly.

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


[clang] [llvm] [PowerPC][AIX] 64-bit large code-model support for toc-data (PR #90619)

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

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

LGTM just some nits. I don't think it needs another review for them from my 
side.

Please commit when @diggerlin is also happy.

Thanks very much for adding this support.

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


[clang] [llvm] [PowerPC][AIX] 64-bit large code-model support for toc-data (PR #90619)

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


@@ -1292,8 +1291,9 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr 
*MI) {
 
 unsigned Op = MI->getOpcode();
 
-// Change the opcode to load address for tocdata
-TmpInst.setOpcode(Op == PPC::ADDItocL8 ? PPC::ADDI8 : PPC::LA);
+// Change the opcode to load address for toc data.

chenzheng1030 wrote:

nit: maybe we can also add a comment here saying that for `ADDItocL`, it is 
only used for 32-bit toc data on AIX, so always using LA?

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


[clang] [llvm] [PowerPC][AIX] 64-bit large code-model support for toc-data (PR #90619)

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

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


[clang] [llvm] [PowerPC][AIX] 64-bit large code-model support for toc-data (PR #90619)

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


@@ -1,16 +1,13 @@
 // RUN: %clang -### --target=powerpc-ibm-aix-xcoff -mcmodel=medium -mtocdata 
%s 2>&1 \
-// RUN:   | FileCheck -check-prefix=CHECK-NOTOC %s
+// RUN:   | FileCheck -check-prefix=CHECK-TOC %s

chenzheng1030 wrote:

nit: since all the check prefix are "TOC", maybe we can use the default one, 
i.e., without setting -check-prefix?

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


[clang] [Serialization] Read the initializer for interesting static variables before consuming it (PR #92218)

2024-05-15 Thread Chuanqi Xu via cfe-commits

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


[clang] 3a4c1b9 - [Serialization] Read the initializer for interesting static variables before consuming it (#92218)

2024-05-15 Thread via cfe-commits

Author: Chuanqi Xu
Date: 2024-05-16T09:55:36+08:00
New Revision: 3a4c1b9b4428b08d4475decf74c11e0d328c5842

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

LOG: [Serialization] Read the initializer for interesting static variables 
before consuming it (#92218)

Close https://github.com/llvm/llvm-project/issues/91418

Since we load the variable's initializers lazily, it'd be problematic if
the initializers dependent on each other.

For example,

```
SomeType a = ...;
SomeType b = a;
```

Previously, when we load variable `b`, we need to load the initializer,
then we need to load `a`. We can only mark the variable `b` as loaded
after we load `a`. Then `a` is always initialized before `b`. However,
it is not true after we implement lazy loading for initializers.

So here we try to load the initializers of static variables to make sure
they are passed to code generator by order. If we read any thing
interesting, we would consume that before emitting the current
declaration.

Added: 
clang/test/Modules/pr91418.cppm

Modified: 
clang/lib/Serialization/ASTReaderDecl.cpp
clang/test/OpenMP/nvptx_lambda_capturing.cpp

Removed: 




diff  --git a/clang/lib/Serialization/ASTReaderDecl.cpp 
b/clang/lib/Serialization/ASTReaderDecl.cpp
index 0c647086e304a..a6254b70560c3 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -4186,12 +4186,35 @@ void ASTReader::PassInterestingDeclsToConsumer() {
 GetDecl(ID);
   EagerlyDeserializedDecls.clear();
 
-  while (!PotentiallyInterestingDecls.empty()) {
-Decl *D = PotentiallyInterestingDecls.front();
-PotentiallyInterestingDecls.pop_front();
+  auto ConsumingPotentialInterestingDecls = [this]() {
+while (!PotentiallyInterestingDecls.empty()) {
+  Decl *D = PotentiallyInterestingDecls.front();
+  PotentiallyInterestingDecls.pop_front();
+  if (isConsumerInterestedIn(D))
+PassInterestingDeclToConsumer(D);
+}
+  };
+  std::deque MaybeInterestingDecls =
+  std::move(PotentiallyInterestingDecls);
+  assert(PotentiallyInterestingDecls.empty());
+  while (!MaybeInterestingDecls.empty()) {
+Decl *D = MaybeInterestingDecls.front();
+MaybeInterestingDecls.pop_front();
+// Since we load the variable's initializers lazily, it'd be problematic
+// if the initializers dependent on each other. So here we try to load the
+// initializers of static variables to make sure they are passed to code
+// generator by order. If we read anything interesting, we would consume
+// that before emitting the current declaration.
+if (auto *VD = dyn_cast(D);
+VD && VD->isFileVarDecl() && !VD->isExternallyVisible())
+  VD->getInit();
+ConsumingPotentialInterestingDecls();
 if (isConsumerInterestedIn(D))
   PassInterestingDeclToConsumer(D);
   }
+
+  // If we add any new potential interesting decl in the last call, consume it.
+  ConsumingPotentialInterestingDecls();
 }
 
 void ASTReader::loadDeclUpdateRecords(PendingUpdateRecord ) {

diff  --git a/clang/test/Modules/pr91418.cppm b/clang/test/Modules/pr91418.cppm
new file mode 100644
index 0..33fec992439d6
--- /dev/null
+++ b/clang/test/Modules/pr91418.cppm
@@ -0,0 +1,67 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 -x c++-header 
%t/foo.h \
+// RUN: -emit-pch -o %t/foo.pch
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 %t/use.cpp 
-include-pch \
+// RUN: %t/foo.pch -emit-llvm -o - | FileCheck %t/use.cpp
+
+//--- foo.h
+#ifndef FOO_H
+#define FOO_H
+typedef float __m128 __attribute__((__vector_size__(16), __aligned__(16)));
+
+static __inline__ __m128 __attribute__((__always_inline__, 
__min_vector_width__(128)))
+_mm_setr_ps(float __z, float __y, float __x, float __w)
+{
+  return __extension__ (__m128){ __z, __y, __x, __w };
+}
+
+typedef __m128 VR;
+
+inline VR MakeVR( float X, float Y, float Z, float W )
+{
+ return _mm_setr_ps( X, Y, Z, W );
+}
+
+extern "C" float sqrtf(float);
+
+namespace VectorSinConstantsSSE
+{
+  float a = (16 * sqrtf(0.225f));
+  VR A = MakeVR(a, a, a, a);
+  static const float b = (16 * sqrtf(0.225f));
+  static const VR B = MakeVR(b, b, b, b);
+}
+
+#endif // FOO_H
+
+//--- use.cpp
+#include "foo.h"
+float use() {
+return VectorSinConstantsSSE::A[0] + VectorSinConstantsSSE::A[1] +
+   VectorSinConstantsSSE::A[2] + VectorSinConstantsSSE::A[3] +
+   VectorSinConstantsSSE::B[0] + VectorSinConstantsSSE::B[1] +
+   VectorSinConstantsSSE::B[2] + VectorSinConstantsSSE::B[3];
+}
+
+// CHECK: define{{.*}}@__cxx_global_var_init(
+// CHECK: store{{.*}}[[a_RESULT:%[a-zA-Z0-9]+]], ptr 
@_ZN21VectorSinConstantsSSE1aE
+

[clang] Reapply "[Clang][Sema] Earlier type checking for builtin unary operators (#90500)" (PR #92283)

2024-05-15 Thread Krystian Stasiowski via cfe-commits

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


[clang] 1595988 - Reapply "[Clang][Sema] Earlier type checking for builtin unary operators (#90500)" (#92283)

2024-05-15 Thread via cfe-commits

Author: Krystian Stasiowski
Date: 2024-05-15T21:52:59-04:00
New Revision: 1595988ee6f9732e7ea79928af8a470ad5ef7dbe

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

LOG: Reapply "[Clang][Sema] Earlier type checking for builtin unary operators 
(#90500)" (#92283)

This patch reapplies #90500, addressing a bug which caused binary
operators with dependent operands to be incorrectly rebuilt by
`TreeTransform`.

Added: 
clang/test/CXX/expr/expr.unary/expr.unary.general/p1.cpp
clang/test/CXX/over/over.oper/over.oper.general/p1.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/Type.h
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/TreeTransform.h
clang/test/AST/ast-dump-expr-json.cpp
clang/test/AST/ast-dump-expr.cpp
clang/test/AST/ast-dump-lambda.cpp
clang/test/CXX/over/over.built/ast.cpp
clang/test/CXX/over/over.built/p10.cpp
clang/test/CXX/over/over.built/p11.cpp
clang/test/CXX/temp/temp.res/temp.dep/temp.dep.type/p4.cpp
clang/test/Frontend/noderef_templates.cpp
clang/test/SemaCXX/cxx2b-deducing-this.cpp
clang/test/SemaTemplate/class-template-spec.cpp
clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 089a85c8cb365..11812c355f8d1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -56,6 +56,9 @@ C++ Specific Potentially Breaking Changes
 
 - Clang now rejects pointer to member from parenthesized expression in 
unevaluated context such as ``decltype(&(foo::bar))``. (#GH40906).
 
+- Clang now performs semantic analysis for unary operators with dependent 
operands
+  that are known to be of non-class non-enumeration type prior to 
instantiation.
+
 ABI Changes in This Version
 ---
 - Fixed Microsoft name mangling of implicitly defined variables used for thread

diff  --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index e6643469e0b33..da3834f19ca04 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -8044,7 +8044,10 @@ inline bool Type::isUndeducedType() const {
 /// Determines whether this is a type for which one can define
 /// an overloaded operator.
 inline bool Type::isOverloadableType() const {
-  return isDependentType() || isRecordType() || isEnumeralType();
+  if (!CanonicalType->isDependentType())
+return isRecordType() || isEnumeralType();
+  return !isArrayType() && !isFunctionType() && !isAnyPointerType() &&
+ !isMemberPointerType();
 }
 
 /// Determines whether this type is written as a typedef-name.

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index ec84798e4ce60..50569c1cd5367 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -672,12 +672,12 @@ ExprResult Sema::DefaultLvalueConversion(Expr *E) {
 
   // We don't want to throw lvalue-to-rvalue casts on top of
   // expressions of certain types in C++.
-  if (getLangOpts().CPlusPlus &&
-  (E->getType() == Context.OverloadTy ||
-   // FIXME: This is a hack! We want the lvalue-to-rvalue conversion 
applied
-   // to pointer types even if the pointee type is dependent.
-   (T->isDependentType() && !T->isPointerType()) || T->isRecordType()))
-return E;
+  if (getLangOpts().CPlusPlus) {
+if (T == Context.OverloadTy || T->isRecordType() ||
+(T->isDependentType() && !T->isAnyPointerType() &&
+ !T->isMemberPointerType()))
+  return E;
+  }
 
   // The C standard is actually really unclear on this point, and
   // DR106 tells us what the result should be but not why.  It's
@@ -10827,7 +10827,7 @@ static bool checkArithmeticIncompletePointerType(Sema 
, SourceLocation Loc,
   if (const AtomicType *ResAtomicType = ResType->getAs())
 ResType = ResAtomicType->getValueType();
 
-  assert(ResType->isAnyPointerType() && !ResType->isDependentType());
+  assert(ResType->isAnyPointerType());
   QualType PointeeTy = ResType->getPointeeType();
   return S.RequireCompleteSizedType(
   Loc, PointeeTy,
@@ -13957,9 +13957,6 @@ static QualType CheckIncrementDecrementOperand(Sema , 
Expr *Op,
ExprObjectKind ,
SourceLocation OpLoc, bool 
IsInc,
bool IsPrefix) {
-  if (Op->isTypeDependent())
-return S.Context.DependentTy;
-
   QualType ResType = Op->getType();
   // Atomic types can be used for increment / decrement where the non-atomic
   // versions can, so ignore the _Atomic() specifier for the purpose of
@@ -14410,9 +14407,6 @@ static void RecordModifiableNonNullParam(Sema , const 
Expr *Exp) {
 static 

[clang] [clang-tools-extra] [compiler-rt] [lldb] [llvm] [mlir] [openmp] [polly] fix(python): fix comparison to None (PR #91857)

2024-05-15 Thread Chuanqi Xu via cfe-commits

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


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


[clang] [analyzer] Check C++ base or member initializer in WebKit checkers. (PR #92220)

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

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


[clang] 72200fc - [analyzer] Check C++ base or member initializer in WebKit checkers. (#92220)

2024-05-15 Thread via cfe-commits

Author: Ryosuke Niwa
Date: 2024-05-15T18:16:39-07:00
New Revision: 72200fcc346bee1830d9e640e42d717a55acd74c

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

LOG: [analyzer] Check C++ base or member initializer in WebKit checkers. 
(#92220)

Co-authored-by: Ryosuke Niwa 

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 950d35a090a3f..5c797d5233089 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -525,11 +525,19 @@ bool TrivialFunctionAnalysis::isTrivialImpl(
   if (!IsNew)
 return It->second;
 
+  TrivialFunctionAnalysisVisitor V(Cache);
+
+  if (auto *CtorDecl = dyn_cast(D)) {
+for (auto *CtorInit : CtorDecl->inits()) {
+  if (!V.Visit(CtorInit->getInit()))
+return false;
+}
+  }
+
   const Stmt *Body = D->getBody();
   if (!Body)
 return false;
 
-  TrivialFunctionAnalysisVisitor V(Cache);
   bool Result = V.Visit(Body);
   if (Result)
 Cache[D] = true;

diff  --git a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp 
b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
index ed37671df3d3e..96986631726fe 100644
--- a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
@@ -159,10 +159,13 @@ template class OptionSet {
   StorageType m_storage { 0 };
 };
 
+int atoi(const char* str);
+
 class Number {
 public:
   Number(int v) : v(v) { }
   Number(double);
+  Number(const char* str) : v(atoi(str)) { }
   Number operator+(const Number&);
   Number& operator++() { ++v; return *this; }
   Number operator++(int) { Number returnValue(v); ++v; return returnValue; }
@@ -173,9 +176,16 @@ class Number {
   int v;
 };
 
+class DerivedNumber : public Number {
+public:
+  DerivedNumber(char c) : Number(c - '0') { }
+  DerivedNumber(const char* str) : Number(atoi(str)) { }
+};
+
 class ComplexNumber {
 public:
   ComplexNumber() : realPart(0), complexPart(0) { }
+  ComplexNumber(int real, const char* str) : realPart(real), complexPart(str) 
{ }
   ComplexNumber(const ComplexNumber&);
   ComplexNumber& operator++() { realPart.someMethod(); return *this; }
   ComplexNumber operator++(int);
@@ -311,6 +321,7 @@ class RefCounted {
 return;
   }
   unsigned trivial60() { return ObjectWithNonTrivialDestructor { 5 }.value(); }
+  unsigned trivial61() { return DerivedNumber('7').value(); }
 
   static RefCounted& singleton() {
 static RefCounted s_RefCounted;
@@ -391,6 +402,9 @@ class RefCounted {
   ComplexNumber nonTrivial18() { return +complex; }
   ComplexNumber* nonTrivial19() { return new ComplexNumber(complex); }
   unsigned nonTrivial20() { return ObjectWithMutatingDestructor { 7 }.value(); 
}
+  unsigned nonTrivial21() { return Number("123").value(); }
+  unsigned nonTrivial22() { return ComplexNumber(123, "456").real().value(); }
+  unsigned nonTrivial23() { return DerivedNumber("123").value(); }
 
   static unsigned s_v;
   unsigned v { 0 };
@@ -479,6 +493,7 @@ class UnrelatedClass {
 getFieldTrivial().trivial58(); // no-warning
 getFieldTrivial().trivial59(); // no-warning
 getFieldTrivial().trivial60(); // no-warning
+getFieldTrivial().trivial61(); // no-warning
 
 RefCounted::singleton().trivial18(); // no-warning
 RefCounted::singleton().someFunction(); // no-warning
@@ -525,6 +540,12 @@ class UnrelatedClass {
 // expected-warning@-1{{Call argument for 'this' parameter is uncounted 
and unsafe}}
 getFieldTrivial().nonTrivial20();
 // expected-warning@-1{{Call argument for 'this' parameter is uncounted 
and unsafe}}
+getFieldTrivial().nonTrivial21();
+// expected-warning@-1{{Call argument for 'this' parameter is uncounted 
and unsafe}}
+getFieldTrivial().nonTrivial22();
+// expected-warning@-1{{Call argument for 'this' parameter is uncounted 
and unsafe}}
+getFieldTrivial().nonTrivial23();
+// expected-warning@-1{{Call argument for 'this' parameter is uncounted 
and unsafe}}
   }
 };
 



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


[clang] [analyzer] Check C++ base or member initializer in WebKit checkers. (PR #92220)

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

rniwa wrote:

Thanks for the review!

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


[clang] [analyzer] Check C++ base or member initializer in WebKit checkers. (PR #92220)

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


@@ -525,11 +525,19 @@ bool TrivialFunctionAnalysis::isTrivialImpl(
   if (!IsNew)
 return It->second;
 
+  TrivialFunctionAnalysisVisitor V(Cache);
+
+  if (auto *CtorDecl = dyn_cast(D)) {
+for (auto *CtorInit : CtorDecl->inits()) {
+  if (!V.Visit(CtorInit->getInit()))

rniwa wrote:

Doesn't seem to hit any crashes as far as building WebKit goes :) 

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


[clang] [llvm] [MC] Remove UseAssemblerInfoForParsing (PR #91082)

2024-05-15 Thread Nikita Popov via cfe-commits

nikic wrote:

Reverted in 
https://github.com/llvm/llvm-project/commit/fa750f09be6966de7423ddce1af7d1eaf817182c
 due to large compile-time regressions in some cases, see 
https://llvm-compile-time-tracker.com/compare.php?from=9bbefb7f600019c9d7025281132dd160729bfff2=03c53c69a367008da689f0d2940e2197eb4a955c=instructions:u.
 sqlite3 regresses by 5% in unoptimized builds.

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


[clang] fa750f0 - Revert "[MC] Remove UseAssemblerInfoForParsing"

2024-05-15 Thread Nikita Popov via cfe-commits

Author: Nikita Popov
Date: 2024-05-16T09:56:07+09:00
New Revision: fa750f09be6966de7423ddce1af7d1eaf817182c

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

LOG: Revert "[MC] Remove UseAssemblerInfoForParsing"

This reverts commit 03c53c69a367008da689f0d2940e2197eb4a955c.

This causes very large compile-time regressions in some cases,
e.g. sqlite3 at O0 regresses by 5%.

Added: 


Modified: 
clang/tools/driver/cc1as_main.cpp
llvm/include/llvm/MC/MCStreamer.h
llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
llvm/lib/MC/MCObjectStreamer.cpp
llvm/lib/MC/MCStreamer.cpp
llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
llvm/lib/Target/SPIRV/SPIRVAsmPrinter.cpp
llvm/test/MC/AsmParser/assembler-expressions-inlineasm.ll
llvm/tools/llvm-mc/llvm-mc.cpp
llvm/tools/llvm-ml/llvm-ml.cpp

Removed: 




diff  --git a/clang/tools/driver/cc1as_main.cpp 
b/clang/tools/driver/cc1as_main.cpp
index 4eb753a7297a9..86afe22fac24c 100644
--- a/clang/tools/driver/cc1as_main.cpp
+++ b/clang/tools/driver/cc1as_main.cpp
@@ -576,6 +576,9 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation ,
 Str.get()->emitZeros(1);
   }
 
+  // Assembly to object compilation should leverage assembly info.
+  Str->setUseAssemblerInfoForParsing(true);
+
   bool Failed = false;
 
   std::unique_ptr Parser(

diff  --git a/llvm/include/llvm/MC/MCStreamer.h 
b/llvm/include/llvm/MC/MCStreamer.h
index 50986e6bde886..69867620e1bf8 100644
--- a/llvm/include/llvm/MC/MCStreamer.h
+++ b/llvm/include/llvm/MC/MCStreamer.h
@@ -245,6 +245,8 @@ class MCStreamer {
   /// requires.
   unsigned NextWinCFIID = 0;
 
+  bool UseAssemblerInfoForParsing;
+
   /// Is the assembler allowed to insert padding automatically?  For
   /// correctness reasons, we sometimes need to ensure instructions aren't
   /// separated in unexpected ways.  At the moment, this feature is only
@@ -294,10 +296,11 @@ class MCStreamer {
 
   MCContext () const { return Context; }
 
-  // MCObjectStreamer has an MCAssembler and allows more expression folding at
-  // parse time.
   virtual MCAssembler *getAssemblerPtr() { return nullptr; }
 
+  void setUseAssemblerInfoForParsing(bool v) { UseAssemblerInfoForParsing = v; 
}
+  bool getUseAssemblerInfoForParsing() { return UseAssemblerInfoForParsing; }
+
   MCTargetStreamer *getTargetStreamer() {
 return TargetStreamer.get();
   }

diff  --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp 
b/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
index 08e3c208ba4d3..d0ef3e5a19391 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
@@ -102,6 +102,9 @@ void AsmPrinter::emitInlineAsm(StringRef Str, const 
MCSubtargetInfo ,
   std::unique_ptr Parser(
   createMCAsmParser(SrcMgr, OutContext, *OutStreamer, *MAI, BufNum));
 
+  // Do not use assembler-level information for parsing inline assembly.
+  OutStreamer->setUseAssemblerInfoForParsing(false);
+
   // We create a new MCInstrInfo here since we might be at the module level
   // and not have a MachineFunction to initialize the TargetInstrInfo from and
   // we only need MCInstrInfo for asm parsing. We create one unconditionally

diff  --git a/llvm/lib/MC/MCObjectStreamer.cpp 
b/llvm/lib/MC/MCObjectStreamer.cpp
index a9003a164b306..d2da5d0d3f90f 100644
--- a/llvm/lib/MC/MCObjectStreamer.cpp
+++ b/llvm/lib/MC/MCObjectStreamer.cpp
@@ -40,7 +40,14 @@ MCObjectStreamer::MCObjectStreamer(MCContext ,
 
 MCObjectStreamer::~MCObjectStreamer() = default;
 
-MCAssembler *MCObjectStreamer::getAssemblerPtr() { return Assembler.get(); }
+// AssemblerPtr is used for evaluation of expressions and causes
+// 
diff erence between asm and object outputs. Return nullptr to in
+// inline asm mode to limit divergence to assembly inputs.
+MCAssembler *MCObjectStreamer::getAssemblerPtr() {
+  if (getUseAssemblerInfoForParsing())
+return Assembler.get();
+  return nullptr;
+}
 
 void MCObjectStreamer::addPendingLabel(MCSymbol* S) {
   MCSection *CurSection = getCurrentSectionOnly();

diff  --git a/llvm/lib/MC/MCStreamer.cpp b/llvm/lib/MC/MCStreamer.cpp
index 199d865ea3496..176d55aa890be 100644
--- a/llvm/lib/MC/MCStreamer.cpp
+++ b/llvm/lib/MC/MCStreamer.cpp
@@ -93,7 +93,7 @@ void MCTargetStreamer::emitAssignment(MCSymbol *Symbol, const 
MCExpr *Value) {}
 
 MCStreamer::MCStreamer(MCContext )
 : Context(Ctx), CurrentWinFrameInfo(nullptr),
-  CurrentProcWinFrameInfoStartIndex(0) {
+  CurrentProcWinFrameInfoStartIndex(0), UseAssemblerInfoForParsing(false) {
   SectionStack.push_back(std::pair());
 }
 

diff  --git a/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp 
b/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
index bd48a5f80c828..b7388ed9e85a8 100644
--- 

[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

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

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


[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

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

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

>From c4b72afa655c0e35005dca8aea18e651189f8938 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Wed, 1 May 2024 22:29:45 -0300
Subject: [PATCH] [clang] Implement provisional wording for CWG2398 regarding
 packs

This solves some ambuguity introduced in P0522 regarding how
template template parameters are partially ordered, and should reduce
the negative impact of enabling `-frelaxed-template-template-args`
by default.

When performing template argument deduction, a template template parameter
containing no packs should be more specialized than one that does.

Given the following example:
```C++
template struct A;
template class TT1, class T4> struct A>; // #1
template class TT2, class T6> struct A>; // #2

template struct B;
template struct A>;
```

Prior to P0522, candidate #2 would be more specialized.
After P0522, neither is more specialized, so this becomes ambiguous.
With this change, #2 becomes more specialized again,
maintaining compatibility with pre-P0522 implementations.

The problem is that in P0522, candidates are at least as specialized
when matching packs to fixed-size lists both ways, whereas before,
a fixed-size list is more specialized.

This patch keeps the original behavior when checking template arguments
outside deduction, but restores this aspect of pre-P0522 matching
during deduction.

---

Since this changes provisional implementation of CWG2398 which has
not been released yet, and already contains a changelog entry,
we don't provide a changelog entry here.
---
 clang/include/clang/Sema/Sema.h  |  5 +-
 clang/lib/Sema/SemaTemplate.cpp  | 10 ++--
 clang/lib/Sema/SemaTemplateDeduction.cpp | 67 +++-
 clang/test/SemaTemplate/cwg2398.cpp  | 24 ++---
 4 files changed, 80 insertions(+), 26 deletions(-)

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 6a414aa57f32b..7d7eb6c559110 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -9133,7 +9133,7 @@ class Sema final : public SemaBase {
CheckTemplateArgumentKind CTAK);
   bool CheckTemplateTemplateArgument(TemplateTemplateParmDecl *Param,
  TemplateParameterList *Params,
- TemplateArgumentLoc );
+ TemplateArgumentLoc , bool IsDeduced);
 
   void NoteTemplateLocation(const NamedDecl ,
 std::optional ParamRange = {});
@@ -9603,7 +9603,8 @@ class Sema final : public SemaBase {
 sema::TemplateDeductionInfo );
 
   bool isTemplateTemplateParameterAtLeastAsSpecializedAs(
-  TemplateParameterList *PParam, TemplateDecl *AArg, SourceLocation Loc);
+  TemplateParameterList *PParam, TemplateDecl *AArg, SourceLocation Loc,
+  bool IsDeduced);
 
   void MarkUsedTemplateParameters(const Expr *E, bool OnlyDeduced,
   unsigned Depth, llvm::SmallBitVector );
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index c7aac068e264b..116d1ac077b29 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -6484,7 +6484,8 @@ bool Sema::CheckTemplateArgument(
 
   case TemplateArgument::Template:
   case TemplateArgument::TemplateExpansion:
-if (CheckTemplateTemplateArgument(TempParm, Params, Arg))
+if (CheckTemplateTemplateArgument(TempParm, Params, Arg,
+  /*IsDeduced=*/CTAK != CTAK_Specified))
   return true;
 
 SugaredConverted.push_back(Arg.getArgument());
@@ -8402,7 +8403,8 @@ static void DiagnoseTemplateParameterListArityMismatch(
 /// It returns true if an error occurred, and false otherwise.
 bool Sema::CheckTemplateTemplateArgument(TemplateTemplateParmDecl *Param,
  TemplateParameterList *Params,
- TemplateArgumentLoc ) {
+ TemplateArgumentLoc ,
+ bool IsDeduced) {
   TemplateName Name = Arg.getArgument().getAsTemplateOrTemplatePattern();
   TemplateDecl *Template = Name.getAsTemplateDecl();
   if (!Template) {
@@ -8454,8 +8456,8 @@ bool 
Sema::CheckTemplateTemplateArgument(TemplateTemplateParmDecl *Param,
 !Template->hasAssociatedConstraints())
   return false;
 
-if (isTemplateTemplateParameterAtLeastAsSpecializedAs(Params, Template,
-  Arg.getLocation())) {
+if (isTemplateTemplateParameterAtLeastAsSpecializedAs(
+Params, Template, Arg.getLocation(), IsDeduced)) {
   // P2113
   // C++20[temp.func.order]p2
   //   [...] If both deductions succeed, the partial ordering selects the
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 

[clang] [llvm] [IR] Add getelementptr nusw and nuw flags (PR #90824)

2024-05-15 Thread Nikita Popov via cfe-commits

https://github.com/nikic updated https://github.com/llvm/llvm-project/pull/90824

>From 009ffa45c131982caac5b9025678cde0418ac003 Mon Sep 17 00:00:00 2001
From: Nikita Popov 
Date: Thu, 2 May 2024 12:11:18 +0900
Subject: [PATCH 1/7] Add support for getelementptr nusw and nuw

---
 llvm/docs/LangRef.rst | 57 --
 llvm/docs/ReleaseNotes.rst|  1 +
 llvm/include/llvm/AsmParser/LLToken.h |  1 +
 llvm/include/llvm/Bitcode/LLVMBitCodes.h  |  8 +++
 llvm/include/llvm/IR/Instructions.h   | 14 +
 llvm/include/llvm/IR/Operator.h   | 26 +++-
 llvm/lib/AsmParser/LLLexer.cpp|  1 +
 llvm/lib/AsmParser/LLParser.cpp   | 21 ++-
 llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 20 +--
 llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 11 +++-
 llvm/lib/IR/AsmWriter.cpp |  4 ++
 llvm/lib/IR/Instruction.cpp   | 22 +--
 llvm/lib/IR/Instructions.cpp  | 16 +
 llvm/lib/IR/Operator.cpp  |  3 +-
 .../Scalar/SeparateConstOffsetFromGEP.cpp |  8 +++
 .../Transforms/Utils/FunctionComparator.cpp   |  6 ++
 llvm/lib/Transforms/Vectorize/VPlan.h |  5 ++
 llvm/test/Assembler/flags.ll  | 43 +
 llvm/test/Transforms/InstCombine/freeze.ll| 22 +++
 llvm/test/Transforms/SimplifyCFG/HoistCode.ll | 60 +++
 llvm/test/tools/llvm-reduce/reduce-flags.ll   | 18 --
 .../deltas/ReduceInstructionFlags.cpp |  4 ++
 22 files changed, 333 insertions(+), 38 deletions(-)

diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index e2f4d8bfcaeed..aedd1c2281eff 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -11180,6 +11180,8 @@ Syntax:
 
= getelementptr , ptr {,  }*
= getelementptr inbounds , ptr {,  }*
+   = getelementptr nusw , ptr {,  }*
+   = getelementptr nuw , ptr {,  }*
= getelementptr inrange(S,E) , ptr {,  }*
= getelementptr ,  ,  

 
@@ -11295,27 +11297,46 @@ memory though, even if it happens to point into 
allocated storage. See the
 :ref:`Pointer Aliasing Rules ` section for more
 information.
 
-If the ``inbounds`` keyword is present, the result value of a
-``getelementptr`` with any non-zero indices is a
-:ref:`poison value ` if one of the following rules is violated:
-
-*  The base pointer has an *in bounds* address of an allocated object, which
+The ``getelementptr`` instruction may have a number of attributes that impose
+additional rules. If any of the rules are violated, the result value is a
+:ref:`poison value `. In cases where the base is a vector of
+pointers, the attributes apply to each computation element-wise.
+
+For ``nusw`` (no unsigned signed wrap):
+
+ * If the type of an index is larger than the pointer index type, the
+   truncation to the pointer index type preserves the signed value
+   (``trunc nsw``).
+ * The multiplication of an index by the type size does not wrap the pointer
+   index type in a signed sense (``mul nsw``).
+ * The successive addition of each offset (without adding the base address)
+   does not wrap the pointer index type in a signed sense (``add nsw``).
+ * The successive addition of the current address, truncated to the index type
+   and interpreted as an unsigned number, and each offset, interpreted as
+   a signed number, does not wrap the index type.
+
+For ``nuw`` (no unsigned wrap):
+
+ * If the type of an index is larger than the pointer index type, the
+   truncation to the pointer index type preserves the unsigned value
+   (``trunc nuw``).
+ * The multiplication of an index by the type size does not wrap the pointer
+   index type in an unsigned sense (``mul nuw``).
+ * The successive addition of each offset (without adding the base address)
+   does not wrap the pointer index type in an unsigned sense (``add nuw``).
+ * The successive addition of the current address, truncated to the index type
+   and interpreted as an unsigned number, and each offset, also interpreted as
+   an unsigned number, does not wrap the index type (``add nuw``).
+
+For ``inbounds`` all rules of the ``nusw`` attribute apply. Additionally,
+if the ``getelementptr`` has any non-zero indices, the following rules apply:
+
+ * The base pointer has an *in bounds* address of an allocated object, which
means that it points into an allocated object, or to its end. Note that the
object does not have to be live anymore; being in-bounds of a deallocated
object is sufficient.
-*  If the type of an index is larger than the pointer index type, the
-   truncation to the pointer index type preserves the signed value.
-*  The multiplication of an index by the type size does not wrap the pointer
-   index type in a signed sense (``nsw``).
-*  The successive addition of each offset (without adding the base address) 
does
-   not wrap the pointer index type in a signed sense 

[clang] Run ObjCContractPass in Distributed Thin-LTO Pipeline (PR #92331)

2024-05-15 Thread Nuri Amari via cfe-commits

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


[clang] Run ObjCContractPass in Distributed Thin-LTO Pipeline (PR #92331)

2024-05-15 Thread Nuri Amari via cfe-commits

https://github.com/NuriAmari created 
https://github.com/llvm/llvm-project/pull/92331

Prior to this patch, when using -fthinlto-index= the ObjCARCContractPass isn't 
run prior to CodeGen, and instruction selection fails on IR containing arc 
intrinstics.

The pass would normally be added here: 
https://github.com/llvm/llvm-project/blob/c00e012bcf5da384a3e7339dc2e046779b339063/clang/lib/CodeGen/BackendUtil.cpp#L1352
 Since because we are using an index file, we return early above after 
`runThinLTOBackend`:
https://github.com/llvm/llvm-project/blob/c00e012bcf5da384a3e7339dc2e046779b339063/clang/lib/CodeGen/BackendUtil.cpp#L1333-L1339


>From 66ddf609c0e77867ec48c17136fb80d1e482041d Mon Sep 17 00:00:00 2001
From: Nuri Amari 
Date: Wed, 15 May 2024 16:33:03 -0700
Subject: [PATCH] Run ObjCContractPass in Distributed Thin-LTO Pipeline

Prior to this patch, when using -fthinlto-index= the
ObjCARCContractPass isn't run prior to CodeGen, and
instruction selection fails on IR containing
arc intrinstics.
---
 clang/lib/CodeGen/BackendUtil.cpp |  3 +++
 .../thinlto-distributed-objc-contract-pass.ll | 19 +++
 2 files changed, 22 insertions(+)
 create mode 100644 clang/test/CodeGen/thinlto-distributed-objc-contract-pass.ll

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 90985c08fe7f8..03dd1df281d80 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -1289,6 +1289,9 @@ static void runThinLTOBackend(
 };
 break;
   default:
+Conf.PreCodeGenPassesHook = [](legacy::PassManager ) {
+  Pm.add(createObjCARCContractPass());
+};
 Conf.CGFileType = getCodeGenFileType(Action);
 break;
   }
diff --git a/clang/test/CodeGen/thinlto-distributed-objc-contract-pass.ll 
b/clang/test/CodeGen/thinlto-distributed-objc-contract-pass.ll
new file mode 100644
index 0..7d0247555b5c8
--- /dev/null
+++ b/clang/test/CodeGen/thinlto-distributed-objc-contract-pass.ll
@@ -0,0 +1,19 @@
+; RUN: opt -thinlto-bc -o %t.o %s
+
+; RUN: llvm-lto2 run -thinlto-distributed-indexes %t.o \
+; RUN:   -o %t2.index \
+; RUN:   -r=%t.o,_use_arc,px
+
+; RUN: %clang_cc1 -triple x86_64-apple-darwin \
+; RUN:   -emit-obj -fthinlto-index=%t.o.thinlto.bc \
+; RUN:   -o %t.native.o -x ir %t.o
+
+target datalayout = 
"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-apple-darwin"
+
+define void @use_arc(ptr %a, ptr %b) {
+  call void (...) @llvm.objc.clang.arc.use(i8* %a, i8* %b) nounwind
+  ret void
+}
+
+declare void @llvm.objc.clang.arc.use(...) nounwind

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


[clang] [Coverage] Handle array decomposition correctly (PR #88881)

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

bolshakov-a wrote:

Thanks!

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


[clang] [HLSL] support packoffset in clang codeGen (PR #91999)

2024-05-15 Thread Xiang Li via cfe-commits

python3kgae wrote:

> I'm a little concerned about the strategy here. LLVM generally doesn't 
> explicitly capture padding it relies on the data layout rules to capture that.
> 
> If this is the approach we're going with you can't put any vectors or 
> matrices into the cbuffer structure type and we need to account for all the 
> padding bytes explicitly.

Could you explain more about can't put any vectors or matrices into the cbuffer 
structure type?

The issue is packoffset might generate gap in the layout.
The datalayout cannot express the gap.
If we cannot implement it with padding, the other option will be metadata.


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


[clang] [clang] Enable C++17 relaxed template template argument matching by default (PR #89807)

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

mizvekov wrote:

@joanahalili This is now merged in main: 
https://github.com/llvm/llvm-project/pull/92324

You can pass `-Wno-deprecated-no-relaxed-template-template-args` to disable the 
deprecation warning for `-fno-relaxed-template-template-args` specifically, 
without affecting other warnings.

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


[clang] [clang] Create new warning group for deprecation of '-fno-relaxed-template-template-args' (PR #92324)

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

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


[clang] c227bf1 - [clang] Create new warning group for deprecation of '-fno-relaxed-template-template-args' (#92324)

2024-05-15 Thread via cfe-commits

Author: Matheus Izvekov
Date: 2024-05-15T20:01:17-03:00
New Revision: c227bf1b217598066acd32de8c9a75c2e0928f89

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

LOG: [clang] Create new warning group for deprecation of 
'-fno-relaxed-template-template-args' (#92324)

This allows the warning to be disabled in isolation, as it helps when
treating them as errors.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/include/clang/Basic/DiagnosticGroups.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/frelaxed-template-template-args.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6f7e54252150c..089a85c8cb365 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -51,7 +51,8 @@ C++ Specific Potentially Breaking Changes
 - The behavior controlled by the `-frelaxed-template-template-args` flag is now
   on by default, and the flag is deprecated. Until the flag is finally removed,
   it's negative spelling can be used to obtain compatibility with previous
-  versions of clang.
+  versions of clang. The deprecation warning for the negative spelling can be
+  disabled with `-Wno-deprecated-no-relaxed-template-template-args`.
 
 - Clang now rejects pointer to member from parenthesized expression in 
unevaluated context such as ``decltype(&(foo::bar))``. (#GH40906).
 

diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 9781fcaa4ff5e..9d97a75f696f6 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -436,6 +436,9 @@ def warn_drv_clang_unsupported : Warning<
   "the clang compiler does not support '%0'">;
 def warn_drv_deprecated_arg : Warning<
   "argument '%0' is deprecated%select{|, use '%2' instead}1">, 
InGroup;
+def warn_drv_deprecated_arg_no_relaxed_template_template_args : Warning<
+  "argument '-fno-relaxed-template-template-args' is deprecated">,
+  InGroup;
 def warn_drv_deprecated_custom : Warning<
   "argument '%0' is deprecated, %1">, InGroup;
 def warn_drv_assuming_mfloat_abi_is : Warning<

diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 2beb1d45124b4..4cb4f3d999f7a 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -104,6 +104,7 @@ def EnumConversion : DiagGroup<"enum-conversion",
[EnumEnumConversion,
 EnumFloatConversion,
 EnumCompareConditional]>;
+def DeprecatedNoRelaxedTemplateTemplateArgs : 
DiagGroup<"deprecated-no-relaxed-template-template-args">;
 def ObjCSignedCharBoolImplicitIntConversion :
   DiagGroup<"objc-signed-char-bool-implicit-int-conversion">;
 def Shorten64To32 : DiagGroup<"shorten-64-to-32">;
@@ -228,6 +229,7 @@ def Deprecated : DiagGroup<"deprecated", 
[DeprecatedAnonEnumEnumConversion,
   DeprecatedLiteralOperator,
   DeprecatedPragma,
   DeprecatedRegister,
+  
DeprecatedNoRelaxedTemplateTemplateArgs,
   DeprecatedThisCapture,
   DeprecatedType,
   DeprecatedVolatile,

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 42feb1650574e..c3e6d563f3bd2 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7253,10 +7253,14 @@ void Clang::ConstructJob(Compilation , const 
JobAction ,
   if (Arg *A =
   Args.getLastArg(options::OPT_frelaxed_template_template_args,
   options::OPT_fno_relaxed_template_template_args)) {
-D.Diag(diag::warn_drv_deprecated_arg)
-<< A->getAsString(Args) << /*hasReplacement=*/false;
-if 
(A->getOption().matches(options::OPT_fno_relaxed_template_template_args))
+if (A->getOption().matches(
+options::OPT_fno_relaxed_template_template_args)) {
+  D.Diag(diag::warn_drv_deprecated_arg_no_relaxed_template_template_args);
   CmdArgs.push_back("-fno-relaxed-template-template-args");
+} else {
+  D.Diag(diag::warn_drv_deprecated_arg)
+  << A->getAsString(Args) << /*hasReplacement=*/false;
+}
   }
 
   // -fsized-deallocation is off by default, as it is an ABI-breaking change 
for

diff  --git a/clang/test/Driver/frelaxed-template-template-args.cpp 

[clang] [Clang][Sema] Do not mark template parameters in the exception specification as used during partial ordering (PR #91534)

2024-05-15 Thread Krystian Stasiowski via cfe-commits

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


[clang] 667d12f - [Clang][Sema] Do not mark template parameters in the exception specification as used during partial ordering (#91534)

2024-05-15 Thread via cfe-commits

Author: Krystian Stasiowski
Date: 2024-05-15T18:55:53-04:00
New Revision: 667d12f86e626173726e87e101626a9060b8d967

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

LOG: [Clang][Sema] Do not mark template parameters in the exception 
specification as used during partial ordering (#91534)

We do not deduce template arguments from the exception specification
when determining the primary template of a function template
specialization or when taking the address of a function template.
Therefore, this patch changes `isAtLeastAsSpecializedAs` such that we do
not mark template parameters in the exception specification as 'used'
during partial ordering (per [temp.deduct.partial]
p12) to prevent the following from being ambiguous:

```
template
void f(U) noexcept(noexcept(T())); // #1

template
void f(T*) noexcept; // #2

template<>
void f(int*) noexcept; // currently ambiguous, selects #2 with this patch 
applied 
```

Although there is no corresponding wording in the standard (see core issue 
filed here
https://github.com/cplusplus/CWG/issues/537), this seems
to be the intended behavior given the definition of _deduction
substitution loci_ in [temp.deduct.general] p7 (and EDG does the same thing).

Added: 
clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.partial/p3.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaTemplateDeduction.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ae699ebfc6038..6f7e54252150c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -713,6 +713,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).
+- Clang now ignores template parameters only used within the exception 
specification of candidate function
+  templates during partial ordering when deducing template arguments from a 
function declaration or when
+  taking the address of a function template.
 
 Bug Fixes to AST Handling
 ^

diff  --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 853c0e1b50619..b5d405111fe4c 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -5453,7 +5453,7 @@ static bool isAtLeastAsSpecializedAs(Sema , 
SourceLocation Loc,
 // is used.
 if (DeduceTemplateArgumentsByTypeMatch(
 S, TemplateParams, FD2->getType(), FD1->getType(), Info, Deduced,
-TDF_None,
+TDF_AllowCompatibleFunctionType,
 /*PartialOrdering=*/true) != TemplateDeductionResult::Success)
   return false;
 break;
@@ -5485,20 +5485,40 @@ static bool isAtLeastAsSpecializedAs(Sema , 
SourceLocation Loc,
   switch (TPOC) {
   case TPOC_Call:
 for (unsigned I = 0, N = Args2.size(); I != N; ++I)
-  ::MarkUsedTemplateParameters(S.Context, Args2[I], false,
-   TemplateParams->getDepth(),
-   UsedParameters);
+  ::MarkUsedTemplateParameters(S.Context, Args2[I], /*OnlyDeduced=*/false,
+   TemplateParams->getDepth(), UsedParameters);
 break;
 
   case TPOC_Conversion:
-::MarkUsedTemplateParameters(S.Context, Proto2->getReturnType(), false,
+::MarkUsedTemplateParameters(S.Context, Proto2->getReturnType(),
+ /*OnlyDeduced=*/false,
  TemplateParams->getDepth(), UsedParameters);
 break;
 
   case TPOC_Other:
-::MarkUsedTemplateParameters(S.Context, FD2->getType(), false,
- TemplateParams->getDepth(),
- UsedParameters);
+// We do not deduce template arguments from the exception specification
+// when determining the primary template of a function template
+// specialization or when taking the address of a function template.
+// Therefore, we do not mark template parameters in the exception
+// specification as used during partial ordering to prevent the following
+// from being ambiguous:
+//
+//   template
+//   void f(U) noexcept(noexcept(T())); // #1
+//
+//   template
+//   void f(T*) noexcept; // #2
+//
+//   template<>
+//   void f(int*) noexcept; // explicit specialization of #2
+//
+// Although there is no corresponding wording in the standard, this seems
+// to be the intended behavior given the definition of
+// 'deduction substitution loci' in [temp.deduct].

[clang] [clang] Create new warning group for deprecation of '-fno-relaxed-template-template-args' (PR #92324)

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

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


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


[clang] [clang] Create new warning group for deprecation of '-fno-relaxed-template-template-args' (PR #92324)

2024-05-15 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-driver

@llvm/pr-subscribers-clang

Author: Matheus Izvekov (mizvekov)


Changes

This allows the warning to be disabled in isolation, as it helps when treating 
them as errors.

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


5 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+2-1) 
- (modified) clang/include/clang/Basic/DiagnosticDriverKinds.td (+3) 
- (modified) clang/include/clang/Basic/DiagnosticGroups.td (+2) 
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+7-3) 
- (modified) clang/test/Driver/frelaxed-template-template-args.cpp (+3-1) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ae699ebfc6038..8f847a4376247 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -51,7 +51,8 @@ C++ Specific Potentially Breaking Changes
 - The behavior controlled by the `-frelaxed-template-template-args` flag is now
   on by default, and the flag is deprecated. Until the flag is finally removed,
   it's negative spelling can be used to obtain compatibility with previous
-  versions of clang.
+  versions of clang. The deprecation warning for the negative spelling can be
+  disabled with `-Wno-deprecated-no-relaxed-template-template-args`.
 
 - Clang now rejects pointer to member from parenthesized expression in 
unevaluated context such as ``decltype(&(foo::bar))``. (#GH40906).
 
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 9781fcaa4ff5e..9d97a75f696f6 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -436,6 +436,9 @@ def warn_drv_clang_unsupported : Warning<
   "the clang compiler does not support '%0'">;
 def warn_drv_deprecated_arg : Warning<
   "argument '%0' is deprecated%select{|, use '%2' instead}1">, 
InGroup;
+def warn_drv_deprecated_arg_no_relaxed_template_template_args : Warning<
+  "argument '-fno-relaxed-template-template-args' is deprecated">,
+  InGroup;
 def warn_drv_deprecated_custom : Warning<
   "argument '%0' is deprecated, %1">, InGroup;
 def warn_drv_assuming_mfloat_abi_is : Warning<
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 2beb1d45124b4..4cb4f3d999f7a 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -104,6 +104,7 @@ def EnumConversion : DiagGroup<"enum-conversion",
[EnumEnumConversion,
 EnumFloatConversion,
 EnumCompareConditional]>;
+def DeprecatedNoRelaxedTemplateTemplateArgs : 
DiagGroup<"deprecated-no-relaxed-template-template-args">;
 def ObjCSignedCharBoolImplicitIntConversion :
   DiagGroup<"objc-signed-char-bool-implicit-int-conversion">;
 def Shorten64To32 : DiagGroup<"shorten-64-to-32">;
@@ -228,6 +229,7 @@ def Deprecated : DiagGroup<"deprecated", 
[DeprecatedAnonEnumEnumConversion,
   DeprecatedLiteralOperator,
   DeprecatedPragma,
   DeprecatedRegister,
+  
DeprecatedNoRelaxedTemplateTemplateArgs,
   DeprecatedThisCapture,
   DeprecatedType,
   DeprecatedVolatile,
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 42feb1650574e..c3e6d563f3bd2 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7253,10 +7253,14 @@ void Clang::ConstructJob(Compilation , const 
JobAction ,
   if (Arg *A =
   Args.getLastArg(options::OPT_frelaxed_template_template_args,
   options::OPT_fno_relaxed_template_template_args)) {
-D.Diag(diag::warn_drv_deprecated_arg)
-<< A->getAsString(Args) << /*hasReplacement=*/false;
-if 
(A->getOption().matches(options::OPT_fno_relaxed_template_template_args))
+if (A->getOption().matches(
+options::OPT_fno_relaxed_template_template_args)) {
+  D.Diag(diag::warn_drv_deprecated_arg_no_relaxed_template_template_args);
   CmdArgs.push_back("-fno-relaxed-template-template-args");
+} else {
+  D.Diag(diag::warn_drv_deprecated_arg)
+  << A->getAsString(Args) << /*hasReplacement=*/false;
+}
   }
 
   // -fsized-deallocation is off by default, as it is an ABI-breaking change 
for
diff --git a/clang/test/Driver/frelaxed-template-template-args.cpp 
b/clang/test/Driver/frelaxed-template-template-args.cpp
index 57fc4e3da6e5d..7a7fd6f0bbc8f 100644
--- a/clang/test/Driver/frelaxed-template-template-args.cpp
+++ b/clang/test/Driver/frelaxed-template-template-args.cpp
@@ -1,7 +1,9 @@
 // RUN: %clang 

[clang] [clang] Create new warning group for deprecation of '-fno-relaxed-template-template-args' (PR #92324)

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

https://github.com/mizvekov created 
https://github.com/llvm/llvm-project/pull/92324

This allows the warning to be disabled in isolation, as it helps when treating 
them as errors.

>From 8b70909746ec85483b6d7f54fec4989956fb4c21 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Wed, 15 May 2024 19:41:03 -0300
Subject: [PATCH] [clang] Create new warning group for deprecation of
 '-fno-relaxed-template-template-args'

This allows this warning to be disabled in isolation.
This helps when treating warnings as errors.
---
 clang/docs/ReleaseNotes.rst   |  3 ++-
 clang/include/clang/Basic/DiagnosticDriverKinds.td|  3 +++
 clang/include/clang/Basic/DiagnosticGroups.td |  2 ++
 clang/lib/Driver/ToolChains/Clang.cpp | 10 +++---
 clang/test/Driver/frelaxed-template-template-args.cpp |  4 +++-
 5 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ae699ebfc6038..8f847a4376247 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -51,7 +51,8 @@ C++ Specific Potentially Breaking Changes
 - The behavior controlled by the `-frelaxed-template-template-args` flag is now
   on by default, and the flag is deprecated. Until the flag is finally removed,
   it's negative spelling can be used to obtain compatibility with previous
-  versions of clang.
+  versions of clang. The deprecation warning for the negative spelling can be
+  disabled with `-Wno-deprecated-no-relaxed-template-template-args`.
 
 - Clang now rejects pointer to member from parenthesized expression in 
unevaluated context such as ``decltype(&(foo::bar))``. (#GH40906).
 
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 9781fcaa4ff5e..9d97a75f696f6 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -436,6 +436,9 @@ def warn_drv_clang_unsupported : Warning<
   "the clang compiler does not support '%0'">;
 def warn_drv_deprecated_arg : Warning<
   "argument '%0' is deprecated%select{|, use '%2' instead}1">, 
InGroup;
+def warn_drv_deprecated_arg_no_relaxed_template_template_args : Warning<
+  "argument '-fno-relaxed-template-template-args' is deprecated">,
+  InGroup;
 def warn_drv_deprecated_custom : Warning<
   "argument '%0' is deprecated, %1">, InGroup;
 def warn_drv_assuming_mfloat_abi_is : Warning<
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 2beb1d45124b4..4cb4f3d999f7a 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -104,6 +104,7 @@ def EnumConversion : DiagGroup<"enum-conversion",
[EnumEnumConversion,
 EnumFloatConversion,
 EnumCompareConditional]>;
+def DeprecatedNoRelaxedTemplateTemplateArgs : 
DiagGroup<"deprecated-no-relaxed-template-template-args">;
 def ObjCSignedCharBoolImplicitIntConversion :
   DiagGroup<"objc-signed-char-bool-implicit-int-conversion">;
 def Shorten64To32 : DiagGroup<"shorten-64-to-32">;
@@ -228,6 +229,7 @@ def Deprecated : DiagGroup<"deprecated", 
[DeprecatedAnonEnumEnumConversion,
   DeprecatedLiteralOperator,
   DeprecatedPragma,
   DeprecatedRegister,
+  
DeprecatedNoRelaxedTemplateTemplateArgs,
   DeprecatedThisCapture,
   DeprecatedType,
   DeprecatedVolatile,
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 42feb1650574e..c3e6d563f3bd2 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7253,10 +7253,14 @@ void Clang::ConstructJob(Compilation , const 
JobAction ,
   if (Arg *A =
   Args.getLastArg(options::OPT_frelaxed_template_template_args,
   options::OPT_fno_relaxed_template_template_args)) {
-D.Diag(diag::warn_drv_deprecated_arg)
-<< A->getAsString(Args) << /*hasReplacement=*/false;
-if 
(A->getOption().matches(options::OPT_fno_relaxed_template_template_args))
+if (A->getOption().matches(
+options::OPT_fno_relaxed_template_template_args)) {
+  D.Diag(diag::warn_drv_deprecated_arg_no_relaxed_template_template_args);
   CmdArgs.push_back("-fno-relaxed-template-template-args");
+} else {
+  D.Diag(diag::warn_drv_deprecated_arg)
+  << A->getAsString(Args) << /*hasReplacement=*/false;
+}
   }
 
   // -fsized-deallocation is off by default, as it is an ABI-breaking change 
for
diff --git 

[clang] [flang] [flang] New -fdebug-unparse-with-modules option (PR #91660)

2024-05-15 Thread Peter Klausler via cfe-commits

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


[clang] e00a3cc - [flang] New -fdebug-unparse-with-modules option (#91660)

2024-05-15 Thread via cfe-commits

Author: Peter Klausler
Date: 2024-05-15T15:44:37-07:00
New Revision: e00a3ccf43563209b71c5b68f56d83f4052dca63

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

LOG: [flang] New -fdebug-unparse-with-modules option (#91660)

This option is a compilation action that parses a source file and
performs semantic analysis on it, like the existing -fdebug-unparse
option does. Its output, however, is preceded by the effective contents
of all of the non-intrinsic modules on which it depends but does not
define, transitively preceded by the closure of all of those modules'
dependencies.

The output from this option is therefore the analyzed parse tree for a
source file encapsulated with all of its non-intrinsic module
dependencies. This output may be useful for extracting code from large
applications for use as an attachment to a bug report, or as input to a
test case reduction tool for problem isolation.

Added: 
flang/test/Driver/unparse-with-modules.f90

Modified: 
clang/include/clang/Driver/Options.td
flang/include/flang/Frontend/FrontendActions.h
flang/include/flang/Frontend/FrontendOptions.h
flang/include/flang/Semantics/unparse-with-symbols.h
flang/lib/Frontend/CompilerInvocation.cpp
flang/lib/Frontend/FrontendActions.cpp
flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
flang/lib/Semantics/mod-file.cpp
flang/lib/Semantics/mod-file.h
flang/lib/Semantics/unparse-with-symbols.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c54eb543d6580..e579f1a0a3665 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -6647,7 +6647,9 @@ def fdebug_unparse : Flag<["-"], "fdebug-unparse">, 
Group,
   DocBrief<[{Run the parser and the semantic checks. Then unparse the
 parse-tree and output the generated Fortran source file.}]>;
 def fdebug_unparse_with_symbols : Flag<["-"], "fdebug-unparse-with-symbols">, 
Group,
-  HelpText<"Unparse and stop.">;
+  HelpText<"Unparse with symbols and stop.">;
+def fdebug_unparse_with_modules : Flag<["-"], "fdebug-unparse-with-modules">, 
Group,
+  HelpText<"Unparse with dependent modules and stop.">;
 def fdebug_dump_symbols : Flag<["-"], "fdebug-dump-symbols">, 
Group,
   HelpText<"Dump symbols after the semantic analysis">;
 def fdebug_dump_parse_tree : Flag<["-"], "fdebug-dump-parse-tree">, 
Group,

diff  --git a/flang/include/flang/Frontend/FrontendActions.h 
b/flang/include/flang/Frontend/FrontendActions.h
index e2e859f3a81bd..7823565eb815f 100644
--- a/flang/include/flang/Frontend/FrontendActions.h
+++ b/flang/include/flang/Frontend/FrontendActions.h
@@ -108,6 +108,10 @@ class DebugUnparseWithSymbolsAction : public 
PrescanAndSemaAction {
   void executeAction() override;
 };
 
+class DebugUnparseWithModulesAction : public PrescanAndSemaAction {
+  void executeAction() override;
+};
+
 class DebugUnparseAction : public PrescanAndSemaAction {
   void executeAction() override;
 };

diff  --git a/flang/include/flang/Frontend/FrontendOptions.h 
b/flang/include/flang/Frontend/FrontendOptions.h
index 06b1318f243b0..82ca99672ec61 100644
--- a/flang/include/flang/Frontend/FrontendOptions.h
+++ b/flang/include/flang/Frontend/FrontendOptions.h
@@ -63,6 +63,10 @@ enum ActionKind {
   /// Fortran source file
   DebugUnparseWithSymbols,
 
+  /// Parse, run semantics, and output a Fortran source file preceded
+  /// by all the necessary modules (transitively)
+  DebugUnparseWithModules,
+
   /// Parse, run semantics and then output symbols from semantics
   DebugDumpSymbols,
 

diff  --git a/flang/include/flang/Semantics/unparse-with-symbols.h 
b/flang/include/flang/Semantics/unparse-with-symbols.h
index d70110245e2b2..5e18b3fc3063d 100644
--- a/flang/include/flang/Semantics/unparse-with-symbols.h
+++ b/flang/include/flang/Semantics/unparse-with-symbols.h
@@ -21,8 +21,12 @@ struct Program;
 }
 
 namespace Fortran::semantics {
+class SemanticsContext;
 void UnparseWithSymbols(llvm::raw_ostream &, const parser::Program &,
 parser::Encoding encoding = parser::Encoding::UTF_8);
+void UnparseWithModules(llvm::raw_ostream &, SemanticsContext &,
+const parser::Program &,
+parser::Encoding encoding = parser::Encoding::UTF_8);
 }
 
 #endif // FORTRAN_SEMANTICS_UNPARSE_WITH_SYMBOLS_H_

diff  --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index db7fd37a2..e8a8c90045d92 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -488,6 +488,9 @@ static bool parseFrontendArgs(FrontendOptions , 
llvm::opt::ArgList ,
 case clang::driver::options::OPT_fdebug_unparse_with_symbols:
   opts.programAction = 

[clang] [Coverage] Handle array decomposition correctly (PR #88881)

2024-05-15 Thread Eli Friedman via cfe-commits

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


[clang] 5ff6c65 - [Coverage] Handle array decomposition correctly (#88881)

2024-05-15 Thread via cfe-commits

Author: Andrey Ali Khan Bolshakov
Date: 2024-05-15T15:40:03-07:00
New Revision: 5ff6c6542ac451daaed6c417e481e313165d3454

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

LOG: [Coverage] Handle array decomposition correctly (#1)

`ArrayInitLoopExpr` AST node has two occurences of its as-written
initializing expression in its subexpressions through a non-unique
`OpaqueValueExpr`. It causes double-visiting of the initializing
expression if not handled explicitly, as discussed in #85837.

Added: 
clang/test/CoverageMapping/decomposition.cpp

Modified: 
clang/lib/CodeGen/CoverageMappingGen.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index e46560029ab08..cc8ab7a5b4369 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -2177,6 +2177,10 @@ struct CounterCoverageMappingBuilder
 // propagate counts into them.
   }
 
+  void VisitArrayInitLoopExpr(const ArrayInitLoopExpr *AILE) {
+Visit(AILE->getCommonExpr()->getSourceExpr());
+  }
+
   void VisitPseudoObjectExpr(const PseudoObjectExpr *POE) {
 // Just visit syntatic expression as this is what users actually write.
 VisitStmt(POE->getSyntacticForm());

diff  --git a/clang/test/CoverageMapping/decomposition.cpp 
b/clang/test/CoverageMapping/decomposition.cpp
new file mode 100644
index 0..601ea630faeec
--- /dev/null
+++ b/clang/test/CoverageMapping/decomposition.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false -triple 
%itanium_abi_triple -fprofile-instrument=clang -fcoverage-mapping 
-dump-coverage-mapping -emit-llvm-only %s | FileCheck %s
+
+// CHECK-LABEL:   _Z19array_decompositioni:
+// CHECK-NEXT:  File 0, [[@LINE+6]]:32 -> {{[0-9]+}}:2 = #0
+// CHECK-NEXT:  File 0, [[@LINE+8]]:20 -> [[@LINE+8]]:25 = #0
+// CHECK-NEXT:  Branch,File 0, [[@LINE+7]]:20 -> [[@LINE+7]]:25 = #1, 
(#0 - #1)
+// CHECK-NEXT:  Gap,File 0, [[@LINE+6]]:27 -> [[@LINE+6]]:28 = #1
+// CHECK-NEXT:  File 0, [[@LINE+5]]:28 -> [[@LINE+5]]:29 = #1
+// CHECK-NEXT:  File 0, [[@LINE+4]]:32 -> [[@LINE+4]]:33 = (#0 - #1)
+int array_decomposition(int i) {
+  int a[] = {1, 2, 3};
+  int b[] = {4, 5, 6};
+  auto [x, y, z] = i > 0 ? a : b;
+  return x + y + z;
+}



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


[clang] [Coverage] Handle `CoroutineSuspendExpr` correctly (PR #88898)

2024-05-15 Thread Eli Friedman via cfe-commits

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


[clang] 050593f - [Coverage] Handle `CoroutineSuspendExpr` correctly (#88898)

2024-05-15 Thread via cfe-commits

Author: Andrey Ali Khan Bolshakov
Date: 2024-05-15T15:39:12-07:00
New Revision: 050593fc4f9a7f2b9450ee093c4638b8539315b7

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

LOG: [Coverage] Handle `CoroutineSuspendExpr` correctly (#88898)

This avoids visiting `co_await` or `co_yield` operand 5 times (it is
repeated under transformed awaiter subexpression, and under
`await_ready`, `await_suspend`, and `await_resume` generated call
subexpressions).

Added: 


Modified: 
clang/lib/CodeGen/CoverageMappingGen.cpp
clang/test/CoverageMapping/coroutine.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index ce2f39aeb0821..e46560029ab08 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -1439,6 +1439,10 @@ struct CounterCoverageMappingBuilder
 terminateRegion(S);
   }
 
+  void VisitCoroutineSuspendExpr(const CoroutineSuspendExpr *E) {
+Visit(E->getOperand());
+  }
+
   void VisitCXXThrowExpr(const CXXThrowExpr *E) {
 extendRegion(E);
 if (E->getSubExpr())

diff  --git a/clang/test/CoverageMapping/coroutine.cpp 
b/clang/test/CoverageMapping/coroutine.cpp
index 0105005d198a1..d322bc351a727 100644
--- a/clang/test/CoverageMapping/coroutine.cpp
+++ b/clang/test/CoverageMapping/coroutine.cpp
@@ -32,6 +32,7 @@ struct std::coroutine_traits {
 suspend_always final_suspend() noexcept;
 void unhandled_exception() noexcept;
 void return_value(int);
+suspend_always yield_value(int);
   };
 };
 
@@ -45,3 +46,21 @@ int f1(int x) {   // CHECK-NEXT: File 0, [[@LINE]]:15 -> 
[[@LINE+8]]:2 = #0
   }   // CHECK-NEXT: File 0, [[@LINE-2]]:10 -> [[@LINE]]:4 = 
(#0 - #1)
   co_return x;// CHECK-NEXT: Gap,File 0, [[@LINE-1]]:4 -> [[@LINE]]:3 
= #1
 } // CHECK-NEXT: File 0, [[@LINE-1]]:3 -> [[@LINE-1]]:14 = #1
+
+// CHECK-LABEL: _Z2f2i:
+// CHECK-NEXT: File 0, [[@LINE+1]]:15 -> [[@LINE+15]]:2 = #0
+int f2(int x) {
+// CHECK-NEXT: File 0, [[@LINE+5]]:13 -> [[@LINE+5]]:18 = #0
+// CHECK-NEXT: Branch,File 0, [[@LINE+4]]:13 -> [[@LINE+4]]:18 = #1, (#0 - #1)
+// CHECK-NEXT: Gap,File 0, [[@LINE+3]]:20 -> [[@LINE+3]]:21 = #1
+// CHECK-NEXT: File 0, [[@LINE+2]]:21 -> [[@LINE+2]]:37 = #1
+// CHECK-NEXT: File 0, [[@LINE+1]]:40 -> [[@LINE+1]]:56 = (#0 - #1)
+  co_await (x > 0 ? suspend_always{} : suspend_always{});
+// CHECK-NEXT: File 0, [[@LINE+5]]:12 -> [[@LINE+5]]:17 = #0
+// CHECK-NEXT: Branch,File 0, [[@LINE+4]]:12 -> [[@LINE+4]]:17 = #2, (#0 - #2)
+// CHECK-NEXT: Gap,File 0, [[@LINE+3]]:19 -> [[@LINE+3]]:20 = #2
+// CHECK-NEXT: File 0, [[@LINE+2]]:20 -> [[@LINE+2]]:21 = #2
+// CHECK-NEXT: File 0, [[@LINE+1]]:24 -> [[@LINE+1]]:25 = (#0 - #2)
+  co_yield x > 0 ? 1 : 2;
+  co_return 0;
+}



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


[clang] [libunwind] [libunwind][WebAssembly] Make libunwind compilable (PR #92192)

2024-05-15 Thread Heejin Ahn via cfe-commits

https://github.com/aheejin updated 
https://github.com/llvm/llvm-project/pull/92192

>From 95b9e56ac8bdd3b0bde08f63f64e35d47a61b784 Mon Sep 17 00:00:00 2001
From: Heejin Ahn 
Date: Tue, 14 May 2024 22:08:20 +
Subject: [PATCH 1/3] [libunwind][WebAssembly] Make libunwind compilable

This tries to make Wasm compilable in LLVM tree with CMake for
non-Emscripten platform.

This
- Adds `-D__USING_WASM_EXCEPTIONS__` when you compile with
  `-fwasm-exceptions` (like other EH options) in Clang
- Exclude `UnwindLevel1.c` when compiling with Wasm
- Changed some `__USING_WASM_EXCEPTIONS__` to `__wasm__`; they should be
  applied when compiling with Wasm w/o exceptions.
- Define some unused macros to make it compile
---
 clang/lib/Frontend/InitPreprocessor.cpp | 2 ++
 libunwind/cmake/config-ix.cmake | 1 +
 libunwind/include/__libunwind_config.h  | 4 
 libunwind/src/UnwindLevel1.c| 3 ++-
 libunwind/src/libunwind.cpp | 4 ++--
 5 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index c1d209466ffe5..3cc85ff502776 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -1006,6 +1006,8 @@ static void InitializePredefinedMacros(const TargetInfo 
,
   else if (LangOpts.hasDWARFExceptions() &&
(TI.getTriple().isThumb() || TI.getTriple().isARM()))
 Builder.defineMacro("__ARM_DWARF_EH__");
+  else if (LangOpts.hasWasmExceptions())
+Builder.defineMacro("__USING_WASM_EXCEPTIONS__");
 
   if (LangOpts.Deprecated)
 Builder.defineMacro("__DEPRECATED");
diff --git a/libunwind/cmake/config-ix.cmake b/libunwind/cmake/config-ix.cmake
index 126c872f0d489..d505ee1d346fa 100644
--- a/libunwind/cmake/config-ix.cmake
+++ b/libunwind/cmake/config-ix.cmake
@@ -109,6 +109,7 @@ check_cxx_compiler_flag(-nostdinc++ 
CXX_SUPPORTS_NOSTDINCXX_FLAG)
 check_symbol_exists(__arm__ "" LIBUNWIND_TARGET_ARM)
 check_symbol_exists(__USING_SJLJ_EXCEPTIONS__ "" 
LIBUNWIND_USES_SJLJ_EXCEPTIONS)
 check_symbol_exists(__ARM_DWARF_EH__ "" LIBUNWIND_USES_DWARF_EH)
+check_symbol_exists(__USING_WASM_EXCEPTIONS__ "" 
LIBUNWIND_USES_WASM_EXCEPTIONS)
 
 if(LIBUNWIND_TARGET_ARM AND NOT LIBUNWIND_USES_SJLJ_EXCEPTIONS AND NOT 
LIBUNWIND_USES_DWARF_EH)
   # This condition is copied from __libunwind_config.h
diff --git a/libunwind/include/__libunwind_config.h 
b/libunwind/include/__libunwind_config.h
index 8db336b2d727c..7d87831a80446 100644
--- a/libunwind/include/__libunwind_config.h
+++ b/libunwind/include/__libunwind_config.h
@@ -180,6 +180,10 @@
 #endif
 #define _LIBUNWIND_HIGHEST_DWARF_REGISTER  
\
   _LIBUNWIND_HIGHEST_DWARF_REGISTER_LOONGARCH
+#elif defined(__wasm__)
+// Unused
+# define _LIBUNWIND_CONTEXT_SIZE 0
+# define _LIBUNWIND_CURSOR_SIZE 0
 # else
 #  error "Unsupported architecture."
 # endif
diff --git a/libunwind/src/UnwindLevel1.c b/libunwind/src/UnwindLevel1.c
index 05d0f2cb0a0a7..48e7bc3b9e00e 100644
--- a/libunwind/src/UnwindLevel1.c
+++ b/libunwind/src/UnwindLevel1.c
@@ -31,7 +31,8 @@
 #include "libunwind_ext.h"
 #include "unwind.h"
 
-#if !defined(_LIBUNWIND_ARM_EHABI) && !defined(__USING_SJLJ_EXCEPTIONS__)
+#if !defined(_LIBUNWIND_ARM_EHABI) && !defined(__USING_SJLJ_EXCEPTIONS__) &&   
\
+!defined(__wasm__)
 
 #ifndef _LIBUNWIND_SUPPORT_SEH_UNWIND
 
diff --git a/libunwind/src/libunwind.cpp b/libunwind/src/libunwind.cpp
index 217dde9098637..7e5c6bd263e14 100644
--- a/libunwind/src/libunwind.cpp
+++ b/libunwind/src/libunwind.cpp
@@ -26,7 +26,7 @@
 #include 
 #endif
 
-#if !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__USING_WASM_EXCEPTIONS__)
+#if !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__wasm__)
 #include "AddressSpace.hpp"
 #include "UnwindCursor.hpp"
 
@@ -348,7 +348,7 @@ void __unw_remove_dynamic_eh_frame_section(unw_word_t 
eh_frame_start) {
 
 #endif // defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
 #endif // !defined(__USING_SJLJ_EXCEPTIONS__) &&
-   // !defined(__USING_WASM_EXCEPTIONS__)
+   // !defined(__wasm__)
 
 #ifdef __APPLE__
 

>From 496e9b1652a2799c77626082a337803f9c907a3a Mon Sep 17 00:00:00 2001
From: Heejin Ahn 
Date: Tue, 14 May 2024 23:48:37 +
Subject: [PATCH 2/3] clang-format

---
 libunwind/include/__libunwind_config.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libunwind/include/__libunwind_config.h 
b/libunwind/include/__libunwind_config.h
index 7d87831a80446..028b9e3baa806 100644
--- a/libunwind/include/__libunwind_config.h
+++ b/libunwind/include/__libunwind_config.h
@@ -182,8 +182,8 @@
   _LIBUNWIND_HIGHEST_DWARF_REGISTER_LOONGARCH
 #elif defined(__wasm__)
 // Unused
-# define _LIBUNWIND_CONTEXT_SIZE 0
-# define _LIBUNWIND_CURSOR_SIZE 0
+#define _LIBUNWIND_CONTEXT_SIZE 0
+#define _LIBUNWIND_CURSOR_SIZE 0
 # else
 #  error "Unsupported architecture."
 # endif

>From 86179cc37229612c4ee0011a4db8e738587b95db Mon Sep 17 00:00:00 2001
From: 

[clang] [libunwind] [libunwind][WebAssembly] Make libunwind compilable (PR #92192)

2024-05-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Heejin Ahn (aheejin)


Changes

This tries to make Wasm compilable in LLVM tree with CMake for non-Emscripten 
platform.

This
- Adds `-D__USING_WASM_EXCEPTIONS__` when you compile with `-fwasm-exceptions` 
(like other EH options) in Clang
- Exclude `UnwindLevel1.c`, `UnwindRegistersSave.S`, and 
`UnwindRegistersRestore.S` when compiling with Wasm
- Changed some `__USING_WASM_EXCEPTIONS__` to `__wasm__`; they should be 
applied when compiling with Wasm w/o exceptions.
- Define some unused macros to make it compile

Fixes #72771.

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


7 Files Affected:

- (modified) clang/lib/Frontend/InitPreprocessor.cpp (+2) 
- (modified) libunwind/cmake/config-ix.cmake (+1) 
- (modified) libunwind/include/__libunwind_config.h (+4) 
- (modified) libunwind/src/UnwindLevel1.c (+2-1) 
- (modified) libunwind/src/UnwindRegistersRestore.S (+2-2) 
- (modified) libunwind/src/UnwindRegistersSave.S (+2-2) 
- (modified) libunwind/src/libunwind.cpp (+2-2) 


``diff
diff --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index c1d209466ffe5..3cc85ff502776 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -1006,6 +1006,8 @@ static void InitializePredefinedMacros(const TargetInfo 
,
   else if (LangOpts.hasDWARFExceptions() &&
(TI.getTriple().isThumb() || TI.getTriple().isARM()))
 Builder.defineMacro("__ARM_DWARF_EH__");
+  else if (LangOpts.hasWasmExceptions())
+Builder.defineMacro("__USING_WASM_EXCEPTIONS__");
 
   if (LangOpts.Deprecated)
 Builder.defineMacro("__DEPRECATED");
diff --git a/libunwind/cmake/config-ix.cmake b/libunwind/cmake/config-ix.cmake
index 126c872f0d489..d505ee1d346fa 100644
--- a/libunwind/cmake/config-ix.cmake
+++ b/libunwind/cmake/config-ix.cmake
@@ -109,6 +109,7 @@ check_cxx_compiler_flag(-nostdinc++ 
CXX_SUPPORTS_NOSTDINCXX_FLAG)
 check_symbol_exists(__arm__ "" LIBUNWIND_TARGET_ARM)
 check_symbol_exists(__USING_SJLJ_EXCEPTIONS__ "" 
LIBUNWIND_USES_SJLJ_EXCEPTIONS)
 check_symbol_exists(__ARM_DWARF_EH__ "" LIBUNWIND_USES_DWARF_EH)
+check_symbol_exists(__USING_WASM_EXCEPTIONS__ "" 
LIBUNWIND_USES_WASM_EXCEPTIONS)
 
 if(LIBUNWIND_TARGET_ARM AND NOT LIBUNWIND_USES_SJLJ_EXCEPTIONS AND NOT 
LIBUNWIND_USES_DWARF_EH)
   # This condition is copied from __libunwind_config.h
diff --git a/libunwind/include/__libunwind_config.h 
b/libunwind/include/__libunwind_config.h
index 8db336b2d727c..028b9e3baa806 100644
--- a/libunwind/include/__libunwind_config.h
+++ b/libunwind/include/__libunwind_config.h
@@ -180,6 +180,10 @@
 #endif
 #define _LIBUNWIND_HIGHEST_DWARF_REGISTER  
\
   _LIBUNWIND_HIGHEST_DWARF_REGISTER_LOONGARCH
+#elif defined(__wasm__)
+// Unused
+#define _LIBUNWIND_CONTEXT_SIZE 0
+#define _LIBUNWIND_CURSOR_SIZE 0
 # else
 #  error "Unsupported architecture."
 # endif
diff --git a/libunwind/src/UnwindLevel1.c b/libunwind/src/UnwindLevel1.c
index 05d0f2cb0a0a7..48e7bc3b9e00e 100644
--- a/libunwind/src/UnwindLevel1.c
+++ b/libunwind/src/UnwindLevel1.c
@@ -31,7 +31,8 @@
 #include "libunwind_ext.h"
 #include "unwind.h"
 
-#if !defined(_LIBUNWIND_ARM_EHABI) && !defined(__USING_SJLJ_EXCEPTIONS__)
+#if !defined(_LIBUNWIND_ARM_EHABI) && !defined(__USING_SJLJ_EXCEPTIONS__) &&   
\
+!defined(__wasm__)
 
 #ifndef _LIBUNWIND_SUPPORT_SEH_UNWIND
 
diff --git a/libunwind/src/UnwindRegistersRestore.S 
b/libunwind/src/UnwindRegistersRestore.S
index 42c2488fc7cf7..d8552babfe081 100644
--- a/libunwind/src/UnwindRegistersRestore.S
+++ b/libunwind/src/UnwindRegistersRestore.S
@@ -20,7 +20,7 @@
   .text
 #endif
 
-#if !defined(__USING_SJLJ_EXCEPTIONS__)
+#if !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__wasm__)
 
 #if defined(__i386__)
 DEFINE_LIBUNWIND_FUNCTION(__libunwind_Registers_x86_jumpto)
@@ -1232,7 +1232,7 @@ 
DEFINE_LIBUNWIND_FUNCTION(_ZN9libunwind19Registers_loongarch6jumptoEv)
 
 #endif
 
-#endif /* !defined(__USING_SJLJ_EXCEPTIONS__) */
+#endif /* !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__wasm) */
 
 NO_EXEC_STACK_DIRECTIVE
 
diff --git a/libunwind/src/UnwindRegistersSave.S 
b/libunwind/src/UnwindRegistersSave.S
index 19a0e87d683ce..5bf6055fe4147 100644
--- a/libunwind/src/UnwindRegistersSave.S
+++ b/libunwind/src/UnwindRegistersSave.S
@@ -20,7 +20,7 @@
 .text
 #endif
 
-#if !defined(__USING_SJLJ_EXCEPTIONS__)
+#if !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__wasm__)
 
 #if defined(__i386__)
 
@@ -1177,6 +1177,6 @@ DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext)
 
   WEAK_ALIAS(__unw_getcontext, unw_getcontext)
 
-#endif /* !defined(__USING_SJLJ_EXCEPTIONS__) */
+#endif /* !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__wasm__) */
 
 NO_EXEC_STACK_DIRECTIVE
diff --git a/libunwind/src/libunwind.cpp b/libunwind/src/libunwind.cpp
index 217dde9098637..7e5c6bd263e14 100644
--- a/libunwind/src/libunwind.cpp
+++ 

[clang] [libunwind] [libunwind][WebAssembly] Make libunwind compilable (PR #92192)

2024-05-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-libunwind

Author: Heejin Ahn (aheejin)


Changes

This tries to make Wasm compilable in LLVM tree with CMake for non-Emscripten 
platform.

This
- Adds `-D__USING_WASM_EXCEPTIONS__` when you compile with `-fwasm-exceptions` 
(like other EH options) in Clang
- Exclude `UnwindLevel1.c`, `UnwindRegistersSave.S`, and 
`UnwindRegistersRestore.S` when compiling with Wasm
- Changed some `__USING_WASM_EXCEPTIONS__` to `__wasm__`; they should be 
applied when compiling with Wasm w/o exceptions.
- Define some unused macros to make it compile

Fixes #72771.

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


7 Files Affected:

- (modified) clang/lib/Frontend/InitPreprocessor.cpp (+2) 
- (modified) libunwind/cmake/config-ix.cmake (+1) 
- (modified) libunwind/include/__libunwind_config.h (+4) 
- (modified) libunwind/src/UnwindLevel1.c (+2-1) 
- (modified) libunwind/src/UnwindRegistersRestore.S (+2-2) 
- (modified) libunwind/src/UnwindRegistersSave.S (+2-2) 
- (modified) libunwind/src/libunwind.cpp (+2-2) 


``diff
diff --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index c1d209466ffe5..3cc85ff502776 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -1006,6 +1006,8 @@ static void InitializePredefinedMacros(const TargetInfo 
,
   else if (LangOpts.hasDWARFExceptions() &&
(TI.getTriple().isThumb() || TI.getTriple().isARM()))
 Builder.defineMacro("__ARM_DWARF_EH__");
+  else if (LangOpts.hasWasmExceptions())
+Builder.defineMacro("__USING_WASM_EXCEPTIONS__");
 
   if (LangOpts.Deprecated)
 Builder.defineMacro("__DEPRECATED");
diff --git a/libunwind/cmake/config-ix.cmake b/libunwind/cmake/config-ix.cmake
index 126c872f0d489..d505ee1d346fa 100644
--- a/libunwind/cmake/config-ix.cmake
+++ b/libunwind/cmake/config-ix.cmake
@@ -109,6 +109,7 @@ check_cxx_compiler_flag(-nostdinc++ 
CXX_SUPPORTS_NOSTDINCXX_FLAG)
 check_symbol_exists(__arm__ "" LIBUNWIND_TARGET_ARM)
 check_symbol_exists(__USING_SJLJ_EXCEPTIONS__ "" 
LIBUNWIND_USES_SJLJ_EXCEPTIONS)
 check_symbol_exists(__ARM_DWARF_EH__ "" LIBUNWIND_USES_DWARF_EH)
+check_symbol_exists(__USING_WASM_EXCEPTIONS__ "" 
LIBUNWIND_USES_WASM_EXCEPTIONS)
 
 if(LIBUNWIND_TARGET_ARM AND NOT LIBUNWIND_USES_SJLJ_EXCEPTIONS AND NOT 
LIBUNWIND_USES_DWARF_EH)
   # This condition is copied from __libunwind_config.h
diff --git a/libunwind/include/__libunwind_config.h 
b/libunwind/include/__libunwind_config.h
index 8db336b2d727c..028b9e3baa806 100644
--- a/libunwind/include/__libunwind_config.h
+++ b/libunwind/include/__libunwind_config.h
@@ -180,6 +180,10 @@
 #endif
 #define _LIBUNWIND_HIGHEST_DWARF_REGISTER  
\
   _LIBUNWIND_HIGHEST_DWARF_REGISTER_LOONGARCH
+#elif defined(__wasm__)
+// Unused
+#define _LIBUNWIND_CONTEXT_SIZE 0
+#define _LIBUNWIND_CURSOR_SIZE 0
 # else
 #  error "Unsupported architecture."
 # endif
diff --git a/libunwind/src/UnwindLevel1.c b/libunwind/src/UnwindLevel1.c
index 05d0f2cb0a0a7..48e7bc3b9e00e 100644
--- a/libunwind/src/UnwindLevel1.c
+++ b/libunwind/src/UnwindLevel1.c
@@ -31,7 +31,8 @@
 #include "libunwind_ext.h"
 #include "unwind.h"
 
-#if !defined(_LIBUNWIND_ARM_EHABI) && !defined(__USING_SJLJ_EXCEPTIONS__)
+#if !defined(_LIBUNWIND_ARM_EHABI) && !defined(__USING_SJLJ_EXCEPTIONS__) &&   
\
+!defined(__wasm__)
 
 #ifndef _LIBUNWIND_SUPPORT_SEH_UNWIND
 
diff --git a/libunwind/src/UnwindRegistersRestore.S 
b/libunwind/src/UnwindRegistersRestore.S
index 42c2488fc7cf7..d8552babfe081 100644
--- a/libunwind/src/UnwindRegistersRestore.S
+++ b/libunwind/src/UnwindRegistersRestore.S
@@ -20,7 +20,7 @@
   .text
 #endif
 
-#if !defined(__USING_SJLJ_EXCEPTIONS__)
+#if !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__wasm__)
 
 #if defined(__i386__)
 DEFINE_LIBUNWIND_FUNCTION(__libunwind_Registers_x86_jumpto)
@@ -1232,7 +1232,7 @@ 
DEFINE_LIBUNWIND_FUNCTION(_ZN9libunwind19Registers_loongarch6jumptoEv)
 
 #endif
 
-#endif /* !defined(__USING_SJLJ_EXCEPTIONS__) */
+#endif /* !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__wasm) */
 
 NO_EXEC_STACK_DIRECTIVE
 
diff --git a/libunwind/src/UnwindRegistersSave.S 
b/libunwind/src/UnwindRegistersSave.S
index 19a0e87d683ce..5bf6055fe4147 100644
--- a/libunwind/src/UnwindRegistersSave.S
+++ b/libunwind/src/UnwindRegistersSave.S
@@ -20,7 +20,7 @@
 .text
 #endif
 
-#if !defined(__USING_SJLJ_EXCEPTIONS__)
+#if !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__wasm__)
 
 #if defined(__i386__)
 
@@ -1177,6 +1177,6 @@ DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext)
 
   WEAK_ALIAS(__unw_getcontext, unw_getcontext)
 
-#endif /* !defined(__USING_SJLJ_EXCEPTIONS__) */
+#endif /* !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__wasm__) */
 
 NO_EXEC_STACK_DIRECTIVE
diff --git a/libunwind/src/libunwind.cpp b/libunwind/src/libunwind.cpp
index 217dde9098637..7e5c6bd263e14 100644
--- a/libunwind/src/libunwind.cpp
+++ 

[clang] [libunwind] [libunwind][WebAssembly] Make libunwind compilable (PR #92192)

2024-05-15 Thread Heejin Ahn via cfe-commits

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


[clang] [libunwind] [libunwind][WebAssembly] Make libunwind compilable (PR #92192)

2024-05-15 Thread Heejin Ahn via cfe-commits

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


[clang] [libunwind] [libunwind][WebAssembly] Make libunwind compilable (PR #92192)

2024-05-15 Thread Heejin Ahn via cfe-commits

https://github.com/aheejin updated 
https://github.com/llvm/llvm-project/pull/92192

>From 95b9e56ac8bdd3b0bde08f63f64e35d47a61b784 Mon Sep 17 00:00:00 2001
From: Heejin Ahn 
Date: Tue, 14 May 2024 22:08:20 +
Subject: [PATCH 1/3] [libunwind][WebAssembly] Make libunwind compilable

This tries to make Wasm compilable in LLVM tree with CMake for
non-Emscripten platform.

This
- Adds `-D__USING_WASM_EXCEPTIONS__` when you compile with
  `-fwasm-exceptions` (like other EH options) in Clang
- Exclude `UnwindLevel1.c` when compiling with Wasm
- Changed some `__USING_WASM_EXCEPTIONS__` to `__wasm__`; they should be
  applied when compiling with Wasm w/o exceptions.
- Define some unused macros to make it compile
---
 clang/lib/Frontend/InitPreprocessor.cpp | 2 ++
 libunwind/cmake/config-ix.cmake | 1 +
 libunwind/include/__libunwind_config.h  | 4 
 libunwind/src/UnwindLevel1.c| 3 ++-
 libunwind/src/libunwind.cpp | 4 ++--
 5 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index c1d209466ffe5..3cc85ff502776 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -1006,6 +1006,8 @@ static void InitializePredefinedMacros(const TargetInfo 
,
   else if (LangOpts.hasDWARFExceptions() &&
(TI.getTriple().isThumb() || TI.getTriple().isARM()))
 Builder.defineMacro("__ARM_DWARF_EH__");
+  else if (LangOpts.hasWasmExceptions())
+Builder.defineMacro("__USING_WASM_EXCEPTIONS__");
 
   if (LangOpts.Deprecated)
 Builder.defineMacro("__DEPRECATED");
diff --git a/libunwind/cmake/config-ix.cmake b/libunwind/cmake/config-ix.cmake
index 126c872f0d489..d505ee1d346fa 100644
--- a/libunwind/cmake/config-ix.cmake
+++ b/libunwind/cmake/config-ix.cmake
@@ -109,6 +109,7 @@ check_cxx_compiler_flag(-nostdinc++ 
CXX_SUPPORTS_NOSTDINCXX_FLAG)
 check_symbol_exists(__arm__ "" LIBUNWIND_TARGET_ARM)
 check_symbol_exists(__USING_SJLJ_EXCEPTIONS__ "" 
LIBUNWIND_USES_SJLJ_EXCEPTIONS)
 check_symbol_exists(__ARM_DWARF_EH__ "" LIBUNWIND_USES_DWARF_EH)
+check_symbol_exists(__USING_WASM_EXCEPTIONS__ "" 
LIBUNWIND_USES_WASM_EXCEPTIONS)
 
 if(LIBUNWIND_TARGET_ARM AND NOT LIBUNWIND_USES_SJLJ_EXCEPTIONS AND NOT 
LIBUNWIND_USES_DWARF_EH)
   # This condition is copied from __libunwind_config.h
diff --git a/libunwind/include/__libunwind_config.h 
b/libunwind/include/__libunwind_config.h
index 8db336b2d727c..7d87831a80446 100644
--- a/libunwind/include/__libunwind_config.h
+++ b/libunwind/include/__libunwind_config.h
@@ -180,6 +180,10 @@
 #endif
 #define _LIBUNWIND_HIGHEST_DWARF_REGISTER  
\
   _LIBUNWIND_HIGHEST_DWARF_REGISTER_LOONGARCH
+#elif defined(__wasm__)
+// Unused
+# define _LIBUNWIND_CONTEXT_SIZE 0
+# define _LIBUNWIND_CURSOR_SIZE 0
 # else
 #  error "Unsupported architecture."
 # endif
diff --git a/libunwind/src/UnwindLevel1.c b/libunwind/src/UnwindLevel1.c
index 05d0f2cb0a0a7..48e7bc3b9e00e 100644
--- a/libunwind/src/UnwindLevel1.c
+++ b/libunwind/src/UnwindLevel1.c
@@ -31,7 +31,8 @@
 #include "libunwind_ext.h"
 #include "unwind.h"
 
-#if !defined(_LIBUNWIND_ARM_EHABI) && !defined(__USING_SJLJ_EXCEPTIONS__)
+#if !defined(_LIBUNWIND_ARM_EHABI) && !defined(__USING_SJLJ_EXCEPTIONS__) &&   
\
+!defined(__wasm__)
 
 #ifndef _LIBUNWIND_SUPPORT_SEH_UNWIND
 
diff --git a/libunwind/src/libunwind.cpp b/libunwind/src/libunwind.cpp
index 217dde9098637..7e5c6bd263e14 100644
--- a/libunwind/src/libunwind.cpp
+++ b/libunwind/src/libunwind.cpp
@@ -26,7 +26,7 @@
 #include 
 #endif
 
-#if !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__USING_WASM_EXCEPTIONS__)
+#if !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__wasm__)
 #include "AddressSpace.hpp"
 #include "UnwindCursor.hpp"
 
@@ -348,7 +348,7 @@ void __unw_remove_dynamic_eh_frame_section(unw_word_t 
eh_frame_start) {
 
 #endif // defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
 #endif // !defined(__USING_SJLJ_EXCEPTIONS__) &&
-   // !defined(__USING_WASM_EXCEPTIONS__)
+   // !defined(__wasm__)
 
 #ifdef __APPLE__
 

>From 496e9b1652a2799c77626082a337803f9c907a3a Mon Sep 17 00:00:00 2001
From: Heejin Ahn 
Date: Tue, 14 May 2024 23:48:37 +
Subject: [PATCH 2/3] clang-format

---
 libunwind/include/__libunwind_config.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libunwind/include/__libunwind_config.h 
b/libunwind/include/__libunwind_config.h
index 7d87831a80446..028b9e3baa806 100644
--- a/libunwind/include/__libunwind_config.h
+++ b/libunwind/include/__libunwind_config.h
@@ -182,8 +182,8 @@
   _LIBUNWIND_HIGHEST_DWARF_REGISTER_LOONGARCH
 #elif defined(__wasm__)
 // Unused
-# define _LIBUNWIND_CONTEXT_SIZE 0
-# define _LIBUNWIND_CURSOR_SIZE 0
+#define _LIBUNWIND_CONTEXT_SIZE 0
+#define _LIBUNWIND_CURSOR_SIZE 0
 # else
 #  error "Unsupported architecture."
 # endif

>From 86179cc37229612c4ee0011a4db8e738587b95db Mon Sep 17 00:00:00 2001
From: 

[clang] [Coverage] Handle array decomposition correctly (PR #88881)

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

bolshakov-a wrote:

Could you please merge both of these?

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


[clang] [HLSL] support packoffset in clang codeGen (PR #91999)

2024-05-15 Thread Chris B via cfe-commits

https://github.com/llvm-beanz commented:

I'm a little concerned about the strategy here. LLVM generally doesn't 
explicitly capture padding it relies on the data layout rules to capture that.

If this is the approach we're going with you can't put any vectors or matrices 
into the cbuffer structure type and we need to account for all the padding 
bytes explicitly.

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


[clang] [Safe Buffers] Serialize unsafe_buffer_usage pragmas (PR #92031)

2024-05-15 Thread Dana Jansens via cfe-commits

danakj wrote:

Thanks for the explanation :)

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


[clang] [HLSL] support packoffset in clang codeGen (PR #91999)

2024-05-15 Thread Chris B via cfe-commits


@@ -5671,6 +5671,54 @@ HLSLBufferDecl 
*HLSLBufferDecl::CreateDeserialized(ASTContext ,
 SourceLocation(), SourceLocation());
 }
 
+static uint64_t calculateLegacyCbufferAlign(const ASTContext ,
+QualType T) {
+  if (T->isAggregateType())
+return 128;
+  else if (const VectorType *VT = T->getAs())
+return Context.getTypeSize(VT->getElementType());
+  else
+return Context.getTypeSize(T);
+}
+
+unsigned HLSLBufferDecl::calculateLegacyCbufferSize(const ASTContext ,

llvm-beanz wrote:

This function seems like something we should be able to have some unit tests 
of. Can we write unit tests that exercise this through a bunch of the 
interesting variations to ensure it does the right thing?

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


[clang] [Clang][Sema] Don't build CXXDependentScopeMemberExprs for potentially implicit class member access expressions (PR #92318)

2024-05-15 Thread Krystian Stasiowski via cfe-commits

https://github.com/sdkrystian updated 
https://github.com/llvm/llvm-project/pull/92318

>From a5ed54f967e4a15a80f41ee648f79e77202906d8 Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski 
Date: Wed, 15 May 2024 16:13:03 -0400
Subject: [PATCH 1/2] [Clang][Sema] Don't build CXXDependentScopeMemberExprs
 for potentially implicit class member access expressions

---
 clang/include/clang/Sema/Sema.h   | 11 +--
 clang/lib/Sema/SemaCXXScopeSpec.cpp   |  8 ++
 clang/lib/Sema/SemaExpr.cpp   | 31 ++
 clang/lib/Sema/SemaTemplate.cpp   | 98 ++-
 clang/lib/Sema/TreeTransform.h|  6 +-
 .../class.mfct/class.mfct.non-static/p3.cpp   | 91 -
 ...ms-function-specialization-class-scope.cpp | 52 ++
 .../ms-lookup-template-base-classes.cpp   | 12 +--
 .../ASTMatchers/ASTMatchersNodeTest.cpp   |  6 +-
 9 files changed, 206 insertions(+), 109 deletions(-)

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 6a414aa57f32b..779e3134b3067 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -5366,11 +5366,9 @@ class Sema final : public SemaBase {
   bool UseArgumentDependentLookup(const CXXScopeSpec , const LookupResult 
,
   bool HasTrailingLParen);
 
-  ExprResult
-  BuildQualifiedDeclarationNameExpr(CXXScopeSpec ,
-const DeclarationNameInfo ,
-bool IsAddressOfOperand, const Scope *S,
-TypeSourceInfo **RecoveryTSI = nullptr);
+  ExprResult BuildQualifiedDeclarationNameExpr(
+  CXXScopeSpec , const DeclarationNameInfo ,
+  bool IsAddressOfOperand, TypeSourceInfo **RecoveryTSI = nullptr);
 
   ExprResult BuildDeclarationNameExpr(const CXXScopeSpec , LookupResult ,
   bool NeedsADL,
@@ -8982,7 +8980,8 @@ class Sema final : public SemaBase {
   ExprResult
   BuildQualifiedTemplateIdExpr(CXXScopeSpec , SourceLocation TemplateKWLoc,
const DeclarationNameInfo ,
-   const TemplateArgumentListInfo *TemplateArgs);
+   const TemplateArgumentListInfo *TemplateArgs,
+   bool IsAddressOfOperand);
 
   TemplateNameKind ActOnTemplateName(Scope *S, CXXScopeSpec ,
  SourceLocation TemplateKWLoc,
diff --git a/clang/lib/Sema/SemaCXXScopeSpec.cpp 
b/clang/lib/Sema/SemaCXXScopeSpec.cpp
index fca5bd131bbc0..c405fbc0aa421 100644
--- a/clang/lib/Sema/SemaCXXScopeSpec.cpp
+++ b/clang/lib/Sema/SemaCXXScopeSpec.cpp
@@ -796,6 +796,14 @@ bool Sema::BuildCXXNestedNameSpecifier(Scope *S, 
NestedNameSpecInfo ,
 Diag(IdInfo.IdentifierLoc,
  diag::ext_undeclared_unqual_id_with_dependent_base)
 << IdInfo.Identifier << ContainingClass;
+// Fake up a nested-name-specifier that starts with the
+// injected-class-name of the enclosing class.
+QualType T = Context.getTypeDeclType(ContainingClass);
+TypeLocBuilder TLB;
+TLB.pushTrivial(Context, T, IdInfo.IdentifierLoc);
+SS.Extend(Context, /*TemplateKWLoc=*/SourceLocation(),
+  TLB.getTypeLocInContext(Context, T), IdInfo.IdentifierLoc);
+// Add the identifier to form a dependent name.
 SS.Extend(Context, IdInfo.Identifier, IdInfo.IdentifierLoc,
   IdInfo.CCLoc);
 return false;
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index ec84798e4ce60..ad6cfb632fd94 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -2946,26 +2946,14 @@ Sema::ActOnIdExpression(Scope *S, CXXScopeSpec ,
 /// this path.
 ExprResult Sema::BuildQualifiedDeclarationNameExpr(
 CXXScopeSpec , const DeclarationNameInfo ,
-bool IsAddressOfOperand, const Scope *S, TypeSourceInfo **RecoveryTSI) {
-  if (NameInfo.getName().isDependentName())
-return BuildDependentDeclRefExpr(SS, /*TemplateKWLoc=*/SourceLocation(),
- NameInfo, /*TemplateArgs=*/nullptr);
-
-  DeclContext *DC = computeDeclContext(SS, false);
-  if (!DC)
-return BuildDependentDeclRefExpr(SS, /*TemplateKWLoc=*/SourceLocation(),
- NameInfo, /*TemplateArgs=*/nullptr);
-
-  if (RequireCompleteDeclContext(SS, DC))
-return ExprError();
-
+bool IsAddressOfOperand, TypeSourceInfo **RecoveryTSI) {
   LookupResult R(*this, NameInfo, LookupOrdinaryName);
-  LookupQualifiedName(R, DC);
+  LookupParsedName(R, /*S=*/nullptr, , /*ObjectType=*/QualType());
 
   if (R.isAmbiguous())
 return ExprError();
 
-  if (R.getResultKind() == LookupResult::NotFoundInCurrentInstantiation)
+  if (R.wasNotFoundInCurrentInstantiation() || SS.isInvalid())
 return BuildDependentDeclRefExpr(SS, /*TemplateKWLoc=*/SourceLocation(),
   

[clang] HLSL availability diagnostics design doc (PR #92207)

2024-05-15 Thread Xiang Li via cfe-commits


@@ -0,0 +1,53 @@
+=
+HLSL Availability Diagnostics
+=
+
+.. contents::
+   :local:
+
+Introduction
+
+
+HLSL availability diagnostics emits errors or warning when unavailable shader 
APIs are used. Unavailable shader APIs are APIs that are exposed in HLSL code 
but are not available in the target shader stage or shader model version.

python3kgae wrote:

Could we add some hlsl examples?

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


[clang] HLSL availability diagnostics design doc (PR #92207)

2024-05-15 Thread Cooper Partin via cfe-commits

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

This looks good to me.

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


[clang] [clang] Enable C++17 relaxed template template argument matching by default (PR #89807)

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

erichkeane wrote:

Great, I agree that is the right way forward.  A more complicated flag like 
that might be cool someday, but not something we need today.

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


[clang] HLSL availability diagnostics design doc (PR #92207)

2024-05-15 Thread Helena Kotas via cfe-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/92207

>From 3df0ba0fd2171a0115427bc6ba5e3f8e84831747 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Tue, 14 May 2024 19:06:59 -0700
Subject: [PATCH 1/4] HLSL Availability Diagnostics Design Document - initial
 commit

---
 clang/docs/HLSL/AvailabilityDiagnostics.rst | 50 +
 clang/docs/HLSL/HLSLDocs.rst|  1 +
 2 files changed, 51 insertions(+)
 create mode 100644 clang/docs/HLSL/AvailabilityDiagnostics.rst

diff --git a/clang/docs/HLSL/AvailabilityDiagnostics.rst 
b/clang/docs/HLSL/AvailabilityDiagnostics.rst
new file mode 100644
index 0..218047495e6b9
--- /dev/null
+++ b/clang/docs/HLSL/AvailabilityDiagnostics.rst
@@ -0,0 +1,50 @@
+=
+HLSL Availability Diagnostics
+=
+
+.. contents::
+   :local:
+
+Introduction
+
+
+HLSL availability diagnostics emits errors or warning when unavailable shader 
APIs are used. Unavailable shader APIs are APIs that are exposed in HLSL code 
but are not available in the target shader stage or shader model version.
+
+There are three modes of HLSL availability diagnostic:
+1. **Default mode** - compiler emits an error when an unavailable shader API 
is found in a code that is reachable from the shader entry point function or 
from an exported library function (when compiling a shader library)
+2. **Relaxed mode** - same as default mode except the compiler emits a 
warning. This mode is enabled by ``-Wno-error=hlsl-availability``.
+3. **Strict mode** - compiler emits an error when when an unavailable API is 
found in parsed code regardless of whether it can be reached from the shader 
entry point or exported functions, or not. This mode is enabled by 
``-fhlsl-strict-diagnostics``.
+
+Implementation Details
+==
+
+Environment Parameter
+-
+
+In order to encode API availability based on the shader model version and 
shader model stage a new ``environment`` parameter was added to the existing 
Clang ``availability`` attribute. 
+
+The values allowed for this parameter are a subset of values allowed as the 
``llvm::Triple`` environment component. If the environment parameters is 
present, the declared availability attribute applies only to targets with the 
same platform and environment.
+
+Default and Relaxed Diagnostic Modes
+
+
+This mode is implemeted in ``DiagnoseHLSLAvailability`` class in 
``SemaHLSL.cpp`` and it is invoked after the whole translation unit is parsed 
(from ``Sema::ActOnEndOfTranslationUnit``). The implementation iterates over 
all shader entry points and exported library functions in the translation unit 
and performs an AST traversal of each function body.
+
+When a reference to another function is found and it has a body, the AST of 
the referenced function is also scanned. This chain of AST traversals will 
reach all of the code that is reachable from the initial shader entry point or 
exported library function.
+
+All shader APIs have an availability attribute that specifies the shader model 
version (and environment, if applicable) when this API was first 
introduced.When a reference to a function without a definition is found and it 
has an availability attribute, the version of the attribute is checked against 
the target shader model version and shader stage (if shader stage context is 
known), and an appropriate diagnostic is generated as needed.
+
+All shader entry functions have ``HLSLShaderAttr`` attribute that specifies 
what type of shader this function represents. However, for exported library 
functions the target shader stage is unknown, so in this case the HLSL API 
availability will be only checked against the shader model version.
+
+A list of functions that were already scanned is kept in order to avoid 
duplicate scans and diagnostics (see 
``DiagnoseHLSLAvailability::ScannedDecls``). It might happen that a shader 
library has multiple shader entry points for different shader stages that all 
call into the same shared function. It is therefore important to record not 
just that a function has been scanned, but also in which shader stage context. 
This is done by using ``llvm::DenseMap`` that maps ``FunctionDecl *`` to a 
``unsigned`` bitmap that represents a set of shader stages (or environments) 
the function has been scanned for. The ``N``'th bit in the set is set if the 
function has been scanned in shader environment whose 
``HLSLShaderAttr::ShaderType`` integer value equals ``N``.
+
+The emitted diagnostic messages belong to ``hlsl-availability`` diagnostic 
group and are reported as errors by default. With 
``-Wno-error=hlsl-availability`` flang they become warning, making it relaxed 
HLSL diagnostics mode.
+
+Strict Diagnostic Mode
+--
+
+When strict HLSL availability diagnostic mode is enabled the compiler must 
report all HLSL API 

[clang] [Clang][HLSL] Add environment parameter to availability attribute (PR #89809)

2024-05-15 Thread Helena Kotas via cfe-commits

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


[clang] [WIP][Safe Buffers] Serialize unsafe_buffer_usage pragmas (PR #92031)

2024-05-15 Thread Ziqing Luo via cfe-commits

https://github.com/ziqingluo-90 updated 
https://github.com/llvm/llvm-project/pull/92031

>From ac5aeb5c3a134d085320fc7fc5cf3f2c8c41a1f1 Mon Sep 17 00:00:00 2001
From: ziqingluo-90 
Date: Mon, 13 May 2024 13:31:21 -0700
Subject: [PATCH 1/2] fix safe buffer opt-out region serialization

---
 clang/include/clang/Lex/Preprocessor.h|  22 +++-
 .../include/clang/Serialization/ASTBitCodes.h |   3 +
 clang/lib/Lex/Preprocessor.cpp| 106 ++
 clang/lib/Serialization/ASTReader.cpp |  11 ++
 clang/lib/Serialization/ASTWriter.cpp |   7 ++
 clang/test/Modules/Inputs/SafeBuffers/base.h  |   9 ++
 .../SafeBuffers/safe_buffers_test.modulemap   |  10 ++
 .../Modules/Inputs/SafeBuffers/test_sub1.h|  20 
 .../Modules/Inputs/SafeBuffers/test_sub2.h|  11 ++
 clang/test/Modules/safe_buffers_optout.cpp|  39 +++
 ...unsafe-buffer-usage-pragma-pch-complex.cpp |  72 
 .../warn-unsafe-buffer-usage-pragma-pch.cpp   |  27 +
 12 files changed, 314 insertions(+), 23 deletions(-)
 create mode 100644 clang/test/Modules/Inputs/SafeBuffers/base.h
 create mode 100644 
clang/test/Modules/Inputs/SafeBuffers/safe_buffers_test.modulemap
 create mode 100644 clang/test/Modules/Inputs/SafeBuffers/test_sub1.h
 create mode 100644 clang/test/Modules/Inputs/SafeBuffers/test_sub2.h
 create mode 100644 clang/test/Modules/safe_buffers_optout.cpp
 create mode 100644 
clang/test/SemaCXX/warn-unsafe-buffer-usage-pragma-pch-complex.cpp
 create mode 100644 clang/test/SemaCXX/warn-unsafe-buffer-usage-pragma-pch.cpp

diff --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index e89b4a2c5230e..8d6884ebe7597 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -2883,11 +2883,15 @@ class Preprocessor {
   /// otherwise.
   SourceLocation CurrentSafeBufferOptOutStart; // It is used to report the 
start location of an never-closed region.
 
-  // An ordered sequence of "-Wunsafe-buffer-usage" opt-out regions in one
-  // translation unit. Each region is represented by a pair of start and end
-  // locations.  A region is "open" if its' start and end locations are
+  using SafeBufferOptOutMapTy =
+  SmallVector, 16>;
+  // An ordered sequence of "-Wunsafe-buffer-usage" opt-out regions in this
+  // translation unit. Each region is represented by a pair of start and
+  // end locations.  A region is "open" if its' start and end locations are
   // identical.
-  SmallVector, 8> 
SafeBufferOptOutMap;
+  SafeBufferOptOutMapTy SafeBufferOptOutMap;
+  // `SafeBufferOptOutMap`s of loaded files:
+  llvm::DenseMap LoadedSafeBufferOptOutMap;
 
 public:
   /// \return true iff the given `Loc` is in a "-Wunsafe-buffer-usage" opt-out
@@ -2918,6 +2922,16 @@ class Preprocessor {
   ///  opt-out region
   bool isPPInSafeBufferOptOutRegion(SourceLocation );
 
+  /// \return a sequence of SourceLocations representing ordered opt-out 
regions
+  /// specified by
+  /// `\#pragma clang unsafe_buffer_usage begin/end`s of this translation unit.
+  SmallVector serializeSafeBufferOptOutMap() const;
+
+  /// \param SrcLocSeqs a sequence of SourceLocations deserialized from a
+  /// record of code `PP_UNSAFE_BUFFER_USAGE`.
+  void setDeserializedSafeBufferOptOutMap(
+  const SmallVectorImpl );
+
 private:
   /// Helper functions to forward lexing to the actual lexer. They all share 
the
   /// same signature.
diff --git a/clang/include/clang/Serialization/ASTBitCodes.h 
b/clang/include/clang/Serialization/ASTBitCodes.h
index dcfa4ac0c1967..d1a0eba943039 100644
--- a/clang/include/clang/Serialization/ASTBitCodes.h
+++ b/clang/include/clang/Serialization/ASTBitCodes.h
@@ -775,6 +775,9 @@ enum ASTRecordTypes {
   /// Record code for lexical and visible block for delayed namespace in
   /// reduced BMI.
   DELAYED_NAMESPACE_LEXICAL_VISIBLE_RECORD = 68,
+
+  /// Record code for \#pragma clang unsafe_buffer_usage begin/end
+  PP_UNSAFE_BUFFER_USAGE = 69,
 };
 
 /// Record types used within a source manager block.
diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp
index 0b70192743a39..6a41e3d4138aa 100644
--- a/clang/lib/Lex/Preprocessor.cpp
+++ b/clang/lib/Lex/Preprocessor.cpp
@@ -58,6 +58,7 @@
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/iterator_range.h"
 #include "llvm/Support/Capacity.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/MemoryBuffer.h"
@@ -1483,26 +1484,41 @@ void Preprocessor::emitFinalMacroWarning(const Token 
,
 }
 
 bool Preprocessor::isSafeBufferOptOut(const SourceManager ,
-   const SourceLocation ) const {
-  // Try to find a region in `SafeBufferOptOutMap` where `Loc` is in:
-  auto FirstRegionEndingAfterLoc = llvm::partition_point(
-  SafeBufferOptOutMap,
-  [,
-   ](const std::pair ) {
-return 

[clang] [Clang][Sema] Don't build CXXDependentScopeMemberExprs for potentially implicit class member access expressions (PR #92318)

2024-05-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Krystian Stasiowski (sdkrystian)


Changes

According to [[expr.prim.id.general] 
p2](http://eel.is/c++draft/expr.prim.id.general#2):
 If an _id-expression_ `E` denotes a non-static non-type member of some 
class `C` at a point where the current class is `X` and
 - `E` is potentially evaluated or `C` is `X` or a base class of `X`, and
 - `E` is not the _id-expression_ of a class member access expression, and
 - if `E` is a _qualified-id_, `E` is not the un-parenthesized operand of 
the unary `` operator,

 the _id-expression_ is transformed into a class member access expression 
using `(*this)` as the object expression.

Consider the following:
```cpp
struct A
{
void f0();

templatetypename T
void f1();
};

templatetypename T
struct B : T
{
auto g0() - decltype(T::f0()); // ok

auto g1() - decltype(T::template f1int()); // error: call to 
non-static member function without an object argument
};

template struct BA;
```

Clang incorrectly rejects the call to `f1` in the _trailing-return-type_ of 
`g1`. Furthermore, the following snippet results in a crash during codegen:
```cpp
struct A
{
void f();
};

templatetypename T
struct B : T
{
templatetypename U
static void g();

template
void gint()
{
return T::f(); // crash here
}
};

template struct BA;
```
This happens because we unconditionally build a `CXXDependentScopeMemberExpr` 
(with an implicit object expression) for `T::f` when parsing the template 
definition, even though we don't know whether `g` is an implicit object member 
function yet.

This patch fixes these issues by instead building `DependentScopeDeclRefExpr`s 
for such expressions, and only transforming them into implicit class member 
access expressions during instantiation. Since we implemented the MS 
"unqualified lookup into dependent bases" extension by building an implicit 
class member access (and relying on the first component name of the 
_nested-name-specifier_ to be looked up in the context of the object expression 
during instantiation), we instead pre-append a fake _nested-name-specifier_ 
that refers to the injected-class-name of the enclosing class. This patch also 
refactors `Sema::BuildQualifiedDeclarationNameExpr` and 
`Sema::BuildQualifiedTemplateIdExpr`, streamlining their implementation and 
removing any redundant checks.

---

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


9 Files Affected:

- (modified) clang/include/clang/Sema/Sema.h (+5-6) 
- (modified) clang/lib/Sema/SemaCXXScopeSpec.cpp (+8) 
- (modified) clang/lib/Sema/SemaExpr.cpp (+9-22) 
- (modified) clang/lib/Sema/SemaTemplate.cpp (+30-68) 
- (modified) clang/lib/Sema/TreeTransform.h (+3-3) 
- (modified) clang/test/CXX/class/class.mfct/class.mfct.non-static/p3.cpp 
(+89-2) 
- (modified) clang/test/SemaTemplate/ms-function-specialization-class-scope.cpp 
(+52) 
- (modified) clang/test/SemaTemplate/ms-lookup-template-base-classes.cpp (+6-6) 
- (modified) clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp (+4-2) 


``diff
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 6a414aa57f32b..779e3134b3067 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -5366,11 +5366,9 @@ class Sema final : public SemaBase {
   bool UseArgumentDependentLookup(const CXXScopeSpec , const LookupResult 
,
   bool HasTrailingLParen);
 
-  ExprResult
-  BuildQualifiedDeclarationNameExpr(CXXScopeSpec ,
-const DeclarationNameInfo ,
-bool IsAddressOfOperand, const Scope *S,
-TypeSourceInfo **RecoveryTSI = nullptr);
+  ExprResult BuildQualifiedDeclarationNameExpr(
+  CXXScopeSpec , const DeclarationNameInfo ,
+  bool IsAddressOfOperand, TypeSourceInfo **RecoveryTSI = nullptr);
 
   ExprResult BuildDeclarationNameExpr(const CXXScopeSpec , LookupResult ,
   bool NeedsADL,
@@ -8982,7 +8980,8 @@ class Sema final : public SemaBase {
   ExprResult
   BuildQualifiedTemplateIdExpr(CXXScopeSpec , SourceLocation TemplateKWLoc,
const DeclarationNameInfo ,
-   const TemplateArgumentListInfo *TemplateArgs);
+   const TemplateArgumentListInfo *TemplateArgs,
+   bool IsAddressOfOperand);
 
   TemplateNameKind ActOnTemplateName(Scope *S, CXXScopeSpec ,
  SourceLocation TemplateKWLoc,
diff --git a/clang/lib/Sema/SemaCXXScopeSpec.cpp 
b/clang/lib/Sema/SemaCXXScopeSpec.cpp
index fca5bd131bbc0..c405fbc0aa421 100644
--- a/clang/lib/Sema/SemaCXXScopeSpec.cpp
+++ b/clang/lib/Sema/SemaCXXScopeSpec.cpp
@@ -796,6 +796,14 @@ bool Sema::BuildCXXNestedNameSpecifier(Scope *S, 

[clang] [Clang][Sema] Don't build CXXDependentScopeMemberExprs for potentially implicit class member access expressions (PR #92318)

2024-05-15 Thread Krystian Stasiowski via cfe-commits

https://github.com/sdkrystian created 
https://github.com/llvm/llvm-project/pull/92318

According to [[expr.prim.id.general] 
p2](http://eel.is/c++draft/expr.prim.id.general#2):
> If an _id-expression_ `E` denotes a non-static non-type member of some class 
> `C` at a point where the current class is `X` and
> - `E` is potentially evaluated or `C` is `X` or a base class of `X`, and
> - `E` is not the _id-expression_ of a class member access expression, and
> - if `E` is a _qualified-id_, `E` is not the un-parenthesized operand of the 
> unary `&` operator,
>
> the _id-expression_ is transformed into a class member access expression 
> using `(*this)` as the object expression.

Consider the following:
```cpp
struct A
{
void f0();

template
void f1();
};

template
struct B : T
{
auto g0() -> decltype(T::f0()); // ok

auto g1() -> decltype(T::template f1()); // error: call to non-static 
member function without an object argument
};

template struct B;
```

Clang incorrectly rejects the call to `f1` in the _trailing-return-type_ of 
`g1`. Furthermore, the following snippet results in a crash during codegen:
```cpp
struct A
{
void f();
};

template
struct B : T
{
template
static void g();

template<>
void g()
{
return T::f(); // crash here
}
};

template struct B;
```
This happens because we unconditionally build a `CXXDependentScopeMemberExpr` 
(with an implicit object expression) for `T::f` when parsing the template 
definition, even though we don't know whether `g` is an implicit object member 
function yet.

This patch fixes these issues by instead building `DependentScopeDeclRefExpr`s 
for such expressions, and only transforming them into implicit class member 
access expressions during instantiation. Since we implemented the MS 
"unqualified lookup into dependent bases" extension by building an implicit 
class member access (and relying on the first component name of the 
_nested-name-specifier_ to be looked up in the context of the object expression 
during instantiation), we instead pre-append a fake _nested-name-specifier_ 
that refers to the injected-class-name of the enclosing class. This patch also 
refactors `Sema::BuildQualifiedDeclarationNameExpr` and 
`Sema::BuildQualifiedTemplateIdExpr`, streamlining their implementation and 
removing any redundant checks.

>From a5ed54f967e4a15a80f41ee648f79e77202906d8 Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski 
Date: Wed, 15 May 2024 16:13:03 -0400
Subject: [PATCH] [Clang][Sema] Don't build CXXDependentScopeMemberExprs for
 potentially implicit class member access expressions

---
 clang/include/clang/Sema/Sema.h   | 11 +--
 clang/lib/Sema/SemaCXXScopeSpec.cpp   |  8 ++
 clang/lib/Sema/SemaExpr.cpp   | 31 ++
 clang/lib/Sema/SemaTemplate.cpp   | 98 ++-
 clang/lib/Sema/TreeTransform.h|  6 +-
 .../class.mfct/class.mfct.non-static/p3.cpp   | 91 -
 ...ms-function-specialization-class-scope.cpp | 52 ++
 .../ms-lookup-template-base-classes.cpp   | 12 +--
 .../ASTMatchers/ASTMatchersNodeTest.cpp   |  6 +-
 9 files changed, 206 insertions(+), 109 deletions(-)

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 6a414aa57f32b..779e3134b3067 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -5366,11 +5366,9 @@ class Sema final : public SemaBase {
   bool UseArgumentDependentLookup(const CXXScopeSpec , const LookupResult 
,
   bool HasTrailingLParen);
 
-  ExprResult
-  BuildQualifiedDeclarationNameExpr(CXXScopeSpec ,
-const DeclarationNameInfo ,
-bool IsAddressOfOperand, const Scope *S,
-TypeSourceInfo **RecoveryTSI = nullptr);
+  ExprResult BuildQualifiedDeclarationNameExpr(
+  CXXScopeSpec , const DeclarationNameInfo ,
+  bool IsAddressOfOperand, TypeSourceInfo **RecoveryTSI = nullptr);
 
   ExprResult BuildDeclarationNameExpr(const CXXScopeSpec , LookupResult ,
   bool NeedsADL,
@@ -8982,7 +8980,8 @@ class Sema final : public SemaBase {
   ExprResult
   BuildQualifiedTemplateIdExpr(CXXScopeSpec , SourceLocation TemplateKWLoc,
const DeclarationNameInfo ,
-   const TemplateArgumentListInfo *TemplateArgs);
+   const TemplateArgumentListInfo *TemplateArgs,
+   bool IsAddressOfOperand);
 
   TemplateNameKind ActOnTemplateName(Scope *S, CXXScopeSpec ,
  SourceLocation TemplateKWLoc,
diff --git a/clang/lib/Sema/SemaCXXScopeSpec.cpp 
b/clang/lib/Sema/SemaCXXScopeSpec.cpp
index fca5bd131bbc0..c405fbc0aa421 100644
--- a/clang/lib/Sema/SemaCXXScopeSpec.cpp
+++ b/clang/lib/Sema/SemaCXXScopeSpec.cpp

[clang] [clang] Enable C++17 relaxed template template argument matching by default (PR #89807)

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

mizvekov wrote:

> I think I prefer pretty fine-grained ones TBH, it makes our deprecation 
> warnings more valuable. In a perfect world, it would change every release of 
> the compiler so that folks would be frequently reminded of it, but it isn't a 
> perfect world :)

I meant something fine grained, but generic, like 
`-Wno-deprecated-flag=-fno-relaxed-template-template-args`.
We have something similar for generic warnings.
That would probably take a little longer to get everyone onboard the design, 
and may lack other motivators presently.
 
> Is doing so much of a task? I would expect it to be like other diagnostics 
> and take roughly the same amount of time as reverting the 
> negative-spelling-deprecation. I don't see the request to remove the 
> deprecation (it IS just a warning afterall!) to be particularly motivating 
> until release time (it IS just a warning afterall!), so I'd think it would a 
> better spending of time to implement what Richard suggested.

Right, it takes about the same amount of time, so we may as well implement the 
simple thing, and argue about something else later if someone sees motivation.


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


[clang] HLSL availability diagnostics design doc (PR #92207)

2024-05-15 Thread Xiang Li via cfe-commits


@@ -0,0 +1,53 @@
+=
+HLSL Availability Diagnostics
+=
+
+.. contents::
+   :local:
+
+Introduction
+
+
+HLSL availability diagnostics emits errors or warning when unavailable shader 
APIs are used. Unavailable shader APIs are APIs that are exposed in HLSL code 
but are not available in the target shader stage or shader model version.
+
+There are three modes of HLSL availability diagnostic:
+
+#. **Default mode** - compiler emits an error when an unavailable API is found 
in a code that is reachable from the shader entry point function or from an 
exported library function (when compiling a shader library)
+
+#. **Relaxed mode** - same as default mode except the compiler emits a 
warning. This mode is enabled by ``-Wno-error=hlsl-availability``.
+
+#. **Strict mode** - compiler emits an error when an unavailable API is found 
in parsed code regardless of whether it can be reached from the shader entry 
point or exported functions, or not. This mode is enabled by 
``-fhlsl-strict-diagnostics``.
+
+Implementation Details
+==
+
+Environment Parameter
+-
+
+In order to encode API availability based on the shader model version and 
shader model stage a new ``environment`` parameter was added to the existing 
Clang ``availability`` attribute. 
+
+The values allowed for this parameter are a subset of values allowed as the 
``llvm::Triple`` environment component. If the environment parameters is 
present, the declared availability attribute applies only to targets with the 
same platform and environment.
+
+Default and Relaxed Diagnostic Modes
+
+
+This mode is implemented in ``DiagnoseHLSLAvailability`` class in 
``SemaHLSL.cpp`` and it is invoked after the whole translation unit is parsed 
(from ``Sema::ActOnEndOfTranslationUnit``). The implementation iterates over 
all shader entry points and exported library functions in the translation unit 
and performs an AST traversal of each function body.
+
+When a reference to another function is found and it has a body, the AST of 
the referenced function is also scanned. This chain of AST traversals will 
reach all of the code that is reachable from the initial shader entry point or 
exported library function.
+
+All shader APIs have an availability attribute that specifies the shader model 
version (and environment, if applicable) when this API was first 
introduced.When a reference to a function without a definition is found and it 
has an availability attribute, the version of the attribute is checked against 
the target shader model version and shader stage (if shader stage context is 
known), and an appropriate diagnostic is generated as needed.
+
+All shader entry functions have ``HLSLShaderAttr`` attribute that specifies 
what type of shader this function represents. However, for exported library 
functions the target shader stage is unknown, so in this case the HLSL API 
availability will be only checked against the shader model version. It means 
that for exported library functions the diagnostic of APIs with availability 
specific to shader stage will be deferred until DXIL linking time.
+
+A list of functions that were already scanned is kept in order to avoid 
duplicate scans and diagnostics (see 
``DiagnoseHLSLAvailability::ScannedDecls``). It might happen that a shader 
library has multiple shader entry points for different shader stages that all 
call into the same shared function. It is therefore important to record not 
just that a function has been scanned, but also in which shader stage context. 
This is done by using ``llvm::DenseMap`` that maps ``FunctionDecl *`` to a 
``unsigned`` bitmap that represents a set of shader stages (or environments) 
the function has been scanned for. The ``N``'th bit in the set is set if the 
function has been scanned in shader environment whose 
``HLSLShaderAttr::ShaderType`` integer value equals ``N``.
+
+The emitted diagnostic messages belong to ``hlsl-availability`` diagnostic 
group and are reported as errors by default. With 
``-Wno-error=hlsl-availability`` flag they become warning, making it relaxed 
HLSL diagnostics mode.
+
+Strict Diagnostic Mode
+--
+
+When strict HLSL availability diagnostic mode is enabled the compiler must 
report all HLSL API availability issues regardless of code reachability. The 
implementation of this mode takes advantage of an existing diagnostic scan in 
``DiagnoseUnguardedAvailability`` class which is already traversing AST of each 
function as soon as the function body has been parsed. For HLSL, this pass was 
only slightly modified, such as making sure diagnostic messages are in the 
```hlsl-availability`` group and that availability checks based on shader stage 
are not included if the shader stage context is unknown.

python3kgae wrote:

```suggestion
When strict HLSL availability 

[clang] HLSL availability diagnostics design doc (PR #92207)

2024-05-15 Thread Helena Kotas via cfe-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/92207

>From 3df0ba0fd2171a0115427bc6ba5e3f8e84831747 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Tue, 14 May 2024 19:06:59 -0700
Subject: [PATCH 1/3] HLSL Availability Diagnostics Design Document - initial
 commit

---
 clang/docs/HLSL/AvailabilityDiagnostics.rst | 50 +
 clang/docs/HLSL/HLSLDocs.rst|  1 +
 2 files changed, 51 insertions(+)
 create mode 100644 clang/docs/HLSL/AvailabilityDiagnostics.rst

diff --git a/clang/docs/HLSL/AvailabilityDiagnostics.rst 
b/clang/docs/HLSL/AvailabilityDiagnostics.rst
new file mode 100644
index 0..218047495e6b9
--- /dev/null
+++ b/clang/docs/HLSL/AvailabilityDiagnostics.rst
@@ -0,0 +1,50 @@
+=
+HLSL Availability Diagnostics
+=
+
+.. contents::
+   :local:
+
+Introduction
+
+
+HLSL availability diagnostics emits errors or warning when unavailable shader 
APIs are used. Unavailable shader APIs are APIs that are exposed in HLSL code 
but are not available in the target shader stage or shader model version.
+
+There are three modes of HLSL availability diagnostic:
+1. **Default mode** - compiler emits an error when an unavailable shader API 
is found in a code that is reachable from the shader entry point function or 
from an exported library function (when compiling a shader library)
+2. **Relaxed mode** - same as default mode except the compiler emits a 
warning. This mode is enabled by ``-Wno-error=hlsl-availability``.
+3. **Strict mode** - compiler emits an error when when an unavailable API is 
found in parsed code regardless of whether it can be reached from the shader 
entry point or exported functions, or not. This mode is enabled by 
``-fhlsl-strict-diagnostics``.
+
+Implementation Details
+==
+
+Environment Parameter
+-
+
+In order to encode API availability based on the shader model version and 
shader model stage a new ``environment`` parameter was added to the existing 
Clang ``availability`` attribute. 
+
+The values allowed for this parameter are a subset of values allowed as the 
``llvm::Triple`` environment component. If the environment parameters is 
present, the declared availability attribute applies only to targets with the 
same platform and environment.
+
+Default and Relaxed Diagnostic Modes
+
+
+This mode is implemeted in ``DiagnoseHLSLAvailability`` class in 
``SemaHLSL.cpp`` and it is invoked after the whole translation unit is parsed 
(from ``Sema::ActOnEndOfTranslationUnit``). The implementation iterates over 
all shader entry points and exported library functions in the translation unit 
and performs an AST traversal of each function body.
+
+When a reference to another function is found and it has a body, the AST of 
the referenced function is also scanned. This chain of AST traversals will 
reach all of the code that is reachable from the initial shader entry point or 
exported library function.
+
+All shader APIs have an availability attribute that specifies the shader model 
version (and environment, if applicable) when this API was first 
introduced.When a reference to a function without a definition is found and it 
has an availability attribute, the version of the attribute is checked against 
the target shader model version and shader stage (if shader stage context is 
known), and an appropriate diagnostic is generated as needed.
+
+All shader entry functions have ``HLSLShaderAttr`` attribute that specifies 
what type of shader this function represents. However, for exported library 
functions the target shader stage is unknown, so in this case the HLSL API 
availability will be only checked against the shader model version.
+
+A list of functions that were already scanned is kept in order to avoid 
duplicate scans and diagnostics (see 
``DiagnoseHLSLAvailability::ScannedDecls``). It might happen that a shader 
library has multiple shader entry points for different shader stages that all 
call into the same shared function. It is therefore important to record not 
just that a function has been scanned, but also in which shader stage context. 
This is done by using ``llvm::DenseMap`` that maps ``FunctionDecl *`` to a 
``unsigned`` bitmap that represents a set of shader stages (or environments) 
the function has been scanned for. The ``N``'th bit in the set is set if the 
function has been scanned in shader environment whose 
``HLSLShaderAttr::ShaderType`` integer value equals ``N``.
+
+The emitted diagnostic messages belong to ``hlsl-availability`` diagnostic 
group and are reported as errors by default. With 
``-Wno-error=hlsl-availability`` flang they become warning, making it relaxed 
HLSL diagnostics mode.
+
+Strict Diagnostic Mode
+--
+
+When strict HLSL availability diagnostic mode is enabled the compiler must 
report all HLSL API 

[clang] HLSL availability diagnostics design doc (PR #92207)

2024-05-15 Thread Helena Kotas via cfe-commits


@@ -0,0 +1,53 @@
+=
+HLSL Availability Diagnostics
+=
+
+.. contents::
+   :local:
+
+Introduction
+
+
+HLSL availability diagnostics emits errors or warning when unavailable shader 
APIs are used. Unavailable shader APIs are APIs that are exposed in HLSL code 
but are not available in the target shader stage or shader model version.
+
+There are three modes of HLSL availability diagnostic:
+
+#. **Default mode** - compiler emits an error when an unavailable shader API 
is found in a code that is reachable from the shader entry point function or 
from an exported library function (when compiling a shader library)
+
+#. **Relaxed mode** - same as default mode except the compiler emits a 
warning. This mode is enabled by ``-Wno-error=hlsl-availability``.
+
+#. **Strict mode** - compiler emits an error when when an unavailable API is 
found in parsed code regardless of whether it can be reached from the shader 
entry point or exported functions, or not. This mode is enabled by 
``-fhlsl-strict-diagnostics``.
+
+Implementation Details
+==
+
+Environment Parameter
+-
+
+In order to encode API availability based on the shader model version and 
shader model stage a new ``environment`` parameter was added to the existing 
Clang ``availability`` attribute. 
+
+The values allowed for this parameter are a subset of values allowed as the 
``llvm::Triple`` environment component. If the environment parameters is 
present, the declared availability attribute applies only to targets with the 
same platform and environment.
+
+Default and Relaxed Diagnostic Modes
+
+
+This mode is implemeted in ``DiagnoseHLSLAvailability`` class in 
``SemaHLSL.cpp`` and it is invoked after the whole translation unit is parsed 
(from ``Sema::ActOnEndOfTranslationUnit``). The implementation iterates over 
all shader entry points and exported library functions in the translation unit 
and performs an AST traversal of each function body.
+
+When a reference to another function is found and it has a body, the AST of 
the referenced function is also scanned. This chain of AST traversals will 
reach all of the code that is reachable from the initial shader entry point or 
exported library function.
+
+All shader APIs have an availability attribute that specifies the shader model 
version (and environment, if applicable) when this API was first 
introduced.When a reference to a function without a definition is found and it 
has an availability attribute, the version of the attribute is checked against 
the target shader model version and shader stage (if shader stage context is 
known), and an appropriate diagnostic is generated as needed.
+
+All shader entry functions have ``HLSLShaderAttr`` attribute that specifies 
what type of shader this function represents. However, for exported library 
functions the target shader stage is unknown, so in this case the HLSL API 
availability will be only checked against the shader model version.

hekota wrote:

It should. I will add a note about that.

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


[clang] [clang] Enable C++17 relaxed template template argument matching by default (PR #89807)

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

erichkeane wrote:

> > Would it be reasonable to add a 
> > `-Wno-deprecated-relaxed-template-template-args` flag (or something like 
> > that) for this specific deprecation?
> 
> I had similar idea, but what about instead implementing something generic to 
> ignore deprecation of any driver flag?

I think I prefer pretty fine-grained ones TBH, it makes our deprecation 
warnings more valuable.  In a perfect world, it would change every release of 
the compiler so that folks would be frequently reminded of it, but it isn't a 
perfect world :) 

> Does it sound good for everyone that we revert the deprecation of the 
> negative spelling of the flag for a while, until we come up with a patch for 
> a new flag which helps ignore these deprecations?

Is doing so much of a task? I would expect it to be like other diagnostics and 
take roughly the same amount of time as reverting the 
negative-spelling-deprecation.  I don't see the request to remove the 
deprecation (it IS just a warning afterall!) to be particularly motivating 
until release time (it IS just a warning afterall!), so I'd think it would a 
better spending of time to implement what Richard suggested.

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


[clang] [clang] Enable C++17 relaxed template template argument matching by default (PR #89807)

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

mizvekov wrote:

Regarding @joanahalili 's post

Does it sound good for everyone that we revert the deprecation of the positive 
spelling of the flag for a while, until we come up with a patch for a new flag 
which helps ignore these deprecations?



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


  1   2   3   4   5   >