[clang] [Clang] Implement P2280R4 Using unknown pointers and references in constant expressions (PR #95474)
https://github.com/frederick-vs-ja edited https://github.com/llvm/llvm-project/pull/95474 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Implement P2280R4 Using unknown pointers and references in constant expressions (PR #95474)
@@ -3300,6 +3308,11 @@ static bool HandleLValueComplexElement(EvalInfo , const Expr *E, static bool evaluateVarDeclInit(EvalInfo , const Expr *E, const VarDecl *VD, CallStackFrame *Frame, unsigned Version, APValue *) { + // P2280R4 If we have a reference type and we are in C++23 allow unknown + // references and pointers. + bool AllowConstexprUnknown = + Info.getLangOpts().CPlusPlus23 && VD->getType()->isReferenceType(); frederick-vs-ja wrote: This is a DR per [N4916](https://wg21.link/n4916) (ditto below). ```suggestion // P2280R4 allow unknown references and pointers. bool AllowConstexprUnknown = VD->getType()->isReferenceType(); ``` https://github.com/llvm/llvm-project/pull/95474 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Implement P2280R4 Using unknown pointers and references in constant expressions (PR #95474)
@@ -1961,7 +1961,8 @@ namespace ConstexprConstructorRecovery { namespace Lifetime { void f() { -constexpr int = n; // expected-error {{constant expression}} expected-note {{use of reference outside its lifetime}} expected-warning {{not yet bound to a value}} +constexpr int = n; // expected-error {{constant expression}} cxx23-note {{reference to 'n' is not a constant expression}} cxx23-note {{address of non-static constexpr variable 'n' may differ}} expected-warning {{not yet bound to a value}} + // cxx11_20-note@-1 {{use of reference outside its lifetime is not allowed in a constant expression}} frederick-vs-ja wrote: This looks strange. The old message looks better (see also [CWG453](https://cplusplus.github.io/CWG/issues/453.html)) and the new one is possibly misleading as we perhaps shoudn't say the address of a reference variable. https://github.com/llvm/llvm-project/pull/95474 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] fix(95366): enhance cast operation safety with LValue validation (PR #95479)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/95479 >From d66fdcbe0a56e17dbd25e6d2ed5bdcce1970fdea Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 14 Jun 2024 01:26:34 +0300 Subject: [PATCH 1/2] fix(95366): enhance cast operation safety with LValue validation --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/AST/ExprConstant.cpp| 3 +++ clang/test/Sema/integral-to-ptr.c | 3 +++ 3 files changed, 7 insertions(+) create mode 100644 clang/test/Sema/integral-to-ptr.c diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 8c2f737836a9d..77906360b 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -847,6 +847,7 @@ Bug Fixes to C++ Support - Fixed several bugs in capturing variables within unevaluated contexts. (#GH63845), (#GH67260), (#GH69307), (#GH88081), (#GH89496), (#GH90669) and (#GH91633). - Fixed handling of brace ellison when building deduction guides. (#GH64625), (#GH83368). +- Fix an assertion failure caused by non-lvalue usage in lvalue context. (GH95366). Bug Fixes to AST Handling ^ diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 7178f081d9cf3..08bee806f172f 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -9325,6 +9325,9 @@ bool PointerExprEvaluator::VisitCastExpr(const CastExpr *E) { Result.IsNullPtr = false; return true; } else { + if (!Value.isLValue()) +return false; + // Cast is of an lvalue, no need to change value. Result.setFrom(Info.Ctx, Value); return true; diff --git a/clang/test/Sema/integral-to-ptr.c b/clang/test/Sema/integral-to-ptr.c new file mode 100644 index 0..99f83c3e52057 --- /dev/null +++ b/clang/test/Sema/integral-to-ptr.c @@ -0,0 +1,3 @@ +// RUN: %clang_cc1 %s -verify -fsyntax-only -std=c11 + +int x(void) { e: b: ; return & - & < x; } // expected-warning {{ordered comparison between pointer and integer ('long' and 'int (*)(void)')}} >From 8ce09ce067b22346378d6f108e4fa1786bc460ef Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 14 Jun 2024 08:50:03 +0300 Subject: [PATCH 2/2] update test expectations --- clang/test/Sema/integral-to-ptr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/Sema/integral-to-ptr.c b/clang/test/Sema/integral-to-ptr.c index 99f83c3e52057..b8ab4cb79820d 100644 --- a/clang/test/Sema/integral-to-ptr.c +++ b/clang/test/Sema/integral-to-ptr.c @@ -1,3 +1,3 @@ // RUN: %clang_cc1 %s -verify -fsyntax-only -std=c11 -int x(void) { e: b: ; return & - & < x; } // expected-warning {{ordered comparison between pointer and integer ('long' and 'int (*)(void)')}} +int x(void) { e: b: ; return & - & < x; } // expected-warning {{ordered comparison between pointer and integer}} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Safe Buffers] Serialize unsafe_buffer_usage pragmas (PR #92031)
https://github.com/ziqingluo-90 closed https://github.com/llvm/llvm-project/pull/92031 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 2e7b95e - [Safe Buffers] Serialize unsafe_buffer_usage pragmas (#92031)
Author: Ziqing Luo Date: 2024-06-13T22:44:24-07:00 New Revision: 2e7b95e4c080426e5085c38cec01176b56798534 URL: https://github.com/llvm/llvm-project/commit/2e7b95e4c080426e5085c38cec01176b56798534 DIFF: https://github.com/llvm/llvm-project/commit/2e7b95e4c080426e5085c38cec01176b56798534.diff LOG: [Safe Buffers] Serialize unsafe_buffer_usage pragmas (#92031) The commit adds serialization and de-serialization implementations for the stored regions. Basically, the serialized representation of the regions of a PP is a (ordered) sequence of source location encodings. For de-serialization, regions from loaded files are stored by their ASTs. When later one queries if a loaded location L is in an opt-out region, PP looks up the regions of the loaded AST where L is at. (Background if helps: a pair of `#pragma clang unsafe_buffer_usage begin/end` pragmas marks a warning-opt-out region. The begin and end locations (opt-out regions) are stored in preprocessor instances (PP) and will be queried by the `-Wunsafe-buffer-usage` analyzer.) The reported issue at upstream: https://github.com/llvm/llvm-project/issues/90501 rdar://124035402 Added: clang/test/Modules/safe_buffers_optout.cpp clang/test/PCH/unsafe-buffer-usage-pragma-pch-complex.cpp clang/test/PCH/unsafe-buffer-usage-pragma-pch-cross-files-2.cpp clang/test/PCH/unsafe-buffer-usage-pragma-pch-cross-files.cpp clang/test/SemaCXX/warn-unsafe-buffer-usage-pragma-pch.cpp Modified: clang/include/clang/Basic/SourceManager.h clang/include/clang/Lex/Preprocessor.h clang/include/clang/Serialization/ASTBitCodes.h clang/lib/Basic/SourceManager.cpp clang/lib/Lex/Preprocessor.cpp clang/lib/Serialization/ASTReader.cpp clang/lib/Serialization/ASTWriter.cpp Removed: diff --git a/clang/include/clang/Basic/SourceManager.h b/clang/include/clang/Basic/SourceManager.h index ce33423551039..d2e2e914327f2 100644 --- a/clang/include/clang/Basic/SourceManager.h +++ b/clang/include/clang/Basic/SourceManager.h @@ -1676,6 +1676,11 @@ class SourceManager : public RefCountedBase { isInTheSameTranslationUnit(std::pair , std::pair ) const; + /// \param Loc a source location in a loaded AST (of a PCH/Module file). + /// \returns a FileID uniquely identifies the AST of a loaded + /// module/PCH where `Loc` is at. + FileID getUniqueLoadedASTFileID(SourceLocation Loc) const; + /// Determines whether the two decomposed source location is in the same TU. bool isInTheSameTranslationUnitImpl( const std::pair , diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h index 9b1628d2d86f9..9d8a1aae23df3 100644 --- a/clang/include/clang/Lex/Preprocessor.h +++ b/clang/include/clang/Lex/Preprocessor.h @@ -2883,11 +2883,41 @@ class Preprocessor { /// otherwise. SourceLocation CurrentSafeBufferOptOutStart; // It is used to report the start location of an never-closed region. - // An ordered sequence of "-Wunsafe-buffer-usage" opt-out regions in one - // translation unit. Each region is represented by a pair of start and end - // locations. A region is "open" if its' start and end locations are - // identical. - SmallVector, 8> SafeBufferOptOutMap; + using SafeBufferOptOutRegionsTy = + SmallVector, 16>; + // An ordered sequence of "-Wunsafe-buffer-usage" opt-out regions in this + // translation unit. Each region is represented by a pair of start and + // end locations. + SafeBufferOptOutRegionsTy SafeBufferOptOutMap; + + // The "-Wunsafe-buffer-usage" opt-out regions in loaded ASTs. We use the + // following structure to manage them by their ASTs. + struct { +// A map from unique IDs to region maps of loaded ASTs. The ID identifies a +// loaded AST. See `SourceManager::getUniqueLoadedASTID`. +llvm::DenseMap LoadedRegions; + +// Returns a reference to the safe buffer opt-out regions of the loaded +// AST where `Loc` belongs to. (Construct if absent) +SafeBufferOptOutRegionsTy & +findAndConsLoadedOptOutMap(SourceLocation Loc, SourceManager ) { + return LoadedRegions[SrcMgr.getUniqueLoadedASTFileID(Loc)]; +} + +// Returns a reference to the safe buffer opt-out regions of the loaded +// AST where `Loc` belongs to. (This const function returns nullptr if +// absent.) +const SafeBufferOptOutRegionsTy * +lookupLoadedOptOutMap(SourceLocation Loc, + const SourceManager ) const { + FileID FID = SrcMgr.getUniqueLoadedASTFileID(Loc); + auto Iter = LoadedRegions.find(FID); + + if (Iter == LoadedRegions.end()) +return nullptr; + return >getSecond(); +} + } LoadedSafeBufferOptOutMap; public: /// \return true iff the given `Loc` is in a "-Wunsafe-buffer-usage" opt-out @@ -2918,6 +2948,18 @@ class Preprocessor { /// opt-out
[clang] fix(95366): enhance cast operation safety with LValue validation (PR #95479)
@@ -0,0 +1,3 @@ +// RUN: %clang_cc1 %s -verify -fsyntax-only -std=c11 + +int x(void) { e: b: ; return & - & < x; } // expected-warning {{ordered comparison between pointer and integer ('long' and 'int (*)(void)')}} Sirraide wrote: ```suggestion int x(void) { e: b: ; return & - & < x; } // expected-warning {{ordered comparison between pointer and integer}} ``` On Windows, this is a `long long`, not a `long`, which is why the test is currently failing. https://github.com/llvm/llvm-project/pull/95479 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] fix(95366): enhance cast operation safety with LValue validation (PR #95479)
https://github.com/Sirraide approved this pull request. LGTM after addressing one issue. Looking at the rest of the constant evaluator (and the comments on the issue as well), everything else seems to use `EvaluateInteger`, which makes sure the result of the evaluation is an integer, so this seems like it is the only place where we can wind up with an `AddrLabelDiff`, so rejecting it here makes sense. https://github.com/llvm/llvm-project/pull/95479 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] fix(95366): enhance cast operation safety with LValue validation (PR #95479)
https://github.com/Sirraide edited https://github.com/llvm/llvm-project/pull/95479 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [serialization] no transitive decl change (PR #92083)
ChuanqiXu9 wrote: I sent https://github.com/llvm/llvm-project/pull/95506. It is a independent patch which may mitigate the issue you met. @alexfh you can try this when you have time. https://github.com/llvm/llvm-project/pull/92083 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Serialization] Don't read all declaration id eagerly when merge the tables (PR #95506)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Chuanqi Xu (ChuanqiXu9) Changes See the post commit message in https://github.com/llvm/llvm-project/pull/92083 for rationale. Previously, when we merge the lookup tables, we will read the tables completely to get the data. But the above page shows that it might be problematic in specific cases where there a lot of DeclIDs to be read. In this patch, we mitigated the problem by not reading the contents of the merged tables. But we may need to pay for the additional memory usages. --- Full diff: https://github.com/llvm/llvm-project/pull/95506.diff 1 Files Affected: - (modified) clang/lib/Serialization/MultiOnDiskHashTable.h (+54-10) ``diff diff --git a/clang/lib/Serialization/MultiOnDiskHashTable.h b/clang/lib/Serialization/MultiOnDiskHashTable.h index a0d75ec3a9e76..f98394e904549 100644 --- a/clang/lib/Serialization/MultiOnDiskHashTable.h +++ b/clang/lib/Serialization/MultiOnDiskHashTable.h @@ -73,6 +73,51 @@ template class MultiOnDiskHashTable { struct MergedTable { std::vector Files; llvm::DenseMap Data; + +struct UnreadDataInfo { + Info *InfoObj; + const unsigned char *start; + unsigned DataLen; +}; + +llvm::DenseMap> +UnReadData; + +std::vector MergedOnDiskTables; + +void clear() { + for (OnDiskTable *ODT : MergedOnDiskTables) +delete ODT; + + MergedOnDiskTables.clear(); +} + +void readAll() { + for (const auto : UnReadData) { +internal_key_type Key = Iter.first; +data_type_builder ValueBuilder(Data[Key]); + +for (const UnreadDataInfo : Iter.second) + I.InfoObj->ReadDataInto(Key, I.start, I.DataLen, ValueBuilder); + } + + UnReadData.clear(); + clear(); +} + +data_type find(internal_key_type Key) { + auto UnreadIter = UnReadData.find(Key); + if (UnreadIter != UnReadData.end()) { +data_type_builder ValueBuilder(Data[Key]); +for (auto : UnreadIter->second) + I.InfoObj->ReadDataInto(Key, I.start, I.DataLen, ValueBuilder); +UnReadData.erase(UnreadIter); + } + + return Data[Key]; +} + +~MergedTable() { clear(); } }; using Table = llvm::PointerUnion; @@ -159,13 +204,14 @@ template class MultiOnDiskHashTable { // FIXME: Don't rely on the OnDiskHashTable format here. auto L = InfoObj.ReadKeyDataLength(LocalPtr); const internal_key_type = InfoObj.ReadKey(LocalPtr, L.first); -data_type_builder ValueBuilder(Merged->Data[Key]); -InfoObj.ReadDataInto(Key, LocalPtr + L.first, L.second, - ValueBuilder); +// Make sure Merged->Data contains every key. +(void)Merged->Data[Key]; +Merged->UnReadData[Key].push_back( +{, LocalPtr + L.first, L.second}); } Merged->Files.push_back(ODT->File); - delete ODT; + Merged->MergedOnDiskTables.push_back(ODT); } Tables.clear(); @@ -239,11 +285,8 @@ template class MultiOnDiskHashTable { internal_key_type Key = Info::GetInternalKey(EKey); auto KeyHash = Info::ComputeHash(Key); -if (MergedTable *M = getMergedTable()) { - auto It = M->Data.find(Key); - if (It != M->Data.end()) -Result = It->second; -} +if (MergedTable *M = getMergedTable()) + Result = M->find(Key); data_type_builder ResultBuilder(Result); @@ -268,6 +311,7 @@ template class MultiOnDiskHashTable { removeOverriddenTables(); if (MergedTable *M = getMergedTable()) { + M->readAll(); for (auto : M->Data) Info::MergeDataInto(KV.second, ResultBuilder); } @@ -327,7 +371,7 @@ class MultiOnDiskHashTableGenerator { // Add all merged entries from Base to the generator. for (auto : Merged->Data) { if (!Gen.contains(KV.first, Info)) -Gen.insert(KV.first, Info.ImportData(KV.second), Info); +Gen.insert(KV.first, Info.ImportData(Merged->find(KV.first)), Info); } } else { Writer.write(0); `` https://github.com/llvm/llvm-project/pull/95506 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Serialization] Don't read all declaration id eagerly when merge the tables (PR #95506)
https://github.com/ChuanqiXu9 created https://github.com/llvm/llvm-project/pull/95506 See the post commit message in https://github.com/llvm/llvm-project/pull/92083 for rationale. Previously, when we merge the lookup tables, we will read the tables completely to get the data. But the above page shows that it might be problematic in specific cases where there a lot of DeclIDs to be read. In this patch, we mitigated the problem by not reading the contents of the merged tables. But we may need to pay for the additional memory usages. >From 5adb69ef86de078f2b6446a16501941dfbdf4f57 Mon Sep 17 00:00:00 2001 From: Chuanqi Xu Date: Fri, 14 Jun 2024 13:05:05 +0800 Subject: [PATCH] [Serialization] Don't read all declaration id eagerly when merge the tables See the post commit message in https://github.com/llvm/llvm-project/pull/92083 for rationale. Previously, when we merge the lookup tables, we will read the tables completely to get the data. But the above page shows that it might be problematic in specific cases where there a lot of DeclIDs to be read. In this patch, we mitigated the problem by not reading the contents of the merged tables. But we may need to pay for the additional memory usages. --- .../lib/Serialization/MultiOnDiskHashTable.h | 64 --- 1 file changed, 54 insertions(+), 10 deletions(-) diff --git a/clang/lib/Serialization/MultiOnDiskHashTable.h b/clang/lib/Serialization/MultiOnDiskHashTable.h index a0d75ec3a9e76..f98394e904549 100644 --- a/clang/lib/Serialization/MultiOnDiskHashTable.h +++ b/clang/lib/Serialization/MultiOnDiskHashTable.h @@ -73,6 +73,51 @@ template class MultiOnDiskHashTable { struct MergedTable { std::vector Files; llvm::DenseMap Data; + +struct UnreadDataInfo { + Info *InfoObj; + const unsigned char *start; + unsigned DataLen; +}; + +llvm::DenseMap> +UnReadData; + +std::vector MergedOnDiskTables; + +void clear() { + for (OnDiskTable *ODT : MergedOnDiskTables) +delete ODT; + + MergedOnDiskTables.clear(); +} + +void readAll() { + for (const auto : UnReadData) { +internal_key_type Key = Iter.first; +data_type_builder ValueBuilder(Data[Key]); + +for (const UnreadDataInfo : Iter.second) + I.InfoObj->ReadDataInto(Key, I.start, I.DataLen, ValueBuilder); + } + + UnReadData.clear(); + clear(); +} + +data_type find(internal_key_type Key) { + auto UnreadIter = UnReadData.find(Key); + if (UnreadIter != UnReadData.end()) { +data_type_builder ValueBuilder(Data[Key]); +for (auto : UnreadIter->second) + I.InfoObj->ReadDataInto(Key, I.start, I.DataLen, ValueBuilder); +UnReadData.erase(UnreadIter); + } + + return Data[Key]; +} + +~MergedTable() { clear(); } }; using Table = llvm::PointerUnion; @@ -159,13 +204,14 @@ template class MultiOnDiskHashTable { // FIXME: Don't rely on the OnDiskHashTable format here. auto L = InfoObj.ReadKeyDataLength(LocalPtr); const internal_key_type = InfoObj.ReadKey(LocalPtr, L.first); -data_type_builder ValueBuilder(Merged->Data[Key]); -InfoObj.ReadDataInto(Key, LocalPtr + L.first, L.second, - ValueBuilder); +// Make sure Merged->Data contains every key. +(void)Merged->Data[Key]; +Merged->UnReadData[Key].push_back( +{, LocalPtr + L.first, L.second}); } Merged->Files.push_back(ODT->File); - delete ODT; + Merged->MergedOnDiskTables.push_back(ODT); } Tables.clear(); @@ -239,11 +285,8 @@ template class MultiOnDiskHashTable { internal_key_type Key = Info::GetInternalKey(EKey); auto KeyHash = Info::ComputeHash(Key); -if (MergedTable *M = getMergedTable()) { - auto It = M->Data.find(Key); - if (It != M->Data.end()) -Result = It->second; -} +if (MergedTable *M = getMergedTable()) + Result = M->find(Key); data_type_builder ResultBuilder(Result); @@ -268,6 +311,7 @@ template class MultiOnDiskHashTable { removeOverriddenTables(); if (MergedTable *M = getMergedTable()) { + M->readAll(); for (auto : M->Data) Info::MergeDataInto(KV.second, ResultBuilder); } @@ -327,7 +371,7 @@ class MultiOnDiskHashTableGenerator { // Add all merged entries from Base to the generator. for (auto : Merged->Data) { if (!Gen.contains(KV.first, Info)) -Gen.insert(KV.first, Info.ImportData(KV.second), Info); +Gen.insert(KV.first, Info.ImportData(Merged->find(KV.first)), Info); } } else { Writer.write(0); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Don't count template template parameter as declaration (PR #95025)
@@ -1269,10 +1269,17 @@ class AnnotatingParser { if (CurrentToken && CurrentToken->is(tok::less)) { CurrentToken->setType(TT_TemplateOpener); next(); - if (!parseAngle()) + TemplateDeclarationDepth++; + if (!parseAngle()) { +TemplateDeclarationDepth--; return false; - if (CurrentToken) + } + TemplateDeclarationDepth--; + if (CurrentToken && + (TemplateDeclarationDepth == 0 || + !CurrentToken->isOneOf(tok::kw_typename, tok::kw_class))) { owenca wrote: Actually, checking the nesting level of the template brackets like you did is easier to understand. You just don't need to check the type-parameter keys IMO. Below is a rewrite of the function based on your solution: ```cpp $ git diff diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 958b46c535a9..9be5c09a32dd 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1266,23 +1266,22 @@ private: } bool parseTemplateDeclaration() { -if (CurrentToken && CurrentToken->is(tok::less)) { - CurrentToken->setType(TT_TemplateOpener); - next(); - TemplateDeclarationDepth++; - if (!parseAngle()) { -TemplateDeclarationDepth--; -return false; - } - TemplateDeclarationDepth--; - if (CurrentToken && - (TemplateDeclarationDepth == 0 || - !CurrentToken->isOneOf(tok::kw_typename, tok::kw_class))) { -CurrentToken->Previous->ClosesTemplateDeclaration = true; - } - return true; -} -return false; +if (!CurrentToken || CurrentToken->isNot(tok::less)) + return false; + +CurrentToken->setType(TT_TemplateOpener); +next(); + +TemplateDeclarationDepth++; +const bool WellFormed = parseAngle(); +TemplateDeclarationDepth--; +if (!WellFormed) + return false; + +if (CurrentToken && TemplateDeclarationDepth == 0) + CurrentToken->Previous->ClosesTemplateDeclaration = true; + +return true; } bool consumeToken() { $ ``` https://github.com/llvm/llvm-project/pull/95025 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][NFC] Avoid opening namespace std (PR #95470)
https://github.com/steakhal approved this pull request. LGTM. Please make clang format happy before merging. https://github.com/llvm/llvm-project/pull/95470 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][modules] HeaderSearch::MarkFileModuleHeader sets textual headers' HeaderFileInfo non-external when it shouldn't (PR #89005)
https://github.com/ian-twilightcoder updated https://github.com/llvm/llvm-project/pull/89005 >From eb296a4e28e54971f6e90e2fe4543ead4c7c2dbb Mon Sep 17 00:00:00 2001 From: Ian Anderson Date: Tue, 16 Apr 2024 17:08:28 -0700 Subject: [PATCH] [clang][modules] HeaderSearch::MarkFileModuleHeader sets textual headers' HeaderFileInfo non-external when it shouldn't HeaderSearch::MarkFileModuleHeader is no longer properly checking for no-changes, and so sets the HeaderFileInfo for every `textual header` to non-external. --- clang/include/clang/Lex/HeaderSearch.h | 4 +- clang/lib/Lex/HeaderSearch.cpp | 14 +++-- clang/unittests/Lex/HeaderSearchTest.cpp | 68 3 files changed, 82 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/Lex/HeaderSearch.h b/clang/include/clang/Lex/HeaderSearch.h index 5ac634d4e..d8ca1c528de36 100644 --- a/clang/include/clang/Lex/HeaderSearch.h +++ b/clang/include/clang/Lex/HeaderSearch.h @@ -90,7 +90,9 @@ struct HeaderFileInfo { LLVM_PREFERRED_TYPE(bool) unsigned isModuleHeader : 1; - /// Whether this header is a `textual header` in a module. + /// Whether this header is a `textual header` in a module. If a header is + /// textual in one module and normal in another module, this bit will not be + /// set, only `isModuleHeader`. LLVM_PREFERRED_TYPE(bool) unsigned isTextualModuleHeader : 1; diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp index 574723b33866a..18c0bab4a81e4 100644 --- a/clang/lib/Lex/HeaderSearch.cpp +++ b/clang/lib/Lex/HeaderSearch.cpp @@ -1313,11 +1313,19 @@ OptionalFileEntryRef HeaderSearch::LookupSubframeworkHeader( // File Info Management. //===--===// +static bool moduleMembershipNeedsMerge(const HeaderFileInfo *HFI, + ModuleMap::ModuleHeaderRole Role) { + if (ModuleMap::isModular(Role)) +return !HFI->isModuleHeader || HFI->isTextualModuleHeader; + else if (!HFI->isModuleHeader && (Role & ModuleMap::TextualHeader)) +return !HFI->isTextualModuleHeader; + else +return false; +} + static void mergeHeaderFileInfoModuleBits(HeaderFileInfo , bool isModuleHeader, bool isTextualModuleHeader) { - assert((!isModuleHeader || !isTextualModuleHeader) && - "A header can't build with a module and be textual at the same time"); HFI.isModuleHeader |= isModuleHeader; if (HFI.isModuleHeader) HFI.isTextualModuleHeader = false; @@ -1432,7 +1440,7 @@ void HeaderSearch::MarkFileModuleHeader(FileEntryRef FE, if ((Role & ModuleMap::ExcludedHeader)) return; auto *HFI = getExistingFileInfo(FE); -if (HFI && HFI->isModuleHeader) +if (HFI && !moduleMembershipNeedsMerge(HFI, Role)) return; } diff --git a/clang/unittests/Lex/HeaderSearchTest.cpp b/clang/unittests/Lex/HeaderSearchTest.cpp index c578fa72c859e..23d0cf7789392 100644 --- a/clang/unittests/Lex/HeaderSearchTest.cpp +++ b/clang/unittests/Lex/HeaderSearchTest.cpp @@ -308,5 +308,73 @@ TEST_F(HeaderSearchTest, HeaderMapFrameworkLookup) { EXPECT_EQ(Search.getIncludeNameForHeader(FE), "Foo/Foo.h"); } +TEST_F(HeaderSearchTest, HeaderFileInfoMerge) { + auto AddHeader = [&](std::string HeaderPath) -> FileEntryRef { +VFS->addFile(HeaderPath, 0, + llvm::MemoryBuffer::getMemBufferCopy("", HeaderPath), + /*User=*/std::nullopt, /*Group=*/std::nullopt, + llvm::sys::fs::file_type::regular_file); +return *FileMgr.getOptionalFileRef(HeaderPath); + }; + + class MockExternalHeaderFileInfoSource : public ExternalHeaderFileInfoSource { +HeaderFileInfo GetHeaderFileInfo(FileEntryRef FE) { + HeaderFileInfo HFI; + auto FileName = FE.getName(); + if (FileName == ModularPath) +HFI.mergeModuleMembership(ModuleMap::NormalHeader); + else if (FileName == TextualPath) +HFI.mergeModuleMembership(ModuleMap::TextualHeader); + HFI.External = true; + HFI.IsValid = true; + return HFI; +} + + public: +std::string ModularPath = "/modular.h"; +std::string TextualPath = "/textual.h"; + }; + + auto ExternalSource = new MockExternalHeaderFileInfoSource(); + Search.SetExternalSource(ExternalSource); + + // Everything should start out external. + auto ModularFE = AddHeader(ExternalSource->ModularPath); + auto TextualFE = AddHeader(ExternalSource->TextualPath); + EXPECT_TRUE(Search.getExistingFileInfo(ModularFE)->External); + EXPECT_TRUE(Search.getExistingFileInfo(TextualFE)->External); + + // Marking the same role should keep it external + Search.MarkFileModuleHeader(ModularFE, ModuleMap::NormalHeader, + /*isCompilingModuleHeader=*/false); + Search.MarkFileModuleHeader(TextualFE, ModuleMap::TextualHeader, +
[clang] [clang][modules] HeaderSearch::MarkFileModuleHeader sets textual headers' HeaderFileInfo non-external when it shouldn't (PR #89005)
https://github.com/ian-twilightcoder updated https://github.com/llvm/llvm-project/pull/89005 >From bdb35190d9873e4413863be1bba842cb202842fc Mon Sep 17 00:00:00 2001 From: Ian Anderson Date: Tue, 16 Apr 2024 17:08:28 -0700 Subject: [PATCH] [clang][modules] HeaderSearch::MarkFileModuleHeader sets textual headers' HeaderFileInfo non-external when it shouldn't HeaderSearch::MarkFileModuleHeader is no longer properly checking for no-changes, and so sets the HeaderFileInfo for every `textual header` to non-external. --- clang/include/clang/Lex/HeaderSearch.h | 4 +- clang/lib/Lex/HeaderSearch.cpp | 14 - clang/unittests/Lex/HeaderSearchTest.cpp | 77 3 files changed, 91 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/Lex/HeaderSearch.h b/clang/include/clang/Lex/HeaderSearch.h index 5ac634d4e..d8ca1c528de36 100644 --- a/clang/include/clang/Lex/HeaderSearch.h +++ b/clang/include/clang/Lex/HeaderSearch.h @@ -90,7 +90,9 @@ struct HeaderFileInfo { LLVM_PREFERRED_TYPE(bool) unsigned isModuleHeader : 1; - /// Whether this header is a `textual header` in a module. + /// Whether this header is a `textual header` in a module. If a header is + /// textual in one module and normal in another module, this bit will not be + /// set, only `isModuleHeader`. LLVM_PREFERRED_TYPE(bool) unsigned isTextualModuleHeader : 1; diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp index 574723b33866a..18c0bab4a81e4 100644 --- a/clang/lib/Lex/HeaderSearch.cpp +++ b/clang/lib/Lex/HeaderSearch.cpp @@ -1313,11 +1313,19 @@ OptionalFileEntryRef HeaderSearch::LookupSubframeworkHeader( // File Info Management. //===--===// +static bool moduleMembershipNeedsMerge(const HeaderFileInfo *HFI, + ModuleMap::ModuleHeaderRole Role) { + if (ModuleMap::isModular(Role)) +return !HFI->isModuleHeader || HFI->isTextualModuleHeader; + else if (!HFI->isModuleHeader && (Role & ModuleMap::TextualHeader)) +return !HFI->isTextualModuleHeader; + else +return false; +} + static void mergeHeaderFileInfoModuleBits(HeaderFileInfo , bool isModuleHeader, bool isTextualModuleHeader) { - assert((!isModuleHeader || !isTextualModuleHeader) && - "A header can't build with a module and be textual at the same time"); HFI.isModuleHeader |= isModuleHeader; if (HFI.isModuleHeader) HFI.isTextualModuleHeader = false; @@ -1432,7 +1440,7 @@ void HeaderSearch::MarkFileModuleHeader(FileEntryRef FE, if ((Role & ModuleMap::ExcludedHeader)) return; auto *HFI = getExistingFileInfo(FE); -if (HFI && HFI->isModuleHeader) +if (HFI && !moduleMembershipNeedsMerge(HFI, Role)) return; } diff --git a/clang/unittests/Lex/HeaderSearchTest.cpp b/clang/unittests/Lex/HeaderSearchTest.cpp index c578fa72c859e..ac1359746668a 100644 --- a/clang/unittests/Lex/HeaderSearchTest.cpp +++ b/clang/unittests/Lex/HeaderSearchTest.cpp @@ -308,5 +308,82 @@ TEST_F(HeaderSearchTest, HeaderMapFrameworkLookup) { EXPECT_EQ(Search.getIncludeNameForHeader(FE), "Foo/Foo.h"); } +TEST_F(HeaderSearchTest, HeaderFileInfoMerge) { + auto AddHeader = [&](std::string HeaderPath) -> FileEntryRef { +VFS->addFile(HeaderPath, 0, + llvm::MemoryBuffer::getMemBufferCopy("", HeaderPath), + /*User=*/std::nullopt, /*Group=*/std::nullopt, + llvm::sys::fs::file_type::regular_file); +return *Search.LookupFile( +HeaderPath, SourceLocation(), /*isAngled=*/false, /*FromDir=*/nullptr, +/*CurDir=*/nullptr, /*Includers=*/{}, /*SearchPath=*/nullptr, +/*RelativePath=*/nullptr, /*RequestingModule=*/nullptr, +/*SuggestedModule=*/nullptr, /*IsMapped=*/nullptr, +/*IsFrameworkFound=*/nullptr); + }; + + class MockExternalHeaderFileInfoSource : public ExternalHeaderFileInfoSource { +HeaderFileInfo GetHeaderFileInfo(FileEntryRef FE) { + HeaderFileInfo HFI; + auto FileName = FE.getName(); + if (FileName == ModularPath) +HFI.mergeModuleMembership(ModuleMap::NormalHeader); + else if (FileName == TextualPath) +HFI.mergeModuleMembership(ModuleMap::TextualHeader); + HFI.External = true; + HFI.IsValid = true; + return HFI; +} + + public: +std::string ModularPath = is_style_windows(llvm::sys::path::Style::native) + ? "C:/modular.h" + : "/modular.h"; +std::string TextualPath = is_style_windows(llvm::sys::path::Style::native) + ? "C:/textual.h" + : "/textual.h"; + }; + + auto ExternalSource = new MockExternalHeaderFileInfoSource(); + Search.SetExternalSource(ExternalSource); + + //
[clang] [clang][ARM] Fix warning for VFP function calls from interrupts. (PR #91870)
chrisnc wrote: While doing some more research and comparing `gcc` and `clang`, I noticed that `clang` doesn't even save the volatile fp registers in an interrupt handler when it uses them directly, so there's no point in just checking for function calls. `gcc` does except for `fpscr`, which it will still clobber if floating-point conditionals are computed. Maybe the behavior was different when this warning was introduced, but as of now, using fp at all in an interrupt handler will clobber vfp state, so I think the right path here is to just implement `-Wattributes` in essentially the same way `gcc` does... https://github.com/llvm/llvm-project/pull/91870 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Handle AttributeMacro before access modifiers (PR #95503)
llvmbot wrote: @llvm/pr-subscribers-clang-format Author: Owen Pan (owenca) Changes Closes #95094. --- Full diff: https://github.com/llvm/llvm-project/pull/95503.diff 2 Files Affected: - (modified) clang/lib/Format/UnwrappedLineFormatter.cpp (+4-1) - (modified) clang/unittests/Format/FormatTest.cpp (+15) ``diff diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp index 4d53361aaf333..80ab9827b050c 100644 --- a/clang/lib/Format/UnwrappedLineFormatter.cpp +++ b/clang/lib/Format/UnwrappedLineFormatter.cpp @@ -57,7 +57,10 @@ class LevelIndentTracker { /// Update the indent state given that \p Line is going to be formatted /// next. void nextLine(const AnnotatedLine ) { -Offset = getIndentOffset(*Line.First); +const auto *Tok = Line.First; +if (Tok->is(TT_AttributeMacro) && Tok->Next) + Tok = Tok->Next; +Offset = getIndentOffset(*Tok); // Update the indent level cache size so that we can rely on it // having the right size in adjustToUnmodifiedline. if (Line.Level >= IndentForLevel.size()) diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index fb57333858529..2ca85c7b70e65 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -12912,6 +12912,15 @@ TEST_F(FormatTest, FormatsAccessModifiers) { " int j;\n" "};", Style); + Style.AttributeMacros.push_back("FOO"); + Style.AttributeMacros.push_back("BAR"); + verifyFormat("struct foo {\n" + "FOO private:\n" + " int i;\n" + "BAR private:\n" + " int j;\n" + "};", + Style); FormatStyle NoEmptyLines = getLLVMStyle(); NoEmptyLines.MaxEmptyLinesToKeep = 0; @@ -26130,6 +26139,12 @@ TEST_F(FormatTest, IndentAccessModifiers) { " int i;\n" "};", Style); + Style.AttributeMacros.push_back("FOO"); + verifyFormat("class C {\n" + " FOO public:\n" + " int i;\n" + "};", + Style); } TEST_F(FormatTest, LimitlessStringsAndComments) { `` https://github.com/llvm/llvm-project/pull/95503 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Handle AttributeMacro before access modifiers (PR #95503)
https://github.com/owenca created https://github.com/llvm/llvm-project/pull/95503 Closes #95094. >From 6684ed759ce118bb28e9da22be51bcfece2a1909 Mon Sep 17 00:00:00 2001 From: Owen Pan Date: Thu, 13 Jun 2024 21:25:08 -0700 Subject: [PATCH] [clang-format] Handle AttributeMacro before access modifiers Closes #95094. --- clang/lib/Format/UnwrappedLineFormatter.cpp | 5 - clang/unittests/Format/FormatTest.cpp | 15 +++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp index 4d53361aaf333..80ab9827b050c 100644 --- a/clang/lib/Format/UnwrappedLineFormatter.cpp +++ b/clang/lib/Format/UnwrappedLineFormatter.cpp @@ -57,7 +57,10 @@ class LevelIndentTracker { /// Update the indent state given that \p Line is going to be formatted /// next. void nextLine(const AnnotatedLine ) { -Offset = getIndentOffset(*Line.First); +const auto *Tok = Line.First; +if (Tok->is(TT_AttributeMacro) && Tok->Next) + Tok = Tok->Next; +Offset = getIndentOffset(*Tok); // Update the indent level cache size so that we can rely on it // having the right size in adjustToUnmodifiedline. if (Line.Level >= IndentForLevel.size()) diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index fb57333858529..2ca85c7b70e65 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -12912,6 +12912,15 @@ TEST_F(FormatTest, FormatsAccessModifiers) { " int j;\n" "};", Style); + Style.AttributeMacros.push_back("FOO"); + Style.AttributeMacros.push_back("BAR"); + verifyFormat("struct foo {\n" + "FOO private:\n" + " int i;\n" + "BAR private:\n" + " int j;\n" + "};", + Style); FormatStyle NoEmptyLines = getLLVMStyle(); NoEmptyLines.MaxEmptyLinesToKeep = 0; @@ -26130,6 +26139,12 @@ TEST_F(FormatTest, IndentAccessModifiers) { " int i;\n" "};", Style); + Style.AttributeMacros.push_back("FOO"); + verifyFormat("class C {\n" + " FOO public:\n" + " int i;\n" + "};", + Style); } TEST_F(FormatTest, LimitlessStringsAndComments) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Support `guarded_by` attribute and related attributes inside C structs and support late parsing them (PR #95455)
@@ -3330,6 +3340,118 @@ void Parser::DistributeCLateParsedAttrs(Decl *Dcl, } } +/// GuardedBy attributes (e.g., guarded_by): +/// AttrName '(' expression ')' +void Parser::ParseGuardedByAttribute( +IdentifierInfo , SourceLocation AttrNameLoc, +ParsedAttributes , IdentifierInfo *ScopeName, SourceLocation ScopeLoc, +SourceLocation *EndLoc, ParsedAttr::Form Form) { + assert(Tok.is(tok::l_paren) && "Attribute arg list not starting with '('"); + + BalancedDelimiterTracker Parens(*this, tok::l_paren); + Parens.consumeOpen(); + + if (Tok.is(tok::r_paren)) { +Diag(Tok.getLocation(), diag::err_argument_required_after_attribute); +Parens.consumeClose(); +return; + } + + ArgsVector ArgExprs; + // Don't evaluate argument when the attribute is ignored. + using ExpressionKind = + Sema::ExpressionEvaluationContextRecord::ExpressionKind; + EnterExpressionEvaluationContext EC( + Actions, + getLangOpts().CPlusPlus + ? Sema::ExpressionEvaluationContext::Unevaluated + : Sema::ExpressionEvaluationContext::PotentiallyEvaluated, hnrklssn wrote: Why does C need to parse using `PotentiallyEvaluated` while C++ needs `Unevaluated`? What happens if we parse using `Unevaluted` in C? https://github.com/llvm/llvm-project/pull/95455 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Fuchsia] Use unsigned int for wint_t on *-fuchsia targets (PR #95499)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Roland McGrath (frobtech) Changes This aligns Fuchsia targets with other similar OS targets such as Linux. Fuchsia's libc already uses unsigned rather than the compiler-provided __WINT_TYPE__ macro for its wint_t typedef, so this just makes the compiler consistent with the OS's actual ABI. The only known manifestation of the mismatch is -Wformat warnings for %lc no matching wint_t arguments. The closest thing I could see to existing tests for each target's wint_t type setting was the predefine tests that check various macros including __WINT_TYPE__ on a per-machine and/or per-OS basis. While the setting is done per-OS in most of the target implementations rather than actually varying by machine, the only existing tests for __WINT_TYPE__ are in per-machine checks that are also wholly or partly tagged as per-OS. x86_64 and riscv64 tests for respective *-linux-gnu targets now check for the same definitions in the respective *-fuchsia targets. __WINT_TYPE__ is not among the type checked in the aarch64 tests and those lack a section that's specifically tested for aarch64-linux-gnu; if such is added then it can similarly be made to check for most or all of the same value on aarch64-fuchsia as aarch64-linux-gnu. But since the actual implementation of choosing the type is done per-OS and not per-machine for the three machines with Fuchsia target support, the x86 and riscv64 tests are already redundantly testing that same code and seem sufficient. --- Full diff: https://github.com/llvm/llvm-project/pull/95499.diff 3 Files Affected: - (modified) clang/lib/Basic/Targets/OSTargets.h (+1) - (modified) clang/test/Preprocessor/init-x86.c (+1) - (modified) clang/test/Preprocessor/init.c (+2) ``diff diff --git a/clang/lib/Basic/Targets/OSTargets.h b/clang/lib/Basic/Targets/OSTargets.h index 4366c1149e405..5f27c3469f861 100644 --- a/clang/lib/Basic/Targets/OSTargets.h +++ b/clang/lib/Basic/Targets/OSTargets.h @@ -868,6 +868,7 @@ class LLVM_LIBRARY_VISIBILITY FuchsiaTargetInfo : public OSTargetInfo { public: FuchsiaTargetInfo(const llvm::Triple , const TargetOptions ) : OSTargetInfo(Triple, Opts) { +this->WIntType = TargetInfo::UnsignedInt; this->MCountName = "__mcount"; this->TheCXXABI.set(TargetCXXABI::Fuchsia); } diff --git a/clang/test/Preprocessor/init-x86.c b/clang/test/Preprocessor/init-x86.c index 1268419e18a5c..6f5aa5674e48e 100644 --- a/clang/test/Preprocessor/init-x86.c +++ b/clang/test/Preprocessor/init-x86.c @@ -999,6 +999,7 @@ // X32:#define __x86_64__ 1 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=x86_64-pc-linux-gnu < /dev/null | FileCheck -match-full-lines -check-prefix X86_64-LINUX %s +// RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=x86_64-unknown-fuchsia < /dev/null | FileCheck -match-full-lines -check-prefix X86_64-LINUX %s // // X86_64-LINUX:#define _LP64 1 // X86_64-LINUX:#define __BIGGEST_ALIGNMENT__ 16 diff --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c index 2641fee940231..6e7c0ea5c730b 100644 --- a/clang/test/Preprocessor/init.c +++ b/clang/test/Preprocessor/init.c @@ -2527,6 +2527,8 @@ // RUN: | FileCheck -match-full-lines -check-prefix=RISCV64 %s // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=riscv64-unknown-linux < /dev/null \ // RUN: | FileCheck -match-full-lines -check-prefixes=RISCV64,RISCV64-LINUX %s +// RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=riscv64-unknown-fuchsia < /dev/null \ +// RUN: | FileCheck -match-full-lines -check-prefixes=RISCV64 %s // RISCV64: #define _LP64 1 // RISCV64: #define __ATOMIC_ACQUIRE 2 // RISCV64: #define __ATOMIC_ACQ_REL 4 `` https://github.com/llvm/llvm-project/pull/95499 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Fuchsia] Use unsigned int for wint_t on *-fuchsia targets (PR #95499)
https://github.com/frobtech ready_for_review https://github.com/llvm/llvm-project/pull/95499 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Fuchsia] Use unsigned int for wint_t on *-fuchsia targets (PR #95499)
https://github.com/frobtech updated https://github.com/llvm/llvm-project/pull/95499 >From c4e8968197c401f03baaed904d07a5ce77c19ace Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Thu, 13 Jun 2024 20:25:24 -0700 Subject: [PATCH] [clang][Fuchsia] Use unsigned int for wint_t on *-fuchsia targets This aligns Fuchsia targets with other similar OS targets such as Linux. Fuchsia's libc already uses unsigned rather than the compiler-provided __WINT_TYPE__ macro for its wint_t typedef, so this just makes the compiler consistent with the OS's actual ABI. The only known manifestation of the mismatch is -Wformat warnings for %lc no matching wint_t arguments. The closest thing I could see to existing tests for each target's wint_t type setting was the predefine tests that check various macros including __WINT_TYPE__ on a per-machine and/or per-OS basis. While the setting is done per-OS in most of the target implementations rather than actually varying by machine, the only existing tests for __WINT_TYPE__ are in per-machine checks that are also wholly or partly tagged as per-OS. x86_64 and riscv64 tests for respective *-linux-gnu targets now check for the same definitions in the respective *-fuchsia targets. __WINT_TYPE__ is not among the type checked in the aarch64 tests and those lack a section that's specifically tested for aarch64-linux-gnu; if such is added then it can similarly be made to check for most or all of the same value on aarch64-fuchsia as aarch64-linux-gnu. But since the actual implementation of choosing the type is done per-OS and not per-machine for the three machines with Fuchsia target support, the x86 and riscv64 tests are already redundantly testing that same code and seem sufficient. --- clang/lib/Basic/Targets/OSTargets.h | 1 + clang/test/Preprocessor/init-x86.c | 1 + clang/test/Preprocessor/init.c | 2 ++ 3 files changed, 4 insertions(+) diff --git a/clang/lib/Basic/Targets/OSTargets.h b/clang/lib/Basic/Targets/OSTargets.h index 4366c1149e405..5f27c3469f861 100644 --- a/clang/lib/Basic/Targets/OSTargets.h +++ b/clang/lib/Basic/Targets/OSTargets.h @@ -868,6 +868,7 @@ class LLVM_LIBRARY_VISIBILITY FuchsiaTargetInfo : public OSTargetInfo { public: FuchsiaTargetInfo(const llvm::Triple , const TargetOptions ) : OSTargetInfo(Triple, Opts) { +this->WIntType = TargetInfo::UnsignedInt; this->MCountName = "__mcount"; this->TheCXXABI.set(TargetCXXABI::Fuchsia); } diff --git a/clang/test/Preprocessor/init-x86.c b/clang/test/Preprocessor/init-x86.c index 1268419e18a5c..6f5aa5674e48e 100644 --- a/clang/test/Preprocessor/init-x86.c +++ b/clang/test/Preprocessor/init-x86.c @@ -999,6 +999,7 @@ // X32:#define __x86_64__ 1 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=x86_64-pc-linux-gnu < /dev/null | FileCheck -match-full-lines -check-prefix X86_64-LINUX %s +// RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=x86_64-unknown-fuchsia < /dev/null | FileCheck -match-full-lines -check-prefix X86_64-LINUX %s // // X86_64-LINUX:#define _LP64 1 // X86_64-LINUX:#define __BIGGEST_ALIGNMENT__ 16 diff --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c index 2641fee940231..6e7c0ea5c730b 100644 --- a/clang/test/Preprocessor/init.c +++ b/clang/test/Preprocessor/init.c @@ -2527,6 +2527,8 @@ // RUN: | FileCheck -match-full-lines -check-prefix=RISCV64 %s // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=riscv64-unknown-linux < /dev/null \ // RUN: | FileCheck -match-full-lines -check-prefixes=RISCV64,RISCV64-LINUX %s +// RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=riscv64-unknown-fuchsia < /dev/null \ +// RUN: | FileCheck -match-full-lines -check-prefixes=RISCV64 %s // RISCV64: #define _LP64 1 // RISCV64: #define __ATOMIC_ACQUIRE 2 // RISCV64: #define __ATOMIC_ACQ_REL 4 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Fuchsia] Use unsigned int for wint_t on *-fuchsia targets (PR #95499)
https://github.com/frobtech created https://github.com/llvm/llvm-project/pull/95499 This aligns Fuchsia targets with other similar OS targets such as Linux. Fuchsia's libc already uses unsigned rather than the compiler-provided __WINT_TYPE__ macro for its wint_t typedef, so this just makes the compiler consistent with the OS's actual ABI. The only known manifestation of the mismatch is -Wformat warnings for %lc no matching wint_t arguments. The closest thing I could see to existing tests for each target's wint_t type setting was the predefine tests that check various macros including __WINT_TYPE__ on a per-machine and/or per-OS basis. While the setting is done per-OS in most of the target implementations rather than actually varying by machine, the only existing tests for __WINT_TYPE__ are in per-machine checks that are also wholly or partly tagged as per-OS. x86_64 and riscv64 tests for respective *-linux-gnu targets now check for the same definitions in the respective *-fuchsia targets. __WINT_TYPE__ is not among the type checked in the aarch64 tests and those lack a section that's specifically tested for aarch64-linux-gnu; if such is added then it can similarly be made to check for most or all of the same value on aarch64-fuchsia as aarch64-linux-gnu. But since the actual implementation of choosing the type is done per-OS and not per-machine for the three machines with Fuchsia target support, the x86 and riscv64 tests are already redundantly testing that same code and seem sufficient. >From c4e8968197c401f03baaed904d07a5ce77c19ace Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Thu, 13 Jun 2024 20:25:24 -0700 Subject: [PATCH] [clang][Fuchsia] Use unsigned int for wint_t on *-fuchsia targets This aligns Fuchsia targets with other similar OS targets such as Linux. Fuchsia's libc already uses unsigned rather than the compiler-provided __WINT_TYPE__ macro for its wint_t typedef, so this just makes the compiler consistent with the OS's actual ABI. The only known manifestation of the mismatch is -Wformat warnings for %lc no matching wint_t arguments. The closest thing I could see to existing tests for each target's wint_t type setting was the predefine tests that check various macros including __WINT_TYPE__ on a per-machine and/or per-OS basis. While the setting is done per-OS in most of the target implementations rather than actually varying by machine, the only existing tests for __WINT_TYPE__ are in per-machine checks that are also wholly or partly tagged as per-OS. x86_64 and riscv64 tests for respective *-linux-gnu targets now check for the same definitions in the respective *-fuchsia targets. __WINT_TYPE__ is not among the type checked in the aarch64 tests and those lack a section that's specifically tested for aarch64-linux-gnu; if such is added then it can similarly be made to check for most or all of the same value on aarch64-fuchsia as aarch64-linux-gnu. But since the actual implementation of choosing the type is done per-OS and not per-machine for the three machines with Fuchsia target support, the x86 and riscv64 tests are already redundantly testing that same code and seem sufficient. --- clang/lib/Basic/Targets/OSTargets.h | 1 + clang/test/Preprocessor/init-x86.c | 1 + clang/test/Preprocessor/init.c | 2 ++ 3 files changed, 4 insertions(+) diff --git a/clang/lib/Basic/Targets/OSTargets.h b/clang/lib/Basic/Targets/OSTargets.h index 4366c1149e405..5f27c3469f861 100644 --- a/clang/lib/Basic/Targets/OSTargets.h +++ b/clang/lib/Basic/Targets/OSTargets.h @@ -868,6 +868,7 @@ class LLVM_LIBRARY_VISIBILITY FuchsiaTargetInfo : public OSTargetInfo { public: FuchsiaTargetInfo(const llvm::Triple , const TargetOptions ) : OSTargetInfo(Triple, Opts) { +this->WIntType = TargetInfo::UnsignedInt; this->MCountName = "__mcount"; this->TheCXXABI.set(TargetCXXABI::Fuchsia); } diff --git a/clang/test/Preprocessor/init-x86.c b/clang/test/Preprocessor/init-x86.c index 1268419e18a5c..6f5aa5674e48e 100644 --- a/clang/test/Preprocessor/init-x86.c +++ b/clang/test/Preprocessor/init-x86.c @@ -999,6 +999,7 @@ // X32:#define __x86_64__ 1 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=x86_64-pc-linux-gnu < /dev/null | FileCheck -match-full-lines -check-prefix X86_64-LINUX %s +// RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=x86_64-unknown-fuchsia < /dev/null | FileCheck -match-full-lines -check-prefix X86_64-LINUX %s // // X86_64-LINUX:#define _LP64 1 // X86_64-LINUX:#define __BIGGEST_ALIGNMENT__ 16 diff --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c index 2641fee940231..6e7c0ea5c730b 100644 --- a/clang/test/Preprocessor/init.c +++ b/clang/test/Preprocessor/init.c @@ -2527,6 +2527,8 @@ // RUN: | FileCheck -match-full-lines -check-prefix=RISCV64 %s // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=riscv64-unknown-linux < /dev/null \ // RUN: | FileCheck
[clang] [llvm] [C++23] [CLANG] Adding C++23 constexpr math functions: fmin, fmax and frexp. (PR #88978)
hubert-reinterpretcast wrote: > All the LIT tests failing are due to the latest changes I made. I will edit > them once I know that the latest implementation is correct. Thanks. I may be delayed in reviewing this as the C++ committee meeting is the week after next. https://github.com/llvm/llvm-project/pull/88978 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [InstCombine] Add multi-use tests for shift-of-shift transform (NFC) (PR #95497)
https://github.com/frobtech closed https://github.com/llvm/llvm-project/pull/95497 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [InstCombine] Add multi-use tests for shift-of-shift transform (NFC) (PR #95497)
https://github.com/frobtech created https://github.com/llvm/llvm-project/pull/95497 Also drop irrelevant function attributes from tests. >From c4e8968197c401f03baaed904d07a5ce77c19ace Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Thu, 13 Jun 2024 20:25:24 -0700 Subject: [PATCH] [clang][Fuchsia] Use unsigned int for wint_t on *-fuchsia targets This aligns Fuchsia targets with other similar OS targets such as Linux. Fuchsia's libc already uses unsigned rather than the compiler-provided __WINT_TYPE__ macro for its wint_t typedef, so this just makes the compiler consistent with the OS's actual ABI. The only known manifestation of the mismatch is -Wformat warnings for %lc no matching wint_t arguments. The closest thing I could see to existing tests for each target's wint_t type setting was the predefine tests that check various macros including __WINT_TYPE__ on a per-machine and/or per-OS basis. While the setting is done per-OS in most of the target implementations rather than actually varying by machine, the only existing tests for __WINT_TYPE__ are in per-machine checks that are also wholly or partly tagged as per-OS. x86_64 and riscv64 tests for respective *-linux-gnu targets now check for the same definitions in the respective *-fuchsia targets. __WINT_TYPE__ is not among the type checked in the aarch64 tests and those lack a section that's specifically tested for aarch64-linux-gnu; if such is added then it can similarly be made to check for most or all of the same value on aarch64-fuchsia as aarch64-linux-gnu. But since the actual implementation of choosing the type is done per-OS and not per-machine for the three machines with Fuchsia target support, the x86 and riscv64 tests are already redundantly testing that same code and seem sufficient. --- clang/lib/Basic/Targets/OSTargets.h | 1 + clang/test/Preprocessor/init-x86.c | 1 + clang/test/Preprocessor/init.c | 2 ++ 3 files changed, 4 insertions(+) diff --git a/clang/lib/Basic/Targets/OSTargets.h b/clang/lib/Basic/Targets/OSTargets.h index 4366c1149e405..5f27c3469f861 100644 --- a/clang/lib/Basic/Targets/OSTargets.h +++ b/clang/lib/Basic/Targets/OSTargets.h @@ -868,6 +868,7 @@ class LLVM_LIBRARY_VISIBILITY FuchsiaTargetInfo : public OSTargetInfo { public: FuchsiaTargetInfo(const llvm::Triple , const TargetOptions ) : OSTargetInfo(Triple, Opts) { +this->WIntType = TargetInfo::UnsignedInt; this->MCountName = "__mcount"; this->TheCXXABI.set(TargetCXXABI::Fuchsia); } diff --git a/clang/test/Preprocessor/init-x86.c b/clang/test/Preprocessor/init-x86.c index 1268419e18a5c..6f5aa5674e48e 100644 --- a/clang/test/Preprocessor/init-x86.c +++ b/clang/test/Preprocessor/init-x86.c @@ -999,6 +999,7 @@ // X32:#define __x86_64__ 1 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=x86_64-pc-linux-gnu < /dev/null | FileCheck -match-full-lines -check-prefix X86_64-LINUX %s +// RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=x86_64-unknown-fuchsia < /dev/null | FileCheck -match-full-lines -check-prefix X86_64-LINUX %s // // X86_64-LINUX:#define _LP64 1 // X86_64-LINUX:#define __BIGGEST_ALIGNMENT__ 16 diff --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c index 2641fee940231..6e7c0ea5c730b 100644 --- a/clang/test/Preprocessor/init.c +++ b/clang/test/Preprocessor/init.c @@ -2527,6 +2527,8 @@ // RUN: | FileCheck -match-full-lines -check-prefix=RISCV64 %s // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=riscv64-unknown-linux < /dev/null \ // RUN: | FileCheck -match-full-lines -check-prefixes=RISCV64,RISCV64-LINUX %s +// RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=riscv64-unknown-fuchsia < /dev/null \ +// RUN: | FileCheck -match-full-lines -check-prefixes=RISCV64 %s // RISCV64: #define _LP64 1 // RISCV64: #define __ATOMIC_ACQUIRE 2 // RISCV64: #define __ATOMIC_ACQ_REL 4 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [serialization] no transitive decl change (PR #92083)
ChuanqiXu9 wrote: Thanks for the profiling data. It narrows the scope a lot. But it makes me confusing too. Since the scope is pretty narrow, we can do an analysis here: https://github.com/llvm/llvm-project/blob/a7a1195f01037e5019f671c96ef4bca9af9bb9a7/clang/lib/Serialization/MultiOnDiskHashTable.h#L145-L173 In `clang::serialization::MultiOnDiskHashTable::condense()`, only https://github.com/llvm/llvm-project/blob/a7a1195f01037e5019f671c96ef4bca9af9bb9a7/clang/lib/Serialization/MultiOnDiskHashTable.h#L160 and https://github.com/llvm/llvm-project/blob/a7a1195f01037e5019f671c96ef4bca9af9bb9a7/clang/lib/Serialization/MultiOnDiskHashTable.h#L163-L164 should be affected by this patch. Where the change in https://github.com/llvm/llvm-project/blob/a7a1195f01037e5019f671c96ef4bca9af9bb9a7/clang/lib/Serialization/MultiOnDiskHashTable.h#L160 should almost be constant since it reads the length. And for https://github.com/llvm/llvm-project/blob/a7a1195f01037e5019f671c96ef4bca9af9bb9a7/clang/lib/Serialization/MultiOnDiskHashTable.h#L163-L164, its implementation is: https://github.com/llvm/llvm-project/blob/43bd7ae65af40ff3378d5a0395a058ba834ad8dd/clang/lib/Serialization/ASTReader.cpp#L1215-L1225 For `ASTReader::getGlobalDeclID()`, the implementation is https://github.com/llvm/llvm-project/blob/43bd7ae65af40ff3378d5a0395a058ba834ad8dd/clang/lib/Serialization/ASTReader.cpp#L7623-L7644, what is almost bit operation comparing to the previous state. So it just looks like the reason is that we extend the DeclID from uint32_t to uint64_t and there are too many on-disk hash tables (not a blame). @alexfh could you try to profile on the statements level? --- BTW, I feel we may read too many times in `MultiOnDiskHashTable `, maybe we can improve this. https://github.com/llvm/llvm-project/pull/92083 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 43bd7ae - StreamChecker.cpp: Use isa<> (for #93408) [-Wunused-but-set-variable]
Author: NAKAMURA Takumi Date: 2024-06-14T12:18:41+09:00 New Revision: 43bd7ae65af40ff3378d5a0395a058ba834ad8dd URL: https://github.com/llvm/llvm-project/commit/43bd7ae65af40ff3378d5a0395a058ba834ad8dd DIFF: https://github.com/llvm/llvm-project/commit/43bd7ae65af40ff3378d5a0395a058ba834ad8dd.diff LOG: StreamChecker.cpp: Use isa<> (for #93408) [-Wunused-but-set-variable] Added: Modified: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp Removed: diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp index 74ee607849a5b..613c221de7b4c 100644 --- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp @@ -969,9 +969,9 @@ static std::optional getStartIndex(SValBuilder , if (const auto *ER = dyn_cast(R)) return ER->getIndex(); - if (const auto *TR = dyn_cast(R)) + if (isa(R)) return Zero(); - if (const auto *SR = dyn_cast(R)) + if (isa(R)) return Zero(); return std::nullopt; } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Clang][Coroutines] Improve CoroElide with [[clang::coro_structured_concurrency]] attribute for C++ (PR #94693)
https://github.com/yuxuanchen1997 edited https://github.com/llvm/llvm-project/pull/94693 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Clang] Improve CoroElide with [[clang::coro_structured_concurrency]] attribute for C++ (PR #94693)
https://github.com/yuxuanchen1997 edited https://github.com/llvm/llvm-project/pull/94693 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Clang] Introduce [[clang::coro_structured_concurrency]] (PR #94693)
https://github.com/yuxuanchen1997 edited https://github.com/llvm/llvm-project/pull/94693 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] Cleanup MC/DC intrinsics for #82448 (PR #95496)
llvmbot wrote: @llvm/pr-subscribers-pgo @llvm/pr-subscribers-llvm-transforms Author: NAKAMURA Takumi (chapuni) Changes 3rd arg of `tvbitmap.update` was made unused. Remove 3rd arg. Sweep `condbitmap.update`, since it is no longer used. --- Full diff: https://github.com/llvm/llvm-project/pull/95496.diff 9 Files Affected: - (modified) clang/lib/CodeGen/CodeGenPGO.cpp (+1-2) - (modified) clang/test/Profile/c-mcdc.c (+1-1) - (modified) llvm/docs/LangRef.rst (+2-51) - (modified) llvm/include/llvm/IR/IntrinsicInst.h (+2-33) - (modified) llvm/include/llvm/IR/Intrinsics.td (+1-6) - (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp (-2) - (modified) llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp (-35) - (modified) llvm/test/Instrumentation/InstrProfiling/mcdc.ll (+2-11) - (modified) llvm/unittests/IR/IntrinsicsTest.cpp (-3) ``diff diff --git a/clang/lib/CodeGen/CodeGenPGO.cpp b/clang/lib/CodeGen/CodeGenPGO.cpp index 59139e342de88..2839697614595 100644 --- a/clang/lib/CodeGen/CodeGenPGO.cpp +++ b/clang/lib/CodeGen/CodeGenPGO.cpp @@ -1260,9 +1260,8 @@ void CodeGenPGO::emitMCDCTestVectorBitmapUpdate(CGBuilderTy , // from a pointer to a dedicated temporary value on the stack that is itself // updated via emitMCDCCondBitmapReset() and emitMCDCCondBitmapUpdate(). The // index represents an executed test vector. - llvm::Value *Args[5] = {llvm::ConstantExpr::getBitCast(FuncNameVar, I8PtrTy), + llvm::Value *Args[4] = {llvm::ConstantExpr::getBitCast(FuncNameVar, I8PtrTy), Builder.getInt64(FunctionHash), - Builder.getInt32(0), // Unused Builder.getInt32(MCDCTestVectorBitmapOffset), MCDCCondBitmapAddr.emitRawPointer(CGF)}; Builder.CreateCall( diff --git a/clang/test/Profile/c-mcdc.c b/clang/test/Profile/c-mcdc.c index 251c18baa861d..7c1d734028364 100644 --- a/clang/test/Profile/c-mcdc.c +++ b/clang/test/Profile/c-mcdc.c @@ -82,7 +82,7 @@ int test(int a, int b, int c, int d, int e, int f) { // UPDATE FINAL BITMASK WITH RESULT. // NOPROFPASS-LABEL: lor.end: -// NOPROFPASS: call void @llvm.instrprof.mcdc.tvbitmap.update(ptr @__profn_test, i64 [[HASH]], i32 0, i32 0, ptr %mcdc.addr) +// NOPROFPASS: call void @llvm.instrprof.mcdc.tvbitmap.update(ptr @__profn_test, i64 [[HASH]], i32 0, ptr %mcdc.addr) // MCDC-DAG: %[[TEMP0:mcdc.temp[0-9]*]] = load i32, ptr %mcdc.addr, align 4 // MCDC: %[[TEMP:[0-9]+]] = add i32 %[[TEMP0]], 0 // MCDC: %[[LAB1:[0-9]+]] = lshr i32 %[[TEMP]], 3 diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst index 10d53bea149ef..a587afed6ca88 100644 --- a/llvm/docs/LangRef.rst +++ b/llvm/docs/LangRef.rst @@ -14441,52 +14441,6 @@ to generate the appropriate data structures and the code to instrument MC/DC test vectors in a format that can be written out by a compiler runtime and consumed via the ``llvm-profdata`` tool. -'``llvm.instrprof.mcdc.condbitmap.update``' Intrinsic -^ - -Syntax: -""" - -:: - - declare void @llvm.instrprof.mcdc.condbitmap.update(ptr , i64 , - i32 , - ptr , - i1 ) - -Overview: -" - -The '``llvm.instrprof.mcdc.condbitmap.update``' intrinsic is used to track -MC/DC condition evaluation for each condition in a boolean expression. - -Arguments: -"" - -The first argument is a pointer to a global variable containing the -name of the entity being instrumented. This should generally be the -(mangled) function name for a set of counters. - -The second argument is a hash value that can be used by the consumer -of the profile data to detect changes to the instrumented source. - -The third argument is an ID of a condition to track. This value is used as a -bit index into the condition bitmap. - -The fourth argument is the address of the condition bitmap. - -The fifth argument is the boolean value representing the evaluation of the -condition (true or false) - -Semantics: -"" - -This intrinsic represents the update of a condition bitmap that is local to a -function and will cause the ``-instrprof`` pass to generate the code to -instrument the control flow around each condition in a boolean expression. The -ID of each condition corresponds to a bit index in the condition bitmap which -is set based on the evaluation of the condition. - '``llvm.instrprof.mcdc.tvbitmap.update``' Intrinsic ^^^ @@ -14496,7 +14450,6 @@ Syntax: :: declare void @llvm.instrprof.mcdc.tvbitmap.update(ptr , i64 , -i32 ) i32 , ptr ) @@ -14520,12 +14473,10 @@
[clang] [llvm] Cleanup MC/DC intrinsics for #82448 (PR #95496)
https://github.com/chapuni created https://github.com/llvm/llvm-project/pull/95496 3rd arg of `tvbitmap.update` was made unused. Remove 3rd arg. Sweep `condbitmap.update`, since it is no longer used. >From 80e4ff0501e6ba4c30bd94faec03ba3dcd2ad4ee Mon Sep 17 00:00:00 2001 From: NAKAMURA Takumi Date: Thu, 13 Jun 2024 20:28:22 +0900 Subject: [PATCH] Cleanup MC/DC intrinsics for #82448 3rd arg of `tvbitmap.update` was made unused. Remove 3rd arg. Sweep `condbitmap.update`, since it is no longer used. --- clang/lib/CodeGen/CodeGenPGO.cpp | 3 +- clang/test/Profile/c-mcdc.c | 2 +- llvm/docs/LangRef.rst | 53 +-- llvm/include/llvm/IR/IntrinsicInst.h | 35 +--- llvm/include/llvm/IR/Intrinsics.td| 7 +-- .../SelectionDAG/SelectionDAGBuilder.cpp | 2 - .../Instrumentation/InstrProfiling.cpp| 35 .../Instrumentation/InstrProfiling/mcdc.ll| 13 + llvm/unittests/IR/IntrinsicsTest.cpp | 3 -- 9 files changed, 9 insertions(+), 144 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenPGO.cpp b/clang/lib/CodeGen/CodeGenPGO.cpp index 59139e342de88..2839697614595 100644 --- a/clang/lib/CodeGen/CodeGenPGO.cpp +++ b/clang/lib/CodeGen/CodeGenPGO.cpp @@ -1260,9 +1260,8 @@ void CodeGenPGO::emitMCDCTestVectorBitmapUpdate(CGBuilderTy , // from a pointer to a dedicated temporary value on the stack that is itself // updated via emitMCDCCondBitmapReset() and emitMCDCCondBitmapUpdate(). The // index represents an executed test vector. - llvm::Value *Args[5] = {llvm::ConstantExpr::getBitCast(FuncNameVar, I8PtrTy), + llvm::Value *Args[4] = {llvm::ConstantExpr::getBitCast(FuncNameVar, I8PtrTy), Builder.getInt64(FunctionHash), - Builder.getInt32(0), // Unused Builder.getInt32(MCDCTestVectorBitmapOffset), MCDCCondBitmapAddr.emitRawPointer(CGF)}; Builder.CreateCall( diff --git a/clang/test/Profile/c-mcdc.c b/clang/test/Profile/c-mcdc.c index 251c18baa861d..7c1d734028364 100644 --- a/clang/test/Profile/c-mcdc.c +++ b/clang/test/Profile/c-mcdc.c @@ -82,7 +82,7 @@ int test(int a, int b, int c, int d, int e, int f) { // UPDATE FINAL BITMASK WITH RESULT. // NOPROFPASS-LABEL: lor.end: -// NOPROFPASS: call void @llvm.instrprof.mcdc.tvbitmap.update(ptr @__profn_test, i64 [[HASH]], i32 0, i32 0, ptr %mcdc.addr) +// NOPROFPASS: call void @llvm.instrprof.mcdc.tvbitmap.update(ptr @__profn_test, i64 [[HASH]], i32 0, ptr %mcdc.addr) // MCDC-DAG: %[[TEMP0:mcdc.temp[0-9]*]] = load i32, ptr %mcdc.addr, align 4 // MCDC: %[[TEMP:[0-9]+]] = add i32 %[[TEMP0]], 0 // MCDC: %[[LAB1:[0-9]+]] = lshr i32 %[[TEMP]], 3 diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst index 10d53bea149ef..a587afed6ca88 100644 --- a/llvm/docs/LangRef.rst +++ b/llvm/docs/LangRef.rst @@ -14441,52 +14441,6 @@ to generate the appropriate data structures and the code to instrument MC/DC test vectors in a format that can be written out by a compiler runtime and consumed via the ``llvm-profdata`` tool. -'``llvm.instrprof.mcdc.condbitmap.update``' Intrinsic -^ - -Syntax: -""" - -:: - - declare void @llvm.instrprof.mcdc.condbitmap.update(ptr , i64 , - i32 , - ptr , - i1 ) - -Overview: -" - -The '``llvm.instrprof.mcdc.condbitmap.update``' intrinsic is used to track -MC/DC condition evaluation for each condition in a boolean expression. - -Arguments: -"" - -The first argument is a pointer to a global variable containing the -name of the entity being instrumented. This should generally be the -(mangled) function name for a set of counters. - -The second argument is a hash value that can be used by the consumer -of the profile data to detect changes to the instrumented source. - -The third argument is an ID of a condition to track. This value is used as a -bit index into the condition bitmap. - -The fourth argument is the address of the condition bitmap. - -The fifth argument is the boolean value representing the evaluation of the -condition (true or false) - -Semantics: -"" - -This intrinsic represents the update of a condition bitmap that is local to a -function and will cause the ``-instrprof`` pass to generate the code to -instrument the control flow around each condition in a boolean expression. The -ID of each condition corresponds to a bit index in the condition bitmap which -is set based on the evaluation of the condition. - '``llvm.instrprof.mcdc.tvbitmap.update``' Intrinsic ^^^ @@ -14496,7 +14450,6 @@ Syntax: :: declare void @llvm.instrprof.mcdc.tvbitmap.update(ptr , i64 , -
[clang] [clang] SourceLocIdentKind::Function should not be dependent (PR #94942)
jcsxky wrote: ```cpp struct BasicPersistent; struct SourceLocation { static constexpr const char* Current(const char * func = __builtin_FUNCTION()) { return func; } }; template BasicPersistent &&__declval(int); template auto declval() -> decltype(__declval<_Tp>(0)); template _Tp forward; template auto construct_at(_Tp *, _Args...) -> decltype(new _Tp(declval<_Args>()...)) { constexpr auto *F = SourceLocation::Current(); static_assert(__builtin_strlen(F) == 12); return 0; } template struct allocator; template struct allocator_traits; template struct allocator_traits> { using pointer = _Tp *; template static void construct(_Up __p, _Args...) { construct_at(__p, forward<_Args>...); } }; struct __alloc_traits : allocator_traits> { } push_back___x; __alloc_traits::pointer _M_impl_0; template void emplace_back(_Args...) { __alloc_traits::construct(_M_impl_0, forward<_Args>...); } struct BasicPersistent { BasicPersistent(BasicPersistent &&, const char* = SourceLocation::Current()) {} }; void CFXJSE_EngineAddObjectToUpArray() { emplace_back(push_back___x); } ``` I modify the testcase as above and I think we just need to make dependent if Kind is `SourceLocIdentKind::SourceLocStruct`. Could you please take another look? @cor3ntin https://github.com/llvm/llvm-project/pull/94942 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [llvm] [InstrProf] Created Thread local counter instrumentation, compiler-rt runtimes (PR #95494)
ajwock wrote: https://discourse.llvm.org/t/rfc-profiling-counters-in-thread-local-storage/79596 https://github.com/llvm/llvm-project/pull/95494 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [llvm] [InstrProf] Created Thread local counter instrumentation, compiler-rt runtimes (PR #95494)
llvmbot wrote: @llvm/pr-subscribers-clang-driver Author: Andrew Wock (ajwock) Changes LLVM can now generate increments to counters in thread local storage. Use a new compiler-rt runtime to atomically add thread local counters to global counters on thread exit. The clang driver will link the new runtime libraries in when the new option -fprofile-thread-local is specified. More details available in the RFC on discourse. --- Patch is 67.04 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/95494.diff 36 Files Affected: - (modified) clang/docs/UsersManual.rst (+8) - (modified) clang/include/clang/Basic/CodeGenOptions.def (+1) - (modified) clang/include/clang/Driver/Options.td (+3) - (modified) clang/include/clang/Driver/ToolChain.h (+6) - (modified) clang/lib/Driver/ToolChain.cpp (+10) - (modified) clang/lib/Driver/ToolChains/Clang.cpp (+12) - (modified) clang/lib/Driver/ToolChains/Linux.cpp (+7) - (modified) compiler-rt/include/profile/InstrProfData.inc (+4) - (modified) compiler-rt/lib/profile/CMakeLists.txt (+35) - (added) compiler-rt/lib/profile/InstrProfilingDyLibLinux.cpp (+63) - (modified) compiler-rt/lib/profile/InstrProfilingFile.c (+6) - (modified) compiler-rt/lib/profile/InstrProfilingPlatformLinux.c (+1) - (added) compiler-rt/lib/profile/InstrProfilingStaticTLSLinux.cpp (+123) - (added) compiler-rt/lib/profile/InstrProfilingTLS.c (+29) - (added) compiler-rt/lib/profile/InstrProfilingTLS.h (+39) - (added) compiler-rt/lib/profile/InstrProfilingTLSDyLib.c (+100) - (added) compiler-rt/lib/profile/InstrProfilingTLSDyLib.h (+4) - (modified) compiler-rt/lib/tsan/rtl/CMakeLists.txt (+1-1) - (added) compiler-rt/test/profile/Inputs/instrprof-tls-dlclose-lib.c (+7) - (added) compiler-rt/test/profile/Inputs/instrprof-tls-dlclose-main.c (+93) - (added) compiler-rt/test/profile/Inputs/instrprof-tls-dlopen-func.c (+9) - (added) compiler-rt/test/profile/Inputs/instrprof-tls-dlopen-func2.c (+9) - (added) compiler-rt/test/profile/Inputs/instrprof-tls-dlopen-main.c (+105) - (added) compiler-rt/test/profile/Inputs/instrprof-tls-exit.c (+37) - (added) compiler-rt/test/profile/Linux/instrprof-tls-dlclose-memfault.test (+27) - (added) compiler-rt/test/profile/Linux/instrprof-tls-dlclose-mix-subset.test (+41) - (added) compiler-rt/test/profile/Linux/instrprof-tls-dlclose-mix.test (+48) - (added) compiler-rt/test/profile/Linux/instrprof-tls-dlclose-nodelete.test (+24) - (added) compiler-rt/test/profile/Linux/instrprof-tls-dlopen.test (+32) - (added) compiler-rt/test/profile/Linux/instrprof-tls-exit.test (+17) - (added) compiler-rt/test/profile/Linux/instrprof-tls-noclose-mix.test (+51) - (added) compiler-rt/test/profile/Linux/instrprof-tls-shared-mix-subset.test (+35) - (added) compiler-rt/test/profile/Linux/instrprof-tls-shared-mix.test (+48) - (modified) llvm/include/llvm/ProfileData/InstrProf.h (+3) - (modified) llvm/include/llvm/ProfileData/InstrProfData.inc (+4) - (modified) llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp (+68-3) ``diff diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst index f954857b0235a..f7db513b92909 100644 --- a/clang/docs/UsersManual.rst +++ b/clang/docs/UsersManual.rst @@ -2932,6 +2932,14 @@ indexed format, regardeless whether it is produced by frontend or the IR pass. overhead. ``prefer-atomic`` will be transformed to ``atomic`` when supported by the target, or ``single`` otherwise. +.. option:: -fprofile-thread-local + + Increment profile counters in thread local storage and atomically add their + values to global counters on thread exit. This has the potential to deliver + both accuracy and high performance whenever there is high thread contention + on profile counters. This is an experimental option and it is only supported + on 64-bit linux. + Fine Tuning Profile Collection ^^ diff --git a/clang/include/clang/Basic/CodeGenOptions.def b/clang/include/clang/Basic/CodeGenOptions.def index 7ffc40a00504f..7cd0bfb6d71b5 100644 --- a/clang/include/clang/Basic/CodeGenOptions.def +++ b/clang/include/clang/Basic/CodeGenOptions.def @@ -218,6 +218,7 @@ ENUM_CODEGENOPT(ProfileUse, ProfileInstrKind, 2, ProfileNone) /// instrumented. Selected group numbers can be 0 to N-1 inclusive. VALUE_CODEGENOPT(ProfileTotalFunctionGroups, 32, 1) VALUE_CODEGENOPT(ProfileSelectedFunctionGroup, 32, 0) +CODEGENOPT(InstrProfileThreadLocal, 1, 0) ///< Counters are updated on a per-thread basis CODEGENOPT(CoverageMapping , 1, 0) ///< Generate coverage mapping regions to ///< enable code coverage analysis. CODEGENOPT(DumpCoverageMapping , 1, 0) ///< Dump the generated coverage mapping diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index d44faa55c456f..aab5b63c991f1 100644 --- a/clang/include/clang/Driver/Options.td +++
[clang] [compiler-rt] [llvm] [InstrProf] Created Thread local counter instrumentation, compiler-rt runtimes (PR #95494)
https://github.com/ajwock created https://github.com/llvm/llvm-project/pull/95494 LLVM can now generate increments to counters in thread local storage. Use a new compiler-rt runtime to atomically add thread local counters to global counters on thread exit. The clang driver will link the new runtime libraries in when the new option -fprofile-thread-local is specified. More details available in the RFC on discourse. >From 44e2159636efd601c90aced44856d17d77728caa Mon Sep 17 00:00:00 2001 From: Andrew Wock Date: Tue, 4 Jun 2024 09:45:31 -0400 Subject: [PATCH] Created Thread local counter instrumentation. LLVM can now generate increments to counters in thread local storage. Use a new compiler-rt runtime to atomically add thread local counters to global counters on thread exit. The clang driver will link the new runtime libraries in when the new option -fprofile-thread-local is specified. Signed-off-by: Andrew Wock --- clang/docs/UsersManual.rst| 8 ++ clang/include/clang/Basic/CodeGenOptions.def | 1 + clang/include/clang/Driver/Options.td | 3 + clang/include/clang/Driver/ToolChain.h| 6 + clang/lib/Driver/ToolChain.cpp| 10 ++ clang/lib/Driver/ToolChains/Clang.cpp | 12 ++ clang/lib/Driver/ToolChains/Linux.cpp | 7 + compiler-rt/include/profile/InstrProfData.inc | 4 + compiler-rt/lib/profile/CMakeLists.txt| 35 + .../lib/profile/InstrProfilingDyLibLinux.cpp | 63 + compiler-rt/lib/profile/InstrProfilingFile.c | 6 + .../lib/profile/InstrProfilingPlatformLinux.c | 1 + .../profile/InstrProfilingStaticTLSLinux.cpp | 123 ++ compiler-rt/lib/profile/InstrProfilingTLS.c | 29 + compiler-rt/lib/profile/InstrProfilingTLS.h | 39 ++ .../lib/profile/InstrProfilingTLSDyLib.c | 100 ++ .../lib/profile/InstrProfilingTLSDyLib.h | 4 + compiler-rt/lib/tsan/rtl/CMakeLists.txt | 2 +- .../Inputs/instrprof-tls-dlclose-lib.c| 7 + .../Inputs/instrprof-tls-dlclose-main.c | 93 + .../Inputs/instrprof-tls-dlopen-func.c| 9 ++ .../Inputs/instrprof-tls-dlopen-func2.c | 9 ++ .../Inputs/instrprof-tls-dlopen-main.c| 105 +++ .../test/profile/Inputs/instrprof-tls-exit.c | 37 ++ .../Linux/instrprof-tls-dlclose-memfault.test | 27 .../instrprof-tls-dlclose-mix-subset.test | 41 ++ .../Linux/instrprof-tls-dlclose-mix.test | 48 +++ .../Linux/instrprof-tls-dlclose-nodelete.test | 24 .../profile/Linux/instrprof-tls-dlopen.test | 32 + .../profile/Linux/instrprof-tls-exit.test | 17 +++ .../Linux/instrprof-tls-noclose-mix.test | 51 .../instrprof-tls-shared-mix-subset.test | 35 + .../Linux/instrprof-tls-shared-mix.test | 48 +++ llvm/include/llvm/ProfileData/InstrProf.h | 3 + .../llvm/ProfileData/InstrProfData.inc| 4 + .../Instrumentation/InstrProfiling.cpp| 71 +- 36 files changed, 1110 insertions(+), 4 deletions(-) create mode 100644 compiler-rt/lib/profile/InstrProfilingDyLibLinux.cpp create mode 100644 compiler-rt/lib/profile/InstrProfilingStaticTLSLinux.cpp create mode 100644 compiler-rt/lib/profile/InstrProfilingTLS.c create mode 100644 compiler-rt/lib/profile/InstrProfilingTLS.h create mode 100644 compiler-rt/lib/profile/InstrProfilingTLSDyLib.c create mode 100644 compiler-rt/lib/profile/InstrProfilingTLSDyLib.h create mode 100644 compiler-rt/test/profile/Inputs/instrprof-tls-dlclose-lib.c create mode 100644 compiler-rt/test/profile/Inputs/instrprof-tls-dlclose-main.c create mode 100644 compiler-rt/test/profile/Inputs/instrprof-tls-dlopen-func.c create mode 100644 compiler-rt/test/profile/Inputs/instrprof-tls-dlopen-func2.c create mode 100644 compiler-rt/test/profile/Inputs/instrprof-tls-dlopen-main.c create mode 100644 compiler-rt/test/profile/Inputs/instrprof-tls-exit.c create mode 100644 compiler-rt/test/profile/Linux/instrprof-tls-dlclose-memfault.test create mode 100644 compiler-rt/test/profile/Linux/instrprof-tls-dlclose-mix-subset.test create mode 100644 compiler-rt/test/profile/Linux/instrprof-tls-dlclose-mix.test create mode 100644 compiler-rt/test/profile/Linux/instrprof-tls-dlclose-nodelete.test create mode 100644 compiler-rt/test/profile/Linux/instrprof-tls-dlopen.test create mode 100644 compiler-rt/test/profile/Linux/instrprof-tls-exit.test create mode 100644 compiler-rt/test/profile/Linux/instrprof-tls-noclose-mix.test create mode 100644 compiler-rt/test/profile/Linux/instrprof-tls-shared-mix-subset.test create mode 100644 compiler-rt/test/profile/Linux/instrprof-tls-shared-mix.test diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst index f954857b0235a..f7db513b92909 100644 --- a/clang/docs/UsersManual.rst +++ b/clang/docs/UsersManual.rst @@ -2932,6 +2932,14 @@ indexed format, regardeless whether it
[clang] [C++20] [Modules] [Itanium ABI] Generate the vtable in the module unit of dynamic classes (PR #75912)
@@ -318,6 +318,9 @@ namespace { if (Diags.hasUnrecoverableErrorOccurred()) return; + if (RD->shouldEmitInExternalSource()) ChuanqiXu9 wrote: Done. I don't mind doing it really. But what I confuse is, it looks there are a lot of codes in CodeGen to decide whether or not to emit the vtable. So it looks not like a pure Sema job to me. https://github.com/llvm/llvm-project/pull/75912 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C++20] [Modules] [Itanium ABI] Generate the vtable in the module unit of dynamic classes (PR #75912)
https://github.com/ChuanqiXu9 updated https://github.com/llvm/llvm-project/pull/75912 >From cf8be3c418dde67b74d4a5a4ea98a33f0e2fbd72 Mon Sep 17 00:00:00 2001 From: Chuanqi Xu Date: Tue, 19 Dec 2023 17:00:59 +0800 Subject: [PATCH 1/7] [C++20] [Modules] [Itanium ABI] Generate the vtable in the module unit of dynamic classes Close https://github.com/llvm/llvm-project/issues/70585 and reflect https://github.com/itanium-cxx-abi/cxx-abi/issues/170. The significant change of the patch is: for dynamic classes attached to module units, we generate the vtable to the attached module units directly and the key functions for such classes is meaningless. --- clang/include/clang/AST/DeclBase.h| 3 ++ clang/lib/AST/DeclBase.cpp| 9 + clang/lib/CodeGen/CGVTables.cpp | 28 ++ clang/lib/CodeGen/CodeGenModule.cpp | 7 clang/lib/CodeGen/ItaniumCXXABI.cpp | 3 ++ clang/lib/Sema/SemaDecl.cpp | 9 + clang/lib/Sema/SemaDeclCXX.cpp| 12 -- clang/lib/Serialization/ASTReaderDecl.cpp | 6 +++ clang/lib/Serialization/ASTWriterDecl.cpp | 6 +++ clang/test/CodeGenCXX/modules-vtable.cppm | 31 +-- clang/test/CodeGenCXX/pr70585.cppm| 47 +++ 11 files changed, 138 insertions(+), 23 deletions(-) create mode 100644 clang/test/CodeGenCXX/pr70585.cppm diff --git a/clang/include/clang/AST/DeclBase.h b/clang/include/clang/AST/DeclBase.h index 600ce73c7f019..f38386381853b 100644 --- a/clang/include/clang/AST/DeclBase.h +++ b/clang/include/clang/AST/DeclBase.h @@ -670,6 +670,9 @@ class alignas(8) Decl { /// Whether this declaration comes from another module unit. bool isInAnotherModuleUnit() const; + /// Whether this declaration comes from the same module unit being compiled. + bool isInCurrentModuleUnit() const; + /// Whether the definition of the declaration should be emitted in external /// sources. bool shouldEmitInExternalSource() const; diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp index 1e9c879e371bc..153dc3351dae5 100644 --- a/clang/lib/AST/DeclBase.cpp +++ b/clang/lib/AST/DeclBase.cpp @@ -1106,6 +1106,15 @@ bool Decl::isInAnotherModuleUnit() const { return M != getASTContext().getCurrentNamedModule(); } +bool Decl::isInCurrentModuleUnit() const { + auto *M = getOwningModule(); + + if (!M || !M->isNamedModule()) +return false; + + return M == getASTContext().getCurrentNamedModule(); +} + bool Decl::shouldEmitInExternalSource() const { ExternalASTSource *Source = getASTContext().getExternalSource(); if (!Source) diff --git a/clang/lib/CodeGen/CGVTables.cpp b/clang/lib/CodeGen/CGVTables.cpp index 001633453f242..55c3032dc9332 100644 --- a/clang/lib/CodeGen/CGVTables.cpp +++ b/clang/lib/CodeGen/CGVTables.cpp @@ -1051,6 +1051,11 @@ CodeGenModule::getVTableLinkage(const CXXRecordDecl *RD) { if (!RD->isExternallyVisible()) return llvm::GlobalVariable::InternalLinkage; + // V-tables for non-template classes with an owning module are always + // uniquely emitted in that module. + if (RD->isInNamedModule()) +return llvm::GlobalVariable::ExternalLinkage; + // We're at the end of the translation unit, so the current key // function is fully correct. const CXXMethodDecl *keyFunction = Context.getCurrentKeyFunction(RD); @@ -1185,6 +1190,21 @@ bool CodeGenVTables::isVTableExternal(const CXXRecordDecl *RD) { TSK == TSK_ExplicitInstantiationDefinition) return false; + // Itanium C++ ABI [5.2.3]: + // Virtual tables for dynamic classes are emitted as follows: + // + // - If the class is templated, the tables are emitted in every object that + // references any of them. + // - Otherwise, if the class is attached to a module, the tables are uniquely + // emitted in the object for the module unit in which it is defined. + // - Otherwise, if the class has a key function (see below), the tables are + // emitted in the object for the translation unit containing the definition of + // the key function. This is unique if the key function is not inline. + // - Otherwise, the tables are emitted in every object that references any of + // them. + if (RD->isInNamedModule()) +return RD->shouldEmitInExternalSource(); + // Otherwise, if the class doesn't have a key function (possibly // anymore), the vtable must be defined here. const CXXMethodDecl *keyFunction = CGM.getContext().getCurrentKeyFunction(RD); @@ -1194,13 +1214,7 @@ bool CodeGenVTables::isVTableExternal(const CXXRecordDecl *RD) { const FunctionDecl *Def; // Otherwise, if we don't have a definition of the key function, the // vtable must be defined somewhere else. - if (!keyFunction->hasBody(Def)) -return true; - - assert(Def && "The body of the key function is not assigned to Def?"); - // If the non-inline key function comes from another module unit, the vtable - // must be defined there. - return
[clang] [llvm] [Clang] Introduce [[clang::coro_structured_concurrency]] (PR #94693)
https://github.com/yuxuanchen1997 edited https://github.com/llvm/llvm-project/pull/94693 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] (New) Add option to generate additional debug info for expression dereferencing pointer to pointers (PR #95298)
@@ -5746,6 +5746,57 @@ void CGDebugInfo::EmitExternalVariable(llvm::GlobalVariable *Var, Var->addDebugInfo(GVE); } +void CGDebugInfo::EmitPseudoVariable(CGBuilderTy , + llvm::Instruction *Value, QualType Ty) { + // Only when -g2 or above is specified, debug info for variables will be + // generated. + if (CGM.getCodeGenOpts().getDebugInfo() <= + llvm::codegenoptions::DebugLineTablesOnly) +return; + + llvm::DILocation *DIL = Value->getDebugLoc().get(); + if (!DIL) +return; + + llvm::DIFile *Unit = DIL->getFile(); + llvm::DIType *Type = getOrCreateType(Ty, Unit); + + // Check if Value is already a declared variable and has debug info, in this + // case we have nothing to do. Clang emits declared variable as alloca, and huangjd wrote: Done. https://github.com/llvm/llvm-project/pull/95298 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] (New) Add option to generate additional debug info for expression dereferencing pointer to pointers (PR #95298)
@@ -5746,6 +5746,57 @@ void CGDebugInfo::EmitExternalVariable(llvm::GlobalVariable *Var, Var->addDebugInfo(GVE); } +void CGDebugInfo::EmitPseudoVariable(CGBuilderTy , + llvm::Instruction *Value, QualType Ty) { + // Only when -g2 or above is specified, debug info for variables will be + // generated. + if (CGM.getCodeGenOpts().getDebugInfo() <= + llvm::codegenoptions::DebugLineTablesOnly) +return; + + llvm::DILocation *DIL = Value->getDebugLoc().get(); + if (!DIL) +return; + + llvm::DIFile *Unit = DIL->getFile(); + llvm::DIType *Type = getOrCreateType(Ty, Unit); + + // Check if Value is already a declared variable and has debug info, in this + // case we have nothing to do. Clang emits declared variable as alloca, and + // it is loaded upon use, so we identify such pattern here. + if (llvm::LoadInst *Load = dyn_cast(Value)) { +llvm::Value *Var = Load->getPointerOperand(); +// There can be implicit type cast applied on a variable if it is an opaque +// ptr, in this case its debug info may not match the actual type of object +// being used as in the next instruction, so we will need to emit a pseudo +// variable for type-casted value. +auto DeclareTypeMatches = [&](auto *DbgDeclare) { + return DbgDeclare->getVariable()->getType() == Type; +}; +if (any_of(llvm::findDbgDeclares(Var), DeclareTypeMatches) || +any_of(llvm::findDVRDeclares(Var), DeclareTypeMatches)) + return; + } + + // Find the correct location to insert the debug value. + llvm::BasicBlock *InsertBB = Value->getParent(); + llvm::Instruction *InsertBefore = Value->getIterator()->getNextNode(); + if (llvm::InvokeInst *Invoke = dyn_cast(Value)) { +InsertBB = Invoke->getNormalDest(); +InsertBefore = InsertBB->size() > 0 ? &(InsertBB->front()) : nullptr; + } huangjd wrote: Done. https://github.com/llvm/llvm-project/pull/95298 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] (New) Add option to generate additional debug info for expression dereferencing pointer to pointers (PR #95298)
https://github.com/huangjd updated https://github.com/llvm/llvm-project/pull/95298 >From 0c49ae55b4b05a9c701288f106c138cab4af37f0 Mon Sep 17 00:00:00 2001 From: William Huang Date: Wed, 12 Jun 2024 03:48:51 -0400 Subject: [PATCH 1/2] (New) Add option to generate additional debug info for expression dereferencing pointer to pointers This is a different implementation to #94100, which has been reverted. When -fdebug-info-for-profiling is specified, for any Load expression if the pointer operand is not a declared variable, clang will emit debug info describing the type of the pointer operand (which can be an intermediate expr) --- clang/lib/CodeGen/CGDebugInfo.cpp | 51 clang/lib/CodeGen/CGDebugInfo.h | 6 + clang/lib/CodeGen/CGExprScalar.cpp| 21 +++- .../test/CodeGenCXX/debug-info-ptr-to-ptr.cpp | 115 ++ 4 files changed, 192 insertions(+), 1 deletion(-) create mode 100644 clang/test/CodeGenCXX/debug-info-ptr-to-ptr.cpp diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index 99e12da0081af..d3b754d14b19e 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -5746,6 +5746,57 @@ void CGDebugInfo::EmitExternalVariable(llvm::GlobalVariable *Var, Var->addDebugInfo(GVE); } +void CGDebugInfo::EmitPseudoVariable(CGBuilderTy , + llvm::Instruction *Value, QualType Ty) { + // Only when -g2 or above is specified, debug info for variables will be + // generated. + if (CGM.getCodeGenOpts().getDebugInfo() <= + llvm::codegenoptions::DebugLineTablesOnly) +return; + + llvm::DILocation *DIL = Value->getDebugLoc().get(); + if (!DIL) +return; + + llvm::DIFile *Unit = DIL->getFile(); + llvm::DIType *Type = getOrCreateType(Ty, Unit); + + // Check if Value is already a declared variable and has debug info, in this + // case we have nothing to do. Clang emits declared variable as alloca, and + // it is loaded upon use, so we identify such pattern here. + if (llvm::LoadInst *Load = dyn_cast(Value)) { +llvm::Value *Var = Load->getPointerOperand(); +// There can be implicit type cast applied on a variable if it is an opaque +// ptr, in this case its debug info may not match the actual type of object +// being used as in the next instruction, so we will need to emit a pseudo +// variable for type-casted value. +auto DeclareTypeMatches = [&](auto *DbgDeclare) { + return DbgDeclare->getVariable()->getType() == Type; +}; +if (any_of(llvm::findDbgDeclares(Var), DeclareTypeMatches) || +any_of(llvm::findDVRDeclares(Var), DeclareTypeMatches)) + return; + } + + // Find the correct location to insert the debug value. + llvm::BasicBlock *InsertBB = Value->getParent(); + llvm::Instruction *InsertBefore = Value->getIterator()->getNextNode(); + if (llvm::InvokeInst *Invoke = dyn_cast(Value)) { +InsertBB = Invoke->getNormalDest(); +InsertBefore = InsertBB->size() > 0 ? &(InsertBB->front()) : nullptr; + } + + llvm::DILocalVariable *D = DBuilder.createAutoVariable( + LexicalBlockStack.back(), "", nullptr, 0, Type, false, + llvm::DINode::FlagArtificial); + if (InsertBefore) +DBuilder.insertDbgValueIntrinsic(Value, D, DBuilder.createExpression(), DIL, + InsertBefore); + else +DBuilder.insertDbgValueIntrinsic(Value, D, DBuilder.createExpression(), DIL, + InsertBB); +} + void CGDebugInfo::EmitGlobalAlias(const llvm::GlobalValue *GV, const GlobalDecl GD) { diff --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h index 8fe738be21568..da466837aa3c3 100644 --- a/clang/lib/CodeGen/CGDebugInfo.h +++ b/clang/lib/CodeGen/CGDebugInfo.h @@ -530,6 +530,12 @@ class CGDebugInfo { /// Emit information about an external variable. void EmitExternalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl); + /// Emit a pseudo variable and debug info for an intermediate value if it does + /// not correspond to a variable in the source code, so that a profiler can + /// track more accurate usage of certain instructions of interest. + void EmitPseudoVariable(CGBuilderTy , llvm::Instruction *Value, + QualType Ty); + /// Emit information about global variable alias. void EmitGlobalAlias(const llvm::GlobalValue *GV, const GlobalDecl Decl); diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp index 1b144c178ce96..58f0a3113b4f8 100644 --- a/clang/lib/CodeGen/CGExprScalar.cpp +++ b/clang/lib/CodeGen/CGExprScalar.cpp @@ -1937,7 +1937,26 @@ Value *ScalarExprEmitter::VisitMemberExpr(MemberExpr *E) { } } - return EmitLoadOfLValue(E); + llvm::Value *Result = EmitLoadOfLValue(E); + + // If -fdebug-info-for-profiling is specified, emit a pseudo variable and its + // debug
[clang] Check whether EvaluatedStmt::Value is valid in VarDecl::hasInit (PR #94515)
https://github.com/ahatanak updated https://github.com/llvm/llvm-project/pull/94515 >From 22a8fa09e81337f45c2ed94e229f06e9aaa32c0e Mon Sep 17 00:00:00 2001 From: Akira Hatanaka Date: Wed, 5 Jun 2024 11:02:31 -0700 Subject: [PATCH 1/2] Check whether EvaluatedStmt::Value is valid in VarDecl::hasInit VarDecl::isNull() doesn't tell whether the VarDecl has an initializer as methods like ensureEvaluatedStmt can create an EvaluatedStmt even when there isn't an initializer. Revert e1c3e16d24b5cc097ff08e9283f53319acd3f245 as the change isn't needed anymore with this change. See the discussion in https://github.com/llvm/llvm-project/pull/93749. --- clang/lib/AST/Decl.cpp | 10 ++ 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 1f19dadafa44e..fc04f877b2268 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -2390,6 +2390,9 @@ bool VarDecl::hasInit() const { if (P->hasUnparsedDefaultArg() || P->hasUninstantiatedDefaultArg()) return false; + if (auto *Eval = getEvaluatedStmt()) +return Eval->Value.isValid(); + return !Init.isNull(); } @@ -2402,10 +2405,9 @@ Expr *VarDecl::getInit() { auto *Eval = getEvaluatedStmt(); - return cast_if_present( - Eval->Value.isOffset() - ? Eval->Value.get(getASTContext().getExternalSource()) - : Eval->Value.get(nullptr)); + return cast(Eval->Value.isOffset() +? Eval->Value.get(getASTContext().getExternalSource()) +: Eval->Value.get(nullptr)); } Stmt **VarDecl::getInitAddress() { >From a54e9ac892aa7bbbcf73256e7ac5eaec187578fe Mon Sep 17 00:00:00 2001 From: Akira Hatanaka Date: Thu, 13 Jun 2024 18:21:38 -0700 Subject: [PATCH 2/2] Move the conditional into the argument --- clang/lib/AST/Decl.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index fc04f877b2268..9d0a835a12c45 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -2405,9 +2405,8 @@ Expr *VarDecl::getInit() { auto *Eval = getEvaluatedStmt(); - return cast(Eval->Value.isOffset() -? Eval->Value.get(getASTContext().getExternalSource()) -: Eval->Value.get(nullptr)); + return cast(Eval->Value.get( + Eval->Value.isOffset() ? getASTContext().getExternalSource() : nullptr)); } Stmt **VarDecl::getInitAddress() { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Safe Buffers] Serialize unsafe_buffer_usage pragmas (PR #92031)
https://github.com/haoNoQ approved this pull request. Ok LGTM!! Thanks again for figuring this all out! https://github.com/llvm/llvm-project/pull/92031 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Safe Buffers] Serialize unsafe_buffer_usage pragmas (PR #92031)
https://github.com/ziqingluo-90 updated https://github.com/llvm/llvm-project/pull/92031 >From ac5aeb5c3a134d085320fc7fc5cf3f2c8c41a1f1 Mon Sep 17 00:00:00 2001 From: ziqingluo-90 Date: Mon, 13 May 2024 13:31:21 -0700 Subject: [PATCH 1/7] fix safe buffer opt-out region serialization --- clang/include/clang/Lex/Preprocessor.h| 22 +++- .../include/clang/Serialization/ASTBitCodes.h | 3 + clang/lib/Lex/Preprocessor.cpp| 106 ++ clang/lib/Serialization/ASTReader.cpp | 11 ++ clang/lib/Serialization/ASTWriter.cpp | 7 ++ clang/test/Modules/Inputs/SafeBuffers/base.h | 9 ++ .../SafeBuffers/safe_buffers_test.modulemap | 10 ++ .../Modules/Inputs/SafeBuffers/test_sub1.h| 20 .../Modules/Inputs/SafeBuffers/test_sub2.h| 11 ++ clang/test/Modules/safe_buffers_optout.cpp| 39 +++ ...unsafe-buffer-usage-pragma-pch-complex.cpp | 72 .../warn-unsafe-buffer-usage-pragma-pch.cpp | 27 + 12 files changed, 314 insertions(+), 23 deletions(-) create mode 100644 clang/test/Modules/Inputs/SafeBuffers/base.h create mode 100644 clang/test/Modules/Inputs/SafeBuffers/safe_buffers_test.modulemap create mode 100644 clang/test/Modules/Inputs/SafeBuffers/test_sub1.h create mode 100644 clang/test/Modules/Inputs/SafeBuffers/test_sub2.h create mode 100644 clang/test/Modules/safe_buffers_optout.cpp create mode 100644 clang/test/SemaCXX/warn-unsafe-buffer-usage-pragma-pch-complex.cpp create mode 100644 clang/test/SemaCXX/warn-unsafe-buffer-usage-pragma-pch.cpp diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h index e89b4a2c5230e..8d6884ebe7597 100644 --- a/clang/include/clang/Lex/Preprocessor.h +++ b/clang/include/clang/Lex/Preprocessor.h @@ -2883,11 +2883,15 @@ class Preprocessor { /// otherwise. SourceLocation CurrentSafeBufferOptOutStart; // It is used to report the start location of an never-closed region. - // An ordered sequence of "-Wunsafe-buffer-usage" opt-out regions in one - // translation unit. Each region is represented by a pair of start and end - // locations. A region is "open" if its' start and end locations are + using SafeBufferOptOutMapTy = + SmallVector, 16>; + // An ordered sequence of "-Wunsafe-buffer-usage" opt-out regions in this + // translation unit. Each region is represented by a pair of start and + // end locations. A region is "open" if its' start and end locations are // identical. - SmallVector, 8> SafeBufferOptOutMap; + SafeBufferOptOutMapTy SafeBufferOptOutMap; + // `SafeBufferOptOutMap`s of loaded files: + llvm::DenseMap LoadedSafeBufferOptOutMap; public: /// \return true iff the given `Loc` is in a "-Wunsafe-buffer-usage" opt-out @@ -2918,6 +2922,16 @@ class Preprocessor { /// opt-out region bool isPPInSafeBufferOptOutRegion(SourceLocation ); + /// \return a sequence of SourceLocations representing ordered opt-out regions + /// specified by + /// `\#pragma clang unsafe_buffer_usage begin/end`s of this translation unit. + SmallVector serializeSafeBufferOptOutMap() const; + + /// \param SrcLocSeqs a sequence of SourceLocations deserialized from a + /// record of code `PP_UNSAFE_BUFFER_USAGE`. + void setDeserializedSafeBufferOptOutMap( + const SmallVectorImpl ); + private: /// Helper functions to forward lexing to the actual lexer. They all share the /// same signature. diff --git a/clang/include/clang/Serialization/ASTBitCodes.h b/clang/include/clang/Serialization/ASTBitCodes.h index dcfa4ac0c1967..d1a0eba943039 100644 --- a/clang/include/clang/Serialization/ASTBitCodes.h +++ b/clang/include/clang/Serialization/ASTBitCodes.h @@ -775,6 +775,9 @@ enum ASTRecordTypes { /// Record code for lexical and visible block for delayed namespace in /// reduced BMI. DELAYED_NAMESPACE_LEXICAL_VISIBLE_RECORD = 68, + + /// Record code for \#pragma clang unsafe_buffer_usage begin/end + PP_UNSAFE_BUFFER_USAGE = 69, }; /// Record types used within a source manager block. diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp index 0b70192743a39..6a41e3d4138aa 100644 --- a/clang/lib/Lex/Preprocessor.cpp +++ b/clang/lib/Lex/Preprocessor.cpp @@ -58,6 +58,7 @@ #include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" +#include "llvm/ADT/iterator_range.h" #include "llvm/Support/Capacity.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/MemoryBuffer.h" @@ -1483,26 +1484,41 @@ void Preprocessor::emitFinalMacroWarning(const Token , } bool Preprocessor::isSafeBufferOptOut(const SourceManager , - const SourceLocation ) const { - // Try to find a region in `SafeBufferOptOutMap` where `Loc` is in: - auto FirstRegionEndingAfterLoc = llvm::partition_point( - SafeBufferOptOutMap, - [, - ](const std::pair ) { -return
[clang] [llvm] [llvm][AArch64] Support -mcpu=apple-m4 (PR #95478)
https://github.com/jroelofs updated https://github.com/llvm/llvm-project/pull/95478 >From 1461be872bf26e2e0f2572f688a45af795421432 Mon Sep 17 00:00:00 2001 From: Jon Roelofs Date: Thu, 13 Jun 2024 10:27:52 -0700 Subject: [PATCH 1/2] [llvm][AArch64] Support -mcpu=apple-m4 --- .../llvm/TargetParser/AArch64TargetParser.h | 9 +- llvm/lib/Target/AArch64/AArch64Processors.td | 31 +-- llvm/lib/Target/AArch64/AArch64Subtarget.cpp | 2 ++ .../TargetParser/TargetParserTest.cpp | 17 +- 4 files changed, 55 insertions(+), 4 deletions(-) diff --git a/llvm/include/llvm/TargetParser/AArch64TargetParser.h b/llvm/include/llvm/TargetParser/AArch64TargetParser.h index df8e685eb6667..c1a68a0ec5c19 100644 --- a/llvm/include/llvm/TargetParser/AArch64TargetParser.h +++ b/llvm/include/llvm/TargetParser/AArch64TargetParser.h @@ -521,7 +521,14 @@ inline constexpr CpuInfo CpuInfos[] = { AArch64::ExtensionBitset({AArch64::AEK_AES, AArch64::AEK_SHA2, AArch64::AEK_SHA3, AArch64::AEK_FP16, AArch64::AEK_FP16FML})}, - +// Technically apple-m4 is ARMv9.2a, but a quirk of LLVM defines v9.0 as +// requiring SVE, which is optional according to the Arm ARM and not +// supported by the core. ARMv8.7a is the next closest choice. +{"apple-m4", ARMV8_7A, + AArch64::ExtensionBitset( + {AArch64::AEK_AES, AArch64::AEK_SHA2, AArch64::AEK_SHA3, + AArch64::AEK_FP16, AArch64::AEK_FP16FML, AArch64::AEK_SME, + AArch64::AEK_SME2, AArch64::AEK_SMEF64F64, AArch64::AEK_SMEI16I64})}, {"apple-s4", ARMV8_3A, AArch64::ExtensionBitset( {AArch64::AEK_AES, AArch64::AEK_SHA2, AArch64::AEK_FP16})}, diff --git a/llvm/lib/Target/AArch64/AArch64Processors.td b/llvm/lib/Target/AArch64/AArch64Processors.td index c04c20c78e8eb..57df6b85ab11d 100644 --- a/llvm/lib/Target/AArch64/AArch64Processors.td +++ b/llvm/lib/Target/AArch64/AArch64Processors.td @@ -398,6 +398,22 @@ def TuneAppleA17 : SubtargetFeature<"apple-a17", "ARMProcFamily", "AppleA17", FeatureZCRegMove, FeatureZCZeroing]>; +def TuneAppleM4 : SubtargetFeature<"apple-m4", "ARMProcFamily", "AppleM4", + "Apple M4", [ + FeatureAlternateSExtLoadCVTF32Pattern, + FeatureArithmeticBccFusion, + FeatureArithmeticCbzFusion, + FeatureDisableLatencySchedHeuristic, + FeatureFuseAddress, + FeatureFuseAES, + FeatureFuseArithmeticLogic, + FeatureFuseCCSelect, + FeatureFuseCryptoEOR, + FeatureFuseLiterals, + FeatureZCRegMove, + FeatureZCZeroing + ]>; + def TuneExynosM3 : SubtargetFeature<"exynosm3", "ARMProcFamily", "ExynosM3", "Samsung Exynos-M3 processors", [FeatureExynosCheapAsMoveHandling, @@ -784,6 +800,14 @@ def ProcessorFeatures { FeatureNEON, FeaturePerfMon, FeatureSHA3, FeatureFullFP16, FeatureFP16FML, FeatureHCX]; + // Technically apple-m4 is ARMv9.2. See the corresponding comment in + // AArch64TargetParser.h. + list AppleM4 = [HasV8_7aOps, FeatureCrypto, FeatureFPARMv8, +FeatureNEON, FeaturePerfMon, FeatureSHA3, +FeatureFullFP16, FeatureFP16FML, +FeatureAES, FeatureBF16, +FeatureSME2, +FeatureSMEF64F64, FeatureSMEI16I64]; list ExynosM3 = [HasV8_0aOps, FeatureCRC, FeatureCrypto, FeaturePerfMon]; list ExynosM4 = [HasV8_2aOps, FeatureCrypto, FeatureDotProd, @@ -1010,6 +1034,9 @@ def : ProcessorModel<"apple-a16", CycloneModel, ProcessorFeatures.AppleA16, [TuneAppleA16]>; def : ProcessorModel<"apple-a17", CycloneModel, ProcessorFeatures.AppleA17, [TuneAppleA17]>; +def : ProcessorModel<"apple-m4", CycloneModel, ProcessorFeatures.AppleM4, + [TuneAppleM4]>; + // Mac CPUs def : ProcessorModel<"apple-m1", CycloneModel, ProcessorFeatures.AppleA14, [TuneAppleA14]>; @@ -1025,8 +1052,8 @@ def : ProcessorModel<"apple-s5", CycloneModel, ProcessorFeatures.AppleA12, [TuneAppleA12]>; // Alias for the latest Apple processor model supported by LLVM. -def :
[clang] [HLSL] Use hlsl vector template in type printer (PR #95489)
llvmbot wrote: @llvm/pr-subscribers-hlsl Author: Chris B (llvm-beanz) Changes In HLSL we really want to be using the HLSL vector template and other built-in sugared spellings for some builtin types. This updates the type printer to take an option to use HLSL type spellings. This changes printing vector type names from: ``` T __attribute__((ext_vector_type(N))) ``` To: ``` vectorT, N ``` --- Patch is 42.77 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/95489.diff 16 Files Affected: - (modified) clang/include/clang/AST/PrettyPrinter.h (+6-1) - (modified) clang/lib/AST/TypePrinter.cpp (+25-7) - (modified) clang/test/AST/HLSL/pch.hlsl (+1-1) - (modified) clang/test/AST/HLSL/pch_with_buf.hlsl (+1-1) - (modified) clang/test/AST/HLSL/vector-alias.hlsl (+8-8) - (modified) clang/test/AST/HLSL/vector-constructors.hlsl (+11-11) - (modified) clang/test/SemaHLSL/BuiltIns/RWBuffers.hlsl (+1-1) - (modified) clang/test/SemaHLSL/BuiltIns/clamp-errors.hlsl (+1-1) - (modified) clang/test/SemaHLSL/BuiltIns/dot-errors.hlsl (+1-1) - (modified) clang/test/SemaHLSL/BuiltIns/lerp-errors.hlsl (+1-1) - (modified) clang/test/SemaHLSL/BuiltIns/mad-errors.hlsl (+1-1) - (modified) clang/test/SemaHLSL/BuiltIns/vector-errors.hlsl (+2-2) - (modified) clang/test/SemaHLSL/Types/BuiltinVector/ScalarSwizzleErrors.hlsl (+2-2) - (modified) clang/test/SemaHLSL/Types/BuiltinVector/ScalarSwizzles.hlsl (+28-28) - (modified) clang/test/SemaHLSL/VectorOverloadResolution.hlsl (+15-15) - (modified) clang/test/SemaHLSL/standard_conversion_sequences.hlsl (+45-45) ``diff diff --git a/clang/include/clang/AST/PrettyPrinter.h b/clang/include/clang/AST/PrettyPrinter.h index da276e26049b0..332ac3c6a004a 100644 --- a/clang/include/clang/AST/PrettyPrinter.h +++ b/clang/include/clang/AST/PrettyPrinter.h @@ -77,7 +77,7 @@ struct PrintingPolicy { PrintCanonicalTypes(false), PrintInjectedClassNameWithArguments(true), UsePreferredNames(true), AlwaysIncludeTypeForTemplateArgument(false), CleanUglifiedParameters(false), EntireContentsOfLargeArray(true), -UseEnumerators(true) {} +UseEnumerators(true), UseHLSLTypes(LO.HLSL) {} /// Adjust this printing policy for cases where it's known that we're /// printing C++ code (for instance, if AST dumping reaches a C++-only @@ -342,6 +342,11 @@ struct PrintingPolicy { LLVM_PREFERRED_TYPE(bool) unsigned UseEnumerators : 1; + /// Whether or not we're printing known HLSL code and should print HLSL + /// sugared types when possible. + LLVM_PREFERRED_TYPE(bool) + unsigned UseHLSLTypes : 1; + /// Callbacks to use to allow the behavior of printing to be customized. const PrintingCallbacks *Callbacks = nullptr; }; diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp index 58d01705d607b..4add4d3af69a3 100644 --- a/clang/lib/AST/TypePrinter.cpp +++ b/clang/lib/AST/TypePrinter.cpp @@ -644,16 +644,25 @@ void TypePrinter::printDependentAddressSpaceAfter( void TypePrinter::printDependentSizedExtVectorBefore( const DependentSizedExtVectorType *T, raw_ostream ) { + if (Policy.UseHLSLTypes) +OS << "vector<"; printBefore(T->getElementType(), OS); } void TypePrinter::printDependentSizedExtVectorAfter( const DependentSizedExtVectorType *T, raw_ostream ) { - OS << " __attribute__((ext_vector_type("; - if (T->getSizeExpr()) -T->getSizeExpr()->printPretty(OS, nullptr, Policy); - OS << ")))"; + if (Policy.UseHLSLTypes) { +OS << ", "; +if (T->getSizeExpr()) + T->getSizeExpr()->printPretty(OS, nullptr, Policy); +OS << ">"; + } else { +OS << " __attribute__((ext_vector_type("; +if (T->getSizeExpr()) + T->getSizeExpr()->printPretty(OS, nullptr, Policy); +OS << ")))"; + } printAfter(T->getElementType(), OS); } @@ -815,14 +824,23 @@ void TypePrinter::printDependentVectorAfter( void TypePrinter::printExtVectorBefore(const ExtVectorType *T, raw_ostream ) { + if (Policy.UseHLSLTypes) +OS << "vector<"; printBefore(T->getElementType(), OS); } void TypePrinter::printExtVectorAfter(const ExtVectorType *T, raw_ostream ) { printAfter(T->getElementType(), OS); - OS << " __attribute__((ext_vector_type("; - OS << T->getNumElements(); - OS << ")))"; + + if (Policy.UseHLSLTypes) { +OS << ", "; +OS << T->getNumElements(); +OS << ">"; + } else { +OS << " __attribute__((ext_vector_type("; +OS << T->getNumElements(); +OS << ")))"; + } } void TypePrinter::printConstantMatrixBefore(const ConstantMatrixType *T, diff --git a/clang/test/AST/HLSL/pch.hlsl b/clang/test/AST/HLSL/pch.hlsl index 839a13093bd15..483af0f5b4c79 100644 --- a/clang/test/AST/HLSL/pch.hlsl +++
[clang] [HLSL] Use hlsl vector template in type printer (PR #95489)
https://github.com/llvm-beanz edited https://github.com/llvm/llvm-project/pull/95489 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Use hlsl vector template in type printer (PR #95489)
https://github.com/llvm-beanz created https://github.com/llvm/llvm-project/pull/95489 In HLSL we really want to be using the HLSL vector template and other built-in sugared spellings for some builtin types. This updates the type printer to take an option to use HLSL type spellings. This changes printing vector type names from: T __attribute__((ext_vector_type(N))) To: vector >From e391736c66563ac7ddf8cffe4f686535158e3b25 Mon Sep 17 00:00:00 2001 From: Chris Bieneman Date: Thu, 13 Jun 2024 18:21:56 -0500 Subject: [PATCH] [HLSL] Use hlsl vector template in type printer In HLSL we really want to be using the HLSL vector template and other built-in sugared spellings for some builtin types. This updates the type printer to take an option to use HLSL type spellings. This changes printing vector type names from: T __attribute__((ext_vector_type(N))) To: vector --- clang/include/clang/AST/PrettyPrinter.h | 7 +- clang/lib/AST/TypePrinter.cpp | 32 +-- clang/test/AST/HLSL/pch.hlsl | 2 +- clang/test/AST/HLSL/pch_with_buf.hlsl | 2 +- clang/test/AST/HLSL/vector-alias.hlsl | 16 ++-- clang/test/AST/HLSL/vector-constructors.hlsl | 22 ++--- clang/test/SemaHLSL/BuiltIns/RWBuffers.hlsl | 2 +- .../test/SemaHLSL/BuiltIns/clamp-errors.hlsl | 2 +- clang/test/SemaHLSL/BuiltIns/dot-errors.hlsl | 2 +- clang/test/SemaHLSL/BuiltIns/lerp-errors.hlsl | 2 +- clang/test/SemaHLSL/BuiltIns/mad-errors.hlsl | 2 +- .../test/SemaHLSL/BuiltIns/vector-errors.hlsl | 4 +- .../BuiltinVector/ScalarSwizzleErrors.hlsl| 4 +- .../Types/BuiltinVector/ScalarSwizzles.hlsl | 56 ++-- .../SemaHLSL/VectorOverloadResolution.hlsl| 30 +++ .../standard_conversion_sequences.hlsl| 90 +-- 16 files changed, 149 insertions(+), 126 deletions(-) diff --git a/clang/include/clang/AST/PrettyPrinter.h b/clang/include/clang/AST/PrettyPrinter.h index da276e26049b0..332ac3c6a004a 100644 --- a/clang/include/clang/AST/PrettyPrinter.h +++ b/clang/include/clang/AST/PrettyPrinter.h @@ -77,7 +77,7 @@ struct PrintingPolicy { PrintCanonicalTypes(false), PrintInjectedClassNameWithArguments(true), UsePreferredNames(true), AlwaysIncludeTypeForTemplateArgument(false), CleanUglifiedParameters(false), EntireContentsOfLargeArray(true), -UseEnumerators(true) {} +UseEnumerators(true), UseHLSLTypes(LO.HLSL) {} /// Adjust this printing policy for cases where it's known that we're /// printing C++ code (for instance, if AST dumping reaches a C++-only @@ -342,6 +342,11 @@ struct PrintingPolicy { LLVM_PREFERRED_TYPE(bool) unsigned UseEnumerators : 1; + /// Whether or not we're printing known HLSL code and should print HLSL + /// sugared types when possible. + LLVM_PREFERRED_TYPE(bool) + unsigned UseHLSLTypes : 1; + /// Callbacks to use to allow the behavior of printing to be customized. const PrintingCallbacks *Callbacks = nullptr; }; diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp index 58d01705d607b..4add4d3af69a3 100644 --- a/clang/lib/AST/TypePrinter.cpp +++ b/clang/lib/AST/TypePrinter.cpp @@ -644,16 +644,25 @@ void TypePrinter::printDependentAddressSpaceAfter( void TypePrinter::printDependentSizedExtVectorBefore( const DependentSizedExtVectorType *T, raw_ostream ) { + if (Policy.UseHLSLTypes) +OS << "vector<"; printBefore(T->getElementType(), OS); } void TypePrinter::printDependentSizedExtVectorAfter( const DependentSizedExtVectorType *T, raw_ostream ) { - OS << " __attribute__((ext_vector_type("; - if (T->getSizeExpr()) -T->getSizeExpr()->printPretty(OS, nullptr, Policy); - OS << ")))"; + if (Policy.UseHLSLTypes) { +OS << ", "; +if (T->getSizeExpr()) + T->getSizeExpr()->printPretty(OS, nullptr, Policy); +OS << ">"; + } else { +OS << " __attribute__((ext_vector_type("; +if (T->getSizeExpr()) + T->getSizeExpr()->printPretty(OS, nullptr, Policy); +OS << ")))"; + } printAfter(T->getElementType(), OS); } @@ -815,14 +824,23 @@ void TypePrinter::printDependentVectorAfter( void TypePrinter::printExtVectorBefore(const ExtVectorType *T, raw_ostream ) { + if (Policy.UseHLSLTypes) +OS << "vector<"; printBefore(T->getElementType(), OS); } void TypePrinter::printExtVectorAfter(const ExtVectorType *T, raw_ostream ) { printAfter(T->getElementType(), OS); - OS << " __attribute__((ext_vector_type("; - OS << T->getNumElements(); - OS << ")))"; + + if (Policy.UseHLSLTypes) { +OS << ", "; +OS << T->getNumElements(); +OS << ">"; + } else { +OS << " __attribute__((ext_vector_type("; +OS << T->getNumElements(); +OS << ")))"; + } } void
[clang] [clang][modules] HeaderSearch::MarkFileModuleHeader sets textual headers' HeaderFileInfo non-external when it shouldn't (PR #89005)
https://github.com/ian-twilightcoder updated https://github.com/llvm/llvm-project/pull/89005 >From a416e28efabdf812756f452b823c4b1e7388c865 Mon Sep 17 00:00:00 2001 From: Ian Anderson Date: Tue, 16 Apr 2024 17:08:28 -0700 Subject: [PATCH] [clang][modules] HeaderSearch::MarkFileModuleHeader sets textual headers' HeaderFileInfo non-external when it shouldn't HeaderSearch::MarkFileModuleHeader is no longer properly checking for no-changes, and so sets the HeaderFileInfo for every `textual header` to non-external. --- clang/include/clang/Lex/HeaderSearch.h | 4 +- clang/lib/Lex/HeaderSearch.cpp | 14 - clang/unittests/Lex/HeaderSearchTest.cpp | 73 3 files changed, 87 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/Lex/HeaderSearch.h b/clang/include/clang/Lex/HeaderSearch.h index 5ac634d4e..d8ca1c528de36 100644 --- a/clang/include/clang/Lex/HeaderSearch.h +++ b/clang/include/clang/Lex/HeaderSearch.h @@ -90,7 +90,9 @@ struct HeaderFileInfo { LLVM_PREFERRED_TYPE(bool) unsigned isModuleHeader : 1; - /// Whether this header is a `textual header` in a module. + /// Whether this header is a `textual header` in a module. If a header is + /// textual in one module and normal in another module, this bit will not be + /// set, only `isModuleHeader`. LLVM_PREFERRED_TYPE(bool) unsigned isTextualModuleHeader : 1; diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp index 574723b33866a..18c0bab4a81e4 100644 --- a/clang/lib/Lex/HeaderSearch.cpp +++ b/clang/lib/Lex/HeaderSearch.cpp @@ -1313,11 +1313,19 @@ OptionalFileEntryRef HeaderSearch::LookupSubframeworkHeader( // File Info Management. //===--===// +static bool moduleMembershipNeedsMerge(const HeaderFileInfo *HFI, + ModuleMap::ModuleHeaderRole Role) { + if (ModuleMap::isModular(Role)) +return !HFI->isModuleHeader || HFI->isTextualModuleHeader; + else if (!HFI->isModuleHeader && (Role & ModuleMap::TextualHeader)) +return !HFI->isTextualModuleHeader; + else +return false; +} + static void mergeHeaderFileInfoModuleBits(HeaderFileInfo , bool isModuleHeader, bool isTextualModuleHeader) { - assert((!isModuleHeader || !isTextualModuleHeader) && - "A header can't build with a module and be textual at the same time"); HFI.isModuleHeader |= isModuleHeader; if (HFI.isModuleHeader) HFI.isTextualModuleHeader = false; @@ -1432,7 +1440,7 @@ void HeaderSearch::MarkFileModuleHeader(FileEntryRef FE, if ((Role & ModuleMap::ExcludedHeader)) return; auto *HFI = getExistingFileInfo(FE); -if (HFI && HFI->isModuleHeader) +if (HFI && !moduleMembershipNeedsMerge(HFI, Role)) return; } diff --git a/clang/unittests/Lex/HeaderSearchTest.cpp b/clang/unittests/Lex/HeaderSearchTest.cpp index c578fa72c859e..8bea41c642673 100644 --- a/clang/unittests/Lex/HeaderSearchTest.cpp +++ b/clang/unittests/Lex/HeaderSearchTest.cpp @@ -308,5 +308,78 @@ TEST_F(HeaderSearchTest, HeaderMapFrameworkLookup) { EXPECT_EQ(Search.getIncludeNameForHeader(FE), "Foo/Foo.h"); } +TEST_F(HeaderSearchTest, HeaderFileInfoMerge) { + auto AddHeader = [&](std::string HeaderPath) -> FileEntryRef { +VFS->addFile(HeaderPath, 0, + llvm::MemoryBuffer::getMemBufferCopy("", HeaderPath), + /*User=*/std::nullopt, /*Group=*/std::nullopt, + llvm::sys::fs::file_type::regular_file); +return *Search.LookupFile( +HeaderPath, SourceLocation(), /*isAngled=*/false, /*FromDir=*/nullptr, +/*CurDir=*/nullptr, /*Includers=*/{}, /*SearchPath=*/nullptr, +/*RelativePath=*/nullptr, /*RequestingModule=*/nullptr, +/*SuggestedModule=*/nullptr, /*IsMapped=*/nullptr, +/*IsFrameworkFound=*/nullptr); + }; + + class MockExternalHeaderFileInfoSource : public ExternalHeaderFileInfoSource { +HeaderFileInfo GetHeaderFileInfo(FileEntryRef FE) { + HeaderFileInfo HFI; + auto FileName = FE.getName(); + if (FileName == ModularPath) +HFI.mergeModuleMembership(ModuleMap::NormalHeader); + else if (FileName == TextualPath) +HFI.mergeModuleMembership(ModuleMap::TextualHeader); + HFI.External = true; + HFI.IsValid = true; + return HFI; +} + + public: +std::string ModularPath = "/modular.h"; +std::string TextualPath = "/textual.h"; + }; + + auto ExternalSource = new MockExternalHeaderFileInfoSource(); + Search.SetExternalSource(ExternalSource); + + // Everything should start out external. + auto ModularFE = AddHeader(ExternalSource->ModularPath); + auto TextualFE = AddHeader(ExternalSource->TextualPath); + EXPECT_TRUE(Search.getExistingFileInfo(ModularFE)->External); +
[clang] [clang][modules] HeaderSearch::MarkFileModuleHeader sets textual headers' HeaderFileInfo non-external when it shouldn't (PR #89005)
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 602634d70cba2c51f6177740c4a98a377d10ab6a f6bcc20d07248069dee1ff19c1aa334152b311a8 -- clang/include/clang/Lex/HeaderSearch.h clang/lib/Lex/HeaderSearch.cpp clang/unittests/Lex/HeaderSearchTest.cpp `` View the diff from clang-format here. ``diff diff --git a/clang/unittests/Lex/HeaderSearchTest.cpp b/clang/unittests/Lex/HeaderSearchTest.cpp index b55d52df14..8bea41c642 100644 --- a/clang/unittests/Lex/HeaderSearchTest.cpp +++ b/clang/unittests/Lex/HeaderSearchTest.cpp @@ -350,15 +350,19 @@ TEST_F(HeaderSearchTest, HeaderFileInfoMerge) { EXPECT_TRUE(Search.getExistingFileInfo(TextualFE)->External); // Marking the same role should keep it external - Search.MarkFileModuleHeader(ModularFE, ModuleMap::NormalHeader, /*isCompilingModuleHeader=*/false); - Search.MarkFileModuleHeader(TextualFE, ModuleMap::TextualHeader, /*isCompilingModuleHeader=*/false); + Search.MarkFileModuleHeader(ModularFE, ModuleMap::NormalHeader, + /*isCompilingModuleHeader=*/false); + Search.MarkFileModuleHeader(TextualFE, ModuleMap::TextualHeader, + /*isCompilingModuleHeader=*/false); EXPECT_TRUE(Search.getExistingFileInfo(ModularFE)->External); EXPECT_TRUE(Search.getExistingFileInfo(TextualFE)->External); // textual -> modular should update the HFI, but modular -> textual should be // a no-op. - Search.MarkFileModuleHeader(ModularFE, ModuleMap::TextualHeader, /*isCompilingModuleHeader=*/false); - Search.MarkFileModuleHeader(TextualFE, ModuleMap::NormalHeader, /*isCompilingModuleHeader=*/false); + Search.MarkFileModuleHeader(ModularFE, ModuleMap::TextualHeader, + /*isCompilingModuleHeader=*/false); + Search.MarkFileModuleHeader(TextualFE, ModuleMap::NormalHeader, + /*isCompilingModuleHeader=*/false); auto ModularFI = Search.getExistingFileInfo(ModularFE); auto TextualFI = Search.getExistingFileInfo(TextualFE); EXPECT_TRUE(ModularFI->External); @@ -369,8 +373,10 @@ TEST_F(HeaderSearchTest, HeaderFileInfoMerge) { EXPECT_FALSE(ModularFI->isTextualModuleHeader); // Compiling the module should make the HFI local. - Search.MarkFileModuleHeader(ModularFE, ModuleMap::NormalHeader, /*isCompilingModuleHeader=*/true); - Search.MarkFileModuleHeader(TextualFE, ModuleMap::NormalHeader, /*isCompilingModuleHeader=*/true); + Search.MarkFileModuleHeader(ModularFE, ModuleMap::NormalHeader, + /*isCompilingModuleHeader=*/true); + Search.MarkFileModuleHeader(TextualFE, ModuleMap::NormalHeader, + /*isCompilingModuleHeader=*/true); EXPECT_FALSE(Search.getExistingFileInfo(ModularFE)->External); EXPECT_FALSE(Search.getExistingFileInfo(TextualFE)->External); } `` https://github.com/llvm/llvm-project/pull/89005 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][modules] HeaderSearch::MarkFileModuleHeader sets textual headers' HeaderFileInfo non-external when it shouldn't (PR #89005)
https://github.com/ian-twilightcoder updated https://github.com/llvm/llvm-project/pull/89005 >From f6bcc20d07248069dee1ff19c1aa334152b311a8 Mon Sep 17 00:00:00 2001 From: Ian Anderson Date: Tue, 16 Apr 2024 17:08:28 -0700 Subject: [PATCH] [clang][modules] HeaderSearch::MarkFileModuleHeader sets textual headers' HeaderFileInfo non-external when it shouldn't HeaderSearch::MarkFileModuleHeader is no longer properly checking for no-changes, and so sets the HeaderFileInfo for every `textual header` to non-external. --- clang/include/clang/Lex/HeaderSearch.h | 4 +- clang/lib/Lex/HeaderSearch.cpp | 14 +++-- clang/unittests/Lex/HeaderSearchTest.cpp | 67 3 files changed, 81 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/Lex/HeaderSearch.h b/clang/include/clang/Lex/HeaderSearch.h index 5ac634d4e..d8ca1c528de36 100644 --- a/clang/include/clang/Lex/HeaderSearch.h +++ b/clang/include/clang/Lex/HeaderSearch.h @@ -90,7 +90,9 @@ struct HeaderFileInfo { LLVM_PREFERRED_TYPE(bool) unsigned isModuleHeader : 1; - /// Whether this header is a `textual header` in a module. + /// Whether this header is a `textual header` in a module. If a header is + /// textual in one module and normal in another module, this bit will not be + /// set, only `isModuleHeader`. LLVM_PREFERRED_TYPE(bool) unsigned isTextualModuleHeader : 1; diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp index 574723b33866a..18c0bab4a81e4 100644 --- a/clang/lib/Lex/HeaderSearch.cpp +++ b/clang/lib/Lex/HeaderSearch.cpp @@ -1313,11 +1313,19 @@ OptionalFileEntryRef HeaderSearch::LookupSubframeworkHeader( // File Info Management. //===--===// +static bool moduleMembershipNeedsMerge(const HeaderFileInfo *HFI, + ModuleMap::ModuleHeaderRole Role) { + if (ModuleMap::isModular(Role)) +return !HFI->isModuleHeader || HFI->isTextualModuleHeader; + else if (!HFI->isModuleHeader && (Role & ModuleMap::TextualHeader)) +return !HFI->isTextualModuleHeader; + else +return false; +} + static void mergeHeaderFileInfoModuleBits(HeaderFileInfo , bool isModuleHeader, bool isTextualModuleHeader) { - assert((!isModuleHeader || !isTextualModuleHeader) && - "A header can't build with a module and be textual at the same time"); HFI.isModuleHeader |= isModuleHeader; if (HFI.isModuleHeader) HFI.isTextualModuleHeader = false; @@ -1432,7 +1440,7 @@ void HeaderSearch::MarkFileModuleHeader(FileEntryRef FE, if ((Role & ModuleMap::ExcludedHeader)) return; auto *HFI = getExistingFileInfo(FE); -if (HFI && HFI->isModuleHeader) +if (HFI && !moduleMembershipNeedsMerge(HFI, Role)) return; } diff --git a/clang/unittests/Lex/HeaderSearchTest.cpp b/clang/unittests/Lex/HeaderSearchTest.cpp index c578fa72c859e..b55d52df14d5d 100644 --- a/clang/unittests/Lex/HeaderSearchTest.cpp +++ b/clang/unittests/Lex/HeaderSearchTest.cpp @@ -308,5 +308,72 @@ TEST_F(HeaderSearchTest, HeaderMapFrameworkLookup) { EXPECT_EQ(Search.getIncludeNameForHeader(FE), "Foo/Foo.h"); } +TEST_F(HeaderSearchTest, HeaderFileInfoMerge) { + auto AddHeader = [&](std::string HeaderPath) -> FileEntryRef { +VFS->addFile(HeaderPath, 0, + llvm::MemoryBuffer::getMemBufferCopy("", HeaderPath), + /*User=*/std::nullopt, /*Group=*/std::nullopt, + llvm::sys::fs::file_type::regular_file); +return *Search.LookupFile( +HeaderPath, SourceLocation(), /*isAngled=*/false, /*FromDir=*/nullptr, +/*CurDir=*/nullptr, /*Includers=*/{}, /*SearchPath=*/nullptr, +/*RelativePath=*/nullptr, /*RequestingModule=*/nullptr, +/*SuggestedModule=*/nullptr, /*IsMapped=*/nullptr, +/*IsFrameworkFound=*/nullptr); + }; + + class MockExternalHeaderFileInfoSource : public ExternalHeaderFileInfoSource { +HeaderFileInfo GetHeaderFileInfo(FileEntryRef FE) { + HeaderFileInfo HFI; + auto FileName = FE.getName(); + if (FileName == ModularPath) +HFI.mergeModuleMembership(ModuleMap::NormalHeader); + else if (FileName == TextualPath) +HFI.mergeModuleMembership(ModuleMap::TextualHeader); + HFI.External = true; + HFI.IsValid = true; + return HFI; +} + + public: +std::string ModularPath = "/modular.h"; +std::string TextualPath = "/textual.h"; + }; + + auto ExternalSource = new MockExternalHeaderFileInfoSource(); + Search.SetExternalSource(ExternalSource); + + // Everything should start out external. + auto ModularFE = AddHeader(ExternalSource->ModularPath); + auto TextualFE = AddHeader(ExternalSource->TextualPath); + EXPECT_TRUE(Search.getExistingFileInfo(ModularFE)->External); +
[clang] [clang][modules] HeaderSearch::MarkFileModuleHeader sets textual headers' HeaderFileInfo non-external when it shouldn't (PR #89005)
ian-twilightcoder wrote: > From Jan: > > > Maybe we can add the number of external HeaderFileInfos to > > HeaderSearch::PrintStats() and have a test that checks for it. > > The flag to enable that output is -show-stats I think. We tried this, but it seems that by the time the modules compile, everything ends up being local instead of external anyway. I think a unit test is probably good enough for this one since we aren't even sure what the practical consequence is of this bug. https://github.com/llvm/llvm-project/pull/89005 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][modules] HeaderSearch::MarkFileModuleHeader sets textual headers' HeaderFileInfo non-external when it shouldn't (PR #89005)
https://github.com/ian-twilightcoder updated https://github.com/llvm/llvm-project/pull/89005 >From 011ff5a95a4a5de1dc6ae2d271ae42f28075b2b0 Mon Sep 17 00:00:00 2001 From: Ian Anderson Date: Tue, 16 Apr 2024 17:08:28 -0700 Subject: [PATCH] [clang][modules] HeaderSearch::MarkFileModuleHeader sets textual headers' HeaderFileInfo non-external when it shouldn't HeaderSearch::MarkFileModuleHeader is no longer properly checking for no-changes, and so sets the HeaderFileInfo for every `textual header` to non-external. --- clang/include/clang/Lex/HeaderSearch.h | 4 +- clang/lib/Lex/HeaderSearch.cpp | 14 +++-- clang/unittests/Lex/HeaderSearchTest.cpp | 67 3 files changed, 81 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/Lex/HeaderSearch.h b/clang/include/clang/Lex/HeaderSearch.h index 5ac634d4e..d8ca1c528de36 100644 --- a/clang/include/clang/Lex/HeaderSearch.h +++ b/clang/include/clang/Lex/HeaderSearch.h @@ -90,7 +90,9 @@ struct HeaderFileInfo { LLVM_PREFERRED_TYPE(bool) unsigned isModuleHeader : 1; - /// Whether this header is a `textual header` in a module. + /// Whether this header is a `textual header` in a module. If a header is + /// textual in one module and normal in another module, this bit will not be + /// set, only `isModuleHeader`. LLVM_PREFERRED_TYPE(bool) unsigned isTextualModuleHeader : 1; diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp index 574723b33866a..18c0bab4a81e4 100644 --- a/clang/lib/Lex/HeaderSearch.cpp +++ b/clang/lib/Lex/HeaderSearch.cpp @@ -1313,11 +1313,19 @@ OptionalFileEntryRef HeaderSearch::LookupSubframeworkHeader( // File Info Management. //===--===// +static bool moduleMembershipNeedsMerge(const HeaderFileInfo *HFI, + ModuleMap::ModuleHeaderRole Role) { + if (ModuleMap::isModular(Role)) +return !HFI->isModuleHeader || HFI->isTextualModuleHeader; + else if (!HFI->isModuleHeader && (Role & ModuleMap::TextualHeader)) +return !HFI->isTextualModuleHeader; + else +return false; +} + static void mergeHeaderFileInfoModuleBits(HeaderFileInfo , bool isModuleHeader, bool isTextualModuleHeader) { - assert((!isModuleHeader || !isTextualModuleHeader) && - "A header can't build with a module and be textual at the same time"); HFI.isModuleHeader |= isModuleHeader; if (HFI.isModuleHeader) HFI.isTextualModuleHeader = false; @@ -1432,7 +1440,7 @@ void HeaderSearch::MarkFileModuleHeader(FileEntryRef FE, if ((Role & ModuleMap::ExcludedHeader)) return; auto *HFI = getExistingFileInfo(FE); -if (HFI && HFI->isModuleHeader) +if (HFI && !moduleMembershipNeedsMerge(HFI, Role)) return; } diff --git a/clang/unittests/Lex/HeaderSearchTest.cpp b/clang/unittests/Lex/HeaderSearchTest.cpp index c578fa72c859e..f1735c2d46946 100644 --- a/clang/unittests/Lex/HeaderSearchTest.cpp +++ b/clang/unittests/Lex/HeaderSearchTest.cpp @@ -308,5 +308,72 @@ TEST_F(HeaderSearchTest, HeaderMapFrameworkLookup) { EXPECT_EQ(Search.getIncludeNameForHeader(FE), "Foo/Foo.h"); } +TEST_F(HeaderSearchTest, HeaderFileInfoMerge) { + auto AddHeader = [&](std::string HeaderPath) -> FileEntryRef { +VFS->addFile(HeaderPath, 0, + llvm::MemoryBuffer::getMemBufferCopy("", HeaderPath), + /*User=*/std::nullopt, /*Group=*/std::nullopt, + llvm::sys::fs::file_type::regular_file); +return *Search.LookupFile( +HeaderPath, SourceLocation(), /*isAngled=*/false, /*FromDir=*/nullptr, +/*CurDir=*/nullptr, /*Includers=*/{}, /*SearchPath=*/nullptr, +/*RelativePath=*/nullptr, /*RequestingModule=*/nullptr, +/*SuggestedModule=*/nullptr, /*IsMapped=*/nullptr, +/*IsFrameworkFound=*/nullptr); + }; + + class MockExternalHeaderFileInfoSource : public ExternalHeaderFileInfoSource { +HeaderFileInfo GetHeaderFileInfo(FileEntryRef FE) { + HeaderFileInfo HFI; + auto FileName = FE.getName(); + if (FileName == ModularPath) +HFI.mergeModuleMembership(ModuleMap::NormalHeader); + else if (FileName == TextualPath) +HFI.mergeModuleMembership(ModuleMap::TextualHeader); + HFI.External = true; + HFI.IsValid = true; + return HFI; +} + + public: +std::string ModularPath = "/modular.h"; +std::string TextualPath = "/textual.h"; + }; + + auto ExternalSource = new MockExternalHeaderFileInfoSource(); + Search.SetExternalSource(ExternalSource); + + // Everything should start out external. + auto ModularFE = AddHeader(ExternalSource->ModularPath); + auto TextualFE = AddHeader(ExternalSource->TextualPath); + EXPECT_TRUE(Search.getExistingFileInfo(ModularFE)->External); +
[clang] [Safe Buffers] Serialize unsafe_buffer_usage pragmas (PR #92031)
@@ -1911,18 +1911,22 @@ SourceManager::getDecomposedIncludedLoc(FileID FID) const { return DecompLoc; } -FileID SourceManager::getFirstFIDOfLoadedAST(SourceLocation Loc) const { +unsigned SourceManager::getUniqueLoadedASTID(SourceLocation Loc) const { assert(isLoadedSourceLocation(Loc) && "Must be a source location in a loaded PCH/Module file"); auto [FID, Ignore] = getDecomposedLoc(Loc); + // `LoadedSLocEntryAllocBegin` stores the sorted lowest FID of each loaded + // allocation. Later allocations have lower FileIDs. The call below is to find + // the lowest FID of a loaded allocation from any FID in the same allocation. + // The lowest FID is used to identify a loaded allocation. const FileID *FirstFID = llvm::lower_bound(LoadedSLocEntryAllocBegin, FID, std::greater{}); assert(FirstFID && "The failure to find the first FileID of a " "loaded AST from a loaded source location was unexpected."); - return *FirstFID; + return FirstFID->getHashValue(); haoNoQ wrote: Hmm can we go back to returning `FileID` here? We really shouldn't rely on the fact that the _hash_ value is equal to the actual thing we're looking for. https://github.com/llvm/llvm-project/pull/92031 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Safe Buffers] Serialize unsafe_buffer_usage pragmas (PR #92031)
https://github.com/ziqingluo-90 updated https://github.com/llvm/llvm-project/pull/92031 >From ac5aeb5c3a134d085320fc7fc5cf3f2c8c41a1f1 Mon Sep 17 00:00:00 2001 From: ziqingluo-90 Date: Mon, 13 May 2024 13:31:21 -0700 Subject: [PATCH 1/6] fix safe buffer opt-out region serialization --- clang/include/clang/Lex/Preprocessor.h| 22 +++- .../include/clang/Serialization/ASTBitCodes.h | 3 + clang/lib/Lex/Preprocessor.cpp| 106 ++ clang/lib/Serialization/ASTReader.cpp | 11 ++ clang/lib/Serialization/ASTWriter.cpp | 7 ++ clang/test/Modules/Inputs/SafeBuffers/base.h | 9 ++ .../SafeBuffers/safe_buffers_test.modulemap | 10 ++ .../Modules/Inputs/SafeBuffers/test_sub1.h| 20 .../Modules/Inputs/SafeBuffers/test_sub2.h| 11 ++ clang/test/Modules/safe_buffers_optout.cpp| 39 +++ ...unsafe-buffer-usage-pragma-pch-complex.cpp | 72 .../warn-unsafe-buffer-usage-pragma-pch.cpp | 27 + 12 files changed, 314 insertions(+), 23 deletions(-) create mode 100644 clang/test/Modules/Inputs/SafeBuffers/base.h create mode 100644 clang/test/Modules/Inputs/SafeBuffers/safe_buffers_test.modulemap create mode 100644 clang/test/Modules/Inputs/SafeBuffers/test_sub1.h create mode 100644 clang/test/Modules/Inputs/SafeBuffers/test_sub2.h create mode 100644 clang/test/Modules/safe_buffers_optout.cpp create mode 100644 clang/test/SemaCXX/warn-unsafe-buffer-usage-pragma-pch-complex.cpp create mode 100644 clang/test/SemaCXX/warn-unsafe-buffer-usage-pragma-pch.cpp diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h index e89b4a2c5230e..8d6884ebe7597 100644 --- a/clang/include/clang/Lex/Preprocessor.h +++ b/clang/include/clang/Lex/Preprocessor.h @@ -2883,11 +2883,15 @@ class Preprocessor { /// otherwise. SourceLocation CurrentSafeBufferOptOutStart; // It is used to report the start location of an never-closed region. - // An ordered sequence of "-Wunsafe-buffer-usage" opt-out regions in one - // translation unit. Each region is represented by a pair of start and end - // locations. A region is "open" if its' start and end locations are + using SafeBufferOptOutMapTy = + SmallVector, 16>; + // An ordered sequence of "-Wunsafe-buffer-usage" opt-out regions in this + // translation unit. Each region is represented by a pair of start and + // end locations. A region is "open" if its' start and end locations are // identical. - SmallVector, 8> SafeBufferOptOutMap; + SafeBufferOptOutMapTy SafeBufferOptOutMap; + // `SafeBufferOptOutMap`s of loaded files: + llvm::DenseMap LoadedSafeBufferOptOutMap; public: /// \return true iff the given `Loc` is in a "-Wunsafe-buffer-usage" opt-out @@ -2918,6 +2922,16 @@ class Preprocessor { /// opt-out region bool isPPInSafeBufferOptOutRegion(SourceLocation ); + /// \return a sequence of SourceLocations representing ordered opt-out regions + /// specified by + /// `\#pragma clang unsafe_buffer_usage begin/end`s of this translation unit. + SmallVector serializeSafeBufferOptOutMap() const; + + /// \param SrcLocSeqs a sequence of SourceLocations deserialized from a + /// record of code `PP_UNSAFE_BUFFER_USAGE`. + void setDeserializedSafeBufferOptOutMap( + const SmallVectorImpl ); + private: /// Helper functions to forward lexing to the actual lexer. They all share the /// same signature. diff --git a/clang/include/clang/Serialization/ASTBitCodes.h b/clang/include/clang/Serialization/ASTBitCodes.h index dcfa4ac0c1967..d1a0eba943039 100644 --- a/clang/include/clang/Serialization/ASTBitCodes.h +++ b/clang/include/clang/Serialization/ASTBitCodes.h @@ -775,6 +775,9 @@ enum ASTRecordTypes { /// Record code for lexical and visible block for delayed namespace in /// reduced BMI. DELAYED_NAMESPACE_LEXICAL_VISIBLE_RECORD = 68, + + /// Record code for \#pragma clang unsafe_buffer_usage begin/end + PP_UNSAFE_BUFFER_USAGE = 69, }; /// Record types used within a source manager block. diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp index 0b70192743a39..6a41e3d4138aa 100644 --- a/clang/lib/Lex/Preprocessor.cpp +++ b/clang/lib/Lex/Preprocessor.cpp @@ -58,6 +58,7 @@ #include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" +#include "llvm/ADT/iterator_range.h" #include "llvm/Support/Capacity.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/MemoryBuffer.h" @@ -1483,26 +1484,41 @@ void Preprocessor::emitFinalMacroWarning(const Token , } bool Preprocessor::isSafeBufferOptOut(const SourceManager , - const SourceLocation ) const { - // Try to find a region in `SafeBufferOptOutMap` where `Loc` is in: - auto FirstRegionEndingAfterLoc = llvm::partition_point( - SafeBufferOptOutMap, - [, - ](const std::pair ) { -return
[clang] [Clang][AMDGPU] Add a new builtin type for buffer rsrc (PR #94830)
@@ -0,0 +1,69 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py + // REQUIRES: amdgpu-registered-target + // RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu verde -emit-llvm -o - %s | FileCheck %s + // RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu tonga -emit-llvm -o - %s | FileCheck %s + // RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx1100 -emit-llvm -o - %s | FileCheck %s + +typedef struct AA_ty { + int x; + __amdgcn_buffer_rsrc_t r; +} AA; + +AA getAA(void *p); +__amdgcn_buffer_rsrc_t getBuffer(void *p); +void consumeBuffer(__amdgcn_buffer_rsrc_t); + +// CHECK-LABEL: @consumeBufferPtr( shiltian wrote: `update_cc_test_checks.py` doesn't appear to have an argument to check the function return type. I added `--function-signature` though. The `ret` instruction at the end of each function can be used to verify the return type. https://github.com/llvm/llvm-project/pull/94830 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AMDGPU] Add a new builtin type for buffer rsrc (PR #94830)
https://github.com/shiltian updated https://github.com/llvm/llvm-project/pull/94830 >From 24703e0480835fb2c491b7140c2ab5022218777d Mon Sep 17 00:00:00 2001 From: Shilei Tian Date: Thu, 13 Jun 2024 18:43:29 -0400 Subject: [PATCH] [Clang][AMDGPU] Add a new builtin type for buffer rsrc --- clang/include/clang/AST/ASTContext.h | 2 + clang/include/clang/AST/Type.h| 3 + clang/include/clang/AST/TypeProperties.td | 4 + clang/include/clang/Basic/AMDGPUTypes.def | 21 + .../include/clang/Serialization/ASTBitCodes.h | 5 +- clang/lib/AST/ASTContext.cpp | 16 clang/lib/AST/ASTImporter.cpp | 4 + clang/lib/AST/ExprConstant.cpp| 2 + clang/lib/AST/ItaniumMangle.cpp | 6 ++ clang/lib/AST/MicrosoftMangle.cpp | 2 + clang/lib/AST/NSAPI.cpp | 2 + clang/lib/AST/PrintfFormatString.cpp | 2 + clang/lib/AST/Type.cpp| 6 ++ clang/lib/AST/TypeLoc.cpp | 2 + clang/lib/CodeGen/CGDebugInfo.cpp | 11 ++- clang/lib/CodeGen/CGDebugInfo.h | 2 + clang/lib/CodeGen/CodeGenTypes.cpp| 5 ++ clang/lib/CodeGen/ItaniumCXXABI.cpp | 2 + clang/lib/Index/USRGeneration.cpp | 4 + clang/lib/Sema/Sema.cpp | 7 ++ clang/lib/Sema/SemaExpr.cpp | 4 + clang/lib/Serialization/ASTCommon.cpp | 5 ++ clang/lib/Serialization/ASTReader.cpp | 5 ++ clang/test/AST/ast-dump-amdgpu-types.c| 10 +++ .../amdgpu-buffer-rsrc-type-debug-info.c | 9 ++ .../amdgpu-buffer-rsrc-typeinfo.cpp | 9 ++ .../CodeGenOpenCL/amdgcn-buffer-rsrc-type.cl | 84 +++ clang/test/SemaCXX/amdgpu-buffer-rsrc.cpp | 17 clang/tools/libclang/CIndex.cpp | 2 + 29 files changed, 251 insertions(+), 2 deletions(-) create mode 100644 clang/include/clang/Basic/AMDGPUTypes.def create mode 100644 clang/test/AST/ast-dump-amdgpu-types.c create mode 100644 clang/test/CodeGen/amdgpu-buffer-rsrc-type-debug-info.c create mode 100644 clang/test/CodeGenCXX/amdgpu-buffer-rsrc-typeinfo.cpp create mode 100644 clang/test/CodeGenOpenCL/amdgcn-buffer-rsrc-type.cl create mode 100644 clang/test/SemaCXX/amdgpu-buffer-rsrc.cpp diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index 53ece996769a8..4d1f440506e09 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -1147,6 +1147,8 @@ class ASTContext : public RefCountedBase { #include "clang/Basic/RISCVVTypes.def" #define WASM_TYPE(Name, Id, SingletonId) CanQualType SingletonId; #include "clang/Basic/WebAssemblyReferenceTypes.def" +#define AMDGPU_TYPE(Name, Id, SingletonId) CanQualType SingletonId; +#include "clang/Basic/AMDGPUTypes.def" // Types for deductions in C++0x [stmt.ranged]'s desugaring. Built on demand. mutable QualType AutoDeductTy; // Deduction against 'auto'. diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h index fab233b62d8d1..61246479188e9 100644 --- a/clang/include/clang/AST/Type.h +++ b/clang/include/clang/AST/Type.h @@ -3015,6 +3015,9 @@ class BuiltinType : public Type { // WebAssembly reference types #define WASM_TYPE(Name, Id, SingletonId) Id, #include "clang/Basic/WebAssemblyReferenceTypes.def" +// AMDGPU types +#define AMDGPU_TYPE(Name, Id, SingletonId) Id, +#include "clang/Basic/AMDGPUTypes.def" // All other builtin types #define BUILTIN_TYPE(Id, SingletonId) Id, #define LAST_BUILTIN_TYPE(Id) LastKind = Id diff --git a/clang/include/clang/AST/TypeProperties.td b/clang/include/clang/AST/TypeProperties.td index 40dd16f080e2e..aba14b222a03a 100644 --- a/clang/include/clang/AST/TypeProperties.td +++ b/clang/include/clang/AST/TypeProperties.td @@ -861,6 +861,10 @@ let Class = BuiltinType in { case BuiltinType::ID: return ctx.SINGLETON_ID; #include "clang/Basic/WebAssemblyReferenceTypes.def" +#define AMDGPU_TYPE(NAME, ID, SINGLETON_ID) \ + case BuiltinType::ID: return ctx.SINGLETON_ID; +#include "clang/Basic/AMDGPUTypes.def" + #define BUILTIN_TYPE(ID, SINGLETON_ID) \ case BuiltinType::ID: return ctx.SINGLETON_ID; #include "clang/AST/BuiltinTypes.def" diff --git a/clang/include/clang/Basic/AMDGPUTypes.def b/clang/include/clang/Basic/AMDGPUTypes.def new file mode 100644 index 0..c035c6dbced11 --- /dev/null +++ b/clang/include/clang/Basic/AMDGPUTypes.def @@ -0,0 +1,21 @@ +//===-- AMDGPUTypes.def - Metadata about AMDGPU types ---*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// This file defines various AMDGPU
[clang] [clang] Clean up macOS version flags (PR #95374)
@@ -389,6 +389,7 @@ my %CompilerLinkerOptionMap = ( '-target' => 1, '-v' => 0, '-mmacosx-version-min' => 0, # This is really a 1 argument, but always has '=' + '-mmacos-version-min' => 0, # This is really a 1 argument, but always has '=' haoNoQ wrote: Nice nice nice thanks! https://github.com/llvm/llvm-project/pull/95374 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] fix(95366): enhance cast operation safety with LValue validation (PR #95479)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Oleksandr T. (a-tarasyuk) Changes Fixes #95366 --- Full diff: https://github.com/llvm/llvm-project/pull/95479.diff 3 Files Affected: - (modified) clang/docs/ReleaseNotes.rst (+1) - (modified) clang/lib/AST/ExprConstant.cpp (+3) - (added) clang/test/Sema/integral-to-ptr.c (+3) ``diff diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 8c2f737836a9d..77906360b 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -847,6 +847,7 @@ Bug Fixes to C++ Support - Fixed several bugs in capturing variables within unevaluated contexts. (#GH63845), (#GH67260), (#GH69307), (#GH88081), (#GH89496), (#GH90669) and (#GH91633). - Fixed handling of brace ellison when building deduction guides. (#GH64625), (#GH83368). +- Fix an assertion failure caused by non-lvalue usage in lvalue context. (GH95366). Bug Fixes to AST Handling ^ diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 7178f081d9cf3..08bee806f172f 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -9325,6 +9325,9 @@ bool PointerExprEvaluator::VisitCastExpr(const CastExpr *E) { Result.IsNullPtr = false; return true; } else { + if (!Value.isLValue()) +return false; + // Cast is of an lvalue, no need to change value. Result.setFrom(Info.Ctx, Value); return true; diff --git a/clang/test/Sema/integral-to-ptr.c b/clang/test/Sema/integral-to-ptr.c new file mode 100644 index 0..99f83c3e52057 --- /dev/null +++ b/clang/test/Sema/integral-to-ptr.c @@ -0,0 +1,3 @@ +// RUN: %clang_cc1 %s -verify -fsyntax-only -std=c11 + +int x(void) { e: b: ; return & - & < x; } // expected-warning {{ordered comparison between pointer and integer ('long' and 'int (*)(void)')}} `` https://github.com/llvm/llvm-project/pull/95479 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Make warning pragma override -Werror=foo and DefaultError warnings (PR #93647)
MaskRay wrote: Ping:) https://github.com/llvm/llvm-project/pull/93647 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] fix(95366): enhance cast operation safety with LValue validation (PR #95479)
https://github.com/a-tarasyuk created https://github.com/llvm/llvm-project/pull/95479 Fixes #95366 >From d66fdcbe0a56e17dbd25e6d2ed5bdcce1970fdea Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 14 Jun 2024 01:26:34 +0300 Subject: [PATCH] fix(95366): enhance cast operation safety with LValue validation --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/AST/ExprConstant.cpp| 3 +++ clang/test/Sema/integral-to-ptr.c | 3 +++ 3 files changed, 7 insertions(+) create mode 100644 clang/test/Sema/integral-to-ptr.c diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 8c2f737836a9d..77906360b 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -847,6 +847,7 @@ Bug Fixes to C++ Support - Fixed several bugs in capturing variables within unevaluated contexts. (#GH63845), (#GH67260), (#GH69307), (#GH88081), (#GH89496), (#GH90669) and (#GH91633). - Fixed handling of brace ellison when building deduction guides. (#GH64625), (#GH83368). +- Fix an assertion failure caused by non-lvalue usage in lvalue context. (GH95366). Bug Fixes to AST Handling ^ diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 7178f081d9cf3..08bee806f172f 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -9325,6 +9325,9 @@ bool PointerExprEvaluator::VisitCastExpr(const CastExpr *E) { Result.IsNullPtr = false; return true; } else { + if (!Value.isLValue()) +return false; + // Cast is of an lvalue, no need to change value. Result.setFrom(Info.Ctx, Value); return true; diff --git a/clang/test/Sema/integral-to-ptr.c b/clang/test/Sema/integral-to-ptr.c new file mode 100644 index 0..99f83c3e52057 --- /dev/null +++ b/clang/test/Sema/integral-to-ptr.c @@ -0,0 +1,3 @@ +// RUN: %clang_cc1 %s -verify -fsyntax-only -std=c11 + +int x(void) { e: b: ; return & - & < x; } // expected-warning {{ordered comparison between pointer and integer ('long' and 'int (*)(void)')}} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AMDGPU] Add a new builtin type for buffer rsrc (PR #94830)
@@ -0,0 +1,69 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py + // REQUIRES: amdgpu-registered-target + // RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu verde -emit-llvm -o - %s | FileCheck %s + // RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu tonga -emit-llvm -o - %s | FileCheck %s + // RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx1100 -emit-llvm -o - %s | FileCheck %s + +typedef struct AA_ty { + int x; + __amdgcn_buffer_rsrc_t r; +} AA; + +AA getAA(void *p); +__amdgcn_buffer_rsrc_t getBuffer(void *p); +void consumeBuffer(__amdgcn_buffer_rsrc_t); + +// CHECK-LABEL: @consumeBufferPtr( arsenm wrote: The interesting check here is the IR type in the function signature which are missing. Also should test it as a return value (and return value in a struct) https://github.com/llvm/llvm-project/pull/94830 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AArch64] set AppleA14 architecture version to v8.4-a (PR #92600)
jroelofs wrote: > @jroelofs on a slight tangent, when do we get to add information on the M4 > chip? https://github.com/llvm/llvm-project/pull/95478 https://github.com/llvm/llvm-project/pull/92600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Support [[guarded_by(mutex)]] attribute inside C struct (PR #94216)
pdherbemont wrote: Follow-up PR #95455 https://github.com/llvm/llvm-project/pull/94216 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C++20] [Modules] [Itanium ABI] Generate the vtable in the module unit of dynamic classes (PR #75912)
@@ -318,6 +318,9 @@ namespace { if (Diags.hasUnrecoverableErrorOccurred()) return; + if (RD->shouldEmitInExternalSource()) efriedma-quic wrote: The way I see it, Sema should have the exact right answer for whether the vtable is required. If we need to second-guess the choice later, that means Sema didn't compute the right thing in the first place, which would be a bug in Sema. https://github.com/llvm/llvm-project/pull/75912 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Implement P2280R4 Using unknown pointers and references in constant expressions (PR #95474)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Shafik Yaghmour (shafik) Changes P2280R4 allows the use of references in pointers of unknown origins in a constant expression context but only in specific cases that could be constant expressions. We track whether a variable is a constexpr unknown in a constant expression by setting a flag in either APValue or LValue and using this flag to prevent using unknown values in places where it is not allowed. Fixes: https://github.com/llvm/llvm-project/issues/63139 https://github.com/llvm/llvm-project/issues/63117 --- Patch is 21.02 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/95474.diff 6 Files Affected: - (modified) clang/include/clang/AST/APValue.h (+33-15) - (modified) clang/lib/AST/APValue.cpp (+10-2) - (modified) clang/lib/AST/ExprConstant.cpp (+76-9) - (modified) clang/test/SemaCXX/constant-expression-cxx11.cpp (+9-7) - (modified) clang/test/SemaCXX/constant-expression-cxx2a.cpp (+1-2) - (added) clang/test/SemaCXX/constant-expression-p2280r4.cpp (+54) ``diff diff --git a/clang/include/clang/AST/APValue.h b/clang/include/clang/AST/APValue.h index c4206b73b1156..6352348107a64 100644 --- a/clang/include/clang/AST/APValue.h +++ b/clang/include/clang/AST/APValue.h @@ -249,6 +249,7 @@ class APValue { struct NoLValuePath {}; struct UninitArray {}; struct UninitStruct {}; + struct ConstexprUnknown {}; template friend class clang::serialization::BasicReaderBase; friend class ASTImporter; @@ -256,6 +257,7 @@ class APValue { private: ValueKind Kind; + bool AllowConstexprUnknown = false; struct ComplexAPSInt { APSInt Real, Imag; @@ -314,53 +316,69 @@ class APValue { DataType Data; public: - APValue() : Kind(None) {} - explicit APValue(APSInt I) : Kind(None) { + bool allowConstexprUnknown() const { return AllowConstexprUnknown; } + + void setConstexprUnknown() { AllowConstexprUnknown = true; } + + APValue() : Kind(None), AllowConstexprUnknown(false) {} + explicit APValue(APSInt I) : Kind(None), AllowConstexprUnknown(false) { MakeInt(); setInt(std::move(I)); } - explicit APValue(APFloat F) : Kind(None) { + explicit APValue(APFloat F) : Kind(None), AllowConstexprUnknown(false) { MakeFloat(); setFloat(std::move(F)); } - explicit APValue(APFixedPoint FX) : Kind(None) { + explicit APValue(APFixedPoint FX) : Kind(None), AllowConstexprUnknown(false) { MakeFixedPoint(std::move(FX)); } - explicit APValue(const APValue *E, unsigned N) : Kind(None) { + explicit APValue(const APValue *E, unsigned N) + : Kind(None), AllowConstexprUnknown(false) { MakeVector(); setVector(E, N); } - APValue(APSInt R, APSInt I) : Kind(None) { + APValue(APSInt R, APSInt I) : Kind(None), AllowConstexprUnknown(false) { MakeComplexInt(); setComplexInt(std::move(R), std::move(I)); } - APValue(APFloat R, APFloat I) : Kind(None) { + APValue(APFloat R, APFloat I) : Kind(None), AllowConstexprUnknown(false) { MakeComplexFloat(); setComplexFloat(std::move(R), std::move(I)); } APValue(const APValue ); APValue(APValue &); APValue(LValueBase B, const CharUnits , NoLValuePath N, bool IsNullPtr = false) - : Kind(None) { + : Kind(None), AllowConstexprUnknown(false) { MakeLValue(); setLValue(B, O, N, IsNullPtr); } APValue(LValueBase B, const CharUnits , ArrayRef Path, bool OnePastTheEnd, bool IsNullPtr = false) - : Kind(None) { + : Kind(None), AllowConstexprUnknown(false) { MakeLValue(); setLValue(B, O, Path, OnePastTheEnd, IsNullPtr); } - APValue(UninitArray, unsigned InitElts, unsigned Size) : Kind(None) { + + APValue(LValueBase B, ConstexprUnknown, const CharUnits , + bool IsNullPtr = false) + : Kind(None), AllowConstexprUnknown(true) { +MakeLValue(); +setLValue(B, O, NoLValuePath{}, IsNullPtr); + } + + APValue(UninitArray, unsigned InitElts, unsigned Size) + : Kind(None), AllowConstexprUnknown(false) { MakeArray(InitElts, Size); } - APValue(UninitStruct, unsigned B, unsigned M) : Kind(None) { + APValue(UninitStruct, unsigned B, unsigned M) + : Kind(None), AllowConstexprUnknown(false) { MakeStruct(B, M); } explicit APValue(const FieldDecl *D, const APValue = APValue()) - : Kind(None) { + : Kind(None), AllowConstexprUnknown(false) { MakeUnion(); setUnion(D, V); } APValue(const ValueDecl *Member, bool IsDerivedMember, - ArrayRef Path) : Kind(None) { + ArrayRef Path) + : Kind(None), AllowConstexprUnknown(false) { MakeMemberPointer(Member, IsDerivedMember, Path); } - APValue(const AddrLabelExpr* LHSExpr, const AddrLabelExpr* RHSExpr) - : Kind(None) { + APValue(const AddrLabelExpr *LHSExpr, const AddrLabelExpr *RHSExpr) + : Kind(None), AllowConstexprUnknown(false) { MakeAddrLabelDiff(); setAddrLabelDiff(LHSExpr, RHSExpr); }
[clang] [Clang] Implement P2280R4 Using unknown pointers and references in constant expressions (PR #95474)
https://github.com/shafik created https://github.com/llvm/llvm-project/pull/95474 P2280R4 allows the use of references in pointers of unknown origins in a constant expression context but only in specific cases that could be constant expressions. We track whether a variable is a constexpr unknown in a constant expression by setting a flag in either APValue or LValue and using this flag to prevent using unknown values in places where it is not allowed. Fixes: https://github.com/llvm/llvm-project/issues/63139 https://github.com/llvm/llvm-project/issues/63117 >From 7583d32c023f38cd2b4c6a3fad3bea5e115e9905 Mon Sep 17 00:00:00 2001 From: Shafik Yaghmour Date: Thu, 13 Jun 2024 14:20:50 -0700 Subject: [PATCH] [Clang] Implement P2280R4 Using unknown pointers and references in constant expressions P2280R4 allows the use of references in pointers of unknown origins in a constant expression context but only in specific cases that could be constant expressions. We track whether a variable is a constexpr unknown in a constant expression by setting a flag in either APValue or LValue and using this flag to prevent using unknown values in places where it is not allowed. Fixes: https://github.com/llvm/llvm-project/issues/63139 https://github.com/llvm/llvm-project/issues/63117 --- clang/include/clang/AST/APValue.h | 48 +++ clang/lib/AST/APValue.cpp | 12 ++- clang/lib/AST/ExprConstant.cpp| 85 +-- .../SemaCXX/constant-expression-cxx11.cpp | 16 ++-- .../SemaCXX/constant-expression-cxx2a.cpp | 3 +- .../SemaCXX/constant-expression-p2280r4.cpp | 54 6 files changed, 183 insertions(+), 35 deletions(-) create mode 100644 clang/test/SemaCXX/constant-expression-p2280r4.cpp diff --git a/clang/include/clang/AST/APValue.h b/clang/include/clang/AST/APValue.h index c4206b73b1156..6352348107a64 100644 --- a/clang/include/clang/AST/APValue.h +++ b/clang/include/clang/AST/APValue.h @@ -249,6 +249,7 @@ class APValue { struct NoLValuePath {}; struct UninitArray {}; struct UninitStruct {}; + struct ConstexprUnknown {}; template friend class clang::serialization::BasicReaderBase; friend class ASTImporter; @@ -256,6 +257,7 @@ class APValue { private: ValueKind Kind; + bool AllowConstexprUnknown = false; struct ComplexAPSInt { APSInt Real, Imag; @@ -314,53 +316,69 @@ class APValue { DataType Data; public: - APValue() : Kind(None) {} - explicit APValue(APSInt I) : Kind(None) { + bool allowConstexprUnknown() const { return AllowConstexprUnknown; } + + void setConstexprUnknown() { AllowConstexprUnknown = true; } + + APValue() : Kind(None), AllowConstexprUnknown(false) {} + explicit APValue(APSInt I) : Kind(None), AllowConstexprUnknown(false) { MakeInt(); setInt(std::move(I)); } - explicit APValue(APFloat F) : Kind(None) { + explicit APValue(APFloat F) : Kind(None), AllowConstexprUnknown(false) { MakeFloat(); setFloat(std::move(F)); } - explicit APValue(APFixedPoint FX) : Kind(None) { + explicit APValue(APFixedPoint FX) : Kind(None), AllowConstexprUnknown(false) { MakeFixedPoint(std::move(FX)); } - explicit APValue(const APValue *E, unsigned N) : Kind(None) { + explicit APValue(const APValue *E, unsigned N) + : Kind(None), AllowConstexprUnknown(false) { MakeVector(); setVector(E, N); } - APValue(APSInt R, APSInt I) : Kind(None) { + APValue(APSInt R, APSInt I) : Kind(None), AllowConstexprUnknown(false) { MakeComplexInt(); setComplexInt(std::move(R), std::move(I)); } - APValue(APFloat R, APFloat I) : Kind(None) { + APValue(APFloat R, APFloat I) : Kind(None), AllowConstexprUnknown(false) { MakeComplexFloat(); setComplexFloat(std::move(R), std::move(I)); } APValue(const APValue ); APValue(APValue &); APValue(LValueBase B, const CharUnits , NoLValuePath N, bool IsNullPtr = false) - : Kind(None) { + : Kind(None), AllowConstexprUnknown(false) { MakeLValue(); setLValue(B, O, N, IsNullPtr); } APValue(LValueBase B, const CharUnits , ArrayRef Path, bool OnePastTheEnd, bool IsNullPtr = false) - : Kind(None) { + : Kind(None), AllowConstexprUnknown(false) { MakeLValue(); setLValue(B, O, Path, OnePastTheEnd, IsNullPtr); } - APValue(UninitArray, unsigned InitElts, unsigned Size) : Kind(None) { + + APValue(LValueBase B, ConstexprUnknown, const CharUnits , + bool IsNullPtr = false) + : Kind(None), AllowConstexprUnknown(true) { +MakeLValue(); +setLValue(B, O, NoLValuePath{}, IsNullPtr); + } + + APValue(UninitArray, unsigned InitElts, unsigned Size) + : Kind(None), AllowConstexprUnknown(false) { MakeArray(InitElts, Size); } - APValue(UninitStruct, unsigned B, unsigned M) : Kind(None) { + APValue(UninitStruct, unsigned B, unsigned M) + : Kind(None), AllowConstexprUnknown(false) { MakeStruct(B, M); } explicit
[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)
https://github.com/JustinStitt updated https://github.com/llvm/llvm-project/pull/86618 >From 6152bd26438a32711589424f705281291475d548 Mon Sep 17 00:00:00 2001 From: Justin Stitt Date: Tue, 5 Mar 2024 03:14:49 + Subject: [PATCH] implement wraps attribute Signed-off-by: Justin Stitt --- clang/docs/ReleaseNotes.rst | 10 +++ clang/include/clang/AST/Expr.h| 3 + clang/include/clang/AST/Type.h| 2 + clang/include/clang/Basic/Attr.td | 7 ++ clang/include/clang/Basic/AttrDocs.td | 69 +++ clang/include/clang/Basic/DiagnosticGroups.td | 6 ++ .../clang/Basic/DiagnosticSemaKinds.td| 7 ++ clang/lib/AST/Expr.cpp| 9 +++ clang/lib/AST/ExprConstant.cpp| 4 +- clang/lib/AST/Type.cpp| 4 ++ clang/lib/AST/TypePrinter.cpp | 3 + clang/lib/CodeGen/CGExprScalar.cpp| 47 + clang/lib/Sema/Sema.cpp | 3 + clang/lib/Sema/SemaChecking.cpp | 33 - clang/lib/Sema/SemaDeclAttr.cpp | 8 ++- clang/lib/Sema/SemaType.cpp | 15 clang/test/CodeGen/integer-overflow.c | 66 ++ clang/test/CodeGen/unsigned-overflow.c| 63 ++--- ...a-attribute-supported-attributes-list.test | 1 + clang/test/Sema/attr-wraps.c | 43 20 files changed, 377 insertions(+), 26 deletions(-) create mode 100644 clang/test/Sema/attr-wraps.c diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 8c2f737836a9d..675d33d67cb97 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -472,6 +472,16 @@ Attribute Changes in Clang }; +- Introduced ``__attribute((wraps))__`` which can be added to type or variable + declarations. Using an attributed type or variable in an arithmetic + expression will define the overflow behavior for that expression as having + two's complement wrap-around. These expressions cannot trigger integer + overflow warnings or sanitizer warnings. They also cannot be optimized away + by some eager UB optimizations. + + This attribute is only valid for C, as there are built-in language + alternatives for other languages. + Improvements to Clang's diagnostics --- - Clang now applies syntax highlighting to the code snippets it diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h index f2bf667636dc9..48968cbbbaf7e 100644 --- a/clang/include/clang/AST/Expr.h +++ b/clang/include/clang/AST/Expr.h @@ -4061,6 +4061,9 @@ class BinaryOperator : public Expr { return getFPFeaturesInEffect(LO).getAllowFEnvAccess(); } + /// Does one of the subexpressions have the wraps attribute? + bool hasWrappingOperand(const ASTContext ) const; + protected: BinaryOperator(const ASTContext , Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, ExprValueKind VK, ExprObjectKind OK, diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h index fab233b62d8d1..9bb468ee96646 100644 --- a/clang/include/clang/AST/Type.h +++ b/clang/include/clang/AST/Type.h @@ -1455,6 +1455,8 @@ class QualType { return getQualifiers().hasStrongOrWeakObjCLifetime(); } + bool hasWrapsAttr() const; + // true when Type is objc's weak and weak is enabled but ARC isn't. bool isNonWeakInMRRWithObjCWeak(const ASTContext ) const; diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index b70b0c8b836a5..8d3bd6f5e9949 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -4606,3 +4606,10 @@ def ClspvLibclcBuiltin: InheritableAttr { let Documentation = [ClspvLibclcBuiltinDoc]; let SimpleHandler = 1; } + +def Wraps : DeclOrTypeAttr { + let Spellings = [Clang<"wraps">]; + let Subjects = SubjectList<[Var, TypedefName, Field]>; + let Documentation = [WrapsDocs]; + let LangOpts = [COnly]; +} diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td index 70d5dfa8aaf86..87f8ca855d2af 100644 --- a/clang/include/clang/Basic/AttrDocs.td +++ b/clang/include/clang/Basic/AttrDocs.td @@ -8106,3 +8106,72 @@ Attribute used by `clspv`_ (OpenCL-C to Vulkan SPIR-V compiler) to identify func .. _`libclc`: https://libclc.llvm.org }]; } + +def WrapsDocs : Documentation { + let Category = DocCatField; + let Content = [{ +This attribute can be used with type or variable declarations to denote that +arithmetic containing these marked components have defined overflow behavior. +Specifically, the behavior is defined as being consistent with two's complement +wrap-around. For the purposes of sanitizers or warnings that concern themselves +with the definedness of integer arithmetic, they will cease to instrument or +warn about arithmetic that directly involves a "wrapping"
[clang] added regcall struct by reg support (PR #95257)
efriedma-quic wrote: Right, the specification requires splitting the whole structure into chunks; if we add a special-case for 8-byte structs, we'll just have to throw it away when we implement the right algorithm. Also, I'm not sure what the isBuiltinType() check is supposed to handle. It seems to exclude values you'd want to handle, like pointers. https://github.com/llvm/llvm-project/pull/95257 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [compiler-rt] [flang] [libc] [lld] [lldb] [llvm] [mlir] [openmp] [llvm-project] Fix typo "seperate" (PR #95373)
https://github.com/Superty approved this pull request. https://github.com/llvm/llvm-project/pull/95373 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Require base element type of `__has_unique_object_representations` to be complete (PR #95432)
https://github.com/cor3ntin approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/95432 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Bump the DWARF version number to 5 on Darwin. (PR #95164)
adrian-prantl wrote: Relanded in 8f57f6895724f858c9db924200524fad86cc4f11 https://github.com/llvm/llvm-project/pull/95164 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeGen] Return RValue from `EmitVAArg` (PR #94635)
@@ -325,14 +325,19 @@ Address SparcV9ABIInfo::EmitVAArg(CodeGenFunction , Address VAListAddr, break; case ABIArgInfo::Ignore: -return Address(llvm::UndefValue::get(ArgPtrTy), ArgTy, TypeInfo.Align); +return CGF.EmitLoadOfAnyValue( +CGF.MakeAddrLValue( efriedma-quic wrote: If you're going to switch all the other Ignore handlers to just `return Slot.asRValue();`, might as well also change this one. https://github.com/llvm/llvm-project/pull/94635 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeGen] Return RValue from `EmitVAArg` (PR #94635)
@@ -834,5 +834,4 @@ typedef struct {} empty; empty empty_record_test(void) { // CHECK-LABEL: define{{.*}} void @empty_record_test() return va_arg(the_list, empty); -// CHECK: [[GR_OFFS:%[a-z_0-9]+]] = load ptr, ptr @the_list efriedma-quic wrote: Maybe should check something here? Something like `// CHECK: call void @llvm.va_start // CHECK-NEXT: ret void`. https://github.com/llvm/llvm-project/pull/94635 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeGen] Return RValue from `EmitVAArg` (PR #94635)
https://github.com/efriedma-quic approved this pull request. A couple minor comments; otherwise LGTM https://github.com/llvm/llvm-project/pull/94635 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeGen] Return RValue from `EmitVAArg` (PR #94635)
https://github.com/efriedma-quic edited https://github.com/llvm/llvm-project/pull/94635 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AMDGPU] Add a new builtin type for buffer rsrc (PR #94830)
@@ -0,0 +1,9 @@ + +// REQUIRES: amdgpu-registered-target +// RUN: %clang_cc1 -triple amdgcn -emit-llvm -o - %s -debug-info-kind=limited 2>&1 | FileCheck %s + +// CHECK: name: "__amdgcn_buffer_rsrc_t",{{.*}}baseType: ![[BT:[0-9]+]] +// CHECK: [[BT]] = !DICompositeType(tag: DW_TAG_structure_type, name: "__amdgcn_buffer_rsrc_t", {{.*}} flags: DIFlagFwdDecl) krzysz00 wrote: Yeah, debug as a struct's probably a more sensible representation, since it basically is a struct https://github.com/llvm/llvm-project/pull/94830 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AMDGPU] Add a new builtin type for buffer rsrc (PR #94830)
https://github.com/shiltian updated https://github.com/llvm/llvm-project/pull/94830 >From 2eb6b3a58692ae3b8a6250e87516450a5085fa0f Mon Sep 17 00:00:00 2001 From: Shilei Tian Date: Thu, 13 Jun 2024 17:02:11 -0400 Subject: [PATCH] [Clang][AMDGPU] Add a new builtin type for buffer rsrc --- clang/include/clang/AST/ASTContext.h | 2 + clang/include/clang/AST/Type.h| 3 + clang/include/clang/AST/TypeProperties.td | 4 ++ clang/include/clang/Basic/AMDGPUTypes.def | 21 ++ .../include/clang/Serialization/ASTBitCodes.h | 5 +- clang/lib/AST/ASTContext.cpp | 16 + clang/lib/AST/ASTImporter.cpp | 4 ++ clang/lib/AST/ExprConstant.cpp| 2 + clang/lib/AST/ItaniumMangle.cpp | 6 ++ clang/lib/AST/MicrosoftMangle.cpp | 2 + clang/lib/AST/NSAPI.cpp | 2 + clang/lib/AST/PrintfFormatString.cpp | 2 + clang/lib/AST/Type.cpp| 6 ++ clang/lib/AST/TypeLoc.cpp | 2 + clang/lib/CodeGen/CGDebugInfo.cpp | 11 ++- clang/lib/CodeGen/CGDebugInfo.h | 2 + clang/lib/CodeGen/CodeGenTypes.cpp| 5 ++ clang/lib/CodeGen/ItaniumCXXABI.cpp | 2 + clang/lib/Index/USRGeneration.cpp | 4 ++ clang/lib/Sema/Sema.cpp | 7 ++ clang/lib/Sema/SemaExpr.cpp | 4 ++ clang/lib/Serialization/ASTCommon.cpp | 5 ++ clang/lib/Serialization/ASTReader.cpp | 5 ++ clang/test/AST/ast-dump-amdgpu-types.c| 10 +++ .../amdgpu-buffer-rsrc-type-debug-info.c | 9 +++ .../amdgpu-buffer-rsrc-typeinfo.cpp | 9 +++ .../CodeGenOpenCL/amdgcn-buffer-rsrc-type.cl | 69 +++ clang/test/SemaCXX/amdgpu-buffer-rsrc.cpp | 17 + clang/tools/libclang/CIndex.cpp | 2 + 29 files changed, 236 insertions(+), 2 deletions(-) create mode 100644 clang/include/clang/Basic/AMDGPUTypes.def create mode 100644 clang/test/AST/ast-dump-amdgpu-types.c create mode 100644 clang/test/CodeGen/amdgpu-buffer-rsrc-type-debug-info.c create mode 100644 clang/test/CodeGenCXX/amdgpu-buffer-rsrc-typeinfo.cpp create mode 100644 clang/test/CodeGenOpenCL/amdgcn-buffer-rsrc-type.cl create mode 100644 clang/test/SemaCXX/amdgpu-buffer-rsrc.cpp diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index 53ece996769a8..4d1f440506e09 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -1147,6 +1147,8 @@ class ASTContext : public RefCountedBase { #include "clang/Basic/RISCVVTypes.def" #define WASM_TYPE(Name, Id, SingletonId) CanQualType SingletonId; #include "clang/Basic/WebAssemblyReferenceTypes.def" +#define AMDGPU_TYPE(Name, Id, SingletonId) CanQualType SingletonId; +#include "clang/Basic/AMDGPUTypes.def" // Types for deductions in C++0x [stmt.ranged]'s desugaring. Built on demand. mutable QualType AutoDeductTy; // Deduction against 'auto'. diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h index fab233b62d8d1..61246479188e9 100644 --- a/clang/include/clang/AST/Type.h +++ b/clang/include/clang/AST/Type.h @@ -3015,6 +3015,9 @@ class BuiltinType : public Type { // WebAssembly reference types #define WASM_TYPE(Name, Id, SingletonId) Id, #include "clang/Basic/WebAssemblyReferenceTypes.def" +// AMDGPU types +#define AMDGPU_TYPE(Name, Id, SingletonId) Id, +#include "clang/Basic/AMDGPUTypes.def" // All other builtin types #define BUILTIN_TYPE(Id, SingletonId) Id, #define LAST_BUILTIN_TYPE(Id) LastKind = Id diff --git a/clang/include/clang/AST/TypeProperties.td b/clang/include/clang/AST/TypeProperties.td index 40dd16f080e2e..aba14b222a03a 100644 --- a/clang/include/clang/AST/TypeProperties.td +++ b/clang/include/clang/AST/TypeProperties.td @@ -861,6 +861,10 @@ let Class = BuiltinType in { case BuiltinType::ID: return ctx.SINGLETON_ID; #include "clang/Basic/WebAssemblyReferenceTypes.def" +#define AMDGPU_TYPE(NAME, ID, SINGLETON_ID) \ + case BuiltinType::ID: return ctx.SINGLETON_ID; +#include "clang/Basic/AMDGPUTypes.def" + #define BUILTIN_TYPE(ID, SINGLETON_ID) \ case BuiltinType::ID: return ctx.SINGLETON_ID; #include "clang/AST/BuiltinTypes.def" diff --git a/clang/include/clang/Basic/AMDGPUTypes.def b/clang/include/clang/Basic/AMDGPUTypes.def new file mode 100644 index 0..c035c6dbced11 --- /dev/null +++ b/clang/include/clang/Basic/AMDGPUTypes.def @@ -0,0 +1,21 @@ +//===-- AMDGPUTypes.def - Metadata about AMDGPU types ---*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// This file defines various
[clang] [Clang][AMDGPU] Add a new builtin type for buffer rsrc (PR #94830)
@@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -x hip -aux-triple amdgcn-amd-amdhsa %s -fsyntax-only -verify + +#define __device__ __attribute__((device)) + +__device__ __amdgcn_buffer_rsrc_t test_buffer_rsrc_t_device() {} // expected-warning {{non-void function does not return a value}} +__amdgcn_buffer_rsrc_t test_buffer_rsrc_t_host() {} // expected-error {{'__amdgcn_buffer_rsrc_t' can only be used in device-side function}} shiltian wrote: Okay, that makes sense. Then I'll remove this test. https://github.com/llvm/llvm-project/pull/94830 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang] Reland Add tanf16 builtin and support for tan constrained intrinsic (PR #94559)
efriedma-quic wrote: Yes, I think it's just a historical mistake; sin/cos/log/exp were added a very long time ago, and we weren't as careful about that sort of thing. And nobody has taken the time to try to cleanup the current defaults. https://github.com/llvm/llvm-project/pull/94559 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [InstallAPI] Pick up input headers by directory traversal (PR #94508)
cyndyishida wrote: ping https://github.com/llvm/llvm-project/pull/94508 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Fix __is_trivially_equality_comparable returning true with ineligebile defaulted overloads (PR #93113)
AMP999 wrote: LGTM now, for what it's worth. https://github.com/llvm/llvm-project/pull/93113 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] avoid false positive when overload for bugprone-return-const-ref-from-parameter (PR #95434)
llvmbot wrote: @llvm/pr-subscribers-clang-tools-extra @llvm/pr-subscribers-clang-tidy Author: Congcong Cai (HerrCai0907) Changes Fixes: #90274 --- Full diff: https://github.com/llvm/llvm-project/pull/95434.diff 2 Files Affected: - (modified) clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp (+71-5) - (modified) clang-tools-extra/test/clang-tidy/checkers/bugprone/return-const-ref-from-parameter.cpp (+34) ``diff diff --git a/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp index cacba38b4a5aa..ecdcd3c2d2571 100644 --- a/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp @@ -7,7 +7,6 @@ //===--===// #include "ReturnConstRefFromParameterCheck.h" -#include "../utils/Matchers.h" #include "clang/ASTMatchers/ASTMatchFinder.h" #include "clang/ASTMatchers/ASTMatchers.h" @@ -18,20 +17,87 @@ namespace clang::tidy::bugprone { void ReturnConstRefFromParameterCheck::registerMatchers(MatchFinder *Finder) { Finder->addMatcher( returnStmt( - hasReturnValue(declRefExpr(to(parmVarDecl(hasType(hasCanonicalType( - qualType(matchers::isReferenceToConst()).bind("type"))), - hasAncestor(functionDecl(hasReturnTypeLoc( - loc(qualType(hasCanonicalType(equalsBoundNode("type" + hasReturnValue(declRefExpr( + to(parmVarDecl(hasType(hasCanonicalType( + qualType(lValueReferenceType(pointee( + qualType(isConstQualified() + .bind("type" + .bind("param", + hasAncestor( + functionDecl(hasReturnTypeLoc(loc(qualType( + hasCanonicalType(equalsBoundNode("type")) + .bind("func"))) .bind("ret"), this); } +static bool isSameTypeIgnoringConst(QualType A, QualType B) { + A = A.getCanonicalType(); + B = B.getCanonicalType(); + A.addConst(); + B.addConst(); + return A == B; +} + +static bool isSameTypeIgnoringConstRef(QualType A, QualType B) { + return isSameTypeIgnoringConst(A.getCanonicalType().getNonReferenceType(), + B.getCanonicalType().getNonReferenceType()); +} + +static bool hasSameParameterTypes(const FunctionDecl , const FunctionDecl , + const ParmVarDecl ) { + if (FD.getNumParams() != O.getNumParams()) +return false; + for (unsigned I = 0, E = FD.getNumParams(); I < E; ++I) { +const ParmVarDecl *DPD = FD.getParamDecl(I); +const QualType OPT = O.getParamDecl(I)->getType(); +if (DPD == ) { + if (!llvm::isa(OPT) || + !isSameTypeIgnoringConstRef(DPD->getType(), OPT)) +return false; +} else { + if (!isSameTypeIgnoringConst(DPD->getType(), OPT)) +return false; +} + } + return true; +} + +static const Decl *findRVRefOverload(const FunctionDecl , + const ParmVarDecl ) { + // Actually it would be better to do lookup in caller site. + // But in most of cases, overloads of LVRef and RVRef will appear together. + // FIXME: + // 1. overload in anonymous namespace + // 2. forward reference + DeclContext::lookup_result LookupResult = + FD.getParent()->lookup(FD.getNameInfo().getName()); + if (LookupResult.isSingleResult()) { +return nullptr; + } + for (const Decl *Overload : LookupResult) { +if (Overload == ) + continue; +Overload->dumpColor(); +if (const auto *O = dyn_cast(Overload)) + if (hasSameParameterTypes(FD, *O, PD)) +return O; + } + return nullptr; +} + void ReturnConstRefFromParameterCheck::check( const MatchFinder::MatchResult ) { + const auto *FD = Result.Nodes.getNodeAs("func"); + const auto *PD = Result.Nodes.getNodeAs("param"); const auto *R = Result.Nodes.getNodeAs("ret"); const SourceRange Range = R->getRetValue()->getSourceRange(); if (Range.isInvalid()) return; + + if (findRVRefOverload(*FD, *PD) != nullptr) +return; + diag(Range.getBegin(), "returning a constant reference parameter may cause use-after-free " "when the parameter is constructed from a temporary") diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/return-const-ref-from-parameter.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/return-const-ref-from-parameter.cpp index ca41bdf74a107..d13c127da7c2a 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/return-const-ref-from-parameter.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/return-const-ref-from-parameter.cpp @@ -143,3 +143,37 @@ void
[clang] [Clang][NFC] Avoid opening namespace std (PR #95470)
https://github.com/Sirraide approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/95470 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] d4a0154 - [llvm-project] Fix typo "seperate" (#95373)
Author: Jay Foad Date: 2024-06-13T20:20:27+01:00 New Revision: d4a0154902fb9b0611ed857134b26a64a1d5ad1e URL: https://github.com/llvm/llvm-project/commit/d4a0154902fb9b0611ed857134b26a64a1d5ad1e DIFF: https://github.com/llvm/llvm-project/commit/d4a0154902fb9b0611ed857134b26a64a1d5ad1e.diff LOG: [llvm-project] Fix typo "seperate" (#95373) Added: Modified: clang-tools-extra/clangd/TidyProvider.cpp clang/include/clang/Frontend/FrontendOptions.h clang/include/clang/InstallAPI/DylibVerifier.h clang/lib/InstallAPI/Visitor.cpp clang/lib/Serialization/ASTWriterStmt.cpp compiler-rt/test/dfsan/custom.cpp compiler-rt/test/orc/TestCases/Linux/ppc64/trivial-tls-pwr10.test flang/examples/FlangOmpReport/yaml_summarizer.py flang/lib/Semantics/check-omp-structure.cpp flang/test/Driver/mllvm_vs_mmlir.f90 libc/src/__support/FPUtil/x86_64/FEnvImpl.h libc/src/stdio/printf_core/float_hex_converter.h libc/test/src/__support/str_to_float_comparison_test.cpp lld/test/wasm/data-segments.ll lldb/include/lldb/Expression/DWARFExpressionList.h lldb/include/lldb/Target/MemoryTagManager.h lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp lldb/test/API/CMakeLists.txt lldb/test/API/tools/lldb-server/memory-tagging/TestGdbRemoteMemoryTagging.py lldb/test/Shell/SymbolFile/DWARF/x86/DW_AT_data_bit_offset-DW_OP_stack_value.s llvm/include/llvm/CodeGen/LiveRegUnits.h llvm/include/llvm/CodeGen/MIRFormatter.h llvm/include/llvm/MC/MCAsmInfo.h llvm/include/llvm/Support/raw_socket_stream.h llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp llvm/lib/FileCheck/FileCheck.cpp llvm/lib/IR/DebugInfo.cpp llvm/lib/MC/MCPseudoProbe.cpp llvm/lib/Support/VirtualFileSystem.cpp llvm/lib/Support/raw_socket_stream.cpp llvm/lib/Target/ARM/ARMISelLowering.cpp llvm/lib/Target/RISCV/RISCVMachineFunctionInfo.h llvm/lib/TargetParser/RISCVISAInfo.cpp llvm/lib/TextAPI/Utils.cpp llvm/lib/Transforms/IPO/Attributor.cpp llvm/lib/Transforms/IPO/SampleProfileProbe.cpp llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp llvm/test/CodeGen/X86/AMX/amx-greedy-ra.ll llvm/test/CodeGen/X86/apx/shift-eflags.ll llvm/test/CodeGen/X86/merge-consecutive-stores-nt.ll llvm/test/CodeGen/X86/shift-eflags.ll llvm/test/Transforms/InstSimplify/constant-fold-fp-denormal.ll llvm/test/Transforms/LoopVectorize/LoongArch/defaults.ll llvm/test/Transforms/LoopVectorize/RISCV/defaults.ll llvm/test/Transforms/SeparateConstOffsetFromGEP/split-gep-or-as-add.ll llvm/test/Verifier/alloc-size-failedparse.ll llvm/test/tools/llvm-ar/windows-path.test llvm/test/tools/llvm-objcopy/ELF/mirror-permissions-win.test llvm/tools/llvm-cov/CodeCoverage.cpp llvm/tools/llvm-profgen/PerfReader.cpp llvm/unittests/Support/Path.cpp mlir/include/mlir/Analysis/Presburger/IntegerRelation.h mlir/include/mlir/Analysis/Presburger/PresburgerSpace.h mlir/include/mlir/Dialect/OpenMP/OpenMPInterfaces.h mlir/lib/Analysis/Presburger/PresburgerSpace.cpp mlir/lib/Conversion/GPUCommon/GPUOpsLowering.h mlir/lib/Dialect/LLVMIR/IR/BasicPtxBuilderInterface.cpp mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp mlir/test/Integration/Dialect/SparseTensor/CPU/sparse_reduce_custom_prod.mlir mlir/test/Target/LLVMIR/omptarget-constant-alloca-raise.mlir openmp/tools/Modules/FindOpenMPTarget.cmake Removed: diff --git a/clang-tools-extra/clangd/TidyProvider.cpp b/clang-tools-extra/clangd/TidyProvider.cpp index a4121df30d3df..a87238e0c0938 100644 --- a/clang-tools-extra/clangd/TidyProvider.cpp +++ b/clang-tools-extra/clangd/TidyProvider.cpp @@ -195,10 +195,10 @@ TidyProvider addTidyChecks(llvm::StringRef Checks, } TidyProvider disableUnusableChecks(llvm::ArrayRef ExtraBadChecks) { - constexpr llvm::StringLiteral Seperator(","); + constexpr llvm::StringLiteral Separator(","); static const std::string BadChecks = llvm::join_items( - Seperator, - // We want this list to start with a seperator to + Separator, + // We want this list to start with a separator to // simplify appending in the lambda. So including an // empty string here will force that. "", @@ -227,7 +227,7 @@ TidyProvider disableUnusableChecks(llvm::ArrayRef ExtraBadChecks) { for (const std::string : ExtraBadChecks) { if (Str.empty()) continue; -Size += Seperator.size(); +Size += Separator.size(); if (LLVM_LIKELY(Str.front() != '-')) ++Size; Size += Str.size(); @@ -238,7 +238,7 @@ TidyProvider disableUnusableChecks(llvm::ArrayRef ExtraBadChecks) { for (const
[clang] [clang-tools-extra] [clang] Implement CWG2398 provisional TTP matching to class templates (PR #94981)
@@ -9219,7 +9222,8 @@ class Sema final : public SemaBase { /// \returns true if an error occurred, false otherwise. bool CheckTemplateArgumentList( TemplateDecl *Template, SourceLocation TemplateLoc, - TemplateArgumentListInfo , bool PartialTemplateArgs, + TemplateArgumentListInfo , mizvekov wrote: Yeah. One issue I have often had with these functions with large amount of both defaulted and non-defaulted parameters, is that you would want to extend it by changing the signature, then arguments would match parameters incorrectly, but this would not cause a hard error on all of the call sites. I could have easily added DefaultArgs as defaulted empty here, but chose not to due to this reason. Besides that, overloading functions with such huge numbers of parameters creates some confusion as well. I'd slightly prefer if we avoided that, but don't have strong enough feelings to go on a crusade against it. https://github.com/llvm/llvm-project/pull/94981 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [Clang] Implement CWG2813: Class member access with prvalues (PR #95112)
@@ -124,21 +125,67 @@ void usage() { } }; // namespace p1771 -#ifdef EXT -// expected-warning@5 {{use of the 'nodiscard' attribute is a C++17 extension}} -// expected-warning@9 {{use of the 'nodiscard' attribute is a C++17 extension}} -// expected-warning@12 {{use of the 'nodiscard' attribute is a C++17 extension}} -// expected-warning@13 {{use of the 'nodiscard' attribute is a C++17 extension}} -// expected-warning@29 {{use of the 'nodiscard' attribute is a C++17 extension}} -// expected-warning@65 {{use of the 'nodiscard' attribute is a C++20 extension}} -// expected-warning@67 {{use of the 'nodiscard' attribute is a C++20 extension}} -// expected-warning@71 {{use of the 'nodiscard' attribute is a C++20 extension}} -// expected-warning@73 {{use of the 'nodiscard' attribute is a C++20 extension}} -// expected-warning@74 {{use of the 'nodiscard' attribute is a C++20 extension}} -// expected-warning@84 {{use of the 'nodiscard' attribute is a C++20 extension}} -// expected-warning@86 {{use of the 'nodiscard' attribute is a C++17 extension}} -// expected-warning@87 {{use of the 'nodiscard' attribute is a C++20 extension}} -// expected-warning@91 {{use of the 'nodiscard' attribute is a C++17 extension}} -// expected-warning@92 {{use of the 'nodiscard' attribute is a C++20 extension}} -// expected-warning@95 {{use of the 'nodiscard' attribute is a C++20 extension}} +namespace discarded_member_access { +struct X { + union { +int variant_member; + }; + struct { +int anonymous_struct_member; + }; + int data_member; + static int static_data_member; + enum { +unscoped_enum + }; + enum class scoped_enum_t { +scoped_enum + }; + using enum scoped_enum_t; + // cxx11-17-warning@-1 {{using enum declaration is a C++20 extension}} + + void implicit_object_member_function(); + static void static_member_function(); +#if __cplusplus >= 202302L + void explicit_object_member_function(this X self); #endif +}; + Sirraide wrote: This is missing tests for MS properties (though I’d maybe put those in a different file). https://github.com/llvm/llvm-project/pull/95112 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AMDGPU] Add a new builtin type for buffer rsrc (PR #94830)
@@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -x hip -aux-triple amdgcn-amd-amdhsa %s -fsyntax-only -verify + +#define __device__ __attribute__((device)) + +__device__ __amdgcn_buffer_rsrc_t test_buffer_rsrc_t_device() {} // expected-warning {{non-void function does not return a value}} +__amdgcn_buffer_rsrc_t test_buffer_rsrc_t_host() {} // expected-error {{'__amdgcn_buffer_rsrc_t' can only be used in device-side function}} yxsamliu wrote: As discussed in https://github.com/llvm/llvm-project/pull/69366, I think the trend is to make HIP more like C++ where every function is both device and host function, and de-emphasize handling based on host/device attributes. Ideally, we can imagine we are compiling a HIP program for a processor that has the capability of both the host CPU and the device GPU, so that we can ignore host/device difference during semantic checking, and we defer the diagnosing to codegen or linker. The reason is that C++ is not designed with host/device in mind and the current parser/sema does not consider host/device attributes in many cases, especially about templates. Adding more host/device based sema seems to make things more complicated and not to help making generic C++ code (e.g. the standard C++ library) work for both host/device. Another reason not to emphasize the host/device difference is that difference in device/host AST risks violation of ODR and causes issues difficult to diagnose. In a word, I would not recommend restricting a type to device only. https://github.com/llvm/llvm-project/pull/94830 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [Clang] Implement CWG2813: Class member access with prvalues (PR #95112)
@@ -9182,6 +9182,9 @@ def warn_unused_constructor : Warning< def warn_unused_constructor_msg : Warning< "ignoring temporary created by a constructor declared with %0 attribute: %1">, InGroup; +def warn_discarded_class_member_access : Warning< + "left operand of dot in this class member access is discarded and has no effect">, Sirraide wrote: >From what I can tell, the call to the `MakeDiscardedValue()` lambda that >you’ve added could take the integer for the `%select` here as a parameter. https://github.com/llvm/llvm-project/pull/95112 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [Clang] Implement CWG2813: Class member access with prvalues (PR #95112)
@@ -1174,6 +1207,9 @@ Sema::BuildMemberReferenceExpr(Expr *BaseExpr, QualType BaseExprType, valueKind = VK_PRValue; type = Context.BoundMemberTy; Sirraide wrote: Don’t we need a call to `MakeGLValue()` somewhere in here? https://github.com/llvm/llvm-project/pull/95112 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [Clang] Implement CWG2813: Class member access with prvalues (PR #95112)
@@ -1140,26 +1131,68 @@ Sema::BuildMemberReferenceExpr(Expr *BaseExpr, QualType BaseExprType, BaseExpr = BuildCXXThisExpr(Loc, BaseExprType, /*IsImplicit=*/true); } + // C++17 [expr.ref]p2, per CWG2813: + // For the first option (dot), if the id-expression names a static member or + // an enumerator, the first expression is a discarded-value expression; if + // the id-expression names a non-static data member, the first expression + // shall be a glvalue. + auto MakeDiscardedValue = [, IsArrow, this] { +assert(getLangOpts().CPlusPlus && + "Static member / member enumerator outside of C++"); +if (IsArrow) + return false; +ExprResult Converted = IgnoredValueConversions(BaseExpr); +if (Converted.isInvalid()) + return true; +BaseExpr = Converted.get(); +DiagnoseUnusedExprResult(BaseExpr, + diag::warn_discarded_class_member_access); +return false; + }; + auto MakeGLValue = [, IsArrow, this] { +if (IsArrow || !BaseExpr->isPRValue()) + return false; +ExprResult Converted = TemporaryMaterializationConversion(BaseExpr); +if (Converted.isInvalid()) + return true; +BaseExpr = Converted.get(); +return false; + }; + // Check the use of this member. if (DiagnoseUseOfDecl(MemberDecl, MemberLoc)) return ExprError(); - if (FieldDecl *FD = dyn_cast(MemberDecl)) + if (FieldDecl *FD = dyn_cast(MemberDecl)) { +if (MakeGLValue()) + return ExprError(); return BuildFieldReferenceExpr(BaseExpr, IsArrow, OpLoc, SS, FD, FoundDecl, MemberNameInfo); + } - if (MSPropertyDecl *PD = dyn_cast(MemberDecl)) + if (MSPropertyDecl *PD = dyn_cast(MemberDecl)) { +// Properties treated as non-static data members for the purpose of +// temporary materialization +if (MakeGLValue()) Sirraide wrote: I’m not sure this is correct. Consider e.g. https://godbolt.org/z/exK1cbez4 (compiled w/ `-fdeclspec`): ```c++ struct S { static int getX() { return 42; } __declspec(property(get = getX)) int x; }; int main() { return S().x; } ``` I’d expect this defect report to also apply to this (if properties were a standard C++ feature, that is) seeing as it is just sugar for a call to a static member function. (I’d love to see what MSVC does w/ this, but unfortunately, MSVC is currently down on godbolt...) https://github.com/llvm/llvm-project/pull/95112 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [Clang] Implement CWG2813: Class member access with prvalues (PR #95112)
@@ -1140,26 +1131,68 @@ Sema::BuildMemberReferenceExpr(Expr *BaseExpr, QualType BaseExprType, BaseExpr = BuildCXXThisExpr(Loc, BaseExprType, /*IsImplicit=*/true); } + // C++17 [expr.ref]p2, per CWG2813: + // For the first option (dot), if the id-expression names a static member or + // an enumerator, the first expression is a discarded-value expression; if + // the id-expression names a non-static data member, the first expression + // shall be a glvalue. + auto MakeDiscardedValue = [, IsArrow, this] { +assert(getLangOpts().CPlusPlus && + "Static member / member enumerator outside of C++"); +if (IsArrow) + return false; +ExprResult Converted = IgnoredValueConversions(BaseExpr); +if (Converted.isInvalid()) + return true; +BaseExpr = Converted.get(); +DiagnoseUnusedExprResult(BaseExpr, + diag::warn_discarded_class_member_access); +return false; + }; + auto MakeGLValue = [, IsArrow, this] { Sirraide wrote: ```suggestion auto MakeGLValue = [&] { ``` Same here https://github.com/llvm/llvm-project/pull/95112 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [Clang] Implement CWG2813: Class member access with prvalues (PR #95112)
@@ -1140,26 +1131,68 @@ Sema::BuildMemberReferenceExpr(Expr *BaseExpr, QualType BaseExprType, BaseExpr = BuildCXXThisExpr(Loc, BaseExprType, /*IsImplicit=*/true); } + // C++17 [expr.ref]p2, per CWG2813: + // For the first option (dot), if the id-expression names a static member or + // an enumerator, the first expression is a discarded-value expression; if + // the id-expression names a non-static data member, the first expression + // shall be a glvalue. + auto MakeDiscardedValue = [, IsArrow, this] { Sirraide wrote: ```suggestion auto MakeDiscardedValue = [&] { ``` I would personally just do this, but I candidly don’t know if we have a policy on this... https://github.com/llvm/llvm-project/pull/95112 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [Clang] Implement CWG2813: Class member access with prvalues (PR #95112)
@@ -387,9 +388,16 @@ void Sema::DiagnoseUnusedExprResult(const Stmt *S, unsigned DiagID) { // Do not diagnose use of a comma operator in a SFINAE context because the // type of the left operand could be used for SFINAE, so technically it is // *used*. - if (DiagID != diag::warn_unused_comma_left_operand || !isSFINAEContext()) -DiagIfReachable(Loc, S ? llvm::ArrayRef(S) : std::nullopt, -PDiag(DiagID) << R1 << R2); + if (DiagID == diag::warn_unused_comma_left_operand && isSFINAEContext()) +return; + + // Don't diagnose discarded left of dot in static class member access + // because its type is "used" to determine the class to access + if (OrigDiagID == diag::warn_discarded_class_member_access) +return; Sirraide wrote: Er, doesn’t this prevent all diagnostics that this pr is supposed to introduce, or am I missing something? I don’t think we should be suppressing the diagnostic here. If you want to access a *static* member of a specific class, we already have a syntax for that that doesn’t involve constructing a temporary, after all: `S::x`. https://github.com/llvm/llvm-project/pull/95112 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [Clang] Implement CWG2813: Class member access with prvalues (PR #95112)
@@ -9182,6 +9182,9 @@ def warn_unused_constructor : Warning< def warn_unused_constructor_msg : Warning< "ignoring temporary created by a constructor declared with %0 attribute: %1">, InGroup; +def warn_discarded_class_member_access : Warning< + "left operand of dot in this class member access is discarded and has no effect">, Sirraide wrote: ```suggestion "discarding left operand of '.' in %select{access to static data member|access to enumerator|call to static member function}0">, ``` (and maybe more cases if I missed any) https://github.com/llvm/llvm-project/pull/95112 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][NFC] Avoid opening namespace std (PR #95470)
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 45964eb9b88c46045e4e84beb4e2135cdeed6855 f5fc162cd1a6fdef3dcdc3e4c73aedcf67b603df -- clang/include/clang/Format/Format.h clang/include/clang/Frontend/PrecompiledPreamble.h clang/include/clang/Frontend/SerializedDiagnosticReader.h clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp `` View the diff from clang-format here. ``diff diff --git a/clang/include/clang/Frontend/SerializedDiagnosticReader.h b/clang/include/clang/Frontend/SerializedDiagnosticReader.h index 96d576a63b..f7c2012a76 100644 --- a/clang/include/clang/Frontend/SerializedDiagnosticReader.h +++ b/clang/include/clang/Frontend/SerializedDiagnosticReader.h @@ -129,6 +129,7 @@ protected: } // namespace clang template <> -struct std::is_error_code_enum : std::true_type {}; +struct std::is_error_code_enum +: std::true_type {}; #endif // LLVM_CLANG_FRONTEND_SERIALIZEDDIAGNOSTICREADER_H `` https://github.com/llvm/llvm-project/pull/95470 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 3dd73dc - [Fuchsia] Add armv7m and armv8m runtimes to Fuchsia Clang toolchain (#95337)
Author: Haowei Date: 2024-06-13T10:24:24-07:00 New Revision: 3dd73dc1996940645620fd191110b57c49183531 URL: https://github.com/llvm/llvm-project/commit/3dd73dc1996940645620fd191110b57c49183531 DIFF: https://github.com/llvm/llvm-project/commit/3dd73dc1996940645620fd191110b57c49183531.diff LOG: [Fuchsia] Add armv7m and armv8m runtimes to Fuchsia Clang toolchain (#95337) This patch adds armv7m and armv8m runtimes to Fuchsia Clang toolchain configuration. Added: Modified: clang/cmake/caches/Fuchsia-stage2.cmake Removed: diff --git a/clang/cmake/caches/Fuchsia-stage2.cmake b/clang/cmake/caches/Fuchsia-stage2.cmake index aa07b04be65cc..a573ec5473210 100644 --- a/clang/cmake/caches/Fuchsia-stage2.cmake +++ b/clang/cmake/caches/Fuchsia-stage2.cmake @@ -300,14 +300,14 @@ if(FUCHSIA_SDK) set(LLVM_RUNTIME_MULTILIB_hwasan+noexcept_TARGETS "aarch64-unknown-fuchsia;riscv64-unknown-fuchsia" CACHE STRING "") endif() -foreach(target armv6m-unknown-eabi) +foreach(target armv6m-unknown-eabi;armv7m-unknown-eabi;armv8m-unknown-eabi) list(APPEND BUILTIN_TARGETS "${target}") set(BUILTINS_${target}_CMAKE_SYSTEM_NAME Generic CACHE STRING "") set(BUILTINS_${target}_CMAKE_SYSTEM_PROCESSOR arm CACHE STRING "") set(BUILTINS_${target}_CMAKE_SYSROOT "" CACHE STRING "") set(BUILTINS_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "") foreach(lang C;CXX;ASM) -set(BUILTINS_${target}_CMAKE_${lang}_FLAGS "--target=${target} -mcpu=cortex-m0plus -mthumb" CACHE STRING "") +set(BUILTINS_${target}_CMAKE_${lang}_FLAGS "--target=${target} -mthumb" CACHE STRING "") endforeach() foreach(type SHARED;MODULE;EXE) set(BUILTINS_${target}_CMAKE_${type}_LINKER_FLAGS "-fuse-ld=lld" CACHE STRING "") @@ -321,7 +321,7 @@ foreach(target armv6m-unknown-eabi) set(RUNTIMES_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "") set(RUNTIMES_${target}_CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY CACHE STRING "") foreach(lang C;CXX;ASM) -set(RUNTIMES_${target}_CMAKE_${lang}_FLAGS "--target=${target} -mcpu=cortex-m0plus -mthumb" CACHE STRING "") +set(RUNTIMES_${target}_CMAKE_${lang}_FLAGS "--target=${target} -mthumb" CACHE STRING "") endforeach() foreach(type SHARED;MODULE;EXE) set(RUNTIMES_${target}_CMAKE_${type}_LINKER_FLAGS "-fuse-ld=lld" CACHE STRING "") ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits