[clang] a68638b - [C++20] [Modules] [Reduced BMI] Handling Deduction Guide in reduced BMI

2024-06-03 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2024-06-03T14:59:23+08:00
New Revision: a68638bf6a6a5cb60947753ccaf7d1de80f6c89e

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

LOG: [C++20] [Modules] [Reduced BMI] Handling Deduction Guide in reduced BMI
carefully

Close https://github.com/llvm/llvm-project/issues/93859

The direct pattern of the issue is that, in a reduced BMI, we're going
to wrtie a class but we didn't write the deduction guide. Although we
handled deduction guide, but we tried to record the found deduction
guide from `noload_lookup` directly.

It is slightly problematic if the found deduction guide is from AST.
e.g.,

```
module;
export module m;
import xxx; // Also contains the class and the deduction guide
...
```

Then when we writes the class in the current file, we tried to record
the deduction guide, but `noload_lookup` returns the deduction guide
from the AST file then we didn't record the local deduction guide. Then
mismatch happens.

To mitiagte the problem, we tried to record the canonical declaration
for the decution guide.

Added: 
clang/test/Modules/pr93859.cppm

Modified: 
clang/lib/Serialization/ASTWriterDecl.cpp

Removed: 




diff  --git a/clang/lib/Serialization/ASTWriterDecl.cpp 
b/clang/lib/Serialization/ASTWriterDecl.cpp
index bbd16dbdb8fff..5a6ab4408eb2b 100644
--- a/clang/lib/Serialization/ASTWriterDecl.cpp
+++ b/clang/lib/Serialization/ASTWriterDecl.cpp
@@ -1733,7 +1733,7 @@ void 
ASTDeclWriter::VisitClassTemplateDecl(ClassTemplateDecl *D) {
   if (Writer.isGeneratingReducedBMI()) {
 auto Name = Context.DeclarationNames.getCXXDeductionGuideName(D);
 for (auto *DG : D->getDeclContext()->noload_lookup(Name))
-  Writer.GetDeclRef(DG);
+  Writer.GetDeclRef(DG->getCanonicalDecl());
   }
 
   Code = serialization::DECL_CLASS_TEMPLATE;

diff  --git a/clang/test/Modules/pr93859.cppm b/clang/test/Modules/pr93859.cppm
new file mode 100644
index 0..d1d45bb975308
--- /dev/null
+++ b/clang/test/Modules/pr93859.cppm
@@ -0,0 +1,146 @@
+// Reduced from https://github.com/llvm/llvm-project/issues/93859
+//
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 %t/reduced_std.cppm 
-emit-reduced-module-interface -o %t/reduced_std.pcm
+// RUN: %clang_cc1 -std=c++20 %t/Misc.cppm -emit-reduced-module-interface -o 
%t/Misc.pcm \
+// RUN: -fprebuilt-module-path=%t
+// RUN: %clang_cc1 -std=c++20 %t/Instance.cppm -emit-reduced-module-interface 
-o %t/Instance.pcm \
+// RUN: -fprebuilt-module-path=%t
+// RUN: %clang_cc1 -std=c++20 %t/Device.cppm -emit-reduced-module-interface -o 
%t/Device.pcm \
+// RUN: -fprebuilt-module-path=%t
+// RUN: %clang_cc1 -std=c++20 %t/Overlay.cppm -emit-reduced-module-interface 
-o %t/Overlay.pcm \
+// RUN: -fprebuilt-module-path=%t
+// RUN: %clang_cc1 -std=c++20 %t/App.cppm -emit-module-interface -o /dev/null \
+// RUN: -fexperimental-modules-reduced-bmi -fmodule-output=%t/App.pcm \
+// RUN: -fprebuilt-module-path=%t
+// RUN: %clang_cc1 -std=c++20 %t/test.cc -fsyntax-only -verify \
+// RUN: -fprebuilt-module-path=%t
+
+//--- header.h
+namespace std {
+
+template 
+struct pair
+{
+  _T1 first;
+  _T2 second;
+
+  constexpr pair()
+  : first(), second() {}
+
+  constexpr pair(_T1 const& __t1, _T2 const& __t2)
+  : first(__t1), second(__t2) {}
+};
+
+template 
+pair(_T1, _T2) -> pair<_T1, _T2>;
+
+template 
+class __tree_const_iterator {
+public:
+  template 
+  friend class __tree;
+};
+
+template 
+class __tree {
+public:
+  typedef _Tp value_type;
+  typedef __tree_const_iterator const_iterator;
+
+  template 
+  friend class map;
+};
+
+template 
+class set {
+public:
+  typedef __tree<_Key> __base;
+
+  typedef typename __base::const_iterator iterator;
+
+  set() {}
+
+  pair
+  insert(const _Key& __v);
+};
+
+template 
+inline constexpr _OutputIterator
+copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result) {
+  return pair{__first, __last}.second;
+}
+
+}
+
+//--- reduced_std.cppm
+module;
+#include "header.h"
+export module reduced_std;
+
+export namespace std {
+using std::set;
+using std::copy;
+}
+
+//--- Misc.cppm
+export module Misc;
+import reduced_std;
+
+export void check_result(int res) {
+std::set extensions;
+extensions.insert('f');
+}
+
+//--- Instance.cppm
+export module Instance;
+import reduced_std;
+
+export class Instance {
+public:
+Instance() {
+std::set extensions;
+extensions.insert("foo");
+}
+};
+
+//--- Device.cppm
+export module Device;
+import reduced_std;
+import Instance;
+import Misc;
+
+std::set wtf_set;
+
+//--- Overlay.cppm
+export module Overlay;
+
+import reduced_std;
+import Device;
+
+void overlay_vector_use() {
+std::set nums;
+nums.

[clang] [Clang][Comments] Add argument parsing for @throw @throws @exception (PR #84726)

2024-06-03 Thread via cfe-commits

https://github.com/hdoc updated https://github.com/llvm/llvm-project/pull/84726

>From ec3f444913d9162de4494cdb09b336b1b00380fa Mon Sep 17 00:00:00 2001
From: hdoc 
Date: Mon, 11 Mar 2024 01:13:25 -0700
Subject: [PATCH 1/7] Comment parsing: add argument parsing for @throw @throws
 @exception

Doxygen allows for the @throw, @throws, and @exception commands to
have an attached argument indicating the type being thrown. Currently,
Clang's AST parsing doesn't support parsing out this argument from doc
comments. The result is missing compatibility with Doxygen.

We would find it helpful if the AST exposed these thrown types as
BlockCommandComment arguments so that we could generate better
documentation.

This PR implements parsing of arguments for the @throw, @throws, and
@exception commands. Each command can only have one argument, matching
the semantics of Doxygen. We have also added unit tests to validate
the functionality.
---
 clang/include/clang/AST/CommentCommands.td |   6 +-
 clang/include/clang/AST/CommentParser.h|   3 +
 clang/lib/AST/CommentParser.cpp| 133 
 clang/unittests/AST/CommentParser.cpp  | 235 -
 4 files changed, 373 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/AST/CommentCommands.td 
b/clang/include/clang/AST/CommentCommands.td
index e839031752cdd..06b2fa9b5531c 100644
--- a/clang/include/clang/AST/CommentCommands.td
+++ b/clang/include/clang/AST/CommentCommands.td
@@ -132,9 +132,9 @@ def Tparam : BlockCommand<"tparam"> { let IsTParamCommand = 
1; }
 // HeaderDoc command for template parameter documentation.
 def Templatefield : BlockCommand<"templatefield"> { let IsTParamCommand = 1; }
 
-def Throws: BlockCommand<"throws"> { let IsThrowsCommand = 1; }
-def Throw : BlockCommand<"throw"> { let IsThrowsCommand = 1; }
-def Exception : BlockCommand<"exception"> { let IsThrowsCommand = 1; }
+def Throws: BlockCommand<"throws"> { let IsThrowsCommand = 1; let NumArgs 
= 1; }
+def Throw : BlockCommand<"throw"> { let IsThrowsCommand = 1; let NumArgs = 
1; }
+def Exception : BlockCommand<"exception"> { let IsThrowsCommand = 1; let 
NumArgs = 1;}
 
 def Deprecated : BlockCommand<"deprecated"> {
   let IsEmptyParagraphAllowed = 1;
diff --git a/clang/include/clang/AST/CommentParser.h 
b/clang/include/clang/AST/CommentParser.h
index e11e818b1af0a..5884a25d00785 100644
--- a/clang/include/clang/AST/CommentParser.h
+++ b/clang/include/clang/AST/CommentParser.h
@@ -100,6 +100,9 @@ class Parser {
   ArrayRef
   parseCommandArgs(TextTokenRetokenizer &Retokenizer, unsigned NumArgs);
 
+  ArrayRef
+  parseThrowCommandArgs(TextTokenRetokenizer &Retokenizer, unsigned NumArgs);
+
   BlockCommandComment *parseBlockCommand();
   InlineCommandComment *parseInlineCommand();
 
diff --git a/clang/lib/AST/CommentParser.cpp b/clang/lib/AST/CommentParser.cpp
index 8adfd85d0160c..c70fa1b05cb24 100644
--- a/clang/lib/AST/CommentParser.cpp
+++ b/clang/lib/AST/CommentParser.cpp
@@ -75,6 +75,25 @@ class TextTokenRetokenizer {
 return *Pos.BufferPtr;
   }
 
+  char peekNext(unsigned offset) const {
+assert(!isEnd());
+assert(Pos.BufferPtr != Pos.BufferEnd);
+if (Pos.BufferPtr + offset <= Pos.BufferEnd) {
+  return *(Pos.BufferPtr + offset);
+} else {
+  return '\0';
+}
+  }
+
+  void peekNextToken(SmallString<32> &WordText) const {
+unsigned offset = 1;
+char C = peekNext(offset++);
+while (!isWhitespace(C) && C != '\0') {
+  WordText.push_back(C);
+  C = peekNext(offset++);
+}
+  }
+
   void consumeChar() {
 assert(!isEnd());
 assert(Pos.BufferPtr != Pos.BufferEnd);
@@ -89,6 +108,29 @@ class TextTokenRetokenizer {
 }
   }
 
+  /// Extract a template type
+  bool lexTemplateType(SmallString<32> &WordText) {
+unsigned IncrementCounter = 0;
+while (!isEnd()) {
+  const char C = peek();
+  WordText.push_back(C);
+  consumeChar();
+  switch (C) {
+  default:
+break;
+  case '<': {
+IncrementCounter++;
+  } break;
+  case '>': {
+IncrementCounter--;
+if (!IncrementCounter)
+  return true;
+  } break;
+  }
+}
+return false;
+  }
+
   /// Add a token.
   /// Returns true on success, false if there are no interesting tokens to
   /// fetch from lexer.
@@ -149,6 +191,76 @@ class TextTokenRetokenizer {
 addToken();
   }
 
+  /// Extract a type argument
+  bool lexDataType(Token &Tok) {
+if (isEnd())
+  return false;
+Position SavedPos = Pos;
+consumeWhitespace();
+SmallString<32> NextToken;
+SmallString<32> WordText;
+const char *WordBegin = Pos.BufferPtr;
+SourceLocation Loc = getSourceLocation();
+StringRef ConstVal = StringRef("const");
+bool ConstPointer = false;
+
+while (!isEnd()) {
+  const char C = peek();
+  if (!isWhitespace(C)) {
+if (C == '<') {
+  if (!lexTemplateType(WordText))
+return false;
+  

[clang] [Clang][Comments] Add argument parsing for @throw @throws @exception (PR #84726)

2024-06-03 Thread via cfe-commits

hdoc wrote:

@cor3ntin we appreciate the feedback. Likewise, we agree that the home-grown 
parser just for parsing `type-id`s in comments is less than ideal. We had some 
alternative approaches in mind, like using an instance of `clang::Lexer`, but 
went with our original approach at first.

I've refactored the PR and reduced the functionality to the subset you 
requested. I think that makes more sense from a maintainability perspective, as 
you highlighted. Please review the PR when you get a chance. Thank you.

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


[clang] [Clang][Comments] Attach comments to decl even if preproc directives are in between (PR #88367)

2024-06-03 Thread via cfe-commits


@@ -107,6 +107,24 @@
 ///The 2nd source tile. Max size is 1024 Bytes.
 #define _tile_cmmrlfp16ps(dst, a, b) __builtin_ia32_tcmmrlfp16ps(dst, a, b)
 
+/// Perform matrix multiplication of two tiles containing complex elements and

hdoc wrote:

This is not an unrelated change, I describe the issue in the "Complications" 
section of the PR body. In short, the `-Wdocumentation` warning gets triggered 
here because the macro for the `#define` on line 108 has a doc comment which 
Clang attributes to the function on line 128. Since the params documented in 
the macro's doc comment don't match the params in the function, 
`-Wdocumentation` throws an error. 

As a hack, I originally put semicolons on their own line because that 
effectively splits the decls from `-Wdocumentation`'s point of view, but it's a 
bit of a dirty hack. Instead, I just added a proper doc comment for the 
function here which stops the warning without changing the underlying comment 
parsing functionality. Still a workaround, but cleaner.

Changing that underlying functionality would be a much more involved since the 
comment parser operates on the AST, at which point most of the preproc info is 
gone because of how Clang is structured (please correct me if I'm wrong here).

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


[clang] [Clang][Comments] Attach comments to decl even if preproc directives are in between (PR #88367)

2024-06-03 Thread via cfe-commits


@@ -533,6 +533,8 @@ __rdtscp(unsigned int *__A) {
 /// \see __rdpmc
 #define _rdpmc(A) __rdpmc(A)
 
+;

hdoc wrote:

If it sounds reasonable to you, I can fix this with the same method used in the 
`clang/lib/Headers/amxcomplexintrin.h` file. Unfortunately changing the 
underlying comment parsing functionality would be a complicated change.

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


[clang] [clang][analyzer] Move PutenvStackArrayChecker out of alpha package. (PR #93980)

2024-06-03 Thread Balázs Kéri via cfe-commits


@@ -1179,6 +1179,41 @@ security.insecureAPI.DeprecatedOrUnsafeBufferHandling (C)
strncpy(buf, "a", 1); // warn
  }
 
+.. _security-putenv-stack-array:
+
+security.PutenvStackArray (C)
+"
+Finds calls to the ``putenv`` function which pass a pointer to a 
stack-allocated
+(automatic) array as the argument. Function ``putenv`` does not copy the passed
+string, only a pointer to the data is stored and this data can be read even by
+other threads. Content of a stack-allocated array is likely to be overwritten
+after returning from the parent function.

balazske wrote:

This text was not accurate, probably even better is "after exiting from the 
function" (the "parent function" was meant to be the parent of the allocated 
stack memory).

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


[clang] [clang][analyzer] Move PutenvStackArrayChecker out of alpha package. (PR #93980)

2024-06-03 Thread Balázs Kéri via cfe-commits


@@ -1179,6 +1179,41 @@ security.insecureAPI.DeprecatedOrUnsafeBufferHandling (C)
strncpy(buf, "a", 1); // warn
  }
 
+.. _security-putenv-stack-array:
+
+security.PutenvStackArray (C)
+"
+Finds calls to the ``putenv`` function which pass a pointer to a 
stack-allocated
+(automatic) array as the argument. Function ``putenv`` does not copy the passed
+string, only a pointer to the data is stored and this data can be read even by
+other threads. Content of a stack-allocated array is likely to be overwritten
+after returning from the parent function.
+
+The problem can be solved by using a static array variable or dynamically
+allocated memory. Even better is to avoid using ``putenv`` (it has other
+problems related to memory leaks) and use ``setenv`` instead.
+
+The check corresponds to CERT rule
+`POS34-C. Do not call putenv() with a pointer to an automatic variable as the 
argument
+`_.
+
+.. code-block:: c
+
+  int f() {
+char env[] = "NAME=value";
+return putenv(env); // putenv function should not be called with 
stack-allocated string
+  }
+
+There is one case where the checker can report a false positive. This is when
+the stack-allocated array is used at `putenv` in a function or code branch that
+does not return (calls `fork` or `exec` like function).

balazske wrote:

Then it looks better to remove this section about the false positive. At least 
for `execv` it should copy the environment that could be changed by `putenv`, 
and I did not found in the documentation that `fork` does not use it. One case 
still exists, when all paths after `putenv` do exit from the program (call 
`exit` or assert) (this happens really in the linked case). This is probably a 
checkable thing (with limitations), but maybe not worth it. 

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


[clang] [serialization] no transitive decl change (PR #92083)

2024-06-03 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

I'd like to land this since:
- I want to give more time testing this
- the design of the patch is pretty similar with the previous one 
(https://github.com/llvm/llvm-project/pull/86912)
- the scale of the patch is not very big (100+ lines of code except new tests)
- I do think the functionality is very very important to modules.

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


[clang] [clang-format] Handle AttributeMacros in parseRecord() (PR #94189)

2024-06-03 Thread Owen Pan via cfe-commits

https://github.com/owenca created 
https://github.com/llvm/llvm-project/pull/94189

Fixes #94184.

>From 45c818098c1eedd72b82e9b5362538e2781698ab Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Mon, 3 Jun 2024 00:40:18 -0700
Subject: [PATCH] [clang-format] Handle AttributeMacros in parseRecord()

Fixes #94184.
---
 clang/lib/Format/UnwrappedLineParser.cpp  | 4 +++-
 clang/unittests/Format/TokenAnnotatorTest.cpp | 8 
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 053fd3d4df559..d6061c2666c2a 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -3993,8 +3993,10 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
 case tok::coloncolon:
   break;
 default:
-  if (!ClassName && Previous->is(tok::identifier))
+  if (!ClassName && Previous->is(tok::identifier) &&
+  Previous->isNot(TT_AttributeMacro)) {
 ClassName = Previous;
+  }
 }
   }
 
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index a3b2569d80633..3d609a1f041bc 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -493,6 +493,14 @@ TEST_F(TokenAnnotatorTest, UnderstandsStructs) {
   Tokens = annotate("template  struct S {};");
   ASSERT_EQ(Tokens.size(), 15u) << Tokens;
   EXPECT_TOKEN(Tokens[11], tok::l_brace, TT_StructLBrace);
+
+  auto Style = getLLVMStyle();
+  Style.AttributeMacros.push_back("EXPORT");
+  Tokens = annotate("struct EXPORT StructName {};", Style);
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::identifier, TT_AttributeMacro);
+  EXPECT_TOKEN(Tokens[3], tok::l_brace, TT_StructLBrace);
+  EXPECT_TOKEN(Tokens[4], tok::r_brace, TT_StructRBrace);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsUnions) {

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


[clang] [clang-format] Handle AttributeMacros in parseRecord() (PR #94189)

2024-06-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: Owen Pan (owenca)


Changes

Fixes #94184.

---
Full diff: https://github.com/llvm/llvm-project/pull/94189.diff


2 Files Affected:

- (modified) clang/lib/Format/UnwrappedLineParser.cpp (+3-1) 
- (modified) clang/unittests/Format/TokenAnnotatorTest.cpp (+8) 


``diff
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 053fd3d4df559..d6061c2666c2a 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -3993,8 +3993,10 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
 case tok::coloncolon:
   break;
 default:
-  if (!ClassName && Previous->is(tok::identifier))
+  if (!ClassName && Previous->is(tok::identifier) &&
+  Previous->isNot(TT_AttributeMacro)) {
 ClassName = Previous;
+  }
 }
   }
 
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index a3b2569d80633..3d609a1f041bc 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -493,6 +493,14 @@ TEST_F(TokenAnnotatorTest, UnderstandsStructs) {
   Tokens = annotate("template  struct S {};");
   ASSERT_EQ(Tokens.size(), 15u) << Tokens;
   EXPECT_TOKEN(Tokens[11], tok::l_brace, TT_StructLBrace);
+
+  auto Style = getLLVMStyle();
+  Style.AttributeMacros.push_back("EXPORT");
+  Tokens = annotate("struct EXPORT StructName {};", Style);
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::identifier, TT_AttributeMacro);
+  EXPECT_TOKEN(Tokens[3], tok::l_brace, TT_StructLBrace);
+  EXPECT_TOKEN(Tokens[4], tok::r_brace, TT_StructRBrace);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsUnions) {

``




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


[clang] a41a20b - [NFC] [C++20] [Modules] [Reduced BMI] Reorder Emitting reduced BMI and normal BMI for named modules

2024-06-03 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2024-06-03T15:47:34+08:00
New Revision: a41a20bd47968b16bb84761578628752080e9f24

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

LOG: [NFC] [C++20] [Modules] [Reduced BMI] Reorder Emitting reduced BMI and 
normal BMI for named modules

When we generate the reduced BMI on the fly, the order of the emitting
phase is different within `-emit-obj` and `-emit-module-interface`.
Although this is meant to be fine, we observed it in
https://github.com/llvm/llvm-project/issues/93859 (that the different phase 
order may cause problems).
Also it turns out to be a different fundamental reason to the orders.

But it might be fine to make the order of emitting reducing BMI at first
to avoid such confusions in the future.

Added: 


Modified: 
clang/lib/Frontend/FrontendActions.cpp

Removed: 




diff  --git a/clang/lib/Frontend/FrontendActions.cpp 
b/clang/lib/Frontend/FrontendActions.cpp
index 454653a31534c..4f064321997a2 100644
--- a/clang/lib/Frontend/FrontendActions.cpp
+++ b/clang/lib/Frontend/FrontendActions.cpp
@@ -273,9 +273,6 @@ std::unique_ptr
 GenerateModuleInterfaceAction::CreateASTConsumer(CompilerInstance &CI,
  StringRef InFile) {
   std::vector> Consumers;
-  Consumers.push_back(std::make_unique(
-  CI.getPreprocessor(), CI.getModuleCache(),
-  CI.getFrontendOpts().OutputFile));
 
   if (CI.getFrontendOpts().GenReducedBMI &&
   !CI.getFrontendOpts().ModuleOutputPath.empty()) {
@@ -284,6 +281,10 @@ 
GenerateModuleInterfaceAction::CreateASTConsumer(CompilerInstance &CI,
 CI.getFrontendOpts().ModuleOutputPath));
   }
 
+  Consumers.push_back(std::make_unique(
+  CI.getPreprocessor(), CI.getModuleCache(),
+  CI.getFrontendOpts().OutputFile));
+
   return std::make_unique(std::move(Consumers));
 }
 



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


[clang] [Clang] Fix crash on improper use of __array_extent (PR #94173)

2024-06-03 Thread via cfe-commits

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


[clang] [clang][analyzer] Move PutenvStackArrayChecker out of alpha package. (PR #93980)

2024-06-03 Thread Balázs Kéri via cfe-commits

https://github.com/balazske updated 
https://github.com/llvm/llvm-project/pull/93980

From 033c7c2187f4dcbd050c69c5279ae2dcfe02c529 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bal=C3=A1zs=20K=C3=A9ri?= 
Date: Wed, 29 May 2024 16:47:42 +0200
Subject: [PATCH 1/2] [clang][analyzer] Move PutenvStackArrayChecker out of
 alpha package.

Checker alpha.security.PutenvStackArray is moved to security.PutenvStackArray.
---
 clang/docs/analyzer/checkers.rst  | 70 +--
 .../clang/StaticAnalyzer/Checkers/Checkers.td | 10 +--
 clang/test/Analysis/putenv-stack-array.c  |  2 +-
 3 files changed, 41 insertions(+), 41 deletions(-)

diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst
index 3a31708a1e9de..ac13f731e508e 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -1179,6 +1179,41 @@ security.insecureAPI.DeprecatedOrUnsafeBufferHandling (C)
strncpy(buf, "a", 1); // warn
  }
 
+.. _security-putenv-stack-array:
+
+security.PutenvStackArray (C)
+"
+Finds calls to the ``putenv`` function which pass a pointer to a 
stack-allocated
+(automatic) array as the argument. Function ``putenv`` does not copy the passed
+string, only a pointer to the data is stored and this data can be read even by
+other threads. Content of a stack-allocated array is likely to be overwritten
+after returning from the parent function.
+
+The problem can be solved by using a static array variable or dynamically
+allocated memory. Even better is to avoid using ``putenv`` (it has other
+problems related to memory leaks) and use ``setenv`` instead.
+
+The check corresponds to CERT rule
+`POS34-C. Do not call putenv() with a pointer to an automatic variable as the 
argument
+`_.
+
+.. code-block:: c
+
+  int f() {
+char env[] = "NAME=value";
+return putenv(env); // putenv function should not be called with 
stack-allocated string
+  }
+
+There is one case where the checker can report a false positive. This is when
+the stack-allocated array is used at `putenv` in a function or code branch that
+does not return (calls `fork` or `exec` like function).
+
+Another special case is if the `putenv` is called from function `main`. Here
+the stack is deallocated at the end of the program and it should be no problem
+to use the stack-allocated string (a multi-threaded program may require more
+attention). The checker does not warn for cases when stack space of `main` is
+used at the `putenv` call.
+
 security.SetgidSetuidOrder (C)
 ""
 When dropping user-level and group-level privileges in a program by using
@@ -2833,41 +2868,6 @@ Warn on mmap() calls that are both writable and 
executable.
//   code
  }
 
-.. _alpha-security-putenv-stack-array:
-
-alpha.security.PutenvStackArray (C)
-"""
-Finds calls to the ``putenv`` function which pass a pointer to a 
stack-allocated
-(automatic) array as the argument. Function ``putenv`` does not copy the passed
-string, only a pointer to the data is stored and this data can be read even by
-other threads. Content of a stack-allocated array is likely to be overwritten
-after returning from the parent function.
-
-The problem can be solved by using a static array variable or dynamically
-allocated memory. Even better is to avoid using ``putenv`` (it has other
-problems related to memory leaks) and use ``setenv`` instead.
-
-The check corresponds to CERT rule
-`POS34-C. Do not call putenv() with a pointer to an automatic variable as the 
argument
-`_.
-
-.. code-block:: c
-
-  int f() {
-char env[] = "NAME=value";
-return putenv(env); // putenv function should not be called with 
stack-allocated string
-  }
-
-There is one case where the checker can report a false positive. This is when
-the stack-allocated array is used at `putenv` in a function or code branch that
-does not return (calls `fork` or `exec` like function).
-
-Another special case is if the `putenv` is called from function `main`. Here
-the stack is deallocated at the end of the program and it should be no problem
-to use the stack-allocated string (a multi-threaded program may require more
-attention). The checker does not warn for cases when stack space of `main` is
-used at the `putenv` call.
-
 .. _alpha-security-ReturnPtrRange:
 
 alpha.security.ReturnPtrRange (C)
diff --git a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td 
b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
index 40f443047bd4b..9ab8e42f7cdcd 100644
--- a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -1011,6 +1011,11 @@ def FloatLoo

[clang] [Clang] Fix crash on improper use of __array_extent (PR #94173)

2024-06-03 Thread via cfe-commits

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

I've edited the title of the PR (which is then used as commit message)
Please follow that style in the future (see also 
https://llvm.org/docs/DeveloperPolicy.html#commit-messages)

The change itself looks fine, thanks!

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


[clang] [Clang] Allow raw string literals in C as an extension (PR #88265)

2024-06-03 Thread via cfe-commits

cor3ntin wrote:

> C has Unicode string literals as well: https://godbolt.org/z/chdjYrK9v and so 
> if we're allowing raw string literals, it makes sense to also allow raw 
> unicode string literals IMO. I don't think we need to rename the flag though.

Yes, these things are completely orthogonal, it makes no sense to treat raw 
strings with an encoding prefix differently

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


[clang] [Clang] Fix crash on improper use of __array_extent (PR #94173)

2024-06-03 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk updated 
https://github.com/llvm/llvm-project/pull/94173

>From b4f5d6d43d369649711cece6057c8fe2758a5a89 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Mon, 3 Jun 2024 00:22:02 +0300
Subject: [PATCH 1/2] fix(80474): use expression error on incomplete
 __array_extent

---
 clang/docs/ReleaseNotes.rst| 1 +
 clang/lib/Parse/ParseExprCXX.cpp   | 3 +++
 clang/test/SemaCXX/incomplete-array-extent.cpp | 5 +
 3 files changed, 9 insertions(+)
 create mode 100644 clang/test/SemaCXX/incomplete-array-extent.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0c700d23257bf..32515fbac64f6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -823,6 +823,7 @@ Bug Fixes to C++ Support
   differering by their constraints when only one of these function was 
variadic.
 - Fix a crash when a variable is captured by a block nested inside a lambda. 
(Fixes #GH93625).
 - Fixed a type constraint substitution issue involving a generic lambda 
expression. (#GH93821)
+- Fix a crash caused by improper use of ``__array_extent``. (#GH80474)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index 1558e3dcb8974..6f21a4f9bd826 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -4011,6 +4011,9 @@ ExprResult Parser::ParseArrayTypeTrait() {
 ExprResult DimExpr = ParseExpression();
 T.consumeClose();
 
+if (DimExpr.isInvalid())
+  return ExprError();
+
 return Actions.ActOnArrayTypeTrait(ATT, Loc, Ty.get(), DimExpr.get(),
T.getCloseLocation());
   }
diff --git a/clang/test/SemaCXX/incomplete-array-extent.cpp 
b/clang/test/SemaCXX/incomplete-array-extent.cpp
new file mode 100644
index 0..d59800f67a6ae
--- /dev/null
+++ b/clang/test/SemaCXX/incomplete-array-extent.cpp
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -verify -std=c++11 %s
+
+auto f() { // expected-error {{'auto' return without trailing return type; 
deduced return types are a C++14 extension}}
+  return __array_extent(int, ); // expected-error {{expected expression}}
+}

>From 5415766441ece7516cfea6d577988e73047873de Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Mon, 3 Jun 2024 09:58:00 +0300
Subject: [PATCH 2/2] use c++14 to reduce unnecessary diagnostics

---
 clang/test/SemaCXX/incomplete-array-extent.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/test/SemaCXX/incomplete-array-extent.cpp 
b/clang/test/SemaCXX/incomplete-array-extent.cpp
index d59800f67a6ae..8134af6b9251b 100644
--- a/clang/test/SemaCXX/incomplete-array-extent.cpp
+++ b/clang/test/SemaCXX/incomplete-array-extent.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -verify -std=c++11 %s
+// RUN: %clang_cc1 -verify -std=c++14 %s
 
-auto f() { // expected-error {{'auto' return without trailing return type; 
deduced return types are a C++14 extension}}
+auto f() {
   return __array_extent(int, ); // expected-error {{expected expression}}
 }

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


[clang] f4a7f81 - [clang-format][doc] Minor cleanup

2024-06-03 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2024-06-03T01:04:05-07:00
New Revision: f4a7f81a914ca8aceddd9b7a71e36bb0828ae052

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

LOG: [clang-format][doc] Minor cleanup

Added: 


Modified: 
clang/docs/ClangFormatStyleOptions.rst
clang/include/clang/Format/Format.h

Removed: 




diff  --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 677dac25df68e..bb00c20922d36 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -5117,7 +5117,7 @@ the configuration (without a prefix: ``Auto``).
 
   .. note::
 
-   It must contain ``type``.
+   It **must** contain ``type``.
 
   Items to the left of ``type`` will be placed to the left of the type and
   aligned in the order supplied. Items to the right of ``type`` will be
@@ -6410,6 +6410,7 @@ the configuration (without a prefix: ``Auto``).
 
 TableGenBreakInsideDAGArg: BreakAll
 TableGenBreakingDAGArgOperators: [ins, outs]
+
   makes the line break only occurs inside DAGArgs beginning with the
   specified identifiers ``ins`` and ``outs``.
 
@@ -6537,7 +6538,7 @@ The goal of the clang-format project is more on the side 
of supporting a
 limited set of styles really well as opposed to supporting every single style
 used by a codebase somewhere in the wild. Of course, we do want to support all
 major projects and thus have established the following bar for adding style
-options. Each new style option must ..
+options. Each new style option must:
 
   * be used in a project of significant size (have dozens of contributors)
   * have a publicly accessible style guide

diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 9bae252df366c..4fd6e013df25b 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -3650,7 +3650,7 @@ struct FormatStyle {
   ///   * type
   ///
   /// \note
-  ///  It \b must contain ``type``.
+  ///  It **must** contain ``type``.
   /// \endnote
   ///
   /// Items to the left of ``type`` will be placed to the left of the type and



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


[clang] [Clang][Comments] Add argument parsing for @throw @throws @exception (PR #84726)

2024-06-03 Thread via cfe-commits

https://github.com/cor3ntin commented:

The general direction looks good now. I left a few nitpicky comments.

Thanks!

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


[clang] [Clang][Comments] Add argument parsing for @throw @throws @exception (PR #84726)

2024-06-03 Thread via cfe-commits


@@ -89,6 +89,31 @@ class TextTokenRetokenizer {
 }
   }
 
+  /// Extract a template type
+  bool lexTemplate(SmallString<32> &WordText) {
+unsigned IncrementCounter = 0;
+while (!isEnd()) {
+  const char C = peek();
+  WordText.push_back(C);
+  consumeChar();

cor3ntin wrote:

It would be nice to modify `consumeChar` to return the consumed char

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


[clang] [Clang][Comments] Add argument parsing for @throw @throws @exception (PR #84726)

2024-06-03 Thread via cfe-commits

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


[clang] [Clang][Comments] Add argument parsing for @throw @throws @exception (PR #84726)

2024-06-03 Thread via cfe-commits


@@ -149,6 +174,54 @@ class TextTokenRetokenizer {
 addToken();
   }
 
+  /// Extract a type argument
+  bool lexType(Token &Tok) {
+if (isEnd())
+  return false;
+
+// Save current position in case we need to rollback because the type is
+// empty.
+Position SavedPos = Pos;
+
+// Consume any leading whitespace.
+consumeWhitespace();
+SmallString<32> WordText;
+const char *WordBegin = Pos.BufferPtr;
+SourceLocation Loc = getSourceLocation();
+
+while (!isEnd()) {
+  const char C = peek();
+  // For non-whitespace characters we check if it's a template or otherwise
+  // continue reading the text into a word.
+  if (!isWhitespace(C)) {
+if (C == '<') {
+  if (!lexTemplate(WordText))
+return false;
+} else {
+  WordText.push_back(C);
+  consumeChar();
+}
+  } else {
+consumeChar();
+break;
+  }
+}
+
+const unsigned Length = WordText.size();
+if (Length == 0) {
+  Pos = SavedPos;
+  return false;
+}
+
+char *TextPtr = Allocator.Allocate(Length + 1);
+
+memcpy(TextPtr, WordText.c_str(), Length + 1);
+StringRef Text = StringRef(TextPtr, Length);
+
+formTokenWithChars(Tok, Loc, WordBegin, Length, Text);

cor3ntin wrote:

I'd like to see that extracted in a separate function (and replace the few 
places where we do the exact same thing)

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


[clang] [Clang][Comments] Add argument parsing for @throw @throws @exception (PR #84726)

2024-06-03 Thread via cfe-commits


@@ -89,6 +89,31 @@ class TextTokenRetokenizer {
 }
   }
 
+  /// Extract a template type
+  bool lexTemplate(SmallString<32> &WordText) {
+unsigned IncrementCounter = 0;

cor3ntin wrote:

`BracketCount` would be a better name

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


[clang] [Clang][Comments] Add argument parsing for @throw @throws @exception (PR #84726)

2024-06-03 Thread via cfe-commits


@@ -295,6 +367,7 @@ Parser::parseCommandArgs(TextTokenRetokenizer &Retokenizer, 
unsigned NumArgs) {
   Comment::Argument[NumArgs];
   unsigned ParsedArgs = 0;
   Token Arg;
+

cor3ntin wrote:

Can you revert whitespace only changes?

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


[clang] [Clang][Comments] Add argument parsing for @throw @throws @exception (PR #84726)

2024-06-03 Thread via cfe-commits


@@ -100,6 +100,11 @@ class Parser {
   ArrayRef
   parseCommandArgs(TextTokenRetokenizer &Retokenizer, unsigned NumArgs);
 
+  /// Parse arguments for \\throws command supported args are in form of class

cor3ntin wrote:

```suggestion
  /// Parse arguments for \throws command supported args are in form of class
```

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


[clang] [Clang][Comments] Add argument parsing for @throw @throws @exception (PR #84726)

2024-06-03 Thread via cfe-commits


@@ -149,6 +276,93 @@ class TextTokenRetokenizer {
 addToken();
   }
 
+  /// Extract a type argument
+  bool lexType(Token &Tok) {
+if (isEnd())
+  return false;
+Position SavedPos = Pos;
+consumeWhitespace();
+SmallString<32> NextToken;
+SmallString<32> WordText;
+const char *WordBegin = Pos.BufferPtr;
+SourceLocation Loc = getSourceLocation();
+StringRef ConstVal = StringRef("const");
+StringRef PointerVal = StringRef("*");
+StringRef ReferenceVal = StringRef("&");
+bool ConstPointer = false;
+
+while (!isEnd()) {
+  const char C = peek();
+  if (!isWhitespace(C)) {
+if (C == '<') {
+  if (!lexTemplate(WordText))
+return false;
+} else {
+  WordText.push_back(C);

cor3ntin wrote:

Which I think is fine, we are just trying to find a boundary

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


[clang] ccb73e8 - [serialization] no transitive decl change (#92083)

2024-06-03 Thread via cfe-commits

Author: Chuanqi Xu
Date: 2024-06-03T16:13:55+08:00
New Revision: ccb73e882b2d727877cfda42a14a6979cfd31f04

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

LOG: [serialization] no transitive decl change (#92083)

Following of https://github.com/llvm/llvm-project/pull/86912

 Motivation Example

The motivation of the patch series is that, for a module interface unit
`X`, when the dependent modules of `X` changes, if the changes is not
relevant with `X`, we hope the BMI of `X` won't change. For the specific
patch, we hope if the changes was about irrelevant declaration changes,
we hope the BMI of `X` won't change. **However**, I found the patch
itself is not very useful in practice, since the adding or removing
declarations, will change the state of identifiers and types in most
cases.

That said, for the most simple example,

```
// partA.cppm
export module m:partA;

// partA.v1.cppm
export module m:partA;
export void a() {}

// partB.cppm
export module m:partB;
export void b() {}

// m.cppm
export module m;
export import :partA;
export import :partB;

// onlyUseB;
export module onlyUseB;
import m;
export inline void onluUseB() {
b();
}
```

the BMI of `onlyUseB` will change after we change the implementation of
`partA.cppm` to `partA.v1.cppm`. Since `partA.v1.cppm` introduces new
identifiers and types (the function prototype).

So in this patch, we have to write the tests as:

```
// partA.cppm
export module m:partA;
export int getA() { ... }
export int getA2(int) { ... }

// partA.v1.cppm
export module m:partA;
export int getA() { ... }
export int getA(int) { ... }
export int getA2(int) { ... }

// partB.cppm
export module m:partB;
export void b() {}

// m.cppm
export module m;
export import :partA;
export import :partB;

// onlyUseB;
export module onlyUseB;
import m;
export inline void onluUseB() {
b();
}
```

so that the new introduced declaration `int getA(int)` doesn't introduce
new identifiers and types, then the BMI of `onlyUseB` can keep
unchanged.

While it looks not so great, the patch should be the base of the patch
to erase the transitive change for identifiers and types since I don't
know how can we introduce new types and identifiers without introducing
new declarations. Given how tightly the relationship between
declarations, types and identifiers, I think we can only reach the ideal
state after we made the series for all of the three entties.

 Design details

The design of the patch is similar to
https://github.com/llvm/llvm-project/pull/86912, which extends the
32-bit DeclID to 64-bit and use the higher bits to store the module file
index and the lower bits to store the Local Decl ID.

A slight difference is that we only use 48 bits to store the new DeclID
since we try to use the higher 16 bits to store the module ID in the
prefix of Decl class. Previously, we use 32 bits to store the module ID
and 32 bits to store the DeclID. I don't want to allocate additional
space so I tried to make the additional space the same as 64 bits. An
potential interesting thing here is about the relationship between the
module ID and the module file index. I feel we can get the module file
index by the module ID. But I didn't prove it or implement it. Since I
want to make the patch itself as small as possible. We can make it in
the future if we want.

Another change in the patch is the new concept Decl Index, which means
the index of the very big array `DeclsLoaded` in ASTReader. Previously,
the index of a loaded declaration is simply the Decl ID minus
PREDEFINED_DECL_NUMs. So there are some places they got used
ambiguously. But this patch tried to split these two concepts.

 Overhead

As https://github.com/llvm/llvm-project/pull/86912 did, the change will
increase the on-disk PCM file sizes. As the declaration ID may be the
most IDs in the PCM file, this can have the biggest impact on the size.
In my experiments, this change will bring 6.6% increase of the on-disk
PCM size. No compile-time performance regression observed. Given the
benefits in the motivation example, I think the cost is worthwhile.

Added: 
clang/test/Modules/no-transitive-decls-change.cppm

Modified: 
clang/include/clang/AST/DeclBase.h
clang/include/clang/AST/DeclID.h
clang/include/clang/Serialization/ASTBitCodes.h
clang/include/clang/Serialization/ASTReader.h
clang/include/clang/Serialization/ModuleFile.h
clang/include/clang/Serialization/ModuleManager.h
clang/lib/AST/DeclBase.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTReaderDecl.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/lib/Serialization/ModuleFile.cpp

Removed: 




diff  --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index e43e812cd9

[clang] [serialization] no transitive decl change (PR #92083)

2024-06-03 Thread Chuanqi Xu via cfe-commits

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


[clang] [Serialization] No transitive identifier change (PR #92085)

2024-06-03 Thread Chuanqi Xu via cfe-commits

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


[clang] Pass LangOpts from CompilerInstance to DependencyScanningWorker (PR #93753)

2024-06-03 Thread via cfe-commits

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

I think this makes sense.
Thanks a lot for the fix

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


[clang] [llvm] [AMDGPU] Extend readlane, writelane and readfirstlane intrinsic lowering for generic types (PR #89217)

2024-06-03 Thread Vikram Hegde via cfe-commits

vikramRH wrote:

> You should add the mentioned convergence-tokens.ll test function

Added the test in a separate test file

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


[clang] [ClangFormat] Add DiagHandler for getStyle function (PR #91317)

2024-06-03 Thread via cfe-commits

pointhex wrote:

Hi @mydeveloperday, friendly reminder :)

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


[clang-tools-extra] Enforce SL.con.3: Add check to replace operator[] with at() (PR #90043)

2024-06-03 Thread Paul Heidekrüger via cfe-commits

PBHDK wrote:

> I am adding @leunam99 and @PBHDK to the PR, who will contribute in the next 
> few weeks.

Since we cannot push to this PR, we will be submitting a new PR with 
@sebwolf-de's + our work, correct, @EugeneZelenko, @PiotrZSL, @HerrCai0907?

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


[clang-tools-extra] Enforce SL.con.3: Add check to replace operator[] with at() (PR #90043)

2024-06-03 Thread Manuel Pietsch via cfe-commits


@@ -0,0 +1,81 @@
+//===--- AvoidBoundsErrorsCheck.cpp - clang-tidy 
--===//
+//
+// 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
+//
+//===--===//
+
+#include "AvoidBoundsErrorsCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+#include 
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::cppcoreguidelines {
+
+bool isApplicable(const QualType &Type) {
+  const auto TypeStr = Type.getAsString();
+  bool Result = false;
+  // Only check for containers in the std namespace
+  if (TypeStr.find("std::vector") != std::string::npos) {
+Result = true;
+  }
+  if (TypeStr.find("std::array") != std::string::npos) {
+Result = true;
+  }
+  if (TypeStr.find("std::deque") != std::string::npos) {
+Result = true;
+  }
+  if (TypeStr.find("std::map") != std::string::npos) {
+Result = true;

leunam99 wrote:

We had a look at the standard library; the same applies to `std::unordered_map` 
and `std::flat_map` too, correct? So, by default, we'd be excluding `std::map`, 
`std::unordered_map`, and `std::flat_map`. Can you think of any others?

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


[clang-tools-extra] Enforce SL.con.3: Add check to replace operator[] with at() (PR #90043)

2024-06-03 Thread Manuel Pietsch via cfe-commits


@@ -0,0 +1,66 @@
+namespace std {
+  template
+  struct array {
+T operator[](unsigned i) {
+  return T{1};
+}
+T at(unsigned i) {
+  return T{1};
+}
+  };
+
+  template
+  struct unique_ptr {
+T operator[](unsigned i) {
+  return T{1};
+}
+  };
+
+  template
+  struct span {
+T operator[](unsigned i) {
+  return T{1};
+}
+  };
+} // namespace std
+
+namespace json {
+  template
+  struct node{
+T operator[](unsigned i) {
+  return T{1};
+}
+  };
+} // namespace json
+
+
+// RUN: %check_clang_tidy %s cppcoreguidelines-avoid-bounds-errors %t
+std::array a;

leunam99 wrote:

As suggested, we added a test where the object is a template parameter and the 
method is called once with a class that has `at()` and once with a class that 
has not, but we are not sure what the best behaviour is. Should we 

-  not warn, because the fix suggested in the message will lead the other 
instantiation to not compile?
- warn at the place that requires the template instantiation?
- keep the warning and add the name of the class of the object / the template 
parameters that lead to the message?

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


[clang] [clang] Add tests for some CWG issues from 2024-05-31 telecon (PR #94167)

2024-06-03 Thread via cfe-commits

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

LGTM, thanks!

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


[clang] [clang] Add tests for some CWG issues from 2024-05-31 telecon (PR #94167)

2024-06-03 Thread via cfe-commits

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


[clang] [clang] Add tests for some CWG issues from 2024-05-31 telecon (PR #94167)

2024-06-03 Thread via cfe-commits


@@ -180,3 +200,64 @@ void f() {
 
 } // namespace cwg2881
 
+namespace cwg2882 { // cwg2882: 2.7 tentatively ready 2024-05-31
+struct C {
+  operator void() = delete;
+  // expected-warning@-1 {{conversion function converting 'cwg2882::C' to 
'void' will never be used}}
+  // cxx98-error@-2 {{deleted function definitions are a C++11 extension}}
+};
+
+void f(C c) {
+  (void)c;
+}
+} // namespace cwg2882
+
+namespace cwg2883 { // cwg2883: no tentatively ready 2024-05-31
+#if __cplusplus >= 201103L
+void f() {
+  int x;
+  (void)[&] {
+return x;
+  };
+}
+#endif
+#if __cplusplus >= 202002L
+struct A {
+  A() = default;
+  A(const A &) = delete; // #cwg2883-A-copy-ctor
+  constexpr operator int() { return 42; }
+};
+void g() {
+  constexpr A a;
+  // FIXME: OK, not odr-usable from a default template argument, and not 
odr-used
+  (void)[=] {};
+  // since-cxx20-error@-1 {{call to deleted constructor of 'const A'}}
+  //   since-cxx20-note@#cwg2883-A-copy-ctor {{'A' has been explicitly marked 
deleted here}}
+}
+#endif
+} // namespace cwg2883

cor3ntin wrote:

We do emit a diag later https://compiler-explorer.com/z/bd39GcqMP
I think it's still fair  to say it's not implemented

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


[clang] 8918d35 - [clang][Modules] Move `ASTSourceDescriptor` into its own file (#67930)

2024-06-03 Thread via cfe-commits

Author: David Stone
Date: 2024-06-03T11:09:13+02:00
New Revision: 8918d35dbde126c95350b674a2bb102692d90260

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

LOG: [clang][Modules] Move `ASTSourceDescriptor` into its own file (#67930)

Added: 
clang/include/clang/Basic/ASTSourceDescriptor.h
clang/lib/Basic/ASTSourceDescriptor.cpp

Modified: 
clang/include/clang/Basic/Module.h
clang/lib/AST/ExternalASTSource.cpp
clang/lib/Basic/CMakeLists.txt
clang/lib/Basic/Module.cpp
clang/lib/CodeGen/CGDebugInfo.h
clang/lib/Serialization/ASTReader.cpp
lldb/source/Plugins/ExpressionParser/Clang/ASTUtils.h

lldb/source/Plugins/ExpressionParser/Clang/ClangExternalASTSourceCallbacks.cpp
lldb/source/Plugins/ExpressionParser/Clang/ClangExternalASTSourceCallbacks.h

Removed: 




diff  --git a/clang/include/clang/Basic/ASTSourceDescriptor.h 
b/clang/include/clang/Basic/ASTSourceDescriptor.h
new file mode 100644
index 0..175e0551db765
--- /dev/null
+++ b/clang/include/clang/Basic/ASTSourceDescriptor.h
@@ -0,0 +1,52 @@
+//===- ASTSourceDescriptor.h -*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+/// \file
+/// Defines the clang::ASTSourceDescriptor class, which abstracts clang modules
+/// and precompiled header files
+//
+//===--===//
+
+#ifndef LLVM_CLANG_BASIC_ASTSOURCEDESCRIPTOR_H
+#define LLVM_CLANG_BASIC_ASTSOURCEDESCRIPTOR_H
+
+#include "clang/Basic/Module.h"
+#include "llvm/ADT/StringRef.h"
+#include 
+#include 
+
+namespace clang {
+
+/// Abstracts clang modules and precompiled header files and holds
+/// everything needed to generate debug info for an imported module
+/// or PCH.
+class ASTSourceDescriptor {
+  StringRef PCHModuleName;
+  StringRef Path;
+  StringRef ASTFile;
+  ASTFileSignature Signature;
+  Module *ClangModule = nullptr;
+
+public:
+  ASTSourceDescriptor() = default;
+  ASTSourceDescriptor(StringRef Name, StringRef Path, StringRef ASTFile,
+  ASTFileSignature Signature)
+  : PCHModuleName(std::move(Name)), Path(std::move(Path)),
+ASTFile(std::move(ASTFile)), Signature(Signature) {}
+  ASTSourceDescriptor(Module &M);
+
+  std::string getModuleName() const;
+  StringRef getPath() const { return Path; }
+  StringRef getASTFile() const { return ASTFile; }
+  ASTFileSignature getSignature() const { return Signature; }
+  Module *getModuleOrNull() const { return ClangModule; }
+};
+
+} // namespace clang
+
+#endif // LLVM_CLANG_BASIC_ASTSOURCEDESCRIPTOR_H

diff  --git a/clang/include/clang/Basic/Module.h 
b/clang/include/clang/Basic/Module.h
index 2d62d05cd9190..e86f4303d732b 100644
--- a/clang/include/clang/Basic/Module.h
+++ b/clang/include/clang/Basic/Module.h
@@ -868,32 +868,6 @@ class VisibleModuleSet {
   unsigned Generation = 0;
 };
 
-/// Abstracts clang modules and precompiled header files and holds
-/// everything needed to generate debug info for an imported module
-/// or PCH.
-class ASTSourceDescriptor {
-  StringRef PCHModuleName;
-  StringRef Path;
-  StringRef ASTFile;
-  ASTFileSignature Signature;
-  Module *ClangModule = nullptr;
-
-public:
-  ASTSourceDescriptor() = default;
-  ASTSourceDescriptor(StringRef Name, StringRef Path, StringRef ASTFile,
-  ASTFileSignature Signature)
-  : PCHModuleName(std::move(Name)), Path(std::move(Path)),
-ASTFile(std::move(ASTFile)), Signature(Signature) {}
-  ASTSourceDescriptor(Module &M);
-
-  std::string getModuleName() const;
-  StringRef getPath() const { return Path; }
-  StringRef getASTFile() const { return ASTFile; }
-  ASTFileSignature getSignature() const { return Signature; }
-  Module *getModuleOrNull() const { return ClangModule; }
-};
-
-
 } // namespace clang
 
 #endif // LLVM_CLANG_BASIC_MODULE_H

diff  --git a/clang/lib/AST/ExternalASTSource.cpp 
b/clang/lib/AST/ExternalASTSource.cpp
index e96a474968511..a5b6f80bde694 100644
--- a/clang/lib/AST/ExternalASTSource.cpp
+++ b/clang/lib/AST/ExternalASTSource.cpp
@@ -15,10 +15,10 @@
 #include "clang/AST/ExternalASTSource.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/DeclarationName.h"
+#include "clang/Basic/ASTSourceDescriptor.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/IdentifierTable.h"
 #include "clang/Basic/LLVM.h"
-#include "clang/Basic/Module.h"
 #include "clang/Basic/SourceManager.h"
 #include "llvm/Support/ErrorHandling.h"
 #include 

diff  --git a/clang/lib

[clang] [lldb] [clang][Modules] Move `ASTSourceDescriptor` into its own file (PR #67930)

2024-06-03 Thread via cfe-commits

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


[clang] [Clang] Implement resolution for CWG1835 (PR #92957)

2024-06-03 Thread Krystian Stasiowski via cfe-commits

sdkrystian wrote:

> > Per [[basic.lookup.qual.general] 
> > p1](http://eel.is/c++draft/basic.lookup.qual.general#1), lookup for a 
> > member-qualified name is type-only if it's an identifier followed by ::;
> 
> Per my reading, type-only lookup is performed only for elaborated type 
> specifiers (http://eel.is/c++draft/basic.lookup#elab-1.sentence-1) and 
> base-specifiers (http://eel.is/c++draft/class.derived#general-2.sentence-4). 
> What [basic.lookup.qual.general] p1 describes is much like type-only lookup, 
> but namespaces are considered. Another important difference is that 
> http://eel.is/c++draft/basic.lookup#general-4.sentence-2 does apply to lookup 
> of identifiers followed by `::`.
> 
> Not saying that this materially changes anything, but we should be more 
> cautious with terminology.

Sorry, I used "type-only" there but I intended to write "only considers 
namespaces, types, and templates whose specializations are types". I'll edit my 
comment to fix that. The intended phrasing is what I implemented.

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


[clang] [Clang] Implement resolution for CWG1835 (PR #92957)

2024-06-03 Thread Krystian Stasiowski via cfe-commits

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


[clang] [llvm] [RISCV] Remove experimental from Zabha (PR #93831)

2024-06-03 Thread via cfe-commits

AlexGhiti wrote:

> I'm guessing you don't have commit access?

I don't think so indeed (?).

Thanks for your quick review,

Alex

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


[clang] 6b74449 - [RISCV] Remove experimental from Zabha (#93831)

2024-06-03 Thread via cfe-commits

Author: AlexGhiti
Date: 2024-06-03T17:27:02+08:00
New Revision: 6b7444964a8d028989beee554a1f5c61d16a1cac

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

LOG: [RISCV] Remove experimental from Zabha (#93831)

The Zabha extension was ratified in April 2024.

Co-authored-by: Alexandre Ghiti 

Added: 


Modified: 
clang/test/Preprocessor/riscv-target-features.c
llvm/docs/RISCVUsage.rst
llvm/docs/ReleaseNotes.rst
llvm/lib/Target/RISCV/RISCVFeatures.td
llvm/test/CodeGen/RISCV/atomic-cmpxchg-branch-on-result.ll
llvm/test/CodeGen/RISCV/atomic-cmpxchg.ll
llvm/test/CodeGen/RISCV/atomic-rmw.ll
llvm/test/CodeGen/RISCV/attributes.ll
llvm/test/MC/RISCV/rvzabha-invalid.s
llvm/test/MC/RISCV/rvzabha-valid.s
llvm/test/MC/RISCV/rvzabha-zacas-valid.s
llvm/unittests/TargetParser/RISCVISAInfoTest.cpp

Removed: 




diff  --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index 0865add7e8fb8..09b9ad0a160bb 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -80,6 +80,7 @@
 // CHECK-NOT: __riscv_za128rs {{.*$}}
 // CHECK-NOT: __riscv_za64rs {{.*$}}
 // CHECK-NOT: __riscv_zaamo {{.*$}}
+// CHECK-NOT: __riscv_zabha {{.*$}}
 // CHECK-NOT: __riscv_zacas {{.*$}}
 // CHECK-NOT: __riscv_zalrsc {{.*$}}
 // CHECK-NOT: __riscv_zama16b {{.*$}}
@@ -176,7 +177,6 @@
 // CHECK-NOT: __riscv_sspm{{.*$}}
 // CHECK-NOT: __riscv_ssqosid{{.*$}}
 // CHECK-NOT: __riscv_supm{{.*$}}
-// CHECK-NOT: __riscv_zabha {{.*$}}
 // CHECK-NOT: __riscv_zalasr {{.*$}}
 // CHECK-NOT: __riscv_zfbfmin {{.*$}}
 // CHECK-NOT: __riscv_zicfilp {{.*$}}
@@ -715,6 +715,14 @@
 // RUN:   -o - | FileCheck --check-prefix=CHECK-ZAAMO-EXT %s
 // CHECK-ZAAMO-EXT: __riscv_zaamo 100{{$}}
 
+// RUN: %clang --target=riscv32 \
+// RUN:   -march=rv32ia_zabha1p0 -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-ZABHA-EXT %s
+// RUN: %clang --target=riscv64 \
+// RUN:   -march=rv64ia_zabha1p0 -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-ZABHA-EXT %s
+// CHECK-ZABHA-EXT: __riscv_zabha 100{{$}}
+
 // RUN: %clang --target=riscv32 \
 // RUN:   -march=rv32ia_zacas1p0 -E -dM %s \
 // RUN:   -o - | FileCheck --check-prefix=CHECK-ZACAS-EXT %s
@@ -1570,14 +1578,6 @@
 // CHECK-ZVKT-EXT: __riscv_zvkt 100{{$}}
 
 // Experimental extensions
-// RUN: %clang --target=riscv32 -menable-experimental-extensions \
-// RUN:   -march=rv32ia_zabha1p0 -E -dM %s \
-// RUN:   -o - | FileCheck --check-prefix=CHECK-ZABHA-EXT %s
-// RUN: %clang --target=riscv64 -menable-experimental-extensions \
-// RUN:   -march=rv64ia_zabha1p0 -E -dM %s \
-// RUN:   -o - | FileCheck --check-prefix=CHECK-ZABHA-EXT %s
-// CHECK-ZABHA-EXT: __riscv_zabha 100{{$}}
-
 // RUN: %clang --target=riscv32 -menable-experimental-extensions \
 // RUN:   -march=rv32i_zalasr0p1 -E -dM %s \
 // RUN:   -o - | FileCheck --check-prefix=CHECK-ZALASR-EXT %s

diff  --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index 5ecee2a480f7d..35115e67ecf92 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -120,6 +120,7 @@ on support follow.
  ``Za128rs``   Supported (`See note 
<#riscv-profiles-extensions-note>`__)
  ``Za64rs``Supported (`See note 
<#riscv-profiles-extensions-note>`__)
  ``Zaamo`` Assembly Support
+ ``Zabha`` Supported
  ``Zacas`` Supported (`See note <#riscv-zacas-note>`__)
  ``Zalrsc``Assembly Support
  ``Zama16b``   Supported (`See note 
<#riscv-profiles-extensions-note>`__)
@@ -262,9 +263,6 @@ The primary goal of experimental support is to assist in 
the process of ratifica
 ``experimental-ssqosid``
   LLVM implements assembler support for the `v1.0-rc1 draft specification 
`_.
 
-``experimental-zabha``
-  LLVM implements the `v1.0-rc1 draft specification 
`__.
-
 ``experimental-zalasr``
   LLVM implements the `0.0.5 draft specification 
`__.
 

diff  --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index c7c2c2825f58b..32ec26bf1dcb2 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -136,6 +136,7 @@ Changes to the RISC-V Backend
 * Added smstateen extension to -march. CSR names for smstateen were already 
supported.
 * Zaamo and Zalrsc are no longer experimental.
 * Processors that enable post reg-alloc scheduling (PostMachineScheduler) by 
default should use the `UsePostRAScheduler` subtarget feature. Setting 
`PostRAScheduler = 1` in the scheduler model will have no effect on the 
enabling of the PostMachin

[clang] [llvm] [RISCV] Remove experimental from Zabha (PR #93831)

2024-06-03 Thread Yingwei Zheng via cfe-commits

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


[clang] [llvm] [RISCV] Remove experimental from Zabha (PR #93831)

2024-06-03 Thread via cfe-commits

github-actions[bot] wrote:



@AlexGhiti Congratulations on having your first Pull Request (PR) merged into 
the LLVM Project!

Your changes will be combined with recent changes from other authors, then 
tested
by our [build bots](https://lab.llvm.org/buildbot/). If there is a problem with 
a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as
the builds can include changes from many authors. It is not uncommon for your
change to be included in a build that fails due to someone else's changes, or
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail 
[here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr).

If your change does cause a problem, it may be reverted, or you can revert it 
yourself.
This is a normal part of [LLVM 
development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy).
 You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are 
working as expected, well done!


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


[clang] 4f2dba3 - [clang] Add tests for some CWG issues from 2024-05-31 telecon (#94167)

2024-06-03 Thread via cfe-commits

Author: Vlad Serebrennikov
Date: 2024-06-03T13:47:28+04:00
New Revision: 4f2dba3c0b4e5f11b968a840b5f70070f5288cfe

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

LOG: [clang] Add tests for some CWG issues from 2024-05-31 telecon (#94167)

This patch adds tests for some CWG issues that were discussed at
2024-05-31 telecon. While all of them are tentatively ready at the
moment, I'm expecting them to be moved to DRs without changes. CWG
issues that are expected to have follow-ups are not included in this PR.

I also realized that `cwg28xx.cpp` has been testing without
`-pedantic-errors`. I fixed that. Fortunately, no existing tests had
anything hidden by the lack of this flag.

The following CWG issues are covered:
[CWG2877](https://cplusplus.github.io/CWG/issues/2877.html) "Type-only
lookup for _using-enum-declarator_"
[CWG2882](https://cplusplus.github.io/CWG/issues/2882.html) "Unclear
treatment of conversion to `void`"
[CWG2883](https://cplusplus.github.io/CWG/issues/2883.html) "Definition
of "odr-usable" ignores lambda scopes"
[CWG2885](https://cplusplus.github.io/CWG/issues/2885.html)
"Non-eligible trivial default constructors"
[CWG2886](https://cplusplus.github.io/CWG/issues/2886.html) "Temporaries
and trivial potentially-throwing special member functions"

Added: 


Modified: 
clang/test/CXX/drs/cwg28xx.cpp
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/test/CXX/drs/cwg28xx.cpp b/clang/test/CXX/drs/cwg28xx.cpp
index 8469a065ccaa0..da81eccc8dc22 100644
--- a/clang/test/CXX/drs/cwg28xx.cpp
+++ b/clang/test/CXX/drs/cwg28xx.cpp
@@ -1,10 +1,10 @@
-// RUN: %clang_cc1 -std=c++98 -verify=expected %s
-// RUN: %clang_cc1 -std=c++11 -verify=expected %s
-// RUN: %clang_cc1 -std=c++14 -verify=expected %s
-// RUN: %clang_cc1 -std=c++17 -verify=expected %s
-// RUN: %clang_cc1 -std=c++20 -verify=expected,since-cxx20 %s
-// RUN: %clang_cc1 -std=c++23 -verify=expected,since-cxx20,since-cxx23 %s
-// RUN: %clang_cc1 -std=c++2c 
-verify=expected,since-cxx20,since-cxx23,since-cxx26 %s
+// RUN: %clang_cc1 -std=c++98 -pedantic-errors -verify=expected,cxx98 %s
+// RUN: %clang_cc1 -std=c++11 -pedantic-errors -verify=expected %s
+// RUN: %clang_cc1 -std=c++14 -pedantic-errors -verify=expected %s
+// RUN: %clang_cc1 -std=c++17 -pedantic-errors -verify=expected %s
+// RUN: %clang_cc1 -std=c++20 -pedantic-errors -verify=expected,since-cxx20 %s
+// RUN: %clang_cc1 -std=c++23 -pedantic-errors 
-verify=expected,since-cxx20,since-cxx23 %s
+// RUN: %clang_cc1 -std=c++2c -pedantic-errors 
-verify=expected,since-cxx20,since-cxx23,since-cxx26 %s
 
 namespace cwg2819 { // cwg2819: 19 tentatively ready 2023-12-01
 #if __cpp_constexpr >= 202306L
@@ -110,6 +110,26 @@ struct A {
 
 } // namespace cwg2858
 
+namespace cwg2877 { // cwg2877: no tentatively ready 2024-05-31
+#if __cplusplus >= 202002L
+enum E { x };
+void f() {
+  int E;
+  // FIXME: OK, names ::E
+  using enum E;
+  // since-cxx20-error@-1 {{unknown type name E}}
+}
+using F = E;
+using enum F; // OK, designates ::E
+template using EE = T;
+void g() {
+  // FIXME: OK, designates ::E
+  using enum EE;
+  // since-cxx20-error@-1 {{using enum requires an enum or typedef name}}
+}
+#endif
+} // namespace cwg2877
+
 namespace cwg2881 { // cwg2881: 19 tentatively ready 2024-04-19
 
 #if __cplusplus >= 202302L
@@ -180,3 +200,64 @@ void f() {
 
 } // namespace cwg2881
 
+namespace cwg2882 { // cwg2882: 2.7 tentatively ready 2024-05-31
+struct C {
+  operator void() = delete;
+  // expected-warning@-1 {{conversion function converting 'cwg2882::C' to 
'void' will never be used}}
+  // cxx98-error@-2 {{deleted function definitions are a C++11 extension}}
+};
+
+void f(C c) {
+  (void)c;
+}
+} // namespace cwg2882
+
+namespace cwg2883 { // cwg2883: no tentatively ready 2024-05-31
+#if __cplusplus >= 201103L
+void f() {
+  int x;
+  (void)[&] {
+return x;
+  };
+}
+#endif
+#if __cplusplus >= 202002L
+struct A {
+  A() = default;
+  A(const A &) = delete; // #cwg2883-A-copy-ctor
+  constexpr operator int() { return 42; }
+};
+void g() {
+  constexpr A a;
+  // FIXME: OK, not odr-usable from a default template argument, and not 
odr-used
+  (void)[=] {};
+  // since-cxx20-error@-1 {{call to deleted constructor of 'const A'}}
+  //   since-cxx20-note@#cwg2883-A-copy-ctor {{'A' has been explicitly marked 
deleted here}}
+}
+#endif
+} // namespace cwg2883
+
+namespace cwg2885 { // cwg2885: 16 tentatively ready 2024-05-31
+#if __cplusplus >= 202002L
+template 
+struct A {
+  A() requires (false) = default;
+  A() : t(42) {}
+  T t;
+};
+
+struct B : A {};
+static_assert(!__is_trivially_constructible(B));
+#endif
+} // namespace cwg2885
+
+namespace cwg2886 { // cwg2886: 9 tentatively ready 2024-05-31
+#if __cplusplus >= 201103L
+struct C {

[clang] [clang] Add tests for some CWG issues from 2024-05-31 telecon (PR #94167)

2024-06-03 Thread Vlad Serebrennikov via cfe-commits

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


[clang] [ClangFormat] Add DiagHandler for getStyle function (PR #91317)

2024-06-03 Thread via cfe-commits

mydeveloperday wrote:

Please log an issue explaining the problem you are trying solve, its not clear 
to me what problem led you to this.

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


[clang] [Clang][Sema] Tweak tryCaptureVariable for unevaluated lambdas (PR #93206)

2024-06-03 Thread Younan Zhang via cfe-commits


@@ -1576,7 +1576,10 @@ ExprResult Parser::ParseLambdaExpressionAfterIntroducer(
   TrailingReturnTypeLoc, &DS),
   std::move(Attributes), DeclEndLoc);
 
-Actions.ActOnLambdaClosureQualifiers(Intro, MutableLoc);
+// We have called ActOnLambdaClosureQualifiers for parentheses-less cases

zyn0217 wrote:

> Yes, we need to set whether the lambda has a mutable keyword as soon as the 
> parameters, if present, are parsed, as that affect the meaning of subsequent 
> id-expressions
> When there are no parens, there can be a noexcept clause for example, and 
> parsing that does requires knowing whether the lambda is mutable, so that we 
> can adjust the type of any reference-to-capture.

Thanks, that makes sense! We currently set `LSI->Mutable` in 
`ActOnLambdaClosureQualifiers()` , and while I think it's possible to move it 
out of the function, I'm not opposed to leaving it as-is.

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


[clang] [Clang][Sema] Tweak tryCaptureVariable for unevaluated lambdas (PR #93206)

2024-06-03 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 updated 
https://github.com/llvm/llvm-project/pull/93206

>From 658e9d46adf6dd79aa6aef03a1817444a880348a Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Thu, 23 May 2024 22:35:11 +0800
Subject: [PATCH 1/3] [Clang][Sema] Tweak tryCaptureVariable for unevaluated
 lambdas

This patch picks up #78598 with the hope that we can address such
crashes in tryCaptureVariable for unevaluated lambdas.

In addition to tryCaptureVariable, this also contains several other
fixes on e.g. lambda parsing/dependencies.
---
 clang/docs/ReleaseNotes.rst   |   3 +
 clang/include/clang/AST/DeclBase.h|   4 +
 clang/lib/Parse/ParseExprCXX.cpp  |   5 +-
 clang/lib/Sema/SemaExpr.cpp   |  10 ++
 clang/lib/Sema/SemaLambda.cpp |  20 +++
 clang/lib/Sema/TreeTransform.h|   2 +-
 clang/test/SemaCXX/lambda-unevaluated.cpp | 164 ++
 7 files changed, 206 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 49ab222bec405..e06a5cd9536aa 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -710,6 +710,9 @@ Bug Fixes to C++ Support
 - Correctly treat the compound statement of an ``if consteval`` as an 
immediate context. Fixes (#GH91509).
 - When partial ordering alias templates against template template parameters,
   allow pack expansions when the alias has a fixed-size parameter list. Fixes 
(#GH62529).
+- Fixes several bugs in capturing variables within unevaluated contexts. Fixes 
(#GH63845), (#GH67260), (#GH69307), (#GH88081),
+  (#GH89496), (#GH90669) and (#GH91633).
+
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index e43e812cd9455..3a311d4c55916 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -2148,6 +2148,10 @@ class DeclContext {
getDeclKind() <= Decl::lastRecord;
   }
 
+  bool isRequiresExprBody() const {
+return getDeclKind() == Decl::RequiresExprBody;
+  }
+
   bool isNamespace() const { return getDeclKind() == Decl::Namespace; }
 
   bool isStdNamespace() const;
diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index 825031da358ad..73f619a085b04 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -1576,7 +1576,10 @@ ExprResult Parser::ParseLambdaExpressionAfterIntroducer(
   TrailingReturnTypeLoc, &DS),
   std::move(Attributes), DeclEndLoc);
 
-Actions.ActOnLambdaClosureQualifiers(Intro, MutableLoc);
+// We have called ActOnLambdaClosureQualifiers for parentheses-less cases
+// above.
+if (HasParentheses)
+  Actions.ActOnLambdaClosureQualifiers(Intro, MutableLoc);
 
 if (HasParentheses && Tok.is(tok::kw_requires))
   ParseTrailingRequiresClause(D);
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index e6c3fa51d54da..7a4ede9898034 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -18831,6 +18831,10 @@ bool Sema::tryCaptureVariable(
   DeclContext *VarDC = Var->getDeclContext();
   DeclContext *DC = CurContext;
 
+  // Skip past RequiresExprBodys because they don't constitute function scopes.
+  while (DC->isRequiresExprBody())
+DC = DC->getParent();
+
   // tryCaptureVariable is called every time a DeclRef is formed,
   // it can therefore have non-negigible impact on performances.
   // For local variables and when there is no capturing scope,
@@ -18838,6 +18842,12 @@ bool Sema::tryCaptureVariable(
   if (CapturingFunctionScopes == 0 && (!BuildAndDiagnose || VarDC == DC))
 return true;
 
+  // Exception: Function parameters are not tied to the function's DeclContext
+  // until we enter the function definition. Capturing them anyway would result
+  // in an out-of-bounds error while traversing DC and its parents.
+  if (isa(Var) && !VarDC->isFunctionOrMethod())
+return true;
+
   const auto *VD = dyn_cast(Var);
   if (VD) {
 if (VD->isInitCapture())
diff --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index 1743afaf15287..999316e544b91 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -1036,6 +1036,7 @@ void 
Sema::ActOnLambdaExpressionAfterIntroducer(LambdaIntroducer &Intro,
   // be dependent, because there are template parameters in scope.
   CXXRecordDecl::LambdaDependencyKind LambdaDependencyKind =
   CXXRecordDecl::LDK_Unknown;
+
   if (LSI->NumExplicitTemplateParams > 0) {
 Scope *TemplateParamScope = CurScope->getTemplateParamParent();
 assert(TemplateParamScope &&
@@ -1046,6 +1047,25 @@ void 
Sema::ActOnLambdaExpressionAfterIntroducer(LambdaIntroducer &Intro,
   LambdaDependencyKind = CXXRecordDecl::LDK_AlwaysDependent;
   } else if (CurScope->getTemplateParamParent() != nullptr) {
 LambdaDependencyKind = CXXRe

[clang] [clang-format] Handle AttributeMacros in parseRecord() (PR #94189)

2024-06-03 Thread via cfe-commits

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


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


[clang] [clang-format] Add DiagHandler for getStyle function (PR #91317)

2024-06-03 Thread via cfe-commits

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


[clang] [Clang][Sema] Tweak tryCaptureVariable for unevaluated lambdas (PR #93206)

2024-06-03 Thread Younan Zhang via cfe-commits

zyn0217 wrote:

@cor3ntin I have reduced the test cases (removed duplicate ones) and hopefully 
they look better. Can you please take another look? thanks!

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


[clang] [clang][analyzer] Move PutenvStackArrayChecker out of alpha package (PR #93980)

2024-06-03 Thread Balazs Benics via cfe-commits
=?utf-8?q?Balázs_Kéri?= 
Message-ID:
In-Reply-To: 


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


[clang] [clang][analyzer] Move PutenvStackArrayChecker out of alpha package (PR #93980)

2024-06-03 Thread Balazs Benics via cfe-commits
=?utf-8?q?Bal=C3=A1zs_K=C3=A9ri?= 
Message-ID:
In-Reply-To: 


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


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


[clang] [llvm] [OpenMP] OpenMP 5.1 "assume" directive parsing support (PR #92731)

2024-06-03 Thread Julian Brown via cfe-commits

https://github.com/jtb20 updated https://github.com/llvm/llvm-project/pull/92731

>From 4337a97fb8982addfd6740db2ff08dfb0398842e Mon Sep 17 00:00:00 2001
From: Julian Brown 
Date: Wed, 1 May 2024 06:35:59 -0500
Subject: [PATCH] [OpenMP] OpenMP 5.1 "assume" directive parsing support

This is a minimal patch to support parsing for "omp assume" directives.
These are meant to be hints to a compiler' optimisers: as such, it is
legitimate (if not very useful) to ignore them.  The patch builds on top
of the existing support for "omp assumes" directives (note spelling!).

Unlike the "omp [begin/end] assumes" directives, "omp assume" is
associated with a compound statement, i.e. it can appear within a
function.  The "holds" assumption could (theoretically) be mapped onto
the existing builtin "__builtin_assume", though the latter applies to a
single point in the program, and the former to a range (i.e. the whole
of the associated compound statement).

This patch fixes sollve's OpenMP 5.1 "omp assume"-based tests.

Change-Id: Ibd4a0e2af82c4ac818eaa3de8867a006307361ec
---
 clang/lib/Parse/ParseOpenMP.cpp  | 22 +
 clang/lib/Sema/SemaOpenMP.cpp|  3 +-
 clang/test/OpenMP/assume_lambda.cpp  | 31 +
 clang/test/OpenMP/assume_messages.c  | 23 +
 clang/test/OpenMP/assume_messages_attr.c | 23 +
 clang/test/OpenMP/assume_template.cpp| 42 
 llvm/include/llvm/Frontend/OpenMP/OMP.td |  3 ++
 7 files changed, 146 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/OpenMP/assume_lambda.cpp
 create mode 100644 clang/test/OpenMP/assume_messages.c
 create mode 100644 clang/test/OpenMP/assume_messages_attr.c
 create mode 100644 clang/test/OpenMP/assume_template.cpp

diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 50a872fedebf7c..513af9846aa7ed 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -2444,6 +2444,7 @@ Parser::DeclGroupPtrTy 
Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl(
   case OMPD_target_teams_loop:
   case OMPD_parallel_loop:
   case OMPD_target_parallel_loop:
+  case OMPD_assume:
 Diag(Tok, diag::err_omp_unexpected_directive)
 << 1 << getOpenMPDirectiveName(DKind);
 break;
@@ -3023,6 +3024,27 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
 << 1 << getOpenMPDirectiveName(DKind);
 SkipUntil(tok::annot_pragma_openmp_end);
 break;
+  case OMPD_assume: {
+ParseScope OMPDirectiveScope(this, Scope::FnScope | Scope::DeclScope |
+ Scope::CompoundStmtScope);
+ParseOpenMPAssumesDirective(DKind, ConsumeToken());
+
+SkipUntil(tok::annot_pragma_openmp_end);
+
+ParsingOpenMPDirectiveRAII NormalScope(*this);
+StmtResult AssociatedStmt;
+{
+  Sema::CompoundScopeRAII Scope(Actions);
+  AssociatedStmt = ParseStatement();
+  EndLoc = Tok.getLocation();
+  Directive = Actions.ActOnCompoundStmt(Loc, EndLoc,
+AssociatedStmt.get(),
+/*isStmtExpr=*/false);
+}
+ParseOpenMPEndAssumesDirective(Loc);
+OMPDirectiveScope.Exit();
+break;
+  }
   case OMPD_unknown:
   default:
 Diag(Tok, diag::err_omp_unknown_directive);
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 99528c2a4f1f44..82aaafa91b715f 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -3511,7 +3511,8 @@ void 
SemaOpenMP::ActOnOpenMPAssumesDirective(SourceLocation Loc,
 
   auto *AA =
   OMPAssumeAttr::Create(getASTContext(), llvm::join(Assumptions, ","), 
Loc);
-  if (DKind == llvm::omp::Directive::OMPD_begin_assumes) {
+  if (DKind == llvm::omp::Directive::OMPD_begin_assumes ||
+  DKind == llvm::omp::Directive::OMPD_assume) {
 OMPAssumeScoped.push_back(AA);
 return;
   }
diff --git a/clang/test/OpenMP/assume_lambda.cpp 
b/clang/test/OpenMP/assume_lambda.cpp
new file mode 100644
index 00..a38380ed4482a3
--- /dev/null
+++ b/clang/test/OpenMP/assume_lambda.cpp
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -ast-print %s | FileCheck %s
+// expected-no-diagnostics
+
+extern int bar(int);
+
+int foo(int arg)
+{
+  #pragma omp assume no_openmp_routines
+  {
+auto fn = [](int x) { return bar(x); };
+// CHECK: auto fn = [](int x) {
+return fn(5);
+  }
+}
+
+class C {
+public:
+  int foo(int a);
+};
+
+// We're really just checking that this parses.  All the assumptions are thrown
+// away immediately for now.
+int C::foo(int a)
+{
+  #pragma omp assume holds(sizeof(T) == 8) absent(parallel)
+  {
+auto fn = [](int x) { return bar(x); };
+// CHECK: auto fn = [](int x) {
+return fn(5);
+  }
+}
\ No newline at end of file
diff --git a/clang/test/OpenMP/assume_messages.c 
b/clang/test/OpenMP/assume_messages.c
new file mode 100644
index 00..33c1c6f7c

[clang] [clang] Make sure all C++ DR tests are running with `-pedantic-errors` (PR #94203)

2024-06-03 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll created 
https://github.com/llvm/llvm-project/pull/94203

In #94167 I found out that `cwg28xx.cpp` has been running without 
`-pedantic-errors` and fixed that. This patch fixes that for the rest of the 
test suite. Only one tests as affected with a trivial fix (warning was 
escalated to an error).

I'm intentionally leaving out test for CWG2390, because it requires major 
surgery. I'll address it separately.

>From ab76669285344516c7cf59d7a3e9b051b3e1c2f4 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Mon, 3 Jun 2024 13:07:23 +0300
Subject: [PATCH] [clang] Make sure all C++ DR tests are running with
 `-pedantic-errors`

---
 clang/test/CXX/drs/cwg24xx.cpp | 14 +++---
 clang/test/CXX/drs/cwg2630.cpp | 12 ++--
 clang/test/CXX/drs/cwg26xx.cpp | 16 
 clang/test/CXX/drs/cwg27xx.cpp | 14 +++---
 4 files changed, 28 insertions(+), 28 deletions(-)

diff --git a/clang/test/CXX/drs/cwg24xx.cpp b/clang/test/CXX/drs/cwg24xx.cpp
index 4c7b1506e86ea..16b8ec07fc50f 100644
--- a/clang/test/CXX/drs/cwg24xx.cpp
+++ b/clang/test/CXX/drs/cwg24xx.cpp
@@ -1,10 +1,10 @@
-// RUN: %clang_cc1 -std=c++98 %s -verify=expected
-// RUN: %clang_cc1 -std=c++11 %s -verify=expected
-// RUN: %clang_cc1 -std=c++14 %s -verify=expected
-// RUN: %clang_cc1 -std=c++17 %s -verify=expected,since-cxx17
-// RUN: %clang_cc1 -std=c++20 %s -verify=expected,since-cxx17
-// RUN: %clang_cc1 -std=c++23 %s -verify=expected,since-cxx17
-// RUN: %clang_cc1 -std=c++2c %s -verify=expected,since-cxx17
+// RUN: %clang_cc1 -std=c++98 -pedantic-errors %s -verify=expected
+// RUN: %clang_cc1 -std=c++11 -pedantic-errors %s -verify=expected
+// RUN: %clang_cc1 -std=c++14 -pedantic-errors %s -verify=expected
+// RUN: %clang_cc1 -std=c++17 -pedantic-errors %s -verify=expected,since-cxx17
+// RUN: %clang_cc1 -std=c++20 -pedantic-errors %s -verify=expected,since-cxx17
+// RUN: %clang_cc1 -std=c++23 -pedantic-errors %s -verify=expected,since-cxx17
+// RUN: %clang_cc1 -std=c++2c -pedantic-errors %s -verify=expected,since-cxx17
 
 #if __cplusplus <= 201402L
 // expected-no-diagnostics
diff --git a/clang/test/CXX/drs/cwg2630.cpp b/clang/test/CXX/drs/cwg2630.cpp
index 0f50dc4f7458c..b20aed45b1410 100644
--- a/clang/test/CXX/drs/cwg2630.cpp
+++ b/clang/test/CXX/drs/cwg2630.cpp
@@ -1,10 +1,10 @@
 // RUN: split-file --leading-lines %s %t
-// RUN: %clang_cc1 -std=c++20 -verify -emit-module-interface %t/module.cppm -o 
%t/module.pcm
-// RUN: %clang_cc1 -std=c++20 -verify -fmodule-file=A=%t/module.pcm %t/main.cpp
-// RUN: %clang_cc1 -std=c++23 -verify -emit-module-interface %t/module.cppm -o 
%t/module.pcm
-// RUN: %clang_cc1 -std=c++23 -verify -fmodule-file=A=%t/module.pcm %t/main.cpp
-// RUN: %clang_cc1 -std=c++2c -verify -emit-module-interface %t/module.cppm -o 
%t/module.pcm
-// RUN: %clang_cc1 -std=c++2c -verify -fmodule-file=A=%t/module.pcm %t/main.cpp
+// RUN: %clang_cc1 -std=c++20 -pedantic-errors -verify -emit-module-interface 
%t/module.cppm -o %t/module.pcm
+// RUN: %clang_cc1 -std=c++20 -pedantic-errors -verify 
-fmodule-file=A=%t/module.pcm %t/main.cpp
+// RUN: %clang_cc1 -std=c++23 -pedantic-errors -verify -emit-module-interface 
%t/module.cppm -o %t/module.pcm
+// RUN: %clang_cc1 -std=c++23 -pedantic-errors -verify 
-fmodule-file=A=%t/module.pcm %t/main.cpp
+// RUN: %clang_cc1 -std=c++2c -pedantic-errors -verify -emit-module-interface 
%t/module.cppm -o %t/module.pcm
+// RUN: %clang_cc1 -std=c++2c -pedantic-errors -verify 
-fmodule-file=A=%t/module.pcm %t/main.cpp
 
 //--- module.cppm
 // expected-no-diagnostics
diff --git a/clang/test/CXX/drs/cwg26xx.cpp b/clang/test/CXX/drs/cwg26xx.cpp
index d3c5b5bb7b6b9..05c5d0a4963a5 100644
--- a/clang/test/CXX/drs/cwg26xx.cpp
+++ b/clang/test/CXX/drs/cwg26xx.cpp
@@ -1,10 +1,10 @@
-// RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s 
-verify=expected
-// RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s 
-verify=expected,since-cxx11,cxx11
-// RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s 
-verify=expected,since-cxx11
-// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s 
-verify=expected,since-cxx11
-// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s 
-verify=expected,since-cxx11,since-cxx20
-// RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-unknown %s 
-verify=expected,since-cxx11,since-cxx20,since-cxx23
-// RUN: %clang_cc1 -std=c++2c -triple x86_64-unknown-unknown %s 
-verify=expected,since-cxx11,since-cxx20,since-cxx23
+// RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown -pedantic-errors 
%s -verify=expected
+// RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown -pedantic-errors 
%s -verify=expected,since-cxx11,cxx11
+// RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown -pedantic-errors 
%s -verify=expected,since-cxx11
+// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown -pedantic-errors 
%s -verify=expected,since-cxx11
+// RUN: %clang_cc1 -std=c++20 -tri

[clang] [clang] Make sure all C++ DR tests are running with `-pedantic-errors` (PR #94203)

2024-06-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Vlad Serebrennikov (Endilll)


Changes

In #94167 I found out that `cwg28xx.cpp` has been running without 
`-pedantic-errors` and fixed that. This patch fixes that for the rest of the 
test suite. Only one tests as affected with a trivial fix (warning was 
escalated to an error).

I'm intentionally leaving out test for CWG2390, because it requires major 
surgery. I'll address it separately.

---
Full diff: https://github.com/llvm/llvm-project/pull/94203.diff


4 Files Affected:

- (modified) clang/test/CXX/drs/cwg24xx.cpp (+7-7) 
- (modified) clang/test/CXX/drs/cwg2630.cpp (+6-6) 
- (modified) clang/test/CXX/drs/cwg26xx.cpp (+8-8) 
- (modified) clang/test/CXX/drs/cwg27xx.cpp (+7-7) 


``diff
diff --git a/clang/test/CXX/drs/cwg24xx.cpp b/clang/test/CXX/drs/cwg24xx.cpp
index 4c7b1506e86ea..16b8ec07fc50f 100644
--- a/clang/test/CXX/drs/cwg24xx.cpp
+++ b/clang/test/CXX/drs/cwg24xx.cpp
@@ -1,10 +1,10 @@
-// RUN: %clang_cc1 -std=c++98 %s -verify=expected
-// RUN: %clang_cc1 -std=c++11 %s -verify=expected
-// RUN: %clang_cc1 -std=c++14 %s -verify=expected
-// RUN: %clang_cc1 -std=c++17 %s -verify=expected,since-cxx17
-// RUN: %clang_cc1 -std=c++20 %s -verify=expected,since-cxx17
-// RUN: %clang_cc1 -std=c++23 %s -verify=expected,since-cxx17
-// RUN: %clang_cc1 -std=c++2c %s -verify=expected,since-cxx17
+// RUN: %clang_cc1 -std=c++98 -pedantic-errors %s -verify=expected
+// RUN: %clang_cc1 -std=c++11 -pedantic-errors %s -verify=expected
+// RUN: %clang_cc1 -std=c++14 -pedantic-errors %s -verify=expected
+// RUN: %clang_cc1 -std=c++17 -pedantic-errors %s -verify=expected,since-cxx17
+// RUN: %clang_cc1 -std=c++20 -pedantic-errors %s -verify=expected,since-cxx17
+// RUN: %clang_cc1 -std=c++23 -pedantic-errors %s -verify=expected,since-cxx17
+// RUN: %clang_cc1 -std=c++2c -pedantic-errors %s -verify=expected,since-cxx17
 
 #if __cplusplus <= 201402L
 // expected-no-diagnostics
diff --git a/clang/test/CXX/drs/cwg2630.cpp b/clang/test/CXX/drs/cwg2630.cpp
index 0f50dc4f7458c..b20aed45b1410 100644
--- a/clang/test/CXX/drs/cwg2630.cpp
+++ b/clang/test/CXX/drs/cwg2630.cpp
@@ -1,10 +1,10 @@
 // RUN: split-file --leading-lines %s %t
-// RUN: %clang_cc1 -std=c++20 -verify -emit-module-interface %t/module.cppm -o 
%t/module.pcm
-// RUN: %clang_cc1 -std=c++20 -verify -fmodule-file=A=%t/module.pcm %t/main.cpp
-// RUN: %clang_cc1 -std=c++23 -verify -emit-module-interface %t/module.cppm -o 
%t/module.pcm
-// RUN: %clang_cc1 -std=c++23 -verify -fmodule-file=A=%t/module.pcm %t/main.cpp
-// RUN: %clang_cc1 -std=c++2c -verify -emit-module-interface %t/module.cppm -o 
%t/module.pcm
-// RUN: %clang_cc1 -std=c++2c -verify -fmodule-file=A=%t/module.pcm %t/main.cpp
+// RUN: %clang_cc1 -std=c++20 -pedantic-errors -verify -emit-module-interface 
%t/module.cppm -o %t/module.pcm
+// RUN: %clang_cc1 -std=c++20 -pedantic-errors -verify 
-fmodule-file=A=%t/module.pcm %t/main.cpp
+// RUN: %clang_cc1 -std=c++23 -pedantic-errors -verify -emit-module-interface 
%t/module.cppm -o %t/module.pcm
+// RUN: %clang_cc1 -std=c++23 -pedantic-errors -verify 
-fmodule-file=A=%t/module.pcm %t/main.cpp
+// RUN: %clang_cc1 -std=c++2c -pedantic-errors -verify -emit-module-interface 
%t/module.cppm -o %t/module.pcm
+// RUN: %clang_cc1 -std=c++2c -pedantic-errors -verify 
-fmodule-file=A=%t/module.pcm %t/main.cpp
 
 //--- module.cppm
 // expected-no-diagnostics
diff --git a/clang/test/CXX/drs/cwg26xx.cpp b/clang/test/CXX/drs/cwg26xx.cpp
index d3c5b5bb7b6b9..05c5d0a4963a5 100644
--- a/clang/test/CXX/drs/cwg26xx.cpp
+++ b/clang/test/CXX/drs/cwg26xx.cpp
@@ -1,10 +1,10 @@
-// RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s 
-verify=expected
-// RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s 
-verify=expected,since-cxx11,cxx11
-// RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s 
-verify=expected,since-cxx11
-// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s 
-verify=expected,since-cxx11
-// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s 
-verify=expected,since-cxx11,since-cxx20
-// RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-unknown %s 
-verify=expected,since-cxx11,since-cxx20,since-cxx23
-// RUN: %clang_cc1 -std=c++2c -triple x86_64-unknown-unknown %s 
-verify=expected,since-cxx11,since-cxx20,since-cxx23
+// RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown -pedantic-errors 
%s -verify=expected
+// RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown -pedantic-errors 
%s -verify=expected,since-cxx11,cxx11
+// RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown -pedantic-errors 
%s -verify=expected,since-cxx11
+// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown -pedantic-errors 
%s -verify=expected,since-cxx11
+// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown -pedantic-errors 
%s -verify=expected,since-cxx11,since-cxx20
+// RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-unknown -pedantic-error

[clang] [analyzer][NFC] Fix comparison to True/False (PR #94038)

2024-06-03 Thread Donát Nagy via cfe-commits

https://github.com/NagyDonat commented:

This change follows both the letter and the spirit of PEP8. (Note that `True` 
and `False` are not "singletons like `None`" because the type `bool` has two 
possible values -- but different rules still claim that the original code was 
bad and the new code is good.)  

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


[clang] [clang][analyzer] Improved PointerSubChecker (PR #93676)

2024-06-03 Thread Donát Nagy via cfe-commits


@@ -0,0 +1,74 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.core.PointerSub -verify %s
+
+void f1(void) {
+  int x, y, z[10];
+  int d = &y - &x; // expected-warning{{Subtraction of two pointers that do 
not point into the same array is undefined behavior}}
+  d = z - &y; // expected-warning{{Subtraction of two pointers that do not 
point into the same array is undefined behavior}}
+  d = &x - &x; // expected-warning{{Subtraction of two pointers that do not 
point into the same array is undefined behavior}}
+  d = (long*)&x - (long*)&x;
+}
+
+void f2(void) {
+  int a[10], b[10], c;
+  int *p = &a[2];
+  int *q = &a[8];
+  int d = q - p; // no-warning
+
+  q = &b[3];
+  d = q - p; // expected-warning{{Subtraction of two pointers that}}
+
+  q = a + 10;
+  d = q - p; // no warning (use of pointer to one after the end is allowed)
+  d = &a[4] - a; // no warning
+
+  q = a + 11;
+  d = q - a; // ?
+
+  d = &c - p; // expected-warning{{Subtraction of two pointers that}}
+}
+
+void f3(void) {
+  int a[3][4];
+  int d;
+
+  d = &(a[2]) - &(a[1]);
+  d = a[2] - a[1]; // expected-warning{{Subtraction of two pointers that}}
+  d = a[1] - a[1];
+  d = &(a[1][2]) - &(a[1][0]);
+  d = &(a[1][2]) - &(a[0][0]); // expected-warning{{Subtraction of two 
pointers that}}
+}
+
+void f4(void) {
+  int n = 4, m = 3;
+  int a[n][m];
+  int (*p)[m] = a; // p == &a[0]
+  p += 1; // p == &a[1]
+  int d = p - a; // d == 1 // expected-warning{{subtraction of pointers to 
type 'int[m]' of zero size has undefined behavior}}
+
+  d = &(a[2]) - &(a[1]); // expected-warning{{subtraction of pointers to type 
'int[m]' of zero size has undefined behavior}}
+  d = a[2] - a[1]; // expected-warning{{Subtraction of two pointers that}}

NagyDonat wrote:

Could you add a FIXME comment which states that these "type 'int[m]' of zero 
size" warnings are false positives emitted by checker X (and they should be 
eliminated eventually)?

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


[clang] Reapply "[Clang][CWG1815] Support lifetime extension of temporary created by aggregate initialization using a default member initializer" (PR #92527)

2024-06-03 Thread via cfe-commits

bgra8 wrote:

heads-up @yronglin: we've bisected many compilation breakages to this patch.
We're working on a reproducer.

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


[clang] [clang-format] Add DiagHandler for getStyle function (PR #91317)

2024-06-03 Thread via cfe-commits

pointhex wrote:

Done: https://github.com/llvm/llvm-project/issues/94205

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


[clang] [clang] Move CWG2390 test into `cwg23xx.cpp` (PR #94206)

2024-06-03 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll created 
https://github.com/llvm/llvm-project/pull/94206

This patch refactors an existing test for 
[CWG2390](https://cplusplus.github.io/CWG/issues/2390.html) "Is the argument of 
`__has_cpp_attribute` macro-expanded?" to use `#error` instead of emitting a 
variable in IRGen and checking it via FileCheck. As a bonus, this makes it 
possible to move the test into `cwg23xx.cpp`.

>From 8b5382c62691ac4cb8bb0eeb0fe6a2b97b602b66 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Mon, 3 Jun 2024 13:19:28 +0300
Subject: [PATCH] [clang] Move CWG2390 test into `cwg23xx.cpp`

---
 clang/test/CXX/drs/cwg2390.cpp | 47 --
 clang/test/CXX/drs/cwg23xx.cpp | 37 +-
 2 files changed, 36 insertions(+), 48 deletions(-)
 delete mode 100644 clang/test/CXX/drs/cwg2390.cpp

diff --git a/clang/test/CXX/drs/cwg2390.cpp b/clang/test/CXX/drs/cwg2390.cpp
deleted file mode 100644
index 41bbd0d1c5499..0
--- a/clang/test/CXX/drs/cwg2390.cpp
+++ /dev/null
@@ -1,47 +0,0 @@
-// RUN: %clang_cc1 -E -P %s -o - | FileCheck %s
-
-// cwg2390: 14
-
-namespace PR48462 {
-// Test that macro expansion of the builtin argument works.
-#define C clang
-#define F fallthrough
-#define CF clang::fallthrough
-
-#if __has_cpp_attribute(F)
-int has_fallthrough;
-#endif
-// CHECK: int has_fallthrough;
-
-#if __has_cpp_attribute(C::F)
-int has_clang_fallthrough_1;
-#endif
-// CHECK: int has_clang_fallthrough_1;
-
-#if __has_cpp_attribute(clang::F)
-int has_clang_fallthrough_2;
-#endif
-// CHECK: int has_clang_fallthrough_2;
-
-#if __has_cpp_attribute(C::fallthrough)
-int has_clang_fallthrough_3;
-#endif
-// CHECK: int has_clang_fallthrough_3;
-
-#if __has_cpp_attribute(CF)
-int has_clang_fallthrough_4;
-#endif
-// CHECK: int has_clang_fallthrough_4;
-
-#define FUNCLIKE1(x) clang::x
-#if __has_cpp_attribute(FUNCLIKE1(fallthrough))
-int funclike_1;
-#endif
-// CHECK: int funclike_1;
-
-#define FUNCLIKE2(x) _Clang::x
-#if __has_cpp_attribute(FUNCLIKE2(fallthrough))
-int funclike_2;
-#endif
-// CHECK: int funclike_2;
-} // namespace PR48462
diff --git a/clang/test/CXX/drs/cwg23xx.cpp b/clang/test/CXX/drs/cwg23xx.cpp
index ae5ec3b878f59..e4a1e90941dbf 100644
--- a/clang/test/CXX/drs/cwg23xx.cpp
+++ b/clang/test/CXX/drs/cwg23xx.cpp
@@ -317,7 +317,42 @@ namespace cwg2387 { // cwg2387: 9
 #endif
 }
 
-// cwg2390 is in cwg2390.cpp
+namespace cwg2390 { // cwg2390: 14
+// Test that macro expansion of the builtin argument works.
+#define C clang
+#define F fallthrough
+#define CF clang::fallthrough
+
+#if !__has_cpp_attribute(F)
+#error "doesn't have fallthrough"
+#endif
+
+#if !__has_cpp_attribute(C::F)
+#error "doesn't have clang::fallthrough 1"
+#endif
+
+#if !__has_cpp_attribute(clang::F)
+#error "doesn't have clang::fallthrough 2"
+#endif
+
+#if !__has_cpp_attribute(C::fallthrough)
+#error "doesn't have clang::fallthrough 3"
+#endif
+
+#if !__has_cpp_attribute(CF)
+#error "doesn't have clang::fallthrough 4"
+#endif
+
+#define FUNCLIKE1(x) clang::x
+#if !__has_cpp_attribute(FUNCLIKE1(fallthrough))
+#error "doesn't have clang::fallthrough through func-like macro 1"
+#endif
+
+#define FUNCLIKE2(x) _Clang::x
+#if !__has_cpp_attribute(FUNCLIKE2(fallthrough))
+#error "doesn't have clang::fallthrough through func-like macro 2"
+#endif
+} // namespace cwg2390
 
 namespace cwg2394 { // cwg2394: 15
 

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


[clang] [clang] Make sure all C++ DR tests are running with `-pedantic-errors` (PR #94203)

2024-06-03 Thread Vlad Serebrennikov via cfe-commits

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


[clang] [clang] Move CWG2390 test into `cwg23xx.cpp` (PR #94206)

2024-06-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Vlad Serebrennikov (Endilll)


Changes

This patch refactors an existing test for 
[CWG2390](https://cplusplus.github.io/CWG/issues/2390.html) "Is the argument of 
`__has_cpp_attribute` macro-expanded?" to use `#error` instead of emitting a 
variable in IRGen and checking it via FileCheck. As a bonus, this makes it 
possible to move the test into `cwg23xx.cpp`.

---
Full diff: https://github.com/llvm/llvm-project/pull/94206.diff


2 Files Affected:

- (removed) clang/test/CXX/drs/cwg2390.cpp (-47) 
- (modified) clang/test/CXX/drs/cwg23xx.cpp (+36-1) 


``diff
diff --git a/clang/test/CXX/drs/cwg2390.cpp b/clang/test/CXX/drs/cwg2390.cpp
deleted file mode 100644
index 41bbd0d1c5499..0
--- a/clang/test/CXX/drs/cwg2390.cpp
+++ /dev/null
@@ -1,47 +0,0 @@
-// RUN: %clang_cc1 -E -P %s -o - | FileCheck %s
-
-// cwg2390: 14
-
-namespace PR48462 {
-// Test that macro expansion of the builtin argument works.
-#define C clang
-#define F fallthrough
-#define CF clang::fallthrough
-
-#if __has_cpp_attribute(F)
-int has_fallthrough;
-#endif
-// CHECK: int has_fallthrough;
-
-#if __has_cpp_attribute(C::F)
-int has_clang_fallthrough_1;
-#endif
-// CHECK: int has_clang_fallthrough_1;
-
-#if __has_cpp_attribute(clang::F)
-int has_clang_fallthrough_2;
-#endif
-// CHECK: int has_clang_fallthrough_2;
-
-#if __has_cpp_attribute(C::fallthrough)
-int has_clang_fallthrough_3;
-#endif
-// CHECK: int has_clang_fallthrough_3;
-
-#if __has_cpp_attribute(CF)
-int has_clang_fallthrough_4;
-#endif
-// CHECK: int has_clang_fallthrough_4;
-
-#define FUNCLIKE1(x) clang::x
-#if __has_cpp_attribute(FUNCLIKE1(fallthrough))
-int funclike_1;
-#endif
-// CHECK: int funclike_1;
-
-#define FUNCLIKE2(x) _Clang::x
-#if __has_cpp_attribute(FUNCLIKE2(fallthrough))
-int funclike_2;
-#endif
-// CHECK: int funclike_2;
-} // namespace PR48462
diff --git a/clang/test/CXX/drs/cwg23xx.cpp b/clang/test/CXX/drs/cwg23xx.cpp
index ae5ec3b878f59..e4a1e90941dbf 100644
--- a/clang/test/CXX/drs/cwg23xx.cpp
+++ b/clang/test/CXX/drs/cwg23xx.cpp
@@ -317,7 +317,42 @@ namespace cwg2387 { // cwg2387: 9
 #endif
 }
 
-// cwg2390 is in cwg2390.cpp
+namespace cwg2390 { // cwg2390: 14
+// Test that macro expansion of the builtin argument works.
+#define C clang
+#define F fallthrough
+#define CF clang::fallthrough
+
+#if !__has_cpp_attribute(F)
+#error "doesn't have fallthrough"
+#endif
+
+#if !__has_cpp_attribute(C::F)
+#error "doesn't have clang::fallthrough 1"
+#endif
+
+#if !__has_cpp_attribute(clang::F)
+#error "doesn't have clang::fallthrough 2"
+#endif
+
+#if !__has_cpp_attribute(C::fallthrough)
+#error "doesn't have clang::fallthrough 3"
+#endif
+
+#if !__has_cpp_attribute(CF)
+#error "doesn't have clang::fallthrough 4"
+#endif
+
+#define FUNCLIKE1(x) clang::x
+#if !__has_cpp_attribute(FUNCLIKE1(fallthrough))
+#error "doesn't have clang::fallthrough through func-like macro 1"
+#endif
+
+#define FUNCLIKE2(x) _Clang::x
+#if !__has_cpp_attribute(FUNCLIKE2(fallthrough))
+#error "doesn't have clang::fallthrough through func-like macro 2"
+#endif
+} // namespace cwg2390
 
 namespace cwg2394 { // cwg2394: 15
 

``




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


[clang] [llvm] Enable LLDB tests in pre-merge CI (PR #94208)

2024-06-03 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll created 
https://github.com/llvm/llvm-project/pull/94208

None

>From 5c757153a3f462d40663add6a9ae7caf42272913 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Mon, 3 Jun 2024 13:33:36 +0300
Subject: [PATCH 1/2] Enable LLDB tests in pre-submit CI

---
 .ci/generate-buildkite-pipeline-premerge | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/.ci/generate-buildkite-pipeline-premerge 
b/.ci/generate-buildkite-pipeline-premerge
index 033ab804b165e..a9972f235ff46 100755
--- a/.ci/generate-buildkite-pipeline-premerge
+++ b/.ci/generate-buildkite-pipeline-premerge
@@ -153,7 +153,6 @@ function exclude-linux() {
   for project in ${projects}; do
 case ${project} in
 cross-project-tests) ;; # tests failing
-lldb);; # tests failing
 openmp)  ;; # 
https://github.com/google/llvm-premerge-checks/issues/410
 *)
   echo "${project}"
@@ -170,7 +169,6 @@ function exclude-windows() {
 compiler-rt) ;; # tests taking too long
 openmp)  ;; # TODO: having trouble with the Perl installation
 libc);; # no Windows support
-lldb);; # tests failing
 bolt);; # tests are not supported yet
 *)
   echo "${project}"
@@ -213,7 +211,7 @@ function check-targets() {
   echo "check-unwind"
 ;;
 lldb)
-  echo "check-all" # TODO: check-lldb may not include all the LLDB tests?
+  echo "check-lldb" # TODO: check-lldb may not include all the LLDB tests?
 ;;
 pstl)
   echo "check-all"

>From 49e21f6b92623e280cfc49ac631b7481eb7a1229 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Mon, 3 Jun 2024 13:34:18 +0300
Subject: [PATCH 2/2] Trigger Clang CI

---
 clang/examples/PrintFunctionNames/PrintFunctionNames.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/examples/PrintFunctionNames/PrintFunctionNames.cpp 
b/clang/examples/PrintFunctionNames/PrintFunctionNames.cpp
index 6509a6440e12d..b2b785b87c25c 100644
--- a/clang/examples/PrintFunctionNames/PrintFunctionNames.cpp
+++ b/clang/examples/PrintFunctionNames/PrintFunctionNames.cpp
@@ -72,7 +72,7 @@ class PrintFunctionsConsumer : public ASTConsumer {
   *sema.LateParsedTemplateMap.find(FD)->second;
   sema.LateTemplateParser(sema.OpaqueParser, LPT);
   llvm::errs() << "late-parsed-decl: \"" << FD->getNameAsString() << 
"\"\n";
-}   
+}
   }
 };
 

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


[clang] [llvm] Enable LLDB tests in pre-merge CI (PR #94208)

2024-06-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Vlad Serebrennikov (Endilll)


Changes



---
Full diff: https://github.com/llvm/llvm-project/pull/94208.diff


2 Files Affected:

- (modified) .ci/generate-buildkite-pipeline-premerge (+1-3) 
- (modified) clang/examples/PrintFunctionNames/PrintFunctionNames.cpp (+1-1) 


``diff
diff --git a/.ci/generate-buildkite-pipeline-premerge 
b/.ci/generate-buildkite-pipeline-premerge
index 033ab804b165e..a9972f235ff46 100755
--- a/.ci/generate-buildkite-pipeline-premerge
+++ b/.ci/generate-buildkite-pipeline-premerge
@@ -153,7 +153,6 @@ function exclude-linux() {
   for project in ${projects}; do
 case ${project} in
 cross-project-tests) ;; # tests failing
-lldb);; # tests failing
 openmp)  ;; # 
https://github.com/google/llvm-premerge-checks/issues/410
 *)
   echo "${project}"
@@ -170,7 +169,6 @@ function exclude-windows() {
 compiler-rt) ;; # tests taking too long
 openmp)  ;; # TODO: having trouble with the Perl installation
 libc);; # no Windows support
-lldb);; # tests failing
 bolt);; # tests are not supported yet
 *)
   echo "${project}"
@@ -213,7 +211,7 @@ function check-targets() {
   echo "check-unwind"
 ;;
 lldb)
-  echo "check-all" # TODO: check-lldb may not include all the LLDB tests?
+  echo "check-lldb" # TODO: check-lldb may not include all the LLDB tests?
 ;;
 pstl)
   echo "check-all"
diff --git a/clang/examples/PrintFunctionNames/PrintFunctionNames.cpp 
b/clang/examples/PrintFunctionNames/PrintFunctionNames.cpp
index 6509a6440e12d..b2b785b87c25c 100644
--- a/clang/examples/PrintFunctionNames/PrintFunctionNames.cpp
+++ b/clang/examples/PrintFunctionNames/PrintFunctionNames.cpp
@@ -72,7 +72,7 @@ class PrintFunctionsConsumer : public ASTConsumer {
   *sema.LateParsedTemplateMap.find(FD)->second;
   sema.LateTemplateParser(sema.OpaqueParser, LPT);
   llvm::errs() << "late-parsed-decl: \"" << FD->getNameAsString() << 
"\"\n";
-}   
+}
   }
 };
 

``




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


[clang] [clang][analyzer] Move unix.BlockInCriticalSection out of alpha (PR #93815)

2024-06-03 Thread Endre Fülöp via cfe-commits

https://github.com/gamesh411 updated 
https://github.com/llvm/llvm-project/pull/93815

From 1da3d4dc3c74f1240e7d921c97b0c7eea2a53e33 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Endre=20F=C3=BCl=C3=B6p?= 
Date: Wed, 29 May 2024 00:38:07 +0200
Subject: [PATCH 1/2] [clang][analyzer] Move unix.BlockInCriticalSection out of
 alpha

After recent improvements, and testing on open source projects, the
checker is ready to move out of the alpha package.
---
 clang/docs/analyzer/checkers.rst  | 86 +--
 .../clang/StaticAnalyzer/Checkers/Checkers.td |  8 +-
 .../test/Analysis/analyzer-enabled-checkers.c |  1 +
 .../test/Analysis/block-in-critical-section.c |  2 +-
 .../Analysis/block-in-critical-section.cpp|  2 +-
 .../test/Analysis/block-in-critical-section.m |  2 +-
 ...c-library-functions-arg-enabled-checkers.c |  1 +
 clang/www/analyzer/alpha_checks.html  | 33 ---
 8 files changed, 52 insertions(+), 83 deletions(-)

diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst
index bbc31832b9c3c..99a31bbdce283 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -1235,6 +1235,49 @@ Check calls to various UNIX/Posix functions: ``open, 
pthread_once, calloc, mallo
 .. literalinclude:: checkers/unix_api_example.c
 :language: c
 
+.. _unix-BlockInCriticalSection:
+
+unix.BlockInCriticalSection (C)
+"
+Check for calls to blocking functions inside a critical section.
+Blocking functions detected by this checker: ``sleep, getc, fgets, read, 
recv``.
+Critical section handling functions modelled by this checker: ``lock, unlock, 
pthread_mutex_lock, pthread_mutex_trylock, pthread_mutex_unlock, mtx_lock, 
mtx_timedlock, mtx_trylock, mtx_unlock, lock_guard, unique_lock``.
+
+.. code-block:: c
+
+ void pthread_lock_example(pthread_mutex_t *m) {
+   pthread_mutex_lock(m); // note: entering critical section here
+   sleep(10); // warn: Call to blocking function 'sleep' inside of critical 
section
+   pthread_mutex_unlock(m);
+ }
+
+.. code-block:: cpp
+
+ void overlapping_critical_sections(mtx_t *m1, std::mutex &m2) {
+   std::lock_guard lg{m2}; // note: entering critical section here
+   mtx_lock(m1); // note: entering critical section here
+   sleep(10); // warn: Call to blocking function 'sleep' inside of critical 
section
+   mtx_unlock(m1);
+   sleep(10); // warn: Call to blocking function 'sleep' inside of critical 
section
+ // still inside of the critical section of the std::lock_guard
+ }
+
+**Limitations**
+
+* The ``trylock`` and ``timedlock`` versions of acquiring locks are currently 
assumed to always succeed.
+  This can lead to false positives.
+
+.. code-block:: c
+
+ void trylock_example(pthread_mutex_t *m) {
+   if (pthread_mutex_trylock(m) == 0) { // assume trylock always succeeds
+ sleep(10); // warn: Call to blocking function 'sleep' inside of critical 
section
+ pthread_mutex_unlock(m);
+   } else {
+ sleep(10); // false positive: Incorrect warning about blocking function 
inside critical section.
+   }
+ }
+
 .. _unix-Errno:
 
 unix.Errno (C)
@@ -3130,49 +3173,6 @@ For a more detailed description of configuration 
options, please see the
 alpha.unix
 ^^
 
-.. _alpha-unix-BlockInCriticalSection:
-
-alpha.unix.BlockInCriticalSection (C)
-"
-Check for calls to blocking functions inside a critical section.
-Blocking functions detected by this checker: ``sleep, getc, fgets, read, 
recv``.
-Critical section handling functions modelled by this checker: ``lock, unlock, 
pthread_mutex_lock, pthread_mutex_trylock, pthread_mutex_unlock, mtx_lock, 
mtx_timedlock, mtx_trylock, mtx_unlock, lock_guard, unique_lock``.
-
-.. code-block:: c
-
- void pthread_lock_example(pthread_mutex_t *m) {
-   pthread_mutex_lock(m); // note: entering critical section here
-   sleep(10); // warn: Call to blocking function 'sleep' inside of critical 
section
-   pthread_mutex_unlock(m);
- }
-
-.. code-block:: cpp
-
- void overlapping_critical_sections(mtx_t *m1, std::mutex &m2) {
-   std::lock_guard lg{m2}; // note: entering critical section here
-   mtx_lock(m1); // note: entering critical section here
-   sleep(10); // warn: Call to blocking function 'sleep' inside of critical 
section
-   mtx_unlock(m1);
-   sleep(10); // warn: Call to blocking function 'sleep' inside of critical 
section
- // still inside of the critical section of the std::lock_guard
- }
-
-**Limitations**
-
-* The ``trylock`` and ``timedlock`` versions of acquiring locks are currently 
assumed to always succeed.
-  This can lead to false positives.
-
-.. code-block:: c
-
- void trylock_example(pthread_mutex_t *m) {
-   if (pthread_mutex_trylock(m) == 0) { // assume trylock always succeeds
- sleep(10); // warn: Call to blocking function 'sleep' inside of critical 
section
- pthread_mutex_unlock(m);
-   } else {
- sleep(10); // false positive: I

[clang] [clang][analyzer] Improved PointerSubChecker (PR #93676)

2024-06-03 Thread Donát Nagy via cfe-commits

NagyDonat wrote:

> With the current version I have the following observations:
> 
> * There is a warning for `(&x + 1) - &x` and `(&x - 1) - &x`. Should this 
> be fixed?

The expression `(&x + 1) - &x` is valid and should not produce a warning. It 
could appear e.g. in code that's structured like
```
void log_observations(double *begin, double *end, /*...*/) {
  log_observation_count(end - begin);
  // also log the actual observations
}
void do_observations(/*...*/) {
  double array[1024], *p = array;
  //...
  while (can_observe()) {
*p++ = /* ... */
  }
  log_observations(array, p);
}
void do_single_observation(/*...*/) {
  if (!can_observe())
return;
  double result = /* ... */
  // ...
  log_observations(&result, &result + 1);
}
```

On the other hand `(&x - 1) - &x` is not standard-compliant, because the 
standard guarantees an "after-the-end" pointer (which is valid in calculations 
but must not be dereferenced) but it doesn't accept a "before-the-begin" 
pointer.

> * The code `(int *)((char *)(&a[4]) + sizeof(int)) - &a[4]` produces no 
> warning but `(int *)((char *)(&a[4]) + 1) - &a[4]` produces warning.

That's very nice, even a slightly less accurate solution would be acceptable.

> For 2-dimensional arrays there is warning for all of these cases (lines 44-47 
> in the test file). Is this possible to fix (to get warning in all cases), or 
> no warning is needed here?

I'd say that the current behavior (warning on all of 44-47) is OK here -- this 
is very unusual trickery and deserves a highlight. However I could also accept 
a situation where there was no warning for these complex multidimensional cases.

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


[clang] [serialization] no transitive decl change (PR #92083)

2024-06-03 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

I'll close it as there are some crashes.

---

The crash log:

```
** TEST 'Clang :: Modules/redecl-ivars.m' FAILED 
Exit Code: 1

Command Output (stderr):
--
RUN: at line 2: rm -rf 
/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/tools/clang/test/Modules/Output/redecl-ivars.m.tmp
+ rm -rf 
/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/tools/clang/test/Modules/Output/redecl-ivars.m.tmp
RUN: at line 3: split-file 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/Modules/redecl-ivars.m
 
/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/tools/clang/test/Modules/Output/redecl-ivars.m.tmp
+ split-file 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/Modules/redecl-ivars.m
 
/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/tools/clang/test/Modules/Output/redecl-ivars.m.tmp
RUN: at line 4: 
/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/clang -cc1 
-internal-isystem 
/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/lib/clang/19/include 
-nostdsysteminc -fsyntax-only -fobjc-runtime=macosx-10.9 -verify 
-I/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/tools/clang/test/Modules/Output/redecl-ivars.m.tmp/include
 
/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/tools/clang/test/Modules/Output/redecl-ivars.m.tmp/test-mismatch-in-extension.m
+ /b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/clang -cc1 
-internal-isystem 
/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/lib/clang/19/include 
-nostdsysteminc -fsyntax-only -fobjc-runtime=macosx-10.9 -verify 
-I/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/tools/clang/test/Modules/Output/redecl-ivars.m.tmp/include
 
/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/tools/clang/test/Modules/Output/redecl-ivars.m.tmp/test-mismatch-in-extension.m
RUN: at line 5: 
/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/clang -cc1 
-internal-isystem 
/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/lib/clang/19/include 
-nostdsysteminc -fsyntax-only -fobjc-runtime=macosx-10.9 -verify 
-I/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/tools/clang/test/Modules/Output/redecl-ivars.m.tmp/include
 
/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/tools/clang/test/Modules/Output/redecl-ivars.m.tmp/test-mismatch-in-extension.m
 -fmodules -fimplicit-module-maps 
-fmodules-cache-path=/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/tools/clang/test/Modules/Output/redecl-ivars.m.tmp/modules.cache
+ /b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/clang -cc1 
-internal-isystem 
/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/lib/clang/19/include 
-nostdsysteminc -fsyntax-only -fobjc-runtime=macosx-10.9 -verify 
-I/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/tools/clang/test/Modules/Output/redecl-ivars.m.tmp/include
 
/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/tools/clang/test/Modules/Output/redecl-ivars.m.tmp/test-mismatch-in-extension.m
 -fmodules -fimplicit-module-maps 
-fmodules-cache-path=/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/tools/clang/test/Modules/Output/redecl-ivars.m.tmp/modules.cache
/b/sanitizer-x86_64-linux-fast/build/libcxx_build_asan_ubsan/include/c++/v1/__algorithm/lower_bound.h:39:53:
 runtime error: reference binding to misaligned address 0x52945c44 for type 
'const clang::serialization::ObjCCategoriesInfo', which requires 8 byte 
alignment
0x52945c44: note: pointer points here
  00 00 00 00 02 00 00 00  01 00 00 00 02 00 00 00  00 00 00 00 c3 0d 88 60  0a 
a8 81 10 03 20 08 00
  ^ 
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior 
/b/sanitizer-x86_64-linux-fast/build/libcxx_build_asan_ubsan/include/c++/v1/__algorithm/lower_bound.h:39:53
 

--

It looks like misaligned access too. I'll try to fix it.

(It is somewhat hurting that we can't find them on the trunk.)
```

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


[clang] 6b30180 - Revert "[serialization] no transitive decl change (#92083)"

2024-06-03 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2024-06-03T18:49:18+08:00
New Revision: 6b30180b663e1fe4de32046398581a374c8a54f2

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

LOG: Revert "[serialization] no transitive decl change (#92083)"

This reverts commit ccb73e882b2d727877cfda42a14a6979cfd31f04.

It looks like there are some bots complaining about the patch.
See the post commit comment in
https://github.com/llvm/llvm-project/pull/92083 to track it.

Added: 


Modified: 
clang/include/clang/AST/DeclBase.h
clang/include/clang/AST/DeclID.h
clang/include/clang/Serialization/ASTBitCodes.h
clang/include/clang/Serialization/ASTReader.h
clang/include/clang/Serialization/ModuleFile.h
clang/include/clang/Serialization/ModuleManager.h
clang/lib/AST/DeclBase.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTReaderDecl.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/lib/Serialization/ModuleFile.cpp

Removed: 
clang/test/Modules/no-transitive-decls-change.cppm



diff  --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index 4bdf27aa99405..e43e812cd9455 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -701,7 +701,10 @@ class alignas(8) Decl {
 
   /// Set the owning module ID.  This may only be called for
   /// deserialized Decls.
-  void setOwningModuleID(unsigned ID);
+  void setOwningModuleID(unsigned ID) {
+assert(isFromASTFile() && "Only works on a deserialized declaration");
+*((unsigned*)this - 2) = ID;
+  }
 
 public:
   /// Determine the availability of the given declaration.
@@ -774,11 +777,19 @@ class alignas(8) Decl {
 
   /// Retrieve the global declaration ID associated with this
   /// declaration, which specifies where this Decl was loaded from.
-  GlobalDeclID getGlobalID() const;
+  GlobalDeclID getGlobalID() const {
+if (isFromASTFile())
+  return (*((const GlobalDeclID *)this - 1));
+return GlobalDeclID();
+  }
 
   /// Retrieve the global ID of the module that owns this particular
   /// declaration.
-  unsigned getOwningModuleID() const;
+  unsigned getOwningModuleID() const {
+if (isFromASTFile())
+  return *((const unsigned*)this - 2);
+return 0;
+  }
 
 private:
   Module *getOwningModuleSlow() const;

diff  --git a/clang/include/clang/AST/DeclID.h 
b/clang/include/clang/AST/DeclID.h
index 32d2ed41a374a..614ba06b63860 100644
--- a/clang/include/clang/AST/DeclID.h
+++ b/clang/include/clang/AST/DeclID.h
@@ -19,8 +19,6 @@
 #include "llvm/ADT/DenseMapInfo.h"
 #include "llvm/ADT/iterator.h"
 
-#include 
-
 namespace clang {
 
 /// Predefined declaration IDs.
@@ -109,16 +107,12 @@ class DeclIDBase {
   ///
   /// DeclID should only be used directly in serialization. All other users
   /// should use LocalDeclID or GlobalDeclID.
-  using DeclID = uint64_t;
+  using DeclID = uint32_t;
 
 protected:
   DeclIDBase() : ID(PREDEF_DECL_NULL_ID) {}
   explicit DeclIDBase(DeclID ID) : ID(ID) {}
 
-  explicit DeclIDBase(unsigned LocalID, unsigned ModuleFileIndex) {
-ID = (DeclID)LocalID | ((DeclID)ModuleFileIndex << 32);
-  }
-
 public:
   DeclID get() const { return ID; }
 
@@ -130,10 +124,6 @@ class DeclIDBase {
 
   bool isInvalid() const { return ID == PREDEF_DECL_NULL_ID; }
 
-  unsigned getModuleFileIndex() const { return ID >> 32; }
-
-  unsigned getLocalDeclIndex() const;
-
   friend bool operator==(const DeclIDBase &LHS, const DeclIDBase &RHS) {
 return LHS.ID == RHS.ID;
   }
@@ -166,9 +156,6 @@ class LocalDeclID : public DeclIDBase {
   LocalDeclID(PredefinedDeclIDs ID) : Base(ID) {}
   explicit LocalDeclID(DeclID ID) : Base(ID) {}
 
-  explicit LocalDeclID(unsigned LocalID, unsigned ModuleFileIndex)
-  : Base(LocalID, ModuleFileIndex) {}
-
   LocalDeclID &operator++() {
 ++ID;
 return *this;
@@ -188,9 +175,6 @@ class GlobalDeclID : public DeclIDBase {
   GlobalDeclID() : Base() {}
   explicit GlobalDeclID(DeclID ID) : Base(ID) {}
 
-  explicit GlobalDeclID(unsigned LocalID, unsigned ModuleFileIndex)
-  : Base(LocalID, ModuleFileIndex) {}
-
   // For DeclIDIterator to be able to convert a GlobalDeclID
   // to a LocalDeclID.
   explicit operator LocalDeclID() const { return LocalDeclID(this->ID); }

diff  --git a/clang/include/clang/Serialization/ASTBitCodes.h 
b/clang/include/clang/Serialization/ASTBitCodes.h
index 9e4b21baa7d20..fe1bd47348be1 100644
--- a/clang/include/clang/Serialization/ASTBitCodes.h
+++ b/clang/include/clang/Serialization/ASTBitCodes.h
@@ -255,12 +255,6 @@ class DeclOffset {
   }
 };
 
-// The unaligned decl ID used in the Blobs of bistreams.
-using unaligned_decl_id_t =
-llvm::support::detail::packed_endian_specific_integral<
-serialization::DeclID, llvm::endianness

[clang] [clang][analyzer] Move unix.BlockInCriticalSection out of alpha (PR #93815)

2024-06-03 Thread Balazs Benics via cfe-commits
Endre =?utf-8?q?F=C3=BCl=C3=B6p?= 
Message-ID:
In-Reply-To: 


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


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


[clang] [serialization] no transitive decl change (PR #92083)

2024-06-03 Thread David Spickett via cfe-commits

DavidSpickett wrote:

This also broke an lldb test: 
https://lab.llvm.org/buildbot/#/builders/96/builds/58449

`lldb-test: ../llvm-project/clang/lib/AST/DeclBase.cpp:132: void 
clang::Decl::setOwningModuleID(unsigned int): Assertion `!((*IDAddress) >> 48) 
&& "We should only set the module ID once"' failed.`

I can't say if right now whether lldb is being too strict or this is a real 
problem. Could be the result of the same thing UBSAN found.

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


[clang] [serialization] no transitive decl change (PR #92083)

2024-06-03 Thread Mitch Phillips via cfe-commits

hctim wrote:

Hi from the sanitizer buildbot mainter, thanks for the fast revert! For full 
reproduction, you can use 
https://github.com/google/sanitizers/wiki/SanitizerBotReproduceBuild and 
`buildbot_fast.sh`. But, you can reproduce it quicker by using 
`-DCMAKE_C_FLAGS="-fsanitize=undefined"  
-DCMAKE_CXX_FLAGS="-fsanitize=undefined" -DLLVM_USE_SANITIZER=Undefined` in 
your cmake (then `{ninja,make} check-clang`).


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


[clang] [clang] Move CWG2390 test into `cwg23xx.cpp` (PR #94206)

2024-06-03 Thread via cfe-commits

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


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


[clang] [llvm] Enable LLDB tests in pre-merge CI (PR #94208)

2024-06-03 Thread Michael Buch via cfe-commits

Michael137 wrote:

Worth a shot i guess. Though it could be somewhat disruptive if we do in fact 
have flaky tests. I don't think we need to run *all* tests. Should we just run 
the tests for the LLDB C++ language plugin (i.e., the part of LLDB that invokes 
Clang and the JIT). And then we could expand the set of tests from there?

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


[clang] [serialization] no transitive decl change (PR #92083)

2024-06-03 Thread Michael Buch via cfe-commits

Michael137 wrote:

I.e., also broke the macOS LLDB buildbots: 
https://green.lab.llvm.org/job/llvm.org/view/LLDB/job/lldb-cmake/2637/execution/node/97/log/

```
Assertion failed: (!((*IDAddress) >> 48) && "We should only set the module ID 
once"), function setOwningModuleID, file DeclBase.cpp, line 132.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and 
include the crash backtrace.
```

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


[clang] [llvm] Enable LLDB tests in pre-merge CI (PR #94208)

2024-06-03 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

> Should we just run the tests for the LLDB C++ language plugin (i.e., the part 
> of LLDB that invokes Clang and the JIT). And then we could expand the set of 
> tests from there later?

In the bash script that currently handles this, "targets that we need to check 
if lldb is tested" is expressible, but "targets that we need to check if lldb 
is tested on clang changes" is not, and I consider it already too complicated 
for a bash script.

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


[clang] [llvm] Enable LLDB tests in pre-merge CI (PR #94208)

2024-06-03 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

First Windows CI results: LLDB unit tests do not even build.
```
FAILED: 
tools/lldb/unittests/Process/gdb-remote/CMakeFiles/ProcessGdbRemoteTests.dir/GDBRemoteCommunicationClientTest.cpp.obj
 
sccache C:\BuildTools\VC\Tools\MSVC\14.29.30133\bin\Hostx64\x64\cl.exe  /nologo 
/TP -DBUILD_EXAMPLES -DGTEST_HAS_RTTI=0 -DUNICODE -D_CRT_NONSTDC_NO_DEPRECATE 
-D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS 
-D_ENABLE_EXTENDED_ALIGNED_STORAGE -D_GLIBCXX_ASSERTIONS -D_HAS_EXCEPTIONS=0 
-D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -D_UNICODE 
-D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-Itools\lldb\unittests\Process\gdb-remote 
-IC:\ws\src\lldb\unittests\Process\gdb-remote -IC:\ws\src\lldb\include 
-Itools\lldb\include -Iinclude -IC:\ws\src\llvm\include 
-IC:\ws\src\llvm\..\clang\include -Itools\lldb\..\clang\include 
-IC:\ws\src\lldb\source -IC:\ws\src\lldb\unittests 
-IC:\ws\src\third-party\unittest\googletest\include 
-IC:\ws\src\third-party\unittest\googlemock\include /DWIN32 /D_WINDOWS   
/Zc:inline /Zc:preprocessor /Zc:__cplusplus /Oi /bigobj /permissive- /W4 
-wd4141 -wd4146 -wd4244 -wd4267 -wd4291 -wd4351 -wd4456 -wd4457 -wd4458 -wd4459 
-wd4503 -wd4624 -wd4722 -wd4100 -wd4127 -wd4512 -wd4505 -wd4610 -wd4510 -wd4702 
-wd4245 -wd4706 -wd4310 -wd4701 -wd4703 -wd4389 -wd4611 -wd4805 -wd4204 -wd4577 
-wd4091 -wd4592 -wd4319 -wd4709 -wd5105 -wd4324 -w14062 -we4238 /Gw /O2 /Ob2  
-MD   -wd4018 -wd4068 -wd4150 -wd4201 -wd4251 -wd4521 -wd4530 -wd4589  /EHs-c- 
/GR- -UNDEBUG -std:c++17 /showIncludes 
/Fotools\lldb\unittests\Process\gdb-remote\CMakeFiles\ProcessGdbRemoteTests.dir\GDBRemoteCommunicationClientTest.cpp.obj
 
/Fdtools\lldb\unittests\Process\gdb-remote\CMakeFiles\ProcessGdbRemoteTests.dir\
 /FS -c 
C:\ws\src\lldb\unittests\Process\gdb-remote\GDBRemoteCommunicationClientTest.cpp
C:\BuildTools\VC\Tools\MSVC\14.29.30133\include\future(196): error C2512: 
'llvm::ErrorOr': no appropriate default constructor 
available
C:\ws\src\llvm\include\llvm/Support/FileSystem.h(432): note: see declaration of 
'llvm::ErrorOr'
C:\BuildTools\VC\Tools\MSVC\14.29.30133\include\future(193): note: while 
compiling class template member function 
'std::_Associated_state<_Ty>::_Associated_state(std::_Deleter_base<_Ty> *)'
with
[
_Ty=llvm::ErrorOr
]
C:\BuildTools\VC\Tools\MSVC\14.29.30133\include\future(464): note: see 
reference to function template instantiation 
'std::_Associated_state<_Ty>::_Associated_state(std::_Deleter_base<_Ty> *)' 
being compiled
with
[
_Ty=llvm::ErrorOr
]
C:\BuildTools\VC\Tools\MSVC\14.29.30133\include\future(774): note: see 
reference to class template instantiation 'std::_Associated_state<_Ty>' being 
compiled
with
[
_Ty=llvm::ErrorOr
]
C:\BuildTools\VC\Tools\MSVC\14.29.30133\include\future(769): note: while 
compiling class template member function '_Ty 
&std::_State_manager<_Ty>::_Get_value(void) const'
with
[
_Ty=llvm::ErrorOr
]
C:\BuildTools\VC\Tools\MSVC\14.29.30133\include\future(884): note: see 
reference to function template instantiation '_Ty 
&std::_State_manager<_Ty>::_Get_value(void) const' being compiled
with
[
_Ty=llvm::ErrorOr
]
C:\BuildTools\VC\Tools\MSVC\14.29.30133\include\future(860): note: see 
reference to class template instantiation 'std::_State_manager<_Ty>' being 
compiled
with
[
_Ty=llvm::ErrorOr
]
C:\ws\src\lldb\unittests\Process\gdb-remote\GDBRemoteCommunicationClientTest.cpp(598):
 note: see reference to class template instantiation 
'std::future>' being compiled
```

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


[clang] 9a7bd8a - remove goma support from clang (#93942)

2024-06-03 Thread via cfe-commits

Author: Takuto Ikuta
Date: 2024-06-03T07:30:14-04:00
New Revision: 9a7bd8a60f03595be5d42315790df6d409f81091

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

LOG: remove goma support from clang (#93942)

goma is deprecated and not maintained anymore.

https://chromium.googlesource.com/infra/goma/client/

Added: 


Modified: 
clang/lib/Tooling/JSONCompilationDatabase.cpp
clang/unittests/Tooling/CompilationDatabaseTest.cpp

Removed: 




diff  --git a/clang/lib/Tooling/JSONCompilationDatabase.cpp 
b/clang/lib/Tooling/JSONCompilationDatabase.cpp
index a77686996879f..5ecba5dfece3d 100644
--- a/clang/lib/Tooling/JSONCompilationDatabase.cpp
+++ b/clang/lib/Tooling/JSONCompilationDatabase.cpp
@@ -260,7 +260,7 @@ static llvm::StringRef 
stripExecutableExtension(llvm::StringRef Name) {
   return Name;
 }
 
-// There are compiler-wrappers (ccache, distcc, gomacc) that take the "real"
+// There are compiler-wrappers (ccache, distcc) that take the "real"
 // compiler as an argument, e.g. distcc gcc -O3 foo.c.
 // These end up in compile_commands.json when people set CC="distcc gcc".
 // Clang's driver doesn't understand this, so we need to unwrap.
@@ -269,8 +269,7 @@ static bool unwrapCommand(std::vector &Args) {
 return false;
   StringRef Wrapper =
   stripExecutableExtension(llvm::sys::path::filename(Args.front()));
-  if (Wrapper == "distcc" || Wrapper == "gomacc" || Wrapper == "ccache" ||
-  Wrapper == "sccache") {
+  if (Wrapper == "distcc" || Wrapper == "ccache" || Wrapper == "sccache") {
 // Most of these wrappers support being invoked 3 ways:
 // `distcc g++ file.c` This is the mode we're trying to match.
 // We need to drop `distcc`.

diff  --git a/clang/unittests/Tooling/CompilationDatabaseTest.cpp 
b/clang/unittests/Tooling/CompilationDatabaseTest.cpp
index 45062cf7c16f6..2032b13726c45 100644
--- a/clang/unittests/Tooling/CompilationDatabaseTest.cpp
+++ b/clang/unittests/Tooling/CompilationDatabaseTest.cpp
@@ -402,7 +402,6 @@ TEST(findCompileArgsInJsonDatabase, FindsEntry) {
 TEST(findCompileArgsInJsonDatabase, ParsesCompilerWrappers) {
   std::vector> Cases = {
   {"distcc gcc foo.c", "gcc foo.c"},
-  {"gomacc clang++ foo.c", "clang++ foo.c"},
   {"sccache clang++ foo.c", "clang++ foo.c"},
   {"ccache gcc foo.c", "gcc foo.c"},
   {"ccache.exe gcc foo.c", "gcc foo.c"},



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


[clang] remove goma support from clang (PR #93942)

2024-06-03 Thread Aaron Ballman via cfe-commits

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


[clang] [Clang] Implement resolution for CWG1835 (PR #92957)

2024-06-03 Thread Krystian Stasiowski via cfe-commits

sdkrystian wrote:

This does seem to cause an error in libstdc++:

```
include/c++/11/bits/shared_ptr.h:365:10: error: use 'template' keyword to treat 
'__shared_ptr' as a dependent template name

this->__shared_ptr<_Tp>::operator=(__r);
  ^
```
Since `this` is dependent (it's of type `shared_ptr*`) and `shared_ptr` 
inherits from `__shared_ptr` (i.e. it has a dependent base), `template` is 
required to treat `<` as the start of a template argument list. I think we can 
detect these cases and diagnose this as a language extension. 


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


[clang] [llvm] Enable LLDB tests in pre-merge CI (PR #94208)

2024-06-03 Thread Michael Buch via cfe-commits

Michael137 wrote:

> > Should we just run the tests for the LLDB C++ language plugin (i.e., the 
> > part of LLDB that invokes Clang and the JIT). And then we could expand the 
> > set of tests from there later?
> 
> In the bash script that currently handles this, "targets that we need to 
> check if lldb is tested" is expressible, but "targets that we need to check 
> if lldb is tested on clang changes" is not, and I consider it already too 
> complicated for a bash script.

Ah i see, could you point me to that part of the bash script?

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


[clang] [analyzer] Refine invalidation caused by `fread` (PR #93408)

2024-06-03 Thread Balazs Benics via cfe-commits


@@ -937,8 +990,21 @@ void StreamChecker::evalFreadFwrite(const FnDescription 
*Desc,
 
   // At read, invalidate the buffer in any case of error or success,
   // except if EOF was already present.
-  if (IsFread && !E.isStreamEof())
-State = escapeArgs(State, C, Call, {0});
+  if (IsFread && !E.isStreamEof()) {
+// Try to invalidate the individual elements.
+if (const auto *BufferFirstElem =
+dyn_cast_or_null(Call.getArgSVal(0).getAsRegion())) 
{

steakhal wrote:

In case `fread` reads to the beginning of a buffer, we won't have an 
`ElementRegion`, thus the heuristic for eagerly binding the invalidated 
elements won't trigger. This is unfortunate, but you can think of this as we 
keep the previous behavior.
To circumvent this, I'd need to know the type for for the pointee.
This would imply that I should special-case `TypedValueRegion` and 
`SymbolicRegion`.

I'll think about it.

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


[clang] [llvm] Enable LLDB tests in pre-merge CI (PR #94208)

2024-06-03 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

@Michael137 This is for Linux. Windows works the same way just below those 
lines: 
https://github.com/llvm/llvm-project/blob/9a7bd8a60f03595be5d42315790df6d409f81091/.ci/generate-buildkite-pipeline-premerge#L253-L255

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


[clang] [Clang][Sema] Tweak tryCaptureVariable for unevaluated lambdas (PR #93206)

2024-06-03 Thread via cfe-commits

https://github.com/cor3ntin commented:

I think it makes sense.
I kinda wish there would be a more generic way to skip over requires 
expressions but I also can't think of other contexts we'd want to skip over, so 
this looks fine. 

Thanks for fixing a large number of issues

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


[clang] [Clang][Sema] Tweak tryCaptureVariable for unevaluated lambdas (PR #93206)

2024-06-03 Thread via cfe-commits

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


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


[clang] [analyzer] Refine invalidation caused by `fread` (PR #93408)

2024-06-03 Thread Balazs Benics via cfe-commits


@@ -717,18 +717,71 @@ const ExplodedNode 
*StreamChecker::getAcquisitionSite(const ExplodedNode *N,
   return nullptr;
 }
 
+/// Invalidate only the requested elements instead of the whole buffer.
+/// This is basically a refinement of the more generic 'escapeArgs' or
+/// the plain old 'invalidateRegions'.
+/// This only works if the \p StartIndex and \p Count are concrete or
+/// perfectly-constrained.
+static ProgramStateRef
+escapeByStartIndexAndCount(ProgramStateRef State, CheckerContext &C,
+   const CallEvent &Call, const MemRegion *Buffer,
+   QualType ElemType, SVal StartIndex, SVal Count) {
+  if (!llvm::isa_and_nonnull(Buffer))
+return State;
+
+  auto UnboxAsInt = [&C, &State](SVal V) -> std::optional {
+auto &SVB = C.getSValBuilder();
+if (const llvm::APSInt *Int = SVB.getKnownValue(State, V))
+  return Int->tryExtValue();
+return std::nullopt;
+  };
+
+  auto StartIndexVal = UnboxAsInt(StartIndex);
+  auto CountVal = UnboxAsInt(Count);
+
+  // FIXME: Maybe we could make this more generic, and expose this by the
+  // 'invalidateRegions' API. After doing so, it might make sense to make this
+  // limit configurable.
+  constexpr int MaxInvalidatedElementsLimit = 64;
+  if (!StartIndexVal || !CountVal || *CountVal > MaxInvalidatedElementsLimit) {
+return State->invalidateRegions({loc::MemRegionVal{Buffer}},
+Call.getOriginExpr(), C.blockCount(),
+C.getLocationContext(),
+/*CausesPointerEscape=*/false);
+  }
+
+  constexpr auto DoNotInvalidateSuperRegion =
+  RegionAndSymbolInvalidationTraits::InvalidationKinds::
+  TK_DoNotInvalidateSuperRegion;
+
+  auto &RegionManager = Buffer->getMemRegionManager();
+  SmallVector EscapingVals;
+  EscapingVals.reserve(*CountVal);
+
+  RegionAndSymbolInvalidationTraits ITraits;
+  for (auto Idx : llvm::seq(*StartIndexVal, *StartIndexVal + *CountVal)) {

steakhal wrote:

Yes, this is a problem.
To properly invalidate element-wise, I must bind the correctly typed conjured 
symbols so that subsequent lookups in the store would hit the entry.
Consequently, I can't consider the buffer as a char array and invalidate each 
chars in the range.
I must use `ElementRegions`, thus I need properly aligned item-wise iteration 
and invalidation.

So, I could try to convert the element size and item count into a start byte 
offset and length in bytes. After this I could check if the start bytes offset 
would land on an item boundary and if the length would cover a whole element 
object.

This way we could cover the case like:
```
int buffer[100]; // assuming 4 byte ints.
fread(buffer + 1, 2, 10, file); // Reads 20 bytes of data, which is dividable 
by 4, thus we can think of the 'buffer[1:6]' elements as individually 
invalidated.
``` 

WDYT?

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


[clang] [analyzer] Refine invalidation caused by `fread` (PR #93408)

2024-06-03 Thread Balazs Benics via cfe-commits

https://github.com/steakhal updated 
https://github.com/llvm/llvm-project/pull/93408

>From f9e841ddaa865d529c806b2d115d5ddbc7109243 Mon Sep 17 00:00:00 2001
From: Balazs Benics 
Date: Sun, 26 May 2024 11:40:01 +0200
Subject: [PATCH 1/6] [analyzer] Refine invalidation caused by `fread`

This change enables more accurate modeling of the write effects of `fread`.
In particular, instead of invalidating the whole buffer, in a best-effort
basis, we would try to invalidate the actually accesses elements of the buffer.
This preserves the previous value of the buffer of the unaffected slots.
As a result, diagnose more uninitialized buffer uses for example.

Currently, this refined invalidation only triggers for `fread` if and
only if the `count` parameter and the buffer pointer's index component
are concrete or perfectly-constrained symbols.
Additionally, if the `fread` would read more than 64 elements, the whole
buffer is invalidated as before. This is to have safeguards against
performance issues.

Refer to the comments of the assertions in the following example to see
the changes in the diagnostics:

```c++
void demo() {
  FILE *fp = fopen("/home/test", "rb+");
  if (!fp) return;
  int buffer[10]; // uninitialized
  int read_items = fread(buffer+1, sizeof(int), 5, fp);
  if (5 == read_items) {
int v1 = buffer[1]; // Unknown value but not garbage.
clang_analyzer_isTainted(v1); // expected-warning {{YES}} <-- Would be "NO" 
without this patch.
clang_analyzer_dump(v1); // expected-warning {{conj_}} <-- Not a "derived" 
symbol, so it's directly invalidated now.
int v0 = buffer[0]; // expected-warning {{Assigned value is garbage or 
undefined}} <-- Had no report here before.
(void)(v1 + v0);
  } else {
// If 'fread' had an error.
int v0 = buffer[0]; // expected-warning {{Assigned value is garbage or 
undefined}} <-- Had no report here before.
(void)v0;
  }
  fclose(fp);
}
```

[CPP-3247](https://sonarsource.atlassian.net/browse/CPP-3247)

Patch by Marco Borgeaud (marco-antognini-sonarsource)
---
 .../StaticAnalyzer/Checkers/StreamChecker.cpp |  88 -
 clang/test/Analysis/fread.cpp | 328 ++
 2 files changed, 405 insertions(+), 11 deletions(-)
 create mode 100644 clang/test/Analysis/fread.cpp

diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index d4e020f7a72a0..7b42c4f72b322 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -717,18 +717,71 @@ const ExplodedNode 
*StreamChecker::getAcquisitionSite(const ExplodedNode *N,
   return nullptr;
 }
 
+/// Invalidate only the requested elements instead of the whole buffer.
+/// This is basically a refinement of the more generic 'escapeArgs' or
+/// the plain old 'invalidateRegions'.
+/// This only works if the \p StartIndex and \p Count are concrete or
+/// perfectly-constrained.
+static ProgramStateRef
+escapeByStartIndexAndCount(ProgramStateRef State, CheckerContext &C,
+   const CallEvent &Call, const MemRegion *Buffer,
+   QualType ElemType, SVal StartIndex, SVal Count) {
+  if (!llvm::isa_and_nonnull(Buffer))
+return State;
+
+  auto UnboxAsInt = [&C, &State](SVal V) -> std::optional {
+auto &SVB = C.getSValBuilder();
+if (const llvm::APSInt *Int = SVB.getKnownValue(State, V))
+  return Int->tryExtValue();
+return std::nullopt;
+  };
+
+  auto StartIndexVal = UnboxAsInt(StartIndex);
+  auto CountVal = UnboxAsInt(Count);
+
+  // FIXME: Maybe we could make this more generic, and expose this by the
+  // 'invalidateRegions' API. After doing so, it might make sense to make this
+  // limit configurable.
+  constexpr int MaxInvalidatedElementsLimit = 64;
+  if (!StartIndexVal || !CountVal || *CountVal > MaxInvalidatedElementsLimit) {
+return State->invalidateRegions({loc::MemRegionVal{Buffer}},
+Call.getOriginExpr(), C.blockCount(),
+C.getLocationContext(),
+/*CausesPointerEscape=*/false);
+  }
+
+  constexpr auto DoNotInvalidateSuperRegion =
+  RegionAndSymbolInvalidationTraits::InvalidationKinds::
+  TK_DoNotInvalidateSuperRegion;
+
+  auto &RegionManager = Buffer->getMemRegionManager();
+  SmallVector EscapingVals;
+  EscapingVals.reserve(*CountVal);
+
+  RegionAndSymbolInvalidationTraits ITraits;
+  for (auto Idx : llvm::seq(*StartIndexVal, *StartIndexVal + *CountVal)) {
+NonLoc Index = C.getSValBuilder().makeArrayIndex(Idx);
+const auto *Element = RegionManager.getElementRegion(
+ElemType, Index, cast(Buffer), C.getASTContext());
+EscapingVals.push_back(loc::MemRegionVal(Element));
+ITraits.setTrait(Element, DoNotInvalidateSuperRegion);
+  }
+  return State->invalidateRegions(EscapingVals, Call.getOriginExpr(),
+  C.

[clang] [analyzer] New optin.taint.TaintAlloc checker for catching unbounded memory allocation calls (PR #92420)

2024-06-03 Thread Daniel Krupp via cfe-commits


@@ -1730,6 +1721,21 @@ def UnixAPIPortabilityChecker : Checker<"UnixAPI">,
 
 } // end optin.portability
 
+
+//===--===//
+// Taint checkers.
+//===--===//
+
+let ParentPackage = TaintOptIn in {
+
+def TaintMallocChecker: Checker<"TaintMalloc">,
+  HelpText<"Check for memory allocations, where the size parameter "
+   "might be a tainted (attacker controlled) value.">,
+  Dependencies<[DynamicMemoryModeling]>,

dkrupp wrote:

I added the GenerictaintChecker as a dependency too. I think it makes sense to 
add it now so that we dont forget it later.

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


[clang] [analyzer] Refine invalidation caused by `fread` (PR #93408)

2024-06-03 Thread Balazs Benics via cfe-commits

steakhal wrote:

Fixed most NFC typos and suggestions.
Let's continue the discussion.

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


[clang] [ExtractAPI,test] fix filecheck annotation (PR #92231)

2024-06-03 Thread via cfe-commits

https://github.com/klensy updated 
https://github.com/llvm/llvm-project/pull/92231

>From 910a674252a7f0968db46c9ed09879ae58e90d3b Mon Sep 17 00:00:00 2001
From: klensy 
Date: Wed, 15 May 2024 12:14:56 +0300
Subject: [PATCH] [ExtractAPI,test] fix filecheck annotation

---
 clang/test/ExtractAPI/availability.c  | 2 +-
 clang/test/ExtractAPI/objc_property.m | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/test/ExtractAPI/availability.c 
b/clang/test/ExtractAPI/availability.c
index 237b2ffa55d7dc..ca6007e12e255c 100644
--- a/clang/test/ExtractAPI/availability.c
+++ b/clang/test/ExtractAPI/availability.c
@@ -40,7 +40,7 @@ void b(void) __attribute__((availability(macos, 
introduced=11.0, deprecated=12.0
 // B-NEXT:   }
 // B-NEXT: ]
 
-// RUN: FileCheck %s --input-file %t/output.symbols.json --check-prefix E
+// RUN: FileCheck %s --input-file %t/output.symbols.json --check-prefix C
 void c(void) __attribute__((availability(macos, introduced=11.0, 
deprecated=12.0, obsoleted=20.0))) __attribute__((availability(ios, 
introduced=13.0)));
 // C-LABEL: "!testLabel": "c:@F@c"
 // C:   "availability": [
diff --git a/clang/test/ExtractAPI/objc_property.m 
b/clang/test/ExtractAPI/objc_property.m
index f05584c885d91f..0c0b17c9c000fd 100644
--- a/clang/test/ExtractAPI/objc_property.m
+++ b/clang/test/ExtractAPI/objc_property.m
@@ -11,7 +11,7 @@ @protocol Protocol
 
 @interface Interface
 @property(class) int myInterfaceTypeProp;
-// CHECk-DAG: "!testRelLabel": "memberOf $ 
c:objc(cs)Interface(cpy)myInterfaceTypeProp $ c:objc(cs)Interface"
+// CHECK-DAG: "!testRelLabel": "memberOf $ 
c:objc(cs)Interface(cpy)myInterfaceTypeProp $ c:objc(cs)Interface"
 @property int myInterfaceInstanceProp;
 // CHECK-DAG: "!testRelLabel": "memberOf $ 
c:objc(cs)Interface(py)myInterfaceInstanceProp $ c:objc(cs)Interface"
 @end
@@ -20,7 +20,7 @@ @interface Interface (Category) 
 @property(class) int myCategoryTypeProp;
 // CHECK-DAG: "!testRelLabel": "memberOf $ 
c:objc(cs)Interface(cpy)myCategoryTypeProp $ c:objc(cs)Interface"
 @property int myCategoryInstanceProp;
-// CHECK-DAG "!testRelLabel": "memberOf $ 
c:objc(cs)Interface(py)myCategoryInstanceProp $ c:objc(cs)Interface"
+// CHECK-DAG: "!testRelLabel": "memberOf $ 
c:objc(cs)Interface(py)myCategoryInstanceProp $ c:objc(cs)Interface"
 @end
 
 // expected-no-diagnostics

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


[clang] [llvm] [clang][CodeGen] Global constructors/destructors are globals (PR #93914)

2024-06-03 Thread Alex Voicu via cfe-commits

https://github.com/AlexVlx updated 
https://github.com/llvm/llvm-project/pull/93914

>From 34b9646a38c6bdd0419dd9d2eb1bc847c4d16596 Mon Sep 17 00:00:00 2001
From: Alex Voicu 
Date: Tue, 28 May 2024 20:09:15 +0100
Subject: [PATCH 1/8] Fix `emitUsed` to place `used` globals in the Global AS.
 Update tests accordingly.

---
 clang/lib/CodeGen/CodeGenModule.cpp   | 11 ++-
 clang/test/CodeGen/2005-12-04-AttributeUsed.c |  2 ++
 clang/test/CodeGen/attr-retain.c  |  4 +++-
 clang/test/CodeGenCUDA/llvm-used.cu   |  7 +--
 clang/test/CodeGenCXX/attr-retain.cpp |  2 ++
 ...static-member-variable-explicit-specialization.cpp |  6 +-
 .../test/OpenMP/amdgcn_target_global_constructor.cpp  |  4 ++--
 7 files changed, 25 insertions(+), 11 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index e4774a587707a..30a18b1c5e7a8 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -2047,9 +2047,9 @@ void CodeGenModule::EmitCtorList(CtorList &Fns, const 
char *GlobalName) {
   llvm::Type *CtorPFTy = llvm::PointerType::get(CtorFTy,
   TheModule.getDataLayout().getProgramAddressSpace());
 
-  // Get the type of a ctor entry, { i32, void ()*, i8* }.
+  // Get the type of a ctor entry, { i32, program void ()*, global i8* }.
   llvm::StructType *CtorStructTy = llvm::StructType::get(
-  Int32Ty, CtorPFTy, VoidPtrTy);
+  Int32Ty, CtorPFTy, GlobalsInt8PtrTy);
 
   // Construct the constructor and destructor arrays.
   ConstantInitBuilder builder(*this);
@@ -2061,7 +2061,7 @@ void CodeGenModule::EmitCtorList(CtorList &Fns, const 
char *GlobalName) {
 if (I.AssociatedData)
   ctor.add(I.AssociatedData);
 else
-  ctor.addNullPointer(VoidPtrTy);
+  ctor.addNullPointer(GlobalsInt8PtrTy);
 ctor.finishAndAddTo(ctors);
   }
 
@@ -2928,12 +2928,13 @@ static void emitUsed(CodeGenModule &CGM, StringRef Name,
   for (unsigned i = 0, e = List.size(); i != e; ++i) {
 UsedArray[i] =
 llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast(
-cast(&*List[i]), CGM.Int8PtrTy);
+cast(&*List[i]), CGM.GlobalsInt8PtrTy);
   }
 
   if (UsedArray.empty())
 return;
-  llvm::ArrayType *ATy = llvm::ArrayType::get(CGM.Int8PtrTy, UsedArray.size());
+  llvm::ArrayType *ATy = llvm::ArrayType::get(CGM.GlobalsInt8PtrTy,
+  UsedArray.size());
 
   auto *GV = new llvm::GlobalVariable(
   CGM.getModule(), ATy, false, llvm::GlobalValue::AppendingLinkage,
diff --git a/clang/test/CodeGen/2005-12-04-AttributeUsed.c 
b/clang/test/CodeGen/2005-12-04-AttributeUsed.c
index bd232831fe1a6..c5089d9bda2c6 100644
--- a/clang/test/CodeGen/2005-12-04-AttributeUsed.c
+++ b/clang/test/CodeGen/2005-12-04-AttributeUsed.c
@@ -1,6 +1,8 @@
 // RUN: %clang_cc1 %s -triple x86_64-apple-darwin -emit-llvm -o - | FileCheck 
%s
+// RUN: %clang_cc1 %s -triple amdgcn-amd-amdhsa -emit-llvm -o - | FileCheck %s 
--check-prefix=GLOBALAS
 
 // CHECK: @llvm.used = appending global [2 x ptr] [ptr @foo, ptr @X], section 
"llvm.metadata"
+// GLOBALAS: @llvm.compiler.used = appending addrspace(1) global [2 x ptr 
addrspace(1)] [ptr addrspace(1) addrspacecast (ptr @foo to ptr addrspace(1)), 
ptr addrspace(1) @X], section "llvm.metadata"
 int X __attribute__((used));
 int Y;
 
diff --git a/clang/test/CodeGen/attr-retain.c b/clang/test/CodeGen/attr-retain.c
index fc41be76f9d0a..e86f6ae8ed06c 100644
--- a/clang/test/CodeGen/attr-retain.c
+++ b/clang/test/CodeGen/attr-retain.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -emit-llvm -triple x86_64 %s -o - | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -triple amdgcn-amd-amdhsa %s -o - | FileCheck %s 
--check-prefix=GLOBALAS
 
 /// Set !retain regardless of the target. The backend will lower !retain to
 /// SHF_GNU_RETAIN on ELF and ignore the metadata for other binary formats.
@@ -11,7 +12,8 @@
 
 // CHECK:  @llvm.used = appending global [8 x ptr] [ptr @c0, ptr @foo.l0, 
ptr @f0, ptr @f2, ptr @g0, ptr @g1, ptr @g3, ptr @g4], section "llvm.metadata"
 // CHECK:  @llvm.compiler.used = appending global [3 x ptr] [ptr @f2, ptr 
@g3, ptr @g4], section "llvm.metadata"
-
+// GLOBALAS:   @llvm.used = appending addrspace(1) global [8 x ptr 
addrspace(1)] [ptr addrspace(1) addrspacecast (ptr addrspace(4) @c0 to ptr 
addrspace(1)), ptr addrspace(1) @foo.l0, ptr addrspace(1) addrspacecast (ptr 
@f0 to ptr addrspace(1)), ptr addrspace(1) addrspacecast (ptr @f2 to ptr 
addrspace(1)), ptr addrspace(1) @g0, ptr addrspace(1) @g1, ptr addrspace(1) 
@g3, ptr addrspace(1) @g4], section "llvm.metadata"
+// GLOBALAS:   @llvm.compiler.used = appending addrspace(1) global [3 x ptr 
addrspace(1)] [ptr addrspace(1) addrspacecast (ptr @f2 to ptr addrspace(1)), 
ptr addrspace(1) @g3, ptr addrspace(1) @g4], section "llvm.metadata"
 const int c0 __attribute__((retain)) = 42;
 
 void foo(void) {
diff -

[clang] [clang] Fix-it hint for `++this` -> `++*this` when deref is modifiable (PR #94159)

2024-06-03 Thread Rajveer Singh Bharadwaj via cfe-commits

Rajveer100 wrote:

Tests which fail currently:

Clang :: Sema/exprs.c
Clang :: Sema/va_arg_x86_32.c
Clang :: SemaObjCXX/sel-address.mm

Also, what do you think about the fix-it hint wording for errors such as 
`assignment to cast is illegal, lvalue casts are not supported`?

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


[clang] [llvm] [IR] Avoid creating icmp/fcmp constant expressions (PR #92885)

2024-06-03 Thread via cfe-commits

mikaelholmen wrote:

Hi @nikic 

The following starts crashing with this patch:
```
opt ic2.ll -S -o /dev/null -passes=instcombine
```
It hits
```
opt: ../include/llvm/Support/Casting.h:578: decltype(auto) llvm::cast(From *) 
[To = llvm::TruncInst, From = llvm::Value]: Assertion `isa(Val) && 
"cast() argument of incompatible type!"' failed.
```
[ic2.ll.gz](https://github.com/user-attachments/files/15533503/ic2.ll.gz)


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


[clang] [llvm] Enable LLDB tests in pre-merge CI (PR #94208)

2024-06-03 Thread Michael Buch via cfe-commits

Michael137 wrote:

> @Michael137 This is for Linux. Windows works the same way just below those 
> lines:
> 
> https://github.com/llvm/llvm-project/blob/9a7bd8a60f03595be5d42315790df6d409f81091/.ci/generate-buildkite-pipeline-premerge#L253-L255

Ah, so what would the issue be with just adding more specific `check-lldb-*` 
targets, rather than all of `check-lldb`?

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


[clang] [clang-repl] Teach clang-repl how to load PCHs. (PR #94166)

2024-06-03 Thread Aaron Ballman via cfe-commits


@@ -138,6 +138,8 @@ namespace {
   assert(!M && "Replacing existing Module?");
   M.reset(new llvm::Module(ExpandModuleName(ModuleName, CodeGenOpts), C));
 
+  IRGenFinished = false;

AaronBallman wrote:

Why is IR gen *finished* when we're just starting the module?

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


[clang] [clang-repl] Teach clang-repl how to load PCHs. (PR #94166)

2024-06-03 Thread Aaron Ballman via cfe-commits


@@ -282,6 +288,8 @@ namespace {
 }
 
 void HandleTranslationUnit(ASTContext &Ctx) override {
+  IRGenFinished = true;

AaronBallman wrote:

shouldn't this be set at the end of `HandleTranslationUnit` rather than the 
beginning?

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


[clang] [clang] Make sure all C++ DR tests are running with `-pedantic-errors` (PR #94203)

2024-06-03 Thread Aaron Ballman via cfe-commits

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


[clang] [clang] Make sure all C++ DR tests are running with `-pedantic-errors` (PR #94203)

2024-06-03 Thread Aaron Ballman via cfe-commits

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


  1   2   3   4   5   >