[clang] [clang] Add support for passing FileSystem to buildASTFromCodeWithArgs() (PR #123042)

2025-01-15 Thread Boaz Brickner via cfe-commits
https://github.com/bricknerb closed https://github.com/llvm/llvm-project/pull/123042 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang] Add support for passing FileSystem to buildASTFromCodeWithArgs() (PR #123042)

2025-01-15 Thread Boaz Brickner via cfe-commits
@@ -223,7 +223,11 @@ buildASTFromCode(StringRef Code, StringRef FileName = "input.cc", /// \param PCHContainerOps The PCHContainerOperations for loading and creating /// clang modules. /// -/// \param Adjuster A function to filter the command line arguments as specified. +///

[clang] [clang] Add support for passing FileSystem to buildASTFromCodeWithArgs() (PR #123042)

2025-01-15 Thread Boaz Brickner via cfe-commits
@@ -692,11 +692,12 @@ std::unique_ptr buildASTFromCodeWithArgs( StringRef Code, const std::vector &Args, StringRef FileName, StringRef ToolName, std::shared_ptr PCHContainerOps, ArgumentsAdjuster Adjuster, const FileContentMappings &VirtualMappedFiles, -Diagnos

[clang] [clang] Add support for passing FileSystem to buildASTFromCodeWithArgs() (PR #123042)

2025-01-15 Thread Boaz Brickner via cfe-commits
https://github.com/bricknerb unassigned https://github.com/llvm/llvm-project/pull/123042 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang] Add support for passing FileSystem to buildASTFromCodeWithArgs() (PR #123042)

2025-01-15 Thread Boaz Brickner via cfe-commits
https://github.com/bricknerb updated https://github.com/llvm/llvm-project/pull/123042 >From 197fa433e56c875b4098806576f14b33a37a4300 Mon Sep 17 00:00:00 2001 From: Boaz Brickner Date: Wed, 15 Jan 2025 11:48:20 +0100 Subject: [PATCH 1/2] [clang] Add support for passing FileSystem to buildASTFro

[clang] [clang] Add support for passing FileSystem to buildASTFromCodeWithArgs() (PR #123042)

2025-01-15 Thread Boaz Brickner via cfe-commits
https://github.com/bricknerb created https://github.com/llvm/llvm-project/pull/123042 This would allow tools that don't use the real file system to use this function. >From 197fa433e56c875b4098806576f14b33a37a4300 Mon Sep 17 00:00:00 2001 From: Boaz Brickner Date: Wed, 15 Jan 2025 11:48:20 +01

[clang] Use range-based for to iterate over fields in record layout, NFC (PR #122029)

2025-01-08 Thread Boaz Brickner via cfe-commits
https://github.com/bricknerb edited https://github.com/llvm/llvm-project/pull/122029 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] Use range-based for to iterate over fields in record layout, NFC (PR #122029)

2025-01-08 Thread Boaz Brickner via cfe-commits
@@ -3115,7 +3115,19 @@ class FieldDecl : public DeclaratorDecl, public Mergeable { /// Returns the index of this field within its record, /// as appropriate for passing to ASTRecordLayout::getFieldOffset. - unsigned getFieldIndex() const; + unsigned getFieldIndex() cons

[clang] Use range-based for to iterate over fields in record layout, NFC (PR #122029)

2025-01-08 Thread Boaz Brickner via cfe-commits
@@ -3115,7 +3115,19 @@ class FieldDecl : public DeclaratorDecl, public Mergeable { /// Returns the index of this field within its record, /// as appropriate for passing to ASTRecordLayout::getFieldOffset. - unsigned getFieldIndex() const; + unsigned getFieldIndex() cons

[clang] Use range-based for to iterate over fields in record layout, NFC (PR #122029)

2025-01-08 Thread Boaz Brickner via cfe-commits
@@ -3115,7 +3115,19 @@ class FieldDecl : public DeclaratorDecl, public Mergeable { /// Returns the index of this field within its record, /// as appropriate for passing to ASTRecordLayout::getFieldOffset. - unsigned getFieldIndex() const; + unsigned getFieldIndex() cons

[clang] Use range-based for to iterate over fields in record layout, NFC (PR #122029)

2025-01-08 Thread Boaz Brickner via cfe-commits
https://github.com/bricknerb approved this pull request. https://github.com/llvm/llvm-project/pull/122029 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] Use range-based for to iterate over fields in record layout, NFC (PR #122029)

2025-01-08 Thread Boaz Brickner via cfe-commits
@@ -3115,7 +3115,19 @@ class FieldDecl : public DeclaratorDecl, public Mergeable { /// Returns the index of this field within its record, /// as appropriate for passing to ASTRecordLayout::getFieldOffset. - unsigned getFieldIndex() const; + unsigned getFieldIndex() cons

[clang] Use range-based for to iterate over fields in record layout, NFC (PR #122029)

2025-01-08 Thread Boaz Brickner via cfe-commits
bricknerb wrote: Thanks for doing this! FWIW, I think splitting this to smaller PRs would be easier. For example: 1. `getFieldIndex()` inlining. 2. Passing fields instead of their indexes and iterate over fields. 3. Use `std::next()` instead of defining a `Next` variable. 4. Rename `isNoUniqueAdd

[clang] [clang] [NFC] Remove SourceLocation() parameter from Diag.Report() calls in SourceManager, and use the equivalent Report() overload instead (PR #116937)

2024-11-21 Thread Boaz Brickner via cfe-commits
https://github.com/bricknerb closed https://github.com/llvm/llvm-project/pull/116937 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [ASTWriter] Do not allocate source location space for module maps used only for textual headers (PR #116374)

2024-11-20 Thread Boaz Brickner via cfe-commits
@@ -184,14 +184,30 @@ GetAffectingModuleMaps(const Preprocessor &PP, Module *RootModule) { const SourceManager &SM = PP.getSourceManager(); const ModuleMap &MM = HS.getModuleMap(); - llvm::DenseSet ModuleMaps; - - llvm::DenseSet ProcessedModules; - auto CollectModuleMa

[clang] [ASTWriter] Do not allocate source location space for module maps used only for textual headers (PR #116374)

2024-11-20 Thread Boaz Brickner via cfe-commits
@@ -184,14 +184,30 @@ GetAffectingModuleMaps(const Preprocessor &PP, Module *RootModule) { const SourceManager &SM = PP.getSourceManager(); const ModuleMap &MM = HS.getModuleMap(); - llvm::DenseSet ModuleMaps; - - llvm::DenseSet ProcessedModules; - auto CollectModuleMa

[clang] [llvm] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-20 Thread Boaz Brickner via cfe-commits
https://github.com/bricknerb approved this pull request. Thanks! https://github.com/llvm/llvm-project/pull/115921 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [ASTWriter] Do not allocate source location space for module maps used only for textual headers (PR #116374)

2024-11-20 Thread Boaz Brickner via cfe-commits
@@ -184,14 +184,30 @@ GetAffectingModuleMaps(const Preprocessor &PP, Module *RootModule) { const SourceManager &SM = PP.getSourceManager(); const ModuleMap &MM = HS.getModuleMap(); - llvm::DenseSet ModuleMaps; - - llvm::DenseSet ProcessedModules; - auto CollectModuleMa

[clang] [ASTWriter] Do not allocate source location space for module maps used only for textual headers (PR #116374)

2024-11-20 Thread Boaz Brickner via cfe-commits
https://github.com/bricknerb approved this pull request. https://github.com/llvm/llvm-project/pull/116374 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [ASTWriter] Do not allocate source location space for module maps used only for textual headers (PR #116374)

2024-11-20 Thread Boaz Brickner via cfe-commits
bricknerb wrote: > Added @bricknerb to help with reviewing this (esp. the code style aspects) Focused on code style, please let me know if you want me to dive in more to correctness. https://github.com/llvm/llvm-project/pull/116374 ___ cfe-commits ma

[clang] [ASTWriter] Do not allocate source location space for module maps used only for textual headers (PR #116374)

2024-11-20 Thread Boaz Brickner via cfe-commits
@@ -184,14 +184,30 @@ GetAffectingModuleMaps(const Preprocessor &PP, Module *RootModule) { const SourceManager &SM = PP.getSourceManager(); const ModuleMap &MM = HS.getModuleMap(); - llvm::DenseSet ModuleMaps; - - llvm::DenseSet ProcessedModules; - auto CollectModuleMa

[clang] [llvm] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-20 Thread Boaz Brickner via cfe-commits
@@ -0,0 +1,348 @@ +// RUN: %clang_cc1 --std=c++20 -fsyntax-only -Wdangling -Wdangling-field -Wreturn-stack-address -verify %s + +#include "Inputs/lifetime-analysis.h" + +struct X { + const int *x; +}; +X x; + +// **

[clang] [llvm] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-20 Thread Boaz Brickner via cfe-commits
@@ -0,0 +1,348 @@ +// RUN: %clang_cc1 --std=c++20 -fsyntax-only -Wdangling -Wdangling-field -Wreturn-stack-address -verify %s + +#include "Inputs/lifetime-analysis.h" + +struct X { + const int *x; +}; +X x; + +// **

[clang] [llvm] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-20 Thread Boaz Brickner via cfe-commits
@@ -3922,16 +3922,41 @@ def LifetimeCaptureByDocs : Documentation { let Category = DocCatFunction; let Content = [{ Similar to `lifetimebound`_, the ``lifetime_capture_by(X)`` attribute on a function -parameter or implicit object parameter indicates that that objects t

[clang] [llvm] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-20 Thread Boaz Brickner via cfe-commits
bricknerb wrote: Do we have tests for bad usage of [[lifetime_capture_by]] ? For example, wrong number of parameters, "X" not defined, "X" is not an object that can actually capture something (for example: an integer passed by value) etc. ? Perhaps some of the

[clang] [clang] [NFC] Remove SourceLocation() parameter from Diag.Report() calls in SourceManager, and use the equivalent Report() overload instead (PR #116937)

2024-11-20 Thread Boaz Brickner via cfe-commits
https://github.com/bricknerb created https://github.com/llvm/llvm-project/pull/116937 None >From 376c3582016fb100743a0bbedd329ea480a14a31 Mon Sep 17 00:00:00 2001 From: Boaz Brickner Date: Wed, 20 Nov 2024 09:19:22 +0100 Subject: [PATCH] [clang] [NFC] Remove SourceLocation() parameter from Di

[clang] [clang] [NFC] In GetDiagForGotoScopeDecl(), limit Init to inside the if condition (PR #116080)

2024-11-19 Thread Boaz Brickner via cfe-commits
https://github.com/bricknerb closed https://github.com/llvm/llvm-project/pull/116080 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [llvm] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-19 Thread Boaz Brickner via cfe-commits
bricknerb wrote: I'm not familiar either with such a feature, but it seems it's possible to achieve, though not in a super straight forward way: For example: https://stackoverflow.com/questions/16937359/git-copy-file-preserving-history https://github.com/llvm

[clang] [clang] [NFC] Merge conditions (PR #116612)

2024-11-19 Thread Boaz Brickner via cfe-commits
https://github.com/bricknerb closed https://github.com/llvm/llvm-project/pull/116612 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [llvm] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-18 Thread Boaz Brickner via cfe-commits
@@ -3951,7 +3958,7 @@ The capturing entity ``X`` can be one of the following: std::set s; }; -- 'global', 'unknown' (without quotes). +- `global`, `unknown`. bricknerb wrote: Parameter names have enough constraints given local style guides and read

[clang] [llvm] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-18 Thread Boaz Brickner via cfe-commits
@@ -3951,7 +3958,7 @@ The capturing entity ``X`` can be one of the following: std::set s; }; -- 'global', 'unknown' (without quotes). +- `global`, `unknown`. bricknerb wrote: Thanks for clarifying! I think we should try to find an alternative for li

[clang] [llvm] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-18 Thread Boaz Brickner via cfe-commits
@@ -0,0 +1,220 @@ +// RUN: %clang_cc1 --std=c++20 -fsyntax-only -Wdangling -Wdangling-field -Wreturn-stack-address -verify %s + +#include "Inputs/lifetime-analysis.h" bricknerb wrote: I might tend to agree if this test file was short and easy to follow. Given th

[clang] [llvm] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-18 Thread Boaz Brickner via cfe-commits
@@ -3922,16 +3922,41 @@ def LifetimeCaptureByDocs : Documentation { let Category = DocCatFunction; let Content = [{ Similar to `lifetimebound`_, the ``lifetime_capture_by(X)`` attribute on a function -parameter or implicit object parameter indicates that that objects t

[clang] [llvm] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-18 Thread Boaz Brickner via cfe-commits
@@ -0,0 +1,220 @@ +// RUN: %clang_cc1 --std=c++20 -fsyntax-only -Wdangling -Wdangling-field -Wreturn-stack-address -verify %s + +#include "Inputs/lifetime-analysis.h" + +struct X { + const int *x; + void captureInt(const int& x [[clang::lifetime_capture_by(this)]]) { this->x =

[clang] [llvm] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-18 Thread Boaz Brickner via cfe-commits
@@ -1110,13 +1117,14 @@ static bool shouldRunGSLAssignmentAnalysis(const Sema &SemaRef, isAssignmentOperatorLifetimeBound(Entity.AssignmentOperator))); } -static void checkExprLifetimeImpl(Sema &SemaRef, - const InitializedEntity *I

[clang] [llvm] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-18 Thread Boaz Brickner via cfe-commits
https://github.com/bricknerb requested changes to this pull request. https://github.com/llvm/llvm-project/pull/115921 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [llvm] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-18 Thread Boaz Brickner via cfe-commits
@@ -3922,16 +3922,41 @@ def LifetimeCaptureByDocs : Documentation { let Category = DocCatFunction; let Content = [{ Similar to `lifetimebound`_, the ``lifetime_capture_by(X)`` attribute on a function -parameter or implicit object parameter indicates that that objects t

[clang] [llvm] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-18 Thread Boaz Brickner via cfe-commits
@@ -3951,7 +3958,7 @@ The capturing entity ``X`` can be one of the following: std::set s; }; -- 'global', 'unknown' (without quotes). +- `global`, `unknown`. bricknerb wrote: To clarify, I suggested the following: ```c++ void captureInt(const int &

[clang] [clang] [NFC] Merge conditions (PR #116612)

2024-11-18 Thread Boaz Brickner via cfe-commits
https://github.com/bricknerb created https://github.com/llvm/llvm-project/pull/116612 None >From 26e955a339c9b676d48711ee54713092c0401d48 Mon Sep 17 00:00:00 2001 From: Boaz Brickner Date: Mon, 18 Nov 2024 14:29:07 +0100 Subject: [PATCH] [clang] [NFC] Merge conditions --- clang/lib/Sema/Chec

[clang] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-15 Thread Boaz Brickner via cfe-commits
@@ -1411,18 +1437,34 @@ static void checkExprLifetimeImpl(Sema &SemaRef, // warnings or errors on inner temporaries within this one's initializer. return false; }; - bricknerb wrote: Bring back the blank line after the visitor definition. https://gi

[clang] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-15 Thread Boaz Brickner via cfe-commits
@@ -3229,6 +3230,52 @@ void Sema::CheckArgAlignment(SourceLocation Loc, NamedDecl *FDecl, << ParamName << (FDecl != nullptr) << FDecl; } +void Sema::checkLifetimeCaptureBy(FunctionDecl *FD, bool IsMemberFunction, + const Expr *ThisArg,

[clang] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-15 Thread Boaz Brickner via cfe-commits
@@ -1110,13 +1117,14 @@ static bool shouldRunGSLAssignmentAnalysis(const Sema &SemaRef, isAssignmentOperatorLifetimeBound(Entity.AssignmentOperator))); } -static void checkExprLifetimeImpl(Sema &SemaRef, - const InitializedEntity *I

[clang] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-15 Thread Boaz Brickner via cfe-commits
@@ -0,0 +1,220 @@ +// RUN: %clang_cc1 --std=c++20 -fsyntax-only -Wdangling -Wdangling-field -Wreturn-stack-address -verify %s + +#include "Inputs/lifetime-analysis.h" + +struct X { + const int *x; + void captureInt(const int& x [[clang::lifetime_capture_by(this)]]) { this->x =

[clang] [clang] [NFC] Merge two ifs to a single one (PR #116226)

2024-11-15 Thread Boaz Brickner via cfe-commits
https://github.com/bricknerb closed https://github.com/llvm/llvm-project/pull/116226 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-15 Thread Boaz Brickner via cfe-commits
@@ -3229,6 +3230,52 @@ void Sema::CheckArgAlignment(SourceLocation Loc, NamedDecl *FDecl, << ParamName << (FDecl != nullptr) << FDecl; } +void Sema::checkLifetimeCaptureBy(FunctionDecl *FD, bool IsMemberFunction, + const Expr *ThisArg,

[clang] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-15 Thread Boaz Brickner via cfe-commits
@@ -0,0 +1,220 @@ +// RUN: %clang_cc1 --std=c++20 -fsyntax-only -Wdangling -Wdangling-field -Wreturn-stack-address -verify %s + +#include "Inputs/lifetime-analysis.h" + +struct X { + const int *x; + void captureInt(const int& x [[clang::lifetime_capture_by(this)]]) { this->x =

[clang] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-15 Thread Boaz Brickner via cfe-commits
@@ -3925,13 +3925,20 @@ def LifetimeCaptureByDocs : Documentation { parameter or implicit object parameter indicates that that objects that are referred to by that parameter may also be referred to by the capturing entity ``X``. -By default, a reference is considered to refer

[clang] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-15 Thread Boaz Brickner via cfe-commits
@@ -3951,7 +3958,7 @@ The capturing entity ``X`` can be one of the following: std::set s; }; -- 'global', 'unknown' (without quotes). +- `global`, `unknown`. bricknerb wrote: What happens when the parameters are named "global" or "unknown"? https:/

[clang] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-15 Thread Boaz Brickner via cfe-commits
@@ -3229,6 +3230,52 @@ void Sema::CheckArgAlignment(SourceLocation Loc, NamedDecl *FDecl, << ParamName << (FDecl != nullptr) << FDecl; } +void Sema::checkLifetimeCaptureBy(FunctionDecl *FD, bool IsMemberFunction, + const Expr *ThisArg,

[clang] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-15 Thread Boaz Brickner via cfe-commits
https://github.com/bricknerb requested changes to this pull request. https://github.com/llvm/llvm-project/pull/115921 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-15 Thread Boaz Brickner via cfe-commits
@@ -0,0 +1,220 @@ +// RUN: %clang_cc1 --std=c++20 -fsyntax-only -Wdangling -Wdangling-field -Wreturn-stack-address -verify %s + +#include "Inputs/lifetime-analysis.h" + +struct X { + const int *x; + void captureInt(const int& x [[clang::lifetime_capture_by(this)]]) { this->x =

[clang] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-15 Thread Boaz Brickner via cfe-commits
@@ -0,0 +1,220 @@ +// RUN: %clang_cc1 --std=c++20 -fsyntax-only -Wdangling -Wdangling-field -Wreturn-stack-address -verify %s + +#include "Inputs/lifetime-analysis.h" bricknerb wrote: Perhaps let's split the test file that checks the capture-by on the standard

[clang] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-15 Thread Boaz Brickner via cfe-commits
@@ -3229,6 +3230,52 @@ void Sema::CheckArgAlignment(SourceLocation Loc, NamedDecl *FDecl, << ParamName << (FDecl != nullptr) << FDecl; } +void Sema::checkLifetimeCaptureBy(FunctionDecl *FD, bool IsMemberFunction, + const Expr *ThisArg,

[clang] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-15 Thread Boaz Brickner via cfe-commits
@@ -0,0 +1,220 @@ +// RUN: %clang_cc1 --std=c++20 -fsyntax-only -Wdangling -Wdangling-field -Wreturn-stack-address -verify %s + +#include "Inputs/lifetime-analysis.h" + +struct X { + const int *x; + void captureInt(const int& x [[clang::lifetime_capture_by(this)]]) { this->x =

[clang] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-15 Thread Boaz Brickner via cfe-commits
@@ -1460,7 +1502,15 @@ void checkExprLifetime(Sema &SemaRef, const AssignedEntity &Entity, checkExprLifetimeImpl(SemaRef, /*InitEntity=*/nullptr, /*ExtendingEntity=*/nullptr, LK_Assignment, &Entity, -Init); +

[clang] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-15 Thread Boaz Brickner via cfe-commits
@@ -3925,13 +3925,20 @@ def LifetimeCaptureByDocs : Documentation { parameter or implicit object parameter indicates that that objects that are referred to bricknerb wrote: While you're here, remove one of the "that" ? https://github.com/llvm/llvm-project/pull

[clang] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-15 Thread Boaz Brickner via cfe-commits
@@ -3983,6 +3990,21 @@ The attribute supports specifying more than one capturing entities: s2.insert(a); } +Currently clang would diagnose when a temporary is used as an argument to a bricknerb wrote: Nit: Use "Clang" and not "clang" when referring to

[clang] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-15 Thread Boaz Brickner via cfe-commits
@@ -3925,13 +3925,20 @@ def LifetimeCaptureByDocs : Documentation { parameter or implicit object parameter indicates that that objects that are referred to by that parameter may also be referred to by the capturing entity ``X``. -By default, a reference is considered to refer

[clang] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-14 Thread Boaz Brickner via cfe-commits
@@ -793,3 +793,108 @@ void test13() { } } // namespace GH100526 + +namespace lifetime_capture_by { +struct S { + const int *x; + void captureInt(const int&x [[clang::lifetime_capture_by(this)]]) { this->x = &x; } + void captureSV(std::string_view sv [[clang::lifetime_captu

[clang] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-14 Thread Boaz Brickner via cfe-commits
https://github.com/bricknerb edited https://github.com/llvm/llvm-project/pull/115921 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-14 Thread Boaz Brickner via cfe-commits
@@ -249,7 +254,7 @@ static void visitLocalsRetainedByReferenceBinding(IndirectLocalPath &Path, LocalVisitor Visit); template static bool isRecordWithAttr(QualType Type) { - if (auto *RD = Type->getAsCXXRecordDecl()) + if (a

[clang] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-14 Thread Boaz Brickner via cfe-commits
@@ -793,3 +806,202 @@ void test13() { } } // namespace GH100526 + +namespace lifetime_capture_by { +struct X { + const int *x; + void captureInt(const int& x [[clang::lifetime_capture_by(this)]]) { this->x = &x; } + void captureSV(std::string_view sv [[clang::lifetime_capt

[clang] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-14 Thread Boaz Brickner via cfe-commits
@@ -1420,9 +1446,18 @@ static void checkExprLifetimeImpl(Sema &SemaRef, ? IndirectLocalPathEntry::LifetimeBoundCall : IndirectLocalPathEntry::GslPointerAssignment, Init}); + } else if (LK == LK_LifetimeCapture) { bricknerb wr

[clang] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-14 Thread Boaz Brickner via cfe-commits
https://github.com/bricknerb commented: Please request another review after comments are addressed. https://github.com/llvm/llvm-project/pull/115921 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo

[clang] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-14 Thread Boaz Brickner via cfe-commits
@@ -3229,6 +3231,52 @@ void Sema::CheckArgAlignment(SourceLocation Loc, NamedDecl *FDecl, << ParamName << (FDecl != nullptr) << FDecl; } +void Sema::checkLifetimeCaptureBy(FunctionDecl *FD, bool IsMemberFunction, + const Expr *ThisArg,

[clang] [clang] [NFC] Merge two ifs to a single one (PR #116226)

2024-11-14 Thread Boaz Brickner via cfe-commits
https://github.com/bricknerb created https://github.com/llvm/llvm-project/pull/116226 None >From 35c1a01df73a52acda55bb4a162fdbddd03c764d Mon Sep 17 00:00:00 2001 From: Boaz Brickner Date: Thu, 14 Nov 2024 14:27:33 +0100 Subject: [PATCH] [clang] [NFC] Merge two ifs to a single one --- clang/

[clang] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-13 Thread Boaz Brickner via cfe-commits
@@ -1199,6 +1207,21 @@ static void checkExprLifetimeImpl(Sema &SemaRef, break; } +case LK_LifetimeCapture: { + if (!MTE) +return false; + assert(shouldLifetimeExtendThroughPath(Path) == + PathLifetimeKind::NoExtend && +

[clang] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-13 Thread Boaz Brickner via cfe-commits
https://github.com/bricknerb edited https://github.com/llvm/llvm-project/pull/115921 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-13 Thread Boaz Brickner via cfe-commits
@@ -10230,6 +10230,9 @@ def warn_dangling_pointer_assignment : Warning< "object backing %select{|the pointer }0%1 " "will be destroyed at the end of the full-expression">, InGroup; +def warn_dangling_reference_captured : Warning< + "object whose reference is captured

[clang] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-13 Thread Boaz Brickner via cfe-commits
@@ -793,3 +806,202 @@ void test13() { } } // namespace GH100526 + +namespace lifetime_capture_by { +struct S { + const int *x; + void captureInt(const int&x [[clang::lifetime_capture_by(this)]]) { this->x = &x; } bricknerb wrote: Be consistent regarding sp

[clang] [clang] [NFC] In GetDiagForGotoScopeDecl(), limit Init to inside the if condition (PR #116080)

2024-11-13 Thread Boaz Brickner via cfe-commits
https://github.com/bricknerb created https://github.com/llvm/llvm-project/pull/116080 None >From 3d3d273f849ed5cdf357d6c1ea7c34f76f51afeb Mon Sep 17 00:00:00 2001 From: Boaz Brickner Date: Wed, 13 Nov 2024 17:54:40 +0100 Subject: [PATCH] [clang] [NFC] In GetDiagForGotoScopeDecl(), limit Init t

[clang] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-13 Thread Boaz Brickner via cfe-commits
@@ -1199,6 +1207,21 @@ static void checkExprLifetimeImpl(Sema &SemaRef, break; } +case LK_LifetimeCapture: { + if (!MTE) +return false; + assert(shouldLifetimeExtendThroughPath(Path) == + PathLifetimeKind::NoExtend && +

[clang] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-13 Thread Boaz Brickner via cfe-commits
@@ -10132,10 +10132,10 @@ def err_lifetimebound_ctor_dtor : Error< "%select{constructor|destructor}0">; def err_lifetimebound_parameter_void_return_type : Error< "'lifetimebound' attribute cannot be applied to a parameter of a function " - "that returns void">; + "that re

[clang] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-13 Thread Boaz Brickner via cfe-commits
@@ -1438,13 +1471,13 @@ void checkExprLifetime(Sema &SemaRef, const InitializedEntity &Entity, LifetimeKind LK = LTResult.getInt(); const InitializedEntity *ExtendingEntity = LTResult.getPointer(); checkExprLifetimeImpl(SemaRef, &Entity, ExtendingEntity, LK, -

[clang] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-13 Thread Boaz Brickner via cfe-commits
@@ -3229,6 +3231,52 @@ void Sema::CheckArgAlignment(SourceLocation Loc, NamedDecl *FDecl, << ParamName << (FDecl != nullptr) << FDecl; } +void Sema::checkLifetimeCaptureBy(FunctionDecl *FD, bool IsMemberFunction, + const Expr *ThisArg,

[clang] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-13 Thread Boaz Brickner via cfe-commits
@@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -Wdangling -Wdangling-field -Wreturn-stack-address -verify %s +// RUN: %clang_cc1 --std=c++20 -fsyntax-only -Wdangling -Wdangling-field -Wreturn-stack-address -verify %s bricknerb wrote: Should we limit all the

[clang] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-13 Thread Boaz Brickner via cfe-commits
@@ -1199,6 +1207,21 @@ static void checkExprLifetimeImpl(Sema &SemaRef, break; } +case LK_LifetimeCapture: { + if (!MTE) bricknerb wrote: Add a comment explaining when do we expect this to happen? https://github.com/llvm/llvm-project/pull/

[clang] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-13 Thread Boaz Brickner via cfe-commits
@@ -1110,12 +1117,13 @@ static bool shouldRunGSLAssignmentAnalysis(const Sema &SemaRef, isAssignmentOperatorLifetimeBound(Entity.AssignmentOperator))); } -static void checkExprLifetimeImpl(Sema &SemaRef, - const InitializedEntity *I

[clang] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-13 Thread Boaz Brickner via cfe-commits
@@ -793,3 +806,202 @@ void test13() { } } // namespace GH100526 + +namespace lifetime_capture_by { +struct S { + const int *x; + void captureInt(const int&x [[clang::lifetime_capture_by(this)]]) { this->x = &x; } + void captureSV(std::string_view sv [[clang::lifetime_captu

[clang] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-13 Thread Boaz Brickner via cfe-commits
https://github.com/bricknerb commented: First pass, still didn't dive fully into the logic. https://github.com/llvm/llvm-project/pull/115921 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-com

[clang] [Clang] [NFC] Add "human" diagnostic argument format (PR #115835)

2024-11-12 Thread Boaz Brickner via cfe-commits
https://github.com/bricknerb closed https://github.com/llvm/llvm-project/pull/115835 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang] [NFC] Split checkAttributesAfterMerging() to multiple functions (PR #115464)

2024-11-12 Thread Boaz Brickner via cfe-commits
https://github.com/bricknerb closed https://github.com/llvm/llvm-project/pull/115464 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [Clang] [NFC] Add "human" diagnostic argument format (PR #115835)

2024-11-12 Thread Boaz Brickner via cfe-commits
@@ -315,6 +315,18 @@ Description: than ``1`` are not supported. This formatter is currently hard-coded to use English ordinals. +**"human" format** + +Example: + ``"total size is %human0 bytes"`` +Class: + Integers +Description: + This is a formatter which represents t

[clang] [Clang] [NFC] Add "human" diagnostic argument format (PR #115835)

2024-11-12 Thread Boaz Brickner via cfe-commits
https://github.com/bricknerb updated https://github.com/llvm/llvm-project/pull/115835 >From ccf18e49f884b4430dff70d59fb3236259661f9d Mon Sep 17 00:00:00 2001 From: Boaz Brickner Date: Tue, 12 Nov 2024 10:19:58 +0100 Subject: [PATCH 1/3] [Clang] [NFC] Add "human" diagnostic argument format This

[clang] [clang-tools-extra] [NFC] Explicitly pass a VFS when creating DiagnosticsEngine (PR #115852)

2024-11-12 Thread Boaz Brickner via cfe-commits
@@ -368,11 +365,10 @@ IntrusiveRefCntPtr CompilerInstance::createDiagnostics( SetUpDiagnosticLog(Opts, CodeGenOpts, *Diags); if (!Opts->DiagnosticSerializationFile.empty()) -SetupSerializedDiagnostics(Opts, *Diags, - Opts->DiagnosticSer

[clang] [clang-tools-extra] [NFC] Explicitly pass a VFS when creating DiagnosticsEngine (PR #115852)

2024-11-12 Thread Boaz Brickner via cfe-commits
@@ -332,23 +332,20 @@ static void SetupSerializedDiagnostics(DiagnosticOptions *DiagOpts, } } -void CompilerInstance::createDiagnostics(DiagnosticConsumer *Client, +void CompilerInstance::createDiagnostics(llvm::vfs::FileSystem &VFS, +

[clang] [clang-tools-extra] [NFC] Explicitly pass a VFS when creating DiagnosticsEngine (PR #115852)

2024-11-12 Thread Boaz Brickner via cfe-commits
https://github.com/bricknerb approved this pull request. Thanks for fixing! It might be worth understanding whether this should have been caught by some test. We might want to add a test or a check that would catch this. https://github.com/llvm/llvm-project/pull/115852 _

[clang] [clang-tools-extra] [NFC] Explicitly pass a VFS when creating DiagnosticsEngine (PR #115852)

2024-11-12 Thread Boaz Brickner via cfe-commits
https://github.com/bricknerb edited https://github.com/llvm/llvm-project/pull/115852 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [Clang] [NFC] Add "human" diagnostic argument format (PR #115835)

2024-11-12 Thread Boaz Brickner via cfe-commits
https://github.com/bricknerb updated https://github.com/llvm/llvm-project/pull/115835 >From ccf18e49f884b4430dff70d59fb3236259661f9d Mon Sep 17 00:00:00 2001 From: Boaz Brickner Date: Tue, 12 Nov 2024 10:19:58 +0100 Subject: [PATCH 1/2] [Clang] [NFC] Add "human" diagnostic argument format This

[clang] [Clang] [NFC] Add "human" diagnostic argument format (PR #115835)

2024-11-12 Thread Boaz Brickner via cfe-commits
https://github.com/bricknerb created https://github.com/llvm/llvm-project/pull/115835 This allows formatting large integers in a human friendly way. Example: "5321584" -> "5.32M". Use it where such human numbers are generated manually today. >From ccf18e49f884b4430dff70d59fb3236259661f9d Mon S

[clang] [clang-tools-extra] [llvm] [clang] Introduce diagnostics suppression mappings (PR #112517)

2024-11-08 Thread Boaz Brickner via cfe-commits
@@ -477,6 +486,136 @@ void DiagnosticsEngine::setSeverityForAll(diag::Flavor Flavor, setSeverity(Diag, Map, Loc); } +namespace { +// FIXME: We should isolate the parser from SpecialCaseList and just use it +// here. +class WarningsSpecialCaseList : public llvm::SpecialC

[clang] [clang] [NFC] Split checkAttributesAfterMerging() to multiple functions (PR #115464)

2024-11-08 Thread Boaz Brickner via cfe-commits
https://github.com/bricknerb created https://github.com/llvm/llvm-project/pull/115464 None >From 01200ae10a21ad408b08eda542e759f9d3d76cbb Mon Sep 17 00:00:00 2001 From: Boaz Brickner Date: Fri, 8 Nov 2024 12:18:21 +0100 Subject: [PATCH] [clang] [NFC] Split checkAttributesAfterMerging() to mult

[clang] [clang-tools-extra] [llvm] [clang] Introduce diagnostics suppression mappings (PR #112517)

2024-11-08 Thread Boaz Brickner via cfe-commits
@@ -167,4 +179,155 @@ TEST(DiagnosticTest, storedDiagEmptyWarning) { // Make sure an empty warning can round-trip with \c StoredDiagnostic. Diags.Report(CaptureConsumer.StoredDiags.front()); } + +class SuppressionMappingTest : public testing::Test { +public: + SuppressionM

[clang] [clang-tools-extra] [llvm] [clang] Introduce diagnostics suppression mappings (PR #112517)

2024-11-08 Thread Boaz Brickner via cfe-commits
@@ -167,4 +176,159 @@ TEST(DiagnosticTest, storedDiagEmptyWarning) { // Make sure an empty warning can round-trip with \c StoredDiagnostic. Diags.Report(CaptureConsumer.StoredDiags.front()); } + +class SuppressionMappingTest : public testing::Test { +public: + SuppressionM

[clang] [clang-tools-extra] [llvm] [clang] Introduce diagnostics suppression mappings (PR #112517)

2024-11-08 Thread Boaz Brickner via cfe-commits
@@ -167,4 +176,159 @@ TEST(DiagnosticTest, storedDiagEmptyWarning) { // Make sure an empty warning can round-trip with \c StoredDiagnostic. Diags.Report(CaptureConsumer.StoredDiags.front()); } + +class SuppressionMappingTest : public testing::Test { +public: + SuppressionM

[clang] [clang-tools-extra] [llvm] [clang] Introduce diagnostics suppression mappings (PR #112517)

2024-11-08 Thread Boaz Brickner via cfe-commits
@@ -477,6 +486,109 @@ void DiagnosticsEngine::setSeverityForAll(diag::Flavor Flavor, setSeverity(Diag, Map, Loc); } +namespace { +class WarningsSpecialCaseList : public llvm::SpecialCaseList { +public: + static std::unique_ptr + create(const llvm::MemoryBuffer &MB, st

[clang] [clang-tools-extra] [llvm] [clang] Introduce diagnostics suppression mappings (PR #112517)

2024-11-08 Thread Boaz Brickner via cfe-commits
https://github.com/bricknerb approved this pull request. https://github.com/llvm/llvm-project/pull/112517 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang-tools-extra] [llvm] [clang] Introduce diagnostics suppression mappings (PR #112517)

2024-11-08 Thread Boaz Brickner via cfe-commits
@@ -0,0 +1,90 @@ + +Warning suppression mappings + + +.. contents:: + :local: + +Introduction + + +Warning suppression mappings enable users to suppress Clang's diagnostics in a +per-file granular manner. Enabli

[clang] [clang-tools-extra] [llvm] [clang] Introduce diagnostics suppression mappings (PR #112517)

2024-11-08 Thread Boaz Brickner via cfe-commits
@@ -477,6 +486,136 @@ void DiagnosticsEngine::setSeverityForAll(diag::Flavor Flavor, setSeverity(Diag, Map, Loc); } +namespace { +// FIXME: We should isolate the parser from SpecialCaseList and just use it +// here. +class WarningsSpecialCaseList : public llvm::SpecialC

[clang] [clang-tools-extra] [llvm] [clang] Introduce diagnostics suppression mappings (PR #112517)

2024-11-08 Thread Boaz Brickner via cfe-commits
bricknerb wrote: Unit tests cover the code and Clang integration tests are useful to test a feature end-to-end. The compiler logic that handles the code until it reaches this point might break the assumptions we have in the specific code (especially if we thin

  1   2   3   >