[PATCH] D144522: [clang-tidy] Add readability-operators-representation check

2023-04-01 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

In D144522#4236636 , @PiotrZSL wrote:

> @carlosgalvezp
> Thank you, by any chance would you be able to look into other reviews ?

Doing my best to catch up, I have a long list of patches to review! 
Unfortunately very limited availability at the moment, mostly only weekends. I 
tend to prioritize smaller patches that fix things since they are easier/faster 
to review, but I'll definitely come back to your other larger patches when I 
find some time :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144522

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


[PATCH] D144347: [clang-tidy] Add readability-forward-usage check

2023-04-01 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL planned changes to this revision.
PiotrZSL added a comment.

TODO: Extract DisableTypeMismatchSuggestion & that logic into separate check in 
bugprone category.
TODO: Validate more situations with templates.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144347

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


[PATCH] D146881: [clang-tidy] Fix findNextTokenSkippingComments & rangeContainsExpansionsOrDirectives

2023-04-01 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

I'm surprised we don't have unit tests that catch this?




Comment at: clang-tools-extra/clang-tidy/utils/LexerUtils.cpp:84-85
+Lexer::findNextToken(Start, SM, LangOpts);
+if (!CurrentToken || !CurrentToken->is(tok::comment))
+  return CurrentToken;
+

I'm not sure this logic is correct - `if (CurrentToken` is there to ensure that 
`CurrentToken` is not a nullopt before dereferencing via `CurrentToken->is`. It 
should be:

```
if (CurrentToken && !CurrentToken->is(tok::comment))
  return CurrentToken;
```



Comment at: clang-tools-extra/clang-tidy/utils/LexerUtils.cpp:99
 
-  while (Loc < Range.getEnd()) {
+  while (Loc <= Range.getEnd()) {
 if (Loc.isMacroID())

This is a bit unintuitive if we compare it with e.g. STL iterators - `end()` is 
always "one-past" the end. What's the convention for `SourceRange`, does `end` 
contain a valid end range, or one-past-the-end?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146881

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


[PATCH] D146881: [clang-tidy] Fix findNextTokenSkippingComments & rangeContainsExpansionsOrDirectives

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



Comment at: clang-tools-extra/clang-tidy/utils/LexerUtils.cpp:84-85
+Lexer::findNextToken(Start, SM, LangOpts);
+if (!CurrentToken || !CurrentToken->is(tok::comment))
+  return CurrentToken;
+

carlosgalvezp wrote:
> I'm not sure this logic is correct - `if (CurrentToken` is there to ensure 
> that `CurrentToken` is not a nullopt before dereferencing via 
> `CurrentToken->is`. It should be:
> 
> ```
> if (CurrentToken && !CurrentToken->is(tok::comment))
>   return CurrentToken;
> ```
Current code is correct, it's inversion of what we had in while, simply if no 
token, or token is not comment, then leave.



Comment at: clang-tools-extra/clang-tidy/utils/LexerUtils.cpp:99
 
-  while (Loc < Range.getEnd()) {
+  while (Loc <= Range.getEnd()) {
 if (Loc.isMacroID())

carlosgalvezp wrote:
> This is a bit unintuitive if we compare it with e.g. STL iterators - `end()` 
> is always "one-past" the end. What's the convention for `SourceRange`, does 
> `end` contain a valid end range, or one-past-the-end?
In SourceRange end is pointing to last token, not to last token + 1.
This is inclusive range.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146881

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


[PATCH] D146881: [clang-tidy] Fix findNextTokenSkippingComments & rangeContainsExpansionsOrDirectives

2023-04-01 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added a comment.

We don't have unit tests for most of code... It's usually tested indirectly by 
checks... But this code is used I think only in 1-2 checks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146881

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


[PATCH] D139653: [clang] Set ShowInSystemHeader for module-build and module-import remarks

2023-04-01 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added subscribers: ChuanqiXu, aaron.ballman.
aaron.ballman added a reviewer: ChuanqiXu.
aaron.ballman added a comment.

CC @ChuanqiXu -- this relates to our discussions about diagnostics in modules. 
Are you okay with the direction this change is going?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139653

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


[PATCH] D147376: [clang-tidy] Small refactor for ExceptionAnalyzer

2023-04-01 Thread André Schackier via Phabricator via cfe-commits
AMS21 created this revision.
AMS21 added a reviewer: njames93.
Herald added subscribers: PiotrZSL, carlosgalvezp, manas, ASDenysPetrov, 
dkrupp, donat.nagy, Szelethus, a.sidorin, baloghadamsoftware, xazax.hun.
Herald added a project: All.
AMS21 requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

- Use llvm::DenseMap<> with pre-allocation instead of std::map<> for 
FunctionCache
- Avoid double lookup for FunctionCache
- Use try_emplace instead of insert
- Simplify definition of State enum


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147376

Files:
  clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp
  clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.h


Index: clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.h
===
--- clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.h
+++ clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.h
@@ -21,11 +21,11 @@
 /// custom exception types.
 class ExceptionAnalyzer {
 public:
-  enum class State : std::int8_t {
-Throwing = 0,///< The function can definitely throw given an AST.
-NotThrowing = 1, ///< This function can not throw, given an AST.
-Unknown = 2, ///< This can happen for extern functions without 
available
- ///< definition.
+  enum class State {
+Throwing,///< The function can definitely throw given an AST.
+NotThrowing, ///< This function can not throw, given an AST.
+Unknown, ///< This can happen for extern functions without available
+ ///< definition.
   };
 
   /// Bundle the gathered information about an entity like a function regarding
@@ -144,7 +144,7 @@
 
   bool IgnoreBadAlloc = true;
   llvm::StringSet<> IgnoredExceptions;
-  std::map FunctionCache;
+  llvm::DenseMap FunctionCache{32u};
 };
 
 } // namespace clang::tidy::utils
Index: clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp
===
--- clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp
+++ clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp
@@ -537,7 +537,8 @@
   ExceptionInfo ExceptionList;
 
   // Check if the function has already been analyzed and reuse that result.
-  if (FunctionCache.count(Func) == 0) {
+  const auto CacheEntry = FunctionCache.find(Func);
+  if (CacheEntry == FunctionCache.end()) {
 llvm::SmallSet CallStack;
 ExceptionList = throwsException(Func, CallStack);
 
@@ -545,9 +546,9 @@
 // because it is best to keep as much information as possible.
 // The results here might be relevant to different analysis passes
 // with different needs as well.
-FunctionCache.insert(std::make_pair(Func, ExceptionList));
+FunctionCache.try_emplace(Func, ExceptionList);
   } else
-ExceptionList = FunctionCache[Func];
+ExceptionList = CacheEntry->getSecond();
 
   return ExceptionList;
 }
@@ -579,8 +580,7 @@
   return analyzeDispatch(Func);
 }
 
-ExceptionAnalyzer::ExceptionInfo
-ExceptionAnalyzer::analyze(const Stmt *Stmt) {
+ExceptionAnalyzer::ExceptionInfo ExceptionAnalyzer::analyze(const Stmt *Stmt) {
   return analyzeDispatch(Stmt);
 }
 


Index: clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.h
===
--- clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.h
+++ clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.h
@@ -21,11 +21,11 @@
 /// custom exception types.
 class ExceptionAnalyzer {
 public:
-  enum class State : std::int8_t {
-Throwing = 0,///< The function can definitely throw given an AST.
-NotThrowing = 1, ///< This function can not throw, given an AST.
-Unknown = 2, ///< This can happen for extern functions without available
- ///< definition.
+  enum class State {
+Throwing,///< The function can definitely throw given an AST.
+NotThrowing, ///< This function can not throw, given an AST.
+Unknown, ///< This can happen for extern functions without available
+ ///< definition.
   };
 
   /// Bundle the gathered information about an entity like a function regarding
@@ -144,7 +144,7 @@
 
   bool IgnoreBadAlloc = true;
   llvm::StringSet<> IgnoredExceptions;
-  std::map FunctionCache;
+  llvm::DenseMap FunctionCache{32u};
 };
 
 } // namespace clang::tidy::utils
Index: clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp
===
--- clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp
+++ clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp
@@ -537,7 +537,8 @@
   ExceptionInfo ExceptionList;
 
   // Check if the function has already been analyzed and reuse that result.
-  if (FunctionCache.count(Func) == 0) {
+  const auto CacheEntry = FunctionCache.find(Func);
+  if (CacheEntry == FunctionCache.end()) {
 llvm:

[PATCH] D147349: [C2x] Implement support for empty brace initialization (WG14 N2900 and WG14 N3011)

2023-04-01 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman updated this revision to Diff 510213.
aaron.ballman added a comment.

Fixed some test failures found by precommit CI.


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

https://reviews.llvm.org/D147349

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticCommonKinds.td
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/lib/Parse/ParseInit.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/test/C/C2x/n2900_n3011.c
  clang/test/C/C2x/n2900_n3011_2.c
  clang/test/Sema/array-init.c
  clang/test/Sema/complex-init-list.c
  clang/test/Sema/compound-literal.c
  clang/test/Sema/flexible-array-init.c
  clang/test/Sema/gnu-flags.c
  clang/test/Sema/sizeless-1.c
  clang/test/Sema/vla.c
  clang/test/SemaObjC/property.m
  clang/test/SemaOpenCL/intel-subgroup-avc-ext-types.cl
  clang/www/c_status.html

Index: clang/www/c_status.html
===
--- clang/www/c_status.html
+++ clang/www/c_status.html
@@ -1083,11 +1083,11 @@
 

 https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2900.htm";>N2900
-Unknown
+Clang 17
   

 https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3011.htm";>N3011
-Unknown
+Clang 17
   
 
   Not-so-magic: typeof
Index: clang/test/SemaOpenCL/intel-subgroup-avc-ext-types.cl
===
--- clang/test/SemaOpenCL/intel-subgroup-avc-ext-types.cl
+++ clang/test/SemaOpenCL/intel-subgroup-avc-ext-types.cl
@@ -28,37 +28,34 @@
   intel_sub_group_avc_sic_result_t result_sic = ss;
   intel_sub_group_avc_ime_result_single_reference_streamout_t sstreamout = v;
   intel_sub_group_avc_ime_result_dual_reference_streamout_t dstreamin_list = {0x0, 0x1};
-  intel_sub_group_avc_ime_dual_reference_streamin_t dstreamin_list2 = {};
   intel_sub_group_avc_ime_single_reference_streamin_t dstreamin_list3 = {c};
   intel_sub_group_avc_ime_dual_reference_streamin_t dstreamin_list4 = {1};
 #ifdef EXT
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_mce_payload_t' with an expression of incompatible type 'int'}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_ime_payload_t' with an expression of incompatible type 'int'}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_ref_payload_t' with an expression of incompatible type '__private float'}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_sic_payload_t' with an expression of incompatible type '__private struct st'}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_mce_result_t' with an expression of incompatible type 'int'}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_ime_result_t' with an expression of incompatible type 'int'}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_ref_result_t' with an expression of incompatible type '__private float'}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_sic_result_t' with an expression of incompatible type '__private struct st'}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_ime_result_single_reference_streamout_t' with an expression of incompatible type '__private void *__private'}}
-// expected-warning@-14 {{excess elements in struct initializer}}
-// expected-error@-14 {{scalar initializer cannot be empty}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_ime_single_reference_streamin_t' with an expression of incompatible type '__private char'}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_ime_dual_reference_streamin_t' with an expression of incompatible type 'int'}}
+// expected-error@-13 {{initializing '__private intel_sub_group_avc_mce_payload_t' with an expression of incompatible type 'int'}}
+// expected-error@-13 {{initializing '__private intel_sub_group_avc_ime_payload_t' with an expression of incompatible type 'int'}}
+// expected-error@-13 {{initializing '__private intel_sub_group_avc_ref_payload_t' with an expression of incompatible type '__private float'}}
+// expected-error@-13 {{initializing '__private intel_sub_group_avc_sic_payload_t' with an expression of incompatible type '__private struct st'}}
+// expected-error@-13 {{initializing '__private intel_sub_group_avc_mce_result_t' with an expression of incompatible type 'int'}}
+// expected-error@-13 {{initializing '__private intel_sub_group_avc_ime_result_t' with an expression of incompatible type 'int'}}
+// expected-error@-13 {{initializing '__private intel_sub_group_avc_ref_result_t' with an expression of incompatible type '__private float'}}
+// expected-error@-13 {{initializing '__private intel_sub_group_avc_sic_result_t' with an expression of incompatible type '__private struct st

[PATCH] D147377: [clang-format] Don't allow variable decls to have trailing return arrows

2023-04-01 Thread Emilia Dreamer via Phabricator via cfe-commits
rymiel created this revision.
rymiel added a project: clang-format.
rymiel added reviewers: HazardyKnusperkeks, owenpan, MyDeveloperDay.
Herald added projects: All, clang.
Herald added a subscriber: cfe-commits.
rymiel requested review of this revision.

The heuristic for determining if an arrow is a trailing return arrow
looks for the auto keyword, along with parentheses. This isn't
sufficient, since it also triggers on variable declarations with an auto
type, and with an arrow operator.

This patch unsets the `auto` state when the annotator encounters the
equals sign of a variable declaration.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147377

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1468,6 +1468,72 @@
   EXPECT_TOKEN(Tokens[9], tok::colon, TT_GenericSelectionColon);
 }
 
+TEST_F(TokenAnnotatorTest, UnderstandsTrailingReturnArrow) {
+  auto Tokens = annotate("auto f() -> int;");
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::arrow, TT_TrailingReturnArrow);
+
+  Tokens = annotate("auto operator->() -> int;");
+  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
+  EXPECT_TOKEN(Tokens[2], tok::arrow, TT_OverloadedOperator);
+  EXPECT_TOKEN(Tokens[5], tok::arrow, TT_TrailingReturnArrow);
+
+  Tokens = annotate("auto operator++(int) -> int;");
+  ASSERT_EQ(Tokens.size(), 10u) << Tokens;
+  EXPECT_TOKEN(Tokens[6], tok::arrow, TT_TrailingReturnArrow);
+
+  Tokens = annotate("auto operator=() -> int;");
+  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
+  EXPECT_TOKEN(Tokens[5], tok::arrow, TT_TrailingReturnArrow);
+
+  Tokens = annotate("auto operator=(int) -> int;");
+  ASSERT_EQ(Tokens.size(), 10u) << Tokens;
+  EXPECT_TOKEN(Tokens[6], tok::arrow, TT_TrailingReturnArrow);
+
+  Tokens = annotate("auto foo() -> auto { return Val; }");
+  ASSERT_EQ(Tokens.size(), 12u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::arrow, TT_TrailingReturnArrow);
+
+  Tokens = annotate("struct S { auto bar() const -> int; };");
+  ASSERT_EQ(Tokens.size(), 14u) << Tokens;
+  EXPECT_TOKEN(Tokens[8], tok::arrow, TT_TrailingReturnArrow);
+
+  // Not trailing return arrows
+  Tokens = annotate("auto a = b->c;");
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::arrow, TT_Unknown);
+
+  Tokens = annotate("auto a = (b)->c;");
+  ASSERT_EQ(Tokens.size(), 10u) << Tokens;
+  EXPECT_TOKEN(Tokens[6], tok::arrow, TT_Unknown);
+
+  Tokens = annotate("auto a = b()->c;");
+  ASSERT_EQ(Tokens.size(), 10u) << Tokens;
+  EXPECT_TOKEN(Tokens[6], tok::arrow, TT_Unknown);
+
+  Tokens = annotate("auto a = b->c();");
+  ASSERT_EQ(Tokens.size(), 10u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::arrow, TT_Unknown);
+
+  Tokens = annotate("decltype(auto) a = b()->c;");
+  ASSERT_EQ(Tokens.size(), 13u) << Tokens;
+  EXPECT_TOKEN(Tokens[9], tok::arrow, TT_Unknown);
+
+  Tokens = annotate("void f() { auto a = b->c(); }");
+  ASSERT_EQ(Tokens.size(), 16u) << Tokens;
+  EXPECT_TOKEN(Tokens[9], tok::arrow, TT_Unknown);
+
+  Tokens = annotate("void f() { auto a = b()->c; }");
+  ASSERT_EQ(Tokens.size(), 16u) << Tokens;
+  EXPECT_TOKEN(Tokens[11], tok::arrow, TT_Unknown);
+
+  // Mixed
+  Tokens = annotate("auto f() -> int { auto a = b()->c; }");
+  ASSERT_EQ(Tokens.size(), 18u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::arrow, TT_TrailingReturnArrow);
+  EXPECT_TOKEN(Tokens[13], tok::arrow, TT_Unknown);
+}
+
 TEST_F(TokenAnnotatorTest, UnderstandsVerilogOperators) {
   auto Annotate = [this](llvm::StringRef Code) {
 return annotate(Code, getLLVMStyle(FormatStyle::LK_Verilog));
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1970,6 +1970,12 @@
 if (Current.getPrecedence() == prec::Assignment)
   Contexts.back().VerilogAssignmentFound = true;
   }
+  if (AutoFound && Current.is(tok::equal) && Current.Previous &&
+  Current.Previous->isNot(tok::kw_operator)) {
+// AutoFound is only used for function declarations with `auto`. This
+// looks like a variable declaration, so unset it.
+AutoFound = false;
+  }
   Current.setType(TT_BinaryOperator);
 } else if (Current.is(tok::comment)) {
   if (Current.TokenText.startswith("/*")) {


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1468,6 +1468,72 @@
   EXPECT_TOKEN(Tokens[9], tok::colon, TT_GenericSelectionColon);
 }
 
+TEST_F(TokenAnnotatorTest

[PATCH] D147318: [clang-format] Don't format typename template parameters as expression

2023-04-01 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 rG50acd67018a5: [clang-format] Don't format typename 
template parameters as expression (authored by rymiel).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147318

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -261,6 +261,15 @@
   Tokens = annotate("template  struct S {};");
   ASSERT_EQ(Tokens.size(), 18u) << Tokens;
   EXPECT_TOKEN(Tokens[9], tok::ampamp, TT_BinaryOperator);
+
+  Tokens = annotate("template  struct S {};");
+  ASSERT_EQ(Tokens.size(), 17u) << Tokens;
+  EXPECT_TOKEN(Tokens[9], tok::ampamp, TT_PointerOrReference);
+
+  Tokens = annotate("template  struct S {};");
+  ASSERT_EQ(Tokens.size(), 19u) << Tokens;
+  EXPECT_TOKEN(Tokens[6], tok::l_paren, TT_FunctionTypeLParen);
+  EXPECT_TOKEN(Tokens[7], tok::star, TT_PointerOrReference);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsUsesOfPlusAndMinus) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1723,10 +1723,13 @@
   return false;
 }
 
-// This is the default value of a non-template type parameter, so treat
-// it as an expression.
-if (Contexts.back().ContextKind == tok::less)
-  return true;
+// This is the default value of a template parameter, determine if it's
+// type or non-type.
+if (Contexts.back().ContextKind == tok::less) {
+  assert(Current.Previous->Previous);
+  return !Current.Previous->Previous->isOneOf(tok::kw_typename,
+  tok::kw_class);
+}
 
 Tok = Tok->MatchingParen;
 if (!Tok)


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -261,6 +261,15 @@
   Tokens = annotate("template  struct S {};");
   ASSERT_EQ(Tokens.size(), 18u) << Tokens;
   EXPECT_TOKEN(Tokens[9], tok::ampamp, TT_BinaryOperator);
+
+  Tokens = annotate("template  struct S {};");
+  ASSERT_EQ(Tokens.size(), 17u) << Tokens;
+  EXPECT_TOKEN(Tokens[9], tok::ampamp, TT_PointerOrReference);
+
+  Tokens = annotate("template  struct S {};");
+  ASSERT_EQ(Tokens.size(), 19u) << Tokens;
+  EXPECT_TOKEN(Tokens[6], tok::l_paren, TT_FunctionTypeLParen);
+  EXPECT_TOKEN(Tokens[7], tok::star, TT_PointerOrReference);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsUsesOfPlusAndMinus) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1723,10 +1723,13 @@
   return false;
 }
 
-// This is the default value of a non-template type parameter, so treat
-// it as an expression.
-if (Contexts.back().ContextKind == tok::less)
-  return true;
+// This is the default value of a template parameter, determine if it's
+// type or non-type.
+if (Contexts.back().ContextKind == tok::less) {
+  assert(Current.Previous->Previous);
+  return !Current.Previous->Previous->isOneOf(tok::kw_typename,
+  tok::kw_class);
+}
 
 Tok = Tok->MatchingParen;
 if (!Tok)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 50acd67 - [clang-format] Don't format typename template parameters as expression

2023-04-01 Thread Emilia Dreamer via cfe-commits

Author: Emilia Dreamer
Date: 2023-04-01T16:52:51+03:00
New Revision: 50acd67018a53239f11a2889c28f77a1c7dc8c6b

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

LOG: [clang-format] Don't format typename template parameters as expression

bb4f6c4dca98a47054117708015bb2724256ee83 made it so that template
parameter defaults are seen akin to assignments and formatted as
expressions, however, the patch did this for all template parameters,
even for `typename` template parameters.

This patch formats `typename` and `class` template parameters as types.

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

Reviewed By: HazardyKnusperkeks, owenpan, MyDeveloperDay

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

Added: 


Modified: 
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 1fc190e56c28..b1060bde9ded 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1723,10 +1723,13 @@ class AnnotatingParser {
   return false;
 }
 
-// This is the default value of a non-template type parameter, so treat
-// it as an expression.
-if (Contexts.back().ContextKind == tok::less)
-  return true;
+// This is the default value of a template parameter, determine if it's
+// type or non-type.
+if (Contexts.back().ContextKind == tok::less) {
+  assert(Current.Previous->Previous);
+  return !Current.Previous->Previous->isOneOf(tok::kw_typename,
+  tok::kw_class);
+}
 
 Tok = Tok->MatchingParen;
 if (!Tok)

diff  --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index bea85e5bdba2..19b1d96f75ab 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -261,6 +261,15 @@ TEST_F(TokenAnnotatorTest, UnderstandsUsesOfStarAndAmp) {
   Tokens = annotate("template  struct S {};");
   ASSERT_EQ(Tokens.size(), 18u) << Tokens;
   EXPECT_TOKEN(Tokens[9], tok::ampamp, TT_BinaryOperator);
+
+  Tokens = annotate("template  struct S {};");
+  ASSERT_EQ(Tokens.size(), 17u) << Tokens;
+  EXPECT_TOKEN(Tokens[9], tok::ampamp, TT_PointerOrReference);
+
+  Tokens = annotate("template  struct S {};");
+  ASSERT_EQ(Tokens.size(), 19u) << Tokens;
+  EXPECT_TOKEN(Tokens[6], tok::l_paren, TT_FunctionTypeLParen);
+  EXPECT_TOKEN(Tokens[7], tok::star, TT_PointerOrReference);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsUsesOfPlusAndMinus) {



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


[PATCH] D146881: [clang-tidy] Fix findNextTokenSkippingComments & rangeContainsExpansionsOrDirectives

2023-04-01 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.

> It's usually tested indirectly by checks... But this code is used I think 
> only in 1-2 checks.

I see. I'm still trying to understand why we haven't seen this before. If the 
function is an endless loop, shouldn't the checks that use this function end up 
in an endless loop too? Would be interesting to try and reproduce an endless 
loop in the tests of one of the checks that use this. Anyway the patch is fine 
as is, thanks for fixing!




Comment at: clang-tools-extra/clang-tidy/utils/LexerUtils.cpp:84-85
+Lexer::findNextToken(Start, SM, LangOpts);
+if (!CurrentToken || !CurrentToken->is(tok::comment))
+  return CurrentToken;
+

PiotrZSL wrote:
> carlosgalvezp wrote:
> > I'm not sure this logic is correct - `if (CurrentToken` is there to ensure 
> > that `CurrentToken` is not a nullopt before dereferencing via 
> > `CurrentToken->is`. It should be:
> > 
> > ```
> > if (CurrentToken && !CurrentToken->is(tok::comment))
> >   return CurrentToken;
> > ```
> Current code is correct, it's inversion of what we had in while, simply if no 
> token, or token is not comment, then leave.
You are right, nevermind!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146881

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


[PATCH] D141215: [clang-repl] Introduce Value to capture expression results

2023-04-01 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 510226.
junaire added a comment.

I dont know why the premerge tests are failling, let me try to do a update...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141215

Files:
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Interpreter/Interpreter.h
  clang/include/clang/Interpreter/Value.h
  clang/include/clang/Parse/Parser.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Frontend/PrintPreprocessedOutput.cpp
  clang/lib/Interpreter/CMakeLists.txt
  clang/lib/Interpreter/IncrementalExecutor.cpp
  clang/lib/Interpreter/IncrementalExecutor.h
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Interpreter/IncrementalParser.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/lib/Interpreter/InterpreterUtils.cpp
  clang/lib/Interpreter/InterpreterUtils.h
  clang/lib/Interpreter/Value.cpp
  clang/lib/Lex/PPLexerChange.cpp
  clang/lib/Parse/ParseCXXInlineMethods.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Parse/Parser.cpp
  clang/tools/clang-repl/CMakeLists.txt
  clang/unittests/Interpreter/CMakeLists.txt
  clang/unittests/Interpreter/InterpreterTest.cpp

Index: clang/unittests/Interpreter/InterpreterTest.cpp
===
--- clang/unittests/Interpreter/InterpreterTest.cpp
+++ clang/unittests/Interpreter/InterpreterTest.cpp
@@ -17,6 +17,7 @@
 #include "clang/AST/Mangle.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/TextDiagnosticPrinter.h"
+#include "clang/Interpreter/Value.h"
 #include "clang/Sema/Lookup.h"
 #include "clang/Sema/Sema.h"
 
@@ -33,6 +34,10 @@
 #define CLANG_INTERPRETER_NO_SUPPORT_EXEC
 #endif
 
+int Global = 42;
+int getGlobal() { return Global; }
+void setGlobal(int val) { Global = val; }
+
 namespace {
 using Args = std::vector;
 static std::unique_ptr
@@ -276,8 +281,7 @@
   std::vector Args = {"-fno-delayed-template-parsing"};
   std::unique_ptr Interp = createInterpreter(Args);
 
-  llvm::cantFail(Interp->Parse("void* operator new(__SIZE_TYPE__, void* __p);"
-   "extern \"C\" int printf(const char*,...);"
+  llvm::cantFail(Interp->Parse("extern \"C\" int printf(const char*,...);"
"class A {};"
"struct B {"
"  template"
@@ -314,4 +318,38 @@
   free(NewA);
 }
 
+TEST(InterpreterTest, Value) {
+  std::unique_ptr Interp = createInterpreter();
+
+  Value V1;
+  llvm::cantFail(Interp->ParseAndExecute("int x = 42;"));
+  llvm::cantFail(Interp->ParseAndExecute("x", &V1));
+  EXPECT_EQ(V1.getInt(), 42);
+  EXPECT_TRUE(V1.getType()->isIntegerType());
+
+  Value V2;
+  llvm::cantFail(Interp->ParseAndExecute("double y = 3.14;"));
+  llvm::cantFail(Interp->ParseAndExecute("y", &V2));
+  EXPECT_EQ(V2.getAs(), 3.14);
+  EXPECT_TRUE(V2.getType()->isFloatingType());
+  EXPECT_EQ(V2.castAs(), 3);
+
+  llvm::cantFail(Interp->ParseAndExecute("int getGlobal();"));
+  llvm::cantFail(Interp->ParseAndExecute("void setGlobal(int);"));
+  Value V3;
+  llvm::cantFail(Interp->ParseAndExecute("getGlobal()", &V3));
+  EXPECT_EQ(V3.getInt(), 42);
+  EXPECT_TRUE(V3.getType()->isIntegerType());
+
+  // Change the global from the compiled code.
+  setGlobal(43);
+  Value V4;
+  llvm::cantFail(Interp->ParseAndExecute("getGlobal()", &V4));
+  EXPECT_EQ(V4.getInt(), 43);
+  EXPECT_TRUE(V4.getType()->isIntegerType());
+
+  // Change the global from the interpreted code.
+  llvm::cantFail(Interp->ParseAndExecute("setGlobal(44);"));
+  EXPECT_EQ(getGlobal(), 44);
+}
 } // end anonymous namespace
Index: clang/unittests/Interpreter/CMakeLists.txt
===
--- clang/unittests/Interpreter/CMakeLists.txt
+++ clang/unittests/Interpreter/CMakeLists.txt
@@ -22,3 +22,5 @@
 if(NOT WIN32)
   add_subdirectory(ExceptionTests)
 endif()
+
+export_executable_symbols(ClangReplInterpreterTests)
Index: clang/tools/clang-repl/CMakeLists.txt
===
--- clang/tools/clang-repl/CMakeLists.txt
+++ clang/tools/clang-repl/CMakeLists.txt
@@ -12,6 +12,7 @@
   )
 
 clang_target_link_libraries(clang-repl PRIVATE
+  clangAST
   clangBasic
   clangFrontend
   clangInterpreter
Index: clang/lib/Parse/Parser.cpp
===
--- clang/lib/Parse/Parser.cpp
+++ clang/lib/Parse/Parser.cpp
@@ -320,6 +320,7 @@
 case tok::annot_module_begin:
 case tok::annot_module_end:
 case tok::annot_module_include:
+case tok::annot_input_end:
   // Stop before we change submodules. They generally indicate a "good"
   // place to pick up parsing again (except in the special case where
   // we're trying to skip to EOF).
@@ -616,8 +617,8 @@
 
   // Skip over the EOF token, flagging end of previous input for

[PATCH] D147349: [C2x] Implement support for empty brace initialization (WG14 N2900 and WG14 N3011)

2023-04-01 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman updated this revision to Diff 510228.
aaron.ballman added a comment.

Another round of fixing what post commit CI found.


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

https://reviews.llvm.org/D147349

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticCommonKinds.td
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/lib/Parse/ParseInit.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/test/C/C2x/n2900_n3011.c
  clang/test/C/C2x/n2900_n3011_2.c
  clang/test/Sema/array-init.c
  clang/test/Sema/complex-init-list.c
  clang/test/Sema/compound-literal.c
  clang/test/Sema/flexible-array-init.c
  clang/test/Sema/gnu-flags.c
  clang/test/Sema/sizeless-1.c
  clang/test/Sema/vla.c
  clang/test/SemaObjC/property.m
  clang/test/SemaOpenCL/intel-subgroup-avc-ext-types.cl
  clang/www/c_status.html

Index: clang/www/c_status.html
===
--- clang/www/c_status.html
+++ clang/www/c_status.html
@@ -1083,11 +1083,11 @@
 

 https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2900.htm";>N2900
-Unknown
+Clang 17
   

 https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3011.htm";>N3011
-Unknown
+Clang 17
   
 
   Not-so-magic: typeof
Index: clang/test/SemaOpenCL/intel-subgroup-avc-ext-types.cl
===
--- clang/test/SemaOpenCL/intel-subgroup-avc-ext-types.cl
+++ clang/test/SemaOpenCL/intel-subgroup-avc-ext-types.cl
@@ -28,37 +28,34 @@
   intel_sub_group_avc_sic_result_t result_sic = ss;
   intel_sub_group_avc_ime_result_single_reference_streamout_t sstreamout = v;
   intel_sub_group_avc_ime_result_dual_reference_streamout_t dstreamin_list = {0x0, 0x1};
-  intel_sub_group_avc_ime_dual_reference_streamin_t dstreamin_list2 = {};
   intel_sub_group_avc_ime_single_reference_streamin_t dstreamin_list3 = {c};
   intel_sub_group_avc_ime_dual_reference_streamin_t dstreamin_list4 = {1};
 #ifdef EXT
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_mce_payload_t' with an expression of incompatible type 'int'}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_ime_payload_t' with an expression of incompatible type 'int'}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_ref_payload_t' with an expression of incompatible type '__private float'}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_sic_payload_t' with an expression of incompatible type '__private struct st'}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_mce_result_t' with an expression of incompatible type 'int'}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_ime_result_t' with an expression of incompatible type 'int'}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_ref_result_t' with an expression of incompatible type '__private float'}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_sic_result_t' with an expression of incompatible type '__private struct st'}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_ime_result_single_reference_streamout_t' with an expression of incompatible type '__private void *__private'}}
-// expected-warning@-14 {{excess elements in struct initializer}}
-// expected-error@-14 {{scalar initializer cannot be empty}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_ime_single_reference_streamin_t' with an expression of incompatible type '__private char'}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_ime_dual_reference_streamin_t' with an expression of incompatible type 'int'}}
+// expected-error@-13 {{initializing '__private intel_sub_group_avc_mce_payload_t' with an expression of incompatible type 'int'}}
+// expected-error@-13 {{initializing '__private intel_sub_group_avc_ime_payload_t' with an expression of incompatible type 'int'}}
+// expected-error@-13 {{initializing '__private intel_sub_group_avc_ref_payload_t' with an expression of incompatible type '__private float'}}
+// expected-error@-13 {{initializing '__private intel_sub_group_avc_sic_payload_t' with an expression of incompatible type '__private struct st'}}
+// expected-error@-13 {{initializing '__private intel_sub_group_avc_mce_result_t' with an expression of incompatible type 'int'}}
+// expected-error@-13 {{initializing '__private intel_sub_group_avc_ime_result_t' with an expression of incompatible type 'int'}}
+// expected-error@-13 {{initializing '__private intel_sub_group_avc_ref_result_t' with an expression of incompatible type '__private float'}}
+// expected-error@-13 {{initializing '__private intel_sub_group_avc_sic_result_t' with an expression of incompatible type '__private struct

[PATCH] D147379: [clang-tidy] Disable misc-definitions-in-headers for declarations in anonymous namespaces

2023-04-01 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp created this revision.
Herald added subscribers: PiotrZSL, xazax.hun.
Herald added a reviewer: njames93.
Herald added a project: All.
carlosgalvezp requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Anonymous namespaces are another way of providing internal linkage,
and the check already ignores other cases of internal linkage in
headers, via "static" or "const".

Anonymous namespaces in headers are definitely a source of pitfalls,
but it's not the responsibility of this check to cover that. Instead,
google-build-namespaces will specifically warn about this issue.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147379

Files:
  clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/definitions-in-headers.rst
  clang-tools-extra/test/clang-tidy/checkers/misc/definitions-in-headers.hpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/misc/definitions-in-headers.hpp
===
--- clang-tools-extra/test/clang-tidy/checkers/misc/definitions-in-headers.hpp
+++ clang-tools-extra/test/clang-tidy/checkers/misc/definitions-in-headers.hpp
@@ -108,8 +108,7 @@
 int f5(); // OK: function declaration.
 inline int f6() { return 1; } // OK: inline function definition.
 namespace {
-  int f7() { return 1; }
-// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: function 'f7' defined in a header 
file;
+  int f7() { return 1; }  // OK: each TU defines the function in a unique 
namespace
 }
 
 int f8() = delete; // OK: the function being marked delete is not callable.
@@ -142,8 +141,7 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: variable 'ca' defined in a header 
file;
 
 namespace {
-  int e = 2;
-// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: variable 'e' defined in a header 
file;
+  int e = 2;  // OK: each TU defines the variable in a unique namespace
 }
 
 const char* const g = "foo"; // OK: internal linkage variable definition.
Index: clang-tools-extra/docs/clang-tidy/checks/misc/definitions-in-headers.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/misc/definitions-in-headers.rst
+++ clang-tools-extra/docs/clang-tidy/checks/misc/definitions-in-headers.rst
@@ -27,6 +27,7 @@
const int c = 1;
const char* const str2 = "foo";
constexpr int k = 1;
+   namespace { int x = 1; }
 
// Warning: function definition.
int g() {
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -199,6 +199,10 @@
   ` check.
   Global options of the same name should be used instead.
 
+- Fixed false positive in :doc:`misc-definitions-in-headers
+  ` to avoid warning on
+  declarations inside anonymous namespaces.
+
 - Deprecated check-local options `HeaderFileExtensions`
   in :doc:`misc-unused-using-decls
   ` check.
Index: clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
===
--- clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
+++ clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
@@ -90,13 +90,11 @@
   // Internal linkage variable definitions are ignored for now:
   //   const int a = 1;
   //   static int b = 1;
+  //   namespace { int c = 1; }
   //
   // Although these might also cause ODR violations, we can be less certain and
   // should try to keep the false-positive rate down.
-  //
-  // FIXME: Should declarations in anonymous namespaces get the same treatment
-  // as static / const declarations?
-  if (!ND->hasExternalFormalLinkage() && !ND->isInAnonymousNamespace())
+  if (!ND->hasExternalFormalLinkage() || ND->isInAnonymousNamespace())
 return;
 
   if (const auto *FD = dyn_cast(ND)) {


Index: clang-tools-extra/test/clang-tidy/checkers/misc/definitions-in-headers.hpp
===
--- clang-tools-extra/test/clang-tidy/checkers/misc/definitions-in-headers.hpp
+++ clang-tools-extra/test/clang-tidy/checkers/misc/definitions-in-headers.hpp
@@ -108,8 +108,7 @@
 int f5(); // OK: function declaration.
 inline int f6() { return 1; } // OK: inline function definition.
 namespace {
-  int f7() { return 1; }
-// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: function 'f7' defined in a header file;
+  int f7() { return 1; }  // OK: each TU defines the function in a unique namespace
 }
 
 int f8() = delete; // OK: the function being marked delete is not callable.
@@ -142,8 +141,7 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: variable 'ca' defined in a header file;
 
 namespace {
-  int e = 2;
-// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: variabl

[PATCH] D147379: [clang-tidy] Disable misc-definitions-in-headers for declarations in anonymous namespaces

2023-04-01 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko accepted this revision.
Eugene.Zelenko added a comment.
This revision is now accepted and ready to land.

Looks OK for me, but will be good idea to wait for other reviewers.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147379

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


[PATCH] D147315: [clang-tidy] support unscoped enumerations in readability-static-accessed-through-instance

2023-04-01 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 510241.
HerrCai0907 added a comment.

update description


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147315

Files:
  
clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/readability/static-accessed-through-instance.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp
@@ -1,10 +1,21 @@
 // RUN: %check_clang_tidy %s readability-static-accessed-through-instance %t -- -- -isystem %S/Inputs/static-accessed-through-instance
 #include <__clang_cuda_builtin_vars.h>
 
+enum OutEnum {
+  E0,
+};
+
 struct C {
   static void foo();
   static int x;
   int nsx;
+  enum {
+Anonymous,
+  };
+  enum E {
+E1,
+  };
+  using enum OutEnum;
   void mf() {
 (void)&x;// OK, x is accessed inside the struct.
 (void)&C::x; // OK, x is accessed using a qualified-id.
@@ -144,6 +155,16 @@
   c1->x; // 2
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
   // CHECK-FIXES: {{^}}  C::x; // 2{{$}}
+  c1->Anonymous; // 3
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+  // CHECK-FIXES: {{^}}  C::Anonymous; // 3{{$}}
+  c1->E1; // 4
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+  // CHECK-FIXES: {{^}}  C::E1; // 4{{$}}
+  c1->E0; // 5
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+  // CHECK-FIXES: {{^}}  C::E0; // 5{{$}}
+
   c1->nsx; // OK, nsx is a non-static member.
 
   const C *c2 = new C();
Index: clang-tools-extra/docs/clang-tidy/checks/readability/static-accessed-through-instance.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/readability/static-accessed-through-instance.rst
+++ clang-tools-extra/docs/clang-tidy/checks/readability/static-accessed-through-instance.rst
@@ -15,11 +15,15 @@
   struct C {
 static void foo();
 static int x;
+enum { E1 };
+enum E { E2 };
   };
 
   C *c1 = new C();
   c1->foo();
   c1->x;
+  c1->E1;
+  c1->E2;
 
 is changed to:
 
@@ -28,4 +32,6 @@
   C *c1 = new C();
   C::foo();
   C::x;
+  C::E1;
+  C::E2;
 
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -244,6 +244,10 @@
   ` check when warning would
   be unnecessarily emitted for template dependent ``if constexpr``.
 
+- Improved :doc:`readability-static-accessed-through-instance
+  ` check to 
+  support unscoped enumerations through instances.
+
 - Fixed a false positive in :doc:`cppcoreguidelines-slicing
   ` check when warning would be
   emitted in constructor for virtual base class initialization.
Index: clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
@@ -39,7 +39,8 @@
 void StaticAccessedThroughInstanceCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
   memberExpr(hasDeclaration(anyOf(cxxMethodDecl(isStaticStorageClass()),
-  varDecl(hasStaticStorageDuration()
+  varDecl(hasStaticStorageDuration()),
+  enumConstantDecl(
   .bind("memberExpression"),
   this);
 }
@@ -64,15 +65,15 @@
   : BaseExpr->getType().getUnqualifiedType();
 
   const ASTContext *AstContext = Result.Context;
-  PrintingPolicy PrintingPolicyWithSupressedTag(AstContext->getLangOpts());
-  PrintingPolicyWithSupressedTag.SuppressTagKeyword = true;
-  PrintingPolicyWithSupressedTag.SuppressUnwrittenScope = true;
+  PrintingPolicy PrintingPolicyWithSuppressedTag(AstContext->getLangOpts());
+  PrintingPolicyWithSuppressedTag.SuppressTagKeyword = true;
+  PrintingPolicyWithSuppressedTag.SuppressUnwrittenScope = true;
 
-  PrintingPolicyWithSupressedTag.PrintCanonicalTypes =
+  PrintingPolicyWithSuppressedTag.PrintCanonicalTypes =
   !BaseExpr->getType()->isTypedefNameType();
 
   std::string BaseTypeName =
-  BaseType.getAsString(PrintingPolicyWithSupressedTag);
+  BaseType.getAsString(PrintingPolicyWithSuppressedTag);
 
   // Do not warn for CUDA built-in variables.
   if (StringRef(BaseType

[PATCH] D147327: [clang-format] Add option for having one port per line in Verilog

2023-04-01 Thread sstwcw via Phabricator via cfe-commits
sstwcw updated this revision to Diff 510244.
sstwcw marked 2 inline comments as done.
sstwcw added a comment.

- Use shorter conditions


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147327

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/FormatToken.h
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/ConfigParseTest.cpp
  clang/unittests/Format/FormatTestVerilog.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp

Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1579,6 +1579,18 @@
   EXPECT_TOKEN_PRECEDENCE(Tokens[1], prec::Assignment);
   EXPECT_TOKEN(Tokens[3], tok::lessequal, TT_BinaryOperator);
   EXPECT_TOKEN_PRECEDENCE(Tokens[3], prec::Relational);
+
+  // Port lists in module instantiation.
+  Tokens = Annotate("module_x instance_1(port_1), instance_2(port_2);");
+  ASSERT_EQ(Tokens.size(), 12u);
+  EXPECT_TOKEN(Tokens[2], tok::l_paren, TT_VerilogInstancePortLParen);
+  EXPECT_TOKEN(Tokens[7], tok::l_paren, TT_VerilogInstancePortLParen);
+  Tokens = Annotate("module_x #(parameter) instance_1(port_1), "
+"instance_2(port_2);");
+  ASSERT_EQ(Tokens.size(), 16u);
+  EXPECT_TOKEN(Tokens[2], tok::l_paren, TT_VerilogInstancePortLParen);
+  EXPECT_TOKEN(Tokens[6], tok::l_paren, TT_VerilogInstancePortLParen);
+  EXPECT_TOKEN(Tokens[11], tok::l_paren, TT_VerilogInstancePortLParen);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandConstructors) {
Index: clang/unittests/Format/FormatTestVerilog.cpp
===
--- clang/unittests/Format/FormatTestVerilog.cpp
+++ clang/unittests/Format/FormatTestVerilog.cpp
@@ -659,6 +659,77 @@
"  x = x;");
 }
 
+TEST_F(FormatTestVerilog, Instantiation) {
+  // Without ports.
+  verifyFormat("ffnand ff1;");
+  // With named ports.
+  verifyFormat("ffnand ff1(.qbar(out1),\n"
+   "   .clear(in1),\n"
+   "   .preset(in2));");
+  // With wildcard.
+  verifyFormat("ffnand ff1(.qbar(out1),\n"
+   "   .clear(in1),\n"
+   "   .preset(in2),\n"
+   "   .*);");
+  verifyFormat("ffnand ff1(.*,\n"
+   "   .qbar(out1),\n"
+   "   .clear(in1),\n"
+   "   .preset(in2));");
+  // With unconnected ports.
+  verifyFormat("ffnand ff1(.q(),\n"
+   "   .qbar(out1),\n"
+   "   .clear(in1),\n"
+   "   .preset(in2));");
+  verifyFormat("ffnand ff1(.q(),\n"
+   "   .qbar(),\n"
+   "   .clear(),\n"
+   "   .preset());");
+  verifyFormat("ffnand ff1(,\n"
+   "   .qbar(out1),\n"
+   "   .clear(in1),\n"
+   "   .preset(in2));");
+  // With positional ports.
+  verifyFormat("ffnand ff1(out1,\n"
+   "   in1,\n"
+   "   in2);");
+  verifyFormat("ffnand ff1(,\n"
+   "   out1,\n"
+   "   in1,\n"
+   "   in2);");
+  // Multiple instantiations.
+  verifyFormat("ffnand ff1(.q(),\n"
+   "   .qbar(out1),\n"
+   "   .clear(in1),\n"
+   "   .preset(in2)),\n"
+   "   ff1(.q(),\n"
+   "   .qbar(out1),\n"
+   "   .clear(in1),\n"
+   "   .preset(in2));");
+  verifyFormat("ffnand //\n"
+   "ff1(.q(),\n"
+   ".qbar(out1),\n"
+   ".clear(in1),\n"
+   ".preset(in2)),\n"
+   "ff1(.q(),\n"
+   ".qbar(out1),\n"
+   ".clear(in1),\n"
+   ".preset(in2));");
+  // With breaking between instance ports disabled.
+  auto Style = getDefaultStyle();
+  Style.VerilogBreakBetweenInstancePorts = false;
+  verifyFormat("ffnand ff1;", Style);
+  verifyFormat("ffnand ff1(.qbar(out1), .clear(in1), .preset(in2), .*);",
+   Style);
+  verifyFormat("ffnand ff1(out1, in1, in2);", Style);
+  verifyFormat("ffnand ff1(.q(), .qbar(out1), .clear(in1), .preset(in2)),\n"
+   "   ff1(.q(), .qbar(out1), .clear(in1), .preset(in2));",
+   Style);
+  verifyFormat("ffnand //\n"
+   "ff1(.q(), .qbar(out1), .clear(in1), .preset(in2)),\n"
+   "ff1(.q(), .qbar(out1), .clear(in1), .preset(in2));",
+   Style);
+}
+
 TEST_F(FormatTestVerilog, Operators) {
   // Test that unary operators are not followed by space.
   verifyFormat("x

[clang] 92b2be3 - [clang-format] Handle enum in Verilog

2023-04-01 Thread via cfe-commits

Author: sstwcw
Date: 2023-04-01T17:09:44Z
New Revision: 92b2be39656b9d5c6b57b844884f3bcf3e44f6cd

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

LOG: [clang-format] Handle enum in Verilog

Verilog has enum just like C.

Reviewed By: HazardyKnusperkeks, owenpan, MyDeveloperDay

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

Added: 


Modified: 
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/FormatTestVerilog.cpp

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index fdf5d85d6b1d..e47d6342357c 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -1709,8 +1709,8 @@ void UnwrappedLineParser::parseStructuralElement(
   // enum definition can start a structural element.
   if (!parseEnum())
 break;
-  // This only applies for C++.
-  if (!Style.isCpp()) {
+  // This only applies to C++ and Verilog.
+  if (!Style.isCpp() && !Style.isVerilog()) {
 addUnwrappedLine();
 return;
   }
@@ -3541,7 +3541,15 @@ bool UnwrappedLineParser::parseEnum() {
  FormatTok->isOneOf(tok::colon, tok::coloncolon, tok::less,
 tok::greater, tok::comma, tok::question,
 tok::l_square, tok::r_square)) {
-nextToken();
+if (Style.isVerilog()) {
+  FormatTok->setFinalizedType(TT_VerilogDimensionedTypeName);
+  nextToken();
+  // In Verilog the base type can have dimensions.
+  while (FormatTok->is(tok::l_square))
+parseSquare();
+} else {
+  nextToken();
+}
 // We can have macros or attributes in between 'enum' and the enum name.
 if (FormatTok->is(tok::l_paren))
   parseParens();

diff  --git a/clang/unittests/Format/FormatTestVerilog.cpp 
b/clang/unittests/Format/FormatTestVerilog.cpp
index 88ce08207c95..3243d3343dca 100644
--- a/clang/unittests/Format/FormatTestVerilog.cpp
+++ b/clang/unittests/Format/FormatTestVerilog.cpp
@@ -338,6 +338,20 @@ TEST_F(FormatTestVerilog, Delay) {
 "x = x;");
 }
 
+TEST_F(FormatTestVerilog, Enum) {
+  verifyFormat("enum { x } x;");
+  verifyFormat("typedef enum { x } x;");
+  verifyFormat("enum { red, yellow, green } x;");
+  verifyFormat("typedef enum { red, yellow, green } x;");
+  verifyFormat("enum integer { x } x;");
+  verifyFormat("typedef enum { x = 0 } x;");
+  verifyFormat("typedef enum { red = 0, yellow = 1, green = 2 } x;");
+  verifyFormat("typedef enum integer { x } x;");
+  verifyFormat("typedef enum bit [0 : 1] { x } x;");
+  verifyFormat("typedef enum { add = 10, sub[5], jmp[6 : 8] } E1;");
+  verifyFormat("typedef enum { add = 10, sub[5] = 0, jmp[6 : 8] = 1 } E1;");
+}
+
 TEST_F(FormatTestVerilog, Headers) {
   // Test headers with multiple ports.
   verifyFormat("module mh1\n"



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


[clang] feb585e - [clang-format] Handle Verilog struct literals

2023-04-01 Thread via cfe-commits

Author: sstwcw
Date: 2023-04-01T17:10:31Z
New Revision: feb585e7d62ce92fcd8334abde4a84ee0301dcd3

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

LOG: [clang-format] Handle Verilog struct literals

Previously `isVerilogIdentifier` was mistaking the apostrophe used in
struct literals as an identifier.  It is fixed.

Reviewed By: HazardyKnusperkeks, owenpan

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

Added: 


Modified: 
clang/lib/Format/Format.cpp
clang/lib/Format/FormatToken.h
clang/unittests/Format/FormatTestVerilog.cpp

Removed: 




diff  --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 618cdb68f7c4..97c4867fcb44 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1489,6 +1489,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind 
Language) {
 break;
   case FormatStyle::LK_Verilog:
 LLVMStyle.IndentCaseLabels = true;
+LLVMStyle.SpacesInContainerLiterals = false;
 break;
   default:
 break;

diff  --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 5cd3422aed5b..59d4a871f7ec 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -1722,8 +1722,9 @@ struct AdditionalKeywords {
 case tok::kw_while:
   return false;
 case tok::identifier:
-  return VerilogExtraKeywords.find(Tok.Tok.getIdentifierInfo()) ==
- VerilogExtraKeywords.end();
+  return isWordLike(Tok) &&
+ VerilogExtraKeywords.find(Tok.Tok.getIdentifierInfo()) ==
+ VerilogExtraKeywords.end();
 default:
   // getIdentifierInfo returns non-null for both identifiers and keywords.
   return Tok.Tok.getIdentifierInfo();

diff  --git a/clang/unittests/Format/FormatTestVerilog.cpp 
b/clang/unittests/Format/FormatTestVerilog.cpp
index 3243d3343dca..9d3ccf9f1da0 100644
--- a/clang/unittests/Format/FormatTestVerilog.cpp
+++ b/clang/unittests/Format/FormatTestVerilog.cpp
@@ -916,6 +916,25 @@ TEST_F(FormatTestVerilog, Streaming) {
   verifyFormat("{

[PATCH] D147328: [clang-format] Handle enum in Verilog

2023-04-01 Thread sstwcw 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 rG92b2be39656b: [clang-format] Handle enum in Verilog 
(authored by sstwcw).

Changed prior to commit:
  https://reviews.llvm.org/D147328?vs=510031&id=510248#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147328

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTestVerilog.cpp


Index: clang/unittests/Format/FormatTestVerilog.cpp
===
--- clang/unittests/Format/FormatTestVerilog.cpp
+++ clang/unittests/Format/FormatTestVerilog.cpp
@@ -338,6 +338,20 @@
 "x = x;");
 }
 
+TEST_F(FormatTestVerilog, Enum) {
+  verifyFormat("enum { x } x;");
+  verifyFormat("typedef enum { x } x;");
+  verifyFormat("enum { red, yellow, green } x;");
+  verifyFormat("typedef enum { red, yellow, green } x;");
+  verifyFormat("enum integer { x } x;");
+  verifyFormat("typedef enum { x = 0 } x;");
+  verifyFormat("typedef enum { red = 0, yellow = 1, green = 2 } x;");
+  verifyFormat("typedef enum integer { x } x;");
+  verifyFormat("typedef enum bit [0 : 1] { x } x;");
+  verifyFormat("typedef enum { add = 10, sub[5], jmp[6 : 8] } E1;");
+  verifyFormat("typedef enum { add = 10, sub[5] = 0, jmp[6 : 8] = 1 } E1;");
+}
+
 TEST_F(FormatTestVerilog, Headers) {
   // Test headers with multiple ports.
   verifyFormat("module mh1\n"
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1709,8 +1709,8 @@
   // enum definition can start a structural element.
   if (!parseEnum())
 break;
-  // This only applies for C++.
-  if (!Style.isCpp()) {
+  // This only applies to C++ and Verilog.
+  if (!Style.isCpp() && !Style.isVerilog()) {
 addUnwrappedLine();
 return;
   }
@@ -3541,7 +3541,15 @@
  FormatTok->isOneOf(tok::colon, tok::coloncolon, tok::less,
 tok::greater, tok::comma, tok::question,
 tok::l_square, tok::r_square)) {
-nextToken();
+if (Style.isVerilog()) {
+  FormatTok->setFinalizedType(TT_VerilogDimensionedTypeName);
+  nextToken();
+  // In Verilog the base type can have dimensions.
+  while (FormatTok->is(tok::l_square))
+parseSquare();
+} else {
+  nextToken();
+}
 // We can have macros or attributes in between 'enum' and the enum name.
 if (FormatTok->is(tok::l_paren))
   parseParens();


Index: clang/unittests/Format/FormatTestVerilog.cpp
===
--- clang/unittests/Format/FormatTestVerilog.cpp
+++ clang/unittests/Format/FormatTestVerilog.cpp
@@ -338,6 +338,20 @@
 "x = x;");
 }
 
+TEST_F(FormatTestVerilog, Enum) {
+  verifyFormat("enum { x } x;");
+  verifyFormat("typedef enum { x } x;");
+  verifyFormat("enum { red, yellow, green } x;");
+  verifyFormat("typedef enum { red, yellow, green } x;");
+  verifyFormat("enum integer { x } x;");
+  verifyFormat("typedef enum { x = 0 } x;");
+  verifyFormat("typedef enum { red = 0, yellow = 1, green = 2 } x;");
+  verifyFormat("typedef enum integer { x } x;");
+  verifyFormat("typedef enum bit [0 : 1] { x } x;");
+  verifyFormat("typedef enum { add = 10, sub[5], jmp[6 : 8] } E1;");
+  verifyFormat("typedef enum { add = 10, sub[5] = 0, jmp[6 : 8] = 1 } E1;");
+}
+
 TEST_F(FormatTestVerilog, Headers) {
   // Test headers with multiple ports.
   verifyFormat("module mh1\n"
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1709,8 +1709,8 @@
   // enum definition can start a structural element.
   if (!parseEnum())
 break;
-  // This only applies for C++.
-  if (!Style.isCpp()) {
+  // This only applies to C++ and Verilog.
+  if (!Style.isCpp() && !Style.isVerilog()) {
 addUnwrappedLine();
 return;
   }
@@ -3541,7 +3541,15 @@
  FormatTok->isOneOf(tok::colon, tok::coloncolon, tok::less,
 tok::greater, tok::comma, tok::question,
 tok::l_square, tok::r_square)) {
-nextToken();
+if (Style.isVerilog()) {
+  FormatTok->setFinalizedType(TT_VerilogDimensionedTypeName);
+  nextToken();
+  // In Verilog the base type can have dimensions.
+  while (FormatTok->is(tok::l_square))
+parseSquare();
+} else {
+  nextToken();
+}
 // We can have macros or attributes in between 'enum' and the enum name.
 if (FormatTok->is(tok::l_

[PATCH] D147329: [clang-format] Handle Verilog struct literals

2023-04-01 Thread sstwcw 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 rGfeb585e7d62c: [clang-format] Handle Verilog struct literals 
(authored by sstwcw).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147329

Files:
  clang/lib/Format/Format.cpp
  clang/lib/Format/FormatToken.h
  clang/unittests/Format/FormatTestVerilog.cpp


Index: clang/unittests/Format/FormatTestVerilog.cpp
===
--- clang/unittests/Format/FormatTestVerilog.cpp
+++ clang/unittests/Format/FormatTestVerilog.cpp
@@ -916,6 +916,25 @@
   verifyFormat("{

[PATCH] D147379: [clang-tidy] Disable misc-definitions-in-headers for declarations in anonymous namespaces

2023-04-01 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL accepted this revision.
PiotrZSL added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147379

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


[PATCH] D147315: [clang-tidy] support unscoped enumerations in readability-static-accessed-through-instance

2023-04-01 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added a comment.

Well, description update didn't update, you can update it here in UI, just edit 
revision, if you use "arc", there is a switch to apply description update.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147315

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


[PATCH] D147315: [clang-tidy] support unscoped enumerations in readability-static-accessed-through-instance

2023-04-01 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

Would it make sense to add a scoped enum to the test, to ensure it doesn't 
warn/fix?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147315

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


[PATCH] D140722: [OpenMP] Prefix outlined and reduction func names with original func's name

2023-04-01 Thread Itay Bookstein via Phabricator via cfe-commits
nextsilicon-itay-bookstein added a comment.

I don't have non-cumbersome access to GPU targets at the moment.
I have run the following locally with the patch, and it seems to pass:

  > ninja check-libomptarget
  [0/1] Running libomptarget tests
  
  Testing Time: 9.69s
Unsupported:  57
Passed : 205


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

https://reviews.llvm.org/D140722

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


[PATCH] D147383: [clang-tidy] Allow bugprone-unchecked-optional-access to handle calls to `std::forward`

2023-04-01 Thread André Schackier via Phabricator via cfe-commits
AMS21 created this revision.
AMS21 added reviewers: PiotrZSL, njames93, carlosgalvezp.
Herald added a subscriber: xazax.hun.
Herald added a reviewer: NoQ.
Herald added a project: All.
AMS21 requested review of this revision.
Herald added projects: clang, clang-tools-extra.
Herald added a subscriber: cfe-commits.

The check now understands that calling `std::forward`
will not modify the underlying optional value.

This fixes llvm#59705


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147383

Files:
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/bugprone/unchecked-optional-access.cpp
  clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp

Index: clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
===
--- clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
+++ clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
@@ -96,7 +96,6 @@
   recordType(hasDeclaration(anyOf(nulloptTypeDecl(), optionalClass());
 }
 
-
 auto inPlaceClass() {
   return recordDecl(
   hasAnyName("std::in_place_t", "absl::in_place_t", "base::in_place_t"));
@@ -149,6 +148,11 @@
   hasArgument(1, hasOptionalType()));
 }
 
+auto isStdForwardCall() {
+  return callExpr(callee(functionDecl(hasName("std::forward"))),
+  argumentCountIs(1), hasArgument(0, hasOptionalType()));
+}
+
 constexpr llvm::StringLiteral ValueOrCallID = "ValueOrCall";
 
 auto isValueOrStringEmptyCall() {
@@ -571,6 +575,32 @@
   transferSwap(*E->getArg(0), SkipPast::Reference, *E->getArg(1), State.Env);
 }
 
+void transferStdForwardCall(const CallExpr *E, const MatchFinder::MatchResult &,
+LatticeTransferState &State) {
+  assert(E->getNumArgs() == 1);
+
+  StorageLocation *LocRet = State.Env.getStorageLocation(*E, SkipPast::None);
+  if (LocRet != nullptr)
+return;
+
+  StorageLocation *LocArg =
+  State.Env.getStorageLocation(*E->getArg(0), SkipPast::Reference);
+
+  if (LocArg == nullptr) {
+return;
+  }
+
+  Value *ValArg = State.Env.getValue(*LocArg);
+  if (ValArg == nullptr)
+ValArg = &createOptionalValue(State.Env, State.Env.makeAtomicBoolValue());
+
+  // Create a new storage location
+  LocRet = &State.Env.createStorageLocation(*E);
+  State.Env.setStorageLocation(*E, *LocRet);
+
+  State.Env.setValue(*LocRet, *ValArg);
+}
+
 BoolValue &evaluateEquality(Environment &Env, BoolValue &EqVal, BoolValue &LHS,
 BoolValue &RHS) {
   // Logically, an optional object is composed of two values - a `has_value`
@@ -686,7 +716,6 @@
   .CaseOfCFGStmt(isOptionalValueOrConversionConstructor(),
transferValueOrConversionConstructor)
 
-
   // optional::operator=
   .CaseOfCFGStmt(
   isOptionalValueOrConversionAssignment(),
@@ -745,6 +774,9 @@
   // std::swap
   .CaseOfCFGStmt(isStdSwapCall(), transferStdSwapCall)
 
+  // std::forward
+  .CaseOfCFGStmt(isStdForwardCall(), transferStdForwardCall)
+
   // opt.value_or("").empty()
   .CaseOfCFGStmt(isValueOrStringEmptyCall(),
transferValueOrStringEmptyCall)
@@ -845,10 +877,12 @@
 return ComparisonResult::Unknown;
   bool MustNonEmpty1 = isNonEmptyOptional(Val1, Env1);
   bool MustNonEmpty2 = isNonEmptyOptional(Val2, Env2);
-  if (MustNonEmpty1 && MustNonEmpty2) return ComparisonResult::Same;
+  if (MustNonEmpty1 && MustNonEmpty2)
+return ComparisonResult::Same;
   // If exactly one is true, then they're different, no reason to check whether
   // they're definitely empty.
-  if (MustNonEmpty1 || MustNonEmpty2) return ComparisonResult::Different;
+  if (MustNonEmpty1 || MustNonEmpty2)
+return ComparisonResult::Different;
   // Check if they're both definitely empty.
   return (isEmptyOptional(Val1, Env1) && isEmptyOptional(Val2, Env2))
  ? ComparisonResult::Same
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/unchecked-optional-access.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/unchecked-optional-access.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/unchecked-optional-access.cpp
@@ -110,3 +110,50 @@
   }
   int foo_;
 };
+
+// llvm#59705
+namespace std
+{
+  template 
+  constexpr T&& forward(T& type) noexcept {
+return static_cast(type);
+  }
+
+  template 
+  constexpr T&& forward(T&& type) noexcept {
+return static_cast(type);
+  }
+}
+
+void std_forward_copy(absl::optional opt) {
+  std::forward>(opt).value();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: unchecked access to optional
+}
+
+void std_forward_copy_safe(absl::optional opt) {
+  if (!opt) return;
+
+  std::forward>(opt).value();
+}
+
+void std_forward_copy(absl::optional& opt) {
+  std::forward>(opt).value()

[clang-tools-extra] 2469bd9 - [clang-tidy] Disable misc-definitions-in-headers for declarations in anonymous namespaces

2023-04-01 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2023-04-01T19:19:00Z
New Revision: 2469bd98a77242606426f8a5a8a797054c932bf0

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

LOG: [clang-tidy] Disable misc-definitions-in-headers for declarations in 
anonymous namespaces

Anonymous namespaces are another way of providing internal linkage,
and the check already ignores other cases of internal linkage in
headers, via "static" or "const".

Anonymous namespaces in headers are definitely a source of pitfalls,
but it's not the responsibility of this check to cover that. Instead,
google-build-namespaces will specifically warn about this issue.

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

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/misc/definitions-in-headers.rst
clang-tools-extra/test/clang-tidy/checkers/misc/definitions-in-headers.hpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
index 67e1a04a35afe..2c07b30429f96 100644
--- a/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
@@ -90,13 +90,11 @@ void DefinitionsInHeadersCheck::check(const 
MatchFinder::MatchResult &Result) {
   // Internal linkage variable definitions are ignored for now:
   //   const int a = 1;
   //   static int b = 1;
+  //   namespace { int c = 1; }
   //
   // Although these might also cause ODR violations, we can be less certain and
   // should try to keep the false-positive rate down.
-  //
-  // FIXME: Should declarations in anonymous namespaces get the same treatment
-  // as static / const declarations?
-  if (!ND->hasExternalFormalLinkage() && !ND->isInAnonymousNamespace())
+  if (!ND->hasExternalFormalLinkage() || ND->isInAnonymousNamespace())
 return;
 
   if (const auto *FD = dyn_cast(ND)) {

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 156e9d73c7be0..099211e592547 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -199,6 +199,10 @@ Changes in existing checks
   ` check.
   Global options of the same name should be used instead.
 
+- Fixed false positive in :doc:`misc-definitions-in-headers
+  ` to avoid warning on
+  declarations inside anonymous namespaces.
+
 - Deprecated check-local options `HeaderFileExtensions`
   in :doc:`misc-unused-using-decls
   ` check.

diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/misc/definitions-in-headers.rst 
b/clang-tools-extra/docs/clang-tidy/checks/misc/definitions-in-headers.rst
index dcded6a42a6d9..08aa9d884c239 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/misc/definitions-in-headers.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/misc/definitions-in-headers.rst
@@ -27,6 +27,7 @@ from multiple translation units.
const int c = 1;
const char* const str2 = "foo";
constexpr int k = 1;
+   namespace { int x = 1; }
 
// Warning: function definition.
int g() {

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc/definitions-in-headers.hpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc/definitions-in-headers.hpp
index f57cc2c256fef..4cf07077a230a 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc/definitions-in-headers.hpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/definitions-in-headers.hpp
@@ -108,8 +108,7 @@ int f3() {
 int f5(); // OK: function declaration.
 inline int f6() { return 1; } // OK: inline function definition.
 namespace {
-  int f7() { return 1; }
-// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: function 'f7' defined in a header 
file;
+  int f7() { return 1; }  // OK: each TU defines the function in a unique 
namespace.
 }
 
 int f8() = delete; // OK: the function being marked delete is not callable.
@@ -142,8 +141,7 @@ const char* ca = "foo";
 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: variable 'ca' defined in a header 
file;
 
 namespace {
-  int e = 2;
-// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: variable 'e' defined in a header 
file;
+  int e = 2;  // OK: each TU defines the variable in a unique namespace.
 }
 
 const char* const g = "foo"; // OK: internal linkage variable definition.



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


[PATCH] D147379: [clang-tidy] Disable misc-definitions-in-headers for declarations in anonymous namespaces

2023-04-01 Thread Carlos Galvez via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2469bd98a772: [clang-tidy] Disable 
misc-definitions-in-headers for declarations in anonymous… (authored by 
carlosgalvezp).

Changed prior to commit:
  https://reviews.llvm.org/D147379?vs=510233&id=510257#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147379

Files:
  clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/definitions-in-headers.rst
  clang-tools-extra/test/clang-tidy/checkers/misc/definitions-in-headers.hpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/misc/definitions-in-headers.hpp
===
--- clang-tools-extra/test/clang-tidy/checkers/misc/definitions-in-headers.hpp
+++ clang-tools-extra/test/clang-tidy/checkers/misc/definitions-in-headers.hpp
@@ -108,8 +108,7 @@
 int f5(); // OK: function declaration.
 inline int f6() { return 1; } // OK: inline function definition.
 namespace {
-  int f7() { return 1; }
-// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: function 'f7' defined in a header 
file;
+  int f7() { return 1; }  // OK: each TU defines the function in a unique 
namespace.
 }
 
 int f8() = delete; // OK: the function being marked delete is not callable.
@@ -142,8 +141,7 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: variable 'ca' defined in a header 
file;
 
 namespace {
-  int e = 2;
-// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: variable 'e' defined in a header 
file;
+  int e = 2;  // OK: each TU defines the variable in a unique namespace.
 }
 
 const char* const g = "foo"; // OK: internal linkage variable definition.
Index: clang-tools-extra/docs/clang-tidy/checks/misc/definitions-in-headers.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/misc/definitions-in-headers.rst
+++ clang-tools-extra/docs/clang-tidy/checks/misc/definitions-in-headers.rst
@@ -27,6 +27,7 @@
const int c = 1;
const char* const str2 = "foo";
constexpr int k = 1;
+   namespace { int x = 1; }
 
// Warning: function definition.
int g() {
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -199,6 +199,10 @@
   ` check.
   Global options of the same name should be used instead.
 
+- Fixed false positive in :doc:`misc-definitions-in-headers
+  ` to avoid warning on
+  declarations inside anonymous namespaces.
+
 - Deprecated check-local options `HeaderFileExtensions`
   in :doc:`misc-unused-using-decls
   ` check.
Index: clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
===
--- clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
+++ clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
@@ -90,13 +90,11 @@
   // Internal linkage variable definitions are ignored for now:
   //   const int a = 1;
   //   static int b = 1;
+  //   namespace { int c = 1; }
   //
   // Although these might also cause ODR violations, we can be less certain and
   // should try to keep the false-positive rate down.
-  //
-  // FIXME: Should declarations in anonymous namespaces get the same treatment
-  // as static / const declarations?
-  if (!ND->hasExternalFormalLinkage() && !ND->isInAnonymousNamespace())
+  if (!ND->hasExternalFormalLinkage() || ND->isInAnonymousNamespace())
 return;
 
   if (const auto *FD = dyn_cast(ND)) {


Index: clang-tools-extra/test/clang-tidy/checkers/misc/definitions-in-headers.hpp
===
--- clang-tools-extra/test/clang-tidy/checkers/misc/definitions-in-headers.hpp
+++ clang-tools-extra/test/clang-tidy/checkers/misc/definitions-in-headers.hpp
@@ -108,8 +108,7 @@
 int f5(); // OK: function declaration.
 inline int f6() { return 1; } // OK: inline function definition.
 namespace {
-  int f7() { return 1; }
-// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: function 'f7' defined in a header file;
+  int f7() { return 1; }  // OK: each TU defines the function in a unique namespace.
 }
 
 int f8() = delete; // OK: the function being marked delete is not callable.
@@ -142,8 +141,7 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: variable 'ca' defined in a header file;
 
 namespace {
-  int e = 2;
-// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: variable 'e' defined in a header file;
+  int e = 2;  // OK: each TU defines the variable in a unique namespace.
 }
 
 const char* const g = "foo"; // OK: internal linkage variable definition.
Index: clang-tools-extra/docs/clang-tidy/checks/misc/definitions-in-headers.rst
===
--- 

[PATCH] D145138: [clang-tidy] Implement FixIts for C arrays

2023-04-01 Thread Chris Cotter via Phabricator via cfe-commits
ccotter updated this revision to Diff 510262.
ccotter added a comment.

- Fix double curly brace matching in tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145138

Files:
  clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.cpp
  clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.h
  clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.h
  clang-tools-extra/clang-tidy/utils/CMakeLists.txt
  clang-tools-extra/clang-tidy/utils/LexerUtils.cpp
  clang-tools-extra/clang-tidy/utils/TypeUtils.cpp
  clang-tools-extra/clang-tidy/utils/TypeUtils.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/modernize/avoid-c-arrays.rst
  clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-c-arrays-cxx17.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-c-arrays.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-c-arrays.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-c-arrays.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-c-arrays.cpp
@@ -1,4 +1,6 @@
-// RUN: %check_clang_tidy %s modernize-avoid-c-arrays %t
+// RUN: %check_clang_tidy -std=c++11 %s modernize-avoid-c-arrays %t
+
+//CHECK-FIXES: #include 
 
 int a[] = {1, 2};
 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: do not declare C-style arrays, use std::array<> instead
@@ -86,3 +88,262 @@
   int j[1];
 };
 }
+
+template  struct TStruct {};
+
+void replacements() {
+  int ar[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array ar;
+  TStruct ar2[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array, 10> ar2;
+  TStruct< int > ar3[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array, 10> ar3;
+  int * ar4[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array ar4;
+  int * /*comment*/ar5[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array /*comment*/ar5;
+  volatile const int * ar6[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array ar6;
+  volatile int ar7[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: volatile std::array ar7;
+  int const * ar8[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array ar8;
+  int ar9[1];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array ar9;
+  static int volatile constexpr ar10[10] = {};
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: static volatile constexpr std::array ar10 = {{[{][{]}}{{[}][}]}};
+  thread_local int ar11[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: thread_local std::array ar11;
+  thread_local/*a*/int/*b*/ar12[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: thread_local/*a*/std::array/*b*/ar12;
+  /*a*/ int/*b*/ /*c*/*/*d*/ /*e*/ /*f*/ar13[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: /*a*/ std::array/*d*/ /*e*/ /*f*/ar13;
+  TStruct ar14[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array, 10> ar14;
+  volatile TStruct ar15[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: volatile std::array, 10> ar15;
+  TStruct ar16[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array, 10> ar16;
+  TStruct ar17[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array, 10> ar17;
+  volatile int static thread_local * ar18[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: static thread_local std::array ar18;
+
+  // Note, there is a tab '\t' before the semicolon in the declaration below.
+  int ar19[3]	;
+  // CHECK-

[PATCH] D145138: [clang-tidy] Implement FixIts for C arrays

2023-04-01 Thread Chris Cotter via Phabricator via cfe-commits
ccotter updated this revision to Diff 510267.
ccotter added a comment.

- Add tests for char[]


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145138

Files:
  clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.cpp
  clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.h
  clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.h
  clang-tools-extra/clang-tidy/utils/CMakeLists.txt
  clang-tools-extra/clang-tidy/utils/LexerUtils.cpp
  clang-tools-extra/clang-tidy/utils/TypeUtils.cpp
  clang-tools-extra/clang-tidy/utils/TypeUtils.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/modernize/avoid-c-arrays.rst
  clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-c-arrays-cxx17.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-c-arrays.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-c-arrays.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-c-arrays.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-c-arrays.cpp
@@ -1,4 +1,6 @@
-// RUN: %check_clang_tidy %s modernize-avoid-c-arrays %t
+// RUN: %check_clang_tidy -std=c++11 %s modernize-avoid-c-arrays %t
+
+//CHECK-FIXES: #include 
 
 int a[] = {1, 2};
 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: do not declare C-style arrays, use std::array<> instead
@@ -86,3 +88,280 @@
   int j[1];
 };
 }
+
+template  struct TStruct {};
+
+void replacements() {
+  int ar[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array ar;
+  TStruct ar2[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array, 10> ar2;
+  TStruct< int > ar3[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array, 10> ar3;
+  int * ar4[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array ar4;
+  int * /*comment*/ar5[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array /*comment*/ar5;
+  volatile const int * ar6[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array ar6;
+  volatile int ar7[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: volatile std::array ar7;
+  int const * ar8[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array ar8;
+  int ar9[1];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array ar9;
+  static int volatile constexpr ar10[10] = {};
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: static volatile constexpr std::array ar10 = {{[{][{]}}{{[}][}]}};
+  thread_local int ar11[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: thread_local std::array ar11;
+  thread_local/*a*/int/*b*/ar12[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: thread_local/*a*/std::array/*b*/ar12;
+  /*a*/ int/*b*/ /*c*/*/*d*/ /*e*/ /*f*/ar13[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: /*a*/ std::array/*d*/ /*e*/ /*f*/ar13;
+  TStruct ar14[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array, 10> ar14;
+  volatile TStruct ar15[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: volatile std::array, 10> ar15;
+  TStruct ar16[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array, 10> ar16;
+  TStruct ar17[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array, 10> ar17;
+  volatile int static thread_local * ar18[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: static thread_local std::array ar18;
+
+  // Note, there is a tab '\t' before the semicolon in the declaration below.
+  int ar19[3]	;
+  // CHECK-MESSAGES: :[[@LINE-1

[PATCH] D145138: [clang-tidy] Implement FixIts for C arrays

2023-04-01 Thread Chris Cotter via Phabricator via cfe-commits
ccotter marked an inline comment as done.
ccotter added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-c-arrays.cpp:170-172
+  char init4[] = "abcdef";
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, 
use std::array<> instead
+  // CHECK-FIXES: std::array init4 = { "abcdef" };

PiotrZSL wrote:
> I don't think this check should replace those strings, simply that could 
> break code, image someone is using this later as an argument to some function 
> that expect pointer.
> For strings std::string_view would be better alternative (at least add a 
> bypass for this).
> And all those changes are not safe if variable is used for pointer arithmetic.
> 
> 
The logic I implemented should fix pointer arithmetic (e.g., `str + 1` is 
replaced by `str.begin() + 1`. I have tests for this for `int[]`, but added 
more for `char[]`. string_view is not appropriate conversion here since the 
arrays may be modified etc.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145138

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


[PATCH] D145138: [clang-tidy] Implement FixIts for C arrays

2023-04-01 Thread Chris Cotter via Phabricator via cfe-commits
ccotter updated this revision to Diff 510270.
ccotter added a comment.

- format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145138

Files:
  clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.cpp
  clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.h
  clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.h
  clang-tools-extra/clang-tidy/utils/CMakeLists.txt
  clang-tools-extra/clang-tidy/utils/LexerUtils.cpp
  clang-tools-extra/clang-tidy/utils/TypeUtils.cpp
  clang-tools-extra/clang-tidy/utils/TypeUtils.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/modernize/avoid-c-arrays.rst
  clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-c-arrays-cxx17.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-c-arrays.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-c-arrays.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-c-arrays.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-c-arrays.cpp
@@ -1,4 +1,6 @@
-// RUN: %check_clang_tidy %s modernize-avoid-c-arrays %t
+// RUN: %check_clang_tidy -std=c++11 %s modernize-avoid-c-arrays %t
+
+//CHECK-FIXES: #include 
 
 int a[] = {1, 2};
 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: do not declare C-style arrays, use std::array<> instead
@@ -86,3 +88,280 @@
   int j[1];
 };
 }
+
+template  struct TStruct {};
+
+void replacements() {
+  int ar[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array ar;
+  TStruct ar2[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array, 10> ar2;
+  TStruct< int > ar3[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array, 10> ar3;
+  int * ar4[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array ar4;
+  int * /*comment*/ar5[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array /*comment*/ar5;
+  volatile const int * ar6[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array ar6;
+  volatile int ar7[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: volatile std::array ar7;
+  int const * ar8[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array ar8;
+  int ar9[1];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array ar9;
+  static int volatile constexpr ar10[10] = {};
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: static volatile constexpr std::array ar10 = {{[{][{]}}{{[}][}]}};
+  thread_local int ar11[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: thread_local std::array ar11;
+  thread_local/*a*/int/*b*/ar12[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: thread_local/*a*/std::array/*b*/ar12;
+  /*a*/ int/*b*/ /*c*/*/*d*/ /*e*/ /*f*/ar13[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: /*a*/ std::array/*d*/ /*e*/ /*f*/ar13;
+  TStruct ar14[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array, 10> ar14;
+  volatile TStruct ar15[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: volatile std::array, 10> ar15;
+  TStruct ar16[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array, 10> ar16;
+  TStruct ar17[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array, 10> ar17;
+  volatile int static thread_local * ar18[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: static thread_local std::array ar18;
+
+  // Note, there is a tab '\t' before the semicolon in the declaration below.
+  int ar19[3]	;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning:

[PATCH] D145138: [clang-tidy] Implement FixIts for C arrays

2023-04-01 Thread Chris Cotter via Phabricator via cfe-commits
ccotter marked 5 inline comments as done.
ccotter added inline comments.



Comment at: clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.cpp:496
+  const Expr *SpelledExpr = E->IgnoreUnlessSpelledInSource();
+  if (dyn_cast(SpelledExpr))
+return false;

PiotrZSL wrote:
> InitListExpr::classof(SpelledExpr)
Why `classof` vs `dyn_cast`? The codebase seems to overwhelmingly use 
`dyn_cst`, and I need to use the downcast type anyway..



Comment at: clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.cpp:531
+return {};
+  // TODO: How can I get FileCheck to accept '{{}}' as a non-regex match?
+  FixIts.push_back(FixItHint::CreateInsertion(InitRange.getBegin(), "{ "));

PiotrZSL wrote:
> https://www.llvm.org/docs/CommandGuide/FileCheck.html
> "In the rare case that you want to match double braces explicitly from the 
> input, you can use something ugly like {{[}][}]}} as your pattern."
Thanks..fixed!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145138

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


[clang] 1d4d21e - [Clang][AST] Fix __has_unique_object_representations computation for unnamed bitfields.

2023-04-01 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2023-04-02T00:54:45+03:00
New Revision: 1d4d21e2e0950f6c451198e380371ee3142ce2fb

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

LOG: [Clang][AST] Fix __has_unique_object_representations computation for 
unnamed bitfields.

As pointed out in https://github.com/llvm/llvm-project/issues/61336, objects 
with
unnamed bitfields aren't be uniquely representable.

Reviewed By: shafik, Endill

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/AST/ASTContext.cpp
clang/test/SemaCXX/type-traits.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4640ecccb9ad4..cd9aae998a503 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -291,6 +291,9 @@ Bug Fixes to C++ Support
   template parameters with 
diff erent nested constraints.
 - Fix type equivalence comparison between auto types to take constraints into
   account.
+- Fix bug in the computation of the ``__has_unique_object_representations``
+  builtin for types with unnamed bitfields.
+  (`#61336 `_)
 
 Bug Fixes to AST Handling
 ^

diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 612fcd4897c8f..bd4f2ff024949 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -2716,6 +2716,11 @@ getSubobjectSizeInBits(const FieldDecl *Field, const 
ASTContext &Context) {
   int64_t FieldSizeInBits =
   Context.toBits(Context.getTypeSizeInChars(Field->getType()));
   if (Field->isBitField()) {
+// If we have explicit padding bits, they don't contribute bits
+// to the actual object representation, so return 0.
+if (Field->isUnnamedBitfield())
+  return 0;
+
 int64_t BitfieldSize = Field->getBitWidthValue(Context);
 if (IsBitIntType) {
   if ((unsigned)BitfieldSize >

diff  --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index 7d425acb56813..e3fc65713cedf 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -2828,6 +2828,17 @@ 
static_assert(!has_unique_object_representations::value, "Alignm
 static_assert(!has_unique_object_representations::value, 
"Alignment causes padding");
 static_assert(!has_unique_object_representations::value, 
"Also no arrays that have padding");
 
+struct __attribute__((packed)) PackedNoPadding1 {
+  short i;
+  int j;
+};
+struct __attribute__((packed)) PackedNoPadding2 {
+  int j;
+  short i;
+};
+static_assert(has_unique_object_representations::value, 
"Packed structs have no padding");
+static_assert(has_unique_object_representations::value, 
"Packed structs have no padding");
+
 static_assert(!has_unique_object_representations::value, "Functions 
are not unique");
 static_assert(!has_unique_object_representations::value, 
"Functions are not unique");
 static_assert(!has_unique_object_representations::value, 
"Functions are not unique");
@@ -2878,9 +2889,35 @@ struct AlignedPaddedBitfield {
   char d : 2;
 };
 
+struct UnnamedBitfield {
+  int named : 8;
+  int : 24;
+};
+
+struct __attribute__((packed)) UnnamedBitfieldPacked {
+  int named : 8;
+  int : 24;
+};
+
+struct UnnamedEmptyBitfield {
+  int named;
+  int : 0;
+};
+
+struct UnnamedEmptyBitfieldSplit {
+  short named;
+  int : 0;
+  short also_named;
+};
+
 static_assert(!has_unique_object_representations::value, 
"Bitfield padding");
 static_assert(has_unique_object_representations::value, 
"Bitfield padding");
 
static_assert(!has_unique_object_representations::value, 
"Bitfield padding");
+static_assert(!has_unique_object_representations::value, 
"Bitfield padding");
+static_assert(!has_unique_object_representations::value,
 "Bitfield padding");
+static_assert(has_unique_object_representations::value, 
"Bitfield padding");
+static_assert(sizeof(UnnamedEmptyBitfieldSplit) != (sizeof(short) * 2), "Wrong 
size");
+static_assert(!has_unique_object_representations::value,
 "Bitfield padding");
 
 struct BoolBitfield {
   bool b : 8;



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


[PATCH] D145852: [Clang][AST] Fix __has_unique_object_representations computation for unnamed bitfields.

2023-04-01 Thread Roy Jacobson 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 rG1d4d21e2e095: [Clang][AST] Fix 
__has_unique_object_representations computation for unnamed… (authored by 
royjacobson).

Changed prior to commit:
  https://reviews.llvm.org/D145852?vs=509298&id=510273#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145852

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/ASTContext.cpp
  clang/test/SemaCXX/type-traits.cpp


Index: clang/test/SemaCXX/type-traits.cpp
===
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -2828,6 +2828,17 @@
 static_assert(!has_unique_object_representations::value, 
"Alignment causes padding");
 static_assert(!has_unique_object_representations::value, 
"Also no arrays that have padding");
 
+struct __attribute__((packed)) PackedNoPadding1 {
+  short i;
+  int j;
+};
+struct __attribute__((packed)) PackedNoPadding2 {
+  int j;
+  short i;
+};
+static_assert(has_unique_object_representations::value, 
"Packed structs have no padding");
+static_assert(has_unique_object_representations::value, 
"Packed structs have no padding");
+
 static_assert(!has_unique_object_representations::value, "Functions 
are not unique");
 static_assert(!has_unique_object_representations::value, 
"Functions are not unique");
 static_assert(!has_unique_object_representations::value, 
"Functions are not unique");
@@ -2878,9 +2889,35 @@
   char d : 2;
 };
 
+struct UnnamedBitfield {
+  int named : 8;
+  int : 24;
+};
+
+struct __attribute__((packed)) UnnamedBitfieldPacked {
+  int named : 8;
+  int : 24;
+};
+
+struct UnnamedEmptyBitfield {
+  int named;
+  int : 0;
+};
+
+struct UnnamedEmptyBitfieldSplit {
+  short named;
+  int : 0;
+  short also_named;
+};
+
 static_assert(!has_unique_object_representations::value, 
"Bitfield padding");
 static_assert(has_unique_object_representations::value, 
"Bitfield padding");
 
static_assert(!has_unique_object_representations::value, 
"Bitfield padding");
+static_assert(!has_unique_object_representations::value, 
"Bitfield padding");
+static_assert(!has_unique_object_representations::value,
 "Bitfield padding");
+static_assert(has_unique_object_representations::value, 
"Bitfield padding");
+static_assert(sizeof(UnnamedEmptyBitfieldSplit) != (sizeof(short) * 2), "Wrong 
size");
+static_assert(!has_unique_object_representations::value,
 "Bitfield padding");
 
 struct BoolBitfield {
   bool b : 8;
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -2716,6 +2716,11 @@
   int64_t FieldSizeInBits =
   Context.toBits(Context.getTypeSizeInChars(Field->getType()));
   if (Field->isBitField()) {
+// If we have explicit padding bits, they don't contribute bits
+// to the actual object representation, so return 0.
+if (Field->isUnnamedBitfield())
+  return 0;
+
 int64_t BitfieldSize = Field->getBitWidthValue(Context);
 if (IsBitIntType) {
   if ((unsigned)BitfieldSize >
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -291,6 +291,9 @@
   template parameters with different nested constraints.
 - Fix type equivalence comparison between auto types to take constraints into
   account.
+- Fix bug in the computation of the ``__has_unique_object_representations``
+  builtin for types with unnamed bitfields.
+  (`#61336 `_)
 
 Bug Fixes to AST Handling
 ^


Index: clang/test/SemaCXX/type-traits.cpp
===
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -2828,6 +2828,17 @@
 static_assert(!has_unique_object_representations::value, "Alignment causes padding");
 static_assert(!has_unique_object_representations::value, "Also no arrays that have padding");
 
+struct __attribute__((packed)) PackedNoPadding1 {
+  short i;
+  int j;
+};
+struct __attribute__((packed)) PackedNoPadding2 {
+  int j;
+  short i;
+};
+static_assert(has_unique_object_representations::value, "Packed structs have no padding");
+static_assert(has_unique_object_representations::value, "Packed structs have no padding");
+
 static_assert(!has_unique_object_representations::value, "Functions are not unique");
 static_assert(!has_unique_object_representations::value, "Functions are not unique");
 static_assert(!has_unique_object_representations::value, "Functions are not unique");
@@ -2878,9 +2889,35 @@
   char d : 2;
 };
 
+struct UnnamedBitfield {
+  int named : 8;
+  int : 24;
+};
+
+struct __attribute__((packed)) Unname

[PATCH] D147327: [clang-format] Add option for having one port per line in Verilog

2023-04-01 Thread Owen Pan via Phabricator via cfe-commits
owenpan added inline comments.



Comment at: clang/lib/Format/TokenAnnotator.cpp:1149-1191
+  if (Style.isVerilog()) {
+const FormatToken *Prev = Tok->getPreviousNonComment();
+const FormatToken *PrevPrev;
+// Identify the parameter list and port list in a module instantiation.
+// This is still needed when we already have
+// UnwrappedLineParser::parseVerilogHierarchyHeader because that
+// function is only responsible for the definition, not the

Can you make it a function or lambda with early returns?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147327

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


[PATCH] D147315: [clang-tidy] support unscoped enumerations in readability-static-accessed-through-instance

2023-04-01 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 added a comment.

In D147315#4238596 , @carlosgalvezp 
wrote:

> Would it make sense to add a scoped enum to the test, to ensure it doesn't 
> warn/fix?

It is not possible to visit scoped enum by instance. I think adding an invalid 
expression to test it is meaningless.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147315

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


[PATCH] D146386: [MS ABI] Fix mangling references to declarations.

2023-04-01 Thread Andrey Ali Khan Bolshakov via Phabricator via cfe-commits
bolshakov-a updated this revision to Diff 510281.
bolshakov-a edited the summary of this revision.
bolshakov-a added a comment.

Mangling of anonymous unions. @eli.friedman, thank you!

> I don't know whether the aforementioned code is acceptable according to the 
> standard, honestly.

It is not acceptable because anonymous unions cannot contain nested types. In 
fact, they cannot contain even other anonymous unions, according to the C++ 
standard:
https://timsong-cpp.github.io/cppwp/n4868/class.union.anon#1
But clang and MSVC both accept such code, probably because recursively nested 
anonymous structs and unions are allowed in C17. Hence, this case is handled 
for generality, but I'm not sure if this behavior should be nailed down in a 
test.


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

https://reviews.llvm.org/D146386

Files:
  clang/lib/AST/MicrosoftMangle.cpp
  clang/test/CodeGenCXX/mangle-class-nttp.cpp
  clang/test/CodeGenCXX/mangle-ms-templates.cpp

Index: clang/test/CodeGenCXX/mangle-ms-templates.cpp
===
--- clang/test/CodeGenCXX/mangle-ms-templates.cpp
+++ clang/test/CodeGenCXX/mangle-ms-templates.cpp
@@ -272,7 +272,7 @@
 };
 extern const record inst;
 void recref(type1) {}
-// CHECK: "?recref@@YAXU?$type1@$E?inst@@3Urecord@@B@@@Z"
+// CHECK: "?recref@@YAXU?$type1@$1?inst@@3Urecord@@B@@@Z"
 
 struct _GUID {};
 struct __declspec(uuid("{12345678-1234-1234-1234-1234567890aB}")) uuid;
@@ -286,7 +286,7 @@
 void fun(UUIDType1 a) {}
 // CHECK: "?fun@@YAXU?$UUIDType1@Uuuid@@$1?_GUID_12345678_1234_1234_1234_1234567890ab@@3U__s_GUID@@B@@@Z"
 void fun(UUIDType2 b) {}
-// CHECK: "?fun@@YAXU?$UUIDType2@Uuuid@@$E?_GUID_12345678_1234_1234_1234_1234567890ab@@3U__s_GUID@@B@@@Z"
+// CHECK: "?fun@@YAXU?$UUIDType2@Uuuid@@$1?_GUID_12345678_1234_1234_1234_1234567890ab@@3U__s_GUID@@B@@@Z"
 
 template  struct TypeWithFriendDefinition {
   friend void FunctionDefinedWithInjectedName(TypeWithFriendDefinition) {}
Index: clang/test/CodeGenCXX/mangle-class-nttp.cpp
===
--- clang/test/CodeGenCXX/mangle-class-nttp.cpp
+++ clang/test/CodeGenCXX/mangle-class-nttp.cpp
@@ -15,7 +15,7 @@
 
 int n = 0;
 // CHECK: define weak_odr void @_Z1fIXtl1BadL_Z1nvv(
-// MSABI: define {{.*}} @"??$f@$2UB@@PEBH1?n@@3HAH0AYAXXZ"
+// MSABI: define {{.*}} @"??$f@$2UB@@PEBHE?n@@3HAH0AYAXXZ"
 template void f();
 // CHECK: define weak_odr void @_Z1fIXtl1BLPKi0ELi1vv(
 // MSABI: define {{.*}} @"??$f@$2UB@@PEBH0A@H00@@@YAXXZ"
@@ -86,33 +86,85 @@
 struct D { const int Derived::*p; int k; };
 template void f() {}
 // CHECK: define weak_odr void @_Z1fIXtl1DLM7DerivedKi0ELi1vv
-// MSABI: define {{.*}} @"??$f@$2UD@@PERDerived@@H0?0H00@@@YAXXZ"
+// MSABI: define {{.*}} @"??$f@$2UD@@PERDerived@@HNH00@@@YAXXZ"
 template void f();
 // CHECK: define weak_odr void @_Z1fIXtl1DEEEvv
-// MSABI: define {{.*}} @"??$f@$2UD@@PERDerived@@H0?0H0AYAXXZ"
+// MSABI: define {{.*}} @"??$f@$2UD@@PERDerived@@HNH0AYAXXZ"
 template void f();
 // CHECK: define weak_odr void @_Z1fIXtl1DadL_ZN7Derived1zEvv
-// MSABI: define {{.*}} @"??$f@$2UD@@PERDerived@@H0BA@H0AYAXXZ"
+// MSABI: define {{.*}} @"??$f@$2UD@@PERDerived@@H82@z@@H0AYAXXZ"
 template void f();
-#ifndef _WIN32
 // CHECK: define weak_odr void @_Z1fIXtl1DmcM7DerivedKiadL_ZN1A1aEEvv
-// MSABI-FIXME: define {{.*}} @"??$f@$2UD@@PERDerived@@H0A@H0AYAXXZ"
+// MSABI: define {{.*}} @"??$f@$2UD@@PERDerived@@H8A@@a@@H0AYAXXZ"
 template void f();
 // CHECK: define weak_odr void @_Z1fIXtl1DmcM7DerivedKiadL_ZN1A1bEEvv
-// MSABI-FIXME: define {{.*}} @"??$f@$2UD@@PERDerived@@H03H0AYAXXZ"
+// MSABI: define {{.*}} @"??$f@$2UD@@PERDerived@@H8A@@b@@H0AYAXXZ"
 template void f();
 // FIXME: Is the Ut_1 mangling here correct?
 // CHECK: define weak_odr void @_Z1fIXtl1DmcM7DerivedKiadL_ZN6NestedUt_1kEE8ELi2vv
-// FIXME: This mangles the same as &A::a (bug in the MS ABI).
-// MSABI-FIXME: define {{.*}} @"??$f@$2UD@@PERDerived@@H0A@H01@@@YAXXZ"
+// MSABI: define {{.*}} @"??$f@$2UD@@PERDerived@@H8@Nested@@k@@H01@@@YAXXZ"
 template void f();
 struct MoreDerived : A, Derived { int z; };
 // CHECK: define weak_odr void @_Z1fIXtl1DmcM7DerivedKiadL_ZN11MoreDerived1zEEn8vv
-// MSABI-FIXME: define {{.*}} @"??$f@$2UD@@PERDerived@@H0BI@H0AYAXXZ"
+// MSABI: define {{.*}} @"??$f@$2UD@@PERDerived@@H8MoreDerived@@z@@H0AYAXXZ"
 template void f();
-#endif
 
-// FIXME: Pointers to member functions.
+struct DerivedVirtually : virtual A, Nested { int z; };
+struct D2 { const int DerivedVirtually::*p; int k; };
+template void f() {}
+// CHECK: define weak_odr void @_Z1fIXtl2D2LM16DerivedVirtuallyKi0ELi1vv
+// MSABI: define {{.*}} @"??$f@$2UD2@@PERDerivedVirtually@@HFA@?0H00@@@YAXXZ"
+template void f();
+// CHECK: define weak_odr void @_Z1fIXtl2D2EEEvv
+// MSABI: define {{.*}} @"??$f@$2UD2@@PERDerivedVirtually@@HFA@?0H0AYAXXZ"
+templa

[PATCH] D146386: [MS ABI] Fix mangling references to declarations.

2023-04-01 Thread Andrey Ali Khan Bolshakov via Phabricator via cfe-commits
bolshakov-a added a comment.

> The following produces a name collision on MSVC

Clang reproduces this buggy behavior. Should it produce an explicit error 
instead? Or, maybe, some temporary correct algorithm should be found? (It is 
pretty sad if clang cannot provide new language features for Windows programs 
just because MSVC doesn't provide them...)


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

https://reviews.llvm.org/D146386

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


[PATCH] D146386: [MS ABI] Fix mangling references to declarations.

2023-04-01 Thread Andrey Ali Khan Bolshakov via Phabricator via cfe-commits
bolshakov-a updated this revision to Diff 510282.
bolshakov-a edited the summary of this revision.
bolshakov-a added a comment.

Fix mangling of references to subobjects.


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

https://reviews.llvm.org/D146386

Files:
  clang/lib/AST/MicrosoftMangle.cpp
  clang/test/CodeGenCXX/mangle-class-nttp.cpp
  clang/test/CodeGenCXX/mangle-ms-templates.cpp

Index: clang/test/CodeGenCXX/mangle-ms-templates.cpp
===
--- clang/test/CodeGenCXX/mangle-ms-templates.cpp
+++ clang/test/CodeGenCXX/mangle-ms-templates.cpp
@@ -272,7 +272,7 @@
 };
 extern const record inst;
 void recref(type1) {}
-// CHECK: "?recref@@YAXU?$type1@$E?inst@@3Urecord@@B@@@Z"
+// CHECK: "?recref@@YAXU?$type1@$1?inst@@3Urecord@@B@@@Z"
 
 struct _GUID {};
 struct __declspec(uuid("{12345678-1234-1234-1234-1234567890aB}")) uuid;
@@ -286,7 +286,7 @@
 void fun(UUIDType1 a) {}
 // CHECK: "?fun@@YAXU?$UUIDType1@Uuuid@@$1?_GUID_12345678_1234_1234_1234_1234567890ab@@3U__s_GUID@@B@@@Z"
 void fun(UUIDType2 b) {}
-// CHECK: "?fun@@YAXU?$UUIDType2@Uuuid@@$E?_GUID_12345678_1234_1234_1234_1234567890ab@@3U__s_GUID@@B@@@Z"
+// CHECK: "?fun@@YAXU?$UUIDType2@Uuuid@@$1?_GUID_12345678_1234_1234_1234_1234567890ab@@3U__s_GUID@@B@@@Z"
 
 template  struct TypeWithFriendDefinition {
   friend void FunctionDefinedWithInjectedName(TypeWithFriendDefinition) {}
Index: clang/test/CodeGenCXX/mangle-class-nttp.cpp
===
--- clang/test/CodeGenCXX/mangle-class-nttp.cpp
+++ clang/test/CodeGenCXX/mangle-class-nttp.cpp
@@ -15,7 +15,7 @@
 
 int n = 0;
 // CHECK: define weak_odr void @_Z1fIXtl1BadL_Z1nvv(
-// MSABI: define {{.*}} @"??$f@$2UB@@PEBH1?n@@3HAH0AYAXXZ"
+// MSABI: define {{.*}} @"??$f@$2UB@@PEBHE?n@@3HAH0AYAXXZ"
 template void f();
 // CHECK: define weak_odr void @_Z1fIXtl1BLPKi0ELi1vv(
 // MSABI: define {{.*}} @"??$f@$2UB@@PEBH0A@H00@@@YAXXZ"
@@ -36,10 +36,13 @@
 
 // Pointers to subobjects.
 struct Nested { union { int k; int arr[2]; }; } nested[2];
-struct Derived : A, Nested { int z; } extern derived;
+struct Derived : A, Nested { int z; A a_field; } extern derived;
 // CHECK: define weak_odr void @_Z1fIXtl1BadsoKiL_Z7derivedE16vv
 // MSABI: define {{.*}} void @"??$f@$2UB@@PEBH56E?derived@@3UDerived@@Az@@@H0AYAXXZ"
 template void f();
+// CHECK: define weak_odr void @_Z1fIXtl1BadsoKiL_Z7derivedE20vv
+// MSABI: define {{.*}} void @"??$f@$2UB@@PEBH566E?derived@@3UDerived@@Aa_field@@a@@@H0AYAXXZ"
+template void f();
 // FIXME: We don't know the MS ABI mangling for array subscripting and
 // past-the-end pointers yet.
 #ifndef _WIN32
@@ -86,33 +89,85 @@
 struct D { const int Derived::*p; int k; };
 template void f() {}
 // CHECK: define weak_odr void @_Z1fIXtl1DLM7DerivedKi0ELi1vv
-// MSABI: define {{.*}} @"??$f@$2UD@@PERDerived@@H0?0H00@@@YAXXZ"
+// MSABI: define {{.*}} @"??$f@$2UD@@PERDerived@@HNH00@@@YAXXZ"
 template void f();
 // CHECK: define weak_odr void @_Z1fIXtl1DEEEvv
-// MSABI: define {{.*}} @"??$f@$2UD@@PERDerived@@H0?0H0AYAXXZ"
+// MSABI: define {{.*}} @"??$f@$2UD@@PERDerived@@HNH0AYAXXZ"
 template void f();
 // CHECK: define weak_odr void @_Z1fIXtl1DadL_ZN7Derived1zEvv
-// MSABI: define {{.*}} @"??$f@$2UD@@PERDerived@@H0BA@H0AYAXXZ"
+// MSABI: define {{.*}} @"??$f@$2UD@@PERDerived@@H82@z@@H0AYAXXZ"
 template void f();
-#ifndef _WIN32
 // CHECK: define weak_odr void @_Z1fIXtl1DmcM7DerivedKiadL_ZN1A1aEEvv
-// MSABI-FIXME: define {{.*}} @"??$f@$2UD@@PERDerived@@H0A@H0AYAXXZ"
+// MSABI: define {{.*}} @"??$f@$2UD@@PERDerived@@H8A@@a@@H0AYAXXZ"
 template void f();
 // CHECK: define weak_odr void @_Z1fIXtl1DmcM7DerivedKiadL_ZN1A1bEEvv
-// MSABI-FIXME: define {{.*}} @"??$f@$2UD@@PERDerived@@H03H0AYAXXZ"
+// MSABI: define {{.*}} @"??$f@$2UD@@PERDerived@@H8A@@b@@H0AYAXXZ"
 template void f();
 // FIXME: Is the Ut_1 mangling here correct?
 // CHECK: define weak_odr void @_Z1fIXtl1DmcM7DerivedKiadL_ZN6NestedUt_1kEE8ELi2vv
-// FIXME: This mangles the same as &A::a (bug in the MS ABI).
-// MSABI-FIXME: define {{.*}} @"??$f@$2UD@@PERDerived@@H0A@H01@@@YAXXZ"
+// MSABI: define {{.*}} @"??$f@$2UD@@PERDerived@@H8@Nested@@k@@H01@@@YAXXZ"
 template void f();
 struct MoreDerived : A, Derived { int z; };
 // CHECK: define weak_odr void @_Z1fIXtl1DmcM7DerivedKiadL_ZN11MoreDerived1zEEn8vv
-// MSABI-FIXME: define {{.*}} @"??$f@$2UD@@PERDerived@@H0BI@H0AYAXXZ"
+// MSABI: define {{.*}} @"??$f@$2UD@@PERDerived@@H8MoreDerived@@z@@H0AYAXXZ"
 template void f();
-#endif
 
-// FIXME: Pointers to member functions.
+struct DerivedVirtually : virtual A, Nested { int z; };
+struct D2 { const int DerivedVirtually::*p; int k; };
+template void f() {}
+// CHECK: define weak_odr void @_Z1fIXtl2D2LM16DerivedVirtuallyKi0ELi1vv
+// MSABI: define {{.*}} @"??$f@$2UD2@@PERDerivedVirtually@@HFA@?0H00@@@YAXXZ"
+template void f();
+/

[PATCH] D141215: [clang-repl] Introduce Value to capture expression results

2023-04-01 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 510286.
junaire added a comment.

Fix known memory issues.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141215

Files:
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Interpreter/Interpreter.h
  clang/include/clang/Interpreter/Value.h
  clang/include/clang/Parse/Parser.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Frontend/PrintPreprocessedOutput.cpp
  clang/lib/Interpreter/CMakeLists.txt
  clang/lib/Interpreter/IncrementalExecutor.cpp
  clang/lib/Interpreter/IncrementalExecutor.h
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Interpreter/IncrementalParser.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/lib/Interpreter/InterpreterUtils.cpp
  clang/lib/Interpreter/InterpreterUtils.h
  clang/lib/Interpreter/Value.cpp
  clang/lib/Lex/PPLexerChange.cpp
  clang/lib/Parse/ParseCXXInlineMethods.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Parse/Parser.cpp
  clang/tools/clang-repl/CMakeLists.txt
  clang/unittests/Interpreter/CMakeLists.txt
  clang/unittests/Interpreter/InterpreterTest.cpp

Index: clang/unittests/Interpreter/InterpreterTest.cpp
===
--- clang/unittests/Interpreter/InterpreterTest.cpp
+++ clang/unittests/Interpreter/InterpreterTest.cpp
@@ -17,6 +17,7 @@
 #include "clang/AST/Mangle.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/TextDiagnosticPrinter.h"
+#include "clang/Interpreter/Value.h"
 #include "clang/Sema/Lookup.h"
 #include "clang/Sema/Sema.h"
 
@@ -33,6 +34,10 @@
 #define CLANG_INTERPRETER_NO_SUPPORT_EXEC
 #endif
 
+int Global = 42;
+int getGlobal() { return Global; }
+void setGlobal(int val) { Global = val; }
+
 namespace {
 using Args = std::vector;
 static std::unique_ptr
@@ -276,8 +281,7 @@
   std::vector Args = {"-fno-delayed-template-parsing"};
   std::unique_ptr Interp = createInterpreter(Args);
 
-  llvm::cantFail(Interp->Parse("void* operator new(__SIZE_TYPE__, void* __p);"
-   "extern \"C\" int printf(const char*,...);"
+  llvm::cantFail(Interp->Parse("extern \"C\" int printf(const char*,...);"
"class A {};"
"struct B {"
"  template"
@@ -314,4 +318,38 @@
   free(NewA);
 }
 
+TEST(InterpreterTest, Value) {
+  std::unique_ptr Interp = createInterpreter();
+
+  Value V1;
+  llvm::cantFail(Interp->ParseAndExecute("int x = 42;"));
+  llvm::cantFail(Interp->ParseAndExecute("x", &V1));
+  EXPECT_EQ(V1.getInt(), 42);
+  EXPECT_TRUE(V1.getType()->isIntegerType());
+
+  Value V2;
+  llvm::cantFail(Interp->ParseAndExecute("double y = 3.14;"));
+  llvm::cantFail(Interp->ParseAndExecute("y", &V2));
+  EXPECT_EQ(V2.getAs(), 3.14);
+  EXPECT_TRUE(V2.getType()->isFloatingType());
+  EXPECT_EQ(V2.castAs(), 3);
+
+  llvm::cantFail(Interp->ParseAndExecute("int getGlobal();"));
+  llvm::cantFail(Interp->ParseAndExecute("void setGlobal(int);"));
+  Value V3;
+  llvm::cantFail(Interp->ParseAndExecute("getGlobal()", &V3));
+  EXPECT_EQ(V3.getInt(), 42);
+  EXPECT_TRUE(V3.getType()->isIntegerType());
+
+  // Change the global from the compiled code.
+  setGlobal(43);
+  Value V4;
+  llvm::cantFail(Interp->ParseAndExecute("getGlobal()", &V4));
+  EXPECT_EQ(V4.getInt(), 43);
+  EXPECT_TRUE(V4.getType()->isIntegerType());
+
+  // Change the global from the interpreted code.
+  llvm::cantFail(Interp->ParseAndExecute("setGlobal(44);"));
+  EXPECT_EQ(getGlobal(), 44);
+}
 } // end anonymous namespace
Index: clang/unittests/Interpreter/CMakeLists.txt
===
--- clang/unittests/Interpreter/CMakeLists.txt
+++ clang/unittests/Interpreter/CMakeLists.txt
@@ -22,3 +22,5 @@
 if(NOT WIN32)
   add_subdirectory(ExceptionTests)
 endif()
+
+export_executable_symbols(ClangReplInterpreterTests)
Index: clang/tools/clang-repl/CMakeLists.txt
===
--- clang/tools/clang-repl/CMakeLists.txt
+++ clang/tools/clang-repl/CMakeLists.txt
@@ -12,6 +12,7 @@
   )
 
 clang_target_link_libraries(clang-repl PRIVATE
+  clangAST
   clangBasic
   clangFrontend
   clangInterpreter
Index: clang/lib/Parse/Parser.cpp
===
--- clang/lib/Parse/Parser.cpp
+++ clang/lib/Parse/Parser.cpp
@@ -320,6 +320,7 @@
 case tok::annot_module_begin:
 case tok::annot_module_end:
 case tok::annot_module_include:
+case tok::annot_input_end:
   // Stop before we change submodules. They generally indicate a "good"
   // place to pick up parsing again (except in the special case where
   // we're trying to skip to EOF).
@@ -616,8 +617,8 @@
 
   // Skip over the EOF token, flagging end of previous input for incremental
   // processing
-  if (PP.isIncremental

[PATCH] D146995: [clang-format][NFC] Refactor unit tests for "LambdaBodyIndentation: OuterScope" option.

2023-04-01 Thread Owen Pan 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 rG1dd31ebe5418: [clang-format][NFC] Refactor unit tests for 
"LambdaBodyIndentation: OuterScope" (authored by jp4a50, committed by 
owenpan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146995

Files:
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -21956,51 +21956,59 @@
LLVMWithBeforeLambdaBody);
 
   // Lambdas with different indentation styles.
-  Style = getLLVMStyleWithColumns(100);
-  EXPECT_EQ("SomeResult doSomething(SomeObject promise) {\n"
-"  return promise.then(\n"
-"  [this, &someVariable, someObject = "
-"std::mv(s)](std::vector evaluated) mutable {\n"
-"return someObject.startAsyncAction().then(\n"
-"[this, &someVariable](AsyncActionResult result) "
-"mutable { result.processMore(); });\n"
-"  });\n"
-"}\n",
-format("SomeResult doSomething(SomeObject promise) {\n"
-   "  return promise.then([this, &someVariable, someObject = "
-   "std::mv(s)](std::vector evaluated) mutable {\n"
-   "return someObject.startAsyncAction().then([this, "
-   "&someVariable](AsyncActionResult result) mutable {\n"
-   "  result.processMore();\n"
-   "});\n"
-   "  });\n"
-   "}\n",
-   Style));
+  Style = getLLVMStyleWithColumns(60);
+  verifyFormat("Result doSomething(Promise promise) {\n"
+   "  return promise.then(\n"
+   "  [this, obj = std::move(s)](int bar) mutable {\n"
+   "return someObject.startAsyncAction().then(\n"
+   "[this, &obj](Result result) mutable {\n"
+   "  result.processMore();\n"
+   "});\n"
+   "  });\n"
+   "}\n",
+   Style);
   Style.LambdaBodyIndentation = FormatStyle::LBI_OuterScope;
-  verifyFormat("test() {\n"
-   "  ([]() -> {\n"
+  verifyFormat("Result doSomething(Promise promise) {\n"
+   "  return promise.then(\n"
+   "  [this, obj = std::move(s)](int bar) mutable {\n"
+   "return obj.startAsyncAction().then(\n"
+   "[this, &obj](Result result) mutable {\n"
+   "  result.processMore();\n"
+   "});\n"
+   "  });\n"
+   "}\n",
+   Style);
+  verifyFormat("Result doSomething(Promise promise) {\n"
+   "  return promise.then([this, obj = std::move(s)] {\n"
+   "return obj.startAsyncAction().then(\n"
+   "[this, &obj](Result result) mutable {\n"
+   "  result.processMore();\n"
+   "});\n"
+   "  });\n"
+   "}\n",
+   Style);
+  verifyFormat("void test() {\n"
+   "  ([]() -> auto {\n"
"int b = 32;\n"
"return 3;\n"
"  }).foo();\n"
"}",
Style);
-  verifyFormat("test() {\n"
-   "  []() -> {\n"
+  verifyFormat("void test() {\n"
+   "  []() -> auto {\n"
"int b = 32;\n"
"return 3;\n"
"  }\n"
"}",
Style);
   verifyFormat("std::sort(v.begin(), v.end(),\n"
-   "  [](const auto &someLongArgumentName, const auto "
-   "&someOtherLongArgumentName) {\n"
-   "  return someLongArgumentName.someMemberVariable < "
-   "someOtherLongArgumentName.someMemberVariable;\n"
-   "});",
+   "  [](const auto &foo, const auto &bar) {\n"
+   "  return foo.baz < bar.baz;\n"
+   "});\n",
Style);
-  verifyFormat("test() {\n"
+  verifyFormat("void test() {\n"
"  (\n"
-   "  []() -> {\n"
+   "  []() -> auto {\n"
"int b = 32;\n"
"return 3;\n"
"  },\n"
@@ -22008,8 +22016,8 @@
"  .foo();\n"
"}",
Style);
-  verifyFormat("test() {\n"
-   "  ([]() -> {\n"
+  verifyFormat("void test() {\n"
+   "  ([]() -> auto {\n"
"int b = 32;\n"
"return 3;\n"
"  })\n"
@@ -22017,51 +22025,14 @@
"  .bar();\n"
 

[clang] 1dd31eb - [clang-format][NFC] Refactor unit tests for "LambdaBodyIndentation: OuterScope"

2023-04-01 Thread Owen Pan via cfe-commits

Author: Jon Phillips
Date: 2023-04-01T19:35:49-07:00
New Revision: 1dd31ebe5418d9581f152dcb6cbc4aed66ac9472

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

LOG: [clang-format][NFC] Refactor unit tests for "LambdaBodyIndentation: 
OuterScope"

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

Added: 


Modified: 
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 1c960eb28ef9..8d009d6a33a4 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -21956,51 +21956,59 @@ TEST_F(FormatTest, FormatsLambdas) {
LLVMWithBeforeLambdaBody);
 
   // Lambdas with 
diff erent indentation styles.
-  Style = getLLVMStyleWithColumns(100);
-  EXPECT_EQ("SomeResult doSomething(SomeObject promise) {\n"
-"  return promise.then(\n"
-"  [this, &someVariable, someObject = "
-"std::mv(s)](std::vector evaluated) mutable {\n"
-"return someObject.startAsyncAction().then(\n"
-"[this, &someVariable](AsyncActionResult result) "
-"mutable { result.processMore(); });\n"
-"  });\n"
-"}\n",
-format("SomeResult doSomething(SomeObject promise) {\n"
-   "  return promise.then([this, &someVariable, someObject = "
-   "std::mv(s)](std::vector evaluated) mutable {\n"
-   "return someObject.startAsyncAction().then([this, "
-   "&someVariable](AsyncActionResult result) mutable {\n"
-   "  result.processMore();\n"
-   "});\n"
-   "  });\n"
-   "}\n",
-   Style));
+  Style = getLLVMStyleWithColumns(60);
+  verifyFormat("Result doSomething(Promise promise) {\n"
+   "  return promise.then(\n"
+   "  [this, obj = std::move(s)](int bar) mutable {\n"
+   "return someObject.startAsyncAction().then(\n"
+   "[this, &obj](Result result) mutable {\n"
+   "  result.processMore();\n"
+   "});\n"
+   "  });\n"
+   "}\n",
+   Style);
   Style.LambdaBodyIndentation = FormatStyle::LBI_OuterScope;
-  verifyFormat("test() {\n"
-   "  ([]() -> {\n"
+  verifyFormat("Result doSomething(Promise promise) {\n"
+   "  return promise.then(\n"
+   "  [this, obj = std::move(s)](int bar) mutable {\n"
+   "return obj.startAsyncAction().then(\n"
+   "[this, &obj](Result result) mutable {\n"
+   "  result.processMore();\n"
+   "});\n"
+   "  });\n"
+   "}\n",
+   Style);
+  verifyFormat("Result doSomething(Promise promise) {\n"
+   "  return promise.then([this, obj = std::move(s)] {\n"
+   "return obj.startAsyncAction().then(\n"
+   "[this, &obj](Result result) mutable {\n"
+   "  result.processMore();\n"
+   "});\n"
+   "  });\n"
+   "}\n",
+   Style);
+  verifyFormat("void test() {\n"
+   "  ([]() -> auto {\n"
"int b = 32;\n"
"return 3;\n"
"  }).foo();\n"
"}",
Style);
-  verifyFormat("test() {\n"
-   "  []() -> {\n"
+  verifyFormat("void test() {\n"
+   "  []() -> auto {\n"
"int b = 32;\n"
"return 3;\n"
"  }\n"
"}",
Style);
   verifyFormat("std::sort(v.begin(), v.end(),\n"
-   "  [](const auto &someLongArgumentName, const auto "
-   "&someOtherLongArgumentName) {\n"
-   "  return someLongArgumentName.someMemberVariable < "
-   "someOtherLongArgumentName.someMemberVariable;\n"
-   "});",
+   "  [](const auto &foo, const auto &bar) {\n"
+   "  return foo.baz < bar.baz;\n"
+   "});\n",
Style);
-  verifyFormat("test() {\n"
+  verifyFormat("void test() {\n"
"  (\n"
-   "  []() -> {\n"
+   "  []() -> auto {\n"
"int b = 32;\n"
"return 3;\n"
"  },\n"
@@ -22008,8 +22016,8 @@ TEST_F(FormatTest, FormatsLambdas) {
"  .foo();\n"
"}",
Style);
-  verifyFormat("test() {\n"
-   "  ([]() -> {\n"
+

[PATCH] D146809: [WIP][clang-repl] Implement Value pretty printing

2023-04-01 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 510288.
junaire added a comment.

CHANGELOG:

1. Add constant array tests.
2. Fix misc issues.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146809

Files:
  clang/include/clang/Interpreter/Interpreter.h
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/__clang_interpreter_runtime_printvalue.h
  clang/lib/Interpreter/CMakeLists.txt
  clang/lib/Interpreter/Interpreter.cpp
  clang/lib/Interpreter/InterpreterUtils.cpp
  clang/lib/Interpreter/InterpreterUtils.h
  clang/lib/Interpreter/Value.cpp
  clang/lib/Interpreter/ValuePrinter.cpp
  clang/test/Interpreter/pretty-print.cpp

Index: clang/test/Interpreter/pretty-print.cpp
===
--- /dev/null
+++ clang/test/Interpreter/pretty-print.cpp
@@ -0,0 +1,48 @@
+// RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
+// RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck --check-prefix=CHECK-DRIVER %s
+// UNSUPPORTED: system-aix
+// CHECK-DRIVER: i = 10
+// RUN: cat %s | clang-repl | FileCheck %s
+char c = 'a';
+c
+// CHECK: (char) 'a'
+
+int x = 42;
+x
+// CHECK-NEXT: (int) 42
+
+x - 2
+// CHECK-NEXT: (int) 40
+
+float f = 4.2f;
+f
+// CHECK-NEXT: (float) 4.2f
+
+double d = 4.21;
+d
+// CHECK-NEXT: (double) 4.210
+
+struct S{};
+S s;
+s
+// CHECK-NEXT: (S &) [[Addr:@0x.*]]
+
+S{}
+// CHECK-NEXT: (S) [[Addr:@0x.*]]
+
+struct SS { ~SS() {} };
+SS{}
+// CHECK-NEXT: (SS) [[Addr:@0x.*]]
+
+int arr[3] = {1,2,3};
+arr
+// CHECK-NEXT: (int[3]) { 1, 2, 3 }
+
+#include 
+
+auto p1 = std::make_shared(42);
+p1
+// CHECK-NEXT: (shared_ptr &) std::shared_ptr -> [[Addr:@0x.*]]
+
+%quit
+
Index: clang/lib/Interpreter/ValuePrinter.cpp
===
--- /dev/null
+++ clang/lib/Interpreter/ValuePrinter.cpp
@@ -0,0 +1,527 @@
+#include "InterpreterUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/PrettyPrinter.h"
+#include "clang/AST/Type.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Interpreter/Interpreter.h"
+#include "clang/Interpreter/Value.h"
+#include "clang/Parse/Parser.h"
+#include "clang/Sema/Lookup.h"
+#include "clang/Sema/Sema.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+#include 
+
+using namespace clang;
+
+namespace rep_runtime_internal {
+REPL_EXTERNAL_VISIBILITY
+extern const char *const kEmptyCollection = "{}";
+} // namespace rep_runtime_internal
+
+static std::string PrintDeclType(const QualType &QT, NamedDecl *D) {
+  std::string Str;
+  llvm::raw_string_ostream SS(Str);
+  if (QT.hasQualifiers())
+SS << QT.getQualifiers().getAsString() << " ";
+  SS << D->getQualifiedNameAsString();
+  return Str;
+}
+
+static std::string PrintQualType(ASTContext &Ctx, QualType QT) {
+  std::string Str;
+  llvm::raw_string_ostream SS(Str);
+  PrintingPolicy Policy(Ctx.getPrintingPolicy());
+  // Print the Allocator in STL containers, for instance.
+  Policy.SuppressDefaultTemplateArgs = false;
+  Policy.SuppressUnwrittenScope = true;
+  // Print 'a >' rather than 'a>'.
+  Policy.SplitTemplateClosers = true;
+
+  struct LocalPrintingPolicyRAII {
+ASTContext &Context;
+PrintingPolicy Policy;
+
+LocalPrintingPolicyRAII(ASTContext &Ctx, PrintingPolicy &PP)
+: Context(Ctx), Policy(Ctx.getPrintingPolicy()) {
+  Context.setPrintingPolicy(PP);
+}
+~LocalPrintingPolicyRAII() { Context.setPrintingPolicy(Policy); }
+  } X(Ctx, Policy);
+
+  const QualType NonRefTy = QT.getNonReferenceType();
+
+  if (const auto *TTy = llvm::dyn_cast(NonRefTy))
+SS << PrintDeclType(NonRefTy, TTy->getDecl());
+  else if (const auto *TRy = dyn_cast(NonRefTy))
+SS << PrintDeclType(NonRefTy, TRy->getDecl());
+  else {
+const QualType Canon = NonRefTy.getCanonicalType();
+if (Canon->isBuiltinType() && !NonRefTy->isFunctionPointerType() &&
+!NonRefTy->isMemberPointerType()) {
+  SS << Canon.getAsString(Ctx.getPrintingPolicy());
+} else if (const auto *TDTy = dyn_cast(NonRefTy)) {
+  // FIXME: TemplateSpecializationType & SubstTemplateTypeParmType checks
+  // are predominately to get STL containers to print nicer and might be
+  // better handled in GetFullyQualifiedName.
+  //
+  // std::vector::iterator is a TemplateSpecializationType
+  // std::vector::value_type is a SubstTemplateTypeParmType
+  //
+  QualType SSDesugar = TDTy->getLocallyUnqualifiedSingleStepDesugaredType();
+  if (llvm::isa(SSDesugar))
+SS << GetFullTypeName(Ctx, Canon);
+  else if (llvm::isa(SSDesugar))
+SS << GetFullTypeName(Ctx, NonRefTy);
+  else
+SS << PrintDeclType(NonRefTy, TDTy->getDecl());
+} else
+  SS << GetFullTypeName(Ctx, NonRefTy);
+  }
+
+  if (QT->isReferenceType())
+SS << " &";
+
+  return Str;
+}
+
+static std::string Pri

[PATCH] D147395: [Clangd] Make the type hint length limit configurable

2023-04-01 Thread Yi Zhang via Phabricator via cfe-commits
zhangyi1357 created this revision.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
zhangyi1357 requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147395

Files:
  clang-tools-extra/clangd/Config.h
  clang-tools-extra/clangd/ConfigCompile.cpp
  clang-tools-extra/clangd/ConfigFragment.h
  clang-tools-extra/clangd/ConfigYAML.cpp
  clang-tools-extra/clangd/InlayHints.cpp


Index: clang-tools-extra/clangd/InlayHints.cpp
===
--- clang-tools-extra/clangd/InlayHints.cpp
+++ clang-tools-extra/clangd/InlayHints.cpp
@@ -688,7 +688,7 @@
   return;
 
 std::string TypeName = T.getAsString(Policy);
-if (TypeName.length() < TypeNameLimit)
+if (TypeName.length() < Cfg.InlayHints.TypeNameLimit)
   addInlayHint(R, HintSide::Right, InlayHintKind::Type, Prefix, TypeName,
/*Suffix=*/"");
   }
@@ -714,8 +714,6 @@
   // the policies are initialized for more details.)
   PrintingPolicy TypeHintPolicy;
   PrintingPolicy StructuredBindingPolicy;
-
-  static const size_t TypeNameLimit = 32;
 };
 
 } // namespace
Index: clang-tools-extra/clangd/ConfigYAML.cpp
===
--- clang-tools-extra/clangd/ConfigYAML.cpp
+++ clang-tools-extra/clangd/ConfigYAML.cpp
@@ -254,6 +254,10 @@
   if (auto Value = boolValue(N, "Designators"))
 F.Designators = *Value;
 });
+Dict.handle("TypeNameLimit", [&](Node &N) {
+  if (auto Value = scalarValue(N, "TypeNameLimit"))
+F.TypeNameLimit = *Value;
+});
 Dict.parse(N);
   }
 
Index: clang-tools-extra/clangd/ConfigFragment.h
===
--- clang-tools-extra/clangd/ConfigFragment.h
+++ clang-tools-extra/clangd/ConfigFragment.h
@@ -322,6 +322,8 @@
 std::optional> DeducedTypes;
 /// Show designators in aggregate initialization.
 std::optional> Designators;
+/// Limit the length of type name hints.
+std::optional> TypeNameLimit;
   };
   InlayHintsBlock InlayHints;
 };
Index: clang-tools-extra/clangd/ConfigCompile.cpp
===
--- clang-tools-extra/clangd/ConfigCompile.cpp
+++ clang-tools-extra/clangd/ConfigCompile.cpp
@@ -611,6 +611,11 @@
   Out.Apply.push_back([Value(**F.Designators)](const Params &, Config &C) {
 C.InlayHints.Designators = Value;
   });
+if (F.TypeNameLimit)
+  Out.Apply.push_back(
+  [Value(**F.TypeNameLimit)](const Params &, Config &C) {
+C.InlayHints.TypeNameLimit = stoul(Value);
+  });
   }
 
   constexpr static llvm::SourceMgr::DiagKind Error = llvm::SourceMgr::DK_Error;
Index: clang-tools-extra/clangd/Config.h
===
--- clang-tools-extra/clangd/Config.h
+++ clang-tools-extra/clangd/Config.h
@@ -147,6 +147,8 @@
 bool Parameters = true;
 bool DeducedTypes = true;
 bool Designators = true;
+// Limit the length of type names in inlay hints.
+size_t TypeNameLimit = 32;
   } InlayHints;
 };
 


Index: clang-tools-extra/clangd/InlayHints.cpp
===
--- clang-tools-extra/clangd/InlayHints.cpp
+++ clang-tools-extra/clangd/InlayHints.cpp
@@ -688,7 +688,7 @@
   return;
 
 std::string TypeName = T.getAsString(Policy);
-if (TypeName.length() < TypeNameLimit)
+if (TypeName.length() < Cfg.InlayHints.TypeNameLimit)
   addInlayHint(R, HintSide::Right, InlayHintKind::Type, Prefix, TypeName,
/*Suffix=*/"");
   }
@@ -714,8 +714,6 @@
   // the policies are initialized for more details.)
   PrintingPolicy TypeHintPolicy;
   PrintingPolicy StructuredBindingPolicy;
-
-  static const size_t TypeNameLimit = 32;
 };
 
 } // namespace
Index: clang-tools-extra/clangd/ConfigYAML.cpp
===
--- clang-tools-extra/clangd/ConfigYAML.cpp
+++ clang-tools-extra/clangd/ConfigYAML.cpp
@@ -254,6 +254,10 @@
   if (auto Value = boolValue(N, "Designators"))
 F.Designators = *Value;
 });
+Dict.handle("TypeNameLimit", [&](Node &N) {
+  if (auto Value = scalarValue(N, "TypeNameLimit"))
+F.TypeNameLimit = *Value;
+});
 Dict.parse(N);
   }
 
Index: clang-tools-extra/clangd/ConfigFragment.h
===
--- clang-tools-extra/clangd/ConfigFragment.h
+++ clang-tools-extra/clangd/ConfigFragment.h
@@ -322,6 +322,8 @@
 std::optional> DeducedTypes;
 /// Show designators in aggregate initialization.
 std::optional> Designators;
+/// Limit the length of type name hints.
+std::optional> TypeNameLimit;
   };
   InlayHintsBlock Inl

[PATCH] D147395: [Clangd] Make the type hint length limit configurable

2023-04-01 Thread Yi Zhang via Phabricator via cfe-commits
zhangyi1357 updated this revision to Diff 510292.
zhangyi1357 added a comment.

Format code modified using clang format.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147395

Files:
  clang-tools-extra/clangd/Config.h
  clang-tools-extra/clangd/ConfigCompile.cpp
  clang-tools-extra/clangd/ConfigFragment.h
  clang-tools-extra/clangd/ConfigYAML.cpp
  clang-tools-extra/clangd/InlayHints.cpp


Index: clang-tools-extra/clangd/InlayHints.cpp
===
--- clang-tools-extra/clangd/InlayHints.cpp
+++ clang-tools-extra/clangd/InlayHints.cpp
@@ -688,7 +688,7 @@
   return;
 
 std::string TypeName = T.getAsString(Policy);
-if (TypeName.length() < TypeNameLimit)
+if (TypeName.length() < Cfg.InlayHints.TypeNameLimit)
   addInlayHint(R, HintSide::Right, InlayHintKind::Type, Prefix, TypeName,
/*Suffix=*/"");
   }
@@ -714,8 +714,6 @@
   // the policies are initialized for more details.)
   PrintingPolicy TypeHintPolicy;
   PrintingPolicy StructuredBindingPolicy;
-
-  static const size_t TypeNameLimit = 32;
 };
 
 } // namespace
Index: clang-tools-extra/clangd/ConfigYAML.cpp
===
--- clang-tools-extra/clangd/ConfigYAML.cpp
+++ clang-tools-extra/clangd/ConfigYAML.cpp
@@ -254,6 +254,10 @@
   if (auto Value = boolValue(N, "Designators"))
 F.Designators = *Value;
 });
+Dict.handle("TypeNameLimit", [&](Node &N) {
+  if (auto Value = scalarValue(N, "TypeNameLimit"))
+F.TypeNameLimit = *Value;
+});
 Dict.parse(N);
   }
 
Index: clang-tools-extra/clangd/ConfigFragment.h
===
--- clang-tools-extra/clangd/ConfigFragment.h
+++ clang-tools-extra/clangd/ConfigFragment.h
@@ -322,6 +322,8 @@
 std::optional> DeducedTypes;
 /// Show designators in aggregate initialization.
 std::optional> Designators;
+/// Limit the length of type name hints.
+std::optional> TypeNameLimit;
   };
   InlayHintsBlock InlayHints;
 };
Index: clang-tools-extra/clangd/ConfigCompile.cpp
===
--- clang-tools-extra/clangd/ConfigCompile.cpp
+++ clang-tools-extra/clangd/ConfigCompile.cpp
@@ -611,6 +611,11 @@
   Out.Apply.push_back([Value(**F.Designators)](const Params &, Config &C) {
 C.InlayHints.Designators = Value;
   });
+if (F.TypeNameLimit)
+  Out.Apply.push_back(
+  [Value(**F.TypeNameLimit)](const Params &, Config &C) {
+C.InlayHints.TypeNameLimit = stoul(Value);
+  });
   }
 
   constexpr static llvm::SourceMgr::DiagKind Error = llvm::SourceMgr::DK_Error;
Index: clang-tools-extra/clangd/Config.h
===
--- clang-tools-extra/clangd/Config.h
+++ clang-tools-extra/clangd/Config.h
@@ -147,6 +147,8 @@
 bool Parameters = true;
 bool DeducedTypes = true;
 bool Designators = true;
+// Limit the length of type names in inlay hints.
+size_t TypeNameLimit = 32;
   } InlayHints;
 };
 


Index: clang-tools-extra/clangd/InlayHints.cpp
===
--- clang-tools-extra/clangd/InlayHints.cpp
+++ clang-tools-extra/clangd/InlayHints.cpp
@@ -688,7 +688,7 @@
   return;
 
 std::string TypeName = T.getAsString(Policy);
-if (TypeName.length() < TypeNameLimit)
+if (TypeName.length() < Cfg.InlayHints.TypeNameLimit)
   addInlayHint(R, HintSide::Right, InlayHintKind::Type, Prefix, TypeName,
/*Suffix=*/"");
   }
@@ -714,8 +714,6 @@
   // the policies are initialized for more details.)
   PrintingPolicy TypeHintPolicy;
   PrintingPolicy StructuredBindingPolicy;
-
-  static const size_t TypeNameLimit = 32;
 };
 
 } // namespace
Index: clang-tools-extra/clangd/ConfigYAML.cpp
===
--- clang-tools-extra/clangd/ConfigYAML.cpp
+++ clang-tools-extra/clangd/ConfigYAML.cpp
@@ -254,6 +254,10 @@
   if (auto Value = boolValue(N, "Designators"))
 F.Designators = *Value;
 });
+Dict.handle("TypeNameLimit", [&](Node &N) {
+  if (auto Value = scalarValue(N, "TypeNameLimit"))
+F.TypeNameLimit = *Value;
+});
 Dict.parse(N);
   }
 
Index: clang-tools-extra/clangd/ConfigFragment.h
===
--- clang-tools-extra/clangd/ConfigFragment.h
+++ clang-tools-extra/clangd/ConfigFragment.h
@@ -322,6 +322,8 @@
 std::optional> DeducedTypes;
 /// Show designators in aggregate initialization.
 std::optional> Designators;
+/// Limit the length of type name hints.
+std::optional> TypeNameLimit;
   };
   InlayHintsBlock InlayHints;
 };
Index: clang-tools-extra/clangd/ConfigCompile.cpp
===

[PATCH] D146686: [Driver] Fix rpath for compiler-rt

2023-04-01 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked 2 inline comments as done.
yaxunl added inline comments.



Comment at: clang/lib/Driver/ToolChain.cpp:638
+  AddPath({getOSLibName(), llvm::Triple::getArchTypeName(getArch())});
+
+  return Paths;

MaskRay wrote:
> unneeded blank line
will remove when committing


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

https://reviews.llvm.org/D146686

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