[clang] [C++20] [Modules] [Reduced BMI] Remove unreachable decls GMF in redued BMI (PR #88359)
llvmbot wrote: @llvm/pr-subscribers-clang-modules Author: Chuanqi Xu (ChuanqiXu9) Changes Following of https://github.com/llvm/llvm-project/pull/76930 This follows the idea of "only writes what we writes", which I think is the most natural and efficient way to implement this optimization. We start writing the BMI from the first declaration in module purview instead of the global module fragment, so that everything in the GMF untouched won't be written in the BMI naturally. The exception is, as I said in https://github.com/llvm/llvm-project/pull/76930, when we write a declaration we need to write its decl context, and when we write the decl context, we need to write everything from it. So when we see `std::vector`, we basically need to write everything under namespace std. This violates our intention. To fix this, this patch delays the writing of namespace in the GMF. >From my local measurement, the size of the BMI decrease to 90M from 112M for a >local modules build. I think this is significant. This feature will be covered under the experimental reduced BMI so that it won't affect any existing users. So I'd like to land this when the CI gets green. Documents will be added seperately. --- Patch is 27.90 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/88359.diff 17 Files Affected: - (modified) clang/include/clang/Serialization/ASTBitCodes.h (+4) - (modified) clang/include/clang/Serialization/ASTReader.h (+14) - (modified) clang/include/clang/Serialization/ASTWriter.h (+25-1) - (modified) clang/lib/Serialization/ASTReader.cpp (+23) - (modified) clang/lib/Serialization/ASTReaderDecl.cpp (+9) - (modified) clang/lib/Serialization/ASTWriter.cpp (+117-22) - (modified) clang/lib/Serialization/ASTWriterDecl.cpp (+25-2) - (added) clang/test/CXX/module/module.glob.frag/cxx20-10-4-ex2.cppm (+58) - (modified) clang/test/Modules/inconsistent-deduction-guide-linkage.cppm (+8) - (modified) clang/test/Modules/named-modules-adl-2.cppm (+6-1) - (modified) clang/test/Modules/named-modules-adl.cppm (+6-1) - (modified) clang/test/Modules/placement-new-reachable.cpp (+7-2) - (modified) clang/test/Modules/polluted-operator.cppm (+16-7) - (modified) clang/test/Modules/pr62589.cppm (+4) - (modified) clang/test/Modules/preferred_name.cppm (+2) - (modified) clang/test/Modules/redundant-template-default-arg3.cpp (+10) - (modified) clang/test/Modules/template-function-specialization.cpp (+7-1) ``diff diff --git a/clang/include/clang/Serialization/ASTBitCodes.h b/clang/include/clang/Serialization/ASTBitCodes.h index f762116fea956c..500098dd3dab1d 100644 --- a/clang/include/clang/Serialization/ASTBitCodes.h +++ b/clang/include/clang/Serialization/ASTBitCodes.h @@ -698,6 +698,10 @@ enum ASTRecordTypes { /// Record code for an unterminated \#pragma clang assume_nonnull begin /// recorded in a preamble. PP_ASSUME_NONNULL_LOC = 67, + + /// Record code for lexical and visible block for delayed namespace in + /// reduced BMI. + DELAYED_NAMESPACE_LEXICAL_VISIBLE_RECORD = 68, }; /// Record types used within a source manager block. diff --git a/clang/include/clang/Serialization/ASTReader.h b/clang/include/clang/Serialization/ASTReader.h index e8b9f28690d9fa..6656c1c58dec9d 100644 --- a/clang/include/clang/Serialization/ASTReader.h +++ b/clang/include/clang/Serialization/ASTReader.h @@ -517,6 +517,20 @@ class ASTReader /// in the chain. DeclUpdateOffsetsMap DeclUpdateOffsets; + using DelayedNamespaceOffsetMapTy = llvm::DenseMap< + serialization::DeclID, + std::pair>; + + /// Mapping from global declaration IDs to the lexical and visible block + /// offset for delayed namespace in reduced BMI. + /// + /// We can't use the existing DeclUpdate mechanism since the DeclUpdate + /// may only be applied in an outer most read. However, we need to know + /// whether or not a DeclContext has external storage during the recursive + /// reading. So we need to apply the offset immediately after we read the + /// namespace as if it is not delayed. + DelayedNamespaceOffsetMapTy DelayedNamespaceOffsetMap; + struct PendingUpdateRecord { Decl *D; serialization::GlobalDeclID ID; diff --git a/clang/include/clang/Serialization/ASTWriter.h b/clang/include/clang/Serialization/ASTWriter.h index 214eb3601148b0..443f7703104700 100644 --- a/clang/include/clang/Serialization/ASTWriter.h +++ b/clang/include/clang/Serialization/ASTWriter.h @@ -201,6 +201,16 @@ class ASTWriter : public ASTDeserializationListener, /// The declarations and types to emit. std::queue DeclTypesToEmit; + /// The delayed namespace to emit. Only meaningful for reduced BMI. + /// + /// In reduced BMI, we want to elide the unreachable declarations in + /// the global module fragment. However, in ASTWriterDecl, when we see + /// a namespace, all the declarations in the namespace would be emitted. + /// So the optimization become mean
[clang] [C++20] [Modules] [Reduced BMI] Remove unreachable decls GMF in redued BMI (PR #88359)
https://github.com/ChuanqiXu9 ready_for_review https://github.com/llvm/llvm-project/pull/88359 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C++20] [Modules] [Reduced BMI] Remove unreachable decls GMF in redued BMI (PR #88359)
https://github.com/ChuanqiXu9 created https://github.com/llvm/llvm-project/pull/88359 Following of https://github.com/llvm/llvm-project/pull/76930 This follows the idea of "only writes what we writes", which I think is the most natural and efficient way to implement this optimization. We start writing the BMI from the first declaration in module purview instead of the global module fragment, so that everything in the GMF untouched won't be written in the BMI naturally. The exception is, as I said in https://github.com/llvm/llvm-project/pull/76930, when we write a declaration we need to write its decl context, and when we write the decl context, we need to write everything from it. So when we see `std::vector`, we basically need to write everything under namespace std. This violates our intention. To fix this, this patch delays the writing of namespace in the GMF. >From my local measurement, the size of the BMI decrease to 90M from 112M for a >local modules build. I think this is significant. This feature will be covered under the experimental reduced BMI so that it won't affect any existing users. So I'd like to land this when the CI gets green. Documents will be added seperately. >From dc35cae9d9fb979e7430a16db5a393edf4c847fa Mon Sep 17 00:00:00 2001 From: Chuanqi Xu Date: Wed, 3 Apr 2024 13:14:07 +0800 Subject: [PATCH] [C++20] [Modules] [Reduced BMI] Remove unreachable decls GMF in reduced BMI Following of https://github.com/llvm/llvm-project/pull/76930 This follows the idea of "only writes what we writes", which I think is the most natural and efficient way to implement this optimization. We start writing the BMI from the first declaration in module purview instead of the global module fragment, so that everything in the GMF untouched won't be written in the BMI naturally. The exception is, as I said in https://github.com/llvm/llvm-project/pull/76930, when we write a declaration we need to write its decl context, and when we write the decl context, we need to write everything from it. So when we see `std::vector`, we basically need to write everything under namespace std. This violates our intention. To fix this, this patch delays the writing of namespace in the GMF. >From my local measurement, the size of the BMI decrease to 90M from 112M for a local modules build. I think this is significant. This feature will be covered under the experimental reduced BMI so that it won't affect any existing users. So I'd like to land this when the CI gets green. Documents will be added seperately. --- .../include/clang/Serialization/ASTBitCodes.h | 4 + clang/include/clang/Serialization/ASTReader.h | 14 ++ clang/include/clang/Serialization/ASTWriter.h | 26 +++- clang/lib/Serialization/ASTReader.cpp | 23 +++ clang/lib/Serialization/ASTReaderDecl.cpp | 9 ++ clang/lib/Serialization/ASTWriter.cpp | 139 +++--- clang/lib/Serialization/ASTWriterDecl.cpp | 27 +++- .../module.glob.frag/cxx20-10-4-ex2.cppm | 58 .../inconsistent-deduction-guide-linkage.cppm | 8 + clang/test/Modules/named-modules-adl-2.cppm | 7 +- clang/test/Modules/named-modules-adl.cppm | 7 +- .../test/Modules/placement-new-reachable.cpp | 9 +- clang/test/Modules/polluted-operator.cppm | 23 ++- clang/test/Modules/pr62589.cppm | 4 + clang/test/Modules/preferred_name.cppm| 2 + .../redundant-template-default-arg3.cpp | 10 ++ .../template-function-specialization.cpp | 8 +- 17 files changed, 341 insertions(+), 37 deletions(-) create mode 100644 clang/test/CXX/module/module.glob.frag/cxx20-10-4-ex2.cppm diff --git a/clang/include/clang/Serialization/ASTBitCodes.h b/clang/include/clang/Serialization/ASTBitCodes.h index f762116fea956c..500098dd3dab1d 100644 --- a/clang/include/clang/Serialization/ASTBitCodes.h +++ b/clang/include/clang/Serialization/ASTBitCodes.h @@ -698,6 +698,10 @@ enum ASTRecordTypes { /// Record code for an unterminated \#pragma clang assume_nonnull begin /// recorded in a preamble. PP_ASSUME_NONNULL_LOC = 67, + + /// Record code for lexical and visible block for delayed namespace in + /// reduced BMI. + DELAYED_NAMESPACE_LEXICAL_VISIBLE_RECORD = 68, }; /// Record types used within a source manager block. diff --git a/clang/include/clang/Serialization/ASTReader.h b/clang/include/clang/Serialization/ASTReader.h index e8b9f28690d9fa..6656c1c58dec9d 100644 --- a/clang/include/clang/Serialization/ASTReader.h +++ b/clang/include/clang/Serialization/ASTReader.h @@ -517,6 +517,20 @@ class ASTReader /// in the chain. DeclUpdateOffsetsMap DeclUpdateOffsets; + using DelayedNamespaceOffsetMapTy = llvm::DenseMap< + serialization::DeclID, + std::pair>; + + /// Mapping from global declaration IDs to the lexical and visible block + /// offset for delayed namespace in reduced BMI. + /// + /// We can't use the existing DeclUpdate mechanism since the DeclUpdate
[clang] [clang][dataflow] Remove deprecated alias `ControlFlowContext`. (PR #88358)
llvmbot wrote: @llvm/pr-subscribers-clang-analysis Author: None (martinboehme) Changes --- Full diff: https://github.com/llvm/llvm-project/pull/88358.diff 2 Files Affected: - (modified) clang/docs/tools/clang-formatted-files.txt (-1) - (removed) clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h (-27) ``diff diff --git a/clang/docs/tools/clang-formatted-files.txt b/clang/docs/tools/clang-formatted-files.txt index 70687c23b15e61..a911963d85cbc7 100644 --- a/clang/docs/tools/clang-formatted-files.txt +++ b/clang/docs/tools/clang-formatted-files.txt @@ -123,7 +123,6 @@ clang/include/clang/Analysis/Analyses/CalledOnceCheck.h clang/include/clang/Analysis/Analyses/CFGReachabilityAnalysis.h clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h clang/include/clang/Analysis/FlowSensitive/AdornedCFG.h -clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h diff --git a/clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h b/clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h deleted file mode 100644 index 3972962d0b2daa..00 --- a/clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h +++ /dev/null @@ -1,27 +0,0 @@ -//===-- ControlFlowContext.h *- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===--===// -// -// This file defines a deprecated alias for AdornedCFG. -// -//===--===// - -#ifndef LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_CONTROLFLOWCONTEXT_H -#define LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_CONTROLFLOWCONTEXT_H - -#include "clang/Analysis/FlowSensitive/AdornedCFG.h" - -namespace clang { -namespace dataflow { - -// This is a deprecated alias. Use `AdornedCFG` instead. -using ControlFlowContext = AdornedCFG; - -} // namespace dataflow -} // namespace clang - -#endif // LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_CONTROLFLOWCONTEXT_H `` https://github.com/llvm/llvm-project/pull/88358 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][dataflow] Remove deprecated alias `ControlFlowContext`. (PR #88358)
https://github.com/martinboehme created https://github.com/llvm/llvm-project/pull/88358 None >From 737c3064bb02fdfb4c0a7cd1f54de8669923a615 Mon Sep 17 00:00:00 2001 From: Martin Braenne Date: Thu, 11 Apr 2024 06:40:49 + Subject: [PATCH] [clang][dataflow] Remove deprecated alias `ControlFlowContext`. --- clang/docs/tools/clang-formatted-files.txt| 1 - .../FlowSensitive/ControlFlowContext.h| 27 --- 2 files changed, 28 deletions(-) delete mode 100644 clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h diff --git a/clang/docs/tools/clang-formatted-files.txt b/clang/docs/tools/clang-formatted-files.txt index 70687c23b15e61..a911963d85cbc7 100644 --- a/clang/docs/tools/clang-formatted-files.txt +++ b/clang/docs/tools/clang-formatted-files.txt @@ -123,7 +123,6 @@ clang/include/clang/Analysis/Analyses/CalledOnceCheck.h clang/include/clang/Analysis/Analyses/CFGReachabilityAnalysis.h clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h clang/include/clang/Analysis/FlowSensitive/AdornedCFG.h -clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h diff --git a/clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h b/clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h deleted file mode 100644 index 3972962d0b2daa..00 --- a/clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h +++ /dev/null @@ -1,27 +0,0 @@ -//===-- ControlFlowContext.h *- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===--===// -// -// This file defines a deprecated alias for AdornedCFG. -// -//===--===// - -#ifndef LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_CONTROLFLOWCONTEXT_H -#define LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_CONTROLFLOWCONTEXT_H - -#include "clang/Analysis/FlowSensitive/AdornedCFG.h" - -namespace clang { -namespace dataflow { - -// This is a deprecated alias. Use `AdornedCFG` instead. -using ControlFlowContext = AdornedCFG; - -} // namespace dataflow -} // namespace clang - -#endif // LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_CONTROLFLOWCONTEXT_H ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [RISCV] Disallow target attribute use in multiversioning (PR #85899)
https://github.com/BeMg updated https://github.com/llvm/llvm-project/pull/85899 >From 894c0975638a99c84fde8d1ea5c845e5cdbf32f4 Mon Sep 17 00:00:00 2001 From: Piyou Chen Date: Mon, 18 Mar 2024 05:07:14 -0700 Subject: [PATCH 1/3] [RISCV] Disallow target attribute use in multiversioning --- clang/lib/Sema/SemaDecl.cpp | 4 1 file changed, 4 insertions(+) diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 5a23179dfbbf44..0aa0350d5c562f 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -11916,6 +11916,10 @@ static bool CheckMultiVersionFunction(Sema &S, FunctionDecl *NewFD, if (NewTA && S.getASTContext().getTargetInfo().getTriple().isAArch64()) return false; + // Target attribute on RISCV is not used for multiversioning + if (NewTA && S.getASTContext().getTargetInfo().getTriple().isRISCV()) +return false; + if (!OldDecl || !OldDecl->getAsFunction() || OldDecl->getDeclContext()->getRedeclContext() != NewFD->getDeclContext()->getRedeclContext()) { >From e6b7a2da5cb6dccd85aa3b7a12bffcc2b4a31270 Mon Sep 17 00:00:00 2001 From: Piyou Chen Date: Mon, 1 Apr 2024 23:21:25 -0700 Subject: [PATCH 2/3] Add testcase --- clang/test/Sema/attr-target-riscv.c | 6 ++ 1 file changed, 6 insertions(+) create mode 100644 clang/test/Sema/attr-target-riscv.c diff --git a/clang/test/Sema/attr-target-riscv.c b/clang/test/Sema/attr-target-riscv.c new file mode 100644 index 00..ed4e2915d6c6ef --- /dev/null +++ b/clang/test/Sema/attr-target-riscv.c @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -triple riscv64-linux-gnu -target-feature +i -fsyntax-only -verify -std=c2x %s + +//expected-note@+1 {{previous definition is here}} +int __attribute__((target("arch=rv64g"))) foo(void) { return 0; } +//expected-error@+1 {{redefinition of 'foo'}} +int __attribute__((target("arch=rv64gc"))) foo(void) { return 0; } >From b9a2a5e3dda4088056da64cf80504a542ff3ddcd Mon Sep 17 00:00:00 2001 From: Piyou Chen Date: Sun, 7 Apr 2024 22:14:46 -0700 Subject: [PATCH 3/3] Share Triple for AArch64 and RISCV --- clang/lib/Sema/SemaDecl.cpp | 6 -- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 0aa0350d5c562f..92d2b2f6120bc9 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -11912,12 +11912,14 @@ static bool CheckMultiVersionFunction(Sema &S, FunctionDecl *NewFD, return false; } + const llvm::Triple &T = S.getASTContext().getTargetInfo().getTriple(); + // Target attribute on AArch64 is not used for multiversioning - if (NewTA && S.getASTContext().getTargetInfo().getTriple().isAArch64()) + if (NewTA && T.isAArch64()) return false; // Target attribute on RISCV is not used for multiversioning - if (NewTA && S.getASTContext().getTargetInfo().getTriple().isRISCV()) + if (NewTA && T.isRISCV()) return false; if (!OldDecl || !OldDecl->getAsFunction() || ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Ensure ToolChain::LibraryPaths is not empty for non-Darwin (PR #87866)
mstorsjo wrote: > @aeubanks The problem is that in your configure, the libclang_rt is placed in > `/lib/clang/19/lib/linux/libclang_rt.builtins-arm-android.a`, > instead of > `/lib/clang/19/lib/arm-unknown-linux-android/libclang_rt.builtins.a`. The point is that both locations were supposed to be accepted, as they were before - this PR was not supposed to be a policy change that affects that. https://github.com/llvm/llvm-project/pull/87866 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][dataflow] Reland #87320: Propagate locations from result objects to initializers. (PR #88316)
https://github.com/martinboehme closed https://github.com/llvm/llvm-project/pull/88316 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 71f1932 - [clang][dataflow] Reland #87320: Propagate locations from result objects to initializers. (#88316)
Author: martinboehme Date: 2024-04-11T08:20:35+02:00 New Revision: 71f1932b842793e5dc7b17051452e8ff2f9219aa URL: https://github.com/llvm/llvm-project/commit/71f1932b842793e5dc7b17051452e8ff2f9219aa DIFF: https://github.com/llvm/llvm-project/commit/71f1932b842793e5dc7b17051452e8ff2f9219aa.diff LOG: [clang][dataflow] Reland #87320: Propagate locations from result objects to initializers. (#88316) This relands #87320 and additionally removes the now-unused function `isOriginalRecordConstructor()`, which was causing buildbots to fail. Added: Modified: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp clang/lib/Analysis/FlowSensitive/Transfer.cpp clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp clang/unittests/Analysis/FlowSensitive/TransferTest.cpp Removed: diff --git a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h index 9a65f76cdf56bc..706664d7db1c25 100644 --- a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h +++ b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h @@ -30,6 +30,7 @@ #include "llvm/ADT/MapVector.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/ErrorHandling.h" +#include #include #include @@ -344,17 +345,6 @@ class Environment { /// location of the result object to pass in `this`, even though prvalues are /// otherwise not associated with storage locations. /// - /// FIXME: Currently, this simply returns a stable storage location for `E`, - /// but this doesn't do the right thing in scenarios like the following: - /// ``` - /// MyClass c = some_condition()? MyClass(foo) : MyClass(bar); - /// ``` - /// Here, `MyClass(foo)` and `MyClass(bar)` will have two diff erent storage - /// locations, when in fact their storage locations should be the same. - /// Eventually, we want to propagate storage locations from result objects - /// down to the prvalues that initialize them, similar to the way that this is - /// done in Clang's CodeGen. - /// /// Requirements: /// `E` must be a prvalue of record type. RecordStorageLocation & @@ -462,7 +452,13 @@ class Environment { /// Initializes the fields (including synthetic fields) of `Loc` with values, /// unless values of the field type are not supported or we hit one of the /// limits at which we stop producing values. - void initializeFieldsWithValues(RecordStorageLocation &Loc); + /// If `Type` is provided, initializes only those fields that are modeled for + /// `Type`; this is intended for use in cases where `Loc` is a derived type + /// and we only want to initialize the fields of a base type. + void initializeFieldsWithValues(RecordStorageLocation &Loc, QualType Type); + void initializeFieldsWithValues(RecordStorageLocation &Loc) { +initializeFieldsWithValues(Loc, Loc.getType()); + } /// Assigns `Val` as the value of `Loc` in the environment. void setValue(const StorageLocation &Loc, Value &Val); @@ -653,6 +649,9 @@ class Environment { LLVM_DUMP_METHOD void dump(raw_ostream &OS) const; private: + using PrValueToResultObject = + llvm::DenseMap; + // The copy-constructor is for use in fork() only. Environment(const Environment &) = default; @@ -682,8 +681,10 @@ class Environment { /// Initializes the fields (including synthetic fields) of `Loc` with values, /// unless values of the field type are not supported or we hit one of the /// limits at which we stop producing values (controlled by `Visited`, - /// `Depth`, and `CreatedValuesCount`). - void initializeFieldsWithValues(RecordStorageLocation &Loc, + /// `Depth`, and `CreatedValuesCount`). If `Type` is diff erent from + /// `Loc.getType()`, initializes only those fields that are modeled for + /// `Type`. + void initializeFieldsWithValues(RecordStorageLocation &Loc, QualType Type, llvm::DenseSet &Visited, int Depth, int &CreatedValuesCount); @@ -702,22 +703,45 @@ class Environment { /// and functions referenced in `FuncDecl`. `FuncDecl` must have a body. void initFieldsGlobalsAndFuncs(const FunctionDecl *FuncDecl); + static PrValueToResultObject + buildResultObjectMap(DataflowAnalysisContext *DACtx, + const FunctionDecl *FuncDecl, + RecordStorageLocation *ThisPointeeLoc, + RecordStorageLocation *LocForRecordReturnVal); + // `DACtx` is not null and not owned by this object. DataflowAnalysisContext *DACtx; - // FIXME: move the fields `CallStack`, `ReturnVal`, `ReturnLoc` and - // `ThisPointeeLoc` into a separate call-context object, shar
[clang] [Driver] Ensure ToolChain::LibraryPaths is not empty for non-Darwin (PR #87866)
wzssyqa wrote: @aeubanks The problem is that in your configure, the libclang_rt is please in `/lib/clang/19/lib/linux/libclang_rt.builtins-arm-android.a`, instead of `/lib/clang/19/lib/arm-unknown-linux-android/libclang_rt.builtins.a`. https://github.com/llvm/llvm-project/pull/87866 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Fix test case due to clang-format bug fix (PR #88352)
owenca wrote: @HighCommander4 Thanks! https://github.com/llvm/llvm-project/pull/88352 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Fix test case due to clang-format bug fix (PR #88352)
https://github.com/owenca closed https://github.com/llvm/llvm-project/pull/88352 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] 5964c94 - [clangd] Fix test case due to clang-format bug fix (#88352)
Author: Owen Pan Date: 2024-04-10T22:25:37-07:00 New Revision: 5964c944bfe74cee2872cddb66eff22866cdb6ee URL: https://github.com/llvm/llvm-project/commit/5964c944bfe74cee2872cddb66eff22866cdb6ee DIFF: https://github.com/llvm/llvm-project/commit/5964c944bfe74cee2872cddb66eff22866cdb6ee.diff LOG: [clangd] Fix test case due to clang-format bug fix (#88352) See commit 51f1681424f1. Added: Modified: clang-tools-extra/clangd/unittests/HoverTests.cpp Removed: diff --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp b/clang-tools-extra/clangd/unittests/HoverTests.cpp index 35db757b9c15b5..5ead74748f550c 100644 --- a/clang-tools-extra/clangd/unittests/HoverTests.cpp +++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp @@ -1983,10 +1983,14 @@ TEST(Hover, All) { HI.Kind = index::SymbolKind::Macro; HI.Definition = R"cpp(#define MACRO \ - { return 0; } + { \ +return 0; \ + } // Expands to -{ return 0; })cpp"; +{ + return 0; +})cpp"; }}, { R"cpp(// Forward class declaration ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Fix test case due to clang-format bug fix (PR #88352)
https://github.com/HighCommander4 approved this pull request. https://github.com/llvm/llvm-project/pull/88352 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Fix test case due to clang-format bug fix (PR #88352)
https://github.com/owenca updated https://github.com/llvm/llvm-project/pull/88352 >From a070f07c16ddacc1aaf7591a1f7c129bf6abc90a Mon Sep 17 00:00:00 2001 From: Owen Pan Date: Wed, 10 Apr 2024 21:22:05 -0700 Subject: [PATCH] [clangd] Fix test case due to clang-format bug fix See commit 51f1681424f1. --- clang-tools-extra/clangd/unittests/HoverTests.cpp | 8 ++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp b/clang-tools-extra/clangd/unittests/HoverTests.cpp index 35db757b9c15b5..5ead74748f550c 100644 --- a/clang-tools-extra/clangd/unittests/HoverTests.cpp +++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp @@ -1983,10 +1983,14 @@ TEST(Hover, All) { HI.Kind = index::SymbolKind::Macro; HI.Definition = R"cpp(#define MACRO \ - { return 0; } + { \ +return 0; \ + } // Expands to -{ return 0; })cpp"; +{ + return 0; +})cpp"; }}, { R"cpp(// Forward class declaration ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [InstCombine] Infer nsw/nuw for trunc (PR #87910)
@@ -897,7 +897,20 @@ Instruction *InstCombinerImpl::visitTrunc(TruncInst &Trunc) { } } - return nullptr; + bool Changed = false; + if (!Trunc.hasNoSignedWrap() && + ComputeMaxSignificantBits(Src, /*Depth=*/0, &Trunc) <= DestWidth) { +Trunc.setHasNoSignedWrap(true); +Changed = true; + } + if (!Trunc.hasNoUnsignedWrap() && + MaskedValueIsZero(Src, APInt::getBitsSetFrom(SrcWidth, DestWidth), +/*Depth=*/0, &Trunc)) { +Trunc.setHasNoUnsignedWrap(true); +Changed = true; dtcxzyw wrote: Ping @nikic https://github.com/llvm/llvm-project/pull/87910 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Add txtpb to the list of supported TextProto extensions (PR #88355)
llvmbot wrote: @llvm/pr-subscribers-clang-format Author: Jing Wang (jingw) Changes According to https://protobuf.dev/reference/protobuf/textformat-spec/#text-format-files, txtpb is the canonical extension --- Full diff: https://github.com/llvm/llvm-project/pull/88355.diff 4 Files Affected: - (modified) clang/docs/ClangFormat.rst (+1-1) - (modified) clang/lib/Format/Format.cpp (+5-1) - (modified) clang/test/Format/lit.local.cfg (+1) - (modified) clang/tools/clang-format/ClangFormat.cpp (+1-1) ``diff diff --git a/clang/docs/ClangFormat.rst b/clang/docs/ClangFormat.rst index 80dc38a075c8fc..dbd9c91ae508e5 100644 --- a/clang/docs/ClangFormat.rst +++ b/clang/docs/ClangFormat.rst @@ -54,7 +54,7 @@ to format C/C++/Java/JavaScript/JSON/Objective-C/Protobuf/C# code. Objective-C: .m .mm Proto: .proto .protodevel TableGen: .td - TextProto: .textpb .pb.txt .textproto .asciipb + TextProto: .txtpb .textpb .pb.txt .textproto .asciipb Verilog: .sv .svh .v .vh --cursor=- The position of the cursor when invoking clang-format from an editor integration diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 89e6c19b0af45c..ccb2c9190e2eff 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -3891,7 +3891,11 @@ static FormatStyle::LanguageKind getLanguageByFileName(StringRef FileName) { FileName.ends_with_insensitive(".protodevel")) { return FormatStyle::LK_Proto; } - if (FileName.ends_with_insensitive(".textpb") || + // txtpb is the canonical extension, and textproto is the legacy canonical + // extension + // https://protobuf.dev/reference/protobuf/textformat-spec/#text-format-files + if (FileName.ends_with_insensitive(".txtpb") || + FileName.ends_with_insensitive(".textpb") || FileName.ends_with_insensitive(".pb.txt") || FileName.ends_with_insensitive(".textproto") || FileName.ends_with_insensitive(".asciipb")) { diff --git a/clang/test/Format/lit.local.cfg b/clang/test/Format/lit.local.cfg index 3851397a3f7ccc..3eb0f54ceaa6f9 100644 --- a/clang/test/Format/lit.local.cfg +++ b/clang/test/Format/lit.local.cfg @@ -12,6 +12,7 @@ config.suffixes = [ ".proto", ".protodevel", ".pb.txt", +".txtpb", ".textproto", ".textpb", ".asciipb", diff --git a/clang/tools/clang-format/ClangFormat.cpp b/clang/tools/clang-format/ClangFormat.cpp index ed401135ad8433..feb733fe3c9e0b 100644 --- a/clang/tools/clang-format/ClangFormat.cpp +++ b/clang/tools/clang-format/ClangFormat.cpp @@ -92,7 +92,7 @@ static cl::opt AssumeFileName( " Objective-C: .m .mm\n" " Proto: .proto .protodevel\n" " TableGen: .td\n" - " TextProto: .textpb .pb.txt .textproto .asciipb\n" + " TextProto: .txtpb .textpb .pb.txt .textproto .asciipb\n" " Verilog: .sv .svh .v .vh"), cl::init(""), cl::cat(ClangFormatCategory)); `` https://github.com/llvm/llvm-project/pull/88355 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Add txtpb to the list of supported TextProto extensions (PR #88355)
github-actions[bot] wrote: Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using `@` followed by their GitHub username. If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the [LLVM GitHub User Guide](https://llvm.org/docs/GitHub.html). You can also ask questions in a comment on this PR, on the [LLVM Discord](https://discord.com/invite/xS7Z362) or on the [forums](https://discourse.llvm.org/). https://github.com/llvm/llvm-project/pull/88355 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Add txtpb to the list of supported TextProto extensions (PR #88355)
https://github.com/jingw created https://github.com/llvm/llvm-project/pull/88355 According to https://protobuf.dev/reference/protobuf/textformat-spec/#text-format-files, txtpb is the canonical extension >From b8463dbc5ffa3a401bc9470a3c86e8c72964a0f6 Mon Sep 17 00:00:00 2001 From: Jing Wang <99ji...@gmail.com> Date: Wed, 10 Apr 2024 22:04:17 -0700 Subject: [PATCH] Add txtpb to the list of supported TextProto extensions According to https://protobuf.dev/reference/protobuf/textformat-spec/#text-format-files, txtpb is the canonical extension --- clang/docs/ClangFormat.rst | 2 +- clang/lib/Format/Format.cpp | 6 +- clang/test/Format/lit.local.cfg | 1 + clang/tools/clang-format/ClangFormat.cpp | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/clang/docs/ClangFormat.rst b/clang/docs/ClangFormat.rst index 80dc38a075c8fc..dbd9c91ae508e5 100644 --- a/clang/docs/ClangFormat.rst +++ b/clang/docs/ClangFormat.rst @@ -54,7 +54,7 @@ to format C/C++/Java/JavaScript/JSON/Objective-C/Protobuf/C# code. Objective-C: .m .mm Proto: .proto .protodevel TableGen: .td - TextProto: .textpb .pb.txt .textproto .asciipb + TextProto: .txtpb .textpb .pb.txt .textproto .asciipb Verilog: .sv .svh .v .vh --cursor=- The position of the cursor when invoking clang-format from an editor integration diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 89e6c19b0af45c..ccb2c9190e2eff 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -3891,7 +3891,11 @@ static FormatStyle::LanguageKind getLanguageByFileName(StringRef FileName) { FileName.ends_with_insensitive(".protodevel")) { return FormatStyle::LK_Proto; } - if (FileName.ends_with_insensitive(".textpb") || + // txtpb is the canonical extension, and textproto is the legacy canonical + // extension + // https://protobuf.dev/reference/protobuf/textformat-spec/#text-format-files + if (FileName.ends_with_insensitive(".txtpb") || + FileName.ends_with_insensitive(".textpb") || FileName.ends_with_insensitive(".pb.txt") || FileName.ends_with_insensitive(".textproto") || FileName.ends_with_insensitive(".asciipb")) { diff --git a/clang/test/Format/lit.local.cfg b/clang/test/Format/lit.local.cfg index 3851397a3f7ccc..3eb0f54ceaa6f9 100644 --- a/clang/test/Format/lit.local.cfg +++ b/clang/test/Format/lit.local.cfg @@ -12,6 +12,7 @@ config.suffixes = [ ".proto", ".protodevel", ".pb.txt", +".txtpb", ".textproto", ".textpb", ".asciipb", diff --git a/clang/tools/clang-format/ClangFormat.cpp b/clang/tools/clang-format/ClangFormat.cpp index ed401135ad8433..feb733fe3c9e0b 100644 --- a/clang/tools/clang-format/ClangFormat.cpp +++ b/clang/tools/clang-format/ClangFormat.cpp @@ -92,7 +92,7 @@ static cl::opt AssumeFileName( " Objective-C: .m .mm\n" " Proto: .proto .protodevel\n" " TableGen: .td\n" - " TextProto: .textpb .pb.txt .textproto .asciipb\n" + " TextProto: .txtpb .textpb .pb.txt .textproto .asciipb\n" " Verilog: .sv .svh .v .vh"), cl::init(""), cl::cat(ClangFormatCategory)); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][NFC] Move more functions to `SemaHLSL` (PR #88354)
llvmbot wrote: @llvm/pr-subscribers-hlsl Author: Vlad Serebrennikov (Endilll) Changes A follow-up to #87912. I'm moving more HLSL-related functions from `Sema` to `SemaHLSL`. I'm also dropping `HLSL` from their names in the process. --- Patch is 24.36 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/88354.diff 6 Files Affected: - (modified) clang/include/clang/Sema/Sema.h (-15) - (modified) clang/include/clang/Sema/SemaHLSL.h (+23-4) - (modified) clang/lib/Parse/ParseHLSL.cpp (+5-5) - (modified) clang/lib/Sema/SemaDecl.cpp (+6-124) - (modified) clang/lib/Sema/SemaDeclAttr.cpp (+4-50) - (modified) clang/lib/Sema/SemaHLSL.cpp (+180-6) ``diff diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index e3e255a0dd76f8..e904cd3ad13fb7 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -2940,13 +2940,6 @@ class Sema final : public SemaBase { QualType NewT, QualType OldT); void CheckMain(FunctionDecl *FD, const DeclSpec &D); void CheckMSVCRTEntryPoint(FunctionDecl *FD); - void ActOnHLSLTopLevelFunction(FunctionDecl *FD); - void CheckHLSLEntryPoint(FunctionDecl *FD); - void CheckHLSLSemanticAnnotation(FunctionDecl *EntryPoint, const Decl *Param, - const HLSLAnnotationAttr *AnnotationAttr); - void DiagnoseHLSLAttrStageMismatch( - const Attr *A, HLSLShaderAttr::ShaderType Stage, - std::initializer_list AllowedStages); Attr *getImplicitCodeSegOrSectionAttrForFunction(const FunctionDecl *FD, bool IsDefinition); void CheckFunctionOrTemplateParamDeclarator(Scope *S, Declarator &D); @@ -3707,14 +3700,6 @@ class Sema final : public SemaBase { StringRef UuidAsWritten, MSGuidDecl *GuidDecl); BTFDeclTagAttr *mergeBTFDeclTagAttr(Decl *D, const BTFDeclTagAttr &AL); - HLSLNumThreadsAttr *mergeHLSLNumThreadsAttr(Decl *D, - const AttributeCommonInfo &AL, - int X, int Y, int Z); - HLSLShaderAttr *mergeHLSLShaderAttr(Decl *D, const AttributeCommonInfo &AL, - HLSLShaderAttr::ShaderType ShaderType); - HLSLParamModifierAttr * - mergeHLSLParamModifierAttr(Decl *D, const AttributeCommonInfo &AL, - HLSLParamModifierAttr::Spelling Spelling); WebAssemblyImportNameAttr * mergeImportNameAttr(Decl *D, const WebAssemblyImportNameAttr &AL); diff --git a/clang/include/clang/Sema/SemaHLSL.h b/clang/include/clang/Sema/SemaHLSL.h index acc675963c23a5..34acaf19517f2a 100644 --- a/clang/include/clang/Sema/SemaHLSL.h +++ b/clang/include/clang/Sema/SemaHLSL.h @@ -13,12 +13,16 @@ #ifndef LLVM_CLANG_SEMA_SEMAHLSL_H #define LLVM_CLANG_SEMA_SEMAHLSL_H +#include "clang/AST/Attr.h" +#include "clang/AST/Decl.h" #include "clang/AST/DeclBase.h" #include "clang/AST/Expr.h" +#include "clang/Basic/AttributeCommonInfo.h" #include "clang/Basic/IdentifierTable.h" #include "clang/Basic/SourceLocation.h" #include "clang/Sema/Scope.h" #include "clang/Sema/SemaBase.h" +#include namespace clang { @@ -26,10 +30,25 @@ class SemaHLSL : public SemaBase { public: SemaHLSL(Sema &S); - Decl *ActOnStartHLSLBuffer(Scope *BufferScope, bool CBuffer, - SourceLocation KwLoc, IdentifierInfo *Ident, - SourceLocation IdentLoc, SourceLocation LBrace); - void ActOnFinishHLSLBuffer(Decl *Dcl, SourceLocation RBrace); + Decl *ActOnStartBuffer(Scope *BufferScope, bool CBuffer, SourceLocation KwLoc, + IdentifierInfo *Ident, SourceLocation IdentLoc, + SourceLocation LBrace); + void ActOnFinishBuffer(Decl *Dcl, SourceLocation RBrace); + HLSLNumThreadsAttr *mergeNumThreadsAttr(Decl *D, + const AttributeCommonInfo &AL, int X, + int Y, int Z); + HLSLShaderAttr *mergeShaderAttr(Decl *D, const AttributeCommonInfo &AL, + HLSLShaderAttr::ShaderType ShaderType); + HLSLParamModifierAttr * + mergeParamModifierAttr(Decl *D, const AttributeCommonInfo &AL, + HLSLParamModifierAttr::Spelling Spelling); + void ActOnTopLevelFunction(FunctionDecl *FD); + void CheckEntryPoint(FunctionDecl *FD); + void CheckSemanticAnnotation(FunctionDecl *EntryPoint, const Decl *Param, + const HLSLAnnotationAttr *AnnotationAttr); + void DiagnoseAttrStageMismatch( + const Attr *A, HLSLShaderAttr::ShaderType Stage, + std::initializer_list AllowedStages); }; } // namespace clang diff --git a/clang/lib/Parse/ParseHLSL.cpp b/clang/lib/Parse/ParseHLSL.cpp index 5afc958600fa55..d97985d42369ad 100644 --- a/clang/lib/Parse/ParseHLSL.cpp +++ b/clang/l
[clang] [clang][NFC] Move more functions to `SemaHLSL` (PR #88354)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Vlad Serebrennikov (Endilll) Changes A follow-up to #87912. I'm moving more HLSL-related functions from `Sema` to `SemaHLSL`. I'm also dropping `HLSL` from their names in the process. --- Patch is 24.36 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/88354.diff 6 Files Affected: - (modified) clang/include/clang/Sema/Sema.h (-15) - (modified) clang/include/clang/Sema/SemaHLSL.h (+23-4) - (modified) clang/lib/Parse/ParseHLSL.cpp (+5-5) - (modified) clang/lib/Sema/SemaDecl.cpp (+6-124) - (modified) clang/lib/Sema/SemaDeclAttr.cpp (+4-50) - (modified) clang/lib/Sema/SemaHLSL.cpp (+180-6) ``diff diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index e3e255a0dd76f8..e904cd3ad13fb7 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -2940,13 +2940,6 @@ class Sema final : public SemaBase { QualType NewT, QualType OldT); void CheckMain(FunctionDecl *FD, const DeclSpec &D); void CheckMSVCRTEntryPoint(FunctionDecl *FD); - void ActOnHLSLTopLevelFunction(FunctionDecl *FD); - void CheckHLSLEntryPoint(FunctionDecl *FD); - void CheckHLSLSemanticAnnotation(FunctionDecl *EntryPoint, const Decl *Param, - const HLSLAnnotationAttr *AnnotationAttr); - void DiagnoseHLSLAttrStageMismatch( - const Attr *A, HLSLShaderAttr::ShaderType Stage, - std::initializer_list AllowedStages); Attr *getImplicitCodeSegOrSectionAttrForFunction(const FunctionDecl *FD, bool IsDefinition); void CheckFunctionOrTemplateParamDeclarator(Scope *S, Declarator &D); @@ -3707,14 +3700,6 @@ class Sema final : public SemaBase { StringRef UuidAsWritten, MSGuidDecl *GuidDecl); BTFDeclTagAttr *mergeBTFDeclTagAttr(Decl *D, const BTFDeclTagAttr &AL); - HLSLNumThreadsAttr *mergeHLSLNumThreadsAttr(Decl *D, - const AttributeCommonInfo &AL, - int X, int Y, int Z); - HLSLShaderAttr *mergeHLSLShaderAttr(Decl *D, const AttributeCommonInfo &AL, - HLSLShaderAttr::ShaderType ShaderType); - HLSLParamModifierAttr * - mergeHLSLParamModifierAttr(Decl *D, const AttributeCommonInfo &AL, - HLSLParamModifierAttr::Spelling Spelling); WebAssemblyImportNameAttr * mergeImportNameAttr(Decl *D, const WebAssemblyImportNameAttr &AL); diff --git a/clang/include/clang/Sema/SemaHLSL.h b/clang/include/clang/Sema/SemaHLSL.h index acc675963c23a5..34acaf19517f2a 100644 --- a/clang/include/clang/Sema/SemaHLSL.h +++ b/clang/include/clang/Sema/SemaHLSL.h @@ -13,12 +13,16 @@ #ifndef LLVM_CLANG_SEMA_SEMAHLSL_H #define LLVM_CLANG_SEMA_SEMAHLSL_H +#include "clang/AST/Attr.h" +#include "clang/AST/Decl.h" #include "clang/AST/DeclBase.h" #include "clang/AST/Expr.h" +#include "clang/Basic/AttributeCommonInfo.h" #include "clang/Basic/IdentifierTable.h" #include "clang/Basic/SourceLocation.h" #include "clang/Sema/Scope.h" #include "clang/Sema/SemaBase.h" +#include namespace clang { @@ -26,10 +30,25 @@ class SemaHLSL : public SemaBase { public: SemaHLSL(Sema &S); - Decl *ActOnStartHLSLBuffer(Scope *BufferScope, bool CBuffer, - SourceLocation KwLoc, IdentifierInfo *Ident, - SourceLocation IdentLoc, SourceLocation LBrace); - void ActOnFinishHLSLBuffer(Decl *Dcl, SourceLocation RBrace); + Decl *ActOnStartBuffer(Scope *BufferScope, bool CBuffer, SourceLocation KwLoc, + IdentifierInfo *Ident, SourceLocation IdentLoc, + SourceLocation LBrace); + void ActOnFinishBuffer(Decl *Dcl, SourceLocation RBrace); + HLSLNumThreadsAttr *mergeNumThreadsAttr(Decl *D, + const AttributeCommonInfo &AL, int X, + int Y, int Z); + HLSLShaderAttr *mergeShaderAttr(Decl *D, const AttributeCommonInfo &AL, + HLSLShaderAttr::ShaderType ShaderType); + HLSLParamModifierAttr * + mergeParamModifierAttr(Decl *D, const AttributeCommonInfo &AL, + HLSLParamModifierAttr::Spelling Spelling); + void ActOnTopLevelFunction(FunctionDecl *FD); + void CheckEntryPoint(FunctionDecl *FD); + void CheckSemanticAnnotation(FunctionDecl *EntryPoint, const Decl *Param, + const HLSLAnnotationAttr *AnnotationAttr); + void DiagnoseAttrStageMismatch( + const Attr *A, HLSLShaderAttr::ShaderType Stage, + std::initializer_list AllowedStages); }; } // namespace clang diff --git a/clang/lib/Parse/ParseHLSL.cpp b/clang/lib/Parse/ParseHLSL.cpp index 5afc958600fa55..d97985d42369ad 100644 --- a/clang/lib/Parse/ParseHLSL.cpp +++ b/clang/
[clang] [clang][NFC] Move more functions to `SemaHLSL` (PR #88354)
https://github.com/Endilll created https://github.com/llvm/llvm-project/pull/88354 A follow-up to #87912. I'm moving more HLSL-related functions from `Sema` to `SemaHLSL`. I'm also dropping `HLSL` from their names in the process. >From ecff8db824552872ba055fdc0bca42b1a0386c39 Mon Sep 17 00:00:00 2001 From: Vlad Serebrennikov Date: Thu, 11 Apr 2024 07:56:46 +0300 Subject: [PATCH] [clang][NFC] Move more functions to `SemaHLSL` --- clang/include/clang/Sema/Sema.h | 15 --- clang/include/clang/Sema/SemaHLSL.h | 27 +++- clang/lib/Parse/ParseHLSL.cpp | 10 +- clang/lib/Sema/SemaDecl.cpp | 130 +-- clang/lib/Sema/SemaDeclAttr.cpp | 54 +--- clang/lib/Sema/SemaHLSL.cpp | 186 +++- 6 files changed, 218 insertions(+), 204 deletions(-) diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index e3e255a0dd76f8..e904cd3ad13fb7 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -2940,13 +2940,6 @@ class Sema final : public SemaBase { QualType NewT, QualType OldT); void CheckMain(FunctionDecl *FD, const DeclSpec &D); void CheckMSVCRTEntryPoint(FunctionDecl *FD); - void ActOnHLSLTopLevelFunction(FunctionDecl *FD); - void CheckHLSLEntryPoint(FunctionDecl *FD); - void CheckHLSLSemanticAnnotation(FunctionDecl *EntryPoint, const Decl *Param, - const HLSLAnnotationAttr *AnnotationAttr); - void DiagnoseHLSLAttrStageMismatch( - const Attr *A, HLSLShaderAttr::ShaderType Stage, - std::initializer_list AllowedStages); Attr *getImplicitCodeSegOrSectionAttrForFunction(const FunctionDecl *FD, bool IsDefinition); void CheckFunctionOrTemplateParamDeclarator(Scope *S, Declarator &D); @@ -3707,14 +3700,6 @@ class Sema final : public SemaBase { StringRef UuidAsWritten, MSGuidDecl *GuidDecl); BTFDeclTagAttr *mergeBTFDeclTagAttr(Decl *D, const BTFDeclTagAttr &AL); - HLSLNumThreadsAttr *mergeHLSLNumThreadsAttr(Decl *D, - const AttributeCommonInfo &AL, - int X, int Y, int Z); - HLSLShaderAttr *mergeHLSLShaderAttr(Decl *D, const AttributeCommonInfo &AL, - HLSLShaderAttr::ShaderType ShaderType); - HLSLParamModifierAttr * - mergeHLSLParamModifierAttr(Decl *D, const AttributeCommonInfo &AL, - HLSLParamModifierAttr::Spelling Spelling); WebAssemblyImportNameAttr * mergeImportNameAttr(Decl *D, const WebAssemblyImportNameAttr &AL); diff --git a/clang/include/clang/Sema/SemaHLSL.h b/clang/include/clang/Sema/SemaHLSL.h index acc675963c23a5..34acaf19517f2a 100644 --- a/clang/include/clang/Sema/SemaHLSL.h +++ b/clang/include/clang/Sema/SemaHLSL.h @@ -13,12 +13,16 @@ #ifndef LLVM_CLANG_SEMA_SEMAHLSL_H #define LLVM_CLANG_SEMA_SEMAHLSL_H +#include "clang/AST/Attr.h" +#include "clang/AST/Decl.h" #include "clang/AST/DeclBase.h" #include "clang/AST/Expr.h" +#include "clang/Basic/AttributeCommonInfo.h" #include "clang/Basic/IdentifierTable.h" #include "clang/Basic/SourceLocation.h" #include "clang/Sema/Scope.h" #include "clang/Sema/SemaBase.h" +#include namespace clang { @@ -26,10 +30,25 @@ class SemaHLSL : public SemaBase { public: SemaHLSL(Sema &S); - Decl *ActOnStartHLSLBuffer(Scope *BufferScope, bool CBuffer, - SourceLocation KwLoc, IdentifierInfo *Ident, - SourceLocation IdentLoc, SourceLocation LBrace); - void ActOnFinishHLSLBuffer(Decl *Dcl, SourceLocation RBrace); + Decl *ActOnStartBuffer(Scope *BufferScope, bool CBuffer, SourceLocation KwLoc, + IdentifierInfo *Ident, SourceLocation IdentLoc, + SourceLocation LBrace); + void ActOnFinishBuffer(Decl *Dcl, SourceLocation RBrace); + HLSLNumThreadsAttr *mergeNumThreadsAttr(Decl *D, + const AttributeCommonInfo &AL, int X, + int Y, int Z); + HLSLShaderAttr *mergeShaderAttr(Decl *D, const AttributeCommonInfo &AL, + HLSLShaderAttr::ShaderType ShaderType); + HLSLParamModifierAttr * + mergeParamModifierAttr(Decl *D, const AttributeCommonInfo &AL, + HLSLParamModifierAttr::Spelling Spelling); + void ActOnTopLevelFunction(FunctionDecl *FD); + void CheckEntryPoint(FunctionDecl *FD); + void CheckSemanticAnnotation(FunctionDecl *EntryPoint, const Decl *Param, + const HLSLAnnotationAttr *AnnotationAttr); + void DiagnoseAttrStageMismatch( + const Attr *A, HLSLShaderAttr::ShaderType Stage, + std::initializer_list AllowedStages); }; } // namespace clang diff --git a/clang/lib/Parse/ParseHLSL.cpp b/clang/lib/Parse/ParseH
[clang] [llvm] [InstCombine] Add canonicalization of `sitofp` -> `uitofp nneg` (PR #88299)
goldsteinn wrote: > Can the implementation of foldFBinOpOfIntCastsFromSign be simplified to use > nneg instead of KnownBits after this change? yeah we could. Should I do a survey of existing folds first to ensure we don't incorrectly keep flags (like with `trunc nuw/nsw`) before integrating too deeply? https://github.com/llvm/llvm-project/pull/88299 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Fix test case due to clang-format bug fix (PR #88352)
llvmbot wrote: @llvm/pr-subscribers-clangd Author: Owen Pan (owenca) Changes See commit 51f1681424f1. --- Full diff: https://github.com/llvm/llvm-project/pull/88352.diff 1 Files Affected: - (modified) clang-tools-extra/clangd/unittests/HoverTests.cpp (+3-1) ``diff diff --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp b/clang-tools-extra/clangd/unittests/HoverTests.cpp index 35db757b9c15b5..45266959802832 100644 --- a/clang-tools-extra/clangd/unittests/HoverTests.cpp +++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp @@ -1986,7 +1986,9 @@ TEST(Hover, All) { { return 0; } // Expands to -{ return 0; })cpp"; + { \ +return 0; \ + })cpp"; }}, { R"cpp(// Forward class declaration `` https://github.com/llvm/llvm-project/pull/88352 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Fix test case due to clang-format bug fix (PR #88352)
llvmbot wrote: @llvm/pr-subscribers-clang-tools-extra Author: Owen Pan (owenca) Changes See commit 51f1681424f1. --- Full diff: https://github.com/llvm/llvm-project/pull/88352.diff 1 Files Affected: - (modified) clang-tools-extra/clangd/unittests/HoverTests.cpp (+3-1) ``diff diff --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp b/clang-tools-extra/clangd/unittests/HoverTests.cpp index 35db757b9c15b5..45266959802832 100644 --- a/clang-tools-extra/clangd/unittests/HoverTests.cpp +++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp @@ -1986,7 +1986,9 @@ TEST(Hover, All) { { return 0; } // Expands to -{ return 0; })cpp"; + { \ +return 0; \ + })cpp"; }}, { R"cpp(// Forward class declaration `` https://github.com/llvm/llvm-project/pull/88352 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Fix test case due to clang-format bug fix (PR #88352)
https://github.com/owenca created https://github.com/llvm/llvm-project/pull/88352 See commit 51f1681424f1. >From 3ecf27d15646345f43703f5a361bd9766307ebf4 Mon Sep 17 00:00:00 2001 From: Owen Pan Date: Wed, 10 Apr 2024 21:22:05 -0700 Subject: [PATCH] [clangd] Fix test case due to clang-format bug fix See commit 51f1681424f1. --- clang-tools-extra/clangd/unittests/HoverTests.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp b/clang-tools-extra/clangd/unittests/HoverTests.cpp index 35db757b9c15b5..45266959802832 100644 --- a/clang-tools-extra/clangd/unittests/HoverTests.cpp +++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp @@ -1986,7 +1986,9 @@ TEST(Hover, All) { { return 0; } // Expands to -{ return 0; })cpp"; + { \ +return 0; \ + })cpp"; }}, { R"cpp(// Forward class declaration ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] XFAIL clang/Driver/test/compress.c on AIX (PR #87269)
MaskRay wrote: Can you edit the description to state which command fails on AIX? These tests all contain `-###` to stop after clangDriver completes. And `clang --target=powerpc-ibm-aix -fintegrated-as -Wa,-compress-debug-sections -c a.c '-###'` seems to work for me. https://github.com/llvm/llvm-project/pull/87269 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang][deps] Overload `Filesystem::exists` in `DependencyScanningFilesystem` to have it use cached `status` (PR #88152)
@@ -270,6 +270,12 @@ DependencyScanningWorkerFilesystem::status(const Twine &Path) { return Result->getStatus(); } +bool +DependencyScanningWorkerFilesystem::exists(const Twine &Path) { + llvm::ErrorOr Status = status(Path); jansvoboda11 wrote: Would be good to explain why it's necessary & okay to kill the `exists()` optimization here. https://github.com/llvm/llvm-project/pull/88152 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 75edf0c - [NFC] [Serialization] Avoid accessing PendingBodies as much as possible
Author: Chuanqi Xu Date: 2024-04-11T11:08:58+08:00 New Revision: 75edf0c18c777d69df7cfc6462e5233649bd47d4 URL: https://github.com/llvm/llvm-project/commit/75edf0c18c777d69df7cfc6462e5233649bd47d4 DIFF: https://github.com/llvm/llvm-project/commit/75edf0c18c777d69df7cfc6462e5233649bd47d4.diff LOG: [NFC] [Serialization] Avoid accessing PendingBodies as much as possible The 'HaveBody' parameter in isConsumerInterestedIn is only used for the function decl if it doesn't have a body already. It should be relatively less frequent than the call to isConsumerInterestedIn. So we can delay the computing of `HaveBdoy` to make it more efficient. Added: Modified: clang/include/clang/Serialization/ASTReader.h clang/lib/Serialization/ASTReaderDecl.cpp Removed: diff --git a/clang/include/clang/Serialization/ASTReader.h b/clang/include/clang/Serialization/ASTReader.h index 5fd55a519c6b0f..e8b9f28690d9fa 100644 --- a/clang/include/clang/Serialization/ASTReader.h +++ b/clang/include/clang/Serialization/ASTReader.h @@ -1492,6 +1492,7 @@ class ASTReader getModuleFileLevelDecls(ModuleFile &Mod); private: + bool isConsumerInterestedIn(Decl *D); void PassInterestingDeclsToConsumer(); void PassInterestingDeclToConsumer(Decl *D); diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp index 78448855fba09c..9e49a3780ff418 100644 --- a/clang/lib/Serialization/ASTReaderDecl.cpp +++ b/clang/lib/Serialization/ASTReaderDecl.cpp @@ -3198,7 +3198,7 @@ inline void ASTReader::LoadedDecl(unsigned Index, Decl *D) { /// This routine should return true for anything that might affect /// code generation, e.g., inline function definitions, Objective-C /// declarations with metadata, etc. -static bool isConsumerInterestedIn(ASTContext &Ctx, Decl *D, bool HasBody) { +bool ASTReader::isConsumerInterestedIn(Decl *D) { // An ObjCMethodDecl is never considered as "interesting" because its // implementation container always is. @@ -3207,7 +3207,7 @@ static bool isConsumerInterestedIn(ASTContext &Ctx, Decl *D, bool HasBody) { if (isPartOfPerModuleInitializer(D)) { auto *M = D->getImportedOwningModule(); if (M && M->Kind == Module::ModuleMapModule && -Ctx.DeclMustBeEmitted(D)) +getContext().DeclMustBeEmitted(D)) return false; } @@ -3222,7 +3222,7 @@ static bool isConsumerInterestedIn(ASTContext &Ctx, Decl *D, bool HasBody) { (Var->isThisDeclarationADefinition() == VarDecl::Definition || OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(Var)); if (const auto *Func = dyn_cast(D)) -return Func->doesThisDeclarationHaveABody() || HasBody; +return Func->doesThisDeclarationHaveABody() || PendingBodies.count(D); if (auto *ES = D->getASTContext().getExternalSource()) if (ES->hasExternalDefinitions(D) == ExternalASTSource::EK_Never) @@ -4173,7 +4173,7 @@ void ASTReader::PassInterestingDeclsToConsumer() { while (!PotentiallyInterestingDecls.empty()) { Decl *D = PotentiallyInterestingDecls.front(); PotentiallyInterestingDecls.pop_front(); -if (isConsumerInterestedIn(getContext(), D, PendingBodies.count(D))) +if (isConsumerInterestedIn(D)) PassInterestingDeclToConsumer(D); } } @@ -4197,8 +4197,7 @@ void ASTReader::loadDeclUpdateRecords(PendingUpdateRecord &Record) { // the declaration, then we know it was interesting and we skip the call // to isConsumerInterestedIn because it is unsafe to call in the // current ASTReader state. -bool WasInteresting = -Record.JustLoaded || isConsumerInterestedIn(getContext(), D, false); +bool WasInteresting = Record.JustLoaded || isConsumerInterestedIn(D); for (auto &FileAndOffset : UpdateOffsets) { ModuleFile *F = FileAndOffset.first; uint64_t Offset = FileAndOffset.second; @@ -4230,8 +4229,7 @@ void ASTReader::loadDeclUpdateRecords(PendingUpdateRecord &Record) { // We might have made this declaration interesting. If so, remember that // we need to hand it off to the consumer. - if (!WasInteresting && - isConsumerInterestedIn(getContext(), D, PendingBodies.count(D))) { + if (!WasInteresting && isConsumerInterestedIn(D)) { PotentiallyInterestingDecls.push_back(D); WasInteresting = true; } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [lld] [llvm] [ThinLTO]Record import type in GlobalValueSummary::GVFlags (PR #87597)
https://github.com/minglotus-6 closed https://github.com/llvm/llvm-project/pull/87597 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] Look for compiler-rt from subdir given by --target (PR #88334)
MaskRay wrote: Can you provide CMake configure command and the compiler-rt file paths? I am not sure we need more changes to clangDriver. https://github.com/llvm/llvm-project/pull/88334 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [X86] Define __APX_F__ when APX is enabled. (PR #88343)
@@ -954,6 +954,8 @@ void X86TargetInfo::getTargetDefines(const LangOptions &Opts, Builder.defineMacro("__CCMP__"); if (HasCF) Builder.defineMacro("__CF__"); + if (HasEGPR && HasPush2Pop2 && HasPPX && HasNDD) FreddyLeaf wrote: 4929d88 https://github.com/llvm/llvm-project/pull/88343 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [X86] Define __APX_F__ when APX is enabled. (PR #88343)
https://github.com/FreddyLeaf updated https://github.com/llvm/llvm-project/pull/88343 >From 88e99b1f3f99140e13f7acb8e7e10162dc1694a0 Mon Sep 17 00:00:00 2001 From: Freddy Ye Date: Wed, 10 Apr 2024 16:49:05 +0800 Subject: [PATCH 1/2] [X86] Define __APX_F__ when APX is enabled. Relate gcc patch: https://gcc.gnu.org/pipermail/gcc-patches/2024-April/648789.html --- clang/lib/Basic/Targets/X86.cpp | 2 ++ clang/test/Preprocessor/x86_target_features.c | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp index 1966af17904d65..b7f98700b8731f 100644 --- a/clang/lib/Basic/Targets/X86.cpp +++ b/clang/lib/Basic/Targets/X86.cpp @@ -954,6 +954,8 @@ void X86TargetInfo::getTargetDefines(const LangOptions &Opts, Builder.defineMacro("__CCMP__"); if (HasCF) Builder.defineMacro("__CF__"); + if (HasEGPR && HasPush2Pop2 && HasPPX && HasNDD) +Builder.defineMacro("__APX_F__"); // Each case falls through to the previous one here. switch (SSELevel) { diff --git a/clang/test/Preprocessor/x86_target_features.c b/clang/test/Preprocessor/x86_target_features.c index a1882043910f76..5602c59158fe5a 100644 --- a/clang/test/Preprocessor/x86_target_features.c +++ b/clang/test/Preprocessor/x86_target_features.c @@ -803,7 +803,8 @@ // RUN: %clang -target x86_64-unknown-unknown -march=x86-64 -mapx-features=ndd -x c -E -dM -o - %s | FileCheck --check-prefix=NDD %s // RUN: %clang -target x86_64-unknown-unknown -march=x86-64 -mapx-features=ccmp -x c -E -dM -o - %s | FileCheck --check-prefix=CCMP %s // RUN: %clang -target x86_64-unknown-unknown -march=x86-64 -mapx-features=cf -x c -E -dM -o - %s | FileCheck --check-prefix=CF %s -// RUN: %clang -target x86_64-unknown-unknown -march=x86-64 -mapxf -x c -E -dM -o - %s | FileCheck --check-prefixes=EGPR,PUSH2POP2,PPX,NDD %s +// RUN: %clang -target x86_64-unknown-unknown -march=x86-64 -mapxf -x c -E -dM -o - %s | FileCheck --check-prefixes=EGPR,PUSH2POP2,PPX,NDD,APXF %s +// APXF: #define __APX_F__ 1 // CCMP: #define __CCMP__ 1 // CF: #define __CF__ 1 // EGPR: #define __EGPR__ 1 >From 4929d88cf83361a5293ac363f94d536f7df1ba29 Mon Sep 17 00:00:00 2001 From: Freddy Ye Date: Thu, 11 Apr 2024 10:29:14 +0800 Subject: [PATCH 2/2] address comments --- clang/lib/Basic/Targets/X86.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp index b7f98700b8731f..bf1767c87fe1ce 100644 --- a/clang/lib/Basic/Targets/X86.cpp +++ b/clang/lib/Basic/Targets/X86.cpp @@ -954,6 +954,7 @@ void X86TargetInfo::getTargetDefines(const LangOptions &Opts, Builder.defineMacro("__CCMP__"); if (HasCF) Builder.defineMacro("__CF__"); + // Condition here is aligned with the feature set of mapxf in Options.td if (HasEGPR && HasPush2Pop2 && HasPPX && HasNDD) Builder.defineMacro("__APX_F__"); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Simplify RenamerClangTidyCheck API (PR #88268)
https://github.com/HerrCai0907 approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/88268 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] Look for compiler-rt from subdir given by --target (PR #88334)
https://github.com/wzssyqa converted_to_draft https://github.com/llvm/llvm-project/pull/88334 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [X86] Define __APX_F__ when APX is enabled. (PR #88343)
https://github.com/KanRobert approved this pull request. LGTM with a suggestion https://github.com/llvm/llvm-project/pull/88343 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [X86] Define __APX_F__ when APX is enabled. (PR #88343)
@@ -954,6 +954,8 @@ void X86TargetInfo::getTargetDefines(const LangOptions &Opts, Builder.defineMacro("__CCMP__"); if (HasCF) Builder.defineMacro("__CF__"); + if (HasEGPR && HasPush2Pop2 && HasPPX && HasNDD) KanRobert wrote: Add comment `Condition here is aligned with the feature set of mapxf in Options.td` https://github.com/llvm/llvm-project/pull/88343 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [X86] Define __APX_F__ when APX is enabled. (PR #88343)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Freddy Ye (FreddyLeaf) Changes Relate gcc patch: https://gcc.gnu.org/pipermail/gcc-patches/2024-April/648789.html --- Full diff: https://github.com/llvm/llvm-project/pull/88343.diff 2 Files Affected: - (modified) clang/lib/Basic/Targets/X86.cpp (+2) - (modified) clang/test/Preprocessor/x86_target_features.c (+2-1) ``diff diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp index 1966af17904d65..b7f98700b8731f 100644 --- a/clang/lib/Basic/Targets/X86.cpp +++ b/clang/lib/Basic/Targets/X86.cpp @@ -954,6 +954,8 @@ void X86TargetInfo::getTargetDefines(const LangOptions &Opts, Builder.defineMacro("__CCMP__"); if (HasCF) Builder.defineMacro("__CF__"); + if (HasEGPR && HasPush2Pop2 && HasPPX && HasNDD) +Builder.defineMacro("__APX_F__"); // Each case falls through to the previous one here. switch (SSELevel) { diff --git a/clang/test/Preprocessor/x86_target_features.c b/clang/test/Preprocessor/x86_target_features.c index a1882043910f76..5602c59158fe5a 100644 --- a/clang/test/Preprocessor/x86_target_features.c +++ b/clang/test/Preprocessor/x86_target_features.c @@ -803,7 +803,8 @@ // RUN: %clang -target x86_64-unknown-unknown -march=x86-64 -mapx-features=ndd -x c -E -dM -o - %s | FileCheck --check-prefix=NDD %s // RUN: %clang -target x86_64-unknown-unknown -march=x86-64 -mapx-features=ccmp -x c -E -dM -o - %s | FileCheck --check-prefix=CCMP %s // RUN: %clang -target x86_64-unknown-unknown -march=x86-64 -mapx-features=cf -x c -E -dM -o - %s | FileCheck --check-prefix=CF %s -// RUN: %clang -target x86_64-unknown-unknown -march=x86-64 -mapxf -x c -E -dM -o - %s | FileCheck --check-prefixes=EGPR,PUSH2POP2,PPX,NDD %s +// RUN: %clang -target x86_64-unknown-unknown -march=x86-64 -mapxf -x c -E -dM -o - %s | FileCheck --check-prefixes=EGPR,PUSH2POP2,PPX,NDD,APXF %s +// APXF: #define __APX_F__ 1 // CCMP: #define __CCMP__ 1 // CF: #define __CF__ 1 // EGPR: #define __EGPR__ 1 `` https://github.com/llvm/llvm-project/pull/88343 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [X86] Define __APX_F__ when APX is enabled. (PR #88343)
https://github.com/FreddyLeaf created https://github.com/llvm/llvm-project/pull/88343 Relate gcc patch: https://gcc.gnu.org/pipermail/gcc-patches/2024-April/648789.html >From 88e99b1f3f99140e13f7acb8e7e10162dc1694a0 Mon Sep 17 00:00:00 2001 From: Freddy Ye Date: Wed, 10 Apr 2024 16:49:05 +0800 Subject: [PATCH] [X86] Define __APX_F__ when APX is enabled. Relate gcc patch: https://gcc.gnu.org/pipermail/gcc-patches/2024-April/648789.html --- clang/lib/Basic/Targets/X86.cpp | 2 ++ clang/test/Preprocessor/x86_target_features.c | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp index 1966af17904d65..b7f98700b8731f 100644 --- a/clang/lib/Basic/Targets/X86.cpp +++ b/clang/lib/Basic/Targets/X86.cpp @@ -954,6 +954,8 @@ void X86TargetInfo::getTargetDefines(const LangOptions &Opts, Builder.defineMacro("__CCMP__"); if (HasCF) Builder.defineMacro("__CF__"); + if (HasEGPR && HasPush2Pop2 && HasPPX && HasNDD) +Builder.defineMacro("__APX_F__"); // Each case falls through to the previous one here. switch (SSELevel) { diff --git a/clang/test/Preprocessor/x86_target_features.c b/clang/test/Preprocessor/x86_target_features.c index a1882043910f76..5602c59158fe5a 100644 --- a/clang/test/Preprocessor/x86_target_features.c +++ b/clang/test/Preprocessor/x86_target_features.c @@ -803,7 +803,8 @@ // RUN: %clang -target x86_64-unknown-unknown -march=x86-64 -mapx-features=ndd -x c -E -dM -o - %s | FileCheck --check-prefix=NDD %s // RUN: %clang -target x86_64-unknown-unknown -march=x86-64 -mapx-features=ccmp -x c -E -dM -o - %s | FileCheck --check-prefix=CCMP %s // RUN: %clang -target x86_64-unknown-unknown -march=x86-64 -mapx-features=cf -x c -E -dM -o - %s | FileCheck --check-prefix=CF %s -// RUN: %clang -target x86_64-unknown-unknown -march=x86-64 -mapxf -x c -E -dM -o - %s | FileCheck --check-prefixes=EGPR,PUSH2POP2,PPX,NDD %s +// RUN: %clang -target x86_64-unknown-unknown -march=x86-64 -mapxf -x c -E -dM -o - %s | FileCheck --check-prefixes=EGPR,PUSH2POP2,PPX,NDD,APXF %s +// APXF: #define __APX_F__ 1 // CCMP: #define __CCMP__ 1 // CF: #define __CF__ 1 // EGPR: #define __EGPR__ 1 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Don't merge a short block for SBS_Never (PR #88238)
https://github.com/owenca closed https://github.com/llvm/llvm-project/pull/88238 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 51f1681 - [clang-format] Don't merge a short block for SBS_Never (#88238)
Author: Owen Pan Date: 2024-04-10T19:06:29-07:00 New Revision: 51f1681424f1a8ccf1e3432d71c341e799597171 URL: https://github.com/llvm/llvm-project/commit/51f1681424f1a8ccf1e3432d71c341e799597171 DIFF: https://github.com/llvm/llvm-project/commit/51f1681424f1a8ccf1e3432d71c341e799597171.diff LOG: [clang-format] Don't merge a short block for SBS_Never (#88238) Also fix unit tests. Fixes #87484. Added: Modified: clang/lib/Format/FormatToken.h clang/lib/Format/UnwrappedLineFormatter.cpp clang/lib/Format/UnwrappedLineParser.cpp clang/unittests/Format/BracesRemoverTest.cpp clang/unittests/Format/FormatTest.cpp clang/unittests/Format/FormatTestMacroExpansion.cpp clang/unittests/Format/TokenAnnotatorTest.cpp Removed: diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h index 48b6a9092a8c09..f651e6228c206d 100644 --- a/clang/lib/Format/FormatToken.h +++ b/clang/lib/Format/FormatToken.h @@ -35,6 +35,8 @@ namespace format { TYPE(BinaryOperator) \ TYPE(BitFieldColon) \ TYPE(BlockComment) \ + /* l_brace of a block that is not the body of a (e.g. loop) statement. */ \ + TYPE(BlockLBrace) \ TYPE(BracedListLBrace) \ /* The colon at the end of a case label. */ \ TYPE(CaseLabelColon) \ diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp index fb31980ab9f491..4ae54e56331bdc 100644 --- a/clang/lib/Format/UnwrappedLineFormatter.cpp +++ b/clang/lib/Format/UnwrappedLineFormatter.cpp @@ -796,8 +796,12 @@ class LineJoiner { } } -if (const auto *LastNonComment = Line.getLastNonComment(); -LastNonComment && LastNonComment->is(tok::l_brace)) { +if (Line.endsWith(tok::l_brace)) { + if (Style.AllowShortBlocksOnASingleLine == FormatStyle::SBS_Never && + Line.First->is(TT_BlockLBrace)) { +return 0; + } + if (IsSplitBlock && Line.First == Line.Last && I > AnnotatedLines.begin() && (I[-1]->endsWith(tok::kw_else) || IsCtrlStmt(*I[-1]))) { diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index c1f7e2874beb24..603268f771ac52 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -395,9 +395,10 @@ bool UnwrappedLineParser::parseLevel(const FormatToken *OpeningBrace, ParseDefault(); continue; } - if (!InRequiresExpression && FormatTok->isNot(TT_MacroBlockBegin) && - tryToParseBracedList()) { -continue; + if (!InRequiresExpression && FormatTok->isNot(TT_MacroBlockBegin)) { +if (tryToParseBracedList()) + continue; +FormatTok->setFinalizedType(TT_BlockLBrace); } parseBlock(); ++StatementCount; diff --git a/clang/unittests/Format/BracesRemoverTest.cpp b/clang/unittests/Format/BracesRemoverTest.cpp index 5155eefb9e08c9..2e983b887ffcb2 100644 --- a/clang/unittests/Format/BracesRemoverTest.cpp +++ b/clang/unittests/Format/BracesRemoverTest.cpp @@ -209,7 +209,9 @@ TEST_F(BracesRemoverTest, RemoveBraces) { verifyFormat("if (a) {\n" " b;\n" "} else {\n" - " { c; }\n" + " {\n" + "c;\n" + " }\n" "}", Style); diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index f312a9e21158a9..4906b3350b5b22 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -52,7 +52,13 @@ TEST_F(FormatTest, FormatsUnwrappedLinesAtFirstFormat) { } TEST_F(FormatTest, FormatsNestedBlockStatements) { - verifyFormat("{\n {\n{}\n }\n}", "{{{}}}"); + verifyFormat("{\n" + " {\n" + "{\n" + "}\n" + " }\n" + "}", + "{{{}}}"); } TEST_F(FormatTest, FormatsNestedCall) { @@ -5669,7 +5675,10 @@ TEST_F(FormatTest, LayoutCodeInMacroDefinitions) { getLLVMStyleWithColumns(14)); } -TEST_F(FormatTest, LayoutRemainingTokens) { verifyFormat("{}"); } +TEST_F(FormatTest, LayoutRemainingTokens) { + verifyFormat("{\n" + "}"); +} TEST_F(FormatTest, MacroDefinitionInsideStatement) { verifyFormat("int x,\n" @@ -6577,7 +6586,11 @@ TEST_F(FormatTest, FormatAlignInsidePreprocessorElseBlock) { } TEST_F(FormatTest, FormatHashIfNotAtStartOfLine) { - verifyFormat("
[clang] [Modules] No transitive source location change (PR #86912)
ChuanqiXu9 wrote: > Could you share the rest of the "no transitive change" patches, or at least > their outline? I'm curious what else goes into making that work. Oh, I haven't started them. The patch in my mind includes two at least: (1) Add a new block recording the semantical hash value of the current named module. (2) A similar patch for DeclID to refactor the existing linear offset to {ModuleFileIndex, LocalDeclID} patch. BTW, with (2), maybe we can refactor the existing super large vector of Decls, `DeclsLoaded`, in the ASTReader into a array of vectors or into a map. But this may not be included in the series of the patches. The motivation for (1) is that: ``` export module a; export import b; ... ``` We want the BMI of `a` to change all the time if `b` changes. Also for the motivation example, if we changed the definition of `funcB` into `inline`, ``` //--- A.cppm export module A; export inline int funcA() { return 43; } //--- B.cppm export module B; import A; export inline int funcB() { return funcA(); } ``` We hope the BMI of module B will change after the function A changes. But the declaration level hash may be tricky, so probably we need to change the BMI of the module B after the module A changes as the initial step. So the result may be, we need to add a new hash or signature value to the BMI for named modules: ``` signature = hash_combine(hash value of the current buffer, combined hash value of the signature export imported modules, combined hash value of touched non-export import modules) ``` (Maybe we need to do this for all module types) Maybe we can reuse the existing ASTSignature or we need to add a new block. But I am sure about this point now. https://github.com/llvm/llvm-project/pull/86912 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Implement resource binding type prefix mismatch errors (PR #87578)
https://github.com/bob80905 updated https://github.com/llvm/llvm-project/pull/87578 >From 3960050439964fe3c0536696490b284a6c470cd1 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Wed, 3 Apr 2024 13:15:59 -0700 Subject: [PATCH 1/4] implement binding type error for t/cbuffers and rwbuffers --- .../clang/Basic/DiagnosticSemaKinds.td| 1 + clang/lib/Sema/HLSLExternalSemaSource.cpp | 19 +++-- clang/lib/Sema/SemaDeclAttr.cpp | 73 ++- .../resource_binding_attr_error_mismatch.hlsl | 65 + 4 files changed, 149 insertions(+), 9 deletions(-) create mode 100644 clang/test/SemaHLSL/resource_binding_attr_error_mismatch.hlsl diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 51af81bf1f6fc5..9a0946276f80fb 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -12149,6 +12149,7 @@ def err_hlsl_missing_semantic_annotation : Error< def err_hlsl_init_priority_unsupported : Error< "initializer priorities are not supported in HLSL">; +def err_hlsl_mismatching_register_type_and_name: Error<"invalid register name prefix '%0' for register type '%1' (expected '%2')">; def err_hlsl_unsupported_register_type : Error<"invalid resource class specifier '%0' used; expected 'b', 's', 't', or 'u'">; def err_hlsl_unsupported_register_number : Error<"register number should be an integer">; def err_hlsl_expected_space : Error<"invalid space specifier '%0' used; expected 'space' followed by an integer, like space1">; diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp b/clang/lib/Sema/HLSLExternalSemaSource.cpp index 1a1febf7a35241..479689ec82dcee 100644 --- a/clang/lib/Sema/HLSLExternalSemaSource.cpp +++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp @@ -119,8 +119,10 @@ struct BuiltinTypeDeclBuilder { ResourceKind RK, bool IsROV) { if (Record->isCompleteDefinition()) return *this; -Record->addAttr(HLSLResourceAttr::CreateImplicit(Record->getASTContext(), - RC, RK, IsROV)); +HLSLResourceAttr *attr = HLSLResourceAttr::CreateImplicit( +Record->getASTContext(), RC, RK, IsROV); + +Record->addAttr(attr); return *this; } @@ -482,15 +484,18 @@ static BuiltinTypeDeclBuilder setupBufferType(CXXRecordDecl *Decl, Sema &S, bool IsROV) { return BuiltinTypeDeclBuilder(Decl) .addHandleMember() - .addDefaultHandleConstructor(S, RC) - .annotateResourceClass(RC, RK, IsROV); + .addDefaultHandleConstructor(S, RC); } void HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() { CXXRecordDecl *Decl; - Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "RWBuffer") - .addSimpleTemplateParams({"element_type"}) - .Record; + Decl = + BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "RWBuffer") + .addSimpleTemplateParams({"element_type"}) + .annotateResourceClass(ResourceClass::UAV, ResourceKind::TypedBuffer, + /*IsROV=*/false) + .Record; + onCompletion(Decl, [this](CXXRecordDecl *Decl) { setupBufferType(Decl, *SemaPtr, ResourceClass::UAV, ResourceKind::TypedBuffer, /*IsROV=*/false) diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index f25f3afd0f4af2..e720fe56c3ea17 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -7333,12 +7333,12 @@ static void handleHLSLResourceBindingAttr(Sema &S, Decl *D, } else { Slot = Str; } - + QualType Ty = ((clang::ValueDecl *)D)->getType(); // Validate. if (!Slot.empty()) { switch (Slot[0]) { -case 'u': case 'b': +case 'u': case 's': case 't': break; @@ -7367,6 +7367,75 @@ static void handleHLSLResourceBindingAttr(Sema &S, Decl *D, return; } + VarDecl *VD = dyn_cast(D); + HLSLBufferDecl *BD = dyn_cast(D); + + if (VD || BD) { +llvm::hlsl::ResourceClass RC; +std::string varTy = ""; +if (VD) { + + const Type *Ty = VD->getType()->getPointeeOrArrayElementType(); + if (!Ty) +return; + QualType t = ((ElaboratedType *)Ty)->getNamedType(); + const CXXRecordDecl *RD = Ty->getAsCXXRecordDecl(); + if (!RD) +return; + + if (auto TDecl = dyn_cast(RD)) +RD = TDecl->getSpecializedTemplate()->getTemplatedDecl(); + RD = RD->getCanonicalDecl(); + const auto *Attr = RD->getAttr(); + if (!Attr) +return; + + RC = Attr->getResourceClass(); + varTy = RD->getNameAsString(); +} else { + if (BD->isCBuffer()) { +RC = llvm::hlsl::ResourceClass::CBuffer; +varTy = "cbuffer"; + } else { +RC = llvm::hlsl::ResourceClass::CBuffer; +v
[clang] [llvm] [InstCombine] Add canonicalization of `sitofp` -> `uitofp nneg` (PR #88299)
nikic wrote: Can the implementation of foldFBinOpOfIntCastsFromSign be simplified to use nneg instead of KnownBits after this change? https://github.com/llvm/llvm-project/pull/88299 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [InstCombine] Add canonicalization of `sitofp` -> `uitofp nneg` (PR #88299)
https://github.com/nikic approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/88299 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Implement resource binding type prefix mismatch errors (PR #87578)
@@ -119,8 +119,10 @@ struct BuiltinTypeDeclBuilder { ResourceKind RK, bool IsROV) { if (Record->isCompleteDefinition()) return *this; -Record->addAttr(HLSLResourceAttr::CreateImplicit(Record->getASTContext(), - RC, RK, IsROV)); +HLSLResourceAttr *attr = HLSLResourceAttr::CreateImplicit( +Record->getASTContext(), RC, RK, IsROV); + +Record->addAttr(attr); bob80905 wrote: Correct, just a result of some debugging, I'll revert it. https://github.com/llvm/llvm-project/pull/87578 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] Look for compiler-rt from subdir given by --target (PR #88334)
llvmbot wrote: @llvm/pr-subscribers-clang-driver Author: YunQiang Su (wzssyqa) Changes Currently, clang looks for compiler-rt only from the normalized triple subdir. While if we are configured with a non-normalized triple with -DLLVM_DEFAULT_TARGET_TRIPLE, such as triples without vendor section, clang will fail to find compiler_rt. Let's look for compiler_rt from the subdir with name from --target option, too. To archive this, we add a new member called Origin to class Triple. Fixes: #87150. --- Full diff: https://github.com/llvm/llvm-project/pull/88334.diff 4 Files Affected: - (modified) clang/lib/Driver/Driver.cpp (+1) - (modified) clang/lib/Driver/ToolChain.cpp (+6) - (modified) llvm/include/llvm/TargetParser/Triple.h (+6) - (modified) llvm/lib/TargetParser/Triple.cpp (+3-3) ``diff diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index e7335a61b10c53..4a0c939039eb31 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -516,6 +516,7 @@ static llvm::Triple computeTargetTriple(const Driver &D, TargetTriple = A->getValue(); llvm::Triple Target(llvm::Triple::normalize(TargetTriple)); + Target.setOrigin(TargetTriple); // GNU/Hurd's triples should have been -hurd-gnu*, but were historically made // -gnu* only, and we can not change this, so we have to detect that case as diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp index 237092ed07e5dc..57f27a61c4060b 100644 --- a/clang/lib/Driver/ToolChain.cpp +++ b/clang/lib/Driver/ToolChain.cpp @@ -755,6 +755,12 @@ std::optional ToolChain::getTargetSubDirPath(StringRef BaseDir) const { auto getPathForTriple = [&](const llvm::Triple &Triple) -> std::optional { +if (!Triple.getOrigin().empty()) { + SmallString<128> Po(BaseDir); + llvm::sys::path::append(Po, Triple.getOrigin()); + if (getVFS().exists(Po)) +return std::string(Po); +} SmallString<128> P(BaseDir); llvm::sys::path::append(P, Triple.str()); if (getVFS().exists(P)) diff --git a/llvm/include/llvm/TargetParser/Triple.h b/llvm/include/llvm/TargetParser/Triple.h index f256e2b205a889..a2fc28ada0ca31 100644 --- a/llvm/include/llvm/TargetParser/Triple.h +++ b/llvm/include/llvm/TargetParser/Triple.h @@ -298,6 +298,8 @@ class Triple { private: std::string Data; + StringRef Origin = StringRef(); + /// The parsed arch type. ArchType Arch{}; @@ -425,6 +427,8 @@ class Triple { const std::string &getTriple() const { return Data; } + const StringRef getOrigin() const { return Origin; } + /// Get the architecture (first) component of the triple. StringRef getArchName() const; @@ -1058,6 +1062,8 @@ class Triple { /// @name Mutators /// @{ + void setOrigin(StringRef Orig) { Origin = Orig; }; + /// Set the architecture (first) component of the triple to a known type. void setArch(ArchType Kind, SubArchType SubArch = NoSubArch); diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp index 624679ff507a7f..ce44903d0f7d70 100644 --- a/llvm/lib/TargetParser/Triple.cpp +++ b/llvm/lib/TargetParser/Triple.cpp @@ -928,9 +928,9 @@ static Triple::ObjectFormatType getDefaultFormat(const Triple &T) { /// This stores the string representation and parses the various pieces into /// enum members. Triple::Triple(const Twine &Str) -: Data(Str.str()), Arch(UnknownArch), SubArch(NoSubArch), - Vendor(UnknownVendor), OS(UnknownOS), Environment(UnknownEnvironment), - ObjectFormat(UnknownObjectFormat) { +: Data(Str.str()), Origin(Str.getSingleStringRef()), Arch(UnknownArch), + SubArch(NoSubArch), Vendor(UnknownVendor), OS(UnknownOS), + Environment(UnknownEnvironment), ObjectFormat(UnknownObjectFormat) { // Do minimal parsing by hand here. SmallVector Components; StringRef(Data).split(Components, '-', /*MaxSplit*/ 3); `` https://github.com/llvm/llvm-project/pull/88334 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] Look for compiler-rt from subdir given by --target (PR #88334)
https://github.com/wzssyqa created https://github.com/llvm/llvm-project/pull/88334 Currently, clang looks for compiler-rt only from the normalized triple subdir. While if we are configured with a non-normalized triple with -DLLVM_DEFAULT_TARGET_TRIPLE, such as triples without vendor section, clang will fail to find compiler_rt. Let's look for compiler_rt from the subdir with name from --target option, too. To archive this, we add a new member called Origin to class Triple. Fixes: #87150. >From a4d6590cf3cecf90b3914933313749e8aad03210 Mon Sep 17 00:00:00 2001 From: YunQiang Su Date: Mon, 1 Apr 2024 17:17:08 +0800 Subject: [PATCH] Look for compiler-rt from subdir given by --target Currently, clang looks for compiler-rt only from the normalized triple subdir. While if we are configured with a non-normalized triple with -DLLVM_DEFAULT_TARGET_TRIPLE, such as triples without vendor section, clang will fail to find compiler_rt. Let's look for compiler_rt from the subdir with name from --target option. To archive this, we add a new member called Origin to class Triple. Fixes: #87150. --- clang/lib/Driver/Driver.cpp | 1 + clang/lib/Driver/ToolChain.cpp | 6 ++ llvm/include/llvm/TargetParser/Triple.h | 6 ++ llvm/lib/TargetParser/Triple.cpp| 6 +++--- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index e7335a61b10c53..4a0c939039eb31 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -516,6 +516,7 @@ static llvm::Triple computeTargetTriple(const Driver &D, TargetTriple = A->getValue(); llvm::Triple Target(llvm::Triple::normalize(TargetTriple)); + Target.setOrigin(TargetTriple); // GNU/Hurd's triples should have been -hurd-gnu*, but were historically made // -gnu* only, and we can not change this, so we have to detect that case as diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp index 237092ed07e5dc..57f27a61c4060b 100644 --- a/clang/lib/Driver/ToolChain.cpp +++ b/clang/lib/Driver/ToolChain.cpp @@ -755,6 +755,12 @@ std::optional ToolChain::getTargetSubDirPath(StringRef BaseDir) const { auto getPathForTriple = [&](const llvm::Triple &Triple) -> std::optional { +if (!Triple.getOrigin().empty()) { + SmallString<128> Po(BaseDir); + llvm::sys::path::append(Po, Triple.getOrigin()); + if (getVFS().exists(Po)) +return std::string(Po); +} SmallString<128> P(BaseDir); llvm::sys::path::append(P, Triple.str()); if (getVFS().exists(P)) diff --git a/llvm/include/llvm/TargetParser/Triple.h b/llvm/include/llvm/TargetParser/Triple.h index f256e2b205a889..a2fc28ada0ca31 100644 --- a/llvm/include/llvm/TargetParser/Triple.h +++ b/llvm/include/llvm/TargetParser/Triple.h @@ -298,6 +298,8 @@ class Triple { private: std::string Data; + StringRef Origin = StringRef(); + /// The parsed arch type. ArchType Arch{}; @@ -425,6 +427,8 @@ class Triple { const std::string &getTriple() const { return Data; } + const StringRef getOrigin() const { return Origin; } + /// Get the architecture (first) component of the triple. StringRef getArchName() const; @@ -1058,6 +1062,8 @@ class Triple { /// @name Mutators /// @{ + void setOrigin(StringRef Orig) { Origin = Orig; }; + /// Set the architecture (first) component of the triple to a known type. void setArch(ArchType Kind, SubArchType SubArch = NoSubArch); diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp index 624679ff507a7f..ce44903d0f7d70 100644 --- a/llvm/lib/TargetParser/Triple.cpp +++ b/llvm/lib/TargetParser/Triple.cpp @@ -928,9 +928,9 @@ static Triple::ObjectFormatType getDefaultFormat(const Triple &T) { /// This stores the string representation and parses the various pieces into /// enum members. Triple::Triple(const Twine &Str) -: Data(Str.str()), Arch(UnknownArch), SubArch(NoSubArch), - Vendor(UnknownVendor), OS(UnknownOS), Environment(UnknownEnvironment), - ObjectFormat(UnknownObjectFormat) { +: Data(Str.str()), Origin(Str.getSingleStringRef()), Arch(UnknownArch), + SubArch(NoSubArch), Vendor(UnknownVendor), OS(UnknownOS), + Environment(UnknownEnvironment), ObjectFormat(UnknownObjectFormat) { // Do minimal parsing by hand here. SmallVector Components; StringRef(Data).split(Components, '-', /*MaxSplit*/ 3); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [lldb] [NFC][Clang] Improve const correctness for IdentifierInfo (PR #79365)
https://github.com/bwendling closed https://github.com/llvm/llvm-project/pull/79365 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] New calling convention preserve_none (PR #76868)
brandtbucher wrote: Draft PR at https://github.com/llvm/llvm-project/pull/88333. https://github.com/llvm/llvm-project/pull/76868 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [BoundsSafety] WIP: Make 'counted_by' work for pointer fields; late parsing for 'counted_by' on decl attr position (PR #87596)
@@ -1599,6 +1599,13 @@ defm double_square_bracket_attributes : BoolFOption<"double-square-bracket-attri LangOpts<"DoubleSquareBracketAttributes">, DefaultTrue, PosFlag, NegFlag>; +defm experimental_late_parse_attributes : BoolFOption<"experimental-late-parse-attributes", delcypher wrote: @rapidsna FYI. Here's a sketch of an experimental late parsing flag. It's not quite done yet and I think it's big enough that it deserves it's own PR. Just pushing it here to give you an idea of my plans https://github.com/llvm/llvm-project/pull/87596 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [BoundsSafety] WIP: Make 'counted_by' work for pointer fields; late parsing for 'counted_by' on decl attr position (PR #87596)
https://github.com/delcypher updated https://github.com/llvm/llvm-project/pull/87596 >From af735f3216dd5db9dcaf164892f3f573731701ec Mon Sep 17 00:00:00 2001 From: Yeoul Na Date: Wed, 3 Apr 2024 20:58:46 -0700 Subject: [PATCH 1/2] [BoundsSafety] WIP: Make 'counted_by' work for pointer fields; late parsing for 'counted_by' on decl attr position --- clang/include/clang/Basic/Attr.td | 3 +- clang/include/clang/Parse/Parser.h| 11 +- clang/include/clang/Sema/Sema.h | 2 +- clang/lib/Parse/ParseDecl.cpp | 108 -- clang/lib/Parse/ParseObjc.cpp | 6 +- clang/lib/Sema/SemaDeclAttr.cpp | 11 +- clang/lib/Sema/SemaType.cpp | 6 +- clang/lib/Sema/TreeTransform.h| 2 +- clang/test/AST/attr-counted-by-late-parsed.c | 29 + clang/test/Sema/attr-counted-by-late-parsed.c | 54 + clang/test/Sema/attr-counted-by.c | 2 +- 11 files changed, 212 insertions(+), 22 deletions(-) create mode 100644 clang/test/AST/attr-counted-by-late-parsed.c create mode 100644 clang/test/Sema/attr-counted-by-late-parsed.c diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 6584460cf5685e..d6caa28938edef 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -2197,7 +2197,8 @@ def TypeNullUnspecified : TypeAttr { def CountedBy : DeclOrTypeAttr { let Spellings = [Clang<"counted_by">]; let Subjects = SubjectList<[Field], ErrorDiag>; - let Args = [ExprArgument<"Count">, IntArgument<"NestedLevel">]; + let Args = [ExprArgument<"Count">, IntArgument<"NestedLevel", 1>]; + let LateParsed = 1; let ParseArgumentsAsUnevaluated = 1; let Documentation = [CountedByDocs]; let LangOpts = [COnly]; diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h index 580bf2a5d79df5..41fc5d5dc98a6b 100644 --- a/clang/include/clang/Parse/Parser.h +++ b/clang/include/clang/Parse/Parser.h @@ -1606,6 +1606,10 @@ class Parser : public CodeCompletionHandler { bool EnterScope, bool OnDefinition); void ParseLexedAttribute(LateParsedAttribute &LA, bool EnterScope, bool OnDefinition); + void ParseLexedCAttributeList(LateParsedAttrList &LA, bool EnterScope, +ParsedAttributes *OutAttrs = nullptr); + void ParseLexedCAttribute(LateParsedAttribute &LA, bool EnterScope, +ParsedAttributes *OutAttrs = nullptr); void ParseLexedMethodDeclarations(ParsingClass &Class); void ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM); void ParseLexedMethodDefs(ParsingClass &Class); @@ -2497,7 +2501,9 @@ class Parser : public CodeCompletionHandler { void ParseStructDeclaration( ParsingDeclSpec &DS, - llvm::function_ref FieldsCallback); + llvm::function_ref + FieldsCallback, + LateParsedAttrList *LateFieldAttrs = nullptr); DeclGroupPtrTy ParseTopLevelStmtDecl(); @@ -3074,6 +3080,9 @@ class Parser : public CodeCompletionHandler { SourceLocation ScopeLoc, ParsedAttr::Form Form); + void DistributeCLateParsedAttrs(Declarator &D, Decl *Dcl, + LateParsedAttrList *LateAttrs); + void ParseBoundsAttribute(IdentifierInfo &AttrName, SourceLocation AttrNameLoc, ParsedAttributes &Attrs, IdentifierInfo *ScopeName, SourceLocation ScopeLoc, diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 8c98d8c7fef7a7..de49f2344f017f 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -11761,7 +11761,7 @@ class Sema final { QualType BuildMatrixType(QualType T, Expr *NumRows, Expr *NumColumns, SourceLocation AttrLoc); - QualType BuildCountAttributedArrayType(QualType WrappedTy, Expr *CountExpr); + QualType BuildCountAttributedArrayOrPointerType(QualType WrappedTy, Expr *CountExpr); QualType BuildAddressSpaceAttr(QualType &T, LangAS ASIdx, Expr *AddrSpace, SourceLocation AttrLoc); diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index 0aa14b0510746b..1c2e6d447cf5d5 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -3254,6 +3254,17 @@ void Parser::ParseAlignmentSpecifier(ParsedAttributes &Attrs, } } +void Parser::DistributeCLateParsedAttrs(Declarator &D, Decl *Dcl, +LateParsedAttrList *LateAttrs) { + if (!LateAttrs) +return; + + for (auto *LateAttr : *LateAttrs) { +if (LateAttr->Decls.empty()) + LateAttr->addDecl(Dcl); + } +} + /// Bounds attributes (e.g., counted_by): /// AttrName '(' expression ')' void Parser::ParseBoundsA
[clang] nonblocking/nonallocating attributes (was: nolock/noalloc) (PR #84983)
@@ -4429,6 +4433,218 @@ class FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode { } }; +// -- + +// TODO: Should FunctionEffect be located elsewhere, where Decl is not +// forward-declared? +class Decl; +class CXXMethodDecl; +class FunctionEffectSet; +class TypeSourceInfo; + +/// Represents an abstract function effect. +class FunctionEffect { +public: + /// Identifies the particular type of effect. + enum class Type { +None = 0, +NonBlocking, +NonAllocating, + }; + + /// Flags describing behaviors of the effect. + // (Why not a struct with bitfields? There's one function that would like to + // test a caller-specified bit. There are some potential optimizations that + // would OR together the bits of multiple effects.) + using Flags = unsigned; + enum FlagBit : unsigned { +// Can verification inspect callees' implementations? (e.g. nonblocking: +// yes, tcb+types: no) +FE_InferrableOnCallees = 0x1, + +// Language constructs which effects can diagnose as disallowed. +FE_ExcludeThrow = 0x2, +FE_ExcludeCatch = 0x4, +FE_ExcludeObjCMessageSend = 0x8, +FE_ExcludeStaticLocalVars = 0x10, +FE_ExcludeThreadLocalVars = 0x20 + }; + + /// Describes the result of effects differing between a base class's virtual + /// method and an overriding method in a subclass. + enum class OverrideResult { +Ignore, +Warn, +Propagate // Base method's effects are merged with those of the override. + }; + +private: + // For uniqueness, currently only Type_ is significant. + + LLVM_PREFERRED_TYPE(Type) + unsigned Type_ : 2; + Flags Flags_ : 8; // A constant function of Type but cached here. + + // Expansion: for hypothetical TCB+types, there could be one Type for TCB, + // then ~16(?) bits "Subtype" to map to a specific named TCB. Subtype would + // be considered for uniqueness. + + // Since this struct is serialized as if it were a uint32_t, it's important + // to pad and explicitly zero the extra bits. + [[maybe_unused]] unsigned Padding : 22; + +public: + using CalleeDeclOrType = + llvm::PointerUnion; + + FunctionEffect() : Type_(unsigned(Type::None)), Flags_(0), Padding(0) {} + + explicit FunctionEffect(Type T); + + /// The type of the effect. + Type type() const { return Type(Type_); } + + /// Flags describing behaviors of the effect. + Flags flags() const { return Flags_; } + + /// The description printed in diagnostics, e.g. 'nonblocking'. + StringRef name() const; + + /// A hashable representation. + uint32_t opaqueRepr() const { return Type_ | (Flags_ << 2u); } + + /// Return true if adding or removing the effect as part of a type conversion + /// should generate a diagnostic. + bool diagnoseConversion(bool Adding, QualType OldType, + FunctionEffectSet OldFX, QualType NewType, + FunctionEffectSet NewFX) const; Sirraide wrote: That is probably what I’d do, yeah. https://github.com/llvm/llvm-project/pull/84983 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang][deps] Overload `Filesystem::exists` in `DependencyScanningFilesystem` to have it use cached `status` (PR #88152)
@@ -0,0 +1,51 @@ +//===- DependencyScanningFilesystemTest.cpp ---===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h" +#include "llvm/ADT/Twine.h" +#include "llvm/Support/VirtualFileSystem.h" +#include "gtest/gtest.h" + +using namespace clang::tooling::dependencies; + +namespace { + struct InstrumentingFilesystem + : llvm::RTTIExtends { + unsigned NumStatCalls = 0; + + using llvm::RTTIExtends::RTTIExtends; + + llvm::ErrorOr status(const llvm::Twine &Path) override { + ++NumStatCalls; + return ProxyFileSystem::status(Path); + } + }; + } // namespace + + +TEST(DependencyScanningFilesystem, CacheStatOnExists) { + auto InMemoryFS = llvm::makeIntrusiveRefCnt(); + InMemoryFS->setCurrentWorkingDirectory("/"); + InMemoryFS->addFile("/foo", 0, llvm::MemoryBuffer::getMemBuffer("")); + InMemoryFS->addFile("/bar", 0, llvm::MemoryBuffer::getMemBuffer("")); + + auto InstrumentingFS = +llvm::makeIntrusiveRefCnt(InMemoryFS); + DependencyScanningFilesystemSharedCache SharedCache; + DependencyScanningWorkerFilesystem DepFS(SharedCache, InstrumentingFS); + + DepFS.status("/foo"); + DepFS.status("/foo"); + DepFS.status("/bar"); + EXPECT_EQ(InstrumentingFS->NumStatCalls, 2u); + + DepFS.exists("/foo"); + DepFS.exists("/bar"); + EXPECT_EQ(InstrumentingFS->NumStatCalls, 2u); jansvoboda11 wrote: Wait, doesn't this test pass even prior to this patch? https://github.com/llvm/llvm-project/pull/88152 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang][deps] Overload `Filesystem::exists` in `DependencyScanningFilesystem` to have it use cached `status` (PR #88152)
https://github.com/jansvoboda11 requested changes to this pull request. https://github.com/llvm/llvm-project/pull/88152 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang][deps] Overload `Filesystem::exists` in `DependencyScanningFilesystem` to have it use cached `status` (PR #88152)
https://github.com/jansvoboda11 edited https://github.com/llvm/llvm-project/pull/88152 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] be10070 - Revert "[Driver] Ensure ToolChain::LibraryPaths is not empty for non-Darwin"
Author: Arthur Eubanks Date: 2024-04-10T23:41:51Z New Revision: be10070f91b86a6f126d2451852242bfcb2cd366 URL: https://github.com/llvm/llvm-project/commit/be10070f91b86a6f126d2451852242bfcb2cd366 DIFF: https://github.com/llvm/llvm-project/commit/be10070f91b86a6f126d2451852242bfcb2cd366.diff LOG: Revert "[Driver] Ensure ToolChain::LibraryPaths is not empty for non-Darwin" This reverts commit ccdebbae4d77d3efc236af92c22941de5d437e01. Causes test failures in the presence of Android runtime libraries in resource-dir. See comments on https://github.com/llvm/llvm-project/pull/87866. Added: Modified: clang/lib/Driver/ToolChain.cpp clang/test/Driver/arm-compiler-rt.c clang/test/Driver/cl-link.c clang/test/Driver/compiler-rt-unwind.c clang/test/Driver/coverage-ld.c clang/test/Driver/instrprof-ld.c clang/test/Driver/linux-ld.c clang/test/Driver/mingw-sanitizers.c clang/test/Driver/msp430-toolchain.c clang/test/Driver/print-libgcc-file-name-clangrt.c clang/test/Driver/print-runtime-dir.c clang/test/Driver/riscv32-toolchain-extra.c clang/test/Driver/riscv32-toolchain.c clang/test/Driver/riscv64-toolchain-extra.c clang/test/Driver/riscv64-toolchain.c clang/test/Driver/sanitizer-ld.c clang/test/Driver/wasm-toolchain.c clang/test/Driver/wasm-toolchain.cpp clang/test/Driver/windows-cross.c clang/test/Driver/zos-ld.c flang/test/Driver/msvc-dependent-lib-flags.f90 Removed: diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp index 237092ed07e5dc..03450fc0f57b93 100644 --- a/clang/lib/Driver/ToolChain.cpp +++ b/clang/lib/Driver/ToolChain.cpp @@ -796,13 +796,7 @@ ToolChain::getTargetSubDirPath(StringRef BaseDir) const { std::optional ToolChain::getRuntimePath() const { SmallString<128> P(D.ResourceDir); llvm::sys::path::append(P, "lib"); - if (auto Ret = getTargetSubDirPath(P)) -return Ret; - // Darwin does not use per-target runtime directory. - if (Triple.isOSDarwin()) -return {}; - llvm::sys::path::append(P, Triple.str()); - return std::string(P); + return getTargetSubDirPath(P); } std::optional ToolChain::getStdlibPath() const { diff --git a/clang/test/Driver/arm-compiler-rt.c b/clang/test/Driver/arm-compiler-rt.c index cb6c29f48a7814..5e9e528400d08e 100644 --- a/clang/test/Driver/arm-compiler-rt.c +++ b/clang/test/Driver/arm-compiler-rt.c @@ -10,47 +10,47 @@ // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \ // RUN: -rtlib=compiler-rt -### %s 2>&1 \ // RUN: | FileCheck %s -check-prefix ARM-GNUEABI -// ARM-GNUEABI: "{{.*[/\\]}}libclang_rt.builtins.a" +// ARM-GNUEABI: "{{.*[/\\]}}libclang_rt.builtins-arm.a" // RUN: %clang -target arm-linux-gnueabi \ // RUN: --sysroot=%S/Inputs/resource_dir_with_arch_subdir \ // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \ // RUN: -rtlib=compiler-rt -mfloat-abi=hard -### %s 2>&1 \ // RUN: | FileCheck %s -check-prefix ARM-GNUEABI-ABI -// ARM-GNUEABI-ABI: "{{.*[/\\]}}libclang_rt.builtins.a" +// ARM-GNUEABI-ABI: "{{.*[/\\]}}libclang_rt.builtins-armhf.a" // RUN: %clang -target arm-linux-gnueabihf \ // RUN: --sysroot=%S/Inputs/resource_dir_with_arch_subdir \ // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \ // RUN: -rtlib=compiler-rt -### %s 2>&1 \ // RUN: | FileCheck %s -check-prefix ARM-GNUEABIHF -// ARM-GNUEABIHF: "{{.*[/\\]}}libclang_rt.builtins.a" +// ARM-GNUEABIHF: "{{.*[/\\]}}libclang_rt.builtins-armhf.a" // RUN: %clang -target arm-linux-gnueabihf \ // RUN: --sysroot=%S/Inputs/resource_dir_with_arch_subdir \ // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \ // RUN: -rtlib=compiler-rt -mfloat-abi=soft -### %s 2>&1 \ // RUN: | FileCheck %s -check-prefix ARM-GNUEABIHF-ABI -// ARM-GNUEABIHF-ABI: "{{.*[/\\]}}libclang_rt.builtins.a" +// ARM-GNUEABIHF-ABI: "{{.*[/\\]}}libclang_rt.builtins-arm.a" // RUN: %clang -target arm-windows-itanium \ // RUN: --sysroot=%S/Inputs/resource_dir_with_arch_subdir \ // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \ // RUN: -rtlib=compiler-rt -### %s 2>&1 \ // RUN: | FileCheck %s -check-prefix ARM-WINDOWS -// ARM-WINDOWS: "{{.*[/\\]}}clang_rt.builtins.lib" +// ARM-WINDOWS: "{{.*[/\\]}}clang_rt.builtins-arm.lib" // RUN: %clang -target arm-linux-androideabi \ // RUN: --sysroot=%S/Inputs/resource_dir_with_arch_subdir \ // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \ // RUN: -rtlib=compiler-rt -### %s 2>&1 \ // RUN: | FileCheck %s -check-prefix ARM-ANDROID -// ARM-ANDROID: "{{.*[/\\]}}libclang_rt.builtins.a" +// ARM-ANDROID: "{{.*[/\\]}}libclang_rt.builtins-arm-android.a" // RUN: not %clang --target=arm-linux-androideabi \ // RUN: --sysroot=%S/Inputs/resource_dir_with_arch_subdir \ // RUN: -resource-dir=%S/Inputs/r
[clang] [Driver] Ensure ToolChain::LibraryPaths is not empty for non-Darwin (PR #87866)
aeubanks wrote: it seems that the test depends on if certain android runtime libraries are present or not in the resource dir (without per-target runtime directory since that's still an issue on Android). perhaps the tests need `-resource-dir` to make them more hermetic? anyway, will revert, feel free to reland once the tests are fixed. this is what's in my resource dir if it's helpful for reproducing ``` $ ls lib/clang/19/lib/linux/ aarch64 libclang_rt.asan_cxx-aarch64-android.a libclang_rt.builtins-aarch64-android.a libclang_rt.tsan_cxx-aarch64-android.a libclang_rt.ubsan_standalone-aarch64-android.so libclang_rt.asan-aarch64-android.a libclang_rt.asan-preinit-aarch64-android.a libclang_rt.profile-aarch64-android.a libclang_rt.ubsan_minimal-aarch64-android.a libclang_rt.ubsan_standalone_cxx-aarch64-android.a libclang_rt.asan-aarch64-android.so libclang_rt.asan_static-aarch64-android.a libclang_rt.tsan-aarch64-android.a libclang_rt.ubsan_standalone-aarch64-android.a ``` https://github.com/llvm/llvm-project/pull/87866 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 6ef4450 - [clang] Fix -Wunused-function in CGStmtOpenMP.cpp (NFC)
Author: Jie Fu Date: 2024-04-11T07:37:12+08:00 New Revision: 6ef4450705473e5cccb025219e8980999f456b71 URL: https://github.com/llvm/llvm-project/commit/6ef4450705473e5cccb025219e8980999f456b71 DIFF: https://github.com/llvm/llvm-project/commit/6ef4450705473e5cccb025219e8980999f456b71.diff LOG: [clang] Fix -Wunused-function in CGStmtOpenMP.cpp (NFC) llvm-project/clang/lib/CodeGen/CGStmtOpenMP.cpp:7959:13: error: unused function 'emitTargetTeamsLoopCodegenStatus' [-Werror,-Wunused-function] static void emitTargetTeamsLoopCodegenStatus(CodeGenFunction &CGF, ^ 1 error generated. Added: Modified: clang/lib/CodeGen/CGStmtOpenMP.cpp Removed: diff --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp b/clang/lib/CodeGen/CGStmtOpenMP.cpp index 3bf99366b69ced..a0a8a07c76ba16 100644 --- a/clang/lib/CodeGen/CGStmtOpenMP.cpp +++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp @@ -7956,10 +7956,10 @@ void CodeGenFunction::EmitOMPTeamsGenericLoopDirective( [](CodeGenFunction &) { return nullptr; }); } +#ifndef NDEBUG static void emitTargetTeamsLoopCodegenStatus(CodeGenFunction &CGF, std::string StatusMsg, const OMPExecutableDirective &D) { -#ifndef NDEBUG bool IsDevice = CGF.CGM.getLangOpts().OpenMPIsTargetDevice; if (IsDevice) StatusMsg += ": DEVICE"; @@ -7972,8 +7972,8 @@ static void emitTargetTeamsLoopCodegenStatus(CodeGenFunction &CGF, unsigned LineNo = PLoc.isValid() ? PLoc.getLine() : SM.getExpansionLineNumber(L); llvm::dbgs() << StatusMsg << ": " << FileName << ": " << LineNo << "\n"; -#endif } +#endif static void emitTargetTeamsGenericLoopRegionAsParallel( CodeGenFunction &CGF, PrePostActionTy &Action, ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang][deps] Cache `VFS::getRealPath()` (PR #68645)
https://github.com/jansvoboda11 updated https://github.com/llvm/llvm-project/pull/68645 >From fce5325720bcc945baed5923e00d09d84daf58e6 Mon Sep 17 00:00:00 2001 From: Jan Svoboda Date: Mon, 9 Oct 2023 10:14:17 -0700 Subject: [PATCH 1/8] [clang] Move lookup filename into function --- .../DependencyScanningFilesystem.h| 4 ++ .../DependencyScanningFilesystem.cpp | 41 --- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h index 9a522a3e2fe252..4cd0f958fcff82 100644 --- a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h +++ b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h @@ -402,6 +402,10 @@ class DependencyScanningWorkerFilesystem llvm::ErrorOr WorkingDirForCacheLookup; void updateWorkingDirForCacheLookup(); + + llvm::ErrorOr + tryGetFilenameForLookup(StringRef OriginalFilename, + llvm::SmallVectorImpl &PathBuf) const; }; } // end namespace dependencies diff --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp b/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp index 9b7812a1adb9e3..c66780d50fa184 100644 --- a/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp +++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp @@ -233,24 +233,15 @@ DependencyScanningWorkerFilesystem::computeAndStoreResult( llvm::ErrorOr DependencyScanningWorkerFilesystem::getOrCreateFileSystemEntry( StringRef OriginalFilename) { - StringRef FilenameForLookup; SmallString<256> PathBuf; - if (llvm::sys::path::is_absolute_gnu(OriginalFilename)) { -FilenameForLookup = OriginalFilename; - } else if (!WorkingDirForCacheLookup) { -return WorkingDirForCacheLookup.getError(); - } else { -StringRef RelFilename = OriginalFilename; -RelFilename.consume_front("./"); -PathBuf = *WorkingDirForCacheLookup; -llvm::sys::path::append(PathBuf, RelFilename); -FilenameForLookup = PathBuf.str(); - } - assert(llvm::sys::path::is_absolute_gnu(FilenameForLookup)); + auto FilenameForLookup = tryGetFilenameForLookup(OriginalFilename, PathBuf); + if (!FilenameForLookup) +return FilenameForLookup.getError(); + if (const auto *Entry = - findEntryByFilenameWithWriteThrough(FilenameForLookup)) + findEntryByFilenameWithWriteThrough(*FilenameForLookup)) return EntryRef(OriginalFilename, *Entry).unwrapError(); - auto MaybeEntry = computeAndStoreResult(OriginalFilename, FilenameForLookup); + auto MaybeEntry = computeAndStoreResult(OriginalFilename, *FilenameForLookup); if (!MaybeEntry) return MaybeEntry.getError(); return EntryRef(OriginalFilename, *MaybeEntry).unwrapError(); @@ -351,4 +342,24 @@ void DependencyScanningWorkerFilesystem::updateWorkingDirForCacheLookup() { llvm::sys::path::is_absolute_gnu(*WorkingDirForCacheLookup)); } +llvm::ErrorOr +DependencyScanningWorkerFilesystem::tryGetFilenameForLookup( +StringRef OriginalFilename, llvm::SmallVectorImpl &PathBuf) const { + StringRef FilenameForLookup; + if (llvm::sys::path::is_absolute_gnu(OriginalFilename)) { +FilenameForLookup = OriginalFilename; + } else if (!WorkingDirForCacheLookup) { +return WorkingDirForCacheLookup.getError(); + } else { +StringRef RelFilename = OriginalFilename; +RelFilename.consume_front("./"); +PathBuf.assign(WorkingDirForCacheLookup->begin(), + WorkingDirForCacheLookup->end()); +llvm::sys::path::append(PathBuf, RelFilename); +FilenameForLookup = StringRef{PathBuf.begin(), PathBuf.size()}; + } + assert(llvm::sys::path::is_absolute_gnu(FilenameForLookup)); + return FilenameForLookup; +} + const char DependencyScanningWorkerFilesystem::ID = 0; >From 548ce9b019eebd8ddfa40c6f097a7d1e7a464690 Mon Sep 17 00:00:00 2001 From: Jan Svoboda Date: Mon, 9 Oct 2023 10:14:22 -0700 Subject: [PATCH 2/8] [clang][deps] Cache `VFS::getRealPath()` --- .../DependencyScanningFilesystem.h| 46 ++- .../DependencyScanningFilesystem.cpp | 76 +++ 2 files changed, 121 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h index 4cd0f958fcff82..467b161fc2f0e3 100644 --- a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h +++ b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h @@ -142,6 +142,8 @@ class CachedFileSystemEntry { CachedFileContents *Contents; }; +using CachedRealPath = llvm::ErrorOr; + /// This class is a shared cache, that caches the 'stat' and 'open' calls to the /// underlying real file sy
[clang] NFC: Make clang resource headers an interface library (PR #88317)
https://github.com/compnerd approved this pull request. Thanks, this seems good! https://github.com/llvm/llvm-project/pull/88317 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang][deps] Overload `Filesystem::exists` in `DependencyScanningFilesystem` to have it use cached `status` (PR #88152)
jansvoboda11 wrote: Seems like some tests failed on Linux. https://github.com/llvm/llvm-project/pull/88152 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang][deps] Overload `Filesystem::exists` in `DependencyScanningFilesystem` to have it use cached `status` (PR #88152)
https://github.com/jansvoboda11 approved this pull request. LGTM. Would be nice to land Ben's change separately. https://github.com/llvm/llvm-project/pull/88152 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [llvm][clang] Trace VFS calls (PR #88326)
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 e72c949c15208ba3dd53a9cebfee02734965a678 540321e84dbd3c5687cfcc60e9deec79d790896e -- clang/include/clang/Driver/Compilation.h clang/include/clang/Frontend/CompilerInstance.h clang/include/clang/Frontend/CompilerInvocation.h clang/include/clang/Frontend/FrontendOptions.h clang/lib/Driver/Driver.cpp clang/lib/Driver/ToolChains/Clang.cpp clang/lib/Frontend/CompilerInstance.cpp clang/lib/Frontend/CompilerInvocation.cpp clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp clang/tools/clang-scan-deps/ClangScanDeps.cpp clang/tools/driver/cc1_main.cpp llvm/include/llvm/Support/VirtualFileSystem.h llvm/lib/Support/VirtualFileSystem.cpp llvm/unittests/Support/VirtualFileSystemTest.cpp `` View the diff from clang-format here. ``diff diff --git a/clang/include/clang/Frontend/CompilerInstance.h b/clang/include/clang/Frontend/CompilerInstance.h index 2135002366..7f645ee9e9 100644 --- a/clang/include/clang/Frontend/CompilerInstance.h +++ b/clang/include/clang/Frontend/CompilerInstance.h @@ -95,8 +95,8 @@ class CompilerInstance : public ModuleLoader { public: /// The instrumenting file system. IntrusiveRefCntPtr IVFS; -private: +private: /// The file manager. IntrusiveRefCntPtr FileMgr; `` https://github.com/llvm/llvm-project/pull/88326 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [llvm][clang] Trace VFS calls (PR #88326)
https://github.com/jansvoboda11 created https://github.com/llvm/llvm-project/pull/88326 None >From 540321e84dbd3c5687cfcc60e9deec79d790896e Mon Sep 17 00:00:00 2001 From: Jan Svoboda Date: Wed, 10 Apr 2024 16:03:19 -0700 Subject: [PATCH] [llvm][clang] Trace VFS calls --- clang/include/clang/Driver/Compilation.h | 11 + clang/include/clang/Driver/Options.td | 7 .../include/clang/Frontend/CompilerInstance.h | 8 .../clang/Frontend/CompilerInvocation.h | 10 +++-- .../include/clang/Frontend/FrontendOptions.h | 3 ++ clang/lib/Driver/Driver.cpp | 34 ++- clang/lib/Driver/ToolChains/Clang.cpp | 3 ++ clang/lib/Frontend/CompilerInstance.cpp | 2 +- clang/lib/Frontend/CompilerInvocation.cpp | 19 ++--- .../DependencyScanningWorker.cpp | 1 + .../DependencyScanning/ModuleDepCollector.cpp | 7 clang/test/ClangScanDeps/modules-inferred.m | 2 +- clang/tools/clang-scan-deps/ClangScanDeps.cpp | 25 ++- clang/tools/clang-scan-deps/Opts.td | 1 + clang/tools/driver/cc1_main.cpp | 13 ++ llvm/include/llvm/Support/VirtualFileSystem.h | 29 + llvm/lib/Support/VirtualFileSystem.cpp| 42 +++ .../Support/VirtualFileSystemTest.cpp | 37 18 files changed, 241 insertions(+), 13 deletions(-) diff --git a/clang/include/clang/Driver/Compilation.h b/clang/include/clang/Driver/Compilation.h index 36ae85c4245143..baf55d6b0f6061 100644 --- a/clang/include/clang/Driver/Compilation.h +++ b/clang/include/clang/Driver/Compilation.h @@ -115,6 +115,9 @@ class Compilation { /// -ftime-trace result files. ArgStringMap TimeTraceFiles; + /// -fvfs-trace result files. + ArgStringMap VFSTraceFiles; + /// Optional redirection for stdin, stdout, stderr. std::vector> Redirects; @@ -280,6 +283,14 @@ class Compilation { TimeTraceFiles[JA] = Name; } + const char *getVFSTraceFile(const JobAction *JA) const { +return VFSTraceFiles.lookup(JA); + } + void addVFSTraceFile(const char *Name, const JobAction *JA) { +assert(!VFSTraceFiles.contains(JA)); +VFSTraceFiles[JA] = Name; + } + /// CleanupFile - Delete a given file. /// /// \param IssueErrors - Report failures as errors. diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 0a74e6c75f95bb..630c1c763b5180 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -3904,6 +3904,13 @@ def ftime_trace_EQ : Joined<["-"], "ftime-trace=">, Group, HelpText<"Similar to -ftime-trace. Specify the JSON file or a directory which will contain the JSON file">, Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>, MarshallingInfoString>; +def fvfs_trace : Flag<["-"], "fvfs-trace">, Group, + HelpText<"Turn of virtual file system profiler. Generates text file based on output filename.">, + Visibility<[ClangOption, CLOption, DXCOption]>; +def fvfs_trace_EQ : Joined<["-"], "fvfs-trace=">, Group, + HelpText<"Similar to -fvfs-trace. Specify the text file or a directory that will contain the text file">, + Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>, + MarshallingInfoString>; def fproc_stat_report : Joined<["-"], "fproc-stat-report">, Group, HelpText<"Print subprocess statistics">; def fproc_stat_report_EQ : Joined<["-"], "fproc-stat-report=">, Group, diff --git a/clang/include/clang/Frontend/CompilerInstance.h b/clang/include/clang/Frontend/CompilerInstance.h index 3464654284f199..2135002366a33a 100644 --- a/clang/include/clang/Frontend/CompilerInstance.h +++ b/clang/include/clang/Frontend/CompilerInstance.h @@ -35,6 +35,9 @@ namespace llvm { class raw_fd_ostream; class Timer; class TimerGroup; +namespace vfs { +struct InstrumentingFileSystem; +} } namespace clang { @@ -89,6 +92,11 @@ class CompilerInstance : public ModuleLoader { /// Auxiliary Target info. IntrusiveRefCntPtr AuxTarget; +public: + /// The instrumenting file system. + IntrusiveRefCntPtr IVFS; +private: + /// The file manager. IntrusiveRefCntPtr FileMgr; diff --git a/clang/include/clang/Frontend/CompilerInvocation.h b/clang/include/clang/Frontend/CompilerInvocation.h index 1a2a39411e58d8..b50e7c7da636ec 100644 --- a/clang/include/clang/Frontend/CompilerInvocation.h +++ b/clang/include/clang/Frontend/CompilerInvocation.h @@ -39,6 +39,7 @@ class ArgList; namespace vfs { class FileSystem; +struct InstrumentingFileSystem; } // namespace vfs @@ -390,13 +391,14 @@ class CowCompilerInvocation : public CompilerInvocationBase { /// @} }; -IntrusiveRefCntPtr -createVFSFromCompilerInvocation(const CompilerInvocation &CI, -DiagnosticsEngine &Diags); +IntrusiveRefCntPtr createVFSFromCompilerInvocation( +const CompilerInvocation &CI, DiagnosticsEngine &Diags, +IntrusiveRefCntPtr *TracingFS = {}); I
[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 10ee32826fc2acb6bd993c88bdb7142360b6f263 Mon Sep 17 00:00:00 2001 From: Justin Stitt Date: Tue, 5 Mar 2024 03:14:49 + Subject: [PATCH 1/9] implement wraps attribute Signed-off-by: Justin Stitt --- clang/docs/ReleaseNotes.rst | 9 +++ clang/include/clang/AST/Expr.h| 3 + clang/include/clang/Basic/Attr.td | 6 ++ clang/include/clang/Basic/AttrDocs.td | 66 +++ .../clang/Basic/DiagnosticSemaKinds.td| 3 + clang/include/clang/Sema/Sema.h | 4 ++ clang/lib/AST/Expr.cpp| 19 ++ clang/lib/AST/ExprConstant.cpp| 6 +- clang/lib/AST/TypePrinter.cpp | 3 + clang/lib/CodeGen/CGExprScalar.cpp| 40 +-- clang/lib/Sema/SemaDeclAttr.cpp | 12 +++- clang/lib/Sema/SemaType.cpp | 15 + clang/test/CodeGen/integer-overflow.c | 56 clang/test/CodeGen/unsigned-overflow.c| 63 +++--- clang/test/Sema/attr-wraps.c | 9 +++ 15 files changed, 298 insertions(+), 16 deletions(-) create mode 100644 clang/test/Sema/attr-wraps.c diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index f96cebbde3d825..cb02af7e948989 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -282,6 +282,15 @@ Attribute Changes in Clang This allows the ``_Nullable`` and ``_Nonnull`` family of type attributes to apply to this class. +- 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 ignored in C++. + 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 2bfefeabc348be..68cd7d7c0fac3b 100644 --- a/clang/include/clang/AST/Expr.h +++ b/clang/include/clang/AST/Expr.h @@ -4077,6 +4077,9 @@ class BinaryOperator : public Expr { static unsigned sizeOfTrailingObjects(bool HasFPFeatures) { return HasFPFeatures * sizeof(FPOptionsOverride); } + + /// Do one of the subexpressions have the wraps attribute? + bool oneOfWraps(const ASTContext &Ctx) const; }; /// CompoundAssignOperator - For compound assignments (e.g. +=), we keep diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index dc87a8c6f022dc..06e41fcee206c4 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -4506,3 +4506,9 @@ def CodeAlign: StmtAttr { static constexpr int MaximumAlignment = 4096; }]; } + +def Wraps : DeclOrTypeAttr { + let Spellings = [Clang<"wraps">, CXX11<"", "wraps", 202403>]; + let Subjects = SubjectList<[Var, TypedefName, Field]>; + let Documentation = [WrapsDocs]; +} diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td index 0ca4ea377fc36a..a2adb923e3c47c 100644 --- a/clang/include/clang/Basic/AttrDocs.td +++ b/clang/include/clang/Basic/AttrDocs.td @@ -8044,3 +8044,69 @@ requirement: } }]; } + +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" component. + +For example, ``-fsanitize=signed-integer-overflow`` or ``-Winteger-overflow`` +will not warn about suspicious overflowing arithmetic -- assuming correct usage +of the wraps attribute. + +This example shows some basic usage of ``__attribute__((wraps))`` on a type +definition when building with ``-fsanitize=signed-integer-overflow`` + +.. code-block:: c + typedef int __attribute__((wraps)) wrapping_int; + + void foo() { +wrapping_int a = INT_MAX; +++a; // no sanitizer warning + } + + int main() { foo(); } + +In the following example, we use ``__attribute__((wraps))`` on a variable to +disable overflow instrumentation for arithmetic expressions it appears in. We +do so with a popular overflow-checking pattern which we might not want to trip +sanitizers (like ``-fsanitize=unsigned-integer-overflow``). + +.. code-block:: c + void foo(int off
[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)
JustinStitt wrote: The most recent commits have massively simplified checking for the wrapping attributes. FWIW, the tests I am running are: ✅ `$ llvm-lit clang/test/CodeGen/integer-overflow.c -v` ✅ `$ llvm-lit clang/test/CodeGen/unsigned-overflow.c -v` ✅ `$ llvm-lit clang/test/Sema/attr-wraps.c -v` ...and some hand-rolled stuff I have. https://github.com/llvm/llvm-project/pull/86618 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] nonblocking/nonallocating attributes (was: nolock/noalloc) (PR #84983)
@@ -4429,6 +4433,218 @@ class FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode { } }; +// -- + +// TODO: Should FunctionEffect be located elsewhere, where Decl is not +// forward-declared? +class Decl; +class CXXMethodDecl; +class FunctionEffectSet; +class TypeSourceInfo; + +/// Represents an abstract function effect. +class FunctionEffect { +public: + /// Identifies the particular type of effect. + enum class Type { +None = 0, +NonBlocking, +NonAllocating, + }; + + /// Flags describing behaviors of the effect. + // (Why not a struct with bitfields? There's one function that would like to + // test a caller-specified bit. There are some potential optimizations that + // would OR together the bits of multiple effects.) + using Flags = unsigned; + enum FlagBit : unsigned { +// Can verification inspect callees' implementations? (e.g. nonblocking: +// yes, tcb+types: no) +FE_InferrableOnCallees = 0x1, + +// Language constructs which effects can diagnose as disallowed. +FE_ExcludeThrow = 0x2, +FE_ExcludeCatch = 0x4, +FE_ExcludeObjCMessageSend = 0x8, +FE_ExcludeStaticLocalVars = 0x10, +FE_ExcludeThreadLocalVars = 0x20 + }; + + /// Describes the result of effects differing between a base class's virtual + /// method and an overriding method in a subclass. + enum class OverrideResult { +Ignore, +Warn, +Propagate // Base method's effects are merged with those of the override. + }; + +private: + // For uniqueness, currently only Type_ is significant. + + LLVM_PREFERRED_TYPE(Type) + unsigned Type_ : 2; + Flags Flags_ : 8; // A constant function of Type but cached here. + + // Expansion: for hypothetical TCB+types, there could be one Type for TCB, + // then ~16(?) bits "Subtype" to map to a specific named TCB. Subtype would + // be considered for uniqueness. + + // Since this struct is serialized as if it were a uint32_t, it's important + // to pad and explicitly zero the extra bits. + [[maybe_unused]] unsigned Padding : 22; + +public: + using CalleeDeclOrType = + llvm::PointerUnion; + + FunctionEffect() : Type_(unsigned(Type::None)), Flags_(0), Padding(0) {} + + explicit FunctionEffect(Type T); + + /// The type of the effect. + Type type() const { return Type(Type_); } + + /// Flags describing behaviors of the effect. + Flags flags() const { return Flags_; } + + /// The description printed in diagnostics, e.g. 'nonblocking'. + StringRef name() const; + + /// A hashable representation. + uint32_t opaqueRepr() const { return Type_ | (Flags_ << 2u); } + + /// Return true if adding or removing the effect as part of a type conversion + /// should generate a diagnostic. + bool diagnoseConversion(bool Adding, QualType OldType, + FunctionEffectSet OldFX, QualType NewType, + FunctionEffectSet NewFX) const; dougsonos wrote: One way to address this would be to move all of the behavioral methods of `FunctionEffect` to be static methods of `Sema` which take `FunctionEffect` as the first parameter. https://github.com/llvm/llvm-project/pull/84983 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[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 10ee32826fc2acb6bd993c88bdb7142360b6f263 Mon Sep 17 00:00:00 2001 From: Justin Stitt Date: Tue, 5 Mar 2024 03:14:49 + Subject: [PATCH 1/8] implement wraps attribute Signed-off-by: Justin Stitt --- clang/docs/ReleaseNotes.rst | 9 +++ clang/include/clang/AST/Expr.h| 3 + clang/include/clang/Basic/Attr.td | 6 ++ clang/include/clang/Basic/AttrDocs.td | 66 +++ .../clang/Basic/DiagnosticSemaKinds.td| 3 + clang/include/clang/Sema/Sema.h | 4 ++ clang/lib/AST/Expr.cpp| 19 ++ clang/lib/AST/ExprConstant.cpp| 6 +- clang/lib/AST/TypePrinter.cpp | 3 + clang/lib/CodeGen/CGExprScalar.cpp| 40 +-- clang/lib/Sema/SemaDeclAttr.cpp | 12 +++- clang/lib/Sema/SemaType.cpp | 15 + clang/test/CodeGen/integer-overflow.c | 56 clang/test/CodeGen/unsigned-overflow.c| 63 +++--- clang/test/Sema/attr-wraps.c | 9 +++ 15 files changed, 298 insertions(+), 16 deletions(-) create mode 100644 clang/test/Sema/attr-wraps.c diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index f96cebbde3d825..cb02af7e948989 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -282,6 +282,15 @@ Attribute Changes in Clang This allows the ``_Nullable`` and ``_Nonnull`` family of type attributes to apply to this class. +- 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 ignored in C++. + 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 2bfefeabc348be..68cd7d7c0fac3b 100644 --- a/clang/include/clang/AST/Expr.h +++ b/clang/include/clang/AST/Expr.h @@ -4077,6 +4077,9 @@ class BinaryOperator : public Expr { static unsigned sizeOfTrailingObjects(bool HasFPFeatures) { return HasFPFeatures * sizeof(FPOptionsOverride); } + + /// Do one of the subexpressions have the wraps attribute? + bool oneOfWraps(const ASTContext &Ctx) const; }; /// CompoundAssignOperator - For compound assignments (e.g. +=), we keep diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index dc87a8c6f022dc..06e41fcee206c4 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -4506,3 +4506,9 @@ def CodeAlign: StmtAttr { static constexpr int MaximumAlignment = 4096; }]; } + +def Wraps : DeclOrTypeAttr { + let Spellings = [Clang<"wraps">, CXX11<"", "wraps", 202403>]; + let Subjects = SubjectList<[Var, TypedefName, Field]>; + let Documentation = [WrapsDocs]; +} diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td index 0ca4ea377fc36a..a2adb923e3c47c 100644 --- a/clang/include/clang/Basic/AttrDocs.td +++ b/clang/include/clang/Basic/AttrDocs.td @@ -8044,3 +8044,69 @@ requirement: } }]; } + +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" component. + +For example, ``-fsanitize=signed-integer-overflow`` or ``-Winteger-overflow`` +will not warn about suspicious overflowing arithmetic -- assuming correct usage +of the wraps attribute. + +This example shows some basic usage of ``__attribute__((wraps))`` on a type +definition when building with ``-fsanitize=signed-integer-overflow`` + +.. code-block:: c + typedef int __attribute__((wraps)) wrapping_int; + + void foo() { +wrapping_int a = INT_MAX; +++a; // no sanitizer warning + } + + int main() { foo(); } + +In the following example, we use ``__attribute__((wraps))`` on a variable to +disable overflow instrumentation for arithmetic expressions it appears in. We +do so with a popular overflow-checking pattern which we might not want to trip +sanitizers (like ``-fsanitize=unsigned-integer-overflow``). + +.. code-block:: c + void foo(int off
[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)
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 eec41d2f8d81b546d7b97648cca6b2d656104bd3 a2f63982920f22d795c4971800bcc5cb55356570 -- clang/test/Sema/attr-wraps.c clang/include/clang/AST/Expr.h clang/include/clang/AST/Type.h clang/include/clang/Sema/Sema.h clang/lib/AST/Expr.cpp clang/lib/AST/ExprConstant.cpp clang/lib/AST/Type.cpp clang/lib/AST/TypePrinter.cpp clang/lib/CodeGen/CGExprScalar.cpp clang/lib/Sema/SemaChecking.cpp clang/lib/Sema/SemaDeclAttr.cpp clang/lib/Sema/SemaType.cpp clang/test/CodeGen/integer-overflow.c clang/test/CodeGen/unsigned-overflow.c `` View the diff from clang-format here. ``diff diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp index a001cdc7b5..4d996b4c57 100644 --- a/clang/lib/CodeGen/CGExprScalar.cpp +++ b/clang/lib/CodeGen/CGExprScalar.cpp @@ -150,9 +150,7 @@ struct BinOpInfo { /// Does the BinaryOperator have the wraps attribute? /// If so, we can ellide overflow sanitizer checks. - bool hasWrappingOperand() const { -return E->getType().hasWrapsAttr(); - } + bool hasWrappingOperand() const { return E->getType().hasWrapsAttr(); } }; static bool MustVisitNullValue(const Expr *E) { @@ -4418,7 +4416,8 @@ Value *ScalarExprEmitter::EmitShl(const BinOpInfo &Ops) { bool SanitizeSignedBase = CGF.SanOpts.has(SanitizerKind::ShiftBase) && Ops.Ty->hasSignedIntegerRepresentation() && !CGF.getLangOpts().isSignedOverflowDefined() && -!CGF.getLangOpts().CPlusPlus20 && !Ops.hasWrappingOperand(); +!CGF.getLangOpts().CPlusPlus20 && +!Ops.hasWrappingOperand(); bool SanitizeUnsignedBase = CGF.SanOpts.has(SanitizerKind::UnsignedShiftBase) && Ops.Ty->hasUnsignedIntegerRepresentation(); `` https://github.com/llvm/llvm-project/pull/86618 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)
@@ -6954,6 +6954,23 @@ static void HandleBTFTypeTagAttribute(QualType &Type, const ParsedAttr &Attr, ::new (Ctx) BTFTypeTagAttr(Ctx, Attr, BTFTypeTag), Type); } +static void handleWrapsAttr(QualType &Type, const ParsedAttr &Attr, +TypeProcessingState &State) { + Sema &S = State.getSema(); + ASTContext &Ctx = S.Context; + + // No need to warn here, that is handled by SemaDeclAttr. + // Simply disable applying this attribute. + if (S.getLangOpts().CPlusPlus) JustinStitt wrote: Right! I missed this. Fixed! https://github.com/llvm/llvm-project/pull/86618 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)
@@ -147,6 +147,15 @@ struct BinOpInfo { return UnOp->getSubExpr()->getType()->isFixedPointType(); return false; } + + /// Does the BinaryOperator have the wraps attribute? + /// If so, we can ellide overflow sanitizer checks. + bool oneOfWraps() const { +const Type *TyPtr = E->getType().getTypePtrOrNull(); +if (TyPtr) JustinStitt wrote: Gotcha, checkout a2f63982920f22d795c4971800bcc5cb55356570 https://github.com/llvm/llvm-project/pull/86618 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)
@@ -2237,6 +2237,21 @@ bool BinaryOperator::isNullPointerArithmeticExtension(ASTContext &Ctx, return true; } +bool BinaryOperator::oneOfWraps(const ASTContext &Ctx) const { + llvm::SmallVector Both = {getLHS(), getRHS()}; JustinStitt wrote: I had trouble with your code snippet because `children()` gives `Stmt` iterators and I would have to add in a cast or two. I went with a simpler approach in a2f63982920f22d795c4971800bcc5cb55356570 (with QualType::hasWrapsAttr()) https://github.com/llvm/llvm-project/pull/86618 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)
@@ -4506,3 +4506,9 @@ def CodeAlign: StmtAttr { static constexpr int MaximumAlignment = 4096; }]; } + +def Wraps : DeclOrTypeAttr { + let Spellings = [GNU<"wraps">]; + let Subjects = SubjectList<[Var, TypedefName, Field]>; + let Documentation = [WrapsDocs]; +} JustinStitt wrote: 0d7566777f06b3f2058d93dd77624ab2c66f1127 https://github.com/llvm/llvm-project/pull/86618 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)
@@ -4506,3 +4506,9 @@ def CodeAlign: StmtAttr { static constexpr int MaximumAlignment = 4096; }]; } + +def Wraps : DeclOrTypeAttr { + let Spellings = [GNU<"wraps">]; JustinStitt wrote: Right, I had that originally. I shouldn't have changed it :) Anyways, fixed in 0d7566777f06b3f2058d93dd77624ab2c66f1127 https://github.com/llvm/llvm-project/pull/86618 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)
@@ -4077,6 +4077,9 @@ class BinaryOperator : public Expr { static unsigned sizeOfTrailingObjects(bool HasFPFeatures) { return HasFPFeatures * sizeof(FPOptionsOverride); } + + /// Do one of the subexpressions have the wraps attribute? + bool oneOfWraps(const ASTContext &Ctx) const; JustinStitt wrote: Hi, fixed with 5e6d926532c2cff3288f25e9b8f872e7f2ec9b65 https://github.com/llvm/llvm-project/pull/86618 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[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 10ee32826fc2acb6bd993c88bdb7142360b6f263 Mon Sep 17 00:00:00 2001 From: Justin Stitt Date: Tue, 5 Mar 2024 03:14:49 + Subject: [PATCH 1/7] implement wraps attribute Signed-off-by: Justin Stitt --- clang/docs/ReleaseNotes.rst | 9 +++ clang/include/clang/AST/Expr.h| 3 + clang/include/clang/Basic/Attr.td | 6 ++ clang/include/clang/Basic/AttrDocs.td | 66 +++ .../clang/Basic/DiagnosticSemaKinds.td| 3 + clang/include/clang/Sema/Sema.h | 4 ++ clang/lib/AST/Expr.cpp| 19 ++ clang/lib/AST/ExprConstant.cpp| 6 +- clang/lib/AST/TypePrinter.cpp | 3 + clang/lib/CodeGen/CGExprScalar.cpp| 40 +-- clang/lib/Sema/SemaDeclAttr.cpp | 12 +++- clang/lib/Sema/SemaType.cpp | 15 + clang/test/CodeGen/integer-overflow.c | 56 clang/test/CodeGen/unsigned-overflow.c| 63 +++--- clang/test/Sema/attr-wraps.c | 9 +++ 15 files changed, 298 insertions(+), 16 deletions(-) create mode 100644 clang/test/Sema/attr-wraps.c diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index f96cebbde3d825..cb02af7e948989 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -282,6 +282,15 @@ Attribute Changes in Clang This allows the ``_Nullable`` and ``_Nonnull`` family of type attributes to apply to this class. +- 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 ignored in C++. + 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 2bfefeabc348be..68cd7d7c0fac3b 100644 --- a/clang/include/clang/AST/Expr.h +++ b/clang/include/clang/AST/Expr.h @@ -4077,6 +4077,9 @@ class BinaryOperator : public Expr { static unsigned sizeOfTrailingObjects(bool HasFPFeatures) { return HasFPFeatures * sizeof(FPOptionsOverride); } + + /// Do one of the subexpressions have the wraps attribute? + bool oneOfWraps(const ASTContext &Ctx) const; }; /// CompoundAssignOperator - For compound assignments (e.g. +=), we keep diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index dc87a8c6f022dc..06e41fcee206c4 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -4506,3 +4506,9 @@ def CodeAlign: StmtAttr { static constexpr int MaximumAlignment = 4096; }]; } + +def Wraps : DeclOrTypeAttr { + let Spellings = [Clang<"wraps">, CXX11<"", "wraps", 202403>]; + let Subjects = SubjectList<[Var, TypedefName, Field]>; + let Documentation = [WrapsDocs]; +} diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td index 0ca4ea377fc36a..a2adb923e3c47c 100644 --- a/clang/include/clang/Basic/AttrDocs.td +++ b/clang/include/clang/Basic/AttrDocs.td @@ -8044,3 +8044,69 @@ requirement: } }]; } + +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" component. + +For example, ``-fsanitize=signed-integer-overflow`` or ``-Winteger-overflow`` +will not warn about suspicious overflowing arithmetic -- assuming correct usage +of the wraps attribute. + +This example shows some basic usage of ``__attribute__((wraps))`` on a type +definition when building with ``-fsanitize=signed-integer-overflow`` + +.. code-block:: c + typedef int __attribute__((wraps)) wrapping_int; + + void foo() { +wrapping_int a = INT_MAX; +++a; // no sanitizer warning + } + + int main() { foo(); } + +In the following example, we use ``__attribute__((wraps))`` on a variable to +disable overflow instrumentation for arithmetic expressions it appears in. We +do so with a popular overflow-checking pattern which we might not want to trip +sanitizers (like ``-fsanitize=unsigned-integer-overflow``). + +.. code-block:: c + void foo(int off
[clang] [llvm] [clang][deps] Overload `Filesystem::exists` in `DependencyScanningFilesystem` to have it use cached `status` (PR #88152)
artemcm wrote: > I'd like to see a unit test specific to `DependencyScanningFilesystem`, > similar to what I have here: #68645. Done! Added one in `DependencyScanningFilesystemTest.cpp`. Thank you. https://github.com/llvm/llvm-project/pull/88152 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang][deps] Overload `Filesystem::exists` in `DependencyScanningFilesystem` to have it use cached `status` (PR #88152)
https://github.com/artemcm updated https://github.com/llvm/llvm-project/pull/88152 >From c2b2cd03e1d8f92b1df814e6312158b8820b790d Mon Sep 17 00:00:00 2001 From: Ben Langmuir Date: Tue, 9 Apr 2024 11:22:44 -0700 Subject: [PATCH 1/2] [llvm][vfs] Make vfs::FileSystem::exists() virtual NFC Allow a vfs::FileSystem to provide a more efficient implementation of exists() if they are able to. The existing FileSystem implementations continue to default to using status() except that overlay, proxy, and redirecting filesystems are taught to forward calls to exists() correctly to their wrapped/external filesystem. --- llvm/include/llvm/Support/VirtualFileSystem.h | 8 +- llvm/lib/Support/VirtualFileSystem.cpp| 56 ++ .../Support/VirtualFileSystemTest.cpp | 165 ++ 3 files changed, 227 insertions(+), 2 deletions(-) diff --git a/llvm/include/llvm/Support/VirtualFileSystem.h b/llvm/include/llvm/Support/VirtualFileSystem.h index 770ca8764426a4..bdc98bfd7d2571 100644 --- a/llvm/include/llvm/Support/VirtualFileSystem.h +++ b/llvm/include/llvm/Support/VirtualFileSystem.h @@ -300,8 +300,9 @@ class FileSystem : public llvm::ThreadSafeRefCountedBase, virtual std::error_code getRealPath(const Twine &Path, SmallVectorImpl &Output) const; - /// Check whether a file exists. Provided for convenience. - bool exists(const Twine &Path); + /// Check whether \p Path exists. By default this uses \c status(), but + /// filesystems may provide a more efficient implementation if available. + virtual bool exists(const Twine &Path); /// Is the file mounted on a local filesystem? virtual std::error_code isLocal(const Twine &Path, bool &Result); @@ -386,6 +387,7 @@ class OverlayFileSystem : public RTTIExtends { void pushOverlay(IntrusiveRefCntPtr FS); llvm::ErrorOr status(const Twine &Path) override; + bool exists(const Twine &Path) override; llvm::ErrorOr> openFileForRead(const Twine &Path) override; directory_iterator dir_begin(const Twine &Dir, std::error_code &EC) override; @@ -439,6 +441,7 @@ class ProxyFileSystem : public RTTIExtends { llvm::ErrorOr status(const Twine &Path) override { return FS->status(Path); } + bool exists(const Twine &Path) override { return FS->exists(Path); } llvm::ErrorOr> openFileForRead(const Twine &Path) override { return FS->openFileForRead(Path); @@ -1044,6 +1047,7 @@ class RedirectingFileSystem bool UseExternalNames, FileSystem &ExternalFS); ErrorOr status(const Twine &Path) override; + bool exists(const Twine &Path) override; ErrorOr> openFileForRead(const Twine &Path) override; std::error_code getRealPath(const Twine &Path, diff --git a/llvm/lib/Support/VirtualFileSystem.cpp b/llvm/lib/Support/VirtualFileSystem.cpp index 057f8eae0552c6..272880ba602b84 100644 --- a/llvm/lib/Support/VirtualFileSystem.cpp +++ b/llvm/lib/Support/VirtualFileSystem.cpp @@ -439,6 +439,15 @@ ErrorOr OverlayFileSystem::status(const Twine &Path) { return make_error_code(llvm::errc::no_such_file_or_directory); } +bool OverlayFileSystem::exists(const Twine &Path) { + // FIXME: handle symlinks that cross file systems + for (iterator I = overlays_begin(), E = overlays_end(); I != E; ++I) { +if ((*I)->exists(Path)) + return true; + } + return false; +} + ErrorOr> OverlayFileSystem::openFileForRead(const llvm::Twine &Path) { // FIXME: handle symlinks that cross file systems @@ -2431,6 +2440,53 @@ ErrorOr RedirectingFileSystem::status(const Twine &OriginalPath) { return S; } +bool RedirectingFileSystem::exists(const Twine &OriginalPath) { + SmallString<256> Path; + OriginalPath.toVector(Path); + + if (makeAbsolute(Path)) +return false; + + if (Redirection == RedirectKind::Fallback) { +// Attempt to find the original file first, only falling back to the +// mapped file if that fails. +if (ExternalFS->exists(Path)) + return true; + } + + ErrorOr Result = lookupPath(Path); + if (!Result) { +// Was not able to map file, fallthrough to using the original path if +// that was the specified redirection type. +if (Redirection == RedirectKind::Fallthrough && +isFileNotFound(Result.getError())) + return ExternalFS->exists(Path); +return false; + } + + std::optional ExtRedirect = Result->getExternalRedirect(); + if (!ExtRedirect) { +assert(isa(Result->E)); +return true; + } + + SmallString<256> RemappedPath((*ExtRedirect).str()); + if (makeAbsolute(RemappedPath)) +return false; + + if (ExternalFS->exists(RemappedPath)) +return true; + + if (Redirection == RedirectKind::Fallthrough) { +// Mapped the file but it wasn't found in the underlying filesystem, +// fallthrough to using the original path if that was the specified +// redirection type. +return ExternalFS->exists(Path); + } + + return false; +} + namespace { /// Provide a file wrapper with an over
[clang] [llvm] [HLSL][SPIRV] Add any intrinsic lowering (PR #88325)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Farzon Lotfi (farzonl) Changes - `CGBuiltin.cpp` - Switch to using `CGM.getHLSLRuntime().get##NAME##Intrinsic()` - `CGHLSLRuntime.h` - Add any to backend intrinsic abstraction - `IntrinsicsSPIRV.td` - Add any intrinsic to SPIR-V. - `SPIRVInstructionSelector.cpp` - Add means of selecting any intrinsic. Any and All share the same behavior up to the opCode. They are only different in vector cases. Completes #88045 --- Patch is 30.77 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/88325.diff 6 Files Affected: - (modified) clang/lib/CodeGen/CGBuiltin.cpp (+2-1) - (modified) clang/lib/CodeGen/CGHLSLRuntime.h (+1) - (modified) clang/test/CodeGenHLSL/builtins/any.hlsl (+244-126) - (modified) llvm/include/llvm/IR/IntrinsicsSPIRV.td (+1) - (modified) llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp (+25-4) - (added) llvm/test/CodeGen/SPIRV/hlsl-intrinsics/any.ll (+187) ``diff diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index c052367d287820..5914862e93c0bb 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -18194,7 +18194,8 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID, Value *Op0 = EmitScalarExpr(E->getArg(0)); return Builder.CreateIntrinsic( /*ReturnType=*/llvm::Type::getInt1Ty(getLLVMContext()), -Intrinsic::dx_any, ArrayRef{Op0}, nullptr, "dx.any"); +CGM.getHLSLRuntime().getAnyIntrinsic(), ArrayRef{Op0}, nullptr, +"hlsl.any"); } case Builtin::BI__builtin_hlsl_elementwise_clamp: { Value *OpX = EmitScalarExpr(E->getArg(0)); diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h b/clang/lib/CodeGen/CGHLSLRuntime.h index 2b8073aef973f8..506b364f5b2ec7 100644 --- a/clang/lib/CodeGen/CGHLSLRuntime.h +++ b/clang/lib/CodeGen/CGHLSLRuntime.h @@ -73,6 +73,7 @@ class CGHLSLRuntime { //===--===// GENERATE_HLSL_INTRINSIC_FUNCTION(All, all) + GENERATE_HLSL_INTRINSIC_FUNCTION(Any, any) GENERATE_HLSL_INTRINSIC_FUNCTION(ThreadId, thread_id) //===--===// diff --git a/clang/test/CodeGenHLSL/builtins/any.hlsl b/clang/test/CodeGenHLSL/builtins/any.hlsl index ae348fec756b3e..84584281a3b7d2 100644 --- a/clang/test/CodeGenHLSL/builtins/any.hlsl +++ b/clang/test/CodeGenHLSL/builtins/any.hlsl @@ -1,186 +1,304 @@ // RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \ +// RUN: spirv-unknown-vulkan-compute %s -fnative-half-type \ +// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s \ +// RUN: --check-prefixes=CHECK,NATIVE_HALF,SPIR_NATIVE_HALF,SPIR_CHECK +// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \ +// RUN: spirv-unknown-vulkan-compute %s -emit-llvm -disable-llvm-passes \ +// RUN: -o - | FileCheck %s --check-prefixes=CHECK,SPIR_NO_HALF,SPIR_CHECK +// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \ // RUN: dxil-pc-shadermodel6.3-library %s -fnative-half-type \ // RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s \ -// RUN: --check-prefixes=CHECK,NATIVE_HALF +// RUN: --check-prefixes=CHECK,NATIVE_HALF,DXIL_NATIVE_HALF,DXIL_CHECK // RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \ // RUN: dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \ -// RUN: -o - | FileCheck %s --check-prefixes=CHECK,NO_HALF +// RUN: -o - | FileCheck %s --check-prefixes=CHECK,DXIL_NO_HALF,DXIL_CHECK #ifdef __HLSL_ENABLE_16_BIT -// NATIVE_HALF: define noundef i1 @ -// NATIVE_HALF: %dx.any = call i1 @llvm.dx.any.i16 -// NATIVE_HALF: ret i1 %dx.any +// DXIL_NATIVE_HALF: define noundef i1 @ +// SPIR_NATIVE_HALF: define spir_func noundef i1 @ +// DXIL_NATIVE_HALF: %hlsl.any = call i1 @llvm.dx.any.i16 +// SPIR_NATIVE_HALF: %hlsl.any = call i1 @llvm.spv.any.i16 +// NATIVE_HALF: ret i1 %hlsl.any bool test_any_int16_t(int16_t p0) { return any(p0); } -// NATIVE_HALF: define noundef i1 @ -// NATIVE_HALF: %dx.any = call i1 @llvm.dx.any.v2i16 -// NATIVE_HALF: ret i1 %dx.any + +// DXIL_NATIVE_HALF: define noundef i1 @ +// SPIR_NATIVE_HALF: define spir_func noundef i1 @ +// DXIL_NATIVE_HALF: %hlsl.any = call i1 @llvm.dx.any.v2i16 +// SPIR_NATIVE_HALF: %hlsl.any = call i1 @llvm.spv.any.v2i16 +// NATIVE_HALF: ret i1 %hlsl.any bool test_any_int16_t2(int16_t2 p0) { return any(p0); } -// NATIVE_HALF: define noundef i1 @ -// NATIVE_HALF: %dx.any = call i1 @llvm.dx.any.v3i16 -// NATIVE_HALF: ret i1 %dx.any + +// DXIL_NATIVE_HALF: define noundef i1 @ +// SPIR_NATIVE_HALF: define spir_func noundef i1 @ +// DXIL_NATIVE_HALF: %hlsl.any = call i1 @llvm.dx.any.v3i16 +// SPIR_NATIVE_HALF: %hlsl.any = call i1 @llvm.spv.any.v3i16 +// NATIVE_HALF: ret i1 %hlsl.any bool test_any_int16_t3(int16_t3 p0) { return any(p0); } -// NATIVE_HALF: define noundef i1 @ -// NATIVE_HALF:
[clang] [llvm] [HLSL][SPIRV] Add any intrinsic lowering (PR #88325)
https://github.com/farzonl created https://github.com/llvm/llvm-project/pull/88325 - `CGBuiltin.cpp` - Switch to using `CGM.getHLSLRuntime().get##NAME##Intrinsic()` - `CGHLSLRuntime.h` - Add any to backend intrinsic abstraction - `IntrinsicsSPIRV.td` - Add any intrinsic to SPIR-V. - `SPIRVInstructionSelector.cpp` - Add means of selecting any intrinsic. Any and All share the same behavior up to the opCode. They are only different in vector cases. Completes #88045 >From 1d1e29047c589e6d8424122b4427ec048dd5ec97 Mon Sep 17 00:00:00 2001 From: Farzon Lotfi Date: Wed, 10 Apr 2024 17:59:24 -0400 Subject: [PATCH] [HLSL][SPIRV] Add any intrinsic lowering --- clang/lib/CodeGen/CGBuiltin.cpp | 3 +- clang/lib/CodeGen/CGHLSLRuntime.h | 1 + clang/test/CodeGenHLSL/builtins/any.hlsl | 370 -- llvm/include/llvm/IR/IntrinsicsSPIRV.td | 1 + .../Target/SPIRV/SPIRVInstructionSelector.cpp | 29 +- .../test/CodeGen/SPIRV/hlsl-intrinsics/any.ll | 187 + 6 files changed, 460 insertions(+), 131 deletions(-) create mode 100644 llvm/test/CodeGen/SPIRV/hlsl-intrinsics/any.ll diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index c052367d287820..5914862e93c0bb 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -18194,7 +18194,8 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID, Value *Op0 = EmitScalarExpr(E->getArg(0)); return Builder.CreateIntrinsic( /*ReturnType=*/llvm::Type::getInt1Ty(getLLVMContext()), -Intrinsic::dx_any, ArrayRef{Op0}, nullptr, "dx.any"); +CGM.getHLSLRuntime().getAnyIntrinsic(), ArrayRef{Op0}, nullptr, +"hlsl.any"); } case Builtin::BI__builtin_hlsl_elementwise_clamp: { Value *OpX = EmitScalarExpr(E->getArg(0)); diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h b/clang/lib/CodeGen/CGHLSLRuntime.h index 2b8073aef973f8..506b364f5b2ec7 100644 --- a/clang/lib/CodeGen/CGHLSLRuntime.h +++ b/clang/lib/CodeGen/CGHLSLRuntime.h @@ -73,6 +73,7 @@ class CGHLSLRuntime { //===--===// GENERATE_HLSL_INTRINSIC_FUNCTION(All, all) + GENERATE_HLSL_INTRINSIC_FUNCTION(Any, any) GENERATE_HLSL_INTRINSIC_FUNCTION(ThreadId, thread_id) //===--===// diff --git a/clang/test/CodeGenHLSL/builtins/any.hlsl b/clang/test/CodeGenHLSL/builtins/any.hlsl index ae348fec756b3e..84584281a3b7d2 100644 --- a/clang/test/CodeGenHLSL/builtins/any.hlsl +++ b/clang/test/CodeGenHLSL/builtins/any.hlsl @@ -1,186 +1,304 @@ // RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \ +// RUN: spirv-unknown-vulkan-compute %s -fnative-half-type \ +// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s \ +// RUN: --check-prefixes=CHECK,NATIVE_HALF,SPIR_NATIVE_HALF,SPIR_CHECK +// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \ +// RUN: spirv-unknown-vulkan-compute %s -emit-llvm -disable-llvm-passes \ +// RUN: -o - | FileCheck %s --check-prefixes=CHECK,SPIR_NO_HALF,SPIR_CHECK +// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \ // RUN: dxil-pc-shadermodel6.3-library %s -fnative-half-type \ // RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s \ -// RUN: --check-prefixes=CHECK,NATIVE_HALF +// RUN: --check-prefixes=CHECK,NATIVE_HALF,DXIL_NATIVE_HALF,DXIL_CHECK // RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \ // RUN: dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \ -// RUN: -o - | FileCheck %s --check-prefixes=CHECK,NO_HALF +// RUN: -o - | FileCheck %s --check-prefixes=CHECK,DXIL_NO_HALF,DXIL_CHECK #ifdef __HLSL_ENABLE_16_BIT -// NATIVE_HALF: define noundef i1 @ -// NATIVE_HALF: %dx.any = call i1 @llvm.dx.any.i16 -// NATIVE_HALF: ret i1 %dx.any +// DXIL_NATIVE_HALF: define noundef i1 @ +// SPIR_NATIVE_HALF: define spir_func noundef i1 @ +// DXIL_NATIVE_HALF: %hlsl.any = call i1 @llvm.dx.any.i16 +// SPIR_NATIVE_HALF: %hlsl.any = call i1 @llvm.spv.any.i16 +// NATIVE_HALF: ret i1 %hlsl.any bool test_any_int16_t(int16_t p0) { return any(p0); } -// NATIVE_HALF: define noundef i1 @ -// NATIVE_HALF: %dx.any = call i1 @llvm.dx.any.v2i16 -// NATIVE_HALF: ret i1 %dx.any + +// DXIL_NATIVE_HALF: define noundef i1 @ +// SPIR_NATIVE_HALF: define spir_func noundef i1 @ +// DXIL_NATIVE_HALF: %hlsl.any = call i1 @llvm.dx.any.v2i16 +// SPIR_NATIVE_HALF: %hlsl.any = call i1 @llvm.spv.any.v2i16 +// NATIVE_HALF: ret i1 %hlsl.any bool test_any_int16_t2(int16_t2 p0) { return any(p0); } -// NATIVE_HALF: define noundef i1 @ -// NATIVE_HALF: %dx.any = call i1 @llvm.dx.any.v3i16 -// NATIVE_HALF: ret i1 %dx.any + +// DXIL_NATIVE_HALF: define noundef i1 @ +// SPIR_NATIVE_HALF: define spir_func noundef i1 @ +// DXIL_NATIVE_HALF: %hlsl.any = call i1 @llvm.dx.any.v3i16 +// SPIR_NATIVE_HALF: %hlsl.any = call i1 @llvm.spv.any.v3i16 +// NA
[clang] [llvm] [ThinLTO]Record import type in GlobalValueSummary::GVFlags (PR #87597)
@@ -564,6 +581,12 @@ class GlobalValueSummary { bool canAutoHide() const { return Flags.CanAutoHide; } + bool shouldImportAsDec() const { minglotus-6 wrote: this makes sense, done. https://github.com/llvm/llvm-project/pull/87597 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ThinLTO]Record import type in GlobalValueSummary::GVFlags (PR #87597)
@@ -16,13 +16,13 @@ ^3 = gv: (guid: 2, summaries: (function: (module: ^1, flags: (linkage: external, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 0), insts: 10, calls: ((callee: ^15, relbf: 256, tail: 1) ; Summaries with different linkage types. -^4 = gv: (guid: 3, summaries: (function: (module: ^0, flags: (linkage: internal, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 1), insts: 1))) +^4 = gv: (guid: 3, summaries: (function: (module: ^0, flags: (linkage: internal, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 1, importType: definition), insts: 1))) ; Make this one an alias with a forward reference to aliasee. -^5 = gv: (guid: 4, summaries: (alias: (module: ^0, flags: (linkage: private, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 1), aliasee: ^14))) +^5 = gv: (guid: 4, summaries: (alias: (module: ^0, flags: (linkage: private, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 1, importType: definition), aliasee: ^14))) ^6 = gv: (guid: 5, summaries: (function: (module: ^0, flags: (linkage: available_externally, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 0), insts: 1))) ^7 = gv: (guid: 6, summaries: (function: (module: ^0, flags: (linkage: linkonce, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 0), insts: 1))) ^8 = gv: (guid: 7, summaries: (function: (module: ^0, flags: (linkage: linkonce_odr, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 0), insts: 1))) -^9 = gv: (guid: 8, summaries: (function: (module: ^0, flags: (linkage: weak_odr, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 1), insts: 1))) +^9 = gv: (guid: 8, summaries: (function: (module: ^0, flags: (linkage: weak_odr, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0, importType: declaration), insts: 1))) minglotus-6 wrote: ah `canAutoHide:0` -> `canAutoHide:1` is not intentional. But I agree it's better to add a new record. Done by taking `^24` and incrementing `^ID` for the rest. https://github.com/llvm/llvm-project/pull/87597 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ThinLTO]Record import type in GlobalValueSummary::GVFlags (PR #87597)
@@ -2072,6 +2072,23 @@ void LLParser::parseOptionalVisibility(unsigned &Res) { Lex.Lex(); } +static GlobalValueSummary::ImportKind +parseOptionalImportType(lltok::Kind Kind) { + GlobalValueSummary::ImportKind Res; + switch (Kind) { + default: +Res = GlobalValueSummary::Definition; minglotus-6 wrote: done, by changing `parseOptionalImportType` to a member function of `LLParser` class (from a static free function) so it could return `tokError`. https://github.com/llvm/llvm-project/pull/87597 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ThinLTO]Record import type in GlobalValueSummary::GVFlags (PR #87597)
@@ -432,6 +432,18 @@ class GlobalValueSummary { /// Sububclass discriminator (for dyn_cast<> et al.) enum SummaryKind : unsigned { AliasKind, FunctionKind, GlobalVarKind }; + enum ImportKind : unsigned { +// The global value definition corresponding to the summary should be +// imported from source module +Definition = 0, + +// When its definition doesn't exist in the destination module and not +// imported (e.g., function is large to be inlined), the global value minglotus-6 wrote: done. https://github.com/llvm/llvm-project/pull/87597 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ThinLTO]Record import type in GlobalValueSummary::GVFlags (PR #87597)
@@ -635,7 +635,8 @@ static void computeFunctionSummary( HasIndirBranchToBlockAddress || HasIFuncCall; GlobalValueSummary::GVFlags Flags( F.getLinkage(), F.getVisibility(), NotEligibleForImport, - /* Live = */ false, F.isDSOLocal(), F.canBeOmittedFromSymbolTable()); + /* Live = */ false, F.isDSOLocal(), F.canBeOmittedFromSymbolTable(), + /*ImportType=*/GlobalValueSummary::ImportKind::Definition); minglotus-6 wrote: done. Fixed all callsites of `GVFlags` constructor. https://github.com/llvm/llvm-project/pull/87597 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ThinLTO]Record import type in GlobalValueSummary::GVFlags (PR #87597)
minglotus-6 wrote: Resolve review feedback, and 'backfilled' three affected tests in `clang/test/CodeGen`. Now `ninja check-llvm check-clang check-compiler-rt` passed locally. https://github.com/llvm/llvm-project/pull/87597 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Remove an unnecessary .ll file in clang/test/SemaHLSL/. (PR #87346)
https://github.com/bogner approved this pull request. https://github.com/llvm/llvm-project/pull/87346 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] NFC: Make clang resource headers an interface library (PR #88317)
https://github.com/etcwilde updated https://github.com/llvm/llvm-project/pull/88317 >From 753df93a4fc054328c0b7caacc1064c283ced8ec Mon Sep 17 00:00:00 2001 From: Evan Wilde Date: Thu, 14 Mar 2024 18:11:24 -0700 Subject: [PATCH] Make clang resource headers an interface library Making the clang resource headers into an interface library means that we can attach the header search paths to the library. Targets that "link" against this library will automatically have the appropriate paths added to their header search paths to find them. --- clang/lib/Headers/CMakeLists.txt | 8 ++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/clang/lib/Headers/CMakeLists.txt b/clang/lib/Headers/CMakeLists.txt index 97104ccd8db59c..e6ae4e19e81db9 100644 --- a/clang/lib/Headers/CMakeLists.txt +++ b/clang/lib/Headers/CMakeLists.txt @@ -437,14 +437,14 @@ foreach( f ${generated_files} ) endforeach( f ) function(add_header_target target_name file_list) - add_custom_target(${target_name} DEPENDS ${file_list}) + add_library(${target_name} INTERFACE ${file_list}) set_target_properties(${target_name} PROPERTIES FOLDER "Misc" RUNTIME_OUTPUT_DIRECTORY "${output_dir}") endfunction() # The catch-all clang-resource-headers target -add_custom_target("clang-resource-headers" ALL DEPENDS ${out_files}) +add_library(clang-resource-headers INTERFACE ${out_files}) set_target_properties("clang-resource-headers" PROPERTIES FOLDER "Misc" RUNTIME_OUTPUT_DIRECTORY "${output_dir}") @@ -501,6 +501,10 @@ add_header_target("windows-resource-headers" ${windows_only_files}) add_header_target("utility-resource-headers" ${utility_files}) get_clang_resource_dir(header_install_dir SUBDIR include) +target_include_directories(clang-resource-headers INTERFACE + $ + $) +set_property(GLOBAL APPEND PROPERTY CLANG_EXPORTS clang-resource-headers) # # Install rules for the catch-all clang-resource-headers target ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang][deps] Overload `Filesystem::exists` in `DependencyScanningFilesystem` to have it use cached `status` (PR #88152)
jansvoboda11 wrote: I'd like to see a unit test specific to `DependencyScanningFilesystem`, similar to what I have here: https://github.com/llvm/llvm-project/pull/68645. https://github.com/llvm/llvm-project/pull/88152 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang][deps] Overload `Filesystem::exists` in `DependencyScanningFilesystem` to have it use cached `status` (PR #88152)
jansvoboda11 wrote: > Not sure @jansvoboda11 perhaps if we want to cherry pick > [b768a8c](https://github.com/llvm/llvm-project/commit/b768a8c1db85b9e84fd8b356570a3a8fbe37acf6) > on `release/18.x`? Or should we land just a simple PR with just the function > change above? I can try pulling b768a8c1db85b9e84fd8b356570a3a8fbe37acf6 into the release branch. https://github.com/llvm/llvm-project/pull/88152 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] NFC: Make clang resource headers an interface library (PR #88317)
@@ -501,6 +501,10 @@ add_header_target("windows-resource-headers" ${windows_only_files}) add_header_target("utility-resource-headers" ${utility_files}) get_clang_resource_dir(header_install_dir SUBDIR include) +target_include_directories(clang-resource-headers INTERFACE + $ etcwilde wrote: Good point. I think I was trying to see if I could remove one set of header copies, but didn't actually remove that bit. Let me point it at the intermediate directory in the build directory instead which should only contain the headers for the targets we've configured LLVM for. https://github.com/llvm/llvm-project/pull/88317 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Extend lifetime of temporaries in mem-default-init for P2718R0 (PR #86960)
@@ -1230,11 +1230,26 @@ CodeGenFunction::EmitCXXForRangeStmt(const CXXForRangeStmt &S, JumpDest LoopExit = getJumpDestInCurrentScope("for.end"); LexicalScope ForScope(*this, S.getSourceRange()); + const DeclStmt *RangeDS = cast(S.getRangeStmt()); + const VarDecl *RangeVar = cast(RangeDS->getSingleDecl()); + if (getLangOpts().CPlusPlus23) efriedma-quic wrote: Oh, so it's actually supposed to say "If a temporary expression is bound to a reference member from a default member initializer, and that member initializer is used by a constructor, the constructor is ill-formed" or something like that? I guess that makes sense in context, but the language could be improved. Back to the issue we were discussing here, when are the destructors for non-lifetime-extended temporaries supposed to run? If they're supposed to stay live for the whole expression, probably the rewriting code in Sema should just rewrite out the ExprWithCleanups. If they're supposed to be destroyed, you might need to add a special-case to ExprWithCleanups handling to special-case the cleanups for the temporaries that are supposed to be lifetime-extended. (If you're going to touch this code, make sure you're working on latest main, since #85398 landed recently.) https://github.com/llvm/llvm-project/pull/86960 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang][deps] Overload `Filesystem::exists` in `DependencyScanningFilesystem` to have it use cached `status` (PR #88152)
@@ -201,6 +201,21 @@ class ErrorDummyFileSystem : public DummyFileSystem { } }; +/// A version of \c DummyFileSystem that aborts on \c status() to test that +/// \c exists() is being used. +class NoStatusDummyFileSystem : public DummyFileSystem { +public: + ErrorOr status(const Twine &Path) override { +llvm::report_fatal_error( +"unexpected call to NoStatusDummyFileSystem::status"); + } + + bool exists(const Twine &Path) override { +auto Status = DummyFileSystem::status(Path); aganea wrote: Explicit return type here too. https://github.com/llvm/llvm-project/pull/88152 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang][deps] Overload `Filesystem::exists` in `DependencyScanningFilesystem` to have it use cached `status` (PR #88152)
https://github.com/aganea approved this pull request. Otherwise this PR LGTM. https://github.com/llvm/llvm-project/pull/88152 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang][deps] Overload `Filesystem::exists` in `DependencyScanningFilesystem` to have it use cached `status` (PR #88152)
https://github.com/aganea edited https://github.com/llvm/llvm-project/pull/88152 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang][deps] Overload `Filesystem::exists` in `DependencyScanningFilesystem` to have it use cached `status` (PR #88152)
aganea wrote: > This patch doesn`t improve my usage, it seems I'm hitting a different > codepath than you do. I'll investigate. Ah I see, the commit https://github.com/llvm/llvm-project/commit/b768a8c1db85b9e84fd8b356570a3a8fbe37acf6 didn't make it in time for the 18.x branch. The issue I'm seeing here is with regular C++ code, no PCH, no modules. It is related to `shouldCacheStatFailures()` which currently in `release/18.x` happens to return `false` for directories. The searching behavior for `#include` files with `clang-cl` (not sure about plain clang) is essentially to query every include path passed on the command-line. That creates lots of OS `status()` calls, like shown in my profile above. Going back to the previous behavior as on `main` solves my issue, ie: ``` static bool shouldCacheStatFailures(StringRef Filename) { StringRef Ext = llvm::sys::path::extension(Filename); if (Ext.empty()) return false; // This may be the module cache directory. return true; } ``` As an order of magnitude, the Unreal Engine target I'm testing consists of 17,801 TUs, generating 1,2 billion status() calls in total (by counting the calls to `FileManager::getStatValue`) out of which 8,3 millions are real OS calls after the change above (by counting the calls to `llvm::sys::windows::status()`. Not sure @jansvoboda11 perhaps if we want to cherry pick b768a8c1db85b9e84fd8b356570a3a8fbe37acf6 on `release/18.x`? Or should we land just a simple PR with just the function change above? https://github.com/llvm/llvm-project/pull/88152 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] NFC: Make clang resource headers an interface library (PR #88317)
@@ -501,6 +501,10 @@ add_header_target("windows-resource-headers" ${windows_only_files}) add_header_target("utility-resource-headers" ${utility_files}) get_clang_resource_dir(header_install_dir SUBDIR include) +target_include_directories(clang-resource-headers INTERFACE + $ compnerd wrote: Do we need to worry about other files accidentally being made visible by using the source directory? https://github.com/llvm/llvm-project/pull/88317 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] NFC: Make clang resource headers an interface library (PR #88317)
https://github.com/compnerd approved this pull request. This seems like a step in the right direction - avoiding custom targets is generally better. https://github.com/llvm/llvm-project/pull/88317 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] NFC: Make clang resource headers an interface library (PR #88317)
https://github.com/compnerd edited https://github.com/llvm/llvm-project/pull/88317 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits