[PATCH] D142587: [clang-tidy] Improved too-small-loop-variable with bit-field support

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

In D142587#4152943 , @Eugene.Zelenko 
wrote:

> @carlosgalvezp: Sorry, there are too much Clang specifics in this patch, so I 
> could not be reviewer.

No prob, thanks for letting us know :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142587

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


[PATCH] D144790: [clang-tidy] readability-identifier-naming.HungarianNotation: rename CharPrinter to CharPointer

2023-02-25 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp accepted this revision.
carlosgalvezp added a comment.
This revision is now accepted and ready to land.

Good catch, thanks for fixing!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144790

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


[PATCH] D144074: [clangd] Hide inlay hints when using a macro as a calling argument that with a param comment

2023-02-25 Thread Nathan Ridge via Phabricator via cfe-commits
nridge accepted this revision.
nridge added a comment.
This revision is now accepted and ready to land.

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144074

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


[PATCH] D142587: [clang-tidy] Improved too-small-loop-variable with bit-field support

2023-02-25 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

@carlosgalvezp: Sorry, there are too much Clang specifics in this patch, so I 
could not be reviewer.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142587

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


[clang] 4dd4eb9 - [Driver][FreeBSD] Further simplify the Driver handling for older FreeBSD releases

2023-02-25 Thread Brad Smith via cfe-commits

Author: Brad Smith
Date: 2023-02-25T20:36:04-05:00
New Revision: 4dd4eb939caef1138c655e22bb4adc8978f16427

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

LOG: [Driver][FreeBSD] Further simplify the Driver handling for older FreeBSD 
releases

Since GCC 4.2 was removed with 10.0 and newer the respective Driver bits can be 
removed.

Reviewed By: dim

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/FreeBSD.cpp
clang/lib/Driver/ToolChains/FreeBSD.h

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp 
b/clang/lib/Driver/ToolChains/FreeBSD.cpp
index f3c60a405883..4ce0087cbe24 100644
--- a/clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -441,30 +441,14 @@ void FreeBSD::addLibCxxIncludePaths(const 
llvm::opt::ArgList &DriverArgs,
concat(getDriver().SysRoot, "/usr/include/c++/v1"));
 }
 
-void FreeBSD::addLibStdCxxIncludePaths(
-const llvm::opt::ArgList &DriverArgs,
-llvm::opt::ArgStringList &CC1Args) const {
-  addLibStdCXXIncludePaths(concat(getDriver().SysRoot, "/usr/include/c++/4.2"),
-   "", "", DriverArgs, CC1Args);
-}
-
 void FreeBSD::AddCXXStdlibLibArgs(const ArgList &Args,
   ArgStringList &CmdArgs) const {
-  CXXStdlibType Type = GetCXXStdlibType(Args);
   unsigned Major = getTriple().getOSMajorVersion();
   bool Profiling = Args.hasArg(options::OPT_pg) && Major != 0 && Major < 14;
 
-  switch (Type) {
-  case ToolChain::CST_Libcxx:
-CmdArgs.push_back(Profiling ? "-lc++_p" : "-lc++");
-if (Args.hasArg(options::OPT_fexperimental_library))
-  CmdArgs.push_back("-lc++experimental");
-break;
-
-  case ToolChain::CST_Libstdcxx:
-CmdArgs.push_back(Profiling ? "-lstdc++_p" : "-lstdc++");
-break;
-  }
+  CmdArgs.push_back(Profiling ? "-lc++_p" : "-lc++");
+  if (Args.hasArg(options::OPT_fexperimental_library))
+CmdArgs.push_back("-lc++experimental");
 }
 
 void FreeBSD::AddCudaIncludeArgs(const ArgList &DriverArgs,

diff  --git a/clang/lib/Driver/ToolChains/FreeBSD.h 
b/clang/lib/Driver/ToolChains/FreeBSD.h
index b12814a444c4..9b24ef1a1e1c 100644
--- a/clang/lib/Driver/ToolChains/FreeBSD.h
+++ b/clang/lib/Driver/ToolChains/FreeBSD.h
@@ -71,9 +71,6 @@ class LLVM_LIBRARY_VISIBILITY FreeBSD : public Generic_ELF {
 
   void addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
  llvm::opt::ArgStringList &CC1Args) const override;
-  void
-  addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
-   llvm::opt::ArgStringList &CC1Args) const override;
   void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs) const override;
   void AddCudaIncludeArgs(const llvm::opt::ArgList &DriverArgs,



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


[PATCH] D144778: [Driver][FreeBSD] Further simplify the Driver handling for older FreeBSD releases

2023-02-25 Thread Brad Smith 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 rG4dd4eb939cae: [Driver][FreeBSD] Further simplify the Driver 
handling for older FreeBSD… (authored by brad).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144778

Files:
  clang/lib/Driver/ToolChains/FreeBSD.cpp
  clang/lib/Driver/ToolChains/FreeBSD.h


Index: clang/lib/Driver/ToolChains/FreeBSD.h
===
--- clang/lib/Driver/ToolChains/FreeBSD.h
+++ clang/lib/Driver/ToolChains/FreeBSD.h
@@ -71,9 +71,6 @@
 
   void addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
  llvm::opt::ArgStringList &CC1Args) const override;
-  void
-  addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
-   llvm::opt::ArgStringList &CC1Args) const override;
   void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs) const override;
   void AddCudaIncludeArgs(const llvm::opt::ArgList &DriverArgs,
Index: clang/lib/Driver/ToolChains/FreeBSD.cpp
===
--- clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -441,30 +441,14 @@
concat(getDriver().SysRoot, "/usr/include/c++/v1"));
 }
 
-void FreeBSD::addLibStdCxxIncludePaths(
-const llvm::opt::ArgList &DriverArgs,
-llvm::opt::ArgStringList &CC1Args) const {
-  addLibStdCXXIncludePaths(concat(getDriver().SysRoot, "/usr/include/c++/4.2"),
-   "", "", DriverArgs, CC1Args);
-}
-
 void FreeBSD::AddCXXStdlibLibArgs(const ArgList &Args,
   ArgStringList &CmdArgs) const {
-  CXXStdlibType Type = GetCXXStdlibType(Args);
   unsigned Major = getTriple().getOSMajorVersion();
   bool Profiling = Args.hasArg(options::OPT_pg) && Major != 0 && Major < 14;
 
-  switch (Type) {
-  case ToolChain::CST_Libcxx:
-CmdArgs.push_back(Profiling ? "-lc++_p" : "-lc++");
-if (Args.hasArg(options::OPT_fexperimental_library))
-  CmdArgs.push_back("-lc++experimental");
-break;
-
-  case ToolChain::CST_Libstdcxx:
-CmdArgs.push_back(Profiling ? "-lstdc++_p" : "-lstdc++");
-break;
-  }
+  CmdArgs.push_back(Profiling ? "-lc++_p" : "-lc++");
+  if (Args.hasArg(options::OPT_fexperimental_library))
+CmdArgs.push_back("-lc++experimental");
 }
 
 void FreeBSD::AddCudaIncludeArgs(const ArgList &DriverArgs,


Index: clang/lib/Driver/ToolChains/FreeBSD.h
===
--- clang/lib/Driver/ToolChains/FreeBSD.h
+++ clang/lib/Driver/ToolChains/FreeBSD.h
@@ -71,9 +71,6 @@
 
   void addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
  llvm::opt::ArgStringList &CC1Args) const override;
-  void
-  addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
-   llvm::opt::ArgStringList &CC1Args) const override;
   void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs) const override;
   void AddCudaIncludeArgs(const llvm::opt::ArgList &DriverArgs,
Index: clang/lib/Driver/ToolChains/FreeBSD.cpp
===
--- clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -441,30 +441,14 @@
concat(getDriver().SysRoot, "/usr/include/c++/v1"));
 }
 
-void FreeBSD::addLibStdCxxIncludePaths(
-const llvm::opt::ArgList &DriverArgs,
-llvm::opt::ArgStringList &CC1Args) const {
-  addLibStdCXXIncludePaths(concat(getDriver().SysRoot, "/usr/include/c++/4.2"),
-   "", "", DriverArgs, CC1Args);
-}
-
 void FreeBSD::AddCXXStdlibLibArgs(const ArgList &Args,
   ArgStringList &CmdArgs) const {
-  CXXStdlibType Type = GetCXXStdlibType(Args);
   unsigned Major = getTriple().getOSMajorVersion();
   bool Profiling = Args.hasArg(options::OPT_pg) && Major != 0 && Major < 14;
 
-  switch (Type) {
-  case ToolChain::CST_Libcxx:
-CmdArgs.push_back(Profiling ? "-lc++_p" : "-lc++");
-if (Args.hasArg(options::OPT_fexperimental_library))
-  CmdArgs.push_back("-lc++experimental");
-break;
-
-  case ToolChain::CST_Libstdcxx:
-CmdArgs.push_back(Profiling ? "-lstdc++_p" : "-lstdc++");
-break;
-  }
+  CmdArgs.push_back(Profiling ? "-lc++_p" : "-lc++");
+  if (Args.hasArg(options::OPT_fexperimental_library))
+CmdArgs.push_back("-lc++experimental");
 }
 
 void FreeBSD::AddCudaIncludeArgs(const ArgList &DriverArgs,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144778: [Driver][FreeBSD] Further simplify the Driver handling for older FreeBSD releases

2023-02-25 Thread Brad Smith via Phabricator via cfe-commits
brad added a comment.

In D144778#4152443 , @dim wrote:

> LGTM, are there no test cases which are affected by this?

The stdc++ library test for FreeBSD 9 was removed in the previous diff and I 
don't see anything testing the header path.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144778

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


[PATCH] D144802: clang: Add __builtin_elementwise_round

2023-02-25 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm created this revision.
arsenm added reviewers: aaron.ballman, RKSimon, fhahn, junaire, bob80905, 
python3kgae, erichkeane.
Herald added a subscriber: StephenFan.
Herald added a project: All.
arsenm requested review of this revision.
Herald added a subscriber: wdng.

This would only differ from the existing __builtin_elementwise_roundeven
with floating point exceptions. I don't really care about the distinction
other than futureproofing for strictfp support.


https://reviews.llvm.org/D144802

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/Basic/Builtins.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtins-elementwise-math.c
  clang/test/Sema/builtins-elementwise-math.c

Index: clang/test/Sema/builtins-elementwise-math.c
===
--- clang/test/Sema/builtins-elementwise-math.c
+++ clang/test/Sema/builtins-elementwise-math.c
@@ -416,6 +416,32 @@
   // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned4' (vector of 4 'unsigned int' values))}}
 }
 
+void test_builtin_elementwise_round(int i, float f, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
+
+  struct Foo s = __builtin_elementwise_round(f);
+  // expected-error@-1 {{initializing 'struct Foo' with an expression of incompatible type 'float'}}
+
+  i = __builtin_elementwise_round();
+  // expected-error@-1 {{too few arguments to function call, expected 1, have 0}}
+
+  i = __builtin_elementwise_round(i);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'int')}}
+
+  i = __builtin_elementwise_round(f, f);
+  // expected-error@-1 {{too many arguments to function call, expected 1, have 2}}
+
+  u = __builtin_elementwise_round(u);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned int')}}
+
+  uv = __builtin_elementwise_round(uv);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned4' (vector of 4 'unsigned int' values))}}
+
+  // FIXME: Error should not mention integer
+  _Complex float c1, c2;
+  c1 = __builtin_elementwise_round(c1);
+  // expected-error@-1 {{1st argument must be a vector, integer or floating point type (was '_Complex float')}}
+}
+
 void test_builtin_elementwise_sin(int i, float f, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
 
   struct Foo s = __builtin_elementwise_sin(f);
Index: clang/test/CodeGen/builtins-elementwise-math.c
===
--- clang/test/CodeGen/builtins-elementwise-math.c
+++ clang/test/CodeGen/builtins-elementwise-math.c
@@ -435,6 +435,22 @@
   vf2 = __builtin_elementwise_roundeven(vf1);
 }
 
+void test_builtin_elementwise_round(float f1, float f2, double d1, double d2,
+float4 vf1, float4 vf2) {
+  // CHECK-LABEL: define void @test_builtin_elementwise_round(
+  // CHECK:  [[F1:%.+]] = load float, ptr %f1.addr, align 4
+  // CHECK-NEXT:  call float @llvm.round.f32(float [[F1]])
+  f2 = __builtin_elementwise_round(f1);
+
+  // CHECK:  [[D1:%.+]] = load double, ptr %d1.addr, align 8
+  // CHECK-NEXT: call double @llvm.round.f64(double [[D1]])
+  d2 = __builtin_elementwise_round(d1);
+
+  // CHECK:  [[VF1:%.+]] = load <4 x float>, ptr %vf1.addr, align 16
+  // CHECK-NEXT: call <4 x float> @llvm.round.v4f32(<4 x float> [[VF1]])
+  vf2 = __builtin_elementwise_round(vf1);
+}
+
 void test_builtin_elementwise_sin(float f1, float f2, double d1, double d2,
   float4 vf1, float4 vf2) {
   // CHECK-LABEL: define void @test_builtin_elementwise_sin(
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -2619,6 +2619,7 @@
   case Builtin::BI__builtin_elementwise_log2:
   case Builtin::BI__builtin_elementwise_log10:
   case Builtin::BI__builtin_elementwise_roundeven:
+  case Builtin::BI__builtin_elementwise_round:
   case Builtin::BI__builtin_elementwise_sin:
   case Builtin::BI__builtin_elementwise_trunc:
   case Builtin::BI__builtin_elementwise_canonicalize: {
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -3106,6 +3106,9 @@
   case Builtin::BI__builtin_elementwise_roundeven:
 return RValue::get(emitUnaryBuiltin(*this, E, llvm::Intrinsic::roundeven,
 "elt.roundeven"));
+  case Builtin::BI__builtin_elementwise_round:
+return RValue::get(emitUnaryBuiltin(*this, E, llvm::Intrinsic::round,
+"elt.round"));
   case Builtin::BI__builtin_elementwise_sin:
 return RValue::get(
 emitUnaryBuiltin(*this, E, llvm::Intrinsic::sin, "elt.sin"));
Index: clang/include/clang/Basic/Builtins.def
==

[PATCH] D144537: [clang-format] Don't move qualifiers past pointers-to-member

2023-02-25 Thread Owen Pan via Phabricator via cfe-commits
owenpan added a comment.

In D144537#4152225 , @rymiel wrote:

> In D144537#4145545 , 
> @MyDeveloperDay wrote:
>
>> maybe we should cherry pick into 16?
>
> I don't know how to do backports and I don't want to mess it up

It's easy. Just reopen the issue, add it to the release milestone, and add a 
`/check-pick` comment and the `release:backport` label. See also 
https://llvm.org/docs/GitHub.html#backporting-fixes-to-the-release-branches.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144537

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


[PATCH] D144790: [clang-tidy] readability-identifier-naming.HungarianNotation: rename CharPrinter to CharPointer

2023-02-25 Thread Alexis Murzeau via Phabricator via cfe-commits
amurzeau created this revision.
amurzeau added reviewers: njames93, alexfh, kazu, dougpuob, aaron.ballman, 
carlosgalvezp.
Herald added a subscriber: xazax.hun.
Herald added a project: All.
amurzeau requested review of this revision.
Herald added subscribers: cfe-commits, aheejin.
Herald added a project: clang-tools-extra.

The CharPrinter is a typo and should have been named CharPointer as it
configures the hungarian notation prefix for char pointers (char*).

As all configuration options within
readability-identifier-naming.HungarianNotation.CString.* were not read
at all in the previous clang-tidy version (fixed in D144431 
), this option
rename won't break existing users.

A note in release notes is added to let users know these options were
renamed.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144790

Files:
  clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/readability/identifier-naming.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/hungarian-notation2/.clang-tidy

Index: clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/hungarian-notation2/.clang-tidy
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/hungarian-notation2/.clang-tidy
+++ clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/hungarian-notation2/.clang-tidy
@@ -120,11 +120,11 @@
 value:  custp
   - key:readability-identifier-naming.HungarianNotation.DerivedType.FunctionPointer
 value:  custfn
-  - key:readability-identifier-naming.HungarianNotation.CString.CharPrinter
+  - key:readability-identifier-naming.HungarianNotation.CString.CharPointer
 value:  custsz
   - key:readability-identifier-naming.HungarianNotation.CString.CharArray
 value:  custsz
-  - key:readability-identifier-naming.HungarianNotation.CString.WideCharPrinter
+  - key:readability-identifier-naming.HungarianNotation.CString.WideCharPointer
 value:  custwsz
   - key:readability-identifier-naming.HungarianNotation.CString.WideCharArray
 value:  custwsz
Index: clang-tools-extra/docs/clang-tidy/checks/readability/identifier-naming.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/readability/identifier-naming.rst
+++ clang-tools-extra/docs/clang-tidy/checks/readability/identifier-naming.rst
@@ -2584,9 +2584,9 @@
 - :option:`HungarianNotation.DerivedType.Pointer`
 - :option:`HungarianNotation.DerivedType.FunctionPointer`
 
-- :option:`HungarianNotation.CString.CharPrinter`
+- :option:`HungarianNotation.CString.CharPointer`
 - :option:`HungarianNotation.CString.CharArray`
-- :option:`HungarianNotation.CString.WideCharPrinter`
+- :option:`HungarianNotation.CString.WideCharPointer`
 - :option:`HungarianNotation.CString.WideCharArray`
 
 - :option:`HungarianNotation.PrimitiveType.*`
@@ -2642,7 +2642,7 @@
 FUNC_PTR fnFuncPtr = NULL;
 
 
-.. option:: HungarianNotation.CString.CharPrinter
+.. option:: HungarianNotation.CString.CharPointer
 
 When defined, the check will ensure variable name will add the prefix with
 the given string. The default prefix is `sz`.
@@ -2652,7 +2652,7 @@
 When defined, the check will ensure variable name will add the prefix with
 the given string. The default prefix is `sz`.
 
-.. option:: HungarianNotation.CString.WideCharPrinter
+.. option:: HungarianNotation.CString.WideCharPointer
 
 When defined, the check will ensure variable name will add the prefix with
 the given string. The default prefix is `wsz`.
@@ -2667,13 +2667,13 @@
 
 .. code-block:: c++
 
-// CharPrinter
+// CharPointer
 const char *NamePtr = "Name";
 
 // CharArray
 const char NameArray[] = "Name";
 
-// WideCharPrinter
+// WideCharPointer
 const wchar_t *WideNamePtr = L"Name";
 
 // WideCharArray
@@ -2683,13 +2683,13 @@
 
 .. code-block:: c++
 
-// CharPrinter
+// CharPointer
 const char *szNamePtr = "Name";
 
 // CharArray
 const char szNameArray[] = "Name";
 
-// WideCharPrinter
+// WideCharPointer
 const wchar_t *wszWideNamePtr = L"Name";
 
 // WideCharArray
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -173,6 +173,11 @@
   :doc:`readability-identifier-naming
   ` check.
 
+- Renamed `HungarianNotation.CString` options `CharPrinter` and
+  `WideCharPrinter` to `CharPointer` and `WideCharPointer` respectively in
+  :doc:`readability-identifier-naming
+  ` check.
+
 - Fixed a false positive in :doc:`readability-container-size-empty
   ` check when comparing
  

[PATCH] D140996: [c++20] P1907R1: Support for generalized non-type template arguments of scalar type.

2023-02-25 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson added a comment.

There are no AST [de]serialization tests in this PR, right? Would be nice to 
add some.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140996

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


[PATCH] D140760: [clang-tidy] Support begin/end free functions in modernize-loop-convert

2023-02-25 Thread Chris Cotter via Phabricator via cfe-commits
ccotter added a comment.

Friendly ping.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140760

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


[PATCH] D143877: [NFC] [clang] Forward forwarding reference

2023-02-25 Thread Chris Cotter via Phabricator via cfe-commits
ccotter added a comment.

@dblaikie thoughts?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143877

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


[PATCH] D143436: [clangd] Move standard options adaptor to CommandMangler

2023-02-25 Thread Dmitry Polukhin via Phabricator via cfe-commits
DmitryPolukhin updated this revision to Diff 500449.
DmitryPolukhin added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143436

Files:
  clang-tools-extra/clangd/CompileCommands.cpp
  clang-tools-extra/clangd/CompileCommands.h
  clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
  clang-tools-extra/clangd/test/Inputs/did-change-configuration-params.args
  clang-tools-extra/clangd/test/did-change-configuration-params.test
  clang-tools-extra/clangd/unittests/ClangdTests.cpp
  clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
  clang-tools-extra/clangd/unittests/SyncAPI.cpp
  clang/include/clang/Tooling/Tooling.h
  clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
  clang/lib/Tooling/Tooling.cpp

Index: clang/lib/Tooling/Tooling.cpp
===
--- clang/lib/Tooling/Tooling.cpp
+++ clang/lib/Tooling/Tooling.cpp
@@ -43,6 +43,7 @@
 #include "llvm/Option/OptTable.h"
 #include "llvm/Option/Option.h"
 #include "llvm/Support/Casting.h"
+#include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FileSystem.h"
@@ -299,6 +300,31 @@
   }
 }
 
+void addExpandedResponseFiles(std::vector &CommandLine,
+  llvm::StringRef WorkingDir,
+  llvm::cl::TokenizerCallback Tokenizer,
+  llvm::vfs::FileSystem &FS) {
+  bool SeenRSPFile = false;
+  llvm::SmallVector Argv;
+  Argv.reserve(CommandLine.size());
+  for (auto &Arg : CommandLine) {
+Argv.push_back(Arg.c_str());
+if (!Arg.empty())
+  SeenRSPFile |= Arg.front() == '@';
+  }
+  if (!SeenRSPFile)
+return;
+  llvm::BumpPtrAllocator Alloc;
+  llvm::cl::ExpansionContext ECtx(Alloc, Tokenizer);
+  llvm::Error Err =
+  ECtx.setVFS(&FS).setCurrentDir(WorkingDir).expandResponseFiles(Argv);
+  if (Err)
+llvm::errs() << Err;
+  // Don't assign directly, Argv aliases CommandLine.
+  std::vector ExpandedArgv(Argv.begin(), Argv.end());
+  CommandLine = std::move(ExpandedArgv);
+}
+
 } // namespace tooling
 } // namespace clang
 
@@ -684,7 +710,7 @@
 
   if (!Invocation.run())
 return nullptr;
- 
+
   assert(ASTs.size() == 1);
   return std::move(ASTs[0]);
 }
Index: clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
===
--- clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
+++ clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "clang/Tooling/CompilationDatabase.h"
+#include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/ConvertUTF.h"
@@ -48,28 +49,9 @@
 
 private:
   std::vector expand(std::vector Cmds) const {
-for (auto &Cmd : Cmds) {
-  bool SeenRSPFile = false;
-  llvm::SmallVector Argv;
-  Argv.reserve(Cmd.CommandLine.size());
-  for (auto &Arg : Cmd.CommandLine) {
-Argv.push_back(Arg.c_str());
-if (!Arg.empty())
-  SeenRSPFile |= Arg.front() == '@';
-  }
-  if (!SeenRSPFile)
-continue;
-  llvm::BumpPtrAllocator Alloc;
-  llvm::cl::ExpansionContext ECtx(Alloc, Tokenizer);
-  llvm::Error Err = ECtx.setVFS(FS.get())
-.setCurrentDir(Cmd.Directory)
-.expandResponseFiles(Argv);
-  if (Err)
-llvm::errs() << Err;
-  // Don't assign directly, Argv aliases CommandLine.
-  std::vector ExpandedArgv(Argv.begin(), Argv.end());
-  Cmd.CommandLine = std::move(ExpandedArgv);
-}
+for (auto &Cmd : Cmds)
+  tooling::addExpandedResponseFiles(Cmd.CommandLine, Cmd.Directory,
+Tokenizer, *FS);
 return Cmds;
   }
 
Index: clang/include/clang/Tooling/Tooling.h
===
--- clang/include/clang/Tooling/Tooling.h
+++ clang/include/clang/Tooling/Tooling.h
@@ -506,6 +506,12 @@
 void addTargetAndModeForProgramName(std::vector &CommandLine,
 StringRef InvokedAs);
 
+/// Helper function that expands response files in command line.
+void addExpandedResponseFiles(std::vector &CommandLine,
+  llvm::StringRef WorkingDir,
+  llvm::cl::TokenizerCallback Tokenizer,
+  llvm::vfs::FileSystem &FS);
+
 /// Creates a \c CompilerInvocation.
 CompilerInvocation *newInvocation(DiagnosticsEngine *Diagnostics,
   ArrayRef CC1Args,
Index: clang-tools-extra/clangd/unittests/SyncAPI.cpp
===
--- clang-tools-extra/clangd

[PATCH] D143851: [clang-tidy] Tweak 'rule of 3/5' checks to allow defaulting a destructor outside the class.

2023-02-25 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson added a comment.

friendly ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143851

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


[PATCH] D142587: [clang-tidy] Improved too-small-loop-variable with bit-field support

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

Thanks for the fix! I have some suggestions for improved readability.




Comment at: 
clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp:97
 
 /// Returns the magnitude bits of an integer type.
+static std::pair

Having an `std::pair` is a bit hard to read, as it's not clear what each 
element of the pair represents. Could you replace it with something like this, 
for improved readability and maintainability? Then you can also skip the 
`utility` header.

```
struct MagnitudeBits
{
  unsigned Width;
  bool IsBitField;
};
```





Comment at: 
clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp:186
+  auto Msg =
+  diag(LoopVar->getBeginLoc(), "loop variable has narrower type '%0%1%2' "
+   "than iteration's upper bound '%3%4%5'");

This is a bit confusing, could you keep it with `%0` and `%1` (which clearly 
represent "loop variable" and "upper bound"), and simply create a `std::string` 
with the appropriate content? Something like:

```
std::string type = LoopVarType.getAsString();
if (LoopVarMagnitudeBits.second) {
  type += ":" + std::to_string(LoopVarMagntiudeBits.second);
}
Msg << type;

```





Comment at: 
clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp:197-202
+  if (UpperBoundMagnitudeBits.second) {
+Msg << ":" << UpperBoundMagnitudeBits.second;
+  } else {
+Msg << ""
+<< "";
+  }

Please create a helper function to remove duplication.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142587

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


[PATCH] D144218: [Clang] [AVR] Fix USHRT_MAX for 16-bit int.

2023-02-25 Thread Daniel Thornburgh via Phabricator via cfe-commits
mysterymath updated this revision to Diff 500442.
mysterymath added a comment.

Minor clarification to release note.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144218

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Headers/limits.h
  clang/test/Headers/limits.cpp

Index: clang/test/Headers/limits.cpp
===
--- clang/test/Headers/limits.cpp
+++ clang/test/Headers/limits.cpp
@@ -3,14 +3,39 @@
 // RUN: %clang_cc1 -std=c++11 -ffreestanding -fsyntax-only -verify %s
 // RUN: %clang_cc1 -std=c17 -ffreestanding -fsyntax-only -verify -x c %s
 // RUN: %clang_cc1 -std=c2x -ffreestanding -fsyntax-only -verify -x c %s
+
+// Specifically test 16-bit int platforms.
+// RUN: %clang_cc1 -triple=avr -ffreestanding -fsyntax-only -verify -x c %s
+
 // expected-no-diagnostics
 
 #include 
 
+#if __cplusplus
+#define EXPR_TYPE_IS(EXPR, TYP) __is_same(__typeof(EXPR), TYP)
+#else
+#define EXPR_TYPE_IS(EXPR, TYP) _Generic(EXPR, TYP: 1, default: 0)
+#endif
+
 _Static_assert(SCHAR_MAX == -(SCHAR_MIN+1), "");
+_Static_assert(EXPR_TYPE_IS(SCHAR_MAX, int), "");
+#if SCHAR_MAX
+#endif
+
 _Static_assert(SHRT_MAX == -(SHRT_MIN+1), "");
+_Static_assert(EXPR_TYPE_IS(SHRT_MAX, int), "");
+#if SHRT_MAX
+#endif
+
 _Static_assert(INT_MAX == -(INT_MIN+1), "");
+_Static_assert(EXPR_TYPE_IS(INT_MAX, int), "");
+#if INT_MAX
+#endif
+
 _Static_assert(LONG_MAX == -(LONG_MIN+1L), "");
+_Static_assert(EXPR_TYPE_IS(LONG_MAX, long), "");
+#if LONG_MAX
+#endif
 
 _Static_assert(SCHAR_MAX == UCHAR_MAX/2, "");
 _Static_assert(SHRT_MAX == USHRT_MAX/2, "");
@@ -18,26 +43,84 @@
 _Static_assert(LONG_MAX == ULONG_MAX/2, "");
 
 _Static_assert(SCHAR_MIN == -SCHAR_MAX-1, "");
+_Static_assert(EXPR_TYPE_IS(SCHAR_MIN, int), "");
+#if SCHAR_MIN
+#endif
+
 _Static_assert(SHRT_MIN == -SHRT_MAX-1, "");
+_Static_assert(EXPR_TYPE_IS(SHRT_MIN, int), "");
+#if SHRT_MIN
+#endif
+
 _Static_assert(INT_MIN == -INT_MAX-1, "");
+_Static_assert(EXPR_TYPE_IS(INT_MIN, int), "");
+#if INT_MIN
+#endif
+
 _Static_assert(LONG_MIN == -LONG_MAX-1L, "");
+_Static_assert(EXPR_TYPE_IS(LONG_MIN, long), "");
+#if LONG_MIN
+#endif
 
 _Static_assert(UCHAR_MAX == (unsigned char)~0ULL, "");
+_Static_assert(UCHAR_MAX <= INT_MAX ?
+ EXPR_TYPE_IS(UCHAR_MAX, int) :
+ EXPR_TYPE_IS(UCHAR_MAX, unsigned int), "");
+#if UCHAR_MAX
+#endif
+
 _Static_assert(USHRT_MAX == (unsigned short)~0ULL, "");
+_Static_assert(USHRT_MAX <= INT_MAX ?
+ EXPR_TYPE_IS(USHRT_MAX, int) :
+ EXPR_TYPE_IS(USHRT_MAX, unsigned int), "");
+#if USHRT_MAX
+#endif
+
 _Static_assert(UINT_MAX == (unsigned int)~0ULL, "");
+_Static_assert(EXPR_TYPE_IS(UINT_MAX, unsigned int), "");
+#if UINT_MAX
+#endif
+
 _Static_assert(ULONG_MAX == (unsigned long)~0ULL, "");
+_Static_assert(EXPR_TYPE_IS(ULONG_MAX, unsigned long), "");
+#if ULONG_MAX
+#endif
 
 _Static_assert(MB_LEN_MAX >= 1, "");
+#if MB_LEN_MAX
+#endif
 
 _Static_assert(CHAR_BIT >= 8, "");
+#if CHAR_BIT
+#endif
 
 _Static_assert(CHAR_MIN == (((char)-1 < (char)0) ? -CHAR_MAX-1 : 0), "");
+_Static_assert(EXPR_TYPE_IS(CHAR_MIN, int), "");
+#if CHAR_MIN
+#endif
+
 _Static_assert(CHAR_MAX == (((char)-1 < (char)0) ? -(CHAR_MIN+1) : (char)~0ULL), "");
+_Static_assert(CHAR_MAX <= INT_MAX ?
+ EXPR_TYPE_IS(CHAR_MAX, int) :
+ EXPR_TYPE_IS(CHAR_MAX, unsigned int), "");
+#if CHAR_MAX
+#endif
 
 #if __STDC_VERSION__ >= 199901 || __cplusplus >= 201103L
 _Static_assert(LLONG_MAX == -(LLONG_MIN+1LL), "");
+_Static_assert(EXPR_TYPE_IS(LLONG_MAX, long long), "");
+#if LLONG_MAX
+#endif
+
 _Static_assert(LLONG_MIN == -LLONG_MAX-1LL, "");
+#if LLONG_MIN
+#endif
+_Static_assert(EXPR_TYPE_IS(LLONG_MIN, long long), "");
+
 _Static_assert(ULLONG_MAX == (unsigned long long)~0ULL, "");
+_Static_assert(EXPR_TYPE_IS(ULLONG_MAX, unsigned long long), "");
+#if ULLONG_MAX
+#endif
 #else
 int LLONG_MIN, LLONG_MAX, ULLONG_MAX; // Not defined.
 #endif
@@ -47,35 +130,61 @@
 #if __STDC_VERSION__ >= 202000L
 /* Validate the standard requirements. */
 _Static_assert(BOOL_WIDTH >= 1);
+#if BOOL_WIDTH
+#endif
 
 _Static_assert(CHAR_WIDTH == CHAR_BIT);
 _Static_assert(CHAR_WIDTH / CHAR_BIT == sizeof(char));
+#if CHAR_WIDTH
+#endif
 _Static_assert(SCHAR_WIDTH == CHAR_BIT);
 _Static_assert(SCHAR_WIDTH / CHAR_BIT == sizeof(signed char));
+#if SCHAR_WIDTH
+#endif
 _Static_assert(UCHAR_WIDTH == CHAR_BIT);
 _Static_assert(UCHAR_WIDTH / CHAR_BIT == sizeof(unsigned char));
+#if UCHAR_WIDTH
+#endif
 
 _Static_assert(USHRT_WIDTH >= 16);
 _Static_assert(USHRT_WIDTH / CHAR_BIT == sizeof(unsigned short));
+#if USHRT_WIDTH
+#endif
 _Static_assert(SHRT_WIDTH == USHRT_WIDTH);
 _Static_assert(SHRT_WIDTH / CHAR_BIT == sizeof(signed short));
+#if SHRT_WIDTH
+#endif
 
 _Static_assert(UINT_WIDTH >= 16);
 _Static_assert(UINT_WIDTH / CHAR_BIT == sizeof(unsigned int));
+#if UINT_WIDTH
+#endif
 _Static_assert

[PATCH] D144217: [clang-tidy] Fix false-positive in readability-container-size-empty

2023-02-25 Thread Piotr Zegar via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe08cc52cfc23: [clang-tidy] Fix false-positive in 
readability-container-size-empty (authored by PiotrZSL).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144217

Files:
  clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
  clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/readability/container-size-empty.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
@@ -1,4 +1,6 @@
-// RUN: %check_clang_tidy %s readability-container-size-empty %t -- -- -fno-delayed-template-parsing
+// RUN: %check_clang_tidy %s readability-container-size-empty %t -- \
+// RUN: -config="{CheckOptions: [{key: readability-container-size-empty.ExcludedComparisonTypes , value: '::std::array;::IgnoredDummyType'}]}" \
+// RUN: -- -fno-delayed-template-parsing
 
 namespace std {
 template  struct vector {
@@ -123,12 +125,12 @@
 ;
   // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used to check for emptiness instead of 'size' [readability-container-size-empty]
   // CHECK-FIXES: {{^  }}if (intSet.empty()){{$}}
-  // CHECK-MESSAGES: :32:8: note: method 'set'::empty() defined here
+  // CHECK-MESSAGES: :34:8: note: method 'set'::empty() defined here
   if (intSet == std::set())
 ;
   // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used to check for emptiness
   // CHECK-FIXES: {{^  }}if (intSet.empty()){{$}}
-  // CHECK-MESSAGES: :32:8: note: method 'set'::empty() defined here
+  // CHECK-MESSAGES: :34:8: note: method 'set'::empty() defined here
   if (s_func() == "")
 ;
   // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
@@ -450,7 +452,7 @@
 public:
   ConstructWithBoolField(const std::vector &C) : B(C.size()) {}
 // CHECK-MESSAGES: :[[@LINE-1]]:57: warning: the 'empty' method should be used
-// CHECK-MESSAGES: :9:8: note: method 'vector'::empty() defined here
+// CHECK-MESSAGES: :11:8: note: method 'vector'::empty() defined here
 // CHECK-FIXES: {{^  }}ConstructWithBoolField(const std::vector &C) : B(!C.empty()) {}
 };
 
@@ -458,21 +460,21 @@
   std::vector C;
   bool B = C.size();
 // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: the 'empty' method should be used
-// CHECK-MESSAGES: :9:8: note: method 'vector'::empty() defined here
+// CHECK-MESSAGES: :11:8: note: method 'vector'::empty() defined here
 // CHECK-FIXES: {{^  }}bool B = !C.empty();
 };
 
 int func(const std::vector &C) {
   return C.size() ? 0 : 1;
 // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: the 'empty' method should be used
-// CHECK-MESSAGES: :9:8: note: method 'vector'::empty() defined here
+// CHECK-MESSAGES: :11:8: note: method 'vector'::empty() defined here
 // CHECK-FIXES: {{^  }}return !C.empty() ? 0 : 1;
 }
 
 constexpr Lazy L;
 static_assert(!L.size(), "");
 // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: the 'empty' method should be used
-// CHECK-MESSAGES: :101:18: note: method 'Lazy'::empty() defined here
+// CHECK-MESSAGES: :103:18: note: method 'Lazy'::empty() defined here
 // CHECK-FIXES: {{^}}static_assert(L.empty(), "");
 
 struct StructWithLazyNoexcept {
@@ -487,7 +489,7 @@
   if (v.size())
 ;
   // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used to check for emptiness instead of 'size' [readability-container-size-empty]
-  // CHECK-MESSAGES: :9:8: note: method 'vector'::empty() defined here
+  // CHECK-MESSAGES: :11:8: note: method 'vector'::empty() defined here
   // CHECK-FIXES: {{^  }}if (!v.empty()){{$}}
   if (v == std::vector())
 ;
@@ -496,24 +498,24 @@
   // CHECK-FIXES-NEXT: ;
   CHECKSIZE(v);
   // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: the 'empty' method should be used
-  // CHECK-MESSAGES: :9:8: note: method 'vector'::empty() defined here
+  // CHECK-MESSAGES: :11:8: note: method 'vector'::empty() defined here
   // CHECK-FIXES: CHECKSIZE(v);
 
   TemplatedContainer templated_container;
   if (templated_container.size())
 ;
   // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
-  // CHECK-MESSAGES: :44:8: note: method 'TemplatedContainer'::empty() defined here
+  // CHECK-MESSAGES: :46:8: note: method 'TemplatedContainer'::empty() defined here
   // CHECK-FIXES: {{^  }}if (!templated_container.empty()){{$}}
   if (templated_container != TemplatedContainer())
 ;
   // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
-  /

[clang-tools-extra] e08cc52 - [clang-tidy] Fix false-positive in readability-container-size-empty

2023-02-25 Thread Piotr Zegar via cfe-commits

Author: Piotr Zegar
Date: 2023-02-25T18:19:40Z
New Revision: e08cc52cfc23d9fcf2e87301e74bfa94d7a4bad0

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

LOG: [clang-tidy] Fix false-positive in readability-container-size-empty

Ignoring std::array type when matching 'std:array == std::array()'.
In such case we shouldn't propose to use empty().

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

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h
clang-tools-extra/docs/ReleaseNotes.rst

clang-tools-extra/docs/clang-tidy/checks/readability/container-size-empty.rst

clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
index a39b72e39c999..e24cb195e70cb 100644
--- a/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
@@ -8,6 +8,7 @@
 #include "ContainerSizeEmptyCheck.h"
 #include "../utils/ASTUtils.h"
 #include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Lex/Lexer.h"
@@ -17,6 +18,7 @@ using namespace clang::ast_matchers;
 
 namespace clang {
 namespace ast_matchers {
+
 AST_POLYMORPHIC_MATCHER_P2(hasAnyArgumentWithParam,
AST_POLYMORPHIC_SUPPORTED_TYPES(CallExpr,
CXXConstructExpr),
@@ -83,12 +85,15 @@ AST_MATCHER(Expr, usedInBooleanContext) {
   });
   return Result;
 }
+
 AST_MATCHER(CXXConstructExpr, isDefaultConstruction) {
   return Node.getConstructor()->isDefaultConstructor();
 }
+
 AST_MATCHER(QualType, isIntegralType) {
   return Node->isIntegralType(Finder->getASTContext());
 }
+
 } // namespace ast_matchers
 namespace tidy::readability {
 
@@ -96,7 +101,14 @@ using utils::isBinaryOrTernary;
 
 ContainerSizeEmptyCheck::ContainerSizeEmptyCheck(StringRef Name,
  ClangTidyContext *Context)
-: ClangTidyCheck(Name, Context) {}
+: ClangTidyCheck(Name, Context),
+  ExcludedComparisonTypes(utils::options::parseStringList(
+  Options.get("ExcludedComparisonTypes", "::std::array"))) {}
+
+void ContainerSizeEmptyCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "ExcludedComparisonTypes",
+utils::options::serializeStringList(ExcludedComparisonTypes));
+}
 
 void ContainerSizeEmptyCheck::registerMatchers(MatchFinder *Finder) {
   const auto ValidContainerRecord = cxxRecordDecl(isSameOrDerivedFrom(
@@ -164,12 +176,26 @@ void 
ContainerSizeEmptyCheck::registerMatchers(MatchFinder *Finder) {
 hasUnaryOperand(
 expr(hasType(pointsTo(ValidContainer))).bind("Pointee"))),
 expr(hasType(ValidContainer)).bind("STLObject"));
+
+  const auto ExcludedComparisonTypesMatcher = qualType(anyOf(
+  hasDeclaration(
+  
cxxRecordDecl(matchers::matchesAnyListedName(ExcludedComparisonTypes))
+  .bind("excluded")),
+  hasCanonicalType(hasDeclaration(
+  
cxxRecordDecl(matchers::matchesAnyListedName(ExcludedComparisonTypes))
+  .bind("excluded");
+  const auto SameExcludedComparisonTypesMatcher =
+  
qualType(anyOf(hasDeclaration(cxxRecordDecl(equalsBoundNode("excluded"))),
+ hasCanonicalType(hasDeclaration(
+ cxxRecordDecl(equalsBoundNode("excluded"));
+
   Finder->addMatcher(
-  binaryOperation(hasAnyOperatorName("==", "!="),
-  hasOperands(WrongComparend,
-  STLArg),
-  unless(hasAncestor(cxxMethodDecl(
-  ofClass(equalsBoundNode("container"))
+  binaryOperation(
+  hasAnyOperatorName("==", "!="), hasOperands(WrongComparend, STLArg),
+  unless(allOf(hasLHS(hasType(ExcludedComparisonTypesMatcher)),
+   hasRHS(hasType(SameExcludedComparisonTypesMatcher,
+  unless(hasAncestor(
+  cxxMethodDecl(ofClass(equalsBoundNode("container"))
   .bind("BinCmp"),
   this);
 }

diff  --git 
a/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h 
b/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h
index 90d18393958b2..a9a65d0185393 100644
--- a/clang-tools-extra/clang-tidy/readability/C

[PATCH] D142569: [OpenMP] Introduce kernel environment

2023-02-25 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 added a comment.

Only `llvm/test/Transforms/OpenMP/spmdization_constant_prop.ll` is left.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142569

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


[PATCH] D142569: [OpenMP] Introduce kernel environment

2023-02-25 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 updated this revision to Diff 500440.
tianshilei1992 added a comment.
Herald added subscribers: okura, kuter, steven_wu.

update tests in LLVM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142569

Files:
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/test/Headers/amdgcn_openmp_device_math_c.c
  clang/test/OpenMP/amdgcn_target_codegen.cpp
  clang/test/OpenMP/declare_target_codegen_globalization.cpp
  clang/test/OpenMP/nvptx_SPMD_codegen.cpp
  clang/test/OpenMP/nvptx_data_sharing.cpp
  clang/test/OpenMP/nvptx_distribute_parallel_generic_mode_codegen.cpp
  clang/test/OpenMP/nvptx_multi_target_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_nested_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_parallel_for_codegen.cpp
  clang/test/OpenMP/nvptx_target_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_num_threads_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_proc_bind_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_reduction_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_reduction_codegen_tbaa_PR46146.cpp
  clang/test/OpenMP/nvptx_target_printf_codegen.c
  clang/test/OpenMP/nvptx_target_simd_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_codegen.cpp
  
clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_generic_mode_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_simd_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_simd_codegen.cpp
  clang/test/OpenMP/nvptx_teams_codegen.cpp
  clang/test/OpenMP/nvptx_teams_reduction_codegen.cpp
  clang/test/OpenMP/reduction_implicit_map.cpp
  clang/test/OpenMP/remarks_parallel_in_multiple_target_state_machines.c
  clang/test/OpenMP/remarks_parallel_in_target_state_machine.c
  clang/test/OpenMP/target_parallel_debug_codegen.cpp
  clang/test/OpenMP/target_parallel_for_debug_codegen.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/lib/Transforms/IPO/OpenMPOpt.cpp
  llvm/test/Transforms/Attributor/reduced/aa_execution_domain_wrong_fn.ll
  llvm/test/Transforms/Attributor/value-simplify-local-remote.ll
  llvm/test/Transforms/OpenMP/add_attributes.ll
  llvm/test/Transforms/OpenMP/always_inline_device.ll
  llvm/test/Transforms/OpenMP/custom_state_machines.ll
  llvm/test/Transforms/OpenMP/custom_state_machines_pre_lto.ll
  llvm/test/Transforms/OpenMP/custom_state_machines_remarks.ll
  llvm/test/Transforms/OpenMP/deduplication_target.ll
  llvm/test/Transforms/OpenMP/get_hardware_num_threads_in_block_fold.ll
  llvm/test/Transforms/OpenMP/get_hardware_num_threads_in_block_fold_optnone.ll
  llvm/test/Transforms/OpenMP/global_constructor.ll
  llvm/test/Transforms/OpenMP/globalization_remarks.ll
  llvm/test/Transforms/OpenMP/gpu_state_machine_function_ptr_replacement.ll
  llvm/test/Transforms/OpenMP/is_spmd_exec_mode_fold.ll
  llvm/test/Transforms/OpenMP/nested_parallelism.ll
  llvm/test/Transforms/OpenMP/parallel_level_fold.ll
  llvm/test/Transforms/OpenMP/remove_globalization.ll
  llvm/test/Transforms/OpenMP/replace_globalization.ll
  llvm/test/Transforms/OpenMP/single_threaded_execution.ll
  llvm/test/Transforms/OpenMP/spmdization.ll
  llvm/test/Transforms/OpenMP/spmdization_assumes.ll
  llvm/test/Transforms/OpenMP/spmdization_guarding.ll
  llvm/test/Transforms/OpenMP/spmdization_guarding_two_reaching_kernels.ll
  llvm/test/Transforms/OpenMP/spmdization_no_guarding_two_reaching_kernels.ll
  llvm/test/Transforms/OpenMP/spmdization_remarks.ll
  llvm/test/Transforms/OpenMP/value-simplify-openmp-opt.ll
  llvm/test/Transforms/PhaseOrdering/openmp-opt-module.ll
  openmp/libomptarget/DeviceRTL/CMakeLists.txt
  openmp/libomptarget/DeviceRTL/include/Debug.h
  openmp/libomptarget/DeviceRTL/include/Interface.h
  openmp/libomptarget/DeviceRTL/include/State.h
  openmp/libomptarget/DeviceRTL/src/Configuration.cpp
  openmp/libomptarget/DeviceRTL/src/Debug.cpp
  openmp/libomptarget/DeviceRTL/src/Kernel.cpp
  openmp/libomptarget/DeviceRTL/src/State.cpp
  openmp/libomptarget/include/DeviceEnvironment.h
  openmp/libomptarget/include/Environment.h
  openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp
  openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.cpp
  openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.h
  openmp/libomptarget/plugins-nextgen/cuda/src/rtl.cpp
  openmp/libomptarget/plugins-nextgen/generic-elf-64bit/src/rtl.cpp
  openmp/libomptarget/plugins/amdgpu/src/rtl.cpp
  openmp/libomptarget/plugins/cuda/src/rtl.cpp

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llv

[PATCH] D144217: [clang-tidy] Fix false-positive in readability-container-size-empty

2023-02-25 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL updated this revision to Diff 500437.
PiotrZSL marked 2 inline comments as done.
PiotrZSL added a comment.

Fix review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144217

Files:
  clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
  clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/readability/container-size-empty.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
@@ -1,4 +1,6 @@
-// RUN: %check_clang_tidy %s readability-container-size-empty %t -- -- -fno-delayed-template-parsing
+// RUN: %check_clang_tidy %s readability-container-size-empty %t -- \
+// RUN: -config="{CheckOptions: [{key: readability-container-size-empty.ExcludedComparisonTypes , value: '::std::array;::IgnoredDummyType'}]}" \
+// RUN: -- -fno-delayed-template-parsing
 
 namespace std {
 template  struct vector {
@@ -123,12 +125,12 @@
 ;
   // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used to check for emptiness instead of 'size' [readability-container-size-empty]
   // CHECK-FIXES: {{^  }}if (intSet.empty()){{$}}
-  // CHECK-MESSAGES: :32:8: note: method 'set'::empty() defined here
+  // CHECK-MESSAGES: :34:8: note: method 'set'::empty() defined here
   if (intSet == std::set())
 ;
   // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used to check for emptiness
   // CHECK-FIXES: {{^  }}if (intSet.empty()){{$}}
-  // CHECK-MESSAGES: :32:8: note: method 'set'::empty() defined here
+  // CHECK-MESSAGES: :34:8: note: method 'set'::empty() defined here
   if (s_func() == "")
 ;
   // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
@@ -450,7 +452,7 @@
 public:
   ConstructWithBoolField(const std::vector &C) : B(C.size()) {}
 // CHECK-MESSAGES: :[[@LINE-1]]:57: warning: the 'empty' method should be used
-// CHECK-MESSAGES: :9:8: note: method 'vector'::empty() defined here
+// CHECK-MESSAGES: :11:8: note: method 'vector'::empty() defined here
 // CHECK-FIXES: {{^  }}ConstructWithBoolField(const std::vector &C) : B(!C.empty()) {}
 };
 
@@ -458,21 +460,21 @@
   std::vector C;
   bool B = C.size();
 // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: the 'empty' method should be used
-// CHECK-MESSAGES: :9:8: note: method 'vector'::empty() defined here
+// CHECK-MESSAGES: :11:8: note: method 'vector'::empty() defined here
 // CHECK-FIXES: {{^  }}bool B = !C.empty();
 };
 
 int func(const std::vector &C) {
   return C.size() ? 0 : 1;
 // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: the 'empty' method should be used
-// CHECK-MESSAGES: :9:8: note: method 'vector'::empty() defined here
+// CHECK-MESSAGES: :11:8: note: method 'vector'::empty() defined here
 // CHECK-FIXES: {{^  }}return !C.empty() ? 0 : 1;
 }
 
 constexpr Lazy L;
 static_assert(!L.size(), "");
 // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: the 'empty' method should be used
-// CHECK-MESSAGES: :101:18: note: method 'Lazy'::empty() defined here
+// CHECK-MESSAGES: :103:18: note: method 'Lazy'::empty() defined here
 // CHECK-FIXES: {{^}}static_assert(L.empty(), "");
 
 struct StructWithLazyNoexcept {
@@ -487,7 +489,7 @@
   if (v.size())
 ;
   // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used to check for emptiness instead of 'size' [readability-container-size-empty]
-  // CHECK-MESSAGES: :9:8: note: method 'vector'::empty() defined here
+  // CHECK-MESSAGES: :11:8: note: method 'vector'::empty() defined here
   // CHECK-FIXES: {{^  }}if (!v.empty()){{$}}
   if (v == std::vector())
 ;
@@ -496,24 +498,24 @@
   // CHECK-FIXES-NEXT: ;
   CHECKSIZE(v);
   // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: the 'empty' method should be used
-  // CHECK-MESSAGES: :9:8: note: method 'vector'::empty() defined here
+  // CHECK-MESSAGES: :11:8: note: method 'vector'::empty() defined here
   // CHECK-FIXES: CHECKSIZE(v);
 
   TemplatedContainer templated_container;
   if (templated_container.size())
 ;
   // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
-  // CHECK-MESSAGES: :44:8: note: method 'TemplatedContainer'::empty() defined here
+  // CHECK-MESSAGES: :46:8: note: method 'TemplatedContainer'::empty() defined here
   // CHECK-FIXES: {{^  }}if (!templated_container.empty()){{$}}
   if (templated_container != TemplatedContainer())
 ;
   // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
-  // CHECK-MESSAGES: :44:8: note: method 'TemplatedContainer'::em

[clang] da846cc - Remove WG14 N2829 from the C status page; NFC

2023-02-25 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2023-02-25T11:06:34-05:00
New Revision: da846cca8fb3b21d7c7674244015efe6670e48cb

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

LOG: Remove WG14 N2829 from the C status page; NFC

This paper is about changes to the assert macro, but assert.h is not
provided by the compiler, so there's no work for Clang to do to support
this feature.

Added: 


Modified: 
clang/www/c_status.html

Removed: 




diff  --git a/clang/www/c_status.html b/clang/www/c_status.html
index 7665d24a381d..425d67b4be6e 100644
--- a/clang/www/c_status.html
+++ b/clang/www/c_status.html
@@ -1035,11 +1035,6 @@ C2x implementation status
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2828.htm";>N2828
   Clang 3.6
 
-
-  Make assert() macro user friendly for C and C++ v2
-  https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2829.htm";>N2829
-  No
-
 
   Identifier Syntax using Unicode Standard Annex 31
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2836.pdf";>N2836



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


[PATCH] D144217: [clang-tidy] Fix false-positive in readability-container-size-empty

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

Thanks for the fix! Looks good, have a couple minor comments.




Comment at: 
clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp:88-89
 }
+
 AST_MATCHER(CXXConstructExpr, isDefaultConstruction) {
   return Node.getConstructor()->isDefaultConstructor();

While this improves readability, we typically prefer these changes to be done 
in a separate NFC patch to reduce review noise (and thereby improving review 
speed).



Comment at: 
clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp:180
+
+  const auto StdArrayType = qualType(anyOf(
+  hasDeclaration(

This is no longer just StdArray, it can be any excluded type - please rename 
accordingly.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/readability/container-size-empty.rst:34
+instead of such comparisons for objects of that class.
+Default value is: `::std::array;::boost::array`.

Only std::array is currently part of the default.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp:658
   // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: the 'empty' method should be 
used
-  // CHECK-MESSAGES: :44:8: note: method 'TemplatedContainer'::empty() defined 
here
+  // CHECK-MESSAGES: :46:8: note: method 'TemplatedContainer'::empty() defined 
here
   // CHECK-FIXES: {{^  }}auto b5 = bool(!templated_container.empty());

What was the motivation for this change? Similarly to my previous comment this 
seems unrelated to the main scope of the patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144217

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


[PATCH] D140996: [c++20] P1907R1: Support for generalized non-type template arguments of scalar type.

2023-02-25 Thread Andrey Ali Khan Bolshakov via Phabricator via cfe-commits
bolshakov-a added inline comments.



Comment at: clang/include/clang/AST/ASTContext.h:3036
 if (!std::is_trivially_destructible::value) {
-  auto DestroyPtr = [](void *V) { static_cast(V)->~T(); };
-  AddDeallocation(DestroyPtr, Ptr);
+  auto DestroyPtr = [](void *V) { ((T *)V)->~T(); };
+  AddDeallocation(DestroyPtr, (void *)Ptr);

erichkeane wrote:
> This change is weird... what is going on here?
Here is not very beautiful attempt to workaround const-ness of 
`TemplateArgument::V::Value` pointer passed here from the added 
`TemplateArgument` constructor. The change in this line isn't acually needed 
and made only for consistence with the next line, I think. Alternatively, I can
1) refactor `addDestruction` and `AddDeallocation` to work with pointers to 
constants, or
2) add `const_cast` to `AddDeallocation` call in the next line, or
3) make `TemplateArgument::V::Value` pointer non-const.

I'm biased to the first variant.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140996

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


[clang] 0617413 - [C2x] Implement support for revised spelling of keywords

2023-02-25 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2023-02-25T09:30:10-05:00
New Revision: 06174134e418251982d43eff9385674b7644007f

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

LOG: [C2x] Implement support for revised spelling of keywords

This implements WG14 N2934
(https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2934.pdf), which
adds keywords for alignas, alignof, bool, static_assert, and
thread_local in C, as aliases for _Alignas, _Alignof, _Bool,
_Static_assert, and _Thread_local. We already supported the keywords in
C2x mode, but this completes support by adding pre-C2x compat warnings
and updates the stdalign.h header in freestanding mode.

Added: 
clang/test/C/C2x/n2934.c

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/lib/Headers/stdalign.h
clang/lib/Parse/ParseDecl.cpp
clang/lib/Parse/ParseDeclCXX.cpp
clang/lib/Parse/ParseExpr.cpp
clang/www/c_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0397ba0b305eb..b4c64c4e60515 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -97,6 +97,10 @@ C2x Feature Support
 - Removed the ``ATOMIC_VAR_INIT`` macro in C2x and later standards modes, which
   implements `WG14 N2886 
`_
 
+- Implemented `WG14 N2934 
`_
+  which introduces the ``bool``, ``static_assert``, ``alignas``, ``alignof``,
+  and ``thread_local`` keywords in C2x.
+
 Non-comprehensive list of changes in this release
 -
 - Clang now saves the address of ABI-indirect function parameters on the stack,

diff  --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index e3849c6658d16..243c69a551650 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -162,6 +162,9 @@ def ext_c99_feature : Extension<
   "'%0' is a C99 extension">, InGroup;
 def ext_c11_feature : Extension<
   "'%0' is a C11 extension">, InGroup;
+def warn_c2x_compat_keyword : Warning<
+ "'%0' is incompatible with C standards before C2x">,
+ InGroup, DefaultIgnore;
 
 def err_c11_noreturn_misplaced : Error<
   "'_Noreturn' keyword must precede function declarator">;
@@ -371,9 +374,6 @@ def warn_cxx11_compat_decltype_auto_type_specifier : 
Warning<
 def ext_auto_type : Extension<
   "'__auto_type' is a GNU extension">,
   InGroup;
-def warn_c2x_compat_typeof_type_specifier : Warning<
-  "'%select{typeof|typeof_unqual}0' is incompatible with C standards before "
-  "C2x">, InGroup, DefaultIgnore;
 def ext_for_range : ExtWarn<
   "range-based for loop is a C++11 extension">, InGroup;
 def warn_cxx98_compat_for_range : Warning<
@@ -704,9 +704,6 @@ def warn_cxx98_compat_nullptr : Warning<
   "'nullptr' is incompatible with C++98">, InGroup, DefaultIgnore;
 def ext_c_nullptr : Extension<
   "'nullptr' is a C2x extension">, InGroup;
-def warn_c17_compat_nullptr : Warning<
-  "'nullptr' is incompatible with C standards before C2x">,
-  InGroup, DefaultIgnore;
 
 def warn_wrong_clang_attr_namespace : Warning<
   "'__clang__' is a predefined macro name, not an attribute scope specifier; "
@@ -1574,9 +1571,6 @@ def warn_ext_int_deprecated : Warning<
 def ext_bit_int : Extension<
   "'_BitInt' in %select{C17 and earlier|C++}0 is a Clang extension">,
   InGroup>;
-def warn_c17_compat_bit_int : Warning<
-  "'_BitInt' is incompatible with C standards before C2x">,
-  InGroup, DefaultIgnore;
 } // end of Parse Issue category.
 
 let CategoryName = "Modules Issue" in {

diff  --git a/clang/lib/Headers/stdalign.h b/clang/lib/Headers/stdalign.h
index 6ad25db4539a1..8ae6e658dd0a2 100644
--- a/clang/lib/Headers/stdalign.h
+++ b/clang/lib/Headers/stdalign.h
@@ -10,6 +10,10 @@
 #ifndef __STDALIGN_H
 #define __STDALIGN_H
 
+/* FIXME: This is using the placeholder dates Clang produces for these macros
+   in C2x mode; switch to the correct values once they've been published. */
+#if defined(__cplusplus) ||
\
+(defined(__STDC_VERSION__) && __STDC_VERSION__ < 202000L)
 #ifndef __cplusplus
 #define alignas _Alignas
 #define alignof _Alignof
@@ -17,5 +21,6 @@
 
 #define __alignas_is_defined 1
 #define __alignof_is_defined 1
+#endif /* __STDC_VERSION__ */
 
 #endif /* __STDALIGN_H */

diff  --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index d654cdff847be..3106571728692 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -3934,6 +3934,8 @@ void Parser::ParseDeclarationSpecifiers(
   isStorageClass = true

[PATCH] D143704: [Flang] Part one of Feature List action

2023-02-25 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added a comment.

In D143704#4150680 , @jdoerfert wrote:

> can we have a test?

+1




Comment at: flang/examples/FeatureList/FeatureList.cpp:34
+
+struct ASTVisitor {
+private:

There is no AST in Flang - could you propose something more descriptive?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143704

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


[PATCH] D144778: [Driver][FreeBSD] Further simplify the Driver handling for older FreeBSD releases

2023-02-25 Thread Dimitry Andric via Phabricator via cfe-commits
dim accepted this revision.
dim added a comment.
This revision is now accepted and ready to land.

LGTM, are there no test cases which are affected by this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144778

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


[PATCH] D144709: [clang-format] Improve left to right const

2023-02-25 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

can you rebase please


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144709

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


[PATCH] D144709: [clang-format] Improve left to right const

2023-02-25 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

when I originally did this work, I checked out the whole fresh area of LLVM and 
applied the both east then back to west const and built both to ensure I didn't 
break anything. Please ensure you do the same, I'm going to be honest you are 
changing it  massively, I'm going to need some time to understand the changes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144709

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


[PATCH] D143415: LibclangTest: remove libclang-test-* tmp dir reliably

2023-02-25 Thread Igor Kushnir via Phabricator via cfe-commits
vedgy added a comment.

@aaron.ballman, this test fix is independent from D143418 
 and can be reviewed separately.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143415

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


[PATCH] D144709: [clang-format] Improve west to east const

2023-02-25 Thread Alexander Hederstaf via Phabricator via cfe-commits
AlexanderHederstaf added a comment.

Thanks for the review so far!

Passes all tests and works in one shot on my test files as well as 3k+ files 
repository, i.e. it does not have to be run twice.

As one use-case of this rule is to be able to checkout code and freely swap 
between left/right. Then the left alignment would also need to handle the same 
cases as right alignment.

I should also make templates with requires work, though I am not familiar with 
the variations that syntax may have.

@rymiel Good, this might take a few more iterations.




Comment at: clang/lib/Format/QualifierAlignmentFixer.cpp:226
+
+  const bool IsEastQualifier = PreviousCheck && [PreviousCheck]() {
+if (PreviousCheck->is(tok::r_paren)) {

HazardyKnusperkeks wrote:
> In the initial commit concerns were raised that `East` and `West` are 
> westcentric terms and should not be used. Thus you should stick here to 
> `Left` and `Right` the same terms we use in the configuration.
Replaced with right/left



Comment at: clang/lib/Format/QualifierAlignmentFixer.cpp:228
+if (PreviousCheck->is(tok::r_paren)) {
+  return true;
+} else if (PreviousCheck->is(TT_TemplateCloser)) {

HazardyKnusperkeks wrote:
> Could you add comments what kind of source code we would have here?
Added comments for the different source code we may have.



Comment at: clang/lib/Format/QualifierAlignmentFixer.cpp:229
+  return true;
+} else if (PreviousCheck->is(TT_TemplateCloser)) {
+  return PreviousCheck->MatchingParen->Previous->isNot(tok::kw_template);

HazardyKnusperkeks wrote:
> No `else` after `return`.
removed 'else' preceeding return.



Comment at: clang/lib/Format/QualifierAlignmentFixer.cpp:230
+} else if (PreviousCheck->is(TT_TemplateCloser)) {
+  return PreviousCheck->MatchingParen->Previous->isNot(tok::kw_template);
+} else if (PreviousCheck->isOneOf(TT_PointerOrReference, tok::identifier,

HazardyKnusperkeks wrote:
> That may be null, or not?
I assumed that if the token is identified as a template closer then there will 
exist an opener. As far as I am aware, something must preceed that opener.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144709

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


[PATCH] D144709: [clang-format] Improve west to east const

2023-02-25 Thread Alexander Hederstaf via Phabricator via cfe-commits
AlexanderHederstaf updated this revision to Diff 500403.
AlexanderHederstaf added a comment.

Add comments for different cases.
Add more tests.
Fix whitespace issue.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144709

Files:
  clang/lib/Format/QualifierAlignmentFixer.cpp
  clang/unittests/Format/QualifierFixerTest.cpp

Index: clang/unittests/Format/QualifierFixerTest.cpp
===
--- clang/unittests/Format/QualifierFixerTest.cpp
+++ clang/unittests/Format/QualifierFixerTest.cpp
@@ -303,6 +303,11 @@
   verifyFormat("void foo() const final;", Style);
   verifyFormat("void foo() const final LLVM_READONLY;", Style);
   verifyFormat("void foo() const LLVM_READONLY;", Style);
+  verifyFormat("void foo() const volatile override;", Style);
+  verifyFormat("void foo() const volatile override LLVM_READONLY;", Style);
+  verifyFormat("void foo() const volatile final;", Style);
+  verifyFormat("void foo() const volatile final LLVM_READONLY;", Style);
+  verifyFormat("void foo() const volatile LLVM_READONLY;", Style);
 
   verifyFormat(
   "template  explicit Action(Action const &action);",
@@ -353,6 +358,10 @@
   verifyFormat("static int const bat;", "static const int bat;", Style);
   verifyFormat("static int const bat;", "static int const bat;", Style);
 
+  verifyFormat("Foo::Bar const volatile A::*;",
+   "volatile const Foo::Bar A::*;",
+   Style);
+
   verifyFormat("int const Foo::bat = 0;", "const int Foo::bat = 0;",
Style);
   verifyFormat("int const Foo::bat = 0;", "int const Foo::bat = 0;",
@@ -581,6 +590,13 @@
   verifyFormat("const volatile int a;", "int volatile const a;", Style);
   verifyFormat("const volatile int a;", "const int volatile a;", Style);
 
+  // TODO: Left style can not move qualifiers past Foo.
+  // verifyFormat("const volatile Foo a;", "const volatile Foo a;", Style);
+  // verifyFormat("const volatile Foo a;", "volatile const Foo a;", Style);
+  // verifyFormat("const volatile Foo a;", "Foo const volatile a;", Style);
+  // verifyFormat("const volatile Foo a;", "Foo volatile const a;", Style);
+  // verifyFormat("const volatile Foo a;", "const Foo volatile a;", Style);
+
   Style.QualifierAlignment = FormatStyle::QAS_Right;
   Style.QualifierOrder = {"type", "const", "volatile"};
 
@@ -590,6 +606,12 @@
   verifyFormat("int const volatile a;", "int volatile const a;", Style);
   verifyFormat("int const volatile a;", "const int volatile a;", Style);
 
+  verifyFormat("Foo const volatile a;", "const volatile Foo a;", Style);
+  verifyFormat("Foo const volatile a;", "volatile const Foo a;", Style);
+  verifyFormat("Foo const volatile a;", "Foo const volatile a;", Style);
+  verifyFormat("Foo const volatile a;", "Foo volatile const a;", Style);
+  verifyFormat("Foo const volatile a;", "const Foo volatile a;", Style);
+
   Style.QualifierAlignment = FormatStyle::QAS_Left;
   Style.QualifierOrder = {"volatile", "const", "type"};
 
@@ -599,6 +621,13 @@
   verifyFormat("volatile const int a;", "int volatile const a;", Style);
   verifyFormat("volatile const int a;", "const int volatile a;", Style);
 
+  // TODO: Left style can not move qualifiers past Foo.
+  // verifyFormat("volatile const Foo a;", "const volatile Foo a;", Style);
+  // verifyFormat("volatile const Foo a;", "volatile const Foo a;", Style);
+  // verifyFormat("volatile const Foo a;", "Foo const volatile a;", Style);
+  // verifyFormat("volatile const Foo a;", "Foo volatile const a;", Style);
+  // verifyFormat("volatile const Foo a;", "const Foo volatile a;", Style);
+
   Style.QualifierAlignment = FormatStyle::QAS_Right;
   Style.QualifierOrder = {"type", "volatile", "const"};
 
@@ -608,6 +637,12 @@
   verifyFormat("int volatile const a;", "int volatile const a;", Style);
   verifyFormat("int volatile const a;", "const int volatile a;", Style);
 
+  verifyFormat("Foo volatile const a;", "const volatile Foo a;", Style);
+  verifyFormat("Foo volatile const a;", "volatile const Foo a;", Style);
+  verifyFormat("Foo volatile const a;", "Foo const volatile a;", Style);
+  verifyFormat("Foo volatile const a;", "Foo volatile const a;", Style);
+  verifyFormat("Foo volatile const a;", "const Foo volatile a;", Style);
+
   Style.QualifierAlignment = FormatStyle::QAS_Custom;
   Style.QualifierOrder = {"type", "volatile", "const"};
 
@@ -616,6 +651,12 @@
   verifyFormat("int volatile const a;", "int const volatile a;", Style);
   verifyFormat("int volatile const a;", "int volatile const a;", Style);
   verifyFormat("int volatile const a;", "const int volatile a;", Style);
+
+  verifyFormat("Foo volatile const a;", "const volatile Foo a;", Style);
+  verifyFormat("Foo volatile const a;", "volatile const Foo a;", Style);
+  verifyFormat("Foo volatile const a;", "Foo const volatile a;", Style);
+  verifyFormat("Foo volatile const a;", "Foo volatile co

[PATCH] D144537: [clang-format] Don't move qualifiers past pointers-to-member

2023-02-25 Thread Emilia Dreamer 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 rG393e197cd6eb: [clang-format] Don't move qualifiers past 
pointers-to-member (authored by rymiel).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144537

Files:
  clang/lib/Format/QualifierAlignmentFixer.cpp
  clang/unittests/Format/QualifierFixerTest.cpp


Index: clang/unittests/Format/QualifierFixerTest.cpp
===
--- clang/unittests/Format/QualifierFixerTest.cpp
+++ clang/unittests/Format/QualifierFixerTest.cpp
@@ -420,6 +420,16 @@
 
   // don't adjust macros
   verifyFormat("const INTPTR a;", "const INTPTR a;", Style);
+
+  // Pointers to members
+  verifyFormat("int S::*a;", Style);
+  verifyFormat("int const S::*a;", "const int S:: *a;", Style);
+  verifyFormat("int const S::*const a;", "const int S::* const a;", Style);
+  verifyFormat("int A::*const A::*p1;", Style);
+  verifyFormat("float (C::*p)(int);", Style);
+  verifyFormat("float (C::*const p)(int);", Style);
+  verifyFormat("float (C::*p)(int) const;", Style);
+  verifyFormat("float const (C::*p)(int);", "const float (C::*p)(int);", 
Style);
 }
 
 TEST_F(QualifierFixerTest, LeftQualifier) {
@@ -565,6 +575,16 @@
 
   // don't adjust macros
   verifyFormat("INTPTR const a;", "INTPTR const a;", Style);
+
+  // Pointers to members
+  verifyFormat("int S::*a;", Style);
+  verifyFormat("const int S::*a;", "int const S:: *a;", Style);
+  verifyFormat("const int S::*const a;", "int const S::* const a;", Style);
+  verifyFormat("int A::*const A::*p1;", Style);
+  verifyFormat("float (C::*p)(int);", Style);
+  verifyFormat("float (C::*const p)(int);", Style);
+  verifyFormat("float (C::*p)(int) const;", Style);
+  verifyFormat("const float (C::*p)(int);", "float const (C::*p)(int);", 
Style);
 }
 
 TEST_F(QualifierFixerTest, ConstVolatileQualifiersOrder) {
Index: clang/lib/Format/QualifierAlignmentFixer.cpp
===
--- clang/lib/Format/QualifierAlignmentFixer.cpp
+++ clang/lib/Format/QualifierAlignmentFixer.cpp
@@ -280,8 +280,11 @@
 // The case  `const Foo &&` -> `Foo const &&`
 // The case  `const std::Foo &&` -> `std::Foo const &&`
 // The case  `const std::Foo &&` -> `std::Foo const &&`
-while (Next && Next->isOneOf(tok::identifier, tok::coloncolon))
+// However,  `const Bar::*` remains the same.
+while (Next && Next->isOneOf(tok::identifier, tok::coloncolon) &&
+   !Next->startsSequence(tok::coloncolon, tok::star)) {
   Next = Next->Next;
+}
 if (Next && Next->is(TT_TemplateOpener)) {
   Next = Next->MatchingParen;
   // Move to the end of any template class members e.g.


Index: clang/unittests/Format/QualifierFixerTest.cpp
===
--- clang/unittests/Format/QualifierFixerTest.cpp
+++ clang/unittests/Format/QualifierFixerTest.cpp
@@ -420,6 +420,16 @@
 
   // don't adjust macros
   verifyFormat("const INTPTR a;", "const INTPTR a;", Style);
+
+  // Pointers to members
+  verifyFormat("int S::*a;", Style);
+  verifyFormat("int const S::*a;", "const int S:: *a;", Style);
+  verifyFormat("int const S::*const a;", "const int S::* const a;", Style);
+  verifyFormat("int A::*const A::*p1;", Style);
+  verifyFormat("float (C::*p)(int);", Style);
+  verifyFormat("float (C::*const p)(int);", Style);
+  verifyFormat("float (C::*p)(int) const;", Style);
+  verifyFormat("float const (C::*p)(int);", "const float (C::*p)(int);", Style);
 }
 
 TEST_F(QualifierFixerTest, LeftQualifier) {
@@ -565,6 +575,16 @@
 
   // don't adjust macros
   verifyFormat("INTPTR const a;", "INTPTR const a;", Style);
+
+  // Pointers to members
+  verifyFormat("int S::*a;", Style);
+  verifyFormat("const int S::*a;", "int const S:: *a;", Style);
+  verifyFormat("const int S::*const a;", "int const S::* const a;", Style);
+  verifyFormat("int A::*const A::*p1;", Style);
+  verifyFormat("float (C::*p)(int);", Style);
+  verifyFormat("float (C::*const p)(int);", Style);
+  verifyFormat("float (C::*p)(int) const;", Style);
+  verifyFormat("const float (C::*p)(int);", "float const (C::*p)(int);", Style);
 }
 
 TEST_F(QualifierFixerTest, ConstVolatileQualifiersOrder) {
Index: clang/lib/Format/QualifierAlignmentFixer.cpp
===
--- clang/lib/Format/QualifierAlignmentFixer.cpp
+++ clang/lib/Format/QualifierAlignmentFixer.cpp
@@ -280,8 +280,11 @@
 // The case  `const Foo &&` -> `Foo const &&`
 // The case  `const std::Foo &&` -> `std::Foo const &&`
 // The case  `const std::Foo &&` -> `std::Foo const &&`
-while (Next && Next->isOneOf(tok::identifier, tok::coloncolon))
+// However,  `const Bar::*` remains the same.
+while (Next && Next->isOneOf(tok::ide

[clang] 393e197 - [clang-format] Don't move qualifiers past pointers-to-member

2023-02-25 Thread Emilia Dreamer via cfe-commits

Author: Emilia Dreamer
Date: 2023-02-25T12:19:20+02:00
New Revision: 393e197cd6eb8942c4eaec3fd6d05bc2e2289212

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

LOG: [clang-format] Don't move qualifiers past pointers-to-member

Previously, given a pointer-to-member type such as `Foo const Bar::*`,
clang-format would see the `const Bar::` part as a regular type name
with scope resolution operators, and with `QualifierAlignment: Right` it
would attempt to "fix" it, resulting in `Foo Bar::const *`, a syntax
error.

This patch no longer allows qualifiers to be moved across `::*`.

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

Reviewed By: owenpan, MyDeveloperDay, HazardyKnusperkeks

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

Added: 


Modified: 
clang/lib/Format/QualifierAlignmentFixer.cpp
clang/unittests/Format/QualifierFixerTest.cpp

Removed: 




diff  --git a/clang/lib/Format/QualifierAlignmentFixer.cpp 
b/clang/lib/Format/QualifierAlignmentFixer.cpp
index cef8b36ff758..609b412380f8 100644
--- a/clang/lib/Format/QualifierAlignmentFixer.cpp
+++ b/clang/lib/Format/QualifierAlignmentFixer.cpp
@@ -280,8 +280,11 @@ const FormatToken 
*LeftRightQualifierAlignmentFixer::analyzeRight(
 // The case  `const Foo &&` -> `Foo const &&`
 // The case  `const std::Foo &&` -> `std::Foo const &&`
 // The case  `const std::Foo &&` -> `std::Foo const &&`
-while (Next && Next->isOneOf(tok::identifier, tok::coloncolon))
+// However,  `const Bar::*` remains the same.
+while (Next && Next->isOneOf(tok::identifier, tok::coloncolon) &&
+   !Next->startsSequence(tok::coloncolon, tok::star)) {
   Next = Next->Next;
+}
 if (Next && Next->is(TT_TemplateOpener)) {
   Next = Next->MatchingParen;
   // Move to the end of any template class members e.g.

diff  --git a/clang/unittests/Format/QualifierFixerTest.cpp 
b/clang/unittests/Format/QualifierFixerTest.cpp
index 875ad8353e01..d320eacc52c8 100755
--- a/clang/unittests/Format/QualifierFixerTest.cpp
+++ b/clang/unittests/Format/QualifierFixerTest.cpp
@@ -420,6 +420,16 @@ TEST_F(QualifierFixerTest, RightQualifier) {
 
   // don't adjust macros
   verifyFormat("const INTPTR a;", "const INTPTR a;", Style);
+
+  // Pointers to members
+  verifyFormat("int S::*a;", Style);
+  verifyFormat("int const S::*a;", "const int S:: *a;", Style);
+  verifyFormat("int const S::*const a;", "const int S::* const a;", Style);
+  verifyFormat("int A::*const A::*p1;", Style);
+  verifyFormat("float (C::*p)(int);", Style);
+  verifyFormat("float (C::*const p)(int);", Style);
+  verifyFormat("float (C::*p)(int) const;", Style);
+  verifyFormat("float const (C::*p)(int);", "const float (C::*p)(int);", 
Style);
 }
 
 TEST_F(QualifierFixerTest, LeftQualifier) {
@@ -565,6 +575,16 @@ TEST_F(QualifierFixerTest, LeftQualifier) {
 
   // don't adjust macros
   verifyFormat("INTPTR const a;", "INTPTR const a;", Style);
+
+  // Pointers to members
+  verifyFormat("int S::*a;", Style);
+  verifyFormat("const int S::*a;", "int const S:: *a;", Style);
+  verifyFormat("const int S::*const a;", "int const S::* const a;", Style);
+  verifyFormat("int A::*const A::*p1;", Style);
+  verifyFormat("float (C::*p)(int);", Style);
+  verifyFormat("float (C::*const p)(int);", Style);
+  verifyFormat("float (C::*p)(int) const;", Style);
+  verifyFormat("const float (C::*p)(int);", "float const (C::*p)(int);", 
Style);
 }
 
 TEST_F(QualifierFixerTest, ConstVolatileQualifiersOrder) {



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


[PATCH] D144296: [clang-format] Rewrite how indent is reduced for compacted namespaces

2023-02-25 Thread Emilia Dreamer 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 rG7ba91016c6ad: [clang-format] Rewrite how indent is reduced 
for compacted namespaces (authored by rymiel).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144296

Files:
  clang/lib/Format/UnwrappedLineFormatter.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -4431,6 +4431,46 @@
"int k; }} // namespace out::mid",
Style));
 
+  verifyFormat("namespace A { namespace B { namespace C {\n"
+   "  int i;\n"
+   "}}} // namespace A::B::C\n"
+   "int main() {\n"
+   "  if (true)\n"
+   "return 0;\n"
+   "}",
+   "namespace A { namespace B {\n"
+   "namespace C {\n"
+   "  int i;\n"
+   "}} // namespace B::C\n"
+   "} // namespace A\n"
+   "int main() {\n"
+   "  if (true)\n"
+   "return 0;\n"
+   "}",
+   Style);
+
+  verifyFormat("namespace A { namespace B { namespace C {\n"
+   "#ifdef FOO\n"
+   "  int i;\n"
+   "#endif\n"
+   "}}} // namespace A::B::C\n"
+   "int main() {\n"
+   "  if (true)\n"
+   "return 0;\n"
+   "}",
+   "namespace A { namespace B {\n"
+   "namespace C {\n"
+   "#ifdef FOO\n"
+   "  int i;\n"
+   "#endif\n"
+   "}} // namespace B::C\n"
+   "} // namespace A\n"
+   "int main() {\n"
+   "  if (true)\n"
+   "return 0;\n"
+   "}",
+   Style);
+
   Style.NamespaceIndentation = FormatStyle::NI_Inner;
   EXPECT_EQ("namespace out { namespace in {\n"
 "  int i;\n"
Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -60,7 +60,8 @@
 Offset = getIndentOffset(*Line.First);
 // Update the indent level cache size so that we can rely on it
 // having the right size in adjustToUnmodifiedline.
-skipLine(Line, /*UnknownIndent=*/true);
+if (Line.Level >= IndentForLevel.size())
+  IndentForLevel.resize(Line.Level + 1, -1);
 if (Style.IndentPPDirectives != FormatStyle::PPDIS_None &&
 (Line.InPPDirective ||
  (Style.IndentPPDirectives == FormatStyle::PPDIS_BeforeHash &&
@@ -81,13 +82,6 @@
   Indent = Line.Level * Style.IndentWidth + Style.ContinuationIndentWidth;
   }
 
-  /// Update the indent state given that \p Line indent should be
-  /// skipped.
-  void skipLine(const AnnotatedLine &Line, bool UnknownIndent = false) {
-if (Line.Level >= IndentForLevel.size())
-  IndentForLevel.resize(Line.Level + 1, UnknownIndent ? -1 : Indent);
-  }
-
   /// Update the level indent to adapt to the given \p Line.
   ///
   /// When a line is not formatted, we move the subsequent lines on the same
@@ -367,20 +361,27 @@
 // instead of TheLine->First.
 
 if (Style.CompactNamespaces) {
-  if (auto nsToken = TheLine->First->getNamespaceToken()) {
-int i = 0;
-unsigned closingLine = TheLine->MatchingClosingBlockLineIndex - 1;
-for (; I + 1 + i != E &&
-   nsToken->TokenText == getNamespaceTokenText(I[i + 1]) &&
-   closingLine == I[i + 1]->MatchingClosingBlockLineIndex &&
-   I[i + 1]->Last->TotalLength < Limit;
- i++, --closingLine) {
-  // No extra indent for compacted namespaces.
-  IndentTracker.skipLine(*I[i + 1]);
-
-  Limit -= I[i + 1]->Last->TotalLength;
+  if (const auto *NSToken = TheLine->First->getNamespaceToken()) {
+int J = 1;
+assert(TheLine->MatchingClosingBlockLineIndex > 0);
+for (auto ClosingLineIndex = TheLine->MatchingClosingBlockLineIndex - 1;
+ I + J != E && NSToken->TokenText == getNamespaceTokenText(I[J]) &&
+ ClosingLineIndex == I[J]->MatchingClosingBlockLineIndex &&
+ I[J]->Last->TotalLength < Limit;
+ ++J, --ClosingLineIndex) {
+  Limit -= I[J]->Last->TotalLength;
+
+  // Reduce indent level for bodies of namespaces which were compacted,
+  // but only if their content was indented in the first place.
+  auto *ClosingLine = AnnotatedLines.begin() + ClosingLineIndex + 1;
+  auto OutdentBy = I[J]->Level - TheLine->Level;
+  for (auto *CompactedL

[clang] 7ba9101 - [clang-format] Rewrite how indent is reduced for compacted namespaces

2023-02-25 Thread Emilia Dreamer via cfe-commits

Author: Emilia Dreamer
Date: 2023-02-25T12:13:53+02:00
New Revision: 7ba91016c6ad4cb8f82ed154753ddeeb524f9a64

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

LOG: [clang-format] Rewrite how indent is reduced for compacted namespaces

The previous version set the indentation directly using IndentForLevel,
however, this has a few caveats, namely:

* IndentForLevel applies to all scopes of the entire program being
  formatted, but this indentation should only be adjusted for scopes
  of namespaces.

* The method it used only set the correct indent amount if one wasn't
  already set for a given level, meaning it didn't work correctly if
  anything with indentation preceded a namespace keyword. This
  includes preprocessing directives if using IndentPPDirectives.

This patch instead reduces the Level of all lines within namespaces
which are compacted by CompactNamespaces. This means they will get
correct indentation using the normal process.

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

Reviewed By: owenpan, MyDeveloperDay, HazardyKnusperkeks

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

Added: 


Modified: 
clang/lib/Format/UnwrappedLineFormatter.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineFormatter.cpp 
b/clang/lib/Format/UnwrappedLineFormatter.cpp
index 2e3441e6caec..b0314d6cfa75 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -60,7 +60,8 @@ class LevelIndentTracker {
 Offset = getIndentOffset(*Line.First);
 // Update the indent level cache size so that we can rely on it
 // having the right size in adjustToUnmodifiedline.
-skipLine(Line, /*UnknownIndent=*/true);
+if (Line.Level >= IndentForLevel.size())
+  IndentForLevel.resize(Line.Level + 1, -1);
 if (Style.IndentPPDirectives != FormatStyle::PPDIS_None &&
 (Line.InPPDirective ||
  (Style.IndentPPDirectives == FormatStyle::PPDIS_BeforeHash &&
@@ -81,13 +82,6 @@ class LevelIndentTracker {
   Indent = Line.Level * Style.IndentWidth + Style.ContinuationIndentWidth;
   }
 
-  /// Update the indent state given that \p Line indent should be
-  /// skipped.
-  void skipLine(const AnnotatedLine &Line, bool UnknownIndent = false) {
-if (Line.Level >= IndentForLevel.size())
-  IndentForLevel.resize(Line.Level + 1, UnknownIndent ? -1 : Indent);
-  }
-
   /// Update the level indent to adapt to the given \p Line.
   ///
   /// When a line is not formatted, we move the subsequent lines on the same
@@ -367,20 +361,27 @@ class LineJoiner {
 // instead of TheLine->First.
 
 if (Style.CompactNamespaces) {
-  if (auto nsToken = TheLine->First->getNamespaceToken()) {
-int i = 0;
-unsigned closingLine = TheLine->MatchingClosingBlockLineIndex - 1;
-for (; I + 1 + i != E &&
-   nsToken->TokenText == getNamespaceTokenText(I[i + 1]) &&
-   closingLine == I[i + 1]->MatchingClosingBlockLineIndex &&
-   I[i + 1]->Last->TotalLength < Limit;
- i++, --closingLine) {
-  // No extra indent for compacted namespaces.
-  IndentTracker.skipLine(*I[i + 1]);
-
-  Limit -= I[i + 1]->Last->TotalLength;
+  if (const auto *NSToken = TheLine->First->getNamespaceToken()) {
+int J = 1;
+assert(TheLine->MatchingClosingBlockLineIndex > 0);
+for (auto ClosingLineIndex = TheLine->MatchingClosingBlockLineIndex - 
1;
+ I + J != E && NSToken->TokenText == getNamespaceTokenText(I[J]) &&
+ ClosingLineIndex == I[J]->MatchingClosingBlockLineIndex &&
+ I[J]->Last->TotalLength < Limit;
+ ++J, --ClosingLineIndex) {
+  Limit -= I[J]->Last->TotalLength;
+
+  // Reduce indent level for bodies of namespaces which were compacted,
+  // but only if their content was indented in the first place.
+  auto *ClosingLine = AnnotatedLines.begin() + ClosingLineIndex + 1;
+  auto OutdentBy = I[J]->Level - TheLine->Level;
+  for (auto *CompactedLine = I + J; CompactedLine <= ClosingLine;
+   ++CompactedLine) {
+if (!(*CompactedLine)->InPPDirective)
+  (*CompactedLine)->Level -= OutdentBy;
+  }
 }
-return i;
+return J - 1;
   }
 
   if (auto nsToken = getMatchingNamespaceToken(TheLine, AnnotatedLines)) {

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 97a0bfae2701..437e7b62a15d 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -4431,6 +4431,46 @@ TEST_F(FormatTest, FormatsCompactNamespaces) {

[PATCH] D144537: [clang-format] Don't move qualifiers past pointers-to-member

2023-02-25 Thread Emilia Dreamer via Phabricator via cfe-commits
rymiel added a comment.

In D144537#4145545 , @MyDeveloperDay 
wrote:

> maybe we should cherry pick into 16?

It's up to one of you (mostly because I don't know how to do backports and I 
don't want to mess it up)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144537

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


[PATCH] D144709: [clang-format] Improve west to east const

2023-02-25 Thread Emilia Dreamer via Phabricator via cfe-commits
rymiel added a comment.

just as a heads up, I'm applying https://reviews.llvm.org/D144537 since it's a 
quick bug fix; this patch *would* replace that one, but may need more time. 
(also conflicts may appear)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144709

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


[PATCH] D144074: [clangd] Hide inlay hints when using a macro as a calling argument that with a param comment

2023-02-25 Thread Younan Zhang via Phabricator via cfe-commits
zyounan updated this revision to Diff 500388.
zyounan added a comment.

Update


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144074

Files:
  clang-tools-extra/clangd/InlayHints.cpp
  clang-tools-extra/clangd/unittests/InlayHintTests.cpp


Index: clang-tools-extra/clangd/unittests/InlayHintTests.cpp
===
--- clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -1050,9 +1050,15 @@
 void bar() {
   foo(/*param*/42);
   foo( /* param = */ 42);
+#define X 42
+#define Y X
+#define Z(...) Y
+  foo(/*param=*/Z(a));
+  foo($macro[[Z(a)]]);
   foo(/* the answer */$param[[42]]);
 }
   )cpp",
+   ExpectedHint{"param: ", "macro"},
ExpectedHint{"param: ", "param"});
 }
 
Index: clang-tools-extra/clangd/InlayHints.cpp
===
--- clang-tools-extra/clangd/InlayHints.cpp
+++ clang-tools-extra/clangd/InlayHints.cpp
@@ -516,8 +516,8 @@
   // at the end.
   bool isPrecededByParamNameComment(const Expr *E, StringRef ParamName) {
 auto &SM = AST.getSourceManager();
-auto ExprStartLoc = SM.getTopMacroCallerLoc(E->getBeginLoc());
-auto Decomposed = SM.getDecomposedLoc(ExprStartLoc);
+auto FileLoc = SM.getFileLoc(E->getBeginLoc());
+auto Decomposed = SM.getDecomposedLoc(FileLoc);
 if (Decomposed.first != MainFileID)
   return false;
 


Index: clang-tools-extra/clangd/unittests/InlayHintTests.cpp
===
--- clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -1050,9 +1050,15 @@
 void bar() {
   foo(/*param*/42);
   foo( /* param = */ 42);
+#define X 42
+#define Y X
+#define Z(...) Y
+  foo(/*param=*/Z(a));
+  foo($macro[[Z(a)]]);
   foo(/* the answer */$param[[42]]);
 }
   )cpp",
+   ExpectedHint{"param: ", "macro"},
ExpectedHint{"param: ", "param"});
 }
 
Index: clang-tools-extra/clangd/InlayHints.cpp
===
--- clang-tools-extra/clangd/InlayHints.cpp
+++ clang-tools-extra/clangd/InlayHints.cpp
@@ -516,8 +516,8 @@
   // at the end.
   bool isPrecededByParamNameComment(const Expr *E, StringRef ParamName) {
 auto &SM = AST.getSourceManager();
-auto ExprStartLoc = SM.getTopMacroCallerLoc(E->getBeginLoc());
-auto Decomposed = SM.getDecomposedLoc(ExprStartLoc);
+auto FileLoc = SM.getFileLoc(E->getBeginLoc());
+auto Decomposed = SM.getDecomposedLoc(FileLoc);
 if (Decomposed.first != MainFileID)
   return false;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144074: [clangd] Hide inlay hints when using a macro as a calling argument that with a param comment

2023-02-25 Thread Younan Zhang via Phabricator via cfe-commits
zyounan added inline comments.



Comment at: clang-tools-extra/clangd/InlayHints.cpp:520
 auto ExprStartLoc = SM.getTopMacroCallerLoc(E->getBeginLoc());
-auto Decomposed = SM.getDecomposedLoc(ExprStartLoc);
+auto Decomposed = SM.getDecomposedExpansionLoc(ExprStartLoc);
 if (Decomposed.first != MainFileID)

nridge wrote:
> I admit I struggle with this spelling/expansion loc stuff. But having spent a 
> bit of time reading the implementations of these functions, would I be 
> correct to say that another, perhaps easier to follow, way to express the 
> same thing would be:
> 
> ```
> auto Decomposed = SM.getDecomposedLoc(SM.getFileLoc(E->getBeginLoc()));
> ```
> 
> ?
Yes, indeed. `SM.getFileLoc` performs exactly the same function as 
`getTopMacroCallerLoc` and `getDecomposedExpansionLoc`: 
If Loc is a FileID, just return Loc. 
In another case it falls into a loop until the result is a FileID: First obtain 
the "top macro caller" location, then the beginning expansion location.



Comment at: clang-tools-extra/clangd/InlayHints.cpp:521
+auto Decomposed = SM.getDecomposedExpansionLoc(ExprStartLoc);
 if (Decomposed.first != MainFileID)
   return false;

nridge wrote:
> zyounan wrote:
> > stupid question: I was suspicious with this check that when would 
> > `Decomposed.first` not being the same as MainFileID? Should the 
> > "top-caller" of the macro always be in main file? I didn't find a case that 
> > differs, except when `getDecomposedLoc` provides wrong FileID.
> I tried adding an assertion in this early-return branch, and it tripped in 
> `ParameterHints.IncludeAtNonGlobalScope`.
> 
> The code there is:
> 
> ```
>   Annotations FooInc(R"cpp(
> void bar() { foo(42); }
>   )cpp");
>   Annotations FooCC(R"cpp(
> struct S {
>   void foo(int param);
>   #include "foo.inc"
> };
>   )cpp");
> ```
> 
> so I guess the decomposed loc there is a file loc, but not in the main file 
> (but rather in `foo.inc`).
Ah, I see. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144074

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


[PATCH] D144074: [clangd] Hide inlay hints when using a macro as a calling argument that with a param comment

2023-02-25 Thread Younan Zhang via Phabricator via cfe-commits
zyounan updated this revision to Diff 500387.
zyounan marked an inline comment as done.
zyounan added a comment.

Address the comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144074

Files:
  clang-tools-extra/clangd/InlayHints.cpp
  clang-tools-extra/clangd/unittests/InlayHintTests.cpp


Index: clang-tools-extra/clangd/unittests/InlayHintTests.cpp
===
--- clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -1050,9 +1050,15 @@
 void bar() {
   foo(/*param*/42);
   foo( /* param = */ 42);
+#define X 42
+#define Y X
+#define Z(...) Y
+  foo(/*param=*/Z(a));
+  foo($macro[[Z(a)]]);
   foo(/* the answer */$param[[42]]);
 }
   )cpp",
+   ExpectedHint{"param: ", "macro"},
ExpectedHint{"param: ", "param"});
 }
 
Index: clang-tools-extra/clangd/InlayHints.cpp
===
--- clang-tools-extra/clangd/InlayHints.cpp
+++ clang-tools-extra/clangd/InlayHints.cpp
@@ -516,8 +516,8 @@
   // at the end.
   bool isPrecededByParamNameComment(const Expr *E, StringRef ParamName) {
 auto &SM = AST.getSourceManager();
-auto ExprStartLoc = SM.getTopMacroCallerLoc(E->getBeginLoc());
-auto Decomposed = SM.getDecomposedLoc(ExprStartLoc);
+auto ExpansionLoc = SM.getFileLoc(E->getBeginLoc());
+auto Decomposed = SM.getDecomposedLoc(ExpansionLoc);
 if (Decomposed.first != MainFileID)
   return false;
 


Index: clang-tools-extra/clangd/unittests/InlayHintTests.cpp
===
--- clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -1050,9 +1050,15 @@
 void bar() {
   foo(/*param*/42);
   foo( /* param = */ 42);
+#define X 42
+#define Y X
+#define Z(...) Y
+  foo(/*param=*/Z(a));
+  foo($macro[[Z(a)]]);
   foo(/* the answer */$param[[42]]);
 }
   )cpp",
+   ExpectedHint{"param: ", "macro"},
ExpectedHint{"param: ", "param"});
 }
 
Index: clang-tools-extra/clangd/InlayHints.cpp
===
--- clang-tools-extra/clangd/InlayHints.cpp
+++ clang-tools-extra/clangd/InlayHints.cpp
@@ -516,8 +516,8 @@
   // at the end.
   bool isPrecededByParamNameComment(const Expr *E, StringRef ParamName) {
 auto &SM = AST.getSourceManager();
-auto ExprStartLoc = SM.getTopMacroCallerLoc(E->getBeginLoc());
-auto Decomposed = SM.getDecomposedLoc(ExprStartLoc);
+auto ExpansionLoc = SM.getFileLoc(E->getBeginLoc());
+auto Decomposed = SM.getDecomposedLoc(ExpansionLoc);
 if (Decomposed.first != MainFileID)
   return false;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144780: Explicit cast on customized offsetof should not be ignored when evaluating as const

2023-02-25 Thread Ding Fei via Phabricator via cfe-commits
danix800 created this revision.
danix800 added a project: clang.
Herald added subscribers: steakhal, martong.
Herald added a reviewer: NoQ.
Herald added a project: All.
danix800 requested review of this revision.
Herald added a subscriber: cfe-commits.

If ignored, the subexpr is a UnaryOperator (&) which cannot be evaluated 
(assertion failed).

`#define offsetof(type,memb) ((unsigned long)&((type*)0)->memb)`


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144780

Files:
  clang/lib/StaticAnalyzer/Core/BugReporter.cpp
  clang/test/Analysis/bitwise-ops-nocrash.c


Index: clang/test/Analysis/bitwise-ops-nocrash.c
===
--- /dev/null
+++ clang/test/Analysis/bitwise-ops-nocrash.c
@@ -0,0 +1,22 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-output=text 
-triple x86_64-linux-gnu -Wno-shift-count-overflow -verify %s
+
+#define offsetof(type,memb) ((unsigned long)&((type*)0)->memb)
+
+typedef struct {
+  unsigned long guest_counter;
+  unsigned int guest_fpc;
+} S;
+
+// no crash
+int left_shift_overflow_no_crash(unsigned int i) {
+  unsigned shift = 323U; // expected-note{{'shift' initialized to 323}}
+  switch (i) { // expected-note{{Control jumps to 'case 8:'  at line 13}}
+  case offsetof(S, guest_fpc):
+return 3 << shift; // expected-warning{{The result of the left shift is 
undefined due to shifting by '323', which is greater or equal to the width of 
type 'int'}}
+// expected-note@-1{{The result of the left shift is undefined due to 
shifting by '323', which is greater or equal to the width of type 'int'}}
+  default:
+break;
+  }
+
+  return 0;
+}
Index: clang/lib/StaticAnalyzer/Core/BugReporter.cpp
===
--- clang/lib/StaticAnalyzer/Core/BugReporter.cpp
+++ clang/lib/StaticAnalyzer/Core/BugReporter.cpp
@@ -766,7 +766,7 @@
 case Stmt::CaseStmtClass: {
   os << "Control jumps to 'case ";
   const auto *Case = cast(S);
-  const Expr *LHS = Case->getLHS()->IgnoreParenCasts();
+  const Expr *LHS = Case->getLHS()->IgnoreParenImpCasts();
 
   // Determine if it is an enum.
   bool GetRawInt = true;


Index: clang/test/Analysis/bitwise-ops-nocrash.c
===
--- /dev/null
+++ clang/test/Analysis/bitwise-ops-nocrash.c
@@ -0,0 +1,22 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-output=text -triple x86_64-linux-gnu -Wno-shift-count-overflow -verify %s
+
+#define offsetof(type,memb) ((unsigned long)&((type*)0)->memb)
+
+typedef struct {
+  unsigned long guest_counter;
+  unsigned int guest_fpc;
+} S;
+
+// no crash
+int left_shift_overflow_no_crash(unsigned int i) {
+  unsigned shift = 323U; // expected-note{{'shift' initialized to 323}}
+  switch (i) { // expected-note{{Control jumps to 'case 8:'  at line 13}}
+  case offsetof(S, guest_fpc):
+return 3 << shift; // expected-warning{{The result of the left shift is undefined due to shifting by '323', which is greater or equal to the width of type 'int'}}
+// expected-note@-1{{The result of the left shift is undefined due to shifting by '323', which is greater or equal to the width of type 'int'}}
+  default:
+break;
+  }
+
+  return 0;
+}
Index: clang/lib/StaticAnalyzer/Core/BugReporter.cpp
===
--- clang/lib/StaticAnalyzer/Core/BugReporter.cpp
+++ clang/lib/StaticAnalyzer/Core/BugReporter.cpp
@@ -766,7 +766,7 @@
 case Stmt::CaseStmtClass: {
   os << "Control jumps to 'case ";
   const auto *Case = cast(S);
-  const Expr *LHS = Case->getLHS()->IgnoreParenCasts();
+  const Expr *LHS = Case->getLHS()->IgnoreParenImpCasts();
 
   // Determine if it is an enum.
   bool GetRawInt = true;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits