[llvm] [clang] [NFC] Remove Type::getInt8PtrTy (PR #71029)
https://github.com/pmatos created https://github.com/llvm/llvm-project/pull/71029 Replace this with PointerType::get(). Also adds AS = 0 as an optional argument to get() methods. >From 28745bc7877747f998f658ee2f661f8312c54814 Mon Sep 17 00:00:00 2001 From: Paulo Matos Date: Thu, 2 Nov 2023 08:11:25 +0100 Subject: [PATCH] [NFC] Remove Type::getInt8PtrTy Replace this with PointerType::get(). Also adds AS = 0 as an optional argument to get() methods. --- clang/lib/CodeGen/CGGPUBuiltin.cpp| 12 ++--- clang/lib/CodeGen/CodeGenPGO.cpp | 2 +- clang/lib/CodeGen/CodeGenTypes.cpp| 2 +- clang/lib/CodeGen/CoverageMappingGen.cpp | 2 +- .../clang-linker-wrapper/OffloadWrapper.cpp | 38 +++ llvm/examples/BrainF/BrainF.cpp | 2 +- llvm/include/llvm/IR/DerivedTypes.h | 8 ++-- llvm/include/llvm/IR/Type.h | 4 -- .../llvm/ProfileData/InstrProfData.inc| 12 ++--- llvm/lib/Analysis/StackSafetyAnalysis.cpp | 4 +- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 2 +- llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp| 2 +- llvm/lib/CodeGen/DwarfEHPrepare.cpp | 4 +- llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp | 8 ++-- llvm/lib/CodeGen/SafeStack.cpp| 2 +- llvm/lib/CodeGen/ShadowStackGCLowering.cpp| 2 +- llvm/lib/CodeGen/SjLjEHPrepare.cpp| 2 +- llvm/lib/CodeGen/StackProtector.cpp | 4 +- llvm/lib/CodeGen/TargetLoweringBase.cpp | 8 ++-- llvm/lib/ExecutionEngine/ExecutionEngine.cpp | 2 +- llvm/lib/Frontend/Offloading/Utility.cpp | 4 +- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp | 14 +++--- llvm/lib/IR/Type.cpp | 4 -- .../Target/AArch64/AArch64ISelLowering.cpp| 4 +- .../AMDGPU/AMDGPULowerModuleLDSPass.cpp | 2 +- .../AMDGPUOpenCLEnqueuedBlockLowering.cpp | 2 +- llvm/lib/Target/ARM/ARMISelLowering.cpp | 4 +- .../Target/BPF/BPFAbstractMemberAccess.cpp| 2 +- llvm/lib/Target/DirectX/DXILOpBuilder.cpp | 2 +- llvm/lib/Target/PowerPC/PPCISelLowering.cpp | 2 +- llvm/lib/Target/X86/X86ISelLowering.cpp | 4 +- llvm/lib/Target/X86/X86ISelLoweringCall.cpp | 4 +- llvm/lib/Target/X86/X86WinEHState.cpp | 12 ++--- llvm/lib/Target/XCore/XCoreISelLowering.cpp | 2 +- llvm/lib/Transforms/CFGuard/CFGuard.cpp | 2 +- llvm/lib/Transforms/Coroutines/CoroElide.cpp | 2 +- llvm/lib/Transforms/Coroutines/CoroInstr.h| 4 +- llvm/lib/Transforms/Coroutines/CoroSplit.cpp | 8 ++-- .../Instrumentation/AddressSanitizer.cpp | 4 +- .../Instrumentation/DataFlowSanitizer.cpp | 8 ++-- .../Instrumentation/GCOVProfiling.cpp | 2 +- .../Instrumentation/InstrProfiling.cpp| 10 ++-- .../Instrumentation/PGOInstrumentation.cpp| 2 +- .../Transforms/Scalar/LoopDataPrefetch.cpp| 2 +- .../Scalar/RewriteStatepointsForGC.cpp| 2 +- .../Scalar/StraightLineStrengthReduce.cpp | 2 +- llvm/lib/Transforms/Utils/CodeExtractor.cpp | 2 +- .../Utils/EntryExitInstrumenter.cpp | 4 +- .../lib/Transforms/Utils/EscapeEnumerator.cpp | 2 +- llvm/lib/Transforms/Utils/InlineFunction.cpp | 2 +- .../lib/Transforms/Utils/LowerGlobalDtors.cpp | 2 +- llvm/lib/Transforms/Utils/ModuleUtils.cpp | 2 +- llvm/lib/Transforms/Utils/SanitizerStats.cpp | 6 +-- llvm/tools/bugpoint/Miscompilation.cpp| 4 +- .../Analysis/CGSCCPassManagerTest.cpp | 16 +++ llvm/unittests/Analysis/LazyCallGraphTest.cpp | 48 +-- .../unittests/Analysis/MemoryBuiltinsTest.cpp | 2 +- .../Analysis/ScalarEvolutionTest.cpp | 2 +- .../Frontend/OpenMPIRBuilderTest.cpp | 4 +- llvm/unittests/FuzzMutate/OperationsTest.cpp | 4 +- llvm/unittests/Linker/LinkModulesTest.cpp | 14 +++--- 61 files changed, 169 insertions(+), 177 deletions(-) diff --git a/clang/lib/CodeGen/CGGPUBuiltin.cpp b/clang/lib/CodeGen/CGGPUBuiltin.cpp index 75fb06de938425d..db6d80f7e0d87e6 100644 --- a/clang/lib/CodeGen/CGGPUBuiltin.cpp +++ b/clang/lib/CodeGen/CGGPUBuiltin.cpp @@ -23,8 +23,8 @@ using namespace CodeGen; namespace { llvm::Function *GetVprintfDeclaration(llvm::Module &M) { - llvm::Type *ArgTypes[] = {llvm::Type::getInt8PtrTy(M.getContext()), -llvm::Type::getInt8PtrTy(M.getContext())}; + llvm::Type *ArgTypes[] = {llvm::PointerType::get(M.getContext()), +llvm::PointerType::get(M.getContext())}; llvm::FunctionType *VprintfFuncType = llvm::FunctionType::get( llvm::Type::getInt32Ty(M.getContext()), ArgTypes, false); @@ -45,8 +45,8 @@ llvm::Function *GetVprintfDeclaration(llvm::Module &M) { llvm::Function *GetOpenMPVprintfDeclaration(CodeGenModule &CGM) { const char *Name = "__llvm_omp_vprintf"; llvm::Module &M = CGM.getModule(); - llvm::Type *ArgTypes[] = {llvm::Type::getInt8PtrTy(M.getContext()), -
[clang] [llvm] [NFC] Remove Type::getInt8PtrTy (PR #71029)
llvmbot wrote: @llvm/pr-subscribers-backend-aarch64 @llvm/pr-subscribers-clang Author: Paulo Matos (pmatos) Changes Replace this with PointerType::get(). Also adds AS = 0 as an optional argument to get() methods. --- Patch is 81.99 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/71029.diff 61 Files Affected: - (modified) clang/lib/CodeGen/CGGPUBuiltin.cpp (+6-6) - (modified) clang/lib/CodeGen/CodeGenPGO.cpp (+1-1) - (modified) clang/lib/CodeGen/CodeGenTypes.cpp (+1-1) - (modified) clang/lib/CodeGen/CoverageMappingGen.cpp (+1-1) - (modified) clang/tools/clang-linker-wrapper/OffloadWrapper.cpp (+19-19) - (modified) llvm/examples/BrainF/BrainF.cpp (+1-1) - (modified) llvm/include/llvm/IR/DerivedTypes.h (+4-4) - (modified) llvm/include/llvm/IR/Type.h (-4) - (modified) llvm/include/llvm/ProfileData/InstrProfData.inc (+6-6) - (modified) llvm/lib/Analysis/StackSafetyAnalysis.cpp (+2-2) - (modified) llvm/lib/Bitcode/Writer/BitcodeWriter.cpp (+1-1) - (modified) llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (+1-1) - (modified) llvm/lib/CodeGen/DwarfEHPrepare.cpp (+2-2) - (modified) llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp (+4-4) - (modified) llvm/lib/CodeGen/SafeStack.cpp (+1-1) - (modified) llvm/lib/CodeGen/ShadowStackGCLowering.cpp (+1-1) - (modified) llvm/lib/CodeGen/SjLjEHPrepare.cpp (+1-1) - (modified) llvm/lib/CodeGen/StackProtector.cpp (+2-2) - (modified) llvm/lib/CodeGen/TargetLoweringBase.cpp (+4-4) - (modified) llvm/lib/ExecutionEngine/ExecutionEngine.cpp (+1-1) - (modified) llvm/lib/Frontend/Offloading/Utility.cpp (+2-2) - (modified) llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp (+7-7) - (modified) llvm/lib/IR/Type.cpp (-4) - (modified) llvm/lib/Target/AArch64/AArch64ISelLowering.cpp (+2-2) - (modified) llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp (+1-1) - (modified) llvm/lib/Target/AMDGPU/AMDGPUOpenCLEnqueuedBlockLowering.cpp (+1-1) - (modified) llvm/lib/Target/ARM/ARMISelLowering.cpp (+2-2) - (modified) llvm/lib/Target/BPF/BPFAbstractMemberAccess.cpp (+1-1) - (modified) llvm/lib/Target/DirectX/DXILOpBuilder.cpp (+1-1) - (modified) llvm/lib/Target/PowerPC/PPCISelLowering.cpp (+1-1) - (modified) llvm/lib/Target/X86/X86ISelLowering.cpp (+2-2) - (modified) llvm/lib/Target/X86/X86ISelLoweringCall.cpp (+2-2) - (modified) llvm/lib/Target/X86/X86WinEHState.cpp (+6-6) - (modified) llvm/lib/Target/XCore/XCoreISelLowering.cpp (+1-1) - (modified) llvm/lib/Transforms/CFGuard/CFGuard.cpp (+1-1) - (modified) llvm/lib/Transforms/Coroutines/CoroElide.cpp (+1-1) - (modified) llvm/lib/Transforms/Coroutines/CoroInstr.h (+2-2) - (modified) llvm/lib/Transforms/Coroutines/CoroSplit.cpp (+4-4) - (modified) llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp (+2-2) - (modified) llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp (+4-4) - (modified) llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp (+1-1) - (modified) llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp (+5-5) - (modified) llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp (+1-1) - (modified) llvm/lib/Transforms/Scalar/LoopDataPrefetch.cpp (+1-1) - (modified) llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp (+1-1) - (modified) llvm/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp (+1-1) - (modified) llvm/lib/Transforms/Utils/CodeExtractor.cpp (+1-1) - (modified) llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp (+2-2) - (modified) llvm/lib/Transforms/Utils/EscapeEnumerator.cpp (+1-1) - (modified) llvm/lib/Transforms/Utils/InlineFunction.cpp (+1-1) - (modified) llvm/lib/Transforms/Utils/LowerGlobalDtors.cpp (+1-1) - (modified) llvm/lib/Transforms/Utils/ModuleUtils.cpp (+1-1) - (modified) llvm/lib/Transforms/Utils/SanitizerStats.cpp (+3-3) - (modified) llvm/tools/bugpoint/Miscompilation.cpp (+2-2) - (modified) llvm/unittests/Analysis/CGSCCPassManagerTest.cpp (+8-8) - (modified) llvm/unittests/Analysis/LazyCallGraphTest.cpp (+24-24) - (modified) llvm/unittests/Analysis/MemoryBuiltinsTest.cpp (+1-1) - (modified) llvm/unittests/Analysis/ScalarEvolutionTest.cpp (+1-1) - (modified) llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp (+2-2) - (modified) llvm/unittests/FuzzMutate/OperationsTest.cpp (+2-2) - (modified) llvm/unittests/Linker/LinkModulesTest.cpp (+7-7) ``diff diff --git a/clang/lib/CodeGen/CGGPUBuiltin.cpp b/clang/lib/CodeGen/CGGPUBuiltin.cpp index 75fb06de938425d..db6d80f7e0d87e6 100644 --- a/clang/lib/CodeGen/CGGPUBuiltin.cpp +++ b/clang/lib/CodeGen/CGGPUBuiltin.cpp @@ -23,8 +23,8 @@ using namespace CodeGen; namespace { llvm::Function *GetVprintfDeclaration(llvm::Module &M) { - llvm::Type *ArgTypes[] = {llvm::Type::getInt8PtrTy(M.getContext()), -llvm::Type::getInt8PtrTy(M.getContext())}; + llvm::Type *ArgTypes[] = {llvm::PointerType::get(M.getContext()), +llvm::PointerType::get(M.getContext())}; llvm::FunctionType *VprintfFunc
[clang] [llvm] [NFC] Remove Type::getInt8PtrTy (PR #71029)
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 e98195f318375978e3e0b153cade8bb3a05029bb 28745bc7877747f998f658ee2f661f8312c54814 -- clang/lib/CodeGen/CGGPUBuiltin.cpp clang/lib/CodeGen/CodeGenPGO.cpp clang/lib/CodeGen/CodeGenTypes.cpp clang/lib/CodeGen/CoverageMappingGen.cpp clang/tools/clang-linker-wrapper/OffloadWrapper.cpp llvm/examples/BrainF/BrainF.cpp llvm/include/llvm/IR/DerivedTypes.h llvm/include/llvm/IR/Type.h llvm/lib/Analysis/StackSafetyAnalysis.cpp llvm/lib/Bitcode/Writer/BitcodeWriter.cpp llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp llvm/lib/CodeGen/DwarfEHPrepare.cpp llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp llvm/lib/CodeGen/SafeStack.cpp llvm/lib/CodeGen/ShadowStackGCLowering.cpp llvm/lib/CodeGen/SjLjEHPrepare.cpp llvm/lib/CodeGen/StackProtector.cpp llvm/lib/CodeGen/TargetLoweringBase.cpp llvm/lib/ExecutionEngine/ExecutionEngine.cpp llvm/lib/Frontend/Offloading/Utility.cpp llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp llvm/lib/IR/Type.cpp llvm/lib/Target/AArch64/AArch64ISelLowering.cpp llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp llvm/lib/Target/AMDGPU/AMDGPUOpenCLEnqueuedBlockLowering.cpp llvm/lib/Target/ARM/ARMISelLowering.cpp llvm/lib/Target/BPF/BPFAbstractMemberAccess.cpp llvm/lib/Target/DirectX/DXILOpBuilder.cpp llvm/lib/Target/PowerPC/PPCISelLowering.cpp llvm/lib/Target/X86/X86ISelLowering.cpp llvm/lib/Target/X86/X86ISelLoweringCall.cpp llvm/lib/Target/X86/X86WinEHState.cpp llvm/lib/Target/XCore/XCoreISelLowering.cpp llvm/lib/Transforms/CFGuard/CFGuard.cpp llvm/lib/Transforms/Coroutines/CoroElide.cpp llvm/lib/Transforms/Coroutines/CoroInstr.h llvm/lib/Transforms/Coroutines/CoroSplit.cpp llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp llvm/lib/Transforms/Scalar/LoopDataPrefetch.cpp llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp llvm/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp llvm/lib/Transforms/Utils/CodeExtractor.cpp llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp llvm/lib/Transforms/Utils/EscapeEnumerator.cpp llvm/lib/Transforms/Utils/InlineFunction.cpp llvm/lib/Transforms/Utils/LowerGlobalDtors.cpp llvm/lib/Transforms/Utils/ModuleUtils.cpp llvm/lib/Transforms/Utils/SanitizerStats.cpp llvm/tools/bugpoint/Miscompilation.cpp llvm/unittests/Analysis/CGSCCPassManagerTest.cpp llvm/unittests/Analysis/LazyCallGraphTest.cpp llvm/unittests/Analysis/MemoryBuiltinsTest.cpp llvm/unittests/Analysis/ScalarEvolutionTest.cpp llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp llvm/unittests/FuzzMutate/OperationsTest.cpp llvm/unittests/Linker/LinkModulesTest.cpp `` View the diff from clang-format here. ``diff diff --git a/clang/lib/CodeGen/CGGPUBuiltin.cpp b/clang/lib/CodeGen/CGGPUBuiltin.cpp index db6d80f7e0d8..b013299181a8 100644 --- a/clang/lib/CodeGen/CGGPUBuiltin.cpp +++ b/clang/lib/CodeGen/CGGPUBuiltin.cpp @@ -99,7 +99,8 @@ packArgsIntoNVPTXFormatBuffer(CodeGenFunction *CGF, const CallArgList &Args) { // Construct and fill the args buffer that we'll pass to vprintf. if (Args.size() <= 1) { // If there are no args, pass a null pointer and size 0 -llvm::Value * BufferPtr = llvm::ConstantPointerNull::get(llvm::PointerType::get(Ctx)); +llvm::Value *BufferPtr = +llvm::ConstantPointerNull::get(llvm::PointerType::get(Ctx)); return {BufferPtr, llvm::TypeSize::Fixed(0)}; } else { llvm::SmallVector ArgTypes; diff --git a/clang/lib/CodeGen/CodeGenPGO.cpp b/clang/lib/CodeGen/CodeGenPGO.cpp index 7dc618d9c422..796993f6b6d1 100644 --- a/clang/lib/CodeGen/CodeGenPGO.cpp +++ b/clang/lib/CodeGen/CodeGenPGO.cpp @@ -1004,8 +1004,7 @@ void CodeGenPGO::valueProfile(CGBuilderTy &Builder, uint32_t ValueKind, Builder.getInt64(FunctionHash), Builder.CreatePtrToInt(ValuePtr, Builder.getInt64Ty()), Builder.getInt32(ValueKind), -Builder.getInt32(NumValueSites[ValueKind]++) -}; +Builder.getInt32(NumValueSites[ValueKind]++)}; Builder.CreateCall( CGM.getIntrinsic(llvm::Intrinsic::instrprof_value_profile), Args); Builder.restoreIP(BuilderInsertPoint); diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp b/clang/lib/CodeGen/CoverageMappingGen.cpp index 50364964259f..4bb9bd823352 100644 --- a/clang/lib/CodeGen/CoverageMappingGen.cpp +++ b/clang/lib/CodeGen/CoverageMappingGen.cpp @@ -1820,8 +1820,8 @@ void CoverageMappingModuleGen::emit() { CGM.addUsedGlobal(CovData); // Create the deferred function records array if (!FunctionNames.empty()) { -auto NamesArrTy = llvm::ArrayType::get(llvm::PointerType::get(Ctx), -
[clang] [llvm] [PowerPC] Add an alias for -mregnames so that full register names used in assembly. (PR #70255)
@@ -197,6 +197,7 @@ CODEGENOPT(HIPCorrectlyRoundedDivSqrt, 1, 1) ///< -fno-hip-fp32-correctly-rounde CODEGENOPT(HIPSaveKernelArgName, 1, 0) ///< Set when -fhip-kernel-arg-name is enabled. CODEGENOPT(UniqueInternalLinkageNames, 1, 0) ///< Internal Linkage symbols get unique names. CODEGENOPT(SplitMachineFunctions, 1, 0) ///< Split machine functions using profile information. +CODEGENOPT(UseFullRegisterNames, 1, 0) ///< Print full register names in assembly -mregnames MaskRay wrote: `PPCUseFullRegisterNames` or `PPCFullRegisterNames` This is rs6000-specific in gcc. https://github.com/llvm/llvm-project/pull/70255 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C++20] [Modules] Don't import function bodies from other module units even with optimizations (PR #71031)
https://github.com/ChuanqiXu9 created https://github.com/llvm/llvm-project/pull/71031 Close https://github.com/llvm/llvm-project/issues/60996. Previously, clang will try to import function bodies from other module units to get more optimization oppotunities as much as possible. Then the motivation becomes the direct cause of the above issue. However, according to the discussion in SG15, the behavior of importing function bodies from other module units breaks the ABI compatibility. It is unwanted. So the original behavior of clang is incorrect. This patch choose to not import function bodies from other module units in all cases to follow the expectation. Note that the desired optimized BMI idea is discarded too. Since it will still break the ABI compatibility after we import function bodies seperately. The release note will be added seperately. There is a similar issue for variable definitions. I'll try to handle that in a different commit. >From 427c1e1960d48e8803e235b4d5beb437ea21c942 Mon Sep 17 00:00:00 2001 From: Chuanqi Xu Date: Thu, 2 Nov 2023 15:19:58 +0800 Subject: [PATCH] [C++20] [Modules] Don't import function bodies from other module units even with optimizations Close https://github.com/llvm/llvm-project/issues/60996. Previously, clang will try to import function bodies from other module units to get more optimization oppotunities as much as possible. Then the motivation becomes the direct cause of the above issue. However, according to the discussion in SG15, the behavior of importing function bodies from other module units breaks the ABI compatibility. It is unwanted. So the original behavior of clang is incorrect. This patch choose to not import function bodies from other module units in all cases to follow the expectation. Note that the desired optimized BMI idea is discarded too. Since it will still break the ABI compatibility after we import function bodies seperately. The release note will be added seperately. There is a similar issue for variable definitions. I'll try to handle that in a different commit. --- clang/lib/CodeGen/CodeGenModule.cpp | 9 +++ .../CodeGenCXX/module-funcs-from-imports.cppm | 10 +-- clang/test/CodeGenCXX/partitions.cpp | 5 +- .../cxx20-importing-function-bodies.cppm | 72 +++ clang/test/Modules/no-import-func-body.cppm | 4 +- 5 files changed, 91 insertions(+), 9 deletions(-) create mode 100644 clang/test/Modules/cxx20-importing-function-bodies.cppm diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index cc81a68b15c4324..893e7643a447033 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -3856,10 +3856,19 @@ CodeGenModule::isTriviallyRecursive(const FunctionDecl *FD) { bool CodeGenModule::shouldEmitFunction(GlobalDecl GD) { if (getFunctionLinkage(GD) != llvm::Function::AvailableExternallyLinkage) return true; + const auto *F = cast(GD.getDecl()); if (CodeGenOpts.OptimizationLevel == 0 && !F->hasAttr()) return false; + // We don't import function bodies from other named module units since that + // behavior may break ABI compatibility of the current unit. + Module *M = F->getOwningModule(); + if (M && M->isModulePurview() && + getContext().getCurrentNamedModule() != M->getTopLevelModule() && + !F->hasAttr()) +return false; + if (F->hasAttr()) return false; diff --git a/clang/test/CodeGenCXX/module-funcs-from-imports.cppm b/clang/test/CodeGenCXX/module-funcs-from-imports.cppm index 3b415bd9c457291..33cdf437110a9e8 100644 --- a/clang/test/CodeGenCXX/module-funcs-from-imports.cppm +++ b/clang/test/CodeGenCXX/module-funcs-from-imports.cppm @@ -64,13 +64,13 @@ int use() { // CHECK-O0-NOT: non_exported_func_not_called // CHECK-O0-NOT: func_not_called -// Checks that all the potentially called function in the importees are generated in the importer's code -// with available_externally attribute. +// Checks that the generated code within optimizations keep the same behavior with +// O0 to keep consistent ABI. // CHECK-O1: define{{.*}}_Z3usev( -// CHECK-O1: define{{.*}}available_externally{{.*}}_ZW1M13exported_funcv( +// CHECK-O1: declare{{.*}}_ZW1M13exported_funcv( // CHECK-O1: define{{.*}}available_externally{{.*}}_ZW1M18always_inline_funcv( -// CHECK-O1: define{{.*}}available_externally{{.*}}_ZW1M17non_exported_funcv( -// CHECK-O1: define{{.*}}available_externally{{.*}}_Z11func_in_gmfv( +// CHECK-O1-NOT: func_in_gmf // CHECK-O1-NOT: func_in_gmf_not_called +// CHECK-O1-NOT: non_exported_func // CHECK-O1-NOT: non_exported_func_not_called // CHECK-O1-NOT: func_not_called diff --git a/clang/test/CodeGenCXX/partitions.cpp b/clang/test/CodeGenCXX/partitions.cpp index 865af5f161eff11..b58e88fafdc6b15 100644 --- a/clang/test/CodeGenCXX/partitions.cpp +++ b/clang/test/CodeGenCXX/partitions.cpp @@ -39,6 +39,7 @@ export int use() { return foo() + bar() + a + b;
[clang] [C++20] [Modules] Don't import function bodies from other module units even with optimizations (PR #71031)
llvmbot wrote: @llvm/pr-subscribers-clang-modules Author: Chuanqi Xu (ChuanqiXu9) Changes Close https://github.com/llvm/llvm-project/issues/60996. Previously, clang will try to import function bodies from other module units to get more optimization oppotunities as much as possible. Then the motivation becomes the direct cause of the above issue. However, according to the discussion in SG15, the behavior of importing function bodies from other module units breaks the ABI compatibility. It is unwanted. So the original behavior of clang is incorrect. This patch choose to not import function bodies from other module units in all cases to follow the expectation. Note that the desired optimized BMI idea is discarded too. Since it will still break the ABI compatibility after we import function bodies seperately. The release note will be added seperately. There is a similar issue for variable definitions. I'll try to handle that in a different commit. --- Full diff: https://github.com/llvm/llvm-project/pull/71031.diff 5 Files Affected: - (modified) clang/lib/CodeGen/CodeGenModule.cpp (+9) - (modified) clang/test/CodeGenCXX/module-funcs-from-imports.cppm (+5-5) - (modified) clang/test/CodeGenCXX/partitions.cpp (+3-2) - (added) clang/test/Modules/cxx20-importing-function-bodies.cppm (+72) - (modified) clang/test/Modules/no-import-func-body.cppm (+2-2) ``diff diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index cc81a68b15c4324..893e7643a447033 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -3856,10 +3856,19 @@ CodeGenModule::isTriviallyRecursive(const FunctionDecl *FD) { bool CodeGenModule::shouldEmitFunction(GlobalDecl GD) { if (getFunctionLinkage(GD) != llvm::Function::AvailableExternallyLinkage) return true; + const auto *F = cast(GD.getDecl()); if (CodeGenOpts.OptimizationLevel == 0 && !F->hasAttr()) return false; + // We don't import function bodies from other named module units since that + // behavior may break ABI compatibility of the current unit. + Module *M = F->getOwningModule(); + if (M && M->isModulePurview() && + getContext().getCurrentNamedModule() != M->getTopLevelModule() && + !F->hasAttr()) +return false; + if (F->hasAttr()) return false; diff --git a/clang/test/CodeGenCXX/module-funcs-from-imports.cppm b/clang/test/CodeGenCXX/module-funcs-from-imports.cppm index 3b415bd9c457291..33cdf437110a9e8 100644 --- a/clang/test/CodeGenCXX/module-funcs-from-imports.cppm +++ b/clang/test/CodeGenCXX/module-funcs-from-imports.cppm @@ -64,13 +64,13 @@ int use() { // CHECK-O0-NOT: non_exported_func_not_called // CHECK-O0-NOT: func_not_called -// Checks that all the potentially called function in the importees are generated in the importer's code -// with available_externally attribute. +// Checks that the generated code within optimizations keep the same behavior with +// O0 to keep consistent ABI. // CHECK-O1: define{{.*}}_Z3usev( -// CHECK-O1: define{{.*}}available_externally{{.*}}_ZW1M13exported_funcv( +// CHECK-O1: declare{{.*}}_ZW1M13exported_funcv( // CHECK-O1: define{{.*}}available_externally{{.*}}_ZW1M18always_inline_funcv( -// CHECK-O1: define{{.*}}available_externally{{.*}}_ZW1M17non_exported_funcv( -// CHECK-O1: define{{.*}}available_externally{{.*}}_Z11func_in_gmfv( +// CHECK-O1-NOT: func_in_gmf // CHECK-O1-NOT: func_in_gmf_not_called +// CHECK-O1-NOT: non_exported_func // CHECK-O1-NOT: non_exported_func_not_called // CHECK-O1-NOT: func_not_called diff --git a/clang/test/CodeGenCXX/partitions.cpp b/clang/test/CodeGenCXX/partitions.cpp index 865af5f161eff11..b58e88fafdc6b15 100644 --- a/clang/test/CodeGenCXX/partitions.cpp +++ b/clang/test/CodeGenCXX/partitions.cpp @@ -39,6 +39,7 @@ export int use() { return foo() + bar() + a + b; } +// FIXME: The definition of the variables shouldn't be exported too. // CHECK: @_ZW3mod1a = available_externally global // CHECK: @_ZW3mod1b = available_externally global // CHECK: declare{{.*}} i32 @_ZW3mod3foov @@ -46,5 +47,5 @@ export int use() { // CHECK-OPT: @_ZW3mod1a = available_externally global // CHECK-OPT: @_ZW3mod1b = available_externally global -// CHECK-OPT: define available_externally{{.*}} i32 @_ZW3mod3foov -// CHECK-OPT: define available_externally{{.*}} i32 @_ZW3mod3barv +// CHECK-OPT: declare{{.*}} i32 @_ZW3mod3foov +// CHECK-OPT: declare{{.*}} i32 @_ZW3mod3barv diff --git a/clang/test/Modules/cxx20-importing-function-bodies.cppm b/clang/test/Modules/cxx20-importing-function-bodies.cppm new file mode 100644 index 000..f1b8f9a8f0c9118 --- /dev/null +++ b/clang/test/Modules/cxx20-importing-function-bodies.cppm @@ -0,0 +1,72 @@ +// RUN: rm -rf %t +// RUN: split-file %s %t +// RUN: cd %t +// +// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/a.cppm \ +// RUN: -emit-module-interface -o %t/a.pcm +// RUN: %clang_cc1 -std=c++20 -tri
[clang] [C++20] [Modules] Warn if we found #include in module purview (PR #69555)
ChuanqiXu9 wrote: I'd like to land this next week if no objection comes in. Since the `frameworks` looks not intended to be the places too. https://github.com/llvm/llvm-project/pull/69555 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [PowerPC] Add an alias for -mregnames so that full register names used in assembly. (PR #70255)
@@ -5011,6 +5011,12 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, Args.AddLastArg(CmdArgs, options::OPT_fthinlto_index_EQ); } + if (const Arg *A = + Args.getLastArg(options::OPT_mregnames, options::OPT_mno_regnames)) { MaskRay wrote: This will make other targets accept the ppc-specific -mregnames https://github.com/llvm/llvm-project/pull/70255 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 3bc056d - [clang-repl] [test] Make an XFAIL more precise (#70991)
Author: Martin Storsjö Date: 2023-11-02T09:51:33+02:00 New Revision: 3bc056d5f0ebe9e4074afa088c3a0355f9ab901a URL: https://github.com/llvm/llvm-project/commit/3bc056d5f0ebe9e4074afa088c3a0355f9ab901a DIFF: https://github.com/llvm/llvm-project/commit/3bc056d5f0ebe9e4074afa088c3a0355f9ab901a.diff LOG: [clang-repl] [test] Make an XFAIL more precise (#70991) The const.cpp testcase fails when running in MSVC mode, while it does succeed in MinGW mode. In MSVC mode, there are more constructor invocations than expected, as the printout looks like this: A(1), this = 02559793 A(1), this = 02559793 f: this = 02559793, val = 1 A(1), this = 02559793 f: this = 02559793, val = 1 ~A, this = 02559793, val = 1 ~A, this = 02559793, val = 1 ~A, this = 02559793, val = 1 While the expected printout looks like this: A(1), this = 02C903E1 f: this = 02C903E1, val = 1 f: this = 02C903E1, val = 1 ~A, this = 02C903E1, val = 1 Added: Modified: clang/test/Interpreter/const.cpp Removed: diff --git a/clang/test/Interpreter/const.cpp b/clang/test/Interpreter/const.cpp index 4b6ce65e3643e64..1412a1d85d6f58f 100644 --- a/clang/test/Interpreter/const.cpp +++ b/clang/test/Interpreter/const.cpp @@ -1,6 +1,6 @@ // UNSUPPORTED: system-aix // see https://github.com/llvm/llvm-project/issues/68092 -// XFAIL: system-windows +// XFAIL: target={{.*}}-windows-msvc // RUN: cat %s | clang-repl | FileCheck %s // RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-repl] [test] Make an XFAIL more precise (PR #70991)
https://github.com/mstorsjo closed https://github.com/llvm/llvm-project/pull/70991 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[compiler-rt] [flang] [clang] [libc] [llvm] [clang-tools-extra] [libcxx] [lldb] [PowerPC] Support mcmodel=large for AIX (PR #70652)
@@ -5723,16 +5723,14 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, if (Arg *A = Args.getLastArg(options::OPT_mcmodel_EQ)) { StringRef CM = A->getValue(); bool Ok = false; -if (Triple.isOSAIX() && CM == "medium") { +if (Triple.isOSAIX() && CM == "medium") CM = "large"; - Ok = true; -} if (Triple.isAArch64(64)) { Ok = CM == "tiny" || CM == "small" || CM == "large"; if (CM == "large" && RelocationModel != llvm::Reloc::Static) D.Diag(diag::err_drv_argument_only_allowed_with) << A->getAsString(Args) << "-fno-pic"; -} else if (Triple.isPPC64()) { +} else if (Triple.isPPC64() || Triple.isOSAIX()) { MaskRay wrote: Hi, may I ask what `-mcmodel=large` does on a 32-bit AIX? `-mcmodel=large` is generally not supported for 32-bit systems and it seems that AIX does something special here. GCC's rs6000 doc says: > Generate PowerPC64 code for the large model: The TOC may be up to 4G in size. > Other data and code is only limited by the 64-bit address space. https://github.com/llvm/llvm-project/pull/70652 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] Restrict 'fopen' & 'tmpfile' modeling to POSIX versions in StreamChecker (PR #70540)
https://github.com/balazske edited https://github.com/llvm/llvm-project/pull/70540 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] Restrict 'fopen' & 'tmpfile' modeling to POSIX versions in StreamChecker (PR #70540)
https://github.com/balazske approved this pull request. https://github.com/llvm/llvm-project/pull/70540 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] Restrict 'fopen' & 'tmpfile' modeling to POSIX versions in StreamChecker (PR #70540)
@@ -0,0 +1,16 @@ +// RUN: %clang_analyze_cc1 -fno-builtin -analyzer-checker=core,alpha.unix.Stream -verify %s +// expected-no-diagnostics + +typedef struct _FILE FILE; + +// These functions are not standard C library functions. +FILE *tmpfile(const char *restrict path); // Real 'tmpfile' should have exactly 0 formal parameters. +FILE *fopen(const char *restrict path); // Real 'fopen' should have exactly 2 formal parameters. + +void test_fopen_non_posix(void) { + FILE *fp = fopen("file"); // no-leak: this isn't the standard POSIX fopen, we don't the semantics of this call. +} + +void test_tmpfile_non_posix(void) { + FILE *fp = tmpfile("file"); // no-leak: this isn't the standard POSIX tmpfile, we don't the semantics of this call. balazske wrote: The comment looks like something is missing from it. https://github.com/llvm/llvm-project/pull/70540 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C++20] [Modules] Don't import function bodies from other module units even with optimizations (PR #71031)
@@ -3856,10 +3856,19 @@ CodeGenModule::isTriviallyRecursive(const FunctionDecl *FD) { bool CodeGenModule::shouldEmitFunction(GlobalDecl GD) { if (getFunctionLinkage(GD) != llvm::Function::AvailableExternallyLinkage) return true; + const auto *F = cast(GD.getDecl()); if (CodeGenOpts.OptimizationLevel == 0 && !F->hasAttr()) return false; + // We don't import function bodies from other named module units since that + // behavior may break ABI compatibility of the current unit. + Module *M = F->getOwningModule(); + if (M && M->isModulePurview() && + getContext().getCurrentNamedModule() != M->getTopLevelModule() && + !F->hasAttr()) +return false; tbaederr wrote: ```suggestion if (const Module *M = F->getOwningModule(); M && M->isModulePurview() && getContext().getCurrentNamedModule() != M->getTopLevelModule() && !F->hasAttr()) return false; ``` Should work, right? https://github.com/llvm/llvm-project/pull/71031 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C++20] [Modules] Don't import function bodies from other module units even with optimizations (PR #71031)
@@ -3856,10 +3856,19 @@ CodeGenModule::isTriviallyRecursive(const FunctionDecl *FD) { bool CodeGenModule::shouldEmitFunction(GlobalDecl GD) { if (getFunctionLinkage(GD) != llvm::Function::AvailableExternallyLinkage) return true; + const auto *F = cast(GD.getDecl()); if (CodeGenOpts.OptimizationLevel == 0 && !F->hasAttr()) return false; + // We don't import function bodies from other named module units since that + // behavior may break ABI compatibility of the current unit. + Module *M = F->getOwningModule(); + if (M && M->isModulePurview() && + getContext().getCurrentNamedModule() != M->getTopLevelModule() && + !F->hasAttr()) +return false; ChuanqiXu9 wrote: Oh, yes. I'll address it in the next round of changes. https://github.com/llvm/llvm-project/pull/71031 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] Restrict 'fopen' & 'tmpfile' modeling to POSIX versions in StreamChecker (PR #70540)
@@ -0,0 +1,16 @@ +// RUN: %clang_analyze_cc1 -fno-builtin -analyzer-checker=core,alpha.unix.Stream -verify %s +// expected-no-diagnostics + +typedef struct _FILE FILE; + +// These functions are not standard C library functions. +FILE *tmpfile(const char *restrict path); // Real 'tmpfile' should have exactly 0 formal parameters. +FILE *fopen(const char *restrict path); // Real 'fopen' should have exactly 2 formal parameters. + +void test_fopen_non_posix(void) { + FILE *fp = fopen("file"); // no-leak: this isn't the standard POSIX fopen, we don't the semantics of this call. +} + +void test_tmpfile_non_posix(void) { + FILE *fp = tmpfile("file"); // no-leak: this isn't the standard POSIX tmpfile, we don't the semantics of this call. benshi001 wrote: I will supplement more, thanks. https://github.com/llvm/llvm-project/pull/70540 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C++20] [Modules] Warn if we found #include in module purview (PR #69555)
Bigcheese wrote: This is fine, it's definitely wrong to include framework headers like this too. https://github.com/llvm/llvm-project/pull/69555 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [SVE2.1][Clang][LLVM]Int/FP reduce builtin in Clang and LLVM intrinsic (PR #69926)
@@ -1224,7 +1233,27 @@ void SVEEmitter::createHeader(raw_ostream &OS) { OS << "typedef __SVBFloat16_t svbfloat16_t;\n"; - OS << "#include \n"; + OS << "#include \n\n"; + + OS << "typedef __attribute__((vector_size (16))) int8_t __sve_int8x16_t;\n"; sdesmalen-arm wrote: These types are unused and can be removed. https://github.com/llvm/llvm-project/pull/69926 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [SVE2.1][Clang][LLVM]Int/FP reduce builtin in Clang and LLVM intrinsic (PR #69926)
@@ -0,0 +1,285 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py +// REQUIRES: aarch64-registered-target +// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 -S -O1 -Werror -Wall -emit-llvm -o - %s | FileCheck %s +// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 -S -O1 -Werror -Wall -emit-llvm -o - -x c++ %s | FileCheck %s -check-prefix=CPP-CHECK +// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu -target-feature +sve2p1 -S -O1 -Werror -Wall -emit-llvm -o - %s | FileCheck %s +// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu -target-feature +sve2p1 -S -O1 -Werror -Wall -emit-llvm -o - -x c++ %s | FileCheck %s -check-prefix=CPP-CHECK +// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 -S -disable-O0-optnone -Werror -Wall -o /dev/null %s +#include sdesmalen-arm wrote: You need fixed-length vector types (e.g. `float16x8_t`), but I think having to include `` manually is not right. There are several things we can do: * `arm_sve.h` could include `arm_neon.h`. However, given the large size of both header files I'd argue against including another massive header file. * `arm_sve.h` could define `float16x8_t`. The downside of this is that when someone includes `arm_neon.h` afterwards, there is a duplicate definition of `float16x8_t`, so that means having to update both arm_sve.h and arm_neon.h to guard against this happening (using `#ifndef __ARM_SVE_H typedef __attribute__((neon_vector_type(..))) `) * `arm_sve.h` and `arm_neon.h` could both include a `arm_neon_types.h` which defines the fixed-length vector types in a separate header file, guarded by its own `__ARM_NEON_TYPES_H` macro. I can't think of any downsides. So the latter approach is probably the way to go. https://github.com/llvm/llvm-project/pull/69926 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] Restrict 'fopen' & 'tmpfile' modeling to POSIX versions in StreamChecker (PR #70540)
https://github.com/benshi001 updated https://github.com/llvm/llvm-project/pull/70540 >From bf36469281f52fe34866e6df5eeafdc51d28819c Mon Sep 17 00:00:00 2001 From: Ben Shi Date: Tue, 31 Oct 2023 13:05:19 +0800 Subject: [PATCH] [clang][analyzer] Restrict 'fopen' & 'tmpfile' modeling to POSIX versions in StreamChecker --- .../StaticAnalyzer/Checkers/StreamChecker.cpp | 4 ++-- .../test/Analysis/stream-non-posix-function.c | 20 +++ 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 clang/test/Analysis/stream-non-posix-function.c diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp index 4b7103c20557cc4..7e8031c7545f691 100644 --- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp @@ -238,10 +238,10 @@ class StreamChecker : public Checker FnDescriptions = { - {{{"fopen"}}, {nullptr, &StreamChecker::evalFopen, ArgNone}}, + {{{"fopen"}, 2}, {nullptr, &StreamChecker::evalFopen, ArgNone}}, {{{"freopen"}, 3}, {&StreamChecker::preFreopen, &StreamChecker::evalFreopen, 2}}, - {{{"tmpfile"}}, {nullptr, &StreamChecker::evalFopen, ArgNone}}, + {{{"tmpfile"}, 0}, {nullptr, &StreamChecker::evalFopen, ArgNone}}, {{{"fclose"}, 1}, {&StreamChecker::preDefault, &StreamChecker::evalFclose, 0}}, {{{"fread"}, 4}, diff --git a/clang/test/Analysis/stream-non-posix-function.c b/clang/test/Analysis/stream-non-posix-function.c new file mode 100644 index 000..3caabb4b097384a --- /dev/null +++ b/clang/test/Analysis/stream-non-posix-function.c @@ -0,0 +1,20 @@ +// RUN: %clang_analyze_cc1 -fno-builtin -analyzer-checker=core,alpha.unix.Stream -verify %s +// expected-no-diagnostics + +typedef struct _FILE FILE; + +// These functions are not standard C library functions. +FILE *tmpfile(const char *restrict path); // Real 'tmpfile' should have exactly 0 formal parameters. +FILE *fopen(const char *restrict path); // Real 'fopen' should have exactly 2 formal parameters. + +void test_fopen_non_posix(void) { + FILE *fp = fopen("file"); + // no-leak: this isn't the standard POSIX fopen, so we do not treat + // `fp` as a new opened local file stream. +} + +void test_tmpfile_non_posix(void) { + FILE *fp = tmpfile("file"); + // no-leak: this isn't the standard POSIX tmpfile, so we do not treat + // `fp` as a new opened local file stream. +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Handle std::move etc. builtins (PR #70772)
Timm =?utf-8?q?Bäder?= Message-ID: In-Reply-To: https://github.com/tbaederr updated https://github.com/llvm/llvm-project/pull/70772 >From b670986c19e412b3c140b610f2c26d957544b23a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Tue, 31 Oct 2023 07:17:16 +0100 Subject: [PATCH 1/2] [clang][Interp] Handle std::move etc. builtins --- clang/lib/AST/Interp/InterpBuiltin.cpp | 17 + clang/test/AST/Interp/functions.cpp| 16 2 files changed, 33 insertions(+) diff --git a/clang/lib/AST/Interp/InterpBuiltin.cpp b/clang/lib/AST/Interp/InterpBuiltin.cpp index e329794cb79243d..10e703d868f168a 100644 --- a/clang/lib/AST/Interp/InterpBuiltin.cpp +++ b/clang/lib/AST/Interp/InterpBuiltin.cpp @@ -412,6 +412,15 @@ static bool interp__builtin_popcount(InterpState &S, CodePtr OpPC, return true; } +static bool interp__builtin_move(InterpState &S, CodePtr OpPC, + const InterpFrame *Frame, const Function *Func, + const CallExpr *Call) { + + const Pointer &Arg = S.Stk.peek(); + S.Stk.push(Arg); + return Func->getDecl()->isConstexpr(); +} + bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F, const CallExpr *Call) { InterpFrame *Frame = S.Current; @@ -537,6 +546,14 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F, return retInt(S, OpPC, Dummy); break; + case Builtin::BIas_const: + case Builtin::BIforward: + case Builtin::BIforward_like: + case Builtin::BImove: +if (interp__builtin_move(S, OpPC, Frame, F, Call)) + return Ret(S, OpPC, Dummy); +break; + default: return false; } diff --git a/clang/test/AST/Interp/functions.cpp b/clang/test/AST/Interp/functions.cpp index 4bef9c2f7c0d1fa..364744203424380 100644 --- a/clang/test/AST/Interp/functions.cpp +++ b/clang/test/AST/Interp/functions.cpp @@ -371,3 +371,19 @@ namespace Variadic { constexpr int (*VFP)(...) = variadic_function2; static_assert(VFP() == 12, ""); } + + +namespace std { +template struct remove_reference { using type = T; }; +template struct remove_reference { using type = T; }; +template struct remove_reference { using type = T; }; +template +constexpr typename std::remove_reference::type&& move(T &&t) noexcept { + return static_cast::type &&>(t); +} +} +/// The std::move declaration above gets translated to a builtin function. +namespace Move { + constexpr int A = std::move(5); + static_assert(A == 5, ""); +} >From 84b0f98a1ab95f49d3f4fe10bb8c2add63e4d55c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Thu, 2 Nov 2023 09:17:41 +0100 Subject: [PATCH 2/2] Add more tests --- clang/test/AST/Interp/functions.cpp | 74 + 1 file changed, 74 insertions(+) diff --git a/clang/test/AST/Interp/functions.cpp b/clang/test/AST/Interp/functions.cpp index 364744203424380..c9a6b348adc0174 100644 --- a/clang/test/AST/Interp/functions.cpp +++ b/clang/test/AST/Interp/functions.cpp @@ -384,6 +384,80 @@ constexpr typename std::remove_reference::type&& move(T &&t) noexcept { } /// The std::move declaration above gets translated to a builtin function. namespace Move { +#if __cplusplus >= 202002L + consteval int f_eval() { // expected-note 12{{declared here}} \ + // ref-note 12{{declared here}} +return 0; + } + + /// From test/SemaCXX/cxx2a-consteval. + struct Copy { +int(*ptr)(); +constexpr Copy(int(*p)() = nullptr) : ptr(p) {} +consteval Copy(const Copy&) = default; + }; + + constexpr const Copy &to_lvalue_ref(const Copy &&a) { +return a; + } + + void test() { +constexpr const Copy C; +// there is no the copy constructor call when its argument is a prvalue because of garanteed copy elision. +// so we need to test with both prvalue and xvalues. +{ Copy c(C); } +{ Copy c((Copy(&f_eval))); } // expected-error {{cannot take address of consteval}} \ + // ref-error {{cannot take address of consteval}} +{ Copy c(std::move(C)); } +{ Copy c(std::move(Copy(&f_eval))); } // expected-error {{is not a constant expression}} \ + // expected-note {{to a consteval}} \ + // ref-error {{is not a constant expression}} \ + // ref-note {{to a consteval}} +{ Copy c(to_lvalue_ref((Copy(&f_eval; } // expected-error {{is not a constant expression}} \ +// expected-note {{to a consteval}} \ +// ref-error {{is not a constant expression}} \ +// ref-note {{to a consteval}} +{ Copy c(to_lvalue_ref(std::move(C))); } +{ Copy c(to_lvalue_ref(std::move(Copy(&f_eval; } // expected-error {{is not a constant expr
[clang] [clang-repl] [test] Make an XFAIL more precise (PR #70991)
mstorsjo wrote: This broke on PS5 bots, like https://lab.llvm.org/buildbot/#/builders/216/builds/29677; those are configured with a triple like `x86_64-sie-ps5`, which seems to use an MSVC like C++ ABI behaviour, so I pushed a revert. Not sure whom to CC to pull in Sony people to discuss this matter, so trying @pogo59. Can we use something like `XFAIL: target={{.*}}-windows-msvc, target={{.*}-ps4, target={{.*}-ps5` to specifically point towards the Sony PS triples that also use the MSVC C++ ABI here? The ideal would be something like `XFAIL: default-target-is-msvc-cxx-abi`, but I don't think we have that. I see triples `x86_64-scei-ps4` and `x86_64-sie-ps5` being mentioned elsewhere in Clang tests as examples of PS4/PS5 triples. https://github.com/llvm/llvm-project/pull/70991 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] Restrict 'fopen' & 'tmpfile' modeling to POSIX versions in StreamChecker (PR #70540)
@@ -0,0 +1,16 @@ +// RUN: %clang_analyze_cc1 -fno-builtin -analyzer-checker=core,alpha.unix.Stream -verify %s +// expected-no-diagnostics + +typedef struct _FILE FILE; + +// These functions are not standard C library functions. +FILE *tmpfile(const char *restrict path); // Real 'tmpfile' should have exactly 0 formal parameters. +FILE *fopen(const char *restrict path); // Real 'fopen' should have exactly 2 formal parameters. + +void test_fopen_non_posix(void) { + FILE *fp = fopen("file"); // no-leak: this isn't the standard POSIX fopen, we don't the semantics of this call. +} + +void test_tmpfile_non_posix(void) { + FILE *fp = tmpfile("file"); // no-leak: this isn't the standard POSIX tmpfile, we don't the semantics of this call. steakhal wrote: I think the verb was missing. Probably the "we don't [know] the semantics..." https://github.com/llvm/llvm-project/pull/70540 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C++20] [Modules] Warn if we found #include in module purview (PR #69555)
ChuanqiXu9 wrote: Got it. Thanks. Then I feel this is ready to land. https://github.com/llvm/llvm-project/pull/69555 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 0d21436 - [C++20] [Modules] Warn if we found #include in module purview (#69555)
Author: Chuanqi Xu Date: 2023-11-02T16:40:20+08:00 New Revision: 0d2143611425081bb9db5bb6ee57aaddfd1eda53 URL: https://github.com/llvm/llvm-project/commit/0d2143611425081bb9db5bb6ee57aaddfd1eda53 DIFF: https://github.com/llvm/llvm-project/commit/0d2143611425081bb9db5bb6ee57aaddfd1eda53.diff LOG: [C++20] [Modules] Warn if we found #include in module purview (#69555) Close https://github.com/llvm/llvm-project/issues/68615. It is generally wrong to include in the module purview. Although there are cases to include files in the module purview, generally these use cases should include files by quotes instead of by angles. Here we think the files got included by angles are the system headers. This is consistency with MSVC too: https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warnings-by-compiler-version?view=msvc-170#warnings-introduced-in-visual-studio-2022-version-170-compiler-version-1930 Added: clang/test/Preprocessor/include-in-module-purview.cppm Modified: clang/include/clang/Basic/DiagnosticLexKinds.td clang/lib/Lex/PPDirectives.cpp Removed: diff --git a/clang/include/clang/Basic/DiagnosticLexKinds.td b/clang/include/clang/Basic/DiagnosticLexKinds.td index 940cca67368492f..564ca48cc32ac55 100644 --- a/clang/include/clang/Basic/DiagnosticLexKinds.td +++ b/clang/include/clang/Basic/DiagnosticLexKinds.td @@ -922,6 +922,11 @@ def err_header_import_semi_in_macro : Error< def err_header_import_not_header_unit : Error< "header file %0 (aka '%1') cannot be imported because " "it is not known to be a header unit">; +def warn_pp_include_angled_in_module_purview : Warning< + "'#include ' attaches the declarations to the named module '%0'" + ", which is not usually intended; consider moving that directive before " + "the module declaration">, + InGroup>; def warn_header_guard : Warning< "%0 is used as a header guard here, followed by #define of a diff erent macro">, diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index 6fd515a5f0c756b..d97a103833c2fa6 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -2537,6 +2537,10 @@ Preprocessor::ImportAction Preprocessor::HandleHeaderIncludeOrImport( return {ImportAction::None}; } + if (isAngled && isInNamedModule()) +Diag(FilenameTok, diag::warn_pp_include_angled_in_module_purview) +<< getNamedModuleName(); + // Look up the file, create a File ID for it. SourceLocation IncludePos = FilenameTok.getLocation(); // If the filename string was the result of macro expansions, set the include diff --git a/clang/test/Preprocessor/include-in-module-purview.cppm b/clang/test/Preprocessor/include-in-module-purview.cppm new file mode 100644 index 000..0a080112b43277c --- /dev/null +++ b/clang/test/Preprocessor/include-in-module-purview.cppm @@ -0,0 +1,60 @@ +// RUN: rm -rf %t +// RUN: mkdir %t +// RUN: split-file %s %t +// +// RUN: %clang_cc1 -std=c++20 %t/a.cppm -E -P -I%t -o %t/tmp 2>&1 | FileCheck %t/a.cppm +// RUN: %clang_cc1 -std=c++20 %t/a.cppm -E -P -I%t -o - 2>&1 \ +// RUN: -Wno-include-angled-in-module-purview | FileCheck %t/a.cppm --check-prefix=CHECK-NO-WARN + +//--- a.h +// left empty + +//--- b.h +#include +// The headers not get included shouldn't be affected. +#ifdef WHATEVER +#include +#endif + +//--- a.cppm +module; +#include +#include +#include +#include "a.h" +#include "b.h" +export module a; + +#include +#include +#include +#include "a.h" +#include "b.h" + +// CHECK: a.cppm:9:10: warning: '#include ' attaches the declarations to the named module 'a' +// CHECK: a.cppm:10:10: warning: '#include ' attaches the declarations to the named module 'a' +// CHECK: a.cppm:11:10: warning: '#include ' attaches the declarations to the named module 'a' +// CHECK: In file included from {{.*}}/a.cppm:11 +// CHECK-NEXT: b.h:1:10: warning: '#include ' attaches the declarations to the named module 'a' +// CHECK: In file included from {{.*}}/a.cppm:13 +// CHECK-NEXT: b.h:1:10: warning: '#include ' attaches the declarations to the named module 'a' + +module :private; +#include +#include +#include +#include "a.h" +#include "b.h" + +// CHECK: a.cppm:24:10: warning: '#include ' attaches the declarations to the named module 'a' +// CHECK: a.cppm:25:10: warning: '#include ' attaches the declarations to the named module 'a' +// CHECK: a.cppm:26:10: warning: '#include ' attaches the declarations to the named module 'a' +// CHECK: In file included from {{.*}}/a.cppm:26 +// CHECK-NEXT: b.h:1:10: warning: '#include ' attaches the declarations to the named module 'a' +// CHECK: In file included from {{.*}}/a.cppm:28 +// CHECK-NEXT: b.h:1:10: warning: '#include ' attaches the declarations to the named module 'a' + +// We should have catched all warnings. +// CHECK: 10 warnings generated. + +// CHECK-NO
[clang] [C++20] [Modules] Warn if we found #include in module purview (PR #69555)
https://github.com/ChuanqiXu9 closed https://github.com/llvm/llvm-project/pull/69555 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] Restrict 'fopen' & 'tmpfile' modeling to POSIX versions in StreamChecker (PR #70540)
@@ -0,0 +1,16 @@ +// RUN: %clang_analyze_cc1 -fno-builtin -analyzer-checker=core,alpha.unix.Stream -verify %s +// expected-no-diagnostics + +typedef struct _FILE FILE; + +// These functions are not standard C library functions. +FILE *tmpfile(const char *restrict path); // Real 'tmpfile' should have exactly 0 formal parameters. +FILE *fopen(const char *restrict path); // Real 'fopen' should have exactly 2 formal parameters. + +void test_fopen_non_posix(void) { + FILE *fp = fopen("file"); // no-leak: this isn't the standard POSIX fopen, we don't the semantics of this call. +} + +void test_tmpfile_non_posix(void) { + FILE *fp = tmpfile("file"); // no-leak: this isn't the standard POSIX tmpfile, we don't the semantics of this call. benshi001 wrote: sorry, English is not my native language :) https://github.com/llvm/llvm-project/pull/70540 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] Restrict 'fopen' & 'tmpfile' modeling to POSIX versions in StreamChecker (PR #70540)
https://github.com/benshi001 updated https://github.com/llvm/llvm-project/pull/70540 >From bbdb534d7c1300c4b18128fc0ccdd3476c3f6d7f Mon Sep 17 00:00:00 2001 From: Ben Shi Date: Tue, 31 Oct 2023 13:05:19 +0800 Subject: [PATCH] [clang][analyzer] Restrict 'fopen' & 'tmpfile' modeling to POSIX versions in StreamChecker --- .../StaticAnalyzer/Checkers/StreamChecker.cpp| 4 ++-- clang/test/Analysis/stream-non-posix-function.c | 16 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 clang/test/Analysis/stream-non-posix-function.c diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp index 4b7103c20557cc4..7e8031c7545f691 100644 --- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp @@ -238,10 +238,10 @@ class StreamChecker : public Checker FnDescriptions = { - {{{"fopen"}}, {nullptr, &StreamChecker::evalFopen, ArgNone}}, + {{{"fopen"}, 2}, {nullptr, &StreamChecker::evalFopen, ArgNone}}, {{{"freopen"}, 3}, {&StreamChecker::preFreopen, &StreamChecker::evalFreopen, 2}}, - {{{"tmpfile"}}, {nullptr, &StreamChecker::evalFopen, ArgNone}}, + {{{"tmpfile"}, 0}, {nullptr, &StreamChecker::evalFopen, ArgNone}}, {{{"fclose"}, 1}, {&StreamChecker::preDefault, &StreamChecker::evalFclose, 0}}, {{{"fread"}, 4}, diff --git a/clang/test/Analysis/stream-non-posix-function.c b/clang/test/Analysis/stream-non-posix-function.c new file mode 100644 index 000..70b3ab25d026532 --- /dev/null +++ b/clang/test/Analysis/stream-non-posix-function.c @@ -0,0 +1,16 @@ +// RUN: %clang_analyze_cc1 -fno-builtin -analyzer-checker=core,alpha.unix.Stream -verify %s +// expected-no-diagnostics + +typedef struct _FILE FILE; + +// These functions are not standard C library functions. +FILE *tmpfile(const char *restrict path); // Real 'tmpfile' should have exactly 0 formal parameters. +FILE *fopen(const char *restrict path); // Real 'fopen' should have exactly 2 formal parameters. + +void test_fopen_non_posix(void) { + FILE *fp = fopen("file"); // no-leak: This isn't the standard POSIX `fopen`, we don't know the semantics of this call. +} + +void test_tmpfile_non_posix(void) { + FILE *fp = tmpfile("file"); // // no-leak: This isn't the standard POSIX `tmpfile`, we don't know the semantics of this call. +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] b73d739 - Revert "[clang-repl] [test] Make an XFAIL more precise (#70991)"
Author: Martin Storsjö Date: 2023-11-02T10:49:55+02:00 New Revision: b73d7390732b48014983aa9569e68c139f61bfcb URL: https://github.com/llvm/llvm-project/commit/b73d7390732b48014983aa9569e68c139f61bfcb DIFF: https://github.com/llvm/llvm-project/commit/b73d7390732b48014983aa9569e68c139f61bfcb.diff LOG: Revert "[clang-repl] [test] Make an XFAIL more precise (#70991)" This reverts commit 3bc056d5f0ebe9e4074afa088c3a0355f9ab901a. This broke on bots with a target triple of x86_64-sie-ps5, which also appear to behave like the MSVC case. Added: Modified: clang/test/Interpreter/const.cpp Removed: diff --git a/clang/test/Interpreter/const.cpp b/clang/test/Interpreter/const.cpp index 1412a1d85d6f58f..4b6ce65e3643e64 100644 --- a/clang/test/Interpreter/const.cpp +++ b/clang/test/Interpreter/const.cpp @@ -1,6 +1,6 @@ // UNSUPPORTED: system-aix // see https://github.com/llvm/llvm-project/issues/68092 -// XFAIL: target={{.*}}-windows-msvc +// XFAIL: system-windows // RUN: cat %s | clang-repl | FileCheck %s // RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] [NFC] Remove Type::getInt8PtrTy (PR #71029)
nikic wrote: > Also adds AS = 0 as an optional argument to get() methods. I believe that was intentionally omitted to make sure address spaces aren't forgotten (getUnqual is used for the case where they aren't relevant). cc @arsenm Not sure whether this consideration is still relevant with opaque pointers, where we no longer create random pointer types for bitcasts all over the place. It may be better to accept the 0 default for simplicity. https://github.com/llvm/llvm-project/pull/71029 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] [NFC] Remove Type::getInt8PtrTy (PR #71029)
arsenm wrote: I still think all the defaulted address space parameters should be purged and it only invites bugs. It's a regression to introduce a new defaulted argument. https://github.com/llvm/llvm-project/pull/71029 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][driver] Add \/../include/c++/v1 to include path on Darwin (PR #70817)
ilg-ul wrote: Then can this bug fix be accepted? Are there any other solutions? https://github.com/llvm/llvm-project/pull/70817 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Implement inc/dec for IntegralAP (PR #69597)
@@ -167,17 +169,13 @@ template class IntegralAP final { } static bool increment(IntegralAP A, IntegralAP *R) { -// FIXME: Implement. -assert(false); -*R = IntegralAP(A.V - 1); -return false; +IntegralAP One(1, A.bitWidth()); tbaederr wrote: That doesn't work because `APInt` is not a literal type. https://github.com/llvm/llvm-project/pull/69597 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[openmp] [clang] [OpenMP] Add support for Solaris/x86_64 (PR #70593)
https://github.com/brad0 updated https://github.com/llvm/llvm-project/pull/70593 >From 261f571d28b8398be221f3928f93bcee211e26ae Mon Sep 17 00:00:00 2001 From: Brad Smith Date: Sun, 29 Oct 2023 09:02:12 -0400 Subject: [PATCH] [OpenMP] Add support for Solaris/x86_64 Tested on `amd64-pc-solaris2.11`. --- clang/lib/Driver/ToolChains/Solaris.cpp | 5 + clang/test/Driver/fopenmp.c | 19 +++- openmp/runtime/cmake/LibompHandleFlags.cmake | 2 +- openmp/runtime/src/kmp.h | 8 +-- openmp/runtime/src/kmp_ftn_entry.h | 2 +- openmp/runtime/src/kmp_platform.h| 11 -- openmp/runtime/src/kmp_runtime.cpp | 8 --- openmp/runtime/src/z_Linux_util.cpp | 23 +++- 8 files changed, 62 insertions(+), 16 deletions(-) diff --git a/clang/lib/Driver/ToolChains/Solaris.cpp b/clang/lib/Driver/ToolChains/Solaris.cpp index 3d5a710842eca44..958ed99c482ed22 100644 --- a/clang/lib/Driver/ToolChains/Solaris.cpp +++ b/clang/lib/Driver/ToolChains/Solaris.cpp @@ -215,6 +215,11 @@ void solaris::Linker::ConstructJob(Compilation &C, const JobAction &JA, if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs, options::OPT_r)) { +// Use the static OpenMP runtime with -static-openmp +bool StaticOpenMP = Args.hasArg(options::OPT_static_openmp) && +!Args.hasArg(options::OPT_static); +addOpenMPRuntime(CmdArgs, getToolChain(), Args, StaticOpenMP); + if (D.CCCIsCXX()) { if (getToolChain().ShouldLinkCXXStdlib(Args)) getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs); diff --git a/clang/test/Driver/fopenmp.c b/clang/test/Driver/fopenmp.c index cf04340ebc06ac6..291946923b3ea3d 100644 --- a/clang/test/Driver/fopenmp.c +++ b/clang/test/Driver/fopenmp.c @@ -16,6 +16,9 @@ // RUN: %clang -target x86_64-dragonfly -fopenmp=libomp -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CC1-OPENMP // RUN: %clang -target x86_64-dragonfly -fopenmp=libgomp -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CC1-NO-OPENMP // RUN: %clang -target x86_64-dragonfly -fopenmp=libiomp5 -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CC1-OPENMP +// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libomp -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CC1-OPENMP +// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libgomp -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CC1-NO-OPENMP +// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libiomp5 -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CC1-OPENMP // RUN: %clang -target x86_64-windows-gnu -fopenmp=libomp -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CC1-OPENMP // RUN: %clang -target x86_64-windows-gnu -fopenmp=libgomp -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CC1-NO-OPENMP // RUN: %clang -target x86_64-windows-gnu -fopenmp=libiomp5 -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CC1-OPENMP @@ -106,6 +109,19 @@ // RUN: %clang -nostdlib -target x86_64-dragonfly -fopenmp=libgomp %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-GOMP // RUN: %clang -nostdlib -target x86_64-dragonfly -fopenmp=libiomp5 %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-IOMP5 // +// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libomp %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-OMP +// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libgomp %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-GOMP --check-prefix=CHECK-LD-GOMP-NO-RT +// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libiomp5 %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-IOMP5 +// +// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libomp -static-openmp %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-STATIC-OMP +// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libgomp -static-openmp %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-STATIC-GOMP --check-prefix=CHECK-LD-STATIC-GOMP-NO-RT +// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libiomp5 -static-openmp %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-STATIC-IOMP5 +// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libiomp5 -static -static-openmp %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-STATIC-IOMP5-NO-BDYNAMIC +// +// RUN: %clang -nostdlib -target i386-pc-solaris2.11 -fopenmp=libomp %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-OMP +// RUN: %clang -nostdlib -target i386-pc-solaris2.11 -fopenmp=libgomp %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-GOMP +// RUN: %clang -nostdlib -target i386-pc-solaris2.11 -fopenmp=libiomp5 %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-IOMP5 +// // RUN: %clang -target x86_64-windows-gnu -fopenmp=libomp %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-OMP // RUN: %clang -target x86_64-windows-gnu -fopenmp=libgomp %s -o %t -### 2>&1 | FileCheck %s --chec
[clang] 32521bb - [clang][analyzer] Restrict 'fopen' & 'tmpfile' modeling to POSIX versions in StreamChecker (#70540)
Author: Ben Shi Date: 2023-11-02T17:10:56+08:00 New Revision: 32521bb37caad512fd539d95bda26170a91e8a4b URL: https://github.com/llvm/llvm-project/commit/32521bb37caad512fd539d95bda26170a91e8a4b DIFF: https://github.com/llvm/llvm-project/commit/32521bb37caad512fd539d95bda26170a91e8a4b.diff LOG: [clang][analyzer] Restrict 'fopen' & 'tmpfile' modeling to POSIX versions in StreamChecker (#70540) 'tmpfile' has only one form that it has no argument. Added: clang/test/Analysis/stream-non-posix-function.c Modified: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp Removed: diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp index a5f8d855f8e06e1..898906977ba9bb6 100644 --- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp @@ -238,10 +238,10 @@ class StreamChecker : public Checker FnDescriptions = { - {{{"fopen"}}, {nullptr, &StreamChecker::evalFopen, ArgNone}}, + {{{"fopen"}, 2}, {nullptr, &StreamChecker::evalFopen, ArgNone}}, {{{"freopen"}, 3}, {&StreamChecker::preFreopen, &StreamChecker::evalFreopen, 2}}, - {{{"tmpfile"}}, {nullptr, &StreamChecker::evalFopen, ArgNone}}, + {{{"tmpfile"}, 0}, {nullptr, &StreamChecker::evalFopen, ArgNone}}, {{{"fclose"}, 1}, {&StreamChecker::preDefault, &StreamChecker::evalFclose, 0}}, {{{"fread"}, 4}, diff --git a/clang/test/Analysis/stream-non-posix-function.c b/clang/test/Analysis/stream-non-posix-function.c new file mode 100644 index 000..70b3ab25d026532 --- /dev/null +++ b/clang/test/Analysis/stream-non-posix-function.c @@ -0,0 +1,16 @@ +// RUN: %clang_analyze_cc1 -fno-builtin -analyzer-checker=core,alpha.unix.Stream -verify %s +// expected-no-diagnostics + +typedef struct _FILE FILE; + +// These functions are not standard C library functions. +FILE *tmpfile(const char *restrict path); // Real 'tmpfile' should have exactly 0 formal parameters. +FILE *fopen(const char *restrict path); // Real 'fopen' should have exactly 2 formal parameters. + +void test_fopen_non_posix(void) { + FILE *fp = fopen("file"); // no-leak: This isn't the standard POSIX `fopen`, we don't know the semantics of this call. +} + +void test_tmpfile_non_posix(void) { + FILE *fp = tmpfile("file"); // // no-leak: This isn't the standard POSIX `tmpfile`, we don't know the semantics of this call. +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] Restrict 'fopen' & 'tmpfile' modeling to POSIX versions in StreamChecker (PR #70540)
https://github.com/benshi001 closed https://github.com/llvm/llvm-project/pull/70540 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [LLVM][AArch64] Add ASM constraints for reduced GPR register ranges. (PR #70970)
peterwaller-arm wrote: Worth a simultaneous update to the langref? https://github.com/llvm/llvm-project/blob/e2564b27472638d2e2019e6cd2fc6d6d608f8b8c/llvm/docs/LangRef.rst#L5080-L5106 https://github.com/llvm/llvm-project/pull/70970 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[flang] [clang] [clang-tools-extra] [llvm] [compiler-rt] [Legalizer] Expand fmaximum and fminimum (PR #67301)
@@ -8201,6 +8201,66 @@ SDValue TargetLowering::expandFMINNUM_FMAXNUM(SDNode *Node, return SDValue(); } +SDValue TargetLowering::expandFMINIMUM_FMAXIMUM(SDNode *N, +SelectionDAG &DAG) const { + SDLoc DL(N); + SDValue LHS = N->getOperand(0); + SDValue RHS = N->getOperand(1); + unsigned Opc = N->getOpcode(); + EVT VT = N->getValueType(0); + EVT CCVT = getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(), VT); + bool NoNaN = (N->getFlags().hasNoNaNs() || +(DAG.isKnownNeverNaN(LHS) && DAG.isKnownNeverNaN(RHS))); + bool NoZeroSign = + (N->getFlags().hasNoSignedZeros() || DAG.isKnownNeverZeroFloat(LHS) || + DAG.isKnownNeverZeroFloat(RHS)); arsenm wrote: Can you defer these checks as late as possible? https://github.com/llvm/llvm-project/pull/67301 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[flang] [compiler-rt] [llvm] [clang-tools-extra] [clang] [Legalizer] Expand fmaximum and fminimum (PR #67301)
@@ -8201,6 +8201,66 @@ SDValue TargetLowering::expandFMINNUM_FMAXNUM(SDNode *Node, return SDValue(); } +SDValue TargetLowering::expandFMINIMUM_FMAXIMUM(SDNode *N, +SelectionDAG &DAG) const { + SDLoc DL(N); + SDValue LHS = N->getOperand(0); + SDValue RHS = N->getOperand(1); + unsigned Opc = N->getOpcode(); + EVT VT = N->getValueType(0); + EVT CCVT = getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(), VT); + bool NoNaN = (N->getFlags().hasNoNaNs() || +(DAG.isKnownNeverNaN(LHS) && DAG.isKnownNeverNaN(RHS))); + bool NoZeroSign = + (N->getFlags().hasNoSignedZeros() || DAG.isKnownNeverZeroFloat(LHS) || + DAG.isKnownNeverZeroFloat(RHS)); + bool IsMax = Opc == ISD::FMAXIMUM; + + if (VT.isVector() && + isOperationLegalOrCustomOrPromote(Opc, VT.getScalarType())) +return SDValue(); + + // First, implement comparison not propagating NaN. If no native fmin or fmax + // available, use plain select with setcc instead. + SDValue MinMax; + if (isOperationLegalOrCustom(IsMax ? ISD::FMAXNUM_IEEE : ISD::FMINNUM_IEEE, + VT)) +MinMax = DAG.getNode(IsMax ? ISD::FMAXNUM_IEEE : ISD::FMINNUM_IEEE, DL, VT, + LHS, RHS); + else if (isOperationLegalOrCustom(IsMax ? ISD::FMAXNUM : ISD::FMINNUM, VT)) +MinMax = DAG.getNode(IsMax ? ISD::FMAXNUM : ISD::FMINNUM, DL, VT, LHS, RHS); + else arsenm wrote: Braces https://github.com/llvm/llvm-project/pull/67301 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [compiler-rt] [flang] [llvm] [Legalizer] Expand fmaximum and fminimum (PR #67301)
@@ -8201,6 +8201,66 @@ SDValue TargetLowering::expandFMINNUM_FMAXNUM(SDNode *Node, return SDValue(); } +SDValue TargetLowering::expandFMINIMUM_FMAXIMUM(SDNode *N, +SelectionDAG &DAG) const { + SDLoc DL(N); + SDValue LHS = N->getOperand(0); + SDValue RHS = N->getOperand(1); + unsigned Opc = N->getOpcode(); + EVT VT = N->getValueType(0); + EVT CCVT = getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(), VT); + bool NoNaN = (N->getFlags().hasNoNaNs() || +(DAG.isKnownNeverNaN(LHS) && DAG.isKnownNeverNaN(RHS))); + bool NoZeroSign = + (N->getFlags().hasNoSignedZeros() || DAG.isKnownNeverZeroFloat(LHS) || + DAG.isKnownNeverZeroFloat(RHS)); + bool IsMax = Opc == ISD::FMAXIMUM; + + if (VT.isVector() && + isOperationLegalOrCustomOrPromote(Opc, VT.getScalarType())) +return SDValue(); + + // First, implement comparison not propagating NaN. If no native fmin or fmax + // available, use plain select with setcc instead. + SDValue MinMax; + if (isOperationLegalOrCustom(IsMax ? ISD::FMAXNUM_IEEE : ISD::FMINNUM_IEEE, + VT)) +MinMax = DAG.getNode(IsMax ? ISD::FMAXNUM_IEEE : ISD::FMINNUM_IEEE, DL, VT, + LHS, RHS); + else if (isOperationLegalOrCustom(IsMax ? ISD::FMAXNUM : ISD::FMINNUM, VT)) +MinMax = DAG.getNode(IsMax ? ISD::FMAXNUM : ISD::FMINNUM, DL, VT, LHS, RHS); + else +MinMax = DAG.getSelect( +DL, VT, +DAG.getSetCC(DL, CCVT, LHS, RHS, IsMax ? ISD::SETGT : ISD::SETLT), LHS, arsenm wrote: Intermediate variable wouldn't hurt. Alternatively could use getSelectCC https://github.com/llvm/llvm-project/pull/67301 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Implement inc/dec for IntegralAP (PR #69597)
@@ -167,17 +169,13 @@ template class IntegralAP final { } static bool increment(IntegralAP A, IntegralAP *R) { -// FIXME: Implement. -assert(false); -*R = IntegralAP(A.V - 1); -return false; +IntegralAP One(1, A.bitWidth()); +return add(A, One, A.bitWidth() + 1, R); } static bool decrement(IntegralAP A, IntegralAP *R) { -// FIXME: Implement. -assert(false); -*R = IntegralAP(A.V - 1); -return false; +IntegralAP One(1, A.bitWidth()); +return sub(A, One, A.bitWidth() + 1, R); tbaederr wrote: So the result can still be displayed on overflow/wraparound. https://github.com/llvm/llvm-project/pull/69597 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Implement inc/dec for IntegralAP (PR #69597)
tbaederr wrote: > FWIW, when the description for the PR says it can't be merged for some > reason, it usually goes on the bottom of my review queue until those issues > are addressed. It's difficult to accept known-broken code. :-( Sorry, I forgot to re-enable the tests here. Now that https://reviews.llvm.org/D154581 has been merged, this works. https://github.com/llvm/llvm-project/pull/69597 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Implement inc/dec for IntegralAP (PR #69597)
Timm =?utf-8?q?Bäder?= Message-ID: In-Reply-To: https://github.com/tbaederr updated https://github.com/llvm/llvm-project/pull/69597 >From 26780a13123c14763467c1b9de6b0cef3d92ff1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Wed, 18 Oct 2023 15:36:13 +0200 Subject: [PATCH 1/2] [clang][Interp] Implement inc/dec for IntegralAP --- clang/lib/AST/Interp/IntegralAP.h | 23 ++-- clang/test/AST/Interp/intap.cpp | 62 +++ 2 files changed, 67 insertions(+), 18 deletions(-) diff --git a/clang/lib/AST/Interp/IntegralAP.h b/clang/lib/AST/Interp/IntegralAP.h index 9aefea6d0c47ed9..234cfd74af452c7 100644 --- a/clang/lib/AST/Interp/IntegralAP.h +++ b/clang/lib/AST/Interp/IntegralAP.h @@ -119,8 +119,10 @@ template class IntegralAP final { constexpr unsigned bitWidth() const { return V.getBitWidth(); } - APSInt toAPSInt(unsigned Bits = 0) const { return APSInt(V, Signed); } - APValue toAPValue() const { return APValue(APSInt(V, Signed)); } + APSInt toAPSInt(unsigned Bits = 0) const { +return APSInt(V, !Signed).extend((Bits > 0) ? Bits : bitWidth()); + } + APValue toAPValue() const { return APValue(toAPSInt()); } bool isZero() const { return V.isZero(); } bool isPositive() const { return V.isNonNegative(); } @@ -170,17 +172,13 @@ template class IntegralAP final { } static bool increment(IntegralAP A, IntegralAP *R) { -// FIXME: Implement. -assert(false); -*R = IntegralAP(A.V - 1); -return false; +IntegralAP One(1, A.bitWidth()); +return add(A, One, A.bitWidth() + 1, R); } static bool decrement(IntegralAP A, IntegralAP *R) { -// FIXME: Implement. -assert(false); -*R = IntegralAP(A.V - 1); -return false; +IntegralAP One(1, A.bitWidth()); +return sub(A, One, A.bitWidth() + 1, R); } static bool add(IntegralAP A, IntegralAP B, unsigned OpBits, IntegralAP *R) { @@ -249,7 +247,10 @@ template class IntegralAP final { static void shiftRight(const IntegralAP A, const IntegralAP B, unsigned OpBits, IntegralAP *R) { -*R = IntegralAP(A.V.ashr(B.V.getZExtValue())); +if constexpr (Signed) + *R = IntegralAP(A.V.ashr(B.V.getZExtValue())); +else + *R = IntegralAP(A.V.lshr(B.V.getZExtValue())); } private: diff --git a/clang/test/AST/Interp/intap.cpp b/clang/test/AST/Interp/intap.cpp index 02a860eb0986c15..dbb9ff95193adbc 100644 --- a/clang/test/AST/Interp/intap.cpp +++ b/clang/test/AST/Interp/intap.cpp @@ -32,9 +32,17 @@ static_assert(BI1 == 3, ""); #ifdef __SIZEOF_INT128__ +typedef __int128 int128_t; +typedef unsigned __int128 uint128_t; +static const __uint128_t UINT128_MAX =__uint128_t(__int128_t(-1L)); +static_assert(UINT128_MAX == -1, ""); + +static const __int128_t INT128_MAX = UINT128_MAX >> (__int128_t)1; +static_assert(INT128_MAX != 0, ""); +static const __int128_t INT128_MIN = -INT128_MAX - 1; + namespace i128 { - typedef __int128 int128_t; - typedef unsigned __int128 uint128_t; + constexpr int128_t I128_1 = 12; static_assert(I128_1 == 12, ""); static_assert(I128_1 != 10, ""); @@ -43,12 +51,7 @@ namespace i128 { // expected-note{{evaluates to}} \ // ref-note{{evaluates to}} - static const __uint128_t UINT128_MAX =__uint128_t(__int128_t(-1L)); - static_assert(UINT128_MAX == -1, ""); - static const __int128_t INT128_MAX = UINT128_MAX >> (__int128_t)1; - static_assert(INT128_MAX != 0, ""); - static const __int128_t INT128_MIN = -INT128_MAX - 1; constexpr __int128 A = INT128_MAX + 1; // expected-error {{must be initialized by a constant expression}} \ // expected-note {{outside the range}} \ // ref-error {{must be initialized by a constant expression}} \ @@ -121,4 +124,49 @@ namespace AddSubOffset { static_assert(*P2 == 1,""); } +namespace IncDec { +#if 0 + constexpr int128_t maxPlus1(bool Pre) { +int128_t a = INT128_MAX; + +if (Pre) + ++a; // ref-note {{value 170141183460469231731687303715884105728 is outside the range}} \ + // expected-note {{value 170141183460469231731687303715884105728 is outside the range}} +else + a++; +return a; + } + static_assert(maxPlus1(true) == 0, ""); // ref-error {{not an integral constant expression}} \ + // ref-note in call to}} \ + // expected-error {{not an integral constant expression}} \ + // expected-note in call to}} + static_assert(maxPlus1(false) == 0, ""); // ref-error {{not an integral constant expression}} \ + // ref-note in call to}} \ + // expected-error {{not an integral constant expression}} \ +
[clang] [clang] Change representation of CurLexerKind (PR #70381)
serge-sans-paille wrote: As expected, the formatter iw now red, otherwise looks good (to me at least), waiting for official approval :-) https://github.com/llvm/llvm-project/pull/70381 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer][NFC] Rework SVal kind representation (PR #71039)
https://github.com/steakhal created https://github.com/llvm/llvm-project/pull/71039 The goal of this patch is to refine how the `SVal` base and sub-kinds are represented by forming one unified enum describing the possible SVals. This means that the `unsigned SVal::Kind` and the attached bit-packing semantics would be replaced by a single unified enum. This is more conventional and leads to a better debugging experience by default. This eases the need of using debug pretty-printers, or the use of runtime functions doing the printing for us like we do today by calling `Val.dump()` whenever we inspect the values. Previously, the first 2 bits of the `unsigned SVal::Kind` discriminated the following quartet: `UndefinedVal`, `UnknownVal`, `Loc`, or `NonLoc`. The rest of the upper bits represented the sub-kind, where the value represented the index among only the `Loc`s or `NonLoc`s, effectively attaching 2 meanings of the upper bits depending on the base-kind. We don't need to pack these bits, as we have plenty even if we would use just a plan-old `unsigned char`. Consequently, in this patch, I propose to lay out all the (non-abstract) `SVal` kinds into a single enum, along with some metadata (`BEGIN_Loc`, `END_Loc`, `BEGIN_NonLoc`, `END_NonLoc`) artificial enum values, similar how we do with the `MemRegions`. Note that in the unified `SVal::Kind` enum, to differentiate `nonloc::ConcreteInt` from `loc::ConcreteInt`, I had to prefix them with `Loc` and `NonLoc` to resolve this ambiguity. This should not surface in general, because I'm replacing the `nonloc::Kind` enum items with `inline constexpr` global constants to mimic the original behavior - and offer nicer spelling to these enum values. Some `SVal` constructors were not marked explicit, which I now mark as such to follow best practices, and marked others as `/*implicit*/` to clarify the intent. During refactoring, I also found at least one function not marked `LLVM_ATTRIBUTE_RETURNS_NONNULL`, so I did that. The `TypeRetrievingVisitor` visitor had some accidental dead code, namely: `VisitNonLocConcreteInt` and `VisitLocConcreteInt`. Previously, the `SValVisitor` expected visit handlers of `VisitNonLocX(nonloc::X)` and `VisitLocX(loc::X)`, where I felt that envoding `NonLoc` and `Loc` in the name is not necessary as the type of the parameter would select the right overload anyways, so I simplified the naming of those visit functions. The rest of the diff is a lot of times just formatting, because `getKind()` by nature, frequently appears in switches, which means that the whole switch gets automatically reformatted. I could probably undo the formatting, but I didn't want to deviate from the rule unless explicitly requested. >From 3bc43ab005aa76a43644d4d93286215b490cc8fa Mon Sep 17 00:00:00 2001 From: Balazs Benics Date: Thu, 2 Nov 2023 10:21:03 +0100 Subject: [PATCH] [analyzer][NFC] Rework SVal kind representation The goal of this patch is to refine how the `SVal` base and sub-kinds are represented by forming one unified enum describing the possible SVals. This means that the `unsigned SVal::Kind` and the attached bit-packing semantics would be replaced by a single unified enum. This is more conventional and leads to a better debugging experience by default. This eases the need of using debug pretty-printers, or the use of runtime functions doing the printing for us like we do today by calling `Val.dump()` whenever we inspect the values. Previously, the first 2 bits of the `unsigned SVal::Kind` discriminated the following quartet: `UndefinedVal`, `UnknownVal`, `Loc`, or `NonLoc`. The rest of the upper bits represented the sub-kind, where the value represented the index among only the `Loc`s or `NonLoc`s, effectively attaching 2 meanings of the upper bits depending on the base-kind. We don't need to pack these bits, as we have plenty even if we would use just a plan-old `unsigned char`. Consequently, in this patch, I propose to lay out all the (non-abstract) `SVal` kinds into a single enum, along with some metadata (`BEGIN_Loc`, `END_Loc`, `BEGIN_NonLoc`, `END_NonLoc`) artificial enum values, similar how we do with the `MemRegions`. Note that in the unified `SVal::Kind` enum, to differentiate `nonloc::ConcreteInt` from `loc::ConcreteInt`, I had to prefix them with `Loc` and `NonLoc` to resolve this ambiguity. This should not surface in general, because I'm replacing the `nonloc::Kind` enum items with `inline constexpr` global constants to mimic the original behavior - and offer nicer spelling to these enum values. Some `SVal` constructors were not marked explicit, which I now mark as such to follow best practices, and marked others as `/*implicit*/` to clarify the intent. During refactoring, I also found at least one function not marked `LLVM_ATTRIBUTE_RETURNS_NONNULL`, so I did that. The `TypeRetrievingVisitor` visitor had some accidental dead code, namely: `VisitNonLocConcreteInt` and `VisitLocCon
[clang] [analyzer][NFC] Rework SVal kind representation (PR #71039)
llvmbot wrote: @llvm/pr-subscribers-clang-static-analyzer-1 Author: Balazs Benics (steakhal) Changes The goal of this patch is to refine how the `SVal` base and sub-kinds are represented by forming one unified enum describing the possible SVals. This means that the `unsigned SVal::Kind` and the attached bit-packing semantics would be replaced by a single unified enum. This is more conventional and leads to a better debugging experience by default. This eases the need of using debug pretty-printers, or the use of runtime functions doing the printing for us like we do today by calling `Val.dump()` whenever we inspect the values. Previously, the first 2 bits of the `unsigned SVal::Kind` discriminated the following quartet: `UndefinedVal`, `UnknownVal`, `Loc`, or `NonLoc`. The rest of the upper bits represented the sub-kind, where the value represented the index among only the `Loc`s or `NonLoc`s, effectively attaching 2 meanings of the upper bits depending on the base-kind. We don't need to pack these bits, as we have plenty even if we would use just a plan-old `unsigned char`. Consequently, in this patch, I propose to lay out all the (non-abstract) `SVal` kinds into a single enum, along with some metadata (`BEGIN_Loc`, `END_Loc`, `BEGIN_NonLoc`, `END_NonLoc`) artificial enum values, similar how we do with the `MemRegions`. Note that in the unified `SVal::Kind` enum, to differentiate `nonloc::ConcreteInt` from `loc::ConcreteInt`, I had to prefix them with `Loc` and `NonLoc` to resolve this ambiguity. This should not surface in general, because I'm replacing the `nonloc::Kind` enum items with `inline constexpr` global constants to mimic the original behavior - and offer nicer spelling to these enum values. Some `SVal` constructors were not marked explicit, which I now mark as such to follow best practices, and marked others as `/*implicit*/` to clarify the intent. During refactoring, I also found at least one function not marked `LLVM_ATTRIBUTE_RETURNS_NONNULL`, so I did that. The `TypeRetrievingVisitor` visitor had some accidental dead code, namely: `VisitNonLocConcreteInt` and `VisitLocConcreteInt`. Previously, the `SValVisitor` expected visit handlers of `VisitNonLocX(nonloc::X)` and `VisitLocX(loc::X)`, where I felt that envoding `NonLoc` and `Loc` in the name is not necessary as the type of the parameter would select the right overload anyways, so I simplified the naming of those visit functions. The rest of the diff is a lot of times just formatting, because `getKind()` by nature, frequently appears in switches, which means that the whole switch gets automatically reformatted. I could probably undo the formatting, but I didn't want to deviate from the rule unless explicitly requested. --- Patch is 40.42 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/71039.diff 9 Files Affected: - (modified) clang/include/clang/StaticAnalyzer/Checkers/SValExplainer.h (+5-5) - (modified) clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValVisitor.h (+25-32) - (modified) clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.def (+18-20) - (modified) clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h (+77-148) - (modified) clang/lib/StaticAnalyzer/Core/SValBuilder.cpp (+14-14) - (modified) clang/lib/StaticAnalyzer/Core/SVals.cpp (+42-45) - (modified) clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp (+2-2) - (modified) clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp (+36-37) - (modified) clang/lib/StaticAnalyzer/Core/Store.cpp (+1-1) ``diff diff --git a/clang/include/clang/StaticAnalyzer/Checkers/SValExplainer.h b/clang/include/clang/StaticAnalyzer/Checkers/SValExplainer.h index 3ae28c1dba3eb5a..43a70f596a4da28 100644 --- a/clang/include/clang/StaticAnalyzer/Checkers/SValExplainer.h +++ b/clang/include/clang/StaticAnalyzer/Checkers/SValExplainer.h @@ -65,7 +65,7 @@ class SValExplainer : public FullSValVisitor { return "undefined value"; } - std::string VisitLocMemRegionVal(loc::MemRegionVal V) { + std::string VisitMemRegionVal(loc::MemRegionVal V) { const MemRegion *R = V.getRegion(); // Avoid the weird "pointer to pointee of ...". if (auto SR = dyn_cast(R)) { @@ -76,7 +76,7 @@ class SValExplainer : public FullSValVisitor { return "pointer to " + Visit(R); } - std::string VisitLocConcreteInt(loc::ConcreteInt V) { + std::string VisitConcreteInt(loc::ConcreteInt V) { const llvm::APSInt &I = V.getValue(); std::string Str; llvm::raw_string_ostream OS(Str); @@ -84,11 +84,11 @@ class SValExplainer : public FullSValVisitor { return Str; } - std::string VisitNonLocSymbolVal(nonloc::SymbolVal V) { + std::string VisitSymbolVal(nonloc::SymbolVal V) { return Visit(V.getSymbol()); } - std::string VisitNonLocConcreteInt(nonloc::ConcreteInt V) { + std::string VisitConcreteInt(nonloc::ConcreteInt V
[clang] [analyzer][NFC] Rework SVal kind representation (PR #71039)
steakhal wrote: This PR relates to #69835 ([comment](https://github.com/llvm/llvm-project/issues/69835#issuecomment-1775533393)). https://github.com/llvm/llvm-project/pull/71039 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] Remove experimental from Vector Crypto extensions (PR #69000)
4vtomat wrote: Since it's possible that **ISA spec** and **intrinsics spec** are not synchronized, so the updates add an dummy extension called **zexperimental**, once `-menable-experimental-extensions` is specified, the feature `zexperimental` is automatically added. If specifying `let RequiredFeatures = ["Zexperimental"] ` is added in `.td` file, it will check if `zexperimental` exists, if not, the corresponding intrinsics would not be added, hence causing an **intrinsics undeclared** error. https://github.com/llvm/llvm-project/pull/69000 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [compiler-rt] [flang] [llvm] [AMDGPU] Fold operand after shrinking instruction in SIFoldOperands (PR #68426)
@@ -290,37 +291,40 @@ bool SIFoldOperands::updateOperand(FoldCandidate &Fold) const { if (Fold.Commuted) TII->commuteInstruction(*Inst32, false); -return true; - } - assert(!Fold.needsShrink() && "not handled"); +Fold.UseMI = Inst32; +Fold.UseOpNo = AMDGPU::getNamedOperandIdx(Fold.UseMI->getOpcode(), + AMDGPU::OpName::src0); jayfoad wrote: Adding the assert showed up some problems to do with knowing whether or not the instruction has been commuted. I need to spend some more time on that. https://github.com/llvm/llvm-project/pull/68426 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [compiler-rt] [flang] [llvm] [AMDGPU] Fold operand after shrinking instruction in SIFoldOperands (PR #68426)
https://github.com/jayfoad converted_to_draft https://github.com/llvm/llvm-project/pull/68426 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [NFC][clang-tidy]refactor isAssignmentToMemberOf in PreferMemberInitializerCheck (PR #71006)
@@ -216,11 +216,12 @@ void PreferMemberInitializerCheck::check( return; } -const FieldDecl *Field = nullptr; -const Expr *InitValue = nullptr; -std::tie(Field, InitValue) = isAssignmentToMemberOf(Class, S, Ctor); -if (!Field) +std::optional> +AssignmentToMember = isAssignmentToMemberOf(Class, S, Ctor); +if (!AssignmentToMember) continue; +const FieldDecl *Field = AssignmentToMember.value().first; PiotrZSL wrote: you can use `->` operator here... No ned for value(). https://github.com/llvm/llvm-project/pull/71006 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [NFC][clang-tidy]refactor isAssignmentToMemberOf in PreferMemberInitializerCheck (PR #71006)
@@ -118,45 +118,45 @@ static void updateAssignmentLevel( } } -static std::pair +static std::optional> PiotrZSL wrote: Consider changing this std::pair into normal struct, in such way there will be no need to make aliases to fields later in check method https://github.com/llvm/llvm-project/pull/71006 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [NFC][clang-tidy]refactor isAssignmentToMemberOf in PreferMemberInitializerCheck (PR #71006)
https://github.com/PiotrZSL approved this pull request. +1, as it's better than was before. https://github.com/llvm/llvm-project/pull/71006 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AMDGPU] Add code model (#70760) test for amdgpu target. (PR #71019)
https://github.com/pravinjagtap updated https://github.com/llvm/llvm-project/pull/71019 >From ef0118818249da417706db7f8e7086d051d17d50 Mon Sep 17 00:00:00 2001 From: Pravin Jagtap Date: Thu, 2 Nov 2023 01:05:35 -0400 Subject: [PATCH 1/2] [AMDGPU] Add code model (#70760) test for amdgpu target. --- llvm/test/CodeGen/AMDGPU/codemodel.ll | 9 + 1 file changed, 9 insertions(+) create mode 100644 llvm/test/CodeGen/AMDGPU/codemodel.ll diff --git a/llvm/test/CodeGen/AMDGPU/codemodel.ll b/llvm/test/CodeGen/AMDGPU/codemodel.ll new file mode 100644 index 000..8b60257b2076aed --- /dev/null +++ b/llvm/test/CodeGen/AMDGPU/codemodel.ll @@ -0,0 +1,9 @@ +; RUN: not llc -verify-machineinstrs -o - -mtriple=amdgcn-unknown-amdhsa -mcpu=gfx900 -code-model=tiny < %s 2>&1 | FileCheck %s --check-prefix=TINY +; RUN: not llc -verify-machineinstrs -o - -mtriple=amdgcn-unknown-amdhsa -mcpu=gfx900 -code-model=kernel < %s 2>&1 | FileCheck %s --check-prefix=KERNEL + +; TINY:Target does not support the tiny CodeModel +; KERNEL:Target does not support the kernel CodeModel + +define void @foo() { + ret void +} >From f4c4ec2dd7829267b0df84a2a651b98e9c18a4e0 Mon Sep 17 00:00:00 2001 From: Pravin Jagtap Date: Thu, 2 Nov 2023 05:51:50 -0400 Subject: [PATCH 2/2] Added clang driver test for code model. --- clang/test/Driver/mcmodel.c | 10 ++ 1 file changed, 10 insertions(+) diff --git a/clang/test/Driver/mcmodel.c b/clang/test/Driver/mcmodel.c index fb3bbccb0c68157..d546d5d81db5261 100644 --- a/clang/test/Driver/mcmodel.c +++ b/clang/test/Driver/mcmodel.c @@ -13,6 +13,11 @@ // RUN: not %clang -### -c --target=aarch64 -mcmodel=medium %s 2>&1 | FileCheck --check-prefix=ERR-MEDIUM %s // RUN: not %clang -### -c --target=aarch64 -mcmodel=kernel %s 2>&1 | FileCheck --check-prefix=ERR-KERNEL %s // RUN: not %clang --target=aarch64_32-linux -### -S -mcmodel=small %s 2>&1 | FileCheck --check-prefix=ERR-AARCH64_32 %s +// RUN: %clang --target=amdgcn-amd-amdhsa -nogpulib -### -c -mcmodel=tiny %s 2>&1 | FileCheck --check-prefix=AMDGPU-MCMODEL-TINY %s +// RUN: %clang --target=amdgcn-amd-amdhsa -nogpulib -### -c -mcmodel=small %s 2>&1 | FileCheck --check-prefix=AMDGPU-MCMODEL-SMALL %s +// RUN: %clang --target=amdgcn-amd-amdhsa -nogpulib -### -S -mcmodel=kernel %s 2>&1 | FileCheck --check-prefix=AMDGPU-MCMODEL-KERNEL %s +// RUN: %clang --target=amdgcn-amd-amdhsa -nogpulib -### -c -mcmodel=medium %s 2>&1 | FileCheck --check-prefix=AMDGPU-MCMODEL-MEDIUM %s +// RUN: %clang --target=amdgcn-amd-amdhsa -nogpulib -### -S -mcmodel=large %s 2>&1 | FileCheck --check-prefix=AMDGPU-MCMODEL-LARGE %s // TINY: "-mcmodel=tiny" // SMALL: "-mcmodel=small" @@ -29,3 +34,8 @@ // AARCH64-PIC-LARGE: error: invalid argument '-mcmodel=large' only allowed with '-fno-pic' // ERR-AARCH64_32: error: unsupported argument 'small' to option '-mcmodel=' for target 'aarch64_32-unknown-linux' +// AMDGPU-MCMODEL-TINY: "-mcmodel=tiny" +// AMDGPU-MCMODEL-SMALL: "-mcmodel=small" +// AMDGPU-MCMODEL-KERNEL: "-mcmodel=kernel" +// AMDGPU-MCMODEL-MEDIUM: "-mcmodel=medium" +// AMDGPU-MCMODEL-LARGE: "-mcmodel=large" ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AMDGPU] Add code model (#70760) test for amdgpu target. (PR #71019)
@@ -13,6 +13,11 @@ // RUN: not %clang -### -c --target=aarch64 -mcmodel=medium %s 2>&1 | FileCheck --check-prefix=ERR-MEDIUM %s // RUN: not %clang -### -c --target=aarch64 -mcmodel=kernel %s 2>&1 | FileCheck --check-prefix=ERR-KERNEL %s // RUN: not %clang --target=aarch64_32-linux -### -S -mcmodel=small %s 2>&1 | FileCheck --check-prefix=ERR-AARCH64_32 %s +// RUN: %clang --target=amdgcn-amd-amdhsa -nogpulib -### -c -mcmodel=tiny %s 2>&1 | FileCheck --check-prefix=AMDGPU-MCMODEL-TINY %s arsenm wrote: I'm not sure exactly what's being tested here, this looks like it's targeting C as a target? The more relevant case would be with amdgcn as the offload target. For direct compilation it would make more sense to emit the error https://github.com/llvm/llvm-project/pull/71019 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang-tools-extra] [clang] [AMDGPU] New ttracedata intrinsics (PR #70235)
https://github.com/jayfoad updated https://github.com/llvm/llvm-project/pull/70235 >From e02640686a8cf0a42cec01da4f32b6888f5de11f Mon Sep 17 00:00:00 2001 From: Jay Foad Date: Wed, 25 Oct 2023 17:14:40 +0100 Subject: [PATCH 1/2] [AMDGPU] New ttracedata intrinsics Add llvm.amdgcn.s.ttracedata and llvm.amdgcn.s.ttracedata.imm which map directly to the corresponding instructions s_ttracedata and s_ttracedata_imm. These are inherently whole-wave operations so any non-uniform inputs are readfirstlaned. --- llvm/include/llvm/IR/IntrinsicsAMDGPU.td | 7 +++ .../Target/AMDGPU/AMDGPURegisterBankInfo.cpp | 10 llvm/lib/Target/AMDGPU/SOPInstructions.td | 9 +++- .../AMDGPU/llvm.amdgcn.s.ttracedata.ll| 53 +++ 4 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 llvm/test/CodeGen/AMDGPU/llvm.amdgcn.s.ttracedata.ll diff --git a/llvm/include/llvm/IR/IntrinsicsAMDGPU.td b/llvm/include/llvm/IR/IntrinsicsAMDGPU.td index 5f1d1d932f74cbd..a3acfccd00f8e16 100644 --- a/llvm/include/llvm/IR/IntrinsicsAMDGPU.td +++ b/llvm/include/llvm/IR/IntrinsicsAMDGPU.td @@ -1697,6 +1697,13 @@ def int_amdgcn_s_setprio : DefaultAttrsIntrinsic<[], [llvm_i16_ty], [ImmArg>, IntrNoMem, IntrHasSideEffects]>; +def int_amdgcn_s_ttracedata : + DefaultAttrsIntrinsic<[], [llvm_i32_ty], +[IntrNoMem, IntrHasSideEffects]>; +def int_amdgcn_s_ttracedata_imm : + DefaultAttrsIntrinsic<[], [llvm_i16_ty], +[IntrNoMem, IntrHasSideEffects, ImmArg>]>; + // This is IntrHasSideEffects so it can be used to read cycle counters. def int_amdgcn_s_getreg : ClangBuiltin<"__builtin_amdgcn_s_getreg">, diff --git a/llvm/lib/Target/AMDGPU/AMDGPURegisterBankInfo.cpp b/llvm/lib/Target/AMDGPU/AMDGPURegisterBankInfo.cpp index 5b056bd9e5dba2c..f117f732cb84ffb 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPURegisterBankInfo.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPURegisterBankInfo.cpp @@ -3064,6 +3064,9 @@ void AMDGPURegisterBankInfo::applyMappingImpl( constrainOpWithReadfirstlane(B, MI, 2); return; } +case Intrinsic::amdgcn_s_ttracedata: + constrainOpWithReadfirstlane(B, MI, 1); // M0 + return; case Intrinsic::amdgcn_raw_buffer_load_lds: case Intrinsic::amdgcn_raw_ptr_buffer_load_lds: { applyDefaultMapping(OpdMapper); @@ -4653,6 +4656,13 @@ AMDGPURegisterBankInfo::getInstrMapping(const MachineInstr &MI) const { OpdsMapping[2] = AMDGPU::getValueMapping(Bank, 32); break; } +case Intrinsic::amdgcn_s_ttracedata: { + // This must be an SGPR, but accept a VGPR. + unsigned Bank = getRegBankID(MI.getOperand(1).getReg(), MRI, + AMDGPU::SGPRRegBankID); + OpdsMapping[1] = AMDGPU::getValueMapping(Bank, 32); + break; +} case Intrinsic::amdgcn_end_cf: { unsigned Size = getSizeInBits(MI.getOperand(1).getReg(), MRI, *TRI); OpdsMapping[1] = AMDGPU::getValueMapping(AMDGPU::SGPRRegBankID, Size); diff --git a/llvm/lib/Target/AMDGPU/SOPInstructions.td b/llvm/lib/Target/AMDGPU/SOPInstructions.td index 2f3b0ff2f76215e..0ec4f8150bfcc06 100644 --- a/llvm/lib/Target/AMDGPU/SOPInstructions.td +++ b/llvm/lib/Target/AMDGPU/SOPInstructions.td @@ -1500,7 +1500,10 @@ def S_INCPERFLEVEL : SOPP_Pseudo <"s_incperflevel", (ins i32imm:$simm16), "$simm def S_DECPERFLEVEL : SOPP_Pseudo <"s_decperflevel", (ins i32imm:$simm16), "$simm16", [(int_amdgcn_s_decperflevel timm:$simm16)]> { } -def S_TTRACEDATA : SOPP_Pseudo <"s_ttracedata", (ins)> { + +let Uses = [M0] in +def S_TTRACEDATA : SOPP_Pseudo <"s_ttracedata", (ins), "", +[(int_amdgcn_s_ttracedata M0)]> { let simm16 = 0; let fixed_imm = 1; } @@ -1544,8 +1547,10 @@ let SubtargetPredicate = isGFX10Plus in { [(SIdenorm_mode (i32 timm:$simm16))]>; } + let hasSideEffects = 1 in def S_TTRACEDATA_IMM : -SOPP_Pseudo<"s_ttracedata_imm", (ins s16imm:$simm16), "$simm16">; +SOPP_Pseudo<"s_ttracedata_imm", (ins s16imm:$simm16), "$simm16", +[(int_amdgcn_s_ttracedata_imm timm:$simm16)]>; } // End SubtargetPredicate = isGFX10Plus let SubtargetPredicate = isGFX11Plus in { diff --git a/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.s.ttracedata.ll b/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.s.ttracedata.ll new file mode 100644 index 000..37b5357950e648b --- /dev/null +++ b/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.s.ttracedata.ll @@ -0,0 +1,53 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 3 +; RUN: llc -global-isel=0 -march=amdgcn -mcpu=gfx1100 -verify-machineinstrs < %s | FileCheck -check-prefixes=GFX11,GFX11-SDAG %s +; RUN: llc -global-isel=1 -march=amdgcn -mcpu=gfx1100 -verify-machineinstrs < %s | FileCheck -check-prefixes=GFX11,GFX11-GISEL %s + +declare void @llvm.amdgcn.s.ttracedata(i32) +declare void @llvm.amdgcn.s.ttracedata.imm(i16) + +define
[clang] [llvm] [NFC] Remove Type::getInt8PtrTy (PR #71029)
pmatos wrote: > I still think all the defaulted address space parameters should be purged and > it only invites bugs. It's a regression to introduce a new defaulted argument. Understandable, although always writing `PointerType::get(Ctx, 0);` really looks weird given most of the time the second parameter is 0. So it just feels like it's a special constant that will suddenly be sprinkled all over the code. https://github.com/llvm/llvm-project/pull/71029 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D154396: [clang] Add support for SerenityOS
brad added inline comments. Comment at: clang/lib/Driver/ToolChains/Serenity.cpp:202 + addSystemInclude(DriverArgs, CC1Args, + concat(D.SysRoot, "/usr/local/include")); + addSystemInclude(DriverArgs, CC1Args, concat(D.SysRoot, "/usr/include")); IMO if the library path is removed then the header path should be as well. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D154396/new/ https://reviews.llvm.org/D154396 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D154396: [clang] Add support for SerenityOS
brad added a comment. But the rest LGTM as a start. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D154396/new/ https://reviews.llvm.org/D154396 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[flang] [clang] WIP: [flang] Enable fir alias tags pass by default when optimizing for speed (PR #68597)
tblah wrote: Hi @vzakhari, currently there is a serious performance regression in spec2017 exchange2. With the TBAA tags we produce slightly better code (less repeated loads, hoisting some code out of loops, etc). Unfortunately, this change to the generated code causes LLVM's function specialization pass to incorrectly judge that specialization will not be profitable, leading to the large performance regression. @Leporacanthicus is working on this now. If you're happy, I think we can enable the tbaa tags by default after that. https://github.com/llvm/llvm-project/pull/68597 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] [clang-tools-extra] [AMDGPU] New ttracedata intrinsics (PR #70235)
https://github.com/jayfoad closed https://github.com/llvm/llvm-project/pull/70235 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [NFC][clang-tidy]refactor isAssignmentToMemberOf in PreferMemberInitializerCheck (PR #71006)
https://github.com/HerrCai0907 updated https://github.com/llvm/llvm-project/pull/71006 >From 69b7688f56f7fe96031201eef1c3804f391c5abe Mon Sep 17 00:00:00 2001 From: Congcong Cai Date: Thu, 2 Nov 2023 08:49:22 +0800 Subject: [PATCH 1/2] [NFC][clang-tidy]refactor isAssignmentToMemberOf in PreferMemberInitializerCheck --- .../PreferMemberInitializerCheck.cpp | 29 ++- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp index b6daf8b936bde0f..f0070265e6a734a 100644 --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp @@ -118,45 +118,45 @@ static void updateAssignmentLevel( } } -static std::pair +static std::optional> isAssignmentToMemberOf(const CXXRecordDecl *Rec, const Stmt *S, const CXXConstructorDecl *Ctor) { if (const auto *BO = dyn_cast(S)) { if (BO->getOpcode() != BO_Assign) - return std::make_pair(nullptr, nullptr); + return {}; const auto *ME = dyn_cast(BO->getLHS()->IgnoreParenImpCasts()); if (!ME) - return std::make_pair(nullptr, nullptr); + return {}; const auto *Field = dyn_cast(ME->getMemberDecl()); if (!Field) - return std::make_pair(nullptr, nullptr); + return {}; if (!isa(ME->getBase())) - return std::make_pair(nullptr, nullptr); + return {}; const Expr *Init = BO->getRHS()->IgnoreParenImpCasts(); return std::make_pair(Field, Init); } if (const auto *COCE = dyn_cast(S)) { if (COCE->getOperator() != OO_Equal) - return std::make_pair(nullptr, nullptr); + return {}; const auto *ME = dyn_cast(COCE->getArg(0)->IgnoreParenImpCasts()); if (!ME) - return std::make_pair(nullptr, nullptr); + return {}; const auto *Field = dyn_cast(ME->getMemberDecl()); if (!Field) - return std::make_pair(nullptr, nullptr); + return {}; if (!isa(ME->getBase())) - return std::make_pair(nullptr, nullptr); + return {}; const Expr *Init = COCE->getArg(1)->IgnoreParenImpCasts(); return std::make_pair(Field, Init); } - return std::make_pair(nullptr, nullptr); + return {}; } PreferMemberInitializerCheck::PreferMemberInitializerCheck( @@ -216,11 +216,12 @@ void PreferMemberInitializerCheck::check( return; } -const FieldDecl *Field = nullptr; -const Expr *InitValue = nullptr; -std::tie(Field, InitValue) = isAssignmentToMemberOf(Class, S, Ctor); -if (!Field) +std::optional> +AssignmentToMember = isAssignmentToMemberOf(Class, S, Ctor); +if (!AssignmentToMember) continue; +const FieldDecl *Field = AssignmentToMember.value().first; +const Expr *InitValue = AssignmentToMember.value().second; updateAssignmentLevel(Field, InitValue, Ctor, AssignedFields); if (!canAdvanceAssignment(AssignedFields[Field])) continue; >From 02201dba276c8d11f324af01ef01d06a04324a4d Mon Sep 17 00:00:00 2001 From: Congcong Cai Date: Thu, 2 Nov 2023 18:44:01 +0800 Subject: [PATCH 2/2] refactor --- .../PreferMemberInitializerCheck.cpp | 19 --- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp index f0070265e6a734a..23d7303371529da 100644 --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp @@ -118,7 +118,12 @@ static void updateAssignmentLevel( } } -static std::optional> +struct AssignmentPair { + const FieldDecl *Field; + const Expr *Init; +}; + +static std::optional isAssignmentToMemberOf(const CXXRecordDecl *Rec, const Stmt *S, const CXXConstructorDecl *Ctor) { if (const auto *BO = dyn_cast(S)) { @@ -136,7 +141,7 @@ isAssignmentToMemberOf(const CXXRecordDecl *Rec, const Stmt *S, if (!isa(ME->getBase())) return {}; const Expr *Init = BO->getRHS()->IgnoreParenImpCasts(); -return std::make_pair(Field, Init); +return AssignmentPair{Field, Init}; } if (const auto *COCE = dyn_cast(S)) { if (COCE->getOperator() != OO_Equal) @@ -154,7 +159,7 @@ isAssignmentToMemberOf(const CXXRecordDecl *Rec, const Stmt *S, if (!isa(ME->getBase())) return {}; const Expr *Init = COCE->getArg(1)->IgnoreParenImpCasts(); -return std::make_pair(Field, Init); +return AssignmentPair{Field, Init}; } return {}; } @@ -216,12 +221,12 @@ void PreferMemberInitializerCheck::check( return; } -std::optional> -Assignme
[flang] [mlir] [clang] [libcxx] [llvm] [lldb] [Flang][OpenMP] Port openmp threadprivate-use-association.f90 test to HLFIR flow (PR #71043)
https://github.com/chandankds created https://github.com/llvm/llvm-project/pull/71043 None >From 029b1687e5217e73655442b319a482865587277b Mon Sep 17 00:00:00 2001 From: chandan singh <36783761+chandan...@users.noreply.github.com> Date: Thu, 2 Nov 2023 11:53:03 +0530 Subject: [PATCH 1/2] [Flang][OpenMP] Port OpenMP threadprivate tests to hlfir flow --- .../OpenMP/threadprivate-use-association.f90 | 74 +++ 1 file changed, 74 insertions(+) create mode 100644 flang/test/Lower/OpenMP/threadprivate-use-association.f90 diff --git a/flang/test/Lower/OpenMP/threadprivate-use-association.f90 b/flang/test/Lower/OpenMP/threadprivate-use-association.f90 new file mode 100644 index 000..71d454bb39ce1d1 --- /dev/null +++ b/flang/test/Lower/OpenMP/threadprivate-use-association.f90 @@ -0,0 +1,74 @@ +! This test checks lowering of OpenMP Threadprivate Directive. +! Test for threadprivate variable in use association. + +!RUN: %flang_fc1 -emit-fir -fopenmp %s -o - | FileCheck %s + +!CHECK-DAG: fir.global common @blk_(dense<0> : vector<24xi8>) : !fir.array<24xi8> +!CHECK-DAG: fir.global @_QMtestEy : f32 { + +module test + integer :: x + real :: y, z(5) + common /blk/ x, z + + !$omp threadprivate(y, /blk/) + +contains + subroutine sub() +! CHECK-LABEL: @_QMtestPsub +!CHECK-DAG: [[ADDR0:%.*]] = fir.address_of(@blk_) : !fir.ref> +!CHECK-DAG: [[NEWADDR0:%.*]] = omp.threadprivate [[ADDR0]] : !fir.ref> -> !fir.ref> +!CHECK-DAG: [[ADDR1:%.*]] = fir.address_of(@_QMtestEy) : !fir.ref +!CHECK-DAG: [[NEWADDR1:%.*]] = omp.threadprivate [[ADDR1]] : !fir.ref -> !fir.ref + +!$omp parallel +!CHECK-DAG:[[ADDR2:%.*]] = omp.threadprivate [[ADDR0]] : !fir.ref> -> !fir.ref> +!CHECK-DAG:[[ADDR3:%.*]] = omp.threadprivate [[ADDR1]] : !fir.ref -> !fir.ref +!CHECK-DAG:[[ADDR4:%.*]] = fir.convert [[ADDR2]] : (!fir.ref>) -> !fir.ref> +!CHECK-DAG:[[ADDR5:%.*]] = fir.coordinate_of [[ADDR4]], %{{.*}} : (!fir.ref>, index) -> !fir.ref +!CHECK-DAG:[[ADDR6:%.*]] = fir.convert [[ADDR5:%.*]] : (!fir.ref) -> !fir.ref +!CHECK-DAG:[[ADDR7:%.*]] = fir.convert [[ADDR2]] : (!fir.ref>) -> !fir.ref> +!CHECK-DAG:[[ADDR8:%.*]] = fir.coordinate_of [[ADDR7]], %{{.*}} : (!fir.ref>, index) -> !fir.ref +!CHECK-DAG:[[ADDR9:%.*]] = fir.convert [[ADDR8:%.*]] : (!fir.ref) -> !fir.ref> +!CHECK-DAG:%{{.*}} = fir.load [[ADDR6]] : !fir.ref +!CHECK-DAG:%{{.*}} = fir.load [[ADDR3]] : !fir.ref +!CHECK-DAG:%{{.*}} = fir.embox [[ADDR9]](%{{.*}}) : (!fir.ref>, !fir.shape<1>) -> !fir.box> + print *, x, y, z +!$omp end parallel + end +end + +program main + use test + integer :: x1 + real :: z1(5) + common /blk/ x1, z1 + + !$omp threadprivate(/blk/) + + call sub() + +! CHECK-LABEL: @_QQmain() +!CHECK-DAG: [[ADDR0:%.*]] = fir.address_of(@blk_) : !fir.ref> +!CHECK-DAG: [[NEWADDR0:%.*]] = omp.threadprivate [[ADDR0]] : !fir.ref> -> !fir.ref> +!CHECK-DAG: [[ADDR1:%.*]] = fir.address_of(@blk_) : !fir.ref> +!CHECK-DAG: [[NEWADDR1:%.*]] = omp.threadprivate [[ADDR1]] : !fir.ref> -> !fir.ref> +!CHECK-DAG: [[ADDR2:%.*]] = fir.address_of(@_QMtestEy) : !fir.ref +!CHECK-DAG: [[NEWADDR2:%.*]] = omp.threadprivate [[ADDR2]] : !fir.ref -> !fir.ref + + !$omp parallel +!CHECK-DAG:[[ADDR4:%.*]] = omp.threadprivate [[ADDR1]] : !fir.ref> -> !fir.ref> +!CHECK-DAG:[[ADDR5:%.*]] = omp.threadprivate [[ADDR2]] : !fir.ref -> !fir.ref +!CHECK-DAG:[[ADDR6:%.*]] = fir.convert [[ADDR4]] : (!fir.ref>) -> !fir.ref> +!CHECK-DAG:[[ADDR7:%.*]] = fir.coordinate_of [[ADDR6]], %{{.*}} : (!fir.ref>, index) -> !fir.ref +!CHECK-DAG:[[ADDR8:%.*]] = fir.convert [[ADDR7:%.*]] : (!fir.ref) -> !fir.ref +!CHECK-DAG:[[ADDR9:%.*]] = fir.convert [[ADDR4]] : (!fir.ref>) -> !fir.ref> +!CHECK-DAG:[[ADDR10:%.*]] = fir.coordinate_of [[ADDR9]], %{{.*}} : (!fir.ref>, index) -> !fir.ref +!CHECK-DAG:[[ADDR11:%.*]] = fir.convert [[ADDR10:%.*]] : (!fir.ref) -> !fir.ref> +!CHECK-DAG:%{{.*}} = fir.load [[ADDR8]] : !fir.ref +!CHECK-DAG:%{{.*}} = fir.load [[ADDR5]] : !fir.ref +!CHECK-DAG:%{{.*}} = fir.embox [[ADDR11]](%{{.*}}) : (!fir.ref>, !fir.shape<1>) -> !fir.box> +print *, x1, y, z1 + !$omp end parallel + +end >From 85fd277116be1d59dd548b73f136a6f2c748dcba Mon Sep 17 00:00:00 2001 From: chandan singh <36783761+chandan...@users.noreply.github.com> Date: Thu, 2 Nov 2023 11:57:40 +0530 Subject: [PATCH 2/2] [Flang][OpenMP] Port openmp threadprivate-use-association.f90 test to HLFIR flow --- .../OpenMP/threadprivate-use-association.f90 | 56 +++ 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/flang/test/Lower/OpenMP/threadprivate-use-association.f90 b/flang/test/Lower/OpenMP/threadprivate-use-association.f90 index 71d454bb39ce1d1..d0d461547db2f68 100644 --- a/flang/test/Lower/OpenMP/threadprivate-use-association.f90 +++ b/flang/test/Lower/OpenMP/threadprivate-use-association.f90 @@ -1,7 +1,7 @@ ! This test checks lowering of Op
[llvm] [clang] [AMDGPU] Add code model (#70760) test for amdgpu target. (PR #71019)
https://github.com/pravinjagtap updated https://github.com/llvm/llvm-project/pull/71019 >From ef0118818249da417706db7f8e7086d051d17d50 Mon Sep 17 00:00:00 2001 From: Pravin Jagtap Date: Thu, 2 Nov 2023 01:05:35 -0400 Subject: [PATCH 1/3] [AMDGPU] Add code model (#70760) test for amdgpu target. --- llvm/test/CodeGen/AMDGPU/codemodel.ll | 9 + 1 file changed, 9 insertions(+) create mode 100644 llvm/test/CodeGen/AMDGPU/codemodel.ll diff --git a/llvm/test/CodeGen/AMDGPU/codemodel.ll b/llvm/test/CodeGen/AMDGPU/codemodel.ll new file mode 100644 index 000..8b60257b2076aed --- /dev/null +++ b/llvm/test/CodeGen/AMDGPU/codemodel.ll @@ -0,0 +1,9 @@ +; RUN: not llc -verify-machineinstrs -o - -mtriple=amdgcn-unknown-amdhsa -mcpu=gfx900 -code-model=tiny < %s 2>&1 | FileCheck %s --check-prefix=TINY +; RUN: not llc -verify-machineinstrs -o - -mtriple=amdgcn-unknown-amdhsa -mcpu=gfx900 -code-model=kernel < %s 2>&1 | FileCheck %s --check-prefix=KERNEL + +; TINY:Target does not support the tiny CodeModel +; KERNEL:Target does not support the kernel CodeModel + +define void @foo() { + ret void +} >From f4c4ec2dd7829267b0df84a2a651b98e9c18a4e0 Mon Sep 17 00:00:00 2001 From: Pravin Jagtap Date: Thu, 2 Nov 2023 05:51:50 -0400 Subject: [PATCH 2/3] Added clang driver test for code model. --- clang/test/Driver/mcmodel.c | 10 ++ 1 file changed, 10 insertions(+) diff --git a/clang/test/Driver/mcmodel.c b/clang/test/Driver/mcmodel.c index fb3bbccb0c68157..d546d5d81db5261 100644 --- a/clang/test/Driver/mcmodel.c +++ b/clang/test/Driver/mcmodel.c @@ -13,6 +13,11 @@ // RUN: not %clang -### -c --target=aarch64 -mcmodel=medium %s 2>&1 | FileCheck --check-prefix=ERR-MEDIUM %s // RUN: not %clang -### -c --target=aarch64 -mcmodel=kernel %s 2>&1 | FileCheck --check-prefix=ERR-KERNEL %s // RUN: not %clang --target=aarch64_32-linux -### -S -mcmodel=small %s 2>&1 | FileCheck --check-prefix=ERR-AARCH64_32 %s +// RUN: %clang --target=amdgcn-amd-amdhsa -nogpulib -### -c -mcmodel=tiny %s 2>&1 | FileCheck --check-prefix=AMDGPU-MCMODEL-TINY %s +// RUN: %clang --target=amdgcn-amd-amdhsa -nogpulib -### -c -mcmodel=small %s 2>&1 | FileCheck --check-prefix=AMDGPU-MCMODEL-SMALL %s +// RUN: %clang --target=amdgcn-amd-amdhsa -nogpulib -### -S -mcmodel=kernel %s 2>&1 | FileCheck --check-prefix=AMDGPU-MCMODEL-KERNEL %s +// RUN: %clang --target=amdgcn-amd-amdhsa -nogpulib -### -c -mcmodel=medium %s 2>&1 | FileCheck --check-prefix=AMDGPU-MCMODEL-MEDIUM %s +// RUN: %clang --target=amdgcn-amd-amdhsa -nogpulib -### -S -mcmodel=large %s 2>&1 | FileCheck --check-prefix=AMDGPU-MCMODEL-LARGE %s // TINY: "-mcmodel=tiny" // SMALL: "-mcmodel=small" @@ -29,3 +34,8 @@ // AARCH64-PIC-LARGE: error: invalid argument '-mcmodel=large' only allowed with '-fno-pic' // ERR-AARCH64_32: error: unsupported argument 'small' to option '-mcmodel=' for target 'aarch64_32-unknown-linux' +// AMDGPU-MCMODEL-TINY: "-mcmodel=tiny" +// AMDGPU-MCMODEL-SMALL: "-mcmodel=small" +// AMDGPU-MCMODEL-KERNEL: "-mcmodel=kernel" +// AMDGPU-MCMODEL-MEDIUM: "-mcmodel=medium" +// AMDGPU-MCMODEL-LARGE: "-mcmodel=large" >From 9dc7689983b74dd381df556bc9e61165e08d85b4 Mon Sep 17 00:00:00 2001 From: Pravin Jagtap Date: Thu, 2 Nov 2023 06:46:22 -0400 Subject: [PATCH 3/3] Updated the mcodel test to target hip --- clang/test/Driver/mcmodel.c | 10 +- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/clang/test/Driver/mcmodel.c b/clang/test/Driver/mcmodel.c index d546d5d81db5261..ab7207252452b47 100644 --- a/clang/test/Driver/mcmodel.c +++ b/clang/test/Driver/mcmodel.c @@ -13,11 +13,11 @@ // RUN: not %clang -### -c --target=aarch64 -mcmodel=medium %s 2>&1 | FileCheck --check-prefix=ERR-MEDIUM %s // RUN: not %clang -### -c --target=aarch64 -mcmodel=kernel %s 2>&1 | FileCheck --check-prefix=ERR-KERNEL %s // RUN: not %clang --target=aarch64_32-linux -### -S -mcmodel=small %s 2>&1 | FileCheck --check-prefix=ERR-AARCH64_32 %s -// RUN: %clang --target=amdgcn-amd-amdhsa -nogpulib -### -c -mcmodel=tiny %s 2>&1 | FileCheck --check-prefix=AMDGPU-MCMODEL-TINY %s -// RUN: %clang --target=amdgcn-amd-amdhsa -nogpulib -### -c -mcmodel=small %s 2>&1 | FileCheck --check-prefix=AMDGPU-MCMODEL-SMALL %s -// RUN: %clang --target=amdgcn-amd-amdhsa -nogpulib -### -S -mcmodel=kernel %s 2>&1 | FileCheck --check-prefix=AMDGPU-MCMODEL-KERNEL %s -// RUN: %clang --target=amdgcn-amd-amdhsa -nogpulib -### -c -mcmodel=medium %s 2>&1 | FileCheck --check-prefix=AMDGPU-MCMODEL-MEDIUM %s -// RUN: %clang --target=amdgcn-amd-amdhsa -nogpulib -### -S -mcmodel=large %s 2>&1 | FileCheck --check-prefix=AMDGPU-MCMODEL-LARGE %s +// RUN: %clang --offload-arch=gfx906 -nogpulib -### -c -x hip -mcmodel=tiny %s 2>&1 | FileCheck --check-prefix=AMDGPU-MCMODEL-TINY %s +// RUN: %clang --offload-arch=gfx906 -nogpulib -### -c -x hip -mcmodel=small %s 2>&1 | FileCheck --check-prefix=AMDGPU-MCMODEL-SMALL %s +// RUN: %clang --offload-arch=gfx906 -nogpulib -### -S -
[llvm] [clang] [AMDGPU] Add code model (#70760) test for amdgpu target. (PR #71019)
@@ -13,6 +13,11 @@ // RUN: not %clang -### -c --target=aarch64 -mcmodel=medium %s 2>&1 | FileCheck --check-prefix=ERR-MEDIUM %s // RUN: not %clang -### -c --target=aarch64 -mcmodel=kernel %s 2>&1 | FileCheck --check-prefix=ERR-KERNEL %s // RUN: not %clang --target=aarch64_32-linux -### -S -mcmodel=small %s 2>&1 | FileCheck --check-prefix=ERR-AARCH64_32 %s +// RUN: %clang --target=amdgcn-amd-amdhsa -nogpulib -### -c -mcmodel=tiny %s 2>&1 | FileCheck --check-prefix=AMDGPU-MCMODEL-TINY %s pravinjagtap wrote: The change is intended to handle all possible code models for AMDGPU target. Basically, we want to avoid erroring out for device side code models. Does it make sense to have negative case for amdgpu ? https://github.com/llvm/llvm-project/pull/71019 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[flang] [mlir] [clang] [Flang][OpenMP][MLIR] Add support for -nogpulib option (PR #71045)
https://github.com/DominikAdamski created https://github.com/llvm/llvm-project/pull/71045 If -nogpulib option is passed by the user, then the OpenMP device runtime is not used and we should not emit globals to configure debugging at compile-time for the device runtime. Link to -nogpulib flag implementation for Clang: https://reviews.llvm.org/D125314 >From 684ade39bda46edd6392521cc63902486659559b Mon Sep 17 00:00:00 2001 From: Dominik Adamski Date: Tue, 31 Oct 2023 08:06:59 -0500 Subject: [PATCH 1/2] [MLIR][OpenMP] Add nogpulib parameter to OpenMP attributes Added an OpenMP attribute which will model nogpulib flag. If nogpulib option is passed by the user, then the OpenMP device runtime is not used and we should not emit globals to configure debugging at compile-time for the device runtime. Link to -nogpulib flag implementation for Clang: https://reviews.llvm.org/D125314 --- flang/include/flang/Tools/CrossToolHelpers.h | 11 +++ mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td | 1 + .../mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td| 5 +++-- .../Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp | 8 ++-- mlir/test/Dialect/OpenMP/attr.mlir| 6 ++ mlir/test/Target/LLVMIR/openmp-llvm.mlir | 10 ++ 6 files changed, 33 insertions(+), 8 deletions(-) diff --git a/flang/include/flang/Tools/CrossToolHelpers.h b/flang/include/flang/Tools/CrossToolHelpers.h index ddec70fa9824c52..a1f5c871992a1f8 100644 --- a/flang/include/flang/Tools/CrossToolHelpers.h +++ b/flang/include/flang/Tools/CrossToolHelpers.h @@ -53,14 +53,16 @@ struct OffloadModuleOpts { OffloadModuleOpts(uint32_t OpenMPTargetDebug, bool OpenMPTeamSubscription, bool OpenMPThreadSubscription, bool OpenMPNoThreadState, bool OpenMPNoNestedParallelism, bool OpenMPIsTargetDevice, - bool OpenMPIsGPU, uint32_t OpenMPVersion, std::string OMPHostIRFile = {}) + bool OpenMPIsGPU, uint32_t OpenMPVersion, std::string OMPHostIRFile = {}, + bool NoGPULib = false) : OpenMPTargetDebug(OpenMPTargetDebug), OpenMPTeamSubscription(OpenMPTeamSubscription), OpenMPThreadSubscription(OpenMPThreadSubscription), OpenMPNoThreadState(OpenMPNoThreadState), OpenMPNoNestedParallelism(OpenMPNoNestedParallelism), OpenMPIsTargetDevice(OpenMPIsTargetDevice), OpenMPIsGPU(OpenMPIsGPU), -OpenMPVersion(OpenMPVersion), OMPHostIRFile(OMPHostIRFile) {} +OpenMPVersion(OpenMPVersion), OMPHostIRFile(OMPHostIRFile), +NoGPULib(NoGPULib) {} OffloadModuleOpts(Fortran::frontend::LangOptions &Opts) : OpenMPTargetDebug(Opts.OpenMPTargetDebug), @@ -70,7 +72,7 @@ struct OffloadModuleOpts { OpenMPNoNestedParallelism(Opts.OpenMPNoNestedParallelism), OpenMPIsTargetDevice(Opts.OpenMPIsTargetDevice), OpenMPIsGPU(Opts.OpenMPIsGPU), OpenMPVersion(Opts.OpenMPVersion), -OMPHostIRFile(Opts.OMPHostIRFile) {} +OMPHostIRFile(Opts.OMPHostIRFile), NoGPULib(false) {} uint32_t OpenMPTargetDebug = 0; bool OpenMPTeamSubscription = false; @@ -81,6 +83,7 @@ struct OffloadModuleOpts { bool OpenMPIsGPU = false; uint32_t OpenMPVersion = 11; std::string OMPHostIRFile = {}; + bool NoGPULib = false; }; // Shares assinging of the OpenMP OffloadModuleInterface and its assorted @@ -95,7 +98,7 @@ void setOffloadModuleInterfaceAttributes( if (Opts.OpenMPIsTargetDevice) { offloadMod.setFlags(Opts.OpenMPTargetDebug, Opts.OpenMPTeamSubscription, Opts.OpenMPThreadSubscription, Opts.OpenMPNoThreadState, - Opts.OpenMPNoNestedParallelism, Opts.OpenMPVersion); + Opts.OpenMPNoNestedParallelism, Opts.OpenMPVersion, false); if (!Opts.OMPHostIRFile.empty()) offloadMod.setHostIRFilePath(Opts.OMPHostIRFile); diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td index 72121ad4f9e47a5..ae2dd018059e3aa 100644 --- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td +++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td @@ -65,6 +65,7 @@ def FlagsAttr : OpenMP_Attr<"Flags", "flags"> { DefaultValuedParameter<"bool", "false">:$assume_threads_oversubscription, DefaultValuedParameter<"bool", "false">:$assume_no_thread_state, DefaultValuedParameter<"bool", "false">:$assume_no_nested_parallelism, +DefaultValuedParameter<"bool", "false">:$no_gpu_lib, DefaultValuedParameter<"uint32_t", "50">:$openmp_device_version ); diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td b/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td index 77001fc816cf91f..89d04af64766fc2 100644 --- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td +++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td @@ -198,11 +198,12 @@ def OffloadModuleInterface : OpInterface<"OffloadModuleInterface"> { "bool":$assumeThreadsOversubscription,
[flang] [mlir] [clang] [Flang][OpenMP][MLIR] Add support for -nogpulib option (PR #71045)
llvmbot wrote: @llvm/pr-subscribers-clang-driver @llvm/pr-subscribers-mlir Author: Dominik Adamski (DominikAdamski) Changes If -nogpulib option is passed by the user, then the OpenMP device runtime is not used and we should not emit globals to configure debugging at compile-time for the device runtime. Link to -nogpulib flag implementation for Clang: https://reviews.llvm.org/D125314 --- Full diff: https://github.com/llvm/llvm-project/pull/71045.diff 14 Files Affected: - (modified) clang/include/clang/Driver/Options.td (+1-1) - (modified) clang/lib/Driver/ToolChains/Flang.cpp (+2) - (modified) flang/include/flang/Frontend/LangOptions.def (+2) - (modified) flang/include/flang/Tools/CrossToolHelpers.h (+7-4) - (modified) flang/lib/Frontend/CompilerInvocation.cpp (+2) - (modified) flang/test/Driver/driver-help-hidden.f90 (+1) - (modified) flang/test/Driver/driver-help.f90 (+2) - (added) flang/test/Lower/OpenMP/nogpulib.f90 (+12) - (modified) flang/tools/bbc/bbc.cpp (+7-1) - (modified) mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td (+1) - (modified) mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td (+3-2) - (modified) mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp (+6-2) - (modified) mlir/test/Dialect/OpenMP/attr.mlir (+6) - (modified) mlir/test/Target/LLVMIR/openmp-llvm.mlir (+10) ``diff diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index b1229b2f4562379..cc50b45b7933d5f 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -5092,7 +5092,7 @@ def nohipwrapperinc : Flag<["-"], "nohipwrapperinc">, Group, HelpText<"Do not include the default HIP wrapper headers and include paths">; def : Flag<["-"], "nocudainc">, Alias; def nogpulib : Flag<["-"], "nogpulib">, MarshallingInfoFlag>, - Visibility<[ClangOption, CC1Option]>, + Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>, HelpText<"Do not link device library for CUDA/HIP device compilation">; def : Flag<["-"], "nocudalib">, Alias; def gpulibc : Flag<["-"], "gpulibc">, Visibility<[ClangOption, CC1Option]>, diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp index 999039f83ddfb92..17d9ac7632128d6 100644 --- a/clang/lib/Driver/ToolChains/Flang.cpp +++ b/clang/lib/Driver/ToolChains/Flang.cpp @@ -295,6 +295,8 @@ void Flang::addOffloadOptions(Compilation &C, const InputInfoList &Inputs, CmdArgs.push_back("-fopenmp-assume-no-thread-state"); if (Args.hasArg(options::OPT_fopenmp_assume_no_nested_parallelism)) CmdArgs.push_back("-fopenmp-assume-no-nested-parallelism"); +if (Args.hasArg(options::OPT_nogpulib)) + CmdArgs.push_back("-nogpulib"); } } diff --git a/flang/include/flang/Frontend/LangOptions.def b/flang/include/flang/Frontend/LangOptions.def index 3a1d44f7fb472d1..2bf10826120a8bd 100644 --- a/flang/include/flang/Frontend/LangOptions.def +++ b/flang/include/flang/Frontend/LangOptions.def @@ -21,6 +21,8 @@ LANGOPT(Name, Bits, Default) ENUM_LANGOPT(FPContractMode, FPModeKind, 2, FPM_Fast) ///< FP Contract Mode (off/fast) +/// Indicate a build without the standard GPU libraries. +LANGOPT(NoGPULib , 1, false) /// Permit floating point optimization without regard to infinities LANGOPT(NoHonorInfs, 1, false) /// Permit floating point optimization without regard to NaN diff --git a/flang/include/flang/Tools/CrossToolHelpers.h b/flang/include/flang/Tools/CrossToolHelpers.h index ddec70fa9824c52..3b51a3845625df3 100644 --- a/flang/include/flang/Tools/CrossToolHelpers.h +++ b/flang/include/flang/Tools/CrossToolHelpers.h @@ -53,14 +53,16 @@ struct OffloadModuleOpts { OffloadModuleOpts(uint32_t OpenMPTargetDebug, bool OpenMPTeamSubscription, bool OpenMPThreadSubscription, bool OpenMPNoThreadState, bool OpenMPNoNestedParallelism, bool OpenMPIsTargetDevice, - bool OpenMPIsGPU, uint32_t OpenMPVersion, std::string OMPHostIRFile = {}) + bool OpenMPIsGPU, uint32_t OpenMPVersion, std::string OMPHostIRFile = {}, + bool NoGPULib = false) : OpenMPTargetDebug(OpenMPTargetDebug), OpenMPTeamSubscription(OpenMPTeamSubscription), OpenMPThreadSubscription(OpenMPThreadSubscription), OpenMPNoThreadState(OpenMPNoThreadState), OpenMPNoNestedParallelism(OpenMPNoNestedParallelism), OpenMPIsTargetDevice(OpenMPIsTargetDevice), OpenMPIsGPU(OpenMPIsGPU), -OpenMPVersion(OpenMPVersion), OMPHostIRFile(OMPHostIRFile) {} +OpenMPVersion(OpenMPVersion), OMPHostIRFile(OMPHostIRFile), +NoGPULib(NoGPULib) {} OffloadModuleOpts(Fortran::frontend::LangOptions &Opts) : OpenMPTargetDebug(Opts.OpenMPTargetDebug), @@ -70,7 +72,7 @@ struct OffloadModuleOpts { OpenMPNoNestedParallelism(Opts.OpenMPNoNestedParallelism), OpenMPIsTargetDevice(Opts.OpenMPIsTargetDevice), OpenMPIsGPU(Opts.OpenMPIsGPU), OpenMPVers
[flang] [mlir] [clang] [Flang][OpenMP][MLIR] Add support for -nogpulib option (PR #71045)
llvmbot wrote: @llvm/pr-subscribers-mlir-llvm Author: Dominik Adamski (DominikAdamski) Changes If -nogpulib option is passed by the user, then the OpenMP device runtime is not used and we should not emit globals to configure debugging at compile-time for the device runtime. Link to -nogpulib flag implementation for Clang: https://reviews.llvm.org/D125314 --- Full diff: https://github.com/llvm/llvm-project/pull/71045.diff 14 Files Affected: - (modified) clang/include/clang/Driver/Options.td (+1-1) - (modified) clang/lib/Driver/ToolChains/Flang.cpp (+2) - (modified) flang/include/flang/Frontend/LangOptions.def (+2) - (modified) flang/include/flang/Tools/CrossToolHelpers.h (+7-4) - (modified) flang/lib/Frontend/CompilerInvocation.cpp (+2) - (modified) flang/test/Driver/driver-help-hidden.f90 (+1) - (modified) flang/test/Driver/driver-help.f90 (+2) - (added) flang/test/Lower/OpenMP/nogpulib.f90 (+12) - (modified) flang/tools/bbc/bbc.cpp (+7-1) - (modified) mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td (+1) - (modified) mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td (+3-2) - (modified) mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp (+6-2) - (modified) mlir/test/Dialect/OpenMP/attr.mlir (+6) - (modified) mlir/test/Target/LLVMIR/openmp-llvm.mlir (+10) ``diff diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index b1229b2f4562379..cc50b45b7933d5f 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -5092,7 +5092,7 @@ def nohipwrapperinc : Flag<["-"], "nohipwrapperinc">, Group, HelpText<"Do not include the default HIP wrapper headers and include paths">; def : Flag<["-"], "nocudainc">, Alias; def nogpulib : Flag<["-"], "nogpulib">, MarshallingInfoFlag>, - Visibility<[ClangOption, CC1Option]>, + Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>, HelpText<"Do not link device library for CUDA/HIP device compilation">; def : Flag<["-"], "nocudalib">, Alias; def gpulibc : Flag<["-"], "gpulibc">, Visibility<[ClangOption, CC1Option]>, diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp index 999039f83ddfb92..17d9ac7632128d6 100644 --- a/clang/lib/Driver/ToolChains/Flang.cpp +++ b/clang/lib/Driver/ToolChains/Flang.cpp @@ -295,6 +295,8 @@ void Flang::addOffloadOptions(Compilation &C, const InputInfoList &Inputs, CmdArgs.push_back("-fopenmp-assume-no-thread-state"); if (Args.hasArg(options::OPT_fopenmp_assume_no_nested_parallelism)) CmdArgs.push_back("-fopenmp-assume-no-nested-parallelism"); +if (Args.hasArg(options::OPT_nogpulib)) + CmdArgs.push_back("-nogpulib"); } } diff --git a/flang/include/flang/Frontend/LangOptions.def b/flang/include/flang/Frontend/LangOptions.def index 3a1d44f7fb472d1..2bf10826120a8bd 100644 --- a/flang/include/flang/Frontend/LangOptions.def +++ b/flang/include/flang/Frontend/LangOptions.def @@ -21,6 +21,8 @@ LANGOPT(Name, Bits, Default) ENUM_LANGOPT(FPContractMode, FPModeKind, 2, FPM_Fast) ///< FP Contract Mode (off/fast) +/// Indicate a build without the standard GPU libraries. +LANGOPT(NoGPULib , 1, false) /// Permit floating point optimization without regard to infinities LANGOPT(NoHonorInfs, 1, false) /// Permit floating point optimization without regard to NaN diff --git a/flang/include/flang/Tools/CrossToolHelpers.h b/flang/include/flang/Tools/CrossToolHelpers.h index ddec70fa9824c52..3b51a3845625df3 100644 --- a/flang/include/flang/Tools/CrossToolHelpers.h +++ b/flang/include/flang/Tools/CrossToolHelpers.h @@ -53,14 +53,16 @@ struct OffloadModuleOpts { OffloadModuleOpts(uint32_t OpenMPTargetDebug, bool OpenMPTeamSubscription, bool OpenMPThreadSubscription, bool OpenMPNoThreadState, bool OpenMPNoNestedParallelism, bool OpenMPIsTargetDevice, - bool OpenMPIsGPU, uint32_t OpenMPVersion, std::string OMPHostIRFile = {}) + bool OpenMPIsGPU, uint32_t OpenMPVersion, std::string OMPHostIRFile = {}, + bool NoGPULib = false) : OpenMPTargetDebug(OpenMPTargetDebug), OpenMPTeamSubscription(OpenMPTeamSubscription), OpenMPThreadSubscription(OpenMPThreadSubscription), OpenMPNoThreadState(OpenMPNoThreadState), OpenMPNoNestedParallelism(OpenMPNoNestedParallelism), OpenMPIsTargetDevice(OpenMPIsTargetDevice), OpenMPIsGPU(OpenMPIsGPU), -OpenMPVersion(OpenMPVersion), OMPHostIRFile(OMPHostIRFile) {} +OpenMPVersion(OpenMPVersion), OMPHostIRFile(OMPHostIRFile), +NoGPULib(NoGPULib) {} OffloadModuleOpts(Fortran::frontend::LangOptions &Opts) : OpenMPTargetDebug(Opts.OpenMPTargetDebug), @@ -70,7 +72,7 @@ struct OffloadModuleOpts { OpenMPNoNestedParallelism(Opts.OpenMPNoNestedParallelism), OpenMPIsTargetDevice(Opts.OpenMPIsTargetDevice), OpenMPIsGPU(Opts.OpenMPIsGPU), OpenMPVersion(Opts.OpenMPVersion), -
[flang] [clang] [mlir] [Flang][OpenMP][MLIR] Add support for -nogpulib option (PR #71045)
llvmbot wrote: @llvm/pr-subscribers-flang-driver Author: Dominik Adamski (DominikAdamski) Changes If -nogpulib option is passed by the user, then the OpenMP device runtime is not used and we should not emit globals to configure debugging at compile-time for the device runtime. Link to -nogpulib flag implementation for Clang: https://reviews.llvm.org/D125314 --- Full diff: https://github.com/llvm/llvm-project/pull/71045.diff 14 Files Affected: - (modified) clang/include/clang/Driver/Options.td (+1-1) - (modified) clang/lib/Driver/ToolChains/Flang.cpp (+2) - (modified) flang/include/flang/Frontend/LangOptions.def (+2) - (modified) flang/include/flang/Tools/CrossToolHelpers.h (+7-4) - (modified) flang/lib/Frontend/CompilerInvocation.cpp (+2) - (modified) flang/test/Driver/driver-help-hidden.f90 (+1) - (modified) flang/test/Driver/driver-help.f90 (+2) - (added) flang/test/Lower/OpenMP/nogpulib.f90 (+12) - (modified) flang/tools/bbc/bbc.cpp (+7-1) - (modified) mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td (+1) - (modified) mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td (+3-2) - (modified) mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp (+6-2) - (modified) mlir/test/Dialect/OpenMP/attr.mlir (+6) - (modified) mlir/test/Target/LLVMIR/openmp-llvm.mlir (+10) ``diff diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index b1229b2f4562379..cc50b45b7933d5f 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -5092,7 +5092,7 @@ def nohipwrapperinc : Flag<["-"], "nohipwrapperinc">, Group, HelpText<"Do not include the default HIP wrapper headers and include paths">; def : Flag<["-"], "nocudainc">, Alias; def nogpulib : Flag<["-"], "nogpulib">, MarshallingInfoFlag>, - Visibility<[ClangOption, CC1Option]>, + Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>, HelpText<"Do not link device library for CUDA/HIP device compilation">; def : Flag<["-"], "nocudalib">, Alias; def gpulibc : Flag<["-"], "gpulibc">, Visibility<[ClangOption, CC1Option]>, diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp index 999039f83ddfb92..17d9ac7632128d6 100644 --- a/clang/lib/Driver/ToolChains/Flang.cpp +++ b/clang/lib/Driver/ToolChains/Flang.cpp @@ -295,6 +295,8 @@ void Flang::addOffloadOptions(Compilation &C, const InputInfoList &Inputs, CmdArgs.push_back("-fopenmp-assume-no-thread-state"); if (Args.hasArg(options::OPT_fopenmp_assume_no_nested_parallelism)) CmdArgs.push_back("-fopenmp-assume-no-nested-parallelism"); +if (Args.hasArg(options::OPT_nogpulib)) + CmdArgs.push_back("-nogpulib"); } } diff --git a/flang/include/flang/Frontend/LangOptions.def b/flang/include/flang/Frontend/LangOptions.def index 3a1d44f7fb472d1..2bf10826120a8bd 100644 --- a/flang/include/flang/Frontend/LangOptions.def +++ b/flang/include/flang/Frontend/LangOptions.def @@ -21,6 +21,8 @@ LANGOPT(Name, Bits, Default) ENUM_LANGOPT(FPContractMode, FPModeKind, 2, FPM_Fast) ///< FP Contract Mode (off/fast) +/// Indicate a build without the standard GPU libraries. +LANGOPT(NoGPULib , 1, false) /// Permit floating point optimization without regard to infinities LANGOPT(NoHonorInfs, 1, false) /// Permit floating point optimization without regard to NaN diff --git a/flang/include/flang/Tools/CrossToolHelpers.h b/flang/include/flang/Tools/CrossToolHelpers.h index ddec70fa9824c52..3b51a3845625df3 100644 --- a/flang/include/flang/Tools/CrossToolHelpers.h +++ b/flang/include/flang/Tools/CrossToolHelpers.h @@ -53,14 +53,16 @@ struct OffloadModuleOpts { OffloadModuleOpts(uint32_t OpenMPTargetDebug, bool OpenMPTeamSubscription, bool OpenMPThreadSubscription, bool OpenMPNoThreadState, bool OpenMPNoNestedParallelism, bool OpenMPIsTargetDevice, - bool OpenMPIsGPU, uint32_t OpenMPVersion, std::string OMPHostIRFile = {}) + bool OpenMPIsGPU, uint32_t OpenMPVersion, std::string OMPHostIRFile = {}, + bool NoGPULib = false) : OpenMPTargetDebug(OpenMPTargetDebug), OpenMPTeamSubscription(OpenMPTeamSubscription), OpenMPThreadSubscription(OpenMPThreadSubscription), OpenMPNoThreadState(OpenMPNoThreadState), OpenMPNoNestedParallelism(OpenMPNoNestedParallelism), OpenMPIsTargetDevice(OpenMPIsTargetDevice), OpenMPIsGPU(OpenMPIsGPU), -OpenMPVersion(OpenMPVersion), OMPHostIRFile(OMPHostIRFile) {} +OpenMPVersion(OpenMPVersion), OMPHostIRFile(OMPHostIRFile), +NoGPULib(NoGPULib) {} OffloadModuleOpts(Fortran::frontend::LangOptions &Opts) : OpenMPTargetDebug(Opts.OpenMPTargetDebug), @@ -70,7 +72,7 @@ struct OffloadModuleOpts { OpenMPNoNestedParallelism(Opts.OpenMPNoNestedParallelism), OpenMPIsTargetDevice(Opts.OpenMPIsTargetDevice), OpenMPIsGPU(Opts.OpenMPIsGPU), OpenMPVersion(Opts.OpenMPVersion), -
[clang] [analyzer][NFC] Rework SVal kind representation (PR #71039)
https://github.com/Endilll edited https://github.com/llvm/llvm-project/pull/71039 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer][NFC] Rework SVal kind representation (PR #71039)
https://github.com/Endilll commented: Converting packed `unsigned Kind` into non-packed `SValKind Kind` is definitely going to help debuggers to display the value correctly. But I have to point out that this patch doesn't address the fact that `const void* Data` is not friendly to debuggers, especially with type information encoded in another member. So even with this patch applied, someone would still have to write (and maintain) a custom formatter on debugger side to display `Data` correctly. If you refactor `const void* Data` to be a `llvm::PointerUnion`, then it will be picked up automatically (`PointerUnion` is a popular type, so I've already written a formatter for it.) Together with removing `BaseBits` from `Kind` and making the latter non-packed, `SVal` will have a debugger-friendly layout. That said, debugger-friendliness is probably not among top priorities, so I'm not going to block this patch, if this is the direction you and reviewers want to take. https://github.com/llvm/llvm-project/pull/71039 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer][NFC] Rework SVal kind representation (PR #71039)
@@ -105,38 +86,25 @@ class SVal { return llvm::dyn_cast(*this); } - unsigned getRawKind() const { return Kind; } - BaseKind getBaseKind() const { return (BaseKind) (Kind & BaseMask); } - unsigned getSubKind() const { return Kind >> BaseBits; } + SValKind getKind() const { return Kind; } // This method is required for using SVal in a FoldingSetNode. It // extracts a unique signature for this SVal object. void Profile(llvm::FoldingSetNodeID &ID) const { -ID.AddInteger((unsigned) getRawKind()); +ID.AddInteger((unsigned)getKind()); Endilll wrote: I think recently introduced `llvm::to_underlying()` is a better fit here. https://github.com/llvm/llvm-project/pull/71039 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer][NFC] Rework SVal kind representation (PR #71039)
steakhal wrote: > But I have to point out that this patch doesn't address the fact that `const > void* Data` is not friendly to debuggers, especially with type information > encoded in another member. So even with this patch applied, someone would > still have to write (and maintain) a custom formatter on debugger side to > display `Data` correctly. That's correct. I'll think about how to resolve that as well. > If you refactor `const void* Data` to be a `llvm::PointerUnion`, then it will > be picked up automatically (`PointerUnion` is a popular type, so I've already > written a formatter for it.) Together with removing `BaseBits` from `Kind` > and making the latter non-packed, `SVal` will have a debugger-friendly layout. I've considered this but I found the number of alternatives too large to make it feasible. Consider that we have 11 possible SValKinds, which would require 4 bits to encode. Requiring all `Data` pointers to be aligned as such seems rough - although not impossible. > That said, debugger-friendliness is probably not among top priorities, so I'm > not going to block this patch, if this is the direction you and reviewers > want to take. I'd say it's one baby step in that direction, but not the end of the journey. How about looking at this like that? https://github.com/llvm/llvm-project/pull/71039 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D159497: [RFC][clangd] Check if SelectionTree is complete
ArcsinX added a comment. > One such heuristic is to check the nodes in the selection tree for the exact > line match It looks like this heuristic doesn't work well in multiline cases. E.g. int f^unc() { return 0; } will give empty result with this patch applied. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D159497/new/ https://reviews.llvm.org/D159497 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] 43e13fd - [NFC][clang-tidy]refactor isAssignmentToMemberOf in PreferMemberInitializerCheck (#71006)
Author: Congcong Cai Date: 2023-11-02T19:30:06+08:00 New Revision: 43e13fdc9e8edd425f640c424071377879c07822 URL: https://github.com/llvm/llvm-project/commit/43e13fdc9e8edd425f640c424071377879c07822 DIFF: https://github.com/llvm/llvm-project/commit/43e13fdc9e8edd425f640c424071377879c07822.diff LOG: [NFC][clang-tidy]refactor isAssignmentToMemberOf in PreferMemberInitializerCheck (#71006) Added: Modified: clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp Removed: diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp index b6daf8b936bde0f..23d7303371529da 100644 --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp @@ -118,45 +118,50 @@ static void updateAssignmentLevel( } } -static std::pair +struct AssignmentPair { + const FieldDecl *Field; + const Expr *Init; +}; + +static std::optional isAssignmentToMemberOf(const CXXRecordDecl *Rec, const Stmt *S, const CXXConstructorDecl *Ctor) { if (const auto *BO = dyn_cast(S)) { if (BO->getOpcode() != BO_Assign) - return std::make_pair(nullptr, nullptr); + return {}; const auto *ME = dyn_cast(BO->getLHS()->IgnoreParenImpCasts()); if (!ME) - return std::make_pair(nullptr, nullptr); + return {}; const auto *Field = dyn_cast(ME->getMemberDecl()); if (!Field) - return std::make_pair(nullptr, nullptr); + return {}; if (!isa(ME->getBase())) - return std::make_pair(nullptr, nullptr); + return {}; const Expr *Init = BO->getRHS()->IgnoreParenImpCasts(); -return std::make_pair(Field, Init); +return AssignmentPair{Field, Init}; } if (const auto *COCE = dyn_cast(S)) { if (COCE->getOperator() != OO_Equal) - return std::make_pair(nullptr, nullptr); + return {}; const auto *ME = dyn_cast(COCE->getArg(0)->IgnoreParenImpCasts()); if (!ME) - return std::make_pair(nullptr, nullptr); + return {}; const auto *Field = dyn_cast(ME->getMemberDecl()); if (!Field) - return std::make_pair(nullptr, nullptr); + return {}; if (!isa(ME->getBase())) - return std::make_pair(nullptr, nullptr); + return {}; const Expr *Init = COCE->getArg(1)->IgnoreParenImpCasts(); -return std::make_pair(Field, Init); +return AssignmentPair{Field, Init}; } - return std::make_pair(nullptr, nullptr); + return {}; } PreferMemberInitializerCheck::PreferMemberInitializerCheck( @@ -216,11 +221,12 @@ void PreferMemberInitializerCheck::check( return; } -const FieldDecl *Field = nullptr; -const Expr *InitValue = nullptr; -std::tie(Field, InitValue) = isAssignmentToMemberOf(Class, S, Ctor); -if (!Field) +std::optional AssignmentToMember = +isAssignmentToMemberOf(Class, S, Ctor); +if (!AssignmentToMember) continue; +const FieldDecl *Field = AssignmentToMember->Field; +const Expr *InitValue = AssignmentToMember->Init; updateAssignmentLevel(Field, InitValue, Ctor, AssignedFields); if (!canAdvanceAssignment(AssignedFields[Field])) continue; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [NFC][clang-tidy]refactor isAssignmentToMemberOf in PreferMemberInitializerCheck (PR #71006)
https://github.com/HerrCai0907 closed https://github.com/llvm/llvm-project/pull/71006 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [clang][NFC] Refactor `clang::Linkage` (PR #71049)
https://github.com/Endilll created https://github.com/llvm/llvm-project/pull/71049 This patch introduces a new enumerator `Invalid = 0`, shifting other enumerators by +1. Contrary to how it might sound, this actually affirms status quo of how this enum is stored in `clang::Decl`: ``` /// If 0, we have not computed the linkage of this declaration. /// Otherwise, it is the linkage + 1. mutable unsigned CacheValidAndLinkage : 3; ``` This patch makes debuggers to not be mistaken about enumerator stored in this bit-field. It also converts `clang::Linkage` to a scoped enum. >From 05089e60021c321b4113db7e4bdf59bdaaa19de7 Mon Sep 17 00:00:00 2001 From: Vlad Serebrennikov Date: Thu, 2 Nov 2023 14:40:12 +0300 Subject: [PATCH] [clang][NFC] Refactor `clang::Linkage` This patch introduces a new enumerator `Invalid = 0`, shifting other enumerators by +1. Contrary to how it might sound, this actually affirms status quo of how this enum is stored in `clang::Decl`: ``` /// If 0, we have not computed the linkage of this declaration. /// Otherwise, it is the linkage + 1. mutable unsigned CacheValidAndLinkage : 3; ``` This patch makes debuggers to not be mistaken about enumerator stored in this bit-field. It also converts `clang::Linkage` to a scoped enum. --- clang-tools-extra/clang-doc/Serialize.cpp | 4 +- clang-tools-extra/clangd/Quality.cpp | 3 +- .../clangd/SemanticHighlighting.cpp | 3 +- clang/include/clang/AST/DeclBase.h| 11 ++-- clang/include/clang/AST/Type.h| 2 +- clang/include/clang/Basic/Linkage.h | 53 +++--- clang/include/clang/Basic/Visibility.h| 28 +- clang/lib/AST/APValue.cpp | 2 +- clang/lib/AST/Decl.cpp| 28 +++--- clang/lib/AST/ItaniumMangle.cpp | 4 +- clang/lib/AST/MicrosoftMangle.cpp | 5 +- clang/lib/AST/Type.cpp| 8 +-- clang/lib/CodeGen/CodeGenModule.cpp | 4 +- clang/lib/CodeGen/ItaniumCXXABI.cpp | 15 +++-- clang/lib/CodeGen/MicrosoftCXXABI.cpp | 15 +++-- clang/lib/Index/IndexSymbol.cpp | 20 --- clang/lib/Sema/SemaChecking.cpp | 2 +- clang/lib/Sema/SemaDecl.cpp | 24 clang/lib/Sema/SemaExpr.cpp | 2 +- clang/lib/Sema/SemaModule.cpp | 6 +- clang/lib/Sema/SemaOverload.cpp | 2 +- clang/lib/Sema/SemaTemplate.cpp | 4 +- clang/lib/Serialization/ASTReaderDecl.cpp | 4 +- clang/lib/Serialization/ASTWriterDecl.cpp | 6 +- .../ClangExtDefMapGen.cpp | 8 ++- clang/tools/libclang/CIndex.cpp | 14 +++-- clang/tools/libclang/CXIndexDataConsumer.cpp | 56 +-- clang/unittests/AST/DeclTest.cpp | 8 +-- 28 files changed, 189 insertions(+), 152 deletions(-) diff --git a/clang-tools-extra/clang-doc/Serialize.cpp b/clang-tools-extra/clang-doc/Serialize.cpp index ac8e253ac06ea0b..3b074d849e8a9cf 100644 --- a/clang-tools-extra/clang-doc/Serialize.cpp +++ b/clang-tools-extra/clang-doc/Serialize.cpp @@ -257,8 +257,8 @@ static bool isPublic(const clang::AccessSpecifier AS, const clang::Linkage Link) { if (AS == clang::AccessSpecifier::AS_private) return false; - else if ((Link == clang::Linkage::ModuleLinkage) || - (Link == clang::Linkage::ExternalLinkage)) + else if ((Link == clang::Linkage::Module) || + (Link == clang::Linkage::External)) return true; return false; // otherwise, linkage is some form of internal linkage } diff --git a/clang-tools-extra/clangd/Quality.cpp b/clang-tools-extra/clangd/Quality.cpp index 8840f805f0e87c7..7371d95fbf27547 100644 --- a/clang-tools-extra/clangd/Quality.cpp +++ b/clang-tools-extra/clangd/Quality.cpp @@ -274,7 +274,8 @@ computeScope(const NamedDecl *D) { return SymbolRelevanceSignals::ClassScope; // ExternalLinkage threshold could be tweaked, e.g. module-visible as global. // Avoid caching linkage if it may change after enclosing code completion. - if (hasUnstableLinkage(D) || D->getLinkageInternal() < ExternalLinkage) + if (hasUnstableLinkage(D) || llvm::to_underlying(D->getLinkageInternal()) < + llvm::to_underlying(Linkage::External)) return SymbolRelevanceSignals::FileScope; return SymbolRelevanceSignals::GlobalScope; } diff --git a/clang-tools-extra/clangd/SemanticHighlighting.cpp b/clang-tools-extra/clangd/SemanticHighlighting.cpp index 7649e37e1f96663..49e479abf456210 100644 --- a/clang-tools-extra/clangd/SemanticHighlighting.cpp +++ b/clang-tools-extra/clangd/SemanticHighlighting.cpp @@ -617,7 +617,8 @@ std::optional scopeModifier(const NamedDecl *D) { if (DC->isTranslationUnit() && D->isTemplateParameter()) return std::nullopt; // ExternalLinkage threshold could be tweaked, e.g. module-visibl
[clang] [clang-tools-extra] [clang][NFC] Refactor `clang::Linkage` (PR #71049)
llvmbot wrote: @llvm/pr-subscribers-clang-modules Author: Vlad Serebrennikov (Endilll) Changes This patch introduces a new enumerator `Invalid = 0`, shifting other enumerators by +1. Contrary to how it might sound, this actually affirms status quo of how this enum is stored in `clang::Decl`: ``` /// If 0, we have not computed the linkage of this declaration. /// Otherwise, it is the linkage + 1. mutable unsigned CacheValidAndLinkage : 3; ``` This patch makes debuggers to not be mistaken about enumerator stored in this bit-field. It also converts `clang::Linkage` to a scoped enum. --- Patch is 40.18 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/71049.diff 28 Files Affected: - (modified) clang-tools-extra/clang-doc/Serialize.cpp (+2-2) - (modified) clang-tools-extra/clangd/Quality.cpp (+2-1) - (modified) clang-tools-extra/clangd/SemanticHighlighting.cpp (+2-1) - (modified) clang/include/clang/AST/DeclBase.h (+5-6) - (modified) clang/include/clang/AST/Type.h (+1-1) - (modified) clang/include/clang/Basic/Linkage.h (+34-19) - (modified) clang/include/clang/Basic/Visibility.h (+15-13) - (modified) clang/lib/AST/APValue.cpp (+1-1) - (modified) clang/lib/AST/Decl.cpp (+20-8) - (modified) clang/lib/AST/ItaniumMangle.cpp (+2-2) - (modified) clang/lib/AST/MicrosoftMangle.cpp (+2-3) - (modified) clang/lib/AST/Type.cpp (+4-4) - (modified) clang/lib/CodeGen/CodeGenModule.cpp (+2-2) - (modified) clang/lib/CodeGen/ItaniumCXXABI.cpp (+9-6) - (modified) clang/lib/CodeGen/MicrosoftCXXABI.cpp (+9-6) - (modified) clang/lib/Index/IndexSymbol.cpp (+11-9) - (modified) clang/lib/Sema/SemaChecking.cpp (+1-1) - (modified) clang/lib/Sema/SemaDecl.cpp (+10-14) - (modified) clang/lib/Sema/SemaExpr.cpp (+1-1) - (modified) clang/lib/Sema/SemaModule.cpp (+3-3) - (modified) clang/lib/Sema/SemaOverload.cpp (+1-1) - (modified) clang/lib/Sema/SemaTemplate.cpp (+2-2) - (modified) clang/lib/Serialization/ASTReaderDecl.cpp (+2-2) - (modified) clang/lib/Serialization/ASTWriterDecl.cpp (+3-3) - (modified) clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp (+5-3) - (modified) clang/tools/libclang/CIndex.cpp (+8-6) - (modified) clang/tools/libclang/CXIndexDataConsumer.cpp (+28-28) - (modified) clang/unittests/AST/DeclTest.cpp (+4-4) ``diff diff --git a/clang-tools-extra/clang-doc/Serialize.cpp b/clang-tools-extra/clang-doc/Serialize.cpp index ac8e253ac06ea0b..3b074d849e8a9cf 100644 --- a/clang-tools-extra/clang-doc/Serialize.cpp +++ b/clang-tools-extra/clang-doc/Serialize.cpp @@ -257,8 +257,8 @@ static bool isPublic(const clang::AccessSpecifier AS, const clang::Linkage Link) { if (AS == clang::AccessSpecifier::AS_private) return false; - else if ((Link == clang::Linkage::ModuleLinkage) || - (Link == clang::Linkage::ExternalLinkage)) + else if ((Link == clang::Linkage::Module) || + (Link == clang::Linkage::External)) return true; return false; // otherwise, linkage is some form of internal linkage } diff --git a/clang-tools-extra/clangd/Quality.cpp b/clang-tools-extra/clangd/Quality.cpp index 8840f805f0e87c7..7371d95fbf27547 100644 --- a/clang-tools-extra/clangd/Quality.cpp +++ b/clang-tools-extra/clangd/Quality.cpp @@ -274,7 +274,8 @@ computeScope(const NamedDecl *D) { return SymbolRelevanceSignals::ClassScope; // ExternalLinkage threshold could be tweaked, e.g. module-visible as global. // Avoid caching linkage if it may change after enclosing code completion. - if (hasUnstableLinkage(D) || D->getLinkageInternal() < ExternalLinkage) + if (hasUnstableLinkage(D) || llvm::to_underlying(D->getLinkageInternal()) < + llvm::to_underlying(Linkage::External)) return SymbolRelevanceSignals::FileScope; return SymbolRelevanceSignals::GlobalScope; } diff --git a/clang-tools-extra/clangd/SemanticHighlighting.cpp b/clang-tools-extra/clangd/SemanticHighlighting.cpp index 7649e37e1f96663..49e479abf456210 100644 --- a/clang-tools-extra/clangd/SemanticHighlighting.cpp +++ b/clang-tools-extra/clangd/SemanticHighlighting.cpp @@ -617,7 +617,8 @@ std::optional scopeModifier(const NamedDecl *D) { if (DC->isTranslationUnit() && D->isTemplateParameter()) return std::nullopt; // ExternalLinkage threshold could be tweaked, e.g. module-visible as global. - if (D->getLinkageInternal() < ExternalLinkage) + if (llvm::to_underlying(D->getLinkageInternal()) < + llvm::to_underlying(Linkage::External)) return HighlightingModifier::FileScope; return HighlightingModifier::GlobalScope; } diff --git a/clang/include/clang/AST/DeclBase.h b/clang/include/clang/AST/DeclBase.h index df1d6e8a3b5af72..f784fa73af5bad5 100644 --- a/clang/include/clang/AST/DeclBase.h +++ b/clang/include/clang/AST/DeclBase.h @@ -49,7 +49,7 @@ class ExternalSourceSymbolAttr; class FunctionDecl; class FunctionType; class IdentifierInfo; -enum Linkage : unsign
[clang] [clang-tools-extra] [clang][NFC] Refactor `clang::Linkage` (PR #71049)
llvmbot wrote: @llvm/pr-subscribers-clang-codegen Author: Vlad Serebrennikov (Endilll) Changes This patch introduces a new enumerator `Invalid = 0`, shifting other enumerators by +1. Contrary to how it might sound, this actually affirms status quo of how this enum is stored in `clang::Decl`: ``` /// If 0, we have not computed the linkage of this declaration. /// Otherwise, it is the linkage + 1. mutable unsigned CacheValidAndLinkage : 3; ``` This patch makes debuggers to not be mistaken about enumerator stored in this bit-field. It also converts `clang::Linkage` to a scoped enum. --- Patch is 40.18 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/71049.diff 28 Files Affected: - (modified) clang-tools-extra/clang-doc/Serialize.cpp (+2-2) - (modified) clang-tools-extra/clangd/Quality.cpp (+2-1) - (modified) clang-tools-extra/clangd/SemanticHighlighting.cpp (+2-1) - (modified) clang/include/clang/AST/DeclBase.h (+5-6) - (modified) clang/include/clang/AST/Type.h (+1-1) - (modified) clang/include/clang/Basic/Linkage.h (+34-19) - (modified) clang/include/clang/Basic/Visibility.h (+15-13) - (modified) clang/lib/AST/APValue.cpp (+1-1) - (modified) clang/lib/AST/Decl.cpp (+20-8) - (modified) clang/lib/AST/ItaniumMangle.cpp (+2-2) - (modified) clang/lib/AST/MicrosoftMangle.cpp (+2-3) - (modified) clang/lib/AST/Type.cpp (+4-4) - (modified) clang/lib/CodeGen/CodeGenModule.cpp (+2-2) - (modified) clang/lib/CodeGen/ItaniumCXXABI.cpp (+9-6) - (modified) clang/lib/CodeGen/MicrosoftCXXABI.cpp (+9-6) - (modified) clang/lib/Index/IndexSymbol.cpp (+11-9) - (modified) clang/lib/Sema/SemaChecking.cpp (+1-1) - (modified) clang/lib/Sema/SemaDecl.cpp (+10-14) - (modified) clang/lib/Sema/SemaExpr.cpp (+1-1) - (modified) clang/lib/Sema/SemaModule.cpp (+3-3) - (modified) clang/lib/Sema/SemaOverload.cpp (+1-1) - (modified) clang/lib/Sema/SemaTemplate.cpp (+2-2) - (modified) clang/lib/Serialization/ASTReaderDecl.cpp (+2-2) - (modified) clang/lib/Serialization/ASTWriterDecl.cpp (+3-3) - (modified) clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp (+5-3) - (modified) clang/tools/libclang/CIndex.cpp (+8-6) - (modified) clang/tools/libclang/CXIndexDataConsumer.cpp (+28-28) - (modified) clang/unittests/AST/DeclTest.cpp (+4-4) ``diff diff --git a/clang-tools-extra/clang-doc/Serialize.cpp b/clang-tools-extra/clang-doc/Serialize.cpp index ac8e253ac06ea0b..3b074d849e8a9cf 100644 --- a/clang-tools-extra/clang-doc/Serialize.cpp +++ b/clang-tools-extra/clang-doc/Serialize.cpp @@ -257,8 +257,8 @@ static bool isPublic(const clang::AccessSpecifier AS, const clang::Linkage Link) { if (AS == clang::AccessSpecifier::AS_private) return false; - else if ((Link == clang::Linkage::ModuleLinkage) || - (Link == clang::Linkage::ExternalLinkage)) + else if ((Link == clang::Linkage::Module) || + (Link == clang::Linkage::External)) return true; return false; // otherwise, linkage is some form of internal linkage } diff --git a/clang-tools-extra/clangd/Quality.cpp b/clang-tools-extra/clangd/Quality.cpp index 8840f805f0e87c7..7371d95fbf27547 100644 --- a/clang-tools-extra/clangd/Quality.cpp +++ b/clang-tools-extra/clangd/Quality.cpp @@ -274,7 +274,8 @@ computeScope(const NamedDecl *D) { return SymbolRelevanceSignals::ClassScope; // ExternalLinkage threshold could be tweaked, e.g. module-visible as global. // Avoid caching linkage if it may change after enclosing code completion. - if (hasUnstableLinkage(D) || D->getLinkageInternal() < ExternalLinkage) + if (hasUnstableLinkage(D) || llvm::to_underlying(D->getLinkageInternal()) < + llvm::to_underlying(Linkage::External)) return SymbolRelevanceSignals::FileScope; return SymbolRelevanceSignals::GlobalScope; } diff --git a/clang-tools-extra/clangd/SemanticHighlighting.cpp b/clang-tools-extra/clangd/SemanticHighlighting.cpp index 7649e37e1f96663..49e479abf456210 100644 --- a/clang-tools-extra/clangd/SemanticHighlighting.cpp +++ b/clang-tools-extra/clangd/SemanticHighlighting.cpp @@ -617,7 +617,8 @@ std::optional scopeModifier(const NamedDecl *D) { if (DC->isTranslationUnit() && D->isTemplateParameter()) return std::nullopt; // ExternalLinkage threshold could be tweaked, e.g. module-visible as global. - if (D->getLinkageInternal() < ExternalLinkage) + if (llvm::to_underlying(D->getLinkageInternal()) < + llvm::to_underlying(Linkage::External)) return HighlightingModifier::FileScope; return HighlightingModifier::GlobalScope; } diff --git a/clang/include/clang/AST/DeclBase.h b/clang/include/clang/AST/DeclBase.h index df1d6e8a3b5af72..f784fa73af5bad5 100644 --- a/clang/include/clang/AST/DeclBase.h +++ b/clang/include/clang/AST/DeclBase.h @@ -49,7 +49,7 @@ class ExternalSourceSymbolAttr; class FunctionDecl; class FunctionType; class IdentifierInfo; -enum Linkage : unsign
[clang] [clang-tools-extra] [clang][NFC] Refactor `clang::Linkage` (PR #71049)
@@ -84,22 +88,33 @@ inline bool isUniqueGVALinkage(GVALinkage L) { } inline bool isExternallyVisible(Linkage L) { - return L >= VisibleNoLinkage; + switch (L) { + case Linkage::Invalid: +llvm_unreachable("Linkage hasn't been computed!"); Endilll wrote: @AaronBallman I sprinkled a lot of `llvm_unreachable` in this patch, following an example I've seen in one of the switches on `Linkage`. Let me know if you'd like this to be handled in a different way. https://github.com/llvm/llvm-project/pull/71049 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [clang][NFC] Refactor `clang::Linkage` (PR #71049)
@@ -2214,7 +2214,7 @@ void ASTWriter::WriteDeclAbbrevs() { Abv->Add(BitCodeAbbrevOp(0)); // TSCSpec Abv->Add(BitCodeAbbrevOp(0)); // InitStyle Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isARCPseudoStrong - Abv->Add(BitCodeAbbrevOp(0)); // Linkage + Abv->Add(BitCodeAbbrevOp(1)); // Linkage Endilll wrote: @ChuanqiXu9 confirmed that touching this is fine (thank you!). If I guess correctly that this value corresponds to `Linkage::None` we have in some default constructors, we should consider changing that default to `Linkage::Invalid`. `Linkage::None` being default feels like we computed the linkage and arrived at `Linkage::None` even when it's not the case. CC @AaronBallman https://github.com/llvm/llvm-project/pull/71049 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer][NFC] Rework SVal kind representation (PR #71039)
Endilll wrote: > I've considered this but I found the number of alternatives too large to make > it feasible. Consider that we have 11 possible SValKinds, which would require > 4 bits to encode. Requiring all Data pointers to be aligned as such seems > rough - although not impossible. Sorry, I missed the part that you can have 11 different types there. `alignas(16)` might not be unreasonable, but it depends and requires consideration. > I'd say it's one baby step in that direction, but not the end of the journey. > How about looking at this like that? No objections to this point of view. I just wanted to make sure debugger struggles are brought up in the discussion and understood. https://github.com/llvm/llvm-project/pull/71039 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer][NFC] Rework SVal kind representation (PR #71039)
https://github.com/Endilll approved this pull request. https://github.com/llvm/llvm-project/pull/71039 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] [Coroutines] Introduce [[clang::coro_only_destroy_when_complete]] (PR #71014)
@@ -777,6 +777,12 @@ void CodeGenFunction::EmitCoroutineBody(const CoroutineBodyStmt &S) { // LLVM require the frontend to mark the coroutine. CurFn->setPresplitCoroutine(); + + { +CXXRecordDecl *RD = FnRetTy->getAsCXXRecordDecl(); +if (RD && RD->hasAttr()) + CurFn->setCoroDestroyOnlyWhenDone(); + } tbaederr wrote: ```suggestion if (const CXXRecordDecl *RD = FnRetTy->getAsCXXRecordDecl(); RD && RD->hasAttr()) CurFn->setCoroDestroyOnlyWhenDone(); ``` https://github.com/llvm/llvm-project/pull/71014 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 98da183 - [clang] Remove diagnostic that came with `[[clang::preferred_type]]` (#70632)
Author: Vlad Serebrennikov Date: 2023-11-02T16:17:17+04:00 New Revision: 98da18344eed96cabfd2214131185686b1983412 URL: https://github.com/llvm/llvm-project/commit/98da18344eed96cabfd2214131185686b1983412 DIFF: https://github.com/llvm/llvm-project/commit/98da18344eed96cabfd2214131185686b1983412.diff LOG: [clang] Remove diagnostic that came with `[[clang::preferred_type]]` (#70632) https://github.com/llvm/llvm-project/pull/69104 introduce a diagnostic that checked underlying type of an enum against type of bit-field that is annotated with `[[clang::preferred_type]]`. When I tried to introduce this annotation in https://github.com/llvm/llvm-project/pull/70349, it turned out to be too chatty, despite effort to avoid that. Added: Modified: clang/include/clang/Basic/DiagnosticGroups.td clang/include/clang/Basic/DiagnosticSemaKinds.td clang/lib/Sema/SemaDeclAttr.cpp Removed: diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index 9a8f3f03b39d165..4c4820d17b7184c 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -54,7 +54,6 @@ def BitFieldConstantConversion : DiagGroup<"bitfield-constant-conversion", [SingleBitBitFieldConstantConversion]>; def BitFieldEnumConversion : DiagGroup<"bitfield-enum-conversion">; def BitFieldWidth : DiagGroup<"bitfield-width">; -def BitFieldType : DiagGroup<"bitfield-type">; def CompoundTokenSplitByMacro : DiagGroup<"compound-token-split-by-macro">; def CompoundTokenSplitBySpace : DiagGroup<"compound-token-split-by-space">; def CompoundTokenSplit : DiagGroup<"compound-token-split", diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 224c0df7f1fb71f..474afc2fb99c1f0 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -3167,9 +3167,6 @@ def err_invalid_branch_protection_spec : Error< "invalid or misplaced branch protection specification '%0'">; def warn_unsupported_branch_protection_spec : Warning< "unsupported branch protection specification '%0'">, InGroup; -def warn_attribute_underlying_type_mismatch : Warning< - "underlying type %0 of enumeration %1 doesn't match bit-field type %2">, - InGroup; def warn_unsupported_target_attribute : Warning<"%select{unsupported|duplicate|unknown}0%select{| CPU|" diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 5e43f66d8be8d76..842a01a88cd3c6d 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -5928,28 +5928,6 @@ static void handlePreferredTypeAttr(Sema &S, Decl *D, const ParsedAttr &AL) { S.RequireCompleteType(ParmTSI->getTypeLoc().getBeginLoc(), QT, diag::err_incomplete_type); - if (QT->isEnumeralType()) { -auto IsCorrespondingType = [&](QualType LHS, QualType RHS) { - assert(LHS != RHS); - if (LHS->isSignedIntegerType()) -return LHS == S.getASTContext().getCorrespondingSignedType(RHS); - return LHS == S.getASTContext().getCorrespondingUnsignedType(RHS); -}; -QualType BitfieldType = -cast(D)->getType()->getCanonicalTypeUnqualified(); -QualType EnumUnderlyingType = QT->getAs() - ->getDecl() - ->getIntegerType() - ->getCanonicalTypeUnqualified(); -if (EnumUnderlyingType != BitfieldType && -!IsCorrespondingType(EnumUnderlyingType, BitfieldType)) { - S.Diag(ParmTSI->getTypeLoc().getBeginLoc(), - diag::warn_attribute_underlying_type_mismatch) - << EnumUnderlyingType << QT << BitfieldType; - return; -} - } - D->addAttr(::new (S.Context) PreferredTypeAttr(S.Context, AL, ParmTSI)); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Remove diagnostic that came with `[[clang::preferred_type]]` (PR #70632)
https://github.com/Endilll closed https://github.com/llvm/llvm-project/pull/70632 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] scan-build: Ensure path prefixes exist (PR #71053)
https://github.com/amcn created https://github.com/llvm/llvm-project/pull/71053 scan-build's `UpdatePrefix` calculates the shared prefix of a set of files. Its use of strings and regular expressions to do so means that it can sometimes end up calculating a prefix which does not correspond to a real directory that exists on the filesystem. If such a prefix is calculated, when it is subsequently used in the calculation of the paths to files containing bugs in the toplevel html report, it can cause incorrect paths to be generated. This patch fixes this by requiring that a calculated prefix exist in the filesystem for it to be considered valid. I noticed this when using `scan-build` to analyse a project which contains several folders each starting with a common prefix. `UpdatePrefix` was including this prefix in its calculated prefix, which subsequently caused the paths in the report to lack it. I have created a project which can demonstrate the issue [here](https://github.com/amcn/scan-build-path-bug-example-repo). >From d9f912f3e71e069417b9cefeca8e89b29f3c21fc Mon Sep 17 00:00:00 2001 From: Andrew McNulty Date: Thu, 2 Nov 2023 11:47:33 +0100 Subject: [PATCH] [clang][analyzer] scan-build: Ensure path prefixes exist scan-build's UpdatePrefix calculates the lowest common ancestor directory of a set of files. Its use of strings and regexes to do so means that it can sometimes end up calculating a prefix which does not correspond to a real directory that exists on the filesystem. This patch fixes this by requiring that a calculated prefix exist in the filesystem for it to be considered valid. --- clang/tools/scan-build/bin/scan-build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/tools/scan-build/bin/scan-build b/clang/tools/scan-build/bin/scan-build index 04734d9cfa9af69..074989ab543af2c 100755 --- a/clang/tools/scan-build/bin/scan-build +++ b/clang/tools/scan-build/bin/scan-build @@ -282,7 +282,7 @@ sub UpdatePrefix { return; } - chop $Prefix while (!($x =~ /^\Q$Prefix/)); + chop $Prefix while (!($x =~ /^\Q$Prefix/) || !(-e $Prefix)); } sub GetPrefix { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] scan-build: Ensure path prefixes exist (PR #71053)
llvmbot wrote: @llvm/pr-subscribers-clang Author: None (amcn) Changes scan-build's `UpdatePrefix` calculates the shared prefix of a set of files. Its use of strings and regular expressions to do so means that it can sometimes end up calculating a prefix which does not correspond to a real directory that exists on the filesystem. If such a prefix is calculated, when it is subsequently used in the calculation of the paths to files containing bugs in the toplevel html report, it can cause incorrect paths to be generated. This patch fixes this by requiring that a calculated prefix exist in the filesystem for it to be considered valid. I noticed this when using `scan-build` to analyse a project which contains several folders each starting with a common prefix. `UpdatePrefix` was including this prefix in its calculated prefix, which subsequently caused the paths in the report to lack it. I have created a project which can demonstrate the issue [here](https://github.com/amcn/scan-build-path-bug-example-repo). --- Full diff: https://github.com/llvm/llvm-project/pull/71053.diff 1 Files Affected: - (modified) clang/tools/scan-build/bin/scan-build (+1-1) ``diff diff --git a/clang/tools/scan-build/bin/scan-build b/clang/tools/scan-build/bin/scan-build index 04734d9cfa9af69..074989ab543af2c 100755 --- a/clang/tools/scan-build/bin/scan-build +++ b/clang/tools/scan-build/bin/scan-build @@ -282,7 +282,7 @@ sub UpdatePrefix { return; } - chop $Prefix while (!($x =~ /^\Q$Prefix/)); + chop $Prefix while (!($x =~ /^\Q$Prefix/) || !(-e $Prefix)); } sub GetPrefix { `` https://github.com/llvm/llvm-project/pull/71053 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] scan-build: Ensure path prefixes exist (PR #71053)
llvmbot wrote: @llvm/pr-subscribers-clang-static-analyzer-1 Author: None (amcn) Changes scan-build's `UpdatePrefix` calculates the shared prefix of a set of files. Its use of strings and regular expressions to do so means that it can sometimes end up calculating a prefix which does not correspond to a real directory that exists on the filesystem. If such a prefix is calculated, when it is subsequently used in the calculation of the paths to files containing bugs in the toplevel html report, it can cause incorrect paths to be generated. This patch fixes this by requiring that a calculated prefix exist in the filesystem for it to be considered valid. I noticed this when using `scan-build` to analyse a project which contains several folders each starting with a common prefix. `UpdatePrefix` was including this prefix in its calculated prefix, which subsequently caused the paths in the report to lack it. I have created a project which can demonstrate the issue [here](https://github.com/amcn/scan-build-path-bug-example-repo). --- Full diff: https://github.com/llvm/llvm-project/pull/71053.diff 1 Files Affected: - (modified) clang/tools/scan-build/bin/scan-build (+1-1) ``diff diff --git a/clang/tools/scan-build/bin/scan-build b/clang/tools/scan-build/bin/scan-build index 04734d9cfa9af69..074989ab543af2c 100755 --- a/clang/tools/scan-build/bin/scan-build +++ b/clang/tools/scan-build/bin/scan-build @@ -282,7 +282,7 @@ sub UpdatePrefix { return; } - chop $Prefix while (!($x =~ /^\Q$Prefix/)); + chop $Prefix while (!($x =~ /^\Q$Prefix/) || !(-e $Prefix)); } sub GetPrefix { `` https://github.com/llvm/llvm-project/pull/71053 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang-tools-extra] [clang][NFC] Annotate `Type` bit-fields with `clang::preferred_type` (PR #70349)
https://github.com/Endilll updated https://github.com/llvm/llvm-project/pull/70349 >From 7329f68092d5f8f5a5978e5a6cbad6ada87d4fe8 Mon Sep 17 00:00:00 2001 From: Vlad Serebrennikov Date: Thu, 26 Oct 2023 16:09:25 +0300 Subject: [PATCH 1/6] [clang][NFC] Annotate `Type` bit-fields with `clang::preferred_type` --- clang/include/clang/AST/DeclBase.h| 2 +- clang/include/clang/AST/DependenceFlags.h | 2 +- clang/include/clang/AST/Type.h| 46 ++- clang/include/clang/Basic/Linkage.h | 2 +- 4 files changed, 47 insertions(+), 5 deletions(-) diff --git a/clang/include/clang/AST/DeclBase.h b/clang/include/clang/AST/DeclBase.h index 978e4255e877ec2..0307691fdd480bf 100644 --- a/clang/include/clang/AST/DeclBase.h +++ b/clang/include/clang/AST/DeclBase.h @@ -49,7 +49,7 @@ class ExternalSourceSymbolAttr; class FunctionDecl; class FunctionType; class IdentifierInfo; -enum Linkage : unsigned char; +enum Linkage : unsigned; class LinkageSpecDecl; class Module; class NamedDecl; diff --git a/clang/include/clang/AST/DependenceFlags.h b/clang/include/clang/AST/DependenceFlags.h index 3b3c1afb096addd..e91b6ff35b34966 100644 --- a/clang/include/clang/AST/DependenceFlags.h +++ b/clang/include/clang/AST/DependenceFlags.h @@ -49,7 +49,7 @@ struct ExprDependenceScope { using ExprDependence = ExprDependenceScope::ExprDependence; struct TypeDependenceScope { - enum TypeDependence : uint8_t { + enum TypeDependence : unsigned { /// Whether this type contains an unexpanded parameter pack /// (for C++11 variadic templates) UnexpandedPack = 1, diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h index 1e8e1303e65f6ba..f24b1dccc240785 100644 --- a/clang/include/clang/AST/Type.h +++ b/clang/include/clang/AST/Type.h @@ -1611,22 +1611,28 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase { template friend class TypePropertyCache; /// TypeClass bitfield - Enum that specifies what subclass this belongs to. +[[clang::preferred_type(TypeClass)]] unsigned TC : 8; /// Store information on the type dependency. +[[clang::preferred_type(TypeDependence)]] unsigned Dependence : llvm::BitWidth; /// True if the cache (i.e. the bitfields here starting with /// 'Cache') is valid. +[[clang::preferred_type(bool)]] mutable unsigned CacheValid : 1; /// Linkage of this type. +[[clang::preferred_type(Linkage)]] mutable unsigned CachedLinkage : 3; /// Whether this type involves and local or unnamed types. +[[clang::preferred_type(bool)]] mutable unsigned CachedLocalOrUnnamed : 1; /// Whether this type comes from an AST file. +[[clang::preferred_type(bool)]] mutable unsigned FromAST : 1; bool isCacheValid() const { @@ -1652,10 +1658,12 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase { class ArrayTypeBitfields { friend class ArrayType; +[[clang::preferred_type(TypeBitfields)]] unsigned : NumTypeBits; /// CVR qualifiers from declarations like /// 'int X[static restrict 4]'. For function parameters only. +[[clang::preferred_type(Qualifiers)]] unsigned IndexTypeQuals : 3; /// Storage class qualifiers from declarations like @@ -1671,12 +1679,14 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase { unsigned : NumArrayTypeBits; /// Whether we have a stored size expression. +[[clang::preferred_type(bool)]] unsigned HasStoredSizeExpr : 1; }; class BuiltinTypeBitfields { friend class BuiltinType; +[[clang::preferred_type(TypeBitfields)]] unsigned : NumTypeBits; /// The kind (BuiltinType::Kind) of builtin type this is. @@ -1691,15 +1701,18 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase { friend class FunctionProtoType; friend class FunctionType; +[[clang::preferred_type(TypeBitfields)]] unsigned : NumTypeBits; /// Extra information which affects how the function is called, like /// regparm and the calling convention. +[[clang::preferred_type(CallingConv)]] unsigned ExtInfo : 13; /// The ref-qualifier associated with a \c FunctionProtoType. /// /// This is a value of type \c RefQualifierKind. +[[clang::preferred_type(RefQualifierKind)]] unsigned RefQualifier : 2; /// Used only by FunctionProtoType, put here to pack with the @@ -1708,8 +1721,10 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase { /// /// C++ 8.3.5p4: The return type, the parameter type list and the /// cv-qualifier-seq, [...], are part of the function type. +[[clang::preferred_type(Qualifiers)]] unsigned FastTypeQuals : Qualifiers::FastWidth; /// Whether this function has extended Qualifiers. +[[clang::preferred_type(bool)]] unsigned HasExtQuals : 1; /// The number of parameters
[clang] [clang-tools-extra] [clang][NFC] Refactor `clang::Linkage` (PR #71049)
@@ -84,22 +88,33 @@ inline bool isUniqueGVALinkage(GVALinkage L) { } inline bool isExternallyVisible(Linkage L) { - return L >= VisibleNoLinkage; + switch (L) { + case Linkage::Invalid: +llvm_unreachable("Linkage hasn't been computed!"); AaronBallman wrote: I think this is a good approach. https://github.com/llvm/llvm-project/pull/71049 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [clang][NFC] Refactor `clang::Linkage` (PR #71049)
@@ -1921,7 +1920,20 @@ bool NamedDecl::declarationReplaces(NamedDecl *OldD, bool IsKnownNewer) const { } bool NamedDecl::hasLinkage() const { - return getFormalLinkage() != NoLinkage; + switch (getFormalLinkage()) { + case Linkage::Invalid: +llvm_unreachable("Linkage hasn't been computed!"); + case Linkage::None: +return false; + case Linkage::Internal: +return true; + case Linkage::UniqueExternal: + case Linkage::VisibleNone: +llvm_unreachable("Non-formal linkage is not allowed here!"); AaronBallman wrote: Can you explain this change a bit? This looks like a functional change? https://github.com/llvm/llvm-project/pull/71049 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [clang][NFC] Refactor `clang::Linkage` (PR #71049)
@@ -2214,7 +2214,7 @@ void ASTWriter::WriteDeclAbbrevs() { Abv->Add(BitCodeAbbrevOp(0)); // TSCSpec Abv->Add(BitCodeAbbrevOp(0)); // InitStyle Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isARCPseudoStrong - Abv->Add(BitCodeAbbrevOp(0)); // Linkage + Abv->Add(BitCodeAbbrevOp(1)); // Linkage AaronBallman wrote: Agreed that those should be swapped to `Invalid` instead of `None` (better done as a separate follow-up patch as it isn't an NFC change). However, this is a change to the serialization format so a new PCH consumed by an older Clang will misbehave. Please check whether `VERSION_MAJOR` (in `ASTBitCodes.h`) has been updated for this release and if it hasn't been, increment it by one. https://github.com/llvm/llvm-project/pull/71049 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang] [clang][NFC] Refactor `clang::Linkage` (PR #71049)
@@ -560,7 +562,7 @@ bool CXIndexDataConsumer::handleDecl(const NamedDecl *D, if (shouldSuppressRefs()) markEntityOccurrenceInFile(D, Loc); - + AaronBallman wrote: Every other change in this file is unrelated to the linkage enum and should be backed out (committed separately). https://github.com/llvm/llvm-project/pull/71049 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Handle std::move etc. builtins (PR #70772)
Timm =?utf-8?q?Bäder?= Message-ID: In-Reply-To: hnrklssn wrote: Nice. I realise you're following the convention already established in the test file, but have you considered compiling with `-verify=new,both` and `-verify=ref,both`, respectively, and combining the shared diagnostics into `both-error` etc. to make it easier to see when they do and don't align? https://github.com/llvm/llvm-project/pull/70772 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] f1c9a1c - Revert "Revert "[APINotes] Upstream APINotesOptions""
Author: Egor Zhdan Date: 2023-11-02T12:39:55Z New Revision: f1c9a1c3a590970ba88e28a58d0f3622e8c2c415 URL: https://github.com/llvm/llvm-project/commit/f1c9a1c3a590970ba88e28a58d0f3622e8c2c415 DIFF: https://github.com/llvm/llvm-project/commit/f1c9a1c3a590970ba88e28a58d0f3622e8c2c415.diff LOG: Revert "Revert "[APINotes] Upstream APINotesOptions"" This re-lands https://github.com/llvm/llvm-project/pull/70827 while preventing the assertion failure that occurred when generating `ASTNodeAPI.json` on non-Apple platforms. Added: clang/include/clang/APINotes/APINotesOptions.h Modified: clang/include/clang/Driver/Options.td clang/include/clang/Frontend/CompilerInvocation.h clang/lib/Frontend/CompilerInvocation.cpp Removed: diff --git a/clang/include/clang/APINotes/APINotesOptions.h b/clang/include/clang/APINotes/APINotesOptions.h new file mode 100644 index 000..e8b8a9ed2261fa1 --- /dev/null +++ b/clang/include/clang/APINotes/APINotesOptions.h @@ -0,0 +1,34 @@ +//===--- APINotesOptions.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 +// +//===--===// + +#ifndef LLVM_CLANG_APINOTES_APINOTESOPTIONS_H +#define LLVM_CLANG_APINOTES_APINOTESOPTIONS_H + +#include "llvm/Support/VersionTuple.h" +#include +#include + +namespace clang { + +/// Tracks various options which control how API notes are found and handled. +class APINotesOptions { +public: + /// The Swift version which should be used for API notes. + llvm::VersionTuple SwiftVersion; + + /// The set of search paths where we API notes can be found for particular + /// modules. + /// + /// The API notes in this directory are stored as .apinotes, and + /// are only applied when building the module . + std::vector ModuleSearchPaths; +}; + +} // namespace clang + +#endif // LLVM_CLANG_APINOTES_APINOTESOPTIONS_H diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index b1229b2f4562379..fcf6a4b2ccb2369 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -1733,6 +1733,10 @@ def fswift_async_fp_EQ : Joined<["-"], "fswift-async-fp=">, NormalizedValuesScope<"CodeGenOptions::SwiftAsyncFramePointerKind">, NormalizedValues<["Auto", "Always", "Never"]>, MarshallingInfoEnum, "Always">; +def fapinotes_swift_version : Joined<["-"], "fapinotes-swift-version=">, + Group, Visibility<[ClangOption, CC1Option]>, + MetaVarName<"">, + HelpText<"Specify the Swift version to use when filtering API notes">; defm addrsig : BoolFOption<"addrsig", CodeGenOpts<"Addrsig">, DefaultFalse, @@ -4129,6 +4133,9 @@ def ibuiltininc : Flag<["-"], "ibuiltininc">, Group, def index_header_map : Flag<["-"], "index-header-map">, Visibility<[ClangOption, CC1Option]>, HelpText<"Make the next included directory (-I or -F) an indexer header map">; +def iapinotes_modules : JoinedOrSeparate<["-"], "iapinotes-modules">, Group, + Visibility<[ClangOption, CC1Option]>, + HelpText<"Add directory to the API notes search path referenced by module name">, MetaVarName<"">; def idirafter : JoinedOrSeparate<["-"], "idirafter">, Group, Visibility<[ClangOption, CC1Option]>, HelpText<"Add directory to AFTER include search path">; diff --git a/clang/include/clang/Frontend/CompilerInvocation.h b/clang/include/clang/Frontend/CompilerInvocation.h index 45e263e7bc76822..c6528779bde7b2e 100644 --- a/clang/include/clang/Frontend/CompilerInvocation.h +++ b/clang/include/clang/Frontend/CompilerInvocation.h @@ -9,6 +9,7 @@ #ifndef LLVM_CLANG_FRONTEND_COMPILERINVOCATION_H #define LLVM_CLANG_FRONTEND_COMPILERINVOCATION_H +#include "clang/APINotes/APINotesOptions.h" #include "clang/Basic/CodeGenOptions.h" #include "clang/Basic/DiagnosticOptions.h" #include "clang/Basic/FileSystemOptions.h" @@ -92,6 +93,9 @@ class CompilerInvocationBase { std::shared_ptr MigratorOpts; + /// Options controlling API notes. + std::shared_ptr APINotesOpts; + /// Options controlling IRgen and the backend. std::shared_ptr CodeGenOpts; @@ -131,6 +135,7 @@ class CompilerInvocationBase { const PreprocessorOptions &getPreprocessorOpts() const { return *PPOpts; } const AnalyzerOptions &getAnalyzerOpts() const { return *AnalyzerOpts; } const MigratorOptions &getMigratorOpts() const { return *MigratorOpts; } + const APINotesOptions &getAPINotesOpts() const { return *APINotesOpts; } const CodeGenOptions &getCodeGenOpts() const { return *CodeGenOpts; } const FileSystemOptions &getFileSystemOpts() const { return *FSOpts; } const FrontendOptions &getFrontendOpts() const { return *FrontendOp
[clang] Revert "Revert "[APINotes] Upstream APINotesOptions"" (PR #70975)
https://github.com/egorzhdan closed https://github.com/llvm/llvm-project/pull/70975 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang] [clang][NFC] Refactor `clang::Linkage` (PR #71049)
@@ -1921,7 +1920,20 @@ bool NamedDecl::declarationReplaces(NamedDecl *OldD, bool IsKnownNewer) const { } bool NamedDecl::hasLinkage() const { - return getFormalLinkage() != NoLinkage; + switch (getFormalLinkage()) { + case Linkage::Invalid: +llvm_unreachable("Linkage hasn't been computed!"); + case Linkage::None: +return false; + case Linkage::Internal: +return true; + case Linkage::UniqueExternal: + case Linkage::VisibleNone: +llvm_unreachable("Non-formal linkage is not allowed here!"); Endilll wrote: As I was making sure that `Linkage::Invalid` doesn't creep up where it wasn't before, I converted this to a switch. Then I realized that `UniqueExternal` and `VisibleNone` is not something `getFormalLinkage()` allowed to return, and did a drive-by fix. Since this patch is up for review anyway, I can remove `[NFC]` tag. https://github.com/llvm/llvm-project/pull/71049 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [clang][NFC] Refactor `clang::Linkage` (PR #71049)
@@ -560,7 +562,7 @@ bool CXIndexDataConsumer::handleDecl(const NamedDecl *D, if (shouldSuppressRefs()) markEntityOccurrenceInFile(D, Loc); - + Endilll wrote: I guess that's clang-format at work. I'll revert this. https://github.com/llvm/llvm-project/pull/71049 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits