[clang] [X86_64] fix empty structure vaarg in c++ (PR #77907)

2024-03-19 Thread Phoebe Wang via cfe-commits


@@ -3014,6 +3014,11 @@ Address X86_64ABIInfo::EmitVAArg(CodeGenFunction &CGF, 
Address VAListAddr,
   ABIArgInfo AI = classifyArgumentType(Ty, 0, neededInt, neededSSE,
/*isNamedArg*/false);
 
+  // Empty records are ignored for parameter passing purposes.
+  if (AI.isIgnore()) {
+return CGF.CreateMemTemp(Ty);
+  }

phoebewang wrote:

Does it behave differently between C and C++? Maybe adding a C test for it?

Besides, do not use parentheses for single line code.

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


[clang] [X86_64] fix arg pass error in struct. (PR #85394)

2024-03-19 Thread Longsheng Mou via cfe-commits

https://github.com/CoTinker updated 
https://github.com/llvm/llvm-project/pull/85394

>From d344d20883a73ef1d273a4b74eb1b5df2893041e Mon Sep 17 00:00:00 2001
From: Longsheng Mou 
Date: Fri, 15 Mar 2024 20:50:54 +0800
Subject: [PATCH] [X86_64] fix arg pass error in struct.

typedef long long ll __attribute__((aligned (4)));
struct S {
  int a;
  ll b;
};

when classify:
a: Lo = Integer, Hi = NoClass
b: Lo = Integer, Hi = NoClass
struct S: Lo = Integer, Hi = NoClass

In this case, only one i64 register is used when the structure
parameter is transferred, which is obviously incorrect.So we need
to treat the split case specially.
---
 clang/lib/CodeGen/Targets/X86.cpp |  6 ++
 clang/test/CodeGen/X86/x86_64-arguments.c | 18 ++
 2 files changed, 24 insertions(+)

diff --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index 2291c991fb1107..d91911ece69683 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -1787,6 +1787,8 @@ void X86_64ABIInfo::classify(QualType Ty, uint64_t 
OffsetBase, Class &Lo,
   Lo = Hi = NoClass;
 
   Class &Current = OffsetBase < 64 ? Lo : Hi;
+  bool IsSplit =
+  OffsetBase < 64 && (OffsetBase + getContext().getTypeSize(Ty)) > 64;
   Current = Memory;
 
   if (const BuiltinType *BT = Ty->getAs()) {
@@ -1798,9 +1800,13 @@ void X86_64ABIInfo::classify(QualType Ty, uint64_t 
OffsetBase, Class &Lo,
   Lo = Integer;
   Hi = Integer;
 } else if (k >= BuiltinType::Bool && k <= BuiltinType::LongLong) {
+  if (IsSplit)
+return;
   Current = Integer;
 } else if (k == BuiltinType::Float || k == BuiltinType::Double ||
k == BuiltinType::Float16 || k == BuiltinType::BFloat16) {
+  if (IsSplit)
+return;
   Current = SSE;
 } else if (k == BuiltinType::Float128) {
   Lo = SSE;
diff --git a/clang/test/CodeGen/X86/x86_64-arguments.c 
b/clang/test/CodeGen/X86/x86_64-arguments.c
index cf5636cfd518b6..82845f0a2b31fd 100644
--- a/clang/test/CodeGen/X86/x86_64-arguments.c
+++ b/clang/test/CodeGen/X86/x86_64-arguments.c
@@ -533,6 +533,24 @@ typedef float t66 __attribute__((__vector_size__(128), 
__aligned__(128)));
 void f66(t66 a0) {
 }
 
+typedef long long t67 __attribute__((aligned (4)));
+struct s67 {
+  int a;
+  t67 b;
+};
+// CHECK-LABEL: define{{.*}} void @f67(ptr noundef byval(%struct.s67) align 8 
%x)
+void f67(struct s67 x) {
+}
+
+typedef double t68 __attribute__((aligned (4)));
+struct s68 {
+  int a;
+  t68 b;
+};
+// CHECK-LABEL: define{{.*}} void @f68(ptr noundef byval(%struct.s68) align 8 
%x)
+void f68(struct s68 x) {
+}
+
 /// The synthesized __va_list_tag does not have file/line fields.
 // CHECK:  = distinct !DICompositeType(tag: DW_TAG_structure_type, name: 
"__va_list_tag",
 // CHECK-NOT:  file:

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


[clang] [clang][dataflow] Refactor processing of terminator element (PR #84499)

2024-03-19 Thread via cfe-commits

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

Thanks -- _so_ much better!

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


[clang] [clang][NFC] Add documentation for `CastExpr::path()`. (PR #85623)

2024-03-19 Thread via cfe-commits

https://github.com/martinboehme updated 
https://github.com/llvm/llvm-project/pull/85623

>From 369410916bd61671f81702c4654bd48bfc3c6c53 Mon Sep 17 00:00:00 2001
From: Martin Braenne 
Date: Mon, 18 Mar 2024 09:51:23 +
Subject: [PATCH 1/2] [clang][NFC] Add documentation for `CastExpr::path()`.

This didn't have any documentation, so I had to do some experimenting in
godbolt when I used this in https://github.com/llvm/llvm-project/pull/84138,
and my reviewer later also had some
[questions](https://github.com/llvm/llvm-project/pull/84138#discussion_r1524855434)
about this, so I figured it would be worth adding documentation.
---
 clang/include/clang/AST/Expr.h | 9 +
 1 file changed, 9 insertions(+)

diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 446bec4081e869..8c4db4828477d0 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -3552,6 +3552,15 @@ class CastExpr : public Expr {
   /// function that it invokes.
   NamedDecl *getConversionFunction() const;
 
+  /// Path through the class hierarchy taken by a `DerivedToBase` or
+  /// `UncheckedDerivedToBase` cast. For each derived-to-base edge in the path,
+  /// the path contains a `CXXBaseSpecifier` for the base class of that edge;
+  /// the entries are ordered from derived class to base class.
+  ///
+  /// For example, given classes `Base`, `Intermediate : public Base` and
+  /// `Derived : public Intermediate`, the path for a cast from `Derived *` to
+  /// `Base *` contains two entries: One for `Intermediate`, and one for 
`Base`,
+  /// in that order.
   typedef CXXBaseSpecifier **path_iterator;
   typedef const CXXBaseSpecifier *const *path_const_iterator;
   bool path_empty() const { return path_size() == 0; }

>From 571d5f4b180b2e55b03a4a43a7c0fadbee2ed25a Mon Sep 17 00:00:00 2001
From: Martin Braenne 
Date: Tue, 19 Mar 2024 07:30:39 +
Subject: [PATCH 2/2] fixup! [clang][NFC] Add documentation for
 `CastExpr::path()`.

---
 clang/include/clang/AST/Expr.h | 11 +++
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 8c4db4828477d0..292cda39dc56bf 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -3552,10 +3552,13 @@ class CastExpr : public Expr {
   /// function that it invokes.
   NamedDecl *getConversionFunction() const;
 
-  /// Path through the class hierarchy taken by a `DerivedToBase` or
-  /// `UncheckedDerivedToBase` cast. For each derived-to-base edge in the path,
-  /// the path contains a `CXXBaseSpecifier` for the base class of that edge;
-  /// the entries are ordered from derived class to base class.
+  /// Path through the class hierarchy taken by casts between base and derived
+  /// classes (see implementation of `CastConsistency()` for a full list of
+  /// cast kinds that have a path).
+  ///
+  /// For each derived-to-base edge in the path, the path contains a
+  /// `CXXBaseSpecifier` for the base class of that edge; the entries are
+  /// ordered from derived class to base class.
   ///
   /// For example, given classes `Base`, `Intermediate : public Base` and
   /// `Derived : public Intermediate`, the path for a cast from `Derived *` to

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


[clang] [clang][NFC] Add documentation for `CastExpr::path()`. (PR #85623)

2024-03-19 Thread via cfe-commits


@@ -3552,6 +3552,15 @@ class CastExpr : public Expr {
   /// function that it invokes.
   NamedDecl *getConversionFunction() const;
 
+  /// Path through the class hierarchy taken by a `DerivedToBase` or
+  /// `UncheckedDerivedToBase` cast. For each derived-to-base edge in the path,
+  /// the path contains a `CXXBaseSpecifier` for the base class of that edge;
+  /// the entries are ordered from derived class to base class.

martinboehme wrote:

Thanks for pointing this out! I've fixed this -- WDYT?

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


[clang] [clang][frontend] Make DumpModuleInfoAction emit the full macro (PR #85745)

2024-03-19 Thread Zhang Yi via cfe-commits

https://github.com/zhanyi22333 created 
https://github.com/llvm/llvm-project/pull/85745

This PR works on the TODO `Emit the macro definition bodies completely`  in 
FrontendActions.cpp. Emiting the macro definition bodies completely can help 
user get more details about macro.

The beginning of macro-body string is get by MacroInfo definition location in 
SourceManager. Then it compute the macro-body string length by locate the '\n' 
but not '\\\n'. After that, the string is getted and reformmatted into one 
line. 
When cannot get the MacroInfo, it will only emit the name of macro definition. 

@rjmccall @kpneal @zahiraam @efriedma-quic @vgvassilev @junaire

>From d29678159c34a668259fbed601df975275190105 Mon Sep 17 00:00:00 2001
From: Zhang Yi <18994118...@163.com>
Date: Mon, 18 Mar 2024 20:22:39 -0700
Subject: [PATCH 1/2] [clang][frontend] change DumpModuleInfoAction test cases.

---
 clang/test/Modules/cxx20-module-file-info-macros.cpp | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/clang/test/Modules/cxx20-module-file-info-macros.cpp 
b/clang/test/Modules/cxx20-module-file-info-macros.cpp
index 3b67e9b9acd410..fad218bdfc9638 100644
--- a/clang/test/Modules/cxx20-module-file-info-macros.cpp
+++ b/clang/test/Modules/cxx20-module-file-info-macros.cpp
@@ -37,8 +37,8 @@
 
 // CHECK: Macro Definitions:
 // CHECK-DAG: REDEFINE
-// CHECK-DAG: FUNC_Macro
-// CHECK-DAG: CONSTANT
+// CHECK-DAG: FUNC_Macro(X) (X+1)
+// CHECK-DAG: CONSTANT 43
 // CHECK-DAG: FOO
 // CHECK-NEXT: ===
 
@@ -46,8 +46,8 @@
 #include "foo.h"
 #undef REDEFINE
 // CHECK: Macro Definitions:
-// CHECK-DAG: CONSTANT
-// CHECK-DAG: FUNC_Macro
+// CHECK-DAG: CONSTANT 43
+// CHECK-DAG: FUNC_Macro(X) (X+1)
 // CHECK-DAG: FOO
 // CHECK-NEXT: ===
 

>From ce6501638142a9cbce7733ff9acab70f82d65891 Mon Sep 17 00:00:00 2001
From: Zhang Yi <18994118...@163.com>
Date: Mon, 18 Mar 2024 20:23:00 -0700
Subject: [PATCH 2/2] [clang][frontend] Make DumpModuleInfoAction emit the full
 macro

---
 clang/lib/Frontend/FrontendActions.cpp | 32 +++---
 1 file changed, 29 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Frontend/FrontendActions.cpp 
b/clang/lib/Frontend/FrontendActions.cpp
index 81fcd8d5ae9bd3..aa2781daef3988 100644
--- a/clang/lib/Frontend/FrontendActions.cpp
+++ b/clang/lib/Frontend/FrontendActions.cpp
@@ -925,15 +925,41 @@ void DumpModuleInfoAction::ExecuteAction() {
 
 // Emit the macro definitions in the module file so that we can know how
 // much definitions in the module file quickly.
-// TODO: Emit the macro definition bodies completely.
 if (auto FilteredMacros = llvm::make_filter_range(
 R->getPreprocessor().macros(),
 [](const auto &Macro) { return Macro.first->isFromAST(); });
 !FilteredMacros.empty()) {
   Out << "   Macro Definitions:\n";
   for (/* pair*/ const auto &Macro :
-   FilteredMacros)
-Out << " " << Macro.first->getName() << "\n";
+   FilteredMacros) {
+SourceManager &SM = PP.getSourceManager();
+clang::MacroInfo *MacroInfo = PP.getMacroInfo(Macro.first);
+if (MacroInfo) {
+  bool isInvalid=true;
+  const char* 
ContentStrPtr=SM.getCharacterData(MacroInfo->getDefinitionLoc(),&isInvalid);
+  if (!isInvalid) {
+  int ContentLength=0;
+  while ( !(*(ContentStrPtr+ContentLength)=='\n') ||  
*(ContentStrPtr+ContentLength-1)=='\\') {
+ContentLength++;
+  }
+  std::string MacroContent=std::string(ContentStrPtr,ContentLength);
+  // Replace '\\\n' with space
+  size_t pos = 0;
+  while ((pos = MacroContent.find("\\\n", pos)) != std::string::npos) {
+MacroContent.replace(pos, 2," ");
+  }
+  // Merge spaces
+  auto new_end = std::unique(MacroContent.begin(), MacroContent.end(), 
[](char a, char b) {
+return a == ' ' && b == ' ';
+  });
+  MacroContent.erase(new_end, MacroContent.end());
+  Out << " " << MacroContent << '\n';
+  }
+}
+else {
+  Out << " " << Macro.first->getName() << "\n";
+}
+  }
 }
 
 // Now let's print out any modules we did not see as part of the Primary.

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


[clang] [clang][frontend] Make DumpModuleInfoAction emit the full macro (PR #85745)

2024-03-19 Thread via cfe-commits

github-actions[bot] wrote:



Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from 
other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

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


[clang] [clang][frontend] Make DumpModuleInfoAction emit the full macro (PR #85745)

2024-03-19 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-modules

Author: Zhang Yi (zhanyi22333)


Changes

This PR works on the TODO `Emit the macro definition bodies completely`  in 
FrontendActions.cpp. Emiting the macro definition bodies completely can help 
user get more details about macro.

The beginning of macro-body string is get by MacroInfo definition location in 
SourceManager. Then it compute the macro-body string length by locate the '\n' 
but not '\\\n'. After that, the string is getted and reformmatted into one 
line. 
When cannot get the MacroInfo, it will only emit the name of macro definition. 

@rjmccall @kpneal @zahiraam @efriedma-quic 
@vgvassilev @junaire

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


2 Files Affected:

- (modified) clang/lib/Frontend/FrontendActions.cpp (+29-3) 
- (modified) clang/test/Modules/cxx20-module-file-info-macros.cpp (+4-4) 


``diff
diff --git a/clang/lib/Frontend/FrontendActions.cpp 
b/clang/lib/Frontend/FrontendActions.cpp
index 81fcd8d5ae9bd3..aa2781daef3988 100644
--- a/clang/lib/Frontend/FrontendActions.cpp
+++ b/clang/lib/Frontend/FrontendActions.cpp
@@ -925,15 +925,41 @@ void DumpModuleInfoAction::ExecuteAction() {
 
 // Emit the macro definitions in the module file so that we can know how
 // much definitions in the module file quickly.
-// TODO: Emit the macro definition bodies completely.
 if (auto FilteredMacros = llvm::make_filter_range(
 R->getPreprocessor().macros(),
 [](const auto &Macro) { return Macro.first->isFromAST(); });
 !FilteredMacros.empty()) {
   Out << "   Macro Definitions:\n";
   for (/* pair*/ const auto &Macro :
-   FilteredMacros)
-Out << " " << Macro.first->getName() << "\n";
+   FilteredMacros) {
+SourceManager &SM = PP.getSourceManager();
+clang::MacroInfo *MacroInfo = PP.getMacroInfo(Macro.first);
+if (MacroInfo) {
+  bool isInvalid=true;
+  const char* 
ContentStrPtr=SM.getCharacterData(MacroInfo->getDefinitionLoc(),&isInvalid);
+  if (!isInvalid) {
+  int ContentLength=0;
+  while ( !(*(ContentStrPtr+ContentLength)=='\n') ||  
*(ContentStrPtr+ContentLength-1)=='\\') {
+ContentLength++;
+  }
+  std::string MacroContent=std::string(ContentStrPtr,ContentLength);
+  // Replace '\\\n' with space
+  size_t pos = 0;
+  while ((pos = MacroContent.find("\\\n", pos)) != std::string::npos) {
+MacroContent.replace(pos, 2," ");
+  }
+  // Merge spaces
+  auto new_end = std::unique(MacroContent.begin(), MacroContent.end(), 
[](char a, char b) {
+return a == ' ' && b == ' ';
+  });
+  MacroContent.erase(new_end, MacroContent.end());
+  Out << " " << MacroContent << '\n';
+  }
+}
+else {
+  Out << " " << Macro.first->getName() << "\n";
+}
+  }
 }
 
 // Now let's print out any modules we did not see as part of the Primary.
diff --git a/clang/test/Modules/cxx20-module-file-info-macros.cpp 
b/clang/test/Modules/cxx20-module-file-info-macros.cpp
index 3b67e9b9acd410..fad218bdfc9638 100644
--- a/clang/test/Modules/cxx20-module-file-info-macros.cpp
+++ b/clang/test/Modules/cxx20-module-file-info-macros.cpp
@@ -37,8 +37,8 @@
 
 // CHECK: Macro Definitions:
 // CHECK-DAG: REDEFINE
-// CHECK-DAG: FUNC_Macro
-// CHECK-DAG: CONSTANT
+// CHECK-DAG: FUNC_Macro(X) (X+1)
+// CHECK-DAG: CONSTANT 43
 // CHECK-DAG: FOO
 // CHECK-NEXT: ===
 
@@ -46,8 +46,8 @@
 #include "foo.h"
 #undef REDEFINE
 // CHECK: Macro Definitions:
-// CHECK-DAG: CONSTANT
-// CHECK-DAG: FUNC_Macro
+// CHECK-DAG: CONSTANT 43
+// CHECK-DAG: FUNC_Macro(X) (X+1)
 // CHECK-DAG: FOO
 // CHECK-NEXT: ===
 

``




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


[clang] [X86_64] fix empty structure vaarg in c++ (PR #77907)

2024-03-19 Thread via cfe-commits

https://github.com/hstk30-hw updated 
https://github.com/llvm/llvm-project/pull/77907

>From 95e44553a83f92876c1489f43efad57daf960965 Mon Sep 17 00:00:00 2001
From: Longsheng Mou 
Date: Fri, 12 Jan 2024 18:24:08 +0800
Subject: [PATCH] [X86_64] fix empty structure vaarg in c++

SizeInBytes of empty structure is 0 in C, while 1 in C++.
And empty structure argument of the function is ignored
in X86_64 backend.As a result, the value of variable
arguments in C++ is incorrect.So we should just make a
temporary and return its address.
---
 clang/lib/CodeGen/Targets/X86.cpp  |  4 
 clang/test/CodeGenCXX/x86_64-vaarg.cpp | 13 +
 2 files changed, 17 insertions(+)
 create mode 100644 clang/test/CodeGenCXX/x86_64-vaarg.cpp

diff --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index d053f41ab168f5..936ca16f1565fa 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -3014,6 +3014,10 @@ Address X86_64ABIInfo::EmitVAArg(CodeGenFunction &CGF, 
Address VAListAddr,
   ABIArgInfo AI = classifyArgumentType(Ty, 0, neededInt, neededSSE,
/*isNamedArg*/false);
 
+  // Empty records are ignored for parameter passing purposes.
+  if (AI.isIgnore())
+return CGF.CreateMemTemp(Ty);
+
   // AMD64-ABI 3.5.7p5: Step 1. Determine whether type may be passed
   // in the registers. If not go to step 7.
   if (!neededInt && !neededSSE)
diff --git a/clang/test/CodeGenCXX/x86_64-vaarg.cpp 
b/clang/test/CodeGenCXX/x86_64-vaarg.cpp
new file mode 100644
index 00..849afd5fdd53b8
--- /dev/null
+++ b/clang/test/CodeGenCXX/x86_64-vaarg.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -x c -o - %s | 
FileCheck %s
+
+typedef struct { struct {} a; } empty;
+
+// CHECK-LABEL: define{{.*}} void @{{.*}}empty_record_test{{.*}}()
+empty empty_record_test(void) {
+// CHECK: [[RET:%[a-z]+]] = alloca %struct.empty, align 1
+// CHECK: [[TMP:%[a-z]+]] = alloca %struct.empty, align 1
+// CHECK: call void @llvm.memcpy{{.*}}(ptr align 1 [[RET]], ptr align 1 [[TMP]]
+  __builtin_va_list list;
+  return __builtin_va_arg(list, empty);
+}

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


[clang] [clang][frontend] Make DumpModuleInfoAction emit the full macro (PR #85745)

2024-03-19 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff f8042171552ca16e77a5e9367188e7f218474380 
ce6501638142a9cbce7733ff9acab70f82d65891 -- 
clang/lib/Frontend/FrontendActions.cpp 
clang/test/Modules/cxx20-module-file-info-macros.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Frontend/FrontendActions.cpp 
b/clang/lib/Frontend/FrontendActions.cpp
index aa2781daef..c6ed8231af 100644
--- a/clang/lib/Frontend/FrontendActions.cpp
+++ b/clang/lib/Frontend/FrontendActions.cpp
@@ -935,28 +935,31 @@ void DumpModuleInfoAction::ExecuteAction() {
 SourceManager &SM = PP.getSourceManager();
 clang::MacroInfo *MacroInfo = PP.getMacroInfo(Macro.first);
 if (MacroInfo) {
-  bool isInvalid=true;
-  const char* 
ContentStrPtr=SM.getCharacterData(MacroInfo->getDefinitionLoc(),&isInvalid);
+  bool isInvalid = true;
+  const char *ContentStrPtr =
+  SM.getCharacterData(MacroInfo->getDefinitionLoc(), &isInvalid);
   if (!isInvalid) {
-  int ContentLength=0;
-  while ( !(*(ContentStrPtr+ContentLength)=='\n') ||  
*(ContentStrPtr+ContentLength-1)=='\\') {
-ContentLength++;
+int ContentLength = 0;
+while (!(*(ContentStrPtr + ContentLength) == '\n') ||
+   *(ContentStrPtr + ContentLength - 1) == '\\') {
+  ContentLength++;
+}
+std::string MacroContent =
+std::string(ContentStrPtr, ContentLength);
+// Replace '\\\n' with space
+size_t pos = 0;
+while ((pos = MacroContent.find("\\\n", pos)) !=
+   std::string::npos) {
+  MacroContent.replace(pos, 2, " ");
+}
+// Merge spaces
+auto new_end = std::unique(
+MacroContent.begin(), MacroContent.end(),
+[](char a, char b) { return a == ' ' && b == ' '; });
+MacroContent.erase(new_end, MacroContent.end());
+Out << " " << MacroContent << '\n';
   }
-  std::string MacroContent=std::string(ContentStrPtr,ContentLength);
-  // Replace '\\\n' with space
-  size_t pos = 0;
-  while ((pos = MacroContent.find("\\\n", pos)) != std::string::npos) {
-MacroContent.replace(pos, 2," ");
-  }
-  // Merge spaces
-  auto new_end = std::unique(MacroContent.begin(), MacroContent.end(), 
[](char a, char b) {
-return a == ' ' && b == ' ';
-  });
-  MacroContent.erase(new_end, MacroContent.end());
-  Out << " " << MacroContent << '\n';
-  }
-}
-else {
+} else {
   Out << " " << Macro.first->getName() << "\n";
 }
   }

``




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


[clang] [clang][dataflow][NFC] Rename `ControlFlowContext` to `AdornedCFG`. (PR #85640)

2024-03-19 Thread via cfe-commits

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


[clang] 59ff3ad - [clang][dataflow][NFC] Rename `ControlFlowContext` to `AdornedCFG`. (#85640)

2024-03-19 Thread via cfe-commits

Author: martinboehme
Date: 2024-03-19T08:44:08+01:00
New Revision: 59ff3adcc1310e22ab31163767e49b4edb20c6b4

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

LOG: [clang][dataflow][NFC] Rename `ControlFlowContext` to `AdornedCFG`. 
(#85640)

This expresses better what the class actually does, and it reduces the
number of
`Context`s that we have in the codebase.

A deprecated alias `ControlFlowContext` is available from the old
header.

Added: 
clang/include/clang/Analysis/FlowSensitive/AdornedCFG.h
clang/lib/Analysis/FlowSensitive/AdornedCFG.cpp

Modified: 
clang/docs/tools/clang-formatted-files.txt
clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
clang/include/clang/Analysis/FlowSensitive/Logger.h
clang/include/clang/Analysis/FlowSensitive/Transfer.h
clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h
clang/lib/Analysis/FlowSensitive/CMakeLists.txt
clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp
clang/lib/Analysis/FlowSensitive/Logger.cpp
clang/lib/Analysis/FlowSensitive/Transfer.cpp
clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
clang/unittests/Analysis/FlowSensitive/DeterminismTest.cpp
clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp
clang/unittests/Analysis/FlowSensitive/TestingSupport.h
clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp

Removed: 
clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp



diff  --git a/clang/docs/tools/clang-formatted-files.txt 
b/clang/docs/tools/clang-formatted-files.txt
index 40ab76fa26a9e3..70687c23b15e61 100644
--- a/clang/docs/tools/clang-formatted-files.txt
+++ b/clang/docs/tools/clang-formatted-files.txt
@@ -122,6 +122,7 @@ clang/include/clang/Analysis/MacroExpansionContext.h
 clang/include/clang/Analysis/Analyses/CalledOnceCheck.h
 clang/include/clang/Analysis/Analyses/CFGReachabilityAnalysis.h
 clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
+clang/include/clang/Analysis/FlowSensitive/AdornedCFG.h
 clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h
 clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
 clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
@@ -306,7 +307,7 @@ clang/include/clang-c/Index.h
 clang/lib/Analysis/CalledOnceCheck.cpp
 clang/lib/Analysis/CloneDetection.cpp
 clang/lib/Analysis/CodeInjector.cpp
-clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
+clang/lib/Analysis/FlowSensitive/AdornedCFG.cpp
 clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
 clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
 clang/lib/Analysis/FlowSensitive/DebugSupport.cpp

diff  --git a/clang/include/clang/Analysis/FlowSensitive/AdornedCFG.h 
b/clang/include/clang/Analysis/FlowSensitive/AdornedCFG.h
new file mode 100644
index 00..420f13ce11bfde
--- /dev/null
+++ b/clang/include/clang/Analysis/FlowSensitive/AdornedCFG.h
@@ -0,0 +1,96 @@
+//===-- AdornedCFG.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
+//
+//===--===//
+//
+//  This file defines an AdornedCFG class that is used by dataflow analyses 
that
+//  run over Control-Flow Graphs (CFGs).
+//
+//===--===//
+
+#ifndef LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_ADORNEDCFG_H
+#define LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_ADORNEDCFG_H
+
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Stmt.h"
+#include "clang/Analysis/CFG.h"
+#include "llvm/ADT/BitVector.h"
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/Support/Error.h"
+#include 
+#include 
+
+namespace clang {
+namespace dataflow {
+
+/// Holds CFG with additional information derived from it that is needed to
+/// perform dataflow analysis.
+class AdornedCFG {
+public:
+  /// Builds an `AdornedCFG` from a `FunctionDecl`.
+  /// `Func.doesThisDeclarationHaveABody()` must be true, and
+  /// `Func.isTemplated()` must be false.
+  static llvm::Expected build(const FunctionDecl &Func);
+
+  /// Builds an `AdornedCFG` from an AST node. `D` is the function in which
+  /// `S` resides. `D.isTemplated()` must be false.
+  static llvm::Expected build(const Decl &D, Stmt &S,
+  ASTContext &C);
+
+  /// Returns the 

[clang] [clang][frontend] Make DumpModuleInfoAction emit the full macro (PR #85745)

2024-03-19 Thread Zhang Yi via cfe-commits

https://github.com/zhanyi22333 updated 
https://github.com/llvm/llvm-project/pull/85745

>From d29678159c34a668259fbed601df975275190105 Mon Sep 17 00:00:00 2001
From: Zhang Yi <18994118...@163.com>
Date: Mon, 18 Mar 2024 20:22:39 -0700
Subject: [PATCH 1/2] [clang][frontend] change DumpModuleInfoAction test cases.

---
 clang/test/Modules/cxx20-module-file-info-macros.cpp | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/clang/test/Modules/cxx20-module-file-info-macros.cpp 
b/clang/test/Modules/cxx20-module-file-info-macros.cpp
index 3b67e9b9acd410..fad218bdfc9638 100644
--- a/clang/test/Modules/cxx20-module-file-info-macros.cpp
+++ b/clang/test/Modules/cxx20-module-file-info-macros.cpp
@@ -37,8 +37,8 @@
 
 // CHECK: Macro Definitions:
 // CHECK-DAG: REDEFINE
-// CHECK-DAG: FUNC_Macro
-// CHECK-DAG: CONSTANT
+// CHECK-DAG: FUNC_Macro(X) (X+1)
+// CHECK-DAG: CONSTANT 43
 // CHECK-DAG: FOO
 // CHECK-NEXT: ===
 
@@ -46,8 +46,8 @@
 #include "foo.h"
 #undef REDEFINE
 // CHECK: Macro Definitions:
-// CHECK-DAG: CONSTANT
-// CHECK-DAG: FUNC_Macro
+// CHECK-DAG: CONSTANT 43
+// CHECK-DAG: FUNC_Macro(X) (X+1)
 // CHECK-DAG: FOO
 // CHECK-NEXT: ===
 

>From 37e6d22a1aa4930521b85d13b7860a168416e256 Mon Sep 17 00:00:00 2001
From: Zhang Yi <18994118...@163.com>
Date: Mon, 18 Mar 2024 20:23:00 -0700
Subject: [PATCH 2/2] [clang][frontend] Make DumpModuleInfoAction emit the full
 macro

---
 clang/lib/Frontend/FrontendActions.cpp | 35 +++---
 1 file changed, 32 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Frontend/FrontendActions.cpp 
b/clang/lib/Frontend/FrontendActions.cpp
index 81fcd8d5ae9bd3..c6ed8231af0ecd 100644
--- a/clang/lib/Frontend/FrontendActions.cpp
+++ b/clang/lib/Frontend/FrontendActions.cpp
@@ -925,15 +925,44 @@ void DumpModuleInfoAction::ExecuteAction() {
 
 // Emit the macro definitions in the module file so that we can know how
 // much definitions in the module file quickly.
-// TODO: Emit the macro definition bodies completely.
 if (auto FilteredMacros = llvm::make_filter_range(
 R->getPreprocessor().macros(),
 [](const auto &Macro) { return Macro.first->isFromAST(); });
 !FilteredMacros.empty()) {
   Out << "   Macro Definitions:\n";
   for (/* pair*/ const auto &Macro :
-   FilteredMacros)
-Out << " " << Macro.first->getName() << "\n";
+   FilteredMacros) {
+SourceManager &SM = PP.getSourceManager();
+clang::MacroInfo *MacroInfo = PP.getMacroInfo(Macro.first);
+if (MacroInfo) {
+  bool isInvalid = true;
+  const char *ContentStrPtr =
+  SM.getCharacterData(MacroInfo->getDefinitionLoc(), &isInvalid);
+  if (!isInvalid) {
+int ContentLength = 0;
+while (!(*(ContentStrPtr + ContentLength) == '\n') ||
+   *(ContentStrPtr + ContentLength - 1) == '\\') {
+  ContentLength++;
+}
+std::string MacroContent =
+std::string(ContentStrPtr, ContentLength);
+// Replace '\\\n' with space
+size_t pos = 0;
+while ((pos = MacroContent.find("\\\n", pos)) !=
+   std::string::npos) {
+  MacroContent.replace(pos, 2, " ");
+}
+// Merge spaces
+auto new_end = std::unique(
+MacroContent.begin(), MacroContent.end(),
+[](char a, char b) { return a == ' ' && b == ' '; });
+MacroContent.erase(new_end, MacroContent.end());
+Out << " " << MacroContent << '\n';
+  }
+} else {
+  Out << " " << Macro.first->getName() << "\n";
+}
+  }
 }
 
 // Now let's print out any modules we did not see as part of the Primary.

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


[clang] [Clang] Coroutines: Properly Check if `await_suspend` return type convertible to `std::coroutine_handle<>` (PR #85684)

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

ChuanqiXu9 wrote:

> I am also ok with changing the patch to reject programs whose await_suspend 
> doesn't strictly return std::coroutine_handle if upstream prefers.

It should be good to do that since it makes the behavior more conforming. And 
maybe it is better to do this a seperate patch.
Especially if it can help reduce the many non-semantical changes in 
SemaExprCXX.cpp.



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


[clang] [X86_64] fix empty structure vaarg in c++ (PR #77907)

2024-03-19 Thread Phoebe Wang via cfe-commits

phoebewang wrote:

Checked both pr77036.cpp and pr77036.c get the same result, so looks like a 
right fix. But I want to wait @efriedma-quic to sign off.

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


[clang] b788e46 - [clang][dataflow] Model assignment to derived class from base. (#85064)

2024-03-19 Thread via cfe-commits

Author: martinboehme
Date: 2024-03-19T09:22:35+01:00
New Revision: b788e4655c4e06f6821bc220e5745d6a4f9d4d09

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

LOG: [clang][dataflow] Model assignment to derived class from base. (#85064)

This is a relatively rare case, but

- It's still nice to get this right,
- We can remove the special case for this in
`VisitCXXOperatorCallExpr()` (that
  simply bails out), and
- With this in place, I can avoid having to add a similar special case
in an
  upcoming patch.

Added: 


Modified: 
clang/include/clang/Analysis/FlowSensitive/RecordOps.h
clang/lib/Analysis/FlowSensitive/RecordOps.cpp
clang/lib/Analysis/FlowSensitive/Transfer.cpp
clang/unittests/Analysis/FlowSensitive/RecordOpsTest.cpp
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Removed: 




diff  --git a/clang/include/clang/Analysis/FlowSensitive/RecordOps.h 
b/clang/include/clang/Analysis/FlowSensitive/RecordOps.h
index 783e53e980aa2c..8fad45fc11d81e 100644
--- a/clang/include/clang/Analysis/FlowSensitive/RecordOps.h
+++ b/clang/include/clang/Analysis/FlowSensitive/RecordOps.h
@@ -31,7 +31,11 @@ namespace dataflow {
 ///
 /// Requirements:
 ///
-///  `Src` and `Dst` must have the same canonical unqualified type.
+///  Either:
+///- `Src` and `Dest` must have the same canonical unqualified type, or
+///- The type of `Src` must be derived from `Dest`, or
+///- The type of `Dest` must be derived from `Src` (in this case, any 
fields
+///  that are only present in `Dest` are not overwritten).
 void copyRecord(RecordStorageLocation &Src, RecordStorageLocation &Dst,
 Environment &Env);
 

diff  --git a/clang/lib/Analysis/FlowSensitive/RecordOps.cpp 
b/clang/lib/Analysis/FlowSensitive/RecordOps.cpp
index da4dd6dc078515..2f0b0e5c5640c3 100644
--- a/clang/lib/Analysis/FlowSensitive/RecordOps.cpp
+++ b/clang/lib/Analysis/FlowSensitive/RecordOps.cpp
@@ -14,18 +14,52 @@
 
 #define DEBUG_TYPE "dataflow"
 
-void clang::dataflow::copyRecord(RecordStorageLocation &Src,
- RecordStorageLocation &Dst, Environment &Env) 
{
+namespace clang::dataflow {
+
+static void copyField(const ValueDecl &Field, StorageLocation *SrcFieldLoc,
+  StorageLocation *DstFieldLoc, RecordStorageLocation &Dst,
+  Environment &Env) {
+  assert(Field.getType()->isReferenceType() ||
+ (SrcFieldLoc != nullptr && DstFieldLoc != nullptr));
+
+  if (Field.getType()->isRecordType()) {
+copyRecord(cast(*SrcFieldLoc),
+   cast(*DstFieldLoc), Env);
+  } else if (Field.getType()->isReferenceType()) {
+Dst.setChild(Field, SrcFieldLoc);
+  } else {
+if (Value *Val = Env.getValue(*SrcFieldLoc))
+  Env.setValue(*DstFieldLoc, *Val);
+else
+  Env.clearValue(*DstFieldLoc);
+  }
+}
+
+static void copySyntheticField(QualType FieldType, StorageLocation 
&SrcFieldLoc,
+   StorageLocation &DstFieldLoc, Environment &Env) 
{
+  if (FieldType->isRecordType()) {
+copyRecord(cast(SrcFieldLoc),
+   cast(DstFieldLoc), Env);
+  } else {
+if (Value *Val = Env.getValue(SrcFieldLoc))
+  Env.setValue(DstFieldLoc, *Val);
+else
+  Env.clearValue(DstFieldLoc);
+  }
+}
+
+void copyRecord(RecordStorageLocation &Src, RecordStorageLocation &Dst,
+Environment &Env) {
   auto SrcType = Src.getType().getCanonicalType().getUnqualifiedType();
   auto DstType = Dst.getType().getCanonicalType().getUnqualifiedType();
 
   auto SrcDecl = SrcType->getAsCXXRecordDecl();
   auto DstDecl = DstType->getAsCXXRecordDecl();
 
-  bool compatibleTypes =
+  [[maybe_unused]] bool compatibleTypes =
   SrcType == DstType ||
-  (SrcDecl && DstDecl && SrcDecl->isDerivedFrom(DstDecl));
-  (void)compatibleTypes;
+  (SrcDecl != nullptr && DstDecl != nullptr &&
+   (SrcDecl->isDerivedFrom(DstDecl) || DstDecl->isDerivedFrom(SrcDecl)));
 
   LLVM_DEBUG({
 if (!compatibleTypes) {
@@ -35,45 +69,27 @@ void clang::dataflow::copyRecord(RecordStorageLocation &Src,
   });
   assert(compatibleTypes);
 
-  for (auto [Field, DstFieldLoc] : Dst.children()) {
-StorageLocation *SrcFieldLoc = Src.getChild(*Field);
-
-assert(Field->getType()->isReferenceType() ||
-   (SrcFieldLoc != nullptr && DstFieldLoc != nullptr));
-
-if (Field->getType()->isRecordType()) {
-  copyRecord(cast(*SrcFieldLoc),
- cast(*DstFieldLoc), Env);
-} else if (Field->getType()->isReferenceType()) {
-  Dst.setChild(*Field, SrcFieldLoc);
-} else {
-  if (Value *Val = Env.getValue(*SrcFieldLoc))
-Env.setValue(*DstFieldLoc, *Val);
-  else
-Env.clearValue(*DstFieldLoc);
-}
-  }
-
-  for (const aut

[clang] [clang][dataflow] Model assignment to derived class from base. (PR #85064)

2024-03-19 Thread via cfe-commits

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


[clang] [clang-tools-extra] [libcxx] [clang] Enable sized deallocation by default in C++14 onwards (PR #83774)

2024-03-19 Thread Wang Pengcheng via cfe-commits

https://github.com/wangpc-pp updated 
https://github.com/llvm/llvm-project/pull/83774

>From 26245679b0f40b510e628aaed091739e9931c29c Mon Sep 17 00:00:00 2001
From: wangpc 
Date: Fri, 14 Jul 2023 10:38:14 +0800
Subject: [PATCH 1/5] [clang] Enable sized deallocation by default in C++14
 onwards

Since C++14 has been released for about nine years and most standard
libraries have implemented sized deallocation functions, it's time to
make this feature default again.

Differential Revision: https://reviews.llvm.org/D112921
---
 .../clangd/unittests/FindTargetTests.cpp  |   4 +-
 .../checkers/misc/new-delete-overloads.cpp|  10 -
 clang/docs/ReleaseNotes.rst   |   4 +
 clang/include/clang/Basic/SizedDeallocation.h |  44 
 clang/include/clang/Driver/Options.td |   5 +-
 clang/lib/Driver/ToolChains/Clang.cpp |  13 +-
 clang/lib/Driver/ToolChains/Darwin.cpp|  41 ++-
 clang/lib/Driver/ToolChains/Darwin.h  |   4 +
 clang/lib/Driver/ToolChains/ZOS.cpp   |   6 +
 clang/test/AST/ast-dump-expr-json.cpp |   2 +-
 clang/test/AST/ast-dump-expr.cpp  |   2 +-
 clang/test/AST/ast-dump-stmt-json.cpp | 244 +-
 clang/test/Analysis/cxxnewexpr-callback.cpp   |   4 +-
 .../basic.stc.dynamic.deallocation/p2.cpp |   2 +-
 clang/test/CXX/drs/dr292.cpp  |   6 +-
 .../test/CXX/expr/expr.unary/expr.new/p14.cpp |   2 +-
 .../CodeGenCXX/cxx1y-sized-deallocation.cpp   |  10 +-
 .../CodeGenCXX/cxx1z-aligned-allocation.cpp   |   6 +-
 .../CodeGenCXX/cxx2a-destroying-delete.cpp|   4 +-
 clang/test/CodeGenCXX/delete-two-arg.cpp  |   4 +-
 clang/test/CodeGenCXX/delete.cpp  |  12 +-
 clang/test/CodeGenCXX/dllimport.cpp   |   4 +-
 clang/test/CodeGenCXX/new.cpp |   6 +-
 .../coro-aligned-alloc-2.cpp  |   2 -
 .../CodeGenCoroutines/coro-aligned-alloc.cpp  |   6 +-
 clang/test/CodeGenCoroutines/coro-alloc.cpp   |   6 +-
 clang/test/CodeGenCoroutines/coro-cleanup.cpp |   6 +-
 clang/test/CodeGenCoroutines/coro-dealloc.cpp |   2 -
 clang/test/CodeGenCoroutines/coro-gro.cpp |   3 +-
 clang/test/CodeGenCoroutines/pr56919.cpp  |   9 +-
 clang/test/Lexer/cxx-features.cpp |  20 +-
 clang/test/PCH/cxx1z-aligned-alloc.cpp|  10 +-
 clang/test/SemaCXX/MicrosoftExtensions.cpp|   8 +-
 .../SemaCXX/builtin-operator-new-delete.cpp   |   2 +-
 .../test/SemaCXX/cxx1y-sized-deallocation.cpp |   2 +-
 .../unavailable_aligned_allocation.cpp|  15 +-
 .../StaticAnalyzer/CallEventTest.cpp  |   2 +-
 clang/www/cxx_status.html |  11 +-
 .../support.dynamic/libcpp_deallocate.sh.cpp  |   3 +
 .../sized_delete_array14.pass.cpp |   8 +-
 .../new.delete.single/sized_delete14.pass.cpp |   8 +-
 41 files changed, 458 insertions(+), 104 deletions(-)
 create mode 100644 clang/include/clang/Basic/SizedDeallocation.h

diff --git a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp 
b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
index 0af6036734ba53..1b7b96281dfaa5 100644
--- a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -839,7 +839,9 @@ TEST_F(TargetDeclTest, OverloadExpr) {
   [[delete]] x;
 }
   )cpp";
-  EXPECT_DECLS("CXXDeleteExpr", "void operator delete(void *) noexcept");
+  // Sized deallocation is enabled by default in C++14 onwards.
+  EXPECT_DECLS("CXXDeleteExpr",
+   "void operator delete(void *, unsigned long) noexcept");
 }
 
 TEST_F(TargetDeclTest, DependentExprs) {
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc/new-delete-overloads.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc/new-delete-overloads.cpp
index 78f021144b2e19..f86fe8a4c5b14f 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc/new-delete-overloads.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/new-delete-overloads.cpp
@@ -12,16 +12,6 @@ struct S {
 // CHECK-MESSAGES: :[[@LINE+1]]:7: warning: declaration of 'operator new' has 
no matching declaration of 'operator delete' at the same scope
 void *operator new(size_t size) noexcept(false);
 
-struct T {
-  // Sized deallocations are not enabled by default, and so this new/delete 
pair
-  // does not match. However, we expect only one warning, for the new, because
-  // the operator delete is a placement delete and we do not warn on 
mismatching
-  // placement operations.
-  // CHECK-MESSAGES: :[[@LINE+1]]:9: warning: declaration of 'operator new' 
has no matching declaration of 'operator delete' at the same scope
-  void *operator new(size_t size) noexcept;
-  void operator delete(void *ptr, size_t) noexcept; // ok only if sized 
deallocation is enabled
-};
-
 struct U {
   void *operator new(size_t size) noexcept;
   void operator delete(void *ptr) noexcept;
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6f6ce7c6

[clang] [llvm] [AArch64] Add support for Cortex-A520AE and Cortex-A720AE CPUs (PR #85401)

2024-03-19 Thread David Green via cfe-commits

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

Thanks. LGTM

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


[clang] [clang-format] Add Options to break inside the TableGen DAGArg. (PR #83149)

2024-03-19 Thread Wang Pengcheng via cfe-commits

wangpc-pp wrote:

This breaks CI `Test documentation build` like: 
https://github.com/llvm/llvm-project/actions/runs/8339765845/job/22822367034

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


[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)

2024-03-19 Thread Sander de Smalen via cfe-commits


@@ -3717,6 +3717,16 @@ def err_sme_definition_using_za_in_non_sme_target : 
Error<
   "function using ZA state requires 'sme'">;
 def err_sme_definition_using_zt0_in_non_sme2_target : Error<
   "function using ZT0 state requires 'sme2'">;
+def warn_sme_streaming_pass_return_vl_to_non_streaming : Warning<
+  "passing a VL-dependent argument to/from a function that has a different"
+  " streaming-mode. The streaming and non-streaming vector lengths may be"
+  " different">,
+  InGroup, DefaultIgnore;
+def warn_sme_locally_streaming_has_vl_args_returns : Warning<
+  "passing/returning a VL-dependent argument from a function"
+  " arm_locally_streaming attribute. The streaming and non-streaming vector"

sdesmalen-arm wrote:

```suggestion
  "passing/returning a VL-dependent argument from a __arm_locally_streaming"
  " function. The streaming and non-streaming vector"
```

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


[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)

2024-03-19 Thread Sander de Smalen via cfe-commits

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


[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)

2024-03-19 Thread Sander de Smalen via cfe-commits

https://github.com/sdesmalen-arm commented:

Thanks for the update. I just left a few more suggestions to clean up the code 
a bit.

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


[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)

2024-03-19 Thread Sander de Smalen via cfe-commits


@@ -7513,6 +7516,30 @@ void Sema::checkCall(NamedDecl *FDecl, const 
FunctionProtoType *Proto,
   }
 }
 
+auto *CallerFD = dyn_cast(CurContext);
+bool IsCalleeStreaming =
+(ExtInfo.AArch64SMEAttributes & FunctionType::SME_PStateSMEnabledMask);
+bool IsCalleeStreamingCompatible =
+(ExtInfo.AArch64SMEAttributes &
+ FunctionType::SME_PStateSMCompatibleMask);
+bool IsBuiltin = (FD && FD->getBuiltinID());

sdesmalen-arm wrote:

nit: parentheses are unnecessary.
```suggestion
bool IsBuiltin = FD && FD->getBuiltinID();
```

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


[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)

2024-03-19 Thread Sander de Smalen via cfe-commits


@@ -7513,6 +7516,30 @@ void Sema::checkCall(NamedDecl *FDecl, const 
FunctionProtoType *Proto,
   }
 }
 
+auto *CallerFD = dyn_cast(CurContext);
+bool IsCalleeStreaming =
+(ExtInfo.AArch64SMEAttributes & FunctionType::SME_PStateSMEnabledMask);
+bool IsCalleeStreamingCompatible =
+(ExtInfo.AArch64SMEAttributes &
+ FunctionType::SME_PStateSMCompatibleMask);
+bool IsBuiltin = (FD && FD->getBuiltinID());
+AnyScalableArgsOrRet |= Proto->getReturnType()->isSizelessVectorType();
+
+// If the caller is a function and the callee has a different
+// non-compitable streaming attribute. If it passed any VL-based arguments
+// or return VL-based value, then warn that the streaming and non-streaming
+// vector lengths may be different.
+if (CallerFD && !IsBuiltin && AnyScalableArgsOrRet) {
+  ArmStreamingType CallerFnType = getArmStreamingFnType(CallerFD);
+  if ((CallerFnType != ArmStreaming &&
+   CallerFnType != ArmStreamingCompatible && IsCalleeStreaming) ||
+  (CallerFnType == ArmStreaming && !IsCalleeStreaming &&
+   !IsCalleeStreamingCompatible) ||
+  (CallerFnType == ArmStreamingCompatible &&
+   (IsCalleeStreaming || !IsCalleeStreamingCompatible)))

sdesmalen-arm wrote:

This can be simplified to:
```
if (!IsCalleeStreamingCompatible &&
(CallerFnType == ArmStreamingCompatible ||
 ((CallerFnType == ArmStreaming) ^ IsCalleeStreaming)))
```

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


[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)

2024-03-19 Thread Sander de Smalen via cfe-commits


@@ -7513,6 +7516,30 @@ void Sema::checkCall(NamedDecl *FDecl, const 
FunctionProtoType *Proto,
   }
 }
 
+auto *CallerFD = dyn_cast(CurContext);

sdesmalen-arm wrote:

nit: move this closer to its use, preferably wrap the condition, e.g.
```
  if (auto *CallerFD = dyn_cast<..>(..)) {
...
  }
```

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


[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)

2024-03-19 Thread Sander de Smalen via cfe-commits


@@ -7513,6 +7516,30 @@ void Sema::checkCall(NamedDecl *FDecl, const 
FunctionProtoType *Proto,
   }
 }
 
+auto *CallerFD = dyn_cast(CurContext);
+bool IsCalleeStreaming =
+(ExtInfo.AArch64SMEAttributes & FunctionType::SME_PStateSMEnabledMask);

sdesmalen-arm wrote:

nit: parentheses are unnecessary.
```suggestion
ExtInfo.AArch64SMEAttributes & FunctionType::SME_PStateSMEnabledMask;
```

Also, please move these closer to their use (inside the if blocks)

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


[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)

2024-03-19 Thread Sander de Smalen via cfe-commits


@@ -7513,6 +7516,30 @@ void Sema::checkCall(NamedDecl *FDecl, const 
FunctionProtoType *Proto,
   }
 }
 
+auto *CallerFD = dyn_cast(CurContext);
+bool IsCalleeStreaming =
+(ExtInfo.AArch64SMEAttributes & FunctionType::SME_PStateSMEnabledMask);
+bool IsCalleeStreamingCompatible =
+(ExtInfo.AArch64SMEAttributes &
+ FunctionType::SME_PStateSMCompatibleMask);

sdesmalen-arm wrote:

nit: parentheses are unnecessary.
```suggestion
bool IsCalleeStreamingCompatible =
ExtInfo.AArch64SMEAttributes &
 FunctionType::SME_PStateSMCompatibleMask;
```

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


[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)

2024-03-19 Thread Sander de Smalen via cfe-commits


@@ -7513,6 +7516,30 @@ void Sema::checkCall(NamedDecl *FDecl, const 
FunctionProtoType *Proto,
   }
 }
 
+auto *CallerFD = dyn_cast(CurContext);
+bool IsCalleeStreaming =
+(ExtInfo.AArch64SMEAttributes & FunctionType::SME_PStateSMEnabledMask);
+bool IsCalleeStreamingCompatible =
+(ExtInfo.AArch64SMEAttributes &
+ FunctionType::SME_PStateSMCompatibleMask);
+bool IsBuiltin = (FD && FD->getBuiltinID());
+AnyScalableArgsOrRet |= Proto->getReturnType()->isSizelessVectorType();
+
+// If the caller is a function and the callee has a different
+// non-compitable streaming attribute. If it passed any VL-based arguments
+// or return VL-based value, then warn that the streaming and non-streaming
+// vector lengths may be different.

sdesmalen-arm wrote:

This comment reads a bit strange. What about:

```
// If the call requires a streaming-mode change and has scalable vector
// arguments or return values, then warn the user that the streaming and
// non-streaming vector lengths may be different.
```

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


[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)

2024-03-19 Thread Sander de Smalen via cfe-commits


@@ -7513,6 +7516,30 @@ void Sema::checkCall(NamedDecl *FDecl, const 
FunctionProtoType *Proto,
   }
 }
 
+auto *CallerFD = dyn_cast(CurContext);
+bool IsCalleeStreaming =
+(ExtInfo.AArch64SMEAttributes & FunctionType::SME_PStateSMEnabledMask);
+bool IsCalleeStreamingCompatible =
+(ExtInfo.AArch64SMEAttributes &
+ FunctionType::SME_PStateSMCompatibleMask);
+bool IsBuiltin = (FD && FD->getBuiltinID());
+AnyScalableArgsOrRet |= Proto->getReturnType()->isSizelessVectorType();

sdesmalen-arm wrote:

Why not initialise the variable with 
`Proto->getReturnType()->isSizelessVectorType()` and then remove this separate 
`|=` statement?

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


[clang] [dataflow] CXXForRangeStmt should extend flow condition (PR #80989)

2024-03-19 Thread via cfe-commits


@@ -1710,4 +1710,25 @@ TEST_F(TopTest, ForRangeStmtConverges) {
 // analysis converged.
   });
 }
+
+TEST_F(TopTest, ForRangeStmtHasFlowCondition) {
+  std::string Code = R"(
+#include 
+void target(bool Foo) {
+  std::array t;
+  for (auto& i : t) {
+(void)0;
+/*[[p1]]*/
+  }
+}

martinboehme wrote:

```suggestion
#include 
void target() {
  for (auto& i : {1, 2}) {
(void)0;
/*[[p1]]*/
  }
}
```

Try to keep code snippets as simple as possible:

*  I don't think `Foo` is needed here?
*  An `initializer_list` is probably the simplest thing you can use to iterate 
over (it doesn't matter specifically what you're iterating over, right?)

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


[clang] [dataflow] CXXForRangeStmt should extend flow condition (PR #80989)

2024-03-19 Thread via cfe-commits


@@ -1710,4 +1710,25 @@ TEST_F(TopTest, ForRangeStmtConverges) {
 // analysis converged.
   });
 }
+
+TEST_F(TopTest, ForRangeStmtHasFlowCondition) {
+  std::string Code = R"(
+#include 
+void target(bool Foo) {
+  std::array t;
+  for (auto& i : t) {
+(void)0;
+/*[[p1]]*/
+  }
+}
+  )";
+  runDataflow(Code,
+  [](const llvm::StringMap> 
&Results,
+ const AnalysisOutputs &AO) {
+  ASSERT_THAT(Results.keys(), UnorderedElementsAre("p1"));
+  const Environment &Env1 = 
getEnvironmentAtAnnotation(Results, "p1");
+  
ASSERT_TRUE(Env1.proves(Env1.arena().makeAtomRef(Env1.getFlowConditionToken(;
+  });
+}

martinboehme wrote:

See comments above -- I'm not sure that the test, if it fails, means that we 
need a flow condition for the range-based for. (User code will never be able to 
"observe" this flow condition, so I'm not sure why we need it.)

I still don't understand what the underlying purpose is that you need this flow 
condition for in the iterator check. Can you expand? (I want to make sure we're 
not dealing with an [XY problem](https://en.wikipedia.org/wiki/XY_problem).)

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


[clang] [dataflow] CXXForRangeStmt should extend flow condition (PR #80989)

2024-03-19 Thread via cfe-commits


@@ -1710,4 +1710,25 @@ TEST_F(TopTest, ForRangeStmtConverges) {
 // analysis converged.
   });
 }
+
+TEST_F(TopTest, ForRangeStmtHasFlowCondition) {
+  std::string Code = R"(
+#include 
+void target(bool Foo) {
+  std::array t;
+  for (auto& i : t) {
+(void)0;
+/*[[p1]]*/
+  }
+}
+  )";
+  runDataflow(Code,
+  [](const llvm::StringMap> 
&Results,
+ const AnalysisOutputs &AO) {
+  ASSERT_THAT(Results.keys(), UnorderedElementsAre("p1"));
+  const Environment &Env1 = 
getEnvironmentAtAnnotation(Results, "p1");
+  
ASSERT_TRUE(Env1.proves(Env1.arena().makeAtomRef(Env1.getFlowConditionToken(;

martinboehme wrote:

```suggestion
  
EXPECT_TRUE(Env1.proves(Env1.arena().makeAtomRef(Env1.getFlowConditionToken(;
```

`ASSERT_` aborts the test if the check fails and should generally only be used 
if it's not meaningful to execute the rest of the test in this case. Otherwise, 
use `EXPECT_` so that you can continue executing the rest of the test.

It obviously doesn't make a difference in this case, but a) it's good style to 
default to `EXPECT_` anyway, and b) people might add more checks later, and 
they might forget to change the `ASSERT_` to an `EXPECT_`.

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


[clang] [dataflow] CXXForRangeStmt should extend flow condition (PR #80989)

2024-03-19 Thread via cfe-commits


@@ -1710,4 +1710,25 @@ TEST_F(TopTest, ForRangeStmtConverges) {
 // analysis converged.
   });
 }
+
+TEST_F(TopTest, ForRangeStmtHasFlowCondition) {
+  std::string Code = R"(
+#include 
+void target(bool Foo) {
+  std::array t;
+  for (auto& i : t) {
+(void)0;
+/*[[p1]]*/
+  }
+}
+  )";
+  runDataflow(Code,
+  [](const llvm::StringMap> 
&Results,
+ const AnalysisOutputs &AO) {
+  ASSERT_THAT(Results.keys(), UnorderedElementsAre("p1"));
+  const Environment &Env1 = 
getEnvironmentAtAnnotation(Results, "p1");
+  
ASSERT_TRUE(Env1.proves(Env1.arena().makeAtomRef(Env1.getFlowConditionToken(;
+  });

martinboehme wrote:

Does this fail without the other changes in this PR?

If it does, this looks to me more like a bug in `DataflowEnvironment`; this 
assertion should generally be true for _any_ environment, whether or not we 
extended the flow condition. (In that sense, the name of the test isn't 
accurate, because we would expect this to pass even if the flow condition was 
not extended.)

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


[clang] [dataflow] CXXForRangeStmt should extend flow condition (PR #80989)

2024-03-19 Thread via cfe-commits


@@ -1710,4 +1710,25 @@ TEST_F(TopTest, ForRangeStmtConverges) {
 // analysis converged.
   });
 }
+
+TEST_F(TopTest, ForRangeStmtHasFlowCondition) {
+  std::string Code = R"(
+#include 
+void target(bool Foo) {
+  std::array t;
+  for (auto& i : t) {
+(void)0;
+/*[[p1]]*/
+  }
+}
+  )";
+  runDataflow(Code,
+  [](const llvm::StringMap> 
&Results,
+ const AnalysisOutputs &AO) {
+  ASSERT_THAT(Results.keys(), UnorderedElementsAre("p1"));
+  const Environment &Env1 = 
getEnvironmentAtAnnotation(Results, "p1");

martinboehme wrote:

```suggestion
  const Environment &Env = getEnvironmentAtAnnotation(Results, 
"p");
```

*  A lot of tests still do the `ASSERT_THAT(Results.keys(), 
UnorderedElementsAre(...));`, but it's unnecessary -- 
`getEnvironmentAtAnnotation()` itself asserts that the annotation exists.

*  When there is only one environment you want to query, the usual names are 
`Env` and `p` (will need to be changed in the code snippet too, obviously).

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


[clang] [dataflow] CXXForRangeStmt should extend flow condition (PR #80989)

2024-03-19 Thread via cfe-commits

martinboehme wrote:

Note code formatting failure in CI. (Use `git clang-format` to fix.)

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


[clang] [analyzer] Fix false double free when including 3rd-party headers with overloaded delete operator as system headers (PR #85224)

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


@@ -1090,7 +1090,8 @@ static bool isStandardNewDelete(const FunctionDecl *FD) {
   // If the header for operator delete is not included, it's still defined
   // in an invalid source location. Check to make sure we don't crash.
   return !L.isValid() ||
- FD->getASTContext().getSourceManager().isInSystemHeader(L);
+ (!FD->hasBody() && // FIXME: Still a false alarm after CTU inlining.
+  FD->getASTContext().getSourceManager().isInSystemHeader(L));

balazske wrote:

Is it possible to move the check into `checkPostCall`? Then this situation can 
not happen.

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


[clang] [clang] Add `intrin0.h` header to mimic `intrin0.h` used by MSVC STL for clang-cl (PR #75711)

2024-03-19 Thread Benjamin Buch via cfe-commits

bebuch wrote:

@AaronBallman Can you merge this please? We are eagerly waiting for this to end 
up in a release! ;-)

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


[clang] 6aaf9c8 - [clang][Interp][NFC] Sanitize collectBaseOffset parameters

2024-03-19 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-03-19T10:07:23+01:00
New Revision: 6aaf9c83099b80e73ef2208ae9f7f300c7808659

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

LOG: [clang][Interp][NFC] Sanitize collectBaseOffset parameters

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index af214d4a8577c6..73831eefba4568 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -3337,6 +3337,8 @@ template 
 unsigned
 ByteCodeExprGen::collectBaseOffset(const RecordType *BaseType,
 const RecordType *DerivedType) {
+  assert(BaseType);
+  assert(DerivedType);
   const auto *FinalDecl = cast(BaseType->getDecl());
   const RecordDecl *CurDecl = DerivedType->getDecl();
   const Record *CurRecord = getRecord(CurDecl);



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


[clang-tools-extra] [clangd] Handle variables templates consistently with class templates in code completion (PR #85740)

2024-03-19 Thread Haojian Wu via cfe-commits

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


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


[clang] [flang] [flang] Enable polymorphic lowering by default (PR #83285)

2024-03-19 Thread via cfe-commits

https://github.com/jeanPerier updated 
https://github.com/llvm/llvm-project/pull/83285

>From 6944f908d5ce82871323816bc247fcb7e765531f Mon Sep 17 00:00:00 2001
From: Jean Perier 
Date: Wed, 28 Feb 2024 06:17:11 -0800
Subject: [PATCH] [flang] Enable polymorphic lowering by default

Polymorphic entity lowering status is good. There main remaining TODO
is to allow lowering of vector subscripted polymorphic entity.

Remove experimental option and enable lowering of polymorphic
entity by default.
---
 clang/include/clang/Driver/Options.td  |  5 -
 clang/lib/Driver/ToolChains/Flang.cpp  |  1 -
 flang/include/flang/Lower/LoweringOptions.def  |  3 ---
 flang/lib/Frontend/CompilerInvocation.cpp  |  5 -
 flang/lib/Lower/CallInterface.cpp  |  6 --
 flang/lib/Lower/ConvertType.cpp|  4 
 flang/test/Driver/driver-help-hidden.f90   |  2 --
 .../Driver/flang-experimental-polymorphism-flag.f90| 10 --
 flang/test/Driver/frontend-forwarding.f90  |  2 --
 flang/test/Fir/dispatch.f90|  4 ++--
 flang/test/HLFIR/assumed-type-actual-args.f90  |  2 +-
 flang/test/HLFIR/boxchar_emboxing.f90  |  2 +-
 flang/test/HLFIR/call_with_poly_dummy.f90  |  2 +-
 .../Lower/HLFIR/actual_target_for_dummy_pointer.f90|  2 +-
 flang/test/Lower/HLFIR/allocatable-return.f90  |  2 +-
 flang/test/Lower/HLFIR/array-ctor-derived.f90  |  2 +-
 flang/test/Lower/HLFIR/calls-assumed-shape.f90 |  2 +-
 .../HLFIR/calls-constant-expr-arg-polymorphic.f90  |  2 +-
 flang/test/Lower/HLFIR/calls-optional.f90  |  2 +-
 flang/test/Lower/HLFIR/calls-poly-to-assumed-type.f90  |  2 +-
 flang/test/Lower/HLFIR/convert-mbox-to-value.f90   |  2 +-
 flang/test/Lower/HLFIR/designators-component-ref.f90   |  2 +-
 .../Lower/HLFIR/designators-parameter-array-slice.f90  |  2 +-
 flang/test/Lower/HLFIR/elemental-array-ops.f90 |  2 +-
 flang/test/Lower/HLFIR/elemental-polymorphic-merge.f90 |  2 +-
 .../HLFIR/elemental-user-procedure-ref-polymorphic.f90 |  2 +-
 flang/test/Lower/HLFIR/function-return-as-expr.f90 |  2 +-
 flang/test/Lower/HLFIR/function-return-destroy.f90 |  2 +-
 .../Lower/HLFIR/ignore-rank-unlimited-polymorphic.f90  |  2 +-
 flang/test/Lower/HLFIR/ignore-type-assumed-shape.f90   |  2 +-
 .../Lower/HLFIR/intentout-allocatable-components.f90   |  2 +-
 .../Lower/HLFIR/internal-procedures-polymorphic.f90|  2 +-
 flang/test/Lower/HLFIR/intrinsic-assumed-type.f90  |  2 +-
 flang/test/Lower/HLFIR/parent-component-ref.f90|  2 +-
 flang/test/Lower/HLFIR/poly_expr_for_nonpoly_dummy.f90 |  2 +-
 flang/test/Lower/HLFIR/polymorphic-expressions.f90 |  2 +-
 flang/test/Lower/HLFIR/proc-pointer-comp-nopass.f90|  2 +-
 flang/test/Lower/HLFIR/proc-pointer-comp-pass.f90  |  2 +-
 flang/test/Lower/HLFIR/select-type-selector.f90|  2 +-
 flang/test/Lower/HLFIR/transpose.f90   |  2 +-
 flang/test/Lower/HLFIR/type-bound-call-mismatch.f90|  2 +-
 flang/test/Lower/HLFIR/vector-subscript-as-value.f90   |  2 +-
 flang/test/Lower/Intrinsics/extends_type_of.f90|  2 +-
 flang/test/Lower/Intrinsics/same_type_as.f90   |  2 +-
 flang/test/Lower/Intrinsics/sizeof.f90 |  2 +-
 flang/test/Lower/Intrinsics/spread.f90 |  2 +-
 flang/test/Lower/Intrinsics/storage_size.f90   |  2 +-
 flang/test/Lower/allocatable-polymorphic.f90   |  4 ++--
 flang/test/Lower/allocatable-return.f90|  2 +-
 flang/test/Lower/assumed-type.f90  |  2 +-
 flang/test/Lower/default-initialization.f90|  2 +-
 flang/test/Lower/derived-type-finalization.f90 |  2 +-
 flang/test/Lower/dispatch-table.f90|  2 +-
 flang/test/Lower/dispatch.f90  |  2 +-
 flang/test/Lower/intentout-deallocate.f90  |  4 ++--
 flang/test/Lower/io-derived-type-2.f90 |  2 +-
 flang/test/Lower/io-derived-type.f90   |  2 +-
 flang/test/Lower/nullify-polymorphic.f90   |  2 +-
 flang/test/Lower/pass-null-for-class-arg.f90   |  4 ++--
 flang/test/Lower/pointer-association-polymorphic.f90   |  2 +-
 flang/test/Lower/pointer-disassociate.f90  |  2 +-
 flang/test/Lower/polymorphic-temp.f90  |  2 +-
 flang/test/Lower/polymorphic-types.f90 |  2 +-
 flang/test/Lower/polymorphic.f90   |  2 +-
 flang/test/Lower/select-type-2.f90 |  2 +-
 flang/test/Lower/select-type.f90   |  4 ++--
 flang/tools/bbc/bbc.cpp|  6 --
 67 files changed, 62 insertions(+), 106 deletions(-)
 delete mode 100644 flang/test/Driver/flang-experimental-polymorphism-flag.f90

diff --git a/clang/include/clang/Driver/O

[clang] [clang][NFC] Add documentation for `CastExpr::path()`. (PR #85623)

2024-03-19 Thread Timm Baeder via cfe-commits

tbaederr wrote:

Does this actually show up at the right place? Or is it now the documentation 
for `path_empty()`? Or  even `path_iterator`?

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


[clang] [clang][dataflow] Make optional checker work for types derived from optional. (PR #84138)

2024-03-19 Thread via cfe-commits

https://github.com/martinboehme updated 
https://github.com/llvm/llvm-project/pull/84138

>From 209aac483514f6d041486f36e6dabec78598fcec Mon Sep 17 00:00:00 2001
From: Martin Braenne 
Date: Tue, 12 Mar 2024 15:56:41 +
Subject: [PATCH 1/3] [clang][dataflow] Make optional checker work for types
 derived from optional.

`llvm::MaybeAlign` does this, for example.

It's not an option to simply ignore these derived classes because they get cast
back to the optional classes (for example, simply when calling the optional
member functions), and our transfer functions will then run on those optional
classes and therefore require them to be properly initialized.
---
 .../Models/UncheckedOptionalAccessModel.cpp   | 174 +-
 .../UncheckedOptionalAccessModelTest.cpp  |  60 ++
 2 files changed, 183 insertions(+), 51 deletions(-)

diff --git 
a/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp 
b/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
index 1d31b22b6d25ff..90b4b7d04187df 100644
--- a/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
@@ -64,39 +64,117 @@ static bool hasOptionalClassName(const CXXRecordDecl &RD) {
   return false;
 }
 
+static const CXXRecordDecl *getOptionalBaseClass(const CXXRecordDecl *RD) {
+  if (RD == nullptr)
+return nullptr;
+  if (hasOptionalClassName(*RD))
+return RD;
+
+  if (!RD->hasDefinition())
+return nullptr;
+
+  for (const CXXBaseSpecifier &Base : RD->bases())
+if (const CXXRecordDecl *BaseClass =
+getOptionalBaseClass(Base.getType()->getAsCXXRecordDecl()))
+  return BaseClass;
+
+  return nullptr;
+}
+
 namespace {
 
 using namespace ::clang::ast_matchers;
 using LatticeTransferState = TransferState;
 
-AST_MATCHER(CXXRecordDecl, hasOptionalClassNameMatcher) {
-  return hasOptionalClassName(Node);
+AST_MATCHER(CXXRecordDecl, optionalClass) { return hasOptionalClassName(Node); 
}
+
+AST_MATCHER(CXXRecordDecl, optionalOrDerivedClass) {
+  return getOptionalBaseClass(&Node) != nullptr;
 }
 
-DeclarationMatcher optionalClass() {
-  return classTemplateSpecializationDecl(
-  hasOptionalClassNameMatcher(),
-  hasTemplateArgument(0, refersToType(type().bind("T";
+auto desugarsToOptionalType() {
+  return hasUnqualifiedDesugaredType(
+  recordType(hasDeclaration(cxxRecordDecl(optionalClass();
 }
 
-auto optionalOrAliasType() {
+auto desugarsToOptionalOrDerivedType() {
   return hasUnqualifiedDesugaredType(
-  recordType(hasDeclaration(optionalClass(;
+  recordType(hasDeclaration(cxxRecordDecl(optionalOrDerivedClass();
 }
 
-/// Matches any of the spellings of the optional types and sugar, aliases, etc.
-auto hasOptionalType() { return hasType(optionalOrAliasType()); }
+auto hasOptionalType() { return hasType(desugarsToOptionalType()); }
+
+/// Matches any of the spellings of the optional types and sugar, aliases,
+/// derived classes, etc.
+auto hasOptionalOrDerivedType() {
+  return hasType(desugarsToOptionalOrDerivedType());
+}
+
+QualType getPublicType(const Expr *E) {
+  auto *Cast = dyn_cast(E->IgnoreParens());
+  if (Cast == nullptr || Cast->getCastKind() != CK_UncheckedDerivedToBase) {
+QualType Ty = E->getType();
+if (Ty->isPointerType())
+  return Ty->getPointeeType();
+return Ty;
+  }
+
+  QualType Ty = getPublicType(Cast->getSubExpr());
+
+  // Is `Ty` the type of `*this`? In this special case, we can upcast to the
+  // base class even if the base is non-public.
+  bool TyIsThisType = isa(Cast->getSubExpr());
+
+  for (const CXXBaseSpecifier *Base : Cast->path()) {
+if (Base->getAccessSpecifier() != AS_public && !TyIsThisType)
+  break;
+Ty = Base->getType();
+TyIsThisType = false;
+  }
+
+  return Ty;
+}
+
+// Returns the least-derived type for the receiver of `MCE` that
+// `MCE.getImplicitObjectArgument()->IgnoreParentImpCasts()` can be downcast 
to.
+// Effectively, we upcast until we reach a non-public base class, unless that
+// base is a base of `*this`.
+//
+// This is needed to correctly match methods called on types derived from
+// `std::optional`.
+//
+// Say we have a `struct Derived : public std::optional {} d;` For a call
+// `d.has_value()`, the `getImplicitObjectArgument()` looks like this:
+//
+//   ImplicitCastExpr 'const std::__optional_storage_base' lvalue
+//   | 
__optional_storage_base)>
+//   `-DeclRefExpr 'Derived' lvalue Var 'd' 'Derived'
+//
+// The type of the implicit object argument is `__optional_storage_base`
+// (since this is the internal type that `has_value()` is declared on). If we
+// call `IgnoreParenImpCasts()` on the implicit object argument, we get the
+// `DeclRefExpr`, which has type `Derived`. Neither of these types is
+// `optional`, and hence neither is sufficient for querying whether we are
+// calling a method on `optional`.
+//
+// Instead, 

[clang] [clang][dataflow] Make optional checker work for types derived from optional. (PR #84138)

2024-03-19 Thread via cfe-commits


@@ -119,20 +119,28 @@ QualType getPublicType(const Expr *E) {
 return Ty;
   }
 
-  QualType Ty = getPublicType(Cast->getSubExpr());
-
-  // Is `Ty` the type of `*this`? In this special case, we can upcast to the
-  // base class even if the base is non-public.
-  bool TyIsThisType = isa(Cast->getSubExpr());
-
+  // Is the derived type that we're casting from the type of `*this`? In this
+  // special case, we can upcast to the base class even if the base is
+  // non-public.
+  bool CastingFromThis = isa(Cast->getSubExpr());
+
+  // Find the least-derived type in the path (i.e. the last entry in the list)
+  // that we can access.
+  QualType Ty;
   for (const CXXBaseSpecifier *Base : Cast->path()) {
-if (Base->getAccessSpecifier() != AS_public && !TyIsThisType)
+if (Base->getAccessSpecifier() != AS_public && !CastingFromThis)
   break;
 Ty = Base->getType();

martinboehme wrote:

Done.

More importantly than the minor efficiency gain, I think this makes the code 
more self-documenting. Thanks!

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


[clang] [clang][dataflow] Make optional checker work for types derived from optional. (PR #84138)

2024-03-19 Thread via cfe-commits


@@ -129,19 +215,19 @@ auto inPlaceClass() {
 
 auto isOptionalNulloptConstructor() {
   return cxxConstructExpr(
-  hasOptionalType(),
+  hasOptionalOrDerivedType(),

martinboehme wrote:

Done.

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


[clang] 0d40de7 - [clang][Interp][NFC] Add InterpFrame::dump()

2024-03-19 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-03-19T10:25:21+01:00
New Revision: 0d40de754a8fc34e606d0a83902f950606f42385

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

LOG: [clang][Interp][NFC] Add InterpFrame::dump()

Added: 


Modified: 
clang/lib/AST/Interp/Disasm.cpp
clang/lib/AST/Interp/InterpFrame.h

Removed: 




diff  --git a/clang/lib/AST/Interp/Disasm.cpp b/clang/lib/AST/Interp/Disasm.cpp
index 390d79d44b0a74..01ef1c24744a58 100644
--- a/clang/lib/AST/Interp/Disasm.cpp
+++ b/clang/lib/AST/Interp/Disasm.cpp
@@ -16,6 +16,7 @@
 #include "FunctionPointer.h"
 #include "Integral.h"
 #include "IntegralAP.h"
+#include "InterpFrame.h"
 #include "Opcode.h"
 #include "PrimType.h"
 #include "Program.h"
@@ -206,3 +207,29 @@ LLVM_DUMP_METHOD void Descriptor::dump(llvm::raw_ostream 
&OS) const {
   if (isDummy())
 OS << " dummy";
 }
+
+LLVM_DUMP_METHOD void InterpFrame::dump(llvm::raw_ostream &OS,
+unsigned Indent) const {
+  unsigned Spaces = Indent * 2;
+  {
+ColorScope SC(OS, true, {llvm::raw_ostream::BLUE, true});
+OS.indent(Spaces);
+if (getCallee())
+  describe(OS);
+else
+  OS << "Frame (Depth: " << getDepth() << ")";
+OS << "\n";
+  }
+  OS.indent(Spaces) << "Function: " << getFunction();
+  if (const Function *F = getFunction()) {
+OS << " (" << F->getName() << ")";
+  }
+  OS << "\n";
+  OS.indent(Spaces) << "This: " << getThis() << "\n";
+  OS.indent(Spaces) << "RVO: " << getRVOPtr() << "\n";
+
+  while (const InterpFrame *F = this->Caller) {
+F->dump(OS, Indent + 1);
+F = F->Caller;
+  }
+}

diff  --git a/clang/lib/AST/Interp/InterpFrame.h 
b/clang/lib/AST/Interp/InterpFrame.h
index 322d5dcfa698ae..1f80a0a5d2c492 100644
--- a/clang/lib/AST/Interp/InterpFrame.h
+++ b/clang/lib/AST/Interp/InterpFrame.h
@@ -123,6 +123,9 @@ class InterpFrame final : public Frame {
 
   unsigned getDepth() const { return Depth; }
 
+  void dump() const { dump(llvm::errs(), 0); }
+  void dump(llvm::raw_ostream &OS, unsigned Indent = 0) const;
+
 private:
   /// Returns an original argument from the stack.
   template  const T &stackRef(unsigned Offset) const {



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


[clang] [codegen] Emit cleanups for branch in stmt-expr and coro suspensions [take-2] (PR #85398)

2024-03-19 Thread Utkarsh Saxena via cfe-commits

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


[clang] [clang-tools-extra] [clang-tidy][dataflow] Add `bugprone-null-check-after-dereference` check (PR #84166)

2024-03-19 Thread via cfe-commits


@@ -0,0 +1,171 @@
+//===--- NullCheckAfterDereferenceCheck.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 "NullCheckAfterDereferenceCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/DeclTemplate.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Analysis/CFG.h"
+#include "clang/Analysis/FlowSensitive/ControlFlowContext.h"
+#include "clang/Analysis/FlowSensitive/DataflowAnalysisContext.h"
+#include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
+#include "clang/Analysis/FlowSensitive/DataflowLattice.h"
+#include "clang/Analysis/FlowSensitive/Models/NullPointerAnalysisModel.h"
+#include "clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h"
+#include "clang/Basic/SourceLocation.h"
+#include "llvm/ADT/Any.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/Support/Error.h"
+#include 
+#include 
+
+namespace clang::tidy::bugprone {
+
+using ast_matchers::MatchFinder;
+using dataflow::NullCheckAfterDereferenceDiagnoser;
+using dataflow::NullPointerAnalysisModel;
+
+static constexpr llvm::StringLiteral FuncID("fun");
+
+struct ExpandedResult {
+  SourceLocation WarningLoc;
+  std::optional DerefLoc;
+};
+
+using ExpandedResultType =
+std::pair, std::vector>;
+
+static std::optional
+analyzeFunction(const FunctionDecl &FuncDecl) {
+  using dataflow::ControlFlowContext;
+  using dataflow::DataflowAnalysisState;
+  using llvm::Expected;
+
+  ASTContext &ASTCtx = FuncDecl.getASTContext();
+
+  if (FuncDecl.getBody() == nullptr) {
+return std::nullopt;
+  }
+
+  Expected Context =
+  ControlFlowContext::build(FuncDecl, *FuncDecl.getBody(), ASTCtx);
+  if (!Context)
+return std::nullopt;
+
+  dataflow::DataflowAnalysisContext AnalysisContext(
+  std::make_unique());
+  dataflow::Environment Env(AnalysisContext, FuncDecl);
+  NullPointerAnalysisModel Analysis(ASTCtx);
+  NullCheckAfterDereferenceDiagnoser Diagnoser;
+  NullCheckAfterDereferenceDiagnoser::ResultType Diagnostics;
+
+  using LatticeState = 
DataflowAnalysisState;
+  using DetailMaybeLatticeStates = std::vector>;
+
+  auto DiagnoserImpl = [&ASTCtx, &Diagnoser,
+&Diagnostics](const CFGElement &Elt,
+  const LatticeState &S) mutable -> void {
+auto EltDiagnostics = Diagnoser.diagnose(ASTCtx, &Elt, S.Env);
+llvm::move(EltDiagnostics.first, std::back_inserter(Diagnostics.first));
+llvm::move(EltDiagnostics.second, std::back_inserter(Diagnostics.second));
+  };
+
+  Expected BlockToOutputState =
+  dataflow::runDataflowAnalysis(*Context, Analysis, Env, DiagnoserImpl);
+
+  if (llvm::Error E = BlockToOutputState.takeError()) {
+llvm::dbgs() << "Dataflow analysis failed: " << 
llvm::toString(std::move(E))
+ << ".\n";
+return std::nullopt;
+  }
+
+  ExpandedResultType ExpandedDiagnostics;
+
+  llvm::transform(Diagnostics.first,
+  std::back_inserter(ExpandedDiagnostics.first),
+  [&](SourceLocation WarningLoc) -> ExpandedResult {
+if (auto Val = Diagnoser.WarningLocToVal[WarningLoc];
+auto DerefExpr = Diagnoser.ValToDerefLoc[Val]) {
+  return {WarningLoc, DerefExpr->getBeginLoc()};
+}
+
+return {WarningLoc, std::nullopt};
+  });
+
+  llvm::transform(Diagnostics.second,
+  std::back_inserter(ExpandedDiagnostics.second),
+  [&](SourceLocation WarningLoc) -> ExpandedResult {
+if (auto Val = Diagnoser.WarningLocToVal[WarningLoc];
+auto DerefExpr = Diagnoser.ValToDerefLoc[Val]) {
+  return {WarningLoc, DerefExpr->getBeginLoc()};
+}
+
+return {WarningLoc, std::nullopt};
+  });
+
+  return ExpandedDiagnostics;
+}
+
+void NullCheckAfterDereferenceCheck::registerMatchers(MatchFinder *Finder) {
+  using namespace ast_matchers;
+
+  auto hasPointerValue =
+  hasDescendant(NullPointerAnalysisModel::ptrValueMatcher());

martinboehme wrote:

That link to the implementation doesn't work for me, and I still can't find the 
implementation by searching the diff. (When I asked where it's "defined", I 
specifically meant the implementation; the mention of the function in the 
header file is a declaration.)

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


[clang] [clang-tools-extra] [clang-tidy][dataflow] Add `bugprone-null-check-after-dereference` check (PR #84166)

2024-03-19 Thread via cfe-commits

martinboehme wrote:

Some general comments:

*  Is this ready for the next round of review? I see you've pushed a change, 
but you remark in other comments that there are still changes left to do. Can 
you let us know when this is ready for review again?

*  When updating the PR, can you [use fixups instead of 
force-pushing](https://llvm.org/docs/GitHub.html#updating-pull-requests)? This 
makes it easier to see what you've changed.

*  This PR has a _lot_ of reviewers on it. I'd suggest keeping the ones who 
have made comments so far and removing the others. (They can always re-add 
themselves if they want to, but a PR shouldn't generally need this many 
reviewers.)

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


[clang] [clang-tools-extra] [clang-tidy][dataflow] Add `bugprone-null-check-after-dereference` check (PR #84166)

2024-03-19 Thread via cfe-commits

martinboehme wrote:

PS

*  Tests appear to be failing.

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


[clang] [clang-tools-extra] [clang-tidy][dataflow] Add `bugprone-null-check-after-dereference` check (PR #84166)

2024-03-19 Thread via cfe-commits


@@ -0,0 +1,625 @@
+//===-- NullPointerAnalysisModel.cpp *- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file defines a generic null-pointer analysis model, used for finding
+// pointer null-checks after the pointer has already been dereferenced.
+//
+// Only a limited set of operations are currently recognized. Notably, pointer
+// arithmetic, null-pointer assignments and _nullable/_nonnull attributes are
+// missing as of yet.
+//
+//===--===//
+
+#include "clang/Analysis/FlowSensitive/Models/NullPointerAnalysisModel.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Stmt.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Analysis/CFG.h"
+#include "clang/Analysis/FlowSensitive/CFGMatchSwitch.h"
+#include "clang/Analysis/FlowSensitive/DataflowAnalysis.h"
+#include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
+#include "clang/Analysis/FlowSensitive/DataflowLattice.h"
+#include "clang/Analysis/FlowSensitive/MapLattice.h"
+#include "clang/Analysis/FlowSensitive/NoopLattice.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/Twine.h"
+
+namespace clang::dataflow {
+
+namespace {
+using namespace ast_matchers;
+
+constexpr char kCond[] = "condition";
+constexpr char kVar[] = "var";
+constexpr char kValue[] = "value";
+constexpr char kIsNonnull[] = "is-nonnull";
+constexpr char kIsNull[] = "is-null";
+
+enum class SatisfiabilityResult {
+  // Returned when the value was not initialized yet.
+  Nullptr,
+  // Special value that signals that the boolean value can be anything.
+  // It signals that the underlying formulas are too complex to be calculated
+  // efficiently.
+  Top,
+  // Equivalent to the literal True in the current environment.
+  True,
+  // Equivalent to the literal False in the current environment.
+  False,
+  // Both True and False values could be produced with an appropriate set of
+  // conditions.
+  Unknown
+};
+
+using SR = SatisfiabilityResult;
+
+// FIXME: These AST matchers should also be exported via the
+// NullPointerAnalysisModel class, for tests
+auto ptrToVar(llvm::StringRef VarName = kVar) {
+  return traverse(TK_IgnoreUnlessSpelledInSource,
+  declRefExpr(hasType(isAnyPointer())).bind(VarName));
+}
+
+auto derefMatcher() {
+  return traverse(
+  TK_IgnoreUnlessSpelledInSource,
+  unaryOperator(hasOperatorName("*"), hasUnaryOperand(ptrToVar(;
+}
+
+auto arrowMatcher() {
+  return traverse(
+  TK_IgnoreUnlessSpelledInSource,
+  memberExpr(allOf(isArrow(), hasObjectExpression(ptrToVar();
+}
+
+auto castExprMatcher() {
+  return castExpr(hasCastKind(CK_PointerToBoolean),
+  hasSourceExpression(ptrToVar()))

martinboehme wrote:

> I was afraid that a more complex argument would run into issues with being 
> rvalue vs lvalue, and the differences between the two had me crash the 
> framework a couple times before.

If this is causing issues for you and you're not clear on why, let me know -- 
happy to go over the details of how this works.

Nit: The relevant distinction is actually between:

*  prvalue -- a "pure rvalue" that is "just a value" (it has no storage 
location / address, i.e. it's not permissible to apply the address-of operator 
`&` to it). This is represented in the framework as a `Value` (or some subclass)

*  glvalue -- a "generalized lvalue", i.e. something that has a storage 
location / address, which you can obtain using the `&` operator. This is 
represented in the framework as a `StorageLocation` (or 
`RecordStorageLocation`).

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


[clang] [clang-format][NFC] Eliminate the IsCpp parameter in all functions (PR #84599)

2024-03-19 Thread Benjamin Kramer via cfe-commits

d0k wrote:

It calls `clang::format::cleanupAroundReplacements` from multiple threads. Now 
there's a race condition on IsCpp.

If this was supposed to be a cleanup please revert it.

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


[clang] [clang-format] Fixed the warning in building document for TableGenBreakingDAGArgOperators. (PR #85760)

2024-03-19 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 created 
https://github.com/llvm/llvm-project/pull/85760

Intend to fix the `Test documentation build `, degraded here 
https://github.com/llvm/llvm-project/pull/83149 .

>From 612bc89ef805a3324520f4b7ef1ebb13e334ec0b Mon Sep 17 00:00:00 2001
From: hnakamura5 
Date: Tue, 19 Mar 2024 18:46:37 +0900
Subject: [PATCH] [clang-format] Fixed the warning in building document for
 TableGenBreakingDAGArgOperators.

---
 clang/docs/ClangFormatStyleOptions.rst | 2 +-
 clang/include/clang/Format/Format.h| 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 35b6d0a2b52b67..be021dfc5c084c 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -6204,7 +6204,7 @@ the configuration (without a prefix: ``Auto``).
 
   For example the configuration,
 
-  .. code-block:: c++
+  .. code-block:: yaml
 
 TableGenBreakInsideDAGArg: BreakAll
 TableGenBreakingDAGArgOperators: ['ins', 'outs']
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 54861a66889e22..7ad2579bf7773b 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4735,7 +4735,7 @@ struct FormatStyle {
   /// the specified identifiers.
   ///
   /// For example the configuration,
-  /// \code
+  /// \code{.yaml}
   ///   TableGenBreakInsideDAGArg: BreakAll
   ///   TableGenBreakingDAGArgOperators: ['ins', 'outs']
   /// \endcode

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


[clang] [clang-format] Fixed the warning in building document for TableGenBreakingDAGArgOperators. (PR #85760)

2024-03-19 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-format

Author: Hirofumi Nakamura (hnakamura5)


Changes

Intend to fix the `Test documentation build `, degraded here 
https://github.com/llvm/llvm-project/pull/83149 .

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


2 Files Affected:

- (modified) clang/docs/ClangFormatStyleOptions.rst (+1-1) 
- (modified) clang/include/clang/Format/Format.h (+1-1) 


``diff
diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 35b6d0a2b52b67..be021dfc5c084c 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -6204,7 +6204,7 @@ the configuration (without a prefix: ``Auto``).
 
   For example the configuration,
 
-  .. code-block:: c++
+  .. code-block:: yaml
 
 TableGenBreakInsideDAGArg: BreakAll
 TableGenBreakingDAGArgOperators: ['ins', 'outs']
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 54861a66889e22..7ad2579bf7773b 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4735,7 +4735,7 @@ struct FormatStyle {
   /// the specified identifiers.
   ///
   /// For example the configuration,
-  /// \code
+  /// \code{.yaml}
   ///   TableGenBreakInsideDAGArg: BreakAll
   ///   TableGenBreakingDAGArgOperators: ['ins', 'outs']
   /// \endcode

``




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


[clang] [clang][analyzer] Model more getline/getdelim pre and postconditions (PR #83027)

2024-03-19 Thread Alejandro Álvarez Ayllón via cfe-commits

alejandro-alvarez-sonarsource wrote:

@balazske would you agree with my proposal of keeping this logic in 
`UnixAPIChecker`? I am also happy with adding more NULL checks to 
`StreamChecker`, but I can understand your concerns about overreaching its 
scope.

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


[clang] [clang][analyzer] Model more getline/getdelim pre and postconditions (PR #83027)

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

balazske wrote:

> So, it seems removing them from `StdLibraryFunctionsChecker` is not out of 
> the question. We can leave them together with other stream functions, or we 
> could move them to `UnixAPIChecker`, which we have enabled downstream.
> 
> I think the latter is a reasonable compromise so `StreamChecker` scope is the 
> stream itself, and not everything surrounding the `FILE*` APIs.

I like more if the new checks are moved to `UnixAPIChecker`, or into 
`StdLibraryFunctionsChecker`. The mentioned FIXME comment is about that these 
functions should be moved into the `ModelPOSIX` part in 
`StdLibraryFunctionsChecker`. 

Probably it would be better if `StdLibraryFunctionsChecker` would be an API 
(instead of checker) and in this way any checker can use it for the specific 
functions. But with the current solution the checks in 
`StdLibraryFunctionsChecker` can be changed for specific needs. (For example if 
a buffer size check is needed in a checker like `StreamChecker` it could use a 
simple API to do this. With the current implementation it can not use an API, 
but we can add the check into `StdLibraryFunctionsChecker` instead.) The checks 
like sufficient buffer size or NULL pointer arguments are common to many 
checkers and implementing these separately is code repetition and makes checker 
code more difficult.

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


[clang] e85bfa6 - [AArch64] Add support for Cortex-A520AE and Cortex-A720AE CPUs (#85401)

2024-03-19 Thread via cfe-commits

Author: Jonathan Thackray
Date: 2024-03-19T10:04:51Z
New Revision: e85bfa65651eb45aefc8a9233e160f27af55f894

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

LOG: [AArch64] Add support for Cortex-A520AE and Cortex-A720AE CPUs (#85401)

[AArch64] Add support for Cortex-A520AE and Cortex-A720AE CPUs

Cortex-A520AE and Cortex-A720AE are Armv9.2 AArch64 CPUs.

Technical Reference Manual for Cortex-A520AE:
   https://developer.arm.com/documentation/107726/latest/

Technical Reference Manual for Cortex-A720AE:
   https://developer.arm.com/documentation/102828/latest/

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/test/Driver/aarch64-mcpu.c
clang/test/Misc/target-invalid-cpu-note.c
llvm/docs/ReleaseNotes.rst
llvm/include/llvm/TargetParser/AArch64TargetParser.h
llvm/lib/Target/AArch64/AArch64.td
llvm/lib/TargetParser/Host.cpp
llvm/unittests/TargetParser/TargetParserTest.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3a74c070ff9ffe..dab7e1bf369754 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -445,6 +445,8 @@ Arm and AArch64 Support
   like ``target_version`` or ``target_clones``.
 - Support has been added for the following processors (-mcpu identifiers in 
parenthesis):
 * Arm Cortex-A78AE (cortex-a78ae).
+* Arm Cortex-A520AE (cortex-a520ae).
+* Arm Cortex-A720AE (cortex-a720ae).
 
 Android Support
 ^^^

diff  --git a/clang/test/Driver/aarch64-mcpu.c 
b/clang/test/Driver/aarch64-mcpu.c
index cacfc691058d13..77ba43122b2453 100644
--- a/clang/test/Driver/aarch64-mcpu.c
+++ b/clang/test/Driver/aarch64-mcpu.c
@@ -56,6 +56,8 @@
 // CORTEX-A715: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" 
"cortex-a715"
 // RUN: %clang --target=aarch64 -mcpu=cortex-a720  -### -c %s 2>&1 | FileCheck 
-check-prefix=CORTEX-A720 %s
 // CORTEX-A720: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" 
"cortex-a720"
+// RUN: %clang --target=aarch64 -mcpu=cortex-a720ae  -### -c %s 2>&1 | 
FileCheck -check-prefix=CORTEX-A720AE %s
+// CORTEX-A720AE: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" 
"cortex-a720ae"
 // RUN: %clang --target=aarch64 -mcpu=neoverse-e1  -### -c %s 2>&1 | FileCheck 
-check-prefix=NEOVERSE-E1 %s
 // NEOVERSE-E1: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" 
"neoverse-e1"
 // RUN: %clang --target=aarch64 -mcpu=neoverse-v1  -### -c %s 2>&1 | FileCheck 
-check-prefix=NEOVERSE-V1 %s
@@ -70,6 +72,8 @@
 // NEOVERSE-512TVB: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" 
"neoverse-512tvb"
 // RUN: %clang --target=aarch64 -mcpu=cortex-a520 -### -c %s 2>&1 | FileCheck 
-check-prefix=CORTEX-A520 %s
 // CORTEX-A520: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" 
"cortex-a520"
+// RUN: %clang --target=aarch64 -mcpu=cortex-a520ae -### -c %s 2>&1 | 
FileCheck -check-prefix=CORTEX-A520AE %s
+// CORTEX-A520AE: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" 
"cortex-a520ae"
 
 // RUN: %clang --target=aarch64 -mcpu=cortex-r82  -### -c %s 2>&1 | FileCheck 
-check-prefix=CORTEXR82 %s
 // CORTEXR82: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "cortex-r82"

diff  --git a/clang/test/Misc/target-invalid-cpu-note.c 
b/clang/test/Misc/target-invalid-cpu-note.c
index b65a8fb057ee53..9c91c4157cd6a0 100644
--- a/clang/test/Misc/target-invalid-cpu-note.c
+++ b/clang/test/Misc/target-invalid-cpu-note.c
@@ -5,11 +5,11 @@
 
 // RUN: not %clang_cc1 -triple arm64--- -target-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix AARCH64
 // AARCH64: error: unknown target CPU 'not-a-cpu'
-// AARCH64-NEXT: note: valid target CPU values are: cortex-a34, cortex-a35, 
cortex-a53, cortex-a55, cortex-a510, cortex-a520, cortex-a57, cortex-a65, 
cortex-a65ae, cortex-a72, cortex-a73, cortex-a75, cortex-a76, cortex-a76ae, 
cortex-a77, cortex-a78, cortex-a78ae, cortex-a78c, cortex-a710, cortex-a715, 
cortex-a720, cortex-r82, cortex-x1, cortex-x1c, cortex-x2, cortex-x3, 
cortex-x4, neoverse-e1, neoverse-n1, neoverse-n2, neoverse-512tvb, neoverse-v1, 
neoverse-v2, cyclone, apple-a7, apple-a8, apple-a9, apple-a10, apple-a11, 
apple-a12, apple-a13, apple-a14, apple-a15, apple-a16, apple-a17, apple-m1, 
apple-m2, apple-m3, apple-s4, apple-s5, exynos-m3, exynos-m4, exynos-m5, 
falkor, saphira, kryo, thunderx2t99, thunderx3t110, thunderx, thunderxt88, 
thunderxt81, thunderxt83, tsv110, a64fx, carmel, ampere1, ampere1a, ampere1b, 
cobalt-100, grace{{$}}
+// AARCH64-NEXT: note: valid target CPU values are: cortex-a34, cortex-a35, 
cortex-a53, cortex-a55, cortex-a510, cortex-a520, cortex-a520ae, cortex-a57, 
cortex-a65, cortex-a65ae, cortex-a72, cortex-a73, cortex-a75, cortex-a76, 
cortex-a76ae, cortex-a77, cortex-a78, cortex-a78ae, cortex-a78c, 

[clang] [llvm] [AArch64] Add support for Cortex-A520AE and Cortex-A720AE CPUs (PR #85401)

2024-03-19 Thread Jonathan Thackray via cfe-commits

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


[clang] [clang-format] Fixed the warning in building document for TableGenBreakingDAGArgOperators. (PR #85760)

2024-03-19 Thread Björn Schäpers via cfe-commits

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


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


[clang] 29cde04 - [clang-format] Fixed the warning in building document for TableGenBreakingDAGArgOperators. (#85760)

2024-03-19 Thread via cfe-commits

Author: Hirofumi Nakamura
Date: 2024-03-19T11:13:06+01:00
New Revision: 29cde04c3972a54efeb6d09b1580b275f39c315a

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

LOG: [clang-format] Fixed the warning in building document for 
TableGenBreakingDAGArgOperators. (#85760)

Intend to fix the `Test documentation build `, degraded here
https://github.com/llvm/llvm-project/pull/83149 .

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 35b6d0a2b52b67..be021dfc5c084c 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -6204,7 +6204,7 @@ the configuration (without a prefix: ``Auto``).
 
   For example the configuration,
 
-  .. code-block:: c++
+  .. code-block:: yaml
 
 TableGenBreakInsideDAGArg: BreakAll
 TableGenBreakingDAGArgOperators: ['ins', 'outs']

diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 54861a66889e22..7ad2579bf7773b 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4735,7 +4735,7 @@ struct FormatStyle {
   /// the specified identifiers.
   ///
   /// For example the configuration,
-  /// \code
+  /// \code{.yaml}
   ///   TableGenBreakInsideDAGArg: BreakAll
   ///   TableGenBreakingDAGArgOperators: ['ins', 'outs']
   /// \endcode



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


[clang] [clang-format] Fixed the warning in building document for TableGenBreakingDAGArgOperators. (PR #85760)

2024-03-19 Thread Björn Schäpers via cfe-commits

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


[clang] [clang-format] Add Options to break inside the TableGen DAGArg. (PR #83149)

2024-03-19 Thread Björn Schäpers via cfe-commits

HazardyKnusperkeks wrote:

Presumably fixed by #85760 

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


[clang] [clang][Sema] Refine unused-member-function diagnostic message for constructors (PR #84515)

2024-03-19 Thread via cfe-commits

guillem-bartina-sonarsource wrote:

Ping

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


[clang] [clang][Sema] Refine unused-member-function diagnostic message for constructors (PR #84515)

2024-03-19 Thread Timm Baeder via cfe-commits


@@ -76,10 +76,33 @@ struct S {
   struct SVS : public VS {
 void vm() { }
   };
+
+  struct CS {
+CS() {}
+CS(bool a) {}
+CS(int b) {} // expected-warning{{unused constructor 'CS'}}
+CS(float c);
+  };
+
+  struct DCS : public CS {
+DCS() = default; // expected-warning{{unused constructor 'DCS'}}
+DCS(bool a) : CS(a) {} // expected-warning{{unused constructor 'DCS'}}

tbaederr wrote:

Is the name of the constructor actually useful in this diagostic? It will 
always be the name of the surrounding class, won't it?

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


[clang] [clang][NFC] Add documentation for `CastExpr::path()`. (PR #85623)

2024-03-19 Thread via cfe-commits

https://github.com/martinboehme updated 
https://github.com/llvm/llvm-project/pull/85623

>From 369410916bd61671f81702c4654bd48bfc3c6c53 Mon Sep 17 00:00:00 2001
From: Martin Braenne 
Date: Mon, 18 Mar 2024 09:51:23 +
Subject: [PATCH 1/3] [clang][NFC] Add documentation for `CastExpr::path()`.

This didn't have any documentation, so I had to do some experimenting in
godbolt when I used this in https://github.com/llvm/llvm-project/pull/84138,
and my reviewer later also had some
[questions](https://github.com/llvm/llvm-project/pull/84138#discussion_r1524855434)
about this, so I figured it would be worth adding documentation.
---
 clang/include/clang/AST/Expr.h | 9 +
 1 file changed, 9 insertions(+)

diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 446bec4081e869..8c4db4828477d0 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -3552,6 +3552,15 @@ class CastExpr : public Expr {
   /// function that it invokes.
   NamedDecl *getConversionFunction() const;
 
+  /// Path through the class hierarchy taken by a `DerivedToBase` or
+  /// `UncheckedDerivedToBase` cast. For each derived-to-base edge in the path,
+  /// the path contains a `CXXBaseSpecifier` for the base class of that edge;
+  /// the entries are ordered from derived class to base class.
+  ///
+  /// For example, given classes `Base`, `Intermediate : public Base` and
+  /// `Derived : public Intermediate`, the path for a cast from `Derived *` to
+  /// `Base *` contains two entries: One for `Intermediate`, and one for 
`Base`,
+  /// in that order.
   typedef CXXBaseSpecifier **path_iterator;
   typedef const CXXBaseSpecifier *const *path_const_iterator;
   bool path_empty() const { return path_size() == 0; }

>From 571d5f4b180b2e55b03a4a43a7c0fadbee2ed25a Mon Sep 17 00:00:00 2001
From: Martin Braenne 
Date: Tue, 19 Mar 2024 07:30:39 +
Subject: [PATCH 2/3] fixup! [clang][NFC] Add documentation for
 `CastExpr::path()`.

---
 clang/include/clang/AST/Expr.h | 11 +++
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 8c4db4828477d0..292cda39dc56bf 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -3552,10 +3552,13 @@ class CastExpr : public Expr {
   /// function that it invokes.
   NamedDecl *getConversionFunction() const;
 
-  /// Path through the class hierarchy taken by a `DerivedToBase` or
-  /// `UncheckedDerivedToBase` cast. For each derived-to-base edge in the path,
-  /// the path contains a `CXXBaseSpecifier` for the base class of that edge;
-  /// the entries are ordered from derived class to base class.
+  /// Path through the class hierarchy taken by casts between base and derived
+  /// classes (see implementation of `CastConsistency()` for a full list of
+  /// cast kinds that have a path).
+  ///
+  /// For each derived-to-base edge in the path, the path contains a
+  /// `CXXBaseSpecifier` for the base class of that edge; the entries are
+  /// ordered from derived class to base class.
   ///
   /// For example, given classes `Base`, `Intermediate : public Base` and
   /// `Derived : public Intermediate`, the path for a cast from `Derived *` to

>From 806ee8eab73a61867cb7cf305762aa4755bd20f4 Mon Sep 17 00:00:00 2001
From: Martin Braenne 
Date: Tue, 19 Mar 2024 10:36:11 +
Subject: [PATCH 3/3] fixup! fixup! [clang][NFC] Add documentation for
 `CastExpr::path()`.

---
 clang/include/clang/AST/Expr.h | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 292cda39dc56bf..a76404b3138dda 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -3552,6 +3552,15 @@ class CastExpr : public Expr {
   /// function that it invokes.
   NamedDecl *getConversionFunction() const;
 
+  typedef CXXBaseSpecifier **path_iterator;
+  typedef const CXXBaseSpecifier *const *path_const_iterator;
+  bool path_empty() const { return path_size() == 0; }
+  unsigned path_size() const { return CastExprBits.BasePathSize; }
+  path_iterator path_begin() { return path_buffer(); }
+  path_iterator path_end() { return path_buffer() + path_size(); }
+  path_const_iterator path_begin() const { return path_buffer(); }
+  path_const_iterator path_end() const { return path_buffer() + path_size(); }
+
   /// Path through the class hierarchy taken by casts between base and derived
   /// classes (see implementation of `CastConsistency()` for a full list of
   /// cast kinds that have a path).
@@ -3564,15 +3573,6 @@ class CastExpr : public Expr {
   /// `Derived : public Intermediate`, the path for a cast from `Derived *` to
   /// `Base *` contains two entries: One for `Intermediate`, and one for 
`Base`,
   /// in that order.
-  typedef CXXBaseSpecifier **path_iterator;
-  typedef const CXXBaseSpecifier *const *path_const_iterator;
-  bool pat

[clang] [clang][NFC] Add documentation for `CastExpr::path()`. (PR #85623)

2024-03-19 Thread via cfe-commits

martinboehme wrote:

> Does this actually show up at the right place? Or is it now the documentation 
> for `path_empty()`? Or even `path_iterator`?

Hm, good question. This seemed the most logical place to put the documentation 
in the source code, but of course, once it gets processed by Doxygen, it will 
probably get attached to something we don't want.

I've moved the documentation down, right above the declaration of `path()`. 
WDYT?

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


[clang] [flang] [flang] Enable polymorphic lowering by default (PR #83285)

2024-03-19 Thread via cfe-commits

https://github.com/jeanPerier updated 
https://github.com/llvm/llvm-project/pull/83285

>From 8c5bd904e624c9ec10d75ddf09b8ec55c32d8b06 Mon Sep 17 00:00:00 2001
From: Jean Perier 
Date: Wed, 28 Feb 2024 06:17:11 -0800
Subject: [PATCH] [flang] Enable polymorphic lowering by default

Polymorphic entity lowering status is good. There main remaining TODO
is to allow lowering of vector subscripted polymorphic entity.

Remove experimental option and enable lowering of polymorphic
entity by default.
---
 clang/include/clang/Driver/Options.td  |  5 -
 clang/lib/Driver/ToolChains/Flang.cpp  |  1 -
 flang/include/flang/Lower/LoweringOptions.def  |  3 ---
 flang/lib/Frontend/CompilerInvocation.cpp  |  5 -
 flang/lib/Lower/CallInterface.cpp  |  6 --
 flang/lib/Lower/ConvertType.cpp|  4 
 flang/test/Driver/driver-help-hidden.f90   |  2 --
 .../Driver/flang-experimental-polymorphism-flag.f90| 10 --
 flang/test/Driver/frontend-forwarding.f90  |  2 --
 flang/test/Fir/dispatch.f90|  4 ++--
 flang/test/HLFIR/assumed-type-actual-args.f90  |  2 +-
 flang/test/HLFIR/boxchar_emboxing.f90  |  2 +-
 flang/test/HLFIR/call_with_poly_dummy.f90  |  2 +-
 .../Lower/HLFIR/actual_target_for_dummy_pointer.f90|  2 +-
 flang/test/Lower/HLFIR/allocatable-return.f90  |  2 +-
 flang/test/Lower/HLFIR/array-ctor-derived.f90  |  2 +-
 .../HLFIR/call-sequence-associated-descriptors.f90 |  2 +-
 flang/test/Lower/HLFIR/calls-assumed-shape.f90 |  2 +-
 .../HLFIR/calls-constant-expr-arg-polymorphic.f90  |  2 +-
 flang/test/Lower/HLFIR/calls-optional.f90  |  2 +-
 flang/test/Lower/HLFIR/calls-poly-to-assumed-type.f90  |  2 +-
 flang/test/Lower/HLFIR/convert-mbox-to-value.f90   |  2 +-
 flang/test/Lower/HLFIR/designators-component-ref.f90   |  2 +-
 .../Lower/HLFIR/designators-parameter-array-slice.f90  |  2 +-
 flang/test/Lower/HLFIR/elemental-array-ops.f90 |  2 +-
 flang/test/Lower/HLFIR/elemental-polymorphic-merge.f90 |  2 +-
 .../HLFIR/elemental-user-procedure-ref-polymorphic.f90 |  2 +-
 flang/test/Lower/HLFIR/function-return-as-expr.f90 |  2 +-
 flang/test/Lower/HLFIR/function-return-destroy.f90 |  2 +-
 .../Lower/HLFIR/ignore-rank-unlimited-polymorphic.f90  |  2 +-
 flang/test/Lower/HLFIR/ignore-type-assumed-shape.f90   |  2 +-
 .../Lower/HLFIR/intentout-allocatable-components.f90   |  2 +-
 .../Lower/HLFIR/internal-procedures-polymorphic.f90|  2 +-
 flang/test/Lower/HLFIR/intrinsic-assumed-type.f90  |  2 +-
 flang/test/Lower/HLFIR/parent-component-ref.f90|  2 +-
 flang/test/Lower/HLFIR/poly_expr_for_nonpoly_dummy.f90 |  2 +-
 flang/test/Lower/HLFIR/polymorphic-expressions.f90 |  2 +-
 flang/test/Lower/HLFIR/proc-pointer-comp-nopass.f90|  2 +-
 flang/test/Lower/HLFIR/proc-pointer-comp-pass.f90  |  2 +-
 flang/test/Lower/HLFIR/select-type-selector.f90|  2 +-
 flang/test/Lower/HLFIR/transpose.f90   |  2 +-
 flang/test/Lower/HLFIR/type-bound-call-mismatch.f90|  2 +-
 flang/test/Lower/HLFIR/vector-subscript-as-value.f90   |  2 +-
 flang/test/Lower/Intrinsics/extends_type_of.f90|  2 +-
 flang/test/Lower/Intrinsics/same_type_as.f90   |  2 +-
 flang/test/Lower/Intrinsics/sizeof.f90 |  2 +-
 flang/test/Lower/Intrinsics/spread.f90 |  2 +-
 flang/test/Lower/Intrinsics/storage_size.f90   |  2 +-
 flang/test/Lower/allocatable-polymorphic.f90   |  4 ++--
 flang/test/Lower/allocatable-return.f90|  2 +-
 flang/test/Lower/assumed-type.f90  |  2 +-
 flang/test/Lower/default-initialization.f90|  2 +-
 flang/test/Lower/derived-type-finalization.f90 |  2 +-
 flang/test/Lower/dispatch-table.f90|  2 +-
 flang/test/Lower/dispatch.f90  |  2 +-
 flang/test/Lower/intentout-deallocate.f90  |  4 ++--
 flang/test/Lower/io-derived-type-2.f90 |  2 +-
 flang/test/Lower/io-derived-type.f90   |  2 +-
 flang/test/Lower/nullify-polymorphic.f90   |  2 +-
 flang/test/Lower/pass-null-for-class-arg.f90   |  4 ++--
 flang/test/Lower/pointer-association-polymorphic.f90   |  2 +-
 flang/test/Lower/pointer-disassociate.f90  |  2 +-
 flang/test/Lower/polymorphic-temp.f90  |  2 +-
 flang/test/Lower/polymorphic-types.f90 |  2 +-
 flang/test/Lower/polymorphic.f90   |  2 +-
 flang/test/Lower/select-type-2.f90 |  2 +-
 flang/test/Lower/select-type.f90   |  4 ++--
 flang/tools/bbc/bbc.cpp|  6 --
 68 files changed, 63 insertions(+), 107 deletions(-)
 delete mode 100644 flang/test/Driver/flang-experimental-

[clang] [llvm] [DebugInfo] Use DW_op_bit_piece for structured bindings of bitfields (PR #85665)

2024-03-19 Thread John Brawn via cfe-commits


@@ -8,8 +8,8 @@ struct S0 {
 // CHECK-LABEL: define dso_local void @_Z3fS0v
 // CHECK:alloca %struct.S0, align 4
 // CHECK-NEXT:[[TMP0:%.*]] = alloca %struct.S0, align 4
-// CHECK: call void @llvm.dbg.declare(metadata ptr [[TMP0]], metadata 
[[S0_A:![0-9]+]], metadata !DIExpression())
-// CHECK-NEXT:call void @llvm.dbg.declare(metadata ptr [[TMP0]], metadata 
[[S0_B:![0-9]+]], metadata !DIExpression(DW_OP_plus_uconst, 2))
+// CHECK: call void @llvm.dbg.declare(metadata ptr [[TMP0]], metadata 
[[S0_A:![0-9]+]], metadata !DIExpression(DW_OP_bit_piece, 16, 0))

john-brawn-arm wrote:

The LLVM langref says "Note that contrary to DW_OP_bit_piece, the offset is 
describing the location within the described source variable". What I think 
this means is that while DW_OP_bit_piece means "you get the source variable by 
extracting these bits of this location", DW_OP_LLVM_fragment means "the value 
of this location is these bits of the source variable".

Trying out DW_OP_LLVM_fragment in
```
struct {
  unsigned int a : 8;
  unsigned int b : 8;
} X = { 1, 2 };

int main() {
  auto [a, b] = X;
  return a + b;
}
```
the resulting dwarf info looks pretty strange
```
 <2><7f>: Abbrev Number: 7 (DW_TAG_variable)
<80>   DW_AT_location: 4 byte block: 93 1 91 78 (DW_OP_piece: 
1; DW_OP_fbreg: -8)
<85>   DW_AT_name: (indirect string, offset: 0x9c): a
<89>   DW_AT_decl_file   : 1
<8a>   DW_AT_decl_line   : 7
<8b>   DW_AT_type: <0x5f>
 <2><8f>: Abbrev Number: 7 (DW_TAG_variable)
<90>   DW_AT_location: 6 byte block: 93 1 91 78 93 1(DW_OP_piece: 
1; DW_OP_fbreg: -8; DW_OP_piece: 1)
<97>   DW_AT_name: (indirect string, offset: 0xab): b
<9b>   DW_AT_decl_file   : 1
<9c>   DW_AT_decl_line   : 7
<9d>   DW_AT_type: <0x5f>
```
lldb says (at line 8)
```
(lldb) p a
(unsigned int) 513
(lldb) p b
(unsigned int) 256
```
gdb appears to not like this dwarf info and just says
```
(gdb) p a
$1 = 
(gdb) p b
$2 = 
```

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


[clang] [clang][Sema] Refine unused-member-function diagnostic message for constructors (PR #84515)

2024-03-19 Thread via cfe-commits


@@ -76,10 +76,33 @@ struct S {
   struct SVS : public VS {
 void vm() { }
   };
+
+  struct CS {
+CS() {}
+CS(bool a) {}
+CS(int b) {} // expected-warning{{unused constructor 'CS'}}
+CS(float c);
+  };
+
+  struct DCS : public CS {
+DCS() = default; // expected-warning{{unused constructor 'DCS'}}
+DCS(bool a) : CS(a) {} // expected-warning{{unused constructor 'DCS'}}

guillem-bartina-sonarsource wrote:

Yes, you are right, it will always be the same. I left it for consistency with 
the previous message but I agree that it doesn't provide useful information. 
Would you prefer the message to be "unused constructor"?

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


[clang] [clang][Sema] Refine unused-member-function diagnostic message for constructors (PR #84515)

2024-03-19 Thread via cfe-commits

https://github.com/guillem-bartina-sonarsource edited 
https://github.com/llvm/llvm-project/pull/84515
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [flang] Enable polymorphic lowering by default (PR #83285)

2024-03-19 Thread via cfe-commits

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


[clang] d0829fb - [flang] Enable polymorphic lowering by default (#83285)

2024-03-19 Thread via cfe-commits

Author: jeanPerier
Date: 2024-03-19T11:45:31+01:00
New Revision: d0829fbdeda0a2faa8cf684e1396e579691bdfa2

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

LOG: [flang] Enable polymorphic lowering by default (#83285)

Polymorphic entity lowering status is good. The main remaining TODO is
to allow lowering of vector subscripted polymorphic entity, but this
does not deserve blocking all application using polymorphism.

Remove experimental option and enable lowering of polymorphic entity by
default.

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Flang.cpp
flang/include/flang/Lower/LoweringOptions.def
flang/lib/Frontend/CompilerInvocation.cpp
flang/lib/Lower/CallInterface.cpp
flang/lib/Lower/ConvertType.cpp
flang/test/Driver/driver-help-hidden.f90
flang/test/Driver/frontend-forwarding.f90
flang/test/Fir/dispatch.f90
flang/test/HLFIR/assumed-type-actual-args.f90
flang/test/HLFIR/boxchar_emboxing.f90
flang/test/HLFIR/call_with_poly_dummy.f90
flang/test/Lower/HLFIR/actual_target_for_dummy_pointer.f90
flang/test/Lower/HLFIR/allocatable-return.f90
flang/test/Lower/HLFIR/array-ctor-derived.f90
flang/test/Lower/HLFIR/call-sequence-associated-descriptors.f90
flang/test/Lower/HLFIR/calls-assumed-shape.f90
flang/test/Lower/HLFIR/calls-constant-expr-arg-polymorphic.f90
flang/test/Lower/HLFIR/calls-optional.f90
flang/test/Lower/HLFIR/calls-poly-to-assumed-type.f90
flang/test/Lower/HLFIR/convert-mbox-to-value.f90
flang/test/Lower/HLFIR/designators-component-ref.f90
flang/test/Lower/HLFIR/designators-parameter-array-slice.f90
flang/test/Lower/HLFIR/elemental-array-ops.f90
flang/test/Lower/HLFIR/elemental-polymorphic-merge.f90
flang/test/Lower/HLFIR/elemental-user-procedure-ref-polymorphic.f90
flang/test/Lower/HLFIR/function-return-as-expr.f90
flang/test/Lower/HLFIR/function-return-destroy.f90
flang/test/Lower/HLFIR/ignore-rank-unlimited-polymorphic.f90
flang/test/Lower/HLFIR/ignore-type-assumed-shape.f90
flang/test/Lower/HLFIR/intentout-allocatable-components.f90
flang/test/Lower/HLFIR/internal-procedures-polymorphic.f90
flang/test/Lower/HLFIR/intrinsic-assumed-type.f90
flang/test/Lower/HLFIR/parent-component-ref.f90
flang/test/Lower/HLFIR/poly_expr_for_nonpoly_dummy.f90
flang/test/Lower/HLFIR/polymorphic-expressions.f90
flang/test/Lower/HLFIR/proc-pointer-comp-nopass.f90
flang/test/Lower/HLFIR/proc-pointer-comp-pass.f90
flang/test/Lower/HLFIR/select-type-selector.f90
flang/test/Lower/HLFIR/transpose.f90
flang/test/Lower/HLFIR/type-bound-call-mismatch.f90
flang/test/Lower/HLFIR/vector-subscript-as-value.f90
flang/test/Lower/Intrinsics/extends_type_of.f90
flang/test/Lower/Intrinsics/same_type_as.f90
flang/test/Lower/Intrinsics/sizeof.f90
flang/test/Lower/Intrinsics/spread.f90
flang/test/Lower/Intrinsics/storage_size.f90
flang/test/Lower/allocatable-polymorphic.f90
flang/test/Lower/allocatable-return.f90
flang/test/Lower/assumed-type.f90
flang/test/Lower/default-initialization.f90
flang/test/Lower/derived-type-finalization.f90
flang/test/Lower/dispatch-table.f90
flang/test/Lower/dispatch.f90
flang/test/Lower/intentout-deallocate.f90
flang/test/Lower/io-derived-type-2.f90
flang/test/Lower/io-derived-type.f90
flang/test/Lower/nullify-polymorphic.f90
flang/test/Lower/pass-null-for-class-arg.f90
flang/test/Lower/pointer-association-polymorphic.f90
flang/test/Lower/pointer-disassociate.f90
flang/test/Lower/polymorphic-temp.f90
flang/test/Lower/polymorphic-types.f90
flang/test/Lower/polymorphic.f90
flang/test/Lower/select-type-2.f90
flang/test/Lower/select-type.f90
flang/tools/bbc/bbc.cpp

Removed: 
flang/test/Driver/flang-experimental-polymorphism-flag.f90



diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 4b1fcf1db1ad09..29c226f4bd8da7 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -6441,11 +6441,6 @@ def flang_deprecated_no_hlfir : Flag<["-"], 
"flang-deprecated-no-hlfir">,
   Flags<[HelpHidden]>, Visibility<[FlangOption, FC1Option]>,
   HelpText<"Do not use HLFIR lowering (deprecated)">;
 
-def flang_experimental_polymorphism : Flag<["-"], 
"flang-experimental-polymorphism">,
-  Flags<[HelpHidden]>, Visibility<[FlangOption, FC1Option]>,
-  HelpText<"Enable Fortran 2003 polymorphism (experimental)">;
-
-
 
//===--===//
 // FLangOption + CoreOption + NoXarchOption
 
//===-

[clang] [clang-format] Fixed the warning in building document for TableGenBreakingDAGArgOperators. (PR #85760)

2024-03-19 Thread Hirofumi Nakamura via cfe-commits

hnakamura5 wrote:

Thank you so much for quick response!

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


[clang] [clang-format] Add Options to break inside the TableGen DAGArg. (PR #83149)

2024-03-19 Thread Hirofumi Nakamura via cfe-commits

hnakamura5 wrote:

@wangpc-pp 
Thank you for telling, and sorry for overlooking the detailed check for CI.

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


[clang] [clang-format] Add Options to break inside the TableGen DAGArg. (PR #83149)

2024-03-19 Thread Hirofumi Nakamura via cfe-commits

hnakamura5 wrote:

@HazardyKnusperkeks 
Thank you for reviewing and merging the fix.

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


[clang] [clang][analyzer] Model more getline/getdelim pre and postconditions (PR #83027)

2024-03-19 Thread via cfe-commits
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?Message-ID:
In-Reply-To: 


NagyDonat wrote:

Just chiming in to cast a supporting vote for the idea that
> Probably it would be better if StdLibraryFunctionsChecker would be an API 
> (instead of checker) and in this way any checker can use it for the specific 
> functions. But with the current solution the checks in 
> StdLibraryFunctionsChecker can be changed for specific needs. (For example if 
> a buffer size check is needed in a checker like StreamChecker it could use a 
> simple API to do this. With the current implementation it can not use an API, 
> but we can add the check into StdLibraryFunctionsChecker instead.) The checks 
> like sufficient buffer size or NULL pointer arguments are common to many 
> checkers and implementing these separately is code repetition and makes 
> checker code more difficult.

@balazske Are you interested in refactoring the logic of 
`StdLibraryFunctionsChecker` into an API that can be used by separate checkers?

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


[clang] [clang-cl] Fix value of __FUNCTION__ in MSVC mode. (PR #84014)

2024-03-19 Thread Zahira Ammarguellat via cfe-commits

https://github.com/zahiraam updated 
https://github.com/llvm/llvm-project/pull/84014

>From bdefe754c14c5e050ebf2b9c82eca458041564a4 Mon Sep 17 00:00:00 2001
From: Zahira Ammarguellat 
Date: Tue, 5 Mar 2024 05:35:16 -0800
Subject: [PATCH 01/10] [clang-cl] Fix value of __FUNCTION__ in MSVC mode.

---
 clang/docs/ReleaseNotes.rst   |  3 +
 clang/include/clang/AST/Expr.h|  3 +-
 clang/lib/AST/Expr.cpp| 26 ++--
 clang/lib/AST/TypePrinter.cpp | 24 +--
 clang/lib/Sema/SemaExpr.cpp   |  5 +-
 clang/test/AST/Interp/literals.cpp|  8 +--
 clang/test/Analysis/eval-predefined-exprs.cpp | 22 +--
 clang/test/SemaCXX/source_location.cpp| 64 +++
 clang/unittests/AST/DeclPrinterTest.cpp   | 15 +
 9 files changed, 149 insertions(+), 21 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 612b4329727455..20c14fae1dd31b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -224,6 +224,9 @@ Bug Fixes in This Version
   for variables created through copy initialization having side-effects in 
C++17 and later.
   Fixes (#GH64356) (#GH79518).
 
+- Fix value of predefined macro ``__FUNCTION__`` to match MSVC's value. Fixes
+  (`#66114 `_).
+
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index bf0622bdeca30e..ce8e64a4bed04b 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -2034,7 +2034,8 @@ class PredefinedExpr final
   }
 
   static std::string ComputeName(PredefinedIdentKind IK,
- const Decl *CurrentDecl);
+ const Decl *CurrentDecl,
+ bool ForceElaboratedPrinting = false);
 
   SourceLocation getBeginLoc() const { return getLocation(); }
   SourceLocation getEndLoc() const { return getLocation(); }
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index b4de2155adcebd..796e50817ee319 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -673,7 +673,8 @@ StringRef 
PredefinedExpr::getIdentKindName(PredefinedIdentKind IK) {
 // FIXME: Maybe this should use DeclPrinter with a special "print predefined
 // expr" policy instead.
 std::string PredefinedExpr::ComputeName(PredefinedIdentKind IK,
-const Decl *CurrentDecl) {
+const Decl *CurrentDecl,
+bool ForceElaboratedPrinting) {
   ASTContext &Context = CurrentDecl->getASTContext();
 
   if (IK == PredefinedIdentKind::FuncDName) {
@@ -721,10 +722,17 @@ std::string 
PredefinedExpr::ComputeName(PredefinedIdentKind IK,
 return std::string(Out.str());
   }
   if (const FunctionDecl *FD = dyn_cast(CurrentDecl)) {
-if (IK != PredefinedIdentKind::PrettyFunction &&
-IK != PredefinedIdentKind::PrettyFunctionNoVirtual &&
-IK != PredefinedIdentKind::FuncSig &&
-IK != PredefinedIdentKind::LFuncSig)
+const auto &LO = Context.getLangOpts();
+if ((ForceElaboratedPrinting &&
+ (((IK == PredefinedIdentKind::Func ||
+IK == PredefinedIdentKind ::Function) &&
+   !LO.MicrosoftExt) ||
+  (IK == PredefinedIdentKind::LFunction && LO.MicrosoftExt))) ||
+(!ForceElaboratedPrinting &&
+ (IK != PredefinedIdentKind::PrettyFunction &&
+  IK != PredefinedIdentKind::PrettyFunctionNoVirtual &&
+  IK != PredefinedIdentKind::FuncSig &&
+  IK != PredefinedIdentKind::LFuncSig)))
   return FD->getNameAsString();
 
 SmallString<256> Name;
@@ -752,6 +760,8 @@ std::string PredefinedExpr::ComputeName(PredefinedIdentKind 
IK,
 PrintingPolicy Policy(Context.getLangOpts());
 PrettyCallbacks PrettyCB(Context.getLangOpts());
 Policy.Callbacks = &PrettyCB;
+if (IK == PredefinedIdentKind::Function && ForceElaboratedPrinting)
+  Policy.SuppressTagKeyword = !LO.MicrosoftExt;
 std::string Proto;
 llvm::raw_string_ostream POut(Proto);
 
@@ -779,6 +789,12 @@ std::string 
PredefinedExpr::ComputeName(PredefinedIdentKind IK,
 
 FD->printQualifiedName(POut, Policy);
 
+if (IK == PredefinedIdentKind::Function) {
+  POut.flush();
+  Out << Proto;
+  return std::string(Name);
+}
+
 POut << "(";
 if (FT) {
   for (unsigned i = 0, e = Decl->getNumParams(); i != e; ++i) {
diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp
index 7dcc4348f8e036..21605e1f53e3d9 100644
--- a/clang/lib/AST/TypePrinter.cpp
+++ b/clang/lib/AST/TypePrinter.cpp
@@ -1635,6 +1635,17 @@ void TypePrinter::printElaboratedBefore(const 
ElaboratedType *T,
 if (T->getKeyword() != ElaboratedTypeKeyword::None)
   OS << " ";
 NestedNameSpecifier 

[clang] [clang][analyzer] Model more getline/getdelim pre and postconditions (PR #83027)

2024-03-19 Thread via cfe-commits
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?Message-ID:
In-Reply-To: 


https://github.com/NagyDonat commented:

And now that I'm here I also give a quick review for the commit itself: I think 
that it's good overall (but I didn't analyze its logic too deeply). I have a 
few minor suggestions, but they're not mandatory/blocking.

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


[clang] [clang][analyzer] Model more getline/getdelim pre and postconditions (PR #83027)

2024-03-19 Thread via cfe-commits
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?Message-ID:
In-Reply-To: 



@@ -1179,6 +1195,113 @@ void StreamChecker::evalUngetc(const FnDescription 
*Desc, const CallEvent &Call,
   C.addTransition(StateFailed);
 }
 
+ProgramStateRef StreamChecker::ensureGetdelimBufferAndSizeCorrect(
+SVal LinePtrPtrSVal, SVal SizePtrSVal, const Expr *LinePtrPtrExpr,
+const Expr *SizePtrExpr, CheckerContext &C, ProgramStateRef State) const {
+  static constexpr char SizeGreaterThanBufferSize[] =
+  "The buffer from the first argument is smaller than the size "
+  "specified by the second parameter";
+  static constexpr char SizeUndef[] =
+  "The buffer from the first argument is not NULL, but the size specified "
+  "by the second parameter is undefined.";
+
+  auto EmitBugReport = [this, &C, SizePtrExpr,
+LinePtrPtrExpr](const ProgramStateRef &BugState,

NagyDonat wrote:

```suggestion
LinePtrPtrExpr](ProgramStateRef BugState,
```
`ProgramStateRef` is almost always passed by value in existing code, so 
consider using that style. (By the way, `ProgramStateRef` a typedef for 
`IntrusiveRefCntPtr`; so I think it's premature 
optimization to pass it by const reference.)

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


[clang] [clang][analyzer] Model more getline/getdelim pre and postconditions (PR #83027)

2024-03-19 Thread via cfe-commits
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?Message-ID:
In-Reply-To: 


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


[clang] [clang][analyzer] Model more getline/getdelim pre and postconditions (PR #83027)

2024-03-19 Thread via cfe-commits
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?Message-ID:
In-Reply-To: 



@@ -1179,6 +1195,113 @@ void StreamChecker::evalUngetc(const FnDescription 
*Desc, const CallEvent &Call,
   C.addTransition(StateFailed);
 }
 
+ProgramStateRef StreamChecker::ensureGetdelimBufferAndSizeCorrect(
+SVal LinePtrPtrSVal, SVal SizePtrSVal, const Expr *LinePtrPtrExpr,
+const Expr *SizePtrExpr, CheckerContext &C, ProgramStateRef State) const {
+  static constexpr char SizeGreaterThanBufferSize[] =
+  "The buffer from the first argument is smaller than the size "
+  "specified by the second parameter";
+  static constexpr char SizeUndef[] =
+  "The buffer from the first argument is not NULL, but the size specified "
+  "by the second parameter is undefined.";

NagyDonat wrote:

For `constexpr` strings consider using the type `llvm::StringLiteral` which is 
a subclass of `StringRef` and computes the length in compile time.

(And don't confuse it with `clang::StringLiteral` which is an AST node :wink: .)

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


[clang] [clang][analyzer] Model more getline/getdelim pre and postconditions (PR #83027)

2024-03-19 Thread via cfe-commits
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?Message-ID:
In-Reply-To: 



@@ -1179,6 +1195,113 @@ void StreamChecker::evalUngetc(const FnDescription 
*Desc, const CallEvent &Call,
   C.addTransition(StateFailed);
 }
 
+ProgramStateRef StreamChecker::ensureGetdelimBufferAndSizeCorrect(
+SVal LinePtrPtrSVal, SVal SizePtrSVal, const Expr *LinePtrPtrExpr,
+const Expr *SizePtrExpr, CheckerContext &C, ProgramStateRef State) const {
+  static constexpr char SizeGreaterThanBufferSize[] =
+  "The buffer from the first argument is smaller than the size "
+  "specified by the second parameter";
+  static constexpr char SizeUndef[] =
+  "The buffer from the first argument is not NULL, but the size specified "
+  "by the second parameter is undefined.";
+
+  auto EmitBugReport = [this, &C, SizePtrExpr,
+LinePtrPtrExpr](const ProgramStateRef &BugState,
+const char *ErrMsg) {
+if (ExplodedNode *N = C.generateErrorNode(BugState)) {
+  auto R =
+  std::make_unique(BT_IllegalSize, ErrMsg, N);
+  bugreporter::trackExpressionValue(N, SizePtrExpr, *R);
+  bugreporter::trackExpressionValue(N, LinePtrPtrExpr, *R);
+  C.emitReport(std::move(R));
+}
+  };
+
+  // We have a pointer to a pointer to the buffer, and a pointer to the size.
+  // We want what they point at.
+  auto LinePtrSVal = getPointeeVal(LinePtrPtrSVal, 
State)->getAs();
+  auto NSVal = getPointeeVal(SizePtrSVal, State);
+  if (!LinePtrSVal || !NSVal || NSVal->isUnknown())
+return nullptr;
+
+  assert(LinePtrPtrExpr && SizePtrExpr);
+
+  const auto [LinePtrNotNull, LinePtrNull] = State->assume(*LinePtrSVal);
+  if (LinePtrNotNull && !LinePtrNull) {
+// If `*lineptr` is not null, but `*n` is undefined, there is UB.
+if (NSVal->isUndef()) {
+  EmitBugReport(LinePtrNotNull, SizeUndef);
+  return nullptr;
+}
+
+// If it is defined, and known, its size must be less than or equal to
+// the buffer size.
+auto NDefSVal = NSVal->getAs();
+auto &SVB = C.getSValBuilder();
+auto LineBufSize =
+getDynamicExtent(LinePtrNotNull, LinePtrSVal->getAsRegion(), SVB);
+auto LineBufSizeGtN = SVB.evalBinOp(LinePtrNotNull, BO_GE, LineBufSize,
+*NDefSVal, SVB.getConditionType())
+  .getAs();
+if (!LineBufSizeGtN) {
+  return LinePtrNotNull;
+}
+if (auto LineBufSizeOk = LinePtrNotNull->assume(*LineBufSizeGtN, true)) {
+  return LineBufSizeOk;
+}

NagyDonat wrote:

```suggestion
if (!LineBufSizeGtN)
  return LinePtrNotNull;
 
if (auto LineBufSizeOk = LinePtrNotNull->assume(*LineBufSizeGtN, true))
  return LineBufSizeOk;
```
Unbrace simple conditionals.

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


[clang] [clang][analyzer] Model more getline/getdelim pre and postconditions (PR #83027)

2024-03-19 Thread via cfe-commits
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?Message-ID:
In-Reply-To: 


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


[clang] [clang-cl] Fix value of __FUNCTION__ in MSVC mode. (PR #84014)

2024-03-19 Thread Zahira Ammarguellat via cfe-commits

zahiraam wrote:

Thank you all for the reviews.

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


[clang] [lld] [llvm] [ARM][AArch64] Change module flags values. (PR #84804)

2024-03-19 Thread Daniel Kiss via cfe-commits

https://github.com/DanielKristofKiss updated 
https://github.com/llvm/llvm-project/pull/84804

>From e0596b2e216c041cfeb63faa8cf6d31a2601934f Mon Sep 17 00:00:00 2001
From: Daniel Kiss 
Date: Fri, 8 Mar 2024 15:06:28 +0100
Subject: [PATCH 1/2] [LLVM] Autoupgrade function attributes from Module
 attributes.

Refactoring #82763 to cache module attributes.
---
 lld/test/ELF/lto/aarch64_inline.ll| 51 +++
 llvm/include/llvm/IR/AutoUpgrade.h|  3 ++
 llvm/lib/IR/AutoUpgrade.cpp   | 47 +
 llvm/lib/Linker/IRMover.cpp   | 10 
 .../AArch64/link-branch-target-enforcement.ll |  3 ++
 .../LTO/AArch64/link-sign-return-address.ll   | 43 
 llvm/test/Linker/link-arm-and-thumb.ll|  6 +--
 7 files changed, 160 insertions(+), 3 deletions(-)
 create mode 100644 lld/test/ELF/lto/aarch64_inline.ll
 create mode 100644 llvm/test/LTO/AArch64/link-sign-return-address.ll

diff --git a/lld/test/ELF/lto/aarch64_inline.ll 
b/lld/test/ELF/lto/aarch64_inline.ll
new file mode 100644
index 00..781c283bc56a3e
--- /dev/null
+++ b/lld/test/ELF/lto/aarch64_inline.ll
@@ -0,0 +1,51 @@
+; REQUIRES: aarch64
+;; Test verifies inlining happens cross module when module flags are upgraded
+;; by the thin-lto linker/IRMover.
+;; Regression test for #82763
+
+; RUN: split-file %s %t
+; RUN: opt -thinlto-bc -thinlto-split-lto-unit -unified-lto %t/foo.s -o 
%t/foo.o
+; RUN: opt -thinlto-bc -thinlto-split-lto-unit -unified-lto %t/main.s -o 
%t/main.o
+; RUN: ld.lld -O2 --lto=thin --entry=main %t/main.o %t/foo.o -o %t/exe
+; RUN: llvm-objdump -d %t/exe | FileCheck %s
+
+
+; CHECK-LABEL:  :
+; CHECK-NEXT: pacibsp
+; CHECK-NEXT: mov w0, #0x22
+; CHECK-NEXT: autibsp
+; CHECK-NEXT: ret
+
+;--- foo.s
+target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
+target triple = "aarch64-unknown-linux-gnu"
+
+define dso_local noundef i32 @foo() local_unnamed_addr #0 {
+entry:
+  ret i32 34
+}
+
+attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn 
memory(none) }
+!llvm.module.flags = !{!0, !1, !2, !3 }
+!0 = !{i32 8, !"branch-target-enforcement", i32 1}
+!1 = !{i32 8, !"sign-return-address", i32 1}
+!2 = !{i32 8, !"sign-return-address-all", i32 1}
+!3 = !{i32 8, !"sign-return-address-with-bkey", i32 1}
+
+;--- main.s
+target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
+target triple = "aarch64-unknown-linux-gnu"
+
+declare i32 @foo();
+
+define i32 @main() {
+entry:
+  %1 = call i32 @foo()
+  ret i32 %1
+}
+
+!llvm.module.flags = !{!0, !1, !2, !3 }
+!0 = !{i32 8, !"branch-target-enforcement", i32 1}
+!1 = !{i32 8, !"sign-return-address", i32 1}
+!2 = !{i32 8, !"sign-return-address-all", i32 1}
+!3 = !{i32 8, !"sign-return-address-with-bkey", i32 1}
diff --git a/llvm/include/llvm/IR/AutoUpgrade.h 
b/llvm/include/llvm/IR/AutoUpgrade.h
index 152f781ffa9b30..1ef32bcb121bec 100644
--- a/llvm/include/llvm/IR/AutoUpgrade.h
+++ b/llvm/include/llvm/IR/AutoUpgrade.h
@@ -88,6 +88,9 @@ namespace llvm {
   /// info. Return true if module is modified.
   bool UpgradeDebugInfo(Module &M);
 
+  /// Copies module attributes to the functions in the module.
+  void CopyModuleAttrToFunctions(Module &M);
+
   /// Check whether a string looks like an old loop attachment tag.
   inline bool mayBeOldLoopAttachmentTag(StringRef Name) {
 return Name.starts_with("llvm.vectorizer.");
diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp
index be0abb4b71dae2..ed7699c113584b 100644
--- a/llvm/lib/IR/AutoUpgrade.cpp
+++ b/llvm/lib/IR/AutoUpgrade.cpp
@@ -5178,6 +5178,53 @@ void llvm::UpgradeFunctionAttributes(Function &F) {
 Arg.removeAttrs(AttributeFuncs::typeIncompatible(Arg.getType()));
 }
 
+// Check if the module attribute is present and not zero.
+static bool isModuleAttributeSet(Module &M, const StringRef &ModAttr) {
+  const auto *Attr =
+  mdconst::extract_or_null(M.getModuleFlag(ModAttr));
+  return Attr && !Attr->isZero();
+}
+
+// Check if the function attribute is not present and set it.
+static void SetFunctionAttrIfNotSet(Function &F, StringRef FnAttrName,
+StringRef Value) {
+  if (!F.hasFnAttribute(FnAttrName))
+F.addFnAttr(FnAttrName, Value);
+}
+
+void llvm::CopyModuleAttrToFunctions(Module &M) {
+  Triple T(M.getTargetTriple());
+  if (!T.isThumb() && !T.isARM() && !T.isAArch64())
+return;
+
+  StringRef SignTypeValue = "none";
+  if (isModuleAttributeSet(M, "sign-return-address-all"))
+SignTypeValue = "all";
+  else if (isModuleAttributeSet(M, "sign-return-address"))
+SignTypeValue = "non-leaf";
+
+  StringRef BTEValue =
+  isModuleAttributeSet(M, "branch-target-enforcement") ? "true" : "false";
+  StringRef BPPLValue =
+  isModuleAttributeSet(M, "branch-protection-pauth-lr") ? "true" : "false";
+  StringRef GCSValue =
+  isModuleAttributeSet(M, "guarded-control-st

[clang] Reland Print library module manifest path again (PR #84881)

2024-03-19 Thread Mark de Wever via cfe-commits

mordante wrote:

> > > > The file we're looking for is `modules.json`; Renaming it 
> > > > `libc++.modules.json` like `.so` / `.a` file might be a better idea 
> > > > which could avoid name clashes when installed in `/usr/lib`.
> > > 
> > > 
> > > but i didn't rename it, it was with the libc++ prefix directly :/
> > 
> > 
> > Good point I did :-/ It seems we originally talked about `modules.json` and 
> > later mentioned using the libname. @ChuanqiXu9 I prefer to keep the current 
> > name `libc++.modules.json` and adjust clang. WDYT?
> 
> Could you elaborate the reason more? I feel like renaming 
> `libc++.modules.json` to `modules.json` is straightforward. Maybe I didn't 
> take part it in the old disscussion or I missed : )

It would allow to install libstdc++ and libc++ in the same lib directory 
without "fighting" who owns `modules.json`. Also if we want to provide 
`libc++-asan.so` in the future we can provide `libc++-asan.modules.json`. 
Whether we need a different `module.json` for ASan is unknown at the moment, 
but I can imagine we have additional compiler or linker flags for ASan. 

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


[clang] [clang-tools-extra] [libcxx] [clang] Enable sized deallocation by default in C++14 onwards (PR #83774)

2024-03-19 Thread Wang Pengcheng via cfe-commits

wangpc-pp wrote:

> > > There is a Windows failure that I can't reproduce: 
> > > https://buildkite.com/llvm-project/github-pull-requests/builds/46331 Can 
> > > someone help me to figure out what is wrong?
> > 
> > 
> > I'm not certain what's going on yet, but it smells a bit like the 
> > interpreter needs to know about sized deallocations now being on by default 
> > (this may be exposing an existing bug rather than introducing a new one).
> > CC @vgvassilev
> 
> I am shooting in the dark here, too. Can you forward declare the new operator 
> delete here:
> 
> https://github.com/llvm/llvm-project/blob/e2e3624fae669f85de1445bf7037ff29feb30905/clang/lib/Interpreter/Interpreter.cpp#L262

It's still failing. :-(

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


[clang] [clang-tools-extra] [libcxx] [clang] Enable sized deallocation by default in C++14 onwards (PR #83774)

2024-03-19 Thread Mark de Wever via cfe-commits


@@ -1227,12 +1227,11 @@ C++14 implementation status
 
 
 
-(7): In Clang 3.7 and later, sized deallocation is only 
enabled
-if the user passes the -fsized-deallocation flag. The user must
-supply definitions of the sized deallocation functions, either by providing 
them
-explicitly or by using a C++ standard library that does. libstdc++
-added these functions in version 5.0, and libc++ added them in
-version 3.7.
+(7): The user must supply definitions of the sized 
deallocation
+  functions, either by providing them explicitly or by using a C++ standard 
library
+  that does. libstdc++ added these functions in version 5.0, and
+  libc++ added them in version 3.7. The user can also use the
+  -fno-sized-deallocation option to disable sized deallocation.

mordante wrote:

I'm not entirely sure what the question is. If the question is do we allow 
users to provide their own definition of the sized allocation function, then 
the answer is yes. http://eel.is/c++draft/replacement.functions.

I'm not sure whether we still need to mention the versions of libc++ and 
libstdc++; I expect when people use Clang 19 they have a somewhat recent std 
lib. (Especially since building Clang requires C++17.)

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


[clang] d712c5e - [clang][dataflow] Make optional checker work for types derived from optional. (#84138)

2024-03-19 Thread via cfe-commits

Author: martinboehme
Date: 2024-03-19T12:53:50+01:00
New Revision: d712c5ed8fab4940ae0480e01fc72a944cbb79e6

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

LOG: [clang][dataflow] Make optional checker work for types derived from 
optional. (#84138)

`llvm::MaybeAlign` does this, for example.

It's not an option to simply ignore these derived classes because they
get cast
back to the optional classes (for example, simply when calling the
optional
member functions), and our transfer functions will then run on those
optional
classes and therefore require them to be properly initialized.

Added: 


Modified: 
clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp

Removed: 




diff  --git 
a/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp 
b/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
index 1d31b22b6d25ff..dbf4878622eba9 100644
--- a/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
@@ -64,39 +64,125 @@ static bool hasOptionalClassName(const CXXRecordDecl &RD) {
   return false;
 }
 
+static const CXXRecordDecl *getOptionalBaseClass(const CXXRecordDecl *RD) {
+  if (RD == nullptr)
+return nullptr;
+  if (hasOptionalClassName(*RD))
+return RD;
+
+  if (!RD->hasDefinition())
+return nullptr;
+
+  for (const CXXBaseSpecifier &Base : RD->bases())
+if (const CXXRecordDecl *BaseClass =
+getOptionalBaseClass(Base.getType()->getAsCXXRecordDecl()))
+  return BaseClass;
+
+  return nullptr;
+}
+
 namespace {
 
 using namespace ::clang::ast_matchers;
 using LatticeTransferState = TransferState;
 
-AST_MATCHER(CXXRecordDecl, hasOptionalClassNameMatcher) {
-  return hasOptionalClassName(Node);
+AST_MATCHER(CXXRecordDecl, optionalClass) { return hasOptionalClassName(Node); 
}
+
+AST_MATCHER(CXXRecordDecl, optionalOrDerivedClass) {
+  return getOptionalBaseClass(&Node) != nullptr;
 }
 
-DeclarationMatcher optionalClass() {
-  return classTemplateSpecializationDecl(
-  hasOptionalClassNameMatcher(),
-  hasTemplateArgument(0, refersToType(type().bind("T";
+auto desugarsToOptionalType() {
+  return hasUnqualifiedDesugaredType(
+  recordType(hasDeclaration(cxxRecordDecl(optionalClass();
 }
 
-auto optionalOrAliasType() {
+auto desugarsToOptionalOrDerivedType() {
   return hasUnqualifiedDesugaredType(
-  recordType(hasDeclaration(optionalClass(;
+  recordType(hasDeclaration(cxxRecordDecl(optionalOrDerivedClass();
+}
+
+auto hasOptionalType() { return hasType(desugarsToOptionalType()); }
+
+/// Matches any of the spellings of the optional types and sugar, aliases,
+/// derived classes, etc.
+auto hasOptionalOrDerivedType() {
+  return hasType(desugarsToOptionalOrDerivedType());
+}
+
+QualType getPublicType(const Expr *E) {
+  auto *Cast = dyn_cast(E->IgnoreParens());
+  if (Cast == nullptr || Cast->getCastKind() != CK_UncheckedDerivedToBase) {
+QualType Ty = E->getType();
+if (Ty->isPointerType())
+  return Ty->getPointeeType();
+return Ty;
+  }
+
+  // Is the derived type that we're casting from the type of `*this`? In this
+  // special case, we can upcast to the base class even if the base is
+  // non-public.
+  bool CastingFromThis = isa(Cast->getSubExpr());
+
+  // Find the least-derived type in the path (i.e. the last entry in the list)
+  // that we can access.
+  const CXXBaseSpecifier *PublicBase = nullptr;
+  for (const CXXBaseSpecifier *Base : Cast->path()) {
+if (Base->getAccessSpecifier() != AS_public && !CastingFromThis)
+  break;
+PublicBase = Base;
+CastingFromThis = false;
+  }
+
+  if (PublicBase != nullptr)
+return PublicBase->getType();
+
+  // We didn't find any public type that we could cast to. There may be more
+  // casts in `getSubExpr()`, so recurse. (If there aren't any more casts, this
+  // will return the type of `getSubExpr()`.)
+  return getPublicType(Cast->getSubExpr());
 }
 
-/// Matches any of the spellings of the optional types and sugar, aliases, etc.
-auto hasOptionalType() { return hasType(optionalOrAliasType()); }
+// Returns the least-derived type for the receiver of `MCE` that
+// `MCE.getImplicitObjectArgument()->IgnoreParentImpCasts()` can be downcast 
to.
+// Effectively, we upcast until we reach a non-public base class, unless that
+// base is a base of `*this`.
+//
+// This is needed to correctly match methods called on types derived from
+// `std::optional`.
+//
+// Say we have a `struct Derived : public std::optional {} d;` For a call
+// `d.has_value()`, the `getImplicitObjectArgument()` looks lik

[clang] [clang][dataflow] Make optional checker work for types derived from optional. (PR #84138)

2024-03-19 Thread via cfe-commits

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


[clang] [clang][NFC] Add documentation for `CastExpr::path()`. (PR #85623)

2024-03-19 Thread Timm Baeder via cfe-commits

tbaederr wrote:

> I've moved the documentation down, right above the declaration of `path()`. 
> WDYT?

I think that should work.

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


[clang] [Clang][Sema] Diagnose class member access expressions naming non-existent members of the current instantiation prior to instantiation in the absence of dependent base classes (PR #84050)

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

sdkrystian wrote:

@erichkeane This PR is in a more "ready" state now, if you'd like to take 
another look. The added overload of `LookupTemplateName` which has no 
`MemberOfUnknownSpecialization` parameter it more of an experimental change... 
it can be ignored. 

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


[clang] afec08e - [clang] Add `intrin0.h` header to mimic `intrin0.h` used by MSVC STL for clang-cl (#75711)

2024-03-19 Thread via cfe-commits

Author: Max Winkler
Date: 2024-03-19T08:30:54-04:00
New Revision: afec08ef9f1015ea3fe8d67b92acfbb7837c6e9f

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

LOG: [clang] Add `intrin0.h` header to mimic `intrin0.h` used by MSVC STL for 
clang-cl (#75711)

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

 Description 

Provide `intrin0.h` to be the minimal set of intrinsics that the MSVC
STL requires.
The `intrin0.h` header matches the latest header provided by MSVC 1939
which does include some extra intrinsics that the MSVC STL does not use.

Inside `BuiltinHeaders.def` I kept the header description as `intrin.h`.
If you want me to change those to `intrin0.h` for the moved intrinsics
let me know.

This should now allow `immintrin.h` to be used with function targets for
runtime cpu detection of simd instruction sets without worrying about
the compile-time overhead from MSVC STL including `intrin.h` on clang.

I still need to figure out how to best update MSVC STL to detect for the
presence of `intrin0.h` from clang and to use this header over
`intrin.h`.

 Testing 

Built clang locally and ran the test suite. I still need to do a pass
over the existing unit tests for the ms intrinsics to make sure there
aren't any gaps. Wanted to get this PR up for discussion first.

Modified latest MSVC STL from github to point to `intrin0.h` for clang.

Wrote some test files that included MSVC STL headers that rely on
intrinsics such as `atomic`, `bit` and `vector`. Built the unit tests
against x86, arm, aarch64, and x64.

 Benchmarks 

The following include times are based on the x64 target with the
modified headers in this PR.
These timings were done by using `clang-cl.exe -ftime-trace` and taking
the wall time for parsing `intrin.h` and `intrin0.h`.

`intrin.h` takes ~897ms to parse.
`intrin0.h` takes ~1ms to parse.

If there is anything required or a different approach is preferred let
me know. I would very much like to move this over the finish line so we
can use function targets with clang-cl.

Added: 
clang/lib/Headers/intrin0.h
clang/lib/Headers/yvals_core.h

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Headers/CMakeLists.txt
clang/lib/Headers/bmiintrin.h
clang/lib/Headers/immintrin.h
clang/lib/Headers/intrin.h
clang/lib/Headers/keylockerintrin.h
clang/lib/Headers/x86gprintrin.h
clang/lib/Headers/x86intrin.h

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index dab7e1bf369754..5372a575071c0c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -454,6 +454,26 @@ Android Support
 Windows Support
 ^^^
 
+- Clang-cl now supports function targets with intrinsic headers. This allows
+  for runtime feature detection of intrinsics. Previously under clang-cl
+  ``immintrin.h`` and similar intrinsic headers would only include the 
intrinsics
+  if building with that feature enabled at compile time, e.g. ``avxintrin.h``
+  would only be included if AVX was enabled at compile time. This was done to 
work
+  around include times from MSVC STL including ``intrin.h`` under clang-cl.
+  Clang-cl now provides ``intrin0.h`` for MSVC STL and therefore all intrinsic
+  features without requiring enablement at compile time.
+  Fixes: (`#53520 `_)
+
+- Improved compile times with MSVC STL. MSVC provides ``intrin0.h`` which is a
+  header that only includes intrinsics that are used by MSVC STL to avoid the
+  use of ``intrin.h``. MSVC STL when compiled under clang uses ``intrin.h``
+  instead. Clang-cl now provides ``intrin0.h`` for the same compiler throughput
+  purposes as MSVC. Clang-cl also provides ``yvals_core.h`` to redefine
+  ``_STL_INTRIN_HEADER`` to expand to ``intrin0.h`` instead of ``intrin.h``.
+  This also means that if all intrinsic features are enabled at compile time
+  including STL headers will no longer slow down compile times since 
``intrin.h``
+  is not included from MSVC STL.
+
 LoongArch Support
 ^
 

diff  --git a/clang/lib/Headers/CMakeLists.txt 
b/clang/lib/Headers/CMakeLists.txt
index 902e33bb95897c..97104ccd8db59c 100644
--- a/clang/lib/Headers/CMakeLists.txt
+++ b/clang/lib/Headers/CMakeLists.txt
@@ -254,8 +254,10 @@ set(x86_files
   )
 
 set(windows_only_files
+  intrin0.h
   intrin.h
   vadefs.h
+  yvals_core.h
 )
 
 set(utility_files

diff  --git a/clang/lib/Headers/bmiintrin.h b/clang/lib/Headers/bmiintrin.h
index d8e57c0cb49404..78bffe68e221a9 100644
--- a/clang/lib/Headers/bmiintrin.h
+++ b/clang/lib/Headers/bmiintrin.h
@@ -161,8 +161,7 @@ _mm_tzcnt_64(unsigned long long __X)
 
 #undef __RELAXED_FN_ATTRS
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_fe

[clang] [clang] Add `intrin0.h` header to mimic `intrin0.h` used by MSVC STL for clang-cl (PR #75711)

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

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


[clang] [clang] Add `intrin0.h` header to mimic `intrin0.h` used by MSVC STL for clang-cl (PR #75711)

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

AaronBallman wrote:

> @AaronBallman Can you merge this please? We are eagerly waiting for this to 
> end up in a release! ;-)

Thank you for the ping, this fell off my radar!

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


[clang] [clang][Tooling] Add special symbol mappings for C, starting with size_t (PR #85784)

2024-03-19 Thread kadir çetinkaya via cfe-commits

https://github.com/kadircet created 
https://github.com/llvm/llvm-project/pull/85784

None

From 8b12e22a01058bcfdcf211b1f64d192d7c5f8463 Mon Sep 17 00:00:00 2001
From: Kadir Cetinkaya 
Date: Tue, 19 Mar 2024 13:33:35 +0100
Subject: [PATCH] [clang][Tooling] Add special symbol mappings for C, starting
 with size_t

---
 .../Tooling/Inclusions/Stdlib/CSpecialSymbolMap.inc  |  8 
 .../Tooling/Inclusions/Stdlib/StandardLibrary.cpp|  3 ++-
 clang/unittests/Tooling/StandardLibraryTest.cpp  | 12 
 3 files changed, 22 insertions(+), 1 deletion(-)
 create mode 100644 clang/lib/Tooling/Inclusions/Stdlib/CSpecialSymbolMap.inc

diff --git a/clang/lib/Tooling/Inclusions/Stdlib/CSpecialSymbolMap.inc 
b/clang/lib/Tooling/Inclusions/Stdlib/CSpecialSymbolMap.inc
new file mode 100644
index 00..1d9c294d207970
--- /dev/null
+++ b/clang/lib/Tooling/Inclusions/Stdlib/CSpecialSymbolMap.inc
@@ -0,0 +1,8 @@
+//===-- StdSpecialSymbolMap.inc ---*- C 
-*-===//
+//
+// This is a hand-curated list for C symbols that cannot be parsed/extracted
+// via the include-mapping tool (gen_std.py).
+//
+//===--===//
+
+SYMBOL(size_t, None, )
diff --git a/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp 
b/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
index adf1b230ff0318..386094fc2992e1 100644
--- a/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
+++ b/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
@@ -55,11 +55,12 @@ static const SymbolHeaderMapping *getMappingPerLang(Lang L) 
{
 }
 
 static int countSymbols(Lang Language) {
-  ArrayRef Symbols;
+  ArrayRef Symbols;
 #define SYMBOL(Name, NS, Header) #NS #Name,
   switch (Language) {
   case Lang::C: {
 static constexpr const char *CSymbols[] = {
+#include "CSpecialSymbolMap.inc"
 #include "CSymbolMap.inc"
 };
 Symbols = CSymbols;
diff --git a/clang/unittests/Tooling/StandardLibraryTest.cpp 
b/clang/unittests/Tooling/StandardLibraryTest.cpp
index edca31649accfa..d93b7d1af82d37 100644
--- a/clang/unittests/Tooling/StandardLibraryTest.cpp
+++ b/clang/unittests/Tooling/StandardLibraryTest.cpp
@@ -185,6 +185,18 @@ TEST(StdlibTest, RecognizerForC99) {
 stdlib::Symbol::named("", "uint8_t", stdlib::Lang::C));
 }
 
+TEST(StdlibTest, SpecialCMappings) {
+  TestInputs Input("typedef char size_t;");
+  Input.Language = TestLanguage::Lang_C99;
+  TestAST AST(Input);
+
+  auto &SizeT = lookup(AST, "size_t");
+  stdlib::Recognizer Recognizer;
+  auto ActualSym = Recognizer(&SizeT);
+  EXPECT_EQ(ActualSym, stdlib::Symbol::named("", "size_t", stdlib::Lang::C));
+  EXPECT_EQ(ActualSym->header()->name(), "");
+}
+
 } // namespace
 } // namespace tooling
 } // namespace clang

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


[clang] [clang][Tooling] Add special symbol mappings for C, starting with size_t (PR #85784)

2024-03-19 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: kadir çetinkaya (kadircet)


Changes



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


3 Files Affected:

- (added) clang/lib/Tooling/Inclusions/Stdlib/CSpecialSymbolMap.inc (+8) 
- (modified) clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp (+2-1) 
- (modified) clang/unittests/Tooling/StandardLibraryTest.cpp (+12) 


``diff
diff --git a/clang/lib/Tooling/Inclusions/Stdlib/CSpecialSymbolMap.inc 
b/clang/lib/Tooling/Inclusions/Stdlib/CSpecialSymbolMap.inc
new file mode 100644
index 00..1d9c294d207970
--- /dev/null
+++ b/clang/lib/Tooling/Inclusions/Stdlib/CSpecialSymbolMap.inc
@@ -0,0 +1,8 @@
+//===-- StdSpecialSymbolMap.inc ---*- C 
-*-===//
+//
+// This is a hand-curated list for C symbols that cannot be parsed/extracted
+// via the include-mapping tool (gen_std.py).
+//
+//===--===//
+
+SYMBOL(size_t, None, )
diff --git a/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp 
b/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
index adf1b230ff0318..386094fc2992e1 100644
--- a/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
+++ b/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
@@ -55,11 +55,12 @@ static const SymbolHeaderMapping *getMappingPerLang(Lang L) 
{
 }
 
 static int countSymbols(Lang Language) {
-  ArrayRef Symbols;
+  ArrayRef Symbols;
 #define SYMBOL(Name, NS, Header) #NS #Name,
   switch (Language) {
   case Lang::C: {
 static constexpr const char *CSymbols[] = {
+#include "CSpecialSymbolMap.inc"
 #include "CSymbolMap.inc"
 };
 Symbols = CSymbols;
diff --git a/clang/unittests/Tooling/StandardLibraryTest.cpp 
b/clang/unittests/Tooling/StandardLibraryTest.cpp
index edca31649accfa..d93b7d1af82d37 100644
--- a/clang/unittests/Tooling/StandardLibraryTest.cpp
+++ b/clang/unittests/Tooling/StandardLibraryTest.cpp
@@ -185,6 +185,18 @@ TEST(StdlibTest, RecognizerForC99) {
 stdlib::Symbol::named("", "uint8_t", stdlib::Lang::C));
 }
 
+TEST(StdlibTest, SpecialCMappings) {
+  TestInputs Input("typedef char size_t;");
+  Input.Language = TestLanguage::Lang_C99;
+  TestAST AST(Input);
+
+  auto &SizeT = lookup(AST, "size_t");
+  stdlib::Recognizer Recognizer;
+  auto ActualSym = Recognizer(&SizeT);
+  EXPECT_EQ(ActualSym, stdlib::Symbol::named("", "size_t", stdlib::Lang::C));
+  EXPECT_EQ(ActualSym->header()->name(), "");
+}
+
 } // namespace
 } // namespace tooling
 } // namespace clang

``




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


[clang] Add support for builtin_verbose_trap (PR #79230)

2024-03-19 Thread Paul T Robinson via cfe-commits


@@ -0,0 +1,49 @@
+// RUN: %clang_cc1 -triple arm64-apple-ios -std=c++20 -emit-llvm 
-debug-info-kind=limited %s -o - | FileCheck %s

pogo59 wrote:

If you want to test optimization behavior, that would be an LLVM test starting 
from IR. Clang itself does not optimize and so should not test optimization 
behavior.

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


[clang] [clang][Tooling] Add special symbol mappings for C, starting with size_t (PR #85784)

2024-03-19 Thread Haojian Wu via cfe-commits

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


[clang] [clang][Tooling] Add special symbol mappings for C, starting with size_t (PR #85784)

2024-03-19 Thread Haojian Wu via cfe-commits


@@ -0,0 +1,8 @@
+//===-- StdSpecialSymbolMap.inc ---*- C 
-*-===//
+//
+// This is a hand-curated list for C symbols that cannot be parsed/extracted
+// via the include-mapping tool (gen_std.py).
+//
+//===--===//
+
+SYMBOL(size_t, None, )

hokein wrote:

I think we probably want to list all alternative headers as listed in 
https://en.cppreference.com/w/c/types/size_t. (we do it for C++ symbol as well.)

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


  1   2   3   4   5   >