[clang] 4f37de9 - [clang-format][doc] Fix a typo

2023-02-03 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2023-02-03T00:24:54-08:00
New Revision: 4f37de9c91eb0674c3f218c5b585780bd7072593

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

LOG: [clang-format][doc] Fix a typo

Added: 


Modified: 
clang/docs/ClangFormatStyleOptions.rst

Removed: 




diff  --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 8f5bb78b90bbb..ea4fe179eddce 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -115,7 +115,7 @@ delimited range. The code between a comment ``// 
clang-format off`` or
 ``/* clang-format off */`` up to a comment ``// clang-format on`` or
 ``/* clang-format on */`` will not be formatted. The comments themselves will 
be
 formatted (aligned) normally. Also, a colon (``:``) and additional text may
-follow ``// clang-format off`` or `` clang-format on`` to explain why
+follow ``// clang-format off`` or ``// clang-format on`` to explain why
 clang-format is turned off or back on.
 
 .. code-block:: c++



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


[PATCH] D79378: PR34581: Don't remove an 'if (p)' guarding a call to 'operator delete(p)' under -Oz.

2023-02-03 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

In D79378#4101613 , @shiva0217 wrote:

> Hi,
>
> I have a question for the delete function call sinking in -Oz.
>
> https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3690.pdf.
> According to 3.7.4.2/3
> ` The value of the first argument supplied to a deallocation function may be 
> a null pointer value; if so, and if the deallocation function is one supplied 
> in the standard library, the call has no effect. Otherwise, the behavior is 
> undefined`
>
> It seems the null checking can be skipped only when the delete is not from 
> the standard library(have been overloaded by the user), isn't it?

The paragraph you just quoted says that the deallocation functions provided by 
the standard library are required have no effect on null pointers.  That means 
it's fine to call them with a null pointer even if the source wouldn't normally 
execute that call.  We could just insert these calls into random other code if 
we wanted to.

As discussed in the original review, removing null checks around calls to 
`operator delete` is rarely going to be a good code-speed optimization, but it 
is a good code-size optimization, and `-Oz` in Clang is a request to minimize 
code size even if it makes the code slower.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79378

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


[PATCH] D140290: [clang-tidy] Add misc-static-declaration-in-header check

2023-02-03 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

Friendly ping. I realized @aaron.ballman you probably have very good insights 
into this use case, since (AFAICT) you wrote a guideline about anonymous 
namespaces in headers, which is very closely related to this:
https://wiki.sei.cmu.edu/confluence/display/cplusplus/DCL59-CPP.+Do+not+define+an+unnamed+namespace+in+a+header+file

Would appreciate your feedback!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140290

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


[PATCH] D137070: [clang][Interp] Support destructors

2023-02-03 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder marked an inline comment as done.
tbaeder added inline comments.



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:1915-1916
+
+if (const CXXDestructorDecl *Dtor = ElemRecord->getDestructor();
+Dtor && !Dtor->isTrivial()) {
+  for (size_t I = 0, E = Desc->getNumElems(); I != E; ++I) {

aaron.ballman wrote:
> tbaeder wrote:
> > aaron.ballman wrote:
> > > `isTrivial()` only works once the class has been fully built up by Sema 
> > > IIRC; we should have a test case for that situation.
> > Are you saying that `isTrivial()` cannot be used like this, or just that it 
> > can, but needs a test case to ensure that this is true?
> > 
> > Also, how would such a test case look like?
> `Sema::DeclareImplicitDestructor()` decides whether the destructor is trivial 
> or not, and that is based on information that the class collects as the class 
> is being declared. While the class is being parsed, the `DeclarationData` for 
> the class is updated as we go and we use that to decide if we need the 
> destructor, whether it's trivial, etc. So it's possible for us to have not 
> seen a part of the class yet that would cause the special member function to 
> be (non)trivial and so asking the method "are you trivial" may give a 
> different answer depending on when the question is asked.
> 
> In terms of a test case, I think it would be trying to hit one of these cases 
> http://eel.is/c++draft/class.mem#class.dtor-8 by using a constexpr function 
> that needs to be evaluated before we get to something that causes the dtor to 
> no longer be trivial.
Hm, I can't come up with a reproducer for this. The class of a member variable 
must be fully defined when the member is declared, so I can't forward-declare 
it and then introduce a non-trivial destructor later. And as soon as I add a 
destructor declaration (and try to define i later), the destructor is 
automatically not trivial anymore.


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

https://reviews.llvm.org/D137070

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


[PATCH] D141591: [clang][Interp] Properly identify not-yet-defined functions

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



Comment at: clang/test/AST/Interp/functions.cpp:158-174
+struct F {
+  constexpr bool ok() const {
+return okRecurse();
+  }
+  constexpr bool okRecurse() const {
+return true;
+  }

aaron.ballman wrote:
> Should we have some similar tests involving free functions as well?
> 
> Also, how does `BodylessMemberFunction` differ from `F`? They both look to be 
> testing the same thing aside from return types.
> 
> Should we have a test that involves a defaulted special member function that 
> is called explicitly? e.g., https://godbolt.org/z/nzjEcPMKG (Clang is correct 
> here, GCC fails to catch the UB).
We have a test for free-standing functions already higher up:

```
constexpr int f(); // expected-note {{declared here}} \
   // ref-note {{declared here}}
[...]
constexpr int a() {
  return f();
}
constexpr int f() {
  return 5;
}
static_assert(a() == 5, "");
```

I //think// the two used to test something different, but now they test the 
same thing, yes. I'll remove one of them.

> Should we have a test that involves a defaulted special member function that 
> is called explicitly? e.g., https://godbolt.org/z/nzjEcPMKG (Clang is correct 
> here, GCC fails to catch the UB).

That is also caught but the diagnostics are in the wrong place (and slightly 
different. The old interpreter emits "destruction of dereferenced null pointer" 
while the new one does "member call on dereferenced null pointer").


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

https://reviews.llvm.org/D141591

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


[PATCH] D79378: PR34581: Don't remove an 'if (p)' guarding a call to 'operator delete(p)' under -Oz.

2023-02-03 Thread Shiva Chen via Phabricator via cfe-commits
shiva0217 added a comment.

In D79378#4101829 , @rjmccall wrote:

> In D79378#4101613 , @shiva0217 wrote:
>
>> Hi,
>>
>> I have a question for the delete function call sinking in -Oz.
>>
>> https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3690.pdf.
>> According to 3.7.4.2/3
>> ` The value of the first argument supplied to a deallocation function may be 
>> a null pointer value; if so, and if the deallocation function is one 
>> supplied in the standard library, the call has no effect. Otherwise, the 
>> behavior is undefined`
>>
>> It seems the null checking can be skipped only when the delete is not from 
>> the standard library(have been overloaded by the user), isn't it?
>
> The paragraph you just quoted says that the deallocation functions provided 
> by the standard library are required have no effect on null pointers.  That 
> means it's fine to call them with a null pointer even if the source wouldn't 
> normally execute that call.  We could just insert these calls into random 
> other code if we wanted to.

Is a null operand of delete in the source code no effect because there will be 
null pointer checking generated?  Or the delete(null) in assembly code also 
valid?

> As discussed in the original review, removing null checks around calls to 
> `operator delete` is rarely going to be a good code-speed optimization, but 
> it is a good code-size optimization, and `-Oz` in Clang is a request to 
> minimize code size even if it makes the code slower.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79378

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


[clang] 450a461 - [Clang] Add builtin_nondeterministic_value

2023-02-03 Thread via cfe-commits

Author: ManuelJBrito
Date: 2023-02-03T09:47:46Z
New Revision: 450a4612c39cc150879a0f0e692adfc1d0d9

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

LOG: [Clang] Add builtin_nondeterministic_value

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

Added: 
clang/test/CodeGen/builtins-nondeterministic-value.c

Modified: 
clang/docs/LanguageExtensions.rst
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/Builtins.def
clang/include/clang/Sema/Sema.h
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/Sema/SemaChecking.cpp

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 90e7943510608..9d5a4d78e8040 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -3081,6 +3081,32 @@ Query for this feature with 
``__has_builtin(__builtin_debugtrap)``.
 
 Query for this feature with ``__has_builtin(__builtin_trap)``.
 
+``__builtin_nondeterministic_value``
+
+
+``__builtin_nondeterministic_value`` returns a valid nondeterministic value of 
the same type as the provided argument.
+
+**Syntax**:
+
+.. code-block:: c++
+
+type __builtin_nondeterministic_value(type x)
+
+**Examples**:
+
+.. code-block:: c++
+
+int x = __builtin_nondeterministic_value(x);
+float y = __builtin_nondeterministic_value(y);
+__m256i a = __builtin_nondeterministic_value(a);
+
+**Description**
+
+Each call to ``__builtin_nondeterministic_value`` returns a valid value of the 
type given by the argument.
+
+The types currently supported are: integer types, floating-point types, vector 
types.
+
+Query for this feature with 
``__has_builtin(__builtin_nondeterministic_value)``.
 
 ``__builtin_sycl_unique_stable_name``
 -

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c7b084ef8e29c..d2f1919f24a33 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -79,6 +79,8 @@ Non-comprehensive list of changes in this release
 - Clang now saves the address of ABI-indirect function parameters on the stack,
   improving the debug information available in programs compiled without
   optimizations.
+- Clang now supports ``__builtin_nondeterministic_value`` that returns a
+  nondeterministic value of the same type as the provided argument.
 
 New Compiler Flags
 --

diff  --git a/clang/include/clang/Basic/Builtins.def 
b/clang/include/clang/Basic/Builtins.def
index 07e0a2d7748c5..2d25a030fd682 100644
--- a/clang/include/clang/Basic/Builtins.def
+++ b/clang/include/clang/Basic/Builtins.def
@@ -655,6 +655,7 @@ BUILTIN(__builtin_alloca_uninitialized, "v*z", "Fn")
 BUILTIN(__builtin_alloca_with_align, "v*zIz", "Fn")
 BUILTIN(__builtin_alloca_with_align_uninitialized, "v*zIz", "Fn")
 BUILTIN(__builtin_call_with_static_chain, "v.", "nt")
+BUILTIN(__builtin_nondeterministic_value, "v.", "nt")
 
 BUILTIN(__builtin_elementwise_abs, "v.", "nct")
 BUILTIN(__builtin_elementwise_max, "v.", "nct")

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 741c2503127af..67d55ab3d8c6d 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -13571,6 +13571,8 @@ class Sema final {
   bool PrepareBuiltinElementwiseMathOneArgCall(CallExpr *TheCall);
   bool PrepareBuiltinReduceMathOneArgCall(CallExpr *TheCall);
 
+  bool SemaBuiltinNonDeterministicValue(CallExpr *TheCall);
+
   // Matrix builtin handling.
   ExprResult SemaBuiltinMatrixTranspose(CallExpr *TheCall,
 ExprResult CallResult);

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 8f733d7d14c6e..aefbc731f8738 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3060,6 +3060,15 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 return RValue::get(V);
   }
 
+  case Builtin::BI__builtin_nondeterministic_value: {
+llvm::Type *Ty = ConvertType(E->getArg(0)->getType());
+
+Value *Result = PoisonValue::get(Ty);
+Result = Builder.CreateFreeze(Result);
+
+return RValue::get(Result);
+  }
+
   case Builtin::BI__builtin_elementwise_abs: {
 Value *Result;
 QualType QT = E->getArg(0)->getType();

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index f1c4aabadef5f..efba0a8871c6c 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -2584,6 +2584,12 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, 
unsigned BuiltinID,
 break;
   }
 
+  case Builtin::BI__builtin_nondeterministic_value: {
+if (SemaBuiltinNonDeterministicValue(TheCall))
+  ret

[PATCH] D142388: [clang] Add builtin_nondeterministic_value

2023-02-03 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 rG450a4612c39c: [Clang] Add builtin_nondeterministic_value 
(authored by ManuelJBrito).

Changed prior to commit:
  https://reviews.llvm.org/D142388?vs=494338&id=494552#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142388

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/Builtins.def
  clang/include/clang/Sema/Sema.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtins-nondeterministic-value.c

Index: clang/test/CodeGen/builtins-nondeterministic-value.c
===
--- /dev/null
+++ clang/test/CodeGen/builtins-nondeterministic-value.c
@@ -0,0 +1,60 @@
+// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s
+
+typedef float float4 __attribute__((ext_vector_type(4)));
+typedef _Bool bool4 __attribute__((ext_vector_type(4)));
+
+int clang_nondet_i( int x ) {
+// CHECK-LABEL: entry
+// CHECK: [[A:%.*]] = alloca i32, align 4
+// CHECK: store i32 [[X:%.*]], ptr [[A]], align 4
+// CHECK: [[R:%.*]] = freeze i32 poison
+// CHECK: ret i32 [[R]]
+  return __builtin_nondeterministic_value(x);
+}
+
+float clang_nondet_f( float x ) {
+// CHECK-LABEL: entry
+// CHECK: [[A:%.*]] = alloca float, align 4
+// CHECK: store float [[X:%.*]], ptr [[A]], align 4
+// CHECK: [[R:%.*]] = freeze float poison
+// CHECK: ret float [[R]]
+  return __builtin_nondeterministic_value(x);
+}
+
+double clang_nondet_d( double x ) {
+// CHECK-LABEL: entry
+// CHECK: [[A:%.*]] = alloca double, align 8
+// CHECK: store double [[X:%.*]], ptr [[A]], align 8
+// CHECK: [[R:%.*]] = freeze double poison
+// CHECK: ret double [[R]]
+  return __builtin_nondeterministic_value(x);
+}
+
+_Bool clang_nondet_b( _Bool x) {
+// CHECK-LABEL: entry
+// CHECK: [[A:%.*]] = alloca i8, align 1
+// CHECK: [[B:%.*]] = zext i1 %x to i8
+// CHECK: store i8 [[B]], ptr [[A]], align 1
+// CHECK: [[R:%.*]] = freeze i1 poison
+// CHECK: ret i1 [[R]]
+  return __builtin_nondeterministic_value(x);
+}
+
+void clang_nondet_fv( ) {
+// CHECK-LABEL: entry
+// CHECK: [[A:%.*]] = alloca <4 x float>, align 16
+// CHECK: [[R:%.*]] = freeze <4 x float> poison
+// CHECK: store <4 x float> [[R]], ptr [[A]], align 16
+// CHECK: ret void
+  float4 x = __builtin_nondeterministic_value(x);
+}
+
+void clang_nondet_bv( ) {
+// CHECK: [[A:%.*]] = alloca i8, align 1
+// CHECK: [[V:%.*]] = freeze <4 x i1> poison
+// CHECK: [[SV:%.*]] = shufflevector <4 x i1> [[V]], <4 x i1> poison, <8 x i32> 
+// CHECK: [[BC:%.*]] = bitcast <8 x i1> [[SV]] to i8
+// CHECK: store i8 [[BC]], ptr [[A]], align 1
+// CHECK: ret void
+  bool4 x = __builtin_nondeterministic_value(x);
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -2584,6 +2584,12 @@
 break;
   }
 
+  case Builtin::BI__builtin_nondeterministic_value: {
+if (SemaBuiltinNonDeterministicValue(TheCall))
+  return ExprError();
+break;
+  }
+
   // __builtin_elementwise_abs restricts the element type to signed integers or
   // floating point types only.
   case Builtin::BI__builtin_elementwise_abs: {
@@ -17858,6 +17864,21 @@
   return false;
 }
 
+bool Sema::SemaBuiltinNonDeterministicValue(CallExpr *TheCall) {
+  if (checkArgCount(*this, TheCall, 1))
+return true;
+
+  ExprResult Arg = TheCall->getArg(0);
+  QualType TyArg = Arg.get()->getType();
+
+  if (!TyArg->isBuiltinType() && !TyArg->isVectorType())
+return Diag(TheCall->getArg(0)->getBeginLoc(), diag::err_builtin_invalid_arg_type)
+   << 1 << /*vector, integer or floating point ty*/ 0 << TyArg;
+
+  TheCall->setType(TyArg);
+  return false;
+}
+
 ExprResult Sema::SemaBuiltinMatrixTranspose(CallExpr *TheCall,
 ExprResult CallResult) {
   if (checkArgCount(*this, TheCall, 1))
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -3060,6 +3060,15 @@
 return RValue::get(V);
   }
 
+  case Builtin::BI__builtin_nondeterministic_value: {
+llvm::Type *Ty = ConvertType(E->getArg(0)->getType());
+
+Value *Result = PoisonValue::get(Ty);
+Result = Builder.CreateFreeze(Result);
+
+return RValue::get(Result);
+  }
+
   case Builtin::BI__builtin_elementwise_abs: {
 Value *Result;
 QualType QT = E->getArg(0)->getType();
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -13571,6 +13571,8 @@
   bool PrepareBuiltinElementwiseMathOneArgCall(CallEx

[PATCH] D142467: [Tooling] Add stdlib::Symbol::all() and stdlib::Symbol::qualified_name()

2023-02-03 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp:18
 
 static llvm::StringRef *HeaderNames;
+static struct SymbolName {

nit: we group five symbols together, it is a bit hard to follow.

Can you move the HeaderNames just before the `HeaderIDs` and mention the value 
of the `HeaderIDs`  is the index of `HeaderNames`?



Comment at: clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp:108
+  std::vector Result;
+  Result.reserve(HeaderIDs->size());
+  for (unsigned I = 0, E = SymbolCount; I < E; ++I)

should be `SymbolCount`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142467

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


[PATCH] D143160: [include-mapping] Introduce a human-edit CXXSymbolMapping file

2023-02-03 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 494573.
hokein added a comment.

refine the patch: include multiple-header symbols.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143160

Files:
  clang/include/clang/Tooling/Inclusions/CXXSymbolMap.inc

Index: clang/include/clang/Tooling/Inclusions/CXXSymbolMap.inc
===
--- /dev/null
+++ clang/include/clang/Tooling/Inclusions/CXXSymbolMap.inc
@@ -0,0 +1,210 @@
+//===-- CXXSymbolMap.inc *- C++ -*-===//
+//
+// Unlike the generated StdSymbolMap.inc, this file contains a hand-cruted list
+// of symbols (which are hard to handle by the generator script). It intends
+// to overlay the StdSymbolMap.inc.
+//
+//===--===//
+
+// Symbols that can be provided by any of the headers, ordered by the header
+// preference.
+SYMBOL(consume_header, std::, ) // declared
+SYMBOL(consume_header, std::, )  // defined
+SYMBOL(generate_header, std::, )
+SYMBOL(generate_header, std::, )
+SYMBOL(little_endian, std::, )
+SYMBOL(little_endian, std::, )
+SYMBOL(mbstate_t, std::, )
+SYMBOL(mbstate_t, std::, )
+SYMBOL(size_t, std::, )
+SYMBOL(size_t, std::, )
+SYMBOL(size_t, std::, )
+SYMBOL(size_t, std::, )
+SYMBOL(size_t, std::, )
+SYMBOL(size_t, std::, )
+SYMBOL(size_t, std::, )
+// C++ [meta.trans.other 21.3.8.7]:
+// In addition to being available via inclusion of the  header,
+// the templates unwrap_­reference, unwrap_­ref_­decay, unwrap_­reference_­t,
+// and unwrap_­ref_­decay_­t are available when the header 
+// ([functional.syn]) is included.
+SYMBOL(unwrap_ref_decay, std::, )
+SYMBOL(unwrap_ref_decay, std::, )
+SYMBOL(unwrap_reference, std::, )
+SYMBOL(unwrap_reference, std::, )
+SYMBOL(unwrap_ref_decay_t, std::, )
+SYMBOL(unwrap_ref_decay_t, std::, )
+SYMBOL(wint_t, std::, )
+SYMBOL(wint_t, std::, )
+// C++ [iterator.range 25.7]: In addition to being available via inclusion of
+// the  header, the function templates in [iterator.range] are
+// available when any of the following headers are included: , ,
+// , ... and .
+SYMBOL(begin, std::, )
+SYMBOL(begin, std::, )
+SYMBOL(begin, std::, )
+SYMBOL(begin, std::, )
+SYMBOL(begin, std::, )
+SYMBOL(begin, std::, )
+SYMBOL(begin, std::, )
+SYMBOL(begin, std::, )
+SYMBOL(begin, std::, )
+SYMBOL(begin, std::, )
+SYMBOL(begin, std::, )
+SYMBOL(begin, std::, )
+SYMBOL(begin, std::, )
+SYMBOL(begin, std::, )
+SYMBOL(cbegin, std::, )
+SYMBOL(cbegin, std::, )
+SYMBOL(cbegin, std::, )
+SYMBOL(cbegin, std::, )
+SYMBOL(cbegin, std::, )
+SYMBOL(cbegin, std::, )
+SYMBOL(cbegin, std::, )
+SYMBOL(cbegin, std::, )
+SYMBOL(cbegin, std::, )
+SYMBOL(cbegin, std::, )
+SYMBOL(cbegin, std::, )
+SYMBOL(cbegin, std::, )
+SYMBOL(cbegin, std::, )
+SYMBOL(cbegin, std::, )
+SYMBOL(cend, std::, )
+SYMBOL(cend, std::, )
+SYMBOL(cend, std::, )
+SYMBOL(cend, std::, )
+SYMBOL(cend, std::, )
+SYMBOL(cend, std::, )
+SYMBOL(cend, std::, )
+SYMBOL(cend, std::, )
+SYMBOL(cend, std::, )
+SYMBOL(cend, std::, )
+SYMBOL(cend, std::, )
+SYMBOL(cend, std::, )
+SYMBOL(cend, std::, )
+SYMBOL(cend, std::, )
+SYMBOL(crbegin, std::, )
+SYMBOL(crbegin, std::, )
+SYMBOL(crbegin, std::, )
+SYMBOL(crbegin, std::, )
+SYMBOL(crbegin, std::, )
+SYMBOL(crbegin, std::, )
+SYMBOL(crbegin, std::, )
+SYMBOL(crbegin, std::, )
+SYMBOL(crbegin, std::, )
+SYMBOL(crbegin, std::, )
+SYMBOL(crbegin, std::, )
+SYMBOL(crbegin, std::, )
+SYMBOL(crbegin, std::, )
+SYMBOL(crbegin, std::, )
+SYMBOL(crend, std::, )
+SYMBOL(crend, std::, )
+SYMBOL(crend, std::, )
+SYMBOL(crend, std::, )
+SYMBOL(crend, std::, )
+SYMBOL(crend, std::, )
+SYMBOL(crend, std::, )
+SYMBOL(crend, std::, )
+SYMBOL(crend, std::, )
+SYMBOL(crend, std::, )
+SYMBOL(crend, std::, )
+SYMBOL(crend, std::, )
+SYMBOL(crend, std::, )
+SYMBOL(crend, std::, )
+SYMBOL(data, std::, )
+SYMBOL(data, std::, )
+SYMBOL(data, std::, )
+SYMBOL(data, std::, )
+SYMBOL(data, std::, )
+SYMBOL(data, std::, )
+SYMBOL(data, std::, )
+SYMBOL(data, std::, )
+SYMBOL(data, std::, )
+SYMBOL(data, std::, )
+SYMBOL(data, std::, )
+SYMBOL(data, std::, )
+SYMBOL(data, std::, )
+SYMBOL(data, std::, )
+SYMBOL(empty, std::, )
+SYMBOL(empty, std::, )
+SYMBOL(empty, std::, )
+SYMBOL(empty, std::, )
+SYMBOL(empty, std::, )
+SYMBOL(empty, std::, )
+SYMBOL(empty, std::, )
+SYMBOL(empty, std::, )
+SYMBOL(empty, std::, )
+SYMBOL(empty, std::, )
+SYMBOL(empty, std::, )
+SYMBOL(empty, std::, )
+SYMBOL(empty, std::, )
+SYMBOL(empty, std::, )
+SYMBOL(end, std::, )
+SYMBOL(end, std::, )
+SYMBOL(end, std::, )
+SYMBOL(end, std::, )
+SYMBOL(end, std::, )
+SYMBOL(end, std::, )
+SYMBOL(end, std::, )
+SYMBOL(end, std::, )
+SYMBOL(end, std::, )
+SYMBOL(end, std::, )
+SYMBOL(end, std::, )
+SYMBOL(end, std::, )
+SYMBOL(end, std::, )
+SYMBOL(end, std::, )
+SYMBOL(rbegin, std::, )
+SYMBOL(rbegin, std::, )
+SYMBOL(rbegin, std::, )
+SYMBO

[PATCH] D142384: [C++20] Fix a crash with modules.

2023-02-03 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

In D142384#4101461 , @ChuanqiXu wrote:

> It should be good to prevent crashes. But it looks not good that it doesn't 
> have a test. Do you have plans to add a test case for this soon?

It would be great to have a test, but we didn't manage to come up with a small 
repro (we spent 2 weeks on-and-off trying to come up with one).
This only breaks inside our internal builds with header modules, internal 
version of Bazel, multiple targets with modules and STL.

We'll keep trying to reproduce this, but can't promise any exact dates.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142384

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


[PATCH] D143260: [clangd] Add semantic token for labels

2023-02-03 Thread Christian Kandeler via Phabricator via cfe-commits
ckandeler created this revision.
ckandeler added a reviewer: sammccall.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
ckandeler requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143260

Files:
  clang-tools-extra/clangd/SemanticHighlighting.cpp
  clang-tools-extra/clangd/SemanticHighlighting.h
  clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp


Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -1025,6 +1025,16 @@
 template $Bracket[[<]]C2$Bracket[[<]]int$Bracket[[>]] 
$TemplateParameter_def[[A]]$Bracket[[>]]
 class $Class_def[[B]] {};
   )cpp",
+  // Labels
+  R"cpp(
+bool $Function_def[[funcWithGoto]](bool $Parameter_def[[b]]) {
+  if ($Parameter[[b]])
+goto $Label[[return_true]];
+  return false;
+  $Label_decl[[return_true]]:
+return true;
+}
+  )cpp",
   // no crash
   R"cpp(
 struct $Class_def[[Foo]] {
Index: clang-tools-extra/clangd/SemanticHighlighting.h
===
--- clang-tools-extra/clangd/SemanticHighlighting.h
+++ clang-tools-extra/clangd/SemanticHighlighting.h
@@ -52,6 +52,7 @@
   Modifier,
   Operator,
   Bracket,
+  Label,
 
   // This one is different from the other kinds as it's a line style
   // rather than a token style.
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -154,6 +154,8 @@
 return HighlightingKind::TemplateParameter;
   if (isa(D))
 return HighlightingKind::Concept;
+  if (isa(D))
+return HighlightingKind::Label;
   if (const auto *UUVD = dyn_cast(D)) {
 auto Targets = Resolver->resolveUsingValueDecl(UUVD);
 if (!Targets.empty()) {
@@ -1212,6 +1214,8 @@
 return OS << "Operator";
   case HighlightingKind::Bracket:
 return OS << "Bracket";
+  case HighlightingKind::Label:
+return OS << "Label";
   case HighlightingKind::InactiveCode:
 return OS << "InactiveCode";
   }
@@ -1352,6 +1356,8 @@
 return "operator";
   case HighlightingKind::Bracket:
 return "bracket";
+  case HighlightingKind::Label:
+return "label";
   case HighlightingKind::InactiveCode:
 return "comment";
   }


Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -1025,6 +1025,16 @@
 template $Bracket[[<]]C2$Bracket[[<]]int$Bracket[[>]] $TemplateParameter_def[[A]]$Bracket[[>]]
 class $Class_def[[B]] {};
   )cpp",
+  // Labels
+  R"cpp(
+bool $Function_def[[funcWithGoto]](bool $Parameter_def[[b]]) {
+  if ($Parameter[[b]])
+goto $Label[[return_true]];
+  return false;
+  $Label_decl[[return_true]]:
+return true;
+}
+  )cpp",
   // no crash
   R"cpp(
 struct $Class_def[[Foo]] {
Index: clang-tools-extra/clangd/SemanticHighlighting.h
===
--- clang-tools-extra/clangd/SemanticHighlighting.h
+++ clang-tools-extra/clangd/SemanticHighlighting.h
@@ -52,6 +52,7 @@
   Modifier,
   Operator,
   Bracket,
+  Label,
 
   // This one is different from the other kinds as it's a line style
   // rather than a token style.
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -154,6 +154,8 @@
 return HighlightingKind::TemplateParameter;
   if (isa(D))
 return HighlightingKind::Concept;
+  if (isa(D))
+return HighlightingKind::Label;
   if (const auto *UUVD = dyn_cast(D)) {
 auto Targets = Resolver->resolveUsingValueDecl(UUVD);
 if (!Targets.empty()) {
@@ -1212,6 +1214,8 @@
 return OS << "Operator";
   case HighlightingKind::Bracket:
 return OS << "Bracket";
+  case HighlightingKind::Label:
+return OS << "Label";
   case HighlightingKind::InactiveCode:
 return OS << "InactiveCode";
   }
@@ -1352,6 +1356,8 @@
 return "operator";
   case HighlightingKind::Bracket:
 return "bracket";
+  case HighlightingKind::Label:
+return "label";
   case HighlightingKind::InactiveCode:
 return "c

[PATCH] D141389: [DFSAN] Add support for strnlen, strncat, strsep, sscanf and _tolower

2023-02-03 Thread Andrew via Phabricator via cfe-commits
browneee added inline comments.



Comment at: compiler-rt/lib/dfsan/dfsan_custom.cpp:213
+  char *res = strsep(s, delim);
+  s_label = dfsan_read_label(base, strlen(base));
+  if (res && (res != base)) {

tkuchta wrote:
> browneee wrote:
> > tkuchta wrote:
> > > browneee wrote:
> > > > tkuchta wrote:
> > > > > browneee wrote:
> > > > > > The `s_label` represents the taint label for `s` (the pointer).
> > > > > > 
> > > > > > This line would clobber the taint label of the pointer (`s`) with a 
> > > > > > taint label from `s[0][0..n]`.
> > > > > > 
> > > > > > I think this line should be deleted.
> > > > > Agree, s_label represents the taint associated with the **s pointer. 
> > > > > However I am now wondering if that is the taint wich we would like to 
> > > > > return.
> > > > > For example, if we have
> > > > > if (flags().strict_data_dependencies) {
> > > > > *ret_label = res ? s_label : 0;
> > > > > 
> > > > > We would taint the return value with the value of the pointer, not 
> > > > > the data. It means that if we operate on a string for which the 
> > > > > characters are tainted, but the pointer itself isn't, we are likely 
> > > > > going to return label 0. My understanding was that we are more 
> > > > > concerned with the taint of the data, not the pointer, am I missing 
> > > > > something?
> > > > > 
> > > > Yes, we are usually more concerned with the taint of the data, not the 
> > > > pointer.
> > > > 
> > > > With strict dependencies:
> > > > // If the input pointer is tainted, the output pointer would be tainted 
> > > > (because it is derived from the input pointer - maybe the same value).
> > > > taint(s[0]) == dfsan_read_label(s, sizeof(s)) > taint(ret) == 
> > > > ret_label[0]
> > > > 
> > > > // If the input data is tainted, the output data would be tainted 
> > > > (because it is derived from the input data).
> > > > taint(s[0][0]) == MEM_TO_SHADOW(s[0])[0] > taint(ret[0]) == 
> > > > MEM_TO_SHADOW(ret)[0]
> > > > 
> > > > Because s[0] == ret  (or ret==null), (for the non-null case) the output 
> > > > shadow bytes are the same bytes as input shadow bytes and so these 
> > > > taint labels for the string data in shadow memory do not need to be 
> > > > explicitly propagated in this function. 
> > > > 
> > > > I think the only case actually changing/copying string data is writing 
> > > > a delimiter byte to NULL, which you handled.
> > > I am working on the changes and I came across a strange behavior that I 
> > > would like to ask about.
> > > 
> > > It turned out that if we do
> > > 
> > > char *s = " ... ";
> > > dfsan_set_label(label, &p_s, sizeof(&p_s));
> > > 
> > > Then, the s_label within the handler is 0, not "label". This is 
> > > unexpected, as we would like the pointer itself to be labeled here.
> > > I believe this has something to do with the fact that the input string in 
> > > strsep is a double pointer. For example this works as expected for the 
> > > delimiter string, which is a single pointer. 
> > > It's either I'm doing something incorrectly or there is some issue with 
> > > propagating labels for double pointers.
> > > Have you perhaps come across this behavior before?
> > I'm not sure what p_s is in your example. Could you provide a more complete 
> > example?
> > (and maybe all in one function, not half in __dfsw_strsep and half in 
> > another function)
> > 
> > Here is an example showing taint labels at different levels of indirection:
> > 
> > ```
> > #include 
> > #include 
> > #include 
> > 
> > int main(void) {
> >   char *s = " ... ";
> >   char **p_s = &s;
> >   char ***pp_s = &p_s;
> > 
> >   dfsan_label i_label = 1 << 0;
> >   dfsan_label j_label = 1 << 1;
> >   dfsan_label k_label = 1 << 2;
> >   dfsan_label m_label = 1 << 3;
> > 
> >   // string data
> >   dfsan_set_label(i_label, s, strlen(s));
> >   // pointer s
> >   dfsan_set_label(j_label, &s, sizeof(s));
> >   // pointer to pointer s
> >   dfsan_set_label(k_label, &p_s, sizeof(p_s));
> >   // pointer to pointer to pointer s
> >   dfsan_set_label(m_label, &pp_s, sizeof(pp_s));
> > 
> >   assert(pp_s[0][0] == s);
> > 
> >   // string data
> >   assert(dfsan_read_label(s, strlen(s)) == i_label);
> >   // pointer s
> >   assert(dfsan_read_label(&s, sizeof(s)) == j_label);
> >   // pointer to pointer s
> >   assert(dfsan_read_label(&p_s, sizeof(p_s)) == k_label);
> >   // pointer to pointer to pointer s
> >   assert(dfsan_read_label(&pp_s, sizeof(pp_s)) == m_label);
> > 
> >   return 0;
> > }
> > ```
> Hello,
> 
> Thank you for the comment.
> 
> I should have provided a more complete example.
> What I meant is a behavior I've found while working on the tests.
> In the test file I have something like that:
> 
> ```
> char *s = "Hello world/";
> char *delim = " /";
> dfsan_set_label(label, &s, sizeof(&s));
> char *rv = strep(&s, delim);
>  ```
> 
> If I get this right, the line 
> ```
> dfsan_set_label(label, &s, sizeof(&s));
> 
> ``` 
> should have 

[PATCH] D142467: [Tooling] Add stdlib::Symbol::all() and stdlib::Symbol::qualified_name()

2023-02-03 Thread Sam McCall via Phabricator via cfe-commits
sammccall marked 2 inline comments as done.
sammccall added inline comments.



Comment at: clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp:18
 
 static llvm::StringRef *HeaderNames;
+static struct SymbolName {

hokein wrote:
> nit: we group five symbols together, it is a bit hard to follow.
> 
> Can you move the HeaderNames just before the `HeaderIDs` and mention the 
> value of the `HeaderIDs`  is the index of `HeaderNames`?
Rearranged these and added comments to each.



Comment at: clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp:108
+  std::vector Result;
+  Result.reserve(HeaderIDs->size());
+  for (unsigned I = 0, E = SymbolCount; I < E; ++I)

hokein wrote:
> should be `SymbolCount`.
Oops, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142467

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


[clang] e1aaa31 - [Tooling] Add stdlib::Symbol::all() and stdlib::Symbol::qualified_name()

2023-02-03 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2023-02-03T13:22:26+01:00
New Revision: e1aaa314a46cd303019da117bfd330611d5b7a84

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

LOG: [Tooling] Add stdlib::Symbol::all() and stdlib::Symbol::qualified_name()

These address some remaining reasons to #include StdSymbolMap.inc directly.

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

Added: 


Modified: 
clang/include/clang/Tooling/Inclusions/StandardLibrary.h
clang/lib/Sema/SemaDecl.cpp
clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
clang/test/AST/dump.cpp
clang/unittests/Tooling/StandardLibraryTest.cpp

Removed: 




diff  --git a/clang/include/clang/Tooling/Inclusions/StandardLibrary.h 
b/clang/include/clang/Tooling/Inclusions/StandardLibrary.h
index beb2f496f51f4..6dc8d6d09390b 100644
--- a/clang/include/clang/Tooling/Inclusions/StandardLibrary.h
+++ b/clang/include/clang/Tooling/Inclusions/StandardLibrary.h
@@ -37,6 +37,7 @@ class Symbol;
 // "" and "" (and their symbols) are treated 
diff erently.
 class Header {
 public:
+  static std::vector all();
   // Name should contain the angle brackets, e.g. "".
   static std::optional named(llvm::StringRef Name);
 
@@ -63,16 +64,18 @@ class Header {
 // for them.
 class Symbol {
 public:
+  static std::vector all();
   /// \p Scope should have the trailing "::", for example:
   /// named("std::chrono::", "system_clock")
   static std::optional named(llvm::StringRef Scope,
   llvm::StringRef Name);
 
   friend llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const Symbol &S) 
{
-return OS << S.scope() << S.name();
+return OS << S.qualified_name();
   }
   llvm::StringRef scope() const;
   llvm::StringRef name() const;
+  llvm::StringRef qualified_name() const;
   // The preferred header for this symbol (e.g. the suggested insertion).
   Header header() const;
   // Some symbols may be provided by multiple headers.

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index b2bece4d9db08..c1af566f76bc5 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -17203,6 +17203,10 @@ Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind 
TUK, SourceLocation KWLoc,
   SkipBody->Previous = Def;
   return Def;
 } else {
+  llvm::errs() << "got here\n";
+  Def->dump();
+  Hidden->dump();
+  NameLoc.dump(getSourceManager());
   SkipBody->ShouldSkip = true;
   SkipBody->Previous = Def;
   makeMergedDefinitionVisible(Hidden);

diff  --git a/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp 
b/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
index 9e5e421fdebcd..cc084c4d56894 100644
--- a/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
+++ b/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
@@ -15,23 +15,34 @@ namespace clang {
 namespace tooling {
 namespace stdlib {
 
+// Header::ID => header name
 static llvm::StringRef *HeaderNames;
-static std::pair *SymbolNames;
-static unsigned *SymbolHeaderIDs;
+// Header name => Header::ID
 static llvm::DenseMap *HeaderIDs;
-// Maps symbol name -> Symbol::ID, within a namespace.
+
+static unsigned SymbolCount = 0;
+// Symbol::ID => symbol qualified_name/name/scope
+static struct SymbolName {
+  const char *Data;  // std::vector
+  unsigned ScopeLen; // ~
+  unsigned NameLen;  //  ~~
+} *SymbolNames;
+// Symbol name -> Symbol::ID, within a namespace.
 using NSSymbolMap = llvm::DenseMap;
 static llvm::DenseMap *NamespaceSymbols;
+// Symbol::ID => Header::ID
+static unsigned *SymbolHeaderIDs;
 
 static int initialize() {
-  unsigned SymCount = 0;
-#define SYMBOL(Name, NS, Header) ++SymCount;
+  SymbolCount = 0;
+#define SYMBOL(Name, NS, Header) ++SymbolCount;
 #include "clang/Tooling/Inclusions/CSymbolMap.inc"
 #include "clang/Tooling/Inclusions/StdSymbolMap.inc"
 #undef SYMBOL
-  SymbolNames = new std::remove_reference_t[SymCount];
+  SymbolNames =
+  new std::remove_reference_t[SymbolCount];
   SymbolHeaderIDs =
-  new std::remove_reference_t[SymCount];
+  new std::remove_reference_t[SymbolCount];
   NamespaceSymbols = new std::remove_reference_t;
   HeaderIDs = new std::remove_reference_t;
 
@@ -46,20 +57,25 @@ static int initialize() {
 return HeaderIDs->try_emplace(Header, HeaderIDs->size()).first->second;
   };
 
-  auto Add = [&, SymIndex(0)](llvm::StringRef Name, llvm::StringRef NS,
+  auto Add = [&, SymIndex(0)](llvm::StringRef QName, unsigned NSLen,
   llvm::StringRef HeaderName) mutable {
-if (NS == "None")
-  NS = "";
+// Correct "Nonefoo" => foo.

[PATCH] D142467: [Tooling] Add stdlib::Symbol::all() and stdlib::Symbol::qualified_name()

2023-02-03 Thread Sam McCall via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
sammccall marked 2 inline comments as done.
Closed by commit rGe1aaa314a46c: [Tooling] Add stdlib::Symbol::all() and 
stdlib::Symbol::qualified_name() (authored by sammccall).
Herald added a reviewer: jdoerfert.
Herald added a subscriber: sstefan1.

Changed prior to commit:
  https://reviews.llvm.org/D142467?vs=491766&id=494587#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142467

Files:
  clang/include/clang/Tooling/Inclusions/StandardLibrary.h
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
  clang/test/AST/dump.cpp
  clang/unittests/Tooling/StandardLibraryTest.cpp

Index: clang/unittests/Tooling/StandardLibraryTest.cpp
===
--- clang/unittests/Tooling/StandardLibraryTest.cpp
+++ clang/unittests/Tooling/StandardLibraryTest.cpp
@@ -18,6 +18,7 @@
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
+using ::testing::Contains;
 using ::testing::ElementsAre;
 
 namespace clang {
@@ -35,17 +36,24 @@
 TEST(StdlibTest, All) {
   auto VectorH = stdlib::Header::named("");
   EXPECT_TRUE(VectorH);
+  EXPECT_EQ(VectorH->name(), "");
   EXPECT_EQ(llvm::to_string(*VectorH), "");
   EXPECT_FALSE(stdlib::Header::named("HeadersTests.cpp"));
 
   auto Vector = stdlib::Symbol::named("std::", "vector");
   EXPECT_TRUE(Vector);
+  EXPECT_EQ(Vector->scope(), "std::");
+  EXPECT_EQ(Vector->name(), "vector");
+  EXPECT_EQ(Vector->qualified_name(), "std::vector");
   EXPECT_EQ(llvm::to_string(*Vector), "std::vector");
   EXPECT_FALSE(stdlib::Symbol::named("std::", "dongle"));
   EXPECT_FALSE(stdlib::Symbol::named("clang::", "ASTContext"));
 
   EXPECT_EQ(Vector->header(), *VectorH);
   EXPECT_THAT(Vector->headers(), ElementsAre(*VectorH));
+
+  EXPECT_THAT(stdlib::Header::all(), Contains(*VectorH));
+  EXPECT_THAT(stdlib::Symbol::all(), Contains(*Vector));
 }
 
 TEST(StdlibTest, Recognizer) {
Index: clang/test/AST/dump.cpp
===
--- clang/test/AST/dump.cpp
+++ clang/test/AST/dump.cpp
@@ -30,7 +30,7 @@
 // CHECK-NEXT: | `-VarDecl {{.+}}  col:40 implicit used omp_out 'char'
 // CHECK-NEXT: |-OMPDeclareReductionDecl {{.+}}  col:37 fun 'float' combiner 0x{{.+}} initializer 0x{{.+}}
 // CHECK-NEXT: | |-CompoundAssignOperator {{.+}}  'float' lvalue '+=' ComputeLHSTy='float' ComputeResultTy='float'
-// CHECK-NEXT: | | |-DeclRefExpr {{.+}}  'float' lvalue Var {{.+}} 'omp_out' 'float'
+// CHECK-NEXT: | | |-BOOM{{.+}}  'float' lvalue Var {{.+}} 'omp_out' 'float'
 // CHECK-NEXT: | | `-ImplicitCastExpr {{.+}}  'float' 
 // CHECK-NEXT: | |   `-DeclRefExpr {{.+}}  'float' lvalue Var {{.+}} 'omp_in' 'float'
 // CHECK-NEXT: | |-BinaryOperator {{.+}}  'float' '+'
Index: clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
===
--- clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
+++ clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
@@ -15,23 +15,34 @@
 namespace tooling {
 namespace stdlib {
 
+// Header::ID => header name
 static llvm::StringRef *HeaderNames;
-static std::pair *SymbolNames;
-static unsigned *SymbolHeaderIDs;
+// Header name => Header::ID
 static llvm::DenseMap *HeaderIDs;
-// Maps symbol name -> Symbol::ID, within a namespace.
+
+static unsigned SymbolCount = 0;
+// Symbol::ID => symbol qualified_name/name/scope
+static struct SymbolName {
+  const char *Data;  // std::vector
+  unsigned ScopeLen; // ~
+  unsigned NameLen;  //  ~~
+} *SymbolNames;
+// Symbol name -> Symbol::ID, within a namespace.
 using NSSymbolMap = llvm::DenseMap;
 static llvm::DenseMap *NamespaceSymbols;
+// Symbol::ID => Header::ID
+static unsigned *SymbolHeaderIDs;
 
 static int initialize() {
-  unsigned SymCount = 0;
-#define SYMBOL(Name, NS, Header) ++SymCount;
+  SymbolCount = 0;
+#define SYMBOL(Name, NS, Header) ++SymbolCount;
 #include "clang/Tooling/Inclusions/CSymbolMap.inc"
 #include "clang/Tooling/Inclusions/StdSymbolMap.inc"
 #undef SYMBOL
-  SymbolNames = new std::remove_reference_t[SymCount];
+  SymbolNames =
+  new std::remove_reference_t[SymbolCount];
   SymbolHeaderIDs =
-  new std::remove_reference_t[SymCount];
+  new std::remove_reference_t[SymbolCount];
   NamespaceSymbols = new std::remove_reference_t;
   HeaderIDs = new std::remove_reference_t;
 
@@ -46,20 +57,25 @@
 return HeaderIDs->try_emplace(Header, HeaderIDs->size()).first->second;
   };
 
-  auto Add = [&, SymIndex(0)](llvm::StringRef Name, llvm::StringRef NS,
+  auto Add = [&, SymIndex(0)](llvm::StringRef QName, unsigned NSLen,
   llvm::StringRef HeaderName) mutable {
-if (NS == "None")
-  NS = "";
+// Correct "Nonefoo" => foo.
+// FIXME: get rid o

[PATCH] D143194: [clang][analyzer] Make messages of StdCLibraryFunctionsChecker user-friendly

2023-02-03 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added a reviewer: gamesh411.
Szelethus added a comment.

Awesome, been a long time coming!!

Other than the minor observation of changing "of function" to "to", I'm 
inclined to accept this patch. We definitely should describe what the value IS, 
not just what is should be (aside from the cases concerning nullness, I think 
they are fine as-is), but seems to be another can of worms deserving of its own 
patch.

The reason why I'd solve the description of the argument separately is that 
other checkers also suffer from this problem (`alpha.security.ArrayBoundV2`, 
hello), and it opens conversations such as "What if we can't sensibly describe 
that value?", and on occasions, we have felt that the go-to solution should be 
just suppressing the warning. But then again, its an intentional false negative.




Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:915
   Result += getArgDesc(ArgN);
-  Result += DK == Violation ? " should not be NULL" : " is not NULL";
+  Result += " of function '";
+  Result += getFunctionName(Call);

Looking at the tests, the word 'function' may be redundant and unnecessary.



Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:932
   Result += getArgDesc(ArgN);
-  Result += DK == Violation ? " should be " : " is ";
-
-  // Range kind as a string.
-  Kind == OutOfRange ? Result += "out of" : Result += "within";
-
-  // Get the range values as a string.
-  Result += " the range ";
-  if (Ranges.size() > 1)
-Result += "[";
-  unsigned I = Ranges.size();
-  for (const std::pair &R : Ranges) {
-Result += "[";
-const llvm::APSInt &Min = BVF.getValue(R.first, T);
-const llvm::APSInt &Max = BVF.getValue(R.second, T);
-Min.toString(Result);
-Result += ", ";
-Max.toString(Result);
-Result += "]";
-if (--I > 0)
-  Result += ", ";
+  Result += " of function '";
+  Result += getFunctionName(Call);

Here too.



Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:966
   Result += getArgDesc(ArgN);
-  Result += DK == Violation ? " should be " : " is ";
-  Result += "equal to or greater than the value of ";
+  Result += " of function '";
+  Result += getFunctionName(Call);

Here too.



Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:980
   }
   return Result.c_str();
 }

We are saying what the value should be, but neglect to say what it is instead. 
Something like this would be good:

"The value of the 1st argument to _nonnull should be equal to or less then 10, 
but is 11".

This is what I (and many of our users IIRC) miss in checker messages, like in 
those where we are supposed to describe what the value of the index is (besides 
it causing a buffer overflow).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143194

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


[clang] 506e55b - Revert unintended debug things :-(

2023-02-03 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2023-02-03T13:47:13+01:00
New Revision: 506e55b041b94808c80099d61cef5539390ab215

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

LOG: Revert unintended debug things :-(

Added: 


Modified: 
clang/lib/Sema/SemaDecl.cpp
clang/test/AST/dump.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index c1af566f76bc5..b2bece4d9db08 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -17203,10 +17203,6 @@ Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind 
TUK, SourceLocation KWLoc,
   SkipBody->Previous = Def;
   return Def;
 } else {
-  llvm::errs() << "got here\n";
-  Def->dump();
-  Hidden->dump();
-  NameLoc.dump(getSourceManager());
   SkipBody->ShouldSkip = true;
   SkipBody->Previous = Def;
   makeMergedDefinitionVisible(Hidden);

diff  --git a/clang/test/AST/dump.cpp b/clang/test/AST/dump.cpp
index 651a594986f74..bbd388cbf0957 100644
--- a/clang/test/AST/dump.cpp
+++ b/clang/test/AST/dump.cpp
@@ -30,7 +30,7 @@ int ga, gb;
 // CHECK-NEXT: | `-VarDecl {{.+}}  col:40 implicit used omp_out 'char'
 // CHECK-NEXT: |-OMPDeclareReductionDecl {{.+}}  col:37 
fun 'float' combiner 0x{{.+}} initializer 0x{{.+}}
 // CHECK-NEXT: | |-CompoundAssignOperator {{.+}}  'float' 
lvalue '+=' ComputeLHSTy='float' ComputeResultTy='float'
-// CHECK-NEXT: | | |-BOOM{{.+}}  'float' lvalue Var {{.+}} 'omp_out' 
'float'
+// CHECK-NEXT: | | |-DeclRefExpr {{.+}}  'float' lvalue Var {{.+}} 
'omp_out' 'float'
 // CHECK-NEXT: | | `-ImplicitCastExpr {{.+}}  'float' 
 // CHECK-NEXT: | |   `-DeclRefExpr {{.+}}  'float' lvalue Var {{.+}} 
'omp_in' 'float'
 // CHECK-NEXT: | |-BinaryOperator {{.+}}  'float' '+'



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


[PATCH] D143093: [clangd] #undef macros inside preamble patch

2023-02-03 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

In D143093#4099623 , @sammccall wrote:

> I can't understand from the description, code, or testcases what problem this 
> is fixing. Can you clarify, ideally by improving the testcases?

Yeah should've elaborated on this one. As explained offline the issue is macro 
token contents are not preserved in the PCH and are re-lexed when needed (for 
diagnosing macro-redefined errors in our case). Since PCH contents are stale, 
when we retrieve token contents based on ranges stored in the PCH using the new 
file contents, we get a false-positive.
This patch tries to avoid such false positive diagnostics by emitting an #undef 
statement before any macro definition we're going to emit.

---

> It seems to introduce a false negative in the case that the preamble *does* 
> contain a definition of an already-defined macro, which probably needs to be 
> called out.

I am failing to follow this one. I can think of two different cases:

  #define FOO 1
  #define FOO 2
  ;

changes to

  #define BAR
  #define FOO 1
  #define FOO 2
  ;

we won't have diagnostics here, not because of the `#undef` logic, but because 
we're not moving the diagnostic ranges around.

Other case is we've

  #define FOO 1
  ;
  #define FOO 2

and it gets changed to

  #define BAR
  #define FOO 1
  ;
  #define FOO 2

now the issue is we're emitting re-definition diag to a location inside the 
preamble patch, but we don't translate the location back to main-file. again it 
has nothing to do with the `#undef` logic proposed here (and fixed by D143095 
).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143093

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


[PATCH] D141858: [clang][Interp] Fix Pointer::toAPValue() for expressions

2023-02-03 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 rGf63138d44429: [clang][Interp] Fix Pointer::toAPValue() for 
expressions (authored by tbaeder).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141858

Files:
  clang/lib/AST/Interp/Pointer.cpp


Index: clang/lib/AST/Interp/Pointer.cpp
===
--- clang/lib/AST/Interp/Pointer.cpp
+++ clang/lib/AST/Interp/Pointer.cpp
@@ -103,6 +103,10 @@
 if (isUnknownSizeArray()) {
   IsOnePastEnd = false;
   Offset = CharUnits::Zero();
+} else if (Desc->asExpr()) {
+  // Pointer pointing to a an expression.
+  IsOnePastEnd = false;
+  Offset = CharUnits::Zero();
 } else {
   // TODO: compute the offset into the object.
   Offset = CharUnits::Zero();


Index: clang/lib/AST/Interp/Pointer.cpp
===
--- clang/lib/AST/Interp/Pointer.cpp
+++ clang/lib/AST/Interp/Pointer.cpp
@@ -103,6 +103,10 @@
 if (isUnknownSizeArray()) {
   IsOnePastEnd = false;
   Offset = CharUnits::Zero();
+} else if (Desc->asExpr()) {
+  // Pointer pointing to a an expression.
+  IsOnePastEnd = false;
+  Offset = CharUnits::Zero();
 } else {
   // TODO: compute the offset into the object.
   Offset = CharUnits::Zero();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] f63138d - [clang][Interp] Fix Pointer::toAPValue() for expressions

2023-02-03 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-02-03T14:30:05+01:00
New Revision: f63138d44429fc04bd2d7477f2e492f180d7aab3

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

LOG: [clang][Interp] Fix Pointer::toAPValue() for expressions

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

Added: 


Modified: 
clang/lib/AST/Interp/Pointer.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Pointer.cpp 
b/clang/lib/AST/Interp/Pointer.cpp
index e25b4f8b58449..8f1dfa346c632 100644
--- a/clang/lib/AST/Interp/Pointer.cpp
+++ b/clang/lib/AST/Interp/Pointer.cpp
@@ -103,6 +103,10 @@ APValue Pointer::toAPValue() const {
 if (isUnknownSizeArray()) {
   IsOnePastEnd = false;
   Offset = CharUnits::Zero();
+} else if (Desc->asExpr()) {
+  // Pointer pointing to a an expression.
+  IsOnePastEnd = false;
+  Offset = CharUnits::Zero();
 } else {
   // TODO: compute the offset into the object.
   Offset = CharUnits::Zero();



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


[PATCH] D142123: [clang-tidy] Add header guard style to suggest use of #pragma once

2023-02-03 Thread Kyle Edwards via Phabricator via cfe-commits
KyleFromKitware added a comment.

@aaron.ballman @njames93 could you guys please take another look at this?


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

https://reviews.llvm.org/D142123

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


[PATCH] D142992: [include-mapping] Implement language separation in stdlib recognizer library

2023-02-03 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

Thanks, this looks good to me!

This requires some work to rebase for 
https://github.com/llvm/llvm-project/commit/e1aaa314a46cd303019da117bfd330611d5b7a84,
 I will rebase it and land it for you.




Comment at: clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp:31
+
+static llvm::DenseMap LanguageMappings;
+

VitaNuo wrote:
> hokein wrote:
> > VitaNuo wrote:
> > > hokein wrote:
> > > > using a map here seems like an overkill, we have just 2 elements, I'd 
> > > > just use two separate variables (`CMapping`, and `CXXMapping`)
> > > what about the design idea that we might potentially want to extend this 
> > > to multiple standards etc.? The idea is that it's extensible to `ObjC`, 
> > > `OpenCL`... and so on and so forth, as has been discussed offline.
> > I think having a generic `Lang` enum structure is sufficient for the future 
> > extension, and I don't think we're going to add other languages in the 
> > foreseeable future (that's why I value the simple implementation at the 
> > beginning).
> > 
> > But you're right, getting the implementation right is probably a good idea. 
> > I'd like to remove the DenseMap, just use a raw array, something like below 
> > should work 
> > 
> > ```
> > enum Lang {
> >C = 0,
> >CXX,
> > 
> >LastValue = CXX,
> > };
> > 
> > // access by e.g. LanguageMappings[static_cast(Lang::C)].
> > static SymbolHeaderMapping* 
> > LanguageMappings[static_cast(Lang::LastValue) + 1];
> > 
> > ```
> Ok, this will need some casting, but I don't have a strong opinion.
yeah, it is the sad bit, but I think it is OK.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142992

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


[PATCH] D140999: [NFC][TargetParser] Deprecate llvm/Support/AArch64TargetParser.h

2023-02-03 Thread Sam Elliott via Phabricator via cfe-commits
lenary added a comment.

In D140999#4030131 , @MaskRay wrote:

> I don't think it is necessary to deprecate the old header then delete it 
> after 16.0.0 is branched.
> llvm/Support/AArch64TargetParser.h has very few open-source out-of-tree uses. 
> Perhaps only ldc `driver/targetmachine.cpp` uses the header. So it is not 
> worth extra expedience.
> Just deleting it in another change should be fine.
>
> Changing the include to `#include "llvm/TargetParser/AArch64TargetParser.h"` 
> is totally fine, though.

Sorry, busy time on downstream work means I haven't got back to this.

My plan now is:

- Rebase this to not care about the modulemap patch it is based on, as that is 
getting no review at all, despite being pinged.
- Just start deleting the forwarding headers, as [NFC] commits, updating all 
the references to the new headers. We're after the 16 branch point, so I think 
that's been a long enough cut-over period.

At some point, people will need to fix the bazel/modulemap builds, but I've 
tried the latter and got no traction on patches to do so.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140999

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


[PATCH] D140999: [NFC][TargetParser] Remove llvm/Support/AArch64TargetParser.h

2023-02-03 Thread Sam Elliott via Phabricator via cfe-commits
lenary retitled this revision from "[NFC][TargetParser] Deprecate 
llvm/Support/AArch64TargetParser.h" to "[NFC][TargetParser] Remove 
llvm/Support/AArch64TargetParser.h".
lenary edited the summary of this revision.
lenary updated this revision to Diff 494596.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140999

Files:
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/AArch64.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Driver/SanitizerArgs.cpp
  clang/lib/Driver/ToolChains/Arch/AArch64.cpp
  lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
  llvm/include/llvm/Support/AArch64TargetParser.h
  llvm/lib/Target/AArch64/AArch64Subtarget.cpp
  llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp

Index: llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
===
--- llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
+++ llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
@@ -48,7 +48,7 @@
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Support/SMLoc.h"
-#include "llvm/Support/AArch64TargetParser.h"
+#include "llvm/TargetParser/AArch64TargetParser.h"
 #include "llvm/Support/TargetParser.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/TargetParser/AArch64TargetParser.h"
Index: llvm/lib/Target/AArch64/AArch64Subtarget.cpp
===
--- llvm/lib/Target/AArch64/AArch64Subtarget.cpp
+++ llvm/lib/Target/AArch64/AArch64Subtarget.cpp
@@ -24,7 +24,7 @@
 #include "llvm/CodeGen/MachineFrameInfo.h"
 #include "llvm/CodeGen/MachineScheduler.h"
 #include "llvm/IR/GlobalValue.h"
-#include "llvm/Support/AArch64TargetParser.h"
+#include "llvm/TargetParser/AArch64TargetParser.h"
 #include "llvm/Support/TargetParser.h"
 
 using namespace llvm;
Index: llvm/include/llvm/Support/AArch64TargetParser.h
===
--- llvm/include/llvm/Support/AArch64TargetParser.h
+++ /dev/null
@@ -1,15 +0,0 @@
-//===-- llvm/Support/AArch64TargetParser.h --*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-///
-/// \file
-/// This header is deprecated in favour of
-/// `llvm/TargetParser/AArch64TargetParser.h`.
-///
-//===--===//
-
-#include "llvm/TargetParser/AArch64TargetParser.h"
Index: lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
===
--- lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
+++ lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
@@ -23,7 +23,7 @@
 #include "llvm/MC/MCSubtargetInfo.h"
 #include "llvm/MC/MCTargetOptions.h"
 #include "llvm/MC/TargetRegistry.h"
-#include "llvm/Support/AArch64TargetParser.h"
+#include "llvm/TargetParser/AArch64TargetParser.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/TargetSelect.h"
Index: clang/lib/Driver/ToolChains/Arch/AArch64.cpp
===
--- clang/lib/Driver/ToolChains/Arch/AArch64.cpp
+++ clang/lib/Driver/ToolChains/Arch/AArch64.cpp
@@ -12,7 +12,7 @@
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/Options.h"
 #include "llvm/Option/ArgList.h"
-#include "llvm/Support/AArch64TargetParser.h"
+#include "llvm/TargetParser/AArch64TargetParser.h"
 #include "llvm/Support/TargetParser.h"
 #include "llvm/Support/Host.h"
 
Index: clang/lib/Driver/SanitizerArgs.cpp
===
--- clang/lib/Driver/SanitizerArgs.cpp
+++ clang/lib/Driver/SanitizerArgs.cpp
@@ -14,7 +14,7 @@
 #include "clang/Driver/ToolChain.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringSwitch.h"
-#include "llvm/Support/AArch64TargetParser.h"
+#include "llvm/TargetParser/AArch64TargetParser.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/SpecialCaseList.h"
 #include "llvm/Support/TargetParser.h"
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -52,7 +52,7 @@
 #include "llvm/IR/IntrinsicsX86.h"
 #include "llvm/IR/MDBuilder.h"
 #include "llvm/IR/MatrixBuilder.h"
-#include "llvm/Support/AArch64TargetParser.h"
+#include "llvm/TargetParser/AArch64TargetParser.h"
 #include "llvm/Support/ConvertUTF.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/X86TargetParser.h"
Index: clang/lib/Basic/Targe

[PATCH] D140999: [NFC][TargetParser] Remove llvm/Support/AArch64TargetParser.h

2023-02-03 Thread Sam Elliott via Phabricator via cfe-commits
lenary updated this revision to Diff 494600.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140999

Files:
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/AArch64.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Driver/SanitizerArgs.cpp
  clang/lib/Driver/ToolChains/Arch/AArch64.cpp
  lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
  llvm/include/llvm/Support/AArch64TargetParser.h
  llvm/lib/Target/AArch64/AArch64Subtarget.cpp
  llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp

Index: llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
===
--- llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
+++ llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
@@ -48,7 +48,6 @@
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Support/SMLoc.h"
-#include "llvm/Support/AArch64TargetParser.h"
 #include "llvm/Support/TargetParser.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/TargetParser/AArch64TargetParser.h"
Index: llvm/lib/Target/AArch64/AArch64Subtarget.cpp
===
--- llvm/lib/Target/AArch64/AArch64Subtarget.cpp
+++ llvm/lib/Target/AArch64/AArch64Subtarget.cpp
@@ -24,8 +24,8 @@
 #include "llvm/CodeGen/MachineFrameInfo.h"
 #include "llvm/CodeGen/MachineScheduler.h"
 #include "llvm/IR/GlobalValue.h"
-#include "llvm/Support/AArch64TargetParser.h"
 #include "llvm/Support/TargetParser.h"
+#include "llvm/TargetParser/AArch64TargetParser.h"
 
 using namespace llvm;
 
Index: llvm/include/llvm/Support/AArch64TargetParser.h
===
--- llvm/include/llvm/Support/AArch64TargetParser.h
+++ /dev/null
@@ -1,15 +0,0 @@
-//===-- llvm/Support/AArch64TargetParser.h --*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-///
-/// \file
-/// This header is deprecated in favour of
-/// `llvm/TargetParser/AArch64TargetParser.h`.
-///
-//===--===//
-
-#include "llvm/TargetParser/AArch64TargetParser.h"
Index: lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
===
--- lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
+++ lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
@@ -23,10 +23,10 @@
 #include "llvm/MC/MCSubtargetInfo.h"
 #include "llvm/MC/MCTargetOptions.h"
 #include "llvm/MC/TargetRegistry.h"
-#include "llvm/Support/AArch64TargetParser.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/TargetSelect.h"
+#include "llvm/TargetParser/AArch64TargetParser.h"
 
 #include "lldb/Core/Address.h"
 #include "lldb/Core/Module.h"
Index: clang/lib/Driver/ToolChains/Arch/AArch64.cpp
===
--- clang/lib/Driver/ToolChains/Arch/AArch64.cpp
+++ clang/lib/Driver/ToolChains/Arch/AArch64.cpp
@@ -12,9 +12,9 @@
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/Options.h"
 #include "llvm/Option/ArgList.h"
-#include "llvm/Support/AArch64TargetParser.h"
-#include "llvm/Support/TargetParser.h"
 #include "llvm/Support/Host.h"
+#include "llvm/Support/TargetParser.h"
+#include "llvm/TargetParser/AArch64TargetParser.h"
 
 using namespace clang::driver;
 using namespace clang::driver::tools;
Index: clang/lib/Driver/SanitizerArgs.cpp
===
--- clang/lib/Driver/SanitizerArgs.cpp
+++ clang/lib/Driver/SanitizerArgs.cpp
@@ -14,11 +14,11 @@
 #include "clang/Driver/ToolChain.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringSwitch.h"
-#include "llvm/Support/AArch64TargetParser.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/SpecialCaseList.h"
 #include "llvm/Support/TargetParser.h"
 #include "llvm/Support/VirtualFileSystem.h"
+#include "llvm/TargetParser/AArch64TargetParser.h"
 #include "llvm/Transforms/Instrumentation/AddressSanitizerOptions.h"
 #include 
 
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -52,10 +52,10 @@
 #include "llvm/IR/IntrinsicsX86.h"
 #include "llvm/IR/MDBuilder.h"
 #include "llvm/IR/MatrixBuilder.h"
-#include "llvm/Support/AArch64TargetParser.h"
 #include "llvm/Support/ConvertUTF.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/X86TargetParser.h"
+#include "llvm/TargetParser/AArch64

[PATCH] D140999: [NFC][TargetParser] Remove llvm/Support/AArch64TargetParser.h

2023-02-03 Thread Sam Elliott via Phabricator via cfe-commits
lenary added a comment.

Most recent diff was to clang-format the patch, which has removed some 
duplicate includes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140999

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


[PATCH] D143094: [clang] Change AMX macros to match names from GCC

2023-02-03 Thread Joe Loser via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8998fa6c14f1: [clang] Change AMX macros to match names from 
GCC (authored by jloser).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143094

Files:
  clang/lib/Basic/Targets/X86.cpp
  clang/lib/Headers/immintrin.h
  clang/test/Preprocessor/predefined-arch-macros.c
  clang/test/Preprocessor/x86_amx_target_features.c
  clang/test/Preprocessor/x86_target_features.c

Index: clang/test/Preprocessor/x86_target_features.c
===
--- clang/test/Preprocessor/x86_target_features.c
+++ clang/test/Preprocessor/x86_target_features.c
@@ -548,16 +548,16 @@
 // RUN: %clang -target x86_64-unknown-linux-gnu -march=atom -mamx-fp16 -x c \
 // RUN: -E -dM -o - %s | FileCheck  -check-prefix=AMX-FP16 %s
 
-// AMX-FP16: #define __AMXFP16__ 1
-// AMX-FP16: #define __AMXTILE__ 1
+// AMX-FP16: #define __AMX_FP16__ 1
+// AMX-FP16: #define __AMX_TILE__ 1
 
 // RUN: %clang -target x86_64-unknown-linux-gnu -march=atom -mno-amx-fp16 \
 // RUN: -x c -E -dM -o - %s | FileCheck  -check-prefix=NO-AMX-FP16 %s
 // RUN: %clang -target x86_64-unknown-linux-gnu -march=atom -mamx-fp16 \
 // RUN: -mno-amx-tile -x c -E -dM -o - %s | FileCheck  -check-prefix=NO-AMX-FP16 %s
 
-// NO-AMX-FP16-NOT: #define __AMXFP16__ 1
-// NO-AMX-FP16-NOT: #define __AMXTILE__ 1
+// NO-AMX-FP16-NOT: #define __AMX_FP16__ 1
+// NO-AMX-FP16-NOT: #define __AMX_TILE__ 1
 
 // RUN: %clang -target i386-unknown-unknown -march=atom -mavxvnni -x c -E -dM -o - %s | FileCheck -match-full-lines --check-prefix=AVXVNNI %s
 
Index: clang/test/Preprocessor/x86_amx_target_features.c
===
--- clang/test/Preprocessor/x86_amx_target_features.c
+++ clang/test/Preprocessor/x86_amx_target_features.c
@@ -1,35 +1,35 @@
 // RUN: %clang -target i386-unknown-linux-gnu -march=i386 -mamx-tile -x c -E -dM -o - %s | FileCheck  -check-prefix=AMX-TILE %s
 
-// AMX-TILE: #define __AMXTILE__ 1
+// AMX-TILE: #define __AMX_TILE__ 1
 
 // RUN: %clang -target i386-unknown-linux-gnu -march=i386 -mamx-bf16 -x c -E -dM -o - %s | FileCheck -check-prefix=AMX-BF16 %s
 
-// AMX-BF16: #define __AMXBF16__ 1
-// AMX-BF16: #define __AMXTILE__ 1
+// AMX-BF16: #define __AMX_BF16__ 1
+// AMX-BF16: #define __AMX_TILE__ 1
 
 // RUN: %clang -target i386-unknown-linux-gnu -march=i386 -mamx-int8 -x c -E -dM -o - %s | FileCheck -check-prefix=AMX-INT8 %s
 
-// AMX-INT8: #define __AMXINT8__ 1
-// AMX-INT8: #define __AMXTILE__ 1
+// AMX-INT8: #define __AMX_INT8__ 1
+// AMX-INT8: #define __AMX_TILE__ 1
 
 // RUN: %clang -target i386-unknown-linux-gnu -march=i386 -mno-amx-tile -x c -E -dM -o - %s | FileCheck  -check-prefix=NOAMX-TILE %s
 
-// NOAMX-TILE-NOT: #define __AMXTILE__ 1
+// NOAMX-TILE-NOT: #define __AMX_TILE__ 1
 
 // RUN: %clang -target i386-unknown-linux-gnu -march=i386 -mno-amx-bf16 -x c -E -dM -o - %s | FileCheck  -check-prefix=NOAMX-BF16 %s
 
-// NOAMX-BF16-NOT: #define __AMXBF16__ 1
+// NOAMX-BF16-NOT: #define __AMX_BF16__ 1
 
 // RUN: %clang -target i386-unknown-linux-gnu -march=i386 -mamx-bf16 -mno-amx-tile -x c -E -dM -o - %s | FileCheck  -check-prefix=NOAMX-BF16 %s
 
-// NOAMX-BF16-NOT: #define __AMXTILE__ 1
-// NOAMX-BF16-NOT: #define __AMXBF16__ 1
+// NOAMX-BF16-NOT: #define __AMX_TILE__ 1
+// NOAMX-BF16-NOT: #define __AMX_BF16__ 1
 
 // RUN: %clang -target i386-unknown-linux-gnu -march=i386 -mno-amx-int8 -x c -E -dM -o - %s | FileCheck  -check-prefix=NOAMX-INT8 %s
 
-// NOAMX-INT8-NOT: #define __AMXINT8__ 1
+// NOAMX-INT8-NOT: #define __AMX_INT8__ 1
 
 // RUN: %clang -target i386-unknown-linux-gnu -march=i386 -mamx-int8 -mno-amx-tile -x c -E -dM -o - %s | FileCheck  -check-prefix=NOAMX-INT8 %s
 
-// NOAMX-INT8-NOT: #define __AMXTILE__ 1
-// NOAMX-INT8-NOT: #define __AMXINT8__ 1
+// NOAMX-INT8-NOT: #define __AMX_TILE__ 1
+// NOAMX-INT8-NOT: #define __AMX_INT8__ 1
Index: clang/test/Preprocessor/predefined-arch-macros.c
===
--- clang/test/Preprocessor/predefined-arch-macros.c
+++ clang/test/Preprocessor/predefined-arch-macros.c
@@ -1649,9 +1649,9 @@
 // RUN: -target i386-unknown-linux \
 // RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_SPR_M32
 // CHECK_SPR_M32: #define __AES__ 1
-// CHECK_SPR_M32: #define __AMXBF16__ 1
-// CHECK_SPR_M32: #define __AMXINT8__ 1
-// CHECK_SPR_M32: #define __AMXTILE__ 1
+// CHECK_SPR_M32: #define __AMX_BF16__ 1
+// CHECK_SPR_M32: #define __AMX_INT8__ 1
+// CHECK_SPR_M32: #define __AMX_TILE__ 1
 // CHECK_SPR_M32: #define __AVX2__ 1
 // CHECK_SPR_M32: #define __AVX512BF16__ 1
 // CHECK_SPR_M32: #define __AVX512BITALG__ 1
@@ -1724,9 +1724,9 @@
 // RUN: -target i386-unknown-linux \
 // RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_SPR_M64
 // CHECK_SPR_M64: #define __AES__ 1
-// CHECK_SPR_M64

[clang] 8998fa6 - [clang] Change AMX macros to match names from GCC

2023-02-03 Thread Joe Loser via cfe-commits

Author: Joe Loser
Date: 2023-02-03T07:00:16-07:00
New Revision: 8998fa6c14f1e19957858aa0e4b592d62ae56041

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

LOG: [clang] Change AMX macros to match names from GCC

The current behavior for AMX macros is:

```
gcc -march=native -dM -E - < /dev/null | grep TILE

clang -march=native -dM -E - < /dev/null | grep TILE
```

which is not ideal.  Change `__AMXTILE__` and friends to `__AMX_TILE__` (i.e.
have an underscore in them).  This makes GCC and Clang agree on the naming of
these AMX macros to simplify downstream user code.

Fix this for `__AMXTILE__`, `__AMX_INT8__`, `__AMX_BF16__`, and `__AMX_FP16__`.

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

Added: 


Modified: 
clang/lib/Basic/Targets/X86.cpp
clang/lib/Headers/immintrin.h
clang/test/Preprocessor/predefined-arch-macros.c
clang/test/Preprocessor/x86_amx_target_features.c
clang/test/Preprocessor/x86_target_features.c

Removed: 




diff  --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index cb31712275301..490e20ce4514e 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -795,13 +795,13 @@ void X86TargetInfo::getTargetDefines(const LangOptions 
&Opts,
   if (HasHRESET)
 Builder.defineMacro("__HRESET__");
   if (HasAMXTILE)
-Builder.defineMacro("__AMXTILE__");
+Builder.defineMacro("__AMX_TILE__");
   if (HasAMXINT8)
-Builder.defineMacro("__AMXINT8__");
+Builder.defineMacro("__AMX_INT8__");
   if (HasAMXBF16)
-Builder.defineMacro("__AMXBF16__");
+Builder.defineMacro("__AMX_BF16__");
   if (HasAMXFP16)
-Builder.defineMacro("__AMXFP16__");
+Builder.defineMacro("__AMX_FP16__");
   if (HasCMPCCXADD)
 Builder.defineMacro("__CMPCCXADD__");
   if (HasRAOINT)

diff  --git a/clang/lib/Headers/immintrin.h b/clang/lib/Headers/immintrin.h
index 6967b46fdb241..0d2e8be6e4862 100644
--- a/clang/lib/Headers/immintrin.h
+++ b/clang/lib/Headers/immintrin.h
@@ -524,7 +524,7 @@ _storebe_i64(void * __P, long long __D) {
 #include 
 #endif
 #if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  
\
-defined(__AMXFP16__)
+defined(__AMX_FP16__)
 #include 
 #endif
 
@@ -534,7 +534,7 @@ _storebe_i64(void * __P, long long __D) {
 #endif
 
 #if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  
\
-defined(__AMXTILE__) || defined(__AMXINT8__) || defined(__AMXBF16__)
+defined(__AMX_TILE__) || defined(__AMX_INT8__) || defined(__AMX_BF16__)
 #include 
 #endif
 

diff  --git a/clang/test/Preprocessor/predefined-arch-macros.c 
b/clang/test/Preprocessor/predefined-arch-macros.c
index a78bac132db15..a64e5afa7aac3 100644
--- a/clang/test/Preprocessor/predefined-arch-macros.c
+++ b/clang/test/Preprocessor/predefined-arch-macros.c
@@ -1649,9 +1649,9 @@
 // RUN: -target i386-unknown-linux \
 // RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_SPR_M32
 // CHECK_SPR_M32: #define __AES__ 1
-// CHECK_SPR_M32: #define __AMXBF16__ 1
-// CHECK_SPR_M32: #define __AMXINT8__ 1
-// CHECK_SPR_M32: #define __AMXTILE__ 1
+// CHECK_SPR_M32: #define __AMX_BF16__ 1
+// CHECK_SPR_M32: #define __AMX_INT8__ 1
+// CHECK_SPR_M32: #define __AMX_TILE__ 1
 // CHECK_SPR_M32: #define __AVX2__ 1
 // CHECK_SPR_M32: #define __AVX512BF16__ 1
 // CHECK_SPR_M32: #define __AVX512BITALG__ 1
@@ -1724,9 +1724,9 @@
 // RUN: -target i386-unknown-linux \
 // RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_SPR_M64
 // CHECK_SPR_M64: #define __AES__ 1
-// CHECK_SPR_M64: #define __AMXBF16__ 1
-// CHECK_SPR_M64: #define __AMXINT8__ 1
-// CHECK_SPR_M64: #define __AMXTILE__ 1
+// CHECK_SPR_M64: #define __AMX_BF16__ 1
+// CHECK_SPR_M64: #define __AMX_INT8__ 1
+// CHECK_SPR_M64: #define __AMX_TILE__ 1
 // CHECK_SPR_M64: #define __AVX2__ 1
 // CHECK_SPR_M64: #define __AVX512BF16__ 1
 // CHECK_SPR_M64: #define __AVX512BITALG__ 1
@@ -1797,10 +1797,10 @@
 // RUN: --target=i386 \
 // RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_GNR_M32
 // CHECK_GNR_M32: #define __AES__ 1
-// CHECK_GNR_M32: #define __AMXBF16__ 1
-// CHECK_GNR_M32: #define __AMXFP16__ 1
-// CHECK_GNR_M32: #define __AMXINT8__ 1
-// CHECK_GNR_M32: #define __AMXTILE__ 1
+// CHECK_GNR_M32: #define __AMX_BF16__ 1
+// CHECK_GNR_M32: #define __AMX_FP16__ 1
+// CHECK_GNR_M32: #define __AMX_INT8__ 1
+// CHECK_GNR_M32: #define __AMX_TILE__ 1
 // CHECK_GNR_M32: #define __AVX2__ 1
 // CHECK_GNR_M32: #define __AVX512BF16__ 1
 // CHECK_GNR_M32: #define __AVX512BITALG__ 1
@@ -1871,10 +1871,10 @@
 // RUN: --target=x86_64 \
 // RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_GNR_M64
 // CHECK_GNR_M64: #define __AES__ 1
-// CHECK_GNR_M64: #define __AMXBF16__ 1
-// CHECK_GNR

[clang] 7bb615e - [clang][Interp] Materializing primitive temporaries

2023-02-03 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-02-03T15:11:15+01:00
New Revision: 7bb615ea0ec015eb5991ddc00e0a3fc31cb2735e

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

LOG: [clang][Interp] Materializing primitive temporaries

Implement MaterializeTemporaryExpr for primitive types.

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

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/ByteCodeExprGen.h
clang/lib/AST/Interp/Interp.h
clang/lib/AST/Interp/Opcodes.td
clang/test/AST/Interp/references.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 4c3b6f59a3016..b02e3ae02ae7c 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -782,6 +782,57 @@ bool ByteCodeExprGen::VisitCompoundAssignOperator(
   return this->emitStore(*ResultT, E);
 }
 
+template 
+bool ByteCodeExprGen::VisitExprWithCleanups(
+const ExprWithCleanups *E) {
+  const Expr *SubExpr = E->getSubExpr();
+
+  assert(E->getNumObjects() == 0 && "TODO: Implement cleanups");
+  return this->visit(SubExpr);
+}
+
+template 
+bool ByteCodeExprGen::VisitMaterializeTemporaryExpr(
+const MaterializeTemporaryExpr *E) {
+  StorageDuration SD = E->getStorageDuration();
+
+  // We conservatively only support these for now.
+  if (SD != SD_Static && SD != SD_Automatic)
+return false;
+
+  const Expr *SubExpr = E->getSubExpr();
+  std::optional SubExprT = classify(SubExpr);
+  // FIXME: Implement this for records and arrays as well.
+  if (!SubExprT)
+return false;
+
+  if (SD == SD_Static) {
+if (std::optional GlobalIndex = P.createGlobal(E)) {
+  const LifetimeExtendedTemporaryDecl *TempDecl =
+  E->getLifetimeExtendedTemporaryDecl();
+
+  if (!this->visitInitializer(SubExpr))
+return false;
+
+  if (!this->emitInitGlobalTemp(*SubExprT, *GlobalIndex, TempDecl, E))
+return false;
+  return this->emitGetPtrGlobal(*GlobalIndex, E);
+}
+  } else if (SD == SD_Automatic) {
+if (std::optional LocalIndex =
+allocateLocalPrimitive(SubExpr, *SubExprT, true, true)) {
+  if (!this->visitInitializer(SubExpr))
+return false;
+
+  if (!this->emitSetLocal(*SubExprT, *LocalIndex, E))
+return false;
+  return this->emitGetPtrLocal(*LocalIndex, E);
+}
+  }
+
+  return false;
+}
+
 template  bool ByteCodeExprGen::discard(const Expr *E) 
{
   if (E->containsErrors())
 return false;

diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.h 
b/clang/lib/AST/Interp/ByteCodeExprGen.h
index 0a64ff3513dd8..540b9ec2f3d46 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -87,6 +87,8 @@ class ByteCodeExprGen : public 
ConstStmtVisitor, bool>,
   bool VisitCharacterLiteral(const CharacterLiteral *E);
   bool VisitCompoundAssignOperator(const CompoundAssignOperator *E);
   bool VisitFloatCompoundAssignOperator(const CompoundAssignOperator *E);
+  bool VisitExprWithCleanups(const ExprWithCleanups *E);
+  bool VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *E);
 
 protected:
   bool visitExpr(const Expr *E) override;

diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index b35cc017d3d70..99c1bd58acd25 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -818,6 +818,22 @@ bool InitGlobal(InterpState &S, CodePtr OpPC, uint32_t I) {
   return true;
 }
 
+/// 1) Converts the value on top of the stack to an APValue
+/// 2) Sets that APValue on \Temp
+/// 3) Initialized global with index \I with that
+template ::T>
+bool InitGlobalTemp(InterpState &S, CodePtr OpPC, uint32_t I,
+const LifetimeExtendedTemporaryDecl *Temp) {
+  assert(Temp);
+  const T Value = S.Stk.peek();
+  APValue APV = Value.toAPValue();
+  APValue *Cached = Temp->getOrCreateValue(true);
+  *Cached = APV;
+
+  S.P.getGlobal(I)->deref() = S.Stk.pop();
+  return true;
+}
+
 template ::T>
 bool InitThisField(InterpState &S, CodePtr OpPC, uint32_t I) {
   if (S.checkingPotentialConstantExpression())

diff  --git a/clang/lib/AST/Interp/Opcodes.td b/clang/lib/AST/Interp/Opcodes.td
index 8b49fb4e61b1b..d1ad7adc1edc6 100644
--- a/clang/lib/AST/Interp/Opcodes.td
+++ b/clang/lib/AST/Interp/Opcodes.td
@@ -49,6 +49,7 @@ def ArgRecordDecl : ArgType { let Name = "const RecordDecl 
*"; }
 def ArgRecordField : ArgType { let Name = "const Record::Field *"; }
 def ArgFltSemantics : ArgType { let Name = "const llvm::fltSemantics *"; }
 def ArgRoundingMode : ArgType { let Name = "llvm::RoundingMode"; }
+def ArgLETD: ArgType { let Name = "const LifetimeExtendedTemporaryDecl *"; }
 
 
//===

[PATCH] D136017: [clang][Interp] Materializing primitive temporaries

2023-02-03 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 rG7bb615ea0ec0: [clang][Interp] Materializing primitive 
temporaries (authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D136017?vs=468895&id=494606#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136017

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/Opcodes.td
  clang/test/AST/Interp/references.cpp

Index: clang/test/AST/Interp/references.cpp
===
--- clang/test/AST/Interp/references.cpp
+++ clang/test/AST/Interp/references.cpp
@@ -2,8 +2,6 @@
 // RUN: %clang_cc1 -verify=ref %s
 
 
-// ref-no-diagnostics
-
 constexpr int a = 10;
 constexpr const int &b = a;
 static_assert(a == b, "");
@@ -71,9 +69,22 @@
 }
 static_assert(testGetValue() == 30, "");
 
-// FIXME: ExprWithCleanups + MaterializeTemporaryExpr not implemented
-constexpr const int &MCE = 1; // expected-error{{must be initialized by a constant expression}}
+constexpr const int &MCE = 20;
+static_assert(MCE == 20, "");
+static_assert(MCE == 30, ""); // expected-error {{static assertion failed}} \
+  // expected-note {{evaluates to '20 == 30'}} \
+  // ref-error {{static assertion failed}} \
+  // ref-note {{evaluates to '20 == 30'}}
 
+constexpr int LocalMCE() {
+  const int &m = 100;
+  return m;
+}
+static_assert(LocalMCE() == 100, "");
+static_assert(LocalMCE() == 200, ""); // expected-error {{static assertion failed}} \
+  // expected-note {{evaluates to '100 == 200'}} \
+  // ref-error {{static assertion failed}} \
+  // ref-note {{evaluates to '100 == 200'}}
 
 struct S {
   int i, j;
Index: clang/lib/AST/Interp/Opcodes.td
===
--- clang/lib/AST/Interp/Opcodes.td
+++ clang/lib/AST/Interp/Opcodes.td
@@ -49,6 +49,7 @@
 def ArgRecordField : ArgType { let Name = "const Record::Field *"; }
 def ArgFltSemantics : ArgType { let Name = "const llvm::fltSemantics *"; }
 def ArgRoundingMode : ArgType { let Name = "llvm::RoundingMode"; }
+def ArgLETD: ArgType { let Name = "const LifetimeExtendedTemporaryDecl *"; }
 
 //===--===//
 // Classes of types instructions operate on.
@@ -332,6 +333,10 @@
 // [Value] -> []
 def InitGlobal : AccessOpcode;
 // [Value] -> []
+def InitGlobalTemp : AccessOpcode {
+  let Args = [ArgUint32, ArgLETD];
+}
+// [Value] -> []
 def SetGlobal : AccessOpcode;
 
 // [] -> [Value]
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -818,6 +818,22 @@
   return true;
 }
 
+/// 1) Converts the value on top of the stack to an APValue
+/// 2) Sets that APValue on \Temp
+/// 3) Initialized global with index \I with that
+template ::T>
+bool InitGlobalTemp(InterpState &S, CodePtr OpPC, uint32_t I,
+const LifetimeExtendedTemporaryDecl *Temp) {
+  assert(Temp);
+  const T Value = S.Stk.peek();
+  APValue APV = Value.toAPValue();
+  APValue *Cached = Temp->getOrCreateValue(true);
+  *Cached = APV;
+
+  S.P.getGlobal(I)->deref() = S.Stk.pop();
+  return true;
+}
+
 template ::T>
 bool InitThisField(InterpState &S, CodePtr OpPC, uint32_t I) {
   if (S.checkingPotentialConstantExpression())
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -87,6 +87,8 @@
   bool VisitCharacterLiteral(const CharacterLiteral *E);
   bool VisitCompoundAssignOperator(const CompoundAssignOperator *E);
   bool VisitFloatCompoundAssignOperator(const CompoundAssignOperator *E);
+  bool VisitExprWithCleanups(const ExprWithCleanups *E);
+  bool VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *E);
 
 protected:
   bool visitExpr(const Expr *E) override;
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -782,6 +782,57 @@
   return this->emitStore(*ResultT, E);
 }
 
+template 
+bool ByteCodeExprGen::VisitExprWithCleanups(
+const ExprWithCleanups *E) {
+  const Expr *SubExpr = E->getSubExpr();
+
+  assert(E->getNumObjects() == 0 && "TODO: Implement cleanups");
+  return this->visit(SubExpr);
+}
+
+template 
+bool ByteCodeExprGen::VisitMaterializeTemporaryExpr(
+const Materia

[PATCH] D140415: [flang] stack arrays pass

2023-02-03 Thread Kiran Chandramohan via Phabricator via cfe-commits
kiranchandramohan accepted this revision.
kiranchandramohan added a comment.
This revision is now accepted and ready to land.

LGTM. Please wait till end of day Monday before you submit to provide other 
reviewers with a chance to provide further comments or request changes.

You can consider inlining D141401  in this 
pass till it is merged.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140415

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


[PATCH] D143194: [clang][analyzer] Make messages of StdCLibraryFunctionsChecker user-friendly

2023-02-03 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added a comment.

I had the plan to add a note that tells the value that is out of range. In the 
most simple case it can work if we have a fixed value. But this may be the most 
obvious from the code too. Otherwise a new function can be added that can print 
the assumed constraint ranges.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143194

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


[PATCH] D127762: [Clang][AArch64] Add ACLE attributes for SME.

2023-02-03 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

So I still don't see this doing the module writing/reading part, which is 
necessary if you're making this part of the type.

I'd like to see more testing/thought put into how this interfaces with 
overloads and template resolution.

Finally, and this is something @aaron.ballman probably wants to answer:  Is 
this sufficiently important that we're willing to take the additional overhead 
of 8 bits for each function type (plus an extra 8 bits for its prototype?).  
Memory wise, this seems a little costly.




Comment at: clang/include/clang/AST/Type.h:3940
+/// on declarations and function pointers.
+unsigned AArch64SMEAttributes : 8;
+

sdesmalen wrote:
> erichkeane wrote:
> > sdesmalen wrote:
> > > erichkeane wrote:
> > > > We seem to be missing all of the modules-storage code for these.  Since 
> > > > this is modifying the AST, we need to increment the 'breaking change' 
> > > > AST code, plus add this to the ASTWriter/ASTReader interface.
> > > > Since this is modifying the AST, we need to increment the 'breaking 
> > > > change' AST code
> > > Could you give me some pointers on what you expect to see changed here? I 
> > > understand your point about adding this to the ASTWriter/Reader 
> > > interfaces for module-storage, but it's not entirely clear what you mean 
> > > by "increment the breaking change AST code". 
> > > 
> > > I see there is also an ASTImporter, I guess this different from the 
> > > ASTReader?
> > > 
> > > Please apologise my ignorance here, I'm not as familiar with the Clang 
> > > codebase.
> > See VersionMajor here: 
> > https://clang.llvm.org/doxygen/ASTBitCodes_8h_source.html
> > 
> > Yes, ASTReader/ASTWriter and ASTImporter are different unfortunately.  I'm 
> > not completely sure of the difference, but doing this patch changing the 
> > type here without doing those will break modules.
> So I tried to create some tests for this (see 
> clang/test/AST/ast-dump-sme-attributes.cpp) and realised that the 
> serialization/deserialization works out-of-the-box.
> 
> Does that mean all is needed is an increment of the VERSION_MAJOR or 
> VERSION_MINOR number?
So its not just ast-dump that matters, it is what happens when these functions 
are exported from a module, and imported from another?  Unless you make changes 
to those areas, this SME stuff will be lost, since you're making it part of the 
type.



Comment at: clang/test/Sema/aarch64-sme-func-attrs.c:172
+// expected-cpp-note@-4 {{candidate template ignored: could not match 'short 
(short) __attribute__((arm_streaming))' against 'short (short)'}}
+template short templated(short);
+#endif

What happens with implicit instantiations?  Can you make sure calling these 
doesn't lose the attribute?  Our implicit instantiation mechanism has an opt-in 
for a lot of attributes/etc.

Additionally, can these be overloaded on in C++?  I don't see any tests for 
this.  Since they are part of the function type, is that deduced properly? 
(that is, a function pointer passed as template argument, does it pick up the 
right type, and does it end up as a separate template isntantiation?).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127762

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


[PATCH] D136751: [clang][Interp] This pointers are writable in constructors

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

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136751

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


[PATCH] D142933: Add -print-multi-selection-flags argument

2023-02-03 Thread Michael Platings via Phabricator via cfe-commits
michaelplatings updated this revision to Diff 494610.
michaelplatings added a comment.

Bugfix: if -msoft-float is set then -mfpu should be none.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142933

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/ToolChain.h
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/Arch/ARM.cpp
  clang/lib/Driver/ToolChains/Arch/ARM.h
  clang/test/Driver/print-multi-selection-flags.c

Index: clang/test/Driver/print-multi-selection-flags.c
===
--- /dev/null
+++ clang/test/Driver/print-multi-selection-flags.c
@@ -0,0 +1,44 @@
+// RUN: %clang -print-multi-selection-flags-experimental --target=aarch64-linux -fc++-abi=itanium -fsanitize=address | FileCheck --check-prefix=CHECK-LINUX %s
+// CHECK-LINUX: fc++-abi=itanium
+// CHECK-LINUX-NEXT: fexceptions
+// CHECK-LINUX-NEXT: frtti
+// CHECK-LINUX-NEXT: fsanitize=address
+// CHECK-LINUX-NEXT: target=aarch64-unknown-linux
+
+// RUN: %clang -print-multi-selection-flags-experimental --target=aarch64-fuchsia -fsanitize=hwaddress | FileCheck --check-prefix=CHECK-FUCHSIA %s
+// CHECK-FUCHSIA: fsanitize=hwaddress
+// CHECK-FUCHSIA: target=aarch64-unknown-fuchsia
+
+// RUN: %clang -print-multi-selection-flags-experimental --target=arm-none-eabi -mfloat-abi=soft -fno-exceptions -fno-rtti | FileCheck --check-prefix=CHECK-ARMV4T %s
+// CHECK-ARMV4T: fno-exceptions
+// CHECK-ARMV4T: fno-rtti
+// CHECK-ARMV4T: mfloat-abi=soft
+// CHECK-ARMV4T: mfpu=none
+// CHECK-ARMV4T: target=armv4t-none-unknown-eabi
+
+// RUN: %clang -print-multi-selection-flags-experimental --target=armv7em-none-eabi -mfloat-abi=softfp | FileCheck --check-prefix=CHECK-SOFTFP %s
+// CHECK-SOFTFP: mfloat-abi=softfp
+// CHECK-SOFTFP: mfpu=fpv4-sp-d16
+// CHECK-SOFTFP: target=thumbv7em-none-unknown-eabi
+
+// RUN: %clang -print-multi-selection-flags-experimental --target=arm-none-eabihf -march=armv7em -mfpu=fpv5-d16 | FileCheck --check-prefix=CHECK-HARD %s
+// CHECK-HARD: mfloat-abi=hard
+// CHECK-HARD: mfpu=fpv5-d16
+// CHECK-HARD: target=thumbv7em-none-unknown-eabihf
+
+// RUN: %clang -print-multi-selection-flags-experimental --target=arm-none-eabi -mfloat-abi=soft -march=armv8-m.main+nofp | FileCheck --check-prefix=CHECK-V8MMAIN-NOFP %s
+// CHECK-V8MMAIN-NOFP: mfloat-abi=soft
+// CHECK-V8MMAIN-NOFP: mfpu=none
+// CHECK-V8MMAIN-NOFP: target=thumbv8m.main-none-unknown-eabi
+
+// RUN: %clang -print-multi-selection-flags-experimental --target=arm-none-eabi -mfloat-abi=hard -march=armv8.1m.main+mve.fp | FileCheck --check-prefix=CHECK-MVE %s
+// CHECK-MVE: march=+mve
+// CHECK-MVE: march=+mve.fp
+// CHECK-MVE: mfloat-abi=hard
+// CHECK-MVE: mfpu=fp-armv8-fullfp16-sp-d16
+// CHECK-MVE: target=thumbv8.1m.main-none-unknown-eabihf
+
+// RUN: %clang -print-multi-selection-flags-experimental --target=arm-none-eabi -march=armv8.1m.main+mve+nofp | FileCheck --check-prefix=CHECK-MVENOFP %s
+// CHECK-MVENOFP: march=+mve
+// CHECK-MVENOFP-NOT: march=+mve.fp
+// CHECK-MVENOFP: mfpu=none
Index: clang/lib/Driver/ToolChains/Arch/ARM.h
===
--- clang/lib/Driver/ToolChains/Arch/ARM.h
+++ clang/lib/Driver/ToolChains/Arch/ARM.h
@@ -64,9 +64,11 @@
 void getARMArchCPUFromArgs(const llvm::opt::ArgList &Args,
llvm::StringRef &Arch, llvm::StringRef &CPU,
bool FromAs = false);
+// Optionally returns the FPUKind
 void getARMTargetFeatures(const Driver &D, const llvm::Triple &Triple,
   const llvm::opt::ArgList &Args,
-  std::vector &Features, bool ForAS);
+  std::vector &Features, bool ForAS,
+  unsigned *OutFPUKind = nullptr);
 int getARMSubArchVersionNumber(const llvm::Triple &Triple);
 bool isARMMProfile(const llvm::Triple &Triple);
 bool isARMAProfile(const llvm::Triple &Triple);
Index: clang/lib/Driver/ToolChains/Arch/ARM.cpp
===
--- clang/lib/Driver/ToolChains/Arch/ARM.cpp
+++ clang/lib/Driver/ToolChains/Arch/ARM.cpp
@@ -438,7 +438,8 @@
 
 void arm::getARMTargetFeatures(const Driver &D, const llvm::Triple &Triple,
const ArgList &Args,
-   std::vector &Features, bool ForAS) {
+   std::vector &Features, bool ForAS,
+   unsigned *OutFPUKind) {
   bool KernelOrKext =
   Args.hasArg(options::OPT_mkernel, options::OPT_fapple_kext);
   arm::FloatABI ABI = arm::getARMFloatABI(D, Triple, Args);
@@ -632,6 +633,7 @@
 // above call.
 Features.insert(Features.end(), {"-dotprod", "-fp16fml", "-bf16", "-mve",
  "-mve.fp", "-fpregs"});
+FPUID = llvm::ARM::FK_NONE;

[PATCH] D142992: [include-mapping] Implement language separation in stdlib recognizer library

2023-02-03 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 494611.
hokein added a comment.

rebase to main


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142992

Files:
  clang/include/clang/Tooling/Inclusions/StandardLibrary.h
  clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
  clang/unittests/Tooling/StandardLibraryTest.cpp

Index: clang/unittests/Tooling/StandardLibraryTest.cpp
===
--- clang/unittests/Tooling/StandardLibraryTest.cpp
+++ clang/unittests/Tooling/StandardLibraryTest.cpp
@@ -40,6 +40,9 @@
   EXPECT_EQ(llvm::to_string(*VectorH), "");
   EXPECT_FALSE(stdlib::Header::named("HeadersTests.cpp"));
 
+  EXPECT_TRUE(stdlib::Header::named("", stdlib::Lang::CXX));
+  EXPECT_FALSE(stdlib::Header::named("", stdlib::Lang::C));
+
   auto Vector = stdlib::Symbol::named("std::", "vector");
   EXPECT_TRUE(Vector);
   EXPECT_EQ(Vector->scope(), "std::");
@@ -49,11 +52,21 @@
   EXPECT_FALSE(stdlib::Symbol::named("std::", "dongle"));
   EXPECT_FALSE(stdlib::Symbol::named("clang::", "ASTContext"));
 
+  EXPECT_TRUE(stdlib::Symbol::named("std::", "vector", stdlib::Lang::CXX));
+  EXPECT_FALSE(stdlib::Symbol::named("std::", "vector", stdlib::Lang::C));
+
   EXPECT_EQ(Vector->header(), *VectorH);
   EXPECT_THAT(Vector->headers(), ElementsAre(*VectorH));
 
   EXPECT_THAT(stdlib::Header::all(), Contains(*VectorH));
   EXPECT_THAT(stdlib::Symbol::all(), Contains(*Vector));
+  EXPECT_FALSE(stdlib::Header::named(""));
+  EXPECT_FALSE(stdlib::Header::named("", stdlib::Lang::CXX));
+  EXPECT_TRUE(stdlib::Header::named("", stdlib::Lang::C));
+
+  EXPECT_FALSE(stdlib::Symbol::named("", "int16_t"));
+  EXPECT_FALSE(stdlib::Symbol::named("", "int16_t", stdlib::Lang::CXX));
+  EXPECT_TRUE(stdlib::Symbol::named("", "int16_t", stdlib::Lang::C));
 }
 
 TEST(StdlibTest, Recognizer) {
@@ -104,10 +117,14 @@
 
   EXPECT_EQ(Recognizer(&VectorNonstd), std::nullopt);
   EXPECT_EQ(Recognizer(Vec), stdlib::Symbol::named("std::", "vector"));
+  EXPECT_EQ(Recognizer(Vec),
+stdlib::Symbol::named("std::", "vector", stdlib::Lang::CXX));
   EXPECT_EQ(Recognizer(Nest), stdlib::Symbol::named("std::", "vector"));
   EXPECT_EQ(Recognizer(Clock),
 stdlib::Symbol::named("std::chrono::", "system_clock"));
   EXPECT_EQ(Recognizer(CDivT), stdlib::Symbol::named("", "div_t"));
+  EXPECT_EQ(Recognizer(CDivT),
+stdlib::Symbol::named("", "div_t", stdlib::Lang::C));
   EXPECT_EQ(Recognizer(Sec), std::nullopt);
 }
 
Index: clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
===
--- clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
+++ clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
@@ -8,6 +8,7 @@
 
 #include "clang/Tooling/Inclusions/StandardLibrary.h"
 #include "clang/AST/Decl.h"
+#include "clang/Basic/LangOptions.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Casting.h"
 
@@ -15,46 +16,74 @@
 namespace tooling {
 namespace stdlib {
 
-// Header::ID => header name
-static llvm::StringRef *HeaderNames;
-// Header name => Header::ID
-static llvm::DenseMap *HeaderIDs;
-
-static unsigned SymbolCount = 0;
-// Symbol::ID => symbol qualified_name/name/scope
-static struct SymbolName {
-  const char *Data;  // std::vector
-  unsigned ScopeLen; // ~
-  unsigned NameLen;  //  ~~
-} *SymbolNames;
+namespace {
 // Symbol name -> Symbol::ID, within a namespace.
 using NSSymbolMap = llvm::DenseMap;
-static llvm::DenseMap *NamespaceSymbols;
-// Symbol::ID => Header::ID
-static unsigned *SymbolHeaderIDs;
 
-static int initialize() {
-  SymbolCount = 0;
-#define SYMBOL(Name, NS, Header) ++SymbolCount;
+// A Mapping per language.
+struct SymbolHeaderMapping {
+  llvm::StringRef *HeaderNames = nullptr;
+  // Header name => Header::ID
+  llvm::DenseMap *HeaderIDs;
+
+  unsigned SymbolCount = 0;
+  // Symbol::ID => symbol qualified_name/name/scope
+  struct SymbolName {
+const char *Data;  // std::vector
+unsigned ScopeLen; // ~
+unsigned NameLen;  //  ~~
+  } *SymbolNames = nullptr;
+  // Symbol name -> Symbol::ID, within a namespace.
+  llvm::DenseMap *NamespaceSymbols = nullptr;
+  // Symbol::ID => Header::ID
+  unsigned *SymbolHeaderIDs = nullptr;
+};
+} // namespace
+static SymbolHeaderMapping
+*LanguageMappings[static_cast(Lang::LastValue) + 1];
+static const SymbolHeaderMapping *getMappingPerLang(Lang L) {
+  return LanguageMappings[static_cast(L)];
+}
+
+static int countSymbols(Lang Language) {
+  unsigned SymCount = 0;
+#define SYMBOL(Name, NS, Header) ++SymCount;
+  switch (Language) {
+  case Lang::C:
 #include "clang/Tooling/Inclusions/CSymbolMap.inc"
+break;
+  case Lang::CXX:
 #include "clang/Tooling/Inclusions/StdSymbolMap.inc"
+break;
+  }
 #undef SYMBOL
-  SymbolNames =
-  new std::remove_reference_t[SymbolCount];
-  SymbolHeaderIDs =
-  new s

[clang] 0505c0b - [clang][Interp][NFC] Make VariableScope::getParent() const

2023-02-03 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-02-03T15:35:42+01:00
New Revision: 0505c0b8cc998399979fcb970634dc8ee974dc7d

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

LOG: [clang][Interp][NFC] Make VariableScope::getParent() const

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.h

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.h 
b/clang/lib/AST/Interp/ByteCodeExprGen.h
index 540b9ec2f3d4..6b16b62a2e58 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -297,7 +297,7 @@ template  class VariableScope {
 
   virtual void emitDestruction() {}
 
-  VariableScope *getParent() { return Parent; }
+  VariableScope *getParent() const { return Parent; }
 
 protected:
   /// ByteCodeExprGen instance.



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


[PATCH] D142694: [clang][Interp] Only generate disassembly in debug builds

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

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142694

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


[clang] 60dcc70 - [clang][Interp] Only generate disassembly in debug builds

2023-02-03 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-02-03T15:40:25+01:00
New Revision: 60dcc70e48fa9814a4e0d5e12856bc88b7f927eb

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

LOG: [clang][Interp] Only generate disassembly in debug builds

With the current set of opcodes, this saves 3460 lines in the generated
Opcodes.inc in release builds (-17%).

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

Added: 


Modified: 
clang/lib/AST/Interp/Disasm.cpp
clang/utils/TableGen/ClangOpcodesEmitter.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Disasm.cpp b/clang/lib/AST/Interp/Disasm.cpp
index 1c95782536fba..aa07c0d7b8159 100644
--- a/clang/lib/AST/Interp/Disasm.cpp
+++ b/clang/lib/AST/Interp/Disasm.cpp
@@ -34,6 +34,7 @@ template  inline T ReadArg(Program &P, CodePtr 
&OpPC) {
 LLVM_DUMP_METHOD void Function::dump() const { dump(llvm::errs()); }
 
 LLVM_DUMP_METHOD void Function::dump(llvm::raw_ostream &OS) const {
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
   if (F) {
 if (const auto *MD = dyn_cast(F))
   OS << MD->getParent()->getDeclName() << "::";
@@ -64,6 +65,7 @@ LLVM_DUMP_METHOD void Function::dump(llvm::raw_ostream &OS) 
const {
 #undef GET_DISASM
 }
   }
+#endif
 }
 
 LLVM_DUMP_METHOD void Program::dump() const { dump(llvm::errs()); }

diff  --git a/clang/utils/TableGen/ClangOpcodesEmitter.cpp 
b/clang/utils/TableGen/ClangOpcodesEmitter.cpp
index aa012233c46ee..c4992ef7d25b7 100644
--- a/clang/utils/TableGen/ClangOpcodesEmitter.cpp
+++ b/clang/utils/TableGen/ClangOpcodesEmitter.cpp
@@ -161,6 +161,7 @@ void ClangOpcodesEmitter::EmitInterp(raw_ostream &OS, 
StringRef N, Record *R) {
 }
 
 void ClangOpcodesEmitter::EmitDisasm(raw_ostream &OS, StringRef N, Record *R) {
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
   OS << "#ifdef GET_DISASM\n";
   Enumerate(R, N, [R, &OS](ArrayRef, const Twine &ID) {
 OS << "case OP_" << ID << ":\n";
@@ -176,6 +177,7 @@ void ClangOpcodesEmitter::EmitDisasm(raw_ostream &OS, 
StringRef N, Record *R) {
 OS << "  continue;\n";
   });
   OS << "#endif\n";
+#endif
 }
 
 void ClangOpcodesEmitter::EmitEmitter(raw_ostream &OS, StringRef N, Record *R) 
{



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


[PATCH] D142694: [clang][Interp] Only generate disassembly in debug builds

2023-02-03 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 rG60dcc70e48fa: [clang][Interp] Only generate disassembly in 
debug builds (authored by tbaeder).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142694

Files:
  clang/lib/AST/Interp/Disasm.cpp
  clang/utils/TableGen/ClangOpcodesEmitter.cpp


Index: clang/utils/TableGen/ClangOpcodesEmitter.cpp
===
--- clang/utils/TableGen/ClangOpcodesEmitter.cpp
+++ clang/utils/TableGen/ClangOpcodesEmitter.cpp
@@ -161,6 +161,7 @@
 }
 
 void ClangOpcodesEmitter::EmitDisasm(raw_ostream &OS, StringRef N, Record *R) {
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
   OS << "#ifdef GET_DISASM\n";
   Enumerate(R, N, [R, &OS](ArrayRef, const Twine &ID) {
 OS << "case OP_" << ID << ":\n";
@@ -176,6 +177,7 @@
 OS << "  continue;\n";
   });
   OS << "#endif\n";
+#endif
 }
 
 void ClangOpcodesEmitter::EmitEmitter(raw_ostream &OS, StringRef N, Record *R) 
{
Index: clang/lib/AST/Interp/Disasm.cpp
===
--- clang/lib/AST/Interp/Disasm.cpp
+++ clang/lib/AST/Interp/Disasm.cpp
@@ -34,6 +34,7 @@
 LLVM_DUMP_METHOD void Function::dump() const { dump(llvm::errs()); }
 
 LLVM_DUMP_METHOD void Function::dump(llvm::raw_ostream &OS) const {
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
   if (F) {
 if (const auto *MD = dyn_cast(F))
   OS << MD->getParent()->getDeclName() << "::";
@@ -64,6 +65,7 @@
 #undef GET_DISASM
 }
   }
+#endif
 }
 
 LLVM_DUMP_METHOD void Program::dump() const { dump(llvm::errs()); }


Index: clang/utils/TableGen/ClangOpcodesEmitter.cpp
===
--- clang/utils/TableGen/ClangOpcodesEmitter.cpp
+++ clang/utils/TableGen/ClangOpcodesEmitter.cpp
@@ -161,6 +161,7 @@
 }
 
 void ClangOpcodesEmitter::EmitDisasm(raw_ostream &OS, StringRef N, Record *R) {
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
   OS << "#ifdef GET_DISASM\n";
   Enumerate(R, N, [R, &OS](ArrayRef, const Twine &ID) {
 OS << "case OP_" << ID << ":\n";
@@ -176,6 +177,7 @@
 OS << "  continue;\n";
   });
   OS << "#endif\n";
+#endif
 }
 
 void ClangOpcodesEmitter::EmitEmitter(raw_ostream &OS, StringRef N, Record *R) {
Index: clang/lib/AST/Interp/Disasm.cpp
===
--- clang/lib/AST/Interp/Disasm.cpp
+++ clang/lib/AST/Interp/Disasm.cpp
@@ -34,6 +34,7 @@
 LLVM_DUMP_METHOD void Function::dump() const { dump(llvm::errs()); }
 
 LLVM_DUMP_METHOD void Function::dump(llvm::raw_ostream &OS) const {
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
   if (F) {
 if (const auto *MD = dyn_cast(F))
   OS << MD->getParent()->getDeclName() << "::";
@@ -64,6 +65,7 @@
 #undef GET_DISASM
 }
   }
+#endif
 }
 
 LLVM_DUMP_METHOD void Program::dump() const { dump(llvm::errs()); }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D142123: [clang-tidy] Add header guard style to suggest use of #pragma once

2023-02-03 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/readability/header-guard.rst:31
+ Use ``#pragma once`` instead of macro guards. Note that ``#pragma once``
+ is not part of the C++ standard, and may not work correctly in all cases.

It's also not in the C standard, so reworded slightly.



Comment at: 
clang-tools-extra/unittests/clang-tidy/ReadabilityModuleTest.cpp:569-571
+runPragmaOnceCheck("#ifndef BOTH_H\n"
+   "#define BOTH_H\n"
+   "#pragma once\n"

How about a test for:
```
#if !defined(HEADER_GUARD_H)
#define HEADER_GUARD_H 1

#endif
```
and a test for what happens when there's no header guard or pragma once in the 
file.


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

https://reviews.llvm.org/D142123

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


[PATCH] D127762: [Clang][AArch64] Add ACLE attributes for SME.

2023-02-03 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D127762#4102436 , @erichkeane 
wrote:

> Finally, and this is something @aaron.ballman probably wants to answer:  Is 
> this sufficiently important that we're willing to take the additional 
> overhead of 8 bits for each function type (plus an extra 8 bits for its 
> prototype?).  Memory wise, this seems a little costly.

It'd be nice to have a rough idea of what the overhead costs are. I think we 
can steal a few bits back to reduce memory overhead if necessary.




Comment at: clang/include/clang/AST/Type.h:4123
 bool HasTrailingReturn : 1;
+unsigned AArch64SMEAttributes : 8;
 Qualifiers TypeQuals;

We could steal two bits back here and make this a 6-bit bit-field (we'd 
probably want to adjust `SME_AttributeMask` accordingly as well).



Comment at: clang/include/clang/Basic/AttrDocs.td:6322
+
+Only when Clang defines __ARM_FEATURE_SME, the support for this feature is
+considered to be stable and complete.

aaron.ballman wrote:
> Double-checking: that macro is missing the trailing double underscore, is 
> that expected?
Still wondering on this.



Comment at: clang/lib/Sema/SemaDecl.cpp:3746-3753
+  // It is not allowed to redeclare an SME function with different SME
+  // attributes.
+  if (IsInvalidSMECallConversion(Old->getType(), New->getType())) {
+Diag(New->getLocation(), diag::err_sme_attr_mismatch)
+<< New->getType() << Old->getType();
+Diag(OldLocation, diag::note_previous_declaration);
+return true;

sdesmalen wrote:
> aaron.ballman wrote:
> > How should these work with template (partial) specializations? Should it be 
> > invalid to write this on the primary template? Should it be invalid if the 
> > specialization doesn't match the primary template?
> Can you share an example of what you're thinking of?
> 
> Do you mean something like:
> 
>   template void (*a)(T, T);
>   template<> __attribute__((arm_streaming)) void (*a)(int, int);
> 
> where calling `a(0, 0)` and `a(0, 0)` have different 
> streaming-mode behaviour? If so, then that is the intent. The SME attributes 
> behave similar to a calling convention attributes, with the difference that 
> more than one attribute can be applied.
Yup, that's the scenario I was wondering about -- thanks for the answer (and I 
see test coverage for the situation as well).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127762

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


[clang] a7f3bca - [clang][Interp][NFCI] Handle DiscardResult for ExprWithCleanups

2023-02-03 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-02-03T16:07:14+01:00
New Revision: a7f3bcaa8409f67e604bcbe22a960f54ebc657ef

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

LOG: [clang][Interp][NFCI] Handle DiscardResult for ExprWithCleanups

Just pop the pointer.

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index b02e3ae02ae7..f8ee3a80326b 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -788,7 +788,12 @@ bool ByteCodeExprGen::VisitExprWithCleanups(
   const Expr *SubExpr = E->getSubExpr();
 
   assert(E->getNumObjects() == 0 && "TODO: Implement cleanups");
-  return this->visit(SubExpr);
+  if (!this->visit(SubExpr))
+return false;
+
+  if (DiscardResult)
+return this->emitPopPtr(E);
+  return true;
 }
 
 template 



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


[PATCH] D127762: [Clang][AArch64] Add ACLE attributes for SME.

2023-02-03 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

In D127762#4102526 , @aaron.ballman 
wrote:

> In D127762#4102436 , @erichkeane 
> wrote:
>
>> Finally, and this is something @aaron.ballman probably wants to answer:  Is 
>> this sufficiently important that we're willing to take the additional 
>> overhead of 8 bits for each function type (plus an extra 8 bits for its 
>> prototype?).  Memory wise, this seems a little costly.
>
> It'd be nice to have a rough idea of what the overhead costs are. I think we 
> can steal a few bits back to reduce memory overhead if necessary.

I just have knowing how much memory per-function-type, which is 2 bytes per at 
the moment it looks (1 for the function type, 1 for the prototype).  Reducing 
it to 6 bits saves us 1 of those bytes I think, but the one on 
`FunctionTypeExtraBitfields` doesn't save us anything.  That said... its 
entirely possible to make it cost nothing there now that I look... It is 
`align-as void*`, so align 4 or 8 depending on the platform.  It currently 
contains a single `unsigned` (so 4 bytes) for the number of types in an 
exception spec.  So on 64 bit systems, we currently don't use any additional 
memory there as far as I can tell, but on 32 bit systems this likely costs 32 
bits there (despite being an 8 bit bitfield).

By standard imp-limits, apparently we only need to handle 8 bits worth for the 
Exception Spec types.  I'd be tempted, based on exception specs being 
deprecated and rarely used, to reduce it to an 'unsigned short' (2 bytes), 
which makes this cost-free on 32 bit machines.  WDYT?




Comment at: clang/include/clang/AST/Type.h:4123
 bool HasTrailingReturn : 1;
+unsigned AArch64SMEAttributes : 8;
 Qualifiers TypeQuals;

aaron.ballman wrote:
> We could steal two bits back here and make this a 6-bit bit-field (we'd 
> probably want to adjust `SME_AttributeMask` accordingly as well).
That would be nice at least here, since Variadic/TrailingReturn would use the 
other 2, and mean that htis takes zero more data, instead of an entire 
additional byte.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127762

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


[clang] 0bf5845 - [Tooling/Inclusions] ensure the Mapping is inititalized in

2023-02-03 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2023-02-03T16:10:05+01:00
New Revision: 0bf58458d31e238b4ae850e2a0d934190c6682cc

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

LOG: [Tooling/Inclusions] ensure the Mapping is inititalized in
Symbol/Header::all() calls

Added: 


Modified: 
clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp

Removed: 




diff  --git a/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp 
b/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
index cc084c4d5689..9d06657df18a 100644
--- a/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
+++ b/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
@@ -93,6 +93,7 @@ static void ensureInitialized() {
 }
 
 std::vector Header::all() {
+  ensureInitialized();
   std::vector Result;
   Result.reserve(HeaderIDs->size());
   for (unsigned I = 0, E = HeaderIDs->size(); I < E; ++I)
@@ -109,6 +110,7 @@ std::optional Header::named(llvm::StringRef Name) {
 llvm::StringRef Header::name() const { return HeaderNames[ID]; }
 
 std::vector Symbol::all() {
+  ensureInitialized();
   std::vector Result;
   Result.reserve(SymbolCount);
   for (unsigned I = 0, E = SymbolCount; I < E; ++I)



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


[PATCH] D142609: [Clang] Fix -Wconstant-logical-operand when LHS is a constant

2023-02-03 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta updated this revision to Diff 494629.
xgupta added a comment.

clang-format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142609

Files:
  clang/lib/Sema/SemaExpr.cpp


Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -13600,19 +13600,18 @@
 Diag(Loc, diag::warn_enum_constant_in_bool_context);
 
   // Diagnose cases where the user write a logical and/or but probably meant a
-  // bitwise one.  We do this when one of the operand is a non-bool integer and
-  // the other is a constant.
-  if (!EnumConstantInBoolContext &&
-  LHS.get()->getType()->isIntegerType() &&
-!LHS.get()->getType()->isBooleanType() &&
-RHS.get()->getType()->isIntegerType() &&
-!RHS.get()->isValueDependent() &&
+  // bitwise one.  We do this when the LHS is a non-bool integer and the RHS
+  // is a constant.
+  if (!EnumConstantInBoolContext && LHS.get()->getType()->isIntegerType() &&
+  !LHS.get()->getType()->isBooleanType() &&
+  RHS.get()->getType()->isIntegerType() && !RHS.get()->isValueDependent() 
&&
   // Don't warn in macros or template instantiations.
   !Loc.isMacroID() && !inTemplateInstantiation()) {
-// If the operand can be constant folded, and if it constant folds to
-// something that isn't 0 or 1 (which indicate a potential logical 
operation
-// that happened to fold to true/false) then warn. Parens on the operand 
are
-// ignored.
+
+// If the RHS can be constant folded, and if it constant folds to something
+// that isn't 0 or 1 (which indicate a potential logical operation that
+// happened to fold to true/false) then warn.
+// Parens on the RHS are ignored.
 Expr::EvalResult EVResult;
 
 if (RHS.get()->EvaluateAsInt(EVResult, Context)) {
@@ -13636,25 +13635,21 @@
  RHS.get()->getEndLoc()));
   }
 }
-}
-
+  }
   // Diagnose cases where the user write a logical and/or but probably meant a
-  // bitwise one.  We do this when one of the operand is a non-bool integer and
-  // the other is a constant.
-  if (!EnumConstantInBoolContext &&
-  RHS.get()->getType()->isIntegerType() &&
-!RHS.get()->getType()->isBooleanType() &&
-LHS.get()->getType()->isIntegerType() &&
-!LHS.get()->isValueDependent() &&
+  // bitwise one.  We do this when the RHS is a non-bool integer and the LHS
+  // is a constant.
+  if (!EnumConstantInBoolContext && RHS.get()->getType()->isIntegerType() &&
+  !RHS.get()->getType()->isBooleanType() &&
+  LHS.get()->getType()->isIntegerType() && !LHS.get()->isValueDependent() 
&&
   // Don't warn in macros or template instantiations.
   !Loc.isMacroID() && !inTemplateInstantiation()) {
-// If the operand can be constant folded, and if it constant folds to
-// something that isn't 0 or 1 (which indicate a potential logical 
operation
-// that happened to fold to true/false) then warn. Parens on the operand 
are
-// ignored.
+// If the LHS can be constant folded, and if it constant folds to something
+// that isn't 0 or 1 (which indicate a potential logical operation that
+// happened to fold to true/false) then warn.
+// Parens on the LHS are ignored.
 Expr::EvalResult EVResult;
 
-
 if (LHS.get()->EvaluateAsInt(EVResult, Context)) {
   llvm::APSInt Result = EVResult.Val.getInt();
   if ((getLangOpts().Bool && !LHS.get()->getType()->isBooleanType() &&
@@ -13669,7 +13664,7 @@
SourceRange(Loc, getLocForEndOfToken(Loc)),
Opc == BO_LAnd ? "&" : "|");
 if (Opc == BO_LAnd)
-  // Suggest replacing "kNonZero && foo() " with "Foo()"
+  // Suggest replacing "kNonZero" && Foo() with "Foo()"
   Diag(Loc, diag::note_logical_instead_of_bitwise_remove_constant)
   << FixItHint::CreateRemoval(
  SourceRange(getLocForEndOfToken(RHS.get()->getEndLoc()),


Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -13600,19 +13600,18 @@
 Diag(Loc, diag::warn_enum_constant_in_bool_context);
 
   // Diagnose cases where the user write a logical and/or but probably meant a
-  // bitwise one.  We do this when one of the operand is a non-bool integer and
-  // the other is a constant.
-  if (!EnumConstantInBoolContext &&
-  LHS.get()->getType()->isIntegerType() &&
-!LHS.get()->getType()->isBooleanType() &&
-RHS.get()->getType()->isIntegerType() &&
-!RHS.get()->isValueDependent() &&
+  // bitwise one.  We do this when the LHS is a non-bool integer and the RHS
+  // is a constant.
+  if (!EnumConstantInBoolContext && LHS.get()->getType()->isIntegerType() &&
+

[PATCH] D142609: [Clang] Fix -Wconstant-logical-operand when LHS is a constant

2023-02-03 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta updated this revision to Diff 494631.
xgupta added a comment.

remov blank


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142609

Files:
  clang/lib/Sema/SemaExpr.cpp
  clang/test/C/drs/dr4xx.c
  clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p5.cpp
  clang/test/Parser/cxx2a-concept-declaration.cpp
  clang/test/Sema/exprs.c
  clang/test/SemaCXX/expressions.cpp
  clang/test/SemaCXX/warn-unsequenced.cpp
  clang/test/SemaTemplate/dependent-expr.cpp

Index: clang/test/SemaTemplate/dependent-expr.cpp
===
--- clang/test/SemaTemplate/dependent-expr.cpp
+++ clang/test/SemaTemplate/dependent-expr.cpp
@@ -43,7 +43,9 @@
 
 namespace PR7724 {
   template int myMethod()
-  { return 2 && sizeof(OT); }
+  { return 2 && sizeof(OT); } // expected-warning {{use of logical '&&' with constant operand}} \
+  // expected-note {{use '&' for a bitwise operation}} \
+  // expected-note {{remove constant to silence this warning}}
 }
 
 namespace test4 {
Index: clang/test/SemaCXX/warn-unsequenced.cpp
===
--- clang/test/SemaCXX/warn-unsequenced.cpp
+++ clang/test/SemaCXX/warn-unsequenced.cpp
@@ -76,15 +76,37 @@
 
   (xs[2] && (a = 0)) + a; // cxx11-warning {{unsequenced modification and access to 'a'}}
   // cxx17-warning@-1 {{unsequenced modification and access to 'a'}}
-  (0 && (a = 0)) + a; // ok
+
+  (0 && (a = 0)) + a; // cxx11-warning {{use of logical '&&' with constant operand}}
+  // cxx11-note@-1 {{use '&' for a bitwise operation}}
+  // cxx11-note@-2 {{remove constant to silence this warning}}
+  // cxx17-warning@-3 {{use of logical '&&' with constant operand}}
+  // cxx17-note@-4 {{use '&' for a bitwise operation}}
+  // cxx17-note@-5 {{remove constant to silence this warning}}
+
   (1 && (a = 0)) + a; // cxx11-warning {{unsequenced modification and access to 'a'}}
   // cxx17-warning@-1 {{unsequenced modification and access to 'a'}}
+  // cxx11-warning@-2 {{use of logical '&&' with constant operand}}
+  // cxx11-note@-3 {{use '&' for a bitwise operation}}
+  // cxx11-note@-4 {{remove constant to silence this warning}}
+  // cxx17-warning@-5 {{use of logical '&&' with constant operand}}
+  // cxx17-note@-6 {{use '&' for a bitwise operation}}
+  // cxx17-note@-7 {{remove constant to silence this warning}}
+
 
   (xs[3] || (a = 0)) + a; // cxx11-warning {{unsequenced modification and access to 'a'}}
   // cxx17-warning@-1 {{unsequenced modification and access to 'a'}}
   (0 || (a = 0)) + a; // cxx11-warning {{unsequenced modification and access to 'a'}}
   // cxx17-warning@-1 {{unsequenced modification and access to 'a'}}
-  (1 || (a = 0)) + a; // ok
+  // cxx11-warning@-2 {{use of logical '||' with constant operand}}
+  // cxx11-note@-3 {{use '|' for a bitwise operation}}
+  // cxx17-warning@-4 {{use of logical '||' with constant operand}}
+  // cxx17-note@-5 {{use '|' for a bitwise operation}}
+  (1 || (a = 0)) + a; // cxx11-warning {{use of logical '||' with constant operand}}
+  // cxx11-note@-1 {{use '|' for a bitwise operation}}
+  // cxx17-warning@-2 {{use of logical '||' with constant operand}}
+  // cxx17-note@-3 {{use '|' for a bitwise operation}}
+
 
   (xs[4] ? a : ++a) + a; // cxx11-warning {{unsequenced modification and access to 'a'}}
  // cxx17-warning@-1 {{unsequenced modification and access to 'a'}}
Index: clang/test/SemaCXX/expressions.cpp
===
--- clang/test/SemaCXX/expressions.cpp
+++ clang/test/SemaCXX/expressions.cpp
@@ -44,6 +44,9 @@
   return x && 4; // expected-warning {{use of logical '&&' with constant operand}} \
// expected-note {{use '&' for a bitwise operation}} \
// expected-note {{remove constant to silence this warning}}
+  return 4 && x; // expected-warning {{use of logical '&&' with constant operand}} \
+   // expected-note {{use '&' for a bitwise operation}} \
+   // expected-note {{remove constant to silence this warning}}
 
   return x && sizeof(int) == 4;  // no warning, RHS is logical op.
   return x && true;
@@ -66,6 +69,8 @@
// expected-note {{use '|' for a bitwise operation}}
   return x || 5; // expected-warning {{use of logical '||' with constant operand}} \
// expected-no

[clang] 5059193 - Revert "[clang][Interp] Only generate disassembly in debug builds"

2023-02-03 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-02-03T16:24:04+01:00
New Revision: 50591936a1befc44f2853f1a6493ee1ef2afaa6e

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

LOG: Revert "[clang][Interp] Only generate disassembly in debug builds"

This reverts commit 60dcc70e48fa9814a4e0d5e12856bc88b7f927eb.

This breaks builders, e.g.
https://lab.llvm.org/buildbot/#/builders/36/builds/30036

Added: 


Modified: 
clang/lib/AST/Interp/Disasm.cpp
clang/utils/TableGen/ClangOpcodesEmitter.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Disasm.cpp b/clang/lib/AST/Interp/Disasm.cpp
index aa07c0d7b8159..1c95782536fba 100644
--- a/clang/lib/AST/Interp/Disasm.cpp
+++ b/clang/lib/AST/Interp/Disasm.cpp
@@ -34,7 +34,6 @@ template  inline T ReadArg(Program &P, CodePtr 
&OpPC) {
 LLVM_DUMP_METHOD void Function::dump() const { dump(llvm::errs()); }
 
 LLVM_DUMP_METHOD void Function::dump(llvm::raw_ostream &OS) const {
-#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
   if (F) {
 if (const auto *MD = dyn_cast(F))
   OS << MD->getParent()->getDeclName() << "::";
@@ -65,7 +64,6 @@ LLVM_DUMP_METHOD void Function::dump(llvm::raw_ostream &OS) 
const {
 #undef GET_DISASM
 }
   }
-#endif
 }
 
 LLVM_DUMP_METHOD void Program::dump() const { dump(llvm::errs()); }

diff  --git a/clang/utils/TableGen/ClangOpcodesEmitter.cpp 
b/clang/utils/TableGen/ClangOpcodesEmitter.cpp
index c4992ef7d25b7..aa012233c46ee 100644
--- a/clang/utils/TableGen/ClangOpcodesEmitter.cpp
+++ b/clang/utils/TableGen/ClangOpcodesEmitter.cpp
@@ -161,7 +161,6 @@ void ClangOpcodesEmitter::EmitInterp(raw_ostream &OS, 
StringRef N, Record *R) {
 }
 
 void ClangOpcodesEmitter::EmitDisasm(raw_ostream &OS, StringRef N, Record *R) {
-#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
   OS << "#ifdef GET_DISASM\n";
   Enumerate(R, N, [R, &OS](ArrayRef, const Twine &ID) {
 OS << "case OP_" << ID << ":\n";
@@ -177,7 +176,6 @@ void ClangOpcodesEmitter::EmitDisasm(raw_ostream &OS, 
StringRef N, Record *R) {
 OS << "  continue;\n";
   });
   OS << "#endif\n";
-#endif
 }
 
 void ClangOpcodesEmitter::EmitEmitter(raw_ostream &OS, StringRef N, Record *R) 
{



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


[PATCH] D124351: [Clang] Implement Change scope of lambda trailing-return-type

2023-02-03 Thread Evgeny Eltsin via Phabricator via cfe-commits
eaeltsin added a comment.

> Looks like we fail to enter the appropriate context somewhere (my guess is 
> that it might be specific to the attribute but it's hard to say without 
> picking around), definitely a bug
>
> I'll be away the next 2 weeks, I'll look at it when I get back. Maybe we 
> should track it in an issue though.

Should we revert this then?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124351

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


[PATCH] D142800: [Clang][Diagnostic] Add `-Wcomparison-op-parentheses` to warn on chained comparisons

2023-02-03 Thread Takuya Shimizu via Phabricator via cfe-commits
hazohelet updated this revision to Diff 494635.
hazohelet added a comment.

Address comments from erichkeane:

- Fix comment wording
- Avoid using macro in test file

Implement my proposal for fix-it hint:

- In the case of chained relational operators (`<`, `>`, `<=`, `>=`), suggest 
adding `&&`.
- In other cases, suggest parentheses.


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

https://reviews.llvm.org/D142800

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Misc/warning-wall.c
  clang/test/Sema/comparison-op-parentheses.c
  libcxx/test/support/test_comparisons.h

Index: libcxx/test/support/test_comparisons.h
===
--- libcxx/test/support/test_comparisons.h
+++ libcxx/test/support/test_comparisons.h
@@ -162,7 +162,7 @@
 bool less= order == Order::less;
 bool greater = order == Order::greater;
 
-return (t1 <=> t2 == order) && testComparisonsComplete(t1, t2, equal, less, greater);
+return ((t1 <=> t2) == order) && testComparisonsComplete(t1, t2, equal, less, greater);
 }
 
 template 
Index: clang/test/Sema/comparison-op-parentheses.c
===
--- /dev/null
+++ clang/test/Sema/comparison-op-parentheses.c
@@ -0,0 +1,73 @@
+// RUN: %clang_cc1 -fsyntax-only -verify=off %s
+// RUN: %clang_cc1 -fsyntax-only -verify %s -Wcomparison-op-parentheses
+// RUN: %clang_cc1 -fsyntax-only -verify %s -Wparentheses
+// RUN: %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits %s -Wcomparison-op-parentheses 2>&1 | FileCheck %s
+
+// off-no-diagnostics
+
+void comparison_op_parentheses(int a, int b, int c) {
+  (void)(a ==
+ b > c);
+  // expected-warning@-1 {{'>' within '=='}}
+  // expected-note@-2 {{place parentheses around the '>' expression to silence this warning}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:14-[[@LINE-3]]:14}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:19-[[@LINE-4]]:19}:")"
+
+  (void)(a ==b == c);
+  // expected-warning@-1 {{'==' within '=='}}
+  // expected-note@-2 {{place parentheses around the '==' expression to silence this warning}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:10-[[@LINE-3]]:10}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:15-[[@LINE-4]]:15}:")"
+
+  (void)(a !=b == c);
+  // expected-warning@-1 {{'!=' within '=='}}
+  // expected-note@-2 {{place parentheses around the '!=' expression to silence this warning}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:10-[[@LINE-3]]:10}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:15-[[@LINE-4]]:15}:")"
+
+  (void)(a !=
+ b < c);
+  // expected-warning@-1 {{'<' within '!='}}
+  // expected-note@-2 {{place parentheses around the '<' expression to silence this warning}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:14-[[@LINE-3]]:14}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:19-[[@LINE-4]]:19}:")"
+
+  (void)(a>=b >= c);
+  // expected-warning@-1 {{'>=' within '>='; did you mean 'a >= b && b >= c'?}}
+  // expected-note@-2 {{split the comparison into two}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:14-[[@LINE-3]]:14}:"&& b"
+
+  (void)(a >b >= c);
+  // expected-warning@-1 {{'>' within '>='; did you mean 'a > b && b >= c'?}}
+  // expected-note@-2 {{split the comparison into two}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:14-[[@LINE-3]]:14}:"&& b"
+
+  (void)(a >b > c);
+  // expected-warning@-1 {{'>' within '>'; did you mean 'a > b && b > c'?}}
+  // expected-note@-2 {{split the comparison into two}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:14-[[@LINE-3]]:14}:"&& b"
+
+  (void)(b + c <= c + a < a + b);
+  // expected-warning@-1 {{'<=' within '<'; did you mean 'b + c <= c + a && c + a < a + b'?}}
+  // expected-note@-2 {{split the comparison into two}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:24-[[@LINE-3]]:24}:"&& c + a"
+
+
+  (void)(a c);
+  // expected-warning@-1 {{'<' within '>'; did you mean 'a < b && b > c'?}}
+  // expected-note@-2 {{split the comparison into two}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:13-[[@LINE-3]]:13}:"&& b"
+
+  (void)(a != (b > c));
+  (void)(a == (b > c));
+  (void)((a>b) >= c);
+  (void)((a c);
+  (void)(a != b && a > c);
+  (void)((a c);
+}
Index: clang/test/Misc/warning-wall.c
===
--- clang/test/Misc/warning-wall.c
+++ clang/test/Misc/warning-wall.c
@@ -92,6 +92,7 @@
 CHECK-NEXT:-Wlogical-not-parentheses
 CHECK-NEXT:-Wbitwise-conditional-parentheses
 CHECK-NEXT:-Wbitwise-op-parentheses
+CHECK-NEXT:-Wcomparison-op-parentheses
 CHECK-NEXT:-Wshift-op-parentheses
 CHECK-NEXT:-Woverloaded-shift-op-parentheses
 CHECK-NEXT:-Wparentheses-equality
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp

[PATCH] D142609: [Clang] Fix -Wconstant-logical-operand when LHS is a constant

2023-02-03 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta added inline comments.



Comment at: clang/lib/Sema/SemaExpr.cpp:13611-13653
 if (RHS.get()->EvaluateAsInt(EVResult, Context)) {
   llvm::APSInt Result = EVResult.Val.getInt();
   if ((getLangOpts().Bool && !RHS.get()->getType()->isBooleanType() &&
!RHS.get()->getExprLoc().isMacroID()) ||
   (Result != 0 && Result != 1)) {
 Diag(Loc, diag::warn_logical_instead_of_bitwise)
 << RHS.get()->getSourceRange() << (Opc == BO_LAnd ? "&&" : "||");

nickdesaulniers wrote:
> There seems to be a lot of duplication between the two; should we move these 
> into a static function that's called twice? Perhaps Op1 and Op2 would be 
> better identifiers than LHS RHS in that case?
I have tried many ways, but couldn't figure out a way to do it with function, 
unrelated test cases started failing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142609

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


[clang] 4a2c4ac - [clang][Interp] Support pointers in compound assignment operators

2023-02-03 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-02-03T16:42:46+01:00
New Revision: 4a2c4acb98694bb90c04e05052898708a03a7ebc

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

LOG: [clang][Interp] Support pointers in compound assignment operators

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

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index f8ee3a80326b..2b4e324f7b0f 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -685,6 +685,41 @@ bool 
ByteCodeExprGen::VisitFloatCompoundAssignOperator(
   return this->emitStore(*LT, E);
 }
 
+template 
+bool ByteCodeExprGen::VisitPointerCompoundAssignOperator(
+const CompoundAssignOperator *E) {
+  BinaryOperatorKind Op = E->getOpcode();
+  const Expr *LHS = E->getLHS();
+  const Expr *RHS = E->getRHS();
+  std::optional LT = classify(LHS->getType());
+  std::optional RT = classify(RHS->getType());
+
+  if (Op != BO_AddAssign && Op != BO_SubAssign)
+return false;
+
+  if (!LT || !RT)
+return false;
+  assert(*LT == PT_Ptr);
+
+  if (!visit(LHS))
+return false;
+
+  if (!this->emitLoadPtr(LHS))
+return false;
+
+  if (!visit(RHS))
+return false;
+
+  if (Op == BO_AddAssign)
+this->emitAddOffset(*RT, E);
+  else
+this->emitSubOffset(*RT, E);
+
+  if (DiscardResult)
+return this->emitStorePopPtr(E);
+  return this->emitStorePtr(E);
+}
+
 template 
 bool ByteCodeExprGen::VisitCompoundAssignOperator(
 const CompoundAssignOperator *E) {
@@ -694,6 +729,9 @@ bool ByteCodeExprGen::VisitCompoundAssignOperator(
   if (E->getType()->isFloatingType())
 return VisitFloatCompoundAssignOperator(E);
 
+  if (E->getType()->isPointerType())
+return VisitPointerCompoundAssignOperator(E);
+
   const Expr *LHS = E->getLHS();
   const Expr *RHS = E->getRHS();
   std::optional LHSComputationT =
@@ -705,9 +743,7 @@ bool ByteCodeExprGen::VisitCompoundAssignOperator(
   if (!LT || !RT || !ResultT || !LHSComputationT)
 return false;
 
-  assert(!E->getType()->isPointerType() &&
- "Support pointer arithmethic in compound assignment operators");
-
+  assert(!E->getType()->isPointerType() && "Handled above");
   assert(!E->getType()->isFloatingType() && "Handled above");
 
   // Get LHS pointer, load its value and get RHS value.

diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.h 
b/clang/lib/AST/Interp/ByteCodeExprGen.h
index 6b16b62a2e58..74cd5984daf5 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -87,6 +87,7 @@ class ByteCodeExprGen : public 
ConstStmtVisitor, bool>,
   bool VisitCharacterLiteral(const CharacterLiteral *E);
   bool VisitCompoundAssignOperator(const CompoundAssignOperator *E);
   bool VisitFloatCompoundAssignOperator(const CompoundAssignOperator *E);
+  bool VisitPointerCompoundAssignOperator(const CompoundAssignOperator *E);
   bool VisitExprWithCleanups(const ExprWithCleanups *E);
   bool VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *E);
 

diff  --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index c57485aecbf9..7121a24052f9 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -669,5 +669,42 @@ namespace IncDec {
   // expected-note {{in call to 
'IntMul}} \
   // ref-error {{not an integral 
constant expression}} \
   // ref-note {{in call to 
'IntMul}}
+  constexpr int arr[] = {1,2,3};
+  constexpr int ptrInc1() {
+const int *p = arr;
+p += 2;
+return *p;
+  }
+  static_assert(ptrInc1() == 3, "");
+
+  constexpr int ptrInc2() {
+const int *p = arr;
+return *(p += 1);
+  }
+  static_assert(ptrInc2() == 2, "");
+
+  constexpr int ptrInc3() { // expected-error {{never produces a constant 
expression}} \
+// ref-error {{never produces a constant 
expression}}
+const int *p = arr;
+p += 12; // expected-note {{cannot refer to element 12 of array of 3 
elements}} \
+ // ref-note {{cannot refer to element 12 of array of 3 elements}}
+return *p;
+  }
+
+  constexpr int ptrIncDec1() {
+const int *p = arr;
+p += 2;
+p -= 1;
+return *p;
+  }
+  static_assert(ptrIncDec1() == 2, "");
+
+  constexpr int ptrDec1() { // expected-error {{never produces a constant 
expression}} \
+// ref-error {{never produces a constant expression}}
+const int *p = arr;
+p -= 1;  

[PATCH] D142800: [Clang][Diagnostic] Add `-Wcomparison-op-parentheses` to warn on chained comparisons

2023-02-03 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

I'm reasonably happy here.  I think the chained-comparisons getting the && 
suggestion is nice.  However in each case, the diagnostic is REALLY poor.  It 
isn't really clear to most folks (barely clear to me!) that `'<' within '>'` 
really means anything.  I'd love if we could spend some time brainstorming some 
better diagnostic wording that makes it clear what the problem is.


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

https://reviews.llvm.org/D142800

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


[PATCH] D140874: [clang][Interp] Support pointer types in compound assignment operations

2023-02-03 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 rG4a2c4acb9869: [clang][Interp] Support pointers in compound 
assignment operators (authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D140874?vs=491619&id=494638#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140874

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.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
@@ -669,5 +669,42 @@
   // expected-note {{in call to 'IntMul}} \
   // ref-error {{not an integral constant expression}} \
   // ref-note {{in call to 'IntMul}}
+  constexpr int arr[] = {1,2,3};
+  constexpr int ptrInc1() {
+const int *p = arr;
+p += 2;
+return *p;
+  }
+  static_assert(ptrInc1() == 3, "");
+
+  constexpr int ptrInc2() {
+const int *p = arr;
+return *(p += 1);
+  }
+  static_assert(ptrInc2() == 2, "");
+
+  constexpr int ptrInc3() { // expected-error {{never produces a constant expression}} \
+// ref-error {{never produces a constant expression}}
+const int *p = arr;
+p += 12; // expected-note {{cannot refer to element 12 of array of 3 elements}} \
+ // ref-note {{cannot refer to element 12 of array of 3 elements}}
+return *p;
+  }
+
+  constexpr int ptrIncDec1() {
+const int *p = arr;
+p += 2;
+p -= 1;
+return *p;
+  }
+  static_assert(ptrIncDec1() == 2, "");
+
+  constexpr int ptrDec1() { // expected-error {{never produces a constant expression}} \
+// ref-error {{never produces a constant expression}}
+const int *p = arr;
+p -= 1;  // expected-note {{cannot refer to element -1 of array of 3 elements}} \
+ // ref-note {{cannot refer to element -1 of array of 3 elements}}
+return *p;
+  }
 };
 #endif
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -87,6 +87,7 @@
   bool VisitCharacterLiteral(const CharacterLiteral *E);
   bool VisitCompoundAssignOperator(const CompoundAssignOperator *E);
   bool VisitFloatCompoundAssignOperator(const CompoundAssignOperator *E);
+  bool VisitPointerCompoundAssignOperator(const CompoundAssignOperator *E);
   bool VisitExprWithCleanups(const ExprWithCleanups *E);
   bool VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *E);
 
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -685,6 +685,41 @@
   return this->emitStore(*LT, E);
 }
 
+template 
+bool ByteCodeExprGen::VisitPointerCompoundAssignOperator(
+const CompoundAssignOperator *E) {
+  BinaryOperatorKind Op = E->getOpcode();
+  const Expr *LHS = E->getLHS();
+  const Expr *RHS = E->getRHS();
+  std::optional LT = classify(LHS->getType());
+  std::optional RT = classify(RHS->getType());
+
+  if (Op != BO_AddAssign && Op != BO_SubAssign)
+return false;
+
+  if (!LT || !RT)
+return false;
+  assert(*LT == PT_Ptr);
+
+  if (!visit(LHS))
+return false;
+
+  if (!this->emitLoadPtr(LHS))
+return false;
+
+  if (!visit(RHS))
+return false;
+
+  if (Op == BO_AddAssign)
+this->emitAddOffset(*RT, E);
+  else
+this->emitSubOffset(*RT, E);
+
+  if (DiscardResult)
+return this->emitStorePopPtr(E);
+  return this->emitStorePtr(E);
+}
+
 template 
 bool ByteCodeExprGen::VisitCompoundAssignOperator(
 const CompoundAssignOperator *E) {
@@ -694,6 +729,9 @@
   if (E->getType()->isFloatingType())
 return VisitFloatCompoundAssignOperator(E);
 
+  if (E->getType()->isPointerType())
+return VisitPointerCompoundAssignOperator(E);
+
   const Expr *LHS = E->getLHS();
   const Expr *RHS = E->getRHS();
   std::optional LHSComputationT =
@@ -705,9 +743,7 @@
   if (!LT || !RT || !ResultT || !LHSComputationT)
 return false;
 
-  assert(!E->getType()->isPointerType() &&
- "Support pointer arithmethic in compound assignment operators");
-
+  assert(!E->getType()->isPointerType() && "Handled above");
   assert(!E->getType()->isFloatingType() && "Handled above");
 
   // Get LHS pointer, load its value and get RHS value.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D124351: [Clang] Implement Change scope of lambda trailing-return-type

2023-02-03 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D124351#4102634 , @eaeltsin wrote:

>> Looks like we fail to enter the appropriate context somewhere (my guess is 
>> that it might be specific to the attribute but it's hard to say without 
>> picking around), definitely a bug
>>
>> I'll be away the next 2 weeks, I'll look at it when I get back. Maybe we 
>> should track it in an issue though.
>
> Should we revert this then?

Yes, I think we should. We should also file an issue so @cor3ntin doesn't lose 
track of the issue. Anyone want to volunteer to do that? (I can do it early 
next week otherwise.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124351

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


[PATCH] D142465: [clang][lex] Consolidate PPCallbacks::PragmaDirective parameters

2023-02-03 Thread Kyle Edwards via Phabricator via cfe-commits
KyleFromKitware updated this revision to Diff 494644.

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

https://reviews.llvm.org/D142465

Files:
  clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
  clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h
  clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp
  clang-tools-extra/docs/pp-trace.rst
  clang-tools-extra/pp-trace/PPCallbacksTracker.cpp
  clang-tools-extra/pp-trace/PPCallbacksTracker.h
  clang-tools-extra/test/pp-trace/pp-trace-pragma-general.cpp
  clang-tools-extra/test/pp-trace/pp-trace-pragma-ms.cpp
  clang-tools-extra/test/pp-trace/pp-trace-pragma-opencl.cpp
  clang/include/clang/Lex/PPCallbacks.h
  clang/lib/Lex/Pragma.cpp

Index: clang/lib/Lex/Pragma.cpp
===
--- clang/lib/Lex/Pragma.cpp
+++ clang/lib/Lex/Pragma.cpp
@@ -166,7 +166,7 @@
 /// rest of the pragma, passing it to the registered pragma handlers.
 void Preprocessor::HandlePragmaDirective(PragmaIntroducer Introducer) {
   if (Callbacks)
-Callbacks->PragmaDirective(Introducer.Loc, Introducer.Kind);
+Callbacks->PragmaDirective(Introducer);
 
   if (!PragmasEnabled)
 return;
Index: clang/include/clang/Lex/PPCallbacks.h
===
--- clang/include/clang/Lex/PPCallbacks.h
+++ clang/include/clang/Lex/PPCallbacks.h
@@ -193,9 +193,7 @@
   }
 
   /// Callback invoked when start reading any pragma directive.
-  virtual void PragmaDirective(SourceLocation Loc,
-   PragmaIntroducerKind Introducer) {
-  }
+  virtual void PragmaDirective(PragmaIntroducer Introducer) {}
 
   /// Callback invoked when a \#pragma comment directive is read.
   virtual void PragmaComment(SourceLocation Loc, const IdentifierInfo *Kind,
@@ -511,10 +509,9 @@
 Second->Ident(Loc, str);
   }
 
-  void PragmaDirective(SourceLocation Loc,
-   PragmaIntroducerKind Introducer) override {
-First->PragmaDirective(Loc, Introducer);
-Second->PragmaDirective(Loc, Introducer);
+  void PragmaDirective(PragmaIntroducer Introducer) override {
+First->PragmaDirective(Introducer);
+Second->PragmaDirective(Introducer);
   }
 
   void PragmaComment(SourceLocation Loc, const IdentifierInfo *Kind,
Index: clang-tools-extra/test/pp-trace/pp-trace-pragma-opencl.cpp
===
--- clang-tools-extra/test/pp-trace/pp-trace-pragma-opencl.cpp
+++ clang-tools-extra/test/pp-trace/pp-trace-pragma-opencl.cpp
@@ -6,24 +6,21 @@
 
 // CHECK: ---
 // CHECK-NEXT: - Callback: PragmaDirective
-// CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-opencl.cpp:3:1"
-// CHECK-NEXT:   Introducer: PIK_HashPragma
+// CHECK-NEXT:   Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-opencl.cpp:3:1", Kind: PIK_HashPragma}
 // CHECK-NEXT: - Callback: PragmaOpenCLExtension
 // CHECK-NEXT:   NameLoc: "{{.*}}{{[/\\]}}pp-trace-pragma-opencl.cpp:3:26"
 // CHECK-NEXT:   Name: all
 // CHECK-NEXT:   StateLoc: "{{.*}}{{[/\\]}}pp-trace-pragma-opencl.cpp:3:32"
 // CHECK-NEXT:   State: 0
 // CHECK-NEXT: - Callback: PragmaDirective
-// CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-opencl.cpp:4:1"
-// CHECK-NEXT:   Introducer: PIK_HashPragma
+// CHECK-NEXT:   Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-opencl.cpp:4:1", Kind: PIK_HashPragma}
 // CHECK-NEXT: - Callback: PragmaOpenCLExtension
 // CHECK-NEXT:   NameLoc: "{{.*}}{{[/\\]}}pp-trace-pragma-opencl.cpp:4:26"
 // CHECK-NEXT:   Name: cl_khr_int64_base_atomics
 // CHECK-NEXT:   StateLoc: "{{.*}}{{[/\\]}}pp-trace-pragma-opencl.cpp:4:54"
 // CHECK-NEXT:   State: 0
 // CHECK-NEXT: - Callback: PragmaDirective
-// CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-opencl.cpp:5:1"
-// CHECK-NEXT:   Introducer: PIK_HashPragma
+// CHECK-NEXT:   Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-opencl.cpp:5:1", Kind: PIK_HashPragma}
 // CHECK-NEXT: - Callback: PragmaOpenCLExtension
 // CHECK-NEXT:   NameLoc: "{{.*}}{{[/\\]}}pp-trace-pragma-opencl.cpp:5:26"
 // CHECK-NEXT:   Name: cl_khr_int64_base_atomics
Index: clang-tools-extra/test/pp-trace/pp-trace-pragma-ms.cpp
===
--- clang-tools-extra/test/pp-trace/pp-trace-pragma-ms.cpp
+++ clang-tools-extra/test/pp-trace/pp-trace-pragma-ms.cpp
@@ -18,72 +18,61 @@
 
 // CHECK: ---
 // CHECK-NEXT: - Callback: PragmaDirective
-// CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-ms.cpp:3:1"
-// CHECK-NEXT:   Introducer: PIK_HashPragma
+// CHECK-NEXT:   Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-ms.cpp:3:1", Kind: PIK_HashPragma}
 // CHECK-NEXT: - Callback: PragmaComment
 // CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-ms.cpp:3:9"
 // CHECK-NEXT:   Kind: compiler
 // CHECK-NEXT:   Str: compiler comment
 // CHECK-NEXT: - Callback: PragmaDirective
-// CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-ms.cpp:4:1"
-// CH

[PATCH] D142030: [pp-trace] Print HashLoc/Introducer parameter

2023-02-03 Thread Kyle Edwards via Phabricator via cfe-commits
KyleFromKitware updated this revision to Diff 494646.

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

https://reviews.llvm.org/D142030

Files:
  clang-tools-extra/docs/pp-trace.rst
  clang-tools-extra/pp-trace/PPCallbacksTracker.cpp
  clang-tools-extra/test/pp-trace/pp-trace-conditional.cpp
  clang-tools-extra/test/pp-trace/pp-trace-ident.cpp
  clang-tools-extra/test/pp-trace/pp-trace-include.cpp
  clang-tools-extra/test/pp-trace/pp-trace-macro.cpp
  clang-tools-extra/test/pp-trace/pp-trace-pragma-general.cpp
  clang-tools-extra/test/pp-trace/pp-trace-pragma-ms.cpp
  clang-tools-extra/test/pp-trace/pp-trace-pragma-opencl.cpp

Index: clang-tools-extra/test/pp-trace/pp-trace-pragma-opencl.cpp
===
--- clang-tools-extra/test/pp-trace/pp-trace-pragma-opencl.cpp
+++ clang-tools-extra/test/pp-trace/pp-trace-pragma-opencl.cpp
@@ -8,6 +8,7 @@
 // CHECK-NEXT: - Callback: PragmaDirective
 // CHECK-NEXT:   Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-opencl.cpp:3:1", Kind: PIK_HashPragma}
 // CHECK-NEXT: - Callback: PragmaOpenCLExtension
+// CHECK-NEXT:   Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-opencl.cpp:3:1", Kind: PIK_HashPragma}
 // CHECK-NEXT:   NameLoc: "{{.*}}{{[/\\]}}pp-trace-pragma-opencl.cpp:3:26"
 // CHECK-NEXT:   Name: all
 // CHECK-NEXT:   StateLoc: "{{.*}}{{[/\\]}}pp-trace-pragma-opencl.cpp:3:32"
@@ -15,6 +16,7 @@
 // CHECK-NEXT: - Callback: PragmaDirective
 // CHECK-NEXT:   Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-opencl.cpp:4:1", Kind: PIK_HashPragma}
 // CHECK-NEXT: - Callback: PragmaOpenCLExtension
+// CHECK-NEXT:   Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-opencl.cpp:4:1", Kind: PIK_HashPragma}
 // CHECK-NEXT:   NameLoc: "{{.*}}{{[/\\]}}pp-trace-pragma-opencl.cpp:4:26"
 // CHECK-NEXT:   Name: cl_khr_int64_base_atomics
 // CHECK-NEXT:   StateLoc: "{{.*}}{{[/\\]}}pp-trace-pragma-opencl.cpp:4:54"
@@ -22,6 +24,7 @@
 // CHECK-NEXT: - Callback: PragmaDirective
 // CHECK-NEXT:   Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-opencl.cpp:5:1", Kind: PIK_HashPragma}
 // CHECK-NEXT: - Callback: PragmaOpenCLExtension
+// CHECK-NEXT:   Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-opencl.cpp:5:1", Kind: PIK_HashPragma}
 // CHECK-NEXT:   NameLoc: "{{.*}}{{[/\\]}}pp-trace-pragma-opencl.cpp:5:26"
 // CHECK-NEXT:   Name: cl_khr_int64_base_atomics
 // CHECK-NEXT:   StateLoc: "{{.*}}{{[/\\]}}pp-trace-pragma-opencl.cpp:5:54"
Index: clang-tools-extra/test/pp-trace/pp-trace-pragma-ms.cpp
===
--- clang-tools-extra/test/pp-trace/pp-trace-pragma-ms.cpp
+++ clang-tools-extra/test/pp-trace/pp-trace-pragma-ms.cpp
@@ -20,36 +20,42 @@
 // CHECK-NEXT: - Callback: PragmaDirective
 // CHECK-NEXT:   Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-ms.cpp:3:1", Kind: PIK_HashPragma}
 // CHECK-NEXT: - Callback: PragmaComment
+// CHECK-NEXT:   Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-ms.cpp:3:1", Kind: PIK_HashPragma}
 // CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-ms.cpp:3:9"
 // CHECK-NEXT:   Kind: compiler
 // CHECK-NEXT:   Str: compiler comment
 // CHECK-NEXT: - Callback: PragmaDirective
 // CHECK-NEXT:   Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-ms.cpp:4:1", Kind: PIK_HashPragma}
 // CHECK-NEXT: - Callback: PragmaComment
+// CHECK-NEXT:   Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-ms.cpp:4:1", Kind: PIK_HashPragma}
 // CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-ms.cpp:4:9"
 // CHECK-NEXT:   Kind: exestr
 // CHECK-NEXT:   Str: exestr comment
 // CHECK-NEXT: - Callback: PragmaDirective
 // CHECK-NEXT:   Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-ms.cpp:5:1", Kind: PIK_HashPragma}
 // CHECK-NEXT: - Callback: PragmaComment
+// CHECK-NEXT:   Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-ms.cpp:5:1", Kind: PIK_HashPragma}
 // CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-ms.cpp:5:9"
 // CHECK-NEXT:   Kind: lib
 // CHECK-NEXT:   Str: lib comment
 // CHECK-NEXT: - Callback: PragmaDirective
 // CHECK-NEXT:   Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-ms.cpp:6:1", Kind: PIK_HashPragma}
 // CHECK-NEXT: - Callback: PragmaComment
+// CHECK-NEXT:   Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-ms.cpp:6:1", Kind: PIK_HashPragma}
 // CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-ms.cpp:6:9"
 // CHECK-NEXT:   Kind: linker
 // CHECK-NEXT:   Str: linker comment
 // CHECK-NEXT: - Callback: PragmaDirective
 // CHECK-NEXT:   Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-ms.cpp:7:1", Kind: PIK_HashPragma}
 // CHECK-NEXT: - Callback: PragmaComment
+// CHECK-NEXT:   Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-ms.cpp:7:1", Kind: PIK_HashPragma}
 // CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-ms.cpp:7:9"
 // CHECK-NEXT:   Kind: user
 // CHECK-NEXT:   Str: user comment
 // CHECK-NEXT: - Callback: PragmaDirective
 // CHECK-NEXT:   Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-ms.cpp:9

[PATCH] D142470: [clang][lex] Add PragmaOnce callback to PPCallbacks

2023-02-03 Thread Kyle Edwards via Phabricator via cfe-commits
KyleFromKitware updated this revision to Diff 494647.

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

https://reviews.llvm.org/D142470

Files:
  clang/include/clang/Lex/PPCallbacks.h
  clang/include/clang/Lex/Preprocessor.h
  clang/lib/Lex/Pragma.cpp


Index: clang/lib/Lex/Pragma.cpp
===
--- clang/lib/Lex/Pragma.cpp
+++ clang/lib/Lex/Pragma.cpp
@@ -403,7 +403,8 @@
 }
 
 /// HandlePragmaOnce - Handle \#pragma once.  OnceTok is the 'once'.
-void Preprocessor::HandlePragmaOnce(Token &OnceTok) {
+void Preprocessor::HandlePragmaOnce(PragmaIntroducer Introducer,
+Token &OnceTok) {
   // Don't honor the 'once' when handling the primary source file, unless
   // this is a prefix to a TU, which indicates we're generating a PCH file, or
   // when the main file is a header (e.g. when -xc-header is provided on the
@@ -416,6 +417,9 @@
   // Get the current file lexer we're looking at.  Ignore _Pragma 'files' etc.
   // Mark the file as a once-only file now.
   HeaderInfo.MarkFileIncludeOnce(getCurrentFileLexer()->getFileEntry());
+
+  if (Callbacks)
+Callbacks->PragmaOnce(Introducer, OnceTok.getLocation());
 }
 
 void Preprocessor::HandlePragmaMark(PragmaIntroducer Introducer,
@@ -991,7 +995,7 @@
   void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
 Token &OnceTok) override {
 PP.CheckEndOfDirective("pragma once");
-PP.HandlePragmaOnce(OnceTok);
+PP.HandlePragmaOnce(Introducer, OnceTok);
   }
 };
 
Index: clang/include/clang/Lex/Preprocessor.h
===
--- clang/include/clang/Lex/Preprocessor.h
+++ clang/include/clang/Lex/Preprocessor.h
@@ -2615,7 +2615,7 @@
   void HandlePragmaDirective(PragmaIntroducer Introducer);
 
 public:
-  void HandlePragmaOnce(Token &OnceTok);
+  void HandlePragmaOnce(PragmaIntroducer Introducer, Token &OnceTok);
   void HandlePragmaMark(PragmaIntroducer Introducer, Token &MarkTok);
   void HandlePragmaPoison();
   void HandlePragmaSystemHeader(Token &SysHeaderTok);
Index: clang/include/clang/Lex/PPCallbacks.h
===
--- clang/include/clang/Lex/PPCallbacks.h
+++ clang/include/clang/Lex/PPCallbacks.h
@@ -305,6 +305,9 @@
   virtual void PragmaAssumeNonNullEnd(PragmaIntroducer Introducer,
   SourceLocation Loc) {}
 
+  /// Callback invoked when a \#pragma once directive is read.
+  virtual void PragmaOnce(PragmaIntroducer Introducer, SourceLocation Loc) {}
+
   /// Called by Preprocessor::HandleMacroExpandedIdentifier when a
   /// macro invocation is found.
   virtual void MacroExpands(const Token &MacroNameTok,
@@ -627,6 +630,11 @@
 Second->PragmaAssumeNonNullEnd(Introducer, Loc);
   }
 
+  void PragmaOnce(PragmaIntroducer Introducer, SourceLocation Loc) override {
+First->PragmaOnce(Introducer, Loc);
+Second->PragmaOnce(Introducer, Loc);
+  }
+
   void MacroExpands(const Token &MacroNameTok, const MacroDefinition &MD,
 SourceRange Range, const MacroArgs *Args) override {
 First->MacroExpands(MacroNameTok, MD, Range, Args);


Index: clang/lib/Lex/Pragma.cpp
===
--- clang/lib/Lex/Pragma.cpp
+++ clang/lib/Lex/Pragma.cpp
@@ -403,7 +403,8 @@
 }
 
 /// HandlePragmaOnce - Handle \#pragma once.  OnceTok is the 'once'.
-void Preprocessor::HandlePragmaOnce(Token &OnceTok) {
+void Preprocessor::HandlePragmaOnce(PragmaIntroducer Introducer,
+Token &OnceTok) {
   // Don't honor the 'once' when handling the primary source file, unless
   // this is a prefix to a TU, which indicates we're generating a PCH file, or
   // when the main file is a header (e.g. when -xc-header is provided on the
@@ -416,6 +417,9 @@
   // Get the current file lexer we're looking at.  Ignore _Pragma 'files' etc.
   // Mark the file as a once-only file now.
   HeaderInfo.MarkFileIncludeOnce(getCurrentFileLexer()->getFileEntry());
+
+  if (Callbacks)
+Callbacks->PragmaOnce(Introducer, OnceTok.getLocation());
 }
 
 void Preprocessor::HandlePragmaMark(PragmaIntroducer Introducer,
@@ -991,7 +995,7 @@
   void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
 Token &OnceTok) override {
 PP.CheckEndOfDirective("pragma once");
-PP.HandlePragmaOnce(OnceTok);
+PP.HandlePragmaOnce(Introducer, OnceTok);
   }
 };
 
Index: clang/include/clang/Lex/Preprocessor.h
===
--- clang/include/clang/Lex/Preprocessor.h
+++ clang/include/clang/Lex/Preprocessor.h
@@ -2615,7 +2615,7 @@
   void HandlePragmaDirective(PragmaIntroducer Introducer);
 
 public:
-  void HandlePragmaOnce(Token &OnceTok);
+  void HandlePragmaOnce(PragmaIntroducer Introducer, Token &OnceTok);
   void HandlePragmaMark(Pragma

[PATCH] D142471: [pp-trace] Add PragmaOnce callback

2023-02-03 Thread Kyle Edwards via Phabricator via cfe-commits
KyleFromKitware updated this revision to Diff 494648.

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

https://reviews.llvm.org/D142471

Files:
  clang-tools-extra/pp-trace/PPCallbacksTracker.cpp
  clang-tools-extra/pp-trace/PPCallbacksTracker.h
  clang-tools-extra/test/pp-trace/pp-trace-pragma-general.cpp


Index: clang-tools-extra/test/pp-trace/pp-trace-pragma-general.cpp
===
--- clang-tools-extra/test/pp-trace/pp-trace-pragma-general.cpp
+++ clang-tools-extra/test/pp-trace/pp-trace-pragma-general.cpp
@@ -1,4 +1,4 @@
-// RUN: pp-trace -callbacks '*,-FileChanged,-MacroDefined' %s -- | FileCheck 
--strict-whitespace %s
+// RUN: pp-trace -callbacks '*,-FileChanged,-MacroDefined' 
-extra-arg-before=-xc++-header %s -- | FileCheck --strict-whitespace %s
 
 #pragma clang diagnostic push
 #pragma clang diagnostic pop
@@ -19,6 +19,8 @@
 { }
 }
 
+#pragma once
+
 // CHECK: ---
 // CHECK-NEXT: - Callback: PragmaDirective
 // CHECK-NEXT:   Introducer: {Loc: 
"{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:3:1", Kind: PIK_HashPragma}
@@ -114,5 +116,10 @@
 // CHECK-NEXT:   Introducer: {Loc: 
"{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:18:1", Kind: PIK_HashPragma}
 // CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:18:23"
 // CHECK-NEXT:   DebugType: captured
+// CHECK-NEXT: - Callback: PragmaDirective
+// CHECK-NEXT:   Introducer: {Loc: 
"{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:22:1", Kind: PIK_HashPragma}
+// CHECK-NEXT: - Callback: PragmaOnce
+// CHECK-NEXT:   Introducer: {Loc: 
"{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:22:1", Kind: PIK_HashPragma}
+// CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:22:9"
 // CHECK-NEXT: - Callback: EndOfMainFile
 // CHECK-NEXT: ...
Index: clang-tools-extra/pp-trace/PPCallbacksTracker.h
===
--- clang-tools-extra/pp-trace/PPCallbacksTracker.h
+++ clang-tools-extra/pp-trace/PPCallbacksTracker.h
@@ -135,6 +135,7 @@
  StringRef Str) override;
   void PragmaExecCharsetPop(PragmaIntroducer Introducer,
 SourceLocation Loc) override;
+  void PragmaOnce(PragmaIntroducer Introducer, SourceLocation Loc) override;
   void MacroExpands(const Token &MacroNameTok, const MacroDefinition &MD,
 SourceRange Range, const MacroArgs *Args) override;
   void MacroDefined(SourceLocation HashLoc, const Token &MacroNameTok,
Index: clang-tools-extra/pp-trace/PPCallbacksTracker.cpp
===
--- clang-tools-extra/pp-trace/PPCallbacksTracker.cpp
+++ clang-tools-extra/pp-trace/PPCallbacksTracker.cpp
@@ -337,6 +337,14 @@
   appendArgument("Loc", Loc);
 }
 
+/// Callback invoked when a \#pragma once directive is read.
+void PPCallbacksTracker::PragmaOnce(PragmaIntroducer Introducer,
+SourceLocation Loc) {
+  beginCallback("PragmaOnce");
+  appendArgument("Introducer", Introducer);
+  appendArgument("Loc", Loc);
+}
+
 // Called by Preprocessor::HandleMacroExpandedIdentifier when a
 // macro invocation is found.
 void PPCallbacksTracker::MacroExpands(const Token &MacroNameTok,


Index: clang-tools-extra/test/pp-trace/pp-trace-pragma-general.cpp
===
--- clang-tools-extra/test/pp-trace/pp-trace-pragma-general.cpp
+++ clang-tools-extra/test/pp-trace/pp-trace-pragma-general.cpp
@@ -1,4 +1,4 @@
-// RUN: pp-trace -callbacks '*,-FileChanged,-MacroDefined' %s -- | FileCheck --strict-whitespace %s
+// RUN: pp-trace -callbacks '*,-FileChanged,-MacroDefined' -extra-arg-before=-xc++-header %s -- | FileCheck --strict-whitespace %s
 
 #pragma clang diagnostic push
 #pragma clang diagnostic pop
@@ -19,6 +19,8 @@
 { }
 }
 
+#pragma once
+
 // CHECK: ---
 // CHECK-NEXT: - Callback: PragmaDirective
 // CHECK-NEXT:   Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:3:1", Kind: PIK_HashPragma}
@@ -114,5 +116,10 @@
 // CHECK-NEXT:   Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:18:1", Kind: PIK_HashPragma}
 // CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:18:23"
 // CHECK-NEXT:   DebugType: captured
+// CHECK-NEXT: - Callback: PragmaDirective
+// CHECK-NEXT:   Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:22:1", Kind: PIK_HashPragma}
+// CHECK-NEXT: - Callback: PragmaOnce
+// CHECK-NEXT:   Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:22:1", Kind: PIK_HashPragma}
+// CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:22:9"
 // CHECK-NEXT: - Callback: EndOfMainFile
 // CHECK-NEXT: ...
Index: clang-tools-extra/pp-trace/PPCallbacksTracker.h
===
--- clang-tools-extra/pp-trace/PPCallbacksTracker.h
+++ clang-tools-extra/pp-trace/PPCallbacksTracker.h
@@ -135,6 +135,7 @@
  

[PATCH] D142673: [clang-tidy] Refactor HeaderGuardCheck to add HeaderGuardStyle

2023-02-03 Thread Kyle Edwards via Phabricator via cfe-commits
KyleFromKitware updated this revision to Diff 494649.

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

https://reviews.llvm.org/D142673

Files:
  clang-tools-extra/clang-tidy/ClangTidyModule.h
  clang-tools-extra/clang-tidy/llvm/CMakeLists.txt
  clang-tools-extra/clang-tidy/llvm/HeaderGuardCheck.cpp
  clang-tools-extra/clang-tidy/llvm/HeaderGuardCheck.h
  clang-tools-extra/clang-tidy/llvm/HeaderGuardStyle.cpp
  clang-tools-extra/clang-tidy/llvm/HeaderGuardStyle.h
  clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp
  clang-tools-extra/clang-tidy/readability/CMakeLists.txt
  clang-tools-extra/clang-tidy/readability/HeaderGuardCheck.cpp
  clang-tools-extra/clang-tidy/readability/HeaderGuardCheck.h
  clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tools-extra/clang-tidy/utils/CMakeLists.txt
  clang-tools-extra/clang-tidy/utils/HeaderGuard.cpp
  clang-tools-extra/clang-tidy/utils/HeaderGuard.h
  clang-tools-extra/clang-tidy/utils/HeaderGuardStyle.cpp
  clang-tools-extra/clang-tidy/utils/HeaderGuardStyle.h
  clang-tools-extra/clang-tidy/utils/MacroHeaderGuardStyle.cpp
  clang-tools-extra/clang-tidy/utils/MacroHeaderGuardStyle.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/llvm/header-guard.rst
  clang-tools-extra/docs/clang-tidy/checks/readability/header-guard.rst
  clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp
@@ -3,6 +3,7 @@
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/HeaderGuardCheck.h"
+#include "llvm/HeaderGuardStyle.h"
 #include "llvm/IncludeOrderCheck.h"
 #include "gtest/gtest.h"
 #include 
@@ -49,10 +50,18 @@
 }
 
 namespace {
+struct WithEndifCommentStyle : public LLVMHeaderGuardStyle {
+  WithEndifCommentStyle(readability::HeaderGuardCheck *Check)
+  : LLVMHeaderGuardStyle(Check) {}
+  bool shouldSuggestEndifComment(StringRef Filename) override { return true; }
+};
+
 struct WithEndifComment : public LLVMHeaderGuardCheck {
   WithEndifComment(StringRef Name, ClangTidyContext *Context)
   : LLVMHeaderGuardCheck(Name, Context) {}
-  bool shouldSuggestEndifComment(StringRef Filename) override { return true; }
+  std::unique_ptr createHeaderGuardStyle() override {
+return std::make_unique(this);
+  }
 };
 
 static std::string
Index: clang-tools-extra/docs/clang-tidy/checks/readability/header-guard.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/readability/header-guard.rst
@@ -0,0 +1,26 @@
+.. title:: clang-tidy - readability-header-guard
+
+readability-header-guard
+
+
+Finds and fixes header guards that do not adhere to a specified style.
+
+Options
+---
+
+.. option:: HeaderFileExtensions
+
+   A comma-separated list of filename extensions of header files (the filename
+   extensions should not include "." prefix). Default is "h,hh,hpp,hxx".
+   For header files without an extension, use an empty string (if there are no
+   other desired extensions) or leave an empty element in the list. E.g.,
+   "h,hh,hpp,hxx," (note the trailing comma).
+
+.. option:: Style
+
+   The name of a header guard style to select. The default is "llvm". Available
+   options are:
+
+   ``llvm``
+
+ Use the LLVM header guard style.
Index: clang-tools-extra/docs/clang-tidy/checks/llvm/header-guard.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/llvm/header-guard.rst
+++ clang-tools-extra/docs/clang-tidy/checks/llvm/header-guard.rst
@@ -5,6 +5,10 @@
 
 Finds and fixes header guards that do not adhere to LLVM style.
 
+Note: this check is deprecated, it will be removed in :program:`clang-tidy`
+version 19. Please use the check `readability-header-guard`. with the ``llvm``
+style.
+
 Options
 ---
 
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -339,6 +339,7 @@
`readability-else-after-return `_, "Yes"
`readability-function-cognitive-complexity `_,
`readability-function-size `_,
+   `readability-header-guard `_,
`readability-identifier-length `_,
`readability-identifier-naming `_, "Yes"
`readability-implicit-bool-conversion `_, "Yes"
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -110,6 +110,11 @@
 
   Warns when lambda specify a 

[PATCH] D142123: [clang-tidy] Add header guard style to suggest use of #pragma once

2023-02-03 Thread Kyle Edwards via Phabricator via cfe-commits
KyleFromKitware updated this revision to Diff 494650.
KyleFromKitware added a comment.

Updated with review feedback.


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

https://reviews.llvm.org/D142123

Files:
  clang-tools-extra/clang-tidy/readability/CMakeLists.txt
  clang-tools-extra/clang-tidy/readability/PragmaOnceHeaderGuardStyle.cpp
  clang-tools-extra/clang-tidy/readability/PragmaOnceHeaderGuardStyle.h
  clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tools-extra/docs/clang-tidy/checks/readability/header-guard.rst
  clang-tools-extra/unittests/clang-tidy/ReadabilityModuleTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/ReadabilityModuleTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/ReadabilityModuleTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/ReadabilityModuleTest.cpp
@@ -1,6 +1,8 @@
 #include "ClangTidyTest.h"
 #include "readability/BracesAroundStatementsCheck.h"
+#include "readability/HeaderGuardCheck.h"
 #include "readability/NamespaceCommentCheck.h"
+#include "readability/PragmaOnceHeaderGuardStyle.h"
 #include "readability/SimplifyBooleanExprCheck.h"
 #include "gtest/gtest.h"
 
@@ -513,6 +515,97 @@
 nullptr, "input.cc", {"-Wno-error=return-type"}));
 }
 
+namespace {
+struct UsePragmaOnceCheck : readability::HeaderGuardCheck {
+  UsePragmaOnceCheck(StringRef Name, ClangTidyContext *Context)
+  : HeaderGuardCheck(Name, Context) {}
+
+  std::unique_ptr createHeaderGuardStyle() override {
+return std::make_unique(this);
+  }
+};
+
+std::string runPragmaOnceCheck(StringRef Code, const Twine &Filename,
+   std::optional ExpectedWarning,
+   std::map PathsToContent =
+   std::map()) {
+  std::vector Errors;
+  std::string Result = test::runCheckOnCode(
+  Code, &Errors, Filename, std::string("-xc++-header"), ClangTidyOptions{},
+  std::move(PathsToContent));
+  if (Errors.size() != (size_t)ExpectedWarning.has_value())
+return "invalid error count";
+  if (ExpectedWarning && *ExpectedWarning != Errors.back().Message.Message)
+return "expected: '" + ExpectedWarning->str() + "', saw: '" +
+   Errors.back().Message.Message + "'";
+  return Result;
+}
+} // namespace
+
+TEST(PragmaOnceHeaderGuardStyleTest, AddPragmaOnce) {
+  EXPECT_EQ("#pragma once\n"
+"\n"
+"void headerGuard();\n"
+"\n",
+runPragmaOnceCheck("#ifndef HEADER_GUARD_H\n"
+   "#define HEADER_GUARD_H\n"
+   "\n"
+   "void headerGuard();\n"
+   "\n"
+   "#endif // HEADER_GUARD_H\n",
+   "header-guard.h",
+   StringRef("use #pragma once")));
+  EXPECT_EQ("#pragma once\n"
+"\n"
+"void headerGuardValue();\n"
+"\n",
+runPragmaOnceCheck("#ifndef HEADER_GUARD_VALUE_H\n"
+   "#define HEADER_GUARD_VALUE_H \\\n"
+   "1\n"
+   "\n"
+   "void headerGuardValue();\n"
+   "\n"
+   "#endif\n",
+   "header-guard-value.h",
+   StringRef("use #pragma once")));
+  EXPECT_EQ("#if !defined(DEFINED_HEADER_GUARD_H)\n"
+"#define DEFINED_HEADER_GUARD_H\n"
+"\n"
+"void definedHeaderGuard();\n"
+"\n"
+"#endif\n",
+runPragmaOnceCheck("#if !defined(DEFINED_HEADER_GUARD_H)\n"
+   "#define DEFINED_HEADER_GUARD_H\n"
+   "\n"
+   "void definedHeaderGuard();\n"
+   "\n"
+   "#endif\n",
+   "defined-header-guard.h", std::nullopt));
+  EXPECT_EQ("#pragma once\n"
+"\n"
+"void pragmaOnce();\n",
+runPragmaOnceCheck("#pragma once\n"
+   "\n"
+   "void pragmaOnce();\n",
+   "pragma-once.h", std::nullopt));
+  EXPECT_EQ("#pragma once\n"
+"\n"
+"void both();\n"
+"\n",
+runPragmaOnceCheck("#ifndef BOTH_H\n"
+   "#define BOTH_H\n"
+   "#pragma once\n"
+   "\n"
+   "void both();\n"
+   "\n"
+   "#endif // BOTH_H\n",
+   "both.h", StringRef("use #pragma once")));
+  EXPECT_EQ("#pragma once\n"
+"void neither();\n",
+

[PATCH] D142123: [clang-tidy] Add header guard style to suggest use of #pragma once

2023-02-03 Thread Kyle Edwards via Phabricator via cfe-commits
KyleFromKitware added inline comments.



Comment at: 
clang-tools-extra/unittests/clang-tidy/ReadabilityModuleTest.cpp:569-571
+runPragmaOnceCheck("#ifndef BOTH_H\n"
+   "#define BOTH_H\n"
+   "#pragma once\n"

aaron.ballman wrote:
> How about a test for:
> ```
> #if !defined(HEADER_GUARD_H)
> #define HEADER_GUARD_H 1
> 
> #endif
> ```
> and a test for what happens when there's no header guard or pragma once in 
> the file.
> How about a test for:
> ```
> #if !defined(HEADER_GUARD_H)
> #define HEADER_GUARD_H 1
> 
> #endif
> ```

Good catch. The case of `!defined()` was not being handled by the existing 
header guard check except to basically ignore it. The `#pragma once` check 
crashed on this case. I've updated it to also ignore the `!defined()` case.

> and a test for what happens when there's no header guard or pragma once in 
> the file.

I already have this, see the "neither" test at the bottom.


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

https://reviews.llvm.org/D142123

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


[PATCH] D142123: [clang-tidy] Add header guard style to suggest use of #pragma once

2023-02-03 Thread Kyle Edwards via Phabricator via cfe-commits
KyleFromKitware updated this revision to Diff 494652.
KyleFromKitware added a comment.

Updated documentation.


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

https://reviews.llvm.org/D142123

Files:
  clang-tools-extra/clang-tidy/readability/CMakeLists.txt
  clang-tools-extra/clang-tidy/readability/PragmaOnceHeaderGuardStyle.cpp
  clang-tools-extra/clang-tidy/readability/PragmaOnceHeaderGuardStyle.h
  clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tools-extra/docs/clang-tidy/checks/readability/header-guard.rst
  clang-tools-extra/unittests/clang-tidy/ReadabilityModuleTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/ReadabilityModuleTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/ReadabilityModuleTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/ReadabilityModuleTest.cpp
@@ -1,6 +1,8 @@
 #include "ClangTidyTest.h"
 #include "readability/BracesAroundStatementsCheck.h"
+#include "readability/HeaderGuardCheck.h"
 #include "readability/NamespaceCommentCheck.h"
+#include "readability/PragmaOnceHeaderGuardStyle.h"
 #include "readability/SimplifyBooleanExprCheck.h"
 #include "gtest/gtest.h"
 
@@ -513,6 +515,97 @@
 nullptr, "input.cc", {"-Wno-error=return-type"}));
 }
 
+namespace {
+struct UsePragmaOnceCheck : readability::HeaderGuardCheck {
+  UsePragmaOnceCheck(StringRef Name, ClangTidyContext *Context)
+  : HeaderGuardCheck(Name, Context) {}
+
+  std::unique_ptr createHeaderGuardStyle() override {
+return std::make_unique(this);
+  }
+};
+
+std::string runPragmaOnceCheck(StringRef Code, const Twine &Filename,
+   std::optional ExpectedWarning,
+   std::map PathsToContent =
+   std::map()) {
+  std::vector Errors;
+  std::string Result = test::runCheckOnCode(
+  Code, &Errors, Filename, std::string("-xc++-header"), ClangTidyOptions{},
+  std::move(PathsToContent));
+  if (Errors.size() != (size_t)ExpectedWarning.has_value())
+return "invalid error count";
+  if (ExpectedWarning && *ExpectedWarning != Errors.back().Message.Message)
+return "expected: '" + ExpectedWarning->str() + "', saw: '" +
+   Errors.back().Message.Message + "'";
+  return Result;
+}
+} // namespace
+
+TEST(PragmaOnceHeaderGuardStyleTest, AddPragmaOnce) {
+  EXPECT_EQ("#pragma once\n"
+"\n"
+"void headerGuard();\n"
+"\n",
+runPragmaOnceCheck("#ifndef HEADER_GUARD_H\n"
+   "#define HEADER_GUARD_H\n"
+   "\n"
+   "void headerGuard();\n"
+   "\n"
+   "#endif // HEADER_GUARD_H\n",
+   "header-guard.h",
+   StringRef("use #pragma once")));
+  EXPECT_EQ("#pragma once\n"
+"\n"
+"void headerGuardValue();\n"
+"\n",
+runPragmaOnceCheck("#ifndef HEADER_GUARD_VALUE_H\n"
+   "#define HEADER_GUARD_VALUE_H \\\n"
+   "1\n"
+   "\n"
+   "void headerGuardValue();\n"
+   "\n"
+   "#endif\n",
+   "header-guard-value.h",
+   StringRef("use #pragma once")));
+  EXPECT_EQ("#if !defined(DEFINED_HEADER_GUARD_H)\n"
+"#define DEFINED_HEADER_GUARD_H\n"
+"\n"
+"void definedHeaderGuard();\n"
+"\n"
+"#endif\n",
+runPragmaOnceCheck("#if !defined(DEFINED_HEADER_GUARD_H)\n"
+   "#define DEFINED_HEADER_GUARD_H\n"
+   "\n"
+   "void definedHeaderGuard();\n"
+   "\n"
+   "#endif\n",
+   "defined-header-guard.h", std::nullopt));
+  EXPECT_EQ("#pragma once\n"
+"\n"
+"void pragmaOnce();\n",
+runPragmaOnceCheck("#pragma once\n"
+   "\n"
+   "void pragmaOnce();\n",
+   "pragma-once.h", std::nullopt));
+  EXPECT_EQ("#pragma once\n"
+"\n"
+"void both();\n"
+"\n",
+runPragmaOnceCheck("#ifndef BOTH_H\n"
+   "#define BOTH_H\n"
+   "#pragma once\n"
+   "\n"
+   "void both();\n"
+   "\n"
+   "#endif // BOTH_H\n",
+   "both.h", StringRef("use #pragma once")));
+  EXPECT_EQ("#pragma once\n"
+"void neither();\n",
+   

[PATCH] D142123: [clang-tidy] Add header guard style to suggest use of #pragma once

2023-02-03 Thread Kyle Edwards via Phabricator via cfe-commits
KyleFromKitware updated this revision to Diff 494653.
KyleFromKitware added a comment.

Removed comma from documentation.


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

https://reviews.llvm.org/D142123

Files:
  clang-tools-extra/clang-tidy/readability/CMakeLists.txt
  clang-tools-extra/clang-tidy/readability/PragmaOnceHeaderGuardStyle.cpp
  clang-tools-extra/clang-tidy/readability/PragmaOnceHeaderGuardStyle.h
  clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tools-extra/docs/clang-tidy/checks/readability/header-guard.rst
  clang-tools-extra/unittests/clang-tidy/ReadabilityModuleTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/ReadabilityModuleTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/ReadabilityModuleTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/ReadabilityModuleTest.cpp
@@ -1,6 +1,8 @@
 #include "ClangTidyTest.h"
 #include "readability/BracesAroundStatementsCheck.h"
+#include "readability/HeaderGuardCheck.h"
 #include "readability/NamespaceCommentCheck.h"
+#include "readability/PragmaOnceHeaderGuardStyle.h"
 #include "readability/SimplifyBooleanExprCheck.h"
 #include "gtest/gtest.h"
 
@@ -513,6 +515,97 @@
 nullptr, "input.cc", {"-Wno-error=return-type"}));
 }
 
+namespace {
+struct UsePragmaOnceCheck : readability::HeaderGuardCheck {
+  UsePragmaOnceCheck(StringRef Name, ClangTidyContext *Context)
+  : HeaderGuardCheck(Name, Context) {}
+
+  std::unique_ptr createHeaderGuardStyle() override {
+return std::make_unique(this);
+  }
+};
+
+std::string runPragmaOnceCheck(StringRef Code, const Twine &Filename,
+   std::optional ExpectedWarning,
+   std::map PathsToContent =
+   std::map()) {
+  std::vector Errors;
+  std::string Result = test::runCheckOnCode(
+  Code, &Errors, Filename, std::string("-xc++-header"), ClangTidyOptions{},
+  std::move(PathsToContent));
+  if (Errors.size() != (size_t)ExpectedWarning.has_value())
+return "invalid error count";
+  if (ExpectedWarning && *ExpectedWarning != Errors.back().Message.Message)
+return "expected: '" + ExpectedWarning->str() + "', saw: '" +
+   Errors.back().Message.Message + "'";
+  return Result;
+}
+} // namespace
+
+TEST(PragmaOnceHeaderGuardStyleTest, AddPragmaOnce) {
+  EXPECT_EQ("#pragma once\n"
+"\n"
+"void headerGuard();\n"
+"\n",
+runPragmaOnceCheck("#ifndef HEADER_GUARD_H\n"
+   "#define HEADER_GUARD_H\n"
+   "\n"
+   "void headerGuard();\n"
+   "\n"
+   "#endif // HEADER_GUARD_H\n",
+   "header-guard.h",
+   StringRef("use #pragma once")));
+  EXPECT_EQ("#pragma once\n"
+"\n"
+"void headerGuardValue();\n"
+"\n",
+runPragmaOnceCheck("#ifndef HEADER_GUARD_VALUE_H\n"
+   "#define HEADER_GUARD_VALUE_H \\\n"
+   "1\n"
+   "\n"
+   "void headerGuardValue();\n"
+   "\n"
+   "#endif\n",
+   "header-guard-value.h",
+   StringRef("use #pragma once")));
+  EXPECT_EQ("#if !defined(DEFINED_HEADER_GUARD_H)\n"
+"#define DEFINED_HEADER_GUARD_H\n"
+"\n"
+"void definedHeaderGuard();\n"
+"\n"
+"#endif\n",
+runPragmaOnceCheck("#if !defined(DEFINED_HEADER_GUARD_H)\n"
+   "#define DEFINED_HEADER_GUARD_H\n"
+   "\n"
+   "void definedHeaderGuard();\n"
+   "\n"
+   "#endif\n",
+   "defined-header-guard.h", std::nullopt));
+  EXPECT_EQ("#pragma once\n"
+"\n"
+"void pragmaOnce();\n",
+runPragmaOnceCheck("#pragma once\n"
+   "\n"
+   "void pragmaOnce();\n",
+   "pragma-once.h", std::nullopt));
+  EXPECT_EQ("#pragma once\n"
+"\n"
+"void both();\n"
+"\n",
+runPragmaOnceCheck("#ifndef BOTH_H\n"
+   "#define BOTH_H\n"
+   "#pragma once\n"
+   "\n"
+   "void both();\n"
+   "\n"
+   "#endif // BOTH_H\n",
+   "both.h", StringRef("use #pragma once")));
+  EXPECT_EQ("#pragma once\n"
+"void neither();\n

[clang] 1285172 - [include-mapping] Implement language separation in stdlib recognizer library

2023-02-03 Thread Haojian Wu via cfe-commits

Author: Viktoriia Bakalova
Date: 2023-02-03T17:05:25+01:00
New Revision: 1285172c21ef4867d9f895c0b2ab0f338c46e36f

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

LOG: [include-mapping] Implement language separation in stdlib recognizer 
library

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

Added: 


Modified: 
clang/include/clang/Tooling/Inclusions/StandardLibrary.h
clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
clang/unittests/Tooling/StandardLibraryTest.cpp

Removed: 




diff  --git a/clang/include/clang/Tooling/Inclusions/StandardLibrary.h 
b/clang/include/clang/Tooling/Inclusions/StandardLibrary.h
index 6dc8d6d09390b..60509a9cebcab 100644
--- a/clang/include/clang/Tooling/Inclusions/StandardLibrary.h
+++ b/clang/include/clang/Tooling/Inclusions/StandardLibrary.h
@@ -30,6 +30,7 @@ namespace tooling {
 namespace stdlib {
 
 class Symbol;
+enum class Lang { C = 0, CXX, LastValue = CXX };
 
 // A standard library header, such as 
 // Lightweight class, in fact just an index into a table.
@@ -37,9 +38,10 @@ class Symbol;
 // "" and "" (and their symbols) are treated 
diff erently.
 class Header {
 public:
-  static std::vector all();
+  static std::vector all(Lang L = Lang::CXX);
   // Name should contain the angle brackets, e.g. "".
-  static std::optional named(llvm::StringRef Name);
+  static std::optional named(llvm::StringRef Name,
+ Lang Language = Lang::CXX);
 
   friend llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const Header &H) 
{
 return OS << H.name();
@@ -47,8 +49,10 @@ class Header {
   llvm::StringRef name() const;
 
 private:
-  Header(unsigned ID) : ID(ID) {}
+  Header(unsigned ID, Lang Language) : ID(ID), Language(Language) {}
   unsigned ID;
+  Lang Language;
+
   friend Symbol;
   friend llvm::DenseMapInfo;
   friend bool operator==(const Header &L, const Header &R) {
@@ -64,11 +68,11 @@ class Header {
 // for them.
 class Symbol {
 public:
-  static std::vector all();
+  static std::vector all(Lang L = Lang::CXX);
   /// \p Scope should have the trailing "::", for example:
   /// named("std::chrono::", "system_clock")
-  static std::optional named(llvm::StringRef Scope,
-  llvm::StringRef Name);
+  static std::optional
+  named(llvm::StringRef Scope, llvm::StringRef Name, Lang Language = 
Lang::CXX);
 
   friend llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const Symbol &S) 
{
 return OS << S.qualified_name();
@@ -82,8 +86,10 @@ class Symbol {
   llvm::SmallVector headers() const;
 
 private:
-  Symbol(unsigned ID) : ID(ID) {}
+  Symbol(unsigned ID, Lang Language) : ID(ID), Language(Language) {}
   unsigned ID;
+  Lang Language;
+
   friend class Recognizer;
   friend llvm::DenseMapInfo;
   friend bool operator==(const Symbol &L, const Symbol &R) {
@@ -114,10 +120,12 @@ namespace llvm {
 
 template <> struct DenseMapInfo {
   static inline clang::tooling::stdlib::Header getEmptyKey() {
-return clang::tooling::stdlib::Header(-1);
+return clang::tooling::stdlib::Header(-1,
+  clang::tooling::stdlib::Lang::CXX);
   }
   static inline clang::tooling::stdlib::Header getTombstoneKey() {
-return clang::tooling::stdlib::Header(-2);
+return clang::tooling::stdlib::Header(-2,
+  clang::tooling::stdlib::Lang::CXX);
   }
   static unsigned getHashValue(const clang::tooling::stdlib::Header &H) {
 return hash_value(H.ID);
@@ -130,10 +138,12 @@ template <> struct 
DenseMapInfo {
 
 template <> struct DenseMapInfo {
   static inline clang::tooling::stdlib::Symbol getEmptyKey() {
-return clang::tooling::stdlib::Symbol(-1);
+return clang::tooling::stdlib::Symbol(-1,
+  clang::tooling::stdlib::Lang::CXX);
   }
   static inline clang::tooling::stdlib::Symbol getTombstoneKey() {
-return clang::tooling::stdlib::Symbol(-2);
+return clang::tooling::stdlib::Symbol(-2,
+  clang::tooling::stdlib::Lang::CXX);
   }
   static unsigned getHashValue(const clang::tooling::stdlib::Symbol &S) {
 return hash_value(S.ID);

diff  --git a/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp 
b/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
index 9d06657df18a2..add8414eaf091 100644
--- a/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
+++ b/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
@@ -8,6 +8,7 @@
 
 #include "clang/Tooling/Inclusions/StandardLibrary.h"
 #include "clang/AST/Decl.h"
+#include "clang/Basic/LangOptions.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Casting.h"
 
@@ -15,46 +16,74 @@ namespace clang {
 namespace toolin

[PATCH] D137070: [clang][Interp] Support destructors

2023-02-03 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM assuming no surprises with the new test request.




Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:1915-1916
+
+if (const CXXDestructorDecl *Dtor = ElemRecord->getDestructor();
+Dtor && !Dtor->isTrivial()) {
+  for (size_t I = 0, E = Desc->getNumElems(); I != E; ++I) {

tbaeder wrote:
> aaron.ballman wrote:
> > tbaeder wrote:
> > > aaron.ballman wrote:
> > > > `isTrivial()` only works once the class has been fully built up by Sema 
> > > > IIRC; we should have a test case for that situation.
> > > Are you saying that `isTrivial()` cannot be used like this, or just that 
> > > it can, but needs a test case to ensure that this is true?
> > > 
> > > Also, how would such a test case look like?
> > `Sema::DeclareImplicitDestructor()` decides whether the destructor is 
> > trivial or not, and that is based on information that the class collects as 
> > the class is being declared. While the class is being parsed, the 
> > `DeclarationData` for the class is updated as we go and we use that to 
> > decide if we need the destructor, whether it's trivial, etc. So it's 
> > possible for us to have not seen a part of the class yet that would cause 
> > the special member function to be (non)trivial and so asking the method 
> > "are you trivial" may give a different answer depending on when the 
> > question is asked.
> > 
> > In terms of a test case, I think it would be trying to hit one of these 
> > cases http://eel.is/c++draft/class.mem#class.dtor-8 by using a constexpr 
> > function that needs to be evaluated before we get to something that causes 
> > the dtor to no longer be trivial.
> Hm, I can't come up with a reproducer for this. The class of a member 
> variable must be fully defined when the member is declared, so I can't 
> forward-declare it and then introduce a non-trivial destructor later. And as 
> soon as I add a destructor declaration (and try to define i later), the 
> destructor is automatically not trivial anymore.
Yeah, I'm struggling to make a test case as well, so let's move on.



Comment at: clang/test/AST/Interp/cxx20.cpp:439
+  static_assert(Foo::a.A == 0);
+
+

Another test case that I think would be interesting is with a static member 
that is not constexpr (to show it doesn't cause problems) and an out-of-line 
destructor just because it's a bit of an oddity: https://godbolt.org/z/YqrPMEEr4


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

https://reviews.llvm.org/D137070

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


[PATCH] D142992: [include-mapping] Implement language separation in stdlib recognizer library

2023-02-03 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1285172c21ef: [include-mapping] Implement language 
separation in stdlib recognizer library (authored by VitaNuo, committed by 
hokein).

Changed prior to commit:
  https://reviews.llvm.org/D142992?vs=494611&id=494654#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142992

Files:
  clang/include/clang/Tooling/Inclusions/StandardLibrary.h
  clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
  clang/unittests/Tooling/StandardLibraryTest.cpp

Index: clang/unittests/Tooling/StandardLibraryTest.cpp
===
--- clang/unittests/Tooling/StandardLibraryTest.cpp
+++ clang/unittests/Tooling/StandardLibraryTest.cpp
@@ -40,6 +40,9 @@
   EXPECT_EQ(llvm::to_string(*VectorH), "");
   EXPECT_FALSE(stdlib::Header::named("HeadersTests.cpp"));
 
+  EXPECT_TRUE(stdlib::Header::named("", stdlib::Lang::CXX));
+  EXPECT_FALSE(stdlib::Header::named("", stdlib::Lang::C));
+
   auto Vector = stdlib::Symbol::named("std::", "vector");
   EXPECT_TRUE(Vector);
   EXPECT_EQ(Vector->scope(), "std::");
@@ -49,11 +52,21 @@
   EXPECT_FALSE(stdlib::Symbol::named("std::", "dongle"));
   EXPECT_FALSE(stdlib::Symbol::named("clang::", "ASTContext"));
 
+  EXPECT_TRUE(stdlib::Symbol::named("std::", "vector", stdlib::Lang::CXX));
+  EXPECT_FALSE(stdlib::Symbol::named("std::", "vector", stdlib::Lang::C));
+
   EXPECT_EQ(Vector->header(), *VectorH);
   EXPECT_THAT(Vector->headers(), ElementsAre(*VectorH));
 
   EXPECT_THAT(stdlib::Header::all(), Contains(*VectorH));
   EXPECT_THAT(stdlib::Symbol::all(), Contains(*Vector));
+  EXPECT_FALSE(stdlib::Header::named(""));
+  EXPECT_FALSE(stdlib::Header::named("", stdlib::Lang::CXX));
+  EXPECT_TRUE(stdlib::Header::named("", stdlib::Lang::C));
+
+  EXPECT_FALSE(stdlib::Symbol::named("", "int16_t"));
+  EXPECT_FALSE(stdlib::Symbol::named("", "int16_t", stdlib::Lang::CXX));
+  EXPECT_TRUE(stdlib::Symbol::named("", "int16_t", stdlib::Lang::C));
 }
 
 TEST(StdlibTest, Recognizer) {
@@ -104,10 +117,14 @@
 
   EXPECT_EQ(Recognizer(&VectorNonstd), std::nullopt);
   EXPECT_EQ(Recognizer(Vec), stdlib::Symbol::named("std::", "vector"));
+  EXPECT_EQ(Recognizer(Vec),
+stdlib::Symbol::named("std::", "vector", stdlib::Lang::CXX));
   EXPECT_EQ(Recognizer(Nest), stdlib::Symbol::named("std::", "vector"));
   EXPECT_EQ(Recognizer(Clock),
 stdlib::Symbol::named("std::chrono::", "system_clock"));
   EXPECT_EQ(Recognizer(CDivT), stdlib::Symbol::named("", "div_t"));
+  EXPECT_EQ(Recognizer(CDivT),
+stdlib::Symbol::named("", "div_t", stdlib::Lang::C));
   EXPECT_EQ(Recognizer(Sec), std::nullopt);
 }
 
Index: clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
===
--- clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
+++ clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
@@ -8,6 +8,7 @@
 
 #include "clang/Tooling/Inclusions/StandardLibrary.h"
 #include "clang/AST/Decl.h"
+#include "clang/Basic/LangOptions.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Casting.h"
 
@@ -15,46 +16,74 @@
 namespace tooling {
 namespace stdlib {
 
-// Header::ID => header name
-static llvm::StringRef *HeaderNames;
-// Header name => Header::ID
-static llvm::DenseMap *HeaderIDs;
-
-static unsigned SymbolCount = 0;
-// Symbol::ID => symbol qualified_name/name/scope
-static struct SymbolName {
-  const char *Data;  // std::vector
-  unsigned ScopeLen; // ~
-  unsigned NameLen;  //  ~~
-} *SymbolNames;
+namespace {
 // Symbol name -> Symbol::ID, within a namespace.
 using NSSymbolMap = llvm::DenseMap;
-static llvm::DenseMap *NamespaceSymbols;
-// Symbol::ID => Header::ID
-static unsigned *SymbolHeaderIDs;
 
-static int initialize() {
-  SymbolCount = 0;
-#define SYMBOL(Name, NS, Header) ++SymbolCount;
+// A Mapping per language.
+struct SymbolHeaderMapping {
+  llvm::StringRef *HeaderNames = nullptr;
+  // Header name => Header::ID
+  llvm::DenseMap *HeaderIDs;
+
+  unsigned SymbolCount = 0;
+  // Symbol::ID => symbol qualified_name/name/scope
+  struct SymbolName {
+const char *Data;  // std::vector
+unsigned ScopeLen; // ~
+unsigned NameLen;  //  ~~
+  } *SymbolNames = nullptr;
+  // Symbol name -> Symbol::ID, within a namespace.
+  llvm::DenseMap *NamespaceSymbols = nullptr;
+  // Symbol::ID => Header::ID
+  unsigned *SymbolHeaderIDs = nullptr;
+};
+} // namespace
+static SymbolHeaderMapping
+*LanguageMappings[static_cast(Lang::LastValue) + 1];
+static const SymbolHeaderMapping *getMappingPerLang(Lang L) {
+  return LanguageMappings[static_cast(L)];
+}
+
+static int countSymbols(Lang Language) {
+  unsigned SymCount = 0;
+#define SYMBOL(Name, NS, Header) ++SymCount;
+  switch (Language) {
+  case Lang::C:
 #include "clang/Tooling/Inclusions/CSy

[PATCH] D143274: [clangd] Remove the direct use of StdSymbolMapping.inc usage.

2023-02-03 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: kadircet.
Herald added subscribers: arphaman, mgrang.
Herald added a project: All.
hokein requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Replace them with the library APIs.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143274

Files:
  clang-tools-extra/clangd/index/CanonicalIncludes.cpp
  clang-tools-extra/clangd/index/StdLib.cpp

Index: clang-tools-extra/clangd/index/StdLib.cpp
===
--- clang-tools-extra/clangd/index/StdLib.cpp
+++ clang-tools-extra/clangd/index/StdLib.cpp
@@ -22,6 +22,7 @@
 #include "clang/Basic/LangOptions.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Lex/PreprocessorOptions.h"
+#include "clang/Tooling/Inclusions/StandardLibrary.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/MemoryBuffer.h"
@@ -67,7 +68,7 @@
 }
 
 std::string buildUmbrella(llvm::StringLiteral Mandatory,
-  std::vector Headers) {
+  llvm::ArrayRef Headers) {
   std::string Result;
   llvm::raw_string_ostream OS(Result);
 
@@ -80,13 +81,11 @@
   "#endif\n",
   Mandatory);
 
-  llvm::sort(Headers);
-  auto Last = std::unique(Headers.begin(), Headers.end());
-  for (auto Header = Headers.begin(); Header != Last; ++Header) {
+  for (auto Header : Headers) {
 OS << llvm::formatv("#if __has_include({0})\n"
 "#include {0}\n"
 "#endif\n",
-*Header);
+Header);
   }
   OS.flush();
   return Result;
@@ -102,20 +101,14 @@
   Lang L = langFromOpts(LO);
   switch (L) {
   case CXX:
-static std::string *UmbrellaCXX =
-new std::string(buildUmbrella(mandatoryHeader(L), {
-#define SYMBOL(Name, NameSpace, Header) #Header,
-#include "clang/Tooling/Inclusions/StdSymbolMap.inc"
-#undef SYMBOL
-  }));
+static std::string *UmbrellaCXX = new std::string(buildUmbrella(
+mandatoryHeader(L),
+tooling::stdlib::Header::all(tooling::stdlib::Lang::CXX)));
 return *UmbrellaCXX;
   case C:
-static std::string *UmbrellaC =
-new std::string(buildUmbrella(mandatoryHeader(L), {
-#define SYMBOL(Name, NameSpace, Header) #Header,
-#include "clang/Tooling/Inclusions/CSymbolMap.inc"
-#undef SYMBOL
-  }));
+static std::string *UmbrellaC = new std::string(
+buildUmbrella(mandatoryHeader(L),
+  tooling::stdlib::Header::all(tooling::stdlib::Lang::C)));
 return *UmbrellaC;
   }
   llvm_unreachable("invalid Lang in langFromOpts");
@@ -141,13 +134,10 @@
 
   static auto &StandardHeaders = *[] {
 auto *Set = new llvm::DenseSet();
-for (llvm::StringRef Header : {
-#define SYMBOL(Name, NameSpace, Header) #Header,
-#include "clang/Tooling/Inclusions/CSymbolMap.inc"
-#include "clang/Tooling/Inclusions/StdSymbolMap.inc"
-#undef SYMBOL
- })
-  Set->insert(Header);
+for (auto Header : tooling::stdlib::Header::all(tooling::stdlib::Lang::CXX))
+  Set->insert(Header.name());
+for (auto Header : tooling::stdlib::Header::all(tooling::stdlib::Lang::C))
+  Set->insert(Header.name());
 return Set;
   }();
 
Index: clang-tools-extra/clangd/index/CanonicalIncludes.cpp
===
--- clang-tools-extra/clangd/index/CanonicalIncludes.cpp
+++ clang-tools-extra/clangd/index/CanonicalIncludes.cpp
@@ -10,6 +10,7 @@
 #include "Headers.h"
 #include "clang/Basic/FileEntry.h"
 #include "clang/Tooling/Inclusions/HeaderAnalysis.h"
+#include "clang/Tooling/Inclusions/StandardLibrary.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/FileSystem/UniqueID.h"
 #include "llvm/Support/Path.h"
@@ -733,24 +734,24 @@
 
 void CanonicalIncludes::addSystemHeadersMapping(const LangOptions &Language) {
   if (Language.CPlusPlus) {
-static const auto *Symbols = new llvm::StringMap({
-#define SYMBOL(Name, NameSpace, Header) {#NameSpace #Name, #Header},
-#include "clang/Tooling/Inclusions/StdSymbolMap.inc"
-// There are two std::move()s, this is by far the most common.
-SYMBOL(move, std::, )
-// There are multiple headers for size_t, pick one.
-SYMBOL(size_t, std::, )
-#undef SYMBOL
-});
+static const auto *Symbols = []() {
+  auto *Result = new llvm::StringMap(
+  {// There are two std::move()s, this is by far the most common.
+   {"std::move", ""},
+   // There are multiple headers for size_t, pick one.
+   {"std::size_t", ""}});
+  for (auto Sym : tooling::stdlib::Symbol::all(tooling::stdlib::Lang::CXX))
+Result->try_emplace(Sym.qualified_name(), Sym.header().name());
+  return 

[PATCH] D137070: [clang][Interp] Support destructors

2023-02-03 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 494660.
tbaeder marked an inline comment as done.
tbaeder added a comment.

No surprises I think.


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

https://reviews.llvm.org/D137070

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/ByteCodeStmtGen.cpp
  clang/test/AST/Interp/cxx20.cpp

Index: clang/test/AST/Interp/cxx20.cpp
===
--- clang/test/AST/Interp/cxx20.cpp
+++ clang/test/AST/Interp/cxx20.cpp
@@ -217,3 +217,250 @@
// ref-error {{must be initialized by a constant expression}}
 
 };
+
+namespace Destructors {
+
+  class Inc final {
+  public:
+int &I;
+constexpr Inc(int &I) : I(I) {}
+constexpr ~Inc() {
+  I++;
+}
+  };
+
+  class Dec final {
+  public:
+int &I;
+constexpr Dec(int &I) : I(I) {}
+constexpr ~Dec() {
+  I--;
+}
+  };
+
+
+
+  constexpr int m() {
+int i = 0;
+{
+  Inc f1(i);
+  Inc f2(i);
+  Inc f3(i);
+}
+return i;
+  }
+  static_assert(m() == 3, "");
+
+
+  constexpr int C() {
+int i = 0;
+
+while (i < 10) {
+  Inc inc(i);
+  continue;
+  Dec dec(i);
+}
+return i;
+  }
+  static_assert(C() == 10, "");
+
+
+  constexpr int D() {
+int i = 0;
+
+{
+  Inc i1(i);
+  {
+Inc i2(i);
+return i;
+  }
+}
+
+return i;
+  }
+  static_assert(D() == 0, "");
+
+  constexpr int E() {
+int i = 0;
+
+for(;;) {
+  Inc i1(i);
+  break;
+}
+return i;
+  }
+  static_assert(E() == 1, "");
+
+
+  /// FIXME: This should be rejected, since we call the destructor
+  ///   twice. However, GCC doesn't care either.
+  constexpr int ManualDtor() {
+int i = 0;
+{
+  Inc I(i); // ref-note {{destroying object 'I' whose lifetime has already ended}}
+  I.~Inc();
+}
+return i;
+  }
+  static_assert(ManualDtor() == 1, ""); // expected-error {{static assertion failed}} \
+// expected-note {{evaluates to '2 == 1'}} \
+// ref-error {{not an integral constant expression}} \
+// ref-note {{in call to 'ManualDtor()'}}
+
+  constexpr void doInc(int &i) {
+Inc I(i);
+return;
+  }
+  constexpr int testInc() {
+int i = 0;
+doInc(i);
+return i;
+  }
+  static_assert(testInc() == 1, "");
+  constexpr void doInc2(int &i) {
+Inc I(i);
+// No return statement.
+  }
+   constexpr int testInc2() {
+int i = 0;
+doInc2(i);
+return i;
+  }
+  static_assert(testInc2() == 1, "");
+
+
+  namespace DtorOrder {
+class A {
+  public:
+  int &I;
+  constexpr A(int &I) : I(I) {}
+  constexpr ~A() {
+I = 1337;
+  }
+};
+
+class B : public A {
+  public:
+  constexpr B(int &I) : A(I) {}
+  constexpr ~B() {
+I = 42;
+  }
+};
+
+constexpr int foo() {
+  int i = 0;
+  {
+B b(i);
+  }
+  return i;
+}
+
+static_assert(foo() == 1337);
+  }
+
+  class FieldDtor1 {
+  public:
+Inc I1;
+Inc I2;
+constexpr FieldDtor1(int &I) : I1(I), I2(I){}
+  };
+
+  constexpr int foo2() {
+int i = 0;
+{
+  FieldDtor1 FD1(i);
+}
+return i;
+  }
+
+  static_assert(foo2() == 2);
+
+  class FieldDtor2 {
+  public:
+Inc Incs[3];
+constexpr FieldDtor2(int &I)  : Incs{Inc(I), Inc(I), Inc(I)} {}
+  };
+
+  constexpr int foo3() {
+int i = 0;
+{
+  FieldDtor2 FD2(i);
+}
+return i;
+  }
+
+  static_assert(foo3() == 3);
+
+  struct ArrD {
+int index;
+int *arr;
+int &p;
+constexpr ~ArrD() {
+  arr[p] = index;
+  ++p;
+}
+  };
+  constexpr bool ArrayOrder() {
+int order[3] = {0, 0, 0};
+int p = 0;
+{
+  ArrD ds[3] = {
+{1, order, p},
+{2, order, p},
+{3, order, p},
+  };
+  // ds will be destroyed.
+}
+return order[0] == 3 && order[1] == 2 && order[2] == 1;
+  }
+  static_assert(ArrayOrder());
+
+
+  // Static members aren't destroyed.
+  class Dec2 {
+  public:
+int A = 0;
+constexpr ~Dec2() {
+  A++;
+}
+  };
+  class Foo {
+  public:
+static constexpr Dec2 a;
+static Dec2 b;
+  };
+  static_assert(Foo::a.A == 0);
+  constexpr bool f() {
+Foo f;
+return true;
+  }
+  static_assert(Foo::a.A == 0);
+  static_assert(f());
+  static_assert(Foo::a.A == 0);
+
+
+  struct NotConstexpr {
+NotConstexpr() {}
+~NotConstexpr() {}
+  };
+
+  struct Outer {
+constexpr Outer() = default;
+constexpr ~Outer();
+
+constexpr int foo() {
+  return 12;
+}
+
+constexpr int bar()const  {
+  return Outer{}.foo();
+}
+
+static NotConstexpr Val;
+  };
+
+  constexpr Outer::~Outer() {}
+
+  constexpr Outer O;
+  static_assert(O.bar() == 12);
+}
Index: clan

[PATCH] D142822: [clang] ASTImporter: Fix importing of va_list types and declarations

2023-02-03 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added a comment.

I looked at some of the failing tests but can not decide how to fix the 
problems. The problem seems to be with the extra `namespace std` that was not 
there before. I do not know what the tests are exactly testing. A part of the 
tests can be fixed by adding new expect lines but these must be platform 
specific.




Comment at: clang-tools-extra/test/clang-tidy/checkers/cert/dcl58-cpp.cpp:3
+// RUN: %check_clang_tidy -std=c++17-or-later %s cert-dcl58-cpp %t -- -- -I 
%clang_tidy_headers -target aarch64
+// RUN: %check_clang_tidy -std=c++17-or-later %s cert-dcl58-cpp %t -- -- -I 
%clang_tidy_headers -target arm
+

I am not sure if these platform specific should be added. A problem was 
discovered on this platform but this could be true for all other tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142822

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


[PATCH] D142800: [Clang][Diagnostic] Add `-Wcomparison-op-parentheses` to warn on chained comparisons

2023-02-03 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:6654
+def warn_comp_op_in_comp_op : Warning<
+  "'%0' within '%1'">, InGroup, DefaultIgnore;
+def warn_rel_op_in_rel_op : Warning<

Spit-balling wording ideas:

`'%0' results in a boolean value which is then compared using '%1'; did you 
mean a three-way comparison instead?`

`comparing the boolean result of '%0' with '%1' does not perform a three-way 
comparison`

Also, why are these diagnostics off by default? Do we have some idea as to the 
false positive rate?



Comment at: clang/lib/Sema/SemaExpr.cpp:15548
+
+  SuggestParentheses(Self, Bop->getOperatorLoc(),
+ Self.PDiag(diag::note_precedence_silence)

erichkeane wrote:
> hazohelet wrote:
> > erichkeane wrote:
> > > I find myself wondering if we could provide a better 'suggested fix' 
> > > here.  Aaron is better with the diagnostics than I am, but I would think 
> > > that someone doing:
> > > 
> > > `a < b < c` PROBABLY doesn't mean that, they probably mean: `a < b && b < 
> > > c`.
> > > 
> > > Also, is the mistake the 'same' when they do something like `a > b != c` 
> > > ?  It would seem to me that mixing operators might make it something 
> > > either more intentional/meaningful.  ADDITIONALLY, in the case where they 
> > > are booleans, these end up being overly noisy.  The pattern of the  == c 
> > > (where 'c' is bool, or convertible to bool) is probably intentional.
> > > 
> > > I think the logic here needs to be more complicated than just "Comparison 
> > > within Comparison", however I don't have a fully formed idea of when to 
> > > diagnose.
> > > 
> > > @tahonermann : Do you perhaps have a good idea?
> > > I find myself wondering if we could provide a better 'suggested fix' 
> > > here.  Aaron is better with the diagnostics than I am, but I would think 
> > > that someone doing:
> > > 
> > > `a < b < c` PROBABLY doesn't mean that, they probably mean: `a < b && b < 
> > > c`.
> > 
> > Yes. We could provide a better fix-it hint.
> > My idea:
> > - In the case of chained relational operators (`<`, `>`, `<=`, `>=`), clang 
> > suggests adding `&&`.
> > - In other cases, clang suggests parentheses.
> > How about doing it this way? It's similar to how Rust handles chained 
> > comparisons.
> > 
> > > Also, is the mistake the 'same' when they do something like `a > b != c` 
> > > ?  It would seem to me that mixing operators might make it something 
> > > either more intentional/meaningful.  ADDITIONALLY, in the case where they 
> > > are booleans, these end up being overly noisy.  The pattern of the  == c 
> > > (where 'c' is bool, or convertible to bool) is probably intentional.
> > > 
> > > I think the logic here needs to be more complicated than just "Comparison 
> > > within Comparison", however I don't have a fully formed idea of when to 
> > > diagnose.
> > 
> > I have a differing perspective on suppressing the warning for boolean and 
> > boolean-convertible values.
> > There are two possible programmer mistakes in chained comparisons.
> > 1. `a > b != c` misunderstood as `a > b && b != c`
> > 2. `a > b != c` misunderstood as `a > (b != c)`
> > While the latter is considered rare in this scenario, the former could be 
> > likely to happen due to other languages, such as Python handling chained 
> > comparisons in the former manner.
> > 
> > 
> I'd be interested to see the fixit-hints for the first bit, also to see how 
> others feel about it here.
> 
> 
> IMO, `a > b != c` to mean `(a > b) != c` is a reasonably common pattern I 
> suspect we won't want to be noisy on.
Common? I did a code search and everything I'm seeing is either a false 
positive (a lot of template stuff) or within a comment: 
https://sourcegraph.com/search?q=context:global+%5BA-Za-z0-9_%5D%2B%5Cs*%28%5C%3D%5C%3D%7C%5C%21%5C%3D%7C%5C%3C%7C%5C%3E%7C%5C%3C%5C%3D%7C%5C%3E%5C%3D%29%5Cs*%5BA-Za-z0-9_%5D%2B%5Cs*%5B%5C%21%5C%3D%5D%5C%3D%5Cs*%5BA-Za-z0-9_%5D%2B+lang:c+lang:C%2B%2B+&patternType=regexp&sm=1&groupBy=repo


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

https://reviews.llvm.org/D142800

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


[clang] 74ce297 - Revert "[Clang] Implement Change scope of lambda trailing-return-type"

2023-02-03 Thread Jordan Rupprecht via cfe-commits

Author: Jordan Rupprecht
Date: 2023-02-03T08:49:34-08:00
New Revision: 74ce297045bac4bc475b8e762d2a1ea19bb16d3c

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

LOG: Revert "[Clang] Implement Change scope of lambda trailing-return-type"

This reverts commit d708a186b6a9b050d09558163dd353d9f738c82d (and typo fix 
e4bc9898ddbeb70bc49d713bbf863f050f21e03f). It causes a compilation error for 
this:

```
struct StringLiteral {
  template 
  StringLiteral(const char (&array)[N])
  __attribute__((enable_if(N > 0 && N == __builtin_strlen(array) + 1,
   "invalid string literal")));
};

struct Message {
  Message(StringLiteral);
};

void Func1() {
  auto x = Message("x");  // Note: this is fine

  // Note: "xx\0" to force a different type, StringLiteral<3>, otherwise this
  // successfully builds.
  auto y = [&](decltype(Message("xx"))) {};

  // ^ fails with: repro.cc:18:13: error: reference to local variable 'array'
  // declared in enclosing function 'StringLiteral::StringLiteral<3>'

  (void)x;
  (void)y;
}
```

More details posted to D124351.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/DeclCXX.h
clang/include/clang/Sema/Scope.h
clang/include/clang/Sema/ScopeInfo.h
clang/include/clang/Sema/Sema.h
clang/lib/Parse/ParseExprCXX.cpp
clang/lib/Sema/Scope.cpp
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaCXXScopeSpec.cpp
clang/lib/Sema/SemaConcept.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaLambda.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/lib/Sema/TreeTransform.h
clang/test/CXX/expr/expr.prim/expr.prim.lambda/p11-1y.cpp
clang/test/CXX/expr/expr.prim/expr.prim.lambda/p4.cpp
clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
clang/www/cxx_status.html

Removed: 
clang/test/SemaCXX/lambda-capture-type-deduction.cpp



diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d2f1919f24a3..4463f0317454 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -130,11 +130,6 @@ C++20 Feature Support
 C++2b Feature Support
 ^
 
-- Implemented `P2036R3: Change scope of lambda trailing-return-type 
`_
-  and `P2579R0 Mitigation strategies for P2036 `_.
-  These proposals modify how variables captured in lambdas can appear in 
trailing return type
-  expressions and how their types are deduced therein, in all C++ language 
versions.
-
 CUDA/HIP Language Changes in Clang
 --
 

diff  --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index ff8f8a1bb12d..11276c77490c 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1092,11 +1092,6 @@ class CXXRecordDecl : public RecordDecl {
 
   unsigned capture_size() const { return getLambdaData().NumCaptures; }
 
-  const LambdaCapture *getCapture(unsigned I) const {
-assert(isLambda() && I < capture_size() && "invalid index for capture");
-return captures_begin() + I;
-  }
-
   using conversion_iterator = UnresolvedSetIterator;
 
   conversion_iterator conversion_begin() const {
@@ -1831,20 +1826,6 @@ class CXXRecordDecl : public RecordDecl {
 return getLambdaData().MethodTyInfo;
   }
 
-  void setLambdaTypeInfo(TypeSourceInfo *TS) {
-assert(DefinitionData && DefinitionData->IsLambda &&
-   "setting lambda property of non-lambda class");
-auto &DL = static_cast(*DefinitionData);
-DL.MethodTyInfo = TS;
-  }
-
-  void setLambdaIsGeneric(bool IsGeneric) {
-assert(DefinitionData && DefinitionData->IsLambda &&
-   "setting lambda property of non-lambda class");
-auto &DL = static_cast(*DefinitionData);
-DL.IsGenericLambda = IsGeneric;
-  }
-
   // Determine whether this type is an Interface Like type for
   // __interface inheritance purposes.
   bool isInterfaceLike() const;

diff  --git a/clang/include/clang/Sema/Scope.h 
b/clang/include/clang/Sema/Scope.h
index 9e81706cd2aa..be5cdb62045b 100644
--- a/clang/include/clang/Sema/Scope.h
+++ b/clang/include/clang/Sema/Scope.h
@@ -145,11 +145,6 @@ class Scope {
 /// This is a scope of some OpenMP directive with
 /// order clause which specifies concurrent
 OpenMPOrderClauseScope = 0x400,
-/// This is the scope for a lambda, after the lambda introducer.
-/// Lambdas need two FunctionPrototypeScope scopes (because there is a
-/// template scope in between), the outer scope does not increase the
-/// depth of recursion.
-LambdaScope = 0x800,
   };
 
 private:

diff  --git a/clang/include/clang/Sema/ScopeInfo.h 
b/clang/include/clang/Sema/ScopeInfo.h

[PATCH] D124351: [Clang] Implement Change scope of lambda trailing-return-type

2023-02-03 Thread Jordan Rupprecht via Phabricator via cfe-commits
rupprecht added a comment.

In D124351#4102679 , @aaron.ballman 
wrote:

> In D124351#4102634 , @eaeltsin 
> wrote:
>
>>> Looks like we fail to enter the appropriate context somewhere (my guess is 
>>> that it might be specific to the attribute but it's hard to say without 
>>> picking around), definitely a bug
>>>
>>> I'll be away the next 2 weeks, I'll look at it when I get back. Maybe we 
>>> should track it in an issue though.
>>
>> Should we revert this then?
>
> Yes, I think we should. We should also file an issue so @cor3ntin doesn't 
> lose track of the issue. Anyone want to volunteer to do that? (I can do it 
> early next week otherwise.)

Done in 74ce297045bac4bc475b8e762d2a1ea19bb16d3c 
 and filed 
https://github.com/llvm/llvm-project/issues/60518 to track re-landing this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124351

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


[PATCH] D124351: [Clang] Implement Change scope of lambda trailing-return-type

2023-02-03 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D124351#4102818 , @rupprecht wrote:

> In D124351#4102679 , @aaron.ballman 
> wrote:
>
>> In D124351#4102634 , @eaeltsin 
>> wrote:
>>
 Looks like we fail to enter the appropriate context somewhere (my guess is 
 that it might be specific to the attribute but it's hard to say without 
 picking around), definitely a bug

 I'll be away the next 2 weeks, I'll look at it when I get back. Maybe we 
 should track it in an issue though.
>>>
>>> Should we revert this then?
>>
>> Yes, I think we should. We should also file an issue so @cor3ntin doesn't 
>> lose track of the issue. Anyone want to volunteer to do that? (I can do it 
>> early next week otherwise.)
>
> Done in 74ce297045bac4bc475b8e762d2a1ea19bb16d3c 
>  and 
> filed https://github.com/llvm/llvm-project/issues/60518 to track re-landing 
> this.

Thank you (and thank you for letting us know about the issue)!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124351

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


[PATCH] D127762: [Clang][AArch64] Add ACLE attributes for SME.

2023-02-03 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D127762#4102578 , @erichkeane 
wrote:

> By standard imp-limits, apparently we only need to handle 8 bits worth for 
> the Exception Spec types.  I'd be tempted, based on exception specs being 
> deprecated and rarely used, to reduce it to an 'unsigned short' (2 bytes), 
> which makes this cost-free on 32 bit machines.  WDYT?

It's a bit orthogonal to this patch, but I think it's a reasonable change to 
make so long as we don't break significant code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127762

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


[PATCH] D142123: [clang-tidy] Add header guard style to suggest use of #pragma once

2023-02-03 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

LGTM assuming precommit CI doesn't discover any surprises, but hopefully 
@njames93 or @carlosgalvezp can weigh in as well since they've been in this 
code more recently than I have.




Comment at: 
clang-tools-extra/unittests/clang-tidy/ReadabilityModuleTest.cpp:569-571
+runPragmaOnceCheck("#ifndef BOTH_H\n"
+   "#define BOTH_H\n"
+   "#pragma once\n"

KyleFromKitware wrote:
> aaron.ballman wrote:
> > How about a test for:
> > ```
> > #if !defined(HEADER_GUARD_H)
> > #define HEADER_GUARD_H 1
> > 
> > #endif
> > ```
> > and a test for what happens when there's no header guard or pragma once in 
> > the file.
> > How about a test for:
> > ```
> > #if !defined(HEADER_GUARD_H)
> > #define HEADER_GUARD_H 1
> > 
> > #endif
> > ```
> 
> Good catch. The case of `!defined()` was not being handled by the existing 
> header guard check except to basically ignore it. The `#pragma once` check 
> crashed on this case. I've updated it to also ignore the `!defined()` case.
> 
> > and a test for what happens when there's no header guard or pragma once in 
> > the file.
> 
> I already have this, see the "neither" test at the bottom.
>> and a test for what happens when there's no header guard or pragma once in 
>> the file.
> I already have this, see the "neither" test at the bottom.

Ah! I was misreading:
```
  EXPECT_EQ("#pragma once\n"
"void neither();\n",
runPragmaOnceCheck("void neither();\n", "neither.h",
   StringRef("use #pragma once")));
```
as having the pragma once in there, which is backwards. Thanks!


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

https://reviews.llvm.org/D142123

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


[PATCH] D143280: [include-mapping] Better #includes support for std input/output symbols

2023-02-03 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: kadircet.
Herald added a project: All.
hokein requested review of this revision.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143280

Files:
  clang/include/clang/Tooling/Inclusions/StdSymbolMap.inc
  clang/tools/include-mapping/gen_std.py

Index: clang/tools/include-mapping/gen_std.py
===
--- clang/tools/include-mapping/gen_std.py
+++ clang/tools/include-mapping/gen_std.py
@@ -40,6 +40,7 @@
 import os
 import sys
 
+
 CODE_PREFIX = """\
 //===-- gen_std.py generated file ---*- C++ -*-===//
 //
@@ -66,6 +67,105 @@
   required=True) 
   return parser.parse_args()
 
+def AdditionalHeadersForIOSymbols(symbol):
+  # IO-related symbols declared in the  header, per C++
+  # [iosfwd.syn 31.3.1]:
+  iosfwd_symbols = [
+  'basic_ios',
+  'basic_streambuf',
+  'basic_istream',
+  'basic_ostream',
+  'basic_iostream',
+
+  'basic_stringbuf',
+  'basic_istringstream',
+  'basic_ostringstream',
+  'basic_stringstream',
+
+  'basic_spanbuf',
+  'basic_ispanstream',
+  'basic_ospanstream',
+  'basic_spanstream',
+
+  'basic_filebuf',
+  'basic_ifstream',
+  'basic_ofstream',
+  'basic_fstream',
+
+  'basic_syncbuf',
+  'basic_osyncstream',
+
+  'istreambuf_iterator',
+  'ostreambuf_iterator',
+
+  'ios',
+  'wios',
+
+  'streambuf',
+  'istream',
+  'ostream',
+  'iostream',
+
+  'stringbuf',
+  'istringstream',
+  'ostringstream',
+  'stringstream',
+
+  'spanbuf',
+  'ispanstream',
+  'ospanstream',
+  'spanstream',
+
+  'filebuf',
+  'ifstream',
+  'ofstream',
+  'fstream',
+
+  'syncbuf',
+  'osyncstream',
+
+  'wstreambuf',
+  'wistream',
+  'wostream',
+  'wiostream',
+
+  'wstringbuf',
+  'wistringstream',
+  'wostringstream',
+  'wstringstream',
+
+  'wspanbuf',
+  'wispanstream',
+  'wospanstream',
+  'wspanstream',
+
+  'wfilebuf',
+  'wifstream',
+  'wofstream',
+  'wfstream',
+
+  'wsyncbuf',
+  'wosyncstream',
+
+  'fpos',
+  'streampos',
+  'wstreampos',
+  'u8streampos',
+  'u16streampos',
+  'u32streampos',
+  ]
+  assert(len(symbol.headers) == 1)
+  sym_header = symbol.headers[0]
+  headers = [sym_header]
+  if symbol.name in iosfwd_symbols:
+headers.append("")
+
+  #  is an alternative of , , , .
+  # per C++ [iostream.syn 31.4.1]
+  if sym_header in ["", "", "", ""]:
+headers.append("")
+  return headers
+
 
 def main():
   args = ParseArg()
@@ -109,8 +209,9 @@
   for symbol in symbols:
 if len(symbol.headers) == 1:
   # SYMBOL(unqualified_name, namespace, header)
-  print("SYMBOL(%s, %s, %s)" % (symbol.name, symbol.namespace,
-symbol.headers[0]))
+  for header in AdditionalHeadersForIOSymbols(symbol):
+print("SYMBOL(%s, %s, %s)" % (symbol.name, symbol.namespace,
+  header))
 elif len(symbol.headers) == 0:
   sys.stderr.write("No header found for symbol %s\n" % symbol.name)
 else:
Index: clang/include/clang/Tooling/Inclusions/StdSymbolMap.inc
===
--- clang/include/clang/Tooling/Inclusions/StdSymbolMap.inc
+++ clang/include/clang/Tooling/Inclusions/StdSymbolMap.inc
@@ -149,32 +149,56 @@
 SYMBOL(barrier, std::, )
 SYMBOL(basic_common_reference, std::, )
 SYMBOL(basic_filebuf, std::, )
+SYMBOL(basic_filebuf, std::, )
 SYMBOL(basic_format_arg, std::, )
 SYMBOL(basic_format_args, std::, )
 SYMBOL(basic_format_context, std::, )
 SYMBOL(basic_format_parse_context, std::, )
 SYMBOL(basic_fstream, std::, )
+SYMBOL(basic_fstream, std::, )
 SYMBOL(basic_ifstream, std::, )
+SYMBOL(basic_ifstream, std::, )
 SYMBOL(basic_ios, std::, )
+SYMBOL(basic_ios, std::, )
+SYMBOL(basic_ios, std::, )
 SYMBOL(basic_iostream, std::, )
+SYMBOL(basic_iostream, std::, )
+SYMBOL(basic_iostream, std::, )
 SYMBOL(basic_ispanstream, std::, )
+SYMBOL(basic_ispanstream, std::, )
 SYMBOL(basic_istream, std::, )
+SYMBOL(basic_istream, std::, )
+SYMBOL(basic_istream, std::, )
 SYMBOL(basic_istringstream, std::, )
+SYMBOL(basic_istringstream, std::, )
 SYMBOL(basic_ofstream, std::, )
+SYMBOL(basic_ofstream, std::, )
 SYMBOL(basic_ospanstream, std::, )
+SYMBOL(basic_ospanstream, std::, )
 SYMBOL(basic_ostream, std::, )
+SYMBOL(basic_ostream, std::, )
+SYMBOL(basic_ostream, std::, )
 SYMBOL(basic_ostringstream, std::, )
+SYMBOL(basic_ostringstream, std::, )
 SYMBOL(basic_osyncstream, std::, )
+SYMBOL(basic_osyncstream, std::, )
 SYMBOL(basic_regex, std::, )
 SYMBOL(basic_spanbuf, std::, )
+SYMBOL(basic_spanbuf, std::, )
 SYMBOL(basic_spanstream, std::, )
+SYMBOL(basic_spanstream, std::, )
 SYMBOL(

[PATCH] D142123: [clang-tidy] Add header guard style to suggest use of #pragma once

2023-02-03 Thread Kyle Edwards via Phabricator via cfe-commits
KyleFromKitware added a comment.

CI on all seven commits in this stack looks good.


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

https://reviews.llvm.org/D142123

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


[PATCH] D142384: [C++20] Fix a crash with modules.

2023-02-03 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

It looks like this is making one of Chromium's clang plugins traverse (and 
flag) more code: https://bugs.chromium.org/p/chromium/issues/detail?id=1412769
No modules involved :)

I don't know if that's expected or not, but maybe that behavior change could be 
used as an inspiration for a test case.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142384

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


[clang] 8c71229 - [NFC][TargetParser] Remove llvm/Support/AArch64TargetParser.h

2023-02-03 Thread Archibald Elliott via cfe-commits

Author: Archibald Elliott
Date: 2023-02-03T17:34:01Z
New Revision: 8c712296fb75ff73db08f92444b35c438c01a405

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

LOG: [NFC][TargetParser] Remove llvm/Support/AArch64TargetParser.h

Removes the forwarding header `llvm/Support/AArch64TargetParser.h`.

I am proposing to do this for all the forwarding headers left after
rGf09cf34d00625e57dea5317a3ac0412c07292148 - for each header:
- Update all relevant in-tree includes
- Remove the forwarding Header

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

Added: 


Modified: 
clang/lib/Basic/Targets/AArch64.cpp
clang/lib/Basic/Targets/AArch64.h
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/Driver/SanitizerArgs.cpp
clang/lib/Driver/ToolChains/Arch/AArch64.cpp
lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
llvm/lib/Target/AArch64/AArch64Subtarget.cpp
llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp

Removed: 
llvm/include/llvm/Support/AArch64TargetParser.h



diff  --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index b670a2578f843..00387ab173b39 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -17,7 +17,6 @@
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringSwitch.h"
-#include "llvm/Support/AArch64TargetParser.h"
 #include "llvm/Support/ARMTargetParserCommon.h"
 #include "llvm/TargetParser/AArch64TargetParser.h"
 #include 

diff  --git a/clang/lib/Basic/Targets/AArch64.h 
b/clang/lib/Basic/Targets/AArch64.h
index 34df886377eaa..7f88f3516780f 100644
--- a/clang/lib/Basic/Targets/AArch64.h
+++ b/clang/lib/Basic/Targets/AArch64.h
@@ -15,7 +15,7 @@
 
 #include "OSTargets.h"
 #include "clang/Basic/TargetBuiltins.h"
-#include "llvm/Support/AArch64TargetParser.h"
+#include "llvm/TargetParser/AArch64TargetParser.h"
 #include 
 
 namespace clang {

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index aefbc731f8738..01b980cfed793 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -52,10 +52,10 @@
 #include "llvm/IR/IntrinsicsX86.h"
 #include "llvm/IR/MDBuilder.h"
 #include "llvm/IR/MatrixBuilder.h"
-#include "llvm/Support/AArch64TargetParser.h"
 #include "llvm/Support/ConvertUTF.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/X86TargetParser.h"
+#include "llvm/TargetParser/AArch64TargetParser.h"
 #include 
 #include 
 

diff  --git a/clang/lib/Driver/SanitizerArgs.cpp 
b/clang/lib/Driver/SanitizerArgs.cpp
index 52bee6a755ff4..84be06b90ee62 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -14,11 +14,11 @@
 #include "clang/Driver/ToolChain.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringSwitch.h"
-#include "llvm/Support/AArch64TargetParser.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/SpecialCaseList.h"
 #include "llvm/Support/TargetParser.h"
 #include "llvm/Support/VirtualFileSystem.h"
+#include "llvm/TargetParser/AArch64TargetParser.h"
 #include "llvm/Transforms/Instrumentation/AddressSanitizerOptions.h"
 #include 
 

diff  --git a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp 
b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
index 4b641bbb73d41..9e17c06db106f 100644
--- a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
@@ -12,9 +12,9 @@
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/Options.h"
 #include "llvm/Option/ArgList.h"
-#include "llvm/Support/AArch64TargetParser.h"
-#include "llvm/Support/TargetParser.h"
 #include "llvm/Support/Host.h"
+#include "llvm/Support/TargetParser.h"
+#include "llvm/TargetParser/AArch64TargetParser.h"
 
 using namespace clang::driver;
 using namespace clang::driver::tools;

diff  --git a/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp 
b/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
index ed3b3e6da02ba..8a4fd08a9268b 100644
--- a/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
+++ b/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
@@ -23,10 +23,10 @@
 #include "llvm/MC/MCSubtargetInfo.h"
 #include "llvm/MC/MCTargetOptions.h"
 #include "llvm/MC/TargetRegistry.h"
-#include "llvm/Support/AArch64TargetParser.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/TargetSelect.h"
+#include "llvm/TargetParser/AArch64TargetParser.h"
 
 #include "lldb/Core/Address.h"
 #include "lldb/Core/Module.h"

diff  --git a/llvm/include/llvm/Support/AArch64TargetParser.h 
b/llvm/include/llvm/Support/AArch64TargetParser.h
deleted file mode 100644
index 54c4a2b786c96..0
--- a/llvm/i

[PATCH] D140999: [NFC][TargetParser] Remove llvm/Support/AArch64TargetParser.h

2023-02-03 Thread Sam Elliott via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8c712296fb75: [NFC][TargetParser] Remove 
llvm/Support/AArch64TargetParser.h (authored by lenary).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140999

Files:
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/AArch64.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Driver/SanitizerArgs.cpp
  clang/lib/Driver/ToolChains/Arch/AArch64.cpp
  lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
  llvm/include/llvm/Support/AArch64TargetParser.h
  llvm/lib/Target/AArch64/AArch64Subtarget.cpp
  llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp

Index: llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
===
--- llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
+++ llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
@@ -48,7 +48,6 @@
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Support/SMLoc.h"
-#include "llvm/Support/AArch64TargetParser.h"
 #include "llvm/Support/TargetParser.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/TargetParser/AArch64TargetParser.h"
Index: llvm/lib/Target/AArch64/AArch64Subtarget.cpp
===
--- llvm/lib/Target/AArch64/AArch64Subtarget.cpp
+++ llvm/lib/Target/AArch64/AArch64Subtarget.cpp
@@ -24,8 +24,8 @@
 #include "llvm/CodeGen/MachineFrameInfo.h"
 #include "llvm/CodeGen/MachineScheduler.h"
 #include "llvm/IR/GlobalValue.h"
-#include "llvm/Support/AArch64TargetParser.h"
 #include "llvm/Support/TargetParser.h"
+#include "llvm/TargetParser/AArch64TargetParser.h"
 
 using namespace llvm;
 
Index: llvm/include/llvm/Support/AArch64TargetParser.h
===
--- llvm/include/llvm/Support/AArch64TargetParser.h
+++ /dev/null
@@ -1,15 +0,0 @@
-//===-- llvm/Support/AArch64TargetParser.h --*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-///
-/// \file
-/// This header is deprecated in favour of
-/// `llvm/TargetParser/AArch64TargetParser.h`.
-///
-//===--===//
-
-#include "llvm/TargetParser/AArch64TargetParser.h"
Index: lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
===
--- lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
+++ lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
@@ -23,10 +23,10 @@
 #include "llvm/MC/MCSubtargetInfo.h"
 #include "llvm/MC/MCTargetOptions.h"
 #include "llvm/MC/TargetRegistry.h"
-#include "llvm/Support/AArch64TargetParser.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/TargetSelect.h"
+#include "llvm/TargetParser/AArch64TargetParser.h"
 
 #include "lldb/Core/Address.h"
 #include "lldb/Core/Module.h"
Index: clang/lib/Driver/ToolChains/Arch/AArch64.cpp
===
--- clang/lib/Driver/ToolChains/Arch/AArch64.cpp
+++ clang/lib/Driver/ToolChains/Arch/AArch64.cpp
@@ -12,9 +12,9 @@
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/Options.h"
 #include "llvm/Option/ArgList.h"
-#include "llvm/Support/AArch64TargetParser.h"
-#include "llvm/Support/TargetParser.h"
 #include "llvm/Support/Host.h"
+#include "llvm/Support/TargetParser.h"
+#include "llvm/TargetParser/AArch64TargetParser.h"
 
 using namespace clang::driver;
 using namespace clang::driver::tools;
Index: clang/lib/Driver/SanitizerArgs.cpp
===
--- clang/lib/Driver/SanitizerArgs.cpp
+++ clang/lib/Driver/SanitizerArgs.cpp
@@ -14,11 +14,11 @@
 #include "clang/Driver/ToolChain.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringSwitch.h"
-#include "llvm/Support/AArch64TargetParser.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/SpecialCaseList.h"
 #include "llvm/Support/TargetParser.h"
 #include "llvm/Support/VirtualFileSystem.h"
+#include "llvm/TargetParser/AArch64TargetParser.h"
 #include "llvm/Transforms/Instrumentation/AddressSanitizerOptions.h"
 #include 
 
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -52,10 +52,10 @@
 #include "llvm/IR/IntrinsicsX86.h"
 #include "llvm/IR/MDBuilder.h"
 #include "llvm/IR/MatrixBuilder.h"
-#include "llvm/Support/AArch64TargetParser.h"
 #include "

[PATCH] D138802: [clang][Interp] Implement DecompositionDecls

2023-02-03 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder marked 2 inline comments as done.
tbaeder added inline comments.



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:34-35
 
+  virtual ~DeclScope() override { this->emitDestruction(); }
+
   void addExtended(const Scope::Local &Local) override {

aaron.ballman wrote:
> aaron.ballman wrote:
> > The destructor for `LocalScope` already calls `emitDestruction()` which is 
> > a virtual function, so is this necessary?
> Still wondering about this
You're right, removed it again. Thanks.


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

https://reviews.llvm.org/D138802

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


[PATCH] D142673: [clang-tidy] Refactor HeaderGuardCheck to add HeaderGuardStyle

2023-02-03 Thread Kyle Edwards via Phabricator via cfe-commits
KyleFromKitware updated this revision to Diff 494675.
KyleFromKitware added a comment.

Added virtual destructor to `HeaderGuardStyle`.


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

https://reviews.llvm.org/D142673

Files:
  clang-tools-extra/clang-tidy/ClangTidyModule.h
  clang-tools-extra/clang-tidy/llvm/CMakeLists.txt
  clang-tools-extra/clang-tidy/llvm/HeaderGuardCheck.cpp
  clang-tools-extra/clang-tidy/llvm/HeaderGuardCheck.h
  clang-tools-extra/clang-tidy/llvm/HeaderGuardStyle.cpp
  clang-tools-extra/clang-tidy/llvm/HeaderGuardStyle.h
  clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp
  clang-tools-extra/clang-tidy/readability/CMakeLists.txt
  clang-tools-extra/clang-tidy/readability/HeaderGuardCheck.cpp
  clang-tools-extra/clang-tidy/readability/HeaderGuardCheck.h
  clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tools-extra/clang-tidy/utils/CMakeLists.txt
  clang-tools-extra/clang-tidy/utils/HeaderGuard.cpp
  clang-tools-extra/clang-tidy/utils/HeaderGuard.h
  clang-tools-extra/clang-tidy/utils/HeaderGuardStyle.cpp
  clang-tools-extra/clang-tidy/utils/HeaderGuardStyle.h
  clang-tools-extra/clang-tidy/utils/MacroHeaderGuardStyle.cpp
  clang-tools-extra/clang-tidy/utils/MacroHeaderGuardStyle.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/llvm/header-guard.rst
  clang-tools-extra/docs/clang-tidy/checks/readability/header-guard.rst
  clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp
@@ -3,6 +3,7 @@
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/HeaderGuardCheck.h"
+#include "llvm/HeaderGuardStyle.h"
 #include "llvm/IncludeOrderCheck.h"
 #include "gtest/gtest.h"
 #include 
@@ -49,10 +50,18 @@
 }
 
 namespace {
+struct WithEndifCommentStyle : public LLVMHeaderGuardStyle {
+  WithEndifCommentStyle(readability::HeaderGuardCheck *Check)
+  : LLVMHeaderGuardStyle(Check) {}
+  bool shouldSuggestEndifComment(StringRef Filename) override { return true; }
+};
+
 struct WithEndifComment : public LLVMHeaderGuardCheck {
   WithEndifComment(StringRef Name, ClangTidyContext *Context)
   : LLVMHeaderGuardCheck(Name, Context) {}
-  bool shouldSuggestEndifComment(StringRef Filename) override { return true; }
+  std::unique_ptr createHeaderGuardStyle() override {
+return std::make_unique(this);
+  }
 };
 
 static std::string
Index: clang-tools-extra/docs/clang-tidy/checks/readability/header-guard.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/readability/header-guard.rst
@@ -0,0 +1,26 @@
+.. title:: clang-tidy - readability-header-guard
+
+readability-header-guard
+
+
+Finds and fixes header guards that do not adhere to a specified style.
+
+Options
+---
+
+.. option:: HeaderFileExtensions
+
+   A comma-separated list of filename extensions of header files (the filename
+   extensions should not include "." prefix). Default is "h,hh,hpp,hxx".
+   For header files without an extension, use an empty string (if there are no
+   other desired extensions) or leave an empty element in the list. E.g.,
+   "h,hh,hpp,hxx," (note the trailing comma).
+
+.. option:: Style
+
+   The name of a header guard style to select. The default is "llvm". Available
+   options are:
+
+   ``llvm``
+
+ Use the LLVM header guard style.
Index: clang-tools-extra/docs/clang-tidy/checks/llvm/header-guard.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/llvm/header-guard.rst
+++ clang-tools-extra/docs/clang-tidy/checks/llvm/header-guard.rst
@@ -5,6 +5,10 @@
 
 Finds and fixes header guards that do not adhere to LLVM style.
 
+Note: this check is deprecated, it will be removed in :program:`clang-tidy`
+version 19. Please use the check `readability-header-guard`. with the ``llvm``
+style.
+
 Options
 ---
 
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -339,6 +339,7 @@
`readability-else-after-return `_, "Yes"
`readability-function-cognitive-complexity `_,
`readability-function-size `_,
+   `readability-header-guard `_,
`readability-identifier-length `_,
`readability-identifier-naming `_, "Yes"
`readability-implicit-bool-conversion `_, "Yes"
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools

[clang] 3de55e6 - Fix tests commited in 450a461

2023-02-03 Thread via cfe-commits

Author: ManuelJBrito
Date: 2023-02-03T17:52:23Z
New Revision: 3de55e6b0e7faf374510aa469aafbf3fba7c848e

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

LOG: Fix tests commited in 450a461

Remove alignment matching in tests to avoid ABI compatibility issues

Added: 


Modified: 
clang/test/CodeGen/builtins-nondeterministic-value.c

Removed: 




diff  --git a/clang/test/CodeGen/builtins-nondeterministic-value.c 
b/clang/test/CodeGen/builtins-nondeterministic-value.c
index 8727644624ced..5b22902de2e7d 100644
--- a/clang/test/CodeGen/builtins-nondeterministic-value.c
+++ b/clang/test/CodeGen/builtins-nondeterministic-value.c
@@ -42,19 +42,19 @@ _Bool clang_nondet_b( _Bool x) {
 
 void clang_nondet_fv( ) {
 // CHECK-LABEL: entry
-// CHECK: [[A:%.*]] = alloca <4 x float>, align 16
+// CHECK: [[A:%.*]] = alloca <4 x float>, align
 // CHECK: [[R:%.*]] = freeze <4 x float> poison
-// CHECK: store <4 x float> [[R]], ptr [[A]], align 16
+// CHECK: store <4 x float> [[R]], ptr [[A]], align
 // CHECK: ret void
   float4 x = __builtin_nondeterministic_value(x);
 }
 
 void clang_nondet_bv( ) {
-// CHECK: [[A:%.*]] = alloca i8, align 1
+// CHECK: [[A:%.*]] = alloca i8, align
 // CHECK: [[V:%.*]] = freeze <4 x i1> poison
 // CHECK: [[SV:%.*]] = shufflevector <4 x i1> [[V]], <4 x i1> poison, <8 x 
i32> 
 // CHECK: [[BC:%.*]] = bitcast <8 x i1> [[SV]] to i8
-// CHECK: store i8 [[BC]], ptr [[A]], align 1
+// CHECK: store i8 [[BC]], ptr [[A]], align
 // CHECK: ret void
   bool4 x = __builtin_nondeterministic_value(x);
 }



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


[PATCH] D142609: [Clang] Fix -Wconstant-logical-operand when LHS is a constant

2023-02-03 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 requested changes to this revision.
xbolva00 added a comment.
This revision now requires changes to proceed.

Huge code duplication.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142609

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


[PATCH] D143025: [Fuchsia] Add llvm-mt and llvm-rc to clang bootstrap dependency

2023-02-03 Thread Petr Hosek via Phabricator via cfe-commits
phosek added inline comments.



Comment at: clang/cmake/caches/Fuchsia.cmake:20-46
+# Passthrough stage1 flags to stage1.
+set(_FUCHSIA_BOOTSTRAP_PASSTHROUGH
+  LLVM_ENABLE_ZLIB
+  ZLIB_INCLUDE_DIR
+  ZLIB_LIBRARY
+  LLVM_ENABLE_ZSTD
+  zstd_DIR

Could we move this to a separate change since it's unrelated to the `llvm-rc` 
and `llvm-mt` change?



Comment at: clang/cmake/caches/Fuchsia.cmake:170-171
   runtimes
+  llvm-rc
+  llvm-mt
   CACHE STRING "")

Could we do this in 
https://github.com/llvm/llvm-project/blob/98f0e4f611b40c902cb0df3ef080ae2c00e862d4/clang/CMakeLists.txt#L619?
 That would be more consistent with other tools such as `llvm-ar`.


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

https://reviews.llvm.org/D143025

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


[PATCH] D141738: Add initial support for cross compile Windows runtimes under Linux when building Fuchsia clang toolchain

2023-02-03 Thread Petr Hosek via Phabricator via cfe-commits
phosek accepted this revision.
phosek added a comment.

LGTM




Comment at: clang/cmake/caches/Fuchsia-stage2.cmake:95
+# and remove these libpath flags.
+-libpath:"${LLVM_WINSYSROOT}/VC/Tools/MSVC/14.34.31933/lib/x64"
+-libpath:"${LLVM_WINSYSROOT}/VC/Tools/MSVC/14.34.31933/atlmfc/lib/x64"

haowei wrote:
> phosek wrote:
> > phosek wrote:
> > > haowei wrote:
> > > > thakis wrote:
> > > > > You can tell cmake to invoke lld-link, which has a /winsysroot: flag.
> > > > What would be a good way to make CMake invoke lld-link (or through 
> > > > clang-cl) instead of using `cmake vs_link` in this situation?
> > > > We thought about using
> > > > 
> > > > ```
> > > > set(CMAKE_${LANG}_SIMULATE_ID "MSVC")
> > > > set(CMAKE_${LANG}_COMPILER_FRONTEND_VARIANT "GNU")
> > > > ```
> > > > 
> > > > but I don't feel great about changing variables that are not suppose to 
> > > > change. 
> > > Wouldn't CMake use `lld-link` if you set `CMAKE_LINKER=lld-link`. We 
> > > already do this in 
> > > https://github.com/llvm/llvm-project/blob/0e09bb8b143c80426c497a924ee4fa57a26af6b5/llvm/cmake/modules/LLVMExternalProjectUtils.cmake#L179
> > >  which is used by the bootstrapping build so you should be able to use 
> > > `/winsysroot:` here.
> > @haowei have tried this suggestion?
> I tried:
> 
> ```
> FAILED: 
> runtimes/runtimes-x86_64-pc-windows-msvc-stamps/runtimes-x86_64-pc-windows-msvc-configure
>  
> /mnt/nvme_sec/SRC/llvm-project/build-lldlink/runtimes/runtimes-x86_64-pc-windows-msvc-stamps/runtimes-x86_64-pc-windows-msvc-configure
>  
> cd 
> /mnt/nvme_sec/SRC/llvm-project/build-lldlink/runtimes/runtimes-x86_64-pc-windows-msvc-bins
>  && /mnt/nvme_sec/SRC/llvm-prebuilts/cmake/linux-amd64/bin/cmake \
> -DCMAKE_C_COMPILER=/mnt/nvme_sec/SRC/llvm-project/build-lldlink/./bin/clang-cl
>  \
> -DCMAKE_CXX_COMPILER=/mnt/nvme_sec/SRC/llvm-project/build-lldlink/./bin/clang-cl
>  \
> -DCMAKE_ASM_COMPILER=/mnt/nvme_sec/SRC/llvm-project/build-lldlink/./bin/clang-cl
>  \
> -DCMAKE_LINKER=/mnt/nvme_sec/SRC/llvm-project/build-lldlink/./bin/lld-link \
> 
> 
> ```
> 
> But cmake is still using vs_link, see:
> 
> ```
> FAILED: cmTC_a05d1.exe 
> : && /mnt/nvme_sec/SRC/llvm-prebuilts/cmake/linux-amd64/bin/cmake -E 
> vs_link_exe --intdir=CMakeFiles/cmTC_a05d1.dir 
> --rc=/mnt/nvme_sec/SRC/llvm-project/build-lldlink/./bin/llvm-rc 
> --mt=/mnt/nvme_sec/SRC/llvm-project/build-lldlink/bin/llvm-mt --manifests  -- 
> /mnt/nvme_sec/SRC/llvm-project/build-lldlink/bin/lld-link /nologo 
> CMakeFiles/cmTC_a05d1.dir/CMakeCCompilerABI.c.obj  /out:cmTC_a05d1.exe 
> /implib:cmTC_a05d1.lib /pdb:cmTC_a05d1.pdb /version:0.0 
> /vfsoverlay:/mnt/nvme_sec/SRC/WinSDK/winsdk-cipd/llvm-vfsoverlay.yaml  /debug 
> /INCREMENTAL /subsystem:console
> ```
Thanks for checking, we should investigate this further and perhaps reach out 
to CMake maintainers but that can be done separately.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141738

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


[PATCH] D143287: [Clang][x86] Change x86 cast intrinsics to use __builtin_nondeterministic_value

2023-02-03 Thread Manuel Brito via Phabricator via cfe-commits
ManuelJBrito created this revision.
ManuelJBrito added reviewers: craig.topper, RKSimon.
Herald added subscribers: pengfei, mgrang.
Herald added a project: All.
ManuelJBrito requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The following intrinsics are currently implemented using a shufflevector with 
an undefined mask, this is however incorrect according to intel's semantics for 
undefined value which expect an unknown but consistent value.

With `__builtin_nondeterministic_value` we can now match intel's undefined 
value.

Related patch for more context : https://reviews.llvm.org/D103874


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143287

Files:
  clang/lib/Headers/avx512fintrin.h
  clang/lib/Headers/avx512fp16intrin.h
  clang/lib/Headers/avxintrin.h
  clang/test/CodeGen/X86/avx-builtins.c
  clang/test/CodeGen/X86/avx512f-builtins.c
  clang/test/CodeGen/X86/avx512fp16-builtins.c

Index: clang/test/CodeGen/X86/avx512fp16-builtins.c
===
--- clang/test/CodeGen/X86/avx512fp16-builtins.c
+++ clang/test/CodeGen/X86/avx512fp16-builtins.c
@@ -326,19 +326,19 @@
 
 __m256h test_mm256_castph128_ph256(__m128h __a) {
   // CHECK-LABEL: test_mm256_castph128_ph256
-  // CHECK: shufflevector <8 x half> %{{.*}}, <8 x half> %{{.*}}, <16 x i32> 
+  // CHECK: shufflevector <8 x half> %{{.*}}, <8 x half> %{{.*}}, <16 x i32> 
   return _mm256_castph128_ph256(__a);
 }
 
 __m512h test_mm512_castph128_ph512(__m128h __a) {
   // CHECK-LABEL: test_mm512_castph128_ph512
-  // CHECK: shufflevector <8 x half> %{{.*}}, <8 x half> %{{.*}}, <32 x i32> 
+  // CHECK: shufflevector <8 x half> %{{.*}}, <8 x half> %{{.*}}, <32 x i32> 
   return _mm512_castph128_ph512(__a);
 }
 
 __m512h test_mm512_castph256_ph512(__m256h __a) {
   // CHECK-LABEL: test_mm512_castph256_ph512
-  // CHECK: shufflevector <16 x half> %{{.*}}, <16 x half> %{{.*}}, <32 x i32> 
+  // CHECK: shufflevector <16 x half> %{{.*}}, <16 x half> %{{.*}}, <32 x i32> 
   return _mm512_castph256_ph512(__a);
 }
 
Index: clang/test/CodeGen/X86/avx512f-builtins.c
===
--- clang/test/CodeGen/X86/avx512f-builtins.c
+++ clang/test/CodeGen/X86/avx512f-builtins.c
@@ -8987,13 +8987,13 @@
 
 __m512 test_mm512_castps128_ps512(__m128 __A) {
   // CHECK-LABEL: @test_mm512_castps128_ps512
-  // CHECK: shufflevector <4 x float> %{{.*}}, <4 x float> %{{.*}}, <16 x i32> 
+  // CHECK: shufflevector <4 x float> %{{.*}}, <4 x float> %{{.*}}, <16 x i32> 
   return _mm512_castps128_ps512(__A); 
 }
 
 __m512d test_mm512_castpd128_pd512(__m128d __A) {
   // CHECK-LABEL: @test_mm512_castpd128_pd512
-  // CHECK: shufflevector <2 x double> %{{.*}}, <2 x double> %{{.*}}, <8 x i32> 
+  // CHECK: shufflevector <2 x double> %{{.*}}, <2 x double> %{{.*}}, <8 x i32> 
   return _mm512_castpd128_pd512(__A); 
 }
 
@@ -9086,7 +9086,7 @@
 __m512d test_mm512_castpd256_pd512(__m256d a)
 {
   // CHECK-LABEL: @test_mm512_castpd256_pd512
-  // CHECK: shufflevector <4 x double> {{.*}} 
+  // CHECK: shufflevector <4 x double> {{.*}} 
   return _mm512_castpd256_pd512(a);
 }
 
@@ -9112,13 +9112,13 @@
 }
 __m512i test_mm512_castsi128_si512(__m128i __A) {
   // CHECK-LABEL: @test_mm512_castsi128_si512
-  // CHECK: shufflevector <2 x i64> %{{.*}}, <2 x i64> %{{.*}}, <8 x i32> 
+  // CHECK: shufflevector <2 x i64> %{{.*}}, <2 x i64> %{{.*}}, <8 x i32> 
   return _mm512_castsi128_si512(__A); 
 }
 
 __m512i test_mm512_castsi256_si512(__m256i __A) {
   // CHECK-LABEL: @test_mm512_castsi256_si512
-  // CHECK: shufflevector <4 x i64> %{{.*}}, <4 x i64> %{{.*}}, <8 x i32> 
+  // CHECK: shufflevector <4 x i64> %{{.*}}, <4 x i64> %{{.*}}, <8 x i32> 
   return _mm512_castsi256_si512(__A); 
 }
 
Index: clang/test/CodeGen/X86/avx-builtins.c
===
--- clang/test/CodeGen/X86/avx-builtins.c
+++ clang/test/CodeGen/X86/avx-builtins.c
@@ -143,7 +143,7 @@
 
 __m256d test_mm256_castpd128_pd256(__m128d A) {
   // CHECK-LABEL: test_mm256_castpd128_pd256
-  // CHECK: shufflevector <2 x double> %{{.*}}, <2 x double> %{{.*}}, <4 x i32> 
+  // CHECK: shufflevector <2 x double> %{{.*}}, <2 x double> %{{.*}}, <4 x i32> 
   return _mm256_castpd128_pd256(A);
 }
 
@@ -165,7 +165,7 @@
 
 __m256 test_mm256_castps128_ps256(__m128 A) {
   // CHECK-LABEL: test_mm256_castps128_ps256
-  // CHECK: shufflevector <4 x float> %{{.*}}, <4 x float> %{{.*}}, <8 x i32> 
+  // CHECK: shufflevector <4 x float> %{{.*}}, <4 x float> %{{.*}}, <8 x i32> 
   return _mm256_castps128_ps256(A);
 }
 
@@ -177,7 +177,7 @@
 
 __m256i test_mm256_castsi128_si256(__m128i A) {
   // CHECK-LABEL: test_mm256_castsi128_si256
-  // CHECK: shufflevector <2 x i64> %{{.*}}, <2 x i64> %{{.*}}, <4 x i32> 
+  // CHECK: shufflevector <2 x i64> %{{.*}}, <2 x i64> %{{.*}}, <4 x i32> 
   return _mm256_castsi128_si256(A);
 }
 
Index: clang/l

[PATCH] D139737: [-Wunsafe-buffer-usage] Initiate Fix-it generation for local variable declarations

2023-02-03 Thread Ziqing Luo via Phabricator via cfe-commits
ziqingluo-90 updated this revision to Diff 494689.
ziqingluo-90 added a comment.

address comments


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

https://reviews.llvm.org/D139737

Files:
  clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
  clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Analysis/UnsafeBufferUsage.cpp
  clang/lib/Sema/AnalysisBasedWarnings.cpp
  clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-local-var-span.cpp
  clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp

Index: clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp
===
--- clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp
+++ clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp
@@ -80,20 +80,24 @@
 
 void testArraySubscriptsWithAuto(int *p, int **pp) {
   int a[10];
-  auto ap1 = a;   // expected-warning{{'ap1' is an unsafe pointer used for buffer access}}
+  auto ap1 = a;   // expected-warning{{'ap1' is an unsafe pointer used for buffer access}} \
+		 expected-note{{change type of 'ap1' to 'std::span' to preserve bounds information}}
 
-  foo(ap1[1]);// expected-note{{used in buffer access here}}
+  foo(ap1[1]);// expected-note{{used in buffer access here}} 
 
-  auto ap2 = p;   // expected-warning{{'ap2' is an unsafe pointer used for buffer access}}
+  auto ap2 = p;   // expected-warning{{'ap2' is an unsafe pointer used for buffer access}} \
+  		 expected-note{{change type of 'ap2' to 'std::span' to preserve bounds information}}
 
   foo(ap2[1]);// expected-note{{used in buffer access here}}
 
-  auto ap3 = pp;  // expected-warning{{'ap3' is an unsafe pointer used for buffer access}}
+  auto ap3 = pp;  // expected-warning{{'ap3' is an unsafe pointer used for buffer access}} \
+		 expected-note{{change type of 'ap3' to 'std::span' to preserve bounds information}}
 
   foo(ap3[1][1]); // expected-note{{used in buffer access here}}
   // expected-warning@-1{{unsafe buffer access}}
 
-  auto ap4 = *pp; // expected-warning{{'ap4' is an unsafe pointer used for buffer access}}
+  auto ap4 = *pp; // expected-warning{{'ap4' is an unsafe pointer used for buffer access}} \
+  		 expected-note{{change type of 'ap4' to 'std::span' to preserve bounds information}}
 
   foo(ap4[1]);// expected-note{{used in buffer access here}}
 }
@@ -355,7 +359,8 @@
   auto
 
 
-  ap1 = p;  // expected-warning{{'ap1' is an unsafe pointer used for buffer access}}
+  ap1 = p;  // expected-warning{{'ap1' is an unsafe pointer used for buffer access}} \
+ 	   expected-note{{change type of 'ap1' to 'std::span' to preserve bounds information}}
 
   foo(ap1[1]);  // expected-note{{used in buffer access here}}
 }
Index: clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-local-var-span.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-local-var-span.cpp
@@ -0,0 +1,175 @@
+// RUN: %clang_cc1 -std=c++20 -Wunsafe-buffer-usage -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
+typedef int * Int_ptr_t;
+typedef int Int_t;
+
+void local_array_subscript_simple() {
+  int tmp;
+  int *p = new int[10];
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:11}:"std::span p"
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-2]]:12-[[@LINE-2]]:12}:"{"
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-3]]:23-[[@LINE-3]]:23}:", 10}"
+  const int *q = new int[10];
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:17}:"std::span q"
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-2]]:18-[[@LINE-2]]:18}:"{"
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-3]]:29-[[@LINE-3]]:29}:", 10}"
+  tmp = p[5];
+  tmp = q[5];
+
+  Int_ptr_t x = new int[10];
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:16}:"std::span x"
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-2]]:17-[[@LINE-2]]:17}:"{"
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-3]]:28-[[@LINE-3]]:28}:", 10}"
+  Int_ptr_t y = new int;
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:16}:"std::span y"
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-2]]:17-[[@LINE-2]]:17}:"{"
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-3]]:24-[[@LINE-3]]:24}:", 1}"
+  Int_t * z = new int[10];
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:14}:"std::span z"
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-2]]:15-[[@LINE-2]]:15}:"{"
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-3]]:26-[[@LINE-3]]:26}:", 10}"
+  Int_t * w = new Int_t[10];
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:14}:"std::span w"
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-2]]:15-[[@LINE-2]]:15}:"{"
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-3]]:28-[[@LINE-3]]:28}:", 10}"
+
+  tmp = x[5];
+  tmp = y[5]; // y[5] will crash after being span
+  tmp = z[5];
+  tmp = w[5];
+}
+
+void local_array_subscript_auto() {
+  int tmp;
+  auto p = new int[10];
+  // CHECK-DAG: f

[PATCH] D142867: [Clang] Add machinery to catch overflow in unary minus outside of a constant expression context

2023-02-03 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

Amusingly this fired on some code that used negation with the intention of 
getting fewer warnings: 
https://github.com/KhronosGroup/glslang/commit/866f67140ed98865350b53312bba1b654b59f937
 :-)
Fixed in 
https://github.com/KhronosGroup/glslang/commit/7341a21b345e7aea1d2791db0f2d36866c434c03


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142867

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


[PATCH] D140179: [-Wunsafe-buffer-usage] Add unsafe buffer checking opt-out pragmas

2023-02-03 Thread Ziqing Luo via Phabricator via cfe-commits
ziqingluo-90 updated this revision to Diff 494693.
ziqingluo-90 added a comment.

Change the fix-it test style


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

https://reviews.llvm.org/D140179

Files:
  clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
  clang/include/clang/Basic/DiagnosticLexKinds.td
  clang/include/clang/Lex/Preprocessor.h
  clang/lib/Analysis/UnsafeBufferUsage.cpp
  clang/lib/Lex/PPLexerChange.cpp
  clang/lib/Lex/Pragma.cpp
  clang/lib/Lex/Preprocessor.cpp
  clang/lib/Sema/AnalysisBasedWarnings.cpp
  clang/test/SemaCXX/warn-unsafe-buffer-usage-pragma-fixit.cpp
  clang/test/SemaCXX/warn-unsafe-buffer-usage-pragma-misuse.cpp
  clang/test/SemaCXX/warn-unsafe-buffer-usage-pragma.cpp
  clang/test/SemaCXX/warn-unsafe-buffer-usage-pragma.h

Index: clang/test/SemaCXX/warn-unsafe-buffer-usage-pragma.h
===
--- /dev/null
+++ clang/test/SemaCXX/warn-unsafe-buffer-usage-pragma.h
@@ -0,0 +1,14 @@
+#ifdef _INCLUDE_NO_WARN
+// the snippet will be included in an opt-out region
+p1++;
+
+#undef _INCLUDE_NO_WARN
+
+#elif defined(_INCLUDE_WARN)
+// the snippet will be included in a location where warnings are expected
+p2++; // expected-note{{used in pointer arithmetic here}}
+#undef _INCLUDE_WARN
+
+#else
+
+#endif
Index: clang/test/SemaCXX/warn-unsafe-buffer-usage-pragma.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/warn-unsafe-buffer-usage-pragma.cpp
@@ -0,0 +1,100 @@
+// RUN: %clang_cc1 -std=c++20 -Wunsafe-buffer-usage -Wno-unused-value -verify %s
+
+void basic(int * x) {// expected-warning{{'x' is an unsafe pointer used for buffer access}}
+  int *p1 = new int[10]; // not to warn
+  int *p2 = new int[10]; // expected-warning{{'p2' is an unsafe pointer used for buffer access}}
+
+#pragma clang unsafe_buffer_usage begin
+  p1[5];  // not to warn
+
+#define _INCLUDE_NO_WARN
+#include "warn-unsafe-buffer-usage-pragma.h" // increment p1 in header
+
+  int *p3 = new int[10]; // expected-warning{{'p3' is an unsafe pointer used for buffer access}}
+
+#pragma clang unsafe_buffer_usage end
+  p2[5]; //expected-note{{used in buffer access here}}
+  p3[5]; //expected-note{{used in buffer access here}}
+  x++;   //expected-note{{used in pointer arithmetic here}}
+#define _INCLUDE_WARN
+#include "warn-unsafe-buffer-usage-pragma.h" // increment p2 in header
+}
+
+
+void withDiagnosticWarning() {
+  int *p1 = new int[10]; // not to warn
+  int *p2 = new int[10]; // expected-warning{{'p2' is an unsafe pointer used for buffer access}}
+
+  // diagnostics in opt-out region
+#pragma clang unsafe_buffer_usage begin
+  p1[5];  // not to warn
+  p2[5];  // not to warn
+#pragma clang diagnostic push
+#pragma clang diagnostic warning "-Wunsafe-buffer-usage"
+  p1[5];  // not to warn
+  p2[5];  // not to warn
+#pragma clang diagnostic warning "-Weverything"
+  p1[5];  // not to warn expected-warning{{expression result unused}}
+  p2[5];  // not to warn expected-warning{{expression result unused}}
+#pragma clang diagnostic pop
+#pragma clang unsafe_buffer_usage end
+
+  // opt-out region under diagnostic warning
+#pragma clang diagnostic push
+#pragma clang diagnostic warning "-Wunsafe-buffer-usage"
+#pragma clang unsafe_buffer_usage begin
+  p1[5];  // not to warn
+  p2[5];  // not to warn
+#pragma clang unsafe_buffer_usage end
+#pragma clang diagnostic pop
+
+  p2[5]; // expected-note{{used in buffer access here}}
+}
+
+
+void withDiagnosticIgnore() {
+  int *p1 = new int[10]; // not to warn
+  int *p2 = new int[10]; // expected-warning{{'p2' is an unsafe pointer used for buffer access}}
+  int *p3 = new int[10]; // expected-warning{{'p3' is an unsafe pointer used for buffer access}}
+
+#pragma clang unsafe_buffer_usage begin
+  p1[5];  // not to warn
+  p2[5];  // not to warn
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
+  p1[5];  // not to warn
+  p2[5];  // not to warn
+#pragma clang diagnostic ignored "-Weverything"
+  p1[5];  // not to warn
+  p2[5];  // not to warn
+#pragma clang diagnostic pop
+#pragma clang unsafe_buffer_usage end
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
+#pragma clang unsafe_buffer_usage begin
+  p1[5];  // not to warn
+  p2[5];  // not to warn
+#pragma clang unsafe_buffer_usage end
+#pragma clang diagnostic pop
+
+  p2[5]; // expected-note{{used in buffer access here}}
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
+#pragma clang unsafe_buffer_usage begin
+  p1[5];  // not to warn
+  p2[5];  // not to warn
+#pragma clang unsafe_buffer_usage end
+  p3[5];  // expected-note{{used in buffer access here}}
+#pragma clang diagnostic pop
+}
+
+void noteGoesWithVarDeclWarning() {
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
+  int *p = new int[10]; // not to warn
+#pragma 

[PATCH] D143288: [Fuchsia] Simplified the stage2 build setup

2023-02-03 Thread Haowei Wu via Phabricator via cfe-commits
haowei created this revision.
haowei added a reviewer: phosek.
Herald added a subscriber: abrachet.
Herald added a project: All.
haowei requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch simplified the BOOTSTRAP_ flags, allowing them to be passed through 
from regular flags.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143288

Files:
  clang/cmake/caches/Fuchsia.cmake


Index: clang/cmake/caches/Fuchsia.cmake
===
--- clang/cmake/caches/Fuchsia.cmake
+++ clang/cmake/caches/Fuchsia.cmake
@@ -17,6 +17,34 @@
 set(LLVM_INCLUDE_DOCS OFF CACHE BOOL "")
 set(LLVM_INCLUDE_EXAMPLES OFF CACHE BOOL "")
 
+# Passthrough stage1 flags to stage1.
+set(_FUCHSIA_BOOTSTRAP_PASSTHROUGH
+  LLVM_ENABLE_ZLIB
+  ZLIB_INCLUDE_DIR
+  ZLIB_LIBRARY
+  LLVM_ENABLE_ZSTD
+  zstd_DIR
+  LLVM_ENABLE_LIBXML2
+  LibXml2_ROOT
+  LLVM_ENABLE_CURL
+  CURL_ROOT
+  OpenSSL_ROOT
+  CMAKE_FIND_PACKAGE_PREFER_CONFIG
+  CMAKE_SYSROOT
+  CMAKE_MODULE_LINKER_FLAGS
+  CMAKE_SHARED_LINKER_FLAGS
+  CMAKE_EXE_LINKER_FLAGS
+)
+
+foreach(variable ${_FUCHSIA_BOOTSTRAP_PASSTHROUGH})
+  get_property(is_value_set CACHE ${variable} PROPERTY VALUE SET)
+  if(${is_value_set})
+get_property(value CACHE ${variable} PROPERTY VALUE)
+get_property(type CACHE ${variable} PROPERTY TYPE)
+set(BOOTSTRAP_${variable} "${value}" CACHE ${type} "")
+  endif()
+endforeach()
+
 if(WIN32)
   set(LLVM_USE_CRT_RELEASE "MT" CACHE STRING "")
 endif()


Index: clang/cmake/caches/Fuchsia.cmake
===
--- clang/cmake/caches/Fuchsia.cmake
+++ clang/cmake/caches/Fuchsia.cmake
@@ -17,6 +17,34 @@
 set(LLVM_INCLUDE_DOCS OFF CACHE BOOL "")
 set(LLVM_INCLUDE_EXAMPLES OFF CACHE BOOL "")
 
+# Passthrough stage1 flags to stage1.
+set(_FUCHSIA_BOOTSTRAP_PASSTHROUGH
+  LLVM_ENABLE_ZLIB
+  ZLIB_INCLUDE_DIR
+  ZLIB_LIBRARY
+  LLVM_ENABLE_ZSTD
+  zstd_DIR
+  LLVM_ENABLE_LIBXML2
+  LibXml2_ROOT
+  LLVM_ENABLE_CURL
+  CURL_ROOT
+  OpenSSL_ROOT
+  CMAKE_FIND_PACKAGE_PREFER_CONFIG
+  CMAKE_SYSROOT
+  CMAKE_MODULE_LINKER_FLAGS
+  CMAKE_SHARED_LINKER_FLAGS
+  CMAKE_EXE_LINKER_FLAGS
+)
+
+foreach(variable ${_FUCHSIA_BOOTSTRAP_PASSTHROUGH})
+  get_property(is_value_set CACHE ${variable} PROPERTY VALUE SET)
+  if(${is_value_set})
+get_property(value CACHE ${variable} PROPERTY VALUE)
+get_property(type CACHE ${variable} PROPERTY TYPE)
+set(BOOTSTRAP_${variable} "${value}" CACHE ${type} "")
+  endif()
+endforeach()
+
 if(WIN32)
   set(LLVM_USE_CRT_RELEASE "MT" CACHE STRING "")
 endif()
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D143091: [clang-format] PackConstructorInitializers support PCIS_OnlyNextLine

2023-02-03 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added a comment.

In D143091#4099585 , @Backl1ght wrote:

> In D143091#4097534 , 
> @HazardyKnusperkeks wrote:
>
>> An entry in the changelog would be nice.
>
> It is already added I think.

I don't see anything. And how could it, if you add that value?


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

https://reviews.llvm.org/D143091

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


[PATCH] D142891: [clang-format] Recognize Verilog non-blocking assignment

2023-02-03 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks accepted this revision.
HazardyKnusperkeks added a comment.
This revision is now accepted and ready to land.

Looks ok to me. Please wait for some other opinion.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142891

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


[PATCH] D142499: [Clang][AMDGPU] Set LTO CG opt level based on Clang option

2023-02-03 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added a comment.
This revision is now accepted and ready to land.

Fine with me, but you may need an AMDGPU reviewer.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142499

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


[PATCH] D142499: [Clang][AMDGPU] Set LTO CG opt level based on Clang option

2023-02-03 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl accepted this revision.
yaxunl added a comment.

LGTM. Thanks


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142499

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


[PATCH] D142384: [C++20] Fix a crash with modules.

2023-02-03 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

In D142384#4102937 , @hans wrote:

> I don't know if that's expected or not, but maybe that behavior change could 
> be used as an inspiration for a test case.

At least this suggests a way to test this with a C++ unit test: get a 
`RecordDecl*` referring to a forward declaration of a struct with a definition, 
and iterate over its fields.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142384

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


[PATCH] D142948: [OpenCL] Disable vector to scalar types coercion for OpenCL

2023-02-03 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

It doesn't seem to make sense to have a `LangOpt` for this, if anything a new 
`CodeGenOpt` feels like a better fit. Then you should probably extend existing 
classify functions to prevent coercion instead of adding yet another function 
otherwise you will need to handle all the different corner cases again as there 
seem to be quite many if I look at `X86_32ABIInfo::classifyReturnType`...

FYI OpenCL vectors are implemented as generic vector extension so this probably 
shouldn't be bind to OpenCL at all:
https://clang.llvm.org/docs/LanguageExtensions.html#vectors-and-extended-vectors?

Perhaps it can be a general feature to prevent coercion? But then other targets 
have similar logic too... should it then be more generalized?

> Such behavior is completely valid for x86, but the backend vectorizer
> cannot work with scalars instead of vectors.
>
> With this patch, argument and result types will be leaved unchanged in
> the CodeGen.
>
> New option fopencl-force-vector-abi is also added to force-disables
> vector to scalar coercion when provided.

Do you have any public examples to look at? The coercion is part of the ABI so 
it should ideally be respected by other tools.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142948

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


[PATCH] D142077: [Clang][SemaCXX][Coroutines] Fix misleading diagnostics with -Wunsequenced

2023-02-03 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno updated this revision to Diff 494707.
bruno added a comment.

Update patch to reuse `std-coroutine.h` and add a few more other bits there.


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

https://reviews.llvm.org/D142077

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/SemaCXX/Inputs/std-coroutine.h
  clang/test/SemaCXX/warn-unsequenced-coro.cpp

Index: clang/test/SemaCXX/warn-unsequenced-coro.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/warn-unsequenced-coro.cpp
@@ -0,0 +1,105 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only -verify -std=c++20 -I%S/Inputs -Wno-unused -Wno-uninitialized -Wunsequenced %s
+
+// expected-no-diagnostics
+
+#include "std-coroutine.h"
+
+typedef __PTRDIFF_TYPE__ ptrdiff_t;
+
+using namespace std;
+
+template
+struct Task {
+struct promise_type {
+Task get_return_object() noexcept;
+suspend_always initial_suspend() noexcept;
+suspend_always final_suspend() noexcept;
+void return_value(T);
+void unhandled_exception();
+auto yield_value(Task) noexcept { return final_suspend(); }
+};
+bool await_ready() noexcept { return false; }
+void await_suspend(coroutine_handle<>) noexcept {}
+T await_resume();
+};
+
+template<>
+struct Task {
+struct promise_type {
+Task get_return_object() noexcept;
+suspend_always initial_suspend() noexcept;
+suspend_always final_suspend() noexcept;
+void return_void() noexcept;
+void unhandled_exception() noexcept;
+auto yield_value(Task) noexcept { return final_suspend(); }
+};
+bool await_ready() noexcept { return false; }
+void await_suspend(coroutine_handle<>) noexcept {}
+void await_resume() noexcept {}
+};
+
+template 
+class generator
+{
+  struct Promise
+  {
+auto get_return_object() { return generator{*this}; }
+auto initial_suspend() { return suspend_never{}; }
+auto final_suspend() noexcept { return suspend_always{}; }
+void unhandled_exception() {}
+void return_void() {}
+
+auto yield_value(T value)
+{
+  value_ = std::move(value);
+  return suspend_always{};
+}
+
+T value_;
+  };
+
+  using Handle = coroutine_handle;
+
+  struct sentinel{};
+  struct iterator
+  {
+using iterator_category = input_iterator_tag;
+using value_type = T;
+using difference_type = ptrdiff_t;
+using reference = T &;
+using const_reference = const T &;
+using pointer = T *;
+
+iterator &operator++()
+{
+  h_.resume();
+  return *this;
+}
+const_reference &operator*() const { return h_.promise().value_; }
+bool operator!=(sentinel) { return !h_.done(); }
+
+Handle h_;
+  };
+
+  explicit generator(Promise &p) : h_(Handle::from_promise(p)) {}
+  Handle h_;
+public:
+  using promise_type = Promise;
+  auto begin() { return iterator{h_}; }
+  auto end() { return sentinel{}; }
+};
+
+Task c(int i) {
+  co_await (i = 0, std::suspend_always{});
+}
+
+generator range(int start, int end)
+{
+  while (start < end)
+co_yield start++;
+}
+
+Task go(int const& val);
+Task go1(int x) {
+  co_return co_await go(++x);
+}
\ No newline at end of file
Index: clang/test/SemaCXX/Inputs/std-coroutine.h
===
--- clang/test/SemaCXX/Inputs/std-coroutine.h
+++ clang/test/SemaCXX/Inputs/std-coroutine.h
@@ -4,12 +4,23 @@
 
 namespace std {
 
+template struct remove_reference   { typedef T type; };
+template struct remove_reference  { typedef T type; };
+template struct remove_reference { typedef T type; };
+
+template
+typename remove_reference::type &&move(T &&t) noexcept;
+
+struct input_iterator_tag {};
+struct forward_iterator_tag : public input_iterator_tag {};
+
 template 
 struct coroutine_traits { using promise_type = typename Ret::promise_type; };
 
 template 
 struct coroutine_handle {
   static coroutine_handle from_address(void *) noexcept;
+  static coroutine_handle from_promise(Promise &promise);
   constexpr void* address() const noexcept;
 };
 template <>
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -15241,6 +15241,23 @@
 Base::VisitStmt(E);
   }
 
+  void VisitCoroutineSuspendExpr(const CoroutineSuspendExpr *CSE) {
+for (auto *Sub : CSE->children()) {
+  const Expr *ChildExpr = dyn_cast_or_null(Sub);
+  if (!ChildExpr)
+continue;
+
+  if (ChildExpr == CSE->getOperand())
+// Do not recurse over a CoroutineSuspendExpr's operand.
+// The operand is also a subexpression of getCommonExpr(), and
+// recursing into it directly could confuse object management
+// for the sake of sequence tracking.
+continue;
+
+  Visit(Sub);
+}
+  }
+
   void VisitCastExpr(const 

  1   2   >