[clang] [RFC][C++20][Modules] Fix crash when function and lambda inside loaded from different modules (PR #104512)

2024-08-20 Thread Dmitry Polukhin via cfe-commits

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


[clang] [clang][bytecode] Fix initializing base casts (PR #104901)

2024-08-20 Thread Timm Baeder via cfe-commits

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

Use delegate() there. To fix a follow-up problem, abort when a cast ends up on 
a valid Pointer that isn't a base class.

>From cd2cc98cecc1f237da4a2aa30a9c07b07ae4c804 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Tue, 20 Aug 2024 09:28:37 +0200
Subject: [PATCH] [clang][bytecode] Fix initializing base casts

Use delegate() there. To fix a follow-up problem, abort when a cast ends
up on a valid Pointer that isn't a base class.
---
 clang/lib/AST/ByteCode/Compiler.cpp  | 8 
 clang/lib/AST/ByteCode/Interp.h  | 4 ++--
 clang/test/Modules/merge-using-decls.cpp | 1 +
 3 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 53144a50ccf4a9..d84da1efb97695 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -214,7 +214,7 @@ bool Compiler::VisitCastExpr(const CastExpr *CE) {
 unsigned DerivedOffset = collectBaseOffset(QualType(ToMP->getClass(), 0),
QualType(FromMP->getClass(), 
0));
 
-if (!this->visit(SubExpr))
+if (!this->delegate(SubExpr))
   return false;
 
 return this->emitGetMemberPtrBasePop(DerivedOffset, CE);
@@ -229,14 +229,14 @@ bool Compiler::VisitCastExpr(const CastExpr *CE) 
{
 unsigned DerivedOffset = collectBaseOffset(QualType(FromMP->getClass(), 0),
QualType(ToMP->getClass(), 0));
 
-if (!this->visit(SubExpr))
+if (!this->delegate(SubExpr))
   return false;
 return this->emitGetMemberPtrBasePop(-DerivedOffset, CE);
   }
 
   case CK_UncheckedDerivedToBase:
   case CK_DerivedToBase: {
-if (!this->visit(SubExpr))
+if (!this->delegate(SubExpr))
   return false;
 
 const auto extractRecordDecl = [](QualType Ty) -> const CXXRecordDecl * {
@@ -265,7 +265,7 @@ bool Compiler::VisitCastExpr(const CastExpr *CE) {
   }
 
   case CK_BaseToDerived: {
-if (!this->visit(SubExpr))
+if (!this->delegate(SubExpr))
   return false;
 
 unsigned DerivedOffset =
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index 5aa3d24ebc7582..3c1fa0f93273d4 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -1568,7 +1568,7 @@ inline bool GetPtrBase(InterpState &S, CodePtr OpPC, 
uint32_t Off) {
   if (!CheckSubobject(S, OpPC, Ptr, CSK_Base))
 return false;
   const Pointer &Result = Ptr.atField(Off);
-  if (Result.isPastEnd())
+  if (Result.isPastEnd() || !Result.isBaseClass())
 return false;
   S.Stk.push(Result);
   return true;
@@ -1581,7 +1581,7 @@ inline bool GetPtrBasePop(InterpState &S, CodePtr OpPC, 
uint32_t Off) {
   if (!CheckSubobject(S, OpPC, Ptr, CSK_Base))
 return false;
   const Pointer &Result = Ptr.atField(Off);
-  if (Result.isPastEnd())
+  if (Result.isPastEnd() || !Result.isBaseClass())
 return false;
   S.Stk.push(Result);
   return true;
diff --git a/clang/test/Modules/merge-using-decls.cpp 
b/clang/test/Modules/merge-using-decls.cpp
index e9794a40837ef9..b678eb4e0f851f 100644
--- a/clang/test/Modules/merge-using-decls.cpp
+++ b/clang/test/Modules/merge-using-decls.cpp
@@ -8,6 +8,7 @@
 // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -x 
c++ -I%S/Inputs/merge-using-decls -verify -std=c++11 %s -DORDER=2
 
 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -fmodules 
-fimplicit-module-maps -fmodules-cache-path=%t -x c++ 
-I%S/Inputs/merge-using-decls -verify -std=c++17 %s -DORDER=2
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -fmodules 
-fimplicit-module-maps -fexperimental-new-constant-interpreter 
-fmodules-cache-path=%t -x c++ -I%S/Inputs/merge-using-decls -verify -std=c++98 
%s -DORDER=1
 
 #if ORDER == 1
 #include "a.h"

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


[clang] [Sparc] Add flags to enable errata workaround pass for GR712RC and UT700 (PR #104742)

2024-08-20 Thread Daniel Cederman via cfe-commits

doac wrote:

Thank you for your comments!

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


[clang] [Sparc] Add flags to enable errata workaround pass for GR712RC and UT700 (PR #104742)

2024-08-20 Thread Daniel Cederman via cfe-commits

https://github.com/doac updated https://github.com/llvm/llvm-project/pull/104742

>From a68dec7b074afdc003c63e721cd384c9c6721610 Mon Sep 17 00:00:00 2001
From: Daniel Cederman 
Date: Mon, 19 Aug 2024 08:17:36 +0200
Subject: [PATCH 1/3] [Sparc] Add flags to enable errata workaround pass for
 GR712RC and UT700

This adds the flags -mfix-gr712rc and -mfix-ut700 which enables the
necessary errata workarounds for the GR712RC and UT700 processors.
The functionality enabled by the flag is the same as the functionality
provided by the corresponding GCC flag.
---
 clang/include/clang/Driver/Options.td  |  4 
 clang/lib/Driver/ToolChains/Arch/Sparc.cpp | 13 +
 clang/test/Driver/sparc-fix.c  | 12 
 3 files changed, 29 insertions(+)
 create mode 100644 clang/test/Driver/sparc-fix.c

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index cfd9e595c55178..0ef3a2dbd69ae3 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -6148,6 +6148,10 @@ def mv8plus : Flag<["-"], "mv8plus">, 
Group,
   HelpText<"Enable V8+ mode, allowing use of 64-bit V9 instructions in 32-bit 
code">;
 def mno_v8plus : Flag<["-"], "mno-v8plus">, Group,
   HelpText<"Disable V8+ mode">;
+def mfix_gr712rc : Flag<["-"], "mfix-gr712rc">, Group,
+  HelpText<"Enable workarounds for GR712RC errata">;
+def mfix_ut700 : Flag<["-"], "mfix-ut700">, Group,
+  HelpText<"Enable workarounds for UT700 errata">;
 foreach i = 1 ... 7 in
   def ffixed_g#i : Flag<["-"], "ffixed-g"#i>, Group,
 HelpText<"Reserve the G"#i#" register (SPARC only)">;
diff --git a/clang/lib/Driver/ToolChains/Arch/Sparc.cpp 
b/clang/lib/Driver/ToolChains/Arch/Sparc.cpp
index 5a1fedbec06adf..f7f0a265fef68b 100644
--- a/clang/lib/Driver/ToolChains/Arch/Sparc.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/Sparc.cpp
@@ -264,4 +264,17 @@ void sparc::getSparcTargetFeatures(const Driver &D, const 
ArgList &Args,
 
   if (Args.hasArg(options::OPT_ffixed_i5))
 Features.push_back("+reserve-i5");
+
+  if (Args.hasArg(options::OPT_mfix_gr712rc)) {
+Features.push_back("+fix-tn0009");
+Features.push_back("+fix-tn0011");
+Features.push_back("+fix-tn0012");
+Features.push_back("+fix-tn0013");
+  }
+
+  if (Args.hasArg(options::OPT_mfix_ut700)) {
+Features.push_back("+fix-tn0009");
+Features.push_back("+fix-tn0010");
+Features.push_back("+fix-tn0013");
+  }
 }
diff --git a/clang/test/Driver/sparc-fix.c b/clang/test/Driver/sparc-fix.c
new file mode 100644
index 00..2b4bc4117adb68
--- /dev/null
+++ b/clang/test/Driver/sparc-fix.c
@@ -0,0 +1,12 @@
+// RUN: %clang -target sparc -mfix-gr712rc -### %s 2> %t
+// RUN: FileCheck --check-prefix=CHECK-FIX-GR712RC < %t %s
+// CHECK-FIX-GR712RC: "-target-feature" "+fix-tn0009"
+// CHECK-FIX-GR712RC: "-target-feature" "+fix-tn0011"
+// CHECK-FIX-GR712RC: "-target-feature" "+fix-tn0012"
+// CHECK-FIX-GR712RC: "-target-feature" "+fix-tn0013"
+
+// RUN: %clang -target sparc -mfix-ut700 -### %s 2> %t
+// RUN: FileCheck --check-prefix=CHECK-FIX-UT700 < %t %s
+// CHECK-FIX-UT700: "-target-feature" "+fix-tn0009"
+// CHECK-FIX-UT700: "-target-feature" "+fix-tn0010"
+// CHECK-FIX-UT700: "-target-feature" "+fix-tn0013"

>From a4ee7ebd69db218a1084e44fee35832a169f7c7e Mon Sep 17 00:00:00 2001
From: Daniel Cederman 
Date: Tue, 20 Aug 2024 09:46:53 +0200
Subject: [PATCH 2/3] [Sparc] Use --target= instead of -target

---
 clang/test/Driver/sparc-fix.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/test/Driver/sparc-fix.c b/clang/test/Driver/sparc-fix.c
index 2b4bc4117adb68..f2815c721db9b8 100644
--- a/clang/test/Driver/sparc-fix.c
+++ b/clang/test/Driver/sparc-fix.c
@@ -1,11 +1,11 @@
-// RUN: %clang -target sparc -mfix-gr712rc -### %s 2> %t
+// RUN: %clang --target=sparc -mfix-gr712rc -### %s 2> %t
 // RUN: FileCheck --check-prefix=CHECK-FIX-GR712RC < %t %s
 // CHECK-FIX-GR712RC: "-target-feature" "+fix-tn0009"
 // CHECK-FIX-GR712RC: "-target-feature" "+fix-tn0011"
 // CHECK-FIX-GR712RC: "-target-feature" "+fix-tn0012"
 // CHECK-FIX-GR712RC: "-target-feature" "+fix-tn0013"
 
-// RUN: %clang -target sparc -mfix-ut700 -### %s 2> %t
+// RUN: %clang --target=sparc -mfix-ut700 -### %s 2> %t
 // RUN: FileCheck --check-prefix=CHECK-FIX-UT700 < %t %s
 // CHECK-FIX-UT700: "-target-feature" "+fix-tn0009"
 // CHECK-FIX-UT700: "-target-feature" "+fix-tn0010"

>From 2a3d7aa43733908a5e4d498f6b6e1c7f73e5deb7 Mon Sep 17 00:00:00 2001
From: Daniel Cederman 
Date: Tue, 20 Aug 2024 09:48:33 +0200
Subject: [PATCH 3/3] [Sparc] Place checks for same target on same line

---
 clang/test/Driver/sparc-fix.c | 15 ---
 1 file changed, 4 insertions(+), 11 deletions(-)

diff --git a/clang/test/Driver/sparc-fix.c b/clang/test/Driver/sparc-fix.c
index f2815c721db9b8..1f034399ce2245 100644
--- a/clang/test/Driver/sparc-fix.c
+++ b/clang/test/Driver/sparc-fix.c
@@ -1,12 +1,5 @@
-// RUN: %clang --target=sp

[clang] [clang][bytecode] Fix initializing base casts (PR #104901)

2024-08-20 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

Use delegate() there. To fix a follow-up problem, abort when a cast ends up on 
a valid Pointer that isn't a base class.

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


3 Files Affected:

- (modified) clang/lib/AST/ByteCode/Compiler.cpp (+4-4) 
- (modified) clang/lib/AST/ByteCode/Interp.h (+2-2) 
- (modified) clang/test/Modules/merge-using-decls.cpp (+1) 


``diff
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 53144a50ccf4a9..d84da1efb97695 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -214,7 +214,7 @@ bool Compiler::VisitCastExpr(const CastExpr *CE) {
 unsigned DerivedOffset = collectBaseOffset(QualType(ToMP->getClass(), 0),
QualType(FromMP->getClass(), 
0));
 
-if (!this->visit(SubExpr))
+if (!this->delegate(SubExpr))
   return false;
 
 return this->emitGetMemberPtrBasePop(DerivedOffset, CE);
@@ -229,14 +229,14 @@ bool Compiler::VisitCastExpr(const CastExpr *CE) 
{
 unsigned DerivedOffset = collectBaseOffset(QualType(FromMP->getClass(), 0),
QualType(ToMP->getClass(), 0));
 
-if (!this->visit(SubExpr))
+if (!this->delegate(SubExpr))
   return false;
 return this->emitGetMemberPtrBasePop(-DerivedOffset, CE);
   }
 
   case CK_UncheckedDerivedToBase:
   case CK_DerivedToBase: {
-if (!this->visit(SubExpr))
+if (!this->delegate(SubExpr))
   return false;
 
 const auto extractRecordDecl = [](QualType Ty) -> const CXXRecordDecl * {
@@ -265,7 +265,7 @@ bool Compiler::VisitCastExpr(const CastExpr *CE) {
   }
 
   case CK_BaseToDerived: {
-if (!this->visit(SubExpr))
+if (!this->delegate(SubExpr))
   return false;
 
 unsigned DerivedOffset =
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index 5aa3d24ebc7582..3c1fa0f93273d4 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -1568,7 +1568,7 @@ inline bool GetPtrBase(InterpState &S, CodePtr OpPC, 
uint32_t Off) {
   if (!CheckSubobject(S, OpPC, Ptr, CSK_Base))
 return false;
   const Pointer &Result = Ptr.atField(Off);
-  if (Result.isPastEnd())
+  if (Result.isPastEnd() || !Result.isBaseClass())
 return false;
   S.Stk.push(Result);
   return true;
@@ -1581,7 +1581,7 @@ inline bool GetPtrBasePop(InterpState &S, CodePtr OpPC, 
uint32_t Off) {
   if (!CheckSubobject(S, OpPC, Ptr, CSK_Base))
 return false;
   const Pointer &Result = Ptr.atField(Off);
-  if (Result.isPastEnd())
+  if (Result.isPastEnd() || !Result.isBaseClass())
 return false;
   S.Stk.push(Result);
   return true;
diff --git a/clang/test/Modules/merge-using-decls.cpp 
b/clang/test/Modules/merge-using-decls.cpp
index e9794a40837ef9..b678eb4e0f851f 100644
--- a/clang/test/Modules/merge-using-decls.cpp
+++ b/clang/test/Modules/merge-using-decls.cpp
@@ -8,6 +8,7 @@
 // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -x 
c++ -I%S/Inputs/merge-using-decls -verify -std=c++11 %s -DORDER=2
 
 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -fmodules 
-fimplicit-module-maps -fmodules-cache-path=%t -x c++ 
-I%S/Inputs/merge-using-decls -verify -std=c++17 %s -DORDER=2
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -fmodules 
-fimplicit-module-maps -fexperimental-new-constant-interpreter 
-fmodules-cache-path=%t -x c++ -I%S/Inputs/merge-using-decls -verify -std=c++98 
%s -DORDER=1
 
 #if ORDER == 1
 #include "a.h"

``




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


[clang-tools-extra] c29aba7 - [clang-doc] add support for block commands in clang-doc html output (#101108)

2024-08-20 Thread via cfe-commits

Author: PeterChou1
Date: 2024-08-20T03:58:47-04:00
New Revision: c29aba7159473c5fc225d4aea75647939497e3ac

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

LOG: [clang-doc] add support for block commands in clang-doc html output 
(#101108)

Added: 


Modified: 
clang-tools-extra/clang-doc/HTMLGenerator.cpp
clang-tools-extra/test/clang-doc/basic-project.test

Removed: 




diff  --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp 
b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
index 068eec6599ead8..e3532559a32fcc 100644
--- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -678,6 +678,19 @@ static std::unique_ptr genHTML(const CommentInfo 
&I) {
 return std::move(ParagraphComment);
   }
 
+  if (I.Kind == "BlockCommandComment") {
+auto BlockComment = std::make_unique(HTMLTag::TAG_DIV);
+BlockComment->Children.emplace_back(
+std::make_unique(HTMLTag::TAG_DIV, I.Name));
+for (const auto &Child : I.Children) {
+  std::unique_ptr Node = genHTML(*Child);
+  if (Node)
+BlockComment->Children.emplace_back(std::move(Node));
+}
+if (BlockComment->Children.empty())
+  return nullptr;
+return std::move(BlockComment);
+  }
   if (I.Kind == "TextComment") {
 if (I.Text == "")
   return nullptr;

diff  --git a/clang-tools-extra/test/clang-doc/basic-project.test 
b/clang-tools-extra/test/clang-doc/basic-project.test
index 2865ed4446e7ef..7c46c52bae687c 100644
--- a/clang-tools-extra/test/clang-doc/basic-project.test
+++ b/clang-tools-extra/test/clang-doc/basic-project.test
@@ -56,32 +56,62 @@
 
 // HTML-SHAPE: class Shape
 // HTML-SHAPE: Defined at line 8 of file {{.*}}Shape.h
+// HTML-SHAPE: brief
+// HTML-SHAPE:  Abstract base class for shapes.
 // HTML-SHAPE:  Provides a common interface for 
diff erent types of shapes.
 // HTML-SHAPE: Functions
 // HTML-SHAPE: area
 // HTML-SHAPE: public double area()
+// HTML-SHAPE: brief
+// HTML-SHAPE:  Calculates the area of the shape.
 // HTML-SHAPE: perimeter
 // HTML-SHAPE: public double perimeter()
+// HTML-SHAPE: brief
+// HTML-SHAPE:  Calculates the perimeter of the shape.
+// HTML-SHAPE: return
+// HTML-SHAPE:  double The perimeter of the shape.
 // HTML-SHAPE: ~Shape
 // HTML-SHAPE: public void ~Shape()
 // HTML-SHAPE: Defined at line 13 of file {{.*}}Shape.h
+// HTML-SHAPE: brief
+// HTML-SHAPE:  Virtual destructor.
 
-// HTML-CALC:  class Calculator
-// HTML-CALC:  Defined at line 8 of file {{.*}}Calculator.h
-// HTML-CALC:   Provides basic arithmetic operations.
-// HTML-CALC:  Functions
-// HTML-CALC:  add
-// HTML-CALC:  public int add(int a, int b)
-// HTML-CALC:  Defined at line 3 of file {{.*}}Calculator.cpp
-// HTML-CALC:  subtract
-// HTML-CALC:  public int subtract(int a, int b)
-// HTML-CALC:  Defined at line 7 of file {{.*}}Calculator.cpp
-// HTML-CALC:  multiply
-// HTML-CALC:  public int multiply(int a, int b)
-// HTML-CALC:  Defined at line 11 of file {{.*}}Calculator.cpp
-// HTML-CALC:  divide
-// HTML-CALC:  public double divide(int a, int b)
-// HTML-CALC:  Defined at line 15 of file {{.*}}Calculator.cpp
+// HTML-CALC: class Calculator
+// HTML-CALC: Defined at line 8 of file {{.*}}Calculator.h
+// HTML-CALC: brief
+// HTML-CALC:  A simple calculator class.
+// HTML-CALC:  Provides basic arithmetic operations.
+// HTML-CALC: Functions
+// HTML-CALC: add
+// HTML-CALC: public int add(int a, int b)
+// HTML-CALC: Defined at line 3 of file {{.*}}Calculator.cpp
+// HTML-CALC: brief
+// HTML-CALC:  Adds two integers.
+// HTML-CALC: return
+// HTML-CALC:  int The sum of a and b.
+// HTML-CALC: subtract
+// HTML-CALC: public int subtract(int a, int b)
+// HTML-CALC: Defined at line 7 of file {{.*}}Calculator.cpp
+// HTML-CALC: brief
+// HTML-CALC:  Subtracts the second integer from the first.
+// HTML-CALC: return
+// HTML-CALC:  int The result of a - b.
+// HTML-CALC: multiply
+// HTML-CALC: public int multiply(int a, int b)
+// HTML-CALC: Defined at line 11 of file {{.*}}Calculator.cpp
+// HTML-CALC: brief
+// HTML-CALC:  Multiplies two integers.
+// HTML-CALC: return
+// HTML-CALC:  int The product of a and b.
+// HTML-CALC: divide
+// HTML-CALC: public double divide(int a, int b)
+// HTML-CALC: Defined at line 15 of file {{.*}}Calculator.cpp
+// HTML-CALC: brief
+// HTML-CALC:  Divides the first integer by the second.
+// HTML-CALC: return
+// HTML-CALC:  double The result of a / b.
+// HTML-CALC: throw
+// HTML-CALC: if b is zero.
 
 // HTML-RECTANGLE: class Rectangle
 // HTML-RECTANGLE: Defined at line 10 of file {{.*}}Rectangle.h
@@ -99,15 +129,27 @@
 // HTML-RECTANGLE: Rectangle
 // HTML-RECTANGLE: public void Rectangle(double width, double height)
 // HTML-RECTANGLE: Defined at line 3 of file {{.*}}Rec

[clang-tools-extra] [clang-doc] add support for block commands in clang-doc html output (PR #101108)

2024-08-20 Thread via cfe-commits

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


[clang] [lld] [llvm] [NFC] Cleanup in Support headers. (PR #104825)

2024-08-20 Thread Nikita Popov via cfe-commits

nikic wrote:

> For reference: [compile-time-tracker 
> run](https://llvm-compile-time-tracker.com/compare.php?from=82fdfd4aa7f60b1f8e715211b925a7f2bfe57ea9&to=70b88a21f2c8bc26a0178c6ae9aa2b0834e8&stat=instructions%3Au)
>  with the change (please check the instructions:u for "clang build" at the 
> bottom). See also [the per-file 
> breakdown](https://llvm-compile-time-tracker.com/compare_clang.php?from=82fdfd4aa7f60b1f8e715211b925a7f2bfe57ea9&to=70b88a21f2c8bc26a0178c6ae9aa2b0834e8&stat=instructions%3Au).

This shows compile-time regressions -- that really shouldn't happen for include 
changes.

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


[clang] [lld] [llvm] [NFC] Cleanup in Support headers. (PR #104825)

2024-08-20 Thread Nikita Popov via cfe-commits

nikic wrote:

Best guess on how this could happen: Something depends on a no longer included 
macro via `#if defined`.

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


[clang] [Clang] Add `__builtin_experimental_vectorcompress` (PR #102476)

2024-08-20 Thread Lawrence Benson via cfe-commits

lawben wrote:

Makes sense. I'll try to add the logic for the reamining SVE types in the next 
few days. I've been working on x86 instruction selection for this. I'll wait 
with this PR until both ARM and x86 are supported.

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


[clang] [clang] Support -Wa, options -mmsa and -mno-msa (PR #99615)

2024-08-20 Thread YunQiang Su via cfe-commits

wzssyqa wrote:

I figure out another use case:
```
f:
fadd.w  $w0,$w1,$w2
```

```
# ./bin/clang --target=mipsel-linux-gnu -mfp64 -Wa,-mmsa -fintegrated-as -c 
xx.s 
xx.s:2:2: error: instruction requires a CPU feature not currently enabled
fadd.w  $w0,$w1,$w2
^
```
```
# ./bin/clang --target=mipsel-linux-gnu -mfp64 -Wa,-mmsa -fno-integrated-as -c 
xx.s
# Returns OK.
```

I guess that the use case of `-Wa,-mmsa` is to be compatible with some 
pre-exists software.


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


[clang] [clang] Support -Wa, options -mmsa and -mno-msa (PR #99615)

2024-08-20 Thread YunQiang Su via cfe-commits

wzssyqa wrote:

> I figure out another use case:
> 
> ```
> f:
> fadd.w  $w0,$w1,$w2
> ```
> 
>  ```
> # ./bin/clang --target=mipsel-linux-gnu -mfp64 -Wa,-mmsa -fintegrated-as -c 
> xx.s 
> xx.s:2:2: error: instruction requires a CPU feature not currently enabled
> fadd.w  $w0,$w1,$w2
> ^
> ```
> 
>  ```
> # ./bin/clang --target=mipsel-linux-gnu -mfp64 -Wa,-mmsa -fno-integrated-as 
> -c xx.s
> # Returns OK.
> ```
> 
> I guess that the use case of `-Wa,-mmsa` is to be compatible with some 
> pre-exists software.

So I think that I want to know that which software asks for us to add such 
option?
As I understand, some software may set `AS` env as "CC -Wa,".  Is it?

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


[clang] [clang] Merge lifetimebound and GSL code paths for lifetime analysis (PR #104906)

2024-08-20 Thread Haojian Wu via cfe-commits

https://github.com/hokein created 
https://github.com/llvm/llvm-project/pull/104906

In the current lifetime analysis, we have two parallel code paths: one for 
lifetimebound and another for GSL. These paths perform the same logic, both 
determining whether to continue visiting subexpressions.

This PR merges the two paths into a single code path. As a result, we'll reduce 
the overhead by eliminating a redundant visit to subexpressions. The change is 
mostly NFC (No Functional Change). The only notable difference is that when a 
subexpression is visited due to either lifetimebound or GSL, we will prioritize 
the lifetimebound path. This means the final diagnostic will be -Wdangling 
(rather than both `-Wdangling` and `-Wdangling-gsl`)

This might cause a slight change in behavior if the -Wdangling diagnostic is 
disabled, but I think this is not a major concern since both diagnostics are 
enabled by default.

Fixes #93386 

>From 773a03b25a94d991206f4b517eefdf3693e6a287 Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Tue, 20 Aug 2024 10:22:44 +0200
Subject: [PATCH] [clang] Merge the lifetimebound and GSL code paths for
 lifetime analysis.

---
 clang/docs/ReleaseNotes.rst   |   2 +
 clang/lib/Sema/CheckExprLifetime.cpp  | 129 --
 .../Sema/warn-lifetime-analysis-nocfg.cpp |  13 ++
 3 files changed, 72 insertions(+), 72 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 249249971dec7c..924968452819d1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -225,6 +225,8 @@ Improvements to Clang's diagnostics
 
 - Clang now diagnoses when the result of a [[nodiscard]] function is discarded 
after being cast in C. Fixes #GH104391.
 
+- Don't emit duplicated dangling diagnostics. (#GH93386).
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/lib/Sema/CheckExprLifetime.cpp 
b/clang/lib/Sema/CheckExprLifetime.cpp
index 7389046eaddde1..06eb909659d05d 100644
--- a/clang/lib/Sema/CheckExprLifetime.cpp
+++ b/clang/lib/Sema/CheckExprLifetime.cpp
@@ -326,66 +326,6 @@ static bool shouldTrackFirstArgument(const FunctionDecl 
*FD) {
   return false;
 }
 
-static void handleGslAnnotatedTypes(IndirectLocalPath &Path, Expr *Call,
-LocalVisitor Visit) {
-  auto VisitPointerArg = [&](const Decl *D, Expr *Arg, bool Value) {
-// We are not interested in the temporary base objects of gsl Pointers:
-//   Temp().ptr; // Here ptr might not dangle.
-if (isa(Arg->IgnoreImpCasts()))
-  return;
-// Once we initialized a value with a reference, it can no longer dangle.
-if (!Value) {
-  for (const IndirectLocalPathEntry &PE : llvm::reverse(Path)) {
-if (PE.Kind == IndirectLocalPathEntry::GslReferenceInit)
-  continue;
-if (PE.Kind == IndirectLocalPathEntry::GslPointerInit ||
-PE.Kind == IndirectLocalPathEntry::GslPointerAssignment)
-  return;
-break;
-  }
-}
-Path.push_back({Value ? IndirectLocalPathEntry::GslPointerInit
-  : IndirectLocalPathEntry::GslReferenceInit,
-Arg, D});
-if (Arg->isGLValue())
-  visitLocalsRetainedByReferenceBinding(Path, Arg, RK_ReferenceBinding,
-Visit,
-/*EnableLifetimeWarnings=*/true);
-else
-  visitLocalsRetainedByInitializer(Path, Arg, Visit, true,
-   /*EnableLifetimeWarnings=*/true);
-Path.pop_back();
-  };
-
-  if (auto *MCE = dyn_cast(Call)) {
-const auto *MD = cast_or_null(MCE->getDirectCallee());
-if (MD && shouldTrackImplicitObjectArg(MD))
-  VisitPointerArg(MD, MCE->getImplicitObjectArgument(),
-  !MD->getReturnType()->isReferenceType());
-return;
-  } else if (auto *OCE = dyn_cast(Call)) {
-FunctionDecl *Callee = OCE->getDirectCallee();
-if (Callee && Callee->isCXXInstanceMember() &&
-shouldTrackImplicitObjectArg(cast(Callee)))
-  VisitPointerArg(Callee, OCE->getArg(0),
-  !Callee->getReturnType()->isReferenceType());
-return;
-  } else if (auto *CE = dyn_cast(Call)) {
-FunctionDecl *Callee = CE->getDirectCallee();
-if (Callee && shouldTrackFirstArgument(Callee))
-  VisitPointerArg(Callee, CE->getArg(0),
-  !Callee->getReturnType()->isReferenceType());
-return;
-  }
-
-  if (auto *CCE = dyn_cast(Call)) {
-const auto *Ctor = CCE->getConstructor();
-const CXXRecordDecl *RD = Ctor->getParent();
-if (CCE->getNumArgs() > 0 && RD->hasAttr())
-  VisitPointerArg(Ctor->getParamDecl(0), CCE->getArgs()[0], true);
-  }
-}
-
 static bool implicitObjectParamIsLifetimeBound(const FunctionDecl *FD) {
   const TypeSourceInfo *TSI = FD->getTypeSourceInfo();
   if (!TSI)
@@ -423,8 +363,10 @@ static bool implicitObjectParamIsLife

[clang] [X86][AVX10] Fix unexpected error and warning when using intrinsic (PR #104781)

2024-08-20 Thread Freddy Ye via cfe-commits

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

LGTM

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


[clang] [Clang] Add [[clang::diagnose_specializations]] (PR #101469)

2024-08-20 Thread Nikolas Klauser via cfe-commits


@@ -3327,6 +3330,15 @@ def DiagnoseIf : InheritableAttr {
   let Documentation = [DiagnoseIfDocs];
 }
 
+def DiagnoseSpecializations : InheritableAttr {
+  let Spellings = [Clang<"diagnose_specializations", /*AllowInC*/0>];
+  let Args = [StringArgument<"Message", 1>];

philnik777 wrote:

The idea of this attribute is that it says "if you specialize this anything 
could happen, so don't do it". I don't think it makes a ton of sense to give 
the choice of making this a warning by default on the attribute level.

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


[clang] [Clang] Add [[clang::diagnose_specializations]] (PR #101469)

2024-08-20 Thread Nikolas Klauser via cfe-commits


@@ -3327,6 +3330,15 @@ def DiagnoseIf : InheritableAttr {
   let Documentation = [DiagnoseIfDocs];
 }
 
+def DiagnoseSpecializations : InheritableAttr {
+  let Spellings = [Clang<"diagnose_specializations", /*AllowInC*/0>];

philnik777 wrote:

Do explicit specializations include partial specializations?

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


[clang] [X86][AVX10] Fix unexpected error and warning when using intrinsic (PR #104781)

2024-08-20 Thread Shengchen Kan via cfe-commits

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

LGTM

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


[clang] [clang] Support -Wa, options -mmsa and -mno-msa (PR #99615)

2024-08-20 Thread via cfe-commits

yingopq wrote:




> > I figure out another use case:
> > ```
> > f:
> > fadd.w  $w0,$w1,$w2
> > ```
> > 
> > 
> > 
> >   
> > 
> > 
> >   
> > 
> > 
> > 
> >   
> > ```
> > # ./bin/clang --target=mipsel-linux-gnu -mfp64 -Wa,-mmsa -fintegrated-as -c 
> > xx.s 
> > xx.s:2:2: error: instruction requires a CPU feature not currently enabled
> >fadd.w  $w0,$w1,$w2
> >^
> > ```
> > 
> > 
> > 
> >   
> > 
> > 
> >   
> > 
> > 
> > 
> >   
> > ```
> > # ./bin/clang --target=mipsel-linux-gnu -mfp64 -Wa,-mmsa -fno-integrated-as 
> > -c xx.s
> > # Returns OK.
> > ```
> > 
> > 
> > 
> >   
> > 
> > 
> >   
> > 
> > 
> > 
> >   
> > I guess that the use case of `-Wa,-mmsa` is to be compatible with some 
> > pre-exists software.
> 
> So I think that I want to know that which software asks for us to add such 
> option? As I understand, some software may set `AS` env as "CC -Wa,". Is 
> it?

This is a required task @FlyGoat mentioned before.

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


[clang] [clang] Support -Wa, options -mmsa and -mno-msa (PR #99615)

2024-08-20 Thread Jiaxun Yang via cfe-commits

FlyGoat wrote:

Yes, such usage is required by FFmpeg

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


[clang] [clang][bytecode] Fix discarding CompoundLiteralExprs (PR #104909)

2024-08-20 Thread Timm Baeder via cfe-commits

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

None

>From 6d45a286525465b4832e4ee01fa747db871f002e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Tue, 20 Aug 2024 11:02:25 +0200
Subject: [PATCH] [clang][bytecode] Fix discarding CompoundLiteralExprs

---
 clang/lib/AST/ByteCode/Compiler.cpp | 6 +++---
 clang/test/AST/ByteCode/c23.c   | 5 -
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 131b83ae8eb397..87d7a67e9ca932 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -2325,6 +2325,9 @@ bool Compiler::VisitCXXBindTemporaryExpr(
 template 
 bool Compiler::VisitCompoundLiteralExpr(const CompoundLiteralExpr *E) 
{
   const Expr *Init = E->getInitializer();
+  if (DiscardResult)
+return this->discard(Init);
+
   if (Initializing) {
 // We already have a value, just initialize that.
 return this->visitInitializer(Init) && this->emitFinishInit(E);
@@ -2378,9 +2381,6 @@ bool Compiler::VisitCompoundLiteralExpr(const 
CompoundLiteralExpr *E) {
   if (!this->visitInitializer(Init) || !this->emitFinishInit(E))
 return false;
 }
-
-if (DiscardResult)
-  return this->emitPopPtr(E);
 return true;
   }
 
diff --git a/clang/test/AST/ByteCode/c23.c b/clang/test/AST/ByteCode/c23.c
index e839fc716f5b52..f9157e40610cc3 100644
--- a/clang/test/AST/ByteCode/c23.c
+++ b/clang/test/AST/ByteCode/c23.c
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 -std=c23 -fexperimental-new-constant-interpreter 
-verify=expected,both %s
 // RUN: %clang_cc1 -std=c23 -verify=ref,both %s
 
-
+typedef typeof(nullptr) nullptr_t;
 
 const _Bool inf1 =  (1.0/0.0 == __builtin_inf());
 constexpr _Bool inf2 = (1.0/0.0 == __builtin_inf()); // both-error {{must be 
initialized by a constant expression}} \
@@ -22,3 +22,6 @@ char bar() {
   ((struct S *)buffer)->c = 'a';
   return ((struct S *)buffer)->c;
 }
+
+
+static_assert((nullptr_t){} == 0);

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


[clang] [clang][bytecode] Fix discarding CompoundLiteralExprs (PR #104909)

2024-08-20 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes



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


2 Files Affected:

- (modified) clang/lib/AST/ByteCode/Compiler.cpp (+3-3) 
- (modified) clang/test/AST/ByteCode/c23.c (+4-1) 


``diff
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 131b83ae8eb397..87d7a67e9ca932 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -2325,6 +2325,9 @@ bool Compiler::VisitCXXBindTemporaryExpr(
 template 
 bool Compiler::VisitCompoundLiteralExpr(const CompoundLiteralExpr *E) 
{
   const Expr *Init = E->getInitializer();
+  if (DiscardResult)
+return this->discard(Init);
+
   if (Initializing) {
 // We already have a value, just initialize that.
 return this->visitInitializer(Init) && this->emitFinishInit(E);
@@ -2378,9 +2381,6 @@ bool Compiler::VisitCompoundLiteralExpr(const 
CompoundLiteralExpr *E) {
   if (!this->visitInitializer(Init) || !this->emitFinishInit(E))
 return false;
 }
-
-if (DiscardResult)
-  return this->emitPopPtr(E);
 return true;
   }
 
diff --git a/clang/test/AST/ByteCode/c23.c b/clang/test/AST/ByteCode/c23.c
index e839fc716f5b52..f9157e40610cc3 100644
--- a/clang/test/AST/ByteCode/c23.c
+++ b/clang/test/AST/ByteCode/c23.c
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 -std=c23 -fexperimental-new-constant-interpreter 
-verify=expected,both %s
 // RUN: %clang_cc1 -std=c23 -verify=ref,both %s
 
-
+typedef typeof(nullptr) nullptr_t;
 
 const _Bool inf1 =  (1.0/0.0 == __builtin_inf());
 constexpr _Bool inf2 = (1.0/0.0 == __builtin_inf()); // both-error {{must be 
initialized by a constant expression}} \
@@ -22,3 +22,6 @@ char bar() {
   ((struct S *)buffer)->c = 'a';
   return ((struct S *)buffer)->c;
 }
+
+
+static_assert((nullptr_t){} == 0);

``




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


[clang] 522c253 - [Coroutines] Salvage the debug information for coroutine frames within optimizations

2024-08-20 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2024-08-20T17:21:43+08:00
New Revision: 522c253f47ea27d8eeb759e06f8749092b1de71e

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

LOG: [Coroutines] Salvage the debug information for coroutine frames within 
optimizations

This patch tries to salvage the debug information for the coroutine
frames within optimizations by creating the help alloca varaibles with
optimizations too. We didn't do this when I implement it initially. I
roughtly remember the reason was, we feel the additional help alloca
variable may pessimize the performance, which is almost the most
important thing under optimizations. But now, it looks like the new
inserted help alloca variables can be optimized out by the following
optimizations. So it looks like the time to make it available within
optimizations.

And also, it looks like the following optimizations will convert the
generated dbg.declare instrinsic into dbg.value intrinsic within
optimizations.

In LLVM's test, there is a slightly regression
that a dbg.declare for the promise object failed to be remained after
this change. But it looks like we won't have a chance to see dbg.declare
for the promise object when we split the coroutine as that dbg.declare
will be converted into a dbg.value in early stage.

So everything looks fine.

Added: 
clang/test/CodeGenCoroutines/coro-dwarf-O2.cpp

Modified: 
llvm/lib/Transforms/Coroutines/CoroFrame.cpp
llvm/lib/Transforms/Coroutines/CoroInternal.h
llvm/lib/Transforms/Coroutines/CoroSplit.cpp
llvm/test/Transforms/Coroutines/coro-debug-O2.ll

Removed: 




diff  --git a/clang/test/CodeGenCoroutines/coro-dwarf-O2.cpp 
b/clang/test/CodeGenCoroutines/coro-dwarf-O2.cpp
new file mode 100644
index 00..53f4a07982e427
--- /dev/null
+++ b/clang/test/CodeGenCoroutines/coro-dwarf-O2.cpp
@@ -0,0 +1,39 @@
+// Check that we can still observe the value of the coroutine frame
+// with optimizations.
+//
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 \
+// RUN:   -emit-llvm %s -debug-info-kind=limited -dwarf-version=5 \
+// RUN:   -O2 -o - | FileCheck %s
+
+#include "Inputs/coroutine.h"
+
+template <>
+struct std::coroutine_traits {
+  struct promise_type {
+void get_return_object();
+std::suspend_always initial_suspend();
+std::suspend_always final_suspend() noexcept;
+void return_void();
+void unhandled_exception();
+  };
+};
+
+struct ScalarAwaiter {
+  template  void await_suspend(F);
+  bool await_ready();
+  int await_resume();
+};
+
+extern "C" void UseScalar(int);
+
+extern "C" void f() {
+  UseScalar(co_await ScalarAwaiter{});
+
+  int Val = co_await ScalarAwaiter{};
+
+  co_await ScalarAwaiter{};
+}
+
+// CHECK: define {{.*}}@f.resume({{.*}} %[[ARG:.*]])
+// CHECK:  #dbg_value(ptr %[[ARG]], ![[CORO_NUM:[0-9]+]], 
!DIExpression(DW_OP_deref)
+// CHECK: ![[CORO_NUM]] = !DILocalVariable(name: "__coro_frame"

diff  --git a/llvm/lib/Transforms/Coroutines/CoroFrame.cpp 
b/llvm/lib/Transforms/Coroutines/CoroFrame.cpp
index fa04735340406d..00f49b7bdce294 100644
--- a/llvm/lib/Transforms/Coroutines/CoroFrame.cpp
+++ b/llvm/lib/Transforms/Coroutines/CoroFrame.cpp
@@ -1914,8 +1914,7 @@ static void insertSpills(const FrameDataInfo &FrameData, 
coro::Shape &Shape) {
   }
   // This dbg.declare is for the main function entry point.  It
   // will be deleted in all coro-split functions.
-  coro::salvageDebugInfo(ArgToAllocaMap, *DDI, Shape.OptimizeFrame,
- false /*UseEntryValue*/);
+  coro::salvageDebugInfo(ArgToAllocaMap, *DDI, false 
/*UseEntryValue*/);
 };
 for_each(DIs, SalvageOne);
 for_each(DVRs, SalvageOne);
@@ -2852,9 +2851,8 @@ static void collectFrameAlloca(AllocaInst *AI, 
coro::Shape &Shape,
 
 static std::optional>
 salvageDebugInfoImpl(SmallDenseMap 
&ArgToAllocaMap,
- bool OptimizeFrame, bool UseEntryValue, Function *F,
- Value *Storage, DIExpression *Expr,
- bool SkipOutermostLoad) {
+ bool UseEntryValue, Function *F, Value *Storage,
+ DIExpression *Expr, bool SkipOutermostLoad) {
   IRBuilder<> Builder(F->getContext());
   auto InsertPt = F->getEntryBlock().getFirstInsertionPt();
   while (isa(InsertPt))
@@ -2906,10 +2904,9 @@ salvageDebugInfoImpl(SmallDenseMap &ArgToAllocaMap,
 
   // If the coroutine frame is an Argument, store it in an alloca to improve
   // its availability (e.g. registers may be clobbered).
-  // Avoid this if optimizations are enabled (they would remove the alloca) or
-  // if the value is guaranteed to be available through other means (e.g. swift
-  // ABI guarantees).
-  if (StorageAsArg && !OptimizeFrame && !IsSwiftAs

[clang] [clang-forma] Support `PointerAlignment` for pointers to members (PR #86253)

2024-08-20 Thread kadir çetinkaya via cfe-commits

kadircet wrote:

Hi folks, I am a little confused about the behavior introduced by this patch.

I was expecting `Foo::*` in `Type Foo::* name` to be treated as a single entity 
and whole thing to be aligned with `name` or spaced away from it, Rather than 
splitting `*` . To add some more from the grammar, Pointers, and 
pointers-to-members are grammatically different:
- The former is introduced by appending `*` to another declarator, see 
https://eel.is/c++draft/dcl.ptr.
- Whereas the latter is introduced by appending `nested-name-spec*`, see 
https://eel.is/c++draft/dcl.mptr.

So I think there is value in keeping `nested-name-spec` and `*` together and 
moving the whole `nested-name-spec::*` block, rather than just moving `*` left 
or right. e.g, instead of `int Foo:: *member;` we should prefer:
- `int Foo::*member;` or -- pointer alignment right
- `int Foo::* member;` -- pointer alignment left

Looking at the bug https://github.com/llvm/llvm-project/issues/85761, I can't 
see any strong indications towards just moving `*` around. Moreover user is 
actually talking about space between `::*` and `name`, hence I think they were 
also intending for `::*` to stay together.

Changing behavior to keep `nested-name-specifier` and `*` together also ensures 
this is a no-op when pointer-alignment is right.

Were there any strong reasons to perform a split after `::`?

---

Second surprising change is around method pointers, we currently have 
[logic](https://github.com/llvm/llvm-project/blame/a6d81cdf896d901e0f5e672b9a3eccc4ae8759ce/clang/lib/Format/TokenAnnotator.cpp#L4597)
 to never separate pointer and name in function-pointers like `void (*foo)();`. 
This applied to method-pointers as well, e.g. `void (Foo::*f)();`. After this 
change we introduced a different behavior for this case when we have a method 
pointer instead of function pointer.

Was this change intentional? If not can we restore the unified behavior between 
handling of method-pointers and function-pointers? This issue is also reported 
by https://github.com/llvm/llvm-project/issues/100841, cc @vogelsgesang 

P.S. I am happy to do these changes myself, I just want to make sure we agree 
on the desired behaviors here.

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


[clang] [clang][bytecode] Fix initializing base casts (PR #104901)

2024-08-20 Thread Timm Baeder via cfe-commits

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


[clang] ba7dadf - [clang][bytecode] Fix initializing base casts (#104901)

2024-08-20 Thread via cfe-commits

Author: Timm Baeder
Date: 2024-08-20T11:44:30+02:00
New Revision: ba7dadf0e918cbb0e6867d78aebd0cc3fc843bcc

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

LOG: [clang][bytecode] Fix initializing base casts (#104901)

Use delegate() there. To fix a follow-up problem, abort when a cast ends
up on a valid Pointer that isn't a base class.

Added: 


Modified: 
clang/lib/AST/ByteCode/Compiler.cpp
clang/lib/AST/ByteCode/Interp.h
clang/test/Modules/merge-using-decls.cpp

Removed: 




diff  --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 131b83ae8eb397..0af473f9bd0802 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -214,7 +214,7 @@ bool Compiler::VisitCastExpr(const CastExpr *CE) {
 unsigned DerivedOffset = collectBaseOffset(QualType(ToMP->getClass(), 0),
QualType(FromMP->getClass(), 
0));
 
-if (!this->visit(SubExpr))
+if (!this->delegate(SubExpr))
   return false;
 
 return this->emitGetMemberPtrBasePop(DerivedOffset, CE);
@@ -229,14 +229,14 @@ bool Compiler::VisitCastExpr(const CastExpr *CE) 
{
 unsigned DerivedOffset = collectBaseOffset(QualType(FromMP->getClass(), 0),
QualType(ToMP->getClass(), 0));
 
-if (!this->visit(SubExpr))
+if (!this->delegate(SubExpr))
   return false;
 return this->emitGetMemberPtrBasePop(-DerivedOffset, CE);
   }
 
   case CK_UncheckedDerivedToBase:
   case CK_DerivedToBase: {
-if (!this->visit(SubExpr))
+if (!this->delegate(SubExpr))
   return false;
 
 const auto extractRecordDecl = [](QualType Ty) -> const CXXRecordDecl * {
@@ -265,7 +265,7 @@ bool Compiler::VisitCastExpr(const CastExpr *CE) {
   }
 
   case CK_BaseToDerived: {
-if (!this->visit(SubExpr))
+if (!this->delegate(SubExpr))
   return false;
 
 unsigned DerivedOffset =

diff  --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index bad46e98304845..b805b7b246c51b 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -1568,7 +1568,7 @@ inline bool GetPtrBase(InterpState &S, CodePtr OpPC, 
uint32_t Off) {
   if (!CheckSubobject(S, OpPC, Ptr, CSK_Base))
 return false;
   const Pointer &Result = Ptr.atField(Off);
-  if (Result.isPastEnd())
+  if (Result.isPastEnd() || !Result.isBaseClass())
 return false;
   S.Stk.push(Result);
   return true;
@@ -1581,7 +1581,7 @@ inline bool GetPtrBasePop(InterpState &S, CodePtr OpPC, 
uint32_t Off) {
   if (!CheckSubobject(S, OpPC, Ptr, CSK_Base))
 return false;
   const Pointer &Result = Ptr.atField(Off);
-  if (Result.isPastEnd())
+  if (Result.isPastEnd() || !Result.isBaseClass())
 return false;
   S.Stk.push(Result);
   return true;

diff  --git a/clang/test/Modules/merge-using-decls.cpp 
b/clang/test/Modules/merge-using-decls.cpp
index e9794a40837ef9..b678eb4e0f851f 100644
--- a/clang/test/Modules/merge-using-decls.cpp
+++ b/clang/test/Modules/merge-using-decls.cpp
@@ -8,6 +8,7 @@
 // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -x 
c++ -I%S/Inputs/merge-using-decls -verify -std=c++11 %s -DORDER=2
 
 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -fmodules 
-fimplicit-module-maps -fmodules-cache-path=%t -x c++ 
-I%S/Inputs/merge-using-decls -verify -std=c++17 %s -DORDER=2
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -fmodules 
-fimplicit-module-maps -fexperimental-new-constant-interpreter 
-fmodules-cache-path=%t -x c++ -I%S/Inputs/merge-using-decls -verify -std=c++98 
%s -DORDER=1
 
 #if ORDER == 1
 #include "a.h"



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


[clang] [Clang][test] Add bytecode interpreter tests for floating comparison functions (PR #104703)

2024-08-20 Thread Timm Baeder via cfe-commits

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


[clang] f1b6427 - [Clang][test] Add bytecode interpreter tests for floating comparison functions (#104703)

2024-08-20 Thread via cfe-commits

Author: Mital Ashok
Date: 2024-08-20T11:45:33+02:00
New Revision: f1b642775f11c6defd06eea64df22a465b46a0ce

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

LOG: [Clang][test] Add bytecode interpreter tests for floating comparison 
functions (#104703)

See also: #94118, 71801707e33c235656b172fa7dfb8662473a95c2

Added: 


Modified: 
clang/test/AST/ByteCode/builtin-functions.cpp

Removed: 




diff  --git a/clang/test/AST/ByteCode/builtin-functions.cpp 
b/clang/test/AST/ByteCode/builtin-functions.cpp
index b179298fee9bde..1cff2228cd7a97 100644
--- a/clang/test/AST/ByteCode/builtin-functions.cpp
+++ b/clang/test/AST/ByteCode/builtin-functions.cpp
@@ -193,6 +193,51 @@ namespace isfpclass {
   char isfpclass_snan_3   [!__builtin_isfpclass(__builtin_nans(""), 0x01F8) ? 
1 : -1]; // fcFinite
 }
 
+namespace signbit {
+  static_assert(
+!__builtin_signbit(1.0) && __builtin_signbit(-1.0) && 
!__builtin_signbit(0.0) && __builtin_signbit(-0.0) &&
+!__builtin_signbitf(1.0f) && __builtin_signbitf(-1.0f) && 
!__builtin_signbitf(0.0f) && __builtin_signbitf(-0.0f) &&
+!__builtin_signbitl(1.0L) && __builtin_signbitf(-1.0L) && 
!__builtin_signbitf(0.0L) && __builtin_signbitf(-0.0L) &&
+!__builtin_signbit(1.0f) && __builtin_signbit(-1.0f) && 
!__builtin_signbit(0.0f) && __builtin_signbit(-0.0f) &&
+!__builtin_signbit(1.0L) && __builtin_signbit(-1.0L) && 
!__builtin_signbit(0.0L) && __builtin_signbit(-0.0L) &&
+true, ""
+  );
+}
+
+namespace floating_comparison {
+#define LESS(X, Y) \
+  !__builtin_isgreater(X, Y) && __builtin_isgreater(Y, X) && \
+  !__builtin_isgreaterequal(X, Y) && __builtin_isgreaterequal(Y, X) &&   \
+  __builtin_isless(X, Y) && !__builtin_isless(Y, X) &&   \
+  __builtin_islessequal(X, Y) && !__builtin_islessequal(Y, X) && \
+  __builtin_islessgreater(X, Y) && __builtin_islessgreater(Y, X) &&  \
+  !__builtin_isunordered(X, Y) && !__builtin_isunordered(Y, X)
+#define EQUAL(X, Y) \
+  !__builtin_isgreater(X, Y) && !__builtin_isgreater(Y, X) &&\
+  __builtin_isgreaterequal(X, Y) && __builtin_isgreaterequal(Y, X) &&\
+  !__builtin_isless(X, Y) && !__builtin_isless(Y, X) &&  \
+  __builtin_islessequal(X, Y) && __builtin_islessequal(Y, X) &&  \
+  !__builtin_islessgreater(X, Y) && !__builtin_islessgreater(Y, X) &&\
+  !__builtin_isunordered(X, Y) && !__builtin_isunordered(Y, X)
+#define UNORDERED(X, Y) \
+  !__builtin_isgreater(X, Y) && !__builtin_isgreater(Y, X) &&\
+  !__builtin_isgreaterequal(X, Y) && !__builtin_isgreaterequal(Y, X) &&  \
+  !__builtin_isless(X, Y) && !__builtin_isless(Y, X) &&  \
+  !__builtin_islessequal(X, Y) && !__builtin_islessequal(Y, X) &&\
+  !__builtin_islessgreater(X, Y) && !__builtin_islessgreater(Y, X) &&\
+  __builtin_isunordered(X, Y) && __builtin_isunordered(Y, X)
+
+  static_assert(
+LESS(0.0, 1.0) && EQUAL(1.0, 1.0) && EQUAL(0.0, -0.0) &&
+UNORDERED(__builtin_nan(""), 1.0) && UNORDERED(__builtin_nan(""), 
__builtin_inf()) && LESS(0.0, __builtin_inf()) &&
+LESS(0.0f, 1.0f) && EQUAL(1.0f, 1.0f) && EQUAL(0.0f, -0.0f) &&
+UNORDERED(__builtin_nanf(""), 1.0f) && UNORDERED(__builtin_nanf(""), 
__builtin_inff()) && LESS(0.0f, __builtin_inff()) &&
+LESS(0.0L, 1.0L) && EQUAL(1.0L, 1.0L) && EQUAL(0.0L, -0.0L) &&
+UNORDERED(__builtin_nanl(""), 1.0L) && UNORDERED(__builtin_nanl(""), 
__builtin_infl()) && LESS(0.0L, __builtin_infl()) &&
+true, ""
+  );
+}
+
 namespace fpclassify {
   char classify_nan [__builtin_fpclassify(+1, -1, -1, -1, -1, 
__builtin_nan(""))];
   char classify_snan[__builtin_fpclassify(+1, -1, -1, -1, -1, 
__builtin_nans(""))];



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


[clang] [RFC][C++20][Modules] Fix crash when function and lambda inside loaded from different modules (PR #104512)

2024-08-20 Thread Dmitry Polukhin via cfe-commits

https://github.com/dmpolukhin updated 
https://github.com/llvm/llvm-project/pull/104512

>From 8e11c66e4515bb35671853b89152b43d1ff60ffa Mon Sep 17 00:00:00 2001
From: Dmitry Polukhin 
Date: Thu, 15 Aug 2024 14:03:57 -0700
Subject: [PATCH 1/3] [RFC][C++20][Modules] Fix crash when function and lambda
 inside loaded from different modules
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Summary:
Because AST loading code is lazy and happens in unpredictable order it could 
happen that function and lambda inside function can be loaded from different 
modules. In this case, captured DeclRefExpr won’t match the corresponding 
VarDecl inside function. In AST it looks like this:
```
FunctionDecl 0x64f4aff0  line:33:35 imported in 
./thrift_cpp2_base.h hidden tryTo 'Expected ()' inline
|-also in ./folly-conv.h
`-CompoundStmt 0x64f7cfc8 
  |-DeclStmt 0x64f7ced8 
  | `-VarDecl 0x64f7cef8  col:7 imported in 
./thrift_cpp2_base.h hidden referenced result 'Tgt' cinit
  |   `-IntegerLiteral 0x64f7d080  'int' 0
  |-CallExpr 0x64f7cea8  ''
  | |-UnresolvedLookupExpr 0x64f7bea0  '' lvalue (no ADL) = 'then_' 0x64f7bef0
  | |-CXXTemporaryObjectExpr 0x64f7bcb0  'Expected':'folly::Expected' 'void () noexcept' zeroing
  | `-LambdaExpr 0x64f7bc88  '(lambda at Conv.h:39:48)'
  |   |-CXXRecordDecl 0x64f76b88  col:48 imported in ./folly-conv.h 
hidden implicit  class definition
  |   | |-also in ./thrift_cpp2_base.h
  |   | `-DefinitionData lambda empty standard_layout trivially_copyable 
literal can_const_default_init
  |   |   |-DefaultConstructor defaulted_is_constexpr
  |   |   |-CopyConstructor simple trivial has_const_param needs_implicit 
implicit_has_const_param
  |   |   |-MoveConstructor exists simple trivial needs_implicit
  |   |   |-CopyAssignment trivial has_const_param needs_implicit 
implicit_has_const_param
  |   |   |-MoveAssignment
  |   |   `-Destructor simple irrelevant trivial constexpr needs_implicit
  |   `-CompoundStmt 0x64f7d1a8 
  | `-ReturnStmt 0x64f7d198 
  |   `-DeclRefExpr 0x64f7d0a0  'Tgt' lvalue Var 0x64f7d0c8 
'result' 'Tgt' refers_to_enclosing_variable_or_capture
  `-ReturnStmt 0x64f7bc78 
`-InitListExpr 0x64f7bc38  'void'
```
I’m not sure that it is the right fix for the problem so any ideas how to fix 
it better are very appreciated.

Test Plan: check-clang
---
 ...rash-instantiated-in-scope-cxx-modules.cpp | 76 +++
 1 file changed, 76 insertions(+)
 create mode 100644 
clang/test/Headers/crash-instantiated-in-scope-cxx-modules.cpp

diff --git a/clang/test/Headers/crash-instantiated-in-scope-cxx-modules.cpp 
b/clang/test/Headers/crash-instantiated-in-scope-cxx-modules.cpp
new file mode 100644
index 00..80844a58ad825a
--- /dev/null
+++ b/clang/test/Headers/crash-instantiated-in-scope-cxx-modules.cpp
@@ -0,0 +1,76 @@
+// RUN: rm -fR %t
+// RUN: split-file %s %t
+// RUN: cd %t
+// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header 
-Werror=uninitialized folly-conv.h
+// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header 
-Werror=uninitialized thrift_cpp2_base.h
+// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header 
-Werror=uninitialized -fmodule-file=folly-conv.pcm 
-fmodule-file=thrift_cpp2_base.pcm logger_base.h
+
+//--- Conv.h
+#pragma once
+
+template 
+_Up __declval(int);
+
+template 
+auto declval() noexcept -> decltype(__declval<_Tp>(0));
+
+namespace folly {
+
+template 
+struct Expected {
+  template 
+  auto thenOrThrow() -> decltype(declval()) {
+return 1;
+  }
+};
+
+struct ExpectedHelper {
+  template 
+  static constexpr Expected return_(T) {
+return Expected();
+  }
+
+  template 
+  static auto then_(This&&, Fn&&)
+  -> decltype(T::template return_((declval()(true), 0))) {
+return Expected();
+  }
+};
+
+template 
+inline Expected tryTo() {
+  Tgt result = 0;
+  // In build with asserts:
+  // clang/lib/Sema/SemaTemplateInstantiate.cpp: llvm::PointerUnion 
*clang::LocalInstantiationScope::findInstantiationOf(const Decl *): Assertion 
`isa(D) && "declaration not instantiated in this scope"' failed.
+  // In release build compilation error on the line below inside lambda:
+  // error: variable 'result' is uninitialized when used here 
[-Werror,-Wuninitialized]
+  ExpectedHelper::then_(Expected(), [&](bool) { return result; });
+  return {};
+}
+
+} // namespace folly
+
+inline void bar() {
+  folly::tryTo();
+}
+// expected-no-diagnostics
+
+//--- folly-conv.h
+#pragma once
+#include "Conv.h"
+// expected-no-diagnostics
+
+//--- thrift_cpp2_base.h
+#pragma once
+#include "Conv.h"
+// expected-no-diagnostics
+
+//--- logger_base.h
+#pragma once
+import "folly-conv.h";
+import "thrift_cpp2_base.h";
+
+inline void foo() {
+  folly::tryTo();
+}
+// expected-no-diagnostics

>From 02e09990e08de701c4efe952e4ff3e2070055cd2 Mon Sep 17 00:00:00 2001
From: Dmitry Polukhin 
Date: Thu, 15 Aug 2024 1

[clang] [clang][bytecode] Fix initializing base casts (PR #104901)

2024-08-20 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`openmp-offload-amdgpu-runtime` running on `omp-vega20-0` while building 
`clang` at step 7 "Add check check-offload".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/30/builds/4371

Here is the relevant piece of the build log for the reference:
```
Step 7 (Add check check-offload) failure: test (failure)
 TEST 'libomptarget :: amdgcn-amd-amdhsa :: 
sanitizer/kernel_crash_async.c' FAILED 
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 3
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/clang 
-fopenmp-I 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test -I 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -L 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload
 -L /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib -L 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
  -nogpulib 
-Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload
 
-Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib 
 -fopenmp-targets=amdgcn-amd-amdhsa -O3 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test/sanitizer/kernel_crash_async.c
 -o 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/sanitizer/Output/kernel_crash_async.c.tmp
 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib/libomptarget.devicertl.a
# executed command: 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/clang 
-fopenmp -I 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test -I 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -L 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload
 -L /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib -L 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -nogpulib 
-Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload
 
-Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib 
-fopenmp-targets=amdgcn-amd-amdhsa -O3 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test/sanitizer/kernel_crash_async.c
 -o 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/sanitizer/Output/kernel_crash_async.c.tmp
 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib/libomptarget.devicertl.a
# note: command had no output on stdout or stderr
# RUN: at line 4
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/not --crash 
env -u LLVM_DISABLE_SYMBOLIZATION OFFLOAD_TRACK_NUM_KERNEL_LAUNCH_TRACES=1 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/sanitizer/Output/kernel_crash_async.c.tmp
 2>&1 | 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/FileCheck 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test/sanitizer/kernel_crash_async.c
 --check-prefixes=TRACE
# executed command: 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/not --crash 
env -u LLVM_DISABLE_SYMBOLIZATION OFFLOAD_TRACK_NUM_KERNEL_LAUNCH_TRACES=1 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/sanitizer/Output/kernel_crash_async.c.tmp
# note: command had no output on stdout or stderr
# executed command: 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/FileCheck 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test/sanitizer/kernel_crash_async.c
 --check-prefixes=TRACE
# note: command had no output on stdout or stderr
# RUN: at line 5
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/not --crash 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/sanitizer/Output/kernel_crash_async.c.tmp
 2>&1 | 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/FileCheck 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test/sanitizer/kernel_crash_async.c
 --check-prefixes=CHECK
# executed command: 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/not --crash 
/home/ompworker/bbot/ope

[clang] [RFC][C++20][Modules] Fix crash when function and lambda inside loaded from different modules (PR #104512)

2024-08-20 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 059e7be2d1e4397fd40ecaaf913b8a4bfe759779 
70a504833bfb540b54bbbe86e8065cf22bdf286b --extensions cpp -- 
clang/test/Headers/crash-instantiated-in-scope-cxx-modules.cpp 
clang/lib/AST/DeclTemplate.cpp clang/test/Modules/odr_hash.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp
index 7dc9afd615..bdd40b01c0 100644
--- a/clang/lib/AST/DeclTemplate.cpp
+++ b/clang/lib/AST/DeclTemplate.cpp
@@ -354,7 +354,7 @@ void 
RedeclarableTemplateDecl::loadLazySpecializationsImpl() const {
 // This order matches the order in which namelookup discovers declarations
 // coming from modules.
 for (unsigned I = SpecSize; I != 0; --I)
-  (void)Context.getExternalSource()->GetExternalDecl(Specs[I-1]);
+  (void)Context.getExternalSource()->GetExternalDecl(Specs[I - 1]);
   }
 }
 

``




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


[clang] [RFC][C++20][Modules] Fix crash when function and lambda inside loaded from different modules (PR #104512)

2024-08-20 Thread Dmitry Polukhin via cfe-commits

https://github.com/dmpolukhin updated 
https://github.com/llvm/llvm-project/pull/104512

>From 8e11c66e4515bb35671853b89152b43d1ff60ffa Mon Sep 17 00:00:00 2001
From: Dmitry Polukhin 
Date: Thu, 15 Aug 2024 14:03:57 -0700
Subject: [PATCH 1/4] [RFC][C++20][Modules] Fix crash when function and lambda
 inside loaded from different modules
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Summary:
Because AST loading code is lazy and happens in unpredictable order it could 
happen that function and lambda inside function can be loaded from different 
modules. In this case, captured DeclRefExpr won’t match the corresponding 
VarDecl inside function. In AST it looks like this:
```
FunctionDecl 0x64f4aff0  line:33:35 imported in 
./thrift_cpp2_base.h hidden tryTo 'Expected ()' inline
|-also in ./folly-conv.h
`-CompoundStmt 0x64f7cfc8 
  |-DeclStmt 0x64f7ced8 
  | `-VarDecl 0x64f7cef8  col:7 imported in 
./thrift_cpp2_base.h hidden referenced result 'Tgt' cinit
  |   `-IntegerLiteral 0x64f7d080  'int' 0
  |-CallExpr 0x64f7cea8  ''
  | |-UnresolvedLookupExpr 0x64f7bea0  '' lvalue (no ADL) = 'then_' 0x64f7bef0
  | |-CXXTemporaryObjectExpr 0x64f7bcb0  'Expected':'folly::Expected' 'void () noexcept' zeroing
  | `-LambdaExpr 0x64f7bc88  '(lambda at Conv.h:39:48)'
  |   |-CXXRecordDecl 0x64f76b88  col:48 imported in ./folly-conv.h 
hidden implicit  class definition
  |   | |-also in ./thrift_cpp2_base.h
  |   | `-DefinitionData lambda empty standard_layout trivially_copyable 
literal can_const_default_init
  |   |   |-DefaultConstructor defaulted_is_constexpr
  |   |   |-CopyConstructor simple trivial has_const_param needs_implicit 
implicit_has_const_param
  |   |   |-MoveConstructor exists simple trivial needs_implicit
  |   |   |-CopyAssignment trivial has_const_param needs_implicit 
implicit_has_const_param
  |   |   |-MoveAssignment
  |   |   `-Destructor simple irrelevant trivial constexpr needs_implicit
  |   `-CompoundStmt 0x64f7d1a8 
  | `-ReturnStmt 0x64f7d198 
  |   `-DeclRefExpr 0x64f7d0a0  'Tgt' lvalue Var 0x64f7d0c8 
'result' 'Tgt' refers_to_enclosing_variable_or_capture
  `-ReturnStmt 0x64f7bc78 
`-InitListExpr 0x64f7bc38  'void'
```
I’m not sure that it is the right fix for the problem so any ideas how to fix 
it better are very appreciated.

Test Plan: check-clang
---
 ...rash-instantiated-in-scope-cxx-modules.cpp | 76 +++
 1 file changed, 76 insertions(+)
 create mode 100644 
clang/test/Headers/crash-instantiated-in-scope-cxx-modules.cpp

diff --git a/clang/test/Headers/crash-instantiated-in-scope-cxx-modules.cpp 
b/clang/test/Headers/crash-instantiated-in-scope-cxx-modules.cpp
new file mode 100644
index 00..80844a58ad825a
--- /dev/null
+++ b/clang/test/Headers/crash-instantiated-in-scope-cxx-modules.cpp
@@ -0,0 +1,76 @@
+// RUN: rm -fR %t
+// RUN: split-file %s %t
+// RUN: cd %t
+// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header 
-Werror=uninitialized folly-conv.h
+// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header 
-Werror=uninitialized thrift_cpp2_base.h
+// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header 
-Werror=uninitialized -fmodule-file=folly-conv.pcm 
-fmodule-file=thrift_cpp2_base.pcm logger_base.h
+
+//--- Conv.h
+#pragma once
+
+template 
+_Up __declval(int);
+
+template 
+auto declval() noexcept -> decltype(__declval<_Tp>(0));
+
+namespace folly {
+
+template 
+struct Expected {
+  template 
+  auto thenOrThrow() -> decltype(declval()) {
+return 1;
+  }
+};
+
+struct ExpectedHelper {
+  template 
+  static constexpr Expected return_(T) {
+return Expected();
+  }
+
+  template 
+  static auto then_(This&&, Fn&&)
+  -> decltype(T::template return_((declval()(true), 0))) {
+return Expected();
+  }
+};
+
+template 
+inline Expected tryTo() {
+  Tgt result = 0;
+  // In build with asserts:
+  // clang/lib/Sema/SemaTemplateInstantiate.cpp: llvm::PointerUnion 
*clang::LocalInstantiationScope::findInstantiationOf(const Decl *): Assertion 
`isa(D) && "declaration not instantiated in this scope"' failed.
+  // In release build compilation error on the line below inside lambda:
+  // error: variable 'result' is uninitialized when used here 
[-Werror,-Wuninitialized]
+  ExpectedHelper::then_(Expected(), [&](bool) { return result; });
+  return {};
+}
+
+} // namespace folly
+
+inline void bar() {
+  folly::tryTo();
+}
+// expected-no-diagnostics
+
+//--- folly-conv.h
+#pragma once
+#include "Conv.h"
+// expected-no-diagnostics
+
+//--- thrift_cpp2_base.h
+#pragma once
+#include "Conv.h"
+// expected-no-diagnostics
+
+//--- logger_base.h
+#pragma once
+import "folly-conv.h";
+import "thrift_cpp2_base.h";
+
+inline void foo() {
+  folly::tryTo();
+}
+// expected-no-diagnostics

>From 02e09990e08de701c4efe952e4ff3e2070055cd2 Mon Sep 17 00:00:00 2001
From: Dmitry Polukhin 
Date: Thu, 15 Aug 2024 1

[clang] [RFC][C++20][Modules] Fix crash when function and lambda inside loaded from different modules (PR #104512)

2024-08-20 Thread Dmitry Polukhin via cfe-commits

https://github.com/dmpolukhin updated 
https://github.com/llvm/llvm-project/pull/104512

>From 8e11c66e4515bb35671853b89152b43d1ff60ffa Mon Sep 17 00:00:00 2001
From: Dmitry Polukhin 
Date: Thu, 15 Aug 2024 14:03:57 -0700
Subject: [PATCH 1/4] [RFC][C++20][Modules] Fix crash when function and lambda
 inside loaded from different modules
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Summary:
Because AST loading code is lazy and happens in unpredictable order it could 
happen that function and lambda inside function can be loaded from different 
modules. In this case, captured DeclRefExpr won’t match the corresponding 
VarDecl inside function. In AST it looks like this:
```
FunctionDecl 0x64f4aff0  line:33:35 imported in 
./thrift_cpp2_base.h hidden tryTo 'Expected ()' inline
|-also in ./folly-conv.h
`-CompoundStmt 0x64f7cfc8 
  |-DeclStmt 0x64f7ced8 
  | `-VarDecl 0x64f7cef8  col:7 imported in 
./thrift_cpp2_base.h hidden referenced result 'Tgt' cinit
  |   `-IntegerLiteral 0x64f7d080  'int' 0
  |-CallExpr 0x64f7cea8  ''
  | |-UnresolvedLookupExpr 0x64f7bea0  '' lvalue (no ADL) = 'then_' 0x64f7bef0
  | |-CXXTemporaryObjectExpr 0x64f7bcb0  'Expected':'folly::Expected' 'void () noexcept' zeroing
  | `-LambdaExpr 0x64f7bc88  '(lambda at Conv.h:39:48)'
  |   |-CXXRecordDecl 0x64f76b88  col:48 imported in ./folly-conv.h 
hidden implicit  class definition
  |   | |-also in ./thrift_cpp2_base.h
  |   | `-DefinitionData lambda empty standard_layout trivially_copyable 
literal can_const_default_init
  |   |   |-DefaultConstructor defaulted_is_constexpr
  |   |   |-CopyConstructor simple trivial has_const_param needs_implicit 
implicit_has_const_param
  |   |   |-MoveConstructor exists simple trivial needs_implicit
  |   |   |-CopyAssignment trivial has_const_param needs_implicit 
implicit_has_const_param
  |   |   |-MoveAssignment
  |   |   `-Destructor simple irrelevant trivial constexpr needs_implicit
  |   `-CompoundStmt 0x64f7d1a8 
  | `-ReturnStmt 0x64f7d198 
  |   `-DeclRefExpr 0x64f7d0a0  'Tgt' lvalue Var 0x64f7d0c8 
'result' 'Tgt' refers_to_enclosing_variable_or_capture
  `-ReturnStmt 0x64f7bc78 
`-InitListExpr 0x64f7bc38  'void'
```
I’m not sure that it is the right fix for the problem so any ideas how to fix 
it better are very appreciated.

Test Plan: check-clang
---
 ...rash-instantiated-in-scope-cxx-modules.cpp | 76 +++
 1 file changed, 76 insertions(+)
 create mode 100644 
clang/test/Headers/crash-instantiated-in-scope-cxx-modules.cpp

diff --git a/clang/test/Headers/crash-instantiated-in-scope-cxx-modules.cpp 
b/clang/test/Headers/crash-instantiated-in-scope-cxx-modules.cpp
new file mode 100644
index 00..80844a58ad825a
--- /dev/null
+++ b/clang/test/Headers/crash-instantiated-in-scope-cxx-modules.cpp
@@ -0,0 +1,76 @@
+// RUN: rm -fR %t
+// RUN: split-file %s %t
+// RUN: cd %t
+// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header 
-Werror=uninitialized folly-conv.h
+// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header 
-Werror=uninitialized thrift_cpp2_base.h
+// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header 
-Werror=uninitialized -fmodule-file=folly-conv.pcm 
-fmodule-file=thrift_cpp2_base.pcm logger_base.h
+
+//--- Conv.h
+#pragma once
+
+template 
+_Up __declval(int);
+
+template 
+auto declval() noexcept -> decltype(__declval<_Tp>(0));
+
+namespace folly {
+
+template 
+struct Expected {
+  template 
+  auto thenOrThrow() -> decltype(declval()) {
+return 1;
+  }
+};
+
+struct ExpectedHelper {
+  template 
+  static constexpr Expected return_(T) {
+return Expected();
+  }
+
+  template 
+  static auto then_(This&&, Fn&&)
+  -> decltype(T::template return_((declval()(true), 0))) {
+return Expected();
+  }
+};
+
+template 
+inline Expected tryTo() {
+  Tgt result = 0;
+  // In build with asserts:
+  // clang/lib/Sema/SemaTemplateInstantiate.cpp: llvm::PointerUnion 
*clang::LocalInstantiationScope::findInstantiationOf(const Decl *): Assertion 
`isa(D) && "declaration not instantiated in this scope"' failed.
+  // In release build compilation error on the line below inside lambda:
+  // error: variable 'result' is uninitialized when used here 
[-Werror,-Wuninitialized]
+  ExpectedHelper::then_(Expected(), [&](bool) { return result; });
+  return {};
+}
+
+} // namespace folly
+
+inline void bar() {
+  folly::tryTo();
+}
+// expected-no-diagnostics
+
+//--- folly-conv.h
+#pragma once
+#include "Conv.h"
+// expected-no-diagnostics
+
+//--- thrift_cpp2_base.h
+#pragma once
+#include "Conv.h"
+// expected-no-diagnostics
+
+//--- logger_base.h
+#pragma once
+import "folly-conv.h";
+import "thrift_cpp2_base.h";
+
+inline void foo() {
+  folly::tryTo();
+}
+// expected-no-diagnostics

>From 02e09990e08de701c4efe952e4ff3e2070055cd2 Mon Sep 17 00:00:00 2001
From: Dmitry Polukhin 
Date: Thu, 15 Aug 2024 1

[clang] [Clang] Add [[clang::diagnose_specializations]] (PR #101469)

2024-08-20 Thread via cfe-commits

https://github.com/cor3ntin commented:

I like the general idea 


- I would prefer this to be called `no_specializations` or 
`disallow_specializations`
- I would like to see more tests to what it can mor cannot be applied to (for 
example an explicit specialization, a variable template, an alias)
- In the same vein, can this be applied to a partial specialization to prevent 
subsequent specializations?
- I think the diagnostic should say `note: marked `[[clang::no_specialization]] 
here`


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


[clang] [lld] [llvm] [NFC] Cleanup in Support headers. (PR #104825)

2024-08-20 Thread Daniil Fukalov via cfe-commits

https://github.com/dfukalov updated 
https://github.com/llvm/llvm-project/pull/104825

>From cce13227c78d3d1831fb8773fc52005fabd412c6 Mon Sep 17 00:00:00 2001
From: dfukalov 
Date: Mon, 19 Aug 2024 20:02:52 +0200
Subject: [PATCH 1/4] [NFC] Cleanup in Support headers.

Remove unused directly includes and forward declarations in Support headers.
---
 clang/lib/CodeGen/ObjectFilePCHContainerWriter.cpp  | 1 +
 clang/lib/Format/Format.cpp | 1 +
 clang/lib/Format/FormatTokenSource.h| 1 +
 clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp   | 1 +
 clang/tools/driver/driver.cpp   | 1 +
 clang/unittests/Format/MacroCallReconstructorTest.cpp   | 1 +
 lld/ELF/Writer.cpp  | 1 +
 lld/MachO/BPSectionOrderer.cpp  | 1 +
 lld/MachO/Dwarf.cpp | 1 +
 lld/MachO/SectionPriorities.cpp | 1 +
 lld/wasm/WriterUtils.h  | 1 +
 llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h | 1 -
 llvm/include/llvm/Support/Atomic.h  | 2 +-
 llvm/include/llvm/Support/BalancedPartitioning.h| 3 ++-
 llvm/include/llvm/Support/BinaryStreamReader.h  | 1 -
 llvm/include/llvm/Support/BranchProbability.h   | 1 -
 llvm/include/llvm/Support/CRC.h | 2 +-
 llvm/include/llvm/Support/CachePruning.h| 4 +++-
 llvm/include/llvm/Support/Casting.h | 1 -
 llvm/include/llvm/Support/Chrono.h  | 5 +
 llvm/include/llvm/Support/CommandLine.h | 4 
 llvm/include/llvm/Support/Compression.h | 6 --
 llvm/include/llvm/Support/ConvertEBCDIC.h   | 4 +++-
 llvm/include/llvm/Support/DataExtractor.h   | 1 -
 llvm/include/llvm/Support/DebugCounter.h| 4 ++--
 llvm/include/llvm/Support/ELFAttributeParser.h  | 1 -
 llvm/include/llvm/Support/Error.h   | 3 ---
 llvm/include/llvm/Support/ErrorHandling.h   | 2 --
 llvm/include/llvm/Support/ExponentialBackoff.h  | 2 --
 llvm/include/llvm/Support/FileOutputBuffer.h| 1 -
 llvm/include/llvm/Support/FileUtilities.h   | 2 --
 llvm/include/llvm/Support/FormatVariadic.h  | 1 -
 llvm/include/llvm/Support/LineIterator.h| 1 -
 llvm/include/llvm/Support/LockFileManager.h | 1 -
 llvm/include/llvm/Support/MathExtras.h  | 1 -
 llvm/include/llvm/Support/Memory.h  | 1 -
 llvm/include/llvm/Support/OptimizedStructLayout.h   | 3 ++-
 llvm/include/llvm/Support/PGOOptions.h  | 2 +-
 llvm/include/llvm/Support/Path.h| 1 -
 llvm/include/llvm/Support/PrettyStackTrace.h| 1 -
 llvm/include/llvm/Support/Process.h | 1 -
 llvm/include/llvm/Support/RandomNumberGenerator.h   | 2 --
 llvm/include/llvm/Support/ScopedPrinter.h   | 1 -
 llvm/include/llvm/Support/SpecialCaseList.h | 1 -
 llvm/include/llvm/Support/ThreadPool.h  | 3 +--
 llvm/include/llvm/Support/Threading.h   | 1 -
 llvm/include/llvm/Support/Timer.h   | 1 -
 llvm/include/llvm/Support/TypeSize.h| 1 -
 llvm/include/llvm/Support/VirtualFileSystem.h   | 1 -
 llvm/include/llvm/Support/Watchdog.h| 2 --
 llvm/include/llvm/Support/WithColor.h   | 1 -
 llvm/include/llvm/Support/raw_ostream.h | 2 --
 llvm/include/llvm/Testing/ADT/StringMap.h   | 1 -
 llvm/lib/Analysis/AliasAnalysis.cpp | 1 +
 llvm/lib/Analysis/DXILMetadataAnalysis.cpp  | 1 +
 llvm/lib/Analysis/DXILResource.cpp  | 1 +
 llvm/lib/Analysis/InlineAdvisor.cpp | 1 +
 llvm/lib/Analysis/InlineOrder.cpp   | 1 +
 llvm/lib/Analysis/InteractiveModelRunner.cpp| 1 +
 llvm/lib/Analysis/ReplayInlineAdvisor.cpp   | 1 +
 llvm/lib/Analysis/StackSafetyAnalysis.cpp   | 1 +
 llvm/lib/Bitcode/Writer/BitcodeWriterPass.cpp   | 1 +
 llvm/lib/CodeGen/MachineCFGPrinter.cpp  | 2 +-
 llvm/lib/CodeGen/ReplaceWithVeclib.cpp  | 1 +
 llvm/lib/DebugInfo/BTF/BTFParser.cpp| 1 +
 llvm/lib/DebugInfo/DWARF/DWARFLocationExpression.cpp| 1 +
 llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp  | 1 +
 llvm/lib/ExecutionEngine/Orc/OrcABISupport.cpp  | 1 +
 llvm/lib/ExecutionEngine/Orc/TargetProcess/JITLoader

[clang] [Clang][NFCI] Cleanup the fix for default function substitution (PR #104911)

2024-08-20 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 created 
https://github.com/llvm/llvm-project/pull/104911

(This is one step towards tweaking getTemplateInstantiationArgs() as discussed 
in https://github.com/llvm/llvm-project/pull/102922)

We don't always substitute into default arguments while transforming a function 
parameter. In that case, we would preserve the uninstantiated expression until 
after, e.g. building up a CXXDefaultArgExpr and instantiating the expression 
there.

For member function instantiation, this algorithm used to cause a problem in 
that the default argument of an out-of-line member function specialization 
couldn't get properly instantiated. This is because, in 
getTemplateInstantiationArgs(), we would give up visiting a function's 
declaration context if the function is a specialization of a member template. 
For example,

```cpp
template 
struct S {
  template 
  void f(T = sizeof(T));
};

template <> template 
void S::f(int) {}
```

The default argument `sizeof(U)` that lexically appears inside the declaration 
would be copied to the function declaration in the class template 
specialization S, as well as to the function's out-of-line definition. We 
use template arguments collected from the out-of-line function definition when 
substituting into the default arguments. We would therefore give up the 
traversal after the function, resulting in a single-level template argument of 
the f itself. However the default argument here could still reference the 
template parameters of the primary template, hence the error.

In fact, this is similar to constraint checking in some respects: we actually 
want the "whole" template arguments relative to the primary template, not those 
relative to the function definition. So this patch adds another flag to 
indicate getTemplateInstantiationArgs() for that.

This patch also consolidates the tests for default arguments and removes some 
unnecessary tests.

>From c8b8360fe046d38452f71479368c21e217468ddb Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Tue, 20 Aug 2024 17:18:35 +0800
Subject: [PATCH] [Clang][NFCI] Cleanup the fix for default function
 substitution

---
 clang/include/clang/Sema/Sema.h   |   9 +-
 clang/lib/Sema/SemaTemplateInstantiate.cpp|  23 +--
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |  10 +-
 clang/test/SemaTemplate/default-arguments.cpp |  55 ++
 clang/test/SemaTemplate/default-parm-init.cpp | 186 --
 5 files changed, 77 insertions(+), 206 deletions(-)

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 2ec6367eccea01..84df847726e6d2 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -13053,12 +13053,19 @@ class Sema final : public SemaBase {
   /// ForConstraintInstantiation indicates we should continue looking when
   /// encountering a lambda generic call operator, and continue looking for
   /// arguments on an enclosing class template.
+  ///
+  /// \param SkipForSpecialization when specified, any template specializations
+  /// in a traversal would be ignored.
+  /// \param ForDefaultArgumentSubstitution indicates we should continue 
looking
+  /// when encountering a specialized member function template, rather than
+  /// returning immediately.
   MultiLevelTemplateArgumentList getTemplateInstantiationArgs(
   const NamedDecl *D, const DeclContext *DC = nullptr, bool Final = false,
   std::optional> Innermost = std::nullopt,
   bool RelativeToPrimary = false, const FunctionDecl *Pattern = nullptr,
   bool ForConstraintInstantiation = false,
-  bool SkipForSpecialization = false);
+  bool SkipForSpecialization = false,
+  bool ForDefaultArgumentSubstitution = false);
 
   /// RAII object to handle the state changes required to synthesize
   /// a function body.
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index de470739ab78e7..feed797de838dd 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -255,7 +255,8 @@ HandleClassTemplateSpec(const 
ClassTemplateSpecializationDecl *ClassTemplSpec,
 Response HandleFunction(Sema &SemaRef, const FunctionDecl *Function,
 MultiLevelTemplateArgumentList &Result,
 const FunctionDecl *Pattern, bool RelativeToPrimary,
-bool ForConstraintInstantiation) {
+bool ForConstraintInstantiation,
+bool ForDefaultArgumentSubstitution) {
   // Add template arguments from a function template specialization.
   if (!RelativeToPrimary &&
   Function->getTemplateSpecializationKindForInstantiation() ==
@@ -285,7 +286,8 @@ Response HandleFunction(Sema &SemaRef, const FunctionDecl 
*Function,
 // If this function was instantiated from a specialized member that is
 // a function template, we're done.
 assert(Function->getPrimaryTemplate() &

[clang] [clang][NFC] order C++ standards in reverse in release notes (PR #104866)

2024-08-20 Thread via cfe-commits

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


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


[clang] [lld] [llvm] [NFC] Cleanup in Support headers. (PR #104825)

2024-08-20 Thread Sergei Barannikov via cfe-commits


@@ -17,7 +17,7 @@
 #ifndef LLVM_SUPPORT_ATOMIC_H
 #define LLVM_SUPPORT_ATOMIC_H
 
-#include "llvm/Support/DataTypes.h"
+#include 

s-barannikov wrote:

```suggestion
#include 
```

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


[clang] [lld] [llvm] [NFC] Cleanup in Support headers. (PR #104825)

2024-08-20 Thread Sergei Barannikov via cfe-commits


@@ -13,7 +13,7 @@
 #ifndef LLVM_SUPPORT_CRC_H
 #define LLVM_SUPPORT_CRC_H
 
-#include "llvm/Support/DataTypes.h"
+#include 

s-barannikov wrote:

```suggestion
#include 
```

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


[clang] [clang] Merge lifetimebound and GSL code paths for lifetime analysis (PR #104906)

2024-08-20 Thread Gábor Horváth via cfe-commits

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


[clang] [clang] Merge lifetimebound and GSL code paths for lifetime analysis (PR #104906)

2024-08-20 Thread Gábor Horváth via cfe-commits

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

LGTM, thanks! 

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


[clang] [clang] Merge lifetimebound and GSL code paths for lifetime analysis (PR #104906)

2024-08-20 Thread Gábor Horváth via cfe-commits


@@ -478,13 +449,32 @@ static void visitLifetimeBoundArguments(IndirectLocalPath 
&Path, Expr *Call,
   CheckCoroObjArg = false;
 if (implicitObjectParamIsLifetimeBound(Callee) || CheckCoroObjArg)
   VisitLifetimeBoundArg(Callee, ObjectArg);
+else if (EnableLifetimeWarnings) {
+  if (auto *CME = dyn_cast(Callee);
+  CME && shouldTrackImplicitObjectArg(CME))
+VisitGSLPointerArg(Callee, ObjectArg,
+!Callee->getReturnType()->isReferenceType());
+}
   }
 
   for (unsigned I = 0,
 N = std::min(Callee->getNumParams(), Args.size());
I != N; ++I) {
 if (CheckCoroCall || Callee->getParamDecl(I)->hasAttr())
   VisitLifetimeBoundArg(Callee->getParamDecl(I), Args[I]);
+else if (EnableLifetimeWarnings) {
+  if (I == 0) {

Xazax-hun wrote:

Nit: maybe `EnableLifetimeWarnings && I == 0` to reduce the indentation?

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


[clang] [clang] Merge lifetimebound and GSL code paths for lifetime analysis (PR #104906)

2024-08-20 Thread Gábor Horváth via cfe-commits

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


[clang] [clang] Emit -Wdangling diagnoses for cases where a gsl-pointer is construct from a gsl-owner object in a container. (PR #104556)

2024-08-20 Thread Utkarsh Saxena via cfe-commits


@@ -344,9 +347,11 @@ static void handleGslAnnotatedTypes(IndirectLocalPath 
&Path, Expr *Call,
 break;
   }
 }
-Path.push_back({Value ? IndirectLocalPathEntry::GslPointerInit
-  : IndirectLocalPathEntry::GslReferenceInit,
-Arg, D});
+
+Path.push_back({!ReturnType->isReferenceType()
+? IndirectLocalPathEntry::GslPointerInit
+: IndirectLocalPathEntry::GslReferenceInit,

usx95 wrote:

nit: simplify without `!`
`ReturnType->isReferenceType() ? IndirectLocalPathEntry::GslReferenceInit: 
IndirectLocalPathEntry::GslPointerInit`

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


[clang] [clang] Emit -Wdangling diagnoses for cases where a gsl-pointer is construct from a gsl-owner object in a container. (PR #104556)

2024-08-20 Thread Utkarsh Saxena via cfe-commits

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


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


[clang] [clang] Emit -Wdangling diagnoses for cases where a gsl-pointer is construct from a gsl-owner object in a container. (PR #104556)

2024-08-20 Thread Utkarsh Saxena via cfe-commits


@@ -360,29 +365,26 @@ static void handleGslAnnotatedTypes(IndirectLocalPath 
&Path, Expr *Call,
   if (auto *MCE = dyn_cast(Call)) {
 const auto *MD = cast_or_null(MCE->getDirectCallee());
 if (MD && shouldTrackImplicitObjectArg(MD))
-  VisitPointerArg(MD, MCE->getImplicitObjectArgument(),
-  !MD->getReturnType()->isReferenceType());
+  VisitPointerArg(MD, MCE->getImplicitObjectArgument());
 return;
   } else if (auto *OCE = dyn_cast(Call)) {
 FunctionDecl *Callee = OCE->getDirectCallee();
 if (Callee && Callee->isCXXInstanceMember() &&
 shouldTrackImplicitObjectArg(cast(Callee)))
-  VisitPointerArg(Callee, OCE->getArg(0),
-  !Callee->getReturnType()->isReferenceType());
+  VisitPointerArg(Callee, OCE->getArg(0));
 return;
   } else if (auto *CE = dyn_cast(Call)) {
 FunctionDecl *Callee = CE->getDirectCallee();
 if (Callee && shouldTrackFirstArgument(Callee))
-  VisitPointerArg(Callee, CE->getArg(0),
-  !Callee->getReturnType()->isReferenceType());
+  VisitPointerArg(Callee, CE->getArg(0));
 return;
   }
 
   if (auto *CCE = dyn_cast(Call)) {
 const auto *Ctor = CCE->getConstructor();
 const CXXRecordDecl *RD = Ctor->getParent();
 if (CCE->getNumArgs() > 0 && RD->hasAttr())
-  VisitPointerArg(Ctor->getParamDecl(0), CCE->getArgs()[0], true);
+  VisitPointerArg(Ctor, CCE->getArgs()[0]);

usx95 wrote:

Is this a no-op change ? i.e., passing Ctor instead of the param decl ?

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


[clang] [Clang] Add __builtin_is_within_lifetime to implement P2641R4's std::is_within_lifetime (PR #91895)

2024-08-20 Thread Mital Ashok via cfe-commits


@@ -3760,6 +3765,9 @@ findSubobject(EvalInfo &Info, const Expr *E, const 
CompleteObject &Obj,
 if ((O->isAbsent() && !(handler.AccessKind == AK_Construct && I == N)) ||
 (O->isIndeterminate() &&
  !isValidIndeterminateAccess(handler.AccessKind))) {
+  // Object has ended lifetime since pointer was formed
+  if (handler.AccessKind == AK_IsWithinLifetime)
+return false;

MitalAshok wrote:

There are already other `return false;`/`return true;` returns in 
`findSubobject`, so `findSubobject::result_type` must be constructible from bool

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


[clang] [Clang] Add __builtin_is_within_lifetime to implement P2641R4's std::is_within_lifetime (PR #91895)

2024-08-20 Thread Mital Ashok via cfe-commits


@@ -17264,3 +17288,76 @@ bool Expr::tryEvaluateStrLen(uint64_t &Result, 
ASTContext &Ctx) const {
   EvalInfo Info(Ctx, Status, EvalInfo::EM_ConstantFold);
   return EvaluateBuiltinStrLen(this, Result, Info);
 }
+
+namespace {
+struct IsWithinLifetimeHandler {
+  EvalInfo &Info;
+  static constexpr AccessKinds AccessKind = AccessKinds::AK_IsWithinLifetime;
+  using result_type = std::optional;
+  std::optional failed() { return std::nullopt; }
+  template 
+  std::optional found(T &Subobj, QualType SubobjType) {
+return true;
+  }
+};
+
+std::optional EvaluateBuiltinIsWithinLifetime(IntExprEvaluator &IEE,
+const CallExpr *E) {
+  EvalInfo &Info = IEE.Info;
+  // Sometimes this is called during some sorts of constant folding / early
+  // evaluation. These are meant for non-constant expressions and are not
+  // necessary since this consteval builtin will never be evaluated at runtime.
+  // Just fail to evaluate when not in a constant context.
+  if (!Info.InConstantContext)
+return std::nullopt;
+  assert(E->getBuiltinCallee() == Builtin::BI__builtin_is_within_lifetime);
+  const Expr *Arg = E->getArg(0);
+  if (Arg->isValueDependent())
+return std::nullopt;
+  LValue Val;
+  if (!EvaluatePointer(Arg, Val, Info))
+return std::nullopt;
+
+  auto Error = [&](int Diag) {
+const auto *Callee = Info.CurrentCall->getCallee();
+bool CalledFromStd = Callee && Callee->isInStdNamespace() &&
+ Callee->getIdentifier() &&
+ Callee->getIdentifier()->isStr("is_within_lifetime");
+Info.report(CalledFromStd ? Info.CurrentCall->getCallRange().getBegin()
+  : E->getExprLoc(),
+diag::err_invalid_is_within_lifetime)
+<< (CalledFromStd ? "std::is_within_lifetime"
+  : "__builtin_is_within_lifetime")
+<< Diag;
+return std::nullopt;
+  };
+  // C++2c [meta.const.eval]p4:
+  //   During the evaluation of an expression E as a core constant expression, 
a
+  //   call to this function is ill-formed unless p points to an object that is
+  //   usable in constant expressions or whose complete object's lifetime began
+  //   within E.
+
+  // Make sure it points to an object
+  // nullptr does not point to an object
+  if (Val.isNullPointer() || Val.getLValueBase().isNull())
+return Error(0);
+  QualType T = Val.getLValueBase().getType();
+  if (T->isFunctionType())
+return Error(1);
+  assert(T->isObjectType());
+  // Hypothetical array element is not an object
+  if (Val.getLValueDesignator().isOnePastTheEnd())
+return Error(2);
+  assert(Val.getLValueDesignator().isValidSubobject() &&
+ "Unchecked case for valid subobject");
+  // All other ill-formed values should have failed EvaluatePointer, so the
+  // object should be a pointer to an object that is usable in a constant
+  // expression or whose complete lifetime began within the expression
+  CompleteObject CO =
+  findCompleteObject(Info, E, AccessKinds::AK_IsWithinLifetime, Val, T);
+  if (!CO)
+return false;
+  IsWithinLifetimeHandler handler{Info};
+  return findSubobject(Info, E, CO, Val.getLValueDesignator(), handler);

MitalAshok wrote:

Yeah, it's intentional: `std::nullopt` -> this call was ill-formed, `false` -> 
this is a well-formed call and results in `false`, `true` -> this is a 
well-formed call that results in `true`. I especially want the second one to 
return `false` instead of nullopt

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


[clang] [llvm] [NVPTX] Support __usAtomicCAS builtin (PR #99646)

2024-08-20 Thread via cfe-commits

https://github.com/DenisGZM updated 
https://github.com/llvm/llvm-project/pull/99646

>From accdc9bee5a6f2ee2add330dd8d06d280cd13b64 Mon Sep 17 00:00:00 2001
From: Denis Gerasimov 
Date: Fri, 19 Jul 2024 15:47:57 +0300
Subject: [PATCH 1/8] [NVPTX] Support __usAtomicCAS builtin

---
 clang/include/clang/Basic/BuiltinsNVPTX.def   |  3 +++
 clang/lib/CodeGen/CGBuiltin.cpp   |  3 +++
 clang/lib/Headers/__clang_cuda_device_functions.h | 12 
 clang/test/CodeGen/builtins-nvptx.c   |  3 +++
 llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp   |  2 +-
 llvm/lib/Target/NVPTX/NVPTXIntrinsics.td  | 15 +++
 6 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/BuiltinsNVPTX.def 
b/clang/include/clang/Basic/BuiltinsNVPTX.def
index 504314d8d96e91..3cf683a2f21298 100644
--- a/clang/include/clang/Basic/BuiltinsNVPTX.def
+++ b/clang/include/clang/Basic/BuiltinsNVPTX.def
@@ -829,6 +829,9 @@ BUILTIN(__nvvm_atom_xor_gen_ll, "LLiLLiD*LLi", "n")
 TARGET_BUILTIN(__nvvm_atom_cta_xor_gen_ll, "LLiLLiD*LLi", "n", SM_60)
 TARGET_BUILTIN(__nvvm_atom_sys_xor_gen_ll, "LLiLLiD*LLi", "n", SM_60)
 
+TARGET_BUILTIN(__nvvm_atom_cas_gen_us, "UsUsD*UsUs", "n", SM_70)
+TARGET_BUILTIN(__nvvm_atom_cta_cas_gen_us, "UsUsD*UsUs", "n", SM_70)
+TARGET_BUILTIN(__nvvm_atom_sys_cas_gen_us, "UsUsD*UsUs", "n", SM_70)
 BUILTIN(__nvvm_atom_cas_gen_i, "iiD*ii", "n")
 TARGET_BUILTIN(__nvvm_atom_cta_cas_gen_i, "iiD*ii", "n", SM_60)
 TARGET_BUILTIN(__nvvm_atom_sys_cas_gen_i, "iiD*ii", "n", SM_60)
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index f424ddaa175400..769b3ce1886baf 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -20357,6 +20357,7 @@ Value *CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned 
BuiltinID,
   case NVPTX::BI__nvvm_atom_min_gen_ull:
 return MakeBinaryAtomicValue(*this, llvm::AtomicRMWInst::UMin, E);
 
+  case NVPTX::BI__nvvm_atom_cas_gen_us:
   case NVPTX::BI__nvvm_atom_cas_gen_i:
   case NVPTX::BI__nvvm_atom_cas_gen_l:
   case NVPTX::BI__nvvm_atom_cas_gen_ll:
@@ -20548,6 +20549,7 @@ Value *CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned 
BuiltinID,
   case NVPTX::BI__nvvm_atom_sys_xor_gen_l:
   case NVPTX::BI__nvvm_atom_sys_xor_gen_ll:
 return MakeScopedAtomic(Intrinsic::nvvm_atomic_xor_gen_i_sys, *this, E);
+  case NVPTX::BI__nvvm_atom_cta_cas_gen_us:
   case NVPTX::BI__nvvm_atom_cta_cas_gen_i:
   case NVPTX::BI__nvvm_atom_cta_cas_gen_l:
   case NVPTX::BI__nvvm_atom_cta_cas_gen_ll: {
@@ -20559,6 +20561,7 @@ Value *CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned 
BuiltinID,
 Intrinsic::nvvm_atomic_cas_gen_i_cta, {ElemTy, Ptr->getType()}),
 {Ptr, EmitScalarExpr(E->getArg(1)), EmitScalarExpr(E->getArg(2))});
   }
+  case NVPTX::BI__nvvm_atom_sys_cas_gen_us:
   case NVPTX::BI__nvvm_atom_sys_cas_gen_i:
   case NVPTX::BI__nvvm_atom_sys_cas_gen_l:
   case NVPTX::BI__nvvm_atom_sys_cas_gen_ll: {
diff --git a/clang/lib/Headers/__clang_cuda_device_functions.h 
b/clang/lib/Headers/__clang_cuda_device_functions.h
index f8a12cefdb81b4..f66fe625a39676 100644
--- a/clang/lib/Headers/__clang_cuda_device_functions.h
+++ b/clang/lib/Headers/__clang_cuda_device_functions.h
@@ -529,6 +529,18 @@ __DEVICE__ void __threadfence(void) { __nvvm_membar_gl(); }
 __DEVICE__ void __threadfence_block(void) { __nvvm_membar_cta(); };
 __DEVICE__ void __threadfence_system(void) { __nvvm_membar_sys(); };
 __DEVICE__ void __trap(void) { __asm__ __volatile__("trap;"); }
+__DEVICE__ unsigned short __usAtomicCAS(unsigned short *__p, unsigned short 
__cmp,
+unsigned short __v) {
+  return __nvvm_atom_cas_gen_us(__p, __cmp, __v);
+}
+__DEVICE__ unsigned short __usAtomicCAS_block(unsigned short *__p, unsigned 
short __cmp,
+  unsigned short __v) {
+  return __nvvm_atom_cta_cas_gen_us(__p, __cmp, __v);
+}
+__DEVICE__ unsigned short __usAtomicCAS_system(unsigned short *__p, unsigned 
short __cmp,
+   unsigned short __v) {
+  return __nvvm_atom_sys_cas_gen_us(__p, __cmp, __v);
+}
 __DEVICE__ unsigned int __uAtomicAdd(unsigned int *__p, unsigned int __v) {
   return __nvvm_atom_add_gen_i((int *)__p, __v);
 }
diff --git a/clang/test/CodeGen/builtins-nvptx.c 
b/clang/test/CodeGen/builtins-nvptx.c
index 75b9d6d1fe1902..3ba1fabd05335e 100644
--- a/clang/test/CodeGen/builtins-nvptx.c
+++ b/clang/test/CodeGen/builtins-nvptx.c
@@ -306,6 +306,9 @@ __device__ void nvvm_atom(float *fp, float f, double *dfp, 
double df, int *ip,
   // CHECK: atomicrmw umin ptr {{.*}} seq_cst, align 8
   __nvvm_atom_min_gen_ull((unsigned long long *)&sll, ll);
 
+  // CHECK: cmpxchg ptr {{.*}} seq_cst seq_cst, align 2
+  // CHECK-NEXT: extractvalue { i16, i1 } {{%[0-9]+}}, 0
+  __nvvm_atom_cas_gen_us(ip, 0, i);
   // CHECK: cmpxchg ptr {{.*}} seq_cst seq_cst, align 4
   // CHECK-NEXT: extractvalue { 

[clang] [llvm] [NVPTX] Support __usAtomicCAS builtin (PR #99646)

2024-08-20 Thread via cfe-commits

https://github.com/DenisGZM updated 
https://github.com/llvm/llvm-project/pull/99646

>From accdc9bee5a6f2ee2add330dd8d06d280cd13b64 Mon Sep 17 00:00:00 2001
From: Denis Gerasimov 
Date: Fri, 19 Jul 2024 15:47:57 +0300
Subject: [PATCH 1/8] [NVPTX] Support __usAtomicCAS builtin

---
 clang/include/clang/Basic/BuiltinsNVPTX.def   |  3 +++
 clang/lib/CodeGen/CGBuiltin.cpp   |  3 +++
 clang/lib/Headers/__clang_cuda_device_functions.h | 12 
 clang/test/CodeGen/builtins-nvptx.c   |  3 +++
 llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp   |  2 +-
 llvm/lib/Target/NVPTX/NVPTXIntrinsics.td  | 15 +++
 6 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/BuiltinsNVPTX.def 
b/clang/include/clang/Basic/BuiltinsNVPTX.def
index 504314d8d96e91..3cf683a2f21298 100644
--- a/clang/include/clang/Basic/BuiltinsNVPTX.def
+++ b/clang/include/clang/Basic/BuiltinsNVPTX.def
@@ -829,6 +829,9 @@ BUILTIN(__nvvm_atom_xor_gen_ll, "LLiLLiD*LLi", "n")
 TARGET_BUILTIN(__nvvm_atom_cta_xor_gen_ll, "LLiLLiD*LLi", "n", SM_60)
 TARGET_BUILTIN(__nvvm_atom_sys_xor_gen_ll, "LLiLLiD*LLi", "n", SM_60)
 
+TARGET_BUILTIN(__nvvm_atom_cas_gen_us, "UsUsD*UsUs", "n", SM_70)
+TARGET_BUILTIN(__nvvm_atom_cta_cas_gen_us, "UsUsD*UsUs", "n", SM_70)
+TARGET_BUILTIN(__nvvm_atom_sys_cas_gen_us, "UsUsD*UsUs", "n", SM_70)
 BUILTIN(__nvvm_atom_cas_gen_i, "iiD*ii", "n")
 TARGET_BUILTIN(__nvvm_atom_cta_cas_gen_i, "iiD*ii", "n", SM_60)
 TARGET_BUILTIN(__nvvm_atom_sys_cas_gen_i, "iiD*ii", "n", SM_60)
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index f424ddaa175400..769b3ce1886baf 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -20357,6 +20357,7 @@ Value *CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned 
BuiltinID,
   case NVPTX::BI__nvvm_atom_min_gen_ull:
 return MakeBinaryAtomicValue(*this, llvm::AtomicRMWInst::UMin, E);
 
+  case NVPTX::BI__nvvm_atom_cas_gen_us:
   case NVPTX::BI__nvvm_atom_cas_gen_i:
   case NVPTX::BI__nvvm_atom_cas_gen_l:
   case NVPTX::BI__nvvm_atom_cas_gen_ll:
@@ -20548,6 +20549,7 @@ Value *CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned 
BuiltinID,
   case NVPTX::BI__nvvm_atom_sys_xor_gen_l:
   case NVPTX::BI__nvvm_atom_sys_xor_gen_ll:
 return MakeScopedAtomic(Intrinsic::nvvm_atomic_xor_gen_i_sys, *this, E);
+  case NVPTX::BI__nvvm_atom_cta_cas_gen_us:
   case NVPTX::BI__nvvm_atom_cta_cas_gen_i:
   case NVPTX::BI__nvvm_atom_cta_cas_gen_l:
   case NVPTX::BI__nvvm_atom_cta_cas_gen_ll: {
@@ -20559,6 +20561,7 @@ Value *CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned 
BuiltinID,
 Intrinsic::nvvm_atomic_cas_gen_i_cta, {ElemTy, Ptr->getType()}),
 {Ptr, EmitScalarExpr(E->getArg(1)), EmitScalarExpr(E->getArg(2))});
   }
+  case NVPTX::BI__nvvm_atom_sys_cas_gen_us:
   case NVPTX::BI__nvvm_atom_sys_cas_gen_i:
   case NVPTX::BI__nvvm_atom_sys_cas_gen_l:
   case NVPTX::BI__nvvm_atom_sys_cas_gen_ll: {
diff --git a/clang/lib/Headers/__clang_cuda_device_functions.h 
b/clang/lib/Headers/__clang_cuda_device_functions.h
index f8a12cefdb81b4..f66fe625a39676 100644
--- a/clang/lib/Headers/__clang_cuda_device_functions.h
+++ b/clang/lib/Headers/__clang_cuda_device_functions.h
@@ -529,6 +529,18 @@ __DEVICE__ void __threadfence(void) { __nvvm_membar_gl(); }
 __DEVICE__ void __threadfence_block(void) { __nvvm_membar_cta(); };
 __DEVICE__ void __threadfence_system(void) { __nvvm_membar_sys(); };
 __DEVICE__ void __trap(void) { __asm__ __volatile__("trap;"); }
+__DEVICE__ unsigned short __usAtomicCAS(unsigned short *__p, unsigned short 
__cmp,
+unsigned short __v) {
+  return __nvvm_atom_cas_gen_us(__p, __cmp, __v);
+}
+__DEVICE__ unsigned short __usAtomicCAS_block(unsigned short *__p, unsigned 
short __cmp,
+  unsigned short __v) {
+  return __nvvm_atom_cta_cas_gen_us(__p, __cmp, __v);
+}
+__DEVICE__ unsigned short __usAtomicCAS_system(unsigned short *__p, unsigned 
short __cmp,
+   unsigned short __v) {
+  return __nvvm_atom_sys_cas_gen_us(__p, __cmp, __v);
+}
 __DEVICE__ unsigned int __uAtomicAdd(unsigned int *__p, unsigned int __v) {
   return __nvvm_atom_add_gen_i((int *)__p, __v);
 }
diff --git a/clang/test/CodeGen/builtins-nvptx.c 
b/clang/test/CodeGen/builtins-nvptx.c
index 75b9d6d1fe1902..3ba1fabd05335e 100644
--- a/clang/test/CodeGen/builtins-nvptx.c
+++ b/clang/test/CodeGen/builtins-nvptx.c
@@ -306,6 +306,9 @@ __device__ void nvvm_atom(float *fp, float f, double *dfp, 
double df, int *ip,
   // CHECK: atomicrmw umin ptr {{.*}} seq_cst, align 8
   __nvvm_atom_min_gen_ull((unsigned long long *)&sll, ll);
 
+  // CHECK: cmpxchg ptr {{.*}} seq_cst seq_cst, align 2
+  // CHECK-NEXT: extractvalue { i16, i1 } {{%[0-9]+}}, 0
+  __nvvm_atom_cas_gen_us(ip, 0, i);
   // CHECK: cmpxchg ptr {{.*}} seq_cst seq_cst, align 4
   // CHECK-NEXT: extractvalue { 

[clang] b986438 - [clang][modules] Built-in modules are not correctly enabled for Mac Catalyst (#104872)

2024-08-20 Thread via cfe-commits

Author: Ian Anderson
Date: 2024-08-20T03:29:11-07:00
New Revision: b9864387d9d00e1d4888181460d05dbc92364d75

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

LOG: [clang][modules] Built-in modules are not correctly enabled for Mac 
Catalyst (#104872)

Mac Catalyst is the iOS platform, but it builds against the macOS SDK
and so it needs to be checking the macOS SDK version instead of the iOS
one. Add tests against a greater-than SDK version just to make sure this
works beyond the initially supporting SDKs.

Added: 
clang/test/Driver/Inputs/MacOSX15.1.sdk/SDKSettings.json

Modified: 
clang/lib/Driver/ToolChains/Darwin.cpp
clang/test/Driver/darwin-builtin-modules.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index ee6890d5b98f0e..2550541a438481 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -2953,7 +2953,15 @@ static bool sdkSupportsBuiltinModules(
   case Darwin::MacOS:
 return SDKVersion >= VersionTuple(15U);
   case Darwin::IPhoneOS:
-return SDKVersion >= VersionTuple(18U);
+switch (TargetEnvironment) {
+case Darwin::MacCatalyst:
+  // Mac Catalyst uses `-target arm64-apple-ios18.0-macabi` so the platform
+  // is iOS, but it builds with the macOS SDK, so it's the macOS SDK 
version
+  // that's relevant.
+  return SDKVersion >= VersionTuple(15U);
+default:
+  return SDKVersion >= VersionTuple(18U);
+}
   case Darwin::TvOS:
 return SDKVersion >= VersionTuple(18U);
   case Darwin::WatchOS:

diff  --git a/clang/test/Driver/Inputs/MacOSX15.1.sdk/SDKSettings.json 
b/clang/test/Driver/Inputs/MacOSX15.1.sdk/SDKSettings.json
new file mode 100644
index 00..d46295b2ab5a17
--- /dev/null
+++ b/clang/test/Driver/Inputs/MacOSX15.1.sdk/SDKSettings.json
@@ -0,0 +1 @@
+{"Version":"15.1", "MaximumDeploymentTarget": "15.1.99"}

diff  --git a/clang/test/Driver/darwin-builtin-modules.c 
b/clang/test/Driver/darwin-builtin-modules.c
index ec515133be8aba..4564d7317d7abe 100644
--- a/clang/test/Driver/darwin-builtin-modules.c
+++ b/clang/test/Driver/darwin-builtin-modules.c
@@ -8,5 +8,8 @@
 
 // RUN: %clang -isysroot %S/Inputs/MacOSX15.0.sdk -target 
x86_64-apple-macos14.0 -### %s 2>&1 | FileCheck --check-prefix=CHECK_FUTURE %s
 // RUN: %clang -isysroot %S/Inputs/MacOSX15.0.sdk -target 
x86_64-apple-macos15.0 -### %s 2>&1 | FileCheck --check-prefix=CHECK_FUTURE %s
+// RUN: %clang -isysroot %S/Inputs/MacOSX15.0.sdk -target 
x86_64-apple-ios18.0-macabi -### %s 2>&1 | FileCheck 
--check-prefix=CHECK_FUTURE %s
+// RUN: %clang -isysroot %S/Inputs/MacOSX15.1.sdk -target 
x86_64-apple-macos15.1 -darwin-target-variant x86_64-apple-ios18.1-macabi -### 
%s 2>&1 | FileCheck --check-prefix=CHECK_FUTURE %s
+// RUN: %clang -isysroot %S/Inputs/MacOSX15.1.sdk -target 
x86_64-apple-ios18.1-macabi -darwin-target-variant x86_64-apple-macos15.1 -### 
%s 2>&1 | FileCheck --check-prefix=CHECK_FUTURE %s
 // RUN: %clang -isysroot %S/Inputs/DriverKit23.0.sdk -target 
arm64-apple-driverkit23.0 -### %s 2>&1 | FileCheck --check-prefix=CHECK_FUTURE 
%s
 // CHECK_FUTURE-NOT: -fbuiltin-headers-in-system-modules



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


[clang] [clang][modules] Built-in modules are not correctly enabled for Mac Catalyst (PR #104872)

2024-08-20 Thread Ian Anderson via cfe-commits

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


[clang] [Clang][NFCI] Cleanup the fix for default function argument substitution (PR #104911)

2024-08-20 Thread Younan Zhang via cfe-commits

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


[clang] [Clang][NFCI] Cleanup the fix for default function argument substitution (PR #104911)

2024-08-20 Thread Younan Zhang via cfe-commits

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


[clang] 3b49d27 - [X86] Add clang codegen test coverage for #104848

2024-08-20 Thread Simon Pilgrim via cfe-commits

Author: Simon Pilgrim
Date: 2024-08-20T11:51:28+01:00
New Revision: 3b49d274e6f16d1c8db5f4557eb7866a4bafffa5

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

LOG: [X86] Add clang codegen test coverage for #104848

Added: 
clang/test/CodeGen/X86/strictfp_patterns.c

Modified: 


Removed: 




diff  --git a/clang/test/CodeGen/X86/strictfp_patterns.c 
b/clang/test/CodeGen/X86/strictfp_patterns.c
new file mode 100644
index 00..fd1ecdb262d812
--- /dev/null
+++ b/clang/test/CodeGen/X86/strictfp_patterns.c
@@ -0,0 +1,32 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 %s -O2 -emit-llvm -o - -triple x86_64-unknown-unknown 
-ffreestanding -ffp-exception-behavior=maytrap -Wall -Werror | FileCheck %s
+
+#include 
+
+// TODO: PR104848 - ensure the _mm_set_ss/d headers don't implicity promote 
any integer/fp values.
+
+// CHECK-LABEL: @test_mm_set_ss(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[VECINIT_I:%.*]] = insertelement <4 x float> poison, float 
[[NUM:%.*]], i64 0
+// CHECK-NEXT:[[CONV_I:%.*]] = tail call float 
@llvm.experimental.constrained.sitofp.f32.i32(i32 0, metadata 
!"round.tonearest", metadata !"fpexcept.maytrap") #[[ATTR2:[0-9]+]]
+// CHECK-NEXT:[[VECINIT1_I:%.*]] = insertelement <4 x float> 
[[VECINIT_I]], float [[CONV_I]], i64 1
+// CHECK-NEXT:[[VECINIT3_I:%.*]] = insertelement <4 x float> 
[[VECINIT1_I]], float [[CONV_I]], i64 2
+// CHECK-NEXT:[[VECINIT5_I:%.*]] = insertelement <4 x float> 
[[VECINIT3_I]], float [[CONV_I]], i64 3
+// CHECK-NEXT:ret <4 x float> [[VECINIT5_I]]
+//
+__m128 test_mm_set_ss(float num)
+{
+return _mm_set_ss(num);
+}
+
+// CHECK-LABEL: @test_mm_set_sd(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[VECINIT_I:%.*]] = insertelement <2 x double> poison, 
double [[NUM:%.*]], i64 0
+// CHECK-NEXT:[[CONV_I:%.*]] = tail call double 
@llvm.experimental.constrained.sitofp.f64.i32(i32 0, metadata 
!"round.tonearest", metadata !"fpexcept.maytrap") #[[ATTR2]]
+// CHECK-NEXT:[[VECINIT1_I:%.*]] = insertelement <2 x double> 
[[VECINIT_I]], double [[CONV_I]], i64 1
+// CHECK-NEXT:ret <2 x double> [[VECINIT1_I]]
+//
+__m128d test_mm_set_sd(double num)
+{
+return _mm_set_sd(num);
+}



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


[clang] 6dcce42 - [X86] Use correct fp immediate types in _mm_set_ss/sd

2024-08-20 Thread Simon Pilgrim via cfe-commits

Author: Simon Pilgrim
Date: 2024-08-20T11:51:29+01:00
New Revision: 6dcce422ca06601f2b00e85cc18c745ede245ca6

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

LOG: [X86] Use correct fp immediate types in _mm_set_ss/sd

Avoids implicit sint_to_fp which wasn't occurring on strict fp codegen

Fixes #104848

Added: 


Modified: 
clang/lib/Headers/emmintrin.h
clang/lib/Headers/xmmintrin.h
clang/test/CodeGen/X86/strictfp_patterns.c

Removed: 




diff  --git a/clang/lib/Headers/emmintrin.h b/clang/lib/Headers/emmintrin.h
index a3176570a468f7..b880dae712e1f8 100644
--- a/clang/lib/Headers/emmintrin.h
+++ b/clang/lib/Headers/emmintrin.h
@@ -1774,7 +1774,7 @@ static __inline__ __m128d __DEFAULT_FN_ATTRS 
_mm_undefined_pd(void) {
 ///lower 64 bits contain the value of the parameter. The upper 64 bits are
 ///set to zero.
 static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_set_sd(double __w) {
-  return __extension__(__m128d){__w, 0};
+  return __extension__(__m128d){__w, 0.0};
 }
 
 /// Constructs a 128-bit floating-point vector of [2 x double], with each

diff  --git a/clang/lib/Headers/xmmintrin.h b/clang/lib/Headers/xmmintrin.h
index 5b9e90e8f061c1..c9a96d09a48521 100644
--- a/clang/lib/Headers/xmmintrin.h
+++ b/clang/lib/Headers/xmmintrin.h
@@ -1925,7 +1925,7 @@ _mm_undefined_ps(void)
 static __inline__ __m128 __DEFAULT_FN_ATTRS
 _mm_set_ss(float __w)
 {
-  return __extension__ (__m128){ __w, 0, 0, 0 };
+  return __extension__ (__m128){ __w, 0.0f, 0.0f, 0.0f };
 }
 
 /// Constructs a 128-bit floating-point vector of [4 x float], with each

diff  --git a/clang/test/CodeGen/X86/strictfp_patterns.c 
b/clang/test/CodeGen/X86/strictfp_patterns.c
index fd1ecdb262d812..55d85f22c3ba3d 100644
--- a/clang/test/CodeGen/X86/strictfp_patterns.c
+++ b/clang/test/CodeGen/X86/strictfp_patterns.c
@@ -3,16 +3,12 @@
 
 #include 
 
-// TODO: PR104848 - ensure the _mm_set_ss/d headers don't implicity promote 
any integer/fp values.
+// PR104848 - ensure the _mm_set_ss/d headers don't implicity promote any 
integer/fp values.
 
 // CHECK-LABEL: @test_mm_set_ss(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[VECINIT_I:%.*]] = insertelement <4 x float> poison, float 
[[NUM:%.*]], i64 0
-// CHECK-NEXT:[[CONV_I:%.*]] = tail call float 
@llvm.experimental.constrained.sitofp.f32.i32(i32 0, metadata 
!"round.tonearest", metadata !"fpexcept.maytrap") #[[ATTR2:[0-9]+]]
-// CHECK-NEXT:[[VECINIT1_I:%.*]] = insertelement <4 x float> 
[[VECINIT_I]], float [[CONV_I]], i64 1
-// CHECK-NEXT:[[VECINIT3_I:%.*]] = insertelement <4 x float> 
[[VECINIT1_I]], float [[CONV_I]], i64 2
-// CHECK-NEXT:[[VECINIT5_I:%.*]] = insertelement <4 x float> 
[[VECINIT3_I]], float [[CONV_I]], i64 3
-// CHECK-NEXT:ret <4 x float> [[VECINIT5_I]]
+// CHECK-NEXT:[[VECINIT3_I:%.*]] = insertelement <4 x float> , float 
[[NUM:%.*]], i64 0
+// CHECK-NEXT:ret <4 x float> [[VECINIT3_I]]
 //
 __m128 test_mm_set_ss(float num)
 {
@@ -21,9 +17,7 @@ __m128 test_mm_set_ss(float num)
 
 // CHECK-LABEL: @test_mm_set_sd(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[VECINIT_I:%.*]] = insertelement <2 x double> poison, 
double [[NUM:%.*]], i64 0
-// CHECK-NEXT:[[CONV_I:%.*]] = tail call double 
@llvm.experimental.constrained.sitofp.f64.i32(i32 0, metadata 
!"round.tonearest", metadata !"fpexcept.maytrap") #[[ATTR2]]
-// CHECK-NEXT:[[VECINIT1_I:%.*]] = insertelement <2 x double> 
[[VECINIT_I]], double [[CONV_I]], i64 1
+// CHECK-NEXT:[[VECINIT1_I:%.*]] = insertelement <2 x double> , double [[NUM:%.*]], i64 0
 // CHECK-NEXT:ret <2 x double> [[VECINIT1_I]]
 //
 __m128d test_mm_set_sd(double num)



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


[clang] [Clang][NFCI] Cleanup the fix for default function argument substitution (PR #104911)

2024-08-20 Thread Younan Zhang via cfe-commits

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

>From c8b8360fe046d38452f71479368c21e217468ddb Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Tue, 20 Aug 2024 17:18:35 +0800
Subject: [PATCH 1/2] [Clang][NFCI] Cleanup the fix for default function
 substitution

---
 clang/include/clang/Sema/Sema.h   |   9 +-
 clang/lib/Sema/SemaTemplateInstantiate.cpp|  23 +--
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |  10 +-
 clang/test/SemaTemplate/default-arguments.cpp |  55 ++
 clang/test/SemaTemplate/default-parm-init.cpp | 186 --
 5 files changed, 77 insertions(+), 206 deletions(-)

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 2ec6367eccea01..84df847726e6d2 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -13053,12 +13053,19 @@ class Sema final : public SemaBase {
   /// ForConstraintInstantiation indicates we should continue looking when
   /// encountering a lambda generic call operator, and continue looking for
   /// arguments on an enclosing class template.
+  ///
+  /// \param SkipForSpecialization when specified, any template specializations
+  /// in a traversal would be ignored.
+  /// \param ForDefaultArgumentSubstitution indicates we should continue 
looking
+  /// when encountering a specialized member function template, rather than
+  /// returning immediately.
   MultiLevelTemplateArgumentList getTemplateInstantiationArgs(
   const NamedDecl *D, const DeclContext *DC = nullptr, bool Final = false,
   std::optional> Innermost = std::nullopt,
   bool RelativeToPrimary = false, const FunctionDecl *Pattern = nullptr,
   bool ForConstraintInstantiation = false,
-  bool SkipForSpecialization = false);
+  bool SkipForSpecialization = false,
+  bool ForDefaultArgumentSubstitution = false);
 
   /// RAII object to handle the state changes required to synthesize
   /// a function body.
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index de470739ab78e7..feed797de838dd 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -255,7 +255,8 @@ HandleClassTemplateSpec(const 
ClassTemplateSpecializationDecl *ClassTemplSpec,
 Response HandleFunction(Sema &SemaRef, const FunctionDecl *Function,
 MultiLevelTemplateArgumentList &Result,
 const FunctionDecl *Pattern, bool RelativeToPrimary,
-bool ForConstraintInstantiation) {
+bool ForConstraintInstantiation,
+bool ForDefaultArgumentSubstitution) {
   // Add template arguments from a function template specialization.
   if (!RelativeToPrimary &&
   Function->getTemplateSpecializationKindForInstantiation() ==
@@ -285,7 +286,8 @@ Response HandleFunction(Sema &SemaRef, const FunctionDecl 
*Function,
 // If this function was instantiated from a specialized member that is
 // a function template, we're done.
 assert(Function->getPrimaryTemplate() && "No function template?");
-if (Function->getPrimaryTemplate()->isMemberSpecialization())
+if (!ForDefaultArgumentSubstitution &&
+Function->getPrimaryTemplate()->isMemberSpecialization())
   return Response::Done();
 
 // If this function is a generic lambda specialization, we are done.
@@ -467,7 +469,7 @@ MultiLevelTemplateArgumentList 
Sema::getTemplateInstantiationArgs(
 const NamedDecl *ND, const DeclContext *DC, bool Final,
 std::optional> Innermost, bool 
RelativeToPrimary,
 const FunctionDecl *Pattern, bool ForConstraintInstantiation,
-bool SkipForSpecialization) {
+bool SkipForSpecialization, bool ForDefaultArgumentSubstitution) {
   assert((ND || DC) && "Can't find arguments for a decl if one isn't 
provided");
   // Accumulate the set of template argument lists in this structure.
   MultiLevelTemplateArgumentList Result;
@@ -509,7 +511,8 @@ MultiLevelTemplateArgumentList 
Sema::getTemplateInstantiationArgs(
   SkipForSpecialization);
 } else if (const auto *Function = dyn_cast(CurDecl)) {
   R = HandleFunction(*this, Function, Result, Pattern, RelativeToPrimary,
- ForConstraintInstantiation);
+ ForConstraintInstantiation,
+ ForDefaultArgumentSubstitution);
 } else if (const auto *Rec = dyn_cast(CurDecl)) {
   R = HandleRecordDecl(*this, Rec, Result, Context,
ForConstraintInstantiation);
@@ -3229,7 +3232,6 @@ bool Sema::SubstDefaultArgument(
 //   default argument expression appears.
 ContextRAII SavedContext(*this, FD);
 std::unique_ptr LIS;
-MultiLevelTemplateArgumentList NewTemplateArgs = TemplateArgs;
 
 if (ForCallExpr) {
   // When instantiating a default argument due to use in a cal

[clang] [Clang][NFCI] Cleanup the fix for default function argument substitution (PR #104911)

2024-08-20 Thread Younan Zhang via cfe-commits

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


[clang] [Clang][NFCI] Cleanup the fix for default function argument substitution (PR #104911)

2024-08-20 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Younan Zhang (zyn0217)


Changes

(This is one step towards tweaking `getTemplateInstantiationArgs()` as 
discussed in https://github.com/llvm/llvm-project/pull/102922)

We don't always substitute into default arguments while transforming a function 
parameter. In that case, we would preserve the uninstantiated expression until 
after, e.g. building up a CXXDefaultArgExpr and instantiate the expression 
there.

For member function instantiation, this algorithm used to cause a problem in 
that the default argument of an out-of-line member function specialization 
couldn't get properly instantiated. This is because, in 
`getTemplateInstantiationArgs()`, we would give up visiting a function's 
declaration context if the function is a specialization of a member template. 
For example,

```cpp
template 
struct S {
  template 
  void f(T = sizeof(T));
};

template <> template 
void S::f(int) {}
```

The default argument `sizeof(U)` that lexically appears inside the declaration 
would be copied to the function declaration in the class template 
specialization `S`, as well as to the function's out-of-line 
definition. We use template arguments collected from the out-of-line function 
definition when substituting into the default arguments. We would therefore 
give up the traversal after the function, resulting in a single-level template 
argument of the f itself. However the default argument here could still 
reference the template parameters of the primary template, hence the error.

In fact, this is similar to constraint checking in some respects: we actually 
want the "whole" template arguments relative to the primary template, not those 
relative to the function definition. So this patch adds another flag to 
indicate `getTemplateInstantiationArgs()` for that.

This patch also consolidates the tests for default arguments and removes some 
unnecessary tests.

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


5 Files Affected:

- (modified) clang/include/clang/Sema/Sema.h (+8-1) 
- (modified) clang/lib/Sema/SemaTemplateInstantiate.cpp (+8-15) 
- (modified) clang/lib/Sema/SemaTemplateInstantiateDecl.cpp (+6-4) 
- (modified) clang/test/SemaTemplate/default-arguments.cpp (+55) 
- (modified) clang/test/SemaTemplate/default-parm-init.cpp (-186) 


``diff
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 2ec6367eccea01..84df847726e6d2 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -13053,12 +13053,19 @@ class Sema final : public SemaBase {
   /// ForConstraintInstantiation indicates we should continue looking when
   /// encountering a lambda generic call operator, and continue looking for
   /// arguments on an enclosing class template.
+  ///
+  /// \param SkipForSpecialization when specified, any template specializations
+  /// in a traversal would be ignored.
+  /// \param ForDefaultArgumentSubstitution indicates we should continue 
looking
+  /// when encountering a specialized member function template, rather than
+  /// returning immediately.
   MultiLevelTemplateArgumentList getTemplateInstantiationArgs(
   const NamedDecl *D, const DeclContext *DC = nullptr, bool Final = false,
   std::optional> Innermost = std::nullopt,
   bool RelativeToPrimary = false, const FunctionDecl *Pattern = nullptr,
   bool ForConstraintInstantiation = false,
-  bool SkipForSpecialization = false);
+  bool SkipForSpecialization = false,
+  bool ForDefaultArgumentSubstitution = false);
 
   /// RAII object to handle the state changes required to synthesize
   /// a function body.
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index de470739ab78e7..feed797de838dd 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -255,7 +255,8 @@ HandleClassTemplateSpec(const 
ClassTemplateSpecializationDecl *ClassTemplSpec,
 Response HandleFunction(Sema &SemaRef, const FunctionDecl *Function,
 MultiLevelTemplateArgumentList &Result,
 const FunctionDecl *Pattern, bool RelativeToPrimary,
-bool ForConstraintInstantiation) {
+bool ForConstraintInstantiation,
+bool ForDefaultArgumentSubstitution) {
   // Add template arguments from a function template specialization.
   if (!RelativeToPrimary &&
   Function->getTemplateSpecializationKindForInstantiation() ==
@@ -285,7 +286,8 @@ Response HandleFunction(Sema &SemaRef, const FunctionDecl 
*Function,
 // If this function was instantiated from a specialized member that is
 // a function template, we're done.
 assert(Function->getPrimaryTemplate() && "No function template?");
-if (Function->getPrimaryTemplate()->isMemberSpecialization())
+

[clang] [lld] [llvm] [NFC] Cleanup in Support headers. (PR #104825)

2024-08-20 Thread Daniil Fukalov via cfe-commits

https://github.com/dfukalov updated 
https://github.com/llvm/llvm-project/pull/104825

>From cce13227c78d3d1831fb8773fc52005fabd412c6 Mon Sep 17 00:00:00 2001
From: dfukalov 
Date: Mon, 19 Aug 2024 20:02:52 +0200
Subject: [PATCH 1/5] [NFC] Cleanup in Support headers.

Remove unused directly includes and forward declarations in Support headers.
---
 clang/lib/CodeGen/ObjectFilePCHContainerWriter.cpp  | 1 +
 clang/lib/Format/Format.cpp | 1 +
 clang/lib/Format/FormatTokenSource.h| 1 +
 clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp   | 1 +
 clang/tools/driver/driver.cpp   | 1 +
 clang/unittests/Format/MacroCallReconstructorTest.cpp   | 1 +
 lld/ELF/Writer.cpp  | 1 +
 lld/MachO/BPSectionOrderer.cpp  | 1 +
 lld/MachO/Dwarf.cpp | 1 +
 lld/MachO/SectionPriorities.cpp | 1 +
 lld/wasm/WriterUtils.h  | 1 +
 llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h | 1 -
 llvm/include/llvm/Support/Atomic.h  | 2 +-
 llvm/include/llvm/Support/BalancedPartitioning.h| 3 ++-
 llvm/include/llvm/Support/BinaryStreamReader.h  | 1 -
 llvm/include/llvm/Support/BranchProbability.h   | 1 -
 llvm/include/llvm/Support/CRC.h | 2 +-
 llvm/include/llvm/Support/CachePruning.h| 4 +++-
 llvm/include/llvm/Support/Casting.h | 1 -
 llvm/include/llvm/Support/Chrono.h  | 5 +
 llvm/include/llvm/Support/CommandLine.h | 4 
 llvm/include/llvm/Support/Compression.h | 6 --
 llvm/include/llvm/Support/ConvertEBCDIC.h   | 4 +++-
 llvm/include/llvm/Support/DataExtractor.h   | 1 -
 llvm/include/llvm/Support/DebugCounter.h| 4 ++--
 llvm/include/llvm/Support/ELFAttributeParser.h  | 1 -
 llvm/include/llvm/Support/Error.h   | 3 ---
 llvm/include/llvm/Support/ErrorHandling.h   | 2 --
 llvm/include/llvm/Support/ExponentialBackoff.h  | 2 --
 llvm/include/llvm/Support/FileOutputBuffer.h| 1 -
 llvm/include/llvm/Support/FileUtilities.h   | 2 --
 llvm/include/llvm/Support/FormatVariadic.h  | 1 -
 llvm/include/llvm/Support/LineIterator.h| 1 -
 llvm/include/llvm/Support/LockFileManager.h | 1 -
 llvm/include/llvm/Support/MathExtras.h  | 1 -
 llvm/include/llvm/Support/Memory.h  | 1 -
 llvm/include/llvm/Support/OptimizedStructLayout.h   | 3 ++-
 llvm/include/llvm/Support/PGOOptions.h  | 2 +-
 llvm/include/llvm/Support/Path.h| 1 -
 llvm/include/llvm/Support/PrettyStackTrace.h| 1 -
 llvm/include/llvm/Support/Process.h | 1 -
 llvm/include/llvm/Support/RandomNumberGenerator.h   | 2 --
 llvm/include/llvm/Support/ScopedPrinter.h   | 1 -
 llvm/include/llvm/Support/SpecialCaseList.h | 1 -
 llvm/include/llvm/Support/ThreadPool.h  | 3 +--
 llvm/include/llvm/Support/Threading.h   | 1 -
 llvm/include/llvm/Support/Timer.h   | 1 -
 llvm/include/llvm/Support/TypeSize.h| 1 -
 llvm/include/llvm/Support/VirtualFileSystem.h   | 1 -
 llvm/include/llvm/Support/Watchdog.h| 2 --
 llvm/include/llvm/Support/WithColor.h   | 1 -
 llvm/include/llvm/Support/raw_ostream.h | 2 --
 llvm/include/llvm/Testing/ADT/StringMap.h   | 1 -
 llvm/lib/Analysis/AliasAnalysis.cpp | 1 +
 llvm/lib/Analysis/DXILMetadataAnalysis.cpp  | 1 +
 llvm/lib/Analysis/DXILResource.cpp  | 1 +
 llvm/lib/Analysis/InlineAdvisor.cpp | 1 +
 llvm/lib/Analysis/InlineOrder.cpp   | 1 +
 llvm/lib/Analysis/InteractiveModelRunner.cpp| 1 +
 llvm/lib/Analysis/ReplayInlineAdvisor.cpp   | 1 +
 llvm/lib/Analysis/StackSafetyAnalysis.cpp   | 1 +
 llvm/lib/Bitcode/Writer/BitcodeWriterPass.cpp   | 1 +
 llvm/lib/CodeGen/MachineCFGPrinter.cpp  | 2 +-
 llvm/lib/CodeGen/ReplaceWithVeclib.cpp  | 1 +
 llvm/lib/DebugInfo/BTF/BTFParser.cpp| 1 +
 llvm/lib/DebugInfo/DWARF/DWARFLocationExpression.cpp| 1 +
 llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp  | 1 +
 llvm/lib/ExecutionEngine/Orc/OrcABISupport.cpp  | 1 +
 llvm/lib/ExecutionEngine/Orc/TargetProcess/JITLoader

[clang] [Clang][NFCI] Cleanup the fix for default function argument substitution (PR #104911)

2024-08-20 Thread Younan Zhang via cfe-commits


@@ -285,7 +286,8 @@ Response HandleFunction(Sema &SemaRef, const FunctionDecl 
*Function,
 // If this function was instantiated from a specialized member that is
 // a function template, we're done.
 assert(Function->getPrimaryTemplate() && "No function template?");
-if (Function->getPrimaryTemplate()->isMemberSpecialization())
+if (!ForDefaultArgumentSubstitution &&
+Function->getPrimaryTemplate()->isMemberSpecialization())

zyn0217 wrote:

An alternative is to use `(ForConstraintInstantiation || !RelativeToPrimary)` 
so we could get rid of the usages for concepts where it expects an end after a 
member specialization. But I feel like that makes the semantics of the flags 
vague, so ideas are welcome here.

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


[clang] [Clang][NFCI] Cleanup the fix for default function argument substitution (PR #104911)

2024-08-20 Thread Younan Zhang via cfe-commits

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

>From c8b8360fe046d38452f71479368c21e217468ddb Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Tue, 20 Aug 2024 17:18:35 +0800
Subject: [PATCH 1/3] [Clang][NFCI] Cleanup the fix for default function
 substitution

---
 clang/include/clang/Sema/Sema.h   |   9 +-
 clang/lib/Sema/SemaTemplateInstantiate.cpp|  23 +--
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |  10 +-
 clang/test/SemaTemplate/default-arguments.cpp |  55 ++
 clang/test/SemaTemplate/default-parm-init.cpp | 186 --
 5 files changed, 77 insertions(+), 206 deletions(-)

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 2ec6367eccea01..84df847726e6d2 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -13053,12 +13053,19 @@ class Sema final : public SemaBase {
   /// ForConstraintInstantiation indicates we should continue looking when
   /// encountering a lambda generic call operator, and continue looking for
   /// arguments on an enclosing class template.
+  ///
+  /// \param SkipForSpecialization when specified, any template specializations
+  /// in a traversal would be ignored.
+  /// \param ForDefaultArgumentSubstitution indicates we should continue 
looking
+  /// when encountering a specialized member function template, rather than
+  /// returning immediately.
   MultiLevelTemplateArgumentList getTemplateInstantiationArgs(
   const NamedDecl *D, const DeclContext *DC = nullptr, bool Final = false,
   std::optional> Innermost = std::nullopt,
   bool RelativeToPrimary = false, const FunctionDecl *Pattern = nullptr,
   bool ForConstraintInstantiation = false,
-  bool SkipForSpecialization = false);
+  bool SkipForSpecialization = false,
+  bool ForDefaultArgumentSubstitution = false);
 
   /// RAII object to handle the state changes required to synthesize
   /// a function body.
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index de470739ab78e7..feed797de838dd 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -255,7 +255,8 @@ HandleClassTemplateSpec(const 
ClassTemplateSpecializationDecl *ClassTemplSpec,
 Response HandleFunction(Sema &SemaRef, const FunctionDecl *Function,
 MultiLevelTemplateArgumentList &Result,
 const FunctionDecl *Pattern, bool RelativeToPrimary,
-bool ForConstraintInstantiation) {
+bool ForConstraintInstantiation,
+bool ForDefaultArgumentSubstitution) {
   // Add template arguments from a function template specialization.
   if (!RelativeToPrimary &&
   Function->getTemplateSpecializationKindForInstantiation() ==
@@ -285,7 +286,8 @@ Response HandleFunction(Sema &SemaRef, const FunctionDecl 
*Function,
 // If this function was instantiated from a specialized member that is
 // a function template, we're done.
 assert(Function->getPrimaryTemplate() && "No function template?");
-if (Function->getPrimaryTemplate()->isMemberSpecialization())
+if (!ForDefaultArgumentSubstitution &&
+Function->getPrimaryTemplate()->isMemberSpecialization())
   return Response::Done();
 
 // If this function is a generic lambda specialization, we are done.
@@ -467,7 +469,7 @@ MultiLevelTemplateArgumentList 
Sema::getTemplateInstantiationArgs(
 const NamedDecl *ND, const DeclContext *DC, bool Final,
 std::optional> Innermost, bool 
RelativeToPrimary,
 const FunctionDecl *Pattern, bool ForConstraintInstantiation,
-bool SkipForSpecialization) {
+bool SkipForSpecialization, bool ForDefaultArgumentSubstitution) {
   assert((ND || DC) && "Can't find arguments for a decl if one isn't 
provided");
   // Accumulate the set of template argument lists in this structure.
   MultiLevelTemplateArgumentList Result;
@@ -509,7 +511,8 @@ MultiLevelTemplateArgumentList 
Sema::getTemplateInstantiationArgs(
   SkipForSpecialization);
 } else if (const auto *Function = dyn_cast(CurDecl)) {
   R = HandleFunction(*this, Function, Result, Pattern, RelativeToPrimary,
- ForConstraintInstantiation);
+ ForConstraintInstantiation,
+ ForDefaultArgumentSubstitution);
 } else if (const auto *Rec = dyn_cast(CurDecl)) {
   R = HandleRecordDecl(*this, Rec, Result, Context,
ForConstraintInstantiation);
@@ -3229,7 +3232,6 @@ bool Sema::SubstDefaultArgument(
 //   default argument expression appears.
 ContextRAII SavedContext(*this, FD);
 std::unique_ptr LIS;
-MultiLevelTemplateArgumentList NewTemplateArgs = TemplateArgs;
 
 if (ForCallExpr) {
   // When instantiating a default argument due to use in a cal

[clang] Fix bug with -ffp-contract=fast-honor-pragmas (PR #104857)

2024-08-20 Thread Aaron Ballman via cfe-commits

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

Changes LGTM modulo nits, but please also add a release note to 
`clang/docs/ReleaseNotes.rst` so users know about the fix.

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


[clang] Fix bug with -ffp-contract=fast-honor-pragmas (PR #104857)

2024-08-20 Thread Aaron Ballman via cfe-commits


@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -O3 -ffp-contract=fast-honor-pragmas -triple 
%itanium_abi_triple -emit-llvm -o - %s | FileCheck %s
+
+float fp_contract_1(float a, float b, float c) {
+  // CHECK-LABEL: fp_contract_1fff(
+  // CHECK: fmul contract float
+  // CHECK: fadd contract float
+  return a * b + c;
+}
+
+float fp_contract_2(float a, float b, float c) {
+  // CHECK-LABEL: fp_contract_2fff(
+  // CHECK: fmul contract float
+  // CHECK: fsub contract float
+  return a * b - c;
+}
+
+void fp_contract_3(float *a, float b, float c) {
+  // CHECK-LABEL: fp_contract_3Pfff(
+  // CHECK: fmul contract float
+  // CHECK: fadd contract float
+  a[0] += b * c;
+}
+
+void fp_contract_4(float *a, float b, float c) {
+  // CHECK-LABEL: fp_contract_4Pfff(
+  // CHECK: fmul contract float
+  // CHECK: fsub contract float
+  a[0] -= b * c;
+}
+
+float fp_contract_5(float a, float b, float c) {
+  // CHECK-LABEL: fp_contract_5fff(
+  // CHECK: fmul contract float
+  // CHECK: fadd contract float
+  float t = a * b;
+  return t + c;
+}

AaronBallman wrote:

Please add a newline to the end of the file.

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


[clang] Fix bug with -ffp-contract=fast-honor-pragmas (PR #104857)

2024-08-20 Thread Aaron Ballman via cfe-commits

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


[clang] Fix bug with -ffp-contract=fast-honor-pragmas (PR #104857)

2024-08-20 Thread Aaron Ballman via cfe-commits


@@ -0,0 +1,151 @@
+// RUN: %clang_cc1 -O3 -ffp-contract=fast-honor-pragmas -triple 
%itanium_abi_triple -emit-llvm -o - %s | FileCheck %s
+
+float fp_contract_on_1(float a, float b, float c) {
+  // CHECK-LABEL: fp_contract_on_1fff(
+  // CHECK: call float @llvm.fmuladd.f32(float {{.*}}, float {{.*}}, float 
{{.*}})
+  #pragma STDC FP_CONTRACT ON
+  return a * b + c;
+}
+
+float fp_contract_on_2(float a, float b, float c) {
+  // CHECK-LABEL: fp_contract_on_2fff(
+  // CHECK: fmul float
+  // CHECK: fadd float
+  #pragma STDC FP_CONTRACT ON
+  float t = a * b;
+  return t + c;
+}
+
+float fp_contract_off_1(float a, float b, float c) {
+  // CHECK-LABEL: fp_contract_off_1fff(
+  // CHECK: fmul float
+  // CHECK: fadd float
+  #pragma STDC FP_CONTRACT OFF
+  return a * b + c;
+}
+
+float fp_contract_off_2(float a, float b, float c) {
+  // CHECK-LABEL: fp_contract_off_2fff(
+  // CHECK: fmul float
+  // CHECK: fadd float
+  #pragma STDC FP_CONTRACT OFF
+  float t = a * b;
+  return t + c;
+}
+
+float fp_contract_default_1(float a, float b, float c) {
+  // CHECK-LABEL: fp_contract_default_1fff(
+  // CHECK: fmul contract float
+  // CHECK: fadd contract float
+  #pragma STDC FP_CONTRACT DEFAULT
+  return a * b + c;
+}
+
+float fp_contract_default_2(float a, float b, float c) {
+  // CHECK-LABEL: fp_contract_default_2fff(
+  // CHECK: fmul contract float
+  // CHECK: fadd contract float
+  #pragma STDC FP_CONTRACT DEFAULT
+  float t = a * b;
+  return t + c;
+}
+
+float fp_contract_clang_on_1(float a, float b, float c) {
+  // CHECK-LABEL: fp_contract_clang_on_1fff(
+  // CHECK: call float @llvm.fmuladd.f32(float {{.*}}, float {{.*}}, float 
{{.*}})
+  #pragma clang fp contract(on)
+  return a * b + c;
+}
+
+float fp_contract_clang_on_2(float a, float b, float c) {
+  // CHECK-LABEL: fp_contract_clang_on_2fff(
+  // CHECK: fmul float
+  // CHECK: fadd float
+  #pragma clang fp contract(on)
+  float t = a * b;
+  return t + c;
+}
+
+float fp_contract_clang_off_1(float a, float b, float c) {
+  // CHECK-LABEL: fp_contract_clang_off_1fff(
+  // CHECK: fmul float
+  // CHECK: fadd float
+  #pragma clang fp contract(off)
+  return a * b + c;
+}
+
+float fp_contract_clang_off_2(float a, float b, float c) {
+  // CHECK-LABEL: fp_contract_clang_off_2fff(
+  // CHECK: fmul float
+  // CHECK: fadd float
+  #pragma clang fp contract(off)
+  float t = a * b;
+  return t + c;
+}
+
+float fp_contract_clang_fast_1(float a, float b, float c) {
+  // CHECK-LABEL: fp_contract_clang_fast_1fff(
+  // CHECK: fmul contract float
+  // CHECK: fadd contract float
+  #pragma clang fp contract(fast)
+  return a * b + c;
+}
+
+float fp_contract_clang_fast_2(float a, float b, float c) {
+  // CHECK-LABEL: fp_contract_clang_fast_2fff(
+  // CHECK: fmul contract float
+  // CHECK: fadd contract float
+  #pragma clang fp contract(fast)
+  float t = a * b;
+  return t + c;
+}
+
+#pragma STDC FP_CONTRACT ON
+
+float fp_contract_global_on_1(float a, float b, float c) {
+  // CHECK-LABEL: fp_contract_global_on_1fff(
+  // CHECK: call float @llvm.fmuladd.f32(float {{.*}}, float {{.*}}, float 
{{.*}})
+  return a * b + c;
+}
+
+float fp_contract_global_on_2(float a, float b, float c) {
+  // CHECK-LABEL: fp_contract_global_on_2fff(
+  // CHECK: fmul float
+  // CHECK: fadd float
+  float t = a * b;
+  return t + c;
+}
+
+#pragma STDC FP_CONTRACT OFF
+
+float fp_contract_global_off_1(float a, float b, float c) {
+  // CHECK-LABEL: fp_contract_global_off_1fff(
+  // CHECK: fmul float
+  // CHECK: fadd float
+  return a * b + c;
+}
+
+float fp_contract_global_off_2(float a, float b, float c) {
+  // CHECK-LABEL: fp_contract_global_off_2fff(
+  // CHECK: fmul float
+  // CHECK: fadd float
+  float t = a * b;
+  return t + c;
+}
+
+#pragma STDC FP_CONTRACT DEFAULT
+
+float fp_contract_global_default_1(float a, float b, float c) {
+  // CHECK-LABEL: fp_contract_global_default_1fff(
+  // CHECK: fmul contract float
+  // CHECK: fadd contract float
+  return a * b + c;
+}
+
+float fp_contract_global_default_2(float a, float b, float c) {
+  // CHECK-LABEL: fp_contract_global_default_2fff(
+  // CHECK: fmul contract float
+  // CHECK: fadd contract float
+  float t = a * b;
+  return t + c;
+}

AaronBallman wrote:

And a newline here as well.

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


[clang] [llvm] [Clang][AArch64] Add customisable immediate range checking to NEON (PR #100278)

2024-08-20 Thread via cfe-commits


@@ -1959,9 +2064,12 @@ multiclass VCMLA_ROTS {
 
 let isLaneQ = 1 in  {
   // vcmla{ROT}_laneq
+  // ACLE specifies that the fp16 vcmla_#ROT_laneq variant has an 
immedaite range of 0 <= lane <= 1.
+  // fp16 is the only variant for which these two differ.
+  // https://developer.arm.com/documentation/ihi0073/latest/ 
+  defvar getlanety = !if(!eq(type, "h"), lanety, laneqty);
   def : SOpInst<"vcmla" # ROT # "_laneq", "...QI", type,  Op<(call "vcmla" 
# ROT, $p0, $p1,
-  (bitcast $p0, (dup_typed lanety, (call "vget_lane", (bitcast 
laneqty, $p2), $p3>>;
-
+(bitcast $p0, (dup_typed lanety, (call "vget_lane", (bitcast 
getlanety, $p2), $p3>>;

SpencerAbson wrote:

If we look at what this intrinsic compiles to, 
[FCMLA](https://developer.arm.com/documentation/ddi0596/2021-03/SIMD-FP-Instructions/FCMLA--by-element---Floating-point-Complex-Multiply-Accumulate--by-element--?lang=en),
 it looks like the reduced range (`0<=lane<=1`) is due to the fact that we must 
have `H=='0'` for this instruction to be defined when we use the `'01'` size 
specifier and `Q='0'` (what is required for this variant). This means that only 
bit-field `L` can be used to encode ``.

Thanks to @rsandifo-arm for pointing this out.

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


[clang] [llvm] [Clang][AArch64] Add customisable immediate range checking to NEON (PR #100278)

2024-08-20 Thread via cfe-commits


@@ -1959,9 +2064,12 @@ multiclass VCMLA_ROTS {
 
 let isLaneQ = 1 in  {
   // vcmla{ROT}_laneq
+  // ACLE specifies that the fp16 vcmla_#ROT_laneq variant has an 
immedaite range of 0 <= lane <= 1.
+  // fp16 is the only variant for which these two differ.
+  // https://developer.arm.com/documentation/ihi0073/latest/ 
+  defvar getlanety = !if(!eq(type, "h"), lanety, laneqty);
   def : SOpInst<"vcmla" # ROT # "_laneq", "...QI", type,  Op<(call "vcmla" 
# ROT, $p0, $p1,
-  (bitcast $p0, (dup_typed lanety, (call "vget_lane", (bitcast 
laneqty, $p2), $p3>>;
-
+(bitcast $p0, (dup_typed lanety, (call "vget_lane", (bitcast 
getlanety, $p2), $p3>>;

Lukacma wrote:

I am not sure I follow what you trying to say there. I think, it might be 
because your link to FCMLA is for the old spec and there may be some 
differences in instruction spec compared to the latest one. But if you look at 
the most recent spec for this 
[instruction](https://developer.arm.com/documentation/ddi0602/2024-06/SVE-Instructions/FCMLA--indexed---Floating-point-complex-multiply-add-by-indexed-values-with-rotate-),
 it says quite clearly that immediate range for half-precision variant is from 
0 to 3

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


[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)

2024-08-20 Thread via cfe-commits

https://github.com/zmodem commented:

Just some nits from my side. (I only looked at the docs and driver code)

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


[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)

2024-08-20 Thread via cfe-commits

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


[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)

2024-08-20 Thread via cfe-commits


@@ -3034,6 +3034,12 @@ def fms_extensions : Flag<["-"], "fms-extensions">, 
Group,
   Visibility<[ClangOption, CC1Option, CLOption]>,
   HelpText<"Accept some non-standard constructs supported by the Microsoft 
compiler">,
   MarshallingInfoFlag>, 
ImpliedByAnyOf<[fms_compatibility.KeyPath]>;
+def fms_reference_binding : Flag<["-"], "fms-reference-binding">, 
Group,
+  Visibility<[ClangOption, CC1Option, CLOption]>,
+  HelpText<"Accept expressions that bind a non-const lvalue reference to a 
user-defined type temporary as supported by the Microsoft Compiler">,

zmodem wrote:

s/Compiler/compiler/

I know the file is not consistent, but historically it's been trying to stay 
within 80 columns, so consider breaking up the HelpText (also below). See e.g. 
fms_compatibility_version for an example.

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


[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)

2024-08-20 Thread via cfe-commits


@@ -950,12 +950,14 @@ static void TranslatePermissive(Arg *A, 
llvm::opt::DerivedArgList &DAL,
 const OptTable &Opts) {
   DAL.AddFlagArg(A, Opts.getOption(options::OPT__SLASH_Zc_twoPhase_));
   DAL.AddFlagArg(A, Opts.getOption(options::OPT_fno_operator_names));
+  DAL.AddFlagArg(A, Opts.getOption(options::OPT_fms_reference_binding));

zmodem wrote:

Do we need to check for c++20 like we do above?

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


[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)

2024-08-20 Thread via cfe-commits


@@ -7272,6 +7272,11 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 CmdArgs.push_back("-fdelayed-template-parsing");
   }
 
+  if (Args.hasFlag(options::OPT_fms_reference_binding,
+   options::OPT_fno_ms_reference_binding,
+   IsWindowsMSVC && !HaveCxx20))

zmodem wrote:

Could we do something better for the non-windows or c++20 cases?

We could emit a warning saying the flag is unsupported, or we could put those 
conditions first so that we don't call hasFlag, which would make clang warn 
about the unused option.

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


[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)

2024-08-20 Thread via cfe-commits


@@ -5821,3 +5821,33 @@ specify the starting offset to begin embedding from. The 
resources is treated
 as being empty if the specified offset is larger than the number of bytes in
 the resource. The offset will be applied *before* any ``limit`` parameters are
 applied.
+
+MSVC Extensions
+===
+
+Clang supports a number of extensions inorder to imitate MSVC.
+Some of these extensions are behind ``-fms-compatibility`` and 
``-fms-extensions`` which
+are further described in :doc:`MSVCCompatibility`.
+
+MSVC Reference Binding
+--
+
+.. code-block:: c++
+
+  struct A {};
+
+  A& a = A();
+
+Please see the `MSDN doc
+`_
+for more information on this non-conforming C++ extension.
+
+MSVC allows user-defined type temporaries to be bound to non-const lvalue 
references when ``/permissive``
+or ``/Zc:referenceBinding-`` are given on the command line.
+
+The current default behavior as of MSVC 1940 is ``/permissive``.
+As of Visual Studio 2017, ``/permissive-`` is the default for projects meaning 
C++ conformance is enforced when
+building with MSVC in Visual Studio.
+
+This MSVC extension can be enabled with ``-fms-reference-binding`` with the 
clang or cl driver.
+This MSVC extension can be enabled with ``/Zc:referenceBinding-`` with the cl 
driver.

zmodem wrote:

Let's s/cl/clang-cl/g. (I think we always refer to it as clang-cl in docs.)

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


[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)

2024-08-20 Thread via cfe-commits


@@ -8492,6 +8498,12 @@ def _SLASH_Zc_wchar_t : CLFlag<"Zc:wchar_t">,
   HelpText<"Enable C++ builtin type wchar_t (default)">;
 def _SLASH_Zc_wchar_t_ : CLFlag<"Zc:wchar_t-">,
   HelpText<"Disable C++ builtin type wchar_t">;
+def _SLASH_Zc_referenceBinding : CLFlag<"Zc:referenceBinding">,
+  HelpText<"Do not accept expressions that bind a non-const lvalue reference 
to a user-defined type temporary">,

zmodem wrote:

"(default)" at the end of the help text.

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


[clang] [RFC][C++20][Modules] Fix crash when function and lambda inside loaded from different modules (PR #104512)

2024-08-20 Thread Dmitry Polukhin via cfe-commits

dmpolukhin wrote:

> Here is another example that merging lambdas are problematic: #102721. 
> Although I think we need to solve the problems separately. They are different 
> problems.

Thank you for the reference, we need this fix too.

> But the current patch still smells bad. Let's try to find a cleaner way to 
> proceed. IIUC, the key of the current problem is that, the CXXRecordDecl of 
> the lambda are assigned to the wrong FunctionDecl as the DeclContext? Or the 
> LambdaExpr appears in the wrong FunctionDecl?

Yeah, I agree. Problem with current code is not wrong assignment (everything 
match respectively) but which decl becomes canonical. Function decl from module 
A became canonical but for lambda canonical decl is chosen from module B. It 
happens because of the order of loading template specialization. Lookup by name 
makes canonical decl for function `tryTo` from module `thrift_cpp2_base.pcm` 
(last module loaded). `RedeclarableTemplateDecl::loadLazySpecializationsImpl` 
gets the most recent decl from module `thrift_cpp2_base.pcm` but it loads 
specialization in direct order so specialization from the first module 
`folly-conv.pcm` are loaded before specialization from `thrift_cpp2_base.pcm` 
and thus via dependencies lambda from the wrong module became canonical. In the 
last version I changed order of specialization loading to match order of lookup 
by name. I'm not sure that it will solve all cases when canonical decl for 
lambda can be chosen from another module but it seems that it reduces such 
probability substantially because now it match the most frequent case lookup by 
name. I'm still testing my changes on bigger codebase but so far it seems that 
it doesn't regress anything and solves my test case.

It doesn't completely solve the issue because it might be other code paths that 
result making canonical decl in different order. Alternative solution is 
abandon lazy loading for function and load its internal lambda right after 
making any function canonical. I think it will negatively affect performance 
because more things will be loaded that can be avoided with current approach. 
WDYT?

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


[clang] [RFC][C++20][Modules] Fix crash when function and lambda inside loaded from different modules (PR #104512)

2024-08-20 Thread Dmitry Polukhin via cfe-commits

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


[clang] [RFC][C++20][Modules] Fix crash when function and lambda inside loaded from different modules (PR #104512)

2024-08-20 Thread Dmitry Polukhin via cfe-commits

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


[clang] [clang][NFC] Split invalid-cpu-note tests (PR #104601)

2024-08-20 Thread Sam Elliott via cfe-commits

lenary wrote:

Failures seem unrelated. Merging.

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


[clang] 3f25f23 - [X86][AVX10] Fix unexpected error and warning when using intrinsic (#104781)

2024-08-20 Thread via cfe-commits

Author: Phoebe Wang
Date: 2024-08-20T19:56:19+08:00
New Revision: 3f25f23a2b8aaff300e751d4724a3ddba4d694eb

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

LOG: [X86][AVX10] Fix unexpected error and warning when using intrinsic 
(#104781)

E.g.: https://godbolt.org/z/G8zK5svjK

Based on Evgenii's work.

Added: 


Modified: 
clang/lib/Basic/Targets/X86.cpp
clang/lib/Headers/avx2intrin.h
clang/lib/Headers/avxintrin.h
clang/lib/Headers/emmintrin.h
clang/lib/Headers/gfniintrin.h
clang/lib/Headers/mmintrin.h
clang/lib/Headers/pmmintrin.h
clang/lib/Headers/smmintrin.h
clang/lib/Headers/tmmintrin.h
clang/lib/Headers/xmmintrin.h
clang/test/CodeGen/X86/avx512vlbw-builtins.c

Removed: 




diff  --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index 3fb3587eb59140..a9cbdb7b10dff8 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -186,14 +186,14 @@ bool X86TargetInfo::initFeatureMap(
   llvm::append_range(UpdatedFeaturesVec, UpdatedAVX10FeaturesVec);
   // HasEVEX512 is a three-states flag. We need to turn it into [+-]evex512
   // according to other features.
-  if (HasAVX512F) {
+  if (!HasAVX10_512 && HasAVX512F) {
 UpdatedFeaturesVec.push_back(HasEVEX512 == FE_FALSE ? "-evex512"
 : "+evex512");
-if (HasAVX10 && !HasAVX10_512 && HasEVEX512 != FE_FALSE)
+if (HasAVX10 && HasEVEX512 != FE_FALSE)
   Diags.Report(diag::warn_invalid_feature_combination)
   << LastAVX512 + " " + LastAVX10 + "; will be promoted to 
avx10.1-512";
   } else if (HasAVX10) {
-if (HasEVEX512 != FE_NOSET)
+if (!HasAVX512F && HasEVEX512 != FE_NOSET)
   Diags.Report(diag::warn_invalid_feature_combination)
   << LastAVX10 + (HasEVEX512 == FE_TRUE ? " +evex512" : " -evex512");
 UpdatedFeaturesVec.push_back(HasAVX10_512 ? "+evex512" : "-evex512");

diff  --git a/clang/lib/Headers/avx2intrin.h b/clang/lib/Headers/avx2intrin.h
index 096cae01b57d01..dc9fc073143236 100644
--- a/clang/lib/Headers/avx2intrin.h
+++ b/clang/lib/Headers/avx2intrin.h
@@ -15,12 +15,21 @@
 #define __AVX2INTRIN_H
 
 /* Define the default attributes for the functions in this file. */
+#if defined(__EVEX512__) && !defined(__AVX10_1_512__)
 #define __DEFAULT_FN_ATTRS256  
\
   __attribute__((__always_inline__, __nodebug__,   
\
  __target__("avx2,no-evex512"), __min_vector_width__(256)))
 #define __DEFAULT_FN_ATTRS128  
\
   __attribute__((__always_inline__, __nodebug__,   
\
  __target__("avx2,no-evex512"), __min_vector_width__(128)))
+#else
+#define __DEFAULT_FN_ATTRS256  
\
+  __attribute__((__always_inline__, __nodebug__, __target__("avx2"),   
\
+ __min_vector_width__(256)))
+#define __DEFAULT_FN_ATTRS128  
\
+  __attribute__((__always_inline__, __nodebug__, __target__("avx2"),   
\
+ __min_vector_width__(128)))
+#endif
 
 /* SSE4 Multiple Packed Sums of Absolute Difference.  */
 /// Computes sixteen sum of absolute 
diff erence (SAD) operations on sets of

diff  --git a/clang/lib/Headers/avxintrin.h b/clang/lib/Headers/avxintrin.h
index 4983f331137001..73707c623065e7 100644
--- a/clang/lib/Headers/avxintrin.h
+++ b/clang/lib/Headers/avxintrin.h
@@ -50,12 +50,21 @@ typedef __bf16 __m256bh __attribute__((__vector_size__(32), 
__aligned__(32)));
 #endif
 
 /* Define the default attributes for the functions in this file. */
+#if defined(__EVEX512__) && !defined(__AVX10_1_512__)
 #define __DEFAULT_FN_ATTRS 
\
   __attribute__((__always_inline__, __nodebug__, __target__("avx,no-evex512"), 
\
  __min_vector_width__(256)))
 #define __DEFAULT_FN_ATTRS128  
\
   __attribute__((__always_inline__, __nodebug__, __target__("avx,no-evex512"), 
\
  __min_vector_width__(128)))
+#else
+#define __DEFAULT_FN_ATTRS 
\
+  __attribute__((__always_inline__, __nodebug__, __target__("avx"),
\
+ __min_vector_width__(256)))
+#define __DEFAULT_FN_ATTRS128  
\
+  __attribute__((__always_inline__, __nodebug__, __target__("avx"),
\
+ __min_vector_width__(128)))
+#endif
 
 /* Arithmetic */
 /// Adds two 256-bit vectors of [4 x double].

diff  --git a/clang/lib/Headers/emmin

[clang] [X86][AVX10] Fix unexpected error and warning when using intrinsic (PR #104781)

2024-08-20 Thread Phoebe Wang via cfe-commits

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


[clang] 39e3085 - [clang][NFC] Split invalid-cpu-note tests (#104601)

2024-08-20 Thread via cfe-commits

Author: Sam Elliott
Date: 2024-08-20T12:56:49+01:00
New Revision: 39e3085a55880dbbc5aeddc3661342980d5e1467

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

LOG: [clang][NFC] Split invalid-cpu-note tests (#104601)

This change does two kinds of splits:
- Splits each target into a different file. Some targets are left in the
same files, such as riscv32/64 and x86/_64 as these tests and lists are
very similar.
- Splits up the very long 'note:' lines which contain a list of CPUs,
using `CHECK-SAME`. There was a note about this not being possible
before, but with `{{^}}`, this is now possible -- I have
verified that this does the right thing if a single CPU anywhere in the
list is left out.

These tests had become quite annoying to change when adding a CPU, and I
believe this change makes these easier to maintain, and should cut down
on conflicts in these files (or at least makes conflicts easier to
resolve).

I apologise in advance for downstream conflicts, but hopefully that's a
small amount of short term pain, in return for fewer conflicts in
future.

Added: 
clang/test/Misc/target-invalid-cpu-note/aarch64.c
clang/test/Misc/target-invalid-cpu-note/amdgcn.c
clang/test/Misc/target-invalid-cpu-note/arm.c
clang/test/Misc/target-invalid-cpu-note/avr.c
clang/test/Misc/target-invalid-cpu-note/bpf.c
clang/test/Misc/target-invalid-cpu-note/hexagon.c
clang/test/Misc/target-invalid-cpu-note/lanai.c
clang/test/Misc/target-invalid-cpu-note/mips.c
clang/test/Misc/target-invalid-cpu-note/nvptx.c
clang/test/Misc/target-invalid-cpu-note/powerpc.c
clang/test/Misc/target-invalid-cpu-note/r600.c
clang/test/Misc/target-invalid-cpu-note/riscv.c
clang/test/Misc/target-invalid-cpu-note/sparc.c
clang/test/Misc/target-invalid-cpu-note/systemz.c
clang/test/Misc/target-invalid-cpu-note/wasm.c
clang/test/Misc/target-invalid-cpu-note/x86.c

Modified: 


Removed: 
clang/test/Misc/target-invalid-cpu-note.c



diff  --git a/clang/test/Misc/target-invalid-cpu-note.c 
b/clang/test/Misc/target-invalid-cpu-note.c
deleted file mode 100644
index b1783f3917a350..00
--- a/clang/test/Misc/target-invalid-cpu-note.c
+++ /dev/null
@@ -1,96 +0,0 @@
-// Use CHECK-NEXT instead of multiple CHECK-SAME to ensure we will fail if 
there is anything extra in the output.
-// RUN: not %clang_cc1 -triple armv5--- -target-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix ARM
-// ARM: error: unknown target CPU 'not-a-cpu'
-// ARM-NEXT: note: valid target CPU values are: arm8, arm810, strongarm, 
strongarm110, strongarm1100, strongarm1110, arm7tdmi, arm7tdmi-s, arm710t, 
arm720t, arm9, arm9tdmi, arm920, arm920t, arm922t, arm940t, ep9312, arm10tdmi, 
arm1020t, arm9e, arm946e-s, arm966e-s, arm968e-s, arm10e, arm1020e, arm1022e, 
arm926ej-s, arm1136j-s, arm1136jf-s, mpcore, mpcorenovfp, arm1176jz-s, 
arm1176jzf-s, arm1156t2-s, arm1156t2f-s, cortex-m0, cortex-m0plus, cortex-m1, 
sc000, cortex-a5, cortex-a7, cortex-a8, cortex-a9, cortex-a12, cortex-a15, 
cortex-a17, krait, cortex-r4, cortex-r4f, cortex-r5, cortex-r7, cortex-r8, 
cortex-r52, cortex-r52plus, sc300, cortex-m3, cortex-m4, cortex-m7, cortex-m23, 
cortex-m33, cortex-m35p, cortex-m55, cortex-m85, cortex-m52, cortex-a32, 
cortex-a35, cortex-a53, cortex-a55, cortex-a57, cortex-a72, cortex-a73, 
cortex-a75, cortex-a76, cortex-a76ae, cortex-a77, cortex-a78, cortex-a78ae, 
cortex-a78c, cortex-a710, cortex-x1, cortex-x1c, neoverse-n1, neoverse-n2, 
neoverse-v1, cyclone, exynos-m3, exynos-m4, exynos-m5, kryo, iwmmxt, xscale, 
swift{{$}}
-
-// RUN: not %clang_cc1 -triple arm64--- -target-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix AARCH64
-// AARCH64: error: unknown target CPU 'not-a-cpu'
-// AARCH64-NEXT: note: valid target CPU values are: a64fx, ampere1, ampere1a, 
ampere1b, apple-a10, apple-a11, apple-a12, apple-a13, apple-a14, apple-a15, 
apple-a16, apple-a17, apple-a7, apple-a8, apple-a9, apple-m1, apple-m2, 
apple-m3, apple-m4, apple-s4, apple-s5, carmel, cobalt-100, cortex-a34, 
cortex-a35, cortex-a510, cortex-a520, cortex-a520ae, cortex-a53, cortex-a55, 
cortex-a57, cortex-a65, cortex-a65ae, cortex-a710, cortex-a715, cortex-a72, 
cortex-a720, cortex-a720ae, cortex-a725, cortex-a73, cortex-a75, cortex-a76, 
cortex-a76ae, cortex-a77, cortex-a78, cortex-a78ae, cortex-a78c, cortex-r82, 
cortex-r82ae, cortex-x1, cortex-x1c, cortex-x2, cortex-x3, cortex-x4, 
cortex-x925, cyclone, exynos-m3, exynos-m4, exynos-m5, falkor, generic, grace, 
kryo, neoverse-512tvb, neoverse-e1, neoverse-n1, neoverse-n2, neoverse-n3, 
neoverse-v1, neoverse-v2, neoverse-v3, neoverse-v3ae, oryon-1, saphira, 
thunderx, thunderx2t99, thunderx3t110, thunderxt81, thunderxt83, thunderxt88, 
tsv110{{$}}
-
-// 

[clang] [clang][NFC] Split invalid-cpu-note tests (PR #104601)

2024-08-20 Thread Sam Elliott via cfe-commits

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


[clang] [clang] Improve diagnostics with incompatible VLA types (PR #101261)

2024-08-20 Thread Andrew Sukach via cfe-commits

https://github.com/sookach updated 
https://github.com/llvm/llvm-project/pull/101261

>From 2666871e019dee2314933cc60bcb4ca27d7555ba Mon Sep 17 00:00:00 2001
From: Andrew Sukach 
Date: Tue, 30 Jul 2024 19:31:41 -0400
Subject: [PATCH] [clang] Improve diagnostics with incompatible VLA types

---
 .../clang/Basic/DiagnosticSemaKinds.td|  3 ++
 clang/lib/Basic/Diagnostic.cpp| 35 +--
 .../test/Sema/incompatible-vla-assignment.cpp |  9 +
 3 files changed, 37 insertions(+), 10 deletions(-)
 create mode 100644 clang/test/Sema/incompatible-vla-assignment.cpp

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 9e6d85c469d641..5533ffb4b991c3 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8643,6 +8643,9 @@ def err_typecheck_convert_incompatible_pointer : Error<
   "; take the address with &|"
   "; remove *|"
   "; remove &}3">;
+def err_typecheck_convert_incompatible_vla : Error<
+  "incompatible assignment of pointers of variable-length array type %0"
+  "; consider using a typedef to use the same variable-length array type for 
both operands">;
 def err_typecheck_convert_incompatible_function_pointer : Error<
   "incompatible function pointer types "
   "%select{%diff{assigning to $ from $|assigning to different types}0,1"
diff --git a/clang/lib/Basic/Diagnostic.cpp b/clang/lib/Basic/Diagnostic.cpp
index 66776daa5e1493..b7029dd6472e7c 100644
--- a/clang/lib/Basic/Diagnostic.cpp
+++ b/clang/lib/Basic/Diagnostic.cpp
@@ -1099,37 +1099,52 @@ FormatDiagnostic(const char *DiagStr, const char 
*DiagEnd,
   const char *FirstDollar = ScanFormat(Argument, ArgumentEnd, '$');
   const char *SecondDollar = ScanFormat(FirstDollar + 1, ArgumentEnd, '$');
 
-  // Append before text
-  FormatDiagnostic(Argument, FirstDollar, OutStr);
-
-  // Append first type
+  // Get first type text
   TDT.PrintTree = false;
   TDT.PrintFromType = true;
+  SmallString<64> FromTypeStr, ToTypeStr;
   getDiags()->ConvertArgToString(Kind, val,
  StringRef(Modifier, ModifierLen),
  StringRef(Argument, ArgumentLen),
  FormattedArgs,
- OutStr, QualTypeVals);
+ FromTypeStr, QualTypeVals);
   if (!TDT.TemplateDiffUsed)
 FormattedArgs.push_back(std::make_pair(DiagnosticsEngine::ak_qualtype,
TDT.FromType));
 
-  // Append middle text
-  FormatDiagnostic(FirstDollar + 1, SecondDollar, OutStr);
-
-  // Append second type
+  // Get second type text
   TDT.PrintFromType = false;
   getDiags()->ConvertArgToString(Kind, val,
  StringRef(Modifier, ModifierLen),
  StringRef(Argument, ArgumentLen),
  FormattedArgs,
- OutStr, QualTypeVals);
+ ToTypeStr, QualTypeVals);
   if (!TDT.TemplateDiffUsed)
 FormattedArgs.push_back(std::make_pair(DiagnosticsEngine::ak_qualtype,
TDT.ToType));
 
+  // Append before text
+  FormatDiagnostic(Argument, FirstDollar, OutStr);
+
+  // Append first type
+  OutStr.append(FromTypeStr);
+
+  // Append middle text
+  FormatDiagnostic(FirstDollar + 1, SecondDollar, OutStr);
+
+  // Append second type
+  OutStr.append(ToTypeStr);
+
   // Append end text
   FormatDiagnostic(SecondDollar + 1, Pipe, OutStr);
+
+  if (FromTypeStr == ToTypeStr) {
+SmallString<86> IncompatibleVLADiag(
+"; consider using a typedef to use the same variable-length array "
+"type for both operands");
+OutStr.append(IncompatibleVLADiag);
+  }
+
   break;
 }
 }
diff --git a/clang/test/Sema/incompatible-vla-assignment.cpp 
b/clang/test/Sema/incompatible-vla-assignment.cpp
new file mode 100644
index 00..8be063631b7a8a
--- /dev/null
+++ b/clang/test/Sema/incompatible-vla-assignment.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+void func(int n) {
+int grp[n][n];
+int (*ptr)[n];
+
+for (int i = 0; i < n; i++)
+ptr = &grp[i]; // expected-error {{incompatible pointer types 
assigning to 'int (*)[n]' from 'int (*)[n]'; consider using a typedef to use 
the same variable-length array type for both operands}}
+}

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


[clang] [llvm] [Clang][AArch64] Add customisable immediate range checking to NEON (PR #100278)

2024-08-20 Thread via cfe-commits


@@ -1959,9 +2064,12 @@ multiclass VCMLA_ROTS {
 
 let isLaneQ = 1 in  {
   // vcmla{ROT}_laneq
+  // ACLE specifies that the fp16 vcmla_#ROT_laneq variant has an 
immedaite range of 0 <= lane <= 1.
+  // fp16 is the only variant for which these two differ.
+  // https://developer.arm.com/documentation/ihi0073/latest/ 
+  defvar getlanety = !if(!eq(type, "h"), lanety, laneqty);
   def : SOpInst<"vcmla" # ROT # "_laneq", "...QI", type,  Op<(call "vcmla" 
# ROT, $p0, $p1,
-  (bitcast $p0, (dup_typed lanety, (call "vget_lane", (bitcast 
laneqty, $p2), $p3>>;
-
+(bitcast $p0, (dup_typed lanety, (call "vget_lane", (bitcast 
getlanety, $p2), $p3>>;

rsandifo-arm wrote:

> [I]f you look at the most recent spec for this 
> [instruction](https://developer.arm.com/documentation/ddi0602/2024-06/SVE-Instructions/FCMLA--indexed---Floating-point-complex-multiply-add-by-indexed-values-with-rotate-),
>  it says quite clearly that immediate range for half-precision variant is 
> from 0 to 3

That link is to the SVE instruction though, rather than the Advanced SIMD one.  
The range for the 8H Advanced SIMD instruction is [0, 3], but the range for the 
4H one is [0, 1].

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


[clang] [clang] Improve diagnostics with incompatible VLA types (PR #101261)

2024-08-20 Thread Andrew Sukach via cfe-commits

https://github.com/sookach updated 
https://github.com/llvm/llvm-project/pull/101261

>From 5df72d9e8e89079b2c5312583e66756c048e5abe Mon Sep 17 00:00:00 2001
From: Andrew Sukach 
Date: Tue, 30 Jul 2024 19:31:41 -0400
Subject: [PATCH] [clang] Improve diagnostics with incompatible VLA types

---
 clang/lib/Basic/Diagnostic.cpp| 35 +--
 .../test/Sema/incompatible-vla-assignment.cpp |  9 +
 2 files changed, 34 insertions(+), 10 deletions(-)
 create mode 100644 clang/test/Sema/incompatible-vla-assignment.cpp

diff --git a/clang/lib/Basic/Diagnostic.cpp b/clang/lib/Basic/Diagnostic.cpp
index 66776daa5e1493..b7029dd6472e7c 100644
--- a/clang/lib/Basic/Diagnostic.cpp
+++ b/clang/lib/Basic/Diagnostic.cpp
@@ -1099,37 +1099,52 @@ FormatDiagnostic(const char *DiagStr, const char 
*DiagEnd,
   const char *FirstDollar = ScanFormat(Argument, ArgumentEnd, '$');
   const char *SecondDollar = ScanFormat(FirstDollar + 1, ArgumentEnd, '$');
 
-  // Append before text
-  FormatDiagnostic(Argument, FirstDollar, OutStr);
-
-  // Append first type
+  // Get first type text
   TDT.PrintTree = false;
   TDT.PrintFromType = true;
+  SmallString<64> FromTypeStr, ToTypeStr;
   getDiags()->ConvertArgToString(Kind, val,
  StringRef(Modifier, ModifierLen),
  StringRef(Argument, ArgumentLen),
  FormattedArgs,
- OutStr, QualTypeVals);
+ FromTypeStr, QualTypeVals);
   if (!TDT.TemplateDiffUsed)
 FormattedArgs.push_back(std::make_pair(DiagnosticsEngine::ak_qualtype,
TDT.FromType));
 
-  // Append middle text
-  FormatDiagnostic(FirstDollar + 1, SecondDollar, OutStr);
-
-  // Append second type
+  // Get second type text
   TDT.PrintFromType = false;
   getDiags()->ConvertArgToString(Kind, val,
  StringRef(Modifier, ModifierLen),
  StringRef(Argument, ArgumentLen),
  FormattedArgs,
- OutStr, QualTypeVals);
+ ToTypeStr, QualTypeVals);
   if (!TDT.TemplateDiffUsed)
 FormattedArgs.push_back(std::make_pair(DiagnosticsEngine::ak_qualtype,
TDT.ToType));
 
+  // Append before text
+  FormatDiagnostic(Argument, FirstDollar, OutStr);
+
+  // Append first type
+  OutStr.append(FromTypeStr);
+
+  // Append middle text
+  FormatDiagnostic(FirstDollar + 1, SecondDollar, OutStr);
+
+  // Append second type
+  OutStr.append(ToTypeStr);
+
   // Append end text
   FormatDiagnostic(SecondDollar + 1, Pipe, OutStr);
+
+  if (FromTypeStr == ToTypeStr) {
+SmallString<86> IncompatibleVLADiag(
+"; consider using a typedef to use the same variable-length array "
+"type for both operands");
+OutStr.append(IncompatibleVLADiag);
+  }
+
   break;
 }
 }
diff --git a/clang/test/Sema/incompatible-vla-assignment.cpp 
b/clang/test/Sema/incompatible-vla-assignment.cpp
new file mode 100644
index 00..8be063631b7a8a
--- /dev/null
+++ b/clang/test/Sema/incompatible-vla-assignment.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+void func(int n) {
+int grp[n][n];
+int (*ptr)[n];
+
+for (int i = 0; i < n; i++)
+ptr = &grp[i]; // expected-error {{incompatible pointer types 
assigning to 'int (*)[n]' from 'int (*)[n]'; consider using a typedef to use 
the same variable-length array type for both operands}}
+}

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


[clang] [llvm] [RISCV] Add Hazard3 Core as taped out for RP2350 (PR #102452)

2024-08-20 Thread Sam Elliott via cfe-commits

lenary wrote:

The commit this was stacked on is merged, and I think we have sorted out naming 
issues and pinned down the exact cpu configuration, so I think this is ready 
for review and merge.

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


[clang] [clang] Improve diagnostics with incompatible VLA types (PR #101261)

2024-08-20 Thread Andrew Sukach via cfe-commits

https://github.com/sookach updated 
https://github.com/llvm/llvm-project/pull/101261

>From 6f1868ec7aebf24cfd61472a1a33f6bd65ebeeb5 Mon Sep 17 00:00:00 2001
From: Andrew Sukach 
Date: Tue, 30 Jul 2024 19:31:41 -0400
Subject: [PATCH] [clang] Improve diagnostics with incompatible VLA types

---
 clang/lib/Basic/Diagnostic.cpp| 45 ---
 .../test/Sema/incompatible-vla-assignment.cpp |  9 
 2 files changed, 38 insertions(+), 16 deletions(-)
 create mode 100644 clang/test/Sema/incompatible-vla-assignment.cpp

diff --git a/clang/lib/Basic/Diagnostic.cpp b/clang/lib/Basic/Diagnostic.cpp
index 66776daa5e1493..cba350b4727547 100644
--- a/clang/lib/Basic/Diagnostic.cpp
+++ b/clang/lib/Basic/Diagnostic.cpp
@@ -1099,37 +1099,50 @@ FormatDiagnostic(const char *DiagStr, const char 
*DiagEnd,
   const char *FirstDollar = ScanFormat(Argument, ArgumentEnd, '$');
   const char *SecondDollar = ScanFormat(FirstDollar + 1, ArgumentEnd, '$');
 
-  // Append before text
-  FormatDiagnostic(Argument, FirstDollar, OutStr);
-
-  // Append first type
+  // Get first type text
   TDT.PrintTree = false;
   TDT.PrintFromType = true;
+  SmallString<64> FromTypeStr, ToTypeStr;
   getDiags()->ConvertArgToString(Kind, val,
  StringRef(Modifier, ModifierLen),
  StringRef(Argument, ArgumentLen),
- FormattedArgs,
- OutStr, QualTypeVals);
+ FormattedArgs, FromTypeStr, QualTypeVals);
   if (!TDT.TemplateDiffUsed)
-FormattedArgs.push_back(std::make_pair(DiagnosticsEngine::ak_qualtype,
-   TDT.FromType));
+FormattedArgs.push_back(
+std::make_pair(DiagnosticsEngine::ak_qualtype, TDT.FromType));
 
-  // Append middle text
-  FormatDiagnostic(FirstDollar + 1, SecondDollar, OutStr);
-
-  // Append second type
+  // Get second type text
   TDT.PrintFromType = false;
   getDiags()->ConvertArgToString(Kind, val,
  StringRef(Modifier, ModifierLen),
  StringRef(Argument, ArgumentLen),
- FormattedArgs,
- OutStr, QualTypeVals);
+ FormattedArgs, ToTypeStr, QualTypeVals);
   if (!TDT.TemplateDiffUsed)
-FormattedArgs.push_back(std::make_pair(DiagnosticsEngine::ak_qualtype,
-   TDT.ToType));
+FormattedArgs.push_back(
+std::make_pair(DiagnosticsEngine::ak_qualtype, TDT.ToType));
+
+  // Append before text
+  FormatDiagnostic(Argument, FirstDollar, OutStr);
+
+  // Append first type
+  OutStr.append(FromTypeStr);
+
+  // Append middle text
+  FormatDiagnostic(FirstDollar + 1, SecondDollar, OutStr);
+
+  // Append second type
+  OutStr.append(ToTypeStr);
 
   // Append end text
   FormatDiagnostic(SecondDollar + 1, Pipe, OutStr);
+
+  if (FromTypeStr == ToTypeStr) {
+SmallString<86> IncompatibleVLADiag(
+"; consider using a typedef to use the same variable-length array "
+"type for both operands");
+OutStr.append(IncompatibleVLADiag);
+  }
+
   break;
 }
 }
diff --git a/clang/test/Sema/incompatible-vla-assignment.cpp 
b/clang/test/Sema/incompatible-vla-assignment.cpp
new file mode 100644
index 00..8be063631b7a8a
--- /dev/null
+++ b/clang/test/Sema/incompatible-vla-assignment.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+void func(int n) {
+int grp[n][n];
+int (*ptr)[n];
+
+for (int i = 0; i < n; i++)
+ptr = &grp[i]; // expected-error {{incompatible pointer types 
assigning to 'int (*)[n]' from 'int (*)[n]'; consider using a typedef to use 
the same variable-length array type for both operands}}
+}

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


[clang] [llvm] [AMDGPU] Convert AMDGPUResourceUsageAnalysis pass from Module to MF pass (PR #102913)

2024-08-20 Thread Janek van Oirschot via cfe-commits


@@ -68,82 +71,84 @@ void MCResourceInfo::assignMaxRegs() {
   assignMaxRegSym(MaxSGPRSym, MaxSGPR);
 }
 
-void MCResourceInfo::finalize() {
-  assert(!finalized && "Cannot finalize ResourceInfo again.");
-  finalized = true;
-  assignMaxRegs();
+void MCResourceInfo::finalize(MCContext &OutContext) {
+  assert(!Finalized && "Cannot finalize ResourceInfo again.");
+  Finalized = true;
+  assignMaxRegs(OutContext);
 }
 
-MCSymbol *MCResourceInfo::getMaxVGPRSymbol() {
+MCSymbol *MCResourceInfo::getMaxVGPRSymbol(MCContext &OutContext) {
   return OutContext.getOrCreateSymbol("max_num_vgpr");
 }
 
-MCSymbol *MCResourceInfo::getMaxAGPRSymbol() {
+MCSymbol *MCResourceInfo::getMaxAGPRSymbol(MCContext &OutContext) {
   return OutContext.getOrCreateSymbol("max_num_agpr");
 }
 
-MCSymbol *MCResourceInfo::getMaxSGPRSymbol() {
+MCSymbol *MCResourceInfo::getMaxSGPRSymbol(MCContext &OutContext) {
   return OutContext.getOrCreateSymbol("max_num_sgpr");
 }
 
 void MCResourceInfo::assignResourceInfoExpr(
-int64_t localValue, ResourceInfoKind RIK, AMDGPUMCExpr::VariantKind Kind,
-const MachineFunction &MF,
-const SmallVectorImpl &Callees) {
-  const MCConstantExpr *localConstExpr =
-  MCConstantExpr::create(localValue, OutContext);
-  const MCExpr *SymVal = localConstExpr;
+int64_t LocalValue, ResourceInfoKind RIK, AMDGPUMCExpr::VariantKind Kind,
+const MachineFunction &MF, const SmallVectorImpl 
&Callees,
+MCContext &OutContext) {
+  const MCConstantExpr *LocalConstExpr =
+  MCConstantExpr::create(LocalValue, OutContext);
+  const MCExpr *SymVal = LocalConstExpr;

JanekvO wrote:

As in, finding the module level maximum?

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


[clang] [clang] Improve diagnostics with incompatible VLA types (PR #101261)

2024-08-20 Thread Andrew Sukach via cfe-commits

sookach wrote:

Sorry for taking so long, but the new commit handles the diagnostic a little 
differently. I store the text types in temporary strings and then append a 
message to the diagnostic if the texts are identical.

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


[clang] [clang] Improve diagnostics with incompatible VLA types (PR #101261)

2024-08-20 Thread Andrew Sukach via cfe-commits


@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+void func(int n) {
+int grp[n][n];
+int (*ptr)[n];
+
+for (int i = 0; i < n; i++)
+ptr = &grp[i]; // expected-error {{incompatible assignment of pointers 
of variable-length array type 'int (*)[n]'; consider using a typedef to use the 
same variable-length array type for both operands}}
+}

sookach wrote:

Just out of curiosity, what does the new line do? or is it just a formatting 
thing?

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


[clang] [clang] Improve diagnostics with incompatible VLA types (PR #101261)

2024-08-20 Thread Andrew Sukach via cfe-commits

https://github.com/sookach updated 
https://github.com/llvm/llvm-project/pull/101261

>From 1de106f82720ea6c470ce6c974c19f966599b9cc Mon Sep 17 00:00:00 2001
From: Andrew Sukach 
Date: Tue, 30 Jul 2024 19:31:41 -0400
Subject: [PATCH] [clang] Improve diagnostics with incompatible VLA types

---
 clang/lib/Basic/Diagnostic.cpp| 45 ---
 .../test/Sema/incompatible-vla-assignment.cpp |  9 
 2 files changed, 38 insertions(+), 16 deletions(-)
 create mode 100644 clang/test/Sema/incompatible-vla-assignment.cpp

diff --git a/clang/lib/Basic/Diagnostic.cpp b/clang/lib/Basic/Diagnostic.cpp
index 66776daa5e1493..9e1d2f996147a9 100644
--- a/clang/lib/Basic/Diagnostic.cpp
+++ b/clang/lib/Basic/Diagnostic.cpp
@@ -1099,37 +1099,50 @@ FormatDiagnostic(const char *DiagStr, const char 
*DiagEnd,
   const char *FirstDollar = ScanFormat(Argument, ArgumentEnd, '$');
   const char *SecondDollar = ScanFormat(FirstDollar + 1, ArgumentEnd, '$');
 
-  // Append before text
-  FormatDiagnostic(Argument, FirstDollar, OutStr);
-
-  // Append first type
+  // Get first type text
   TDT.PrintTree = false;
   TDT.PrintFromType = true;
+  SmallString<64> FromTypeStr, ToTypeStr;
   getDiags()->ConvertArgToString(Kind, val,
  StringRef(Modifier, ModifierLen),
  StringRef(Argument, ArgumentLen),
- FormattedArgs,
- OutStr, QualTypeVals);
+ FormattedArgs, FromTypeStr, QualTypeVals);
   if (!TDT.TemplateDiffUsed)
-FormattedArgs.push_back(std::make_pair(DiagnosticsEngine::ak_qualtype,
-   TDT.FromType));
+FormattedArgs.push_back(
+std::make_pair(DiagnosticsEngine::ak_qualtype, TDT.FromType));
 
-  // Append middle text
-  FormatDiagnostic(FirstDollar + 1, SecondDollar, OutStr);
-
-  // Append second type
+  // Get second type text
   TDT.PrintFromType = false;
   getDiags()->ConvertArgToString(Kind, val,
  StringRef(Modifier, ModifierLen),
  StringRef(Argument, ArgumentLen),
- FormattedArgs,
- OutStr, QualTypeVals);
+ FormattedArgs, ToTypeStr, QualTypeVals);
   if (!TDT.TemplateDiffUsed)
-FormattedArgs.push_back(std::make_pair(DiagnosticsEngine::ak_qualtype,
-   TDT.ToType));
+FormattedArgs.push_back(
+std::make_pair(DiagnosticsEngine::ak_qualtype, TDT.ToType));
+
+  // Append before text
+  FormatDiagnostic(Argument, FirstDollar, OutStr);
+
+  // Append first type
+  OutStr.append(FromTypeStr);
+
+  // Append middle text
+  FormatDiagnostic(FirstDollar + 1, SecondDollar, OutStr);
+
+  // Append second type
+  OutStr.append(ToTypeStr);
 
   // Append end text
   FormatDiagnostic(SecondDollar + 1, Pipe, OutStr);
+
+  if (FromTypeStr == ToTypeStr) {
+SmallString<88> IncompatibleVLADiag(
+"; consider using a typedef to use the same variable-length array "
+"type for both operands");
+OutStr.append(IncompatibleVLADiag);
+  }
+
   break;
 }
 }
diff --git a/clang/test/Sema/incompatible-vla-assignment.cpp 
b/clang/test/Sema/incompatible-vla-assignment.cpp
new file mode 100644
index 00..8be063631b7a8a
--- /dev/null
+++ b/clang/test/Sema/incompatible-vla-assignment.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+void func(int n) {
+int grp[n][n];
+int (*ptr)[n];
+
+for (int i = 0; i < n; i++)
+ptr = &grp[i]; // expected-error {{incompatible pointer types 
assigning to 'int (*)[n]' from 'int (*)[n]'; consider using a typedef to use 
the same variable-length array type for both operands}}
+}

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


[clang] [llvm] [Clang][AArch64] Add customisable immediate range checking to NEON (PR #100278)

2024-08-20 Thread via cfe-commits


@@ -1959,9 +2064,12 @@ multiclass VCMLA_ROTS {
 
 let isLaneQ = 1 in  {
   // vcmla{ROT}_laneq
+  // ACLE specifies that the fp16 vcmla_#ROT_laneq variant has an 
immedaite range of 0 <= lane <= 1.
+  // fp16 is the only variant for which these two differ.
+  // https://developer.arm.com/documentation/ihi0073/latest/ 
+  defvar getlanety = !if(!eq(type, "h"), lanety, laneqty);
   def : SOpInst<"vcmla" # ROT # "_laneq", "...QI", type,  Op<(call "vcmla" 
# ROT, $p0, $p1,
-  (bitcast $p0, (dup_typed lanety, (call "vget_lane", (bitcast 
laneqty, $p2), $p3>>;
-
+(bitcast $p0, (dup_typed lanety, (call "vget_lane", (bitcast 
getlanety, $p2), $p3>>;

Lukacma wrote:

Apologies got confused there. Now I see what you are talking about. But to me 
it seems that whoever wrote this part of ACLE still wanted to allow lane to be 
from 0 to 3 and got around this limitation of the instruction by using DUP . So 
if we want to be consistent with ACLE we should still allow this wider range. 
Or do you think we should go and propose changing ACLE for this variant? 

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


[clang] [llvm] [RISC-V] Make EmitRISCVCpuSupports accept multiple features (PR #104917)

2024-08-20 Thread Piyou Chen via cfe-commits

https://github.com/BeMg updated https://github.com/llvm/llvm-project/pull/104917

>From c8b31f1e1d1d30cb8523772d3fd15a0358c540d6 Mon Sep 17 00:00:00 2001
From: Piyou Chen 
Date: Tue, 20 Aug 2024 04:37:20 -0700
Subject: [PATCH 1/2] [RISC-V] Make EmitRISCVCpuSupports accept multiple
 features

This patch creates an additional EmitRISCVCpuSupports function to handle 
situations with multiple features. It also modifies the original 
EmitRISCVCpuSupports function to invoke the new one.
---
 clang/lib/CodeGen/CGBuiltin.cpp   | 71 --
 clang/lib/CodeGen/CodeGenFunction.h   |  1 +
 clang/test/CodeGen/builtin-cpu-supports.c | 72 ++-
 .../llvm/TargetParser/RISCVTargetParser.h |  2 +
 4 files changed, 91 insertions(+), 55 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index f424ddaa175400..39df4f134c9ef3 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -64,6 +64,7 @@
 #include "llvm/Support/ScopedPrinter.h"
 #include "llvm/TargetParser/AArch64TargetParser.h"
 #include "llvm/TargetParser/RISCVISAInfo.h"
+#include "llvm/TargetParser/RISCVTargetParser.h"
 #include "llvm/TargetParser/X86TargetParser.h"
 #include 
 #include 
@@ -14439,33 +14440,57 @@ Value *CodeGenFunction::EmitRISCVCpuSupports(const 
CallExpr *E) {
   if (!getContext().getTargetInfo().validateCpuSupports(FeatureStr))
 return Builder.getFalse();
 
-  // Note: We are making an unchecked assumption that the size of the
-  // feature array is >= 1.  This holds for any version of compiler-rt
-  // which defines this interface.
-  llvm::ArrayType *ArrayOfInt64Ty = llvm::ArrayType::get(Int64Ty, 1);
+  return EmitRISCVCpuSupports(ArrayRef(FeatureStr));
+}
+
+static Value *loadRISCVFeatureBits(unsigned Index, CGBuilderTy &Builder,
+   CodeGenModule &CGM,
+   llvm::LLVMContext &Context) {
+  llvm::Type *Int32Ty = llvm::Type::getInt32Ty(Context);
+  llvm::Type *Int64Ty = llvm::Type::getInt64Ty(Context);
+  llvm::ArrayType *ArrayOfInt64Ty =
+  llvm::ArrayType::get(Int64Ty, llvm::RISCV::RISCVFeatureBitSize);
   llvm::Type *StructTy = llvm::StructType::get(Int32Ty, ArrayOfInt64Ty);
   llvm::Constant *RISCVFeaturesBits =
   CGM.CreateRuntimeVariable(StructTy, "__riscv_feature_bits");
-  auto *GV = cast(RISCVFeaturesBits);
-  GV->setDSOLocal(true);
-
-  auto LoadFeatureBit = [&](unsigned Index) {
-// Create GEP then load.
-Value *IndexVal = llvm::ConstantInt::get(Int32Ty, Index);
-llvm::Value *GEPIndices[] = {Builder.getInt32(0), Builder.getInt32(1),
- IndexVal};
-Value *Ptr =
-Builder.CreateInBoundsGEP(StructTy, RISCVFeaturesBits, GEPIndices);
-Value *FeaturesBit =
-Builder.CreateAlignedLoad(Int64Ty, Ptr, CharUnits::fromQuantity(8));
-return FeaturesBit;
-  };
+  cast(RISCVFeaturesBits)->setDSOLocal(true);
+  Value *IndexVal = llvm::ConstantInt::get(Int32Ty, Index);
+  llvm::Value *GEPIndices[] = {Builder.getInt32(0), Builder.getInt32(1),
+   IndexVal};
+  Value *Ptr =
+  Builder.CreateInBoundsGEP(StructTy, RISCVFeaturesBits, GEPIndices);
+  Value *FeaturesBit =
+  Builder.CreateAlignedLoad(Int64Ty, Ptr, CharUnits::fromQuantity(8));
+  return FeaturesBit;
+}
+
+Value *CodeGenFunction::EmitRISCVCpuSupports(ArrayRef FeaturesStrs) 
{
+  const unsigned RISCVFeatureLength = llvm::RISCV::RISCVFeatureBitSize;
+  SmallVector RequireBitMasks(RISCVFeatureLength);
+
+  for (auto Feat : FeaturesStrs) {
+auto [GroupID, BitPos] = RISCVISAInfo::getRISCVFeaturesBitsInfo(Feat);
+
+// If there isn't BitPos for this feature, skip this version.
+// It also report the warning to user during compilation.
+if (BitPos == -1)
+  return Builder.getFalse();
 
-  auto [GroupID, BitPos] = RISCVISAInfo::getRISCVFeaturesBitsInfo(FeatureStr);
-  assert(BitPos != -1 && "validation should have rejected this feature");
-  Value *MaskV = Builder.getInt64(1ULL << BitPos);
-  Value *Bitset = Builder.CreateAnd(LoadFeatureBit(GroupID), MaskV);
-  return Builder.CreateICmpEQ(Bitset, MaskV);
+RequireBitMasks[GroupID] |= (1ULL << BitPos);
+  }
+
+  Value *Result = Builder.getTrue();
+  for (unsigned Idx = 0; Idx < RISCVFeatureLength; Idx++) {
+if (RequireBitMasks[Idx] == 0)
+  continue;
+
+Value *Mask = Builder.getInt64(RequireBitMasks[Idx]);
+Value *Bitset = Builder.CreateAnd(
+loadRISCVFeatureBits(Idx, Builder, CGM, getLLVMContext()), Mask);
+Value *CmpV = Builder.CreateICmpEQ(Bitset, Mask);
+Result = Builder.CreateAnd(Result, CmpV);
+  }
+  return Result;
 }
 
 Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned BuiltinID,
diff --git a/clang/lib/CodeGen/CodeGenFunction.h 
b/clang/lib/CodeGen/CodeGenFunction.h
index 57e0b7f91e9bf8..e1b9ada3c1e1fd 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction

[clang] [llvm] [AMDGPU] Convert AMDGPUResourceUsageAnalysis pass from Module to MF pass (PR #102913)

2024-08-20 Thread Matt Arsenault via cfe-commits


@@ -68,82 +71,84 @@ void MCResourceInfo::assignMaxRegs() {
   assignMaxRegSym(MaxSGPRSym, MaxSGPR);
 }
 
-void MCResourceInfo::finalize() {
-  assert(!finalized && "Cannot finalize ResourceInfo again.");
-  finalized = true;
-  assignMaxRegs();
+void MCResourceInfo::finalize(MCContext &OutContext) {
+  assert(!Finalized && "Cannot finalize ResourceInfo again.");
+  Finalized = true;
+  assignMaxRegs(OutContext);
 }
 
-MCSymbol *MCResourceInfo::getMaxVGPRSymbol() {
+MCSymbol *MCResourceInfo::getMaxVGPRSymbol(MCContext &OutContext) {
   return OutContext.getOrCreateSymbol("max_num_vgpr");
 }
 
-MCSymbol *MCResourceInfo::getMaxAGPRSymbol() {
+MCSymbol *MCResourceInfo::getMaxAGPRSymbol(MCContext &OutContext) {
   return OutContext.getOrCreateSymbol("max_num_agpr");
 }
 
-MCSymbol *MCResourceInfo::getMaxSGPRSymbol() {
+MCSymbol *MCResourceInfo::getMaxSGPRSymbol(MCContext &OutContext) {
   return OutContext.getOrCreateSymbol("max_num_sgpr");
 }
 
 void MCResourceInfo::assignResourceInfoExpr(
-int64_t localValue, ResourceInfoKind RIK, AMDGPUMCExpr::VariantKind Kind,
-const MachineFunction &MF,
-const SmallVectorImpl &Callees) {
-  const MCConstantExpr *localConstExpr =
-  MCConstantExpr::create(localValue, OutContext);
-  const MCExpr *SymVal = localConstExpr;
+int64_t LocalValue, ResourceInfoKind RIK, AMDGPUMCExpr::VariantKind Kind,
+const MachineFunction &MF, const SmallVectorImpl 
&Callees,
+MCContext &OutContext) {
+  const MCConstantExpr *LocalConstExpr =
+  MCConstantExpr::create(LocalValue, OutContext);
+  const MCExpr *SymVal = LocalConstExpr;

arsenm wrote:

No, we can know when an indirect call has a known possible range of callees. 
Whether from !callees metadata or from seeing the possible values of the call 
target 

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


[clang] [llvm] [RISCV] Add Hazard3 Core as taped out for RP2350 (PR #102452)

2024-08-20 Thread Sam Elliott via cfe-commits

https://github.com/lenary updated 
https://github.com/llvm/llvm-project/pull/102452

>From b125071eeb35ee4a76e126967b7c29d86a1fae56 Mon Sep 17 00:00:00 2001
From: Sam Elliott 
Date: Fri, 16 Aug 2024 07:52:53 -0700
Subject: [PATCH 1/2] [clang][test] Split invalid-cpu-note tests

This change does two kinds of splits:
- Splits each target into a different file. Some targets are left in the
  same files, such as riscv32/64 and x86/_64 as these tests and lists
  are very similar.
- Splits up the very long 'note:' lines which contain a list of CPUs,
  using `CHECK-SAME`. There was a note about this not being possible
  before, but with `--implicit-check-not`, this is now possible -- I
  have verified that this does the right thing if a single CPU anywhere
  in the list is left out.

These tests had become quite annoying to change when adding a CPU, and I
believe this change makes these easier to maintain, and should cut down
on conflicts in these files (or at least makes conflicts easier to
resolve).

I apologise in advance for downstream conflicts, but hopefully that's a
small amount of short term pain, in return for fewer conflicts in
future.
---
 clang/test/Misc/target-invalid-cpu-note.c |  96 -
 .../Misc/target-invalid-cpu-note/aarch64.c|  92 +
 .../Misc/target-invalid-cpu-note/amdgcn.c |  76 
 clang/test/Misc/target-invalid-cpu-note/arm.c | 100 +
 clang/test/Misc/target-invalid-cpu-note/avr.c | 322 +++
 clang/test/Misc/target-invalid-cpu-note/bpf.c |  15 +
 .../Misc/target-invalid-cpu-note/hexagon.c|  21 +
 .../test/Misc/target-invalid-cpu-note/lanai.c |   9 +
 .../test/Misc/target-invalid-cpu-note/mips.c  |  26 ++
 .../test/Misc/target-invalid-cpu-note/nvptx.c |  80 
 .../Misc/target-invalid-cpu-note/powerpc.c|  73 
 .../test/Misc/target-invalid-cpu-note/r600.c  |  34 ++
 .../test/Misc/target-invalid-cpu-note/riscv.c |  91 +
 .../test/Misc/target-invalid-cpu-note/sparc.c |  54 +++
 .../Misc/target-invalid-cpu-note/systemz.c|  22 +
 .../test/Misc/target-invalid-cpu-note/wasm.c  |  11 +
 clang/test/Misc/target-invalid-cpu-note/x86.c | 384 ++
 17 files changed, 1410 insertions(+), 96 deletions(-)
 delete mode 100644 clang/test/Misc/target-invalid-cpu-note.c
 create mode 100644 clang/test/Misc/target-invalid-cpu-note/aarch64.c
 create mode 100644 clang/test/Misc/target-invalid-cpu-note/amdgcn.c
 create mode 100644 clang/test/Misc/target-invalid-cpu-note/arm.c
 create mode 100644 clang/test/Misc/target-invalid-cpu-note/avr.c
 create mode 100644 clang/test/Misc/target-invalid-cpu-note/bpf.c
 create mode 100644 clang/test/Misc/target-invalid-cpu-note/hexagon.c
 create mode 100644 clang/test/Misc/target-invalid-cpu-note/lanai.c
 create mode 100644 clang/test/Misc/target-invalid-cpu-note/mips.c
 create mode 100644 clang/test/Misc/target-invalid-cpu-note/nvptx.c
 create mode 100644 clang/test/Misc/target-invalid-cpu-note/powerpc.c
 create mode 100644 clang/test/Misc/target-invalid-cpu-note/r600.c
 create mode 100644 clang/test/Misc/target-invalid-cpu-note/riscv.c
 create mode 100644 clang/test/Misc/target-invalid-cpu-note/sparc.c
 create mode 100644 clang/test/Misc/target-invalid-cpu-note/systemz.c
 create mode 100644 clang/test/Misc/target-invalid-cpu-note/wasm.c
 create mode 100644 clang/test/Misc/target-invalid-cpu-note/x86.c

diff --git a/clang/test/Misc/target-invalid-cpu-note.c 
b/clang/test/Misc/target-invalid-cpu-note.c
deleted file mode 100644
index b1783f3917a350..00
--- a/clang/test/Misc/target-invalid-cpu-note.c
+++ /dev/null
@@ -1,96 +0,0 @@
-// Use CHECK-NEXT instead of multiple CHECK-SAME to ensure we will fail if 
there is anything extra in the output.
-// RUN: not %clang_cc1 -triple armv5--- -target-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix ARM
-// ARM: error: unknown target CPU 'not-a-cpu'
-// ARM-NEXT: note: valid target CPU values are: arm8, arm810, strongarm, 
strongarm110, strongarm1100, strongarm1110, arm7tdmi, arm7tdmi-s, arm710t, 
arm720t, arm9, arm9tdmi, arm920, arm920t, arm922t, arm940t, ep9312, arm10tdmi, 
arm1020t, arm9e, arm946e-s, arm966e-s, arm968e-s, arm10e, arm1020e, arm1022e, 
arm926ej-s, arm1136j-s, arm1136jf-s, mpcore, mpcorenovfp, arm1176jz-s, 
arm1176jzf-s, arm1156t2-s, arm1156t2f-s, cortex-m0, cortex-m0plus, cortex-m1, 
sc000, cortex-a5, cortex-a7, cortex-a8, cortex-a9, cortex-a12, cortex-a15, 
cortex-a17, krait, cortex-r4, cortex-r4f, cortex-r5, cortex-r7, cortex-r8, 
cortex-r52, cortex-r52plus, sc300, cortex-m3, cortex-m4, cortex-m7, cortex-m23, 
cortex-m33, cortex-m35p, cortex-m55, cortex-m85, cortex-m52, cortex-a32, 
cortex-a35, cortex-a53, cortex-a55, cortex-a57, cortex-a72, cortex-a73, 
cortex-a75, cortex-a76, cortex-a76ae, cortex-a77, cortex-a78, cortex-a78ae, 
cortex-a78c, cortex-a710, cortex-x1, cortex-x1c, neoverse-n1, neoverse-n2, 
neoverse-v1, cyclone, exynos-m3, exynos-m4, exynos-m5, kryo, iwmmxt, xscale, 
swift{{$}}
-
-// RUN: not %clang_cc1 -trip

[clang] [llvm] [AMDGPU] Convert AMDGPUResourceUsageAnalysis pass from Module to MF pass (PR #102913)

2024-08-20 Thread Matt Arsenault via cfe-commits


@@ -2,12 +2,12 @@
 // RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -target-cpu gfx908 
-Rpass-analysis=kernel-resource-usage -S -O0 -verify %s -o /dev/null
 
 // expected-remark@+10 {{Function Name: foo}}
-// expected-remark@+9 {{SGPRs: 13}}
-// expected-remark@+8 {{VGPRs: 10}}
-// expected-remark@+7 {{AGPRs: 12}}
-// expected-remark@+6 {{ScratchSize [bytes/lane]: 0}}
+// expected-remark@+9 {{SGPRs: foo.num_sgpr+(extrasgprs(foo.uses_vcc, 
foo.uses_flat_scratch, 1))}}

arsenm wrote:

This is another case that should have trivially resolved and produced a usable 
answer 

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


[clang] [Clang][NFCI] Cleanup the fix for default function argument substitution (PR #104911)

2024-08-20 Thread via cfe-commits

cor3ntin wrote:

Can you keep the tests as is? Otherwise it's hard to trust this is really NFC.
I have some concerns over the number of booleans we are adding to these 
functions, did you consider an enum or a less easy to miss use interface?

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


[clang] Fix bug with -ffp-contract=fast-honor-pragmas (PR #104857)

2024-08-20 Thread Zahira Ammarguellat via cfe-commits

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

LGTM. Thanks.
I had to double check, but it looks like the LIT test 
`ffp-contract-fast-honor-pragma-option.cpp` has the same behavior with and 
without this patch. Right? Aren't there already tests that check the output of 
the option? 

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


[clang] [Clang] Add __builtin_is_within_lifetime to implement P2641R4's std::is_within_lifetime (PR #91895)

2024-08-20 Thread via cfe-commits


@@ -17310,3 +17332,83 @@ bool Expr::tryEvaluateStrLen(uint64_t &Result, 
ASTContext &Ctx) const {
   EvalInfo Info(Ctx, Status, EvalInfo::EM_ConstantFold);
   return EvaluateBuiltinStrLen(this, Result, Info);
 }
+
+namespace {
+struct IsWithinLifetimeHandler {
+  EvalInfo &Info;
+  static constexpr AccessKinds AccessKind = AccessKinds::AK_IsWithinLifetime;
+  using result_type = std::optional;
+  std::optional failed() { return std::nullopt; }
+  template 
+  std::optional found(T &Subobj, QualType SubobjType) {
+return true;
+  }
+};
+
+std::optional EvaluateBuiltinIsWithinLifetime(IntExprEvaluator &IEE,
+const CallExpr *E) {
+  EvalInfo &Info = IEE.Info;
+  // Sometimes this is called during some sorts of constant folding / early
+  // evaluation. These are meant for non-constant expressions and are not
+  // necessary since this consteval builtin will never be evaluated at runtime.
+  // Just fail to evaluate when not in a constant context.
+  if (!Info.InConstantContext)
+return std::nullopt;
+  assert(E->getBuiltinCallee() == Builtin::BI__builtin_is_within_lifetime);
+  const Expr *Arg = E->getArg(0);
+  if (Arg->isValueDependent())
+return std::nullopt;
+  LValue Val;
+  if (!EvaluatePointer(Arg, Val, Info))
+return std::nullopt;
+
+  auto Error = [&](int Diag) {
+bool CalledFromStd = false;
+const auto *Callee = Info.CurrentCall->getCallee();
+if (Callee && Callee->isInStdNamespace()) {
+  const IdentifierInfo *Identifier = Callee->getIdentifier();
+  CalledFromStd = Identifier && Identifier->isStr("is_within_lifetime");
+}
+Info.CCEDiag(CalledFromStd ? Info.CurrentCall->getCallRange().getBegin()
+   : E->getExprLoc(),
+ diag::err_invalid_is_within_lifetime)
+<< (CalledFromStd ? "std::is_within_lifetime"
+  : "__builtin_is_within_lifetime")
+<< Diag;
+return std::nullopt;
+  };
+  // C++2c [meta.const.eval]p4:
+  //   During the evaluation of an expression E as a core constant expression, 
a
+  //   call to this function is ill-formed unless p points to an object that is
+  //   usable in constant expressions or whose complete object's lifetime began
+  //   within E.
+
+  // Make sure it points to an object
+  // nullptr does not point to an object
+  if (Val.isNullPointer() || Val.getLValueBase().isNull())
+return Error(0);
+  QualType T = Val.getLValueBase().getType();
+  if (T->isFunctionType())
+return Error(1);

cor3ntin wrote:

I really want to see that be a sema check rather than a constant evaluation 
error (I am happy keeping the void* case for now as LWG is still talking about 
it)  

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


[clang] [llvm] [MC] Emit a jump table size section (PR #101962)

2024-08-20 Thread Nabeel Omer via cfe-commits

https://github.com/omern1 updated 
https://github.com/llvm/llvm-project/pull/101962

>From 14f3cb82f0d7e69261bd7e1317bd66392e9a2c2b Mon Sep 17 00:00:00 2001
From: Nabeel Omer 
Date: Mon, 5 Aug 2024 11:50:18 +0100
Subject: [PATCH 1/7] [MC] Emit a jump table size section

This patch will make LLVM emit a jump table size section containing
tuples of (jump table address, entry count) in object files.
This section is useful for tools that need to statically reconstruct
the control flow of executables.

The name of the new section is .debug_llvm_jump_table_sizes
because that makes both llvm-strip and GNU strip remove it.

At the moment this is only enabled by default for the PS5 target.
---
 clang/lib/Driver/ToolChains/PS4CPU.cpp|  8 ++
 clang/test/Driver/ps4-ps5-toolchain.c |  5 +
 llvm/docs/Extensions.rst  |  6 ++
 llvm/include/llvm/BinaryFormat/ELF.h  |  1 +
 llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp| 26 +
 llvm/lib/MC/MCParser/ELFAsmParser.cpp |  2 +
 llvm/lib/MC/MCSectionELF.cpp  |  2 +
 llvm/lib/Object/ELF.cpp   |  1 +
 .../CodeGen/X86/jump-table-size-section.ll| 97 +++
 9 files changed, 148 insertions(+)
 create mode 100644 llvm/test/CodeGen/X86/jump-table-size-section.ll

diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index a9e612c44da06a..f9a9e995fff8e2 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -265,6 +265,8 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
 CmdArgs.push_back(D.getLTOMode() == LTOK_Thin ? "--lto=thin"
   : "--lto=full");
 
+  AddLTOFlag("-emit-jump-table-sizes-section");
+
   if (UseJMC)
 AddLTOFlag("-enable-jmc-instrument");
 
@@ -483,6 +485,12 @@ void toolchains::PS4PS5Base::addClangTargetOptions(
 else
   CC1Args.push_back("-fvisibility-externs-nodllstorageclass=keep");
   }
+
+  // Enable jump table sizes section for PS5.
+  if (getTriple().isPS5()) {
+CC1Args.push_back("-mllvm");
+CC1Args.push_back("-emit-jump-table-sizes-section");
+  }
 }
 
 // PS4 toolchain.
diff --git a/clang/test/Driver/ps4-ps5-toolchain.c 
b/clang/test/Driver/ps4-ps5-toolchain.c
index 444e9df24714bd..c9987c2b5758b3 100644
--- a/clang/test/Driver/ps4-ps5-toolchain.c
+++ b/clang/test/Driver/ps4-ps5-toolchain.c
@@ -11,3 +11,8 @@
 // RUN: %clang %s -### -target x86_64-sie-ps5 -flto 2>&1 | FileCheck %s 
--check-prefix=LTO
 // LTO-NOT: error:
 // LTO-NOT: unable to pass LLVM bit-code
+
+// Verify that the jump table sizes section is enabled.
+// RUN: %clang %s -target x86_64-sie-ps5 -### 2>&1 | FileCheck 
-check-prefix=JUMPTABLESIZES %s
+// JUMPTABLESIZES: "-mllvm" "-emit-jump-table-sizes-section"
+// JUMPTABLESIZES: "-plugin-opt=-emit-jump-table-sizes-section"
diff --git a/llvm/docs/Extensions.rst b/llvm/docs/Extensions.rst
index 74ca8cb0aa6879..0e209f3fe5cc0d 100644
--- a/llvm/docs/Extensions.rst
+++ b/llvm/docs/Extensions.rst
@@ -554,6 +554,12 @@ time. This section is generated when the compiler enables 
fat LTO. This section
 has the ``SHF_EXCLUDE`` flag so that it is stripped from the final executable
 or shared library.
 
+``SHT_LLVM_JT_SIZES`` Section (Jump table addresses and sizes)
+^^^
+This section stores pairs of (jump table address, number of entries).
+This information is useful for tools that need to statically reconstruct
+the control flow of executables.
+
 CodeView-Dependent
 --
 
diff --git a/llvm/include/llvm/BinaryFormat/ELF.h 
b/llvm/include/llvm/BinaryFormat/ELF.h
index fb39bb4b10b377..7bec01688783d3 100644
--- a/llvm/include/llvm/BinaryFormat/ELF.h
+++ b/llvm/include/llvm/BinaryFormat/ELF.h
@@ -1121,6 +1121,7 @@ enum : unsigned {
   SHT_LLVM_BB_ADDR_MAP = 0x6fff4c0a,// LLVM Basic Block Address Map.
   SHT_LLVM_OFFLOADING = 0x6fff4c0b, // LLVM device offloading data.
   SHT_LLVM_LTO = 0x6fff4c0c,// .llvm.lto for fat LTO.
+  SHT_LLVM_JT_SIZES = 0x6fff4c0d,   // LLVM jump tables sizes.
   // Android's experimental support for SHT_RELR sections.
   // 
https://android.googlesource.com/platform/bionic/+/b7feec74547f84559a1467aca02708ff61346d2a/libc/include/elf.h#512
   SHT_ANDROID_RELR = 0x6f00,   // Relocation entries; only offsets.
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp 
b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index b64fe83959eb18..05624d2728bfdb 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -107,6 +107,7 @@
 #include "llvm/Pass.h"
 #include "llvm/Remarks/RemarkStreamer.h"
 #include "llvm/Support/Casting.h"
+#include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FileSystem.h"
@@ -155,6 +156,11 @@ static

  1   2   3   4   >