[clang] [clang-format] Disable string breaking in JS for now (PR #66372)

2023-09-15 Thread via cfe-commits

https://github.com/eywdck2l closed 
https://github.com/llvm/llvm-project/pull/66372
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] ae90f68 - [clang-format] Disable string breaking in JS for now (#66372)

2023-09-15 Thread via cfe-commits

Author: sstwcw
Date: 2023-09-15T12:36:09Z
New Revision: ae90f689a59fa0ac0b29ca49743757842ba32bf4

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

LOG: [clang-format] Disable string breaking in JS for now (#66372)

See the discussion

[here](https://github.com/llvm/llvm-project/pull/66168#issuecomment-1719038797).

The functionality is not mature enough.

Added: 


Modified: 
clang/docs/ClangFormatStyleOptions.rst
clang/include/clang/Format/Format.h
clang/lib/Format/ContinuationIndenter.cpp
clang/unittests/Format/FormatTestJS.cpp

Removed: 




diff  --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index d5d9faa5c78cffb..4ab0b3a207270dc 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -2783,17 +2783,17 @@ the configuration (without a prefix: ``Auto``).
  const char* x =
  "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
 
-  In C#, Java, and JavaScript:
+  In C# and Java:
 
   .. code-block:: c++
 
  true:
- var x = "veryVeryVeryVeryVeryVe" +
- "ryVeryVeryVeryVeryVery" +
- "VeryLongString";
+ string x = "veryVeryVeryVeryVeryVe" +
+"ryVeryVeryVeryVeryVery" +
+"VeryLongString";
 
  false:
- var x =
+ string x =
  "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
 
   C# and JavaScript interpolated strings are not broken.

diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index c7bd356b7faeded..e78aa62f93cffe1 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2062,19 +2062,19 @@ struct FormatStyle {
   ///"veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
   /// \endcode
   ///
-  /// In C#, Java, and JavaScript:
+  /// In C# and Java:
   /// \code
   ///true:
-  ///var x = "veryVeryVeryVeryVeryVe" +
-  ///"ryVeryVeryVeryVeryVery" +
-  ///"VeryLongString";
+  ///string x = "veryVeryVeryVeryVeryVe" +
+  ///   "ryVeryVeryVeryVeryVery" +
+  ///   "VeryLongString";
   ///
   ///false:
-  ///var x =
+  ///string x =
   ///"veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
   /// \endcode
   ///
-  /// C# and JavaScript interpolated strings are not broken.
+  /// C# interpolated strings are not broken.
   ///
   /// In Verilog:
   /// \code

diff  --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 6673b5c703b835f..17567572f030542 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -2237,15 +2237,10 @@ ContinuationIndenter::createBreakableToken(const 
FormatToken ,
LineState , bool AllowBreak) {
   unsigned StartColumn = State.Column - Current.ColumnWidth;
   if (Current.isStringLiteral()) {
-// Strings in JSON can not be broken.
-if (Style.isJson() || !Style.BreakStringLiterals || !AllowBreak)
-  return nullptr;
-
-// Strings in TypeScript types and dictionary keys can not be broken.
-if (Style.isJavaScript() &&
-(Current.is(TT_SelectorName) ||
- State.Line->startsWith(Keywords.kw_type) ||
- State.Line->startsWith(tok::kw_export, Keywords.kw_type))) {
+// Strings in JSON cannot be broken. Breaking strings in JavaScript is
+// disabled for now.
+if (Style.isJson() || Style.isJavaScript() || !Style.BreakStringLiterals ||
+!AllowBreak) {
   return nullptr;
 }
 

diff  --git a/clang/unittests/Format/FormatTestJS.cpp 
b/clang/unittests/Format/FormatTestJS.cpp
index 51543d0a54d8561..23b010dbc982684 100644
--- a/clang/unittests/Format/FormatTestJS.cpp
+++ b/clang/unittests/Format/FormatTestJS.cpp
@@ -1506,121 +1506,11 @@ TEST_F(FormatTestJS, StringLiteralConcatenation) {
   verifyFormat("var literal = 'hello ' +\n"
"'world';");
 
-  // Long strings should be broken.
+  // String breaking is disabled for now.
   verifyFormat("var literal =\n"
-   "' ' +\n"
-   "'';",
+   "' ';",
"var literal = ' ';",
getGoogleJSStyleWithColumns(17));
-  verifyFormat("var literal =\n"
-   "' ' +\n"
-   "'';",
-   "var literal = ' ';",
-   getGoogleJSStyleWithColumns(18));
-  verifyFormat("var literal =\n"
-   "'' +\n"
-   "' ';",
-   "var literal = ' ';",
-   

[clang] [clang-format] Disable string breaking in JS for now (PR #66372)

2023-09-15 Thread via cfe-commits

https://github.com/sstwcw updated 
https://github.com/llvm/llvm-project/pull/66372

>From a736d84df61e3e7c1a4c8b22c7cd1e7524499d64 Mon Sep 17 00:00:00 2001
From: sstwcw 
Date: Thu, 14 Sep 2023 13:04:56 +
Subject: [PATCH 1/2] [clang-format] Disable string breaking in JS for now

See the discussion
[here](https://github.com/llvm/llvm-project/pull/66168#issuecomment-1719038797).

The functionality is not mature enough.
---
 clang/docs/ClangFormatStyleOptions.rst|  10 +-
 clang/include/clang/Format/Format.h   |  10 +-
 clang/lib/Format/ContinuationIndenter.cpp |  13 +--
 clang/unittests/Format/FormatTestJS.cpp   | 114 +-
 4 files changed, 16 insertions(+), 131 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index d5d9faa5c78cffb..4ab0b3a207270dc 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -2783,17 +2783,17 @@ the configuration (without a prefix: ``Auto``).
  const char* x =
  "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
 
-  In C#, Java, and JavaScript:
+  In C# and Java:
 
   .. code-block:: c++
 
  true:
- var x = "veryVeryVeryVeryVeryVe" +
- "ryVeryVeryVeryVeryVery" +
- "VeryLongString";
+ string x = "veryVeryVeryVeryVeryVe" +
+"ryVeryVeryVeryVeryVery" +
+"VeryLongString";
 
  false:
- var x =
+ string x =
  "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
 
   C# and JavaScript interpolated strings are not broken.
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index c7bd356b7faeded..3bf70838d059086 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2062,15 +2062,15 @@ struct FormatStyle {
   ///"veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
   /// \endcode
   ///
-  /// In C#, Java, and JavaScript:
+  /// In C# and Java:
   /// \code
   ///true:
-  ///var x = "veryVeryVeryVeryVeryVe" +
-  ///"ryVeryVeryVeryVeryVery" +
-  ///"VeryLongString";
+  ///string x = "veryVeryVeryVeryVeryVe" +
+  ///   "ryVeryVeryVeryVeryVery" +
+  ///   "VeryLongString";
   ///
   ///false:
-  ///var x =
+  ///string x =
   ///"veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
   /// \endcode
   ///
diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 6673b5c703b835f..15b9ad41a37af59 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -2237,15 +2237,10 @@ ContinuationIndenter::createBreakableToken(const 
FormatToken ,
LineState , bool AllowBreak) {
   unsigned StartColumn = State.Column - Current.ColumnWidth;
   if (Current.isStringLiteral()) {
-// Strings in JSON can not be broken.
-if (Style.isJson() || !Style.BreakStringLiterals || !AllowBreak)
-  return nullptr;
-
-// Strings in TypeScript types and dictionary keys can not be broken.
-if (Style.isJavaScript() &&
-(Current.is(TT_SelectorName) ||
- State.Line->startsWith(Keywords.kw_type) ||
- State.Line->startsWith(tok::kw_export, Keywords.kw_type))) {
+// Strings in JSON can not be broken. Breaking strings in JavaScript is
+// disabled for now.
+if (Style.isJson() || Style.isJavaScript() || !Style.BreakStringLiterals ||
+!AllowBreak) {
   return nullptr;
 }
 
diff --git a/clang/unittests/Format/FormatTestJS.cpp 
b/clang/unittests/Format/FormatTestJS.cpp
index 51543d0a54d8561..23b010dbc982684 100644
--- a/clang/unittests/Format/FormatTestJS.cpp
+++ b/clang/unittests/Format/FormatTestJS.cpp
@@ -1506,121 +1506,11 @@ TEST_F(FormatTestJS, StringLiteralConcatenation) {
   verifyFormat("var literal = 'hello ' +\n"
"'world';");
 
-  // Long strings should be broken.
+  // String breaking is disabled for now.
   verifyFormat("var literal =\n"
-   "' ' +\n"
-   "'';",
+   "' ';",
"var literal = ' ';",
getGoogleJSStyleWithColumns(17));
-  verifyFormat("var literal =\n"
-   "' ' +\n"
-   "'';",
-   "var literal = ' ';",
-   getGoogleJSStyleWithColumns(18));
-  verifyFormat("var literal =\n"
-   "'' +\n"
-   "' ';",
-   "var literal = ' ';",
-   getGoogleJSStyleWithColumns(16));
-  // The quotes should be correct.
-  for (char OriginalQuote : {'\'', '"'}) {
-auto VerifyQuotes = [=](FormatStyle::JavaScriptQuoteStyle StyleQuote,
-char TargetQuote) {
-

[PATCH] D158415: [Lex] Handle repl_input_end in Preprocessor::LexTokensUntilEOF()

2023-09-15 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld updated this revision to Diff 556849.
Hahnfeld retitled this revision from "[Lex] Handle repl_input_end in 
Preprocessor::LexAll()" to "[Lex] Handle repl_input_end in 
Preprocessor::LexTokensUntilEOF()".
Hahnfeld added a comment.

Rebase on D158413 


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

https://reviews.llvm.org/D158415

Files:
  clang/lib/Lex/Preprocessor.cpp


Index: clang/lib/Lex/Preprocessor.cpp
===
--- clang/lib/Lex/Preprocessor.cpp
+++ clang/lib/Lex/Preprocessor.cpp
@@ -999,7 +999,8 @@
   while (1) {
 Token tok;
 Lex(tok);
-if (tok.isOneOf(tok::unknown, tok::eof, tok::eod))
+if (tok.isOneOf(tok::unknown, tok::eof, tok::eod,
+tok::annot_repl_input_end))
   break;
 if (Tokens != nullptr)
   Tokens->push_back(tok);


Index: clang/lib/Lex/Preprocessor.cpp
===
--- clang/lib/Lex/Preprocessor.cpp
+++ clang/lib/Lex/Preprocessor.cpp
@@ -999,7 +999,8 @@
   while (1) {
 Token tok;
 Lex(tok);
-if (tok.isOneOf(tok::unknown, tok::eof, tok::eod))
+if (tok.isOneOf(tok::unknown, tok::eof, tok::eod,
+tok::annot_repl_input_end))
   break;
 if (Tokens != nullptr)
   Tokens->push_back(tok);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158414: [LexerTest] Use LexTokensUntilEOF() in StringifyArgs

2023-09-15 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld updated this revision to Diff 556848.
Hahnfeld retitled this revision from "[LexerTest] Use LexAll() in 
StringifyArgs" to "[LexerTest] Use LexTokensUntilEOF() in StringifyArgs".
Hahnfeld edited the summary of this revision.

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

https://reviews.llvm.org/D158414

Files:
  clang/unittests/Lex/LexerTest.cpp


Index: clang/unittests/Lex/LexerTest.cpp
===
--- clang/unittests/Lex/LexerTest.cpp
+++ clang/unittests/Lex/LexerTest.cpp
@@ -451,18 +451,15 @@
   Token Eof;
   Eof.setKind(tok::eof);
   std::vector ArgTokens;
-  while (1) {
-Token tok;
-PP->Lex(tok);
-if (tok.is(tok::eof)) {
-  ArgTokens.push_back(Eof);
-  break;
+  PP->LexTokensUntilEOF();
+  // Replace all tok::comma with tok::eof for stringification.
+  for (auto  : ArgTokens) {
+if (tok.is(tok::comma)) {
+  tok = Eof;
 }
-if (tok.is(tok::comma))
-  ArgTokens.push_back(Eof);
-else
-  ArgTokens.push_back(tok);
   }
+  // Push a tok::eof as the last element.
+  ArgTokens.push_back(Eof);
 
   auto MacroArgsDeleter = [](MacroArgs *M) { M->destroy(*PP); };
   std::unique_ptr MA(


Index: clang/unittests/Lex/LexerTest.cpp
===
--- clang/unittests/Lex/LexerTest.cpp
+++ clang/unittests/Lex/LexerTest.cpp
@@ -451,18 +451,15 @@
   Token Eof;
   Eof.setKind(tok::eof);
   std::vector ArgTokens;
-  while (1) {
-Token tok;
-PP->Lex(tok);
-if (tok.is(tok::eof)) {
-  ArgTokens.push_back(Eof);
-  break;
+  PP->LexTokensUntilEOF();
+  // Replace all tok::comma with tok::eof for stringification.
+  for (auto  : ArgTokens) {
+if (tok.is(tok::comma)) {
+  tok = Eof;
 }
-if (tok.is(tok::comma))
-  ArgTokens.push_back(Eof);
-else
-  ArgTokens.push_back(tok);
   }
+  // Push a tok::eof as the last element.
+  ArgTokens.push_back(Eof);
 
   auto MacroArgsDeleter = [](MacroArgs *M) { M->destroy(*PP); };
   std::unique_ptr MA(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][dataflow] Add a test for context-sensitive analysis on a self-referential class. (PR #66359)

2023-09-15 Thread via cfe-commits

https://github.com/martinboehme closed 
https://github.com/llvm/llvm-project/pull/66359
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 0069004 - [clang][dataflow] Add a test for context-sensitive analysis on a self-referential class. (#66359)

2023-09-15 Thread via cfe-commits

Author: martinboehme
Date: 2023-09-15T14:31:10+02:00
New Revision: 0069004856dd216ffed48a860a38b986dfe3e871

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

LOG: [clang][dataflow] Add a test for context-sensitive analysis on a 
self-referential class. (#66359)

The test demonstrates that the `this` pointer seen in the constructor
has the
same value as the address of the variable the object is constructed
into.

Added: 


Modified: 
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Removed: 




diff  --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index e0e3b71503d2176..cdb1bc3cd16ac7b 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -5481,6 +5481,41 @@ TEST(TransferTest, ContextSensitiveConstructorDefault) {
   {BuiltinOptions{ContextSensitiveOptions{}}});
 }
 
+TEST(TransferTest, ContextSensitiveSelfReferentialClass) {
+  // Test that the `this` pointer seen in the constructor has the same value
+  // as the address of the variable the object is constructed into.
+  std::string Code = R"(
+class MyClass {
+public:
+  MyClass() : Self(this) {}
+  MyClass *Self;
+};
+
+void target() {
+  MyClass MyObj;
+  MyClass *SelfPtr = MyObj.Self;
+  // [[p]]
+}
+  )";
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> ,
+ ASTContext ) {
+ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+
+const ValueDecl *MyObjDecl = findValueDecl(ASTCtx, "MyObj");
+ASSERT_THAT(MyObjDecl, NotNull());
+
+const ValueDecl *SelfDecl = findValueDecl(ASTCtx, "SelfPtr");
+ASSERT_THAT(SelfDecl, NotNull());
+
+const Environment  = getEnvironmentAtAnnotation(Results, "p");
+auto  = *cast(Env.getValue(*SelfDecl));
+EXPECT_EQ(Env.getStorageLocation(*MyObjDecl), 
());
+  },
+  {BuiltinOptions{ContextSensitiveOptions{}}});
+}
+
 TEST(TransferTest, UnnamedBitfieldInitializer) {
   std::string Code = R"(
 struct B {};



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


[clang] [clang][AST] fix lack comparison of declRefExpr in ASTStructuralEquivalence (PR #66041)

2023-09-15 Thread Ding Fei via cfe-commits

danix800 wrote:

LGTM! If no further comment I'll merge this in a day or two.

https://github.com/llvm/llvm-project/pull/66041
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [dataflow] Parse formulas from text (PR #66424)

2023-09-15 Thread Yitzhak Mandelbaum via cfe-commits

https://github.com/ymand approved this pull request.


https://github.com/llvm/llvm-project/pull/66424
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [dataflow] Parse formulas from text (PR #66424)

2023-09-15 Thread Yitzhak Mandelbaum via cfe-commits


@@ -87,6 +87,9 @@ class alignas(const Formula *) Formula {
  ArrayRef Operands,
  unsigned Value = 0);
 
+  // Parse Formulas using Arena rather than caling this function directly.

ymand wrote:

nit: Maybe prefix with "note:" or somesuch? I started reading this as a 
description of the function.

https://github.com/llvm/llvm-project/pull/66424
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [dataflow] Parse formulas from text (PR #66424)

2023-09-15 Thread Yitzhak Mandelbaum via cfe-commits

https://github.com/ymand edited https://github.com/llvm/llvm-project/pull/66424
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-transformer] Allow stencils to read from system headers. (PR #66480)

2023-09-15 Thread Yitzhak Mandelbaum via cfe-commits


@@ -230,7 +230,7 @@ class SelectorStencil : public StencilInterface {
   // message. If it's valid, then something else is the cause and we just
   // return the generic failure message.
   if (auto Err =
-  tooling::validateEditRange(*RawRange, *Match.SourceManager))
+  tooling::validateRange(*RawRange, *Match.SourceManager, true))

ymand wrote:

Please use `/*AllowSystemHeaders=*/` before `true`, here and below.

https://github.com/llvm/llvm-project/pull/66480
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-transformer] Allow stencils to read from system headers. (PR #66480)

2023-09-15 Thread Yitzhak Mandelbaum via cfe-commits


@@ -91,6 +91,10 @@ StringRef getExtendedText(const T , tok::TokenKind Next,
 llvm::Error validateEditRange(const CharSourceRange ,
   const SourceManager );
 
+/// Determines whether \p Range is one that can be read from.
+llvm::Error validateRange(const CharSourceRange , const SourceManager 
,
+  bool AllowSystemHeaders);

ymand wrote:

Please explain `AllowSystemHeaders` in the comments. May not be totally obvious.

https://github.com/llvm/llvm-project/pull/66480
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-transformer] Allow stencils to read from system headers. (PR #66480)

2023-09-15 Thread Yitzhak Mandelbaum via cfe-commits

https://github.com/ymand requested changes to this pull request.


https://github.com/llvm/llvm-project/pull/66480
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-transformer] Allow stencils to read from system headers. (PR #66480)

2023-09-15 Thread Yitzhak Mandelbaum via cfe-commits

https://github.com/ymand edited https://github.com/llvm/llvm-project/pull/66480
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Bugfix for chosing the correct deduction guide (PR #66487)

2023-09-15 Thread via cfe-commits

https://github.com/HoBoIs edited https://github.com/llvm/llvm-project/pull/66487
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Bugfix for chosing the correct deduction guide (PR #66487)

2023-09-15 Thread via cfe-commits


@@ -2129,7 +2129,7 @@ Decl *TemplateDeclInstantiator::VisitFunctionDecl(
 Function = CXXDeductionGuideDecl::Create(
 SemaRef.Context, DC, D->getInnerLocStart(),
 InstantiatedExplicitSpecifier, NameInfo, T, TInfo,
-D->getSourceRange().getEnd(), /*Ctor=*/nullptr,
+D->getSourceRange().getEnd(), DGuide->getCorrespondingConstructor(),

HoBoIs wrote:

I'm a new developer, can someone with more experience in clang check if this 
can never cause a use after free.

https://github.com/llvm/llvm-project/pull/66487
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Interp] Handle AttributedStmts (PR #66495)

2023-09-15 Thread via cfe-commits


@@ -628,6 +630,12 @@ bool ByteCodeStmtGen::visitAsmStmt(const AsmStmt 
*S) {
   return this->emitInvalid(S);
 }
 
+template 
+bool ByteCodeStmtGen::visitAttributedStmt(const AttributedStmt *S) {
+  // Ignore all attributes.

cor3ntin wrote:

We can add a fix me but i wouldn't worry about it too much, until we have a 
clearer idea of what we do, which we really don't atm
And the wording is clear that this is unspecified either way.

And for vendor attributes, it would only make sense to check them if we want 
them to fail the evaluation, do we have such things?

https://github.com/llvm/llvm-project/pull/66495
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Bugfix for chosing the correct deduction guide (PR #66487)

2023-09-15 Thread via cfe-commits

https://github.com/HoBoIs updated 
https://github.com/llvm/llvm-project/pull/66487

>From 258462cc65403af147bb47cbeb95210df8e18cd3 Mon Sep 17 00:00:00 2001
From: hobois 
Date: Fri, 15 Sep 2023 09:28:21 +0200
Subject: [PATCH] Choose the correct deduction guide

If there are two guides, one of them generated from a non-templated constructor
and the other from a templated constructor, then the standard gives priority to
the first. Clang detected ambiguity before, now the correct guide is chosen.

As an unrelated minor change, fix the issue #64020, which could've led to
incorrect behavior if further development inserted code after a call to
isAddressSpaceSubsetOf() which specified the two parameters in the wrong order.
---
 clang/lib/Sema/SemaOverload.cpp | 17 -
 clang/lib/Sema/SemaTemplateInstantiateDecl.cpp  |  2 +-
 .../over.match.class.deduct/p2.cpp  | 10 ++
 3 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 45a9e5dc98c032d..1bb81238520173a 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -10153,6 +10153,21 @@ bool clang::isBetterOverloadCandidate(
   //  -- F1 is the copy deduction candidate(16.3.1.8) and F2 is not
   if (Guide1->getDeductionCandidateKind() == DeductionCandidate::Copy)
 return true;
+  if (Guide2->getDeductionCandidateKind() == DeductionCandidate::Copy)
+return false;
+
+  //  --F1 is generated from a non-template constructor and F2 is generated
+  //  from a constructor template
+  const auto *Constructor1 = Guide1->getCorrespondingConstructor();
+  const auto *Constructor2 = Guide2->getCorrespondingConstructor();
+  if (Constructor1 && Constructor2) {
+bool isC1Templated = Constructor1->getTemplatedKind() !=
+ FunctionDecl::TemplatedKind::TK_NonTemplate;
+bool isC2Templated = Constructor2->getTemplatedKind() !=
+ FunctionDecl::TemplatedKind::TK_NonTemplate;
+if (isC1Templated != isC2Templated)
+  return isC2Templated;
+  }
 }
   }
 
@@ -10196,7 +10211,7 @@ bool clang::isBetterOverloadCandidate(
 if (AS1 != AS2) {
   if (Qualifiers::isAddressSpaceSupersetOf(AS2, AS1))
 return true;
-  if (Qualifiers::isAddressSpaceSupersetOf(AS2, AS1))
+  if (Qualifiers::isAddressSpaceSupersetOf(AS1, AS2))
 return false;
 }
   }
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 9e5f85b0f9166bd..b9c4a9db842b9ee 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -2129,7 +2129,7 @@ Decl *TemplateDeclInstantiator::VisitFunctionDecl(
 Function = CXXDeductionGuideDecl::Create(
 SemaRef.Context, DC, D->getInnerLocStart(),
 InstantiatedExplicitSpecifier, NameInfo, T, TInfo,
-D->getSourceRange().getEnd(), /*Ctor=*/nullptr,
+D->getSourceRange().getEnd(), DGuide->getCorrespondingConstructor(),
 DGuide->getDeductionCandidateKind());
 Function->setAccess(D->getAccess());
   } else {
diff --git 
a/clang/test/CXX/over/over.match/over.match.funcs/over.match.class.deduct/p2.cpp
 
b/clang/test/CXX/over/over.match/over.match.funcs/over.match.class.deduct/p2.cpp
index 4eac0a1ac510f1d..d939d724dc7a0fd 100644
--- 
a/clang/test/CXX/over/over.match/over.match.funcs/over.match.class.deduct/p2.cpp
+++ 
b/clang/test/CXX/over/over.match/over.match.funcs/over.match.class.deduct/p2.cpp
@@ -85,3 +85,13 @@ int main() {
 
 
 }
+
+namespace deduceTemplatedConstructor{
+template  struct A {
+  A(T, T, int);
+  template
+A(int, T, U);
+};
+
+A x(1, 2, 3);   // no-error
+}

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


[clang] [analyzer] Simplify SVal for simple NonLoc->Loc casts (PR #66498)

2023-09-15 Thread Ding Fei via cfe-commits

https://github.com/danix800 edited 
https://github.com/llvm/llvm-project/pull/66498
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Simplify SVal for simple NonLoc->Loc casts (PR #66498)

2023-09-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-static-analyzer-1


Changes
NonLoc symbolic SVal to Loc casts are not supported except for 
nonloc::ConcreteInt.

This change simplifies the source SVals so that the more casts can go through 
nonloc::ConcreteInt->loc::ConcreteInt path. For example:

  void test_simplified_before_cast_add(long long t1) {
long long t2 = t1 + 3;
if (!t2) {
  int *p = (int *) t2;
  clang_analyzer_eval(p == 0); // expected-warning{{TRUE}}
}
  }

If simplified, 't2' is 0, resulting 'p' is nullptr, otherwise 'p' is unknown.

Fixes #62232
--
Full diff: https://github.com/llvm/llvm-project/pull/66498.diff

2 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp (+2-1) 
- (modified) clang/test/Analysis/symbol-simplification-nonloc-loc.cpp (+27-1) 



diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp 
b/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
index 2a47116db55a1ad..7e431f7e598c4cb 100644
--- a/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
@@ -264,7 +264,8 @@ ProgramStateRef ExprEngine::handleLValueBitCast(
   }
   // Delegate to SValBuilder to process.
   SVal OrigV = state-gt;getSVal(Ex, LCtx);
-  SVal V = svalBuilder.evalCast(OrigV, T, ExTy);
+  SVal SimplifiedOrigV = svalBuilder.simplifySVal(state, OrigV);
+  SVal V = svalBuilder.evalCast(SimplifiedOrigV, T, ExTy);
   // Negate the result if we#x27;re treating the boolean as a signed i1
   if (CastE-gt;getCastKind() == CK_BooleanToSignedIntegral 
amp;amp; V.isValid())
 V = svalBuilder.evalMinus(V.castAslt;NonLocgt;());
diff --git a/clang/test/Analysis/symbol-simplification-nonloc-loc.cpp 
b/clang/test/Analysis/symbol-simplification-nonloc-loc.cpp
index 485f68d9a5acfba..6cfe8da971429c3 100644
--- a/clang/test/Analysis/symbol-simplification-nonloc-loc.cpp
+++ b/clang/test/Analysis/symbol-simplification-nonloc-loc.cpp
@@ -1,6 +1,8 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=core %s \
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection %s \
 // RUN:-triple x86_64-pc-linux-gnu -verify
 
+void clang_analyzer_eval(int);
+
 #define BINOP(OP) [](auto x, auto y) { return x OP y; }
 
 template lt;typename BinOpgt;
@@ -73,3 +75,27 @@ void zoo1backwards() {
   *(0 + p) = nullptr;  // warn
   **(0 + p) = #x27;a#x27;; // no-warning: this should be 
unreachable
 }
+
+void test_simplified_before_cast_add(long t1) {
+  long t2 = t1 + 3;
+  if (!t2) {
+int *p = (int *) t2;
+clang_analyzer_eval(p == 0); // expected-warning{{TRUE}}
+  }
+}
+
+void test_simplified_before_cast_sub(long t1) {
+  long t2 = t1 - 3;
+  if (!t2) {
+int *p = (int *) t2;
+clang_analyzer_eval(p == 0); // expected-warning{{TRUE}}
+  }
+}
+
+void test_simplified_before_cast_mul(long t1) {
+  long t2 = t1 * 3;
+  if (!t2) {
+int *p = (int *) t2;
+clang_analyzer_eval(p == 0); // expected-warning{{TRUE}}
+  }
+}




https://github.com/llvm/llvm-project/pull/66498
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Simplify SVal for simple NonLoc->Loc casts (PR #66463)

2023-09-15 Thread Ding Fei via cfe-commits

danix800 wrote:

Fixed and resubmited #66498

https://github.com/llvm/llvm-project/pull/66463
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Simplify SVal for simple NonLoc->Loc casts (PR #66498)

2023-09-15 Thread Ding Fei via cfe-commits

https://github.com/danix800 created 
https://github.com/llvm/llvm-project/pull/66498

NonLoc symbolic SVal to Loc casts are not supported except for 
nonloc::ConcreteInt.

This change simplifies the source SVals so that the more casts can go through 
nonloc::ConcreteInt->loc::ConcreteInt path. For example:

  void test_simplified_before_cast_add(long long t1) {
long long t2 = t1 + 3;
if (!t2) {
  int *p = (int *) t2;
  clang_analyzer_eval(p == 0); // expected-warning{{TRUE}}
}
  }

If simplified, 't2' is 0, resulting 'p' is nullptr, otherwise 'p' is unknown.

Fixes #62232

>From 0b776deb2bbd4d03325b02680eb99c788d3bc37d Mon Sep 17 00:00:00 2001
From: dingfei 
Date: Fri, 15 Sep 2023 14:01:26 +0800
Subject: [PATCH] [analyzer] Simplify SVal for simple NonLoc->Loc casts

NonLoc symbolic SVal to Loc casts are not supported except for
nonloc::ConcreteInt.

This change simplifies the source SVals so that the more casts can
go through nonloc::ConcreteInt->loc::ConcreteInt path. For example:

  void test_simplified_before_cast_add(long long t1) {
long long t2 = t1 + 3;
if (!t2) {
  int *p = (int *) t2;
  clang_analyzer_eval(p == 0); // expected-warning{{TRUE}}
}
  }

If simplified, 't2' is 0, resulting 'p' is nullptr, otherwise 'p'
is unknown.

Fixes #62232
---
 clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp |  3 +-
 .../symbol-simplification-nonloc-loc.cpp  | 28 ++-
 2 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp 
b/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
index 2a47116db55a1ad..7e431f7e598c4cb 100644
--- a/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
@@ -264,7 +264,8 @@ ProgramStateRef ExprEngine::handleLValueBitCast(
   }
   // Delegate to SValBuilder to process.
   SVal OrigV = state->getSVal(Ex, LCtx);
-  SVal V = svalBuilder.evalCast(OrigV, T, ExTy);
+  SVal SimplifiedOrigV = svalBuilder.simplifySVal(state, OrigV);
+  SVal V = svalBuilder.evalCast(SimplifiedOrigV, T, ExTy);
   // Negate the result if we're treating the boolean as a signed i1
   if (CastE->getCastKind() == CK_BooleanToSignedIntegral && V.isValid())
 V = svalBuilder.evalMinus(V.castAs());
diff --git a/clang/test/Analysis/symbol-simplification-nonloc-loc.cpp 
b/clang/test/Analysis/symbol-simplification-nonloc-loc.cpp
index 485f68d9a5acfba..6cfe8da971429c3 100644
--- a/clang/test/Analysis/symbol-simplification-nonloc-loc.cpp
+++ b/clang/test/Analysis/symbol-simplification-nonloc-loc.cpp
@@ -1,6 +1,8 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=core %s \
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection %s \
 // RUN:-triple x86_64-pc-linux-gnu -verify
 
+void clang_analyzer_eval(int);
+
 #define BINOP(OP) [](auto x, auto y) { return x OP y; }
 
 template 
@@ -73,3 +75,27 @@ void zoo1backwards() {
   *(0 + p) = nullptr;  // warn
   **(0 + p) = 'a'; // no-warning: this should be unreachable
 }
+
+void test_simplified_before_cast_add(long t1) {
+  long t2 = t1 + 3;
+  if (!t2) {
+int *p = (int *) t2;
+clang_analyzer_eval(p == 0); // expected-warning{{TRUE}}
+  }
+}
+
+void test_simplified_before_cast_sub(long t1) {
+  long t2 = t1 - 3;
+  if (!t2) {
+int *p = (int *) t2;
+clang_analyzer_eval(p == 0); // expected-warning{{TRUE}}
+  }
+}
+
+void test_simplified_before_cast_mul(long t1) {
+  long t2 = t1 * 3;
+  if (!t2) {
+int *p = (int *) t2;
+clang_analyzer_eval(p == 0); // expected-warning{{TRUE}}
+  }
+}

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


[clang] Introduce paged vector (PR #66430)

2023-09-15 Thread Giulio Eulisse via cfe-commits

ktf wrote:

@s-barannikov, AFAICT, that would not work because the overwrite is not 
unconditional, but it will actually check for default initialised content. 
Basically the current mechanics relies on default initialisation rather than 
being "uninitialised". This for sure does not work with LoadedDecls (I just 
checked). 

I even thought to have a `std::pmr::vector` backed by `calloc`, so that 
uninitialised parts are guaranteed to be zero-ed. However in the end I 
considered such implementation more complicated and I went for what I have in 
this PR (especially because I am not sure `std::pmr*` are actually allowed in 
the codebase).

Besides the above considerations, at least for my use case, I also noticed the 
page granularity is actually not good enough to guarantee good memory savings 
(that's why I use 1024 / sizeof(T)).

https://github.com/llvm/llvm-project/pull/66430
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Interp] Handle AttributedStmts (PR #66495)

2023-09-15 Thread Aaron Ballman via cfe-commits


@@ -628,6 +630,12 @@ bool ByteCodeStmtGen::visitAsmStmt(const AsmStmt 
*S) {
   return this->emitInvalid(S);
 }
 
+template 
+bool ByteCodeStmtGen::visitAttributedStmt(const AttributedStmt *S) {
+  // Ignore all attributes.

AaronBallman wrote:

Is this what we want to do for `[[assume]]`? We can do it this way: 
https://eel.is/c++draft/expr.const#5.8 but we can also do it better: 
https://eel.is/c++draft/expr.const#5.33

CC @erichkeane @cor3ntin

(We don't support assumptions yet, so I think the code is fine as-is, but I'm 
wondering if we want to add a FIXME here about `[[assume]]`. We should also see 
if any of our vendor statement attributes have UB we need to consider as well.)

https://github.com/llvm/llvm-project/pull/66495
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Fix StackAddrEscapeChecker crash on temporary object fields (PR #66493)

2023-09-15 Thread via cfe-commits

https://github.com/DonatNagyE approved this pull request.

Nice bugfix; I have only one tangential remark.

https://github.com/llvm/llvm-project/pull/66493
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Fix StackAddrEscapeChecker crash on temporary object fields (PR #66493)

2023-09-15 Thread via cfe-commits


@@ -398,7 +400,7 @@ void StackAddrEscapeChecker::checkEndFunction(const 
ReturnStmt *RS,
 }(Referrer->getMemorySpace());
 
 // This cast supposed to succeed.

DonatNagyE wrote:

Perhaps explain why will the cast succeed (or, alternatively, just remove this 
meaningless comment).

https://github.com/llvm/llvm-project/pull/66493
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Fix StackAddrEscapeChecker crash on temporary object fields (PR #66493)

2023-09-15 Thread via cfe-commits

https://github.com/DonatNagyE edited 
https://github.com/llvm/llvm-project/pull/66493
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][docs] Pass full path of source TD file to gen_rst_from_td. [NFC] (PR #66497)

2023-09-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang


Changes
This change is needed to be able to refer to TD files that are not stored in 
${CMAKE_CURRENT_SOURCE_DIR}.
--
Full diff: https://github.com/llvm/llvm-project/pull/66497.diff

1 Files Affected:

- (modified) clang/docs/CMakeLists.txt (+6-7) 



diff --git a/clang/docs/CMakeLists.txt b/clang/docs/CMakeLists.txt
index 4163dd2d90ad5b3..a63823c63428288 100644
--- a/clang/docs/CMakeLists.txt
+++ b/clang/docs/CMakeLists.txt
@@ -91,10 +91,10 @@ endif()
 endif()
 
 function (gen_rst_file_from_td output_file td_option source docs_targets)
-  if (NOT EXISTS quot;${CMAKE_CURRENT_SOURCE_DIR}/${source}quot;)
-message(FATAL_ERROR quot;Cannot find source file: ${source} in 
${CMAKE_CURRENT_SOURCE_DIR}quot;)
+  if (NOT EXISTS quot;${source}quot;)
+message(FATAL_ERROR quot;Cannot find source file: ${source}quot;)
   endif()
-  get_filename_component(TABLEGEN_INCLUDE_DIR 
quot;${CMAKE_CURRENT_SOURCE_DIR}/${source}quot; DIRECTORY)
+  get_filename_component(TABLEGEN_INCLUDE_DIR quot;${source}quot; 
DIRECTORY)
   list(APPEND LLVM_TABLEGEN_FLAGS 
quot;-I${TABLEGEN_INCLUDE_DIR}quot;)
   clang_tablegen(${output_file} ${td_option} SOURCE ${source} TARGET 
quot;gen-${output_file}quot;)
   foreach(target ${docs_targets})
@@ -138,10 +138,9 @@ if (LLVM_ENABLE_SPHINX)
 endif()
 
 # Generated files
-gen_rst_file_from_td(AttributeReference.rst -gen-attr-docs 
../include/clang/Basic/Attr.td quot;${docs_targets}quot;)
-gen_rst_file_from_td(DiagnosticsReference.rst -gen-diag-docs 
../include/clang/Basic/Diagnostic.td quot;${docs_targets}quot;)
-gen_rst_file_from_td(ClangCommandLineReference.rst -gen-opt-docs 
../include/clang/Driver/ClangOptionDocs.td quot;${docs_targets}quot;)
-
+gen_rst_file_from_td(AttributeReference.rst -gen-attr-docs 
${CMAKE_CURRENT_SOURCE_DIR}/../include/clang/Basic/Attr.td 
quot;${docs_targets}quot;)
+gen_rst_file_from_td(DiagnosticsReference.rst -gen-diag-docs 
${CMAKE_CURRENT_SOURCE_DIR}/../include/clang/Basic/Diagnostic.td 
quot;${docs_targets}quot;)
+gen_rst_file_from_td(ClangCommandLineReference.rst -gen-opt-docs 
${CMAKE_CURRENT_SOURCE_DIR}/../include/clang/Driver/ClangOptionDocs.td 
quot;${docs_targets}quot;)
 foreach(target ${docs_targets})
   add_dependencies(${target} copy-clang-rst-docs)
 endforeach()




https://github.com/llvm/llvm-project/pull/66497
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][docs] Pass full path of source TD file to gen_rst_from_td. [NFC] (PR #66497)

2023-09-15 Thread Francesco Petrogalli via cfe-commits

https://github.com/fpetrogalli created 
https://github.com/llvm/llvm-project/pull/66497

This change is needed to be able to refer to TD files that are not stored in 
${CMAKE_CURRENT_SOURCE_DIR}.

>From 1887649a491b353f4e6a9a318fa2b150db268868 Mon Sep 17 00:00:00 2001
From: Francesco Petrogalli 
Date: Fri, 15 Sep 2023 10:56:29 +0200
Subject: [PATCH] [clang][docs] Pass full path of source TD file to
 gen_rst_from_td. [NFC]

This change is needed to be able to refer to TD files that are not
stored in ${CMAKE_CURRENT_SOURCE_DIR}.
---
 clang/docs/CMakeLists.txt | 13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/clang/docs/CMakeLists.txt b/clang/docs/CMakeLists.txt
index 4163dd2d90ad5b3..a63823c63428288 100644
--- a/clang/docs/CMakeLists.txt
+++ b/clang/docs/CMakeLists.txt
@@ -91,10 +91,10 @@ endif()
 endif()
 
 function (gen_rst_file_from_td output_file td_option source docs_targets)
-  if (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${source}")
-message(FATAL_ERROR "Cannot find source file: ${source} in 
${CMAKE_CURRENT_SOURCE_DIR}")
+  if (NOT EXISTS "${source}")
+message(FATAL_ERROR "Cannot find source file: ${source}")
   endif()
-  get_filename_component(TABLEGEN_INCLUDE_DIR 
"${CMAKE_CURRENT_SOURCE_DIR}/${source}" DIRECTORY)
+  get_filename_component(TABLEGEN_INCLUDE_DIR "${source}" DIRECTORY)
   list(APPEND LLVM_TABLEGEN_FLAGS "-I${TABLEGEN_INCLUDE_DIR}")
   clang_tablegen(${output_file} ${td_option} SOURCE ${source} TARGET 
"gen-${output_file}")
   foreach(target ${docs_targets})
@@ -138,10 +138,9 @@ if (LLVM_ENABLE_SPHINX)
 endif()
 
 # Generated files
-gen_rst_file_from_td(AttributeReference.rst -gen-attr-docs 
../include/clang/Basic/Attr.td "${docs_targets}")
-gen_rst_file_from_td(DiagnosticsReference.rst -gen-diag-docs 
../include/clang/Basic/Diagnostic.td "${docs_targets}")
-gen_rst_file_from_td(ClangCommandLineReference.rst -gen-opt-docs 
../include/clang/Driver/ClangOptionDocs.td "${docs_targets}")
-
+gen_rst_file_from_td(AttributeReference.rst -gen-attr-docs 
${CMAKE_CURRENT_SOURCE_DIR}/../include/clang/Basic/Attr.td "${docs_targets}")
+gen_rst_file_from_td(DiagnosticsReference.rst -gen-diag-docs 
${CMAKE_CURRENT_SOURCE_DIR}/../include/clang/Basic/Diagnostic.td 
"${docs_targets}")
+gen_rst_file_from_td(ClangCommandLineReference.rst -gen-opt-docs 
${CMAKE_CURRENT_SOURCE_DIR}/../include/clang/Driver/ClangOptionDocs.td 
"${docs_targets}")
 foreach(target ${docs_targets})
   add_dependencies(${target} copy-clang-rst-docs)
 endforeach()

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


[clang] [Clang] Handle consteval expression in array bounds expressions (PR #66222)

2023-09-15 Thread Takuya Shimizu via cfe-commits

hazohelet wrote:

> I'll add a test. immediate contexts are recursive, constant evaluated 
> contexts are not, i don't think there is a case where you would get an 
> additional evaluation context that is not for a full expression, and if you 
> have a full expression you do expect the immediate invocation to be called 
> anyway - eg, lambda case.

It turns out I was misunderstanding the standard about the recursiveness of 
constant-evaluated-context. I found a flaw in my patch that comes from it 
(pushing constant-evaluated context upon lambda body if it happens in 
constant-evaluated context). Thanks!

https://github.com/llvm/llvm-project/pull/66222
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 73371fa - [clang][Interp][NFC] Remove unused includes

2023-09-15 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-09-15T13:37:35+02:00
New Revision: 73371faf05887fbe84916456b7c200b07978e7b5

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

LOG: [clang][Interp][NFC] Remove unused includes

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeStmtGen.cpp
clang/lib/AST/Interp/ByteCodeStmtGen.h

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp 
b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
index b7553d8963ff0ee..5beb5c3d22b4f64 100644
--- a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -12,9 +12,6 @@
 #include "Context.h"
 #include "Function.h"
 #include "PrimType.h"
-#include "Program.h"
-#include "State.h"
-#include "clang/Basic/LLVM.h"
 
 using namespace clang;
 using namespace clang::interp;

diff  --git a/clang/lib/AST/Interp/ByteCodeStmtGen.h 
b/clang/lib/AST/Interp/ByteCodeStmtGen.h
index 278e804a803c951..5d48c0d27d245eb 100644
--- a/clang/lib/AST/Interp/ByteCodeStmtGen.h
+++ b/clang/lib/AST/Interp/ByteCodeStmtGen.h
@@ -16,11 +16,7 @@
 #include "ByteCodeEmitter.h"
 #include "ByteCodeExprGen.h"
 #include "EvalEmitter.h"
-#include "Pointer.h"
 #include "PrimType.h"
-#include "Record.h"
-#include "clang/AST/Decl.h"
-#include "clang/AST/Expr.h"
 #include "clang/AST/StmtVisitor.h"
 
 namespace clang {



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


[PATCH] D147844: [clang][Sema]Print diagnostic warning about precedence when integer expression is used without parentheses in an conditional operator expression

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

In D147844#4641735 , @ldionne wrote:

> Ping. What's missing to land this?

Folks have raised enough concerns about chattiness on the thread that I think 
we should not move forward without more evidence that the changes will find new 
true positives. I'm marking this as requesting changes so the review gets out 
of people's Phab queues, but the "changes" are largely about what evidence we 
find.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

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


[clang] Introduce paged vector (PR #66430)

2023-09-15 Thread Sergei Barannikov via cfe-commits

s-barannikov wrote:

> Why don't just turn SLocEntry into a POD (if it is not yet already) and use 
> SmallVector::resize_for_overwrite? That way the vector will not be 
> initialized and the OS will only allocate physical memory on the first access 
> to a page.

Never mind, it isn't "just", the class is more complex than it looks, and there 
is also QualType.
Still, the introduced class partially repeats the work done by the operating 
system, that is allocating pages on first access.
I can't suggest how this fact can be used though.

https://github.com/llvm/llvm-project/pull/66430
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NVPTX] Add support for maxclusterrank in launch_bounds (PR #66496)

2023-09-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang


Changes
Since SM_90 CUDA supports specifying additional argument to the launch_bounds 
attribute: maxBlocksPerCluster, to express the maximum number of CTAs that can 
be part of the cluster. See: 
https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#cluster-dimension-directives-maxclusterrank
 and
https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#launch-bounds 
for details.
--

Patch is 24.44 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/66496.diff

13 Files Affected:

- (modified) clang/include/clang/Basic/Attr.td (+2-1) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+4) 
- (modified) clang/include/clang/Sema/Sema.h (+3-2) 
- (modified) clang/lib/CodeGen/Targets/NVPTX.cpp (+10-2) 
- (modified) clang/lib/Parse/ParseOpenMP.cpp (+2-1) 
- (modified) clang/lib/Sema/SemaDeclAttr.cpp (+39-7) 
- (modified) clang/lib/Sema/SemaTemplateInstantiateDecl.cpp (+9-1) 
- (modified) clang/test/CodeGenCUDA/launch-bounds.cu (+69) 
- (modified) clang/test/SemaCUDA/launch_bounds.cu (+3-1) 
- (added) clang/test/SemaCUDA/launch_bounds_sm_90.cu (+45) 
- (modified) llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp (+36-43) 
- (modified) llvm/lib/Target/NVPTX/NVPTXUtilities.cpp (+4) 
- (modified) llvm/lib/Target/NVPTX/NVPTXUtilities.h (+1) 



diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index c95db7e8049d47a..3c51261bd3eb081 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1267,7 +1267,8 @@ def CUDAInvalidTarget : InheritableAttr {
 
 def CUDALaunchBounds : InheritableAttr {
   let Spellings = [GNUlt;quot;launch_boundsquot;gt;, 
Declspeclt;quot;__launch_bounds__quot;gt;];
-  let Args = [ExprArgumentlt;quot;MaxThreadsquot;gt;, 
ExprArgumentlt;quot;MinBlocksquot;, 1gt;];
+  let Args = [ExprArgumentlt;quot;MaxThreadsquot;gt;, 
ExprArgumentlt;quot;MinBlocksquot;, 1gt;,
+  ExprArgumentlt;quot;MaxBlocksquot;, 1gt;];
   let LangOpts = [CUDA];
   let Subjects = SubjectListlt;[ObjCMethod, FunctionLike]gt;;
   // An AST node is created for this attribute, but is not used by other parts
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 0ac4df8edb242f6..088e3a45c7babba 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11836,6 +11836,10 @@ def err_sycl_special_type_num_init_method : 
Errorlt;
   quot;types with #x27;sycl_special_class#x27; attribute must 
have one and only one #x27;__init#x27; quot;
   quot;method definedquot;gt;;
 
+def warn_cuda_maxclusterrank_sm_90 : Warninglt;
+  quot;maxclusterrank requires sm_90 or higher, CUDA arch provided: %0, 
ignoring quot;
+  quot;%1 attributequot;gt;, 
InGrouplt;IgnoredAttributesgt;;
+
 def err_bit_int_bad_size : Errorlt;quot;%select{signed|unsigned}0 
_BitInt must quot;
  quot;have a bit size of at least 
%select{2|1}0quot;gt;;
 def err_bit_int_max_size : Errorlt;quot;%select{signed|unsigned}0 
_BitInt of bit quot;
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 47379e00a7445e3..dca7b66da3796d9 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -11051,12 +11051,13 @@ class Sema final {
   /// Create an CUDALaunchBoundsAttr attribute.
   CUDALaunchBoundsAttr *CreateLaunchBoundsAttr(const AttributeCommonInfo 
amp;CI,
Expr *MaxThreads,
-   Expr *MinBlocks);
+   Expr *MinBlocks,
+   Expr *MaxBlocks);
 
   /// AddLaunchBoundsAttr - Adds a launch_bounds attribute to a particular
   /// declaration.
   void AddLaunchBoundsAttr(Decl *D, const AttributeCommonInfo amp;CI,
-   Expr *MaxThreads, Expr *MinBlocks);
+   Expr *MaxThreads, Expr *MinBlocks, Expr *MaxBlocks);
 
   /// AddModeAttr - Adds a mode attribute to a particular declaration.
   void AddModeAttr(Decl *D, const AttributeCommonInfo amp;CI, 
IdentifierInfo *Name,
diff --git a/clang/lib/CodeGen/Targets/NVPTX.cpp 
b/clang/lib/CodeGen/Targets/NVPTX.cpp
index 0d4bbd795648008..64d019a10514d60 100644
--- a/clang/lib/CodeGen/Targets/NVPTX.cpp
+++ b/clang/lib/CodeGen/Targets/NVPTX.cpp
@@ -296,8 +296,8 @@ void CodeGenModule::handleCUDALaunchBoundsAttr(
 NVPTXTargetCodeGenInfo::addNVVMMetadata(F, quot;maxntidxquot;,
 MaxThreads.getExtValue());
 
-  // min blocks is an optional argument for CUDALaunchBoundsAttr. If it was
-  // not specified in __launch_bounds__ or if the user specified a 0 value,
+  // min and max blocks is an optional argument for CUDALaunchBoundsAttr. If it
+  // was not specified in 

[clang] [NVPTX] Add support for maxclusterrank in launch_bounds (PR #66496)

2023-09-15 Thread Jakub Chlanda via cfe-commits

https://github.com/jchlanda created 
https://github.com/llvm/llvm-project/pull/66496

Since SM_90 CUDA supports specifying additional argument to the launch_bounds 
attribute: maxBlocksPerCluster, to express the maximum number of CTAs that can 
be part of the cluster. See: 
https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#cluster-dimension-directives-maxclusterrank
 and
https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#launch-bounds 
for details.

>From 9c8caed3c8def15ccdbfdf831f36d0befed1fc84 Mon Sep 17 00:00:00 2001
From: Jakub Chlanda 
Date: Fri, 15 Sep 2023 12:08:04 +0100
Subject: [PATCH] [NVPTX] Add support for maxclusterrank in launch_bounds

Since SM_90 CUDA supports specifying additional argument to the
launch_bounds attribute: maxBlocksPerCluster, to express the maximum
number of CTAs that can be part of the cluster. See:
https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#cluster-dimension-directives-maxclusterrank
and
https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#launch-bounds
for details.
---
 clang/include/clang/Basic/Attr.td |  3 +-
 .../clang/Basic/DiagnosticSemaKinds.td|  4 +
 clang/include/clang/Sema/Sema.h   |  5 +-
 clang/lib/CodeGen/Targets/NVPTX.cpp   | 12 ++-
 clang/lib/Parse/ParseOpenMP.cpp   |  3 +-
 clang/lib/Sema/SemaDeclAttr.cpp   | 46 +--
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  | 10 ++-
 clang/test/CodeGenCUDA/launch-bounds.cu   | 69 
 clang/test/SemaCUDA/launch_bounds.cu  |  4 +-
 clang/test/SemaCUDA/launch_bounds_sm_90.cu| 45 +++
 llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp | 79 +--
 llvm/lib/Target/NVPTX/NVPTXUtilities.cpp  |  4 +
 llvm/lib/Target/NVPTX/NVPTXUtilities.h|  1 +
 13 files changed, 227 insertions(+), 58 deletions(-)
 create mode 100644 clang/test/SemaCUDA/launch_bounds_sm_90.cu

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index c95db7e8049d47a..3c51261bd3eb081 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1267,7 +1267,8 @@ def CUDAInvalidTarget : InheritableAttr {
 
 def CUDALaunchBounds : InheritableAttr {
   let Spellings = [GNU<"launch_bounds">, Declspec<"__launch_bounds__">];
-  let Args = [ExprArgument<"MaxThreads">, ExprArgument<"MinBlocks", 1>];
+  let Args = [ExprArgument<"MaxThreads">, ExprArgument<"MinBlocks", 1>,
+  ExprArgument<"MaxBlocks", 1>];
   let LangOpts = [CUDA];
   let Subjects = SubjectList<[ObjCMethod, FunctionLike]>;
   // An AST node is created for this attribute, but is not used by other parts
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 0ac4df8edb242f6..088e3a45c7babba 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11836,6 +11836,10 @@ def err_sycl_special_type_num_init_method : Error<
   "types with 'sycl_special_class' attribute must have one and only one 
'__init' "
   "method defined">;
 
+def warn_cuda_maxclusterrank_sm_90 : Warning<
+  "maxclusterrank requires sm_90 or higher, CUDA arch provided: %0, ignoring "
+  "%1 attribute">, InGroup;
+
 def err_bit_int_bad_size : Error<"%select{signed|unsigned}0 _BitInt must "
  "have a bit size of at least %select{2|1}0">;
 def err_bit_int_max_size : Error<"%select{signed|unsigned}0 _BitInt of bit "
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 47379e00a7445e3..dca7b66da3796d9 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -11051,12 +11051,13 @@ class Sema final {
   /// Create an CUDALaunchBoundsAttr attribute.
   CUDALaunchBoundsAttr *CreateLaunchBoundsAttr(const AttributeCommonInfo ,
Expr *MaxThreads,
-   Expr *MinBlocks);
+   Expr *MinBlocks,
+   Expr *MaxBlocks);
 
   /// AddLaunchBoundsAttr - Adds a launch_bounds attribute to a particular
   /// declaration.
   void AddLaunchBoundsAttr(Decl *D, const AttributeCommonInfo ,
-   Expr *MaxThreads, Expr *MinBlocks);
+   Expr *MaxThreads, Expr *MinBlocks, Expr *MaxBlocks);
 
   /// AddModeAttr - Adds a mode attribute to a particular declaration.
   void AddModeAttr(Decl *D, const AttributeCommonInfo , IdentifierInfo 
*Name,
diff --git a/clang/lib/CodeGen/Targets/NVPTX.cpp 
b/clang/lib/CodeGen/Targets/NVPTX.cpp
index 0d4bbd795648008..64d019a10514d60 100644
--- a/clang/lib/CodeGen/Targets/NVPTX.cpp
+++ b/clang/lib/CodeGen/Targets/NVPTX.cpp
@@ -296,8 +296,8 @@ void CodeGenModule::handleCUDALaunchBoundsAttr(
 NVPTXTargetCodeGenInfo::addNVVMMetadata(F, 

[clang] [analyzer] Simplify SVal for simple NonLoc->Loc casts (PR #66463)

2023-09-15 Thread Balazs Benics via cfe-commits

steakhal wrote:

I thought "Mergeing" would wait and confirm if the checks pass, and only merge 
it if they succeed. Apparently, it's not the case here xD

The tests now break even on x86 linux. Could you please have a look? @danix800 

https://github.com/llvm/llvm-project/pull/66463
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 7af24c7 - Disable writing an output file to the source directory in Driver test

2023-09-15 Thread Benjamin Kramer via cfe-commits

Author: Benjamin Kramer
Date: 2023-09-15T13:19:13+02:00
New Revision: 7af24c765d0255e6fa4a9f564e0d3699e0cfa107

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

LOG: Disable writing an output file to the source directory in Driver test

Added: 


Modified: 
clang/test/Driver/omit-rtti-component-without-no-rtti.cpp

Removed: 




diff  --git a/clang/test/Driver/omit-rtti-component-without-no-rtti.cpp 
b/clang/test/Driver/omit-rtti-component-without-no-rtti.cpp
index 2108c7dea7f3386..87e5bba08368ad7 100644
--- a/clang/test/Driver/omit-rtti-component-without-no-rtti.cpp
+++ b/clang/test/Driver/omit-rtti-component-without-no-rtti.cpp
@@ -1,12 +1,12 @@
 /// Ensure that -fexperimental-omit-vtable-rtti is only allowed if rtti is
 /// disabled.
 
-// RUN: not %clang -c -Xclang -fexperimental-omit-vtable-rtti -frtti %s 2>&1 | 
FileCheck -check-prefix=ERROR %s
-// RUN: not %clang -c -Xclang -fexperimental-omit-vtable-rtti -fno-rtti -frtti 
%s 2>&1 | FileCheck -check-prefix=ERROR %s
+// RUN: not %clang -fsyntax-only -Xclang -fexperimental-omit-vtable-rtti 
-frtti %s 2>&1 | FileCheck -check-prefix=ERROR %s
+// RUN: not %clang -fsyntax-only -Xclang -fexperimental-omit-vtable-rtti 
-fno-rtti -frtti %s 2>&1 | FileCheck -check-prefix=ERROR %s
 
-// RUN: %clang -c -Xclang -fexperimental-omit-vtable-rtti -fno-rtti %s 2>&1 | 
FileCheck -check-prefix=NO-ERROR %s --allow-empty
-// RUN: %clang -c -Xclang -fno-experimental-omit-vtable-rtti -frtti %s 2>&1 | 
FileCheck -check-prefix=NO-ERROR %s --allow-empty
-// RUN: %clang -c -Xclang -fexperimental-omit-vtable-rtti -Xclang 
-fno-experimental-omit-vtable-rtti -frtti %s 2>&1 | FileCheck 
-check-prefix=NO-ERROR %s --allow-empty
+// RUN: %clang -fsyntax-only -Xclang -fexperimental-omit-vtable-rtti -fno-rtti 
%s 2>&1 | FileCheck -check-prefix=NO-ERROR %s --allow-empty
+// RUN: %clang -fsyntax-only -Xclang -fno-experimental-omit-vtable-rtti -frtti 
%s 2>&1 | FileCheck -check-prefix=NO-ERROR %s --allow-empty
+// RUN: %clang -fsyntax-only -Xclang -fexperimental-omit-vtable-rtti -Xclang 
-fno-experimental-omit-vtable-rtti -frtti %s 2>&1 | FileCheck 
-check-prefix=NO-ERROR %s --allow-empty
 
 // ERROR: -fexperimental-omit-vtable-rtti call only be used with -fno-rtti
 // NO-ERROR-NOT: -fexperimental-omit-vtable-rtti call only be used with 
-fno-rtti



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


[PATCH] D156511: [clang][Interp] Diagnose more unkonwn DeclRefExprs

2023-09-15 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder closed this revision.
tbaeder added a comment.

Looks like I squashed this into https://reviews.llvm.org/D156509 for some 
reason.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156511

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


[clang] 03693d5 - Revert "[analyzer] Simplify SVal for simple NonLoc->Loc casts (#66463)"

2023-09-15 Thread Balazs Benics via cfe-commits

Author: Balazs Benics
Date: 2023-09-15T13:18:34+02:00
New Revision: 03693d5b40f187921ead5a502fa3cf72ce30fea4

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

LOG: Revert "[analyzer] Simplify SVal for simple NonLoc->Loc casts (#66463)"

This reverts commit 3ebf3dd30da219f9f9aee12f42d45d18d55e7580.

I thought "Mergeing" will wait and confirm if the checks pass, and only
merge it if they succeed. Apparently, it's not the case here xD

The test is just broken in x86. See:
https://lab.llvm.org/buildbot/#/builders/109/builds/73686

Added: 


Modified: 
clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
clang/test/Analysis/symbol-simplification-nonloc-loc.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp 
b/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
index 7e431f7e598c4cb..2a47116db55a1ad 100644
--- a/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
@@ -264,8 +264,7 @@ ProgramStateRef ExprEngine::handleLValueBitCast(
   }
   // Delegate to SValBuilder to process.
   SVal OrigV = state->getSVal(Ex, LCtx);
-  SVal SimplifiedOrigV = svalBuilder.simplifySVal(state, OrigV);
-  SVal V = svalBuilder.evalCast(SimplifiedOrigV, T, ExTy);
+  SVal V = svalBuilder.evalCast(OrigV, T, ExTy);
   // Negate the result if we're treating the boolean as a signed i1
   if (CastE->getCastKind() == CK_BooleanToSignedIntegral && V.isValid())
 V = svalBuilder.evalMinus(V.castAs());

diff  --git a/clang/test/Analysis/symbol-simplification-nonloc-loc.cpp 
b/clang/test/Analysis/symbol-simplification-nonloc-loc.cpp
index 619fda824cb70b5..485f68d9a5acfba 100644
--- a/clang/test/Analysis/symbol-simplification-nonloc-loc.cpp
+++ b/clang/test/Analysis/symbol-simplification-nonloc-loc.cpp
@@ -1,8 +1,6 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=core %s \
 // RUN:-triple x86_64-pc-linux-gnu -verify
 
-void clang_analyzer_eval(int);
-
 #define BINOP(OP) [](auto x, auto y) { return x OP y; }
 
 template 
@@ -75,27 +73,3 @@ void zoo1backwards() {
   *(0 + p) = nullptr;  // warn
   **(0 + p) = 'a'; // no-warning: this should be unreachable
 }
-
-void test_simplified_before_cast_add(long t1) {
-  long long t2 = t1 + 3;
-  if (!t2) {
-int *p = (int *) t2;
-clang_analyzer_eval(p == 0); // expected-warning{{TRUE}}
-  }
-}
-
-void test_simplified_before_cast_sub(long t1) {
-  long long t2 = t1 - 3;
-  if (!t2) {
-int *p = (int *) t2;
-clang_analyzer_eval(p == 0); // expected-warning{{TRUE}}
-  }
-}
-
-void test_simplified_before_cast_mul(long t1) {
-  long long t2 = t1 * 3;
-  if (!t2) {
-int *p = (int *) t2;
-clang_analyzer_eval(p == 0); // expected-warning{{TRUE}}
-  }
-}



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


[PATCH] D156509: [clang][Interp] Diagnose unknown parameter values

2023-09-15 Thread Timm Bäder via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG23c39f9a9e14: [clang][Interp] Diagnose unknown parameter 
values (authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D156509?vs=545193=556845#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156509

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/Interp.cpp
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/Opcodes.td
  clang/test/AST/Interp/c.c
  clang/test/AST/Interp/functions.cpp
  clang/test/AST/Interp/literals.cpp

Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -1088,3 +1088,31 @@
   int array[(intptr_t)(char*)0]; // ref-warning {{variable length array folded to constant array}} \
  // expected-warning {{variable length array folded to constant array}}
 }
+
+namespace InvalidDeclRefs {
+  bool b00; // ref-note {{declared here}} \
+// expected-note {{declared here}}
+  static_assert(b00, ""); // ref-error {{not an integral constant expression}} \
+  // ref-note {{read of non-const variable}} \
+  // expected-error {{not an integral constant expression}} \
+  // expected-note {{read of non-const variable}}
+
+  float b01; // ref-note {{declared here}} \
+ // expected-note {{declared here}}
+  static_assert(b01, ""); // ref-error {{not an integral constant expression}} \
+  // ref-note {{read of non-constexpr variable}} \
+  // expected-error {{not an integral constant expression}} \
+  // expected-note {{read of non-constexpr variable}}
+
+  extern const int b02; // ref-note {{declared here}} \
+// expected-note {{declared here}}
+  static_assert(b02, ""); // ref-error {{not an integral constant expression}} \
+  // ref-note {{initializer of 'b02' is unknown}} \
+  // expected-error {{not an integral constant expression}} \
+  // expected-note {{initializer of 'b02' is unknown}}
+
+  /// FIXME: This should also be diagnosed in the new interpreter.
+  int b03 = 3; // ref-note {{declared here}}
+  static_assert(b03, ""); // ref-error {{not an integral constant expression}} \
+  // ref-note {{read of non-const variable}}
+}
Index: clang/test/AST/Interp/functions.cpp
===
--- clang/test/AST/Interp/functions.cpp
+++ clang/test/AST/Interp/functions.cpp
@@ -1,5 +1,9 @@
 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify %s
+// RUN: %clang_cc1 -std=c++14 -fexperimental-new-constant-interpreter -verify %s
+// RUN: %clang_cc1 -std=c++20 -fexperimental-new-constant-interpreter -verify %s
 // RUN: %clang_cc1 -verify=ref %s
+// RUN: %clang_cc1 -std=c++14 -verify=ref %s
+// RUN: %clang_cc1 -std=c++20 -verify=ref %s
 
 constexpr void doNothing() {}
 constexpr int gimme5() {
@@ -307,3 +311,24 @@
   }
   static_assert((foo(),1) == 1, "");
 }
+
+namespace InvalidReclRefs {
+  void param(bool b) { // ref-note {{declared here}} \
+   // expected-note {{declared here}}
+static_assert(b, ""); // ref-error {{not an integral constant expression}} \
+  // ref-note {{function parameter 'b' with unknown value}} \
+  // expected-error {{not an integral constant expression}} \
+  // expected-note {{function parameter 'b' with unknown value}}
+static_assert(true ? true : b, "");
+  }
+
+#if __cplusplus >= 202002L
+  consteval void param2(bool b) { // ref-note {{declared here}} \
+ // expected-note {{declared here}}
+static_assert(b, ""); // ref-error {{not an integral constant expression}} \
+  // ref-note {{function parameter 'b' with unknown value}} \
+  // expected-error {{not an integral constant expression}} \
+  // expected-note {{function parameter 'b' with unknown value}}
+  }
+#endif
+}
Index: clang/test/AST/Interp/c.c
===
--- clang/test/AST/Interp/c.c
+++ clang/test/AST/Interp/c.c
@@ -3,8 +3,6 @@
 // RUN: %clang_cc1 -verify=ref -std=c11 %s
 // RUN: %clang_cc1 -pedantic -verify=pedantic-ref -std=c11 %s
 
-/// expected-no-diagnostics
-
 _Static_assert(1, "");
 _Static_assert(0 != 1, "");
 _Static_assert(1.0 == 1.0, ""); // pedantic-ref-warning {{not an integer constant expression}} \
@@ -26,3 +24,15 @@
 _Static_assert(b == 3, ""); // 

[clang] 23c39f9 - [clang][Interp] Diagnose unknown parameter values

2023-09-15 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-09-15T13:10:19+02:00
New Revision: 23c39f9a9e14caae7b0113e306bf2faf1e4f88f3

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

LOG: [clang][Interp] Diagnose unknown parameter values

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

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/Interp.cpp
clang/lib/AST/Interp/Interp.h
clang/lib/AST/Interp/Opcodes.td
clang/test/AST/Interp/c.c
clang/test/AST/Interp/functions.cpp
clang/test/AST/Interp/literals.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index e49dc80a5c9ce7c..823bef7a8c19e11 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -2492,7 +2492,8 @@ bool ByteCodeExprGen::VisitDeclRefExpr(const 
DeclRefExpr *E) {
   return this->VisitDeclRefExpr(E);
 }
   }
-  return false;
+
+  return this->emitInvalidDeclRef(E, E);
 }
 
 template 

diff  --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index 67fc11d9c9bf9c1..e1951574edb6288 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -542,6 +542,38 @@ bool CheckFloatResult(InterpState , CodePtr OpPC, const 
Floating ,
   return true;
 }
 
+/// We aleady know the given DeclRefExpr is invalid for some reason,
+/// now figure out why and print appropriate diagnostics.
+bool CheckDeclRef(InterpState , CodePtr OpPC, const DeclRefExpr *DR) {
+  const ValueDecl *D = DR->getDecl();
+  const SourceInfo  = S.Current->getSource(OpPC);
+
+  if (isa(D)) {
+S.FFDiag(E, diag::note_constexpr_function_param_value_unknown) << D;
+S.Note(D->getLocation(), diag::note_declared_at) << D->getSourceRange();
+  } else if (const auto *VD = dyn_cast(D)) {
+if (!VD->getType().isConstQualified()) {
+  S.FFDiag(E,
+   VD->getType()->isIntegralOrEnumerationType()
+   ? diag::note_constexpr_ltor_non_const_int
+   : diag::note_constexpr_ltor_non_constexpr,
+   1)
+  << VD;
+  S.Note(VD->getLocation(), diag::note_declared_at) << 
VD->getSourceRange();
+  return false;
+}
+
+// const, but no initializer.
+if (!VD->getAnyInitializer()) {
+  S.FFDiag(E, diag::note_constexpr_var_init_unknown, 1) << VD;
+  S.Note(VD->getLocation(), diag::note_declared_at) << 
VD->getSourceRange();
+  return false;
+}
+  }
+
+  return false;
+}
+
 bool Interpret(InterpState , APValue ) {
   // The current stack frame when we started Interpret().
   // This is being used by the ops to determine wheter

diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 37d3dd0da6568af..8453856e526a6b2 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -175,6 +175,9 @@ bool CheckDivRem(InterpState , CodePtr OpPC, const T 
, const T ) {
 bool CheckFloatResult(InterpState , CodePtr OpPC, const Floating ,
   APFloat::opStatus Status);
 
+/// Checks why the given DeclRefExpr is invalid.
+bool CheckDeclRef(InterpState , CodePtr OpPC, const DeclRefExpr *DR);
+
 /// Interpreter entry point.
 bool Interpret(InterpState , APValue );
 
@@ -1854,6 +1857,12 @@ inline bool InvalidCast(InterpState , CodePtr OpPC, 
CastKind Kind) {
   return false;
 }
 
+inline bool InvalidDeclRef(InterpState , CodePtr OpPC,
+   const DeclRefExpr *DR) {
+  assert(DR);
+  return CheckDeclRef(S, OpPC, DR);
+}
+
 template ::T>
 inline bool OffsetOf(InterpState , CodePtr OpPC, const OffsetOfExpr *E) {
   llvm::SmallVector ArrayIndices;

diff  --git a/clang/lib/AST/Interp/Opcodes.td b/clang/lib/AST/Interp/Opcodes.td
index e0c7cf1eaf92489..eeb71db125fef73 100644
--- a/clang/lib/AST/Interp/Opcodes.td
+++ b/clang/lib/AST/Interp/Opcodes.td
@@ -54,6 +54,7 @@ def ArgLETD: ArgType { let Name = "const 
LifetimeExtendedTemporaryDecl *"; }
 def ArgCastKind : ArgType { let Name = "CastKind"; }
 def ArgCallExpr : ArgType { let Name = "const CallExpr *"; }
 def ArgOffsetOfExpr : ArgType { let Name = "const OffsetOfExpr *"; }
+def ArgDeclRef : ArgType { let Name = "const DeclRefExpr *"; }
 
 
//===--===//
 // Classes of types instructions operate on.
@@ -632,3 +633,7 @@ def Invalid : Opcode {}
 def InvalidCast : Opcode {
   let Args = [ArgCastKind];
 }
+
+def InvalidDeclRef : Opcode {
+  let Args = [ArgDeclRef];
+}

diff  --git a/clang/test/AST/Interp/c.c b/clang/test/AST/Interp/c.c
index 789139362335236..c0ec5f8339dd1d7 100644
--- a/clang/test/AST/Interp/c.c
+++ b/clang/test/AST/Interp/c.c
@@ -3,8 +3,6 @@
 // RUN: %clang_cc1 -verify=ref -std=c11 

[PATCH] D150075: Fix PR#62594 : static lambda call operator is not convertible to function pointer on win32

2023-09-15 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson added a comment.

@shafik @aaron.ballman does any of you want to commandeer this diff? seems 
simple enough of a change


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150075

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


[PATCH] D154893: [Clang] Fix some triviality computations

2023-09-15 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson added a comment.

In D154893#4646405 , @cor3ntin wrote:

> @royjacobson ^

I did not have a lot of time for Clang the last few months unfortunately. I 
might take a look at this again next month when I'll have a bit more time.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154893

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


[clang] [clang-tidy]add new check `bugprone-compare-pointer-to-member-virtual-function` (PR #66055)

2023-09-15 Thread Piotr Zegar via cfe-commits

PiotrZSL wrote:

> Could I land it now?
Yes


https://github.com/llvm/llvm-project/pull/66055
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158702: [clang][Interp] Check pointer inc/dec ops for initialization

2023-09-15 Thread Timm Bäder via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG177f9ab2fbd8: [clang][Interp] Check pointer inc/dec ops for 
initialization (authored by tbaeder).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158702

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

Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -509,36 +509,72 @@
   }
   static_assert(incBool(), "");
 
-  template
+  /// FIXME: The diagnostics for pre-inc/dec of pointers doesn't match the
+  /// current interpreter. But they are stil OK.
+  template
   constexpr int uninit() {
 T a;
-if constexpr (Inc)
-  ++a; // ref-note 2{{increment of uninitialized}} \
-   // expected-note 2{{increment of uninitialized}}
-else
-  --a; // ref-note 2{{decrement of uninitialized}} \
-   // expected-note 2{{decrement of uninitialized}}
+if constexpr (Inc) {
+  if (Pre)
+++a; // ref-note 3{{increment of uninitialized}} \
+ // expected-note 2{{increment of uninitialized}} \
+ // expected-note {{read of uninitialized}}
+  else
+a++; // ref-note 2{{increment of uninitialized}} \
+ // expected-note 2{{increment of uninitialized}}
+} else {
+  if (Pre)
+--a; // ref-note 3{{decrement of uninitialized}} \
+ // expected-note 2{{decrement of uninitialized}} \
+ // expected-note {{read of uninitialized}}
+  else
+a--; // ref-note 2{{decrement of uninitialized}} \
+ // expected-note 2{{decrement of uninitialized}}
+}
 return 1;
   }
-  static_assert(uninit(), ""); // ref-error {{not an integral constant expression}} \
-  // ref-note {{in call to 'uninit()'}} \
-  // expected-error {{not an integral constant expression}} \
-  // expected-note {{in call to 'uninit()'}}
-
-  static_assert(uninit(), ""); // ref-error {{not an integral constant expression}} \
-   // ref-note {{in call to 'uninit()'}} \
-   // expected-error {{not an integral constant expression}} \
-   // expected-note {{in call to 'uninit()'}}
-
-  static_assert(uninit(), ""); // ref-error {{not an integral constant expression}} \
-// ref-note {{in call to 'uninit()'}} \
-// expected-error {{not an integral constant expression}} \
-// expected-note {{in call to 'uninit()'}}
-
-  static_assert(uninit(), ""); // ref-error {{not an integral constant expression}} \
- // ref-note {{in call to 'uninit()'}} \
- // expected-error {{not an integral constant expression}} \
- // expected-note {{in call to 'uninit()'}}
+  static_assert(uninit(), ""); // ref-error {{not an integral constant expression}} \
+// ref-note {{in call to 'uninit()'}} \
+// expected-error {{not an integral constant expression}} \
+// expected-note {{in call to 'uninit()'}}
+  static_assert(uninit(), ""); // ref-error {{not an integral constant expression}} \
+ // ref-note {{in call to 'uninit()'}} \
+ // expected-error {{not an integral constant expression}} \
+ // expected-note {{in call to 'uninit()'}}
+
+  static_assert(uninit(), ""); // ref-error {{not an integral constant expression}} \
+  // ref-note {{in call to 'uninit()'}} \
+  // expected-error {{not an integral constant expression}} \
+  // expected-note {{in call to 'uninit()'}}
+  static_assert(uninit(), ""); // ref-error {{not an integral constant expression}} \
+   // ref-note {{in call to 'uninit()'}} \
+   // expected-error {{not an integral constant expression}} \
+   // expected-note {{in call to 'uninit()'}}
+  static_assert(uninit(), ""); // ref-error {{not an integral constant expression}} \
+  

[clang] 177f9ab - [clang][Interp] Check pointer inc/dec ops for initialization

2023-09-15 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-09-15T13:04:04+02:00
New Revision: 177f9ab2fbd868fb9cc7d5504e56a241e8e79329

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

LOG: [clang][Interp] Check pointer inc/dec ops for initialization

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

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index b109f2bda17bfb1..37d3dd0da6568af 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -1441,9 +1441,9 @@ bool SubOffset(InterpState , CodePtr OpPC) {
 }
 
 template 
-static inline bool IncDecPtrHelper(InterpState , CodePtr OpPC) {
+static inline bool IncDecPtrHelper(InterpState , CodePtr OpPC,
+   const Pointer ) {
   using OneT = Integral<8, false>;
-  const Pointer  = S.Stk.pop();
 
   // Get the current value on the stack.
   S.Stk.push(Ptr.deref());
@@ -1460,11 +1460,21 @@ static inline bool IncDecPtrHelper(InterpState , 
CodePtr OpPC) {
 }
 
 static inline bool IncPtr(InterpState , CodePtr OpPC) {
-  return IncDecPtrHelper(S, OpPC);
+  const Pointer  = S.Stk.pop();
+
+  if (!CheckInitialized(S, OpPC, Ptr, AK_Increment))
+return false;
+
+  return IncDecPtrHelper(S, OpPC, Ptr);
 }
 
 static inline bool DecPtr(InterpState , CodePtr OpPC) {
-  return IncDecPtrHelper(S, OpPC);
+  const Pointer  = S.Stk.pop();
+
+  if (!CheckInitialized(S, OpPC, Ptr, AK_Decrement))
+return false;
+
+  return IncDecPtrHelper(S, OpPC, Ptr);
 }
 
 /// 1) Pops a Pointer from the stack.

diff  --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index dae1d5af6f7ae38..1a12413f3f0fa8e 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -509,36 +509,72 @@ namespace IncDec {
   }
   static_assert(incBool(), "");
 
-  template
+  /// FIXME: The diagnostics for pre-inc/dec of pointers doesn't match the
+  /// current interpreter. But they are stil OK.
+  template
   constexpr int uninit() {
 T a;
-if constexpr (Inc)
-  ++a; // ref-note 2{{increment of uninitialized}} \
-   // expected-note 2{{increment of uninitialized}}
-else
-  --a; // ref-note 2{{decrement of uninitialized}} \
-   // expected-note 2{{decrement of uninitialized}}
+if constexpr (Inc) {
+  if (Pre)
+++a; // ref-note 3{{increment of uninitialized}} \
+ // expected-note 2{{increment of uninitialized}} \
+ // expected-note {{read of uninitialized}}
+  else
+a++; // ref-note 2{{increment of uninitialized}} \
+ // expected-note 2{{increment of uninitialized}}
+} else {
+  if (Pre)
+--a; // ref-note 3{{decrement of uninitialized}} \
+ // expected-note 2{{decrement of uninitialized}} \
+ // expected-note {{read of uninitialized}}
+  else
+a--; // ref-note 2{{decrement of uninitialized}} \
+ // expected-note 2{{decrement of uninitialized}}
+}
 return 1;
   }
-  static_assert(uninit(), ""); // ref-error {{not an integral 
constant expression}} \
-  // ref-note {{in call to 
'uninit()'}} \
-  // expected-error {{not an integral 
constant expression}} \
-  // expected-note {{in call to 
'uninit()'}}
-
-  static_assert(uninit(), ""); // ref-error {{not an integral 
constant expression}} \
-   // ref-note {{in call to 
'uninit()'}} \
-   // expected-error {{not an integral 
constant expression}} \
-   // expected-note {{in call to 
'uninit()'}}
-
-  static_assert(uninit(), ""); // ref-error {{not an integral 
constant expression}} \
-// ref-note {{in call to 
'uninit()'}} \
-// expected-error {{not an 
integral constant expression}} \
-// expected-note {{in call to 
'uninit()'}}
-
-  static_assert(uninit(), ""); // ref-error {{not an integral 
constant expression}} \
- // ref-note {{in call to 
'uninit()'}} \
- // expected-error {{not an 
integral constant expression}} \
- // expected-note {{in call to 
'uninit()'}}
+  static_assert(uninit(), ""); // ref-error {{not an integral 
constant expression}} \
+// ref-note {{in call to 
'uninit()'}} \
+  

[clang] Introduce paged vector (PR #66430)

2023-09-15 Thread Sergei Barannikov via cfe-commits

s-barannikov wrote:

Why don't just turn SLocEntry into a POD and use 
SmallVector::resize_for_overwrite? That way the vector will not be initialized 
and the OS will only allocate physical memory on the first access to a page.


https://github.com/llvm/llvm-project/pull/66430
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Simplify SVal for simple NonLoc->Loc casts (PR #66463)

2023-09-15 Thread Balazs Benics via cfe-commits

https://github.com/steakhal closed 
https://github.com/llvm/llvm-project/pull/66463
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 3ebf3dd - [analyzer] Simplify SVal for simple NonLoc->Loc casts (#66463)

2023-09-15 Thread via cfe-commits

Author: Ding Fei
Date: 2023-09-15T13:00:32+02:00
New Revision: 3ebf3dd30da219f9f9aee12f42d45d18d55e7580

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

LOG: [analyzer] Simplify SVal for simple NonLoc->Loc casts (#66463)

NonLoc symbolic SVal to Loc casts are not supported except for
nonloc::ConcreteInt.

This change simplifies the source SVals so that the more casts can go
through nonloc::ConcreteInt->loc::ConcreteInt path. For example:

```c
  void test_simplified_before_cast_add(long long t1) {
long long t2 = t1 + 3;
if (!t2) {
  int *p = (int *) t2;
  clang_analyzer_eval(p == 0); // expected-warning{{TRUE}}
}
  }
```
If simplified, `t2` is 0, resulting `p` is nullptr, otherwise `p` is
unknown.

Fixes #62232

Added: 


Modified: 
clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
clang/test/Analysis/symbol-simplification-nonloc-loc.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp 
b/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
index 2a47116db55a1ad..7e431f7e598c4cb 100644
--- a/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
@@ -264,7 +264,8 @@ ProgramStateRef ExprEngine::handleLValueBitCast(
   }
   // Delegate to SValBuilder to process.
   SVal OrigV = state->getSVal(Ex, LCtx);
-  SVal V = svalBuilder.evalCast(OrigV, T, ExTy);
+  SVal SimplifiedOrigV = svalBuilder.simplifySVal(state, OrigV);
+  SVal V = svalBuilder.evalCast(SimplifiedOrigV, T, ExTy);
   // Negate the result if we're treating the boolean as a signed i1
   if (CastE->getCastKind() == CK_BooleanToSignedIntegral && V.isValid())
 V = svalBuilder.evalMinus(V.castAs());

diff  --git a/clang/test/Analysis/symbol-simplification-nonloc-loc.cpp 
b/clang/test/Analysis/symbol-simplification-nonloc-loc.cpp
index 485f68d9a5acfba..619fda824cb70b5 100644
--- a/clang/test/Analysis/symbol-simplification-nonloc-loc.cpp
+++ b/clang/test/Analysis/symbol-simplification-nonloc-loc.cpp
@@ -1,6 +1,8 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=core %s \
 // RUN:-triple x86_64-pc-linux-gnu -verify
 
+void clang_analyzer_eval(int);
+
 #define BINOP(OP) [](auto x, auto y) { return x OP y; }
 
 template 
@@ -73,3 +75,27 @@ void zoo1backwards() {
   *(0 + p) = nullptr;  // warn
   **(0 + p) = 'a'; // no-warning: this should be unreachable
 }
+
+void test_simplified_before_cast_add(long t1) {
+  long long t2 = t1 + 3;
+  if (!t2) {
+int *p = (int *) t2;
+clang_analyzer_eval(p == 0); // expected-warning{{TRUE}}
+  }
+}
+
+void test_simplified_before_cast_sub(long t1) {
+  long long t2 = t1 - 3;
+  if (!t2) {
+int *p = (int *) t2;
+clang_analyzer_eval(p == 0); // expected-warning{{TRUE}}
+  }
+}
+
+void test_simplified_before_cast_mul(long t1) {
+  long long t2 = t1 * 3;
+  if (!t2) {
+int *p = (int *) t2;
+clang_analyzer_eval(p == 0); // expected-warning{{TRUE}}
+  }
+}



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


[clang] [clang-tidy]add new check `bugprone-compare-pointer-to-member-virtual-function` (PR #66055)

2023-09-15 Thread Congcong Cai via cfe-commits

HerrCai0907 wrote:

> I run this check on two bigger projects, didn't found anything (I was 
> expecting it wont).
> 
> So at least in case of false-positives it looks fine.

I also run in some project and find nothing.

Could I land it now?

https://github.com/llvm/llvm-project/pull/66055
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Simplify SVal for simple NonLoc->Loc casts (PR #66463)

2023-09-15 Thread Balazs Benics via cfe-commits

https://github.com/steakhal approved this pull request.

Thanks!

https://github.com/llvm/llvm-project/pull/66463
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Simplify SVal for simple NonLoc->Loc casts (PR #66463)

2023-09-15 Thread Balazs Benics via cfe-commits

https://github.com/steakhal resolved 
https://github.com/llvm/llvm-project/pull/66463
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)

2023-09-15 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/65844

>From db98faff4cfc86657ee8f47dac0e1e2a441049b8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sat, 9 Sep 2023 10:34:26 +0200
Subject: [PATCH 1/3] [clang][Interp] Add IntegralAP for arbitrary-precision
 integers

---
 clang/lib/AST/Interp/ByteCodeExprGen.cpp |  11 +-
 clang/lib/AST/Interp/Context.cpp |   6 +-
 clang/lib/AST/Interp/Descriptor.cpp  |   9 +
 clang/lib/AST/Interp/EvalEmitter.cpp |   1 +
 clang/lib/AST/Interp/Integral.h  |   4 +
 clang/lib/AST/Interp/IntegralAP.h| 253 +++
 clang/lib/AST/Interp/Interp.h|  21 +-
 clang/lib/AST/Interp/InterpStack.h   |   5 +
 clang/lib/AST/Interp/Opcodes.td  |   8 +-
 clang/lib/AST/Interp/PrimType.cpp|   1 +
 clang/lib/AST/Interp/PrimType.h  |  13 ++
 clang/test/AST/Interp/literals.cpp   |  24 +++
 12 files changed, 343 insertions(+), 13 deletions(-)
 create mode 100644 clang/lib/AST/Interp/IntegralAP.h

diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index e49dc80a5c9ce7c..1d7b8201ae92802 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -171,14 +171,17 @@ bool ByteCodeExprGen::VisitCastExpr(const 
CastExpr *CE) {
   return this->discard(SubExpr);
 std::optional FromT = classify(SubExpr->getType());
 std::optional ToT = classify(CE->getType());
+
 if (!FromT || !ToT)
   return false;
 
 if (!this->visit(SubExpr))
   return false;
 
-if (FromT == ToT)
+if (FromT == ToT) {
+  assert(ToT != PT_IntAP && ToT != PT_IntAPS);
   return true;
+}
 
 return this->emitCast(*FromT, *ToT, CE);
   }
@@ -1596,6 +1599,9 @@ bool 
ByteCodeExprGen::visitZeroInitializer(QualType QT,
 return this->emitZeroSint64(E);
   case PT_Uint64:
 return this->emitZeroUint64(E);
+  case PT_IntAP:
+  case PT_IntAPS:
+assert(false);
   case PT_Ptr:
 return this->emitNullPtr(E);
   case PT_FnPtr:
@@ -1835,6 +1841,9 @@ bool ByteCodeExprGen::emitConst(T Value, 
PrimType Ty, const Expr *E) {
 return this->emitConstSint64(Value, E);
   case PT_Uint64:
 return this->emitConstUint64(Value, E);
+  case PT_IntAP:
+  case PT_IntAPS:
+assert(false);
   case PT_Bool:
 return this->emitConstBool(Value, E);
   case PT_Ptr:
diff --git a/clang/lib/AST/Interp/Context.cpp b/clang/lib/AST/Interp/Context.cpp
index 1a732b6c1a092ac..ed2b23514e86665 100644
--- a/clang/lib/AST/Interp/Context.cpp
+++ b/clang/lib/AST/Interp/Context.cpp
@@ -102,7 +102,8 @@ std::optional Context::classify(QualType T) const 
{
 case 8:
   return PT_Sint8;
 default:
-  return std::nullopt;
+  return PT_IntAPS;
+  // return std::nullopt;
 }
   }
 
@@ -117,7 +118,8 @@ std::optional Context::classify(QualType T) const 
{
 case 8:
   return PT_Uint8;
 default:
-  return std::nullopt;
+  return PT_IntAP;
+  // return std::nullopt;
 }
   }
 
diff --git a/clang/lib/AST/Interp/Descriptor.cpp 
b/clang/lib/AST/Interp/Descriptor.cpp
index db49a569eff33ea..4ecb7466998e705 100644
--- a/clang/lib/AST/Interp/Descriptor.cpp
+++ b/clang/lib/AST/Interp/Descriptor.cpp
@@ -10,6 +10,7 @@
 #include "Boolean.h"
 #include "Floating.h"
 #include "FunctionPointer.h"
+#include "IntegralAP.h"
 #include "Pointer.h"
 #include "PrimType.h"
 #include "Record.h"
@@ -182,6 +183,10 @@ static BlockCtorFn getCtorPrim(PrimType Type) {
   // constructor called.
   if (Type == PT_Float)
 return ctorTy::T>;
+  if (Type == PT_IntAP)
+return ctorTy::T>;
+  if (Type == PT_IntAPS)
+return ctorTy::T>;
 
   COMPOSITE_TYPE_SWITCH(Type, return ctorTy, return nullptr);
 }
@@ -191,6 +196,10 @@ static BlockDtorFn getDtorPrim(PrimType Type) {
   // destructor called, since they might allocate memory.
   if (Type == PT_Float)
 return dtorTy::T>;
+  if (Type == PT_IntAP)
+return dtorTy::T>;
+  if (Type == PT_IntAPS)
+return dtorTy::T>;
 
   COMPOSITE_TYPE_SWITCH(Type, return dtorTy, return nullptr);
 }
diff --git a/clang/lib/AST/Interp/EvalEmitter.cpp 
b/clang/lib/AST/Interp/EvalEmitter.cpp
index d26ee8e40a437b9..c9332d8b2364fa1 100644
--- a/clang/lib/AST/Interp/EvalEmitter.cpp
+++ b/clang/lib/AST/Interp/EvalEmitter.cpp
@@ -8,6 +8,7 @@
 
 #include "EvalEmitter.h"
 #include "Context.h"
+#include "IntegralAP.h"
 #include "Interp.h"
 #include "Opcode.h"
 #include "Program.h"
diff --git a/clang/lib/AST/Interp/Integral.h b/clang/lib/AST/Interp/Integral.h
index 72285cabcbbf8ce..f8e529aa3392696 100644
--- a/clang/lib/AST/Interp/Integral.h
+++ b/clang/lib/AST/Interp/Integral.h
@@ -29,6 +29,8 @@ namespace interp {
 using APInt = llvm::APInt;
 using APSInt = llvm::APSInt;
 
+template  class IntegralAP;
+
 // Helper structure to select the representation.
 template  

[clang] [analyzer] Simplify SVal for simple NonLoc->Loc casts (PR #66463)

2023-09-15 Thread Balazs Benics via cfe-commits

https://github.com/steakhal resolved 
https://github.com/llvm/llvm-project/pull/66463
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Simplify SVal for simple NonLoc->Loc casts (PR #66463)

2023-09-15 Thread Balazs Benics via cfe-commits

https://github.com/steakhal resolved 
https://github.com/llvm/llvm-project/pull/66463
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Interp] Handle AttributedStmts (PR #66495)

2023-09-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang


Changes
Just ignore the attributes.
--
Full diff: https://github.com/llvm/llvm-project/pull/66495.diff

3 Files Affected:

- (modified) clang/lib/AST/Interp/ByteCodeStmtGen.cpp (+8) 
- (modified) clang/lib/AST/Interp/ByteCodeStmtGen.h (+1) 
- (modified) clang/test/AST/Interp/if.cpp (+7) 



diff --git a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp 
b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
index b7553d8963ff0ee..a0f50c3e69dd918 100644
--- a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -246,6 +246,8 @@ bool 
ByteCodeStmtGenlt;Emittergt;::visitStmt(const Stmt *S) {
   case Stmt::GCCAsmStmtClass:
   case Stmt::MSAsmStmtClass:
 return visitAsmStmt(castlt;AsmStmtgt;(S));
+  case Stmt::AttributedStmtClass:
+return visitAttributedStmt(castlt;AttributedStmtgt;(S));
   case Stmt::NullStmtClass:
 return true;
   default: {
@@ -628,6 +630,12 @@ bool 
ByteCodeStmtGenlt;Emittergt;::visitAsmStmt(const AsmStmt *S) {
   return this-gt;emitInvalid(S);
 }
 
+template lt;class Emittergt;
+bool ByteCodeStmtGenlt;Emittergt;::visitAttributedStmt(const 
AttributedStmt *S) {
+  // Ignore all attributes.
+  return this-gt;visitStmt(S-gt;getSubStmt());
+}
+
 namespace clang {
 namespace interp {
 
diff --git a/clang/lib/AST/Interp/ByteCodeStmtGen.h 
b/clang/lib/AST/Interp/ByteCodeStmtGen.h
index 278e804a803c951..3bdcdd78f397e5b 100644
--- a/clang/lib/AST/Interp/ByteCodeStmtGen.h
+++ b/clang/lib/AST/Interp/ByteCodeStmtGen.h
@@ -68,6 +68,7 @@ class ByteCodeStmtGen final : public 
ByteCodeExprGenlt;Emittergt; {
   bool visitCaseStmt(const CaseStmt *S);
   bool visitDefaultStmt(const DefaultStmt *S);
   bool visitAsmStmt(const AsmStmt *S);
+  bool visitAttributedStmt(const AttributedStmt *S);
 
   bool emitLambdaStaticInvokerBody(const CXXMethodDecl *MD);
 
diff --git a/clang/test/AST/Interp/if.cpp b/clang/test/AST/Interp/if.cpp
index 2449ace4dd6c6b5..86ae8de6f73ebb7 100644
--- a/clang/test/AST/Interp/if.cpp
+++ b/clang/test/AST/Interp/if.cpp
@@ -43,4 +43,11 @@ namespace InitDecl {
 return false;
   }
   static_assert(!f2(), quot;quot;);
+
+
+  constexpr int attrs() {
+if (1) [[likely]] {}
+return 1;
+  }
+  static_assert(attrs() == 1, quot;quot;);
 };




https://github.com/llvm/llvm-project/pull/66495
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Interp] Handle AttributedStmts (PR #66495)

2023-09-15 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/66495

Just ignore the attributes.

>From c1c216058408cf54771bfdac71b0bcf28110f292 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Fri, 15 Sep 2023 12:55:04 +0200
Subject: [PATCH] [clang][Interp] Handle AttributedStmts

Just ignore the attributes.
---
 clang/lib/AST/Interp/ByteCodeStmtGen.cpp | 8 
 clang/lib/AST/Interp/ByteCodeStmtGen.h   | 1 +
 clang/test/AST/Interp/if.cpp | 7 +++
 3 files changed, 16 insertions(+)

diff --git a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp 
b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
index b7553d8963ff0ee..a0f50c3e69dd918 100644
--- a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -246,6 +246,8 @@ bool ByteCodeStmtGen::visitStmt(const Stmt *S) {
   case Stmt::GCCAsmStmtClass:
   case Stmt::MSAsmStmtClass:
 return visitAsmStmt(cast(S));
+  case Stmt::AttributedStmtClass:
+return visitAttributedStmt(cast(S));
   case Stmt::NullStmtClass:
 return true;
   default: {
@@ -628,6 +630,12 @@ bool ByteCodeStmtGen::visitAsmStmt(const AsmStmt 
*S) {
   return this->emitInvalid(S);
 }
 
+template 
+bool ByteCodeStmtGen::visitAttributedStmt(const AttributedStmt *S) {
+  // Ignore all attributes.
+  return this->visitStmt(S->getSubStmt());
+}
+
 namespace clang {
 namespace interp {
 
diff --git a/clang/lib/AST/Interp/ByteCodeStmtGen.h 
b/clang/lib/AST/Interp/ByteCodeStmtGen.h
index 278e804a803c951..3bdcdd78f397e5b 100644
--- a/clang/lib/AST/Interp/ByteCodeStmtGen.h
+++ b/clang/lib/AST/Interp/ByteCodeStmtGen.h
@@ -68,6 +68,7 @@ class ByteCodeStmtGen final : public ByteCodeExprGen 
{
   bool visitCaseStmt(const CaseStmt *S);
   bool visitDefaultStmt(const DefaultStmt *S);
   bool visitAsmStmt(const AsmStmt *S);
+  bool visitAttributedStmt(const AttributedStmt *S);
 
   bool emitLambdaStaticInvokerBody(const CXXMethodDecl *MD);
 
diff --git a/clang/test/AST/Interp/if.cpp b/clang/test/AST/Interp/if.cpp
index 2449ace4dd6c6b5..86ae8de6f73ebb7 100644
--- a/clang/test/AST/Interp/if.cpp
+++ b/clang/test/AST/Interp/if.cpp
@@ -43,4 +43,11 @@ namespace InitDecl {
 return false;
   }
   static_assert(!f2(), "");
+
+
+  constexpr int attrs() {
+if (1) [[likely]] {}
+return 1;
+  }
+  static_assert(attrs() == 1, "");
 };

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


[clang] [analyzer] Fix StackAddrEscapeChecker crash on temporary object fields (PR #66493)

2023-09-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang


Changes
Basically, the issue was that we should have unwrap the base region before we 
special handle temp object regions.

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

I also decided to add some extra range information to the diagnostics to make 
it consistent with the other reporting path.
--
Full diff: https://github.com/llvm/llvm-project/pull/66493.diff

2 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp 
(+4-2) 
- (added) clang/test/Analysis/stackaddrleak.cpp (+24) 



diff --git a/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
index 19ff8c8e2a171ae..23a774931b21dec 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
@@ -369,7 +369,7 @@ void StackAddrEscapeChecker::checkEndFunction(const 
ReturnStmt *RS,
   quot;Stack address stored into global 
variablequot;);
 
   for (const auto amp;P : Cb.V) {
-const MemRegion *Referrer = P.first;
+const MemRegion *Referrer = P.first-gt;getBaseRegion();
 const MemRegion *Referred = P.second;
 
 // Generate a report for this bug.
@@ -384,6 +384,8 @@ void StackAddrEscapeChecker::checkEndFunction(const 
ReturnStmt *RS,
   lt;lt; CommonSuffix;
   auto Report =
   
std::make_uniquelt;PathSensitiveBugReportgt;(*BT_stackleak, 
Out.str(), N);
+  if (Range.isValid())
+Report-gt;addRange(Range);
   Ctx.emitReport(std::move(Report));
   return;
 }
@@ -398,7 +400,7 @@ void StackAddrEscapeChecker::checkEndFunction(const 
ReturnStmt *RS,
 }(Referrer-gt;getMemorySpace());
 
 // This cast supposed to succeed.
-const VarRegion *ReferrerVar = 
castlt;VarRegiongt;(Referrer-gt;getBaseRegion());
+const auto *ReferrerVar = castlt;VarRegiongt;(Referrer);
 const std::string ReferrerVarName =
 ReferrerVar-gt;getDecl()-gt;getDeclName().getAsString();
 
diff --git a/clang/test/Analysis/stackaddrleak.cpp 
b/clang/test/Analysis/stackaddrleak.cpp
new file mode 100644
index 000..5828f2ac6e78c8d
--- /dev/null
+++ b/clang/test/Analysis/stackaddrleak.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core -verify %s
+
+void *operator new(unsigned long, void *p) { return p; }
+
+struct myfunction {
+  union storage_t {
+char buffer[100];
+unsigned long long max_align;
+  } storage;
+
+  template lt;typename Funcgt; myfunction(Func fn) {
+new (amp;storage.buffer) Func(fn);
+  }
+  void operator()();
+};
+
+myfunction create_func() {
+  int n;
+  auto c = [amp;n] {};
+  return c; // expected-warning {{Address of stack memory associated with 
local variable #x27;n#x27; is still referred to by a temporary object 
on the stack upon returning to the caller.  This will be a dangling reference}}
+}
+void gh_66221() {
+  create_func()();
+}




https://github.com/llvm/llvm-project/pull/66493
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][AST] fix lack comparison of declRefExpr in ASTStructuralEquivalence (PR #66041)

2023-09-15 Thread via cfe-commits

https://github.com/mzyKi edited https://github.com/llvm/llvm-project/pull/66041
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] fix lack comparison of declRefExpr in ASTStructuralEquivalence (PR #66041)

2023-09-15 Thread via cfe-commits

https://github.com/mzyKi resolved 
https://github.com/llvm/llvm-project/pull/66041
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] fix lack comparison of declRefExpr in ASTStructuralEquivalence (PR #66041)

2023-09-15 Thread via cfe-commits

https://github.com/mzyKi resolved 
https://github.com/llvm/llvm-project/pull/66041
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Fix StackAddrEscapeChecker crash on temporary object fields (PR #66493)

2023-09-15 Thread Balazs Benics via cfe-commits

https://github.com/steakhal created 
https://github.com/llvm/llvm-project/pull/66493

Basically, the issue was that we should have unwrap the base region before we 
special handle temp object regions.

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

I also decided to add some extra range information to the diagnostics to make 
it consistent with the other reporting path.

>From cfdbc40487481b341d42f0472e196ff4bd33 Mon Sep 17 00:00:00 2001
From: Balazs Benics 
Date: Fri, 15 Sep 2023 12:42:39 +0200
Subject: [PATCH] [analyzer] Fix StackAddrEscapeChecker crash on temporary
 object fields

Basically, the issue was that we should have unwrap the base region
before we special handle temp object regions.

Fixes https://github.com/llvm/llvm-project/issues/66221
---
 .../Checkers/StackAddrEscapeChecker.cpp   |  6 +++--
 clang/test/Analysis/stackaddrleak.cpp | 24 +++
 2 files changed, 28 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Analysis/stackaddrleak.cpp

diff --git a/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
index 19ff8c8e2a171ae..23a774931b21dec 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
@@ -369,7 +369,7 @@ void StackAddrEscapeChecker::checkEndFunction(const 
ReturnStmt *RS,
   "Stack address stored into global variable");
 
   for (const auto  : Cb.V) {
-const MemRegion *Referrer = P.first;
+const MemRegion *Referrer = P.first->getBaseRegion();
 const MemRegion *Referred = P.second;
 
 // Generate a report for this bug.
@@ -384,6 +384,8 @@ void StackAddrEscapeChecker::checkEndFunction(const 
ReturnStmt *RS,
   << CommonSuffix;
   auto Report =
   std::make_unique(*BT_stackleak, Out.str(), 
N);
+  if (Range.isValid())
+Report->addRange(Range);
   Ctx.emitReport(std::move(Report));
   return;
 }
@@ -398,7 +400,7 @@ void StackAddrEscapeChecker::checkEndFunction(const 
ReturnStmt *RS,
 }(Referrer->getMemorySpace());
 
 // This cast supposed to succeed.
-const VarRegion *ReferrerVar = cast(Referrer->getBaseRegion());
+const auto *ReferrerVar = cast(Referrer);
 const std::string ReferrerVarName =
 ReferrerVar->getDecl()->getDeclName().getAsString();
 
diff --git a/clang/test/Analysis/stackaddrleak.cpp 
b/clang/test/Analysis/stackaddrleak.cpp
new file mode 100644
index 000..5828f2ac6e78c8d
--- /dev/null
+++ b/clang/test/Analysis/stackaddrleak.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core -verify %s
+
+void *operator new(unsigned long, void *p) { return p; }
+
+struct myfunction {
+  union storage_t {
+char buffer[100];
+unsigned long long max_align;
+  } storage;
+
+  template  myfunction(Func fn) {
+new () Func(fn);
+  }
+  void operator()();
+};
+
+myfunction create_func() {
+  int n;
+  auto c = [] {};
+  return c; // expected-warning {{Address of stack memory associated with 
local variable 'n' is still referred to by a temporary object on the stack upon 
returning to the caller.  This will be a dangling reference}}
+}
+void gh_66221() {
+  create_func()();
+}

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


[clang] [clang] fix lack comparison of declRefExpr in ASTStructuralEquivalence (PR #66041)

2023-09-15 Thread via cfe-commits

https://github.com/mzyKi updated https://github.com/llvm/llvm-project/pull/66041

>From a1635d87e4b56b501403f1add333c97b96b30a0f Mon Sep 17 00:00:00 2001
From: miaozhiyuan 
Date: Tue, 12 Sep 2023 10:51:35 +0800
Subject: [PATCH] [clang][AST] fix lack comparison of declRefExpr in
 ASTStructuralEquivalence

---
 clang/docs/ReleaseNotes.rst   | 2 ++
 clang/lib/AST/ASTStructuralEquivalence.cpp| 9 +
 clang/unittests/AST/StructuralEquivalenceTest.cpp | 9 +
 3 files changed, 20 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3cdad2f7b9f0e5a..d112a8701d387af 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -218,6 +218,8 @@ Bug Fixes in This Version
   (`#65156 `_)
 - Clang no longer considers the loss of ``__unaligned`` qualifier from objects 
as
   an invalid conversion during method function overload resolution.
+- Fix lack of comparison of declRefExpr in ASTStructuralEquivalence
+  (`#66047 `_)
 - Fix parser crash when dealing with ill-formed objective C++ header code. 
Fixes
   (`#64836 `_)
 
diff --git a/clang/lib/AST/ASTStructuralEquivalence.cpp 
b/clang/lib/AST/ASTStructuralEquivalence.cpp
index 544420234ef0eb0..560d199620657a5 100644
--- a/clang/lib/AST/ASTStructuralEquivalence.cpp
+++ b/clang/lib/AST/ASTStructuralEquivalence.cpp
@@ -214,6 +214,15 @@ class StmtComparer {
 return E1->size() == E2->size();
   }
 
+  bool IsStmtEquivalent(const DeclRefExpr *DRE1, const DeclRefExpr *DRE2) {
+const ValueDecl *Decl1 = DRE1->getDecl();
+const ValueDecl *Decl2 = DRE2->getDecl();
+if (!Decl1 || !Decl2)
+  return false;
+return IsStructurallyEquivalent(Context, const_cast(Decl1),
+const_cast(Decl2));
+  }
+
   bool IsStmtEquivalent(const DependentScopeDeclRefExpr *DE1,
 const DependentScopeDeclRefExpr *DE2) {
 if (!IsStructurallyEquivalent(Context, DE1->getDeclName(),
diff --git a/clang/unittests/AST/StructuralEquivalenceTest.cpp 
b/clang/unittests/AST/StructuralEquivalenceTest.cpp
index 4e9f476659b9ee6..00041a2b2190089 100644
--- a/clang/unittests/AST/StructuralEquivalenceTest.cpp
+++ b/clang/unittests/AST/StructuralEquivalenceTest.cpp
@@ -2320,5 +2320,14 @@ TEST_F(StructuralEquivalenceStmtTest, UnresolvedLookup) {
   EXPECT_TRUE(testStructuralMatch(t));
 }
 
+TEST_F(StructuralEquivalenceStmtTest, DeclRefExpr) {
+  std::string Prefix = "enum Test { AAA, BBB };";
+  auto t = makeStmts(
+  Prefix + "void foo(int i) {if (i > 0) {i = AAA;} else {i = BBB;}}",
+  Prefix + "void foo(int i) {if (i > 0) {i = BBB;} else {i = AAA;}}",
+  Lang_CXX03, ifStmt());
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
 } // end namespace ast_matchers
 } // end namespace clang

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


[clang] [analyzer] Simplify SVal for simple NonLoc->Loc casts (PR #66463)

2023-09-15 Thread Ding Fei via cfe-commits

https://github.com/danix800 updated 
https://github.com/llvm/llvm-project/pull/66463

>From d48b57387e3dc1c2f3fdeae00fe1596b3466638d Mon Sep 17 00:00:00 2001
From: dingfei 
Date: Fri, 15 Sep 2023 14:01:26 +0800
Subject: [PATCH] [analyzer] Simplify SVal for simple NonLoc->Loc casts

NonLoc symbolic SVal to Loc casts are not supported except for
nonloc::ConcreteInt.

This change simplifies the source SVals so that the more casts can
go through nonloc::ConcreteInt->loc::ConcreteInt path. For example:

  void test_simplified_before_cast_add(long long t1) {
long long t2 = t1 + 3;
if (!t2) {
  int *p = (int *) t2;
  clang_analyzer_eval(p == 0); // expected-warning{{TRUE}}
}
  }

If simplified, 't2' is 0, resulting 'p' is nullptr, otherwise 'p'
is unknown.

Fixes #62232
---
 clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp |  3 ++-
 .../symbol-simplification-nonloc-loc.cpp  | 26 +++
 2 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp 
b/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
index 2a47116db55a1ad..7e431f7e598c4cb 100644
--- a/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
@@ -264,7 +264,8 @@ ProgramStateRef ExprEngine::handleLValueBitCast(
   }
   // Delegate to SValBuilder to process.
   SVal OrigV = state->getSVal(Ex, LCtx);
-  SVal V = svalBuilder.evalCast(OrigV, T, ExTy);
+  SVal SimplifiedOrigV = svalBuilder.simplifySVal(state, OrigV);
+  SVal V = svalBuilder.evalCast(SimplifiedOrigV, T, ExTy);
   // Negate the result if we're treating the boolean as a signed i1
   if (CastE->getCastKind() == CK_BooleanToSignedIntegral && V.isValid())
 V = svalBuilder.evalMinus(V.castAs());
diff --git a/clang/test/Analysis/symbol-simplification-nonloc-loc.cpp 
b/clang/test/Analysis/symbol-simplification-nonloc-loc.cpp
index 485f68d9a5acfba..619fda824cb70b5 100644
--- a/clang/test/Analysis/symbol-simplification-nonloc-loc.cpp
+++ b/clang/test/Analysis/symbol-simplification-nonloc-loc.cpp
@@ -1,6 +1,8 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=core %s \
 // RUN:-triple x86_64-pc-linux-gnu -verify
 
+void clang_analyzer_eval(int);
+
 #define BINOP(OP) [](auto x, auto y) { return x OP y; }
 
 template 
@@ -73,3 +75,27 @@ void zoo1backwards() {
   *(0 + p) = nullptr;  // warn
   **(0 + p) = 'a'; // no-warning: this should be unreachable
 }
+
+void test_simplified_before_cast_add(long t1) {
+  long long t2 = t1 + 3;
+  if (!t2) {
+int *p = (int *) t2;
+clang_analyzer_eval(p == 0); // expected-warning{{TRUE}}
+  }
+}
+
+void test_simplified_before_cast_sub(long t1) {
+  long long t2 = t1 - 3;
+  if (!t2) {
+int *p = (int *) t2;
+clang_analyzer_eval(p == 0); // expected-warning{{TRUE}}
+  }
+}
+
+void test_simplified_before_cast_mul(long t1) {
+  long long t2 = t1 * 3;
+  if (!t2) {
+int *p = (int *) t2;
+clang_analyzer_eval(p == 0); // expected-warning{{TRUE}}
+  }
+}

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


[clang] [analyzer] Simplify SVal for simple NonLoc->Loc casts (PR #66463)

2023-09-15 Thread Ding Fei via cfe-commits


@@ -0,0 +1,31 @@
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=false \
+// RUN:   -verify
+
+void clang_analyzer_eval(int);
+
+void test_simplified_before_cast_add(long long t1) {
+  long long t2 = t1 + 3;
+  if (!t2) {
+int *p = (int *) t2;
+clang_analyzer_eval(p == 0); // expected-warning{{TRUE}}
+  }
+}
+
+void test_simplified_before_cast_sub(long long t1) {
+  long long t2 = t1 - 3;
+  if (!t2) {
+int *p = (int *) t2;
+clang_analyzer_eval(p == 0); // expected-warning{{TRUE}}
+  }
+}
+
+void test_simplified_before_cast_mul(long long t1) {
+  long long t2 = t1 * 3;
+  if (!t2) {
+int *p = (int *) t2;
+clang_analyzer_eval(p == 0); // expected-warning{{TRUE}}
+  }
+}

danix800 wrote:

Moved this into `symbol-simplification-nonloc-loc.cpp`.

https://github.com/llvm/llvm-project/pull/66463
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Simplify SVal for simple NonLoc->Loc casts (PR #66463)

2023-09-15 Thread Ding Fei via cfe-commits


@@ -0,0 +1,31 @@
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=false \
+// RUN:   -verify
+
+void clang_analyzer_eval(int);
+
+void test_simplified_before_cast_add(long long t1) {
+  long long t2 = t1 + 3;
+  if (!t2) {
+int *p = (int *) t2;

danix800 wrote:

I'll move this into `symbol-simplification-nonloc-loc.cpp` which already 
restrict that target to be `x86_64`.

https://github.com/llvm/llvm-project/pull/66463
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] fix lack comparison of declRefExpr in ASTStructuralEquivalence (PR #66041)

2023-09-15 Thread via cfe-commits

https://github.com/mzyKi updated https://github.com/llvm/llvm-project/pull/66041

>From f74271d018d413832290e9d021ad6f25209a35fd Mon Sep 17 00:00:00 2001
From: miaozhiyuan 
Date: Tue, 12 Sep 2023 10:51:35 +0800
Subject: [PATCH] [clang][AST] fix lack comparison of declRefExpr in
 ASTStructuralEquivalence

---
 clang/docs/ReleaseNotes.rst   |  2 +
 clang/lib/AST/ASTStructuralEquivalence.cpp| 54 +++
 .../AST/StructuralEquivalenceTest.cpp |  9 
 3 files changed, 43 insertions(+), 22 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3cdad2f7b9f0e5a..58b8622ed42236d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -218,6 +218,8 @@ Bug Fixes in This Version
   (`#65156 `_)
 - Clang no longer considers the loss of ``__unaligned`` qualifier from objects 
as
   an invalid conversion during method function overload resolution.
+- Fix lack of comparison of declRefExpr in ASTStructuralEquivalence
+  (`#66047 `_`)
 - Fix parser crash when dealing with ill-formed objective C++ header code. 
Fixes
   (`#64836 `_)
 
diff --git a/clang/lib/AST/ASTStructuralEquivalence.cpp 
b/clang/lib/AST/ASTStructuralEquivalence.cpp
index 544420234ef0eb0..0f132b73c23b80b 100644
--- a/clang/lib/AST/ASTStructuralEquivalence.cpp
+++ b/clang/lib/AST/ASTStructuralEquivalence.cpp
@@ -214,6 +214,15 @@ class StmtComparer {
 return E1->size() == E2->size();
   }
 
+  bool IsStmtEquivalent(const DeclRefExpr *DRE1, const DeclRefExpr *DRE2) {
+const ValueDecl *Decl1 = DRE1->getDecl();
+const ValueDecl *Decl2 = DRE2->getDecl();
+if (!Decl1 || !Decl2)
+  return false;
+return IsStructurallyEquivalent(Context, const_cast(Decl1),
+const_cast(Decl2));
+  }
+
   bool IsStmtEquivalent(const DependentScopeDeclRefExpr *DE1,
 const DependentScopeDeclRefExpr *DE2) {
 if (!IsStructurallyEquivalent(Context, DE1->getDeclName(),
@@ -366,7 +375,8 @@ class StmtComparer {
 return true;
   }
 
-  bool IsStmtEquivalent(const CXXBoolLiteralExpr *E1, const CXXBoolLiteralExpr 
*E2) {
+  bool IsStmtEquivalent(const CXXBoolLiteralExpr *E1,
+const CXXBoolLiteralExpr *E2) {
 return E1->getValue() == E2->getValue();
   }
 
@@ -551,13 +561,12 @@ static bool 
IsStructurallyEquivalent(StructuralEquivalenceContext ,
P1->getIndex() == P2->getIndex();
   }
 
-   case TemplateName::Template:
-   case TemplateName::QualifiedTemplate:
-   case TemplateName::SubstTemplateTemplateParm:
-   case TemplateName::UsingTemplate:
- // It is sufficient to check value of getAsTemplateDecl.
- break;
-
+  case TemplateName::Template:
+  case TemplateName::QualifiedTemplate:
+  case TemplateName::SubstTemplateTemplateParm:
+  case TemplateName::UsingTemplate:
+// It is sufficient to check value of getAsTemplateDecl.
+break;
   }
 
   return true;
@@ -579,18 +588,20 @@ static bool 
IsStructurallyEquivalent(StructuralEquivalenceContext ,
 return true;
 
   case TemplateArgument::Type:
-return IsStructurallyEquivalent(Context, Arg1.getAsType(), 
Arg2.getAsType());
+return IsStructurallyEquivalent(Context, Arg1.getAsType(),
+Arg2.getAsType());
 
   case TemplateArgument::Integral:
 if (!IsStructurallyEquivalent(Context, Arg1.getIntegralType(),
-  Arg2.getIntegralType()))
+  Arg2.getIntegralType()))
   return false;
 
 return llvm::APSInt::isSameValue(Arg1.getAsIntegral(),
  Arg2.getAsIntegral());
 
   case TemplateArgument::Declaration:
-return IsStructurallyEquivalent(Context, Arg1.getAsDecl(), 
Arg2.getAsDecl());
+return IsStructurallyEquivalent(Context, Arg1.getAsDecl(),
+Arg2.getAsDecl());
 
   case TemplateArgument::NullPtr:
 return true; // FIXME: Is this correct?
@@ -1402,8 +1413,8 @@ static bool 
IsStructurallyEquivalent(StructuralEquivalenceContext ,
   }
 
   // Check the prototypes.
-  if (!::IsStructurallyEquivalent(Context,
-  Method1->getType(), Method2->getType()))
+  if (!::IsStructurallyEquivalent(Context, Method1->getType(),
+  Method2->getType()))
 return false;
 
   return true;
@@ -1902,8 +1913,9 @@ static bool 
IsStructurallyEquivalent(StructuralEquivalenceContext ,
   D2->getTemplateParameters());
 }
 
-static bool IsTemplateDeclCommonStructurallyEquivalent(
-StructuralEquivalenceContext , TemplateDecl *D1, TemplateDecl *D2) {
+static bool
+IsTemplateDeclCommonStructurallyEquivalent(StructuralEquivalenceContext ,
+   

[clang] Replace llvm.memcpy et al's i1 isVolatile with i8 VolFlags (PR #65748)

2023-09-15 Thread Simon Pilgrim via cfe-commits


@@ -24790,8 +24790,8 @@ static SDValue LowerVACOPY(SDValue Op, const 
X86Subtarget ,
   return DAG.getMemcpy(
   Chain, DL, DstPtr, SrcPtr,
   DAG.getIntPtrConstant(Subtarget.isTarget64BitLP64() ? 24 : 16, DL),
-  Align(Subtarget.isTarget64BitLP64() ? 8 : 4), /*isVolatile*/ false, 
false,
-  false, MachinePointerInfo(DstSV), MachinePointerInfo(SrcSV));
+  Align(Subtarget.isTarget64BitLP64() ? 8 : 4), /*Vol=*/{false, false},

RKSimon wrote:

No preference for names - do we need to handle runtime bool values or could a 
few basic hardcoded combos be enough MemTransferVolatility::neverVolatile() / 
MemTransferVolatility::readVolatile() ?

https://github.com/llvm/llvm-project/pull/65748
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Simplify SVal for simple NonLoc->Loc casts (PR #66463)

2023-09-15 Thread Ding Fei via cfe-commits


@@ -264,7 +264,8 @@ ProgramStateRef ExprEngine::handleLValueBitCast(
   }
   // Delegate to SValBuilder to process.
   SVal OrigV = state->getSVal(Ex, LCtx);
-  SVal V = svalBuilder.evalCast(OrigV, T, ExTy);
+  SVal SimplifiedOrigV = svalBuilder.simplifySVal(state, OrigV);
+  SVal V = svalBuilder.evalCast(SimplifiedOrigV, T, ExTy);

danix800 wrote:

Bound value might not be used at all, so I think lazy simplification would be 
better.

https://github.com/llvm/llvm-project/pull/66463
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Introduce paged vector (PR #66430)

2023-09-15 Thread Giulio Eulisse via cfe-commits

https://github.com/ktf updated https://github.com/llvm/llvm-project/pull/66430

>From b952f0577dfe8112f394bd5392212f843c0cc86e Mon Sep 17 00:00:00 2001
From: Giulio Eulisse <10544+...@users.noreply.github.com>
Date: Thu, 14 Sep 2023 21:58:21 +0200
Subject: [PATCH 01/12] Introduce PagedVector class

The goal of the class is to be an (almost) drop in replacement for
SmallVector and std::vector when those are presized and filled later,
as it happens in SourceManager and ASTReader.

By splitting the actual vector in pages of the same size and allocating
the pages only when they are needed, using this containers reduces the
memory usage by a factor 4 for the cases relevant to the ALICE
experiment ROOT / cling usage.
---
 llvm/include/llvm/ADT/PagedVector.h | 96 +
 1 file changed, 96 insertions(+)
 create mode 100644 llvm/include/llvm/ADT/PagedVector.h

diff --git a/llvm/include/llvm/ADT/PagedVector.h 
b/llvm/include/llvm/ADT/PagedVector.h
new file mode 100644
index 000..dab0d249aa706e4
--- /dev/null
+++ b/llvm/include/llvm/ADT/PagedVector.h
@@ -0,0 +1,96 @@
+//===- llvm/ADT/PagedVector.h - 'Lazyly allocated' vectors *- C++
+//-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file defines the PagedVector class.
+//
+//===--===//
+#ifndef LLVM_ADT_PAGEDVECTOR_H
+#define LLVM_ADT_PAGEDVECTOR_H
+
+#include 
+
+// Notice that this does not have iterators, because if you
+// have iterators it probably means you are going to touch
+// all the memory in any case, so better use a std::vector in
+// the first place.
+template  class PagedVector {
+  size_t Size = 0;
+  // Index of where to find a given page in the data
+  mutable std::vector Lookup;
+  // Actual data
+  mutable std::vector Data;
+
+public:
+  // Add a range to the vector.
+  // When vector is accessed, it will call the callback to fill the range
+  // with data.
+
+  // Lookup an element at position i.
+  // If the given range is not filled, it will be filled.
+  // If the given range is filled, return the element.
+  T [](int Index) const { return at(Index); }
+
+  T (int Index) const {
+auto  = Lookup[Index / PAGE_SIZE];
+// If the range is not filled, fill it
+if (PageId == -1) {
+  int OldSize = Data.size();
+  PageId = OldSize / PAGE_SIZE;
+  // Allocate the memory
+  Data.resize(OldSize + PAGE_SIZE);
+  // Fill the whole capacity with empty elements
+  for (int I = 0; I < PAGE_SIZE; ++I) {
+Data[I + OldSize] = T();
+  }
+}
+// Return the element
+return Data[Index % PAGE_SIZE + PAGE_SIZE * PageId];
+  }
+
+  // Return the size of the vector
+  size_t capacity() const { return Lookup.size() * PAGE_SIZE; }
+
+  size_t size() const { return Size; }
+
+  // Expands the vector to the given size.
+  // If the vector is already bigger, does nothing.
+  void expand(size_t NewSize) {
+// You cannot shrink the vector, otherwise
+// you would have to invalidate
+assert(NewSize >= Size);
+if (NewSize <= Size) {
+  return;
+}
+if (NewSize <= capacity()) {
+  Size = NewSize;
+  return;
+}
+auto Pages = NewSize / PAGE_SIZE;
+auto Remainder = NewSize % PAGE_SIZE;
+if (Remainder) {
+  Pages += 1;
+}
+assert(Pages > Lookup.size());
+Lookup.resize(Pages, -1);
+Size = NewSize;
+  }
+
+  // Return true if the vector is empty
+  bool empty() const { return Size == 0; }
+  /// Clear the vector
+  void clear() {
+Size = 0;
+Lookup.clear();
+Data.clear();
+  }
+
+  std::vector const () const { return Data; }
+};
+
+#endif // LLVM_ADT_PAGEDVECTOR_H

>From f0c75c8af0fea27b5b758e2e5775787f33595de3 Mon Sep 17 00:00:00 2001
From: Giulio Eulisse <10544+...@users.noreply.github.com>
Date: Thu, 14 Sep 2023 22:20:29 +0200
Subject: [PATCH 02/12] Use PagedVector to reduce memory usage of sparsely
 populated vectors

---
 clang/include/clang/Basic/SourceManager.h |  3 ++-
 clang/include/clang/Serialization/ASTReader.h |  5 +++--
 clang/lib/Basic/SourceManager.cpp | 12 ++--
 clang/lib/Serialization/ASTReader.cpp |  9 +
 4 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/clang/include/clang/Basic/SourceManager.h 
b/clang/include/clang/Basic/SourceManager.h
index 2f846502d6f3327..b1942a3d86afc37 100644
--- a/clang/include/clang/Basic/SourceManager.h
+++ b/clang/include/clang/Basic/SourceManager.h
@@ -43,6 +43,7 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/ADT/PagedVector.h"
 #include "llvm/ADT/PointerIntPair.h"
 #include 

[clang] Introduce paged vector (PR #66430)

2023-09-15 Thread Vassil Vassilev via cfe-commits

vgvassilev wrote:

> @vgvassilev done.
> 
> @ChuanqiXu9 I think I addressed all your additional comments and updated the 
> PR. Please let me know if you have further ones or if you want me to squash 
> the commits into one.

I think we need to add some test on the clang modules side. I am currently 
thinking how.. 

https://github.com/llvm/llvm-project/pull/66430
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] fix lack comparison of declRefExpr in ASTStructuralEquivalence (PR #66041)

2023-09-15 Thread Ding Fei via cfe-commits


@@ -2320,5 +2320,14 @@ TEST_F(StructuralEquivalenceStmtTest, UnresolvedLookup) {
   EXPECT_TRUE(testStructuralMatch(t));
 }
 
+TEST_F(StructuralEquivalenceStmtTest, DeclRefENoEq) {

danix800 wrote:

```suggestion
TEST_F(StructuralEquivalenceStmtTest, DeclRefExpr) {
```

https://github.com/llvm/llvm-project/pull/66041
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Introduce paged vector (PR #66430)

2023-09-15 Thread Giulio Eulisse via cfe-commits

ktf wrote:

@vgvassilev done.

@ChuanqiXu9 I think I addressed all your additional comments and updated the 
PR. Please let me know if you have further ones or if you want me to squash the 
commits into one.

https://github.com/llvm/llvm-project/pull/66430
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Introduce paged vector (PR #66430)

2023-09-15 Thread Giulio Eulisse via cfe-commits

https://github.com/ktf edited https://github.com/llvm/llvm-project/pull/66430
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] fix lack comparison of declRefExpr in ASTStructuralEquivalence (PR #66041)

2023-09-15 Thread Ding Fei via cfe-commits


@@ -218,6 +218,8 @@ Bug Fixes in This Version
   (`#65156 `_)
 - Clang no longer considers the loss of ``__unaligned`` qualifier from objects 
as
   an invalid conversion during method function overload resolution.
+- Fix lack of comparison of declRefExpr in ASTStructuralEquivalence
+  (`#66047 `_`)

danix800 wrote:

```suggestion
  (`#66047 `_)
```

https://github.com/llvm/llvm-project/pull/66041
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clangd] [C++20] [Modules] Introduce initial support for C++20 Modules (PR #66462)

2023-09-15 Thread Arthur Laurent via cfe-commits

Arthapz wrote:

Oh nice going to try this :)

https://github.com/llvm/llvm-project/pull/66462
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Introduce paged vector (PR #66430)

2023-09-15 Thread Giulio Eulisse via cfe-commits

https://github.com/ktf updated https://github.com/llvm/llvm-project/pull/66430

>From b952f0577dfe8112f394bd5392212f843c0cc86e Mon Sep 17 00:00:00 2001
From: Giulio Eulisse <10544+...@users.noreply.github.com>
Date: Thu, 14 Sep 2023 21:58:21 +0200
Subject: [PATCH 01/11] Introduce PagedVector class

The goal of the class is to be an (almost) drop in replacement for
SmallVector and std::vector when those are presized and filled later,
as it happens in SourceManager and ASTReader.

By splitting the actual vector in pages of the same size and allocating
the pages only when they are needed, using this containers reduces the
memory usage by a factor 4 for the cases relevant to the ALICE
experiment ROOT / cling usage.
---
 llvm/include/llvm/ADT/PagedVector.h | 96 +
 1 file changed, 96 insertions(+)
 create mode 100644 llvm/include/llvm/ADT/PagedVector.h

diff --git a/llvm/include/llvm/ADT/PagedVector.h 
b/llvm/include/llvm/ADT/PagedVector.h
new file mode 100644
index 000..dab0d249aa706e4
--- /dev/null
+++ b/llvm/include/llvm/ADT/PagedVector.h
@@ -0,0 +1,96 @@
+//===- llvm/ADT/PagedVector.h - 'Lazyly allocated' vectors *- C++
+//-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file defines the PagedVector class.
+//
+//===--===//
+#ifndef LLVM_ADT_PAGEDVECTOR_H
+#define LLVM_ADT_PAGEDVECTOR_H
+
+#include 
+
+// Notice that this does not have iterators, because if you
+// have iterators it probably means you are going to touch
+// all the memory in any case, so better use a std::vector in
+// the first place.
+template  class PagedVector {
+  size_t Size = 0;
+  // Index of where to find a given page in the data
+  mutable std::vector Lookup;
+  // Actual data
+  mutable std::vector Data;
+
+public:
+  // Add a range to the vector.
+  // When vector is accessed, it will call the callback to fill the range
+  // with data.
+
+  // Lookup an element at position i.
+  // If the given range is not filled, it will be filled.
+  // If the given range is filled, return the element.
+  T [](int Index) const { return at(Index); }
+
+  T (int Index) const {
+auto  = Lookup[Index / PAGE_SIZE];
+// If the range is not filled, fill it
+if (PageId == -1) {
+  int OldSize = Data.size();
+  PageId = OldSize / PAGE_SIZE;
+  // Allocate the memory
+  Data.resize(OldSize + PAGE_SIZE);
+  // Fill the whole capacity with empty elements
+  for (int I = 0; I < PAGE_SIZE; ++I) {
+Data[I + OldSize] = T();
+  }
+}
+// Return the element
+return Data[Index % PAGE_SIZE + PAGE_SIZE * PageId];
+  }
+
+  // Return the size of the vector
+  size_t capacity() const { return Lookup.size() * PAGE_SIZE; }
+
+  size_t size() const { return Size; }
+
+  // Expands the vector to the given size.
+  // If the vector is already bigger, does nothing.
+  void expand(size_t NewSize) {
+// You cannot shrink the vector, otherwise
+// you would have to invalidate
+assert(NewSize >= Size);
+if (NewSize <= Size) {
+  return;
+}
+if (NewSize <= capacity()) {
+  Size = NewSize;
+  return;
+}
+auto Pages = NewSize / PAGE_SIZE;
+auto Remainder = NewSize % PAGE_SIZE;
+if (Remainder) {
+  Pages += 1;
+}
+assert(Pages > Lookup.size());
+Lookup.resize(Pages, -1);
+Size = NewSize;
+  }
+
+  // Return true if the vector is empty
+  bool empty() const { return Size == 0; }
+  /// Clear the vector
+  void clear() {
+Size = 0;
+Lookup.clear();
+Data.clear();
+  }
+
+  std::vector const () const { return Data; }
+};
+
+#endif // LLVM_ADT_PAGEDVECTOR_H

>From f0c75c8af0fea27b5b758e2e5775787f33595de3 Mon Sep 17 00:00:00 2001
From: Giulio Eulisse <10544+...@users.noreply.github.com>
Date: Thu, 14 Sep 2023 22:20:29 +0200
Subject: [PATCH 02/11] Use PagedVector to reduce memory usage of sparsely
 populated vectors

---
 clang/include/clang/Basic/SourceManager.h |  3 ++-
 clang/include/clang/Serialization/ASTReader.h |  5 +++--
 clang/lib/Basic/SourceManager.cpp | 12 ++--
 clang/lib/Serialization/ASTReader.cpp |  9 +
 4 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/clang/include/clang/Basic/SourceManager.h 
b/clang/include/clang/Basic/SourceManager.h
index 2f846502d6f3327..b1942a3d86afc37 100644
--- a/clang/include/clang/Basic/SourceManager.h
+++ b/clang/include/clang/Basic/SourceManager.h
@@ -43,6 +43,7 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/ADT/PagedVector.h"
 #include "llvm/ADT/PointerIntPair.h"
 #include 

[clang] Bugfix for chosing the correct deduction guide (PR #66487)

2023-09-15 Thread via cfe-commits

https://github.com/HoBoIs created 
https://github.com/llvm/llvm-project/pull/66487

If there is 2 guides one of them generated from a non-templated constructor and 
one of them from a templated constructor the standard gives priority to the 
first. Clang detected ambiguity before, now the correct guide is chosen.

Example for the bug:
https://godbolt.org/z/ee3e9qG78

Also a minor fix for issue #64020

I'm a new developer, can someone with more experience in clang check if the 
change in file "clang/lib/Sema/SemaTemplateInstantiateDecl.cpp" can never cause 
a use after free.

>From 5abc9393bf68d14b8cb9cc5cc86a854e3a2aeae5 Mon Sep 17 00:00:00 2001
From: hobois 
Date: Fri, 15 Sep 2023 09:28:21 +0200
Subject: [PATCH] Bugfix for chosing the correct deduction guide

If there is 2 guides one of them generated from a non-templated constructor and 
one of them from a templated constructor the standard gives priority to the 
first. Clang detected ambiguity before, now the correct guide is chosen.

Also a minor fix for issue #64020
---
 clang/lib/Sema/SemaOverload.cpp| 14 +-
 clang/lib/Sema/SemaTemplateInstantiateDecl.cpp |  2 +-
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 45a9e5dc98c032d..ec902fcad817e76 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -10153,6 +10153,18 @@ bool clang::isBetterOverloadCandidate(
   //  -- F1 is the copy deduction candidate(16.3.1.8) and F2 is not
   if (Guide1->getDeductionCandidateKind() == DeductionCandidate::Copy)
 return true;
+  if (Guide2->getDeductionCandidateKind() == DeductionCandidate::Copy)
+return false;
+
+  //  --F1 is generated from a non-template constructor and F2 is 
generated from a constructor template
+  const auto* Constructor1 = Guide1->getCorrespondingConstructor();
+  const auto* Constructor2 = Guide2->getCorrespondingConstructor();
+  if (Constructor1 && Constructor2){
+bool isC1Templated = Constructor1->getTemplatedKind() != 
FunctionDecl::TemplatedKind::TK_NonTemplate;
+bool isC2Templated = Constructor2->getTemplatedKind() != 
FunctionDecl::TemplatedKind::TK_NonTemplate;
+if (isC1Templated != isC2Templated)
+  return isC2Templated;
+  }
 }
   }
 
@@ -10196,7 +10208,7 @@ bool clang::isBetterOverloadCandidate(
 if (AS1 != AS2) {
   if (Qualifiers::isAddressSpaceSupersetOf(AS2, AS1))
 return true;
-  if (Qualifiers::isAddressSpaceSupersetOf(AS2, AS1))
+  if (Qualifiers::isAddressSpaceSupersetOf(AS1, AS2))
 return false;
 }
   }
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 9e5f85b0f9166bd..b9c4a9db842b9ee 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -2129,7 +2129,7 @@ Decl *TemplateDeclInstantiator::VisitFunctionDecl(
 Function = CXXDeductionGuideDecl::Create(
 SemaRef.Context, DC, D->getInnerLocStart(),
 InstantiatedExplicitSpecifier, NameInfo, T, TInfo,
-D->getSourceRange().getEnd(), /*Ctor=*/nullptr,
+D->getSourceRange().getEnd(), DGuide->getCorrespondingConstructor(),
 DGuide->getDeductionCandidateKind());
 Function->setAccess(D->getAccess());
   } else {

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


[clang] Introduce paged vector (PR #66430)

2023-09-15 Thread Giulio Eulisse via cfe-commits

https://github.com/ktf edited https://github.com/llvm/llvm-project/pull/66430
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Introduce paged vector (PR #66430)

2023-09-15 Thread Giulio Eulisse via cfe-commits

https://github.com/ktf updated https://github.com/llvm/llvm-project/pull/66430

>From b952f0577dfe8112f394bd5392212f843c0cc86e Mon Sep 17 00:00:00 2001
From: Giulio Eulisse <10544+...@users.noreply.github.com>
Date: Thu, 14 Sep 2023 21:58:21 +0200
Subject: [PATCH 01/10] Introduce PagedVector class

The goal of the class is to be an (almost) drop in replacement for
SmallVector and std::vector when those are presized and filled later,
as it happens in SourceManager and ASTReader.

By splitting the actual vector in pages of the same size and allocating
the pages only when they are needed, using this containers reduces the
memory usage by a factor 4 for the cases relevant to the ALICE
experiment ROOT / cling usage.
---
 llvm/include/llvm/ADT/PagedVector.h | 96 +
 1 file changed, 96 insertions(+)
 create mode 100644 llvm/include/llvm/ADT/PagedVector.h

diff --git a/llvm/include/llvm/ADT/PagedVector.h 
b/llvm/include/llvm/ADT/PagedVector.h
new file mode 100644
index 000..dab0d249aa706e4
--- /dev/null
+++ b/llvm/include/llvm/ADT/PagedVector.h
@@ -0,0 +1,96 @@
+//===- llvm/ADT/PagedVector.h - 'Lazyly allocated' vectors *- C++
+//-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file defines the PagedVector class.
+//
+//===--===//
+#ifndef LLVM_ADT_PAGEDVECTOR_H
+#define LLVM_ADT_PAGEDVECTOR_H
+
+#include 
+
+// Notice that this does not have iterators, because if you
+// have iterators it probably means you are going to touch
+// all the memory in any case, so better use a std::vector in
+// the first place.
+template  class PagedVector {
+  size_t Size = 0;
+  // Index of where to find a given page in the data
+  mutable std::vector Lookup;
+  // Actual data
+  mutable std::vector Data;
+
+public:
+  // Add a range to the vector.
+  // When vector is accessed, it will call the callback to fill the range
+  // with data.
+
+  // Lookup an element at position i.
+  // If the given range is not filled, it will be filled.
+  // If the given range is filled, return the element.
+  T [](int Index) const { return at(Index); }
+
+  T (int Index) const {
+auto  = Lookup[Index / PAGE_SIZE];
+// If the range is not filled, fill it
+if (PageId == -1) {
+  int OldSize = Data.size();
+  PageId = OldSize / PAGE_SIZE;
+  // Allocate the memory
+  Data.resize(OldSize + PAGE_SIZE);
+  // Fill the whole capacity with empty elements
+  for (int I = 0; I < PAGE_SIZE; ++I) {
+Data[I + OldSize] = T();
+  }
+}
+// Return the element
+return Data[Index % PAGE_SIZE + PAGE_SIZE * PageId];
+  }
+
+  // Return the size of the vector
+  size_t capacity() const { return Lookup.size() * PAGE_SIZE; }
+
+  size_t size() const { return Size; }
+
+  // Expands the vector to the given size.
+  // If the vector is already bigger, does nothing.
+  void expand(size_t NewSize) {
+// You cannot shrink the vector, otherwise
+// you would have to invalidate
+assert(NewSize >= Size);
+if (NewSize <= Size) {
+  return;
+}
+if (NewSize <= capacity()) {
+  Size = NewSize;
+  return;
+}
+auto Pages = NewSize / PAGE_SIZE;
+auto Remainder = NewSize % PAGE_SIZE;
+if (Remainder) {
+  Pages += 1;
+}
+assert(Pages > Lookup.size());
+Lookup.resize(Pages, -1);
+Size = NewSize;
+  }
+
+  // Return true if the vector is empty
+  bool empty() const { return Size == 0; }
+  /// Clear the vector
+  void clear() {
+Size = 0;
+Lookup.clear();
+Data.clear();
+  }
+
+  std::vector const () const { return Data; }
+};
+
+#endif // LLVM_ADT_PAGEDVECTOR_H

>From f0c75c8af0fea27b5b758e2e5775787f33595de3 Mon Sep 17 00:00:00 2001
From: Giulio Eulisse <10544+...@users.noreply.github.com>
Date: Thu, 14 Sep 2023 22:20:29 +0200
Subject: [PATCH 02/10] Use PagedVector to reduce memory usage of sparsely
 populated vectors

---
 clang/include/clang/Basic/SourceManager.h |  3 ++-
 clang/include/clang/Serialization/ASTReader.h |  5 +++--
 clang/lib/Basic/SourceManager.cpp | 12 ++--
 clang/lib/Serialization/ASTReader.cpp |  9 +
 4 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/clang/include/clang/Basic/SourceManager.h 
b/clang/include/clang/Basic/SourceManager.h
index 2f846502d6f3327..b1942a3d86afc37 100644
--- a/clang/include/clang/Basic/SourceManager.h
+++ b/clang/include/clang/Basic/SourceManager.h
@@ -43,6 +43,7 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/ADT/PagedVector.h"
 #include "llvm/ADT/PointerIntPair.h"
 #include 

[clang] Introduce paged vector (PR #66430)

2023-09-15 Thread Vassil Vassilev via cfe-commits

vgvassilev wrote:

> @ChuanqiXu9 I have added a simple unit test, which has 100% code coverage as 
> far as I can tell and covers the usecase the container will be used for.
> 
> @nikic This is in the context of improving the memory used when loading 
> modules, in particular my usecase is the runtime overhead of the ROOT/cling 
> C++ interpreter / I/O subsystem.
> 
> Without this patch, the initialisation of the system, which on startup loads 
> a bunch of unneeded modules, grows to up 80 MB as you can see from:
> 
> ![image](https://user-images.githubusercontent.com/10544/268231067-9c2c7dc3-8e64-403c-a923-97a40cd8f1ff.png)
> 
> With this patch applied, the total overhead goes down to 52MB:
> 
> ![image](https://user-images.githubusercontent.com/10544/268231334-56111b37-fa0e-415d-8d00-0bcd818db3aa.png)
> 
> As you can see the `ROOT::Internal::GetROOT2()` initialisation method goes 
> from 67 to 30 MB (with some of the allocations which are now moved later on, 
> due to the lazy allocation of the PagedVector).

@ktf, could you update the description of the PR including details about the 
reasoning of this change and the current benchmarks.

@nikic, this work is in the context of 
https://github.com/root-project/root/issues/13000. 

TL;DR: The downstream client has a long running session and preloads a 
relatively large list of modules. The clang::ASTReader does almost all of of 
the work lazily when a declaration is needed. However, in a few places we 
pre-allocate large vectors (for types or source locations for the entire module 
file) just to make  sure the sequencing is right. While this patch will not 
make this lazy, as we should, it goes a long way towards making this a 
relatively cheap for module content which is sparsely used. One good example 
where this easily becomes a problem is building a pcm file for boost.

https://github.com/llvm/llvm-project/pull/66430
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tidy]add new check `bugprone-compare-pointer-to-member-virtual-function` (PR #66055)

2023-09-15 Thread Piotr Zegar via cfe-commits

PiotrZSL wrote:

I run this check on two bigger projects, didn't found anything (I was expecting 
it wont).
So at least in case of false-positives it looks fine.

https://github.com/llvm/llvm-project/pull/66055
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] fix lack comparison of declRefExpr in ASTStructuralEquivalence (PR #66041)

2023-09-15 Thread via cfe-commits

https://github.com/mzyKi updated https://github.com/llvm/llvm-project/pull/66041

>From 011c3997ac72918b23db511b94184e9fc5351a54 Mon Sep 17 00:00:00 2001
From: miaozhiyuan 
Date: Tue, 12 Sep 2023 10:51:35 +0800
Subject: [PATCH] [clang] fix lack comparison of declRefExpr in
 ASTStructuralEquivalence

---
 clang/docs/ReleaseNotes.rst   |  2 +
 clang/lib/AST/ASTStructuralEquivalence.cpp| 54 +++
 .../AST/StructuralEquivalenceTest.cpp |  9 
 3 files changed, 43 insertions(+), 22 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3cdad2f7b9f0e5a..58b8622ed42236d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -218,6 +218,8 @@ Bug Fixes in This Version
   (`#65156 `_)
 - Clang no longer considers the loss of ``__unaligned`` qualifier from objects 
as
   an invalid conversion during method function overload resolution.
+- Fix lack of comparison of declRefExpr in ASTStructuralEquivalence
+  (`#66047 `_`)
 - Fix parser crash when dealing with ill-formed objective C++ header code. 
Fixes
   (`#64836 `_)
 
diff --git a/clang/lib/AST/ASTStructuralEquivalence.cpp 
b/clang/lib/AST/ASTStructuralEquivalence.cpp
index 544420234ef0eb0..0f132b73c23b80b 100644
--- a/clang/lib/AST/ASTStructuralEquivalence.cpp
+++ b/clang/lib/AST/ASTStructuralEquivalence.cpp
@@ -214,6 +214,15 @@ class StmtComparer {
 return E1->size() == E2->size();
   }
 
+  bool IsStmtEquivalent(const DeclRefExpr *DRE1, const DeclRefExpr *DRE2) {
+const ValueDecl *Decl1 = DRE1->getDecl();
+const ValueDecl *Decl2 = DRE2->getDecl();
+if (!Decl1 || !Decl2)
+  return false;
+return IsStructurallyEquivalent(Context, const_cast(Decl1),
+const_cast(Decl2));
+  }
+
   bool IsStmtEquivalent(const DependentScopeDeclRefExpr *DE1,
 const DependentScopeDeclRefExpr *DE2) {
 if (!IsStructurallyEquivalent(Context, DE1->getDeclName(),
@@ -366,7 +375,8 @@ class StmtComparer {
 return true;
   }
 
-  bool IsStmtEquivalent(const CXXBoolLiteralExpr *E1, const CXXBoolLiteralExpr 
*E2) {
+  bool IsStmtEquivalent(const CXXBoolLiteralExpr *E1,
+const CXXBoolLiteralExpr *E2) {
 return E1->getValue() == E2->getValue();
   }
 
@@ -551,13 +561,12 @@ static bool 
IsStructurallyEquivalent(StructuralEquivalenceContext ,
P1->getIndex() == P2->getIndex();
   }
 
-   case TemplateName::Template:
-   case TemplateName::QualifiedTemplate:
-   case TemplateName::SubstTemplateTemplateParm:
-   case TemplateName::UsingTemplate:
- // It is sufficient to check value of getAsTemplateDecl.
- break;
-
+  case TemplateName::Template:
+  case TemplateName::QualifiedTemplate:
+  case TemplateName::SubstTemplateTemplateParm:
+  case TemplateName::UsingTemplate:
+// It is sufficient to check value of getAsTemplateDecl.
+break;
   }
 
   return true;
@@ -579,18 +588,20 @@ static bool 
IsStructurallyEquivalent(StructuralEquivalenceContext ,
 return true;
 
   case TemplateArgument::Type:
-return IsStructurallyEquivalent(Context, Arg1.getAsType(), 
Arg2.getAsType());
+return IsStructurallyEquivalent(Context, Arg1.getAsType(),
+Arg2.getAsType());
 
   case TemplateArgument::Integral:
 if (!IsStructurallyEquivalent(Context, Arg1.getIntegralType(),
-  Arg2.getIntegralType()))
+  Arg2.getIntegralType()))
   return false;
 
 return llvm::APSInt::isSameValue(Arg1.getAsIntegral(),
  Arg2.getAsIntegral());
 
   case TemplateArgument::Declaration:
-return IsStructurallyEquivalent(Context, Arg1.getAsDecl(), 
Arg2.getAsDecl());
+return IsStructurallyEquivalent(Context, Arg1.getAsDecl(),
+Arg2.getAsDecl());
 
   case TemplateArgument::NullPtr:
 return true; // FIXME: Is this correct?
@@ -1402,8 +1413,8 @@ static bool 
IsStructurallyEquivalent(StructuralEquivalenceContext ,
   }
 
   // Check the prototypes.
-  if (!::IsStructurallyEquivalent(Context,
-  Method1->getType(), Method2->getType()))
+  if (!::IsStructurallyEquivalent(Context, Method1->getType(),
+  Method2->getType()))
 return false;
 
   return true;
@@ -1902,8 +1913,9 @@ static bool 
IsStructurallyEquivalent(StructuralEquivalenceContext ,
   D2->getTemplateParameters());
 }
 
-static bool IsTemplateDeclCommonStructurallyEquivalent(
-StructuralEquivalenceContext , TemplateDecl *D1, TemplateDecl *D2) {
+static bool
+IsTemplateDeclCommonStructurallyEquivalent(StructuralEquivalenceContext ,
+   

[clang-tools-extra] [include-cleaner] Respect the UsingShadowDecl when find headers for ambiguous std symbols. (PR #66485)

2023-09-15 Thread Haojian Wu via cfe-commits

https://github.com/hokein created 
https://github.com/llvm/llvm-project/pull/66485

In libcpp, the `std::remove(const char*)` is a using decl in std namespace 
`using ::remove`, which was not handled correctly in 
`headerForAmbiguousStdSymbol`

>From ffd109a7b4273d6a1dc5810b64039a110a4147c9 Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Fri, 15 Sep 2023 11:59:06 +0200
Subject: [PATCH] [include-cleaner] Respect the UsingShadowDecl when find
 headers for ambiguous std symbols.

In libcpp, the `std::remove(const char*)` is a using decl in std
namespace `using ::remove`, which was not handled correctly in
`headerForAmbiguousStdSymbol`
---
 .../include-cleaner/lib/FindHeaders.cpp   |  3 ++
 .../unittests/FindHeadersTest.cpp | 31 +++
 2 files changed, 34 insertions(+)

diff --git a/clang-tools-extra/include-cleaner/lib/FindHeaders.cpp 
b/clang-tools-extra/include-cleaner/lib/FindHeaders.cpp
index 06e5e1812ba7218..fd2de6a17ad4a53 100644
--- a/clang-tools-extra/include-cleaner/lib/FindHeaders.cpp
+++ b/clang-tools-extra/include-cleaner/lib/FindHeaders.cpp
@@ -13,6 +13,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclBase.h"
+#include "clang/AST/DeclCXX.h"
 #include "clang/Basic/Builtins.h"
 #include "clang/Basic/FileEntry.h"
 #include "clang/Basic/SourceLocation.h"
@@ -116,6 +117,8 @@ std::optional
 headerForAmbiguousStdSymbol(const NamedDecl *ND) {
   if (!ND->isInStdNamespace())
 return {};
+  if (auto* USD = llvm::dyn_cast(ND))
+ND = USD->getTargetDecl();
   const auto *FD = ND->getAsFunction();
   if (!FD)
 return std::nullopt;
diff --git a/clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp 
b/clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp
index 4cdcde1184a0a9e..5a2a41b2d99bdd7 100644
--- a/clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp
+++ b/clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp
@@ -11,6 +11,7 @@
 #include "clang-include-cleaner/Analysis.h"
 #include "clang-include-cleaner/Record.h"
 #include "clang-include-cleaner/Types.h"
+#include "clang/AST/Expr.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/Basic/FileEntry.h"
 #include "clang/Basic/FileManager.h"
@@ -587,6 +588,36 @@ TEST_F(HeadersForSymbolTest, AmbiguousStdSymbols) {
   }
 }
 
+TEST_F(HeadersForSymbolTest, AmbiguousStdSymbolsUsingShadow) {
+  Inputs.Code = R"cpp(
+void remove(char*);
+namespace std { using ::remove; }
+
+void k() {
+  std::remove("abc");
+}
+  )cpp";
+  buildAST();
+
+  // Find the DeclRefExpr in the std::remove("abc") function call.
+  struct Visitor : public RecursiveASTVisitor {
+const DeclRefExpr *Out = nullptr;
+bool VisitDeclRefExpr(const DeclRefExpr *DRE) {
+  EXPECT_TRUE(Out == nullptr) << "Found multiple DeclRefExpr!";
+  Out = DRE;
+  return true;
+}
+  };
+  Visitor V;
+  V.TraverseDecl(AST->context().getTranslationUnitDecl());
+  ASSERT_TRUE(V.Out) << "Couldn't find a DeclRefExpr!";
+  EXPECT_THAT(headersForSymbol(*(V.Out->getFoundDecl()),
+   AST->sourceManager(), ),
+  UnorderedElementsAre(
+  Header(*tooling::stdlib::Header::named("";
+}
+
+
 TEST_F(HeadersForSymbolTest, StandardHeaders) {
   Inputs.Code = "void assert();";
   buildAST();

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


[clang] [clang] fix lack comparison of declRefExpr in ASTStructuralEquivalence (PR #66041)

2023-09-15 Thread via cfe-commits

https://github.com/mzyKi updated https://github.com/llvm/llvm-project/pull/66041

>From c6022432afb24b4788e6d5065f583b29a1a5277a Mon Sep 17 00:00:00 2001
From: miaozhiyuan 
Date: Tue, 12 Sep 2023 10:51:35 +0800
Subject: [PATCH] [clang] fix lack comparison of declRefExpr in
 ASTStructuralEquivalence

---
 clang/docs/ReleaseNotes.rst   |  2 +
 clang/lib/AST/ASTStructuralEquivalence.cpp| 54 +++
 .../AST/StructuralEquivalenceTest.cpp |  9 
 3 files changed, 43 insertions(+), 22 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3cdad2f7b9f0e5a..58b8622ed42236d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -218,6 +218,8 @@ Bug Fixes in This Version
   (`#65156 `_)
 - Clang no longer considers the loss of ``__unaligned`` qualifier from objects 
as
   an invalid conversion during method function overload resolution.
+- Fix lack of comparison of declRefExpr in ASTStructuralEquivalence
+  (`#66047 `_`)
 - Fix parser crash when dealing with ill-formed objective C++ header code. 
Fixes
   (`#64836 `_)
 
diff --git a/clang/lib/AST/ASTStructuralEquivalence.cpp 
b/clang/lib/AST/ASTStructuralEquivalence.cpp
index 544420234ef0eb0..591df68f62206fe 100644
--- a/clang/lib/AST/ASTStructuralEquivalence.cpp
+++ b/clang/lib/AST/ASTStructuralEquivalence.cpp
@@ -214,6 +214,15 @@ class StmtComparer {
 return E1->size() == E2->size();
   }
 
+  bool IsStmtEquivalent(const DeclRefExpr *DRE1, const DeclRefExpr *DRE2) {
+auto *Decl1 = DRE1->getDecl();
+auto *Decl2 = DRE2->getDecl();
+if (!Decl1 || !Decl2)
+  return false;
+return IsStructurallyEquivalent(Context, const_cast(Decl1),
+const_cast(Decl2));
+  }
+
   bool IsStmtEquivalent(const DependentScopeDeclRefExpr *DE1,
 const DependentScopeDeclRefExpr *DE2) {
 if (!IsStructurallyEquivalent(Context, DE1->getDeclName(),
@@ -366,7 +375,8 @@ class StmtComparer {
 return true;
   }
 
-  bool IsStmtEquivalent(const CXXBoolLiteralExpr *E1, const CXXBoolLiteralExpr 
*E2) {
+  bool IsStmtEquivalent(const CXXBoolLiteralExpr *E1,
+const CXXBoolLiteralExpr *E2) {
 return E1->getValue() == E2->getValue();
   }
 
@@ -551,13 +561,12 @@ static bool 
IsStructurallyEquivalent(StructuralEquivalenceContext ,
P1->getIndex() == P2->getIndex();
   }
 
-   case TemplateName::Template:
-   case TemplateName::QualifiedTemplate:
-   case TemplateName::SubstTemplateTemplateParm:
-   case TemplateName::UsingTemplate:
- // It is sufficient to check value of getAsTemplateDecl.
- break;
-
+  case TemplateName::Template:
+  case TemplateName::QualifiedTemplate:
+  case TemplateName::SubstTemplateTemplateParm:
+  case TemplateName::UsingTemplate:
+// It is sufficient to check value of getAsTemplateDecl.
+break;
   }
 
   return true;
@@ -579,18 +588,20 @@ static bool 
IsStructurallyEquivalent(StructuralEquivalenceContext ,
 return true;
 
   case TemplateArgument::Type:
-return IsStructurallyEquivalent(Context, Arg1.getAsType(), 
Arg2.getAsType());
+return IsStructurallyEquivalent(Context, Arg1.getAsType(),
+Arg2.getAsType());
 
   case TemplateArgument::Integral:
 if (!IsStructurallyEquivalent(Context, Arg1.getIntegralType(),
-  Arg2.getIntegralType()))
+  Arg2.getIntegralType()))
   return false;
 
 return llvm::APSInt::isSameValue(Arg1.getAsIntegral(),
  Arg2.getAsIntegral());
 
   case TemplateArgument::Declaration:
-return IsStructurallyEquivalent(Context, Arg1.getAsDecl(), 
Arg2.getAsDecl());
+return IsStructurallyEquivalent(Context, Arg1.getAsDecl(),
+Arg2.getAsDecl());
 
   case TemplateArgument::NullPtr:
 return true; // FIXME: Is this correct?
@@ -1402,8 +1413,8 @@ static bool 
IsStructurallyEquivalent(StructuralEquivalenceContext ,
   }
 
   // Check the prototypes.
-  if (!::IsStructurallyEquivalent(Context,
-  Method1->getType(), Method2->getType()))
+  if (!::IsStructurallyEquivalent(Context, Method1->getType(),
+  Method2->getType()))
 return false;
 
   return true;
@@ -1902,8 +1913,9 @@ static bool 
IsStructurallyEquivalent(StructuralEquivalenceContext ,
   D2->getTemplateParameters());
 }
 
-static bool IsTemplateDeclCommonStructurallyEquivalent(
-StructuralEquivalenceContext , TemplateDecl *D1, TemplateDecl *D2) {
+static bool
+IsTemplateDeclCommonStructurallyEquivalent(StructuralEquivalenceContext ,
+   TemplateDecl *D1, 

[clang] [analyzer] Add std::variant checker (PR #66481)

2023-09-15 Thread Gábor Spaits via cfe-commits

https://github.com/spaits ready_for_review 
https://github.com/llvm/llvm-project/pull/66481
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Link Flang runtime on Solaris (PR #65644)

2023-09-15 Thread Brad Smith via cfe-commits

https://github.com/brad0 deleted https://github.com/llvm/llvm-project/pull/65644
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Link Flang runtime on Solaris (PR #65644)

2023-09-15 Thread Brad Smith via cfe-commits

https://github.com/brad0 deleted https://github.com/llvm/llvm-project/pull/65644
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Link Flang runtime on Solaris (PR #65644)

2023-09-15 Thread Brad Smith via cfe-commits

https://github.com/brad0 deleted https://github.com/llvm/llvm-project/pull/65644
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Link Flang runtime on Solaris (PR #65644)

2023-09-15 Thread Brad Smith via cfe-commits

brad0 wrote:

Because of where the chunk is being added in the Solaris ToolChain (and what I 
had in my tree for *BSD's) it is checking for the ```nostdlib, nodefaultlibs, 
or r``` flags, where as the Gnu path does not. I just want to make sure the 
behavior is consistent.

tools::gnutools::Linker::ConstructJob

```
  if (D.CCCIsCXX() &&
  !Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs,
   options::OPT_r)) {
if (ToolChain.ShouldLinkCXXStdlib(Args)) {
  bool OnlyLibstdcxxStatic = Args.hasArg(options::OPT_static_libstdcxx) &&
 !Args.hasArg(options::OPT_static);
  if (OnlyLibstdcxxStatic)
CmdArgs.push_back("-Bstatic");
  ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs);
  if (OnlyLibstdcxxStatic)
CmdArgs.push_back("-Bdynamic");
}
CmdArgs.push_back("-lm");
  }

  // Silence warnings when linking C code with a C++ '-stdlib' argument.
  Args.ClaimAllArgs(options::OPT_stdlib_EQ);

  // Additional linker set-up and flags for Fortran. This is required in order
  // to generate executables. As Fortran runtime depends on the C runtime,
  // these dependencies need to be listed before the C runtime below (i.e.
  // AddRuntTimeLibs).
  if (D.IsFlangMode()) {
addFortranRuntimeLibraryPath(ToolChain, Args, CmdArgs);
addFortranRuntimeLibs(ToolChain, CmdArgs);
CmdArgs.push_back("-lm");
  }
```

solaris::Linker::ConstructJob

```
  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs,
   options::OPT_r)) {
if (D.CCCIsCXX()) {
  if (getToolChain().ShouldLinkCXXStdlib(Args))
getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
  CmdArgs.push_back("-lm");
}
// Additional linker set-up and flags for Fortran. This is required in order
// to generate executables. As Fortran runtime depends on the C runtime,
// these dependencies need to be listed before the C runtime below.
if (D.IsFlangMode()) {
  addFortranRuntimeLibraryPath(getToolChain(), Args, CmdArgs);
  addFortranRuntimeLibs(getToolChain(), CmdArgs);
  CmdArgs.push_back("-lm");
}
```

https://github.com/llvm/llvm-project/pull/65644
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Link Flang runtime on Solaris (PR #65644)

2023-09-15 Thread Brad Smith via cfe-commits

https://github.com/brad0 deleted https://github.com/llvm/llvm-project/pull/65644
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Link Flang runtime on Solaris (PR #65644)

2023-09-15 Thread Brad Smith via cfe-commits

brad0 wrote:

One thing to add to this. I noticed the Gnu addition does not check for 
`nostdlib, nodefaultlibs, or r` flags like the C++ library chunk does. With the 
proposed diff and what I had initially being right under the C++ chunk in the 
Solaris and *BSD ToolChain they would be checking for said flags.

https://github.com/llvm/llvm-project/pull/65644
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Link Flang runtime on Solaris (PR #65644)

2023-09-15 Thread Brad Smith via cfe-commits

https://github.com/brad0 deleted https://github.com/llvm/llvm-project/pull/65644
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Link Flang runtime on Solaris (PR #65644)

2023-09-15 Thread Brad Smith via cfe-commits


@@ -4,6 +4,7 @@
 
 ! RUN: %flang -### -target ppc64le-linux-gnu %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,GNU
 ! RUN: %flang -### -target aarch64-apple-darwin %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,DARWIN
+! RUN: %flang -### -target sparc-sun-solaris2.11 %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,GNU

brad0 wrote:

One thing to add to this. I noticed the Gnu addition does not check for 
`nostdlib, nodefaultlibs, or r` flags like the C++ library chunk does. With the 
proposed diff and what I had initially being right under the C++ chunk in the 
Solaris and *BSD ToolChain they would be checking for said flags.

https://github.com/llvm/llvm-project/pull/65644
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D152504: [clang][ThreadSafety] Analyze cleanup functions

2023-09-15 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 556838.

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

https://reviews.llvm.org/D152504

Files:
  clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h
  clang/lib/Analysis/ThreadSafety.cpp
  clang/lib/Analysis/ThreadSafetyCommon.cpp
  clang/test/Sema/warn-thread-safety-analysis.c

Index: clang/test/Sema/warn-thread-safety-analysis.c
===
--- clang/test/Sema/warn-thread-safety-analysis.c
+++ clang/test/Sema/warn-thread-safety-analysis.c
@@ -23,6 +23,7 @@
   __attribute__ ((shared_locks_required(__VA_ARGS__)))
 #define NO_THREAD_SAFETY_ANALYSIS  __attribute__ ((no_thread_safety_analysis))
 
+
 // Define the mutex struct.
 // Simplified only for test purpose.
 struct LOCKABLE Mutex {};
@@ -72,6 +73,8 @@
   return *p;
 }
 
+void unlock_scope(struct Mutex *const *mu) __attribute__((release_capability(**mu)));
+
 int main(void) {
 
   Foo_fun1(1); // expected-warning{{calling function 'Foo_fun1' requires holding mutex 'mu2'}} \
@@ -127,6 +130,13 @@
 // expected-note@-1{{mutex released here}}
   mutex_shared_unlock();// expected-warning {{releasing mutex 'mu1' that was not held}}
 
+  /// Cleanup functions
+  {
+struct Mutex* const __attribute__((cleanup(unlock_scope))) scope = 
+mutex_exclusive_lock(scope);  // Note that we have to lock through scope, because no alias analysis!
+// Cleanup happens automatically -> no warning.
+  }
+
   return 0;
 }
 
Index: clang/lib/Analysis/ThreadSafetyCommon.cpp
===
--- clang/lib/Analysis/ThreadSafetyCommon.cpp
+++ clang/lib/Analysis/ThreadSafetyCommon.cpp
@@ -110,7 +110,8 @@
 /// \param D   The declaration to which the attribute is attached.
 /// \param DeclExp An expression involving the Decl to which the attribute
 ///is attached.  E.g. the call to a function.
-/// \param SelfS-expression to substitute for a \ref CXXThisExpr.
+/// \param SelfS-expression to substitute for a \ref CXXThisExpr in a call,
+///or argument to a cleanup function.
 CapabilityExpr SExprBuilder::translateAttrExpr(const Expr *AttrExp,
const NamedDecl *D,
const Expr *DeclExp,
@@ -144,7 +145,11 @@
 
   if (Self) {
 assert(!Ctx.SelfArg && "Ambiguous self argument");
-Ctx.SelfArg = Self;
+assert(isa(D) && "Self argument requires function");
+if (isa(D))
+  Ctx.SelfArg = Self;
+else
+  Ctx.FunArgs = Self;
 
 // If the attribute has no arguments, then assume the argument is "this".
 if (!AttrExp)
@@ -312,8 +317,14 @@
   ? (cast(D)->getCanonicalDecl() == Canonical)
   : (cast(D)->getCanonicalDecl() == Canonical)) {
 // Substitute call arguments for references to function parameters
-assert(I < Ctx->NumArgs);
-return translate(Ctx->FunArgs[I], Ctx->Prev);
+if (const Expr *const *FunArgs =
+Ctx->FunArgs.dyn_cast()) {
+  assert(I < Ctx->NumArgs);
+  return translate(FunArgs[I], Ctx->Prev);
+}
+
+assert(I == 0);
+return Ctx->FunArgs.get();
   }
 }
 // Map the param back to the param of the original function declaration
Index: clang/lib/Analysis/ThreadSafety.cpp
===
--- clang/lib/Analysis/ThreadSafety.cpp
+++ clang/lib/Analysis/ThreadSafety.cpp
@@ -1773,7 +1773,8 @@
 ///
 /// \param Exp   The call expression.
 /// \param D The callee declaration.
-/// \param Self  If \p Exp = nullptr, the implicit this argument.
+/// \param Self  If \p Exp = nullptr, the implicit this argument or the argument
+///  of an implicitly called cleanup function.
 /// \param Loc   If \p Exp = nullptr, the location.
 void BuildLockset::handleCall(const Expr *Exp, const NamedDecl *D,
   til::LiteralPtr *Self, SourceLocation Loc) {
@@ -2414,6 +2415,15 @@
 AD.getTriggerStmt()->getEndLoc());
   break;
 }
+
+case CFGElement::CleanupFunction: {
+  const CFGCleanupFunction  = BI.castAs();
+  LocksetBuilder.handleCall(/*Exp=*/nullptr, CF.getFunctionDecl(),
+SxBuilder.createVariable(CF.getVarDecl()),
+CF.getVarDecl()->getLocation());
+  break;
+}
+
 case CFGElement::TemporaryDtor: {
   auto TD = BI.castAs();
 
Index: clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h
===
--- clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h
+++ clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h
@@ -361,7 +361,7 @@
 unsigned NumArgs = 0;
 
 // Function 

[clang] [Driver] Link Flang runtime on Solaris (PR #65644)

2023-09-15 Thread Brad Smith via cfe-commits

https://github.com/brad0 edited https://github.com/llvm/llvm-project/pull/65644
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Introduce paged vector (PR #66430)

2023-09-15 Thread Chuanqi Xu via cfe-commits


@@ -0,0 +1,126 @@
+//===- llvm/ADT/PagedVector.h - 'Lazyly allocated' vectors *- C++
+//-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file defines the PagedVector class.
+//
+//===--===//
+#ifndef LLVM_ADT_PAGEDVECTOR_H
+#define LLVM_ADT_PAGEDVECTOR_H
+
+#include 
+
+namespace llvm {
+// A vector that allocates memory in pages.
+// Order is kept, but memory is allocated only when one element of the page is
+// accessed. This introduces a level of indirection, but it is useful when you
+// have a sparsely initialised vector where the full size is allocated upfront
+// with the default constructor and elements are initialised later, on first
+// access.
+//
+// Notice that this does not have iterators, because if you
+// have iterators it probably means you are going to touch
+// all the memory in any case, so better use a std::vector in
+// the first place.
+template  class PagedVector {
+  // The actual number of element in the vector which can be accessed.
+  size_t Size = 0;
+  // The position of the initial element of the page in the Data vector.
+  // Pages are allocated contiguously in the Data vector.
+  mutable std::vector Lookup;
+  // Actual page data. All the page elements are added to this vector on the
+  // first access of any of the elements of the page. Elements default
+  // constructed and elements of the page are stored contiguously. The oder of
+  // the elements however depends on the order of access of the pages.
+  mutable std::vector Data;
+
+public:
+  // Lookup an element at position Index.
+  T [](int Index) const { return at(Index); }
+
+  // Lookup an element at position i.
+  // If the associated page is not filled, it will be filled with default
+  // constructed elements. If the associated page is filled, return the 
element.
+  T (int Index) const {
+auto  = Lookup[Index / PAGE_SIZE];
+// If the range is not filled, fill it
+if (PageId == -1) {
+  int OldSize = Data.size();
+  PageId = OldSize / PAGE_SIZE;
+  // Allocate the memory
+  Data.resize(OldSize + PAGE_SIZE);
+  // Fill the whole capacity with empty elements
+  for (int I = 0; I < PAGE_SIZE; ++I) {
+Data[I + OldSize] = T();
+  }
+}
+// Return the element
+return Data[Index % PAGE_SIZE + PAGE_SIZE * PageId];
+  }
+
+  // Return the capacity of the vector. I.e. the maximum size it can be 
expanded
+  // to with the expand method without allocating more pages.
+  size_t capacity() const { return Lookup.size() * PAGE_SIZE; }
+
+  // Return the size of the vector. I.e. the maximum index that can be
+  // accessed, i.e. the maximum value which was used as argument of the
+  // expand method.
+  size_t size() const { return Size; }
+
+  // Expands the vector to the given NewSize number of elements.
+  // If the vector was smaller, allocates new pages as needed.
+  // It should be called only with NewSize >= Size.
+  void expand(size_t NewSize) {
+// You cannot shrink the vector, otherwise
+// one would have to invalidate contents which is expensive and
+// while giving the false hope that the resize is cheap.
+assert(NewSize >= Size);
+if (NewSize <= Size) {

ChuanqiXu9 wrote:

The 2 lines look odd.

https://github.com/llvm/llvm-project/pull/66430
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Introduce paged vector (PR #66430)

2023-09-15 Thread Chuanqi Xu via cfe-commits


@@ -0,0 +1,126 @@
+//===- llvm/ADT/PagedVector.h - 'Lazyly allocated' vectors *- C++
+//-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file defines the PagedVector class.
+//
+//===--===//
+#ifndef LLVM_ADT_PAGEDVECTOR_H
+#define LLVM_ADT_PAGEDVECTOR_H
+
+#include 
+
+namespace llvm {
+// A vector that allocates memory in pages.
+// Order is kept, but memory is allocated only when one element of the page is
+// accessed. This introduces a level of indirection, but it is useful when you
+// have a sparsely initialised vector where the full size is allocated upfront
+// with the default constructor and elements are initialised later, on first
+// access.
+//
+// Notice that this does not have iterators, because if you
+// have iterators it probably means you are going to touch
+// all the memory in any case, so better use a std::vector in
+// the first place.
+template  class PagedVector {
+  // The actual number of element in the vector which can be accessed.
+  size_t Size = 0;
+  // The position of the initial element of the page in the Data vector.
+  // Pages are allocated contiguously in the Data vector.
+  mutable std::vector Lookup;
+  // Actual page data. All the page elements are added to this vector on the
+  // first access of any of the elements of the page. Elements default
+  // constructed and elements of the page are stored contiguously. The oder of
+  // the elements however depends on the order of access of the pages.
+  mutable std::vector Data;
+
+public:
+  // Lookup an element at position Index.
+  T [](int Index) const { return at(Index); }
+
+  // Lookup an element at position i.
+  // If the associated page is not filled, it will be filled with default
+  // constructed elements. If the associated page is filled, return the 
element.
+  T (int Index) const {

ChuanqiXu9 wrote:

Should we add an `assert` here?

https://github.com/llvm/llvm-project/pull/66430
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Introduce paged vector (PR #66430)

2023-09-15 Thread Chuanqi Xu via cfe-commits


@@ -0,0 +1,126 @@
+//===- llvm/ADT/PagedVector.h - 'Lazyly allocated' vectors *- C++
+//-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file defines the PagedVector class.
+//
+//===--===//
+#ifndef LLVM_ADT_PAGEDVECTOR_H
+#define LLVM_ADT_PAGEDVECTOR_H
+
+#include 
+
+namespace llvm {
+// A vector that allocates memory in pages.
+// Order is kept, but memory is allocated only when one element of the page is
+// accessed. This introduces a level of indirection, but it is useful when you
+// have a sparsely initialised vector where the full size is allocated upfront
+// with the default constructor and elements are initialised later, on first
+// access.
+//
+// Notice that this does not have iterators, because if you
+// have iterators it probably means you are going to touch
+// all the memory in any case, so better use a std::vector in
+// the first place.
+template  class PagedVector {
+  // The actual number of element in the vector which can be accessed.
+  size_t Size = 0;
+  // The position of the initial element of the page in the Data vector.
+  // Pages are allocated contiguously in the Data vector.
+  mutable std::vector Lookup;
+  // Actual page data. All the page elements are added to this vector on the
+  // first access of any of the elements of the page. Elements default
+  // constructed and elements of the page are stored contiguously. The oder of
+  // the elements however depends on the order of access of the pages.
+  mutable std::vector Data;
+
+public:
+  // Lookup an element at position Index.
+  T [](int Index) const { return at(Index); }

ChuanqiXu9 wrote:

The type of Index should be size_t

https://github.com/llvm/llvm-project/pull/66430
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


<    1   2   3   4   5   >