[clang] [llvm] [X86] Add Support for X86 TLSDESC Relocations (PR #83136)
https://github.com/MaskRay edited https://github.com/llvm/llvm-project/pull/83136 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [X86] Add Support for X86 TLSDESC Relocations (PR #83136)
https://github.com/MaskRay approved this pull request. https://github.com/llvm/llvm-project/pull/83136 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [X86] Add Support for X86 TLSDESC Relocations (PR #83136)
@@ -0,0 +1,247 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 4 +; RUN: llc < %s -mtriple=i686 --relocation-model=pic -enable-tlsdesc | FileCheck %s --check-prefix=X86 +; RUN: llc < %s -mtriple=x86_64-pc-linux-gnux32 --relocation-model=pic -enable-tlsdesc | FileCheck %s --check-prefix=X32 +; RUN: llc < %s -mtriple=x86_64 --relocation-model=pic -enable-tlsdesc | FileCheck %s --check-prefix=X64 + +@x = thread_local global i32 0, align 4 +@y = internal thread_local global i32 0, align 4 +@z = internal thread_local global i32 1, align 4 +@t = external hidden thread_local global i32, align 4 + +define ptr @f1() nounwind { +; X86-LABEL: f1: +; X86: # %bb.0: +; X86-NEXT:pushl %ebp +; X86-NEXT:pushl %ebx +; X86-NEXT:pushl %edi +; X86-NEXT:pushl %esi +; X86-NEXT:pushl %eax +; X86-NEXT:calll .L0$pb +; X86-NEXT: .L0$pb: +; X86-NEXT:popl %ebx +; X86-NEXT: .Ltmp0: +; X86-NEXT:addl $_GLOBAL_OFFSET_TABLE_+(.Ltmp0-.L0$pb), %ebx +; X86-NEXT:#APP +; X86-NEXT:#NO_APP +; X86-NEXT:movl %eax, (%esp) # 4-byte Spill +; X86-NEXT:leal x@tlsdesc(%ebx), %eax +; X86-NEXT:calll *x@tlscall(%eax) +; X86-NEXT:addl %gs:0, %eax +; X86-NEXT:movl (%esp), %ebx # 4-byte Reload +; X86-NEXT:#APP +; X86-NEXT:#NO_APP +; X86-NEXT:addl $4, %esp +; X86-NEXT:popl %esi +; X86-NEXT:popl %edi +; X86-NEXT:popl %ebx +; X86-NEXT:popl %ebp +; X86-NEXT:retl +; +; X32-LABEL: f1: +; X32: # %bb.0: +; X32-NEXT:pushq %rax +; X32-NEXT:#APP +; X32-NEXT:#NO_APP +; X32-NEXT:leal x@tlsdesc(%rip), %eax +; X32-NEXT:callq *x@tlscall(%eax) +; X32-NEXT:# kill: def $eax killed $eax def $rax +; X32-NEXT:addl %fs:0, %eax +; X32-NEXT:#APP +; X32-NEXT:#NO_APP +; X32-NEXT:popq %rcx +; X32-NEXT:retq +; +; X64-LABEL: f1: +; X64: # %bb.0: +; X64-NEXT:pushq %rax +; X64-NEXT:#APP +; X64-NEXT:#NO_APP +; X64-NEXT:leaq x@tlsdesc(%rip), %rax +; X64-NEXT:callq *x@tlscall(%rax) +; X64-NEXT:addq %fs:0, %rax +; X64-NEXT:#APP +; X64-NEXT:#NO_APP +; X64-NEXT:popq %rcx +; X64-NEXT:retq + %a = call { i32, i32, i32, i32, i32, i32 } asm sideeffect "", "=r,=r,=r,=r,=r,=r,~{dirflag},~{fpsr},~{flags}"() + %b = call ptr @llvm.threadlocal.address.p0(ptr @x) + %a.0 = extractvalue { i32, i32, i32, i32, i32, i32 } %a, 0 + %a.1 = extractvalue { i32, i32, i32, i32, i32, i32 } %a, 1 + %a.2 = extractvalue { i32, i32, i32, i32, i32, i32 } %a, 2 + %a.3 = extractvalue { i32, i32, i32, i32, i32, i32 } %a, 3 + %a.4 = extractvalue { i32, i32, i32, i32, i32, i32 } %a, 4 + %a.5 = extractvalue { i32, i32, i32, i32, i32, i32 } %a, 5 + call void asm sideeffect "", "r,r,r,r,r,r,~{dirflag},~{fpsr},~{flags}"(i32 %a.0, i32 %a.1, i32 %a.2, i32 %a.3, i32 %a.4, i32 %a.5) + ret ptr %b +} + +define i32 @f2() nounwind { +; X86-LABEL: f2: +; X86: # %bb.0: +; X86-NEXT:pushl %ebx +; X86-NEXT:calll .L1$pb +; X86-NEXT: .L1$pb: +; X86-NEXT:popl %ebx +; X86-NEXT: .Ltmp1: +; X86-NEXT:addl $_GLOBAL_OFFSET_TABLE_+(.Ltmp1-.L1$pb), %ebx +; X86-NEXT:movl %gs:0, %ecx +; X86-NEXT:leal x@tlsdesc(%ebx), %eax +; X86-NEXT:calll *x@tlscall(%eax) +; X86-NEXT:movl (%eax,%ecx), %eax +; X86-NEXT:popl %ebx +; X86-NEXT:retl +; +; X32-LABEL: f2: +; X32: # %bb.0: +; X32-NEXT:pushq %rax +; X32-NEXT:movl %fs:0, %ecx +; X32-NEXT:leal x@tlsdesc(%rip), %eax +; X32-NEXT:callq *x@tlscall(%eax) +; X32-NEXT:movl (%eax,%ecx), %eax +; X32-NEXT:popq %rcx +; X32-NEXT:retq +; +; X64-LABEL: f2: +; X64: # %bb.0: +; X64-NEXT:pushq %rax +; X64-NEXT:movq %fs:0, %rcx +; X64-NEXT:leaq x@tlsdesc(%rip), %rax +; X64-NEXT:callq *x@tlscall(%rax) +; X64-NEXT:movl (%rax,%rcx), %eax +; X64-NEXT:popq %rcx +; X64-NEXT:retq + %1 = tail call ptr @llvm.threadlocal.address.p0(ptr @x) + %2 = load i32, ptr %1 + ret i32 %2 +} + +define ptr @f3() nounwind { +; X86-LABEL: f3: +; X86: # %bb.0: +; X86-NEXT:pushl %ebx +; X86-NEXT:calll .L2$pb +; X86-NEXT: .L2$pb: +; X86-NEXT:popl %ebx +; X86-NEXT: .Ltmp2: +; X86-NEXT:addl $_GLOBAL_OFFSET_TABLE_+(.Ltmp2-.L2$pb), %ebx +; X86-NEXT:leal x@tlsdesc(%ebx), %eax +; X86-NEXT:calll *x@tlscall(%eax) +; X86-NEXT:addl %gs:0, %eax +; X86-NEXT:popl %ebx +; X86-NEXT:retl +; +; X32-LABEL: f3: +; X32: # %bb.0: +; X32-NEXT:pushq %rax +; X32-NEXT:leal x@tlsdesc(%rip), %eax +; X32-NEXT:callq *x@tlscall(%eax) +; X32-NEXT:# kill: def $eax killed $eax def $rax +; X32-NEXT:addl %fs:0, %eax +; X32-NEXT:popq %rcx +; X32-NEXT:retq +; +; X64-LABEL: f3: +; X64: # %bb.0: +; X64-NEXT:pushq %rax +; X64-NEXT:leaq x@tlsdesc(%rip), %rax +; X64-NEXT:callq *x@tlscall(%rax) +; X64-NEXT:addq %fs:0, %rax +; X64-NEXT:popq %rcx +; X64-NEXT:retq + %1 = tail call ptr @llvm.threadlocal.address
[clang] [clang-tools-extra] [CLANGD] Do not crash on designator initialization of union (PR #83369)
https://github.com/HighCommander4 requested changes to this pull request. https://github.com/llvm/llvm-project/pull/83369 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [CLANGD] Do not crash on designator initialization of union (PR #83369)
@@ -72,6 +72,22 @@ TEST_F(ExtractVariableTest, Test) { )cpp"; EXPECT_UNAVAILABLE(NoCrashCasesC); + ExtraArgs = {"-xc"}; + const char *NoCrashDesignator = R"cpp( +struct A { + struct { +int x; + }; +}; +struct B { + int y; +}; +void foo(struct B *b) { + struct A a = {.[[x]]=b->y}; HighCommander4 wrote: This test case does not fail without the fix. The reason is that the selection `[[x]]` does not trigger the crash. The selection needs to be on the `[[->]]` to trigger the crash (and then, the result will be `AVAILABLE`). Otherwise looks good, thanks! https://github.com/llvm/llvm-project/pull/83369 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [CLANGD] Do not crash on designator initialization of union (PR #83369)
https://github.com/HighCommander4 edited https://github.com/llvm/llvm-project/pull/83369 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [FMV] Emit the resolver along with the default version definition. (PR #84405)
@@ -4120,6 +4127,9 @@ void CodeGenModule::emitMultiVersionFunctions() { TA->getArchitecture(), Feats); } else { const auto *TVA = CurFD->getAttr(); + if (TVA->isDefaultVersion() && + CurFD->doesThisDeclarationHaveABody()) +EmitResolver = true; llvm::SmallVector Feats; TVA->getFeatures(Feats); Options.emplace_back(cast(Func), labrinea wrote: It is initialized with `!FD->isTargetVersionMultiVersion()` so it is set to true for target clones. However I've just found a bug when we don't have a default definition but we do have a caller in the TU. In that case we should be checking `isUsed()` too. I'll fix this. https://github.com/llvm/llvm-project/pull/84405 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [FMV] Emit the resolver along with the default version definition. (PR #84405)
@@ -4347,6 +4362,19 @@ void CodeGenModule::emitCPUDispatchDefinition(GlobalDecl GD) { } } +/// Adds a declaration to the list of multi version functions if not present. +void CodeGenModule::AddDeferredMultiVersionResolverToEmit(GlobalDecl GD) { + const auto *FD = cast(GD.getDecl()); + assert(FD && "Not a FunctionDecl?"); + + if (FD->isTargetVersionMultiVersion()) { +StringRef NamePrefix = getMangledName(GD).split('.').first; labrinea wrote: Initially I was using `FD->getName()` as the key here but this wouldn't work for C++ mangled names. `getMangledName()` internally calls `getMangledNameImpl()` which returns the multi versioned name (this would be "foo.bar.baz._Mlse" in you example). The key needs to be the prefix "foo.bar.baz" so that we don't push every multi version of "foo.bar.baz" in the list `MultiVersionFuncs` to be processed by `emitMultiVersionFunctions()`. This would generate a resolver body with multiple copies of the basic blocks corresponding to each version. Hmm, I am not sure how to handle this example properly, perhaps with `rsplit()`. https://github.com/llvm/llvm-project/pull/84405 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [FMV] Emit the resolver along with the default version definition. (PR #84405)
@@ -84,9 +84,33 @@ int hoo(void) { return fp1() + fp2(); } +// This should generate one target version but no resolver. +__attribute__((target_version("default"))) int unused_with_forward_default_decl(void); +__attribute__((target_version("mops"))) int unused_with_forward_default_decl(void) { return 0; } +// This should also generate one target version but no resolver. +extern int unused_with_implicit_extern_forward_default_decl(void); +__attribute__((target_version("dotprod"))) +int unused_with_implicit_extern_forward_default_decl(void) { return 0; } +// This should also generate one target version but no resolver. +__attribute__((target_version("aes"))) int unused_with_default_decl(void) { return 0; } +__attribute__((target_version("default"))) int unused_with_default_decl(void); +// This should generate two target versions and the resolver. +__attribute__((target_version("sve"))) int unused_with_default_def(void) { return 0; } +__attribute__((target_version("default"))) int unused_with_default_def(void) { return 1; } + +// This should also generate two target versions and the resolver. +__attribute__((target_version("fp16"))) int unused_with_implicit_default_def(void) { return 0; } +int unused_with_implicit_default_def(void) { return 1; } + +// This should also generate two target versions and the resolver. +int unused_with_implicit_forward_default_def(void) { return 0; } +__attribute__((target_version("lse"))) int unused_with_implicit_forward_default_def(void) { return 1; } + +// This should generate a normal function. +__attribute__((target_version("rdm"))) int unused_without_default(void) { return 0; } labrinea wrote: I do remember this use case from another review (https://godbolt.org/z/3zaM9MzPb) so I wanted to make sure we support it, which is the case! Now if we would further like to support multi versioning in the absense of default declaration (the header not included) that's a different story. I am not opposing, but will have to check how feasible it is to implement and what do the rest of the stakeholders think about it. https://github.com/llvm/llvm-project/pull/84405 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [X86] Add Support for X86 TLSDESC Relocations (PR #83136)
@@ -0,0 +1,247 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 4 +; RUN: llc < %s -mtriple=i686 --relocation-model=pic -enable-tlsdesc | FileCheck %s --check-prefix=X86 +; RUN: llc < %s -mtriple=x86_64-pc-linux-gnux32 --relocation-model=pic -enable-tlsdesc | FileCheck %s --check-prefix=X32 +; RUN: llc < %s -mtriple=x86_64 --relocation-model=pic -enable-tlsdesc | FileCheck %s --check-prefix=X64 + +@x = thread_local global i32 0, align 4 +@y = internal thread_local global i32 0, align 4 +@z = internal thread_local global i32 1, align 4 +@t = external hidden thread_local global i32, align 4 + +define ptr @f1() nounwind { +; X86-LABEL: f1: +; X86: # %bb.0: +; X86-NEXT:pushl %ebp +; X86-NEXT:pushl %ebx +; X86-NEXT:pushl %edi +; X86-NEXT:pushl %esi +; X86-NEXT:pushl %eax +; X86-NEXT:calll .L0$pb +; X86-NEXT: .L0$pb: +; X86-NEXT:popl %ebx +; X86-NEXT: .Ltmp0: +; X86-NEXT:addl $_GLOBAL_OFFSET_TABLE_+(.Ltmp0-.L0$pb), %ebx +; X86-NEXT:#APP +; X86-NEXT:#NO_APP +; X86-NEXT:movl %eax, (%esp) # 4-byte Spill +; X86-NEXT:leal x@tlsdesc(%ebx), %eax +; X86-NEXT:calll *x@tlscall(%eax) +; X86-NEXT:addl %gs:0, %eax +; X86-NEXT:movl (%esp), %ebx # 4-byte Reload +; X86-NEXT:#APP +; X86-NEXT:#NO_APP +; X86-NEXT:addl $4, %esp +; X86-NEXT:popl %esi +; X86-NEXT:popl %edi +; X86-NEXT:popl %ebx +; X86-NEXT:popl %ebp +; X86-NEXT:retl +; +; X32-LABEL: f1: +; X32: # %bb.0: +; X32-NEXT:pushq %rax +; X32-NEXT:#APP +; X32-NEXT:#NO_APP +; X32-NEXT:leal x@tlsdesc(%rip), %eax +; X32-NEXT:callq *x@tlscall(%eax) +; X32-NEXT:# kill: def $eax killed $eax def $rax +; X32-NEXT:addl %fs:0, %eax +; X32-NEXT:#APP +; X32-NEXT:#NO_APP +; X32-NEXT:popq %rcx +; X32-NEXT:retq +; +; X64-LABEL: f1: +; X64: # %bb.0: +; X64-NEXT:pushq %rax +; X64-NEXT:#APP +; X64-NEXT:#NO_APP +; X64-NEXT:leaq x@tlsdesc(%rip), %rax +; X64-NEXT:callq *x@tlscall(%rax) +; X64-NEXT:addq %fs:0, %rax +; X64-NEXT:#APP +; X64-NEXT:#NO_APP +; X64-NEXT:popq %rcx +; X64-NEXT:retq + %a = call { i32, i32, i32, i32, i32, i32 } asm sideeffect "", "=r,=r,=r,=r,=r,=r,~{dirflag},~{fpsr},~{flags}"() + %b = call ptr @llvm.threadlocal.address.p0(ptr @x) + %a.0 = extractvalue { i32, i32, i32, i32, i32, i32 } %a, 0 + %a.1 = extractvalue { i32, i32, i32, i32, i32, i32 } %a, 1 + %a.2 = extractvalue { i32, i32, i32, i32, i32, i32 } %a, 2 + %a.3 = extractvalue { i32, i32, i32, i32, i32, i32 } %a, 3 + %a.4 = extractvalue { i32, i32, i32, i32, i32, i32 } %a, 4 + %a.5 = extractvalue { i32, i32, i32, i32, i32, i32 } %a, 5 + call void asm sideeffect "", "r,r,r,r,r,r,~{dirflag},~{fpsr},~{flags}"(i32 %a.0, i32 %a.1, i32 %a.2, i32 %a.3, i32 %a.4, i32 %a.5) + ret ptr %b +} + +define i32 @f2() nounwind { +; X86-LABEL: f2: +; X86: # %bb.0: +; X86-NEXT:pushl %ebx +; X86-NEXT:calll .L1$pb +; X86-NEXT: .L1$pb: +; X86-NEXT:popl %ebx +; X86-NEXT: .Ltmp1: +; X86-NEXT:addl $_GLOBAL_OFFSET_TABLE_+(.Ltmp1-.L1$pb), %ebx +; X86-NEXT:movl %gs:0, %ecx +; X86-NEXT:leal x@tlsdesc(%ebx), %eax +; X86-NEXT:calll *x@tlscall(%eax) +; X86-NEXT:movl (%eax,%ecx), %eax +; X86-NEXT:popl %ebx +; X86-NEXT:retl +; +; X32-LABEL: f2: +; X32: # %bb.0: +; X32-NEXT:pushq %rax +; X32-NEXT:movl %fs:0, %ecx +; X32-NEXT:leal x@tlsdesc(%rip), %eax +; X32-NEXT:callq *x@tlscall(%eax) +; X32-NEXT:movl (%eax,%ecx), %eax +; X32-NEXT:popq %rcx +; X32-NEXT:retq +; +; X64-LABEL: f2: +; X64: # %bb.0: +; X64-NEXT:pushq %rax +; X64-NEXT:movq %fs:0, %rcx +; X64-NEXT:leaq x@tlsdesc(%rip), %rax +; X64-NEXT:callq *x@tlscall(%rax) +; X64-NEXT:movl (%rax,%rcx), %eax +; X64-NEXT:popq %rcx +; X64-NEXT:retq + %1 = tail call ptr @llvm.threadlocal.address.p0(ptr @x) + %2 = load i32, ptr %1 + ret i32 %2 +} + +define ptr @f3() nounwind { +; X86-LABEL: f3: +; X86: # %bb.0: +; X86-NEXT:pushl %ebx +; X86-NEXT:calll .L2$pb +; X86-NEXT: .L2$pb: +; X86-NEXT:popl %ebx +; X86-NEXT: .Ltmp2: +; X86-NEXT:addl $_GLOBAL_OFFSET_TABLE_+(.Ltmp2-.L2$pb), %ebx +; X86-NEXT:leal x@tlsdesc(%ebx), %eax +; X86-NEXT:calll *x@tlscall(%eax) +; X86-NEXT:addl %gs:0, %eax +; X86-NEXT:popl %ebx +; X86-NEXT:retl +; +; X32-LABEL: f3: +; X32: # %bb.0: +; X32-NEXT:pushq %rax +; X32-NEXT:leal x@tlsdesc(%rip), %eax +; X32-NEXT:callq *x@tlscall(%eax) +; X32-NEXT:# kill: def $eax killed $eax def $rax +; X32-NEXT:addl %fs:0, %eax +; X32-NEXT:popq %rcx +; X32-NEXT:retq +; +; X64-LABEL: f3: +; X64: # %bb.0: +; X64-NEXT:pushq %rax +; X64-NEXT:leaq x@tlsdesc(%rip), %rax +; X64-NEXT:callq *x@tlscall(%rax) +; X64-NEXT:addq %fs:0, %rax +; X64-NEXT:popq %rcx +; X64-NEXT:retq + %1 = tail call ptr @llvm.threadlocal.address
[clang] [llvm] [X86] Add Support for X86 TLSDESC Relocations (PR #83136)
https://github.com/phoebewang updated https://github.com/llvm/llvm-project/pull/83136 >From cdc9ee6c322af0ceed162f3f714bcd0a22e020c3 Mon Sep 17 00:00:00 2001 From: Phoebe Wang Date: Tue, 27 Feb 2024 22:16:38 +0800 Subject: [PATCH 1/8] [X86] Add Support for X86 TLSDESC Relocations --- clang/lib/Driver/ToolChains/CommonArgs.cpp| 3 +- clang/test/Driver/tls-dialect.c | 2 +- .../lib/Target/X86/MCTargetDesc/X86BaseInfo.h | 14 ++ llvm/lib/Target/X86/X86AsmPrinter.cpp | 2 + llvm/lib/Target/X86/X86ISelLowering.cpp | 98 +++ llvm/lib/Target/X86/X86MCInstLower.cpp| 30 +++- llvm/test/CodeGen/X86/tls-desc.ll | 165 ++ 7 files changed, 273 insertions(+), 41 deletions(-) create mode 100644 llvm/test/CodeGen/X86/tls-desc.ll diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index faceee85a2f8dc..c66e3ee12e50c4 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -740,7 +740,8 @@ bool tools::isTLSDESCEnabled(const ToolChain &TC, SupportedArgument = V == "desc" || V == "trad"; EnableTLSDESC = V == "desc"; } else if (Triple.isX86()) { -SupportedArgument = V == "gnu"; +SupportedArgument = V == "gnu" || V == "gnu2"; +EnableTLSDESC = V == "gnu2"; } else { Unsupported = true; } diff --git a/clang/test/Driver/tls-dialect.c b/clang/test/Driver/tls-dialect.c index f73915b28ec2a3..a808dd81531ce7 100644 --- a/clang/test/Driver/tls-dialect.c +++ b/clang/test/Driver/tls-dialect.c @@ -2,6 +2,7 @@ // RUN: %clang -### --target=riscv64-linux -mtls-dialect=trad %s 2>&1 | FileCheck --check-prefix=NODESC %s // RUN: %clang -### --target=riscv64-linux %s 2>&1 | FileCheck --check-prefix=NODESC %s // RUN: %clang -### --target=x86_64-linux -mtls-dialect=gnu %s 2>&1 | FileCheck --check-prefix=NODESC %s +// RUN: %clang -### --target=x86_64-linux -mtls-dialect=gnu2 %s 2>&1 | FileCheck --check-prefix=DESC %s /// Android supports TLSDESC by default on RISC-V /// TLSDESC is not on by default in Linux, even on RISC-V, and is covered above @@ -18,7 +19,6 @@ /// Unsupported argument // RUN: not %clang -### --target=riscv64-linux -mtls-dialect=gnu2 %s 2>&1 | FileCheck --check-prefix=UNSUPPORTED-ARG %s -// RUN: not %clang -### --target=x86_64-linux -mtls-dialect=gnu2 %s 2>&1 | FileCheck --check-prefix=UNSUPPORTED-ARG %s // DESC: "-cc1" {{.*}}"-enable-tlsdesc" // NODESC-NOT: "-enable-tlsdesc" diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h b/llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h index 4442b80861b61a..1877550f8c40bb 100644 --- a/llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h +++ b/llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h @@ -431,6 +431,20 @@ enum TOF { /// See 'ELF Handling for Thread-Local Storage' for more details. ///SYMBOL_LABEL @TLSLDM MO_TLSLDM, + /// MO_TLSCALL - On a symbol operand this indicates that the immediate is + /// the index of the TLS descriptor function for the symbol. Used in both + /// the IA32 and x86-64 local dynamic TLS access model. + /// See 'RFC-TLSDESC-x86' for more details. + ///SYMBOL_LABEL @TLSCALL + MO_TLSCALL, + /// MO_TLSDESC - On a symbol operand this indicates that the immediate is + /// the index of the TLS descriptor argument for the symbol. When this + /// argument is passed to a call getting from index@TLSCALL, the function will + /// return the offset for the symbol. Used in both the IA32 and x86-64 local + /// dynamic TLS access model. + /// See 'RFC-TLSDESC-x86' for more details. + ///SYMBOL_LABEL @TLSDESC + MO_TLSDESC, /// MO_GOTTPOFF - On a symbol operand this indicates that the immediate is /// the offset of the GOT entry with the thread-pointer offset for the /// symbol. Used in the x86-64 initial exec TLS access model. diff --git a/llvm/lib/Target/X86/X86AsmPrinter.cpp b/llvm/lib/Target/X86/X86AsmPrinter.cpp index 3395a13545e454..d8e111db1cec42 100644 --- a/llvm/lib/Target/X86/X86AsmPrinter.cpp +++ b/llvm/lib/Target/X86/X86AsmPrinter.cpp @@ -271,6 +271,8 @@ void X86AsmPrinter::PrintSymbolOperand(const MachineOperand &MO, case X86II::MO_TLSGD: O << "@TLSGD"; break; case X86II::MO_TLSLD: O << "@TLSLD"; break; case X86II::MO_TLSLDM:O << "@TLSLDM";break; + case X86II::MO_TLSDESC: O << "@TLSDESC"; break; + case X86II::MO_TLSCALL: O << "@TLSCALL"; break; case X86II::MO_GOTTPOFF: O << "@GOTTPOFF"; break; case X86II::MO_INDNTPOFF: O << "@INDNTPOFF"; break; case X86II::MO_TPOFF: O << "@TPOFF"; break; diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp index a86f13135173b0..88314bcf510e9a 100644 --- a/llvm/lib/Target/X86/X86ISelLowering.cpp +++ b/llvm/lib/Target/X86/X86ISelLowering.cpp @@ -18515,17 +18515,17 @@ X86TargetLowering::LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) con
[clang] 0a739eb - [clang][Interp] Implement __builtin___{CF,NS}StringMakeConstantString
Author: Timm Bäder Date: 2024-03-15T08:46:13+01:00 New Revision: 0a739eb75fe68b1cec4e4aaad8b5395bb5da9a89 URL: https://github.com/llvm/llvm-project/commit/0a739eb75fe68b1cec4e4aaad8b5395bb5da9a89 DIFF: https://github.com/llvm/llvm-project/commit/0a739eb75fe68b1cec4e4aaad8b5395bb5da9a89.diff LOG: [clang][Interp] Implement __builtin___{CF,NS}StringMakeConstantString By doing the same thing the current interpreter does: Just passing on the first parameter. Added: Modified: clang/lib/AST/Interp/InterpBuiltin.cpp clang/test/AST/Interp/builtin-functions.cpp Removed: diff --git a/clang/lib/AST/Interp/InterpBuiltin.cpp b/clang/lib/AST/Interp/InterpBuiltin.cpp index 7e29d6183bdadd..b5bd4e99ba84b1 100644 --- a/clang/lib/AST/Interp/InterpBuiltin.cpp +++ b/clang/lib/AST/Interp/InterpBuiltin.cpp @@ -606,10 +606,9 @@ static bool interp__builtin_eh_return_data_regno(InterpState &S, CodePtr OpPC, return true; } -static bool interp__builtin_launder(InterpState &S, CodePtr OpPC, -const InterpFrame *Frame, -const Function *Func, -const CallExpr *Call) { +/// Just takes the first Argument to the call and puts it on the stack. +static bool noopPointer(InterpState &S, CodePtr OpPC, const InterpFrame *Frame, +const Function *Func, const CallExpr *Call) { const Pointer &Arg = S.Stk.peek(); S.Stk.push(Arg); return true; @@ -1144,7 +1143,9 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F, break; case Builtin::BI__builtin_launder: -if (!interp__builtin_launder(S, OpPC, Frame, F, Call)) + case Builtin::BI__builtin___CFStringMakeConstantString: + case Builtin::BI__builtin___NSStringMakeConstantString: +if (!noopPointer(S, OpPC, Frame, F, Call)) return false; break; diff --git a/clang/test/AST/Interp/builtin-functions.cpp b/clang/test/AST/Interp/builtin-functions.cpp index 08fca8428cf5e8..6c8df99a159730 100644 --- a/clang/test/AST/Interp/builtin-functions.cpp +++ b/clang/test/AST/Interp/builtin-functions.cpp @@ -510,3 +510,12 @@ namespace bswap { int h4 = __builtin_bswap32(0x1234) == 0x3412 ? 1 : f(); int h5 = __builtin_bswap64(0x1234) == 0x3412 ? 1 : f(); } + +#define CFSTR __builtin___CFStringMakeConstantString +void test7(void) { + const void *X; + X = CFSTR("\242"); // both-warning {{input conversion stopped}} + X = CFSTR("\0"); // no-warning + X = CFSTR(242); // both-error {{cannot initialize a parameter of type 'const char *' with an rvalue of type 'int'}} + X = CFSTR("foo", "bar"); // both-error {{too many arguments to function call}} +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [X86] Add Support for X86 TLSDESC Relocations (PR #83136)
https://github.com/phoebewang updated https://github.com/llvm/llvm-project/pull/83136 >From cdc9ee6c322af0ceed162f3f714bcd0a22e020c3 Mon Sep 17 00:00:00 2001 From: Phoebe Wang Date: Tue, 27 Feb 2024 22:16:38 +0800 Subject: [PATCH 1/8] [X86] Add Support for X86 TLSDESC Relocations --- clang/lib/Driver/ToolChains/CommonArgs.cpp| 3 +- clang/test/Driver/tls-dialect.c | 2 +- .../lib/Target/X86/MCTargetDesc/X86BaseInfo.h | 14 ++ llvm/lib/Target/X86/X86AsmPrinter.cpp | 2 + llvm/lib/Target/X86/X86ISelLowering.cpp | 98 +++ llvm/lib/Target/X86/X86MCInstLower.cpp| 30 +++- llvm/test/CodeGen/X86/tls-desc.ll | 165 ++ 7 files changed, 273 insertions(+), 41 deletions(-) create mode 100644 llvm/test/CodeGen/X86/tls-desc.ll diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index faceee85a2f8dc..c66e3ee12e50c4 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -740,7 +740,8 @@ bool tools::isTLSDESCEnabled(const ToolChain &TC, SupportedArgument = V == "desc" || V == "trad"; EnableTLSDESC = V == "desc"; } else if (Triple.isX86()) { -SupportedArgument = V == "gnu"; +SupportedArgument = V == "gnu" || V == "gnu2"; +EnableTLSDESC = V == "gnu2"; } else { Unsupported = true; } diff --git a/clang/test/Driver/tls-dialect.c b/clang/test/Driver/tls-dialect.c index f73915b28ec2a3..a808dd81531ce7 100644 --- a/clang/test/Driver/tls-dialect.c +++ b/clang/test/Driver/tls-dialect.c @@ -2,6 +2,7 @@ // RUN: %clang -### --target=riscv64-linux -mtls-dialect=trad %s 2>&1 | FileCheck --check-prefix=NODESC %s // RUN: %clang -### --target=riscv64-linux %s 2>&1 | FileCheck --check-prefix=NODESC %s // RUN: %clang -### --target=x86_64-linux -mtls-dialect=gnu %s 2>&1 | FileCheck --check-prefix=NODESC %s +// RUN: %clang -### --target=x86_64-linux -mtls-dialect=gnu2 %s 2>&1 | FileCheck --check-prefix=DESC %s /// Android supports TLSDESC by default on RISC-V /// TLSDESC is not on by default in Linux, even on RISC-V, and is covered above @@ -18,7 +19,6 @@ /// Unsupported argument // RUN: not %clang -### --target=riscv64-linux -mtls-dialect=gnu2 %s 2>&1 | FileCheck --check-prefix=UNSUPPORTED-ARG %s -// RUN: not %clang -### --target=x86_64-linux -mtls-dialect=gnu2 %s 2>&1 | FileCheck --check-prefix=UNSUPPORTED-ARG %s // DESC: "-cc1" {{.*}}"-enable-tlsdesc" // NODESC-NOT: "-enable-tlsdesc" diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h b/llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h index 4442b80861b61a..1877550f8c40bb 100644 --- a/llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h +++ b/llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h @@ -431,6 +431,20 @@ enum TOF { /// See 'ELF Handling for Thread-Local Storage' for more details. ///SYMBOL_LABEL @TLSLDM MO_TLSLDM, + /// MO_TLSCALL - On a symbol operand this indicates that the immediate is + /// the index of the TLS descriptor function for the symbol. Used in both + /// the IA32 and x86-64 local dynamic TLS access model. + /// See 'RFC-TLSDESC-x86' for more details. + ///SYMBOL_LABEL @TLSCALL + MO_TLSCALL, + /// MO_TLSDESC - On a symbol operand this indicates that the immediate is + /// the index of the TLS descriptor argument for the symbol. When this + /// argument is passed to a call getting from index@TLSCALL, the function will + /// return the offset for the symbol. Used in both the IA32 and x86-64 local + /// dynamic TLS access model. + /// See 'RFC-TLSDESC-x86' for more details. + ///SYMBOL_LABEL @TLSDESC + MO_TLSDESC, /// MO_GOTTPOFF - On a symbol operand this indicates that the immediate is /// the offset of the GOT entry with the thread-pointer offset for the /// symbol. Used in the x86-64 initial exec TLS access model. diff --git a/llvm/lib/Target/X86/X86AsmPrinter.cpp b/llvm/lib/Target/X86/X86AsmPrinter.cpp index 3395a13545e454..d8e111db1cec42 100644 --- a/llvm/lib/Target/X86/X86AsmPrinter.cpp +++ b/llvm/lib/Target/X86/X86AsmPrinter.cpp @@ -271,6 +271,8 @@ void X86AsmPrinter::PrintSymbolOperand(const MachineOperand &MO, case X86II::MO_TLSGD: O << "@TLSGD"; break; case X86II::MO_TLSLD: O << "@TLSLD"; break; case X86II::MO_TLSLDM:O << "@TLSLDM";break; + case X86II::MO_TLSDESC: O << "@TLSDESC"; break; + case X86II::MO_TLSCALL: O << "@TLSCALL"; break; case X86II::MO_GOTTPOFF: O << "@GOTTPOFF"; break; case X86II::MO_INDNTPOFF: O << "@INDNTPOFF"; break; case X86II::MO_TPOFF: O << "@TPOFF"; break; diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp index a86f13135173b0..88314bcf510e9a 100644 --- a/llvm/lib/Target/X86/X86ISelLowering.cpp +++ b/llvm/lib/Target/X86/X86ISelLowering.cpp @@ -18515,17 +18515,17 @@ X86TargetLowering::LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) con
[clang] [llvm] Adapted MemRegion::getDescriptiveName to handle ElementRegions (PR #85104)
https://github.com/T-Gruber updated https://github.com/llvm/llvm-project/pull/85104 >From 0f964127ed91e23f8e969e08ce680535cfeb8906 Mon Sep 17 00:00:00 2001 From: Andreas Steinhausen Date: Wed, 13 Mar 2024 17:07:53 +0100 Subject: [PATCH 01/10] Adapted MemRegion::getDescriptiveName to handle ElementRegions --- clang/lib/StaticAnalyzer/Core/MemRegion.cpp | 244 -- clang/unittests/StaticAnalyzer/CMakeLists.txt | 1 + .../StaticAnalyzer/MemRegionTest.cpp | 56 3 files changed, 167 insertions(+), 134 deletions(-) create mode 100644 clang/unittests/StaticAnalyzer/MemRegionTest.cpp diff --git a/clang/lib/StaticAnalyzer/Core/MemRegion.cpp b/clang/lib/StaticAnalyzer/Core/MemRegion.cpp index 16db6b249dc92b..89791bd88001e3 100644 --- a/clang/lib/StaticAnalyzer/Core/MemRegion.cpp +++ b/clang/lib/StaticAnalyzer/Core/MemRegion.cpp @@ -66,7 +66,7 @@ using namespace ento; //===--===// template -RegionTy* MemRegionManager::getSubRegion(const Arg1Ty arg1, +RegionTy *MemRegionManager::getSubRegion(const Arg1Ty arg1, const SuperTy *superRegion) { llvm::FoldingSetNodeID ID; RegionTy::ProfileRegion(ID, arg1, superRegion); @@ -82,7 +82,7 @@ RegionTy* MemRegionManager::getSubRegion(const Arg1Ty arg1, } template -RegionTy* MemRegionManager::getSubRegion(const Arg1Ty arg1, const Arg2Ty arg2, +RegionTy *MemRegionManager::getSubRegion(const Arg1Ty arg1, const Arg2Ty arg2, const SuperTy *superRegion) { llvm::FoldingSetNodeID ID; RegionTy::ProfileRegion(ID, arg1, arg2, superRegion); @@ -97,9 +97,9 @@ RegionTy* MemRegionManager::getSubRegion(const Arg1Ty arg1, const Arg2Ty arg2, return R; } -template -RegionTy* MemRegionManager::getSubRegion(const Arg1Ty arg1, const Arg2Ty arg2, +template +RegionTy *MemRegionManager::getSubRegion(const Arg1Ty arg1, const Arg2Ty arg2, const Arg3Ty arg3, const SuperTy *superRegion) { llvm::FoldingSetNodeID ID; @@ -129,8 +129,8 @@ MemRegionManager::~MemRegionManager() = default; // Basic methods. //===--===// -bool SubRegion::isSubRegionOf(const MemRegion* R) const { - const MemRegion* r = this; +bool SubRegion::isSubRegionOf(const MemRegion *R) const { + const MemRegion *r = this; do { if (r == R) return true; @@ -143,7 +143,7 @@ bool SubRegion::isSubRegionOf(const MemRegion* R) const { } MemRegionManager &SubRegion::getMemRegionManager() const { - const SubRegion* r = this; + const SubRegion *r = this; do { const MemRegion *superRegion = r->getSuperRegion(); if (const auto *sr = dyn_cast(superRegion)) { @@ -178,9 +178,7 @@ ObjCIvarRegion::ObjCIvarRegion(const ObjCIvarDecl *ivd, const SubRegion *sReg) const ObjCIvarDecl *ObjCIvarRegion::getDecl() const { return IVD; } -QualType ObjCIvarRegion::getValueType() const { - return getDecl()->getType(); -} +QualType ObjCIvarRegion::getValueType() const { return getDecl()->getType(); } QualType CXXBaseObjectRegion::getValueType() const { return QualType(getDecl()->getTypeForDecl(), 0); @@ -251,26 +249,25 @@ void ObjCStringRegion::ProfileRegion(llvm::FoldingSetNodeID &ID, ID.AddPointer(superRegion); } -void AllocaRegion::ProfileRegion(llvm::FoldingSetNodeID& ID, - const Expr *Ex, unsigned cnt, - const MemRegion *superRegion) { +void AllocaRegion::ProfileRegion(llvm::FoldingSetNodeID &ID, const Expr *Ex, + unsigned cnt, const MemRegion *superRegion) { ID.AddInteger(static_cast(AllocaRegionKind)); ID.AddPointer(Ex); ID.AddInteger(cnt); ID.AddPointer(superRegion); } -void AllocaRegion::Profile(llvm::FoldingSetNodeID& ID) const { +void AllocaRegion::Profile(llvm::FoldingSetNodeID &ID) const { ProfileRegion(ID, Ex, Cnt, superRegion); } -void CompoundLiteralRegion::Profile(llvm::FoldingSetNodeID& ID) const { +void CompoundLiteralRegion::Profile(llvm::FoldingSetNodeID &ID) const { CompoundLiteralRegion::ProfileRegion(ID, CL, superRegion); } -void CompoundLiteralRegion::ProfileRegion(llvm::FoldingSetNodeID& ID, +void CompoundLiteralRegion::ProfileRegion(llvm::FoldingSetNodeID &ID, const CompoundLiteralExpr *CL, - const MemRegion* superRegion) { + const MemRegion *superRegion) { ID.AddInteger(static_cast(CompoundLiteralRegionKind)); ID.AddPointer(CL); ID.AddPointer(superRegion); @@ -292,9 +289,9 @@ void FieldRegion::Profile(llvm::FoldingSetNodeID &ID) const { ProfileRegion(ID, getDecl(), superRegion); } -void ObjCIvarRegion::ProfileRegion(llvm::FoldingSetNodeID& ID, +void ObjCIv
[clang] [llvm] Adapted MemRegion::getDescriptiveName to handle ElementRegions (PR #85104)
@@ -720,14 +720,20 @@ std::string MemRegion::getDescriptiveName(bool UseQuotes) const { CI->getValue().toString(Idx); ArrayIndices = (llvm::Twine("[") + Idx.str() + "]" + ArrayIndices).str(); } -// If not a ConcreteInt, try to obtain the variable -// name by calling 'getDescriptiveName' recursively. -else { - std::string Idx = ER->getDescriptiveName(false); - if (!Idx.empty()) { -ArrayIndices = (llvm::Twine("[") + Idx + "]" + ArrayIndices).str(); +// Index is a SymbolVal. +else if (auto SI = ER->getIndex().getAs()) { + if (SymbolRef SR = SI->getAsSymbol()) { +if (const MemRegion *OR = SR->getOriginRegion()) { + std::string Idx = OR->getDescriptiveName(false); + ArrayIndices = (llvm::Twine("[") + Idx + "]" + ArrayIndices).str(); +} } } +// Index is neither a ConcreteInt nor SymbolVal, give up and return. +else { + assert(false && "we should have a descriptive name"); + return ""; +} T-Gruber wrote: Hi @NagyDonat, thank you for the hint. I improved the implementation based on your suggestion and also added 3 more test cases to the unittest. https://github.com/llvm/llvm-project/pull/85104 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] Adapted MemRegion::getDescriptiveName to handle ElementRegions (PR #85104)
T-Gruber wrote: > In addition to the above-mentioned issues there is also a conceptual problem > with using `getOriginRegion()` to describe a symbol: it names the region > where the symbol _originated_ (if it originated as the unknown initial value > of a symbol), which is not necessarily the region where the symbol is stored > _now_. > > For example consider the (somewhat contrived) code > > ``` > int matrix[10][10]; > int func(int x, int y) { > int tmp = x; > x = y; > y = tmp; > return matrix[x][-999]; > } > ``` > > Here the checker alpha.security.ArrayBoundV2 (which uses > `getDescriptiveName`) would report that > > ``` > Access of 'matrix[y]' at negative byte offset > ``` > > because the symbolic value of the index _originated from_ the parameter `y` > (i.e. the symbol is identified as "this is the initial value of `y`). Yes, thats right. But the previous implementation ended up in an endless recursion if the index is not of type ConcreteInt. Therefore, the proposed version is a significant improvement (at least for my use cases). https://github.com/llvm/llvm-project/pull/85104 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [PowerPC] Tune AIX shared library TLS model at function level by heuristic (PR #84132)
https://github.com/orcguru edited https://github.com/llvm/llvm-project/pull/84132 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [PowerPC] Tune AIX shared library TLS model at function level by heuristic (PR #84132)
https://github.com/orcguru edited https://github.com/llvm/llvm-project/pull/84132 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AMDGPU] Extend __builtin_amdgcn_sched_group_barrier to support rules. (PR #85304)
llvmbot wrote: @llvm/pr-subscribers-backend-amdgpu Author: Jeffrey Byrnes (jrbyrnes) Changes I am still working with the user to define the actual rules, so it is still a WIP. However, this current version contains the main machinery of the feature. This helps bridge the gap between sched_group_barrier and iglp_opt, enabling users (with compiler support) more ability to create the pipelines they want. In particular, this is aimed at helping control scheduling in blocks with loop-carried dependencies. Since this is a global scheduling problem, there is no straightforward way to tune the scheduler against these blocks. --- Full diff: https://github.com/llvm/llvm-project/pull/85304.diff 9 Files Affected: - (modified) clang/include/clang/Basic/BuiltinsAMDGPU.def (+1-1) - (modified) clang/lib/CodeGen/CGBuiltin.cpp (+17) - (modified) clang/test/CodeGenOpenCL/builtins-amdgcn.cl (+14) - (modified) llvm/include/llvm/IR/IntrinsicsAMDGPU.td (+11-4) - (modified) llvm/lib/Target/AMDGPU/AMDGPUIGroupLP.cpp (+102-10) - (modified) llvm/lib/Target/AMDGPU/AMDGPUMCInstLower.cpp (+14) - (modified) llvm/lib/Target/AMDGPU/SIInstructions.td (+16) - (modified) llvm/lib/Target/AMDGPU/SIPostRABundler.cpp (+2-1) - (modified) llvm/test/CodeGen/AMDGPU/llvm.amdgcn.sched.group.barrier.ll (+25) ``diff diff --git a/clang/include/clang/Basic/BuiltinsAMDGPU.def b/clang/include/clang/Basic/BuiltinsAMDGPU.def index 61ec8b79bf054d..f7b6a4610bd80a 100644 --- a/clang/include/clang/Basic/BuiltinsAMDGPU.def +++ b/clang/include/clang/Basic/BuiltinsAMDGPU.def @@ -63,7 +63,7 @@ BUILTIN(__builtin_amdgcn_s_sendmsghalt, "vIiUi", "n") BUILTIN(__builtin_amdgcn_s_barrier, "v", "n") BUILTIN(__builtin_amdgcn_wave_barrier, "v", "n") BUILTIN(__builtin_amdgcn_sched_barrier, "vIi", "n") -BUILTIN(__builtin_amdgcn_sched_group_barrier, "vIiIiIi", "n") +BUILTIN(__builtin_amdgcn_sched_group_barrier, "vIiIiIi.", "n") BUILTIN(__builtin_amdgcn_iglp_opt, "vIi", "n") BUILTIN(__builtin_amdgcn_s_dcache_inv, "v", "n") BUILTIN(__builtin_amdgcn_buffer_wbinvl1, "v", "n") diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 528a13fb275124..4bf71c7535db63 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -18761,6 +18761,23 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned BuiltinID, case AMDGPU::BI__builtin_amdgcn_grid_size_z: return EmitAMDGPUGridSize(*this, 2); + // scheduling builtins + case AMDGPU::BI__builtin_amdgcn_sched_group_barrier: { +return E->getNumArgs() == 3 + ? Builder.CreateCall( + CGM.getIntrinsic(Intrinsic::amdgcn_sched_group_barrier), + {EmitScalarExpr(E->getArg(0)), + EmitScalarExpr(E->getArg(1)), + EmitScalarExpr(E->getArg(2))}) + : Builder.CreateCall( + CGM.getIntrinsic( + Intrinsic::amdgcn_sched_group_barrier_rule), + {EmitScalarExpr(E->getArg(0)), + EmitScalarExpr(E->getArg(1)), + EmitScalarExpr(E->getArg(2)), + EmitScalarExpr(E->getArg(3))}); + } + // r600 intrinsics case AMDGPU::BI__builtin_r600_recipsqrt_ieee: case AMDGPU::BI__builtin_r600_recipsqrt_ieeef: diff --git a/clang/test/CodeGenOpenCL/builtins-amdgcn.cl b/clang/test/CodeGenOpenCL/builtins-amdgcn.cl index 8a4533633706b2..e28e0a6987484b 100644 --- a/clang/test/CodeGenOpenCL/builtins-amdgcn.cl +++ b/clang/test/CodeGenOpenCL/builtins-amdgcn.cl @@ -436,6 +436,20 @@ void test_sched_group_barrier() __builtin_amdgcn_sched_group_barrier(15, 1, -1); } +// CHECK-LABEL: @test_sched_group_barrier_rule +// CHECK: call void @llvm.amdgcn.sched.group.barrier.rule(i32 0, i32 1, i32 2, i32 0) +// CHECK: call void @llvm.amdgcn.sched.group.barrier.rule(i32 1, i32 2, i32 4, i32 0) +// CHECK: call void @llvm.amdgcn.sched.group.barrier.rule(i32 4, i32 8, i32 16, i32 100) +// CHECK: call void @llvm.amdgcn.sched.group.barrier.rule(i32 15, i32 1, i32 -1, i32 -100) +void test_sched_group_barrier_rule() +{ + __builtin_amdgcn_sched_group_barrier(0, 1, 2, 0); + __builtin_amdgcn_sched_group_barrier(1, 2, 4, 0); + __builtin_amdgcn_sched_group_barrier(4, 8, 16, 100); + __builtin_amdgcn_sched_group_barrier(15, 1, -1, -100); +} + + // CHECK-LABEL: @test_iglp_opt // CHECK: call void @llvm.amdgcn.iglp.opt(i32 0) // CHECK: call void @llvm.amdgcn.iglp.opt(i32 1) diff --git a/llvm/include/llvm/IR/IntrinsicsAMDGPU.td b/llvm/include/llvm/IR/IntrinsicsAMDGPU.td index 051e603c0819d2..68fe42a8f04d21 100644 --- a/llvm/include/llvm/IR/IntrinsicsAMDGPU.td +++ b/llvm/include/llvm/IR/IntrinsicsAMDGPU.td @@ -297,10 +297,17 @@ def int_amdgcn_sched_barrier : ClangBuiltin<"__builtin_amdgcn_sched_barrier">, // matching instructions that will be associated with this sched_group_barrier. // The third parameter is an identifier which is used
[clang] c42bc2e - [clang][NFC] Make some local pointers const
Author: Timm Bäder Date: 2024-03-15T09:57:27+01:00 New Revision: c42bc2ea8f66def31ca9a381e995ec61e9fa9b05 URL: https://github.com/llvm/llvm-project/commit/c42bc2ea8f66def31ca9a381e995ec61e9fa9b05 DIFF: https://github.com/llvm/llvm-project/commit/c42bc2ea8f66def31ca9a381e995ec61e9fa9b05.diff LOG: [clang][NFC] Make some local pointers const The function returns a const Expr* anyway. Added: Modified: clang/lib/AST/ExprConstant.cpp Removed: diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index b154a196e11c7d..7137efb7876de2 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -11858,8 +11858,8 @@ static QualType getObjectType(APValue::LValueBase B) { static const Expr *ignorePointerCastsAndParens(const Expr *E) { assert(E->isPRValue() && E->getType()->hasPointerRepresentation()); - auto *NoParens = E->IgnoreParens(); - auto *Cast = dyn_cast(NoParens); + const Expr *NoParens = E->IgnoreParens(); + const auto *Cast = dyn_cast(NoParens); if (Cast == nullptr) return NoParens; @@ -11870,7 +11870,7 @@ static const Expr *ignorePointerCastsAndParens(const Expr *E) { CastKind != CK_AddressSpaceConversion) return NoParens; - auto *SubExpr = Cast->getSubExpr(); + const auto *SubExpr = Cast->getSubExpr(); if (!SubExpr->getType()->hasPointerRepresentation() || !SubExpr->isPRValue()) return NoParens; return ignorePointerCastsAndParens(SubExpr); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 8ab0632 - [clang][Interp] Handle goto and label statements
Author: Timm Bäder Date: 2024-03-15T09:57:28+01:00 New Revision: 8ab0632735f87961d27094a1076a41264e2fd3ed URL: https://github.com/llvm/llvm-project/commit/8ab0632735f87961d27094a1076a41264e2fd3ed DIFF: https://github.com/llvm/llvm-project/commit/8ab0632735f87961d27094a1076a41264e2fd3ed.diff LOG: [clang][Interp] Handle goto and label statements Added: Modified: clang/lib/AST/Interp/ByteCodeStmtGen.cpp clang/lib/AST/Interp/ByteCodeStmtGen.h clang/test/AST/Interp/cxx23.cpp Removed: diff --git a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp index 6da3860f98d8c0..b9e8e6a77a7205 100644 --- a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp @@ -273,15 +273,18 @@ bool ByteCodeStmtGen::visitStmt(const Stmt *S) { return visitCaseStmt(cast(S)); case Stmt::DefaultStmtClass: return visitDefaultStmt(cast(S)); - case Stmt::GCCAsmStmtClass: - case Stmt::MSAsmStmtClass: -return visitAsmStmt(cast(S)); case Stmt::AttributedStmtClass: return visitAttributedStmt(cast(S)); case Stmt::CXXTryStmtClass: return visitCXXTryStmt(cast(S)); case Stmt::NullStmtClass: return true; + // Always invalid statements. + case Stmt::GCCAsmStmtClass: + case Stmt::MSAsmStmtClass: + case Stmt::GotoStmtClass: + case Stmt::LabelStmtClass: +return this->emitInvalid(S); default: { if (auto *Exp = dyn_cast(S)) return this->discard(Exp); @@ -657,11 +660,6 @@ bool ByteCodeStmtGen::visitDefaultStmt(const DefaultStmt *S) { return this->visitStmt(S->getSubStmt()); } -template -bool ByteCodeStmtGen::visitAsmStmt(const AsmStmt *S) { - return this->emitInvalid(S); -} - template bool ByteCodeStmtGen::visitAttributedStmt(const AttributedStmt *S) { // Ignore all attributes. diff --git a/clang/lib/AST/Interp/ByteCodeStmtGen.h b/clang/lib/AST/Interp/ByteCodeStmtGen.h index 64e03587ab2112..ab7a591fb798ee 100644 --- a/clang/lib/AST/Interp/ByteCodeStmtGen.h +++ b/clang/lib/AST/Interp/ByteCodeStmtGen.h @@ -63,7 +63,6 @@ class ByteCodeStmtGen final : public ByteCodeExprGen { bool visitSwitchStmt(const SwitchStmt *S); bool visitCaseStmt(const CaseStmt *S); bool visitDefaultStmt(const DefaultStmt *S); - bool visitAsmStmt(const AsmStmt *S); bool visitAttributedStmt(const AttributedStmt *S); bool visitCXXTryStmt(const CXXTryStmt *S); diff --git a/clang/test/AST/Interp/cxx23.cpp b/clang/test/AST/Interp/cxx23.cpp index 127b58915127cf..9ca3a38254b2d1 100644 --- a/clang/test/AST/Interp/cxx23.cpp +++ b/clang/test/AST/Interp/cxx23.cpp @@ -1,6 +1,6 @@ -// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fcxx-exceptions -verify=ref20,all,all-20 %s +// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fcxx-exceptions -verify=ref20,all,all20 %s // RUN: %clang_cc1 -std=c++23 -fsyntax-only -fcxx-exceptions -verify=ref23,all %s -// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fcxx-exceptions -verify=expected20,all,all-20 %s -fexperimental-new-constant-interpreter +// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fcxx-exceptions -verify=expected20,all,all20 %s -fexperimental-new-constant-interpreter // RUN: %clang_cc1 -std=c++23 -fsyntax-only -fcxx-exceptions -verify=expected23,all %s -fexperimental-new-constant-interpreter /// FIXME: The new interpreter is missing all the 'control flows through...' diagnostics. @@ -108,9 +108,9 @@ namespace StaticOperators { static_assert(f2() == 3); struct S1 { -constexpr S1() { // all-20-error {{never produces a constant expression}} +constexpr S1() { // all20-error {{never produces a constant expression}} throw; // all-note {{not valid in a constant expression}} \ - // all-20-note {{not valid in a constant expression}} + // all20-note {{not valid in a constant expression}} } static constexpr int operator()() { return 3; } // ref20-warning {{C++23 extension}} \ // expected20-warning {{C++23 extension}} @@ -121,3 +121,19 @@ namespace StaticOperators { } + +int test_in_lambdas() { + auto c = [](int n) constexpr { +if (n == 0) + return 0; +else + goto test; // all-note {{subexpression not valid in a constant expression}} \ + // all20-warning {{use of this statement in a constexpr function is a C++23 extension}} + test: +return 1; + }; + c(0); + constexpr auto A = c(1); // all-error {{must be initialized by a constant expression}} \ + // all-note {{in call to}} + return 0; +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 719e077 - [clang][Interp] Handle PackIndexExprs
Author: Timm Bäder Date: 2024-03-15T10:04:23+01:00 New Revision: 719e077a5680ccfd6601195754c1702b03ba3645 URL: https://github.com/llvm/llvm-project/commit/719e077a5680ccfd6601195754c1702b03ba3645 DIFF: https://github.com/llvm/llvm-project/commit/719e077a5680ccfd6601195754c1702b03ba3645.diff LOG: [clang][Interp] Handle PackIndexExprs Added: Modified: clang/lib/AST/Interp/ByteCodeExprGen.cpp clang/lib/AST/Interp/ByteCodeExprGen.h clang/test/AST/Interp/cxx23.cpp Removed: diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index 088301c08b81bb..39bacbebb5ba7b 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -2226,6 +2226,12 @@ bool ByteCodeExprGen::VisitPseudoObjectExpr( return true; } +template +bool ByteCodeExprGen::VisitPackIndexingExpr( +const PackIndexingExpr *E) { + return this->delegate(E->getSelectedExpr()); +} + template bool ByteCodeExprGen::discard(const Expr *E) { if (E->containsErrors()) return false; diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.h b/clang/lib/AST/Interp/ByteCodeExprGen.h index 5ad2e74d7c2693..969598c9780513 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.h +++ b/clang/lib/AST/Interp/ByteCodeExprGen.h @@ -119,6 +119,7 @@ class ByteCodeExprGen : public ConstStmtVisitor, bool>, bool VisitConceptSpecializationExpr(const ConceptSpecializationExpr *E); bool VisitCXXRewrittenBinaryOperator(const CXXRewrittenBinaryOperator *E); bool VisitPseudoObjectExpr(const PseudoObjectExpr *E); + bool VisitPackIndexingExpr(const PackIndexingExpr *E); protected: bool visitExpr(const Expr *E) override; diff --git a/clang/test/AST/Interp/cxx23.cpp b/clang/test/AST/Interp/cxx23.cpp index 9ca3a38254b2d1..042e29613aa753 100644 --- a/clang/test/AST/Interp/cxx23.cpp +++ b/clang/test/AST/Interp/cxx23.cpp @@ -137,3 +137,12 @@ int test_in_lambdas() { // all-note {{in call to}} return 0; } + +/// PackIndexExpr. +template +struct check_ice { +enum e { +x = p...[0] // all-warning {{is a C++2c extension}} +}; +}; +static_assert(check_ice<42>::x == 42); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AMDGPU] Add an option to disable unsafe uses of atomic xor (PR #69229)
arsenm wrote: > @arsenm I agree that the default should be assuming fine-grained is possible. > My thinking behind the original naming and direction was not wanting to > introduce an unexpected performance regression by default. I'm happy for both > to be changed, and this patch being rebased on top of #85052 once it is > merged. The opting for fast-and-maybe-broken by default needs to be a frontend decision (i.e. the language can choose to add the metadata to all atomics). I believe @yxsamliu is going to be working on the frontend half which will preserve the HIP behavior > > One oustanding question for me is, although outside of the scope of this PR, > how will the original 'no-unsafe-fp' option fit in the new metadata node in > terms of constraints? Would it imply a new constraint or be covered by > `no_fine_grained` and `no_remote`? I believe we need an additional piece of metadata (which I have another draft for) to express the relaxable floating point. We can express the unsafe-fp-math option with the 2 combined, and then can drop the old IR attribute https://github.com/llvm/llvm-project/pull/69229 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang][HLSL][SPRI-V] Add convergence intrinsics (PR #80680)
Nathan =?utf-8?q?Gauër?= , Nathan =?utf-8?q?Gauër?= , Nathan =?utf-8?q?Gauër?= , Nathan =?utf-8?q?Gauër?= , Nathan =?utf-8?q?Gauër?= Message-ID: In-Reply-To: @@ -1295,11 +1295,13 @@ double4 trunc(double4); /// true, across all active lanes in the current wave. _HLSL_AVAILABILITY(shadermodel, 6.0) _HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_count_bits) +__attribute__((convergent)) arsenm wrote: Should remove the convergent attribute (we never should have added this). The language settings need to set IR convergent on everything https://github.com/llvm/llvm-project/pull/80680 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][MSVC] Correct mangling of thread-safe static initialization variables. (PR #85300)
https://github.com/zmodem edited https://github.com/llvm/llvm-project/pull/85300 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][MSVC] Correct mangling of thread-safe static initialization variables. (PR #85300)
https://github.com/zmodem approved this pull request. lgtm, thanks! Please include a "Fixes #83616" reference in the commit message. https://github.com/llvm/llvm-project/pull/85300 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][MSVC] Correct mangling of thread-safe static initialization variables. (PR #85300)
@@ -3920,7 +3920,8 @@ void MicrosoftMangleContextImpl::mangleThreadSafeStaticGuardVariable( msvc_hashing_ostream MHO(Out); MicrosoftCXXNameMangler Mangler(*this, MHO); - Mangler.getStream() << "?$TSS" << GuardNum << '@'; + Mangler.getStream() << "?"; + Mangler.mangleSourceName("$TSS" + llvm::utostr(GuardNum)); zmodem wrote: Can you file a bug for followup on these? https://github.com/llvm/llvm-project/pull/85300 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][MSVC] Correct mangling of thread-safe static initialization variables. (PR #85300)
https://github.com/zmodem edited https://github.com/llvm/llvm-project/pull/85300 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Don't alias -mstrict-align to -mno-unaligned-access (PR #85350)
@@ -321,9 +321,11 @@ void aarch64::getAArch64TargetFeatures(const Driver &D, } } - if (Arg *A = Args.getLastArg(options::OPT_mno_unaligned_access, - options::OPT_munaligned_access)) { -if (A->getOption().matches(options::OPT_mno_unaligned_access)) + if (Arg *A = Args.getLastArg( + options::OPT_mstrict_align, options::OPT_mno_strict_align, + options::OPT_mno_unaligned_access, options::OPT_munaligned_access)) { +if (A->getOption().matches(options::OPT_mstrict_align) || +A->getOption().matches(options::OPT_mno_unaligned_access)) smithp35 wrote: Preventing unaligned access can be useful in AArch64, it is an option we do use to build our embedded C-libraries with (not a focus for GCC). It is documented in the toolchain manual https://developer.arm.com/documentation/101754/0621/armclang-Reference/armclang-Command-line-Options/-munaligned-access---mno-unaligned-access In summary, we'd like to keep it for AArch64. AArch64 always has the option of using unaligned accesses, but they can be disabled by writing the SCTLR register, and accesses to Device memory always need to be aligned. Code that runs before the MMU is enabled runs as if Device memory. ``` Unaligned accesses to Normal memory The behavior of unaligned accesses to Normal memory is dependent on all of the following: • The instruction causing the memory access. • The memory attributes of the accessed memory. • The value of SCTLR_ELx.{A, nAA}. • Whether or not FEAT_LSE2 is implemented. ``` https://github.com/llvm/llvm-project/pull/85350 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [WebAssembly] Implement an alternative translation for -wasm-enable-sjlj (PR #84137)
@@ -198,9 +198,18 @@ /// /// If there are calls to setjmp() /// -/// 2) and 3): The same as 2) and 3) in Emscripten SjLj. -/// (setjmpTable/setjmpTableSize initialization + setjmp callsite -/// transformation) +/// 2) In the function entry that calls setjmp, initialize +///functionInvocationId as follows: +/// +///functionInvocationId = alloca() +/// +/// 3) Lower +/// setjmp(env) +///into +/// __wasm_setjmp(env, label, functionInvocationId) +/// +///A BB with setjmp is split into two after setjmp call in order to +///make the post-setjmp BB the possible destination of longjmp BB. yamt wrote: done https://github.com/llvm/llvm-project/pull/84137 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [WebAssembly] Implement an alternative translation for -wasm-enable-sjlj (PR #84137)
@@ -198,9 +198,18 @@ /// /// If there are calls to setjmp() /// -/// 2) and 3): The same as 2) and 3) in Emscripten SjLj. -/// (setjmpTable/setjmpTableSize initialization + setjmp callsite -/// transformation) +/// 2) In the function entry that calls setjmp, initialize +///functionInvocationId as follows: +/// +///functionInvocationId = alloca() yamt wrote: yes https://github.com/llvm/llvm-project/pull/84137 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [WebAssembly] Implement an alternative translation for -wasm-enable-sjlj (PR #84137)
yamt wrote: > i tried to run the relevant emscripten tests. but i have not succeeded yet > even w/o these changes. (i'm an emscripten newbie.) they passed with the latest version of this PR and the emscripten PR. https://github.com/llvm/llvm-project/pull/84137 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 72d85b0 - [clang][Interp] Emit Error op for contains-error expressions
Author: Timm Bäder Date: 2024-03-15T10:52:58+01:00 New Revision: 72d85b0315628c982be21c7aada59b6f9274de90 URL: https://github.com/llvm/llvm-project/commit/72d85b0315628c982be21c7aada59b6f9274de90 DIFF: https://github.com/llvm/llvm-project/commit/72d85b0315628c982be21c7aada59b6f9274de90.diff LOG: [clang][Interp] Emit Error op for contains-error expressions Instead of aborting interpretation right away. This way we can still successfully evaluate such functions provided we don't reach the Error op at all. Added: Modified: clang/lib/AST/Interp/ByteCodeExprGen.cpp clang/lib/AST/Interp/Interp.h clang/lib/AST/Interp/Opcodes.td clang/test/AST/Interp/if.cpp Removed: diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index 39bacbebb5ba7b..f07e430e279d22 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -2244,7 +2244,7 @@ template bool ByteCodeExprGen::discard(const Expr *E) { template bool ByteCodeExprGen::delegate(const Expr *E) { if (E->containsErrors()) -return false; +return this->emitError(E); // We're basically doing: // OptionScope Scope(this, DicardResult, Initializing); @@ -2254,7 +2254,7 @@ bool ByteCodeExprGen::delegate(const Expr *E) { template bool ByteCodeExprGen::visit(const Expr *E) { if (E->containsErrors()) -return false; +return this->emitError(E); if (E->getType()->isVoidType()) return this->discard(E); @@ -2283,7 +2283,7 @@ bool ByteCodeExprGen::visitInitializer(const Expr *E) { assert(!classify(E->getType())); if (E->containsErrors()) -return false; +return this->emitError(E); OptionScope Scope(this, /*NewDiscardResult=*/false, /*NewInitializing=*/true); diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h index 08e272cbc005bd..405993eb827036 100644 --- a/clang/lib/AST/Interp/Interp.h +++ b/clang/lib/AST/Interp/Interp.h @@ -2227,6 +2227,9 @@ inline bool Invalid(InterpState &S, CodePtr OpPC) { return false; } +/// Do nothing and just abort execution. +inline bool Error(InterpState &S, CodePtr OpPC) { return false; } + /// Same here, but only for casts. inline bool InvalidCast(InterpState &S, CodePtr OpPC, CastKind Kind) { const SourceLocation &Loc = S.Current->getLocation(OpPC); diff --git a/clang/lib/AST/Interp/Opcodes.td b/clang/lib/AST/Interp/Opcodes.td index 0ed214af3548aa..cc1310f4c0d52a 100644 --- a/clang/lib/AST/Interp/Opcodes.td +++ b/clang/lib/AST/Interp/Opcodes.td @@ -706,6 +706,7 @@ def Dup : Opcode { // [] -> [] def Invalid : Opcode {} +def Error : Opcode {} def InvalidCast : Opcode { let Args = [ArgCastKind]; } diff --git a/clang/test/AST/Interp/if.cpp b/clang/test/AST/Interp/if.cpp index 86ae8de6f73ebb..37289d69d32554 100644 --- a/clang/test/AST/Interp/if.cpp +++ b/clang/test/AST/Interp/if.cpp @@ -1,8 +1,5 @@ -// RUN: %clang_cc1 -std=c++23 -fsyntax-only -fexperimental-new-constant-interpreter %s -verify -// RUN: %clang_cc1 -std=c++23 -fsyntax-only %s -verify=ref - -// expected-no-diagnostics -// ref-no-diagnostics +// RUN: %clang_cc1 -std=c++23 -fsyntax-only -fexperimental-new-constant-interpreter %s -verify=expected,both +// RUN: %clang_cc1 -std=c++23 -fsyntax-only %s -verify=ref,both namespace ConstEval { constexpr int f() { @@ -51,3 +48,13 @@ namespace InitDecl { } static_assert(attrs() == 1, ""); }; + +/// The faulty if statement creates a RecoveryExpr with contains-errors, +/// but the execution will never reach that. +constexpr char g(char const (&x)[2]) { +return 'x'; + if (auto [a, b] = x) // both-error {{an array type is not allowed here}} \ + // both-warning {{ISO C++17 does not permit structured binding declaration in a condition}} +; +} +static_assert(g("x") == 'x'); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][PowerPC] Add flag to enable compatibility with GNU for complex arguments (PR #77732)
https://github.com/Long5hot updated https://github.com/llvm/llvm-project/pull/77732 >From ac3e5526189f5d9e2abe739a21394a63f75567b5 Mon Sep 17 00:00:00 2001 From: Kishan Parmar Date: Fri, 15 Mar 2024 15:29:41 +0530 Subject: [PATCH] [clang][PowerPC] Add flag to enable compatibility with GNU for complex arguments Fixes : https://github.com/llvm/llvm-project/issues/56023 https://godbolt.org/z/1bsW1sKMs newFlag : -fcomplex-ppc-gnu-abi GNU uses GPRs for complex parameters and return values storing for PowerPC-32bit, which can be enabled which above flag. Intent of this patch is to make clang compatible with GNU libraries of complex. Following up with this patch : https://reviews.llvm.org/D146942 --- clang/include/clang/Basic/CodeGenOptions.def | 2 + clang/include/clang/Basic/CodeGenOptions.h| 6 + clang/include/clang/Driver/Options.td | 4 + clang/lib/CodeGen/Targets/PPC.cpp | 107 +++- clang/lib/Driver/ToolChains/Clang.cpp | 9 + clang/lib/Frontend/CompilerInvocation.cpp | 8 + .../CodeGen/PowerPC/ppc32-complex-gnu-abi.c | 255 ++ 7 files changed, 379 insertions(+), 12 deletions(-) create mode 100644 clang/test/CodeGen/PowerPC/ppc32-complex-gnu-abi.c diff --git a/clang/include/clang/Basic/CodeGenOptions.def b/clang/include/clang/Basic/CodeGenOptions.def index 340b08dd7e2a33..f4845e9e424c67 100644 --- a/clang/include/clang/Basic/CodeGenOptions.def +++ b/clang/include/clang/Basic/CodeGenOptions.def @@ -225,6 +225,8 @@ CODEGENOPT(MCDCCoverage , 1, 0) ///< Enable MC/DC code coverage criteria. /// If -fpcc-struct-return or -freg-struct-return is specified. ENUM_CODEGENOPT(StructReturnConvention, StructReturnConventionKind, 2, SRCK_Default) + /// If -fcomplex-ppc-gnu-abi is specified on ppc32. +ENUM_CODEGENOPT(ComplexInRegABI, ComplexArgumentConventionKind, 2, CMPLX_OnStack) CODEGENOPT(RelaxAll , 1, 0) ///< Relax all machine code instructions. CODEGENOPT(RelaxedAliasing , 1, 0) ///< Set when -fno-strict-aliasing is enabled. diff --git a/clang/include/clang/Basic/CodeGenOptions.h b/clang/include/clang/Basic/CodeGenOptions.h index 9469a424045bb0..1c9424f65623dd 100644 --- a/clang/include/clang/Basic/CodeGenOptions.h +++ b/clang/include/clang/Basic/CodeGenOptions.h @@ -78,6 +78,12 @@ class CodeGenOptions : public CodeGenOptionsBase { SRCK_InRegs// Small structs in registers (-freg-struct-return). }; + enum ComplexArgumentConventionKind { +CMPLX_OnStack, +CMPLX_InGPR, // If -fcomplex-ppc-gnu-abi is specified on ppc32 +CMPLX_InFPR + }; + enum ProfileInstrKind { ProfileNone, // Profile instrumentation is turned off. ProfileClangInstr, // Clang instrumentation to generate execution counts diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index a7e43b4d179a4d..2128b87abe8ea6 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -2578,6 +2578,10 @@ def ffp_contract : Joined<["-"], "ffp-contract=">, Group, HelpText<"Form fused FP ops (e.g. FMAs)">, Values<"fast,on,off,fast-honor-pragmas">; +def fcomplex_ppc_gnu_abi : Flag<["-"], "fcomplex-ppc-gnu-abi">, Group, Visibility<[ClangOption, CC1Option]>, + DocBrief<"Follow the GNU ABI, pass Complex values in GPRs instead of the stack for PowerPC-32">, + HelpText<"Pass Complex values in GPR instead of stack for PowerPC-32">; + defm strict_float_cast_overflow : BoolFOption<"strict-float-cast-overflow", CodeGenOpts<"StrictFloatCastOverflow">, DefaultTrue, NegFlag( -CGT, SoftFloatABI, RetSmallStructInRegABI)) {} +CGT, SoftFloatABI, RetSmallStructInRegABI, ComplexInRegABI)) {} static bool isStructReturnInRegABI(const llvm::Triple &Triple, const CodeGenOptions &Opts); @@ -396,12 +407,77 @@ CharUnits PPC32_SVR4_ABIInfo::getParamTypeAlignment(QualType Ty) const { return CharUnits::fromQuantity(4); } +ABIArgInfo PPC32_SVR4_ABIInfo::handleComplex(uint64_t &TypeSize) const { + llvm::Type *ElemTy; + unsigned RegsNeeded; // Registers Needed for Complex. + + // Choice of using llvm::Type::getInt64Ty(getVMContext()) for complex + // single-precision floats is based on the ABI ATR-PASS-COMPLEX-IN-GPRS + // specification. According to the specification: + // - For complex single-precision floats: If the register (gr) is even, it's + // incremented by one, and the lower-addressed word of the argument is loaded + // into gr, while the higher-addressed word is loaded into gr + 1. Then, gr is + // incremented by 2. + // - For complex double-precision floats: The words of the argument are loaded + // in memory-address order into gr, gr + 1, gr + 2, and gr + 3, with gr being + // incremented by 4. Thus, to maintain even alignment and adhere to the ABI + // specification, llvm::Type::getInt64Ty(getVMContext()) is used when TypeSize + // is 64. Powerpc backen
[clang] [clang][PowerPC] Add flag to enable compatibility with GNU for complex arguments (PR #77732)
@@ -0,0 +1,177 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 2 + +// RUN: %clang_cc1 -triple powerpc-unknown-linux-gnu \ +// RUN: -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK-DEF +// RUN: %clang_cc1 -triple powerpc-unknown-linux-gnu -fcomplex-ppc-gnu-abi \ +// RUN: -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK-GNU + +// CHECK-DEF-LABEL: define dso_local void @foo1 +// CHECK-DEF-SAME: (ptr dead_on_unwind noalias writable sret({ float, float }) align 4 [[AGG_RESULT:%.*]], ptr noundef byval({ float, float }) align 4 [[X:%.*]]) #[[ATTR0:[0-9]+]] { Long5hot wrote: I couldn't remove #[[ATTR0:[0-9]+]]1. Because testcase fails saying no missing attributes. llvm-lit(clang) generates IR with # attributes, so looks like Filecheck expects #attribute fields to be present. https://github.com/llvm/llvm-project/pull/77732 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][PowerPC] Add flag to enable compatibility with GNU for complex arguments (PR #77732)
https://github.com/Long5hot edited https://github.com/llvm/llvm-project/pull/77732 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Add clang-tidy check readability-math-missing-parentheses (PR #84481)
https://github.com/11happy updated https://github.com/llvm/llvm-project/pull/84481 >From 8fdf6306085ed4cf0f77b7e718e374e9f65fedf9 Mon Sep 17 00:00:00 2001 From: 11happy Date: Fri, 8 Mar 2024 19:02:47 +0530 Subject: [PATCH 1/3] add clang-tidy check readability-math-missing-parentheses Signed-off-by: 11happy --- .../clang-tidy/readability/CMakeLists.txt | 1 + .../MathMissingParenthesesCheck.cpp | 167 ++ .../readability/MathMissingParenthesesCheck.h | 31 .../readability/ReadabilityTidyModule.cpp | 3 + clang-tools-extra/docs/ReleaseNotes.rst | 6 + .../docs/clang-tidy/checks/list.rst | 1 + .../readability/math-missing-parentheses.rst | 19 ++ .../readability/math-missing-parentheses.cpp | 42 + 8 files changed, 270 insertions(+) create mode 100644 clang-tools-extra/clang-tidy/readability/MathMissingParenthesesCheck.cpp create mode 100644 clang-tools-extra/clang-tidy/readability/MathMissingParenthesesCheck.h create mode 100644 clang-tools-extra/docs/clang-tidy/checks/readability/math-missing-parentheses.rst create mode 100644 clang-tools-extra/test/clang-tidy/checkers/readability/math-missing-parentheses.cpp diff --git a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt index a6c8cbd8eb448a..0d4fa095501dfb 100644 --- a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt @@ -27,6 +27,7 @@ add_clang_library(clangTidyReadabilityModule IsolateDeclarationCheck.cpp MagicNumbersCheck.cpp MakeMemberFunctionConstCheck.cpp + MathMissingParenthesesCheck.cpp MisleadingIndentationCheck.cpp MisplacedArrayIndexCheck.cpp NamedParameterCheck.cpp diff --git a/clang-tools-extra/clang-tidy/readability/MathMissingParenthesesCheck.cpp b/clang-tools-extra/clang-tidy/readability/MathMissingParenthesesCheck.cpp new file mode 100644 index 00..d9574a9fb7a476 --- /dev/null +++ b/clang-tools-extra/clang-tidy/readability/MathMissingParenthesesCheck.cpp @@ -0,0 +1,167 @@ +//===--- MathMissingParenthesesCheck.cpp - clang-tidy -===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "MathMissingParenthesesCheck.h" +#include "../utils/ASTUtils.h" +#include "clang/AST/ASTContext.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/Lex/Preprocessor.h" +#include +#include + +using namespace clang::ast_matchers; + +namespace clang::tidy::readability { + +void MathMissingParenthesesCheck::registerMatchers(MatchFinder *Finder) { + Finder->addMatcher(binaryOperator(unless(hasParent(binaryOperator())), +hasDescendant(binaryOperator())) + .bind("binOp"), + this); +} +static int precedenceCheck(const char op) { + if (op == '/' || op == '*' || op == '%') +return 5; + + else if (op == '+' || op == '-') +return 4; + + else if (op == '&') +return 3; + else if (op == '^') +return 2; + + else if (op == '|') +return 1; + + else +return 0; +} +static bool isOperand(const char c) { + if (c >= 'a' && c <= 'z') +return true; + else if (c >= 'A' && c <= 'Z') +return true; + else if (c >= '0' && c <= '9') +return true; + else if (c == '$') +return true; + else +return false; +} +static bool conditionForNegative(const std::string s, int i, + const std::string CurStr) { + if (CurStr[0] == '-') { +if (i == 0) { + return true; +} else { + while (s[i - 1] == ' ') { +i--; + } + if (!isOperand(s[i - 1])) { +return true; + } else { +return false; + } +} + } else { +return false; + } +} +static std::string getOperationOrder(std::string s, std::set &Operators) { + std::stack StackOne; + std::string TempStr = ""; + for (int i = 0; i < s.length(); i++) { +std::string CurStr = ""; +CurStr += s[i]; +if (CurStr == " ") + continue; +else { + if (isOperand(CurStr[0]) || conditionForNegative(s, i, CurStr)) { +while (i < s.length() && (isOperand(s[i]) || s[i] == '-')) { + if (s[i] == '-') { +TempStr += "$"; + } else { +TempStr += CurStr; + } + i++; + CurStr = s[i]; +} +TempStr += " "; + } else if (CurStr == "(") { +StackOne.push("("); + } else if (CurStr == ")") { +while (StackOne.top() != "(") { + TempStr += StackOne.top(); + StackOne.pop(); +} +StackOne.pop(); + } else { +while (!StackOne.empty() && precedenceCheck
[clang-tools-extra] Add clang-tidy check readability-math-missing-parentheses (PR #84481)
https://github.com/11happy updated https://github.com/llvm/llvm-project/pull/84481 >From 8fdf6306085ed4cf0f77b7e718e374e9f65fedf9 Mon Sep 17 00:00:00 2001 From: 11happy Date: Fri, 8 Mar 2024 19:02:47 +0530 Subject: [PATCH 1/4] add clang-tidy check readability-math-missing-parentheses Signed-off-by: 11happy --- .../clang-tidy/readability/CMakeLists.txt | 1 + .../MathMissingParenthesesCheck.cpp | 167 ++ .../readability/MathMissingParenthesesCheck.h | 31 .../readability/ReadabilityTidyModule.cpp | 3 + clang-tools-extra/docs/ReleaseNotes.rst | 6 + .../docs/clang-tidy/checks/list.rst | 1 + .../readability/math-missing-parentheses.rst | 19 ++ .../readability/math-missing-parentheses.cpp | 42 + 8 files changed, 270 insertions(+) create mode 100644 clang-tools-extra/clang-tidy/readability/MathMissingParenthesesCheck.cpp create mode 100644 clang-tools-extra/clang-tidy/readability/MathMissingParenthesesCheck.h create mode 100644 clang-tools-extra/docs/clang-tidy/checks/readability/math-missing-parentheses.rst create mode 100644 clang-tools-extra/test/clang-tidy/checkers/readability/math-missing-parentheses.cpp diff --git a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt index a6c8cbd8eb448a..0d4fa095501dfb 100644 --- a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt @@ -27,6 +27,7 @@ add_clang_library(clangTidyReadabilityModule IsolateDeclarationCheck.cpp MagicNumbersCheck.cpp MakeMemberFunctionConstCheck.cpp + MathMissingParenthesesCheck.cpp MisleadingIndentationCheck.cpp MisplacedArrayIndexCheck.cpp NamedParameterCheck.cpp diff --git a/clang-tools-extra/clang-tidy/readability/MathMissingParenthesesCheck.cpp b/clang-tools-extra/clang-tidy/readability/MathMissingParenthesesCheck.cpp new file mode 100644 index 00..d9574a9fb7a476 --- /dev/null +++ b/clang-tools-extra/clang-tidy/readability/MathMissingParenthesesCheck.cpp @@ -0,0 +1,167 @@ +//===--- MathMissingParenthesesCheck.cpp - clang-tidy -===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "MathMissingParenthesesCheck.h" +#include "../utils/ASTUtils.h" +#include "clang/AST/ASTContext.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/Lex/Preprocessor.h" +#include +#include + +using namespace clang::ast_matchers; + +namespace clang::tidy::readability { + +void MathMissingParenthesesCheck::registerMatchers(MatchFinder *Finder) { + Finder->addMatcher(binaryOperator(unless(hasParent(binaryOperator())), +hasDescendant(binaryOperator())) + .bind("binOp"), + this); +} +static int precedenceCheck(const char op) { + if (op == '/' || op == '*' || op == '%') +return 5; + + else if (op == '+' || op == '-') +return 4; + + else if (op == '&') +return 3; + else if (op == '^') +return 2; + + else if (op == '|') +return 1; + + else +return 0; +} +static bool isOperand(const char c) { + if (c >= 'a' && c <= 'z') +return true; + else if (c >= 'A' && c <= 'Z') +return true; + else if (c >= '0' && c <= '9') +return true; + else if (c == '$') +return true; + else +return false; +} +static bool conditionForNegative(const std::string s, int i, + const std::string CurStr) { + if (CurStr[0] == '-') { +if (i == 0) { + return true; +} else { + while (s[i - 1] == ' ') { +i--; + } + if (!isOperand(s[i - 1])) { +return true; + } else { +return false; + } +} + } else { +return false; + } +} +static std::string getOperationOrder(std::string s, std::set &Operators) { + std::stack StackOne; + std::string TempStr = ""; + for (int i = 0; i < s.length(); i++) { +std::string CurStr = ""; +CurStr += s[i]; +if (CurStr == " ") + continue; +else { + if (isOperand(CurStr[0]) || conditionForNegative(s, i, CurStr)) { +while (i < s.length() && (isOperand(s[i]) || s[i] == '-')) { + if (s[i] == '-') { +TempStr += "$"; + } else { +TempStr += CurStr; + } + i++; + CurStr = s[i]; +} +TempStr += " "; + } else if (CurStr == "(") { +StackOne.push("("); + } else if (CurStr == ")") { +while (StackOne.top() != "(") { + TempStr += StackOne.top(); + StackOne.pop(); +} +StackOne.pop(); + } else { +while (!StackOne.empty() && precedenceCheck
[clang-tools-extra] Add clang-tidy check readability-math-missing-parentheses (PR #84481)
@@ -0,0 +1,68 @@ +//===--- MathMissingParenthesesCheck.cpp - clang-tidy -===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "MathMissingParenthesesCheck.h" +#include "../utils/ASTUtils.h" +#include "clang/AST/ASTContext.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/Lex/Preprocessor.h" +#include "clang/Rewrite/Core/Rewriter.h" +#include +using namespace std; + +using namespace clang::ast_matchers; + +namespace clang::tidy::readability { + +void MathMissingParenthesesCheck::registerMatchers(MatchFinder *Finder) { + Finder->addMatcher(binaryOperator(unless(hasParent(binaryOperator())), +hasDescendant(binaryOperator())) + .bind("binOp"), + this); +} + +void addParantheses(const BinaryOperator *BinOp, clang::Rewriter &Rewrite, +const BinaryOperator *ParentBinOp, bool &NeedToDiagnose) { + if (!BinOp) +return; + if (ParentBinOp != nullptr && + ParentBinOp->getOpcode() != BinOp->getOpcode()) { +NeedToDiagnose = true; + } + clang::SourceLocation StartLoc = BinOp->getLHS()->getBeginLoc(); + clang::SourceLocation EndLoc = BinOp->getRHS()->getEndLoc(); + Rewrite.InsertText(StartLoc, "("); + Rewrite.InsertTextAfterToken(EndLoc, ")"); + addParantheses(dyn_cast(BinOp->getLHS()), Rewrite, BinOp, + NeedToDiagnose); + addParantheses(dyn_cast(BinOp->getRHS()), Rewrite, BinOp, + NeedToDiagnose); +} + +void MathMissingParenthesesCheck::check( +const MatchFinder::MatchResult &Result) { + const auto *BinOp = Result.Nodes.getNodeAs("binOp"); + if (!BinOp) +return; + clang::SourceManager &SM = *Result.SourceManager; + clang::LangOptions LO = Result.Context->getLangOpts(); + Rewriter Rewrite(SM, LO); + bool NeedToDiagnose = false; + addParantheses(BinOp, Rewrite, nullptr, NeedToDiagnose); + clang::SourceLocation StartLoc = BinOp->getLHS()->getBeginLoc(); + clang::SourceLocation EndLoc = + BinOp->getRHS()->getEndLoc().getLocWithOffset(1); + clang::SourceRange range(StartLoc, EndLoc); + std::string NewExpression = Rewrite.getRewrittenText(range); + if (NeedToDiagnose) { +diag(StartLoc, "add parantheses to clarify the precedence of operations") +<< FixItHint::CreateReplacement(range, NewExpression); 11happy wrote: done https://github.com/llvm/llvm-project/pull/84481 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Add clang-tidy check readability-math-missing-parentheses (PR #84481)
@@ -0,0 +1,74 @@ +// RUN: %check_clang_tidy %s readability-math-missing-parentheses %t + +// FIXME: Add something that triggers the check here. 11happy wrote: done https://github.com/llvm/llvm-project/pull/84481 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Add clang-tidy check readability-math-missing-parentheses (PR #84481)
@@ -0,0 +1,68 @@ +//===--- MathMissingParenthesesCheck.cpp - clang-tidy -===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "MathMissingParenthesesCheck.h" +#include "../utils/ASTUtils.h" +#include "clang/AST/ASTContext.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/Lex/Preprocessor.h" +#include "clang/Rewrite/Core/Rewriter.h" +#include +using namespace std; + +using namespace clang::ast_matchers; + +namespace clang::tidy::readability { + +void MathMissingParenthesesCheck::registerMatchers(MatchFinder *Finder) { + Finder->addMatcher(binaryOperator(unless(hasParent(binaryOperator())), +hasDescendant(binaryOperator())) + .bind("binOp"), + this); +} + +void addParantheses(const BinaryOperator *BinOp, clang::Rewriter &Rewrite, +const BinaryOperator *ParentBinOp, bool &NeedToDiagnose) { + if (!BinOp) +return; + if (ParentBinOp != nullptr && + ParentBinOp->getOpcode() != BinOp->getOpcode()) { +NeedToDiagnose = true; + } + clang::SourceLocation StartLoc = BinOp->getLHS()->getBeginLoc(); + clang::SourceLocation EndLoc = BinOp->getRHS()->getEndLoc(); + Rewrite.InsertText(StartLoc, "("); + Rewrite.InsertTextAfterToken(EndLoc, ")"); + addParantheses(dyn_cast(BinOp->getLHS()), Rewrite, BinOp, + NeedToDiagnose); + addParantheses(dyn_cast(BinOp->getRHS()), Rewrite, BinOp, + NeedToDiagnose); +} + +void MathMissingParenthesesCheck::check( +const MatchFinder::MatchResult &Result) { + const auto *BinOp = Result.Nodes.getNodeAs("binOp"); + if (!BinOp) +return; + clang::SourceManager &SM = *Result.SourceManager; + clang::LangOptions LO = Result.Context->getLangOpts(); + Rewriter Rewrite(SM, LO); + bool NeedToDiagnose = false; + addParantheses(BinOp, Rewrite, nullptr, NeedToDiagnose); + clang::SourceLocation StartLoc = BinOp->getLHS()->getBeginLoc(); + clang::SourceLocation EndLoc = + BinOp->getRHS()->getEndLoc().getLocWithOffset(1); 11happy wrote: done https://github.com/llvm/llvm-project/pull/84481 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Add clang-tidy check readability-math-missing-parentheses (PR #84481)
@@ -0,0 +1,68 @@ +//===--- MathMissingParenthesesCheck.cpp - clang-tidy -===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "MathMissingParenthesesCheck.h" +#include "../utils/ASTUtils.h" +#include "clang/AST/ASTContext.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/Lex/Preprocessor.h" +#include "clang/Rewrite/Core/Rewriter.h" +#include +using namespace std; + +using namespace clang::ast_matchers; + +namespace clang::tidy::readability { + +void MathMissingParenthesesCheck::registerMatchers(MatchFinder *Finder) { + Finder->addMatcher(binaryOperator(unless(hasParent(binaryOperator())), +hasDescendant(binaryOperator())) + .bind("binOp"), + this); +} + +void addParantheses(const BinaryOperator *BinOp, clang::Rewriter &Rewrite, +const BinaryOperator *ParentBinOp, bool &NeedToDiagnose) { + if (!BinOp) +return; + if (ParentBinOp != nullptr && + ParentBinOp->getOpcode() != BinOp->getOpcode()) { +NeedToDiagnose = true; + } + clang::SourceLocation StartLoc = BinOp->getLHS()->getBeginLoc(); + clang::SourceLocation EndLoc = BinOp->getRHS()->getEndLoc(); + Rewrite.InsertText(StartLoc, "("); + Rewrite.InsertTextAfterToken(EndLoc, ")"); + addParantheses(dyn_cast(BinOp->getLHS()), Rewrite, BinOp, + NeedToDiagnose); + addParantheses(dyn_cast(BinOp->getRHS()), Rewrite, BinOp, + NeedToDiagnose); +} + +void MathMissingParenthesesCheck::check( +const MatchFinder::MatchResult &Result) { + const auto *BinOp = Result.Nodes.getNodeAs("binOp"); + if (!BinOp) +return; + clang::SourceManager &SM = *Result.SourceManager; + clang::LangOptions LO = Result.Context->getLangOpts(); 11happy wrote: done https://github.com/llvm/llvm-project/pull/84481 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Add clang-tidy check readability-math-missing-parentheses (PR #84481)
@@ -0,0 +1,19 @@ +.. title:: clang-tidy - readability-math-missing-parentheses + +readability-math-missing-parentheses + + +Checks for mathematical expressions that involve operators of different priorities. 11happy wrote: done https://github.com/llvm/llvm-project/pull/84481 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Add clang-tidy check readability-math-missing-parentheses (PR #84481)
@@ -0,0 +1,68 @@ +//===--- MathMissingParenthesesCheck.cpp - clang-tidy -===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "MathMissingParenthesesCheck.h" +#include "../utils/ASTUtils.h" +#include "clang/AST/ASTContext.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/Lex/Preprocessor.h" +#include "clang/Rewrite/Core/Rewriter.h" +#include +using namespace std; + +using namespace clang::ast_matchers; + +namespace clang::tidy::readability { + +void MathMissingParenthesesCheck::registerMatchers(MatchFinder *Finder) { + Finder->addMatcher(binaryOperator(unless(hasParent(binaryOperator())), +hasDescendant(binaryOperator())) + .bind("binOp"), + this); +} + +void addParantheses(const BinaryOperator *BinOp, clang::Rewriter &Rewrite, +const BinaryOperator *ParentBinOp, bool &NeedToDiagnose) { + if (!BinOp) +return; + if (ParentBinOp != nullptr && + ParentBinOp->getOpcode() != BinOp->getOpcode()) { +NeedToDiagnose = true; + } + clang::SourceLocation StartLoc = BinOp->getLHS()->getBeginLoc(); + clang::SourceLocation EndLoc = BinOp->getRHS()->getEndLoc(); + Rewrite.InsertText(StartLoc, "("); + Rewrite.InsertTextAfterToken(EndLoc, ")"); + addParantheses(dyn_cast(BinOp->getLHS()), Rewrite, BinOp, + NeedToDiagnose); + addParantheses(dyn_cast(BinOp->getRHS()), Rewrite, BinOp, + NeedToDiagnose); +} + +void MathMissingParenthesesCheck::check( +const MatchFinder::MatchResult &Result) { + const auto *BinOp = Result.Nodes.getNodeAs("binOp"); + if (!BinOp) +return; 11happy wrote: done https://github.com/llvm/llvm-project/pull/84481 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [PowerPC] Fix behavior of rldimi/rlwimi/rlwnm builtins (PR #85040)
https://github.com/chenzheng1030 commented: Looks almost good to me though I have a comment for the all one mask case. https://github.com/llvm/llvm-project/pull/85040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [PowerPC] Fix behavior of rldimi/rlwimi/rlwnm builtins (PR #85040)
https://github.com/chenzheng1030 edited https://github.com/llvm/llvm-project/pull/85040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [PowerPC] Fix behavior of rldimi/rlwimi/rlwnm builtins (PR #85040)
@@ -10764,30 +10764,53 @@ SDValue PPCTargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op, return DAG.getRegister(PPC::R2, MVT::i32); case Intrinsic::ppc_rldimi: { +assert(Subtarget.isPPC64() && "rldimi is only available in 64-bit!"); +if (Op.getConstantOperandVal(4) == 0) + return Op.getOperand(2); uint64_t SH = Op.getConstantOperandVal(3); unsigned MB = 0, ME = 0; -if (!isRunOfOnes64(Op.getConstantOperandVal(4), MB, ME) || ME != 63 - SH) +if (!isRunOfOnes64(Op.getConstantOperandVal(4), MB, ME)) report_fatal_error("invalid rldimi mask!"); -return SDValue(DAG.getMachineNode( - PPC::RLDIMI, dl, MVT::i64, - {Op.getOperand(1), Op.getOperand(2), Op.getOperand(3), -DAG.getTargetConstant(MB, dl, MVT::i32)}), - 0); + +// For all-one mask, MB will be set to 0, adjust it next to 63-SH. chenzheng1030 wrote: For all-one mask, to improve the readability, is it better to just return the `Intrinsic::ppc_rldimi` as `ISD::ROTL (Op.getOperand(1), Op.getOperand(3))`? I think this would also benefit later optimizations as we are using a ISD node here. https://github.com/llvm/llvm-project/pull/85040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [PowerPC] Fix behavior of rldimi/rlwimi/rlwnm builtins (PR #85040)
@@ -72,4 +72,74 @@ define i64 @rldimi_intrinsic(i64 %a) { ret i64 %r3 } +define i64 @rldimi5(i64 %a, i64 %b) { +; CHECK-LABEL: rldimi5: +; CHECK: # %bb.0: +; CHECK-NEXT:rldimi 4, 3, 8, 40 +; CHECK-NEXT:mr 3, 4 +; CHECK-NEXT:blr + %r = call i64 @llvm.ppc.rldimi(i64 %a, i64 %b, i32 8, i64 16776960) ; 0x << 8 + ret i64 %r +} + +define i64 @rldimi6(i64 %a, i64 %b) { +; CHECK-LABEL: rldimi6: +; CHECK: # %bb.0: +; CHECK-NEXT:rotldi 3, 3, 1 +; CHECK-NEXT:rldimi 4, 3, 7, 41 +; CHECK-NEXT:mr 3, 4 +; CHECK-NEXT:blr + %r = call i64 @llvm.ppc.rldimi(i64 %a, i64 %b, i32 8, i64 8388480) ; 0x << 7 + ret i64 %r +} + +define i64 @rldimi7(i64 %a, i64 %b) { +; CHECK-LABEL: rldimi7: +; CHECK: # %bb.0: +; CHECK-NEXT:rotldi 3, 3, 63 +; CHECK-NEXT:rldimi 4, 3, 9, 39 +; CHECK-NEXT:mr 3, 4 +; CHECK-NEXT:blr + %r = call i64 @llvm.ppc.rldimi(i64 %a, i64 %b, i32 8, i64 33553920) ; 0x << 9 + ret i64 %r +} + +define i64 @rldimi8(i64 %a, i64 %b) { +; CHECK-LABEL: rldimi8: +; CHECK: # %bb.0: +; CHECK-NEXT:mr 3, 4 +; CHECK-NEXT:blr + %r = call i64 @llvm.ppc.rldimi(i64 %a, i64 %b, i32 0, i64 0) + ret i64 %r +} + +define i64 @rldimi9(i64 %a, i64 %b) { +; CHECK-LABEL: rldimi9: +; CHECK: # %bb.0: +; CHECK-NEXT:mr 3, 4 +; CHECK-NEXT:blr + %r = call i64 @llvm.ppc.rldimi(i64 %a, i64 %b, i32 63, i64 0) + ret i64 %r +} + +define i64 @rldimi10(i64 %a, i64 %b) { +; CHECK-LABEL: rldimi10: +; CHECK: # %bb.0: +; CHECK-NEXT:rldimi 4, 3, 0, 0 +; CHECK-NEXT:mr 3, 4 +; CHECK-NEXT:blr + %r = call i64 @llvm.ppc.rldimi(i64 %a, i64 %b, i32 0, i64 -1) + ret i64 %r +} + +define i64 @rldimi11(i64 %a, i64 %b) { +; CHECK-LABEL: rldimi11: +; CHECK: # %bb.0: +; CHECK-NEXT:rldimi 4, 3, 8, 56 +; CHECK-NEXT:mr 3, 4 +; CHECK-NEXT:blr + %r = call i64 @llvm.ppc.rldimi(i64 %a, i64 %b, i32 8, i64 -1) chenzheng1030 wrote: If we change to use `ISD::ROTL`, we will get `rotldi` as this place. Although `rldimi 4, 3, 8, 56` is right, it uses a wrap full mask. `rotldi` may be more friendly for optimizations like PPC peepholes. https://github.com/llvm/llvm-project/pull/85040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Add clang-tidy check readability-math-missing-parentheses (PR #84481)
@@ -0,0 +1,74 @@ +// RUN: %check_clang_tidy %s readability-math-missing-parentheses %t + +// FIXME: Add something that triggers the check here. + +int foo(){ +return 5; +} + +int bar(){ +return 4; +} + +class fun{ +public: +int A; +double B; +fun(){ +A = 5; +B = 5.4; +} +}; + +void f(){ +//CHECK-MESSAGES: :[[@LINE+2]]:13: warning: add parantheses to clarify the precedence of operations [readability-math-missing-parentheses] +//CHECK-FIXES: int a = (1 + (2 * 3)); +int a = 1 + 2 * 3; + +int b = 1 + 2 + 3; // No warning + +int c = 1 * 2 * 3; // No warning + +//CHECK-MESSAGES: :[[@LINE+2]]:13: warning: add parantheses to clarify the precedence of operations [readability-math-missing-parentheses] +//CHECK-FIXES: int d = ((1 + (2 * 3)) - (4 / 5)); +int d = 1 + 2 * 3 - 4 / 5; + +//CHECK-MESSAGES: :[[@LINE+2]]:13: warning: add parantheses to clarify the precedence of operations [readability-math-missing-parentheses] +//CHECK-FIXES: int e = ((1 & (2 + 3)) | (4 * 5)); +int e = 1 & 2 + 3 | 4 * 5; + +//CHECK-MESSAGES: :[[@LINE+2]]:13: warning: add parantheses to clarify the precedence of operations [readability-math-missing-parentheses] +//CHECK-FIXES: int f = ((1 * -2) + 4); +int f = 1 * -2 + 4; + +//CHECK-MESSAGES: :[[@LINE+2]]:13: warning: add parantheses to clarify the precedence of operations [readability-math-missing-parentheses] +//CHECK-FIXES: int g = 1 * 2) * 3) + 4) + 5); +int g = 1 * 2 * 3 + 4 + 5; + +// CHECK-MESSAGES: :[[@LINE+2]]:13: warning: add parantheses to clarify the precedence of operations [readability-math-missing-parentheses] +// CHECK-FIXES: int h = ((120 & (2 + 3)) | (22 * 5)); +int h = 120 & 2 + 3 | 22 * 5; + +int i = 1 & 2 & 3; // No warning + +int j = 1 | 2 | 3; // No warning + +int k = 1 ^ 2 ^ 3; // No warning + +// CHECK-MESSAGES: :[[@LINE+2]]:13: warning: add parantheses to clarify the precedence of operations [readability-math-missing-parentheses] +// CHECK-FIXES: int l = ((1 + 2) ^ 3); +int l = 1 + 2 ^ 3; + +// CHECK-MESSAGES: :[[@LINE+2]]:13: warning: add parantheses to clarify the precedence of operations [readability-math-missing-parentheses] +// CHECK-FIXES: int m = ((2 * foo()) + bar()); +int m = 2 * foo() + bar(); + +// CHECK-MESSAGES: :[[@LINE+2]]:13: warning: add parantheses to clarify the precedence of operations [readability-math-missing-parentheses] +// CHECK-FIXES: int n = ((1.05 * foo()) + double(bar())); +int n = 1.05 * foo() + double(bar()); + +// CHECK-MESSAGES: :[[@LINE+3]]:13: warning: add parantheses to clarify the precedence of operations [readability-math-missing-parentheses] +// CHECK-FIXES: int o = (1 + (obj.A * 3)) + obj.B; +fun obj; +int o = 1 + obj.A * 3 + obj.B; +} 11happy wrote: done https://github.com/llvm/llvm-project/pull/84481 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Add clang-tidy check readability-math-missing-parentheses (PR #84481)
@@ -0,0 +1,68 @@ +//===--- MathMissingParenthesesCheck.cpp - clang-tidy -===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "MathMissingParenthesesCheck.h" +#include "../utils/ASTUtils.h" +#include "clang/AST/ASTContext.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/Lex/Preprocessor.h" +#include "clang/Rewrite/Core/Rewriter.h" +#include +using namespace std; + +using namespace clang::ast_matchers; + +namespace clang::tidy::readability { + +void MathMissingParenthesesCheck::registerMatchers(MatchFinder *Finder) { + Finder->addMatcher(binaryOperator(unless(hasParent(binaryOperator())), +hasDescendant(binaryOperator())) + .bind("binOp"), + this); +} + +void addParantheses(const BinaryOperator *BinOp, clang::Rewriter &Rewrite, +const BinaryOperator *ParentBinOp, bool &NeedToDiagnose) { + if (!BinOp) +return; + if (ParentBinOp != nullptr && + ParentBinOp->getOpcode() != BinOp->getOpcode()) { +NeedToDiagnose = true; + } + clang::SourceLocation StartLoc = BinOp->getLHS()->getBeginLoc(); + clang::SourceLocation EndLoc = BinOp->getRHS()->getEndLoc(); + Rewrite.InsertText(StartLoc, "("); + Rewrite.InsertTextAfterToken(EndLoc, ")"); + addParantheses(dyn_cast(BinOp->getLHS()), Rewrite, BinOp, + NeedToDiagnose); + addParantheses(dyn_cast(BinOp->getRHS()), Rewrite, BinOp, + NeedToDiagnose); 11happy wrote: done https://github.com/llvm/llvm-project/pull/84481 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Add clang-tidy check readability-math-missing-parentheses (PR #84481)
@@ -0,0 +1,68 @@ +//===--- MathMissingParenthesesCheck.cpp - clang-tidy -===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "MathMissingParenthesesCheck.h" +#include "../utils/ASTUtils.h" +#include "clang/AST/ASTContext.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/Lex/Preprocessor.h" +#include "clang/Rewrite/Core/Rewriter.h" +#include +using namespace std; + +using namespace clang::ast_matchers; + +namespace clang::tidy::readability { + +void MathMissingParenthesesCheck::registerMatchers(MatchFinder *Finder) { + Finder->addMatcher(binaryOperator(unless(hasParent(binaryOperator())), +hasDescendant(binaryOperator())) + .bind("binOp"), + this); +} + +void addParantheses(const BinaryOperator *BinOp, clang::Rewriter &Rewrite, +const BinaryOperator *ParentBinOp, bool &NeedToDiagnose) { + if (!BinOp) +return; + if (ParentBinOp != nullptr && + ParentBinOp->getOpcode() != BinOp->getOpcode()) { +NeedToDiagnose = true; + } + clang::SourceLocation StartLoc = BinOp->getLHS()->getBeginLoc(); + clang::SourceLocation EndLoc = BinOp->getRHS()->getEndLoc(); 11happy wrote: done https://github.com/llvm/llvm-project/pull/84481 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Add clang-tidy check readability-math-missing-parentheses (PR #84481)
@@ -0,0 +1,68 @@ +//===--- MathMissingParenthesesCheck.cpp - clang-tidy -===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "MathMissingParenthesesCheck.h" +#include "../utils/ASTUtils.h" +#include "clang/AST/ASTContext.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/Lex/Preprocessor.h" +#include "clang/Rewrite/Core/Rewriter.h" +#include +using namespace std; 11happy wrote: done https://github.com/llvm/llvm-project/pull/84481 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Add clang-tidy check readability-math-missing-parentheses (PR #84481)
@@ -0,0 +1,68 @@ +//===--- MathMissingParenthesesCheck.cpp - clang-tidy -===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "MathMissingParenthesesCheck.h" +#include "../utils/ASTUtils.h" +#include "clang/AST/ASTContext.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/Lex/Preprocessor.h" 11happy wrote: done https://github.com/llvm/llvm-project/pull/84481 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Add clang-tidy check readability-math-missing-parentheses (PR #84481)
@@ -0,0 +1,68 @@ +//===--- MathMissingParenthesesCheck.cpp - clang-tidy -===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "MathMissingParenthesesCheck.h" +#include "../utils/ASTUtils.h" 11happy wrote: done https://github.com/llvm/llvm-project/pull/84481 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Add clang-tidy check readability-math-missing-parentheses (PR #84481)
@@ -0,0 +1,68 @@ +//===--- MathMissingParenthesesCheck.cpp - clang-tidy -===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "MathMissingParenthesesCheck.h" +#include "../utils/ASTUtils.h" +#include "clang/AST/ASTContext.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/Lex/Preprocessor.h" +#include "clang/Rewrite/Core/Rewriter.h" +#include +using namespace std; + +using namespace clang::ast_matchers; + +namespace clang::tidy::readability { + +void MathMissingParenthesesCheck::registerMatchers(MatchFinder *Finder) { + Finder->addMatcher(binaryOperator(unless(hasParent(binaryOperator())), +hasDescendant(binaryOperator())) 11happy wrote: I agree with you should be restricted to `+-*/%` https://github.com/llvm/llvm-project/pull/84481 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-repl] Fix assertion failure in CleanUpPTU() (PR #85378)
https://github.com/weliveindetail created https://github.com/llvm/llvm-project/pull/85378 This assertion failure is one (fortunate) symptom: ``` clang/include/clang/AST/DeclBase.h:1337: reference clang::DeclListNode::iterator::operator*() const: Assertion `Ptr && "dereferencing end() iterator"' failed. ``` Using `remove()` from `DeclContext::lookup_result` list invalidates iterators. It can't be used while iterating. From 6fbd6e36133af7af008c84a1a2e44c243aed26be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Gr=C3=A4nitz?= Date: Fri, 15 Mar 2024 11:01:09 +0100 Subject: [PATCH] [clang-repl] Fix assertion failure in CleanUpPTU() `remove()` from `DeclContext::lookup_result` list invalidates iterators. This assertion failure is one symptom: ``` clang/include/clang/AST/DeclBase.h:1337: reference clang::DeclListNode::iterator::operator*() const: Assertion `Ptr && "dereferencing end() iterator"' failed. ``` --- clang/lib/Interpreter/IncrementalParser.cpp | 19 +-- 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/clang/lib/Interpreter/IncrementalParser.cpp b/clang/lib/Interpreter/IncrementalParser.cpp index 370bcbfee8b014..fdb7b686ecfdcc 100644 --- a/clang/lib/Interpreter/IncrementalParser.cpp +++ b/clang/lib/Interpreter/IncrementalParser.cpp @@ -13,6 +13,7 @@ #include "IncrementalParser.h" #include "clang/AST/DeclContextInternals.h" +#include "clang/AST/DeclarationName.h" #include "clang/CodeGen/BackendUtil.h" #include "clang/CodeGen/CodeGenAction.h" #include "clang/CodeGen/ModuleBuilder.h" @@ -375,16 +376,22 @@ void IncrementalParser::CleanUpPTU(PartialTranslationUnit &PTU) { TranslationUnitDecl *MostRecentTU = PTU.TUPart; TranslationUnitDecl *FirstTU = MostRecentTU->getFirstDecl(); if (StoredDeclsMap *Map = FirstTU->getPrimaryContext()->getLookupPtr()) { -for (auto I = Map->begin(); I != Map->end(); ++I) { - StoredDeclsList &List = I->second; +for (auto &&[Key, List] : *Map) { DeclContextLookupResult R = List.getLookupResult(); + std::vector NamedDeclsToRemove; + bool RemoveAll = true; for (NamedDecl *D : R) { -if (D->getTranslationUnitDecl() == MostRecentTU) { +if (D->getTranslationUnitDecl() == MostRecentTU) + NamedDeclsToRemove.push_back(D); +else + RemoveAll = false; + } + if (LLVM_LIKELY(RemoveAll)) { +Map->erase(Key); + } else { +for (NamedDecl *D : NamedDeclsToRemove) List.remove(D); -} } - if (List.isNull()) -Map->erase(I); } } } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-repl] Fix assertion failure in CleanUpPTU() (PR #85378)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Stefan Gränitz (weliveindetail) Changes This assertion failure is one (fortunate) symptom: ``` clang/include/clang/AST/DeclBase.h:1337: reference clang::DeclListNode::iterator::operator*() const: Assertion `Ptr && "dereferencing end() iterator"' failed. ``` Using `remove()` from `DeclContext::lookup_result` list invalidates iterators. It can't be used while iterating. --- Full diff: https://github.com/llvm/llvm-project/pull/85378.diff 1 Files Affected: - (modified) clang/lib/Interpreter/IncrementalParser.cpp (+13-6) ``diff diff --git a/clang/lib/Interpreter/IncrementalParser.cpp b/clang/lib/Interpreter/IncrementalParser.cpp index 370bcbfee8b014..fdb7b686ecfdcc 100644 --- a/clang/lib/Interpreter/IncrementalParser.cpp +++ b/clang/lib/Interpreter/IncrementalParser.cpp @@ -13,6 +13,7 @@ #include "IncrementalParser.h" #include "clang/AST/DeclContextInternals.h" +#include "clang/AST/DeclarationName.h" #include "clang/CodeGen/BackendUtil.h" #include "clang/CodeGen/CodeGenAction.h" #include "clang/CodeGen/ModuleBuilder.h" @@ -375,16 +376,22 @@ void IncrementalParser::CleanUpPTU(PartialTranslationUnit &PTU) { TranslationUnitDecl *MostRecentTU = PTU.TUPart; TranslationUnitDecl *FirstTU = MostRecentTU->getFirstDecl(); if (StoredDeclsMap *Map = FirstTU->getPrimaryContext()->getLookupPtr()) { -for (auto I = Map->begin(); I != Map->end(); ++I) { - StoredDeclsList &List = I->second; +for (auto &&[Key, List] : *Map) { DeclContextLookupResult R = List.getLookupResult(); + std::vector NamedDeclsToRemove; + bool RemoveAll = true; for (NamedDecl *D : R) { -if (D->getTranslationUnitDecl() == MostRecentTU) { +if (D->getTranslationUnitDecl() == MostRecentTU) + NamedDeclsToRemove.push_back(D); +else + RemoveAll = false; + } + if (LLVM_LIKELY(RemoveAll)) { +Map->erase(Key); + } else { +for (NamedDecl *D : NamedDeclsToRemove) List.remove(D); -} } - if (List.isNull()) -Map->erase(I); } } } `` https://github.com/llvm/llvm-project/pull/85378 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeGen] Allow memcpy replace with trivial auto var init (PR #84230)
https://github.com/antoniofrighetto updated https://github.com/llvm/llvm-project/pull/84230 >From 869f015ac440ff1885caf44abffe28cd6ebf0f13 Mon Sep 17 00:00:00 2001 From: Antonio Frighetto Date: Wed, 6 Mar 2024 23:49:40 +0100 Subject: [PATCH] [clang][CodeGen] Allow `memcpy` replace with trivial auto var init pattern When emitting the storage (or memory copy operations) for constant initializers, the decision whether to split a constant structure or array store into a sequence of field stores or to use `memcpy` is based upon the optimization level and the size of the initializer. In afe8b93ffdfef5d8879e1894b9d7dda40dee2b8d, we extended this by allowing constants to be split when the array (or struct) type does not match the type of data the address to the object (constant) is expected to contain. This may happen when `emitStoresForConstant` is called by `EmitAutoVarInit`, as the element type of the address gets shrunk. When this occurs, let the initializer be split into a bunch of stores only under `-ftrivial-auto-var-init=pattern`. Fixes: https://github.com/llvm/llvm-project/issues/84178. --- clang/lib/CodeGen/CGDecl.cpp | 43 ++- clang/test/CodeGen/aapcs-align.cpp| 4 +-- clang/test/CodeGen/aapcs64-align.cpp | 8 ++--- clang/test/CodeGen/attr-counted-by.c | 26 -- clang/test/CodeGenCXX/auto-var-init.cpp | 27 +++--- clang/test/CodeGenOpenCL/amdgpu-printf.cl | 9 + clang/test/OpenMP/bug54082.c | 4 +-- 7 files changed, 56 insertions(+), 65 deletions(-) diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp index dc42faf8dbb9fd..2ef5ed04af30b6 100644 --- a/clang/lib/CodeGen/CGDecl.cpp +++ b/clang/lib/CodeGen/CGDecl.cpp @@ -1242,27 +1242,38 @@ static void emitStoresForConstant(CodeGenModule &CGM, const VarDecl &D, return; } - // If the initializer is small, use a handful of stores. + // If the initializer is small or trivialAutoVarInit is set, use a handful of + // stores. + bool IsTrivialAutoVarInitPattern = + CGM.getContext().getLangOpts().getTrivialAutoVarInit() == + LangOptions::TrivialAutoVarInitKind::Pattern; if (shouldSplitConstantStore(CGM, ConstantSize)) { if (auto *STy = dyn_cast(Ty)) { - const llvm::StructLayout *Layout = - CGM.getDataLayout().getStructLayout(STy); - for (unsigned i = 0; i != constant->getNumOperands(); i++) { -CharUnits CurOff = CharUnits::fromQuantity(Layout->getElementOffset(i)); -Address EltPtr = Builder.CreateConstInBoundsByteGEP( -Loc.withElementType(CGM.Int8Ty), CurOff); -emitStoresForConstant(CGM, D, EltPtr, isVolatile, Builder, - constant->getAggregateElement(i), IsAutoInit); + if (STy == Loc.getElementType() || + (STy != Loc.getElementType() && IsTrivialAutoVarInitPattern)) { +const llvm::StructLayout *Layout = +CGM.getDataLayout().getStructLayout(STy); +for (unsigned i = 0; i != constant->getNumOperands(); i++) { + CharUnits CurOff = + CharUnits::fromQuantity(Layout->getElementOffset(i)); + Address EltPtr = Builder.CreateConstInBoundsByteGEP( + Loc.withElementType(CGM.Int8Ty), CurOff); + emitStoresForConstant(CGM, D, EltPtr, isVolatile, Builder, +constant->getAggregateElement(i), IsAutoInit); +} +return; } - return; } else if (auto *ATy = dyn_cast(Ty)) { - for (unsigned i = 0; i != ATy->getNumElements(); i++) { -Address EltPtr = Builder.CreateConstGEP( -Loc.withElementType(ATy->getElementType()), i); -emitStoresForConstant(CGM, D, EltPtr, isVolatile, Builder, - constant->getAggregateElement(i), IsAutoInit); + if (ATy == Loc.getElementType() || + (ATy != Loc.getElementType() && IsTrivialAutoVarInitPattern)) { +for (unsigned i = 0; i != ATy->getNumElements(); i++) { + Address EltPtr = Builder.CreateConstGEP( + Loc.withElementType(ATy->getElementType()), i); + emitStoresForConstant(CGM, D, EltPtr, isVolatile, Builder, +constant->getAggregateElement(i), IsAutoInit); +} +return; } - return; } } diff --git a/clang/test/CodeGen/aapcs-align.cpp b/clang/test/CodeGen/aapcs-align.cpp index 2886a32974b066..4f393d9e6b7f32 100644 --- a/clang/test/CodeGen/aapcs-align.cpp +++ b/clang/test/CodeGen/aapcs-align.cpp @@ -134,8 +134,8 @@ void g6() { f6m(1, 2, 3, 4, 5, s); } // CHECK: define{{.*}} void @g6 -// CHECK: call void @f6(i32 noundef 1, [4 x i32] [i32 6, i32 7, i32 0, i32 0]) -// CHECK: call void @f6m(i32 noundef 1, i32 noundef 2, i32 noundef 3, i32 noundef 4, i32 noundef 5, [4 x i32] [i32 6, i32 7, i32 0, i32 0]) +// CHECK: call void @f6(i32 noundef 1, [4 x i32] [i32 6, i32 7, i32 0, i32 undef]) +// CHE
[clang] [clang][CodeGen] Allow memcpy replace with trivial auto var init (PR #84230)
https://github.com/antoniofrighetto updated https://github.com/llvm/llvm-project/pull/84230 >From 3c006a4fbec11e7e8ccaadbf347484077597894f Mon Sep 17 00:00:00 2001 From: Antonio Frighetto Date: Wed, 6 Mar 2024 23:49:40 +0100 Subject: [PATCH] [clang][CodeGen] Allow `memcpy` replace with trivial auto var init When emitting the storage (or memory copy operations) for constant initializers, the decision whether to split a constant structure or array store into a sequence of field stores or to use `memcpy` is based upon the optimization level and the size of the initializer. In afe8b93ffdfef5d8879e1894b9d7dda40dee2b8d, we extended this by allowing constants to be split when the array (or struct) type does not match the type of data the address to the object (constant) is expected to contain. This may happen when `emitStoresForConstant` is called by `EmitAutoVarInit`, as the element type of the address gets shrunk. When this occurs, let the initializer be split into a bunch of stores only under `-ftrivial-auto-var-init=pattern`. Fixes: https://github.com/llvm/llvm-project/issues/84178. --- clang/lib/CodeGen/CGDecl.cpp | 43 ++- clang/test/CodeGen/aapcs-align.cpp| 4 +-- clang/test/CodeGen/aapcs64-align.cpp | 8 ++--- clang/test/CodeGen/attr-counted-by.c | 26 -- clang/test/CodeGenCXX/auto-var-init.cpp | 27 +++--- clang/test/CodeGenOpenCL/amdgpu-printf.cl | 9 + clang/test/OpenMP/bug54082.c | 4 +-- 7 files changed, 56 insertions(+), 65 deletions(-) diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp index dc42faf8dbb9fd..2ef5ed04af30b6 100644 --- a/clang/lib/CodeGen/CGDecl.cpp +++ b/clang/lib/CodeGen/CGDecl.cpp @@ -1242,27 +1242,38 @@ static void emitStoresForConstant(CodeGenModule &CGM, const VarDecl &D, return; } - // If the initializer is small, use a handful of stores. + // If the initializer is small or trivialAutoVarInit is set, use a handful of + // stores. + bool IsTrivialAutoVarInitPattern = + CGM.getContext().getLangOpts().getTrivialAutoVarInit() == + LangOptions::TrivialAutoVarInitKind::Pattern; if (shouldSplitConstantStore(CGM, ConstantSize)) { if (auto *STy = dyn_cast(Ty)) { - const llvm::StructLayout *Layout = - CGM.getDataLayout().getStructLayout(STy); - for (unsigned i = 0; i != constant->getNumOperands(); i++) { -CharUnits CurOff = CharUnits::fromQuantity(Layout->getElementOffset(i)); -Address EltPtr = Builder.CreateConstInBoundsByteGEP( -Loc.withElementType(CGM.Int8Ty), CurOff); -emitStoresForConstant(CGM, D, EltPtr, isVolatile, Builder, - constant->getAggregateElement(i), IsAutoInit); + if (STy == Loc.getElementType() || + (STy != Loc.getElementType() && IsTrivialAutoVarInitPattern)) { +const llvm::StructLayout *Layout = +CGM.getDataLayout().getStructLayout(STy); +for (unsigned i = 0; i != constant->getNumOperands(); i++) { + CharUnits CurOff = + CharUnits::fromQuantity(Layout->getElementOffset(i)); + Address EltPtr = Builder.CreateConstInBoundsByteGEP( + Loc.withElementType(CGM.Int8Ty), CurOff); + emitStoresForConstant(CGM, D, EltPtr, isVolatile, Builder, +constant->getAggregateElement(i), IsAutoInit); +} +return; } - return; } else if (auto *ATy = dyn_cast(Ty)) { - for (unsigned i = 0; i != ATy->getNumElements(); i++) { -Address EltPtr = Builder.CreateConstGEP( -Loc.withElementType(ATy->getElementType()), i); -emitStoresForConstant(CGM, D, EltPtr, isVolatile, Builder, - constant->getAggregateElement(i), IsAutoInit); + if (ATy == Loc.getElementType() || + (ATy != Loc.getElementType() && IsTrivialAutoVarInitPattern)) { +for (unsigned i = 0; i != ATy->getNumElements(); i++) { + Address EltPtr = Builder.CreateConstGEP( + Loc.withElementType(ATy->getElementType()), i); + emitStoresForConstant(CGM, D, EltPtr, isVolatile, Builder, +constant->getAggregateElement(i), IsAutoInit); +} +return; } - return; } } diff --git a/clang/test/CodeGen/aapcs-align.cpp b/clang/test/CodeGen/aapcs-align.cpp index 2886a32974b066..4f393d9e6b7f32 100644 --- a/clang/test/CodeGen/aapcs-align.cpp +++ b/clang/test/CodeGen/aapcs-align.cpp @@ -134,8 +134,8 @@ void g6() { f6m(1, 2, 3, 4, 5, s); } // CHECK: define{{.*}} void @g6 -// CHECK: call void @f6(i32 noundef 1, [4 x i32] [i32 6, i32 7, i32 0, i32 0]) -// CHECK: call void @f6m(i32 noundef 1, i32 noundef 2, i32 noundef 3, i32 noundef 4, i32 noundef 5, [4 x i32] [i32 6, i32 7, i32 0, i32 0]) +// CHECK: call void @f6(i32 noundef 1, [4 x i32] [i32 6, i32 7, i32 0, i32 undef]) +// CHECK: call
[clang] [llvm] [BPF] Add support for may_goto insn (PR #85358)
https://github.com/eddyz87 approved this pull request. https://github.com/llvm/llvm-project/pull/85358 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeGen] Allow memcpy replace with trivial auto var init (PR #84230)
antoniofrighetto wrote: @efriedma-quic, comment updated, thanks. https://github.com/llvm/llvm-project/pull/84230 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang][HLSL][SPRI-V] Add convergence intrinsics (PR #80680)
@@ -1295,11 +1295,13 @@ double4 trunc(double4); /// true, across all active lanes in the current wave. _HLSL_AVAILABILITY(shadermodel, 6.0) _HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_count_bits) +__attribute__((convergent)) Keenuts wrote: @llvm-beanz FYI. Seems like I'll remove it then. https://github.com/llvm/llvm-project/pull/80680 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AMDGPU] Enable OpenCL hostcall printf (WIP) (PR #72556)
@@ -3616,6 +3617,12 @@ unsigned FunctionDecl::getBuiltinID(bool ConsiderWrapperFunctions) const { if (!ConsiderWrapperFunctions && getStorageClass() == SC_Static) return 0; + // AMDGCN implementation supports printf as a builtin + // for OpenCL + if (Context.getTargetInfo().getTriple().isAMDGCN() && + Context.getLangOpts().OpenCL && BuiltinID == AMDGPU::BIprintf) +return BuiltinID; vikramRH wrote: ping @arsenm https://github.com/llvm/llvm-project/pull/72556 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 5334afc - [clang][Interp] Don't forget to visit condition variable decls
Author: Timm Bäder Date: 2024-03-15T12:30:37+01:00 New Revision: 5334afcad827a6284ff56f5bde81d4e3416aae8c URL: https://github.com/llvm/llvm-project/commit/5334afcad827a6284ff56f5bde81d4e3416aae8c DIFF: https://github.com/llvm/llvm-project/commit/5334afcad827a6284ff56f5bde81d4e3416aae8c.diff LOG: [clang][Interp] Don't forget to visit condition variable decls We did this for if statements, but switch and loop constructs need to do it as well. Added: Modified: clang/lib/AST/Interp/ByteCodeStmtGen.cpp clang/test/SemaCXX/decomposed-condition.cpp Removed: diff --git a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp index b9e8e6a77a7205..675063e7489886 100644 --- a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp @@ -423,6 +423,11 @@ bool ByteCodeStmtGen::visitWhileStmt(const WhileStmt *S) { LoopScope LS(this, EndLabel, CondLabel); this->emitLabel(CondLabel); + + if (const DeclStmt *CondDecl = S->getConditionVariableDeclStmt()) +if (!visitDeclStmt(CondDecl)) + return false; + if (!this->visitBool(Cond)) return false; if (!this->jumpFalse(EndLabel)) @@ -487,6 +492,10 @@ bool ByteCodeStmtGen::visitForStmt(const ForStmt *S) { if (Init && !this->visitStmt(Init)) return false; this->emitLabel(CondLabel); + + if (const DeclStmt *CondDecl = S->getConditionVariableDeclStmt()) +if (!visitDeclStmt(CondDecl)) + return false; if (Cond) { if (!this->visitBool(Cond)) return false; @@ -585,17 +594,21 @@ bool ByteCodeStmtGen::visitContinueStmt(const ContinueStmt *S) { template bool ByteCodeStmtGen::visitSwitchStmt(const SwitchStmt *S) { const Expr *Cond = S->getCond(); - PrimType CondT = this->classifyPrim(Cond->getType()); LabelTy EndLabel = this->getLabel(); OptLabelTy DefaultLabel = std::nullopt; - unsigned CondVar = this->allocateLocalPrimitive(Cond, CondT, true, false); if (const auto *CondInit = S->getInit()) if (!visitStmt(CondInit)) return false; + if (const DeclStmt *CondDecl = S->getConditionVariableDeclStmt()) +if (!visitDeclStmt(CondDecl)) + return false; + // Initialize condition variable. + PrimType CondT = this->classifyPrim(Cond->getType()); + unsigned CondVar = this->allocateLocalPrimitive(Cond, CondT, true, false); if (!this->visit(Cond)) return false; if (!this->emitSetLocal(CondT, CondVar, S)) diff --git a/clang/test/SemaCXX/decomposed-condition.cpp b/clang/test/SemaCXX/decomposed-condition.cpp index ab011f6ae4ba43..e55bbee3134ca2 100644 --- a/clang/test/SemaCXX/decomposed-condition.cpp +++ b/clang/test/SemaCXX/decomposed-condition.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -std=c++1z -Wno-binding-in-condition -verify %s +// RUN: %clang_cc1 -std=c++1z -Wno-binding-in-condition -verify %s -fexperimental-new-constant-interpreter struct X { bool flag; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CLANG] Full support of complex multiplication and division. (PR #81514)
@@ -1046,30 +1046,35 @@ defm offload_uniform_block : BoolFOption<"offload-uniform-block", NegFlag, BothFlags<[], [ClangOption], " that kernels are launched with uniform block sizes (default true for CUDA/HIP and false otherwise)">>; -def fcx_limited_range : Joined<["-"], "fcx-limited-range">, +def fcomplex_arithmetic_EQ : Joined<["-"], "fcomplex-arithmetic=">, Group, + Visibility<[ClangOption, CC1Option]>, + Values<"full,improved,promoted,basic">, NormalizedValuesScope<"LangOptions">, + NormalizedValues<["CX_Full", "CX_Improved", "CX_Promoted", "CX_Basic"]>; + +def complex_range_EQ : Joined<["-"], "complex-range=">, Group, + Visibility<[CC1Option]>, + Values<"full,improved,promoted,basic">, NormalizedValuesScope<"LangOptions">, + NormalizedValues<["CX_Full", "CX_Improved", "CX_Promoted", "CX_Basic"]>, + MarshallingInfoEnum, "CX_Full">; + +def fcx_limited_range : Flag<["-"], "fcx-limited-range">, Group, Visibility<[ClangOption, CC1Option]>, HelpText<"Basic algebraic expansions of complex arithmetic operations " "involving are enabled.">; -def fno_cx_limited_range : Joined<["-"], "fno-cx-limited-range">, +def fno_cx_limited_range : Flag<["-"], "fno-cx-limited-range">, Group, Visibility<[ClangOption, CC1Option]>, HelpText<"Basic algebraic expansions of complex arithmetic operations " "involving are disabled.">; -def fcx_fortran_rules : Joined<["-"], "fcx-fortran-rules">, +def fcx_fortran_rules : Flag<["-"], "fcx-fortran-rules">, Group, Visibility<[ClangOption, CC1Option]>, HelpText<"Range reduction is enabled for complex arithmetic operations.">; -def fno_cx_fortran_rules : Joined<["-"], "fno-cx-fortran-rules">, +def fno_cx_fortran_rules : Flag<["-"], "fno-cx-fortran-rules">, zahiraam wrote: Can `BoolOptionWithoutMarshalling` be used for clang options? https://github.com/llvm/llvm-project/pull/81514 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
https://github.com/dtemirbulatov updated https://github.com/llvm/llvm-project/pull/79842 >From af323998a63a72f569d543cf5167d5d28e784682 Mon Sep 17 00:00:00 2001 From: Dinar Temirbulatov Date: Mon, 29 Jan 2024 14:43:13 + Subject: [PATCH 01/10] [Clang][AArch64] Warn when calling streaming/non-streaming about vector size might be different. The compiler doesn't know in advance if the streaming and non-streaming vector-lengths are different, so it should be safe to give a warning diagnostic to warn the user about possible undefined behaviour. If the user knows the vector lengths are equal, they can disable the warning separately. --- .../clang/Basic/DiagnosticSemaKinds.td| 24 +++ clang/lib/Sema/SemaChecking.cpp | 42 clang/test/Sema/aarch64-sme-func-attrs.c | 68 ++- 3 files changed, 132 insertions(+), 2 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 24d32cb87c89e2..37fea5746936c7 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -3717,6 +3717,30 @@ def err_sme_definition_using_za_in_non_sme_target : Error< "function using ZA state requires 'sme'">; def err_sme_definition_using_zt0_in_non_sme2_target : Error< "function using ZT0 state requires 'sme2'">; +def warn_sme_streaming_caller_pass_args_to_non_streaming : Warning< + "streaming caller passes a VL-dependent argument to non-streaming callee, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_non_streaming_callee_returns_to_streaming : Warning< + "non-streaming callee returns a VL-dependent value to streaming caller, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_non_streaming_caller_pass_args_to_streaming : Warning< + "non-streaming caller passes a VL-dependent argument to streaming callee, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_non_streaming_caller_returns_to_streaming : Warning< + "non-streaming callee returns a VL-dependent value to streaming caller, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_locally_streaming_has_vl_args : Warning< + "non-streaming callee receives a VL-dependent argument and the callee has an arm_locally_streaming attribute, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_locally_streaming_returns_vl : Warning< + "non-streaming callee returns a VL-dependent value and the callee has an arm_locally_streaming attribute, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; def err_conflicting_attributes_arm_state : Error< "conflicting attributes for state '%0'">; def err_unknown_arm_state : Error< diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 502b24bcdf8b42..e668a45c69e5f9 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -7480,6 +7480,7 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, // For variadic functions, we may have more args than parameters. // For some K&R functions, we may have less args than parameters. const auto N = std::min(Proto->getNumParams(), Args.size()); +bool AnyScalableArgs = false; for (unsigned ArgIdx = 0; ArgIdx < N; ++ArgIdx) { // Args[ArgIdx] can be null in malformed code. if (const Expr *Arg = Args[ArgIdx]) { @@ -7493,6 +7494,8 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, checkAIXMemberAlignment((Arg->getExprLoc()), Arg); QualType ParamTy = Proto->getParamType(ArgIdx); +if (ParamTy->isSizelessVectorType()) + AnyScalableArgs = true; QualType ArgTy = Arg->getType(); CheckArgAlignment(Arg->getExprLoc(), FDecl, std::to_string(ArgIdx + 1), ArgTy, ParamTy); @@ -7513,6 +7516,45 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, } } +auto *CallerFD = dyn_cast(CurContext); +if (FD && CallerFD && Context.getTargetInfo().hasFeature("sme") && +!FD->getBuiltinID()) { + // If the callee has an AArch64 SME __arm_locally_streaming attribute + // warn if this function returns VL-based value or pass any such argument, + // the streaming and non-streaming vector lengths may be different. + ArmStreamingType CalleeFnType = getArmStreamingFnType(FD); + ArmStreamingType CallerFnType = getArmStreamingFnType(CallerFD); + if (FD->hasAttr() && + CallerFnType != ArmStreaming) { +if (AnyScalableArgs) + Diag(Loc, diag::warn_sme_locally_streaming_has_vl_args); +if (FD->getReturnType()->isSizelessVectorType()) + Diag(Loc, diag::wa
[clang] [clang-repl] Fix assertion failure in CleanUpPTU() (PR #85378)
vgvassilev wrote: Nice catch! Any chance for having a test? https://github.com/llvm/llvm-project/pull/85378 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [X86_64] fix empty structure vaarg in c++ (PR #77907)
https://github.com/hstk30-hw updated https://github.com/llvm/llvm-project/pull/77907 >From 75eb445f153d2391a8980716f36be77ed2fb24ed Mon Sep 17 00:00:00 2001 From: Longsheng Mou Date: Fri, 12 Jan 2024 18:24:08 +0800 Subject: [PATCH] [X86_64] fix empty structure vaarg in c++ SizeInBytes of empty structure is 0 in C, while 1 in C++. And empty structure argument of the function is ignored in X86_64 backend.As a result, the value of variable arguments in C++ is incorrect.So we should just make a temporary and return its address. --- clang/lib/CodeGen/Targets/X86.cpp | 5 + clang/test/CodeGenCXX/x86_64-vaarg.cpp | 12 2 files changed, 17 insertions(+) create mode 100644 clang/test/CodeGenCXX/x86_64-vaarg.cpp diff --git a/clang/lib/CodeGen/Targets/X86.cpp b/clang/lib/CodeGen/Targets/X86.cpp index d053f41ab168f5..c5c66bb425628a 100644 --- a/clang/lib/CodeGen/Targets/X86.cpp +++ b/clang/lib/CodeGen/Targets/X86.cpp @@ -3014,6 +3014,11 @@ Address X86_64ABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAListAddr, ABIArgInfo AI = classifyArgumentType(Ty, 0, neededInt, neededSSE, /*isNamedArg*/false); + // Empty records are ignored for parameter passing purposes. + if (AI.isIgnore()) { +return CGF.CreateMemTemp(Ty); + } + // AMD64-ABI 3.5.7p5: Step 1. Determine whether type may be passed // in the registers. If not go to step 7. if (!neededInt && !neededSSE) diff --git a/clang/test/CodeGenCXX/x86_64-vaarg.cpp b/clang/test/CodeGenCXX/x86_64-vaarg.cpp new file mode 100644 index 00..4d77a5c89455cd --- /dev/null +++ b/clang/test/CodeGenCXX/x86_64-vaarg.cpp @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %s | FileCheck %s + +typedef struct { struct {} a; } empty; + +// CHECK-LABEL: define{{.*}} void @_Z17empty_record_testv() +empty empty_record_test(void) { +// CHECK: [[RET:%[a-z]+]] = alloca %struct.empty, align 1 +// CHECK: [[TMP:%[a-z]+]] = alloca %struct.empty, align 1 +// CHECK: call void @llvm.memcpy{{.*}}(ptr align 1 [[RET]], ptr align 1 [[TMP]] + __builtin_va_list list; + return __builtin_va_arg(list, empty); +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-repl] Fix assertion failure in CleanUpPTU() (PR #85378)
weliveindetail wrote: I can reproduce it downstream in the implicit Undo after including a header that causes a lot of parse errors in nested headers. I am afraid it's unpractical to emulate in the test suite upstream. The code is exercised in all Undo tests. They don't reproduce the issue right now, but it's just a matter of likeliness. I think this fix is fine without an additional test. https://github.com/llvm/llvm-project/pull/85378 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-repl] Fix assertion failure in CleanUpPTU() (PR #85378)
vgvassilev wrote: Okay, sounds fair. https://github.com/llvm/llvm-project/pull/85378 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-repl] Fix assertion failure in CleanUpPTU() (PR #85378)
https://github.com/vgvassilev approved this pull request. Thank you! https://github.com/llvm/llvm-project/pull/85378 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang][HLSL][SPRI-V] Add convergence intrinsics (PR #80680)
https://github.com/Keenuts updated https://github.com/llvm/llvm-project/pull/80680 From 818ccfd0258602fdd0630823bb2b8af0507749d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nathan=20Gau=C3=ABr?= Date: Fri, 2 Feb 2024 16:38:46 +0100 Subject: [PATCH 1/7] [clang][HLSL][SPRI-V] Add convergence intrinsics MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit HLSL has wave operations and other kind of function which required the control flow to either be converged, or respect certain constraints as where and how to re-converge. At the HLSL level, the convergence are mostly obvious: the control flow is expected to re-converge at the end of a scope. Once translated to IR, HLSL scopes disapear. This means we need a way to communicate convergence restrictions down to the backend. For this, the SPIR-V backend uses convergence intrinsics. So this commit adds some code to generate convergence intrinsics when required. This commit is not to be submitted as-is (lacks testing), but should serve as a basis for an upcoming RFC. Signed-off-by: Nathan Gauër --- clang/lib/CodeGen/CGBuiltin.cpp | 102 +++ clang/lib/CodeGen/CGCall.cpp | 4 ++ clang/lib/CodeGen/CGLoopInfo.h | 8 ++- clang/lib/CodeGen/CodeGenFunction.h | 19 + llvm/include/llvm/IR/IntrinsicInst.h | 13 5 files changed, 145 insertions(+), 1 deletion(-) diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 20c35757939152..ba5e27a5d4668c 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -1130,8 +1130,97 @@ struct BitTest { static BitTest decodeBitTestBuiltin(unsigned BuiltinID); }; + +// Returns the first convergence entry/loop/anchor instruction found in |BB|. +// std::nullopt otherwise. +std::optional getConvergenceToken(llvm::BasicBlock *BB) { + for (auto &I : *BB) { +auto *II = dyn_cast(&I); +if (II && isConvergenceControlIntrinsic(II->getIntrinsicID())) + return II; + } + return std::nullopt; +} + } // namespace +llvm::CallBase * +CodeGenFunction::AddConvergenceControlAttr(llvm::CallBase *Input, + llvm::Value *ParentToken) { + llvm::Value *bundleArgs[] = {ParentToken}; + llvm::OperandBundleDef OB("convergencectrl", bundleArgs); + auto Output = llvm::CallBase::addOperandBundle( + Input, llvm::LLVMContext::OB_convergencectrl, OB, Input); + Input->replaceAllUsesWith(Output); + Input->eraseFromParent(); + return Output; +} + +llvm::IntrinsicInst * +CodeGenFunction::EmitConvergenceLoop(llvm::BasicBlock *BB, + llvm::Value *ParentToken) { + CGBuilderTy::InsertPoint IP = Builder.saveIP(); + Builder.SetInsertPoint(&BB->front()); + auto CB = Builder.CreateIntrinsic( + llvm::Intrinsic::experimental_convergence_loop, {}, {}); + Builder.restoreIP(IP); + + auto I = AddConvergenceControlAttr(CB, ParentToken); + // Controlled convergence is incompatible with uncontrolled convergence. + // Removing any old attributes. + I->setNotConvergent(); + + assert(isa(I)); + return dyn_cast(I); +} + +llvm::IntrinsicInst * +CodeGenFunction::getOrEmitConvergenceEntryToken(llvm::Function *F) { + auto *BB = &F->getEntryBlock(); + auto token = getConvergenceToken(BB); + if (token.has_value()) +return token.value(); + + // Adding a convergence token requires the function to be marked as + // convergent. + F->setConvergent(); + + CGBuilderTy::InsertPoint IP = Builder.saveIP(); + Builder.SetInsertPoint(&BB->front()); + auto I = Builder.CreateIntrinsic( + llvm::Intrinsic::experimental_convergence_entry, {}, {}); + assert(isa(I)); + Builder.restoreIP(IP); + + return dyn_cast(I); +} + +llvm::IntrinsicInst * +CodeGenFunction::getOrEmitConvergenceLoopToken(const LoopInfo *LI) { + assert(LI != nullptr); + + auto token = getConvergenceToken(LI->getHeader()); + if (token.has_value()) +return *token; + + llvm::IntrinsicInst *PII = + LI->getParent() + ? EmitConvergenceLoop(LI->getHeader(), +getOrEmitConvergenceLoopToken(LI->getParent())) + : getOrEmitConvergenceEntryToken(LI->getHeader()->getParent()); + + return EmitConvergenceLoop(LI->getHeader(), PII); +} + +llvm::CallBase * +CodeGenFunction::AddControlledConvergenceAttr(llvm::CallBase *Input) { + llvm::Value *ParentToken = + LoopStack.hasInfo() + ? getOrEmitConvergenceLoopToken(&LoopStack.getInfo()) + : getOrEmitConvergenceEntryToken(Input->getFunction()); + return AddConvergenceControlAttr(Input, ParentToken); +} + BitTest BitTest::decodeBitTestBuiltin(unsigned BuiltinID) { switch (BuiltinID) { // Main portable variants. @@ -5698,6 +5787,19 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, {NDRange, Kernel, Block})); } + case Builtin::BI__builtin_hlsl_wave_active_count_bits: { +llvm::Typ
[clang] [clang] Better bitfield access units (PR #65742)
@@ -439,82 +444,194 @@ CGRecordLowering::accumulateBitFields(RecordDecl::field_iterator Field, Members.push_back(MemberInfo(bitsToCharUnits(StartBitOffset), MemberInfo::Field, nullptr, *Field)); } -return; +return Field; } - // Check if OffsetInRecord (the size in bits of the current run) is better - // as a single field run. When OffsetInRecord has legal integer width, and - // its bitfield offset is naturally aligned, it is better to make the - // bitfield a separate storage component so as it can be accessed directly - // with lower cost. - auto IsBetterAsSingleFieldRun = [&](uint64_t OffsetInRecord, - uint64_t StartBitOffset) { -if (!Types.getCodeGenOpts().FineGrainedBitfieldAccesses) - return false; -if (OffsetInRecord < 8 || !llvm::isPowerOf2_64(OffsetInRecord) || -!DataLayout.fitsInLegalInteger(OffsetInRecord)) - return false; -// Make sure StartBitOffset is naturally aligned if it is treated as an -// IType integer. -if (StartBitOffset % -Context.toBits(getAlignment(getIntNType(OffsetInRecord))) != -0) - return false; -return true; - }; + // The SysV ABI can overlap bitfield storage units with both other bitfield + // storage units /and/ other non-bitfield data members. Accessing a sequence + // of bitfields mustn't interfere with adjacent non-bitfields -- they're + // permitted to be accessed in separate threads for instance. + + // We split runs of bit-fields into a sequence of "access units". When we emit + // a load or store of a bit-field, we'll load/store the entire containing + // access unit. As mentioned, the standard requires that these loads and + // stores must not interfere with accesses to other memory locations, and it + // defines the bit-field's memory location as the current run of + // non-zero-width bit-fields. So an access unit must never overlap with + // non-bit-field storage or cross a zero-width bit-field. Otherwise, we're + // free to draw the lines as we see fit. + + // Drawing these lines well can be complicated. LLVM generally can't modify a + // program to access memory that it didn't before, so using very narrow access + // units can prevent the compiler from using optimal access patterns. For + // example, suppose a run of bit-fields occupies four bytes in a struct. If we + // split that into four 1-byte access units, then a sequence of assignments + // that doesn't touch all four bytes may have to be emitted with multiple + // 8-bit stores instead of a single 32-bit store. On the other hand, if we use + // very wide access units, we may find ourselves emitting accesses to + // bit-fields we didn't really need to touch, just because LLVM was unable to + // clean up after us. + + // It is desirable to have access units be aligned powers of 2 no larger than + // a register. (On non-strict alignment ISAs, the alignment requirement can be + // dropped.) A three byte access unit will be accessed using 2-byte and 1-byte + // accesses and bit manipulation. If no bitfield straddles across the two + // separate accesses, it is better to have separate 2-byte and 1-byte access + // units, as then LLVM will not generate unnecessary memory accesses, or bit + // manipulation. Similarly, on a strict-alignment architecture, it is better + // to keep access-units naturally aligned, to avoid similar bit + // manipulation synthesizing larger unaligned accesses. + + // We do this in two phases, processing a sequential run of bitfield + // declarations. + + // a) Bitfields that share parts of a single byte are, of necessity, placed in + // the same access unit. That unit will encompass a consecutive + // run where adjacent bitfields share parts of a byte. (The first bitfield of + // such an access unit will start at the beginning of a byte.) + + // b) Accumulate adjacent access units when the combined unit is naturally + // sized, no larger than a register, and on a strict alignment ISA, + // aligned. Note that this requires lookahead to one or more subsequent access + // units. For instance, consider a 2-byte access-unit followed by 2 1-byte + // units. We can merge that into a 4-byte access-unit, but we would not want + // to merge a 2-byte followed by a single 1-byte (and no available tail + // padding). + + // This accumulation is prevented when: + // *) it would cross a zero-width bitfield (ABI-dependent), or + // *) one of the candidate access units contains a volatile bitfield, or + // *) fine-grained bitfield access option is in effect. + + CharUnits RegSize = + bitsToCharUnits(Context.getTargetInfo().getRegisterWidth()); + unsigned CharBits = Context.getCharWidth(); + + RecordDecl::field_iterator Begin = FieldEnd; + CharUnits StartOffset; + uint64_t BitSize; + CharUnits BestEndOffset; + RecordDecl::field_iterator BestEnd = B
[clang] [CLANG] Full support of complex multiplication and division. (PR #81514)
@@ -794,8 +834,10 @@ ComplexPairTy ComplexExprEmitter::EmitBinMul(const BinOpInfo &Op) { ResR = Builder.CreateFSub(AC, BD, "mul_r"); ResI = Builder.CreateFAdd(AD, BC, "mul_i"); - if (Op.FPFeatures.getComplexRange() == LangOptions::CX_Limited || - Op.FPFeatures.getComplexRange() == LangOptions::CX_Fortran) + if (Op.FPFeatures.getComplexRange() == LangOptions::CX_Basic || + Op.FPFeatures.getComplexRange() == LangOptions::CX_Improved || + Op.FPFeatures.getComplexRange() == LangOptions::CX_Promoted || + CGF.getLangOpts().NoHonorInfs || CGF.getLangOpts().NoHonorNaNs) zahiraam wrote: This code is in `EmitBinMul` and your `godbolt` link has a `div` operation. At any case the `complex-range` is **not** set when `-ffinite-math-only` is used on the command line. The function `applyFastMath` sets the range only when `ffast-math` or `fp-model` are used. With `CGF.getLangOpts().NoHonorInfs || CGF.getLangOpts().NoHonorNaNs` we would get the same behavior than `gcc` for a` mul` operation: algebraic implementation with no `nan` testing. If you don't want this condition here. then `applyFastMath` needs to be called when `ffinite-math-only` is on the command line. WDYT? https://github.com/llvm/llvm-project/pull/81514 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-repl] Fix assertion failure in CleanUpPTU() (PR #85378)
https://github.com/weliveindetail updated https://github.com/llvm/llvm-project/pull/85378 From 6fbd6e36133af7af008c84a1a2e44c243aed26be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Gr=C3=A4nitz?= Date: Fri, 15 Mar 2024 11:01:09 +0100 Subject: [PATCH 1/2] [clang-repl] Fix assertion failure in CleanUpPTU() `remove()` from `DeclContext::lookup_result` list invalidates iterators. This assertion failure is one symptom: ``` clang/include/clang/AST/DeclBase.h:1337: reference clang::DeclListNode::iterator::operator*() const: Assertion `Ptr && "dereferencing end() iterator"' failed. ``` --- clang/lib/Interpreter/IncrementalParser.cpp | 19 +-- 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/clang/lib/Interpreter/IncrementalParser.cpp b/clang/lib/Interpreter/IncrementalParser.cpp index 370bcbfee8b014..fdb7b686ecfdcc 100644 --- a/clang/lib/Interpreter/IncrementalParser.cpp +++ b/clang/lib/Interpreter/IncrementalParser.cpp @@ -13,6 +13,7 @@ #include "IncrementalParser.h" #include "clang/AST/DeclContextInternals.h" +#include "clang/AST/DeclarationName.h" #include "clang/CodeGen/BackendUtil.h" #include "clang/CodeGen/CodeGenAction.h" #include "clang/CodeGen/ModuleBuilder.h" @@ -375,16 +376,22 @@ void IncrementalParser::CleanUpPTU(PartialTranslationUnit &PTU) { TranslationUnitDecl *MostRecentTU = PTU.TUPart; TranslationUnitDecl *FirstTU = MostRecentTU->getFirstDecl(); if (StoredDeclsMap *Map = FirstTU->getPrimaryContext()->getLookupPtr()) { -for (auto I = Map->begin(); I != Map->end(); ++I) { - StoredDeclsList &List = I->second; +for (auto &&[Key, List] : *Map) { DeclContextLookupResult R = List.getLookupResult(); + std::vector NamedDeclsToRemove; + bool RemoveAll = true; for (NamedDecl *D : R) { -if (D->getTranslationUnitDecl() == MostRecentTU) { +if (D->getTranslationUnitDecl() == MostRecentTU) + NamedDeclsToRemove.push_back(D); +else + RemoveAll = false; + } + if (LLVM_LIKELY(RemoveAll)) { +Map->erase(Key); + } else { +for (NamedDecl *D : NamedDeclsToRemove) List.remove(D); -} } - if (List.isNull()) -Map->erase(I); } } } From fe92a1ce9bebc055d35ce91d92579e013225cc1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Gr=C3=A4nitz?= Date: Fri, 15 Mar 2024 13:46:35 +0100 Subject: [PATCH 2/2] Remove unused include and fix related comment (NFC) --- clang/include/clang/AST/DeclContextInternals.h | 2 +- clang/lib/Interpreter/IncrementalParser.cpp| 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/clang/include/clang/AST/DeclContextInternals.h b/clang/include/clang/AST/DeclContextInternals.h index 903cdb7bfcc822..c4734ab5789538 100644 --- a/clang/include/clang/AST/DeclContextInternals.h +++ b/clang/include/clang/AST/DeclContextInternals.h @@ -205,7 +205,7 @@ class StoredDeclsList { Data.setPointer(Head); } - /// Return an array of all the decls that this list represents. + /// Return the list of all the decls. DeclContext::lookup_result getLookupResult() const { return DeclContext::lookup_result(Data.getPointer()); } diff --git a/clang/lib/Interpreter/IncrementalParser.cpp b/clang/lib/Interpreter/IncrementalParser.cpp index fdb7b686ecfdcc..5eec2a2fd6d1a6 100644 --- a/clang/lib/Interpreter/IncrementalParser.cpp +++ b/clang/lib/Interpreter/IncrementalParser.cpp @@ -13,7 +13,6 @@ #include "IncrementalParser.h" #include "clang/AST/DeclContextInternals.h" -#include "clang/AST/DeclarationName.h" #include "clang/CodeGen/BackendUtil.h" #include "clang/CodeGen/CodeGenAction.h" #include "clang/CodeGen/ModuleBuilder.h" ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [NVPTX] Add `-march=general` option to mirror default configuration (PR #85222)
https://github.com/jhuber6 approved this pull request. LG, thanks for the patch. https://github.com/llvm/llvm-project/pull/85222 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-repl] Fix assertion failure in CleanUpPTU() (PR #85378)
https://github.com/weliveindetail edited https://github.com/llvm/llvm-project/pull/85378 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-repl] Fix assertion failure in CleanUpPTU() (PR #85378)
https://github.com/weliveindetail commented: Two minor remarks https://github.com/llvm/llvm-project/pull/85378 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-repl] Fix assertion failure in CleanUpPTU() (PR #85378)
@@ -375,16 +375,22 @@ void IncrementalParser::CleanUpPTU(PartialTranslationUnit &PTU) { TranslationUnitDecl *MostRecentTU = PTU.TUPart; TranslationUnitDecl *FirstTU = MostRecentTU->getFirstDecl(); if (StoredDeclsMap *Map = FirstTU->getPrimaryContext()->getLookupPtr()) { -for (auto I = Map->begin(); I != Map->end(); ++I) { - StoredDeclsList &List = I->second; +for (auto &&[Key, List] : *Map) { DeclContextLookupResult R = List.getLookupResult(); + std::vector NamedDeclsToRemove; + bool RemoveAll = true; for (NamedDecl *D : R) { -if (D->getTranslationUnitDecl() == MostRecentTU) { +if (D->getTranslationUnitDecl() == MostRecentTU) + NamedDeclsToRemove.push_back(D); +else + RemoveAll = false; + } + if (LLVM_LIKELY(RemoveAll)) { +Map->erase(Key); + } else { +for (NamedDecl *D : NamedDeclsToRemove) List.remove(D); weliveindetail wrote: BTW it would have been nice to use `llvm::remove_if`, but the iterator doesn't support assignment unfortunately. https://github.com/llvm/llvm-project/pull/85378 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-repl] Fix assertion failure in CleanUpPTU() (PR #85378)
@@ -205,7 +205,7 @@ class StoredDeclsList { Data.setPointer(Head); } - /// Return an array of all the decls that this list represents. + /// Return the list of all the decls. weliveindetail wrote: This is not an array (otherwise we could have done erase-remove) https://github.com/llvm/llvm-project/pull/85378 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [X86_64] fix arg pass error in struct. (PR #85394)
https://github.com/CoTinker created https://github.com/llvm/llvm-project/pull/85394 typedef long long Alignll __attribute__((align (4))); struct S { int a; Alignll b; }; When classify: a: Lo = Integer, Hi = NoClass b: Lo = Integer, Hi = NoClass struct S: Lo = Integer, Hi = NoClass In this case, only one i64 register is used when the structure parameter is transferred, which is obviously incorrect.So we need to treat the split case specially. fix #85387. >From 8efa87d7b03ebf2cf304e97c5fcebdb4211350b4 Mon Sep 17 00:00:00 2001 From: Longsheng Mou Date: Fri, 15 Mar 2024 20:50:54 +0800 Subject: [PATCH] [X86_64] fix arg pass error in struct. typedef long long Alignll __attribute__((align (4))); struct S { int a; Alignll b; }; When classify: a: Lo = Integer, Hi = NoClass b: Lo = Integer, Hi = NoClass struct S: Lo = Integer, Hi = NoClass In this case, only one i64 register is used when the structure parameter is transferred, which is obviously incorrect.So we need to treat the split case specially. --- clang/lib/CodeGen/Targets/X86.cpp | 5 + clang/test/CodeGen/X86/x86_64-arguments.c | 18 ++ 2 files changed, 23 insertions(+) diff --git a/clang/lib/CodeGen/Targets/X86.cpp b/clang/lib/CodeGen/Targets/X86.cpp index 2291c991fb1107..1a02d94a8eb530 100644 --- a/clang/lib/CodeGen/Targets/X86.cpp +++ b/clang/lib/CodeGen/Targets/X86.cpp @@ -1787,6 +1787,7 @@ void X86_64ABIInfo::classify(QualType Ty, uint64_t OffsetBase, Class &Lo, Lo = Hi = NoClass; Class &Current = OffsetBase < 64 ? Lo : Hi; + bool IsSplit = OffsetBase < 64 && (OffsetBase + getContext().getTypeSize(Ty)) > 64; Current = Memory; if (const BuiltinType *BT = Ty->getAs()) { @@ -1799,9 +1800,13 @@ void X86_64ABIInfo::classify(QualType Ty, uint64_t OffsetBase, Class &Lo, Hi = Integer; } else if (k >= BuiltinType::Bool && k <= BuiltinType::LongLong) { Current = Integer; + if (IsSplit) +Hi = Integer; } else if (k == BuiltinType::Float || k == BuiltinType::Double || k == BuiltinType::Float16 || k == BuiltinType::BFloat16) { Current = SSE; + if (IsSplit) +Hi = SSE; } else if (k == BuiltinType::Float128) { Lo = SSE; Hi = SSEUp; diff --git a/clang/test/CodeGen/X86/x86_64-arguments.c b/clang/test/CodeGen/X86/x86_64-arguments.c index cf5636cfd518b6..c8a215989cf9fc 100644 --- a/clang/test/CodeGen/X86/x86_64-arguments.c +++ b/clang/test/CodeGen/X86/x86_64-arguments.c @@ -533,6 +533,24 @@ typedef float t66 __attribute__((__vector_size__(128), __aligned__(128))); void f66(t66 a0) { } +typedef long long t67 __attribute__((align (4))); +struct s67 { + int a; + t67 b; +}; +// CHECK-LABEL: define{{.*}} void @f67(i64 %x.coerce0, i32 %x.coerce1) +void f67(struct s67 x) { +} + +typedef double t68 __attribute__((align (4))); +struct s68 { + int a; + t68 b; +}; +// CHECK-LABEL: define{{.*}} void @f68(i64 %x.coerce0, double %x.coerce1) +void f68(struct s68 x) { +} + /// The synthesized __va_list_tag does not have file/line fields. // CHECK: = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "__va_list_tag", // CHECK-NOT: file: ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [X86_64] fix arg pass error in struct. (PR #85394)
github-actions[bot] wrote: Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using `@` followed by their GitHub username. If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the [LLVM GitHub User Guide](https://llvm.org/docs/GitHub.html). You can also ask questions in a comment on this PR, on the [LLVM Discord](https://discord.com/invite/xS7Z362) or on the [forums](https://discourse.llvm.org/). https://github.com/llvm/llvm-project/pull/85394 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [X86_64] fix arg pass error in struct. (PR #85394)
llvmbot wrote: @llvm/pr-subscribers-clang-codegen @llvm/pr-subscribers-backend-x86 @llvm/pr-subscribers-clang Author: Longsheng Mou (CoTinker) Changes typedef long long Alignll __attribute__((align (4))); struct S { int a; Alignll b; }; When classify: a: Lo = Integer, Hi = NoClass b: Lo = Integer, Hi = NoClass struct S: Lo = Integer, Hi = NoClass In this case, only one i64 register is used when the structure parameter is transferred, which is obviously incorrect.So we need to treat the split case specially. fix #85387. --- Full diff: https://github.com/llvm/llvm-project/pull/85394.diff 2 Files Affected: - (modified) clang/lib/CodeGen/Targets/X86.cpp (+5) - (modified) clang/test/CodeGen/X86/x86_64-arguments.c (+18) ``diff diff --git a/clang/lib/CodeGen/Targets/X86.cpp b/clang/lib/CodeGen/Targets/X86.cpp index 2291c991fb1107..1a02d94a8eb530 100644 --- a/clang/lib/CodeGen/Targets/X86.cpp +++ b/clang/lib/CodeGen/Targets/X86.cpp @@ -1787,6 +1787,7 @@ void X86_64ABIInfo::classify(QualType Ty, uint64_t OffsetBase, Class &Lo, Lo = Hi = NoClass; Class &Current = OffsetBase < 64 ? Lo : Hi; + bool IsSplit = OffsetBase < 64 && (OffsetBase + getContext().getTypeSize(Ty)) > 64; Current = Memory; if (const BuiltinType *BT = Ty->getAs()) { @@ -1799,9 +1800,13 @@ void X86_64ABIInfo::classify(QualType Ty, uint64_t OffsetBase, Class &Lo, Hi = Integer; } else if (k >= BuiltinType::Bool && k <= BuiltinType::LongLong) { Current = Integer; + if (IsSplit) +Hi = Integer; } else if (k == BuiltinType::Float || k == BuiltinType::Double || k == BuiltinType::Float16 || k == BuiltinType::BFloat16) { Current = SSE; + if (IsSplit) +Hi = SSE; } else if (k == BuiltinType::Float128) { Lo = SSE; Hi = SSEUp; diff --git a/clang/test/CodeGen/X86/x86_64-arguments.c b/clang/test/CodeGen/X86/x86_64-arguments.c index cf5636cfd518b6..c8a215989cf9fc 100644 --- a/clang/test/CodeGen/X86/x86_64-arguments.c +++ b/clang/test/CodeGen/X86/x86_64-arguments.c @@ -533,6 +533,24 @@ typedef float t66 __attribute__((__vector_size__(128), __aligned__(128))); void f66(t66 a0) { } +typedef long long t67 __attribute__((align (4))); +struct s67 { + int a; + t67 b; +}; +// CHECK-LABEL: define{{.*}} void @f67(i64 %x.coerce0, i32 %x.coerce1) +void f67(struct s67 x) { +} + +typedef double t68 __attribute__((align (4))); +struct s68 { + int a; + t68 b; +}; +// CHECK-LABEL: define{{.*}} void @f68(i64 %x.coerce0, double %x.coerce1) +void f68(struct s68 x) { +} + /// The synthesized __va_list_tag does not have file/line fields. // CHECK: = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "__va_list_tag", // CHECK-NOT: file: `` https://github.com/llvm/llvm-project/pull/85394 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [X86_64] fix arg pass error in struct. (PR #85394)
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 61671e2500771dfbf502acd86e2ef70cba847a39 8efa87d7b03ebf2cf304e97c5fcebdb4211350b4 -- clang/lib/CodeGen/Targets/X86.cpp clang/test/CodeGen/X86/x86_64-arguments.c `` View the diff from clang-format here. ``diff diff --git a/clang/lib/CodeGen/Targets/X86.cpp b/clang/lib/CodeGen/Targets/X86.cpp index 1a02d94a8e..c3e32e5ed6 100644 --- a/clang/lib/CodeGen/Targets/X86.cpp +++ b/clang/lib/CodeGen/Targets/X86.cpp @@ -1787,7 +1787,8 @@ void X86_64ABIInfo::classify(QualType Ty, uint64_t OffsetBase, Class &Lo, Lo = Hi = NoClass; Class &Current = OffsetBase < 64 ? Lo : Hi; - bool IsSplit = OffsetBase < 64 && (OffsetBase + getContext().getTypeSize(Ty)) > 64; + bool IsSplit = + OffsetBase < 64 && (OffsetBase + getContext().getTypeSize(Ty)) > 64; Current = Memory; if (const BuiltinType *BT = Ty->getAs()) { `` https://github.com/llvm/llvm-project/pull/85394 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [X86_64] fix arg pass error in struct. (PR #85394)
https://github.com/CoTinker edited https://github.com/llvm/llvm-project/pull/85394 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [X86_64] fix arg pass error in struct. (PR #85394)
https://github.com/CoTinker edited https://github.com/llvm/llvm-project/pull/85394 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [X86_64] fix arg pass error in struct. (PR #85394)
https://github.com/CoTinker updated https://github.com/llvm/llvm-project/pull/85394 >From 30d8d0490b383b8b52fee7d8ddd591f8ed5b585e Mon Sep 17 00:00:00 2001 From: Longsheng Mou Date: Fri, 15 Mar 2024 20:50:54 +0800 Subject: [PATCH] [X86_64] fix arg pass error in struct. typedef long long Alignll __attribute__((align (4))); struct S { int a; Alignll b; }; When classify: a: Lo = Integer, Hi = NoClass b: Lo = Integer, Hi = NoClass struct S: Lo = Integer, Hi = NoClass In this case, only one i64 register is used when the structure parameter is transferred, which is obviously incorrect.So we need to treat the split case specially. --- clang/lib/CodeGen/Targets/X86.cpp | 6 ++ clang/test/CodeGen/X86/x86_64-arguments.c | 18 ++ 2 files changed, 24 insertions(+) diff --git a/clang/lib/CodeGen/Targets/X86.cpp b/clang/lib/CodeGen/Targets/X86.cpp index 2291c991fb1107..c3e32e5ed63a97 100644 --- a/clang/lib/CodeGen/Targets/X86.cpp +++ b/clang/lib/CodeGen/Targets/X86.cpp @@ -1787,6 +1787,8 @@ void X86_64ABIInfo::classify(QualType Ty, uint64_t OffsetBase, Class &Lo, Lo = Hi = NoClass; Class &Current = OffsetBase < 64 ? Lo : Hi; + bool IsSplit = + OffsetBase < 64 && (OffsetBase + getContext().getTypeSize(Ty)) > 64; Current = Memory; if (const BuiltinType *BT = Ty->getAs()) { @@ -1799,9 +1801,13 @@ void X86_64ABIInfo::classify(QualType Ty, uint64_t OffsetBase, Class &Lo, Hi = Integer; } else if (k >= BuiltinType::Bool && k <= BuiltinType::LongLong) { Current = Integer; + if (IsSplit) +Hi = Integer; } else if (k == BuiltinType::Float || k == BuiltinType::Double || k == BuiltinType::Float16 || k == BuiltinType::BFloat16) { Current = SSE; + if (IsSplit) +Hi = SSE; } else if (k == BuiltinType::Float128) { Lo = SSE; Hi = SSEUp; diff --git a/clang/test/CodeGen/X86/x86_64-arguments.c b/clang/test/CodeGen/X86/x86_64-arguments.c index cf5636cfd518b6..c8a215989cf9fc 100644 --- a/clang/test/CodeGen/X86/x86_64-arguments.c +++ b/clang/test/CodeGen/X86/x86_64-arguments.c @@ -533,6 +533,24 @@ typedef float t66 __attribute__((__vector_size__(128), __aligned__(128))); void f66(t66 a0) { } +typedef long long t67 __attribute__((align (4))); +struct s67 { + int a; + t67 b; +}; +// CHECK-LABEL: define{{.*}} void @f67(i64 %x.coerce0, i32 %x.coerce1) +void f67(struct s67 x) { +} + +typedef double t68 __attribute__((align (4))); +struct s68 { + int a; + t68 b; +}; +// CHECK-LABEL: define{{.*}} void @f68(i64 %x.coerce0, double %x.coerce1) +void f68(struct s68 x) { +} + /// The synthesized __va_list_tag does not have file/line fields. // CHECK: = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "__va_list_tag", // CHECK-NOT: file: ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Add clang-tidy check readability-math-missing-parentheses (PR #84481)
https://github.com/5chmidti edited https://github.com/llvm/llvm-project/pull/84481 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AMDGPU] Add an option to disable unsafe uses of atomic xor (PR #69229)
yxsamliu wrote: > > @arsenm I agree that the default should be assuming fine-grained is > > possible. My thinking behind the original naming and direction was not > > wanting to introduce an unexpected performance regression by default. I'm > > happy for both to be changed, and this patch being rebased on top of #85052 > > once it is merged. > > The opting for fast-and-maybe-broken by default needs to be a frontend > decision (i.e. the language can choose to add the metadata to all atomics). I > believe @yxsamliu is going to be working on the frontend half which will > preserve the HIP behavior > > > One oustanding question for me is, although outside of the scope of this > > PR, how will the original 'no-unsafe-fp' option fit in the new metadata > > node in terms of constraints? Would it imply a new constraint or be covered > > by `no_fine_grained` and `no_remote`? > > I believe we need an additional piece of metadata (which I have another draft > for) to express the relaxable floating point. We can express the > unsafe-fp-math option with the 2 combined, and then can drop the old IR > attribute Will the metadata for unsafe-fp-atomics also be controlled by the pragma that controls the no-fine-grained and no-remote metadata? e.g. something like ``` #pragma clang atomics begin no-fine-grained(on) no-remote(on) unsafe-fp(on) ``` https://github.com/llvm/llvm-project/pull/69229 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [FMV] Emit the resolver along with the default version definition. (PR #84405)
@@ -4347,6 +4362,19 @@ void CodeGenModule::emitCPUDispatchDefinition(GlobalDecl GD) { } } +/// Adds a declaration to the list of multi version functions if not present. +void CodeGenModule::AddDeferredMultiVersionResolverToEmit(GlobalDecl GD) { + const auto *FD = cast(GD.getDecl()); + assert(FD && "Not a FunctionDecl?"); + + if (FD->isTargetVersionMultiVersion()) { +StringRef NamePrefix = getMangledName(GD).split('.').first; labrinea wrote: I tried experimenting with __asm__ but couldn't construct a sensible example in regards to multi versioning. Can you please show me? https://github.com/llvm/llvm-project/pull/84405 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [codegen] Emit cleanups for branch in stmt-expr and coro suspensions (PR #85398)
https://github.com/usx95 created https://github.com/llvm/llvm-project/pull/85398 Promotes some EHOnly cleanups to NormalAndEHCleanups to make sure these are emitted if we see a branch inside an expression (through statement expressions or coroutine suspensions). These are usually deactivated after the full expression and destroyed later as part of the destructor of aggregate/array being constructed. Also fixes the emission of deactivated but branch-throughed normal cleanups. >From 0654f624b3b60026398e8b0168623a85e3129630 Mon Sep 17 00:00:00 2001 From: Utkarsh Saxena Date: Fri, 15 Mar 2024 13:19:36 + Subject: [PATCH] [codegen] Emit cleanups for branch in stmt-expr and coro suspensions --- clang/lib/CodeGen/CGCleanup.cpp | 7 +-- clang/lib/CodeGen/CGExprAgg.cpp | 13 +++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/clang/lib/CodeGen/CGCleanup.cpp b/clang/lib/CodeGen/CGCleanup.cpp index f87caf050eeaa7..c22d4da0fefc3c 100644 --- a/clang/lib/CodeGen/CGCleanup.cpp +++ b/clang/lib/CodeGen/CGCleanup.cpp @@ -694,7 +694,8 @@ void CodeGenFunction::PopCleanupBlock(bool FallthroughIsBranchThrough) { // - whether there's a fallthrough llvm::BasicBlock *FallthroughSource = Builder.GetInsertBlock(); - bool HasFallthrough = (FallthroughSource != nullptr && IsActive); + bool HasFallthrough = + FallthroughSource != nullptr && (IsActive || HasExistingBranches); // Branch-through fall-throughs leave the insertion point set to the // end of the last cleanup, which points to the current scope. The @@ -719,7 +720,9 @@ void CodeGenFunction::PopCleanupBlock(bool FallthroughIsBranchThrough) { // If we have a prebranched fallthrough into an inactive normal // cleanup, rewrite it so that it leads to the appropriate place. - if (Scope.isNormalCleanup() && HasPrebranchedFallthrough && !IsActive) { + if (Scope.isNormalCleanup() && HasPrebranchedFallthrough && + !RequiresNormalCleanup) { +assert(!IsActive); llvm::BasicBlock *prebranchDest; // If the prebranch is semantically branching through the next diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp index 5190b22bcc1622..7e62599089b8df 100644 --- a/clang/lib/CodeGen/CGExprAgg.cpp +++ b/clang/lib/CodeGen/CGExprAgg.cpp @@ -15,6 +15,7 @@ #include "CodeGenFunction.h" #include "CodeGenModule.h" #include "ConstantEmitter.h" +#include "EHScopeStack.h" #include "TargetInfo.h" #include "clang/AST/ASTContext.h" #include "clang/AST/Attr.h" @@ -1389,15 +1390,15 @@ AggExprEmitter::VisitLambdaExpr(LambdaExpr *E) { if (QualType::DestructionKind DtorKind = CurField->getType().isDestructedType()) { assert(LV.isSimple()); - if (CGF.needsEHCleanup(DtorKind)) { + if (DtorKind) { if (!CleanupDominator) CleanupDominator = CGF.Builder.CreateAlignedLoad( CGF.Int8Ty, llvm::Constant::getNullValue(CGF.Int8PtrTy), CharUnits::One()); // placeholder -CGF.pushDestroy(EHCleanup, LV.getAddress(CGF), CurField->getType(), -CGF.getDestroyer(DtorKind), false); +CGF.pushDestroy(NormalAndEHCleanup, LV.getAddress(CGF), +CurField->getType(), CGF.getDestroyer(DtorKind), false); Cleanups.push_back(CGF.EHStack.stable_begin()); } } @@ -1806,9 +1807,9 @@ void AggExprEmitter::VisitCXXParenListOrInitListExpr( if (QualType::DestructionKind dtorKind = field->getType().isDestructedType()) { assert(LV.isSimple()); - if (CGF.needsEHCleanup(dtorKind)) { -CGF.pushDestroy(EHCleanup, LV.getAddress(CGF), field->getType(), -CGF.getDestroyer(dtorKind), false); + if (dtorKind) { +CGF.pushDestroy(NormalAndEHCleanup, LV.getAddress(CGF), +field->getType(), CGF.getDestroyer(dtorKind), false); addCleanup(CGF.EHStack.stable_begin()); pushedCleanup = true; } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][dataflow] Make optional checker work for types derived from optional. (PR #84138)
martinboehme wrote: > One high level question: is there a simpler path by which we avoid crashing > on derived types but also don't support them? It seems like there is a lot of > complexity required in getting this just right. Is it worth it (both in the > code itself and in terms of runtime cost) to support these unusual cases? Of > course, if it's necessary then the point is moot... This is a good question. tl;dr: I think actually handling these cases instead of just ignoring them is the right tradeoff, but the situation certainly isn't clear cut. It's _possible_ to avoid crashing on derived types but otherwise not support them. What we would need to do is call `RecordStorageLocation::getType()` on the storage location of the object that we're accessing; we would only proceed if we see an actual optional type (not a derived type). The thing is though that we would need to do this in _every_ `transfer_...` handler; this isn't ideal because it's easy to forget one, and then we get crashes there. I considered this option, but it seemed to me that the more principled and less error-prone approach is to actually treat derived types correctly. As I say, the tradeoff isn't clear-cut. To summarize: **Bail out but don't crash** Pros: * Less conceptual complexity... Cons: * ...but need a check in every handler (i.e. still lots of lines of code). * If we forget to add the check everywhere, we get crashes. **Correctly handle derived types** Pros: * The additional code is centralized in one place. * Actually makes the check more expressive Cons: * We need to walk the inheritance hierarchy and chains of casts, which adds complexity and potentially makes the check slower. Will respond to the individual comments too, but probably not before Monday. https://github.com/llvm/llvm-project/pull/84138 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [codegen] Emit cleanups for branch in stmt-expr and coro suspensions [take-2] (PR #85398)
https://github.com/usx95 edited https://github.com/llvm/llvm-project/pull/85398 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add `__has_feature(swiftcc)` support (PR #85347)
https://github.com/aschwaighofer edited https://github.com/llvm/llvm-project/pull/85347 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add `__has_feature(swiftcc)` support (PR #85347)
https://github.com/aschwaighofer requested changes to this pull request. In a past review (https://github.com/llvm/llvm-project/pull/72159), @AaronBallman (https://github.com/AaronBallman) noted that the existing use of `FEATURE` (as in `FEATURE(swiftasynccc,...`) was not the right qualifier to use. And it should have been an `EXTENSION` instead. We should use `EXTENSION` for the `swiftcc` check. Quoting from the top of the file: ``` // FEATURE(...) should be used to advertise support for standard language // features, whereas EXTENSION(...) should be used for clang extensions. Note // that many of the identifiers in this file don't follow this rule for backward // compatibility reasons. ``` https://github.com/llvm/llvm-project/pull/85347 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add `__has_feature(swiftcc)` support (PR #85347)
@@ -102,6 +102,9 @@ FEATURE(memory_sanitizer, FEATURE(thread_sanitizer, LangOpts.Sanitize.has(SanitizerKind::Thread)) FEATURE(dataflow_sanitizer, LangOpts.Sanitize.has(SanitizerKind::DataFlow)) FEATURE(scudo, LangOpts.Sanitize.hasOneOf(SanitizerKind::Scudo)) +FEATURE(swiftcc, aschwaighofer wrote: I think we should use `EXTENSION` instead of `FEATURE`. https://github.com/llvm/llvm-project/pull/85347 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add `__has_feature(swiftcc)` support (PR #85347)
https://github.com/aschwaighofer edited https://github.com/llvm/llvm-project/pull/85347 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AMDGPU] Add an option to disable unsafe uses of atomic xor (PR #69229)
arsenm wrote: > Will the metadata for unsafe-fp-atomics also be controlled by the pragma that > controls the no-fine-grained and no-remote metadata? e.g. something like > > ``` > #pragma clang atomics begin no-fine-grained(on) no-remote(on) unsafe-fp(on) > ``` Yes, I would expect something like that for consistency. The most problematic part is the denormal flushing in some address spaces, and secondarily the fixed rounding mode in other cases https://github.com/llvm/llvm-project/pull/69229 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CLANG] Full support of complex multiplication and division. (PR #81514)
https://github.com/zahiraam edited https://github.com/llvm/llvm-project/pull/81514 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CLANG] Full support of complex multiplication and division. (PR #81514)
https://github.com/zahiraam edited https://github.com/llvm/llvm-project/pull/81514 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits