[clang] [clang][NFC] Regroup declarations in `Sema` (PR #82217)

2024-02-18 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

I've built doxygen documentation locally. Now I see what I expected so see 
(proper member groups).

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


[clang] [clang][NFC] Regroup declarations in `Sema` (PR #82217)

2024-02-18 Thread Vlad Serebrennikov via cfe-commits

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


[clang] [Clang] CXXConstructExpr may be immediate calls. (PR #82179)

2024-02-18 Thread via cfe-commits

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


[clang] 9d3d6ec - [Clang] CXXConstructExpr may be immediate calls. (#82179)

2024-02-18 Thread via cfe-commits

Author: cor3ntin
Date: 2024-02-19T08:45:38+01:00
New Revision: 9d3d6ec665d6284b6ba8c51a57a4a618d67a1697

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

LOG: [Clang] CXXConstructExpr may be immediate calls. (#82179)

A CXXConstructExpr may refer to an immediate constructor, in which case
it should be substituted in the
enclosing default init expression.

Fixes #82154

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaExpr.cpp
clang/test/CodeGenCXX/cxx2a-consteval.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 06c7d57d73ca70..45ace4191592d3 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -265,6 +265,8 @@ Bug Fixes to C++ Support
 - No longer reject valid use of the ``_Alignas`` specifier when declaring a
   local variable, which is supported as a C11 extension in C++. Previously, it
   was only accepted at namespace scope but not at local function scope.
+- Clang no longer tries to call consteval constructors at runtime when they 
appear in a member initializer.
+  (`#782154 `_`)
 
 Bug Fixes to AST Handling
 ^

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 4049ab3bf6cafb..37a7db889a6eac 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -6201,6 +6201,12 @@ struct ImmediateCallVisitor : public 
RecursiveASTVisitor {
 return RecursiveASTVisitor::VisitStmt(E);
   }
 
+  bool VisitCXXConstructExpr(CXXConstructExpr *E) {
+if (const FunctionDecl *FD = E->getConstructor())
+  HasImmediateCalls |= FD->isImmediateFunction();
+return RecursiveASTVisitor::VisitStmt(E);
+  }
+
   // SourceLocExpr are not immediate invocations
   // but CXXDefaultInitExpr/CXXDefaultArgExpr containing a SourceLocExpr
   // need to be rebuilt so that they refer to the correct SourceLocation and

diff  --git a/clang/test/CodeGenCXX/cxx2a-consteval.cpp 
b/clang/test/CodeGenCXX/cxx2a-consteval.cpp
index 06f1d512accec5..075cab58358abf 100644
--- a/clang/test/CodeGenCXX/cxx2a-consteval.cpp
+++ b/clang/test/CodeGenCXX/cxx2a-consteval.cpp
@@ -258,3 +258,20 @@ void void_call() { // EVAL-FN-LABEL: define {{.*}} 
@_Z9void_call
   void_test();
   // EVAL-FN: {{^}}}
 }
+
+
+namespace GH82154 {
+struct S1 { consteval S1(int) {} };
+struct S3 { constexpr S3(int) {} };
+
+void f() {
+struct S2 {
+S1 s = 0;
+S3 s2 = 0;
+};
+S2 s;
+// EVAL-FN-LABEL: define {{.*}} void @_ZZN7GH821541fEvEN2S2C2Ev
+// EVAL-FN-NOT: call void @_ZN7GH821542S1C2Ei
+// EVAL-FN: call void @_ZN7GH821542S3C2Ei
+}
+}



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


[clang] [llvm] [AMDGPU] Emit a waitcnt instruction after each memory instruction (PR #79236)

2024-02-18 Thread Pierre van Houtryve via cfe-commits


@@ -167,6 +167,10 @@ def FeatureCuMode : SubtargetFeature<"cumode",
   "Enable CU wavefront execution mode"
 >;
 
+def FeaturePreciseMemory

Pierre-vh wrote:

The extra overhead is just 3 lines in `clang/lib/Driver/ToolChains/AMDGPU.cpp`, 
it's negligible.
We don't have any target feature that starts with `amdgpu` so it's out of place 
IMO, it should really drop the `amdgpu-` prefix.

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


[clang] [llvm] [AMDGPU] Emit a waitcnt instruction after each memory instruction (PR #79236)

2024-02-18 Thread Pierre van Houtryve via cfe-commits


@@ -355,6 +356,18 @@ class SICacheControl {
MachineBasicBlock::iterator ) const {
 return false;
   }
+
+public:
+  // The following is for supporting precise memory mode. When the option
+  // amdgpu-precise-memory is enabled, an s_waitcnt instruction is inserted
+  // after each memory instruction.
+
+  virtual bool
+  handleNonAtomicForPreciseMemory(MachineBasicBlock::iterator ) = 0;
+  /// Handles atomic instruction \p MI with \p IsAtomicWithRet indicating
+  /// whether \p MI returns a result.

Pierre-vh wrote:

IMO the comment isn't needed, I think the function's name describes it well 
enough (and the comment just before adds enough context), the comment just 
rephrases the function + argument names

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


[clang] [llvm] [AMDGPU] Emit a waitcnt instruction after each memory instruction (PR #79236)

2024-02-18 Thread Pierre van Houtryve via cfe-commits

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


[clang] [llvm] [AMDGPU] Emit a waitcnt instruction after each memory instruction (PR #79236)

2024-02-18 Thread Pierre van Houtryve via cfe-commits

https://github.com/Pierre-vh requested changes to this pull request.

Did you try to move this to SIInsertWaitCnt, as suggested?

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


[clang] [clangd] Fix C++20 modules crash (PR #81919)

2024-02-18 Thread via cfe-commits

h-vetinari wrote:

> A test will be helpful for us to understand what happened.

There's a reproducer in https://github.com/llvm/llvm-project/issues/80570

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


[clang] [OpenMP][Clang] Enable inscan modifier for generic datatypes (PR #82220)

2024-02-18 Thread Saiyedul Islam via cfe-commits

https://github.com/saiislam commented:

May be merge the two PRs in one?
They both are not independent.

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


[clang] [clang][NFC] Regroup declarations in `Sema` (PR #82217)

2024-02-18 Thread Vlad Serebrennikov via cfe-commits

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


[clang] [OpenMP][Clang] Enable inscan modifier for generic datatypes (PR #82220)

2024-02-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Animesh Kumar (animeshk-amd)


Changes

This patch fixes the #67002 ([OpenMP][Clang] Scan Directive not 
supported for Generic types). It disables the Sema checks/analysis that are run 
on the helper arrays which go into the implementation of the `omp scan` 
directive until the template instantiation happens.
Grateful to @alexey-bataev for suggesting these changes.

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


1 Files Affected:

- (modified) clang/lib/Sema/SemaOpenMP.cpp (+2-1) 


``diff
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 7f75cfc5b54f35..f4364a259ad57f 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -4962,7 +4962,8 @@ StmtResult Sema::ActOnOpenMPRegionEnd(StmtResult S,
   if (RC->getModifier() != OMPC_REDUCTION_inscan)
 continue;
   for (Expr *E : RC->copy_array_temps())
-MarkDeclarationsReferencedInExpr(E);
+if (E)
+  MarkDeclarationsReferencedInExpr(E);
 }
 if (auto *AC = dyn_cast(C)) {
   for (Expr *E : AC->varlists())

``




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


[clang] [OpenMP][Clang] Enable inscan modifier for generic datatypes (PR #82220)

2024-02-18 Thread Animesh Kumar via cfe-commits

https://github.com/animeshk-amd created 
https://github.com/llvm/llvm-project/pull/82220

This patch fixes the #67002 ([OpenMP][Clang] Scan Directive not supported for 
Generic types). It disables the Sema checks/analysis that are run on the helper 
arrays which go into the implementation of the `omp scan` directive until the 
template instantiation happens.
Grateful to @alexey-bataev for suggesting these changes.

>From 92ce8475d7c5b30d1c46f11cb85707b6e7d70f71 Mon Sep 17 00:00:00 2001
From: Animesh Kumar 
Date: Mon, 19 Feb 2024 00:28:39 -0600
Subject: [PATCH] [OpenMP][Clang] Enable inscan modifier for generic datatypes

This patch fixes the #67002 ([OpenMP][Clang] Scan Directive not
supported for Generic types). It disables the Sema checks/analysis
that are run on the helper arrays which go into the implementation
of the `omp scan` directive until the template instantiation
happens.
---
 clang/lib/Sema/SemaOpenMP.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 7f75cfc5b54f35..f4364a259ad57f 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -4962,7 +4962,8 @@ StmtResult Sema::ActOnOpenMPRegionEnd(StmtResult S,
   if (RC->getModifier() != OMPC_REDUCTION_inscan)
 continue;
   for (Expr *E : RC->copy_array_temps())
-MarkDeclarationsReferencedInExpr(E);
+if (E)
+  MarkDeclarationsReferencedInExpr(E);
 }
 if (auto *AC = dyn_cast(C)) {
   for (Expr *E : AC->varlists())

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


[clang] [clang][NFC] Regroup declarations in `Sema` (PR #82217)

2024-02-18 Thread Vlad Serebrennikov via cfe-commits

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


[clang] [clang][NFC] Regroup declarations in `Sema` (PR #82217)

2024-02-18 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 dd7386d85f11cf6ad911b9827c7018fb08c6c205 
681cecc15a472aede4c6d4bf1e75c755fdcce3e5 -- clang/include/clang/Sema/Sema.h 
clang/lib/Sema/Sema.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index e039f97198..d28987db2d 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3967,7 +3967,7 @@ public:
 const ProcessDeclAttributeOptions  =
 ProcessDeclAttributeOptions());
   bool ProcessAccessDeclAttributeList(AccessSpecDecl *ASDecl,
-   const ParsedAttributesView );
+  const ParsedAttributesView );
 
   void checkUnusedDeclAttributes(Declarator );
 

``




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


[clang] [clang][NFC] Regroup declarations in `Sema` (PR #82217)

2024-02-18 Thread Vlad Serebrennikov via cfe-commits

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


[clang] [clang][NFC] Regroup declarations in `Sema` (PR #82217)

2024-02-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Vlad Serebrennikov (Endilll)


Changes

This patch regroups declarations in `Sema` based on the file they are 
implemented in (e.g. `SemaChecking.cpp`). This allows to logically split `Sema` 
in 42 groups. Table of contents added at the very beginning of `Sema`.

While grouping is intentional, as well as each group consisting of `public` 
declarations followed by `private` ones (without changing access in-between), 
exact contents and order of declarations of each group is partially carried 
over from old structure, partially accidental due to time constrains to do the 
regrouping over the weekend (`Sema` is just enormously big). Further work is 
expected to refine contents and order of declarations.

What is also intentional is some kind of layering, where Concepts group follows 
template groups, and ObjC, code completion, CUDA, HLSL, OpenACC, OpenMP, and 
SYCL are all placed at the end of the file, after C and C++ parts of `Sema`.

Member initializer list of `Sema` in `Sema.cpp` is rewritten to reflect new 
order of data members in order to avoid `-Wreorder-ctor`.

---

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


2 Files Affected:

- (modified) clang/include/clang/Sema/Sema.h (+11441-11193) 
- (modified) clang/lib/Sema/Sema.cpp (+19-19) 


``diff
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index e9cd42ae777df5..e039f9719826d3 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -423,590 +423,650 @@ enum class TemplateDeductionResult {
 
 /// Sema - This implements semantic analysis and AST building for C.
 class Sema final {
-  Sema(const Sema &) = delete;
-  void operator=(const Sema &) = delete;
-
-  ///Source of additional semantic information.
-  IntrusiveRefCntPtr ExternalSource;
-
-  static bool mightHaveNonExternalLinkage(const DeclaratorDecl *FD);
-
-  /// Determine whether two declarations should be linked together, given that
-  /// the old declaration might not be visible and the new declaration might
-  /// not have external linkage.
-  bool shouldLinkPossiblyHiddenDecl(const NamedDecl *Old,
-const NamedDecl *New) {
-if (isVisible(Old))
- return true;
-// See comment in below overload for why it's safe to compute the linkage
-// of the new declaration here.
-if (New->isExternallyDeclarable()) {
-  assert(Old->isExternallyDeclarable() &&
- "should not have found a non-externally-declarable previous 
decl");
-  return true;
-}
-return false;
-  }
-  bool shouldLinkPossiblyHiddenDecl(LookupResult , const NamedDecl *New);
-
-  void setupImplicitSpecialMemberType(CXXMethodDecl *SpecialMem,
-  QualType ResultTy,
-  ArrayRef Args);
+  // Table of Contents
+  // -
+  // 1. Semantic Analysis (Sema.cpp)
+  // 2. C++ Access Control (SemaAccess.cpp)
+  // 3. Attributes (SemaAttr.cpp)
+  // 4. Availability Attribute Handling (SemaAvailability.cpp)
+  // 5. Casts (SemaCast.cpp)
+  // 6. Extra Semantic Checking (SemaChecking.cpp)
+  // 7. C++ Coroutines (SemaCoroutine.cpp)
+  // 8. C++ Scope Specifiers (SemaCXXScopeSpec.cpp)
+  // 9. Declarations (SemaDecl.cpp)
+  // 10. Declaration Attribute Handling (SemaDeclAttr.cpp)
+  // 11. C++ Declarations (SemaDeclCXX.cpp)
+  // 12. C++ Exception Specifications (SemaExceptionSpec.cpp)
+  // 13. Expressions (SemaExpr.cpp)
+  // 14. C++ Expressions (SemaExprCXX.cpp)
+  // 15. Member Access Expressions (SemaExprMember.cpp)
+  // 16. Initializers (SemaInit.cpp)
+  // 17. C++ Lambda Expressions (SemaLambda.cpp)
+  // 18. Name Lookup (SemaLookup.cpp)
+  // 19. Modules (SemaModule.cpp)
+  // 20. C++ Overloading (SemaOverload.cpp)
+  // 21. Pseudo-Object (SemaPseudoObject.cpp)
+  // 22. Statements (SemaStmt.cpp)
+  // 23. `inline asm` Statement (SemaStmtAsm.cpp)
+  // 24. Statement Attribute Handling (SemaStmtAttr.cpp)
+  // 25. C++ Templates (SemaTemplate.cpp)
+  // 26. C++ Template Argument Deduction (SemaTemplateDeduction.cpp)
+  // 27. C++ Template Instantiation (SemaTemplateInstantiate.cpp)
+  // 28. C++ Template Declaration Instantiation
+  // (SemaTemplateInstantiateDecl.cpp)
+  // 29. C++ Variadic Templates (SemaTemplateVariadic.cpp)
+  // 30. Constraints and Concepts (SemaConcept.cpp)
+  // 31. Types (SemaType.cpp)
+  // 32. ObjC Declarations (SemaDeclObjC.cpp)
+  // 33. ObjC Expressions (SemaExprObjC.cpp)
+  // 34. ObjC @property and @synthesize (SemaObjCProperty.cpp)
+  // 35. Code Completion (SemaCodeComplete.cpp)
+  // 36. FixIt Helpers (SemaFixItUtils.cpp)
+  // 37. Name Lookup for RISC-V Vector Intrinsic (SemaRISCVVectorLookup.cpp)
+  // 38. CUDA (SemaCUDA.cpp)
+  // 39. HLSL Constructs (SemaHLSL.cpp)
+  // 40. OpenACC Constructs (SemaOpenACC.cpp)
+  // 41. OpenMP Directives and Clauses 

[clang] [Serialization] Load Specializations Lazily (PR #76774)

2024-02-18 Thread Vassil Vassilev via cfe-commits

vgvassilev wrote:

> > Let's zoom out a little. The approach in D41416 shows that it is feasible 
> > to store _a_ hash of the template arguments to delay eager 
> > deserializations. The ODR hash approach is a second order problem because 
> > we can swap it with something better once we need to. In order to make 
> > progress we have introduced [D153003](https://reviews.llvm.org/D153003) 
> > which allows our infrastructure to work. The way I see moving forward here 
> > is:
> > 
> > * Base this PR on D41416 in the approach how we model the lazy 
> > deserialization of templates. That'd mean that we "just" need to replace 
> > `LazySpecializationInfo *LazySpecializations = nullptr;` with the on-disk 
> > hash table approach. That would probably require centralizing that logic 
> > somewhere in the ASTReader (the way this PR does) but with minimal changes 
> > wrt D41416.
> > * Test the implementation on our infrastructure for correctness
> > * Test the implementation on the Google infrastructure for scalability
> > * Think on a better approach to replace odr hashing if we see more 
> > pathological problems.
> 
> Yeah, no problem at all. This is what I want in the higher level too. What I 
> am confused is about the status of 
> [D153003](https://reviews.llvm.org/D153003). If it is true that we've 
> describe the problem completely in the review page, then 
> [c31d6b4](https://github.com/llvm/llvm-project/commit/c31d6b4ef135098280b0ebb93e95b258a0d372ca)
>  should be a proper fix for that.

I can try it on our infrastructure and if it works I will remove D153003.

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


[clang] [Analyzer] Support RefAllowingPartiallyDestroyed and RefPtrAllowingPartiallyDestroyed (PR #82209)

2024-02-18 Thread Ryosuke Niwa via cfe-commits

https://github.com/rniwa updated https://github.com/llvm/llvm-project/pull/82209

>From 196ab7a875040a6b653a118b88d3e892d2256b46 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Sun, 18 Feb 2024 21:47:48 -0800
Subject: [PATCH] [Analyzer] Support RefAllowingPartiallyDestroyed and
 RefPtrAllowingPartiallyDestroyed

This PR adds the support for WebKit's RefAllowingPartiallyDestroyed and
RefPtrAllowingPartiallyDestroyed, which are smart pointer types which may be 
used
after the destructor had started running.
---
 .../Checkers/WebKit/PtrTypesSemantics.cpp | 27 +--
 .../Analysis/Checkers/WebKit/mock-types.h |  3 +-
 .../ref-allowing-partially-destroyed.cpp  | 46 +++
 3 files changed, 62 insertions(+), 14 deletions(-)
 create mode 100644 
clang/test/Analysis/Checkers/WebKit/ref-allowing-partially-destroyed.cpp

diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 6f236db0474079..6f768983edb65b 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -103,15 +103,18 @@ std::optional isRefCountable(const CXXRecordDecl* R)
   return hasRef && hasDeref;
 }
 
+bool isRefType(const std::string ) {
+  return name == "Ref" || name == "RefAllowingPartiallyDestroyed" ||
+ name == "RefPtr" || name == "RefPtrAllowingPartiallyDestroyed";
+}
+
 bool isCtorOfRefCounted(const clang::FunctionDecl *F) {
   assert(F);
   const auto  = safeGetName(F);
 
-  return FunctionName == "Ref" || FunctionName == "makeRef"
-
- || FunctionName == "RefPtr" || FunctionName == "makeRefPtr"
-
- || FunctionName == "UniqueRef" || FunctionName == "makeUniqueRef" ||
+  return isRefType(FunctionName) || FunctionName == "makeRef" ||
+ FunctionName == "makeRefPtr" || FunctionName == "UniqueRef" ||
+ FunctionName == "makeUniqueRef" ||
  FunctionName == "makeUniqueRefWithoutFastMallocCheck"
 
  || FunctionName == "String" || FunctionName == "AtomString" ||
@@ -131,7 +134,7 @@ bool isReturnValueRefCounted(const clang::FunctionDecl *F) {
 if (auto *specialT = type->getAs()) {
   if (auto *decl = specialT->getTemplateName().getAsTemplateDecl()) {
 auto name = decl->getNameAsString();
-return name == "Ref" || name == "RefPtr";
+return isRefType(name);
   }
   return false;
 }
@@ -172,20 +175,18 @@ std::optional isGetterOfRefCounted(const 
CXXMethodDecl* M)
   if (isa(M)) {
 const CXXRecordDecl *calleeMethodsClass = M->getParent();
 auto className = safeGetName(calleeMethodsClass);
-auto methodName = safeGetName(M);
+auto method = safeGetName(M);
 
-if (((className == "Ref" || className == "RefPtr") &&
- methodName == "get") ||
-(className == "Ref" && methodName == "ptr") ||
+if ((isRefType(className) && (method == "get" || method == "ptr")) ||
 ((className == "String" || className == "AtomString" ||
   className == "AtomStringImpl" || className == "UniqueString" ||
   className == "UniqueStringImpl" || className == "Identifier") &&
- methodName == "impl"))
+ method == "impl"))
   return true;
 
 // Ref -> T conversion
 // FIXME: Currently allowing any Ref -> whatever cast.
-if (className == "Ref" || className == "RefPtr") {
+if (isRefType(className)) {
   if (auto *maybeRefToRawOperator = dyn_cast(M)) {
 if (auto *targetConversionType =
 maybeRefToRawOperator->getConversionType().getTypePtrOrNull()) 
{
@@ -202,7 +203,7 @@ bool isRefCounted(const CXXRecordDecl *R) {
   if (auto *TmplR = R->getTemplateInstantiationPattern()) {
 // FIXME: String/AtomString/UniqueString
 const auto  = safeGetName(TmplR);
-return ClassName == "RefPtr" || ClassName == "Ref";
+return isRefType(ClassName);
   }
   return false;
 }
diff --git a/clang/test/Analysis/Checkers/WebKit/mock-types.h 
b/clang/test/Analysis/Checkers/WebKit/mock-types.h
index d08a997aa8c043..e43641c0c61445 100644
--- a/clang/test/Analysis/Checkers/WebKit/mock-types.h
+++ b/clang/test/Analysis/Checkers/WebKit/mock-types.h
@@ -5,9 +5,10 @@ template  struct Ref {
   T *t;
 
   Ref() : t{} {};
-  Ref(T *) {}
+  Ref(T &) {}
   T *get() { return t; }
   T *ptr() { return t; }
+  T *operator->() { return t; }
   operator const T &() const { return *t; }
   operator T &() { return *t; }
 };
diff --git 
a/clang/test/Analysis/Checkers/WebKit/ref-allowing-partially-destroyed.cpp 
b/clang/test/Analysis/Checkers/WebKit/ref-allowing-partially-destroyed.cpp
new file mode 100644
index 00..f9c0f405968231
--- /dev/null
+++ b/clang/test/Analysis/Checkers/WebKit/ref-allowing-partially-destroyed.cpp
@@ -0,0 +1,46 @@
+// RUN: %clang_analyze_cc1 
-analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s
+// expected-no-diagnostics
+
+#include 

[clang] [alpha.webkit.UncountedCallArgsChecker] Ignore calls to WTF's container methods (PR #82156)

2024-02-18 Thread Ryosuke Niwa via cfe-commits

https://github.com/rniwa updated https://github.com/llvm/llvm-project/pull/82156

>From d169fddf3896bd334bc4776059258116ac08096a Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Sun, 18 Feb 2024 01:32:00 -0800
Subject: [PATCH] [alpha.webkit.UncountedCallArgsChecker] Ignore calls to WTF's
 container methods

This PR makes the checker ignore / skip calls to methods of Web Template 
Framework's container types
such as HashMap, HashSet, WeakHashSet, WeakHashMap, Vector, etc...
---
 .../WebKit/UncountedCallArgsChecker.cpp   |  32 
 .../WebKit/call-args-wtf-containers.cpp   | 146 ++
 2 files changed, 178 insertions(+)
 create mode 100644 
clang/test/Analysis/Checkers/WebKit/call-args-wtf-containers.cpp

diff --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
index 17a64e1b1b8e04..9ed7f2a4e065d3 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
@@ -25,6 +25,11 @@ using namespace ento;
 
 namespace {
 
+bool stringEndsWith(const std::string , const std::string ) {
+  auto index = str.rfind(suffix);
+  return index != std::string::npos && str.size() - suffix.size() == index;
+}
+
 class UncountedCallArgsChecker
 : public Checker> {
   BugType Bug{this,
@@ -165,6 +170,9 @@ class UncountedCallArgsChecker
 if (!Callee)
   return false;
 
+if (isMethodOnWTFContainerType(Callee))
+  return true;
+
 auto overloadedOperatorType = Callee->getOverloadedOperator();
 if (overloadedOperatorType == OO_EqualEqual ||
 overloadedOperatorType == OO_ExclaimEqual ||
@@ -193,6 +201,30 @@ class UncountedCallArgsChecker
 return false;
   }
 
+  bool isMethodOnWTFContainerType(const FunctionDecl *Decl) const {
+if (!isa(Decl))
+  return false;
+auto *ClassDecl = Decl->getParent();
+if (!ClassDecl || !isa(ClassDecl))
+  return false;
+
+auto *NsDecl = ClassDecl->getParent();
+if (!NsDecl || !isa(NsDecl))
+  return false;
+
+auto methodName = safeGetName(Decl);
+auto clsName = safeGetName(ClassDecl);
+auto nsName = safeGetName(NsDecl);
+// FIXME: These should be implemented via attributes.
+return nsName == "WTF" &&
+   (methodName == "find" || methodName == "findIf" ||
+methodName == "reverseFind" || methodName == "reverseFindIf" ||
+methodName == "get" || methodName == "inlineGet" ||
+methodName == "contains" || methodName == "containsIf") &&
+   (stringEndsWith(clsName, "Vector") ||
+stringEndsWith(clsName, "Set") || stringEndsWith(clsName, "Map"));
+  }
+
   void reportBug(const Expr *CallArg, const ParmVarDecl *Param) const {
 assert(CallArg);
 
diff --git a/clang/test/Analysis/Checkers/WebKit/call-args-wtf-containers.cpp 
b/clang/test/Analysis/Checkers/WebKit/call-args-wtf-containers.cpp
new file mode 100644
index 00..0a63a789856127
--- /dev/null
+++ b/clang/test/Analysis/Checkers/WebKit/call-args-wtf-containers.cpp
@@ -0,0 +1,146 @@
+// RUN: %clang_analyze_cc1 
-analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s
+
+#include "mock-types.h"
+
+namespace WTF {
+
+  template 
+  class HashSet {
+  public:
+template  T* find(U&) const;
+template  bool contains(U&) const;
+unsigned size() { return m_size; }
+template  void add(U&) const;
+template  void remove(U&) const;
+
+  private:
+T* m_table { nullptr };
+unsigned m_size { 0 };
+  };
+
+  template 
+  class HashMap {
+  public:
+struct Item {
+  T key;
+  S value;
+};
+
+template  Item* find(U&) const;
+template  bool contains(U&) const;
+template  S* get(U&) const;
+template  S* inlineGet(U&) const;
+template  void add(U&) const;
+template  void remove(U&) const;
+
+  private:
+Item* m_table { nullptr };
+  };
+
+  template 
+  class WeakHashSet {
+  public:
+template  T* find(U&) const;
+template  bool contains(U&) const;
+template  void add(U&) const;
+template  void remove(U&) const;
+  };
+
+  template 
+  class Vector {
+  public:
+unsigned size() { return m_size; }
+T& at(unsigned i) { return m_buffer[i]; }
+T& operator[](unsigned i) { return m_buffer[i]; }
+template  unsigned find(U&);
+template  unsigned reverseFind(U&);
+template  bool contains(U&);
+template  unsigned findIf(const MatchFunction& 
match)
+{
+  for (unsigned i = 0; i < m_size; ++i) {
+if (match(at(i)))
+  return i;
+  }
+  return static_cast(-1);
+}
+template  unsigned reverseFindIf(const 
MatchFunction& match)
+{
+  for (unsigned i = 0; i < m_size; ++i) {
+if (match(at(m_size - i)))
+  return i;
+  }
+  return static_cast(-1);
+}
+template  bool containsIf(const MatchFunction& 
match)
+{
+  

[clang] [alpha.webkit.UncountedCallArgsChecker] Ignore calls to WTF's container methods (PR #82156)

2024-02-18 Thread Ryosuke Niwa via cfe-commits

https://github.com/rniwa updated https://github.com/llvm/llvm-project/pull/82156

>From 51b65a767eee7bae07932c073702502a701d4ef2 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Sun, 18 Feb 2024 01:32:00 -0800
Subject: [PATCH] [alpha.webkit.UncountedCallArgsChecker] Ignore calls to WTF's
 container methods

This PR makes the checker ignore / skip calls to methods of Web Template 
Framework's container types
such as HashMap, HashSet, WeakHashSet, WeakHashMap, Vector, etc...
---
 .../WebKit/UncountedCallArgsChecker.cpp   |  32 
 .../WebKit/call-args-wtf-containers.cpp   | 146 ++
 2 files changed, 178 insertions(+)
 create mode 100644 
clang/test/Analysis/Checkers/WebKit/call-args-wtf-containers.cpp

diff --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
index 17a64e1b1b8e04..0fed1e2c481332 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
@@ -25,6 +25,11 @@ using namespace ento;
 
 namespace {
 
+bool stringEndsWith(const std::string& str, const std::string ) {
+  auto index = str.rfind(suffix);
+  return index != std::string::npos && str.size() - suffix.size() == index;
+}
+
 class UncountedCallArgsChecker
 : public Checker> {
   BugType Bug{this,
@@ -165,6 +170,9 @@ class UncountedCallArgsChecker
 if (!Callee)
   return false;
 
+if (isMethodOnWTFContainerType(Callee))
+  return true;
+
 auto overloadedOperatorType = Callee->getOverloadedOperator();
 if (overloadedOperatorType == OO_EqualEqual ||
 overloadedOperatorType == OO_ExclaimEqual ||
@@ -193,6 +201,30 @@ class UncountedCallArgsChecker
 return false;
   }
 
+  bool isMethodOnWTFContainerType(const FunctionDecl *Decl) const {
+if (!isa(Decl))
+  return false;
+auto *ClassDecl = Decl->getParent();
+if (!ClassDecl || !isa(ClassDecl))
+  return false;
+
+auto *NsDecl = ClassDecl->getParent();
+if (!NsDecl || !isa(NsDecl))
+  return false;
+
+auto methodName = safeGetName(Decl);
+auto clsName = safeGetName(ClassDecl);
+auto nsName = safeGetName(NsDecl);
+// FIXME: These should be implemented via attributes.
+return nsName == "WTF" &&
+   (methodName == "find" || methodName == "findIf" ||
+methodName == "reverseFind" || methodName == "reverseFindIf" ||
+methodName == "get" || methodName == "inlineGet" ||
+methodName == "contains" || methodName == "containsIf") &&
+   (stringEndsWith(clsName, "Vector") ||
+stringEndsWith(clsName, "Set") || stringEndsWith(clsName, "Map"));
+  }
+
   void reportBug(const Expr *CallArg, const ParmVarDecl *Param) const {
 assert(CallArg);
 
diff --git a/clang/test/Analysis/Checkers/WebKit/call-args-wtf-containers.cpp 
b/clang/test/Analysis/Checkers/WebKit/call-args-wtf-containers.cpp
new file mode 100644
index 00..0a63a789856127
--- /dev/null
+++ b/clang/test/Analysis/Checkers/WebKit/call-args-wtf-containers.cpp
@@ -0,0 +1,146 @@
+// RUN: %clang_analyze_cc1 
-analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s
+
+#include "mock-types.h"
+
+namespace WTF {
+
+  template 
+  class HashSet {
+  public:
+template  T* find(U&) const;
+template  bool contains(U&) const;
+unsigned size() { return m_size; }
+template  void add(U&) const;
+template  void remove(U&) const;
+
+  private:
+T* m_table { nullptr };
+unsigned m_size { 0 };
+  };
+
+  template 
+  class HashMap {
+  public:
+struct Item {
+  T key;
+  S value;
+};
+
+template  Item* find(U&) const;
+template  bool contains(U&) const;
+template  S* get(U&) const;
+template  S* inlineGet(U&) const;
+template  void add(U&) const;
+template  void remove(U&) const;
+
+  private:
+Item* m_table { nullptr };
+  };
+
+  template 
+  class WeakHashSet {
+  public:
+template  T* find(U&) const;
+template  bool contains(U&) const;
+template  void add(U&) const;
+template  void remove(U&) const;
+  };
+
+  template 
+  class Vector {
+  public:
+unsigned size() { return m_size; }
+T& at(unsigned i) { return m_buffer[i]; }
+T& operator[](unsigned i) { return m_buffer[i]; }
+template  unsigned find(U&);
+template  unsigned reverseFind(U&);
+template  bool contains(U&);
+template  unsigned findIf(const MatchFunction& 
match)
+{
+  for (unsigned i = 0; i < m_size; ++i) {
+if (match(at(i)))
+  return i;
+  }
+  return static_cast(-1);
+}
+template  unsigned reverseFindIf(const 
MatchFunction& match)
+{
+  for (unsigned i = 0; i < m_size; ++i) {
+if (match(at(m_size - i)))
+  return i;
+  }
+  return static_cast(-1);
+}
+template  bool containsIf(const MatchFunction& 
match)
+

[clang] [Analyzer] Support RefAllowingPartiallyDestroyed and RefPtrAllowingPartiallyDestroyed (PR #82209)

2024-02-18 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 ead0a9777f8ccb5c26d50d96bade6cd5b47f496b 
d26f41816f443922569fc713d1cd919fd96ba124 -- 
clang/test/Analysis/Checkers/WebKit/ref-allowing-partially-destroyed.cpp 
clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
clang/test/Analysis/Checkers/WebKit/mock-types.h
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 1b349d48a9..6f768983ed 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -103,7 +103,7 @@ std::optional isRefCountable(const CXXRecordDecl* R)
   return hasRef && hasDeref;
 }
 
-bool isRefType(const std::string& name) {
+bool isRefType(const std::string ) {
   return name == "Ref" || name == "RefAllowingPartiallyDestroyed" ||
  name == "RefPtr" || name == "RefPtrAllowingPartiallyDestroyed";
 }

``




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


[clang] [Analyzer] Support RefAllowingPartiallyDestroyed and RefPtrAllowingPartiallyDestroyed (PR #82209)

2024-02-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Ryosuke Niwa (rniwa)


Changes

This PR adds the support for WebKit's RefAllowingPartiallyDestroyed and 
RefPtrAllowingPartiallyDestroyed, which are smart pointer types which may be 
used after the destructor had started running.

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


3 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
(+14-13) 
- (modified) clang/test/Analysis/Checkers/WebKit/mock-types.h (+2-1) 
- (added) 
clang/test/Analysis/Checkers/WebKit/ref-allowing-partially-destroyed.cpp (+46) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 6f236db0474079..1b349d48a9f881 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -103,15 +103,18 @@ std::optional isRefCountable(const CXXRecordDecl* R)
   return hasRef && hasDeref;
 }
 
+bool isRefType(const std::string& name) {
+  return name == "Ref" || name == "RefAllowingPartiallyDestroyed" ||
+ name == "RefPtr" || name == "RefPtrAllowingPartiallyDestroyed";
+}
+
 bool isCtorOfRefCounted(const clang::FunctionDecl *F) {
   assert(F);
   const auto  = safeGetName(F);
 
-  return FunctionName == "Ref" || FunctionName == "makeRef"
-
- || FunctionName == "RefPtr" || FunctionName == "makeRefPtr"
-
- || FunctionName == "UniqueRef" || FunctionName == "makeUniqueRef" ||
+  return isRefType(FunctionName) || FunctionName == "makeRef" ||
+ FunctionName == "makeRefPtr" || FunctionName == "UniqueRef" ||
+ FunctionName == "makeUniqueRef" ||
  FunctionName == "makeUniqueRefWithoutFastMallocCheck"
 
  || FunctionName == "String" || FunctionName == "AtomString" ||
@@ -131,7 +134,7 @@ bool isReturnValueRefCounted(const clang::FunctionDecl *F) {
 if (auto *specialT = type->getAs()) {
   if (auto *decl = specialT->getTemplateName().getAsTemplateDecl()) {
 auto name = decl->getNameAsString();
-return name == "Ref" || name == "RefPtr";
+return isRefType(name);
   }
   return false;
 }
@@ -172,20 +175,18 @@ std::optional isGetterOfRefCounted(const 
CXXMethodDecl* M)
   if (isa(M)) {
 const CXXRecordDecl *calleeMethodsClass = M->getParent();
 auto className = safeGetName(calleeMethodsClass);
-auto methodName = safeGetName(M);
+auto method = safeGetName(M);
 
-if (((className == "Ref" || className == "RefPtr") &&
- methodName == "get") ||
-(className == "Ref" && methodName == "ptr") ||
+if ((isRefType(className) && (method == "get" || method == "ptr")) ||
 ((className == "String" || className == "AtomString" ||
   className == "AtomStringImpl" || className == "UniqueString" ||
   className == "UniqueStringImpl" || className == "Identifier") &&
- methodName == "impl"))
+ method == "impl"))
   return true;
 
 // Ref -> T conversion
 // FIXME: Currently allowing any Ref -> whatever cast.
-if (className == "Ref" || className == "RefPtr") {
+if (isRefType(className)) {
   if (auto *maybeRefToRawOperator = dyn_cast(M)) {
 if (auto *targetConversionType =
 maybeRefToRawOperator->getConversionType().getTypePtrOrNull()) 
{
@@ -202,7 +203,7 @@ bool isRefCounted(const CXXRecordDecl *R) {
   if (auto *TmplR = R->getTemplateInstantiationPattern()) {
 // FIXME: String/AtomString/UniqueString
 const auto  = safeGetName(TmplR);
-return ClassName == "RefPtr" || ClassName == "Ref";
+return isRefType(ClassName);
   }
   return false;
 }
diff --git a/clang/test/Analysis/Checkers/WebKit/mock-types.h 
b/clang/test/Analysis/Checkers/WebKit/mock-types.h
index d08a997aa8c043..e43641c0c61445 100644
--- a/clang/test/Analysis/Checkers/WebKit/mock-types.h
+++ b/clang/test/Analysis/Checkers/WebKit/mock-types.h
@@ -5,9 +5,10 @@ template  struct Ref {
   T *t;
 
   Ref() : t{} {};
-  Ref(T *) {}
+  Ref(T &) {}
   T *get() { return t; }
   T *ptr() { return t; }
+  T *operator->() { return t; }
   operator const T &() const { return *t; }
   operator T &() { return *t; }
 };
diff --git 
a/clang/test/Analysis/Checkers/WebKit/ref-allowing-partially-destroyed.cpp 
b/clang/test/Analysis/Checkers/WebKit/ref-allowing-partially-destroyed.cpp
new file mode 100644
index 00..f9c0f405968231
--- /dev/null
+++ b/clang/test/Analysis/Checkers/WebKit/ref-allowing-partially-destroyed.cpp
@@ -0,0 +1,46 @@
+// RUN: %clang_analyze_cc1 
-analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s
+// expected-no-diagnostics
+
+#include "mock-types.h"
+
+template  struct RefAllowingPartiallyDestroyed {
+  T *t;
+
+  RefAllowingPartiallyDestroyed() : t{} {};
+  RefAllowingPartiallyDestroyed(T &) {}
+  T *get() { return t; }
+  T *ptr() { return t; }
+  

[clang] [Analyzer] Support RefAllowingPartiallyDestroyed and RefPtrAllowingPartiallyDestroyed (PR #82209)

2024-02-18 Thread Ryosuke Niwa via cfe-commits

https://github.com/rniwa created https://github.com/llvm/llvm-project/pull/82209

This PR adds the support for WebKit's RefAllowingPartiallyDestroyed and 
RefPtrAllowingPartiallyDestroyed, which are smart pointer types which may be 
used after the destructor had started running.

>From d26f41816f443922569fc713d1cd919fd96ba124 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Sun, 18 Feb 2024 21:47:48 -0800
Subject: [PATCH] [Analyzer] Support RefAllowingPartiallyDestroyed and
 RefPtrAllowingPartiallyDestroyed

This PR adds the support for WebKit's RefAllowingPartiallyDestroyed and
RefPtrAllowingPartiallyDestroyed, which are smart pointer types which may be 
used
after the destructor had started running.
---
 .../Checkers/WebKit/PtrTypesSemantics.cpp | 27 +--
 .../Analysis/Checkers/WebKit/mock-types.h |  3 +-
 .../ref-allowing-partially-destroyed.cpp  | 46 +++
 3 files changed, 62 insertions(+), 14 deletions(-)
 create mode 100644 
clang/test/Analysis/Checkers/WebKit/ref-allowing-partially-destroyed.cpp

diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 6f236db0474079..1b349d48a9f881 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -103,15 +103,18 @@ std::optional isRefCountable(const CXXRecordDecl* R)
   return hasRef && hasDeref;
 }
 
+bool isRefType(const std::string& name) {
+  return name == "Ref" || name == "RefAllowingPartiallyDestroyed" ||
+ name == "RefPtr" || name == "RefPtrAllowingPartiallyDestroyed";
+}
+
 bool isCtorOfRefCounted(const clang::FunctionDecl *F) {
   assert(F);
   const auto  = safeGetName(F);
 
-  return FunctionName == "Ref" || FunctionName == "makeRef"
-
- || FunctionName == "RefPtr" || FunctionName == "makeRefPtr"
-
- || FunctionName == "UniqueRef" || FunctionName == "makeUniqueRef" ||
+  return isRefType(FunctionName) || FunctionName == "makeRef" ||
+ FunctionName == "makeRefPtr" || FunctionName == "UniqueRef" ||
+ FunctionName == "makeUniqueRef" ||
  FunctionName == "makeUniqueRefWithoutFastMallocCheck"
 
  || FunctionName == "String" || FunctionName == "AtomString" ||
@@ -131,7 +134,7 @@ bool isReturnValueRefCounted(const clang::FunctionDecl *F) {
 if (auto *specialT = type->getAs()) {
   if (auto *decl = specialT->getTemplateName().getAsTemplateDecl()) {
 auto name = decl->getNameAsString();
-return name == "Ref" || name == "RefPtr";
+return isRefType(name);
   }
   return false;
 }
@@ -172,20 +175,18 @@ std::optional isGetterOfRefCounted(const 
CXXMethodDecl* M)
   if (isa(M)) {
 const CXXRecordDecl *calleeMethodsClass = M->getParent();
 auto className = safeGetName(calleeMethodsClass);
-auto methodName = safeGetName(M);
+auto method = safeGetName(M);
 
-if (((className == "Ref" || className == "RefPtr") &&
- methodName == "get") ||
-(className == "Ref" && methodName == "ptr") ||
+if ((isRefType(className) && (method == "get" || method == "ptr")) ||
 ((className == "String" || className == "AtomString" ||
   className == "AtomStringImpl" || className == "UniqueString" ||
   className == "UniqueStringImpl" || className == "Identifier") &&
- methodName == "impl"))
+ method == "impl"))
   return true;
 
 // Ref -> T conversion
 // FIXME: Currently allowing any Ref -> whatever cast.
-if (className == "Ref" || className == "RefPtr") {
+if (isRefType(className)) {
   if (auto *maybeRefToRawOperator = dyn_cast(M)) {
 if (auto *targetConversionType =
 maybeRefToRawOperator->getConversionType().getTypePtrOrNull()) 
{
@@ -202,7 +203,7 @@ bool isRefCounted(const CXXRecordDecl *R) {
   if (auto *TmplR = R->getTemplateInstantiationPattern()) {
 // FIXME: String/AtomString/UniqueString
 const auto  = safeGetName(TmplR);
-return ClassName == "RefPtr" || ClassName == "Ref";
+return isRefType(ClassName);
   }
   return false;
 }
diff --git a/clang/test/Analysis/Checkers/WebKit/mock-types.h 
b/clang/test/Analysis/Checkers/WebKit/mock-types.h
index d08a997aa8c043..e43641c0c61445 100644
--- a/clang/test/Analysis/Checkers/WebKit/mock-types.h
+++ b/clang/test/Analysis/Checkers/WebKit/mock-types.h
@@ -5,9 +5,10 @@ template  struct Ref {
   T *t;
 
   Ref() : t{} {};
-  Ref(T *) {}
+  Ref(T &) {}
   T *get() { return t; }
   T *ptr() { return t; }
+  T *operator->() { return t; }
   operator const T &() const { return *t; }
   operator T &() { return *t; }
 };
diff --git 
a/clang/test/Analysis/Checkers/WebKit/ref-allowing-partially-destroyed.cpp 
b/clang/test/Analysis/Checkers/WebKit/ref-allowing-partially-destroyed.cpp
new file mode 100644
index 00..f9c0f405968231
--- /dev/null
+++ 

[clang] [compiler-rt] [llvm] [InstrProf] Single byte counters in coverage (PR #75425)

2024-02-18 Thread Alan Phipps via cfe-commits

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

LGTM. I would like to see this broadened to include branch coverage as well!

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


[clang] [llvm] [CMake] Add a linker test for -Bsymbolic-functions to AddLLVM (PR #79539)

2024-02-18 Thread Brad Smith via cfe-commits

brad0 wrote:

> What's the issue? GNU ld has had -Bsymbolic-functions since 2007 and for 
> quite a few releases LLVM has been using `-Bsymbolic-functions`.

This is binutils 2.17. We've had patches for awhile in our tree too 
specifically for the exceptions not using LLD.

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


[clang] [llvm] [clang] Use separator for large numeric values in overflow diagnostic (PR #80939)

2024-02-18 Thread Atousa Duprat via cfe-commits

Atousa wrote:

@AaronBallman @tbaederr, Do you have any further comments?

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


[clang] [clang][Sema] Fix for enums overflowing (#24667) (PR #78742)

2024-02-18 Thread via cfe-commits

wheatman wrote:

I believe I have correct implementations added for N3029 and N3030.  
I also tried to add tests.  One thing I was not sure about was how to add tests 
that have different expected behavior for different versions.  I just used  
`#if __STDC_VERSION__  < 202311L` but please let me know if there is a better 
way.  I also updated the release notes to mention these additions.

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


[clang] [Clang] CXXConstructExpr may be immediate calls. (PR #82179)

2024-02-18 Thread Chuanqi Xu via cfe-commits

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

LGTM.

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


[clang] [Serialization] Load Specializations Lazily (PR #76774)

2024-02-18 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

> Let's zoom out a little. The approach in D41416 shows that it is feasible to 
> store _a_ hash of the template arguments to delay eager deserializations. The 
> ODR hash approach is a second order problem because we can swap it with 
> something better once we need to. In order to make progress we have 
> introduced [D153003](https://reviews.llvm.org/D153003) which allows our 
> infrastructure to work. The way I see moving forward here is:
> 
> * Base this PR on D41416 in the approach how we model the lazy 
> deserialization of templates. That'd mean that we "just" need to replace 
> `LazySpecializationInfo *LazySpecializations = nullptr;` with the on-disk 
> hash table approach. That would probably require centralizing that logic 
> somewhere in the ASTReader (the way this PR does) but with minimal changes 
> wrt D41416.
> * Test the implementation on our infrastructure for correctness
> * Test the implementation on the Google infrastructure for scalability
> * Think on a better approach to replace odr hashing if we see more 
> pathological problems.

Yeah, no problem at all. This is what I want in the higher level too. What I am 
confused is about the status of [D153003](https://reviews.llvm.org/D153003). If 
it is true that we've describe the problem completely in the review page, then 
https://github.com/llvm/llvm-project/commit/c31d6b4ef135098280b0ebb93e95b258a0d372ca
 should be a proper fix for that.

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


[clang] Reland "[clang][modules] Print library module manifest path." (PR #82160)

2024-02-18 Thread Chuanqi Xu via cfe-commits


@@ -0,0 +1,38 @@
+// Test that -print-library-module-manifest-path finds the correct file.
+
+// REQUIRES: x86-registered-target

ChuanqiXu9 wrote:

```suggestion
// FIXME: 
// REQUIRES: x86-registered-target
```

I feel better with a FIXME to remind us to remove this later.

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


[clang] Reland "[clang][modules] Print library module manifest path." (PR #82160)

2024-02-18 Thread Chuanqi Xu via cfe-commits

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

LGTM.

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


[clang] Reland "[clang][modules] Print library module manifest path." (PR #82160)

2024-02-18 Thread Chuanqi Xu via cfe-commits

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


[clang-tools-extra] [clang-tidy] Add fix-its to `avoid-return-with-void-value` check (PR #81420)

2024-02-18 Thread Congcong Cai via cfe-commits

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


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


[clang-tools-extra] [clang-tidy] Add fix-its to `avoid-return-with-void-value` check (PR #81420)

2024-02-18 Thread Congcong Cai via cfe-commits


@@ -42,10 +43,28 @@ void AvoidReturnWithVoidValueCheck::check(
   const auto *VoidReturn = Result.Nodes.getNodeAs("void_return");
   if (IgnoreMacros && VoidReturn->getBeginLoc().isMacroID())
 return;
-  if (!StrictMode && !Result.Nodes.getNodeAs("compound_parent"))
+  const auto *SurroundingBlock =
+  Result.Nodes.getNodeAs("compound_parent");
+  if (!StrictMode && !SurroundingBlock)
 return;
+  const StringRef ReturnExpr =
+  Lexer::getSourceText(CharSourceRange::getTokenRange(
+   VoidReturn->getRetValue()->getSourceRange()),
+   *Result.SourceManager, getLangOpts());
+  SourceLocation SemicolonPos;
+  if (const std::optional NextToken =
+  Lexer::findNextToken(VoidReturn->getRetValue()->getEndLoc(),
+   *Result.SourceManager, getLangOpts()))
+SemicolonPos = NextToken->getEndLoc();
+  std::string Replacement = (ReturnExpr + "; return;").str();
+  if (!SurroundingBlock)
+Replacement = "{" + Replacement + "}";
   diag(VoidReturn->getBeginLoc(), "return statement within a void function "
-  "should not have a specified return value");
+  "should not have a specified return value")
+  << FixItHint::CreateReplacement(
+ CharSourceRange::getTokenRange(VoidReturn->getBeginLoc(),
+SemicolonPos),

HerrCai0907 wrote:

what will happen if `SemicolonPos` is invalid?

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


[clang-tools-extra] [clang-tidy] Add fix-its to `avoid-return-with-void-value` check (PR #81420)

2024-02-18 Thread Congcong Cai via cfe-commits

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


[clang] [clang][CodeCoverage] Fix conditional-operator test (PR #82192)

2024-02-18 Thread David Tellenbach via cfe-commits

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


[clang] 7970949 - [clang][CodeCoverage] Fix conditional-operator test (#82192)

2024-02-18 Thread via cfe-commits

Author: David Tellenbach
Date: 2024-02-18T15:11:08-08:00
New Revision: 79709498eaa57095a9888b882e94f6d15a244d4b

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

LOG: [clang][CodeCoverage] Fix conditional-operator test (#82192)

Added: 


Modified: 
clang/test/CoverageMapping/conditional-operator.c

Removed: 




diff  --git a/clang/test/CoverageMapping/conditional-operator.c 
b/clang/test/CoverageMapping/conditional-operator.c
index 06b89c6b5a697e..956eb3d2aedac4 100644
--- a/clang/test/CoverageMapping/conditional-operator.c
+++ b/clang/test/CoverageMapping/conditional-operator.c
@@ -12,7 +12,7 @@ int binary_conditional(int x) {
 }
 
 // CHECK-LABEL:   ternary_conditional:
-// CHECK-NEXT:  File 0, [[@LINE+6]]:31 -> {{[0-9]+}}:2 = #0
+// CHECK-NEXT:  File 0, [[@LINE+6]]:32 -> {{[0-9]+}}:2 = #0
 // CHECK-NEXT:  File 0, [[@LINE+6]]:7 -> [[@LINE+6]]:8 = #0
 // CHECK-NEXT:  Branch,File 0, [[@LINE+5]]:7 -> [[@LINE+5]]:8 = #1, 
(#0 - #1)
 // CHECK-NEXT:  Gap,File 0, [[@LINE+4]]:10 -> [[@LINE+4]]:11 = #1



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


[clang] [clang][CodeCoverage] Fix conditional-operator test (PR #82192)

2024-02-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: David Tellenbach (dtellenbach)


Changes



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


1 Files Affected:

- (modified) clang/test/CoverageMapping/conditional-operator.c (+1-1) 


``diff
diff --git a/clang/test/CoverageMapping/conditional-operator.c 
b/clang/test/CoverageMapping/conditional-operator.c
index 06b89c6b5a697e..956eb3d2aedac4 100644
--- a/clang/test/CoverageMapping/conditional-operator.c
+++ b/clang/test/CoverageMapping/conditional-operator.c
@@ -12,7 +12,7 @@ int binary_conditional(int x) {
 }
 
 // CHECK-LABEL:   ternary_conditional:
-// CHECK-NEXT:  File 0, [[@LINE+6]]:31 -> {{[0-9]+}}:2 = #0
+// CHECK-NEXT:  File 0, [[@LINE+6]]:32 -> {{[0-9]+}}:2 = #0
 // CHECK-NEXT:  File 0, [[@LINE+6]]:7 -> [[@LINE+6]]:8 = #0
 // CHECK-NEXT:  Branch,File 0, [[@LINE+5]]:7 -> [[@LINE+5]]:8 = #1, 
(#0 - #1)
 // CHECK-NEXT:  Gap,File 0, [[@LINE+4]]:10 -> [[@LINE+4]]:11 = #1

``




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


[clang] [clang][CodeCoverage] Fix conditional-operator test (PR #82192)

2024-02-18 Thread David Tellenbach via cfe-commits

https://github.com/dtellenbach created 
https://github.com/llvm/llvm-project/pull/82192

None

>From 23b311470d4609fa394bc51b6fce8af83aeff022 Mon Sep 17 00:00:00 2001
From: David Tellenbach 
Date: Sun, 18 Feb 2024 14:46:43 -0800
Subject: [PATCH] [clang][CodeCoverage] Fix conditional-operator test

---
 clang/test/CoverageMapping/conditional-operator.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/CoverageMapping/conditional-operator.c 
b/clang/test/CoverageMapping/conditional-operator.c
index 06b89c6b5a697e..956eb3d2aedac4 100644
--- a/clang/test/CoverageMapping/conditional-operator.c
+++ b/clang/test/CoverageMapping/conditional-operator.c
@@ -12,7 +12,7 @@ int binary_conditional(int x) {
 }
 
 // CHECK-LABEL:   ternary_conditional:
-// CHECK-NEXT:  File 0, [[@LINE+6]]:31 -> {{[0-9]+}}:2 = #0
+// CHECK-NEXT:  File 0, [[@LINE+6]]:32 -> {{[0-9]+}}:2 = #0
 // CHECK-NEXT:  File 0, [[@LINE+6]]:7 -> [[@LINE+6]]:8 = #0
 // CHECK-NEXT:  Branch,File 0, [[@LINE+5]]:7 -> [[@LINE+5]]:8 = #1, 
(#0 - #1)
 // CHECK-NEXT:  Gap,File 0, [[@LINE+4]]:10 -> [[@LINE+4]]:11 = #1

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


[clang] [clang][CodeCoverage] Fix CoverageMapping for binary conditionals ops (PR #82141)

2024-02-18 Thread David Tellenbach via cfe-commits

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


[clang] dc94eb5 - [clang][CodeCoverage] Fix CoverageMapping for binary conditionals ops (#82141)

2024-02-18 Thread via cfe-commits

Author: David Tellenbach
Date: 2024-02-18T14:34:35-08:00
New Revision: dc94eb57e39a925a9672bfc4d7cba0fb0da874d8

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

LOG: [clang][CodeCoverage] Fix CoverageMapping for binary conditionals ops 
(#82141)

Fix an issue that produces a wrong coverage mapping when using binary
conditional operators as show in the example below.

Before this patch:

1|  1|int binary_cond(int x) {
2|  1|  x = x ?: 4;
3|  1|  int y = 0;
4|  0|  return x;   <-- Not covered
5|  1|}

After this patch:

1|  1|int binary_cond(int x) {
2|  1|  x = x ?: 4;
3|  1|  int y = 0;
4|  1|  return x;   <-- Covered
5|  1|}

Added: 
clang/test/CoverageMapping/conditional-operator.c

Modified: 
clang/lib/CodeGen/CoverageMappingGen.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index c10d85ea89ee61..d8fa69d825b8d6 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -1942,6 +1942,8 @@ struct CounterCoverageMappingBuilder
 
   extendRegion(E->getTrueExpr());
   OutCount = propagateCounts(TrueCount, E->getTrueExpr());
+} else {
+  OutCount = TrueCount;
 }
 
 extendRegion(E->getFalseExpr());

diff  --git a/clang/test/CoverageMapping/conditional-operator.c 
b/clang/test/CoverageMapping/conditional-operator.c
new file mode 100644
index 00..06b89c6b5a697e
--- /dev/null
+++ b/clang/test/CoverageMapping/conditional-operator.c
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false 
-fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping 
-emit-llvm-only %s | FileCheck %s
+
+// CHECK-LABEL:   binary_conditional:
+// CHECK-NEXT:  File 0, [[@LINE+4]]:31 -> {{[0-9]+}}:2 = #0
+// CHECK-NEXT:  File 0, [[@LINE+4]]:7 -> [[@LINE+4]]:8 = #0
+// CHECK-NEXT:  Branch,File 0, [[@LINE+3]]:7 -> [[@LINE+3]]:8 = #1, 
(#0 - #1)
+// CHECK-NEXT:  File 0, [[@LINE+2]]:13 -> [[@LINE+2]]:14 = (#0 - #1)
+int binary_conditional(int x) {
+  x = x ? : 4;
+  int y = x;
+  return y;
+}
+
+// CHECK-LABEL:   ternary_conditional:
+// CHECK-NEXT:  File 0, [[@LINE+6]]:31 -> {{[0-9]+}}:2 = #0
+// CHECK-NEXT:  File 0, [[@LINE+6]]:7 -> [[@LINE+6]]:8 = #0
+// CHECK-NEXT:  Branch,File 0, [[@LINE+5]]:7 -> [[@LINE+5]]:8 = #1, 
(#0 - #1)
+// CHECK-NEXT:  Gap,File 0, [[@LINE+4]]:10 -> [[@LINE+4]]:11 = #1
+// CHECK-NEXT:  File 0, [[@LINE+3]]:11 -> [[@LINE+3]]:12 = #1
+// CHECK-NEXT:  File 0, [[@LINE+2]]:15 -> [[@LINE+2]]:16 = (#0 - #1)
+int ternary_conditional(int x) {
+  x = x ? x : 4;
+  int y = x;
+  return y;
+}



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


[clang] [clang][CodeCoverage] Fix CoverageMapping for binary conditionals ops (PR #82141)

2024-02-18 Thread David Tellenbach via cfe-commits


@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false 
-fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping 
-emit-llvm-only %s | FileCheck %s
+
+// CHECK-LABEL:   binary_conditional:
+// CHECK-NEXT:  File 0, [[@LINE+4]]:31 -> {{[0-9]+}}:2 = #0
+// CHECK-NEXT:  File 0, [[@LINE+4]]:7 -> [[@LINE+4]]:8 = #0
+// CHECK-NEXT:  Branch,File 0, [[@LINE+3]]:7 -> [[@LINE+3]]:8 = #1, 
(#0 - #1)
+// CHECK-NEXT:  File 0, [[@LINE+2]]:13 -> [[@LINE+2]]:14 = (#0 - #1)
+int binary_conditional(int x) {
+  x = x ? : 4;
+  int y = x;
+  return y;
+}
+
+// CHECK-LABEL:   tenary_conditional:
+// CHECK-NEXT:  File 0, [[@LINE+6]]:31 -> {{[0-9]+}}:2 = #0
+// CHECK-NEXT:  File 0, [[@LINE+6]]:7 -> [[@LINE+6]]:8 = #0
+// CHECK-NEXT:  Branch,File 0, [[@LINE+5]]:7 -> [[@LINE+5]]:8 = #1, 
(#0 - #1)
+// CHECK-NEXT:  Gap,File 0, [[@LINE+4]]:10 -> [[@LINE+4]]:11 = #1
+// CHECK-NEXT:  File 0, [[@LINE+3]]:11 -> [[@LINE+3]]:12 = #1
+// CHECK-NEXT:  File 0, [[@LINE+2]]:15 -> [[@LINE+2]]:16 = (#0 - #1)
+int tenary_conditional(int x) {

dtellenbach wrote:

Ah, thanks for catching that!

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


[clang] [clang][CodeCoverage] Fix CoverageMapping for binary conditionals ops (PR #82141)

2024-02-18 Thread David Tellenbach via cfe-commits

https://github.com/dtellenbach updated 
https://github.com/llvm/llvm-project/pull/82141

>From f8e11fed8b4b6b0cc359e2915e4f2f32c3f08bb5 Mon Sep 17 00:00:00 2001
From: David Tellenbach 
Date: Sat, 17 Feb 2024 15:16:39 -0800
Subject: [PATCH 1/2] [clang][CodeCoverage] Fix CoverageMapping for binary
 conditionals ops

Fix an issue that produces a wrong coverage mapping when using binary
conditional operators as show in the example below.

Before this patch:

1|  1|int binary_cond(int x) {
2|  1|  x = x ?: 4;
3|  1|  int y = 0;
4|  0|  return x;   <-- Not covered
5|  1|}

After this patch:

1|  1|int binary_cond(int x) {
2|  1|  x = x ?: 4;
3|  1|  int y = 0;
4|  1|  return x;   <-- Covered
5|  1|}
---
 clang/lib/CodeGen/CoverageMappingGen.cpp  |  2 ++
 .../CoverageMapping/conditional-operator.c| 25 +++
 2 files changed, 27 insertions(+)
 create mode 100644 clang/test/CoverageMapping/conditional-operator.c

diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index c10d85ea89ee61..d8fa69d825b8d6 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -1942,6 +1942,8 @@ struct CounterCoverageMappingBuilder
 
   extendRegion(E->getTrueExpr());
   OutCount = propagateCounts(TrueCount, E->getTrueExpr());
+} else {
+  OutCount = TrueCount;
 }
 
 extendRegion(E->getFalseExpr());
diff --git a/clang/test/CoverageMapping/conditional-operator.c 
b/clang/test/CoverageMapping/conditional-operator.c
new file mode 100644
index 00..5f3eb9c03e79fb
--- /dev/null
+++ b/clang/test/CoverageMapping/conditional-operator.c
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false 
-fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping 
-emit-llvm-only %s | FileCheck %s
+
+// CHECK-LABEL:   binary_conditional:
+// CHECK-NEXT:  File 0, [[@LINE+4]]:31 -> {{[0-9]+}}:2 = #0
+// CHECK-NEXT:  File 0, [[@LINE+4]]:7 -> [[@LINE+4]]:8 = #0
+// CHECK-NEXT:  Branch,File 0, [[@LINE+3]]:7 -> [[@LINE+3]]:8 = #1, 
(#0 - #1)
+// CHECK-NEXT:  File 0, [[@LINE+2]]:13 -> [[@LINE+2]]:14 = (#0 - #1)
+int binary_conditional(int x) {
+  x = x ? : 4;
+  int y = x;
+  return y;
+}
+
+// CHECK-LABEL:   tenary_conditional:
+// CHECK-NEXT:  File 0, [[@LINE+6]]:31 -> {{[0-9]+}}:2 = #0
+// CHECK-NEXT:  File 0, [[@LINE+6]]:7 -> [[@LINE+6]]:8 = #0
+// CHECK-NEXT:  Branch,File 0, [[@LINE+5]]:7 -> [[@LINE+5]]:8 = #1, 
(#0 - #1)
+// CHECK-NEXT:  Gap,File 0, [[@LINE+4]]:10 -> [[@LINE+4]]:11 = #1
+// CHECK-NEXT:  File 0, [[@LINE+3]]:11 -> [[@LINE+3]]:12 = #1
+// CHECK-NEXT:  File 0, [[@LINE+2]]:15 -> [[@LINE+2]]:16 = (#0 - #1)
+int tenary_conditional(int x) {
+  x = x ? x : 4;
+  int y = x;
+  return y;
+}

>From 28737890db53bd2cef7a6fad4b260e20e325f899 Mon Sep 17 00:00:00 2001
From: David Tellenbach 
Date: Sun, 18 Feb 2024 14:28:58 -0800
Subject: [PATCH 2/2] Fix typo in test

---
 clang/test/CoverageMapping/conditional-operator.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/test/CoverageMapping/conditional-operator.c 
b/clang/test/CoverageMapping/conditional-operator.c
index 5f3eb9c03e79fb..06b89c6b5a697e 100644
--- a/clang/test/CoverageMapping/conditional-operator.c
+++ b/clang/test/CoverageMapping/conditional-operator.c
@@ -11,14 +11,14 @@ int binary_conditional(int x) {
   return y;
 }
 
-// CHECK-LABEL:   tenary_conditional:
+// CHECK-LABEL:   ternary_conditional:
 // CHECK-NEXT:  File 0, [[@LINE+6]]:31 -> {{[0-9]+}}:2 = #0
 // CHECK-NEXT:  File 0, [[@LINE+6]]:7 -> [[@LINE+6]]:8 = #0
 // CHECK-NEXT:  Branch,File 0, [[@LINE+5]]:7 -> [[@LINE+5]]:8 = #1, 
(#0 - #1)
 // CHECK-NEXT:  Gap,File 0, [[@LINE+4]]:10 -> [[@LINE+4]]:11 = #1
 // CHECK-NEXT:  File 0, [[@LINE+3]]:11 -> [[@LINE+3]]:12 = #1
 // CHECK-NEXT:  File 0, [[@LINE+2]]:15 -> [[@LINE+2]]:16 = (#0 - #1)
-int tenary_conditional(int x) {
+int ternary_conditional(int x) {
   x = x ? x : 4;
   int y = x;
   return y;

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


[clang-tools-extra] [clang-tidy] Keep parentheses when replacing index access in `sizeof` calls (PR #82166)

2024-02-18 Thread Danny Mösch via cfe-commits

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


[clang-tools-extra] 5e83b26 - [clang-tidy] Keep parentheses when replacing index access in `sizeof` calls (#82166)

2024-02-18 Thread via cfe-commits

Author: Danny Mösch
Date: 2024-02-18T22:42:17+01:00
New Revision: 5e83b26584c9a02f8a2923651d08cad2dcc8479a

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

LOG: [clang-tidy] Keep parentheses when replacing index access in `sizeof` 
calls (#82166)

Fixes #56021.

Added: 


Modified: 
clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
index f0791da143ad9d..3229e302eb4322 100644
--- a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
@@ -706,13 +706,17 @@ void LoopConvertCheck::doConversion(
 ReplaceText = Usage.Kind == Usage::UK_MemberThroughArrow
   ? VarNameOrStructuredBinding + "."
   : VarNameOrStructuredBinding;
-auto Parents = Context->getParents(*Usage.Expression);
+const DynTypedNodeList Parents = 
Context->getParents(*Usage.Expression);
 if (Parents.size() == 1) {
   if (const auto *Paren = Parents[0].get()) {
 // Usage.Expression will be replaced with the new index variable,
 // and parenthesis around a simple DeclRefExpr can always be
-// removed.
-Range = Paren->getSourceRange();
+// removed except in case of a `sizeof` operator call.
+const DynTypedNodeList GrandParents = Context->getParents(*Paren);
+if (GrandParents.size() != 1 ||
+GrandParents[0].get() == nullptr) {
+  Range = Paren->getSourceRange();
+}
   } else if (const auto *UOP = Parents[0].get()) {
 // If we are taking the address of the loop variable, then we must
 // not use a copy, as it would mean taking the address of the 
loop's

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 7ca7037e2a6a4f..58629426216ba8 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -170,6 +170,11 @@ Changes in existing checks
   `AllowStringArrays` option, enabling the exclusion of array types with 
deduced
   length initialized from string literals.
 
+- Improved :doc:`modernize-loop-convert
+  ` check by ensuring that fix-its
+  don't remove parentheses used in ``sizeof`` calls when they have array index
+  accesses as arguments.
+
 - Improved :doc:`modernize-use-override
   ` check to also remove any trailing
   whitespace when deleting the ``virtual`` keyword.

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
index c29fbc9f9b23b7..695925a5d877c9 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
@@ -88,6 +88,19 @@ void f() {
   // CHECK-FIXES-NEXT: printf("Fibonacci number %d has address %p\n", I, );
   // CHECK-FIXES-NEXT: Sum += I + 2;
 
+  int Matrix[N][12];
+  unsigned size = 0;
+  for (int I = 0; I < N; ++I) {
+  size += sizeof(Matrix[I]);
+  size += sizeof Matrix[I];
+  size += sizeof((Matrix[I]));
+  }
+  // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & I : Matrix)
+  // CHECK-FIXES-NEXT: size += sizeof(I);
+  // CHECK-FIXES-NEXT: size += sizeof I;
+  // CHECK-FIXES-NEXT: size += sizeof(I);
+
   Val Teas[N];
   for (int I = 0; I < N; ++I) {
 Teas[I].g();



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


[clang-tools-extra] [clang-tidy] Add fix-its to `avoid-return-with-void-value` check (PR #81420)

2024-02-18 Thread Danny Mösch via cfe-commits

https://github.com/SimplyDanny updated 
https://github.com/llvm/llvm-project/pull/81420

From b99fe4bcec7ac74f6511538959fe2e14689b1cdb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Danny=20M=C3=B6sch?= 
Date: Sun, 11 Feb 2024 17:04:12 +0100
Subject: [PATCH] [clang-tidy] Add fix-its to `avoid-return-with-void-value`
 check

---
 .../AvoidReturnWithVoidValueCheck.cpp | 31 +++
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 +++
 .../avoid-return-with-void-value.cpp  | 14 +++--
 3 files changed, 41 insertions(+), 8 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/readability/AvoidReturnWithVoidValueCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/AvoidReturnWithVoidValueCheck.cpp
index e3400f614fa564..46d8108b63af51 100644
--- a/clang-tools-extra/clang-tidy/readability/AvoidReturnWithVoidValueCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/AvoidReturnWithVoidValueCheck.cpp
@@ -10,16 +10,17 @@
 #include "clang/AST/Stmt.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Lex/Lexer.h"
 
 using namespace clang::ast_matchers;
 
 namespace clang::tidy::readability {
 
-static constexpr auto IgnoreMacrosName = "IgnoreMacros";
-static constexpr auto IgnoreMacrosDefault = true;
+static constexpr char IgnoreMacrosName[] = "IgnoreMacros";
+static const bool IgnoreMacrosDefault = true;
 
-static constexpr auto StrictModeName = "StrictMode";
-static constexpr auto StrictModeDefault = true;
+static constexpr char StrictModeName[] = "StrictMode";
+static const bool StrictModeDefault = true;
 
 AvoidReturnWithVoidValueCheck::AvoidReturnWithVoidValueCheck(
 StringRef Name, ClangTidyContext *Context)
@@ -42,10 +43,28 @@ void AvoidReturnWithVoidValueCheck::check(
   const auto *VoidReturn = Result.Nodes.getNodeAs("void_return");
   if (IgnoreMacros && VoidReturn->getBeginLoc().isMacroID())
 return;
-  if (!StrictMode && !Result.Nodes.getNodeAs("compound_parent"))
+  const auto *SurroundingBlock =
+  Result.Nodes.getNodeAs("compound_parent");
+  if (!StrictMode && !SurroundingBlock)
 return;
+  const StringRef ReturnExpr =
+  Lexer::getSourceText(CharSourceRange::getTokenRange(
+   VoidReturn->getRetValue()->getSourceRange()),
+   *Result.SourceManager, getLangOpts());
+  SourceLocation SemicolonPos;
+  if (const std::optional NextToken =
+  Lexer::findNextToken(VoidReturn->getRetValue()->getEndLoc(),
+   *Result.SourceManager, getLangOpts()))
+SemicolonPos = NextToken->getEndLoc();
+  std::string Replacement = (ReturnExpr + "; return;").str();
+  if (!SurroundingBlock)
+Replacement = "{" + Replacement + "}";
   diag(VoidReturn->getBeginLoc(), "return statement within a void function "
-  "should not have a specified return value");
+  "should not have a specified return value")
+  << FixItHint::CreateReplacement(
+ CharSourceRange::getTokenRange(VoidReturn->getBeginLoc(),
+SemicolonPos),
+ Replacement);
 }
 
 void AvoidReturnWithVoidValueCheck::storeOptions(
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 7ca7037e2a6a4f..2c1199b5f44081 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -174,6 +174,10 @@ Changes in existing checks
   ` check to also remove any trailing
   whitespace when deleting the ``virtual`` keyword.
 
+- Improved :doc:`readability-avoid-return-with-void-value
+  ` check by adding
+  fix-its.
+
 - Improved :doc:`readability-implicit-bool-conversion
   ` check to provide
   valid fix suggestions for ``static_cast`` without a preceding space and
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/avoid-return-with-void-value.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/avoid-return-with-void-value.cpp
index f00407c99ce570..0d269ceee82bc9 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/avoid-return-with-void-value.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/avoid-return-with-void-value.cpp
@@ -12,14 +12,18 @@ void f2() {
 return f1();
 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: return statement within a void 
function should not have a specified return value 
[readability-avoid-return-with-void-value]
 // CHECK-MESSAGES-LENIENT: :[[@LINE-2]]:5: warning: return statement 
within a void function should not have a specified return value 
[readability-avoid-return-with-void-value]
+// CHECK-FIXES: f1(); return;
 }
 
 void f3(bool b) {
 if (b) return f1();
 // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: return statement within a 
void function should not have a specified return value 
[readability-avoid-return-with-void-value]
+// CHECK-FIXES: if 

[clang-tools-extra] [clang-tidy] Keep parentheses when replacing index access in `sizeof` calls (PR #82166)

2024-02-18 Thread Danny Mösch via cfe-commits

https://github.com/SimplyDanny updated 
https://github.com/llvm/llvm-project/pull/82166

From 7aa267d752408fedcf14b62cd015d90de6719459 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Danny=20M=C3=B6sch?= 
Date: Sun, 18 Feb 2024 14:46:54 +0100
Subject: [PATCH 1/5] [clang-tidy] Keep parentheses when replacing index access
 in `sizeof` calls

---
 .../clang-tidy/modernize/LoopConvertCheck.cpp   |  8 ++--
 clang-tools-extra/docs/ReleaseNotes.rst |  5 +
 .../checkers/modernize/loop-convert-basic.cpp   | 13 -
 3 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
index f0791da143ad9d..6c9a330d733407 100644
--- a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
@@ -711,8 +711,12 @@ void LoopConvertCheck::doConversion(
   if (const auto *Paren = Parents[0].get()) {
 // Usage.Expression will be replaced with the new index variable,
 // and parenthesis around a simple DeclRefExpr can always be
-// removed.
-Range = Paren->getSourceRange();
+// removed except in case of a `sizeof` operator call.
+auto GrandParents = Context->getParents(*Paren);
+if (GrandParents.size() != 1 ||
+!GrandParents[0].get()) {
+  Range = Paren->getSourceRange();
+}
   } else if (const auto *UOP = Parents[0].get()) {
 // If we are taking the address of the loop variable, then we must
 // not use a copy, as it would mean taking the address of the 
loop's
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 7ca7037e2a6a4f..58629426216ba8 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -170,6 +170,11 @@ Changes in existing checks
   `AllowStringArrays` option, enabling the exclusion of array types with 
deduced
   length initialized from string literals.
 
+- Improved :doc:`modernize-loop-convert
+  ` check by ensuring that fix-its
+  don't remove parentheses used in ``sizeof`` calls when they have array index
+  accesses as arguments.
+
 - Improved :doc:`modernize-use-override
   ` check to also remove any trailing
   whitespace when deleting the ``virtual`` keyword.
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
index c29fbc9f9b23b7..02601b6320491a 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
@@ -1,4 +1,6 @@
-// RUN: %check_clang_tidy %s modernize-loop-convert %t -- -- -I 
%S/Inputs/loop-convert
+// RUN: %check_clang_tidy %s modernize-loop-convert %t -- -- -I 
%S/Inputs/loop-convert -isystem %clang_tidy_headers
+
+#include 
 
 #include "structures.h"
 
@@ -88,6 +90,15 @@ void f() {
   // CHECK-FIXES-NEXT: printf("Fibonacci number %d has address %p\n", I, );
   // CHECK-FIXES-NEXT: Sum += I + 2;
 
+  int Matrix[N][12];
+  size_t size = 0;
+  for (int I = 0; I < N; ++I) {
+  size += sizeof(Matrix[I]) + sizeof Matrix[I];
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & I : Matrix)
+  // CHECK-FIXES-NEXT: size += sizeof(I) + sizeof I;
+
   Val Teas[N];
   for (int I = 0; I < N; ++I) {
 Teas[I].g();

From 47d265569f26f7fab74ebd75be752807e2d04e75 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Danny=20M=C3=B6sch?= 
Date: Sun, 18 Feb 2024 17:33:24 +0100
Subject: [PATCH 2/5] Avoid auto

---
 clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
index 6c9a330d733407..cac742cd46331e 100644
--- a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
@@ -706,13 +706,13 @@ void LoopConvertCheck::doConversion(
 ReplaceText = Usage.Kind == Usage::UK_MemberThroughArrow
   ? VarNameOrStructuredBinding + "."
   : VarNameOrStructuredBinding;
-auto Parents = Context->getParents(*Usage.Expression);
+const DynTypedNodeList Parents = 
Context->getParents(*Usage.Expression);
 if (Parents.size() == 1) {
   if (const auto *Paren = Parents[0].get()) {
 // Usage.Expression will be replaced with the new index variable,
 // and parenthesis around a simple DeclRefExpr can always be
 // removed except in case of a `sizeof` operator call.
-auto GrandParents = 

[clang-tools-extra] [clang-tidy] Keep parentheses when replacing index access in `sizeof` calls (PR #82166)

2024-02-18 Thread Piotr Zegar via cfe-commits
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= 
Message-ID:
In-Reply-To: 



@@ -1,4 +1,6 @@
-// RUN: %check_clang_tidy %s modernize-loop-convert %t -- -- -I 
%S/Inputs/loop-convert
+// RUN: %check_clang_tidy %s modernize-loop-convert %t -- -- -I 
%S/Inputs/loop-convert -isystem %clang_tidy_headers
+
+#include 

PiotrZSL wrote:

you could just use `unsigned int size` in line 94 instead of including this 
header.

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


[clang-tools-extra] [clang-tidy] Keep parentheses when replacing index access in `sizeof` calls (PR #82166)

2024-02-18 Thread Piotr Zegar via cfe-commits
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= 
Message-ID:
In-Reply-To: 


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

Overall, LGTM.

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


[clang-tools-extra] [clang-tidy] Keep parentheses when replacing index access in `sizeof` calls (PR #82166)

2024-02-18 Thread Piotr Zegar via cfe-commits
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= 
Message-ID:
In-Reply-To: 



@@ -706,13 +706,17 @@ void LoopConvertCheck::doConversion(
 ReplaceText = Usage.Kind == Usage::UK_MemberThroughArrow
   ? VarNameOrStructuredBinding + "."
   : VarNameOrStructuredBinding;
-auto Parents = Context->getParents(*Usage.Expression);
+const DynTypedNodeList Parents = 
Context->getParents(*Usage.Expression);
 if (Parents.size() == 1) {
   if (const auto *Paren = Parents[0].get()) {
 // Usage.Expression will be replaced with the new index variable,
 // and parenthesis around a simple DeclRefExpr can always be
-// removed.
-Range = Paren->getSourceRange();
+// removed except in case of a `sizeof` operator call.
+const DynTypedNodeList GrandParents = Context->getParents(*Paren);
+if (GrandParents.size() != 1 ||
+!GrandParents[0].get()) {

PiotrZSL wrote:

Use `== nullptr`, it's more readable in this case

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


[clang-tools-extra] [clang-tidy] Keep parentheses when replacing index access in `sizeof` calls (PR #82166)

2024-02-18 Thread Piotr Zegar via cfe-commits
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= 
Message-ID:
In-Reply-To: 


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


[clang] Thread safety analysis: provide printSCFG definition. (PR #80277)

2024-02-18 Thread Aaron Puchert via cfe-commits

aaronpuchert wrote:

It might have been commented out so that it doesn't take up space in the 
compiled binary.

I'd like seeing it compiled, just to make sure it doesn't break. But I'd also 
like if it doesn't appear in the final binary. Perhaps we can change visibility 
so that `--gc-sections` or LTO can optimize it out? But I'm not sure if that's 
enough.

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


[clang] cc2fe7b - [clang][Interp][NFC] Make Record::{Base,Field} member pointers const

2024-02-18 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-02-18T18:07:29+01:00
New Revision: cc2fe7b516c1dbf1f8747ade0f17891f9990dede

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

LOG: [clang][Interp][NFC] Make Record::{Base,Field} member pointers const

Added: 


Modified: 
clang/lib/AST/Interp/Descriptor.cpp
clang/lib/AST/Interp/Program.cpp
clang/lib/AST/Interp/Record.h

Removed: 




diff  --git a/clang/lib/AST/Interp/Descriptor.cpp 
b/clang/lib/AST/Interp/Descriptor.cpp
index f75a9fc4b46650..ce7ed9cec3db3f 100644
--- a/clang/lib/AST/Interp/Descriptor.cpp
+++ b/clang/lib/AST/Interp/Descriptor.cpp
@@ -139,7 +139,7 @@ static void moveArrayDesc(Block *B, const std::byte *Src, 
std::byte *Dst,
 static void ctorRecord(Block *B, std::byte *Ptr, bool IsConst, bool IsMutable,
bool IsActive, const Descriptor *D) {
   const bool IsUnion = D->ElemRecord->isUnion();
-  auto CtorSub = [=](unsigned SubOff, Descriptor *F, bool IsBase) {
+  auto CtorSub = [=](unsigned SubOff, const Descriptor *F, bool IsBase) {
 auto *Desc = reinterpret_cast(Ptr + SubOff) - 1;
 Desc->Offset = SubOff;
 Desc->Desc = F;
@@ -161,7 +161,7 @@ static void ctorRecord(Block *B, std::byte *Ptr, bool 
IsConst, bool IsMutable,
 }
 
 static void dtorRecord(Block *B, std::byte *Ptr, const Descriptor *D) {
-  auto DtorSub = [=](unsigned SubOff, Descriptor *F) {
+  auto DtorSub = [=](unsigned SubOff, const Descriptor *F) {
 if (auto Fn = F->DtorFn)
   Fn(B, Ptr + SubOff, F);
   };

diff  --git a/clang/lib/AST/Interp/Program.cpp 
b/clang/lib/AST/Interp/Program.cpp
index 5624d5955c042c..ec6cdebcd820fa 100644
--- a/clang/lib/AST/Interp/Program.cpp
+++ b/clang/lib/AST/Interp/Program.cpp
@@ -248,7 +248,7 @@ Record *Program::getOrCreateRecord(const RecordDecl *RD) {
 
   // Helper to get a base descriptor.
   auto GetBaseDesc = [this](const RecordDecl *BD,
-const Record *BR) -> Descriptor * {
+const Record *BR) -> const Descriptor * {
 if (!BR)
   return nullptr;
 return allocateDescriptor(BD, BR, std::nullopt, /*isConst=*/false,
@@ -268,9 +268,9 @@ Record *Program::getOrCreateRecord(const RecordDecl *RD) {
   // In error cases, the base might not be a RecordType.
   if (const auto *RT = Spec.getType()->getAs()) {
 const RecordDecl *BD = RT->getDecl();
+const Record *BR = getOrCreateRecord(BD);
 
-Record *BR = getOrCreateRecord(BD);
-if (Descriptor *Desc = GetBaseDesc(BD, BR)) {
+if (const Descriptor *Desc = GetBaseDesc(BD, BR)) {
   BaseSize += align(sizeof(InlineDescriptor));
   Bases.push_back({BD, BaseSize, Desc, BR});
   BaseSize += align(BR->getSize());
@@ -284,9 +284,9 @@ Record *Program::getOrCreateRecord(const RecordDecl *RD) {
 
   if (const auto *RT = Spec.getType()->getAs()) {
 const RecordDecl *BD = RT->getDecl();
-Record *BR = getOrCreateRecord(BD);
+const Record *BR = getOrCreateRecord(BD);
 
-if (Descriptor *Desc = GetBaseDesc(BD, BR)) {
+if (const Descriptor *Desc = GetBaseDesc(BD, BR)) {
   VirtSize += align(sizeof(InlineDescriptor));
   VirtBases.push_back({BD, VirtSize, Desc, BR});
   VirtSize += align(BR->getSize());
@@ -307,7 +307,7 @@ Record *Program::getOrCreateRecord(const RecordDecl *RD) {
 QualType FT = FD->getType();
 const bool IsConst = FT.isConstQualified();
 const bool IsMutable = FD->isMutable();
-Descriptor *Desc;
+const Descriptor *Desc;
 if (std::optional T = Ctx.classify(FT)) {
   Desc = createDescriptor(FD, *T, std::nullopt, IsConst,
   /*isTemporary=*/false, IsMutable);

diff  --git a/clang/lib/AST/Interp/Record.h b/clang/lib/AST/Interp/Record.h
index b0952af2d1ac6c..284bb468d6af47 100644
--- a/clang/lib/AST/Interp/Record.h
+++ b/clang/lib/AST/Interp/Record.h
@@ -28,7 +28,7 @@ class Record final {
   struct Field {
 const FieldDecl *Decl;
 unsigned Offset;
-Descriptor *Desc;
+const Descriptor *Desc;
 bool isBitField() const { return Decl->isBitField(); }
   };
 
@@ -36,8 +36,8 @@ class Record final {
   struct Base {
 const RecordDecl *Decl;
 unsigned Offset;
-Descriptor *Desc;
-Record *R;
+const Descriptor *Desc;
+const Record *R;
   };
 
   /// Mapping from identifiers to field descriptors.



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


[clang] [Clang] CXXConstructExpr may be immediate calls. (PR #82179)

2024-02-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: cor3ntin (cor3ntin)


Changes

A CXXConstructExpr may refer to an immediate constructor, in which case it 
should be substituted in the
enclosing default init expression.

Fixes #82154

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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+2) 
- (modified) clang/lib/Sema/SemaExpr.cpp (+6) 
- (modified) clang/test/CodeGenCXX/cxx2a-consteval.cpp (+17) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 06c7d57d73ca70..45ace4191592d3 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -265,6 +265,8 @@ Bug Fixes to C++ Support
 - No longer reject valid use of the ``_Alignas`` specifier when declaring a
   local variable, which is supported as a C11 extension in C++. Previously, it
   was only accepted at namespace scope but not at local function scope.
+- Clang no longer tries to call consteval constructors at runtime when they 
appear in a member initializer.
+  (`#782154 `_`)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 4049ab3bf6cafb..37a7db889a6eac 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -6201,6 +6201,12 @@ struct ImmediateCallVisitor : public 
RecursiveASTVisitor {
 return RecursiveASTVisitor::VisitStmt(E);
   }
 
+  bool VisitCXXConstructExpr(CXXConstructExpr *E) {
+if (const FunctionDecl *FD = E->getConstructor())
+  HasImmediateCalls |= FD->isImmediateFunction();
+return RecursiveASTVisitor::VisitStmt(E);
+  }
+
   // SourceLocExpr are not immediate invocations
   // but CXXDefaultInitExpr/CXXDefaultArgExpr containing a SourceLocExpr
   // need to be rebuilt so that they refer to the correct SourceLocation and
diff --git a/clang/test/CodeGenCXX/cxx2a-consteval.cpp 
b/clang/test/CodeGenCXX/cxx2a-consteval.cpp
index 06f1d512accec5..075cab58358abf 100644
--- a/clang/test/CodeGenCXX/cxx2a-consteval.cpp
+++ b/clang/test/CodeGenCXX/cxx2a-consteval.cpp
@@ -258,3 +258,20 @@ void void_call() { // EVAL-FN-LABEL: define {{.*}} 
@_Z9void_call
   void_test();
   // EVAL-FN: {{^}}}
 }
+
+
+namespace GH82154 {
+struct S1 { consteval S1(int) {} };
+struct S3 { constexpr S3(int) {} };
+
+void f() {
+struct S2 {
+S1 s = 0;
+S3 s2 = 0;
+};
+S2 s;
+// EVAL-FN-LABEL: define {{.*}} void @_ZZN7GH821541fEvEN2S2C2Ev
+// EVAL-FN-NOT: call void @_ZN7GH821542S1C2Ei
+// EVAL-FN: call void @_ZN7GH821542S3C2Ei
+}
+}

``




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


[clang] [Clang] CXXConstructExpr may be immediate calls. (PR #82179)

2024-02-18 Thread via cfe-commits

https://github.com/cor3ntin created 
https://github.com/llvm/llvm-project/pull/82179

A CXXConstructExpr may refer to an immediate constructor, in which case it 
should be substituted in the
enclosing default init expression.

Fixes #82154

>From c44bc36631c0b36f4a8e91f50221cc0f6d85038d Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Sun, 18 Feb 2024 18:06:14 +0100
Subject: [PATCH] [Clang] CXXConstructExpr may be immediate calls.

A CXXConstructExpr may refer to an immediate constructor,
in which case it should be substituted in the
enclosing default init expression.

Fixes #82154
---
 clang/docs/ReleaseNotes.rst   |  2 ++
 clang/lib/Sema/SemaExpr.cpp   |  6 ++
 clang/test/CodeGenCXX/cxx2a-consteval.cpp | 17 +
 3 files changed, 25 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 06c7d57d73ca70..45ace4191592d3 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -265,6 +265,8 @@ Bug Fixes to C++ Support
 - No longer reject valid use of the ``_Alignas`` specifier when declaring a
   local variable, which is supported as a C11 extension in C++. Previously, it
   was only accepted at namespace scope but not at local function scope.
+- Clang no longer tries to call consteval constructors at runtime when they 
appear in a member initializer.
+  (`#782154 `_`)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 4049ab3bf6cafb..37a7db889a6eac 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -6201,6 +6201,12 @@ struct ImmediateCallVisitor : public 
RecursiveASTVisitor {
 return RecursiveASTVisitor::VisitStmt(E);
   }
 
+  bool VisitCXXConstructExpr(CXXConstructExpr *E) {
+if (const FunctionDecl *FD = E->getConstructor())
+  HasImmediateCalls |= FD->isImmediateFunction();
+return RecursiveASTVisitor::VisitStmt(E);
+  }
+
   // SourceLocExpr are not immediate invocations
   // but CXXDefaultInitExpr/CXXDefaultArgExpr containing a SourceLocExpr
   // need to be rebuilt so that they refer to the correct SourceLocation and
diff --git a/clang/test/CodeGenCXX/cxx2a-consteval.cpp 
b/clang/test/CodeGenCXX/cxx2a-consteval.cpp
index 06f1d512accec5..075cab58358abf 100644
--- a/clang/test/CodeGenCXX/cxx2a-consteval.cpp
+++ b/clang/test/CodeGenCXX/cxx2a-consteval.cpp
@@ -258,3 +258,20 @@ void void_call() { // EVAL-FN-LABEL: define {{.*}} 
@_Z9void_call
   void_test();
   // EVAL-FN: {{^}}}
 }
+
+
+namespace GH82154 {
+struct S1 { consteval S1(int) {} };
+struct S3 { constexpr S3(int) {} };
+
+void f() {
+struct S2 {
+S1 s = 0;
+S3 s2 = 0;
+};
+S2 s;
+// EVAL-FN-LABEL: define {{.*}} void @_ZZN7GH821541fEvEN2S2C2Ev
+// EVAL-FN-NOT: call void @_ZN7GH821542S1C2Ei
+// EVAL-FN: call void @_ZN7GH821542S3C2Ei
+}
+}

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


[clang] 4136405 - [clang][Interp] Not all record bases are of RecordType

2024-02-18 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-02-18T18:07:29+01:00
New Revision: 41364051ac9380a6b62f61c794fc5978b2e703c9

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

LOG: [clang][Interp] Not all record bases are of RecordType

See the attached test case.

Added: 
clang/test/AST/Interp/crash-GH49103-2.cpp

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

Removed: 




diff  --git a/clang/lib/AST/Interp/Program.cpp 
b/clang/lib/AST/Interp/Program.cpp
index 964c0377c6dc1f..5624d5955c042c 100644
--- a/clang/lib/AST/Interp/Program.cpp
+++ b/clang/lib/AST/Interp/Program.cpp
@@ -247,7 +247,8 @@ Record *Program::getOrCreateRecord(const RecordDecl *RD) {
   unsigned VirtSize = 0;
 
   // Helper to get a base descriptor.
-  auto GetBaseDesc = [this](const RecordDecl *BD, Record *BR) -> Descriptor * {
+  auto GetBaseDesc = [this](const RecordDecl *BD,
+const Record *BR) -> Descriptor * {
 if (!BR)
   return nullptr;
 return allocateDescriptor(BD, BR, std::nullopt, /*isConst=*/false,
@@ -258,31 +259,39 @@ Record *Program::getOrCreateRecord(const RecordDecl *RD) {
   // Reserve space for base classes.
   Record::BaseList Bases;
   Record::VirtualBaseList VirtBases;
-  if (auto *CD = dyn_cast(RD)) {
+  if (const auto *CD = dyn_cast(RD)) {
+
 for (const CXXBaseSpecifier  : CD->bases()) {
   if (Spec.isVirtual())
 continue;
 
-  const RecordDecl *BD = Spec.getType()->castAs()->getDecl();
-  Record *BR = getOrCreateRecord(BD);
-  if (Descriptor *Desc = GetBaseDesc(BD, BR)) {
-BaseSize += align(sizeof(InlineDescriptor));
-Bases.push_back({BD, BaseSize, Desc, BR});
-BaseSize += align(BR->getSize());
-continue;
+  // In error cases, the base might not be a RecordType.
+  if (const auto *RT = Spec.getType()->getAs()) {
+const RecordDecl *BD = RT->getDecl();
+
+Record *BR = getOrCreateRecord(BD);
+if (Descriptor *Desc = GetBaseDesc(BD, BR)) {
+  BaseSize += align(sizeof(InlineDescriptor));
+  Bases.push_back({BD, BaseSize, Desc, BR});
+  BaseSize += align(BR->getSize());
+  continue;
+}
   }
   return nullptr;
 }
 
 for (const CXXBaseSpecifier  : CD->vbases()) {
-  const RecordDecl *BD = Spec.getType()->castAs()->getDecl();
-  Record *BR = getOrCreateRecord(BD);
 
-  if (Descriptor *Desc = GetBaseDesc(BD, BR)) {
-VirtSize += align(sizeof(InlineDescriptor));
-VirtBases.push_back({BD, VirtSize, Desc, BR});
-VirtSize += align(BR->getSize());
-continue;
+  if (const auto *RT = Spec.getType()->getAs()) {
+const RecordDecl *BD = RT->getDecl();
+Record *BR = getOrCreateRecord(BD);
+
+if (Descriptor *Desc = GetBaseDesc(BD, BR)) {
+  VirtSize += align(sizeof(InlineDescriptor));
+  VirtBases.push_back({BD, VirtSize, Desc, BR});
+  VirtSize += align(BR->getSize());
+  continue;
+}
   }
   return nullptr;
 }

diff  --git a/clang/test/AST/Interp/crash-GH49103-2.cpp 
b/clang/test/AST/Interp/crash-GH49103-2.cpp
new file mode 100644
index 00..82d78e2aeab0cc
--- /dev/null
+++ b/clang/test/AST/Interp/crash-GH49103-2.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -verify -std=c++98 %s 
-fexperimental-new-constant-interpreter
+// RUN: %clang_cc1 -verify -std=c++11 %s 
-fexperimental-new-constant-interpreter
+// RUN: %clang_cc1 -verify -std=c++14 %s 
-fexperimental-new-constant-interpreter
+// RUN: %clang_cc1 -verify -std=c++17 %s 
-fexperimental-new-constant-interpreter
+// RUN: %clang_cc1 -verify -std=c++20 %s 
-fexperimental-new-constant-interpreter
+// RUN: %clang_cc1 -verify -std=c++23 %s 
-fexperimental-new-constant-interpreter
+// RUN: %clang_cc1 -verify -std=c++2c %s 
-fexperimental-new-constant-interpreter
+
+// https://github.com/llvm/llvm-project/issues/49103
+
+template struct A; // expected-note 0+ {{}}
+struct S : __make_integer_seq { }; // expected-error 0+ {{}}
+S s;



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


[clang-tools-extra] [clang-tidy] Keep parentheses when replacing index access in `sizeof` calls (PR #82166)

2024-02-18 Thread Danny Mösch via cfe-commits

https://github.com/SimplyDanny updated 
https://github.com/llvm/llvm-project/pull/82166

From cd3c0d0d4b3133927a830c249a541510bacfabf8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Danny=20M=C3=B6sch?= 
Date: Sun, 18 Feb 2024 14:46:54 +0100
Subject: [PATCH 1/3] [clang-tidy] Keep parentheses when replacing index access
 in `sizeof` calls

---
 .../clang-tidy/modernize/LoopConvertCheck.cpp   |  8 ++--
 clang-tools-extra/docs/ReleaseNotes.rst |  5 +
 .../checkers/modernize/loop-convert-basic.cpp   | 13 -
 3 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
index f0791da143ad9d..6c9a330d733407 100644
--- a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
@@ -711,8 +711,12 @@ void LoopConvertCheck::doConversion(
   if (const auto *Paren = Parents[0].get()) {
 // Usage.Expression will be replaced with the new index variable,
 // and parenthesis around a simple DeclRefExpr can always be
-// removed.
-Range = Paren->getSourceRange();
+// removed except in case of a `sizeof` operator call.
+auto GrandParents = Context->getParents(*Paren);
+if (GrandParents.size() != 1 ||
+!GrandParents[0].get()) {
+  Range = Paren->getSourceRange();
+}
   } else if (const auto *UOP = Parents[0].get()) {
 // If we are taking the address of the loop variable, then we must
 // not use a copy, as it would mean taking the address of the 
loop's
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 7ca7037e2a6a4f..58629426216ba8 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -170,6 +170,11 @@ Changes in existing checks
   `AllowStringArrays` option, enabling the exclusion of array types with 
deduced
   length initialized from string literals.
 
+- Improved :doc:`modernize-loop-convert
+  ` check by ensuring that fix-its
+  don't remove parentheses used in ``sizeof`` calls when they have array index
+  accesses as arguments.
+
 - Improved :doc:`modernize-use-override
   ` check to also remove any trailing
   whitespace when deleting the ``virtual`` keyword.
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
index c29fbc9f9b23b7..02601b6320491a 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
@@ -1,4 +1,6 @@
-// RUN: %check_clang_tidy %s modernize-loop-convert %t -- -- -I 
%S/Inputs/loop-convert
+// RUN: %check_clang_tidy %s modernize-loop-convert %t -- -- -I 
%S/Inputs/loop-convert -isystem %clang_tidy_headers
+
+#include 
 
 #include "structures.h"
 
@@ -88,6 +90,15 @@ void f() {
   // CHECK-FIXES-NEXT: printf("Fibonacci number %d has address %p\n", I, );
   // CHECK-FIXES-NEXT: Sum += I + 2;
 
+  int Matrix[N][12];
+  size_t size = 0;
+  for (int I = 0; I < N; ++I) {
+  size += sizeof(Matrix[I]) + sizeof Matrix[I];
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & I : Matrix)
+  // CHECK-FIXES-NEXT: size += sizeof(I) + sizeof I;
+
   Val Teas[N];
   for (int I = 0; I < N; ++I) {
 Teas[I].g();

From dff0ca1e6f12e2d11838359cc1e4b7833c02cab2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Danny=20M=C3=B6sch?= 
Date: Sun, 18 Feb 2024 17:33:24 +0100
Subject: [PATCH 2/3] Avoid auto

---
 clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
index 6c9a330d733407..cac742cd46331e 100644
--- a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
@@ -706,13 +706,13 @@ void LoopConvertCheck::doConversion(
 ReplaceText = Usage.Kind == Usage::UK_MemberThroughArrow
   ? VarNameOrStructuredBinding + "."
   : VarNameOrStructuredBinding;
-auto Parents = Context->getParents(*Usage.Expression);
+const DynTypedNodeList Parents = 
Context->getParents(*Usage.Expression);
 if (Parents.size() == 1) {
   if (const auto *Paren = Parents[0].get()) {
 // Usage.Expression will be replaced with the new index variable,
 // and parenthesis around a simple DeclRefExpr can always be
 // removed except in case of a `sizeof` operator call.
-auto GrandParents = 

[clang-tools-extra] [clang-tidy] Keep parentheses when replacing index access in `sizeof` calls (PR #82166)

2024-02-18 Thread Danny Mösch via cfe-commits

https://github.com/SimplyDanny updated 
https://github.com/llvm/llvm-project/pull/82166

From cd3c0d0d4b3133927a830c249a541510bacfabf8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Danny=20M=C3=B6sch?= 
Date: Sun, 18 Feb 2024 14:46:54 +0100
Subject: [PATCH 1/2] [clang-tidy] Keep parentheses when replacing index access
 in `sizeof` calls

---
 .../clang-tidy/modernize/LoopConvertCheck.cpp   |  8 ++--
 clang-tools-extra/docs/ReleaseNotes.rst |  5 +
 .../checkers/modernize/loop-convert-basic.cpp   | 13 -
 3 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
index f0791da143ad9d..6c9a330d733407 100644
--- a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
@@ -711,8 +711,12 @@ void LoopConvertCheck::doConversion(
   if (const auto *Paren = Parents[0].get()) {
 // Usage.Expression will be replaced with the new index variable,
 // and parenthesis around a simple DeclRefExpr can always be
-// removed.
-Range = Paren->getSourceRange();
+// removed except in case of a `sizeof` operator call.
+auto GrandParents = Context->getParents(*Paren);
+if (GrandParents.size() != 1 ||
+!GrandParents[0].get()) {
+  Range = Paren->getSourceRange();
+}
   } else if (const auto *UOP = Parents[0].get()) {
 // If we are taking the address of the loop variable, then we must
 // not use a copy, as it would mean taking the address of the 
loop's
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 7ca7037e2a6a4f..58629426216ba8 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -170,6 +170,11 @@ Changes in existing checks
   `AllowStringArrays` option, enabling the exclusion of array types with 
deduced
   length initialized from string literals.
 
+- Improved :doc:`modernize-loop-convert
+  ` check by ensuring that fix-its
+  don't remove parentheses used in ``sizeof`` calls when they have array index
+  accesses as arguments.
+
 - Improved :doc:`modernize-use-override
   ` check to also remove any trailing
   whitespace when deleting the ``virtual`` keyword.
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
index c29fbc9f9b23b7..02601b6320491a 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
@@ -1,4 +1,6 @@
-// RUN: %check_clang_tidy %s modernize-loop-convert %t -- -- -I 
%S/Inputs/loop-convert
+// RUN: %check_clang_tidy %s modernize-loop-convert %t -- -- -I 
%S/Inputs/loop-convert -isystem %clang_tidy_headers
+
+#include 
 
 #include "structures.h"
 
@@ -88,6 +90,15 @@ void f() {
   // CHECK-FIXES-NEXT: printf("Fibonacci number %d has address %p\n", I, );
   // CHECK-FIXES-NEXT: Sum += I + 2;
 
+  int Matrix[N][12];
+  size_t size = 0;
+  for (int I = 0; I < N; ++I) {
+  size += sizeof(Matrix[I]) + sizeof Matrix[I];
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & I : Matrix)
+  // CHECK-FIXES-NEXT: size += sizeof(I) + sizeof I;
+
   Val Teas[N];
   for (int I = 0; I < N; ++I) {
 Teas[I].g();

From dff0ca1e6f12e2d11838359cc1e4b7833c02cab2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Danny=20M=C3=B6sch?= 
Date: Sun, 18 Feb 2024 17:33:24 +0100
Subject: [PATCH 2/2] Avoid auto

---
 clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
index 6c9a330d733407..cac742cd46331e 100644
--- a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
@@ -706,13 +706,13 @@ void LoopConvertCheck::doConversion(
 ReplaceText = Usage.Kind == Usage::UK_MemberThroughArrow
   ? VarNameOrStructuredBinding + "."
   : VarNameOrStructuredBinding;
-auto Parents = Context->getParents(*Usage.Expression);
+const DynTypedNodeList Parents = 
Context->getParents(*Usage.Expression);
 if (Parents.size() == 1) {
   if (const auto *Paren = Parents[0].get()) {
 // Usage.Expression will be replaced with the new index variable,
 // and parenthesis around a simple DeclRefExpr can always be
 // removed except in case of a `sizeof` operator call.
-auto GrandParents = 

[clang-tools-extra] [clang-tidy] Keep parentheses when replacing index access in `sizeof` calls (PR #82166)

2024-02-18 Thread via cfe-commits


@@ -711,8 +711,12 @@ void LoopConvertCheck::doConversion(
   if (const auto *Paren = Parents[0].get()) {
 // Usage.Expression will be replaced with the new index variable,
 // and parenthesis around a simple DeclRefExpr can always be
-// removed.
-Range = Paren->getSourceRange();
+// removed except in case of a `sizeof` operator call.
+auto GrandParents = Context->getParents(*Paren);

EugeneZelenko wrote:

Please do not use `auto` unless type is explicitly spelled in same statement or 
iterator.

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


[clang] ba27c39 - [clang][Interp] Classify correct type for compound shifts

2024-02-18 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-02-18T16:31:40+01:00
New Revision: ba27c3963d785a023cc8963ec3b6f508fe31527e

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

LOG: [clang][Interp] Classify correct type for compound shifts

RT must be the type of the RHS, otherwise this later fails when
we set the RHS value to the temporary variable.

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 72789d9d348144..6ad75d4e034a9d 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1468,7 +1468,7 @@ bool 
ByteCodeExprGen::VisitCompoundAssignOperator(
   std::optional LHSComputationT =
   classify(E->getComputationLHSType());
   std::optional LT = classify(LHS->getType());
-  std::optional RT = classify(E->getComputationResultType());
+  std::optional RT = classify(RHS->getType());
   std::optional ResultT = classify(E->getType());
 
   if (!LT || !RT || !ResultT || !LHSComputationT)

diff  --git a/clang/test/AST/Interp/shifts.cpp 
b/clang/test/AST/Interp/shifts.cpp
index cf71e7145c2742..e5201b3f8bbef7 100644
--- a/clang/test/AST/Interp/shifts.cpp
+++ b/clang/test/AST/Interp/shifts.cpp
@@ -188,3 +188,12 @@ namespace shifts {
   // ref-cxx17-error {{not an integral constant 
expression}} \
   // ref-cxx17-note {{in call to 'foo(2)'}}
 };
+
+namespace LongInt {
+  constexpr int f() {
+int a = 1;
+a <<= (long)0;
+return 1;
+  }
+  static_assert(f() == 1, "");
+};



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


[clang] [clang] Differentiate between identifier and string EnumArgument (PR #68550)

2024-02-18 Thread Sergei Barannikov via cfe-commits

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


[clang] 2d0137d - [clang] Differentiate between identifier and string EnumArgument (#68550)

2024-02-18 Thread via cfe-commits

Author: Sergei Barannikov
Date: 2024-02-18T17:44:19+03:00
New Revision: 2d0137dd64017c34101f8a763fd8958c20acd6bb

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

LOG: [clang] Differentiate between identifier and string EnumArgument (#68550)

EnumArgument may be a string or an identifier. If it is a string, it
should be parsed as unevaluated string literal. Add IsString flag to
EnumArgument so that the parser can choose the correct parsing method.

Target-specific attributes that share spelling may have different
attribute "prototypes". For example, ARM's version of "interrupt"
attribute accepts a string enum, while MSP430's version accepts an
unsigned integer. Adjust ClangAttrEmitter so that the generated
`attributeStringLiteralListArg` returns the correct mask depending on
target triple.

It is worth noting that even after this change some string arguments are
still parsed as identifiers or, worse, as expressions. This is because
of some special logic in `ParseAttributeArgsCommon`. Fixing it is out of
scope of this patch.

Added: 


Modified: 
clang/include/clang/Basic/Attr.td
clang/lib/Parse/ParseDecl.cpp
clang/test/Sema/attr-function-return.c
clang/test/Sema/callingconv-iamcu.c
clang/test/Sema/callingconv.c
clang/test/Sema/mips-interrupt-attr.c
clang/test/Sema/riscv-interrupt-attr.c
clang/test/Sema/zero_call_used_regs.c
clang/test/SemaCXX/warn-consumed-parsing.cpp
clang/test/SemaHLSL/shader_type_attr.hlsl
clang/utils/TableGen/ClangAttrEmitter.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 7e643b89971c17..fa191c7378dba4 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -284,12 +284,15 @@ class DefaultIntArgument : 
IntArgument {
 
 // This argument is more complex, it includes the enumerator type
 // name, whether the enum type is externally defined, a list of
-// strings to accept, and a list of enumerators to map them to.
-class EnumArgument values,
+// possible values, and a list of enumerators to map them to.
+class EnumArgument 
values,
list enums, bit opt = 0, bit fake = 0,
bit isExternalType = 0>
 : Argument {
   string Type = type;
+  // When true, the argument will be parsed as an unevaluated string literal
+  // and otherwise as an identifier.
+  bit IsString = is_string;
   list Values = values;
   list Enums = enums;
   bit IsExternalType = isExternalType;
@@ -297,10 +300,14 @@ class EnumArgument 
values,
 
 // FIXME: There should be a VariadicArgument type that takes any other type
 //of argument and generates the appropriate type.
-class VariadicEnumArgument values,
-   list enums, bit isExternalType = 0>
+class VariadicEnumArgument values, list enums,
+   bit isExternalType = 0>
 : Argument  {
   string Type = type;
+  // When true, the argument will be parsed as an unevaluated string literal
+  // and otherwise as an identifier.
+  bit IsString = is_string;
   list Values = values;
   list Enums = enums;
   bit IsExternalType = isExternalType;
@@ -907,7 +914,7 @@ def ARMInterrupt : InheritableAttr, 
TargetSpecificAttr {
   // MSP430Interrupt's, MipsInterrupt's and AnyX86Interrupt's spellings
   // must match.
   let Spellings = [GCC<"interrupt">];
-  let Args = [EnumArgument<"Interrupt", "InterruptType",
+  let Args = [EnumArgument<"Interrupt", "InterruptType", /*is_string=*/true,
["IRQ", "FIQ", "SWI", "ABORT", "UNDEF", ""],
["IRQ", "FIQ", "SWI", "ABORT", "UNDEF", "Generic"],
1>];
@@ -1032,7 +1039,8 @@ def ExternalSourceSymbol : InheritableAttr {
 
 def Blocks : InheritableAttr {
   let Spellings = [Clang<"blocks">];
-  let Args = [EnumArgument<"Type", "BlockType", ["byref"], ["ByRef"]>];
+  let Args = [EnumArgument<"Type", "BlockType", /*is_string=*/true,
+   ["byref"], ["ByRef"]>];
   let Documentation = [Undocumented];
 }
 
@@ -1614,7 +1622,7 @@ def FlagEnum : InheritableAttr {
 def EnumExtensibility : InheritableAttr {
   let Spellings = [Clang<"enum_extensibility">];
   let Subjects = SubjectList<[Enum]>;
-  let Args = [EnumArgument<"Extensibility", "Kind",
+  let Args = [EnumArgument<"Extensibility", "Kind", /*is_string=*/false,
   ["closed", "open"], ["Closed", "Open"]>];
   let Documentation = [EnumExtensibilityDocs];
 }
@@ -1780,7 +1788,7 @@ def MipsInterrupt : InheritableAttr, 
TargetSpecificAttr {
   // must match.
   let Spellings = [GCC<"interrupt">];
   let Subjects = SubjectList<[Function]>;
-  let Args = [EnumArgument<"Interrupt", "InterruptType",
+  let Args = 

[clang] [clang] Differentiate between identifier and string EnumArgument (PR #68550)

2024-02-18 Thread Sergei Barannikov via cfe-commits

https://github.com/s-barannikov updated 
https://github.com/llvm/llvm-project/pull/68550

>From 96dd0121b095f92cc66fcfc3ef08a19d0b2d6bec Mon Sep 17 00:00:00 2001
From: Sergei Barannikov 
Date: Mon, 9 Oct 2023 01:38:33 +0300
Subject: [PATCH 1/2] [clang] Differentiate between identifier and string
 EnumArgument

EnumArgument may be a string or an identifier. If it is a string, it
should be parsed as unevaluated string literal. Add IsString flag to
EnumArgument so that the parser can choose the correct parsing method.

Target-specific attributes that share spelling may have different
attribute "prototypes". For example, ARM's version of "interrupt"
attribute accepts a string enum, while MSP430's version accepts an
unsigned integer. Adjust ClangAttrEmitter so that the generated
`attributeStringLiteralListArg` returns the correct mask depending on
target triple.

It is worth noting that even after this change some string arguments are
still parsed as identifiers or, worse, as expressions. This is because
of some special logic in `ParseAttributeArgsCommon`. Fixing it is out of
scope of this patch.
---
 clang/include/clang/Basic/Attr.td| 82 +++-
 clang/lib/Parse/ParseDecl.cpp|  4 +-
 clang/test/Sema/attr-function-return.c   |  2 +-
 clang/test/Sema/callingconv-iamcu.c  |  2 +-
 clang/test/Sema/callingconv.c|  2 +-
 clang/test/Sema/zero_call_used_regs.c|  2 +-
 clang/test/SemaCXX/warn-consumed-parsing.cpp |  2 +-
 clang/test/SemaHLSL/shader_type_attr.hlsl|  4 +-
 clang/utils/TableGen/ClangAttrEmitter.cpp| 80 +++
 9 files changed, 119 insertions(+), 61 deletions(-)

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index db17211747b17d..d9b55422d3a530 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -279,12 +279,15 @@ class DefaultIntArgument : 
IntArgument {
 
 // This argument is more complex, it includes the enumerator type
 // name, whether the enum type is externally defined, a list of
-// strings to accept, and a list of enumerators to map them to.
-class EnumArgument values,
+// possible values, and a list of enumerators to map them to.
+class EnumArgument 
values,
list enums, bit opt = 0, bit fake = 0,
bit isExternalType = 0>
 : Argument {
   string Type = type;
+  // When true, the argument will be parsed as an unevaluated string literal
+  // and otherwise as an identifier.
+  bit IsString = is_string;
   list Values = values;
   list Enums = enums;
   bit IsExternalType = isExternalType;
@@ -292,10 +295,14 @@ class EnumArgument 
values,
 
 // FIXME: There should be a VariadicArgument type that takes any other type
 //of argument and generates the appropriate type.
-class VariadicEnumArgument values,
-   list enums, bit isExternalType = 0>
+class VariadicEnumArgument values, list enums,
+   bit isExternalType = 0>
 : Argument  {
   string Type = type;
+  // When true, the argument will be parsed as an unevaluated string literal
+  // and otherwise as an identifier.
+  bit IsString = is_string;
   list Values = values;
   list Enums = enums;
   bit IsExternalType = isExternalType;
@@ -898,7 +905,7 @@ def ARMInterrupt : InheritableAttr, 
TargetSpecificAttr {
   // MSP430Interrupt's, MipsInterrupt's and AnyX86Interrupt's spellings
   // must match.
   let Spellings = [GCC<"interrupt">];
-  let Args = [EnumArgument<"Interrupt", "InterruptType",
+  let Args = [EnumArgument<"Interrupt", "InterruptType", /*is_string=*/true,
["IRQ", "FIQ", "SWI", "ABORT", "UNDEF", ""],
["IRQ", "FIQ", "SWI", "ABORT", "UNDEF", "Generic"],
1>];
@@ -1023,7 +1030,8 @@ def ExternalSourceSymbol : InheritableAttr {
 
 def Blocks : InheritableAttr {
   let Spellings = [Clang<"blocks">];
-  let Args = [EnumArgument<"Type", "BlockType", ["byref"], ["ByRef"]>];
+  let Args = [EnumArgument<"Type", "BlockType", /*is_string=*/true,
+   ["byref"], ["ByRef"]>];
   let Documentation = [Undocumented];
 }
 
@@ -1597,7 +1605,7 @@ def FlagEnum : InheritableAttr {
 def EnumExtensibility : InheritableAttr {
   let Spellings = [Clang<"enum_extensibility">];
   let Subjects = SubjectList<[Enum]>;
-  let Args = [EnumArgument<"Extensibility", "Kind",
+  let Args = [EnumArgument<"Extensibility", "Kind", /*is_string=*/false,
   ["closed", "open"], ["Closed", "Open"]>];
   let Documentation = [EnumExtensibilityDocs];
 }
@@ -1763,7 +1771,7 @@ def MipsInterrupt : InheritableAttr, 
TargetSpecificAttr {
   // must match.
   let Spellings = [GCC<"interrupt">];
   let Subjects = SubjectList<[Function]>;
-  let Args = [EnumArgument<"Interrupt", "InterruptType",
+  let Args = [EnumArgument<"Interrupt", "InterruptType", /*is_string=*/true,

[clang-tools-extra] [clang-tidy] Keep parentheses when replacing index access in `sizeof` calls (PR #82166)

2024-02-18 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-tools-extra

@llvm/pr-subscribers-clang-tidy

Author: Danny Mösch (SimplyDanny)


Changes

Fixes #56021.

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


3 Files Affected:

- (modified) clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp (+6-2) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+5) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp 
(+12-1) 


``diff
diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
index f0791da143ad9d..6c9a330d733407 100644
--- a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
@@ -711,8 +711,12 @@ void LoopConvertCheck::doConversion(
   if (const auto *Paren = Parents[0].get()) {
 // Usage.Expression will be replaced with the new index variable,
 // and parenthesis around a simple DeclRefExpr can always be
-// removed.
-Range = Paren->getSourceRange();
+// removed except in case of a `sizeof` operator call.
+auto GrandParents = Context->getParents(*Paren);
+if (GrandParents.size() != 1 ||
+!GrandParents[0].get()) {
+  Range = Paren->getSourceRange();
+}
   } else if (const auto *UOP = Parents[0].get()) {
 // If we are taking the address of the loop variable, then we must
 // not use a copy, as it would mean taking the address of the 
loop's
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 7ca7037e2a6a4f..58629426216ba8 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -170,6 +170,11 @@ Changes in existing checks
   `AllowStringArrays` option, enabling the exclusion of array types with 
deduced
   length initialized from string literals.
 
+- Improved :doc:`modernize-loop-convert
+  ` check by ensuring that fix-its
+  don't remove parentheses used in ``sizeof`` calls when they have array index
+  accesses as arguments.
+
 - Improved :doc:`modernize-use-override
   ` check to also remove any trailing
   whitespace when deleting the ``virtual`` keyword.
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
index c29fbc9f9b23b7..02601b6320491a 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
@@ -1,4 +1,6 @@
-// RUN: %check_clang_tidy %s modernize-loop-convert %t -- -- -I 
%S/Inputs/loop-convert
+// RUN: %check_clang_tidy %s modernize-loop-convert %t -- -- -I 
%S/Inputs/loop-convert -isystem %clang_tidy_headers
+
+#include 
 
 #include "structures.h"
 
@@ -88,6 +90,15 @@ void f() {
   // CHECK-FIXES-NEXT: printf("Fibonacci number %d has address %p\n", I, );
   // CHECK-FIXES-NEXT: Sum += I + 2;
 
+  int Matrix[N][12];
+  size_t size = 0;
+  for (int I = 0; I < N; ++I) {
+  size += sizeof(Matrix[I]) + sizeof Matrix[I];
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & I : Matrix)
+  // CHECK-FIXES-NEXT: size += sizeof(I) + sizeof I;
+
   Val Teas[N];
   for (int I = 0; I < N; ++I) {
 Teas[I].g();

``




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


[clang-tools-extra] [clang-tidy] Keep parentheses when replacing index access in `sizeof` calls (PR #82166)

2024-02-18 Thread Danny Mösch via cfe-commits

https://github.com/SimplyDanny created 
https://github.com/llvm/llvm-project/pull/82166

Fixes #56021.

From cd3c0d0d4b3133927a830c249a541510bacfabf8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Danny=20M=C3=B6sch?= 
Date: Sun, 18 Feb 2024 14:46:54 +0100
Subject: [PATCH] [clang-tidy] Keep parentheses when replacing index access in
 `sizeof` calls

---
 .../clang-tidy/modernize/LoopConvertCheck.cpp   |  8 ++--
 clang-tools-extra/docs/ReleaseNotes.rst |  5 +
 .../checkers/modernize/loop-convert-basic.cpp   | 13 -
 3 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
index f0791da143ad9d..6c9a330d733407 100644
--- a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
@@ -711,8 +711,12 @@ void LoopConvertCheck::doConversion(
   if (const auto *Paren = Parents[0].get()) {
 // Usage.Expression will be replaced with the new index variable,
 // and parenthesis around a simple DeclRefExpr can always be
-// removed.
-Range = Paren->getSourceRange();
+// removed except in case of a `sizeof` operator call.
+auto GrandParents = Context->getParents(*Paren);
+if (GrandParents.size() != 1 ||
+!GrandParents[0].get()) {
+  Range = Paren->getSourceRange();
+}
   } else if (const auto *UOP = Parents[0].get()) {
 // If we are taking the address of the loop variable, then we must
 // not use a copy, as it would mean taking the address of the 
loop's
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 7ca7037e2a6a4f..58629426216ba8 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -170,6 +170,11 @@ Changes in existing checks
   `AllowStringArrays` option, enabling the exclusion of array types with 
deduced
   length initialized from string literals.
 
+- Improved :doc:`modernize-loop-convert
+  ` check by ensuring that fix-its
+  don't remove parentheses used in ``sizeof`` calls when they have array index
+  accesses as arguments.
+
 - Improved :doc:`modernize-use-override
   ` check to also remove any trailing
   whitespace when deleting the ``virtual`` keyword.
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
index c29fbc9f9b23b7..02601b6320491a 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
@@ -1,4 +1,6 @@
-// RUN: %check_clang_tidy %s modernize-loop-convert %t -- -- -I 
%S/Inputs/loop-convert
+// RUN: %check_clang_tidy %s modernize-loop-convert %t -- -- -I 
%S/Inputs/loop-convert -isystem %clang_tidy_headers
+
+#include 
 
 #include "structures.h"
 
@@ -88,6 +90,15 @@ void f() {
   // CHECK-FIXES-NEXT: printf("Fibonacci number %d has address %p\n", I, );
   // CHECK-FIXES-NEXT: Sum += I + 2;
 
+  int Matrix[N][12];
+  size_t size = 0;
+  for (int I = 0; I < N; ++I) {
+  size += sizeof(Matrix[I]) + sizeof Matrix[I];
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & I : Matrix)
+  // CHECK-FIXES-NEXT: size += sizeof(I) + sizeof I;
+
   Val Teas[N];
   for (int I = 0; I < N; ++I) {
 Teas[I].g();

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


[clang] [Clang] Fix looking for immediate calls in default arguments. (PR #80690)

2024-02-18 Thread via cfe-commits

https://github.com/cor3ntin updated 
https://github.com/llvm/llvm-project/pull/80690

>From 77556982a14dc7969a5ab6dc19ce0bfc8a0a763c Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Mon, 5 Feb 2024 15:42:21 +0100
Subject: [PATCH 1/2] [Clang] Fix looking for immediate calls in default
 arguments.

Due to improper use of RecursiveASTVisitor.

Fixes #80630
---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/lib/Sema/SemaExpr.cpp|  6 +++---
 .../SemaCXX/cxx2a-consteval-default-params.cpp | 15 +++
 clang/test/SemaCXX/source_location.cpp | 18 ++
 4 files changed, 38 insertions(+), 3 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 06c7d57d73ca70..184fe5dd108f96 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -265,6 +265,8 @@ Bug Fixes to C++ Support
 - No longer reject valid use of the ``_Alignas`` specifier when declaring a
   local variable, which is supported as a C11 extension in C++. Previously, it
   was only accepted at namespace scope but not at local function scope.
+- Fix evaluation of some immediate calls in default arguments.
+  Fixes (`#80630 `_)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 4049ab3bf6cafb..f75ab794886444 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -6198,7 +6198,7 @@ struct ImmediateCallVisitor : public 
RecursiveASTVisitor {
   bool VisitCallExpr(CallExpr *E) {
 if (const FunctionDecl *FD = E->getDirectCallee())
   HasImmediateCalls |= FD->isImmediateFunction();
-return RecursiveASTVisitor::VisitStmt(E);
+return RecursiveASTVisitor::VisitCallExpr(E);
   }
 
   // SourceLocExpr are not immediate invocations
@@ -6222,9 +6222,9 @@ struct ImmediateCallVisitor : public 
RecursiveASTVisitor {
 
   // Blocks don't support default parameters, and, as for lambdas,
   // we don't consider their body a subexpression.
-  bool VisitBlockDecl(BlockDecl *B) { return false; }
+  bool VisitBlockDecl(BlockDecl *B) { return true; }
 
-  bool VisitCompoundStmt(CompoundStmt *B) { return false; }
+  bool VisitCompoundStmt(CompoundStmt *B) { return true; }
 
   bool VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
 return TraverseStmt(E->getExpr());
diff --git a/clang/test/SemaCXX/cxx2a-consteval-default-params.cpp 
b/clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
index be8f7cc788589f..e4b13725b2dacd 100644
--- a/clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
+++ b/clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
@@ -82,3 +82,18 @@ namespace GH62224 {
   C<> Val; // No error since fwd is defined already.
   static_assert(Val.get() == 42);
 }
+
+namespace GH80630 {
+
+consteval const char* ce() { return "Hello"; }
+
+auto f2(const char* loc = []( char const* fn )
+{ return fn; }  ( ce() ) ) {
+return loc;
+}
+
+auto g() {
+return f2();
+}
+
+}
diff --git a/clang/test/SemaCXX/source_location.cpp 
b/clang/test/SemaCXX/source_location.cpp
index 7414fbce7828d1..b151fc45fdad62 100644
--- a/clang/test/SemaCXX/source_location.cpp
+++ b/clang/test/SemaCXX/source_location.cpp
@@ -832,3 +832,21 @@ void test() {
 }
 
 }
+
+namespace GH80630 {
+
+#define GH80630_LAMBDA \
+[]( char const* fn ) { \
+static constexpr std::source_location loc = 
std::source_location::current(); \
+return  \
+}( std::source_location::current().function() )
+
+auto f( std::source_location const* loc = GH80630_LAMBDA ) {
+return loc;
+}
+
+auto g() {
+return f();
+}
+
+}

>From c0fdb22a9e6484fdb037bec70aea69d0c9184f28 Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Sun, 18 Feb 2024 14:45:22 +0100
Subject: [PATCH 2/2] Address Aaron's feedback

---
 clang/lib/Sema/SemaExpr.cpp | 8 +---
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index f75ab794886444..0ea485cc65ce18 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -6198,7 +6198,7 @@ struct ImmediateCallVisitor : public 
RecursiveASTVisitor {
   bool VisitCallExpr(CallExpr *E) {
 if (const FunctionDecl *FD = E->getDirectCallee())
   HasImmediateCalls |= FD->isImmediateFunction();
-return RecursiveASTVisitor::VisitCallExpr(E);
+return RecursiveASTVisitor::VisitStmt(E);
   }
 
   // SourceLocExpr are not immediate invocations
@@ -6220,12 +6220,6 @@ struct ImmediateCallVisitor : public 
RecursiveASTVisitor {
 return VisitCXXMethodDecl(E->getCallOperator());
   }
 
-  // Blocks don't support default parameters, and, as for lambdas,
-  // we don't consider their body a subexpression.
-  bool VisitBlockDecl(BlockDecl *B) { return true; }
-
-  bool VisitCompoundStmt(CompoundStmt *B) { return true; }
-
   bool VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
 return 

[clang] [clang][Sema] Fix for enums overflowing (#24667) (PR #78742)

2024-02-18 Thread via cfe-commits

https://github.com/wheatman updated 
https://github.com/llvm/llvm-project/pull/78742

>From 6bbd4953ff86a120097fae7bb83e00989392c14f Mon Sep 17 00:00:00 2001
From: Brian Wheatman 
Date: Fri, 19 Jan 2024 11:13:33 -0500
Subject: [PATCH] [clang][Sema] Fix for enums overflowing (#24667)

Enums which do not have a specified type can only grow to bigger types
which contain more bits than the prior types.  This means that the
largest signed integer type cannot grow to the largest unsigned integer types.

In the Process also implements N3029 Improved Normal Enumerations and N3030
Enhancements to Enumerations which brings C enums more inline with C++
enums.

Fixes #24667
---
 clang/docs/ReleaseNotes.rst |  9 +
 clang/lib/Sema/SemaDecl.cpp | 65 -
 clang/test/Sema/enum.c  | 41 +--
 clang/test/SemaCXX/enum.cpp |  2 ++
 4 files changed, 98 insertions(+), 19 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 06c7d57d73ca70..35b7e314b0ceb7 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -135,6 +135,13 @@ C23 Feature Support
 
   Fixes (`#81472 `_).
 
+  - Enumerations should allow values greater than INT_MAX and smaller than
+INT_MIN, in order to provide a value-preserved set of integer constants. 
`N3029 Improved Normal Enumerations 
`_
+
+  - Enumerations should have the ability to specify the underlying type to aid
+in portability and usability across platforms, across ABIs, and across
+languages (for serialization and similar purposes). `N3030 Enhancements to 
Enumerations `_
+
 Non-comprehensive list of changes in this release
 -
 
@@ -207,6 +214,8 @@ Bug Fixes in This Version
 - Clang now doesn't produce false-positive warning `-Wconstant-logical-operand`
   for logical operators in C23.
   Fixes (`#64356 `_).
+- Fixes miscompilation when an enum has a specified value such that the auto
+  increment overflows a signed long. Fixes (`#24667 
`_)
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 0aaaba0e5d15f9..34c07d32a551aa 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -19781,6 +19781,19 @@ EnumConstantDecl *Sema::CheckEnumConstant(EnumDecl 
*Enum,
   // - If an initializer is specified for an enumerator, the
   //   initializing value has the same type as the expression.
   EltTy = Val->getType();
+} else if (getLangOpts().C23) {
+  // C23 6.7.2.2p11 b4
+  // int, if given explicitly with = and the value of the
+  // integer constant expression is representable by an int
+  //
+  // C23 6.7.2.2p11 b5
+  // the type of the integer constant expression, if given
+  // explicitly with = and if the value of the integer
+  // constant expression is not representable by int;
+  if (isRepresentableIntegerValue(Context, EnumVal, Context.IntTy)) {
+Val = ImpCastExprToType(Val, Context.IntTy, CK_IntegralCast).get();
+  }
+  EltTy = Val->getType();
 } else {
   // C99 6.7.2.2p2:
   //   The expression that defines the value of an enumeration constant
@@ -19790,8 +19803,8 @@ EnumConstantDecl *Sema::CheckEnumConstant(EnumDecl 
*Enum,
   // Complain if the value is not representable in an int.
   if (!isRepresentableIntegerValue(Context, EnumVal, Context.IntTy))
 Diag(IdLoc, diag::ext_enum_value_not_int)
-  << toString(EnumVal, 10) << Val->getSourceRange()
-  << (EnumVal.isUnsigned() || EnumVal.isNonNegative());
+<< toString(EnumVal, 10) << Val->getSourceRange()
+<< (EnumVal.isUnsigned() || EnumVal.isNonNegative());
   else if (!Context.hasSameType(Val->getType(), Context.IntTy)) {
 // Force the type of the expression to 'int'.
 Val = ImpCastExprToType(Val, Context.IntTy, CK_IntegralCast).get();
@@ -19839,20 +19852,28 @@ EnumConstantDecl *Sema::CheckEnumConstant(EnumDecl 
*Enum,
 //   sufficient to contain the incremented value. If no such type
 //   exists, the program is ill-formed.
 QualType T = getNextLargerIntegralType(Context, EltTy);
-if (T.isNull() || Enum->isFixed()) {
+if (Enum->isFixed()) {
   // There is no integral type larger enough to represent this
   // value. Complain, then allow the value to wrap around.
   EnumVal = LastEnumConst->getInitVal();
   EnumVal = 

[clang] [clang] move -Wcast-function-type under -Wextra (PR #77178)

2024-02-18 Thread Abhin P Jose via cfe-commits

https://github.com/Abhinkop updated 
https://github.com/llvm/llvm-project/pull/77178

>From d147292312ea05eb6b4a28940faffe54093c900e Mon Sep 17 00:00:00 2001
From: Abhin Parekadan Jose 
Date: Sat, 6 Jan 2024 05:09:36 +0100
Subject: [PATCH 1/8] [clang] move -Wcast-function-type under -Wextra

---
 clang/include/clang/Basic/DiagnosticGroups.td |  1 +
 .../Sema/warn-cast-function-type-strict.c |  2 +-
 clang/test/Sema/warn-cast-function-type.c |  1 +
 .../warn-extra-cast-function-type-strict.c| 42 +++
 .../warn-cast-function-type-strict.cpp|  1 +
 .../test/SemaCXX/warn-cast-function-type.cpp  |  1 +
 6 files changed, 47 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Sema/warn-extra-cast-function-type-strict.c

diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 6765721ae7002c..d3e57de8ac7a58 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1026,6 +1026,7 @@ def Extra : DiagGroup<"extra", [
 EmptyInitStatement,
 StringConcatation,
 FUseLdPath,
+CastFunctionType,
   ]>;
 
 def Most : DiagGroup<"most", [
diff --git a/clang/test/Sema/warn-cast-function-type-strict.c 
b/clang/test/Sema/warn-cast-function-type-strict.c
index 5233680796e972..68b49bb0d05d06 100644
--- a/clang/test/Sema/warn-cast-function-type-strict.c
+++ b/clang/test/Sema/warn-cast-function-type-strict.c
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 %s -fsyntax-only -Wcast-function-type -verify
 // RUN: %clang_cc1 %s -fsyntax-only -Wcast-function-type-strict -verify
-
+// RUN: %clang_cc1 %s -fsyntax-only -Wextra -Wno-ignored-qualifiers -verify
 
 int t(int array[static 12]);
 int u(int i);
diff --git a/clang/test/Sema/warn-cast-function-type.c 
b/clang/test/Sema/warn-cast-function-type.c
index d7ddcdb73725c0..09d169026b1c86 100644
--- a/clang/test/Sema/warn-cast-function-type.c
+++ b/clang/test/Sema/warn-cast-function-type.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -fsyntax-only -Wcast-function-type 
-Wno-cast-function-type-strict -verify
+// RUN: %clang_cc1 %s -fsyntax-only -Wextra -Wno-cast-function-type-strict 
-verify
 
 int x(long);
 
diff --git a/clang/test/Sema/warn-extra-cast-function-type-strict.c 
b/clang/test/Sema/warn-extra-cast-function-type-strict.c
new file mode 100644
index 00..ef8853616ba832
--- /dev/null
+++ b/clang/test/Sema/warn-extra-cast-function-type-strict.c
@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 %s -fsyntax-only -Wextra -verify
+
+
+int t(int array[static 12]);
+int u(int i);
+const int v(int i); /* expected-warning {{'const' type qualifier on return 
type has no effec}} */
+int x(long);
+
+typedef int (f1)(long);
+typedef int (f2)(void*);
+typedef int (f3)();
+typedef void (f4)();
+typedef void (f5)(void);
+typedef int (f6)(long, int);
+typedef int (f7)(long,...);
+typedef int (f8)(int *);
+typedef int (f9)(const int);
+typedef int (f10)(int);
+
+f1 *a;
+f2 *b;
+f3 *c;
+f4 *d;
+f5 *e;
+f6 *f;
+f7 *g;
+f8 *h;
+f9 *i;
+f10 *j;
+
+void foo(void) {
+  a = (f1 *)x;
+  b = (f2 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f2 *' (aka 
'int (*)(void *)') converts to incompatible function type}} */
+  c = (f3 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f3 *' (aka 
'int (*)()') converts to incompatible function type}} */
+  d = (f4 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f4 *' (aka 
'void (*)()') converts to incompatible function type}} */
+  e = (f5 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f5 *' (aka 
'void (*)(void)') converts to incompatible function type}} */
+  f = (f6 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f6 *' (aka 
'int (*)(long, int)') converts to incompatible function type}} */
+  g = (f7 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f7 *' (aka 
'int (*)(long, ...)') converts to incompatible function type}} */
+  h = (f8 *)t;
+  i = (f9 *)u;
+  j = (f10 *)v; /* expected-warning {{cast from 'const int (*)(int)' to 'f10 
*' (aka 'int (*)(int)') converts to incompatible function type}} */
+}
diff --git a/clang/test/SemaCXX/warn-cast-function-type-strict.cpp 
b/clang/test/SemaCXX/warn-cast-function-type-strict.cpp
index f7ee55f84ac280..b3164afde5a0ca 100644
--- a/clang/test/SemaCXX/warn-cast-function-type-strict.cpp
+++ b/clang/test/SemaCXX/warn-cast-function-type-strict.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 %s -fblocks -fsyntax-only -Wcast-function-type -verify
 // RUN: %clang_cc1 %s -fblocks -fsyntax-only -Wcast-function-type-strict 
-verify
+// RUN: %clang_cc1 %s -fblocks -fsyntax-only -Wextra -verify
 
 int x(long);
 
diff --git a/clang/test/SemaCXX/warn-cast-function-type.cpp 
b/clang/test/SemaCXX/warn-cast-function-type.cpp
index c613aaea1e33f2..db2ee030fcbfc9 100644
--- a/clang/test/SemaCXX/warn-cast-function-type.cpp
+++ b/clang/test/SemaCXX/warn-cast-function-type.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -fblocks -fsyntax-only 

[clang] [clang][Sema] Fix for enums overflowing (#24667) (PR #78742)

2024-02-18 Thread via cfe-commits

https://github.com/wheatman updated 
https://github.com/llvm/llvm-project/pull/78742

>From 88a908062d5d217d529b48028bd861bdf6fa9e76 Mon Sep 17 00:00:00 2001
From: Brian Wheatman 
Date: Fri, 19 Jan 2024 11:13:33 -0500
Subject: [PATCH] [clang][Sema] Fix for enums overflowing (#24667)

Enums which do not have a specified type can only grow to bigger types
which contain more bits than the prior types.  This means that the
largest signed integer type cannot grow to the largest unsigned integer types.

In the Process also implements N3029 Improved Normal Enumerations and N3030
Enhancements to Enumerations which brings C enums more inline with C++
enums.

Fixes #24667
---
 clang/docs/ReleaseNotes.rst |  9 +
 clang/lib/Sema/SemaDecl.cpp | 65 -
 clang/test/Sema/enum.c  | 41 +--
 clang/test/SemaCXX/enum.cpp |  2 ++
 4 files changed, 98 insertions(+), 19 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 06c7d57d73ca70..54a753b1301276 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -135,6 +135,13 @@ C23 Feature Support
 
   Fixes (`#81472 `_).
 
+  - Enumerations should allow values greater than INT_MAX and smaller than 
+INT_MIN, in order to provide a value-preserved set of integer constants. 
`N3029 Improved Normal Enumerations 
`_
+
+  - Enumerations should have the ability to specify the underlying type to aid
+in portability and usability across platforms, across ABIs, and across
+languages (for serialization and similar purposes). `N3030 Enhancements to 
Enumerations `_
+
 Non-comprehensive list of changes in this release
 -
 
@@ -207,6 +214,8 @@ Bug Fixes in This Version
 - Clang now doesn't produce false-positive warning `-Wconstant-logical-operand`
   for logical operators in C23.
   Fixes (`#64356 `_).
+- Fixes miscompilation when an enum has a specified value such that the auto
+  increment overflows a signed long. Fixes (`#24667 
`_)
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 0aaaba0e5d15f9..34c07d32a551aa 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -19781,6 +19781,19 @@ EnumConstantDecl *Sema::CheckEnumConstant(EnumDecl 
*Enum,
   // - If an initializer is specified for an enumerator, the
   //   initializing value has the same type as the expression.
   EltTy = Val->getType();
+} else if (getLangOpts().C23) {
+  // C23 6.7.2.2p11 b4
+  // int, if given explicitly with = and the value of the
+  // integer constant expression is representable by an int
+  //
+  // C23 6.7.2.2p11 b5
+  // the type of the integer constant expression, if given
+  // explicitly with = and if the value of the integer
+  // constant expression is not representable by int;
+  if (isRepresentableIntegerValue(Context, EnumVal, Context.IntTy)) {
+Val = ImpCastExprToType(Val, Context.IntTy, CK_IntegralCast).get();
+  }
+  EltTy = Val->getType();
 } else {
   // C99 6.7.2.2p2:
   //   The expression that defines the value of an enumeration constant
@@ -19790,8 +19803,8 @@ EnumConstantDecl *Sema::CheckEnumConstant(EnumDecl 
*Enum,
   // Complain if the value is not representable in an int.
   if (!isRepresentableIntegerValue(Context, EnumVal, Context.IntTy))
 Diag(IdLoc, diag::ext_enum_value_not_int)
-  << toString(EnumVal, 10) << Val->getSourceRange()
-  << (EnumVal.isUnsigned() || EnumVal.isNonNegative());
+<< toString(EnumVal, 10) << Val->getSourceRange()
+<< (EnumVal.isUnsigned() || EnumVal.isNonNegative());
   else if (!Context.hasSameType(Val->getType(), Context.IntTy)) {
 // Force the type of the expression to 'int'.
 Val = ImpCastExprToType(Val, Context.IntTy, CK_IntegralCast).get();
@@ -19839,20 +19852,28 @@ EnumConstantDecl *Sema::CheckEnumConstant(EnumDecl 
*Enum,
 //   sufficient to contain the incremented value. If no such type
 //   exists, the program is ill-formed.
 QualType T = getNextLargerIntegralType(Context, EltTy);
-if (T.isNull() || Enum->isFixed()) {
+if (Enum->isFixed()) {
   // There is no integral type larger enough to represent this
   // value. Complain, then allow the value to wrap around.
   EnumVal = LastEnumConst->getInitVal();
   EnumVal = 

[clang] [clang] move -Wcast-function-type under -Wextra (PR #77178)

2024-02-18 Thread Abhin P Jose via cfe-commits

https://github.com/Abhinkop updated 
https://github.com/llvm/llvm-project/pull/77178

>From d147292312ea05eb6b4a28940faffe54093c900e Mon Sep 17 00:00:00 2001
From: Abhin Parekadan Jose 
Date: Sat, 6 Jan 2024 05:09:36 +0100
Subject: [PATCH 1/4] [clang] move -Wcast-function-type under -Wextra

---
 clang/include/clang/Basic/DiagnosticGroups.td |  1 +
 .../Sema/warn-cast-function-type-strict.c |  2 +-
 clang/test/Sema/warn-cast-function-type.c |  1 +
 .../warn-extra-cast-function-type-strict.c| 42 +++
 .../warn-cast-function-type-strict.cpp|  1 +
 .../test/SemaCXX/warn-cast-function-type.cpp  |  1 +
 6 files changed, 47 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Sema/warn-extra-cast-function-type-strict.c

diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 6765721ae7002c..d3e57de8ac7a58 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1026,6 +1026,7 @@ def Extra : DiagGroup<"extra", [
 EmptyInitStatement,
 StringConcatation,
 FUseLdPath,
+CastFunctionType,
   ]>;
 
 def Most : DiagGroup<"most", [
diff --git a/clang/test/Sema/warn-cast-function-type-strict.c 
b/clang/test/Sema/warn-cast-function-type-strict.c
index 5233680796e972..68b49bb0d05d06 100644
--- a/clang/test/Sema/warn-cast-function-type-strict.c
+++ b/clang/test/Sema/warn-cast-function-type-strict.c
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 %s -fsyntax-only -Wcast-function-type -verify
 // RUN: %clang_cc1 %s -fsyntax-only -Wcast-function-type-strict -verify
-
+// RUN: %clang_cc1 %s -fsyntax-only -Wextra -Wno-ignored-qualifiers -verify
 
 int t(int array[static 12]);
 int u(int i);
diff --git a/clang/test/Sema/warn-cast-function-type.c 
b/clang/test/Sema/warn-cast-function-type.c
index d7ddcdb73725c0..09d169026b1c86 100644
--- a/clang/test/Sema/warn-cast-function-type.c
+++ b/clang/test/Sema/warn-cast-function-type.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -fsyntax-only -Wcast-function-type 
-Wno-cast-function-type-strict -verify
+// RUN: %clang_cc1 %s -fsyntax-only -Wextra -Wno-cast-function-type-strict 
-verify
 
 int x(long);
 
diff --git a/clang/test/Sema/warn-extra-cast-function-type-strict.c 
b/clang/test/Sema/warn-extra-cast-function-type-strict.c
new file mode 100644
index 00..ef8853616ba832
--- /dev/null
+++ b/clang/test/Sema/warn-extra-cast-function-type-strict.c
@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 %s -fsyntax-only -Wextra -verify
+
+
+int t(int array[static 12]);
+int u(int i);
+const int v(int i); /* expected-warning {{'const' type qualifier on return 
type has no effec}} */
+int x(long);
+
+typedef int (f1)(long);
+typedef int (f2)(void*);
+typedef int (f3)();
+typedef void (f4)();
+typedef void (f5)(void);
+typedef int (f6)(long, int);
+typedef int (f7)(long,...);
+typedef int (f8)(int *);
+typedef int (f9)(const int);
+typedef int (f10)(int);
+
+f1 *a;
+f2 *b;
+f3 *c;
+f4 *d;
+f5 *e;
+f6 *f;
+f7 *g;
+f8 *h;
+f9 *i;
+f10 *j;
+
+void foo(void) {
+  a = (f1 *)x;
+  b = (f2 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f2 *' (aka 
'int (*)(void *)') converts to incompatible function type}} */
+  c = (f3 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f3 *' (aka 
'int (*)()') converts to incompatible function type}} */
+  d = (f4 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f4 *' (aka 
'void (*)()') converts to incompatible function type}} */
+  e = (f5 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f5 *' (aka 
'void (*)(void)') converts to incompatible function type}} */
+  f = (f6 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f6 *' (aka 
'int (*)(long, int)') converts to incompatible function type}} */
+  g = (f7 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f7 *' (aka 
'int (*)(long, ...)') converts to incompatible function type}} */
+  h = (f8 *)t;
+  i = (f9 *)u;
+  j = (f10 *)v; /* expected-warning {{cast from 'const int (*)(int)' to 'f10 
*' (aka 'int (*)(int)') converts to incompatible function type}} */
+}
diff --git a/clang/test/SemaCXX/warn-cast-function-type-strict.cpp 
b/clang/test/SemaCXX/warn-cast-function-type-strict.cpp
index f7ee55f84ac280..b3164afde5a0ca 100644
--- a/clang/test/SemaCXX/warn-cast-function-type-strict.cpp
+++ b/clang/test/SemaCXX/warn-cast-function-type-strict.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 %s -fblocks -fsyntax-only -Wcast-function-type -verify
 // RUN: %clang_cc1 %s -fblocks -fsyntax-only -Wcast-function-type-strict 
-verify
+// RUN: %clang_cc1 %s -fblocks -fsyntax-only -Wextra -verify
 
 int x(long);
 
diff --git a/clang/test/SemaCXX/warn-cast-function-type.cpp 
b/clang/test/SemaCXX/warn-cast-function-type.cpp
index c613aaea1e33f2..db2ee030fcbfc9 100644
--- a/clang/test/SemaCXX/warn-cast-function-type.cpp
+++ b/clang/test/SemaCXX/warn-cast-function-type.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -fblocks -fsyntax-only 

[clang] [clang] move -Wcast-function-type under -Wextra (PR #77178)

2024-02-18 Thread Abhin P Jose via cfe-commits

https://github.com/Abhinkop updated 
https://github.com/llvm/llvm-project/pull/77178

>From d147292312ea05eb6b4a28940faffe54093c900e Mon Sep 17 00:00:00 2001
From: Abhin Parekadan Jose 
Date: Sat, 6 Jan 2024 05:09:36 +0100
Subject: [PATCH 1/3] [clang] move -Wcast-function-type under -Wextra

---
 clang/include/clang/Basic/DiagnosticGroups.td |  1 +
 .../Sema/warn-cast-function-type-strict.c |  2 +-
 clang/test/Sema/warn-cast-function-type.c |  1 +
 .../warn-extra-cast-function-type-strict.c| 42 +++
 .../warn-cast-function-type-strict.cpp|  1 +
 .../test/SemaCXX/warn-cast-function-type.cpp  |  1 +
 6 files changed, 47 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Sema/warn-extra-cast-function-type-strict.c

diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 6765721ae7002c..d3e57de8ac7a58 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1026,6 +1026,7 @@ def Extra : DiagGroup<"extra", [
 EmptyInitStatement,
 StringConcatation,
 FUseLdPath,
+CastFunctionType,
   ]>;
 
 def Most : DiagGroup<"most", [
diff --git a/clang/test/Sema/warn-cast-function-type-strict.c 
b/clang/test/Sema/warn-cast-function-type-strict.c
index 5233680796e972..68b49bb0d05d06 100644
--- a/clang/test/Sema/warn-cast-function-type-strict.c
+++ b/clang/test/Sema/warn-cast-function-type-strict.c
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 %s -fsyntax-only -Wcast-function-type -verify
 // RUN: %clang_cc1 %s -fsyntax-only -Wcast-function-type-strict -verify
-
+// RUN: %clang_cc1 %s -fsyntax-only -Wextra -Wno-ignored-qualifiers -verify
 
 int t(int array[static 12]);
 int u(int i);
diff --git a/clang/test/Sema/warn-cast-function-type.c 
b/clang/test/Sema/warn-cast-function-type.c
index d7ddcdb73725c0..09d169026b1c86 100644
--- a/clang/test/Sema/warn-cast-function-type.c
+++ b/clang/test/Sema/warn-cast-function-type.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -fsyntax-only -Wcast-function-type 
-Wno-cast-function-type-strict -verify
+// RUN: %clang_cc1 %s -fsyntax-only -Wextra -Wno-cast-function-type-strict 
-verify
 
 int x(long);
 
diff --git a/clang/test/Sema/warn-extra-cast-function-type-strict.c 
b/clang/test/Sema/warn-extra-cast-function-type-strict.c
new file mode 100644
index 00..ef8853616ba832
--- /dev/null
+++ b/clang/test/Sema/warn-extra-cast-function-type-strict.c
@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 %s -fsyntax-only -Wextra -verify
+
+
+int t(int array[static 12]);
+int u(int i);
+const int v(int i); /* expected-warning {{'const' type qualifier on return 
type has no effec}} */
+int x(long);
+
+typedef int (f1)(long);
+typedef int (f2)(void*);
+typedef int (f3)();
+typedef void (f4)();
+typedef void (f5)(void);
+typedef int (f6)(long, int);
+typedef int (f7)(long,...);
+typedef int (f8)(int *);
+typedef int (f9)(const int);
+typedef int (f10)(int);
+
+f1 *a;
+f2 *b;
+f3 *c;
+f4 *d;
+f5 *e;
+f6 *f;
+f7 *g;
+f8 *h;
+f9 *i;
+f10 *j;
+
+void foo(void) {
+  a = (f1 *)x;
+  b = (f2 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f2 *' (aka 
'int (*)(void *)') converts to incompatible function type}} */
+  c = (f3 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f3 *' (aka 
'int (*)()') converts to incompatible function type}} */
+  d = (f4 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f4 *' (aka 
'void (*)()') converts to incompatible function type}} */
+  e = (f5 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f5 *' (aka 
'void (*)(void)') converts to incompatible function type}} */
+  f = (f6 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f6 *' (aka 
'int (*)(long, int)') converts to incompatible function type}} */
+  g = (f7 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f7 *' (aka 
'int (*)(long, ...)') converts to incompatible function type}} */
+  h = (f8 *)t;
+  i = (f9 *)u;
+  j = (f10 *)v; /* expected-warning {{cast from 'const int (*)(int)' to 'f10 
*' (aka 'int (*)(int)') converts to incompatible function type}} */
+}
diff --git a/clang/test/SemaCXX/warn-cast-function-type-strict.cpp 
b/clang/test/SemaCXX/warn-cast-function-type-strict.cpp
index f7ee55f84ac280..b3164afde5a0ca 100644
--- a/clang/test/SemaCXX/warn-cast-function-type-strict.cpp
+++ b/clang/test/SemaCXX/warn-cast-function-type-strict.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 %s -fblocks -fsyntax-only -Wcast-function-type -verify
 // RUN: %clang_cc1 %s -fblocks -fsyntax-only -Wcast-function-type-strict 
-verify
+// RUN: %clang_cc1 %s -fblocks -fsyntax-only -Wextra -verify
 
 int x(long);
 
diff --git a/clang/test/SemaCXX/warn-cast-function-type.cpp 
b/clang/test/SemaCXX/warn-cast-function-type.cpp
index c613aaea1e33f2..db2ee030fcbfc9 100644
--- a/clang/test/SemaCXX/warn-cast-function-type.cpp
+++ b/clang/test/SemaCXX/warn-cast-function-type.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -fblocks -fsyntax-only 

[clang] [clang] move -Wcast-function-type under -Wextra (PR #77178)

2024-02-18 Thread Abhin P Jose via cfe-commits


@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 %s -fsyntax-only -Wextra -verify

Abhinkop wrote:

Done. File removed, and a FIXME comment added for the existing test. 

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


[clang] [clang] move -Wcast-function-type under -Wextra (PR #77178)

2024-02-18 Thread Abhin P Jose via cfe-commits


@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 %s -fsyntax-only -Wextra -verify
+
+
+int t(int array[static 12]);
+int u(int i);
+const int v(int i); /* expected-warning {{'const' type qualifier on return 
type has no effec}} */
+int x(long);
+
+typedef int (f1)(long);
+typedef int (f2)(void*);
+typedef int (f3)();
+typedef void (f4)();
+typedef void (f5)(void);
+typedef int (f6)(long, int);
+typedef int (f7)(long,...);
+typedef int (f8)(int *);
+typedef int (f9)(const int);
+typedef int (f10)(int);
+
+f1 *a;
+f2 *b;
+f3 *c;
+f4 *d;
+f5 *e;
+f6 *f;
+f7 *g;
+f8 *h;
+f9 *i;
+f10 *j;
+
+void foo(void) {
+  a = (f1 *)x;
+  b = (f2 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f2 *' (aka 
'int (*)(void *)') converts to incompatible function type}} */
+  c = (f3 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f3 *' (aka 
'int (*)()') converts to incompatible function type}} */
+  d = (f4 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f4 *' (aka 
'void (*)()') converts to incompatible function type}} */
+  e = (f5 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f5 *' (aka 
'void (*)(void)') converts to incompatible function type}} */
+  f = (f6 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f6 *' (aka 
'int (*)(long, int)') converts to incompatible function type}} */
+  g = (f7 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f7 *' (aka 
'int (*)(long, ...)') converts to incompatible function type}} */
+  h = (f8 *)t;
+  i = (f9 *)u;
+  j = (f10 *)v; /* expected-warning {{cast from 'const int (*)(int)' to 'f10 
*' (aka 'int (*)(int)') converts to incompatible function type}} */

Abhinkop wrote:

Done.

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


[clang] [clang] move -Wcast-function-type under -Wextra (PR #77178)

2024-02-18 Thread Abhin P Jose via cfe-commits


@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 %s -fsyntax-only -Wextra -verify
+
+
+int t(int array[static 12]);
+int u(int i);
+const int v(int i); /* expected-warning {{'const' type qualifier on return 
type has no effec}} */

Abhinkop wrote:

Didn't have to do it as the file is now not added.

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


[clang] [clang] move -Wcast-function-type under -Wextra (PR #77178)

2024-02-18 Thread Abhin P Jose via cfe-commits

https://github.com/Abhinkop updated 
https://github.com/llvm/llvm-project/pull/77178

>From d147292312ea05eb6b4a28940faffe54093c900e Mon Sep 17 00:00:00 2001
From: Abhin Parekadan Jose 
Date: Sat, 6 Jan 2024 05:09:36 +0100
Subject: [PATCH 1/3] [clang] move -Wcast-function-type under -Wextra

---
 clang/include/clang/Basic/DiagnosticGroups.td |  1 +
 .../Sema/warn-cast-function-type-strict.c |  2 +-
 clang/test/Sema/warn-cast-function-type.c |  1 +
 .../warn-extra-cast-function-type-strict.c| 42 +++
 .../warn-cast-function-type-strict.cpp|  1 +
 .../test/SemaCXX/warn-cast-function-type.cpp  |  1 +
 6 files changed, 47 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Sema/warn-extra-cast-function-type-strict.c

diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 6765721ae7002c..d3e57de8ac7a58 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1026,6 +1026,7 @@ def Extra : DiagGroup<"extra", [
 EmptyInitStatement,
 StringConcatation,
 FUseLdPath,
+CastFunctionType,
   ]>;
 
 def Most : DiagGroup<"most", [
diff --git a/clang/test/Sema/warn-cast-function-type-strict.c 
b/clang/test/Sema/warn-cast-function-type-strict.c
index 5233680796e972..68b49bb0d05d06 100644
--- a/clang/test/Sema/warn-cast-function-type-strict.c
+++ b/clang/test/Sema/warn-cast-function-type-strict.c
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 %s -fsyntax-only -Wcast-function-type -verify
 // RUN: %clang_cc1 %s -fsyntax-only -Wcast-function-type-strict -verify
-
+// RUN: %clang_cc1 %s -fsyntax-only -Wextra -Wno-ignored-qualifiers -verify
 
 int t(int array[static 12]);
 int u(int i);
diff --git a/clang/test/Sema/warn-cast-function-type.c 
b/clang/test/Sema/warn-cast-function-type.c
index d7ddcdb73725c0..09d169026b1c86 100644
--- a/clang/test/Sema/warn-cast-function-type.c
+++ b/clang/test/Sema/warn-cast-function-type.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -fsyntax-only -Wcast-function-type 
-Wno-cast-function-type-strict -verify
+// RUN: %clang_cc1 %s -fsyntax-only -Wextra -Wno-cast-function-type-strict 
-verify
 
 int x(long);
 
diff --git a/clang/test/Sema/warn-extra-cast-function-type-strict.c 
b/clang/test/Sema/warn-extra-cast-function-type-strict.c
new file mode 100644
index 00..ef8853616ba832
--- /dev/null
+++ b/clang/test/Sema/warn-extra-cast-function-type-strict.c
@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 %s -fsyntax-only -Wextra -verify
+
+
+int t(int array[static 12]);
+int u(int i);
+const int v(int i); /* expected-warning {{'const' type qualifier on return 
type has no effec}} */
+int x(long);
+
+typedef int (f1)(long);
+typedef int (f2)(void*);
+typedef int (f3)();
+typedef void (f4)();
+typedef void (f5)(void);
+typedef int (f6)(long, int);
+typedef int (f7)(long,...);
+typedef int (f8)(int *);
+typedef int (f9)(const int);
+typedef int (f10)(int);
+
+f1 *a;
+f2 *b;
+f3 *c;
+f4 *d;
+f5 *e;
+f6 *f;
+f7 *g;
+f8 *h;
+f9 *i;
+f10 *j;
+
+void foo(void) {
+  a = (f1 *)x;
+  b = (f2 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f2 *' (aka 
'int (*)(void *)') converts to incompatible function type}} */
+  c = (f3 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f3 *' (aka 
'int (*)()') converts to incompatible function type}} */
+  d = (f4 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f4 *' (aka 
'void (*)()') converts to incompatible function type}} */
+  e = (f5 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f5 *' (aka 
'void (*)(void)') converts to incompatible function type}} */
+  f = (f6 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f6 *' (aka 
'int (*)(long, int)') converts to incompatible function type}} */
+  g = (f7 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f7 *' (aka 
'int (*)(long, ...)') converts to incompatible function type}} */
+  h = (f8 *)t;
+  i = (f9 *)u;
+  j = (f10 *)v; /* expected-warning {{cast from 'const int (*)(int)' to 'f10 
*' (aka 'int (*)(int)') converts to incompatible function type}} */
+}
diff --git a/clang/test/SemaCXX/warn-cast-function-type-strict.cpp 
b/clang/test/SemaCXX/warn-cast-function-type-strict.cpp
index f7ee55f84ac280..b3164afde5a0ca 100644
--- a/clang/test/SemaCXX/warn-cast-function-type-strict.cpp
+++ b/clang/test/SemaCXX/warn-cast-function-type-strict.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 %s -fblocks -fsyntax-only -Wcast-function-type -verify
 // RUN: %clang_cc1 %s -fblocks -fsyntax-only -Wcast-function-type-strict 
-verify
+// RUN: %clang_cc1 %s -fblocks -fsyntax-only -Wextra -verify
 
 int x(long);
 
diff --git a/clang/test/SemaCXX/warn-cast-function-type.cpp 
b/clang/test/SemaCXX/warn-cast-function-type.cpp
index c613aaea1e33f2..db2ee030fcbfc9 100644
--- a/clang/test/SemaCXX/warn-cast-function-type.cpp
+++ b/clang/test/SemaCXX/warn-cast-function-type.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -fblocks -fsyntax-only 

[clang] [clang] move -Wcast-function-type under -Wextra (PR #77178)

2024-02-18 Thread Abhin P Jose via cfe-commits

https://github.com/Abhinkop updated 
https://github.com/llvm/llvm-project/pull/77178

>From d147292312ea05eb6b4a28940faffe54093c900e Mon Sep 17 00:00:00 2001
From: Abhin Parekadan Jose 
Date: Sat, 6 Jan 2024 05:09:36 +0100
Subject: [PATCH 1/2] [clang] move -Wcast-function-type under -Wextra

---
 clang/include/clang/Basic/DiagnosticGroups.td |  1 +
 .../Sema/warn-cast-function-type-strict.c |  2 +-
 clang/test/Sema/warn-cast-function-type.c |  1 +
 .../warn-extra-cast-function-type-strict.c| 42 +++
 .../warn-cast-function-type-strict.cpp|  1 +
 .../test/SemaCXX/warn-cast-function-type.cpp  |  1 +
 6 files changed, 47 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Sema/warn-extra-cast-function-type-strict.c

diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 6765721ae7002c..d3e57de8ac7a58 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1026,6 +1026,7 @@ def Extra : DiagGroup<"extra", [
 EmptyInitStatement,
 StringConcatation,
 FUseLdPath,
+CastFunctionType,
   ]>;
 
 def Most : DiagGroup<"most", [
diff --git a/clang/test/Sema/warn-cast-function-type-strict.c 
b/clang/test/Sema/warn-cast-function-type-strict.c
index 5233680796e972..68b49bb0d05d06 100644
--- a/clang/test/Sema/warn-cast-function-type-strict.c
+++ b/clang/test/Sema/warn-cast-function-type-strict.c
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 %s -fsyntax-only -Wcast-function-type -verify
 // RUN: %clang_cc1 %s -fsyntax-only -Wcast-function-type-strict -verify
-
+// RUN: %clang_cc1 %s -fsyntax-only -Wextra -Wno-ignored-qualifiers -verify
 
 int t(int array[static 12]);
 int u(int i);
diff --git a/clang/test/Sema/warn-cast-function-type.c 
b/clang/test/Sema/warn-cast-function-type.c
index d7ddcdb73725c0..09d169026b1c86 100644
--- a/clang/test/Sema/warn-cast-function-type.c
+++ b/clang/test/Sema/warn-cast-function-type.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -fsyntax-only -Wcast-function-type 
-Wno-cast-function-type-strict -verify
+// RUN: %clang_cc1 %s -fsyntax-only -Wextra -Wno-cast-function-type-strict 
-verify
 
 int x(long);
 
diff --git a/clang/test/Sema/warn-extra-cast-function-type-strict.c 
b/clang/test/Sema/warn-extra-cast-function-type-strict.c
new file mode 100644
index 00..ef8853616ba832
--- /dev/null
+++ b/clang/test/Sema/warn-extra-cast-function-type-strict.c
@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 %s -fsyntax-only -Wextra -verify
+
+
+int t(int array[static 12]);
+int u(int i);
+const int v(int i); /* expected-warning {{'const' type qualifier on return 
type has no effec}} */
+int x(long);
+
+typedef int (f1)(long);
+typedef int (f2)(void*);
+typedef int (f3)();
+typedef void (f4)();
+typedef void (f5)(void);
+typedef int (f6)(long, int);
+typedef int (f7)(long,...);
+typedef int (f8)(int *);
+typedef int (f9)(const int);
+typedef int (f10)(int);
+
+f1 *a;
+f2 *b;
+f3 *c;
+f4 *d;
+f5 *e;
+f6 *f;
+f7 *g;
+f8 *h;
+f9 *i;
+f10 *j;
+
+void foo(void) {
+  a = (f1 *)x;
+  b = (f2 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f2 *' (aka 
'int (*)(void *)') converts to incompatible function type}} */
+  c = (f3 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f3 *' (aka 
'int (*)()') converts to incompatible function type}} */
+  d = (f4 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f4 *' (aka 
'void (*)()') converts to incompatible function type}} */
+  e = (f5 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f5 *' (aka 
'void (*)(void)') converts to incompatible function type}} */
+  f = (f6 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f6 *' (aka 
'int (*)(long, int)') converts to incompatible function type}} */
+  g = (f7 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f7 *' (aka 
'int (*)(long, ...)') converts to incompatible function type}} */
+  h = (f8 *)t;
+  i = (f9 *)u;
+  j = (f10 *)v; /* expected-warning {{cast from 'const int (*)(int)' to 'f10 
*' (aka 'int (*)(int)') converts to incompatible function type}} */
+}
diff --git a/clang/test/SemaCXX/warn-cast-function-type-strict.cpp 
b/clang/test/SemaCXX/warn-cast-function-type-strict.cpp
index f7ee55f84ac280..b3164afde5a0ca 100644
--- a/clang/test/SemaCXX/warn-cast-function-type-strict.cpp
+++ b/clang/test/SemaCXX/warn-cast-function-type-strict.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 %s -fblocks -fsyntax-only -Wcast-function-type -verify
 // RUN: %clang_cc1 %s -fblocks -fsyntax-only -Wcast-function-type-strict 
-verify
+// RUN: %clang_cc1 %s -fblocks -fsyntax-only -Wextra -verify
 
 int x(long);
 
diff --git a/clang/test/SemaCXX/warn-cast-function-type.cpp 
b/clang/test/SemaCXX/warn-cast-function-type.cpp
index c613aaea1e33f2..db2ee030fcbfc9 100644
--- a/clang/test/SemaCXX/warn-cast-function-type.cpp
+++ b/clang/test/SemaCXX/warn-cast-function-type.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -fblocks -fsyntax-only 

[clang] [Clang][Sema]: Allow copy constructor side effects (PR #81127)

2024-02-18 Thread Vinayak Dev via cfe-commits

vinayakdsci wrote:

OK, it looks like there should not be a warning in C++11 and 14 too, as copy 
initialization with side effects appears to be permitted sine C++11.
Could you direct me to the functions that Clang uses internally for implicit 
type conversion?
I am sure that using that I will be able to handle the other cases too.

Thanks!

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


[clang] [Clang][Sema] Remove invalid ctor (NFC) (PR #82161)

2024-02-18 Thread via cfe-commits

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


[clang] [Clang][Sema] Remove invalid ctor (NFC) (PR #82161)

2024-02-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Alexander (Smertig)


Changes

`TemplateArgumentLocInventIterator` default constructor should not exists
https://github.com/llvm/llvm-project/blob/3496927edcd0685807351ba88a7e2cfb006e1c0d/clang/lib/Sema/TreeTransform.h#L4742
 because it doesn't and couldn't initialize `Self` member that is reference:
https://github.com/llvm/llvm-project/blob/3496927edcd0685807351ba88a7e2cfb006e1c0d/clang/lib/Sema/TreeTransform.h#L4721-L4723

Instantiation of this constructor is always a compile-time error. 

Please note, that I didn't run any tests, because cannot imagine situation 
where this constructor can be properly used. There's no new tests for this fix 
for the same reason.

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


1 Files Affected:

- (modified) clang/lib/Sema/TreeTransform.h (-2) 


``diff
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index a32a585531873a..07f11c965cde62 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -4739,8 +4739,6 @@ class TemplateArgumentLocInventIterator {
 const TemplateArgumentLoc *operator->() const { return  }
   };
 
-  TemplateArgumentLocInventIterator() { }
-
   explicit TemplateArgumentLocInventIterator(TreeTransform ,
  InputIterator Iter)
 : Self(Self), Iter(Iter) { }

``




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


[clang] [Clang][Sema] Remove invalid ctor (NFC) (PR #82161)

2024-02-18 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/82161
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Sema] Remove invalid ctor (NFC) (PR #82161)

2024-02-18 Thread via cfe-commits

https://github.com/Smertig created 
https://github.com/llvm/llvm-project/pull/82161

`TemplateArgumentLocInventIterator` default constructor should not exists
https://github.com/llvm/llvm-project/blob/3496927edcd0685807351ba88a7e2cfb006e1c0d/clang/lib/Sema/TreeTransform.h#L4742
 because it doesn't and couldn't initialize `Self` member that is reference:
https://github.com/llvm/llvm-project/blob/3496927edcd0685807351ba88a7e2cfb006e1c0d/clang/lib/Sema/TreeTransform.h#L4721-L4723

Instantiation of this constructor is always a compile-time error. 

Please note, that I didn't run any tests, because cannot imagine situation 
where this constructor can be properly used. There's no new tests for this fix 
for the same reason.

>From fb582783665aa67ec2895d4a847deeb4f7768e90 Mon Sep 17 00:00:00 2001
From: Smertig 
Date: Sun, 18 Feb 2024 13:58:40 +0200
Subject: [PATCH] [Clang][Sema] Remove invalid ctor (NFC)

- TemplateArgumentLocInventIterator default constructor should not exists, 
because it doesn't and couldn't initialize 'Self' member that is reference. 
Instantiation of this ctor is always a compile-time error.
---
 clang/lib/Sema/TreeTransform.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index a32a585531873a..07f11c965cde62 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -4739,8 +4739,6 @@ class TemplateArgumentLocInventIterator {
 const TemplateArgumentLoc *operator->() const { return  }
   };
 
-  TemplateArgumentLocInventIterator() { }
-
   explicit TemplateArgumentLocInventIterator(TreeTransform ,
  InputIterator Iter)
 : Self(Self), Iter(Iter) { }

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


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-02-18 Thread Mark de Wever via cfe-commits

mordante wrote:

> (This is another example that the github review can't work well with the 
> reverted patches...)
> 
> @mordante I think you can add `// REQUIRES: x86-registered-target` to the 
> test if @kaz7 can't respond quickly. It will skip the test on targets other 
> than x86. And it should keep the CI green and enable us to backport this 
> clang18.
> 
> We can still improve this later.

I've created https://github.com/llvm/llvm-project/pull/82160 as you suggested.

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


[clang] Reland "[clang][modules] Print library module manifest path." (PR #82160)

2024-02-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Mark de Wever (mordante)


Changes

This implements a way for the compiler to find the modules.json associated with 
the C++23 Standard library modules.

This is based on a discussion in SG15. At the moment no Standard library 
installs this manifest. #75741 adds this feature in libc++.

This reverts commit 82f424f766be00b037a706a835d0a0663a2680f1.

Disables the tests on non-X86 platforms as suggested.

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


4 Files Affected:

- (modified) clang/include/clang/Driver/Driver.h (+10) 
- (modified) clang/include/clang/Driver/Options.td (+3) 
- (modified) clang/lib/Driver/Driver.cpp (+44) 
- (added) clang/test/Driver/modules-print-library-module-manifest-path.cpp 
(+38) 


``diff
diff --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index 908bc87c14b1ca..ac258dc384e688 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -611,6 +611,16 @@ class Driver {
   // FIXME: This should be in CompilationInfo.
   std::string GetProgramPath(StringRef Name, const ToolChain ) const;
 
+  /// Lookup the path to the Standard library module manifest.
+  ///
+  /// \param C - The compilation.
+  /// \param TC - The tool chain for additional information on
+  /// directories to search.
+  //
+  // FIXME: This should be in CompilationInfo.
+  std::string GetStdModuleManifestPath(const Compilation ,
+   const ToolChain ) const;
+
   /// HandleAutocompletions - Handle --autocomplete by searching and printing
   /// possible flags, descriptions, and its arguments.
   void HandleAutocompletions(StringRef PassedFlags) const;
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 53f23f9abb4c96..2963cbc6af5328 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5371,6 +5371,9 @@ def print_resource_dir : Flag<["-", "--"], 
"print-resource-dir">,
 def print_search_dirs : Flag<["-", "--"], "print-search-dirs">,
   HelpText<"Print the paths used for finding libraries and programs">,
   Visibility<[ClangOption, CLOption]>;
+def print_std_module_manifest_path : Flag<["-", "--"], 
"print-library-module-manifest-path">,
+  HelpText<"Print the path for the C++ Standard library module manifest">,
+  Visibility<[ClangOption, CLOption]>;
 def print_targets : Flag<["-", "--"], "print-targets">,
   HelpText<"Print the registered targets">,
   Visibility<[ClangOption, CLOption]>;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 5a323bf4c0c5f4..82ee18b4588aa5 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -2197,6 +2197,12 @@ bool Driver::HandleImmediateArgs(const Compilation ) {
 return false;
   }
 
+  if (C.getArgs().hasArg(options::OPT_print_std_module_manifest_path)) {
+llvm::outs() << GetStdModuleManifestPath(C, C.getDefaultToolChain())
+ << '\n';
+return false;
+  }
+
   if (C.getArgs().hasArg(options::OPT_print_runtime_dir)) {
 if (std::optional RuntimePath = TC.getRuntimePath())
   llvm::outs() << *RuntimePath << '\n';
@@ -6183,6 +6189,44 @@ std::string Driver::GetProgramPath(StringRef Name, const 
ToolChain ) const {
   return std::string(Name);
 }
 
+std::string Driver::GetStdModuleManifestPath(const Compilation ,
+ const ToolChain ) const {
+  std::string error = "";
+
+  switch (TC.GetCXXStdlibType(C.getArgs())) {
+  case ToolChain::CST_Libcxx: {
+std::string lib = GetFilePath("libc++.so", TC);
+
+// Note when there are multiple flavours of libc++ the module json needs to
+// look at the command-line arguments for the proper json.
+// These flavours do not exist at the moment, but there are plans to
+// provide a variant that is built with sanitizer instrumentation enabled.
+
+// For example
+//  StringRef modules = [&] {
+//const SanitizerArgs  = TC.getSanitizerArgs(C.getArgs());
+//if (Sanitize.needsAsanRt())
+//  return "modules-asan.json";
+//return "modules.json";
+//  }();
+
+SmallString<128> path(lib.begin(), lib.end());
+llvm::sys::path::remove_filename(path);
+llvm::sys::path::append(path, "modules.json");
+if (TC.getVFS().exists(path))
+  return static_cast(path);
+
+return error;
+  }
+
+  case ToolChain::CST_Libstdcxx:
+// libstdc++ does not provide Standard library modules yet.
+return error;
+  }
+
+  return error;
+}
+
 std::string Driver::GetTemporaryPath(StringRef Prefix, StringRef Suffix) const 
{
   SmallString<128> Path;
   std::error_code EC = llvm::sys::fs::createTemporaryFile(Prefix, Suffix, 
Path);
diff --git a/clang/test/Driver/modules-print-library-module-manifest-path.cpp 
b/clang/test/Driver/modules-print-library-module-manifest-path.cpp
new file mode 

[clang] Reland "[clang][modules] Print library module manifest path." (PR #82160)

2024-02-18 Thread Mark de Wever via cfe-commits

https://github.com/mordante created 
https://github.com/llvm/llvm-project/pull/82160

This implements a way for the compiler to find the modules.json associated with 
the C++23 Standard library modules.

This is based on a discussion in SG15. At the moment no Standard library 
installs this manifest. #75741 adds this feature in libc++.

This reverts commit 82f424f766be00b037a706a835d0a0663a2680f1.

Disables the tests on non-X86 platforms as suggested.

>From cb3f20463548110617fd555ac11ee58d5b8b7ad5 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Sun, 18 Feb 2024 12:57:33 +0100
Subject: [PATCH] Reland "[clang][modules] Print library module manifest path."

This implements a way for the compiler to find the modules.json
associated with the C++23 Standard library modules.

This is based on a discussion in SG15. At the moment no Standard library
installs this manifest. #75741 adds this feature in libc++.

This reverts commit 82f424f766be00b037a706a835d0a0663a2680f1.

Disables the tests on non-X86 platforms as suggested.
---
 clang/include/clang/Driver/Driver.h   | 10 +
 clang/include/clang/Driver/Options.td |  3 ++
 clang/lib/Driver/Driver.cpp   | 44 +++
 ...les-print-library-module-manifest-path.cpp | 38 
 4 files changed, 95 insertions(+)
 create mode 100644 
clang/test/Driver/modules-print-library-module-manifest-path.cpp

diff --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index 908bc87c14b1ca..ac258dc384e688 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -611,6 +611,16 @@ class Driver {
   // FIXME: This should be in CompilationInfo.
   std::string GetProgramPath(StringRef Name, const ToolChain ) const;
 
+  /// Lookup the path to the Standard library module manifest.
+  ///
+  /// \param C - The compilation.
+  /// \param TC - The tool chain for additional information on
+  /// directories to search.
+  //
+  // FIXME: This should be in CompilationInfo.
+  std::string GetStdModuleManifestPath(const Compilation ,
+   const ToolChain ) const;
+
   /// HandleAutocompletions - Handle --autocomplete by searching and printing
   /// possible flags, descriptions, and its arguments.
   void HandleAutocompletions(StringRef PassedFlags) const;
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 53f23f9abb4c96..2963cbc6af5328 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5371,6 +5371,9 @@ def print_resource_dir : Flag<["-", "--"], 
"print-resource-dir">,
 def print_search_dirs : Flag<["-", "--"], "print-search-dirs">,
   HelpText<"Print the paths used for finding libraries and programs">,
   Visibility<[ClangOption, CLOption]>;
+def print_std_module_manifest_path : Flag<["-", "--"], 
"print-library-module-manifest-path">,
+  HelpText<"Print the path for the C++ Standard library module manifest">,
+  Visibility<[ClangOption, CLOption]>;
 def print_targets : Flag<["-", "--"], "print-targets">,
   HelpText<"Print the registered targets">,
   Visibility<[ClangOption, CLOption]>;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 5a323bf4c0c5f4..82ee18b4588aa5 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -2197,6 +2197,12 @@ bool Driver::HandleImmediateArgs(const Compilation ) {
 return false;
   }
 
+  if (C.getArgs().hasArg(options::OPT_print_std_module_manifest_path)) {
+llvm::outs() << GetStdModuleManifestPath(C, C.getDefaultToolChain())
+ << '\n';
+return false;
+  }
+
   if (C.getArgs().hasArg(options::OPT_print_runtime_dir)) {
 if (std::optional RuntimePath = TC.getRuntimePath())
   llvm::outs() << *RuntimePath << '\n';
@@ -6183,6 +6189,44 @@ std::string Driver::GetProgramPath(StringRef Name, const 
ToolChain ) const {
   return std::string(Name);
 }
 
+std::string Driver::GetStdModuleManifestPath(const Compilation ,
+ const ToolChain ) const {
+  std::string error = "";
+
+  switch (TC.GetCXXStdlibType(C.getArgs())) {
+  case ToolChain::CST_Libcxx: {
+std::string lib = GetFilePath("libc++.so", TC);
+
+// Note when there are multiple flavours of libc++ the module json needs to
+// look at the command-line arguments for the proper json.
+// These flavours do not exist at the moment, but there are plans to
+// provide a variant that is built with sanitizer instrumentation enabled.
+
+// For example
+//  StringRef modules = [&] {
+//const SanitizerArgs  = TC.getSanitizerArgs(C.getArgs());
+//if (Sanitize.needsAsanRt())
+//  return "modules-asan.json";
+//return "modules.json";
+//  }();
+
+SmallString<128> path(lib.begin(), lib.end());
+llvm::sys::path::remove_filename(path);
+llvm::sys::path::append(path, 

[clang] [Clang][Sema]: Allow copy constructor side effects (PR #81127)

2024-02-18 Thread via cfe-commits

cor3ntin wrote:

@AaronBallman does not handling c++11 make sense to you? Thanks!

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


[clang] [clang] Implement `__is_layout_compatible` (PR #81506)

2024-02-18 Thread via cfe-commits

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

LGTM!

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


[clang] [clang] Implement `__is_layout_compatible` (PR #81506)

2024-02-18 Thread via cfe-commits


@@ -90,6 +90,12 @@ C++20 Feature Support
   behavior can use the flag '-Xclang -fno-skip-odr-check-in-gmf'.
   (`#79240 `_).
 
+- Implemented `__is_layout_compatible` intrinsic, which backs up
+  `P0466R5: Layout-compatibility and Pointer-interconvertibility Traits 
`_.
+  `CWG1719: Layout compatibility and cv-qualification revisited  
`_
+  and `CWG2759: [[no_unique_address] and common initial sequence 
`_
+  are not yet implemented.
+

cor3ntin wrote:

```suggestion
- Implemented the `__is_layout_compatible` intrinsic to support
  `P0466R5: Layout-compatibility and Pointer-interconvertibility Traits 
`_.
  Note: `CWG1719: Layout compatibility and cv-qualification revisited  
`_
  and `CWG2759: [[no_unique_address] and common initial sequence 
`_
  are not yet implemented.

```

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


[clang] [clang] Implement `__is_layout_compatible` (PR #81506)

2024-02-18 Thread via cfe-commits

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


[clang] [Clang][Sema]: Allow copy constructor side effects (PR #81127)

2024-02-18 Thread Vinayak Dev via cfe-commits

vinayakdsci wrote:

@cor3ntin gentle ping. Could you direct on what other changes are required?

Thanks!

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


[clang-tools-extra] [clang-tidy] Fixes to readability-implicit-bool-conversion (PR #72050)

2024-02-18 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] 3496927 - [clang-tidy] Fixes to readability-implicit-bool-conversion (#72050)

2024-02-18 Thread via cfe-commits

Author: Piotr Zegar
Date: 2024-02-18T12:30:43+01:00
New Revision: 3496927edcd0685807351ba88a7e2cfb006e1c0d

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

LOG: [clang-tidy] Fixes to readability-implicit-bool-conversion (#72050)

- Fixed issue with invalid code being generated when static_cast is put
into fix, and no space were added before it.
- Fixed issue with duplicate parentheses being added when double
implicit cast is used.

Closes #71848

Added: 


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

clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
index 11706ffb5b7d4f..4f02950e7794cb 100644
--- a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
@@ -151,16 +151,29 @@ StringRef getEquivalentBoolLiteralForExpr(const Expr 
*Expression,
   return {};
 }
 
+bool needsSpacePrefix(SourceLocation Loc, ASTContext ) {
+  SourceRange PrefixRange(Loc.getLocWithOffset(-1), Loc);
+  StringRef SpaceBeforeStmtStr = Lexer::getSourceText(
+  CharSourceRange::getCharRange(PrefixRange), Context.getSourceManager(),
+  Context.getLangOpts(), nullptr);
+  if (SpaceBeforeStmtStr.empty())
+return true;
+
+  const StringRef AllowedCharacters(" \t\n\v\f\r(){}[]<>;,+=-|&~!^*/");
+  return !AllowedCharacters.contains(SpaceBeforeStmtStr.back());
+}
+
 void fixGenericExprCastFromBool(DiagnosticBuilder ,
 const ImplicitCastExpr *Cast,
 ASTContext , StringRef OtherType) {
   const Expr *SubExpr = Cast->getSubExpr();
-  bool NeedParens = !isa(SubExpr);
+  const bool NeedParens = !isa(SubExpr->IgnoreImplicit());
+  const bool NeedSpace = needsSpacePrefix(Cast->getBeginLoc(), Context);
 
   Diag << FixItHint::CreateInsertion(
-  Cast->getBeginLoc(),
-  (Twine("static_cast<") + OtherType + ">" + (NeedParens ? "(" : ""))
-  .str());
+  Cast->getBeginLoc(), (Twine() + (NeedSpace ? " " : "") + "static_cast<" +
+OtherType + ">" + (NeedParens ? "(" : ""))
+   .str());
 
   if (NeedParens) {
 SourceLocation EndLoc = Lexer::getLocForEndOfToken(

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 737ea9ba6d44f7..7ca7037e2a6a4f 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -174,6 +174,11 @@ Changes in existing checks
   ` check to also remove any trailing
   whitespace when deleting the ``virtual`` keyword.
 
+- Improved :doc:`readability-implicit-bool-conversion
+  ` check to provide
+  valid fix suggestions for ``static_cast`` without a preceding space and
+  fixed problem with duplicate parentheses in double implicit casts.
+
 - Improved :doc:`readability-redundant-inline-specifier
   ` check to properly
   emit warnings for static data member with an in-class initializer.

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.cpp
index 6f1f2972971887..d6e7dcc4d8867b 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.cpp
@@ -524,3 +524,12 @@ namespace PR71867 {
 // CHECK-FIXES: return (x ? 1 : 0) != 0;
   }
 }
+
+namespace PR71848 {
+  int fun() {
+bool foo = false;
+return( foo );
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: implicit conversion 'bool' -> 
'int' [readability-implicit-bool-conversion]
+// CHECK-FIXES: return static_cast( foo );
+  }
+}



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


[clang] [NVPTX][AMDGPU][CodeGen] Fix `local_space nullptr` handling for NVPTX and local/private `nullptr` value for AMDGPU. (PR #78759)

2024-02-18 Thread via cfe-commits

https://github.com/mmoadeli updated 
https://github.com/llvm/llvm-project/pull/78759

>From 9d743cbf91dd727dc32e994e82205f8114a44d7b Mon Sep 17 00:00:00 2001
From: m moadeli 
Date: Fri, 19 Jan 2024 18:42:24 +
Subject: [PATCH 1/2] - Address space cast of a `local_space` specialized
 `nullptr` into a generic space for the CUDA backend. - In the context of AMD
 GPU, assigns a NULL value of `~0` for the address spaces of `sycl_local` and
 `sycl_private`

---
 clang/lib/Basic/Targets/AMDGPU.h  |   6 +-
 clang/lib/CodeGen/Targets/NVPTX.cpp   |  18 +++
 .../CodeGenSYCL/address-space-conversions.cpp |   4 +
 .../amd-address-space-conversions.cpp | 128 ++
 .../cuda-address-space-conversions.cpp| 122 +
 5 files changed, 276 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/CodeGenSYCL/amd-address-space-conversions.cpp
 create mode 100644 clang/test/CodeGenSYCL/cuda-address-space-conversions.cpp

diff --git a/clang/lib/Basic/Targets/AMDGPU.h b/clang/lib/Basic/Targets/AMDGPU.h
index e80589dde0ecb5..94d9ba93ed226f 100644
--- a/clang/lib/Basic/Targets/AMDGPU.h
+++ b/clang/lib/Basic/Targets/AMDGPU.h
@@ -414,8 +414,10 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : 
public TargetInfo {
   // value ~0.
   uint64_t getNullPointerValue(LangAS AS) const override {
 // FIXME: Also should handle region.
-return (AS == LangAS::opencl_local || AS == LangAS::opencl_private)
-  ? ~0 : 0;
+return (AS == LangAS::opencl_local || AS == LangAS::opencl_private ||
+AS == LangAS::sycl_local || AS == LangAS::sycl_private)
+   ? ~0
+   : 0;
   }
 
   void setAuxTarget(const TargetInfo *Aux) override;
diff --git a/clang/lib/CodeGen/Targets/NVPTX.cpp 
b/clang/lib/CodeGen/Targets/NVPTX.cpp
index d0dc7c258a03a6..8718f1ecf3a7e0 100644
--- a/clang/lib/CodeGen/Targets/NVPTX.cpp
+++ b/clang/lib/CodeGen/Targets/NVPTX.cpp
@@ -47,6 +47,10 @@ class NVPTXTargetCodeGenInfo : public TargetCodeGenInfo {
CodeGen::CodeGenModule ) const override;
   bool shouldEmitStaticExternCAliases() const override;
 
+  llvm::Constant *getNullPointer(const CodeGen::CodeGenModule ,
+ llvm::PointerType *T,
+ QualType QT) const override;
+
   llvm::Type *getCUDADeviceBuiltinSurfaceDeviceType() const override {
 // On the device side, surface reference is represented as an object handle
 // in 64-bit integer.
@@ -285,6 +289,20 @@ void 
NVPTXTargetCodeGenInfo::addNVVMMetadata(llvm::GlobalValue *GV,
 bool NVPTXTargetCodeGenInfo::shouldEmitStaticExternCAliases() const {
   return false;
 }
+
+llvm::Constant *
+NVPTXTargetCodeGenInfo::getNullPointer(const CodeGen::CodeGenModule ,
+   llvm::PointerType *PT,
+   QualType QT) const {
+  auto  = CGM.getContext();
+  if (PT->getAddressSpace() != Ctx.getTargetAddressSpace(LangAS::opencl_local))
+return llvm::ConstantPointerNull::get(PT);
+
+  auto NPT = llvm::PointerType::get(
+  PT->getContext(), Ctx.getTargetAddressSpace(LangAS::opencl_generic));
+  return llvm::ConstantExpr::getAddrSpaceCast(
+  llvm::ConstantPointerNull::get(NPT), PT);
+}
 }
 
 void CodeGenModule::handleCUDALaunchBoundsAttr(llvm::Function *F,
diff --git a/clang/test/CodeGenSYCL/address-space-conversions.cpp 
b/clang/test/CodeGenSYCL/address-space-conversions.cpp
index 3933ad375412da..10a181318a174b 100644
--- a/clang/test/CodeGenSYCL/address-space-conversions.cpp
+++ b/clang/test/CodeGenSYCL/address-space-conversions.cpp
@@ -25,6 +25,10 @@ void usages() {
   __attribute__((opencl_local)) int *LOC;
   // CHECK-DAG: [[NoAS:%[a-zA-Z0-9]+]] = alloca ptr addrspace(4)
   // CHECK-DAG: [[NoAS]].ascast = addrspacecast ptr [[NoAS]] to ptr 
addrspace(4)
+  LOC = nullptr;
+  // CHECK-DAG: store ptr addrspace(3) null, ptr addrspace(4) [[LOC]].ascast, 
align 8
+  GLOB = nullptr;
+  // CHECK-DAG: store ptr addrspace(1) null, ptr addrspace(4) [[GLOB]].ascast, 
align 8
   int *NoAS;
   // CHECK-DAG: [[PRIV:%[a-zA-Z0-9]+]] = alloca ptr
   // CHECK-DAG: [[PRIV]].ascast = addrspacecast ptr [[PRIV]] to ptr 
addrspace(4)
diff --git a/clang/test/CodeGenSYCL/amd-address-space-conversions.cpp 
b/clang/test/CodeGenSYCL/amd-address-space-conversions.cpp
new file mode 100644
index 00..35da61cd8cbbe3
--- /dev/null
+++ b/clang/test/CodeGenSYCL/amd-address-space-conversions.cpp
@@ -0,0 +1,128 @@
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -fsycl-is-device 
-disable-llvm-passes -emit-llvm %s -o - | FileCheck %s
+void bar(int ) {}
+// CHECK-DAG: define dso_local void @[[RAW_REF:[a-zA-Z0-9_]+]](ptr noundef 
nonnull align 4 dereferenceable(4) %
+void bar2(int ) {}
+// CHECK-DAG: define dso_local void @[[RAW_REF2:[a-zA-Z0-9_]+]](ptr noundef 
nonnull align 4 dereferenceable(4) %
+void bar(__attribute__((opencl_local)) int ) {}
+// CHECK-DAG: define dso_local void 

[clang-tools-extra] [clangd] forward clang-tidy's readability-identifier-naming fix to textDocument/rename (PR #78454)

2024-02-18 Thread Tom Praschan via cfe-commits

https://github.com/tom-anders updated 
https://github.com/llvm/llvm-project/pull/78454

>From 3a1ef6006764bd4d307ceec74199ed81a18aba2d Mon Sep 17 00:00:00 2001
From: tom-anders <13141438+tom-and...@users.noreply.github.com>
Date: Wed, 17 Jan 2024 15:36:02 +0100
Subject: [PATCH] [clangd] forward clang-tidy's readability-identifier-naming
 fix to textDocument/rename

---
 clang-tools-extra/clangd/ClangdLSPServer.cpp  | 32 ++
 clang-tools-extra/clangd/ClangdLSPServer.h|  1 +
 clang-tools-extra/clangd/ClangdServer.cpp | 44 ++---
 clang-tools-extra/clangd/ClangdServer.h   |  6 ++
 clang-tools-extra/clangd/Protocol.cpp |  8 +++
 clang-tools-extra/clangd/Protocol.h   |  1 +
 .../clangd/test/initialize-params.test|  1 +
 .../clangd/unittests/ClangdLSPServerTests.cpp | 61 +++
 .../clangd/unittests/LSPClient.cpp| 31 +-
 .../clangd/unittests/LSPClient.h  |  6 ++
 10 files changed, 182 insertions(+), 9 deletions(-)

diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp 
b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index a87da252b7a7e9..81c434bc4d987d 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -73,6 +73,23 @@ std::optional decodeVersion(llvm::StringRef 
Encoded) {
 
 const llvm::StringLiteral ApplyFixCommand = "clangd.applyFix";
 const llvm::StringLiteral ApplyTweakCommand = "clangd.applyTweak";
+const llvm::StringLiteral ApplyRenameCommand = "clangd.applyRename";
+
+CodeAction toCodeAction(const ClangdServer::CodeActionResult::Rename ,
+const URIForFile ) {
+  CodeAction CA;
+  CA.title = R.FixMessage;
+  CA.kind = std::string(CodeAction::REFACTOR_KIND);
+  CA.command.emplace();
+  CA.command->title = R.FixMessage;
+  CA.command->command = std::string(ApplyRenameCommand);
+  RenameParams Params;
+  Params.textDocument = TextDocumentIdentifier{File};
+  Params.position = R.Diag.Range.start;
+  Params.newName = R.NewName;
+  CA.command->argument = Params;
+  return CA;
+}
 
 /// Transforms a tweak into a code action that would apply it if executed.
 /// EXPECTS: T.prepare() was called and returned true.
@@ -808,6 +825,16 @@ void ClangdLSPServer::onCommandApplyTweak(const TweakArgs 
,
  std::move(Action));
 }
 
+void ClangdLSPServer::onCommandApplyRename(const RenameParams ,
+   Callback Reply) {
+  onRename(R, [this, Reply = std::move(Reply)](
+  llvm::Expected Edit) mutable {
+if (!Edit)
+  Reply(Edit.takeError());
+applyEdit(std::move(*Edit), "Rename applied.", std::move(Reply));
+  });
+}
+
 void ClangdLSPServer::applyEdit(WorkspaceEdit WE, llvm::json::Value Success,
 Callback Reply) {
   ApplyWorkspaceEditParams Edit;
@@ -1043,6 +1070,10 @@ void ClangdLSPServer::onCodeAction(const 
CodeActionParams ,
 CAs.back().diagnostics = {It->second};
   }
 }
+
+for (const auto  : Fixits->Renames)
+  CAs.push_back(toCodeAction(R, File));
+
 for (const auto  : Fixits->TweakRefs)
   CAs.push_back(toCodeAction(TR, File, Selection));
 
@@ -1664,6 +1695,7 @@ void ClangdLSPServer::bindMethods(LSPBinder ,
   Bind.method("textDocument/foldingRange", this, 
::onFoldingRange);
   Bind.command(ApplyFixCommand, this, ::onCommandApplyEdit);
   Bind.command(ApplyTweakCommand, this, ::onCommandApplyTweak);
+  Bind.command(ApplyRenameCommand, this, 
::onCommandApplyRename);
 
   ApplyWorkspaceEdit = Bind.outgoingMethod("workspace/applyEdit");
   PublishDiagnostics = 
Bind.outgoingNotification("textDocument/publishDiagnostics");
diff --git a/clang-tools-extra/clangd/ClangdLSPServer.h 
b/clang-tools-extra/clangd/ClangdLSPServer.h
index 79579c22b788a9..69a349c6a5e087 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.h
+++ b/clang-tools-extra/clangd/ClangdLSPServer.h
@@ -174,6 +174,7 @@ class ClangdLSPServer : private ClangdServer::Callbacks,
   /// Implement commands.
   void onCommandApplyEdit(const WorkspaceEdit &, Callback);
   void onCommandApplyTweak(const TweakArgs &, Callback);
+  void onCommandApplyRename(const RenameParams &, Callback);
 
   /// Outgoing LSP calls.
   LSPBinder::OutgoingMethodrunWithAST("Rename", File, std::move(Action));
 }
 
+namespace {
 // May generate several candidate selections, due to SelectionTree ambiguity.
 // vector of pointers because GCC doesn't like non-copyable Selection.
-static llvm::Expected>>
+llvm::Expected>>
 tweakSelection(const Range , const InputsAndAST ,
llvm::vfs::FileSystem *FS) {
   auto Begin = positionToOffset(AST.Inputs.Contents, Sel.start);
@@ -648,6 +649,27 @@ tweakSelection(const Range , const InputsAndAST ,
   return std::move(Result);
 }
 
+// Some fixes may perform local renaming, we want to convert those to clangd
+// rename commands, such that we can leverage the index for more accurate
+// results.
+std::optional

[clang-tools-extra] [clangd] forward clang-tidy's readability-identifier-naming fix to textDocument/rename (PR #78454)

2024-02-18 Thread Tom Praschan via cfe-commits

tom-anders wrote:

> Something else I noticed while trying out the patch locally: before the 
> patch, the description of the code action in the editor is "change 'foo' to 
> 'Foo'", i.e. a description of what the code action will do.
> 
> After the patch, the description of the code action is now "invalid case 
> style for function 'foo'", i.e. it describes the problem, not the fix.
> 
> We should keep the description of the code action the same, i.e. describing 
> the fix.

Ah good find, I added a new `FixMessage` field for this (and also added this to 
the test)

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


[clang] [Serialization] Load Specializations Lazily (PR #76774)

2024-02-18 Thread Vassil Vassilev via cfe-commits

vgvassilev wrote:

Let's zoom out a little. The approach in D41416 shows that it is feasible to 
store *a* hash of the template arguments to delay eager deserializations. The 
ODR hash approach is a second order problem because we can swap it with 
something better once we need to. In order to make progress we have introduced 
[D153003](https://reviews.llvm.org/D153003) which allows our infrastructure to 
work. The way I see moving forward here is:

  * Base this PR on D41416 in the approach how we model the lazy 
deserialization of templates. That'd mean that we "just" need to replace 
`LazySpecializationInfo *LazySpecializations = nullptr;` with the on-disk hash 
table approach. That would probably require centralizing that logic somewhere 
in the ASTReader (the way this PR does) but with minimal changes wrt D41416.
  * Test the implementation on our infrastructure for correctness
  * Test the implementation on the Google infrastructure for scalability
  * Think on a better approach to replace odr hashing if we see more 
pathological problems.
 

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


[clang-tools-extra] [clangd] forward clang-tidy's readability-identifier-naming fix to textDocument/rename (PR #78454)

2024-02-18 Thread Tom Praschan via cfe-commits


@@ -648,6 +649,27 @@ tweakSelection(const Range , const InputsAndAST ,
   return std::move(Result);
 }
 
+// Some fixes may perform local renaming, we want to convert those to clangd
+// rename commands, such that we can leverage the index for more accurate
+// results.
+std::optional
+TryConvertToRename(const Diag *Diag, const ClangdServer::DiagRef ,

tom-anders wrote:

hah :D 

At work we're using Google style, so functions are CamelCase and variables 
snake_case. Switching back and forth between Google and LLVM style is so 
confusing

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


[clang-tools-extra] [clang-tidy] Fixes to readability-implicit-bool-conversion (PR #72050)

2024-02-18 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL updated 
https://github.com/llvm/llvm-project/pull/72050

>From f77e3fce830166cdc9ffce42db6599c407147ba3 Mon Sep 17 00:00:00 2001
From: Piotr Zegar 
Date: Sun, 12 Nov 2023 11:31:21 +
Subject: [PATCH] [clang-tidy] Fixes to readability-implicit-bool-conversion

- Fixed issue with invalid code being generated when static_cast
  is put into fix, and no space were added before it.
- Fixed issue with duplicate parentheses being added when double
  implicit cast is used.
---
 .../ImplicitBoolConversionCheck.cpp   | 21 +++
 clang-tools-extra/docs/ReleaseNotes.rst   |  5 +
 .../readability/implicit-bool-conversion.cpp  |  9 
 3 files changed, 31 insertions(+), 4 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
index 11706ffb5b7d4f..4f02950e7794cb 100644
--- a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
@@ -151,16 +151,29 @@ StringRef getEquivalentBoolLiteralForExpr(const Expr 
*Expression,
   return {};
 }
 
+bool needsSpacePrefix(SourceLocation Loc, ASTContext ) {
+  SourceRange PrefixRange(Loc.getLocWithOffset(-1), Loc);
+  StringRef SpaceBeforeStmtStr = Lexer::getSourceText(
+  CharSourceRange::getCharRange(PrefixRange), Context.getSourceManager(),
+  Context.getLangOpts(), nullptr);
+  if (SpaceBeforeStmtStr.empty())
+return true;
+
+  const StringRef AllowedCharacters(" \t\n\v\f\r(){}[]<>;,+=-|&~!^*/");
+  return !AllowedCharacters.contains(SpaceBeforeStmtStr.back());
+}
+
 void fixGenericExprCastFromBool(DiagnosticBuilder ,
 const ImplicitCastExpr *Cast,
 ASTContext , StringRef OtherType) {
   const Expr *SubExpr = Cast->getSubExpr();
-  bool NeedParens = !isa(SubExpr);
+  const bool NeedParens = !isa(SubExpr->IgnoreImplicit());
+  const bool NeedSpace = needsSpacePrefix(Cast->getBeginLoc(), Context);
 
   Diag << FixItHint::CreateInsertion(
-  Cast->getBeginLoc(),
-  (Twine("static_cast<") + OtherType + ">" + (NeedParens ? "(" : ""))
-  .str());
+  Cast->getBeginLoc(), (Twine() + (NeedSpace ? " " : "") + "static_cast<" +
+OtherType + ">" + (NeedParens ? "(" : ""))
+   .str());
 
   if (NeedParens) {
 SourceLocation EndLoc = Lexer::getLocForEndOfToken(
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 737ea9ba6d44f7..7ca7037e2a6a4f 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -174,6 +174,11 @@ Changes in existing checks
   ` check to also remove any trailing
   whitespace when deleting the ``virtual`` keyword.
 
+- Improved :doc:`readability-implicit-bool-conversion
+  ` check to provide
+  valid fix suggestions for ``static_cast`` without a preceding space and
+  fixed problem with duplicate parentheses in double implicit casts.
+
 - Improved :doc:`readability-redundant-inline-specifier
   ` check to properly
   emit warnings for static data member with an in-class initializer.
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.cpp
index 6f1f2972971887..d6e7dcc4d8867b 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.cpp
@@ -524,3 +524,12 @@ namespace PR71867 {
 // CHECK-FIXES: return (x ? 1 : 0) != 0;
   }
 }
+
+namespace PR71848 {
+  int fun() {
+bool foo = false;
+return( foo );
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: implicit conversion 'bool' -> 
'int' [readability-implicit-bool-conversion]
+// CHECK-FIXES: return static_cast( foo );
+  }
+}

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


[clang] [Serialization] Load Specializations Lazily (PR #76774)

2024-02-18 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

> > But my point is that we can't land that if we don't understand what's going 
> > wrong without that patch.
> 
> We understand that very well and it's described in 
> https://reviews.llvm.org/D153003 as well as the surrounding discussions: 
> because of the way that `ODRHash` works, template template arguments `A` and 
> `B` will hash to different values, even if `using A = B`. 

Yeah, so I tried to fix that in the following patches. And if that works, I 
expect that can fix internal errors in your workloads.

> However, for template specializations, we require them to hash to the same 
> value (with some form of normalization) or we won't find nor load the right 
> specializations. That's why I said that IMHO `ODRHash` is not the right tool 
> for the job here, which follows directly from an old comment of yours: 
> https://reviews.llvm.org/D153003#4427412
> 
> > An important node here is that ODRHash is used to check the AST Nodes are 
> > keeping the same across compilations. There is gap to use ODRHash to check 
> > the semantical equality.
> 
> (and IIRC that's the same direction that Richard was going)



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


[clang] [Serialization] Load Specializations Lazily (PR #76774)

2024-02-18 Thread Jonas Hahnfeld via cfe-commits

hahnjo wrote:

> But my point is that we can't land that if we don't understand what's going 
> wrong without that patch.

We understand that very well and it's described in 
https://reviews.llvm.org/D153003 as well as the surrounding discussions: 
because of the way that `ODRHash` works, template template arguments `A` and 
`B` will hash to different values, even if `using A = B`. However, for template 
specializations, we require them to hash to the same value (with some form of 
normalization) or we won't find nor load the right specializations. That's why 
I said that IMHO `ODRHash` is not the right tool for the job here, which 
follows directly from an old comment of yours: 
https://reviews.llvm.org/D153003#4427412

> An important node here is that ODRHash is used to check the AST Nodes are 
> keeping the same across compilations. There is gap to use ODRHash to check 
> the semantical equality.

(and IIRC that's the same direction that Richard was going)

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


  1   2   >