[clang] [clang][PowerPC] Add flag to enable compatibility with GNU for complex arguments (PR #77732)

2024-08-03 Thread Kishan Parmar via cfe-commits

Long5hot wrote:

ping!


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


[clang] [Clang] Adjust `exit()` builtin impl (PR #101689)

2024-08-03 Thread Dmitry Chestnykh via cfe-commits

chestnykh wrote:

> In #74803, the question of "why" came up and was never answered.

Okay, i can remove `let AddBuiltinPrefixedAlias = 1;`, but IMO that the rest of 
changes makes sense. What do you think? 

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


[clang] [libclang/python] Fix bug in `SourceRange.__contains__`, add tests (PR #101802)

2024-08-03 Thread Jannick Kremer via cfe-commits

https://github.com/DeinAlptraum created 
https://github.com/llvm/llvm-project/pull/101802

This resolves #22617 and #52827 

>From 444d9480cf9629c81ae26636922af20db5bd52bf Mon Sep 17 00:00:00 2001
From: Jannick Kremer 
Date: Sat, 3 Aug 2024 09:28:02 +0100
Subject: [PATCH] [libclang/python] Fix bug in SourceRange.__contains__, add
 tests

---
 clang/bindings/python/clang/cindex.py |  4 ++
 .../python/tests/cindex/test_source_range.py  | 56 +++
 2 files changed, 60 insertions(+)
 create mode 100644 clang/bindings/python/tests/cindex/test_source_range.py

diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index c251c46a04adf..5fd7cc6481073 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -386,6 +386,10 @@ def __contains__(self, other):
 # same file, in between lines
 if self.start.line < other.line < self.end.line:
 return True
+# between columns in one-liner range
+elif self.start.line == other.line == self.end.line:
+if self.start.column <= other.column <= self.end.column:
+return True
 elif self.start.line == other.line:
 # same file first line
 if self.start.column <= other.column:
diff --git a/clang/bindings/python/tests/cindex/test_source_range.py 
b/clang/bindings/python/tests/cindex/test_source_range.py
new file mode 100644
index 0..9f76848e89020
--- /dev/null
+++ b/clang/bindings/python/tests/cindex/test_source_range.py
@@ -0,0 +1,56 @@
+import unittest
+
+from clang.cindex import SourceLocation, SourceRange
+
+from .util import get_tu
+
+
+def create_location(tu, line, column):
+return SourceLocation.from_position(tu, tu.get_file(tu.spelling), line, 
column)
+
+
+def create_range(tu, line1, column1, line2, column2):
+return SourceRange.from_locations(
+create_location(tu, line1, column1), create_location(tu, line2, 
column2)
+)
+
+
+class TestSourceRange(unittest.TestCase):
+def test_contains(self):
+tu = get_tu(
+"""a
+a
+a
+a"""
+)
+
+l13 = create_location(tu, 1, 3)
+l21 = create_location(tu, 2, 1)
+l22 = create_location(tu, 2, 2)
+l23 = create_location(tu, 2, 3)
+l24 = create_location(tu, 2, 4)
+l25 = create_location(tu, 2, 5)
+l33 = create_location(tu, 3, 3)
+l31 = create_location(tu, 3, 1)
+r22_24 = create_range(tu, 2, 2, 2, 4)
+r23_23 = create_range(tu, 2, 3, 2, 3)
+r24_32 = create_range(tu, 2, 4, 3, 2)
+r14_32 = create_range(tu, 1, 4, 3, 2)
+
+assert l13 not in r22_24  # Line before start
+assert l21 not in r22_24  # Column before start
+assert l22 in r22_24  # Colum on start
+assert l23 in r22_24  # Column in range
+assert l24 in r22_24  # Column on end
+assert l25 not in r22_24  # Column after end
+assert l33 not in r22_24  # Line after end
+
+assert l23 in r23_23  # In one-column range
+
+assert l23 not in r24_32  # Outside range in first line
+assert l33 not in r24_32  # Outside range in last line
+assert l25 in r24_32  # In range in first line
+assert l31 in r24_32  # In range in last line
+
+assert l21 in r14_32  # In range at start of center line
+assert l25 in r14_32  # In range at end of center line

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


[clang] [libclang/python] Fix bug in `SourceRange.__contains__`, add tests (PR #101802)

2024-08-03 Thread Jannick Kremer via cfe-commits

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


[clang] [libclang/python] Fix bug in `SourceRange.__contains__`, add tests (PR #101802)

2024-08-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Jannick Kremer (DeinAlptraum)


Changes

Resolves #22617 
Resolves #52827 

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


2 Files Affected:

- (modified) clang/bindings/python/clang/cindex.py (+4) 
- (added) clang/bindings/python/tests/cindex/test_source_range.py (+56) 


``diff
diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index c251c46a04adf..5fd7cc6481073 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -386,6 +386,10 @@ def __contains__(self, other):
 # same file, in between lines
 if self.start.line < other.line < self.end.line:
 return True
+# between columns in one-liner range
+elif self.start.line == other.line == self.end.line:
+if self.start.column <= other.column <= self.end.column:
+return True
 elif self.start.line == other.line:
 # same file first line
 if self.start.column <= other.column:
diff --git a/clang/bindings/python/tests/cindex/test_source_range.py 
b/clang/bindings/python/tests/cindex/test_source_range.py
new file mode 100644
index 0..9f76848e89020
--- /dev/null
+++ b/clang/bindings/python/tests/cindex/test_source_range.py
@@ -0,0 +1,56 @@
+import unittest
+
+from clang.cindex import SourceLocation, SourceRange
+
+from .util import get_tu
+
+
+def create_location(tu, line, column):
+return SourceLocation.from_position(tu, tu.get_file(tu.spelling), line, 
column)
+
+
+def create_range(tu, line1, column1, line2, column2):
+return SourceRange.from_locations(
+create_location(tu, line1, column1), create_location(tu, line2, 
column2)
+)
+
+
+class TestSourceRange(unittest.TestCase):
+def test_contains(self):
+tu = get_tu(
+"""a
+a
+a
+a"""
+)
+
+l13 = create_location(tu, 1, 3)
+l21 = create_location(tu, 2, 1)
+l22 = create_location(tu, 2, 2)
+l23 = create_location(tu, 2, 3)
+l24 = create_location(tu, 2, 4)
+l25 = create_location(tu, 2, 5)
+l33 = create_location(tu, 3, 3)
+l31 = create_location(tu, 3, 1)
+r22_24 = create_range(tu, 2, 2, 2, 4)
+r23_23 = create_range(tu, 2, 3, 2, 3)
+r24_32 = create_range(tu, 2, 4, 3, 2)
+r14_32 = create_range(tu, 1, 4, 3, 2)
+
+assert l13 not in r22_24  # Line before start
+assert l21 not in r22_24  # Column before start
+assert l22 in r22_24  # Colum on start
+assert l23 in r22_24  # Column in range
+assert l24 in r22_24  # Column on end
+assert l25 not in r22_24  # Column after end
+assert l33 not in r22_24  # Line after end
+
+assert l23 in r23_23  # In one-column range
+
+assert l23 not in r24_32  # Outside range in first line
+assert l33 not in r24_32  # Outside range in last line
+assert l25 in r24_32  # In range in first line
+assert l31 in r24_32  # In range in last line
+
+assert l21 in r14_32  # In range at start of center line
+assert l25 in r14_32  # In range at end of center line

``




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


[clang] [clang][Interp] Fix array subscript eval order (PR #101804)

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

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

Always evaluate LHS first, then RHS.

>From b2295d98eb4c9b9810e4f380f4a768309765 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sat, 3 Aug 2024 11:31:38 +0200
Subject: [PATCH] [clang][Interp] Fix array subscript eval order

Always evaluate LHS first, then RHS.
---
 clang/lib/AST/Interp/Compiler.cpp| 24 +---
 clang/lib/AST/Interp/Interp.h| 15 +++
 clang/lib/AST/Interp/Opcodes.td  |  5 +
 clang/test/AST/Interp/eval-order.cpp |  9 -
 4 files changed, 41 insertions(+), 12 deletions(-)

diff --git a/clang/lib/AST/Interp/Compiler.cpp 
b/clang/lib/AST/Interp/Compiler.cpp
index f600d9b5b80f8..e1fa0eb1eacb3 100644
--- a/clang/lib/AST/Interp/Compiler.cpp
+++ b/clang/lib/AST/Interp/Compiler.cpp
@@ -1282,21 +1282,31 @@ bool Compiler::VisitImplicitValueInitExpr(
 
 template 
 bool Compiler::VisitArraySubscriptExpr(const ArraySubscriptExpr *E) {
-  const Expr *Base = E->getBase();
+  const Expr *LHS = E->getLHS();
+  const Expr *RHS = E->getRHS();
   const Expr *Index = E->getIdx();
 
   if (DiscardResult)
-return this->discard(Base) && this->discard(Index);
+return this->discard(LHS) && this->discard(RHS);
 
-  // Take pointer of LHS, add offset from RHS.
-  // What's left on the stack after this is a pointer.
-  if (!this->visit(Base))
-return false;
+  // C++17's rules require us to evaluate the LHS first, regardless of which
+  // side is the base.
+  bool Success = true;
+  for (const Expr *SubExpr : {LHS, RHS}) {
+if (!this->visit(SubExpr))
+  Success = false;
+  }
 
-  if (!this->visit(Index))
+  if (!Success)
 return false;
 
   PrimType IndexT = classifyPrim(Index->getType());
+  // If the index is first, we need to change that.
+  if (LHS == Index) {
+if (!this->emitFlip(PT_Ptr, IndexT, E))
+  return false;
+  }
+
   return this->emitArrayElemPtrPop(IndexT, E);
 }
 
diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index b54635b9988e2..a3f81e2de466b 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -1158,6 +1158,21 @@ bool Pop(InterpState &S, CodePtr OpPC) {
   return true;
 }
 
+/// [Value1, Value2] -> [Value2, Value1]
+template 
+bool Flip(InterpState &S, CodePtr OpPC) {
+  using TopT = typename PrimConv::T;
+  using BottomT = typename PrimConv::T;
+
+  const auto &Top = S.Stk.pop();
+  const auto &Bottom = S.Stk.pop();
+
+  S.Stk.push(Top);
+  S.Stk.push(Bottom);
+
+  return true;
+}
+
 
//===--===//
 // Const
 
//===--===//
diff --git a/clang/lib/AST/Interp/Opcodes.td b/clang/lib/AST/Interp/Opcodes.td
index 3e830f89754dc..70d06bdfdc21c 100644
--- a/clang/lib/AST/Interp/Opcodes.td
+++ b/clang/lib/AST/Interp/Opcodes.td
@@ -729,6 +729,11 @@ def Dup : Opcode {
   let HasGroup = 1;
 }
 
+def Flip : Opcode {
+  let Types = [AllTypeClass, AllTypeClass];
+  let HasGroup = 1;
+}
+
 // [] -> []
 def Invalid : Opcode {}
 def Unsupported : Opcode {}
diff --git a/clang/test/AST/Interp/eval-order.cpp 
b/clang/test/AST/Interp/eval-order.cpp
index 7a7ce6a714601..77f50831f4f47 100644
--- a/clang/test/AST/Interp/eval-order.cpp
+++ b/clang/test/AST/Interp/eval-order.cpp
@@ -45,7 +45,7 @@ namespace EvalOrder {
 }
 template  constexpr T &&b(T &&v) {
   if (!done_a)
-throw "wrong"; // expected-note 7{{not valid}}
+throw "wrong"; // expected-note 5{{not valid}}
   done_b = true;
   return (T &&)v;
 }
@@ -95,10 +95,9 @@ namespace EvalOrder {
   constexpr int arr[3] = {};
   SEQ(A(arr)[B(0)]);
   SEQ(A(+arr)[B(0)]);
-  SEQ(A(0)[B(arr)]); // expected-error {{not an integral constant expression}} 
FIXME \
- // expected-note 2{{in call to}}
-  SEQ(A(0)[B(+arr)]); // expected-error {{not an integral constant 
expression}} FIXME \
-  // expected-note 2{{in call to}}
+  SEQ(A(0)[B(arr)]);
+  SEQ(A(0)[B(+arr)]);
+
   SEQ(A(ud)[B(0)]);
 
   // Rule 7: a << b

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


[clang] [clang][Interp] Fix array subscript eval order (PR #101804)

2024-08-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

Always evaluate LHS first, then RHS.

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


4 Files Affected:

- (modified) clang/lib/AST/Interp/Compiler.cpp (+17-7) 
- (modified) clang/lib/AST/Interp/Interp.h (+15) 
- (modified) clang/lib/AST/Interp/Opcodes.td (+5) 
- (modified) clang/test/AST/Interp/eval-order.cpp (+4-5) 


``diff
diff --git a/clang/lib/AST/Interp/Compiler.cpp 
b/clang/lib/AST/Interp/Compiler.cpp
index f600d9b5b80f8..e1fa0eb1eacb3 100644
--- a/clang/lib/AST/Interp/Compiler.cpp
+++ b/clang/lib/AST/Interp/Compiler.cpp
@@ -1282,21 +1282,31 @@ bool Compiler::VisitImplicitValueInitExpr(
 
 template 
 bool Compiler::VisitArraySubscriptExpr(const ArraySubscriptExpr *E) {
-  const Expr *Base = E->getBase();
+  const Expr *LHS = E->getLHS();
+  const Expr *RHS = E->getRHS();
   const Expr *Index = E->getIdx();
 
   if (DiscardResult)
-return this->discard(Base) && this->discard(Index);
+return this->discard(LHS) && this->discard(RHS);
 
-  // Take pointer of LHS, add offset from RHS.
-  // What's left on the stack after this is a pointer.
-  if (!this->visit(Base))
-return false;
+  // C++17's rules require us to evaluate the LHS first, regardless of which
+  // side is the base.
+  bool Success = true;
+  for (const Expr *SubExpr : {LHS, RHS}) {
+if (!this->visit(SubExpr))
+  Success = false;
+  }
 
-  if (!this->visit(Index))
+  if (!Success)
 return false;
 
   PrimType IndexT = classifyPrim(Index->getType());
+  // If the index is first, we need to change that.
+  if (LHS == Index) {
+if (!this->emitFlip(PT_Ptr, IndexT, E))
+  return false;
+  }
+
   return this->emitArrayElemPtrPop(IndexT, E);
 }
 
diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index b54635b9988e2..a3f81e2de466b 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -1158,6 +1158,21 @@ bool Pop(InterpState &S, CodePtr OpPC) {
   return true;
 }
 
+/// [Value1, Value2] -> [Value2, Value1]
+template 
+bool Flip(InterpState &S, CodePtr OpPC) {
+  using TopT = typename PrimConv::T;
+  using BottomT = typename PrimConv::T;
+
+  const auto &Top = S.Stk.pop();
+  const auto &Bottom = S.Stk.pop();
+
+  S.Stk.push(Top);
+  S.Stk.push(Bottom);
+
+  return true;
+}
+
 
//===--===//
 // Const
 
//===--===//
diff --git a/clang/lib/AST/Interp/Opcodes.td b/clang/lib/AST/Interp/Opcodes.td
index 3e830f89754dc..70d06bdfdc21c 100644
--- a/clang/lib/AST/Interp/Opcodes.td
+++ b/clang/lib/AST/Interp/Opcodes.td
@@ -729,6 +729,11 @@ def Dup : Opcode {
   let HasGroup = 1;
 }
 
+def Flip : Opcode {
+  let Types = [AllTypeClass, AllTypeClass];
+  let HasGroup = 1;
+}
+
 // [] -> []
 def Invalid : Opcode {}
 def Unsupported : Opcode {}
diff --git a/clang/test/AST/Interp/eval-order.cpp 
b/clang/test/AST/Interp/eval-order.cpp
index 7a7ce6a714601..77f50831f4f47 100644
--- a/clang/test/AST/Interp/eval-order.cpp
+++ b/clang/test/AST/Interp/eval-order.cpp
@@ -45,7 +45,7 @@ namespace EvalOrder {
 }
 template  constexpr T &&b(T &&v) {
   if (!done_a)
-throw "wrong"; // expected-note 7{{not valid}}
+throw "wrong"; // expected-note 5{{not valid}}
   done_b = true;
   return (T &&)v;
 }
@@ -95,10 +95,9 @@ namespace EvalOrder {
   constexpr int arr[3] = {};
   SEQ(A(arr)[B(0)]);
   SEQ(A(+arr)[B(0)]);
-  SEQ(A(0)[B(arr)]); // expected-error {{not an integral constant expression}} 
FIXME \
- // expected-note 2{{in call to}}
-  SEQ(A(0)[B(+arr)]); // expected-error {{not an integral constant 
expression}} FIXME \
-  // expected-note 2{{in call to}}
+  SEQ(A(0)[B(arr)]);
+  SEQ(A(0)[B(+arr)]);
+
   SEQ(A(ud)[B(0)]);
 
   // Rule 7: a << b

``




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


[clang] [clang] Implement `__builtin_is_implicit_lifetime()` (PR #101807)

2024-08-03 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll created 
https://github.com/llvm/llvm-project/pull/101807

This intrinsic supports [P2647R1](https://wg21.link/p2674r1) "A trait for 
implicit lifetime types".

>From 9c4e7ccf47d5ede2b6169effb2a09668f512a182 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Sat, 3 Aug 2024 13:05:21 +0300
Subject: [PATCH] [clang] Implement `__builtin_is_implicit_lifetime()`

This intrinsic supports [P2647R1](https://wg21.link/p2674r1) "A trait for 
implicit lifetime types".
---
 clang/docs/LanguageExtensions.rst|  1 +
 clang/docs/ReleaseNotes.rst  |  3 +
 clang/include/clang/Basic/TokenKinds.def |  1 +
 clang/lib/Sema/SemaExprCXX.cpp   | 22 +++
 clang/test/SemaCXX/type-traits.cpp   | 81 +++-
 5 files changed, 107 insertions(+), 1 deletion(-)

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index a747464582e77..f04e6b0057b51 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1546,6 +1546,7 @@ The following type trait primitives are supported by 
Clang. Those traits marked
 * ``__array_extent(type, dim)`` (Embarcadero):
   The ``dim``'th array bound in the type ``type``, or ``0`` if
   ``dim >= __array_rank(type)``.
+* ``__builtin_is_implicit_lifetime`` (C++, GNU, Microsoft)
 * ``__builtin_is_virtual_base_of`` (C++, GNU, Microsoft)
 * ``__can_pass_in_regs`` (C++)
   Returns whether a class can be passed in registers under the current
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 25f5bd37bbe94..6854a321e1720 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -86,6 +86,9 @@ C++23 Feature Support
 C++2c Feature Support
 ^
 
+- Add ``__builtin_is_implicit_lifetime`` intrinsic, which supports
+  `P2647R1 A trait for implicit lifetime types `_
+
 - Add ``__builtin_is_virtual_base_of`` intrinsic, which supports
   `P2985R0 A type trait for detecting virtual base classes 
`_
 
diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 7e638dc1ddcdb..7505c5a1a1f27 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -501,6 +501,7 @@ TYPE_TRAIT_1(__has_trivial_move_assign, 
HasTrivialMoveAssign, KEYCXX)
 TYPE_TRAIT_1(__has_trivial_move_constructor, HasTrivialMoveConstructor, KEYCXX)
 
 // GNU and MS Type Traits
+TYPE_TRAIT_1(__builtin_is_implicit_lifetime, IsImplicitLifetime, KEYCXX)
 TYPE_TRAIT_2(__builtin_is_virtual_base_of, IsVirtualBaseOf, KEYCXX)
 TYPE_TRAIT_1(__has_nothrow_assign, HasNothrowAssign, KEYCXX)
 TYPE_TRAIT_1(__has_nothrow_copy, HasNothrowCopy, KEYCXX)
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index c5003d9ac0254..504dc93316db5 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -5039,6 +5039,7 @@ static bool CheckUnaryTypeTraitTypeCompleteness(Sema &S, 
TypeTrait UTT,
 
   // LWG3823: T shall be an array type, a complete type, or cv void.
   case UTT_IsAggregate:
+  case UTT_IsImplicitLifetime:
 if (ArgTy->isArrayType() || ArgTy->isVoidType())
   return true;
 
@@ -5637,6 +5638,27 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, TypeTrait 
UTT,
 return false;
   case UTT_IsTriviallyEqualityComparable:
 return isTriviallyEqualityComparableType(Self, T, KeyLoc);
+  case UTT_IsImplicitLifetime: {
+DiagnoseVLAInCXXTypeTrait(Self, TInfo,
+  tok::kw___builtin_is_implicit_lifetime);
+QualType UnqualT = T->getCanonicalTypeUnqualified();
+if (UnqualT->isScalarType())
+  return true;
+if (UnqualT->isArrayType())
+  return true;
+
+CXXRecordDecl *RD = UnqualT->getAsCXXRecordDecl();
+if (!RD)
+  return false;
+if (UnqualT->isAggregateType())
+  if (!RD->getDestructor()->isUserProvided())
+return true;
+if (RD->hasTrivialDestructor())
+  if (RD->hasTrivialDefaultConstructor() ||
+  RD->hasTrivialCopyConstructor() || RD->hasTrivialMoveConstructor())
+return true;
+return false;
+  }
   }
 }
 
diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index 4acb3d6c9eebe..11041414c1bba 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -18,7 +18,7 @@ enum class SignedEnumClass : signed int {};
 enum class UnsignedEnumClass : unsigned int {};
 struct POD { Enum e; int i; float f; NonPOD* p; };
 struct Empty {};
-struct IncompleteStruct;
+struct IncompleteStruct; // expected-note {{forward declaration of 
'IncompleteStruct'}}
 typedef Empty EmptyAr[10];
 typedef Empty EmptyArNB[];
 typedef Empty EmptyArMB[1][2];
@@ -1944,6 +1944,85 @@ void is_pointer_interconvertible_base_of(int n)
 }
 }
 
+struct NoEligibleTrivialContructor {
+  NoEligibleTrivialContructor() {};
+  NoEligibleTrivialContructo

[clang] [clang] Implement `__builtin_is_implicit_lifetime()` (PR #101807)

2024-08-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Vlad Serebrennikov (Endilll)


Changes

This intrinsic supports [P2647R1](https://wg21.link/p2674r1) "A trait for 
implicit lifetime types".

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


5 Files Affected:

- (modified) clang/docs/LanguageExtensions.rst (+1) 
- (modified) clang/docs/ReleaseNotes.rst (+3) 
- (modified) clang/include/clang/Basic/TokenKinds.def (+1) 
- (modified) clang/lib/Sema/SemaExprCXX.cpp (+22) 
- (modified) clang/test/SemaCXX/type-traits.cpp (+80-1) 


``diff
diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index a747464582e77..f04e6b0057b51 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1546,6 +1546,7 @@ The following type trait primitives are supported by 
Clang. Those traits marked
 * ``__array_extent(type, dim)`` (Embarcadero):
   The ``dim``'th array bound in the type ``type``, or ``0`` if
   ``dim >= __array_rank(type)``.
+* ``__builtin_is_implicit_lifetime`` (C++, GNU, Microsoft)
 * ``__builtin_is_virtual_base_of`` (C++, GNU, Microsoft)
 * ``__can_pass_in_regs`` (C++)
   Returns whether a class can be passed in registers under the current
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 25f5bd37bbe94..6854a321e1720 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -86,6 +86,9 @@ C++23 Feature Support
 C++2c Feature Support
 ^
 
+- Add ``__builtin_is_implicit_lifetime`` intrinsic, which supports
+  `P2647R1 A trait for implicit lifetime types `_
+
 - Add ``__builtin_is_virtual_base_of`` intrinsic, which supports
   `P2985R0 A type trait for detecting virtual base classes 
`_
 
diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 7e638dc1ddcdb..7505c5a1a1f27 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -501,6 +501,7 @@ TYPE_TRAIT_1(__has_trivial_move_assign, 
HasTrivialMoveAssign, KEYCXX)
 TYPE_TRAIT_1(__has_trivial_move_constructor, HasTrivialMoveConstructor, KEYCXX)
 
 // GNU and MS Type Traits
+TYPE_TRAIT_1(__builtin_is_implicit_lifetime, IsImplicitLifetime, KEYCXX)
 TYPE_TRAIT_2(__builtin_is_virtual_base_of, IsVirtualBaseOf, KEYCXX)
 TYPE_TRAIT_1(__has_nothrow_assign, HasNothrowAssign, KEYCXX)
 TYPE_TRAIT_1(__has_nothrow_copy, HasNothrowCopy, KEYCXX)
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index c5003d9ac0254..504dc93316db5 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -5039,6 +5039,7 @@ static bool CheckUnaryTypeTraitTypeCompleteness(Sema &S, 
TypeTrait UTT,
 
   // LWG3823: T shall be an array type, a complete type, or cv void.
   case UTT_IsAggregate:
+  case UTT_IsImplicitLifetime:
 if (ArgTy->isArrayType() || ArgTy->isVoidType())
   return true;
 
@@ -5637,6 +5638,27 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, TypeTrait 
UTT,
 return false;
   case UTT_IsTriviallyEqualityComparable:
 return isTriviallyEqualityComparableType(Self, T, KeyLoc);
+  case UTT_IsImplicitLifetime: {
+DiagnoseVLAInCXXTypeTrait(Self, TInfo,
+  tok::kw___builtin_is_implicit_lifetime);
+QualType UnqualT = T->getCanonicalTypeUnqualified();
+if (UnqualT->isScalarType())
+  return true;
+if (UnqualT->isArrayType())
+  return true;
+
+CXXRecordDecl *RD = UnqualT->getAsCXXRecordDecl();
+if (!RD)
+  return false;
+if (UnqualT->isAggregateType())
+  if (!RD->getDestructor()->isUserProvided())
+return true;
+if (RD->hasTrivialDestructor())
+  if (RD->hasTrivialDefaultConstructor() ||
+  RD->hasTrivialCopyConstructor() || RD->hasTrivialMoveConstructor())
+return true;
+return false;
+  }
   }
 }
 
diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index 4acb3d6c9eebe..11041414c1bba 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -18,7 +18,7 @@ enum class SignedEnumClass : signed int {};
 enum class UnsignedEnumClass : unsigned int {};
 struct POD { Enum e; int i; float f; NonPOD* p; };
 struct Empty {};
-struct IncompleteStruct;
+struct IncompleteStruct; // expected-note {{forward declaration of 
'IncompleteStruct'}}
 typedef Empty EmptyAr[10];
 typedef Empty EmptyArNB[];
 typedef Empty EmptyArMB[1][2];
@@ -1944,6 +1944,85 @@ void is_pointer_interconvertible_base_of(int n)
 }
 }
 
+struct NoEligibleTrivialContructor {
+  NoEligibleTrivialContructor() {};
+  NoEligibleTrivialContructor(const NoEligibleTrivialContructor&) {}
+  NoEligibleTrivialContructor(NoEligibleTrivialContructor&&) {}
+};
+
+struct OnlyDefaultConstructorIsTrivial {
+  OnlyDefaultConstructorIsTrivial() = default;
+  OnlyDefaultConstructorIsTrivial(const OnlyDefaul

[clang] 0dcada9 - [clang][Interp] Fix array subscript eval order (#101804)

2024-08-03 Thread via cfe-commits

Author: Timm Baeder
Date: 2024-08-03T12:25:20+02:00
New Revision: 0dcada94bb1ae79f0edd91013038098c62a96b3b

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

LOG: [clang][Interp] Fix array subscript eval order (#101804)

Always evaluate LHS first, then RHS.

Added: 


Modified: 
clang/lib/AST/Interp/Compiler.cpp
clang/lib/AST/Interp/Interp.h
clang/lib/AST/Interp/Opcodes.td
clang/test/AST/Interp/eval-order.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Compiler.cpp 
b/clang/lib/AST/Interp/Compiler.cpp
index f600d9b5b80f8..e1fa0eb1eacb3 100644
--- a/clang/lib/AST/Interp/Compiler.cpp
+++ b/clang/lib/AST/Interp/Compiler.cpp
@@ -1282,21 +1282,31 @@ bool Compiler::VisitImplicitValueInitExpr(
 
 template 
 bool Compiler::VisitArraySubscriptExpr(const ArraySubscriptExpr *E) {
-  const Expr *Base = E->getBase();
+  const Expr *LHS = E->getLHS();
+  const Expr *RHS = E->getRHS();
   const Expr *Index = E->getIdx();
 
   if (DiscardResult)
-return this->discard(Base) && this->discard(Index);
+return this->discard(LHS) && this->discard(RHS);
 
-  // Take pointer of LHS, add offset from RHS.
-  // What's left on the stack after this is a pointer.
-  if (!this->visit(Base))
-return false;
+  // C++17's rules require us to evaluate the LHS first, regardless of which
+  // side is the base.
+  bool Success = true;
+  for (const Expr *SubExpr : {LHS, RHS}) {
+if (!this->visit(SubExpr))
+  Success = false;
+  }
 
-  if (!this->visit(Index))
+  if (!Success)
 return false;
 
   PrimType IndexT = classifyPrim(Index->getType());
+  // If the index is first, we need to change that.
+  if (LHS == Index) {
+if (!this->emitFlip(PT_Ptr, IndexT, E))
+  return false;
+  }
+
   return this->emitArrayElemPtrPop(IndexT, E);
 }
 

diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index b54635b9988e2..a3f81e2de466b 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -1158,6 +1158,21 @@ bool Pop(InterpState &S, CodePtr OpPC) {
   return true;
 }
 
+/// [Value1, Value2] -> [Value2, Value1]
+template 
+bool Flip(InterpState &S, CodePtr OpPC) {
+  using TopT = typename PrimConv::T;
+  using BottomT = typename PrimConv::T;
+
+  const auto &Top = S.Stk.pop();
+  const auto &Bottom = S.Stk.pop();
+
+  S.Stk.push(Top);
+  S.Stk.push(Bottom);
+
+  return true;
+}
+
 
//===--===//
 // Const
 
//===--===//

diff  --git a/clang/lib/AST/Interp/Opcodes.td b/clang/lib/AST/Interp/Opcodes.td
index 3e830f89754dc..70d06bdfdc21c 100644
--- a/clang/lib/AST/Interp/Opcodes.td
+++ b/clang/lib/AST/Interp/Opcodes.td
@@ -729,6 +729,11 @@ def Dup : Opcode {
   let HasGroup = 1;
 }
 
+def Flip : Opcode {
+  let Types = [AllTypeClass, AllTypeClass];
+  let HasGroup = 1;
+}
+
 // [] -> []
 def Invalid : Opcode {}
 def Unsupported : Opcode {}

diff  --git a/clang/test/AST/Interp/eval-order.cpp 
b/clang/test/AST/Interp/eval-order.cpp
index 7a7ce6a714601..77f50831f4f47 100644
--- a/clang/test/AST/Interp/eval-order.cpp
+++ b/clang/test/AST/Interp/eval-order.cpp
@@ -45,7 +45,7 @@ namespace EvalOrder {
 }
 template  constexpr T &&b(T &&v) {
   if (!done_a)
-throw "wrong"; // expected-note 7{{not valid}}
+throw "wrong"; // expected-note 5{{not valid}}
   done_b = true;
   return (T &&)v;
 }
@@ -95,10 +95,9 @@ namespace EvalOrder {
   constexpr int arr[3] = {};
   SEQ(A(arr)[B(0)]);
   SEQ(A(+arr)[B(0)]);
-  SEQ(A(0)[B(arr)]); // expected-error {{not an integral constant expression}} 
FIXME \
- // expected-note 2{{in call to}}
-  SEQ(A(0)[B(+arr)]); // expected-error {{not an integral constant 
expression}} FIXME \
-  // expected-note 2{{in call to}}
+  SEQ(A(0)[B(arr)]);
+  SEQ(A(0)[B(+arr)]);
+
   SEQ(A(ud)[B(0)]);
 
   // Rule 7: a << b



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


[clang] [clang][Interp] Fix array subscript eval order (PR #101804)

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

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


[clang] [RISCV][sema] Correct the requirement of `vf[|n|w]cvt.f.*` intrinsics (PR #101608)

2024-08-03 Thread Brandon Wu via cfe-commits

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


[clang] [RISCV][sema] Correct the requirement of `vf[|n|w]cvt.f.*` intrinsics (PR #101608)

2024-08-03 Thread Brandon Wu via cfe-commits

4vtomat wrote:

This has been resolved by: https://github.com/llvm/llvm-project/pull/101733

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


[clang] [libclang/python] Fix bug in `SourceRange.__contains__`, add tests (PR #101802)

2024-08-03 Thread Vlad Serebrennikov via cfe-commits


@@ -386,6 +386,10 @@ def __contains__(self, other):
 # same file, in between lines
 if self.start.line < other.line < self.end.line:
 return True
+# between columns in one-liner range
+elif self.start.line == other.line == self.end.line:

Endilll wrote:

How about we follow the `SourceRange::fullyContains`? In other words, expose 
`SourceLocation::operator<` to enable ordering of source locations, and 
leverage that in `SourceRange.__contains__`. I expect the latter to become much 
simpler.

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


[clang] [clang] Implement `__builtin_is_implicit_lifetime()` (PR #101807)

2024-08-03 Thread Vlad Serebrennikov via cfe-commits

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


[clang] [clang] Implement `__builtin_is_implicit_lifetime()` (PR #101807)

2024-08-03 Thread Vlad Serebrennikov via cfe-commits

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


[clang] [clang][Interp] Fix array subscript eval order (PR #101804)

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

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `sanitizer-windows` running 
on `sanitizer-windows` while building `clang` at step 4 "annotate".

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

Here is the relevant piece of the build log for the reference:
```
Step 4 (annotate) failure: 'python 
../llvm-zorg/zorg/buildbot/builders/annotated/sanitizer-windows.py ...' 
(failure)
...
[14/26] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\Context.cpp.obj
[15/26] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\InterpBuiltin.cpp.obj
[16/26] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\Compiler.cpp.obj
[17/26] Building CXX object 
lib\CodeGen\AsmPrinter\CMakeFiles\LLVMAsmPrinter.dir\AsmPrinter.cpp.obj
[18/26] Linking CXX static library lib\LLVMAsmPrinter.lib
[19/26] Building CXX object lib\LTO\CMakeFiles\LLVMLTO.dir\LTO.cpp.obj
[20/26] Linking CXX static library lib\LLVMLTO.lib
[21/26] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\EvalEmitter.cpp.obj
[22/26] Linking CXX executable bin\lld.exe
[23/26] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\Disasm.cpp.obj
command timed out: 1200 seconds without output running ['python', 
'../llvm-zorg/zorg/buildbot/builders/annotated/sanitizer-windows.py', 
'--jobs=16'], attempting to kill
program finished with exit code 1
elapsedTime=1268.363000
Step 7 (stage 1 build) failure: stage 1 build (failure)
@@@BUILD_STEP stage 1 build@@@
Running: ninja -j 16 compiler-rt
[1/2] Building CXX object 
projects\compiler-rt\lib\asan\CMakeFiles\RTAsan_dynamic_version_script_dummy.x86_64.dir\dummy.cpp.obj
[2/2] Linking CXX shared library 
lib\clang\20\lib\windows\clang_rt.asan_dynamic-x86_64.dll
Running: ninja -j 16 clang lld
[1/26] Building Opcodes.inc...
[2/26] Generating VCSRevision.h
[3/26] Generating VCSVersion.inc
[4/26] Building CXX object 
tools\clang\lib\Basic\CMakeFiles\obj.clangBasic.dir\Version.cpp.obj
[5/26] Building CXX object lib\Object\CMakeFiles\LLVMObject.dir\IRSymtab.cpp.obj
[6/26] Linking CXX static library lib\LLVMObject.lib
[7/26] Generating VCSVersion.inc
[8/26] Linking CXX static library lib\clangBasic.lib
[9/26] Building CXX object 
tools\lld\Common\CMakeFiles\lldCommon.dir\Version.cpp.obj
[10/26] Linking CXX static library lib\lldCommon.lib
[11/26] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\Function.cpp.obj
[12/26] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\Program.cpp.obj
[13/26] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\ByteCodeEmitter.cpp.obj
[14/26] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\Context.cpp.obj
[15/26] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\InterpBuiltin.cpp.obj
[16/26] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\Compiler.cpp.obj
[17/26] Building CXX object 
lib\CodeGen\AsmPrinter\CMakeFiles\LLVMAsmPrinter.dir\AsmPrinter.cpp.obj
[18/26] Linking CXX static library lib\LLVMAsmPrinter.lib
[19/26] Building CXX object lib\LTO\CMakeFiles\LLVMLTO.dir\LTO.cpp.obj
[20/26] Linking CXX static library lib\LLVMLTO.lib
[21/26] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\EvalEmitter.cpp.obj
[22/26] Linking CXX executable bin\lld.exe
[23/26] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\Disasm.cpp.obj

command timed out: 1200 seconds without output running ['python', 
'../llvm-zorg/zorg/buildbot/builders/annotated/sanitizer-windows.py', 
'--jobs=16'], attempting to kill
program finished with exit code 1
elapsedTime=1268.363000

```

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


[clang] [clang][Interp] Fix array subscript eval order (PR #101804)

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

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `clang-aarch64-sve-vls` 
running on `linaro-g3-02` while building `clang` at step 13 "test-suite".

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

Here is the relevant piece of the build log for the reference:
```
Step 13 (test-suite) failure: test (failure)
 TEST 'test-suite :: 
Fortran/gfortran/regression/gfortran-regression-execute-regression__random_init_2_f90.test'
 FAILED 

/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/test/sandbox/build/tools/timeit-target
 --timeout 7200 --limit-core 0 --limit-cpu 7200 --limit-file-size 209715200 
--limit-rss-size 838860800 --redirect-input /dev/null --chdir 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/test/sandbox/build/Fortran/gfortran/regression/gfortran-regression-execute-regression__random_init_2_f90.wd
 --summary 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/test/sandbox/build/Fortran/gfortran/regression/Output/gfortran-regression-execute-regression__random_init_2_f90.test.time
 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/test/sandbox/build/Fortran/gfortran/regression/gfortran-regression-execute-regression__random_init_2_f90

+ 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/test/sandbox/build/tools/timeit-target
 --timeout 7200 --limit-core 0 --limit-cpu 7200 --limit-file-size 209715200 
--limit-rss-size 838860800 --redirect-input /dev/null --chdir 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/test/sandbox/build/Fortran/gfortran/regression/gfortran-regression-execute-regression__random_init_2_f90.wd
 --summary 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/test/sandbox/build/Fortran/gfortran/regression/Output/gfortran-regression-execute-regression__random_init_2_f90.test.time
 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/test/sandbox/build/Fortran/gfortran/regression/gfortran-regression-execute-regression__random_init_2_f90
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/test/sandbox/build/tools/timeit-target:
 error: child terminated by signal 6




```

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


[clang] Retrieve BinaryOperator::getOpcode and BinaryOperator::getOpcodeStr via libclang and its python interface (PR #98489)

2024-08-03 Thread Jannick Kremer via cfe-commits


@@ -54,6 +54,8 @@ LLVM_13 {
 clang_Cursor_Evaluate;
 clang_Cursor_getArgument;
 clang_Cursor_getBriefCommentText;
+clang_Cursor_getBinaryOpcode;
+clang_Cursor_getBinaryOpcodeStr;

DeinAlptraum wrote:

This is the `LLVM_13` section of the file.
>From the top of the file:
```
# If you add a symbol to this file, make sure to add it with the correct
# version.  For example, if the LLVM main branch is LLVM 14.0.0, add new
# symbols with the version LLVM_14.
# On platforms where versions scripts are not used, this file will be used to
# generate a list of exports for libclang.so
```
I'm not familiar with how the bindings actually interact with the C++ side, so 
I don't know what kinds of problems this would cause. Does this need to be 
backported for 19.x?
@Endilll are you familiar with this?

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


[clang] Retrieve BinaryOperator::getOpcode and BinaryOperator::getOpcodeStr via libclang and its python interface (PR #98489)

2024-08-03 Thread Jannick Kremer via cfe-commits

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


[clang] Retrieve BinaryOperator::getOpcode and BinaryOperator::getOpcodeStr via libclang and its python interface (PR #98489)

2024-08-03 Thread Jannick Kremer via cfe-commits

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


[clang] Retrieve BinaryOperator::getOpcode and BinaryOperator::getOpcodeStr via libclang and its python interface (PR #98489)

2024-08-03 Thread Thomas Wucher via cfe-commits


@@ -54,6 +54,8 @@ LLVM_13 {
 clang_Cursor_Evaluate;
 clang_Cursor_getArgument;
 clang_Cursor_getBriefCommentText;
+clang_Cursor_getBinaryOpcode;
+clang_Cursor_getBinaryOpcodeStr;

thomaswucher wrote:

I must have missed this when rebasing the patch, sorry. If it needs to be fixed 
I can of course provide a follow up pull request next week.

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


[clang] [RISCV][sema] Correct the requirement of `vf[n|w]cvt.x[|u].f` intrinsics (PR #101811)

2024-08-03 Thread Brandon Wu via cfe-commits

https://github.com/4vtomat created 
https://github.com/llvm/llvm-project/pull/101811

Fix https://github.com/llvm/llvm-project/issues/101526

`vf[n|w]cvt.x[|u].f` for f16 needs `zvfh` instead of `zvfhmin`, current approach
is not able to detect this. Ultimately we need to add `zvfh` to RequiredFeatures
to check other intrinsics instead, the type check should be done in 
checkRVVTypeSupport.


>From 1ffab9fdd26c9fd3e6524a26ca23cbd5535da377 Mon Sep 17 00:00:00 2001
From: Brandon Wu 
Date: Sat, 3 Aug 2024 03:28:25 -0700
Subject: [PATCH] [RISCV][sema] Correct the requirement of `vf[n|w]cvt.x[|u].f`
 intrinsics

Fix https://github.com/llvm/llvm-project/issues/101526

`vf[n|w]cvt.x[|u].f` for f16 needs `zvfh` instead of `zvfhmin`, current approach
is not able to detect this. Ultimately we need to add `zvfh` to RequiredFeatures
to check other intrinsics instead, the type check should be done in 
checkRVVTypeSupport.
---
 clang/include/clang/Basic/riscv_vector.td | 48 ---
 .../clang/Basic/riscv_vector_common.td|  4 +-
 .../clang/Support/RISCVVIntrinsicUtils.h  |  3 +-
 clang/lib/Sema/SemaRISCV.cpp  |  6 +++
 clang/utils/TableGen/RISCVVEmitter.cpp|  1 +
 5 files changed, 53 insertions(+), 9 deletions(-)

diff --git a/clang/include/clang/Basic/riscv_vector.td 
b/clang/include/clang/Basic/riscv_vector.td
index 0cab4b8067f0d..662771d640b69 100644
--- a/clang/include/clang/Basic/riscv_vector.td
+++ b/clang/include/clang/Basic/riscv_vector.td
@@ -1912,8 +1912,18 @@ def vfcvt_rtz_x_f_v : 
RVVConvToSignedBuiltin<"vfcvt_rtz_x">;
 let Log2LMUL = [-3, -2, -1, 0, 1, 2] in {
   def vfwcvt_rtz_xu_f_v : RVVConvToWidenUnsignedBuiltin<"vfwcvt_rtz_xu">;
   def vfwcvt_rtz_x_f_v : RVVConvToWidenSignedBuiltin<"vfwcvt_rtz_x">;
-  def vfwcvt_f_xu_v : RVVConvBuiltin<"Fw", "FwUv", "csi", "vfwcvt_f">;
-  def vfwcvt_f_x_v : RVVConvBuiltin<"Fw", "Fwv", "csi", "vfwcvt_f">;
+  def vfwcvt_f_xu_v : RVVConvBuiltin<"Fw", "FwUv", "si", "vfwcvt_f">;
+  def vfwcvt_f_x_v : RVVConvBuiltin<"Fw", "Fwv", "si", "vfwcvt_f">;
+  let RequiredFeatures = ["Zvfh"] in {
+let Name = "vfwcvt_f_xu_v",
+IRName = "vfwcvt_f_xu_v",
+MaskedIRName = "vfwcvt_f_xu_v_mask" in
+  def : RVVConvBuiltin<"Fw", "FwUv", "c", "vfwcvt_f">;
+let Name = "vfwcvt_f_x_v",
+IRName = "vfwcvt_f_x_v",
+MaskedIRName = "vfwcvt_f_x_v_mask" in
+  def : RVVConvBuiltin<"Fw", "Fwv", "c", "vfwcvt_f">;
+  }
   def vfwcvt_f_f_v : RVVConvBuiltin<"w", "wv", "f", "vfwcvt_f">;
   let RequiredFeatures = ["Zvfhmin"] in
 def vfwcvt_f_f_v_fp16 : RVVConvBuiltin<"w", "wv", "x", "vfwcvt_f"> {
@@ -1927,6 +1937,16 @@ let Log2LMUL = [-3, -2, -1, 0, 1, 2] in {
 let Log2LMUL = [-3, -2, -1, 0, 1, 2] in {
   def vfncvt_rtz_xu_f_w : RVVConvToNarrowingUnsignedBuiltin<"vfncvt_rtz_xu">;
   def vfncvt_rtz_x_f_w : RVVConvToNarrowingSignedBuiltin<"vfncvt_rtz_x">;
+  let RequiredFeatures = ["Zvfh"] in {
+let Name = "vfncvt_rtz_xu_f_w",
+IRName = "vfncvt_rtz_xu_f_w",
+MaskedIRName = "vfncvt_rtz_xu_f_w_mask" in
+  def : RVVConvBuiltin<"Uv", "UvFw", "c", "vfncvt_rtz_xu">;
+let Name = "vfncvt_rtz_x_f_w",
+IRName = "vfncvt_rtz_x_f_w",
+MaskedIRName = "vfncvt_rtz_x_f_w_mask" in
+  def : RVVConvBuiltin<"Iv", "IvFw", "c", "vfncvt_rtz_x">;
+  }
   def vfncvt_rod_f_f_w : RVVConvBuiltin<"v", "vw", "xf", "vfncvt_rod_f">;
 }
 
@@ -2005,10 +2025,18 @@ let ManualCodegen = [{
 let Log2LMUL = [-3, -2, -1, 0, 1, 2] in {
   let OverloadedName = "vfncvt_x" in
 defm :
-  RVVConvBuiltinSet<"vfncvt_x_f_w", "csi", [["Iv", "IvFwu"]]>;
+  RVVConvBuiltinSet<"vfncvt_x_f_w", "si", [["Iv", "IvFwu"]]>;
   let OverloadedName = "vfncvt_xu" in
 defm :
-  RVVConvBuiltinSet<"vfncvt_xu_f_w", "csi", [["Uv", "UvFwu"]]>;
+  RVVConvBuiltinSet<"vfncvt_xu_f_w", "si", [["Uv", "UvFwu"]]>;
+  let RequiredFeatures = ["Zvfh"] in {
+let OverloadedName = "vfncvt_x" in
+  defm :
+RVVConvBuiltinSet<"vfncvt_x_f_w", "c", [["Iv", "IvFwu"]]>;
+let OverloadedName = "vfncvt_xu" in
+  defm :
+RVVConvBuiltinSet<"vfncvt_xu_f_w", "c", [["Uv", "UvFwu"]]>;
+  }
   let OverloadedName = "vfncvt_f" in {
 defm :
   RVVConvBuiltinSet<"vfncvt_f_x_w", "xf", [["v", "vIwu"]]>;
@@ -2055,10 +2083,18 @@ let ManualCodegen = [{
   let Log2LMUL = [-3, -2, -1, 0, 1, 2] in {
 let OverloadedName = "vfncvt_x" in
   defm :
-RVVConvBuiltinSet<"vfncvt_x_f_w", "csi", [["Iv", "IvFw"]]>;
+RVVConvBuiltinSet<"vfncvt_x_f_w", "si", [["Iv", "IvFw"]]>;
 let OverloadedName = "vfncvt_xu" in
   defm :
-RVVConvBuiltinSet<"vfncvt_xu_f_w", "csi", [["Uv", "UvFw"]]>;
+RVVConvBuiltinSet<"vfncvt_xu_f_w", "si", [["Uv", "UvFw"]]>;
+let RequiredFeatures = ["Zvfh"] in {
+  let OverloadedName = "vfncvt_x" in
+defm :
+  RVVConvBuiltinSet<"vfncvt_x_f_w", "c", [["Iv", "IvF

[clang] [RISCV][sema] Correct the requirement of `vf[n|w]cvt.x[|u].f` intrinsics (PR #101811)

2024-08-03 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-backend-risc-v

@llvm/pr-subscribers-clang

Author: Brandon Wu (4vtomat)


Changes

Fix https://github.com/llvm/llvm-project/issues/101526

`vf[n|w]cvt.x[|u].f` for f16 needs `zvfh` instead of `zvfhmin`, current approach
is not able to detect this. Ultimately we need to add `zvfh` to RequiredFeatures
to check other intrinsics instead, the type check should be done in 
checkRVVTypeSupport.


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


5 Files Affected:

- (modified) clang/include/clang/Basic/riscv_vector.td (+42-6) 
- (modified) clang/include/clang/Basic/riscv_vector_common.td (+2-2) 
- (modified) clang/include/clang/Support/RISCVVIntrinsicUtils.h (+2-1) 
- (modified) clang/lib/Sema/SemaRISCV.cpp (+6) 
- (modified) clang/utils/TableGen/RISCVVEmitter.cpp (+1) 


``diff
diff --git a/clang/include/clang/Basic/riscv_vector.td 
b/clang/include/clang/Basic/riscv_vector.td
index 0cab4b8067f0d..662771d640b69 100644
--- a/clang/include/clang/Basic/riscv_vector.td
+++ b/clang/include/clang/Basic/riscv_vector.td
@@ -1912,8 +1912,18 @@ def vfcvt_rtz_x_f_v : 
RVVConvToSignedBuiltin<"vfcvt_rtz_x">;
 let Log2LMUL = [-3, -2, -1, 0, 1, 2] in {
   def vfwcvt_rtz_xu_f_v : RVVConvToWidenUnsignedBuiltin<"vfwcvt_rtz_xu">;
   def vfwcvt_rtz_x_f_v : RVVConvToWidenSignedBuiltin<"vfwcvt_rtz_x">;
-  def vfwcvt_f_xu_v : RVVConvBuiltin<"Fw", "FwUv", "csi", "vfwcvt_f">;
-  def vfwcvt_f_x_v : RVVConvBuiltin<"Fw", "Fwv", "csi", "vfwcvt_f">;
+  def vfwcvt_f_xu_v : RVVConvBuiltin<"Fw", "FwUv", "si", "vfwcvt_f">;
+  def vfwcvt_f_x_v : RVVConvBuiltin<"Fw", "Fwv", "si", "vfwcvt_f">;
+  let RequiredFeatures = ["Zvfh"] in {
+let Name = "vfwcvt_f_xu_v",
+IRName = "vfwcvt_f_xu_v",
+MaskedIRName = "vfwcvt_f_xu_v_mask" in
+  def : RVVConvBuiltin<"Fw", "FwUv", "c", "vfwcvt_f">;
+let Name = "vfwcvt_f_x_v",
+IRName = "vfwcvt_f_x_v",
+MaskedIRName = "vfwcvt_f_x_v_mask" in
+  def : RVVConvBuiltin<"Fw", "Fwv", "c", "vfwcvt_f">;
+  }
   def vfwcvt_f_f_v : RVVConvBuiltin<"w", "wv", "f", "vfwcvt_f">;
   let RequiredFeatures = ["Zvfhmin"] in
 def vfwcvt_f_f_v_fp16 : RVVConvBuiltin<"w", "wv", "x", "vfwcvt_f"> {
@@ -1927,6 +1937,16 @@ let Log2LMUL = [-3, -2, -1, 0, 1, 2] in {
 let Log2LMUL = [-3, -2, -1, 0, 1, 2] in {
   def vfncvt_rtz_xu_f_w : RVVConvToNarrowingUnsignedBuiltin<"vfncvt_rtz_xu">;
   def vfncvt_rtz_x_f_w : RVVConvToNarrowingSignedBuiltin<"vfncvt_rtz_x">;
+  let RequiredFeatures = ["Zvfh"] in {
+let Name = "vfncvt_rtz_xu_f_w",
+IRName = "vfncvt_rtz_xu_f_w",
+MaskedIRName = "vfncvt_rtz_xu_f_w_mask" in
+  def : RVVConvBuiltin<"Uv", "UvFw", "c", "vfncvt_rtz_xu">;
+let Name = "vfncvt_rtz_x_f_w",
+IRName = "vfncvt_rtz_x_f_w",
+MaskedIRName = "vfncvt_rtz_x_f_w_mask" in
+  def : RVVConvBuiltin<"Iv", "IvFw", "c", "vfncvt_rtz_x">;
+  }
   def vfncvt_rod_f_f_w : RVVConvBuiltin<"v", "vw", "xf", "vfncvt_rod_f">;
 }
 
@@ -2005,10 +2025,18 @@ let ManualCodegen = [{
 let Log2LMUL = [-3, -2, -1, 0, 1, 2] in {
   let OverloadedName = "vfncvt_x" in
 defm :
-  RVVConvBuiltinSet<"vfncvt_x_f_w", "csi", [["Iv", "IvFwu"]]>;
+  RVVConvBuiltinSet<"vfncvt_x_f_w", "si", [["Iv", "IvFwu"]]>;
   let OverloadedName = "vfncvt_xu" in
 defm :
-  RVVConvBuiltinSet<"vfncvt_xu_f_w", "csi", [["Uv", "UvFwu"]]>;
+  RVVConvBuiltinSet<"vfncvt_xu_f_w", "si", [["Uv", "UvFwu"]]>;
+  let RequiredFeatures = ["Zvfh"] in {
+let OverloadedName = "vfncvt_x" in
+  defm :
+RVVConvBuiltinSet<"vfncvt_x_f_w", "c", [["Iv", "IvFwu"]]>;
+let OverloadedName = "vfncvt_xu" in
+  defm :
+RVVConvBuiltinSet<"vfncvt_xu_f_w", "c", [["Uv", "UvFwu"]]>;
+  }
   let OverloadedName = "vfncvt_f" in {
 defm :
   RVVConvBuiltinSet<"vfncvt_f_x_w", "xf", [["v", "vIwu"]]>;
@@ -2055,10 +2083,18 @@ let ManualCodegen = [{
   let Log2LMUL = [-3, -2, -1, 0, 1, 2] in {
 let OverloadedName = "vfncvt_x" in
   defm :
-RVVConvBuiltinSet<"vfncvt_x_f_w", "csi", [["Iv", "IvFw"]]>;
+RVVConvBuiltinSet<"vfncvt_x_f_w", "si", [["Iv", "IvFw"]]>;
 let OverloadedName = "vfncvt_xu" in
   defm :
-RVVConvBuiltinSet<"vfncvt_xu_f_w", "csi", [["Uv", "UvFw"]]>;
+RVVConvBuiltinSet<"vfncvt_xu_f_w", "si", [["Uv", "UvFw"]]>;
+let RequiredFeatures = ["Zvfh"] in {
+  let OverloadedName = "vfncvt_x" in
+defm :
+  RVVConvBuiltinSet<"vfncvt_x_f_w", "c", [["Iv", "IvFw"]]>;
+  let OverloadedName = "vfncvt_xu" in
+defm :
+  RVVConvBuiltinSet<"vfncvt_xu_f_w", "c", [["Uv", "UvFw"]]>;
+}
 let OverloadedName = "vfncvt_f" in {
   defm :
 RVVConvBuiltinSet<"vfncvt_f_x_w", "xf", [["v", "vIw"]]>;
diff --git a/clang/include/clang/Basic/riscv_vector_common.td 
b/clang/include/clang/Basic/riscv_vector_common.td
index 040db6f0cdbfb..33f6441217a5e 10064

[clang] fix issue: [Clang][OpenMP] Implicit conversion with `pragma omp taskloop` #100536 (PR #101812)

2024-08-03 Thread via cfe-commits

https://github.com/HenryZ16 created 
https://github.com/llvm/llvm-project/pull/101812

This PR fixes #100536
I've noticed that this issue was caused by setting `VType` and `StrideVType` to 
a specified type:
```cpp
if (isOpenMPTaskLoopDirective(DKind)) {
VType =
SemaRef.Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/0);
StrideVType =
SemaRef.Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/1);
  }
```
Then performed type-checking on these types. So I avoided the corresponding 
type-checkings to these types.
To test whether this fix can avoid the failure under `-Werror -Wconversion`, 
you can simply use the code in #100536:
```cpp
int main(void)
{
#pragma omp parallel
#pragma omp single
{
#pragma omp taskloop
for (int i = 0; i < 1; i++) {
#pragma omp task
{}
}

#pragma omp taskloop
for (long i = 0L; i < 1L; i++) {
#pragma omp task
{}
}

#pragma omp taskloop
for (unsigned long i = 0UL; i < 1UL; i++) {
#pragma omp task
{}
}
}
return 0;
}
```
It used to fail, but now it can be compiled without any errors.

>From 217b910739f6bbc392cbb98f34fdd785bca2f57e Mon Sep 17 00:00:00 2001
From: HenryZ16 <1546169...@qq.com>
Date: Sat, 3 Aug 2024 05:03:15 -0600
Subject: [PATCH] fix issue: [Clang][OpenMP] Implicit conversion with `pragma
 omp taskloop` #100536

---
 clang/include/clang/Sema/Sema.h |  9 +++-
 clang/lib/Sema/SemaExprCXX.cpp  |  6 ++-
 clang/lib/Sema/SemaOpenMP.cpp   | 76 ++---
 3 files changed, 73 insertions(+), 18 deletions(-)

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 2ec6367eccea0..c62919cb13962 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -8279,9 +8279,16 @@ class Sema final : public SemaBase {
 return ActOnFinishFullExpr(
 Expr, Expr ? Expr->getExprLoc() : SourceLocation(), DiscardedValue);
   }
+  ExprResult ActOnFinishFullExprNoCheckExpr(Expr *Expr, bool DiscardedValue) {
+return ActOnFinishFullExpr(
+Expr, Expr ? Expr->getExprLoc() : SourceLocation(), DiscardedValue,
+/*IsConstexpr=*/false, /*IsTemplateArgument=*/false,
+/*PerformsCheckCompletedExpr=*/false);
+  }
   ExprResult ActOnFinishFullExpr(Expr *Expr, SourceLocation CC,
  bool DiscardedValue, bool IsConstexpr = false,
- bool IsTemplateArgument = false);
+ bool IsTemplateArgument = false,
+ bool PerformsCheckCompletedExpr = true);
   StmtResult ActOnFinishFullStmt(Stmt *Stmt);
 
   /// Process the expression contained within a decltype. For such expressions,
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index c5003d9ac0254..8d47602712d3a 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -9083,7 +9083,8 @@ Sema::CorrectDelayedTyposInExpr(Expr *E, VarDecl 
*InitDecl,
 
 ExprResult Sema::ActOnFinishFullExpr(Expr *FE, SourceLocation CC,
  bool DiscardedValue, bool IsConstexpr,
- bool IsTemplateArgument) {
+ bool IsTemplateArgument,
+ bool PerformsCheckCompletedExpr) {
   ExprResult FullExpr = FE;
 
   if (!FullExpr.get())
@@ -9117,7 +9118,8 @@ ExprResult Sema::ActOnFinishFullExpr(Expr *FE, 
SourceLocation CC,
   if (FullExpr.isInvalid())
 return ExprError();
 
-  CheckCompletedExpr(FullExpr.get(), CC, IsConstexpr);
+  if (PerformsCheckCompletedExpr)
+CheckCompletedExpr(FullExpr.get(), CC, IsConstexpr);
 
   // At the end of this full expression (which could be a deeply nested
   // lambda), if there is a potential capture within the nested lambda,
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index cecb80f8fb7fd..87a5457664fd1 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -9758,7 +9758,11 @@ checkOpenMPLoop(OpenMPDirectiveKind DKind, Expr 
*CollapseLoopCountExpr,
 LastIteration.get(), UB.get());
 EUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, UB.get(),
  CondOp.get());
-EUB = SemaRef.ActOnFinishFullExpr(EUB.get(), /*DiscardedValue*/ false);
+EUB =
+isOpenMPTaskLoopDirective(DKind)
+? SemaRef.ActOnFinishFullExprNoCheckExpr(EUB.get(),
+ /*DiscardedValue*/ false)
+: SemaRef.ActOnFinishFullExpr(EUB.get(), /*DiscardedValue*/ false);
 
 // If we have a combined directive that combine

[clang] fix issue: [Clang][OpenMP] Implicit conversion with `pragma omp taskloop` #100536 (PR #101812)

2024-08-03 Thread via cfe-commits

github-actions[bot] wrote:



Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from 
other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

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


[clang] fix issue: [Clang][OpenMP] Implicit conversion with `pragma omp taskloop` #100536 (PR #101812)

2024-08-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (HenryZ16)


Changes

This PR fixes #100536
I've noticed that this issue was caused by setting `VType` and `StrideVType` to 
a specified type:
```cpp
if (isOpenMPTaskLoopDirective(DKind)) {
VType =
SemaRef.Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/0);
StrideVType =
SemaRef.Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/1);
  }
```
Then performed type-checking on these types. So I avoided the corresponding 
type-checkings to these types.
To test whether this fix can avoid the failure under `-Werror -Wconversion`, 
you can simply use the code in #100536:
```cpp
int main(void)
{
#pragma omp parallel
#pragma omp single
{
#pragma omp taskloop
for (int i = 0; i < 1; i++) {
#pragma omp task
{}
}

#pragma omp taskloop
for (long i = 0L; i < 1L; i++) {
#pragma omp task
{}
}

#pragma omp taskloop
for (unsigned long i = 0UL; i < 1UL; i++) {
#pragma omp task
{}
}
}
return 0;
}
```
It used to fail, but now it can be compiled without any errors.

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


3 Files Affected:

- (modified) clang/include/clang/Sema/Sema.h (+8-1) 
- (modified) clang/lib/Sema/SemaExprCXX.cpp (+4-2) 
- (modified) clang/lib/Sema/SemaOpenMP.cpp (+61-15) 


``diff
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 2ec6367eccea0..c62919cb13962 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -8279,9 +8279,16 @@ class Sema final : public SemaBase {
 return ActOnFinishFullExpr(
 Expr, Expr ? Expr->getExprLoc() : SourceLocation(), DiscardedValue);
   }
+  ExprResult ActOnFinishFullExprNoCheckExpr(Expr *Expr, bool DiscardedValue) {
+return ActOnFinishFullExpr(
+Expr, Expr ? Expr->getExprLoc() : SourceLocation(), DiscardedValue,
+/*IsConstexpr=*/false, /*IsTemplateArgument=*/false,
+/*PerformsCheckCompletedExpr=*/false);
+  }
   ExprResult ActOnFinishFullExpr(Expr *Expr, SourceLocation CC,
  bool DiscardedValue, bool IsConstexpr = false,
- bool IsTemplateArgument = false);
+ bool IsTemplateArgument = false,
+ bool PerformsCheckCompletedExpr = true);
   StmtResult ActOnFinishFullStmt(Stmt *Stmt);
 
   /// Process the expression contained within a decltype. For such expressions,
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index c5003d9ac0254..8d47602712d3a 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -9083,7 +9083,8 @@ Sema::CorrectDelayedTyposInExpr(Expr *E, VarDecl 
*InitDecl,
 
 ExprResult Sema::ActOnFinishFullExpr(Expr *FE, SourceLocation CC,
  bool DiscardedValue, bool IsConstexpr,
- bool IsTemplateArgument) {
+ bool IsTemplateArgument,
+ bool PerformsCheckCompletedExpr) {
   ExprResult FullExpr = FE;
 
   if (!FullExpr.get())
@@ -9117,7 +9118,8 @@ ExprResult Sema::ActOnFinishFullExpr(Expr *FE, 
SourceLocation CC,
   if (FullExpr.isInvalid())
 return ExprError();
 
-  CheckCompletedExpr(FullExpr.get(), CC, IsConstexpr);
+  if (PerformsCheckCompletedExpr)
+CheckCompletedExpr(FullExpr.get(), CC, IsConstexpr);
 
   // At the end of this full expression (which could be a deeply nested
   // lambda), if there is a potential capture within the nested lambda,
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index cecb80f8fb7fd..87a5457664fd1 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -9758,7 +9758,11 @@ checkOpenMPLoop(OpenMPDirectiveKind DKind, Expr 
*CollapseLoopCountExpr,
 LastIteration.get(), UB.get());
 EUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, UB.get(),
  CondOp.get());
-EUB = SemaRef.ActOnFinishFullExpr(EUB.get(), /*DiscardedValue*/ false);
+EUB =
+isOpenMPTaskLoopDirective(DKind)
+? SemaRef.ActOnFinishFullExprNoCheckExpr(EUB.get(),
+ /*DiscardedValue*/ false)
+: SemaRef.ActOnFinishFullExpr(EUB.get(), /*DiscardedValue*/ false);
 
 // If we have a combined directive that combines 'distribute', 'for' or
 // 'simd' we need to be able to access the bounds of the schedule of the
@@ -9788,7 +9792,11 @@ checkOpenMPLoop(OpenMPDirectiveKind DKind, Expr 
*CollapseLoopCountExpr,

[clang] [clang] Implement `__builtin_is_implicit_lifetime()` (PR #101807)

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


@@ -5637,6 +5638,27 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, TypeTrait 
UTT,
 return false;
   case UTT_IsTriviallyEqualityComparable:
 return isTriviallyEqualityComparableType(Self, T, KeyLoc);
+  case UTT_IsImplicitLifetime: {
+DiagnoseVLAInCXXTypeTrait(Self, TInfo,
+  tok::kw___builtin_is_implicit_lifetime);
+QualType UnqualT = T->getCanonicalTypeUnqualified();
+if (UnqualT->isScalarType())
+  return true;
+if (UnqualT->isArrayType())
+  return true;
+
+CXXRecordDecl *RD = UnqualT->getAsCXXRecordDecl();

tbaederr wrote:

```suggestion
const CXXRecordDecl *RD = UnqualT->getAsCXXRecordDecl();
```

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


[clang] fix issue: [Clang][OpenMP] Implicit conversion with `pragma omp taskloop` #100536 (PR #101812)

2024-08-03 Thread via cfe-commits

HenryZ16 wrote:

@jdoerfert @alexey-bataev 

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


[clang] [llvm] [X86][AVX10.2] Support AVX10.2-MINMAX new instructions. (PR #101598)

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


@@ -0,0 +1,219 @@
+/*===--- avx10_2_512minmaxintrin.h - AVX10_2_512MINMAX intrinsics
+ *-===
+ *
+ * Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+ * See https://llvm.org/LICENSE.txt for license information.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ *
+ *===---===
+ */
+#ifndef __IMMINTRIN_H
+#error 
\
+"Never use  directly; include  
instead."
+#endif // __IMMINTRIN_H
+
+#ifndef __AVX10_2_512MINMAXINTRIN_H
+#define __AVX10_2_512MINMAXINTRIN_H
+
+#define _mm512_minmaxne_pbh(A, B, C)   
\
+  ((__m512bh)__builtin_ia32_vminmaxnepbf16512( 
\
+  (__v32bf)(__m512bh)(A), (__v32bf)(__m512bh)(A), (int)(C)))
+
+#define _mm512_mask_minmaxne_pbh(W, U, A, B, C)
\
+  ((__m512bh)__builtin_ia32_selectpbf_512( 
\
+  (__mmask32)(U),  
\
+  (__v32bf)__builtin_ia32_vminmaxnepbf16512(   
\

phoebewang wrote:

We prefer to use `_mm512_minmaxne_pbh` instead of builtin. The same below.

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


[clang] [llvm] [X86][AVX10.2] Support AVX10.2-MINMAX new instructions. (PR #101598)

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


@@ -2022,6 +2022,22 @@ TARGET_BUILTIN(__builtin_ia32_vsm4key4256, 
"V8UiV8UiV8Ui", "nV:256:", "sm4")
 TARGET_BUILTIN(__builtin_ia32_vsm4rnds4128, "V4UiV4UiV4Ui", "nV:128:", "sm4")
 TARGET_BUILTIN(__builtin_ia32_vsm4rnds4256, "V8UiV8UiV8Ui", "nV:256:", "sm4")
 
+// AVX10-MINMAX

phoebewang wrote:

Suggest using `AVX10 MINMAX` in case someone will think it's a real CPUID.

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


[clang] [llvm] [X86][AVX10.2] Support AVX10.2-MINMAX new instructions. (PR #101598)

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


@@ -0,0 +1,219 @@
+/*===--- avx10_2_512minmaxintrin.h - AVX10_2_512MINMAX intrinsics
+ *-===

phoebewang wrote:

Make it one line.

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


[clang] [llvm] [X86][AVX10.2] Support AVX10.2-MINMAX new instructions. (PR #101598)

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


@@ -0,0 +1,188 @@
+/*===--- avx10_2minmaxintrin.h - AVX10_2MINMAX intrinsics
+ *-===

phoebewang wrote:

ditto.

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


[clang] [llvm] [X86][AVX10.2] Support AVX10.2-MINMAX new instructions. (PR #101598)

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


@@ -0,0 +1,219 @@
+/*===--- avx10_2_512minmaxintrin.h - AVX10_2_512MINMAX intrinsics
+ *-===
+ *
+ * Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+ * See https://llvm.org/LICENSE.txt for license information.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ *
+ *===---===
+ */
+#ifndef __IMMINTRIN_H
+#error 
\
+"Never use  directly; include  
instead."
+#endif // __IMMINTRIN_H
+
+#ifndef __AVX10_2_512MINMAXINTRIN_H
+#define __AVX10_2_512MINMAXINTRIN_H
+
+#define _mm512_minmaxne_pbh(A, B, C)   
\
+  ((__m512bh)__builtin_ia32_vminmaxnepbf16512( 
\
+  (__v32bf)(__m512bh)(A), (__v32bf)(__m512bh)(A), (int)(C)))
+
+#define _mm512_mask_minmaxne_pbh(W, U, A, B, C)
\
+  ((__m512bh)__builtin_ia32_selectpbf_512( 
\
+  (__mmask32)(U),  
\
+  (__v32bf)__builtin_ia32_vminmaxnepbf16512(   
\
+  (__v32bf)(__m512bh)(A), (__v32bf)(__m512bh)(B), (int)(C)),   
\
+  (__v32bf)(__m512bh)(W)))
+
+#define _mm512_maskz_minmaxne_pbh(U, A, B, C)  
\
+  ((__m512bh)__builtin_ia32_selectpbf_512( 
\
+  (__mmask32)(U),  
\
+  (__v32bf)__builtin_ia32_vminmaxnepbf16512(   
\
+  (__v32bf)(__m512bh)(A), (__v32bf)(__m512bh)(B), (int)(C)),   
\
+  (__v32bf) __builtin_bit_cast(__m512bh, _mm512_setzero_ps(
+
+#define _mm512_minmax_pd(A, B, C)  
\
+  ((__m512d)__builtin_ia32_vminmaxpd512_round_mask(
\
+  (__v8df)(__m512d)(A), (__v8df)(__m512d)(B), (int)(C),
\
+  (__v8df)_mm512_undefined_pd(), (__mmask8) - 1,   
\

phoebewang wrote:

`(__mmask8)-1`. The same below.

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


[clang] [llvm] [X86][AVX10.2] Support AVX10.2-MINMAX new instructions. (PR #101598)

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


@@ -0,0 +1,210 @@
+// RUN: %clang_cc1 %s -flax-vector-conversions=none -ffreestanding 
-triple=x86_64 -target-feature +avx10.2-512 \
+// RUN: -emit-llvm -o - -Wno-invalid-feature-combination -Wall -Werror | 
FileCheck %s
+// RUN: %clang_cc1 %s -flax-vector-conversions=none -ffreestanding 
-triple=i386 -target-feature +avx10.2-512 \
+// RUN: -emit-llvm -o - -Wno-invalid-feature-combination -Wall -Werror | 
FileCheck %s

phoebewang wrote:

`+avx10.2-256`

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


[clang] [llvm] [X86][AVX10.2] Support AVX10.2-MINMAX new instructions. (PR #101598)

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


@@ -2022,6 +2022,22 @@ TARGET_BUILTIN(__builtin_ia32_vsm4key4256, 
"V8UiV8UiV8Ui", "nV:256:", "sm4")
 TARGET_BUILTIN(__builtin_ia32_vsm4rnds4128, "V4UiV4UiV4Ui", "nV:128:", "sm4")
 TARGET_BUILTIN(__builtin_ia32_vsm4rnds4256, "V8UiV8UiV8Ui", "nV:256:", "sm4")
 
+// AVX10-MINMAX
+TARGET_BUILTIN(__builtin_ia32_vminmaxnepbf16128, "V8yV8yV8yIi", "nV:128:", 
"avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vminmaxnepbf16256, "V16yV16yV16yIi", "nV:256:", 
"avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vminmaxnepbf16512, "V32yV32yV32yIi", "nV:512:", 
"avx10.2-512")
+TARGET_BUILTIN(__builtin_ia32_vminmaxpd128_mask, "V2dV2dV2dIiV2dUc", 
"nV:128:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vminmaxpd256_round_mask, "V4dV4dV4dIiV4dUcIi", 
"nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vminmaxpd512_round_mask, "V8dV8dV8dIiV8dUcIi", 
"nV:512:", "avx10.2-512")
+TARGET_BUILTIN(__builtin_ia32_vminmaxph128_mask, "V8xV8xV8xIiV8xUc", 
"nV:128:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vminmaxph256_round_mask, 
"V16xV16xV16xIiV16xUsIi", "nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vminmaxph512_round_mask, 
"V32xV32xV32xIiV32xUiIi", "nV:512:", "avx10.2-512")
+TARGET_BUILTIN(__builtin_ia32_vminmaxps128_mask, "V4fV4fV4fIiV4fUc", 
"nV:128:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vminmaxps256_round_mask, "V8fV8fV8fIiV8fUcIi", 
"nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vminmaxps512_round_mask, 
"V16fV16fV16fIiV16fUsIi", "nV:512:", "avx10.2-512")
+TARGET_BUILTIN(__builtin_ia32_vminmaxsd_round_mask, "V2dV2dV2dIiV2dUcIi", 
"nV:128:", "avx10.2-512")
+TARGET_BUILTIN(__builtin_ia32_vminmaxsh_round_mask, "V8xV8xV8xIiV8xUcIi", 
"nV:128:", "avx10.2-512")
+TARGET_BUILTIN(__builtin_ia32_vminmaxss_round_mask, "V4fV4fV4fIiV4fUcIi", 
"nV:128:", "avx10.2-512")

phoebewang wrote:

These need `avx10.2-256`.

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


[clang] [llvm] [X86][AVX10.2] Support AVX10.2-MINMAX new instructions. (PR #101598)

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


@@ -0,0 +1,648 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s -verify-machineinstrs -mtriple=x86_64-unknown-unknown 
--show-mc-encoding -mattr=+avx10.2-512 | FileCheck %s --check-prefixes=X64
+; RUN: llc < %s -verify-machineinstrs -mtriple=i686-unknown-unknown 
--show-mc-encoding -mattr=+avx10.2-512 | FileCheck %s --check-prefixes=X86
+
+define <32 x bfloat> @test_int_x86_avx10_vminmaxnepbf16512(<32 x bfloat> %A, 
<32 x bfloat> %B) nounwind {
+; X64-LABEL: test_int_x86_avx10_vminmaxnepbf16512:
+; X64:   # %bb.0:
+; X64-NEXT:vminmaxnepbf16 $127, %zmm1, %zmm0, %zmm0 # encoding: 
[0x62,0xf3,0x7f,0x48,0x52,0xc1,0x7f]
+; X64-NEXT:retq # encoding: [0xc3]
+;
+; X86-LABEL: test_int_x86_avx10_vminmaxnepbf16512:
+; X86:   # %bb.0:
+; X86-NEXT:vminmaxnepbf16 $127, %zmm1, %zmm0, %zmm0 # encoding: 
[0x62,0xf3,0x7f,0x48,0x52,0xc1,0x7f]
+; X86-NEXT:retl # encoding: [0xc3]
+  %ret = call <32 x bfloat> @llvm.x86.avx10.vminmaxnepbf16512(<32 x bfloat> 
%A, <32 x bfloat> %B, i32 127)
+  ret <32 x bfloat> %ret
+}
+
+define <32 x bfloat> @test_int_x86_avx10_mask_vminmaxnepbf16512(<32 x bfloat> 
%A, <32 x bfloat> %B, <32 x bfloat> %C, i32 %D) nounwind {
+; X64-LABEL: test_int_x86_avx10_mask_vminmaxnepbf16512:
+; X64:   # %bb.0:
+; X64-NEXT:kmovd %edi, %k1 # encoding: [0xc5,0xfb,0x92,0xcf]
+; X64-NEXT:vminmaxnepbf16 $127, %zmm1, %zmm0, %zmm2 {%k1} # encoding: 
[0x62,0xf3,0x7f,0x49,0x52,0xd1,0x7f]
+; X64-NEXT:vmovdqa64 %zmm2, %zmm0 # encoding: 
[0x62,0xf1,0xfd,0x48,0x6f,0xc2]
+; X64-NEXT:retq # encoding: [0xc3]
+;
+; X86-LABEL: test_int_x86_avx10_mask_vminmaxnepbf16512:
+; X86:   # %bb.0:
+; X86-NEXT:kmovd {{[0-9]+}}(%esp), %k1 # encoding: 
[0xc4,0xe1,0xf9,0x90,0x4c,0x24,0x04]
+; X86-NEXT:vminmaxnepbf16 $127, %zmm1, %zmm0, %zmm2 {%k1} # encoding: 
[0x62,0xf3,0x7f,0x49,0x52,0xd1,0x7f]
+; X86-NEXT:vmovdqa64 %zmm2, %zmm0 # encoding: 
[0x62,0xf1,0xfd,0x48,0x6f,0xc2]
+; X86-NEXT:retl # encoding: [0xc3]
+entry:
+  %0 = call <32 x bfloat> @llvm.x86.avx10.vminmaxnepbf16512(<32 x bfloat> %A, 
<32 x bfloat> %B, i32 127)
+  %1 = bitcast i32 %D to <32 x i1>
+  %2 = select reassoc nsz arcp contract afn <32 x i1> %1, <32 x bfloat> %0, 
<32 x bfloat> %C
+  ret <32 x bfloat> %2
+}
+
+declare <32 x bfloat> @llvm.x86.avx10.vminmaxnepbf16512(<32 x bfloat> %A, <32 
x bfloat> %B, i32 %C)
+
+define <32 x bfloat> @test_int_x86_avx10_maskz_vminmaxnepbf16512(<32 x bfloat> 
%A, <32 x bfloat> %B, i32 %C) nounwind {
+; X64-LABEL: test_int_x86_avx10_maskz_vminmaxnepbf16512:
+; X64:   # %bb.0:
+; X64-NEXT:kmovd %edi, %k1 # encoding: [0xc5,0xfb,0x92,0xcf]
+; X64-NEXT:vminmaxnepbf16 $127, %zmm1, %zmm0, %zmm0 {%k1} {z} # encoding: 
[0x62,0xf3,0x7f,0xc9,0x52,0xc1,0x7f]
+; X64-NEXT:retq # encoding: [0xc3]
+;
+; X86-LABEL: test_int_x86_avx10_maskz_vminmaxnepbf16512:
+; X86:   # %bb.0:
+; X86-NEXT:kmovd {{[0-9]+}}(%esp), %k1 # encoding: 
[0xc4,0xe1,0xf9,0x90,0x4c,0x24,0x04]
+; X86-NEXT:vminmaxnepbf16 $127, %zmm1, %zmm0, %zmm0 {%k1} {z} # encoding: 
[0x62,0xf3,0x7f,0xc9,0x52,0xc1,0x7f]
+; X86-NEXT:retl # encoding: [0xc3]
+entry:
+  %0 = call <32 x bfloat> @llvm.x86.avx10.vminmaxnepbf16512(<32 x bfloat> %A, 
<32 x bfloat> %B, i32 127)
+  %1 = bitcast i32 %C to <32 x i1>
+  %2 = select reassoc nsz arcp contract afn <32 x i1> %1, <32 x bfloat> %0, 
<32 x bfloat> zeroinitializer
+  ret <32 x bfloat> %2
+}
+
+define <8 x double>@test_int_x86_vminmaxpd(<8 x double> %A, <8 x double> %B) 
nounwind {
+; X64-LABEL: test_int_x86_vminmaxpd:
+; X64:   # %bb.0:
+; X64-NEXT:vminmaxpd $127, %zmm1, %zmm0, %zmm0 # encoding: 
[0x62,0xf3,0xfd,0x48,0x52,0xc1,0x7f]
+; X64-NEXT:retq # encoding: [0xc3]
+;
+; X86-LABEL: test_int_x86_vminmaxpd:
+; X86:   # %bb.0:
+; X86-NEXT:vminmaxpd $127, %zmm1, %zmm0, %zmm0 # encoding: 
[0x62,0xf3,0xfd,0x48,0x52,0xc1,0x7f]
+; X86-NEXT:retl # encoding: [0xc3]
+  %ret = call <8 x double> @llvm.x86.avx10.mask.vminmaxpd.round(<8 x double> 
%A, <8 x double> %B, i32 127, <8 x double> undef, i8 -1, i32 4)
+  ret <8 x double> %ret
+}
+
+define <8 x double>@test_int_x86_mask_vminmaxpd(<8 x double> %A, <8 x double> 
%B, <8 x double> %C, i8 %D) nounwind {
+; X64-LABEL: test_int_x86_mask_vminmaxpd:
+; X64:   # %bb.0:
+; X64-NEXT:kmovd %edi, %k1 # encoding: [0xc5,0xfb,0x92,0xcf]
+; X64-NEXT:vminmaxpd $127, %zmm1, %zmm0, %zmm2 {%k1} # encoding: 
[0x62,0xf3,0xfd,0x49,0x52,0xd1,0x7f]
+; X64-NEXT:vmovapd %zmm2, %zmm0 # encoding: [0x62,0xf1,0xfd,0x48,0x28,0xc2]
+; X64-NEXT:retq # encoding: [0xc3]
+;
+; X86-LABEL: test_int_x86_mask_vminmaxpd:
+; X86:   # %bb.0:
+; X86-NEXT:kmovb {{[0-9]+}}(%esp), %k1 # encoding: 
[0xc5,0xf9,0x90,0x4c,0x24,0x04]
+; X86-NEXT:vminmaxpd $127, %zmm1, %zmm0, %zmm2 {%k1} # encoding: 
[0x62,0xf3,0xfd,0x49,0x52,0xd1,0x7f]
+; X86-NEXT:vmovapd %zmm2, %zmm0 # encoding: [0x62,0xf1,0xfd,0x48,0x28,0xc2]
+; X86-NEXT:retl # encoding:

[clang] [llvm] [X86][AVX10.2] Support AVX10.2-MINMAX new instructions. (PR #101598)

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


@@ -0,0 +1,188 @@
+/*===--- avx10_2minmaxintrin.h - AVX10_2MINMAX intrinsics
+ *-===
+ *
+ * Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+ * See https://llvm.org/LICENSE.txt for license information.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ *
+ *===---===
+ */
+#ifndef __IMMINTRIN_H
+#error 
\
+"Never use  directly; include  
instead."
+#endif // __IMMINTRIN_H
+
+#ifndef __AVX10_2MINMAXINTRIN_H
+#define __AVX10_2MINMAXINTRIN_H
+
+#define _mm_minmaxne_pbh(A, B, C)  
\
+  ((__m128bh)__builtin_ia32_vminmaxnepbf16128( 
\
+  (__m128bh)(__v8bf)(A), (__m128bh)(__v8bf)(B), (int)(C)))
+
+#define _mm_mask_minmaxne_pbh(W, U, A, B, C)   
\
+  ((__m128bh)__builtin_ia32_selectpbf_128( 
\
+  (__mmask8)(U),   
\
+  (__v8bf)__builtin_ia32_vminmaxnepbf16128(
\
+  (__m128bh)(__v8bf)(A), (__m128bh)(__v8bf)(B), (int)(C)), 
\
+  (__v8bf)(W)))
+
+#define _mm_maskz_minmaxne_pbh(U, A, B, C) 
\
+  ((__m128bh)__builtin_ia32_selectpbf_128( 
\
+  (__mmask8)(U),   
\
+  (__v8bf)__builtin_ia32_vminmaxnepbf16128(
\
+  (__m128bh)(__v8bf)(A), (__m128bh)(__v8bf)(B), (int)(C)), 
\
+  (__v8bf) __builtin_bit_cast(__m128bh, _mm_setzero_ps(
+
+#define _mm256_minmaxne_pbh(A, B, C)   
\
+  ((__m256bh)__builtin_ia32_vminmaxnepbf16256( 
\
+  (__m256bh)(__v16bf)(A), (__m256bh)(__v16bf)(B), (int)(C)))
+
+#define _mm256_mask_minmaxne_pbh(W, U, A, B, C)
\
+  ((__m256bh)__builtin_ia32_selectpbf_256( 
\
+  (__mmask16)(U),  
\
+  (__v16bf)__builtin_ia32_vminmaxnepbf16256(   
\
+  (__m256bh)(__v16bf)(A), (__m256bh)(__v16bf)(B), (int)(C)),   
\
+  (__v16bf)(W)))
+
+#define _mm256_maskz_minmaxne_pbh(U, A, B, C)  
\
+  ((__m256bh)__builtin_ia32_selectpbf_256( 
\
+  (__mmask16)(U),  
\
+  (__v16bf)__builtin_ia32_vminmaxnepbf16256(   
\
+  (__m256bh)(__v16bf)(A), (__m256bh)(__v16bf)(B), (int)(C)),   
\
+  (__v16bf) __builtin_bit_cast(__m256bh, _mm256_setzero_ps(
+
+#define _mm_minmax_pd(A, B, C) 
\
+  ((__m128d)__builtin_ia32_vminmaxpd128_mask(  
\
+  (__v2df)(__m128d)(A), (__v2df)(__m128d)(B), (int)(C),
\
+  (__v2df)_mm_setzero_pd(), (__mmask8)(-1)))
+
+#define _mm_mask_minmax_pd(W, U, A, B, C)  
\
+  ((__m128d)__builtin_ia32_vminmaxpd128_mask(  
\
+  (__v2df)(__m128d)(A), (__v2df)(__m128d)(B), (int)(C),
\
+  (__v2df)(__m128d)(W), (__mmask8)(U)))
+
+#define _mm_maskz_minmax_pd(U, A, B, C)
\
+  ((__m128d)__builtin_ia32_vminmaxpd128_mask(  
\
+  (__v2df)(__m128d)(A), (__v2df)(__m128d)(B), (int)(C),
\
+  (__v2df)_mm_setzero_pd(), (__mmask8)(U)))
+
+#define _mm256_minmax_pd(A, B, C)  
\
+  ((__m256d)__builtin_ia32_vminmaxpd256_round_mask(
\
+  (__v4df)(__m256d)(A), (__v4df)(__m256d)(B), (int)(C),
\
+  (__v4df)_mm256_setzero_pd(), (__mmask8)(-1), _MM_FROUND_NO_EXC))

phoebewang wrote:

No need `()` around `-1`. The same below.

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


[clang] [llvm] [X86][AVX10.2] Support AVX10.2-MINMAX new instructions. (PR #101598)

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


@@ -0,0 +1,219 @@
+/*===--- avx10_2_512minmaxintrin.h - AVX10_2_512MINMAX intrinsics
+ *-===
+ *
+ * Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+ * See https://llvm.org/LICENSE.txt for license information.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ *
+ *===---===
+ */
+#ifndef __IMMINTRIN_H
+#error 
\
+"Never use  directly; include  
instead."
+#endif // __IMMINTRIN_H
+
+#ifndef __AVX10_2_512MINMAXINTRIN_H
+#define __AVX10_2_512MINMAXINTRIN_H
+
+#define _mm512_minmaxne_pbh(A, B, C)   
\
+  ((__m512bh)__builtin_ia32_vminmaxnepbf16512( 
\
+  (__v32bf)(__m512bh)(A), (__v32bf)(__m512bh)(A), (int)(C)))
+
+#define _mm512_mask_minmaxne_pbh(W, U, A, B, C)
\
+  ((__m512bh)__builtin_ia32_selectpbf_512( 
\
+  (__mmask32)(U),  
\
+  (__v32bf)__builtin_ia32_vminmaxnepbf16512(   
\
+  (__v32bf)(__m512bh)(A), (__v32bf)(__m512bh)(B), (int)(C)),   
\
+  (__v32bf)(__m512bh)(W)))
+
+#define _mm512_maskz_minmaxne_pbh(U, A, B, C)  
\
+  ((__m512bh)__builtin_ia32_selectpbf_512( 
\
+  (__mmask32)(U),  
\
+  (__v32bf)__builtin_ia32_vminmaxnepbf16512(   
\
+  (__v32bf)(__m512bh)(A), (__v32bf)(__m512bh)(B), (int)(C)),   
\
+  (__v32bf) __builtin_bit_cast(__m512bh, _mm512_setzero_ps(
+
+#define _mm512_minmax_pd(A, B, C)  
\
+  ((__m512d)__builtin_ia32_vminmaxpd512_round_mask(
\
+  (__v8df)(__m512d)(A), (__v8df)(__m512d)(B), (int)(C),
\
+  (__v8df)_mm512_undefined_pd(), (__mmask8) - 1,   
\
+  _MM_FROUND_CUR_DIRECTION))
+
+#define _mm512_mask_minmax_pd(W, U, A, B, C)   
\
+  ((__m512d)__builtin_ia32_vminmaxpd512_round_mask(
\
+  (__v8df)(__m512d)(A), (__v8df)(__m512d)(B), (int)(C),
\
+  (__v8df)(__m512d)(W), (__mmask8)(U), _MM_FROUND_CUR_DIRECTION))
+
+#define _mm512_maskz_minmax_pd(U, A, B, C) 
\
+  ((__m512d)__builtin_ia32_vminmaxpd512_round_mask(
\
+  (__v8df)(__m512d)(A), (__v8df)(__m512d)(B), (int)(C),
\
+  (__v8df)_mm512_setzero_pd(), (__mmask8)(U), _MM_FROUND_CUR_DIRECTION))
+
+#define _mm512_minmax_round_pd(A, B, C, R) 
\
+  ((__m512d)__builtin_ia32_vminmaxpd512_round_mask(
\
+  (__v8df)(__m512d)(A), (__v8df)(__m512d)(B), (int)(C),
\
+  (__v8df)_mm512_undefined_pd(), (__mmask8) - 1, (int)(R)))
+
+#define _mm512_mask_minmax_round_pd(W, U, A, B, C, R)  
\
+  ((__m512d)__builtin_ia32_vminmaxpd512_round_mask(
\
+  (__v8df)(__m512d)(A), (__v8df)(__m512d)(B), (int)(C),
\
+  (__v8df)(__m512d)(W), (__mmask8)(U), (int)(R)))
+
+#define _mm512_maskz_minmax_round_pd(U, A, B, C, R)
\
+  ((__m512d)__builtin_ia32_vminmaxpd512_round_mask(
\
+  (__v8df)(__m512d)(A), (__v8df)(__m512d)(B), (int)(C),
\
+  (__v8df)_mm512_setzero_pd(), (__mmask8)(U), (int)(R)))
+
+#define _mm512_minmax_ph(A, B, C)  
\
+  ((__m512h)__builtin_ia32_vminmaxph512_round_mask(
\
+  (__v32hf)(__m512h)(A), (__v32hf)(__m512h)(B), (int)(C),  
\
+  (__v32hf)_mm512_undefined_ph(), (__mmask32) - 1, 
\
+  _MM_FROUND_CUR_DIRECTION))
+
+#define _mm512_mask_minmax_ph(W, U, A, B, C)   
\
+  ((__m512h)__builtin_ia32_vminmaxph512_round_mask(
\
+  (__v32hf)(__m512h)(A), (__v32hf)(__m512h)(B), (int)(C),  
\
+  (__v32hf)(__m512h)(W), (__mmask32)(U), _MM_FROUND_CUR_DIRECTION))
+
+#define _mm512_maskz_minmax_ph(U, A, B, C) 
\
+  ((__m512h)__builtin_ia32_vminmaxph512_round_mask(
\
+  (__v32hf)(__m512h)(A), (__v32hf)(__m512h)(B), (int)(C),  
\
+  (__v32hf)_mm512_setzero_ph(), (__mmask32)(U), _MM_FROUND_CUR_DIRECTION))
+
+#define _mm512_minmax_round_ph(A, B, C, R) 
\
+  ((__m512h)__builtin_ia32_vminmaxph512_round_mask(

[clang] [llvm] [X86][AVX10.2] Support AVX10.2-MINMAX new instructions. (PR #101598)

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


@@ -0,0 +1,244 @@
+// RUN: %clang_cc1 %s -flax-vector-conversions=none -ffreestanding 
-triple=x86_64 -target-feature +avx10.2-512 \
+// RUN: -emit-llvm -o - -Wno-invalid-feature-combination -Wall -Werror | 
FileCheck %s
+// RUN: %clang_cc1 %s -flax-vector-conversions=none -ffreestanding 
-triple=i386 -target-feature +avx10.2-512 \
+// RUN: -emit-llvm -o - -Wno-invalid-feature-combination -Wall -Werror | 
FileCheck %s
+
+#include 
+
+__m512bh test_mm512_minmaxne_pbh(__m512bh __A, __m512bh __B) {
+  // CHECK-LABEL: @test_mm512_minmaxne_pbh(
+  // CHECK: call <32 x bfloat> @llvm.x86.avx10.vminmaxnepbf16512(
+  return _mm512_minmaxne_pbh(__A, __B, 127);
+}
+
+__m512bh test_mm512_mask_minmaxne_pbh(__m512bh __A, __mmask32 __B, __m512bh 
__C, __m512bh __D) {
+  // CHECK-LABEL: @test_mm512_mask_minmaxne_pbh(
+  // CHECK: call <32 x bfloat> @llvm.x86.avx10.vminmaxnepbf16512(
+  // CHECK: select <32 x i1> %{{.*}}, <32 x bfloat> %{{.*}}, <32 x bfloat> 
%{{.*}}
+  return _mm512_mask_minmaxne_pbh(__A, __B, __C, __D, 127);
+}
+
+__m512bh test_mm512_maskz_minmaxne_pbh(__mmask32 __A, __m512bh __B, __m512bh 
__C) {
+  // CHECK-LABEL: @test_mm512_maskz_minmaxne_pbh(
+  // CHECK: call <32 x bfloat> @llvm.x86.avx10.vminmaxnepbf16512(
+  // CHECK: zeroinitializer
+  // CHECK: select <32 x i1> %{{.*}}, <32 x bfloat> %{{.*}}, <32 x bfloat> 
%{{.*}}
+  return _mm512_maskz_minmaxne_pbh(__A, __B, __C, 127);
+}
+
+__m512d test_mm512_minmax_pd(__m512d __A, __m512d __B) {
+  // CHECK-LABEL: @test_mm512_minmax_pd(
+  // CHECK: call <8 x double> @llvm.x86.avx10.mask.vminmaxpd.round(
+  return _mm512_minmax_pd(__A, __B, 127);
+}
+
+__m512d test_mm512_mask_minmax_pd(__m512d __A, __mmask8 __B, __m512d __C, 
__m512d __D) {
+  // CHECK-LABEL: @test_mm512_mask_minmax_pd(
+  // CHECK: call <8 x double> @llvm.x86.avx10.mask.vminmaxpd.round(
+  return _mm512_mask_minmax_pd(__A, __B, __C, __D, 127);
+}
+
+__m512d test_mm512_maskz_minmax_pd(__mmask8 __A, __m512d __B, __m512d __C) {
+  // CHECK-LABEL: @test_mm512_maskz_minmax_pd(
+  // CHECK: call <8 x double> @llvm.x86.avx10.mask.vminmaxpd.round(
+  return _mm512_maskz_minmax_pd(__A, __B, __C, 127);
+}
+
+__m512d test_mm512_minmax_round_pd(__m512d __A, __m512d __B) {
+  // CHECK-LABEL: @test_mm512_minmax_round_pd(
+  // CHECK: call <8 x double> @llvm.x86.avx10.mask.vminmaxpd.round(
+  return _mm512_minmax_round_pd(__A, __B, 127, _MM_FROUND_NO_EXC);
+}
+
+__m512d test_mm512_mask_minmax_round_pd(__m512d __A, __mmask8 __B, __m512d 
__C, __m512d __D) {
+  // CHECK-LABEL: @test_mm512_mask_minmax_round_pd(
+  // CHECK: call <8 x double> @llvm.x86.avx10.mask.vminmaxpd.round(
+  return _mm512_mask_minmax_round_pd(__A, __B, __C, __D, 127, 
_MM_FROUND_NO_EXC);
+}
+
+__m512d test_mm512_maskz_minmax_round_pd(__mmask8 __A, __m512d __B, __m512d 
__C) {
+  // CHECK-LABEL: @test_mm512_maskz_minmax_round_pd(
+  // CHECK: call <8 x double> @llvm.x86.avx10.mask.vminmaxpd.round(
+  return _mm512_maskz_minmax_round_pd(__A, __B, __C, 127, _MM_FROUND_NO_EXC);
+}
+
+__m512h test_mm512_minmax_ph(__m512h __A, __m512h __B) {
+  // CHECK-LABEL: @test_mm512_minmax_ph(
+  // CHECK: call <32 x half> @llvm.x86.avx10.mask.vminmaxph.round(
+  return _mm512_minmax_ph(__A, __B, 127);
+}
+
+__m512h test_mm512_mask_minmax_ph(__m512h __A, __mmask32 __B, __m512h __C, 
__m512h __D) {
+  // CHECK-LABEL: @test_mm512_mask_minmax_ph(
+  // CHECK: call <32 x half> @llvm.x86.avx10.mask.vminmaxph.round(
+  return _mm512_mask_minmax_ph(__A, __B, __C, __D, 127);
+}
+
+__m512h test_mm512_maskz_minmax_ph(__mmask32 __A, __m512h __B, __m512h __C) {
+  // CHECK-LABEL: @test_mm512_maskz_minmax_ph(
+  // CHECK: call <32 x half> @llvm.x86.avx10.mask.vminmaxph.round(
+  return _mm512_maskz_minmax_ph(__A, __B, __C, 127);
+}
+
+__m512h test_mm512_minmax_round_ph(__m512h __A, __m512h __B) {
+  // CHECK-LABEL: @test_mm512_minmax_round_ph(
+  // CHECK: call <32 x half> @llvm.x86.avx10.mask.vminmaxph.round(
+  return _mm512_minmax_round_ph(__A, __B, 127, _MM_FROUND_NO_EXC);
+}
+
+__m512h test_mm512_mask_minmax_round_ph(__m512h __A, __mmask32 __B, __m512h 
__C, __m512h __D) {
+  // CHECK-LABEL: @test_mm512_mask_minmax_round_ph(
+  // CHECK: call <32 x half> @llvm.x86.avx10.mask.vminmaxph.round(
+  return _mm512_mask_minmax_round_ph(__A, __B, __C, __D, 127, 
_MM_FROUND_NO_EXC);
+}
+
+__m512h test_mm512_maskz_minmax_round_ph(__mmask32 __A, __m512h __B, __m512h 
__C) {
+  // CHECK-LABEL: @test_mm512_maskz_minmax_round_ph(
+  // CHECK: call <32 x half> @llvm.x86.avx10.mask.vminmaxph.round(
+  return _mm512_maskz_minmax_round_ph(__A, __B, __C, 127, _MM_FROUND_NO_EXC);
+}
+
+__m512 test_mm512_minmax_ps(__m512 __A, __m512 __B) {
+  // CHECK-LABEL: @test_mm512_minmax_ps(
+  // CHECK: call <16 x float> @llvm.x86.avx10.mask.vminmaxps.round(
+  return _mm512_minmax_ps(__A, __B, 127);
+}
+
+__m512 test_mm512_mask_minmax_ps(__m512 __A, __mmask16 __B, __m512 __C, __m512 
__D) {
+  // CHECK-LABEL: @test_mm512_mask_minmax_ps(
+  // CHECK: call <16 x float> @l

[clang] [llvm] [X86][AVX10.2] Support AVX10.2-MINMAX new instructions. (PR #101598)

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


@@ -388,12 +388,27 @@ static const IntrinsicData IntrinsicsWithoutChain[] = {
 X86_INTRINSIC_DATA(avx_vpermilvar_ps, INTR_TYPE_2OP, X86ISD::VPERMILPV, 0),
 X86_INTRINSIC_DATA(avx_vpermilvar_ps_256, INTR_TYPE_2OP, X86ISD::VPERMILPV,
0),
+X86_INTRINSIC_DATA(avx10_mask_vminmaxpd_round, INTR_TYPE_3OP_MASK_SAE, 
X86ISD::VMINMAX, X86ISD::VMINMAX_SAE),
+X86_INTRINSIC_DATA(avx10_mask_vminmaxpd128, INTR_TYPE_3OP_MASK_SAE, 
X86ISD::VMINMAX, 0),
+X86_INTRINSIC_DATA(avx10_mask_vminmaxpd256_round, INTR_TYPE_3OP_MASK_SAE, 
X86ISD::VMINMAX, X86ISD::VMINMAX_SAE),
+X86_INTRINSIC_DATA(avx10_mask_vminmaxph_round, INTR_TYPE_3OP_MASK_SAE, 
X86ISD::VMINMAX, X86ISD::VMINMAX_SAE),
+X86_INTRINSIC_DATA(avx10_mask_vminmaxph128, INTR_TYPE_3OP_MASK_SAE, 
X86ISD::VMINMAX, 0),
+X86_INTRINSIC_DATA(avx10_mask_vminmaxph256_round, INTR_TYPE_3OP_MASK_SAE, 
X86ISD::VMINMAX, X86ISD::VMINMAX_SAE),
+X86_INTRINSIC_DATA(avx10_mask_vminmaxps_round, INTR_TYPE_3OP_MASK_SAE, 
X86ISD::VMINMAX, X86ISD::VMINMAX_SAE),
+X86_INTRINSIC_DATA(avx10_mask_vminmaxps128, INTR_TYPE_3OP_MASK_SAE, 
X86ISD::VMINMAX, 0),
+X86_INTRINSIC_DATA(avx10_mask_vminmaxps256_round, INTR_TYPE_3OP_MASK_SAE, 
X86ISD::VMINMAX, X86ISD::VMINMAX_SAE),
+X86_INTRINSIC_DATA(avx10_mask_vminmaxsd_round, INTR_TYPE_3OP_MASK_SAE, 
X86ISD::VMINMAXS, X86ISD::VMINMAXS_SAE),
+X86_INTRINSIC_DATA(avx10_mask_vminmaxsh_round, INTR_TYPE_3OP_MASK_SAE, 
X86ISD::VMINMAXS, X86ISD::VMINMAXS_SAE),
+X86_INTRINSIC_DATA(avx10_mask_vminmaxss_round, INTR_TYPE_3OP_MASK_SAE, 
X86ISD::VMINMAXS, X86ISD::VMINMAXS_SAE),

phoebewang wrote:

Format the code.

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


[clang] Retrieve BinaryOperator::getOpcode and BinaryOperator::getOpcodeStr via libclang and its python interface (PR #98489)

2024-08-03 Thread Vlad Serebrennikov via cfe-commits


@@ -54,6 +54,8 @@ LLVM_13 {
 clang_Cursor_Evaluate;
 clang_Cursor_getArgument;
 clang_Cursor_getBriefCommentText;
+clang_Cursor_getBinaryOpcode;
+clang_Cursor_getBinaryOpcodeStr;

Endilll wrote:

This is symbol versioning, which allows us to update libclang functions, 
retaining backwards ABI compatibility. I think the most famous user of this 
mechanism is glibc.

I don't think that this is critical, but I can see how confusing it might be 
when you list exported function in libclang 13 and libclang 19, and see that 
libclang 19 claims that libclang 13 should have two more functions added in 
this patch. This should fixed and backported to 19. We're far enough into 
release schedule (approaching rc2) that this has some urgency.

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


[clang] [clang] Implement `__builtin_is_implicit_lifetime()` (PR #101807)

2024-08-03 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll updated 
https://github.com/llvm/llvm-project/pull/101807

>From 9c4e7ccf47d5ede2b6169effb2a09668f512a182 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Sat, 3 Aug 2024 13:05:21 +0300
Subject: [PATCH 1/2] [clang] Implement `__builtin_is_implicit_lifetime()`

This intrinsic supports [P2647R1](https://wg21.link/p2674r1) "A trait for 
implicit lifetime types".
---
 clang/docs/LanguageExtensions.rst|  1 +
 clang/docs/ReleaseNotes.rst  |  3 +
 clang/include/clang/Basic/TokenKinds.def |  1 +
 clang/lib/Sema/SemaExprCXX.cpp   | 22 +++
 clang/test/SemaCXX/type-traits.cpp   | 81 +++-
 5 files changed, 107 insertions(+), 1 deletion(-)

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index a747464582e77..f04e6b0057b51 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1546,6 +1546,7 @@ The following type trait primitives are supported by 
Clang. Those traits marked
 * ``__array_extent(type, dim)`` (Embarcadero):
   The ``dim``'th array bound in the type ``type``, or ``0`` if
   ``dim >= __array_rank(type)``.
+* ``__builtin_is_implicit_lifetime`` (C++, GNU, Microsoft)
 * ``__builtin_is_virtual_base_of`` (C++, GNU, Microsoft)
 * ``__can_pass_in_regs`` (C++)
   Returns whether a class can be passed in registers under the current
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 25f5bd37bbe94..6854a321e1720 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -86,6 +86,9 @@ C++23 Feature Support
 C++2c Feature Support
 ^
 
+- Add ``__builtin_is_implicit_lifetime`` intrinsic, which supports
+  `P2647R1 A trait for implicit lifetime types `_
+
 - Add ``__builtin_is_virtual_base_of`` intrinsic, which supports
   `P2985R0 A type trait for detecting virtual base classes 
`_
 
diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 7e638dc1ddcdb..7505c5a1a1f27 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -501,6 +501,7 @@ TYPE_TRAIT_1(__has_trivial_move_assign, 
HasTrivialMoveAssign, KEYCXX)
 TYPE_TRAIT_1(__has_trivial_move_constructor, HasTrivialMoveConstructor, KEYCXX)
 
 // GNU and MS Type Traits
+TYPE_TRAIT_1(__builtin_is_implicit_lifetime, IsImplicitLifetime, KEYCXX)
 TYPE_TRAIT_2(__builtin_is_virtual_base_of, IsVirtualBaseOf, KEYCXX)
 TYPE_TRAIT_1(__has_nothrow_assign, HasNothrowAssign, KEYCXX)
 TYPE_TRAIT_1(__has_nothrow_copy, HasNothrowCopy, KEYCXX)
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index c5003d9ac0254..504dc93316db5 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -5039,6 +5039,7 @@ static bool CheckUnaryTypeTraitTypeCompleteness(Sema &S, 
TypeTrait UTT,
 
   // LWG3823: T shall be an array type, a complete type, or cv void.
   case UTT_IsAggregate:
+  case UTT_IsImplicitLifetime:
 if (ArgTy->isArrayType() || ArgTy->isVoidType())
   return true;
 
@@ -5637,6 +5638,27 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, TypeTrait 
UTT,
 return false;
   case UTT_IsTriviallyEqualityComparable:
 return isTriviallyEqualityComparableType(Self, T, KeyLoc);
+  case UTT_IsImplicitLifetime: {
+DiagnoseVLAInCXXTypeTrait(Self, TInfo,
+  tok::kw___builtin_is_implicit_lifetime);
+QualType UnqualT = T->getCanonicalTypeUnqualified();
+if (UnqualT->isScalarType())
+  return true;
+if (UnqualT->isArrayType())
+  return true;
+
+CXXRecordDecl *RD = UnqualT->getAsCXXRecordDecl();
+if (!RD)
+  return false;
+if (UnqualT->isAggregateType())
+  if (!RD->getDestructor()->isUserProvided())
+return true;
+if (RD->hasTrivialDestructor())
+  if (RD->hasTrivialDefaultConstructor() ||
+  RD->hasTrivialCopyConstructor() || RD->hasTrivialMoveConstructor())
+return true;
+return false;
+  }
   }
 }
 
diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index 4acb3d6c9eebe..11041414c1bba 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -18,7 +18,7 @@ enum class SignedEnumClass : signed int {};
 enum class UnsignedEnumClass : unsigned int {};
 struct POD { Enum e; int i; float f; NonPOD* p; };
 struct Empty {};
-struct IncompleteStruct;
+struct IncompleteStruct; // expected-note {{forward declaration of 
'IncompleteStruct'}}
 typedef Empty EmptyAr[10];
 typedef Empty EmptyArNB[];
 typedef Empty EmptyArMB[1][2];
@@ -1944,6 +1944,85 @@ void is_pointer_interconvertible_base_of(int n)
 }
 }
 
+struct NoEligibleTrivialContructor {
+  NoEligibleTrivialContructor() {};
+  NoEligibleTrivialContructor(const NoEligibleTrivialContructor&) {}
+  NoEligibleTrivialContructor(NoEligibleTrivialContructo

[clang] Retrieve BinaryOperator::getOpcode and BinaryOperator::getOpcodeStr via libclang and its python interface (PR #98489)

2024-08-03 Thread Jannick Kremer via cfe-commits


@@ -54,6 +54,8 @@ LLVM_13 {
 clang_Cursor_Evaluate;
 clang_Cursor_getArgument;
 clang_Cursor_getBriefCommentText;
+clang_Cursor_getBinaryOpcode;
+clang_Cursor_getBinaryOpcodeStr;

DeinAlptraum wrote:

I will open a fix PR rightaway

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


[clang] Retrieve BinaryOperator::getOpcode and BinaryOperator::getOpcodeStr via libclang and its python interface (PR #98489)

2024-08-03 Thread Vlad Serebrennikov via cfe-commits


@@ -54,6 +54,8 @@ LLVM_13 {
 clang_Cursor_Evaluate;
 clang_Cursor_getArgument;
 clang_Cursor_getBriefCommentText;
+clang_Cursor_getBinaryOpcode;
+clang_Cursor_getBinaryOpcodeStr;

Endilll wrote:

Make sure to fix this on `main` first, then we can initiate backporting.

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


[clang] [libclang] Move getBinaryOpcode library functions to LLVM 19 (PR #101820)

2024-08-03 Thread Jannick Kremer via cfe-commits

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


[clang] [libclang] Move getBinaryOpcode library functions to LLVM 19 (PR #101820)

2024-08-03 Thread Jannick Kremer via cfe-commits

https://github.com/DeinAlptraum created 
https://github.com/llvm/llvm-project/pull/101820

None

>From aff16c3b3a0cb7065a5ac143ae06850bbbeb666a Mon Sep 17 00:00:00 2001
From: Jannick Kremer 
Date: Sat, 3 Aug 2024 13:43:41 +0100
Subject: [PATCH] [libclang] Move getBinaryOpcode library functions to LLVM 19

---
 clang/tools/libclang/libclang.map | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/clang/tools/libclang/libclang.map 
b/clang/tools/libclang/libclang.map
index 91c329b5765d4..371fe512ce71c 100644
--- a/clang/tools/libclang/libclang.map
+++ b/clang/tools/libclang/libclang.map
@@ -54,8 +54,6 @@ LLVM_13 {
 clang_Cursor_Evaluate;
 clang_Cursor_getArgument;
 clang_Cursor_getBriefCommentText;
-clang_Cursor_getBinaryOpcode;
-clang_Cursor_getBinaryOpcodeStr;
 clang_Cursor_getCXXManglings;
 clang_Cursor_getCommentRange;
 clang_Cursor_getMangling;
@@ -430,6 +428,12 @@ LLVM_17 {
 clang_getCursorUnaryOperatorKind;
 };
 
+LLVM_19 {
+  global:
+clang_Cursor_getBinaryOpcode;
+clang_Cursor_getBinaryOpcodeStr;
+};
+
 # Example of how to add a new symbol version entry.  If you do add a new symbol
 # version, please update the example to depend on the version you added.
 # LLVM_X {

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


[clang] [libclang] Move getBinaryOpcode library functions to LLVM 19 (PR #101820)

2024-08-03 Thread Jannick Kremer via cfe-commits

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


[clang] [libclang] Move getBinaryOpcode library functions to LLVM 19 (PR #101820)

2024-08-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Jannick Kremer (DeinAlptraum)


Changes



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


1 Files Affected:

- (modified) clang/tools/libclang/libclang.map (+6-2) 


``diff
diff --git a/clang/tools/libclang/libclang.map 
b/clang/tools/libclang/libclang.map
index 91c329b5765d4..371fe512ce71c 100644
--- a/clang/tools/libclang/libclang.map
+++ b/clang/tools/libclang/libclang.map
@@ -54,8 +54,6 @@ LLVM_13 {
 clang_Cursor_Evaluate;
 clang_Cursor_getArgument;
 clang_Cursor_getBriefCommentText;
-clang_Cursor_getBinaryOpcode;
-clang_Cursor_getBinaryOpcodeStr;
 clang_Cursor_getCXXManglings;
 clang_Cursor_getCommentRange;
 clang_Cursor_getMangling;
@@ -430,6 +428,12 @@ LLVM_17 {
 clang_getCursorUnaryOperatorKind;
 };
 
+LLVM_19 {
+  global:
+clang_Cursor_getBinaryOpcode;
+clang_Cursor_getBinaryOpcodeStr;
+};
+
 # Example of how to add a new symbol version entry.  If you do add a new symbol
 # version, please update the example to depend on the version you added.
 # LLVM_X {

``




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


[clang] [libclang] Move getBinaryOpcode library functions to LLVM 19 (PR #101820)

2024-08-03 Thread Vlad Serebrennikov via cfe-commits

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


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


[clang] [libclang] Fix symbol version of `getBinaryOpcode` functions (PR #101820)

2024-08-03 Thread Vlad Serebrennikov via cfe-commits

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


[clang] [libclang] Fix symbol version of `getBinaryOpcode` functions (PR #101820)

2024-08-03 Thread Vlad Serebrennikov via cfe-commits

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


[clang] [libclang] Fix symbol version of `getBinaryOpcode` functions (PR #101820)

2024-08-03 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

I wrote a description to provide readers some context. In general PRs without 
descriptions are discouraged.
Hope you don't mind.

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


[clang] [clang][Interp] Fix function pointer callexpr eval order (PR #101821)

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

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

We need to evaluate the callee before the arguments.

>From ef92f7ef23014f001630fe9d30cdf7c39d19bfbf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sat, 3 Aug 2024 15:06:12 +0200
Subject: [PATCH] [clang][Interp] Fix function pointer callexpr eval order

We need to evaluate the callee before the arguments.
---
 clang/lib/AST/Interp/Compiler.cpp| 22 +-
 clang/test/AST/Interp/eval-order.cpp |  5 ++---
 2 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/clang/lib/AST/Interp/Compiler.cpp 
b/clang/lib/AST/Interp/Compiler.cpp
index e1fa0eb1eacb3..ada22b569b2b0 100644
--- a/clang/lib/AST/Interp/Compiler.cpp
+++ b/clang/lib/AST/Interp/Compiler.cpp
@@ -4003,6 +4003,13 @@ bool Compiler::VisitCallExpr(const CallExpr *E) 
{
 } else if (!this->visit(MC->getImplicitObjectArgument())) {
   return false;
 }
+  } else if (!FuncDecl) {
+const Expr *Callee = E->getCallee();
+CalleeOffset = this->allocateLocalPrimitive(Callee, PT_FnPtr, true, false);
+if (!this->visit(Callee))
+  return false;
+if (!this->emitSetLocal(PT_FnPtr, *CalleeOffset, E))
+  return false;
   }
 
   llvm::BitVector NonNullArgs = collectNonNullArgs(FuncDecl, Args);
@@ -4071,22 +4078,19 @@ bool Compiler::VisitCallExpr(const CallExpr 
*E) {
 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
   ArgSize += align(primSize(classify(E->getArg(I)).value_or(PT_Ptr)));
 
-// Get the callee, either from a member pointer saved in CalleeOffset,
-// or by just visiting the Callee expr.
-if (CalleeOffset) {
+// Get the callee, either from a member pointer or function pointer saved 
in
+// CalleeOffset.
+if (isa(E) && CalleeOffset) {
   if (!this->emitGetLocal(PT_MemberPtr, *CalleeOffset, E))
 return false;
   if (!this->emitGetMemberPtrDecl(E))
 return false;
-  if (!this->emitCallPtr(ArgSize, E, E))
-return false;
 } else {
-  if (!this->visit(E->getCallee()))
-return false;
-
-  if (!this->emitCallPtr(ArgSize, E, E))
+  if (!this->emitGetLocal(PT_FnPtr, *CalleeOffset, E))
 return false;
 }
+if (!this->emitCallPtr(ArgSize, E, E))
+  return false;
   }
 
   // Cleanup for discarded return values.
diff --git a/clang/test/AST/Interp/eval-order.cpp 
b/clang/test/AST/Interp/eval-order.cpp
index 77f50831f4f47..d9cfd0b4642fa 100644
--- a/clang/test/AST/Interp/eval-order.cpp
+++ b/clang/test/AST/Interp/eval-order.cpp
@@ -45,7 +45,7 @@ namespace EvalOrder {
 }
 template  constexpr T &&b(T &&v) {
   if (!done_a)
-throw "wrong"; // expected-note 5{{not valid}}
+throw "wrong"; // expected-note 4{{not valid}}
   done_b = true;
   return (T &&)v;
 }
@@ -75,8 +75,7 @@ namespace EvalOrder {
   SEQ(A(&ud)->*B(&UserDefined::n));
 
   // Rule 4: a(b1, b2, b3)
-  SEQ(A(f)(B(1), B(2), B(3))); // expected-error {{not an integral constant 
expression}} FIXME \
-   // expected-note 2{{in call to}}
+  SEQ(A(f)(B(1), B(2), B(3)));
 
   // Rule 5: b = a, b @= a
   SEQ(B(lvalue().get()) = A(0)); // expected-error {{not an integral 
constant expression}} FIXME \

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


[clang] [clang][Interp] Fix function pointer callexpr eval order (PR #101821)

2024-08-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

We need to evaluate the callee before the arguments.

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


2 Files Affected:

- (modified) clang/lib/AST/Interp/Compiler.cpp (+13-9) 
- (modified) clang/test/AST/Interp/eval-order.cpp (+2-3) 


``diff
diff --git a/clang/lib/AST/Interp/Compiler.cpp 
b/clang/lib/AST/Interp/Compiler.cpp
index e1fa0eb1eacb3..ada22b569b2b0 100644
--- a/clang/lib/AST/Interp/Compiler.cpp
+++ b/clang/lib/AST/Interp/Compiler.cpp
@@ -4003,6 +4003,13 @@ bool Compiler::VisitCallExpr(const CallExpr *E) 
{
 } else if (!this->visit(MC->getImplicitObjectArgument())) {
   return false;
 }
+  } else if (!FuncDecl) {
+const Expr *Callee = E->getCallee();
+CalleeOffset = this->allocateLocalPrimitive(Callee, PT_FnPtr, true, false);
+if (!this->visit(Callee))
+  return false;
+if (!this->emitSetLocal(PT_FnPtr, *CalleeOffset, E))
+  return false;
   }
 
   llvm::BitVector NonNullArgs = collectNonNullArgs(FuncDecl, Args);
@@ -4071,22 +4078,19 @@ bool Compiler::VisitCallExpr(const CallExpr 
*E) {
 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
   ArgSize += align(primSize(classify(E->getArg(I)).value_or(PT_Ptr)));
 
-// Get the callee, either from a member pointer saved in CalleeOffset,
-// or by just visiting the Callee expr.
-if (CalleeOffset) {
+// Get the callee, either from a member pointer or function pointer saved 
in
+// CalleeOffset.
+if (isa(E) && CalleeOffset) {
   if (!this->emitGetLocal(PT_MemberPtr, *CalleeOffset, E))
 return false;
   if (!this->emitGetMemberPtrDecl(E))
 return false;
-  if (!this->emitCallPtr(ArgSize, E, E))
-return false;
 } else {
-  if (!this->visit(E->getCallee()))
-return false;
-
-  if (!this->emitCallPtr(ArgSize, E, E))
+  if (!this->emitGetLocal(PT_FnPtr, *CalleeOffset, E))
 return false;
 }
+if (!this->emitCallPtr(ArgSize, E, E))
+  return false;
   }
 
   // Cleanup for discarded return values.
diff --git a/clang/test/AST/Interp/eval-order.cpp 
b/clang/test/AST/Interp/eval-order.cpp
index 77f50831f4f47..d9cfd0b4642fa 100644
--- a/clang/test/AST/Interp/eval-order.cpp
+++ b/clang/test/AST/Interp/eval-order.cpp
@@ -45,7 +45,7 @@ namespace EvalOrder {
 }
 template  constexpr T &&b(T &&v) {
   if (!done_a)
-throw "wrong"; // expected-note 5{{not valid}}
+throw "wrong"; // expected-note 4{{not valid}}
   done_b = true;
   return (T &&)v;
 }
@@ -75,8 +75,7 @@ namespace EvalOrder {
   SEQ(A(&ud)->*B(&UserDefined::n));
 
   // Rule 4: a(b1, b2, b3)
-  SEQ(A(f)(B(1), B(2), B(3))); // expected-error {{not an integral constant 
expression}} FIXME \
-   // expected-note 2{{in call to}}
+  SEQ(A(f)(B(1), B(2), B(3)));
 
   // Rule 5: b = a, b @= a
   SEQ(B(lvalue().get()) = A(0)); // expected-error {{not an integral 
constant expression}} FIXME \

``




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


[clang] [clang][ASTImporter] support import return with UnaryTransformType (PR #101517)

2024-08-03 Thread Balázs Kéri via cfe-commits

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


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


[clang] 2bae7ae - [libclang] Fix symbol version of `getBinaryOpcode` functions (#101820)

2024-08-03 Thread via cfe-commits

Author: Jannick Kremer
Date: 2024-08-03T15:56:54+02:00
New Revision: 2bae7aeab42062e61d6f9d6458660d4a5646f7af

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

LOG: [libclang] Fix symbol version of `getBinaryOpcode` functions (#101820)

#98489 resurrected an [old patch](https://reviews.llvm.org/D10833) that
was adding new libclang functions. That PR got merged with old `LLVM_13`
symbol versions for new functions. This patch fixes this oversight.

Added: 


Modified: 
clang/tools/libclang/libclang.map

Removed: 




diff  --git a/clang/tools/libclang/libclang.map 
b/clang/tools/libclang/libclang.map
index 91c329b5765d4..371fe512ce71c 100644
--- a/clang/tools/libclang/libclang.map
+++ b/clang/tools/libclang/libclang.map
@@ -54,8 +54,6 @@ LLVM_13 {
 clang_Cursor_Evaluate;
 clang_Cursor_getArgument;
 clang_Cursor_getBriefCommentText;
-clang_Cursor_getBinaryOpcode;
-clang_Cursor_getBinaryOpcodeStr;
 clang_Cursor_getCXXManglings;
 clang_Cursor_getCommentRange;
 clang_Cursor_getMangling;
@@ -430,6 +428,12 @@ LLVM_17 {
 clang_getCursorUnaryOperatorKind;
 };
 
+LLVM_19 {
+  global:
+clang_Cursor_getBinaryOpcode;
+clang_Cursor_getBinaryOpcodeStr;
+};
+
 # Example of how to add a new symbol version entry.  If you do add a new symbol
 # version, please update the example to depend on the version you added.
 # LLVM_X {



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


[clang] [libclang] Fix symbol version of `getBinaryOpcode` functions (PR #101820)

2024-08-03 Thread Jannick Kremer via cfe-commits

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


[clang] [libclang] Fix symbol version of `getBinaryOpcode` functions (PR #101820)

2024-08-03 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

/cherry-pick 2bae7aeab42062e61d6f9d6458660d4a5646f7af

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


[clang] [libclang] Fix symbol version of `getBinaryOpcode` functions (PR #101820)

2024-08-03 Thread via cfe-commits

llvmbot wrote:

/pull-request llvm/llvm-project#101824

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


[clang] [llvm] [X86][AVX10.2] Support YMM rounding new instructions (PR #101825)

2024-08-03 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-backend-x86

@llvm/pr-subscribers-clang-codegen

Author: Phoebe Wang (phoebewang)


Changes

Ref.: https://cdrdv2.intel.com/v1/dl/getContent/828965

---

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


17 Files Affected:

- (modified) clang/include/clang/Basic/BuiltinsX86.def (+120) 
- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+120) 
- (modified) clang/lib/Headers/avx10_2niintrin.h (+1623) 
- (modified) clang/lib/Sema/SemaX86.cpp (+136) 
- (modified) clang/test/CodeGen/X86/avx10_2ni-builtins.c (+2344) 
- (modified) llvm/include/llvm/IR/IntrinsicsX86.td (+436) 
- (modified) llvm/lib/Target/X86/Disassembler/X86Disassembler.cpp (+1-1) 
- (modified) llvm/lib/Target/X86/X86InstrAVX10.td (+275-1) 
- (modified) llvm/lib/Target/X86/X86InstrAVX512.td (+4-4) 
- (modified) llvm/lib/Target/X86/X86InstrFMA3Info.cpp (+6-3) 
- (modified) llvm/lib/Target/X86/X86IntrinsicsInfo.h (+176) 
- (modified) llvm/test/CodeGen/X86/avx10_2ni-intrinsics.ll (+4253) 
- (modified) llvm/test/MC/Disassembler/X86/avx10_2ni-32.txt (+1740) 
- (modified) llvm/test/MC/Disassembler/X86/avx10_2ni-64.txt (+1740) 
- (modified) llvm/test/MC/X86/avx10_2ni-32-intel.s (+1740) 
- (modified) llvm/test/MC/X86/avx10_2ni-64-att.s (+1740) 
- (modified) llvm/utils/TableGen/X86DisassemblerTables.cpp (+3-3) 


``diff
diff --git a/clang/include/clang/Basic/BuiltinsX86.def 
b/clang/include/clang/Basic/BuiltinsX86.def
index f028711a807c0..b117c6d6d9340 100644
--- a/clang/include/clang/Basic/BuiltinsX86.def
+++ b/clang/include/clang/Basic/BuiltinsX86.def
@@ -1966,6 +1966,126 @@ TARGET_BUILTIN(__builtin_ia32_mpsadbw512, 
"V32sV64cV64cIc", "ncV:512:", "avx10.2
 TARGET_BUILTIN(__builtin_ia32_vaddpd256_round, "V4dV4dV4dIi", "nV:256:", 
"avx10.2-256")
 TARGET_BUILTIN(__builtin_ia32_vaddph256_round, "V16xV16xV16xIi", "nV:256:", 
"avx10.2-256")
 TARGET_BUILTIN(__builtin_ia32_vaddps256_round, "V8fV8fV8fIi", "nV:256:", 
"avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcmppd256_round_mask, "UcV4dV4dIiUcIi", 
"nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcmpph256_round_mask, "UsV16xV16xIiUsIi", 
"nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcmpps256_round_mask, "UcV8fV8fIiUcIi", 
"nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvtdq2ph256_round_mask, "V8xV8iV8xUcIi", 
"nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvtdq2ps256_round_mask, "V8fV8iV8fUcIi", 
"nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvtpd2dq256_round_mask, "V4iV4dV4iUcIi", 
"nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvtpd2ph256_round_mask, "V8xV4dV8xUcIi", 
"nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvtpd2ps256_round_mask, "V4fV4dV4fUcIi", 
"nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvtpd2qq256_round_mask, "V4LLiV4dV4LLiUcIi", 
"nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvtpd2udq256_round_mask, "V4UiV4dV4UiUcIi", 
"nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvtpd2uqq256_round_mask, "V4ULLiV4dV4ULLiUcIi", 
"nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvtph2dq256_round_mask, "V8iV8xV8iUcIi", 
"nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvtph2pd256_round_mask, "V4dV8xV4dUcIi", 
"nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvtph2psx256_round_mask, "V8fV8xV8fUcIi", 
"nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvtph2qq256_round_mask, "V4LLiV8xV4LLiUcIi", 
"nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvtph2udq256_round_mask, "V8UiV8xV8UiUcIi", 
"nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvtph2uqq256_round_mask, "V4ULLiV8xV4ULLiUcIi", 
"nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvtph2uw256_round_mask, "V16UsV16xV16UsUsIi", 
"nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvtph2w256_round_mask, "V16sV16xV16sUsIi", 
"nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvtps2dq256_round_mask, "V8iV8fV8iUcIi", 
"nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvtps2pd256_round_mask, "V4dV4fV4dUcIi", 
"nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvtps2phx256_round_mask, "V8xV8fV8xUcIi", 
"nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvtps2qq256_round_mask, "V4LLiV4fV4LLiUcIi", 
"nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvtps2udq256_round_mask, "V8UiV8fV8UiUcIi", 
"nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvtps2uqq256_round_mask, "V4ULLiV4fV4ULLiUcIi", 
"nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvtqq2pd256_round_mask, "V4dV4LLiV4dUcIi", 
"nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvtqq2ph256_round_mask, "V8xV4LLiV8xUcIi", 
"nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvtqq2ps256_round_mask, "V4fV4LLiV4fUcIi", 
"nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvttpd2dq256_round_mask, "V4iV4dV4iUcIi", 
"nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__bui

[clang] [llvm] [X86][AVX10.2] Support YMM rounding new instructions (PR #101825)

2024-08-03 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 79f7630e28589364ccf989a4a838f5dd74ce260a 
520379066196ffc922c7d571399052a2eb7f869c --extensions cpp,c,h -- 
clang/lib/CodeGen/CGBuiltin.cpp clang/lib/Headers/avx10_2niintrin.h 
clang/lib/Sema/SemaX86.cpp clang/test/CodeGen/X86/avx10_2ni-builtins.c 
llvm/lib/Target/X86/Disassembler/X86Disassembler.cpp 
llvm/lib/Target/X86/X86InstrFMA3Info.cpp 
llvm/lib/Target/X86/X86IntrinsicsInfo.h 
llvm/utils/TableGen/X86DisassemblerTables.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Headers/avx10_2niintrin.h 
b/clang/lib/Headers/avx10_2niintrin.h
index 42b24d2b5b..830028650f 100644
--- a/clang/lib/Headers/avx10_2niintrin.h
+++ b/clang/lib/Headers/avx10_2niintrin.h
@@ -81,7 +81,7 @@
 
 #define _mm256_cmp_round_pd_mask(A, B, P, R)   
\
   ((__mmask8)__builtin_ia32_vcmppd256_round_mask(  
\
-  (__v4df)(__m256d)(A), (__v4df)(__m256d)(B), (int)(P), (__mmask8)-1,  
\
+  (__v4df)(__m256d)(A), (__v4df)(__m256d)(B), (int)(P), (__mmask8) - 1,
\
   (int)(R)))
 
 #define _mm256_mask_cmp_round_pd_mask(U, A, B, P, R)   
\
@@ -91,7 +91,7 @@
 
 #define _mm256_cmp_round_ph_mask(A, B, P, R)   
\
   ((__mmask16)__builtin_ia32_vcmpph256_round_mask( 
\
-  (__v16hf)(__m256h)(A), (__v16hf)(__m256h)(B), (int)(P), (__mmask16)-1,   
\
+  (__v16hf)(__m256h)(A), (__v16hf)(__m256h)(B), (int)(P), (__mmask16) - 1, 
\
   (int)(R)))
 
 #define _mm256_mask_cmp_round_ph_mask(U, A, B, P, R)   
\
@@ -101,7 +101,7 @@
 
 #define _mm256_cmp_round_ps_mask(A, B, P, R)   
\
   ((__mmask8)__builtin_ia32_vcmpps256_round_mask(  
\
-  (__v8sf)(__m256)(A), (__v8sf)(__m256)(B), (int)(P), (__mmask8)-1,
\
+  (__v8sf)(__m256)(A), (__v8sf)(__m256)(B), (int)(P), (__mmask8) - 1,  
\
   (int)(R)))
 
 #define _mm256_mask_cmp_round_ps_mask(U, A, B, P, R)   
\
@@ -124,7 +124,7 @@
 #define _mm256_cvt_roundepi32_ps(A, R) 
\
   ((__m256)__builtin_ia32_vcvtdq2ps256_round_mask((__v8si)(__m256i)(A),
\
   (__v8sf)_mm256_setzero_ps(), 
\
-  (__mmask8)-1, (int)(R)))
+  (__mmask8) - 1, (int)(R)))
 
 #define _mm256_mask_cvt_roundepi32_ps(W, U, A, R)  
\
   ((__m256)__builtin_ia32_vcvtdq2ps256_round_mask( 
\
@@ -137,7 +137,7 @@
 
 #define _mm256_cvt_roundpd_epi32(A, R) 
\
   ((__m128i)__builtin_ia32_vcvtpd2dq256_round_mask(
\
-  (__v4df)(__m256d)(A), (__v4si)_mm_setzero_si128(), (__mmask8)-1, 
\
+  (__v4df)(__m256d)(A), (__v4si)_mm_setzero_si128(), (__mmask8) - 1,   
\
   (int)(R)))
 
 #define _mm256_mask_cvt_roundpd_epi32(W, U, A, R)  
\
@@ -162,8 +162,9 @@
   (__v4df)(A), (__v8hf)_mm_setzero_ph(), (__mmask8)(U), (int)(R)))
 
 #define _mm256_cvt_roundpd_ps(A, R)
\
-  ((__m128)__builtin_ia32_vcvtpd2ps256_round_mask( 
\
-  (__v4df)(__m256d)(A), (__v4sf)_mm_setzero_ps(), (__mmask8)-1, (int)(R)))
+  ((__m128)__builtin_ia32_vcvtpd2ps256_round_mask((__v4df)(__m256d)(A),
\
+  (__v4sf)_mm_setzero_ps(),
\
+  (__mmask8) - 1, (int)(R)))
 
 #define _mm256_mask_cvt_roundpd_ps(W, U, A, R) 
\
   ((__m128)__builtin_ia32_vcvtpd2ps256_round_mask( 
\
@@ -176,7 +177,7 @@
 
 #define _mm256_cvt_roundpd_epi64(A, R) 
\
   ((__m256i)__builtin_ia32_vcvtpd2qq256_round_mask(
\
-  (__v4df)(__m256d)(A), (__v4di)_mm256_setzero_si256(), (__mmask8)-1,  
\
+  (__v4df)(__m256d)(A), (__v4di)_mm256_setzero_si256(), (__mmask8) - 1,
\
   (int)(R)))
 
 #define _mm256_mask_cvt_roundpd_epi64(W, U, A, R)  
\
@@ -190,7 +191,7 @@
 
 #define _mm256_cvt_roundpd_epu32(A, R) 
\
   ((__m128i)__builtin_ia32_vcvtpd2udq256_round_mask(   
\
-  (__v4df)(__m256d)(A), (__v4su)_mm_setzero_si128(), (__mmask8)-1, 
\
+  (__v4df)(__m256d)(A), (__v4su)_mm_setzero_si128(), (__mmask8) - 1,   
\
   (int)(R)))
 
 #define _mm256_mask_cvt_roundpd_epu32(W, U, A, R)   

[clang] [llvm] [X86][AVX10.2] Support YMM rounding new instructions (PR #101825)

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

phoebewang wrote:

> ⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️
> 
> You can test this locally with the following command:
> View the diff from clang-format here.

The clang-format seems problematic, and isn't compatible with previous version. 
It looks like a bug to me.

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


[clang] [llvm] [X86][AVX10.2] Support YMM rounding new instructions (PR #101825)

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


@@ -785,9 +785,9 @@ void DisassemblerTables::emitModRMDecision(raw_ostream &o1, 
raw_ostream &o2,
 break;
   }
 
-  // We assume that the index can fit into uint16_t.
-  assert(sEntryNumber < 65536U &&
- "Index into ModRMDecision is too large for uint16_t!");
+  // We assume that the index can fit into uint32_t.
+  assert(sEntryNumber < -1U &&
+ "Index into ModRMDecision is too large for uint32_t!");

KanRobert wrote:

I suggest not using the tricky `-1`, it's not robust b/c the suffix `U` can 
represent unsigned long long 
(https://en.cppreference.com/w/cpp/language/integer_literal)

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


[clang] [llvm] [X86][AVX10.2] Support YMM rounding new instructions (PR #101825)

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


@@ -785,9 +785,9 @@ void DisassemblerTables::emitModRMDecision(raw_ostream &o1, 
raw_ostream &o2,
 break;
   }
 
-  // We assume that the index can fit into uint16_t.
-  assert(sEntryNumber < 65536U &&
- "Index into ModRMDecision is too large for uint16_t!");
+  // We assume that the index can fit into uint32_t.
+  assert(sEntryNumber < -1U &&
+ "Index into ModRMDecision is too large for uint32_t!");

phoebewang wrote:

`-1U` is wildly used in LLVM code base. I think the document means it can be 
automatically recognized as `LLU` with the range of constant value, instead of 
not to use it for small value. See https://godbolt.org/z/9W9srbYYM

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


[clang] f78d288 - [clang][Interp] Fix function pointer callexpr eval order (#101821)

2024-08-03 Thread via cfe-commits

Author: Timm Baeder
Date: 2024-08-03T16:56:37+02:00
New Revision: f78d288d9d77c66f8b3036c62bb55160f19ba9cd

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

LOG: [clang][Interp] Fix function pointer callexpr eval order (#101821)

We need to evaluate the callee before the arguments.

Added: 


Modified: 
clang/lib/AST/Interp/Compiler.cpp
clang/test/AST/Interp/eval-order.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Compiler.cpp 
b/clang/lib/AST/Interp/Compiler.cpp
index e1fa0eb1eacb3..ada22b569b2b0 100644
--- a/clang/lib/AST/Interp/Compiler.cpp
+++ b/clang/lib/AST/Interp/Compiler.cpp
@@ -4003,6 +4003,13 @@ bool Compiler::VisitCallExpr(const CallExpr *E) 
{
 } else if (!this->visit(MC->getImplicitObjectArgument())) {
   return false;
 }
+  } else if (!FuncDecl) {
+const Expr *Callee = E->getCallee();
+CalleeOffset = this->allocateLocalPrimitive(Callee, PT_FnPtr, true, false);
+if (!this->visit(Callee))
+  return false;
+if (!this->emitSetLocal(PT_FnPtr, *CalleeOffset, E))
+  return false;
   }
 
   llvm::BitVector NonNullArgs = collectNonNullArgs(FuncDecl, Args);
@@ -4071,22 +4078,19 @@ bool Compiler::VisitCallExpr(const CallExpr 
*E) {
 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
   ArgSize += align(primSize(classify(E->getArg(I)).value_or(PT_Ptr)));
 
-// Get the callee, either from a member pointer saved in CalleeOffset,
-// or by just visiting the Callee expr.
-if (CalleeOffset) {
+// Get the callee, either from a member pointer or function pointer saved 
in
+// CalleeOffset.
+if (isa(E) && CalleeOffset) {
   if (!this->emitGetLocal(PT_MemberPtr, *CalleeOffset, E))
 return false;
   if (!this->emitGetMemberPtrDecl(E))
 return false;
-  if (!this->emitCallPtr(ArgSize, E, E))
-return false;
 } else {
-  if (!this->visit(E->getCallee()))
-return false;
-
-  if (!this->emitCallPtr(ArgSize, E, E))
+  if (!this->emitGetLocal(PT_FnPtr, *CalleeOffset, E))
 return false;
 }
+if (!this->emitCallPtr(ArgSize, E, E))
+  return false;
   }
 
   // Cleanup for discarded return values.

diff  --git a/clang/test/AST/Interp/eval-order.cpp 
b/clang/test/AST/Interp/eval-order.cpp
index 77f50831f4f47..d9cfd0b4642fa 100644
--- a/clang/test/AST/Interp/eval-order.cpp
+++ b/clang/test/AST/Interp/eval-order.cpp
@@ -45,7 +45,7 @@ namespace EvalOrder {
 }
 template  constexpr T &&b(T &&v) {
   if (!done_a)
-throw "wrong"; // expected-note 5{{not valid}}
+throw "wrong"; // expected-note 4{{not valid}}
   done_b = true;
   return (T &&)v;
 }
@@ -75,8 +75,7 @@ namespace EvalOrder {
   SEQ(A(&ud)->*B(&UserDefined::n));
 
   // Rule 4: a(b1, b2, b3)
-  SEQ(A(f)(B(1), B(2), B(3))); // expected-error {{not an integral constant 
expression}} FIXME \
-   // expected-note 2{{in call to}}
+  SEQ(A(f)(B(1), B(2), B(3)));
 
   // Rule 5: b = a, b @= a
   SEQ(B(lvalue().get()) = A(0)); // expected-error {{not an integral 
constant expression}} FIXME \



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


[clang] [clang][Interp] Fix function pointer callexpr eval order (PR #101821)

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

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


[clang] [libclang] Fix symbol version of `getBinaryOpcode` functions (PR #101820)

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

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`clang-aarch64-sve-vla-2stage` running on `linaro-g3-04` while building `clang` 
at step 11 "build stage 2".

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

Here is the relevant piece of the build log for the reference:
```
Step 11 (build stage 2) failure: 'ninja' (failure)
...
[7747/8607] Building CXX object 
tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/HlfirIntrinsics.cpp.o
[7748/8607] Building CXX object 
tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/SymbolMap.cpp.o
[7749/8607] Building CXX object 
tools/flang/lib/Evaluate/CMakeFiles/FortranEvaluate.dir/tools.cpp.o
[7750/8607] Building CXX object 
tools/flang/lib/Parser/CMakeFiles/FortranParser.dir/Fortran-parsers.cpp.o
[7751/8607] Building CXX object 
tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/Coarray.cpp.o
[7752/8607] Building CXX object 
tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/check-namelist.cpp.o
[7753/8607] Building CXX object 
tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/check-allocate.cpp.o
[7754/8607] Building CXX object 
tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/definable.cpp.o
[7755/8607] Building CXX object 
tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/check-nullify.cpp.o
[7756/8607] Building CXX object 
tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/OpenMP/Clauses.cpp.o
FAILED: tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/OpenMP/Clauses.cpp.o 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/stage1.install/bin/clang++
 -DFLANG_INCLUDE_TESTS=1 -DFLANG_LITTLE_ENDIAN=1 -DGTEST_HAS_RTTI=0 -D_DEBUG 
-D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS 
-D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-I/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/stage2/tools/flang/lib/Lower
 -I/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/llvm/flang/lib/Lower 
-I/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/llvm/flang/include 
-I/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/stage2/tools/flang/include
 -I/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/stage2/include 
-I/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/llvm/llvm/include 
-isystem 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/llvm/llvm/../mlir/include
 -isystem 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/stage2/tools/mlir/include
 -isystem 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/stage2/tools/clang/include
 -isystem 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/llvm/llvm/../clang/include
 -mcpu=neoverse-512tvb -mllvm -scalable-vectorization=preferred -mllvm 
-treat-scalable-fixed-error-as-warning=false -fPIC -fno-semantic-interposition 
-fvisibility-inlines-hidden -Werror=date-time 
-Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter 
-Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic 
-Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough 
-Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor 
-Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wstring-conversion 
-Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color 
-ffunction-sections -fdata-sections -Wno-deprecated-copy -Wno-string-conversion 
-Wno-ctad-maybe-unsupported -Wno-unused-command-line-argument 
-Wstring-conversion   -Wcovered-switch-default -Wno-nested-anon-types 
-O3 -DNDEBUG  -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -std=c++17 -MD 
-MT tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/OpenMP/Clauses.cpp.o -MF 
tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/OpenMP/Clauses.cpp.o.d -o 
tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/OpenMP/Clauses.cpp.o -c 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/llvm/flang/lib/Lower/OpenMP/Clauses.cpp
Killed
[7757/8607] Building CXX object 
tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/check-if-stmt.cpp.o
[7758/8607] Building CXX object 
tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/check-select-type.cpp.o
[7759/8607] Building CXX object 
tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/data-to-inits.cpp.o
[7760/8607] Building CXX object 
tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/check-stop.cpp.o
[7761/8607] Building CXX object 
tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/check-deallocate.cpp.o
[7762/8607] Building CXX object 
tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/check-io.cpp.o
[7763/8607] Building CXX object 
tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/check-arithmeticif.cpp.o
[7764/8607] Building CXX object 
tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/OpenMP/ReductionProcessor.cpp.o
[7765/8607] Building CXX object 
tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/check-return.cpp.o
[7766/8607] Building CXX object 
tools/flang/lib/Semantics/CMakeFiles/FortranSemantic

[clang] [clang][Interp] Fix assignment eval order (PR #101833)

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

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

RHS first.

>From dc4740dd572eb71af1a7cd33e2c4cf5400d7d5af Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sat, 3 Aug 2024 17:24:15 +0200
Subject: [PATCH] [clang][Interp] Fix assignment eval order

RHS first.
---
 clang/lib/AST/Interp/Compiler.cpp| 16 
 clang/test/AST/Interp/eval-order.cpp |  5 ++---
 2 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/clang/lib/AST/Interp/Compiler.cpp 
b/clang/lib/AST/Interp/Compiler.cpp
index ada22b569b2b0..d9db1c788314c 100644
--- a/clang/lib/AST/Interp/Compiler.cpp
+++ b/clang/lib/AST/Interp/Compiler.cpp
@@ -733,8 +733,8 @@ bool Compiler::VisitBinaryOperator(const 
BinaryOperator *BO) {
   }
 
   // Typecheck the args.
-  std::optional LT = classify(LHS->getType());
-  std::optional RT = classify(RHS->getType());
+  std::optional LT = classify(LHS);
+  std::optional RT = classify(RHS);
   std::optional T = classify(BO->getType());
 
   // Special case for C++'s three-way/spaceship operator <=>, which
@@ -769,8 +769,16 @@ bool Compiler::VisitBinaryOperator(const 
BinaryOperator *BO) {
   return this->VisitPointerArithBinOp(BO);
   }
 
-  if (!visit(LHS) || !visit(RHS))
-return false;
+  // Assignmentes require us to evalute the RHS first.
+  if (BO->getOpcode() == BO_Assign) {
+if (!visit(RHS) || !visit(LHS))
+  return false;
+if (!this->emitFlip(*LT, *RT, BO))
+  return false;
+  } else {
+if (!visit(LHS) || !visit(RHS))
+  return false;
+  }
 
   // For languages such as C, cast the result of one
   // of our comparision opcodes to T (which is usually int).
diff --git a/clang/test/AST/Interp/eval-order.cpp 
b/clang/test/AST/Interp/eval-order.cpp
index d9cfd0b4642fa..c78c5061a08f2 100644
--- a/clang/test/AST/Interp/eval-order.cpp
+++ b/clang/test/AST/Interp/eval-order.cpp
@@ -45,7 +45,7 @@ namespace EvalOrder {
 }
 template  constexpr T &&b(T &&v) {
   if (!done_a)
-throw "wrong"; // expected-note 4{{not valid}}
+throw "wrong"; // expected-note 3{{not valid}}
   done_b = true;
   return (T &&)v;
 }
@@ -78,8 +78,7 @@ namespace EvalOrder {
   SEQ(A(f)(B(1), B(2), B(3)));
 
   // Rule 5: b = a, b @= a
-  SEQ(B(lvalue().get()) = A(0)); // expected-error {{not an integral 
constant expression}} FIXME \
-  // expected-note 2{{in call to}}
+  SEQ(B(lvalue().get()) = A(0));
   SEQ(B(lvalue().get()) = A(ud)); // expected-error {{not an 
integral constant expression}} FIXME \
// expected-note 2{{in call to}}
   SEQ(B(lvalue().get()) += A(0));

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


[clang] [clang][Interp] Fix assignment eval order (PR #101833)

2024-08-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

RHS first.

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


2 Files Affected:

- (modified) clang/lib/AST/Interp/Compiler.cpp (+12-4) 
- (modified) clang/test/AST/Interp/eval-order.cpp (+2-3) 


``diff
diff --git a/clang/lib/AST/Interp/Compiler.cpp 
b/clang/lib/AST/Interp/Compiler.cpp
index ada22b569b2b0..d9db1c788314c 100644
--- a/clang/lib/AST/Interp/Compiler.cpp
+++ b/clang/lib/AST/Interp/Compiler.cpp
@@ -733,8 +733,8 @@ bool Compiler::VisitBinaryOperator(const 
BinaryOperator *BO) {
   }
 
   // Typecheck the args.
-  std::optional LT = classify(LHS->getType());
-  std::optional RT = classify(RHS->getType());
+  std::optional LT = classify(LHS);
+  std::optional RT = classify(RHS);
   std::optional T = classify(BO->getType());
 
   // Special case for C++'s three-way/spaceship operator <=>, which
@@ -769,8 +769,16 @@ bool Compiler::VisitBinaryOperator(const 
BinaryOperator *BO) {
   return this->VisitPointerArithBinOp(BO);
   }
 
-  if (!visit(LHS) || !visit(RHS))
-return false;
+  // Assignmentes require us to evalute the RHS first.
+  if (BO->getOpcode() == BO_Assign) {
+if (!visit(RHS) || !visit(LHS))
+  return false;
+if (!this->emitFlip(*LT, *RT, BO))
+  return false;
+  } else {
+if (!visit(LHS) || !visit(RHS))
+  return false;
+  }
 
   // For languages such as C, cast the result of one
   // of our comparision opcodes to T (which is usually int).
diff --git a/clang/test/AST/Interp/eval-order.cpp 
b/clang/test/AST/Interp/eval-order.cpp
index d9cfd0b4642fa..c78c5061a08f2 100644
--- a/clang/test/AST/Interp/eval-order.cpp
+++ b/clang/test/AST/Interp/eval-order.cpp
@@ -45,7 +45,7 @@ namespace EvalOrder {
 }
 template  constexpr T &&b(T &&v) {
   if (!done_a)
-throw "wrong"; // expected-note 4{{not valid}}
+throw "wrong"; // expected-note 3{{not valid}}
   done_b = true;
   return (T &&)v;
 }
@@ -78,8 +78,7 @@ namespace EvalOrder {
   SEQ(A(f)(B(1), B(2), B(3)));
 
   // Rule 5: b = a, b @= a
-  SEQ(B(lvalue().get()) = A(0)); // expected-error {{not an integral 
constant expression}} FIXME \
-  // expected-note 2{{in call to}}
+  SEQ(B(lvalue().get()) = A(0));
   SEQ(B(lvalue().get()) = A(ud)); // expected-error {{not an 
integral constant expression}} FIXME \
// expected-note 2{{in call to}}
   SEQ(B(lvalue().get()) += A(0));

``




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


[clang] [clang][Interp] Fix assignment eval order (PR #101834)

2024-08-03 Thread via cfe-commits

https://github.com/cIamor created 
https://github.com/llvm/llvm-project/pull/101834

RHS first

>From ddb379384065566c7b89de29f8084b172d885f52 Mon Sep 17 00:00:00 2001
From: layta 
Date: Sat, 3 Aug 2024 16:28:10 +0100
Subject: [PATCH] [clang][Interp] Fix assignment eval order

RHS first
---
 clang/lib/AST/Interp/Compiler.cpp | 16 
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/clang/lib/AST/Interp/Compiler.cpp 
b/clang/lib/AST/Interp/Compiler.cpp
index ada22b569b2b0..d9db1c788314c 100644
--- a/clang/lib/AST/Interp/Compiler.cpp
+++ b/clang/lib/AST/Interp/Compiler.cpp
@@ -733,8 +733,8 @@ bool Compiler::VisitBinaryOperator(const 
BinaryOperator *BO) {
   }
 
   // Typecheck the args.
-  std::optional LT = classify(LHS->getType());
-  std::optional RT = classify(RHS->getType());
+  std::optional LT = classify(LHS);
+  std::optional RT = classify(RHS);
   std::optional T = classify(BO->getType());
 
   // Special case for C++'s three-way/spaceship operator <=>, which
@@ -769,8 +769,16 @@ bool Compiler::VisitBinaryOperator(const 
BinaryOperator *BO) {
   return this->VisitPointerArithBinOp(BO);
   }
 
-  if (!visit(LHS) || !visit(RHS))
-return false;
+  // Assignmentes require us to evalute the RHS first.
+  if (BO->getOpcode() == BO_Assign) {
+if (!visit(RHS) || !visit(LHS))
+  return false;
+if (!this->emitFlip(*LT, *RT, BO))
+  return false;
+  } else {
+if (!visit(LHS) || !visit(RHS))
+  return false;
+  }
 
   // For languages such as C, cast the result of one
   // of our comparision opcodes to T (which is usually int).

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


[clang] [libclang] Fix symbol version of `getBinaryOpcode` functions (PR #101820)

2024-08-03 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

The failure is not related to this PR
```
[7756/8607] Building CXX object 
tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/OpenMP/Clauses.cpp.o
FAILED: tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/OpenMP/Clauses.cpp.o 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/stage1.install/bin/clang++
 -DFLANG_INCLUDE_TESTS=1 -DFLANG_LITTLE_ENDIAN=1 -DGTEST_HAS_RTTI=0 -D_DEBUG 
-D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS 
-D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-I/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/stage2/tools/flang/lib/Lower
 -I/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/llvm/flang/lib/Lower 
-I/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/llvm/flang/include 
-I/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/stage2/tools/flang/include
 -I/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/stage2/include 
-I/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/llvm/llvm/include 
-isystem 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/llvm/llvm/../mlir/include
 -isystem 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/stage2/tools/mlir/include
 -isystem 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/stage2/tools/clang/include
 -isystem 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/llvm/llvm/../clang/include
 -mcpu=neoverse-512tvb -mllvm -scalable-vectorization=preferred -mllvm 
-treat-scalable-fixed-error-as-warning=false -fPIC -fno-semantic-interposition 
-fvisibility-inlines-hidden -Werror=date-time 
-Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter 
-Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic 
-Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough 
-Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor 
-Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wstring-conversion 
-Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color 
-ffunction-sections -fdata-sections -Wno-deprecated-copy -Wno-string-conversion 
-Wno-ctad-maybe-unsupported -Wno-unused-command-line-argument 
-Wstring-conversion   -Wcovered-switch-default -Wno-nested-anon-types 
-O3 -DNDEBUG  -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -std=c++17 -MD 
-MT tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/OpenMP/Clauses.cpp.o -MF 
tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/OpenMP/Clauses.cpp.o.d -o 
tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/OpenMP/Clauses.cpp.o -c 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/llvm/flang/lib/Lower/OpenMP/Clauses.cpp
Killed
```

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


[clang] [clang][Interp] Fix assignment eval order (PR #101834)

2024-08-03 Thread via cfe-commits

github-actions[bot] wrote:



Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from 
other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

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


[clang] [clang] Update argument checking tablegen code to use a 'full' name (PR #99993)

2024-08-03 Thread Mike Rice via cfe-commits

mikerice1969 wrote:

Proposed fix for compile-time regression 
https://github.com/llvm/llvm-project/pull/101768

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


[clang] [clang][Interp] Fix assignment eval order (PR #101834)

2024-08-03 Thread via cfe-commits

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


[clang] [clang][Interp] Fix assignment eval order (PR #101834)

2024-08-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: layta (cIamor)


Changes

RHS first

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


1 Files Affected:

- (modified) clang/lib/AST/Interp/Compiler.cpp (+12-4) 


``diff
diff --git a/clang/lib/AST/Interp/Compiler.cpp 
b/clang/lib/AST/Interp/Compiler.cpp
index ada22b569b2b0..d9db1c788314c 100644
--- a/clang/lib/AST/Interp/Compiler.cpp
+++ b/clang/lib/AST/Interp/Compiler.cpp
@@ -733,8 +733,8 @@ bool Compiler::VisitBinaryOperator(const 
BinaryOperator *BO) {
   }
 
   // Typecheck the args.
-  std::optional LT = classify(LHS->getType());
-  std::optional RT = classify(RHS->getType());
+  std::optional LT = classify(LHS);
+  std::optional RT = classify(RHS);
   std::optional T = classify(BO->getType());
 
   // Special case for C++'s three-way/spaceship operator <=>, which
@@ -769,8 +769,16 @@ bool Compiler::VisitBinaryOperator(const 
BinaryOperator *BO) {
   return this->VisitPointerArithBinOp(BO);
   }
 
-  if (!visit(LHS) || !visit(RHS))
-return false;
+  // Assignmentes require us to evalute the RHS first.
+  if (BO->getOpcode() == BO_Assign) {
+if (!visit(RHS) || !visit(LHS))
+  return false;
+if (!this->emitFlip(*LT, *RT, BO))
+  return false;
+  } else {
+if (!visit(LHS) || !visit(RHS))
+  return false;
+  }
 
   // For languages such as C, cast the result of one
   // of our comparision opcodes to T (which is usually int).

``




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


[clang] [libclang] Fix symbol version of `getBinaryOpcode` functions (PR #101820)

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

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`clang-aarch64-sve-vls-2stage` running on `linaro-g3-03` while building `clang` 
at step 11 "build stage 2".

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

Here is the relevant piece of the build log for the reference:
```
Step 11 (build stage 2) failure: 'ninja' (failure)
...
[7780/8607] Building CXX object 
tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/Coarray.cpp.o
[7781/8607] Building CXX object 
tools/flang/lib/Parser/CMakeFiles/FortranParser.dir/Fortran-parsers.cpp.o
[7782/8607] Building CXX object 
tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/Runtime.cpp.o
[7783/8607] Building CXX object 
tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/check-data.cpp.o
[7784/8607] Building CXX object 
tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/OpenMP/ReductionProcessor.cpp.o
[7785/8607] Building CXX object 
tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/check-acc-structure.cpp.o
[7786/8607] Building CXX object 
tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/CustomIntrinsicCall.cpp.o
[7787/8607] Building CXX object 
tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/check-case.cpp.o
[7788/8607] Building CXX object 
tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/check-call.cpp.o
[7789/8607] Building CXX object 
tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/OpenMP/Clauses.cpp.o
FAILED: tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/OpenMP/Clauses.cpp.o 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls-2stage/stage1.install/bin/clang++
 -DFLANG_INCLUDE_TESTS=1 -DFLANG_LITTLE_ENDIAN=1 -DGTEST_HAS_RTTI=0 -D_DEBUG 
-D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS 
-D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-I/home/tcwg-buildbot/worker/clang-aarch64-sve-vls-2stage/stage2/tools/flang/lib/Lower
 -I/home/tcwg-buildbot/worker/clang-aarch64-sve-vls-2stage/llvm/flang/lib/Lower 
-I/home/tcwg-buildbot/worker/clang-aarch64-sve-vls-2stage/llvm/flang/include 
-I/home/tcwg-buildbot/worker/clang-aarch64-sve-vls-2stage/stage2/tools/flang/include
 -I/home/tcwg-buildbot/worker/clang-aarch64-sve-vls-2stage/stage2/include 
-I/home/tcwg-buildbot/worker/clang-aarch64-sve-vls-2stage/llvm/llvm/include 
-isystem 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls-2stage/llvm/llvm/../mlir/include
 -isystem 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls-2stage/stage2/tools/mlir/include
 -isystem 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls-2stage/stage2/tools/clang/include
 -isystem 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls-2stage/llvm/llvm/../clang/include
 -mcpu=neoverse-512tvb -msve-vector-bits=256 -mllvm 
-treat-scalable-fixed-error-as-warning=false -fPIC -fno-semantic-interposition 
-fvisibility-inlines-hidden -Werror=date-time 
-Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter 
-Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic 
-Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough 
-Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor 
-Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wstring-conversion 
-Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color 
-ffunction-sections -fdata-sections -Wno-deprecated-copy -Wno-string-conversion 
-Wno-ctad-maybe-unsupported -Wno-unused-command-line-argument 
-Wstring-conversion   -Wcovered-switch-default -Wno-nested-anon-types 
-O3 -DNDEBUG  -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -std=c++17 -MD 
-MT tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/OpenMP/Clauses.cpp.o -MF 
tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/OpenMP/Clauses.cpp.o.d -o 
tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/OpenMP/Clauses.cpp.o -c 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls-2stage/llvm/flang/lib/Lower/OpenMP/Clauses.cpp
Killed
[7790/8607] Building CXX object 
tools/flang/lib/Evaluate/CMakeFiles/FortranEvaluate.dir/tools.cpp.o
[7791/8607] Building CXX object 
tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/check-cuda.cpp.o
[7792/8607] Building CXX object 
tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/DumpEvaluateExpr.cpp.o
[7793/8607] Building CXX object 
tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/ConvertProcedureDesignator.cpp.o
[7794/8607] Building CXX object 
tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/OpenMP/Utils.cpp.o
[7795/8607] Building CXX object 
tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/check-coarray.cpp.o
[7796/8607] Building CXX object 
tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/HostAssociations.cpp.o
[7797/8607] Building CXX object 
tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/ConvertArrayConstructor.cpp.o
[7798/8607] Building CXX object 
tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/Bridge.cpp.o
[7799/8607] Building CXX object 
tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/IterationSpace.cpp.o
[7800/8607] Building CXX object 

[clang] [CodeGen][NFCI] Don't re-implement parts of ASTContext::getIntWidth (PR #101765)

2024-08-03 Thread Alexander Richardson via cfe-commits

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


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


[clang] [clang][Interp] Fix function pointer callexpr eval order (PR #101821)

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

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `clang-aarch64-sve-vls` 
running on `linaro-g3-02` while building `clang` at step 7 "ninja check 1".

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

Here is the relevant piece of the build log for the reference:
```
Step 7 (ninja check 1) failure: stage 1 checked (failure)
 TEST 'lit :: googletest-timeout.py' FAILED 

Exit Code: 1

Command Output (stdout):
--
# RUN: at line 9
not env -u FILECHECK_OPTS "/usr/bin/python3.8" 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/llvm/llvm/utils/lit/lit.py -j1 
--order=lexical -v Inputs/googletest-timeout--param 
gtest_filter=InfiniteLoopSubTest --timeout=1 > 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/utils/lit/tests/Output/googletest-timeout.py.tmp.cmd.out
# executed command: not env -u FILECHECK_OPTS /usr/bin/python3.8 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/llvm/llvm/utils/lit/lit.py -j1 
--order=lexical -v Inputs/googletest-timeout --param 
gtest_filter=InfiniteLoopSubTest --timeout=1
# .---command stderr
# | lit.py: 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/llvm/llvm/utils/lit/lit/main.py:72:
 note: The test suite configuration requested an individual test timeout of 0 
seconds but a timeout of 1 seconds was requested on the command line. Forcing 
timeout to be 1 seconds.
# `-
# RUN: at line 11
FileCheck --check-prefix=CHECK-INF < 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/utils/lit/tests/Output/googletest-timeout.py.tmp.cmd.out
 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/utils/lit/tests/googletest-timeout.py
# executed command: FileCheck --check-prefix=CHECK-INF 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/utils/lit/tests/googletest-timeout.py
# RUN: at line 16
not env -u FILECHECK_OPTS "/usr/bin/python3.8" 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/llvm/llvm/utils/lit/lit.py -j1 
--order=lexical -v Inputs/googletest-timeout   --param 
gtest_filter=InfiniteLoopSubTest  --param set_timeout=1   > 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/utils/lit/tests/Output/googletest-timeout.py.tmp.cfgset.out
# executed command: not env -u FILECHECK_OPTS /usr/bin/python3.8 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/llvm/llvm/utils/lit/lit.py -j1 
--order=lexical -v Inputs/googletest-timeout --param 
gtest_filter=InfiniteLoopSubTest --param set_timeout=1
# .---command stderr
# | Traceback (most recent call last):
# |   File 
"/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/llvm/llvm/utils/lit/lit/formats/googletest.py",
 line 304, in post_process_shard_results
# | testsuites = json.load(f)["testsuites"]
# |   File "/usr/lib/python3.8/json/__init__.py", line 293, in load
# | return loads(fp.read(),
# |   File "/usr/lib/python3.8/json/__init__.py", line 357, in loads
# | return _default_decoder.decode(s)
# |   File "/usr/lib/python3.8/json/decoder.py", line 337, in decode
# | obj, end = self.raw_decode(s, idx=_w(s, 0).end())
# |   File "/usr/lib/python3.8/json/decoder.py", line 355, in raw_decode
# | raise JSONDecodeError("Expecting value", s, err.value) from None
# | json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
# | 
# | During handling of the above exception, another exception occurred:
# | 
# | Traceback (most recent call last):
# |   File 
"/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/llvm/llvm/utils/lit/lit.py", 
line 6, in 
# | main()
# |   File 
"/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/llvm/llvm/utils/lit/lit/main.py",
 line 130, in main
# | selected_tests, discovered_tests = 
GoogleTest.post_process_shard_results(
# |   File 
"/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/llvm/llvm/utils/lit/lit/formats/googletest.py",
 line 306, in post_process_shard_results
# | raise RuntimeError(
# | RuntimeError: Failed to parse json file: 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/utils/lit/tests/Inputs/googletest-timeout/DummySubDir/OneTest.py-googletest-timeout-4160003-1-2.json
# | 
# `-
# RUN: at line 19
FileCheck --check-prefix=CHECK-INF < 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/utils/lit/tests/Output/googletest-timeout.py.tmp.cfgset.out
 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/utils/lit/tests/googletest-timeout.py
# executed command: FileCheck --check-prefix=CHECK-INF 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/utils/lit/tests/googletest-timeout.py
# .---command stderr
# | 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/utils/lit/tests/googletest-timeout.py:34:14:
 error: CHECK-INF: expected string not found in input
# | # CHECK-INF: Timed Out: 1
# |  ^
...

```

https://github.com/llvm/llvm-project/pull/101821
___
cfe-commits mailing l

[clang] a99e8c9 - [clang][Interp] Fix assignment eval order (#101833)

2024-08-03 Thread via cfe-commits

Author: Timm Baeder
Date: 2024-08-03T17:57:23+02:00
New Revision: a99e8c9c1d624433b57e16d46ab4ecf9f944f6ae

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

LOG: [clang][Interp] Fix assignment eval order (#101833)

RHS first.

Added: 


Modified: 
clang/lib/AST/Interp/Compiler.cpp
clang/test/AST/Interp/eval-order.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Compiler.cpp 
b/clang/lib/AST/Interp/Compiler.cpp
index ada22b569b2b0..d9db1c788314c 100644
--- a/clang/lib/AST/Interp/Compiler.cpp
+++ b/clang/lib/AST/Interp/Compiler.cpp
@@ -733,8 +733,8 @@ bool Compiler::VisitBinaryOperator(const 
BinaryOperator *BO) {
   }
 
   // Typecheck the args.
-  std::optional LT = classify(LHS->getType());
-  std::optional RT = classify(RHS->getType());
+  std::optional LT = classify(LHS);
+  std::optional RT = classify(RHS);
   std::optional T = classify(BO->getType());
 
   // Special case for C++'s three-way/spaceship operator <=>, which
@@ -769,8 +769,16 @@ bool Compiler::VisitBinaryOperator(const 
BinaryOperator *BO) {
   return this->VisitPointerArithBinOp(BO);
   }
 
-  if (!visit(LHS) || !visit(RHS))
-return false;
+  // Assignmentes require us to evalute the RHS first.
+  if (BO->getOpcode() == BO_Assign) {
+if (!visit(RHS) || !visit(LHS))
+  return false;
+if (!this->emitFlip(*LT, *RT, BO))
+  return false;
+  } else {
+if (!visit(LHS) || !visit(RHS))
+  return false;
+  }
 
   // For languages such as C, cast the result of one
   // of our comparision opcodes to T (which is usually int).

diff  --git a/clang/test/AST/Interp/eval-order.cpp 
b/clang/test/AST/Interp/eval-order.cpp
index d9cfd0b4642fa..c78c5061a08f2 100644
--- a/clang/test/AST/Interp/eval-order.cpp
+++ b/clang/test/AST/Interp/eval-order.cpp
@@ -45,7 +45,7 @@ namespace EvalOrder {
 }
 template  constexpr T &&b(T &&v) {
   if (!done_a)
-throw "wrong"; // expected-note 4{{not valid}}
+throw "wrong"; // expected-note 3{{not valid}}
   done_b = true;
   return (T &&)v;
 }
@@ -78,8 +78,7 @@ namespace EvalOrder {
   SEQ(A(f)(B(1), B(2), B(3)));
 
   // Rule 5: b = a, b @= a
-  SEQ(B(lvalue().get()) = A(0)); // expected-error {{not an integral 
constant expression}} FIXME \
-  // expected-note 2{{in call to}}
+  SEQ(B(lvalue().get()) = A(0));
   SEQ(B(lvalue().get()) = A(ud)); // expected-error {{not an 
integral constant expression}} FIXME \
// expected-note 2{{in call to}}
   SEQ(B(lvalue().get()) += A(0));



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


[clang] [clang][Interp] Fix assignment eval order (PR #101833)

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

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


[clang] [clang][ASTImporter] New fix for default template parameter values. (PR #101836)

2024-08-03 Thread Balázs Kéri via cfe-commits

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

Commit e4440b8 added a change that introduced new crash in an incorrectly 
handled case. This is fixed here.

From 2e98fc222566c5e746ade4ccaba23de3b59e0a5d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bal=C3=A1zs=20K=C3=A9ri?= 
Date: Sat, 3 Aug 2024 18:10:34 +0200
Subject: [PATCH] [clang][ASTImporter] New fix for default template parameter
 values.

Commit e4440b8 added a change that introduced new crash in an
incorrectly handled case. This is fixed here.
---
 clang/lib/AST/ASTImporter.cpp   | 12 ++-
 clang/unittests/AST/ASTImporterTest.cpp | 97 +
 2 files changed, 106 insertions(+), 3 deletions(-)

diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 103235547f482..7e4a92ccbe40f 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -5972,7 +5972,11 @@ 
ASTNodeImporter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
 import(D->getDefaultArgument());
 if (!ToDefaultArgOrErr)
   return ToDefaultArgOrErr.takeError();
-ToD->setDefaultArgument(ToD->getASTContext(), *ToDefaultArgOrErr);
+// The import process can trigger import of the parent template which can
+// set the default argument value (to "inherited").
+// In this case do nothing here.
+if (!ToD->hasDefaultArgument())
+  ToD->setDefaultArgument(ToD->getASTContext(), *ToDefaultArgOrErr);
   }
 
   return ToD;
@@ -6004,7 +6008,8 @@ 
ASTNodeImporter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
 import(D->getDefaultArgument());
 if (!ToDefaultArgOrErr)
   return ToDefaultArgOrErr.takeError();
-ToD->setDefaultArgument(Importer.getToContext(), *ToDefaultArgOrErr);
+if (!ToD->hasDefaultArgument())
+  ToD->setDefaultArgument(Importer.getToContext(), *ToDefaultArgOrErr);
   }
 
   return ToD;
@@ -6041,7 +6046,8 @@ 
ASTNodeImporter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
 import(D->getDefaultArgument());
 if (!ToDefaultArgOrErr)
   return ToDefaultArgOrErr.takeError();
-ToD->setDefaultArgument(Importer.getToContext(), *ToDefaultArgOrErr);
+if (!ToD->hasDefaultArgument())
+  ToD->setDefaultArgument(Importer.getToContext(), *ToDefaultArgOrErr);
   }
 
   return ToD;
diff --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittests/AST/ASTImporterTest.cpp
index 57242ff49fe3b..4c41171deec46 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -9919,6 +9919,103 @@ TEST_P(ImportTemplateParmDeclDefaultValue, 
ImportExistingVarTemplate) {
   testImport(FromLastD);
 }
 
+TEST_P(ImportTemplateParmDeclDefaultValue,
+   ImportParentTemplateDuringNonTypeTemplateParmDecl) {
+  // This wants to provoke that during import of 'Y' in "typename T = Y"
+  // (before this import returns) the later definition of 'X' is imported 
fully.
+  const char *Code =
+  R"(
+  struct Z;
+
+  struct Y {
+Z *z;
+static const int x = 1;
+  };
+
+  template 
+  struct X;
+
+  template 
+  struct X {
+static const int A = 1;
+  };
+
+  struct Z {
+template
+void f(int A = X::A);
+  };
+  )";
+
+  Decl *FromTU = getTuDecl(Code, Lang_CXX14);
+  auto *FromD = FirstDeclMatcher().match(
+  FromTU, nonTypeTemplateParmDecl(hasName("P")));
+  auto *ToD = Import(FromD, Lang_CXX14);
+  EXPECT_TRUE(ToD);
+}
+
+TEST_P(ImportTemplateParmDeclDefaultValue,
+   ImportParentTemplateDuringTemplateTypeParmDecl) {
+  const char *Code =
+  R"(
+  struct Z;
+
+  struct Y {
+Z *z;
+  };
+
+  template 
+  struct X;
+
+  template 
+  struct X {
+static const int A = 1;
+  };
+
+  struct Z {
+template
+void f(int A = X::A);
+  };
+  )";
+
+  Decl *FromTU = getTuDecl(Code, Lang_CXX14);
+  auto *FromD = FirstDeclMatcher().match(
+  FromTU, templateTypeParmDecl(hasName("T")));
+  auto *ToD = Import(FromD, Lang_CXX14);
+  EXPECT_TRUE(ToD);
+}
+
+TEST_P(ImportTemplateParmDeclDefaultValue,
+   ImportParentTemplateDuringTemplateTemplateParmDecl) {
+  const char *Code =
+  R"(
+  struct Z;
+
+  template 
+  struct Y {
+Z *z;
+  };
+
+  template  class T = Y>
+  struct X;
+
+  template  class T>
+  struct X {
+static const int A = 1;
+  };
+
+  struct Z {
+template  class T>
+void f(int A = X::A);
+  };
+  )";
+
+  Decl *FromTU = getTuDecl(Code, Lang_CXX14);
+  auto *FromD = FirstDeclMatcher().match(
+  FromTU, templateTemplateParmDecl(hasName("T")));
+  auto *ToD = Import(FromD, Lang_CXX14);
+  EXPECT_TRUE(ToD);
+}
+
 INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest,
  DefaultTestValuesForRunOptions);
 

___
cfe-

[clang] [clang][ASTImporter] New fix for default template parameter values. (PR #101836)

2024-08-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Balázs Kéri (balazske)


Changes

Commit e4440b8 added a change that introduced new crash in an incorrectly 
handled case. This is fixed here.

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


2 Files Affected:

- (modified) clang/lib/AST/ASTImporter.cpp (+9-3) 
- (modified) clang/unittests/AST/ASTImporterTest.cpp (+97) 


``diff
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 103235547f482..7e4a92ccbe40f 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -5972,7 +5972,11 @@ 
ASTNodeImporter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
 import(D->getDefaultArgument());
 if (!ToDefaultArgOrErr)
   return ToDefaultArgOrErr.takeError();
-ToD->setDefaultArgument(ToD->getASTContext(), *ToDefaultArgOrErr);
+// The import process can trigger import of the parent template which can
+// set the default argument value (to "inherited").
+// In this case do nothing here.
+if (!ToD->hasDefaultArgument())
+  ToD->setDefaultArgument(ToD->getASTContext(), *ToDefaultArgOrErr);
   }
 
   return ToD;
@@ -6004,7 +6008,8 @@ 
ASTNodeImporter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
 import(D->getDefaultArgument());
 if (!ToDefaultArgOrErr)
   return ToDefaultArgOrErr.takeError();
-ToD->setDefaultArgument(Importer.getToContext(), *ToDefaultArgOrErr);
+if (!ToD->hasDefaultArgument())
+  ToD->setDefaultArgument(Importer.getToContext(), *ToDefaultArgOrErr);
   }
 
   return ToD;
@@ -6041,7 +6046,8 @@ 
ASTNodeImporter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
 import(D->getDefaultArgument());
 if (!ToDefaultArgOrErr)
   return ToDefaultArgOrErr.takeError();
-ToD->setDefaultArgument(Importer.getToContext(), *ToDefaultArgOrErr);
+if (!ToD->hasDefaultArgument())
+  ToD->setDefaultArgument(Importer.getToContext(), *ToDefaultArgOrErr);
   }
 
   return ToD;
diff --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittests/AST/ASTImporterTest.cpp
index 57242ff49fe3b..4c41171deec46 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -9919,6 +9919,103 @@ TEST_P(ImportTemplateParmDeclDefaultValue, 
ImportExistingVarTemplate) {
   testImport(FromLastD);
 }
 
+TEST_P(ImportTemplateParmDeclDefaultValue,
+   ImportParentTemplateDuringNonTypeTemplateParmDecl) {
+  // This wants to provoke that during import of 'Y' in "typename T = Y"
+  // (before this import returns) the later definition of 'X' is imported 
fully.
+  const char *Code =
+  R"(
+  struct Z;
+
+  struct Y {
+Z *z;
+static const int x = 1;
+  };
+
+  template 
+  struct X;
+
+  template 
+  struct X {
+static const int A = 1;
+  };
+
+  struct Z {
+template
+void f(int A = X::A);
+  };
+  )";
+
+  Decl *FromTU = getTuDecl(Code, Lang_CXX14);
+  auto *FromD = FirstDeclMatcher().match(
+  FromTU, nonTypeTemplateParmDecl(hasName("P")));
+  auto *ToD = Import(FromD, Lang_CXX14);
+  EXPECT_TRUE(ToD);
+}
+
+TEST_P(ImportTemplateParmDeclDefaultValue,
+   ImportParentTemplateDuringTemplateTypeParmDecl) {
+  const char *Code =
+  R"(
+  struct Z;
+
+  struct Y {
+Z *z;
+  };
+
+  template 
+  struct X;
+
+  template 
+  struct X {
+static const int A = 1;
+  };
+
+  struct Z {
+template
+void f(int A = X::A);
+  };
+  )";
+
+  Decl *FromTU = getTuDecl(Code, Lang_CXX14);
+  auto *FromD = FirstDeclMatcher().match(
+  FromTU, templateTypeParmDecl(hasName("T")));
+  auto *ToD = Import(FromD, Lang_CXX14);
+  EXPECT_TRUE(ToD);
+}
+
+TEST_P(ImportTemplateParmDeclDefaultValue,
+   ImportParentTemplateDuringTemplateTemplateParmDecl) {
+  const char *Code =
+  R"(
+  struct Z;
+
+  template 
+  struct Y {
+Z *z;
+  };
+
+  template  class T = Y>
+  struct X;
+
+  template  class T>
+  struct X {
+static const int A = 1;
+  };
+
+  struct Z {
+template  class T>
+void f(int A = X::A);
+  };
+  )";
+
+  Decl *FromTU = getTuDecl(Code, Lang_CXX14);
+  auto *FromD = FirstDeclMatcher().match(
+  FromTU, templateTemplateParmDecl(hasName("T")));
+  auto *ToD = Import(FromD, Lang_CXX14);
+  EXPECT_TRUE(ToD);
+}
+
 INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest,
  DefaultTestValuesForRunOptions);
 

``




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


[clang] [clang][ASTImporter] New fix for default template parameter values. (PR #101836)

2024-08-03 Thread Balázs Kéri via cfe-commits


@@ -9919,6 +9919,103 @@ TEST_P(ImportTemplateParmDeclDefaultValue, 
ImportExistingVarTemplate) {
   testImport(FromLastD);
 }
 
+TEST_P(ImportTemplateParmDeclDefaultValue,
+   ImportParentTemplateDuringNonTypeTemplateParmDecl) {
+  // This wants to provoke that during import of 'Y' in "typename T = Y"
+  // (before this import returns) the later definition of 'X' is imported 
fully.

balazske wrote:

This comment is not accurate, I will remove it.
What exactly should happen:

1. import first `struct X` declaration
3. start import of second `int P`
4. finish import of second `struct X`, this will set `int P` to "inherited"
5. import (visit) function for importing second `int P` returns


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


[clang] [libclang] Fix symbol version of `getBinaryOpcode` functions (PR #101820)

2024-08-03 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

This one is the same, consequently not related:
```
[7789/8607] Building CXX object 
tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/OpenMP/Clauses.cpp.o
FAILED: tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/OpenMP/Clauses.cpp.o 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls-2stage/stage1.install/bin/clang++
 -DFLANG_INCLUDE_TESTS=1 -DFLANG_LITTLE_ENDIAN=1 -DGTEST_HAS_RTTI=0 -D_DEBUG 
-D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS 
-D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-I/home/tcwg-buildbot/worker/clang-aarch64-sve-vls-2stage/stage2/tools/flang/lib/Lower
 -I/home/tcwg-buildbot/worker/clang-aarch64-sve-vls-2stage/llvm/flang/lib/Lower 
-I/home/tcwg-buildbot/worker/clang-aarch64-sve-vls-2stage/llvm/flang/include 
-I/home/tcwg-buildbot/worker/clang-aarch64-sve-vls-2stage/stage2/tools/flang/include
 -I/home/tcwg-buildbot/worker/clang-aarch64-sve-vls-2stage/stage2/include 
-I/home/tcwg-buildbot/worker/clang-aarch64-sve-vls-2stage/llvm/llvm/include 
-isystem 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls-2stage/llvm/llvm/../mlir/include
 -isystem 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls-2stage/stage2/tools/mlir/include
 -isystem 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls-2stage/stage2/tools/clang/include
 -isystem 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls-2stage/llvm/llvm/../clang/include
 -mcpu=neoverse-512tvb -msve-vector-bits=256 -mllvm 
-treat-scalable-fixed-error-as-warning=false -fPIC -fno-semantic-interposition 
-fvisibility-inlines-hidden -Werror=date-time 
-Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter 
-Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic 
-Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough 
-Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor 
-Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wstring-conversion 
-Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color 
-ffunction-sections -fdata-sections -Wno-deprecated-copy -Wno-string-conversion 
-Wno-ctad-maybe-unsupported -Wno-unused-command-line-argument 
-Wstring-conversion   -Wcovered-switch-default -Wno-nested-anon-types 
-O3 -DNDEBUG  -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -std=c++17 -MD 
-MT tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/OpenMP/Clauses.cpp.o -MF 
tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/OpenMP/Clauses.cpp.o.d -o 
tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/OpenMP/Clauses.
```

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


[clang] [clang][Interp] Fix assignment operator call eval order (PR #101845)

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

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

None

>From d3912da14ccba5ecc07ae229a95b647f78ea2001 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sat, 3 Aug 2024 21:15:35 +0200
Subject: [PATCH] [clang][Interp] Fix assignment operator call eval order

---
 clang/lib/AST/Interp/Compiler.cpp| 26 --
 clang/test/AST/Interp/eval-order.cpp | 21 +
 2 files changed, 29 insertions(+), 18 deletions(-)

diff --git a/clang/lib/AST/Interp/Compiler.cpp 
b/clang/lib/AST/Interp/Compiler.cpp
index d9db1c788314c..bd2b0f74b34c5 100644
--- a/clang/lib/AST/Interp/Compiler.cpp
+++ b/clang/lib/AST/Interp/Compiler.cpp
@@ -3977,7 +3977,19 @@ bool Compiler::VisitCallExpr(const CallExpr *E) 
{
 }
   }
 
-  auto Args = llvm::ArrayRef(E->getArgs(), E->getNumArgs());
+  SmallVector Args(
+  llvm::ArrayRef(E->getArgs(), E->getNumArgs()));
+
+  bool IsAssignmentOperatorCall = false;
+  if (const auto *OCE = dyn_cast(E);
+  OCE && OCE->isAssignmentOp()) {
+// Just like with regular assignments, we need to special-case assignment
+// operators here and evaluate the RHS (the second arg) before the LHS (the
+// first arg. We fix this by using a Flip op later.
+assert(Args.size() == 2);
+IsAssignmentOperatorCall = true;
+std::reverse(Args.begin(), Args.end());
+  }
   // Calling a static operator will still
   // pass the instance, but we don't need it.
   // Discard it here.
@@ -3986,7 +3998,8 @@ bool Compiler::VisitCallExpr(const CallExpr *E) {
 MD && MD->isStatic()) {
   if (!this->discard(E->getArg(0)))
 return false;
-  Args = Args.drop_front();
+  // Drop first arg.
+  Args.erase(Args.begin());
 }
   }
 
@@ -4038,6 +4051,15 @@ bool Compiler::VisitCallExpr(const CallExpr *E) 
{
 ++ArgIndex;
   }
 
+  // Undo the argument reversal we did earlier.
+  if (IsAssignmentOperatorCall) {
+assert(Args.size() == 2);
+PrimType Arg1T = classify(Args[0]).value_or(PT_Ptr);
+PrimType Arg2T = classify(Args[1]).value_or(PT_Ptr);
+if (!this->emitFlip(Arg2T, Arg1T, E))
+  return false;
+  }
+
   if (FuncDecl) {
 const Function *Func = getFunction(FuncDecl);
 if (!Func)
diff --git a/clang/test/AST/Interp/eval-order.cpp 
b/clang/test/AST/Interp/eval-order.cpp
index c78c5061a08f2..213ef209a1c04 100644
--- a/clang/test/AST/Interp/eval-order.cpp
+++ b/clang/test/AST/Interp/eval-order.cpp
@@ -1,13 +1,7 @@
 // RUN: %clang_cc1 -std=c++1z -verify=ref,both %s -fcxx-exceptions 
-triple=x86_64-linux-gnu
 // RUN: %clang_cc1 -std=c++1z -verify=expected,both %s -fcxx-exceptions 
-triple=x86_64-linux-gnu -fexperimental-new-constant-interpreter
 
-// ref-no-diagnostics
-
-/// Check that assignment operators evaluate their operands right-to-left.
-/// Copied from test/SemaCXX/constant-expression-cxx1z.cpp
-///
-/// As you can see from the FIXME comments, some of these are not yet working 
correctly
-/// in the new interpreter.
+// both-no-diagnostics
 namespace EvalOrder {
   template struct lvalue {
 T t;
@@ -45,7 +39,7 @@ namespace EvalOrder {
 }
 template  constexpr T &&b(T &&v) {
   if (!done_a)
-throw "wrong"; // expected-note 3{{not valid}}
+throw "wrong";
   done_b = true;
   return (T &&)v;
 }
@@ -79,15 +73,10 @@ namespace EvalOrder {
 
   // Rule 5: b = a, b @= a
   SEQ(B(lvalue().get()) = A(0));
-  SEQ(B(lvalue().get()) = A(ud)); // expected-error {{not an 
integral constant expression}} FIXME \
-   // expected-note 2{{in call to}}
+  SEQ(B(lvalue().get()) = A(ud));
   SEQ(B(lvalue().get()) += A(0));
-  SEQ(B(lvalue().get()) += A(ud)); // expected-error {{not an 
integral constant expression}} FIXME \
-// expected-note 2{{in call 
to}}
-
-  SEQ(B(lvalue().get()) += A(nm)); // expected-error {{not an 
integral constant expression}} FIXME \
-  // expected-note 2{{in call to}}
-
+  SEQ(B(lvalue().get()) += A(ud));
+  SEQ(B(lvalue().get()) += A(nm));
 
   // Rule 6: a[b]
   constexpr int arr[3] = {};

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


[clang] [clang][Interp] Fix assignment operator call eval order (PR #101845)

2024-08-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes



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


2 Files Affected:

- (modified) clang/lib/AST/Interp/Compiler.cpp (+24-2) 
- (modified) clang/test/AST/Interp/eval-order.cpp (+5-16) 


``diff
diff --git a/clang/lib/AST/Interp/Compiler.cpp 
b/clang/lib/AST/Interp/Compiler.cpp
index d9db1c788314c..bd2b0f74b34c5 100644
--- a/clang/lib/AST/Interp/Compiler.cpp
+++ b/clang/lib/AST/Interp/Compiler.cpp
@@ -3977,7 +3977,19 @@ bool Compiler::VisitCallExpr(const CallExpr *E) 
{
 }
   }
 
-  auto Args = llvm::ArrayRef(E->getArgs(), E->getNumArgs());
+  SmallVector Args(
+  llvm::ArrayRef(E->getArgs(), E->getNumArgs()));
+
+  bool IsAssignmentOperatorCall = false;
+  if (const auto *OCE = dyn_cast(E);
+  OCE && OCE->isAssignmentOp()) {
+// Just like with regular assignments, we need to special-case assignment
+// operators here and evaluate the RHS (the second arg) before the LHS (the
+// first arg. We fix this by using a Flip op later.
+assert(Args.size() == 2);
+IsAssignmentOperatorCall = true;
+std::reverse(Args.begin(), Args.end());
+  }
   // Calling a static operator will still
   // pass the instance, but we don't need it.
   // Discard it here.
@@ -3986,7 +3998,8 @@ bool Compiler::VisitCallExpr(const CallExpr *E) {
 MD && MD->isStatic()) {
   if (!this->discard(E->getArg(0)))
 return false;
-  Args = Args.drop_front();
+  // Drop first arg.
+  Args.erase(Args.begin());
 }
   }
 
@@ -4038,6 +4051,15 @@ bool Compiler::VisitCallExpr(const CallExpr *E) 
{
 ++ArgIndex;
   }
 
+  // Undo the argument reversal we did earlier.
+  if (IsAssignmentOperatorCall) {
+assert(Args.size() == 2);
+PrimType Arg1T = classify(Args[0]).value_or(PT_Ptr);
+PrimType Arg2T = classify(Args[1]).value_or(PT_Ptr);
+if (!this->emitFlip(Arg2T, Arg1T, E))
+  return false;
+  }
+
   if (FuncDecl) {
 const Function *Func = getFunction(FuncDecl);
 if (!Func)
diff --git a/clang/test/AST/Interp/eval-order.cpp 
b/clang/test/AST/Interp/eval-order.cpp
index c78c5061a08f2..213ef209a1c04 100644
--- a/clang/test/AST/Interp/eval-order.cpp
+++ b/clang/test/AST/Interp/eval-order.cpp
@@ -1,13 +1,7 @@
 // RUN: %clang_cc1 -std=c++1z -verify=ref,both %s -fcxx-exceptions 
-triple=x86_64-linux-gnu
 // RUN: %clang_cc1 -std=c++1z -verify=expected,both %s -fcxx-exceptions 
-triple=x86_64-linux-gnu -fexperimental-new-constant-interpreter
 
-// ref-no-diagnostics
-
-/// Check that assignment operators evaluate their operands right-to-left.
-/// Copied from test/SemaCXX/constant-expression-cxx1z.cpp
-///
-/// As you can see from the FIXME comments, some of these are not yet working 
correctly
-/// in the new interpreter.
+// both-no-diagnostics
 namespace EvalOrder {
   template struct lvalue {
 T t;
@@ -45,7 +39,7 @@ namespace EvalOrder {
 }
 template  constexpr T &&b(T &&v) {
   if (!done_a)
-throw "wrong"; // expected-note 3{{not valid}}
+throw "wrong";
   done_b = true;
   return (T &&)v;
 }
@@ -79,15 +73,10 @@ namespace EvalOrder {
 
   // Rule 5: b = a, b @= a
   SEQ(B(lvalue().get()) = A(0));
-  SEQ(B(lvalue().get()) = A(ud)); // expected-error {{not an 
integral constant expression}} FIXME \
-   // expected-note 2{{in call to}}
+  SEQ(B(lvalue().get()) = A(ud));
   SEQ(B(lvalue().get()) += A(0));
-  SEQ(B(lvalue().get()) += A(ud)); // expected-error {{not an 
integral constant expression}} FIXME \
-// expected-note 2{{in call 
to}}
-
-  SEQ(B(lvalue().get()) += A(nm)); // expected-error {{not an 
integral constant expression}} FIXME \
-  // expected-note 2{{in call to}}
-
+  SEQ(B(lvalue().get()) += A(ud));
+  SEQ(B(lvalue().get()) += A(nm));
 
   // Rule 6: a[b]
   constexpr int arr[3] = {};

``




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


[clang] [llvm] [BPF] introduce `__attribute__((bpf_fastcall))` (PR #101228)

2024-08-03 Thread via cfe-commits

eddyz87 wrote:

@AaronBallman , @efriedma-quic , could you please check my last comment 
[here](https://github.com/llvm/llvm-project/pull/101228#issuecomment-2263848414)?

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


[clang] [Clang] strengthen checks for 'main' function to meet [basic.start.main] p2 requirements (PR #101853)

2024-08-03 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk created 
https://github.com/llvm/llvm-project/pull/101853

Fixes #101512 

>From 16706eb1648653f41da5b6d10c1104b1cf1609bf Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Sun, 4 Aug 2024 00:45:49 +0300
Subject: [PATCH] [Clang] strengthen checks for 'main' function to meet
 [basic.start.main] p2 requirements

---
 clang/docs/ReleaseNotes.rst   |  2 ++
 .../clang/Basic/DiagnosticSemaKinds.td|  3 ++
 clang/include/clang/Sema/Sema.h   |  2 +-
 clang/lib/AST/Decl.cpp| 14 +
 clang/lib/Sema/SemaDecl.cpp   | 15 +++---
 clang/test/CodeGenCXX/mangle.cpp  | 10 ---
 clang/test/SemaCXX/linkage1.cpp   | 29 +++
 7 files changed, 55 insertions(+), 20 deletions(-)
 create mode 100644 clang/test/SemaCXX/linkage1.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4c7bd099420ab..3303db5a87ace 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -145,6 +145,8 @@ Improvements to Clang's diagnostics
 
 - -Wdangling-assignment-gsl is enabled by default.
 
+- Clang now diagnoses the use of `main` in `extern` context as invalid 
according to [basic.start.main] p2. Fixes #GH101512.
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 581434d33c5c9..dd95ea3cc6f0f 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5986,6 +5986,9 @@ def err_new_abi_tag_on_redeclaration : Error<
   "'abi_tag' %0 missing in original declaration">;
 def note_use_ifdef_guards : Note<
   "unguarded header; consider using #ifdef guards or #pragma once">;
+def err_invalid_linkage_specification : Error<
+  "invalid linkage specification "
+  "'extern \"%select{C|C++}0\"'">;
 
 def warn_var_decl_not_read_only : Warning<
   "object of type %0 cannot be placed in read-only memory">,
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 2ec6367eccea0..0fc07d4a01ad3 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3585,7 +3585,7 @@ class Sema final : public SemaBase {
   /// \param OldT The portion of the type of the old declaration to check.
   bool canFullyTypeCheckRedeclaration(ValueDecl *NewD, ValueDecl *OldD,
   QualType NewT, QualType OldT);
-  void CheckMain(FunctionDecl *FD, const DeclSpec &D);
+  void CheckMain(FunctionDecl *FD, DeclContext *DC, const DeclSpec &D);
   void CheckMSVCRTEntryPoint(FunctionDecl *FD);
 
   /// Returns an implicit CodeSegAttr if a __declspec(code_seg) is found on a
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 490c4a2fc525c..447297103f396 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -3292,11 +3292,15 @@ bool FunctionDecl::isImmediateFunction() const {
 }
 
 bool FunctionDecl::isMain() const {
-  const TranslationUnitDecl *tunit =
-dyn_cast(getDeclContext()->getRedeclContext());
-  return tunit &&
- !tunit->getASTContext().getLangOpts().Freestanding &&
- isNamed(this, "main");
+  const TranslationUnitDecl *TUnit =
+  dyn_cast(getDeclContext()->getRedeclContext());
+  const LinkageSpecDecl *LSD = dyn_cast(getDeclContext());
+  if (!TUnit && !LSD)
+return false;
+  if ((TUnit && TUnit->getASTContext().getLangOpts().Freestanding) ||
+  (LSD && LSD->getASTContext().getLangOpts().Freestanding))
+return false;
+  return isNamed(this, "main");
 }
 
 bool FunctionDecl::isMSVCRTEntryPoint() const {
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 4fea38d1b02a9..ae6d6681d6029 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -10308,7 +10308,7 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, 
DeclContext *DC,
   if (!getLangOpts().CPlusPlus) {
 // Perform semantic checking on the function declaration.
 if (!NewFD->isInvalidDecl() && NewFD->isMain())
-  CheckMain(NewFD, D.getDeclSpec());
+  CheckMain(NewFD, DC, D.getDeclSpec());
 
 if (!NewFD->isInvalidDecl() && NewFD->isMSVCRTEntryPoint())
   CheckMSVCRTEntryPoint(NewFD);
@@ -10473,7 +10473,7 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, 
DeclContext *DC,
 
 // Perform semantic checking on the function declaration.
 if (!NewFD->isInvalidDecl() && NewFD->isMain())
-  CheckMain(NewFD, D.getDeclSpec());
+  CheckMain(NewFD, DC, D.getDeclSpec());
 
 if (!NewFD->isInvalidDecl() && NewFD->isMSVCRTEntryPoint())
   CheckMSVCRTEntryPoint(NewFD);
@@ -12210,7 +12210,15 @@ bool Sema::CheckFunctionDeclaration(Scope *S, 
FunctionDecl *NewFD,
   return Redeclaration;
 }
 
-void Sema::CheckMain(FunctionDecl* FD, const DeclSpec& DS) {
+void Sema::CheckMain(FunctionDecl *FD, DeclC

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

2024-08-03 Thread Carlos Galvez via cfe-commits
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= 
Message-ID:
In-Reply-To: 


carlosgalvezp wrote:

> It seems that this check is very similar up the 
> `cppcoreguidelines-pro-bounds-constant-array-index` check, Is there not a way 
> this could be merged with that check. I'm mindful that people will have both 
> checks enabled and get 2 different warnings for the same violation

Since it's 2 different rules from the guidelines I think it's better to have 
them as separate  checks to have a 1:1 mapping. People can easily suppress both 
of they want via `NOLINT(cppcoreguidelines-probounds-*` if needed.

Otherwise the check will do "too much" and there will come a day where someone 
will want to split the check into two as it has happened in the past.

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


[clang] Fix all mypy --strict errors in clang python binding (PR #101784)

2024-08-03 Thread Jannick Kremer via cfe-commits

DeinAlptraum wrote:

@TsXor thank you for your work!
I am generally all in favor of typing annotations, and I like that `ctyped` 
adds a stronger connection between the Python function definitions and the C 
library functions in terms of types.

That said, this PR is pretty massive and grows the Python bindings by about 800 
lines of code (ignoring tests), which imo is quite a lot just to pass the 
strict type check. There are also a lot of refactoring and other changes in 
this PR that, while generally welcome, seem unrelated and should be factored 
out. In general, multiple smaller PRs are preferred over something of this 
size, to have clearer boundaries and ease reviewing.

For reference, I'd like to point out that I've also opened a PR for strict 
typing in #78114, which has been under review for a while.
With that out of the way: I'm still a very new contributor and since I've 
opened a PR for essentially the exact same thing, don't feel comfortable 
deciding on how to proceed with this. I'm summoning @Endilll: what are your 
thoughts on this?

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


[clang] [Clang] strengthen checks for 'main' function to meet [basic.start.main] p2 requirements (PR #101853)

2024-08-03 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk updated 
https://github.com/llvm/llvm-project/pull/101853

>From f4f091b742d7b7ca0a96725b42a7cd09530240f5 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Sun, 4 Aug 2024 00:45:49 +0300
Subject: [PATCH] [Clang] strengthen checks for 'main' function to meet
 [basic.start.main] p2 requirements

---
 clang/docs/ReleaseNotes.rst   |  2 ++
 .../clang/Basic/DiagnosticSemaKinds.td|  3 ++
 clang/include/clang/Sema/Sema.h   |  2 +-
 clang/lib/AST/Decl.cpp| 14 +
 clang/lib/Sema/SemaDecl.cpp   | 15 +++---
 clang/test/SemaCXX/linkage1.cpp   | 29 +++
 6 files changed, 55 insertions(+), 10 deletions(-)
 create mode 100644 clang/test/SemaCXX/linkage1.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4c7bd099420ab..3303db5a87ace 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -145,6 +145,8 @@ Improvements to Clang's diagnostics
 
 - -Wdangling-assignment-gsl is enabled by default.
 
+- Clang now diagnoses the use of `main` in `extern` context as invalid 
according to [basic.start.main] p2. Fixes #GH101512.
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 581434d33c5c9..2005133b2f568 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -990,6 +990,9 @@ def warn_main_redefined : Warning<"variable named 'main' 
with external linkage "
 "has undefined behavior">, InGroup;
 def ext_main_used : Extension<
 "referring to 'main' within an expression is a Clang extension">, 
InGroup;
+def err_invalid_linkage_specification : Extension<
+  "invalid linkage specification "
+  "'extern \"%select{C|C++}0\"'">;
 
 /// parser diagnostics
 def ext_no_declarators : ExtWarn<"declaration does not declare anything">,
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 2ec6367eccea0..0fc07d4a01ad3 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3585,7 +3585,7 @@ class Sema final : public SemaBase {
   /// \param OldT The portion of the type of the old declaration to check.
   bool canFullyTypeCheckRedeclaration(ValueDecl *NewD, ValueDecl *OldD,
   QualType NewT, QualType OldT);
-  void CheckMain(FunctionDecl *FD, const DeclSpec &D);
+  void CheckMain(FunctionDecl *FD, DeclContext *DC, const DeclSpec &D);
   void CheckMSVCRTEntryPoint(FunctionDecl *FD);
 
   /// Returns an implicit CodeSegAttr if a __declspec(code_seg) is found on a
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 490c4a2fc525c..447297103f396 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -3292,11 +3292,15 @@ bool FunctionDecl::isImmediateFunction() const {
 }
 
 bool FunctionDecl::isMain() const {
-  const TranslationUnitDecl *tunit =
-dyn_cast(getDeclContext()->getRedeclContext());
-  return tunit &&
- !tunit->getASTContext().getLangOpts().Freestanding &&
- isNamed(this, "main");
+  const TranslationUnitDecl *TUnit =
+  dyn_cast(getDeclContext()->getRedeclContext());
+  const LinkageSpecDecl *LSD = dyn_cast(getDeclContext());
+  if (!TUnit && !LSD)
+return false;
+  if ((TUnit && TUnit->getASTContext().getLangOpts().Freestanding) ||
+  (LSD && LSD->getASTContext().getLangOpts().Freestanding))
+return false;
+  return isNamed(this, "main");
 }
 
 bool FunctionDecl::isMSVCRTEntryPoint() const {
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 4fea38d1b02a9..ae6d6681d6029 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -10308,7 +10308,7 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, 
DeclContext *DC,
   if (!getLangOpts().CPlusPlus) {
 // Perform semantic checking on the function declaration.
 if (!NewFD->isInvalidDecl() && NewFD->isMain())
-  CheckMain(NewFD, D.getDeclSpec());
+  CheckMain(NewFD, DC, D.getDeclSpec());
 
 if (!NewFD->isInvalidDecl() && NewFD->isMSVCRTEntryPoint())
   CheckMSVCRTEntryPoint(NewFD);
@@ -10473,7 +10473,7 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, 
DeclContext *DC,
 
 // Perform semantic checking on the function declaration.
 if (!NewFD->isInvalidDecl() && NewFD->isMain())
-  CheckMain(NewFD, D.getDeclSpec());
+  CheckMain(NewFD, DC, D.getDeclSpec());
 
 if (!NewFD->isInvalidDecl() && NewFD->isMSVCRTEntryPoint())
   CheckMSVCRTEntryPoint(NewFD);
@@ -12210,7 +12210,15 @@ bool Sema::CheckFunctionDeclaration(Scope *S, 
FunctionDecl *NewFD,
   return Redeclaration;
 }
 
-void Sema::CheckMain(FunctionDecl* FD, const DeclSpec& DS) {
+void Sema::CheckMain(FunctionDecl *FD, DeclContext *DC, const DeclSpec &DS) {
+  // [basic.

[clang] Fix all mypy --strict errors in clang python binding (PR #101784)

2024-08-03 Thread via cfe-commits

github-actions[bot] wrote:




:warning: Python code formatter, darker found issues in your code. :warning:



You can test this locally with the following command:


``bash
darker --check --diff -r 
98e4413a38f286147b863a6ead9625228ab0ec7d...c3ebad6a3447101cb307d5ca118d28d1b78b4dbe
 clang/bindings/python/clang/ctyped.py 
clang/bindings/python/tests/ctyped/__init__.py 
clang/bindings/python/tests/ctyped/test_stub_conversion.py 
clang/bindings/python/clang/cindex.py 
clang/bindings/python/tests/cindex/test_translation_unit.py 
clang/bindings/python/tests/cindex/test_type.py
``





View the diff from darker here.


``diff
--- clang/cindex.py 2024-08-03 14:40:40.00 +
+++ clang/cindex.py 2024-08-03 23:15:21.593600 +
@@ -60,14 +60,33 @@
 # o cleanup ctypes wrapping, would be nice to separate the ctypes details more
 #   clearly, and hide from the external interface (i.e., help(cindex)).
 #
 # o implement additional SourceLocation, SourceRange, and File methods.
 
-from ctypes import (c_byte, c_ubyte, c_short, c_ushort, c_int, c_uint, c_long, 
 # pyright: ignore[reportUnusedImport]
-c_ulong, c_longlong,c_ulonglong, c_size_t, c_ssize_t,  # 
pyright: ignore[reportUnusedImport]
-c_bool, c_char, c_wchar, c_float, c_double, c_longdouble,  
# pyright: ignore[reportUnusedImport]
-c_char_p, c_wchar_p, c_void_p)  # pyright: 
ignore[reportUnusedImport]
+from ctypes import (
+c_byte,
+c_ubyte,
+c_short,
+c_ushort,
+c_int,
+c_uint,
+c_long,  # pyright: ignore[reportUnusedImport]
+c_ulong,
+c_longlong,
+c_ulonglong,
+c_size_t,
+c_ssize_t,  # pyright: ignore[reportUnusedImport]
+c_bool,
+c_char,
+c_wchar,
+c_float,
+c_double,
+c_longdouble,  # pyright: ignore[reportUnusedImport]
+c_char_p,
+c_wchar_p,
+c_void_p,
+)  # pyright: ignore[reportUnusedImport]
 from ctypes import py_object, Structure, POINTER, byref, cast, cdll
 from .ctyped import *
 from .ctyped import ANNO_CONVERTIBLE, generate_metadata
 
 import os
@@ -114,11 +133,11 @@
 ...
 
 
 # Python 3 strings are unicode, translate them to/from utf8 for C-interop.
 class c_interop_string(c_char_p):
-def __init__(self, p: 'CInteropString' = None):
+def __init__(self, p: "CInteropString" = None):
 if p is None:
 p = ""
 if isinstance(p, str):
 p = p.encode("utf8")
 super(c_char_p, self).__init__(p)
@@ -132,11 +151,11 @@
 if val is None:
 return None
 return val.decode("utf8")
 
 @classmethod
-def from_param(cls, param: 'CInteropString') -> c_interop_string:
+def from_param(cls, param: "CInteropString") -> c_interop_string:
 if isinstance(param, str):
 return cls(param)
 if isinstance(param, bytes):
 return cls(param)
 if param is None:
@@ -168,11 +187,11 @@
 
 ### Exception Classes ###
 
 
 class CXError(Exception):
-'''Represents C error of type enum CXErrorCode.'''
+"""Represents C error of type enum CXErrorCode."""
 
 # A generic error code, no further details are available.
 #
 # Errors of this kind can get their own specific error codes in future
 # libclang versions.
@@ -297,11 +316,15 @@
 
 def __del__(self) -> None:
 conf.lib.clang_disposeString(self)
 
 @staticmethod
-def from_result(res: _CXString, fn: Optional[Callable[..., _CXString]] = 
None, args: Optional[Tuple[Any, ...]] = None) -> str:
+def from_result(
+res: _CXString,
+fn: Optional[Callable[..., _CXString]] = None,
+args: Optional[Tuple[Any, ...]] = None,
+) -> str:
 assert isinstance(res, _CXString)
 pystr: str | None = conf.lib.clang_getCString(res)
 if pystr is None:
 return ""
 return pystr
@@ -329,11 +352,13 @@
 f = None
 self._data = (f, int(l.value), int(c.value), int(o.value))
 return self._data
 
 @staticmethod
-def from_position(tu: TranslationUnit, file: File, line: int, column: int) 
-> SourceLocation:
+def from_position(
+tu: TranslationUnit, file: File, line: int, column: int
+) -> SourceLocation:
 """
 Retrieve the source location associated with a given file/line/column 
in
 a particular translation unit.
 """
 return conf.lib.clang_getLocation(tu, file, line, column)
@@ -445,12 +470,14 @@
 return False
 if (
 other.file is not None
 and self.start.file is not None
 and self.end.file is not None
-and (other.file.name != self.start.file.name
- or other.file.name != self.end.file.name)
+and (
+other.file.name != self.start.file.name
+or other.file.name != self.end.file.name
+)
 ):
   

[clang] Warning Libc functions (PR #101583)

2024-08-03 Thread Ziqing Luo via cfe-commits

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

>From 8a8b317c2b1c73117bcbbf771a783338448724a5 Mon Sep 17 00:00:00 2001
From: Ziqing Luo 
Date: Thu, 1 Aug 2024 16:36:27 -0700
Subject: [PATCH] [-Wunsafe-buffer-usage] Add warn on unsafe calls to libc
 functions

Warning about calls to libc functions involving buffer access.  Warned
functions are hardcoded by names.

(rdar://117182250)
---
 .../Analysis/Analyses/UnsafeBufferUsage.h |   8 +
 .../Analyses/UnsafeBufferUsageGadgets.def |   1 +
 .../clang/Basic/DiagnosticSemaKinds.td|   2 +
 clang/lib/Analysis/UnsafeBufferUsage.cpp  | 322 +-
 clang/lib/Sema/AnalysisBasedWarnings.cpp  |  12 +
 ...arn-unsafe-buffer-usage-libc-functions.cpp |  81 +
 ...n-unsafe-buffer-usage-test-unreachable.cpp |   4 +-
 7 files changed, 425 insertions(+), 5 deletions(-)
 create mode 100644 
clang/test/SemaCXX/warn-unsafe-buffer-usage-libc-functions.cpp

diff --git a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h 
b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
index 228b4ae1e3e11..62d0c6e350f37 100644
--- a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
+++ b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
@@ -15,6 +15,7 @@
 #define LLVM_CLANG_ANALYSIS_ANALYSES_UNSAFEBUFFERUSAGE_H
 
 #include "clang/AST/Decl.h"
+#include "clang/AST/Expr.h"
 #include "clang/AST/Stmt.h"
 #include "clang/Basic/SourceLocation.h"
 #include "llvm/Support/Debug.h"
@@ -106,6 +107,13 @@ class UnsafeBufferUsageHandler {
   virtual void handleUnsafeOperation(const Stmt *Operation,
  bool IsRelatedToDecl, ASTContext &Ctx) = 
0;
 
+  /// Invoked when a call to an unsafe libc function is found.
+  /// \param PrintfInfo is 0 if the callee function is not a member of the
+  /// printf family; is 1 if the callee is `sprintf`; is 2 if
+  /// the callee is other printfs
+  virtual void handleUnsafeLibcCall(const CallExpr *Call, unsigned PrintfInfo,
+ASTContext &Ctx) = 0;
+
   /// Invoked when an unsafe operation with a std container is found.
   virtual void handleUnsafeOperationInContainer(const Stmt *Operation,
 bool IsRelatedToDecl,
diff --git a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def 
b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def
index 242ad763ba62b..ac01b285ae833 100644
--- a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def
+++ b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def
@@ -38,6 +38,7 @@ WARNING_GADGET(PointerArithmetic)
 WARNING_GADGET(UnsafeBufferUsageAttr)
 WARNING_GADGET(UnsafeBufferUsageCtorAttr)
 WARNING_GADGET(DataInvocation)
+WARNING_GADGET(UnsafeLibcFunctionCall)
 WARNING_CONTAINER_GADGET(SpanTwoParamConstructor) // Uses of `std::span(arg0, 
arg1)`
 FIXABLE_GADGET(ULCArraySubscript)  // `DRE[any]` in an Unspecified 
Lvalue Context
 FIXABLE_GADGET(DerefSimplePtrArithFixable)
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 581434d33c5c9..ce77f459fab4f 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12376,6 +12376,8 @@ def warn_unsafe_buffer_operation : Warning<
   "%select{unsafe pointer operation|unsafe pointer arithmetic|"
   "unsafe buffer access|function introduces unsafe buffer manipulation|unsafe 
invocation of span::data}0">,
   InGroup, DefaultIgnore;
+def note_unsafe_buffer_printf_call : Note<
+  "%select{| change to 'snprintf' for explicit bounds checking | use 
'std::string::c_str' as pointer to guarantee null-termination}0">;
 def note_unsafe_buffer_operation : Note<
   "used%select{| in pointer arithmetic| in buffer access}0 here">;
 def note_unsafe_buffer_variable_fixit_group : Note<
diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index 866222380974b..7402cf0f24c1e 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -9,19 +9,21 @@
 #include "clang/Analysis/Analyses/UnsafeBufferUsage.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
 #include "clang/AST/Expr.h"
+#include "clang/AST/ExprCXX.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/Stmt.h"
-#include "clang/AST/StmtVisitor.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
-#include "clang/Basic/CharInfo.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Lex/Lexer.h"
 #include "clang/Lex/Preprocessor.h"
 #include "llvm/ADT/APSInt.h"
+#include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/iterator_range.h"
 #include "llvm/Support/Casting.h"
 #include 
 #include 
@@ -44

[clang] Fix all mypy --strict errors in clang python binding (PR #101784)

2024-08-03 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

Thank you for your contribution! This is somewhat tricky situation, now that we 
have multiple opened PR in the same area of the codebase. But I think there is 
way forward:

1. https://github.com/llvm/llvm-project/pull/78114 and related work has been 
underway for several weeks, and I don't think anything should change there from 
the procedural standpoint. I encourage @TsXor to review it, and if you think 
something can be done better, feel free to leave a review. I also encourage 
@DeinAlptraum to take a look at this PR as it stands, and if you think this PR 
does something better than your work that is not yet merged, we can go with the 
approach here instead.

2. This PR is massive, which makes it hard to both review and, potentially, 
revert. As with https://github.com/llvm/llvm-project/pull/78114, I suspect that 
one can compile a list of fixes by topic that this PR covers. Items in such 
list are a good approximation of individual PRs that you should submit instead 
of this PR.

3. I see that >1k changed lines are tested by just 360 lines of code. This is 
sure a very rough estimate (sorry, I don't have time to review something this 
big right away), but it makes me wonder whether there's a room for more 
testing. 

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


[clang] [clang-tools-extra] [clangd] show lambda name instead of operator() in signature help (PR #101857)

2024-08-03 Thread via cfe-commits

https://github.com/tilobyte created 
https://github.com/llvm/llvm-project/pull/101857

addresses https://github.com/clangd/clangd/issues/86

>From c1afe853ccacae1605fecfe552bb9a263c6b8c1d Mon Sep 17 00:00:00 2001
From: Timothy Akintilo 
Date: Sat, 27 Jul 2024 16:17:46 -0500
Subject: [PATCH] use lambda name instead of operator()

---
 clang-tools-extra/clangd/CodeComplete.cpp |  2 ++
 .../clangd/unittests/CodeCompleteTests.cpp|  9 +++
 .../include/clang/Sema/CodeCompleteConsumer.h | 18 ++
 clang/include/clang/Sema/Overload.h   |  5 
 clang/include/clang/Sema/Sema.h   | 22 -
 clang/lib/Sema/CodeCompleteConsumer.cpp   | 10 +++-
 clang/lib/Sema/SemaCodeComplete.cpp   | 17 ++---
 clang/lib/Sema/SemaLookup.cpp |  3 ++-
 clang/lib/Sema/SemaOverload.cpp   | 24 +--
 9 files changed, 82 insertions(+), 28 deletions(-)

diff --git a/clang-tools-extra/clangd/CodeComplete.cpp 
b/clang-tools-extra/clangd/CodeComplete.cpp
index 89eee392837af..4f8a53aa7aae7 100644
--- a/clang-tools-extra/clangd/CodeComplete.cpp
+++ b/clang-tools-extra/clangd/CodeComplete.cpp
@@ -1139,6 +1139,8 @@ class SignatureHelpCollector final : public 
CodeCompleteConsumer {
   switch (K) {
   case OC::CK_Aggregate:
 return 0;
+  case OC::CK_Lambda:
+[[fallthrough]];
   case OC::CK_Function:
 return 1;
   case OC::CK_FunctionType:
diff --git a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp 
b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
index 96d1ee1f0add7..4f748168d75aa 100644
--- a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -1437,6 +1437,15 @@ TEST(SignatureHelpTest, Overloads) {
   EXPECT_EQ(0, Results.activeParameter);
 }
 
+TEST(SignatureHelpTest, ShowLambdaNameInsteadOfOperatorParens) {
+  auto const Results = signatures(R"cpp(
+auto foo = [](int x, int y){};
+int main() { foo(^); }
+  )cpp");
+  EXPECT_THAT(Results.signatures,
+  UnorderedElementsAre(sig("foo([[int x]], [[int y]]) -> void")));
+}
+
 TEST(SignatureHelpTest, FunctionPointers) {
   llvm::StringLiteral Tests[] = {
   // Variable of function pointer type
diff --git a/clang/include/clang/Sema/CodeCompleteConsumer.h 
b/clang/include/clang/Sema/CodeCompleteConsumer.h
index 0924dc27af82b..a6530c3c93d91 100644
--- a/clang/include/clang/Sema/CodeCompleteConsumer.h
+++ b/clang/include/clang/Sema/CodeCompleteConsumer.h
@@ -1028,6 +1028,9 @@ class CodeCompleteConsumer {
   /// The candidate is a function declaration.
   CK_Function,
 
+  // The candidate is a lambda operator().
+  CK_Lambda,
+
   /// The candidate is a function template, arguments are being completed.
   CK_FunctionTemplate,
 
@@ -1055,6 +1058,13 @@ class CodeCompleteConsumer {
   /// Kind == CK_Function.
   FunctionDecl *Function;
 
+  /// The lambda operator() candidate paired with the
+  /// lambda variable, available when Kind == CK_Lambda.
+  struct {
+FunctionDecl *OperatorParens;
+VarDecl *Var;
+  } Lambda;
+
   /// The function template overload candidate, available when
   /// Kind == CK_FunctionTemplate.
   FunctionTemplateDecl *FunctionTemplate;
@@ -1082,6 +1092,12 @@ class CodeCompleteConsumer {
   assert(Function != nullptr);
 }
 
+OverloadCandidate(FunctionDecl *LambdaOperatorParens, VarDecl *LambdaVar)
+: Kind(CK_Lambda), Lambda{LambdaOperatorParens, LambdaVar} {
+  assert(Lambda.OperatorParens != nullptr);
+  assert(Lambda.Var != nullptr);
+}
+
 OverloadCandidate(FunctionTemplateDecl *FunctionTemplateDecl)
 : Kind(CK_FunctionTemplate), FunctionTemplate(FunctionTemplateDecl) {
   assert(FunctionTemplateDecl != nullptr);
@@ -1112,6 +1128,8 @@ class CodeCompleteConsumer {
 /// function declaration for a function template.
 FunctionDecl *getFunction() const;
 
+VarDecl *getLambdaVarDecl() const;
+
 /// Retrieve the function template overload candidate.
 FunctionTemplateDecl *getFunctionTemplate() const {
   assert(getKind() == CK_FunctionTemplate && "Not a function template");
diff --git a/clang/include/clang/Sema/Overload.h 
b/clang/include/clang/Sema/Overload.h
index d6a6cee62a752..7c4e82f07de02 100644
--- a/clang/include/clang/Sema/Overload.h
+++ b/clang/include/clang/Sema/Overload.h
@@ -876,6 +876,11 @@ class Sema;
 /// function pointer or reference (C++ [over.call.object]).
 FunctionDecl *Function;
 
+/// LambdaName - When the OverloadCandidate is for a
+/// lambda's operator(), points to the declaration of
+/// the lambda variable.
+VarDecl *LambdaName{nullptr};
+
 /// FoundDecl - The original declaration that was looked up /
 /// invented / otherwise found, together with its access.
 /// Might be 

[clang] [clang-tools-extra] [clangd] show lambda name instead of operator() in signature help (PR #101857)

2024-08-03 Thread via cfe-commits

github-actions[bot] wrote:



Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from 
other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

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


[clang] [clang-tools-extra] [clangd] show lambda name instead of operator() in signature help (PR #101857)

2024-08-03 Thread via cfe-commits

llvmbot wrote:




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

Author: Timothy (tilobyte)


Changes

addresses https://github.com/clangd/clangd/issues/86

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


9 Files Affected:

- (modified) clang-tools-extra/clangd/CodeComplete.cpp (+2) 
- (modified) clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp (+9) 
- (modified) clang/include/clang/Sema/CodeCompleteConsumer.h (+18) 
- (modified) clang/include/clang/Sema/Overload.h (+5) 
- (modified) clang/include/clang/Sema/Sema.h (+11-11) 
- (modified) clang/lib/Sema/CodeCompleteConsumer.cpp (+9-1) 
- (modified) clang/lib/Sema/SemaCodeComplete.cpp (+14-3) 
- (modified) clang/lib/Sema/SemaLookup.cpp (+2-1) 
- (modified) clang/lib/Sema/SemaOverload.cpp (+12-12) 


``diff
diff --git a/clang-tools-extra/clangd/CodeComplete.cpp 
b/clang-tools-extra/clangd/CodeComplete.cpp
index 89eee392837af..4f8a53aa7aae7 100644
--- a/clang-tools-extra/clangd/CodeComplete.cpp
+++ b/clang-tools-extra/clangd/CodeComplete.cpp
@@ -1139,6 +1139,8 @@ class SignatureHelpCollector final : public 
CodeCompleteConsumer {
   switch (K) {
   case OC::CK_Aggregate:
 return 0;
+  case OC::CK_Lambda:
+[[fallthrough]];
   case OC::CK_Function:
 return 1;
   case OC::CK_FunctionType:
diff --git a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp 
b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
index 96d1ee1f0add7..4f748168d75aa 100644
--- a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -1437,6 +1437,15 @@ TEST(SignatureHelpTest, Overloads) {
   EXPECT_EQ(0, Results.activeParameter);
 }
 
+TEST(SignatureHelpTest, ShowLambdaNameInsteadOfOperatorParens) {
+  auto const Results = signatures(R"cpp(
+auto foo = [](int x, int y){};
+int main() { foo(^); }
+  )cpp");
+  EXPECT_THAT(Results.signatures,
+  UnorderedElementsAre(sig("foo([[int x]], [[int y]]) -> void")));
+}
+
 TEST(SignatureHelpTest, FunctionPointers) {
   llvm::StringLiteral Tests[] = {
   // Variable of function pointer type
diff --git a/clang/include/clang/Sema/CodeCompleteConsumer.h 
b/clang/include/clang/Sema/CodeCompleteConsumer.h
index 0924dc27af82b..a6530c3c93d91 100644
--- a/clang/include/clang/Sema/CodeCompleteConsumer.h
+++ b/clang/include/clang/Sema/CodeCompleteConsumer.h
@@ -1028,6 +1028,9 @@ class CodeCompleteConsumer {
   /// The candidate is a function declaration.
   CK_Function,
 
+  // The candidate is a lambda operator().
+  CK_Lambda,
+
   /// The candidate is a function template, arguments are being completed.
   CK_FunctionTemplate,
 
@@ -1055,6 +1058,13 @@ class CodeCompleteConsumer {
   /// Kind == CK_Function.
   FunctionDecl *Function;
 
+  /// The lambda operator() candidate paired with the
+  /// lambda variable, available when Kind == CK_Lambda.
+  struct {
+FunctionDecl *OperatorParens;
+VarDecl *Var;
+  } Lambda;
+
   /// The function template overload candidate, available when
   /// Kind == CK_FunctionTemplate.
   FunctionTemplateDecl *FunctionTemplate;
@@ -1082,6 +1092,12 @@ class CodeCompleteConsumer {
   assert(Function != nullptr);
 }
 
+OverloadCandidate(FunctionDecl *LambdaOperatorParens, VarDecl *LambdaVar)
+: Kind(CK_Lambda), Lambda{LambdaOperatorParens, LambdaVar} {
+  assert(Lambda.OperatorParens != nullptr);
+  assert(Lambda.Var != nullptr);
+}
+
 OverloadCandidate(FunctionTemplateDecl *FunctionTemplateDecl)
 : Kind(CK_FunctionTemplate), FunctionTemplate(FunctionTemplateDecl) {
   assert(FunctionTemplateDecl != nullptr);
@@ -1112,6 +1128,8 @@ class CodeCompleteConsumer {
 /// function declaration for a function template.
 FunctionDecl *getFunction() const;
 
+VarDecl *getLambdaVarDecl() const;
+
 /// Retrieve the function template overload candidate.
 FunctionTemplateDecl *getFunctionTemplate() const {
   assert(getKind() == CK_FunctionTemplate && "Not a function template");
diff --git a/clang/include/clang/Sema/Overload.h 
b/clang/include/clang/Sema/Overload.h
index d6a6cee62a752..7c4e82f07de02 100644
--- a/clang/include/clang/Sema/Overload.h
+++ b/clang/include/clang/Sema/Overload.h
@@ -876,6 +876,11 @@ class Sema;
 /// function pointer or reference (C++ [over.call.object]).
 FunctionDecl *Function;
 
+/// LambdaName - When the OverloadCandidate is for a
+/// lambda's operator(), points to the declaration of
+/// the lambda variable.
+VarDecl *LambdaName{nullptr};
+
 /// FoundDecl - The original declaration that was looked up /
 /// invented / otherwise found, together with its access.
 /// Might be a UsingShadowDecl or a FunctionTemplateDecl.
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 2ec6367eccea0..2cf1827c2

[clang] Warning Libc functions (PR #101583)

2024-08-03 Thread Ziqing Luo via cfe-commits

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

>From 8a8b317c2b1c73117bcbbf771a783338448724a5 Mon Sep 17 00:00:00 2001
From: Ziqing Luo 
Date: Thu, 1 Aug 2024 16:36:27 -0700
Subject: [PATCH 1/2] [-Wunsafe-buffer-usage] Add warn on unsafe calls to libc
 functions

Warning about calls to libc functions involving buffer access.  Warned
functions are hardcoded by names.

(rdar://117182250)
---
 .../Analysis/Analyses/UnsafeBufferUsage.h |   8 +
 .../Analyses/UnsafeBufferUsageGadgets.def |   1 +
 .../clang/Basic/DiagnosticSemaKinds.td|   2 +
 clang/lib/Analysis/UnsafeBufferUsage.cpp  | 322 +-
 clang/lib/Sema/AnalysisBasedWarnings.cpp  |  12 +
 ...arn-unsafe-buffer-usage-libc-functions.cpp |  81 +
 ...n-unsafe-buffer-usage-test-unreachable.cpp |   4 +-
 7 files changed, 425 insertions(+), 5 deletions(-)
 create mode 100644 
clang/test/SemaCXX/warn-unsafe-buffer-usage-libc-functions.cpp

diff --git a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h 
b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
index 228b4ae1e3e11..62d0c6e350f37 100644
--- a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
+++ b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
@@ -15,6 +15,7 @@
 #define LLVM_CLANG_ANALYSIS_ANALYSES_UNSAFEBUFFERUSAGE_H
 
 #include "clang/AST/Decl.h"
+#include "clang/AST/Expr.h"
 #include "clang/AST/Stmt.h"
 #include "clang/Basic/SourceLocation.h"
 #include "llvm/Support/Debug.h"
@@ -106,6 +107,13 @@ class UnsafeBufferUsageHandler {
   virtual void handleUnsafeOperation(const Stmt *Operation,
  bool IsRelatedToDecl, ASTContext &Ctx) = 
0;
 
+  /// Invoked when a call to an unsafe libc function is found.
+  /// \param PrintfInfo is 0 if the callee function is not a member of the
+  /// printf family; is 1 if the callee is `sprintf`; is 2 if
+  /// the callee is other printfs
+  virtual void handleUnsafeLibcCall(const CallExpr *Call, unsigned PrintfInfo,
+ASTContext &Ctx) = 0;
+
   /// Invoked when an unsafe operation with a std container is found.
   virtual void handleUnsafeOperationInContainer(const Stmt *Operation,
 bool IsRelatedToDecl,
diff --git a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def 
b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def
index 242ad763ba62b..ac01b285ae833 100644
--- a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def
+++ b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def
@@ -38,6 +38,7 @@ WARNING_GADGET(PointerArithmetic)
 WARNING_GADGET(UnsafeBufferUsageAttr)
 WARNING_GADGET(UnsafeBufferUsageCtorAttr)
 WARNING_GADGET(DataInvocation)
+WARNING_GADGET(UnsafeLibcFunctionCall)
 WARNING_CONTAINER_GADGET(SpanTwoParamConstructor) // Uses of `std::span(arg0, 
arg1)`
 FIXABLE_GADGET(ULCArraySubscript)  // `DRE[any]` in an Unspecified 
Lvalue Context
 FIXABLE_GADGET(DerefSimplePtrArithFixable)
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 581434d33c5c9..ce77f459fab4f 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12376,6 +12376,8 @@ def warn_unsafe_buffer_operation : Warning<
   "%select{unsafe pointer operation|unsafe pointer arithmetic|"
   "unsafe buffer access|function introduces unsafe buffer manipulation|unsafe 
invocation of span::data}0">,
   InGroup, DefaultIgnore;
+def note_unsafe_buffer_printf_call : Note<
+  "%select{| change to 'snprintf' for explicit bounds checking | use 
'std::string::c_str' as pointer to guarantee null-termination}0">;
 def note_unsafe_buffer_operation : Note<
   "used%select{| in pointer arithmetic| in buffer access}0 here">;
 def note_unsafe_buffer_variable_fixit_group : Note<
diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index 866222380974b..7402cf0f24c1e 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -9,19 +9,21 @@
 #include "clang/Analysis/Analyses/UnsafeBufferUsage.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
 #include "clang/AST/Expr.h"
+#include "clang/AST/ExprCXX.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/Stmt.h"
-#include "clang/AST/StmtVisitor.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
-#include "clang/Basic/CharInfo.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Lex/Lexer.h"
 #include "clang/Lex/Preprocessor.h"
 #include "llvm/ADT/APSInt.h"
+#include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/iterator_range.h"
 #include "llvm/Support/Casting.h"
 #include 
 #include 
@@

[clang] [clang-format] Handle parenthesized list in RemoveParentheses (PR #100852)

2024-08-03 Thread Owen Pan via cfe-commits

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


  1   2   >