[clang] [Clang][Concepts] Fix the constraint equivalence checking involving parameter packs (PR #102131)
@@ -972,8 +972,15 @@ static const Expr *SubstituteConstraintExpressionWithoutSatisfaction( // equivalence. LocalInstantiationScope ScopeForParameters(S); if (auto *FD = DeclInfo.getDecl()->getAsFunction()) -for (auto *PVD : FD->parameters()) - ScopeForParameters.InstantiatedLocal(PVD, PVD); +for (auto *PVD : FD->parameters()) { + if (!PVD->isParameterPack()) { +ScopeForParameters.InstantiatedLocal(PVD, PVD); +continue; + } + // Parameter packs should expand to a size-of-1 argument. + ScopeForParameters.MakeInstantiatedLocalArgPack(PVD); + ScopeForParameters.InstantiatedLocalPackArg(PVD, PVD); +} zyn0217 wrote: Thanks for the suggestion; I’m offline and will add more comments when I get to my computer. IIRC, this future improvement could also benefit noexcept specifier comparison as it also requires an instantiation scope that just indicates, “We know this declaration is not instantiated; just go on and leave it an uninstantiated state” Isolating the declaration instantiation from a TreeTransform seems to have inconvenienced other things. Maybe that is what was designed for templates in the first place, but it becomes cumbersome for cases like this and CWG2369, etc, and we need the on-demand instantiation. https://github.com/llvm/llvm-project/pull/102131 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 99b85ca - [clang][bytecode][NFC] Add an additional assertion (#105927)
Author: Timm Baeder Date: 2024-08-24T09:23:25+02:00 New Revision: 99b85cae628c1cc5641944290712cd84ccf1f6c8 URL: https://github.com/llvm/llvm-project/commit/99b85cae628c1cc5641944290712cd84ccf1f6c8 DIFF: https://github.com/llvm/llvm-project/commit/99b85cae628c1cc5641944290712cd84ccf1f6c8.diff LOG: [clang][bytecode][NFC] Add an additional assertion (#105927) Since this must be true, add an assertion instead of just documenting it via the comment. Added: Modified: clang/lib/AST/ByteCode/Interp.h Removed: diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h index 7ba51f737db491..81c547991c3d7d 100644 --- a/clang/lib/AST/ByteCode/Interp.h +++ b/clang/lib/AST/ByteCode/Interp.h @@ -2608,9 +2608,11 @@ inline bool Call(InterpState &S, CodePtr OpPC, const Function *Func, // the function we're about to call is a lambda call operator, // skip the CheckInvoke, since the ThisPtr is a null pointer // anyway. -if (!(S.Current->getFunction() && - S.Current->getFunction()->isLambdaStaticInvoker() && - Func->isLambdaCallOperator())) { +if (S.Current->getFunction() && +S.Current->getFunction()->isLambdaStaticInvoker() && +Func->isLambdaCallOperator()) { + assert(ThisPtr.isZero()); +} else { if (!CheckInvoke(S, OpPC, ThisPtr)) return false; } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][bytecode][NFC] Add an additional assertion (PR #105927)
https://github.com/tbaederr closed https://github.com/llvm/llvm-project/pull/105927 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][HLSL] Update DXIL/SPIRV hybird CodeGen tests to use temp var (PR #105930)
https://github.com/AmrDeveloper created https://github.com/llvm/llvm-project/pull/105930 Update all hybird DXIL/SPIRV codegen tests to use temp variable representing interchange target Fixes: #105710 >From 6f7b394dc573dfb2c9ce68b5ff8ec3a933830225 Mon Sep 17 00:00:00 2001 From: AmrDeveloper Date: Sat, 24 Aug 2024 10:08:23 +0200 Subject: [PATCH] [clang][HLSL] Update DXIL/SPIRV hybird CodeGen tests to use temp var Update all hybird DXIL/SPIRV codegen tests to use temp variable representing interchange target --- .../GlobalConstructorFunction.hlsl| 2 +- .../test/CodeGenHLSL/GlobalConstructors.hlsl | 2 +- clang/test/CodeGenHLSL/GlobalDestructors.hlsl | 2 +- .../builtins/RWBuffer-constructor.hlsl| 9 +- clang/test/CodeGenHLSL/builtins/all.hlsl | 176 +- clang/test/CodeGenHLSL/builtins/any.hlsl | 176 +- .../CodeGenHLSL/builtins/clamp-builtin.hlsl | 2 +- clang/test/CodeGenHLSL/builtins/clamp.hlsl| 80 .../CodeGenHLSL/builtins/create_handle.hlsl | 2 +- clang/test/CodeGenHLSL/builtins/frac.hlsl | 48 ++--- clang/test/CodeGenHLSL/builtins/isinf.hlsl| 24 +-- clang/test/CodeGenHLSL/builtins/length.hlsl | 18 +- .../CodeGenHLSL/builtins/lerp-builtin.hlsl| 4 +- clang/test/CodeGenHLSL/builtins/lerp.hlsl | 60 +++--- clang/test/CodeGenHLSL/builtins/mad.hlsl | 48 ++--- .../test/CodeGenHLSL/builtins/normalize.hlsl | 48 ++--- clang/test/CodeGenHLSL/builtins/rsqrt.hlsl| 48 ++--- clang/test/CodeGenHLSL/builtins/saturate.hlsl | 64 +++ .../semantics/DispatchThreadID.hlsl | 12 +- .../semantics/GroupIndex-codegen.hlsl | 2 +- 20 files changed, 414 insertions(+), 413 deletions(-) diff --git a/clang/test/CodeGenHLSL/GlobalConstructorFunction.hlsl b/clang/test/CodeGenHLSL/GlobalConstructorFunction.hlsl index f954c9d2f029f2..6856cccb3fc3eb 100644 --- a/clang/test/CodeGenHLSL/GlobalConstructorFunction.hlsl +++ b/clang/test/CodeGenHLSL/GlobalConstructorFunction.hlsl @@ -25,7 +25,7 @@ void main(unsigned GI : SV_GroupIndex) {} //CHECK-NEXT: entry: //CHECK-NEXT: call void @"?call_me_first@@YAXXZ"() //CHECK-NEXT: call void @"?then_call_me@@YAXXZ"() -//CHECK-NEXT: %0 = call i32 @llvm.dx.flattened.thread.id.in.group() +//CHECK-NEXT: %0 = call i32 @llvm.[[ICF:dx]].flattened.thread.id.in.group() //CHECK-NEXT: call void @"?main@@YAXI@Z"(i32 %0) //CHECK-NEXT: call void @"?call_me_last@@YAXXZ"( //CHECK-NEXT: ret void diff --git a/clang/test/CodeGenHLSL/GlobalConstructors.hlsl b/clang/test/CodeGenHLSL/GlobalConstructors.hlsl index 7e2f288726c954..676a24b2467c18 100644 --- a/clang/test/CodeGenHLSL/GlobalConstructors.hlsl +++ b/clang/test/CodeGenHLSL/GlobalConstructors.hlsl @@ -11,6 +11,6 @@ void main(unsigned GI : SV_GroupIndex) {} //CHECK: define void @main() //CHECK-NEXT: entry: //CHECK-NEXT: call void @_GLOBAL__sub_I_GlobalConstructors.hlsl() -//CHECK-NEXT: %0 = call i32 @llvm.dx.flattened.thread.id.in.group() +//CHECK-NEXT: %0 = call i32 @llvm.[[ICF:dx]].flattened.thread.id.in.group() //CHECK-NEXT: call void @"?main@@YAXI@Z"(i32 %0) //CHECK-NEXT: ret void diff --git a/clang/test/CodeGenHLSL/GlobalDestructors.hlsl b/clang/test/CodeGenHLSL/GlobalDestructors.hlsl index 24c3c039fc6192..d98a54bbc49fe8 100644 --- a/clang/test/CodeGenHLSL/GlobalDestructors.hlsl +++ b/clang/test/CodeGenHLSL/GlobalDestructors.hlsl @@ -52,7 +52,7 @@ void main(unsigned GI : SV_GroupIndex) { //CHECK: define void @main() //CHECK-NEXT: entry: //CHECK-NEXT: call void @_GLOBAL__sub_I_GlobalDestructors.hlsl() -//CHECK-NEXT: %0 = call i32 @llvm.dx.flattened.thread.id.in.group() +//CHECK-NEXT: %0 = call i32 @llvm.[[ICF:dx]].flattened.thread.id.in.group() //CHECK-NEXT: call void @"?main@@YAXI@Z"(i32 %0) //CHECK-NEXT: call void @_GLOBAL__D_a() //CHECK-NEXT: ret void diff --git a/clang/test/CodeGenHLSL/builtins/RWBuffer-constructor.hlsl b/clang/test/CodeGenHLSL/builtins/RWBuffer-constructor.hlsl index e51eac7f57c2d3..1a2e9aa490709c 100644 --- a/clang/test/CodeGenHLSL/builtins/RWBuffer-constructor.hlsl +++ b/clang/test/CodeGenHLSL/builtins/RWBuffer-constructor.hlsl @@ -1,12 +1,13 @@ -// RUN: %clang_cc1 -triple spirv-vulkan-library -x hlsl -emit-llvm -disable-llvm-passes -o - %s | FileCheck %s --check-prefix=CHECK-SPIRV +// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -emit-llvm -disable-llvm-passes -o - %s | FileCheck %s --check-prefixes=DXCHECK + +// RUN: %clang_cc1 -triple spirv-vulkan-library -x hlsl -emit-llvm -disable-llvm-passes -o - %s | FileCheck %s --check-prefixes=SPVCHECK RWBuffer Buf; // CHECK: define linkonce_odr noundef ptr @"??0?$RWBuffer@M@hlsl@@QAA@XZ" // CHECK-NEXT: entry: -// CHECK: %[[HandleRes:[0-9]+]] = call ptr @llvm.dx.create.handle(i8 1) +// DXCHECK: %[[HandleRes:[0-9]+]] = call ptr @llvm.[[ICF:dx]].create.handle(i8 1) +// SPVCHECK: %[[HandleRes:[0-9]+]] = call ptr @llvm.[[ICF:spv]].crea
[clang] [clang][HLSL] Update DXIL/SPIRV hybird CodeGen tests to use temp var (PR #105930)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Amr Hesham (AmrDeveloper) Changes Update all hybird DXIL/SPIRV codegen tests to use temp variable representing interchange target Fixes: #105710 --- Patch is 101.99 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/105930.diff 20 Files Affected: - (modified) clang/test/CodeGenHLSL/GlobalConstructorFunction.hlsl (+1-1) - (modified) clang/test/CodeGenHLSL/GlobalConstructors.hlsl (+1-1) - (modified) clang/test/CodeGenHLSL/GlobalDestructors.hlsl (+1-1) - (modified) clang/test/CodeGenHLSL/builtins/RWBuffer-constructor.hlsl (+5-4) - (modified) clang/test/CodeGenHLSL/builtins/all.hlsl (+88-88) - (modified) clang/test/CodeGenHLSL/builtins/any.hlsl (+88-88) - (modified) clang/test/CodeGenHLSL/builtins/clamp-builtin.hlsl (+1-1) - (modified) clang/test/CodeGenHLSL/builtins/clamp.hlsl (+40-40) - (modified) clang/test/CodeGenHLSL/builtins/create_handle.hlsl (+1-1) - (modified) clang/test/CodeGenHLSL/builtins/frac.hlsl (+24-24) - (modified) clang/test/CodeGenHLSL/builtins/isinf.hlsl (+12-12) - (modified) clang/test/CodeGenHLSL/builtins/length.hlsl (+9-9) - (modified) clang/test/CodeGenHLSL/builtins/lerp-builtin.hlsl (+2-2) - (modified) clang/test/CodeGenHLSL/builtins/lerp.hlsl (+30-30) - (modified) clang/test/CodeGenHLSL/builtins/mad.hlsl (+24-24) - (modified) clang/test/CodeGenHLSL/builtins/normalize.hlsl (+24-24) - (modified) clang/test/CodeGenHLSL/builtins/rsqrt.hlsl (+24-24) - (modified) clang/test/CodeGenHLSL/builtins/saturate.hlsl (+32-32) - (modified) clang/test/CodeGenHLSL/semantics/DispatchThreadID.hlsl (+6-6) - (modified) clang/test/CodeGenHLSL/semantics/GroupIndex-codegen.hlsl (+1-1) ``diff diff --git a/clang/test/CodeGenHLSL/GlobalConstructorFunction.hlsl b/clang/test/CodeGenHLSL/GlobalConstructorFunction.hlsl index f954c9d2f029f2..6856cccb3fc3eb 100644 --- a/clang/test/CodeGenHLSL/GlobalConstructorFunction.hlsl +++ b/clang/test/CodeGenHLSL/GlobalConstructorFunction.hlsl @@ -25,7 +25,7 @@ void main(unsigned GI : SV_GroupIndex) {} //CHECK-NEXT: entry: //CHECK-NEXT: call void @"?call_me_first@@YAXXZ"() //CHECK-NEXT: call void @"?then_call_me@@YAXXZ"() -//CHECK-NEXT: %0 = call i32 @llvm.dx.flattened.thread.id.in.group() +//CHECK-NEXT: %0 = call i32 @llvm.[[ICF:dx]].flattened.thread.id.in.group() //CHECK-NEXT: call void @"?main@@YAXI@Z"(i32 %0) //CHECK-NEXT: call void @"?call_me_last@@YAXXZ"( //CHECK-NEXT: ret void diff --git a/clang/test/CodeGenHLSL/GlobalConstructors.hlsl b/clang/test/CodeGenHLSL/GlobalConstructors.hlsl index 7e2f288726c954..676a24b2467c18 100644 --- a/clang/test/CodeGenHLSL/GlobalConstructors.hlsl +++ b/clang/test/CodeGenHLSL/GlobalConstructors.hlsl @@ -11,6 +11,6 @@ void main(unsigned GI : SV_GroupIndex) {} //CHECK: define void @main() //CHECK-NEXT: entry: //CHECK-NEXT: call void @_GLOBAL__sub_I_GlobalConstructors.hlsl() -//CHECK-NEXT: %0 = call i32 @llvm.dx.flattened.thread.id.in.group() +//CHECK-NEXT: %0 = call i32 @llvm.[[ICF:dx]].flattened.thread.id.in.group() //CHECK-NEXT: call void @"?main@@YAXI@Z"(i32 %0) //CHECK-NEXT: ret void diff --git a/clang/test/CodeGenHLSL/GlobalDestructors.hlsl b/clang/test/CodeGenHLSL/GlobalDestructors.hlsl index 24c3c039fc6192..d98a54bbc49fe8 100644 --- a/clang/test/CodeGenHLSL/GlobalDestructors.hlsl +++ b/clang/test/CodeGenHLSL/GlobalDestructors.hlsl @@ -52,7 +52,7 @@ void main(unsigned GI : SV_GroupIndex) { //CHECK: define void @main() //CHECK-NEXT: entry: //CHECK-NEXT: call void @_GLOBAL__sub_I_GlobalDestructors.hlsl() -//CHECK-NEXT: %0 = call i32 @llvm.dx.flattened.thread.id.in.group() +//CHECK-NEXT: %0 = call i32 @llvm.[[ICF:dx]].flattened.thread.id.in.group() //CHECK-NEXT: call void @"?main@@YAXI@Z"(i32 %0) //CHECK-NEXT: call void @_GLOBAL__D_a() //CHECK-NEXT: ret void diff --git a/clang/test/CodeGenHLSL/builtins/RWBuffer-constructor.hlsl b/clang/test/CodeGenHLSL/builtins/RWBuffer-constructor.hlsl index e51eac7f57c2d3..1a2e9aa490709c 100644 --- a/clang/test/CodeGenHLSL/builtins/RWBuffer-constructor.hlsl +++ b/clang/test/CodeGenHLSL/builtins/RWBuffer-constructor.hlsl @@ -1,12 +1,13 @@ -// RUN: %clang_cc1 -triple spirv-vulkan-library -x hlsl -emit-llvm -disable-llvm-passes -o - %s | FileCheck %s --check-prefix=CHECK-SPIRV +// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -emit-llvm -disable-llvm-passes -o - %s | FileCheck %s --check-prefixes=DXCHECK + +// RUN: %clang_cc1 -triple spirv-vulkan-library -x hlsl -emit-llvm -disable-llvm-passes -o - %s | FileCheck %s --check-prefixes=SPVCHECK RWBuffer Buf; // CHECK: define linkonce_odr noundef ptr @"??0?$RWBuffer@M@hlsl@@QAA@XZ" // CHECK-NEXT: entry: -// CHECK: %[[HandleRes:[0-9]+]] = call ptr @llvm.dx.create.handle(i8 1) +// DXCHECK: %[[HandleRes:[0-9]+]] = call ptr @llvm.[[ICF:dx]].create.handle(i8 1) +// SPVCHECK: %[[HandleRes:[0-9]+]] = call ptr @llvm.[[ICF:spv]].create.hand
[clang] [clang][HLSL] Update DXIL/SPIRV hybird CodeGen tests to use temp var (PR #105930)
AmrDeveloper wrote: @pow2clk https://github.com/llvm/llvm-project/pull/105930 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Sema] Revisit the fix for the lambda within a type alias template decl (PR #89934)
https://github.com/cor3ntin edited https://github.com/llvm/llvm-project/pull/89934 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][FMV] Pass the '+fmv' target-feature when FMV is enabled. (PR #87942)
labrinea wrote: > @labrinea @jroelofs Is there anything that still needs to be done here or can > this be merged? Currently the dependent PR #87939 is on hold. Unless it moves forward this PR is not needed. https://github.com/llvm/llvm-project/pull/87942 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [RISCV][FMV] Support target_clones (PR #85786)
https://github.com/BeMg updated https://github.com/llvm/llvm-project/pull/85786 >From 395ce72afbf9e4b12fcbfaf9cdbda8921c9ff72a Mon Sep 17 00:00:00 2001 From: Piyou Chen Date: Tue, 23 Jul 2024 19:59:06 -0700 Subject: [PATCH 01/13] [RISCV][FMV] Support target_clones --- .../clang/Basic/DiagnosticFrontendKinds.td| 4 + clang/include/clang/Basic/TargetInfo.h| 3 +- clang/include/clang/Sema/SemaRISCV.h | 1 + clang/lib/AST/ASTContext.cpp | 12 + clang/lib/CodeGen/CodeGenFunction.cpp | 106 - clang/lib/CodeGen/CodeGenFunction.h | 3 + clang/lib/CodeGen/CodeGenModule.cpp | 5 +- clang/lib/CodeGen/Targets/RISCV.cpp | 35 +++ clang/lib/Sema/SemaDeclAttr.cpp | 30 +++ clang/lib/Sema/SemaRISCV.cpp | 10 + .../attr-target-clones-riscv-invalid.c| 8 + clang/test/CodeGen/attr-target-clones-riscv.c | 211 ++ .../CodeGenCXX/attr-target-clones-riscv.cpp | 210 + .../test/SemaCXX/attr-target-clones-riscv.cpp | 35 +++ 14 files changed, 670 insertions(+), 3 deletions(-) create mode 100644 clang/test/CodeGen/attr-target-clones-riscv-invalid.c create mode 100644 clang/test/CodeGen/attr-target-clones-riscv.c create mode 100644 clang/test/CodeGenCXX/attr-target-clones-riscv.cpp create mode 100644 clang/test/SemaCXX/attr-target-clones-riscv.cpp diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td b/clang/include/clang/Basic/DiagnosticFrontendKinds.td index 8a1462c670d68f..0c870a1f3f1442 100644 --- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td +++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td @@ -378,4 +378,8 @@ def warn_missing_symbol_graph_dir : Warning< def err_ast_action_on_llvm_ir : Error< "cannot apply AST actions to LLVM IR file '%0'">, DefaultFatal; + +def err_os_unsupport_riscv_target_clones : Error< + "target_clones is currently only supported on Linux">; + } diff --git a/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h index a58fb5f9792720..f31d88a354ea28 100644 --- a/clang/include/clang/Basic/TargetInfo.h +++ b/clang/include/clang/Basic/TargetInfo.h @@ -1496,7 +1496,8 @@ class TargetInfo : public TransferrableTargetInfo, /// Identify whether this target supports multiversioning of functions, /// which requires support for cpu_supports and cpu_is functionality. bool supportsMultiVersioning() const { -return getTriple().isX86() || getTriple().isAArch64(); +return getTriple().isX86() || getTriple().isAArch64() || + getTriple().isRISCV(); } /// Identify whether this target supports IFuncs. diff --git a/clang/include/clang/Sema/SemaRISCV.h b/clang/include/clang/Sema/SemaRISCV.h index d62fca8128b2a3..d7f17797283b86 100644 --- a/clang/include/clang/Sema/SemaRISCV.h +++ b/clang/include/clang/Sema/SemaRISCV.h @@ -43,6 +43,7 @@ class SemaRISCV : public SemaBase { void handleInterruptAttr(Decl *D, const ParsedAttr &AL); bool isAliasValid(unsigned BuiltinID, llvm::StringRef AliasName); + bool isValidFMVExtension(StringRef Ext); /// Indicate RISC-V vector builtin functions enabled or not. bool DeclareRVVBuiltins = false; diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index b201d201e1ea6a..a4d123219770bb 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -14181,6 +14181,18 @@ void ASTContext::getFunctionFeatureMap(llvm::StringMap &FeatureMap, Target->getTargetOpts().FeaturesAsWritten.begin(), Target->getTargetOpts().FeaturesAsWritten.end()); Target->initFeatureMap(FeatureMap, getDiagnostics(), TargetCPU, Features); +} else if (Target->getTriple().isRISCV()) { + StringRef VersionStr = TC->getFeatureStr(GD.getMultiVersionIndex()); + std::vector Features; + if (VersionStr != "default") { +ParsedTargetAttr ParsedAttr = Target->parseTargetAttr(VersionStr); +Features.insert(Features.begin(), ParsedAttr.Features.begin(), +ParsedAttr.Features.end()); + } + Features.insert(Features.begin(), + Target->getTargetOpts().FeaturesAsWritten.begin(), + Target->getTargetOpts().FeaturesAsWritten.end()); + Target->initFeatureMap(FeatureMap, getDiagnostics(), TargetCPU, Features); } else { std::vector Features; StringRef VersionStr = TC->getFeatureStr(GD.getMultiVersionIndex()); diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index eff8c9f5694084..d625dde684933b 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -2877,12 +2877,116 @@ void CodeGenFunction::EmitMultiVersionResolver( case llvm::Triple::aarch64: EmitAArch64MultiVersionResolver(Resolver, Options); return; + case llvm::Triple::riscv32: + case
[clang] [clang][HLSL] Update DXIL/SPIRV hybird CodeGen tests to use temp var (PR #105930)
https://github.com/AmrDeveloper updated https://github.com/llvm/llvm-project/pull/105930 >From 4568aab8bfd39be10a3df69535e083f3429e3a9e Mon Sep 17 00:00:00 2001 From: AmrDeveloper Date: Sat, 24 Aug 2024 10:08:23 +0200 Subject: [PATCH] [clang][HLSL] Update DXIL/SPIRV hybird CodeGen tests to use temp var Update all hybird DXIL/SPIRV codegen tests to use temp variable representing interchange target --- .../GlobalConstructorFunction.hlsl| 2 +- .../test/CodeGenHLSL/GlobalConstructors.hlsl | 2 +- clang/test/CodeGenHLSL/GlobalDestructors.hlsl | 2 +- .../builtins/RWBuffer-constructor.hlsl| 9 +- clang/test/CodeGenHLSL/builtins/all.hlsl | 176 +- clang/test/CodeGenHLSL/builtins/any.hlsl | 176 +- .../CodeGenHLSL/builtins/clamp-builtin.hlsl | 2 +- clang/test/CodeGenHLSL/builtins/clamp.hlsl| 80 .../CodeGenHLSL/builtins/create_handle.hlsl | 2 +- clang/test/CodeGenHLSL/builtins/frac.hlsl | 48 ++--- clang/test/CodeGenHLSL/builtins/isinf.hlsl| 24 +-- clang/test/CodeGenHLSL/builtins/length.hlsl | 18 +- .../CodeGenHLSL/builtins/lerp-builtin.hlsl| 4 +- clang/test/CodeGenHLSL/builtins/lerp.hlsl | 60 +++--- clang/test/CodeGenHLSL/builtins/mad.hlsl | 48 ++--- .../test/CodeGenHLSL/builtins/normalize.hlsl | 48 ++--- clang/test/CodeGenHLSL/builtins/rsqrt.hlsl| 48 ++--- clang/test/CodeGenHLSL/builtins/saturate.hlsl | 64 +++ .../semantics/DispatchThreadID.hlsl | 12 +- .../semantics/GroupIndex-codegen.hlsl | 2 +- 20 files changed, 414 insertions(+), 413 deletions(-) diff --git a/clang/test/CodeGenHLSL/GlobalConstructorFunction.hlsl b/clang/test/CodeGenHLSL/GlobalConstructorFunction.hlsl index f954c9d2f029f2..6856cccb3fc3eb 100644 --- a/clang/test/CodeGenHLSL/GlobalConstructorFunction.hlsl +++ b/clang/test/CodeGenHLSL/GlobalConstructorFunction.hlsl @@ -25,7 +25,7 @@ void main(unsigned GI : SV_GroupIndex) {} //CHECK-NEXT: entry: //CHECK-NEXT: call void @"?call_me_first@@YAXXZ"() //CHECK-NEXT: call void @"?then_call_me@@YAXXZ"() -//CHECK-NEXT: %0 = call i32 @llvm.dx.flattened.thread.id.in.group() +//CHECK-NEXT: %0 = call i32 @llvm.[[ICF:dx]].flattened.thread.id.in.group() //CHECK-NEXT: call void @"?main@@YAXI@Z"(i32 %0) //CHECK-NEXT: call void @"?call_me_last@@YAXXZ"( //CHECK-NEXT: ret void diff --git a/clang/test/CodeGenHLSL/GlobalConstructors.hlsl b/clang/test/CodeGenHLSL/GlobalConstructors.hlsl index 7e2f288726c954..676a24b2467c18 100644 --- a/clang/test/CodeGenHLSL/GlobalConstructors.hlsl +++ b/clang/test/CodeGenHLSL/GlobalConstructors.hlsl @@ -11,6 +11,6 @@ void main(unsigned GI : SV_GroupIndex) {} //CHECK: define void @main() //CHECK-NEXT: entry: //CHECK-NEXT: call void @_GLOBAL__sub_I_GlobalConstructors.hlsl() -//CHECK-NEXT: %0 = call i32 @llvm.dx.flattened.thread.id.in.group() +//CHECK-NEXT: %0 = call i32 @llvm.[[ICF:dx]].flattened.thread.id.in.group() //CHECK-NEXT: call void @"?main@@YAXI@Z"(i32 %0) //CHECK-NEXT: ret void diff --git a/clang/test/CodeGenHLSL/GlobalDestructors.hlsl b/clang/test/CodeGenHLSL/GlobalDestructors.hlsl index 24c3c039fc6192..d98a54bbc49fe8 100644 --- a/clang/test/CodeGenHLSL/GlobalDestructors.hlsl +++ b/clang/test/CodeGenHLSL/GlobalDestructors.hlsl @@ -52,7 +52,7 @@ void main(unsigned GI : SV_GroupIndex) { //CHECK: define void @main() //CHECK-NEXT: entry: //CHECK-NEXT: call void @_GLOBAL__sub_I_GlobalDestructors.hlsl() -//CHECK-NEXT: %0 = call i32 @llvm.dx.flattened.thread.id.in.group() +//CHECK-NEXT: %0 = call i32 @llvm.[[ICF:dx]].flattened.thread.id.in.group() //CHECK-NEXT: call void @"?main@@YAXI@Z"(i32 %0) //CHECK-NEXT: call void @_GLOBAL__D_a() //CHECK-NEXT: ret void diff --git a/clang/test/CodeGenHLSL/builtins/RWBuffer-constructor.hlsl b/clang/test/CodeGenHLSL/builtins/RWBuffer-constructor.hlsl index e51eac7f57c2d3..1a2e9aa490709c 100644 --- a/clang/test/CodeGenHLSL/builtins/RWBuffer-constructor.hlsl +++ b/clang/test/CodeGenHLSL/builtins/RWBuffer-constructor.hlsl @@ -1,12 +1,13 @@ -// RUN: %clang_cc1 -triple spirv-vulkan-library -x hlsl -emit-llvm -disable-llvm-passes -o - %s | FileCheck %s --check-prefix=CHECK-SPIRV +// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -emit-llvm -disable-llvm-passes -o - %s | FileCheck %s --check-prefixes=DXCHECK + +// RUN: %clang_cc1 -triple spirv-vulkan-library -x hlsl -emit-llvm -disable-llvm-passes -o - %s | FileCheck %s --check-prefixes=SPVCHECK RWBuffer Buf; // CHECK: define linkonce_odr noundef ptr @"??0?$RWBuffer@M@hlsl@@QAA@XZ" // CHECK-NEXT: entry: -// CHECK: %[[HandleRes:[0-9]+]] = call ptr @llvm.dx.create.handle(i8 1) +// DXCHECK: %[[HandleRes:[0-9]+]] = call ptr @llvm.[[ICF:dx]].create.handle(i8 1) +// SPVCHECK: %[[HandleRes:[0-9]+]] = call ptr @llvm.[[ICF:spv]].create.handle(i8 1) // CHECK: store ptr %[[HandleRes]], ptr %h, align 4 -// CHECK-SPIRV: %[[HandleRes:[0-9]+]] = ca
[clang] [clang][test] add TestLanguage.def to specify all tested language versions (PR #94243)
https://github.com/5chmidti updated https://github.com/llvm/llvm-project/pull/94243 >From 1ef1bc0bfebca8ca114a57ea2d5016418e36446d Mon Sep 17 00:00:00 2001 From: Julian Schmidt Date: Sat, 1 Jun 2024 17:38:37 +0200 Subject: [PATCH 1/3] [clang][test] add TestLanguage.def to specify all tested language versions Adds a def file to have a single location where tested language versions are specified. Removes the need to update multiple locations in the testing infrastructure to add a new language version to be tested. Test instatiation can now include all languages without needing to specify them. This patch also adds pretty printing for instantiated test names. That means, that a test instantiated with C++23 will have the name `...TestSuite/TestName/CXX23` instead ending with some number (index of the argument for instantiation of the test), which improves a better experience when encountering a test failure with a specific language version. The suffix will also contain an `_win` if the target contains `win`. --- clang/include/clang/Testing/CommandLineArgs.h | 17 +- clang/include/clang/Testing/TestClangConfig.h | 146 +++--- clang/include/clang/Testing/TestLanguage.def | 39 + clang/lib/Testing/CommandLineArgs.cpp | 119 +++--- clang/unittests/AST/MatchVerifier.h | 37 + .../ASTMatchers/ASTMatchersNodeTest.cpp | 18 ++- .../ASTMatchers/ASTMatchersTraversalTest.cpp | 10 +- .../Tooling/Syntax/BuildTreeTest.cpp | 8 +- .../Tooling/Syntax/MutationsTest.cpp | 7 +- .../Tooling/Syntax/SynthesisTest.cpp | 7 +- clang/unittests/Tooling/Syntax/TreeTest.cpp | 14 +- .../unittests/Tooling/Syntax/TreeTestBase.cpp | 7 +- 12 files changed, 280 insertions(+), 149 deletions(-) create mode 100644 clang/include/clang/Testing/TestLanguage.def diff --git a/clang/include/clang/Testing/CommandLineArgs.h b/clang/include/clang/Testing/CommandLineArgs.h index e71907e8bbd0c6..52beac7254fefc 100644 --- a/clang/include/clang/Testing/CommandLineArgs.h +++ b/clang/include/clang/Testing/CommandLineArgs.h @@ -21,19 +21,18 @@ namespace clang { enum TestLanguage { - Lang_C89, - Lang_C99, - Lang_CXX03, - Lang_CXX11, - Lang_CXX14, - Lang_CXX17, - Lang_CXX20, - Lang_CXX23, +#define TESTLANGUAGE(lang, version, std_flag, version_index) \ + Lang_##lang##version, +#include "clang/Testing/TestLanguage.def" + Lang_OpenCL, Lang_OBJC, - Lang_OBJCXX + Lang_OBJCXX, }; +std::vector getCOrLater(int MinimumStd); +std::vector getCXXOrLater(int MinimumStd); + std::vector getCommandLineArgsForTesting(TestLanguage Lang); std::vector getCC1ArgsForTesting(TestLanguage Lang); diff --git a/clang/include/clang/Testing/TestClangConfig.h b/clang/include/clang/Testing/TestClangConfig.h index 1b4efca80e9d47..4dd1eb9b6f39a0 100644 --- a/clang/include/clang/Testing/TestClangConfig.h +++ b/clang/include/clang/Testing/TestClangConfig.h @@ -27,37 +27,117 @@ struct TestClangConfig { /// The argument of the `-target` command line flag. std::string Target; - bool isC() const { return Language == Lang_C89 || Language == Lang_C99; } - - bool isC99OrLater() const { return Language == Lang_C99; } - - bool isCXX() const { -return Language == Lang_CXX03 || Language == Lang_CXX11 || - Language == Lang_CXX14 || Language == Lang_CXX17 || - Language == Lang_CXX20 || Language == Lang_CXX23; + bool isC() const { +return false +#define TESTLANGUAGE +#define TESTLANGUAGE_C(lang, version, std_flag, version_index) \ + || Language == Lang_##lang##version +#define TESTLANGUAGE_CXX(lang, version, std_flag, version_index) +#include "clang/Testing/TestLanguage.def" +; } - bool isCXX11OrLater() const { -return Language == Lang_CXX11 || Language == Lang_CXX14 || - Language == Lang_CXX17 || Language == Lang_CXX20 || - Language == Lang_CXX23; + bool isCOrLater(int MinimumStdVersion) const { +const auto MinimumStdVersionIndex = 0 +#define TESTLANGUAGE +#define TESTLANGUAGE_C(lang, version, std_flag, version_index) \ + +(MinimumStdVersion == version ? version_index : 0) +#define TESTLANGUAGE_CXX(lang, version, std_flag, version_index) +#include "clang/Testing/TestLanguage.def" +; +switch (Language) { +#define TESTLANGUAGE +#define TESTLANGUAGE_C(lang, version, std_flag, version_index) \ + case Lang_##lang##version: \ +return MinimumStdVersionIndex <= version_index; +#define TESTLANGUAGE_CXX(lang, version, std_flag, version_index) +#include "clang/Testing/TestLanguage.def" +default: + return false; +} } - bool isCXX14OrLater() const { -return Language == Lang_CXX14 || Language == Lang_CXX17 || - Language == Lang_CXX20 || Language == Lang_CXX23; + bool isC99OrLater() const { return isCOrLater(99); } + + bool isCOrEarlie
[clang] [clang][test] add TestLanguage.def to specify all tested language versions (PR #94243)
5chmidti wrote: rebase + ping. @AaronBallman could you check if this is okay now? I could merge the AST matcher doc testing stack if that is the case https://github.com/llvm/llvm-project/pull/94243 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [lldb] Use CLANG_RESOURCE_DIR more consistently (PR #103388)
kimgr wrote: Do we need anything more to make progress with this PR? My own primary concerns are basically things I can't check myself: * Is there an out-of-tree scenario where `CLANG_RESOURCE_DIR` needs to be replaced with something else at runtime, i.e. a real use-case for the optional `CustomResourceDir` optional argument I removed? * The only call in-tree whose behavior changed is https://github.com/llvm/llvm-project/blob/99b85cae628c1cc5641944290712cd84ccf1f6c8/clang/tools/libclang/CIndexer.cpp#L156. Is there any reason to think libclang should behave differently? Not sure who can shed light on these questions. https://github.com/llvm/llvm-project/pull/103388 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Use upper case letters for bool conversion suffix (PR #104882)
@@ -108,6 +108,11 @@ Changes in existing checks ` check to remove `->`, when reduntant `get()` is removed. +- Improved :doc:`readablility-implicit-bool-conversion 5chmidti wrote: Please sort your entry before `readability-redundant-smartptr-get` https://github.com/llvm/llvm-project/pull/104882 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Use upper case letters for bool conversion suffix (PR #104882)
https://github.com/5chmidti edited https://github.com/llvm/llvm-project/pull/104882 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Use upper case letters for bool conversion suffix (PR #104882)
https://github.com/5chmidti approved this pull request. LGTM but with two nits https://github.com/llvm/llvm-project/pull/104882 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Use upper case letters for bool conversion suffix (PR #104882)
@@ -392,8 +402,16 @@ void ImplicitBoolConversionCheck::handleCastFromBool( if (const auto *BoolLiteral = dyn_cast(Cast->getSubExpr()->IgnoreParens())) { -Diag << tooling::fixit::createReplacement( -*Cast, getEquivalentForBoolLiteral(BoolLiteral, DestType, Context)); + +const auto EquivalentForBoolLiteral = +getEquivalentForBoolLiteral(BoolLiteral, DestType, Context); +if (UseUpperCaseLiteralSuffix) { + Diag << tooling::fixit::createReplacement( + *Cast, EquivalentForBoolLiteral.upper()); +} else { + Diag << tooling::fixit::createReplacement(*Cast, +EquivalentForBoolLiteral); +} 5chmidti wrote: nit: do not use compound statements for single statements in control structures https://github.com/llvm/llvm-project/pull/104882 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Fix for cppcoreguidelines-pro-type-union-access if memLoc is invalid (PR #104540)
https://github.com/5chmidti requested changes to this pull request. This is still missing a release note, see https://github.com/llvm/llvm-project/blob/40975da950c95124155b752cd683d945f7d203fd/clang-tools-extra/docs/ReleaseNotes.rst?plain=1#L104 for where to add it and how they look like Functionality-wise, this looks good https://github.com/llvm/llvm-project/pull/104540 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [ASTMatchers] Extend hasName matcher when matching templates (PR #100349)
https://github.com/5chmidti edited https://github.com/llvm/llvm-project/pull/100349 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [ASTMatchers] Extend hasName matcher when matching templates (PR #100349)
@@ -638,6 +638,39 @@ bool HasNameMatcher::matchesNodeFullFast(const NamedDecl &Node) const { return Patterns.foundMatch(/*AllowFullyQualified=*/true); } +static std::optional consumePatternBack(StringRef Pattern, + StringRef Target) { + while (!Pattern.empty()) { +auto Index = Pattern.rfind("<*>"); +if (Index == StringRef::npos) { + if (Target.consume_back(Pattern)) +return Target; + return {}; +} +auto Suffix = Pattern.substr(Index + 2); +if (!Target.consume_back(Suffix)) 5chmidti wrote: Because I had to check this, could you please add a comment why only `+ 2` is used? Something like: > We consume pattern suffix that includes only the `>` of our `<*>`, and drop > every character from the back until we encounter the corresponding `<` > character to ensure balanced angle brackets. https://github.com/llvm/llvm-project/pull/100349 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [ASTMatchers] Extend hasName matcher when matching templates (PR #100349)
@@ -638,6 +638,39 @@ bool HasNameMatcher::matchesNodeFullFast(const NamedDecl &Node) const { return Patterns.foundMatch(/*AllowFullyQualified=*/true); } +static std::optional consumePatternBack(StringRef Pattern, + StringRef Target) { + while (!Pattern.empty()) { +auto Index = Pattern.rfind("<*>"); +if (Index == StringRef::npos) { + if (Target.consume_back(Pattern)) +return Target; + return {}; +} +auto Suffix = Pattern.substr(Index + 2); +if (!Target.consume_back(Suffix)) + return {}; +auto BracketCount = 1; +while (BracketCount) { + if (Target.empty()) +return {}; 5chmidti wrote: IMO returning `std::nullopt` is better here. https://github.com/llvm/llvm-project/pull/100349 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [ASTMatchers] Extend hasName matcher when matching templates (PR #100349)
@@ -638,6 +638,39 @@ bool HasNameMatcher::matchesNodeFullFast(const NamedDecl &Node) const { return Patterns.foundMatch(/*AllowFullyQualified=*/true); } +static std::optional consumePatternBack(StringRef Pattern, + StringRef Target) { + while (!Pattern.empty()) { +auto Index = Pattern.rfind("<*>"); +if (Index == StringRef::npos) { + if (Target.consume_back(Pattern)) +return Target; + return {}; +} +auto Suffix = Pattern.substr(Index + 2); +if (!Target.consume_back(Suffix)) + return {}; +auto BracketCount = 1; 5chmidti wrote: You're using `auto` three times here without the type mentioned on the RHS (not sure how strict `clang/` is w.r.t. this) `Suffix` and `Index` can be `const` https://github.com/llvm/llvm-project/pull/100349 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [ASTMatchers] Extend hasName matcher when matching templates (PR #100349)
https://github.com/5chmidti requested changes to this pull request. I think it does make sense to add this wildcard. The motivation to skip regex sounds like a good one, and it does make sense to special case templates specifically. The implementation looks correct to me. Just some small things to point out regarding the code, and the missing release notes, of course. Your pr comment should also reflect the change to `<*>` from `<>` https://github.com/llvm/llvm-project/pull/100349 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [ASTMatchers] Extend hasName matcher when matching templates (PR #100349)
@@ -653,10 +686,12 @@ bool HasNameMatcher::matchesNodeFullSlow(const NamedDecl &Node) const { for (const StringRef Pattern : Names) { if (Pattern.starts_with("::")) { -if (FullName == Pattern) +if (auto Result = consumePatternBack(Pattern, FullName); +Result && Result->empty()) { return true; - } else if (FullName.ends_with(Pattern) && - FullName.drop_back(Pattern.size()).ends_with("::")) { +} + } else if (auto Result = consumePatternBack(Pattern, FullName); + Result && Result->ends_with("::")) { return true; } 5chmidti wrote: You could write this loop body as ```c++ const std::optional Result = consumePatternBack(Pattern, FullName); if (!Result) continue; if ((Pattern.starts_with("::") && Result->empty()) || Result->ends_with("::")) return true; ``` which is more readable IMO https://github.com/llvm/llvm-project/pull/100349 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Create bugprone-incorrect-enable-shared-from-this check (PR #102299)
5chmidti wrote: > for me oryginal version that used registerMatchers instead of visitor were > way better, specially that there are matchers that could be used for this, or > could be written. We do have the `isDerivedFrom` matcher, actually. > in most projects not many classes actually used std::enable_shared_from_this > and there will be no visible performance gain from "remembering" list of > classes, and as we could see this approach makes this check more complicated. Maybe we should just go with what is simpler, and check the performance of the implementation, but I think it could be more performant. ```c++ struct A {}; struct B : public A {}; struct C : public B {}; struct D : public B {}; ``` When we are visiting a definition of a class, we know that every base class has been visited already, so we do not need to traverse the inheritance hierarchy and instead just need to check our set. We mark `A` as either an `enable_shared_from_this` class, or not. We check for `B`, if any of its base classes is already in the set, and the same goes for `C` and `D`. The base classes of `C` and `D` are never actually transitively traverse when we check `C` and `D`, but instead we do a lookup because we already computed the answer. --- @MichelleCDjunaidi Untested, but this should be roughly what needs to be done (minus the check for a missing `std::` in front of `enable_shared_from_this`). ```c++ bool VisitCXXRecordDecl(CXXRecordDecl *RDecl) { if (RDecl->getQualifiedNameAsString() == "std::enable_shared_from_this") EnableSharedClassSet.insert(RDecl->getCanonicalDecl()); for (const auto &Base : RDecl->bases()) { const auto* BaseRecord = Base.getType()->getAsCXXRecordDecl()->getCanonicalDecl(); if (EnableSharedClassSet.contains(BaseRecord)) { if (Base.getAccessSpecifier() != AccessSpecifier::AS_public) Check.diag(...); else EnableSharedClassSet.insert(RDecl->getCanonicalDecl()); } } return true; } ``` Your `VisitCXXBaseSpecifier` has the same name as the other visitor functions, but it is technically not in the format of the `RecursiveASTVisitor` and may be confusing. `Handle...` or `Check...` would be better IMO. Either way, the direction is still an open question https://github.com/llvm/llvm-project/pull/102299 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix a misannotation of less/greater as angle brackets (PR #105941)
https://github.com/owenca created https://github.com/llvm/llvm-project/pull/105941 Fixes #105877. >From 28983f4532df55ee31fc366fb5a945594c0baf1a Mon Sep 17 00:00:00 2001 From: Owen Pan Date: Sat, 24 Aug 2024 07:32:08 -0700 Subject: [PATCH] [clang-format] Fix a misannotation of less/greater as angle brackets Fixes #105877. --- clang/lib/Format/TokenAnnotator.cpp | 2 +- clang/unittests/Format/TokenAnnotatorTest.cpp | 5 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 0d5741ed76f7cb..a570a909313f41 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -250,7 +250,7 @@ class AnnotatingParser { if (Precedence > prec::Conditional && Precedence < prec::Relational) return false; } - if (Prev.is(TT_ConditionalExpr)) + if (Prev.isOneOf(tok::question, tok::colon) && !Style.isProto()) SeenTernaryOperator = true; updateParameterCount(Left, CurrentToken); if (Style.Language == FormatStyle::LK_Proto) { diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index 99798de43e70ff..bb28b175eb5d50 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -620,6 +620,11 @@ TEST_F(TokenAnnotatorTest, UnderstandsNonTemplateAngleBrackets) { EXPECT_TOKEN(Tokens[2], tok::less, TT_BinaryOperator); EXPECT_TOKEN(Tokens[8], tok::greater, TT_BinaryOperator); + Tokens = annotate("return checklower ? a < b : a > b;"); + ASSERT_EQ(Tokens.size(), 12u) << Tokens; + EXPECT_TOKEN(Tokens[4], tok::less, TT_BinaryOperator); + EXPECT_TOKEN(Tokens[8], tok::greater, TT_BinaryOperator); + Tokens = annotate("return A < B ^ A > B;"); ASSERT_EQ(Tokens.size(), 10u) << Tokens; EXPECT_TOKEN(Tokens[2], tok::less, TT_BinaryOperator); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix a misannotation of less/greater as angle brackets (PR #105941)
llvmbot wrote: @llvm/pr-subscribers-clang-format Author: Owen Pan (owenca) Changes Fixes #105877. --- Full diff: https://github.com/llvm/llvm-project/pull/105941.diff 2 Files Affected: - (modified) clang/lib/Format/TokenAnnotator.cpp (+1-1) - (modified) clang/unittests/Format/TokenAnnotatorTest.cpp (+5) ``diff diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 0d5741ed76f7cb..a570a909313f41 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -250,7 +250,7 @@ class AnnotatingParser { if (Precedence > prec::Conditional && Precedence < prec::Relational) return false; } - if (Prev.is(TT_ConditionalExpr)) + if (Prev.isOneOf(tok::question, tok::colon) && !Style.isProto()) SeenTernaryOperator = true; updateParameterCount(Left, CurrentToken); if (Style.Language == FormatStyle::LK_Proto) { diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index 99798de43e70ff..bb28b175eb5d50 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -620,6 +620,11 @@ TEST_F(TokenAnnotatorTest, UnderstandsNonTemplateAngleBrackets) { EXPECT_TOKEN(Tokens[2], tok::less, TT_BinaryOperator); EXPECT_TOKEN(Tokens[8], tok::greater, TT_BinaryOperator); + Tokens = annotate("return checklower ? a < b : a > b;"); + ASSERT_EQ(Tokens.size(), 12u) << Tokens; + EXPECT_TOKEN(Tokens[4], tok::less, TT_BinaryOperator); + EXPECT_TOKEN(Tokens[8], tok::greater, TT_BinaryOperator); + Tokens = annotate("return A < B ^ A > B;"); ASSERT_EQ(Tokens.size(), 10u) << Tokens; EXPECT_TOKEN(Tokens[2], tok::less, TT_BinaryOperator); `` https://github.com/llvm/llvm-project/pull/105941 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix a misannotation of less/greater as angle brackets (PR #105941)
https://github.com/owenca milestoned https://github.com/llvm/llvm-project/pull/105941 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Update TODO comment check (PR #104868)
@@ -24,3 +24,7 @@ // TODO(b/12345): find the holy grail // TODO (b/12345): allow spaces before parentheses // TODO(asdf) allow missing semicolon +// TODO: bug 12345678 - Remove this after the 2047q4 compatibility window expires. +// TODO: example.com/my-design-doc - Manually fix up this code the next time it's touched. +// TODO(bug 12345678): Update this list after the Foo service is turned down. +// TODO(John): Use a "\*" here for concatenation operator. 5chmidti wrote: Given that this is the text from the style-guide, I'd be concerned regarding licensing? It's under CC 3.0 You could just rewrite the lines that were already here to fit the pattern https://github.com/llvm/llvm-project/pull/104868 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Update TODO comment check (PR #104868)
@@ -9,6 +9,7 @@ #include "TodoCommentCheck.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Lex/Preprocessor.h" +#include 5chmidti wrote: Please remove this unused include https://github.com/llvm/llvm-project/pull/104868 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Fix for cppcoreguidelines-pro-type-union-access if memLoc is invalid (PR #104540)
ksromanov wrote: > This is still missing a release note, see Many thanks! This is my first PR to `llvm`, I didn't know about it, sorry. https://github.com/llvm/llvm-project/pull/104540 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Fix for cppcoreguidelines-pro-type-union-access if memLoc is invalid (PR #104540)
https://github.com/ksromanov updated https://github.com/llvm/llvm-project/pull/104540 >From 31ed1cf97be643b3a6c9a05d4e461789c37e2408 Mon Sep 17 00:00:00 2001 From: Konstantin Romanov Date: Fri, 9 Aug 2024 23:40:07 -0400 Subject: [PATCH 1/5] Workaround for cppcoreguidelines-pro-type-union-access if member location is invalid. --- .../cppcoreguidelines/ProTypeUnionAccessCheck.cpp | 8 ++-- .../checkers/cppcoreguidelines/pro-type-union-access.cpp | 7 +++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeUnionAccessCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeUnionAccessCheck.cpp index 1ed444e630ec25..0e9185956b7aa8 100644 --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeUnionAccessCheck.cpp +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeUnionAccessCheck.cpp @@ -23,8 +23,12 @@ void ProTypeUnionAccessCheck::registerMatchers(MatchFinder *Finder) { void ProTypeUnionAccessCheck::check(const MatchFinder::MatchResult &Result) { const auto *Matched = Result.Nodes.getNodeAs("expr"); - diag(Matched->getMemberLoc(), - "do not access members of unions; use (boost::)variant instead"); + if (auto MemberLoc = Matched->getMemberLoc(); MemberLoc.isValid()) +diag(MemberLoc, + "do not access members of unions; use (boost::)variant instead"); + else +diag(Matched->getBeginLoc(), + "do not access members of unions; use (boost::)variant instead"); } } // namespace clang::tidy::cppcoreguidelines diff --git a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-union-access.cpp b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-union-access.cpp index 6abc22b9e4345e..46bb06ba2c8fbe 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-union-access.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-union-access.cpp @@ -5,6 +5,10 @@ union U { char union_member2; } u; +union W { + template operator TP *() const; +}; + struct S { int non_union_member; union { @@ -20,6 +24,7 @@ void f(char); void f2(U); void f3(U&); void f4(U*); +W f5(); void check() { @@ -38,4 +43,6 @@ void check() f2(u); // OK f3(u); // OK f4(&u); // OK + void *ret = f5(); + // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: do not access members of unions; use (boost::)variant instead } >From f271361fba45dbe5fc5a8d566c60e7265d30 Mon Sep 17 00:00:00 2001 From: Konstantin Romanov Date: Fri, 16 Aug 2024 12:35:30 -0400 Subject: [PATCH 2/5] Update clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeUnionAccessCheck.cpp Co-authored-by: Piotr Zegar --- .../cppcoreguidelines/ProTypeUnionAccessCheck.cpp | 10 -- 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeUnionAccessCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeUnionAccessCheck.cpp index 0e9185956b7aa8..a5b8d1e9a1696c 100644 --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeUnionAccessCheck.cpp +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeUnionAccessCheck.cpp @@ -23,12 +23,10 @@ void ProTypeUnionAccessCheck::registerMatchers(MatchFinder *Finder) { void ProTypeUnionAccessCheck::check(const MatchFinder::MatchResult &Result) { const auto *Matched = Result.Nodes.getNodeAs("expr"); - if (auto MemberLoc = Matched->getMemberLoc(); MemberLoc.isValid()) -diag(MemberLoc, - "do not access members of unions; use (boost::)variant instead"); - else -diag(Matched->getBeginLoc(), - "do not access members of unions; use (boost::)variant instead"); + SourceLocation Loc = Matched->getMemberLoc(); + if (Loc.isInvalid()) + Loc = Matched->getBeginLoc(); + diag(Loc, "do not access members of unions; use (boost::)variant instead"); } } // namespace clang::tidy::cppcoreguidelines >From 87f1f4cd3575fd0215b48b02f5aa03ae40251525 Mon Sep 17 00:00:00 2001 From: Konstantin Romanov Date: Fri, 16 Aug 2024 12:37:07 -0400 Subject: [PATCH 3/5] Address comments. --- .../clang-tidy/cppcoreguidelines/ProTypeUnionAccessCheck.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeUnionAccessCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeUnionAccessCheck.cpp index a5b8d1e9a1696c..c29c4eb60f9d1a 100644 --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeUnionAccessCheck.cpp +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeUnionAccessCheck.cpp @@ -25,8 +25,9 @@ void ProTypeUnionAccessCheck::check(const MatchFinder::MatchResult &Result) { const auto *Matched = Result.Nodes.getNodeAs("expr"); SourceLocation Loc = Matched->getMemberLoc(); if (Loc.isInvalid()) - Loc = Matched->getBeginLoc(); - diag(Loc, "do not access members of unions; use (boost::)
[clang-tools-extra] [clang-tidy] Fix for cppcoreguidelines-pro-type-union-access if memLoc is invalid (PR #104540)
@@ -116,6 +116,10 @@ Changes in existing checks ` check to remove `->`, when redundant `get()` is removed. +- Fixed :doc:`cppcoreguidelines-pro-type-union-access + ` check to + report location even when member location is not valid. 5chmidti wrote: nit: `... report a location even when the member ...` https://github.com/llvm/llvm-project/pull/104540 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Fix for cppcoreguidelines-pro-type-union-access if memLoc is invalid (PR #104540)
https://github.com/5chmidti approved this pull request. https://github.com/llvm/llvm-project/pull/104540 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Match MSVC handling of duplicate header search paths in Microsoft compatibility modes. (PR #105738)
https://github.com/tahonermann updated https://github.com/llvm/llvm-project/pull/105738 >From 57192d52acfdab7f253da013b89cc2f7cef037a3 Mon Sep 17 00:00:00 2001 From: Tom Honermann Date: Thu, 22 Aug 2024 09:44:56 -0700 Subject: [PATCH] [Clang] Match MSVC handling of duplicate header search paths in Microsoft compatibility modes. Clang has historically mimicked gcc behavior for header file searching in which user search paths are ordered before system search paths, user search paths that duplicate a (later) system search path are ignored, and search paths that duplicate an earlier search path of the same user/system kind are ignored. MSVC behavior differs in that user search paths are ordered before system search paths (like gcc), and search paths that duplicate an earlier search path are ignored regardless of user/system kind (similar to gcc, but without the preference for system search paths over duplicate user search paths). The gcc and MSVC differences are observable for driver invocations that pass, e.g., `-Idir1 -isystem dir2 -isystem dir1`. The gcc behavior will result in `dir2` being searched before `dir1` while the MSVC behavior will result in `dir1` being searched before `dir2`. This patch modifies Clang to match the MSVC behavior for handling of duplicate header search paths when running in Microsoft compatibility mode (e.g., when invoked with the `-fms-compatibility` option explicitly or implicitly enabled). --- clang/docs/ReleaseNotes.rst | 14 +++ clang/lib/Lex/InitHeaderSearch.cpp| 21 ++-- clang/test/Driver/header-search-duplicates.c | 76 +++ .../microsoft-header-search-duplicates.c | 97 +++ 4 files changed, 199 insertions(+), 9 deletions(-) create mode 100644 clang/test/Driver/header-search-duplicates.c create mode 100644 clang/test/Driver/microsoft-header-search-duplicates.c diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 5c156a9c073a9c..d9c96d8902efa9 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -363,6 +363,20 @@ Windows Support When `-fms-compatibility-version=18.00` or prior is set on the command line this Microsoft extension is still allowed as VS2013 and prior allow it. +- Clang now matches MSVC behavior for handling of duplicate header search paths + when running in Microsoft compatibility mode. Historically, Clang has + mimicked gcc behavior in which user search paths are ordered before + system search paths, user search paths that duplicate a (later) system search + path are ignored, and search paths that duplicate an earlier search path of + the same user/system kind are ignored. The MSVC behavior is that user search + paths are ordered before system search paths (like gcc), and search paths that + duplicate an earlier search path are ignored regardless of user/system kind + (similar to gcc, but without the preference for system search paths over + duplicate user search paths). These differences are observable for driver + invocations that pass, e.g., `-Idir1 -isystem dir2 -isystem dir1`. The gcc + behavior will search `dir2` before `dir1` and the MSVC behavior will search + `dir1` before `dir2`. + LoongArch Support ^ diff --git a/clang/lib/Lex/InitHeaderSearch.cpp b/clang/lib/Lex/InitHeaderSearch.cpp index 2218db15013d92..3f487f3a4c1c05 100644 --- a/clang/lib/Lex/InitHeaderSearch.cpp +++ b/clang/lib/Lex/InitHeaderSearch.cpp @@ -368,7 +368,8 @@ void InitHeaderSearch::AddDefaultIncludePaths( /// If there are duplicate directory entries in the specified search list, /// remove the later (dead) ones. Returns the number of non-system headers /// removed, which is used to update NumAngled. -static unsigned RemoveDuplicates(std::vector &SearchList, +static unsigned RemoveDuplicates(const LangOptions &Lang, + std::vector &SearchList, unsigned First, bool Verbose) { llvm::SmallPtrSet SeenDirs; llvm::SmallPtrSet SeenFrameworkDirs; @@ -394,14 +395,15 @@ static unsigned RemoveDuplicates(std::vector &SearchList, continue; } -// If we have a normal #include dir/framework/headermap that is shadowed -// later in the chain by a system include location, we actually want to -// ignore the user's request and drop the user dir... keeping the system -// dir. This is weird, but required to emulate GCC's search path correctly. +// When not in MSVC compatibility mode, if we have a normal +// #include dir/framework/headermap that is shadowed later in the chain by +// a system include location, we actually want to ignore the user's request +// and drop the user dir... keeping the system dir. This is weird, but +// required to emulate GCC's search path correctly. // // Since dupes of system dirs are rare, just rescan to find the original // that we're nuking instead of using a DenseM
[clang-tools-extra] [clangd] Let DefineOutline tweak handle member functions (PR #95235)
https://github.com/5chmidti edited https://github.com/llvm/llvm-project/pull/95235 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Let DefineOutline tweak handle member functions (PR #95235)
https://github.com/5chmidti commented: >From a functionality standpoint, this looks good to me. I noted some small >things in the code, and this is also missing a release not entry. https://github.com/llvm/llvm-project/pull/95235 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Let DefineOutline tweak handle member functions (PR #95235)
@@ -212,9 +232,13 @@ getFunctionSourceCode(const FunctionDecl *FD, const DeclContext *TargetContext, } } const NamedDecl *ND = Ref.Targets.front(); -const std::string Qualifier = +std::string Qualifier = getQualification(AST, TargetContext, SM.getLocForStartOfFile(SM.getMainFileID()), ND); +if (ND->getDeclContext()->isDependentContext()) { + if (llvm::isa(ND)) 5chmidti wrote: Merge these two `if`s with a `&&` https://github.com/llvm/llvm-project/pull/95235 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Let DefineOutline tweak handle member functions (PR #95235)
@@ -407,10 +431,21 @@ class DefineOutline : public Tweak { return !SameFile; } -// Bail out in templated classes, as it is hard to spell the class name, -// i.e if the template parameter is unnamed. -if (MD->getParent()->isTemplated()) - return false; +for (const CXXRecordDecl *Parent = MD->getParent(); Parent; + Parent = + llvm::dyn_cast_or_null(Parent->getParent())) { + if (auto Params = Parent->getDescribedTemplateParams()) { 5chmidti wrote: Please explicitly write the type, it is not clear from the rhs what it is (`const TemplateParameterList *`) https://github.com/llvm/llvm-project/pull/95235 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Let DefineOutline tweak handle member functions (PR #95235)
@@ -407,10 +431,21 @@ class DefineOutline : public Tweak { return !SameFile; } -// Bail out in templated classes, as it is hard to spell the class name, -// i.e if the template parameter is unnamed. -if (MD->getParent()->isTemplated()) - return false; +for (const CXXRecordDecl *Parent = MD->getParent(); Parent; + Parent = + llvm::dyn_cast_or_null(Parent->getParent())) { + if (auto Params = Parent->getDescribedTemplateParams()) { + +// Class template member functions must be defined in the +// same file. +SameFile = true; + +for (NamedDecl *P : *Params) { + if (!P->getIdentifier()) +return false; 5chmidti wrote: A comment explaining why we bail out here would be good. FWICT, it is because we can't spell out unnamed params in the outlined definition? https://github.com/llvm/llvm-project/pull/95235 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Let DefineOutline tweak handle member functions (PR #95235)
@@ -144,8 +144,13 @@ getQualification(ASTContext &Context, const DeclContext *DestContext, // since we stored inner-most parent first. std::string Result; llvm::raw_string_ostream OS(Result); - for (const auto *Parent : llvm::reverse(Parents)) + for (const auto *Parent : llvm::reverse(Parents)) { +if (Parent != *Parents.rbegin() && Parent->isDependent() && +Parent->getAsRecordDecl() && +Parent->getAsRecordDecl()->getDescribedClassTemplate()) 5chmidti wrote: Save the duplicate call to `getAsRecordDecl` by adding a variable? (+-) https://github.com/llvm/llvm-project/pull/95235 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Let DefineOutline tweak handle member functions (PR #95235)
@@ -128,7 +128,27 @@ getFunctionSourceAfterReplacements(const FunctionDecl *FD, SM.getBufferData(SM.getMainFileID()), Replacements); if (!QualifiedFunc) return QualifiedFunc.takeError(); - return QualifiedFunc->substr(FuncBegin, FuncEnd - FuncBegin + 1); + + std::string TemplatePrefix; + if (auto *MD = llvm::dyn_cast(FD)) { +for (const CXXRecordDecl *Parent = MD->getParent(); Parent; + Parent = + llvm::dyn_cast_or_null(Parent->getParent())) { + if (auto Params = Parent->getDescribedTemplateParams()) { 5chmidti wrote: Please explicitly write the type here https://github.com/llvm/llvm-project/pull/95235 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Let DefineOutline tweak handle member functions (PR #95235)
https://github.com/5chmidti edited https://github.com/llvm/llvm-project/pull/95235 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Fix for cppcoreguidelines-pro-type-union-access if memLoc is invalid (PR #104540)
https://github.com/ksromanov updated https://github.com/llvm/llvm-project/pull/104540 >From 31ed1cf97be643b3a6c9a05d4e461789c37e2408 Mon Sep 17 00:00:00 2001 From: Konstantin Romanov Date: Fri, 9 Aug 2024 23:40:07 -0400 Subject: [PATCH 1/6] Workaround for cppcoreguidelines-pro-type-union-access if member location is invalid. --- .../cppcoreguidelines/ProTypeUnionAccessCheck.cpp | 8 ++-- .../checkers/cppcoreguidelines/pro-type-union-access.cpp | 7 +++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeUnionAccessCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeUnionAccessCheck.cpp index 1ed444e630ec25..0e9185956b7aa8 100644 --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeUnionAccessCheck.cpp +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeUnionAccessCheck.cpp @@ -23,8 +23,12 @@ void ProTypeUnionAccessCheck::registerMatchers(MatchFinder *Finder) { void ProTypeUnionAccessCheck::check(const MatchFinder::MatchResult &Result) { const auto *Matched = Result.Nodes.getNodeAs("expr"); - diag(Matched->getMemberLoc(), - "do not access members of unions; use (boost::)variant instead"); + if (auto MemberLoc = Matched->getMemberLoc(); MemberLoc.isValid()) +diag(MemberLoc, + "do not access members of unions; use (boost::)variant instead"); + else +diag(Matched->getBeginLoc(), + "do not access members of unions; use (boost::)variant instead"); } } // namespace clang::tidy::cppcoreguidelines diff --git a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-union-access.cpp b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-union-access.cpp index 6abc22b9e4345e..46bb06ba2c8fbe 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-union-access.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-union-access.cpp @@ -5,6 +5,10 @@ union U { char union_member2; } u; +union W { + template operator TP *() const; +}; + struct S { int non_union_member; union { @@ -20,6 +24,7 @@ void f(char); void f2(U); void f3(U&); void f4(U*); +W f5(); void check() { @@ -38,4 +43,6 @@ void check() f2(u); // OK f3(u); // OK f4(&u); // OK + void *ret = f5(); + // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: do not access members of unions; use (boost::)variant instead } >From f271361fba45dbe5fc5a8d566c60e7265d30 Mon Sep 17 00:00:00 2001 From: Konstantin Romanov Date: Fri, 16 Aug 2024 12:35:30 -0400 Subject: [PATCH 2/6] Update clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeUnionAccessCheck.cpp Co-authored-by: Piotr Zegar --- .../cppcoreguidelines/ProTypeUnionAccessCheck.cpp | 10 -- 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeUnionAccessCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeUnionAccessCheck.cpp index 0e9185956b7aa8..a5b8d1e9a1696c 100644 --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeUnionAccessCheck.cpp +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeUnionAccessCheck.cpp @@ -23,12 +23,10 @@ void ProTypeUnionAccessCheck::registerMatchers(MatchFinder *Finder) { void ProTypeUnionAccessCheck::check(const MatchFinder::MatchResult &Result) { const auto *Matched = Result.Nodes.getNodeAs("expr"); - if (auto MemberLoc = Matched->getMemberLoc(); MemberLoc.isValid()) -diag(MemberLoc, - "do not access members of unions; use (boost::)variant instead"); - else -diag(Matched->getBeginLoc(), - "do not access members of unions; use (boost::)variant instead"); + SourceLocation Loc = Matched->getMemberLoc(); + if (Loc.isInvalid()) + Loc = Matched->getBeginLoc(); + diag(Loc, "do not access members of unions; use (boost::)variant instead"); } } // namespace clang::tidy::cppcoreguidelines >From 87f1f4cd3575fd0215b48b02f5aa03ae40251525 Mon Sep 17 00:00:00 2001 From: Konstantin Romanov Date: Fri, 16 Aug 2024 12:37:07 -0400 Subject: [PATCH 3/6] Address comments. --- .../clang-tidy/cppcoreguidelines/ProTypeUnionAccessCheck.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeUnionAccessCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeUnionAccessCheck.cpp index a5b8d1e9a1696c..c29c4eb60f9d1a 100644 --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeUnionAccessCheck.cpp +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeUnionAccessCheck.cpp @@ -25,8 +25,9 @@ void ProTypeUnionAccessCheck::check(const MatchFinder::MatchResult &Result) { const auto *Matched = Result.Nodes.getNodeAs("expr"); SourceLocation Loc = Matched->getMemberLoc(); if (Loc.isInvalid()) - Loc = Matched->getBeginLoc(); - diag(Loc, "do not access members of unions; use (boost::)
[clang-tools-extra] [clang-tidy] Fix for cppcoreguidelines-pro-type-union-access if memLoc is invalid (PR #104540)
@@ -116,6 +116,10 @@ Changes in existing checks ` check to remove `->`, when redundant `get()` is removed. +- Fixed :doc:`cppcoreguidelines-pro-type-union-access + ` check to + report location even when member location is not valid. ksromanov wrote: Thanks! Articles will always be a problem for me. :-( https://github.com/llvm/llvm-project/pull/104540 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][run-clang-tidy] Fix minor shutdown noise (PR #105724)
https://github.com/5chmidti approved this pull request. Because the commit with asyncio is in llvm-19, could you please add a release note for this fix? @PiotrZSL wdyt about backporting this? 19.1.0 may be too late, but for 19.2.0 then https://github.com/llvm/llvm-project/pull/105724 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][run-clang-tidy] Fix minor shutdown noise (PR #105724)
https://github.com/nicovank updated https://github.com/llvm/llvm-project/pull/105724 >From 84535cd4386a7afee32353e07c020e59420e36ef Mon Sep 17 00:00:00 2001 From: Nicolas van Kempen Date: Sat, 24 Aug 2024 12:59:13 -0400 Subject: [PATCH] [clang-tidy][run-clang-tidy] Fix minor shutdown noise On my new machine, the script outputs some shutdown noise: ``` Ctrl-C detected, goodbye. Traceback (most recent call last): File "/home/nvankempen/llvm-project/./clang-tools-extra/clang-tidy/tool/run-clang-tidy.py", line 626, in asyncio.run(main()) File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run return loop.run_until_complete(main) File "/usr/lib/python3.10/asyncio/base_events.py", line 636, in run_until_complete self.run_forever() File "/usr/lib/python3.10/asyncio/base_events.py", line 603, in run_forever self._run_once() File "/usr/lib/python3.10/asyncio/base_events.py", line 1871, in _run_once event_list = self._selector.select(timeout) File "/usr/lib/python3.10/selectors.py", line 469, in select fd_event_list = self._selector.poll(timeout, max_ev) KeyboardInterrupt ``` This fixes it. --- clang-tools-extra/clang-tidy/tool/run-clang-tidy.py | 7 +-- clang-tools-extra/docs/ReleaseNotes.rst | 3 +++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py index 48401ba5ea42a9..30d3afc0173050 100755 --- a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py +++ b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py @@ -49,7 +49,7 @@ import time import traceback from types import ModuleType -from typing import Any, Awaitable, Callable, List, Optional, Tuple, TypeVar +from typing import Any, Awaitable, Callable, List, Optional, TypeVar yaml: Optional[ModuleType] = None @@ -623,4 +623,7 @@ async def main() -> None: if __name__ == "__main__": -asyncio.run(main()) +try: +asyncio.run(main()) +except KeyboardInterrupt: +pass diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 1b025e8f90f7ba..aa69bc4ff3fd31 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -95,6 +95,9 @@ The improvements are... Improvements to clang-tidy -- +- Improved :program:`run-clang-tidy.py` script. Fixed minor shutdown noise + happening on certain platforms when interrupting the script. + New checks ^^ ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][run-clang-tidy] Fix minor shutdown noise (PR #105724)
nicovank wrote: Added release note, rebased to trigger CI again. FWIW I don't remember this happening on any of the ~3 machines I tested on previously, and it only happens on interrupt, not normal execution. If you think this should be backported, let me know if there is anything I can help with. If/when ready you can go ahead and merge this, I have no commit access. https://github.com/llvm/llvm-project/pull/105724 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Match MSVC handling of duplicate header search paths in Microsoft compatibility modes. (PR #105738)
https://github.com/tahonermann converted_to_draft https://github.com/llvm/llvm-project/pull/105738 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix a misannotation of redundant r_paren as CastRParen (PR #105921)
https://github.com/rymiel approved this pull request. https://github.com/llvm/llvm-project/pull/105921 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] [Draft] Implement P0588R1 capture rules (PR #105953)
https://github.com/LYP951018 created https://github.com/llvm/llvm-project/pull/105953 ## Code Changes: - Currently, Clang requires instantiation to determine captures of a packs (refer to 7bf8f6fa8ab123fe97ccd82d9a0ddff85505ee5f), but P0588 allows delayed instantiation of `if constexpr` statements in generic lambdas, which causes packs inside `if constexpr` to not be captured correctly. Therefore, I reverted to the previous approach of instantiating implicit captures in `TransformLambdaExpr` and handled the following two cases: ```cpp auto v = [](auto... c) { sink([&](auto ...b) { c; // case 1 sink(c...); // case 2 }...); }; ``` - P0588R1 allows us to determine the set of implicit captures when parsing the lambda expression, so there is no need to call `tryCaptureVariable(/*BuildAndDiagnose=*/true)` during template instantiation. Therefore: - The previous concept of "capture-capable" has been removed; - Redundant `tryCaptureVariable` calls in potential captures have been removed, but `tryCaptureVariable` in `MarkVarDeclODRUsed` has not been removed yet. ## Behavioral changes https://godbolt.org/z/e3Wb6hPja - When there are nested generic lambdas, and whether a variable inside the lambda is odr-used depends on the outer generic lambda (removing the impact of capture-capable): ```cpp const int x = 10; auto L = [=](auto a) { return [=](auto b) { DEFINE_SELECTOR(a); F_CALL(x, a); return 0; }; }; auto L0 = L('c'); static_assert(sizeof(L0) == sizeof(int)); auto L1 = L(1); static_assert(sizeof(L1) == sizeof(int)); // sizeof(L1) is 1 before, now it is 4. ``` - P0588R1 allows us to capture variables referenced inside `typeid`: ```cpp auto ltid = [=]{ typeid(x); }; static_assert(sizeof(ltid) == sizeof(int)); // sizeof(ltid) is 1 before, now it is 4. ``` ## Remaining issues - Is a separate ABI flag needed? - How to determine if the current variable is within a `typeid` expression in `DoMarkVarDeclReferenced`? I would appreciate any insights or suggestions on this. Thank you in advance for your help! partially fixes #61426 >From 952273b27d2204f266b7f5e42cf1bebc755b1d06 Mon Sep 17 00:00:00 2001 From: letrec Date: Sun, 25 Aug 2024 01:28:42 +0800 Subject: [PATCH 1/2] initial draft --- clang/include/clang/Sema/Sema.h | 22 ++ clang/include/clang/Sema/SemaLambda.h | 11 - clang/lib/Sema/SemaExpr.cpp | 11 +- clang/lib/Sema/SemaExprCXX.cpp| 79 --- clang/lib/Sema/SemaLambda.cpp | 209 +- clang/lib/Sema/SemaTemplateVariadic.cpp | 166 +- clang/lib/Sema/TreeTransform.h| 83 +-- .../cxx1y-generic-lambdas-capturing.cpp | 26 +++ .../test/SemaTemplate/lambda-capture-pack.cpp | 13 ++ 9 files changed, 351 insertions(+), 269 deletions(-) diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 1f7e555d1b8717..77f2f7e41d182a 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -14111,6 +14111,28 @@ class Sema final : public SemaBase { static void collectUnexpandedParameterPacks( Expr *E, SmallVectorImpl &Unexpanded); + static void collectUnexpandedParameterPacksFromLambdaBody( + Stmt *Body, SmallVectorImpl &Unexpanded); + + static bool containsUnexpandedParameterPacksInLambdaBody(Stmt *Body); + + /// Collect decls expanded inside the lambda body. + /// e.g. + /// + /// \code + /// auto v = [](auto... c) { + ///sink([&](auto ...b) { + /// c; // expanded outside the lambda body + /// sink(c...); // expanded inside the lambda body + ///}...); + /// }(400, 50, 6); + /// \endcode + /// + /// \param Body The lambda body + /// + static void collectExpandedParameterPacksFromLambdaBody( + Stmt *Body, SmallVectorImpl &Expanded); + /// Invoked when parsing a template argument followed by an /// ellipsis, which creates a pack expansion. /// diff --git a/clang/include/clang/Sema/SemaLambda.h b/clang/include/clang/Sema/SemaLambda.h index 3c9d22df70c0df..6ee53959551a1e 100644 --- a/clang/include/clang/Sema/SemaLambda.h +++ b/clang/include/clang/Sema/SemaLambda.h @@ -24,17 +24,6 @@ class FunctionScopeInfo; } class Sema; -/// Examines the FunctionScopeInfo stack to determine the nearest -/// enclosing lambda (to the current lambda) that is 'capture-capable' for -/// the variable referenced in the current lambda (i.e. \p VarToCapture). -/// If successful, returns the index into Sema's FunctionScopeInfo stack -/// of the capture-capable lambda's LambdaScopeInfo. -/// See Implementation for more detailed comments. - -std::optional getStackIndexOfNearestEnclosingCaptureCapableLambda( -ArrayRef FunctionScopes, -ValueDecl *VarToCapture, Sema &S); - } // clang #endif diff --g
[clang] [Clang] [Draft] Implement P0588R1 capture rules (PR #105953)
https://github.com/LYP951018 edited https://github.com/llvm/llvm-project/pull/105953 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] [Draft] Implement P0588R1 capture rules (PR #105953)
https://github.com/LYP951018 edited https://github.com/llvm/llvm-project/pull/105953 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] [Draft] Implement P0588R1 capture rules (PR #105953)
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 08acc3f73b64bed578d18812a04015cb537c9c82 afdff4e15c518984206da5b7cdbe9b14bb1b3bea --extensions cpp,h -- clang/include/clang/Sema/Sema.h clang/include/clang/Sema/SemaLambda.h clang/lib/Sema/SemaExpr.cpp clang/lib/Sema/SemaExprCXX.cpp clang/lib/Sema/SemaLambda.cpp clang/lib/Sema/SemaTemplateVariadic.cpp clang/lib/Sema/TreeTransform.h clang/test/SemaCXX/cxx1y-generic-lambdas-capturing.cpp clang/test/SemaTemplate/lambda-capture-pack.cpp `` View the diff from clang-format here. ``diff diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 77f2f7e41d..3176f1c9c4 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -14118,7 +14118,7 @@ public: /// Collect decls expanded inside the lambda body. /// e.g. - /// + /// /// \code /// auto v = [](auto... c) { ///sink([&](auto ...b) { diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index e99422e654..8bdc621ed7 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -19631,14 +19631,15 @@ static void DoMarkVarDeclReferenced( case OdrUseContext::Dependent: // If this is a dependent context, we don't need to mark variables as // odr-used, but we may still need to track them for lambda capture. -// +// // If an expression potentially references a local entity within a // declarative region in which it is odr-usable, and the expression would be // potentially evaluated if the effect of any enclosing typeid expressions // ([expr.typeid]) were ignored, the entity is said to be implicitly // captured by each intervening lambda-expression with an associated // capture-default that does not explicitly capture it. -// TODO: How to determine if the current variable is within a typeid expression? +// TODO: How to determine if the current variable is within a typeid +// expression? DoMarkPotentialCapture(SemaRef, Loc, Var, E); break; diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index fd1b6d9f2d..caea1fc5b3 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -8663,7 +8663,6 @@ static void CheckIfAnyEnclosingLambdasMustCaptureAnyPotentialCaptures( if (!UnderlyingVar) return; - // If the variable is clearly identified as non-odr-used and the full // expression is not instantiation dependent, only then do we not // need to check enclosing lambda's for speculative captures. @@ -8695,30 +8694,29 @@ static void CheckIfAnyEnclosingLambdasMustCaptureAnyPotentialCaptures( } } - - const bool IsVarNeverAConstantExpression = - VariableCanNeverBeAConstantExpression(UnderlyingVar, S.Context); - if (!IsFullExprInstantiationDependent || IsVarNeverAConstantExpression) { -// This full expression is not instantiation dependent or the variable -// can not be used in a constant expression - which means -// this variable must be odr-used here, so diagnose a -// capture violation early, if the variable is un-captureable. -// This is purely for diagnosing errors early. Otherwise, this -// error would get diagnosed when the lambda becomes capture ready. -QualType CaptureType, DeclRefType; -SourceLocation ExprLoc = VarExpr->getExprLoc(); -if (S.tryCaptureVariable(Var, ExprLoc, S.TryCapture_Implicit, - /*EllipsisLoc*/ SourceLocation(), - /*BuildAndDiagnose*/ false, CaptureType, - DeclRefType, nullptr)) { - // We will never be able to capture this variable, and we need - // to be able to in any and all instantiations, so diagnose it. - S.tryCaptureVariable(Var, ExprLoc, S.TryCapture_Implicit, +const bool IsVarNeverAConstantExpression = +VariableCanNeverBeAConstantExpression(UnderlyingVar, S.Context); +if (!IsFullExprInstantiationDependent || IsVarNeverAConstantExpression) { + // This full expression is not instantiation dependent or the variable + // can not be used in a constant expression - which means + // this variable must be odr-used here, so diagnose a + // capture violation early, if the variable is un-captureable. + // This is purely for diagnosing errors early. Otherwise, this + // error would get diagnosed when the lambda becomes capture ready. + QualType CaptureType, DeclRefType; + SourceLocation ExprLoc = VarExpr->getExprLoc(); + if (S.tryCaptureVariable(Var, ExprLoc, S.TryCapture_Implicit, /*EllipsisLoc*/ SourceLocation(), -
[clang] [clang-format] Fix a misannotation of less/greater as angle brackets (PR #105941)
https://github.com/rymiel approved this pull request. https://github.com/llvm/llvm-project/pull/105941 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 43b8885 - [clang-cl] [AST] Reapply #102848 Fix placeholder return type name mangling for MSVC 1920+ / VS2019+ (#104722)
Author: Max Winkler Date: 2024-08-24T12:25:46-07:00 New Revision: 43b88851cefe68645aa59b1fccc8390a8a31f469 URL: https://github.com/llvm/llvm-project/commit/43b88851cefe68645aa59b1fccc8390a8a31f469 DIFF: https://github.com/llvm/llvm-project/commit/43b88851cefe68645aa59b1fccc8390a8a31f469.diff LOG: [clang-cl] [AST] Reapply #102848 Fix placeholder return type name mangling for MSVC 1920+ / VS2019+ (#104722) Reapply https://github.com/llvm/llvm-project/pull/102848. The description in this PR will detail the changes from the reverted original PR above. For `auto&&` return types that can partake in reference collapsing we weren't properly handling that mangling that can arise. When collapsing occurs an inner reference is created with the collapsed reference type. If we return `int&` from such a function then an inner reference of `int&` is created within the `auto&&` return type. `getPointeeType` on a reference type goes through all inner references before returning the pointee type which ends up being a builtin type, `int`, which is unexpected. We can use `getPointeeTypeAsWritten` to get the `AutoType` as expected however for the instantiated template declaration reference collapsing already occurred on the return type. This means `auto&&` is turned into `auto&` in our example above. We end up mangling an lvalue reference type. This is unintended as MSVC mangles on the declaration of the return type, `auto&&` in this case, which is treated as an rvalue reference. ``` template auto&& AutoReferenceCollapseT(int& x) { return static_cast(x); } void test() { int x = 1; auto&& rref = AutoReferenceCollapseT(x); // "??$AutoReferenceCollapseT@X@@YA$$QEA_PAEAH@Z" // Mangled as an rvalue reference to auto } ``` If we are mangling a template with a placeholder return type we want to get the first template declaration and use its return type to do the mangling of any instantiations. This fixes the bug reported in the original PR that caused the revert with libcxx `std::variant`. I also tested locally with libcxx and the following test code which fails in the original PR but now works in this PR. ``` #include void test() { std::variant v{ 1 }; int& r = std::get<0>(v); (void)r; } ``` Added: clang/test/CodeGenCXX/mangle-ms-auto-return.cpp Modified: clang/docs/ReleaseNotes.rst clang/lib/AST/MicrosoftMangle.cpp clang/test/CodeGenCXX/mangle-ms-auto-templates-memptrs.cpp clang/test/CodeGenCXX/mangle-ms-auto-templates-nullptr.cpp clang/test/CodeGenCXX/mangle-ms-auto-templates.cpp Removed: diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 0ced2f779f7058..6e1db41a55cbe0 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -77,6 +77,8 @@ C++ Specific Potentially Breaking Changes ABI Changes in This Version --- +- Fixed Microsoft name mangling of placeholder, auto and decltype(auto), return types for MSVC 1920+. This change resolves incompatibilities with code compiled by MSVC 1920+ but will introduce incompatibilities with code compiled by earlier versions of Clang unless such code is built with the compiler option -fms-compatibility-version=19.14 to imitate the MSVC 1914 mangling behavior. + AST Dumping Potentially Breaking Changes diff --git a/clang/lib/AST/MicrosoftMangle.cpp b/clang/lib/AST/MicrosoftMangle.cpp index ed8d1cf1b98dd8..b539681984ef7c 100644 --- a/clang/lib/AST/MicrosoftMangle.cpp +++ b/clang/lib/AST/MicrosoftMangle.cpp @@ -408,6 +408,8 @@ class MicrosoftCXXNameMangler { void mangleSourceName(StringRef Name); void mangleNestedName(GlobalDecl GD); + void mangleAutoReturnType(QualType T, QualifierMangleMode QMM); + private: bool isStructorDecl(const NamedDecl *ND) const { return ND == Structor || getStructor(ND) == Structor; @@ -477,6 +479,11 @@ class MicrosoftCXXNameMangler { SourceRange Range); void mangleObjCKindOfType(const ObjCObjectType *T, Qualifiers Quals, SourceRange Range); + + void mangleAutoReturnType(const MemberPointerType *T, Qualifiers Quals); + void mangleAutoReturnType(const PointerType *T, Qualifiers Quals); + void mangleAutoReturnType(const LValueReferenceType *T, Qualifiers Quals); + void mangleAutoReturnType(const RValueReferenceType *T, Qualifiers Quals); }; } @@ -2494,6 +2501,57 @@ void MicrosoftCXXNameMangler::mangleAddressSpaceType(QualType T, mangleArtificialTagType(TagTypeKind::Struct, ASMangling, {"__clang"}); } +void MicrosoftCXXNameMangler::mangleAutoReturnType(QualType T, + QualifierMangleMode QMM) { + assert(getASTContext().getLangOpts().isCompatibleWithMSVC( + LangOptions::MSVC2019) && + "Cannot mangle MSVC 2017 auto return types!"); + + if
[clang] [clang-cl] [AST] Reapply #102848 Fix placeholder return type name mangling for MSVC 1920+ / VS2019+ (PR #104722)
https://github.com/MaxEW707 closed https://github.com/llvm/llvm-project/pull/104722 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] check deduction consistency when partial ordering function templates (PR #100692)
https://github.com/mizvekov updated https://github.com/llvm/llvm-project/pull/100692 >From f8fd471a954f5e304f3118df3236cf7ff4ef1020 Mon Sep 17 00:00:00 2001 From: Matheus Izvekov Date: Wed, 24 Jul 2024 03:59:41 -0300 Subject: [PATCH] [clang] check deduction consistency when partial ordering function templates This makes partial ordering of function templates consistent with other entities. Fixes #18291 --- clang/docs/ReleaseNotes.rst | 2 + clang/include/clang/Sema/Sema.h | 7 +- clang/lib/AST/ExprConstant.cpp| 1 - clang/lib/Sema/SemaTemplateDeduction.cpp | 827 -- clang/lib/Sema/SemaTemplateInstantiate.cpp| 29 +- .../test/CodeCompletion/variadic-template.cpp | 2 +- clang/test/Index/complete-call.cpp| 5 +- clang/test/SemaCXX/cxx2b-deducing-this.cpp| 43 + clang/test/SemaTemplate/GH18291.cpp | 32 + clang/test/SemaTemplate/cwg2398.cpp | 14 + clang/test/SemaTemplate/temp_arg_nontype.cpp | 14 +- clang/test/SemaTemplate/temp_arg_type.cpp | 7 +- .../Templight/templight-empty-entries-fix.cpp | 92 +- 13 files changed, 761 insertions(+), 314 deletions(-) create mode 100644 clang/test/SemaTemplate/GH18291.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 249249971dec7c..5f9c3e1969640d 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -276,6 +276,8 @@ Bug Fixes to C++ Support - Clang now properly handles the order of attributes in `extern` blocks. (#GH101990). - Fixed an assertion failure by preventing null explicit object arguments from being deduced. (#GH102025). - Correctly check constraints of explicit instantiations of member functions. (#GH46029) +- When performing partial ordering of function templates, clang now checks that + the deduction was consistent. Fixes (#GH18291). Bug Fixes to AST Handling ^ diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 299a916b9abf8d..b2bfd0e035e95f 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -13273,6 +13273,10 @@ class Sema final : public SemaBase { /// \param AllowDeducedTST Whether a DeducedTemplateSpecializationType is /// acceptable as the top level type of the result. /// + /// \param IsIncompleteSubstitution If provided, the pointee will be set + /// whenever substitution would perform a replacement with a null or + /// non-existent template argument. + /// /// \returns If the instantiation succeeds, the instantiated /// type. Otherwise, produces diagnostics and returns a NULL type. TypeSourceInfo *SubstType(TypeSourceInfo *T, @@ -13282,7 +13286,8 @@ class Sema final : public SemaBase { QualType SubstType(QualType T, const MultiLevelTemplateArgumentList &TemplateArgs, - SourceLocation Loc, DeclarationName Entity); + SourceLocation Loc, DeclarationName Entity, + bool *IsIncompleteSubstitution = nullptr); TypeSourceInfo *SubstType(TypeLoc TL, const MultiLevelTemplateArgumentList &TemplateArgs, diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 5540f58b526705..91c1883e7ab24e 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -5399,7 +5399,6 @@ static EvalStmtResult EvaluateStmt(StmtResult &Result, EvalInfo &Info, const Expr *RetExpr = cast(S)->getRetValue(); FullExpressionRAII Scope(Info); if (RetExpr && RetExpr->isValueDependent()) { - EvaluateDependentExpr(RetExpr, Info); // We know we returned, but we don't know what the value is. return ESR_Failed; } diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp index 35bc8cd713f06c..8ddc7a4df62444 100644 --- a/clang/lib/Sema/SemaTemplateDeduction.cpp +++ b/clang/lib/Sema/SemaTemplateDeduction.cpp @@ -138,7 +138,7 @@ static TemplateDeductionResult DeduceTemplateArgumentsByTypeMatch( Sema &S, TemplateParameterList *TemplateParams, QualType Param, QualType Arg, TemplateDeductionInfo &Info, SmallVectorImpl &Deduced, unsigned TDF, -bool PartialOrdering = false, bool DeducedFromArrayBound = false); +bool PartialOrdering, bool DeducedFromArrayBound, bool *HasDeducedAnyParam); enum class PackFold { ParameterToArgument, ArgumentToParameter }; static TemplateDeductionResult @@ -147,8 +147,8 @@ DeduceTemplateArguments(Sema &S, TemplateParameterList *TemplateParams, ArrayRef As, TemplateDeductionInfo &Info, SmallVectorImpl &Deduced, -bool NumberOfArgumentsMustMatch, -PackFold PackFold = PackFold::ParameterToArgument); +bool NumberOfArgumentsMustMatch, PackFold Pack
[clang] [clang] check deduction consistency when partial ordering function templates (PR #100692)
@@ -5554,38 +5869,50 @@ FunctionTemplateDecl *Sema::getMoreSpecializedTemplate( // "that is a member function with no expicit object argument". // Otherwise the ordering rules for methods with expicit objet arguments // against anything else make no sense. -ShouldConvert1 = Method1 && !Method1->isExplicitObjectMemberFunction(); -ShouldConvert2 = Method2 && !Method2->isExplicitObjectMemberFunction(); -if (ShouldConvert1) { - bool IsRValRef2 = - ShouldConvert2 - ? Method2->getRefQualifier() == RQ_RValue - : Proto2->param_type_begin()[0]->isRValueReferenceType(); - // Compare 'this' from Method1 against first parameter from Method2. - Obj1Ty = GetImplicitObjectParameterType(this->Context, Method1, RawObj1Ty, - IsRValRef2); - Args1.push_back(Obj1Ty); -} -if (ShouldConvert2) { - bool IsRValRef1 = - ShouldConvert1 - ? Method1->getRefQualifier() == RQ_RValue - : Proto1->param_type_begin()[0]->isRValueReferenceType(); - // Compare 'this' from Method2 against first parameter from Method1. - Obj2Ty = GetImplicitObjectParameterType(this->Context, Method2, RawObj2Ty, - IsRValRef1); - Args2.push_back(Obj2Ty); -} + +bool NonStaticMethod1 = Method1 && !Method1->isStatic(), + NonStaticMethod2 = Method2 && !Method2->isStatic(); + +auto Params1Begin = Proto1->param_type_begin(), + Params2Begin = Proto2->param_type_begin(); + size_t NumComparedArguments = NumCallArguments1; -// Either added an argument above or the prototype includes an explicit -// object argument we need to count -if (Method1) - ++NumComparedArguments; -Args1.insert(Args1.end(), Proto1->param_type_begin(), - Proto1->param_type_end()); -Args2.insert(Args2.end(), Proto2->param_type_begin(), - Proto2->param_type_end()); +if ((NonStaticMethod1 && NonStaticMethod2) || FD1->isOverloadedOperator()) { + ShouldConvert1 = + NonStaticMethod1 && !Method1->hasCXXExplicitFunctionObjectParameter(); + ShouldConvert2 = + NonStaticMethod2 && !Method2->hasCXXExplicitFunctionObjectParameter(); + NumComparedArguments += 1; + + if (ShouldConvert1) { +bool IsRValRef2 = +ShouldConvert2 +? Method2->getRefQualifier() == RQ_RValue +: Proto2->param_type_begin()[0]->isRValueReferenceType(); +// Compare 'this' from Method1 against first parameter from Method2. +Obj1Ty = GetImplicitObjectParameterType(this->Context, Method1, +RawObj1Ty, IsRValRef2); +Args1.push_back(Obj1Ty); + } + if (ShouldConvert2) { +bool IsRValRef1 = +ShouldConvert1 +? Method1->getRefQualifier() == RQ_RValue +: Proto1->param_type_begin()[0]->isRValueReferenceType(); +// Compare 'this' from Method2 against first parameter from Method1. +Obj2Ty = GetImplicitObjectParameterType(this->Context, Method2, +RawObj2Ty, IsRValRef1); +Args2.push_back(Obj2Ty); + } +} else { + if (NonStaticMethod1 && Method1->hasCXXExplicitFunctionObjectParameter()) +Params1Begin += 1; + if (NonStaticMethod2 && Method2->hasCXXExplicitFunctionObjectParameter()) +Params2Begin += 1; +} +Args1.insert(Args1.end(), Params1Begin, Proto1->param_type_end()); +Args2.insert(Args2.end(), Params2Begin, Proto2->param_type_end()); mizvekov wrote: `SemaCXX/cxx2b-deducing-this.cpp` was missing test cases for static call and subscript operators. Added and fixed, as they are special cases that behave like regular methods. https://github.com/llvm/llvm-project/pull/100692 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 6bc225e - [clang-format] Fix a misannotation of redundant r_paren as CastRParen (#105921)
Author: Owen Pan Date: 2024-08-24T19:12:15-07:00 New Revision: 6bc225e0630f28e83290a43c3d9b25b057fc815a URL: https://github.com/llvm/llvm-project/commit/6bc225e0630f28e83290a43c3d9b25b057fc815a DIFF: https://github.com/llvm/llvm-project/commit/6bc225e0630f28e83290a43c3d9b25b057fc815a.diff LOG: [clang-format] Fix a misannotation of redundant r_paren as CastRParen (#105921) Fixes #105880. Added: Modified: clang/lib/Format/TokenAnnotator.cpp clang/unittests/Format/TokenAnnotatorTest.cpp Removed: diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index f8bf8d9570d9a8..7c35171ab35232 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -2875,6 +2875,8 @@ class AnnotatingParser { // Search for unexpected tokens. for (auto *Prev = BeforeRParen; Prev != LParen; Prev = Prev->Previous) { if (Prev->is(tok::r_paren)) { +if (Prev->is(TT_CastRParen)) + return false; Prev = Prev->MatchingParen; if (!Prev) return false; diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index 99798de43e70ff..834430fa931129 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -747,6 +747,12 @@ TEST_F(TokenAnnotatorTest, UnderstandsCasts) { EXPECT_TOKEN(Tokens[9], tok::r_paren, TT_CastRParen); EXPECT_TOKEN(Tokens[10], tok::amp, TT_UnaryOperator); + Tokens = annotate("int result = ((int)a) - b;"); + ASSERT_EQ(Tokens.size(), 13u) << Tokens; + EXPECT_TOKEN(Tokens[6], tok::r_paren, TT_CastRParen); + EXPECT_TOKEN(Tokens[8], tok::r_paren, TT_Unknown); + EXPECT_TOKEN(Tokens[9], tok::minus, TT_BinaryOperator); + auto Style = getLLVMStyle(); Style.TypeNames.push_back("Foo"); Tokens = annotate("#define FOO(bar) foo((Foo)&bar)", Style); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix a misannotation of redundant r_paren as CastRParen (PR #105921)
https://github.com/owenca closed https://github.com/llvm/llvm-project/pull/105921 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix a misannotation of redundant r_paren as CastRParen (PR #105921)
owenca wrote: /cherry-pick 6bc225e0630f28e83290a43c3d9b25b057fc815a https://github.com/llvm/llvm-project/pull/105921 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix a misannotation of redundant r_paren as CastRParen (PR #105921)
llvmbot wrote: /pull-request llvm/llvm-project#105967 https://github.com/llvm/llvm-project/pull/105921 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Concepts] Fix the constraint equivalence checking involving parameter packs (PR #102131)
https://github.com/zyn0217 updated https://github.com/llvm/llvm-project/pull/102131 >From aa99ac433c9d383bfca732c19e5082a555f64c2d Mon Sep 17 00:00:00 2001 From: Younan Zhang Date: Tue, 6 Aug 2024 20:08:43 +0800 Subject: [PATCH 1/2] [Clang][Concepts] Fix the constraint equivalence checking for TemplateTypeParmTypes --- clang/lib/Sema/SemaConcept.cpp| 11 +++-- .../SemaTemplate/concepts-out-of-line-def.cpp | 23 +++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp index d4c9d044985e34..14a67f35a8f9f8 100644 --- a/clang/lib/Sema/SemaConcept.cpp +++ b/clang/lib/Sema/SemaConcept.cpp @@ -972,8 +972,15 @@ static const Expr *SubstituteConstraintExpressionWithoutSatisfaction( // equivalence. LocalInstantiationScope ScopeForParameters(S); if (auto *FD = DeclInfo.getDecl()->getAsFunction()) -for (auto *PVD : FD->parameters()) - ScopeForParameters.InstantiatedLocal(PVD, PVD); +for (auto *PVD : FD->parameters()) { + if (!PVD->isParameterPack()) { +ScopeForParameters.InstantiatedLocal(PVD, PVD); +continue; + } + // Parameter packs should expand to a size-of-1 argument. + ScopeForParameters.MakeInstantiatedLocalArgPack(PVD); + ScopeForParameters.InstantiatedLocalPackArg(PVD, PVD); +} std::optional ThisScope; diff --git a/clang/test/SemaTemplate/concepts-out-of-line-def.cpp b/clang/test/SemaTemplate/concepts-out-of-line-def.cpp index 0142efcdc3ee86..333187b0d74ad6 100644 --- a/clang/test/SemaTemplate/concepts-out-of-line-def.cpp +++ b/clang/test/SemaTemplate/concepts-out-of-line-def.cpp @@ -599,3 +599,26 @@ template unsigned long DerivedCollection::index() {} } // namespace GH72557 + +namespace GH101735 { + +template +concept True = true; + +template +class A { + template + void method(Ts&... ts) +requires requires (T t) { + { t.method(static_cast(ts)...) } -> True; +}; +}; + +template +template +void A::method(Ts&... ts) + requires requires (T t) { +{ t.method(static_cast(ts)...) } -> True; + } {} + +} >From 339ab57452ff2998f9b1d13a33d2ef1620a2a67c Mon Sep 17 00:00:00 2001 From: Younan Zhang Date: Sun, 25 Aug 2024 10:32:30 +0800 Subject: [PATCH 2/2] Clarify the reason & add a FIXME --- clang/lib/Sema/SemaConcept.cpp | 17 - 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp index 14a67f35a8f9f8..b83e0f094579d2 100644 --- a/clang/lib/Sema/SemaConcept.cpp +++ b/clang/lib/Sema/SemaConcept.cpp @@ -977,7 +977,22 @@ static const Expr *SubstituteConstraintExpressionWithoutSatisfaction( ScopeForParameters.InstantiatedLocal(PVD, PVD); continue; } - // Parameter packs should expand to a size-of-1 argument. + // This is hacky: we're mapping the parameter pack to a size-of-1 argument + // to avoid building SubstTemplateTypeParmPackTypes for + // PackExpansionTypes. The SubstTemplateTypeParmPackType node would + // otherwise reference the AssociatedDecl of the template arguments, which + // is, in this case, the template declaration. + // + // However, as we're also calculating the redeclarations of the template, + // the canonical declarations thereof are actually themselves at the + // moment. So if we didn't expand these packs, we would end up with an + // incorrect profile difference because we will be profiling the + // canonical types! + // + // FIXME: Improve the "no-transform" machinery in FindInstantiatedDecl so + // that we can eliminate the Scope in the cases where the declarations are + // not necessarily instantiated. It would also benefit the noexcept + // specifier comparison. ScopeForParameters.MakeInstantiatedLocalArgPack(PVD); ScopeForParameters.InstantiatedLocalPackArg(PVD, PVD); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix a misannotation of redundant r_paren as CastRParen (PR #105921)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `sanitizer-x86_64-linux` running on `sanitizer-buildbot2` while building `clang` at step 2 "annotate". Full details are available at: https://lab.llvm.org/buildbot/#/builders/66/builds/3083 Here is the relevant piece of the build log for the reference: ``` Step 2 (annotate) failure: 'python ../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py' (failure) ... llvm-lit: /home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60: warning: Path reported by clang does not exist: "/home/b/sanitizer-x86_64-linux/build/compiler_rt_build/lib/x86_64-unknown-linux-gnu". This path was found by running ['/home/b/sanitizer-x86_64-linux/build/build_default/bin/clang', '--target=x86_64-unknown-linux-gnu', '-m64', '-nobuiltininc', '-I/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/include', '-idirafter', '/home/b/sanitizer-x86_64-linux/build/build_default/lib/clang/20/include', '-resource-dir=/home/b/sanitizer-x86_64-linux/build/compiler_rt_build', '-Wl,-rpath,/home/b/sanitizer-x86_64-linux/build/compiler_rt_build/lib/linux', '-print-runtime-dir']. llvm-lit: /home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60: warning: Path reported by clang does not exist: "/home/b/sanitizer-x86_64-linux/build/compiler_rt_build/lib/x86_64-unknown-linux-gnu". This path was found by running ['/home/b/sanitizer-x86_64-linux/build/build_default/bin/clang', '--target=x86_64-unknown-linux-gnu', '-m64', '-nobuiltininc', '-I/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/include', '-idirafter', '/home/b/sanitizer-x86_64-linux/build/build_default/lib/clang/20/include', '-resource-dir=/home/b/sanitizer-x86_64-linux/build/compiler_rt_build', '-Wl,-rpath,/home/b/sanitizer-x86_64-linux/build/compiler_rt_build/lib/linux', '-print-runtime-dir']. llvm-lit: /home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60: warning: Path reported by clang does not exist: "/home/b/sanitizer-x86_64-linux/build/compiler_rt_build/lib/x86_64-unknown-linux-gnu". This path was found by running ['/home/b/sanitizer-x86_64-linux/build/build_default/bin/clang', '--target=x86_64-unknown-linux-gnu', '-Wthread-safety', '-Wthread-safety-reference', '-Wthread-safety-beta', '-nobuiltininc', '-I/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/include', '-idirafter', '/home/b/sanitizer-x86_64-linux/build/build_default/lib/clang/20/include', '-resource-dir=/home/b/sanitizer-x86_64-linux/build/compiler_rt_build', '-Wl,-rpath,/home/b/sanitizer-x86_64-linux/build/compiler_rt_build/lib/linux', '-print-runtime-dir']. llvm-lit: /home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60: warning: Path reported by clang does not exist: "/home/b/sanitizer-x86_64-linux/build/compiler_rt_build/lib/x86_64-unknown-linux-gnu". This path was found by running ['/home/b/sanitizer-x86_64-linux/build/build_default/bin/clang', '--target=x86_64-unknown-linux-gnu', '-m64', '-nobuiltininc', '-I/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/include', '-idirafter', '/home/b/sanitizer-x86_64-linux/build/build_default/lib/clang/20/include', '-resource-dir=/home/b/sanitizer-x86_64-linux/build/compiler_rt_build', '-Wl,-rpath,/home/b/sanitizer-x86_64-linux/build/compiler_rt_build/lib/linux', '-print-runtime-dir']. llvm-lit: /home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60: warning: Path reported by clang does not exist: "/home/b/sanitizer-x86_64-linux/build/compiler_rt_build/lib/x86_64-unknown-linux-gnu". This path was found by running ['/home/b/sanitizer-x86_64-linux/build/build_default/bin/clang', '--target=x86_64-unknown-linux-gnu', '-m64', '-nobuiltininc', '-I/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/include', '-idirafter', '/home/b/sanitizer-x86_64-linux/build/build_default/lib/clang/20/include', '-resource-dir=/home/b/sanitizer-x86_64-linux/build/compiler_rt_build', '-Wl,-rpath,/home/b/sanitizer-x86_64-linux/build/compiler_rt_build/lib/linux', '-print-runtime-dir']. llvm-lit: /home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60: warning: Path reported by clang does not exist: "/home/b/sanitizer-x86_64-linux/build/compiler_rt_build/lib/x86_64-unknown-linux-gnu". This path was found by running ['/home/b/sanitizer-x86_64-linux/build/build_default/bin/clang', '--target=x86_64-unknown-linux-gnu', '-m64', '-nobuiltininc', '-I/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/include', '-idirafter', '/home/b/sanitizer-x86_64-linux/build/build_default/lib/clang/20/include', '-resource-dir=/home/b/sanitizer-x86_64-linux/build/compiler_rt_build', '-Wl,-rpath,/home/b/sanitizer-x86_64-linux/build/compiler_rt_build/lib/linux', '-print-runtime-dir']. llvm-lit: /
[libclc] [libclc] use default paths with find_program when possible (PR #105969)
https://github.com/RossComputerGuy created https://github.com/llvm/llvm-project/pull/105969 Patch pulled from https://github.com/NixOS/nixpkgs/pull/336465 This PR removes `NO_DEFAULT_PATH` where possible, the flag prevents Nix from building libclc correctly. >From e8b910246d0c7c3d9fff994f71c6f8a48ec09a50 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Sat, 24 Aug 2024 19:56:24 -0700 Subject: [PATCH] [libclc] use default paths with find_program when possible --- libclc/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt index 02bb859ae8590b..6bcd8ae52a5794 100644 --- a/libclc/CMakeLists.txt +++ b/libclc/CMakeLists.txt @@ -55,7 +55,7 @@ if( LIBCLC_STANDALONE_BUILD OR CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DI # Import required tools if( NOT EXISTS ${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR} ) foreach( tool IN ITEMS clang llvm-as llvm-link opt ) - find_program( LLVM_TOOL_${tool} ${tool} PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH ) + find_program( LLVM_TOOL_${tool} ${tool} PATHS ${LLVM_TOOLS_BINARY_DIR} ) set( ${tool}_exe ${LLVM_TOOL_${tool}} ) set( ${tool}_target ) endforeach() @@ -104,7 +104,7 @@ foreach( tool IN ITEMS clang opt llvm-as llvm-link ) endforeach() # llvm-spirv is an optional dependency, used to build spirv-* targets. -find_program( LLVM_SPIRV llvm-spirv PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH ) +find_program( LLVM_SPIRV llvm-spirv PATHS ${LLVM_TOOLS_BINARY_DIR} ) if( LLVM_SPIRV ) add_executable( libclc::llvm-spirv IMPORTED GLOBAL ) ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 0916ae4 - [clang-format] Fix a misannotation of less/greater as angle brackets (#105941)
Author: Owen Pan Date: 2024-08-24T20:10:03-07:00 New Revision: 0916ae49b89db6eb9eee9f6fee4f1a65fd9cdb74 URL: https://github.com/llvm/llvm-project/commit/0916ae49b89db6eb9eee9f6fee4f1a65fd9cdb74 DIFF: https://github.com/llvm/llvm-project/commit/0916ae49b89db6eb9eee9f6fee4f1a65fd9cdb74.diff LOG: [clang-format] Fix a misannotation of less/greater as angle brackets (#105941) Fixes #105877. Added: Modified: clang/lib/Format/TokenAnnotator.cpp clang/unittests/Format/TokenAnnotatorTest.cpp Removed: diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 7c35171ab35232..f15330098a2395 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -250,7 +250,7 @@ class AnnotatingParser { if (Precedence > prec::Conditional && Precedence < prec::Relational) return false; } - if (Prev.is(TT_ConditionalExpr)) + if (Prev.isOneOf(tok::question, tok::colon) && !Style.isProto()) SeenTernaryOperator = true; updateParameterCount(Left, CurrentToken); if (Style.Language == FormatStyle::LK_Proto) { diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index 834430fa931129..db44d418a84484 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -620,6 +620,11 @@ TEST_F(TokenAnnotatorTest, UnderstandsNonTemplateAngleBrackets) { EXPECT_TOKEN(Tokens[2], tok::less, TT_BinaryOperator); EXPECT_TOKEN(Tokens[8], tok::greater, TT_BinaryOperator); + Tokens = annotate("return checklower ? a < b : a > b;"); + ASSERT_EQ(Tokens.size(), 12u) << Tokens; + EXPECT_TOKEN(Tokens[4], tok::less, TT_BinaryOperator); + EXPECT_TOKEN(Tokens[8], tok::greater, TT_BinaryOperator); + Tokens = annotate("return A < B ^ A > B;"); ASSERT_EQ(Tokens.size(), 10u) << Tokens; EXPECT_TOKEN(Tokens[2], tok::less, TT_BinaryOperator); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix a misannotation of less/greater as angle brackets (PR #105941)
https://github.com/owenca closed https://github.com/llvm/llvm-project/pull/105941 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix a misannotation of less/greater as angle brackets (PR #105941)
owenca wrote: /cherry-pick 0916ae49b89db6eb9eee9f6fee4f1a65fd9cdb74 https://github.com/llvm/llvm-project/pull/105941 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix a misannotation of less/greater as angle brackets (PR #105941)
llvmbot wrote: /pull-request llvm/llvm-project#105971 https://github.com/llvm/llvm-project/pull/105941 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix a misannotation of redundant r_paren as CastRParen (PR #105921)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `clang-aarch64-sve-vla-2stage` running on `linaro-g3-04` while building `clang` at step 11 "build stage 2". Full details are available at: https://lab.llvm.org/buildbot/#/builders/41/builds/1495 Here is the relevant piece of the build log for the reference: ``` Step 11 (build stage 2) failure: 'ninja' (failure) ... [7830/8656] Building CXX object tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/check-call.cpp.o [7831/8656] Building CXX object tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/compute-offsets.cpp.o [7832/8656] Building CXX object tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/check-return.cpp.o [7833/8656] Building CXX object tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/Coarray.cpp.o [7834/8656] Building CXX object tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/check-stop.cpp.o [7835/8656] Building CXX object tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/check-select-rank.cpp.o [7836/8656] Building CXX object tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/check-cuda.cpp.o [7837/8656] Building CXX object tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/Runtime.cpp.o [7838/8656] Building CXX object tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/check-do-forall.cpp.o [7839/8656] Building CXX object tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/OpenMP/Clauses.cpp.o FAILED: tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/OpenMP/Clauses.cpp.o /home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/stage1.install/bin/clang++ -DFLANG_INCLUDE_TESTS=1 -DFLANG_LITTLE_ENDIAN=1 -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/stage2/tools/flang/lib/Lower -I/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/llvm/flang/lib/Lower -I/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/llvm/flang/include -I/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/stage2/tools/flang/include -I/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/stage2/include -I/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/llvm/llvm/include -isystem /home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/llvm/llvm/../mlir/include -isystem /home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/stage2/tools/mlir/include -isystem /home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/stage2/tools/clang/include -isystem /home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/llvm/llvm/../clang/include -mcpu=neoverse-512tvb -mllvm -scalable-vectorization=preferred -mllvm -treat-scalable-fixed-error-as-warning=false -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -Wno-deprecated-copy -Wno-string-conversion -Wno-ctad-maybe-unsupported -Wno-unused-command-line-argument -Wstring-conversion -Wcovered-switch-default -Wno-nested-anon-types -O3 -DNDEBUG -std=c++17 -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -MD -MT tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/OpenMP/Clauses.cpp.o -MF tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/OpenMP/Clauses.cpp.o.d -o tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/OpenMP/Clauses.cpp.o -c /home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/llvm/flang/lib/Lower/OpenMP/Clauses.cpp Killed [7840/8656] Building CXX object tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/CustomIntrinsicCall.cpp.o [7841/8656] Building CXX object tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/ConvertCall.cpp.o [7842/8656] Building CXX object tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/Mangler.cpp.o [7843/8656] Building CXX object tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/ConvertExprToHLFIR.cpp.o [7844/8656] Building CXX object tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/IO.cpp.o [7845/8656] Building CXX object tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/HostAssociations.cpp.o [7846/8656] Building CXX object tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/OpenACC.cpp.o [7847/8656] Building CXX object tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/OpenMP/Decomposer.cpp.o [7848/8656] Building CXX object tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/Allocatable.cpp.o [7849/8656] Building CXX object tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/DumpEvaluateExpr.cpp.o [7850/8656] Building CXX object tools/flang/lib/
[clang] [Clang] [Draft] Implement P0588R1 capture rules (PR #105953)
https://github.com/LYP951018 edited https://github.com/llvm/llvm-project/pull/105953 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Sema] Fix particular operator overload crash (PR #105976)
https://github.com/nicovank created https://github.com/llvm/llvm-project/pull/105976 Fix #104883. Fix #104800. Thanks @Endilll for the reduced reproducer. Bisection points to 0cb7e7ca0c864e052bf49978f3bcd667c9e16930 as the faulty commit, but nothing there seems to indicate what the problem is. After some print debugging, `Decl` on [this line](https://github.com/llvm/llvm-project/blob/f22b1da8791edd557ce34c87190e329df2e1c892/clang/lib/Sema/SemaOverload.cpp#L7429) is a `UsingDecl`, not a `CXXMethodDecl`, and the cast fails. Add a conditional case for `UsingDecl`. I am not familiar with Clang/Sema so please make sure this fix makes sense. >From c4d185916fcf12f7f5584e7556829a8f9cbf4eb3 Mon Sep 17 00:00:00 2001 From: Nicolas van Kempen Date: Sun, 25 Aug 2024 02:52:06 -0400 Subject: [PATCH] [clang][Sema] Fix particular operator overload crash Fix #104883. Fix #104800. --- clang/lib/Sema/SemaOverload.cpp | 7 +++ 1 file changed, 7 insertions(+) diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index 1ce0fa091938d7..a2cf334bd176fe 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -7425,6 +7425,13 @@ void Sema::AddMethodCandidate(DeclAccessPair FoundDecl, QualType ObjectType, /*ExplicitArgs*/ nullptr, ObjectType, ObjectClassification, Args, CandidateSet, SuppressUserConversions, false, PO); + } else if (UsingDecl *UD = dyn_cast(Decl)) { +for (auto *Shadow : UD->shadows()) { + AddMethodCandidate(cast(Shadow->getTargetDecl()), + FoundDecl, ActingContext, ObjectType, + ObjectClassification, Args, CandidateSet, + SuppressUserConversions, false, std::nullopt, PO); +} } else { AddMethodCandidate(cast(Decl), FoundDecl, ActingContext, ObjectType, ObjectClassification, Args, CandidateSet, ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Sema] Fix particular operator overload crash (PR #105976)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Nicolas van Kempen (nicovank) Changes Fix #104883. Fix #104800. Thanks @Endilll for the reduced reproducer. Bisection points to 0cb7e7ca0c864e052bf49978f3bcd667c9e16930 as the faulty commit, but nothing there seems to indicate what the problem is. After some print debugging, `Decl` on [this line](https://github.com/llvm/llvm-project/blob/f22b1da8791edd557ce34c87190e329df2e1c892/clang/lib/Sema/SemaOverload.cpp#L7429) is a `UsingDecl`, not a `CXXMethodDecl`, and the cast fails. Add a conditional case for `UsingDecl`. I am not familiar with Clang/Sema so please make sure this fix makes sense. --- Full diff: https://github.com/llvm/llvm-project/pull/105976.diff 1 Files Affected: - (modified) clang/lib/Sema/SemaOverload.cpp (+7) ``diff diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index 1ce0fa091938d7..a2cf334bd176fe 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -7425,6 +7425,13 @@ void Sema::AddMethodCandidate(DeclAccessPair FoundDecl, QualType ObjectType, /*ExplicitArgs*/ nullptr, ObjectType, ObjectClassification, Args, CandidateSet, SuppressUserConversions, false, PO); + } else if (UsingDecl *UD = dyn_cast(Decl)) { +for (auto *Shadow : UD->shadows()) { + AddMethodCandidate(cast(Shadow->getTargetDecl()), + FoundDecl, ActingContext, ObjectType, + ObjectClassification, Args, CandidateSet, + SuppressUserConversions, false, std::nullopt, PO); +} } else { AddMethodCandidate(cast(Decl), FoundDecl, ActingContext, ObjectType, ObjectClassification, Args, CandidateSet, `` https://github.com/llvm/llvm-project/pull/105976 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Sema] Fix particular operator overload crash (PR #105976)
https://github.com/nicovank updated https://github.com/llvm/llvm-project/pull/105976 >From 033d4003154440fb00c62c0e85fe3dac4af10d22 Mon Sep 17 00:00:00 2001 From: Nicolas van Kempen Date: Sun, 25 Aug 2024 02:57:55 -0400 Subject: [PATCH] [clang][Sema] Fix particular operator overload crash Fix #104883. Fix #104800. --- clang/lib/Sema/SemaOverload.cpp | 7 +++ clang/test/SemaCXX/PR105976.cpp | 26 ++ 2 files changed, 33 insertions(+) create mode 100644 clang/test/SemaCXX/PR105976.cpp diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index 1ce0fa091938d7..a2cf334bd176fe 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -7425,6 +7425,13 @@ void Sema::AddMethodCandidate(DeclAccessPair FoundDecl, QualType ObjectType, /*ExplicitArgs*/ nullptr, ObjectType, ObjectClassification, Args, CandidateSet, SuppressUserConversions, false, PO); + } else if (UsingDecl *UD = dyn_cast(Decl)) { +for (auto *Shadow : UD->shadows()) { + AddMethodCandidate(cast(Shadow->getTargetDecl()), + FoundDecl, ActingContext, ObjectType, + ObjectClassification, Args, CandidateSet, + SuppressUserConversions, false, std::nullopt, PO); +} } else { AddMethodCandidate(cast(Decl), FoundDecl, ActingContext, ObjectType, ObjectClassification, Args, CandidateSet, diff --git a/clang/test/SemaCXX/PR105976.cpp b/clang/test/SemaCXX/PR105976.cpp new file mode 100644 index 00..289e53058d6095 --- /dev/null +++ b/clang/test/SemaCXX/PR105976.cpp @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -verify-ignore-unexpected=note %s + +struct B { + void operator==(B); +}; + +struct C { + void operator==(C); +}; + +struct D { + void operator==(D); +}; + +struct E : C, B { + using C::operator==; + using B::operator==; +}; + +struct F : D, E {}; + +void f() { + F{} == F{}; + // expected-error@-1 {{member 'operator==' found in multiple base classes of different types}} + // expected-error@-2 {{use of overloaded operator '==' is ambiguous}} +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits