[clang] [clang] Support --sysroot= for ${arch}-windows-msvc targets (PR #96417)

2024-08-11 Thread via cfe-commits

trcrsired wrote:

![image](https://github.com/user-attachments/assets/23cb90b1-c47d-4804-af14-676f5a649e15)
See wasm. xxx-windows-gnu. aarch64-linux-android. x86_64-linux-gnu etc. They 
all have exactly the same file structures. I do not see why should 
xxx-windows-msvc should be different from x86_64-windows-gnu. /winsysroot and 
clang-cl thing just complicates everything. The thing that pisses me off is 
that clang does not enforce a standard rule for all targets but every target 
rewrites its rule that needs to stop tbh.

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


[clang] [clang][Interp] Properly adjust instance pointer in virtual calls (PR #102800)

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

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

None

>From 623d80c732da293e8696dbb77cb617b42a49e684 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sun, 11 Aug 2024 09:36:55 +0200
Subject: [PATCH] [clang][Interp] Properly adjust instance pointer in virtual
 calls

---
 clang/lib/AST/Interp/Interp.h |  7 ---
 clang/test/AST/Interp/records.cpp | 24 
 2 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index af33d507ef8d7..67b3fc5064509 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -2633,9 +2633,10 @@ inline bool CallVirt(InterpState &S, CodePtr OpPC, const 
Function *Func,
 ThisPtr.getFieldDesc()->getType()->getAsCXXRecordDecl();
 if (Func->getParentDecl()->isDerivedFrom(ThisFieldDecl)) {
   // If the function we call is further DOWN the hierarchy than the
-  // FieldDesc of our pointer, just get the DeclDesc instead, which
-  // is the furthest we might go up in the hierarchy.
-  ThisPtr = ThisPtr.getDeclPtr();
+  // FieldDesc of our pointer, just go up the hierarchy of this field
+  // the furthest we can go.
+  while (ThisPtr.isBaseClass())
+ThisPtr = ThisPtr.getBase();
 }
   }
 
diff --git a/clang/test/AST/Interp/records.cpp 
b/clang/test/AST/Interp/records.cpp
index 343665003c23e..e620bf9e0e041 100644
--- a/clang/test/AST/Interp/records.cpp
+++ b/clang/test/AST/Interp/records.cpp
@@ -1572,3 +1572,27 @@ namespace ctorOverrider {
   constexpr Covariant1 cb;
 }
 #endif
+
+#if __cplusplus >= 202002L
+namespace VirtDtor {
+  struct X { char *p; constexpr ~X() { *p++ = 'X'; } };
+  struct Y : X { int y; virtual constexpr ~Y() { *p++ = 'Y'; } };
+  struct Z : Y { int z; constexpr ~Z() override { *p++ = 'Z'; } };
+
+  union VU {
+constexpr VU() : z() {}
+constexpr ~VU() {}
+Z z;
+  };
+
+  constexpr char virt_dtor(int mode, const char *expected) {
+char buff[4] = {};
+VU vu;
+vu.z.p = buff;
+
+((Y&)vu.z).~Y();
+return true;
+  }
+  static_assert(virt_dtor(0, "ZYX"));
+}
+#endif

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


[clang] [clang][Interp] Properly adjust instance pointer in virtual calls (PR #102800)

2024-08-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes



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


2 Files Affected:

- (modified) clang/lib/AST/Interp/Interp.h (+4-3) 
- (modified) clang/test/AST/Interp/records.cpp (+24) 


``diff
diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index af33d507ef8d7..67b3fc5064509 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -2633,9 +2633,10 @@ inline bool CallVirt(InterpState &S, CodePtr OpPC, const 
Function *Func,
 ThisPtr.getFieldDesc()->getType()->getAsCXXRecordDecl();
 if (Func->getParentDecl()->isDerivedFrom(ThisFieldDecl)) {
   // If the function we call is further DOWN the hierarchy than the
-  // FieldDesc of our pointer, just get the DeclDesc instead, which
-  // is the furthest we might go up in the hierarchy.
-  ThisPtr = ThisPtr.getDeclPtr();
+  // FieldDesc of our pointer, just go up the hierarchy of this field
+  // the furthest we can go.
+  while (ThisPtr.isBaseClass())
+ThisPtr = ThisPtr.getBase();
 }
   }
 
diff --git a/clang/test/AST/Interp/records.cpp 
b/clang/test/AST/Interp/records.cpp
index 343665003c23e..e620bf9e0e041 100644
--- a/clang/test/AST/Interp/records.cpp
+++ b/clang/test/AST/Interp/records.cpp
@@ -1572,3 +1572,27 @@ namespace ctorOverrider {
   constexpr Covariant1 cb;
 }
 #endif
+
+#if __cplusplus >= 202002L
+namespace VirtDtor {
+  struct X { char *p; constexpr ~X() { *p++ = 'X'; } };
+  struct Y : X { int y; virtual constexpr ~Y() { *p++ = 'Y'; } };
+  struct Z : Y { int z; constexpr ~Z() override { *p++ = 'Z'; } };
+
+  union VU {
+constexpr VU() : z() {}
+constexpr ~VU() {}
+Z z;
+  };
+
+  constexpr char virt_dtor(int mode, const char *expected) {
+char buff[4] = {};
+VU vu;
+vu.z.p = buff;
+
+((Y&)vu.z).~Y();
+return true;
+  }
+  static_assert(virt_dtor(0, "ZYX"));
+}
+#endif

``




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


[clang] [clang][Interp] Properly adjust instance pointer in virtual calls (PR #102800)

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

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


[clang] [clang][Interp][NFC] Add a failing test case (PR #102801)

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

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

None

>From 3085070e4e3ff4a65810123c8489cd31300b19d5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sun, 11 Aug 2024 09:48:35 +0200
Subject: [PATCH] [clang][Interp][NFC] Add a failing test case

---
 clang/test/AST/Interp/cxx20.cpp | 44 +
 1 file changed, 44 insertions(+)

diff --git a/clang/test/AST/Interp/cxx20.cpp b/clang/test/AST/Interp/cxx20.cpp
index 27dbd2818be60f..389d9d883725f4 100644
--- a/clang/test/AST/Interp/cxx20.cpp
+++ b/clang/test/AST/Interp/cxx20.cpp
@@ -858,3 +858,47 @@ namespace DefinitionLoc {
   constexpr NonConstexprCopy ncc2 = ncc1; // both-error {{constant 
expression}} \
   // both-note {{non-constexpr 
constructor}}
 }
+
+/// FIXME: Call base dtors when explicitly calling dtor.
+namespace VirtDtor {
+  class B {
+  public:
+constexpr B(char *p) : p(p) {}
+virtual constexpr ~B() {
+  *p = 'B';
+  ++p;
+}
+
+char *p;
+  };
+
+  class C : public B {
+  public:
+constexpr C(char *p) : B(p) {}
+virtual constexpr ~C() override {
+  *p = 'C';
+  ++p;
+}
+  };
+
+  union U {
+constexpr U(char *p) : c(p) {}
+constexpr ~U() {}
+
+C c;
+  };
+
+  constexpr int test(char a, char b) {
+char buff[2] = {};
+U u(buff);
+
+/// U is a union, so it won't call the destructor of its fields.
+/// We do this manually here. Explicitly calling ~C() here should
+/// also call the destructor of the base classes however.
+u.c.~C();
+
+return buff[0] == a && buff[1] == b;
+  }
+
+  static_assert(test('C', 'B')); // expected-error {{failed}}
+}

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


[clang] [clang][Interp][NFC] Add a failing test case (PR #102801)

2024-08-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes



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


1 Files Affected:

- (modified) clang/test/AST/Interp/cxx20.cpp (+44) 


``diff
diff --git a/clang/test/AST/Interp/cxx20.cpp b/clang/test/AST/Interp/cxx20.cpp
index 27dbd2818be60..389d9d883725f 100644
--- a/clang/test/AST/Interp/cxx20.cpp
+++ b/clang/test/AST/Interp/cxx20.cpp
@@ -858,3 +858,47 @@ namespace DefinitionLoc {
   constexpr NonConstexprCopy ncc2 = ncc1; // both-error {{constant 
expression}} \
   // both-note {{non-constexpr 
constructor}}
 }
+
+/// FIXME: Call base dtors when explicitly calling dtor.
+namespace VirtDtor {
+  class B {
+  public:
+constexpr B(char *p) : p(p) {}
+virtual constexpr ~B() {
+  *p = 'B';
+  ++p;
+}
+
+char *p;
+  };
+
+  class C : public B {
+  public:
+constexpr C(char *p) : B(p) {}
+virtual constexpr ~C() override {
+  *p = 'C';
+  ++p;
+}
+  };
+
+  union U {
+constexpr U(char *p) : c(p) {}
+constexpr ~U() {}
+
+C c;
+  };
+
+  constexpr int test(char a, char b) {
+char buff[2] = {};
+U u(buff);
+
+/// U is a union, so it won't call the destructor of its fields.
+/// We do this manually here. Explicitly calling ~C() here should
+/// also call the destructor of the base classes however.
+u.c.~C();
+
+return buff[0] == a && buff[1] == b;
+  }
+
+  static_assert(test('C', 'B')); // expected-error {{failed}}
+}

``




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


[clang] 712ab80 - [clang][Interp] Properly adjust instance pointer in virtual calls (#102800)

2024-08-11 Thread via cfe-commits

Author: Timm Baeder
Date: 2024-08-11T10:09:03+02:00
New Revision: 712ab805140068a7b4719a38de3fee904841dbb3

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

LOG: [clang][Interp] Properly adjust instance pointer in virtual calls (#102800)

`getDeclPtr()` will not just return what we want, but in this case a
pointer to the `vu` local variable.

Added: 


Modified: 
clang/lib/AST/Interp/Interp.h
clang/test/AST/Interp/records.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index af33d507ef8d7..67b3fc5064509 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -2633,9 +2633,10 @@ inline bool CallVirt(InterpState &S, CodePtr OpPC, const 
Function *Func,
 ThisPtr.getFieldDesc()->getType()->getAsCXXRecordDecl();
 if (Func->getParentDecl()->isDerivedFrom(ThisFieldDecl)) {
   // If the function we call is further DOWN the hierarchy than the
-  // FieldDesc of our pointer, just get the DeclDesc instead, which
-  // is the furthest we might go up in the hierarchy.
-  ThisPtr = ThisPtr.getDeclPtr();
+  // FieldDesc of our pointer, just go up the hierarchy of this field
+  // the furthest we can go.
+  while (ThisPtr.isBaseClass())
+ThisPtr = ThisPtr.getBase();
 }
   }
 

diff  --git a/clang/test/AST/Interp/records.cpp 
b/clang/test/AST/Interp/records.cpp
index 343665003c23e..e620bf9e0e041 100644
--- a/clang/test/AST/Interp/records.cpp
+++ b/clang/test/AST/Interp/records.cpp
@@ -1572,3 +1572,27 @@ namespace ctorOverrider {
   constexpr Covariant1 cb;
 }
 #endif
+
+#if __cplusplus >= 202002L
+namespace VirtDtor {
+  struct X { char *p; constexpr ~X() { *p++ = 'X'; } };
+  struct Y : X { int y; virtual constexpr ~Y() { *p++ = 'Y'; } };
+  struct Z : Y { int z; constexpr ~Z() override { *p++ = 'Z'; } };
+
+  union VU {
+constexpr VU() : z() {}
+constexpr ~VU() {}
+Z z;
+  };
+
+  constexpr char virt_dtor(int mode, const char *expected) {
+char buff[4] = {};
+VU vu;
+vu.z.p = buff;
+
+((Y&)vu.z).~Y();
+return true;
+  }
+  static_assert(virt_dtor(0, "ZYX"));
+}
+#endif



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


[clang] [clang][Interp] Properly adjust instance pointer in virtual calls (PR #102800)

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

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


[clang] 2a00bf4 - [clang][Interp][NFC] Add a failing test case (#102801)

2024-08-11 Thread via cfe-commits

Author: Timm Baeder
Date: 2024-08-11T10:18:01+02:00
New Revision: 2a00bf412efec1f87fed0762ee42dd7a6b809cbb

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

LOG: [clang][Interp][NFC] Add a failing test case (#102801)

Added: 


Modified: 
clang/test/AST/Interp/cxx20.cpp

Removed: 




diff  --git a/clang/test/AST/Interp/cxx20.cpp b/clang/test/AST/Interp/cxx20.cpp
index 27dbd2818be60..389d9d883725f 100644
--- a/clang/test/AST/Interp/cxx20.cpp
+++ b/clang/test/AST/Interp/cxx20.cpp
@@ -858,3 +858,47 @@ namespace DefinitionLoc {
   constexpr NonConstexprCopy ncc2 = ncc1; // both-error {{constant 
expression}} \
   // both-note {{non-constexpr 
constructor}}
 }
+
+/// FIXME: Call base dtors when explicitly calling dtor.
+namespace VirtDtor {
+  class B {
+  public:
+constexpr B(char *p) : p(p) {}
+virtual constexpr ~B() {
+  *p = 'B';
+  ++p;
+}
+
+char *p;
+  };
+
+  class C : public B {
+  public:
+constexpr C(char *p) : B(p) {}
+virtual constexpr ~C() override {
+  *p = 'C';
+  ++p;
+}
+  };
+
+  union U {
+constexpr U(char *p) : c(p) {}
+constexpr ~U() {}
+
+C c;
+  };
+
+  constexpr int test(char a, char b) {
+char buff[2] = {};
+U u(buff);
+
+/// U is a union, so it won't call the destructor of its fields.
+/// We do this manually here. Explicitly calling ~C() here should
+/// also call the destructor of the base classes however.
+u.c.~C();
+
+return buff[0] == a && buff[1] == b;
+  }
+
+  static_assert(test('C', 'B')); // expected-error {{failed}}
+}



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


[clang] [clang][Interp][NFC] Add a failing test case (PR #102801)

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

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


[clang] [clang][Interp] Propagate InUnion flag to base classes (PR #102804)

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

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

None

>From d44bc6ce6fdcd6607b987a74c417e48daf304124 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sun, 11 Aug 2024 10:25:12 +0200
Subject: [PATCH] [clang][Interp] Propagate InUnion flag to base classes

---
 clang/lib/AST/Interp/Descriptor.cpp | 11 ++-
 clang/test/AST/Interp/unions.cpp| 23 +++
 2 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/clang/lib/AST/Interp/Descriptor.cpp 
b/clang/lib/AST/Interp/Descriptor.cpp
index 634413b2f2f52..1b7d9f03f8ef0 100644
--- a/clang/lib/AST/Interp/Descriptor.cpp
+++ b/clang/lib/AST/Interp/Descriptor.cpp
@@ -171,30 +171,31 @@ static void initBase(Block *B, std::byte *Ptr, bool 
IsConst, bool IsMutable,
  unsigned FieldOffset, bool IsVirtualBase) {
   assert(D);
   assert(D->ElemRecord);
+  assert(!D->ElemRecord->isUnion()); // Unions cannot be base classes.
 
-  bool IsUnion = D->ElemRecord->isUnion();
   auto *Desc = reinterpret_cast(Ptr + FieldOffset) - 1;
   Desc->Offset = FieldOffset;
   Desc->Desc = D;
   Desc->IsInitialized = D->IsArray;
   Desc->IsBase = true;
   Desc->IsVirtualBase = IsVirtualBase;
-  Desc->IsActive = IsActive && !IsUnion;
+  Desc->IsActive = IsActive && !InUnion;
   Desc->IsConst = IsConst || D->IsConst;
   Desc->IsFieldMutable = IsMutable || D->IsMutable;
+  Desc->InUnion = InUnion;
 
   for (const auto &V : D->ElemRecord->bases())
 initBase(B, Ptr + FieldOffset, IsConst, IsMutable, IsActive, InUnion,
  V.Desc, V.Offset, false);
   for (const auto &F : D->ElemRecord->fields())
 initField(B, Ptr + FieldOffset, IsConst, IsMutable, IsActive, InUnion,
-  IsUnion, F.Desc, F.Offset);
+  InUnion, F.Desc, F.Offset);
 }
 
 static void ctorRecord(Block *B, std::byte *Ptr, bool IsConst, bool IsMutable,
bool IsActive, bool InUnion, const Descriptor *D) {
   for (const auto &V : D->ElemRecord->bases())
-initBase(B, Ptr, IsConst, IsMutable, IsActive, false, V.Desc, V.Offset,
+initBase(B, Ptr, IsConst, IsMutable, IsActive, InUnion, V.Desc, V.Offset,
  false);
   for (const auto &F : D->ElemRecord->fields()) {
 bool IsUnionField = D->isUnion();
@@ -202,7 +203,7 @@ static void ctorRecord(Block *B, std::byte *Ptr, bool 
IsConst, bool IsMutable,
   InUnion || IsUnionField, F.Desc, F.Offset);
   }
   for (const auto &V : D->ElemRecord->virtual_bases())
-initBase(B, Ptr, IsConst, IsMutable, IsActive, false, V.Desc, V.Offset,
+initBase(B, Ptr, IsConst, IsMutable, IsActive, InUnion, V.Desc, V.Offset,
  true);
 }
 
diff --git a/clang/test/AST/Interp/unions.cpp b/clang/test/AST/Interp/unions.cpp
index 4c60c2c0810d4..996d29e143fe2 100644
--- a/clang/test/AST/Interp/unions.cpp
+++ b/clang/test/AST/Interp/unions.cpp
@@ -358,4 +358,27 @@ namespace CopyCtor {
   static_assert(y.b == 42, ""); // both-error {{constant expression}} \
 // both-note {{'b' of union with active member 
'a'}}
 }
+
+namespace UnionInBase {
+  struct Base {
+int y;
+  };
+  struct A : Base {
+int x;
+int arr[3];
+union { int p, q; };
+  };
+  union B {
+A a;
+int b;
+  };
+  constexpr int read_wrong_member_indirect() { // both-error {{never produces 
a constant}}
+B b = {.b = 1};
+int *p = &b.a.y;
+return *p; // both-note 2{{read of member 'a' of union with active member 
'b'}}
+
+  }
+  static_assert(read_wrong_member_indirect() == 1); // both-error {{not an 
integral constant expression}} \
+// both-note {{in call to}}
+}
 #endif

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


[clang] [clang][Interp] Propagate InUnion flag to base classes (PR #102804)

2024-08-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes



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


2 Files Affected:

- (modified) clang/lib/AST/Interp/Descriptor.cpp (+6-5) 
- (modified) clang/test/AST/Interp/unions.cpp (+23) 


``diff
diff --git a/clang/lib/AST/Interp/Descriptor.cpp 
b/clang/lib/AST/Interp/Descriptor.cpp
index 634413b2f2f52..1b7d9f03f8ef0 100644
--- a/clang/lib/AST/Interp/Descriptor.cpp
+++ b/clang/lib/AST/Interp/Descriptor.cpp
@@ -171,30 +171,31 @@ static void initBase(Block *B, std::byte *Ptr, bool 
IsConst, bool IsMutable,
  unsigned FieldOffset, bool IsVirtualBase) {
   assert(D);
   assert(D->ElemRecord);
+  assert(!D->ElemRecord->isUnion()); // Unions cannot be base classes.
 
-  bool IsUnion = D->ElemRecord->isUnion();
   auto *Desc = reinterpret_cast(Ptr + FieldOffset) - 1;
   Desc->Offset = FieldOffset;
   Desc->Desc = D;
   Desc->IsInitialized = D->IsArray;
   Desc->IsBase = true;
   Desc->IsVirtualBase = IsVirtualBase;
-  Desc->IsActive = IsActive && !IsUnion;
+  Desc->IsActive = IsActive && !InUnion;
   Desc->IsConst = IsConst || D->IsConst;
   Desc->IsFieldMutable = IsMutable || D->IsMutable;
+  Desc->InUnion = InUnion;
 
   for (const auto &V : D->ElemRecord->bases())
 initBase(B, Ptr + FieldOffset, IsConst, IsMutable, IsActive, InUnion,
  V.Desc, V.Offset, false);
   for (const auto &F : D->ElemRecord->fields())
 initField(B, Ptr + FieldOffset, IsConst, IsMutable, IsActive, InUnion,
-  IsUnion, F.Desc, F.Offset);
+  InUnion, F.Desc, F.Offset);
 }
 
 static void ctorRecord(Block *B, std::byte *Ptr, bool IsConst, bool IsMutable,
bool IsActive, bool InUnion, const Descriptor *D) {
   for (const auto &V : D->ElemRecord->bases())
-initBase(B, Ptr, IsConst, IsMutable, IsActive, false, V.Desc, V.Offset,
+initBase(B, Ptr, IsConst, IsMutable, IsActive, InUnion, V.Desc, V.Offset,
  false);
   for (const auto &F : D->ElemRecord->fields()) {
 bool IsUnionField = D->isUnion();
@@ -202,7 +203,7 @@ static void ctorRecord(Block *B, std::byte *Ptr, bool 
IsConst, bool IsMutable,
   InUnion || IsUnionField, F.Desc, F.Offset);
   }
   for (const auto &V : D->ElemRecord->virtual_bases())
-initBase(B, Ptr, IsConst, IsMutable, IsActive, false, V.Desc, V.Offset,
+initBase(B, Ptr, IsConst, IsMutable, IsActive, InUnion, V.Desc, V.Offset,
  true);
 }
 
diff --git a/clang/test/AST/Interp/unions.cpp b/clang/test/AST/Interp/unions.cpp
index 4c60c2c0810d4..996d29e143fe2 100644
--- a/clang/test/AST/Interp/unions.cpp
+++ b/clang/test/AST/Interp/unions.cpp
@@ -358,4 +358,27 @@ namespace CopyCtor {
   static_assert(y.b == 42, ""); // both-error {{constant expression}} \
 // both-note {{'b' of union with active member 
'a'}}
 }
+
+namespace UnionInBase {
+  struct Base {
+int y;
+  };
+  struct A : Base {
+int x;
+int arr[3];
+union { int p, q; };
+  };
+  union B {
+A a;
+int b;
+  };
+  constexpr int read_wrong_member_indirect() { // both-error {{never produces 
a constant}}
+B b = {.b = 1};
+int *p = &b.a.y;
+return *p; // both-note 2{{read of member 'a' of union with active member 
'b'}}
+
+  }
+  static_assert(read_wrong_member_indirect() == 1); // both-error {{not an 
integral constant expression}} \
+// both-note {{in call to}}
+}
 #endif

``




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


[clang] [clang][Interp] Properly adjust instance pointer in virtual calls (PR #102800)

2024-08-11 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/1748

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)
...
[8/20] Building CXX object 
tools\lld\Common\CMakeFiles\lldCommon.dir\Version.cpp.obj
[9/20] Linking CXX static library lib\lldCommon.lib
[10/20] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\Context.cpp.obj
[11/20] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\InterpBuiltin.cpp.obj
[12/20] Building CXX object 
lib\CodeGen\AsmPrinter\CMakeFiles\LLVMAsmPrinter.dir\AsmPrinter.cpp.obj
[13/20] Linking CXX static library lib\LLVMAsmPrinter.lib
[14/20] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\EvalEmitter.cpp.obj
[15/20] Building CXX object lib\LTO\CMakeFiles\LLVMLTO.dir\LTO.cpp.obj
[16/20] Linking CXX static library lib\LLVMLTO.lib
[17/20] Linking CXX executable bin\lld.exe
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=1257.266000
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/20] Generating VCSRevision.h
[2/20] Generating VCSVersion.inc
[3/20] Building CXX object 
tools\clang\lib\Basic\CMakeFiles\obj.clangBasic.dir\Version.cpp.obj
[4/20] Building CXX object lib\Object\CMakeFiles\LLVMObject.dir\IRSymtab.cpp.obj
[5/20] Linking CXX static library lib\LLVMObject.lib
[6/20] Generating VCSVersion.inc
[7/20] Linking CXX static library lib\clangBasic.lib
[8/20] Building CXX object 
tools\lld\Common\CMakeFiles\lldCommon.dir\Version.cpp.obj
[9/20] Linking CXX static library lib\lldCommon.lib
[10/20] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\Context.cpp.obj
[11/20] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\InterpBuiltin.cpp.obj
[12/20] Building CXX object 
lib\CodeGen\AsmPrinter\CMakeFiles\LLVMAsmPrinter.dir\AsmPrinter.cpp.obj
[13/20] Linking CXX static library lib\LLVMAsmPrinter.lib
[14/20] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\EvalEmitter.cpp.obj
[15/20] Building CXX object lib\LTO\CMakeFiles\LLVMLTO.dir\LTO.cpp.obj
[16/20] Linking CXX static library lib\LLVMLTO.lib
[17/20] Linking CXX executable bin\lld.exe

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=1257.266000

```

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


[clang] #101784 part 2: fix error handling of TranslationUnit.reparse (PR #102410)

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

https://github.com/DeinAlptraum commented:

A couple minor comments, and the code formatting should be fixed (see output of 
the failing CI run), and then this is good to go!

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


[clang] #101784 part 2: fix error handling of TranslationUnit.reparse (PR #102410)

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

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


[clang] #101784 part 2: fix error handling of TranslationUnit.reparse (PR #102410)

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


@@ -161,7 +161,34 @@ class TranslationUnitLoadError(Exception):
 FIXME: Make libclang expose additional error information in this scenario.

DeinAlptraum wrote:

I would say your change resolves the `FIXME` here. Thanks for expanding this to 
the `create`/`parse` functions as well!

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


[clang] #101784 part 2: fix error handling of TranslationUnit.reparse (PR #102410)

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


@@ -59,6 +59,9 @@ Clang Python Bindings Potentially Breaking Changes
 - Calling a property on the `CompletionChunk` or `CompletionString` class
   statically now leads to an error, instead of returning a `CachedProperty` 
object
   that is used internally. Properties are only available on instances.
+- `TranslationUnitLoadError` now contains an error code in `error_code`
+  attribute. Also, `TranslationUnit.reparse` will throw 
`TranslationUnitLoadError`
+  when operation fails.

DeinAlptraum wrote:

Code highlighting should be in double ` (yes the example above that did it 
incorrectly... will fix)

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


[clang] #101784 part 2: fix error handling of TranslationUnit.reparse (PR #102410)

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


@@ -161,7 +161,34 @@ class TranslationUnitLoadError(Exception):
 FIXME: Make libclang expose additional error information in this scenario.
 """
 
-pass
+# A generic error code, no further details are available.
+#
+# Errors of this kind can get their own specific error codes in future
+# libclang versions.
+ERROR_FAILURE = 1
+
+# libclang crashed while performing the requested operation.
+ERROR_CRASHED = 2
+
+# The function detected that the arguments violate the function
+# contract.
+ERROR_INVALID_ARGUMENTS = 3
+
+# An AST deserialization error has occurred.
+ERROR_AST_READ_ERROR = 4
+
+def __init__(self, enumeration: int, message: str):
+assert isinstance(enumeration, int)
+
+if enumeration < 1 or enumeration > 4:
+raise Exception(
+"Encountered undefined CXError "
+"constant: %d. Please file a bug to have this "
+"value supported." % enumeration
+)
+
+self.error_code = enumeration
+Exception.__init__(self, "Error %d: %s" % (enumeration or 0, message))

DeinAlptraum wrote:

What do you need the `or 0` for?

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


[clang] #101784 part 2: fix error handling of TranslationUnit.reparse (PR #102410)

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


@@ -149,8 +149,8 @@ def b(x: str | bytes) -> bytes:
 # this by marshalling object arguments as void**.
 c_object_p: TType[_Pointer[Any]] = POINTER(c_void_p)
 
-### Exception Classes ###
 
+### Exception Classes ###

DeinAlptraum wrote:

Unnecessary whitespace changes

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


[clang] [NFC][libclang/python] Fix code highlighting in release notes (PR #102807)

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

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

This corrects a release note introduced in #98745

>From 64212e4c8afe2ad75144bf36a1212c4e417dd8c9 Mon Sep 17 00:00:00 2001
From: Jannick Kremer 
Date: Sun, 11 Aug 2024 11:00:52 +0200
Subject: [PATCH] [NFC][libclang/python] Fix code highlighting in release notes

This corrects a release note introduced in #98745
---
 clang/docs/ReleaseNotes.rst | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d002a9c747dd6..6796a619ba97f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -61,9 +61,9 @@ Clang Frontend Potentially Breaking Changes
 Clang Python Bindings Potentially Breaking Changes
 --
 - Parts of the interface returning string results will now return
-  the empty string `""` when no result is available, instead of `None`.
-- Calling a property on the `CompletionChunk` or `CompletionString` class
-  statically now leads to an error, instead of returning a `CachedProperty` 
object
+  the empty string ``""`` when no result is available, instead of ``None``.
+- Calling a property on the ``CompletionChunk`` or ``CompletionString`` class
+  statically now leads to an error, instead of returning a ``CachedProperty`` 
object
   that is used internally. Properties are only available on instances.
 
 What's New in Clang |release|?

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


[clang] [NFC][libclang/python] Fix code highlighting in release notes (PR #102807)

2024-08-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Jannick Kremer (DeinAlptraum)


Changes

This corrects a release note introduced in #98745

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


1 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+3-3) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d002a9c747dd6..6796a619ba97f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -61,9 +61,9 @@ Clang Frontend Potentially Breaking Changes
 Clang Python Bindings Potentially Breaking Changes
 --
 - Parts of the interface returning string results will now return
-  the empty string `""` when no result is available, instead of `None`.
-- Calling a property on the `CompletionChunk` or `CompletionString` class
-  statically now leads to an error, instead of returning a `CachedProperty` 
object
+  the empty string ``""`` when no result is available, instead of ``None``.
+- Calling a property on the ``CompletionChunk`` or ``CompletionString`` class
+  statically now leads to an error, instead of returning a ``CachedProperty`` 
object
   that is used internally. Properties are only available on instances.
 
 What's New in Clang |release|?

``




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


[clang] [clang][Interp][NFC] Add a failing test case (PR #102801)

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

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `lldb-aarch64-windows` 
running on `linaro-armv8-windows-msvc-05` while building `clang` at step 6 
"test".

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

Here is the relevant piece of the build log for the reference:
```
Step 6 (test) failure: build (failure)
...
PASS: lldb-api :: 
tools/lldb-dap/variables/children/TestDAP_variables_children.py (1147 of 1998)
UNSUPPORTED: lldb-api :: tools/lldb-server/TestGdbRemoteAuxvSupport.py (1148 of 
1998)
PASS: lldb-api :: tools/lldb-server/TestGdbRemoteAttach.py (1149 of 1998)
PASS: lldb-api :: tools/lldb-server/TestGdbRemoteCompletion.py (1150 of 1998)
PASS: lldb-api :: tools/lldb-server/TestGdbRemoteExitCode.py (1151 of 1998)
UNSUPPORTED: lldb-api :: tools/lldb-server/TestGdbRemoteFork.py (1152 of 1998)
UNSUPPORTED: lldb-api :: tools/lldb-server/TestGdbRemoteForkNonStop.py (1153 of 
1998)
PASS: lldb-api :: tools/lldb-server/TestGdbRemoteHostInfo.py (1154 of 1998)
PASS: lldb-api :: tools/lldb-server/TestGdbRemoteExpeditedRegisters.py (1155 of 
1998)
PASS: lldb-api :: tools/lldb-server/TestGdbRemoteKill.py (1156 of 1998)
FAIL: lldb-api :: tools/lldb-server/TestGdbRemoteLaunch.py (1157 of 1998)
 TEST 'lldb-api :: 
tools/lldb-server/TestGdbRemoteLaunch.py' FAILED 
Script:
--
C:/Users/tcwg/scoop/apps/python/current/python.exe 
C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/llvm-project/lldb\test\API\dotest.py
 -u CXXFLAGS -u CFLAGS --env 
OBJCOPY=C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/./bin/llvm-objcopy.exe
 --env LLVM_LIBS_DIR=C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/./lib 
--env 
LLVM_INCLUDE_DIR=C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/include 
--env LLVM_TOOLS_DIR=C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/./bin 
--arch aarch64 --build-dir 
C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/lldb-test-build.noindex 
--lldb-module-cache-dir 
C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/lldb-test-build.noindex/module-cache-lldb\lldb-api
 --clang-module-cache-dir 
C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/lldb-test-build.noindex/module-cache-clang\lldb-api
 --executable 
C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/./bin/lldb.exe --compiler 
C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/./bin/clang.exe --dsymutil 
C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/./bin/dsymutil.exe 
--llvm-tools-dir C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/./bin 
--lldb-obj-root C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/tools/lldb 
--lldb-libs-dir C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/./lib 
--skip-category=watchpoint 
C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\lldb\test\API\tools\lldb-server
 -p TestGdbRemoteLaunch.py
--
Exit Code: 1

Command Output (stdout):
--
lldb version 20.0.0git (https://github.com/llvm/llvm-project.git revision 
2a00bf412efec1f87fed0762ee42dd7a6b809cbb)
  clang revision 2a00bf412efec1f87fed0762ee42dd7a6b809cbb
  llvm revision 2a00bf412efec1f87fed0762ee42dd7a6b809cbb
Skipping the following test categories: ['watchpoint', 'libc++', 'libstdcxx', 
'dwo', 'dsym', 'gmodules', 'debugserver', 'objc', 'fork', 'pexpect']


--
Command Output (stderr):
--
UNSUPPORTED: LLDB 
(C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\build\bin\clang.exe-aarch64) :: 
test_QEnvironmentHexEncoded_llgs 
(TestGdbRemoteLaunch.GdbRemoteLaunchTestCase.test_QEnvironmentHexEncoded_llgs) 
(skip on windows) 

UNSUPPORTED: LLDB 
(C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\build\bin\clang.exe-aarch64) :: 
test_QEnvironment_llgs 
(TestGdbRemoteLaunch.GdbRemoteLaunchTestCase.test_QEnvironment_llgs) (skip on 
windows) 

PASS: LLDB 
(C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\build\bin\clang.exe-aarch64) :: 
test_launch_failure_via_vRun_llgs 
(TestGdbRemoteLaunch.GdbRemoteLaunchTestCase.test_launch_failure_via_vRun_llgs)

UNSUPPORTED: LLDB 
(C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\build\bin\clang.exe-aarch64) :: 
test_launch_via_A_llgs 
(TestGdbRemoteLaunch.GdbRemoteLaunchTestCase.test_launch_via_A_llgs) (skip on 
windows) 

UNSUPPORTED: LLDB 
(C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\build\bin\clang.exe-aarch64) :: 
test_launch_via_vRun_llgs 
(TestGdbRemoteLaunch.GdbRemoteLaunchTestCase.test_launch_via_vRun_llgs) (skip 
on windows) 

FAIL: LLDB 
(C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\build\bin\clang.exe-aarch64) :: 
test_launch_via_vRun_no_args_llgs 
(TestGdbRemoteLaunch.GdbRemoteLaunchTestCase.test_launch_via_vRun_no_args_llgs)

==

FAIL: test_launch_via_vRun_no_args_llgs 
(TestGdbRemoteLaunch.GdbRemoteLaunchTestCase.test_launch_via_vRun_no_args_llgs)

--

Traceback (most recent call last):


```

https://github.com/llvm/llvm-project/pull/102801
__

[clang] a245a98 - [NFC][libclang/python] Fix code highlighting in release notes (#102807)

2024-08-11 Thread via cfe-commits

Author: Jannick Kremer
Date: 2024-08-11T11:39:29+02:00
New Revision: a245a984fd41bc4e9ae225219cb7859d53cd83a4

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

LOG: [NFC][libclang/python] Fix code highlighting in release notes (#102807)

This corrects a release note introduced in #98745

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d002a9c747dd6..6796a619ba97f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -61,9 +61,9 @@ Clang Frontend Potentially Breaking Changes
 Clang Python Bindings Potentially Breaking Changes
 --
 - Parts of the interface returning string results will now return
-  the empty string `""` when no result is available, instead of `None`.
-- Calling a property on the `CompletionChunk` or `CompletionString` class
-  statically now leads to an error, instead of returning a `CachedProperty` 
object
+  the empty string ``""`` when no result is available, instead of ``None``.
+- Calling a property on the ``CompletionChunk`` or ``CompletionString`` class
+  statically now leads to an error, instead of returning a ``CachedProperty`` 
object
   that is used internally. Properties are only available on instances.
 
 What's New in Clang |release|?



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


[clang] [NFC][libclang/python] Fix code highlighting in release notes (PR #102807)

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

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


[clang] [NFC][libclang/python] Fix code highlighting in release notes (PR #102807)

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

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `sanitizer-x86_64-linux` 
running on `sanitizer-buildbot2` while building `clang` at step 2 "annotate".

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

Here is the relevant piece of the build log for the reference:
```
Step 2 (annotate) failure: 'python 
../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py'
 (failure)
...
[373/378] Generating MSAN_INST_GTEST.gtest-all.cc.x86_64.o
[374/378] Generating MSAN_INST_TEST_OBJECTS.msan_test.cpp.x86_64-with-call.o
[375/378] Generating Msan-x86_64-with-call-Test
[376/378] Generating MSAN_INST_TEST_OBJECTS.msan_test.cpp.x86_64.o
[377/378] Generating Msan-x86_64-Test
[377/378] Running compiler_rt regression tests
llvm-lit: 
/home/b/sanitizer-x86_64-linux/build/llvm-project/llvm/utils/lit/lit/discovery.py:276:
 warning: input 
'/home/b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/rtsan/X86_64LinuxConfig'
 contained no tests
llvm-lit: 
/home/b/sanitizer-x86_64-linux/build/llvm-project/llvm/utils/lit/lit/main.py:72:
 note: The test suite configuration requested an individual test timeout of 0 
seconds but a timeout of 900 seconds was requested on the command line. Forcing 
timeout to be 900 seconds.
-- Testing: 4495 of 10175 tests, 88 workers --
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60
FAIL: SanitizerCommon-lsan-i386-Linux :: Linux/soft_rss_limit_mb_test.cpp (2918 
of 4495)
 TEST 'SanitizerCommon-lsan-i386-Linux :: 
Linux/soft_rss_limit_mb_test.cpp' FAILED 
Exit Code: 1

Command Output (stderr):
--
RUN: at line 2: /home/b/sanitizer-x86_64-linux/build/build_default/./bin/clang  
--driver-mode=g++ -gline-tables-only -fsanitize=leak  -m32 -funwind-tables  
-I/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test -ldl -O2 
/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Linux/soft_rss_limit_mb_test.cpp
 -o 
/home/b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/lsan-i386-Linux/Linux/Output/soft_rss_limit_mb_test.cpp.tmp
+ /home/b/sanitizer-x86_64-linux/build/build_default/./bin/clang 
--driver-mode=g++ -gline-tables-only -fsanitize=leak -m32 -funwind-tables 
-I/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test -ldl -O2 
/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Linux/soft_rss_limit_mb_test.cpp
 -o 
/home/b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/lsan-i386-Linux/Linux/Output/soft_rss_limit_mb_test.cpp.tmp
RUN: at line 5: env 
LSAN_OPTIONS=soft_rss_limit_mb=220:quarantine_size=1:allocator_may_return_null=1
  
/home/b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/lsan-i386-Linux/Linux/Output/soft_rss_limit_mb_test.cpp.tmp
 2>&1 | FileCheck 
/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Linux/soft_rss_limit_mb_test.cpp
 -check-prefix=CHECK_MAY_RETURN_1
+ env 
LSAN_OPTIONS=soft_rss_limit_mb=220:quarantine_size=1:allocator_may_return_null=1
 
/home/b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/lsan-i386-Linux/Linux/Output/soft_rss_limit_mb_test.cpp.tmp
+ FileCheck 
/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Linux/soft_rss_limit_mb_test.cpp
 -check-prefix=CHECK_MAY_RETURN_1
/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Linux/soft_rss_limit_mb_test.cpp:68:24:
 error: CHECK_MAY_RETURN_1: expected string not found in input
// CHECK_MAY_RETURN_1: allocating 512 times
   ^
:52:44: note: scanning from here
Some of the malloc calls returned non-null: 256
   ^
:52:45: note: possible intended match here
Some of the malloc calls returned non-null: 256
^

Input file: 
Check file: 
/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Linux/soft_rss_limit_mb_test.cpp

-dump-input=help explains the following input dump.

Input was:
<<
.
.
.
   47:  [256] 
   48:  [320] 
   49:  [384] 
   50:  [448] 
   51: Some of the malloc calls returned null: 256 
   52: Some of the malloc calls returned non-null: 256 
check:68'0X error: no match 
found
check:68'1 ?possible 
intended match
Step 11 (test compiler-rt debug) failure: test compiler-rt debug (failure)
...
[373/378] Generating MSAN_INST_GTEST.gtest-all.cc.x86_64.o
[374/378] Generating MSAN_INST_TEST_OBJECTS

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

2024-08-11 Thread via cfe-commits

cor3ntin wrote:

https://cplusplus.github.io/LWG/issue4138

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


[clang] [NFC][libclang/python] Fix code highlighting in release notes (PR #102807)

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

DeinAlptraum wrote:

Unrelated, this change only touched release notes

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


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

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

MitalAshok wrote:

@cor3ntin A `void*` can be a pointer to an object but `void*` is not a 
pointer-to-object type. `is_object_v` -> `is_object_v || is_void_v` or 
`!is_function_v`

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


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

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

Long5hot wrote:

We were compiling simple testcase with complex parameters with clang and it was 
crashing because libraries was built using gcc.

@AaronBallman, Reason for new flag was to enable this for other C standards as 
well. Currently we use c11 as standard in VxWorks toolchain, which has to work 
with gcc compiled libraries.
gcc with c11 as well passes complex parameters in GPRs.



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-tools-extra] [compiler-rt] [flang] [libclc] [lld] [llvm] [mlir] [openmp] [polly] 同步 (PR #102810)

2024-08-11 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/102810
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [compiler-rt] [flang] [libclc] [lld] [llvm] [mlir] [openmp] [polly] 同步 (PR #102810)

2024-08-11 Thread via cfe-commits

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


[clang] [clang][HLSL] Add sign intrinsic part 3 (PR #101989)

2024-08-11 Thread Tim Gymnich via cfe-commits


@@ -1725,5 +1725,76 @@ _HLSL_AVAILABILITY(shadermodel, 6.0)
 _HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_get_lane_index)
 __attribute__((convergent)) uint WaveGetLaneIndex();
 
+//===--===//
+// sign builtins
+//===--===//
+
+/// \fn T sign(T Val)
+/// \brief Returns -1 if \a Val is less than zero; 0 if \a Val equals zero; and
+/// 1 if \a Val is greater than zero. \param Val The input value.
+
+#ifdef __HLSL_ENABLE_16_BIT
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+int16_t sign(int16_t);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+int16_t2 sign(int16_t2);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+int16_t3 sign(int16_t3);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+int16_t4 sign(int16_t4);
+#endif
+
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+half sign(half);
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+half2 sign(half2);
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+half3 sign(half3);
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+half4 sign(half4);
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+int sign(int);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+int2 sign(int2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+int3 sign(int3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+int4 sign(int4);
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+float sign(float);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+float2 sign(float2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+float3 sign(float3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+float4 sign(float4);
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+int64_t sign(int64_t);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+int64_t2 sign(int64_t2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+int64_t3 sign(int64_t3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+int64_t4 sign(int64_t4);
+

tgymnich wrote:

I left out `uint` on purpose, since that would require adding more intrinsics 
e.g. `int_dx_usign` and `int_spv_usign`. Maybe always casting to a signed type 
before calling `sign` would also work.

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


[clang] [clang][HLSL] Add sign intrinsic part 3 (PR #101989)

2024-08-11 Thread Tim Gymnich via cfe-commits


@@ -1108,6 +1117,14 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned 
BuiltinID, CallExpr *TheCall) {
   return true;
 break;
   }
+  case Builtin::BI__builtin_hlsl_elementwise_sign: {
+if (CheckFloatingOrSignedIntRepresentation(&SemaRef, TheCall))
+  return true;
+if (SemaRef.PrepareBuiltinElementwiseMathOneArgCall(TheCall))
+  return true;
+SetElementTypeAsReturnType(&SemaRef, TheCall, getASTContext().IntTy);

tgymnich wrote:

The return type will either be a scalar int or a int vector, based on the shape 
of the first argument. 

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


[clang] [clang][HLSL] Add sign intrinsic part 3 (PR #101989)

2024-08-11 Thread Tim Gymnich via cfe-commits

https://github.com/tgymnich updated 
https://github.com/llvm/llvm-project/pull/101989

>From c7f7a3683805c6a9a1d696905321a1e161ec8beb Mon Sep 17 00:00:00 2001
From: Tim Gymnich 
Date: Fri, 2 Aug 2024 21:40:24 +0200
Subject: [PATCH 1/4] [clang][HLSL] Add sign intrinsic part 3

---
 clang/include/clang/Basic/Builtins.td|  6 ++
 clang/lib/CodeGen/CGBuiltin.cpp  | 17 ++
 clang/lib/CodeGen/CGHLSLRuntime.h|  1 +
 clang/lib/Headers/hlsl/hlsl_intrinsics.h | 71 
 clang/lib/Sema/SemaHLSL.cpp  | 17 ++
 5 files changed, 112 insertions(+)

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index b025a7681bfac3..6f4da6d1ec5576 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4737,6 +4737,12 @@ def HLSLRSqrt : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void(...)";
 }
 
+def HLSLSign : LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_elementwise_sign"];
+  let Attributes = [NoThrow, Const];
+  let Prototype = "int(...)";
+}
+
 // Builtins for XRay.
 def XRayCustomEvent : Builtin {
   let Spellings = ["__xray_customevent"];
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index d1af7fde157b64..aa8dec6239ff18 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -18662,6 +18662,23 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
 llvm::FunctionType::get(IntTy, {}, false), 
"__hlsl_wave_get_lane_index",
 {}, false, true));
   }
+  case Builtin::BI__builtin_hlsl_elementwise_sign: {
+Value *Op0 = EmitScalarExpr(E->getArg(0));
+llvm::Type *Xty = Op0->getType();
+llvm::Type *retType = llvm::Type::getInt32Ty(this->getLLVMContext());
+if (Xty->isVectorTy()) {
+  auto *XVecTy = E->getArg(0)->getType()->getAs();
+  retType = llvm::VectorType::get(
+  retType, ElementCount::getFixed(XVecTy->getNumElements()));
+}
+if (!E->getArg(0)->getType()->hasFloatingRepresentation() &&
+!E->getArg(0)->getType()->hasSignedIntegerRepresentation())
+  llvm_unreachable("sign operand must have a float or int representation");
+
+return Builder.CreateIntrinsic(
+retType, CGM.getHLSLRuntime().getSignIntrinsic(),
+ArrayRef{Op0}, nullptr, "hlsl.sign");
+  }
   }
   return nullptr;
 }
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h 
b/clang/lib/CodeGen/CGHLSLRuntime.h
index 527e73a0e21fc4..fd7cee12f861cf 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.h
+++ b/clang/lib/CodeGen/CGHLSLRuntime.h
@@ -78,6 +78,7 @@ class CGHLSLRuntime {
   GENERATE_HLSL_INTRINSIC_FUNCTION(Length, length)
   GENERATE_HLSL_INTRINSIC_FUNCTION(Lerp, lerp)
   GENERATE_HLSL_INTRINSIC_FUNCTION(Rsqrt, rsqrt)
+  GENERATE_HLSL_INTRINSIC_FUNCTION(Sign, sign)
   GENERATE_HLSL_INTRINSIC_FUNCTION(ThreadId, thread_id)
 
   
//===--===//
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index e35a5262f92809..10510a85a90a94 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -1725,5 +1725,76 @@ _HLSL_AVAILABILITY(shadermodel, 6.0)
 _HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_get_lane_index)
 __attribute__((convergent)) uint WaveGetLaneIndex();
 
+//===--===//
+// sign builtins
+//===--===//
+
+/// \fn T sign(T Val)
+/// \brief Returns -1 if \a Val is less than zero; 0 if \a Val equals zero; and
+/// 1 if \a Val is greater than zero. \param Val The input value.
+
+#ifdef __HLSL_ENABLE_16_BIT
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+int16_t sign(int16_t);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+int16_t2 sign(int16_t2);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+int16_t3 sign(int16_t3);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+int16_t4 sign(int16_t4);
+#endif
+
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+half sign(half);
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+half2 sign(half2);
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+half3 sign(half3);
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+half4 sign(half4);
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+int sign(int);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+int2 sign(int2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+int3 sign(int3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwis

[clang] [clang][HLSL] Add sign intrinsic part 3 (PR #101989)

2024-08-11 Thread Tim Gymnich via cfe-commits


@@ -4737,6 +4737,12 @@ def HLSLRSqrt : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void(...)";
 }
 
+def HLSLSign : LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_elementwise_sign"];
+  let Attributes = [NoThrow, Const];
+  let Prototype = "int(...)";

tgymnich wrote:

thanks. fixed

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


[clang] [clang][HLSL] Add sign intrinsic part 3 (PR #101989)

2024-08-11 Thread Tim Gymnich via cfe-commits


@@ -1725,5 +1725,76 @@ _HLSL_AVAILABILITY(shadermodel, 6.0)
 _HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_get_lane_index)
 __attribute__((convergent)) uint WaveGetLaneIndex();
 
+//===--===//
+// sign builtins
+//===--===//
+
+/// \fn T sign(T Val)
+/// \brief Returns -1 if \a Val is less than zero; 0 if \a Val equals zero; and
+/// 1 if \a Val is greater than zero. \param Val The input value.
+
+#ifdef __HLSL_ENABLE_16_BIT
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+int16_t sign(int16_t);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+int16_t2 sign(int16_t2);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+int16_t3 sign(int16_t3);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+int16_t4 sign(int16_t4);
+#endif
+
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)

tgymnich wrote:

fixed

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


[clang] [clang][HLSL] Add sign intrinsic part 3 (PR #101989)

2024-08-11 Thread Tim Gymnich via cfe-commits


@@ -1725,5 +1725,76 @@ _HLSL_AVAILABILITY(shadermodel, 6.0)
 _HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_get_lane_index)
 __attribute__((convergent)) uint WaveGetLaneIndex();
 
+//===--===//
+// sign builtins
+//===--===//
+
+/// \fn T sign(T Val)
+/// \brief Returns -1 if \a Val is less than zero; 0 if \a Val equals zero; and
+/// 1 if \a Val is greater than zero. \param Val The input value.
+
+#ifdef __HLSL_ENABLE_16_BIT
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+int16_t sign(int16_t);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+int16_t2 sign(int16_t2);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+int16_t3 sign(int16_t3);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+int16_t4 sign(int16_t4);
+#endif
+
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+half sign(half);
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+half2 sign(half2);
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+half3 sign(half3);
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+half4 sign(half4);
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+int sign(int);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+int2 sign(int2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+int3 sign(int3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+int4 sign(int4);
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)

tgymnich wrote:

fixed

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


[clang] [clang][HLSL] Add sign intrinsic part 3 (PR #101989)

2024-08-11 Thread Tim Gymnich via cfe-commits


@@ -1725,5 +1725,76 @@ _HLSL_AVAILABILITY(shadermodel, 6.0)
 _HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_get_lane_index)
 __attribute__((convergent)) uint WaveGetLaneIndex();
 
+//===--===//
+// sign builtins
+//===--===//
+
+/// \fn T sign(T Val)
+/// \brief Returns -1 if \a Val is less than zero; 0 if \a Val equals zero; and
+/// 1 if \a Val is greater than zero. \param Val The input value.
+
+#ifdef __HLSL_ENABLE_16_BIT
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+int16_t sign(int16_t);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+int16_t2 sign(int16_t2);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+int16_t3 sign(int16_t3);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+int16_t4 sign(int16_t4);
+#endif
+
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+half sign(half);
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+half2 sign(half2);
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+half3 sign(half3);
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+half4 sign(half4);
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+int sign(int);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+int2 sign(int2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+int3 sign(int3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+int4 sign(int4);
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+float sign(float);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+float2 sign(float2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+float3 sign(float3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+float4 sign(float4);
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+int64_t sign(int64_t);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+int64_t2 sign(int64_t2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+int64_t3 sign(int64_t3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+int64_t4 sign(int64_t4);
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)

tgymnich wrote:

fixed

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


[clang] [clang][HLSL] Add sign intrinsic part 3 (PR #101989)

2024-08-11 Thread Tim Gymnich via cfe-commits

https://github.com/tgymnich updated 
https://github.com/llvm/llvm-project/pull/101989

>From c7f7a3683805c6a9a1d696905321a1e161ec8beb Mon Sep 17 00:00:00 2001
From: Tim Gymnich 
Date: Fri, 2 Aug 2024 21:40:24 +0200
Subject: [PATCH 1/4] [clang][HLSL] Add sign intrinsic part 3

---
 clang/include/clang/Basic/Builtins.td|  6 ++
 clang/lib/CodeGen/CGBuiltin.cpp  | 17 ++
 clang/lib/CodeGen/CGHLSLRuntime.h|  1 +
 clang/lib/Headers/hlsl/hlsl_intrinsics.h | 71 
 clang/lib/Sema/SemaHLSL.cpp  | 17 ++
 5 files changed, 112 insertions(+)

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index b025a7681bfac3..6f4da6d1ec5576 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4737,6 +4737,12 @@ def HLSLRSqrt : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void(...)";
 }
 
+def HLSLSign : LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_elementwise_sign"];
+  let Attributes = [NoThrow, Const];
+  let Prototype = "int(...)";
+}
+
 // Builtins for XRay.
 def XRayCustomEvent : Builtin {
   let Spellings = ["__xray_customevent"];
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index d1af7fde157b64..aa8dec6239ff18 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -18662,6 +18662,23 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
 llvm::FunctionType::get(IntTy, {}, false), 
"__hlsl_wave_get_lane_index",
 {}, false, true));
   }
+  case Builtin::BI__builtin_hlsl_elementwise_sign: {
+Value *Op0 = EmitScalarExpr(E->getArg(0));
+llvm::Type *Xty = Op0->getType();
+llvm::Type *retType = llvm::Type::getInt32Ty(this->getLLVMContext());
+if (Xty->isVectorTy()) {
+  auto *XVecTy = E->getArg(0)->getType()->getAs();
+  retType = llvm::VectorType::get(
+  retType, ElementCount::getFixed(XVecTy->getNumElements()));
+}
+if (!E->getArg(0)->getType()->hasFloatingRepresentation() &&
+!E->getArg(0)->getType()->hasSignedIntegerRepresentation())
+  llvm_unreachable("sign operand must have a float or int representation");
+
+return Builder.CreateIntrinsic(
+retType, CGM.getHLSLRuntime().getSignIntrinsic(),
+ArrayRef{Op0}, nullptr, "hlsl.sign");
+  }
   }
   return nullptr;
 }
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h 
b/clang/lib/CodeGen/CGHLSLRuntime.h
index 527e73a0e21fc4..fd7cee12f861cf 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.h
+++ b/clang/lib/CodeGen/CGHLSLRuntime.h
@@ -78,6 +78,7 @@ class CGHLSLRuntime {
   GENERATE_HLSL_INTRINSIC_FUNCTION(Length, length)
   GENERATE_HLSL_INTRINSIC_FUNCTION(Lerp, lerp)
   GENERATE_HLSL_INTRINSIC_FUNCTION(Rsqrt, rsqrt)
+  GENERATE_HLSL_INTRINSIC_FUNCTION(Sign, sign)
   GENERATE_HLSL_INTRINSIC_FUNCTION(ThreadId, thread_id)
 
   
//===--===//
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index e35a5262f92809..10510a85a90a94 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -1725,5 +1725,76 @@ _HLSL_AVAILABILITY(shadermodel, 6.0)
 _HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_get_lane_index)
 __attribute__((convergent)) uint WaveGetLaneIndex();
 
+//===--===//
+// sign builtins
+//===--===//
+
+/// \fn T sign(T Val)
+/// \brief Returns -1 if \a Val is less than zero; 0 if \a Val equals zero; and
+/// 1 if \a Val is greater than zero. \param Val The input value.
+
+#ifdef __HLSL_ENABLE_16_BIT
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+int16_t sign(int16_t);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+int16_t2 sign(int16_t2);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+int16_t3 sign(int16_t3);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+int16_t4 sign(int16_t4);
+#endif
+
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+half sign(half);
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+half2 sign(half2);
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+half3 sign(half3);
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+half4 sign(half4);
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+int sign(int);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+int2 sign(int2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_sign)
+int3 sign(int3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwis

[clang] #101784 part 2: fix error handling of TranslationUnit.reparse (PR #102410)

2024-08-11 Thread via cfe-commits


@@ -161,7 +161,34 @@ class TranslationUnitLoadError(Exception):
 FIXME: Make libclang expose additional error information in this scenario.
 """
 
-pass
+# A generic error code, no further details are available.
+#
+# Errors of this kind can get their own specific error codes in future
+# libclang versions.
+ERROR_FAILURE = 1
+
+# libclang crashed while performing the requested operation.
+ERROR_CRASHED = 2
+
+# The function detected that the arguments violate the function
+# contract.
+ERROR_INVALID_ARGUMENTS = 3
+
+# An AST deserialization error has occurred.
+ERROR_AST_READ_ERROR = 4
+
+def __init__(self, enumeration: int, message: str):
+assert isinstance(enumeration, int)
+
+if enumeration < 1 or enumeration > 4:
+raise Exception(
+"Encountered undefined CXError "
+"constant: %d. Please file a bug to have this "
+"value supported." % enumeration
+)
+
+self.error_code = enumeration
+Exception.__init__(self, "Error %d: %s" % (enumeration or 0, message))

TsXor wrote:

That is a leftover. Before the last commit, error code can be `None` because 
`create`/`parse` swallows error code. `%d` does not receive `None` so convert 
`None` to `0`.

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


[clang] #101784 part 2: fix error handling of TranslationUnit.reparse (PR #102410)

2024-08-11 Thread via cfe-commits

https://github.com/TsXor updated 
https://github.com/llvm/llvm-project/pull/102410

>From 4858eef099dbca66b2e3d36fc17aef574c1f3d58 Mon Sep 17 00:00:00 2001
From: TsXor 
Date: Thu, 8 Aug 2024 09:25:52 +0800
Subject: [PATCH 1/3] fix error handling of TranslationUnit.reparse

---
 clang/bindings/python/clang/cindex.py | 42 +++
 clang/docs/ReleaseNotes.rst   |  3 ++
 2 files changed, 40 insertions(+), 5 deletions(-)

diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index 2038ef6045c7df..e4591828f91968 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -149,8 +149,8 @@ def b(x: str | bytes) -> bytes:
 # this by marshalling object arguments as void**.
 c_object_p: TType[_Pointer[Any]] = POINTER(c_void_p)
 
-### Exception Classes ###
 
+### Exception Classes ###
 
 class TranslationUnitLoadError(Exception):
 """Represents an error that occurred when loading a TranslationUnit.
@@ -161,7 +161,35 @@ class TranslationUnitLoadError(Exception):
 FIXME: Make libclang expose additional error information in this scenario.
 """
 
-pass
+# A generic error code, no further details are available.
+#
+# Errors of this kind can get their own specific error codes in future
+# libclang versions.
+ERROR_FAILURE = 1
+
+# libclang crashed while performing the requested operation.
+ERROR_CRASHED = 2
+
+# The function detected that the arguments violate the function
+# contract.
+ERROR_INVALID_ARGUMENTS = 3
+
+# An AST deserialization error has occurred.
+ERROR_AST_READ_ERROR = 4
+
+def __init__(self, enumeration: int | None, message: str):
+if enumeration is not None:
+assert isinstance(enumeration, int)
+
+if enumeration < 1 or enumeration > 4:
+raise Exception(
+"Encountered undefined CXError "
+"constant: %d. Please file a bug to have this "
+"value supported." % enumeration
+)
+
+self.error_code = enumeration
+Exception.__init__(self, "Error %d: %s" % (enumeration or 0, message))
 
 
 class TranslationUnitSaveError(Exception):
@@ -3094,7 +3122,8 @@ def from_source(
 )
 
 if not ptr:
-raise TranslationUnitLoadError("Error parsing translation unit.")
+# FIXME: use clang_parseTranslationUnit2 to preserve error code
+raise TranslationUnitLoadError(None, "Error parsing translation 
unit.")
 
 return cls(ptr, index=index)
 
@@ -3118,7 +3147,8 @@ def from_ast_file(cls, filename, index=None):
 
 ptr = conf.lib.clang_createTranslationUnit(index, os.fspath(filename))
 if not ptr:
-raise TranslationUnitLoadError(filename)
+# FIXME: use clang_createTranslationUnit2 to preserve error code
+raise TranslationUnitLoadError(None, filename)
 
 return cls(ptr=ptr, index=index)
 
@@ -3263,9 +3293,11 @@ def reparse(self, unsaved_files=None, options=0):
 unsaved_files = []
 
 unsaved_files_array = self.process_unsaved_files(unsaved_files)
-ptr = conf.lib.clang_reparseTranslationUnit(
+result = conf.lib.clang_reparseTranslationUnit(
 self, len(unsaved_files), unsaved_files_array, options
 )
+if result != 0:
+raise TranslationUnitLoadError(result, 'Error reparsing 
TranslationUnit.')
 
 def save(self, filename):
 """Saves the TranslationUnit to a file.
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ba70b138a04c4a..33a8c493e5e998 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -59,6 +59,9 @@ Clang Python Bindings Potentially Breaking Changes
 - Calling a property on the `CompletionChunk` or `CompletionString` class
   statically now leads to an error, instead of returning a `CachedProperty` 
object
   that is used internally. Properties are only available on instances.
+- `TranslationUnitLoadError` now contains an optional error code in 
`error_code`
+  attribute. Also, `TranslationUnit.reparse` will throw 
`TranslationUnitLoadError`
+  when operation fails.
 
 What's New in Clang |release|?
 ==

>From 93222078629f7f30ae2102fc53ecb2fa5673d9dc Mon Sep 17 00:00:00 2001
From: TsXor 
Date: Sat, 10 Aug 2024 19:20:56 +0800
Subject: [PATCH 2/3] preserve error code in TU parsing APIs

---
 clang/bindings/python/clang/cindex.py | 57 ---
 clang/docs/ReleaseNotes.rst   |  2 +-
 2 files changed, 34 insertions(+), 25 deletions(-)

diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index e4591828f91968..0e566ebe4c0e06 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -149,16 +149,14 @@ def b(x: str | bytes) -> bytes:
 # this by marsha

[clang-tools-extra] [clang-tidy] Fix modernize-use-std-format lit test signature (PR #102759)

2024-08-11 Thread Mike Crowe via cfe-commits

mikecrowe wrote:

Thanks for the reviews. Please can someone land this for me when convenient?

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


[clang-tools-extra] 4589bf9 - [clang-tidy] Fix modernize-use-std-format lit test signature (#102759)

2024-08-11 Thread via cfe-commits

Author: Mike Crowe
Date: 2024-08-11T21:03:40+08:00
New Revision: 4589bf90aa1849b3851945fb611f5c96af821332

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

LOG: [clang-tidy] Fix modernize-use-std-format lit test signature (#102759)

My fix for my original fix of issue #92896 in
666d224248707f373577b5b049b5b022916c modified the function signature
for fmt::sprintf to more accurately match the real implementation in
libfmt but failed to do the same for absl::StrFormat. The latter fix
applied equally well to absl::StrFormat so it's important that its test
verifies that the bug is fixed too.

Added: 


Modified: 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format.cpp

Removed: 




diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format.cpp
index e8dea1dce2c972..800a95062e8f1a 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format.cpp
@@ -11,9 +11,8 @@
 
 namespace absl
 {
-// Use const char * for the format since the real type is hard to mock up.
-template 
-std::string StrFormat(const char *format, const Args&... args);
+template 
+std::string StrFormat(const S &format, const Args&... args);
 } // namespace absl
 
 template 



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


[clang-tools-extra] [clang-tidy] Fix modernize-use-std-format lit test signature (PR #102759)

2024-08-11 Thread Congcong Cai via cfe-commits

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


[clang] [clang] force libc linked with --no-as-needed when using compiler-rt (PR #95848)

2024-08-11 Thread via cfe-commits

ziyao233 wrote:

ping again

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


[clang] #101784 part 2: fix error handling of TranslationUnit.reparse (PR #102410)

2024-08-11 Thread via cfe-commits

https://github.com/TsXor updated 
https://github.com/llvm/llvm-project/pull/102410

>From 4858eef099dbca66b2e3d36fc17aef574c1f3d58 Mon Sep 17 00:00:00 2001
From: TsXor 
Date: Thu, 8 Aug 2024 09:25:52 +0800
Subject: [PATCH 1/4] fix error handling of TranslationUnit.reparse

---
 clang/bindings/python/clang/cindex.py | 42 +++
 clang/docs/ReleaseNotes.rst   |  3 ++
 2 files changed, 40 insertions(+), 5 deletions(-)

diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index 2038ef6045c7df..e4591828f91968 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -149,8 +149,8 @@ def b(x: str | bytes) -> bytes:
 # this by marshalling object arguments as void**.
 c_object_p: TType[_Pointer[Any]] = POINTER(c_void_p)
 
-### Exception Classes ###
 
+### Exception Classes ###
 
 class TranslationUnitLoadError(Exception):
 """Represents an error that occurred when loading a TranslationUnit.
@@ -161,7 +161,35 @@ class TranslationUnitLoadError(Exception):
 FIXME: Make libclang expose additional error information in this scenario.
 """
 
-pass
+# A generic error code, no further details are available.
+#
+# Errors of this kind can get their own specific error codes in future
+# libclang versions.
+ERROR_FAILURE = 1
+
+# libclang crashed while performing the requested operation.
+ERROR_CRASHED = 2
+
+# The function detected that the arguments violate the function
+# contract.
+ERROR_INVALID_ARGUMENTS = 3
+
+# An AST deserialization error has occurred.
+ERROR_AST_READ_ERROR = 4
+
+def __init__(self, enumeration: int | None, message: str):
+if enumeration is not None:
+assert isinstance(enumeration, int)
+
+if enumeration < 1 or enumeration > 4:
+raise Exception(
+"Encountered undefined CXError "
+"constant: %d. Please file a bug to have this "
+"value supported." % enumeration
+)
+
+self.error_code = enumeration
+Exception.__init__(self, "Error %d: %s" % (enumeration or 0, message))
 
 
 class TranslationUnitSaveError(Exception):
@@ -3094,7 +3122,8 @@ def from_source(
 )
 
 if not ptr:
-raise TranslationUnitLoadError("Error parsing translation unit.")
+# FIXME: use clang_parseTranslationUnit2 to preserve error code
+raise TranslationUnitLoadError(None, "Error parsing translation 
unit.")
 
 return cls(ptr, index=index)
 
@@ -3118,7 +3147,8 @@ def from_ast_file(cls, filename, index=None):
 
 ptr = conf.lib.clang_createTranslationUnit(index, os.fspath(filename))
 if not ptr:
-raise TranslationUnitLoadError(filename)
+# FIXME: use clang_createTranslationUnit2 to preserve error code
+raise TranslationUnitLoadError(None, filename)
 
 return cls(ptr=ptr, index=index)
 
@@ -3263,9 +3293,11 @@ def reparse(self, unsaved_files=None, options=0):
 unsaved_files = []
 
 unsaved_files_array = self.process_unsaved_files(unsaved_files)
-ptr = conf.lib.clang_reparseTranslationUnit(
+result = conf.lib.clang_reparseTranslationUnit(
 self, len(unsaved_files), unsaved_files_array, options
 )
+if result != 0:
+raise TranslationUnitLoadError(result, 'Error reparsing 
TranslationUnit.')
 
 def save(self, filename):
 """Saves the TranslationUnit to a file.
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ba70b138a04c4a..33a8c493e5e998 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -59,6 +59,9 @@ Clang Python Bindings Potentially Breaking Changes
 - Calling a property on the `CompletionChunk` or `CompletionString` class
   statically now leads to an error, instead of returning a `CachedProperty` 
object
   that is used internally. Properties are only available on instances.
+- `TranslationUnitLoadError` now contains an optional error code in 
`error_code`
+  attribute. Also, `TranslationUnit.reparse` will throw 
`TranslationUnitLoadError`
+  when operation fails.
 
 What's New in Clang |release|?
 ==

>From 93222078629f7f30ae2102fc53ecb2fa5673d9dc Mon Sep 17 00:00:00 2001
From: TsXor 
Date: Sat, 10 Aug 2024 19:20:56 +0800
Subject: [PATCH 2/4] preserve error code in TU parsing APIs

---
 clang/bindings/python/clang/cindex.py | 57 ---
 clang/docs/ReleaseNotes.rst   |  2 +-
 2 files changed, 34 insertions(+), 25 deletions(-)

diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index e4591828f91968..0e566ebe4c0e06 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -149,16 +149,14 @@ def b(x: str | bytes) -> bytes:
 # this by marsha

[clang] [analyzer] Model overflow builtins (PR #102602)

2024-08-11 Thread Pavel Skripkin via cfe-commits

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


[clang] [libclang/python] Improve error reporting of `TranslationUnit` creating functions (PR #102410)

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

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


[clang] [libclang/python] Improve error reporting of `TranslationUnit` creating functions (PR #102410)

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

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


[clang] [libclang/python] Improve error reporting of `TranslationUnit` creating functions (PR #102410)

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

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

LGTM. Thanks for adding better error handling!
@Endilll do you also want to take a look at this before it is merged? 
Otherwise, this is good to go imo.

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


[clang] [libclang/python] Improve error reporting of `TranslationUnit` creating functions (PR #102410)

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

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


[clang] [CodeGen] Revert "Generate assume loads only with -fstrict-vtable-pointers" (PR #91900)

2024-08-11 Thread Rose Silicon via cfe-commits

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


[clang] [ObjC] Add support for finally blocks (PR #82934)

2024-08-11 Thread Rose Silicon via cfe-commits

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


[clang] fe59b84 - [clang][Interp] Propagate InUnion flag to base classes (#102804)

2024-08-11 Thread via cfe-commits

Author: Timm Baeder
Date: 2024-08-11T18:16:03+02:00
New Revision: fe59b84f27181ef96fdf0f234a15f19d0a13a5c2

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

LOG: [clang][Interp] Propagate InUnion flag to base classes (#102804)

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/Descriptor.cpp 
b/clang/lib/AST/Interp/Descriptor.cpp
index 634413b2f2f52..1b7d9f03f8ef0 100644
--- a/clang/lib/AST/Interp/Descriptor.cpp
+++ b/clang/lib/AST/Interp/Descriptor.cpp
@@ -171,30 +171,31 @@ static void initBase(Block *B, std::byte *Ptr, bool 
IsConst, bool IsMutable,
  unsigned FieldOffset, bool IsVirtualBase) {
   assert(D);
   assert(D->ElemRecord);
+  assert(!D->ElemRecord->isUnion()); // Unions cannot be base classes.
 
-  bool IsUnion = D->ElemRecord->isUnion();
   auto *Desc = reinterpret_cast(Ptr + FieldOffset) - 1;
   Desc->Offset = FieldOffset;
   Desc->Desc = D;
   Desc->IsInitialized = D->IsArray;
   Desc->IsBase = true;
   Desc->IsVirtualBase = IsVirtualBase;
-  Desc->IsActive = IsActive && !IsUnion;
+  Desc->IsActive = IsActive && !InUnion;
   Desc->IsConst = IsConst || D->IsConst;
   Desc->IsFieldMutable = IsMutable || D->IsMutable;
+  Desc->InUnion = InUnion;
 
   for (const auto &V : D->ElemRecord->bases())
 initBase(B, Ptr + FieldOffset, IsConst, IsMutable, IsActive, InUnion,
  V.Desc, V.Offset, false);
   for (const auto &F : D->ElemRecord->fields())
 initField(B, Ptr + FieldOffset, IsConst, IsMutable, IsActive, InUnion,
-  IsUnion, F.Desc, F.Offset);
+  InUnion, F.Desc, F.Offset);
 }
 
 static void ctorRecord(Block *B, std::byte *Ptr, bool IsConst, bool IsMutable,
bool IsActive, bool InUnion, const Descriptor *D) {
   for (const auto &V : D->ElemRecord->bases())
-initBase(B, Ptr, IsConst, IsMutable, IsActive, false, V.Desc, V.Offset,
+initBase(B, Ptr, IsConst, IsMutable, IsActive, InUnion, V.Desc, V.Offset,
  false);
   for (const auto &F : D->ElemRecord->fields()) {
 bool IsUnionField = D->isUnion();
@@ -202,7 +203,7 @@ static void ctorRecord(Block *B, std::byte *Ptr, bool 
IsConst, bool IsMutable,
   InUnion || IsUnionField, F.Desc, F.Offset);
   }
   for (const auto &V : D->ElemRecord->virtual_bases())
-initBase(B, Ptr, IsConst, IsMutable, IsActive, false, V.Desc, V.Offset,
+initBase(B, Ptr, IsConst, IsMutable, IsActive, InUnion, V.Desc, V.Offset,
  true);
 }
 

diff  --git a/clang/test/AST/Interp/unions.cpp 
b/clang/test/AST/Interp/unions.cpp
index 4c60c2c0810d4..996d29e143fe2 100644
--- a/clang/test/AST/Interp/unions.cpp
+++ b/clang/test/AST/Interp/unions.cpp
@@ -358,4 +358,27 @@ namespace CopyCtor {
   static_assert(y.b == 42, ""); // both-error {{constant expression}} \
 // both-note {{'b' of union with active member 
'a'}}
 }
+
+namespace UnionInBase {
+  struct Base {
+int y;
+  };
+  struct A : Base {
+int x;
+int arr[3];
+union { int p, q; };
+  };
+  union B {
+A a;
+int b;
+  };
+  constexpr int read_wrong_member_indirect() { // both-error {{never produces 
a constant}}
+B b = {.b = 1};
+int *p = &b.a.y;
+return *p; // both-note 2{{read of member 'a' of union with active member 
'b'}}
+
+  }
+  static_assert(read_wrong_member_indirect() == 1); // both-error {{not an 
integral constant expression}} \
+// both-note {{in call to}}
+}
 #endif



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


[clang] [clang][Interp] Propagate InUnion flag to base classes (PR #102804)

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

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


[clang] Revert "[clang][Interp] Improve "in call to" call argument printing" (PR #102785)

2024-08-11 Thread via cfe-commits

yronglin wrote:

Hmm, If I haven't missing something, I have tried to reproduce this issue on 
Windows(MSVC & MinGW) and Ubuntu, but I can't reproduce this issue.
```
cmake -G Ninja -DLLVM_ENABLE_PROJECTS="clang" -DCMAKE_BUILD_TYPE=Release 
-DCMAKE_C_FLAGS="/fsanitize=address" -DCMAKE_CXX_FLAGS="/fsanitize=address" 
-DLLVM_USE_SANITIZER=Address ..\llvm-project\llvm
```
```
cmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ 
-DLLVM_USE_LINKER=lld -GNinja -DCMAKE_BUILD_TYPE=Release 
-DCMAKE_C_FLAGS="-fsanitize=address" -DCMAKE_CXX_FLAGS="-fsanitize=address" 
-DLLVM_USE_SANITIZER=Address -DLLVM_ENABLE_PROJECTS=clang ../llvm-project/llvm
```

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


[clang] [clang][Interp] Propagate InUnion flag to base classes (PR #102804)

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

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `openmp-s390x-linux` 
running on `systemz-1` while building `clang` at step 6 "test-openmp".

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

Here is the relevant piece of the build log for the reference:
```
Step 6 (test-openmp) failure: 1200 seconds without output running [b'ninja', 
b'-j 4', b'check-openmp'], attempting to kill
...
PASS: ompd-test :: openmp_examples/example_3.c (438 of 448)
PASS: ompd-test :: openmp_examples/example_4.c (439 of 448)
PASS: ompd-test :: openmp_examples/example_5.c (440 of 448)
PASS: ompd-test :: openmp_examples/example_task.c (441 of 448)
UNSUPPORTED: ompd-test :: openmp_examples/ompd_bt.c (442 of 448)
PASS: ompd-test :: openmp_examples/fibonacci.c (443 of 448)
UNSUPPORTED: ompd-test :: openmp_examples/ompd_parallel.c (444 of 448)
PASS: ompd-test :: openmp_examples/parallel.c (445 of 448)
PASS: ompd-test :: openmp_examples/ompd_icvs.c (446 of 448)
PASS: ompd-test :: openmp_examples/nested.c (447 of 448)
command timed out: 1200 seconds without output running [b'ninja', b'-j 4', 
b'check-openmp'], attempting to kill
process killed by signal 9
program finished with exit code -1
elapsedTime=1310.044450

```

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


[clang] [clang][llvm-lit] Rewrite constexpr vectors test to use element access (PR #102757)

2024-08-11 Thread Amr Hesham via cfe-commits

AmrDeveloper wrote:

If you have time for review @tbaederr 

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


[clang] [clang][llvm-lit] Rewrite constexpr vectors test to use element access (PR #102757)

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


@@ -1,10 +1,6 @@
-// RUN: %clang_cc1 -std=c++14 -Wno-unused-value %s -disable-llvm-passes 
-triple x86_64-linux-gnu -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s -Wno-uninitialized -std=c++17 -fsyntax-only -verify

tbaederr wrote:

Why did the c++ standard change?

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


[clang] [clang][llvm-lit] Rewrite constexpr vectors test to use element access (PR #102757)

2024-08-11 Thread Amr Hesham via cfe-commits


@@ -1,10 +1,6 @@
-// RUN: %clang_cc1 -std=c++14 -Wno-unused-value %s -disable-llvm-passes 
-triple x86_64-linux-gnu -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s -Wno-uninitialized -std=c++17 -fsyntax-only -verify

AmrDeveloper wrote:

To use C++ extension for static_assert, I can back to c++14 and add empty 
message if that needed

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


[clang] [clang][llvm-lit] Rewrite constexpr vectors test to use element access (PR #102757)

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


@@ -1,10 +1,6 @@
-// RUN: %clang_cc1 -std=c++14 -Wno-unused-value %s -disable-llvm-passes 
-triple x86_64-linux-gnu -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s -Wno-uninitialized -std=c++17 -fsyntax-only -verify

tbaederr wrote:

Yes please, so we can keep the test as it was.

https://github.com/llvm/llvm-project/pull/102757
___
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-11 Thread Timothy Akintilo via cfe-commits

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

>From c1afe853ccacae1605fecfe552bb9a263c6b8c1d Mon Sep 17 00:00:00 2001
From: Timothy Akintilo 
Date: Sat, 27 Jul 2024 16:17:46 -0500
Subject: [PATCH 1/2] 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 89eee392837af4..4f8a53aa7aae7e 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 96d1ee1f0add73..4f748168d75aa7 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 0924dc27af82b5..a6530c3c93d912 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 d6a6cee62a7528..7c4e82f07de02e 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 FunctionTemplateDec

[clang] [clang][llvm-lit] Rewrite constexpr vectors test to use element access (PR #102757)

2024-08-11 Thread Amr Hesham via cfe-commits


@@ -1,10 +1,6 @@
-// RUN: %clang_cc1 -std=c++14 -Wno-unused-value %s -disable-llvm-passes 
-triple x86_64-linux-gnu -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s -Wno-uninitialized -std=c++17 -fsyntax-only -verify

AmrDeveloper wrote:

Sure i will, thanks

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


[clang] [clang][Interp] Fix diagnosing uninitialized nested union fields (PR #102824)

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

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

We were calling initialize() unconditionally when copying the union.

>From 639c0678f29c6a3936a30a35810552a54590aa18 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sun, 11 Aug 2024 19:52:51 +0200
Subject: [PATCH] [clang][Interp] Fix diagnosing uninitialized nested union
 fields

We were calling initialize() unconditionally when copying the union.
---
 clang/lib/AST/Interp/Interp.cpp|  7 +-
 clang/lib/AST/Interp/InterpBuiltin.cpp | 95 --
 clang/test/AST/Interp/unions.cpp   | 25 ++-
 3 files changed, 88 insertions(+), 39 deletions(-)

diff --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index 89ac6938931133..c65d3789333852 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -125,12 +125,17 @@ static bool CheckActive(InterpState &S, CodePtr OpPC, 
const Pointer &Ptr,
   if (Ptr.isActive())
 return true;
 
+  assert(Ptr.isField() && Ptr.getField());
+
   Pointer U = Ptr.getBase();
   Pointer C = Ptr;
   while (!U.isRoot() && U.inUnion() && !U.isActive()) {
-C = U;
+if (U.getField())
+  C = U;
 U = U.getBase();
   }
+  assert(C.isField());
+
   // Get the inactive field descriptor.
   const FieldDecl *InactiveField = C.getField();
   assert(InactiveField);
diff --git a/clang/lib/AST/Interp/InterpBuiltin.cpp 
b/clang/lib/AST/Interp/InterpBuiltin.cpp
index 1841a2a4714d89..c3370e2e5286e0 100644
--- a/clang/lib/AST/Interp/InterpBuiltin.cpp
+++ b/clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -1635,7 +1635,58 @@ bool SetThreeWayComparisonField(InterpState &S, CodePtr 
OpPC,
   return true;
 }
 
-bool DoMemcpy(InterpState &S, CodePtr OpPC, const Pointer &Src, Pointer &Dest) 
{
+static bool copyComposite(InterpState &S, CodePtr OpPC, const Pointer &Src,
+  Pointer &Dest, bool Activate);
+static bool copyRecord(InterpState &S, CodePtr OpPC, const Pointer &Src,
+   Pointer &Dest, bool Activate = false) {
+  [[maybe_unused]] const Descriptor *SrcDesc = Src.getFieldDesc();
+  const Descriptor *DestDesc = Dest.getFieldDesc();
+
+  auto copyField = [&](const Record::Field &F, bool Activate) -> bool {
+Pointer DestField = Dest.atField(F.Offset);
+if (std::optional FT = S.Ctx.classify(F.Decl->getType())) {
+  TYPE_SWITCH(*FT, {
+DestField.deref() = Src.atField(F.Offset).deref();
+if (Src.atField(F.Offset).isInitialized())
+  DestField.initialize();
+if (Activate)
+  DestField.activate();
+  });
+  return true;
+}
+// Composite field.
+return copyComposite(S, OpPC, Src.atField(F.Offset), DestField, Activate);
+  };
+
+  assert(SrcDesc->isRecord());
+  assert(SrcDesc->ElemRecord == DestDesc->ElemRecord);
+  const Record *R = DestDesc->ElemRecord;
+  for (const Record::Field &F : R->fields()) {
+if (R->isUnion()) {
+  // For unions, only copy the active field.
+  const Pointer &SrcField = Src.atField(F.Offset);
+  if (SrcField.isActive()) {
+if (!copyField(F, /*Activate=*/true))
+  return false;
+  }
+} else {
+  if (!copyField(F, Activate))
+return false;
+}
+  }
+
+  for (const Record::Base &B : R->bases()) {
+Pointer DestBase = Dest.atField(B.Offset);
+if (!copyRecord(S, OpPC, Src.atField(B.Offset), DestBase, Activate))
+  return false;
+  }
+
+  Dest.initialize();
+  return true;
+}
+
+static bool copyComposite(InterpState &S, CodePtr OpPC, const Pointer &Src,
+  Pointer &Dest, bool Activate = false) {
   assert(Src.isLive() && Dest.isLive());
 
   [[maybe_unused]] const Descriptor *SrcDesc = Src.getFieldDesc();
@@ -1657,44 +1708,14 @@ bool DoMemcpy(InterpState &S, CodePtr OpPC, const 
Pointer &Src, Pointer &Dest) {
 return true;
   }
 
-  if (DestDesc->isRecord()) {
-auto copyField = [&](const Record::Field &F, bool Activate) -> bool {
-  Pointer DestField = Dest.atField(F.Offset);
-  if (std::optional FT = S.Ctx.classify(F.Decl->getType())) {
-TYPE_SWITCH(*FT, {
-  DestField.deref() = Src.atField(F.Offset).deref();
-  DestField.initialize();
-  if (Activate)
-DestField.activate();
-});
-return true;
-  }
-  return Invalid(S, OpPC);
-};
-
-assert(SrcDesc->isRecord());
-assert(SrcDesc->ElemRecord == DestDesc->ElemRecord);
-const Record *R = DestDesc->ElemRecord;
-for (const Record::Field &F : R->fields()) {
-  if (R->isUnion()) {
-// For unions, only copy the active field.
-const Pointer &SrcField = Src.atField(F.Offset);
-if (SrcField.isActive()) {
-  if (!copyField(F, /*Activate=*/true))
-return false;
-}
-  } else {
-if (!copyField(F, /*Activate=*/false))
-  return false;
-  }
-}
-return true;
-  }
-
-  // FIX

[clang] [clang][Interp] Fix diagnosing uninitialized nested union fields (PR #102824)

2024-08-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

We were calling initialize() unconditionally when copying the union.

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


3 Files Affected:

- (modified) clang/lib/AST/Interp/Interp.cpp (+6-1) 
- (modified) clang/lib/AST/Interp/InterpBuiltin.cpp (+58-37) 
- (modified) clang/test/AST/Interp/unions.cpp (+24-1) 


``diff
diff --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index 89ac6938931133..c65d3789333852 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -125,12 +125,17 @@ static bool CheckActive(InterpState &S, CodePtr OpPC, 
const Pointer &Ptr,
   if (Ptr.isActive())
 return true;
 
+  assert(Ptr.isField() && Ptr.getField());
+
   Pointer U = Ptr.getBase();
   Pointer C = Ptr;
   while (!U.isRoot() && U.inUnion() && !U.isActive()) {
-C = U;
+if (U.getField())
+  C = U;
 U = U.getBase();
   }
+  assert(C.isField());
+
   // Get the inactive field descriptor.
   const FieldDecl *InactiveField = C.getField();
   assert(InactiveField);
diff --git a/clang/lib/AST/Interp/InterpBuiltin.cpp 
b/clang/lib/AST/Interp/InterpBuiltin.cpp
index 1841a2a4714d89..c3370e2e5286e0 100644
--- a/clang/lib/AST/Interp/InterpBuiltin.cpp
+++ b/clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -1635,7 +1635,58 @@ bool SetThreeWayComparisonField(InterpState &S, CodePtr 
OpPC,
   return true;
 }
 
-bool DoMemcpy(InterpState &S, CodePtr OpPC, const Pointer &Src, Pointer &Dest) 
{
+static bool copyComposite(InterpState &S, CodePtr OpPC, const Pointer &Src,
+  Pointer &Dest, bool Activate);
+static bool copyRecord(InterpState &S, CodePtr OpPC, const Pointer &Src,
+   Pointer &Dest, bool Activate = false) {
+  [[maybe_unused]] const Descriptor *SrcDesc = Src.getFieldDesc();
+  const Descriptor *DestDesc = Dest.getFieldDesc();
+
+  auto copyField = [&](const Record::Field &F, bool Activate) -> bool {
+Pointer DestField = Dest.atField(F.Offset);
+if (std::optional FT = S.Ctx.classify(F.Decl->getType())) {
+  TYPE_SWITCH(*FT, {
+DestField.deref() = Src.atField(F.Offset).deref();
+if (Src.atField(F.Offset).isInitialized())
+  DestField.initialize();
+if (Activate)
+  DestField.activate();
+  });
+  return true;
+}
+// Composite field.
+return copyComposite(S, OpPC, Src.atField(F.Offset), DestField, Activate);
+  };
+
+  assert(SrcDesc->isRecord());
+  assert(SrcDesc->ElemRecord == DestDesc->ElemRecord);
+  const Record *R = DestDesc->ElemRecord;
+  for (const Record::Field &F : R->fields()) {
+if (R->isUnion()) {
+  // For unions, only copy the active field.
+  const Pointer &SrcField = Src.atField(F.Offset);
+  if (SrcField.isActive()) {
+if (!copyField(F, /*Activate=*/true))
+  return false;
+  }
+} else {
+  if (!copyField(F, Activate))
+return false;
+}
+  }
+
+  for (const Record::Base &B : R->bases()) {
+Pointer DestBase = Dest.atField(B.Offset);
+if (!copyRecord(S, OpPC, Src.atField(B.Offset), DestBase, Activate))
+  return false;
+  }
+
+  Dest.initialize();
+  return true;
+}
+
+static bool copyComposite(InterpState &S, CodePtr OpPC, const Pointer &Src,
+  Pointer &Dest, bool Activate = false) {
   assert(Src.isLive() && Dest.isLive());
 
   [[maybe_unused]] const Descriptor *SrcDesc = Src.getFieldDesc();
@@ -1657,44 +1708,14 @@ bool DoMemcpy(InterpState &S, CodePtr OpPC, const 
Pointer &Src, Pointer &Dest) {
 return true;
   }
 
-  if (DestDesc->isRecord()) {
-auto copyField = [&](const Record::Field &F, bool Activate) -> bool {
-  Pointer DestField = Dest.atField(F.Offset);
-  if (std::optional FT = S.Ctx.classify(F.Decl->getType())) {
-TYPE_SWITCH(*FT, {
-  DestField.deref() = Src.atField(F.Offset).deref();
-  DestField.initialize();
-  if (Activate)
-DestField.activate();
-});
-return true;
-  }
-  return Invalid(S, OpPC);
-};
-
-assert(SrcDesc->isRecord());
-assert(SrcDesc->ElemRecord == DestDesc->ElemRecord);
-const Record *R = DestDesc->ElemRecord;
-for (const Record::Field &F : R->fields()) {
-  if (R->isUnion()) {
-// For unions, only copy the active field.
-const Pointer &SrcField = Src.atField(F.Offset);
-if (SrcField.isActive()) {
-  if (!copyField(F, /*Activate=*/true))
-return false;
-}
-  } else {
-if (!copyField(F, /*Activate=*/false))
-  return false;
-  }
-}
-return true;
-  }
-
-  // FIXME: Composite types.
-
+  if (DestDesc->isRecord())
+return copyRecord(S, OpPC, Src, Dest, Activate);
   return Invalid(S, OpPC);
 }
 
+bool DoMemcpy(InterpState &S, CodePtr OpPC, const Pointer &Src, Pointer &Dest) 
{
+  return copyComposite(S, Op

[clang] [clang][Interp] Fix diagnosing uninitialized nested union fields (PR #102824)

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

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

>From 983411854aeb39a0ddba04f5d30b6aa284c297bf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sun, 11 Aug 2024 19:52:51 +0200
Subject: [PATCH] [clang][Interp] Fix diagnosing uninitialized nested union
 fields

We were calling initialize() unconditionally when copying the union.
---
 clang/lib/AST/Interp/Interp.cpp|  7 +-
 clang/lib/AST/Interp/InterpBuiltin.cpp | 95 --
 clang/test/AST/Interp/unions.cpp   | 26 ++-
 3 files changed, 89 insertions(+), 39 deletions(-)

diff --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index 89ac6938931133..c65d3789333852 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -125,12 +125,17 @@ static bool CheckActive(InterpState &S, CodePtr OpPC, 
const Pointer &Ptr,
   if (Ptr.isActive())
 return true;
 
+  assert(Ptr.isField() && Ptr.getField());
+
   Pointer U = Ptr.getBase();
   Pointer C = Ptr;
   while (!U.isRoot() && U.inUnion() && !U.isActive()) {
-C = U;
+if (U.getField())
+  C = U;
 U = U.getBase();
   }
+  assert(C.isField());
+
   // Get the inactive field descriptor.
   const FieldDecl *InactiveField = C.getField();
   assert(InactiveField);
diff --git a/clang/lib/AST/Interp/InterpBuiltin.cpp 
b/clang/lib/AST/Interp/InterpBuiltin.cpp
index 1841a2a4714d89..c3370e2e5286e0 100644
--- a/clang/lib/AST/Interp/InterpBuiltin.cpp
+++ b/clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -1635,7 +1635,58 @@ bool SetThreeWayComparisonField(InterpState &S, CodePtr 
OpPC,
   return true;
 }
 
-bool DoMemcpy(InterpState &S, CodePtr OpPC, const Pointer &Src, Pointer &Dest) 
{
+static bool copyComposite(InterpState &S, CodePtr OpPC, const Pointer &Src,
+  Pointer &Dest, bool Activate);
+static bool copyRecord(InterpState &S, CodePtr OpPC, const Pointer &Src,
+   Pointer &Dest, bool Activate = false) {
+  [[maybe_unused]] const Descriptor *SrcDesc = Src.getFieldDesc();
+  const Descriptor *DestDesc = Dest.getFieldDesc();
+
+  auto copyField = [&](const Record::Field &F, bool Activate) -> bool {
+Pointer DestField = Dest.atField(F.Offset);
+if (std::optional FT = S.Ctx.classify(F.Decl->getType())) {
+  TYPE_SWITCH(*FT, {
+DestField.deref() = Src.atField(F.Offset).deref();
+if (Src.atField(F.Offset).isInitialized())
+  DestField.initialize();
+if (Activate)
+  DestField.activate();
+  });
+  return true;
+}
+// Composite field.
+return copyComposite(S, OpPC, Src.atField(F.Offset), DestField, Activate);
+  };
+
+  assert(SrcDesc->isRecord());
+  assert(SrcDesc->ElemRecord == DestDesc->ElemRecord);
+  const Record *R = DestDesc->ElemRecord;
+  for (const Record::Field &F : R->fields()) {
+if (R->isUnion()) {
+  // For unions, only copy the active field.
+  const Pointer &SrcField = Src.atField(F.Offset);
+  if (SrcField.isActive()) {
+if (!copyField(F, /*Activate=*/true))
+  return false;
+  }
+} else {
+  if (!copyField(F, Activate))
+return false;
+}
+  }
+
+  for (const Record::Base &B : R->bases()) {
+Pointer DestBase = Dest.atField(B.Offset);
+if (!copyRecord(S, OpPC, Src.atField(B.Offset), DestBase, Activate))
+  return false;
+  }
+
+  Dest.initialize();
+  return true;
+}
+
+static bool copyComposite(InterpState &S, CodePtr OpPC, const Pointer &Src,
+  Pointer &Dest, bool Activate = false) {
   assert(Src.isLive() && Dest.isLive());
 
   [[maybe_unused]] const Descriptor *SrcDesc = Src.getFieldDesc();
@@ -1657,44 +1708,14 @@ bool DoMemcpy(InterpState &S, CodePtr OpPC, const 
Pointer &Src, Pointer &Dest) {
 return true;
   }
 
-  if (DestDesc->isRecord()) {
-auto copyField = [&](const Record::Field &F, bool Activate) -> bool {
-  Pointer DestField = Dest.atField(F.Offset);
-  if (std::optional FT = S.Ctx.classify(F.Decl->getType())) {
-TYPE_SWITCH(*FT, {
-  DestField.deref() = Src.atField(F.Offset).deref();
-  DestField.initialize();
-  if (Activate)
-DestField.activate();
-});
-return true;
-  }
-  return Invalid(S, OpPC);
-};
-
-assert(SrcDesc->isRecord());
-assert(SrcDesc->ElemRecord == DestDesc->ElemRecord);
-const Record *R = DestDesc->ElemRecord;
-for (const Record::Field &F : R->fields()) {
-  if (R->isUnion()) {
-// For unions, only copy the active field.
-const Pointer &SrcField = Src.atField(F.Offset);
-if (SrcField.isActive()) {
-  if (!copyField(F, /*Activate=*/true))
-return false;
-}
-  } else {
-if (!copyField(F, /*Activate=*/false))
-  return false;
-  }
-}
-return true;
-  }
-
-  // FIXME: Composite types.
-
+  if (DestDesc->isRecord())
+return copyRe

[clang] [analyzer] Model overflow builtins (PR #102602)

2024-08-11 Thread Pavel Skripkin via cfe-commits

https://github.com/pskrgag updated 
https://github.com/llvm/llvm-project/pull/102602

>From 3e0fcffa8fbea5f89ab927fd897c451bcafd8e5e Mon Sep 17 00:00:00 2001
From: Pavel Skripkin 
Date: Fri, 9 Aug 2024 14:37:47 +0300
Subject: [PATCH 1/3] clang/csa: add initial support for builtin overflow

---
 .../Checkers/BuiltinFunctionChecker.cpp   | 124 +-
 clang/test/Analysis/builtin_overflow.c|  65 +
 .../test/Analysis/out-of-bounds-diagnostics.c |  17 +++
 3 files changed, 204 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Analysis/builtin_overflow.c

diff --git a/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
index b198b1c2ff4d11..0c8b9fa3d947b0 100644
--- a/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
@@ -21,16 +21,67 @@
 #include "clang/StaticAnalyzer/Core/PathSensitive/CallDescription.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/DynamicExtent.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
 
 using namespace clang;
 using namespace ento;
 
 namespace {
 
+QualType getOverflowBuiltinResultType(const CallEvent &Call) {
+  assert(Call.getNumArgs() == 3);
+
+  return Call.getArgExpr(2)->getType()->getPointeeType();
+}
+
+QualType getOverflowBuiltinResultType(const CallEvent &Call, CheckerContext &C,
+  unsigned BI) {
+  assert(Call.getNumArgs() == 3);
+
+  ASTContext &Ast = C.getASTContext();
+
+  switch (BI) {
+  case Builtin::BI__builtin_smul_overflow:
+  case Builtin::BI__builtin_ssub_overflow:
+  case Builtin::BI__builtin_sadd_overflow:
+return Ast.IntTy;
+  case Builtin::BI__builtin_smull_overflow:
+  case Builtin::BI__builtin_ssubl_overflow:
+  case Builtin::BI__builtin_saddl_overflow:
+return Ast.LongTy;
+  case Builtin::BI__builtin_smulll_overflow:
+  case Builtin::BI__builtin_ssubll_overflow:
+  case Builtin::BI__builtin_saddll_overflow:
+return Ast.LongLongTy;
+  case Builtin::BI__builtin_umul_overflow:
+  case Builtin::BI__builtin_usub_overflow:
+  case Builtin::BI__builtin_uadd_overflow:
+return Ast.UnsignedIntTy;
+  case Builtin::BI__builtin_umull_overflow:
+  case Builtin::BI__builtin_usubl_overflow:
+  case Builtin::BI__builtin_uaddl_overflow:
+return Ast.UnsignedLongTy;
+  case Builtin::BI__builtin_umulll_overflow:
+  case Builtin::BI__builtin_usubll_overflow:
+  case Builtin::BI__builtin_uaddll_overflow:
+return Ast.UnsignedLongLongTy;
+  case Builtin::BI__builtin_mul_overflow:
+  case Builtin::BI__builtin_sub_overflow:
+  case Builtin::BI__builtin_add_overflow:
+return getOverflowBuiltinResultType(Call);
+  default:
+assert(false && "Unknown overflow builtin");
+  }
+}
+
 class BuiltinFunctionChecker : public Checker {
 public:
   bool evalCall(const CallEvent &Call, CheckerContext &C) const;
+  void HandleOverflowBuiltin(const CallEvent &Call, CheckerContext &C,
+ BinaryOperator::Opcode Op,
+ QualType ResultType) const;
 
 private:
   // From: clang/include/clang/Basic/Builtins.def
@@ -50,6 +101,44 @@ class BuiltinFunctionChecker : public Checker {
 
 } // namespace
 
+void BuiltinFunctionChecker::HandleOverflowBuiltin(const CallEvent &Call,
+   CheckerContext &C,
+   BinaryOperator::Opcode Op,
+   QualType ResultType) const {
+  // All __builtin_*_overflow functions take 3 argumets.
+  assert(Call.getNumArgs() == 3);
+
+  ProgramStateRef State = C.getState();
+  SValBuilder &SVB = C.getSValBuilder();
+  const Expr *CE = Call.getOriginExpr();
+
+  SVal Arg1 = Call.getArgSVal(0);
+  SVal Arg2 = Call.getArgSVal(1);
+
+  SVal RetVal = SVB.evalBinOp(State, Op, Arg1, Arg2, ResultType);
+
+  // TODO: Handle overflows with values that known to overflow. Like INT_MAX + 
1
+  // should not produce state for non-overflow case and threat it as
+  // unreachable.
+
+  // Handle non-overflow case.
+  {
+ProgramStateRef StateSuccess =
+State->BindExpr(CE, C.getLocationContext(), SVB.makeTruthVal(false));
+
+if (auto L = Call.getArgSVal(2).getAs())
+  StateSuccess = StateSuccess->bindLoc(*L, RetVal, C.getLocationContext());
+
+C.addTransition(StateSuccess);
+  }
+
+  // Handle overflow case.
+  {
+C.addTransition(
+State->BindExpr(CE, C.getLocationContext(), SVB.makeTruthVal(true)));
+  }
+}
+
 bool BuiltinFunctionChecker::isBuiltinLikeFunction(
 const CallEvent &Call) const {
   const auto *FD = llvm::dyn_cast_or_null(Call.getDecl());
@@ -82,10 +171,41 @@ bool BuiltinFunctionChe

[clang] [analyzer] Model overflow builtins (PR #102602)

2024-08-11 Thread Pavel Skripkin via cfe-commits

https://github.com/pskrgag updated 
https://github.com/llvm/llvm-project/pull/102602

>From 3e0fcffa8fbea5f89ab927fd897c451bcafd8e5e Mon Sep 17 00:00:00 2001
From: Pavel Skripkin 
Date: Fri, 9 Aug 2024 14:37:47 +0300
Subject: [PATCH 1/4] clang/csa: add initial support for builtin overflow

---
 .../Checkers/BuiltinFunctionChecker.cpp   | 124 +-
 clang/test/Analysis/builtin_overflow.c|  65 +
 .../test/Analysis/out-of-bounds-diagnostics.c |  17 +++
 3 files changed, 204 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Analysis/builtin_overflow.c

diff --git a/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
index b198b1c2ff4d11..0c8b9fa3d947b0 100644
--- a/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
@@ -21,16 +21,67 @@
 #include "clang/StaticAnalyzer/Core/PathSensitive/CallDescription.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/DynamicExtent.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
 
 using namespace clang;
 using namespace ento;
 
 namespace {
 
+QualType getOverflowBuiltinResultType(const CallEvent &Call) {
+  assert(Call.getNumArgs() == 3);
+
+  return Call.getArgExpr(2)->getType()->getPointeeType();
+}
+
+QualType getOverflowBuiltinResultType(const CallEvent &Call, CheckerContext &C,
+  unsigned BI) {
+  assert(Call.getNumArgs() == 3);
+
+  ASTContext &Ast = C.getASTContext();
+
+  switch (BI) {
+  case Builtin::BI__builtin_smul_overflow:
+  case Builtin::BI__builtin_ssub_overflow:
+  case Builtin::BI__builtin_sadd_overflow:
+return Ast.IntTy;
+  case Builtin::BI__builtin_smull_overflow:
+  case Builtin::BI__builtin_ssubl_overflow:
+  case Builtin::BI__builtin_saddl_overflow:
+return Ast.LongTy;
+  case Builtin::BI__builtin_smulll_overflow:
+  case Builtin::BI__builtin_ssubll_overflow:
+  case Builtin::BI__builtin_saddll_overflow:
+return Ast.LongLongTy;
+  case Builtin::BI__builtin_umul_overflow:
+  case Builtin::BI__builtin_usub_overflow:
+  case Builtin::BI__builtin_uadd_overflow:
+return Ast.UnsignedIntTy;
+  case Builtin::BI__builtin_umull_overflow:
+  case Builtin::BI__builtin_usubl_overflow:
+  case Builtin::BI__builtin_uaddl_overflow:
+return Ast.UnsignedLongTy;
+  case Builtin::BI__builtin_umulll_overflow:
+  case Builtin::BI__builtin_usubll_overflow:
+  case Builtin::BI__builtin_uaddll_overflow:
+return Ast.UnsignedLongLongTy;
+  case Builtin::BI__builtin_mul_overflow:
+  case Builtin::BI__builtin_sub_overflow:
+  case Builtin::BI__builtin_add_overflow:
+return getOverflowBuiltinResultType(Call);
+  default:
+assert(false && "Unknown overflow builtin");
+  }
+}
+
 class BuiltinFunctionChecker : public Checker {
 public:
   bool evalCall(const CallEvent &Call, CheckerContext &C) const;
+  void HandleOverflowBuiltin(const CallEvent &Call, CheckerContext &C,
+ BinaryOperator::Opcode Op,
+ QualType ResultType) const;
 
 private:
   // From: clang/include/clang/Basic/Builtins.def
@@ -50,6 +101,44 @@ class BuiltinFunctionChecker : public Checker {
 
 } // namespace
 
+void BuiltinFunctionChecker::HandleOverflowBuiltin(const CallEvent &Call,
+   CheckerContext &C,
+   BinaryOperator::Opcode Op,
+   QualType ResultType) const {
+  // All __builtin_*_overflow functions take 3 argumets.
+  assert(Call.getNumArgs() == 3);
+
+  ProgramStateRef State = C.getState();
+  SValBuilder &SVB = C.getSValBuilder();
+  const Expr *CE = Call.getOriginExpr();
+
+  SVal Arg1 = Call.getArgSVal(0);
+  SVal Arg2 = Call.getArgSVal(1);
+
+  SVal RetVal = SVB.evalBinOp(State, Op, Arg1, Arg2, ResultType);
+
+  // TODO: Handle overflows with values that known to overflow. Like INT_MAX + 
1
+  // should not produce state for non-overflow case and threat it as
+  // unreachable.
+
+  // Handle non-overflow case.
+  {
+ProgramStateRef StateSuccess =
+State->BindExpr(CE, C.getLocationContext(), SVB.makeTruthVal(false));
+
+if (auto L = Call.getArgSVal(2).getAs())
+  StateSuccess = StateSuccess->bindLoc(*L, RetVal, C.getLocationContext());
+
+C.addTransition(StateSuccess);
+  }
+
+  // Handle overflow case.
+  {
+C.addTransition(
+State->BindExpr(CE, C.getLocationContext(), SVB.makeTruthVal(true)));
+  }
+}
+
 bool BuiltinFunctionChecker::isBuiltinLikeFunction(
 const CallEvent &Call) const {
   const auto *FD = llvm::dyn_cast_or_null(Call.getDecl());
@@ -82,10 +171,41 @@ bool BuiltinFunctionChe

[clang] [analyzer] Model overflow builtins (PR #102602)

2024-08-11 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 3364284d87035eaac9662d345d4ddee2714f8fd7 
a928600fcf613ff1f85fa1e5093c7973d4b8cfb8 --extensions cpp,c -- 
clang/test/Analysis/builtin_overflow.c 
clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp 
clang/test/Analysis/out-of-bounds-diagnostics.c
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
index 5d7760c131..1507973c63 100644
--- a/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
@@ -122,14 +122,20 @@ BuiltinFunctionChecker::checkOverflow(CheckerContext &C, 
SVal RetVal,
   assert(Res->isIntegerType());
 
   unsigned BitWidth = ACtx.getIntWidth(Res);
-  auto MinVal = llvm::APSInt::getMinValue(BitWidth, 
Res->isUnsignedIntegerType());
-  auto MaxVal = llvm::APSInt::getMaxValue(BitWidth, 
Res->isUnsignedIntegerType());
-
-  SVal IsLeMax = SVB.evalBinOp(State, BO_LE, RetVal, 
nonloc::ConcreteInt(MaxVal), Res);
-  SVal IsGeMin = SVB.evalBinOp(State, BO_GE, RetVal, 
nonloc::ConcreteInt(MinVal), Res);
-
-  auto [MayNotOverflow, MayOverflow] = 
State->assume(IsLeMax.castAs());
-  auto [MayNotUnderflow, MayUnderflow] = 
State->assume(IsGeMin.castAs());
+  auto MinVal =
+  llvm::APSInt::getMinValue(BitWidth, Res->isUnsignedIntegerType());
+  auto MaxVal =
+  llvm::APSInt::getMaxValue(BitWidth, Res->isUnsignedIntegerType());
+
+  SVal IsLeMax =
+  SVB.evalBinOp(State, BO_LE, RetVal, nonloc::ConcreteInt(MaxVal), Res);
+  SVal IsGeMin =
+  SVB.evalBinOp(State, BO_GE, RetVal, nonloc::ConcreteInt(MinVal), Res);
+
+  auto [MayNotOverflow, MayOverflow] =
+  State->assume(IsLeMax.castAs());
+  auto [MayNotUnderflow, MayUnderflow] =
+  State->assume(IsGeMin.castAs());
 
   return {MayOverflow || MayUnderflow, MayNotOverflow && MayNotUnderflow};
 }

``




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


[clang] [clang][llvm-lit] Rewrite constexpr vectors test to use element access (PR #102757)

2024-08-11 Thread Amr Hesham via cfe-commits

https://github.com/AmrDeveloper updated 
https://github.com/llvm/llvm-project/pull/102757

>From 673b9e08de8a661c9deed2ee497889312f059f3d Mon Sep 17 00:00:00 2001
From: AmrDeveloper 
Date: Sat, 10 Aug 2024 16:54:33 +0200
Subject: [PATCH] [clang][llvm-lit] Rewrite constexpr vectors test to use
 element access

Currently the constexpr vectors lit test depend on CHECK to compare
the vector values and IR, but after vector element access feature is
implemented.

This patch rewrite all tests in constexpr vectors to depend on static
asserts and element access feature
---
 clang/test/SemaCXX/constexpr-vectors.cpp | 539 ++-
 1 file changed, 331 insertions(+), 208 deletions(-)

diff --git a/clang/test/SemaCXX/constexpr-vectors.cpp 
b/clang/test/SemaCXX/constexpr-vectors.cpp
index 99b045f888d87c..6cd305e5732577 100644
--- a/clang/test/SemaCXX/constexpr-vectors.cpp
+++ b/clang/test/SemaCXX/constexpr-vectors.cpp
@@ -1,10 +1,6 @@
-// RUN: %clang_cc1 -std=c++14 -Wno-unused-value %s -disable-llvm-passes 
-triple x86_64-linux-gnu -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s -Wno-uninitialized -std=c++14 -fsyntax-only -verify
 
-// FIXME: Unfortunately there is no good way to validate that our values are
-// correct since Vector types don't have operator [] implemented for constexpr.
-// Instead, we need to use filecheck to ensure the emitted IR is correct. Once
-// someone implements array subscript operator for these types as constexpr,
-// this test should modified to jsut use static asserts.
+// expected-no-diagnostics
 
 using FourCharsVecSize __attribute__((vector_size(4))) = char;
 using FourIntsVecSize __attribute__((vector_size(16))) = int;
@@ -150,564 +146,691 @@ constexpr auto CmpBinOr(T t, U u) {
   return t;
 }
 
+constexpr auto CmpF(float t, float u) {
+  return __builtin_fabs(t - u) < 0.0001;
+}
+
 // Only int vs float makes a difference here, so we only need to test 1 of 
each.
 // Test Char to make sure the mixed-nature of shifts around char is evident.
 void CharUsage() {
   constexpr auto a = FourCharsVecSize{6, 3, 2, 1} +
- FourCharsVecSize{12, 15, 5, 7};
-  // CHECK: store <4 x i8> 
+FourCharsVecSize{12, 15, 5, 7};
+  static_assert(a[0] == 18 && a[1] == 18 && a[2] == 7 && a[3] == 8, "");
+  
   constexpr auto b = FourCharsVecSize{19, 15, 13, 12} -
  FourCharsVecSize{13, 14, 5, 3};
-  // CHECK: store <4 x i8> 
+  static_assert(b[0] == 6 && b[1] == 1 && b[2] == 8 && b[3] == 9, "");
+  
   constexpr auto c = FourCharsVecSize{8, 4, 2, 1} *
  FourCharsVecSize{3, 4, 5, 6};
-  // CHECK: store <4 x i8> 
+  static_assert(c[0] == 24 && c[1] == 16 && c[2] == 10 && c[3] == 6, "");
+
   constexpr auto d = FourCharsVecSize{12, 12, 10, 10} /
  FourCharsVecSize{6, 4, 5, 2};
-  // CHECK: store <4 x i8> 
+  static_assert(d[0] == 2 && d[1] == 3 && d[2] == 2 && d[3] == 5, "");
+
   constexpr auto e = FourCharsVecSize{12, 12, 10, 10} %
  FourCharsVecSize{6, 4, 4, 3};
-  // CHECK: store <4 x i8> 
+  static_assert(e[0] == 0 && e[1] == 0 && e[2] == 2 && e[3] == 1, "");
 
   constexpr auto f = FourCharsVecSize{6, 3, 2, 1} + 3;
-  // CHECK: store <4 x i8> 
+  static_assert(f[0] == 9 && f[1] == 6 && f[2] == 5 && f[3] == 4, "");
+  
   constexpr auto g = FourCharsVecSize{19, 15, 12, 10} - 3;
-  // CHECK: store <4 x i8> 
+  static_assert(g[0] == 16 && g[1] == 12 && g[2] == 9 && g[3] == 7, "");  
+
   constexpr auto h = FourCharsVecSize{8, 4, 2, 1} * 3;
-  // CHECK: store <4 x i8> 
+  static_assert(h[0] == 24 && h[1] == 12 && h[2] == 6 && h[3] == 3, "");
+ 
   constexpr auto j = FourCharsVecSize{12, 15, 18, 21} / 3;
-  // CHECK: store <4 x i8> 
+  static_assert(j[0] == 4 && j[1] == 5 && j[2] == 6 && j[3] == 7, "");
+
   constexpr auto k = FourCharsVecSize{12, 17, 19, 22} % 3;
-  // CHECK: store <4 x i8> 
+  static_assert(k[0] == 0 && k[1] == 2 && k[2] == 1 && k[3] == 1, "");
 
   constexpr auto l = 3 + FourCharsVecSize{6, 3, 2, 1};
-  // CHECK: store <4 x i8> 
+  static_assert(l[0] == 9 && l[1] == 6 && l[2] == 5 && l[3] == 4, "");
+
   constexpr auto m = 20 - FourCharsVecSize{19, 15, 12, 10};
-  // CHECK: store <4 x i8> 
+  static_assert(m[0] == 1 && m[1] == 5 && m[2] == 8 && m[3] == 10, "");
+ 
   constexpr auto n = 3 * FourCharsVecSize{8, 4, 2, 1};
-  // CHECK: store <4 x i8> 
+  static_assert(n[0] == 24 && n[1] == 12 && n[2] == 6 && n[3] == 3, "");
+
   constexpr auto o = 100 / FourCharsVecSize{12, 15, 18, 21};
-  // CHECK: store <4 x i8> 
+  static_assert(o[0] == 8 && o[1] == 6 && o[2] == 5 && o[3] == 4, "");
+
   constexpr auto p = 100 % FourCharsVecSize{12, 15, 18, 21};
-  // CHECK: store <4 x i8> 
+  static_assert(p[0] == 4 && p[1] == 10 && p[2] == 10 && p[3] == 16, "");
 
   constexpr auto q = FourCharsVecSize{6, 3, 2, 1} << FourCharsVecSize{1, 1, 2, 
2};
-  // CHECK: store <4 x i8> 
+  static_assert(q[0] == 12 && q[1] == 6 && q[2] == 8 && q[3] == 4, "");
+
   constexpr auto r = FourCh

[clang] [clang][llvm-lit] Rewrite constexpr vectors test to use element access (PR #102757)

2024-08-11 Thread Amr Hesham via cfe-commits


@@ -1,10 +1,6 @@
-// RUN: %clang_cc1 -std=c++14 -Wno-unused-value %s -disable-llvm-passes 
-triple x86_64-linux-gnu -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s -Wno-uninitialized -std=c++17 -fsyntax-only -verify

AmrDeveloper wrote:

@tbaederr Done

https://github.com/llvm/llvm-project/pull/102757
___
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-11 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/3] [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 a747464582e77d..f04e6b0057b512 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 25f5bd37bbe94f..6854a321e17206 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 7e638dc1ddcdba..7505c5a1a1f27c 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 c5003d9ac02549..504dc93316db50 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 4acb3d6c9eebea..11041414c1bbab 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(NoEligibleTrivia

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

2024-08-11 Thread Vlad Serebrennikov 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())

Endilll wrote:

Honestly, I have no idea. Given that we recently came to agreement that other 
stakeholders should have a say about our extensions, I wonder what libc++ 
thinks of this.
CC @AaronBallman @ldionne @philnik777 

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-11 Thread Vlad Serebrennikov 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;
+
+const CXXRecordDecl *RD = UnqualT->getAsCXXRecordDecl();

Endilll wrote:

I included definitions of both an implicit-lifetime types, and 
implicit-lifetime class types.

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-11 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 293df8afae3ec1f99e44d6bc015e4edf2c165c8d 
49de16a0126a3fe3284f017ee4a4969d41bb4094 --extensions cpp -- 
clang/lib/Sema/SemaExprCXX.cpp clang/test/SemaCXX/type-traits.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 5fb735600f..17f21f1e65 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -5641,7 +5641,7 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, TypeTrait 
UTT,
   case UTT_IsImplicitLifetime: {
 DiagnoseVLAInCXXTypeTrait(Self, TInfo,
   tok::kw___builtin_is_implicit_lifetime);
-
+
 // [basic.types.general] p9
 // Scalar types, implicit-lifetime class types ([class.prop]),
 // array types, and cv-qualified versions of these types
@@ -5654,7 +5654,7 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, TypeTrait 
UTT,
 const CXXRecordDecl *RD = UnqualT->getAsCXXRecordDecl();
 if (!RD)
   return false;
-
+
 // [class.prop] p9
 // A class S is an implicit-lifetime class if
 //   - it is an aggregate whose destructor is not user-provided or

``




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-11 Thread Vlad Serebrennikov 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;
+
+const CXXRecordDecl *RD = UnqualT->getAsCXXRecordDecl();
+if (!RD)
+  return false;
+if (UnqualT->isAggregateType())
+  if (!RD->getDestructor()->isUserProvided())
+return true;
+if (RD->hasTrivialDestructor())

Endilll wrote:

All three types in your examples are implicit lifetime class types, because 
they are aggregates and does not have a user-provided destructor.

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-11 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/4] [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 a747464582e77d..f04e6b0057b512 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 25f5bd37bbe94f..6854a321e17206 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 7e638dc1ddcdba..7505c5a1a1f27c 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 c5003d9ac02549..504dc93316db50 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 4acb3d6c9eebea..11041414c1bbab 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(NoEligibleTrivia

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

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

Endilll wrote:

> can you add tests for non aggregate with non elligible constructors and 
> destructors ?

I don't think that a class with a destructor not eligible via requires clause 
is well-formed per http://eel.is/c++draft/class.dtor#4:
> At the end of the definition of a class, overload resolution is performed 
> among the prospective destructors declared in that class with an empty 
> argument list to select the 
> [destructor](http://eel.is/c++draft/class.dtor#def:destructor) for the class, 
> also known as the [selected 
> destructor](http://eel.is/c++draft/class.dtor#def:destructor,selected)[.](http://eel.is/c++draft/class.dtor#4.sentence-1)
The program is ill-formed if overload resolution 
fails[.](http://eel.is/c++draft/class.dtor#4.sentence-2)
Destructor selection does not constitute a reference to, or odr-use 
([[basic.def.odr]](http://eel.is/c++draft/basic.def.odr#term.odr.use)) of, the 
selected destructor, and in particular, the selected destructor may be deleted 
([[dcl.fct.def.delete]](http://eel.is/c++draft/dcl.fct.def.delete))[.](http://eel.is/c++draft/class.dtor#4.sentence-3)

Note that GCC accepts such classes (erroneously in my opinion).

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] [analyzer] Model overflow builtins (PR #102602)

2024-08-11 Thread Pavel Skripkin via cfe-commits

https://github.com/pskrgag updated 
https://github.com/llvm/llvm-project/pull/102602

>From 7b4f999b39f4308cab253204e6be41ea7a70f695 Mon Sep 17 00:00:00 2001
From: Pavel Skripkin 
Date: Fri, 9 Aug 2024 14:37:47 +0300
Subject: [PATCH 1/4] clang/csa: add initial support for builtin overflow

---
 .../Checkers/BuiltinFunctionChecker.cpp   | 124 +-
 clang/test/Analysis/builtin_overflow.c|  65 +
 .../test/Analysis/out-of-bounds-diagnostics.c |  17 +++
 3 files changed, 204 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Analysis/builtin_overflow.c

diff --git a/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
index b198b1c2ff4d11..0c8b9fa3d947b0 100644
--- a/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
@@ -21,16 +21,67 @@
 #include "clang/StaticAnalyzer/Core/PathSensitive/CallDescription.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/DynamicExtent.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
 
 using namespace clang;
 using namespace ento;
 
 namespace {
 
+QualType getOverflowBuiltinResultType(const CallEvent &Call) {
+  assert(Call.getNumArgs() == 3);
+
+  return Call.getArgExpr(2)->getType()->getPointeeType();
+}
+
+QualType getOverflowBuiltinResultType(const CallEvent &Call, CheckerContext &C,
+  unsigned BI) {
+  assert(Call.getNumArgs() == 3);
+
+  ASTContext &Ast = C.getASTContext();
+
+  switch (BI) {
+  case Builtin::BI__builtin_smul_overflow:
+  case Builtin::BI__builtin_ssub_overflow:
+  case Builtin::BI__builtin_sadd_overflow:
+return Ast.IntTy;
+  case Builtin::BI__builtin_smull_overflow:
+  case Builtin::BI__builtin_ssubl_overflow:
+  case Builtin::BI__builtin_saddl_overflow:
+return Ast.LongTy;
+  case Builtin::BI__builtin_smulll_overflow:
+  case Builtin::BI__builtin_ssubll_overflow:
+  case Builtin::BI__builtin_saddll_overflow:
+return Ast.LongLongTy;
+  case Builtin::BI__builtin_umul_overflow:
+  case Builtin::BI__builtin_usub_overflow:
+  case Builtin::BI__builtin_uadd_overflow:
+return Ast.UnsignedIntTy;
+  case Builtin::BI__builtin_umull_overflow:
+  case Builtin::BI__builtin_usubl_overflow:
+  case Builtin::BI__builtin_uaddl_overflow:
+return Ast.UnsignedLongTy;
+  case Builtin::BI__builtin_umulll_overflow:
+  case Builtin::BI__builtin_usubll_overflow:
+  case Builtin::BI__builtin_uaddll_overflow:
+return Ast.UnsignedLongLongTy;
+  case Builtin::BI__builtin_mul_overflow:
+  case Builtin::BI__builtin_sub_overflow:
+  case Builtin::BI__builtin_add_overflow:
+return getOverflowBuiltinResultType(Call);
+  default:
+assert(false && "Unknown overflow builtin");
+  }
+}
+
 class BuiltinFunctionChecker : public Checker {
 public:
   bool evalCall(const CallEvent &Call, CheckerContext &C) const;
+  void HandleOverflowBuiltin(const CallEvent &Call, CheckerContext &C,
+ BinaryOperator::Opcode Op,
+ QualType ResultType) const;
 
 private:
   // From: clang/include/clang/Basic/Builtins.def
@@ -50,6 +101,44 @@ class BuiltinFunctionChecker : public Checker {
 
 } // namespace
 
+void BuiltinFunctionChecker::HandleOverflowBuiltin(const CallEvent &Call,
+   CheckerContext &C,
+   BinaryOperator::Opcode Op,
+   QualType ResultType) const {
+  // All __builtin_*_overflow functions take 3 argumets.
+  assert(Call.getNumArgs() == 3);
+
+  ProgramStateRef State = C.getState();
+  SValBuilder &SVB = C.getSValBuilder();
+  const Expr *CE = Call.getOriginExpr();
+
+  SVal Arg1 = Call.getArgSVal(0);
+  SVal Arg2 = Call.getArgSVal(1);
+
+  SVal RetVal = SVB.evalBinOp(State, Op, Arg1, Arg2, ResultType);
+
+  // TODO: Handle overflows with values that known to overflow. Like INT_MAX + 
1
+  // should not produce state for non-overflow case and threat it as
+  // unreachable.
+
+  // Handle non-overflow case.
+  {
+ProgramStateRef StateSuccess =
+State->BindExpr(CE, C.getLocationContext(), SVB.makeTruthVal(false));
+
+if (auto L = Call.getArgSVal(2).getAs())
+  StateSuccess = StateSuccess->bindLoc(*L, RetVal, C.getLocationContext());
+
+C.addTransition(StateSuccess);
+  }
+
+  // Handle overflow case.
+  {
+C.addTransition(
+State->BindExpr(CE, C.getLocationContext(), SVB.makeTruthVal(true)));
+  }
+}
+
 bool BuiltinFunctionChecker::isBuiltinLikeFunction(
 const CallEvent &Call) const {
   const auto *FD = llvm::dyn_cast_or_null(Call.getDecl());
@@ -82,10 +171,41 @@ bool BuiltinFunctionChe

[clang] Resolve FIXME: Look at E, not M (PR #85541)

2024-08-11 Thread Rose Silicon via cfe-commits

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


[clang] [clang][Interp] Fix diagnosing uninitialized nested union fields (PR #102824)

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

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

>From 618e8c138544bab863da0d6595c6a9f38426 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sun, 11 Aug 2024 19:52:51 +0200
Subject: [PATCH] [clang][Interp] Fix diagnosing uninitialized nested union
 fields

We were calling initialize() unconditionally when copying the union.
---
 clang/lib/AST/Interp/Interp.cpp|  7 +-
 clang/lib/AST/Interp/InterpBuiltin.cpp | 95 --
 clang/test/AST/Interp/unions.cpp   | 26 ++-
 3 files changed, 89 insertions(+), 39 deletions(-)

diff --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index 89ac6938931133..c65d3789333852 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -125,12 +125,17 @@ static bool CheckActive(InterpState &S, CodePtr OpPC, 
const Pointer &Ptr,
   if (Ptr.isActive())
 return true;
 
+  assert(Ptr.isField() && Ptr.getField());
+
   Pointer U = Ptr.getBase();
   Pointer C = Ptr;
   while (!U.isRoot() && U.inUnion() && !U.isActive()) {
-C = U;
+if (U.getField())
+  C = U;
 U = U.getBase();
   }
+  assert(C.isField());
+
   // Get the inactive field descriptor.
   const FieldDecl *InactiveField = C.getField();
   assert(InactiveField);
diff --git a/clang/lib/AST/Interp/InterpBuiltin.cpp 
b/clang/lib/AST/Interp/InterpBuiltin.cpp
index 1841a2a4714d89..c3370e2e5286e0 100644
--- a/clang/lib/AST/Interp/InterpBuiltin.cpp
+++ b/clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -1635,7 +1635,58 @@ bool SetThreeWayComparisonField(InterpState &S, CodePtr 
OpPC,
   return true;
 }
 
-bool DoMemcpy(InterpState &S, CodePtr OpPC, const Pointer &Src, Pointer &Dest) 
{
+static bool copyComposite(InterpState &S, CodePtr OpPC, const Pointer &Src,
+  Pointer &Dest, bool Activate);
+static bool copyRecord(InterpState &S, CodePtr OpPC, const Pointer &Src,
+   Pointer &Dest, bool Activate = false) {
+  [[maybe_unused]] const Descriptor *SrcDesc = Src.getFieldDesc();
+  const Descriptor *DestDesc = Dest.getFieldDesc();
+
+  auto copyField = [&](const Record::Field &F, bool Activate) -> bool {
+Pointer DestField = Dest.atField(F.Offset);
+if (std::optional FT = S.Ctx.classify(F.Decl->getType())) {
+  TYPE_SWITCH(*FT, {
+DestField.deref() = Src.atField(F.Offset).deref();
+if (Src.atField(F.Offset).isInitialized())
+  DestField.initialize();
+if (Activate)
+  DestField.activate();
+  });
+  return true;
+}
+// Composite field.
+return copyComposite(S, OpPC, Src.atField(F.Offset), DestField, Activate);
+  };
+
+  assert(SrcDesc->isRecord());
+  assert(SrcDesc->ElemRecord == DestDesc->ElemRecord);
+  const Record *R = DestDesc->ElemRecord;
+  for (const Record::Field &F : R->fields()) {
+if (R->isUnion()) {
+  // For unions, only copy the active field.
+  const Pointer &SrcField = Src.atField(F.Offset);
+  if (SrcField.isActive()) {
+if (!copyField(F, /*Activate=*/true))
+  return false;
+  }
+} else {
+  if (!copyField(F, Activate))
+return false;
+}
+  }
+
+  for (const Record::Base &B : R->bases()) {
+Pointer DestBase = Dest.atField(B.Offset);
+if (!copyRecord(S, OpPC, Src.atField(B.Offset), DestBase, Activate))
+  return false;
+  }
+
+  Dest.initialize();
+  return true;
+}
+
+static bool copyComposite(InterpState &S, CodePtr OpPC, const Pointer &Src,
+  Pointer &Dest, bool Activate = false) {
   assert(Src.isLive() && Dest.isLive());
 
   [[maybe_unused]] const Descriptor *SrcDesc = Src.getFieldDesc();
@@ -1657,44 +1708,14 @@ bool DoMemcpy(InterpState &S, CodePtr OpPC, const 
Pointer &Src, Pointer &Dest) {
 return true;
   }
 
-  if (DestDesc->isRecord()) {
-auto copyField = [&](const Record::Field &F, bool Activate) -> bool {
-  Pointer DestField = Dest.atField(F.Offset);
-  if (std::optional FT = S.Ctx.classify(F.Decl->getType())) {
-TYPE_SWITCH(*FT, {
-  DestField.deref() = Src.atField(F.Offset).deref();
-  DestField.initialize();
-  if (Activate)
-DestField.activate();
-});
-return true;
-  }
-  return Invalid(S, OpPC);
-};
-
-assert(SrcDesc->isRecord());
-assert(SrcDesc->ElemRecord == DestDesc->ElemRecord);
-const Record *R = DestDesc->ElemRecord;
-for (const Record::Field &F : R->fields()) {
-  if (R->isUnion()) {
-// For unions, only copy the active field.
-const Pointer &SrcField = Src.atField(F.Offset);
-if (SrcField.isActive()) {
-  if (!copyField(F, /*Activate=*/true))
-return false;
-}
-  } else {
-if (!copyField(F, /*Activate=*/false))
-  return false;
-  }
-}
-return true;
-  }
-
-  // FIXME: Composite types.
-
+  if (DestDesc->isRecord())
+return copyRe

[clang-tools-extra] [clang-tidy] use upper case letters for bool conversion suffix (PR #102831)

2024-08-11 Thread via cfe-commits

https://github.com/Da-Viper created 
https://github.com/llvm/llvm-project/pull/102831

When readability-implicit-bool-conversion-check and 
readability-uppercase-literal-suffix-check is enabled this will cause you to 
apply a fix twice

from (!i) -> (i == 0u) to (i == 0U) twice instead will skip the middle one

>From 8a4f6af9fc1f44c2f8b5fd3693ca14eaf776fd02 Mon Sep 17 00:00:00 2001
From: Ebuka Ezike 
Date: Sun, 11 Aug 2024 21:39:35 +0100
Subject: [PATCH] [clang-tidy] use upper cace letters for bool conversion
 suffix

When readability-implicit-bool-conversion-check and 
readability-uppercase-literal-suffix-check is enabled this will cause you to 
apply a fix twice

from (!i) -> (i == 0u) to (i == 0U) twice instead will skip the middle one
---
 .../readability/ImplicitBoolConversionCheck.cpp   | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
index aa115cd450c4f6..258cec80dd0bac 100644
--- a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
@@ -43,10 +43,10 @@ StringRef getZeroLiteralToCompareWithForType(CastKind 
CastExprKind,
  ASTContext &Context) {
   switch (CastExprKind) {
   case CK_IntegralToBoolean:
-return Type->isUnsignedIntegerType() ? "0u" : "0";
+return Type->isUnsignedIntegerType() ? "0U" : "0";
 
   case CK_FloatingToBoolean:
-return Context.hasSameType(Type, Context.FloatTy) ? "0.0f" : "0.0";
+return Context.hasSameType(Type, Context.FloatTy) ? "0.0F" : "0.0";
 
   case CK_PointerToBoolean:
   case CK_MemberPointerToBoolean: // Fall-through on purpose.
@@ -202,13 +202,13 @@ StringRef getEquivalentForBoolLiteral(const 
CXXBoolLiteralExpr *BoolLiteral,
 
   if (DestType->isFloatingType()) {
 if (Context.hasSameType(DestType, Context.FloatTy)) {
-  return BoolLiteral->getValue() ? "1.0f" : "0.0f";
+  return BoolLiteral->getValue() ? "1.0F" : "0.0F";
 }
 return BoolLiteral->getValue() ? "1.0" : "0.0";
   }
 
   if (DestType->isUnsignedIntegerType()) {
-return BoolLiteral->getValue() ? "1u" : "0u";
+return BoolLiteral->getValue() ? "1U" : "0U";
   }
   return BoolLiteral->getValue() ? "1" : "0";
 }

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


[clang-tools-extra] [clang-tidy] use upper case letters for bool conversion suffix (PR #102831)

2024-08-11 Thread via cfe-commits

llvmbot wrote:




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

Author: None (Da-Viper)


Changes

When readability-implicit-bool-conversion-check and 
readability-uppercase-literal-suffix-check is enabled this will cause you to 
apply a fix twice

from (!i) -> (i == 0u) to (i == 0U) twice instead will skip the middle one

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


1 Files Affected:

- (modified) 
clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp (+4-4) 


``diff
diff --git 
a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
index aa115cd450c4f6..258cec80dd0bac 100644
--- a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
@@ -43,10 +43,10 @@ StringRef getZeroLiteralToCompareWithForType(CastKind 
CastExprKind,
  ASTContext &Context) {
   switch (CastExprKind) {
   case CK_IntegralToBoolean:
-return Type->isUnsignedIntegerType() ? "0u" : "0";
+return Type->isUnsignedIntegerType() ? "0U" : "0";
 
   case CK_FloatingToBoolean:
-return Context.hasSameType(Type, Context.FloatTy) ? "0.0f" : "0.0";
+return Context.hasSameType(Type, Context.FloatTy) ? "0.0F" : "0.0";
 
   case CK_PointerToBoolean:
   case CK_MemberPointerToBoolean: // Fall-through on purpose.
@@ -202,13 +202,13 @@ StringRef getEquivalentForBoolLiteral(const 
CXXBoolLiteralExpr *BoolLiteral,
 
   if (DestType->isFloatingType()) {
 if (Context.hasSameType(DestType, Context.FloatTy)) {
-  return BoolLiteral->getValue() ? "1.0f" : "0.0f";
+  return BoolLiteral->getValue() ? "1.0F" : "0.0F";
 }
 return BoolLiteral->getValue() ? "1.0" : "0.0";
   }
 
   if (DestType->isUnsignedIntegerType()) {
-return BoolLiteral->getValue() ? "1u" : "0u";
+return BoolLiteral->getValue() ? "1U" : "0U";
   }
   return BoolLiteral->getValue() ? "1" : "0";
 }

``




https://github.com/llvm/llvm-project/pull/102831
___
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-11 Thread Mital Ashok 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;
+
+const CXXRecordDecl *RD = UnqualT->getAsCXXRecordDecl();
+if (!RD)
+  return false;
+if (UnqualT->isAggregateType())
+  if (!RD->getDestructor()->isUserProvided())
+return true;
+if (RD->hasTrivialDestructor())

MitalAshok wrote:

@Endilll That's correct for `Z` but `X` and `Y` are not aggregates because they 
have user-declared constructors, so they need a non-deleted destructor

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] [llvm] [Offload][CUDA] Allow CUDA kernels to use LLVM/Offload (PR #94549)

2024-08-11 Thread Johannes Doerfert via cfe-commits

https://github.com/jdoerfert updated 
https://github.com/llvm/llvm-project/pull/94549

>From 96f25f66fd86831e6039fc6ddf30fa8030595456 Mon Sep 17 00:00:00 2001
From: Johannes Doerfert 
Date: Mon, 3 Jun 2024 19:52:12 -0700
Subject: [PATCH] [Offload][CUDA] Allow CUDA kernels to use LLVM/Offload
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Through the new `-foffload-via-llvm` flag, CUDA kernels can now be
lowered to the LLVM/Offload API. On the Clang side, this is simply done
by using the OpenMP offload toolchain and emitting calls to `llvm*`
functions to orchestrate the kernel launch rather than `cuda*`
functions. These `llvm*` functions are implemented on top of the
existing LLVM/Offload API.

As we are about to redefine the Offload API, this wil help us in the
design process as a second offload language.

We do not support any CUDA APIs yet, however, we could:
  https://www.osti.gov/servlets/purl/1892137

For proper host execution we need to resurrect/rebase
  https://tianshilei.me/wp-content/uploads/2021/12/llpp-2021.pdf
(which was designed for debugging).

```
❯❯❯ cat test.cu
extern "C" {
void *llvm_omp_target_alloc_shared(size_t Size, int DeviceNum);
void llvm_omp_target_free_shared(void *DevicePtr, int DeviceNum);
}

__global__ void square(int *A) { *A = 42; }

int main(int argc, char **argv) {
  int DevNo = 0;
  int *Ptr = reinterpret_cast(llvm_omp_target_alloc_shared(4, DevNo));
  *Ptr = 7;
  printf("Ptr %p, *Ptr %i\n", Ptr, *Ptr);
  square<<<1, 1>>>(Ptr);
  printf("Ptr %p, *Ptr %i\n", Ptr, *Ptr);
  llvm_omp_target_free_shared(Ptr, DevNo);
}

❯❯❯ clang++ test.cu -O3 -o test123 -foffload-via-llvm --offload-arch=native

❯❯❯ llvm-objdump --offloading test123

test123:file format elf64-x86-64

OFFLOADING IMAGE [0]:
kindelf
archgfx90a
triple  amdgcn-amd-amdhsa
produceropenmp

❯❯❯ LIBOMPTARGET_INFO=16 ./test123
Ptr 0x155448ac8000, *Ptr 7
Ptr 0x155448ac8000, *Ptr 42
```
---
 clang/include/clang/Basic/LangOptions.def |  1 +
 clang/include/clang/Driver/Options.td |  6 ++
 clang/lib/CodeGen/CGCUDANV.cpp| 97 ---
 clang/lib/Driver/Driver.cpp   | 19 ++--
 clang/lib/Driver/ToolChains/Clang.cpp | 27 +-
 clang/lib/Driver/ToolChains/CommonArgs.cpp|  7 +-
 clang/lib/Driver/ToolChains/Cuda.cpp  | 27 +++---
 clang/lib/Headers/CMakeLists.txt  | 18 +++-
 .../llvm_offload_wrappers/__llvm_offload.h| 31 ++
 .../__llvm_offload_device.h   | 10 ++
 .../__llvm_offload_host.h | 15 +++
 .../__clang_openmp_device_functions.h |  9 +-
 clang/lib/Sema/SemaCUDA.cpp   |  3 +
 clang/test/CodeGenCUDA/offload_via_llvm.cu| 97 +++
 clang/test/Driver/cuda-via-liboffload.cu  | 23 +
 offload/include/Shared/APITypes.h |  5 +-
 offload/include/omptarget.h   |  2 +-
 .../common/src/PluginInterface.cpp| 13 ++-
 offload/src/CMakeLists.txt|  1 +
 offload/src/KernelLanguage/API.cpp| 76 +++
 offload/src/exports   |  3 +
 offload/test/lit.cfg  |  2 +-
 offload/test/offloading/CUDA/basic_launch.cu  | 31 ++
 .../CUDA/basic_launch_blocks_and_threads.cu   | 32 ++
 .../offloading/CUDA/basic_launch_multi_arg.cu | 41 
 offload/test/offloading/CUDA/kernel_tu.cu.inc |  1 +
 offload/test/offloading/CUDA/launch_tu.cu | 32 ++
 27 files changed, 576 insertions(+), 53 deletions(-)
 create mode 100644 clang/lib/Headers/llvm_offload_wrappers/__llvm_offload.h
 create mode 100644 
clang/lib/Headers/llvm_offload_wrappers/__llvm_offload_device.h
 create mode 100644 
clang/lib/Headers/llvm_offload_wrappers/__llvm_offload_host.h
 create mode 100644 clang/test/CodeGenCUDA/offload_via_llvm.cu
 create mode 100644 clang/test/Driver/cuda-via-liboffload.cu
 create mode 100644 offload/src/KernelLanguage/API.cpp
 create mode 100644 offload/test/offloading/CUDA/basic_launch.cu
 create mode 100644 
offload/test/offloading/CUDA/basic_launch_blocks_and_threads.cu
 create mode 100644 offload/test/offloading/CUDA/basic_launch_multi_arg.cu
 create mode 100644 offload/test/offloading/CUDA/kernel_tu.cu.inc
 create mode 100644 offload/test/offloading/CUDA/launch_tu.cu

diff --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 54e689a7a42213..ca9c00a1473bbd 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -298,6 +298,7 @@ LANGOPT(GPUMaxThreadsPerBlock, 32, 1024, "default max 
threads per block for kern
 LANGOPT(GPUDeferDiag, 1, 0, "defer host/device related diagnostic messages for 
CUDA/HIP")
 LANGOPT(GPUExcludeWrongSideOverloads, 1, 0, "always exclude wrong side 
overloads in overloading resolution for CUDA/HIP")
 LANGOPT(OffloadingNewDriver, 1, 0, "use th

[clang] [llvm] [PAC][ELF][AArch64] Encode several ptrauth features in PAuth core info (PR #102508)

2024-08-11 Thread Fangrui Song via cfe-commits

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


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


[clang] Resolve FIXME: Look at E, not M (PR #85541)

2024-08-11 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

> Hmm. The best solution there is probably to use a consistent representation 
> but introduce some sort of `GLValueThatTheStandardAbsurdlyPretendsIsAnRValue` 
> (definitely the only and best word for this, ship it) that we can use as the 
> value category. IIRC, something similar happens in C where the standard 
> pretends that function l-values don't exist.

IIRC GCC also implements a similar value category as an alternative to the 
two-phase lookup rules for implicit moves, pre-C++23. This is almost an XValue, 
except it binds to LValue references as well.

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


[clang] [clang-tools-extra] [lldb] [clang] Reland: Instantiate alias templates with sugar (PR #101858)

2024-08-11 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

> It is not only valuable to external resugarers. Another point that warrants 
> an introduction of it is for unevaluated lambdas. These lambdas e.g. 
> appearing as part of the `using Alias = decltype(lambda)` could carry a 
> requires expression and thus evaluating it requires the recovery of the 
> instantiating template arguments for the type alias, which isn't a quite 
> natural thing without such a Decl. I have improved some of these situations 
> through an on-stack InstantiatingTemplate to help to inspect the template 
> arguments; however, that approach is somewhat cumbersome and still couldn't 
> extend to other scenarios e.g. mangling these lambdas. (#97024. We need a 
> correct DeclContext for the lambda, yet a `TypeAliasTemplateDecl` isn't a 
> DeclContext, unfortunately.)

So in clang we have taken a different approach, in order to not sacrifice 
template type alias performance, we instead put a `Decl` context reference in 
templated declarations that can appear within a template type alias pattern, 
such as lambdas and blocks.

The idea is a tradeoff where template type alias, which are very light weight, 
don't get the big performance hit they would otherwise if they had a 
per-specialization declaration.
But we get a slight performance hit on Lambdas instead, but these are much more 
heavy weight and need the declcontext anyway for other reasons.
The other tradeoff is increased implementation complexity.

See for example CXXRecordDecl's `getLambdaContextDecl` function.

Unfortunately there is an issue where we currently only store this lambda 
context when we need it for mangling reasons, but there are other reasons to 
depend on it as well, and code in clang currently makes the incorrect 
assumption that it will always be available when needed.

I am working on a patch to fix that.

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


[clang] [llvm] [Offload][CUDA] Allow CUDA kernels to use LLVM/Offload (PR #94549)

2024-08-11 Thread Johannes Doerfert via cfe-commits

https://github.com/jdoerfert updated 
https://github.com/llvm/llvm-project/pull/94549

>From 1a3cf890f27db42684061794b9c95665db54656b Mon Sep 17 00:00:00 2001
From: Johannes Doerfert 
Date: Mon, 3 Jun 2024 19:52:12 -0700
Subject: [PATCH] [Offload][CUDA] Allow CUDA kernels to use LLVM/Offload
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Through the new `-foffload-via-llvm` flag, CUDA kernels can now be
lowered to the LLVM/Offload API. On the Clang side, this is simply done
by using the OpenMP offload toolchain and emitting calls to `llvm*`
functions to orchestrate the kernel launch rather than `cuda*`
functions. These `llvm*` functions are implemented on top of the
existing LLVM/Offload API.

As we are about to redefine the Offload API, this wil help us in the
design process as a second offload language.

We do not support any CUDA APIs yet, however, we could:
  https://www.osti.gov/servlets/purl/1892137

For proper host execution we need to resurrect/rebase
  https://tianshilei.me/wp-content/uploads/2021/12/llpp-2021.pdf
(which was designed for debugging).

```
❯❯❯ cat test.cu
extern "C" {
void *llvm_omp_target_alloc_shared(size_t Size, int DeviceNum);
void llvm_omp_target_free_shared(void *DevicePtr, int DeviceNum);
}

__global__ void square(int *A) { *A = 42; }

int main(int argc, char **argv) {
  int DevNo = 0;
  int *Ptr = reinterpret_cast(llvm_omp_target_alloc_shared(4, DevNo));
  *Ptr = 7;
  printf("Ptr %p, *Ptr %i\n", Ptr, *Ptr);
  square<<<1, 1>>>(Ptr);
  printf("Ptr %p, *Ptr %i\n", Ptr, *Ptr);
  llvm_omp_target_free_shared(Ptr, DevNo);
}

❯❯❯ clang++ test.cu -O3 -o test123 -foffload-via-llvm --offload-arch=native

❯❯❯ llvm-objdump --offloading test123

test123:file format elf64-x86-64

OFFLOADING IMAGE [0]:
kindelf
archgfx90a
triple  amdgcn-amd-amdhsa
produceropenmp

❯❯❯ LIBOMPTARGET_INFO=16 ./test123
Ptr 0x155448ac8000, *Ptr 7
Ptr 0x155448ac8000, *Ptr 42
```
---
 clang/include/clang/Basic/LangOptions.def |  1 +
 clang/include/clang/Driver/Options.td |  6 ++
 clang/lib/CodeGen/CGCUDANV.cpp| 97 ---
 clang/lib/CodeGen/CodeGenFunction.cpp |  3 +-
 clang/lib/Driver/Driver.cpp   | 19 ++--
 clang/lib/Driver/ToolChains/Clang.cpp | 31 +-
 clang/lib/Driver/ToolChains/CommonArgs.cpp|  7 +-
 clang/lib/Driver/ToolChains/Cuda.cpp  | 27 +++---
 clang/lib/Headers/CMakeLists.txt  | 18 +++-
 .../llvm_offload_wrappers/__llvm_offload.h| 31 ++
 .../__llvm_offload_device.h   | 10 ++
 .../__llvm_offload_host.h | 15 +++
 .../__clang_openmp_device_functions.h |  9 +-
 clang/lib/Sema/SemaCUDA.cpp   |  3 +
 clang/test/CodeGenCUDA/offload_via_llvm.cu| 97 +++
 clang/test/Driver/cuda-via-liboffload.cu  | 23 +
 offload/include/Shared/APITypes.h |  5 +-
 offload/include/omptarget.h   |  2 +-
 .../common/src/PluginInterface.cpp| 13 ++-
 offload/src/CMakeLists.txt|  1 +
 offload/src/KernelLanguage/API.cpp| 76 +++
 offload/src/exports   |  3 +
 offload/test/lit.cfg  |  2 +-
 offload/test/offloading/CUDA/basic_launch.cu  | 31 ++
 .../CUDA/basic_launch_blocks_and_threads.cu   | 32 ++
 .../offloading/CUDA/basic_launch_multi_arg.cu | 41 
 offload/test/offloading/CUDA/kernel_tu.cu.inc |  1 +
 offload/test/offloading/CUDA/launch_tu.cu | 32 ++
 28 files changed, 582 insertions(+), 54 deletions(-)
 create mode 100644 clang/lib/Headers/llvm_offload_wrappers/__llvm_offload.h
 create mode 100644 
clang/lib/Headers/llvm_offload_wrappers/__llvm_offload_device.h
 create mode 100644 
clang/lib/Headers/llvm_offload_wrappers/__llvm_offload_host.h
 create mode 100644 clang/test/CodeGenCUDA/offload_via_llvm.cu
 create mode 100644 clang/test/Driver/cuda-via-liboffload.cu
 create mode 100644 offload/src/KernelLanguage/API.cpp
 create mode 100644 offload/test/offloading/CUDA/basic_launch.cu
 create mode 100644 
offload/test/offloading/CUDA/basic_launch_blocks_and_threads.cu
 create mode 100644 offload/test/offloading/CUDA/basic_launch_multi_arg.cu
 create mode 100644 offload/test/offloading/CUDA/kernel_tu.cu.inc
 create mode 100644 offload/test/offloading/CUDA/launch_tu.cu

diff --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 54e689a7a42213..ca9c00a1473bbd 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -298,6 +298,7 @@ LANGOPT(GPUMaxThreadsPerBlock, 32, 1024, "default max 
threads per block for kern
 LANGOPT(GPUDeferDiag, 1, 0, "defer host/device related diagnostic messages for 
CUDA/HIP")
 LANGOPT(GPUExcludeWrongSideOverloads, 1, 0, "always exclude wrong side 
overloads in overloading resolution for

[clang] [clang] Ensure `--print-runtime-dir` path exists (PR #102834)

2024-08-11 Thread Alexandre Ganea via cfe-commits

https://github.com/aganea created 
https://github.com/llvm/llvm-project/pull/102834

Before this PR, `clang --print-runtime-dir` used to report a non-existant 
directory if `LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=OFF`.

We now check if any of the known runtime directories exist before printing on 
stdout. If it doesn't, we print `(runtime dir is not present)`.

>From d1d1340b6876d83d48949306e43c723696bf4753 Mon Sep 17 00:00:00 2001
From: Alexandre Ganea 
Date: Sun, 11 Aug 2024 19:03:14 -0400
Subject: [PATCH] [clang] Ensure --print-runtime-dir exits

Before this PR, `clang --print-runtime-dir` used to report a non-existant
directory if LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=OFF.

We now check if any of the known runtime directories exist before
printing on stdout.
---
 clang/lib/Driver/Driver.cpp | 12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index f4e909b79389bc..4c8cd36dd118ee 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -2230,10 +2230,14 @@ bool Driver::HandleImmediateArgs(Compilation &C) {
   }
 
   if (C.getArgs().hasArg(options::OPT_print_runtime_dir)) {
-if (std::optional RuntimePath = TC.getRuntimePath())
-  llvm::outs() << *RuntimePath << '\n';
-else
-  llvm::outs() << TC.getCompilerRTPath() << '\n';
+for (auto RuntimePath :
+ {TC.getRuntimePath(), std::make_optional(TC.getCompilerRTPath())}) {
+  if (RuntimePath && getVFS().exists(*RuntimePath)) {
+llvm::outs() << *RuntimePath << '\n';
+return false;
+  }
+}
+llvm::outs() << "(runtime dir is not present)" << '\n';
 return false;
   }
 

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


[clang] [clang] Ensure `--print-runtime-dir` path exists (PR #102834)

2024-08-11 Thread Alexandre Ganea via cfe-commits

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


[clang] [clang] Ensure `--print-runtime-dir` path exists (PR #102834)

2024-08-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Alexandre Ganea (aganea)


Changes

Before this PR, `clang --print-runtime-dir` used to report a non-existent 
directory if `LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=OFF`.

We now check if any of the known runtime directories exist before printing on 
stdout. If it doesn't, we print `(runtime dir is not present)`.

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


1 Files Affected:

- (modified) clang/lib/Driver/Driver.cpp (+8-4) 


``diff
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index f4e909b79389bc..4c8cd36dd118ee 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -2230,10 +2230,14 @@ bool Driver::HandleImmediateArgs(Compilation &C) {
   }
 
   if (C.getArgs().hasArg(options::OPT_print_runtime_dir)) {
-if (std::optional RuntimePath = TC.getRuntimePath())
-  llvm::outs() << *RuntimePath << '\n';
-else
-  llvm::outs() << TC.getCompilerRTPath() << '\n';
+for (auto RuntimePath :
+ {TC.getRuntimePath(), std::make_optional(TC.getCompilerRTPath())}) {
+  if (RuntimePath && getVFS().exists(*RuntimePath)) {
+llvm::outs() << *RuntimePath << '\n';
+return false;
+  }
+}
+llvm::outs() << "(runtime dir is not present)" << '\n';
 return false;
   }
 

``




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


[clang] [clang] Ensure `--print-runtime-dir` path exists (PR #102834)

2024-08-11 Thread Alexandre Ganea via cfe-commits

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


[clang] [clang] Ensure `--print-runtime-dir` path exists (PR #102834)

2024-08-11 Thread Alexandre Ganea via cfe-commits

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


[clang] [clang] Ensure `--print-runtime-dir` path exists (PR #102834)

2024-08-11 Thread Alexandre Ganea via cfe-commits

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


[clang] [clang-tools-extra] [lldb] [clang] Reland: Instantiate alias templates with sugar (PR #101858)

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

zyn0217 wrote:

> See for example CXXRecordDecl's getLambdaContextDecl function.
> Unfortunately there is an issue where we currently only store this lambda 
> context when we need it for mangling reasons, …

Yeah, I remember we use that to store an ImplicitConceptSpecializationDecl as 
well, not only for the purpose of mangling but also for lambdas appearing 
inside a concept. We probably could do the same for the using aliases, though 
that still needs some tweaking to store template arguments.

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


[clang] [llvm] [Offload][CUDA] Allow CUDA kernels to use LLVM/Offload (PR #94549)

2024-08-11 Thread Johannes Doerfert via cfe-commits

https://github.com/jdoerfert updated 
https://github.com/llvm/llvm-project/pull/94549

>From af99a3106a886d634eace010295796b3111b99ee Mon Sep 17 00:00:00 2001
From: Johannes Doerfert 
Date: Mon, 3 Jun 2024 19:52:12 -0700
Subject: [PATCH] [Offload][CUDA] Allow CUDA kernels to use LLVM/Offload
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Through the new `-foffload-via-llvm` flag, CUDA kernels can now be
lowered to the LLVM/Offload API. On the Clang side, this is simply done
by using the OpenMP offload toolchain and emitting calls to `llvm*`
functions to orchestrate the kernel launch rather than `cuda*`
functions. These `llvm*` functions are implemented on top of the
existing LLVM/Offload API.

As we are about to redefine the Offload API, this wil help us in the
design process as a second offload language.

We do not support any CUDA APIs yet, however, we could:
  https://www.osti.gov/servlets/purl/1892137

For proper host execution we need to resurrect/rebase
  https://tianshilei.me/wp-content/uploads/2021/12/llpp-2021.pdf
(which was designed for debugging).

```
❯❯❯ cat test.cu
extern "C" {
void *llvm_omp_target_alloc_shared(size_t Size, int DeviceNum);
void llvm_omp_target_free_shared(void *DevicePtr, int DeviceNum);
}

__global__ void square(int *A) { *A = 42; }

int main(int argc, char **argv) {
  int DevNo = 0;
  int *Ptr = reinterpret_cast(llvm_omp_target_alloc_shared(4, DevNo));
  *Ptr = 7;
  printf("Ptr %p, *Ptr %i\n", Ptr, *Ptr);
  square<<<1, 1>>>(Ptr);
  printf("Ptr %p, *Ptr %i\n", Ptr, *Ptr);
  llvm_omp_target_free_shared(Ptr, DevNo);
}

❯❯❯ clang++ test.cu -O3 -o test123 -foffload-via-llvm --offload-arch=native

❯❯❯ llvm-objdump --offloading test123

test123:file format elf64-x86-64

OFFLOADING IMAGE [0]:
kindelf
archgfx90a
triple  amdgcn-amd-amdhsa
produceropenmp

❯❯❯ LIBOMPTARGET_INFO=16 ./test123
Ptr 0x155448ac8000, *Ptr 7
Ptr 0x155448ac8000, *Ptr 42
```
---
 clang/include/clang/Basic/LangOptions.def |  1 +
 clang/include/clang/Driver/Options.td |  6 ++
 clang/lib/CodeGen/CGCUDANV.cpp| 97 ---
 clang/lib/CodeGen/CodeGenFunction.cpp |  3 +-
 clang/lib/Driver/Driver.cpp   | 19 ++--
 clang/lib/Driver/ToolChains/Clang.cpp | 31 +-
 clang/lib/Driver/ToolChains/CommonArgs.cpp|  7 +-
 clang/lib/Driver/ToolChains/Cuda.cpp  | 27 +++---
 clang/lib/Headers/CMakeLists.txt  | 18 +++-
 .../llvm_offload_wrappers/__llvm_offload.h| 31 ++
 .../__llvm_offload_device.h   | 10 ++
 .../__llvm_offload_host.h | 15 +++
 .../__clang_openmp_device_functions.h |  9 +-
 clang/lib/Sema/SemaCUDA.cpp   |  3 +
 clang/test/CodeGenCUDA/Inputs/cuda.h  |  5 +
 clang/test/CodeGenCUDA/offload_via_llvm.cu| 90 +
 clang/test/Driver/cuda-via-liboffload.cu  | 23 +
 offload/include/Shared/APITypes.h |  5 +-
 offload/include/omptarget.h   |  2 +-
 .../common/src/PluginInterface.cpp| 13 ++-
 offload/src/CMakeLists.txt|  1 +
 offload/src/KernelLanguage/API.cpp| 76 +++
 offload/src/exports   |  3 +
 offload/test/lit.cfg  |  2 +-
 offload/test/offloading/CUDA/basic_launch.cu  | 31 ++
 .../CUDA/basic_launch_blocks_and_threads.cu   | 32 ++
 .../offloading/CUDA/basic_launch_multi_arg.cu | 41 
 offload/test/offloading/CUDA/kernel_tu.cu.inc |  1 +
 offload/test/offloading/CUDA/launch_tu.cu | 32 ++
 29 files changed, 580 insertions(+), 54 deletions(-)
 create mode 100644 clang/lib/Headers/llvm_offload_wrappers/__llvm_offload.h
 create mode 100644 
clang/lib/Headers/llvm_offload_wrappers/__llvm_offload_device.h
 create mode 100644 
clang/lib/Headers/llvm_offload_wrappers/__llvm_offload_host.h
 create mode 100644 clang/test/CodeGenCUDA/offload_via_llvm.cu
 create mode 100644 clang/test/Driver/cuda-via-liboffload.cu
 create mode 100644 offload/src/KernelLanguage/API.cpp
 create mode 100644 offload/test/offloading/CUDA/basic_launch.cu
 create mode 100644 
offload/test/offloading/CUDA/basic_launch_blocks_and_threads.cu
 create mode 100644 offload/test/offloading/CUDA/basic_launch_multi_arg.cu
 create mode 100644 offload/test/offloading/CUDA/kernel_tu.cu.inc
 create mode 100644 offload/test/offloading/CUDA/launch_tu.cu

diff --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 54e689a7a42213..ca9c00a1473bbd 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -298,6 +298,7 @@ LANGOPT(GPUMaxThreadsPerBlock, 32, 1024, "default max 
threads per block for kern
 LANGOPT(GPUDeferDiag, 1, 0, "defer host/device related diagnostic messages for 
CUDA/HIP")
 LANGOPT(GPUExcludeWrongSideOverloads, 1, 0, "always exclude

[clang] [llvm] Add normalize builtins and normalize HLSL function to DirectX and SPIR-V backend (PR #102683)

2024-08-11 Thread Farzon Lotfi via cfe-commits


@@ -4725,6 +4725,12 @@ def HLSLMad : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void(...)";
 }
 
+def HLSLNormalize : LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_normalize"];

farzonl wrote:

is this an elementwise case? isnt it  `n = normalize(x)  = n[i] = x[i]/ 
length(x)`

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


[clang] [llvm] Add normalize builtins and normalize HLSL function to DirectX and SPIR-V backend (PR #102683)

2024-08-11 Thread Farzon Lotfi via cfe-commits


@@ -18584,6 +18584,29 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned 
BuiltinID,
 CGM.getHLSLRuntime().getLengthIntrinsic(), ArrayRef{X},
 nullptr, "hlsl.length");
   }
+  case Builtin::BI__builtin_hlsl_normalize: {
+Value *X = EmitScalarExpr(E->getArg(0));
+
+assert(E->getArg(0)->getType()->hasFloatingRepresentation() &&
+   "normalize operand must have a float representation");
+
+// scalar inputs should expect a scalar return type
+if (!E->getArg(0)->getType()->isVectorType())
+  return Builder.CreateIntrinsic(
+  /*ReturnType=*/X->getType()->getScalarType(),

farzonl wrote:

the conditional block is `!E->getArg(0)->getType()->isVectorType()` why are  
you  looking up getScalarType? `getType` should be sufficent?

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


[clang] [llvm] Add normalize builtins and normalize HLSL function to DirectX and SPIR-V backend (PR #102683)

2024-08-11 Thread Farzon Lotfi via cfe-commits

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


  1   2   >