[PATCH] D148088: [RFC][clangd] Move preamble index task to a seperate task

2023-04-27 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

> We would like to move the preamble index out of the critical path

Could you provide motivation why you need to do it? What is the underlying 
problem that this change is trying to solve?
We rely on preamble being indexed at that particular time for correct results 
in future steps, it's definitely not a no-op change even if the threading 
issues are resolved (see the other comment).




Comment at: clang-tools-extra/clangd/ClangdServer.cpp:88
+if (PreambleIndexTask)
+  PreambleIndexTask->runAsync("task:" + Path + Version,
+  std::move(Task));

This definitely does not work. After `onPreambleAST` returns, the AST will be 
destroyed and async tasks may access it afterwards.



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148088/new/

https://reviews.llvm.org/D148088

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


[PATCH] D149280: [clang-tidy] Add modernize-printf-to-std-print check

2023-04-27 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tools-extra/clang-tidy/modernize/PrintfToStdPrintCheck.cpp:66
+  if (Converter.canApply()) {
+const auto *PrintfCall = Printf->getCallee();
+DiagnosticBuilder Diag =

Please don't use `auto` unless type is explicitly stated in same statement or 
iterator.



Comment at: clang-tools-extra/clang-tidy/modernize/PrintfToStdPrintCheck.h:15
+namespace clang::tidy::modernize {
+/// Documentation goes here.
+///

Should be elaborated or removed.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:171
 
+- New :doc: `modernize-printf-to-std-print
+  ` check.

Please keep alphabetical order (by check name) in this section.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/modernize/printf-to-std-print.rst:6
+
+This check is capable of converting calls to printf to calls to std::print
+whilst also modifying the format string appropriately.

Please make first statement same as in Release Notes. Please highlight language 
constructs (like `printf`) with double back-ticks.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/modernize/printf-to-std-print.rst:11
+
+ fprintf(stderr, "The %s is %3d\n", answer, value);
+

Please prepend with `.. code-block:: c++` line. Same for other snippets.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/modernize/printf-to-std-print.rst:73
+   printf-style format string and the arguments to be formatted follow
+   immediately afterwards.
+

Please add information about default value.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149280/new/

https://reviews.llvm.org/D149280

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


[PATCH] D149321: [clang][analyzer] Display buffer sizes in StdCLibraryFunctionArgs checker

2023-04-27 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 517554.
balazske added a comment.

using "wihch" at argument values


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149321/new/

https://reviews.llvm.org/D149321

Files:
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
  clang/test/Analysis/std-c-library-functions-arg-constraints-notes.cpp
  clang/test/Analysis/std-c-library-functions-arg-constraints-tracking-notes.c
  clang/test/Analysis/std-c-library-functions-arg-constraints.c

Index: clang/test/Analysis/std-c-library-functions-arg-constraints.c
===
--- clang/test/Analysis/std-c-library-functions-arg-constraints.c
+++ clang/test/Analysis/std-c-library-functions-arg-constraints.c
@@ -210,9 +210,9 @@
   // The 3rd parameter should be the number of elements to read, not
   // the size in bytes.
   fread(wbuf, size, nitems, file); // \
-  // report-warning{{The 1st argument to 'fread' is out of the accepted range; It should be a buffer with size equal to or greater than the value of the 2nd argument times the 3rd argument}} \
-  // bugpath-warning{{The 1st argument to 'fread' is out of the accepted range; It should be a buffer with size equal to or greater than the value of the 2nd argument times the 3rd argument}} \
-  // bugpath-note{{The 1st argument to 'fread' is out of the accepted range; It should be a buffer with size equal to or greater than the value of the 2nd argument times the 3rd argument}}
+  // report-warning{{The 1st argument to 'fread' is a buffer with size 4096 but should be a buffer with size equal to or greater than the value of the 2nd argument (that is 4) times the 3rd argument (that is 4096)}} \
+  // bugpath-warning{{The 1st argument to 'fread' is a buffer with size 4096 but should be a buffer with size equal to or greater than the value of the 2nd argument (that is 4) times the 3rd argument (that is 4096)}} \
+  // bugpath-note{{The 1st argument to 'fread' is a buffer with size 4096 but should be a buffer with size equal to or greater than the value of the 2nd argument (that is 4) times the 3rd argument (that is 4096)}}
 }
 
 int __two_constrained_args(int, int);
@@ -254,9 +254,9 @@
 void test_buf_size_concrete(void) {
   char buf[3];   // bugpath-note{{'buf' initialized here}}
   __buf_size_arg_constraint(buf, 4); // \
-  // report-warning{{The 1st argument to '__buf_size_arg_constraint' is out of the accepted range; It should be a buffer with size equal to or greater than the value of the 2nd argument}} \
-  // bugpath-warning{{The 1st argument to '__buf_size_arg_constraint' is out of the accepted range; It should be a buffer with size equal to or greater than the value of the 2nd argument}} \
-  // bugpath-note{{The 1st argument to '__buf_size_arg_constraint' is out of the accepted range; It should be a buffer with size equal to or greater than the value of the 2nd argument}}
+  // report-warning{{The 1st argument to '__buf_size_arg_constraint' is a buffer with size 3 but should be a buffer with size equal to or greater than the value of the 2nd argument (that is 4)}} \
+  // bugpath-warning{{The 1st argument to '__buf_size_arg_constraint' is a buffer with size 3 but should be a buffer with size equal to or greater than the value of the 2nd argument (that is 4)}} \
+  // bugpath-note{{The 1st argument to '__buf_size_arg_constraint' is a buffer with size 3 but should be a buffer with size equal to or greater than the value of the 2nd argument (that is 4)}}
 }
 void test_buf_size_symbolic(int s) {
   char buf[3];
@@ -281,9 +281,9 @@
 void test_buf_size_concrete_with_multiplication(void) {
   short buf[3]; // bugpath-note{{'buf' initialized here}}
   __buf_size_arg_constraint_mul(buf, 4, sizeof(short)); // \
-  // report-warning{{The 1st argument to '__buf_size_arg_constraint_mul' is out of the accepted range; It should be a buffer with size equal to or greater than the value of the 2nd argument times the 3rd argument}} \
-  // bugpath-warning{{The 1st argument to '__buf_size_arg_constraint_mul' is out of the accepted range; It should be a buffer with size equal to or greater than the value of the 2nd argument times the 3rd argument}} \
-  // bugpath-note{{The 1st argument to '__buf_size_arg_constraint_mul' is out of the accepted range; It should be a buffer with size equal to or greater than the value of the 2nd argument times the 3rd argument}}
+  // report-warning{{The 1st argument to '__buf_size_arg_constraint_mul' is a buffer with size 6 but should be a buffer with size equal to or greater than the value of the 2nd argument (that is 4) times the 3rd argument (that is 2)}} \
+  // bugpath-warning{{The 1st argument to '__buf_size_arg_constraint_mul' is a buffer with size 6 but should be a buffer with size equal to or greater than the value of the 2nd argument (that is 4) times the 3rd argument (that is 

[PATCH] D141627: [Clang][OpenMP] Fix the issue that list items in `has_device_addr` are still mapped to the target device

2023-04-27 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 added a comment.

ping


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141627/new/

https://reviews.llvm.org/D141627

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


[PATCH] D148802: [Sema] Lambdas are not part of immediate context for deduction

2023-04-27 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

In D148802#4283566 , @erichkeane 
wrote:

> My one concern is that this is going to expose our incorrect instantiation of 
> lambdas further and more painfully (see 
> https://github.com/llvm/llvm-project/issues/58872).  Else, I don't see 
> anything to be concerned about here.

That's true, but it seems that as a result of this patch, Clang will start 
rejecting some valid C++ programs when lambdas are used in unevaluated 
contexts, but will stop (incorrectly) accepting a class of programs that are 
invalid according to C++ standard.
I would err on the side of false negatives (correct program not compiled) 
instead of false positives (incorrect program complied). Otherwise, future 
changes that make Clang compliant can potentially require rewriting the code 
that relied on incorrect behavior.
It's still unfortunate that we don't accept valid programs, but at least 
existing code will not need to be changed after GH58872 
 is fixed.
My perspective is based on the need to support a large codebase, in which 
codebase-wide refactorings are expensive, other might have a different opinion 
here.




Comment at: clang/lib/Sema/SemaTemplateInstantiate.cpp:965
+case CodeSynthesisContext::LambdaExpressionSubstitution:
+  // FIXME: add a note for lambdas.
   break;

erichkeane wrote:
> ilya-biryukov wrote:
> > erichkeane wrote:
> > > Would really like this note here, it shouldn't be too difficult, right? 
> > Ah, sorry, I added a comment here that I forgot to submit. The question is: 
> > could it be that we want to skip this note?
> > 
> > I wanted to double-check if folks find this note useful.
> > On one hand, this probably creates some noise as there will always be other 
> > notes that point into the location of a corresponding substitution location 
> > that contains the lambda.
> > On the other hand, since the lambda is not an immediate context, this may 
> > give hints to users on why SFINAE does not apply.
> > 
> > If you feel like the note is useful, I will follow up with an 
> > implementation.
> I think it is useful for exactly the reason you mentioned: this is going to 
> be somewhat shocking behavior to most people, so explaining it better will be 
> helpful.
Makes sense. Added a corresponding note.



Comment at: clang/test/SemaCXX/warn-unused-lambda-capture.cpp:192
 void test_use_template() {
-  test_templated(); // expected-note{{in instantiation of function 
template specialization 'test_templated' requested here}}
+  test_templated(); // expected-note 13{{in instantiation of function 
template specialization 'test_templated' requested here}}
 }

shafik wrote:
> Why the 12 extra notes here, I feel I am missing something but not sure what. 
> I see the increase in notes in other cases as well.
I'm not entirely sure, but it seems there is some deduplication of notes that's 
happening when the stacks of code-synthesis-contexts for subsequent errors are 
the same.
However, this patch introduces a different code synthesis context for lambda 
substitutions, forcing the notes to be added.
In the new version of the patch, the added context actually shows up in the 
notes as well.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148802/new/

https://reviews.llvm.org/D148802

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


[PATCH] D148802: [Sema] Lambdas are not part of immediate context for deduction

2023-04-27 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 517550.
ilya-biryukov marked 5 inline comments as done.
ilya-biryukov added a comment.

- Add a note when substituting into a lambda
- Quote the standard and add explanation for the test


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148802/new/

https://reviews.llvm.org/D148802

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Frontend/FrontendActions.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.lambda/default-arguments.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.lambda/p11-1y.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.lambda/p23.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.lambda/p4.cpp
  clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
  clang/test/CXX/temp/temp.deduct/p9.cpp
  clang/test/CXX/temp/temp.param/p15-cxx0x.cpp
  clang/test/PCH/cxx1y-init-captures.cpp
  clang/test/SemaCXX/cxx1y-generic-lambdas-capturing.cpp
  clang/test/SemaCXX/cxx1y-generic-lambdas.cpp
  clang/test/SemaCXX/cxx1y-init-captures.cpp
  clang/test/SemaCXX/cxx1z-lambda-star-this.cpp
  clang/test/SemaCXX/cxx20-decomposition.cpp
  clang/test/SemaCXX/lambda-expressions.cpp
  clang/test/SemaCXX/lambda-pack-expansion.cpp
  clang/test/SemaCXX/lambda-unevaluated.cpp
  clang/test/SemaCXX/vartemplate-lambda.cpp
  clang/test/SemaCXX/warn-unused-lambda-capture.cpp
  clang/test/SemaTemplate/concepts.cpp
  clang/test/SemaTemplate/cxx1z-using-declaration.cpp
  clang/test/SemaTemplate/instantiate-exception-spec-cxx11.cpp
  clang/test/SemaTemplate/instantiate-local-class.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1024,11 +1024,7 @@
 
   Lambdas in unevaluated contexts
   https://wg21.link/p0315r4;>P0315R4
-  
-Partial
-  temp.deduct/9 is not implemented yet.
-
-  
+  Clang 17
 
 
 
Index: clang/test/SemaTemplate/instantiate-local-class.cpp
===
--- clang/test/SemaTemplate/instantiate-local-class.cpp
+++ clang/test/SemaTemplate/instantiate-local-class.cpp
@@ -473,7 +473,8 @@
   template  void bar() {
 auto lambda = [](T a = "") {}; // expected-error {{conversion function from 'const char[1]' to 'rdar23721638::A' invokes a deleted function}} \
// expected-note  {{in instantiation of default function argument expression for 'operator()' required here}} \
-   // expected-note  {{passing argument to parameter 'a' here}}
+   // expected-note  {{passing argument to parameter 'a' here}} \
+   // expected-note {{while substituting into a lambda}}
 lambda();
   }
   template void bar(); // expected-note {{in instantiation}}
@@ -496,6 +497,7 @@
   // expected-error@-1 {{cannot initialize a parameter of type 'int' with an rvalue of type 'std::nullptr_t'}}
   // expected-note@-2  {{in instantiation of default function argument expression for 'operator()' required here}}
   // expected-note@-3  {{passing argument to parameter 'x' here}}
+  // expected-note@-4  {{while substituting into a lambda}}
 
   void g() { f(); }
   // expected-note@-1 {{in instantiation of default function argument expression for 'f' required here}}
Index: clang/test/SemaTemplate/instantiate-exception-spec-cxx11.cpp
===
--- clang/test/SemaTemplate/instantiate-exception-spec-cxx11.cpp
+++ clang/test/SemaTemplate/instantiate-exception-spec-cxx11.cpp
@@ -160,7 +160,7 @@
 consume([]() noexcept(sizeof(T) == 4) {} ...);
   }
   template void j() {
-consume([](void (*p)() noexcept(B)) {
+consume([](void (*p)() noexcept(B)) { // expected-note {{substituting into a lambda}}
   void (*q)() noexcept = p; // expected-error {{not superset of source}}
 } ...);
   }
Index: clang/test/SemaTemplate/cxx1z-using-declaration.cpp
===
--- clang/test/SemaTemplate/cxx1z-using-declaration.cpp
+++ clang/test/SemaTemplate/cxx1z-using-declaration.cpp
@@ -157,7 +157,7 @@
 
 // Test partial substitution into class-scope pack.
 template auto lambda1() {
-  return [](auto x) {
+  return [](auto x) { // expected-note 1+{{substituting into a lambda}}
 struct A : T::template X... { // expected-note 1+{{instantiation of}}
   using T::template X::f ...;
   using typename T::template X::type ...;
Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -119,7 +119,7 @@
 []() -> C auto{ 

[clang] 843450b - [clang] Try to fix check-clang after f539b6ffc251

2023-04-27 Thread Nico Weber via cfe-commits

Author: Nico Weber
Date: 2023-04-27T10:12:39-04:00
New Revision: 843450b9a67c57f134913a2b90dcb5ba95114e0f

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

LOG: [clang] Try to fix check-clang after f539b6ffc251

Added: 


Modified: 
clang/test/SemaTemplate/concepts-inherited-ctor.cpp

Removed: 




diff  --git a/clang/test/SemaTemplate/concepts-inherited-ctor.cpp 
b/clang/test/SemaTemplate/concepts-inherited-ctor.cpp
index d6f3546b25fb..6ac5a1618784 100644
--- a/clang/test/SemaTemplate/concepts-inherited-ctor.cpp
+++ b/clang/test/SemaTemplate/concepts-inherited-ctor.cpp
@@ -89,4 +89,3 @@ namespace GH62362 {
 Test();
   }
 }
-}



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


[PATCH] D146557: [MLIR][OpenMP] Refactoring how map clause is processed

2023-04-27 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 517548.
TIFitis added a comment.

Rebased


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146557/new/

https://reviews.llvm.org/D146557

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
  mlir/test/Target/LLVMIR/omptarget-llvm.mlir

Index: mlir/test/Target/LLVMIR/omptarget-llvm.mlir
===
--- mlir/test/Target/LLVMIR/omptarget-llvm.mlir
+++ mlir/test/Target/LLVMIR/omptarget-llvm.mlir
@@ -12,32 +12,24 @@
 }
 
 // CHECK: @.offload_maptypes = private unnamed_addr constant [1 x i64] [i64 3]
+// CHECK: @.offload_sizes = private unnamed_addr constant [1 x i64] [i64 4]
 // CHECK-LABEL: define void @_QPopenmp_target_data() {
 // CHECK: %[[VAL_0:.*]] = alloca [1 x ptr], align 8
 // CHECK: %[[VAL_1:.*]] = alloca [1 x ptr], align 8
-// CHECK: %[[VAL_2:.*]] = alloca [1 x i64], align 8
-// CHECK: %[[VAL_3:.*]] = alloca i32, i64 1, align 4
-// CHECK: br label %[[VAL_4:.*]]
-// CHECK:   entry:; preds = %[[VAL_5:.*]]
-// CHECK: %[[VAL_6:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
-// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_6]], align 8
-// CHECK: %[[VAL_7:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
-// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_7]], align 8
-// CHECK: %[[VAL_8:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
-// CHECK: store i64 ptrtoint (ptr getelementptr (ptr, ptr null, i32 1) to i64), ptr %[[VAL_8]], align 4
+// CHECK: %[[VAL_2:.*]] = alloca i32, i64 1, align 4
+// CHECK: br label %[[VAL_3:.*]]
+// CHECK:   entry:; preds = %[[VAL_4:.*]]
+// CHECK: %[[VAL_5:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: store ptr %[[VAL_2]], ptr %[[VAL_5]], align 8
+// CHECK: %[[VAL_6:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: store ptr %[[VAL_2]], ptr %[[VAL_6]], align 8
+// CHECK: %[[VAL_7:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: %[[VAL_8:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: call void @__tgt_target_data_begin_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_7]], ptr %[[VAL_8]], ptr @.offload_sizes, ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: store i32 99, ptr %[[VAL_2]], align 4
 // CHECK: %[[VAL_9:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
 // CHECK: %[[VAL_10:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
-// CHECK: %[[VAL_11:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
-// CHECK: call void @__tgt_target_data_begin_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_9]], ptr %[[VAL_10]], ptr %[[VAL_11]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
-// CHECK: br label %[[VAL_12:.*]]
-// CHECK:   omp.data.region:  ; preds = %[[VAL_4]]
-// CHECK: store i32 99, ptr %[[VAL_3]], align 4
-// CHECK: br label %[[VAL_13:.*]]
-// CHECK:   omp.region.cont:  ; preds = %[[VAL_12]]
-// CHECK: %[[VAL_14:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
-// CHECK: %[[VAL_15:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
-// CHECK: %[[VAL_16:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
-// CHECK: call void @__tgt_target_data_end_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_14]], ptr %[[VAL_15]], ptr %[[VAL_16]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: call void @__tgt_target_data_end_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_9]], ptr %[[VAL_10]], ptr @.offload_sizes, ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
 // CHECK: ret void
 
 // -
@@ -56,38 +48,30 @@
 }
 
 // CHECK: @.offload_maptypes = private unnamed_addr constant [1 x i64] [i64 2]
+// CHECK: @.offload_sizes = private unnamed_addr constant [1 x i64] [i64 4096]
 // CHECK-LABEL: define void @_QPopenmp_target_data_region
 // CHECK: (ptr %[[ARG_0:.*]]) {
 // CHECK: %[[VAL_0:.*]] = alloca [1 x ptr], align 8
 // CHECK: %[[VAL_1:.*]] = alloca [1 x ptr], align 8
-// CHECK: %[[VAL_2:.*]] = alloca [1 x i64], align 8
-// CHECK: br label 

[PATCH] D148601: [Clang] Handle Error message to output proper Prefix

2023-04-27 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman requested changes to this revision.
aaron.ballman added a comment.
This revision now requires changes to proceed.

Thank you for working on this! These changes should come with test coverage (we 
have a handful of verifier tests in `clang/test/Frontend` -- you can add a new 
test file there), but I don't think a release note is required because this is 
a fix for internal functionality. The test should cover the simple case of 
`-verify=something` as well as a more complex test with `-verify=something, 
something_else`.




Comment at: clang/include/clang/Basic/DiagnosticFrontendKinds.td:175-176
 def err_verify_invalid_no_diags : Error<
 "%select{expected|'expected-no-diagnostics'}0 directive cannot follow "
 "%select{'expected-no-diagnostics' directive|other expected directives}0">;
 def err_verify_no_directives : Error<

Should we be handling this situation at the same time, as it's effectively the 
same concern? e.g., https://godbolt.org/z/4Mn1rW9oa


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148601/new/

https://reviews.llvm.org/D148601

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


[PATCH] D146557: [MLIR][OpenMP] Refactoring how map clause is processed

2023-04-27 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis added a comment.

In D146557#4295550 , 
@kiranchandramohan wrote:

> In D146557#4292223 , @TIFitis wrote:
>
>> Cleaned up how IsBegin argument is passed for createTargetData call.
>
> Please submit this directly as an NFC patch.

I have merged it separately.

> We should always work towards simple patches that are easy to review. 
> Sometimes a big patch is required to give the full context. But it can then 
> be broken up into small patches for faster review. I have created D149153 
>  for the `inlineConvertOmpRegions` change.

Thanks for creating your patch. I'll try to make my patches shorter in the 
future.

Once D149153  is merged I'll rebase this 
patch.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146557/new/

https://reviews.llvm.org/D146557

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


[PATCH] D149272: [clang] Call printName to get name of Decl

2023-04-27 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/AST/DeclarationName.cpp:119-125
   if (const RecordType *ClassRec = ClassType->getAs()) {
-OS << *ClassRec->getDecl();
+ClassRec->getDecl()->printName(OS, Policy);
 return;
   }
   if (Policy.SuppressTemplateArgsInCXXConstructors) {
 if (auto *InjTy = ClassType->getAs()) {
+  InjTy->getDecl()->printName(OS, Policy);

dankm wrote:
> aaron.ballman wrote:
> > This isn't the right way to go about this -- the diagnostic engine knows 
> > how to print a `NamedDecl` when given one, and that's what should be fixed. 
> > (We pass in a `NamedDecl` all over the place -- it's preferred to passing 
> > in a string.)
> > 
> > https://github.com/llvm/llvm-project/blob/b893368fd4fdf40b7778df8d0b17312def1a8156/clang/lib/AST/ASTDiagnostic.cpp#L460
> >  is one place where that happens, and 
> > https://github.com/llvm/llvm-project/blob/b893368fd4fdf40b7778df8d0b17312def1a8156/clang/lib/Basic/Diagnostic.cpp#L1060
> >  is another, so I'd start investigating from there.
> Maybe I could have been more clear in my description of the problem; it's not 
> diagnostics. It's naming in the output. With -ffile-prefix-map in use and 
> without this change I see this:
> 
> ```
> % strings lib/x86_64-dankm-freebsd13.2/libc++.so.1.0|grep barrier.cpp
> std::__1::__barrier_algorithm_base::__state_t::(unnamed struct at 
> /home/dan/llvm/llvm-wip/libcxx/src/barrier.cpp:24:9)
> ```
> 
> when I expect (and get with this change):
> 
> ```
> % strings lib/x86_64-dankm-freebsd13.2/libc++.so.1.0|grep barrier.cpp
> std::__1::__barrier_algorithm_base::__state_t::(unnamed struct at 
> /llvm-root/libcxx/src/barrier.cpp:24:9)
> ```
> 
> It looks like every other call in the DeclarationName::print function 
> preserves the policy, these weren't. As far as I can tell, this is the only 
> place this is used.
Ah, thank you for the explanation, now I see what's going on.



Comment at: clang/test/CodeGen/debug-prefix-map.cpp:1
+// RUN: %clang++ -g -fdebug-prefix-map=%p=./UNLIKELY_PATH/empty -S -c %s 
-emit-llvm -o - | FileCheck %s --check-prefix=CHECK-REL
+

I'm taking a guess at correcting the RUN line here, but more tweaks may be 
needed. Basically, `%clang++` isn't a thing, so this test fails. Most of our 
tests should be testing `%clang_cc1` to test the frontend invocation, but some 
of the debug prefix map tests use `%clang` to test the driver functionality. I 
don't think there's a need to test the driver here, so I went with 
`%clang_cc1`. I'm not 100% certain whether `-debug-info-kind=` is necessary or 
not, but the other tests seem to be using that, which may be worth paying 
attention to.

Finally, there's no need to have a custom check prefix for `FileCheck`, the 
builtin `CHECK` prefix suffices.



Comment at: clang/test/CodeGen/debug-prefix-map.cpp:11
+
+// CHECK-REL: !DISubprogram(name: "(unnamed struct at 
./UNLIKELY_PATH/empty{{/|}}{{.*}}",




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149272/new/

https://reviews.llvm.org/D149272

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


[PATCH] D149210: [IR] Change shufflevector undef mask to poison

2023-04-27 Thread Manuel Brito via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8b56da5e9f3b: [IR] Change shufflevector undef mask to poison 
(authored by ManuelJBrito).

Changed prior to commit:
  https://reviews.llvm.org/D149210?vs=517150=517542#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149210/new/

https://reviews.llvm.org/D149210

Files:
  clang/test/CodeGen/PowerPC/builtins-ppc-p10vector.c
  clang/test/CodeGen/PowerPC/builtins-ppc-p9vector.c
  clang/test/CodeGen/builtins-nondeterministic-value.c
  clang/test/CodeGen/builtinshufflevector2.c
  clang/test/CodeGen/ext-vector.c
  clang/test/CodeGenOpenCL/as_type.cl
  clang/test/CodeGenOpenCL/partial_initializer.cl
  clang/test/CodeGenOpenCL/preserve_vec3.cl
  clang/test/CodeGenOpenCL/vector_literals.cl
  clang/test/CodeGenOpenCL/vector_shufflevector.cl
  llvm/lib/IR/AsmWriter.cpp
  llvm/test/Analysis/CostModel/RISCV/shuffle-extract_subvector.ll
  llvm/test/Analysis/CostModel/RISCV/shuffle-insert_subvector.ll
  llvm/test/Analysis/CostModel/X86/reduction.ll
  llvm/test/Analysis/CostModel/X86/shuffle-extract_subvector-codesize.ll
  llvm/test/Analysis/CostModel/X86/shuffle-extract_subvector-latency.ll
  llvm/test/Analysis/CostModel/X86/shuffle-extract_subvector-sizelatency.ll
  llvm/test/Analysis/CostModel/X86/shuffle-extract_subvector.ll
  llvm/test/Analysis/CostModel/X86/shuffle-insert_subvector-codesize.ll
  llvm/test/Analysis/CostModel/X86/shuffle-insert_subvector-latency.ll
  llvm/test/Analysis/CostModel/X86/shuffle-insert_subvector-sizelatency.ll
  llvm/test/Analysis/CostModel/X86/shuffle-insert_subvector.ll
  llvm/test/Analysis/CostModel/X86/shuffle-single-src-codesize.ll
  llvm/test/Analysis/CostModel/X86/shuffle-single-src-latency.ll
  llvm/test/Analysis/CostModel/X86/shuffle-single-src-sizelatency.ll
  llvm/test/Analysis/CostModel/X86/shuffle-single-src.ll
  llvm/test/CodeGen/AMDGPU/amdgpu-codegenprepare-break-large-phis-heuristics.ll
  llvm/test/CodeGen/AMDGPU/rewrite-out-arguments.ll
  llvm/test/CodeGen/Generic/expand-experimental-reductions.ll
  llvm/test/CodeGen/PowerPC/arg_promotion.ll
  llvm/test/Instrumentation/MemorySanitizer/avx-intrinsics-x86.ll
  llvm/test/Transforms/Attributor/nofpclass.ll
  llvm/test/Transforms/CodeGenPrepare/X86/x86-shuffle-sink-inseltpoison.ll
  llvm/test/Transforms/CodeGenPrepare/X86/x86-shuffle-sink.ll
  llvm/test/Transforms/DeadStoreElimination/masked-dead-store-inseltpoison.ll
  llvm/test/Transforms/DeadStoreElimination/masked-dead-store.ll
  llvm/test/Transforms/InstCombine/AArch64/demandelts.ll
  
llvm/test/Transforms/InstCombine/AMDGPU/amdgcn-demanded-vector-elts-inseltpoison.ll
  llvm/test/Transforms/InstCombine/AMDGPU/amdgcn-demanded-vector-elts.ll
  llvm/test/Transforms/InstCombine/X86/x86-addsub-inseltpoison.ll
  llvm/test/Transforms/InstCombine/X86/x86-addsub.ll
  llvm/test/Transforms/InstCombine/X86/x86-avx2-inseltpoison.ll
  llvm/test/Transforms/InstCombine/X86/x86-avx2.ll
  llvm/test/Transforms/InstCombine/X86/x86-avx512-inseltpoison.ll
  llvm/test/Transforms/InstCombine/X86/x86-avx512.ll
  llvm/test/Transforms/InstCombine/X86/x86-muldq-inseltpoison.ll
  llvm/test/Transforms/InstCombine/X86/x86-muldq.ll
  llvm/test/Transforms/InstCombine/X86/x86-pack-inseltpoison.ll
  llvm/test/Transforms/InstCombine/X86/x86-pack.ll
  llvm/test/Transforms/InstCombine/X86/x86-pshufb-inseltpoison.ll
  llvm/test/Transforms/InstCombine/X86/x86-pshufb.ll
  llvm/test/Transforms/InstCombine/X86/x86-sse4a-inseltpoison.ll
  llvm/test/Transforms/InstCombine/X86/x86-sse4a.ll
  llvm/test/Transforms/InstCombine/X86/x86-vpermil-inseltpoison.ll
  llvm/test/Transforms/InstCombine/X86/x86-vpermil.ll
  llvm/test/Transforms/InstCombine/bitreverse.ll
  llvm/test/Transforms/InstCombine/broadcast-inseltpoison.ll
  llvm/test/Transforms/InstCombine/broadcast.ll
  llvm/test/Transforms/InstCombine/bswap-inseltpoison.ll
  llvm/test/Transforms/InstCombine/bswap.ll
  llvm/test/Transforms/InstCombine/canonicalize-vector-insert.ll
  llvm/test/Transforms/InstCombine/extractelement-inseltpoison.ll
  llvm/test/Transforms/InstCombine/extractelement.ll
  llvm/test/Transforms/InstCombine/insert-const-shuf-inseltpoison.ll
  llvm/test/Transforms/InstCombine/insert-const-shuf.ll
  llvm/test/Transforms/InstCombine/insert-extract-shuffle-inseltpoison.ll
  llvm/test/Transforms/InstCombine/insert-extract-shuffle.ll
  llvm/test/Transforms/InstCombine/masked_intrinsics-inseltpoison.ll
  llvm/test/Transforms/InstCombine/masked_intrinsics.ll
  llvm/test/Transforms/InstCombine/minmax-intrinsics.ll
  llvm/test/Transforms/InstCombine/nsw-inseltpoison.ll
  llvm/test/Transforms/InstCombine/nsw.ll
  llvm/test/Transforms/InstCombine/reduction-shufflevector.ll
  llvm/test/Transforms/InstCombine/select-extractelement-inseltpoison.ll
  llvm/test/Transforms/InstCombine/select-extractelement.ll
  llvm/test/Transforms/InstCombine/select-select.ll
  

[PATCH] D149264: GH62362: Handle constraints on "Using" inherited constructors

2023-04-27 Thread Erich Keane via Phabricator via cfe-commits
erichkeane abandoned this revision.
erichkeane added a comment.

Fixed by Richard!  Tests and release note added in f539bffc


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149264/new/

https://reviews.llvm.org/D149264

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


[clang] f539b6f - [NFC] Add tests from my fix for GH62362.

2023-04-27 Thread Erich Keane via cfe-commits

Author: Erich Keane
Date: 2023-04-27T06:33:34-07:00
New Revision: f539b6ffc25144703498176558035c499825dc48

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

LOG: [NFC] Add tests from my fix for GH62362.

This ended up being fixed separately by @rsmith in 1e43349e3 in a
better/correct way. This patch adds the tests from the original, as
though they are reasonably covered in his patch, explicit versions seem
to have value here.

Additionally, this adds a release note for 1e43349e3.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/test/SemaTemplate/concepts-inherited-ctor.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f473f97f6c74..26fdffe920e9 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -327,6 +327,10 @@ Bug Fixes in This Version
   (`#62122 `_)
 - Fix crash when handling undefined template partial specialization
   (`#61356 `_)
+- Fix a crash caused by incorrectly evaluating constraints on an inheriting
+  constructor declaration.
+  (`#62361 `_)
+  (`#62362 `_)
 
 Bug Fixes to Compiler Builtins
 ^^

diff  --git a/clang/test/SemaTemplate/concepts-inherited-ctor.cpp 
b/clang/test/SemaTemplate/concepts-inherited-ctor.cpp
index f50a6aebeeab..d6f3546b25fb 100644
--- a/clang/test/SemaTemplate/concepts-inherited-ctor.cpp
+++ b/clang/test/SemaTemplate/concepts-inherited-ctor.cpp
@@ -68,3 +68,25 @@ namespace no_early_substitution {
 C();
   }
 }
+
+namespace GH62362 {
+  template
+concept C = true;
+  template  struct Test {
+Test()
+  requires(C);
+  };
+  struct Bar : public Test {
+using Test::Test;
+  };
+  template <>
+struct Test : public Test {
+  using Test::Test;
+};
+
+  void foo() {
+Bar();
+Test();
+  }
+}
+}



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


[PATCH] D149264: GH62362: Handle constraints on "Using" inherited constructors

2023-04-27 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

Confirmed this is all fixed by your patch.  Thanks!




Comment at: clang/lib/Sema/SemaTemplateInstantiate.cpp:138-144
+bool SkipForSpecialization,
+bool ForConstraintInstantiation) {
   if (!ClassTemplSpec->isClassScopeExplicitSpecialization()) {
 // We're done when we hit an explicit specialization.
 if (ClassTemplSpec->getSpecializationKind() == TSK_ExplicitSpecialization 
&&
-!isa(ClassTemplSpec))
+!isa(ClassTemplSpec) &&
+!ForConstraintInstantiation)

rsmith wrote:
> rsmith wrote:
> > It seems to me that a namespace-scope explicit specialization shouldn't 
> > pick up template arguments, even during constraint checking:
> > 
> > ```
> > template struct A {};
> > template<> struct A {
> >   template void f() requires U::value;
> > };
> > ```
> > Constraint checking for `A::f` should produce a single level of 
> > template arguments, ``, not two layers `, `, because `U` in 
> > `U::value` is a depth-0 index-0 parameter.
> Complete testcase:
> ```
> struct X {}; struct Y { static constexpr bool value = true; };
> template struct A {};
> template<> struct A {  
>   template void f() requires U::value;
> };   
> void g(A a) { a.f(); }
> ```
Ah! Thanks for the reproducer.  I was having a really hard time determining a 
case where this would break, everything I came up with was blocked by 
https://reviews.llvm.org/D146178

The difficulty was that the parent of the inherited constructor was an inline 
definition of the explicit specialization, so it DID have depth, but it wasn't 
clear how to differentiate the two. I think your patch as listed fixes all the 
issues I was trying to fix as you said, so I'll abandon this, though I'll 
include the tests as an NFC/RAC patch for completeness.




Comment at: clang/lib/Sema/SemaTemplateInstantiate.cpp:217-219
+  if (Ctor->isImplicit() && Ctor->isInheritingConstructor() &&
+  Ctor->getInheritedConstructor().getConstructor())
+Ctor = Ctor->getInheritedConstructor().getConstructor();

rsmith wrote:
> These checks can be simplified.
Ah, thanks!  I must have been looking at the wrong thing, I wasn't convinced 
that the `getInheritedConstructor` call was always legal, but looking again, I 
see that should have been obvious.  


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149264/new/

https://reviews.llvm.org/D149264

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


[PATCH] D149276: [Clang] Fix parsing of `(auto(x))`.

2023-04-27 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 517536.
cor3ntin added a comment.

Fix tests


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149276/new/

https://reviews.llvm.org/D149276

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Parse/Parser.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseTentative.cpp
  clang/lib/Parse/Parser.cpp
  clang/test/Parser/cxx1z-decomposition.cpp
  clang/test/Parser/cxx2b-auto-x.cpp

Index: clang/test/Parser/cxx2b-auto-x.cpp
===
--- clang/test/Parser/cxx2b-auto-x.cpp
+++ clang/test/Parser/cxx2b-auto-x.cpp
@@ -18,7 +18,37 @@
 
 using T = looks_like_declaration *;
 void f() { T()->n = 1; }
-// FIXME: They should be deemed expressions without breaking function pointer
-//parameter declarations with trailing return types.
-// void g() { auto()->n = 0; }
-// void h() { auto{}->n = 0; }
+void g() { auto()->n = 0; } // cxx2b-warning {{before C++2b}} \
+  // cxx20-error {{declaration of variable 'a' with deduced type 'auto (&)' requires an initializer}} \
+  // cxx20-error {{expected ';' at end of declaration}}
+void h() { auto{}->n = 0; } // cxx2b-warning {{before C++2b}} \
+  // cxx20-error {{expected unqualified-id}} \
+  // cxx20-error {{expected expression}}
+
+void e(auto (*p)(int y) -> decltype(y)) {}
+
+struct M;
+struct S{
+S operator()();
+S* operator->();
+int N;
+int M;
+} s; // expected-note {{here}}
+
+void test() {
+auto(s)()->N; // cxx2b-warning {{expression result unused}} \
+  // cxx2b-warning {{before C++2b}} \
+  // cxx20-error {{unknown type name 'N'}}
+auto(s)()->M; // expected-error {{redefinition of 's' as different kind of symbol}}
+}
+
+void test_paren() {
+int a = (auto(0)); // cxx2b-warning {{before C++2b}} \
+   // cxx20-error {{expected expression}} \
+   // cxx20-error {{expected ')'}} \
+   // cxx20-note  {{to match this '('}}
+int b = (auto{0}); // cxx2b-warning {{before C++2b}} \
+   // cxx20-error {{expected expression}} \
+   // cxx20-error {{expected ')'}} \
+   // cxx20-note  {{to match this '('}}
+}
Index: clang/test/Parser/cxx1z-decomposition.cpp
===
--- clang/test/Parser/cxx1z-decomposition.cpp
+++ clang/test/Parser/cxx1z-decomposition.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -std=c++17 %s -verify -fcxx-exceptions
+// RUN: %clang_cc1 -std=c++17 %s -verify=expected,cxx17 -fcxx-exceptions
+// RUN: %clang_cc1 -std=c++2b %s -verify=expected,cxx2b -fcxx-exceptions
 // RUN: not %clang_cc1 -std=c++17 %s -emit-llvm-only -fcxx-exceptions
 
 struct S { int a, b, c; };
@@ -30,7 +31,7 @@
 namespace OtherDecl {
   // A parameter-declaration is not a simple-declaration.
   // This parses as an array declaration.
-  void f(auto [a, b, c]); // expected-error {{'auto' not allowed in function prototype}} expected-error {{'a'}}
+  void f(auto [a, b, c]); // cxx17-error {{'auto' not allowed in function prototype}} expected-error {{'a'}}
 
   void g() {
 // A condition is allowed as a Clang extension.
@@ -57,7 +58,7 @@
 namespace GoodSpecifiers {
   void f() {
 int n[1];
-const volatile auto &[a] = n;
+const volatile auto &[a] = n; // cxx2b-warning {{volatile qualifier in structured binding declaration is deprecated}}
   }
 }
 
@@ -67,8 +68,8 @@
   struct S { int n; } s;
   void f() {
 // storage-class-specifiers
-static auto &[a] = n; // expected-warning {{declared 'static' is a C++20 extension}}
-thread_local auto &[b] = n; // expected-warning {{declared 'thread_local' is a C++20 extension}}
+static auto &[a] = n; // cxx17-warning {{declared 'static' is a C++20 extension}}
+thread_local auto &[b] = n; // cxx17-warning {{declared 'thread_local' is a C++20 extension}}
 extern auto &[c] = n; // expected-error {{cannot be declared 'extern'}} expected-error {{declaration of block scope identifier with linkage cannot have an initializer}}
 struct S {
   mutable auto &[d] = n; // expected-error {{not permitted in this context}}
@@ -85,16 +86,19 @@
   }
 
   static constexpr inline thread_local auto &[j1] = n; // expected-error {{cannot be declared with 'constexpr inline' specifiers}}
-  static thread_local auto &[j2] = n; // expected-warning {{declared with 'static thread_local' specifiers is a C++20 extension}}
+  static thread_local auto &[j2] = n; // cxx17-warning {{declared with 'static thread_local' specifiers is a C++20 extension}}
 
   inline auto &[k] = n; // expected-error {{cannot be declared 'inline'}}
 
   const int K = 5;
+  auto ([c]) = s; // expected-error {{decomposition declaration cannot be declared with parentheses}}
  

[PATCH] D139010: [clang][WebAssembly] Implement support for table types and builtins

2023-04-27 Thread Paulo Matos via Phabricator via cfe-commits
pmatos marked an inline comment as done.
pmatos added a comment.

I think we are almost there. @aaron.ballman what do you think?




Comment at: clang/test/Sema/wasm-refs-and-tables.c:81
+
+  funcref_t func = __builtin_wasm_ref_null_func(0); // expected-error {{too 
many arguments to function call, expected 0, have 1}}
+

aaron.ballman wrote:
> Shouldn't this be in builtins-wasm.c instead?
Moved.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139010/new/

https://reviews.llvm.org/D139010

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


[PATCH] D139010: [clang][WebAssembly] Implement support for table types and builtins

2023-04-27 Thread Paulo Matos via Phabricator via cfe-commits
pmatos updated this revision to Diff 517535.
pmatos added a comment.

Add documentation for table builtins.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139010/new/

https://reviews.llvm.org/D139010

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Type.cpp
  clang/lib/Basic/Targets/WebAssembly.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExceptionSpec.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGen/WebAssembly/builtins-table.c
  clang/test/Sema/builtins-wasm.c
  clang/test/Sema/wasm-refs-and-table-ped.c
  clang/test/Sema/wasm-refs-and-tables.c
  clang/test/Sema/wasm-refs.c
  clang/test/SemaCXX/wasm-refs-and-tables.cpp
  clang/test/SemaCXX/wasm-refs.cpp
  llvm/include/llvm/CodeGen/WasmAddressSpaces.h
  llvm/include/llvm/IR/Type.h
  llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.cpp
  llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
  llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyLowerRefTypesIntPtrConv.cpp

Index: llvm/lib/Target/WebAssembly/WebAssemblyLowerRefTypesIntPtrConv.cpp
===
--- llvm/lib/Target/WebAssembly/WebAssemblyLowerRefTypesIntPtrConv.cpp
+++ llvm/lib/Target/WebAssembly/WebAssemblyLowerRefTypesIntPtrConv.cpp
@@ -62,8 +62,9 @@
   for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) {
 PtrToIntInst *PTI = dyn_cast(&*I);
 IntToPtrInst *ITP = dyn_cast(&*I);
-if (!(PTI && WebAssembly::isRefType(PTI->getPointerOperand()->getType())) &&
-!(ITP && WebAssembly::isRefType(ITP->getDestTy(
+if (!(PTI &&
+  PTI->getPointerOperand()->getType()->isWebAssemblyReferenceType()) &&
+!(ITP && ITP->getDestTy()->isWebAssemblyReferenceType()))
   continue;
 
 UndefValue *U = UndefValue::get(I->getType());
Index: llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
===
--- llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
+++ llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
@@ -1203,7 +1203,7 @@
   // Lastly, if this is a call to a funcref we need to add an instruction
   // table.set to the chain and transform the call.
   if (CLI.CB &&
-  WebAssembly::isFuncrefType(CLI.CB->getCalledOperand()->getType())) {
+  CLI.CB->getCalledOperand()->getType()->isWebAssemblyFuncrefType()) {
 // In the absence of function references proposal where a funcref call is
 // lowered to call_ref, using reference types we generate a table.set to set
 // the funcref to a special table used solely for this purpose, followed by
Index: llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
===
--- llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
+++ llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
@@ -27,43 +27,6 @@
 
 namespace WebAssembly {
 
-enum WasmAddressSpace : unsigned {
-  // Default address space, for pointers to linear memory (stack, heap, data).
-  WASM_ADDRESS_SPACE_DEFAULT = 0,
-  // A non-integral address space for pointers to named objects outside of
-  // linear memory: WebAssembly globals or WebAssembly locals.  Loads and stores
-  // to these pointers are lowered to global.get / global.set or local.get /
-  // local.set, as appropriate.
-  WASM_ADDRESS_SPACE_VAR = 1,
-  // A non-integral address space for externref values
-  WASM_ADDRESS_SPACE_EXTERNREF = 10,
-  // A non-integral address space for funcref values
-  WASM_ADDRESS_SPACE_FUNCREF = 20,
-};
-
-inline bool isDefaultAddressSpace(unsigned AS) {
-  return AS == WASM_ADDRESS_SPACE_DEFAULT;
-}
-inline bool isWasmVarAddressSpace(unsigned AS) {
-  return AS == WASM_ADDRESS_SPACE_VAR;
-}
-inline bool isValidAddressSpace(unsigned AS) {
-  return isDefaultAddressSpace(AS) || isWasmVarAddressSpace(AS);
-}
-inline bool isFuncrefType(const Type *Ty) {
-  return isa(Ty) &&
- Ty->getPointerAddressSpace() ==
- WasmAddressSpace::WASM_ADDRESS_SPACE_FUNCREF;
-}
-inline bool isExternrefType(const Type *Ty) {
-  return isa(Ty) &&
- Ty->getPointerAddressSpace() ==
- WasmAddressSpace::WASM_ADDRESS_SPACE_EXTERNREF;
-}
-inline bool isRefType(const Type *Ty) {
-  return isFuncrefType(Ty) || isExternrefType(Ty);
-}
-
 // Convert StringRef to ValType / HealType / BlockType
 
 MVT parseMVT(StringRef Type);
Index: 

[clang-tools-extra] 6cfcf02 - [clangd] Fix the include-cleaner-batch-fix.test failure on some

2023-04-27 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2023-04-27T14:59:37+02:00
New Revision: 6cfcf0242f3260a3a90bac68e9f271548caa8372

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

LOG: [clangd] Fix the include-cleaner-batch-fix.test failure on some
platforms

It seems that on some platforms, the spelling include doesn't work. Make
the test less strict on it.

Added: 


Modified: 
clang-tools-extra/clangd/test/include-cleaner-batch-fix.test

Removed: 




diff  --git a/clang-tools-extra/clangd/test/include-cleaner-batch-fix.test 
b/clang-tools-extra/clangd/test/include-cleaner-batch-fix.test
index b07da2a9b4df8..4b2208ba3e146 100644
--- a/clang-tools-extra/clangd/test/include-cleaner-batch-fix.test
+++ b/clang-tools-extra/clangd/test/include-cleaner-batch-fix.test
@@ -123,7 +123,7 @@
 # CHECK-NEXT:{
 # CHECK-NEXT:  "edits": [
 # CHECK-NEXT:{
-# CHECK-NEXT:  "newText": "#include \n",
+# CHECK-NEXT:  "newText": "#include {{.*}}foo.h{{.*}}",
 # CHECK-NEXT:  "range": {
 # CHECK-NEXT:"end": {
 # CHECK-NEXT:  "character": 0,
@@ -145,7 +145,7 @@
 # CHECK-NEXT:}
 # CHECK-NEXT:  ],
 # CHECK-NEXT:  "command": "clangd.applyFix",
-# CHECK-NEXT:  "title": "Apply fix: #include "
+# CHECK-NEXT:  "title": "Apply fix: #include {{.*}}foo.h{{.*}}"
 # CHECK-NEXT:},
 # CHECK-NEXT:{
 # CHECK-NEXT:  "arguments": [
@@ -165,7 +165,7 @@
 # CHECK-NEXT:  "edits": [
 # CHECK-NEXT:{
 # CHECK-NEXT:  "annotationId": "AddAllMissingIncludes0",
-# CHECK-NEXT:  "newText": "#include \n",
+# CHECK-NEXT:  "newText": "#include {{.*}}bar.h{{.*}}",
 # CHECK-NEXT:  "range": {
 # CHECK-NEXT:"end": {
 # CHECK-NEXT:  "character": 0,
@@ -179,7 +179,7 @@
 # CHECK-NEXT:},
 # CHECK-NEXT:{
 # CHECK-NEXT:  "annotationId": "AddAllMissingIncludes1",
-# CHECK-NEXT:  "newText": "#include \n",
+# CHECK-NEXT:  "newText": "#include {{.*}}foo.h{{.*}}",
 # CHECK-NEXT:  "range": {
 # CHECK-NEXT:"end": {
 # CHECK-NEXT:  "character": 0,
@@ -257,7 +257,7 @@
 # CHECK-NEXT:},
 # CHECK-NEXT:{
 # CHECK-NEXT:  "annotationId": "AddAllMissingIncludes0",
-# CHECK-NEXT:  "newText": "#include \n",
+# CHECK-NEXT:  "newText": "#include {{.*}}bar.h{{.*}}",
 # CHECK-NEXT:  "range": {
 # CHECK-NEXT:"end": {
 # CHECK-NEXT:  "character": 0,
@@ -271,7 +271,7 @@
 # CHECK-NEXT:},
 # CHECK-NEXT:{
 # CHECK-NEXT:  "annotationId": "AddAllMissingIncludes1",
-# CHECK-NEXT:  "newText": "#include \n",
+# CHECK-NEXT:  "newText": "#include {{.*}}foo.h{{.*}}",
 # CHECK-NEXT:  "range": {
 # CHECK-NEXT:"end": {
 # CHECK-NEXT:  "character": 0,
@@ -442,7 +442,7 @@
 # CHECK-NEXT:},
 # CHECK-NEXT:{
 # CHECK-NEXT:  "annotationId": "AddAllMissingIncludes0",
-# CHECK-NEXT:  "newText": "#include \n",
+# CHECK-NEXT:  "newText": "#include {{.*}}bar.h{{.*}}",
 # CHECK-NEXT:  "range": {
 # CHECK-NEXT:"end": {
 # CHECK-NEXT:  "character": 0,
@@ -456,7 +456,7 @@
 # CHECK-NEXT:},
 # CHECK-NEXT:{
 # CHECK-NEXT:  "annotationId": "AddAllMissingIncludes1",
-# CHECK-NEXT:  "newText": "#include \n",
+# CHECK-NEXT:  "newText": "#include {{.*}}foo.h{{.*}}",
 # CHECK-NEXT:  "range": {
 # CHECK-NEXT:"end": {
 # CHECK-NEXT:  "character": 0,



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


[PATCH] D148924: [clang] Show error if defaulted comparions operator function is volatile or has ref-qualifier &&.

2023-04-27 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Basically looking good to me now, but the changes need a release note and I 
does this mean we can change cxx_status.html to claim full support for P2002R1 
now or is there more left to be done for that? (If there's more left to do, 
adding those details to the cxx_status page would be appropriate.)




Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:9436
+def err_ref_qualifier_comparison_operator : Error<
+  "ref-qualifier '&&' is not allowed on defaulted comparison operators">;
 

ilya-biryukov wrote:
> NIT: for consistency with the wording of `err_ref_qualifier_constructor`
Still need to drop the `s` from `operators`



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:8593-8601
+const FunctionProtoType *FnType = 
FD->getType()->castAs();
+if (FnType->isVolatile()) {
+  Diag(FD->getLocation(), diag::err_volatile_comparison_operator);
+  return true;
+}
+if (FnType->getRefQualifier() == RQ_RValue) {
+  Diag(FD->getLocation(), diag::err_ref_qualifier_comparison_operator);

massberg wrote:
> massberg wrote:
> > aaron.ballman wrote:
> > > aaron.ballman wrote:
> > > > ilya-biryukov wrote:
> > > > > NIT: this version is simpler and more aligned with the code below.
> > > > > Also, could you move the `volatile` handling after the check for 
> > > > > `const`?
> > > > > 
> > > > > 
> > > > > Additionally, we seem to recover in case of `const` by adding it to 
> > > > > the type and suggesting a fix-it to add it in the code.
> > > > > Could we do the same for `volatile` and `ref-qualifier`, i.e. suggest 
> > > > > a fix-it to remove the `ref-qualifier` and `volatile` and change the 
> > > > > corresponding type to make AST pretend they were never there?
> > > > 
> > > Note, you can shorten it further with:
> > > ```
> > > return Diag(...);
> > > ```
> > > because that will return true for you.
> > Thanks! Which the change suggested by Ilya this has become obsolete.
> Thanks, this is much simpler!
> 
> I have moved the code and added a recovery. However, adding a fix-it is much 
> more complex as there is no simple way to get location to remove the 
> keywords. Thus I decided to not offering a fix-it in this patch.
Yeah, it seems we don't track the ref qualifier location on any of the 
`CXXMethodDecl`, `FunctionProtoType`, or `FunctionProtoTypeLoc` classes. A 
future refactoring can consider adding locations for those to 
`FunctionProtoTypeLoc`, but needs to be able to handle multiple qualifiers 
(e.g., `void func() const &;` should track both the `const` and the `&` 
separately).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148924/new/

https://reviews.llvm.org/D148924

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


[PATCH] D134821: [flang][driver] Allow main program to be in an archive

2023-04-27 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski accepted this revision.
awarzynski added a comment.

In D134821#4301701 , @sunshaoce wrote:

> Any further suggestions?

I am happy for you to land this, thanks! LGTM


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D134821/new/

https://reviews.llvm.org/D134821

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


[PATCH] D149206: [clang][driver] Enable MisExpect diagnostics flag outside of CC1

2023-04-27 Thread Hans Wennborg via Phabricator via cfe-commits
hans accepted this revision.
hans added a comment.

lgtm


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149206/new/

https://reviews.llvm.org/D149206

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


[PATCH] D149276: [Clang] Fix parsing of `(auto(x))`.

2023-04-27 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Parse/ParseTentative.cpp:1067
+bool mayHaveDirectInit,
+bool mayHaveTrailingReturnType) {
   // declarator:

tbaeder wrote:
> Not part of this commit I guess, but //four// bool parameters is truly 
> horrific :/
Yeah, a refactoring here would not be amiss (but outside of this patch, I 
think).



Comment at: clang/lib/Parse/ParseTentative.cpp:1416-1417
+  case tok::kw_auto: {
+if (NextToken().is(tok::l_brace))
+  return TPResult::False;
+if (NextToken().is(tok::l_paren)) {

aaron.ballman wrote:
> This seems incorrect to me, consider:
> ```
> auto [[clang::annotate_type("test")]] i = 12;
> ```
> https://godbolt.org/z/7Gx3Gb18h
Ignore this -- `l_brace` is not `l_square`. :-D



Comment at: clang/test/Parser/cxx1z-decomposition.cpp:97
 decltype(auto) [b] = s; // expected-error {{cannot be declared with type 
'decltype(auto)'}}
-auto ([c]) = s; // expected-error {{cannot be declared with parentheses}}
+auto ([c]) = s; // expected-error {{'auto' not allowed here}} \
+// expected-error {{use of undeclared identifier 'c'}} \

cor3ntin wrote:
> aaron.ballman wrote:
> > This first diagnostic is incorrect -- `auto` is definitely allowed there, 
> > just that the rest of the declaration is nonsense. I think the "use of 
> > undeclared identifier" diagnostic is reasonable. The lambda diagnostic 
> > is interesting.
> > 
> > Any way you can improve this, or is that a slog?
> There were multiple issues there.
> 
> The "decomposition declaration cannot be declared with parenthese" error 
> which i had remove can still occur at global scope where a declaration is 
> expected so i put that back and added a test.
> Then, I'm running all the tests in c++17 and 23 modes as the behavior is 
> different.
> 
> I did restore the current behavior in C++20 and earlier modes, such that we 
> will always consider `auto` starts a declaration. That way we can have that 
> structured binding in parentheses diag.
> 
> But in c++23 mode,  We establish it's not a valid declarator. so we parse it 
> as an expression. `[` is always considered as a lambda introducer, which it 
> could be, ie `auto([c] {});` is a valid expression assuming that C exists.
> At that point trying to figure out that `]` is not followed by `{` and is 
> therefore not a lambda seems extremely tricky as you can have arbitrary long 
> expressions between the square brackets.
> 
Thanks for the explanation -- that seems defensible to me.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149276/new/

https://reviews.llvm.org/D149276

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


[PATCH] D139010: [clang][WebAssembly] Implement support for table types and builtins

2023-04-27 Thread Paulo Matos via Phabricator via cfe-commits
pmatos added inline comments.



Comment at: clang/test/SemaCXX/wasm-refs-and-tables.cpp:35
+task<__externref_t[]> g() {
+  co_return table;
+}

@aaron.ballman I tried and failed to create a good testcase for co_return. 
However creating coroutines seems to be an stdlib thing which I am not sure how 
to test here. Do you have any suggestions here?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139010/new/

https://reviews.llvm.org/D139010

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


[PATCH] D139010: [clang][WebAssembly] Implement support for table types and builtins

2023-04-27 Thread Paulo Matos via Phabricator via cfe-commits
pmatos updated this revision to Diff 517525.
pmatos marked an inline comment as done.
pmatos added a comment.

Quick fixup of test.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139010/new/

https://reviews.llvm.org/D139010

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Type.cpp
  clang/lib/Basic/Targets/WebAssembly.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExceptionSpec.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGen/WebAssembly/builtins-table.c
  clang/test/Sema/builtins-wasm.c
  clang/test/Sema/wasm-refs-and-table-ped.c
  clang/test/Sema/wasm-refs-and-tables.c
  clang/test/Sema/wasm-refs.c
  clang/test/SemaCXX/wasm-refs-and-tables.cpp
  clang/test/SemaCXX/wasm-refs.cpp
  llvm/include/llvm/CodeGen/WasmAddressSpaces.h
  llvm/include/llvm/IR/Type.h
  llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.cpp
  llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
  llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyLowerRefTypesIntPtrConv.cpp

Index: llvm/lib/Target/WebAssembly/WebAssemblyLowerRefTypesIntPtrConv.cpp
===
--- llvm/lib/Target/WebAssembly/WebAssemblyLowerRefTypesIntPtrConv.cpp
+++ llvm/lib/Target/WebAssembly/WebAssemblyLowerRefTypesIntPtrConv.cpp
@@ -62,8 +62,9 @@
   for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) {
 PtrToIntInst *PTI = dyn_cast(&*I);
 IntToPtrInst *ITP = dyn_cast(&*I);
-if (!(PTI && WebAssembly::isRefType(PTI->getPointerOperand()->getType())) &&
-!(ITP && WebAssembly::isRefType(ITP->getDestTy(
+if (!(PTI &&
+  PTI->getPointerOperand()->getType()->isWebAssemblyReferenceType()) &&
+!(ITP && ITP->getDestTy()->isWebAssemblyReferenceType()))
   continue;
 
 UndefValue *U = UndefValue::get(I->getType());
Index: llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
===
--- llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
+++ llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
@@ -1203,7 +1203,7 @@
   // Lastly, if this is a call to a funcref we need to add an instruction
   // table.set to the chain and transform the call.
   if (CLI.CB &&
-  WebAssembly::isFuncrefType(CLI.CB->getCalledOperand()->getType())) {
+  CLI.CB->getCalledOperand()->getType()->isWebAssemblyFuncrefType()) {
 // In the absence of function references proposal where a funcref call is
 // lowered to call_ref, using reference types we generate a table.set to set
 // the funcref to a special table used solely for this purpose, followed by
Index: llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
===
--- llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
+++ llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
@@ -27,43 +27,6 @@
 
 namespace WebAssembly {
 
-enum WasmAddressSpace : unsigned {
-  // Default address space, for pointers to linear memory (stack, heap, data).
-  WASM_ADDRESS_SPACE_DEFAULT = 0,
-  // A non-integral address space for pointers to named objects outside of
-  // linear memory: WebAssembly globals or WebAssembly locals.  Loads and stores
-  // to these pointers are lowered to global.get / global.set or local.get /
-  // local.set, as appropriate.
-  WASM_ADDRESS_SPACE_VAR = 1,
-  // A non-integral address space for externref values
-  WASM_ADDRESS_SPACE_EXTERNREF = 10,
-  // A non-integral address space for funcref values
-  WASM_ADDRESS_SPACE_FUNCREF = 20,
-};
-
-inline bool isDefaultAddressSpace(unsigned AS) {
-  return AS == WASM_ADDRESS_SPACE_DEFAULT;
-}
-inline bool isWasmVarAddressSpace(unsigned AS) {
-  return AS == WASM_ADDRESS_SPACE_VAR;
-}
-inline bool isValidAddressSpace(unsigned AS) {
-  return isDefaultAddressSpace(AS) || isWasmVarAddressSpace(AS);
-}
-inline bool isFuncrefType(const Type *Ty) {
-  return isa(Ty) &&
- Ty->getPointerAddressSpace() ==
- WasmAddressSpace::WASM_ADDRESS_SPACE_FUNCREF;
-}
-inline bool isExternrefType(const Type *Ty) {
-  return isa(Ty) &&
- Ty->getPointerAddressSpace() ==
- WasmAddressSpace::WASM_ADDRESS_SPACE_EXTERNREF;
-}
-inline bool isRefType(const Type *Ty) {
-  return isFuncrefType(Ty) || isExternrefType(Ty);
-}
-
 // Convert StringRef to ValType / HealType / BlockType
 
 MVT parseMVT(StringRef Type);

[PATCH] D139010: [clang][WebAssembly] Implement support for table types and builtins

2023-04-27 Thread Paulo Matos via Phabricator via cfe-commits
pmatos marked an inline comment as done.
pmatos added inline comments.



Comment at: clang/test/Sema/wasm-refs-and-tables.c:17
+static __externref_t t6[] = {0}; // expected-error {{only zero-length 
WebAssembly tables are currently supported}}
+__externref_t t7[0]; // expected-error {{WebAssembly table must be 
static}}
+static __externref_t t8[0][0];   // expected-error {{multi-dimensional arrays 
of WebAssembly references are not allowed}}

aaron.ballman wrote:
> pmatos wrote:
> > aaron.ballman wrote:
> > > So why is `extern __externref_t r2;` allowed? Is it because it's not an 
> > > array declaration?
> > I am not sure I understand the question. The externref value can be 
> > declared in another module and here we just define that. Array declarations 
> > of externref just define tables of externref values.
> Thanks, that helps explain my confusion (boy, I *really* do not like these 
> types; they are quite unintuitive). What was confusing me here is that 
> `__externref_t t7[0];` fails because the declaration doesn't declare a static 
> identifier (yet, in C, it doesn't declare *anything at all* because it an 
> array of zero elements of a sizeless type) while `extern __externref_t r2;` 
> is fine despite not declaring a static identifier (yet, in C, it also doesn't 
> declare *anything at all* because it's a sizeless type). I don't think 
> there's anything to be done about this, the design is what it is in the 
> WebAssembly standard, but all of my discomfort stems around how deeply weird 
> this design is (and it shows with just how much effort we have to go to in 
> order to restrict all the various ways you can use these identifiers).
Yes, I understand. 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139010/new/

https://reviews.llvm.org/D139010

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


[PATCH] D139010: [clang][WebAssembly] Implement support for table types and builtins

2023-04-27 Thread Paulo Matos via Phabricator via cfe-commits
pmatos updated this revision to Diff 517521.
pmatos marked 2 inline comments as done.
pmatos added a comment.

Update a few more tests.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139010/new/

https://reviews.llvm.org/D139010

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Type.cpp
  clang/lib/Basic/Targets/WebAssembly.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExceptionSpec.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGen/WebAssembly/builtins-table.c
  clang/test/Sema/builtins-wasm.c
  clang/test/Sema/wasm-refs-and-table-ped.c
  clang/test/Sema/wasm-refs-and-tables.c
  clang/test/Sema/wasm-refs.c
  clang/test/SemaCXX/wasm-refs-and-tables.cpp
  clang/test/SemaCXX/wasm-refs.cpp
  llvm/include/llvm/CodeGen/WasmAddressSpaces.h
  llvm/include/llvm/IR/Type.h
  llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.cpp
  llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
  llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyLowerRefTypesIntPtrConv.cpp

Index: llvm/lib/Target/WebAssembly/WebAssemblyLowerRefTypesIntPtrConv.cpp
===
--- llvm/lib/Target/WebAssembly/WebAssemblyLowerRefTypesIntPtrConv.cpp
+++ llvm/lib/Target/WebAssembly/WebAssemblyLowerRefTypesIntPtrConv.cpp
@@ -62,8 +62,9 @@
   for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) {
 PtrToIntInst *PTI = dyn_cast(&*I);
 IntToPtrInst *ITP = dyn_cast(&*I);
-if (!(PTI && WebAssembly::isRefType(PTI->getPointerOperand()->getType())) &&
-!(ITP && WebAssembly::isRefType(ITP->getDestTy(
+if (!(PTI &&
+  PTI->getPointerOperand()->getType()->isWebAssemblyReferenceType()) &&
+!(ITP && ITP->getDestTy()->isWebAssemblyReferenceType()))
   continue;
 
 UndefValue *U = UndefValue::get(I->getType());
Index: llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
===
--- llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
+++ llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
@@ -1203,7 +1203,7 @@
   // Lastly, if this is a call to a funcref we need to add an instruction
   // table.set to the chain and transform the call.
   if (CLI.CB &&
-  WebAssembly::isFuncrefType(CLI.CB->getCalledOperand()->getType())) {
+  CLI.CB->getCalledOperand()->getType()->isWebAssemblyFuncrefType()) {
 // In the absence of function references proposal where a funcref call is
 // lowered to call_ref, using reference types we generate a table.set to set
 // the funcref to a special table used solely for this purpose, followed by
Index: llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
===
--- llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
+++ llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
@@ -27,43 +27,6 @@
 
 namespace WebAssembly {
 
-enum WasmAddressSpace : unsigned {
-  // Default address space, for pointers to linear memory (stack, heap, data).
-  WASM_ADDRESS_SPACE_DEFAULT = 0,
-  // A non-integral address space for pointers to named objects outside of
-  // linear memory: WebAssembly globals or WebAssembly locals.  Loads and stores
-  // to these pointers are lowered to global.get / global.set or local.get /
-  // local.set, as appropriate.
-  WASM_ADDRESS_SPACE_VAR = 1,
-  // A non-integral address space for externref values
-  WASM_ADDRESS_SPACE_EXTERNREF = 10,
-  // A non-integral address space for funcref values
-  WASM_ADDRESS_SPACE_FUNCREF = 20,
-};
-
-inline bool isDefaultAddressSpace(unsigned AS) {
-  return AS == WASM_ADDRESS_SPACE_DEFAULT;
-}
-inline bool isWasmVarAddressSpace(unsigned AS) {
-  return AS == WASM_ADDRESS_SPACE_VAR;
-}
-inline bool isValidAddressSpace(unsigned AS) {
-  return isDefaultAddressSpace(AS) || isWasmVarAddressSpace(AS);
-}
-inline bool isFuncrefType(const Type *Ty) {
-  return isa(Ty) &&
- Ty->getPointerAddressSpace() ==
- WasmAddressSpace::WASM_ADDRESS_SPACE_FUNCREF;
-}
-inline bool isExternrefType(const Type *Ty) {
-  return isa(Ty) &&
- Ty->getPointerAddressSpace() ==
- WasmAddressSpace::WASM_ADDRESS_SPACE_EXTERNREF;
-}
-inline bool isRefType(const Type *Ty) {
-  return isFuncrefType(Ty) || isExternrefType(Ty);
-}
-
 // Convert StringRef to ValType / HealType / BlockType
 
 MVT parseMVT(StringRef 

[PATCH] D139010: [clang][WebAssembly] Implement support for table types and builtins

2023-04-27 Thread Paulo Matos via Phabricator via cfe-commits
pmatos marked 2 inline comments as done.
pmatos added inline comments.



Comment at: clang/include/clang/Basic/BuiltinsWebAssembly.def:205-210
+TARGET_BUILTIN(__builtin_wasm_table_set,  "viii", "t", "reference-types")
+TARGET_BUILTIN(__builtin_wasm_table_get,  "iii", "t", "reference-types")
+TARGET_BUILTIN(__builtin_wasm_table_size, "ii", "nt", "reference-types")
+TARGET_BUILTIN(__builtin_wasm_table_grow, "", "nt", "reference-types")
+TARGET_BUILTIN(__builtin_wasm_table_fill, "v", "t", "reference-types")
+TARGET_BUILTIN(__builtin_wasm_table_copy, "vi", "t", "reference-types")

aaron.ballman wrote:
> All of these should be documented in `docs/LanguageExtensions.rst` (you can 
> make a Web Assembly section if one doesn't already exist; we've historically 
> been bad about documenting our builtins).
Working on this - thanks for the reminder.



Comment at: clang/test/SemaCXX/wasm-refs-and-tables.cpp:6-7
+
+// Using c++11 to test dynamic exception specifications (which are not 
+// allowed in c++17).
+

aaron.ballman wrote:
> Much of this file is the same test coverage as in the C case; I'd recommend 
> combining the .c and .cpp files into one test with two RUN lines, and use 
> `-verify=whatever` to distinguish between C vs C++ vs both diagnostic 
> behaviors. The C++ specific code can then be split into a much smaller 
> .cpp-specific file.
I have don't this know. I was not aware we could pass an argument to verify - 
thanks.



Comment at: clang/test/SemaCXX/wasm-refs-and-tables.cpp:14
+
+__externref_t *t1;   // expected-error {{pointer to WebAssembly 
reference type is not allowed}}
+__externref_t **t2;  // expected-error {{pointer to WebAssembly 
reference type is not allowed}}

aaron.ballman wrote:
> Anywhere you'd testing pointer behavior for C++, you should have a test with 
> an lvalue reference as well. I presume those will behave the same as 
> pointers? It'd probably be wise to have tests for rvalue references as well.
Here I guess you're talking about testing __externref_t &. However, this might 
be outside the scope of the patch which deals only with tables.

I could add further lvalue and rvalue reference tests to externref and funcref 
in another patch. What do you think?



Comment at: clang/test/SemaCXX/wasm-refs-and-tables.cpp:16-17
+__externref_t **t2;  // expected-error {{pointer to WebAssembly 
reference type is not allowed}}
+__externref_t **t3;  // expected-error {{pointer to WebAssembly 
reference type is not allowed}}
+static __externref_t t4[3];  // expected-error {{only zero-length 
WebAssembly tables are currently supported}}
+static __externref_t t5[];   // expected-error {{only zero-length 
WebAssembly tables are currently supported}}

aaron.ballman wrote:
> pmatos wrote:
> > aaron.ballman wrote:
> > > This seems really... confused. We can't form a pointer to the type, but 
> > > we can form an array of the type (which decays into a pointer when you 
> > > sneeze near it, and it's not clear whether that should be allowed or not) 
> > > so long as it's a zero-length array (which is an extension in C and C++, 
> > > so do we need to silence pedantic warnings in WASM for this?).
> > As it stands, tables are declared as static arrays of size zero. Then to 
> > access them we need to use builtins. No subscripting, no comparison, no 
> > pointer decay, etc. No passing into functions, returning from functions, 
> > etc. Nothing besides using them as arguments to wasm_table... builtins.
> Okay, that's less confused now, thank you! What should the `-pedantic` 
> behavior be for this:
> ```
> static __externref_t table[0];
> ```
> I presume you don't want the usual "zero size arrays are an extension" 
> warning?
I have fixed this but unsure how to best merge it with the remainder of the 
tests, so created a new test file.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139010/new/

https://reviews.llvm.org/D139010

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


[PATCH] D141451: [clang] report inlining decisions with -Wattribute-{warning|error}

2023-04-27 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/test/Frontend/backend-attribute-error-warning-optimize.c:12
   foo(); // expected-error {{call to 'foo' declared with 'error' attribute: oh 
no foo}}
+ // expected-note@* {{In function 'baz'}}
   if (x())

nickdesaulniers wrote:
> cjdb wrote:
> > aaron.ballman wrote:
> > > nickdesaulniers wrote:
> > > > nickdesaulniers wrote:
> > > > > aaron.ballman wrote:
> > > > > > Instead of allowing this note to appear anywhere in the file, I 
> > > > > > think it's better to use "bookmark" comments. e.g.,
> > > > > > ```
> > > > > > void baz() { // #baz_defn
> > > > > > }
> > > > > > 
> > > > > > void foo() {
> > > > > >   baz(); // expected-note@#baz_defn {{whatever note text}}
> > > > > > }
> > > > > > ```
> > > > > > so that we're testing where the diagnostic is emitted. (This is 
> > > > > > especially important given that the changes are about location 
> > > > > > tracking.)
> > > > > oh, that's new (to me)! will do
> > > > It looks like the "bookmarks" don't work because the notes do not 
> > > > line+col info. They follow the warning/error diagnostic which does, on 
> > > > the bottom most call site.
> > > > 
> > > > The warning is supposed to be emitted on the callsite, not the 
> > > > definition.
> > > I still don't think this is reasonable for test coverage because this 
> > > means we'll accept the note *anywhere* in the file. This makes it much 
> > > too easy to regress the behavior accidentally (e.g., accidentally emit 
> > > all the notes on line 1 of the file). I think we need *some* way to nail 
> > > down where these notes are emitted in the test. However, I might be 
> > > asking you to solve "please track location information through the 
> > > backend" for that, so perhaps this isn't a reasonable request?
> > > 
> > > Also, CC @cjdb for awareness of how this kind of diagnostic is produced 
> > > (Chris is working on an idea for how we emit diagnostics so we get better 
> > > structured information from them, so knowing about this novel approach 
> > > might impact that idea).
> > Very interesting, thanks for the heads up! Cross-phase diagnostics are 
> > definitely something I hadn't considered, and it **does** impact the design 
> > (but not in a derailing way).
> I think we're back at "please track location information through the backend".
> 
> That is the tradeoff with this approach; not measurably regressing 
> performance when these attributes aren't used in source in exchange for Note 
> diagnostics that lack precise line+col info, but in practice provide enough 
> info for the user to understand what's going wrong where.
> 
> Your call if the tradeoff is worth it.
Here's my thinking, please correct any misunderstandings I have:

* This functionality is primarily for use with `_FORTIFY_SOURCE` (but not 
solely for that purpose), and that's an important security feature used by 
glibc and the Linux kernel.
* Security of C and C++ source code is Very Important, especially now that 
various gov't agencies [1][2] are suggesting to not use C or C++ for new 
projects specifically because the security posture of the languages and their 
tools.
* Therefore, the ergonomics of this functionality are quite important for the 
intended use cases and the ecosystem as a whole.
* Emitting only the function name but without location information does not 
give a good user experience, especially in circumstances where the function has 
multiple overloads, because it pushes the burden onto the programmer to figure 
out which functions are actually involved in the call chain. This issue is also 
present in C because of support for `__attribute__((overloadable))` and is not 
just a C++ concern.
* The compile-time performance costs of tracking this location information are 
roughly 1%, and there are no runtime or binary size overhead costs unless other 
functionality is enabled (such as emitting debug info).
* We can determine whether we need to enable this location tracking while 
building the AST when we see one of these two attributes being used, so we 
could enable this functionality selectively without burdening the user with 
enabling it manually via a flag. (We could still consider giving the user a 
flag to never track this even in the presence of the attributes if a user had a 
compelling use case for it.)

If this is all reasonably accurate, I think it's worth seriously considering 
accepting the costs. I don't want to increase our compile time overhead, but at 
the same time, if ~1% is a "make or break" amount of compile-time performance 
to lose, we should be addressing *that* issue rather than hamstringing a 
user-facing diagnostic feature related to security. It's hard to argue "that 
CVE was totally worth it because we could then compile 1% faster". That said, 
perhaps others have a strong contrary opinion they'd like to argue in favor of?

[1] 

[PATCH] D134821: [flang][driver] Allow main program to be in an archive

2023-04-27 Thread Shao-Ce SUN via Phabricator via cfe-commits
sunshaoce added a comment.

Any further suggestions?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D134821/new/

https://reviews.llvm.org/D134821

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


[PATCH] D148596: [KMSAN] Enable on SystemZ

2023-04-27 Thread Ilya Leoshkevich via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa3e56a8792ff: [KMSAN] Enable on SystemZ (authored by iii).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148596/new/

https://reviews.llvm.org/D148596

Files:
  clang/lib/Driver/ToolChains/Linux.cpp
  llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
  llvm/test/Instrumentation/MemorySanitizer/SystemZ/basic-kernel.ll
  llvm/test/Instrumentation/MemorySanitizer/SystemZ/vararg-kernel.ll

Index: llvm/test/Instrumentation/MemorySanitizer/SystemZ/vararg-kernel.ll
===
--- llvm/test/Instrumentation/MemorySanitizer/SystemZ/vararg-kernel.ll
+++ llvm/test/Instrumentation/MemorySanitizer/SystemZ/vararg-kernel.ll
@@ -3,9 +3,60 @@
 target datalayout = "E-m:e-i1:8:16-i8:8:16-i64:64-f128:64-a:8:16-n32:64"
 target triple = "s390x-unknown-linux-gnu"
 
-declare i64 @foo(i64 %guard, ...) #0
+%struct.__va_list = type { i64, i64, ptr, ptr }
+declare void @llvm.lifetime.start.p0(i64, ptr)
+declare void @llvm.va_start(ptr)
+declare void @llvm.va_end(ptr)
+declare void @llvm.lifetime.end.p0(i64, ptr)
+
+define i64 @foo(i64 %guard, ...) #1 {
+  %vl = alloca %struct.__va_list
+  call void @llvm.lifetime.start.p0(i64 32, ptr %vl)
+  call void @llvm.va_start(ptr %vl)
+  call void @llvm.va_end(ptr %vl)
+  call void @llvm.lifetime.end.p0(i64 32, ptr %vl)
+  ret i64 0
+}
 
-attributes #0 = { "target-features"="+soft-float" "use-soft-float"="true" }
+; CHECK-LABEL: define {{[^@]+}}@foo(
+
+; Callers store variadic arguments' shadow and origins into va_arg_shadow and
+; va_arg_origin. Their layout is: the register save area (160 bytes) followed
+; by the overflow arg area. It does not depend on "packed-stack".
+; Check that callees correctly backup shadow into a local variable.
+
+; CHECK: [[TMP:%.*]] = alloca { ptr, ptr }
+; CHECK: [[OverflowSize:%.*]] = load i64, ptr %va_arg_overflow_size
+; CHECK: [[MetaSize:%.*]] = add i64 160, [[OverflowSize]]
+; CHECK: [[ShadowBackup:%.*]] = alloca {{.*}} [[MetaSize]]
+; CHECK: [[MetaCopySize:%.*]] = call i64 @llvm.umin.i64(i64 [[MetaSize]], i64 800)
+; CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 8 [[ShadowBackup]], ptr align 8 %va_arg_shadow, i64 [[MetaCopySize]], i1 false)
+; CHECK: [[OverflowBackup:%.*]] = alloca {{.*}} [[MetaSize]]
+; CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 8 [[OverflowBackup]], ptr align 8 %va_arg_origin, i64 [[MetaCopySize]], i1 false)
+
+; Check that va_start() correctly copies the shadow backup into the shadow of
+; the va_list. Register save area and overflow arg area are copied separately.
+; Only 56 bytes of the register save area is copied, because of
+; "use-soft-float".
+
+; CHECK: call void @llvm.va_start(ptr %vl)
+; CHECK: [[VlAddr:%.*]] = ptrtoint ptr %vl to i64
+; CHECK: [[RegSaveAreaAddrAddr:%.*]] = add i64 [[VlAddr]], 24
+; CHECK: [[RegSaveAreaAddr:%.*]] = inttoptr i64 [[RegSaveAreaAddrAddr]] to ptr
+; CHECK: [[RegSaveArea:%.*]] = load ptr, ptr [[RegSaveAreaAddr]]
+; CHECK: call void @__msan_metadata_ptr_for_store_1(ptr [[TMP]], ptr [[RegSaveArea]])
+; CHECK: [[RegSaveAreaMeta:%.*]] = load { ptr, ptr }, ptr [[TMP]]
+; CHECK: [[RegSaveAreaShadow:%.*]] = extractvalue { ptr, ptr } [[RegSaveAreaMeta]], 0
+; CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 8 [[RegSaveAreaShadow]], ptr align 8 [[ShadowBackup]], i64 56, i1 false)
+; CHECK: [[VlAddr:%.*]] = ptrtoint ptr %vl to i64
+; CHECK: [[OverflowAddrAddr:%.*]] = add i64 [[VlAddr]], 16
+; CHECK: [[OverflowAddr:%.*]] = inttoptr i64 [[OverflowAddrAddr]] to ptr
+; CHECK: [[Overflow:%.*]] = load ptr, ptr [[OverflowAddr]]
+; CHECK: call void @__msan_metadata_ptr_for_store_1(ptr [[TMP]], ptr [[Overflow]])
+; CHECK: [[OverflowMeta:%.*]] = load { ptr, ptr }, ptr [[TMP]]
+; CHECK: [[OverflowShadow:%.*]] = extractvalue { ptr, ptr } [[OverflowMeta]], 0
+; CHECK: [[OverflowShadowBackup:%.*]] = getelementptr i8, ptr [[ShadowBackup]], i32 160
+; CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 8 [[OverflowShadow]], ptr align 8 [[OverflowShadowBackup]], i64 [[OverflowSize]], i1 false)
 
 declare i32 @random_i32()
 declare i64 @random_i64()
Index: llvm/test/Instrumentation/MemorySanitizer/SystemZ/basic-kernel.ll
===
--- /dev/null
+++ llvm/test/Instrumentation/MemorySanitizer/SystemZ/basic-kernel.ll
@@ -0,0 +1,169 @@
+; RUN: opt < %s -S -mcpu=z13 -msan-kernel=1 -float-abi=soft -passes=msan 2>&1 | FileCheck %s
+
+target datalayout = "E-m:e-i1:8:16-i8:8:16-i64:64-f128:64-a:8:16-n32:64"
+target triple = "s390x-unknown-linux-gnu"
+
+define void @Store1(ptr %p, i8 %x) sanitize_memory {
+entry:
+  store i8 %x, ptr %p
+  ret void
+}
+
+; CHECK-LABEL: define {{[^@]+}}@Store1(
+; CHECK: [[META_PTR:%[a-z0-9_]+]] = alloca { ptr, ptr }
+; CHECK: call void @__msan_metadata_ptr_for_store_1(ptr 

[clang] a3e56a8 - [KMSAN] Enable on SystemZ

2023-04-27 Thread Ilya Leoshkevich via cfe-commits

Author: Ilya Leoshkevich
Date: 2023-04-27T13:44:54+02:00
New Revision: a3e56a8792ffaf3a3d3538736e1042b8db45ab89

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

LOG: [KMSAN] Enable on SystemZ

Enable -fsanitize=kernel-memory support in Clang.

The x86_64 ABI requires that shadow_origin_ptr_t must be returned via a
register pair, and the s390x ABI requires that it must be returned via
memory pointed to by a hidden parameter. Normally Clang takes care of
the ABI, but the sanitizers run long after it, so unfortunately they
have to duplicate the ABI logic.

Therefore add a special case for SystemZ and manually emit the
s390x-ABI-compliant calling sequences. Since it's only 2 architectures,
do not create a VarArgHelper-like abstraction layer.

The kernel functions are compiled with the "packed-stack" and
"use-soft-float" attributes. For the "packed-stack" functions, it's not
correct for copyRegSaveArea() to copy 160 bytes of shadow and origins,
since the save area is dynamically sized. Things are greatly simplified
by the fact that the vararg "use-soft-float" functions use precisely
56 bytes in order to save the argument registers to where va_arg() can
find them.

Make copyRegSaveArea() copy only 56 bytes in the "use-soft-float" case.
The "packed-stack" && !"use-soft-float" case has no practical uses at
the moment, so leave it for the future.

Add tests.

Reviewed By: eugenis

Differential Revision: https://reviews.llvm.org/D148596

Added: 
llvm/test/Instrumentation/MemorySanitizer/SystemZ/basic-kernel.ll

Modified: 
clang/lib/Driver/ToolChains/Linux.cpp
llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
llvm/test/Instrumentation/MemorySanitizer/SystemZ/vararg-kernel.ll

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Linux.cpp 
b/clang/lib/Driver/ToolChains/Linux.cpp
index 1fbd26aed596d..5b1922970ce2b 100644
--- a/clang/lib/Driver/ToolChains/Linux.cpp
+++ b/clang/lib/Driver/ToolChains/Linux.cpp
@@ -795,7 +795,7 @@ SanitizerMask Linux::getSupportedSanitizers() const {
   if (IsX86_64 || IsMIPS64 || IsAArch64 || IsPowerPC64 || IsSystemZ ||
   IsLoongArch64)
 Res |= SanitizerKind::Thread;
-  if (IsX86_64)
+  if (IsX86_64 || IsSystemZ)
 Res |= SanitizerKind::KernelMemory;
   if (IsX86 || IsX86_64)
 Res |= SanitizerKind::Function;

diff  --git a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp 
b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
index 93667c9482921..e2269c2a8638d 100644
--- a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
@@ -122,6 +122,10 @@
 ///Arbitrary sized accesses are handled with:
 ///  __msan_metadata_ptr_for_load_n(ptr, size)
 ///  __msan_metadata_ptr_for_store_n(ptr, size);
+///Note that the sanitizer code has to deal with how shadow/origin pairs
+///returned by the these functions are represented in 
diff erent ABIs. In
+///the X86_64 ABI they are returned in RDX:RAX, and in the SystemZ ABI they
+///are written to memory pointed to by a hidden parameter.
 ///  - TLS variables are stored in a single per-task struct. A call to a
 ///function __msan_get_context_state() returning a pointer to that struct
 ///is inserted into every instrumented function before the entry block;
@@ -135,7 +139,7 @@
 /// Also, KMSAN currently ignores uninitialized memory passed into inline asm
 /// calls, making sure we're on the safe side wrt. possible false positives.
 ///
-///  KernelMemorySanitizer only supports X86_64 at the moment.
+///  KernelMemorySanitizer only supports X86_64 and SystemZ at the moment.
 ///
 //
 // FIXME: This sanitizer does not yet handle scalable vectors
@@ -543,6 +547,10 @@ class MemorySanitizer {
   void createKernelApi(Module , const TargetLibraryInfo );
   void createUserspaceApi(Module , const TargetLibraryInfo );
 
+  template 
+  FunctionCallee getOrInsertMsanMetadataFunction(Module , StringRef Name,
+ ArgsTy... Args);
+
   /// True if we're compiling the Linux kernel.
   bool CompileKernel;
   /// Track origins (allocation points) of uninitialized values.
@@ -550,6 +558,7 @@ class MemorySanitizer {
   bool Recover;
   bool EagerChecks;
 
+  Triple TargetTriple;
   LLVMContext *C;
   Type *IntptrTy;
   Type *OriginTy;
@@ -620,13 +629,18 @@ class MemorySanitizer {
   /// Functions for poisoning/unpoisoning local variables
   FunctionCallee MsanPoisonAllocaFn, MsanUnpoisonAllocaFn;
 
-  /// Each of the MsanMetadataPtrXxx functions returns a pair of shadow/origin
-  /// pointers.
+  /// Pair of shadow/origin pointers.
+  Type *MsanMetadata;
+
+  /// Each of the MsanMetadataPtrXxx functions returns a MsanMetadata.
   FunctionCallee 

[PATCH] D149334: [RISCV] Enable strict fp for RISC-V in clang.

2023-04-27 Thread Yeting Kuo via Phabricator via cfe-commits
fakepaper56 created this revision.
fakepaper56 added reviewers: craig.topper, reames, frasercrmck, rogfer01.
Herald added subscribers: jobnoorman, luke, VincentWu, vkmr, evandro, 
luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, 
PkmX, the_o, brucehoult, MartinMosbeck, edward-jones, zzheng, jrtc27, 
shiva0217, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, asb, 
arichardson.
Herald added a project: All.
fakepaper56 requested review of this revision.
Herald added subscribers: cfe-commits, pcwang-thead, eopXD, MaskRay.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149334

Files:
  clang/lib/Basic/Targets/RISCV.h
  clang/test/CodeGen/RISCV/fpconstrained.c


Index: clang/test/CodeGen/RISCV/fpconstrained.c
===
--- /dev/null
+++ clang/test/CodeGen/RISCV/fpconstrained.c
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -triple riscv64 -frounding-math 
-ffp-exception-behavior=strict -fexperimental-strict-floating-point -emit-llvm 
-o - %s | FileCheck %s -check-prefix=FPMODELSTRICT
+// RUN: %clang_cc1 -triple riscv64 -ffp-contract=fast -emit-llvm -o - %s | 
FileCheck %s -check-prefix=PRECISE
+// RUN: %clang_cc1 -triple riscv64 -ffast-math -ffp-contract=fast -emit-llvm 
-o - %s | FileCheck %s -check-prefix=FAST
+// RUN: %clang_cc1 -triple riscv64 -ffast-math -emit-llvm -o - %s | FileCheck 
%s -check-prefix=FASTNOCONTRACT
+// RUN: %clang_cc1 -triple riscv64 -ffast-math -ffp-contract=fast 
-ffp-exception-behavior=ignore -emit-llvm -o - %s | FileCheck %s 
-check-prefix=FAST
+// RUN: %clang_cc1 -triple riscv64 -ffast-math -ffp-contract=fast 
-ffp-exception-behavior=strict -fexperimental-strict-floating-point -emit-llvm 
-o - %s | FileCheck %s -check-prefix=EXCEPT
+// RUN: %clang_cc1 -triple riscv64 -ffast-math -ffp-contract=fast 
-ffp-exception-behavior=maytrap -fexperimental-strict-floating-point -emit-llvm 
-o - %s | FileCheck %s -check-prefix=MAYTRAP
+
+// Test strict-fp support in RISC-V.
+
+float f0, f1, f2;
+
+void foo(void) {
+  // CHECK-LABEL: define {{.*}}void @foo()
+
+  // MAYTRAP: llvm.experimental.constrained.fadd.f32(float %{{.*}}, float 
%{{.*}}, metadata !"round.tonearest", metadata !"fpexcept.maytrap")
+  // EXCEPT: llvm.experimental.constrained.fadd.f32(float %{{.*}}, float 
%{{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict")
+  // FPMODELSTRICT: llvm.experimental.constrained.fadd.f32(float %{{.*}}, 
float %{{.*}}, metadata !"round.dynamic", metadata !"fpexcept.strict")
+  // STRICTEXCEPT: llvm.experimental.constrained.fadd.f32(float %{{.*}}, float 
%{{.*}}, metadata !"round.dynamic", metadata !"fpexcept.strict")
+  // STRICTNOEXCEPT: llvm.experimental.constrained.fadd.f32(float %{{.*}}, 
float %{{.*}}, metadata !"round.dynamic", metadata !"fpexcept.ignore")
+  // PRECISE: fadd contract float %{{.*}}, %{{.*}}
+  // FAST: fadd fast
+  // FASTNOCONTRACT: fadd reassoc nnan ninf nsz arcp afn float
+  f0 = f1 + f2;
+
+  // CHECK: ret
+}
Index: clang/lib/Basic/Targets/RISCV.h
===
--- clang/lib/Basic/Targets/RISCV.h
+++ clang/lib/Basic/Targets/RISCV.h
@@ -41,6 +41,7 @@
 HasRISCVVTypes = true;
 MCountName = "_mcount";
 HasFloat16 = true;
+HasStrictFP = true;
   }
 
   bool setCPU(const std::string ) override {


Index: clang/test/CodeGen/RISCV/fpconstrained.c
===
--- /dev/null
+++ clang/test/CodeGen/RISCV/fpconstrained.c
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -triple riscv64 -frounding-math -ffp-exception-behavior=strict -fexperimental-strict-floating-point -emit-llvm -o - %s | FileCheck %s -check-prefix=FPMODELSTRICT
+// RUN: %clang_cc1 -triple riscv64 -ffp-contract=fast -emit-llvm -o - %s | FileCheck %s -check-prefix=PRECISE
+// RUN: %clang_cc1 -triple riscv64 -ffast-math -ffp-contract=fast -emit-llvm -o - %s | FileCheck %s -check-prefix=FAST
+// RUN: %clang_cc1 -triple riscv64 -ffast-math -emit-llvm -o - %s | FileCheck %s -check-prefix=FASTNOCONTRACT
+// RUN: %clang_cc1 -triple riscv64 -ffast-math -ffp-contract=fast -ffp-exception-behavior=ignore -emit-llvm -o - %s | FileCheck %s -check-prefix=FAST
+// RUN: %clang_cc1 -triple riscv64 -ffast-math -ffp-contract=fast -ffp-exception-behavior=strict -fexperimental-strict-floating-point -emit-llvm -o - %s | FileCheck %s -check-prefix=EXCEPT
+// RUN: %clang_cc1 -triple riscv64 -ffast-math -ffp-contract=fast -ffp-exception-behavior=maytrap -fexperimental-strict-floating-point -emit-llvm -o - %s | FileCheck %s -check-prefix=MAYTRAP
+
+// Test strict-fp support in RISC-V.
+
+float f0, f1, f2;
+
+void foo(void) {
+  // CHECK-LABEL: define {{.*}}void @foo()
+
+  // MAYTRAP: llvm.experimental.constrained.fadd.f32(float %{{.*}}, float %{{.*}}, metadata !"round.tonearest", metadata !"fpexcept.maytrap")
+  // EXCEPT: llvm.experimental.constrained.fadd.f32(float %{{.*}}, float 

[PATCH] D139010: [clang][WebAssembly] Implement support for table types and builtins

2023-04-27 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/test/Sema/wasm-refs-and-tables.c:17
+static __externref_t t6[] = {0}; // expected-error {{only zero-length 
WebAssembly tables are currently supported}}
+__externref_t t7[0]; // expected-error {{WebAssembly table must be 
static}}
+static __externref_t t8[0][0];   // expected-error {{multi-dimensional arrays 
of WebAssembly references are not allowed}}

pmatos wrote:
> aaron.ballman wrote:
> > So why is `extern __externref_t r2;` allowed? Is it because it's not an 
> > array declaration?
> I am not sure I understand the question. The externref value can be declared 
> in another module and here we just define that. Array declarations of 
> externref just define tables of externref values.
Thanks, that helps explain my confusion (boy, I *really* do not like these 
types; they are quite unintuitive). What was confusing me here is that 
`__externref_t t7[0];` fails because the declaration doesn't declare a static 
identifier (yet, in C, it doesn't declare *anything at all* because it an array 
of zero elements of a sizeless type) while `extern __externref_t r2;` is fine 
despite not declaring a static identifier (yet, in C, it also doesn't declare 
*anything at all* because it's a sizeless type). I don't think there's anything 
to be done about this, the design is what it is in the WebAssembly standard, 
but all of my discomfort stems around how deeply weird this design is (and it 
shows with just how much effort we have to go to in order to restrict all the 
various ways you can use these identifiers).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139010/new/

https://reviews.llvm.org/D139010

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


[PATCH] D146178: [Clang][Sema] Fix comparison of constraint expressions

2023-04-27 Thread Alexander Shaposhnikov via Phabricator via cfe-commits
alexander-shaposhnikov updated this revision to Diff 517513.
alexander-shaposhnikov added a comment.

Add more tests


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146178/new/

https://reviews.llvm.org/D146178

Files:
  clang/include/clang/AST/DeclTemplate.h
  clang/include/clang/Sema/Template.h
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/SemaTemplate/concepts-friends.cpp
  clang/test/SemaTemplate/concepts-out-of-line-def.cpp
  clang/test/SemaTemplate/concepts.cpp

Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -816,3 +816,62 @@
 static_assert(Parent::TakesBinary::i == 0);
 }
 
+namespace TemplateInsideNonTemplateClass {
+template concept C = true;
+
+template auto L = [] U>() {};
+
+struct Q {
+  template U> friend constexpr auto decltype(L)::operator()() const;
+};
+} // namespace TemplateInsideNonTemplateClass
+
+namespace GH61959 {
+template 
+concept C = (sizeof(T0) >= 4);
+
+template
+struct Orig { };
+
+template
+struct Orig {
+  template requires C
+  void f() { }
+
+  template requires true
+  void f() { }
+};
+
+template  struct Mod {};
+
+template 
+struct Mod {
+  template  requires C
+  constexpr static int f() { return 1; }
+
+  template  requires C
+  constexpr static int f() { return 2; }
+};
+
+static_assert(Mod::f() == 1);
+static_assert(Mod::f() == 2);
+
+template
+struct Outer {
+  template
+  struct Inner {};
+
+  template
+  struct Inner {
+template
+void foo()  requires C && C && C{}
+template
+void foo()  requires true{}
+  };
+};
+
+void bar() {
+  Outer::Inner I;
+  I.foo();
+}
+}
Index: clang/test/SemaTemplate/concepts-out-of-line-def.cpp
===
--- clang/test/SemaTemplate/concepts-out-of-line-def.cpp
+++ clang/test/SemaTemplate/concepts-out-of-line-def.cpp
@@ -127,3 +127,220 @@
 static_assert(S::specialization("str") == SPECIALIZATION_REQUIRES);
 
 } // namespace multiple_template_parameter_lists
+
+static constexpr int CONSTRAINED_METHOD_1 = 1;
+static constexpr int CONSTRAINED_METHOD_2 = 2;
+
+namespace constrained_members {
+
+template 
+struct S {
+  template 
+  static constexpr int constrained_method();
+};
+
+template <>
+template 
+constexpr int S<1>::constrained_method() { return CONSTRAINED_METHOD_1; }
+
+template <>
+template 
+constexpr int S<2>::constrained_method() { return CONSTRAINED_METHOD_2; }
+
+static_assert(S<1>::constrained_method() == CONSTRAINED_METHOD_1);
+static_assert(S<2>::constrained_method() == CONSTRAINED_METHOD_2);
+
+
+template 
+concept ConceptT1T2 = true;
+
+template
+struct S12 {
+  template T4>
+  static constexpr int constrained_method();
+};
+
+template<>
+template T5>
+constexpr int S12::constrained_method() { return CONSTRAINED_METHOD_1; }
+
+template<>
+template T5>
+constexpr int S12::constrained_method() { return CONSTRAINED_METHOD_2; }
+
+static_assert(S12::constrained_method() == CONSTRAINED_METHOD_1);
+static_assert(S12::constrained_method() == CONSTRAINED_METHOD_2);
+
+} // namespace constrained members
+
+namespace constrained_members_of_nested_types {
+
+template 
+struct S {
+  struct Inner0 {
+struct Inner1 {
+  template 
+  static constexpr int constrained_method();
+};
+  };
+};
+
+template <>
+template 
+constexpr int S<1>::Inner0::Inner1::constrained_method() { return CONSTRAINED_METHOD_1; }
+
+template <>
+template 
+constexpr int S<2>::Inner0::Inner1::constrained_method() { return CONSTRAINED_METHOD_2; }
+
+static_assert(S<1>::Inner0::Inner1::constrained_method() == CONSTRAINED_METHOD_1);
+static_assert(S<2>::Inner0::Inner1::constrained_method() == CONSTRAINED_METHOD_2);
+
+
+template 
+concept ConceptT1T2 = true;
+
+template
+struct S12 {
+  struct Inner0 {
+struct Inner1 {
+  template T4>
+  static constexpr int constrained_method();
+};
+  };
+};
+
+template<>
+template T5>
+constexpr int S12::Inner0::Inner1::constrained_method() { return CONSTRAINED_METHOD_1; }
+
+template<>
+template T5>
+constexpr int S12::Inner0::Inner1::constrained_method() { return CONSTRAINED_METHOD_2; }
+
+static_assert(S12::Inner0::Inner1::constrained_method() == CONSTRAINED_METHOD_1);
+static_assert(S12::Inner0::Inner1::constrained_method() == CONSTRAINED_METHOD_2);
+
+} // namespace constrained_members_of_nested_types
+
+namespace constrained_member_sfinae {
+
+template struct S {
+  template
+  static constexpr int constrained_method() requires (sizeof(int[N * 1073741824 + 4]) == 16) {
+return CONSTRAINED_METHOD_1;
+  }
+
+  template
+  static constexpr int constrained_method() requires (sizeof(int[N]) == 16);
+};
+
+template<>
+template
+constexpr int 

[PATCH] D143347: [lldb][DWARF] Infer no_unique_address attribute

2023-04-27 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

In D143347#4298613 , @kpdev42 wrote:

> So what are next steps? Are we going for implementation of 
> `DW_AT_no_unique_address` (which is going to be a non-standard extension) ? 
> @dblaikie @aprantl @Michael137

in my opinion that would be the most convenient way forward. Perhaps something 
like `DW_AT_LLVM_no_unique_address` even?

Btw what does GCC/gdb do in this case?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D143347/new/

https://reviews.llvm.org/D143347

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


[PATCH] D149172: [clang][Interp] Emit proper diagnostic when comparing unrelated pointers

2023-04-27 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

Meh, turns out `(void*)` is a bitcast, so can't push this yet.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149172/new/

https://reviews.llvm.org/D149172

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


[PATCH] D137414: [TySan] Fix Type Sanitizer build on Linux

2023-04-27 Thread Mingjie Xu via Phabricator via cfe-commits
Enna1 created this revision.
Herald added a project: All.
Enna1 updated this revision to Diff 474450.
Enna1 added a comment.
Enna1 added a reviewer: fhahn.
Enna1 added a subscriber: MTC.
Enna1 published this revision for review.
Herald added subscribers: Sanitizers, cfe-commits, StephenFan.
Herald added projects: clang, Sanitizers.

update


fhahn added a comment.

Thanks! It looks like this makes the pre-commit testing happy!


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137414

Files:
  clang/runtime/CMakeLists.txt
  compiler-rt/lib/tysan/CMakeLists.txt
  compiler-rt/lib/tysan/tysan_interceptors.cpp

Index: compiler-rt/lib/tysan/tysan_interceptors.cpp
===
--- compiler-rt/lib/tysan/tysan_interceptors.cpp
+++ compiler-rt/lib/tysan/tysan_interceptors.cpp
@@ -84,7 +84,7 @@
   return res;
 }
 
-#ifndef SANITIZER_APPLE
+#if !SANITIZER_APPLE
 INTERCEPTOR(void *, mmap64, void *addr, SIZE_T length, int prot, int flags,
 int fd, OFF64_T offset) {
   void *res = REAL(mmap64)(addr, length, prot, flags, fd, offset);
@@ -154,35 +154,54 @@
   return res;
 }
 
-#ifndef SANITIZER_APPLE
+#if SANITIZER_INTERCEPT_MEMALIGN
 INTERCEPTOR(void *, memalign, uptr alignment, uptr size) {
   void *res = REAL(memalign)(alignment, size);
   if (res)
 tysan_set_type_unknown(res, size);
   return res;
 }
+#define TYSAN_MAYBE_INTERCEPT_MEMALIGN INTERCEPT_FUNCTION(memalign)
+#else
+#define TYSAN_MAYBE_INTERCEPT_MEMALIGN
+#endif // SANITIZER_INTERCEPT_MEMALIGN
 
+#if SANITIZER_INTERCEPT___LIBC_MEMALIGN
 INTERCEPTOR(void *, __libc_memalign, uptr alignment, uptr size) {
   void *res = REAL(__libc_memalign)(alignment, size);
   if (res)
 tysan_set_type_unknown(res, size);
   return res;
 }
+#define TYSAN_MAYBE_INTERCEPT___LIBC_MEMALIGN  \
+  INTERCEPT_FUNCTION(__libc_memalign)
+#else
+#define TYSAN_MAYBE_INTERCEPT___LIBC_MEMALIGN
+#endif // SANITIZER_INTERCEPT___LIBC_MEMALIGN
 
+#if SANITIZER_INTERCEPT_PVALLOC
 INTERCEPTOR(void *, pvalloc, uptr size) {
   void *res = REAL(pvalloc)(size);
   if (res)
 tysan_set_type_unknown(res, size);
   return res;
 }
-#endif
+#define TYSAN_MAYBE_INTERCEPT_PVALLOC INTERCEPT_FUNCTION(pvalloc)
+#else
+#define TYSAN_MAYBE_INTERCEPT_PVALLOC
+#endif // SANITIZER_INTERCEPT_PVALLOC
 
+#if SANITIZER_INTERCEPT_ALIGNED_ALLOC
 INTERCEPTOR(void *, aligned_alloc, uptr alignment, uptr size) {
   void *res = REAL(aligned_alloc)(alignment, size);
   if (res)
 tysan_set_type_unknown(res, size);
   return res;
 }
+#define TYSAN_MAYBE_INTERCEPT_ALIGNED_ALLOC INTERCEPT_FUNCTION(aligned_alloc)
+#else
+#define TYSAN_MAYBE_INTERCEPT_ALIGNED_ALLOC
+#endif
 
 INTERCEPTOR(int, posix_memalign, void **memptr, uptr alignment, uptr size) {
   int res = REAL(posix_memalign)(memptr, alignment, size);
@@ -216,10 +235,10 @@
   INTERCEPT_FUNCTION(free);
   INTERCEPT_FUNCTION(realloc);
   INTERCEPT_FUNCTION(valloc);
-  INTERCEPT_FUNCTION(memalign);
-  INTERCEPT_FUNCTION(__libc_memalign);
-  INTERCEPT_FUNCTION(pvalloc);
-  INTERCEPT_FUNCTION(aligned_alloc);
+  TYSAN_MAYBE_INTERCEPT_MEMALIGN;
+  TYSAN_MAYBE_INTERCEPT___LIBC_MEMALIGN;
+  TYSAN_MAYBE_INTERCEPT_PVALLOC;
+  TYSAN_MAYBE_INTERCEPT_ALIGNED_ALLOC
   INTERCEPT_FUNCTION(posix_memalign);
 
   INTERCEPT_FUNCTION(memset);
Index: compiler-rt/lib/tysan/CMakeLists.txt
===
--- compiler-rt/lib/tysan/CMakeLists.txt
+++ compiler-rt/lib/tysan/CMakeLists.txt
@@ -46,4 +46,19 @@
 CFLAGS ${TYSAN_CFLAGS}
 DEFS ${TYSAN_COMMON_DEFINITIONS}
 PARENT_TARGET tysan)
+else()
+  foreach(arch ${TYSAN_SUPPORTED_ARCH})
+set(TYSAN_CFLAGS ${TYSAN_COMMON_CFLAGS})
+append_list_if(COMPILER_RT_HAS_FPIE_FLAG -fPIE TYSAN_CFLAGS)
+add_compiler_rt_runtime(clang_rt.tysan
+  STATIC
+  ARCHS ${arch}
+  SOURCES ${TYSAN_SOURCES}
+  $
+  $
+  $
+  $
+  CFLAGS ${TYSAN_CFLAGS}
+  PARENT_TARGET tysan)
+  endforeach()
 endif()
Index: clang/runtime/CMakeLists.txt
===
--- clang/runtime/CMakeLists.txt
+++ clang/runtime/CMakeLists.txt
@@ -119,7 +119,7 @@
COMPONENT compiler-rt)
 
   # Add top-level targets that build specific compiler-rt runtimes.
-  set(COMPILER_RT_RUNTIMES fuzzer asan builtins dfsan lsan msan profile tsan ubsan ubsan-minimal)
+  set(COMPILER_RT_RUNTIMES fuzzer asan builtins dfsan lsan msan profile tsan tysan ubsan ubsan-minimal)
   foreach(runtime ${COMPILER_RT_RUNTIMES})
 get_ext_project_build_command(build_runtime_cmd ${runtime})
 add_custom_target(${runtime}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D148663: [RFC][clangd] Use interpolation for CDB pushed via LSP protocol

2023-04-27 Thread Dmitry Polukhin via Phabricator via cfe-commits
DmitryPolukhin added a comment.

In D148663#4298496 , @ilya-biryukov 
wrote:

> I wanted to chime in and provide a bit of context.
> This was a long time ago, so I might misremember, so take this with a grain 
> of salt.
>
> Idea behind pushing the CDB over LSP was to allow the capable client to 
> **fully** control the commands produced for the files.
> Decisions like interpolation were pushed towards the clients intentionally, 
> not accidentally.
> IIRC, the motivation back in the day was either sourcekit-lsp or Theia.
>
> I will let other do the actual review, just wanted to bring up the history 
> for a complete picutre.

Thank you for sharing the context. I completely agree with the idea that 
nothing should prevent clangd clients from fully controlling CDB if they want 
it.
And, if they do so, this diff will just does nothing because there is an exact 
match. It starts playing only if client provided partial CDB and inference is 
required.
So I think it shouldn't break any existing scenarios. But IMHO having inference 
is a good feature for clangd because it allows pushing exactly the same CDB as 
in
compile_commands.json file and re-using clangd logic how to transfer compile 
commands from source to header. Pushing command via LSP might be preferable
in comparison with file based approach to avoid race condition with updating 
the file and clangd reading it + it works better with build systems that can 
generate
compiles commands on the fly for files and generating all of them in advance 
may not be possible.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148663/new/

https://reviews.llvm.org/D148663

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


[PATCH] D149154: [clang][Interp] Emit diagnostic when comparing function pointers

2023-04-27 Thread Timm Bäder via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf8a9c55bef38: [clang][Interp] Emit diagnostic when comparing 
function pointers (authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D149154?vs=516790=517506#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149154/new/

https://reviews.llvm.org/D149154

Files:
  clang/lib/AST/Interp/FunctionPointer.h
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/Opcodes.td
  clang/test/AST/Interp/functions.cpp

Index: clang/test/AST/Interp/functions.cpp
===
--- clang/test/AST/Interp/functions.cpp
+++ clang/test/AST/Interp/functions.cpp
@@ -178,6 +178,31 @@
   static_assert(s.fp == nullptr, ""); // zero-initialized function pointer.
 }
 
+namespace Comparison {
+  void f(), g();
+  constexpr void (*pf)() = , (*pg)() = 
+
+  constexpr bool u13 = pf < pg; // ref-warning {{ordered comparison of function pointers}} \
+// ref-error {{must be initialized by a constant expression}} \
+// ref-note {{comparison between '' and '' has unspecified value}} \
+// expected-warning {{ordered comparison of function pointers}} \
+// expected-error {{must be initialized by a constant expression}} \
+// expected-note {{comparison between '' and '' has unspecified value}}
+
+  constexpr bool u14 = pf < (void(*)())nullptr; // ref-warning {{ordered comparison of function pointers}} \
+// ref-error {{must be initialized by a constant expression}} \
+// ref-note {{comparison between '' and 'nullptr' has unspecified value}} \
+// expected-warning {{ordered comparison of function pointers}} \
+// expected-error {{must be initialized by a constant expression}} \
+// expected-note {{comparison between '' and 'nullptr' has unspecified value}}
+
+
+
+  static_assert(pf != pg, "");
+  static_assert(pf == , "");
+  static_assert(pg == , "");
+}
+
 }
 
 struct F {
Index: clang/lib/AST/Interp/Opcodes.td
===
--- clang/lib/AST/Interp/Opcodes.td
+++ clang/lib/AST/Interp/Opcodes.td
@@ -94,7 +94,7 @@
 }
 
 def ComparableTypeClass : TypeClass {
-  let Types = !listconcat(AluTypeClass.Types, [Ptr], [Float]);
+  let Types = !listconcat(AluTypeClass.Types, [Ptr], [Float], [FnPtr]);
 }
 
 class SingletonTypeClass : TypeClass {
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -574,6 +574,29 @@
   return CmpHelper(S, OpPC, Fn);
 }
 
+/// Function pointers cannot be compared in an ordered way.
+template <>
+inline bool CmpHelper(InterpState , CodePtr OpPC,
+   CompareFn Fn) {
+  const auto  = S.Stk.pop();
+  const auto  = S.Stk.pop();
+
+  const SourceInfo  = S.Current->getSource(OpPC);
+  S.FFDiag(Loc, diag::note_constexpr_pointer_comparison_unspecified)
+  << LHS.toDiagnosticString(S.getCtx())
+  << RHS.toDiagnosticString(S.getCtx());
+  return false;
+}
+
+template <>
+inline bool CmpHelperEQ(InterpState , CodePtr OpPC,
+ CompareFn Fn) {
+  const auto  = S.Stk.pop();
+  const auto  = S.Stk.pop();
+  S.Stk.push(Boolean::from(Fn(LHS.compare(RHS;
+  return true;
+}
+
 template <>
 inline bool CmpHelper(InterpState , CodePtr OpPC, CompareFn Fn) {
   using BoolT = PrimConv::T;
Index: clang/lib/AST/Interp/FunctionPointer.h
===
--- clang/lib/AST/Interp/FunctionPointer.h
+++ clang/lib/AST/Interp/FunctionPointer.h
@@ -8,6 +8,7 @@
 #include "clang/AST/APValue.h"
 
 namespace clang {
+class ASTContext;
 namespace interp {
 
 class FunctionPointer final {
@@ -38,6 +39,13 @@
 OS << ")";
   }
 
+  std::string toDiagnosticString(const ASTContext ) const {
+if (!Func)
+  return "nullptr";
+
+return toAPValue().getAsString(Ctx, Func->getDecl()->getType());
+  }
+
   ComparisonCategoryResult compare(const FunctionPointer ) const {
 if (Func == RHS.Func)
   return ComparisonCategoryResult::Equal;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] f8a9c55 - [clang][Interp] Emit diagnostic when comparing function pointers

2023-04-27 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-04-27T12:33:28+02:00
New Revision: f8a9c55bef380a592c4588025f8b6ca4dfc94c47

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

LOG: [clang][Interp] Emit diagnostic when comparing function pointers

Function pointers can be compared for (in)equality but, but LE, GE, LT,
and GT opcodes should emit an error and abort.

Differential Revision: https://reviews.llvm.org/D149154

Added: 


Modified: 
clang/lib/AST/Interp/FunctionPointer.h
clang/lib/AST/Interp/Interp.h
clang/lib/AST/Interp/Opcodes.td
clang/test/AST/Interp/functions.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/FunctionPointer.h 
b/clang/lib/AST/Interp/FunctionPointer.h
index 2d449bdb031d..20d4d7793185 100644
--- a/clang/lib/AST/Interp/FunctionPointer.h
+++ b/clang/lib/AST/Interp/FunctionPointer.h
@@ -8,6 +8,7 @@
 #include "clang/AST/APValue.h"
 
 namespace clang {
+class ASTContext;
 namespace interp {
 
 class FunctionPointer final {
@@ -38,6 +39,13 @@ class FunctionPointer final {
 OS << ")";
   }
 
+  std::string toDiagnosticString(const ASTContext ) const {
+if (!Func)
+  return "nullptr";
+
+return toAPValue().getAsString(Ctx, Func->getDecl()->getType());
+  }
+
   ComparisonCategoryResult compare(const FunctionPointer ) const {
 if (Func == RHS.Func)
   return ComparisonCategoryResult::Equal;

diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 7b80bb964991..d751ba021b11 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -574,6 +574,29 @@ bool CmpHelperEQ(InterpState , CodePtr OpPC, CompareFn 
Fn) {
   return CmpHelper(S, OpPC, Fn);
 }
 
+/// Function pointers cannot be compared in an ordered way.
+template <>
+inline bool CmpHelper(InterpState , CodePtr OpPC,
+   CompareFn Fn) {
+  const auto  = S.Stk.pop();
+  const auto  = S.Stk.pop();
+
+  const SourceInfo  = S.Current->getSource(OpPC);
+  S.FFDiag(Loc, diag::note_constexpr_pointer_comparison_unspecified)
+  << LHS.toDiagnosticString(S.getCtx())
+  << RHS.toDiagnosticString(S.getCtx());
+  return false;
+}
+
+template <>
+inline bool CmpHelperEQ(InterpState , CodePtr OpPC,
+ CompareFn Fn) {
+  const auto  = S.Stk.pop();
+  const auto  = S.Stk.pop();
+  S.Stk.push(Boolean::from(Fn(LHS.compare(RHS;
+  return true;
+}
+
 template <>
 inline bool CmpHelper(InterpState , CodePtr OpPC, CompareFn Fn) {
   using BoolT = PrimConv::T;

diff  --git a/clang/lib/AST/Interp/Opcodes.td b/clang/lib/AST/Interp/Opcodes.td
index ed0774a78833..717c4629fcc3 100644
--- a/clang/lib/AST/Interp/Opcodes.td
+++ b/clang/lib/AST/Interp/Opcodes.td
@@ -94,7 +94,7 @@ def AllTypeClass : TypeClass {
 }
 
 def ComparableTypeClass : TypeClass {
-  let Types = !listconcat(AluTypeClass.Types, [Ptr], [Float]);
+  let Types = !listconcat(AluTypeClass.Types, [Ptr], [Float], [FnPtr]);
 }
 
 class SingletonTypeClass : TypeClass {

diff  --git a/clang/test/AST/Interp/functions.cpp 
b/clang/test/AST/Interp/functions.cpp
index a8681aae0d58..5bb48ffc54dd 100644
--- a/clang/test/AST/Interp/functions.cpp
+++ b/clang/test/AST/Interp/functions.cpp
@@ -178,6 +178,31 @@ namespace FunctionReturnType {
   static_assert(s.fp == nullptr, ""); // zero-initialized function pointer.
 }
 
+namespace Comparison {
+  void f(), g();
+  constexpr void (*pf)() = , (*pg)() = 
+
+  constexpr bool u13 = pf < pg; // ref-warning {{ordered comparison of 
function pointers}} \
+// ref-error {{must be initialized by a 
constant expression}} \
+// ref-note {{comparison between '' and '' 
has unspecified value}} \
+// expected-warning {{ordered comparison of 
function pointers}} \
+// expected-error {{must be initialized by a 
constant expression}} \
+// expected-note {{comparison between '' and 
'' has unspecified value}}
+
+  constexpr bool u14 = pf < (void(*)())nullptr; // ref-warning {{ordered 
comparison of function pointers}} \
+// ref-error {{must be 
initialized by a constant expression}} \
+// ref-note {{comparison 
between '' and 'nullptr' has unspecified value}} \
+// expected-warning {{ordered 
comparison of function pointers}} \
+// expected-error {{must be 
initialized by a constant expression}} \
+// expected-note {{comparison 
between '' and 'nullptr' has unspecified value}}
+
+
+
+  static_assert(pf != pg, 

[PATCH] D147684: [clangd] Add batch fixes for include-cleaner diagnostics

2023-04-27 Thread Haojian Wu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4b1cec065227: [clangd] Add batch fixes for include-cleaner 
diagnostics (authored by hokein).

Changed prior to commit:
  https://reviews.llvm.org/D147684?vs=517157=517505#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147684/new/

https://reviews.llvm.org/D147684

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/Diagnostics.cpp
  clang-tools-extra/clangd/Diagnostics.h
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/Protocol.cpp
  clang-tools-extra/clangd/Protocol.h
  clang-tools-extra/clangd/test/Inputs/include-cleaner/all1.h
  clang-tools-extra/clangd/test/Inputs/include-cleaner/all2.h
  clang-tools-extra/clangd/test/Inputs/include-cleaner/bar.h
  clang-tools-extra/clangd/test/Inputs/include-cleaner/foo.h
  clang-tools-extra/clangd/test/include-cleaner-batch-fix.test
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
  clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp

Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -45,8 +45,8 @@
 using ::testing::Pointee;
 using ::testing::UnorderedElementsAre;
 
-Matcher withFix(::testing::Matcher FixMatcher) {
-  return Field(::Fixes, ElementsAre(FixMatcher));
+Matcher withFix(std::vector<::testing::Matcher> FixMatcheres) {
+  return Field(::Fixes, testing::UnorderedElementsAreArray(FixMatcheres));
 }
 
 MATCHER_P2(Diag, Range, Message,
@@ -60,6 +60,8 @@
   return arg.Message == Message && arg.Edits.size() == 1 &&
  arg.Edits[0].range == Range && arg.Edits[0].newText == Replacement;
 }
+MATCHER_P(FixMessage, Message, "") { return arg.Message == Message; }
+
 
 std::string guard(llvm::StringRef Code) {
   return "#pragma once\n" + Code.str();
@@ -255,42 +257,51 @@
   UnorderedElementsAre(
   AllOf(Diag(MainFile.range("b"),
  "No header providing \"b\" is directly included"),
-withFix(Fix(MainFile.range("insert_b"), "#include \"b.h\"\n",
-"#include \"b.h\""))),
+withFix({Fix(MainFile.range("insert_b"), "#include \"b.h\"\n",
+ "#include \"b.h\""),
+ FixMessage("add all missing includes")})),
   AllOf(Diag(MainFile.range("bar"),
  "No header providing \"ns::Bar\" is directly included"),
-withFix(Fix(MainFile.range("insert_d"),
-"#include \"dir/d.h\"\n", "#include \"dir/d.h\""))),
+withFix({Fix(MainFile.range("insert_d"),
+ "#include \"dir/d.h\"\n", "#include \"dir/d.h\""),
+ FixMessage("add all missing includes")})),
   AllOf(Diag(MainFile.range("f"),
  "No header providing \"f\" is directly included"),
-withFix(Fix(MainFile.range("insert_f"), "#include \n",
-"#include "))),
+withFix({Fix(MainFile.range("insert_f"), "#include \n",
+ "#include "),
+ FixMessage("add all missing includes")})),
   AllOf(
   Diag(MainFile.range("foobar"),
"No header providing \"foobar\" is directly included"),
-  withFix(Fix(MainFile.range("insert_foobar"),
-  "#include \"public.h\"\n", "#include \"public.h\""))),
+  withFix({Fix(MainFile.range("insert_foobar"),
+   "#include \"public.h\"\n", "#include \"public.h\""),
+   FixMessage("add all missing includes")})),
   AllOf(
   Diag(MainFile.range("vector"),
"No header providing \"std::vector\" is directly included"),
-  withFix(Fix(MainFile.range("insert_vector"),
-  "#include \n", "#include "))),
+  withFix({Fix(MainFile.range("insert_vector"),
+   "#include \n", "#include "),
+   FixMessage("add all missing includes"),})),
   AllOf(Diag(MainFile.range("FOO"),
  "No header providing \"FOO\" is directly included"),
-withFix(Fix(MainFile.range("insert_foo"),
-"#include \"foo.h\"\n", "#include \"foo.h\""))),
+withFix({Fix(MainFile.range("insert_foo"),
+ "#include \"foo.h\"\n", "#include \"foo.h\""),
+ FixMessage("add all missing includes")})),
   

[clang-tools-extra] 4b1cec0 - [clangd] Add batch fixes for include-cleaner diagnostics

2023-04-27 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2023-04-27T12:08:59+02:00
New Revision: 4b1cec065227db64f870a179a2d45cffa314641a

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

LOG: [clangd] Add batch fixes for include-cleaner diagnostics

For each unused-include/missing-include diagnostic, we provide fix-all
alternative to them.

This patch also adds LSP ChangeAnnotation support.

Differential Revision: https://reviews.llvm.org/D147684

Added: 
clang-tools-extra/clangd/test/Inputs/include-cleaner/all1.h
clang-tools-extra/clangd/test/Inputs/include-cleaner/all2.h
clang-tools-extra/clangd/test/Inputs/include-cleaner/bar.h
clang-tools-extra/clangd/test/Inputs/include-cleaner/foo.h
clang-tools-extra/clangd/test/include-cleaner-batch-fix.test

Modified: 
clang-tools-extra/clangd/ClangdLSPServer.cpp
clang-tools-extra/clangd/ClangdLSPServer.h
clang-tools-extra/clangd/CodeComplete.cpp
clang-tools-extra/clangd/Diagnostics.cpp
clang-tools-extra/clangd/Diagnostics.h
clang-tools-extra/clangd/IncludeCleaner.cpp
clang-tools-extra/clangd/Protocol.cpp
clang-tools-extra/clangd/Protocol.h
clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp 
b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index bef6c4de131ed..26e239fa7bed6 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -99,19 +99,29 @@ CodeAction toCodeAction(const ClangdServer::TweakRef , 
const URIForFile ,
 /// Convert from Fix to LSP CodeAction.
 CodeAction toCodeAction(const Fix , const URIForFile ,
 const std::optional ,
-bool SupportsDocumentChanges) {
+bool SupportsDocumentChanges,
+bool SupportChangeAnnotation) {
   CodeAction Action;
   Action.title = F.Message;
   Action.kind = std::string(CodeAction::QUICKFIX_KIND);
   Action.edit.emplace();
   if (!SupportsDocumentChanges) {
 Action.edit->changes.emplace();
-(*Action.edit->changes)[File.uri()] = {F.Edits.begin(), F.Edits.end()};
+auto  = (*Action.edit->changes)[File.uri()];
+for (const auto  : F.Edits)
+  Changes.push_back({E.range, E.newText, /*annotationId=*/""});
   } else {
 Action.edit->documentChanges.emplace();
-TextDocumentEdit& Edit = Action.edit->documentChanges->emplace_back();
+TextDocumentEdit  = Action.edit->documentChanges->emplace_back();
 Edit.textDocument = VersionedTextDocumentIdentifier{{File}, Version};
-Edit.edits = {F.Edits.begin(), F.Edits.end()};
+for (const auto  : F.Edits)
+  Edit.edits.push_back(
+  {E.range, E.newText,
+   SupportChangeAnnotation ? E.annotationId : ""});
+if (SupportChangeAnnotation) {
+  for (const auto &[AID, Annotation]: F.Annotations)
+Action.edit->changeAnnotations[AID] = Annotation;
+}
   }
   return Action;
 }
@@ -509,6 +519,7 @@ void ClangdLSPServer::onInitialize(const InitializeParams 
,
   SupportsReferenceContainer = Params.capabilities.ReferenceContainer;
   SupportFileStatus = Params.initializationOptions.FileStatus;
   SupportsDocumentChanges = Params.capabilities.DocumentChanges;
+  SupportsChangeAnnotation = Params.capabilities.ChangeAnnotation;
   HoverContentFormat = Params.capabilities.HoverContentFormat;
   Opts.LineFoldingOnly = Params.capabilities.LineFoldingOnly;
   SupportsOffsetsInSignatureHelp = Params.capabilities.OffsetsInSignatureHelp;
@@ -1742,7 +1753,8 @@ void ClangdLSPServer::onDiagnosticsReady(PathRef File, 
llvm::StringRef Version,
  for (const auto  : Fixes)
CodeActions.push_back(toCodeAction(Fix, Notification.uri,
   Notification.version,
-  
SupportsDocumentChanges));
+  SupportsDocumentChanges,
+  
SupportsChangeAnnotation));
 
  if (DiagOpts.EmbedFixesInDiagnostics) {
Diag.codeActions.emplace(CodeActions);

diff  --git a/clang-tools-extra/clangd/ClangdLSPServer.h 
b/clang-tools-extra/clangd/ClangdLSPServer.h
index e5e2104dcec2f..33c8d221f9bd4 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.h
+++ b/clang-tools-extra/clangd/ClangdLSPServer.h
@@ -277,6 +277,9 @@ class ClangdLSPServer : private ClangdServer::Callbacks,
   bool SupportsOffsetsInSignatureHelp = false;
   /// Whether the client supports the versioned document changes.
   bool SupportsDocumentChanges = false;
+  /// Whether the client supports change 

[PATCH] D148987: [clang][Interp] Check Neg ops for errors

2023-04-27 Thread Timm Bäder via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6cf14a72390f: [clang][Interp] Check Neg ops for errors 
(authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D148987?vs=517054=517503#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148987/new/

https://reviews.llvm.org/D148987

Files:
  clang/lib/AST/Interp/Integral.h
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/PrimType.h
  clang/test/AST/Interp/literals.cpp


Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -80,6 +80,12 @@
 static_assert(~INT_MIN == INT_MAX, "");
 static_assert(~INT_MAX == INT_MIN, "");
 
+static_assert(-(1 << 31), ""); // expected-error {{not an integral constant 
expression}} \
+   // expected-note {{outside the range of 
representable values}} \
+   // ref-error {{not an integral constant 
expression}} \
+   // ref-note {{outside the range of 
representable values}} \
+
+
 enum E {};
 constexpr E e = static_cast(0);
 static_assert(~e == -1, "");
Index: clang/lib/AST/Interp/PrimType.h
===
--- clang/lib/AST/Interp/PrimType.h
+++ clang/lib/AST/Interp/PrimType.h
@@ -42,6 +42,8 @@
   PT_FnPtr,
 };
 
+constexpr bool isIntegralType(PrimType T) { return T <= PT_Uint64; }
+
 /// Mapping from primitive types to their representation.
 template  struct PrimConv;
 template <> struct PrimConv { using T = Integral<8, true>; };
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -413,12 +413,32 @@
 
 template ::T>
 bool Neg(InterpState , CodePtr OpPC) {
-  const T  = S.Stk.pop();
+  const T  = S.Stk.pop();
   T Result;
-  T::neg(Val, );
 
+  if (!T::neg(Value, )) {
+S.Stk.push(Result);
+return true;
+  }
+
+  assert(isIntegralType(Name) &&
+ "don't expect other types to fail at constexpr negation");
   S.Stk.push(Result);
-  return true;
+
+  APSInt NegatedValue = -Value.toAPSInt(Value.bitWidth() + 1);
+  const Expr *E = S.Current->getExpr(OpPC);
+  QualType Type = E->getType();
+
+  if (S.checkingForUndefinedBehavior()) {
+SmallString<32> Trunc;
+NegatedValue.trunc(Result.bitWidth()).toString(Trunc, 10);
+auto Loc = E->getExprLoc();
+S.report(Loc, diag::warn_integer_constant_overflow) << Trunc << Type;
+return true;
+  }
+
+  S.CCEDiag(E, diag::note_constexpr_overflow) << NegatedValue << Type;
+  return S.noteUndefinedBehavior();
 }
 
 enum class PushVal : bool {
Index: clang/lib/AST/Interp/Integral.h
===
--- clang/lib/AST/Interp/Integral.h
+++ clang/lib/AST/Interp/Integral.h
@@ -223,6 +223,9 @@
   }
 
   static bool neg(Integral A, Integral *R) {
+if (Signed && A.isMin())
+  return true;
+
 *R = -A;
 return false;
   }


Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -80,6 +80,12 @@
 static_assert(~INT_MIN == INT_MAX, "");
 static_assert(~INT_MAX == INT_MIN, "");
 
+static_assert(-(1 << 31), ""); // expected-error {{not an integral constant expression}} \
+   // expected-note {{outside the range of representable values}} \
+   // ref-error {{not an integral constant expression}} \
+   // ref-note {{outside the range of representable values}} \
+
+
 enum E {};
 constexpr E e = static_cast(0);
 static_assert(~e == -1, "");
Index: clang/lib/AST/Interp/PrimType.h
===
--- clang/lib/AST/Interp/PrimType.h
+++ clang/lib/AST/Interp/PrimType.h
@@ -42,6 +42,8 @@
   PT_FnPtr,
 };
 
+constexpr bool isIntegralType(PrimType T) { return T <= PT_Uint64; }
+
 /// Mapping from primitive types to their representation.
 template  struct PrimConv;
 template <> struct PrimConv { using T = Integral<8, true>; };
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -413,12 +413,32 @@
 
 template ::T>
 bool Neg(InterpState , CodePtr OpPC) {
-  const T  = S.Stk.pop();
+  const T  = S.Stk.pop();
   T Result;
-  T::neg(Val, );
 
+  if (!T::neg(Value, )) {
+S.Stk.push(Result);
+return true;
+  }
+
+  assert(isIntegralType(Name) &&
+ "don't expect other types to fail at constexpr negation");
   S.Stk.push(Result);
-  return true;
+
+  APSInt NegatedValue = 

[clang] 6cf14a7 - [clang][Interp] Check Neg ops for errors

2023-04-27 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-04-27T12:05:23+02:00
New Revision: 6cf14a72390f0914b18f30f2f357b783ff84533c

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

LOG: [clang][Interp] Check Neg ops for errors

This should fail when negating __INT_MIN__.

Differential Revision: https://reviews.llvm.org/D148987

Added: 


Modified: 
clang/lib/AST/Interp/Integral.h
clang/lib/AST/Interp/Interp.h
clang/lib/AST/Interp/PrimType.h
clang/test/AST/Interp/literals.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Integral.h b/clang/lib/AST/Interp/Integral.h
index 932caca29b9f0..cc7c7a9d2430e 100644
--- a/clang/lib/AST/Interp/Integral.h
+++ b/clang/lib/AST/Interp/Integral.h
@@ -223,6 +223,9 @@ template  class Integral final {
   }
 
   static bool neg(Integral A, Integral *R) {
+if (Signed && A.isMin())
+  return true;
+
 *R = -A;
 return false;
   }

diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 152a876a42964..7b80bb9649916 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -413,12 +413,32 @@ bool Inv(InterpState , CodePtr OpPC) {
 
 template ::T>
 bool Neg(InterpState , CodePtr OpPC) {
-  const T  = S.Stk.pop();
+  const T  = S.Stk.pop();
   T Result;
-  T::neg(Val, );
 
+  if (!T::neg(Value, )) {
+S.Stk.push(Result);
+return true;
+  }
+
+  assert(isIntegralType(Name) &&
+ "don't expect other types to fail at constexpr negation");
   S.Stk.push(Result);
-  return true;
+
+  APSInt NegatedValue = -Value.toAPSInt(Value.bitWidth() + 1);
+  const Expr *E = S.Current->getExpr(OpPC);
+  QualType Type = E->getType();
+
+  if (S.checkingForUndefinedBehavior()) {
+SmallString<32> Trunc;
+NegatedValue.trunc(Result.bitWidth()).toString(Trunc, 10);
+auto Loc = E->getExprLoc();
+S.report(Loc, diag::warn_integer_constant_overflow) << Trunc << Type;
+return true;
+  }
+
+  S.CCEDiag(E, diag::note_constexpr_overflow) << NegatedValue << Type;
+  return S.noteUndefinedBehavior();
 }
 
 enum class PushVal : bool {

diff  --git a/clang/lib/AST/Interp/PrimType.h b/clang/lib/AST/Interp/PrimType.h
index 30bec3f2a17cf..693e57210608d 100644
--- a/clang/lib/AST/Interp/PrimType.h
+++ b/clang/lib/AST/Interp/PrimType.h
@@ -42,6 +42,8 @@ enum PrimType : unsigned {
   PT_FnPtr,
 };
 
+constexpr bool isIntegralType(PrimType T) { return T <= PT_Uint64; }
+
 /// Mapping from primitive types to their representation.
 template  struct PrimConv;
 template <> struct PrimConv { using T = Integral<8, true>; };

diff  --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index 598d748c266b4..acad760bc43ee 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -80,6 +80,12 @@ static_assert(~255 == -256, "");
 static_assert(~INT_MIN == INT_MAX, "");
 static_assert(~INT_MAX == INT_MIN, "");
 
+static_assert(-(1 << 31), ""); // expected-error {{not an integral constant 
expression}} \
+   // expected-note {{outside the range of 
representable values}} \
+   // ref-error {{not an integral constant 
expression}} \
+   // ref-note {{outside the range of 
representable values}} \
+
+
 enum E {};
 constexpr E e = static_cast(0);
 static_assert(~e == -1, "");



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


[PATCH] D148712: [clang] Diagnose shadowing of lambda's template parameter by a capture

2023-04-27 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon updated this revision to Diff 517502.
Fznamznon added a comment.

Rebase to double check that pre-commit fail is unrelated, add a release note


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148712/new/

https://reviews.llvm.org/D148712

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaLambda.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.lambda/expr.prim.lambda.capture/p5.cpp
  clang/test/SemaCXX/warn-shadow-in-lambdas.cpp


Index: clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
===
--- clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
+++ clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
@@ -2,6 +2,7 @@
 // RUN: %clang_cc1 -std=c++14 -verify -fsyntax-only -Wshadow 
-Wshadow-uncaptured-local %s
 // RUN: %clang_cc1 -std=c++14 -verify -fsyntax-only -Wshadow-all %s
 // RUN: %clang_cc1 -std=c++17 -verify -fsyntax-only -Wshadow-all %s
+// RUN: %clang_cc1 -std=c++20 -verify -fsyntax-only -Wshadow-all %s
 
 void foo(int param) { // expected-note 1+ {{previous declaration is here}}
   int var = 0; // expected-note 1+ {{previous declaration is here}}
@@ -146,3 +147,22 @@
 int b = 0; // expected-error {{redefinition of 'b'}}
   };
 }
+
+namespace GH61105 {
+void f() {
+  int y = 0;
+  int x = 0;
+#if __cplusplus >= 202002L
+  auto l1 = [y](y) { return 0; }; // expected-error {{declaration 
of 'y' shadows template parameter}} \
+  // expected-note {{template 
parameter is declared here}}
+  auto l2 = [=]() { int a = y; return 0; }; // expected-error 
{{'y' does not refer to a value}} \
+// expected-note 
{{declared here}}
+  auto l3 = [&, y](y) { int a = x; return 0; }; // 
expected-error {{declaration of 'y' shadows template parameter}} \
+  // 
expected-note {{template parameter is declared here}}
+  auto l4 = [x, y]() { return 0; }; // expected-error 
{{declaration of 'y' shadows template parameter}} \
+   // expected-error 
{{declaration of 'x' shadows template parameter}} \
+   // expected-note 
2{{template parameter is declared here}}
+  auto l5 = [](y) { return 0; }; // No diagnostic
+#endif
+}
+}
Index: 
clang/test/CXX/expr/expr.prim/expr.prim.lambda/expr.prim.lambda.capture/p5.cpp
===
--- /dev/null
+++ 
clang/test/CXX/expr/expr.prim/expr.prim.lambda/expr.prim.lambda.capture/p5.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -std=c++20 -verify %s
+
+void f() {
+  int x = 0;
+  auto g = [x](int x) { return 0; }; // expected-error {{a lambda parameter 
cannot shadow an explicitly captured entity}} \
+ // expected-note {{variable 'x' is 
explicitly captured here}}
+  auto h = [y = 0](y) { return 0; };  // expected-error 
{{declaration of 'y' shadows template parameter}} \
+  // expected-note {{template 
parameter is declared here}}
+
+}
Index: clang/lib/Sema/SemaLambda.cpp
===
--- clang/lib/Sema/SemaLambda.cpp
+++ clang/lib/Sema/SemaLambda.cpp
@@ -1365,6 +1365,26 @@
 PushOnScopeChains(P, CurScope);
   }
 
+  // C++23 [expr.prim.lambda.capture]p5:
+  // If an identifier in a capture appears as the declarator-id of a parameter
+  // of the lambda-declarator's parameter-declaration-clause or as the name of 
a
+  // template parameter of the lambda-expression's template-parameter-list, the
+  // program is ill-formed.
+  TemplateParameterList *TemplateParams =
+  getGenericLambdaTemplateParameterList(LSI, *this);
+  if (TemplateParams) {
+for (const auto *TP : TemplateParams->asArray()) {
+  if (!TP->getIdentifier())
+continue;
+  for (const auto  : Intro.Captures) {
+if (Capture.Id == TP->getIdentifier()) {
+  Diag(Capture.Loc, diag::err_template_param_shadow) << Capture.Id;
+  Diag(TP->getLocation(), diag::note_template_param_here);
+}
+  }
+}
+  }
+
   // C++20: dcl.decl.general p4:
   // The optional requires-clause ([temp.pre]) in an init-declarator or
   // member-declarator shall be present only if the declarator declares a
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -231,6 +231,8 @@
 - ``-Wformat`` now recognizes ``%lb`` for the ``printf``/``scanf`` family of
   functions.
   (`#62247: `_).
+- Clang now diagnoses shadowing of lambda's template parameter by a capture.
+  (`#61105: `_).
 
 Bug Fixes in This Version
 

[PATCH] D148330: [clang] Do not crash on undefined template partial specialization

2023-04-27 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7c97dc20ab61: [clang] Do not crash on undefined template 
partial specialization (authored by Fznamznon).

Changed prior to commit:
  https://reviews.llvm.org/D148330?vs=513581=517496#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148330/new/

https://reviews.llvm.org/D148330

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaCXXScopeSpec.cpp
  clang/test/SemaCXX/undefined-partial-specialization.cpp


Index: clang/test/SemaCXX/undefined-partial-specialization.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/undefined-partial-specialization.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -std=c++17 -verify %s
+// RUN: %clang_cc1 -std=c++20 -verify %s
+
+namespace GH61356 {
+
+template 
+class boo {void foo();};
+
+template 
+class boo;
+
+template
+void boo::foo(){} // expected-error{{out-of-line definition of 'foo' 
from class 'boo' without definition}}
+
+}
Index: clang/lib/Sema/SemaCXXScopeSpec.cpp
===
--- clang/lib/Sema/SemaCXXScopeSpec.cpp
+++ clang/lib/Sema/SemaCXXScopeSpec.cpp
@@ -131,7 +131,8 @@
 // entering the context, and that can't happen in a SFINAE context.
 assert(!isSFINAEContext() && "partial specialization scope "
  "specifier in SFINAE context?");
-if (!hasReachableDefinition(PartialSpec))
+if (PartialSpec->hasDefinition() &&
+!hasReachableDefinition(PartialSpec))
   diagnoseMissingImport(SS.getLastQualifierNameLoc(), PartialSpec,
 MissingImportKind::PartialSpecialization,
 true);
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -325,6 +325,8 @@
   member pointer as an invalid expression.
 - Fix crash when member function contains invalid default argument.
   (`#62122 `_)
+- Fix crash when handling undefined template partial specialization
+  (`#61356 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/undefined-partial-specialization.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/undefined-partial-specialization.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -std=c++17 -verify %s
+// RUN: %clang_cc1 -std=c++20 -verify %s
+
+namespace GH61356 {
+
+template 
+class boo {void foo();};
+
+template 
+class boo;
+
+template
+void boo::foo(){} // expected-error{{out-of-line definition of 'foo' from class 'boo' without definition}}
+
+}
Index: clang/lib/Sema/SemaCXXScopeSpec.cpp
===
--- clang/lib/Sema/SemaCXXScopeSpec.cpp
+++ clang/lib/Sema/SemaCXXScopeSpec.cpp
@@ -131,7 +131,8 @@
 // entering the context, and that can't happen in a SFINAE context.
 assert(!isSFINAEContext() && "partial specialization scope "
  "specifier in SFINAE context?");
-if (!hasReachableDefinition(PartialSpec))
+if (PartialSpec->hasDefinition() &&
+!hasReachableDefinition(PartialSpec))
   diagnoseMissingImport(SS.getLastQualifierNameLoc(), PartialSpec,
 MissingImportKind::PartialSpecialization,
 true);
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -325,6 +325,8 @@
   member pointer as an invalid expression.
 - Fix crash when member function contains invalid default argument.
   (`#62122 `_)
+- Fix crash when handling undefined template partial specialization
+  (`#61356 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 7c97dc2 - [clang] Do not crash on undefined template partial specialization

2023-04-27 Thread Mariya Podchishchaeva via cfe-commits

Author: Mariya Podchishchaeva
Date: 2023-04-27T05:38:41-04:00
New Revision: 7c97dc20ab6148289f2cc01b2999130e32a19eb3

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

LOG: [clang] Do not crash on undefined template partial specialization

Before checking that template partial specialization is "reachable",
ensure it exists.

Fixes https://github.com/llvm/llvm-project/issues/61356

Reviewed By: shafik, erichkeane

Differential Revision: https://reviews.llvm.org/D148330

Added: 
clang/test/SemaCXX/undefined-partial-specialization.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaCXXScopeSpec.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ab7b2e05e54c1..f473f97f6c74e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -325,6 +325,8 @@ Bug Fixes in This Version
   member pointer as an invalid expression.
 - Fix crash when member function contains invalid default argument.
   (`#62122 `_)
+- Fix crash when handling undefined template partial specialization
+  (`#61356 `_)
 
 Bug Fixes to Compiler Builtins
 ^^

diff  --git a/clang/lib/Sema/SemaCXXScopeSpec.cpp 
b/clang/lib/Sema/SemaCXXScopeSpec.cpp
index 759ed6f352c81..b11f4f1b7cdd9 100644
--- a/clang/lib/Sema/SemaCXXScopeSpec.cpp
+++ b/clang/lib/Sema/SemaCXXScopeSpec.cpp
@@ -131,7 +131,8 @@ DeclContext *Sema::computeDeclContext(const CXXScopeSpec 
,
 // entering the context, and that can't happen in a SFINAE context.
 assert(!isSFINAEContext() && "partial specialization scope "
  "specifier in SFINAE context?");
-if (!hasReachableDefinition(PartialSpec))
+if (PartialSpec->hasDefinition() &&
+!hasReachableDefinition(PartialSpec))
   diagnoseMissingImport(SS.getLastQualifierNameLoc(), PartialSpec,
 MissingImportKind::PartialSpecialization,
 true);

diff  --git a/clang/test/SemaCXX/undefined-partial-specialization.cpp 
b/clang/test/SemaCXX/undefined-partial-specialization.cpp
new file mode 100644
index 0..b07a513270fd6
--- /dev/null
+++ b/clang/test/SemaCXX/undefined-partial-specialization.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -std=c++17 -verify %s
+// RUN: %clang_cc1 -std=c++20 -verify %s
+
+namespace GH61356 {
+
+template 
+class boo {void foo();};
+
+template 
+class boo;
+
+template
+void boo::foo(){} // expected-error{{out-of-line definition of 'foo' 
from class 'boo' without definition}}
+
+}



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


[PATCH] D149246: [RISCV] Relax rules for ordering s/z/x prefixed extensions in ISA naming strings

2023-04-27 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng accepted this revision.
kito-cheng added a comment.

I am really happy to see this happen, binutils has relaxed for a while in more 
relaxed way[1] - only require must start with `rv[32|64][e|i|g]`, personally I 
would like to relax the order at all like binutils did for GCC, but I don't 
want to disturb that before making sure clang will going same way - otherwise 
just making more incomparable.

The order is kind of not friendly for user, I don't believe how many people 
remember the right order between `z*` extension in short time - even after read 
the RISC-V ISA spec.

[1] https://sourceware.org/pipermail/binutils/2022-December/125267.html


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149246/new/

https://reviews.llvm.org/D149246

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


[PATCH] D132819: [RISCV] Add MC support of RISCV zcmp Extension

2023-04-27 Thread Xinlong Wu via Phabricator via cfe-commits
VincentWu updated this revision to Diff 517494.
VincentWu marked 3 inline comments as done.
VincentWu added a comment.

address comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D132819/new/

https://reviews.llvm.org/D132819

Files:
  clang/test/Preprocessor/riscv-target-features.c
  llvm/docs/RISCVUsage.rst
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
  llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVInstPrinter.cpp
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVInstPrinter.h
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCCodeEmitter.cpp
  llvm/lib/Target/RISCV/RISCVFeatures.td
  llvm/lib/Target/RISCV/RISCVInstrInfoZc.td
  llvm/lib/Target/RISCV/RISCVRegisterInfo.td
  llvm/test/MC/RISCV/attribute-arch.s
  llvm/test/MC/RISCV/rv32zcmp-invalid.s
  llvm/test/MC/RISCV/rv32zcmp-valid.s
  llvm/test/MC/RISCV/rv64zcmp-invalid.s
  llvm/test/MC/RISCV/rv64zcmp-valid.s

Index: llvm/test/MC/RISCV/rv64zcmp-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv64zcmp-valid.s
@@ -0,0 +1,149 @@
+# RUN: llvm-mc %s -triple=riscv64 -mattr=experimental-zcmp -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=experimental-zcmp < %s \
+# RUN: | llvm-objdump --mattr=-c,experimental-zcmp -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefixes=CHECK-ASM-AND-OBJ %s
+
+# CHECK-ASM-AND-OBJ: cm.mvsa01 s1, s0
+# CHECK-ASM: encoding: [0xa2,0xac]
+cm.mvsa01 s1, s0
+
+# CHECK-ASM-AND-OBJ: cm.mva01s s1, s0
+# CHECK-ASM: encoding: [0xe2,0xac]
+cm.mva01s s1, s0
+
+# CHECK-ASM-AND-OBJ: cm.popret   {ra}, 16
+# CHECK-ASM: encoding: [0x42,0xbe]
+cm.popret {ra}, 16
+
+# CHECK-ASM-AND-OBJ: cm.popret   {ra}, 32
+# CHECK-ASM: encoding: [0x46,0xbe]
+cm.popret {ra}, 32
+
+# CHECK-ASM-AND-OBJ: cm.popret   {ra, s0}, 64
+# CHECK-ASM: encoding: [0x5e,0xbe]
+cm.popret {ra, s0}, 64
+
+# CHECK-ASM-AND-OBJ: cm.popret   {ra, s0-s1}, 32
+# CHECK-ASM: encoding: [0x62,0xbe]
+cm.popret {ra,s0-s1}, 32
+
+# CHECK-ASM-AND-OBJ: cm.popret   {ra, s0-s2}, 32
+# CHECK-ASM: encoding: [0x72,0xbe]
+cm.popret {ra, s0-s2}, 32
+
+# CHECK-ASM-AND-OBJ: cm.popret   {ra, s0-s3}, 64
+# CHECK-ASM: encoding: [0x86,0xbe]
+cm.popret {ra, s0-s3}, 64
+
+# CHECK-ASM-AND-OBJ: cm.popret   {ra, s0-s5}, 64
+# CHECK-ASM: encoding: [0xa2,0xbe]
+cm.popret {ra, s0-s5}, 64
+
+# CHECK-ASM-AND-OBJ: cm.popret   {ra, s0-s7}, 80
+# CHECK-ASM: encoding: [0xc2,0xbe]
+cm.popret {ra, s0-s7}, 80
+
+# CHECK-ASM-AND-OBJ: cm.popret   {ra, s0-s11}, 112
+# CHECK-ASM: encoding: [0xf2,0xbe]
+cm.popret {ra, s0-s11}, 112
+
+# CHECK-ASM-AND-OBJ: cm.popretz   {ra}, 16
+# CHECK-ASM: encoding: [0x42,0xbc]
+cm.popretz {ra}, 16
+
+# CHECK-ASM-AND-OBJ: cm.popretz   {ra}, 32
+# CHECK-ASM: encoding: [0x46,0xbc]
+cm.popretz {ra}, 32
+
+# CHECK-ASM-AND-OBJ: cm.popretz   {ra, s0}, 64
+# CHECK-ASM: encoding: [0x5e,0xbc]
+cm.popretz {ra, s0}, 64
+
+# CHECK-ASM-AND-OBJ: cm.popretz   {ra, s0-s1}, 32
+# CHECK-ASM: encoding: [0x62,0xbc]
+cm.popretz {ra, s0-s1}, 32
+
+# CHECK-ASM-AND-OBJ: cm.popretz   {ra, s0-s2}, 32
+# CHECK-ASM: encoding: [0x72,0xbc]
+cm.popretz {ra, s0-s2}, 32
+
+# CHECK-ASM-AND-OBJ: cm.popretz   {ra, s0-s3}, 64
+# CHECK-ASM: encoding: [0x86,0xbc]
+cm.popretz {ra, s0-s3}, 64
+
+# CHECK-ASM-AND-OBJ: cm.popretz   {ra, s0-s5}, 64
+# CHECK-ASM: encoding: [0xa2,0xbc]
+cm.popretz {ra, s0-s5}, 64
+
+# CHECK-ASM-AND-OBJ: cm.popretz   {ra, s0-s7}, 80
+# CHECK-ASM: encoding: [0xc2,0xbc]
+cm.popretz {ra, s0-s7}, 80
+
+# CHECK-ASM-AND-OBJ: cm.popretz   {ra, s0-s11}, 112
+# CHECK-ASM: encoding: [0xf2,0xbc]
+cm.popretz {ra, s0-s11}, 112
+
+# CHECK-ASM-AND-OBJ: cm.pop  {ra}, 16
+# CHECK-ASM: encoding: [0x42,0xba]
+cm.pop {ra}, 16
+
+# CHECK-ASM-AND-OBJ: cm.pop  {ra}, 32
+# CHECK-ASM: encoding: [0x46,0xba]
+cm.pop {ra}, 32
+
+# CHECK-ASM-AND-OBJ: cm.pop  {ra, s0}, 16
+# CHECK-ASM: encoding: [0x52,0xba]
+cm.pop {ra, s0}, 16
+
+# CHECK-ASM-AND-OBJ: cm.pop  {ra, s0-s1}, 32
+# CHECK-ASM: encoding: [0x62,0xba]
+cm.pop {ra, s0-s1}, 32
+
+# CHECK-ASM-AND-OBJ: cm.pop  {ra, s0-s2}, 32
+# CHECK-ASM: encoding: [0x72,0xba]
+cm.pop {ra, s0-s2}, 32
+
+# CHECK-ASM-AND-OBJ: cm.pop  {ra, s0-s5}, 64
+# CHECK-ASM: encoding: [0xa2,0xba]
+cm.pop {ra, s0-s5}, 64
+
+# CHECK-ASM-AND-OBJ: cm.pop  {ra, s0-s7}, 80
+# CHECK-ASM: encoding: [0xc2,0xba]
+cm.pop {ra, s0-s7}, 80
+
+# CHECK-ASM-AND-OBJ: cm.pop  {ra, s0-s11}, 112
+# CHECK-ASM: encoding: [0xf2,0xba]
+cm.pop {ra, s0-s11}, 112
+
+# CHECK-ASM-AND-OBJ: cm.push {ra}, -16
+# CHECK-ASM: encoding: [0x42,0xb8]
+cm.push {ra}, -16
+
+# CHECK-ASM-AND-OBJ: cm.push {ra, s0}, -32
+# CHECK-ASM: encoding: [0x56,0xb8]
+cm.push {ra, s0}, -32
+
+# CHECK-ASM-AND-OBJ: cm.push {ra, s0-s1}, -32
+# 

[PATCH] D149276: [Clang] Fix parsing of `(auto(x))`.

2023-04-27 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/lib/Parse/ParseTentative.cpp:237
   ConsumeAnnotationToken();
-if (Tok.is(tok::identifier))
+if (Tok.isOneOf(tok::identifier, tok::kw_auto))
   ConsumeToken();

aaron.ballman wrote:
> This smells a bit off to me because of the comments above -- this is trying 
> to parse an elaborated type specifier, and `auto` cannot appear in this 
> position for that case. Can you help me understand what's going on?
You are right, this should not have been committed, nice catch!



Comment at: clang/test/Parser/cxx1z-decomposition.cpp:97
 decltype(auto) [b] = s; // expected-error {{cannot be declared with type 
'decltype(auto)'}}
-auto ([c]) = s; // expected-error {{cannot be declared with parentheses}}
+auto ([c]) = s; // expected-error {{'auto' not allowed here}} \
+// expected-error {{use of undeclared identifier 'c'}} \

aaron.ballman wrote:
> This first diagnostic is incorrect -- `auto` is definitely allowed there, 
> just that the rest of the declaration is nonsense. I think the "use of 
> undeclared identifier" diagnostic is reasonable. The lambda diagnostic is 
> interesting.
> 
> Any way you can improve this, or is that a slog?
There were multiple issues there.

The "decomposition declaration cannot be declared with parenthese" error which 
i had remove can still occur at global scope where a declaration is expected so 
i put that back and added a test.
Then, I'm running all the tests in c++17 and 23 modes as the behavior is 
different.

I did restore the current behavior in C++20 and earlier modes, such that we 
will always consider `auto` starts a declaration. That way we can have that 
structured binding in parentheses diag.

But in c++23 mode,  We establish it's not a valid declarator. so we parse it as 
an expression. `[` is always considered as a lambda introducer, which it could 
be, ie `auto([c] {});` is a valid expression assuming that C exists.
At that point trying to figure out that `]` is not followed by `{` and is 
therefore not a lambda seems extremely tricky as you can have arbitrary long 
expressions between the square brackets.



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149276/new/

https://reviews.llvm.org/D149276

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


[PATCH] D148924: [clang] Show error if defaulted comparions operator function is volatile or has ref-qualifier &&.

2023-04-27 Thread Jens Massberg via Phabricator via cfe-commits
massberg marked 5 inline comments as done.
massberg added inline comments.



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:8593
 
+const FunctionProtoType *FnType = 
FD->getType()->castAs();
+if (FnType->isVolatile()) {

aaron.ballman wrote:
> aaron.ballman wrote:
> > ilya-biryukov wrote:
> > > NIT: this version is simpler and more aligned with the code below.
> > > Also, could you move the `volatile` handling after the check for `const`?
> > > 
> > > 
> > > Additionally, we seem to recover in case of `const` by adding it to the 
> > > type and suggesting a fix-it to add it in the code.
> > > Could we do the same for `volatile` and `ref-qualifier`, i.e. suggest a 
> > > fix-it to remove the `ref-qualifier` and `volatile` and change the 
> > > corresponding type to make AST pretend they were never there?
> > 
> Note, you can shorten it further with:
> ```
> return Diag(...);
> ```
> because that will return true for you.
Thanks! Which the change suggested by Ilya this has become obsolete.



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:8593-8601
+const FunctionProtoType *FnType = 
FD->getType()->castAs();
+if (FnType->isVolatile()) {
+  Diag(FD->getLocation(), diag::err_volatile_comparison_operator);
+  return true;
+}
+if (FnType->getRefQualifier() == RQ_RValue) {
+  Diag(FD->getLocation(), diag::err_ref_qualifier_comparison_operator);

massberg wrote:
> aaron.ballman wrote:
> > aaron.ballman wrote:
> > > ilya-biryukov wrote:
> > > > NIT: this version is simpler and more aligned with the code below.
> > > > Also, could you move the `volatile` handling after the check for 
> > > > `const`?
> > > > 
> > > > 
> > > > Additionally, we seem to recover in case of `const` by adding it to the 
> > > > type and suggesting a fix-it to add it in the code.
> > > > Could we do the same for `volatile` and `ref-qualifier`, i.e. suggest a 
> > > > fix-it to remove the `ref-qualifier` and `volatile` and change the 
> > > > corresponding type to make AST pretend they were never there?
> > > 
> > Note, you can shorten it further with:
> > ```
> > return Diag(...);
> > ```
> > because that will return true for you.
> Thanks! Which the change suggested by Ilya this has become obsolete.
Thanks, this is much simpler!

I have moved the code and added a recovery. However, adding a fix-it is much 
more complex as there is no simple way to get location to remove the keywords. 
Thus I decided to not offering a fix-it in this patch.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148924/new/

https://reviews.llvm.org/D148924

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


[PATCH] D149276: [Clang] Fix parsing of `(auto(x))`.

2023-04-27 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/lib/Parse/ParseTentative.cpp:1067
+bool mayHaveDirectInit,
+bool mayHaveTrailingReturnType) {
   // declarator:

Not part of this commit I guess, but //four// bool parameters is truly horrific 
:/


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149276/new/

https://reviews.llvm.org/D149276

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


[PATCH] D149276: [Clang] Fix parsing of `(auto(x))`.

2023-04-27 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 517491.
cor3ntin added a comment.

Do not parse auto( as an expression before C++23


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149276/new/

https://reviews.llvm.org/D149276

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Parse/Parser.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseTentative.cpp
  clang/lib/Parse/Parser.cpp
  clang/test/Parser/cxx1z-decomposition.cpp
  clang/test/Parser/cxx2b-auto-x.cpp

Index: clang/test/Parser/cxx2b-auto-x.cpp
===
--- clang/test/Parser/cxx2b-auto-x.cpp
+++ clang/test/Parser/cxx2b-auto-x.cpp
@@ -18,7 +18,31 @@
 
 using T = looks_like_declaration *;
 void f() { T()->n = 1; }
-// FIXME: They should be deemed expressions without breaking function pointer
-//parameter declarations with trailing return types.
-// void g() { auto()->n = 0; }
-// void h() { auto{}->n = 0; }
+void g() { auto()->n = 0; } // cxx2b-warning {{before C++2b}} \
+  // cxx20-error {{'auto' not allowed here}}
+void h() { auto{}->n = 0; } // cxx2b-warning {{before C++2b}} \
+  // cxx20-error {{'auto' not allowed here}}
+
+void e(auto (*p)(int y) -> decltype(y)) {}
+
+struct M;
+struct S{
+S operator()();
+S* operator->();
+int N;
+int M;
+} s; // expected-note {{here}}
+
+void test() {
+auto(s)()->N; // cxx2b-warning {{expression result unused}} \
+  // cxx2b-warning {{before C++2b}} \
+  // cxx20-error {{'auto' not allowed here}}
+auto(s)()->M; // expected-error {{redefinition of 's' as different kind of symbol}}
+}
+
+void test_paren() {
+int a = (auto(0)); // cxx2b-warning {{before C++2b}} \
+   // cxx20-error {{'auto' not allowed here}}
+int b = (auto{0}); // cxx2b-warning {{before C++2b}} \
+   // cxx20-error {{'auto' not allowed here}}
+}
Index: clang/test/Parser/cxx1z-decomposition.cpp
===
--- clang/test/Parser/cxx1z-decomposition.cpp
+++ clang/test/Parser/cxx1z-decomposition.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -std=c++17 %s -verify -fcxx-exceptions
+// RUN: %clang_cc1 -std=c++17 %s -verify=expected,cxx17 -fcxx-exceptions
+// RUN: %clang_cc1 -std=c++2b %s -verify=expected,cxx2b -fcxx-exceptions
 // RUN: not %clang_cc1 -std=c++17 %s -emit-llvm-only -fcxx-exceptions
 
 struct S { int a, b, c; };
@@ -30,7 +31,7 @@
 namespace OtherDecl {
   // A parameter-declaration is not a simple-declaration.
   // This parses as an array declaration.
-  void f(auto [a, b, c]); // expected-error {{'auto' not allowed in function prototype}} expected-error {{'a'}}
+  void f(auto [a, b, c]); // cxx17-error {{'auto' not allowed in function prototype}} expected-error {{'a'}}
 
   void g() {
 // A condition is allowed as a Clang extension.
@@ -57,7 +58,7 @@
 namespace GoodSpecifiers {
   void f() {
 int n[1];
-const volatile auto &[a] = n;
+const volatile auto &[a] = n; // cxx2b-warning {{volatile qualifier in structured binding declaration is deprecated}}
   }
 }
 
@@ -67,8 +68,8 @@
   struct S { int n; } s;
   void f() {
 // storage-class-specifiers
-static auto &[a] = n; // expected-warning {{declared 'static' is a C++20 extension}}
-thread_local auto &[b] = n; // expected-warning {{declared 'thread_local' is a C++20 extension}}
+static auto &[a] = n; // cxx17-warning {{declared 'static' is a C++20 extension}}
+thread_local auto &[b] = n; // cxx17-warning {{declared 'thread_local' is a C++20 extension}}
 extern auto &[c] = n; // expected-error {{cannot be declared 'extern'}} expected-error {{declaration of block scope identifier with linkage cannot have an initializer}}
 struct S {
   mutable auto &[d] = n; // expected-error {{not permitted in this context}}
@@ -85,16 +86,19 @@
   }
 
   static constexpr inline thread_local auto &[j1] = n; // expected-error {{cannot be declared with 'constexpr inline' specifiers}}
-  static thread_local auto &[j2] = n; // expected-warning {{declared with 'static thread_local' specifiers is a C++20 extension}}
+  static thread_local auto &[j2] = n; // cxx17-warning {{declared with 'static thread_local' specifiers is a C++20 extension}}
 
   inline auto &[k] = n; // expected-error {{cannot be declared 'inline'}}
 
   const int K = 5;
+  auto ([c]) = s; // expected-error {{decomposition declaration cannot be declared with parentheses}}
   void g() {
 // defining-type-specifiers other than cv-qualifiers and 'auto'
 S [a] = s; // expected-error {{cannot be declared with type 'S'}}
 decltype(auto) [b] = s; // expected-error {{cannot be declared with type 'decltype(auto)'}}
-auto ([c]) = s; // expected-error {{cannot be declared with parentheses}}
+auto ([c2]) = s; // cxx17-error {{decomposition declaration cannot be 

[PATCH] D148924: [clang] Show error if defaulted comparions operator function is volatile or has ref-qualifier &&.

2023-04-27 Thread Jens Massberg via Phabricator via cfe-commits
massberg updated this revision to Diff 517489.
massberg added a comment.

Updated  errort messages, code and tests. 



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148924/new/

https://reviews.llvm.org/D148924

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
  clang/test/CodeGenCXX/virtual-compare.cpp

Index: clang/test/CodeGenCXX/virtual-compare.cpp
===
--- clang/test/CodeGenCXX/virtual-compare.cpp
+++ clang/test/CodeGenCXX/virtual-compare.cpp
@@ -21,8 +21,6 @@
   virtual std::strong_ordering operator<=>(const A &) const & = default;
   // CHECK-SAME: @_ZN1A1gEv
   virtual void g();
-  // CHECK-SAME: @_ZNKO1AssERKS_
-  virtual std::strong_ordering operator<=>(const A &) const && = default;
   // CHECK-SAME: @_ZN1A1hEv
   virtual void h();
 
@@ -35,9 +33,6 @@
 
   // CHECK-SAME: @_ZNKR1AeqERKS_
   // implicit virtual A ==(const A&) const & = default;
-
-  // CHECK-SAME: @_ZNKO1AeqERKS_
-  // implicit virtual A ==(const A&) const && = default;
 };
 
 // For Y:
Index: clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
===
--- clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
+++ clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
@@ -15,7 +15,8 @@
 
   bool operator<(const A&) const;
   bool operator<=(const A&) const = default;
-  bool operator==(const A&) const volatile && = default; // surprisingly, OK
+  bool operator==(const A&) const && = default; // expected-error {{ref-qualifier '&&' is not allowed on a defaulted comparison operators}}
+  bool operator>=(const A&) const volatile = default; // expected-error {{defaulted comparison function must not be volatile}}
   bool operator<=>(const A&) = default; // expected-error {{defaulted member three-way comparison operator must be const-qualified}}
   bool operator>=(const B&) const = default; // expected-error-re {{invalid parameter type for defaulted relational comparison operator; found 'const B &', expected 'const A &'{{$
   static bool operator>(const B&) = default; // expected-error {{overloaded 'operator>' cannot be a static member function}}
@@ -185,6 +186,11 @@
 friend bool operator==(const S6&, const S6&) = default; // expected-error {{because it was already declared outside}}
 };
 
+struct S7 {
+  bool operator==(S7 const &) const &&;
+};
+bool S7::operator==(S7 const &) const && = default; // expected-error {{ref-qualifier '&&' is not allowed on a defaulted comparison operators}}
+
 enum e {};
 bool operator==(e, int) = default; // expected-error{{expected class or reference to a constant class}}
 
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -8579,8 +8579,8 @@
   // C++2a [class.compare.default]p1:
   //   A defaulted comparison operator function for some class C shall be a
   //   non-template function declared in the member-specification of C that is
-  //-- a non-static const member of C having one parameter of type
-  //   const C&, or
+  //-- a non-static const non-volatile member of C having one parameter of type
+  //   const C& and either no ref-qualifier or the ref-qualifier &, or
   //-- a friend of C having two parameters of type const C& or two
   //   parameters of type C.
 
@@ -8590,6 +8590,17 @@
 auto *MD = cast(FD);
 assert(!MD->isStatic() && "comparison function cannot be a static member");
 
+if (MD->getRefQualifier() == RQ_RValue) {
+  Diag(MD->getLocation(), diag::err_ref_qualifier_comparison_operator);
+
+  // Remove the ref qualifier to recover.
+  const auto *FPT = MD->getType()->castAs();
+  FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
+  EPI.RefQualifier = RQ_None;
+  MD->setType(Context.getFunctionType(FPT->getReturnType(),
+  FPT->getParamTypes(), EPI));
+}
+
 // If we're out-of-class, this is the class we're comparing.
 if (!RD)
   RD = MD->getParent();
@@ -8612,6 +8623,17 @@
   MD->setType(Context.getFunctionType(FPT->getReturnType(),
   FPT->getParamTypes(), EPI));
 }
+
+if (MD->isVolatile()) {
+  Diag(MD->getLocation(), diag::err_volatile_comparison_operator);
+
+  // Remove the 'volatile' from the type to recover.
+  const auto *FPT = MD->getType()->castAs();
+  FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
+  EPI.TypeQuals.removeVolatile();
+  MD->setType(Context.getFunctionType(FPT->getReturnType(),
+  FPT->getParamTypes(), EPI));
+}
   }
 
   if (FD->getNumParams() != (IsMethod ? 1 

[PATCH] D149276: [Clang] Fix parsing of `(auto(x))`.

2023-04-27 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 517488.
cor3ntin marked 8 inline comments as done.
cor3ntin added a comment.

- Fix tests
- Address aaron's comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149276/new/

https://reviews.llvm.org/D149276

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Parse/Parser.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseTentative.cpp
  clang/lib/Parse/Parser.cpp
  clang/test/Parser/cxx1z-decomposition.cpp
  clang/test/Parser/cxx2b-auto-x.cpp

Index: clang/test/Parser/cxx2b-auto-x.cpp
===
--- clang/test/Parser/cxx2b-auto-x.cpp
+++ clang/test/Parser/cxx2b-auto-x.cpp
@@ -18,7 +18,31 @@
 
 using T = looks_like_declaration *;
 void f() { T()->n = 1; }
-// FIXME: They should be deemed expressions without breaking function pointer
-//parameter declarations with trailing return types.
-// void g() { auto()->n = 0; }
-// void h() { auto{}->n = 0; }
+void g() { auto()->n = 0; } // cxx2b-warning {{before C++2b}} \
+  // cxx20-error {{'auto' not allowed here}}
+void h() { auto{}->n = 0; } // cxx2b-warning {{before C++2b}} \
+  // cxx20-error {{'auto' not allowed here}}
+
+void e(auto (*p)(int y) -> decltype(y)) {}
+
+struct M;
+struct S{
+S operator()();
+S* operator->();
+int N;
+int M;
+} s; // expected-note {{here}}
+
+void test() {
+auto(s)()->N; // cxx2b-warning {{expression result unused}} \
+  // cxx2b-warning {{before C++2b}} \
+  // cxx20-error {{'auto' not allowed here}}
+auto(s)()->M; // expected-error {{redefinition of 's' as different kind of symbol}}
+}
+
+void test_paren() {
+int a = (auto(0)); // cxx2b-warning {{before C++2b}} \
+   // cxx20-error {{'auto' not allowed here}}
+int b = (auto{0}); // cxx2b-warning {{before C++2b}} \
+   // cxx20-error {{'auto' not allowed here}}
+}
Index: clang/test/Parser/cxx1z-decomposition.cpp
===
--- clang/test/Parser/cxx1z-decomposition.cpp
+++ clang/test/Parser/cxx1z-decomposition.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -std=c++17 %s -verify -fcxx-exceptions
+// RUN: %clang_cc1 -std=c++17 %s -verify=expected,cxx17 -fcxx-exceptions
+// RUN: %clang_cc1 -std=c++2b %s -verify=expected,cxx2b -fcxx-exceptions
 // RUN: not %clang_cc1 -std=c++17 %s -emit-llvm-only -fcxx-exceptions
 
 struct S { int a, b, c; };
@@ -30,7 +31,7 @@
 namespace OtherDecl {
   // A parameter-declaration is not a simple-declaration.
   // This parses as an array declaration.
-  void f(auto [a, b, c]); // expected-error {{'auto' not allowed in function prototype}} expected-error {{'a'}}
+  void f(auto [a, b, c]); // cxx17-error {{'auto' not allowed in function prototype}} expected-error {{'a'}}
 
   void g() {
 // A condition is allowed as a Clang extension.
@@ -57,7 +58,7 @@
 namespace GoodSpecifiers {
   void f() {
 int n[1];
-const volatile auto &[a] = n;
+const volatile auto &[a] = n; // cxx2b-warning {{volatile qualifier in structured binding declaration is deprecated}}
   }
 }
 
@@ -67,8 +68,8 @@
   struct S { int n; } s;
   void f() {
 // storage-class-specifiers
-static auto &[a] = n; // expected-warning {{declared 'static' is a C++20 extension}}
-thread_local auto &[b] = n; // expected-warning {{declared 'thread_local' is a C++20 extension}}
+static auto &[a] = n; // cxx17-warning {{declared 'static' is a C++20 extension}}
+thread_local auto &[b] = n; // cxx17-warning {{declared 'thread_local' is a C++20 extension}}
 extern auto &[c] = n; // expected-error {{cannot be declared 'extern'}} expected-error {{declaration of block scope identifier with linkage cannot have an initializer}}
 struct S {
   mutable auto &[d] = n; // expected-error {{not permitted in this context}}
@@ -85,16 +86,19 @@
   }
 
   static constexpr inline thread_local auto &[j1] = n; // expected-error {{cannot be declared with 'constexpr inline' specifiers}}
-  static thread_local auto &[j2] = n; // expected-warning {{declared with 'static thread_local' specifiers is a C++20 extension}}
+  static thread_local auto &[j2] = n; // cxx17-warning {{declared with 'static thread_local' specifiers is a C++20 extension}}
 
   inline auto &[k] = n; // expected-error {{cannot be declared 'inline'}}
 
   const int K = 5;
+  auto ([c]) = s; // expected-error {{decomposition declaration cannot be declared with parentheses}}
   void g() {
 // defining-type-specifiers other than cv-qualifiers and 'auto'
 S [a] = s; // expected-error {{cannot be declared with type 'S'}}
 decltype(auto) [b] = s; // expected-error {{cannot be declared with type 'decltype(auto)'}}
-auto ([c]) = s; // expected-error {{cannot be declared with parentheses}}
+auto ([c2]) = s; // cxx17-error {{'auto' 

[PATCH] D149321: [clang][analyzer] Display buffer sizes in StdCLibraryFunctionArgs checker

2023-04-27 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:889
+  State, getArgSVal(Call, ArgN)))
+Out << " (that is " << *Val << ")";
+}

I think this would be correct.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149321/new/

https://reviews.llvm.org/D149321

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


[PATCH] D139010: [clang][WebAssembly] Implement support for table types and builtins

2023-04-27 Thread Paulo Matos via Phabricator via cfe-commits
pmatos updated this revision to Diff 517478.
pmatos marked 6 inline comments as done.
pmatos added a comment.

Complete fixing tests.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139010/new/

https://reviews.llvm.org/D139010

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Type.cpp
  clang/lib/Basic/Targets/WebAssembly.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExceptionSpec.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGen/WebAssembly/builtins-table.c
  clang/test/Sema/builtins-wasm.c
  clang/test/Sema/wasm-refs-and-tables.c
  clang/test/Sema/wasm-refs.c
  clang/test/SemaCXX/wasm-refs-and-tables.cpp
  clang/test/SemaCXX/wasm-refs.cpp
  llvm/include/llvm/CodeGen/WasmAddressSpaces.h
  llvm/include/llvm/IR/Type.h
  llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.cpp
  llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
  llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyLowerRefTypesIntPtrConv.cpp

Index: llvm/lib/Target/WebAssembly/WebAssemblyLowerRefTypesIntPtrConv.cpp
===
--- llvm/lib/Target/WebAssembly/WebAssemblyLowerRefTypesIntPtrConv.cpp
+++ llvm/lib/Target/WebAssembly/WebAssemblyLowerRefTypesIntPtrConv.cpp
@@ -62,8 +62,9 @@
   for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) {
 PtrToIntInst *PTI = dyn_cast(&*I);
 IntToPtrInst *ITP = dyn_cast(&*I);
-if (!(PTI && WebAssembly::isRefType(PTI->getPointerOperand()->getType())) &&
-!(ITP && WebAssembly::isRefType(ITP->getDestTy(
+if (!(PTI &&
+  PTI->getPointerOperand()->getType()->isWebAssemblyReferenceType()) &&
+!(ITP && ITP->getDestTy()->isWebAssemblyReferenceType()))
   continue;
 
 UndefValue *U = UndefValue::get(I->getType());
Index: llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
===
--- llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
+++ llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
@@ -1203,7 +1203,7 @@
   // Lastly, if this is a call to a funcref we need to add an instruction
   // table.set to the chain and transform the call.
   if (CLI.CB &&
-  WebAssembly::isFuncrefType(CLI.CB->getCalledOperand()->getType())) {
+  CLI.CB->getCalledOperand()->getType()->isWebAssemblyFuncrefType()) {
 // In the absence of function references proposal where a funcref call is
 // lowered to call_ref, using reference types we generate a table.set to set
 // the funcref to a special table used solely for this purpose, followed by
Index: llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
===
--- llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
+++ llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
@@ -27,43 +27,6 @@
 
 namespace WebAssembly {
 
-enum WasmAddressSpace : unsigned {
-  // Default address space, for pointers to linear memory (stack, heap, data).
-  WASM_ADDRESS_SPACE_DEFAULT = 0,
-  // A non-integral address space for pointers to named objects outside of
-  // linear memory: WebAssembly globals or WebAssembly locals.  Loads and stores
-  // to these pointers are lowered to global.get / global.set or local.get /
-  // local.set, as appropriate.
-  WASM_ADDRESS_SPACE_VAR = 1,
-  // A non-integral address space for externref values
-  WASM_ADDRESS_SPACE_EXTERNREF = 10,
-  // A non-integral address space for funcref values
-  WASM_ADDRESS_SPACE_FUNCREF = 20,
-};
-
-inline bool isDefaultAddressSpace(unsigned AS) {
-  return AS == WASM_ADDRESS_SPACE_DEFAULT;
-}
-inline bool isWasmVarAddressSpace(unsigned AS) {
-  return AS == WASM_ADDRESS_SPACE_VAR;
-}
-inline bool isValidAddressSpace(unsigned AS) {
-  return isDefaultAddressSpace(AS) || isWasmVarAddressSpace(AS);
-}
-inline bool isFuncrefType(const Type *Ty) {
-  return isa(Ty) &&
- Ty->getPointerAddressSpace() ==
- WasmAddressSpace::WASM_ADDRESS_SPACE_FUNCREF;
-}
-inline bool isExternrefType(const Type *Ty) {
-  return isa(Ty) &&
- Ty->getPointerAddressSpace() ==
- WasmAddressSpace::WASM_ADDRESS_SPACE_EXTERNREF;
-}
-inline bool isRefType(const Type *Ty) {
-  return isFuncrefType(Ty) || isExternrefType(Ty);
-}
-
 // Convert StringRef to ValType / HealType / BlockType
 
 MVT parseMVT(StringRef Type);
Index: 

[PATCH] D149321: [clang][analyzer] Display buffer sizes in StdCLibraryFunctionArgs checker

2023-04-27 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added reviewers: steakhal, gamesh411.
Szelethus accepted this revision.
Szelethus added a comment.
This revision is now accepted and ready to land.

I am Szelethus, and I approve this warning message!

Now, on another issue, if we can output such a thorough message, we should 
start to consider that in the few cases where we cannot, maybe we should just 
choose to suppress the warning. But that is a job for another patch.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149321/new/

https://reviews.llvm.org/D149321

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


[PATCH] D149321: [clang][analyzer] Display buffer sizes in StdCLibraryFunctionArgs checker

2023-04-27 Thread Balázs Kéri via Phabricator via cfe-commits
balazske created this revision.
Herald added subscribers: steakhal, manas, ASDenysPetrov, martong, gamesh411, 
dkrupp, donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, szepet, 
baloghadamsoftware, xazax.hun.
Herald added a reviewer: Szelethus.
Herald added a reviewer: NoQ.
Herald added a project: All.
balazske requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

If a wrong (too small) buffer argument is found, the dynamic buffer size and
values of connected arguments are displayed in the warning message, if
these are simple known integer values.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149321

Files:
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
  clang/test/Analysis/std-c-library-functions-arg-constraints-notes.cpp
  clang/test/Analysis/std-c-library-functions-arg-constraints-tracking-notes.c
  clang/test/Analysis/std-c-library-functions-arg-constraints.c

Index: clang/test/Analysis/std-c-library-functions-arg-constraints.c
===
--- clang/test/Analysis/std-c-library-functions-arg-constraints.c
+++ clang/test/Analysis/std-c-library-functions-arg-constraints.c
@@ -210,9 +210,9 @@
   // The 3rd parameter should be the number of elements to read, not
   // the size in bytes.
   fread(wbuf, size, nitems, file); // \
-  // report-warning{{The 1st argument to 'fread' is out of the accepted range; It should be a buffer with size equal to or greater than the value of the 2nd argument times the 3rd argument}} \
-  // bugpath-warning{{The 1st argument to 'fread' is out of the accepted range; It should be a buffer with size equal to or greater than the value of the 2nd argument times the 3rd argument}} \
-  // bugpath-note{{The 1st argument to 'fread' is out of the accepted range; It should be a buffer with size equal to or greater than the value of the 2nd argument times the 3rd argument}}
+  // report-warning{{The 1st argument to 'fread' is a buffer with size 4096 but should be a buffer with size equal to or greater than the value of the 2nd argument (that is 4) times the 3rd argument (that is 4096)}} \
+  // bugpath-warning{{The 1st argument to 'fread' is a buffer with size 4096 but should be a buffer with size equal to or greater than the value of the 2nd argument (that is 4) times the 3rd argument (that is 4096)}} \
+  // bugpath-note{{The 1st argument to 'fread' is a buffer with size 4096 but should be a buffer with size equal to or greater than the value of the 2nd argument (that is 4) times the 3rd argument (that is 4096)}}
 }
 
 int __two_constrained_args(int, int);
@@ -254,9 +254,9 @@
 void test_buf_size_concrete(void) {
   char buf[3];   // bugpath-note{{'buf' initialized here}}
   __buf_size_arg_constraint(buf, 4); // \
-  // report-warning{{The 1st argument to '__buf_size_arg_constraint' is out of the accepted range; It should be a buffer with size equal to or greater than the value of the 2nd argument}} \
-  // bugpath-warning{{The 1st argument to '__buf_size_arg_constraint' is out of the accepted range; It should be a buffer with size equal to or greater than the value of the 2nd argument}} \
-  // bugpath-note{{The 1st argument to '__buf_size_arg_constraint' is out of the accepted range; It should be a buffer with size equal to or greater than the value of the 2nd argument}}
+  // report-warning{{The 1st argument to '__buf_size_arg_constraint' is a buffer with size 3 but should be a buffer with size equal to or greater than the value of the 2nd argument (that is 4)}} \
+  // bugpath-warning{{The 1st argument to '__buf_size_arg_constraint' is a buffer with size 3 but should be a buffer with size equal to or greater than the value of the 2nd argument (that is 4)}} \
+  // bugpath-note{{The 1st argument to '__buf_size_arg_constraint' is a buffer with size 3 but should be a buffer with size equal to or greater than the value of the 2nd argument (that is 4)}}
 }
 void test_buf_size_symbolic(int s) {
   char buf[3];
@@ -281,9 +281,9 @@
 void test_buf_size_concrete_with_multiplication(void) {
   short buf[3]; // bugpath-note{{'buf' initialized here}}
   __buf_size_arg_constraint_mul(buf, 4, sizeof(short)); // \
-  // report-warning{{The 1st argument to '__buf_size_arg_constraint_mul' is out of the accepted range; It should be a buffer with size equal to or greater than the value of the 2nd argument times the 3rd argument}} \
-  // bugpath-warning{{The 1st argument to '__buf_size_arg_constraint_mul' is out of the accepted range; It should be a buffer with size equal to or greater than the value of the 2nd argument times the 3rd argument}} \
-  // bugpath-note{{The 1st argument to '__buf_size_arg_constraint_mul' is out of the accepted range; It should be a buffer with size equal to or greater than the value of the 2nd argument times the 3rd argument}}
+  // report-warning{{The 1st 

[PATCH] D149160: [clang][analyzer] Handle special value AT_FDCWD in affected standard functions

2023-04-27 Thread Balázs Kéri via Phabricator via cfe-commits
balazske marked 2 inline comments as done.
balazske added inline comments.



Comment at: 
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:1988
+  return std::make_shared(
+  ArgN, WithinRange, Range({AT_FDCWDv, AT_FDCWDv}, {0, IntMax}), "");
+};

steakhal wrote:
> Should we define a specific constraint description?
> If not, then we should not specify it explicitly - given that it's already 
> defined as an empty string by default.
Now a description is added. This looks better, but the user should know what is 
a "valid file descriptor" (is 0 allowed or not), it is not shown now.



Comment at: 
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:1530-1541
+  // Get platform dependent values of some macros.
+  // Try our best to parse this from the Preprocessor, otherwise fallback to a
+  // default value (what is found in a library header).
+  auto GetMacroValue = [](const char *Name, int Default) -> RangeInt {
 if (const std::optional OptInt =
-tryExpandAsInteger("EOF", C.getPreprocessor()))
+tryExpandAsInteger(Name, C.getPreprocessor()))
   return *OptInt;

steakhal wrote:
> steakhal wrote:
> > 
> What is your response @balazske?
This is much better.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149160/new/

https://reviews.llvm.org/D149160

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


[PATCH] D149160: [clang][analyzer] Handle special value AT_FDCWD in affected standard functions

2023-04-27 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 517470.
balazske marked an inline comment as done.
balazske added a comment.

using short way for getting macro value
added constraint description


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149160/new/

https://reviews.llvm.org/D149160

Files:
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
  clang/test/Analysis/std-c-library-functions-arg-constraints.c

Index: clang/test/Analysis/std-c-library-functions-arg-constraints.c
===
--- clang/test/Analysis/std-c-library-functions-arg-constraints.c
+++ clang/test/Analysis/std-c-library-functions-arg-constraints.c
@@ -3,6 +3,7 @@
 // RUN:   -analyzer-checker=core \
 // RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctions \
 // RUN:   -analyzer-checker=alpha.unix.StdCLibraryFunctionArgs \
+// RUN:   -analyzer-config apiModeling.StdCLibraryFunctions:ModelPOSIX=true \
 // RUN:   -analyzer-checker=debug.StdCLibraryFunctionsTester \
 // RUN:   -analyzer-checker=debug.ExprInspection \
 // RUN:   -triple x86_64-unknown-linux-gnu \
@@ -13,6 +14,7 @@
 // RUN:   -analyzer-checker=core \
 // RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctions \
 // RUN:   -analyzer-checker=alpha.unix.StdCLibraryFunctionArgs \
+// RUN:   -analyzer-config apiModeling.StdCLibraryFunctions:ModelPOSIX=true \
 // RUN:   -analyzer-checker=debug.StdCLibraryFunctionsTester \
 // RUN:   -analyzer-checker=debug.ExprInspection \
 // RUN:   -triple x86_64-unknown-linux-gnu \
@@ -309,3 +311,26 @@
   // bugpath-warning{{The 1st argument to '__buf_size_arg_constraint_concrete' is out of the accepted range; It should be a buffer with size equal to or greater than 10}} \
   // bugpath-note{{The 1st argument to '__buf_size_arg_constraint_concrete' is out of the accepted range; It should be a buffer with size equal to or greater than 10}}
 }
+
+void test_file_fd_at_functions() {
+  (void)linkat(-22, "from", AT_FDCWD, "to", 0); // \
+  // report-warning{{The 1st argument to 'linkat' is -22 but should be a valid file descriptor or AT_FDCWD}} \
+  // bugpath-warning{{The 1st argument to 'linkat' is -22 but should be a valid file descriptor or AT_FDCWD}} \
+  // bugpath-note{{The 1st argument to 'linkat' is -22 but should be a valid file descriptor or AT_FDCWD}}
+
+  // no warning for these functions if the AT_FDCWD value is used
+  (void)linkat(AT_FDCWD, "from", AT_FDCWD, "to", 0);
+  (void)faccessat(AT_FDCWD, "path", 0, 0);
+  (void)symlinkat("oldpath", AT_FDCWD, "newpath");
+  (void)mkdirat(AT_FDCWD, "path", 0);
+  (void)mknodat(AT_FDCWD, "path", 0, 0);
+  (void)fchmodat(AT_FDCWD, "path", 0, 0);
+  (void)fchownat(AT_FDCWD, "path", 0, 0, 0);
+  (void)linkat(AT_FDCWD, "oldpath", AT_FDCWD, "newpath", 0);
+  (void)unlinkat(AT_FDCWD, "newpath", 0);
+  struct stat St;
+  (void)fstatat(AT_FDCWD, "newpath", , 0);
+  char Buf[10];
+  (void)readlinkat(AT_FDCWD, "newpath", Buf, 10);
+  (void)renameat(AT_FDCWD, "oldpath", AT_FDCWD, "newpath");
+}
Index: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -1392,6 +1392,7 @@
   SValBuilder  = C.getSValBuilder();
   BasicValueFactory  = SVB.getBasicValueFactory();
   const ASTContext  = BVF.getContext();
+  Preprocessor  = C.getPreprocessor();
 
   // Helper class to lookup a type by its name.
   class LookupType {
@@ -1527,14 +1528,11 @@
   const RangeInt UCharRangeMax =
   std::min(BVF.getMaxValue(ACtx.UnsignedCharTy).getLimitedValue(), IntMax);
 
-  // The platform dependent value of EOF.
-  // Try our best to parse this from the Preprocessor, otherwise fallback to -1.
-  const auto EOFv = []() -> RangeInt {
-if (const std::optional OptInt =
-tryExpandAsInteger("EOF", C.getPreprocessor()))
-  return *OptInt;
-return -1;
-  }();
+  // Get platform dependent values of some macros.
+  // Try our best to parse this from the Preprocessor, otherwise fallback to a
+  // default value (what is found in a library header).
+  const auto EOFv = tryExpandAsInteger("EOF", PP).value_or(-1);
+  const auto AT_FDCWDv = tryExpandAsInteger("AT_FDCWD", PP).value_or(-100);
 
   // Auxiliary class to aid adding summaries to the summary map.
   struct AddToFunctionSummaryMap {
@@ -1979,6 +1977,12 @@
 ConstraintSet{ReturnValueCondition(WithinRange, Range(-1, IntMax))};
 const auto  = ReturnsNonnegative;
 
+auto ValidFileDescriptorOrAtFdcwd = [&](ArgNo ArgN) {
+  return std::make_shared(
+  ArgN, WithinRange, Range({AT_FDCWDv, AT_FDCWDv}, {0, IntMax}),
+  "a valid file descriptor or AT_FDCWD");
+};
+
 // FILE *fopen(const char *restrict pathname, const char *restrict mode);
 addToFunctionSummaryMap(
 "fopen",
@@ 

[PATCH] D136515: [builtins] Add __builtin_assume_separate_storage.

2023-04-27 Thread Ofek Shilon via Phabricator via cfe-commits
OfekShilon added subscribers: kosarev, OfekShilon.
OfekShilon added inline comments.



Comment at: clang/docs/LanguageExtensions.rst:2393
+particular object (so for example, it's never correct to call this function
+passing the addresses of fields in the same struct, elements of the same array,
+etc.).

bruno wrote:
> davidtgoldblatt wrote:
> > bruno wrote:
> > > Not necessarily a blocker, but it seems like some of these things you 
> > > mention can actually be caught by diagnostics without too much effort? 
> > > Any plans to add them?
> > I hadn't planned to (at least in the short term). Practically I expect uses 
> > of this to be mostly backed out from looking at bad assembly (this is the 
> > way I've been using it so far in experimentation). You wouldn't generally 
> > expect people to want to try to express "these two struct fields don't 
> > alias" and so on because alias analysis can already handle those cases 
> > fairly well.
> > 
> > My inclination would be to wait on the diagnostics until we see if it's a 
> > real problem, but I'm not strongly opposed if you'd really like them in v1. 
> > (Although in that case I'll probably bug you for some help with where / how 
> > to put the diagnostics).
> > My inclination would be to wait on the diagnostics until we see if it's a 
> > real problem
> 
> Sounds fair! Feel free to bug me when/if you decide to explore that route.
+2c: as of today tbaa *doesn't* handle well aliasing of two struct fields. 
There was some work to mitigate it by @kosarev 
(https://reviews.llvm.org/D41539) but it is still hidden behind a 
`-new-struct-path-tbaa` switch.   Example: https://godbolt.org/z/xPMzfea8W


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D136515/new/

https://reviews.llvm.org/D136515

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


[PATCH] D149280: [clang-tidy] Add modernize-printf-to-std-print check

2023-04-27 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added inline comments.



Comment at: clang-tools-extra/clang-tidy/modernize/PrintfToStdPrintCheck.cpp:28
+  ReplacementPrintFunction(Options.get("PrintFunction", "std::print")) {
+  PrintfLikeFunctions.push_back("printf");
+  PrintfLikeFunctions.push_back("absl::PrintF");

NOTE: Consider using fully qualified names, like `::printf`



Comment at: clang-tools-extra/clang-tidy/modernize/PrintfToStdPrintCheck.cpp:45
+  Finder->addMatcher(
+  traverse(TK_AsIs,
+   callExpr(callee(functionDecl(matchers::matchesAnyListedName(

TK_IgnoreUnlessSpelledInSource should be fine for this.



Comment at: clang-tools-extra/clang-tidy/modernize/PrintfToStdPrintCheck.cpp:68
+DiagnosticBuilder Diag =
+diag(PrintfCall->getBeginLoc(), "Replace %0 with '%1'")
+<< OldFunction->getIdentifier() << ReplacementPrintFunction;

start warning with lower case, and maybe something like "use %0 instead of %1" 
(or whatever)



Comment at: clang-tools-extra/clang-tidy/utils/FormatStringConverter.h:32-47
+  const ASTContext *Context;
+  bool ConversionPossible = true;
+  bool FormatStringNeededRewriting = false;
+  size_t PrintfFormatStringPos = 0U;
+  StringRef PrintfFormatString;
+
+  const Expr *const *Args;

NOTE: Consider re-ordering private-public, like in other files, to first put 
public stuff, then private.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149280/new/

https://reviews.llvm.org/D149280

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


[PATCH] D147875: [clang][Diagnostics] Show line numbers when printing code snippets

2023-04-27 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/cert/uppercase-literal-suffix-integer.cpp:34
   // CHECK-MESSAGES-NEXT: ^~
-  // CHECK-MESSAGES-NEXT: {{^ *}}L{{$}}
+  // CHECK-MESSAGES-NEXT: {{^ *| *}}L{{$}}
   // CHECK-FIXES: static constexpr auto v5 = 1L;

PiotrZSL wrote:
> In theory you should escape this character (`|`) by using `\`, otherwise it 
> could be interpreted as an regexp or. Still looks like this test file passes, 
> so 7 to go.
Yeah I noticed the missing backslash but the test passed. 

For the other tests, I've just removed the `{{^ *}}` before the uppercase 
suffix. It seems pointless to check that the line contains nothing else(?). I 
can revert that of course, but it seemed like the easier fix.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147875/new/

https://reviews.llvm.org/D147875

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


[PATCH] D147875: [clang][Diagnostics] Show line numbers when printing code snippets

2023-04-27 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/cert/uppercase-literal-suffix-integer.cpp:34
   // CHECK-MESSAGES-NEXT: ^~
-  // CHECK-MESSAGES-NEXT: {{^ *}}L{{$}}
+  // CHECK-MESSAGES-NEXT: {{^ *| *}}L{{$}}
   // CHECK-FIXES: static constexpr auto v5 = 1L;

In theory you should escape this character (`|`) by using `\`, otherwise it 
could be interpreted as an regexp or. Still looks like this test file passes, 
so 7 to go.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147875/new/

https://reviews.llvm.org/D147875

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


[PATCH] D147875: [clang][Diagnostics] Show line numbers when printing code snippets

2023-04-27 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 517463.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147875/new/

https://reviews.llvm.org/D147875

Files:
  
clang-tools-extra/test/clang-tidy/checkers/cert/uppercase-literal-suffix-integer.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability/uppercase-literal-suffix-float16.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability/uppercase-literal-suffix-floating-point-opencl-half.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability/uppercase-literal-suffix-floating-point.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability/uppercase-literal-suffix-hexadecimal-floating-point.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability/uppercase-literal-suffix-integer-custom-list.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability/uppercase-literal-suffix-integer-ms.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability/uppercase-literal-suffix-integer.cpp
  clang/include/clang/Basic/DiagnosticOptions.def
  clang/include/clang/Basic/DiagnosticOptions.h
  clang/include/clang/Driver/Options.td
  clang/include/clang/Frontend/TextDiagnostic.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/TextDiagnostic.cpp
  clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp
  clang/test/FixIt/fixit-function-call.cpp
  clang/test/FixIt/fixit-newline-style.c
  clang/test/FixIt/fixit-unicode-with-utf8-output.c
  clang/test/FixIt/fixit-unicode.c
  clang/test/Frontend/source-col-map.c
  clang/test/Lexer/header.cpp
  clang/test/Lexer/string-literal-errors.cpp
  clang/test/Misc/caret-diags-macros.c
  clang/test/Misc/caret-diags-multiline.cpp
  clang/test/Misc/diag-macro-backtrace.c
  clang/test/Misc/message-length.c
  clang/test/Misc/tabstop.c
  clang/test/Misc/unnecessary-elipses.cpp
  clang/test/Misc/unprintable.c
  clang/test/Misc/wrong-encoding.c
  clang/test/Parser/brackets.c
  clang/test/Parser/brackets.cpp
  clang/test/Preprocessor/ucn-pp-identifier.c
  clang/test/Sema/caret-diags-complex-init.cpp
  clang/test/SemaCXX/struct-class-redecl.cpp

Index: clang/test/SemaCXX/struct-class-redecl.cpp
===
--- clang/test/SemaCXX/struct-class-redecl.cpp
+++ clang/test/SemaCXX/struct-class-redecl.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -fsyntax-only -Wmismatched-tags -verify %s
-// RUN: not %clang_cc1 -fsyntax-only -Wmismatched-tags %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -fsyntax-only -Wmismatched-tags -fno-diagnostics-show-line-numbers -verify %s
+// RUN: not %clang_cc1 -fsyntax-only -Wmismatched-tags -fno-diagnostics-show-line-numbers %s 2>&1 | FileCheck %s
 class X; // expected-note 2{{here}}
 typedef struct X * X_t; // expected-warning{{previously declared}}
 union X { int x; float y; }; // expected-error{{use of 'X' with tag type that does not match previous declaration}}
Index: clang/test/Sema/caret-diags-complex-init.cpp
===
--- clang/test/Sema/caret-diags-complex-init.cpp
+++ clang/test/Sema/caret-diags-complex-init.cpp
@@ -1,4 +1,4 @@
-// RUN: not %clang_cc1 -std=c++11 -fsyntax-only -fcaret-diagnostics-max-lines 5 %s 2>&1 | FileCheck %s -strict-whitespace
+// RUN: not %clang_cc1 -std=c++11 -fsyntax-only -fno-diagnostics-show-line-numbers -fcaret-diagnostics-max-lines 5 %s 2>&1 | FileCheck %s -strict-whitespace
 
 
 //CHECK: {{.*}}: error: excess elements in scalar initializer
Index: clang/test/Preprocessor/ucn-pp-identifier.c
===
--- clang/test/Preprocessor/ucn-pp-identifier.c
+++ clang/test/Preprocessor/ucn-pp-identifier.c
@@ -112,9 +112,9 @@
 #define capital_u_\U00FC
 // expected-warning@-1 {{incomplete universal character name}} expected-note@-1 {{did you mean to use '\u'?}} expected-warning@-1 {{whitespace}}
 // CHECK: note: did you mean to use '\u'?
-// CHECK-NEXT:   #define capital_u_\U00FC
-// CHECK-NEXT: {{^   \^}}
-// CHECK-NEXT: {{^   u}}
+// CHECK-NEXT: {{^  112 | #define capital_u_\U00FC}}
+// CHECK-NEXT: {{^  |\^}}
+// CHECK-NEXT: {{^  |u}}
 
 #define \u{}   // expected-warning {{empty delimited universal character name; treating as '\' 'u' '{' '}'}} expected-error {{macro name must be an identifier}}
 #define \u1{123}   // expected-warning {{incomplete universal character name; treating as '\' followed by identifier}} expected-error {{macro name must be an identifier}}
Index: clang/test/Parser/brackets.cpp
===
--- clang/test/Parser/brackets.cpp
+++ clang/test/Parser/brackets.cpp
@@ -2,7 +2,7 @@
 // RUN: cp %s %t
 // RUN: not %clang_cc1 -fixit %t -x c++ -DFIXIT
 // RUN: %clang_cc1 -fsyntax-only %t -x c++ -DFIXIT
-// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -strict-whitespace
+// RUN: not %clang_cc1 

[PATCH] D149160: [clang][analyzer] Handle special value AT_FDCWD in affected standard functions

2023-04-27 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added inline comments.



Comment at: 
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:1988
+  return std::make_shared(
+  ArgN, WithinRange, Range({AT_FDCWDv, AT_FDCWDv}, {0, IntMax}), "");
+};

Should we define a specific constraint description?
If not, then we should not specify it explicitly - given that it's already 
defined as an empty string by default.



Comment at: 
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:1530-1541
+  // Get platform dependent values of some macros.
+  // Try our best to parse this from the Preprocessor, otherwise fallback to a
+  // default value (what is found in a library header).
+  auto GetMacroValue = [](const char *Name, int Default) -> RangeInt {
 if (const std::optional OptInt =
-tryExpandAsInteger("EOF", C.getPreprocessor()))
+tryExpandAsInteger(Name, C.getPreprocessor()))
   return *OptInt;

steakhal wrote:
> 
What is your response @balazske?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149160/new/

https://reviews.llvm.org/D149160

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


[PATCH] D149158: [clang][analyzer] Cleanup tests of StdCLibraryFunctionsChecker (NFC)

2023-04-27 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added inline comments.



Comment at: clang/test/Analysis/Inputs/std-c-library-functions.h:1-2
+typedef typeof(sizeof(int)) size_t;
+typedef signed long ssize_t;
+typedef struct {

balazske wrote:
> steakhal wrote:
> > `ssize_t`'s size should match the size of `size_t`. In this implementation, 
> > it would be true only if `size_t` is `long`.
> > 
> I could not find a working way of defining the type in that way (there is no 
> `__sizte_t`). The current definition should work well in the test code, the 
> property of being the same size is supposedly not used in the tests. The 
> previous definition was not better than this (and different in different 
> places).
I think [[ 
https://github.com/llvm/llvm-project/blob/main/clang/test/Sema/format-strings-scanf.c#L7-L15
 | clang/test/Sema/format-strings-scanf.c ]] uses something like this: 
```lang=C++
typedef __SIZE_TYPE__ size_t;
#define __SSIZE_TYPE__ \
  __typeof__(_Generic((__SIZE_TYPE__)0,\
  unsigned long long int : (long long int)0,   \
  unsigned long int : (long int)0, \
  unsigned int : (int)0,   \
  unsigned short : (short)0,   \
  unsigned char : (signed char)0))
typedef __SSIZE_TYPE__ ssize_t;
```



Comment at: clang/test/Analysis/Inputs/std-c-library-functions.h:31
+int getchar(void);
+size_t fread(void *restrict, size_t, size_t, FILE *restrict);
+size_t fwrite(const void *restrict, size_t, size_t, FILE *restrict);

steakhal wrote:
> `restrict` will only work if this header is included from `C` files. In `C++` 
> files we will have a surprising behavior.
Ah, now I see a better way of doing this from [[ 
https://github.com/llvm/llvm-project/blob/main/clang/test/Analysis/Inputs/system-header-simulator.h#L8-L10
 | clang/test/Analysis/Inputs/system-header-simulator.h ]]:
```lang=C++
#ifdef __cplusplus
#define restrict /*restrict*/
#endif
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149158/new/

https://reviews.llvm.org/D149158

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


[PATCH] D148124: [RISCV][Driver] Allow the use of CPUs with a different XLEN than the triple.

2023-04-27 Thread Kito Cheng via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGda4fcb0c0b28: [RISCV][Driver] Allow the use of CPUs with a 
different XLEN than the triple. (authored by kito-cheng).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148124/new/

https://reviews.llvm.org/D148124

Files:
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/riscv-arch.c
  clang/test/Driver/riscv-cpus.c


Index: clang/test/Driver/riscv-cpus.c
===
--- clang/test/Driver/riscv-cpus.c
+++ clang/test/Driver/riscv-cpus.c
@@ -174,6 +174,3 @@
 
 // RUN: %clang --target=riscv32 -### -c %s 2>&1 -mcpu=generic-rv32 
-march=rv64i | FileCheck -check-prefix=MISMATCH-ARCH %s
 // MISMATCH-ARCH: cpu 'generic-rv32' does not support rv64
-
-// RUN: %clang --target=riscv32 -### -c %s 2>&1 -mcpu=generic-rv64 | FileCheck 
-check-prefix=MISMATCH-MCPU %s
-// MISMATCH-MCPU: error: cpu 'generic-rv64' does not support rv32
Index: clang/test/Driver/riscv-arch.c
===
--- clang/test/Driver/riscv-arch.c
+++ clang/test/Driver/riscv-arch.c
@@ -355,12 +355,20 @@
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-TARGET %s
 // RUN: %clang --target=riscv64-unknown-elf -march=rv32i -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-TARGET %s
+// RUN: %clang --target=riscv32-unknown-elf -mcpu=generic-rv32 -### %s \
+// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-TARGET %s
+// RUN: %clang --target=riscv64-unknown-elf -mcpu=generic-rv32 -### %s \
+// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-TARGET %s
 // RV32-TARGET: "-triple" "riscv32-unknown-unknown-elf"
 
 // RUN: %clang --target=riscv32-unknown-elf -march=rv64i -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV64-TARGET %s
 // RUN: %clang --target=riscv64-unknown-elf -march=rv64i -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV64-TARGET %s
+// RUN: %clang --target=riscv32-unknown-elf -mcpu=generic-rv64 -### %s \
+// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV64-TARGET %s
+// RUN: %clang --target=riscv64-unknown-elf -mcpu=generic-rv64 -### %s \
+// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV64-TARGET %s
 // RV64-TARGET: "-triple" "riscv64-unknown-unknown-elf"
 
 // RUN: %clang --target=riscv32-unknown-elf -march=rv32ifzfh01p0 -### %s \
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -12,6 +12,7 @@
 #include "ToolChains/AMDGPUOpenMP.h"
 #include "ToolChains/AVR.h"
 #include "ToolChains/Ananas.h"
+#include "ToolChains/Arch/RISCV.h"
 #include "ToolChains/BareMetal.h"
 #include "ToolChains/CSKYToolChain.h"
 #include "ToolChains/Clang.h"
@@ -689,8 +690,9 @@
   // If target is RISC-V adjust the target triple according to
   // provided architecture name
   if (Target.isRISCV()) {
-if ((A = Args.getLastArg(options::OPT_march_EQ))) {
-  StringRef ArchName = A->getValue();
+if (Args.hasArg(options::OPT_march_EQ) ||
+Args.hasArg(options::OPT_mcpu_EQ)) {
+  StringRef ArchName = tools::riscv::getRISCVArch(Args, Target);
   if (ArchName.startswith_insensitive("rv32"))
 Target.setArch(llvm::Triple::riscv32);
   else if (ArchName.startswith_insensitive("rv64"))


Index: clang/test/Driver/riscv-cpus.c
===
--- clang/test/Driver/riscv-cpus.c
+++ clang/test/Driver/riscv-cpus.c
@@ -174,6 +174,3 @@
 
 // RUN: %clang --target=riscv32 -### -c %s 2>&1 -mcpu=generic-rv32 -march=rv64i | FileCheck -check-prefix=MISMATCH-ARCH %s
 // MISMATCH-ARCH: cpu 'generic-rv32' does not support rv64
-
-// RUN: %clang --target=riscv32 -### -c %s 2>&1 -mcpu=generic-rv64 | FileCheck -check-prefix=MISMATCH-MCPU %s
-// MISMATCH-MCPU: error: cpu 'generic-rv64' does not support rv32
Index: clang/test/Driver/riscv-arch.c
===
--- clang/test/Driver/riscv-arch.c
+++ clang/test/Driver/riscv-arch.c
@@ -355,12 +355,20 @@
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-TARGET %s
 // RUN: %clang --target=riscv64-unknown-elf -march=rv32i -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-TARGET %s
+// RUN: %clang --target=riscv32-unknown-elf -mcpu=generic-rv32 -### %s \
+// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-TARGET %s
+// RUN: %clang --target=riscv64-unknown-elf -mcpu=generic-rv32 -### %s \
+// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-TARGET %s
 // RV32-TARGET: "-triple" "riscv32-unknown-unknown-elf"
 
 // RUN: %clang --target=riscv32-unknown-elf -march=rv64i -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV64-TARGET %s
 // RUN: %clang --target=riscv64-unknown-elf -march=rv64i -### %s \
 // RUN: -fsyntax-only 

[clang] da4fcb0 - [RISCV][Driver] Allow the use of CPUs with a different XLEN than the triple.

2023-04-27 Thread Kito Cheng via cfe-commits

Author: Kito Cheng
Date: 2023-04-27T14:46:01+08:00
New Revision: da4fcb0c0b281746067f92d8804c18dbce4269bd

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

LOG: [RISCV][Driver] Allow the use of CPUs with a different XLEN than the 
triple.

Our downstream toolchain release got some issue is we set the default
triple by creating symbolic link of clang like `riscv64-unknown-elf-clang`,
and has lots of multi-lib config including rv32's config.

However when we trying to set arch by a 32 bit CPU like generic-rv32
but got error message below:
error: unsupported argument 'generic-rv32' to option '-mcpu='

`generic-rv32` is listed in the output of `-mcpu=help`, that
might be confusing for user since help message say supported.

So let clang driver also consider -mcpu option during computing
the target triple to archvie that.

Reviewed By: asb, craig.topper

Differential Revision: https://reviews.llvm.org/D148124

Added: 


Modified: 
clang/lib/Driver/Driver.cpp
clang/test/Driver/riscv-arch.c
clang/test/Driver/riscv-cpus.c

Removed: 




diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 4c8a83e6ff28a..509191762f8b4 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -12,6 +12,7 @@
 #include "ToolChains/AMDGPUOpenMP.h"
 #include "ToolChains/AVR.h"
 #include "ToolChains/Ananas.h"
+#include "ToolChains/Arch/RISCV.h"
 #include "ToolChains/BareMetal.h"
 #include "ToolChains/CSKYToolChain.h"
 #include "ToolChains/Clang.h"
@@ -689,8 +690,9 @@ static llvm::Triple computeTargetTriple(const Driver ,
   // If target is RISC-V adjust the target triple according to
   // provided architecture name
   if (Target.isRISCV()) {
-if ((A = Args.getLastArg(options::OPT_march_EQ))) {
-  StringRef ArchName = A->getValue();
+if (Args.hasArg(options::OPT_march_EQ) ||
+Args.hasArg(options::OPT_mcpu_EQ)) {
+  StringRef ArchName = tools::riscv::getRISCVArch(Args, Target);
   if (ArchName.startswith_insensitive("rv32"))
 Target.setArch(llvm::Triple::riscv32);
   else if (ArchName.startswith_insensitive("rv64"))

diff  --git a/clang/test/Driver/riscv-arch.c b/clang/test/Driver/riscv-arch.c
index 4d11db2a5e09a..5b9a45deb06a2 100644
--- a/clang/test/Driver/riscv-arch.c
+++ b/clang/test/Driver/riscv-arch.c
@@ -355,12 +355,20 @@
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-TARGET %s
 // RUN: %clang --target=riscv64-unknown-elf -march=rv32i -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-TARGET %s
+// RUN: %clang --target=riscv32-unknown-elf -mcpu=generic-rv32 -### %s \
+// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-TARGET %s
+// RUN: %clang --target=riscv64-unknown-elf -mcpu=generic-rv32 -### %s \
+// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-TARGET %s
 // RV32-TARGET: "-triple" "riscv32-unknown-unknown-elf"
 
 // RUN: %clang --target=riscv32-unknown-elf -march=rv64i -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV64-TARGET %s
 // RUN: %clang --target=riscv64-unknown-elf -march=rv64i -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV64-TARGET %s
+// RUN: %clang --target=riscv32-unknown-elf -mcpu=generic-rv64 -### %s \
+// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV64-TARGET %s
+// RUN: %clang --target=riscv64-unknown-elf -mcpu=generic-rv64 -### %s \
+// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV64-TARGET %s
 // RV64-TARGET: "-triple" "riscv64-unknown-unknown-elf"
 
 // RUN: %clang --target=riscv32-unknown-elf -march=rv32ifzfh01p0 -### %s \

diff  --git a/clang/test/Driver/riscv-cpus.c b/clang/test/Driver/riscv-cpus.c
index b107d89773e1c..76325311668d8 100644
--- a/clang/test/Driver/riscv-cpus.c
+++ b/clang/test/Driver/riscv-cpus.c
@@ -174,6 +174,3 @@
 
 // RUN: %clang --target=riscv32 -### -c %s 2>&1 -mcpu=generic-rv32 
-march=rv64i | FileCheck -check-prefix=MISMATCH-ARCH %s
 // MISMATCH-ARCH: cpu 'generic-rv32' does not support rv64
-
-// RUN: %clang --target=riscv32 -### -c %s 2>&1 -mcpu=generic-rv64 | FileCheck 
-check-prefix=MISMATCH-MCPU %s
-// MISMATCH-MCPU: error: cpu 'generic-rv64' does not support rv32



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


[PATCH] D148601: [Clang] Handle Error message to output proper Prefix

2023-04-27 Thread Usman Akinyemi via Phabricator via cfe-commits
Unique_Usman added a comment.

Thanks @tbaeder, I really appreciate your time.

Name is Unique_Usman and my email is usmanakinyemi...@gmail.com

As you mentioned, if anyone later chime in, I will be glad to update the issue 
back. 
Thank you.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148601/new/

https://reviews.llvm.org/D148601

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


[PATCH] D149160: [clang][analyzer] Handle special value AT_FDCWD in affected standard functions

2023-04-27 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 517457.
balazske added a comment.

added special argument condition function to remove code repetition


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149160/new/

https://reviews.llvm.org/D149160

Files:
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
  clang/test/Analysis/std-c-library-functions-arg-constraints.c

Index: clang/test/Analysis/std-c-library-functions-arg-constraints.c
===
--- clang/test/Analysis/std-c-library-functions-arg-constraints.c
+++ clang/test/Analysis/std-c-library-functions-arg-constraints.c
@@ -3,6 +3,7 @@
 // RUN:   -analyzer-checker=core \
 // RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctions \
 // RUN:   -analyzer-checker=alpha.unix.StdCLibraryFunctionArgs \
+// RUN:   -analyzer-config apiModeling.StdCLibraryFunctions:ModelPOSIX=true \
 // RUN:   -analyzer-checker=debug.StdCLibraryFunctionsTester \
 // RUN:   -analyzer-checker=debug.ExprInspection \
 // RUN:   -triple x86_64-unknown-linux-gnu \
@@ -13,6 +14,7 @@
 // RUN:   -analyzer-checker=core \
 // RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctions \
 // RUN:   -analyzer-checker=alpha.unix.StdCLibraryFunctionArgs \
+// RUN:   -analyzer-config apiModeling.StdCLibraryFunctions:ModelPOSIX=true \
 // RUN:   -analyzer-checker=debug.StdCLibraryFunctionsTester \
 // RUN:   -analyzer-checker=debug.ExprInspection \
 // RUN:   -triple x86_64-unknown-linux-gnu \
@@ -309,3 +311,26 @@
   // bugpath-warning{{The 1st argument to '__buf_size_arg_constraint_concrete' is out of the accepted range; It should be a buffer with size equal to or greater than 10}} \
   // bugpath-note{{The 1st argument to '__buf_size_arg_constraint_concrete' is out of the accepted range; It should be a buffer with size equal to or greater than 10}}
 }
+
+void test_file_fd_at_functions() {
+  (void)linkat(-22, "from", AT_FDCWD, "to", 0); // \
+  // report-warning{{The 1st argument to 'linkat' is -22 but should be -101 or >= 0}} \
+  // bugpath-warning{{The 1st argument to 'linkat' is -22 but should be -101 or >= 0}} \
+  // bugpath-note{{The 1st argument to 'linkat' is -22 but should be -101 or >= 0}}
+
+  // no warning for these functions if the AT_FDCWD value is used
+  (void)linkat(AT_FDCWD, "from", AT_FDCWD, "to", 0);
+  (void)faccessat(AT_FDCWD, "path", 0, 0);
+  (void)symlinkat("oldpath", AT_FDCWD, "newpath");
+  (void)mkdirat(AT_FDCWD, "path", 0);
+  (void)mknodat(AT_FDCWD, "path", 0, 0);
+  (void)fchmodat(AT_FDCWD, "path", 0, 0);
+  (void)fchownat(AT_FDCWD, "path", 0, 0, 0);
+  (void)linkat(AT_FDCWD, "oldpath", AT_FDCWD, "newpath", 0);
+  (void)unlinkat(AT_FDCWD, "newpath", 0);
+  struct stat St;
+  (void)fstatat(AT_FDCWD, "newpath", , 0);
+  char Buf[10];
+  (void)readlinkat(AT_FDCWD, "newpath", Buf, 10);
+  (void)renameat(AT_FDCWD, "oldpath", AT_FDCWD, "newpath");
+}
Index: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -1527,14 +1527,18 @@
   const RangeInt UCharRangeMax =
   std::min(BVF.getMaxValue(ACtx.UnsignedCharTy).getLimitedValue(), IntMax);
 
-  // The platform dependent value of EOF.
-  // Try our best to parse this from the Preprocessor, otherwise fallback to -1.
-  const auto EOFv = []() -> RangeInt {
+  // Get platform dependent values of some macros.
+  // Try our best to parse this from the Preprocessor, otherwise fallback to a
+  // default value (what is found in a library header).
+  auto GetMacroValue = [](const char *Name, int Default) -> RangeInt {
 if (const std::optional OptInt =
-tryExpandAsInteger("EOF", C.getPreprocessor()))
+tryExpandAsInteger(Name, C.getPreprocessor()))
   return *OptInt;
-return -1;
-  }();
+return Default;
+  };
+
+  const auto EOFv = GetMacroValue("EOF", -1);
+  const auto AT_FDCWDv = GetMacroValue("AT_FDCWD", -100);
 
   // Auxiliary class to aid adding summaries to the summary map.
   struct AddToFunctionSummaryMap {
@@ -1979,6 +1983,11 @@
 ConstraintSet{ReturnValueCondition(WithinRange, Range(-1, IntMax))};
 const auto  = ReturnsNonnegative;
 
+auto ValidFileDescriptorOrAtFdcwd = [&](ArgNo ArgN) {
+  return std::make_shared(
+  ArgN, WithinRange, Range({AT_FDCWDv, AT_FDCWDv}, {0, IntMax}), "");
+};
+
 // FILE *fopen(const char *restrict pathname, const char *restrict mode);
 addToFunctionSummaryMap(
 "fopen",
@@ -2130,6 +2139,7 @@
 Summary(NoEvalCall)
 .Case(ReturnsZero, ErrnoMustNotBeChecked)
 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant)
+.ArgConstraint(ValidFileDescriptorOrAtFdcwd(ArgNo(0)))
 .ArgConstraint(NotNull(ArgNo(1;
 
 // int dup(int 

[clang] 7c30d30 - [clang] Modernize DelayedDiagnostics (NFC)

2023-04-27 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2023-04-26T23:29:03-07:00
New Revision: 7c30d3028b2cc0bea7858f995f9bb4024ad1d7d0

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

LOG: [clang] Modernize DelayedDiagnostics (NFC)

Added: 


Modified: 
clang/include/clang/Sema/Sema.h

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 0b324bc54c32e..a25dfb7434cf0 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -946,10 +946,10 @@ class Sema final {
   class DelayedDiagnostics {
 /// The current pool of diagnostics into which delayed
 /// diagnostics should go.
-sema::DelayedDiagnosticPool *CurPool;
+sema::DelayedDiagnosticPool *CurPool = nullptr;
 
   public:
-DelayedDiagnostics() : CurPool(nullptr) {}
+DelayedDiagnostics() = default;
 
 /// Adds a delayed diagnostic.
 void add(const sema::DelayedDiagnostic ); // in DelayedDiagnostic.h



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


[PATCH] D149280: [clang-tidy] Add modernize-printf-to-std-print check

2023-04-27 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

It may be a good idea to create unittests for the formatconverter in 
`clang-tools-extra/unittests/clang-tidy/`

Can this check be renamed to just `modernize-use-std-print`. This sticks with 
the convention of other modernize names and potentially in the future allows us 
to convert ostream operations to use `std::print`




Comment at: clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp:322
+  if (!isRealCharType(Pointee))
+ArgFixes.emplace_back(Arg, "reinterpret_cast(");
+}

By default this check should not do this conversion, we shouldn't be creating 
UB in fixes emitted by clang-tidy unless the user explicitly opts in.
Maybe a good framework moving forward is to still a warning about converting up 
std::print, but emit a note here saying why the automatic conversation isn't 
possible.



Comment at: clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp:412
+else
+  ArgFixes.emplace_back(Arg, "reinterpret_cast(");
+break;

`reinterpret_cast` is not needed here, a static cast to`const void*` will work.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/modernize/printf-to-std-print.rst:61
+- any arguments where the format string and the parameter differ in
+  signedness will be wrapped in an approprate ``static_cast``. For example,
+  given ``int i = 42``, then ``printf("%u\n", i)`` will become

Perhaps these conversions should only be done in StrictMode



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/modernize/printf-to-std-print.rst:92
+
+It is helpful to use the `readability-redundant-string-cstr
+<../readability/redundant-string-cstr.html>` check after this check to

It may be wise in a future version to just do that conversion anyway. 2 stage 
fixes are annoying for users to have to use 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149280/new/

https://reviews.llvm.org/D149280

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


[clang] aba32ab - [C++20] [Modules] Avoid crash if the inconsistency the size of lang options exceeds 1

2023-04-27 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2023-04-27T14:20:59+08:00
New Revision: aba32abe2d93133a46f67764937a1c85d455dce8

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

LOG: [C++20] [Modules] Avoid crash if the inconsistency the size of lang 
options exceeds 1

Close https://github.com/llvm/llvm-project/issues/62359

The root reason for the crash is that we didn't test the case that
the bits number of a language option exceeds 1.

Added: 
clang/test/Modules/pr62359.cppm

Modified: 
clang/lib/Lex/Lexer.cpp
clang/lib/Serialization/ASTReader.cpp

Removed: 




diff  --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index bc97ca18a2ebd..53cd43d63ea02 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -4361,11 +4361,9 @@ bool Lexer::LexTokenInternal(Token , bool 
TokAtPhysicalStartOfLine) {
   FormTokenWithChars(Result, CurPtr, tok::hash);
   PP->HandleDirective(Result);
 
-  if (PP->hadModuleLoaderFatalFailure()) {
+  if (PP->hadModuleLoaderFatalFailure())
 // With a fatal failure in the module loader, we abort parsing.
-assert(Result.is(tok::eof) && "Preprocessor did not set tok:eof");
 return true;
-  }
 
   // We parsed the directive; lex a token with the new state.
   return false;

diff  --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index 723dd99ffada2..6a7bc22d3b7b3 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -277,12 +277,17 @@ static bool checkLanguageOptions(const LangOptions 
,
  const LangOptions ,
  DiagnosticsEngine *Diags,
  bool AllowCompatibleDifferences = true) {
-#define LANGOPT(Name, Bits, Default, Description) \
-  if (ExistingLangOpts.Name != LangOpts.Name) {   \
-if (Diags)\
-  Diags->Report(diag::err_pch_langopt_mismatch)   \
-<< Description << LangOpts.Name << ExistingLangOpts.Name; \
-return true;  \
+#define LANGOPT(Name, Bits, Default, Description)   \
+  if (ExistingLangOpts.Name != LangOpts.Name) { \
+if (Diags) {\
+  if (Bits == 1)\
+Diags->Report(diag::err_pch_langopt_mismatch)   \
+  << Description << LangOpts.Name << ExistingLangOpts.Name; \
+  else  \
+Diags->Report(diag::err_pch_langopt_value_mismatch) \
+  << Description;   \
+}   \
+return true;\
   }
 
 #define VALUE_LANGOPT(Name, Bits, Default, Description)   \

diff  --git a/clang/test/Modules/pr62359.cppm b/clang/test/Modules/pr62359.cppm
new file mode 100644
index 0..4632457e57f18
--- /dev/null
+++ b/clang/test/Modules/pr62359.cppm
@@ -0,0 +1,43 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/Hello.cppm -o 
%t/Hello.pcm
+// RUN: not %clang_cc1 -std=c++20 -fopenmp %t/use.cpp 
-fmodule-file=hello=%t/Hello.pcm -fsyntax-only \
+// RUN: 2>&1 | FileCheck %t/use.cpp
+// RUN: not %clang_cc1 -std=c++20 -fopenmp %t/use2.cpp 
-fmodule-file=hello=%t/Hello.pcm -fsyntax-only \
+// RUN: 2>&1 | FileCheck %t/use2.cpp
+//
+// RUN: %clang_cc1 -std=c++20 -fopenmp -emit-module-interface %t/Hello.cppm -o 
%t/Hello.pcm
+// RUN: %clang_cc1 -std=c++20 -fopenmp %t/use.cpp 
-fmodule-file=hello=%t/Hello.pcm -fsyntax-only -verify
+// RUN: %clang_cc1 -std=c++20 -fopenmp %t/use2.cpp 
-fmodule-file=hello=%t/Hello.pcm -fsyntax-only -verify
+
+//--- Hello.cppm
+export module hello;
+export void hello() {
+  
+}
+
+//--- use.cpp
+// expected-no-diagnostics
+import hello;
+int use() {
+  for(int i=0;i<10;i++)
+hello();
+  return 0;
+}
+
+// CHECK: OpenMP{{.*}}
diff ers in PCH file vs. current file
+
+//--- use2.cpp
+// expected-no-diagnostics
+import hello;
+int use2() {
+#pragma omp parallel for
+  for(int i=0;i<10;i++)
+hello();
+  return 0;
+}
+
+// CHECK: OpenMP{{.*}}
diff ers in PCH file vs. current file
+// CHECK: use of undeclared identifier 'pragma'



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


[PATCH] D125272: [clang] Add -fcheck-new support

2023-04-27 Thread Pedro Falcato via Phabricator via cfe-commits
heatd added inline comments.



Comment at: clang/test/CodeGenCXX/fcheck-new.cpp:2
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -fcheck-new -triple x86_64-linux-gnu -S -disable-O0-optnone 
\
+// RUN: -emit-llvm -o - %s | opt -S -passes=mem2reg | FileCheck %s

MaskRay wrote:
> In this test, if I remove `-fcheck-new` , nothing will change. So this isn't 
> a good test.
> 
> I think we need something like:
> ```
> struct A { A(); };
> void *test0() { return A; }
> ```
It will change (the attributes of _Znwm).

From the test (with -fcheck-new):
```
[[CALL:%.*]] = call noalias noundef ptr @_Znwm(i64 noundef 4) #[[ATTR2:[0-9]+]]
```
The same test (but without -fcheck-new, tested locally):

```
  %1 = tail call noalias noundef nonnull dereferenceable(4) ptr @_Znwm(i64 
noundef 4) #2
```

As you'll see, the non-fcheck-new has nonnull attached to _Znwm, while 
-fcheck-new doesn't. This is exactly the behavior we want to test for.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D125272/new/

https://reviews.llvm.org/D125272

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


<    1   2