[clang] [clang][ExprConst] Add diagnostics for invalid binary arithmetic (PR #118475)

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

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

... between unrelated declarations or literals.

Leaving this small (I haven't run the whole test suite locally) to get some 
feedback on the wording and implementation first.

The output of the sample in https://github.com/llvm/llvm-project/issues/117409 
is now:
```console
./array.cpp:57:6: warning: expression result unused [-Wunused-value]
   57 |   am - aj.af();
  |   ~~ ^ ~~~
./array.cpp:70:8: error: call to consteval function 'L::L' is not a 
constant expression
   70 |   q(0, [] {
  |^
./array.cpp:57:6: note: arithmetic on addresses of literals has unspecified 
value
   57 |   am - aj.af();
  |  ^
./array.cpp:62:5: note: in call to 'al(&""[0], {&""[0]})'
   62 | al(bp.af(), k);
  | ^~
./array.cpp:70:8: note: in call to 'L({})'
   70 |   q(0, [] {
  |^~~~
   71 | struct bx {
  | ~~~
   72 |   constexpr operator ab::e>::e>() { return 
t(""); }
  |   
~~
   73 | };
  | ~~
   74 | return bx();
  | 
   75 |   }());
  |   ~~~
```

The output for 
```c++
int a, b;
constexpr int n = &b - &a
```

is now:
```console
./array.cpp:80:15: error: constexpr variable 'n' must be initialized by a 
constant expression
   80 | constexpr int n = &b - &a;
  |   ^   ~~~
./array.cpp:80:22: note: arithmetic involving '&b' and '&a' has unspecified 
value
   80 | constexpr int n = &b - &a;
  |  ^
1 error generated.

```

>From ce52d3d0c04fc53b814debdcd2c5019f488eddc0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Tue, 3 Dec 2024 11:54:07 +0100
Subject: [PATCH] [clang][ExprConst] Add diagnostics for invalid binary
 arithmetic

... between unrelated declarations or literals.
---
 clang/include/clang/Basic/DiagnosticASTKinds.td |  4 
 clang/lib/AST/ExprConstant.cpp  | 17 +++--
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index f630698757c5fb..4d078fc9ca6bb7 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -91,11 +91,15 @@ def note_constexpr_pointer_subtraction_zero_size : Note<
   "subtraction of pointers to type %0 of zero size">;
 def note_constexpr_pointer_comparison_unspecified : Note<
   "comparison between '%0' and '%1' has unspecified value">;
+def note_constexpr_pointer_arith_unspecified : Note<
+  "arithmetic involving '%0' and '%1' has unspecified value">;
 def note_constexpr_pointer_constant_comparison : Note<
   "comparison of numeric address '%0' with pointer '%1' can only be performed "
   "at runtime">;
 def note_constexpr_literal_comparison : Note<
   "comparison of addresses of literals has unspecified value">;
+def note_constexpr_literal_arith : Note<
+  "arithmetic on addresses of literals has unspecified value">;
 def note_constexpr_opaque_call_comparison : Note<
   "comparison against opaque constant address '%0' can only be performed at "
   "runtime">;
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 6b5b95aee35522..2aefcd870ebaf8 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -14548,8 +14548,21 @@ bool IntExprEvaluator::VisitBinaryOperator(const 
BinaryOperator *E) {
 return Error(E);
   const Expr *LHSExpr = LHSValue.Base.dyn_cast();
   const Expr *RHSExpr = RHSValue.Base.dyn_cast();
-  if (!LHSExpr || !RHSExpr)
-return Error(E);
+  if (!LHSExpr || !RHSExpr) {
+std::string LHS = LHSValue.toString(Info.Ctx, E->getLHS()->getType());
+std::string RHS = RHSValue.toString(Info.Ctx, E->getRHS()->getType());
+Info.FFDiag(E, diag::note_constexpr_pointer_arith_unspecified)
+<< LHS << RHS;
+return false;
+  }
+
+  if (ArePotentiallyOverlappingStringLiterals(Info, LHSValue, RHSValue)) {
+std::string LHS = LHSValue.toString(Info.Ctx, E->getLHS()->getType());
+std::string RHS = RHSValue.toString(Info.Ctx, E->getRHS()->getType());
+Info.FFDiag(E, diag::note_constexpr_literal_arith) << LHS << RHS;
+return false;
+  }
+
   const AddrLabelExpr *LHSAddrExpr = dyn_cast(LHSExpr);
   const AddrLabelExpr *RHSAddrExpr = dyn_cast(RHSExpr);
   if (!LHSAddrExpr || !RHSAddrExpr)

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


[clang] [clang] Fix a use-after-free in expression evaluation (PR #118480)

2024-12-03 Thread kadir çetinkaya via cfe-commits

kadircet wrote:

still trying to come up with a reproducer.

i am also not sure if this is the best place to have the cleanup, but if i did 
that closer to 
[leaves](https://github.com/llvm/llvm-project/blob/main/clang/lib/AST/ExprConstant.cpp#L16376-L16385)
 tests start failing. so open for suggestions here :)

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


[clang] [llvm] [AArch64] Add initial support for FUJITSU-MONAKA (PR #118432)

2024-12-03 Thread Kinoshita Kotaro via cfe-commits

https://github.com/kinoshita-fj updated 
https://github.com/llvm/llvm-project/pull/118432

>From bd4c80f2c16e1380be077b586cd13e4bf39f762b Mon Sep 17 00:00:00 2001
From: Kinoshita Kotaro 
Date: Tue, 3 Dec 2024 05:30:33 +
Subject: [PATCH 1/2] [AArch64]  Add initial support for FUJITSU-MONAKA

This patch adds initial support for FUJITSU-MONAKA CPU (-mcpu=fujitsu-monaka).

The scheduling model will be corrected in the future.
---
 clang/test/Driver/aarch64-fujitsu-monaka.c| 13 +++
 .../aarch64-fujitsu-monaka.c  | 82 +++
 .../Misc/target-invalid-cpu-note/aarch64.c|  1 +
 llvm/lib/Target/AArch64/AArch64Processors.td  | 18 
 llvm/lib/Target/AArch64/AArch64Subtarget.cpp  |  3 +
 llvm/lib/TargetParser/Host.cpp|  5 +-
 llvm/test/CodeGen/AArch64/cpus.ll |  1 +
 llvm/unittests/TargetParser/Host.cpp  |  3 +
 .../TargetParser/TargetParserTest.cpp |  3 +-
 9 files changed, 126 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/Driver/aarch64-fujitsu-monaka.c
 create mode 100644 
clang/test/Driver/print-enabled-extensions/aarch64-fujitsu-monaka.c

diff --git a/clang/test/Driver/aarch64-fujitsu-monaka.c 
b/clang/test/Driver/aarch64-fujitsu-monaka.c
new file mode 100644
index 00..df96b36bace681
--- /dev/null
+++ b/clang/test/Driver/aarch64-fujitsu-monaka.c
@@ -0,0 +1,13 @@
+// RUN: %clang --target=aarch64 -mcpu=fujitsu-monaka -### -c %s 2>&1 | 
FileCheck -check-prefix=fujitsu-monaka %s
+// RUN: %clang --target=aarch64 -mlittle-endian -mcpu=fujitsu-monaka -### -c 
%s 2>&1 | FileCheck -check-prefix=fujitsu-monaka %s
+// RUN: %clang --target=aarch64 -mtune=fujitsu-monaka -### -c %s 2>&1 | 
FileCheck -check-prefix=fujitsu-monaka-TUNE %s
+// RUN: %clang --target=aarch64 -mlittle-endian -mtune=fujitsu-monaka -### -c 
%s 2>&1 | FileCheck -check-prefix=fujitsu-monaka-TUNE %s
+// fujitsu-monaka: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" 
"fujitsu-monaka"
+// fujitsu-monaka-TUNE: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" 
"generic"
+
+// RUN: %clang --target=arm64 -mcpu=fujitsu-monaka -### -c %s 2>&1 | FileCheck 
-check-prefix=ARM64-fujitsu-monaka %s
+// RUN: %clang --target=arm64 -mlittle-endian -mcpu=fujitsu-monaka -### -c %s 
2>&1 | FileCheck -check-prefix=ARM64-fujitsu-monaka %s
+// RUN: %clang --target=arm64 -mtune=fujitsu-monaka -### -c %s 2>&1 | 
FileCheck -check-prefix=ARM64-fujitsu-monaka-TUNE %s
+// RUN: %clang --target=arm64 -mlittle-endian -mtune=fujitsu-monaka -### -c %s 
2>&1 | FileCheck -check-prefix=ARM64-fujitsu-monaka-TUNE %s
+// ARM64-fujitsu-monaka: "-cc1"{{.*}} "-triple" "arm64{{.*}}" "-target-cpu" 
"fujitsu-monaka"
+// ARM64-fujitsu-monaka-TUNE: "-cc1"{{.*}} "-triple" "arm64{{.*}}" 
"-target-cpu" "generic"
diff --git 
a/clang/test/Driver/print-enabled-extensions/aarch64-fujitsu-monaka.c 
b/clang/test/Driver/print-enabled-extensions/aarch64-fujitsu-monaka.c
new file mode 100644
index 00..fce76a49c07d38
--- /dev/null
+++ b/clang/test/Driver/print-enabled-extensions/aarch64-fujitsu-monaka.c
@@ -0,0 +1,82 @@
+// REQUIRES: aarch64-registered-target
+// RUN: %clang --target=aarch64 --print-enabled-extensions 
-mcpu=fujitsu-monaka | FileCheck --strict-whitespace --implicit-check-not=FEAT_ 
%s
+
+// CHECK: Extensions enabled for the given AArch64 target
+// CHECK-EMPTY:
+// CHECK-NEXT: Architecture Feature(s)
Description
+// CHECK-NEXT: FEAT_AES, FEAT_PMULL   
Enable AES support
+// CHECK-NEXT: FEAT_AMUv1 
Enable Armv8.4-A Activity Monitors extension
+// CHECK-NEXT: FEAT_AMUv1p1   
Enable Armv8.6-A Activity Monitors Virtualization support
+// CHECK-NEXT: FEAT_AdvSIMD   
Enable Advanced SIMD instructions
+// CHECK-NEXT: FEAT_BF16  
Enable BFloat16 Extension
+// CHECK-NEXT: FEAT_BTI   
Enable Branch Target Identification
+// CHECK-NEXT: FEAT_CCIDX 
Enable Armv8.3-A Extend of the CCSIDR number of sets
+// CHECK-NEXT: FEAT_CLRBHB
Enable Clear BHB instruction
+// CHECK-NEXT: FEAT_CRC32 
Enable Armv8.0-A CRC-32 checksum instructions
+// CHECK-NEXT: FEAT_CSV2_2
Enable architectural speculation restriction
+// CHECK-NEXT: FEAT_DIT   
Enable Armv8.4-A Data Independent Timing instructions
+// CHECK-NEXT: FEAT_DPB   
Enable Armv8.2-A data Cache Clean to Point of Persistence
+// CHECK-NEXT: FEAT_DPB2  
Enable Armv8.5-A Cache Clean to Point of Deep Persistenc

[clang] 61c2ac0 - Revert "[clang][bytecode] Handle __builtin_wcslen (#118446)"

2024-12-03 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-12-03T13:35:57+01:00
New Revision: 61c2ac03d85f731d75cda23d1918f03d0cb962dc

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

LOG: Revert "[clang][bytecode] Handle __builtin_wcslen (#118446)"

This reverts commit 89a0ee89973c3d213c4bc11c26b41eab67e06da0.

This breaks builders:
https://lab.llvm.org/buildbot/#/builders/13/builds/3885

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index b788656f9484fc..85cffb0c4332df 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -243,7 +243,7 @@ static bool interp__builtin_strlen(InterpState &S, CodePtr 
OpPC,
   unsigned ID = Func->getBuiltinID();
   const Pointer &StrPtr = getParam(Frame, 0);
 
-  if (ID == Builtin::BIstrlen || ID == Builtin::BIwcslen)
+  if (ID == Builtin::BIstrlen)
 diagnoseNonConstexprBuiltin(S, OpPC, ID);
 
   if (!CheckArray(S, OpPC, StrPtr))
@@ -1859,8 +1859,6 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const 
Function *F,
 break;
   case Builtin::BI__builtin_strlen:
   case Builtin::BIstrlen:
-  case Builtin::BI__builtin_wcslen:
-  case Builtin::BIwcslen:
 if (!interp__builtin_strlen(S, OpPC, Frame, F, Call))
   return false;
 break;

diff  --git a/clang/test/AST/ByteCode/builtin-functions.cpp 
b/clang/test/AST/ByteCode/builtin-functions.cpp
index b951c04dde5980..f70b77fe74636b 100644
--- a/clang/test/AST/ByteCode/builtin-functions.cpp
+++ b/clang/test/AST/ByteCode/builtin-functions.cpp
@@ -15,10 +15,6 @@
 #error "huh?"
 #endif
 
-extern "C" {
-  typedef decltype(sizeof(int)) size_t;
-  extern size_t wcslen(const wchar_t *p);
-}
 
 namespace strcmp {
   constexpr char kFoobar[6] = {'f','o','o','b','a','r'};
@@ -97,14 +93,6 @@ constexpr const char *a = "foo\0quux";
   constexpr char d[] = { 'f', 'o', 'o' }; // no nul terminator.
   constexpr int bad = __builtin_strlen(d); // both-error {{constant 
expression}} \
// both-note {{one-past-the-end}}
-
-  constexpr int wn = __builtin_wcslen(L"hello");
-  static_assert(wn == 5);
-  constexpr int wm = wcslen(L"hello"); // both-error {{constant expression}} \
-   // both-note {{non-constexpr function 
'wcslen' cannot be used in a constant expression}}
-
-  int arr[3]; // both-note {{here}}
-  int wk = arr[wcslen(L"hello")]; // both-warning {{array index 5}}
 }
 
 namespace nan {



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


[clang] [clang][bytecode] Fix `__extension__` handling for vector operators (PR #118482)

2024-12-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

Don't reject them, but delegate to the subexpression.

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


2 Files Affected:

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


``diff
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index a95353fd2943c9..f6e0b54a81e368 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -5911,6 +5911,9 @@ bool Compiler::VisitVectorUnaryOperator(const 
UnaryOperator *E) {
 return this->discard(SubExpr);
 
   auto UnaryOp = E->getOpcode();
+  if (UnaryOp == UO_Extension)
+return this->delegate(SubExpr);
+
   if (UnaryOp != UO_Plus && UnaryOp != UO_Minus && UnaryOp != UO_LNot &&
   UnaryOp != UO_Not && UnaryOp != UO_AddrOf)
 return this->emitInvalid(E);
diff --git a/clang/test/AST/ByteCode/vectors.cpp 
b/clang/test/AST/ByteCode/vectors.cpp
index 08e2ca2adbf5cd..a04b678a623a1e 100644
--- a/clang/test/AST/ByteCode/vectors.cpp
+++ b/clang/test/AST/ByteCode/vectors.cpp
@@ -37,6 +37,7 @@ static_assert(arr4[1][0] == 0, "");
 static_assert(arr4[1][0] == 0, "");
 static_assert(arr4[1][0] == 0, "");
 
+constexpr VI4 B = __extension__(A);
 
 /// From constant-expression-cxx11.cpp
 namespace Vector {

``




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


[clang] [clang][bytecode] Fix `__extension__` handling for vector operators (PR #118482)

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

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

Don't reject them, but delegate to the subexpression.

>From 7576bf72f204904c65add97cdd867c41e5a3fa48 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Tue, 3 Dec 2024 13:44:14 +0100
Subject: [PATCH] [clang][bytecode] Fix `__extension__` handling for vector
 operators

Don't reject them, but delegate to the subexpression.
---
 clang/lib/AST/ByteCode/Compiler.cpp | 3 +++
 clang/test/AST/ByteCode/vectors.cpp | 1 +
 2 files changed, 4 insertions(+)

diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index a95353fd2943c9..f6e0b54a81e368 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -5911,6 +5911,9 @@ bool Compiler::VisitVectorUnaryOperator(const 
UnaryOperator *E) {
 return this->discard(SubExpr);
 
   auto UnaryOp = E->getOpcode();
+  if (UnaryOp == UO_Extension)
+return this->delegate(SubExpr);
+
   if (UnaryOp != UO_Plus && UnaryOp != UO_Minus && UnaryOp != UO_LNot &&
   UnaryOp != UO_Not && UnaryOp != UO_AddrOf)
 return this->emitInvalid(E);
diff --git a/clang/test/AST/ByteCode/vectors.cpp 
b/clang/test/AST/ByteCode/vectors.cpp
index 08e2ca2adbf5cd..a04b678a623a1e 100644
--- a/clang/test/AST/ByteCode/vectors.cpp
+++ b/clang/test/AST/ByteCode/vectors.cpp
@@ -37,6 +37,7 @@ static_assert(arr4[1][0] == 0, "");
 static_assert(arr4[1][0] == 0, "");
 static_assert(arr4[1][0] == 0, "");
 
+constexpr VI4 B = __extension__(A);
 
 /// From constant-expression-cxx11.cpp
 namespace Vector {

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


[clang-tools-extra] [clangd] Support symbolTags for document symbol (PR #113669)

2024-12-03 Thread Dietrich Travkin via cfe-commits

travkin79 wrote:

Hi @chouzz,
I extended my prototype to create overlay icons for all Symbol Tags. I'm using 
another C++ code example for testing clangd's tags and my visualization. The 
results are promising, but I have a few questions.

* Could you please check if you can also set `Final` tags? It seems, clangd 
doesn't set these yet (see example).
* Is it correct that `virtual ~AbstractClass() = default;` is tagged as 
definition and not as declaration?

**Example: demo.cpp**
```cpp
class AbstractClass // abstract
{
public:

  virtual ~AbstractClass() = default; // public, virtual, declaration

  virtual void f1() = 0; // public, (pure) virtual, declaration

  void f2() const; // public, const, declaration

protected:

  void f3() // protected, (declaration+)definition
  {
  }

private:

  static void f4() // private, static, (declaration+)definition
  {
  }
};

void AbstractClass::f2() const // public, const, definition
{
}

class ImplClass : public AbstractClass
{
public:

  void f1() final // public, override, final, (declaration+)definition
  {
  }
};
```

**Outline prototype:**
![image](https://github.com/user-attachments/assets/94a43fb8-ce52-40d1-b97f-cbb32d28a855)

**LS output:**
```json
{
  "id": "7",
  "jsonrpc": "2.0",
  "result": [
{
  "children": [
{
  "kind": 9,
  "name": "~AbstractClass",
  "range": {
"end": {
  "character": 36,
  "line": 4
},
"start": {
  "character": 2,
  "line": 4
}
  },
  "selectionRange": {
"end": {
  "character": 11,
  "line": 4
},
"start": {
  "character": 10,
  "line": 4
}
  },
  "tags": [
15,
19,
5
  ]
},
{
  "detail": "void ()",
  "kind": 6,
  "name": "f1",
  "range": {
"end": {
  "character": 23,
  "line": 6
},
"start": {
  "character": 2,
  "line": 6
}
  },
  "selectionRange": {
"end": {
  "character": 17,
  "line": 6
},
"start": {
  "character": 15,
  "line": 6
}
  },
  "tags": [
15,
9,
18,
5
  ]
},
{
  "detail": "void () const",
  "kind": 6,
  "name": "f2",
  "range": {
"end": {
  "character": 17,
  "line": 8
},
"start": {
  "character": 2,
  "line": 8
}
  },
  "selectionRange": {
"end": {
  "character": 9,
  "line": 8
},
"start": {
  "character": 7,
  "line": 8
}
  },
  "tags": [
20,
18,
5
  ]
},
{
  "detail": "void ()",
  "kind": 6,
  "name": "f3",
  "range": {
"end": {
  "character": 3,
  "line": 14
},
"start": {
  "character": 2,
  "line": 12
}
  },
  "selectionRange": {
"end": {
  "character": 9,
  "line": 12
},
"start": {
  "character": 7,
  "line": 12
}
  },
  "tags": [
19,
4
  ]
},
{
  "detail": "void ()",
  "kind": 6,
  "name": "f4",
  "range": {
"end": {
  "character": 3,
  "line": 20
},
"start": {
  "character": 2,
  "line": 18
}
  },
  "selectionRange": {
"end": {
  "character": 16,
  "line": 18
},
"start": {
  "character": 14,
  "line": 18
}
  },
  "tags": [
8,
19,
2
  ]
}
  ],
  "detail": "class",
  "kind": 5,
  "name": "AbstractClass",
  "range": {
"end": {
  "character": 1,
  "line": 21
},
"start": {
  "character": 0,
  "line": 0
}
  },
  "selectionRange": {
"end": {
  "character": 19,
  "line": 0
},
"start": {
  "character": 6,
  "line": 0
}
  },
  "tags": [
9,
19
  ]
},
{
  "detail": "void () const",
  "kind": 6,
  "name": "AbstractClass::f2",
  "range": {
"end": {
  "ch

[clang] [flang] [flang] Treat pre-processed input as fixed (PR #117563)

2024-12-03 Thread David Truby via cfe-commits

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

LGTM, thanks for being patient with our requests for changes!

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


[clang] [Clang] Enable -fpointer-tbaa by default. (PR #117244)

2024-12-03 Thread Florian Hahn via cfe-commits

fhahn wrote:

ping :) @AaronBallman WDYT re making this clear in the release notes (also that 
there's an easy way to disable) + the ongoing work in parallel for the type 
sanitizer?

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


[clang] [clang] Fix a use-after-free in expression evaluation (PR #118480)

2024-12-03 Thread Ilya Biryukov via cfe-commits


@@ -4515,6 +4515,8 @@ handleLValueToRValueConversion(EvalInfo &Info, const Expr 
*Conv, QualType Type,
   }
 
   APValue Lit;
+  // Make sure we clean up the temporary created below.
+  FullExpressionRAII CleanupTemps(Info);

ilya-biryukov wrote:

Could we get a reduced test case?

I don't think it's correct to do the cleanups here, we could probably construct 
some examples that break after this change.

There are `ExprWithCleanups` and various other mechanisms that ensure we do all 
the cleanups correctly. This delayed evaluation of compound literals might not 
play well with those cases today, but it's hard to know for sure without 
understanding the full picture. Having an example would help better understand 
if there's a fix needed in a different place.

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


[clang] Pack relocations for Android API >= 28 (PR #117624)

2024-12-03 Thread via cfe-commits

https://github.com/enh-google approved this pull request.


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


[clang] ff0babc - [clang][bytecode] Fix discarded pointer subtractions (#118477)

2024-12-03 Thread via cfe-commits

Author: Timm Baeder
Date: 2024-12-03T14:34:32+01:00
New Revision: ff0babc9172b42a3e9f552d6959f9d98ae450633

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

LOG: [clang][bytecode] Fix discarded pointer subtractions (#118477)

We need to pop the value.

Added: 


Modified: 
clang/lib/AST/ByteCode/Compiler.cpp
clang/test/AST/ByteCode/literals.cpp

Removed: 




diff  --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index a95353fd2943c9..705ab1ec8e8ab6 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -1000,7 +1000,10 @@ bool Compiler::VisitPointerArithBinOp(const 
BinaryOperator *E) {
 if (!visitAsPointer(RHS, *RT) || !visitAsPointer(LHS, *LT))
   return false;
 
-return this->emitSubPtr(classifyPrim(E->getType()), E);
+PrimType IntT = classifyPrim(E->getType());
+if (!this->emitSubPtr(IntT, E))
+  return false;
+return DiscardResult ? this->emitPop(IntT, E) : true;
   }
 
   PrimType OffsetType;

diff  --git a/clang/test/AST/ByteCode/literals.cpp 
b/clang/test/AST/ByteCode/literals.cpp
index 13d6c4feb35002..662823c49cd4a0 100644
--- a/clang/test/AST/ByteCode/literals.cpp
+++ b/clang/test/AST/ByteCode/literals.cpp
@@ -980,6 +980,8 @@ namespace DiscardExprs {
 __uuidof(number); // both-error {{cannot call operator __uuidof on a type 
with no GUID}}
 
 requires{false;};
+constexpr int *p = nullptr;
+p - p;
 
 return 0;
   }



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


[clang] [clang][ExprConst] Add diagnostics for invalid binary arithmetic (PR #118475)

2024-12-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

... between unrelated declarations or literals.

Leaving this small (I haven't run the whole test suite locally) to get some 
feedback on the wording and implementation first.

The output of the sample in https://github.com/llvm/llvm-project/issues/117409 
is now:
```console
./array.cpp:57:6: warning: expression result unused [-Wunused-value]
   57 |   am - aj.af();
  |   ~~ ^ ~~~
./array.cpp:70:8: error: call to consteval function 'L::L' is not a 
constant expression
   70 |   q(0, [] {
  |^
./array.cpp:57:6: note: arithmetic on addresses of literals has unspecified 
value
   57 |   am - aj.af();
  |  ^
./array.cpp:62:5: note: in call to 'al(&""[0], {&""[0]})'
   62 | al(bp.af(), k);
  | ^~
./array.cpp:70:8: note: in call to 'L({})'
   70 |   q(0, [] {
  |^~~~
   71 | struct bx {
  | ~~~
   72 |   constexpr operator 
ab::e>::e>() { return t(""); }
  |   
~~
   73 | };
  | ~~
   74 | return bx();
  | 
   75 |   }());
  |   ~~~
```

The output for 
```c++
int a, b;
constexpr int n = &b - &a
```

is now:
```console
./array.cpp:80:15: error: constexpr variable 'n' must be initialized by a 
constant expression
   80 | constexpr int n = &b - &a;
  |   ^   ~~~
./array.cpp:80:22: note: arithmetic involving '&b' and '&a' has 
unspecified value
   80 | constexpr int n = &b - &a;
  |  ^
1 error generated.

```

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


2 Files Affected:

- (modified) clang/include/clang/Basic/DiagnosticASTKinds.td (+4) 
- (modified) clang/lib/AST/ExprConstant.cpp (+15-2) 


``diff
diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index f630698757c5fb..4d078fc9ca6bb7 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -91,11 +91,15 @@ def note_constexpr_pointer_subtraction_zero_size : Note<
   "subtraction of pointers to type %0 of zero size">;
 def note_constexpr_pointer_comparison_unspecified : Note<
   "comparison between '%0' and '%1' has unspecified value">;
+def note_constexpr_pointer_arith_unspecified : Note<
+  "arithmetic involving '%0' and '%1' has unspecified value">;
 def note_constexpr_pointer_constant_comparison : Note<
   "comparison of numeric address '%0' with pointer '%1' can only be performed "
   "at runtime">;
 def note_constexpr_literal_comparison : Note<
   "comparison of addresses of literals has unspecified value">;
+def note_constexpr_literal_arith : Note<
+  "arithmetic on addresses of literals has unspecified value">;
 def note_constexpr_opaque_call_comparison : Note<
   "comparison against opaque constant address '%0' can only be performed at "
   "runtime">;
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 6b5b95aee35522..2aefcd870ebaf8 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -14548,8 +14548,21 @@ bool IntExprEvaluator::VisitBinaryOperator(const 
BinaryOperator *E) {
 return Error(E);
   const Expr *LHSExpr = LHSValue.Base.dyn_cast();
   const Expr *RHSExpr = RHSValue.Base.dyn_cast();
-  if (!LHSExpr || !RHSExpr)
-return Error(E);
+  if (!LHSExpr || !RHSExpr) {
+std::string LHS = LHSValue.toString(Info.Ctx, E->getLHS()->getType());
+std::string RHS = RHSValue.toString(Info.Ctx, E->getRHS()->getType());
+Info.FFDiag(E, diag::note_constexpr_pointer_arith_unspecified)
+<< LHS << RHS;
+return false;
+  }
+
+  if (ArePotentiallyOverlappingStringLiterals(Info, LHSValue, RHSValue)) {
+std::string LHS = LHSValue.toString(Info.Ctx, E->getLHS()->getType());
+std::string RHS = RHSValue.toString(Info.Ctx, E->getRHS()->getType());
+Info.FFDiag(E, diag::note_constexpr_literal_arith) << LHS << RHS;
+return false;
+  }
+
   const AddrLabelExpr *LHSAddrExpr = dyn_cast(LHSExpr);
   const AddrLabelExpr *RHSAddrExpr = dyn_cast(RHSExpr);
   if (!LHSAddrExpr || !RHSAddrExpr)

``




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


[clang] [llvm] [OpenMP]Initial parsing/sema support for target_device selector set (PR #118471)

2024-12-03 Thread via cfe-commits

https://github.com/Ritanya-B-Bharadwaj updated 
https://github.com/llvm/llvm-project/pull/118471

>From 9aa3ba3d602fd81a4064939c9bb176bb020c98e8 Mon Sep 17 00:00:00 2001
From: Ritanya B Bharadwaj 
Date: Tue, 3 Dec 2024 03:58:40 -0600
Subject: [PATCH] Initial parsing/sema support for target_device selector set

---
 clang/include/clang/Sema/SemaOpenMP.h |   3 +
 clang/lib/AST/OpenMPClause.cpp|   5 +-
 clang/lib/Parse/ParseOpenMP.cpp   |  27 ++-
 clang/lib/Sema/SemaOpenMP.cpp |  28 +++
 .../OpenMP/begin_declare_variant_messages.c   |  22 +-
 clang/test/OpenMP/declare_variant_ast_print.c |   4 +
 .../OpenMP/declare_variant_bind_to_decl.cpp   |   2 +-
 clang/test/OpenMP/declare_variant_messages.c  |  57 +++---
 .../test/OpenMP/declare_variant_messages.cpp  |  28 +--
 clang/test/OpenMP/metadirective_messages.cpp  |   2 +-
 .../nvptx_declare_variant_name_mangling.cpp   |   8 +-
 .../include/llvm/Frontend/OpenMP/OMPContext.h |   9 +-
 .../include/llvm/Frontend/OpenMP/OMPKinds.def |  36 
 llvm/lib/Frontend/OpenMP/OMPContext.cpp   | 192 +-
 llvm/unittests/Frontend/OpenMPContextTest.cpp |  26 ++-
 15 files changed, 319 insertions(+), 130 deletions(-)

diff --git a/clang/include/clang/Sema/SemaOpenMP.h 
b/clang/include/clang/Sema/SemaOpenMP.h
index 3d1cc4fab1c10f..4b9c930db26b5d 100644
--- a/clang/include/clang/Sema/SemaOpenMP.h
+++ b/clang/include/clang/Sema/SemaOpenMP.h
@@ -849,6 +849,9 @@ class SemaOpenMP : public SemaBase {
   ArrayRef AppendArgs, SourceLocation AdjustArgsLoc,
   SourceLocation AppendArgsLoc, SourceRange SR);
 
+  /// Handle device_num selector.
+  void ActOnOpenMPDeviceNum(Expr *DeviceNumExpr);
+
   OMPClause *ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr,
  SourceLocation StartLoc,
  SourceLocation LParenLoc,
diff --git a/clang/lib/AST/OpenMPClause.cpp b/clang/lib/AST/OpenMPClause.cpp
index 4246ba95d827f1..870c4224c323bd 100644
--- a/clang/lib/AST/OpenMPClause.cpp
+++ b/clang/lib/AST/OpenMPClause.cpp
@@ -2903,7 +2903,10 @@ TargetOMPContext::TargetOMPContext(
 const FunctionDecl *CurrentFunctionDecl,
 ArrayRef ConstructTraits)
 : OMPContext(ASTCtx.getLangOpts().OpenMPIsTargetDevice,
- ASTCtx.getTargetInfo().getTriple()),
+ ASTCtx.getTargetInfo().getTriple(),
+ ASTCtx.getLangOpts().OMPTargetTriples.empty()
+ ? llvm::Triple()
+ : ASTCtx.getLangOpts().OMPTargetTriples[0]),
   FeatureValidityCheck([&](StringRef FeatureName) {
 return ASTCtx.getTargetInfo().isValidFeatureName(FeatureName);
   }),
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index b91928063169ee..84f1fcdb6e83f2 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -888,7 +888,18 @@ void Parser::parseOMPTraitPropertyKind(OMPTraitProperty 
&TIProperty,
   TIProperty.Kind = TraitProperty::invalid;
 
   SourceLocation NameLoc = Tok.getLocation();
-  StringRef Name = getNameFromIdOrString(*this, Tok, CONTEXT_TRAIT_LVL);
+  StringRef Name;
+  if (Selector == llvm::omp::TraitSelector::target_device_device_num) {
+Name = "number";
+TIProperty.Kind = getOpenMPContextTraitPropertyKind(Set, Selector, Name);
+ExprResult DeviceNumExprResult = ParseExpression();
+if (!DeviceNumExprResult.isInvalid()) {
+  Expr *DeviceNumExpr = DeviceNumExprResult.get();
+  Actions.OpenMP().ActOnOpenMPDeviceNum(DeviceNumExpr);
+}
+return;
+  }
+  Name = getNameFromIdOrString(*this, Tok, CONTEXT_TRAIT_LVL);
   if (Name.empty()) {
 Diag(Tok.getLocation(), diag::note_omp_declare_variant_ctx_options)
 << CONTEXT_TRAIT_LVL << listOpenMPContextTraitProperties(Set, 
Selector);
@@ -918,7 +929,8 @@ void Parser::parseOMPTraitPropertyKind(OMPTraitProperty 
&TIProperty,
 << "()";
 return;
   }
-  TraitSelector SelectorForName = getOpenMPContextTraitSelectorKind(Name);
+  TraitSelector SelectorForName =
+  getOpenMPContextTraitSelectorKind(Name, SetForName);
   if (SelectorForName != TraitSelector::invalid) {
 Diag(NameLoc, diag::note_omp_declare_variant_ctx_is_a)
 << Name << CONTEXT_SELECTOR_LVL << CONTEXT_TRAIT_LVL;
@@ -935,7 +947,7 @@ void Parser::parseOMPTraitPropertyKind(OMPTraitProperty 
&TIProperty,
   }
   for (const auto &PotentialSet :
{TraitSet::construct, TraitSet::user, TraitSet::implementation,
-TraitSet::device}) {
+TraitSet::device, TraitSet::target_device}) {
 TraitProperty PropertyForName =
 getOpenMPContextTraitPropertyKind(PotentialSet, Selector, Name);
 if (PropertyForName == TraitProperty::invalid)
@@ -1062,7 +1074,7 @@ void Parser::parseOMPTraitSelectorKind(OMPTraitSelector 
&TISelector,
 return;
   }
 
-  TISelector.Kind = getOpenMPContextTraitSelectorKind(Name);
+  TISelector.Kind = g

[clang] [analyzer][Z3] Restore the original timeout of 15s (PR #118291)

2024-12-03 Thread Kristóf Umann via cfe-commits

Szelethus wrote:

> I also have some just-in-case measurements cooking to confirm that we don't 
> observe any nondeterminism with these values. Previous measurements of mine 
> were made with _all_ configs set to 0. Our downstream release goes off with 
> the patch totally reverted.

Sanity check returned normal, no difference in between the report sets.
https://codechecker-demo.eastus.cloudapp.azure.com/Default/reports?run=qtbase_v6.2.0_determinism_check15A_1&run=libwebm_libwebm-1.0.0.27_determinism_check15A_1&run=vim_v8.2.1920_determinism_check15A_1&newcheck=qtbase_v6.2.0_determinism_check15B_1&newcheck=libwebm_libwebm-1.0.0.27_determinism_check15B_1&newcheck=vim_v8.2.1920_determinism_check15B_1

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


[clang] [clang][bytecode] Fix discarded pointer subtractions (PR #118477)

2024-12-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

We need to pop the value.

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


2 Files Affected:

- (modified) clang/lib/AST/ByteCode/Compiler.cpp (+4-1) 
- (modified) clang/test/AST/ByteCode/literals.cpp (+2) 


``diff
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index a95353fd2943c9..705ab1ec8e8ab6 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -1000,7 +1000,10 @@ bool Compiler::VisitPointerArithBinOp(const 
BinaryOperator *E) {
 if (!visitAsPointer(RHS, *RT) || !visitAsPointer(LHS, *LT))
   return false;
 
-return this->emitSubPtr(classifyPrim(E->getType()), E);
+PrimType IntT = classifyPrim(E->getType());
+if (!this->emitSubPtr(IntT, E))
+  return false;
+return DiscardResult ? this->emitPop(IntT, E) : true;
   }
 
   PrimType OffsetType;
diff --git a/clang/test/AST/ByteCode/literals.cpp 
b/clang/test/AST/ByteCode/literals.cpp
index 13d6c4feb35002..662823c49cd4a0 100644
--- a/clang/test/AST/ByteCode/literals.cpp
+++ b/clang/test/AST/ByteCode/literals.cpp
@@ -980,6 +980,8 @@ namespace DiscardExprs {
 __uuidof(number); // both-error {{cannot call operator __uuidof on a type 
with no GUID}}
 
 requires{false;};
+constexpr int *p = nullptr;
+p - p;
 
 return 0;
   }

``




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


[clang] [clang][bytecode] Fix discarded pointer subtractions (PR #118477)

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

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

We need to pop the value.

>From 409fa110d7eeb4a91f62b64d59aecb30db700ebd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Tue, 3 Dec 2024 13:00:29 +0100
Subject: [PATCH] [clang][bytecode] Fix discarded pointer subtractions

We need to pop the value.
---
 clang/lib/AST/ByteCode/Compiler.cpp  | 5 -
 clang/test/AST/ByteCode/literals.cpp | 2 ++
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index a95353fd2943c9..705ab1ec8e8ab6 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -1000,7 +1000,10 @@ bool Compiler::VisitPointerArithBinOp(const 
BinaryOperator *E) {
 if (!visitAsPointer(RHS, *RT) || !visitAsPointer(LHS, *LT))
   return false;
 
-return this->emitSubPtr(classifyPrim(E->getType()), E);
+PrimType IntT = classifyPrim(E->getType());
+if (!this->emitSubPtr(IntT, E))
+  return false;
+return DiscardResult ? this->emitPop(IntT, E) : true;
   }
 
   PrimType OffsetType;
diff --git a/clang/test/AST/ByteCode/literals.cpp 
b/clang/test/AST/ByteCode/literals.cpp
index 13d6c4feb35002..662823c49cd4a0 100644
--- a/clang/test/AST/ByteCode/literals.cpp
+++ b/clang/test/AST/ByteCode/literals.cpp
@@ -980,6 +980,8 @@ namespace DiscardExprs {
 __uuidof(number); // both-error {{cannot call operator __uuidof on a type 
with no GUID}}
 
 requires{false;};
+constexpr int *p = nullptr;
+p - p;
 
 return 0;
   }

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


[clang] [clang] Fix a use-after-free in expression evaluation (PR #118480)

2024-12-03 Thread kadir çetinkaya via cfe-commits

https://github.com/kadircet created 
https://github.com/llvm/llvm-project/pull/118480

following ASAN failure is fixed with this patch.
We store cleanups in EvalInfo, which are usually run with certain
ScopeRAII objects.
We can have temporaries in the cleanup stack, backed by CallStackFrame.
If such temporaries aren't destroyed before the enclosing
CallStackFrame, we end up accessing the freed temporary to run the
cleanup.

```
=
==553356==ERROR: AddressSanitizer: heap-use-after-free on address 
0x7c63f05a65b0 at pc 0x561e4add6ae7 bp 0x7fff430f7770 sp 0x7fff430f7768
READ of size 4 at 0x7c63f05a65b0 thread T0
#0 0x561e4add6ae6 in clang::APValue::operator=(clang::APValue&&) 
third_party/llvm/llvm-project/clang/lib/AST/APValue.cpp:394:9
#1 0x561e4b41fd0b in (anonymous namespace)::Cleanup::endLifetime((anonymous 
namespace)::EvalInfo&, bool) 
third_party/llvm/llvm-project/clang/lib/AST/ExprConstant.cpp:749:27
#2 0x561e4b4d42a7 in (anonymous namespace)::ScopeRAII<((anonymous 
namespace)::ScopeKind)1>::cleanup((anonymous namespace)::EvalInfo&, bool, 
unsigned int) 
third_party/llvm/llvm-project/clang/lib/AST/ExprConstant.cpp:1449:41
#3 0x561e4b4246ec in destroy 
third_party/llvm/llvm-project/clang/lib/AST/ExprConstant.cpp:1427:17
#4 0x561e4b4246ec in ~ScopeRAII 
third_party/llvm/llvm-project/clang/lib/AST/ExprConstant.cpp:1433:9
#5 0x561e4b4246ec in EvaluateCond((anonymous namespace)::EvalInfo&, 
clang::VarDecl const*, clang::Expr const*, bool&) 
third_party/llvm/llvm-project/clang/lib/AST/ExprConstant.cpp:5185:1
#6 0x561e4b41ea8c in EvaluateStmt((anonymous namespace)::StmtResult&, 
(anonymous namespace)::EvalInfo&, clang::Stmt const*, clang::SwitchCase const*) 
third_party/llvm/llvm-project/clang/lib/AST/ExprConstant.cpp::17
#7 0x561e4b423755 in EvaluateLoopBody((anonymous namespace)::StmtResult&, 
(anonymous namespace)::EvalInfo&, clang::Stmt const*, clang::SwitchCase const*) 
third_party/llvm/llvm-project/clang/lib/AST/ExprConstant.cpp:5221:24
#8 0x561e4b41d597 in EvaluateStmt((anonymous namespace)::StmtResult&, 
(anonymous namespace)::EvalInfo&, clang::Stmt const*, clang::SwitchCase const*) 
third_party/llvm/llvm-project/clang/lib/AST/ExprConstant.cpp:5635:28
#9 0x561e4b41d341 in EvaluateStmt((anonymous namespace)::StmtResult&, 
(anonymous namespace)::EvalInfo&, clang::Stmt const*, clang::SwitchCase const*) 
third_party/llvm/llvm-project/clang/lib/AST/ExprConstant.cpp:5521:28
#10 0x561e4b40113c in HandleFunctionCall(clang::SourceLocation, 
clang::FunctionDecl const*, (anonymous namespace)::LValue const*, clang::Expr 
const*, llvm::ArrayRef, (anonymous namespace)::CallRef, 
clang::Stmt const*, (anonymous namespace)::EvalInfo&, clang::APValue&, 
(anonymous namespace)::LValue const*) 
third_party/llvm/llvm-project/clang/lib/AST/ExprConstant.cpp:6520:24
#11 0x561e4b4c9652 in handleCallExpr 
third_party/llvm/llvm-project/clang/lib/AST/ExprConstant.cpp:8332:10
#12 0x561e4b4c9652 in VisitCallExpr 
third_party/llvm/llvm-project/clang/lib/AST/ExprConstant.cpp:8132:10
#13 0x561e4b4c9652 in visitNonBuiltinCallExpr 
third_party/llvm/llvm-project/clang/lib/AST/ExprConstant.cpp:9749:28
#14 0x561e4b4c9652 in (anonymous 
namespace)::PointerExprEvaluator::VisitCallExpr(clang::CallExpr const*) 
third_party/llvm/llvm-project/clang/lib/AST/ExprConstant.cpp:9763:12
#15 0x561e4b4c3e5b in clang::StmtVisitorBase::Visit(clang::Stmt const*) 
blaze-out/k8-opt-asan/genfiles/third_party/llvm/llvm-project/clang/include/clang/AST/StmtNodes.inc
#16 0x561e4b3ff820 in EvaluatePointer 
third_party/llvm/llvm-project/clang/lib/AST/ExprConstant.cpp:9458:60
#17 0x561e4b3ff820 in Evaluate(clang::APValue&, (anonymous 
namespace)::EvalInfo&, clang::Expr const*) 
third_party/llvm/llvm-project/clang/lib/AST/ExprConstant.cpp:16343:10
#18 0x561e4b41f204 in EvaluateStmt((anonymous namespace)::StmtResult&, 
(anonymous namespace)::EvalInfo&, clang::Stmt const*, clang::SwitchCase const*) 
third_party/llvm/llvm-project/clang/lib/AST/ExprConstant.cpp:5511:17
#19 0x561e4b41d341 in EvaluateStmt((anonymous namespace)::StmtResult&, 
(anonymous namespace)::EvalInfo&, clang::Stmt const*, clang::SwitchCase const*) 
third_party/llvm/llvm-project/clang/lib/AST/ExprConstant.cpp:5521:28
#20 0x561e4b40113c in HandleFunctionCall(clang::SourceLocation, 
clang::FunctionDecl const*, (anonymous namespace)::LValue const*, clang::Expr 
const*, llvm::ArrayRef, (anonymous namespace)::CallRef, 
clang::Stmt const*, (anonymous namespace)::EvalInfo&, clang::APValue&, 
(anonymous namespace)::LValue const*) 
third_party/llvm/llvm-project/clang/lib/AST/ExprConstant.cpp:6520:24
#21 0x561e4b4c9652 in handleCallExpr 
third_party/llvm/llvm-project/clang/lib/AST/ExprConstant.cpp:8332:10
#22 0x561e4b4c9652 in VisitCallExpr 
third_party/llvm/llvm-project/clang/lib/AST/ExprConstant.cpp:8132:10
#23 0x561e4b4c9652 in visitNonBuiltinCa

[clang] [clang] Fix a use-after-free in expression evaluation (PR #118480)

2024-12-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: kadir çetinkaya (kadircet)


Changes

following ASAN failure is fixed with this patch.
We store cleanups in EvalInfo, which are usually run with certain
ScopeRAII objects.
We can have temporaries in the cleanup stack, backed by CallStackFrame.
If such temporaries aren't destroyed before the enclosing
CallStackFrame, we end up accessing the freed temporary to run the
cleanup.

```
=
==553356==ERROR: AddressSanitizer: heap-use-after-free on address 
0x7c63f05a65b0 at pc 0x561e4add6ae7 bp 0x7fff430f7770 sp 0x7fff430f7768
READ of size 4 at 0x7c63f05a65b0 thread T0
#0 0x561e4add6ae6 in 
clang::APValue::operator=(clang::APValue&&) 
third_party/llvm/llvm-project/clang/lib/AST/APValue.cpp:394:9
#1 0x561e4b41fd0b in (anonymous 
namespace)::Cleanup::endLifetime((anonymous namespace)::EvalInfo&, bool) 
third_party/llvm/llvm-project/clang/lib/AST/ExprConstant.cpp:749:27
#2 0x561e4b4d42a7 in (anonymous 
namespace)::ScopeRAII<((anonymous 
namespace)::ScopeKind)1>::cleanup((anonymous namespace)::EvalInfo&, 
bool, unsigned int) 
third_party/llvm/llvm-project/clang/lib/AST/ExprConstant.cpp:1449:41
#3 0x561e4b4246ec in destroy 
third_party/llvm/llvm-project/clang/lib/AST/ExprConstant.cpp:1427:17
#4 0x561e4b4246ec in ~ScopeRAII 
third_party/llvm/llvm-project/clang/lib/AST/ExprConstant.cpp:1433:9
#5 0x561e4b4246ec in EvaluateCond((anonymous 
namespace)::EvalInfo&, clang::VarDecl const*, clang::Expr const*, 
bool&) third_party/llvm/llvm-project/clang/lib/AST/ExprConstant.cpp:5185:1
#6 0x561e4b41ea8c in EvaluateStmt((anonymous 
namespace)::StmtResult&, (anonymous namespace)::EvalInfo&, clang::Stmt 
const*, clang::SwitchCase const*) 
third_party/llvm/llvm-project/clang/lib/AST/ExprConstant.cpp::17
#7 0x561e4b423755 in EvaluateLoopBody((anonymous 
namespace)::StmtResult&, (anonymous namespace)::EvalInfo&, clang::Stmt 
const*, clang::SwitchCase const*) 
third_party/llvm/llvm-project/clang/lib/AST/ExprConstant.cpp:5221:24
#8 0x561e4b41d597 in EvaluateStmt((anonymous 
namespace)::StmtResult&, (anonymous namespace)::EvalInfo&, clang::Stmt 
const*, clang::SwitchCase const*) 
third_party/llvm/llvm-project/clang/lib/AST/ExprConstant.cpp:5635:28
#9 0x561e4b41d341 in EvaluateStmt((anonymous 
namespace)::StmtResult&, (anonymous namespace)::EvalInfo&, clang::Stmt 
const*, clang::SwitchCase const*) 
third_party/llvm/llvm-project/clang/lib/AST/ExprConstant.cpp:5521:28
#10 0x561e4b40113c in HandleFunctionCall(clang::SourceLocation, 
clang::FunctionDecl const*, (anonymous namespace)::LValue const*, clang::Expr 
const*, llvm::ArrayRef, (anonymous 
namespace)::CallRef, clang::Stmt const*, (anonymous namespace)::EvalInfo&, 
clang::APValue&, (anonymous namespace)::LValue const*) 
third_party/llvm/llvm-project/clang/lib/AST/ExprConstant.cpp:6520:24
#11 0x561e4b4c9652 in handleCallExpr 
third_party/llvm/llvm-project/clang/lib/AST/ExprConstant.cpp:8332:10
#12 0x561e4b4c9652 in VisitCallExpr 
third_party/llvm/llvm-project/clang/lib/AST/ExprConstant.cpp:8132:10
#13 0x561e4b4c9652 in visitNonBuiltinCallExpr 
third_party/llvm/llvm-project/clang/lib/AST/ExprConstant.cpp:9749:28
#14 0x561e4b4c9652 in (anonymous 
namespace)::PointerExprEvaluator::VisitCallExpr(clang::CallExpr const*) 
third_party/llvm/llvm-project/clang/lib/AST/ExprConstant.cpp:9763:12
#15 0x561e4b4c3e5b in 
clang::StmtVisitorBase::Visit(clang::Stmt const*) 
blaze-out/k8-opt-asan/genfiles/third_party/llvm/llvm-project/clang/include/clang/AST/StmtNodes.inc
#16 0x561e4b3ff820 in EvaluatePointer 
third_party/llvm/llvm-project/clang/lib/AST/ExprConstant.cpp:9458:60
#17 0x561e4b3ff820 in Evaluate(clang::APValue&, (anonymous 
namespace)::EvalInfo&, clang::Expr const*) 
third_party/llvm/llvm-project/clang/lib/AST/ExprConstant.cpp:16343:10
#18 0x561e4b41f204 in EvaluateStmt((anonymous 
namespace)::StmtResult&, (anonymous namespace)::EvalInfo&, clang::Stmt 
const*, clang::SwitchCase const*) 
third_party/llvm/llvm-project/clang/lib/AST/ExprConstant.cpp:5511:17
#19 0x561e4b41d341 in EvaluateStmt((anonymous 
namespace)::StmtResult&, (anonymous namespace)::EvalInfo&, clang::Stmt 
const*, clang::SwitchCase const*) 
third_party/llvm/llvm-project/clang/lib/AST/ExprConstant.cpp:5521:28
#20 0x561e4b40113c in HandleFunctionCall(clang::SourceLocation, 
clang::FunctionDecl const*, (anonymous namespace)::LValue const*, clang::Expr 
const*, llvm::ArrayRef, (anonymous 
namespace)::CallRef, clang::Stmt const*, (anonymous namespace)::EvalInfo&, 
clang::APValue&, (anonymous namespace)::LValue const*) 
third_party/llvm/llvm-project/clang/lib/AST/ExprConstant.cpp:6520:24
#21 0x561e4b4c9652 in handleCallExpr 
third_party/llvm/llvm-project/clang/lib/AST/ExprConstant.cpp:8332:10
#22 0x561e4b4c9652 i

[clang] [flang] [flang] Treat pre-processed input as fixed (PR #117563)

2024-12-03 Thread Andrzej Warzyński via cfe-commits

https://github.com/banach-space approved this pull request.

LGTM, thank you for all the detective work!

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


[clang] [flang] [flang] Treat pre-processed input as fixed (PR #117563)

2024-12-03 Thread via cfe-commits

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


[clang] [clang-format] Add support for `.cjs` as JavaScript file extension (PR #118188)

2024-12-03 Thread Jim B via cfe-commits

https://github.com/d3x0r updated 
https://github.com/llvm/llvm-project/pull/118188

>From 8ce527dc2cc7ac285f782648838664491abffc30 Mon Sep 17 00:00:00 2001
From: d3x0r 
Date: Sat, 30 Nov 2024 02:32:40 -0800
Subject: [PATCH 1/4] Add *.cjs handling for JavaScript Language.

---
 clang/lib/Format/Format.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index ee52972ce66f4a..dcaac4b0d42cc5 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -3950,6 +3950,7 @@ static FormatStyle::LanguageKind 
getLanguageByFileName(StringRef FileName) {
 return FormatStyle::LK_Java;
   if (FileName.ends_with_insensitive(".js") ||
   FileName.ends_with_insensitive(".mjs") ||
+  FileName.ends_with_insensitive(".cjs") ||
   FileName.ends_with_insensitive(".ts")) {
 return FormatStyle::LK_JavaScript; // (module) JavaScript or TypeScript.
   }

>From 3f28f82d1dc87006aceb0e0c7bd95c460d70ccd0 Mon Sep 17 00:00:00 2001
From: d3x0r 
Date: Sun, 1 Dec 2024 13:04:01 -0800
Subject: [PATCH 2/4] Also update docs, command line help info,
 git-clang-format

---
 clang/docs/ClangFormat.rst| 2 +-
 clang/tools/clang-format/ClangFormat.cpp  | 2 +-
 clang/tools/clang-format/git-clang-format | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/docs/ClangFormat.rst b/clang/docs/ClangFormat.rst
index e17d741b0a00eb..10ddca8685e941 100644
--- a/clang/docs/ClangFormat.rst
+++ b/clang/docs/ClangFormat.rst
@@ -49,7 +49,7 @@ to format C/C++/Java/JavaScript/JSON/Objective-C/Protobuf/C# 
code.
  supported:
CSharp: .cs
Java: .java
-   JavaScript: .mjs .js .ts
+   JavaScript: .mjs .js .ts .cjs
Json: .json
Objective-C: .m .mm
Proto: .proto .protodevel
diff --git a/clang/tools/clang-format/ClangFormat.cpp 
b/clang/tools/clang-format/ClangFormat.cpp
index 5481bb6b87503c..a3e80964c68028 100644
--- a/clang/tools/clang-format/ClangFormat.cpp
+++ b/clang/tools/clang-format/ClangFormat.cpp
@@ -87,7 +87,7 @@ static cl::opt AssumeFileName(
  "supported:\n"
  "  CSharp: .cs\n"
  "  Java: .java\n"
- "  JavaScript: .mjs .js .ts\n"
+ "  JavaScript: .cjs .mjs .js .ts\n"
  "  Json: .json\n"
  "  Objective-C: .m .mm\n"
  "  Proto: .proto .protodevel\n"
diff --git a/clang/tools/clang-format/git-clang-format 
b/clang/tools/clang-format/git-clang-format
index 6a2a2a22ec5c2b..f965adae42f435 100755
--- a/clang/tools/clang-format/git-clang-format
+++ b/clang/tools/clang-format/git-clang-format
@@ -94,7 +94,7 @@ def main():
   # Other languages that clang-format supports
   'proto', 'protodevel',  # Protocol Buffers
   'java',  # Java
-  'mjs', 'js',  # JavaScript
+  'cjs', 'mjs', 'js',  # JavaScript
   'ts',  # TypeScript
   'cs',  # C Sharp
   'json',  # Json

>From 30634a1f6bba7de1c429d3d964c0f48b7fdb3dc3 Mon Sep 17 00:00:00 2001
From: d3x0r 
Date: Mon, 2 Dec 2024 01:26:59 -0800
Subject: [PATCH 3/4] Reorder lists for Javascript to .js .mjs .cjs (.ts)

---
 clang/docs/ClangFormat.rst| 2 +-
 clang/tools/clang-format/ClangFormat.cpp  | 2 +-
 clang/tools/clang-format/git-clang-format | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/docs/ClangFormat.rst b/clang/docs/ClangFormat.rst
index 10ddca8685e941..c8f1d7f5a77581 100644
--- a/clang/docs/ClangFormat.rst
+++ b/clang/docs/ClangFormat.rst
@@ -49,7 +49,7 @@ to format C/C++/Java/JavaScript/JSON/Objective-C/Protobuf/C# 
code.
  supported:
CSharp: .cs
Java: .java
-   JavaScript: .mjs .js .ts .cjs
+   JavaScript: .js .mjs .cjs .ts
Json: .json
Objective-C: .m .mm
Proto: .proto .protodevel
diff --git a/clang/tools/clang-format/ClangFormat.cpp 
b/clang/tools/clang-format/ClangFormat.cpp
index a3e80964c68028..28610052b9b74a 100644
--- a/clang/tools/clang-format/ClangFormat.cpp
+++ b/clang/tools/clang-format/ClangFormat.cpp
@@ -87,7 +87,7 @@ static cl::opt AssumeFileName(
  "supported:\n"
  "  CSharp: .cs\n"
  "  Java: .java\n"
- "  JavaScript: .cjs .mjs .js .ts\n"
+ "  JavaScript: .js .mjs .cjs .ts\n"
  "  Json: .json\n"
  "  Objective-C: .m .mm\n"
  "  Proto: .proto .protodevel\n"
diff --git a/clang/tools/clang-format/git-clang-f

[clang] 81d82ca - [flang] Treat pre-processed input as fixed (#117563)

2024-12-03 Thread via cfe-commits

Author: macurtis-amd
Date: 2024-12-03T06:59:57-06:00
New Revision: 81d82cac8c4cbd006bf991fd7380de2d72858d1c

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

LOG: [flang] Treat pre-processed input as fixed (#117563)

Fixes an issue introduced by

9fb2db1e1f42 [flang] Retain spaces when preprocessing fixed-form source

Where flang -fc1 fails to parse preprocessor output because it now
remains in fixed form.

Added: 
flang/test/Driver/pp-fixed-form.f90

Modified: 
clang/lib/Driver/ToolChains/Flang.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 8c18c88fbde7f7..72c0787d7df993 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -777,6 +777,13 @@ void Flang::ConstructJob(Compilation &C, const JobAction 
&JA,
 
   addFortranDialectOptions(Args, CmdArgs);
 
+  // 'flang -E' always produces output that is suitable for use as fixed form
+  // Fortran. However it is only valid free form source if the original is also
+  // free form.
+  if (InputType == types::TY_PP_Fortran &&
+  !Args.getLastArg(options::OPT_ffixed_form, options::OPT_ffree_form))
+CmdArgs.push_back("-ffixed-form");
+
   handleColorDiagnosticsArgs(D, Args, CmdArgs);
 
   // LTO mode is parsed by the Clang driver library.

diff  --git a/flang/test/Driver/pp-fixed-form.f90 
b/flang/test/Driver/pp-fixed-form.f90
new file mode 100644
index 00..4695da78763ae5
--- /dev/null
+++ b/flang/test/Driver/pp-fixed-form.f90
@@ -0,0 +1,19 @@
+!RUN: %flang -save-temps -### %S/Inputs/free-form-test.f90  2>&1 | FileCheck 
%s --check-prefix=FREE
+FREE:   "-fc1" {{.*}} "-o" "free-form-test.i" {{.*}} "-x" "f95-cpp-input" 
"{{.*}}/free-form-test.f90"
+FREE-NEXT:  "-fc1" {{.*}} "-ffixed-form" {{.*}} "-x" "f95" "free-form-test.i"
+
+!RUN: %flang -save-temps -### %S/Inputs/fixed-form-test.f  2>&1 | FileCheck %s 
--check-prefix=FIXED
+FIXED:  "-fc1" {{.*}} "-o" "fixed-form-test.i" {{.*}} "-x" "f95-cpp-input" 
"{{.*}}/fixed-form-test.f"
+FIXED-NEXT: "-fc1" {{.*}} "-ffixed-form" {{.*}} "-x" "f95" "fixed-form-test.i"
+
+!RUN: %flang -save-temps -### -ffree-form %S/Inputs/free-form-test.f90  2>&1 | 
FileCheck %s --check-prefix=FREE-FLAG
+FREE-FLAG:   "-fc1" {{.*}} "-o" "free-form-test.i" {{.*}} "-x" 
"f95-cpp-input" "{{.*}}/free-form-test.f90"
+FREE-FLAG-NEXT:  "-fc1" {{.*}} "-emit-llvm-bc" "-ffree-form"
+FREE-FLAG-NOT:   "-ffixed-form"
+FREE-FLAG-SAME:  "-x" "f95" "free-form-test.i"
+
+!RUN: %flang -save-temps -### -ffixed-form %S/Inputs/fixed-form-test.f  2>&1 | 
FileCheck %s --check-prefix=FIXED-FLAG
+FIXED-FLAG:  "-fc1" {{.*}} "-o" "fixed-form-test.i" {{.*}} "-x" 
"f95-cpp-input" "{{.*}}/fixed-form-test.f"
+FIXED-FLAG-NEXT: "-fc1" {{.*}} "-emit-llvm-bc" "-ffixed-form"
+FIXED-FLAG-NOT:  "-ffixed-form"
+FIXED-FLAG-SAME: "-x" "f95" "fixed-form-test.i"



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


[clang] [flang] [flang] Treat pre-processed input as fixed (PR #117563)

2024-12-03 Thread via cfe-commits

macurtis-amd wrote:

> LGTM, thanks for being patient with our requests for changes!

> LGTM, thank you for all the detective work!

Happy to help!

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


[clang] [clang][bytecode] Fix discarded pointer subtractions (PR #118477)

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

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


[clang-tools-extra] [clangd] Re-land "support outgoing calls in call hierarchy" (PR #117673)

2024-12-03 Thread kadir çetinkaya via cfe-commits

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

thanks, mostly LG! i think not leaving the default parameter values are 
important here to make sure we don't forget to pass the top-level config in any 
of the relevant places (both now, but also in the future). i know it probably 
comes with a bunch of changes to tests though :/ (i wish clangd was better at 
updating signatures in such cases!)

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


[clang-tools-extra] [clangd] Re-land "support outgoing calls in call hierarchy" (PR #117673)

2024-12-03 Thread kadir çetinkaya via cfe-commits


@@ -163,7 +163,7 @@ class Checker {
   unsigned ErrCount = 0;
 
   Checker(llvm::StringRef File, const ClangdLSPServer::Options &Opts)
-  : File(File), Opts(Opts) {}
+  : File(File), Opts(Opts), Index(/*SupportContainedRefs=*/false) {}

kadircet wrote:

why false here? i think it's better if we use whatever clangd-server's default 
is

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


[clang-tools-extra] [clangd] Re-land "support outgoing calls in call hierarchy" (PR #117673)

2024-12-03 Thread kadir çetinkaya via cfe-commits


@@ -108,7 +109,7 @@ class FileSymbols {
 /// FIXME: Expose an interface to remove files that are closed.
 class FileIndex : public MergedIndex {
 public:
-  FileIndex();
+  FileIndex(bool SupportContainedRefs = true);

kadircet wrote:

same with the default param

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


[clang-tools-extra] [clangd] Re-land "support outgoing calls in call hierarchy" (PR #117673)

2024-12-03 Thread kadir çetinkaya via cfe-commits


@@ -69,7 +69,7 @@ enum class DuplicateHandling {
 /// locking when we swap or obtain references to snapshots.
 class FileSymbols {
 public:
-  FileSymbols(IndexContents IdxContents);
+  FileSymbols(IndexContents IdxContents, bool SupportContainedRefs = true);

kadircet wrote:

can we avoid the default param here?

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


[clang-tools-extra] [clangd] Re-land "support outgoing calls in call hierarchy" (PR #117673)

2024-12-03 Thread kadir çetinkaya via cfe-commits


@@ -83,7 +83,8 @@ std::string toYAML(const Ref &);
 // Build an in-memory static index from an index file.
 // The size should be relatively small, so data can be managed in memory.
 std::unique_ptr loadIndex(llvm::StringRef Filename,
-   SymbolOrigin Origin, bool UseDex = 
true);
+   SymbolOrigin Origin, bool UseDex = true,
+   bool SupportContainedRefs = true);

kadircet wrote:

avoiding the default here as well

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


[clang-tools-extra] [clangd] Re-land "support outgoing calls in call hierarchy" (PR #117673)

2024-12-03 Thread kadir çetinkaya via cfe-commits


@@ -64,16 +65,18 @@ class Dex : public SymbolIndex {
 typename FileRange, typename Payload>
   Dex(SymbolRange &&Symbols, RefsRange &&Refs, RelationsRange &&Relations,
   FileRange &&Files, IndexContents IdxContents, Payload &&BackingData,
-  size_t BackingDataSize)
+  size_t BackingDataSize, bool SupportContainedRefs = true)
   : Dex(std::forward(Symbols), std::forward(Refs),
 std::forward(Relations),
-std::forward(BackingData), BackingDataSize) {
+std::forward(BackingData), BackingDataSize,
+SupportContainedRefs) {
 this->Files = std::forward(Files);
 this->IdxContents = IdxContents;
   }
 
   /// Builds an index from slabs. The index takes ownership of the slab.
-  static std::unique_ptr build(SymbolSlab, RefSlab, RelationSlab);
+  static std::unique_ptr build(SymbolSlab, RefSlab, RelationSlab,
+bool SupportContainedRefs = true);

kadircet wrote:

and here

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


[clang-tools-extra] [clangd] Re-land "support outgoing calls in call hierarchy" (PR #117673)

2024-12-03 Thread kadir çetinkaya via cfe-commits


@@ -36,7 +36,8 @@ class Dex : public SymbolIndex {
 public:
   // All data must outlive this index.
   template 
-  Dex(SymbolRange &&Symbols, RefsRange &&Refs, RelationsRange &&Relations)
+  Dex(SymbolRange &&Symbols, RefsRange &&Refs, RelationsRange &&Relations,
+  bool SupportContainedRefs = true)

kadircet wrote:

again the default

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


[clang-tools-extra] [clangd] Re-land "support outgoing calls in call hierarchy" (PR #117673)

2024-12-03 Thread kadir çetinkaya via cfe-commits

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


[clang] [AArch64][SME] Fix bug on SMELd1St1 (PR #118109)

2024-12-03 Thread via cfe-commits

https://github.com/wwwatermiao updated 
https://github.com/llvm/llvm-project/pull/118109

>From 4ced088ff94ec203d24e87371fad044260f2f032 Mon Sep 17 00:00:00 2001
From: chenmiao 
Date: Fri, 29 Nov 2024 23:57:48 +0800
Subject: [PATCH] [AArch64][SME] Fix bug on SMELd1St1

Patch[1] has update intrinsic interface for ld1/st1, while based on ARM's 
document,
"If the intrinsic also has a vnum argument, the ZA slice number is calculated 
by adding vnum to slice.".
But the "vnum" did not work for our realization now, this patch fix this point.

[1]https://github.com/llvm/llvm-project/commit/ee31ba0dd923c3a4628cf3887e137843e43c8b22
---
 clang/lib/CodeGen/CGBuiltin.cpp   |   7 +-
 .../sme-intrinsics/acle_sme_ld1_vnum.c| 168 --
 .../sme-intrinsics/acle_sme_st1_vnum.c| 168 --
 3 files changed, 229 insertions(+), 114 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index e0504c0e38b22a..256687d8b037b5 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -10628,7 +10628,7 @@ Value *CodeGenFunction::EmitSMELd1St1(const 
SVETypeFlags &TypeFlags,
   NewOps.push_back(Ops[2]);
 
   llvm::Value *BasePtr = Ops[3];
-
+  llvm::Value *RealSlice = Ops[1];
   // If the intrinsic contains the vnum parameter, multiply it with the vector
   // size in bytes.
   if (Ops.size() == 5) {
@@ -10640,10 +10640,13 @@ Value *CodeGenFunction::EmitSMELd1St1(const 
SVETypeFlags &TypeFlags,
 Builder.CreateMul(StreamingVectorLengthCall, Ops[4], "mulvl");
 // The type of the ptr parameter is void *, so use Int8Ty here.
 BasePtr = Builder.CreateGEP(Int8Ty, Ops[3], Mulvl);
+RealSlice = Builder.CreateZExt(RealSlice, Int64Ty);
+RealSlice = Builder.CreateAdd(RealSlice, Ops[4]);
+RealSlice = Builder.CreateTrunc(RealSlice, Int32Ty);
   }
   NewOps.push_back(BasePtr);
   NewOps.push_back(Ops[0]);
-  NewOps.push_back(Ops[1]);
+  NewOps.push_back(RealSlice);
   Function *F = CGM.getIntrinsic(IntID);
   return Builder.CreateCall(F, NewOps);
 }
diff --git a/clang/test/CodeGen/AArch64/sme-intrinsics/acle_sme_ld1_vnum.c 
b/clang/test/CodeGen/AArch64/sme-intrinsics/acle_sme_ld1_vnum.c
index fcbd17559dc702..fb86690f07f1d8 100644
--- a/clang/test/CodeGen/AArch64/sme-intrinsics/acle_sme_ld1_vnum.c
+++ b/clang/test/CodeGen/AArch64/sme-intrinsics/acle_sme_ld1_vnum.c
@@ -12,9 +12,12 @@
 // CHECK-C-NEXT:[[TMP0:%.*]] = tail call i64 @llvm.aarch64.sme.cntsb()
 // CHECK-C-NEXT:[[MULVL:%.*]] = mul i64 [[TMP0]], [[VNUM]]
 // CHECK-C-NEXT:[[TMP1:%.*]] = getelementptr i8, ptr [[PTR]], i64 [[MULVL]]
-// CHECK-C-NEXT:tail call void @llvm.aarch64.sme.ld1b.horiz( [[PG]], ptr [[TMP1]], i32 0, i32 [[SLICE_BASE]])
-// CHECK-C-NEXT:[[ADD:%.*]] = add i32 [[SLICE_BASE]], 15
-// CHECK-C-NEXT:tail call void @llvm.aarch64.sme.ld1b.horiz( [[PG]], ptr [[TMP1]], i32 0, i32 [[ADD]])
+// CHECK-C-NEXT:[[TMP2:%.*]] = trunc i64 [[VNUM]] to i32
+// CHECK-C-NEXT:[[TMP3:%.*]] = add i32 [[SLICE_BASE]], [[TMP2]]
+// CHECK-C-NEXT:tail call void @llvm.aarch64.sme.ld1b.horiz( [[PG]], ptr [[TMP1]], i32 0, i32 [[TMP3]])
+// CHECK-C-NEXT:[[ADD:%.*]] = add i32 [[SLICE_BASE]], [[TMP2]]
+// CHECK-C-NEXT:[[TMP4:%.*]] = add i32 [[ADD]], 15
+// CHECK-C-NEXT:tail call void @llvm.aarch64.sme.ld1b.horiz( [[PG]], ptr [[TMP1]], i32 0, i32 [[TMP4]])
 // CHECK-C-NEXT:ret void
 //
 // CHECK-CXX-LABEL: define dso_local void 
@_Z23test_svld1_hor_vnum_za8ju10__SVBool_tPKvl(
@@ -23,9 +26,12 @@
 // CHECK-CXX-NEXT:[[TMP0:%.*]] = tail call i64 @llvm.aarch64.sme.cntsb()
 // CHECK-CXX-NEXT:[[MULVL:%.*]] = mul i64 [[TMP0]], [[VNUM]]
 // CHECK-CXX-NEXT:[[TMP1:%.*]] = getelementptr i8, ptr [[PTR]], i64 
[[MULVL]]
-// CHECK-CXX-NEXT:tail call void @llvm.aarch64.sme.ld1b.horiz( [[PG]], ptr [[TMP1]], i32 0, i32 [[SLICE_BASE]])
-// CHECK-CXX-NEXT:[[ADD:%.*]] = add i32 [[SLICE_BASE]], 15
-// CHECK-CXX-NEXT:tail call void @llvm.aarch64.sme.ld1b.horiz( [[PG]], ptr [[TMP1]], i32 0, i32 [[ADD]])
+// CHECK-CXX-NEXT:[[TMP2:%.*]] = trunc i64 [[VNUM]] to i32
+// CHECK-CXX-NEXT:[[TMP3:%.*]] = add i32 [[SLICE_BASE]], [[TMP2]]
+// CHECK-CXX-NEXT:tail call void @llvm.aarch64.sme.ld1b.horiz( [[PG]], ptr [[TMP1]], i32 0, i32 [[TMP3]])
+// CHECK-CXX-NEXT:[[ADD:%.*]] = add i32 [[SLICE_BASE]], [[TMP2]]
+// CHECK-CXX-NEXT:[[TMP4:%.*]] = add i32 [[ADD]], 15
+// CHECK-CXX-NEXT:tail call void @llvm.aarch64.sme.ld1b.horiz( [[PG]], ptr [[TMP1]], i32 0, i32 [[TMP4]])
 // CHECK-CXX-NEXT:ret void
 //
 void test_svld1_hor_vnum_za8(uint32_t slice_base, svbool_t pg, const void 
*ptr, int64_t vnum) __arm_streaming __arm_out("za") {
@@ -40,9 +46,12 @@ void test_svld1_hor_vnum_za8(uint32_t slice_base, svbool_t 
pg, const void *ptr,
 // CHECK-C-NEXT:[[TMP1:%.*]] = tail call i64 @llvm.aarch64.sme.cntsb()
 // CHECK-C-NEXT:[[MULVL:%.*]] = mul i64 [[TMP1]], [[VNUM]]
 // CHECK-C-NEXT:[[TMP2:%.*]] = ge

[clang] [llvm] [HLSL] Adding Flatten and Branch if attributes (PR #116331)

2024-12-03 Thread Chris B via cfe-commits


@@ -1206,6 +1202,21 @@ class SPIRVStructurizer : public FunctionPass {
 AU.addPreserved();
 FunctionPass::getAnalysisUsage(AU);
   }
+
+  void createOpSelectMerge(IRBuilder<> *Builder, BlockAddress *MergeAddress) {
+Instruction *BBTerminatorInst = Builder->GetInsertBlock()->getTerminator();
+
+MDNode *MDNode = BBTerminatorInst->getMetadata("hlsl.controlflow.hint");
+if (MDNode)
+  assert(MDNode->getNumOperands() == 2 &&

llvm-beanz wrote:

You shouldn't put an `assert` as the only statement on an `if` block, it is 
better to fold it into the assert condition.

Today most C runtimes are nice about the `assert` macro defining to a no-op 
statement because the spec defines it as such, but people do replace `assert`, 
and lots of horrible things can happen if a single-statement `if`'s body is a 
macro expansion and the macro doesn't expand to a complete statement. Things 
like the _next_ statement becoming the body of the `if`.

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


[clang] [llvm] [HLSL] Adding Flatten and Branch if attributes (PR #116331)

2024-12-03 Thread Chris B via cfe-commits


@@ -300,6 +301,36 @@ static MDTuple *emitTopLevelLibraryNode(Module &M, MDNode 
*RMD,
   return constructEntryMetadata(nullptr, nullptr, RMD, Properties, Ctx);
 }
 
+// TODO: We might need to refactor this to be more generic,
+// in case we need more metadata to be replaced.
+static void translateBranchMetadata(Module &M) {
+  for (auto &F : M) {
+for (auto &BB : F) {
+  auto *BBTerminatorInst = BB.getTerminator();
+
+  auto *HlslControlFlowMD =
+  BBTerminatorInst->getMetadata("hlsl.controlflow.hint");
+
+  if (!HlslControlFlowMD || HlslControlFlowMD->getNumOperands() < 2)

llvm-beanz wrote:

Huh? `getMetadata` returns `null` on failure (hence the null check). If it 
finds the named metadata, it must have two operands right? You even have this 
asserting on the SPIR-V side.

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


[clang] [flang] [flang][Driver] Support -nostdlib and -nodefaultlibs (PR #108868)

2024-12-03 Thread Mészáros Gergely via cfe-commits


@@ -5572,7 +5572,8 @@ def : Flag<["-"], "nocudalib">, Alias;
 def gpulibc : Flag<["-"], "gpulibc">, Visibility<[ClangOption, CC1Option, 
FlangOption, FC1Option]>,
   HelpText<"Link the LLVM C Library for GPUs">;
 def nogpulibc : Flag<["-"], "nogpulibc">, Visibility<[ClangOption, CC1Option, 
FlangOption, FC1Option]>;
-def nodefaultlibs : Flag<["-"], "nodefaultlibs">;
+def nodefaultlibs : Flag<["-"], "nodefaultlibs">,
+  Visibility<[ClangOption, FlangOption, CLOption, DXCOption]>;

Maetveis wrote:

@tarunprabhu, @tblah

Shouldn't these be: `Visibility<[ClangOption, FlangOption]>`, it seems like 
`clang-cl` is now accepting `-nodefaultlibs` without diagnostic, and it does 
not do anything (does NOT add /NODEFAULTLIB to link.exe's command line)

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


[clang] (reland) [clang] Warn [[clang::lifetimebound]] misusages on types (PR #118501)

2024-12-03 Thread Maksim Ivanov via cfe-commits

https://github.com/emaxx-google created 
https://github.com/llvm/llvm-project/pull/118501

The reland can go in after we fixed downstream codebases that had incorrectly 
placed attributes.

Original commit description:

Emit the "cannot be applied to types" warning instead of silently ignoring the 
attribute when it's attempted to be used on a type (instead of a function 
argument or the function definition).

Before this commit, the warning has been printed when the attribute was 
(mis)used on a decl-specifier, but not in other places in a declarator.

Examples where the warning starts being emitted with this commit:

```
  int * [[clang::lifetimebound]] x;

  void f(int * [[clang::lifetimebound]] x);

  void g(int * [[clang::lifetimebound]]);
```

Note that the last example is the case of an unnamed function parameter. While 
in theory Clang could've supported the `[[clang::lifetimebound]]` analysis for 
unnamed parameters, it doesn't currently, so the commit at least makes the 
situation better by highlighting this as a warning instead of a silent ignore - 
which was reported at #96034.

>From ffba96ae0b32a25b810c46c46e9c360c3eef400d Mon Sep 17 00:00:00 2001
From: Maksim Ivanov 
Date: Mon, 2 Dec 2024 10:03:25 +
Subject: [PATCH 1/4] [clang] Warn [[clang::lifetimebound]] misusages on types

Emit the "cannot be applied to types" warning instead of silently
ignoring the attribute when it's attempted to be used on a type (instead
of a function argument or the function definition).

Before this commit, the warning has been printed when the attribute was
(mis)used on a decl-specifier, but not in other places in a declarator.

Examples where the warning starts being emitted with this commit:

  int * [[clang::lifetimebound]] x;

  void f(int * [[clang::lifetimebound]] x);

  void g(int * [[clang::lifetimebound]]);

Note that the last example is the case of an unnamed function parameter.
While in theory Clang could've supported the [[clang::lifetimebound]],
it doesn't currently, so the commit at least makes the situation better
by highlighting this as a warning instead of a silent ignore.
---
 clang/lib/Sema/SemaType.cpp   |  3 +++
 clang/test/SemaCXX/attr-lifetimebound.cpp | 13 +++--
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index f32edc5ac06440..2cc083ff6689d6 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -8612,7 +8612,10 @@ static void HandleLifetimeBoundAttr(TypeProcessingState 
&State,
 CurType = State.getAttributedType(
 createSimpleAttr(State.getSema().Context, Attr),
 CurType, CurType);
+return;
   }
+  State.getSema().Diag(Attr.getLoc(), diag::err_attribute_not_type_attr)
+  << Attr << Attr.isRegularKeywordAttribute();
 }
 
 static void HandleLifetimeCaptureByAttr(TypeProcessingState &State,
diff --git a/clang/test/SemaCXX/attr-lifetimebound.cpp 
b/clang/test/SemaCXX/attr-lifetimebound.cpp
index f89b556f5bba08..5f10dea97c29b4 100644
--- a/clang/test/SemaCXX/attr-lifetimebound.cpp
+++ b/clang/test/SemaCXX/attr-lifetimebound.cpp
@@ -9,11 +9,20 @@ namespace usage_invalid {
 ~A() [[clang::lifetimebound]]; // expected-error {{cannot be applied to a 
destructor}}
 static int *static_class_member() [[clang::lifetimebound]]; // 
expected-error {{static member function has no implicit object parameter}}
 int *explicit_object(this A&) [[clang::lifetimebound]]; // expected-error 
{{explicit object member function has no implicit object parameter}}
-int not_function [[clang::lifetimebound]]; // expected-error {{only 
applies to parameters and implicit object parameters}}
-int [[clang::lifetimebound]] also_not_function; // expected-error {{cannot 
be applied to types}}
+int attr_on_var [[clang::lifetimebound]]; // expected-error {{only applies 
to parameters and implicit object parameters}}
+int [[clang::lifetimebound]] attr_on_int; // expected-error {{cannot be 
applied to types}}
+int * [[clang::lifetimebound]] attr_on_int_ptr; // expected-error {{cannot 
be applied to types}}
+int * [[clang::lifetimebound]] * attr_on_int_ptr_ptr; // expected-error 
{{cannot be applied to types}}
+int (* [[clang::lifetimebound]] attr_on_func_ptr)(); // expected-error 
{{cannot be applied to types}}
 void void_return_member() [[clang::lifetimebound]]; // expected-error 
{{'lifetimebound' attribute cannot be applied to an implicit object parameter 
of a function that returns void; did you mean 'lifetime_capture_by(X)'}}
   };
   int *attr_with_param(int ¶m [[clang::lifetimebound(42)]]); // 
expected-error {{takes no arguments}}
+
+  void attr_on_ptr_arg(int * [[clang::lifetimebound]] ptr); // expected-error 
{{cannot be applied to types}}
+  static_assert((int [[clang::lifetimebound]]) 12); // expected-error {{cannot 
be applied to types}}
+  int* attr_on_unnamed_arg(const int& [[clang::lifetimebound]]); // 
expected-error {{c

[clang] (reland) [clang] Warn [[clang::lifetimebound]] misusages on types (PR #118501)

2024-12-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Maksim Ivanov (emaxx-google)


Changes

The reland can go in after we fixed downstream codebases that had incorrectly 
placed attributes.

Original commit description:

Emit the "cannot be applied to types" warning instead of silently ignoring the 
attribute when it's attempted to be used on a type (instead of a function 
argument or the function definition).

Before this commit, the warning has been printed when the attribute was 
(mis)used on a decl-specifier, but not in other places in a declarator.

Examples where the warning starts being emitted with this commit:

```
  int * [[clang::lifetimebound]] x;

  void f(int * [[clang::lifetimebound]] x);

  void g(int * [[clang::lifetimebound]]);
```

Note that the last example is the case of an unnamed function parameter. While 
in theory Clang could've supported the `[[clang::lifetimebound]]` analysis for 
unnamed parameters, it doesn't currently, so the commit at least makes the 
situation better by highlighting this as a warning instead of a silent ignore - 
which was reported at #96034.

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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+16-1) 
- (modified) clang/lib/Sema/SemaType.cpp (+4) 
- (modified) clang/test/SemaCXX/attr-lifetimebound.cpp (+16-2) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b9986434d09d24..b7f0012572f880 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -139,7 +139,7 @@ C++ Specific Potentially Breaking Changes
 // Fixed version:
 unsigned operator""_udl_name(unsigned long long);
 
-- Clang will now produce an error diagnostic when [[clang::lifetimebound]] is
+- Clang will now produce an error diagnostic when ``[[clang::lifetimebound]]`` 
is
   applied on a parameter or an implicit object parameter of a function that
   returns void. This was previously ignored and had no effect. (#GH107556)
 
@@ -148,6 +148,21 @@ C++ Specific Potentially Breaking Changes
 // Now diagnoses with an error.
 void f(int& i [[clang::lifetimebound]]);
 
+- Clang will now produce an error diagnostic when ``[[clang::lifetimebound]]``
+  is applied on a type (instead of a function parameter or an implicit object
+  parameter); this includes the case when the attribute is specified for an
+  unnamed function parameter. These were previously ignored and had no effect.
+  (#GH118281)
+
+  .. code-block:: c++
+
+// Now diagnoses with an error.
+int* [[clang::lifetimebound]] x;
+// Now diagnoses with an error.
+void f(int* [[clang::lifetimebound]] i);
+// Now diagnoses with an error.
+void g(int* [[clang::lifetimebound]]);
+
 - Clang now rejects all field accesses on null pointers in constant 
expressions. The following code
   used to work but will now be rejected:
 
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index f32edc5ac06440..75130436282fbd 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -8612,7 +8612,11 @@ static void HandleLifetimeBoundAttr(TypeProcessingState 
&State,
 CurType = State.getAttributedType(
 createSimpleAttr(State.getSema().Context, Attr),
 CurType, CurType);
+return;
   }
+  State.getSema().Diag(Attr.getLoc(), diag::err_attribute_wrong_decl_type_str)
+  << Attr << Attr.isRegularKeywordAttribute()
+  << "parameters and implicit object parameters";
 }
 
 static void HandleLifetimeCaptureByAttr(TypeProcessingState &State,
diff --git a/clang/test/SemaCXX/attr-lifetimebound.cpp 
b/clang/test/SemaCXX/attr-lifetimebound.cpp
index f89b556f5bba08..c7abec61873efb 100644
--- a/clang/test/SemaCXX/attr-lifetimebound.cpp
+++ b/clang/test/SemaCXX/attr-lifetimebound.cpp
@@ -9,11 +9,25 @@ namespace usage_invalid {
 ~A() [[clang::lifetimebound]]; // expected-error {{cannot be applied to a 
destructor}}
 static int *static_class_member() [[clang::lifetimebound]]; // 
expected-error {{static member function has no implicit object parameter}}
 int *explicit_object(this A&) [[clang::lifetimebound]]; // expected-error 
{{explicit object member function has no implicit object parameter}}
-int not_function [[clang::lifetimebound]]; // expected-error {{only 
applies to parameters and implicit object parameters}}
-int [[clang::lifetimebound]] also_not_function; // expected-error {{cannot 
be applied to types}}
+int attr_on_var [[clang::lifetimebound]]; // expected-error {{only applies 
to parameters and implicit object parameters}}
+int [[clang::lifetimebound]] attr_on_int; // expected-error {{cannot be 
applied to types}}
+int * [[clang::lifetimebound]] attr_on_int_ptr; // expected-error 
{{'lifetimebound' attribute only applies to parameters and implicit object 
parameters}}
+int * [[clang::lifetimebound]] * attr_on_int_ptr_ptr; // expected-error 
{{'lifetimebound' attribute only applies 

[clang] [Clang] Add fake use emission to Clang with -fextend-lifetimes (PR #110102)

2024-12-03 Thread Paul T Robinson via cfe-commits


@@ -1353,6 +1353,19 @@ void CodeGenFunction::EmitLifetimeEnd(llvm::Value *Size, 
llvm::Value *Addr) {
   C->setDoesNotThrow();
 }
 
+void CodeGenFunction::EmitFakeUse(Address Addr) {
+  // We do not emit a fake use if we want to apply optnone to this function,
+  // even if we might not apply it anyway due to minsize or similar attributes.
+  if (!CGM.getCodeGenOpts().DisableO0ImplyOptNone &&
+  CGM.getCodeGenOpts().OptimizationLevel == 0)
+return;

pogo59 wrote:

There's no value to enabling `-fextend-lifetimes` at O0, because we only emit 
stack-home locations at O0, which are valid for the entire function. However, I 
don't remember whether that decision is a blanket decision based on opt level 
or per-function based on optnone. If it's based on opt level, then adding 
fake-uses to an optnone function (at O1 and up) might actually be the right 
thing to do.

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


[clang] [llvm] [WebAssembly] Support the new "Lime1" CPU (PR #112035)

2024-12-03 Thread Dan Gohman via cfe-commits

https://github.com/sunfishcode updated 
https://github.com/llvm/llvm-project/pull/112035

>From a42effda1d0e8c8fc1e59ea060018225fe9ba914 Mon Sep 17 00:00:00 2001
From: Dan Gohman 
Date: Fri, 11 Oct 2024 04:30:32 -0700
Subject: [PATCH 1/3] [WebAssembly] Support the new "Lime1" CPU

This adds WebAssembly support for the new [Lime1 CPU].

First, this defines some new target features. These are subsets of existing
features that reflect implementation concerns:

 - "call-indirect-overlong" - implied by "reference-types"; just the overlong
   encoding for the `call_indirect` immediate, and not the actual reference
   types.

 - "bulk-memory-opt" - implied by "bulk-memory": just `memory.copy` and
   `memory.fill`, and not the other instructions in the bulk-memory
proposal.

Next, this defines a new target CPU, "lime1", which enables mutable-globals,
bulk-memory-opt, multivalue, sign-ext, nontrapping-fptoint, extended-const,
and call-indirect-overlong. Unlike the default "generic" CPU, "lime1" is meant
to be frozen, and followed up by "lime2" and so on when new features are
desired.

[Lime1 CPU]: 
https://github.com/WebAssembly/tool-conventions/blob/main/Lime.md#lime1
---
 clang/docs/ReleaseNotes.rst   |  6 +
 clang/lib/Basic/Targets/WebAssembly.cpp   | 13 +
 llvm/docs/ReleaseNotes.md |  6 +
 llvm/lib/Target/WebAssembly/WebAssembly.td|  7 +
 .../WebAssembly/target-features-cpus.ll   | 27 +++
 5 files changed, 59 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0bb2eb820cd726..4b933b717df301 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -929,9 +929,15 @@ and `-mbulk-memory` flags, which correspond to the [Bulk 
Memory Operations]
 and [Non-trapping float-to-int Conversions] language features, which are
 [widely implemented in engines].
 
+A new Lime1 target CPU is added, -mcpu=lime1. This CPU follows the definition 
of
+the Lime1 CPU [here], and enables -mmultivalue, -mmutable-globals,
+-mcall-indirect-overlong, -msign-ext, -mbulk-memory-opt, -mnontrapping-fptoint,
+and -mextended-const.
+
 [Bulk Memory Operations]: 
https://github.com/WebAssembly/bulk-memory-operations/blob/master/proposals/bulk-memory-operations/Overview.md
 [Non-trapping float-to-int Conversions]: 
https://github.com/WebAssembly/spec/blob/master/proposals/nontrapping-float-to-int-conversion/Overview.md
 [widely implemented in engines]: https://webassembly.org/features/
+[here]: https://github.com/WebAssembly/tool-conventions/blob/main/Lime.md#lime1
 
 AVR Support
 ^^^
diff --git a/clang/lib/Basic/Targets/WebAssembly.cpp 
b/clang/lib/Basic/Targets/WebAssembly.cpp
index d9d01bceb433a2..6a476abb53077a 100644
--- a/clang/lib/Basic/Targets/WebAssembly.cpp
+++ b/clang/lib/Basic/Targets/WebAssembly.cpp
@@ -167,6 +167,17 @@ bool WebAssemblyTargetInfo::initFeatureMap(
 Features["reference-types"] = true;
 Features["sign-ext"] = true;
   };
+  auto addLime1Features = [&]() {
+// Lime1:
+// 

+Features["multivalue"] = true;
+Features["mutable-globals"] = true;
+Features["call-indirect-overlong"] = true;
+Features["sign-ext"] = true;
+Features["bulk-memory-opt"] = true;
+Features["nontrapping-fptoint"] = true;
+Features["extended-const"] = true;
+  };
   auto addBleedingEdgeFeatures = [&]() {
 addGenericFeatures();
 Features["atomics"] = true;
@@ -180,6 +191,8 @@ bool WebAssemblyTargetInfo::initFeatureMap(
   };
   if (CPU == "generic") {
 addGenericFeatures();
+  } else if (CPU == "lime1") {
+addLime1Features();
   } else if (CPU == "bleeding-edge") {
 addBleedingEdgeFeatures();
   }
diff --git a/llvm/docs/ReleaseNotes.md b/llvm/docs/ReleaseNotes.md
index dc3f3aeb735f87..d8d9c4fc4bb8a5 100644
--- a/llvm/docs/ReleaseNotes.md
+++ b/llvm/docs/ReleaseNotes.md
@@ -226,9 +226,15 @@ and `-mbulk-memory` flags, which correspond to the [Bulk 
Memory Operations]
 and [Non-trapping float-to-int Conversions] language features, which are
 [widely implemented in engines].
 
+A new Lime1 target CPU is added, -mcpu=lime1. This CPU follows the definition 
of
+the Lime1 CPU [here], and enables -mmultivalue, -mmutable-globals,
+-mcall-indirect-overlong, -msign-ext, -mbulk-memory-opt, -mnontrapping-fptoint,
+and -mextended-const.
+
 [Bulk Memory Operations]: 
https://github.com/WebAssembly/bulk-memory-operations/blob/master/proposals/bulk-memory-operations/Overview.md
 [Non-trapping float-to-int Conversions]: 
https://github.com/WebAssembly/spec/blob/master/proposals/nontrapping-float-to-int-conversion/Overview.md
 [widely implemented in engines]: https://webassembly.org/features/
+[here]: https://github.com/WebAssembly/tool-conventions/blob/main/Lime.md#lime1
 
 Changes to the Windows Target
 -
diff --git a/llvm/lib/Target/WebAssembly/WebAssembl

[clang] [llvm] [WebAssembly] Support the new "Lime1" CPU (PR #112035)

2024-12-03 Thread Dan Gohman via cfe-commits

https://github.com/sunfishcode updated 
https://github.com/llvm/llvm-project/pull/112035

>From a42effda1d0e8c8fc1e59ea060018225fe9ba914 Mon Sep 17 00:00:00 2001
From: Dan Gohman 
Date: Fri, 11 Oct 2024 04:30:32 -0700
Subject: [PATCH 1/2] [WebAssembly] Support the new "Lime1" CPU

This adds WebAssembly support for the new [Lime1 CPU].

First, this defines some new target features. These are subsets of existing
features that reflect implementation concerns:

 - "call-indirect-overlong" - implied by "reference-types"; just the overlong
   encoding for the `call_indirect` immediate, and not the actual reference
   types.

 - "bulk-memory-opt" - implied by "bulk-memory": just `memory.copy` and
   `memory.fill`, and not the other instructions in the bulk-memory
proposal.

Next, this defines a new target CPU, "lime1", which enables mutable-globals,
bulk-memory-opt, multivalue, sign-ext, nontrapping-fptoint, extended-const,
and call-indirect-overlong. Unlike the default "generic" CPU, "lime1" is meant
to be frozen, and followed up by "lime2" and so on when new features are
desired.

[Lime1 CPU]: 
https://github.com/WebAssembly/tool-conventions/blob/main/Lime.md#lime1
---
 clang/docs/ReleaseNotes.rst   |  6 +
 clang/lib/Basic/Targets/WebAssembly.cpp   | 13 +
 llvm/docs/ReleaseNotes.md |  6 +
 llvm/lib/Target/WebAssembly/WebAssembly.td|  7 +
 .../WebAssembly/target-features-cpus.ll   | 27 +++
 5 files changed, 59 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0bb2eb820cd726..4b933b717df301 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -929,9 +929,15 @@ and `-mbulk-memory` flags, which correspond to the [Bulk 
Memory Operations]
 and [Non-trapping float-to-int Conversions] language features, which are
 [widely implemented in engines].
 
+A new Lime1 target CPU is added, -mcpu=lime1. This CPU follows the definition 
of
+the Lime1 CPU [here], and enables -mmultivalue, -mmutable-globals,
+-mcall-indirect-overlong, -msign-ext, -mbulk-memory-opt, -mnontrapping-fptoint,
+and -mextended-const.
+
 [Bulk Memory Operations]: 
https://github.com/WebAssembly/bulk-memory-operations/blob/master/proposals/bulk-memory-operations/Overview.md
 [Non-trapping float-to-int Conversions]: 
https://github.com/WebAssembly/spec/blob/master/proposals/nontrapping-float-to-int-conversion/Overview.md
 [widely implemented in engines]: https://webassembly.org/features/
+[here]: https://github.com/WebAssembly/tool-conventions/blob/main/Lime.md#lime1
 
 AVR Support
 ^^^
diff --git a/clang/lib/Basic/Targets/WebAssembly.cpp 
b/clang/lib/Basic/Targets/WebAssembly.cpp
index d9d01bceb433a2..6a476abb53077a 100644
--- a/clang/lib/Basic/Targets/WebAssembly.cpp
+++ b/clang/lib/Basic/Targets/WebAssembly.cpp
@@ -167,6 +167,17 @@ bool WebAssemblyTargetInfo::initFeatureMap(
 Features["reference-types"] = true;
 Features["sign-ext"] = true;
   };
+  auto addLime1Features = [&]() {
+// Lime1:
+// 

+Features["multivalue"] = true;
+Features["mutable-globals"] = true;
+Features["call-indirect-overlong"] = true;
+Features["sign-ext"] = true;
+Features["bulk-memory-opt"] = true;
+Features["nontrapping-fptoint"] = true;
+Features["extended-const"] = true;
+  };
   auto addBleedingEdgeFeatures = [&]() {
 addGenericFeatures();
 Features["atomics"] = true;
@@ -180,6 +191,8 @@ bool WebAssemblyTargetInfo::initFeatureMap(
   };
   if (CPU == "generic") {
 addGenericFeatures();
+  } else if (CPU == "lime1") {
+addLime1Features();
   } else if (CPU == "bleeding-edge") {
 addBleedingEdgeFeatures();
   }
diff --git a/llvm/docs/ReleaseNotes.md b/llvm/docs/ReleaseNotes.md
index dc3f3aeb735f87..d8d9c4fc4bb8a5 100644
--- a/llvm/docs/ReleaseNotes.md
+++ b/llvm/docs/ReleaseNotes.md
@@ -226,9 +226,15 @@ and `-mbulk-memory` flags, which correspond to the [Bulk 
Memory Operations]
 and [Non-trapping float-to-int Conversions] language features, which are
 [widely implemented in engines].
 
+A new Lime1 target CPU is added, -mcpu=lime1. This CPU follows the definition 
of
+the Lime1 CPU [here], and enables -mmultivalue, -mmutable-globals,
+-mcall-indirect-overlong, -msign-ext, -mbulk-memory-opt, -mnontrapping-fptoint,
+and -mextended-const.
+
 [Bulk Memory Operations]: 
https://github.com/WebAssembly/bulk-memory-operations/blob/master/proposals/bulk-memory-operations/Overview.md
 [Non-trapping float-to-int Conversions]: 
https://github.com/WebAssembly/spec/blob/master/proposals/nontrapping-float-to-int-conversion/Overview.md
 [widely implemented in engines]: https://webassembly.org/features/
+[here]: https://github.com/WebAssembly/tool-conventions/blob/main/Lime.md#lime1
 
 Changes to the Windows Target
 -
diff --git a/llvm/lib/Target/WebAssembly/WebAssembl

[clang-tools-extra] [NFC] Fix uninitialized scalar field in constructor. (PR #118324)

2024-12-03 Thread Zahira Ammarguellat via cfe-commits

https://github.com/zahiraam updated 
https://github.com/llvm/llvm-project/pull/118324

>From 4142b5bd36a4f7a554196687e191a09dba9e4dcf Mon Sep 17 00:00:00 2001
From: Zahira Ammarguellat 
Date: Mon, 2 Dec 2024 09:09:21 -0800
Subject: [PATCH 1/4] [NFC] Fix uninitialized data member in constructor.

---
 clang-tools-extra/clangd/index/dex/Dex.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang-tools-extra/clangd/index/dex/Dex.h 
b/clang-tools-extra/clangd/index/dex/Dex.h
index 69e161d51135b6..f907c9a55b935b 100644
--- a/clang-tools-extra/clangd/index/dex/Dex.h
+++ b/clang-tools-extra/clangd/index/dex/Dex.h
@@ -58,6 +58,7 @@ class Dex : public SymbolIndex {
 KeepAlive = std::shared_ptr(
 std::make_shared(std::move(BackingData)), nullptr);
 this->BackingDataSize = BackingDataSize;
+this->IdxContents = IndexContents::All;
   }
 
   template From d93be0f1db9eb4cb4691c7b023bf6bc046d7 Mon Sep 17 00:00:00 2001
From: Zahira Ammarguellat 
Date: Mon, 2 Dec 2024 10:54:41 -0800
Subject: [PATCH 2/4] Fix uninitialized scalar field in constructor.

---
 clang-tools-extra/clangd/index/MemIndex.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang-tools-extra/clangd/index/MemIndex.h 
b/clang-tools-extra/clangd/index/MemIndex.h
index fba2c1a7120a2b..879d7750ac0480 100644
--- a/clang-tools-extra/clangd/index/MemIndex.h
+++ b/clang-tools-extra/clangd/index/MemIndex.h
@@ -43,6 +43,7 @@ class MemIndex : public SymbolIndex {
 KeepAlive = std::shared_ptr(
 std::make_shared(std::move(BackingData)), nullptr);
 this->BackingDataSize = BackingDataSize;
+this->IdxContents = IndexContents::All;
   }
 
   template From 12febcfcb0bbf7d4ec0ee3265076dabfc07f6ba6 Mon Sep 17 00:00:00 2001
From: Zahira Ammarguellat 
Date: Mon, 2 Dec 2024 14:10:29 -0800
Subject: [PATCH 3/4] Put the initialization in the declaration.

---
 clang-tools-extra/clangd/index/MemIndex.h | 1 -
 clang-tools-extra/clangd/index/dex/Dex.h  | 3 +--
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/clang-tools-extra/clangd/index/MemIndex.h 
b/clang-tools-extra/clangd/index/MemIndex.h
index 879d7750ac0480..fba2c1a7120a2b 100644
--- a/clang-tools-extra/clangd/index/MemIndex.h
+++ b/clang-tools-extra/clangd/index/MemIndex.h
@@ -43,7 +43,6 @@ class MemIndex : public SymbolIndex {
 KeepAlive = std::shared_ptr(
 std::make_shared(std::move(BackingData)), nullptr);
 this->BackingDataSize = BackingDataSize;
-this->IdxContents = IndexContents::All;
   }
 
   template (
 std::make_shared(std::move(BackingData)), nullptr);
 this->BackingDataSize = BackingDataSize;
-this->IdxContents = IndexContents::All;
   }
 
   template  Files;
   // Contents of the index (symbols, references, etc.)
-  IndexContents IdxContents;
+  IndexContents IdxContents = IndexContents::None;
   // Size of memory retained by KeepAlive.
   size_t BackingDataSize = 0;
 };

>From af9712fd94008868d18c65941abe78e24853ae8b Mon Sep 17 00:00:00 2001
From: Zahira Ammarguellat 
Date: Tue, 3 Dec 2024 07:56:01 -0800
Subject: [PATCH 4/4] Added the initialization of IndexContents in MemIndex.

---
 clang-tools-extra/clangd/index/MemIndex.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang-tools-extra/clangd/index/MemIndex.h 
b/clang-tools-extra/clangd/index/MemIndex.h
index fba2c1a7120a2b..ff427f65fdf066 100644
--- a/clang-tools-extra/clangd/index/MemIndex.h
+++ b/clang-tools-extra/clangd/index/MemIndex.h
@@ -93,7 +93,7 @@ class MemIndex : public SymbolIndex {
   // Set of files which were used during this index build.
   llvm::StringSet<> Files;
   // Contents of the index (symbols, references, etc.)
-  IndexContents IdxContents;
+  IndexContents IdxContents = IndexContents::None;
   std::shared_ptr KeepAlive; // poor man's move-only std::any
   // Size of memory retained by KeepAlive.
   size_t BackingDataSize = 0;

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


[clang] [Clang] Add '-Warray-compare' flag for C++ below version 20 (PR #118031)

2024-12-03 Thread via cfe-commits


@@ -10264,6 +10264,11 @@ def warn_depr_array_comparison : Warning<
   "to compare array addresses, use unary '+' to decay operands to pointers">,
   InGroup;
 
+def warn_array_comparison : Warning<
+  "comparison between two arrays; "

cor3ntin wrote:

we could say "comparison between 2 arrays compare their addresses and will be 
deprecated in c++20"

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


[clang] [Clang][AArch64]Refactor typespec handling in SveEmitter.cpp (PR #117717)

2024-12-03 Thread via cfe-commits

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


[clang-tools-extra] [clang-tidy] Create a check for signed and unsigned integers comparison (PR #113144)

2024-12-03 Thread Congcong Cai via cfe-commits




HerrCai0907 wrote:

char, unsigned char, signed char are very special case, please add some test 
case for them.

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


[clang] [llvm] [SPIR-V] Fixup storage class for global private (PR #116636)

2024-12-03 Thread Nathan Gauër via cfe-commits


@@ -58,6 +58,7 @@ enum class LangAS : unsigned {
 
   // HLSL specific address spaces.
   hlsl_groupshared,
+  hlsl_private,

Keenuts wrote:

We hoped to split the PRs between back-end and FE, shall I land both at the 
same time?

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


[clang] [clang-tools-extra] [clang] Avoid re-evaluating field bitwidth (PR #117732)

2024-12-03 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


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

>From 90929a23af50f7b209e68055abf4deb903a490cb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Wed, 27 Nov 2024 08:54:51 +0100
Subject: [PATCH 1/3] Save FieldDecl BitWidth as a ConstantExpr

---
 .../bugprone/TooSmallLoopVariableCheck.cpp|  2 +-
 .../NarrowingConversionsCheck.cpp |  2 +-
 .../hicpp/MultiwayPathsCoveredCheck.cpp   |  2 +-
 clang-tools-extra/clangd/Hover.cpp|  2 +-
 clang/include/clang/AST/Decl.h|  4 ++--
 clang/include/clang/ASTMatchers/ASTMatchers.h |  3 +--
 clang/lib/AST/ASTContext.cpp  | 10 -
 clang/lib/AST/ByteCode/Interp.h   | 10 -
 .../lib/AST/ByteCode/InterpBuiltinBitCast.cpp |  2 +-
 clang/lib/AST/Decl.cpp| 13 +++-
 clang/lib/AST/DeclCXX.cpp |  2 +-
 clang/lib/AST/Expr.cpp|  3 +--
 clang/lib/AST/ExprConstant.cpp|  2 +-
 clang/lib/AST/Randstruct.cpp  |  2 +-
 clang/lib/AST/RecordLayoutBuilder.cpp |  6 +++---
 clang/lib/CodeGen/ABIInfo.cpp |  2 +-
 clang/lib/CodeGen/ABIInfoImpl.cpp |  2 +-
 clang/lib/CodeGen/CGCall.cpp  |  6 +++---
 clang/lib/CodeGen/CGClass.cpp |  2 +-
 clang/lib/CodeGen/CGDebugInfo.cpp |  8 +++
 clang/lib/CodeGen/CGNonTrivialStruct.cpp  |  6 +++---
 clang/lib/CodeGen/CGObjCMac.cpp   |  3 +--
 clang/lib/CodeGen/CGObjCRuntime.cpp   |  2 +-
 clang/lib/CodeGen/CGRecordLayoutBuilder.cpp   | 20 +-
 clang/lib/CodeGen/SwiftCallingConv.cpp|  2 +-
 clang/lib/CodeGen/Targets/LoongArch.cpp   |  2 +-
 clang/lib/CodeGen/Targets/RISCV.cpp   |  2 +-
 clang/lib/CodeGen/Targets/X86.cpp |  2 +-
 clang/lib/CodeGen/Targets/XCore.cpp   |  2 +-
 .../Frontend/Rewrite/RewriteModernObjC.cpp|  3 ++-
 clang/lib/Sema/SemaChecking.cpp   | 10 -
 clang/lib/Sema/SemaDecl.cpp   | 21 ++-
 clang/lib/Sema/SemaDeclCXX.cpp|  6 +++---
 clang/lib/Sema/SemaDeclObjC.cpp   |  3 +--
 clang/lib/Sema/SemaOverload.cpp   |  2 +-
 clang/lib/StaticAnalyzer/Core/RegionStore.cpp |  2 +-
 clang/tools/libclang/CXType.cpp   |  2 +-
 clang/unittests/AST/ASTImporterTest.cpp   |  4 ++--
 38 files changed, 88 insertions(+), 91 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp
index a73d46f01d9b2d..4ceeefb78ee824 100644
--- a/clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp
@@ -124,7 +124,7 @@ static MagnitudeBits calcMagnitudeBits(const ASTContext 
&Context,
   unsigned SignedBits = IntExprType->isUnsignedIntegerType() ? 0U : 1U;
 
   if (const auto *BitField = IntExpr->getSourceBitField()) {
-unsigned BitFieldWidth = BitField->getBitWidthValue(Context);
+unsigned BitFieldWidth = BitField->getBitWidthValue();
 return {BitFieldWidth - SignedBits, BitFieldWidth};
   }
 
diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp
index 45fef9471d5211..25931d57943de1 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp
@@ -38,7 +38,7 @@ AST_MATCHER(FieldDecl, hasIntBitwidth) {
   assert(Node.isBitField());
   const ASTContext &Ctx = Node.getASTContext();
   unsigned IntBitWidth = Ctx.getIntWidth(Ctx.IntTy);
-  unsigned CurrentBitWidth = Node.getBitWidthValue(Ctx);
+  unsigned CurrentBitWidth = Node.getBitWidthValue();
   return IntBitWidth == CurrentBitWidth;
 }
 
diff --git a/clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp 
b/clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp
index 47dafca2d03ff0..7028c3958f103e 100644
--- a/clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp
+++ b/clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp
@@ -160,7 +160,7 @@ void MultiwayPathsCoveredCheck::handleSwitchWithoutDefault(
 }
 if (const auto *BitfieldDecl =
 Result.Nodes.getNodeAs("bitfield")) {
-  return twoPow(BitfieldDecl->getBitWidthValue(*Result.Context));
+  return twoPow(BitfieldDecl->getBitWidthValue());
 }
 
 return static_cast(0);
diff --git a/clang-tools-extra/clangd/Hover.cpp 
b/clang-tools-extra/clangd/Hover.cpp
index 298fa79e3fd0ba..5e136d0e76ece7 100644
--- a/clang-tools-extra/clangd/Hover.cpp
+++ b/clang-tools-extra/clangd/Hover.cpp
@@ -1

[clang] Add support for referencable labels for attribute documentation (PR #118428)

2024-12-03 Thread Oliver Hunt via cfe-commits

https://github.com/ojhunt updated 
https://github.com/llvm/llvm-project/pull/118428

>From aea2b4001aa8e9239909875153152083b56a6a59 Mon Sep 17 00:00:00 2001
From: Oliver Hunt 
Date: Mon, 2 Dec 2024 21:25:54 -0800
Subject: [PATCH] Add support for referencable labels for attribute
 documentation

The existing mechanism being used is to manually add a reference in the
documentation. These references link to the beginning of the text rather
than the heading for the attribute which is what this PR allows.
---
 clang/include/clang/Basic/Attr.td |  3 +++
 clang/include/clang/Basic/AttrDocs.td | 12 
 clang/utils/TableGen/ClangAttrEmitter.cpp |  3 +++
 3 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 618252f3e75247..522821a79063ac 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -55,6 +55,9 @@ class Documentation {
   // When set, specifies that the attribute is deprecated and can optionally
   // specify a replacement attribute.
   DocDeprecated Deprecated;
+
+  // When set, specifies a label that can be used to reference the 
documentation
+  string Label = "";
 }
 
 // Specifies that the attribute is explicitly omitted from the documentation,
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 5de39be4805600..7a82b8fa320590 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -3360,9 +3360,8 @@ def NoSanitizeAddressDocs : Documentation {
   // This function has multiple distinct spellings, and so it requires a custom
   // heading to be specified. The most common spelling is sufficient.
   let Heading = "no_sanitize_address, no_address_safety_analysis";
+  let Label = "langext-address_sanitizer";
   let Content = [{
-.. _langext-address_sanitizer:
-
 Use ``__attribute__((no_sanitize_address))`` on a function or a global
 variable declaration to specify that address safety instrumentation
 (e.g. AddressSanitizer) should not be applied.
@@ -3372,9 +3371,8 @@ variable declaration to specify that address safety 
instrumentation
 def NoSanitizeThreadDocs : Documentation {
   let Category = DocCatFunction;
   let Heading = "no_sanitize_thread";
+  let Label = "langext-thread_sanitizer";
   let Content = [{
-.. _langext-thread_sanitizer:
-
 Use ``__attribute__((no_sanitize_thread))`` on a function declaration to
 specify that checks for data races on plain (non-atomic) memory accesses should
 not be inserted by ThreadSanitizer. The function is still instrumented by the
@@ -3385,9 +3383,8 @@ tool to avoid false positives and provide meaningful 
stack traces.
 def NoSanitizeMemoryDocs : Documentation {
   let Category = DocCatFunction;
   let Heading = "no_sanitize_memory";
+  let Label = "langext-memory_sanitizer";
   let Content = [{
-.. _langext-memory_sanitizer:
-
 Use ``__attribute__((no_sanitize_memory))`` on a function declaration to
 specify that checks for uninitialized memory should not be inserted
 (e.g. by MemorySanitizer). The function may still be instrumented by the tool
@@ -3398,9 +3395,8 @@ to avoid false positives in other places.
 def CFICanonicalJumpTableDocs : Documentation {
   let Category = DocCatFunction;
   let Heading = "cfi_canonical_jump_table";
+  let Label = "langext-cfi_canonical_jump_table";
   let Content = [{
-.. _langext-cfi_canonical_jump_table:
-
 Use ``__attribute__((cfi_canonical_jump_table))`` on a function declaration to
 make the function's CFI jump table canonical. See :ref:`the CFI documentation
 ` for more details.
diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp 
b/clang/utils/TableGen/ClangAttrEmitter.cpp
index 534bf2d01d7957..60cb4ae452326d 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -5178,6 +5178,9 @@ GetAttributeHeadingAndSpellings(const Record 
&Documentation,
 
 static void WriteDocumentation(const RecordKeeper &Records,
const DocumentationData &Doc, raw_ostream &OS) {
+  if (const StringRef label = Doc.Documentation->getValueAsString("Label");
+  !label.empty())
+OS << ".. _" << label << ":\n\n";
   OS << Doc.Heading << "\n" << std::string(Doc.Heading.length(), '-') << "\n";
 
   // List what spelling syntaxes the attribute supports.

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


[clang] [Clang] Add '-Warray-compare' flag for C++ below version 20 (PR #118031)

2024-12-03 Thread Amr Hesham via cfe-commits

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

>From 9451a1e4f5db18d579b5f7eb206482708c9adc70 Mon Sep 17 00:00:00 2001
From: AmrDeveloper 
Date: Tue, 26 Nov 2024 22:28:16 +0100
Subject: [PATCH 1/7] Add support for '-Warray-compare' compiler flag

---
 clang/include/clang/Basic/DiagnosticGroups.td|  1 +
 clang/include/clang/Basic/DiagnosticSemaKinds.td |  5 +
 clang/lib/Sema/SemaExpr.cpp  | 14 ++
 3 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index df9bf94b5d0398..0b57d41c617963 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -699,6 +699,7 @@ def GNUStatementExpressionFromMacroExpansion :
 def GNUStatementExpression : DiagGroup<"gnu-statement-expression",

[GNUStatementExpressionFromMacroExpansion]>;
 def StringConcatation : DiagGroup<"string-concatenation">;
+def ArrayCompare : DiagGroup<"array-compare">;
 def StringCompare : DiagGroup<"string-compare">;
 def StringPlusInt : DiagGroup<"string-plus-int">;
 def StringPlusChar : DiagGroup<"string-plus-char">;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 834e588c18e376..a96fddcc797d36 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10264,6 +10264,11 @@ def warn_depr_array_comparison : Warning<
   "to compare array addresses, use unary '+' to decay operands to pointers">,
   InGroup;
 
+def warn_array_comparison : Warning<
+  "comparison between two arrays; "
+  "to compare array addresses, use unary '+' to decay operands to pointers">,
+  InGroup;
+
 def warn_stringcompare : Warning<
   "result of comparison against %select{a string literal|@encode}0 is "
   "unspecified (use an explicit string comparison function instead)">,
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index c9d7444d5865a5..d51aca4fbaf492 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -11857,11 +11857,17 @@ static void diagnoseTautologicalComparison(Sema &S, 
SourceLocation Loc,
   // C++2a [depr.array.comp]:
   //   Equality and relational comparisons ([expr.eq], [expr.rel]) between two
   //   operands of array type are deprecated.
-  if (S.getLangOpts().CPlusPlus20 && LHSStripped->getType()->isArrayType() &&
+  if (LHSStripped->getType()->isArrayType() &&
   RHSStripped->getType()->isArrayType()) {
-S.Diag(Loc, diag::warn_depr_array_comparison)
-<< LHS->getSourceRange() << RHS->getSourceRange()
-<< LHSStripped->getType() << RHSStripped->getType();
+auto IsDeprArrayComparionIgnored =
+S.getDiagnostics().isIgnored(diag::warn_depr_array_comparison, Loc);
+auto IsDeprArrayComparion =
+!S.getLangOpts().CPlusPlus20 || IsDeprArrayComparionIgnored;
+
+auto DiagID = IsDeprArrayComparion ? diag::warn_array_comparison
+   : diag::warn_depr_array_comparison;
+S.Diag(Loc, DiagID) << LHS->getSourceRange() << RHS->getSourceRange()
+<< LHSStripped->getType() << RHSStripped->getType();
 // Carry on to produce the tautological comparison warning, if this
 // expression is potentially-evaluated, we can resolve the array to a
 // non-weak declaration, and so on.

>From 6de4cba4dc9edae545efe85d2435d1f4430968af Mon Sep 17 00:00:00 2001
From: AmrDeveloper 
Date: Wed, 27 Nov 2024 21:17:21 +0100
Subject: [PATCH 2/7] Add lit test for array-comparison

---
 clang/test/SemaCXX/deprecated.cpp| 12 +++-
 clang/test/SemaCXX/warn-self-comparisons.cpp |  6 +++---
 2 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/clang/test/SemaCXX/deprecated.cpp 
b/clang/test/SemaCXX/deprecated.cpp
index 667f4d7d3edb03..03f3b2b8ff06be 100644
--- a/clang/test/SemaCXX/deprecated.cpp
+++ b/clang/test/SemaCXX/deprecated.cpp
@@ -246,17 +246,19 @@ namespace ArithConv {
 
 namespace ArrayComp {
   int arr1[3], arr2[4];
-  bool b1 = arr1 == arr2; // expected-warning {{array comparison always 
evaluates to false}} cxx20-warning {{comparison between two arrays is 
deprecated}}
-  bool b2 = arr1 < arr2; // expected-warning {{array comparison always 
evaluates to a constant}} cxx20-warning {{comparison between two arrays is 
deprecated}}
+  bool b1 = arr1 == arr2; // not-cxx20-warning {{comparison between two 
arrays}} cxx20-warning {{comparison between two arrays is deprecated}}
+  // expected-warning@-1 {{array comparison always 
evaluates to false}} 
+  bool b2 = arr1 < arr2; // not-cxx20-warning {{comparison between two 
arrays;}} cxx20-warning {{comparison between two arrays is deprecated}}
+ // expected-warning@-1 {{array comparison always

[clang-tools-extra] [clangd] Re-land "support outgoing calls in call hierarchy" (PR #117673)

2024-12-03 Thread kadir çetinkaya via cfe-commits


@@ -88,9 +90,12 @@ struct UpdateIndexCallbacks : public ParsingCallbacks {
   indexStdlib(CI, std::move(*Loc));
 
 // FIndex outlives the UpdateIndexCallbacks.
-auto Task = [FIndex(FIndex), Path(Path.str()), Version(Version.str()),
+auto Task = [this, FIndex(FIndex), Path(Path.str()), 
Version(Version.str()),
  ASTCtx(std::move(ASTCtx)), PI(std::move(PI))]() mutable {
   trace::Span Tracer("PreambleIndexing");
+  std::optional WithProvidedContext;
+  if (ContextProvider)
+WithProvidedContext.emplace(ContextProvider(""));

kadircet wrote:

why do we need to caputre contextprovider here, can we just use 
`Context::current()`? `onPreambleAST` is only invoked by preamble-thread, which 
already has the relevant context set up. you can just capture and set it via 
`[Ctx(Context::current().clone()] { WithContext WithCtx(std::move(Ctx)); ... };`

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


[clang] [clang][ARM] disable frame pointers by default for bare metal ARM targets (PR #117140)

2024-12-03 Thread Ties Stuij via cfe-commits


@@ -128,12 +128,14 @@ BareMetal::BareMetal(const Driver &D, const llvm::Triple 
&Triple,
   }
 }
 
+namespace clang {
+namespace driver {
+namespace toolchains {
 /// Is the triple {arm,armeb,thumb,thumbeb}-none-none-{eabi,eabihf} ?
-static bool isARMBareMetal(const llvm::Triple &Triple) {
-  if (Triple.getArch() != llvm::Triple::arm &&
-  Triple.getArch() != llvm::Triple::thumb &&
-  Triple.getArch() != llvm::Triple::armeb &&
-  Triple.getArch() != llvm::Triple::thumbeb)
+bool isARMEABIBareMetal(const llvm::Triple &Triple) {

stuij wrote:

Yes, that makes total sense. Done!

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


[clang] [flang] [flang] Treat pre-processed input as fixed (PR #117563)

2024-12-03 Thread Andrzej Warzyński via cfe-commits


@@ -777,6 +777,15 @@ void Flang::ConstructJob(Compilation &C, const JobAction 
&JA,
 
   addFortranDialectOptions(Args, CmdArgs);
 
+  // 'flang -E' always produces output that is suitable for use as fixed form
+  // Fortran. However it is only valid free form source if the original is also
+  // free form.
+  if (InputType == types::TY_PP_Fortran &&
+  !Args.hasArg(options::OPT_ffixed_form) &&
+  !Args.hasArg(options::OPT_ffree_form)) {

banach-space wrote:

This should capture the right-most instance of `-ffixed-form`/`-ffree-form`, 
which is exactly what you want here:
```cpp
Args.getLastArg(clang::driver::options::OPT_ffixed_form,
clang::driver::options::OPT_ffree_form))
```

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


[clang-tools-extra] [clang-tidy] Create a check for signed and unsigned integers comparison (PR #113144)

2024-12-03 Thread Congcong Cai via cfe-commits

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


[clang-tools-extra] [clang-tidy] ignore `[[clang::lifetimebound]]` param in return-const-ref-from-parameter (PR #118315)

2024-12-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: Congcong Cai (HerrCai0907)


Changes

Fixed #117696

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


4 Files Affected:

- (modified) 
clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp 
(+11-1) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+2-1) 
- (modified) 
clang-tools-extra/docs/clang-tidy/checks/bugprone/return-const-ref-from-parameter.rst
 (+18-9) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/bugprone/return-const-ref-from-parameter.cpp
 (+6) 


``diff
diff --git 
a/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp
index 7da27c0474d519..06e1c5c407b175 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "ReturnConstRefFromParameterCheck.h"
+#include "clang/AST/Attrs.inc"
 #include "clang/AST/Expr.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
@@ -15,6 +16,14 @@ using namespace clang::ast_matchers;
 
 namespace clang::tidy::bugprone {
 
+namespace {
+
+AST_MATCHER(ParmVarDecl, hasLifetimeBoundAttr) {
+  return Node.getAttr() != nullptr;
+}
+
+} // namespace
+
 void ReturnConstRefFromParameterCheck::registerMatchers(MatchFinder *Finder) {
   const auto DRef = ignoringParens(
   declRefExpr(
@@ -22,7 +31,8 @@ void 
ReturnConstRefFromParameterCheck::registerMatchers(MatchFinder *Finder) {
  qualType(lValueReferenceType(pointee(
   qualType(isConstQualified()
  .bind("type"))),
- hasDeclContext(functionDecl().bind("owner")))
+ hasDeclContext(functionDecl().bind("owner")),
+ unless(hasLifetimeBoundAttr()))
  .bind("param")))
   .bind("dref"));
   const auto Func =
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 453a91e3b504cd..c7d0c0f167e581 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -184,7 +184,8 @@ Changes in existing checks
   ` check to
   diagnose potential dangling references when returning a ``const &`` parameter
   by using the conditional operator ``cond ? var1 : var2`` and no longer giving
-  false positives for functions which contain lambda.
+  false positives for functions which contain lambda and ignore the parameters
+  with ``[[clang::lifetimebound]]`` attribute.
   
 - Improved :doc:`bugprone-sizeof-expression
   ` check to find suspicious
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/return-const-ref-from-parameter.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/return-const-ref-from-parameter.rst
index 2349e51477b7de..aa2a43b6e8e6d1 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/return-const-ref-from-parameter.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/return-const-ref-from-parameter.rst
@@ -12,15 +12,6 @@ after the call. When the function returns such a parameter 
also as constant refe
 then the returned reference can be used after the object it refers to has been
 destroyed.
 
-This issue can be resolved by declaring an overload of the problematic function
-where the ``const &`` parameter is instead declared as ``&&``. The developer 
has
-to ensure that the implementation of that function does not produce a
-use-after-free, the exact error that this check is warning against.
-Marking such an ``&&`` overload as ``deleted``, will silence the warning as 
-well. In the case of different ``const &`` parameters being returned depending
-on the control flow of the function, an overload where all problematic
-``const &`` parameters have been declared as ``&&`` will resolve the issue.
-
 Example
 ---
 
@@ -38,3 +29,21 @@ Example
 
   const S& s = fn(S{1});
   s.v; // use after free
+
+
+This issue can be resolved by declaring an overload of the problematic function
+where the ``const &`` parameter is instead declared as ``&&``. The developer 
has
+to ensure that the implementation of that function does not produce a
+use-after-free, the exact error that this check is warning against.
+Marking such an ``&&`` overload as ``deleted``, will silence the warning as 
+well. In the case of different ``const &`` parameters being returned depending
+on the control flow of the function, an overload where all problematic
+``const &`` parameters have been declared as ``&&`` will resolve the issue.
+
+This issue can also be resolved by adding ``[[clang::lifetimebound]]`` and
+enabling ``-Wdangling`` in clang. See `lifetimebound

[clang] [clang][Driver] Use shared_ptr in the Compilation class (PR #116406)

2024-12-03 Thread David Truby via cfe-commits

https://github.com/DavidTruby commented:

I think you still don't need any of the shared_ptr usage here, there's no 
shared ownership semantics. If you change all these to unique_ptr then I think 
the patch would look good to me.

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


[clang] [clang][ARM] disable frame pointers by default for bare metal ARM targets (PR #117140)

2024-12-03 Thread Ties Stuij via cfe-commits

https://github.com/stuij updated 
https://github.com/llvm/llvm-project/pull/117140

>From 4a85a0cd98bf328f31465d47c56640abdf7ec08c Mon Sep 17 00:00:00 2001
From: Ties Stuij 
Date: Fri, 15 Nov 2024 13:19:08 +
Subject: [PATCH 1/7] [clang][ARM] disable frame pointers by default for bare
 metal ARM targets

because:
- This brings Clang in line with GCC for which this is the default for ARM
- It frees up a register, so performance increase, especially on Thumb/6-M
- It will also decrease code size
---
 clang/lib/Driver/ToolChains/BareMetal.cpp  |  8 +-
 clang/lib/Driver/ToolChains/BareMetal.h|  2 ++
 clang/lib/Driver/ToolChains/CommonArgs.cpp |  5 
 clang/test/Driver/frame-pointer-elim.c | 29 ++
 4 files changed, 43 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/BareMetal.cpp 
b/clang/lib/Driver/ToolChains/BareMetal.cpp
index f9a73f60973e4c..13b510e7e70994 100644
--- a/clang/lib/Driver/ToolChains/BareMetal.cpp
+++ b/clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -128,8 +128,11 @@ BareMetal::BareMetal(const Driver &D, const llvm::Triple 
&Triple,
   }
 }
 
+namespace clang {
+namespace driver {
+namespace toolchains {
 /// Is the triple {arm,armeb,thumb,thumbeb}-none-none-{eabi,eabihf} ?
-static bool isARMBareMetal(const llvm::Triple &Triple) {
+bool isARMBareMetal(const llvm::Triple &Triple) {
   if (Triple.getArch() != llvm::Triple::arm &&
   Triple.getArch() != llvm::Triple::thumb &&
   Triple.getArch() != llvm::Triple::armeb &&
@@ -148,6 +151,9 @@ static bool isARMBareMetal(const llvm::Triple &Triple) {
 
   return true;
 }
+} // namespace clang
+} // namespace driver
+} // namespace clang
 
 /// Is the triple {aarch64.aarch64_be}-none-elf?
 static bool isAArch64BareMetal(const llvm::Triple &Triple) {
diff --git a/clang/lib/Driver/ToolChains/BareMetal.h 
b/clang/lib/Driver/ToolChains/BareMetal.h
index b385c8cf76aab0..ae09bcedd78a28 100644
--- a/clang/lib/Driver/ToolChains/BareMetal.h
+++ b/clang/lib/Driver/ToolChains/BareMetal.h
@@ -19,6 +19,8 @@ namespace driver {
 
 namespace toolchains {
 
+bool isARMBareMetal(const llvm::Triple &Triple);
+
 class LLVM_LIBRARY_VISIBILITY BareMetal : public ToolChain {
 public:
   BareMetal(const Driver &D, const llvm::Triple &Triple,
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 8d977149e62485..8d54d0a8649cc9 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -19,6 +19,7 @@
 #include "Arch/SystemZ.h"
 #include "Arch/VE.h"
 #include "Arch/X86.h"
+#include "BareMetal.h"
 #include "HIPAMD.h"
 #include "Hexagon.h"
 #include "MSP430.h"
@@ -151,6 +152,10 @@ static bool useFramePointerForTargetByDefault(const 
llvm::opt::ArgList &Args,
 }
   }
 
+  if (toolchains::isARMBareMetal(Triple)) {
+return false;
+  }
+
   return true;
 }
 
diff --git a/clang/test/Driver/frame-pointer-elim.c 
b/clang/test/Driver/frame-pointer-elim.c
index cdedcc7ae4c89f..667c47b34bc703 100644
--- a/clang/test/Driver/frame-pointer-elim.c
+++ b/clang/test/Driver/frame-pointer-elim.c
@@ -162,5 +162,34 @@
 // RUN:   FileCheck --check-prefix=KEEP-NON-LEAF %s
 // RUN: not %clang -### --target=riscv64-linux-android -mbig-endian -O1 -S %s 
2>&1 | \
 // RUN:   FileCheck --check-prefix=KEEP-NON-LEAF %s
+
+// On ARM backend bare metal targets, frame pointer is omitted
+// RUN: %clang -### --target=arm-arm-none-eabi -S %s 2>&1 | \
+// RUN:   FileCheck --check-prefix=KEEP-NONE %s
+// RUN: %clang -### --target=arm-arm-none-eabihf -S %s 2>&1 | \
+// RUN:   FileCheck --check-prefix=KEEP-NONE %s
+// RUN: %clang -### --target=arm-arm-none-eabi -S -fno-omit-frame-pointer %s 
2>&1 | \
+// RUN:   FileCheck --check-prefix=KEEP-ALL %s
+// RUN: %clang -### --target=arm-arm-none-eabihf -S -fno-omit-frame-pointer %s 
2>&1 | \
+// RUN:   FileCheck --check-prefix=KEEP-ALL %s
+// RUN: %clang -### --target=arm-arm-none-eabi -S -O1 %s 2>&1 | \
+// RUN:   FileCheck --check-prefix=KEEP-NONE %s
+// RUN: %clang -### --target=arm-arm-none-eabihf -S -O1 %s 2>&1 | \
+// RUN:   FileCheck --check-prefix=KEEP-NONE %s
+// RUN: %clang -### --target=arm-arm-none-eabi -S -O1 -fno-omit-frame-pointer 
%s 2>&1 | \
+// RUN:   FileCheck --check-prefix=KEEP-ALL %s
+// RUN: %clang -### --target=arm-arm-none-eabihf -S -O1 
-fno-omit-frame-pointer %s 2>&1 | \
+// RUN:   FileCheck --check-prefix=KEEP-ALL %s
+
+// AArch64 bare metal targets behave like hosted targets
+// RUN: %clang -### --target=aarch64-none-elf -S %s 2>&1 |  \
+// RUN:   FileCheck --check-prefix=KEEP-NON-LEAF %s
+// RUN: %clang -### --target=aarch64-none-elf -S -O1 %s 2>&1 |  \
+// RUN:   FileCheck --check-prefix=KEEP-NON-LEAF %s
+// RUN: %clang -### --target=aarch64-none-elf -S -fno-omit-frame-pointer %s 
2>&1 |  \
+// RUN:   FileCheck --check-prefix=KEEP-NON-LEAF %s
+// RUN: %clang -### --target=aarch64-none-elf -S -O1 -fno-omit-frame-pointer 
%s 2>&1 |  \
+// RUN:   FileCheck --check-prefix=KE

[clang] [clang][ASTImporter] Not using primary context in lookup table (PR #118466)

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

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

`ASTImporterLookupTable` did use the `getPrimaryContext` function to get the 
declaration context of the inserted items. This is problematic because the 
primary context can change during import of AST items, most likely if a 
definition of a previously not defined class is imported. (For any record the 
primary context is the definition if there is one.) The use of primary context 
is really not important, only for namespaces because these can be re-opened and 
lookup in one namespace block is not enough. This special search is now moved 
into ASTImporter instead of relying on the lookup table.

From e97972c18fd88129bb868b1bfc880f7fdb8e8c73 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bal=C3=A1zs=20K=C3=A9ri?= 
Date: Fri, 29 Nov 2024 18:00:04 +0100
Subject: [PATCH] [clang][ASTImporter] Not using primary context in lookup
 table

`ASTImporterLookupTable` did use the `getPrimaryContext` function
to get the declaration context of the inserted items. This is
problematic because the primary context can change during import
of AST items, most likely if a definition of a previously not
defined class is imported. (For any record the primary context is
the definition if there is one.) The use of primary context is
really not important, only for namespaces because these can be
re-opened and lookup in one namespace block is not enough. This
special search is now moved into ASTImporter instead of relying
on the lookup table.
---
 clang/lib/AST/ASTImporter.cpp|  24 +++-
 clang/lib/AST/ASTImporterLookupTable.cpp |  20 +--
 clang/unittests/AST/ASTImporterTest.cpp  | 152 ++-
 3 files changed, 181 insertions(+), 15 deletions(-)

diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index a0cd57e2e5ee0d..34b2d8e3696df5 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -3165,6 +3165,7 @@ ExpectedDecl ASTNodeImporter::VisitRecordDecl(RecordDecl 
*D) {
 if (Error Err = ImportImplicitMethods(DCXX, FoundCXX))
   return std::move(Err);
 }
+return FoundDef;
   }
   PrevDecl = FoundRecord->getMostRecentDecl();
   break;
@@ -9052,9 +9053,26 @@ ASTImporter::findDeclsInToCtx(DeclContext *DC, 
DeclarationName Name) {
   // We can diagnose this only if we search in the redecl context.
   DeclContext *ReDC = DC->getRedeclContext();
   if (SharedState->getLookupTable()) {
-ASTImporterLookupTable::LookupResult LookupResult =
-SharedState->getLookupTable()->lookup(ReDC, Name);
-return FoundDeclsTy(LookupResult.begin(), LookupResult.end());
+if (ReDC->isNamespace()) {
+  // Namespaces can be reopened.
+  // Lookup table does not handle this, we must search here in all linked
+  // namespaces.
+  FoundDeclsTy Result;
+  SmallVector NSChain =
+  getCanonicalForwardRedeclChain(
+  dyn_cast(ReDC));
+  for (auto *D : NSChain) {
+ASTImporterLookupTable::LookupResult LookupResult =
+SharedState->getLookupTable()->lookup(dyn_cast(D),
+  Name);
+Result.append(LookupResult.begin(), LookupResult.end());
+  }
+  return Result;
+} else {
+  ASTImporterLookupTable::LookupResult LookupResult =
+  SharedState->getLookupTable()->lookup(ReDC, Name);
+  return FoundDeclsTy(LookupResult.begin(), LookupResult.end());
+}
   } else {
 DeclContext::lookup_result NoloadLookupResult = ReDC->noload_lookup(Name);
 FoundDeclsTy Result(NoloadLookupResult.begin(), NoloadLookupResult.end());
diff --git a/clang/lib/AST/ASTImporterLookupTable.cpp 
b/clang/lib/AST/ASTImporterLookupTable.cpp
index 07d39dcee2583a..4ed3198d7ea62b 100644
--- a/clang/lib/AST/ASTImporterLookupTable.cpp
+++ b/clang/lib/AST/ASTImporterLookupTable.cpp
@@ -115,8 +115,9 @@ void ASTImporterLookupTable::remove(DeclContext *DC, 
NamedDecl *ND) {
 #ifndef NDEBUG
   if (!EraseResult) {
 std::string Message =
-llvm::formatv("Trying to remove not contained Decl '{0}' of type {1}",
-  Name.getAsString(), DC->getDeclKindName())
+llvm::formatv(
+"Trying to remove not contained Decl '{0}' of type {1} from a {2}",
+Name.getAsString(), ND->getDeclKindName(), DC->getDeclKindName())
 .str();
 llvm_unreachable(Message.c_str());
   }
@@ -125,18 +126,18 @@ void ASTImporterLookupTable::remove(DeclContext *DC, 
NamedDecl *ND) {
 
 void ASTImporterLookupTable::add(NamedDecl *ND) {
   assert(ND);
-  DeclContext *DC = ND->getDeclContext()->getPrimaryContext();
+  DeclContext *DC = ND->getDeclContext();
   add(DC, ND);
-  DeclContext *ReDC = DC->getRedeclContext()->getPrimaryContext();
+  DeclContext *ReDC = DC->getRedeclContext();
   if (DC != ReDC)
 add(ReDC, ND);
 }
 
 void ASTImporterLookupTable::remove(NamedDecl *ND) 

[clang] [clang][ASTImporter] Not using primary context in lookup table (PR #118466)

2024-12-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Balázs Kéri (balazske)


Changes

`ASTImporterLookupTable` did use the `getPrimaryContext` function to get the 
declaration context of the inserted items. This is problematic because the 
primary context can change during import of AST items, most likely if a 
definition of a previously not defined class is imported. (For any record the 
primary context is the definition if there is one.) The use of primary context 
is really not important, only for namespaces because these can be re-opened and 
lookup in one namespace block is not enough. This special search is now moved 
into ASTImporter instead of relying on the lookup table.

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


3 Files Affected:

- (modified) clang/lib/AST/ASTImporter.cpp (+21-3) 
- (modified) clang/lib/AST/ASTImporterLookupTable.cpp (+10-10) 
- (modified) clang/unittests/AST/ASTImporterTest.cpp (+150-2) 


``diff
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index a0cd57e2e5ee0d..34b2d8e3696df5 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -3165,6 +3165,7 @@ ExpectedDecl ASTNodeImporter::VisitRecordDecl(RecordDecl 
*D) {
 if (Error Err = ImportImplicitMethods(DCXX, FoundCXX))
   return std::move(Err);
 }
+return FoundDef;
   }
   PrevDecl = FoundRecord->getMostRecentDecl();
   break;
@@ -9052,9 +9053,26 @@ ASTImporter::findDeclsInToCtx(DeclContext *DC, 
DeclarationName Name) {
   // We can diagnose this only if we search in the redecl context.
   DeclContext *ReDC = DC->getRedeclContext();
   if (SharedState->getLookupTable()) {
-ASTImporterLookupTable::LookupResult LookupResult =
-SharedState->getLookupTable()->lookup(ReDC, Name);
-return FoundDeclsTy(LookupResult.begin(), LookupResult.end());
+if (ReDC->isNamespace()) {
+  // Namespaces can be reopened.
+  // Lookup table does not handle this, we must search here in all linked
+  // namespaces.
+  FoundDeclsTy Result;
+  SmallVector NSChain =
+  getCanonicalForwardRedeclChain(
+  dyn_cast(ReDC));
+  for (auto *D : NSChain) {
+ASTImporterLookupTable::LookupResult LookupResult =
+SharedState->getLookupTable()->lookup(dyn_cast(D),
+  Name);
+Result.append(LookupResult.begin(), LookupResult.end());
+  }
+  return Result;
+} else {
+  ASTImporterLookupTable::LookupResult LookupResult =
+  SharedState->getLookupTable()->lookup(ReDC, Name);
+  return FoundDeclsTy(LookupResult.begin(), LookupResult.end());
+}
   } else {
 DeclContext::lookup_result NoloadLookupResult = ReDC->noload_lookup(Name);
 FoundDeclsTy Result(NoloadLookupResult.begin(), NoloadLookupResult.end());
diff --git a/clang/lib/AST/ASTImporterLookupTable.cpp 
b/clang/lib/AST/ASTImporterLookupTable.cpp
index 07d39dcee2583a..4ed3198d7ea62b 100644
--- a/clang/lib/AST/ASTImporterLookupTable.cpp
+++ b/clang/lib/AST/ASTImporterLookupTable.cpp
@@ -115,8 +115,9 @@ void ASTImporterLookupTable::remove(DeclContext *DC, 
NamedDecl *ND) {
 #ifndef NDEBUG
   if (!EraseResult) {
 std::string Message =
-llvm::formatv("Trying to remove not contained Decl '{0}' of type {1}",
-  Name.getAsString(), DC->getDeclKindName())
+llvm::formatv(
+"Trying to remove not contained Decl '{0}' of type {1} from a {2}",
+Name.getAsString(), ND->getDeclKindName(), DC->getDeclKindName())
 .str();
 llvm_unreachable(Message.c_str());
   }
@@ -125,18 +126,18 @@ void ASTImporterLookupTable::remove(DeclContext *DC, 
NamedDecl *ND) {
 
 void ASTImporterLookupTable::add(NamedDecl *ND) {
   assert(ND);
-  DeclContext *DC = ND->getDeclContext()->getPrimaryContext();
+  DeclContext *DC = ND->getDeclContext();
   add(DC, ND);
-  DeclContext *ReDC = DC->getRedeclContext()->getPrimaryContext();
+  DeclContext *ReDC = DC->getRedeclContext();
   if (DC != ReDC)
 add(ReDC, ND);
 }
 
 void ASTImporterLookupTable::remove(NamedDecl *ND) {
   assert(ND);
-  DeclContext *DC = ND->getDeclContext()->getPrimaryContext();
+  DeclContext *DC = ND->getDeclContext();
   remove(DC, ND);
-  DeclContext *ReDC = DC->getRedeclContext()->getPrimaryContext();
+  DeclContext *ReDC = DC->getRedeclContext();
   if (DC != ReDC)
 remove(ReDC, ND);
 }
@@ -161,7 +162,7 @@ void ASTImporterLookupTable::updateForced(NamedDecl *ND, 
DeclContext *OldDC) {
 
 ASTImporterLookupTable::LookupResult
 ASTImporterLookupTable::lookup(DeclContext *DC, DeclarationName Name) const {
-  auto DCI = LookupTable.find(DC->getPrimaryContext());
+  auto DCI = LookupTable.find(DC);
   if (DCI == LookupTable.end())
 return {};
 
@@ -178,7 +179,7 @@ bool ASTImporterLookupTable::contains(DeclContext *DC, 
NamedDecl *ND) const {
 }
 
 void A

[clang-tools-extra] [clang-tidy] Add readability-use-span-first-last check (PR #118074)

2024-12-03 Thread Julian Schmidt via cfe-commits


@@ -0,0 +1,98 @@
+// RUN: %check_clang_tidy -std=c++20 %s readability-use-span-first-last %t
+
+namespace std {
+template 
+class span {
+  T* ptr;
+  __SIZE_TYPE__ len;
+
+public:
+  span(T* p, __SIZE_TYPE__ l) : ptr(p), len(l) {}
+  
+  span subspan(__SIZE_TYPE__ offset) const {
+return span(ptr + offset, len - offset);
+  }
+  
+  span subspan(__SIZE_TYPE__ offset, __SIZE_TYPE__ count) const {
+return span(ptr + offset, count);
+  }
+
+  span first(__SIZE_TYPE__ count) const {
+return span(ptr, count);
+  }
+
+  span last(__SIZE_TYPE__ count) const {
+return span(ptr + (len - count), count);
+  }
+
+  __SIZE_TYPE__ size() const { return len; }
+};
+} // namespace std
+
+void test() {
+  int arr[] = {1, 2, 3, 4, 5};
+  std::span s(arr, 5);
+
+  auto sub1 = s.subspan(0, 3);
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: prefer 'span::first()' over 
'subspan()'
+  // CHECK-FIXES: auto sub1 = s.first(3);
+
+  auto sub2 = s.subspan(s.size() - 2);
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: prefer 'span::last()' over 
'subspan()'
+  // CHECK-FIXES: auto sub2 = s.last(2);
+
+  __SIZE_TYPE__ n = 2;
+  auto sub3 = s.subspan(0, n);
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: prefer 'span::first()' over 
'subspan()'
+  // CHECK-FIXES: auto sub3 = s.first(n);
+
+  auto sub4 = s.subspan(1, 2);  // No warning
+  auto sub5 = s.subspan(2); // No warning
+
+
+#define ZERO 0
+#define TWO 2
+#define SIZE_MINUS(s, n) s.size() - n
+#define MAKE_SUBSPAN(obj, n) obj.subspan(0, n)
+#define MAKE_LAST_N(obj, n) obj.subspan(obj.size() - n)
+
+  auto sub6 = s.subspan(SIZE_MINUS(s, 2));
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: prefer 'span::last()' over 
'subspan()'
+  // CHECK-FIXES: auto sub6 = s.last(2);
+
+  auto sub7 = MAKE_SUBSPAN(s, 3);
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: prefer 'span::first()' over 
'subspan()'
+  // CHECK-FIXES: auto sub7 = s.first(3);
+
+  auto sub8 = MAKE_LAST_N(s, 2);
+  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: prefer 'span::last()' over 
'subspan()'
+  // CHECK-FIXES: auto sub8 = s.last(2);
+
+}
+
+template 
+void testTemplate() {
+  T arr[] = {1, 2, 3, 4, 5};
+  std::span s(arr, 5);
+
+  auto sub1 = s.subspan(0, 3);
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: prefer 'span::first()' over 
'subspan()'
+  // CHECK-FIXES: auto sub1 = s.first(3);
+
+  auto sub2 = s.subspan(s.size() - 2);
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: prefer 'span::last()' over 
'subspan()'
+  // CHECK-FIXES: auto sub2 = s.last(2);
+
+  __SIZE_TYPE__ n = 2;
+  auto sub3 = s.subspan(0, n);
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: prefer 'span::first()' over 
'subspan()'
+  // CHECK-FIXES: auto sub3 = s.first(n);
+
+  auto sub4 = s.subspan(1, 2);  // No warning
+  auto sub5 = s.subspan(2); // No warning
+}
+
+// Test instantiation
+void testInt() {
+  testTemplate();
+}

5chmidti wrote:

Missing newline

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


[clang-tools-extra] [clang-tidy] Add readability-use-span-first-last check (PR #118074)

2024-12-03 Thread Julian Schmidt via cfe-commits


@@ -0,0 +1,24 @@
+.. title:: clang-tidy - readability-use-span-first-last
+
+readability-use-span-first-last
+===
+
+Checks for uses of ``std::span::subspan()`` that can be replaced with clearer
+``first()`` or ``last()`` member functions. These dedicated methods were added 
+to C++20 to provide more expressive alternatives to common subspan operations.
+
+Covered scenarios:
+
+== 
+Expression Replacement
+- 
+``s.subspan(0, n)``   ``s.first(n)``
+``s.subspan(s.size() - n)`` ``s.last(n)``
+== 
+
+
+Non-zero offset with count (like ``subspan(1, n)``) or offset-only calls 
+(like ``subspan(n)``) have no clearer equivalent using ``first()`` or 
+``last()``, so these cases are not transformed.
+
+This check is only active when C++20 or later is used.

5chmidti wrote:

Missing newline

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


[clang-tools-extra] [clang-tidy] Add readability-use-span-first-last check (PR #118074)

2024-12-03 Thread Julian Schmidt via cfe-commits


@@ -0,0 +1,125 @@
+//===--- UseSpanFirstLastCheck.cpp - clang-tidy -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseSpanFirstLastCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+void UseSpanFirstLastCheck::registerMatchers(MatchFinder *Finder) {
+  // Match span::subspan calls
+  const auto HasSpanType =
+  hasType(hasUnqualifiedDesugaredType(recordType(hasDeclaration(
+  classTemplateSpecializationDecl(hasName("::std::span"));
+
+  Finder->addMatcher(cxxMemberCallExpr(callee(memberExpr(hasDeclaration(
+   
cxxMethodDecl(hasName("subspan"),
+   on(expr(HasSpanType)))
+ .bind("subspan"),
+ this);
+}
+
+void UseSpanFirstLastCheck::check(const MatchFinder::MatchResult &Result) {
+  const auto *Call = Result.Nodes.getNodeAs("subspan");
+  if (!Call)
+return;
+
+  handleSubspanCall(Result, Call);
+}
+
+void UseSpanFirstLastCheck::handleSubspanCall(
+const MatchFinder::MatchResult &Result, const CXXMemberCallExpr *Call) {
+  unsigned NumArgs = Call->getNumArgs();
+  if (NumArgs == 0 || NumArgs > 2)
+return;
+
+  const Expr *Offset = Call->getArg(0);
+  const Expr *Count = NumArgs > 1 ? Call->getArg(1) : nullptr;
+  auto &Context = *Result.Context;
+
+  class SubspanVisitor : public RecursiveASTVisitor {

5chmidti wrote:

(on mobile, so I can't check)

The visitor is overkill and will, most importantly, produce false positives: 
`s.subspan(0, 100 + (s.size() - n))`, because the visitor only searches for the 
specific pattern being contained in the arg, and not that it is actually the 
arg itself. It would be much cleaner to check this in the matcher: 
`anyOf(callExpr(has argument(0, integer literal(equals(0)).bind("zero_offset"), 
/*n arg*/), callExpr(/*size-n arg*/)`

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


[clang-tools-extra] [clang-tidy] Add readability-use-span-first-last check (PR #118074)

2024-12-03 Thread Julian Schmidt via cfe-commits


@@ -0,0 +1,125 @@
+//===--- UseSpanFirstLastCheck.cpp - clang-tidy -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseSpanFirstLastCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+void UseSpanFirstLastCheck::registerMatchers(MatchFinder *Finder) {
+  // Match span::subspan calls
+  const auto HasSpanType =
+  hasType(hasUnqualifiedDesugaredType(recordType(hasDeclaration(
+  classTemplateSpecializationDecl(hasName("::std::span"));
+
+  Finder->addMatcher(cxxMemberCallExpr(callee(memberExpr(hasDeclaration(
+   
cxxMethodDecl(hasName("subspan"),
+   on(expr(HasSpanType)))
+ .bind("subspan"),
+ this);
+}
+
+void UseSpanFirstLastCheck::check(const MatchFinder::MatchResult &Result) {
+  const auto *Call = Result.Nodes.getNodeAs("subspan");
+  if (!Call)
+return;
+
+  handleSubspanCall(Result, Call);
+}
+
+void UseSpanFirstLastCheck::handleSubspanCall(
+const MatchFinder::MatchResult &Result, const CXXMemberCallExpr *Call) {
+  unsigned NumArgs = Call->getNumArgs();
+  if (NumArgs == 0 || NumArgs > 2)
+return;
+
+  const Expr *Offset = Call->getArg(0);
+  const Expr *Count = NumArgs > 1 ? Call->getArg(1) : nullptr;
+  auto &Context = *Result.Context;
+
+  class SubspanVisitor : public RecursiveASTVisitor {
+  public:
+SubspanVisitor(const ASTContext &Context) : Context(Context) {}
+
+TraversalKind getTraversalKind() const {
+  return TK_IgnoreUnlessSpelledInSource;
+}
+
+bool VisitIntegerLiteral(IntegerLiteral *IL) {
+  if (IL->getValue() == 0)
+IsZeroOffset = true;
+  return true;
+}
+
+bool VisitBinaryOperator(BinaryOperator *BO) {
+  if (BO->getOpcode() == BO_Sub) {
+if (const auto *SizeCall = dyn_cast(BO->getLHS())) {
+  if (SizeCall->getMethodDecl()->getName() == "size") {
+IsSizeMinusN = true;
+SizeMinusArg = BO->getRHS();
+  }
+}
+  }
+  return true;
+}
+
+bool IsZeroOffset = false;
+bool IsSizeMinusN = false;
+const Expr *SizeMinusArg = nullptr;
+
+  private:
+const ASTContext &Context;
+  };
+
+  SubspanVisitor Visitor(Context);
+  Visitor.TraverseStmt(const_cast(Offset->IgnoreImpCasts()));
+
+  // Build replacement text
+  std::string Replacement;
+  if (Visitor.IsZeroOffset && Count) {
+// subspan(0, count) -> first(count)
+const StringRef CountStr = Lexer::getSourceText(
+CharSourceRange::getTokenRange(Count->getSourceRange()),
+Context.getSourceManager(), Context.getLangOpts());
+const auto *Base =
+cast(Call)->getImplicitObjectArgument();
+const StringRef BaseStr = Lexer::getSourceText(
+CharSourceRange::getTokenRange(Base->getSourceRange()),
+Context.getSourceManager(), Context.getLangOpts());
+Replacement = BaseStr.str() + ".first(" + CountStr.str() + ")";
+  } else if (Visitor.IsSizeMinusN && Visitor.SizeMinusArg) {
+// subspan(size() - n) -> last(n)
+const StringRef ArgStr = Lexer::getSourceText(
+CharSourceRange::getTokenRange(Visitor.SizeMinusArg->getSourceRange()),
+Context.getSourceManager(), Context.getLangOpts());
+const auto *Base =
+cast(Call)->getImplicitObjectArgument();

5chmidti wrote:

Same as above

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


[clang-tools-extra] [clang-tidy] Add readability-use-span-first-last check (PR #118074)

2024-12-03 Thread Julian Schmidt via cfe-commits


@@ -0,0 +1,125 @@
+//===--- UseSpanFirstLastCheck.cpp - clang-tidy -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseSpanFirstLastCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+void UseSpanFirstLastCheck::registerMatchers(MatchFinder *Finder) {
+  // Match span::subspan calls
+  const auto HasSpanType =
+  hasType(hasUnqualifiedDesugaredType(recordType(hasDeclaration(
+  classTemplateSpecializationDecl(hasName("::std::span"));
+
+  Finder->addMatcher(cxxMemberCallExpr(callee(memberExpr(hasDeclaration(
+   
cxxMethodDecl(hasName("subspan"),
+   on(expr(HasSpanType)))
+ .bind("subspan"),
+ this);
+}
+
+void UseSpanFirstLastCheck::check(const MatchFinder::MatchResult &Result) {
+  const auto *Call = Result.Nodes.getNodeAs("subspan");
+  if (!Call)
+return;
+
+  handleSubspanCall(Result, Call);
+}
+
+void UseSpanFirstLastCheck::handleSubspanCall(
+const MatchFinder::MatchResult &Result, const CXXMemberCallExpr *Call) {
+  unsigned NumArgs = Call->getNumArgs();
+  if (NumArgs == 0 || NumArgs > 2)
+return;
+
+  const Expr *Offset = Call->getArg(0);
+  const Expr *Count = NumArgs > 1 ? Call->getArg(1) : nullptr;
+  auto &Context = *Result.Context;
+
+  class SubspanVisitor : public RecursiveASTVisitor {
+  public:
+SubspanVisitor(const ASTContext &Context) : Context(Context) {}
+
+TraversalKind getTraversalKind() const {
+  return TK_IgnoreUnlessSpelledInSource;
+}
+
+bool VisitIntegerLiteral(IntegerLiteral *IL) {
+  if (IL->getValue() == 0)
+IsZeroOffset = true;
+  return true;
+}
+
+bool VisitBinaryOperator(BinaryOperator *BO) {
+  if (BO->getOpcode() == BO_Sub) {
+if (const auto *SizeCall = dyn_cast(BO->getLHS())) {
+  if (SizeCall->getMethodDecl()->getName() == "size") {
+IsSizeMinusN = true;
+SizeMinusArg = BO->getRHS();
+  }
+}
+  }
+  return true;
+}
+
+bool IsZeroOffset = false;
+bool IsSizeMinusN = false;
+const Expr *SizeMinusArg = nullptr;
+
+  private:
+const ASTContext &Context;
+  };
+
+  SubspanVisitor Visitor(Context);
+  Visitor.TraverseStmt(const_cast(Offset->IgnoreImpCasts()));
+
+  // Build replacement text
+  std::string Replacement;
+  if (Visitor.IsZeroOffset && Count) {
+// subspan(0, count) -> first(count)
+const StringRef CountStr = Lexer::getSourceText(
+CharSourceRange::getTokenRange(Count->getSourceRange()),
+Context.getSourceManager(), Context.getLangOpts());
+const auto *Base =
+cast(Call)->getImplicitObjectArgument();

5chmidti wrote:

`Call` is already a `CXXMemberCallExpr`

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


[clang] [Clang] Deleting an incomplete enum type is not an error (PR #118455)

2024-12-03 Thread Mariya Podchishchaeva via cfe-commits


@@ -540,6 +540,14 @@ namespace PR10504 {
   void f(A *x) { delete x; } // expected-warning {{delete called on 
'PR10504::A' that is abstract but has non-virtual destructor}}
 }
 
+#if __cplusplus >= 201103L
+enum GH99278_1 { // expected-note {{definition of 'GH99278_1' is not complete 
until the closing '}'}}
+zero = decltype(delete static_cast(nullptr), 0){}

Fznamznon wrote:

If deleting an incomplete enum was never UB, should the warning be emitted here 
at all?

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


[clang-tools-extra] [clang-tidy] Sync ContainerSizeEmptyCheck with container-size-empty doc (PR #118459)

2024-12-03 Thread Niels Dekker via cfe-commits

https://github.com/N-Dekker created 
https://github.com/llvm/llvm-project/pull/118459

Brought the class documentation in sync with the user documentation at 
container-size-empty.rst:

https://github.com/llvm/llvm-project/blob/bfb26202e05ee2932b4368b5fca607df01e8247f/clang-tools-extra/docs/clang-tidy/checks/readability/container-size-empty.rst#L7-L14

>From 3871b186e4ea0fbcc71c54ac4053256f5afa2289 Mon Sep 17 00:00:00 2001
From: Niels Dekker 
Date: Tue, 3 Dec 2024 11:02:59 +0100
Subject: [PATCH] [clang-tidy] Sync ContainerSizeEmptyCheck with
 container-size-empty doc

Brought the class documentation in sync with the user documentation at
clang-tools-extra/docs/clang-tidy/checks/readability/container-size-empty.rst
---
 .../clang-tidy/readability/ContainerSizeEmptyCheck.h  | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h 
b/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h
index acd8a6bfc50f5e..5f189b426f2413 100644
--- a/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h
@@ -18,10 +18,10 @@ namespace clang::tidy::readability {
 /// a call to `empty()`.
 ///
 /// The emptiness of a container should be checked using the `empty()` method
-/// instead of the `size()` method. It shows clearer intent to use `empty()`.
-/// Furthermore some containers may implement the `empty()` method but not
-/// implement the `size()` method. Using `empty()` whenever possible makes it
-/// easier to switch to another container in the future.
+/// instead of the `size()`/`length()` method. It shows clearer intent to use
+/// `empty()`. Furthermore some containers may implement the `empty()` method
+/// but not implement the `size()` or `length()` method. Using `empty()`
+/// whenever possible makes it easier to switch to another container in the 
future.
 class ContainerSizeEmptyCheck : public ClangTidyCheck {
 public:
   ContainerSizeEmptyCheck(StringRef Name, ClangTidyContext *Context);

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


[clang] [clang] Warn [[clang::lifetimebound]] misusages on types (PR #118281)

2024-12-03 Thread Maksim Ivanov via cfe-commits

emaxx-google wrote:

Thanks for the reviews! Please merge the PR (I don't have write access).

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


[clang-tools-extra] [clang-tidy] Sync ContainerSizeEmptyCheck with container-size-empty doc (PR #118459)

2024-12-03 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-tidy

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

Author: Niels Dekker (N-Dekker)


Changes

Brought the class documentation in sync with the user documentation at 
container-size-empty.rst:

https://github.com/llvm/llvm-project/blob/bfb26202e05ee2932b4368b5fca607df01e8247f/clang-tools-extra/docs/clang-tidy/checks/readability/container-size-empty.rst#L7-L14

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


1 Files Affected:

- (modified) clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h 
(+4-4) 


``diff
diff --git a/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h 
b/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h
index acd8a6bfc50f5e..5f189b426f2413 100644
--- a/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h
@@ -18,10 +18,10 @@ namespace clang::tidy::readability {
 /// a call to `empty()`.
 ///
 /// The emptiness of a container should be checked using the `empty()` method
-/// instead of the `size()` method. It shows clearer intent to use `empty()`.
-/// Furthermore some containers may implement the `empty()` method but not
-/// implement the `size()` method. Using `empty()` whenever possible makes it
-/// easier to switch to another container in the future.
+/// instead of the `size()`/`length()` method. It shows clearer intent to use
+/// `empty()`. Furthermore some containers may implement the `empty()` method
+/// but not implement the `size()` or `length()` method. Using `empty()`
+/// whenever possible makes it easier to switch to another container in the 
future.
 class ContainerSizeEmptyCheck : public ClangTidyCheck {
 public:
   ContainerSizeEmptyCheck(StringRef Name, ClangTidyContext *Context);

``




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


[clang] 4849d59 - [clang] Warn [[clang::lifetimebound]] misusages on types (#118281)

2024-12-03 Thread via cfe-commits

Author: Maksim Ivanov
Date: 2024-12-03T11:10:11+01:00
New Revision: 4849d593ab07c47f9f520bea636f62d159d57006

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

LOG: [clang] Warn [[clang::lifetimebound]] misusages on types (#118281)

Emit the "cannot be applied to types" warning instead of silently
ignoring the attribute when it's attempted to be used on a type (instead
of a function argument or the function definition).

Before this commit, the warning has been printed when the attribute was
(mis)used on a decl-specifier, but not in other places in a declarator.

Examples where the warning starts being emitted with this commit:

```
  int * [[clang::lifetimebound]] x;

  void f(int * [[clang::lifetimebound]] x);

  void g(int * [[clang::lifetimebound]]);
```

Note that the last example is the case of an unnamed function parameter.
While in theory Clang could've supported the `[[clang::lifetimebound]]`
analysis for unnamed parameters, it doesn't currently, so the commit at
least makes the situation better by highlighting this as a warning
instead of a silent ignore - which was reported at #96034.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaType.cpp
clang/test/SemaCXX/attr-lifetimebound.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 01c7899e36c932..4e4dcd83cc28ed 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -139,7 +139,7 @@ C++ Specific Potentially Breaking Changes
 // Fixed version:
 unsigned operator""_udl_name(unsigned long long);
 
-- Clang will now produce an error diagnostic when [[clang::lifetimebound]] is
+- Clang will now produce an error diagnostic when ``[[clang::lifetimebound]]`` 
is
   applied on a parameter or an implicit object parameter of a function that
   returns void. This was previously ignored and had no effect. (#GH107556)
 
@@ -148,6 +148,21 @@ C++ Specific Potentially Breaking Changes
 // Now diagnoses with an error.
 void f(int& i [[clang::lifetimebound]]);
 
+- Clang will now produce an error diagnostic when ``[[clang::lifetimebound]]``
+  is applied on a type (instead of a function parameter or an implicit object
+  parameter); this includes the case when the attribute is specified for an
+  unnamed function parameter. These were previously ignored and had no effect.
+  (#GH118281)
+
+  .. code-block:: c++
+
+// Now diagnoses with an error.
+int* [[clang::lifetimebound]] x;
+// Now diagnoses with an error.
+void f(int* [[clang::lifetimebound]] i);
+// Now diagnoses with an error.
+void g(int* [[clang::lifetimebound]]);
+
 - Clang now rejects all field accesses on null pointers in constant 
expressions. The following code
   used to work but will now be rejected:
 

diff  --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index f32edc5ac06440..75130436282fbd 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -8612,7 +8612,11 @@ static void HandleLifetimeBoundAttr(TypeProcessingState 
&State,
 CurType = State.getAttributedType(
 createSimpleAttr(State.getSema().Context, Attr),
 CurType, CurType);
+return;
   }
+  State.getSema().Diag(Attr.getLoc(), diag::err_attribute_wrong_decl_type_str)
+  << Attr << Attr.isRegularKeywordAttribute()
+  << "parameters and implicit object parameters";
 }
 
 static void HandleLifetimeCaptureByAttr(TypeProcessingState &State,

diff  --git a/clang/test/SemaCXX/attr-lifetimebound.cpp 
b/clang/test/SemaCXX/attr-lifetimebound.cpp
index f89b556f5bba08..c7abec61873efb 100644
--- a/clang/test/SemaCXX/attr-lifetimebound.cpp
+++ b/clang/test/SemaCXX/attr-lifetimebound.cpp
@@ -9,11 +9,25 @@ namespace usage_invalid {
 ~A() [[clang::lifetimebound]]; // expected-error {{cannot be applied to a 
destructor}}
 static int *static_class_member() [[clang::lifetimebound]]; // 
expected-error {{static member function has no implicit object parameter}}
 int *explicit_object(this A&) [[clang::lifetimebound]]; // expected-error 
{{explicit object member function has no implicit object parameter}}
-int not_function [[clang::lifetimebound]]; // expected-error {{only 
applies to parameters and implicit object parameters}}
-int [[clang::lifetimebound]] also_not_function; // expected-error {{cannot 
be applied to types}}
+int attr_on_var [[clang::lifetimebound]]; // expected-error {{only applies 
to parameters and implicit object parameters}}
+int [[clang::lifetimebound]] attr_on_int; // expected-error {{cannot be 
applied to types}}
+int * [[clang::lifetimebound]] attr_on_int_ptr; // expected-error 
{{'lifetimebound' attribute only applies to parameters and implicit object 
parameters}}
+in

[clang] [clang] Warn [[clang::lifetimebound]] misusages on types (PR #118281)

2024-12-03 Thread Haojian Wu via cfe-commits

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


[clang] [clang] Warn [[clang::lifetimebound]] misusages on types (PR #118281)

2024-12-03 Thread Haojian Wu via cfe-commits

hokein wrote:

> Thanks for the reviews! Please merge the PR (I don't have write access).

Done.

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


[clang] [clang] Warn [[clang::lifetimebound]] misusages on types (PR #118281)

2024-12-03 Thread via cfe-commits

github-actions[bot] wrote:



@emaxx-google Congratulations on having your first Pull Request (PR) merged 
into the LLVM Project!

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

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

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

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

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


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


[clang] [clang][bytecode] Handle __builtin_wcslen (PR #118446)

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

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

... just like strlen.

>From 652b93f0487d18fc9703c4bba623149c853f9540 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Tue, 3 Dec 2024 09:39:54 +0100
Subject: [PATCH] [clang][bytecode] Handle __builtin_wcslen

... just like strlen.
---
 clang/lib/AST/ByteCode/InterpBuiltin.cpp  |  4 +++-
 clang/test/AST/ByteCode/builtin-functions.cpp | 12 
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 8ff0fad0aa5a79..2da16608e26c43 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -243,7 +243,7 @@ static bool interp__builtin_strlen(InterpState &S, CodePtr 
OpPC,
   unsigned ID = Func->getBuiltinID();
   const Pointer &StrPtr = getParam(Frame, 0);
 
-  if (ID == Builtin::BIstrlen)
+  if (ID == Builtin::BIstrlen || ID == Builtin::BIwcslen)
 diagnoseNonConstexprBuiltin(S, OpPC, ID);
 
   if (!CheckArray(S, OpPC, StrPtr))
@@ -1857,6 +1857,8 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const 
Function *F,
 break;
   case Builtin::BI__builtin_strlen:
   case Builtin::BIstrlen:
+  case Builtin::BI__builtin_wcslen:
+  case Builtin::BIwcslen:
 if (!interp__builtin_strlen(S, OpPC, Frame, F, Call))
   return false;
 break;
diff --git a/clang/test/AST/ByteCode/builtin-functions.cpp 
b/clang/test/AST/ByteCode/builtin-functions.cpp
index b94adfa3ab36bd..d8c8d207fbc45f 100644
--- a/clang/test/AST/ByteCode/builtin-functions.cpp
+++ b/clang/test/AST/ByteCode/builtin-functions.cpp
@@ -7,6 +7,10 @@
 // RUN: %clang_cc1 -triple avr -std=c++20 -Wno-string-plus-int 
-fexperimental-new-constant-interpreter %s -verify=expected,both
 // RUN: %clang_cc1 -triple avr -std=c++20 -Wno-string-plus-int 
-verify=ref,both %s -Wno-constant-evaluated
 
+extern "C" {
+  typedef decltype(sizeof(int)) size_t;
+  extern size_t wcslen(const wchar_t *p);
+}
 
 namespace strcmp {
   constexpr char kFoobar[6] = {'f','o','o','b','a','r'};
@@ -85,6 +89,14 @@ constexpr const char *a = "foo\0quux";
   constexpr char d[] = { 'f', 'o', 'o' }; // no nul terminator.
   constexpr int bad = __builtin_strlen(d); // both-error {{constant 
expression}} \
// both-note {{one-past-the-end}}
+
+  constexpr int wn = __builtin_wcslen(L"hello");
+  static_assert(wn == 5);
+  constexpr int wm = wcslen(L"hello"); // both-error {{constant expression}} \
+   // both-note {{non-constexpr function 
'wcslen' cannot be used in a constant expression}}
+
+  int arr[3]; // both-note {{here}}
+  int wk = arr[wcslen(L"hello")]; // both-warning {{array index 5}}
 }
 
 namespace nan {

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


[clang-tools-extra] [NFC] Fix uninitialized scalar field in constructor. (PR #118324)

2024-12-03 Thread kadir çetinkaya via cfe-commits

kadircet wrote:

idxcontents is only used when we have a set of file names available. hence this 
was only set via relevant constructors and rest of the runtime doesn't use the 
field.

but we don't construct tons of new index instances every second. so it's 
totally fine to just initialize them to `none`

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


[clang] [Clang] Allow LibBuiltins with placeholder return types to be called (PR #101702)

2024-12-03 Thread via cfe-commits

cor3ntin wrote:

@MitalAshok ping

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


[clang-tools-extra] [clang-tidy] ignore `[[clang::lifetimebound]]` param in return-const-ref-from-parameter (PR #118315)

2024-12-03 Thread Julian Schmidt via cfe-commits


@@ -38,3 +29,21 @@ Example
 
   const S& s = fn(S{1});
   s.v; // use after free
+
+
+This issue can be resolved by declaring an overload of the problematic function
+where the ``const &`` parameter is instead declared as ``&&``. The developer 
has
+to ensure that the implementation of that function does not produce a
+use-after-free, the exact error that this check is warning against.
+Marking such an ``&&`` overload as ``deleted``, will silence the warning as 
+well. In the case of different ``const &`` parameters being returned depending
+on the control flow of the function, an overload where all problematic
+``const &`` parameters have been declared as ``&&`` will resolve the issue.
+
+This issue can also be resolved by adding ``[[clang::lifetimebound]]`` and
+enabling ``-Wdangling`` in clang. See `lifetimebound 
attribute`_
+for details.

5chmidti wrote:

Even better, thanks.

`clang` -> `Clang`
and also please mention that it is enabled by default.

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


[clang] [clang][bytecode] Handle __builtin_wcslen (PR #118446)

2024-12-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

... just like strlen.

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


2 Files Affected:

- (modified) clang/lib/AST/ByteCode/InterpBuiltin.cpp (+3-1) 
- (modified) clang/test/AST/ByteCode/builtin-functions.cpp (+12) 


``diff
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 8ff0fad0aa5a79..2da16608e26c43 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -243,7 +243,7 @@ static bool interp__builtin_strlen(InterpState &S, CodePtr 
OpPC,
   unsigned ID = Func->getBuiltinID();
   const Pointer &StrPtr = getParam(Frame, 0);
 
-  if (ID == Builtin::BIstrlen)
+  if (ID == Builtin::BIstrlen || ID == Builtin::BIwcslen)
 diagnoseNonConstexprBuiltin(S, OpPC, ID);
 
   if (!CheckArray(S, OpPC, StrPtr))
@@ -1857,6 +1857,8 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const 
Function *F,
 break;
   case Builtin::BI__builtin_strlen:
   case Builtin::BIstrlen:
+  case Builtin::BI__builtin_wcslen:
+  case Builtin::BIwcslen:
 if (!interp__builtin_strlen(S, OpPC, Frame, F, Call))
   return false;
 break;
diff --git a/clang/test/AST/ByteCode/builtin-functions.cpp 
b/clang/test/AST/ByteCode/builtin-functions.cpp
index b94adfa3ab36bd..d8c8d207fbc45f 100644
--- a/clang/test/AST/ByteCode/builtin-functions.cpp
+++ b/clang/test/AST/ByteCode/builtin-functions.cpp
@@ -7,6 +7,10 @@
 // RUN: %clang_cc1 -triple avr -std=c++20 -Wno-string-plus-int 
-fexperimental-new-constant-interpreter %s -verify=expected,both
 // RUN: %clang_cc1 -triple avr -std=c++20 -Wno-string-plus-int 
-verify=ref,both %s -Wno-constant-evaluated
 
+extern "C" {
+  typedef decltype(sizeof(int)) size_t;
+  extern size_t wcslen(const wchar_t *p);
+}
 
 namespace strcmp {
   constexpr char kFoobar[6] = {'f','o','o','b','a','r'};
@@ -85,6 +89,14 @@ constexpr const char *a = "foo\0quux";
   constexpr char d[] = { 'f', 'o', 'o' }; // no nul terminator.
   constexpr int bad = __builtin_strlen(d); // both-error {{constant 
expression}} \
// both-note {{one-past-the-end}}
+
+  constexpr int wn = __builtin_wcslen(L"hello");
+  static_assert(wn == 5);
+  constexpr int wm = wcslen(L"hello"); // both-error {{constant expression}} \
+   // both-note {{non-constexpr function 
'wcslen' cannot be used in a constant expression}}
+
+  int arr[3]; // both-note {{here}}
+  int wk = arr[wcslen(L"hello")]; // both-warning {{array index 5}}
 }
 
 namespace nan {

``




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


[clang] 46446bb - [clang][bytecode][NFC] Diagnose non-constexpr builtin strcmp calls (#118442)

2024-12-03 Thread via cfe-commits

Author: Timm Baeder
Date: 2024-12-03T09:49:26+01:00
New Revision: 46446bb2d31a7e3b2f857613b190150d41734696

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

LOG: [clang][bytecode][NFC] Diagnose non-constexpr builtin strcmp calls 
(#118442)

Added: 


Modified: 
clang/lib/AST/ByteCode/InterpBuiltin.cpp

Removed: 




diff  --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index f3024dc3e26fe1..8ff0fad0aa5a79 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -148,6 +148,17 @@ static bool retPrimValue(InterpState &S, CodePtr OpPC,
 #undef RET_CASE
 }
 
+static void diagnoseNonConstexprBuiltin(InterpState &S, CodePtr OpPC,
+unsigned ID) {
+  auto Loc = S.Current->getSource(OpPC);
+  if (S.getLangOpts().CPlusPlus11)
+S.CCEDiag(Loc, diag::note_constexpr_invalid_function)
+<< /*isConstexpr=*/0 << /*isConstructor=*/0
+<< ("'" + S.getASTContext().BuiltinInfo.getName(ID) + "'").str();
+  else
+S.CCEDiag(Loc, diag::note_invalid_subexpr_in_const_expr);
+}
+
 static bool interp__builtin_is_constant_evaluated(InterpState &S, CodePtr OpPC,
   const InterpFrame *Frame,
   const CallExpr *Call) {
@@ -181,10 +192,14 @@ static bool 
interp__builtin_is_constant_evaluated(InterpState &S, CodePtr OpPC,
 
 static bool interp__builtin_strcmp(InterpState &S, CodePtr OpPC,
const InterpFrame *Frame,
-   const CallExpr *Call) {
+   const Function *Func, const CallExpr *Call) 
{
+  unsigned ID = Func->getBuiltinID();
   const Pointer &A = getParam(Frame, 0);
   const Pointer &B = getParam(Frame, 1);
 
+  if (ID == Builtin::BIstrcmp)
+diagnoseNonConstexprBuiltin(S, OpPC, ID);
+
   if (!CheckLive(S, OpPC, A, AK_Read) || !CheckLive(S, OpPC, B, AK_Read))
 return false;
 
@@ -222,16 +237,6 @@ static bool interp__builtin_strcmp(InterpState &S, CodePtr 
OpPC,
   return true;
 }
 
-static void diagnoseNonConstexprBuiltin(InterpState &S, CodePtr OpPC,
-unsigned ID) {
-  auto Loc = S.Current->getSource(OpPC);
-  if (S.getLangOpts().CPlusPlus11)
-S.CCEDiag(Loc, diag::note_constexpr_invalid_function)
-<< /*isConstexpr=*/0 << /*isConstructor=*/0
-<< ("'" + S.getASTContext().BuiltinInfo.getName(ID) + "'").str();
-  else
-S.CCEDiag(Loc, diag::note_invalid_subexpr_in_const_expr);
-}
 static bool interp__builtin_strlen(InterpState &S, CodePtr OpPC,
const InterpFrame *Frame,
const Function *Func, const CallExpr *Call) 
{
@@ -1846,7 +1851,8 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const 
Function *F,
   case Builtin::BI__assume:
 break;
   case Builtin::BI__builtin_strcmp:
-if (!interp__builtin_strcmp(S, OpPC, Frame, Call))
+  case Builtin::BIstrcmp:
+if (!interp__builtin_strcmp(S, OpPC, Frame, F, Call))
   return false;
 break;
   case Builtin::BI__builtin_strlen:



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


[clang] [Clang][OpenCL][AMDGPU] Allow a kernel to call another kernel (PR #115821)

2024-12-03 Thread John McCall via cfe-commits


@@ -1085,8 +1085,10 @@ llvm::Value *CodeGenFunction::EmitBlockLiteral(const 
CGBlockInfo &blockInfo) {
   blockAddr.getPointer(), 
ConvertType(blockInfo.getBlockExpr()->getType()));
 
   if (IsOpenCL) {
-CGM.getOpenCLRuntime().recordBlockInfo(blockInfo.BlockExpression, InvokeFn,
-   result, blockInfo.StructureType);
+CGM.getOpenCLRuntime().recordBlockInfo(
+blockInfo.BlockExpression, InvokeFn, result, blockInfo.StructureType,
+CurGD && CurGD.isDeclOpenCLKernel() &&
+(CurGD.getKernelReferenceKind() == KernelReferenceKind::Kernel));

rjmccall wrote:

That's one of the options, yeah. You'd always emit stubs as directly calling 
their kernels (so `_clang_ocl_kern_imp_caller_kern` would actually just call 
`caller_kern`, at least coming out of IRGen), and then you'd let LLVM decide 
when and whether to inline. The main disadvantage is that there might not 
already be code to emit calls to kernels; I imagine that's normally only done 
by the OpenCL runtime, and the ABI is probably pretty different from the normal 
call ABI.  But maybe that's not a big deal.

The second option is that you could emit stubs by making sure the kernel is 
emitted first and then directly cloning the kernel body into the stub.  Whether 
this is materially different from just inlining, I don't know, but it's an 
option. We do have code for this sort of thing already — we need it for 
emitting virtual varargs thunks in C++.

The third option is that you could emit kernels as directly calling their 
stubs. The advantage here is that all the calls are just normal calls that you 
definitely already have code to handle. The disadvantage is that you'd always 
be forcing the stub to be emitted, even in the 99% case that there are no other 
uses of it. It'll probably get reliably inlined away, but still, it's burning 
some extra compile time.

The last option is that you could emit kernels by emitting the stub and then 
directly cloning the function body into the kernel.

Up to you; they all have trade-offs. But I do think you need to not double-emit 
the kernel body.

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


[clang] dd2b2b8 - [clang][HLSL] Add GroupMemoryBarrierWithGroupSync intrinsic (#111883)

2024-12-03 Thread via cfe-commits

Author: Adam Yang
Date: 2024-12-03T01:16:49-08:00
New Revision: dd2b2b8bbbf4e917a84efe94cbeaaab2ed350fc9

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

LOG: [clang][HLSL] Add GroupMemoryBarrierWithGroupSync intrinsic (#111883)

partially fixes #70103 

### Changes
* Implemented `GroupMemoryBarrierWithGroupSync` clang builtin
* Linked `GroupMemoryBarrierWithGroupSync` clang builtin with
`hlsl_intrinsics.h`
* Added sema checks for `GroupMemoryBarrierWithGroupSync` to
`CheckHLSLBuiltinFunctionCall` in
`SemaChecking.cpp`
* Add codegen for `GroupMemoryBarrierWithGroupSync` to
`EmitHLSLBuiltinExpr` in `CGBuiltin.cpp`
* Add codegen tests to
`clang/test/CodeGenHLSL/builtins/GroupMemoryBarrierWithGroupSync.hlsl`
* Add sema tests to
`clang/test/SemaHLSL/BuiltIns/GroupMemoryBarrierWithGroupSync-errors.hlsl`

### Related PRs
* [[DXIL] Add GroupMemoryBarrierWithGroupSync intrinsic
#111884](https://github.com/llvm/llvm-project/pull/111884)
* [[SPIRV] Add GroupMemoryBarrierWithGroupSync intrinsic
#111888](https://github.com/llvm/llvm-project/pull/111888)

Added: 
clang/test/CodeGenHLSL/builtins/GroupMemoryBarrierWithGroupSync.hlsl
clang/test/SemaHLSL/BuiltIns/GroupMemoryBarrierWithGroupSync-errors.hlsl

Modified: 
clang/include/clang/Basic/Builtins.td
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/CodeGen/CGHLSLRuntime.h
clang/lib/Headers/hlsl/hlsl_intrinsics.h

Removed: 




diff  --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index dda44f3abe0160..e2c3d3c535571c 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4930,6 +4930,12 @@ def HLSLClip: LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void(...)";
 }
 
+def HLSLGroupMemoryBarrierWithGroupSync: LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_group_memory_barrier_with_group_sync"];
+  let Attributes = [NoThrow, Const];
+  let Prototype = "void()";
+}
+
 // 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 a54dd884c7fa5c..7588f8427cdd38 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -19456,6 +19456,12 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
 assert(E->getArg(0)->getType()->hasFloatingRepresentation() &&
"clip operands types mismatch");
 return handleHlslClip(E, this);
+  case Builtin::BI__builtin_hlsl_group_memory_barrier_with_group_sync: {
+Intrinsic::ID ID =
+CGM.getHLSLRuntime().getGroupMemoryBarrierWithGroupSyncIntrinsic();
+return EmitRuntimeCall(
+Intrinsic::getOrInsertDeclaration(&CGM.getModule(), ID));
+  }
   }
   return nullptr;
 }

diff  --git a/clang/lib/CodeGen/CGHLSLRuntime.h 
b/clang/lib/CodeGen/CGHLSLRuntime.h
index 854214d6bc0677..bb120c8b5e9e60 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.h
+++ b/clang/lib/CodeGen/CGHLSLRuntime.h
@@ -103,6 +103,8 @@ class CGHLSLRuntime {
 
   GENERATE_HLSL_INTRINSIC_FUNCTION(CreateHandleFromBinding, handle_fromBinding)
   GENERATE_HLSL_INTRINSIC_FUNCTION(BufferUpdateCounter, bufferUpdateCounter)
+  GENERATE_HLSL_INTRINSIC_FUNCTION(GroupMemoryBarrierWithGroupSync,
+   group_memory_barrier_with_group_sync)
 
   
//===--===//
   // End of reserved area for HLSL intrinsic getters.

diff  --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index a3e0b5c65a6f52..1126e13600f8af 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -2481,5 +2481,17 @@ float3 radians(float3);
 _HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_radians)
 float4 radians(float4);
 
+//===--===//
+// GroupMemoryBarrierWithGroupSync builtins
+//===--===//
+
+/// \fn void GroupMemoryBarrierWithGroupSync(void)
+/// \brief Blocks execution of all threads in a group until all group shared
+/// accesses have been completed and all threads in the group have reached this
+/// call.
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_group_memory_barrier_with_group_sync)
+void GroupMemoryBarrierWithGroupSync(void);
+
 } // namespace hlsl
 #endif //_HLSL_HLSL_INTRINSICS_H_

diff  --git 
a/clang/test/CodeGenHLSL/builtins/GroupMemoryBarrierWithGroupSync.hlsl 
b/clang/test/CodeGenHLSL/builtins/GroupMemoryBarrierWithGroupSync.hlsl
new file mode 100644
index 00..9d95d54852c0be
--- /dev/null
+++ b/clang/test/CodeGenHLSL/builtins/GroupMemoryBarrierWithGroupSync.hlsl
@@ -0,0 +1,2

[clang] [clang][HLSL] Add GroupMemoryBarrierWithGroupSync intrinsic (PR #111883)

2024-12-03 Thread Adam Yang via cfe-commits

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


[clang] 89a0ee8 - [clang][bytecode] Handle __builtin_wcslen (#118446)

2024-12-03 Thread via cfe-commits

Author: Timm Baeder
Date: 2024-12-03T10:20:30+01:00
New Revision: 89a0ee89973c3d213c4bc11c26b41eab67e06da0

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

LOG: [clang][bytecode] Handle __builtin_wcslen (#118446)

... just like strlen.

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 8ff0fad0aa5a79..2da16608e26c43 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -243,7 +243,7 @@ static bool interp__builtin_strlen(InterpState &S, CodePtr 
OpPC,
   unsigned ID = Func->getBuiltinID();
   const Pointer &StrPtr = getParam(Frame, 0);
 
-  if (ID == Builtin::BIstrlen)
+  if (ID == Builtin::BIstrlen || ID == Builtin::BIwcslen)
 diagnoseNonConstexprBuiltin(S, OpPC, ID);
 
   if (!CheckArray(S, OpPC, StrPtr))
@@ -1857,6 +1857,8 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const 
Function *F,
 break;
   case Builtin::BI__builtin_strlen:
   case Builtin::BIstrlen:
+  case Builtin::BI__builtin_wcslen:
+  case Builtin::BIwcslen:
 if (!interp__builtin_strlen(S, OpPC, Frame, F, Call))
   return false;
 break;

diff  --git a/clang/test/AST/ByteCode/builtin-functions.cpp 
b/clang/test/AST/ByteCode/builtin-functions.cpp
index b94adfa3ab36bd..d8c8d207fbc45f 100644
--- a/clang/test/AST/ByteCode/builtin-functions.cpp
+++ b/clang/test/AST/ByteCode/builtin-functions.cpp
@@ -7,6 +7,10 @@
 // RUN: %clang_cc1 -triple avr -std=c++20 -Wno-string-plus-int 
-fexperimental-new-constant-interpreter %s -verify=expected,both
 // RUN: %clang_cc1 -triple avr -std=c++20 -Wno-string-plus-int 
-verify=ref,both %s -Wno-constant-evaluated
 
+extern "C" {
+  typedef decltype(sizeof(int)) size_t;
+  extern size_t wcslen(const wchar_t *p);
+}
 
 namespace strcmp {
   constexpr char kFoobar[6] = {'f','o','o','b','a','r'};
@@ -85,6 +89,14 @@ constexpr const char *a = "foo\0quux";
   constexpr char d[] = { 'f', 'o', 'o' }; // no nul terminator.
   constexpr int bad = __builtin_strlen(d); // both-error {{constant 
expression}} \
// both-note {{one-past-the-end}}
+
+  constexpr int wn = __builtin_wcslen(L"hello");
+  static_assert(wn == 5);
+  constexpr int wm = wcslen(L"hello"); // both-error {{constant expression}} \
+   // both-note {{non-constexpr function 
'wcslen' cannot be used in a constant expression}}
+
+  int arr[3]; // both-note {{here}}
+  int wk = arr[wcslen(L"hello")]; // both-warning {{array index 5}}
 }
 
 namespace nan {



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


[clang] [clang][bytecode] Handle __builtin_wcslen (PR #118446)

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

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


[clang-tools-extra] [clang-tidy] Sync ContainerSizeEmptyCheck with container-size-empty doc (PR #118459)

2024-12-03 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 2526d5b1689389da9b194b5ec2878cfb2f4aca93 
3871b186e4ea0fbcc71c54ac4053256f5afa2289 --extensions h -- 
clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h
``





View the diff from clang-format here.


``diff
diff --git a/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h 
b/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h
index 5f189b426f..3aa4bdc496 100644
--- a/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h
@@ -21,7 +21,8 @@ namespace clang::tidy::readability {
 /// instead of the `size()`/`length()` method. It shows clearer intent to use
 /// `empty()`. Furthermore some containers may implement the `empty()` method
 /// but not implement the `size()` or `length()` method. Using `empty()`
-/// whenever possible makes it easier to switch to another container in the 
future.
+/// whenever possible makes it easier to switch to another container in the
+/// future.
 class ContainerSizeEmptyCheck : public ClangTidyCheck {
 public:
   ContainerSizeEmptyCheck(StringRef Name, ClangTidyContext *Context);

``




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


[clang-tools-extra] [clang-tidy] Sync ContainerSizeEmptyCheck with container-size-empty doc (PR #118459)

2024-12-03 Thread Carlos Galvez via cfe-commits

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


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


[clang] [clang][bytecode] Reject memcpy dummy pointers after null check (PR #118460)

2024-12-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

To match the diagnostic output of the current interpreter.

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


2 Files Affected:

- (modified) clang/lib/AST/ByteCode/InterpBuiltin.cpp (+4-3) 
- (modified) clang/test/AST/ByteCode/builtin-functions.cpp (+4) 


``diff
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index c5473322ecb280..b788656f9484fc 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -1813,9 +1813,6 @@ static bool interp__builtin_memcpy(InterpState &S, 
CodePtr OpPC,
 
   bool Move = (ID == Builtin::BI__builtin_memmove || ID == Builtin::BImemmove);
 
-  if (DestPtr.isDummy() || SrcPtr.isDummy())
-return false;
-
   // If the size is zero, we treat this as always being a valid no-op.
   if (Size.isZero()) {
 S.Stk.push(DestPtr);
@@ -1830,6 +1827,10 @@ static bool interp__builtin_memcpy(InterpState &S, 
CodePtr OpPC,
 return false;
   }
 
+  // As a last resort, reject dummy pointers.
+  if (DestPtr.isDummy() || SrcPtr.isDummy())
+return false;
+
   if (!DoBitCastPtr(S, OpPC, SrcPtr, DestPtr))
 return false;
 
diff --git a/clang/test/AST/ByteCode/builtin-functions.cpp 
b/clang/test/AST/ByteCode/builtin-functions.cpp
index 211ca6e164cbfb..b951c04dde5980 100644
--- a/clang/test/AST/ByteCode/builtin-functions.cpp
+++ b/clang/test/AST/ByteCode/builtin-functions.cpp
@@ -1169,6 +1169,10 @@ namespace BuiltinMemcpy {
   static_assert(__builtin_memcpy(null_incomplete, null_incomplete, 
sizeof(wchar_t))); // both-error {{not an integral constant expression}} \

   // both-note {{source of 'memcpy' is nullptr}}
 
+  wchar_t global;
+  constexpr wchar_t *null = 0;
+  static_assert(__builtin_memcpy(&global, null, sizeof(wchar_t))); // 
both-error {{not an integral constant expression}} \
+   // 
both-note {{source of 'memcpy' is nullptr}}
 
   constexpr int simpleMove() {
 int a = 12;

``




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


[clang] [clang][bytecode] Reject memcpy dummy pointers after null check (PR #118460)

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

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

To match the diagnostic output of the current interpreter.

>From b98163a979e323e05791c866e53cfb9a977fda52 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Tue, 3 Dec 2024 11:14:37 +0100
Subject: [PATCH] [clang][bytecode] Reject memcpy dummy pointers after null
 check

To match the diagnostic output of the current interpreter.
---
 clang/lib/AST/ByteCode/InterpBuiltin.cpp  | 7 ---
 clang/test/AST/ByteCode/builtin-functions.cpp | 4 
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index c5473322ecb280..b788656f9484fc 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -1813,9 +1813,6 @@ static bool interp__builtin_memcpy(InterpState &S, 
CodePtr OpPC,
 
   bool Move = (ID == Builtin::BI__builtin_memmove || ID == Builtin::BImemmove);
 
-  if (DestPtr.isDummy() || SrcPtr.isDummy())
-return false;
-
   // If the size is zero, we treat this as always being a valid no-op.
   if (Size.isZero()) {
 S.Stk.push(DestPtr);
@@ -1830,6 +1827,10 @@ static bool interp__builtin_memcpy(InterpState &S, 
CodePtr OpPC,
 return false;
   }
 
+  // As a last resort, reject dummy pointers.
+  if (DestPtr.isDummy() || SrcPtr.isDummy())
+return false;
+
   if (!DoBitCastPtr(S, OpPC, SrcPtr, DestPtr))
 return false;
 
diff --git a/clang/test/AST/ByteCode/builtin-functions.cpp 
b/clang/test/AST/ByteCode/builtin-functions.cpp
index 211ca6e164cbfb..b951c04dde5980 100644
--- a/clang/test/AST/ByteCode/builtin-functions.cpp
+++ b/clang/test/AST/ByteCode/builtin-functions.cpp
@@ -1169,6 +1169,10 @@ namespace BuiltinMemcpy {
   static_assert(__builtin_memcpy(null_incomplete, null_incomplete, 
sizeof(wchar_t))); // both-error {{not an integral constant expression}} \

   // both-note {{source of 'memcpy' is nullptr}}
 
+  wchar_t global;
+  constexpr wchar_t *null = 0;
+  static_assert(__builtin_memcpy(&global, null, sizeof(wchar_t))); // 
both-error {{not an integral constant expression}} \
+   // 
both-note {{source of 'memcpy' is nullptr}}
 
   constexpr int simpleMove() {
 int a = 12;

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


[clang] [clang] Fix a crash issue that caused by handling of fields with initializers in nested anonymous unions (PR #113049)

2024-12-03 Thread Haojian Wu via cfe-commits

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


[clang] 0f4dc42 - [clang][bytecode] Initialize elements in __builtin_elementwise_popcount (#118457)

2024-12-03 Thread via cfe-commits

Author: Timm Baeder
Date: 2024-12-03T11:14:06+01:00
New Revision: 0f4dc4276f8dd5c5e33c22096612702ede3c81ed

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

LOG: [clang][bytecode] Initialize elements in __builtin_elementwise_popcount 
(#118457)

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 2da16608e26c43..c5473322ecb280 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -1791,6 +1791,7 @@ static bool 
interp__builtin_elementwise_popcount(InterpState &S, CodePtr OpPC,
 INT_TYPE_SWITCH_NO_BOOL(ElemT, {
   Dst.atIndex(I).deref() =
   T::from(Arg.atIndex(I).deref().toAPSInt().popcount());
+  Dst.atIndex(I).initialize();
 });
   }
 

diff  --git a/clang/test/AST/ByteCode/builtin-functions.cpp 
b/clang/test/AST/ByteCode/builtin-functions.cpp
index d8c8d207fbc45f..211ca6e164cbfb 100644
--- a/clang/test/AST/ByteCode/builtin-functions.cpp
+++ b/clang/test/AST/ByteCode/builtin-functions.cpp
@@ -7,6 +7,14 @@
 // RUN: %clang_cc1 -triple avr -std=c++20 -Wno-string-plus-int 
-fexperimental-new-constant-interpreter %s -verify=expected,both
 // RUN: %clang_cc1 -triple avr -std=c++20 -Wno-string-plus-int 
-verify=ref,both %s -Wno-constant-evaluated
 
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+#define LITTLE_END 1
+#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+#define LITTLE_END 0
+#else
+#error "huh?"
+#endif
+
 extern "C" {
   typedef decltype(sizeof(int)) size_t;
   extern size_t wcslen(const wchar_t *p);
@@ -1140,6 +1148,10 @@ namespace ElementwisePopcount {
   static_assert(__builtin_elementwise_popcount(0L) == 0);
   static_assert(__builtin_elementwise_popcount(0xF0F0L) == 8);
   static_assert(__builtin_elementwise_popcount(~0LL) == 8 * sizeof(long long));
+
+#if __INT_WIDTH__ == 32
+  static_assert(__builtin_bit_cast(unsigned, 
__builtin_elementwise_popcount((vector4char){1, 2, 3, 4})) == (LITTLE_END ? 
0x01020101 : 0x01010201));
+#endif
 }
 
 namespace BuiltinMemcpy {



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


[libclc] [libcxx] [llvm] [openmp] [polly] [llvm] Move sub-project lead maintainers into their own Maintainers.md files (PR #118309)

2024-12-03 Thread Fraser Cormack via cfe-commits

frasercrmck wrote:


> For libclc maybe @tstellar -> @frasercrmck (or maybe both).

I'm not opposed to this if people think it suitable. But having someone from 
Red Hat or AMD as co-maintainer(s) makes sense to me, as it's a project used 
(downstream) by several different groups.

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


[clang] [clang][bytecode] Initialize elements in __builtin_elementwise_popcount (PR #118457)

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

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


[clang] [clang] Fix a crash issue that caused by handling of fields with initializers in nested anonymous unions (PR #113049)

2024-12-03 Thread Haojian Wu via cfe-commits

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


[clang] [clang] Fix a crash issue that caused by handling of fields with initializers in nested anonymous unions (PR #113049)

2024-12-03 Thread Haojian Wu via cfe-commits


@@ -750,6 +750,18 @@ void InitListChecker::FillInEmptyInitForField(unsigned 
Init, FieldDecl *Field,
 if (Field->hasInClassInitializer()) {
   if (VerifyOnly)
 return;
+
+  // We do not want to aggressively set the hadError flag and cutoff
+  // parsing. Try to recover when in-class-initializer is a RecoveryExpr.
+  if (isa_and_nonnull(Field->getInClassInitializer())) {

hokein wrote:

It is unclear to me why we need to check the specific `RecoveryExpr`? Can we 
just use the `Field->getInClassInitializer()->containsErrors()`?

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


[clang] [clang] Fix a crash issue that caused by handling of fields with initializers in nested anonymous unions (PR #113049)

2024-12-03 Thread Haojian Wu via cfe-commits

https://github.com/hokein commented:

Is the PR description still update-to-date? 

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


[clang] 356df2d - Revert "[clang] Warn [[clang::lifetimebound]] misusages on types (#118281)"

2024-12-03 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2024-12-03T12:13:13+01:00
New Revision: 356df2dd72e8299b5de58e9390283110c19f7c76

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

LOG: Revert "[clang] Warn [[clang::lifetimebound]] misusages on types (#118281)"

Temporarily revert the patch to give downstream teams some time to clean up 
their codebases.

This reverts commit 4849d593ab07c47f9f520bea636f62d159d57006.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaType.cpp
clang/test/SemaCXX/attr-lifetimebound.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4e4dcd83cc28ed..01c7899e36c932 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -139,7 +139,7 @@ C++ Specific Potentially Breaking Changes
 // Fixed version:
 unsigned operator""_udl_name(unsigned long long);
 
-- Clang will now produce an error diagnostic when ``[[clang::lifetimebound]]`` 
is
+- Clang will now produce an error diagnostic when [[clang::lifetimebound]] is
   applied on a parameter or an implicit object parameter of a function that
   returns void. This was previously ignored and had no effect. (#GH107556)
 
@@ -148,21 +148,6 @@ C++ Specific Potentially Breaking Changes
 // Now diagnoses with an error.
 void f(int& i [[clang::lifetimebound]]);
 
-- Clang will now produce an error diagnostic when ``[[clang::lifetimebound]]``
-  is applied on a type (instead of a function parameter or an implicit object
-  parameter); this includes the case when the attribute is specified for an
-  unnamed function parameter. These were previously ignored and had no effect.
-  (#GH118281)
-
-  .. code-block:: c++
-
-// Now diagnoses with an error.
-int* [[clang::lifetimebound]] x;
-// Now diagnoses with an error.
-void f(int* [[clang::lifetimebound]] i);
-// Now diagnoses with an error.
-void g(int* [[clang::lifetimebound]]);
-
 - Clang now rejects all field accesses on null pointers in constant 
expressions. The following code
   used to work but will now be rejected:
 

diff  --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 75130436282fbd..f32edc5ac06440 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -8612,11 +8612,7 @@ static void HandleLifetimeBoundAttr(TypeProcessingState 
&State,
 CurType = State.getAttributedType(
 createSimpleAttr(State.getSema().Context, Attr),
 CurType, CurType);
-return;
   }
-  State.getSema().Diag(Attr.getLoc(), diag::err_attribute_wrong_decl_type_str)
-  << Attr << Attr.isRegularKeywordAttribute()
-  << "parameters and implicit object parameters";
 }
 
 static void HandleLifetimeCaptureByAttr(TypeProcessingState &State,

diff  --git a/clang/test/SemaCXX/attr-lifetimebound.cpp 
b/clang/test/SemaCXX/attr-lifetimebound.cpp
index c7abec61873efb..f89b556f5bba08 100644
--- a/clang/test/SemaCXX/attr-lifetimebound.cpp
+++ b/clang/test/SemaCXX/attr-lifetimebound.cpp
@@ -9,25 +9,11 @@ namespace usage_invalid {
 ~A() [[clang::lifetimebound]]; // expected-error {{cannot be applied to a 
destructor}}
 static int *static_class_member() [[clang::lifetimebound]]; // 
expected-error {{static member function has no implicit object parameter}}
 int *explicit_object(this A&) [[clang::lifetimebound]]; // expected-error 
{{explicit object member function has no implicit object parameter}}
-int attr_on_var [[clang::lifetimebound]]; // expected-error {{only applies 
to parameters and implicit object parameters}}
-int [[clang::lifetimebound]] attr_on_int; // expected-error {{cannot be 
applied to types}}
-int * [[clang::lifetimebound]] attr_on_int_ptr; // expected-error 
{{'lifetimebound' attribute only applies to parameters and implicit object 
parameters}}
-int * [[clang::lifetimebound]] * attr_on_int_ptr_ptr; // expected-error 
{{'lifetimebound' attribute only applies to parameters and implicit object 
parameters}}
-int (* [[clang::lifetimebound]] attr_on_func_ptr)(); // expected-error 
{{'lifetimebound' attribute only applies to parameters and implicit object 
parameters}}
+int not_function [[clang::lifetimebound]]; // expected-error {{only 
applies to parameters and implicit object parameters}}
+int [[clang::lifetimebound]] also_not_function; // expected-error {{cannot 
be applied to types}}
 void void_return_member() [[clang::lifetimebound]]; // expected-error 
{{'lifetimebound' attribute cannot be applied to an implicit object parameter 
of a function that returns void; did you mean 'lifetime_capture_by(X)'}}
   };
   int *attr_with_param(int ¶m [[clang::lifetimebound(42)]]); // 
expected-error {{takes no arguments}}
-
-  void attr_on_ptr_arg(int * [[clang::lifetimeboun

[clang] [llvm] [OpenMP]Initial parsing/sema support for target_device selector set (PR #118471)

2024-12-03 Thread via cfe-commits

https://github.com/Ritanya-B-Bharadwaj created 
https://github.com/llvm/llvm-project/pull/118471

This patch adds initial support for target_device selector set - Section 9.2 
(Spec 6.0)

>From 7f64773f0d76b8fd7edf12b3a2dd791b5bd2a9bf Mon Sep 17 00:00:00 2001
From: Ritanya B Bharadwaj 
Date: Tue, 3 Dec 2024 03:58:40 -0600
Subject: [PATCH] Initial parsing/sema support for target_device selector set

---
 clang/include/clang/Sema/SemaOpenMP.h |   3 +
 clang/lib/AST/OpenMPClause.cpp|   5 +-
 clang/lib/Parse/ParseOpenMP.cpp   |  27 ++-
 clang/lib/Sema/SemaOpenMP.cpp |  29 +++
 .../OpenMP/begin_declare_variant_messages.c   |  22 +-
 clang/test/OpenMP/declare_variant_ast_print.c |   4 +
 .../OpenMP/declare_variant_bind_to_decl.cpp   |   2 +-
 clang/test/OpenMP/declare_variant_messages.c  |  57 +++---
 .../test/OpenMP/declare_variant_messages.cpp  |  28 +--
 clang/test/OpenMP/metadirective_messages.cpp  |   2 +-
 .../nvptx_declare_variant_name_mangling.cpp   |   8 +-
 .../include/llvm/Frontend/OpenMP/OMPContext.h |   9 +-
 .../include/llvm/Frontend/OpenMP/OMPKinds.def |  36 
 llvm/lib/Frontend/OpenMP/OMPContext.cpp   | 192 +-
 llvm/unittests/Frontend/OpenMPContextTest.cpp |  26 ++-
 15 files changed, 320 insertions(+), 130 deletions(-)

diff --git a/clang/include/clang/Sema/SemaOpenMP.h 
b/clang/include/clang/Sema/SemaOpenMP.h
index 3d1cc4fab1c10f..4b9c930db26b5d 100644
--- a/clang/include/clang/Sema/SemaOpenMP.h
+++ b/clang/include/clang/Sema/SemaOpenMP.h
@@ -849,6 +849,9 @@ class SemaOpenMP : public SemaBase {
   ArrayRef AppendArgs, SourceLocation AdjustArgsLoc,
   SourceLocation AppendArgsLoc, SourceRange SR);
 
+  /// Handle device_num selector.
+  void ActOnOpenMPDeviceNum(Expr *DeviceNumExpr);
+
   OMPClause *ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr,
  SourceLocation StartLoc,
  SourceLocation LParenLoc,
diff --git a/clang/lib/AST/OpenMPClause.cpp b/clang/lib/AST/OpenMPClause.cpp
index 4246ba95d827f1..bb3aa9fc959c3a 100644
--- a/clang/lib/AST/OpenMPClause.cpp
+++ b/clang/lib/AST/OpenMPClause.cpp
@@ -2903,7 +2903,10 @@ TargetOMPContext::TargetOMPContext(
 const FunctionDecl *CurrentFunctionDecl,
 ArrayRef ConstructTraits)
 : OMPContext(ASTCtx.getLangOpts().OpenMPIsTargetDevice,
- ASTCtx.getTargetInfo().getTriple()),
+ASTCtx.getTargetInfo().getTriple(),
+ ASTCtx.getLangOpts().OMPTargetTriples.empty()
+ ? llvm::Triple()
+ : ASTCtx.getLangOpts().OMPTargetTriples[0]),
   FeatureValidityCheck([&](StringRef FeatureName) {
 return ASTCtx.getTargetInfo().isValidFeatureName(FeatureName);
   }),
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index b91928063169ee..84f1fcdb6e83f2 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -888,7 +888,18 @@ void Parser::parseOMPTraitPropertyKind(OMPTraitProperty 
&TIProperty,
   TIProperty.Kind = TraitProperty::invalid;
 
   SourceLocation NameLoc = Tok.getLocation();
-  StringRef Name = getNameFromIdOrString(*this, Tok, CONTEXT_TRAIT_LVL);
+  StringRef Name;
+  if (Selector == llvm::omp::TraitSelector::target_device_device_num) {
+Name = "number";
+TIProperty.Kind = getOpenMPContextTraitPropertyKind(Set, Selector, Name);
+ExprResult DeviceNumExprResult = ParseExpression();
+if (!DeviceNumExprResult.isInvalid()) {
+  Expr *DeviceNumExpr = DeviceNumExprResult.get();
+  Actions.OpenMP().ActOnOpenMPDeviceNum(DeviceNumExpr);
+}
+return;
+  }
+  Name = getNameFromIdOrString(*this, Tok, CONTEXT_TRAIT_LVL);
   if (Name.empty()) {
 Diag(Tok.getLocation(), diag::note_omp_declare_variant_ctx_options)
 << CONTEXT_TRAIT_LVL << listOpenMPContextTraitProperties(Set, 
Selector);
@@ -918,7 +929,8 @@ void Parser::parseOMPTraitPropertyKind(OMPTraitProperty 
&TIProperty,
 << "()";
 return;
   }
-  TraitSelector SelectorForName = getOpenMPContextTraitSelectorKind(Name);
+  TraitSelector SelectorForName =
+  getOpenMPContextTraitSelectorKind(Name, SetForName);
   if (SelectorForName != TraitSelector::invalid) {
 Diag(NameLoc, diag::note_omp_declare_variant_ctx_is_a)
 << Name << CONTEXT_SELECTOR_LVL << CONTEXT_TRAIT_LVL;
@@ -935,7 +947,7 @@ void Parser::parseOMPTraitPropertyKind(OMPTraitProperty 
&TIProperty,
   }
   for (const auto &PotentialSet :
{TraitSet::construct, TraitSet::user, TraitSet::implementation,
-TraitSet::device}) {
+TraitSet::device, TraitSet::target_device}) {
 TraitProperty PropertyForName =
 getOpenMPContextTraitPropertyKind(PotentialSet, Selector, Name);
 if (PropertyForName == TraitProperty::invalid)
@@ -1062,7 +1074,7 @@ void Parser::parseOMPTraitSelectorKind(OMPTraitSelector 
&TISelector,
 return;
  

[clang] [llvm] [OpenMP]Initial parsing/sema support for target_device selector set (PR #118471)

2024-12-03 Thread via cfe-commits

github-actions[bot] wrote:



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

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

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

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

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

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

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

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


[clang] [llvm] [OpenMP]Initial parsing/sema support for target_device selector set (PR #118471)

2024-12-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (Ritanya-B-Bharadwaj)


Changes

This patch adds initial support for target_device selector set - Section 9.2 
(Spec 6.0)

---

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


15 Files Affected:

- (modified) clang/include/clang/Sema/SemaOpenMP.h (+3) 
- (modified) clang/lib/AST/OpenMPClause.cpp (+4-1) 
- (modified) clang/lib/Parse/ParseOpenMP.cpp (+20-7) 
- (modified) clang/lib/Sema/SemaOpenMP.cpp (+29) 
- (modified) clang/test/OpenMP/begin_declare_variant_messages.c (+11-11) 
- (modified) clang/test/OpenMP/declare_variant_ast_print.c (+4) 
- (modified) clang/test/OpenMP/declare_variant_bind_to_decl.cpp (+1-1) 
- (modified) clang/test/OpenMP/declare_variant_messages.c (+34-23) 
- (modified) clang/test/OpenMP/declare_variant_messages.cpp (+14-14) 
- (modified) clang/test/OpenMP/metadirective_messages.cpp (+1-1) 
- (modified) clang/test/OpenMP/nvptx_declare_variant_name_mangling.cpp (+4-4) 
- (modified) llvm/include/llvm/Frontend/OpenMP/OMPContext.h (+7-2) 
- (modified) llvm/include/llvm/Frontend/OpenMP/OMPKinds.def (+36) 
- (modified) llvm/lib/Frontend/OpenMP/OMPContext.cpp (+137-55) 
- (modified) llvm/unittests/Frontend/OpenMPContextTest.cpp (+15-11) 


``diff
diff --git a/clang/include/clang/Sema/SemaOpenMP.h 
b/clang/include/clang/Sema/SemaOpenMP.h
index 3d1cc4fab1c10f..4b9c930db26b5d 100644
--- a/clang/include/clang/Sema/SemaOpenMP.h
+++ b/clang/include/clang/Sema/SemaOpenMP.h
@@ -849,6 +849,9 @@ class SemaOpenMP : public SemaBase {
   ArrayRef AppendArgs, SourceLocation AdjustArgsLoc,
   SourceLocation AppendArgsLoc, SourceRange SR);
 
+  /// Handle device_num selector.
+  void ActOnOpenMPDeviceNum(Expr *DeviceNumExpr);
+
   OMPClause *ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr,
  SourceLocation StartLoc,
  SourceLocation LParenLoc,
diff --git a/clang/lib/AST/OpenMPClause.cpp b/clang/lib/AST/OpenMPClause.cpp
index 4246ba95d827f1..bb3aa9fc959c3a 100644
--- a/clang/lib/AST/OpenMPClause.cpp
+++ b/clang/lib/AST/OpenMPClause.cpp
@@ -2903,7 +2903,10 @@ TargetOMPContext::TargetOMPContext(
 const FunctionDecl *CurrentFunctionDecl,
 ArrayRef ConstructTraits)
 : OMPContext(ASTCtx.getLangOpts().OpenMPIsTargetDevice,
- ASTCtx.getTargetInfo().getTriple()),
+ASTCtx.getTargetInfo().getTriple(),
+ ASTCtx.getLangOpts().OMPTargetTriples.empty()
+ ? llvm::Triple()
+ : ASTCtx.getLangOpts().OMPTargetTriples[0]),
   FeatureValidityCheck([&](StringRef FeatureName) {
 return ASTCtx.getTargetInfo().isValidFeatureName(FeatureName);
   }),
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index b91928063169ee..84f1fcdb6e83f2 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -888,7 +888,18 @@ void Parser::parseOMPTraitPropertyKind(OMPTraitProperty 
&TIProperty,
   TIProperty.Kind = TraitProperty::invalid;
 
   SourceLocation NameLoc = Tok.getLocation();
-  StringRef Name = getNameFromIdOrString(*this, Tok, CONTEXT_TRAIT_LVL);
+  StringRef Name;
+  if (Selector == llvm::omp::TraitSelector::target_device_device_num) {
+Name = "number";
+TIProperty.Kind = getOpenMPContextTraitPropertyKind(Set, Selector, Name);
+ExprResult DeviceNumExprResult = ParseExpression();
+if (!DeviceNumExprResult.isInvalid()) {
+  Expr *DeviceNumExpr = DeviceNumExprResult.get();
+  Actions.OpenMP().ActOnOpenMPDeviceNum(DeviceNumExpr);
+}
+return;
+  }
+  Name = getNameFromIdOrString(*this, Tok, CONTEXT_TRAIT_LVL);
   if (Name.empty()) {
 Diag(Tok.getLocation(), diag::note_omp_declare_variant_ctx_options)
 << CONTEXT_TRAIT_LVL << listOpenMPContextTraitProperties(Set, 
Selector);
@@ -918,7 +929,8 @@ void Parser::parseOMPTraitPropertyKind(OMPTraitProperty 
&TIProperty,
 << "()";
 return;
   }
-  TraitSelector SelectorForName = getOpenMPContextTraitSelectorKind(Name);
+  TraitSelector SelectorForName =
+  getOpenMPContextTraitSelectorKind(Name, SetForName);
   if (SelectorForName != TraitSelector::invalid) {
 Diag(NameLoc, diag::note_omp_declare_variant_ctx_is_a)
 << Name << CONTEXT_SELECTOR_LVL << CONTEXT_TRAIT_LVL;
@@ -935,7 +947,7 @@ void Parser::parseOMPTraitPropertyKind(OMPTraitProperty 
&TIProperty,
   }
   for (const auto &PotentialSet :
{TraitSet::construct, TraitSet::user, TraitSet::implementation,
-TraitSet::device}) {
+TraitSet::device, TraitSet::target_device}) {
 TraitProperty PropertyForName =
 getOpenMPContextTraitPropertyKind(PotentialSet, Selector, Name);
 if (PropertyForName == TraitProperty::invalid)
@@ -1062,7 +1074,7 @@ void Parser::parseOMPTraitSelectorKind(OMPTraitSelector 
&TISelector,
 return;
   }
 

[clang] [llvm] [OpenMP]Initial parsing/sema support for target_device selector set (PR #118471)

2024-12-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-flang-openmp

Author: None (Ritanya-B-Bharadwaj)


Changes

This patch adds initial support for target_device selector set - Section 9.2 
(Spec 6.0)

---

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


15 Files Affected:

- (modified) clang/include/clang/Sema/SemaOpenMP.h (+3) 
- (modified) clang/lib/AST/OpenMPClause.cpp (+4-1) 
- (modified) clang/lib/Parse/ParseOpenMP.cpp (+20-7) 
- (modified) clang/lib/Sema/SemaOpenMP.cpp (+29) 
- (modified) clang/test/OpenMP/begin_declare_variant_messages.c (+11-11) 
- (modified) clang/test/OpenMP/declare_variant_ast_print.c (+4) 
- (modified) clang/test/OpenMP/declare_variant_bind_to_decl.cpp (+1-1) 
- (modified) clang/test/OpenMP/declare_variant_messages.c (+34-23) 
- (modified) clang/test/OpenMP/declare_variant_messages.cpp (+14-14) 
- (modified) clang/test/OpenMP/metadirective_messages.cpp (+1-1) 
- (modified) clang/test/OpenMP/nvptx_declare_variant_name_mangling.cpp (+4-4) 
- (modified) llvm/include/llvm/Frontend/OpenMP/OMPContext.h (+7-2) 
- (modified) llvm/include/llvm/Frontend/OpenMP/OMPKinds.def (+36) 
- (modified) llvm/lib/Frontend/OpenMP/OMPContext.cpp (+137-55) 
- (modified) llvm/unittests/Frontend/OpenMPContextTest.cpp (+15-11) 


``diff
diff --git a/clang/include/clang/Sema/SemaOpenMP.h 
b/clang/include/clang/Sema/SemaOpenMP.h
index 3d1cc4fab1c10f..4b9c930db26b5d 100644
--- a/clang/include/clang/Sema/SemaOpenMP.h
+++ b/clang/include/clang/Sema/SemaOpenMP.h
@@ -849,6 +849,9 @@ class SemaOpenMP : public SemaBase {
   ArrayRef AppendArgs, SourceLocation AdjustArgsLoc,
   SourceLocation AppendArgsLoc, SourceRange SR);
 
+  /// Handle device_num selector.
+  void ActOnOpenMPDeviceNum(Expr *DeviceNumExpr);
+
   OMPClause *ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr,
  SourceLocation StartLoc,
  SourceLocation LParenLoc,
diff --git a/clang/lib/AST/OpenMPClause.cpp b/clang/lib/AST/OpenMPClause.cpp
index 4246ba95d827f1..bb3aa9fc959c3a 100644
--- a/clang/lib/AST/OpenMPClause.cpp
+++ b/clang/lib/AST/OpenMPClause.cpp
@@ -2903,7 +2903,10 @@ TargetOMPContext::TargetOMPContext(
 const FunctionDecl *CurrentFunctionDecl,
 ArrayRef ConstructTraits)
 : OMPContext(ASTCtx.getLangOpts().OpenMPIsTargetDevice,
- ASTCtx.getTargetInfo().getTriple()),
+ASTCtx.getTargetInfo().getTriple(),
+ ASTCtx.getLangOpts().OMPTargetTriples.empty()
+ ? llvm::Triple()
+ : ASTCtx.getLangOpts().OMPTargetTriples[0]),
   FeatureValidityCheck([&](StringRef FeatureName) {
 return ASTCtx.getTargetInfo().isValidFeatureName(FeatureName);
   }),
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index b91928063169ee..84f1fcdb6e83f2 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -888,7 +888,18 @@ void Parser::parseOMPTraitPropertyKind(OMPTraitProperty 
&TIProperty,
   TIProperty.Kind = TraitProperty::invalid;
 
   SourceLocation NameLoc = Tok.getLocation();
-  StringRef Name = getNameFromIdOrString(*this, Tok, CONTEXT_TRAIT_LVL);
+  StringRef Name;
+  if (Selector == llvm::omp::TraitSelector::target_device_device_num) {
+Name = "number";
+TIProperty.Kind = getOpenMPContextTraitPropertyKind(Set, Selector, Name);
+ExprResult DeviceNumExprResult = ParseExpression();
+if (!DeviceNumExprResult.isInvalid()) {
+  Expr *DeviceNumExpr = DeviceNumExprResult.get();
+  Actions.OpenMP().ActOnOpenMPDeviceNum(DeviceNumExpr);
+}
+return;
+  }
+  Name = getNameFromIdOrString(*this, Tok, CONTEXT_TRAIT_LVL);
   if (Name.empty()) {
 Diag(Tok.getLocation(), diag::note_omp_declare_variant_ctx_options)
 << CONTEXT_TRAIT_LVL << listOpenMPContextTraitProperties(Set, 
Selector);
@@ -918,7 +929,8 @@ void Parser::parseOMPTraitPropertyKind(OMPTraitProperty 
&TIProperty,
 << "()";
 return;
   }
-  TraitSelector SelectorForName = getOpenMPContextTraitSelectorKind(Name);
+  TraitSelector SelectorForName =
+  getOpenMPContextTraitSelectorKind(Name, SetForName);
   if (SelectorForName != TraitSelector::invalid) {
 Diag(NameLoc, diag::note_omp_declare_variant_ctx_is_a)
 << Name << CONTEXT_SELECTOR_LVL << CONTEXT_TRAIT_LVL;
@@ -935,7 +947,7 @@ void Parser::parseOMPTraitPropertyKind(OMPTraitProperty 
&TIProperty,
   }
   for (const auto &PotentialSet :
{TraitSet::construct, TraitSet::user, TraitSet::implementation,
-TraitSet::device}) {
+TraitSet::device, TraitSet::target_device}) {
 TraitProperty PropertyForName =
 getOpenMPContextTraitPropertyKind(PotentialSet, Selector, Name);
 if (PropertyForName == TraitProperty::invalid)
@@ -1062,7 +1074,7 @@ void Parser::parseOMPTraitSelectorKind(OMPTraitSelector 
&TISelector,
 return;

[clang] [llvm] [OpenMP]Initial parsing/sema support for target_device selector set (PR #118471)

2024-12-03 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 6c7b988e64b60cff7e9f3777dfcc2b2511ee48c6 
7f64773f0d76b8fd7edf12b3a2dd791b5bd2a9bf --extensions cpp,c,h -- 
clang/include/clang/Sema/SemaOpenMP.h clang/lib/AST/OpenMPClause.cpp 
clang/lib/Parse/ParseOpenMP.cpp clang/lib/Sema/SemaOpenMP.cpp 
clang/test/OpenMP/begin_declare_variant_messages.c 
clang/test/OpenMP/declare_variant_ast_print.c 
clang/test/OpenMP/declare_variant_bind_to_decl.cpp 
clang/test/OpenMP/declare_variant_messages.c 
clang/test/OpenMP/declare_variant_messages.cpp 
clang/test/OpenMP/metadirective_messages.cpp 
clang/test/OpenMP/nvptx_declare_variant_name_mangling.cpp 
llvm/include/llvm/Frontend/OpenMP/OMPContext.h 
llvm/lib/Frontend/OpenMP/OMPContext.cpp 
llvm/unittests/Frontend/OpenMPContextTest.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/AST/OpenMPClause.cpp b/clang/lib/AST/OpenMPClause.cpp
index bb3aa9fc95..870c4224c3 100644
--- a/clang/lib/AST/OpenMPClause.cpp
+++ b/clang/lib/AST/OpenMPClause.cpp
@@ -2903,7 +2903,7 @@ TargetOMPContext::TargetOMPContext(
 const FunctionDecl *CurrentFunctionDecl,
 ArrayRef ConstructTraits)
 : OMPContext(ASTCtx.getLangOpts().OpenMPIsTargetDevice,
-ASTCtx.getTargetInfo().getTriple(),
+ ASTCtx.getTargetInfo().getTriple(),
  ASTCtx.getLangOpts().OMPTargetTriples.empty()
  ? llvm::Triple()
  : ASTCtx.getLangOpts().OMPTargetTriples[0]),
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 48f6fa53fc..6635d5c236 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -15634,7 +15634,7 @@ void SemaOpenMP::ActOnOpenMPDeviceNum(Expr 
*DeviceNumExpr) {
   Expr::EvalResult EvalResult;
   // Strip implicit casts from the expression
   DeviceNumExpr = DeviceNumExpr->IgnoreImpCasts();
- 
+
   // Evaluate the expression to an integer value
   if (DeviceNumExpr->EvaluateAsInt(EvalResult, SemaRef.Context)) {
 // The device expression must evaluate to a non-negative integer value.

``




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


  1   2   3   4   5   6   >