[clang] [analyzer] Improve some comments in ArrayBoundCheckerV2 (NFC) (PR #83545)

2024-03-03 Thread Gábor Spaits via cfe-commits

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


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


[clang] [OpenMP] Parse and Sema support for declare target in local scope (PR #83223)

2024-03-03 Thread Sandeep Kosuri via cfe-commits

https://github.com/sandeepkosuri updated 
https://github.com/llvm/llvm-project/pull/83223

>From cbf1b4409e379309ae3d942b3dbec0964b9ee0d1 Mon Sep 17 00:00:00 2001
From: Sandeep Kosuri 
Date: Tue, 27 Feb 2024 23:19:41 -0600
Subject: [PATCH 1/2] [OpenMP] Parse and Sema support for declare target in
 local scope

---
 .../clang/Basic/DiagnosticSemaKinds.td|  3 +++
 clang/lib/Parse/ParseOpenMP.cpp   | 23 ++-
 clang/lib/Sema/SemaOpenMP.cpp |  9 
 .../test/OpenMP/declare_target_ast_print.cpp  | 19 +++
 clang/test/OpenMP/declare_target_messages.cpp |  9 
 5 files changed, 62 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index a7f2858477bee6..faa7d1872ae3f1 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11326,6 +11326,9 @@ def err_omp_device_type_mismatch : Error<
 def err_omp_wrong_device_function_call : Error<
   "function with 'device_type(%0)' is not available on %select{device|host}1">;
 def note_omp_marked_device_type_here : Note<"marked as 'device_type(%0)' 
here">;
+def warn_omp_declare_target_has_local_vars : Warning<
+  "local variable '%0' ignored in 'declare target' directive; ">,
+  InGroup;
 def warn_omp_declare_target_after_first_use : Warning<
   "declaration marked as declare target after first use, it may lead to 
incorrect results">,
   InGroup;
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index bfc31f2653c237..814126e321d3bc 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -2984,8 +2984,29 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
 OMPDirectiveScope.Exit();
 break;
   }
+  case OMPD_declare_target: {
+SourceLocation DTLoc = ConsumeAnyToken();
+bool HasClauses = Tok.isNot(tok::annot_pragma_openmp_end);
+Sema::DeclareTargetContextInfo DTCI(DKind, DTLoc);
+if (HasClauses)
+  ParseOMPDeclareTargetClauses(DTCI);
+bool HasImplicitMappings =
+!HasClauses || (DTCI.ExplicitlyMapped.empty() && DTCI.Indirect);
+
+if (HasImplicitMappings) {
+  Diag(Tok, diag::err_omp_unexpected_directive)
+  << 1 << getOpenMPDirectiveName(DKind);
+  SkipUntil(tok::annot_pragma_openmp_end);
+  break;
+}
+
+// Skip the last annot_pragma_openmp_end.
+ConsumeAnyToken();
+
+Actions.ActOnFinishedOpenMPDeclareTargetContext(DTCI);
+break;
+  }
   case OMPD_declare_simd:
-  case OMPD_declare_target:
   case OMPD_begin_declare_target:
   case OMPD_end_declare_target:
   case OMPD_requires:
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 7f75cfc5b54f35..0cd8ff065a3419 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -23352,6 +23352,15 @@ void Sema::ActOnOpenMPDeclareTargetName(NamedDecl *ND, 
SourceLocation Loc,
   isa(ND)) &&
  "Expected variable, function or function template.");
 
+  if (auto *VD = dyn_cast(ND)) {
+// Only global variables can be marked as declare target.
+if (!VD->isFileVarDecl() && !VD->isStaticLocal() &&
+!VD->isStaticDataMember()) {
+  Diag(Loc, diag::warn_omp_declare_target_has_local_vars)
+  << VD->getNameAsString();
+  return;
+}
+  }
   // Diagnose marking after use as it may lead to incorrect diagnosis and
   // codegen.
   if (LangOpts.OpenMP >= 50 &&
diff --git a/clang/test/OpenMP/declare_target_ast_print.cpp 
b/clang/test/OpenMP/declare_target_ast_print.cpp
index 40c5dd299abd96..43cccf763e97c3 100644
--- a/clang/test/OpenMP/declare_target_ast_print.cpp
+++ b/clang/test/OpenMP/declare_target_ast_print.cpp
@@ -360,6 +360,17 @@ int inner_link;
 // CHECK-NEXT: int inner_link;
 // CHECK-NEXT: #pragma omp end declare target
 
+void foo2() { return ;}
+// CHECK: #pragma omp declare target
+// CHECK-NEXT: void foo2() {
+// CHECK-NEXT: return;
+// CHECK-NEXT: }
+
+int x;
+// CHECK: #pragma omp declare target link
+// CHECK-NEXT: int x;
+// CHECK-NEXT: #pragma omp end declare target
+
 int main (int argc, char **argv) {
   foo();
   foo_c();
@@ -367,6 +378,14 @@ int main (int argc, char **argv) {
   test1();
   baz();
   baz();
+
+#if _OPENMP == 202111
+#pragma omp declare target enter(foo2)
+#else
+#pragma omp declare target to (foo2)
+#endif
+
+  #pragma omp declare target link(x)
   return (0);
 }
 
diff --git a/clang/test/OpenMP/declare_target_messages.cpp 
b/clang/test/OpenMP/declare_target_messages.cpp
index cf034aca7c9136..39616bc47b2ccb 100644
--- a/clang/test/OpenMP/declare_target_messages.cpp
+++ b/clang/test/OpenMP/declare_target_messages.cpp
@@ -182,11 +182,20 @@ struct S {
 #pragma omp end declare target
 };
 
+void foo3() {
+  return;
+}
+
+int *y;
+int **w = &y;
 int main (int argc, char **argv) {
+  int a = 2;
 #pragma omp declare target // expected-error

[clang] [clang] Add some CodeGen tests for CWG 4xx issues (PR #83715)

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

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

This patch covers the following defect reports:
[CWG438](https://cplusplus.github.io/CWG/issues/438.html) "Possible flaw in 
wording for multiple accesses to object between sequence points", 
[CWG439](https://cplusplus.github.io/CWG/issues/439.html) "Guarantees on 
casting pointer back to cv-qualified version of original type", 
[CWG441](https://cplusplus.github.io/CWG/issues/441.html) "Ordering of static 
reference initialization", 
[CWG462](https://cplusplus.github.io/CWG/issues/462.html) "Lifetime of 
temporaries bound to comma expressions", 
[CWG492](https://cplusplus.github.io/CWG/issues/492.html) "`typeid` constness 
inconsistent with example".

[CWG475](https://cplusplus.github.io/CWG/issues/475.html) "When is 
`std::uncaught_exception()` true? (take 2)" requires a libc++abi test. As for 
[CWG454](https://cplusplus.github.io/CWG/issues/454.html) "When is a definition 
of a static data member required?", I don't feel confident in my understanding 
of it, so skipping over it.

>From 59a558a653098c1b96b47cffc62b1f3bf1cb92d8 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Sun, 3 Mar 2024 12:21:17 +0300
Subject: [PATCH] [clang] Add some CodeGen tests for CWG 4xx issues

This patch covers the following defect reports:
[CWG438](https://cplusplus.github.io/CWG/issues/438.html) "Possible flaw in 
wording for multiple accesses to object between sequence points",
[CWG439](https://cplusplus.github.io/CWG/issues/439.html) "Guarantees on 
casting pointer back to cv-qualified version of original type",
[CWG441](https://cplusplus.github.io/CWG/issues/441.html) "Ordering of static 
reference initialization",
[CWG462](https://cplusplus.github.io/CWG/issues/462.html) "Lifetime of 
temporaries bound to comma expressions",
[CWG492](https://cplusplus.github.io/CWG/issues/492.html) "`typeid` constness 
inconsistent with example".

[CWG475](https://cplusplus.github.io/CWG/issues/475.html) "When is 
`std::uncaught_exception()` true? (take 2)" requires a libc++abi test. As for 
[CWG454](https://cplusplus.github.io/CWG/issues/454.html) "When is a definition 
of a static data member required?", I don't feel confident in my understanding 
of it, so skipping over it.
---
 clang/test/CXX/drs/dr438.cpp | 24 +++
 clang/test/CXX/drs/dr439.cpp | 27 +
 clang/test/CXX/drs/dr441.cpp | 38 
 clang/test/CXX/drs/dr462.cpp | 33 +++
 clang/test/CXX/drs/dr492.cpp | 37 +++
 clang/test/CXX/drs/dr4xx.cpp | 12 ++--
 clang/www/cxx_dr_status.html | 10 +-
 7 files changed, 170 insertions(+), 11 deletions(-)
 create mode 100644 clang/test/CXX/drs/dr438.cpp
 create mode 100644 clang/test/CXX/drs/dr439.cpp
 create mode 100644 clang/test/CXX/drs/dr441.cpp
 create mode 100644 clang/test/CXX/drs/dr462.cpp
 create mode 100644 clang/test/CXX/drs/dr492.cpp

diff --git a/clang/test/CXX/drs/dr438.cpp b/clang/test/CXX/drs/dr438.cpp
new file mode 100644
index 00..1213edf9911518
--- /dev/null
+++ b/clang/test/CXX/drs/dr438.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -std=c++98 %s -triple x86_64-linux-gnu -emit-llvm -o - 
-fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s 
--check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++11 %s -triple x86_64-linux-gnu -emit-llvm -o - 
-fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s 
--check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++14 %s -triple x86_64-linux-gnu -emit-llvm -o - 
-fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s 
--check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++17 %s -triple x86_64-linux-gnu -emit-llvm -o - 
-fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s 
--check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++20 %s -triple x86_64-linux-gnu -emit-llvm -o - 
-fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s 
--check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++23 %s -triple x86_64-linux-gnu -emit-llvm -o - 
-fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s 
--check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++2c %s -triple x86_64-linux-gnu -emit-llvm -o - 
-fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s 
--check-prefixes CHECK
+
+namespace dr438 { // dr438: 2.7
+
+void f() {
+  long A[2];
+  A[0] = 0;
+  A[A[0]] = 1;
+}
+
+} // namespace dr438
+
+// CHECK-LABEL: define {{.*}} void @dr438::f()()
+// CHECK: [[A:%.+]] = alloca [2 x i64]
+// CHECK: [[ARRAYIDX1:%.+]] = getelementptr inbounds [2 x i64], ptr 
[[A]], i64 0, i64 0
+// CHECK: [[TEMPIDX:%.+]] = load i64, ptr [[ARRAYIDX1]]
+// CHECK: [[ARRAYIDX2:%.+]] = getelementptr inbounds [2 x i64], ptr 
[[A]], i64 0, i64 [[TEMPIDX]]
+// CHECK-LABEL: }
diff --git a/clang/test/CXX/

[clang] [clang] Add some CodeGen tests for CWG 4xx issues (PR #83715)

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

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


[clang] [clang] Add some CodeGen tests for CWG 4xx issues (PR #83715)

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

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


[clang] [clang] Add some CodeGen tests for CWG 4xx issues (PR #83715)

2024-03-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Vlad Serebrennikov (Endilll)


Changes

This patch covers the following defect reports:
[CWG438](https://cplusplus.github.io/CWG/issues/438.html) "Possible flaw in 
wording for multiple accesses to object between sequence points",
[CWG439](https://cplusplus.github.io/CWG/issues/439.html) "Guarantees on 
casting pointer back to cv-qualified version of original type",
[CWG441](https://cplusplus.github.io/CWG/issues/441.html) "Ordering of static 
reference initialization",
[CWG462](https://cplusplus.github.io/CWG/issues/462.html) "Lifetime of 
temporaries bound to comma expressions",
[CWG492](https://cplusplus.github.io/CWG/issues/492.html) "`typeid` constness 
inconsistent with example".

[CWG475](https://cplusplus.github.io/CWG/issues/475.html) "When is 
`std::uncaught_exception()` true? (take 2)" requires a libc++abi test. As for 
[CWG454](https://cplusplus.github.io/CWG/issues/454.html) "When is a definition 
of a static data member required?", I don't feel confident in my understanding 
of it, so skipping over it.

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


7 Files Affected:

- (added) clang/test/CXX/drs/dr438.cpp (+24) 
- (added) clang/test/CXX/drs/dr439.cpp (+27) 
- (added) clang/test/CXX/drs/dr441.cpp (+38) 
- (added) clang/test/CXX/drs/dr462.cpp (+33) 
- (added) clang/test/CXX/drs/dr492.cpp (+37) 
- (modified) clang/test/CXX/drs/dr4xx.cpp (+6-6) 
- (modified) clang/www/cxx_dr_status.html (+5-5) 


``diff
diff --git a/clang/test/CXX/drs/dr438.cpp b/clang/test/CXX/drs/dr438.cpp
new file mode 100644
index 00..1213edf9911518
--- /dev/null
+++ b/clang/test/CXX/drs/dr438.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -std=c++98 %s -triple x86_64-linux-gnu -emit-llvm -o - 
-fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s 
--check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++11 %s -triple x86_64-linux-gnu -emit-llvm -o - 
-fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s 
--check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++14 %s -triple x86_64-linux-gnu -emit-llvm -o - 
-fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s 
--check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++17 %s -triple x86_64-linux-gnu -emit-llvm -o - 
-fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s 
--check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++20 %s -triple x86_64-linux-gnu -emit-llvm -o - 
-fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s 
--check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++23 %s -triple x86_64-linux-gnu -emit-llvm -o - 
-fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s 
--check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++2c %s -triple x86_64-linux-gnu -emit-llvm -o - 
-fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s 
--check-prefixes CHECK
+
+namespace dr438 { // dr438: 2.7
+
+void f() {
+  long A[2];
+  A[0] = 0;
+  A[A[0]] = 1;
+}
+
+} // namespace dr438
+
+// CHECK-LABEL: define {{.*}} void @dr438::f()()
+// CHECK: [[A:%.+]] = alloca [2 x i64]
+// CHECK: [[ARRAYIDX1:%.+]] = getelementptr inbounds [2 x i64], ptr 
[[A]], i64 0, i64 0
+// CHECK: [[TEMPIDX:%.+]] = load i64, ptr [[ARRAYIDX1]]
+// CHECK: [[ARRAYIDX2:%.+]] = getelementptr inbounds [2 x i64], ptr 
[[A]], i64 0, i64 [[TEMPIDX]]
+// CHECK-LABEL: }
diff --git a/clang/test/CXX/drs/dr439.cpp b/clang/test/CXX/drs/dr439.cpp
new file mode 100644
index 00..874cd75cf2eb9f
--- /dev/null
+++ b/clang/test/CXX/drs/dr439.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -std=c++98 %s -triple x86_64-linux-gnu -emit-llvm -o - 
-fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s 
--check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++11 %s -triple x86_64-linux-gnu -emit-llvm -o - 
-fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s 
--check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++14 %s -triple x86_64-linux-gnu -emit-llvm -o - 
-fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s 
--check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++17 %s -triple x86_64-linux-gnu -emit-llvm -o - 
-fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s 
--check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++20 %s -triple x86_64-linux-gnu -emit-llvm -o - 
-fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s 
--check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++23 %s -triple x86_64-linux-gnu -emit-llvm -o - 
-fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s 
--check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++2c %s -triple x86_64-linux-gnu -emit-llvm -o - 
-fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s 
--check-prefixes CHECK
+
+namespace dr439 { // dr439: 2.7
+
+void f() {
+ 

[clang] [Clang] [Sema] Do not attempt to dump the layout of dependent types when `-fdump-record-layouts-complete` is passed (PR #83688)

2024-03-03 Thread via cfe-commits


@@ -5042,7 +5042,7 @@ void RecordDecl::completeDefinition() {
 
   // Layouts are dumped when computed, so if we are dumping for all complete
   // types, we need to force usage to get types that wouldn't be used 
elsewhere.
-  if (Ctx.getLangOpts().DumpRecordLayoutsComplete)
+  if (Ctx.getLangOpts().DumpRecordLayoutsComplete && !isDependentType())

Sirraide wrote:

Sure; I was going to do that but I felt it wasn’t really ‘necessary’, but it 
can’t hurt.

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


[clang] [Clang] [Sema] Do not attempt to dump the layout of dependent types when `-fdump-record-layouts-complete` is passed (PR #83688)

2024-03-03 Thread via cfe-commits

https://github.com/Sirraide updated 
https://github.com/llvm/llvm-project/pull/83688

>From 4abc148104769bd756042c73edeb7ee54397a05f Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Sat, 2 Mar 2024 20:41:22 +0100
Subject: [PATCH 1/3] [Clang] [Sema] Do not attempt to dump the layout of
 dependent types

---
 clang/lib/AST/Decl.cpp  |  2 +-
 clang/test/Layout/dump-complete.cpp | 29 -
 2 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 5d6bb72a208a1a..d069cd65732310 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -5042,7 +5042,7 @@ void RecordDecl::completeDefinition() {
 
   // Layouts are dumped when computed, so if we are dumping for all complete
   // types, we need to force usage to get types that wouldn't be used 
elsewhere.
-  if (Ctx.getLangOpts().DumpRecordLayoutsComplete)
+  if (Ctx.getLangOpts().DumpRecordLayoutsComplete && !isDependentType())
 (void)Ctx.getASTRecordLayout(this);
 }
 
diff --git a/clang/test/Layout/dump-complete.cpp 
b/clang/test/Layout/dump-complete.cpp
index 9ccbf477c7052e..0a91d3329e6921 100644
--- a/clang/test/Layout/dump-complete.cpp
+++ b/clang/test/Layout/dump-complete.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -emit-llvm-only -fdump-record-layouts-complete %s | 
FileCheck %s
+// RUN: %clang_cc1 -fsyntax-only -fdump-record-layouts-complete %s | FileCheck 
%s
 
 struct a {
   int x;
@@ -12,7 +12,34 @@ class c {};
 
 class d;
 
+template 
+struct s {
+  int x;
+};
+
+template 
+struct ts {
+  T x;
+};
+
+void f() {
+  ts a;
+  ts b;
+}
+
+namespace gh83684 {
+template 
+struct AllocationResult {
+  Pointer ptr = nullptr;
+  int count = 0;
+};
+}
+
 // CHECK:  0 | struct a
 // CHECK:  0 | struct b
 // CHECK:  0 | class c
+// CHECK:  0 | struct ts
+// CHECK:  0 | struct ts
 // CHECK-NOT:  0 | class d
+// CHECK-NOT:  0 | struct s
+// CHECK-NOT:  0 | struct AllocationResult

>From 3056a8414cae4648a3cc8244cacef29e6dc00564 Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Sat, 2 Mar 2024 20:45:24 +0100
Subject: [PATCH 2/3] [Clang] Add release note

---
 clang/docs/ReleaseNotes.rst | 4 
 1 file changed, 4 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f44fef28b9f17f..69cf0cb643e6aa 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -308,6 +308,10 @@ Miscellaneous Bug Fixes
 Miscellaneous Clang Crashes Fixed
 ^
 
+- Do not attempt to dump the layout of dependent types when 
``-fdump-record-layouts-complete``
+  is passed.
+  Fixes (`#83684 `_).
+
 OpenACC Specific Changes
 
 

>From cdf14b7cef9e08d932b649dc2724362aeea56a40 Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Sun, 3 Mar 2024 10:44:38 +0100
Subject: [PATCH 3/3] [Clang] Add comment and test case for explicit
 specialisation

---
 clang/lib/AST/Decl.cpp  | 3 +++
 clang/test/Layout/dump-complete.cpp | 8 
 2 files changed, 11 insertions(+)

diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index d069cd65732310..a3e4e13ffdc74d 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -5042,6 +5042,9 @@ void RecordDecl::completeDefinition() {
 
   // Layouts are dumped when computed, so if we are dumping for all complete
   // types, we need to force usage to get types that wouldn't be used 
elsewhere.
+  //
+  // If the type is dependent, then we can't compute its layout because there
+  // is no way for us to know the size or alignment of a dependent type.
   if (Ctx.getLangOpts().DumpRecordLayoutsComplete && !isDependentType())
 (void)Ctx.getASTRecordLayout(this);
 }
diff --git a/clang/test/Layout/dump-complete.cpp 
b/clang/test/Layout/dump-complete.cpp
index 0a91d3329e6921..7fed145084dccb 100644
--- a/clang/test/Layout/dump-complete.cpp
+++ b/clang/test/Layout/dump-complete.cpp
@@ -22,9 +22,15 @@ struct ts {
   T x;
 };
 
+template <>
+struct ts {
+  float f;
+};
+
 void f() {
   ts a;
   ts b;
+  ts c;
 }
 
 namespace gh83684 {
@@ -38,6 +44,8 @@ struct AllocationResult {
 // CHECK:  0 | struct a
 // CHECK:  0 | struct b
 // CHECK:  0 | class c
+// CHECK:  0 | struct ts
+// CHECK-NEXT: 0 |   float
 // CHECK:  0 | struct ts
 // CHECK:  0 | struct ts
 // CHECK-NOT:  0 | class d

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


[clang-tools-extra] [clangd] [HeuristicResolver] Protect against infinite recursion on DependentNameTypes (PR #83542)

2024-03-03 Thread Younan Zhang via cfe-commits

zyn0217 wrote:

Great example, thanks! Now I understand the "two-level" case better.

I don't have any other concerns about the refactor, so feel free to land it or 
wait for other folks' opinions.

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


[clang] [clang][AST] fix dereference on class/struct layouts check. (PR #83686)

2024-03-03 Thread Jack Ren via cfe-commits

bjrjk wrote:

Hello, this is a mininal reproducer execute with `clang++ -Xclang 
-fdump-record-layouts-complete test.cpp`:
```cpp
template 
struct integral_constant {
  static constexpr const _Tp value = __v;
  typedef integral_constant type;
};

template 
using _BoolConstant = integral_constant;

template 
struct is_same : _BoolConstant<__is_same(_Tp, _Up)> {};
```

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


[clang] [Clang][Sema] Fix missing warning when comparing mismatched enums in … (PR #81418)

2024-03-03 Thread Stephan Bergmann via cfe-commits

stbergmann wrote:

This change started to break the following C++26 code:
```
$ cat test.cc
enum E1 { E11 };
enum E2 {
E21 = E11,
E22 = 1,
E23 = E21 + E22
};
```
```
clang++ -std=c++26 -fsyntax-only test.cc
test.cc:5:15: error: invalid arithmetic between different enumeration types 
('E1' and 'E2')
5 | E23 = E21 + E22
  |   ~~~ ^ ~~~
1 error generated.
```
as within the definition of enum `E2` with unfixed underlying type, while the 
type of `E21` is indeed `E1`, the type of `E22` there is `int` rather than `E2` 
(see [dcl.enum]/5.1 "If an initializer is specified for an enumerator, the 
constant-expression shall be an integral constant expression (7.7). If the 
expression has unscoped enumeration type, the enumerator has the underlying 
type of that enumeration type, otherwise it has the same type as the 
expression.")

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


[clang] [Clang] [Sema] Do not attempt to dump the layout of dependent types when `-fdump-record-layouts-complete` is passed (PR #83688)

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

Endilll wrote:

This might also fix #83671

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


[clang] [Clang] [Sema] Do not attempt to dump the layout of dependent types when `-fdump-record-layouts-complete` is passed (PR #83688)

2024-03-03 Thread via cfe-commits

Sirraide wrote:

> This might also fix #83671

>From what I saw, that’s a different problem, and there’s a different pr for 
>that already, but I’ll double-check.

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


[clang] [clang][AST] fix dereference on class/struct layouts check. (PR #83686)

2024-03-03 Thread David CARLIER via cfe-commits

devnexen wrote:

it seems [there is an ongoing 
fix](https://github.com/llvm/llvm-project/pull/83688), could you possibly try 
so we can just close this one.

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


[clang] [Clang] [Sema] Do not attempt to dump the layout of dependent types when `-fdump-record-layouts-complete` is passed (PR #83688)

2024-03-03 Thread via cfe-commits

Sirraide wrote:

Oh, apparently, there’s *yet another* problem here; it seems we should also 
check for `isInvalidDecl()`.

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


[clang] [Clang] [Sema] Do not attempt to dump the layout of dependent types when `-fdump-record-layouts-complete` is passed (PR #83688)

2024-03-03 Thread Jack Ren via cfe-commits

bjrjk wrote:

> > This might also fix #83671
> 
> From what I saw, that’s a different problem, and there’s a different pr for 
> that already, but I’ll double-check.

Seems not same problem, root cause are different.

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


[clang] [clang][AST] fix dereference on class/struct layouts check. (PR #83686)

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

Endilll wrote:

I posted a different, even shorter reduction in 
https://github.com/llvm/llvm-project/issues/83671.

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


[clang] [Clang] [Sema] Do not attempt to dump the layout of dependent types when `-fdump-record-layouts-complete` is passed (PR #83688)

2024-03-03 Thread via cfe-commits

https://github.com/Sirraide updated 
https://github.com/llvm/llvm-project/pull/83688

>From 4abc148104769bd756042c73edeb7ee54397a05f Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Sat, 2 Mar 2024 20:41:22 +0100
Subject: [PATCH 1/4] [Clang] [Sema] Do not attempt to dump the layout of
 dependent types

---
 clang/lib/AST/Decl.cpp  |  2 +-
 clang/test/Layout/dump-complete.cpp | 29 -
 2 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 5d6bb72a208a1a..d069cd65732310 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -5042,7 +5042,7 @@ void RecordDecl::completeDefinition() {
 
   // Layouts are dumped when computed, so if we are dumping for all complete
   // types, we need to force usage to get types that wouldn't be used 
elsewhere.
-  if (Ctx.getLangOpts().DumpRecordLayoutsComplete)
+  if (Ctx.getLangOpts().DumpRecordLayoutsComplete && !isDependentType())
 (void)Ctx.getASTRecordLayout(this);
 }
 
diff --git a/clang/test/Layout/dump-complete.cpp 
b/clang/test/Layout/dump-complete.cpp
index 9ccbf477c7052e..0a91d3329e6921 100644
--- a/clang/test/Layout/dump-complete.cpp
+++ b/clang/test/Layout/dump-complete.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -emit-llvm-only -fdump-record-layouts-complete %s | 
FileCheck %s
+// RUN: %clang_cc1 -fsyntax-only -fdump-record-layouts-complete %s | FileCheck 
%s
 
 struct a {
   int x;
@@ -12,7 +12,34 @@ class c {};
 
 class d;
 
+template 
+struct s {
+  int x;
+};
+
+template 
+struct ts {
+  T x;
+};
+
+void f() {
+  ts a;
+  ts b;
+}
+
+namespace gh83684 {
+template 
+struct AllocationResult {
+  Pointer ptr = nullptr;
+  int count = 0;
+};
+}
+
 // CHECK:  0 | struct a
 // CHECK:  0 | struct b
 // CHECK:  0 | class c
+// CHECK:  0 | struct ts
+// CHECK:  0 | struct ts
 // CHECK-NOT:  0 | class d
+// CHECK-NOT:  0 | struct s
+// CHECK-NOT:  0 | struct AllocationResult

>From 3056a8414cae4648a3cc8244cacef29e6dc00564 Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Sat, 2 Mar 2024 20:45:24 +0100
Subject: [PATCH 2/4] [Clang] Add release note

---
 clang/docs/ReleaseNotes.rst | 4 
 1 file changed, 4 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f44fef28b9f17f..69cf0cb643e6aa 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -308,6 +308,10 @@ Miscellaneous Bug Fixes
 Miscellaneous Clang Crashes Fixed
 ^
 
+- Do not attempt to dump the layout of dependent types when 
``-fdump-record-layouts-complete``
+  is passed.
+  Fixes (`#83684 `_).
+
 OpenACC Specific Changes
 
 

>From cdf14b7cef9e08d932b649dc2724362aeea56a40 Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Sun, 3 Mar 2024 10:44:38 +0100
Subject: [PATCH 3/4] [Clang] Add comment and test case for explicit
 specialisation

---
 clang/lib/AST/Decl.cpp  | 3 +++
 clang/test/Layout/dump-complete.cpp | 8 
 2 files changed, 11 insertions(+)

diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index d069cd65732310..a3e4e13ffdc74d 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -5042,6 +5042,9 @@ void RecordDecl::completeDefinition() {
 
   // Layouts are dumped when computed, so if we are dumping for all complete
   // types, we need to force usage to get types that wouldn't be used 
elsewhere.
+  //
+  // If the type is dependent, then we can't compute its layout because there
+  // is no way for us to know the size or alignment of a dependent type.
   if (Ctx.getLangOpts().DumpRecordLayoutsComplete && !isDependentType())
 (void)Ctx.getASTRecordLayout(this);
 }
diff --git a/clang/test/Layout/dump-complete.cpp 
b/clang/test/Layout/dump-complete.cpp
index 0a91d3329e6921..7fed145084dccb 100644
--- a/clang/test/Layout/dump-complete.cpp
+++ b/clang/test/Layout/dump-complete.cpp
@@ -22,9 +22,15 @@ struct ts {
   T x;
 };
 
+template <>
+struct ts {
+  float f;
+};
+
 void f() {
   ts a;
   ts b;
+  ts c;
 }
 
 namespace gh83684 {
@@ -38,6 +44,8 @@ struct AllocationResult {
 // CHECK:  0 | struct a
 // CHECK:  0 | struct b
 // CHECK:  0 | class c
+// CHECK:  0 | struct ts
+// CHECK-NEXT: 0 |   float
 // CHECK:  0 | struct ts
 // CHECK:  0 | struct ts
 // CHECK-NOT:  0 | class d

>From ac9b16aa4a26a9926e221937fc48150640acd09e Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Sun, 3 Mar 2024 11:16:04 +0100
Subject: [PATCH 4/4] [Clang] Don't try to print the layout of an invalid decl

---
 clang/lib/AST/Decl.cpp  | 7 +--
 clang/test/Layout/dump-complete-invalid.cpp | 6 ++
 2 files changed, 11 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Layout/dump-complete-invalid.cpp

diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index a3e4e

[clang] [Clang] [Sema] Do not attempt to dump the layout of dependent types when `-fdump-record-layouts-complete` is passed (PR #83688)

2024-03-03 Thread via cfe-commits

https://github.com/Sirraide updated 
https://github.com/llvm/llvm-project/pull/83688

>From 4abc148104769bd756042c73edeb7ee54397a05f Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Sat, 2 Mar 2024 20:41:22 +0100
Subject: [PATCH 1/5] [Clang] [Sema] Do not attempt to dump the layout of
 dependent types

---
 clang/lib/AST/Decl.cpp  |  2 +-
 clang/test/Layout/dump-complete.cpp | 29 -
 2 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 5d6bb72a208a1a..d069cd65732310 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -5042,7 +5042,7 @@ void RecordDecl::completeDefinition() {
 
   // Layouts are dumped when computed, so if we are dumping for all complete
   // types, we need to force usage to get types that wouldn't be used 
elsewhere.
-  if (Ctx.getLangOpts().DumpRecordLayoutsComplete)
+  if (Ctx.getLangOpts().DumpRecordLayoutsComplete && !isDependentType())
 (void)Ctx.getASTRecordLayout(this);
 }
 
diff --git a/clang/test/Layout/dump-complete.cpp 
b/clang/test/Layout/dump-complete.cpp
index 9ccbf477c7052e..0a91d3329e6921 100644
--- a/clang/test/Layout/dump-complete.cpp
+++ b/clang/test/Layout/dump-complete.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -emit-llvm-only -fdump-record-layouts-complete %s | 
FileCheck %s
+// RUN: %clang_cc1 -fsyntax-only -fdump-record-layouts-complete %s | FileCheck 
%s
 
 struct a {
   int x;
@@ -12,7 +12,34 @@ class c {};
 
 class d;
 
+template 
+struct s {
+  int x;
+};
+
+template 
+struct ts {
+  T x;
+};
+
+void f() {
+  ts a;
+  ts b;
+}
+
+namespace gh83684 {
+template 
+struct AllocationResult {
+  Pointer ptr = nullptr;
+  int count = 0;
+};
+}
+
 // CHECK:  0 | struct a
 // CHECK:  0 | struct b
 // CHECK:  0 | class c
+// CHECK:  0 | struct ts
+// CHECK:  0 | struct ts
 // CHECK-NOT:  0 | class d
+// CHECK-NOT:  0 | struct s
+// CHECK-NOT:  0 | struct AllocationResult

>From 3056a8414cae4648a3cc8244cacef29e6dc00564 Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Sat, 2 Mar 2024 20:45:24 +0100
Subject: [PATCH 2/5] [Clang] Add release note

---
 clang/docs/ReleaseNotes.rst | 4 
 1 file changed, 4 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f44fef28b9f17f..69cf0cb643e6aa 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -308,6 +308,10 @@ Miscellaneous Bug Fixes
 Miscellaneous Clang Crashes Fixed
 ^
 
+- Do not attempt to dump the layout of dependent types when 
``-fdump-record-layouts-complete``
+  is passed.
+  Fixes (`#83684 `_).
+
 OpenACC Specific Changes
 
 

>From cdf14b7cef9e08d932b649dc2724362aeea56a40 Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Sun, 3 Mar 2024 10:44:38 +0100
Subject: [PATCH 3/5] [Clang] Add comment and test case for explicit
 specialisation

---
 clang/lib/AST/Decl.cpp  | 3 +++
 clang/test/Layout/dump-complete.cpp | 8 
 2 files changed, 11 insertions(+)

diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index d069cd65732310..a3e4e13ffdc74d 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -5042,6 +5042,9 @@ void RecordDecl::completeDefinition() {
 
   // Layouts are dumped when computed, so if we are dumping for all complete
   // types, we need to force usage to get types that wouldn't be used 
elsewhere.
+  //
+  // If the type is dependent, then we can't compute its layout because there
+  // is no way for us to know the size or alignment of a dependent type.
   if (Ctx.getLangOpts().DumpRecordLayoutsComplete && !isDependentType())
 (void)Ctx.getASTRecordLayout(this);
 }
diff --git a/clang/test/Layout/dump-complete.cpp 
b/clang/test/Layout/dump-complete.cpp
index 0a91d3329e6921..7fed145084dccb 100644
--- a/clang/test/Layout/dump-complete.cpp
+++ b/clang/test/Layout/dump-complete.cpp
@@ -22,9 +22,15 @@ struct ts {
   T x;
 };
 
+template <>
+struct ts {
+  float f;
+};
+
 void f() {
   ts a;
   ts b;
+  ts c;
 }
 
 namespace gh83684 {
@@ -38,6 +44,8 @@ struct AllocationResult {
 // CHECK:  0 | struct a
 // CHECK:  0 | struct b
 // CHECK:  0 | class c
+// CHECK:  0 | struct ts
+// CHECK-NEXT: 0 |   float
 // CHECK:  0 | struct ts
 // CHECK:  0 | struct ts
 // CHECK-NOT:  0 | class d

>From ac9b16aa4a26a9926e221937fc48150640acd09e Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Sun, 3 Mar 2024 11:16:04 +0100
Subject: [PATCH 4/5] [Clang] Don't try to print the layout of an invalid decl

---
 clang/lib/AST/Decl.cpp  | 7 +--
 clang/test/Layout/dump-complete-invalid.cpp | 6 ++
 2 files changed, 11 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Layout/dump-complete-invalid.cpp

diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index a3e4e

[clang] [Clang] [Sema] Do not attempt to dump the layout of dependent types when `-fdump-record-layouts-complete` is passed (PR #83688)

2024-03-03 Thread via cfe-commits

Sirraide wrote:

> This might also fix #83671

Actually, it seems to fix your reduced test case, hmm...

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


[clang] [clang][AST] fix dereference on class/struct layouts check. (PR #83686)

2024-03-03 Thread via cfe-commits

Sirraide wrote:

> it seems [there is an ongoing 
> fix](https://github.com/llvm/llvm-project/pull/83688), could you possibly try 
> so we can just close this one.

Yeah, it seems that the pr I opened for #83684 also fixes both the reduced test 
cases for this issue (and it also doesn’t crash anymore if I try to compile the 
file that was linked in the issue), though it should be noted that that’s only 
after I noticed that there was another problem and fixed that too. 

I think we should be able to close this one, unless someone comes up with a 
test case that still crashes anyway.

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


[clang] [Clang] [Sema] Do not attempt to dump the layout of dependent types when `-fdump-record-layouts-complete` is passed (PR #83688)

2024-03-03 Thread via cfe-commits

https://github.com/Sirraide updated 
https://github.com/llvm/llvm-project/pull/83688

>From 4abc148104769bd756042c73edeb7ee54397a05f Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Sat, 2 Mar 2024 20:41:22 +0100
Subject: [PATCH 1/6] [Clang] [Sema] Do not attempt to dump the layout of
 dependent types

---
 clang/lib/AST/Decl.cpp  |  2 +-
 clang/test/Layout/dump-complete.cpp | 29 -
 2 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 5d6bb72a208a1a..d069cd65732310 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -5042,7 +5042,7 @@ void RecordDecl::completeDefinition() {
 
   // Layouts are dumped when computed, so if we are dumping for all complete
   // types, we need to force usage to get types that wouldn't be used 
elsewhere.
-  if (Ctx.getLangOpts().DumpRecordLayoutsComplete)
+  if (Ctx.getLangOpts().DumpRecordLayoutsComplete && !isDependentType())
 (void)Ctx.getASTRecordLayout(this);
 }
 
diff --git a/clang/test/Layout/dump-complete.cpp 
b/clang/test/Layout/dump-complete.cpp
index 9ccbf477c7052e..0a91d3329e6921 100644
--- a/clang/test/Layout/dump-complete.cpp
+++ b/clang/test/Layout/dump-complete.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -emit-llvm-only -fdump-record-layouts-complete %s | 
FileCheck %s
+// RUN: %clang_cc1 -fsyntax-only -fdump-record-layouts-complete %s | FileCheck 
%s
 
 struct a {
   int x;
@@ -12,7 +12,34 @@ class c {};
 
 class d;
 
+template 
+struct s {
+  int x;
+};
+
+template 
+struct ts {
+  T x;
+};
+
+void f() {
+  ts a;
+  ts b;
+}
+
+namespace gh83684 {
+template 
+struct AllocationResult {
+  Pointer ptr = nullptr;
+  int count = 0;
+};
+}
+
 // CHECK:  0 | struct a
 // CHECK:  0 | struct b
 // CHECK:  0 | class c
+// CHECK:  0 | struct ts
+// CHECK:  0 | struct ts
 // CHECK-NOT:  0 | class d
+// CHECK-NOT:  0 | struct s
+// CHECK-NOT:  0 | struct AllocationResult

>From 3056a8414cae4648a3cc8244cacef29e6dc00564 Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Sat, 2 Mar 2024 20:45:24 +0100
Subject: [PATCH 2/6] [Clang] Add release note

---
 clang/docs/ReleaseNotes.rst | 4 
 1 file changed, 4 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f44fef28b9f17f..69cf0cb643e6aa 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -308,6 +308,10 @@ Miscellaneous Bug Fixes
 Miscellaneous Clang Crashes Fixed
 ^
 
+- Do not attempt to dump the layout of dependent types when 
``-fdump-record-layouts-complete``
+  is passed.
+  Fixes (`#83684 `_).
+
 OpenACC Specific Changes
 
 

>From cdf14b7cef9e08d932b649dc2724362aeea56a40 Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Sun, 3 Mar 2024 10:44:38 +0100
Subject: [PATCH 3/6] [Clang] Add comment and test case for explicit
 specialisation

---
 clang/lib/AST/Decl.cpp  | 3 +++
 clang/test/Layout/dump-complete.cpp | 8 
 2 files changed, 11 insertions(+)

diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index d069cd65732310..a3e4e13ffdc74d 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -5042,6 +5042,9 @@ void RecordDecl::completeDefinition() {
 
   // Layouts are dumped when computed, so if we are dumping for all complete
   // types, we need to force usage to get types that wouldn't be used 
elsewhere.
+  //
+  // If the type is dependent, then we can't compute its layout because there
+  // is no way for us to know the size or alignment of a dependent type.
   if (Ctx.getLangOpts().DumpRecordLayoutsComplete && !isDependentType())
 (void)Ctx.getASTRecordLayout(this);
 }
diff --git a/clang/test/Layout/dump-complete.cpp 
b/clang/test/Layout/dump-complete.cpp
index 0a91d3329e6921..7fed145084dccb 100644
--- a/clang/test/Layout/dump-complete.cpp
+++ b/clang/test/Layout/dump-complete.cpp
@@ -22,9 +22,15 @@ struct ts {
   T x;
 };
 
+template <>
+struct ts {
+  float f;
+};
+
 void f() {
   ts a;
   ts b;
+  ts c;
 }
 
 namespace gh83684 {
@@ -38,6 +44,8 @@ struct AllocationResult {
 // CHECK:  0 | struct a
 // CHECK:  0 | struct b
 // CHECK:  0 | class c
+// CHECK:  0 | struct ts
+// CHECK-NEXT: 0 |   float
 // CHECK:  0 | struct ts
 // CHECK:  0 | struct ts
 // CHECK-NOT:  0 | class d

>From ac9b16aa4a26a9926e221937fc48150640acd09e Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Sun, 3 Mar 2024 11:16:04 +0100
Subject: [PATCH 4/6] [Clang] Don't try to print the layout of an invalid decl

---
 clang/lib/AST/Decl.cpp  | 7 +--
 clang/test/Layout/dump-complete-invalid.cpp | 6 ++
 2 files changed, 11 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Layout/dump-complete-invalid.cpp

diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index a3e4e

[clang] [Clang] [Sema] Do not attempt to dump the layout of dependent types when `-fdump-record-layouts-complete` is passed (PR #83688)

2024-03-03 Thread via cfe-commits

Sirraide wrote:

So yeah, this pr indeed also seems to fix #83671 as well.

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


[clang] [clang][AST] fix dereference on class/struct layouts check. (PR #83686)

2024-03-03 Thread David CARLIER via cfe-commits

https://github.com/devnexen closed 
https://github.com/llvm/llvm-project/pull/83686
___
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 bugprone-suspicious-stringview-data-usage check (PR #83716)

2024-03-03 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL created 
https://github.com/llvm/llvm-project/pull/83716

This check identifies suspicious usages of std::string_view::data() that could 
lead to reading out-of-bounds data due to inadequate or incorrect string null 
termination.

Closes #80854

>From ce8017e7db56a43f2e015fccc2d1c8d8df8dada0 Mon Sep 17 00:00:00 2001
From: Piotr Zegar 
Date: Tue, 20 Feb 2024 18:15:56 +
Subject: [PATCH] [clang-tidy] Add bugprone-suspicious-stringview-data-usage
 check

This check identifies suspicious usages of std::string_view::data()
that could lead to reading out-of-bounds data due to inadequate or
incorrect string null termination.
---
 .../bugprone/BugproneTidyModule.cpp   |   3 +
 .../clang-tidy/bugprone/CMakeLists.txt|   1 +
 .../SuspiciousStringviewDataUsageCheck.cpp| 100 ++
 .../SuspiciousStringviewDataUsageCheck.h  |  38 +++
 clang-tools-extra/docs/ReleaseNotes.rst   |   7 ++
 .../suspicious-stringview-data-usage.rst  |  58 ++
 .../docs/clang-tidy/checks/list.rst   |   1 +
 .../clang-tidy/checkers/Inputs/Headers/string |   7 ++
 .../suspicious-stringview-data-usage.cpp  |  48 +
 9 files changed, 263 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/SuspiciousStringviewDataUsageCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/SuspiciousStringviewDataUsageCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-stringview-data-usage.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-stringview-data-usage.cpp

diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index a8a23b045f80bb..4040399edbcb81 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -72,6 +72,7 @@
 #include "SuspiciousReallocUsageCheck.h"
 #include "SuspiciousSemicolonCheck.h"
 #include "SuspiciousStringCompareCheck.h"
+#include "SuspiciousStringviewDataUsageCheck.h"
 #include "SwappedArgumentsCheck.h"
 #include "SwitchMissingDefaultCaseCheck.h"
 #include "TerminatingContinueCheck.h"
@@ -217,6 +218,8 @@ class BugproneModule : public ClangTidyModule {
 "bugprone-suspicious-semicolon");
 CheckFactories.registerCheck(
 "bugprone-suspicious-string-compare");
+CheckFactories.registerCheck(
+"bugprone-suspicious-stringview-data-usage");
 CheckFactories.registerCheck(
 "bugprone-swapped-arguments");
 CheckFactories.registerCheck(
diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index 1cd6fb207d7625..db65ce8cb1567b 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -26,6 +26,7 @@ add_clang_library(clangTidyBugproneModule
   ImplicitWideningOfMultiplicationResultCheck.cpp
   InaccurateEraseCheck.cpp
   IncorrectEnableIfCheck.cpp
+  SuspiciousStringviewDataUsageCheck.cpp
   SwitchMissingDefaultCaseCheck.cpp
   IncDecInConditionsCheck.cpp
   IncorrectRoundingsCheck.cpp
diff --git 
a/clang-tools-extra/clang-tidy/bugprone/SuspiciousStringviewDataUsageCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/SuspiciousStringviewDataUsageCheck.cpp
new file mode 100644
index 00..ffb31840c4c886
--- /dev/null
+++ 
b/clang-tools-extra/clang-tidy/bugprone/SuspiciousStringviewDataUsageCheck.cpp
@@ -0,0 +1,100 @@
+//===--- SuspiciousStringviewDataUsageCheck.cpp - clang-tidy 
--===//
+//
+// 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 "SuspiciousStringviewDataUsageCheck.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+SuspiciousStringviewDataUsageCheck::SuspiciousStringviewDataUsageCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  StringViewTypes(utils::options::parseStringList(Options.get(
+  "StringViewTypes", "::std::basic_string_view;::llvm::StringRef"))),
+  AllowedCallees(
+  utils::options::parseStringList(Options.get("AllowedCallees", ""))) 
{}
+
+void SuspiciousStringviewDataUsageCheck::storeOptions(
+ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "StringViewTypes",
+utils::options::serializeStringList(StringViewTypes));
+  Options.store(Opts, "AllowedCallees",
+utils::options::serializeStringList(AllowedCallees

[clang-tools-extra] [clang-tidy] Add bugprone-suspicious-stringview-data-usage check (PR #83716)

2024-03-03 Thread via cfe-commits

llvmbot wrote:




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

Author: Piotr Zegar (PiotrZSL)


Changes

This check identifies suspicious usages of std::string_view::data() that could 
lead to reading out-of-bounds data due to inadequate or incorrect string null 
termination.

Closes #80854

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


9 Files Affected:

- (modified) clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp (+3) 
- (modified) clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt (+1) 
- (added) 
clang-tools-extra/clang-tidy/bugprone/SuspiciousStringviewDataUsageCheck.cpp 
(+100) 
- (added) 
clang-tools-extra/clang-tidy/bugprone/SuspiciousStringviewDataUsageCheck.h 
(+38) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+7) 
- (added) 
clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-stringview-data-usage.rst
 (+58) 
- (modified) clang-tools-extra/docs/clang-tidy/checks/list.rst (+1) 
- (modified) clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string 
(+7) 
- (added) 
clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-stringview-data-usage.cpp
 (+48) 


``diff
diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index a8a23b045f80bb..4040399edbcb81 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -72,6 +72,7 @@
 #include "SuspiciousReallocUsageCheck.h"
 #include "SuspiciousSemicolonCheck.h"
 #include "SuspiciousStringCompareCheck.h"
+#include "SuspiciousStringviewDataUsageCheck.h"
 #include "SwappedArgumentsCheck.h"
 #include "SwitchMissingDefaultCaseCheck.h"
 #include "TerminatingContinueCheck.h"
@@ -217,6 +218,8 @@ class BugproneModule : public ClangTidyModule {
 "bugprone-suspicious-semicolon");
 CheckFactories.registerCheck(
 "bugprone-suspicious-string-compare");
+CheckFactories.registerCheck(
+"bugprone-suspicious-stringview-data-usage");
 CheckFactories.registerCheck(
 "bugprone-swapped-arguments");
 CheckFactories.registerCheck(
diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index 1cd6fb207d7625..db65ce8cb1567b 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -26,6 +26,7 @@ add_clang_library(clangTidyBugproneModule
   ImplicitWideningOfMultiplicationResultCheck.cpp
   InaccurateEraseCheck.cpp
   IncorrectEnableIfCheck.cpp
+  SuspiciousStringviewDataUsageCheck.cpp
   SwitchMissingDefaultCaseCheck.cpp
   IncDecInConditionsCheck.cpp
   IncorrectRoundingsCheck.cpp
diff --git 
a/clang-tools-extra/clang-tidy/bugprone/SuspiciousStringviewDataUsageCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/SuspiciousStringviewDataUsageCheck.cpp
new file mode 100644
index 00..ffb31840c4c886
--- /dev/null
+++ 
b/clang-tools-extra/clang-tidy/bugprone/SuspiciousStringviewDataUsageCheck.cpp
@@ -0,0 +1,100 @@
+//===--- SuspiciousStringviewDataUsageCheck.cpp - clang-tidy 
--===//
+//
+// 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 "SuspiciousStringviewDataUsageCheck.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+SuspiciousStringviewDataUsageCheck::SuspiciousStringviewDataUsageCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  StringViewTypes(utils::options::parseStringList(Options.get(
+  "StringViewTypes", "::std::basic_string_view;::llvm::StringRef"))),
+  AllowedCallees(
+  utils::options::parseStringList(Options.get("AllowedCallees", ""))) 
{}
+
+void SuspiciousStringviewDataUsageCheck::storeOptions(
+ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "StringViewTypes",
+utils::options::serializeStringList(StringViewTypes));
+  Options.store(Opts, "AllowedCallees",
+utils::options::serializeStringList(AllowedCallees));
+}
+
+bool SuspiciousStringviewDataUsageCheck::isLanguageVersionSupported(
+const LangOptions &LangOpts) const {
+  return LangOpts.CPlusPlus;
+}
+
+std::optional
+SuspiciousStringviewDataUsageCheck::getCheckTraversalKind() const {
+  return TK_AsIs;
+}
+
+void SuspiciousStringviewDataUsageCheck::registerMatchers(MatchFinder *Finder) 
{
+
+  auto AncestorCall = anyOf(
+  cxxConstructExpr(), callExpr(unless(cxxOperatorCallExpr())), 
lambdaExpr(),
+  initListExpr(

[clang-tools-extra] [clang-tidy] Add bugprone-suspicious-stringview-data-usage check (PR #83716)

2024-03-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: Piotr Zegar (PiotrZSL)


Changes

This check identifies suspicious usages of std::string_view::data() that could 
lead to reading out-of-bounds data due to inadequate or incorrect string null 
termination.

Closes #80854

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


9 Files Affected:

- (modified) clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp (+3) 
- (modified) clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt (+1) 
- (added) 
clang-tools-extra/clang-tidy/bugprone/SuspiciousStringviewDataUsageCheck.cpp 
(+100) 
- (added) 
clang-tools-extra/clang-tidy/bugprone/SuspiciousStringviewDataUsageCheck.h 
(+38) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+7) 
- (added) 
clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-stringview-data-usage.rst
 (+58) 
- (modified) clang-tools-extra/docs/clang-tidy/checks/list.rst (+1) 
- (modified) clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string 
(+7) 
- (added) 
clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-stringview-data-usage.cpp
 (+48) 


``diff
diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index a8a23b045f80bb..4040399edbcb81 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -72,6 +72,7 @@
 #include "SuspiciousReallocUsageCheck.h"
 #include "SuspiciousSemicolonCheck.h"
 #include "SuspiciousStringCompareCheck.h"
+#include "SuspiciousStringviewDataUsageCheck.h"
 #include "SwappedArgumentsCheck.h"
 #include "SwitchMissingDefaultCaseCheck.h"
 #include "TerminatingContinueCheck.h"
@@ -217,6 +218,8 @@ class BugproneModule : public ClangTidyModule {
 "bugprone-suspicious-semicolon");
 CheckFactories.registerCheck(
 "bugprone-suspicious-string-compare");
+CheckFactories.registerCheck(
+"bugprone-suspicious-stringview-data-usage");
 CheckFactories.registerCheck(
 "bugprone-swapped-arguments");
 CheckFactories.registerCheck(
diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index 1cd6fb207d7625..db65ce8cb1567b 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -26,6 +26,7 @@ add_clang_library(clangTidyBugproneModule
   ImplicitWideningOfMultiplicationResultCheck.cpp
   InaccurateEraseCheck.cpp
   IncorrectEnableIfCheck.cpp
+  SuspiciousStringviewDataUsageCheck.cpp
   SwitchMissingDefaultCaseCheck.cpp
   IncDecInConditionsCheck.cpp
   IncorrectRoundingsCheck.cpp
diff --git 
a/clang-tools-extra/clang-tidy/bugprone/SuspiciousStringviewDataUsageCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/SuspiciousStringviewDataUsageCheck.cpp
new file mode 100644
index 00..ffb31840c4c886
--- /dev/null
+++ 
b/clang-tools-extra/clang-tidy/bugprone/SuspiciousStringviewDataUsageCheck.cpp
@@ -0,0 +1,100 @@
+//===--- SuspiciousStringviewDataUsageCheck.cpp - clang-tidy 
--===//
+//
+// 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 "SuspiciousStringviewDataUsageCheck.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+SuspiciousStringviewDataUsageCheck::SuspiciousStringviewDataUsageCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  StringViewTypes(utils::options::parseStringList(Options.get(
+  "StringViewTypes", "::std::basic_string_view;::llvm::StringRef"))),
+  AllowedCallees(
+  utils::options::parseStringList(Options.get("AllowedCallees", ""))) 
{}
+
+void SuspiciousStringviewDataUsageCheck::storeOptions(
+ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "StringViewTypes",
+utils::options::serializeStringList(StringViewTypes));
+  Options.store(Opts, "AllowedCallees",
+utils::options::serializeStringList(AllowedCallees));
+}
+
+bool SuspiciousStringviewDataUsageCheck::isLanguageVersionSupported(
+const LangOptions &LangOpts) const {
+  return LangOpts.CPlusPlus;
+}
+
+std::optional
+SuspiciousStringviewDataUsageCheck::getCheckTraversalKind() const {
+  return TK_AsIs;
+}
+
+void SuspiciousStringviewDataUsageCheck::registerMatchers(MatchFinder *Finder) 
{
+
+  auto AncestorCall = anyOf(
+  cxxConstructExpr(), callExpr(unless(cxxOperatorCallExpr())), 
lambdaExpr(),
+  initListExpr(
+ 

[clang-tools-extra] eb3b063 - [clang-tidy] Improve `google-explicit-constructor` checks handling of `explicit(bool)` (#82689)

2024-03-03 Thread via cfe-commits

Author: AMS21
Date: 2024-03-03T12:13:25+01:00
New Revision: eb3b063995d6b4f8f3bc22eeecbf239ffaecc29f

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

LOG: [clang-tidy] Improve `google-explicit-constructor` checks handling of 
`explicit(bool)` (#82689)

We now treat `explicit(false)` the same way we treat `noexcept(false)`
in the noexcept checks, which is ignoring it.

Also introduced a new warning message if a constructor has an `explicit`
declaration which evaluates to false and no longer emit a faulty FixIt.

Fixes #81121

Added: 

clang-tools-extra/test/clang-tidy/checkers/google/explicit-constructor-cxx20.cpp

Modified: 
clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp 
b/clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp
index 34d49af9f81e23..6f26de9881357f 100644
--- a/clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp
+++ b/clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp
@@ -79,8 +79,10 @@ static bool isStdInitializerList(QualType Type) {
 }
 
 void ExplicitConstructorCheck::check(const MatchFinder::MatchResult &Result) {
-  constexpr char WarningMessage[] =
+  constexpr char NoExpressionWarningMessage[] =
   "%0 must be marked explicit to avoid unintentional implicit conversions";
+  constexpr char WithExpressionWarningMessage[] =
+  "%0 explicit expression evaluates to 'false'";
 
   if (const auto *Conversion =
   Result.Nodes.getNodeAs("conversion")) {
@@ -91,7 +93,7 @@ void ExplicitConstructorCheck::check(const 
MatchFinder::MatchResult &Result) {
 // gmock to define matchers).
 if (Loc.isMacroID())
   return;
-diag(Loc, WarningMessage)
+diag(Loc, NoExpressionWarningMessage)
 << Conversion << FixItHint::CreateInsertion(Loc, "explicit ");
 return;
   }
@@ -101,9 +103,11 @@ void ExplicitConstructorCheck::check(const 
MatchFinder::MatchResult &Result) {
   Ctor->getMinRequiredArguments() > 1)
 return;
 
+  const ExplicitSpecifier ExplicitSpec = Ctor->getExplicitSpecifier();
+
   bool TakesInitializerList = isStdInitializerList(
   Ctor->getParamDecl(0)->getType().getNonReferenceType());
-  if (Ctor->isExplicit() &&
+  if (ExplicitSpec.isExplicit() &&
   (Ctor->isCopyOrMoveConstructor() || TakesInitializerList)) {
 auto IsKwExplicit = [](const Token &Tok) {
   return Tok.is(tok::raw_identifier) &&
@@ -130,18 +134,31 @@ void ExplicitConstructorCheck::check(const 
MatchFinder::MatchResult &Result) {
 return;
   }
 
-  if (Ctor->isExplicit() || Ctor->isCopyOrMoveConstructor() ||
+  if (ExplicitSpec.isExplicit() || Ctor->isCopyOrMoveConstructor() ||
   TakesInitializerList)
 return;
 
-  bool SingleArgument =
+  // Don't complain about explicit(false) or dependent expressions
+  const Expr *ExplicitExpr = ExplicitSpec.getExpr();
+  if (ExplicitExpr) {
+ExplicitExpr = ExplicitExpr->IgnoreImplicit();
+if (isa(ExplicitExpr) ||
+ExplicitExpr->isInstantiationDependent())
+  return;
+  }
+
+  const bool SingleArgument =
   Ctor->getNumParams() == 1 && !Ctor->getParamDecl(0)->isParameterPack();
   SourceLocation Loc = Ctor->getLocation();
-  diag(Loc, WarningMessage)
+  auto Diag =
+  diag(Loc, ExplicitExpr ? WithExpressionWarningMessage
+ : NoExpressionWarningMessage)
   << (SingleArgument
   ? "single-argument constructors"
-  : "constructors that are callable with a single argument")
-  << FixItHint::CreateInsertion(Loc, "explicit ");
+  : "constructors that are callable with a single argument");
+
+  if (!ExplicitExpr)
+Diag << FixItHint::CreateInsertion(Loc, "explicit ");
 }
 
 } // namespace clang::tidy::google

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 5bae530e942384..0d2467210fc664 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -157,6 +157,10 @@ Changes in existing checks
   ` check by replacing the local
   option `HeaderFileExtensions` by the global option of the same name.
 
+- Improved :doc:`google-explicit-constructor
+  ` check to better handle
+  ``C++-20`` `explicit(bool)`.
+
 - Improved :doc:`google-global-names-in-headers
   ` check by replacing the 
local
   option `HeaderFileExtensions` by the global option of the same name.

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/google/explicit-constructor-cxx20.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/google/explicit-constructor-cxx20.cpp
new file mode 100644
index 00..95206f1ef420c3
--- /dev/n

[clang-tools-extra] [clang-tidy] Improve `google-explicit-constructor` checks handling of `explicit(bool)` (PR #82689)

2024-03-03 Thread Piotr Zegar via cfe-commits

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


[clang] [Clang][Sema] Fix missing warning when comparing mismatched enums in … (PR #81418)

2024-03-03 Thread via cfe-commits

Kupa-Martin wrote:

@stbergmann is right. @erichkeane How should I proceed? Should I open a revert 
PR? Or should I open a separate issue?

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


[clang] [Clang][Driver] Merge the different strategies of how libc++ is included (PR #83721)

2024-03-03 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 created 
https://github.com/llvm/llvm-project/pull/83721

None

>From 756f80f22744bb0f2bfb81e6c4010054f1279337 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Fri, 1 Mar 2024 20:49:30 +0100
Subject: [PATCH] [Clang][Driver] Merge the different strategies of how libc++
 is included

---
 clang/include/clang/Driver/ToolChain.h   | 41 
 clang/lib/Driver/ToolChain.cpp   | 41 
 clang/lib/Driver/ToolChains/AIX.cpp  | 10 ++---
 clang/lib/Driver/ToolChains/BareMetal.cpp| 13 +++
 clang/lib/Driver/ToolChains/CrossWindows.cpp |  3 +-
 clang/lib/Driver/ToolChains/Darwin.cpp   | 32 ++-
 clang/lib/Driver/ToolChains/FreeBSD.cpp  |  5 ++-
 clang/lib/Driver/ToolChains/Fuchsia.cpp  | 22 ++-
 clang/lib/Driver/ToolChains/Gnu.cpp  |  6 +--
 clang/lib/Driver/ToolChains/Haiku.cpp|  5 ++-
 clang/lib/Driver/ToolChains/Hexagon.cpp  | 27 -
 clang/lib/Driver/ToolChains/MinGW.cpp| 16 +++-
 clang/lib/Driver/ToolChains/MipsLinux.cpp|  7 ++--
 clang/lib/Driver/ToolChains/NaCl.cpp | 16 
 clang/lib/Driver/ToolChains/NetBSD.cpp   | 20 +-
 clang/lib/Driver/ToolChains/OHOS.cpp |  9 ++---
 clang/lib/Driver/ToolChains/OpenBSD.cpp  |  5 ++-
 clang/lib/Driver/ToolChains/WebAssembly.cpp  |  4 +-
 clang/lib/Driver/ToolChains/ZOS.cpp  | 22 ---
 clang/lib/Driver/ToolChains/ZOS.h|  3 --
 20 files changed, 178 insertions(+), 129 deletions(-)

diff --git a/clang/include/clang/Driver/ToolChain.h 
b/clang/include/clang/Driver/ToolChain.h
index fbe2e8fe8e88d8..c61cf2aa064ed5 100644
--- a/clang/include/clang/Driver/ToolChain.h
+++ b/clang/include/clang/Driver/ToolChain.h
@@ -705,6 +705,47 @@ class ToolChain {
   AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const;
 
+  struct IncludeStrategy {
+enum AvailabilityOptions {
+  // Check whether the directory is exists before adding it to the
+  // include path. This is the case if AssumeAvailable isn't set.
+  CheckIfAvailable,
+
+  // Don't check whether the directory exists. Just assume it does and add
+  // the include.
+  AssumeAvailable,
+
+  // Use v that is inside `/c++`. If not set, 
always
+  // uses v1.
+  UseMaxVersionAvailable,
+};
+
+IncludeStrategy(AvailabilityOptions Availability,
+bool AddTargetDirIfAvailable = false,
+bool PrintDebugStatements = false)
+: Availability(Availability),
+  AddTargetDirIfAvailable(AddTargetDirIfAvailable),
+  PrintDebugStatements(PrintDebugStatements) {}
+
+LLVM_PREFERRED_TYPE(AvailabilityOptions)
+unsigned Availability : 2;
+
+// Check whether the directory `//c++/v`
+// exists, and add it to the include path if it does.
+LLVM_PREFERRED_TYPE(bool)
+unsigned AddTargetDirIfAvailable : 1;
+
+// Whether to print a message if a checked directory isn't available.
+LLVM_PREFERRED_TYPE(bool)
+unsigned PrintDebugStatements : 1;
+  };
+
+  /// Helper function to implement AddClangCXXStdlibIncludeArgs for libc++.
+  bool AddLibcxxInclude(const llvm::opt::ArgList &DriverArgs,
+llvm::opt::ArgStringList &CC1Args,
+llvm::Twine IncludeRoot,
+IncludeStrategy Strategy) const;
+
   /// AddClangCXXStdlibIsystemArgs - Add the clang -cc1 level arguments to set
   /// the specified include paths for the C++ standard library.
   void AddClangCXXStdlibIsystemArgs(const llvm::opt::ArgList &DriverArgs,
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 08b1fd01b3c0ac..42c9d6e91d3c35 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -40,6 +40,7 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/FileUtilities.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/WithColor.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/TargetParser/AArch64TargetParser.h"
@@ -1250,6 +1251,46 @@ void ToolChain::AddClangCXXStdlibIncludeArgs(const 
ArgList &DriverArgs,
   DriverArgs.AddAllArgs(CC1Args, options::OPT_stdlib_EQ);
 }
 
+bool ToolChain::AddLibcxxInclude(const llvm::opt::ArgList &DriverArgs,
+ llvm::opt::ArgStringList &CC1Args,
+ llvm::Twine IncludeRoot,
+ IncludeStrategy Strategy) const {
+  SmallString<128> Path;
+  IncludeRoot.toVector(Path);
+
+  auto VersionDirName =
+  Strategy.Availability == IncludeStrategy::UseMaxVersionAvailable
+  ? detectLibcxxVersion(Path)
+  : "v1";
+
+  if (VersionDirName.empty())
+return false;
+
+  if (Strategy.AddTargetDirIfAvailable) {
+SmallString<128> T

[clang] [Clang][Driver] Merge the different strategies of how libc++ is included (PR #83721)

2024-03-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 b873847a53ae638e2146e3657fe33efe30c2afe1 
756f80f22744bb0f2bfb81e6c4010054f1279337 -- 
clang/include/clang/Driver/ToolChain.h clang/lib/Driver/ToolChain.cpp 
clang/lib/Driver/ToolChains/AIX.cpp clang/lib/Driver/ToolChains/BareMetal.cpp 
clang/lib/Driver/ToolChains/CrossWindows.cpp 
clang/lib/Driver/ToolChains/Darwin.cpp clang/lib/Driver/ToolChains/FreeBSD.cpp 
clang/lib/Driver/ToolChains/Fuchsia.cpp clang/lib/Driver/ToolChains/Gnu.cpp 
clang/lib/Driver/ToolChains/Haiku.cpp clang/lib/Driver/ToolChains/Hexagon.cpp 
clang/lib/Driver/ToolChains/MinGW.cpp clang/lib/Driver/ToolChains/MipsLinux.cpp 
clang/lib/Driver/ToolChains/NaCl.cpp clang/lib/Driver/ToolChains/NetBSD.cpp 
clang/lib/Driver/ToolChains/OHOS.cpp clang/lib/Driver/ToolChains/OpenBSD.cpp 
clang/lib/Driver/ToolChains/WebAssembly.cpp clang/lib/Driver/ToolChains/ZOS.cpp 
clang/lib/Driver/ToolChains/ZOS.h
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 42c9d6e91d..786110fc10 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -40,9 +40,9 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/FileUtilities.h"
 #include "llvm/Support/Path.h"
-#include "llvm/Support/WithColor.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/Support/VirtualFileSystem.h"
+#include "llvm/Support/WithColor.h"
 #include "llvm/TargetParser/AArch64TargetParser.h"
 #include "llvm/TargetParser/TargetParser.h"
 #include "llvm/TargetParser/Triple.h"
diff --git a/clang/lib/Driver/ToolChains/Hexagon.cpp 
b/clang/lib/Driver/ToolChains/Hexagon.cpp
index 7358c2a121..7f13c0745d 100644
--- a/clang/lib/Driver/ToolChains/Hexagon.cpp
+++ b/clang/lib/Driver/ToolChains/Hexagon.cpp
@@ -743,8 +743,7 @@ void HexagonToolChain::addLibCxxIncludePaths(
 // FIXME: Is this actually expected? (Same below)
 addSystemInclude(DriverArgs, CC1Args,
  D.SysRoot + "/usr/include/c++/v1/backward");
-  }
-  else if (getTriple().isMusl()) {
+  } else if (getTriple().isMusl()) {
 ToolChain::AddLibcxxInclude(DriverArgs, CC1Args, "/usr/include",
 IncludeStrategy::AssumeAvailable);
 addSystemInclude(DriverArgs, CC1Args, "/usr/include/c++/v1/backward");
diff --git a/clang/lib/Driver/ToolChains/NetBSD.cpp 
b/clang/lib/Driver/ToolChains/NetBSD.cpp
index f6ccde40b0..7508323906 100644
--- a/clang/lib/Driver/ToolChains/NetBSD.cpp
+++ b/clang/lib/Driver/ToolChains/NetBSD.cpp
@@ -494,10 +494,10 @@ void NetBSD::AddClangSystemIncludeArgs(
 void NetBSD::addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const {
   const std::string Candidates[] = {
-// directory relative to build tree
-concat(getDriver().Dir, "/../include"),
-// system install with full upstream path
-concat(getDriver().SysRoot, "/usr/include"),
+  // directory relative to build tree
+  concat(getDriver().Dir, "/../include"),
+  // system install with full upstream path
+  concat(getDriver().SysRoot, "/usr/include"),
   };
 
   for (const auto &IncludePath : Candidates) {

``




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


[clang] users/philnik777/add libcxx03 include strategy (PR #83723)

2024-03-03 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 created 
https://github.com/llvm/llvm-project/pull/83723

- [Clang][Driver] Merge the different strategies of how libc++ is included
- [Clang][Driver] Add special-casing for including libc++ in C++03


>From 756f80f22744bb0f2bfb81e6c4010054f1279337 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Fri, 1 Mar 2024 20:49:30 +0100
Subject: [PATCH 1/2] [Clang][Driver] Merge the different strategies of how
 libc++ is included

---
 clang/include/clang/Driver/ToolChain.h   | 41 
 clang/lib/Driver/ToolChain.cpp   | 41 
 clang/lib/Driver/ToolChains/AIX.cpp  | 10 ++---
 clang/lib/Driver/ToolChains/BareMetal.cpp| 13 +++
 clang/lib/Driver/ToolChains/CrossWindows.cpp |  3 +-
 clang/lib/Driver/ToolChains/Darwin.cpp   | 32 ++-
 clang/lib/Driver/ToolChains/FreeBSD.cpp  |  5 ++-
 clang/lib/Driver/ToolChains/Fuchsia.cpp  | 22 ++-
 clang/lib/Driver/ToolChains/Gnu.cpp  |  6 +--
 clang/lib/Driver/ToolChains/Haiku.cpp|  5 ++-
 clang/lib/Driver/ToolChains/Hexagon.cpp  | 27 -
 clang/lib/Driver/ToolChains/MinGW.cpp| 16 +++-
 clang/lib/Driver/ToolChains/MipsLinux.cpp|  7 ++--
 clang/lib/Driver/ToolChains/NaCl.cpp | 16 
 clang/lib/Driver/ToolChains/NetBSD.cpp   | 20 +-
 clang/lib/Driver/ToolChains/OHOS.cpp |  9 ++---
 clang/lib/Driver/ToolChains/OpenBSD.cpp  |  5 ++-
 clang/lib/Driver/ToolChains/WebAssembly.cpp  |  4 +-
 clang/lib/Driver/ToolChains/ZOS.cpp  | 22 ---
 clang/lib/Driver/ToolChains/ZOS.h|  3 --
 20 files changed, 178 insertions(+), 129 deletions(-)

diff --git a/clang/include/clang/Driver/ToolChain.h 
b/clang/include/clang/Driver/ToolChain.h
index fbe2e8fe8e88d8..c61cf2aa064ed5 100644
--- a/clang/include/clang/Driver/ToolChain.h
+++ b/clang/include/clang/Driver/ToolChain.h
@@ -705,6 +705,47 @@ class ToolChain {
   AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const;
 
+  struct IncludeStrategy {
+enum AvailabilityOptions {
+  // Check whether the directory is exists before adding it to the
+  // include path. This is the case if AssumeAvailable isn't set.
+  CheckIfAvailable,
+
+  // Don't check whether the directory exists. Just assume it does and add
+  // the include.
+  AssumeAvailable,
+
+  // Use v that is inside `/c++`. If not set, 
always
+  // uses v1.
+  UseMaxVersionAvailable,
+};
+
+IncludeStrategy(AvailabilityOptions Availability,
+bool AddTargetDirIfAvailable = false,
+bool PrintDebugStatements = false)
+: Availability(Availability),
+  AddTargetDirIfAvailable(AddTargetDirIfAvailable),
+  PrintDebugStatements(PrintDebugStatements) {}
+
+LLVM_PREFERRED_TYPE(AvailabilityOptions)
+unsigned Availability : 2;
+
+// Check whether the directory `//c++/v`
+// exists, and add it to the include path if it does.
+LLVM_PREFERRED_TYPE(bool)
+unsigned AddTargetDirIfAvailable : 1;
+
+// Whether to print a message if a checked directory isn't available.
+LLVM_PREFERRED_TYPE(bool)
+unsigned PrintDebugStatements : 1;
+  };
+
+  /// Helper function to implement AddClangCXXStdlibIncludeArgs for libc++.
+  bool AddLibcxxInclude(const llvm::opt::ArgList &DriverArgs,
+llvm::opt::ArgStringList &CC1Args,
+llvm::Twine IncludeRoot,
+IncludeStrategy Strategy) const;
+
   /// AddClangCXXStdlibIsystemArgs - Add the clang -cc1 level arguments to set
   /// the specified include paths for the C++ standard library.
   void AddClangCXXStdlibIsystemArgs(const llvm::opt::ArgList &DriverArgs,
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 08b1fd01b3c0ac..42c9d6e91d3c35 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -40,6 +40,7 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/FileUtilities.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/WithColor.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/TargetParser/AArch64TargetParser.h"
@@ -1250,6 +1251,46 @@ void ToolChain::AddClangCXXStdlibIncludeArgs(const 
ArgList &DriverArgs,
   DriverArgs.AddAllArgs(CC1Args, options::OPT_stdlib_EQ);
 }
 
+bool ToolChain::AddLibcxxInclude(const llvm::opt::ArgList &DriverArgs,
+ llvm::opt::ArgStringList &CC1Args,
+ llvm::Twine IncludeRoot,
+ IncludeStrategy Strategy) const {
+  SmallString<128> Path;
+  IncludeRoot.toVector(Path);
+
+  auto VersionDirName =
+  Strategy.Availability == IncludeStrategy::UseMaxVersionAvailable
+  ? detectLibcxxVersion(Pat

[clang] [Clang][Driver] Add special-casing for including libc++ in C++03 (PR #83723)

2024-03-03 Thread Nikolas Klauser via cfe-commits

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


[clang] [Clang][Driver] Add special-casing for including libc++ in C++03 (PR #83723)

2024-03-03 Thread Nikolas Klauser via cfe-commits

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


[clang-tools-extra] [clang-tidy] Let `bugprone-use-after-move` also handle calls to `std::forward` (PR #82673)

2024-03-03 Thread Piotr Zegar via cfe-commits

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

Overall, LGTM

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


[clang-tools-extra] [clang-tidy] Let `bugprone-use-after-move` also handle calls to `std::forward` (PR #82673)

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

https://github.com/5chmidti approved this pull request.


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


[clang] [lld] [llvm] [X86] Use generic CPU tuning when tune-cpu is empty (PR #83631)

2024-03-03 Thread via cfe-commits

AtariDreams wrote:

> > This is a turbulent change to both upstream and downstream tests without 
> > any profit as far as I can tell.
> 
> > 
> 
> > I did a similar change for 64-bit a few years ago: 
> > https://reviews.llvm.org/D129647
> 
> > 
> 
> > In comparison, this patch is not to solve a specific problem. It should not 
> > show any value because we don't care about 32-bit performance. Not to 
> > mention, we need to keep the test not changed as many as possible. The way 
> > we used in D129647 is to add an explicit "tune-cpu". We cannot blindly 
> > update tests in case distort the original intention.
> 
> 
> 
> I think I probaby wrote the FIXME and I agree with @phoebewang 

Wait does this only affect 32 bit?

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


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-03 Thread Krzysztof Parzyszek via cfe-commits

https://github.com/kparzysz updated 
https://github.com/llvm/llvm-project/pull/83625

>From b62919c2ce24feb3c75a5bbecce3d6b6ee8e5b7e Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Tue, 16 Jan 2024 16:40:47 -0600
Subject: [PATCH 1/3] [Frontend] Add leaf constructs and association to
 OpenMP/ACC directives

Add members "leafs" and "association" to .td describing OpenMP/ACC
directives: "leafs" are the leaf constructs for composite/combined
constructs, and "association" is the source language construct to
which the directive applies (e.g. loop, block, etc.)

The tblgen-generated output then contains two additional functions
- getLeafConstructs(D), and
- getDirectiveAssociation(D)
plus "enum class Association", all in namespaces "llvm::omp" and
"llvm::acc".

Note: getLeafConstructs returns an empty sequence for a construct
that is itself a leaf construct.

Use the new functions to simplify a few OpenMP-related functions
in clang.
---
 clang/lib/Basic/OpenMPKinds.cpp   | 130 +++---
 .../llvm/Frontend/Directive/DirectiveBase.td  |  36 +++
 llvm/include/llvm/Frontend/OpenACC/ACC.td |  27 +-
 llvm/include/llvm/Frontend/OpenMP/OMP.td  | 172 +++--
 llvm/include/llvm/TableGen/DirectiveEmitter.h |  10 +
 llvm/utils/TableGen/DirectiveEmitter.cpp  | 236 +-
 6 files changed, 489 insertions(+), 122 deletions(-)

diff --git a/clang/lib/Basic/OpenMPKinds.cpp b/clang/lib/Basic/OpenMPKinds.cpp
index 6c31b0824eb8a4..dd1a096d178111 100644
--- a/clang/lib/Basic/OpenMPKinds.cpp
+++ b/clang/lib/Basic/OpenMPKinds.cpp
@@ -574,31 +574,7 @@ const char 
*clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind,
 }
 
 bool clang::isOpenMPLoopDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_simd || DKind == OMPD_for || DKind == OMPD_for_simd ||
- DKind == OMPD_parallel_for || DKind == OMPD_parallel_for_simd ||
- DKind == OMPD_taskloop || DKind == OMPD_taskloop_simd ||
- DKind == OMPD_master_taskloop || DKind == OMPD_master_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop ||
- DKind == OMPD_parallel_master_taskloop_simd ||
- DKind == OMPD_masked_taskloop || DKind == OMPD_masked_taskloop_simd ||
- DKind == OMPD_parallel_masked_taskloop || DKind == OMPD_distribute ||
- DKind == OMPD_parallel_masked_taskloop_simd ||
- DKind == OMPD_target_parallel_for ||
- DKind == OMPD_distribute_parallel_for ||
- DKind == OMPD_distribute_parallel_for_simd ||
- DKind == OMPD_distribute_simd ||
- DKind == OMPD_target_parallel_for_simd || DKind == OMPD_target_simd ||
- DKind == OMPD_teams_distribute ||
- DKind == OMPD_teams_distribute_simd ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute ||
- DKind == OMPD_target_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_simd || DKind == OMPD_tile ||
- DKind == OMPD_unroll || DKind == OMPD_loop ||
- DKind == OMPD_teams_loop || DKind == OMPD_target_teams_loop ||
- DKind == OMPD_parallel_loop || DKind == OMPD_target_parallel_loop;
+  return getDirectiveAssociation(DKind) == Association::Loop;
 }
 
 bool clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) {
@@ -619,44 +595,22 @@ bool 
clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) {
 }
 
 bool clang::isOpenMPTaskLoopDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_taskloop || DKind == OMPD_taskloop_simd ||
- DKind == OMPD_master_taskloop || DKind == OMPD_master_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop ||
- DKind == OMPD_masked_taskloop || DKind == OMPD_masked_taskloop_simd ||
- DKind == OMPD_parallel_masked_taskloop ||
- DKind == OMPD_parallel_masked_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop_simd;
+  return DKind == OMPD_taskloop ||
+ llvm::is_contained(getLeafConstructs(DKind), OMPD_taskloop);
 }
 
 bool clang::isOpenMPParallelDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_parallel || DKind == OMPD_parallel_for ||
- DKind == OMPD_parallel_for_simd || DKind == OMPD_parallel_sections ||
- DKind == OMPD_target_parallel || DKind == OMPD_target_parallel_for ||
- DKind == OMPD_distribute_parallel_for ||
- DKind == OMPD_distribute_parallel_for_simd ||
- DKind == OMPD_target_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute_parallel_for_simd ||
- DKind == OMPD_parallel_master || DKind == OMPD_parallel_masked ||
- DKind == OMPD_pa

[clang] [ObjC] Set visibility of IvarOffsetGV when it is created in ObjCIvarOffsetVariable (PR #83726)

2024-03-03 Thread via cfe-commits

https://github.com/AtariDreams created 
https://github.com/llvm/llvm-project/pull/83726

It makes sense to set the visibility of the IvarOffsetGV when a new value for 
it is made in the heap.

>From 5396049175e77825c5e9de9296d3e8045b454dd6 Mon Sep 17 00:00:00 2001
From: Rose <83477269+ataridre...@users.noreply.github.com>
Date: Fri, 1 Mar 2024 17:52:58 -0500
Subject: [PATCH] [ObjC] Set visibility of IvarOffsetGV when it is created in
 ObjCIvarOffsetVariable

It makes sense to set the visibility of the IvarOffsetGV when a new value for 
it is made in the heap.
---
 clang/lib/CodeGen/CGObjCMac.cpp | 20 
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index 27d77e9a8a5511..cf472707d1794d 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -6826,10 +6826,9 @@ CGObjCNonFragileABIMac::ObjCIvarOffsetVariable(const 
ObjCInterfaceDecl *ID,
   Name += Ivar->getName();
   llvm::GlobalVariable *IvarOffsetGV = CGM.getModule().getGlobalVariable(Name);
   if (!IvarOffsetGV) {
-IvarOffsetGV =
-new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.IvarOffsetVarTy,
- false, llvm::GlobalValue::ExternalLinkage,
- nullptr, Name.str());
+IvarOffsetGV = new llvm::GlobalVariable(
+CGM.getModule(), ObjCTypes.IvarOffsetVarTy, false,
+llvm::GlobalValue::ExternalLinkage, nullptr, Name.str());
 if (CGM.getTriple().isOSBinFormatCOFF()) {
   bool IsPrivateOrPackage =
   Ivar->getAccessControl() == ObjCIvarDecl::Private ||
@@ -6838,11 +6837,16 @@ CGObjCNonFragileABIMac::ObjCIvarOffsetVariable(const 
ObjCInterfaceDecl *ID,
   const ObjCInterfaceDecl *ContainingID = Ivar->getContainingInterface();
 
   if (ContainingID->hasAttr())
-IvarOffsetGV
-->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass);
+IvarOffsetGV->setDLLStorageClass(
+llvm::GlobalValue::DLLImportStorageClass);
   else if (ContainingID->hasAttr() && !IsPrivateOrPackage)
-IvarOffsetGV
-->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass);
+IvarOffsetGV->setDLLStorageClass(
+llvm::GlobalValue::DLLExportStorageClass);
+
+  if (IsPrivateOrPackage || ID->getVisibility() == HiddenVisibility)
+IvarOffsetGV->setVisibility(llvm::GlobalValue::HiddenVisibility);
+  else
+IvarOffsetGV->setVisibility(llvm::GlobalValue::DefaultVisibility);
 }
   }
   return IvarOffsetGV;

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


[clang] [ObjC] Set visibility of IvarOffsetGV when it is created in ObjCIvarOffsetVariable (PR #83726)

2024-03-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: AtariDreams (AtariDreams)


Changes

It makes sense to set the visibility of the IvarOffsetGV when a new value for 
it is made in the heap.

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


1 Files Affected:

- (modified) clang/lib/CodeGen/CGObjCMac.cpp (+12-8) 


``diff
diff --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index 27d77e9a8a5511..cf472707d1794d 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -6826,10 +6826,9 @@ CGObjCNonFragileABIMac::ObjCIvarOffsetVariable(const 
ObjCInterfaceDecl *ID,
   Name += Ivar->getName();
   llvm::GlobalVariable *IvarOffsetGV = CGM.getModule().getGlobalVariable(Name);
   if (!IvarOffsetGV) {
-IvarOffsetGV =
-new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.IvarOffsetVarTy,
- false, llvm::GlobalValue::ExternalLinkage,
- nullptr, Name.str());
+IvarOffsetGV = new llvm::GlobalVariable(
+CGM.getModule(), ObjCTypes.IvarOffsetVarTy, false,
+llvm::GlobalValue::ExternalLinkage, nullptr, Name.str());
 if (CGM.getTriple().isOSBinFormatCOFF()) {
   bool IsPrivateOrPackage =
   Ivar->getAccessControl() == ObjCIvarDecl::Private ||
@@ -6838,11 +6837,16 @@ CGObjCNonFragileABIMac::ObjCIvarOffsetVariable(const 
ObjCInterfaceDecl *ID,
   const ObjCInterfaceDecl *ContainingID = Ivar->getContainingInterface();
 
   if (ContainingID->hasAttr())
-IvarOffsetGV
-->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass);
+IvarOffsetGV->setDLLStorageClass(
+llvm::GlobalValue::DLLImportStorageClass);
   else if (ContainingID->hasAttr() && !IsPrivateOrPackage)
-IvarOffsetGV
-->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass);
+IvarOffsetGV->setDLLStorageClass(
+llvm::GlobalValue::DLLExportStorageClass);
+
+  if (IsPrivateOrPackage || ID->getVisibility() == HiddenVisibility)
+IvarOffsetGV->setVisibility(llvm::GlobalValue::HiddenVisibility);
+  else
+IvarOffsetGV->setVisibility(llvm::GlobalValue::DefaultVisibility);
 }
   }
   return IvarOffsetGV;

``




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


[clang] [ObjC] Set visibility of IvarOffsetGV when it is created in ObjCIvarOffsetVariable (PR #83726)

2024-03-03 Thread via cfe-commits

github-actions[bot] wrote:

⚠️ We detected that you are using a GitHub private e-mail address to contribute 
to the repo.
  Please turn off [Keep my email addresses 
private](https://github.com/settings/emails) setting in your account.
  See [LLVM 
Discourse](https://discourse.llvm.org/t/hidden-emails-on-github-should-we-do-something-about-it)
 for more information.


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


[clang] Reland "[clang][modules] Print library module manifest path." (PR #82160)

2024-03-03 Thread Mark de Wever via cfe-commits

https://github.com/mordante updated 
https://github.com/llvm/llvm-project/pull/82160

>From cb3f20463548110617fd555ac11ee58d5b8b7ad5 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Sun, 18 Feb 2024 12:57:33 +0100
Subject: [PATCH 1/2] Reland "[clang][modules] Print library module manifest
 path."

This implements a way for the compiler to find the modules.json
associated with the C++23 Standard library modules.

This is based on a discussion in SG15. At the moment no Standard library
installs this manifest. #75741 adds this feature in libc++.

This reverts commit 82f424f766be00b037a706a835d0a0663a2680f1.

Disables the tests on non-X86 platforms as suggested.
---
 clang/include/clang/Driver/Driver.h   | 10 +
 clang/include/clang/Driver/Options.td |  3 ++
 clang/lib/Driver/Driver.cpp   | 44 +++
 ...les-print-library-module-manifest-path.cpp | 38 
 4 files changed, 95 insertions(+)
 create mode 100644 
clang/test/Driver/modules-print-library-module-manifest-path.cpp

diff --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index 908bc87c14b1ca..ac258dc384e688 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -611,6 +611,16 @@ class Driver {
   // FIXME: This should be in CompilationInfo.
   std::string GetProgramPath(StringRef Name, const ToolChain &TC) const;
 
+  /// Lookup the path to the Standard library module manifest.
+  ///
+  /// \param C - The compilation.
+  /// \param TC - The tool chain for additional information on
+  /// directories to search.
+  //
+  // FIXME: This should be in CompilationInfo.
+  std::string GetStdModuleManifestPath(const Compilation &C,
+   const ToolChain &TC) const;
+
   /// HandleAutocompletions - Handle --autocomplete by searching and printing
   /// possible flags, descriptions, and its arguments.
   void HandleAutocompletions(StringRef PassedFlags) const;
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 53f23f9abb4c96..2963cbc6af5328 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5371,6 +5371,9 @@ def print_resource_dir : Flag<["-", "--"], 
"print-resource-dir">,
 def print_search_dirs : Flag<["-", "--"], "print-search-dirs">,
   HelpText<"Print the paths used for finding libraries and programs">,
   Visibility<[ClangOption, CLOption]>;
+def print_std_module_manifest_path : Flag<["-", "--"], 
"print-library-module-manifest-path">,
+  HelpText<"Print the path for the C++ Standard library module manifest">,
+  Visibility<[ClangOption, CLOption]>;
 def print_targets : Flag<["-", "--"], "print-targets">,
   HelpText<"Print the registered targets">,
   Visibility<[ClangOption, CLOption]>;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 5a323bf4c0c5f4..82ee18b4588aa5 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -2197,6 +2197,12 @@ bool Driver::HandleImmediateArgs(const Compilation &C) {
 return false;
   }
 
+  if (C.getArgs().hasArg(options::OPT_print_std_module_manifest_path)) {
+llvm::outs() << GetStdModuleManifestPath(C, C.getDefaultToolChain())
+ << '\n';
+return false;
+  }
+
   if (C.getArgs().hasArg(options::OPT_print_runtime_dir)) {
 if (std::optional RuntimePath = TC.getRuntimePath())
   llvm::outs() << *RuntimePath << '\n';
@@ -6183,6 +6189,44 @@ std::string Driver::GetProgramPath(StringRef Name, const 
ToolChain &TC) const {
   return std::string(Name);
 }
 
+std::string Driver::GetStdModuleManifestPath(const Compilation &C,
+ const ToolChain &TC) const {
+  std::string error = "";
+
+  switch (TC.GetCXXStdlibType(C.getArgs())) {
+  case ToolChain::CST_Libcxx: {
+std::string lib = GetFilePath("libc++.so", TC);
+
+// Note when there are multiple flavours of libc++ the module json needs to
+// look at the command-line arguments for the proper json.
+// These flavours do not exist at the moment, but there are plans to
+// provide a variant that is built with sanitizer instrumentation enabled.
+
+// For example
+//  StringRef modules = [&] {
+//const SanitizerArgs &Sanitize = TC.getSanitizerArgs(C.getArgs());
+//if (Sanitize.needsAsanRt())
+//  return "modules-asan.json";
+//return "modules.json";
+//  }();
+
+SmallString<128> path(lib.begin(), lib.end());
+llvm::sys::path::remove_filename(path);
+llvm::sys::path::append(path, "modules.json");
+if (TC.getVFS().exists(path))
+  return static_cast(path);
+
+return error;
+  }
+
+  case ToolChain::CST_Libstdcxx:
+// libstdc++ does not provide Standard library modules yet.
+return error;
+  }
+
+  return error;
+}
+
 std::string Driver::GetTemporaryPath(StringRef Prefix, StringRef Suffix) const 
{
   SmallSt

[clang] [clang][StaticAnalyzer] fix function evalCall() typo in CheckerDocumentation (PR #83677)

2024-03-03 Thread via cfe-commits

mzyKi wrote:

> Makes sense, but how did it build before the fix? I thought by inheriting 
> from `Checker` it would take the address of the member function with the 
> expected signature to store them inside vectors. How could it take the 
> address of a nonexisting member function?
I think ```evalCall()``` is an independent function in CheckerDocumentation.cpp 
and it has no relation with ```Checker```. If no problem, I will 
merge soon.

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


[clang] [ObjC] Set visibility of IvarOffsetGV when it is created in ObjCIvarOffsetVariable (PR #83726)

2024-03-03 Thread via cfe-commits

https://github.com/AtariDreams updated 
https://github.com/llvm/llvm-project/pull/83726

>From 07e6cc851a0855c8c3b1b1de4bceb6a90aa3774f Mon Sep 17 00:00:00 2001
From: Rose <83477269+ataridre...@users.noreply.github.com>
Date: Fri, 1 Mar 2024 17:52:58 -0500
Subject: [PATCH] [ObjC] Set visibility of IvarOffsetGV when it is created in
 ObjCIvarOffsetVariable

It makes sense to set the visibility of the IvarOffsetGV when a new value for 
it is made in the heap.
---
 clang/lib/CodeGen/CGObjCMac.cpp | 30 ++
 1 file changed, 14 insertions(+), 16 deletions(-)

diff --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index 27d77e9a8a5511..71e6a606848108 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -6826,24 +6826,24 @@ CGObjCNonFragileABIMac::ObjCIvarOffsetVariable(const 
ObjCInterfaceDecl *ID,
   Name += Ivar->getName();
   llvm::GlobalVariable *IvarOffsetGV = CGM.getModule().getGlobalVariable(Name);
   if (!IvarOffsetGV) {
-IvarOffsetGV =
-new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.IvarOffsetVarTy,
- false, llvm::GlobalValue::ExternalLinkage,
- nullptr, Name.str());
+IvarOffsetGV = new llvm::GlobalVariable(
+CGM.getModule(), ObjCTypes.IvarOffsetVarTy, false,
+llvm::GlobalValue::ExternalLinkage, nullptr, Name.str());
+bool IsPrivateOrPackage =
+Ivar->getAccessControl() == ObjCIvarDecl::Private ||
+Ivar->getAccessControl() == ObjCIvarDecl::Package;
 if (CGM.getTriple().isOSBinFormatCOFF()) {
-  bool IsPrivateOrPackage =
-  Ivar->getAccessControl() == ObjCIvarDecl::Private ||
-  Ivar->getAccessControl() == ObjCIvarDecl::Package;
-
   const ObjCInterfaceDecl *ContainingID = Ivar->getContainingInterface();
-
   if (ContainingID->hasAttr())
-IvarOffsetGV
-->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass);
+IvarOffsetGV->setDLLStorageClass(
+llvm::GlobalValue::DLLImportStorageClass);
   else if (ContainingID->hasAttr() && !IsPrivateOrPackage)
-IvarOffsetGV
-->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass);
-}
+IvarOffsetGV->setDLLStorageClass(
+llvm::GlobalValue::DLLExportStorageClass);
+} else if (IsPrivateOrPackage || ID->getVisibility() == HiddenVisibility)
+  IvarOffsetGV->setVisibility(llvm::GlobalValue::HiddenVisibility);
+else
+  IvarOffsetGV->setVisibility(llvm::GlobalValue::DefaultVisibility);
   }
   return IvarOffsetGV;
 }
@@ -6859,8 +6859,6 @@ CGObjCNonFragileABIMac::EmitIvarOffsetVar(const 
ObjCInterfaceDecl *ID,
   CGM.getDataLayout().getABITypeAlign(ObjCTypes.IvarOffsetVarTy));
 
   if (!CGM.getTriple().isOSBinFormatCOFF()) {
-// FIXME: This matches gcc, but shouldn't the visibility be set on the use
-// as well (i.e., in ObjCIvarOffsetVariable).
 if (Ivar->getAccessControl() == ObjCIvarDecl::Private ||
 Ivar->getAccessControl() == ObjCIvarDecl::Package ||
 ID->getVisibility() == HiddenVisibility)

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


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-03 Thread Kiran Chandramohan via cfe-commits

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

> Add members "leafs" and "association" to .td describing OpenMP/ACC 
> directives: "leafs" are the leaf constructs for composite/combined 
> constructs, and "association" is the source language construct to which the 
> directive applies (e.g. loop, block, etc.)

Could you clarify that these are terminology used in the OpenMP standard?

Great work @kparzysz.

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


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-03 Thread Kiran Chandramohan via cfe-commits

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


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-03 Thread Kiran Chandramohan via cfe-commits


@@ -619,44 +595,22 @@ bool 
clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) {
 }
 
 bool clang::isOpenMPTaskLoopDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_taskloop || DKind == OMPD_taskloop_simd ||
- DKind == OMPD_master_taskloop || DKind == OMPD_master_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop ||
- DKind == OMPD_masked_taskloop || DKind == OMPD_masked_taskloop_simd ||
- DKind == OMPD_parallel_masked_taskloop ||
- DKind == OMPD_parallel_masked_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop_simd;
+  return DKind == OMPD_taskloop ||
+ llvm::is_contained(getLeafConstructs(DKind), OMPD_taskloop);
 }
 
 bool clang::isOpenMPParallelDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_parallel || DKind == OMPD_parallel_for ||
- DKind == OMPD_parallel_for_simd || DKind == OMPD_parallel_sections ||
- DKind == OMPD_target_parallel || DKind == OMPD_target_parallel_for ||
- DKind == OMPD_distribute_parallel_for ||
- DKind == OMPD_distribute_parallel_for_simd ||
- DKind == OMPD_target_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute_parallel_for_simd ||
- DKind == OMPD_parallel_master || DKind == OMPD_parallel_masked ||
- DKind == OMPD_parallel_master_taskloop ||
- DKind == OMPD_parallel_master_taskloop_simd ||
- DKind == OMPD_parallel_masked_taskloop ||
- DKind == OMPD_parallel_masked_taskloop_simd ||
- DKind == OMPD_parallel_loop || DKind == OMPD_target_parallel_loop ||
- DKind == OMPD_teams_loop;
+  if (DKind == OMPD_parallel_workshare)
+return false;

kiranchandramohan wrote:

Nit: A comment that workshare is not applicable to C/C++ might be helpful.

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


[clang] [ObjC] Set visibility of IvarOffsetGV when it is created in ObjCIvarOffsetVariable (PR #83726)

2024-03-03 Thread via cfe-commits

https://github.com/AtariDreams updated 
https://github.com/llvm/llvm-project/pull/83726

>From 0c00edec5ff4736187f11138334541a75cebccf0 Mon Sep 17 00:00:00 2001
From: Rose <83477269+ataridre...@users.noreply.github.com>
Date: Fri, 1 Mar 2024 17:52:58 -0500
Subject: [PATCH] [ObjC] Set visibility of IvarOffsetGV when it is created in
 ObjCIvarOffsetVariable

It makes sense to set the visibility of the IvarOffsetGV when a new value for 
it is made in the heap.
---
 clang/lib/CodeGen/CGObjCMac.cpp | 30 ++---
 clang/test/CodeGenObjC/dllstorage.m | 10 +-
 2 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index 27d77e9a8a5511..18194d1dff849a 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -6826,24 +6826,26 @@ CGObjCNonFragileABIMac::ObjCIvarOffsetVariable(const 
ObjCInterfaceDecl *ID,
   Name += Ivar->getName();
   llvm::GlobalVariable *IvarOffsetGV = CGM.getModule().getGlobalVariable(Name);
   if (!IvarOffsetGV) {
-IvarOffsetGV =
-new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.IvarOffsetVarTy,
- false, llvm::GlobalValue::ExternalLinkage,
- nullptr, Name.str());
+IvarOffsetGV = new llvm::GlobalVariable(
+CGM.getModule(), ObjCTypes.IvarOffsetVarTy, false,
+llvm::GlobalValue::ExternalLinkage, nullptr, Name.str());
+bool IsPrivateOrPackage =
+Ivar->getAccessControl() == ObjCIvarDecl::Private ||
+Ivar->getAccessControl() == ObjCIvarDecl::Package;
 if (CGM.getTriple().isOSBinFormatCOFF()) {
-  bool IsPrivateOrPackage =
-  Ivar->getAccessControl() == ObjCIvarDecl::Private ||
-  Ivar->getAccessControl() == ObjCIvarDecl::Package;
-
   const ObjCInterfaceDecl *ContainingID = Ivar->getContainingInterface();
-
   if (ContainingID->hasAttr())
-IvarOffsetGV
-->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass);
+IvarOffsetGV->setDLLStorageClass(
+llvm::GlobalValue::DLLImportStorageClass);
   else if (ContainingID->hasAttr() && !IsPrivateOrPackage)
-IvarOffsetGV
-->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass);
+IvarOffsetGV->setDLLStorageClass(
+llvm::GlobalValue::DLLExportStorageClass);
 }
+
+if (IsPrivateOrPackage || ID->getVisibility() == HiddenVisibility)
+  IvarOffsetGV->setVisibility(llvm::GlobalValue::HiddenVisibility);
+else
+  IvarOffsetGV->setVisibility(llvm::GlobalValue::DefaultVisibility);
   }
   return IvarOffsetGV;
 }
@@ -6859,8 +6861,6 @@ CGObjCNonFragileABIMac::EmitIvarOffsetVar(const 
ObjCInterfaceDecl *ID,
   CGM.getDataLayout().getABITypeAlign(ObjCTypes.IvarOffsetVarTy));
 
   if (!CGM.getTriple().isOSBinFormatCOFF()) {
-// FIXME: This matches gcc, but shouldn't the visibility be set on the use
-// as well (i.e., in ObjCIvarOffsetVariable).
 if (Ivar->getAccessControl() == ObjCIvarDecl::Private ||
 Ivar->getAccessControl() == ObjCIvarDecl::Package ||
 ID->getVisibility() == HiddenVisibility)
diff --git a/clang/test/CodeGenObjC/dllstorage.m 
b/clang/test/CodeGenObjC/dllstorage.m
index f45eb7bb6aee78..22b1d4627d3aca 100644
--- a/clang/test/CodeGenObjC/dllstorage.m
+++ b/clang/test/CodeGenObjC/dllstorage.m
@@ -33,7 +33,7 @@ @implementation J {
 }
 @end
 
-// CHECK-IR-DAG: @"OBJC_IVAR_$_J._ivar" = global i32
+// CHECK-IR-DAG: @"OBJC_IVAR_$_J._ivar" = hidden global i32 0, align 4 
 
 // CHECK-NF-DAG: @"__objc_ivar_offset_J._ivar.@" = hidden global i32
 
@@ -54,7 +54,7 @@ @implementation K {
 }
 @end
 
-// CHECK-IR-DAG: @"OBJC_IVAR_$_K._ivar" = global i32
+// CHECK-IR-DAG: @"OBJC_IVAR_$_K._ivar" = hidden global i32
 
 // CHECK-NF-DAG: @"__objc_ivar_offset_K._ivar.@" = hidden global i32
 
@@ -88,11 +88,11 @@ @implementation L {
 }
 @end
 
-// CHECK-IR-DAG: @"OBJC_IVAR_$_L._none" = global i32
+// CHECK-IR-DAG: @"OBJC_IVAR_$_L._none" = hidden global i32
 // CHECK-IR-DAG: @"OBJC_IVAR_$_L._public" = dllexport global i32
 // CHECK-IR-DAG: @"OBJC_IVAR_$_L._protected" = dllexport global i32
-// CHECK-IR-DAG: @"OBJC_IVAR_$_L._package" = global i32
-// CHECK-IR-DAG: @"OBJC_IVAR_$_L._private" = global i32
+// CHECK-IR-DAG: @"OBJC_IVAR_$_L._package" = hidden global i32
+// CHECK-IR-DAG: @"OBJC_IVAR_$_L._private" = hidden global i32
 
 // CHECK-NF-DAG: @"__objc_ivar_offset_L._none.@" = hidden global i32
 // CHECK-NF-DAG: @"__objc_ivar_offset_L._public.@" = dso_local dllexport 
global i32

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


[clang] [ObjC] Set visibility of IvarOffsetGV when it is created in ObjCIvarOffsetVariable (PR #83726)

2024-03-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 03f150bb5688be72ae4dfb43fbe6795aae493e6d 
0c00edec5ff4736187f11138334541a75cebccf0 -- clang/lib/CodeGen/CGObjCMac.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index 18194d1dff..984d6e33e7 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -6841,7 +6841,7 @@ CGObjCNonFragileABIMac::ObjCIvarOffsetVariable(const 
ObjCInterfaceDecl *ID,
 IvarOffsetGV->setDLLStorageClass(
 llvm::GlobalValue::DLLExportStorageClass);
 }
-
+
 if (IsPrivateOrPackage || ID->getVisibility() == HiddenVisibility)
   IvarOffsetGV->setVisibility(llvm::GlobalValue::HiddenVisibility);
 else

``




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


[clang] [ObjC] Set visibility of IvarOffsetGV when it is created in ObjCIvarOffsetVariable (PR #83726)

2024-03-03 Thread via cfe-commits

https://github.com/AtariDreams updated 
https://github.com/llvm/llvm-project/pull/83726

>From d9ea5f5bc8f2d294b467205e41da508def66dcec Mon Sep 17 00:00:00 2001
From: Rose <83477269+ataridre...@users.noreply.github.com>
Date: Fri, 1 Mar 2024 17:52:58 -0500
Subject: [PATCH] [ObjC] Set visibility of IvarOffsetGV when it is created in
 ObjCIvarOffsetVariable

It makes sense to set the visibility of the IvarOffsetGV when a new value for 
it is made in the heap.
---
 clang/lib/CodeGen/CGObjCMac.cpp | 30 ++---
 clang/test/CodeGenObjC/dllstorage.m | 10 +-
 2 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index 27d77e9a8a5511..984d6e33e76780 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -6826,24 +6826,26 @@ CGObjCNonFragileABIMac::ObjCIvarOffsetVariable(const 
ObjCInterfaceDecl *ID,
   Name += Ivar->getName();
   llvm::GlobalVariable *IvarOffsetGV = CGM.getModule().getGlobalVariable(Name);
   if (!IvarOffsetGV) {
-IvarOffsetGV =
-new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.IvarOffsetVarTy,
- false, llvm::GlobalValue::ExternalLinkage,
- nullptr, Name.str());
+IvarOffsetGV = new llvm::GlobalVariable(
+CGM.getModule(), ObjCTypes.IvarOffsetVarTy, false,
+llvm::GlobalValue::ExternalLinkage, nullptr, Name.str());
+bool IsPrivateOrPackage =
+Ivar->getAccessControl() == ObjCIvarDecl::Private ||
+Ivar->getAccessControl() == ObjCIvarDecl::Package;
 if (CGM.getTriple().isOSBinFormatCOFF()) {
-  bool IsPrivateOrPackage =
-  Ivar->getAccessControl() == ObjCIvarDecl::Private ||
-  Ivar->getAccessControl() == ObjCIvarDecl::Package;
-
   const ObjCInterfaceDecl *ContainingID = Ivar->getContainingInterface();
-
   if (ContainingID->hasAttr())
-IvarOffsetGV
-->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass);
+IvarOffsetGV->setDLLStorageClass(
+llvm::GlobalValue::DLLImportStorageClass);
   else if (ContainingID->hasAttr() && !IsPrivateOrPackage)
-IvarOffsetGV
-->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass);
+IvarOffsetGV->setDLLStorageClass(
+llvm::GlobalValue::DLLExportStorageClass);
 }
+
+if (IsPrivateOrPackage || ID->getVisibility() == HiddenVisibility)
+  IvarOffsetGV->setVisibility(llvm::GlobalValue::HiddenVisibility);
+else
+  IvarOffsetGV->setVisibility(llvm::GlobalValue::DefaultVisibility);
   }
   return IvarOffsetGV;
 }
@@ -6859,8 +6861,6 @@ CGObjCNonFragileABIMac::EmitIvarOffsetVar(const 
ObjCInterfaceDecl *ID,
   CGM.getDataLayout().getABITypeAlign(ObjCTypes.IvarOffsetVarTy));
 
   if (!CGM.getTriple().isOSBinFormatCOFF()) {
-// FIXME: This matches gcc, but shouldn't the visibility be set on the use
-// as well (i.e., in ObjCIvarOffsetVariable).
 if (Ivar->getAccessControl() == ObjCIvarDecl::Private ||
 Ivar->getAccessControl() == ObjCIvarDecl::Package ||
 ID->getVisibility() == HiddenVisibility)
diff --git a/clang/test/CodeGenObjC/dllstorage.m 
b/clang/test/CodeGenObjC/dllstorage.m
index f45eb7bb6aee78..22b1d4627d3aca 100644
--- a/clang/test/CodeGenObjC/dllstorage.m
+++ b/clang/test/CodeGenObjC/dllstorage.m
@@ -33,7 +33,7 @@ @implementation J {
 }
 @end
 
-// CHECK-IR-DAG: @"OBJC_IVAR_$_J._ivar" = global i32
+// CHECK-IR-DAG: @"OBJC_IVAR_$_J._ivar" = hidden global i32 0, align 4 
 
 // CHECK-NF-DAG: @"__objc_ivar_offset_J._ivar.@" = hidden global i32
 
@@ -54,7 +54,7 @@ @implementation K {
 }
 @end
 
-// CHECK-IR-DAG: @"OBJC_IVAR_$_K._ivar" = global i32
+// CHECK-IR-DAG: @"OBJC_IVAR_$_K._ivar" = hidden global i32
 
 // CHECK-NF-DAG: @"__objc_ivar_offset_K._ivar.@" = hidden global i32
 
@@ -88,11 +88,11 @@ @implementation L {
 }
 @end
 
-// CHECK-IR-DAG: @"OBJC_IVAR_$_L._none" = global i32
+// CHECK-IR-DAG: @"OBJC_IVAR_$_L._none" = hidden global i32
 // CHECK-IR-DAG: @"OBJC_IVAR_$_L._public" = dllexport global i32
 // CHECK-IR-DAG: @"OBJC_IVAR_$_L._protected" = dllexport global i32
-// CHECK-IR-DAG: @"OBJC_IVAR_$_L._package" = global i32
-// CHECK-IR-DAG: @"OBJC_IVAR_$_L._private" = global i32
+// CHECK-IR-DAG: @"OBJC_IVAR_$_L._package" = hidden global i32
+// CHECK-IR-DAG: @"OBJC_IVAR_$_L._private" = hidden global i32
 
 // CHECK-NF-DAG: @"__objc_ivar_offset_L._none.@" = hidden global i32
 // CHECK-NF-DAG: @"__objc_ivar_offset_L._public.@" = dso_local dllexport 
global i32

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


[clang] 0c89427 - Reland "[clang][modules] Print library module manifest path." (#82160)

2024-03-03 Thread via cfe-commits

Author: Mark de Wever
Date: 2024-03-03T17:58:08+01:00
New Revision: 0c89427b99f6f6d7c217c70ff880ca097340f9a4

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

LOG: Reland "[clang][modules] Print library module manifest path." (#82160)

This implements a way for the compiler to find the modules.json
associated with the C++23 Standard library modules.

This is based on a discussion in SG15. At the moment no Standard library
installs this manifest. #75741 adds this feature in libc++.

This reverts commit 82f424f766be00b037a706a835d0a0663a2680f1.

Disables the tests on non-X86 platforms as suggested.

Added: 
clang/test/Driver/modules-print-library-module-manifest-path.cpp

Modified: 
clang/include/clang/Driver/Driver.h
clang/include/clang/Driver/Options.td
clang/lib/Driver/Driver.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index 73cf326101ffd5..f145ddc05bd9d6 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -620,6 +620,16 @@ class Driver {
   // FIXME: This should be in CompilationInfo.
   std::string GetProgramPath(StringRef Name, const ToolChain &TC) const;
 
+  /// Lookup the path to the Standard library module manifest.
+  ///
+  /// \param C - The compilation.
+  /// \param TC - The tool chain for additional information on
+  /// directories to search.
+  //
+  // FIXME: This should be in CompilationInfo.
+  std::string GetStdModuleManifestPath(const Compilation &C,
+   const ToolChain &TC) const;
+
   /// HandleAutocompletions - Handle --autocomplete by searching and printing
   /// possible flags, descriptions, and its arguments.
   void HandleAutocompletions(StringRef PassedFlags) const;

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index bef38738fde82e..3e857f4e6faf87 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5364,6 +5364,9 @@ def print_resource_dir : Flag<["-", "--"], 
"print-resource-dir">,
 def print_search_dirs : Flag<["-", "--"], "print-search-dirs">,
   HelpText<"Print the paths used for finding libraries and programs">,
   Visibility<[ClangOption, CLOption]>;
+def print_std_module_manifest_path : Flag<["-", "--"], 
"print-library-module-manifest-path">,
+  HelpText<"Print the path for the C++ Standard library module manifest">,
+  Visibility<[ClangOption, CLOption]>;
 def print_targets : Flag<["-", "--"], "print-targets">,
   HelpText<"Print the registered targets">,
   Visibility<[ClangOption, CLOption]>;

diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 00e14071a4afec..d7fbb127fed2dd 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -2197,6 +2197,12 @@ bool Driver::HandleImmediateArgs(const Compilation &C) {
 return false;
   }
 
+  if (C.getArgs().hasArg(options::OPT_print_std_module_manifest_path)) {
+llvm::outs() << GetStdModuleManifestPath(C, C.getDefaultToolChain())
+ << '\n';
+return false;
+  }
+
   if (C.getArgs().hasArg(options::OPT_print_runtime_dir)) {
 if (std::optional RuntimePath = TC.getRuntimePath())
   llvm::outs() << *RuntimePath << '\n';
@@ -6169,6 +6175,44 @@ std::string Driver::GetProgramPath(StringRef Name, const 
ToolChain &TC) const {
   return std::string(Name);
 }
 
+std::string Driver::GetStdModuleManifestPath(const Compilation &C,
+ const ToolChain &TC) const {
+  std::string error = "";
+
+  switch (TC.GetCXXStdlibType(C.getArgs())) {
+  case ToolChain::CST_Libcxx: {
+std::string lib = GetFilePath("libc++.so", TC);
+
+// Note when there are multiple flavours of libc++ the module json needs to
+// look at the command-line arguments for the proper json.
+// These flavours do not exist at the moment, but there are plans to
+// provide a variant that is built with sanitizer instrumentation enabled.
+
+// For example
+//  StringRef modules = [&] {
+//const SanitizerArgs &Sanitize = TC.getSanitizerArgs(C.getArgs());
+//if (Sanitize.needsAsanRt())
+//  return "modules-asan.json";
+//return "modules.json";
+//  }();
+
+SmallString<128> path(lib.begin(), lib.end());
+llvm::sys::path::remove_filename(path);
+llvm::sys::path::append(path, "modules.json");
+if (TC.getVFS().exists(path))
+  return static_cast(path);
+
+return error;
+  }
+
+  case ToolChain::CST_Libstdcxx:
+// libstdc++ does not provide Standard library modules yet.
+return error;
+  }
+
+  return error;
+}
+
 std::string Driver::GetTemporaryPath(StringRef Prefix, StringRef Suffix) const 
{
   Small

[clang] Reland "[clang][modules] Print library module manifest path." (PR #82160)

2024-03-03 Thread Mark de Wever via cfe-commits

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


[clang] Reland "[clang][modules] Print library module manifest path." (PR #82160)

2024-03-03 Thread Mark de Wever via cfe-commits

mordante wrote:

> @mordante if we want this for 18, we need to land and backport it in this 
> week.

Thanks for the reminder, it got a bit under my radar. I'll ask a backport 
tomorrow unless a CI starts to complain again.

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


[clang] [clang] Fix crash when declaring invalid lambda member (PR #74110)

2024-03-03 Thread Nikolas Klauser via cfe-commits

philnik777 wrote:

@AaronBallman Thanks for the review. Sorry for responding so late - I've missed 
your review.

The tests aren't actually unrelated to the path. This is the file where I 
discovered the crash, so I just used it to demonstrate that it's fixed. I'm not 
sure how to split things, since I can't add the run line without fixing the bug.

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


[clang] [ObjC] Check entire chain of superclasses to see if class layout is statically known (PR #81335)

2024-03-03 Thread via cfe-commits

AtariDreams wrote:

@rjmccall ping

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


[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

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

https://github.com/owenca updated 
https://github.com/llvm/llvm-project/pull/83709

>From 91d6e4c6e0ae2e1d79edf496df22978a4e1f3e1a Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Sat, 2 Mar 2024 22:08:29 -0800
Subject: [PATCH 1/2] [clang-format] Handle common C++ non-keyword types as
 such

Fixes #83400.
---
 clang/lib/Format/FormatToken.cpp  | 16 --
 clang/lib/Format/FormatToken.h|  4 +--
 clang/lib/Format/QualifierAlignmentFixer.cpp  | 25 +---
 clang/lib/Format/QualifierAlignmentFixer.h|  5 ++--
 clang/lib/Format/TokenAnnotator.cpp   | 29 ++-
 clang/lib/Format/UnwrappedLineParser.cpp  | 12 
 clang/unittests/Format/TokenAnnotatorTest.cpp |  6 
 7 files changed, 61 insertions(+), 36 deletions(-)

diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp
index 56a7b2d6387765..02952bd20acf9a 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -34,9 +34,15 @@ const char *getTokenTypeName(TokenType Type) {
   return nullptr;
 }
 
+// Sorted common C++ non-keyword types.
+static SmallVector CppNonKeywordTypes = {
+"byte",   "int16_t",  "int32_t",  "int64_t",  "int8_t",
+"size_t", "uint16_t", "uint32_t", "uint64_t", "uint8_t",
+};
+
 // FIXME: This is copy&pasted from Sema. Put it in a common place and remove
 // duplication.
-bool FormatToken::isSimpleTypeSpecifier() const {
+bool FormatToken::isSimpleTypeSpecifier(bool IsCpp) const {
   switch (Tok.getKind()) {
   case tok::kw_short:
   case tok::kw_long:
@@ -66,13 +72,17 @@ bool FormatToken::isSimpleTypeSpecifier() const {
   case tok::kw_decltype:
   case tok::kw__Atomic:
 return true;
+  case tok::identifier:
+return IsCpp && std::binary_search(CppNonKeywordTypes.begin(),
+   CppNonKeywordTypes.end(), TokenText);
   default:
 return false;
   }
 }
 
-bool FormatToken::isTypeOrIdentifier() const {
-  return isSimpleTypeSpecifier() || Tok.isOneOf(tok::kw_auto, tok::identifier);
+bool FormatToken::isTypeOrIdentifier(bool IsCpp) const {
+  return isSimpleTypeSpecifier(IsCpp) ||
+ Tok.isOneOf(tok::kw_auto, tok::identifier);
 }
 
 bool FormatToken::isBlockIndentedInitRBrace(const FormatStyle &Style) const {
diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 31245495041960..2bc136c51d23f1 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -674,9 +674,9 @@ struct FormatToken {
   }
 
   /// Determine whether the token is a simple-type-specifier.
-  [[nodiscard]] bool isSimpleTypeSpecifier() const;
+  [[nodiscard]] bool isSimpleTypeSpecifier(bool IsCpp) const;
 
-  [[nodiscard]] bool isTypeOrIdentifier() const;
+  [[nodiscard]] bool isTypeOrIdentifier(bool IsCpp) const;
 
   bool isObjCAccessSpecifier() const {
 return is(tok::at) && Next &&
diff --git a/clang/lib/Format/QualifierAlignmentFixer.cpp 
b/clang/lib/Format/QualifierAlignmentFixer.cpp
index 0c63d330b5aed4..834ae115908856 100644
--- a/clang/lib/Format/QualifierAlignmentFixer.cpp
+++ b/clang/lib/Format/QualifierAlignmentFixer.cpp
@@ -268,11 +268,13 @@ const FormatToken 
*LeftRightQualifierAlignmentFixer::analyzeRight(
   if (isPossibleMacro(TypeToken))
 return Tok;
 
+  const bool IsCpp = Style.isCpp();
+
   // The case `const long long int volatile` -> `long long int const volatile`
   // The case `long const long int volatile` -> `long long int const volatile`
   // The case `long long volatile int const` -> `long long int const volatile`
   // The case `const long long volatile int` -> `long long int const volatile`
-  if (TypeToken->isSimpleTypeSpecifier()) {
+  if (TypeToken->isSimpleTypeSpecifier(IsCpp)) {
 // The case `const decltype(foo)` -> `const decltype(foo)`
 // The case `const typeof(foo)` -> `const typeof(foo)`
 // The case `const _Atomic(foo)` -> `const _Atomic(foo)`
@@ -280,8 +282,10 @@ const FormatToken 
*LeftRightQualifierAlignmentFixer::analyzeRight(
   return Tok;
 
 const FormatToken *LastSimpleTypeSpecifier = TypeToken;
-while (isQualifierOrType(LastSimpleTypeSpecifier->getNextNonComment()))
+while (isQualifierOrType(LastSimpleTypeSpecifier->getNextNonComment(),
+ IsCpp)) {
   LastSimpleTypeSpecifier = LastSimpleTypeSpecifier->getNextNonComment();
+}
 
 rotateTokens(SourceMgr, Fixes, Tok, LastSimpleTypeSpecifier,
  /*Left=*/false);
@@ -291,7 +295,7 @@ const FormatToken 
*LeftRightQualifierAlignmentFixer::analyzeRight(
   // The case  `unsigned short const` -> `unsigned short const`
   // The case:
   // `unsigned short volatile const` -> `unsigned short const volatile`
-  if (PreviousCheck && PreviousCheck->isSimpleTypeSpecifier()) {
+  if (PreviousCheck && PreviousCheck->isSimpleTypeSpecifier(IsCpp)) {
 if (LastQual != Tok)
   rotateTokens(SourceMgr, Fixes, Tok, LastQual, /*Left=*/false);
 return Tok;
@@ -4

[clang] [ObjC] Check entire chain of superclasses to see if class layout is statically known (PR #81335)

2024-03-03 Thread via cfe-commits

https://github.com/AtariDreams updated 
https://github.com/llvm/llvm-project/pull/81335

>From b6d0f6b4a0c631345313fd3bebf86ac8b9473fac Mon Sep 17 00:00:00 2001
From: Rose <83477269+ataridre...@users.noreply.github.com>
Date: Fri, 9 Feb 2024 17:51:15 -0500
Subject: [PATCH 1/2] [ObjC] Add pre-commit tests [NFC]

---
 .../constant-non-fragile-ivar-offset.m| 96 +++
 1 file changed, 96 insertions(+)

diff --git a/clang/test/CodeGenObjC/constant-non-fragile-ivar-offset.m 
b/clang/test/CodeGenObjC/constant-non-fragile-ivar-offset.m
index 788b3220af3067..c4bb1ebc9a80be 100644
--- a/clang/test/CodeGenObjC/constant-non-fragile-ivar-offset.m
+++ b/clang/test/CodeGenObjC/constant-non-fragile-ivar-offset.m
@@ -1,6 +1,13 @@
 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.14.0 -emit-llvm %s -o - | 
FileCheck %s
 
 // CHECK: @"OBJC_IVAR_$_StaticLayout.static_layout_ivar" = hidden constant i64 
20
+// CHECK: @"OBJC_IVAR_$_SuperClass.superClassIvar" = hidden constant i64 20
+// CHECK: @"OBJC_IVAR_$_SuperClass._superClassProperty" = hidden constant i64 
24
+// CHECK: @"OBJC_IVAR_$_IntermediateClass.intermediateClassIvar" = global i64 
32
+// CHECK: @"OBJC_IVAR_$_IntermediateClass.intermediateClassIvar2" = global i64 
40
+// CHECK: @"OBJC_IVAR_$_IntermediateClass._intermediateProperty" = hidden 
global i64 48
+// CHECK: @"OBJC_IVAR_$_SubClass.subClassIvar" = global i64 56
+// CHECK: @"OBJC_IVAR_$_SubClass._subClassProperty" = hidden global i64 64
 // CHECK: @"OBJC_IVAR_$_NotStaticLayout.not_static_layout_ivar" = hidden 
global i64 12
 
 @interface NSObject {
@@ -20,6 +27,95 @@ -(void)meth {
 }
 @end
 
+// Ivars declared in the @interface
+@interface SuperClass : NSObject
+@property (nonatomic, assign) int superClassProperty;
+@end
+
+@implementation SuperClass {
+  int superClassIvar; // Declare an ivar
+}
+
+// CHECK-LABEL: define internal void @"\01-[SuperClass superClassMethod]"
+- (void)superClassMethod {
+_superClassProperty = 42;
+superClassIvar = 10;
+// CHECK: load i64, ptr @"OBJC_IVAR_$_SuperClass
+// CHECK: getelementptr inbounds i8, ptr %1, i64 20
+}
+
+// implicitly synthesized method here
+// CHECK-LABEL: define internal i32 @"\01-[SuperClass superClassProperty]"
+// CHECK: getelementptr inbounds i8, ptr %0, i64 24
+
+// CHECK-LABEL: define internal void @"\01-[SuperClass setSuperClassProperty:]"
+// CHECK: getelementptr inbounds i8, ptr %1, i64 24
+@end
+
+// Inheritance and Ivars
+@interface IntermediateClass : SuperClass
+{
+double intermediateClassIvar;
+
+@protected
+int intermediateClassIvar2;
+}
+@property (nonatomic, strong) SuperClass *intermediateProperty;
+@end
+
+@implementation IntermediateClass
+@synthesize intermediateProperty = _intermediateProperty;
+- (void)intermediateClassMethod {
+intermediateClassIvar = 3.14;
+// CHECK: load i64, ptr @"OBJC_IVAR_$_IntermediateClass
+// CHECK: getelementptr inbounds i8, ptr %0, i64 %ivar
+}
+
+// CHECK-LABEL: define internal void @"\01-[IntermediateClass 
intermediateClassPropertyMethod]"
+- (void)intermediateClassPropertyMethod {
+self.intermediateProperty = 0;
+// CHECK: load ptr, ptr @OBJC_SELECTOR_REFERENCES_
+// CHECK: call void @objc_msgSend(ptr noundef %0, ptr noundef %1, ptr 
noundef null)
+}
+
+// CHECK-LABEL: define internal void @"\01-[IntermediateClass 
intermediateClassPropertyMethodDirect]"
+- (void)intermediateClassPropertyMethodDirect {
+_intermediateProperty = 0;
+// CHECK: load i64, ptr 
@"OBJC_IVAR_$_IntermediateClass._intermediateProperty"
+}
+@end
+
+@interface SubClass : IntermediateClass
+{
+double subClassIvar;
+}
+@property (nonatomic, assign) SubClass *subClassProperty;
+@end
+
+@implementation SubClass
+// CHECK-LABEL: define internal void @"\01-[SubClass subclassVar]"
+- (void)subclassVar {
+
+subClassIvar = 6.28;
+// CHECK: load i64, ptr @"OBJC_IVAR_$_SubClass
+// CHECK: getelementptr inbounds i8, ptr %0, i64 %ivar
+}
+
+// CHECK-LABEL: define internal void @"\01-[SubClass intermediateSubclassVar]"
+-(void)intermediateSubclassVar {
+intermediateClassIvar = 3.14;
+// CHECK: load i64, ptr @"OBJC_IVAR_$_IntermediateClass
+// CHECK: getelementptr inbounds i8, ptr %0, i64 %ivar
+}
+
+// implicit synthesized method here:
+// CHECK-LABEL: define internal ptr @"\01-[SubClass subClassProperty]"
+// CHECK: load i64, ptr @"OBJC_IVAR_$_SubClass._subClassProperty"
+
+// CHECK-LABEL: define internal void @"\01-[SubClass setSubClassProperty:]"
+// CHECK: load i64, ptr @"OBJC_IVAR_$_SubClass._subClassProperty"
+@end
+
 @interface NotNSObject {
   int these, might, change;
 }

>From 9b33c9bb81695480478a0d38b2c1021b33743be9 Mon Sep 17 00:00:00 2001
From: Rose <83477269+ataridre...@users.noreply.github.com>
Date: Tue, 13 Feb 2024 14:52:49 -0500
Subject: [PATCH 2/2] [ObjC] Check entire chain of superclasses to see if class
 layout is statically known

As of now, we only check if a class directly inherits from NSObject to 
determine 

[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-03 Thread Richard Smith via cfe-commits


@@ -34,9 +34,15 @@ const char *getTokenTypeName(TokenType Type) {
   return nullptr;
 }
 
+// Sorted common C++ non-keyword types.
+static SmallVector CppNonKeywordTypes = {
+"byte",   "int16_t",  "int32_t",  "int64_t",  "int8_t",

zygoloid wrote:

Does `byte` really belong here? It's not available as an unqualified name, only 
as `std::byte`. I could see an argument for including `nullptr_t` here because 
it is available unqualified, but even that seems a little hard to justify since 
I don't think people write that often. I also expect people use `byte` as a 
variable name frequently; the same doesn't seem to be true for these other 
names.

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


[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-03 Thread Richard Smith via cfe-commits


@@ -34,9 +34,15 @@ const char *getTokenTypeName(TokenType Type) {
   return nullptr;
 }
 
+// Sorted common C++ non-keyword types.
+static SmallVector CppNonKeywordTypes = {
+"byte",   "int16_t",  "int32_t",  "int64_t",  "int8_t",
+"size_t", "uint16_t", "uint32_t", "uint64_t", "uint8_t",

zygoloid wrote:

Maybe also `ptrdiff_t`, `intptr_t`, `uintptr_t`. And there's also `float_t`, 
`double_t`, `uint_least32_t`, ...

I wonder if the best heuristic to use here would be simply to look for an 
identifier that matches `[a-z0-9_]*_t`.

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


[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-03 Thread Richard Smith via cfe-commits


@@ -66,13 +72,17 @@ bool FormatToken::isSimpleTypeSpecifier() const {
   case tok::kw_decltype:
   case tok::kw__Atomic:
 return true;
+  case tok::identifier:
+return IsCpp && std::binary_search(CppNonKeywordTypes.begin(),
+   CppNonKeywordTypes.end(), TokenText);

zygoloid wrote:

Should this really be C++-only? All of the types in your list are standard 
library header types in C too, except for `byte` (which, as noted above, 
probably shouldn't be there).

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


[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-03 Thread Richard Smith via cfe-commits


@@ -34,9 +34,15 @@ const char *getTokenTypeName(TokenType Type) {
   return nullptr;
 }
 
+// Sorted common C++ non-keyword types.
+static SmallVector CppNonKeywordTypes = {
+"byte",   "int16_t",  "int32_t",  "int64_t",  "int8_t",
+"size_t", "uint16_t", "uint32_t", "uint64_t", "uint8_t",
+};
+
 // FIXME: This is copy&pasted from Sema. Put it in a common place and remove
 // duplication.

zygoloid wrote:

Looks like this comment is no longer correct.

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


[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-03 Thread Richard Smith via cfe-commits

zygoloid wrote:

Another possibility to consider for the original bug: `(single_identifier)` is 
almost certainly a cast, not redundant parentheses, unless `single_identifier` 
names a macro argument. So I wonder if that would be a better heuristic to use 
to fix the regression.

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


[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

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


@@ -66,13 +72,17 @@ bool FormatToken::isSimpleTypeSpecifier() const {
   case tok::kw_decltype:
   case tok::kw__Atomic:
 return true;
+  case tok::identifier:
+return IsCpp && std::binary_search(CppNonKeywordTypes.begin(),
+   CppNonKeywordTypes.end(), TokenText);

owenca wrote:

There’s no C per se in clang-format. `IsCpp` by clang-format convention means 
C/C++/Objective-C/
Objective-C++.

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


[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

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


@@ -34,9 +34,15 @@ const char *getTokenTypeName(TokenType Type) {
   return nullptr;
 }
 
+// Sorted common C++ non-keyword types.
+static SmallVector CppNonKeywordTypes = {
+"byte",   "int16_t",  "int32_t",  "int64_t",  "int8_t",
+"size_t", "uint16_t", "uint32_t", "uint64_t", "uint8_t",

owenca wrote:

As the comment says, the list includes ~common~ non-keyword types. We can 
always grow the list in the future if necessary. I thought about using regex 
but went for a specific list in order to minimize the possibility of regression.

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


[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

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

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


[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

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


@@ -34,9 +34,15 @@ const char *getTokenTypeName(TokenType Type) {
   return nullptr;
 }
 
+// Sorted common C++ non-keyword types.
+static SmallVector CppNonKeywordTypes = {
+"byte",   "int16_t",  "int32_t",  "int64_t",  "int8_t",
+"size_t", "uint16_t", "uint32_t", "uint64_t", "uint8_t",
+};
+
 // FIXME: This is copy&pasted from Sema. Put it in a common place and remove
 // duplication.

owenca wrote:

This comment is still correct. We need to call the function in the lexer to fix 
it.

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


[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-03 Thread Richard Smith via cfe-commits


@@ -34,9 +34,15 @@ const char *getTokenTypeName(TokenType Type) {
   return nullptr;
 }
 
+// Sorted common C++ non-keyword types.
+static SmallVector CppNonKeywordTypes = {
+"byte",   "int16_t",  "int32_t",  "int64_t",  "int8_t",
+"size_t", "uint16_t", "uint32_t", "uint64_t", "uint8_t",

zygoloid wrote:

According to codesearch.isocpp.org, `intptr_t`, `uintptr_t`, and `ptrdiff_t` 
are all more common than `int8_t`. Also I'd note that POSIX reserves all 
identifiers ending in `_t` for use as types, and C reserves all identifiers 
starting with `int` or `uint` and ending in `_t` for use as types.

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


[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-03 Thread Richard Smith via cfe-commits


@@ -34,9 +34,15 @@ const char *getTokenTypeName(TokenType Type) {
   return nullptr;
 }
 
+// Sorted common C++ non-keyword types.
+static SmallVector CppNonKeywordTypes = {
+"byte",   "int16_t",  "int32_t",  "int64_t",  "int8_t",
+"size_t", "uint16_t", "uint32_t", "uint64_t", "uint8_t",
+};
+
 // FIXME: This is copy&pasted from Sema. Put it in a common place and remove
 // duplication.

zygoloid wrote:

This function is no longer simply copy/pasted from `Sema`. It doesn't even do 
the same thing as the Sema function any more.

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


[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

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

owenca wrote:

> Another possibility to consider for the original bug: `(single_identifier)` 
> is almost certainly a cast, not redundant parentheses, unless 
> `single_identifier` names a macro argument. So I wonder if that would be a 
> better heuristic to use to fix the regression.

I don’t think that would work as`(identifier)` can be a number of constructs 
depending on the context. It can be part of a function/macro call, function 
declaration, macro definition, C++ cast, C cast, `sizeof` operand, etc. 


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


[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-03 Thread Richard Smith via cfe-commits

zygoloid wrote:

> > Another possibility to consider for the original bug: `(single_identifier)` 
> > is almost certainly a cast, not redundant parentheses, unless 
> > `single_identifier` names a macro argument. So I wonder if that would be a 
> > better heuristic to use to fix the regression.
> 
> I don’t think that would work as`(identifier)` can be a number of constructs 
> depending on the context. It can be part of a function/macro call, function 
> declaration, macro definition, C++ cast, C cast, `sizeof` operand, etc.

OK, but the context is deciding whether `(identifier)&x` or `(identifier)*x` is 
a binary operator or a cast. Given no other information, the fact that it's a 
single identifier seems like a very strong signal that it's a cast.

I don't think this PR fixes #83400 -- handling a small handful of common types 
won't address the same issue for the much larger class of cases where the type 
name is not one of these types. Eg, in #83400 itself the examples included:

```diff
-   static _FORCE_INLINE_ m_type get(const Variant *v) { return 
(m_type)*VariantInternal::get_int(v); }\
+   static _FORCE_INLINE_ m_type get(const Variant *v) { return 
(m_type) * VariantInternal::get_int(v); }  \
```

But looking for a parenthesized single identifier addresses all of the examples 
in the issue.

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


[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

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


@@ -34,9 +34,15 @@ const char *getTokenTypeName(TokenType Type) {
   return nullptr;
 }
 
+// Sorted common C++ non-keyword types.
+static SmallVector CppNonKeywordTypes = {
+"byte",   "int16_t",  "int32_t",  "int64_t",  "int8_t",
+"size_t", "uint16_t", "uint32_t", "uint64_t", "uint8_t",

owenca wrote:

I was aware of that. By “common” I mean common C-casted. We definitely don’t 
want to include POSIX-specific types as we have the TypeNames option for that. 
Also, we don’t want to cater to C-specific constructs if it might regress C++ 
code.

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


[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

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


@@ -34,9 +34,15 @@ const char *getTokenTypeName(TokenType Type) {
   return nullptr;
 }
 
+// Sorted common C++ non-keyword types.
+static SmallVector CppNonKeywordTypes = {
+"byte",   "int16_t",  "int32_t",  "int64_t",  "int8_t",
+"size_t", "uint16_t", "uint32_t", "uint64_t", "uint8_t",
+};
+
 // FIXME: This is copy&pasted from Sema. Put it in a common place and remove
 // duplication.

owenca wrote:

That was the case before this patch though.

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


[clang] [clang][Sema] Warn on return of pointer/reference to compound literal (PR #83741)

2024-03-03 Thread Youngsuk Kim via cfe-commits

https://github.com/JOE1994 created 
https://github.com/llvm/llvm-project/pull/83741

Emit a warning if pointer/reference to compound literal is returned from a 
function.

In C, compound literals in block scope are lvalues that have automatic storage 
duration. In C++, compound literals in block scope are temporaries.

In either case, returning a pointer/reference to a compound literal can cause a 
use-after-free bug.

Fixes #8678 

>From fc0cb9c44ec7945f1a88420675b667167908e07c Mon Sep 17 00:00:00 2001
From: JOE1994 
Date: Sun, 3 Mar 2024 12:38:49 -0500
Subject: [PATCH] [clang][Sema] Warn on return of pointer/reference to compound
 literal

Emit a warning if pointer/reference to compound literal is returned from a 
function.

In C, compound literals in block scope are lvalues that have automatic storage 
duration.
In C++, compound literals in block scope are temporaries.

In either case, returning a pointer/reference to a compound literal
can cause a use-after-free bug.
---
 clang/include/clang/Basic/DiagnosticSemaKinds.td |  2 +-
 clang/lib/Sema/SemaInit.cpp  | 12 
 clang/test/Analysis/stack-addr-ps.c  |  4 ++--
 3 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 91105d4231f06a..f5c88b8ae5aade 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9898,7 +9898,7 @@ def err_lifetimebound_ctor_dtor : Error<
 // CHECK: returning address/reference of stack memory
 def warn_ret_stack_addr_ref : Warning<
   "%select{address of|reference to}0 stack memory associated with "
-  "%select{local variable|parameter}2 %1 returned">,
+  "%select{local variable|parameter|compound literal}2 %1 returned">,
   InGroup;
 def warn_ret_local_temp_addr_ref : Warning<
   "returning %select{address of|reference to}0 local temporary object">,
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 0fd458837163e5..93b125382b164f 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -7734,6 +7734,14 @@ static void 
visitLocalsRetainedByReferenceBinding(IndirectLocalPath &Path,
 break;
   }
 
+  case Stmt::CompoundLiteralExprClass: {
+if (auto *CLE = dyn_cast(Init)) {
+  if (!CLE->isFileScope())
+Visit(Path, Local(CLE), RK);
+}
+break;
+  }
+
   // FIXME: Visit the left-hand side of an -> or ->*.
 
   default:
@@ -8289,6 +8297,10 @@ void Sema::checkInitializerLifetime(const 
InitializedEntity &Entity,
 if (LK == LK_StmtExprResult)
   return false;
 Diag(DiagLoc, diag::warn_ret_addr_label) << DiagRange;
+  } else if (auto *CLE = dyn_cast(L)) {
+Diag(DiagLoc, diag::warn_ret_stack_addr_ref)
+<< Entity.getType()->isReferenceType() << CLE->getInitializer() << 
2
+<< DiagRange;
   } else {
 Diag(DiagLoc, diag::warn_ret_local_temp_addr_ref)
  << Entity.getType()->isReferenceType() << DiagRange;
diff --git a/clang/test/Analysis/stack-addr-ps.c 
b/clang/test/Analysis/stack-addr-ps.c
index 26e1cc58350cab..e469396e1bb22a 100644
--- a/clang/test/Analysis/stack-addr-ps.c
+++ b/clang/test/Analysis/stack-addr-ps.c
@@ -20,13 +20,13 @@ int* f3(int x, int *y) {
 
 void* compound_literal(int x, int y) {
   if (x)
-return &(unsigned short){((unsigned short)0x22EF)}; // 
expected-warning{{Address of stack memory}}
+return &(unsigned short){((unsigned short)0x22EF)}; // 
expected-warning{{Address of stack memory}} expected-warning{{address of stack 
memory}}
 
   int* array[] = {};
   struct s { int z; double y; int w; };
   
   if (y)
-return &((struct s){ 2, 0.4, 5 * 8 }); // expected-warning{{Address of 
stack memory}}
+return &((struct s){ 2, 0.4, 5 * 8 }); // expected-warning{{Address of 
stack memory}} expected-warning{{address of stack memory}}
 
   
   void* p = &((struct s){ 42, 0.4, x ? 42 : 0 });

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


[clang] [clang][Sema] Warn on return of pointer/reference to compound literal (PR #83741)

2024-03-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Youngsuk Kim (JOE1994)


Changes

Emit a warning if pointer/reference to compound literal is returned from a 
function.

In C, compound literals in block scope are lvalues that have automatic storage 
duration. In C++, compound literals in block scope are temporaries.

In either case, returning a pointer/reference to a compound literal can cause a 
use-after-free bug.

Fixes #8678 

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


3 Files Affected:

- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+1-1) 
- (modified) clang/lib/Sema/SemaInit.cpp (+12) 
- (modified) clang/test/Analysis/stack-addr-ps.c (+2-2) 


``diff
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 91105d4231f06a..f5c88b8ae5aade 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9898,7 +9898,7 @@ def err_lifetimebound_ctor_dtor : Error<
 // CHECK: returning address/reference of stack memory
 def warn_ret_stack_addr_ref : Warning<
   "%select{address of|reference to}0 stack memory associated with "
-  "%select{local variable|parameter}2 %1 returned">,
+  "%select{local variable|parameter|compound literal}2 %1 returned">,
   InGroup;
 def warn_ret_local_temp_addr_ref : Warning<
   "returning %select{address of|reference to}0 local temporary object">,
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 0fd458837163e5..93b125382b164f 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -7734,6 +7734,14 @@ static void 
visitLocalsRetainedByReferenceBinding(IndirectLocalPath &Path,
 break;
   }
 
+  case Stmt::CompoundLiteralExprClass: {
+if (auto *CLE = dyn_cast(Init)) {
+  if (!CLE->isFileScope())
+Visit(Path, Local(CLE), RK);
+}
+break;
+  }
+
   // FIXME: Visit the left-hand side of an -> or ->*.
 
   default:
@@ -8289,6 +8297,10 @@ void Sema::checkInitializerLifetime(const 
InitializedEntity &Entity,
 if (LK == LK_StmtExprResult)
   return false;
 Diag(DiagLoc, diag::warn_ret_addr_label) << DiagRange;
+  } else if (auto *CLE = dyn_cast(L)) {
+Diag(DiagLoc, diag::warn_ret_stack_addr_ref)
+<< Entity.getType()->isReferenceType() << CLE->getInitializer() << 
2
+<< DiagRange;
   } else {
 Diag(DiagLoc, diag::warn_ret_local_temp_addr_ref)
  << Entity.getType()->isReferenceType() << DiagRange;
diff --git a/clang/test/Analysis/stack-addr-ps.c 
b/clang/test/Analysis/stack-addr-ps.c
index 26e1cc58350cab..e469396e1bb22a 100644
--- a/clang/test/Analysis/stack-addr-ps.c
+++ b/clang/test/Analysis/stack-addr-ps.c
@@ -20,13 +20,13 @@ int* f3(int x, int *y) {
 
 void* compound_literal(int x, int y) {
   if (x)
-return &(unsigned short){((unsigned short)0x22EF)}; // 
expected-warning{{Address of stack memory}}
+return &(unsigned short){((unsigned short)0x22EF)}; // 
expected-warning{{Address of stack memory}} expected-warning{{address of stack 
memory}}
 
   int* array[] = {};
   struct s { int z; double y; int w; };
   
   if (y)
-return &((struct s){ 2, 0.4, 5 * 8 }); // expected-warning{{Address of 
stack memory}}
+return &((struct s){ 2, 0.4, 5 * 8 }); // expected-warning{{Address of 
stack memory}} expected-warning{{address of stack memory}}
 
   
   void* p = &((struct s){ 42, 0.4, x ? 42 : 0 });

``




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


[clang] [ObjC] Check entire chain of superclasses to see if class layout is statically known (PR #81335)

2024-03-03 Thread via cfe-commits

AtariDreams wrote:

@JOE1994 Thoughts on this?

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


[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

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

owenca wrote:

> > > Another possibility to consider for the original bug: 
> > > `(single_identifier)` is almost certainly a cast, not redundant 
> > > parentheses, unless `single_identifier` names a macro argument. So I 
> > > wonder if that would be a better heuristic to use to fix the regression.
> > 
> > 
> > I don’t think that would work as`(identifier)` can be a number of 
> > constructs depending on the context. It can be part of a function/macro 
> > call, function declaration, macro definition, C++ cast, C cast, `sizeof` 
> > operand, etc.
> 
> OK, but the context is deciding whether `(identifier)&x` or `(identifier)*x` 
> is a binary operator or a cast. Given no other information, the fact that 
> it's a single identifier seems like a very strong signal that it's a cast.
> 
> I don't think this PR fixes #83400 -- handling a small handful of common 
> types won't address the same issue for the much larger class of cases where 
> the type name is not one of these types. Eg, in #83400 itself the examples 
> included:
> 
> ```diff
> - static _FORCE_INLINE_ m_type get(const Variant *v) { return 
> (m_type)*VariantInternal::get_int(v); }\
> + static _FORCE_INLINE_ m_type get(const Variant *v) { return 
> (m_type) * VariantInternal::get_int(v); }  \
> ```
> 
> But looking for a parenthesized single identifier addresses all of the 
> examples in the issue.

This patch does not only fix formatting of C-casting to a C++ standard type. It 
correctly identifies (most of) such types and might have fixed other kinds of 
bugs. For casting to a user-defined type, the TypeNames option can be used.

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


[clang] [clang][Sema] Warn on return of pointer/reference to compound literal (PR #83741)

2024-03-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 0c90e8837a9e5f27985ccaf85120083db9e1b43e 
fc0cb9c44ec7945f1a88420675b667167908e07c -- clang/lib/Sema/SemaInit.cpp 
clang/test/Analysis/stack-addr-ps.c
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 93b125382b..1d81330b7e 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -7742,7 +7742,7 @@ static void 
visitLocalsRetainedByReferenceBinding(IndirectLocalPath &Path,
 break;
   }
 
-  // FIXME: Visit the left-hand side of an -> or ->*.
+// FIXME: Visit the left-hand side of an -> or ->*.
 
   default:
 break;

``




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


[clang] [clang][Sema] Warn on return of pointer/reference to compound literal (PR #83741)

2024-03-03 Thread via cfe-commits

https://github.com/AtariDreams commented:

Isn't this warning a duplicate of what is already here?

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


[clang] [clang][Sema] Warn on return of pointer/reference to compound literal (PR #83741)

2024-03-03 Thread Youngsuk Kim via cfe-commits

JOE1994 wrote:

> Isn't this warning a duplicate of what is already here?

The diganostic warning is not emitted when `clang` is run without the 
`-analyze` flag.

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


[clang] [ObjC] Check entire chain of superclasses to see if class layout is statically known (PR #81335)

2024-03-03 Thread Youngsuk Kim via cfe-commits

JOE1994 wrote:

> @JOE1994 Thoughts on this?

I'm not an ideal reviewer for this as I'm unfamiliar with ObjC side of Clang,
but I'll come back to leave a review and to help merge this if this doesn't get 
merged by the end of the day :)

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


[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

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


@@ -34,9 +34,15 @@ const char *getTokenTypeName(TokenType Type) {
   return nullptr;
 }
 
+// Sorted common C++ non-keyword types.
+static SmallVector CppNonKeywordTypes = {
+"byte",   "int16_t",  "int32_t",  "int64_t",  "int8_t",

owenca wrote:

Good point about `byte`. I will remove it from the list.

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


[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-03 Thread Richard Smith via cfe-commits


@@ -34,9 +34,15 @@ const char *getTokenTypeName(TokenType Type) {
   return nullptr;
 }
 
+// Sorted common C++ non-keyword types.
+static SmallVector CppNonKeywordTypes = {
+"byte",   "int16_t",  "int32_t",  "int64_t",  "int8_t",
+"size_t", "uint16_t", "uint32_t", "uint64_t", "uint8_t",
+};
+
 // FIXME: This is copy&pasted from Sema. Put it in a common place and remove
 // duplication.

zygoloid wrote:

Before this patch, the two functions were intended to do the same thing, but 
have apparently diverged. After this patch they are not intended to do the same 
thing. The FIXME is wrong, can you fix it please?

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


[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-03 Thread Richard Smith via cfe-commits

zygoloid wrote:

> This patch does not only fix formatting of C-casting to a C++ standard type. 
> It correctly identifies (most of) such types and might have fixed other kinds 
> of bugs.

Sure, this patch seems like a good change. But it does not fix #83400.

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


[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

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


@@ -34,9 +34,15 @@ const char *getTokenTypeName(TokenType Type) {
   return nullptr;
 }
 
+// Sorted common C++ non-keyword types.
+static SmallVector CppNonKeywordTypes = {
+"byte",   "int16_t",  "int32_t",  "int64_t",  "int8_t",
+"size_t", "uint16_t", "uint32_t", "uint64_t", "uint8_t",

owenca wrote:

I considered to include all [fixed width integer 
types](https://en.cppreference.com/w/cpp/types/integer) but decided to include 
only the common ones to avoid possible regressions. (I also looked at [fixed 
width floating-point 
types](https://en.cppreference.com/w/cpp/types/floating-point) and think we 
should wait until C++23 is commonly used.)

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


[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-03 Thread Richard Smith via cfe-commits


@@ -34,9 +34,15 @@ const char *getTokenTypeName(TokenType Type) {
   return nullptr;
 }
 
+// Sorted common C++ non-keyword types.
+static SmallVector CppNonKeywordTypes = {
+"byte",   "int16_t",  "int32_t",  "int64_t",  "int8_t",
+"size_t", "uint16_t", "uint32_t", "uint64_t", "uint8_t",

zygoloid wrote:

On codesearch.isocpp.org, `(intptr_t)` is more common than `(int8_t)` and 
`(int16_t)`, and similar to `(int32_t)`. But why should this general function 
that's used in various places in clang-format care about how often the type is 
cast with a C-style cast? That doesn't make sense to me.

I find it extremely unlikely that anyone would use `intN_t` as anything other 
than a type; I think your concerns about regressions are unfounded. In 
contrast, there are 518 hits for `(intptr_t)&` in isocpp codesearch, which 
seems pretty logical to me because casts to `(intptr_t)` will be casts from 
pointers.

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


[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-03 Thread Richard Smith via cfe-commits

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


[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

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

owenca wrote:

> > This patch does not only fix formatting of C-casting to a C++ standard 
> > type. It correctly identifies (most of) such types and might have fixed 
> > other kinds of bugs.
> 
> Sure, this patch seems like a good change. But it does not fix #83400.

It does fix the example given. For other diffs involving user-defined types, 
the user need to use the TypeNames option. (If that doesn't work, a separate 
issue should be filed.)

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


[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

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

owenca wrote:

> But looking for a parenthesized single identifier addresses all of the 
> examples in the issue.

I don't think it would work, but you are welcome to submit a patch to prove me 
wrong. 🙂 

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


[clang] [clang][Sema] Add diagnostics for out-of-bounds vector access (PR #76569)

2024-03-03 Thread via cfe-commits

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


[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

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


@@ -34,9 +34,15 @@ const char *getTokenTypeName(TokenType Type) {
   return nullptr;
 }
 
+// Sorted common C++ non-keyword types.
+static SmallVector CppNonKeywordTypes = {
+"byte",   "int16_t",  "int32_t",  "int64_t",  "int8_t",
+"size_t", "uint16_t", "uint32_t", "uint64_t", "uint8_t",

owenca wrote:

> I find it extremely unlikely that anyone would use `intN_t` as anything other 
> than a type; I think your concerns about regressions are unfounded.

"Extremely unlikely" doesn't mean impossible.

I actually hesitated on whether to include `intptr_t`/`uintprt_t` because they 
are marked as optional. I can include them though.

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


[clang] [Driver][RISCV] Forward --no-relax option to linker for RISC-V on *BS… (PR #83216)

2024-03-03 Thread Brad Smith via cfe-commits


@@ -203,3 +203,12 @@
 // RELOCATABLE-NOT: "-l
 // RELOCATABLE-NOT: crt{{[^./\\]+}}.o
 
+// Check that the -X flag is passed to the linker on riscv64

brad0 wrote:

When I was putting the diff together I was questioning whether I should combine 
the two into one instance.

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


[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

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


@@ -34,9 +34,15 @@ const char *getTokenTypeName(TokenType Type) {
   return nullptr;
 }
 
+// Sorted common C++ non-keyword types.
+static SmallVector CppNonKeywordTypes = {
+"byte",   "int16_t",  "int32_t",  "int64_t",  "int8_t",
+"size_t", "uint16_t", "uint32_t", "uint64_t", "uint8_t",
+};
+
 // FIXME: This is copy&pasted from Sema. Put it in a common place and remove
 // duplication.

owenca wrote:

See 
[here](https://github.com/llvm/llvm-project/pull/83533#issuecomment-1974198544).
 After this patch,I will add another parameter and call 
`Token::isSimpleTypeSpecifier()` (which was moved out of `Sema` in #80101) 
directly. That's the right time to fix (i.e. remove) the comment.

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


[clang] [Driver][RISCV] Forward --no-relax option to linker for RISC-V on *BS… (PR #83216)

2024-03-03 Thread Brad Smith via cfe-commits

https://github.com/brad0 updated https://github.com/llvm/llvm-project/pull/83216

>From 35aee78eda1f3e7ac9e217982227c0769eda5ae1 Mon Sep 17 00:00:00 2001
From: Brad Smith 
Date: Tue, 27 Feb 2024 21:07:09 -0500
Subject: [PATCH] [Driver][RISCV] Forward --no-relax option to linker for
 RISC-V on *BSD, Fuchsia and Haiku

Based on https://github.com/llvm/llvm-project/pull/76432
---
 clang/lib/Driver/ToolChains/FreeBSD.cpp | 11 ---
 clang/lib/Driver/ToolChains/Fuchsia.cpp |  5 -
 clang/lib/Driver/ToolChains/Haiku.cpp   |  7 +--
 clang/lib/Driver/ToolChains/NetBSD.cpp  |  5 -
 clang/lib/Driver/ToolChains/OpenBSD.cpp |  6 +-
 clang/test/Driver/freebsd.c |  3 +++
 clang/test/Driver/fuchsia.c |  4 
 clang/test/Driver/haiku.c   |  4 
 clang/test/Driver/netbsd.c  |  6 ++
 clang/test/Driver/openbsd.c |  5 ++---
 10 files changed, 45 insertions(+), 11 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp 
b/clang/lib/Driver/ToolChains/FreeBSD.cpp
index 9d698f77583950..c5757ddebb0f3e 100644
--- a/clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -133,6 +133,7 @@ void freebsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
const char *LinkingOutput) const {
   const auto &ToolChain = static_cast(getToolChain());
   const Driver &D = ToolChain.getDriver();
+  const llvm::Triple &Triple = ToolChain.getTriple();
   const llvm::Triple::ArchType Arch = ToolChain.getArch();
   const bool IsPIE =
   !Args.hasArg(options::OPT_shared) &&
@@ -165,8 +166,7 @@ void freebsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   CmdArgs.push_back("-dynamic-linker");
   CmdArgs.push_back("/libexec/ld-elf.so.1");
 }
-const llvm::Triple &T = ToolChain.getTriple();
-if (Arch == llvm::Triple::arm || T.isX86())
+if (Arch == llvm::Triple::arm || Triple.isX86())
   CmdArgs.push_back("--hash-style=both");
 CmdArgs.push_back("--enable-new-dtags");
   }
@@ -212,12 +212,17 @@ void freebsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   case llvm::Triple::riscv64:
 CmdArgs.push_back("-m");
 CmdArgs.push_back("elf64lriscv");
-CmdArgs.push_back("-X");
 break;
   default:
 break;
   }
 
+  if (Triple.isRISCV64()) {
+CmdArgs.push_back("-X");
+if (Args.hasArg(options::OPT_mno_relax))
+  CmdArgs.push_back("--no-relax");
+  }
+
   if (Arg *A = Args.getLastArg(options::OPT_G)) {
 if (ToolChain.getTriple().isMIPS()) {
   StringRef v = A->getValue();
diff --git a/clang/lib/Driver/ToolChains/Fuchsia.cpp 
b/clang/lib/Driver/ToolChains/Fuchsia.cpp
index 14b838500becce..237d1554d4970d 100644
--- a/clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ b/clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -119,8 +119,11 @@ void fuchsia::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 CmdArgs.push_back(Args.MakeArgString(Dyld));
   }
 
-  if (ToolChain.getArch() == llvm::Triple::riscv64)
+  if (Triple.isRISCV64()) {
 CmdArgs.push_back("-X");
+if (Args.hasArg(options::OPT_mno_relax))
+  CmdArgs.push_back("--no-relax");
+  }
 
   CmdArgs.push_back("-o");
   CmdArgs.push_back(Output.getFilename());
diff --git a/clang/lib/Driver/ToolChains/Haiku.cpp 
b/clang/lib/Driver/ToolChains/Haiku.cpp
index ca7faa68765abf..30464e2229e65b 100644
--- a/clang/lib/Driver/ToolChains/Haiku.cpp
+++ b/clang/lib/Driver/ToolChains/Haiku.cpp
@@ -25,7 +25,7 @@ void haiku::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
const char *LinkingOutput) const {
   const auto &ToolChain = static_cast(getToolChain());
   const Driver &D = ToolChain.getDriver();
-  const llvm::Triple::ArchType Arch = ToolChain.getArch();
+  const llvm::Triple &Triple = ToolChain.getTriple();
   const bool Static = Args.hasArg(options::OPT_static);
   const bool Shared = Args.hasArg(options::OPT_shared);
   ArgStringList CmdArgs;
@@ -61,8 +61,11 @@ void haiku::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   if (!Shared)
 CmdArgs.push_back("--no-undefined");
 
-  if (Arch == llvm::Triple::riscv64)
+  if (Triple.isRISCV64()) {
 CmdArgs.push_back("-X");
+if (Args.hasArg(options::OPT_mno_relax))
+  CmdArgs.push_back("--no-relax");
+  }
 
   assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
   if (Output.isFilename()) {
diff --git a/clang/lib/Driver/ToolChains/NetBSD.cpp 
b/clang/lib/Driver/ToolChains/NetBSD.cpp
index 645d0311641f34..0eec8fddabd5db 100644
--- a/clang/lib/Driver/ToolChains/NetBSD.cpp
+++ b/clang/lib/Driver/ToolChains/NetBSD.cpp
@@ -240,8 +240,11 @@ void netbsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 break;
   }
 
-  if (Triple.isRISCV())
+  if (Triple.isRISCV()) {
 CmdArgs.push_back("-X");
+if (Args.hasArg(options::OPT_mno_relax))
+  CmdArgs.push_back("--no-relax");
+  }
 
  

[clang] [Driver][RISCV] Forward --no-relax option to linker for RISC-V on *BS… (PR #83216)

2024-03-03 Thread Brad Smith via cfe-commits

brad0 wrote:

I fixed up the tesets.

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


[clang] [Driver][RISCV] Forward --no-relax option to linker for RISC-V on *BS… (PR #83216)

2024-03-03 Thread Brad Smith via cfe-commits

https://github.com/brad0 updated https://github.com/llvm/llvm-project/pull/83216

>From 6c68cdaef71eacbad4fc2f6b81d2845c08b124fd Mon Sep 17 00:00:00 2001
From: Brad Smith 
Date: Tue, 27 Feb 2024 21:07:09 -0500
Subject: [PATCH] [Driver][RISCV] Forward --no-relax option to linker for
 RISC-V on *BSD, Fuchsia and Haiku

Based on https://github.com/llvm/llvm-project/pull/76432
---
 clang/lib/Driver/ToolChains/FreeBSD.cpp | 11 ---
 clang/lib/Driver/ToolChains/Fuchsia.cpp |  5 -
 clang/lib/Driver/ToolChains/Haiku.cpp   |  7 +--
 clang/lib/Driver/ToolChains/NetBSD.cpp  |  5 -
 clang/lib/Driver/ToolChains/OpenBSD.cpp |  6 +-
 clang/test/Driver/freebsd.c |  3 +++
 clang/test/Driver/fuchsia.c |  4 
 clang/test/Driver/haiku.c   |  4 
 clang/test/Driver/netbsd.c  |  6 ++
 clang/test/Driver/openbsd.c |  5 ++---
 10 files changed, 45 insertions(+), 11 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp 
b/clang/lib/Driver/ToolChains/FreeBSD.cpp
index 9d698f77583950..c5757ddebb0f3e 100644
--- a/clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -133,6 +133,7 @@ void freebsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
const char *LinkingOutput) const {
   const auto &ToolChain = static_cast(getToolChain());
   const Driver &D = ToolChain.getDriver();
+  const llvm::Triple &Triple = ToolChain.getTriple();
   const llvm::Triple::ArchType Arch = ToolChain.getArch();
   const bool IsPIE =
   !Args.hasArg(options::OPT_shared) &&
@@ -165,8 +166,7 @@ void freebsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   CmdArgs.push_back("-dynamic-linker");
   CmdArgs.push_back("/libexec/ld-elf.so.1");
 }
-const llvm::Triple &T = ToolChain.getTriple();
-if (Arch == llvm::Triple::arm || T.isX86())
+if (Arch == llvm::Triple::arm || Triple.isX86())
   CmdArgs.push_back("--hash-style=both");
 CmdArgs.push_back("--enable-new-dtags");
   }
@@ -212,12 +212,17 @@ void freebsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   case llvm::Triple::riscv64:
 CmdArgs.push_back("-m");
 CmdArgs.push_back("elf64lriscv");
-CmdArgs.push_back("-X");
 break;
   default:
 break;
   }
 
+  if (Triple.isRISCV64()) {
+CmdArgs.push_back("-X");
+if (Args.hasArg(options::OPT_mno_relax))
+  CmdArgs.push_back("--no-relax");
+  }
+
   if (Arg *A = Args.getLastArg(options::OPT_G)) {
 if (ToolChain.getTriple().isMIPS()) {
   StringRef v = A->getValue();
diff --git a/clang/lib/Driver/ToolChains/Fuchsia.cpp 
b/clang/lib/Driver/ToolChains/Fuchsia.cpp
index 14b838500becce..237d1554d4970d 100644
--- a/clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ b/clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -119,8 +119,11 @@ void fuchsia::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 CmdArgs.push_back(Args.MakeArgString(Dyld));
   }
 
-  if (ToolChain.getArch() == llvm::Triple::riscv64)
+  if (Triple.isRISCV64()) {
 CmdArgs.push_back("-X");
+if (Args.hasArg(options::OPT_mno_relax))
+  CmdArgs.push_back("--no-relax");
+  }
 
   CmdArgs.push_back("-o");
   CmdArgs.push_back(Output.getFilename());
diff --git a/clang/lib/Driver/ToolChains/Haiku.cpp 
b/clang/lib/Driver/ToolChains/Haiku.cpp
index ca7faa68765abf..30464e2229e65b 100644
--- a/clang/lib/Driver/ToolChains/Haiku.cpp
+++ b/clang/lib/Driver/ToolChains/Haiku.cpp
@@ -25,7 +25,7 @@ void haiku::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
const char *LinkingOutput) const {
   const auto &ToolChain = static_cast(getToolChain());
   const Driver &D = ToolChain.getDriver();
-  const llvm::Triple::ArchType Arch = ToolChain.getArch();
+  const llvm::Triple &Triple = ToolChain.getTriple();
   const bool Static = Args.hasArg(options::OPT_static);
   const bool Shared = Args.hasArg(options::OPT_shared);
   ArgStringList CmdArgs;
@@ -61,8 +61,11 @@ void haiku::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   if (!Shared)
 CmdArgs.push_back("--no-undefined");
 
-  if (Arch == llvm::Triple::riscv64)
+  if (Triple.isRISCV64()) {
 CmdArgs.push_back("-X");
+if (Args.hasArg(options::OPT_mno_relax))
+  CmdArgs.push_back("--no-relax");
+  }
 
   assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
   if (Output.isFilename()) {
diff --git a/clang/lib/Driver/ToolChains/NetBSD.cpp 
b/clang/lib/Driver/ToolChains/NetBSD.cpp
index 645d0311641f34..0eec8fddabd5db 100644
--- a/clang/lib/Driver/ToolChains/NetBSD.cpp
+++ b/clang/lib/Driver/ToolChains/NetBSD.cpp
@@ -240,8 +240,11 @@ void netbsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 break;
   }
 
-  if (Triple.isRISCV())
+  if (Triple.isRISCV()) {
 CmdArgs.push_back("-X");
+if (Args.hasArg(options::OPT_mno_relax))
+  CmdArgs.push_back("--no-relax");
+  }
 
  

[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

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

https://github.com/owenca updated 
https://github.com/llvm/llvm-project/pull/83709

>From 91d6e4c6e0ae2e1d79edf496df22978a4e1f3e1a Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Sat, 2 Mar 2024 22:08:29 -0800
Subject: [PATCH 1/3] [clang-format] Handle common C++ non-keyword types as
 such

Fixes #83400.
---
 clang/lib/Format/FormatToken.cpp  | 16 --
 clang/lib/Format/FormatToken.h|  4 +--
 clang/lib/Format/QualifierAlignmentFixer.cpp  | 25 +---
 clang/lib/Format/QualifierAlignmentFixer.h|  5 ++--
 clang/lib/Format/TokenAnnotator.cpp   | 29 ++-
 clang/lib/Format/UnwrappedLineParser.cpp  | 12 
 clang/unittests/Format/TokenAnnotatorTest.cpp |  6 
 7 files changed, 61 insertions(+), 36 deletions(-)

diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp
index 56a7b2d6387765..02952bd20acf9a 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -34,9 +34,15 @@ const char *getTokenTypeName(TokenType Type) {
   return nullptr;
 }
 
+// Sorted common C++ non-keyword types.
+static SmallVector CppNonKeywordTypes = {
+"byte",   "int16_t",  "int32_t",  "int64_t",  "int8_t",
+"size_t", "uint16_t", "uint32_t", "uint64_t", "uint8_t",
+};
+
 // FIXME: This is copy&pasted from Sema. Put it in a common place and remove
 // duplication.
-bool FormatToken::isSimpleTypeSpecifier() const {
+bool FormatToken::isSimpleTypeSpecifier(bool IsCpp) const {
   switch (Tok.getKind()) {
   case tok::kw_short:
   case tok::kw_long:
@@ -66,13 +72,17 @@ bool FormatToken::isSimpleTypeSpecifier() const {
   case tok::kw_decltype:
   case tok::kw__Atomic:
 return true;
+  case tok::identifier:
+return IsCpp && std::binary_search(CppNonKeywordTypes.begin(),
+   CppNonKeywordTypes.end(), TokenText);
   default:
 return false;
   }
 }
 
-bool FormatToken::isTypeOrIdentifier() const {
-  return isSimpleTypeSpecifier() || Tok.isOneOf(tok::kw_auto, tok::identifier);
+bool FormatToken::isTypeOrIdentifier(bool IsCpp) const {
+  return isSimpleTypeSpecifier(IsCpp) ||
+ Tok.isOneOf(tok::kw_auto, tok::identifier);
 }
 
 bool FormatToken::isBlockIndentedInitRBrace(const FormatStyle &Style) const {
diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 31245495041960..2bc136c51d23f1 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -674,9 +674,9 @@ struct FormatToken {
   }
 
   /// Determine whether the token is a simple-type-specifier.
-  [[nodiscard]] bool isSimpleTypeSpecifier() const;
+  [[nodiscard]] bool isSimpleTypeSpecifier(bool IsCpp) const;
 
-  [[nodiscard]] bool isTypeOrIdentifier() const;
+  [[nodiscard]] bool isTypeOrIdentifier(bool IsCpp) const;
 
   bool isObjCAccessSpecifier() const {
 return is(tok::at) && Next &&
diff --git a/clang/lib/Format/QualifierAlignmentFixer.cpp 
b/clang/lib/Format/QualifierAlignmentFixer.cpp
index 0c63d330b5aed4..834ae115908856 100644
--- a/clang/lib/Format/QualifierAlignmentFixer.cpp
+++ b/clang/lib/Format/QualifierAlignmentFixer.cpp
@@ -268,11 +268,13 @@ const FormatToken 
*LeftRightQualifierAlignmentFixer::analyzeRight(
   if (isPossibleMacro(TypeToken))
 return Tok;
 
+  const bool IsCpp = Style.isCpp();
+
   // The case `const long long int volatile` -> `long long int const volatile`
   // The case `long const long int volatile` -> `long long int const volatile`
   // The case `long long volatile int const` -> `long long int const volatile`
   // The case `const long long volatile int` -> `long long int const volatile`
-  if (TypeToken->isSimpleTypeSpecifier()) {
+  if (TypeToken->isSimpleTypeSpecifier(IsCpp)) {
 // The case `const decltype(foo)` -> `const decltype(foo)`
 // The case `const typeof(foo)` -> `const typeof(foo)`
 // The case `const _Atomic(foo)` -> `const _Atomic(foo)`
@@ -280,8 +282,10 @@ const FormatToken 
*LeftRightQualifierAlignmentFixer::analyzeRight(
   return Tok;
 
 const FormatToken *LastSimpleTypeSpecifier = TypeToken;
-while (isQualifierOrType(LastSimpleTypeSpecifier->getNextNonComment()))
+while (isQualifierOrType(LastSimpleTypeSpecifier->getNextNonComment(),
+ IsCpp)) {
   LastSimpleTypeSpecifier = LastSimpleTypeSpecifier->getNextNonComment();
+}
 
 rotateTokens(SourceMgr, Fixes, Tok, LastSimpleTypeSpecifier,
  /*Left=*/false);
@@ -291,7 +295,7 @@ const FormatToken 
*LeftRightQualifierAlignmentFixer::analyzeRight(
   // The case  `unsigned short const` -> `unsigned short const`
   // The case:
   // `unsigned short volatile const` -> `unsigned short const volatile`
-  if (PreviousCheck && PreviousCheck->isSimpleTypeSpecifier()) {
+  if (PreviousCheck && PreviousCheck->isSimpleTypeSpecifier(IsCpp)) {
 if (LastQual != Tok)
   rotateTokens(SourceMgr, Fixes, Tok, LastQual, /*Left=*/false);
 return Tok;
@@ -4

[clang] [Driver][RISCV] Forward --no-relax option to linker for RISC-V on *BS… (PR #83216)

2024-03-03 Thread Brad Smith via cfe-commits

https://github.com/brad0 updated https://github.com/llvm/llvm-project/pull/83216

>From 31bb7cee2eb783a242734f3778269efcdb460a4c Mon Sep 17 00:00:00 2001
From: Brad Smith 
Date: Tue, 27 Feb 2024 21:07:09 -0500
Subject: [PATCH] [Driver][RISCV] Forward --no-relax option to linker for
 RISC-V on *BSD, Fuchsia and Haiku

Based on https://github.com/llvm/llvm-project/pull/76432
---
 clang/lib/Driver/ToolChains/FreeBSD.cpp | 11 ---
 clang/lib/Driver/ToolChains/Fuchsia.cpp |  5 -
 clang/lib/Driver/ToolChains/Haiku.cpp   |  7 +--
 clang/lib/Driver/ToolChains/NetBSD.cpp  |  5 -
 clang/lib/Driver/ToolChains/OpenBSD.cpp |  6 +-
 clang/test/Driver/freebsd.c |  4 
 clang/test/Driver/fuchsia.c |  5 +
 clang/test/Driver/haiku.c   |  5 +
 clang/test/Driver/netbsd.c  |  7 +++
 clang/test/Driver/openbsd.c |  8 
 10 files changed, 51 insertions(+), 12 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp 
b/clang/lib/Driver/ToolChains/FreeBSD.cpp
index 9d698f77583950..c5757ddebb0f3e 100644
--- a/clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -133,6 +133,7 @@ void freebsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
const char *LinkingOutput) const {
   const auto &ToolChain = static_cast(getToolChain());
   const Driver &D = ToolChain.getDriver();
+  const llvm::Triple &Triple = ToolChain.getTriple();
   const llvm::Triple::ArchType Arch = ToolChain.getArch();
   const bool IsPIE =
   !Args.hasArg(options::OPT_shared) &&
@@ -165,8 +166,7 @@ void freebsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   CmdArgs.push_back("-dynamic-linker");
   CmdArgs.push_back("/libexec/ld-elf.so.1");
 }
-const llvm::Triple &T = ToolChain.getTriple();
-if (Arch == llvm::Triple::arm || T.isX86())
+if (Arch == llvm::Triple::arm || Triple.isX86())
   CmdArgs.push_back("--hash-style=both");
 CmdArgs.push_back("--enable-new-dtags");
   }
@@ -212,12 +212,17 @@ void freebsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   case llvm::Triple::riscv64:
 CmdArgs.push_back("-m");
 CmdArgs.push_back("elf64lriscv");
-CmdArgs.push_back("-X");
 break;
   default:
 break;
   }
 
+  if (Triple.isRISCV64()) {
+CmdArgs.push_back("-X");
+if (Args.hasArg(options::OPT_mno_relax))
+  CmdArgs.push_back("--no-relax");
+  }
+
   if (Arg *A = Args.getLastArg(options::OPT_G)) {
 if (ToolChain.getTriple().isMIPS()) {
   StringRef v = A->getValue();
diff --git a/clang/lib/Driver/ToolChains/Fuchsia.cpp 
b/clang/lib/Driver/ToolChains/Fuchsia.cpp
index 14b838500becce..237d1554d4970d 100644
--- a/clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ b/clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -119,8 +119,11 @@ void fuchsia::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 CmdArgs.push_back(Args.MakeArgString(Dyld));
   }
 
-  if (ToolChain.getArch() == llvm::Triple::riscv64)
+  if (Triple.isRISCV64()) {
 CmdArgs.push_back("-X");
+if (Args.hasArg(options::OPT_mno_relax))
+  CmdArgs.push_back("--no-relax");
+  }
 
   CmdArgs.push_back("-o");
   CmdArgs.push_back(Output.getFilename());
diff --git a/clang/lib/Driver/ToolChains/Haiku.cpp 
b/clang/lib/Driver/ToolChains/Haiku.cpp
index ca7faa68765abf..30464e2229e65b 100644
--- a/clang/lib/Driver/ToolChains/Haiku.cpp
+++ b/clang/lib/Driver/ToolChains/Haiku.cpp
@@ -25,7 +25,7 @@ void haiku::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
const char *LinkingOutput) const {
   const auto &ToolChain = static_cast(getToolChain());
   const Driver &D = ToolChain.getDriver();
-  const llvm::Triple::ArchType Arch = ToolChain.getArch();
+  const llvm::Triple &Triple = ToolChain.getTriple();
   const bool Static = Args.hasArg(options::OPT_static);
   const bool Shared = Args.hasArg(options::OPT_shared);
   ArgStringList CmdArgs;
@@ -61,8 +61,11 @@ void haiku::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   if (!Shared)
 CmdArgs.push_back("--no-undefined");
 
-  if (Arch == llvm::Triple::riscv64)
+  if (Triple.isRISCV64()) {
 CmdArgs.push_back("-X");
+if (Args.hasArg(options::OPT_mno_relax))
+  CmdArgs.push_back("--no-relax");
+  }
 
   assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
   if (Output.isFilename()) {
diff --git a/clang/lib/Driver/ToolChains/NetBSD.cpp 
b/clang/lib/Driver/ToolChains/NetBSD.cpp
index 645d0311641f34..0eec8fddabd5db 100644
--- a/clang/lib/Driver/ToolChains/NetBSD.cpp
+++ b/clang/lib/Driver/ToolChains/NetBSD.cpp
@@ -240,8 +240,11 @@ void netbsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 break;
   }
 
-  if (Triple.isRISCV())
+  if (Triple.isRISCV()) {
 CmdArgs.push_back("-X");
+if (Args.hasArg(options::OPT_mno_relax))
+  CmdArgs.push_back("--no-relax");
+ 

[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-03 Thread Krzysztof Parzyszek via cfe-commits


@@ -619,44 +595,22 @@ bool 
clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) {
 }
 
 bool clang::isOpenMPTaskLoopDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_taskloop || DKind == OMPD_taskloop_simd ||
- DKind == OMPD_master_taskloop || DKind == OMPD_master_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop ||
- DKind == OMPD_masked_taskloop || DKind == OMPD_masked_taskloop_simd ||
- DKind == OMPD_parallel_masked_taskloop ||
- DKind == OMPD_parallel_masked_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop_simd;
+  return DKind == OMPD_taskloop ||
+ llvm::is_contained(getLeafConstructs(DKind), OMPD_taskloop);
 }
 
 bool clang::isOpenMPParallelDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_parallel || DKind == OMPD_parallel_for ||
- DKind == OMPD_parallel_for_simd || DKind == OMPD_parallel_sections ||
- DKind == OMPD_target_parallel || DKind == OMPD_target_parallel_for ||
- DKind == OMPD_distribute_parallel_for ||
- DKind == OMPD_distribute_parallel_for_simd ||
- DKind == OMPD_target_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute_parallel_for_simd ||
- DKind == OMPD_parallel_master || DKind == OMPD_parallel_masked ||
- DKind == OMPD_parallel_master_taskloop ||
- DKind == OMPD_parallel_master_taskloop_simd ||
- DKind == OMPD_parallel_masked_taskloop ||
- DKind == OMPD_parallel_masked_taskloop_simd ||
- DKind == OMPD_parallel_loop || DKind == OMPD_target_parallel_loop ||
- DKind == OMPD_teams_loop;
+  if (DKind == OMPD_parallel_workshare)
+return false;

kparzysz wrote:

I removed the check.  Formally, it does fall under the "parallel" family of 
directives, so I think we shouldn't exclude it on the basis that it will never 
show up.

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


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-03 Thread Krzysztof Parzyszek via cfe-commits

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


  1   2   >