[PATCH] D135750: [clang][Interp] Track initialization state of local variables

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



Comment at: clang/lib/AST/Interp/InterpBlock.h:97
   void invokeCtor() {
-std::memset(data(), 0, getSize());
+std::memset(rawData(), 0, Desc->getAllocSize());
 if (Desc->CtorFn)

aaron.ballman wrote:
> tbaeder wrote:
> > aaron.ballman wrote:
> > > Why do we want to overwrite the metadata here?
> > This is only called after creating an new block, so nothing is being 
> > overwritten, the metadata hasn't been filled-in yet.
> Sounds like a good reason not to memset over that block then; it's useless 
> work that will be thrown away anyway (I worry we may come to rely on this 
> zero init accidentally)?
FWIW I looked into this and I think zeroing everything is what we want, so the 
initmap is null initially 


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

https://reviews.llvm.org/D135750

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


[PATCH] D137995: [Flang][Driver] Handle target CPU and features

2022-12-02 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski accepted this revision.
awarzynski added a comment.
This revision is now accepted and ready to land.

LGTM, thank you!


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

https://reviews.llvm.org/D137995

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


[PATCH] D139170: [X86][clang] Lift _BitInt() supported max width.

2022-12-02 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe added a comment.

In D139170#3965814 , @mgehre-amd 
wrote:

> Do other targets not support > 128 bit integers, or is this PR only the first 
> conservative step of lifting the limit?

I temporary only enabled > 128 bit FP conversion for X86 in 
https://reviews.llvm.org/D137241, since I highly relied on end-to-end tests to 
implement that pass and I don't have other targets' environment to verify. So 
same to this patch, I only lift the limit for X86. Hope other targets will 
follow us to enable for themselves. WDYT?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139170

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


[PATCH] D139170: [X86][clang] Lift _BitInt() supported max width.

2022-12-02 Thread Matthias Gehre via Phabricator via cfe-commits
mgehre-amd added a comment.

In D139170#3965850 , @FreddyYe wrote:

> In D139170#3965814 , @mgehre-amd 
> wrote:
>
>> Do other targets not support > 128 bit integers, or is this PR only the 
>> first conservative step of lifting the limit?
>
> I temporary only enabled > 128 bit FP conversion for X86 in 
> https://reviews.llvm.org/D137241, since I highly relied on end-to-end tests 
> to implement that pass and I don't have other targets' environment to verify. 
> So same to this patch, I only lift the limit for X86. Hope other targets will 
> follow us to enable for themselves. WDYT?

A right, I was confused because I saw llvm/test/CodeGen/AArch64/O0-pipeline.ll 
running the new pass on AArch64, but actually it doesn't do anything unless 
it's enabled in llvm/lib/Target/*/*ISelLowering.cpp. Got it, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139170

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


[PATCH] D139173: [clang] Add test for CWG600

2022-12-02 Thread Vlad Serebrennikov via Phabricator via cfe-commits
Endill created this revision.
Endill added a reviewer: clang-language-wg.
Herald added a project: All.
Endill requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

P1787 : //CWG600 is resolved by explaining that 
accessibility affects naming a member in the sense of the ODR.//
Wording: see changes to [class.access] p1 and p4.
Additional references: basic.def.odr/8 
: //A function is odr-used 
if it is named by a potentially-evaluated expression or conversion.//


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139173

Files:
  clang/test/CXX/drs/dr6xx.cpp
  clang/www/cxx_dr_status.html


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -3642,7 +3642,7 @@
 https://wg21.link/cwg600";>600
 CD6
 Does access control apply to members or to names?
-Unknown
+Yes
   
   
 https://wg21.link/cwg601";>601
Index: clang/test/CXX/drs/dr6xx.cpp
===
--- clang/test/CXX/drs/dr6xx.cpp
+++ clang/test/CXX/drs/dr6xx.cpp
@@ -3,6 +3,21 @@
 // RUN: %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors -fno-spell-checking
 // RUN: %clang_cc1 -std=c++17 %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors -fno-spell-checking
 // RUN: %clang_cc1 -std=c++20 %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors -fno-spell-checking
+// RUN: %clang_cc1 -std=c++2b %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors -fno-spell-checking
+
+namespace dr600 { // dr600: yes
+struct S {
+  void f(int);
+
+private:
+  void f(double); // expected-note {{declared private here}}
+};
+
+void g(S *sp) {
+  sp->f(2);
+  sp->f(2.2); // expected-error {{is a private member}}
+}
+} // namespace dr600
 
 namespace std {
   struct type_info {};


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -3642,7 +3642,7 @@
 https://wg21.link/cwg600";>600
 CD6
 Does access control apply to members or to names?
-Unknown
+Yes
   
   
 https://wg21.link/cwg601";>601
Index: clang/test/CXX/drs/dr6xx.cpp
===
--- clang/test/CXX/drs/dr6xx.cpp
+++ clang/test/CXX/drs/dr6xx.cpp
@@ -3,6 +3,21 @@
 // RUN: %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -fno-spell-checking
 // RUN: %clang_cc1 -std=c++17 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -fno-spell-checking
 // RUN: %clang_cc1 -std=c++20 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -fno-spell-checking
+// RUN: %clang_cc1 -std=c++2b %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -fno-spell-checking
+
+namespace dr600 { // dr600: yes
+struct S {
+  void f(int);
+
+private:
+  void f(double); // expected-note {{declared private here}}
+};
+
+void g(S *sp) {
+  sp->f(2);
+  sp->f(2.2); // expected-error {{is a private member}}
+}
+} // namespace dr600
 
 namespace std {
   struct type_info {};
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139170: [X86][clang] Lift _BitInt() supported max width.

2022-12-02 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe added a comment.

In D139170#3965852 , @mgehre-amd 
wrote:

> In D139170#3965850 , @FreddyYe 
> wrote:
>
>> In D139170#3965814 , @mgehre-amd 
>> wrote:
>>
>>> Do other targets not support > 128 bit integers, or is this PR only the 
>>> first conservative step of lifting the limit?
>>
>> I temporary only enabled > 128 bit FP conversion for X86 in 
>> https://reviews.llvm.org/D137241, since I highly relied on end-to-end tests 
>> to implement that pass and I don't have other targets' environment to 
>> verify. So same to this patch, I only lift the limit for X86. Hope other 
>> targets will follow us to enable for themselves. WDYT?
>
> A right, I was confused because I saw 
> llvm/test/CodeGen/AArch64/O0-pipeline.ll running the new pass on AArch64, but 
> actually it doesn't do anything unless it's enabled in 
> llvm/lib/Target/*/*ISelLowering.cpp. Got it, thanks!

Yes. Actually, that's the framework you added before. :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139170

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


[PATCH] D139148: Fix nullptr dereference found by Coverity static analysis tool

2022-12-02 Thread Sindhu Chittireddy via Phabricator via cfe-commits
schittir updated this revision to Diff 479541.
schittir added a comment.

Add more nullptr checks per Shafik's comments


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

https://reviews.llvm.org/D139148

Files:
  clang/lib/Sema/SemaInit.cpp


Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -5962,9 +5962,10 @@
 if (Kind.getKind() == InitializationKind::IK_Direct ||
 (Kind.getKind() == InitializationKind::IK_Copy &&
  (Context.hasSameUnqualifiedType(SourceType, DestType) ||
-  S.IsDerivedFrom(Initializer->getBeginLoc(), SourceType, DestType
-  TryConstructorInitialization(S, Entity, Kind, Args,
-   DestType, DestType, *this);
+  (Initializer &&
+   S.IsDerivedFrom(Initializer->getBeginLoc(), SourceType, 
DestType)
+  TryConstructorInitialization(S, Entity, Kind, Args, DestType, DestType,
+   *this);
 // - Otherwise (i.e., for the remaining copy-initialization cases),
 //   user-defined conversion sequences that can convert from the source
 //   type to the destination type or (when a conversion function is
@@ -6027,8 +6028,8 @@
 bool NeedAtomicConversion = false;
 if (const AtomicType *Atomic = DestType->getAs()) {
   if (Context.hasSameUnqualifiedType(SourceType, Atomic->getValueType()) ||
-  S.IsDerivedFrom(Initializer->getBeginLoc(), SourceType,
-  Atomic->getValueType())) {
+  (Initializer && S.IsDerivedFrom(Initializer->getBeginLoc(),
+  SourceType, Atomic->getValueType())) 
{
 DestType = Atomic->getValueType();
 NeedAtomicConversion = true;
   }
@@ -6045,7 +6046,7 @@
   //- Otherwise, if the initialization is direct-initialization, the source
   //type is std::nullptr_t, and the destination type is bool, the initial
   //value of the object being initialized is false.
-  if (!SourceType.isNull() && SourceType->isNullPtrType() &&
+  if (!SourceType.isNull() && SourceType->isNullPtrType() && Initializer &&
   DestType->isBooleanType() &&
   Kind.getKind() == InitializationKind::IK_Direct) {
 AddConversionSequenceStep(
@@ -6095,11 +6096,11 @@
 DeclAccessPair dap;
 if (isLibstdcxxPointerReturnFalseHack(S, Entity, Initializer)) {
   AddZeroInitializationStep(Entity.getType());
-} else if (Initializer->getType() == Context.OverloadTy &&
+} else if (Initializer && Initializer->getType() == Context.OverloadTy &&
!S.ResolveAddressOfOverloadedFunction(Initializer, DestType,
  false, dap))
   SetFailed(InitializationSequence::FK_AddressOfOverloadFailed);
-else if (Initializer->getType()->isFunctionType() &&
+else if (Initializer && Initializer->getType()->isFunctionType() &&
  isExprAnUnaddressableFunction(S, Initializer))
   SetFailed(InitializationSequence::FK_AddressOfUnaddressableFunction);
 else


Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -5962,9 +5962,10 @@
 if (Kind.getKind() == InitializationKind::IK_Direct ||
 (Kind.getKind() == InitializationKind::IK_Copy &&
  (Context.hasSameUnqualifiedType(SourceType, DestType) ||
-  S.IsDerivedFrom(Initializer->getBeginLoc(), SourceType, DestType
-  TryConstructorInitialization(S, Entity, Kind, Args,
-   DestType, DestType, *this);
+  (Initializer &&
+   S.IsDerivedFrom(Initializer->getBeginLoc(), SourceType, DestType)
+  TryConstructorInitialization(S, Entity, Kind, Args, DestType, DestType,
+   *this);
 // - Otherwise (i.e., for the remaining copy-initialization cases),
 //   user-defined conversion sequences that can convert from the source
 //   type to the destination type or (when a conversion function is
@@ -6027,8 +6028,8 @@
 bool NeedAtomicConversion = false;
 if (const AtomicType *Atomic = DestType->getAs()) {
   if (Context.hasSameUnqualifiedType(SourceType, Atomic->getValueType()) ||
-  S.IsDerivedFrom(Initializer->getBeginLoc(), SourceType,
-  Atomic->getValueType())) {
+  (Initializer && S.IsDerivedFrom(Initializer->getBeginLoc(),
+  SourceType, Atomic->getValueType())) {
 DestType = Atomic->getValueType();
 NeedAtomicConversion = true;
   }
@@ -6045,7 +6046,7 @@
   //- Otherwise, if the initialization is direct-initialization, the source
   //type is std::nullptr_t, and the destination type is bool, the initial
   //value of 

[clang] 498abe2 - [clang][docs] Correct floating point option explanations

2022-12-02 Thread KAWASHIMA Takahiro via cfe-commits

Author: KAWASHIMA Takahiro
Date: 2022-12-02T17:50:13+09:00
New Revision: 498abe27dcf89ba7eb865ea6c46b217a7b68f082

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

LOG: [clang][docs] Correct floating point option explanations

Explanations for options of floating point are updated to match
the `RenderFloatingPointOptions` function in
`clang/lib/Driver/ToolChains/Clang.cpp`.

Missing explanations are also added.

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

Added: 


Modified: 
clang/docs/UsersManual.rst

Removed: 




diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 2861c6a4c3c2c..d4e5b3565ee06 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -1437,6 +1437,8 @@ floating point semantic models: precise (the default), 
strict, and fast.
 
* ``-fno-honor-nans``
 
+   * ``-fapprox-func``
+
* ``-fno-math-errno``
 
* ``-ffinite-math-only``
@@ -1449,6 +1451,8 @@ floating point semantic models: precise (the default), 
strict, and fast.
 
* ``-fno-trapping-math``
 
+   * ``-fno-rounding-math``
+
* ``-ffp-contract=fast``
 
Note: ``-ffast-math`` causes ``crtfastmath.o`` to be linked with code. See
@@ -1457,7 +1461,7 @@ floating point semantic models: precise (the default), 
strict, and fast.
 .. option:: -fno-fast-math
 
Disable fast-math mode.  This options disables unsafe floating-point
-   optimizations by preventing the compiler from making any tranformations that
+   optimizations by preventing the compiler from making any transformations 
that
could affect the results.
 
This option implies:
@@ -1466,7 +1470,7 @@ floating point semantic models: precise (the default), 
strict, and fast.
 
* ``-fhonor-nans``
 
-   * ``-fmath-errno``
+   * ``-fno-approx-func``
 
* ``-fno-finite-math-only``
 
@@ -1476,14 +1480,15 @@ floating point semantic models: precise (the default), 
strict, and fast.
 
* ``-fsigned-zeros``
 
-   * ``-fno-trapping-math``
-
* ``-ffp-contract=on``
 
-   * ``-fdenormal-fp-math=ieee``
+   Also, this option resets following options to their target-dependent 
defaults.
+
+   * ``-f[no-]math-errno``
+   * ``-fdenormal-fp-math=``
 
There is ambiguity about how ``-ffp-contract``, ``-ffast-math``,
-   and ``-fno-fast-math`` behave in combination. To keep the value of
+   and ``-fno-fast-math`` behave when combined. To keep the value of
``-ffp-contract`` consistent, we define this set of rules:
 
* ``-ffast-math`` sets ``ffp-contract`` to ``fast``.
@@ -1516,7 +1521,8 @@ floating point semantic models: precise (the default), 
strict, and fast.
* ``preserve-sign`` - the sign of a flushed-to-zero number is preserved in 
the sign of 0
* ``positive-zero`` - denormals are flushed to positive zero
 
-   Defaults to ``ieee``.
+   The default value depends on the target. For most targets, defaults to
+   ``ieee``.
 
 .. option:: -f[no-]strict-float-cast-overflow
 
@@ -1525,6 +1531,7 @@ floating point semantic models: precise (the default), 
strict, and fast.
By default, Clang will not guarantee any particular result in that case.
With the 'no-strict' option, Clang will saturate towards the smallest and
largest representable integer values instead. NaNs will be converted to 
zero.
+   Defaults to ``-fstrict-float-cast-overflow``.
 
 .. option:: -f[no-]math-errno
 
@@ -1572,11 +1579,19 @@ floating point semantic models: precise (the default), 
strict, and fast.
 
 .. option:: -f[no-]honor-infinities
 
+   Allow floating-point optimizations that assume arguments and results are
+   not +-Inf.
+   Defaults to ``-fhonor-infinities``.
+
If both ``-fno-honor-infinities`` and ``-fno-honor-nans`` are used,
has the same effect as specifying ``-ffinite-math-only``.
 
 .. option:: -f[no-]honor-nans
 
+   Allow floating-point optimizations that assume arguments and results are
+   not NaNs.
+   Defaults to ``-fhonor-nans``.
+
If both ``-fno-honor-infinities`` and ``-fno-honor-nans`` are used,
has the same effect as specifying ``-ffinite-math-only``.
 
@@ -1592,7 +1607,7 @@ floating point semantic models: precise (the default), 
strict, and fast.
 .. option:: -f[no-]signed-zeros
 
Allow optimizations that ignore the sign of floating point zeros.
-   Defaults to ``-fno-signed-zeros``.
+   Defaults to ``-fsigned-zeros``.
 
 .. option:: -f[no-]associative-math
 
@@ -1608,24 +1623,48 @@ floating point semantic models: precise (the default), 
strict, and fast.
 
 .. option:: -f[no-]unsafe-math-optimizations
 
-   Allow unsafe floating-point optimizations. Also implies:
+   Allow unsafe floating-point optimizations.
+   ``-funsafe-math-optimizations`` also implies:
 
+   * ``-fapprox-func``
* ``-fassociative-math``
* ``-freciprocal

[PATCH] D138117: [clang][docs] Correct floating point option explanations

2022-12-02 Thread KAWASHIMA Takahiro via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG498abe27dcf8: [clang][docs] Correct floating point option 
explanations (authored by kawashima-fj).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138117

Files:
  clang/docs/UsersManual.rst

Index: clang/docs/UsersManual.rst
===
--- clang/docs/UsersManual.rst
+++ clang/docs/UsersManual.rst
@@ -1437,6 +1437,8 @@
 
* ``-fno-honor-nans``
 
+   * ``-fapprox-func``
+
* ``-fno-math-errno``
 
* ``-ffinite-math-only``
@@ -1449,6 +1451,8 @@
 
* ``-fno-trapping-math``
 
+   * ``-fno-rounding-math``
+
* ``-ffp-contract=fast``
 
Note: ``-ffast-math`` causes ``crtfastmath.o`` to be linked with code. See
@@ -1457,7 +1461,7 @@
 .. option:: -fno-fast-math
 
Disable fast-math mode.  This options disables unsafe floating-point
-   optimizations by preventing the compiler from making any tranformations that
+   optimizations by preventing the compiler from making any transformations that
could affect the results.
 
This option implies:
@@ -1466,7 +1470,7 @@
 
* ``-fhonor-nans``
 
-   * ``-fmath-errno``
+   * ``-fno-approx-func``
 
* ``-fno-finite-math-only``
 
@@ -1476,14 +1480,15 @@
 
* ``-fsigned-zeros``
 
-   * ``-fno-trapping-math``
-
* ``-ffp-contract=on``
 
-   * ``-fdenormal-fp-math=ieee``
+   Also, this option resets following options to their target-dependent defaults.
+
+   * ``-f[no-]math-errno``
+   * ``-fdenormal-fp-math=``
 
There is ambiguity about how ``-ffp-contract``, ``-ffast-math``,
-   and ``-fno-fast-math`` behave in combination. To keep the value of
+   and ``-fno-fast-math`` behave when combined. To keep the value of
``-ffp-contract`` consistent, we define this set of rules:
 
* ``-ffast-math`` sets ``ffp-contract`` to ``fast``.
@@ -1516,7 +1521,8 @@
* ``preserve-sign`` - the sign of a flushed-to-zero number is preserved in the sign of 0
* ``positive-zero`` - denormals are flushed to positive zero
 
-   Defaults to ``ieee``.
+   The default value depends on the target. For most targets, defaults to
+   ``ieee``.
 
 .. option:: -f[no-]strict-float-cast-overflow
 
@@ -1525,6 +1531,7 @@
By default, Clang will not guarantee any particular result in that case.
With the 'no-strict' option, Clang will saturate towards the smallest and
largest representable integer values instead. NaNs will be converted to zero.
+   Defaults to ``-fstrict-float-cast-overflow``.
 
 .. option:: -f[no-]math-errno
 
@@ -1572,11 +1579,19 @@
 
 .. option:: -f[no-]honor-infinities
 
+   Allow floating-point optimizations that assume arguments and results are
+   not +-Inf.
+   Defaults to ``-fhonor-infinities``.
+
If both ``-fno-honor-infinities`` and ``-fno-honor-nans`` are used,
has the same effect as specifying ``-ffinite-math-only``.
 
 .. option:: -f[no-]honor-nans
 
+   Allow floating-point optimizations that assume arguments and results are
+   not NaNs.
+   Defaults to ``-fhonor-nans``.
+
If both ``-fno-honor-infinities`` and ``-fno-honor-nans`` are used,
has the same effect as specifying ``-ffinite-math-only``.
 
@@ -1592,7 +1607,7 @@
 .. option:: -f[no-]signed-zeros
 
Allow optimizations that ignore the sign of floating point zeros.
-   Defaults to ``-fno-signed-zeros``.
+   Defaults to ``-fsigned-zeros``.
 
 .. option:: -f[no-]associative-math
 
@@ -1608,24 +1623,48 @@
 
 .. option:: -f[no-]unsafe-math-optimizations
 
-   Allow unsafe floating-point optimizations. Also implies:
+   Allow unsafe floating-point optimizations.
+   ``-funsafe-math-optimizations`` also implies:
 
+   * ``-fapprox-func``
* ``-fassociative-math``
* ``-freciprocal-math``
-   * ``-fno-signed-zeroes``
-   * ``-fno-trapping-math``.
+   * ``-fno-signed-zeros``
+   * ``-fno-trapping-math``
+   * ``-ffp-contract=fast``
+
+   ``-fno-unsafe-math-optimizations`` implies:
+
+   * ``-fno-approx-func``
+   * ``-fno-associative-math``
+   * ``-fno-reciprocal-math``
+   * ``-fsigned-zeros``
+   * ``-ftrapping-math``
+   * ``-ffp-contract=on``
+   * ``-fdenormal-fp-math=ieee``
+
+   There is ambiguity about how ``-ffp-contract``,
+   ``-funsafe-math-optimizations``, and ``-fno-unsafe-math-optimizations``
+   behave when combined. Explanation in :option:`-fno-fast-math` also applies
+   to these options.
 
Defaults to ``-fno-unsafe-math-optimizations``.
 
 .. option:: -f[no-]finite-math-only
 
Allow floating-point optimizations that assume arguments and results are
-   not NaNs or +-Inf.  This defines the ``__FINITE_MATH_ONLY__`` preprocessor macro.
-   Also implies:
+   not NaNs or +-Inf. ``-ffinite-math-only`` defines the
+   ``__FINITE_MATH_ONLY__`` preprocessor macro.
+   ``-ffinite-math-only`` implies:
 
* ``-fno-honor-infinities``
* ``-fno-honor-nans``
 
+   ``-ffno-inite-math-only`` implies

[clang] eba4efc - [clang] Remove unused bookmark in CWG360 test (NFC)

2022-12-02 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2022-12-02T11:52:19+03:00
New Revision: eba4efcb056ccea1804a5c578b0ddc736100ebcc

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

LOG: [clang] Remove unused bookmark in CWG360 test (NFC)

Added: 


Modified: 
clang/test/CXX/drs/dr3xx.cpp

Removed: 




diff  --git a/clang/test/CXX/drs/dr3xx.cpp b/clang/test/CXX/drs/dr3xx.cpp
index de7f6b9bbf1d1..cca9470bcfd6c 100644
--- a/clang/test/CXX/drs/dr3xx.cpp
+++ b/clang/test/CXX/drs/dr3xx.cpp
@@ -905,7 +905,7 @@ struct B : A {
 protected:
   using A::bar; // #dr360-bar-using-decl
 public:
-  using A::baz; // #dr360-baz-using-decl
+  using A::baz;
 };
 
 int main() {



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


[PATCH] D139167: [clang][Windows]Ignore Options '/d1nodatetime' and '/d1import_no_registry'

2022-12-02 Thread Tobias Hieta via Phabricator via cfe-commits
thieta added a comment.

I tried to look up what these options do exactly - but they don't seem to be 
documented.

`/d1nodatetime` seems like an option that should be implemented instead of just 
ignored since it can have real reproducible problems not being there.

Do you know what `/d1import_no_registry` actually does?

I think we can ignore options that are not applicable in clang-cl, but I think 
if there are options that expect to change something, it's probably better to 
fail than to silently accept them.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139167

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


[PATCH] D139177: [LoongArch] Specify registers used for exception handling

2022-12-02 Thread Lu Weining via Phabricator via cfe-commits
SixWeining created this revision.
SixWeining added reviewers: xen0n, xry111, MaskRay, wangleiat.
Herald added a subscriber: StephenFan.
Herald added a project: All.
SixWeining requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

See definition in backend D134709  and the 
doc [1] for more detail.

With the benefit of this change, most libcxx and libcxxabi tests pass.

[1]: https://llvm.org/docs/ExceptionHandling.html


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139177

Files:
  clang/lib/Basic/Targets/LoongArch.h


Index: clang/lib/Basic/Targets/LoongArch.h
===
--- clang/lib/Basic/Targets/LoongArch.h
+++ clang/lib/Basic/Targets/LoongArch.h
@@ -56,6 +56,14 @@
 
   ArrayRef getGCCRegNames() const override;
 
+  int getEHDataRegisterNumber(unsigned RegNo) const override {
+if (RegNo == 0)
+  return 4;
+if (RegNo == 1)
+  return 5;
+return -1;
+  }
+
   ArrayRef getGCCRegAliases() const override;
 
   bool validateAsmConstraint(const char *&Name,


Index: clang/lib/Basic/Targets/LoongArch.h
===
--- clang/lib/Basic/Targets/LoongArch.h
+++ clang/lib/Basic/Targets/LoongArch.h
@@ -56,6 +56,14 @@
 
   ArrayRef getGCCRegNames() const override;
 
+  int getEHDataRegisterNumber(unsigned RegNo) const override {
+if (RegNo == 0)
+  return 4;
+if (RegNo == 1)
+  return 5;
+return -1;
+  }
+
   ArrayRef getGCCRegAliases() const override;
 
   bool validateAsmConstraint(const char *&Name,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D138939: [WIP][clang] adds a way to provide user-oriented reasons

2022-12-02 Thread Thorsten via Phabricator via cfe-commits
tschuett added a comment.

Then Sarif was a distraction. Still to reduce boilerplate and for A/B testing:

  enum class DiagnosticMode {
Legacy,
UserOriented,
Default = Legacy
  }


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138939

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


[PATCH] D128677: [clangd] Add support for generating #import edits

2022-12-02 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

we should have tests in `clang/unittests/Tooling/HeaderIncludesTest.cpp` and 
the commit itself should be tagged as `[clang][Tooling]` rather than `[clangd]`.




Comment at: clang-tools-extra/clangd/Headers.h:250
+  llvm::Optional insert(llvm::StringRef VerbatimHeader,
+  bool ViaImport) const;
 

again it's better to have an enum here.



Comment at: clang-tools-extra/clangd/IncludeFixer.cpp:253
+   llvm::StringRef Symbol,
+   bool ViaImport) const {
   Fix F;

again can we rather pass the directive enum around?



Comment at: clang/include/clang/Tooling/Inclusions/HeaderIncludes.h:74
+  llvm::Optional
+  insert(llvm::StringRef Header, bool IsAngled, bool IsImport = false) const;
 

rather than a boolean flag, can you introduce an `enum IncludeDirective { 
Include, Import };` and default it to `Include` here?



Comment at: clang/include/clang/Tooling/Inclusions/HeaderIncludes.h:86
 private:
   struct Include {
 Include(StringRef Name, tooling::Range R) : Name(Name), R(R) {}

we also need to preserve includedirective here now. as the behaviour of 
`insert` is to return none iff it's exactly the same spelling. so if there's a 
`#include "foo.h"` and we want to insert `#import "foo.h"` it shouldn't fail.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128677

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


[PATCH] D139177: [LoongArch] Specify registers used for exception handling

2022-12-02 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n accepted this revision.
xen0n added a comment.
This revision is now accepted and ready to land.

Trivial enough (`$a0` and `$a1` respectively, same as RISCV and Mips). Thanks 
for the quick fixing!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139177

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


[PATCH] D139087: [include-cleaner] Handle base class member access from derived class.

2022-12-02 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/include-cleaner/lib/WalkAST.cpp:62
   bool VisitMemberExpr(MemberExpr *E) {
-report(E->getMemberLoc(), E->getFoundDecl().getDecl());
+// Instead of the FieldDecl for MemberExpr, we report the Decl of
+// the corresponding record.

comment doesn't really say why. maybe include something along the lines `as we 
want to mark usage of most specific type (e.g. derived class, when using 
members from the base)`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139087

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


[PATCH] D139177: [LoongArch] Specify registers used for exception handling

2022-12-02 Thread Lu Weining via Phabricator via cfe-commits
SixWeining updated this revision to Diff 479553.
SixWeining added a comment.

Add clang test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139177

Files:
  clang/lib/Basic/Targets/LoongArch.h
  clang/test/CodeGen/builtins-loongarch.c


Index: clang/test/CodeGen/builtins-loongarch.c
===
--- /dev/null
+++ clang/test/CodeGen/builtins-loongarch.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -Wall -Wno-unused-but-set-variable -Werror -triple 
loongarch32 -disable-O0-optnone -emit-llvm -o - %s | opt -S -passes=mem2reg | 
FileCheck %s
+// RUN: %clang_cc1 -Wall -Wno-unused-but-set-variable -Werror -triple 
loongarch64 -disable-O0-optnone -emit-llvm -o - %s | opt -S -passes=mem2reg | 
FileCheck %s
+
+void test_eh_return_data_regno(void) {
+  // CHECK: store volatile i32 4
+  // CHECK: store volatile i32 5
+  volatile int res;
+  res = __builtin_eh_return_data_regno(0);
+  res = __builtin_eh_return_data_regno(1);
+}
Index: clang/lib/Basic/Targets/LoongArch.h
===
--- clang/lib/Basic/Targets/LoongArch.h
+++ clang/lib/Basic/Targets/LoongArch.h
@@ -56,6 +56,14 @@
 
   ArrayRef getGCCRegNames() const override;
 
+  int getEHDataRegisterNumber(unsigned RegNo) const override {
+if (RegNo == 0)
+  return 4;
+if (RegNo == 1)
+  return 5;
+return -1;
+  }
+
   ArrayRef getGCCRegAliases() const override;
 
   bool validateAsmConstraint(const char *&Name,


Index: clang/test/CodeGen/builtins-loongarch.c
===
--- /dev/null
+++ clang/test/CodeGen/builtins-loongarch.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -Wall -Wno-unused-but-set-variable -Werror -triple loongarch32 -disable-O0-optnone -emit-llvm -o - %s | opt -S -passes=mem2reg | FileCheck %s
+// RUN: %clang_cc1 -Wall -Wno-unused-but-set-variable -Werror -triple loongarch64 -disable-O0-optnone -emit-llvm -o - %s | opt -S -passes=mem2reg | FileCheck %s
+
+void test_eh_return_data_regno(void) {
+  // CHECK: store volatile i32 4
+  // CHECK: store volatile i32 5
+  volatile int res;
+  res = __builtin_eh_return_data_regno(0);
+  res = __builtin_eh_return_data_regno(1);
+}
Index: clang/lib/Basic/Targets/LoongArch.h
===
--- clang/lib/Basic/Targets/LoongArch.h
+++ clang/lib/Basic/Targets/LoongArch.h
@@ -56,6 +56,14 @@
 
   ArrayRef getGCCRegNames() const override;
 
+  int getEHDataRegisterNumber(unsigned RegNo) const override {
+if (RegNo == 0)
+  return 4;
+if (RegNo == 1)
+  return 5;
+return -1;
+  }
+
   ArrayRef getGCCRegAliases() const override;
 
   bool validateAsmConstraint(const char *&Name,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139167: [clang][Windows]Ignore Options '/d1nodatetime' and '/d1import_no_registry'

2022-12-02 Thread Qfrost via Phabricator via cfe-commits
Qfrost911 added a comment.

Yes, these options are not documented, so I think they can be ignored. If they 
are important options for windows driver, why MSVC didn't document them. And, 
the windows driver run perfectly even if I ignore these two options.

Moreover, there are lots of options which do nothing were defined in 
//clang/Options.td //and //lld/COFF/Options.td//, such as "kernel", 
"pdbcompress" etc., in order to be compatible with MSVC and other environment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139167

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


[PATCH] D139087: [include-cleaner] Handle base class member access from derived class.

2022-12-02 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 479556.
VitaNuo added a comment.

Add more comments. Add unimplemented VisitCXXDependentScopeMemberExpr method 
with a FIXME comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139087

Files:
  clang-tools-extra/include-cleaner/lib/WalkAST.cpp
  clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp


Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -88,12 +88,10 @@
 auto RTStr = llvm::to_string(RT);
 for (auto Expected : Target.points(RTStr))
   if (!llvm::is_contained(ReferencedOffsets[RT], Expected))
-DiagnosePoint("location not marked used with type " + RTStr,
-  Expected);
+DiagnosePoint("location not marked used with type " + RTStr, Expected);
 for (auto Actual : ReferencedOffsets[RT])
   if (!llvm::is_contained(Target.points(RTStr), Actual))
-DiagnosePoint("location unexpectedly used with type " + RTStr,
-  Actual);
+DiagnosePoint("location unexpectedly used with type " + RTStr, Actual);
   }
 
   // If there were any differences, we print the entire referencing code once.
@@ -172,10 +170,16 @@
 }
 
 TEST(WalkAST, MemberExprs) {
-  testWalk("struct S { void $explicit^foo(); };", "void foo() { S{}.^foo(); 
}");
+  testWalk("struct $explicit^S { void foo(); };", "void foo() { S{}.^foo(); 
}");
   testWalk(
-  "struct S { void foo(); }; struct X : S { using S::$explicit^foo; };",
+  "struct S { void foo(); }; struct $explicit^X : S { using S::foo; };",
   "void foo() { X{}.^foo(); }");
+  testWalk("struct Base { int a; }; struct $explicit^Derived : public Base 
{};",
+   "void fun(Derived d) { d.^a; }");
+  testWalk("struct Base { int a; }; struct $explicit^Derived : public Base 
{};",
+   "void fun(Derived* d) { d->^a; }");
+  testWalk("struct Base { int a; }; struct $explicit^Derived : public Base 
{};",
+   "void fun(Derived& d) { d.^a; }");
 }
 
 TEST(WalkAST, ConstructExprs) {
Index: clang-tools-extra/include-cleaner/lib/WalkAST.cpp
===
--- clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -59,10 +59,29 @@
   }
 
   bool VisitMemberExpr(MemberExpr *E) {
-report(E->getMemberLoc(), E->getFoundDecl().getDecl());
+// Instead of the FieldDecl for MemberExpr, we report the Decl of
+// the corresponding record. This is done in order to report
+// the usage of most specific type (e.g., derived class, when
+// using members from the base).
+QualType Type = E->getBase()->IgnoreImpCasts()->getType();
+RecordDecl *RD = getDeclFromType(Type);
+report(E->getMemberLoc(), RD);
 return true;
   }
 
+  bool VisitCXXDependentScopeMemberExpr(const CXXDependentScopeMemberExpr *E) {
+// FIXME: implement this
+return true;
+  }
+
+  RecordDecl *getDeclFromType(QualType Type) {
+if (Type->isPointerType()) {
+  Type = Type->getPointeeType();
+}
+RecordDecl *RecordDecl = Type->getAsRecordDecl();
+return RecordDecl;
+  }
+
   bool VisitCXXConstructExpr(CXXConstructExpr *E) {
 report(E->getLocation(), E->getConstructor(),
E->getParenOrBraceRange().isValid() ? RefType::Explicit


Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -88,12 +88,10 @@
 auto RTStr = llvm::to_string(RT);
 for (auto Expected : Target.points(RTStr))
   if (!llvm::is_contained(ReferencedOffsets[RT], Expected))
-DiagnosePoint("location not marked used with type " + RTStr,
-  Expected);
+DiagnosePoint("location not marked used with type " + RTStr, Expected);
 for (auto Actual : ReferencedOffsets[RT])
   if (!llvm::is_contained(Target.points(RTStr), Actual))
-DiagnosePoint("location unexpectedly used with type " + RTStr,
-  Actual);
+DiagnosePoint("location unexpectedly used with type " + RTStr, Actual);
   }
 
   // If there were any differences, we print the entire referencing code once.
@@ -172,10 +170,16 @@
 }
 
 TEST(WalkAST, MemberExprs) {
-  testWalk("struct S { void $explicit^foo(); };", "void foo() { S{}.^foo(); }");
+  testWalk("struct $explicit^S { void foo(); };", "void foo() { S{}.^foo(); }");
   testWalk(
-  "struct S { void foo(); }; struct X : S { using S::$explicit^foo; };",
+  "struct S { void foo(); }; struct $explicit^X : S { using S::foo; };",
   "void fo

[PATCH] D139087: [include-cleaner] Handle base class member access from derived class.

2022-12-02 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo marked an inline comment as done.
VitaNuo added inline comments.



Comment at: clang-tools-extra/include-cleaner/lib/WalkAST.cpp:65
+Expr *BE = E->getBase()->IgnoreImpCasts();
+RecordDecl *RD = BE->getType()->getAsRecordDecl();
+report(E->getMemberLoc(), RD);

hokein wrote:
> This is not safe, we can get a nullptr if this type is not a normal 
> `RecordType`.
> 
> I think there are more cases we need to handle:
> 1) pointer type (`Derived *`)
> 2) reference type (`Derived &`)
> 3) a dependent type
> 
> For the 3), some code like `std::vector().size()`, it is tricky -- because 
> we can't get any decl from a dependent type, we need some heuristics (in 
> clangd we have some bits), we don't need to do that in this patch.
> 
> In the code implementation, we should add a dedicated `handleType(QualType)` 
> helper to handle all these cases, so `VisitMemberExpr`, 
> `VisitCXXDependentScopeMemberExpr` callbacks can just dispatch the type to 
> this helper.
Ok, added pointer types. Reference types seem to be working already. Added a 
FIXME for dependent members.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139087

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


[PATCH] D139178: [libclang] Have clang_getCursorSpelling() return the string for a CXCursor_IntegerLiteral cursor

2022-12-02 Thread William Hsu via Phabricator via cfe-commits
GrislyMe created this revision.
GrislyMe added reviewers: abdulras, gribozavr.
GrislyMe added a project: clang.
Herald added a subscriber: arphaman.
Herald added a project: All.
GrislyMe requested review of this revision.
Herald added a subscriber: cfe-commits.

Return the IntegerLiteral cursor value in a string.
The value will be represented in base-10 and unsigned.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139178

Files:
  clang/tools/libclang/CIndex.cpp


Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -4937,6 +4937,13 @@
   SLit->outputString(OS);
   return cxstring::createDup(OS.str());
 }
+if (C.kind == CXCursor_IntegerLiteral) {
+  SmallString<64> Buf;
+  if (const IntegerLiteral *ILit = dyn_cast(E)) {
+ILit->getValue().toString(Buf, 10, true);
+return cxstring::createDup(Buf);
+  }
+}
 
 const Decl *D = getDeclFromExpr(getCursorExpr(C));
 if (D)


Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -4937,6 +4937,13 @@
   SLit->outputString(OS);
   return cxstring::createDup(OS.str());
 }
+if (C.kind == CXCursor_IntegerLiteral) {
+  SmallString<64> Buf;
+  if (const IntegerLiteral *ILit = dyn_cast(E)) {
+ILit->getValue().toString(Buf, 10, true);
+return cxstring::createDup(Buf);
+  }
+}
 
 const Decl *D = getDeclFromExpr(getCursorExpr(C));
 if (D)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139182: AArch64: add CodeGen support for FEAT_XS DSB instructions

2022-12-02 Thread Tim Northover via Phabricator via cfe-commits
t.p.northover created this revision.
Herald added subscribers: hiraditya, kristof.beyls, mcrosier.
Herald added a project: All.
t.p.northover requested review of this revision.
Herald added projects: clang, LLVM.

The new variants like `dsb ishnxs` map naturally to CRm == {16, 20, 24, 28}, 
extending the existing space of immediates for `__builtin_arm_dsb`. This adds 
Clang and backend CodeGen support to emit them when processor support is 
present, and reasonable diagnostics when it's not.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139182

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/AArch64.h
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/builtins-arm64.c
  llvm/include/llvm/Support/AArch64TargetParser.def
  llvm/include/llvm/Support/AArch64TargetParser.h
  llvm/lib/Target/AArch64/AArch64InstrFormats.td
  llvm/lib/Target/AArch64/AArch64InstrInfo.td
  llvm/test/CodeGen/AArch64/dsb-xs.ll
  llvm/unittests/Support/TargetParserTest.cpp

Index: llvm/unittests/Support/TargetParserTest.cpp
===
--- llvm/unittests/Support/TargetParserTest.cpp
+++ llvm/unittests/Support/TargetParserTest.cpp
@@ -1541,7 +1541,7 @@
   AArch64::AEK_PERFMON, AArch64::AEK_SVE2p1,AArch64::AEK_SME2p1,
   AArch64::AEK_B16B16,  AArch64::AEK_SMEF16F16, AArch64::AEK_CSSC,
   AArch64::AEK_RCPC3,   AArch64::AEK_THE,   AArch64::AEK_D128,
-  AArch64::AEK_LSE128,
+  AArch64::AEK_LSE128,  AArch64::AEK_XS,
   };
 
   std::vector Features;
Index: llvm/test/CodeGen/AArch64/dsb-xs.ll
===
--- /dev/null
+++ llvm/test/CodeGen/AArch64/dsb-xs.ll
@@ -0,0 +1,17 @@
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+xs %s -o - | FileCheck %s
+
+define void @test_barriers() {
+; CHECK-LABEL: test_barriers:
+
+; CHECK: dsb oshnxs
+; CHECK: dsb nshnxs
+; CHECK: dsb ishnxs
+; CHECK: dsb synxs
+
+  call void @llvm.aarch64.dsb(i32 16)
+  call void @llvm.aarch64.dsb(i32 20)
+  call void @llvm.aarch64.dsb(i32 24)
+  call void @llvm.aarch64.dsb(i32 28)
+  ret void
+}
+declare void @llvm.aarch64.dsb(i32)
Index: llvm/lib/Target/AArch64/AArch64InstrInfo.td
===
--- llvm/lib/Target/AArch64/AArch64InstrInfo.td
+++ llvm/lib/Target/AArch64/AArch64InstrInfo.td
@@ -1000,7 +1000,8 @@
   let Predicates = [HasTRACEV8_4];
 }
 
-def DSBnXS  : CRmSystemI {
+def DSBnXS  : CRmSystemI {
   let CRm{1-0}   = 0b11;
   let Inst{9-8}  = 0b10;
   let Predicates = [HasXS];
Index: llvm/lib/Target/AArch64/AArch64InstrFormats.td
===
--- llvm/lib/Target/AArch64/AArch64InstrFormats.td
+++ llvm/lib/Target/AArch64/AArch64InstrFormats.td
@@ -1021,6 +1021,14 @@
   let ParserMatchClass = Imm0_255Operand;
 }
 
+def DSBnXSXForm : SDNodeXFormgetTargetConstant((N->getZExtValue() & 0xc) | 3, SDLoc(N), MVT::i32);
+}]>;
+
+def imm32_nXS : ImmLeaf;
+
 // An arithmetic shifter operand:
 //  {7-6} - shift type: 00 = lsl, 01 = lsr, 10 = asr
 //  {5-0} - imm6
Index: llvm/include/llvm/Support/AArch64TargetParser.h
===
--- llvm/include/llvm/Support/AArch64TargetParser.h
+++ llvm/include/llvm/Support/AArch64TargetParser.h
@@ -82,6 +82,7 @@
   AEK_THE = 1ULL << 50, // FEAT_THE
   AEK_D128 =1ULL << 51, // FEAT_D128
   AEK_LSE128 =  1ULL << 52, // FEAT_LSE128
+  AEK_XS =  1ULL << 53, // FEAT_XS
 };
 
 // Represents an extension that can be enabled with -march=+.
Index: llvm/include/llvm/Support/AArch64TargetParser.def
===
--- llvm/include/llvm/Support/AArch64TargetParser.def
+++ llvm/include/llvm/Support/AArch64TargetParser.def
@@ -47,21 +47,21 @@
   AArch64::AEK_SM4  | AArch64::AEK_SHA3 | AArch64::AEK_BF16|
   AArch64::AEK_SHA2 | AArch64::AEK_AES  | AArch64::AEK_I8MM))
 AARCH64_ARCH(8, 7, AProfile, "armv8.7-a", ARMV8_7A, "+v8.7a",
- (AArch64::AEK_CRC | AArch64::AEK_FP |
-  AArch64::AEK_SIMD | AArch64::AEK_RAS | AArch64::AEK_LSE |
-  AArch64::AEK_RDM | AArch64::AEK_RCPC | AArch64::AEK_DOTPROD |
+ (AArch64::AEK_CRC | AArch64::AEK_FP | AArch64::AEK_SIMD |
+  AArch64::AEK_RAS | AArch64::AEK_LSE | AArch64::AEK_RDM |
+  AArch64::AEK_RCPC | AArch64::AEK_DOTPROD | AArch64::AEK_XS |
   AArch64::AEK_SM4 | AArch64::AEK_SHA3 | AArch64::AEK_BF16 |
   AArch64::AEK_SHA2 | AArch64::AEK_AES | AArch64::AEK_I8MM))
 AARCH64_ARCH(8, 8, AProfile, "armv8.8-a", ARMV8_8A, "+v8.8a",
- (AArch64::AEK_CRC | AArch64::AEK_FP |
-  AArch64::AEK_SIMD | AArch64::AEK_RAS | AArch64::AEK_LSE |
-  AArch64::AEK_RDM | AArch64::AEK_RCPC | AArch64::AEK_DOTPROD |
+ 

[PATCH] D139177: [LoongArch] Specify registers used for exception handling

2022-12-02 Thread wanglei via Phabricator via cfe-commits
wangleiat accepted this revision.
wangleiat added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139177

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


[PATCH] D139185: [clang][Interp] Use placement new to construct opcode args into vector

2022-12-02 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added reviewers: sepavloff, aaron.ballman.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The last version of this patch created problems because it was using the 
placement new with unaligned addresses.

This version tries to address this issue. I've enabled ubsan locally and not 
seen problems when running the interpreter test suite.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139185

Files:
  clang/lib/AST/Interp/ByteCodeEmitter.cpp
  clang/lib/AST/Interp/PrimType.h
  clang/lib/AST/Interp/Source.h


Index: clang/lib/AST/Interp/Source.h
===
--- clang/lib/AST/Interp/Source.h
+++ clang/lib/AST/Interp/Source.h
@@ -13,6 +13,7 @@
 #ifndef LLVM_CLANG_AST_INTERP_SOURCE_H
 #define LLVM_CLANG_AST_INTERP_SOURCE_H
 
+#include "PrimType.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/Stmt.h"
 #include "llvm/Support/Endian.h"
@@ -47,9 +48,10 @@
 
   /// Reads data and advances the pointer.
   template  std::enable_if_t::value, T> read() 
{
+assert(aligned(Ptr));
 using namespace llvm::support;
 T Value = endian::read(Ptr);
-Ptr += sizeof(T);
+Ptr += align(sizeof(T));
 return Value;
   }
 
Index: clang/lib/AST/Interp/PrimType.h
===
--- clang/lib/AST/Interp/PrimType.h
+++ clang/lib/AST/Interp/PrimType.h
@@ -62,6 +62,13 @@
   return ((Size + alignof(void *) - 1) / alignof(void *)) * alignof(void *);
 }
 
+constexpr bool aligned(size_t Size) { return Size == align(Size); }
+static_assert(aligned(sizeof(void *)));
+
+static inline bool aligned(const void *P) {
+  return aligned(reinterpret_cast(P));
+}
+
 inline bool isPrimitiveIntegral(PrimType Type) {
   switch (Type) {
   case PT_Bool:
Index: clang/lib/AST/Interp/ByteCodeEmitter.cpp
===
--- clang/lib/AST/Interp/ByteCodeEmitter.cpp
+++ clang/lib/AST/Interp/ByteCodeEmitter.cpp
@@ -116,7 +116,8 @@
   using namespace llvm::support;
 
   /// Rewrite the operand of all jumps to this label.
-  void *Location = Code.data() + Reloc - sizeof(int32_t);
+  void *Location = Code.data() + Reloc - align(sizeof(int32_t));
+  assert(aligned(Location));
   const int32_t Offset = Target - static_cast(Reloc);
   endian::write(Location, Offset);
 }
@@ -126,7 +127,9 @@
 
 int32_t ByteCodeEmitter::getOffset(LabelTy Label) {
   // Compute the PC offset which the jump is relative to.
-  const int64_t Position = Code.size() + sizeof(Opcode) + sizeof(int32_t);
+  const int64_t Position =
+  Code.size() + align(sizeof(Opcode)) + align(sizeof(int32_t));
+  assert(aligned(Position));
 
   // If target is known, compute jump offset.
   auto It = LabelOffsets.find(Label);
@@ -162,13 +165,17 @@
 return;
   }
 
+  // Access must be aligned!
+  size_t ValPos = align(Code.size());
+  Size = align(Size);
+  assert(aligned(ValPos + Size));
+  Code.resize(ValPos + Size);
+
   if constexpr (!std::is_pointer_v) {
-const char *Data = reinterpret_cast(&Val);
-Code.insert(Code.end(), Data, Data + Size);
+new (Code.data() + ValPos) T(Val);
   } else {
 uint32_t ID = P.getOrCreateNativePointer(Val);
-const char *Data = reinterpret_cast(&ID);
-Code.insert(Code.end(), Data, Data + Size);
+new (Code.data() + ValPos) uint32_t(ID);
   }
 }
 


Index: clang/lib/AST/Interp/Source.h
===
--- clang/lib/AST/Interp/Source.h
+++ clang/lib/AST/Interp/Source.h
@@ -13,6 +13,7 @@
 #ifndef LLVM_CLANG_AST_INTERP_SOURCE_H
 #define LLVM_CLANG_AST_INTERP_SOURCE_H
 
+#include "PrimType.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/Stmt.h"
 #include "llvm/Support/Endian.h"
@@ -47,9 +48,10 @@
 
   /// Reads data and advances the pointer.
   template  std::enable_if_t::value, T> read() {
+assert(aligned(Ptr));
 using namespace llvm::support;
 T Value = endian::read(Ptr);
-Ptr += sizeof(T);
+Ptr += align(sizeof(T));
 return Value;
   }
 
Index: clang/lib/AST/Interp/PrimType.h
===
--- clang/lib/AST/Interp/PrimType.h
+++ clang/lib/AST/Interp/PrimType.h
@@ -62,6 +62,13 @@
   return ((Size + alignof(void *) - 1) / alignof(void *)) * alignof(void *);
 }
 
+constexpr bool aligned(size_t Size) { return Size == align(Size); }
+static_assert(aligned(sizeof(void *)));
+
+static inline bool aligned(const void *P) {
+  return aligned(reinterpret_cast(P));
+}
+
 inline bool isPrimitiveIntegral(PrimType Type) {
   switch (Type) {
   case PT_Bool:
Index: clang/lib/AST/Interp/ByteCodeEmitter.cpp
===
--- clang/lib/AST/Interp/ByteCodeEmitter.cpp
+++ clang/lib/AST/Interp/ByteCodeEmitter.cpp
@@ -116,7 

[PATCH] D139013: [include-cleaner] clang-include-cleaner can print/apply edits

2022-12-02 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 479574.
sammccall marked an inline comment as done.
sammccall added a comment.
Herald added a project: clang.

replace fixIncludes impl with clang-format, tweak tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139013

Files:
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
  clang-tools-extra/include-cleaner/lib/Analysis.cpp
  clang-tools-extra/include-cleaner/lib/CMakeLists.txt
  clang-tools-extra/include-cleaner/test/Inputs/foobar.h
  clang-tools-extra/include-cleaner/test/tool.cpp
  clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
  clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
  clang/lib/Format/Format.cpp

Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -,7 +,7 @@
   // Make header insertion replacements insert new headers into correct blocks.
   tooling::Replacements NewReplaces =
   fixCppIncludeInsertions(Code, Replaces, Style);
-  return processReplacements(Cleanup, Code, NewReplaces, Style);
+  return cantFail(processReplacements(Cleanup, Code, NewReplaces, Style));
 }
 
 namespace internal {
Index: clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
@@ -18,6 +18,7 @@
 #include "clang/Tooling/Inclusions/StandardLibrary.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Testing/Support/Annotations.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
@@ -25,6 +26,7 @@
 
 namespace clang::include_cleaner {
 namespace {
+using testing::ElementsAre;
 using testing::Pair;
 using testing::UnorderedElementsAre;
 
@@ -134,6 +136,83 @@
   UnorderedElementsAre(Pair(Main.point(), UnorderedElementsAre(HdrFile;
 }
 
+TEST(Analyze, Basic) {
+  TestInputs Inputs;
+  Inputs.Code = R"cpp(
+#include "a.h"
+#include "b.h"
+
+int x = a + c;
+)cpp";
+  Inputs.ExtraFiles["a.h"] = guard("int a;");
+  Inputs.ExtraFiles["b.h"] = guard(R"cpp(
+#include "c.h"
+int b;
+  )cpp");
+  Inputs.ExtraFiles["c.h"] = guard("int c;");
+
+  RecordedPP PP;
+  Inputs.MakeAction = [&PP] {
+struct Hook : public SyntaxOnlyAction {
+public:
+  Hook(RecordedPP &PP) : PP(PP) {}
+  bool BeginSourceFileAction(clang::CompilerInstance &CI) override {
+CI.getPreprocessor().addPPCallbacks(PP.record(CI.getPreprocessor()));
+return true;
+  }
+
+  RecordedPP &PP;
+};
+return std::make_unique(PP);
+  };
+
+  TestAST AST(Inputs);
+  auto Decls = AST.context().getTranslationUnitDecl()->decls();
+  auto Results =
+  analyze(std::vector{Decls.begin(), Decls.end()},
+  PP.MacroReferences, PP.Includes, /*PragmaIncludes=*/nullptr,
+  AST.sourceManager(), AST.preprocessor().getHeaderSearchInfo());
+
+  const Include *B = PP.Includes.atLine(3);
+  ASSERT_EQ(B->Spelled, "b.h");
+  EXPECT_THAT(Results.Missing, ElementsAre("\"c.h\""));
+  EXPECT_THAT(Results.Unused, ElementsAre(B));
+}
+
+TEST(FixIncludes, Basic) {
+  llvm::StringRef Code = R"cpp(
+#include "a.h"
+#include "b.h"
+#include 
+)cpp";
+
+  Includes Inc;
+  Include I;
+  I.Spelled = "a.h";
+  I.Line = 2;
+  Inc.add(I);
+  I.Spelled = "b.h";
+  I.Line = 3;
+  Inc.add(I);
+  I.Spelled = "c.h";
+  I.Line = 4;
+  I.Angled = true;
+  Inc.add(I);
+
+  AnalysisResults Results;
+  Results.Missing.push_back("\"aa.h\"");
+  Results.Missing.push_back("\"ab.h\"");
+  Results.Missing.push_back("");
+  Results.Unused.push_back(Inc.atLine(3));
+  Results.Unused.push_back(Inc.atLine(4));
+
+  EXPECT_EQ(fixIncludes(Results, Code, format::getLLVMStyle()), R"cpp(
+#include "a.h"
+#include "aa.h"
+#include "ab.h"
+#include 
+)cpp");
+}
 
 } // namespace
 } // namespace clang::include_cleaner
Index: clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
===
--- clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
+++ clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "AnalysisInternal.h"
+#include "clang-include-cleaner/Analysis.h"
 #include "clang-include-cleaner/Record.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendAction.h"
@@ -46,7 +47,48 @@
 cl::cat(IncludeCleaner),
 };
 
-class HTMLReportAction : public clang::ASTFrontendAction {
+enum class PrintStyle { Changes, Final };
+cl::opt Print{
+"print",
+cl::values(
+clEnumValN(PrintStyle::Changes, "changes", "Print symbolic changes"),
+clEnumVa

[PATCH] D139013: [include-cleaner] clang-include-cleaner can print/apply edits

2022-12-02 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: 
clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h:65
+llvm::ArrayRef MacroRefs,
+const Includes &, const PragmaIncludes *PI,
+const SourceManager &SM, HeaderSearch &HS);

kadircet wrote:
> nit: name the `Includes` parameter. preferably `MainFileIncludes` (or 
> `ProvidedIncludes`)?
Added a name for consistency, but I don't think the name is actually useful 
here.

("MainFile" is inconsistent with the other parameters, and "Provided" is 
redundant for an input parameter)



Comment at: clang-tools-extra/include-cleaner/lib/Analysis.cpp:77
+ bool Satisfied = false;
+ for (const Header &H : Providers) {
+   if (H.kind() == Header::Physical && H.physical() == MainFile)

kadircet wrote:
> nit: maybe leave a comment here for skipping `Header`s we've seen before. 
> there's a quite good chance that we'll see same provider showing up multiple 
> times, skipping processing might be helpful (later on we'll probably need to 
> cache the analysis results for diagnostics purposes).
I think you're talking about a performance optimization using a cache?

We still need to process each header to compute `Satisfied`. So at most we're 
replacing a trivial comparison + 2 hashtable lookups (`Inc.match` and 
`Used.insert`) with one cache lookup. (The inner loop count is ~always <=1).

Happy with such a change if it improves a benchmark of course but my 
expectation is that it *wouldn't* (small constant factor on a fairly fast 
operation) so a FIXME seems premature here.



Comment at: clang-tools-extra/include-cleaner/lib/Analysis.cpp:111
+if (auto Edit = HI.insert(Insert.trim("<>\""), Insert.starts_with("<"))) {
+  if (PendingInsert && Edit->getOffset() == PendingInsert->getOffset()) {
+PendingInsert = tooling::Replacement(

kadircet wrote:
> this logic makes me feel a little bit uneasy, as we're relying on 
> alphabetical sorting of `Results.Missing`, which isn't just the filenames but 
> also contains `<` or `"` at the beginning.
> clang-format has weird include categories but I think it never mixes `"` 
> includes with `<` includes. so we're probably safe here.
> but it might still be safer to just keep a map of offsets to edits, up to 
> you. (having a comment at the very least would be nice)
TL;DR: replaced implementation with clang-format, tweaked signature

---

Good catch, this is completely wrong, I should capture all the edits, 
stable_sort them, and then fold together.

But this got me thinking that actually this doesn't give the correct relative 
order of inserted headers: they'll just be in whatever order I start with. I 
switched to using libFormat instead - I can't really understand from the 
implementation how it solves this problem, but it probably does, and if not 
it's the right place to fix it.

This had some knock-on effects on the API: no more messing with MemoryBuffer 
etc.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139013

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


[PATCH] D139013: [include-cleaner] clang-include-cleaner can print/apply edits

2022-12-02 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 479575.
sammccall added a comment.

delete dead code, add comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139013

Files:
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
  clang-tools-extra/include-cleaner/lib/Analysis.cpp
  clang-tools-extra/include-cleaner/lib/CMakeLists.txt
  clang-tools-extra/include-cleaner/test/Inputs/foobar.h
  clang-tools-extra/include-cleaner/test/tool.cpp
  clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
  clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
  clang/lib/Format/Format.cpp

Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -,7 +,7 @@
   // Make header insertion replacements insert new headers into correct blocks.
   tooling::Replacements NewReplaces =
   fixCppIncludeInsertions(Code, Replaces, Style);
-  return processReplacements(Cleanup, Code, NewReplaces, Style);
+  return cantFail(processReplacements(Cleanup, Code, NewReplaces, Style));
 }
 
 namespace internal {
Index: clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
@@ -18,6 +18,7 @@
 #include "clang/Tooling/Inclusions/StandardLibrary.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Testing/Support/Annotations.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
@@ -25,6 +26,7 @@
 
 namespace clang::include_cleaner {
 namespace {
+using testing::ElementsAre;
 using testing::Pair;
 using testing::UnorderedElementsAre;
 
@@ -134,6 +136,83 @@
   UnorderedElementsAre(Pair(Main.point(), UnorderedElementsAre(HdrFile;
 }
 
+TEST(Analyze, Basic) {
+  TestInputs Inputs;
+  Inputs.Code = R"cpp(
+#include "a.h"
+#include "b.h"
+
+int x = a + c;
+)cpp";
+  Inputs.ExtraFiles["a.h"] = guard("int a;");
+  Inputs.ExtraFiles["b.h"] = guard(R"cpp(
+#include "c.h"
+int b;
+  )cpp");
+  Inputs.ExtraFiles["c.h"] = guard("int c;");
+
+  RecordedPP PP;
+  Inputs.MakeAction = [&PP] {
+struct Hook : public SyntaxOnlyAction {
+public:
+  Hook(RecordedPP &PP) : PP(PP) {}
+  bool BeginSourceFileAction(clang::CompilerInstance &CI) override {
+CI.getPreprocessor().addPPCallbacks(PP.record(CI.getPreprocessor()));
+return true;
+  }
+
+  RecordedPP &PP;
+};
+return std::make_unique(PP);
+  };
+
+  TestAST AST(Inputs);
+  auto Decls = AST.context().getTranslationUnitDecl()->decls();
+  auto Results =
+  analyze(std::vector{Decls.begin(), Decls.end()},
+  PP.MacroReferences, PP.Includes, /*PragmaIncludes=*/nullptr,
+  AST.sourceManager(), AST.preprocessor().getHeaderSearchInfo());
+
+  const Include *B = PP.Includes.atLine(3);
+  ASSERT_EQ(B->Spelled, "b.h");
+  EXPECT_THAT(Results.Missing, ElementsAre("\"c.h\""));
+  EXPECT_THAT(Results.Unused, ElementsAre(B));
+}
+
+TEST(FixIncludes, Basic) {
+  llvm::StringRef Code = R"cpp(
+#include "a.h"
+#include "b.h"
+#include 
+)cpp";
+
+  Includes Inc;
+  Include I;
+  I.Spelled = "a.h";
+  I.Line = 2;
+  Inc.add(I);
+  I.Spelled = "b.h";
+  I.Line = 3;
+  Inc.add(I);
+  I.Spelled = "c.h";
+  I.Line = 4;
+  I.Angled = true;
+  Inc.add(I);
+
+  AnalysisResults Results;
+  Results.Missing.push_back("\"aa.h\"");
+  Results.Missing.push_back("\"ab.h\"");
+  Results.Missing.push_back("");
+  Results.Unused.push_back(Inc.atLine(3));
+  Results.Unused.push_back(Inc.atLine(4));
+
+  EXPECT_EQ(fixIncludes(Results, Code, format::getLLVMStyle()), R"cpp(
+#include "a.h"
+#include "aa.h"
+#include "ab.h"
+#include 
+)cpp");
+}
 
 } // namespace
 } // namespace clang::include_cleaner
Index: clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
===
--- clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
+++ clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "AnalysisInternal.h"
+#include "clang-include-cleaner/Analysis.h"
 #include "clang-include-cleaner/Record.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendAction.h"
@@ -46,7 +47,48 @@
 cl::cat(IncludeCleaner),
 };
 
-class HTMLReportAction : public clang::ASTFrontendAction {
+enum class PrintStyle { Changes, Final };
+cl::opt Print{
+"print",
+cl::values(
+clEnumValN(PrintStyle::Changes, "changes", "Print symbolic changes"),
+clEnumValN(PrintStyle::Final, "", "Print final code")),
+cl::ValueOptional,
+cl::init(PrintStyle::Fin

[PATCH] D136078: Use-after-return sanitizer binary metadata

2022-12-02 Thread Marco Elver via Phabricator via cfe-commits
melver added a comment.



>> Do you have any other ideas on how to dead with this?
>
> It's strange we've not encountered this elsewhere - this must be some special 
> (old?) linker. I'll investigate...

GNU ld <= 2.35 does not support mixed SHF_LINK_ORDER and non-SHF_LINK_ORDER 
sections.

This is about the relative w.r.t. other sections when the linker merges the 
sections. From what I can find, we need to retain SHF_LINK_ORDER to support 
gc-sections properly.

This is a good summary: 
https://maskray.me/blog/2021-01-31-metadata-sections-comdat-and-shf-link-order
@MaskRay

I'm going to try and see how I can add the SHF_LINK_ORDER attribute to the 
section output for the dummy variable.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136078

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


[PATCH] D139125: [clang] Correctly handle by-reference capture with an initializer that is a pack expansion in lambdas.

2022-12-02 Thread Jens Massberg via Phabricator via cfe-commits
massberg updated this revision to Diff 479579.
massberg added a comment.

Add a diagnostics test for pack expansions to check if args are passed by 
reference and not by value.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139125

Files:
  clang/lib/Sema/TreeTransform.h
  clang/test/SemaCXX/lambda-pack-expansion.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp


Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -2306,6 +2306,30 @@
   hasName("cc"), hasInitializer(integerLiteral(equals(1));
 }
 
+TEST_P(ASTMatchersTest, LambdaCaptureTest_BindsToCaptureOfReferenceType) {
+  if (!GetParam().isCXX20OrLater()) {
+return;
+  }
+  auto matcher = lambdaExpr(hasAnyCapture(
+  lambdaCapture(capturesVar(varDecl(hasType(referenceType()));
+  EXPECT_TRUE(matches("template  void f(T &...args) {"
+  "  [&...args = args] () mutable {"
+  "  }();"
+  "}"
+  "int main() {"
+  "  int a;"
+  "  f(a);"
+  "}", matcher));
+  EXPECT_FALSE(matches("template  void f(T &...args) {"
+   "  [...args = args] () mutable {"
+   "  }();"
+   "}"
+   "int main() {"
+   "  int a;"
+   "  f(a);"
+   "}", matcher));
+}
+
 TEST(ASTMatchersTestObjC, ObjCMessageCalees) {
   StatementMatcher MessagingFoo =
   objcMessageExpr(callee(objcMethodDecl(hasName("foo";
Index: clang/test/SemaCXX/lambda-pack-expansion.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/lambda-pack-expansion.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -std=c++20 -Wno-unused-value -fsyntax-only -verify %s
+
+namespace std { class type_info; };
+
+namespace GH49266 {
+struct X {
+  X() = default;
+  X(X const&) = delete; // expected-note {{'X' has been explicitly marked 
deleted here}}
+};
+
+void take_by_copy(auto &...args) {
+  [...args = args] {}(); // expected-error {{call to deleted constructor}}
+}
+
+void take_by_ref(auto &...args) {
+  [&...args = args] {}(); // args is passed by reference and not copied.
+}
+
+void foo() {
+  X x;
+  take_by_copy(x); // expected-note {{in instantiation of function template 
specialization}}
+  take_by_ref(x);
+}
+}
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -13145,9 +13145,15 @@
   }
   Expr *NewExprInit = NewExprInitResult.get();
 
+  bool isReferenceType = (isa(OldVD->getType())
+  ? cast(OldVD->getType())
+->getPattern()
+->isReferenceType()
+  : OldVD->getType()->isReferenceType());
+
   QualType NewInitCaptureType =
   getSema().buildLambdaInitCaptureInitialization(
-  C->getLocation(), OldVD->getType()->isReferenceType(),
+  C->getLocation(), isReferenceType,
   EllipsisLoc, NumExpansions, OldVD->getIdentifier(),
   cast(C->getCapturedVar())->getInitStyle() !=
   VarDecl::CInit,


Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -2306,6 +2306,30 @@
   hasName("cc"), hasInitializer(integerLiteral(equals(1));
 }
 
+TEST_P(ASTMatchersTest, LambdaCaptureTest_BindsToCaptureOfReferenceType) {
+  if (!GetParam().isCXX20OrLater()) {
+return;
+  }
+  auto matcher = lambdaExpr(hasAnyCapture(
+  lambdaCapture(capturesVar(varDecl(hasType(referenceType()));
+  EXPECT_TRUE(matches("template  void f(T &...args) {"
+  "  [&...args = args] () mutable {"
+  "  }();"
+  "}"
+  "int main() {"
+  "  int a;"
+  "  f(a);"
+  "}", matcher));
+  EXPECT_FALSE(matches("template  void f(T &...args) {"
+   "  [...args = args] () mutable {"
+   "  }();"
+   "}"
+   "int main() {"
+   "  int a;"
+   "  f(a);"
+   "}", matcher));
+}
+
 TEST(ASTMatchersTestObjC, ObjCMessageCalees) {
   StatementMatcher MessagingFoo =
   objcMessageExpr(callee(objcMethodDecl

[PATCH] D139013: [include-cleaner] clang-include-cleaner can print/apply edits

2022-12-02 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added a comment.

thanks!




Comment at: clang-tools-extra/include-cleaner/lib/Analysis.cpp:77
+ bool Satisfied = false;
+ for (const Header &H : Providers) {
+   if (H.kind() == Header::Physical && H.physical() == MainFile)

sammccall wrote:
> kadircet wrote:
> > nit: maybe leave a comment here for skipping `Header`s we've seen before. 
> > there's a quite good chance that we'll see same provider showing up 
> > multiple times, skipping processing might be helpful (later on we'll 
> > probably need to cache the analysis results for diagnostics purposes).
> I think you're talking about a performance optimization using a cache?
> 
> We still need to process each header to compute `Satisfied`. So at most we're 
> replacing a trivial comparison + 2 hashtable lookups (`Inc.match` and 
> `Used.insert`) with one cache lookup. (The inner loop count is ~always <=1).
> 
> Happy with such a change if it improves a benchmark of course but my 
> expectation is that it *wouldn't* (small constant factor on a fairly fast 
> operation) so a FIXME seems premature here.
> We still need to process each header to compute Satisfied

but we need to do this only once per unique `Providers` across all the 
callbacks (e.g. we'll get `Foo.h` as a provider for every reference of `Foo` 
and `createFoo` in the main file). From header analysis point of view, i don't 
think we need to treat each of these Providers specially based on the nature of 
the reference (neither the symbol nor the reference location/type).

> So at most we're replacing a trivial comparison + 2 hashtable lookups 
> (Inc.match and Used.insert) with one cache lookup. (The inner loop count is 
> ~always <=1).

Yeah I guess you're right. I was treating the inner-loop as going over all the 
includes in the main file, but in practice it's just a bunch of lookups into a 
hashtable and operating over a single include.

> Happy with such a change if it improves a benchmark of course but my 
> expectation is that it *wouldn't* (small constant factor on a fairly fast 
> operation) so a FIXME seems premature here.

no need. agreed that it is unlikely to make a difference. and if it would, it's 
probably better to write this in a way that'll de-duplicate Providers across 
references  with some bucketing over reftypes and process all of them once.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139013

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


[PATCH] D139125: [clang] Correctly handle by-reference capture with an initializer that is a pack expansion in lambdas.

2022-12-02 Thread Jens Massberg via Phabricator via cfe-commits
massberg updated this revision to Diff 479581.
massberg added a comment.

Remove unnecessary code from test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139125

Files:
  clang/lib/Sema/TreeTransform.h
  clang/test/SemaCXX/lambda-pack-expansion.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp


Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -2306,6 +2306,30 @@
   hasName("cc"), hasInitializer(integerLiteral(equals(1));
 }
 
+TEST_P(ASTMatchersTest, LambdaCaptureTest_BindsToCaptureOfReferenceType) {
+  if (!GetParam().isCXX20OrLater()) {
+return;
+  }
+  auto matcher = lambdaExpr(hasAnyCapture(
+  lambdaCapture(capturesVar(varDecl(hasType(referenceType()));
+  EXPECT_TRUE(matches("template  void f(T &...args) {"
+  "  [&...args = args] () mutable {"
+  "  }();"
+  "}"
+  "int main() {"
+  "  int a;"
+  "  f(a);"
+  "}", matcher));
+  EXPECT_FALSE(matches("template  void f(T &...args) {"
+   "  [...args = args] () mutable {"
+   "  }();"
+   "}"
+   "int main() {"
+   "  int a;"
+   "  f(a);"
+   "}", matcher));
+}
+
 TEST(ASTMatchersTestObjC, ObjCMessageCalees) {
   StatementMatcher MessagingFoo =
   objcMessageExpr(callee(objcMethodDecl(hasName("foo";
Index: clang/test/SemaCXX/lambda-pack-expansion.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/lambda-pack-expansion.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -std=c++20 -Wno-unused-value -fsyntax-only -verify %s
+
+namespace GH49266 {
+struct X {
+  X() = default;
+  X(X const&) = delete; // expected-note {{'X' has been explicitly marked 
deleted here}}
+};
+
+void take_by_copy(auto &...args) {
+  [...args = args] {}(); // expected-error {{call to deleted constructor}}
+}
+
+void take_by_ref(auto &...args) {
+  [&...args = args] {}(); // args is passed by reference and not copied.
+}
+
+void foo() {
+  X x;
+  take_by_copy(x); // expected-note {{in instantiation of function template 
specialization}}
+  take_by_ref(x);
+}
+}
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -13145,9 +13145,15 @@
   }
   Expr *NewExprInit = NewExprInitResult.get();
 
+  bool isReferenceType = (isa(OldVD->getType())
+  ? cast(OldVD->getType())
+->getPattern()
+->isReferenceType()
+  : OldVD->getType()->isReferenceType());
+
   QualType NewInitCaptureType =
   getSema().buildLambdaInitCaptureInitialization(
-  C->getLocation(), OldVD->getType()->isReferenceType(),
+  C->getLocation(), isReferenceType,
   EllipsisLoc, NumExpansions, OldVD->getIdentifier(),
   cast(C->getCapturedVar())->getInitStyle() !=
   VarDecl::CInit,


Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -2306,6 +2306,30 @@
   hasName("cc"), hasInitializer(integerLiteral(equals(1));
 }
 
+TEST_P(ASTMatchersTest, LambdaCaptureTest_BindsToCaptureOfReferenceType) {
+  if (!GetParam().isCXX20OrLater()) {
+return;
+  }
+  auto matcher = lambdaExpr(hasAnyCapture(
+  lambdaCapture(capturesVar(varDecl(hasType(referenceType()));
+  EXPECT_TRUE(matches("template  void f(T &...args) {"
+  "  [&...args = args] () mutable {"
+  "  }();"
+  "}"
+  "int main() {"
+  "  int a;"
+  "  f(a);"
+  "}", matcher));
+  EXPECT_FALSE(matches("template  void f(T &...args) {"
+   "  [...args = args] () mutable {"
+   "  }();"
+   "}"
+   "int main() {"
+   "  int a;"
+   "  f(a);"
+   "}", matcher));
+}
+
 TEST(ASTMatchersTestObjC, ObjCMessageCalees) {
   StatementMatcher MessagingFoo =
   objcMessageExpr(callee(objcMethodDecl(hasName("foo";
Index: clang/test/SemaCXX/lambda-pack-expansion.cpp
===

[PATCH] D135750: [clang][Interp] Track initialization state of local variables

2022-12-02 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 479582.
tbaeder marked an inline comment as done.

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

https://reviews.llvm.org/D135750

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeStmtGen.cpp
  clang/lib/AST/Interp/Context.cpp
  clang/lib/AST/Interp/Descriptor.cpp
  clang/lib/AST/Interp/Descriptor.h
  clang/lib/AST/Interp/EvalEmitter.cpp
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/InterpBlock.h
  clang/lib/AST/Interp/InterpFrame.cpp
  clang/lib/AST/Interp/InterpFrame.h
  clang/lib/AST/Interp/Pointer.cpp
  clang/lib/AST/Interp/Pointer.h
  clang/lib/AST/Interp/Program.cpp
  clang/lib/AST/Interp/Program.h
  clang/test/AST/Interp/cxx20.cpp
  clang/test/AST/Interp/literals.cpp
  clang/test/AST/Interp/loops.cpp

Index: clang/test/AST/Interp/loops.cpp
===
--- clang/test/AST/Interp/loops.cpp
+++ clang/test/AST/Interp/loops.cpp
@@ -5,6 +5,7 @@
 
 // ref-no-diagnostics
 // expected-no-diagnostics
+// expected-cpp20-no-diagnostics
 
 namespace WhileLoop {
   constexpr int f() {
@@ -165,8 +166,6 @@
   static_assert(f5(true) == 8, "");
   static_assert(f5(false) == 5, "");
 
-  /// FIXME: This should be accepted in C++20 but is currently being rejected
-  ///   because the variable declaration doesn't have an initializier.
 #if __cplusplus >= 202002L
   constexpr int f6() {
 int i;
@@ -176,7 +175,7 @@
 } while (true);
 return i;
   }
-  static_assert(f6() == 5, ""); // expected-cpp20-error {{not an integral constant}}
+  static_assert(f6() == 5, "");
 #endif
 
 #if 0
Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -407,8 +407,7 @@
 return 1;
   }
   static_assert(uninit(), ""); // ref-error {{not an integral constant expression}} \
-   // ref-note {{in call to 'uninit()'}} \
-   // expected-error {{not an integral constant expression}}
+   // ref-note {{in call to 'uninit()'}}
 
   constexpr int OverFlow() { // ref-error {{never produces a constant expression}}
 int a = INT_MAX;
Index: clang/test/AST/Interp/cxx20.cpp
===
--- clang/test/AST/Interp/cxx20.cpp
+++ clang/test/AST/Interp/cxx20.cpp
@@ -56,33 +56,51 @@
 }
 static_assert(pointerAssign2() == 12, "");
 
-
 constexpr int unInitLocal() {
   int a;
-  return a; // ref-note{{read of uninitialized object}}
+  return a; // ref-note {{read of uninitialized object}} \
+// expected-note {{read of object outside its lifetime}}
+// FIXME: ^^^ Wrong diagnostic.
 }
-static_assert(unInitLocal() == 0, ""); // expected-error {{not an integral constant expression}} \
-   // ref-error {{not an integral constant expression}} \
-   // ref-note {{in call to 'unInitLocal()'}}
-
-/// TODO: The example above is correctly rejected by the new constexpr
-///   interpreter, but for the wrong reasons. We don't reject it because
-///   it is an uninitialized read, we reject it simply because
-///   the local variable does not have an initializer.
-///
-///   The code below should be accepted but is also being rejected
-///   right now.
-#if 0
+static_assert(unInitLocal() == 0, ""); // ref-error {{not an integral constant expression}} \
+   // ref-note {{in call to 'unInitLocal()'}} \
+   // expected-error {{not an integral constant expression}} \
+   // expected-note {{in call to 'unInitLocal()'}} \
+
 constexpr int initializedLocal() {
   int a;
-  int b;
-
   a = 20;
   return a;
 }
 static_assert(initializedLocal() == 20);
 
-/// Similar here, but the uninitialized local is passed as a function parameter.
+constexpr int initializedLocal2() {
+  int a[2];
+  return *a; // expected-note {{read of object outside its lifetime}} \
+ // ref-note {{read of uninitialized object is not allowed in a constant expression}}
+}
+static_assert(initializedLocal2() == 20); // expected-error {{not an integral constant expression}} \
+  // expected-note {{in call to}} \
+  // ref-error {{not an integral constant expression}} \
+  // ref-note {{in call to}}
+
+
+struct Int { int a; };
+constexpr int initializedLocal3() {
+  Int i;
+  return i.a; // expected-note {{read of object outside its lifetime}} \
+  // ref-note {{read of uninitialized object is not allowed in a constant expression}}
+}
+static_assert(initializedLocal3() == 20); // expected-error {{not an integral constant expression}} \
+ 

[PATCH] D139188: [Draft] Sanitize clang target triple

2022-12-02 Thread serge via Phabricator via cfe-commits
serge-sans-paille created this revision.
serge-sans-paille added a reviewer: aaron.ballman.
Herald added a project: All.
serge-sans-paille requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Warn when meeting an unknown vendor / os / environment


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139188

Files:
  clang/include/clang/Basic/DiagnosticCommonKinds.td
  clang/lib/Basic/Targets.cpp


Index: clang/lib/Basic/Targets.cpp
===
--- clang/lib/Basic/Targets.cpp
+++ clang/lib/Basic/Targets.cpp
@@ -691,6 +691,25 @@
 } // namespace targets
 } // namespace clang
 
+
+static
+void CheckTriple(DiagnosticsEngine &Diags, llvm::Triple const& Triple)
+{
+  auto IsUnrecognizedValue = [](StringRef Value) {
+return !Value.empty() && Value != "unknown" && Value != "none";
+  };
+
+  if (Triple.getVendor() == llvm::Triple::UnknownVendor &&
+  IsUnrecognizedValue(Triple.getVendorName()))
+Diags.Report(diag::warn_target_unknown_triple_components) << "vendor" << 
Triple.getVendorName();
+  if (Triple.getOS() == llvm::Triple::UnknownOS &&
+  IsUnrecognizedValue(Triple.getOSName()))
+Diags.Report(diag::warn_target_unknown_triple_components) << "os" << 
Triple.getOSName();
+  if (Triple.getEnvironment() == llvm::Triple::UnknownEnvironment &&
+  IsUnrecognizedValue(Triple.getEnvironmentName()))
+Diags.Report(diag::warn_target_unknown_triple_components) << "environment" 
<< Triple.getEnvironmentName();
+}
+
 using namespace clang::targets;
 /// CreateTargetInfo - Return the target info object for the specified target
 /// options.
@@ -707,6 +726,9 @@
   }
   Target->TargetOpts = Opts;
 
+  // Check after we created the target has it only raises warnings.
+  CheckTriple(Diags, Triple);
+
   // Set the target CPU if specified.
   if (!Opts->CPU.empty() && !Target->setCPU(Opts->CPU)) {
 Diags.Report(diag::err_target_unknown_cpu) << Opts->CPU;
Index: clang/include/clang/Basic/DiagnosticCommonKinds.td
===
--- clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -297,6 +297,8 @@
 
 // Targets
 
+def warn_target_unknown_triple_components : Warning<
+  "unknown triple %0 '%1'">;
 def err_target_unknown_triple : Error<
   "unknown target triple '%0', please use -triple or -arch">;
 def err_target_unknown_cpu : Error<"unknown target CPU '%0'">;


Index: clang/lib/Basic/Targets.cpp
===
--- clang/lib/Basic/Targets.cpp
+++ clang/lib/Basic/Targets.cpp
@@ -691,6 +691,25 @@
 } // namespace targets
 } // namespace clang
 
+
+static
+void CheckTriple(DiagnosticsEngine &Diags, llvm::Triple const& Triple)
+{
+  auto IsUnrecognizedValue = [](StringRef Value) {
+return !Value.empty() && Value != "unknown" && Value != "none";
+  };
+
+  if (Triple.getVendor() == llvm::Triple::UnknownVendor &&
+  IsUnrecognizedValue(Triple.getVendorName()))
+Diags.Report(diag::warn_target_unknown_triple_components) << "vendor" << Triple.getVendorName();
+  if (Triple.getOS() == llvm::Triple::UnknownOS &&
+  IsUnrecognizedValue(Triple.getOSName()))
+Diags.Report(diag::warn_target_unknown_triple_components) << "os" << Triple.getOSName();
+  if (Triple.getEnvironment() == llvm::Triple::UnknownEnvironment &&
+  IsUnrecognizedValue(Triple.getEnvironmentName()))
+Diags.Report(diag::warn_target_unknown_triple_components) << "environment" << Triple.getEnvironmentName();
+}
+
 using namespace clang::targets;
 /// CreateTargetInfo - Return the target info object for the specified target
 /// options.
@@ -707,6 +726,9 @@
   }
   Target->TargetOpts = Opts;
 
+  // Check after we created the target has it only raises warnings.
+  CheckTriple(Diags, Triple);
+
   // Set the target CPU if specified.
   if (!Opts->CPU.empty() && !Target->setCPU(Opts->CPU)) {
 Diags.Report(diag::err_target_unknown_cpu) << Opts->CPU;
Index: clang/include/clang/Basic/DiagnosticCommonKinds.td
===
--- clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -297,6 +297,8 @@
 
 // Targets
 
+def warn_target_unknown_triple_components : Warning<
+  "unknown triple %0 '%1'">;
 def err_target_unknown_triple : Error<
   "unknown target triple '%0', please use -triple or -arch">;
 def err_target_unknown_cpu : Error<"unknown target CPU '%0'">;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139188: [Draft] Sanitize clang target triple

2022-12-02 Thread serge via Phabricator via cfe-commits
serge-sans-paille added a comment.

This is a tentative patch for 
https://discourse.llvm.org/t/linking-without-gcc-on-gnu-linux/66428/3 
unfortunately it appears that many triples are not recognized while widely used 
(at least in the CI) for instance `aarch64-arm-none-eabi` is used a lot in the 
testsuite but `arm` is not a registered vendor... Any thoughts?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139188

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


[PATCH] D135750: [clang][Interp] Track initialization state of local variables

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



Comment at: clang/lib/AST/Interp/Descriptor.h:73
+  /// Flag indicating if the field is mutable (if in a record).
+  unsigned IsMutable : 1;
+

shafik wrote:
> Maybe `IsFieldMutable` b/c we call `CreateDescriptor` it is a little 
> confusing why we have `IsConst` and `IsMutable`
Agreed, but this code was just moved up in this patch, the field was introduced 
earlier.



Comment at: clang/lib/AST/Interp/Pointer.h:63-64
 private:
   static constexpr unsigned PastEndMark = (unsigned)-1;
   static constexpr unsigned RootPtrMark = (unsigned)-1;
 

shafik wrote:
> or `-1u`  
Alright, but those were not introduced in this patch.


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

https://reviews.llvm.org/D135750

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


[PATCH] D138655: [clang-tidy] Fix `cppcoreguidelines-init-variables` for invalid vardecl

2022-12-02 Thread gehry via Phabricator via cfe-commits
Sockke added a comment.

Friendly ping.


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

https://reviews.llvm.org/D138655

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


[PATCH] D139167: [clang][Windows]Ignore Options '/d1nodatetime' and '/d1import_no_registry'

2022-12-02 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

I hadn't seen `/d1` flags before. I suppose they relate to preprocessor stuff 
as opposed to `/d2` flags.

I think the "Unsupported" section below may be better for these. In that case 
clang-cl will parse the option and warn that it's ignoring it. On line 6931 
there's a catch-all for all flags starting with "d2". Perhaps we should add one 
for "d1" too?

Also, please add these to the "Unsupported but parsed options" tests in 
clang/test/Driver/cl-options.c


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139167

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


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

2022-12-02 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

@erichkeane Let me know if you have any insights on that constraint checking 
issue.
I might add a way to get from the CXXRecordDecl to the LambdaExpr and add the 
captures to the instantiation scope during constraint checking that way, but 
I'd love your opinion before going that direction. Thanks!


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] D139013: [include-cleaner] clang-include-cleaner can print/apply edits

2022-12-02 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/include-cleaner/lib/Analysis.cpp:77
+ bool Satisfied = false;
+ for (const Header &H : Providers) {
+   if (H.kind() == Header::Physical && H.physical() == MainFile)

kadircet wrote:
> sammccall wrote:
> > kadircet wrote:
> > > nit: maybe leave a comment here for skipping `Header`s we've seen before. 
> > > there's a quite good chance that we'll see same provider showing up 
> > > multiple times, skipping processing might be helpful (later on we'll 
> > > probably need to cache the analysis results for diagnostics purposes).
> > I think you're talking about a performance optimization using a cache?
> > 
> > We still need to process each header to compute `Satisfied`. So at most 
> > we're replacing a trivial comparison + 2 hashtable lookups (`Inc.match` and 
> > `Used.insert`) with one cache lookup. (The inner loop count is ~always <=1).
> > 
> > Happy with such a change if it improves a benchmark of course but my 
> > expectation is that it *wouldn't* (small constant factor on a fairly fast 
> > operation) so a FIXME seems premature here.
> > We still need to process each header to compute Satisfied
> 
> but we need to do this only once per unique `Providers` across all the 
> callbacks (e.g. we'll get `Foo.h` as a provider for every reference of `Foo` 
> and `createFoo` in the main file). From header analysis point of view, i 
> don't think we need to treat each of these Providers specially based on the 
> nature of the reference (neither the symbol nor the reference location/type).
> 
> > So at most we're replacing a trivial comparison + 2 hashtable lookups 
> > (Inc.match and Used.insert) with one cache lookup. (The inner loop count is 
> > ~always <=1).
> 
> Yeah I guess you're right. I was treating the inner-loop as going over all 
> the includes in the main file, but in practice it's just a bunch of lookups 
> into a hashtable and operating over a single include.
> 
> > Happy with such a change if it improves a benchmark of course but my 
> > expectation is that it *wouldn't* (small constant factor on a fairly fast 
> > operation) so a FIXME seems premature here.
> 
> no need. agreed that it is unlikely to make a difference. and if it would, 
> it's probably better to write this in a way that'll de-duplicate Providers 
> across references  with some bucketing over reftypes and process all of them 
> once.
> but we need to do this only once per unique Providers across all the 
> callbacks (e.g. we'll get Foo.h as a provider for every reference of Foo and 
> createFoo in the main file)

By "process" I mean we need to at least look up into the cache.
That's pretty trivial, but we're not doing much more at the moment.

> but in practice it's just a bunch of lookups into a hashtable

in fact just one lookup!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139013

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


[clang-tools-extra] 1a8dd74 - [include-cleaner] clang-include-cleaner can print/apply edits

2022-12-02 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2022-12-02T13:16:58+01:00
New Revision: 1a8dd7425873fae55a38cbdb41cccb1f17c82e8c

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

LOG: [include-cleaner] clang-include-cleaner can print/apply edits

This adds command-line flags to the tool:
+ -print: prints changed source code
+ -print=changes: prints headers added/removed
+ -edit: rewrites code in place
+ -insert=0/-remove=0: disables additions/deletions for the above

These are supported by a couple of new functions dumped into Analysis:
analyze() sits on top of walkUsed and makes used/unused decisions for
Includes. fixIncludes() applies those results to source code.

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

Added: 
clang-tools-extra/include-cleaner/test/Inputs/foobar.h
clang-tools-extra/include-cleaner/test/tool.cpp

Modified: 
clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
clang-tools-extra/include-cleaner/lib/Analysis.cpp
clang-tools-extra/include-cleaner/lib/CMakeLists.txt
clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
clang/lib/Format/Format.cpp

Removed: 




diff  --git 
a/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h 
b/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
index 31ae7592ceec0..146c652f730de 100644
--- a/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
+++ b/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
@@ -13,14 +13,21 @@
 
 #include "clang-include-cleaner/Record.h"
 #include "clang-include-cleaner/Types.h"
+#include "clang/Format/Format.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/STLFunctionalExtras.h"
+#include "llvm/Support/MemoryBufferRef.h"
 #include 
 
 namespace clang {
 class SourceLocation;
 class Decl;
 class FileEntry;
+class HeaderSearch;
+namespace tooling {
+class Replacements;
+struct IncludeStyle;
+} // namespace tooling
 namespace include_cleaner {
 
 /// A UsedSymbolCB is a callback invoked for each symbol reference seen.
@@ -47,6 +54,24 @@ void walkUsed(llvm::ArrayRef ASTRoots,
   llvm::ArrayRef MacroRefs,
   const PragmaIncludes *PI, const SourceManager &, UsedSymbolCB 
CB);
 
+struct AnalysisResults {
+  std::vector Unused;
+  std::vector Missing; // Spellings, like ""
+};
+
+/// Determine which headers should be inserted or removed from the main file.
+/// This exposes conclusions but not reasons: use lower-level walkUsed for 
that.
+AnalysisResults analyze(llvm::ArrayRef ASTRoots,
+llvm::ArrayRef MacroRefs,
+const Includes &I, const PragmaIncludes *PI,
+const SourceManager &SM, HeaderSearch &HS);
+
+/// Removes unused includes and inserts missing ones in the main file.
+/// Returns the modified main-file code.
+/// The FormatStyle must be C++ or ObjC (to support include ordering).
+std::string fixIncludes(const AnalysisResults &Results, llvm::StringRef Code,
+const format::FormatStyle &IncludeStyle);
+
 } // namespace include_cleaner
 } // namespace clang
 

diff  --git a/clang-tools-extra/include-cleaner/lib/Analysis.cpp 
b/clang-tools-extra/include-cleaner/lib/Analysis.cpp
index 0f96ae26f51c5..c83b4d5a25be0 100644
--- a/clang-tools-extra/include-cleaner/lib/Analysis.cpp
+++ b/clang-tools-extra/include-cleaner/lib/Analysis.cpp
@@ -11,6 +11,10 @@
 #include "clang-include-cleaner/Types.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/Basic/SourceManager.h"
+#include "clang/Format/Format.h"
+#include "clang/Lex/HeaderSearch.h"
+#include "clang/Tooling/Core/Replacement.h"
+#include "clang/Tooling/Inclusions/HeaderIncludes.h"
 #include "clang/Tooling/Inclusions/StandardLibrary.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/SmallVector.h"
@@ -42,4 +46,69 @@ void walkUsed(llvm::ArrayRef ASTRoots,
   }
 }
 
+static std::string spellHeader(const Header &H, HeaderSearch &HS,
+   const FileEntry *Main) {
+  switch (H.kind()) {
+  case Header::Physical: {
+bool IsSystem = false;
+std::string Path = HS.suggestPathToFileForDiagnostics(
+H.physical(), Main->tryGetRealPathName(), &IsSystem);
+return IsSystem ? "<" + Path + ">" : "\"" + Path + "\"";
+  }
+  case Header::Standard:
+return H.standard().name().str();
+  case Header::Verbatim:
+return H.verbatim().str();
+  }
+  llvm_unreachable("Unknown Header kind");
+}
+
+AnalysisResults analyze(llvm::ArrayRef ASTRoots,
+llvm::ArrayRef MacroRefs,
+const Includes &Inc, const PragmaIncludes *PI,
+const SourceManage

[PATCH] D139013: [include-cleaner] clang-include-cleaner can print/apply edits

2022-12-02 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.
Closed by commit rG1a8dd7425873: [include-cleaner] clang-include-cleaner can 
print/apply edits (authored by sammccall).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139013

Files:
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
  clang-tools-extra/include-cleaner/lib/Analysis.cpp
  clang-tools-extra/include-cleaner/lib/CMakeLists.txt
  clang-tools-extra/include-cleaner/test/Inputs/foobar.h
  clang-tools-extra/include-cleaner/test/tool.cpp
  clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
  clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
  clang/lib/Format/Format.cpp

Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -,7 +,7 @@
   // Make header insertion replacements insert new headers into correct blocks.
   tooling::Replacements NewReplaces =
   fixCppIncludeInsertions(Code, Replaces, Style);
-  return processReplacements(Cleanup, Code, NewReplaces, Style);
+  return cantFail(processReplacements(Cleanup, Code, NewReplaces, Style));
 }
 
 namespace internal {
Index: clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
@@ -18,6 +18,7 @@
 #include "clang/Tooling/Inclusions/StandardLibrary.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Testing/Support/Annotations.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
@@ -25,6 +26,7 @@
 
 namespace clang::include_cleaner {
 namespace {
+using testing::ElementsAre;
 using testing::Pair;
 using testing::UnorderedElementsAre;
 
@@ -134,6 +136,83 @@
   UnorderedElementsAre(Pair(Main.point(), UnorderedElementsAre(HdrFile;
 }
 
+TEST(Analyze, Basic) {
+  TestInputs Inputs;
+  Inputs.Code = R"cpp(
+#include "a.h"
+#include "b.h"
+
+int x = a + c;
+)cpp";
+  Inputs.ExtraFiles["a.h"] = guard("int a;");
+  Inputs.ExtraFiles["b.h"] = guard(R"cpp(
+#include "c.h"
+int b;
+  )cpp");
+  Inputs.ExtraFiles["c.h"] = guard("int c;");
+
+  RecordedPP PP;
+  Inputs.MakeAction = [&PP] {
+struct Hook : public SyntaxOnlyAction {
+public:
+  Hook(RecordedPP &PP) : PP(PP) {}
+  bool BeginSourceFileAction(clang::CompilerInstance &CI) override {
+CI.getPreprocessor().addPPCallbacks(PP.record(CI.getPreprocessor()));
+return true;
+  }
+
+  RecordedPP &PP;
+};
+return std::make_unique(PP);
+  };
+
+  TestAST AST(Inputs);
+  auto Decls = AST.context().getTranslationUnitDecl()->decls();
+  auto Results =
+  analyze(std::vector{Decls.begin(), Decls.end()},
+  PP.MacroReferences, PP.Includes, /*PragmaIncludes=*/nullptr,
+  AST.sourceManager(), AST.preprocessor().getHeaderSearchInfo());
+
+  const Include *B = PP.Includes.atLine(3);
+  ASSERT_EQ(B->Spelled, "b.h");
+  EXPECT_THAT(Results.Missing, ElementsAre("\"c.h\""));
+  EXPECT_THAT(Results.Unused, ElementsAre(B));
+}
+
+TEST(FixIncludes, Basic) {
+  llvm::StringRef Code = R"cpp(
+#include "a.h"
+#include "b.h"
+#include 
+)cpp";
+
+  Includes Inc;
+  Include I;
+  I.Spelled = "a.h";
+  I.Line = 2;
+  Inc.add(I);
+  I.Spelled = "b.h";
+  I.Line = 3;
+  Inc.add(I);
+  I.Spelled = "c.h";
+  I.Line = 4;
+  I.Angled = true;
+  Inc.add(I);
+
+  AnalysisResults Results;
+  Results.Missing.push_back("\"aa.h\"");
+  Results.Missing.push_back("\"ab.h\"");
+  Results.Missing.push_back("");
+  Results.Unused.push_back(Inc.atLine(3));
+  Results.Unused.push_back(Inc.atLine(4));
+
+  EXPECT_EQ(fixIncludes(Results, Code, format::getLLVMStyle()), R"cpp(
+#include "a.h"
+#include "aa.h"
+#include "ab.h"
+#include 
+)cpp");
+}
 
 } // namespace
 } // namespace clang::include_cleaner
Index: clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
===
--- clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
+++ clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "AnalysisInternal.h"
+#include "clang-include-cleaner/Analysis.h"
 #include "clang-include-cleaner/Record.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendAction.h"
@@ -46,7 +47,48 @@
 cl::cat(IncludeCleaner),
 };
 
-class HTMLReportAction : public clang::ASTFrontendAction {
+enum class PrintStyle { Changes, Final };
+cl::opt Print{
+"print",
+cl::values(
+clEnumValN(PrintStyle::Changes, "changes", "

[PATCH] D139172: [clang] Mark CWG554 as N/A

2022-12-02 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin accepted this revision.
cor3ntin added a comment.
This revision is now accepted and ready to land.

LGTM.
There are many editorial issues that ended up as defect reports, you could 
probably batch many of them in subsequent PR


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139172

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


[PATCH] D139167: [clang][Windows]Ignore Options '/d1nodatetime' and '/d1import_no_registry'

2022-12-02 Thread Qfrost via Phabricator via cfe-commits
Qfrost911 updated this revision to Diff 479594.
Qfrost911 added a comment.

Ok, I updated this patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139167

Files:
  clang/include/clang/Driver/Options.td
  clang/test/Driver/cl-options.c


Index: clang/test/Driver/cl-options.c
===
--- clang/test/Driver/cl-options.c
+++ clang/test/Driver/cl-options.c
@@ -426,6 +426,8 @@
 // RUN: /Bt \
 // RUN: /Bt+ \
 // RUN: /clr:pure \
+// RUN: /d1import_no_registry \
+// RUN: /d1nodatetime \
 // RUN: /d2FH4 \
 // RUN: /docname \
 // RUN: /experimental:external \
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -6925,6 +6925,7 @@
 def _SLASH_Bt : CLFlag<"Bt">;
 def _SLASH_Bt_plus : CLFlag<"Bt+">;
 def _SLASH_clr : CLJoined<"clr">;
+def _SLASH_d1 : CLJoined<"d1">;
 def _SLASH_d2 : CLJoined<"d2">;
 def _SLASH_doc : CLJoined<"doc">;
 def _SLASH_experimental : CLJoined<"experimental:">;


Index: clang/test/Driver/cl-options.c
===
--- clang/test/Driver/cl-options.c
+++ clang/test/Driver/cl-options.c
@@ -426,6 +426,8 @@
 // RUN: /Bt \
 // RUN: /Bt+ \
 // RUN: /clr:pure \
+// RUN: /d1import_no_registry \
+// RUN: /d1nodatetime \
 // RUN: /d2FH4 \
 // RUN: /docname \
 // RUN: /experimental:external \
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -6925,6 +6925,7 @@
 def _SLASH_Bt : CLFlag<"Bt">;
 def _SLASH_Bt_plus : CLFlag<"Bt+">;
 def _SLASH_clr : CLJoined<"clr">;
+def _SLASH_d1 : CLJoined<"d1">;
 def _SLASH_d2 : CLJoined<"d2">;
 def _SLASH_doc : CLJoined<"doc">;
 def _SLASH_experimental : CLJoined<"experimental:">;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139095: [clang] Mark CWG405 as a duplicate of CWG218

2022-12-02 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

In D139095#3964181 , @Endill wrote:

> So I'd like to raise a couple of questions:
>
> 1. What test for 405 is going to be if not a copy-and-paste of a part of 218 
> test?

I think this is perfectly fine to have a duplicated test case, I agree with 
Aaron, we should not invent duplicated status ourselves.
Adding a comment in the test like "Note: this test is identical to the one for 
CWG405" would be a good idea

> 2. Is it possible to change status of 405 in the official document? Or get a 
> technical rationale for it not being a duplicate of 218.

Nah, that wouldn't be worth the hassle, even if you got people to agree on the 
duplicated nature

> As a side note, I don't feel too comfortable testing name lookup via side 
> effects like diagnostics. `#pragma clang __debug dump` is good, but not 
> powerful enough to test ADL. Are those the only options we currently have?

You could do a codegen tests and check that the correct function gets called 
using its mangled name. There are examples in the drs tests already, grep for 
"// CHECK: call"


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139095

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


[PATCH] D139172: [clang] Mark CWG554 as N/A

2022-12-02 Thread Vlad Serebrennikov via Phabricator via cfe-commits
Endill added a comment.

> There are many editorial issues that ended up as defect reports, you could 
> probably batch many of them in subsequent PR

Thank you for suggestion. I'm being on a safer side at the moment, because 
CWG405 raised more questions than I anticipated.
I'll also wait until tomorrow morning (≈18 hours from now) to let everybody 
interested comment on this, to avoid situations like the one with CWG360 
yesterday.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139172

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


[PATCH] D139182: AArch64: add CodeGen support for FEAT_XS DSB instructions

2022-12-02 Thread Thorsten via Phabricator via cfe-commits
tschuett added a comment.

The def file is going away:
https://reviews.llvm.org/D139102


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139182

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


[PATCH] D139125: [clang] Correctly handle by-reference capture with an initializer that is a pack expansion in lambdas.

2022-12-02 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: clang/lib/Sema/TreeTransform.h:13156
   getSema().buildLambdaInitCaptureInitialization(
-  C->getLocation(), OldVD->getType()->isReferenceType(),
+  C->getLocation(), isReferenceType,
   EllipsisLoc, NumExpansions, OldVD->getIdentifier(),

Could we use `C->getCaptureKind() == LCK_ByRef` instead?

It seems like that was the intention of the function in the first place (that's 
was the other callsite from the parser is doing): pass what was written by the 
user and let the function figure out how to actually build the types.
Normally we want to unify the code that parser uses for non-dependent code and 
the tree-transforms where possible.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139125

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


[PATCH] D139167: [clang][Windows]Ignore Options '/d1nodatetime' and '/d1import_no_registry'

2022-12-02 Thread Hans Wennborg via Phabricator via cfe-commits
hans accepted this revision.
hans added a comment.
This revision is now accepted and ready to land.

Looks great, thanks!

Do you have commit access, or would you like someone to commit this for you?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139167

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


[PATCH] D136694: [clang][Interp] Check that constructor calls initialize all record fields

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

Oh I think this patch is doing too much. The checking should only occur for 
global variables.


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

https://reviews.llvm.org/D136694

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


[PATCH] D139095: [clang] Mark CWG405 as a duplicate of CWG218

2022-12-02 Thread Vlad Serebrennikov via Phabricator via cfe-commits
Endill added a comment.

> I think this is perfectly fine to have a duplicated test case, I agree with 
> Aaron, we should not invent duplicated status ourselves.
> Adding a comment in the test like "Note: this test is identical to the one 
> for CWG405" would be a good idea

Does it mean that duplication with cross-references is the best way to handle 
this even hypothetically? As opposed to, say, new notation for 
make_cxx_dr_status like `// dr405: dup 405 unofficial`.

> Nah, that wouldn't be worth the hassle, even if you got people to agree on 
> the duplicated nature

Sad but definitely not unexpected.

> You could do a codegen tests and check that the correct function gets called 
> using its mangled name. There are examples in the drs tests already, grep for 
> "// CHECK: call"

Thanks for mentioning this! Could definitely be used as a last resort. I'll try 
it for some of the subsequent CWG test.
Observing front-end behavior via back-end still doesn't feel good, though. I 
believe debug facilities should be improved to contain as much DR checks as 
possible at source and AST level.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139095

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


[PATCH] D139168: [C++20] [Modules] [ClangScanDeps] Enable to print make-style dependency file within P1689 format (4/4)

2022-12-02 Thread Ben Boeckel via Phabricator via cfe-commits
ben.boeckel added inline comments.



Comment at: clang/test/ClangScanDeps/P1689.cppm:155
 
+// CHECK-MAKE: [[PREFIX]]/impl_part.o:
+// CHECK-MAKE:   [[PREFIX]]/impl_part.cppm

For scanning, this cannot be the object file. The output needs to be the P1689 
output (or whatever the "main output" for the scanning rule is). This is the 
purpose behind the `-MT ` flag: to say what goes in this slot. I think 
it'll be necessary here (even if `clang-scan-deps` learns an `-o` flag because 
it is the build system that determines the "primary output").

I don't know if the `-MMD` and `-MD` differences are important or not; I don't 
think I particularly care which is default (I've used `-MD` FWIW), but it may 
matter for other situations.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139168

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


[PATCH] D139170: [X86][clang] Lift _BitInt() supported max width.

2022-12-02 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Thanks for working on this! LGTM, but please add a release note when landing so 
that users know about this improvement!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139170

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


[PATCH] D139195: [-Wmissing-noreturn] Detect non-void noreturn function candidates

2022-12-02 Thread Balázs Benics via Phabricator via cfe-commits
steakhal created this revision.
steakhal added reviewers: NoQ, xazax.hun, aaron.ballman.
Herald added subscribers: martong, rnkovacs.
Herald added a reviewer: Szelethus.
Herald added a project: All.
steakhal requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Previously, only `void` returning functions were considered for `noreturn`
attribute candidates. This patch removes this artificial restriction.

Notice the zero-initializations of the `CheckFallThroughDiagnostics`
objects. In some cases, such as inside `MakeForCoroutine()`, some struct
members were left uninitialized (probably by accident).
This way all the fields will be zero-initialized, preventing accidental
uninitialized reads during diagnostics construction.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139195

Files:
  clang/lib/Sema/AnalysisBasedWarnings.cpp
  clang/test/SemaCXX/return-noreturn.cpp
  clang/test/SemaObjC/return.m

Index: clang/test/SemaObjC/return.m
===
--- clang/test/SemaObjC/return.m
+++ clang/test/SemaObjC/return.m
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -Wmissing-noreturn -fobjc-exceptions -Wno-objc-root-class %s
 
-int test1(void) {
+__attribute__((noreturn)) int test1(void) {
   id a;
   @throw a;
 }
Index: clang/test/SemaCXX/return-noreturn.cpp
===
--- clang/test/SemaCXX/return-noreturn.cpp
+++ clang/test/SemaCXX/return-noreturn.cpp
@@ -15,28 +15,28 @@
 // the presence of switches, case statements, labels, and blocks. These tests
 // try to cover bugs reported in both PR6884 and PR10063.
 namespace abort_struct_complex_cfgs {
-  int basic(int x) {
+  __attribute__((noreturn)) int basic(int x) {
 switch (x) { default: pr6884_abort(); }
   }
-  int f1(int x) {
+  __attribute__((noreturn)) int f1(int x) {
 switch (x) default: pr6884_abort_struct();
   }
-  int f2(int x) {
+  __attribute__((noreturn)) int f2(int x) {
 switch (x) { default: pr6884_abort_struct(); }
   }
   int f2_positive(int x) {
 switch (x) { default: ; }
   } // expected-warning {{non-void function does not return a value}}
-  int f3(int x) {
+  __attribute__((noreturn)) int f3(int x) {
 switch (x) { default: { pr6884_abort_struct(); } }
   }
-  int f4(int x) {
+  __attribute__((noreturn)) int f4(int x) {
 switch (x) default: L1: L2: case 4: pr6884_abort_struct();
   }
-  int f5(int x) {
+  __attribute__((noreturn)) int f5(int x) {
 switch (x) default: L1: { L2: case 4: pr6884_abort_struct(); }
   }
-  int f6(int x) {
+  __attribute__((noreturn)) int f6(int x) {
 switch (x) default: L1: L2: case 4: { pr6884_abort_struct(); }
   }
 
@@ -50,11 +50,11 @@
 
   // Test that these constructs work even when extraneous blocks are created
   // before and after the switch due to implicit destructors.
-  int g1(int x) {
+  __attribute__((noreturn)) int g1(int x) {
 other o;
 switch (x) default: pr6884_abort_struct();
   }
-  int g2(int x) {
+  __attribute__((noreturn)) int g2(int x) {
 other o;
 switch (x) { default: pr6884_abort_struct(); }
   }
@@ -62,46 +62,46 @@
 other o;
 switch (x) { default: ; }
   } // expected-warning {{non-void function does not return a value}}
-  int g3(int x) {
+  __attribute__((noreturn)) int g3(int x) {
 other o;
 switch (x) { default: { pr6884_abort_struct(); } }
   }
-  int g4(int x) {
+  __attribute__((noreturn)) int g4(int x) {
 other o;
 switch (x) default: L1: L2: case 4: pr6884_abort_struct();
   }
-  int g5(int x) {
+  __attribute__((noreturn)) int g5(int x) {
 other o;
 switch (x) default: L1: { L2: case 4: pr6884_abort_struct(); }
   }
-  int g6(int x) {
+  __attribute__((noreturn)) int g6(int x) {
 other o;
 switch (x) default: L1: L2: case 4: { pr6884_abort_struct(); }
   }
 
   // Test that these constructs work even with variables carrying the no-return
   // destructor instead of temporaries.
-  int h1(int x) {
+  __attribute__((noreturn)) int h1(int x) {
 other o;
 switch (x) default: pr6884_abort_struct a;
   }
-  int h2(int x) {
+  __attribute__((noreturn)) int h2(int x) {
 other o;
 switch (x) { default: pr6884_abort_struct a; }
   }
-  int h3(int x) {
+  __attribute__((noreturn)) int h3(int x) {
 other o;
 switch (x) { default: { pr6884_abort_struct a; } }
   }
-  int h4(int x) {
+  __attribute__((noreturn)) int h4(int x) {
 other o;
 switch (x) default: L1: L2: case 4: pr6884_abort_struct a;
   }
-  int h5(int x) {
+  __attribute__((noreturn)) int h5(int x) {
 other o;
 switch (x) default: L1: { L2: case 4: pr6884_abort_struct a; }
   }
-  int h6(int x) {
+  __attribute__((noreturn)) int h6(int x) {
 other o;
 switch (x) default: L1: L2: case 4: { pr6884_abort_struct a; }
   }
@@ -155,11 +155,11 @@
   operator bool() const;
 };
 
-int testTernaryUnconditionalNore

[PATCH] D135658: demangle OptFunction trace names

2022-12-02 Thread Jamie Schmeiser via Phabricator via cfe-commits
jamieschmeiser added a comment.

Is the mode change on check-time-trace-sections.py intended?  I did a count of 
python files under llvm-project and < 10% are 755.  I'm not saying it is better 
one way or the other; I'm just ensuring it is intentional.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135658

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


[clang] 26424c9 - Attributes: convert Optional to std::optional

2022-12-02 Thread Krzysztof Parzyszek via cfe-commits

Author: Krzysztof Parzyszek
Date: 2022-12-02T08:15:45-06:00
New Revision: 26424c96c03ee4098d7f129de9234a6f177e49ac

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

LOG: Attributes: convert Optional to std::optional

Added: 


Modified: 
clang/lib/CodeGen/CGCall.cpp
llvm/include/llvm/Analysis/TargetTransformInfo.h
llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
llvm/include/llvm/AsmParser/LLParser.h
llvm/include/llvm/CodeGen/BasicTTIImpl.h
llvm/include/llvm/IR/Attributes.h
llvm/lib/Analysis/InstructionSimplify.cpp
llvm/lib/Analysis/MemoryBuiltins.cpp
llvm/lib/Analysis/TargetTransformInfo.cpp
llvm/lib/Analysis/ValueTracking.cpp
llvm/lib/AsmParser/LLParser.cpp
llvm/lib/IR/AttributeImpl.h
llvm/lib/IR/Attributes.cpp
llvm/lib/IR/Verifier.cpp
llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
llvm/lib/Target/AArch64/AArch64TargetTransformInfo.h
llvm/lib/Target/AArch64/SVEIntrinsicOpts.cpp
llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h
llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
llvm/lib/Transforms/Utils/BuildLibCalls.cpp
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 0f410a8daae66..df500a5981f4c 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -40,6 +40,7 @@
 #include "llvm/IR/Intrinsics.h"
 #include "llvm/IR/Type.h"
 #include "llvm/Transforms/Utils/Local.h"
+#include 
 using namespace clang;
 using namespace CodeGen;
 
@@ -2205,7 +2206,7 @@ void CodeGenModule::ConstructAttributeList(StringRef Name,
 
 HasOptnone = TargetDecl->hasAttr();
 if (auto *AllocSize = TargetDecl->getAttr()) {
-  Optional NumElemsParam;
+  std::optional NumElemsParam;
   if (AllocSize->getNumElemsParam().isValid())
 NumElemsParam = AllocSize->getNumElemsParam().getLLVMIndex();
   FuncAttrs.addAllocSizeAttr(AllocSize->getElemSizeParam().getLLVMIndex(),

diff  --git a/llvm/include/llvm/Analysis/TargetTransformInfo.h 
b/llvm/include/llvm/Analysis/TargetTransformInfo.h
index 592f1146b5cd5..f26fe677a8d1a 100644
--- a/llvm/include/llvm/Analysis/TargetTransformInfo.h
+++ b/llvm/include/llvm/Analysis/TargetTransformInfo.h
@@ -972,10 +972,10 @@ class TargetTransformInfo {
 
   /// \return The maximum value of vscale if the target specifies an
   ///  architectural maximum vector length, and None otherwise.
-  Optional getMaxVScale() const;
+  std::optional getMaxVScale() const;
 
   /// \return the value of vscale to tune the cost model for.
-  Optional getVScaleForTuning() const;
+  std::optional getVScaleForTuning() const;
 
   /// \return True if the vectorization factor should be chosen to
   /// make the vector of the smallest element type match the size of a
@@ -1715,8 +1715,8 @@ class TargetTransformInfo::Concept {
   virtual const char *getRegisterClassName(unsigned ClassID) const = 0;
   virtual TypeSize getRegisterBitWidth(RegisterKind K) const = 0;
   virtual unsigned getMinVectorRegisterBitWidth() const = 0;
-  virtual Optional getMaxVScale() const = 0;
-  virtual Optional getVScaleForTuning() const = 0;
+  virtual std::optional getMaxVScale() const = 0;
+  virtual std::optional getVScaleForTuning() const = 0;
   virtual bool
   shouldMaximizeVectorBandwidth(TargetTransformInfo::RegisterKind K) const = 0;
   virtual ElementCount getMinimumVF(unsigned ElemWidth,
@@ -2239,10 +2239,10 @@ class TargetTransformInfo::Model final : public 
TargetTransformInfo::Concept {
   unsigned getMinVectorRegisterBitWidth() const override {
 return Impl.getMinVectorRegisterBitWidth();
   }
-  Optional getMaxVScale() const override {
+  std::optional getMaxVScale() const override {
 return Impl.getMaxVScale();
   }
-  Optional getVScaleForTuning() const override {
+  std::optional getVScaleForTuning() const override {
 return Impl.getVScaleForTuning();
   }
   bool shouldMaximizeVectorBandwidth(

diff  --git a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h 
b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
index 05cab5b45e282..b21a001810938 100644
--- a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
+++ b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
@@ -22,6 +22,7 @@
 #include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/Operator.h"
 #include "llvm/IR/PatternMatch.h"
+#include 
 #include 
 
 namespace llvm {
@@ -430,8 +431,8 @@ class TargetTransformInfoImplBase {
 
   unsigned getMinVectorRegisterBitWidth() const { return 128; }
 
-  Optional getMaxVScale() const { return None; }
-  Optional getVScaleForTuning() const { return None; }
+  std::optional getMaxVScale() const { return std::n

[PATCH] D139197: Do not warn about redundant static in misc-use-anonymous-namespace

2022-12-02 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp created this revision.
Herald added a reviewer: njames93.
Herald added a project: All.
carlosgalvezp requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

I will create a new check "readability-redundant-static" where this
functionality fits better, together with other cases where static
is redundant.

That way we can add automatic fixits there and keep this check
focused on doing only one thing.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139197

Files:
  clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
  clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.h
  clang-tools-extra/docs/clang-tidy/checks/misc/use-anonymous-namespace.rst
  clang-tools-extra/test/clang-tidy/checkers/misc/use-anonymous-namespace.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/misc/use-anonymous-namespace.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/misc/use-anonymous-namespace.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/misc/use-anonymous-namespace.cpp
@@ -5,13 +5,6 @@
 static int v1;
 // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: variable 'v1' declared 'static', move to anonymous namespace instead
 
-namespace {
-  static void f2();
-  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: function 'f2' declared 'static' in anonymous namespace, remove 'static'
-  static int v2;
-  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: variable 'v2' declared 'static' in anonymous namespace, remove 'static'
-}
-
 namespace a {
   static void f3();
   // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: function 'f3' declared 'static', move to anonymous namespace instead
@@ -19,15 +12,6 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: variable 'v3' declared 'static', move to anonymous namespace instead
 }
 
-namespace a {
-namespace {
-  static void f4();
-  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: function 'f4' declared 'static' in anonymous namespace, remove 'static'
-  static int v4;
-  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: variable 'v4' declared 'static' in anonymous namespace, remove 'static'
-}
-}
-
 // OK
 void f5();
 int v5;
Index: clang-tools-extra/docs/clang-tidy/checks/misc/use-anonymous-namespace.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/misc/use-anonymous-namespace.rst
+++ clang-tools-extra/docs/clang-tidy/checks/misc/use-anonymous-namespace.rst
@@ -4,9 +4,7 @@
 
 
 Finds instances of ``static`` functions or variables declared at global scope
-that could instead be moved into an anonymous namespace. It also detects
-instances moved to an anonymous namespace that still keep the redundant
-``static``.
+that could instead be moved into an anonymous namespace.
 
 Anonymous namespaces are the "superior alternative" according to the C++
 Standard. ``static`` was proposed for deprecation, but later un-deprecated to
@@ -27,18 +25,4 @@
 int x;
   } // namespace
 
-.. code-block:: c++
-
-  // Bad
-  namespace {
-static void foo();
-static int x;
-  }
-
-  // Good
-  namespace {
-void foo();
-int x;
-  }  // namespace
-
 [1] `Undeprecating static `_
Index: clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.h
===
--- clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.h
+++ clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.h
@@ -16,8 +16,7 @@
 namespace misc {
 
 /// Warns when using 'static' functions or variables at global scope, and
-/// suggests moving them to an anonymous namespace. It also suggests removing
-/// 'static' if they are already inside an anonymous namespace.
+/// suggests moving them to an anonymous namespace.
 ///
 /// For the user-facing documentation see:
 /// http://clang.llvm.org/extra/clang-tidy/checks/modernize/use-anonymous-namespace.html
Index: clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
===
--- clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
+++ clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
@@ -21,14 +21,10 @@
   return Node.getStorageClass() == SC_Static;
 }
 
-AST_MATCHER(FunctionDecl, isMemberFunction) {
-  return llvm::isa(&Node);
-}
-AST_MATCHER(VarDecl, isStaticDataMember) { return Node.isStaticDataMember(); }
-} // namespace
-
-static bool isInAnonymousNamespace(const Decl *Decl) {
-  const DeclContext *DC = Decl->getDeclContext();
+AST_POLYMORPHIC_MATCHER(isInAnonymousNamespace,
+AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl,
+VarDecl)) {
+  const DeclContext *DC = Node.getDeclContext();
   if (DC && DC->isNamespace()) {
 

[PATCH] D139197: Do not warn about redundant static in misc-use-anonymous-namespace

2022-12-02 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp updated this revision to Diff 479616.
carlosgalvezp added a comment.

Reorder matchers to reduce diff.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139197

Files:
  clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
  clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.h
  clang-tools-extra/docs/clang-tidy/checks/misc/use-anonymous-namespace.rst
  clang-tools-extra/test/clang-tidy/checkers/misc/use-anonymous-namespace.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/misc/use-anonymous-namespace.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/misc/use-anonymous-namespace.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/misc/use-anonymous-namespace.cpp
@@ -5,13 +5,6 @@
 static int v1;
 // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: variable 'v1' declared 'static', move to anonymous namespace instead
 
-namespace {
-  static void f2();
-  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: function 'f2' declared 'static' in anonymous namespace, remove 'static'
-  static int v2;
-  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: variable 'v2' declared 'static' in anonymous namespace, remove 'static'
-}
-
 namespace a {
   static void f3();
   // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: function 'f3' declared 'static', move to anonymous namespace instead
@@ -19,15 +12,6 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: variable 'v3' declared 'static', move to anonymous namespace instead
 }
 
-namespace a {
-namespace {
-  static void f4();
-  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: function 'f4' declared 'static' in anonymous namespace, remove 'static'
-  static int v4;
-  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: variable 'v4' declared 'static' in anonymous namespace, remove 'static'
-}
-}
-
 // OK
 void f5();
 int v5;
Index: clang-tools-extra/docs/clang-tidy/checks/misc/use-anonymous-namespace.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/misc/use-anonymous-namespace.rst
+++ clang-tools-extra/docs/clang-tidy/checks/misc/use-anonymous-namespace.rst
@@ -4,9 +4,7 @@
 
 
 Finds instances of ``static`` functions or variables declared at global scope
-that could instead be moved into an anonymous namespace. It also detects
-instances moved to an anonymous namespace that still keep the redundant
-``static``.
+that could instead be moved into an anonymous namespace.
 
 Anonymous namespaces are the "superior alternative" according to the C++
 Standard. ``static`` was proposed for deprecation, but later un-deprecated to
@@ -27,18 +25,4 @@
 int x;
   } // namespace
 
-.. code-block:: c++
-
-  // Bad
-  namespace {
-static void foo();
-static int x;
-  }
-
-  // Good
-  namespace {
-void foo();
-int x;
-  }  // namespace
-
 [1] `Undeprecating static `_
Index: clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.h
===
--- clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.h
+++ clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.h
@@ -16,8 +16,7 @@
 namespace misc {
 
 /// Warns when using 'static' functions or variables at global scope, and
-/// suggests moving them to an anonymous namespace. It also suggests removing
-/// 'static' if they are already inside an anonymous namespace.
+/// suggests moving them to an anonymous namespace.
 ///
 /// For the user-facing documentation see:
 /// http://clang.llvm.org/extra/clang-tidy/checks/modernize/use-anonymous-namespace.html
Index: clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
===
--- clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
+++ clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
@@ -25,10 +25,11 @@
   return llvm::isa(&Node);
 }
 AST_MATCHER(VarDecl, isStaticDataMember) { return Node.isStaticDataMember(); }
-} // namespace
 
-static bool isInAnonymousNamespace(const Decl *Decl) {
-  const DeclContext *DC = Decl->getDeclContext();
+AST_POLYMORPHIC_MATCHER(isInAnonymousNamespace,
+AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl,
+VarDecl)) {
+  const DeclContext *DC = Node.getDeclContext();
   if (DC && DC->isNamespace()) {
 const auto *ND = llvm::cast(DC);
 if (ND && ND->isAnonymousNamespace())
@@ -36,25 +37,25 @@
   }
   return false;
 }
+} // namespace
 
 template 
 void UseAnonymousNamespaceCheck::processMatch(const T *MatchedDecl) {
   StringRef Type = llvm::isa(MatchedDecl) ? "variable" : "function";
-  if (isInAnonymousNamespace(MatchedDecl))
-diag(MatchedDecl->getLocation(), "%0 %1 declared '

[PATCH] D139167: [clang][Windows]Ignore Options '/d1nodatetime' and '/d1import_no_registry'

2022-12-02 Thread Tobias Hieta via Phabricator via cfe-commits
thieta added a comment.

Makes sense they are not documented and we probably can ignore them in that 
case!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139167

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


[PATCH] D139197: Do not warn about redundant static in misc-use-anonymous-namespace

2022-12-02 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

This patch should not land before that one does.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139197

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


[PATCH] D139095: [clang] Mark CWG405 as a duplicate of CWG218

2022-12-02 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D139095#3964181 , @Endill wrote:

>> I don't think we should mark it as a dup -- we want the status in our tests 
>> to match the status on the official document, otherwise things get confusing.
>
> We can do it the following way then: `// dr405: yes \n // NB: also dup 218`.

That would be fine by me!

> Do I understand correctly that superseded status should be used if and only 
> if it's used in official document as well?

That one is somewhat harder in that it's possible for future changes to the 
standard to supersede previously resolved issues without the committee going 
back to mark those old DRs as superseded. However, I think in general, we 
should stick with the status in the document, and we can use extra comments to 
add our own information on top of it.

>> The two issues are very closely related, but they change different words in 
>> the standard and should be tested independently as best we can
>
> Make no mistake here: proposed wording for 405 has never made it into the 
> standard. I double-checked this with revision 100 of CWG issues, when this 
> issue still had open status.
> P1787  states that //CWG405 is resolved by 
> stating that argument-dependent lookup (sometimes) occurs after an ordinary 
> unqualified lookup (making statements like “finding a variable prevents 
> argument-dependent lookup” formally correct).//
> The only relevant wording in P1787  I can 
> find is for [basic.lookup.argdep] p1 and p3 (too long; not citing them here). 
> Which, curiously enough, clearly originates from resolution of 218, which is 
> already tested. It also has the same intent as proposed resolution for 405.
>
> So I'd like to raise a couple of questions:
>
> 1. What test for 405 is going to be if not a copy-and-paste of a part of 218 
> test?

In terms of test *coverage*, no benefit. In terms of *implementation status*, 
it makes it clear we considered the DR explicitly instead of leaving future 
folks to wonder.

In D139095#3966438 , @Endill wrote:

>> I think this is perfectly fine to have a duplicated test case, I agree with 
>> Aaron, we should not invent duplicated status ourselves.
>> Adding a comment in the test like "Note: this test is identical to the one 
>> for CWG405" would be a good idea
>
> Does it mean that duplication with cross-references is the best way to handle 
> this even hypothetically? As opposed to, say, new notation for 
> make_cxx_dr_status like `// dr405: dup 405 unofficial`.

I don't see a need for a new notation yet. These notations are specific to us 
generating the dr status page with the correct information, and users don't 
usually care about whether two DRs are dupes of one another so much as "I think 
this DR applies to my code, does Clang implement it?" kind of questions.

>> Nah, that wouldn't be worth the hassle, even if you got people to agree on 
>> the duplicated nature
>
> Sad but definitely not unexpected.
>
>> You could do a codegen tests and check that the correct function gets called 
>> using its mangled name. There are examples in the drs tests already, grep 
>> for "// CHECK: call"
>
> Thanks for mentioning this! Could definitely be used as a last resort. I'll 
> try it for some of the subsequent CWG test.
> Observing front-end behavior via back-end still doesn't feel good, though. I 
> believe debug facilities should be improved to contain as much DR checks as 
> possible at source and AST level.

CodeGen tests would be the approach I'd take; that's not actually testing the 
backend behavior, that's still testing the frontend IR generation (which is 
before the backend gets to start mutating/optimizing it).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139095

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


[PATCH] D139172: [clang] Mark CWG554 as N/A

2022-12-02 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.

LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139172

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


[PATCH] D139197: Do not warn about redundant static in misc-use-anonymous-namespace

2022-12-02 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

In D139197#3966549 , @lebedev.ri 
wrote:

> This patch should not land before that one does.

The original code is 1 day old. Do we really need to be so strict?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139197

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


[PATCH] D139197: Do not warn about redundant static in misc-use-anonymous-namespace

2022-12-02 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

My plan was to apply this removal in the same patch where I add the new check, 
but I know I'd get comments like "please do the removal in a separate patch". 
So that's what I'm doing :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139197

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


[PATCH] D135750: [clang][Interp] Track initialization state of local variables

2022-12-02 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/AST/Interp/Descriptor.h:141-145
   unsigned getAllocSize() const { return AllocSize; }
   /// returns the size of an element when the structure is viewed as an array.
   unsigned getElemSize()  const { return ElemSize; }
+  /// Returns the size of the metadata.
+  unsigned getMetadataSize() const { return MDSize; }

tbaeder wrote:
> aaron.ballman wrote:
> > There's some interface awkwardness here where these values are of type 
> > `InterpSize` but the interface returns `unsigned`
> Yes. `InterpSize` is also only really used in `Descriptor.h`. No idea why.
Yeah, this should be cleaned up (either here or in an NFC follow-up soon after 
this lands).



Comment at: clang/lib/AST/Interp/Descriptor.h:73
+  /// Flag indicating if the field is mutable (if in a record).
+  unsigned IsMutable : 1;
+

tbaeder wrote:
> shafik wrote:
> > Maybe `IsFieldMutable` b/c we call `CreateDescriptor` it is a little 
> > confusing why we have `IsConst` and `IsMutable`
> Agreed, but this code was just moved up in this patch, the field was 
> introduced earlier.
We can do a renaming pass once this lands, but FWIW, I'm also fine clarifying 
the names of things as we refactor code.



Comment at: clang/lib/AST/Interp/InterpBlock.h:97
   void invokeCtor() {
-std::memset(data(), 0, getSize());
+std::memset(rawData(), 0, Desc->getAllocSize());
 if (Desc->CtorFn)

tbaeder wrote:
> aaron.ballman wrote:
> > tbaeder wrote:
> > > aaron.ballman wrote:
> > > > Why do we want to overwrite the metadata here?
> > > This is only called after creating an new block, so nothing is being 
> > > overwritten, the metadata hasn't been filled-in yet.
> > Sounds like a good reason not to memset over that block then; it's useless 
> > work that will be thrown away anyway (I worry we may come to rely on this 
> > zero init accidentally)?
> FWIW I looked into this and I think zeroing everything is what we want, so 
> the initmap is null initially 
Hmmm, would it make more sense to have the init map setting that itself (in 
`allocate()`) rather than relying on `invokeCtor()` to do it?



Comment at: clang/lib/AST/Interp/Pointer.h:63-64
 private:
   static constexpr unsigned PastEndMark = (unsigned)-1;
   static constexpr unsigned RootPtrMark = (unsigned)-1;
 

tbaeder wrote:
> shafik wrote:
> > or `-1u`  
> Alright, but those were not introduced in this patch.
Preference for `~0u` so the types all match up nicely, fine to do in a 
post-commit NFC change.


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

https://reviews.llvm.org/D135750

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


[PATCH] D139197: Do not warn about redundant static in misc-use-anonymous-namespace

2022-12-02 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

I was commenting because we already have a similar diagnostic in clang-tidy 15:

  namespace {
static void foo();
static void bar(){}
void foo() {}
static int x;
  }

  $ clang-tidy-15  -checks=\*,-llvmlibc-* /tmp/test.cpp 
  Error while trying to load a compilation database:
  Could not auto-detect compilation database for file "/tmp/test.cpp"
  No compilation database found in /tmp or any parent directory
  fixed-compilation-database: Error while opening fixed database: No such file 
or directory
  json-compilation-database: Error while opening JSON database: No such file or 
directory
  Running without flags.
  5 warnings generated.
  /tmp/test.cpp:3:17: warning: 'bar' is a static definition in anonymous 
namespace; static is redundant here 
[readability-static-definition-in-anonymous-namespace]
  static void bar(){}
  ~~~ ^
  /tmp/test.cpp:5:16: warning: variable 'x' is non-const and globally 
accessible, consider making it const 
[cppcoreguidelines-avoid-non-const-global-variables]
  static int x;
 ^
  /tmp/test.cpp:5:16: warning: variable name 'x' is too short, expected at 
least 3 characters [readability-identifier-length]
  /tmp/test.cpp:5:16: warning: 'x' is a static definition in anonymous 
namespace; static is redundant here 
[readability-static-definition-in-anonymous-namespace]
  static int x;
  ~~~^
  /tmp/test.cpp:6:3: warning: anonymous namespace not terminated with a closing 
comment [llvm-namespace-comment]
}
^
  // namespace
  /tmp/test.cpp:1:13: note: anonymous namespace starts here
namespace {
  ^

that for some reason only fires on definitions, not declarations.
I thought this was changing that old check.
I think it may be good to not have duplicate coverage,
but do we need a new check given that there is one already?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139197

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


[PATCH] D135658: demangle OptFunction trace names

2022-12-02 Thread Trass3r via Phabricator via cfe-commits
Trass3r added a comment.

Yeah it was conscious at least. No strong opinion on that though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135658

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


[PATCH] D137603: [Clang][Sema] Fix attribute((format)) bug on non-variadic functions

2022-12-02 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.

LGTM, thank you!




Comment at: clang/docs/ReleaseNotes.rst:319
   `Issue 59100 `_
+- Fix issue using __attribute__((format)) on non-variadic functions that expect
+  more than one formatted argument.




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

https://reviews.llvm.org/D137603

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


[PATCH] D139114: [Clang][Sema] Enabled Wshorten-64-to-32 for CompoundAssignment operator.

2022-12-02 Thread Fahad Nayyar via Phabricator via cfe-commits
fahadnayyar updated this revision to Diff 479626.
fahadnayyar retitled this revision from "[Clang][Sema] Enabled 
Wshorten-64-to-32 for CompoundAssignment operator. " to "[Clang][Sema] Enabled 
Wshorten-64-to-32 for CompoundAssignment operator.".
fahadnayyar added a comment.

Fixing clang-format error.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139114

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/conversion-64-32.c

Index: clang/test/Sema/conversion-64-32.c
===
--- clang/test/Sema/conversion-64-32.c
+++ clang/test/Sema/conversion-64-32.c
@@ -17,3 +17,25 @@
 int test2(long v) {
   return v / 2; // expected-warning {{implicit conversion loses integer precision: 'long' to 'int'}}
 }
+
+// rdar://10466193
+void test3(int i, long long ll) {
+  i += ll; // expected-warning {{implicit conversion loses integer precision}}
+  i -= ll; // expected-warning {{implicit conversion loses integer precision}}
+  i *= ll; // expected-warning {{implicit conversion loses integer precision}}
+  i /= ll; // expected-warning {{implicit conversion loses integer precision}}
+}
+
+void test4(int i, long long ll) {
+  i += i-ll; // expected-warning {{implicit conversion loses integer precision}}
+  i += i+ll; // expected-warning {{implicit conversion loses integer precision}}
+  i -= i-ll; // expected-warning {{implicit conversion loses integer precision}}
+  i -= i+ll; // expected-warning {{implicit conversion loses integer precision}}
+}
+
+void test5(int i, int j, long long ll) {
+  i += (i-j)*ll; // expected-warning {{implicit conversion loses integer precision}}
+  i += (i+j)*ll; // expected-warning {{implicit conversion loses integer precision}}
+  i -= ll/(i-j); // expected-warning {{implicit conversion loses integer precision}}
+  i -= ll/(i-j); // expected-warning {{implicit conversion loses integer precision}}
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -13374,44 +13374,6 @@
   }
 }
 
-/// Analyze the given compound assignment for the possible losing of
-/// floating-point precision.
-static void AnalyzeCompoundAssignment(Sema &S, BinaryOperator *E) {
-  assert(isa(E) &&
- "Must be compound assignment operation");
-  // Recurse on the LHS and RHS in here
-  AnalyzeImplicitConversions(S, E->getLHS(), E->getOperatorLoc());
-  AnalyzeImplicitConversions(S, E->getRHS(), E->getOperatorLoc());
-
-  if (E->getLHS()->getType()->isAtomicType())
-S.Diag(E->getOperatorLoc(), diag::warn_atomic_implicit_seq_cst);
-
-  // Now check the outermost expression
-  const auto *ResultBT = E->getLHS()->getType()->getAs();
-  const auto *RBT = cast(E)
-->getComputationResultType()
-->getAs();
-
-  // The below checks assume source is floating point.
-  if (!ResultBT || !RBT || !RBT->isFloatingPoint()) return;
-
-  // If source is floating point but target is an integer.
-  if (ResultBT->isInteger())
-return DiagnoseImpCast(S, E, E->getRHS()->getType(), E->getLHS()->getType(),
-   E->getExprLoc(), diag::warn_impcast_float_integer);
-
-  if (!ResultBT->isFloatingPoint())
-return;
-
-  // If both source and target are floating points, warn about losing precision.
-  int Order = S.getASTContext().getFloatingTypeSemanticOrder(
-  QualType(ResultBT, 0), QualType(RBT, 0));
-  if (Order < 0 && !S.SourceMgr.isInSystemMacro(E->getOperatorLoc()))
-// warn about dropping FP rank.
-DiagnoseImpCast(S, E->getRHS(), E->getLHS()->getType(), E->getOperatorLoc(),
-diag::warn_impcast_float_result_precision);
-}
-
 static std::string PrettyPrintInRange(const llvm::APSInt &Value,
   IntRange Range) {
   if (!Range.Width) return "0";
@@ -14150,6 +14112,51 @@
   }
 }
 
+/// Analyze the given compound assignment for the possible losing of
+/// floating-point precision.
+static void AnalyzeCompoundAssignment(Sema &S, BinaryOperator *E) {
+  assert(isa(E) &&
+ "Must be compound assignment operation");
+  // Recurse on the LHS and RHS in here
+  AnalyzeImplicitConversions(S, E->getLHS(), E->getOperatorLoc());
+  AnalyzeImplicitConversions(S, E->getRHS(), E->getOperatorLoc());
+
+  if (E->getLHS()->getType()->isAtomicType())
+S.Diag(E->getOperatorLoc(), diag::warn_atomic_implicit_seq_cst);
+
+  // Now check the outermost expression
+  const auto *ResultBT = E->getLHS()->getType()->getAs();
+  const auto *RBT = cast(E)
+->getComputationResultType()
+->getAs();
+
+  // Check for implicit conversion loss of precision form 64-to-32 for compound
+  // statements.
+  if (E->getLHS()->getType()->isIntegerType() &&
+  E->getRHS()->getType()->isIntegerTyp

[PATCH] D139087: [include-cleaner] Handle base class member access from derived class.

2022-12-02 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang-tools-extra/include-cleaner/lib/WalkAST.cpp:68
+RecordDecl *RD = getDeclFromType(Type);
+report(E->getMemberLoc(), RD);
 return true;

nit: just `report(E->getMemberLoc(), getDeclFromTye(Type));`.



Comment at: clang-tools-extra/include-cleaner/lib/WalkAST.cpp:73
+  bool VisitCXXDependentScopeMemberExpr(const CXXDependentScopeMemberExpr *E) {
+// FIXME: implement this
+return true;

Be more specific about the comment, something like `// FIMXE: support the 
dependent type case like "std::vector().size();"`.

I will move this FIXME to `VisitMemberExpr`, and remove this function. 



Comment at: clang-tools-extra/include-cleaner/lib/WalkAST.cpp:77
+
+  RecordDecl *getDeclFromType(QualType Type) {
+if (Type->isPointerType()) {

- I'd use `NamedDecl*` as a return type (which is used in `report`)
- move this method to private, it is only used internally inside class, no need 
to make it public
-  what do you think about naming it `resolveType`?



Comment at: clang-tools-extra/include-cleaner/lib/WalkAST.cpp:78
+  RecordDecl *getDeclFromType(QualType Type) {
+if (Type->isPointerType()) {
+  Type = Type->getPointeeType();

nit: remove the surrounding {}



Comment at: clang-tools-extra/include-cleaner/lib/WalkAST.cpp:81
+}
+RecordDecl *RecordDecl = Type->getAsRecordDecl();
+return RecordDecl;

nit: just `return Type->getAsRecordDecl();`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139087

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


[PATCH] D139095: [clang] Mark CWG405 as a duplicate of CWG218

2022-12-02 Thread Vlad Serebrennikov via Phabricator via cfe-commits
Endill added a comment.

>> We can do it the following way then: // dr405: yes \n // NB: also dup 218.
>
> That would be fine by me!

Which way should we handle this? I'd prefer to do it without test duplication, 
but making it clear for readers is a serious concern indeed. (Read on, I 
elaborate on this below.)

>> What test for 405 is going to be if not a copy-and-paste of a part of 218 
>> test?
>
> In terms of test *coverage*, no benefit. In terms of *implementation status*, 
> it makes it clear we considered the DR explicitly instead of leaving future 
> folks to wonder.

Should we really try to meet an expectation that Clang developers haven't 
considered something as obvious as explicitly handling a DR not marked as 
duplicated or superseded officially? It doesn't seem a reasonable expectation 
to me, and at least my personal attitude have always been the opposite.
To be fully honest here, I don't even remember myself how I came across CWG218, 
because I did this test back in spring. So marking it as a duplicate (one way 
or another) on the contrary seems very considerate handling.

> CodeGen tests would be the approach I'd take; that's not actually testing the 
> backend behavior, that's still testing the frontend IR generation (which is 
> before the backend gets to start mutating/optimizing it).

You're very much right. Thank you for reminding me of that!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139095

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


[PATCH] D127284: [clang-repl] Support statements on global scope in incremental mode.

2022-12-02 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!


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

https://reviews.llvm.org/D127284

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


[PATCH] D138597: DebugInfo: Add/support new DW_LANG codes for recent C and C++ versions

2022-12-02 Thread Paul Robinson via Phabricator via cfe-commits
probinson added a comment.

One not-yet-asked question, does gcc produce the C++17/20 codes? If so, does 
fstrict-dwarf affect that?  The major consumers of this would be lldb (which we 
control) and gdb, so following gcc's lead here would seem appropriate.  I can 
accept that listing the codes on the website "counts" as in-spec for 
fstrict-dwarf purposes.

Deferring the v6 language attributes seems totally fair.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138597

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


[PATCH] D135658: demangle OptFunction trace names

2022-12-02 Thread Jamie Schmeiser via Phabricator via cfe-commits
jamieschmeiser accepted this revision.
jamieschmeiser added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135658

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


[PATCH] D139197: Do not warn about redundant static in misc-use-anonymous-namespace

2022-12-02 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

Ah, then it has the exact same functionality! My idea for 
readability-redundant-static was to warn about:

- static in anonymous namespace
- static const/constexpr at global scope (since const gives implicit internal 
linkage in C++).

I will see what I can do about that.

This shouldn't be a blocker for this patch though, it's just removing 
functionality that belongs in another check. As said, the check is 1 day old so 
it's unlikely anyone is relying on it yet :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139197

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


[PATCH] D139195: [-Wmissing-noreturn] Detect non-void noreturn function candidates

2022-12-02 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

> Previously, only void returning functions were considered for noreturn 
> attribute candidates. This patch removes this artificial restriction.

C2x 6.7.12.6p6: The implementation should produce a diagnostic message for a 
function declared with a noreturn attribute that appears to be capable of 
returning to its caller.

p7 has an example showing `[[noreturn]] int h(void);` with the comment 
"Implementations are similarly encouraged to diagnose the declaration of h() 
because it appears capable of returning to its caller due to the non-void 
return type."

So is this really an artificial restriction? To me, putting the `noreturn` 
attribute on a function with a return type makes no sense whatsoever. The 
interface is saying "I promise that calling me will not return" and "when I 
return, this is the type of the value I will give you."


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139195

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


[PATCH] D139202: Link with missing libs to fix broken shared build

2022-12-02 Thread Jun Zhang via Phabricator via cfe-commits
junaire created this revision.
Herald added a subscriber: kadircet.
Herald added a project: All.
junaire requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Signed-off-by: Jun Zhang 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139202

Files:
  clang-tools-extra/include-cleaner/lib/CMakeLists.txt
  clang-tools-extra/include-cleaner/tool/CMakeLists.txt


Index: clang-tools-extra/include-cleaner/tool/CMakeLists.txt
===
--- clang-tools-extra/include-cleaner/tool/CMakeLists.txt
+++ clang-tools-extra/include-cleaner/tool/CMakeLists.txt
@@ -6,6 +6,7 @@
   clangBasic
   clangFrontend
   clangLex
+  clangFormat
   clangSerialization
   clangTooling
   )
Index: clang-tools-extra/include-cleaner/lib/CMakeLists.txt
===
--- clang-tools-extra/include-cleaner/lib/CMakeLists.txt
+++ clang-tools-extra/include-cleaner/lib/CMakeLists.txt
@@ -16,6 +16,7 @@
   clangBasic
   clangFormat
   clangLex
+  clangToolingCore
   clangToolingInclusions
   clangToolingInclusionsStdlib
   )


Index: clang-tools-extra/include-cleaner/tool/CMakeLists.txt
===
--- clang-tools-extra/include-cleaner/tool/CMakeLists.txt
+++ clang-tools-extra/include-cleaner/tool/CMakeLists.txt
@@ -6,6 +6,7 @@
   clangBasic
   clangFrontend
   clangLex
+  clangFormat
   clangSerialization
   clangTooling
   )
Index: clang-tools-extra/include-cleaner/lib/CMakeLists.txt
===
--- clang-tools-extra/include-cleaner/lib/CMakeLists.txt
+++ clang-tools-extra/include-cleaner/lib/CMakeLists.txt
@@ -16,6 +16,7 @@
   clangBasic
   clangFormat
   clangLex
+  clangToolingCore
   clangToolingInclusions
   clangToolingInclusionsStdlib
   )
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D136815: [clang][Interp] Unify visiting variable declarations

2022-12-02 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!


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

https://reviews.llvm.org/D136815

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


[PATCH] D139202: Link with missing libs to fix broken shared build

2022-12-02 Thread Jun Zhang via Phabricator via cfe-commits
junaire added a comment.

This is caused by https://reviews.llvm.org/D139013 I should mention.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139202

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


[PATCH] D138651: [CUDA][HIP] Don't diagnose use for __bf16

2022-12-02 Thread Pierre van Houtryve via Phabricator via cfe-commits
Pierre-vh planned changes to this revision.
Pierre-vh marked an inline comment as done.
Pierre-vh added a comment.

I'll take a look at handling bf16 storage-only for AMDGPU. Looks like our 
Backend already handles it and converts it to i16 so maybe it'll be really easy.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138651

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


[PATCH] D139202: Link with missing libs to fix broken shared build

2022-12-02 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

Thanks, and sorry for the breakage!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139202

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


[PATCH] D139195: [-Wmissing-noreturn] Detect non-void noreturn function candidates

2022-12-02 Thread Balázs Benics via Phabricator via cfe-commits
steakhal planned changes to this revision.
steakhal added a comment.

In D139195#3966675 , @aaron.ballman 
wrote:

>> Previously, only void returning functions were considered for noreturn 
>> attribute candidates. This patch removes this artificial restriction.
>
> C2x 6.7.12.6p6: The implementation should produce a diagnostic message for a 
> function declared with a noreturn attribute that appears to be capable of 
> returning to its caller.
>
> p7 has an example showing `[[noreturn]] int h(void);` with the comment 
> "Implementations are similarly encouraged to diagnose the declaration of h() 
> because it appears capable of returning to its caller due to the non-void 
> return type."
>
> So is this really an artificial restriction? To me, putting the `noreturn` 
> attribute on a function with a return type makes no sense whatsoever. The 
> interface is saying "I promise that calling me will not return" and "when I 
> return, this is the type of the value I will give you."

Hmm, I implicitly took the `__attribute__((noreturn))` suggestion and the 
non-void return type as a code-smell for the exact same reason.
You are right, we should have a clean diagnostic message for these cases 
instead of this implied suggestion.
IDK why I haven't thought about this 😅


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139195

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


[PATCH] D139166: [OPENMP51] Codegen support for error directive.

2022-12-02 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added inline comments.



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.h:334
   llvm::Value *emitUpdateLocation(CodeGenFunction &CGF, SourceLocation Loc,
-  unsigned Flags = 0);
+  unsigned Flags = 0, bool EmitLoc = false);
 

jdoerfert wrote:
> Why the new argument?
Emit error without -g (debug info turn on.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139166

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


[PATCH] D139202: Link with missing libs to fix broken shared build

2022-12-02 Thread Jun Zhang 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 rG8431436e543f: Link with missing libs to fix broken shared 
build (authored by junaire).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139202

Files:
  clang-tools-extra/include-cleaner/lib/CMakeLists.txt
  clang-tools-extra/include-cleaner/tool/CMakeLists.txt


Index: clang-tools-extra/include-cleaner/tool/CMakeLists.txt
===
--- clang-tools-extra/include-cleaner/tool/CMakeLists.txt
+++ clang-tools-extra/include-cleaner/tool/CMakeLists.txt
@@ -6,6 +6,7 @@
   clangBasic
   clangFrontend
   clangLex
+  clangFormat
   clangSerialization
   clangTooling
   )
Index: clang-tools-extra/include-cleaner/lib/CMakeLists.txt
===
--- clang-tools-extra/include-cleaner/lib/CMakeLists.txt
+++ clang-tools-extra/include-cleaner/lib/CMakeLists.txt
@@ -16,6 +16,7 @@
   clangBasic
   clangFormat
   clangLex
+  clangToolingCore
   clangToolingInclusions
   clangToolingInclusionsStdlib
   )


Index: clang-tools-extra/include-cleaner/tool/CMakeLists.txt
===
--- clang-tools-extra/include-cleaner/tool/CMakeLists.txt
+++ clang-tools-extra/include-cleaner/tool/CMakeLists.txt
@@ -6,6 +6,7 @@
   clangBasic
   clangFrontend
   clangLex
+  clangFormat
   clangSerialization
   clangTooling
   )
Index: clang-tools-extra/include-cleaner/lib/CMakeLists.txt
===
--- clang-tools-extra/include-cleaner/lib/CMakeLists.txt
+++ clang-tools-extra/include-cleaner/lib/CMakeLists.txt
@@ -16,6 +16,7 @@
   clangBasic
   clangFormat
   clangLex
+  clangToolingCore
   clangToolingInclusions
   clangToolingInclusionsStdlib
   )
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 8431436 - Link with missing libs to fix broken shared build

2022-12-02 Thread Jun Zhang via cfe-commits

Author: Jun Zhang
Date: 2022-12-03T00:01:37+08:00
New Revision: 8431436e543f78a33e8165257f2e2f89c38269f9

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

LOG: Link with missing libs to fix broken shared build

Signed-off-by: Jun Zhang 

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

Added: 


Modified: 
clang-tools-extra/include-cleaner/lib/CMakeLists.txt
clang-tools-extra/include-cleaner/tool/CMakeLists.txt

Removed: 




diff  --git a/clang-tools-extra/include-cleaner/lib/CMakeLists.txt 
b/clang-tools-extra/include-cleaner/lib/CMakeLists.txt
index 5c83e8fdc1515..75e1fb725c656 100644
--- a/clang-tools-extra/include-cleaner/lib/CMakeLists.txt
+++ b/clang-tools-extra/include-cleaner/lib/CMakeLists.txt
@@ -16,6 +16,7 @@ clang_target_link_libraries(clangIncludeCleaner
   clangBasic
   clangFormat
   clangLex
+  clangToolingCore
   clangToolingInclusions
   clangToolingInclusionsStdlib
   )

diff  --git a/clang-tools-extra/include-cleaner/tool/CMakeLists.txt 
b/clang-tools-extra/include-cleaner/tool/CMakeLists.txt
index 3b9b03141ce1b..f48907f9ae68a 100644
--- a/clang-tools-extra/include-cleaner/tool/CMakeLists.txt
+++ b/clang-tools-extra/include-cleaner/tool/CMakeLists.txt
@@ -6,6 +6,7 @@ clang_target_link_libraries(clang-include-cleaner PRIVATE
   clangBasic
   clangFrontend
   clangLex
+  clangFormat
   clangSerialization
   clangTooling
   )



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


[PATCH] D139148: Fix nullptr dereference found by Coverity static analysis tool

2022-12-02 Thread Tom Honermann via Phabricator via cfe-commits
tahonermann requested changes to this revision.
tahonermann added a comment.
This revision now requires changes to proceed.

Per added comments, I think we should look for a guarantee that `Initializer` 
is non-null earlier in the function. If there is, then we could remove a bunch 
of the current existence checks rather than adding more.




Comment at: clang/lib/Sema/SemaInit.cpp:5824-5828
   // Handle default initialization.
   if (Kind.getKind() == InitializationKind::IK_Default) {
 TryDefaultInitialization(S, Entity, Kind, *this);
 return;
   }

This block handles default initialization and unconditionally performs a 
return. I wonder if this effectively guarantees that `Initializer` is non-null 
if this block is not entered.



Comment at: clang/lib/Sema/SemaInit.cpp:5933
 
   if (TryOCLSamplerInitialization(S, *this, DestType, Initializer))
 return;

The use of `initializer` here looks questionable too; 
`TryOCLSamplerInitialization()` will dereference it without a check if both 
`S.getLangOpts().OpenCL` and `DestType->isSamplerT()` are both true.



Comment at: clang/lib/Sema/SemaInit.cpp:5941
 if (allowObjCWritebackConversion &&
 tryObjCWritebackConversion(S, *this, Entity, Initializer)) {
   return;

This use of `Initializer` is also questionable; `tryObjCWritebackConversion()` 
will unconditionally dereference it.



Comment at: clang/lib/Sema/SemaInit.cpp:5945
 
 if (TryOCLZeroOpaqueTypeInitialization(S, *this, DestType, Initializer))
   return;

This use of `Initializer` is also questionable; 
`TryOCLZeroOpaqueTypeInitialization()` will conditionally dereference it.



Comment at: clang/lib/Sema/SemaInit.cpp:5976
 else
   TryUserDefinedConversion(S, DestType, Kind, Initializer, *this,
TopLevelOfInitList);

This use of `Initializer` looks like it also needs to be protected; 
`TryUserDefinedConversion()` unconditionally dereferences it.



Comment at: clang/lib/Sema/SemaInit.cpp:6038-6039
 
 TryUserDefinedConversion(S, DestType, Kind, Initializer, *this,
  TopLevelOfInitList);
 MaybeProduceObjCObject(S, *this, Entity);

This use of `Initializer` looks like it also needs to be protected; 
`TryUserDefinedConversion()` unconditionally dereferences it.



Comment at: clang/lib/Sema/SemaInit.cpp:6066-6071
 = S.TryImplicitConversion(Initializer, DestType,
   /*SuppressUserConversions*/true,
   Sema::AllowedExplicit::None,
   /*InOverloadResolution*/ false,
   /*CStyle=*/Kind.isCStyleOrFunctionalCast(),
   allowObjCWritebackConversion);

`Initializer` is unconditionally dereferenced in 
`Sema::TryImplicitConversion()`.

I stopped analyzing other uses here. At this point (at least), it seems clear 
that the expectation is that `Initializer` is non-null. That makes me think 
that, rather than adding additional checks, we should look for an existing 
guarantee that `initializer` is in fact non-null (something that Coverity 
missed) or add one. If we need to add such a guarantee, we could add an 
`assert(Initializer)` somewhere earlier in the function, but I'm not sure where.


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

https://reviews.llvm.org/D139148

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


[PATCH] D139172: [clang] Mark CWG554 as N/A

2022-12-02 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added a comment.

@aaron.ballman do you think it is worth it to provide a link to `p1787` as 
well? I know you can just goto the issue and see that but it feels helpful. I 
actually missed this at first b/c I usually goto end of the issue to look for 
the resolution and was confused.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139172

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


[PATCH] D139197: [clang-tidy] Do not warn about redundant static in misc-use-anonymous-namespace

2022-12-02 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp updated this revision to Diff 479651.
carlosgalvezp edited the summary of this revision.
carlosgalvezp added a comment.

Update commit message.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139197

Files:
  clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
  clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.h
  clang-tools-extra/docs/clang-tidy/checks/misc/use-anonymous-namespace.rst
  clang-tools-extra/test/clang-tidy/checkers/misc/use-anonymous-namespace.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/misc/use-anonymous-namespace.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/misc/use-anonymous-namespace.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/misc/use-anonymous-namespace.cpp
@@ -5,13 +5,6 @@
 static int v1;
 // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: variable 'v1' declared 'static', move to anonymous namespace instead
 
-namespace {
-  static void f2();
-  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: function 'f2' declared 'static' in anonymous namespace, remove 'static'
-  static int v2;
-  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: variable 'v2' declared 'static' in anonymous namespace, remove 'static'
-}
-
 namespace a {
   static void f3();
   // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: function 'f3' declared 'static', move to anonymous namespace instead
@@ -19,15 +12,6 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: variable 'v3' declared 'static', move to anonymous namespace instead
 }
 
-namespace a {
-namespace {
-  static void f4();
-  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: function 'f4' declared 'static' in anonymous namespace, remove 'static'
-  static int v4;
-  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: variable 'v4' declared 'static' in anonymous namespace, remove 'static'
-}
-}
-
 // OK
 void f5();
 int v5;
Index: clang-tools-extra/docs/clang-tidy/checks/misc/use-anonymous-namespace.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/misc/use-anonymous-namespace.rst
+++ clang-tools-extra/docs/clang-tidy/checks/misc/use-anonymous-namespace.rst
@@ -4,9 +4,7 @@
 
 
 Finds instances of ``static`` functions or variables declared at global scope
-that could instead be moved into an anonymous namespace. It also detects
-instances moved to an anonymous namespace that still keep the redundant
-``static``.
+that could instead be moved into an anonymous namespace.
 
 Anonymous namespaces are the "superior alternative" according to the C++
 Standard. ``static`` was proposed for deprecation, but later un-deprecated to
@@ -27,18 +25,4 @@
 int x;
   } // namespace
 
-.. code-block:: c++
-
-  // Bad
-  namespace {
-static void foo();
-static int x;
-  }
-
-  // Good
-  namespace {
-void foo();
-int x;
-  }  // namespace
-
 [1] `Undeprecating static `_
Index: clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.h
===
--- clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.h
+++ clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.h
@@ -16,8 +16,7 @@
 namespace misc {
 
 /// Warns when using 'static' functions or variables at global scope, and
-/// suggests moving them to an anonymous namespace. It also suggests removing
-/// 'static' if they are already inside an anonymous namespace.
+/// suggests moving them to an anonymous namespace.
 ///
 /// For the user-facing documentation see:
 /// http://clang.llvm.org/extra/clang-tidy/checks/modernize/use-anonymous-namespace.html
Index: clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
===
--- clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
+++ clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
@@ -25,10 +25,11 @@
   return llvm::isa(&Node);
 }
 AST_MATCHER(VarDecl, isStaticDataMember) { return Node.isStaticDataMember(); }
-} // namespace
 
-static bool isInAnonymousNamespace(const Decl *Decl) {
-  const DeclContext *DC = Decl->getDeclContext();
+AST_POLYMORPHIC_MATCHER(isInAnonymousNamespace,
+AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl,
+VarDecl)) {
+  const DeclContext *DC = Node.getDeclContext();
   if (DC && DC->isNamespace()) {
 const auto *ND = llvm::cast(DC);
 if (ND && ND->isAnonymousNamespace())
@@ -36,25 +37,25 @@
   }
   return false;
 }
+} // namespace
 
 template 
 void UseAnonymousNamespaceCheck::processMatch(const T *MatchedDecl) {
   StringRef Type = llvm::isa(MatchedDecl) ? "variable" : "function";
-  if (isInAnonymousNamespace(MatchedDecl))
-diag(Matc

[PATCH] D137107: Allow MS extension: support of constexpr with __declspec(dllimport).

2022-12-02 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam updated this revision to Diff 479652.
zahiraam marked 2 inline comments as done.

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

https://reviews.llvm.org/D137107

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/lib/CodeGen/CGDeclCXX.cpp
  clang/lib/CodeGen/CGExprConstant.cpp
  clang/test/CodeGenCXX/dllimport.cpp
  clang/test/Sema/dllimport.c
  clang/test/SemaCXX/PR19955.cpp
  clang/test/SemaCXX/constant-expression-cxx11.cpp
  clang/test/SemaCXX/dllimport-constexpr.cpp

Index: clang/test/SemaCXX/dllimport-constexpr.cpp
===
--- clang/test/SemaCXX/dllimport-constexpr.cpp
+++ clang/test/SemaCXX/dllimport-constexpr.cpp
@@ -40,7 +40,6 @@
 // constexpr initialization doesn't work for dllimport things.
 // expected-error@+1{{must be initialized by a constant expression}}
 constexpr void (*constexpr_import_func)() = &imported_func;
-// expected-error@+1{{must be initialized by a constant expression}}
 constexpr int *constexpr_import_int = &imported_int;
 // expected-error@+1{{must be initialized by a constant expression}}
 constexpr void (Foo::*constexpr_memptr)() = &Foo::imported_method;
@@ -60,3 +59,11 @@
   // expected-note@+1 {{requested here}}
   StaticConstexpr::g_fp();
 }
+
+extern int __declspec(dllimport) val;
+constexpr int& val_ref = val;
+
+void assigndllimporttoconst () {
+  extern int _declspec(dllimport) val;
+  constexpr int& val_ref = val;
+}
Index: clang/test/SemaCXX/constant-expression-cxx11.cpp
===
--- clang/test/SemaCXX/constant-expression-cxx11.cpp
+++ clang/test/SemaCXX/constant-expression-cxx11.cpp
@@ -1595,7 +1595,7 @@
   void f(int k) { // expected-note {{here}}
 int arr[k]; // expected-warning {{C99}} expected-note {{function parameter 'k'}}
 constexpr int n = 1 +
-sizeof(arr) // expected-error {{constant expression}}
+sizeof(arr)  // expected-error{{constexpr variable 'n' must be initialized by a constant expression}}
 * 3;
   }
 }
Index: clang/test/SemaCXX/PR19955.cpp
===
--- clang/test/SemaCXX/PR19955.cpp
+++ clang/test/SemaCXX/PR19955.cpp
@@ -2,7 +2,7 @@
 // RUN: %clang_cc1 -triple i686-mingw32 -verify -std=c++11 %s
 
 extern int __attribute__((dllimport)) var;
-constexpr int *varp = &var; // expected-error {{must be initialized by a constant expression}}
+constexpr int *varp = &var;
 
 extern __attribute__((dllimport)) void fun();
 constexpr void (*funp)(void) = &fun; // expected-error {{must be initialized by a constant expression}}
Index: clang/test/Sema/dllimport.c
===
--- clang/test/Sema/dllimport.c
+++ clang/test/Sema/dllimport.c
@@ -38,7 +38,7 @@
 int GlobalDeclAttr __attribute__((dllimport));
 
 // Address of variables can't be used for initialization in C language modes.
-int *VarForInit = &GlobalDecl; // expected-error{{initializer element is not a compile-time constant}}
+int *VarForInit = &GlobalDecl;
 
 // Not allowed on definitions.
 __declspec(dllimport) extern int ExternGlobalInit = 1; // expected-error{{definition of dllimport data}}
Index: clang/test/CodeGenCXX/dllimport.cpp
===
--- clang/test/CodeGenCXX/dllimport.cpp
+++ clang/test/CodeGenCXX/dllimport.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -no-enable-noundef-analysis -triple i686-windows-msvc   -fno-rtti -fno-threadsafe-statics -fms-extensions -emit-llvm -std=c++1y -O0 -o - %s -DMSABI -w | FileCheck --check-prefix=MSC --check-prefix=M32 %s
-// RUN: %clang_cc1 -no-enable-noundef-analysis -triple x86_64-windows-msvc -fno-rtti -fno-threadsafe-statics -fms-extensions -emit-llvm -std=c++1y -O0 -o - %s -DMSABI -w | FileCheck --check-prefix=MSC --check-prefix=M64 %s
+// RUN: %clang_cc1 -no-enable-noundef-analysis -triple i686-windows-msvc   -fno-rtti -fno-threadsafe-statics -fms-extensions -emit-llvm -std=c++1y -O0 -o - %s -DMSABI -w | FileCheck --check-prefix=MSC --check-prefix=M32 --check-prefix=GL32 %s
+// RUN: %clang_cc1 -no-enable-noundef-analysis -triple x86_64-windows-msvc -fno-rtti -fno-threadsafe-statics -fms-extensions -emit-llvm -std=c++1y -O0 -o - %s -DMSABI -w | FileCheck --check-prefix=MSC --check-prefix=M64 --check-prefix=GL64 %s
 // RUN: %clang_cc1 -no-enable-noundef-analysis -triple i686-windows-gnu-fno-rtti -fno-threadsafe-statics -fms-extensions -emit-llvm -std=c++1y -O0 -o - %s -w | FileCheck --check-prefix=GNU --check-prefix=G32 %s
 // RUN: %clang_cc1 -no-enable-noundef-analysis -triple x86_64-windows-gnu  -fno-rtti -fno-threadsafe-statics -fms-extensions -emit-llvm -std=c++1y -O0 -o - %s -w | FileCheck --check-prefix=GNU %s
 // RUN: %clang_cc1 -no-enable-noundef-analysis -triple i686-windows-msvc   -fno-rtti -fno-threadsafe-statics -fms-extensions -fms-compatibility-version=18.00 -emit-llvm -std=c++1y -O1 

[PATCH] D139173: [clang] Add test for CWG600

2022-12-02 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added inline comments.



Comment at: clang/test/CXX/drs/dr6xx.cpp:18
+  sp->f(2);
+  sp->f(2.2); // expected-error {{is a private member}}
+}

Maybe add a comment above this saying something like:

```
// access control is applied after overload resolution
// [class.access.general]p4 "For an overload set, access control is applied 
only to the function selected by overload resolution."
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139173

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


[PATCH] D139173: [clang] Add test for CWG600

2022-12-02 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added a comment.

Thank you for updating the DR statuses! This is much appreciated.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139173

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


[PATCH] D139173: [clang] Add test for CWG600

2022-12-02 Thread Vlad Serebrennikov via Phabricator via cfe-commits
Endill added inline comments.



Comment at: clang/test/CXX/drs/dr6xx.cpp:18
+  sp->f(2);
+  sp->f(2.2); // expected-error {{is a private member}}
+}

shafik wrote:
> Maybe add a comment above this saying something like:
> 
> ```
> // access control is applied after overload resolution
> // [class.access.general]p4 "For an overload set, access control is applied 
> only to the function selected by overload resolution."
> ```
I tend to like the idea, but I wonder about general rule for adding such 
explanations. Currently DR tests contain very little of those. 

If we're going to add explanations, we should also decide whether we're going 
to cite the standard, or paraphrase (and/or) explain intent. My concern is that 
both references to standard and citations could grow old relatively quickly, 
and we don't have any tools to help, at least yet.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139173

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


[clang-tools-extra] 4fd0c14 - Link with missing libs to fix broken shared unittest build

2022-12-02 Thread Jun Zhang via cfe-commits

Author: Jun Zhang
Date: 2022-12-03T01:10:13+08:00
New Revision: 4fd0c14a17f91fb7b0d188b509eb3dbdfbfec01a

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

LOG: Link with missing libs to fix broken shared unittest build

Oops, I think we should link with this as well.

Signed-off-by: Jun Zhang 

Added: 


Modified: 
clang-tools-extra/include-cleaner/unittests/CMakeLists.txt

Removed: 




diff  --git a/clang-tools-extra/include-cleaner/unittests/CMakeLists.txt 
b/clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
index d911b5df70c50..e5a4180a53e31 100644
--- a/clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
+++ b/clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
@@ -22,6 +22,7 @@ clang_target_link_libraries(ClangIncludeCleanerTests
   clangAST
   clangBasic
   clangFrontend
+  clangFormat
   clangLex
   clangToolingInclusionsStdlib
   )



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


[PATCH] D139197: [clang-tidy] Do not warn about redundant static in misc-use-anonymous-namespace

2022-12-02 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp updated this revision to Diff 479656.
carlosgalvezp added a comment.

Simplify anonymous namespace matcher.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139197

Files:
  clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
  clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.h
  clang-tools-extra/docs/clang-tidy/checks/misc/use-anonymous-namespace.rst
  clang-tools-extra/test/clang-tidy/checkers/misc/use-anonymous-namespace.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/misc/use-anonymous-namespace.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/misc/use-anonymous-namespace.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/misc/use-anonymous-namespace.cpp
@@ -5,13 +5,6 @@
 static int v1;
 // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: variable 'v1' declared 'static', move to anonymous namespace instead
 
-namespace {
-  static void f2();
-  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: function 'f2' declared 'static' in anonymous namespace, remove 'static'
-  static int v2;
-  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: variable 'v2' declared 'static' in anonymous namespace, remove 'static'
-}
-
 namespace a {
   static void f3();
   // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: function 'f3' declared 'static', move to anonymous namespace instead
@@ -19,15 +12,6 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: variable 'v3' declared 'static', move to anonymous namespace instead
 }
 
-namespace a {
-namespace {
-  static void f4();
-  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: function 'f4' declared 'static' in anonymous namespace, remove 'static'
-  static int v4;
-  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: variable 'v4' declared 'static' in anonymous namespace, remove 'static'
-}
-}
-
 // OK
 void f5();
 int v5;
Index: clang-tools-extra/docs/clang-tidy/checks/misc/use-anonymous-namespace.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/misc/use-anonymous-namespace.rst
+++ clang-tools-extra/docs/clang-tidy/checks/misc/use-anonymous-namespace.rst
@@ -4,9 +4,7 @@
 
 
 Finds instances of ``static`` functions or variables declared at global scope
-that could instead be moved into an anonymous namespace. It also detects
-instances moved to an anonymous namespace that still keep the redundant
-``static``.
+that could instead be moved into an anonymous namespace.
 
 Anonymous namespaces are the "superior alternative" according to the C++
 Standard. ``static`` was proposed for deprecation, but later un-deprecated to
@@ -27,18 +25,4 @@
 int x;
   } // namespace
 
-.. code-block:: c++
-
-  // Bad
-  namespace {
-static void foo();
-static int x;
-  }
-
-  // Good
-  namespace {
-void foo();
-int x;
-  }  // namespace
-
 [1] `Undeprecating static `_
Index: clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.h
===
--- clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.h
+++ clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.h
@@ -16,8 +16,7 @@
 namespace misc {
 
 /// Warns when using 'static' functions or variables at global scope, and
-/// suggests moving them to an anonymous namespace. It also suggests removing
-/// 'static' if they are already inside an anonymous namespace.
+/// suggests moving them to an anonymous namespace.
 ///
 /// For the user-facing documentation see:
 /// http://clang.llvm.org/extra/clang-tidy/checks/modernize/use-anonymous-namespace.html
Index: clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
===
--- clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
+++ clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
@@ -25,36 +25,29 @@
   return llvm::isa(&Node);
 }
 AST_MATCHER(VarDecl, isStaticDataMember) { return Node.isStaticDataMember(); }
-} // namespace
 
-static bool isInAnonymousNamespace(const Decl *Decl) {
-  const DeclContext *DC = Decl->getDeclContext();
-  if (DC && DC->isNamespace()) {
-const auto *ND = llvm::cast(DC);
-if (ND && ND->isAnonymousNamespace())
-  return true;
-  }
-  return false;
+AST_MATCHER(Decl, isInAnonymousNamespace) {
+  return Node.isInAnonymousNamespace();
 }
+} // namespace
 
 template 
 void UseAnonymousNamespaceCheck::processMatch(const T *MatchedDecl) {
   StringRef Type = llvm::isa(MatchedDecl) ? "variable" : "function";
-  if (isInAnonymousNamespace(MatchedDecl))
-diag(MatchedDecl->getLocation(), "%0 %1 declared 'static' in "
- "anonymous namespace, remove 'static'")
-<< Type << MatchedDecl;
-  else
-diag(Matche

[PATCH] D138511: [CodeGen][AArch64] Fix AArch64ABIInfo::EmitAAPCSVAArg crash with empty record type in variadic arg

2022-12-02 Thread Yurong via Phabricator via cfe-commits
yronglin added a comment.

pin~


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138511

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


[PATCH] D138792: [AArch64] Improve TargetParser API

2022-12-02 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added a comment.

Hi, I bisected this change to lead to a couple of test failures when building 
with `LLVM_LINK_LLVM_DYLIB`. In the past, this had to do with global variable 
initialization order, but nothing immediately jumps to my eye in this patch. Is 
`AARCH64_ARCH` used to define global variables?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138792

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


[PATCH] D138939: [WIP][clang] adds a way to provide user-oriented reasons

2022-12-02 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb added a comment.

In D138939#3965985 , @tschuett wrote:

> Then Sarif was a distraction. Still to reduce boilerplate and for A/B testing:
>
>   enum class DiagnosticMode {
> Legacy,
> UserOriented,
> Default = Legacy
>   }

It took a fair bit of squinting and coffee, but I think I get it now. Having 
SARIF will be good for option 2: I hadn't realised this was at the Clang API 
level and not an enum for users to toggle on the command line! Thanks for your 
patience, I'll implement this now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138939

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


[PATCH] D139197: [clang-tidy] Do not warn about redundant static in misc-use-anonymous-namespace

2022-12-02 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

> This shouldn't be a blocker for this patch though, it's just removing 
> functionality that belongs in another check. As said, the check is 1 day old 
> so it's unlikely anyone is relying on it yet :)

SGTM in general.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139197

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


[PATCH] D128677: [clangd] Add support for generating #import edits

2022-12-02 Thread David Goldman via Phabricator via cfe-commits
dgoldman updated this revision to Diff 479659.
dgoldman marked 4 inline comments as done.
dgoldman added a comment.

Fixes for review


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128677

Files:
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/Headers.cpp
  clang-tools-extra/clangd/Headers.h
  clang-tools-extra/clangd/IncludeFixer.cpp
  clang-tools-extra/clangd/IncludeFixer.h
  clang-tools-extra/clangd/unittests/HeadersTests.cpp
  clang/include/clang/Tooling/Inclusions/HeaderIncludes.h
  clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
  clang/unittests/Tooling/HeaderIncludesTest.cpp

Index: clang/unittests/Tooling/HeaderIncludesTest.cpp
===
--- clang/unittests/Tooling/HeaderIncludesTest.cpp
+++ clang/unittests/Tooling/HeaderIncludesTest.cpp
@@ -20,10 +20,12 @@
 
 class HeaderIncludesTest : public ::testing::Test {
 protected:
-  std::string insert(llvm::StringRef Code, llvm::StringRef Header) {
+  std::string insert(llvm::StringRef Code, llvm::StringRef Header,
+ IncludeDirective Directive = IncludeDirective::Include) {
 HeaderIncludes Includes(FileName, Code, Style);
 assert(Header.startswith("\"") || Header.startswith("<"));
-auto R = Includes.insert(Header.trim("\"<>"), Header.startswith("<"));
+auto R =
+Includes.insert(Header.trim("\"<>"), Header.startswith("<"), Directive);
 if (!R)
   return std::string(Code);
 auto Result = applyAllReplacements(Code, Replacements(*R));
@@ -60,6 +62,17 @@
   EXPECT_EQ(Expected, insert(Code, "\"a2.h\""));
 }
 
+TEST_F(HeaderIncludesTest, InsertImportWithSameInclude) {
+  std::string Code = "#include \"a.h\"\n";
+  std::string Expected = Code + "#import \"a.h\"\n";
+  EXPECT_EQ(Expected, insert(Code, "\"a.h\"", IncludeDirective::Import));
+}
+
+TEST_F(HeaderIncludesTest, DontInsertAlreadyImported) {
+  std::string Code = "#import \"a.h\"\n";
+  EXPECT_EQ(Code, insert(Code, "\"a.h\"", IncludeDirective::Import));
+}
+
 TEST_F(HeaderIncludesTest, NoExistingIncludeWithDefine) {
   std::string Code = "#ifndef A_H\n"
  "#define A_H\n"
Index: clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
===
--- clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
+++ clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
@@ -296,7 +296,9 @@
   addExistingInclude(
   Include(Matches[2],
   tooling::Range(
-  Offset, std::min(Line.size() + 1, Code.size() - Offset))),
+  Offset, std::min(Line.size() + 1, Code.size() - Offset)),
+  Matches[1] == "include" ? tooling::IncludeDirective::Include
+  : tooling::IncludeDirective::Import),
   NextLineOffset);
 }
 Offset = NextLineOffset;
@@ -342,16 +344,18 @@
 }
 
 llvm::Optional
-HeaderIncludes::insert(llvm::StringRef IncludeName, bool IsAngled) const {
+HeaderIncludes::insert(llvm::StringRef IncludeName, bool IsAngled,
+   IncludeDirective Directive) const {
   assert(IncludeName == trimInclude(IncludeName));
   // If a  ("header") already exists in code, "header" () with
-  // different quotation will still be inserted.
+  // different quotation and/or directive will still be inserted.
   // FIXME: figure out if this is the best behavior.
   auto It = ExistingIncludes.find(IncludeName);
   if (It != ExistingIncludes.end())
 for (const auto &Inc : It->second)
-  if ((IsAngled && StringRef(Inc.Name).startswith("<")) ||
-  (!IsAngled && StringRef(Inc.Name).startswith("\"")))
+  if (Inc.Directive == Directive &&
+  ((IsAngled && StringRef(Inc.Name).startswith("<")) ||
+   (!IsAngled && StringRef(Inc.Name).startswith("\""
 return llvm::None;
   std::string Quoted =
   std::string(llvm::formatv(IsAngled ? "<{0}>" : "\"{0}\"", IncludeName));
@@ -372,7 +376,9 @@
   }
   assert(InsertOffset <= Code.size());
   std::string NewInclude =
-  std::string(llvm::formatv("#include {0}\n", QuotedName));
+  Directive == IncludeDirective::Include
+  ? std::string(llvm::formatv("#include {0}\n", QuotedName))
+  : std::string(llvm::formatv("#import {0}\n", QuotedName));
   // When inserting headers at end of the code, also append '\n' to the code
   // if it does not end with '\n'.
   // FIXME: when inserting multiple #includes at the end of code, only one
Index: clang/include/clang/Tooling/Inclusions/HeaderIncludes.h
===
--- clang/include/clang/Tooling/Inclusions/HeaderIncludes.h
+++ clang/include/clang/Tooling/Inclusions/HeaderIncludes.h
@@ -44,6 +44,8 @@
   SmallVector CategoryRegexs;
 };
 
+enum IncludeDirective { Include, Import };
+
 /// Generates replacements for insertin

[PATCH] D135658: demangle OptFunction trace names

2022-12-02 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri requested changes to this revision.
lebedev.ri added a comment.
This revision now requires changes to proceed.

Old pass manager is dead. There is no point in making improvements to it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135658

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


[PATCH] D138939: [WIP][clang] adds a way to provide user-oriented reasons

2022-12-02 Thread Thorsten via Phabricator via cfe-commits
tschuett added a comment.

Maybe the kind/amount of information printed ( `DiagnosticMode` ) and the 
output device (console/sarif) are orthogonal issues.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138939

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


  1   2   >