[clang] [-Wunsafe-buffer-usage] Fix a bug and suppress libc warnings for C files (PR #109496)
https://github.com/ziqingluo-90 closed https://github.com/llvm/llvm-project/pull/109496 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 090dc77 - [-Wunsafe-buffer-usage] Fix a bug and suppress libc warnings for C files (#109496)
Author: Ziqing Luo Date: 2024-09-22T12:29:06-07:00 New Revision: 090dc77a8d636415b772f7e5f95cd120370e41d1 URL: https://github.com/llvm/llvm-project/commit/090dc77a8d636415b772f7e5f95cd120370e41d1 DIFF: https://github.com/llvm/llvm-project/commit/090dc77a8d636415b772f7e5f95cd120370e41d1.diff LOG: [-Wunsafe-buffer-usage] Fix a bug and suppress libc warnings for C files (#109496) - Fix a bug in UnsafeBufferUsage.cpp related to casting to PointerType - Suppress -Wunsafe-buffer-usage-in-libc-call for C files (rdar://117182250) Added: clang/test/SemaCXX/warn-unsafe-buffer-usage-no-libc-functions-in-c.c Modified: clang/lib/Analysis/UnsafeBufferUsage.cpp clang/lib/Sema/AnalysisBasedWarnings.cpp clang/test/SemaCXX/warn-unsafe-buffer-usage-libc-functions.cpp Removed: diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp b/clang/lib/Analysis/UnsafeBufferUsage.cpp index a16762244b1766..97f1c4f16b8f4c 100644 --- a/clang/lib/Analysis/UnsafeBufferUsage.cpp +++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp @@ -250,7 +250,9 @@ AST_MATCHER_P(Stmt, ignoreUnsafeBufferInContainer, AST_MATCHER_P(Stmt, ignoreUnsafeLibcCall, const UnsafeBufferUsageHandler *, Handler) { - return Handler->ignoreUnsafeBufferInLibcCall(Node.getBeginLoc()); + if (Finder->getASTContext().getLangOpts().CPlusPlus) +return Handler->ignoreUnsafeBufferInLibcCall(Node.getBeginLoc()); + return true; /* Only warn about libc calls for C++ */ } AST_MATCHER_P(CastExpr, castSubExpr, internal::Matcher, innerMatcher) { @@ -784,12 +786,12 @@ AST_MATCHER_P(CallExpr, hasUnsafePrintfStringArg, return false; // possibly some user-defined printf function ASTContext &Ctx = Finder->getASTContext(); - QualType FristParmTy = FD->getParamDecl(0)->getType(); + QualType FirstParmTy = FD->getParamDecl(0)->getType(); - if (!FristParmTy->isPointerType()) + if (!FirstParmTy->isPointerType()) return false; // possibly some user-defined printf function - QualType FirstPteTy = (cast(FristParmTy))->getPointeeType(); + QualType FirstPteTy = FirstParmTy->castAs()->getPointeeType(); if (!Ctx.getFILEType() .isNull() && //`FILE *` must be in the context if it is fprintf @@ -865,7 +867,7 @@ AST_MATCHER(CallExpr, hasUnsafeSnprintfBuffer) { if (!FirstParmTy->isPointerType()) return false; // Not an snprint - QualType FirstPteTy = cast(FirstParmTy)->getPointeeType(); + QualType FirstPteTy = FirstParmTy->castAs()->getPointeeType(); const Expr *Buf = Node.getArg(0), *Size = Node.getArg(1); if (FirstPteTy.isConstQualified() || !Buf->getType()->isPointerType() || diff --git a/clang/lib/Sema/AnalysisBasedWarnings.cpp b/clang/lib/Sema/AnalysisBasedWarnings.cpp index 117b2c8bc57935..6496a33b8f5a50 100644 --- a/clang/lib/Sema/AnalysisBasedWarnings.cpp +++ b/clang/lib/Sema/AnalysisBasedWarnings.cpp @@ -2581,7 +2581,8 @@ void clang::sema::AnalysisBasedWarnings::IssueWarnings( !Diags.isIgnored(diag::warn_unsafe_buffer_variable, SourceLocation()) || !Diags.isIgnored(diag::warn_unsafe_buffer_usage_in_container, SourceLocation()) || - !Diags.isIgnored(diag::warn_unsafe_buffer_libc_call, SourceLocation())) { + (!Diags.isIgnored(diag::warn_unsafe_buffer_libc_call, SourceLocation()) && + S.getLangOpts().CPlusPlus /* only warn about libc calls in C++ */)) { CallableVisitor(CallAnalyzers).TraverseTranslationUnitDecl(TU); } } diff --git a/clang/test/SemaCXX/warn-unsafe-buffer-usage-libc-functions.cpp b/clang/test/SemaCXX/warn-unsafe-buffer-usage-libc-functions.cpp index 25b6d8e9e22dc2..a7c19bcac16078 100644 --- a/clang/test/SemaCXX/warn-unsafe-buffer-usage-libc-functions.cpp +++ b/clang/test/SemaCXX/warn-unsafe-buffer-usage-libc-functions.cpp @@ -1,5 +1,7 @@ // RUN: %clang_cc1 -std=c++20 -Wno-all -Wunsafe-buffer-usage \ // RUN:-verify %s +// RUN: %clang_cc1 -std=c++20 -Wno-all -Wunsafe-buffer-usage \ +// RUN:-verify %s -x objective-c++ // RUN: %clang_cc1 -std=c++20 -Wno-all -Wunsafe-buffer-usage-in-libc-call \ // RUN:-verify %s @@ -56,6 +58,11 @@ namespace std { } void f(char * p, char * q, std::span s, std::span s2) { + typedef FILE * _Nullable aligned_file_ptr_t __attribute__((align_value(64))); + typedef char * _Nullable aligned_char_ptr_t __attribute__((align_value(64))); + aligned_file_ptr_t fp; + aligned_char_ptr_t cp; + memcpy(); // expected-warning{{function 'memcpy' is unsafe}} std::memcpy(); // expected-warning{{function 'memcpy' is unsafe}} __builtin_memcpy(p, q, 64); // expected-warning{{function '__builtin_memcpy' is unsafe}} @@ -71,9 +78,11 @@ void f(char * p, char * q, std::span s, std::span s2) { printf("%s%d", // expected-warning{{function 'printf' is unsafe}} p,// expected-note{{string argument is not guaranteed to b
[clang] clang-format: Add AlignFunctionDeclarations attribute to AlignConsecutiveDeclarations (PR #108241)
owenca wrote: > In regards to the "Test documentation build / Test documentation build > (pull_request) " failure, I'm honestly not sure how to fix the formatting in > this. I'm not seeing anything wrong with my addition in Format.h, but maybe > there's something I'm missing. I never touch ClangFormatStyleOptions.rst > directly. See https://github.com/llvm/llvm-project/pull/108241/files#r1770622313. https://github.com/llvm/llvm-project/pull/108241 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] clang-format: Add AlignFunctionDeclarations attribute to AlignConsecutiveDeclarations (PR #108241)
@@ -225,6 +225,21 @@ struct FormatStyle { /// bbb = 2; /// \endcode bool AlignCompound; +/// Only for ``AlignConsecutiveDeclarations``. Whether function declarations +/// are aligned. +/// \code +/// true: +/// unsigned int f1(void); +/// void f2(void); +/// size_t f3(void); +/// +/// false: +/// unsigned int f1(void); +/// void f2(void); +/// size_t f3(void); +/// \endcode +/// \version 20 owenca wrote: Delete. https://github.com/llvm/llvm-project/pull/108241 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] riscv: Support -mstack-protector-guard=tls (PR #108942)
@@ -0,0 +1,19 @@ +; RUN: llc -mtriple=riscv64-unknown-elf < %s | \ keith-packard wrote: Thanks. I wondered how that was supposed to work. https://github.com/llvm/llvm-project/pull/108942 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [Driver][X86] Add flang visibility for -m[no-]evex512 (PR #109598)
https://github.com/phoebewang created https://github.com/llvm/llvm-project/pull/109598 The `-m[no-]evex512` are nontrivial options which are used to control vector size of other AVX512 features. Hence we expose both to flang for Fortran users. >From d9aa2912206bb435bc830a42bc5ddd8b604c7d98 Mon Sep 17 00:00:00 2001 From: "Wang, Phoebe" Date: Mon, 23 Sep 2024 10:36:11 +0800 Subject: [PATCH] [Driver][X86] Add flang visibility for -m[no-]evex512 The `-m[no-]evex512` are nontrivial options which are used to control vector size of other AVX512 features. Hence we expose both to flang for Fortran users. --- clang/include/clang/Driver/Options.td | 6 -- flang/test/Driver/target-cpu-features.f90 | 12 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 376d7d4290c0bf..002f60350543d9 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -6352,8 +6352,10 @@ def mcx16 : Flag<["-"], "mcx16">, Group; def mno_cx16 : Flag<["-"], "mno-cx16">, Group; def menqcmd : Flag<["-"], "menqcmd">, Group; def mno_enqcmd : Flag<["-"], "mno-enqcmd">, Group; -def mevex512 : Flag<["-"], "mevex512">, Group; -def mno_evex512 : Flag<["-"], "mno-evex512">, Group; +def mevex512 : Flag<["-"], "mevex512">, Group, + Visibility<[ClangOption, CLOption, FlangOption]>; +def mno_evex512 : Flag<["-"], "mno-evex512">, Group, + Visibility<[ClangOption, CLOption, FlangOption]>; def mf16c : Flag<["-"], "mf16c">, Group; def mno_f16c : Flag<["-"], "mno-f16c">, Group; def mfma : Flag<["-"], "mfma">, Group; diff --git a/flang/test/Driver/target-cpu-features.f90 b/flang/test/Driver/target-cpu-features.f90 index 1c77d4ace5fbc1..e3eb8491058c7f 100644 --- a/flang/test/Driver/target-cpu-features.f90 +++ b/flang/test/Driver/target-cpu-features.f90 @@ -23,6 +23,12 @@ ! RUN: %flang --target=x86_64-linux-gnu -mno-apx-features=ccmp -c %s -### 2>&1 \ ! RUN: | FileCheck %s -check-prefix=CHECK-NO-APX +! RUN: %flang --target=x86_64-linux-gnu -mevex512 -c %s -### 2>&1 \ +! RUN: | FileCheck %s -check-prefix=CHECK-EVEX512 + +! RUN: %flang --target=x86_64-linux-gnu -mno-evex512 -c %s -### 2>&1 \ +! RUN: | FileCheck %s -check-prefix=CHECK-NO-EVEX512 + ! RUN: %flang --target=x86_64h-linux-gnu -c %s -### 2>&1 \ ! RUN: | FileCheck %s -check-prefix=CHECK-X86_64H @@ -63,6 +69,12 @@ ! CHECK-NO-APX: "-fc1" "-triple" "x86_64-unknown-linux-gnu" ! CHECK-NO-APX-SAME: "-target-feature" "-ccmp" +! CHECK-EVEX512: "-fc1" "-triple" "x86_64-unknown-linux-gnu" +! CHECK-EVEX512-SAME: "-target-feature" "+evex512" + +! CHECK-NO-EVEX512: "-fc1" "-triple" "x86_64-unknown-linux-gnu" +! CHECK-NO-EVEX512-SAME: "-target-feature" "-evex512" + ! CHECK-X86_64H: "-fc1" "-triple" "x86_64h-unknown-linux-gnu" ! CHECK-X86_64H-SAME: "-target-cpu" "x86-64" "-target-feature" "-rdrnd" "-target-feature" "-aes" "-target-feature" "-pclmul" "-target-feature" "-rtm" "-target-feature" "-fsgsbase" ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [Driver][X86] Add flang visibility for -m[no-]evex512 (PR #109598)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Phoebe Wang (phoebewang) Changes The `-m[no-]evex512` are nontrivial options which are used to control vector size of other AVX512 features. Hence we expose both to flang for Fortran users. --- Full diff: https://github.com/llvm/llvm-project/pull/109598.diff 2 Files Affected: - (modified) clang/include/clang/Driver/Options.td (+4-2) - (modified) flang/test/Driver/target-cpu-features.f90 (+12) ``diff diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 376d7d4290c0bf..002f60350543d9 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -6352,8 +6352,10 @@ def mcx16 : Flag<["-"], "mcx16">, Group; def mno_cx16 : Flag<["-"], "mno-cx16">, Group; def menqcmd : Flag<["-"], "menqcmd">, Group; def mno_enqcmd : Flag<["-"], "mno-enqcmd">, Group; -def mevex512 : Flag<["-"], "mevex512">, Group; -def mno_evex512 : Flag<["-"], "mno-evex512">, Group; +def mevex512 : Flag<["-"], "mevex512">, Group, + Visibility<[ClangOption, CLOption, FlangOption]>; +def mno_evex512 : Flag<["-"], "mno-evex512">, Group, + Visibility<[ClangOption, CLOption, FlangOption]>; def mf16c : Flag<["-"], "mf16c">, Group; def mno_f16c : Flag<["-"], "mno-f16c">, Group; def mfma : Flag<["-"], "mfma">, Group; diff --git a/flang/test/Driver/target-cpu-features.f90 b/flang/test/Driver/target-cpu-features.f90 index 1c77d4ace5fbc1..e3eb8491058c7f 100644 --- a/flang/test/Driver/target-cpu-features.f90 +++ b/flang/test/Driver/target-cpu-features.f90 @@ -23,6 +23,12 @@ ! RUN: %flang --target=x86_64-linux-gnu -mno-apx-features=ccmp -c %s -### 2>&1 \ ! RUN: | FileCheck %s -check-prefix=CHECK-NO-APX +! RUN: %flang --target=x86_64-linux-gnu -mevex512 -c %s -### 2>&1 \ +! RUN: | FileCheck %s -check-prefix=CHECK-EVEX512 + +! RUN: %flang --target=x86_64-linux-gnu -mno-evex512 -c %s -### 2>&1 \ +! RUN: | FileCheck %s -check-prefix=CHECK-NO-EVEX512 + ! RUN: %flang --target=x86_64h-linux-gnu -c %s -### 2>&1 \ ! RUN: | FileCheck %s -check-prefix=CHECK-X86_64H @@ -63,6 +69,12 @@ ! CHECK-NO-APX: "-fc1" "-triple" "x86_64-unknown-linux-gnu" ! CHECK-NO-APX-SAME: "-target-feature" "-ccmp" +! CHECK-EVEX512: "-fc1" "-triple" "x86_64-unknown-linux-gnu" +! CHECK-EVEX512-SAME: "-target-feature" "+evex512" + +! CHECK-NO-EVEX512: "-fc1" "-triple" "x86_64-unknown-linux-gnu" +! CHECK-NO-EVEX512-SAME: "-target-feature" "-evex512" + ! CHECK-X86_64H: "-fc1" "-triple" "x86_64h-unknown-linux-gnu" ! CHECK-X86_64H-SAME: "-target-cpu" "x86-64" "-target-feature" "-rdrnd" "-target-feature" "-aes" "-target-feature" "-pclmul" "-target-feature" "-rtm" "-target-feature" "-fsgsbase" `` https://github.com/llvm/llvm-project/pull/109598 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][codegen] Don't mark "int" TBAA on FP libcalls with indirect args (PR #108853)
https://github.com/vfdff edited https://github.com/llvm/llvm-project/pull/108853 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 62f737f - [Driver][X86] Add flang visibility for -m[no-]evex512 (#109598)
Author: Phoebe Wang Date: 2024-09-23T11:21:48+08:00 New Revision: 62f737f7409b5d2b33c746158c62f14e5bb78aed URL: https://github.com/llvm/llvm-project/commit/62f737f7409b5d2b33c746158c62f14e5bb78aed DIFF: https://github.com/llvm/llvm-project/commit/62f737f7409b5d2b33c746158c62f14e5bb78aed.diff LOG: [Driver][X86] Add flang visibility for -m[no-]evex512 (#109598) The `-m[no-]evex512` are nontrivial options which are used to control vector size of other AVX512 features. Hence we expose both to flang for Fortran users. Added: Modified: clang/include/clang/Driver/Options.td flang/test/Driver/target-cpu-features.f90 Removed: diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 376d7d4290c0bf..002f60350543d9 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -6352,8 +6352,10 @@ def mcx16 : Flag<["-"], "mcx16">, Group; def mno_cx16 : Flag<["-"], "mno-cx16">, Group; def menqcmd : Flag<["-"], "menqcmd">, Group; def mno_enqcmd : Flag<["-"], "mno-enqcmd">, Group; -def mevex512 : Flag<["-"], "mevex512">, Group; -def mno_evex512 : Flag<["-"], "mno-evex512">, Group; +def mevex512 : Flag<["-"], "mevex512">, Group, + Visibility<[ClangOption, CLOption, FlangOption]>; +def mno_evex512 : Flag<["-"], "mno-evex512">, Group, + Visibility<[ClangOption, CLOption, FlangOption]>; def mf16c : Flag<["-"], "mf16c">, Group; def mno_f16c : Flag<["-"], "mno-f16c">, Group; def mfma : Flag<["-"], "mfma">, Group; diff --git a/flang/test/Driver/target-cpu-features.f90 b/flang/test/Driver/target-cpu-features.f90 index 1c77d4ace5fbc1..e3eb8491058c7f 100644 --- a/flang/test/Driver/target-cpu-features.f90 +++ b/flang/test/Driver/target-cpu-features.f90 @@ -23,6 +23,12 @@ ! RUN: %flang --target=x86_64-linux-gnu -mno-apx-features=ccmp -c %s -### 2>&1 \ ! RUN: | FileCheck %s -check-prefix=CHECK-NO-APX +! RUN: %flang --target=x86_64-linux-gnu -mevex512 -c %s -### 2>&1 \ +! RUN: | FileCheck %s -check-prefix=CHECK-EVEX512 + +! RUN: %flang --target=x86_64-linux-gnu -mno-evex512 -c %s -### 2>&1 \ +! RUN: | FileCheck %s -check-prefix=CHECK-NO-EVEX512 + ! RUN: %flang --target=x86_64h-linux-gnu -c %s -### 2>&1 \ ! RUN: | FileCheck %s -check-prefix=CHECK-X86_64H @@ -63,6 +69,12 @@ ! CHECK-NO-APX: "-fc1" "-triple" "x86_64-unknown-linux-gnu" ! CHECK-NO-APX-SAME: "-target-feature" "-ccmp" +! CHECK-EVEX512: "-fc1" "-triple" "x86_64-unknown-linux-gnu" +! CHECK-EVEX512-SAME: "-target-feature" "+evex512" + +! CHECK-NO-EVEX512: "-fc1" "-triple" "x86_64-unknown-linux-gnu" +! CHECK-NO-EVEX512-SAME: "-target-feature" "-evex512" + ! CHECK-X86_64H: "-fc1" "-triple" "x86_64h-unknown-linux-gnu" ! CHECK-X86_64H-SAME: "-target-cpu" "x86-64" "-target-feature" "-rdrnd" "-target-feature" "-aes" "-target-feature" "-pclmul" "-target-feature" "-rtm" "-target-feature" "-fsgsbase" ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [Driver][X86] Add flang visibility for -m[no-]evex512 (PR #109598)
https://github.com/phoebewang closed https://github.com/llvm/llvm-project/pull/109598 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [Driver][X86] Add flang visibility for -m[no-]evex512 (PR #109598)
https://github.com/FreddyLeaf approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/109598 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][codegen] Don't mark "int" TBAA on FP libcalls with indirect args (PR #108853)
https://github.com/vfdff approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/108853 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [KCFI][NFC] Rename the !kcfi_type Function metadata to !cfi_type (PR #109080)
mylai-mtk wrote: Excuse me, @MaskRay . I don't understand your stance: > I understand the intention to generalize naming, but I feel that there is > significance chance that the over-generalization may not work with the > alternative CFI schemes, and this change could turn out to be needed when the > other schemes go with different IR constructs. I get that this renaming is an over-generalization, and more changes in the future may be required should different CFI schemes arise, so I guess you're suggesting maybe we should not do the renaming. > I feel that we should make such renaming at this time. But then you propose that we make the renaming now. (??) I'm quite confused by the conflict of these two paragraphs. Can you talk more about your view? https://github.com/llvm/llvm-project/pull/109080 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [lldb] [llvm] [mlir] [APInt] Fix APInt constructions where value does not fit bitwidth (NFCI) (PR #80309)
dtcxzyw wrote: https://github.com/llvm/llvm-project/blob/62f737f7409b5d2b33c746158c62f14e5bb78aed/llvm/lib/Transforms/Utils/SimplifyCFG.cpp#L6516 We should allow truncations here. ``` ; bin/opt -passes='simplifycfg' reduced.ll -S target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128" target triple = "x86_64-unknown-linux-gnu" define i1 @_ZN5image5color9ColorType9has_alpha17h81054606b63d0c15E(i8 %0) { switch i8 %0, label %3 [ i8 9, label %2 i8 1, label %2 i8 7, label %2 i8 3, label %2 i8 5, label %2 ] 2:; preds = %1, %1, %1, %1, %1 br label %3 3:; preds = %2, %1 %.0 = phi i1 [ true, %2 ], [ false, %1 ] ret i1 %.0 } ``` ``` opt: /home/dtcxzyw/WorkSpace/Projects/compilers/llvm-project/llvm/include/llvm/ADT/APInt.h:121: llvm::APInt::APInt(unsigned int, uint64_t, bool, bool): Assertion `llvm::isUIntN(BitWidth, val) && "Value is not an N-bit unsigned value"' failed. PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace. Stack dump: 0. Program arguments: bin/opt -passes=simplifycfg reduced.ll -S 1. Running pass "function(simplifycfg)" on module "reduced.ll" 2. Running pass "simplifycfg" on function "_ZN5image5color9ColorType9has_alpha17h81054606b63d0c15E" #0 0x717e69813f12 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMSupport.so.20.0git+0x213f12) #1 0x717e69810ddf llvm::sys::RunSignalHandlers() (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMSupport.so.20.0git+0x210ddf) #2 0x717e69810f25 SignalHandler(int) Signals.cpp:0:0 #3 0x717e69242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520) #4 0x717e692969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76 #5 0x717e692969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10 #6 0x717e692969fc pthread_kill ./nptl/pthread_kill.c:89:10 #7 0x717e69242476 gsignal ./signal/../sysdeps/posix/raise.c:27:6 #8 0x717e692287f3 abort ./stdlib/abort.c:81:7 #9 0x717e6922871b _nl_load_domain ./intl/loadmsgcat.c:1177:9 #10 0x717e69239e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96) #11 0x717e62d2afef llvm::APInt::APInt(unsigned int, unsigned long, bool, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMTransformUtils.so.20.0git+0x12afef) #12 0x717e62e97856 (anonymous namespace)::SwitchLookupTable::SwitchLookupTable(llvm::Module&, unsigned long, llvm::ConstantInt*, llvm::SmallVectorImpl> const&, llvm::Constant*, llvm::DataLayout const&, llvm::StringRef const&) SimplifyCFG.cpp:0:0 #13 0x717e62eb4a96 switchToLookupTable(llvm::SwitchInst*, llvm::IRBuilder&, llvm::DomTreeUpdater*, llvm::DataLayout const&, llvm::TargetTransformInfo const&) SimplifyCFG.cpp:0:0 #14 0x717e62ebfedd (anonymous namespace)::SimplifyCFGOpt::simplifySwitch(llvm::SwitchInst*, llvm::IRBuilder&) SimplifyCFG.cpp:0:0 #15 0x717e62ec557b llvm::simplifyCFG(llvm::BasicBlock*, llvm::TargetTransformInfo const&, llvm::DomTreeUpdater*, llvm::SimplifyCFGOptions const&, llvm::ArrayRef) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMTransformUtils.so.20.0git+0x2c557b) #16 0x717e635bb663 iterativelySimplifyCFG(llvm::Function&, llvm::TargetTransformInfo const&, llvm::DomTreeUpdater*, llvm::SimplifyCFGOptions const&) SimplifyCFGPass.cpp:0:0 #17 0x717e635bc6d4 simplifyFunctionCFGImpl(llvm::Function&, llvm::TargetTransformInfo const&, llvm::DominatorTree*, llvm::SimplifyCFGOptions const&) SimplifyCFGPass.cpp:0:0 #18 0x717e635bcf05 simplifyFunctionCFG(llvm::Function&, llvm::TargetTransformInfo const&, llvm::DominatorTree*, llvm::SimplifyCFGOptions const&) SimplifyCFGPass.cpp:0:0 #19 0x717e635bd068 llvm::SimplifyCFGPass::run(llvm::Function&, llvm::AnalysisManager&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMScalarOpts.so.20.0git+0x3bd068) #20 0x717e64ed4675 llvm::detail::PassModel>::run(llvm::Function&, llvm::AnalysisManager&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMPasses.so.20.0git+0xd4675) #21 0x717e6215576d llvm::PassManager>::run(llvm::Function&, llvm::AnalysisManager&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMCore.so.20.0git+0x35576d) #22 0x717e684d8695 llvm::detail::PassModel>, llvm::AnalysisManager>::run(llvm::Function&, llvm::AnalysisManager&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMX86CodeGen.so.20.0git+0xd8695) #23 0x717e621538a6 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/.
[clang] [Clang][RISCV] Add preprocessor macros for Zicfilp CFI scheme (PR #109600)
https://github.com/mylai-mtk created https://github.com/llvm/llvm-project/pull/109600 This patch adds preprocessor macros when Zicfilp CFI is enabled. The macros are proposed in riscv-non-isa/riscv-c-api-doc#76 , and the CLI flags are from riscv-non-isa/riscv-toolchain-conventions#54. >From 40ecff66e69ad520dd858d34be8b8f9a6da594fb Mon Sep 17 00:00:00 2001 From: Ming-Yi Lai Date: Wed, 4 Sep 2024 18:40:48 +0800 Subject: [PATCH 1/3] [clang][RISCV] Accept -fcf-protection=branch when Zicfilp extension is on -fcf-protection=branch turns on indirect branching protection on RISC-V targets with Zicfilp extension. --- clang/lib/Basic/Targets/RISCV.h | 7 +++ 1 file changed, 7 insertions(+) diff --git a/clang/lib/Basic/Targets/RISCV.h b/clang/lib/Basic/Targets/RISCV.h index b808ccc8e9cfe9..13d4b4c04ce8e0 100644 --- a/clang/lib/Basic/Targets/RISCV.h +++ b/clang/lib/Basic/Targets/RISCV.h @@ -131,6 +131,13 @@ class RISCVTargetInfo : public TargetInfo { bool supportsCpuInit() const override { return getTriple().isOSLinux(); } bool validateCpuSupports(StringRef Feature) const override; bool isValidFeatureName(StringRef Name) const override; + + bool + checkCFProtectionBranchSupported(DiagnosticsEngine &Diags) const override { +if (ISAInfo->hasExtension("zicfilp")) + return true; +return TargetInfo::checkCFProtectionBranchSupported(Diags); + } }; class LLVM_LIBRARY_VISIBILITY RISCV32TargetInfo : public RISCVTargetInfo { public: >From 71de8dcc7d5a0038e705b552ba8092d7ae6868b7 Mon Sep 17 00:00:00 2001 From: Ming-Yi Lai Date: Fri, 6 Sep 2024 19:00:10 +0800 Subject: [PATCH 2/3] [Clang] Introduce -fcf-branch-label-scheme=unlabeled|func-sig This flag controls the scheme of the labels of landing pad insns. Landing pad insns are special insns that mark the targets of indirect jumps. In RISC-V Zicfilp extension, its landing pad insn further encodes a field of `label', which can be used to limit the sources of indirect jumps to those that set up a matching label according to a `scheme' selected at compile time. This flag controls the selection of that `scheme'. It's named `-fcf-branch-label-scheme` since the generation of landing pad insns is turned on by `-fcf-protection=branch`. --- .../include/clang/Basic/CFProtectionOptions.h | 22 +++ clang/include/clang/Basic/CodeGenOptions.def | 2 + clang/include/clang/Basic/CodeGenOptions.h| 1 + .../clang/Basic/DiagnosticDriverKinds.td | 3 ++ clang/include/clang/Basic/LangOptions.def | 2 + clang/include/clang/Basic/LangOptions.h | 2 + clang/include/clang/Basic/TargetInfo.h| 4 ++ clang/include/clang/Driver/Options.td | 4 ++ clang/lib/Basic/TargetInfo.cpp| 5 +++ clang/lib/Basic/Targets/RISCV.h | 4 ++ clang/lib/Basic/Targets/X86.h | 4 ++ clang/lib/Driver/ToolChains/Clang.cpp | 4 ++ clang/lib/Frontend/CompilerInvocation.cpp | 39 +++ 13 files changed, 96 insertions(+) create mode 100644 clang/include/clang/Basic/CFProtectionOptions.h diff --git a/clang/include/clang/Basic/CFProtectionOptions.h b/clang/include/clang/Basic/CFProtectionOptions.h new file mode 100644 index 00..d97f8489c4631f --- /dev/null +++ b/clang/include/clang/Basic/CFProtectionOptions.h @@ -0,0 +1,22 @@ +//===--- CFProtectionOptions.h --*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// This file defines constants for -fcf-protection and other related flags. +// +//===--===// + +#ifndef LLVM_CLANG_BASIC_CFPROTECTIONOPTIONS_H +#define LLVM_CLANG_BASIC_CFPROTECTIONOPTIONS_H + +namespace clang { + +enum class CFBranchLabelSchemeKind { Default, Unlabeled, FuncSig }; + +} // namespace clang + +#endif // #ifndef LLVM_CLANG_BASIC_CFPROTECTIONOPTIONS_H diff --git a/clang/include/clang/Basic/CodeGenOptions.def b/clang/include/clang/Basic/CodeGenOptions.def index b600198998d85b..feda4260e320c2 100644 --- a/clang/include/clang/Basic/CodeGenOptions.def +++ b/clang/include/clang/Basic/CodeGenOptions.def @@ -110,6 +110,8 @@ CODEGENOPT(CFProtectionReturn , 1, 0) ///< if -fcf-protection is ///< set to full or return. CODEGENOPT(CFProtectionBranch , 1, 0) ///< if -fcf-protection is ///< set to full or branch. +ENUM_CODEGENOPT(CFBranchLabelScheme, CFBranchLabelSchemeKind, 2, +CFBranchLabelSchemeKind::Default) ///< if -fcf-branch-label-scheme is set. CODEGENOPT(FunctionReturnThunks, 1, 0) ///< -mfunction-return={keep|thunk-extern} CODEGENOPT(IndirectBranchCSPrefix, 1, 0) ///< if -mindirect-branch-c
[clang] [Clang][RISCV] Add preprocessor macros for Zicfilp CFI scheme (PR #109600)
llvmbot wrote: @llvm/pr-subscribers-backend-risc-v Author: Ming-Yi Lai (mylai-mtk) Changes This patch adds preprocessor macros when Zicfilp CFI is enabled. The macros are proposed in riscv-non-isa/riscv-c-api-doc#76 , and the CLI flags are from riscv-non-isa/riscv-toolchain-conventions#54. --- Full diff: https://github.com/llvm/llvm-project/pull/109600.diff 15 Files Affected: - (added) clang/include/clang/Basic/CFProtectionOptions.h (+22) - (modified) clang/include/clang/Basic/CodeGenOptions.def (+2) - (modified) clang/include/clang/Basic/CodeGenOptions.h (+1) - (modified) clang/include/clang/Basic/DiagnosticDriverKinds.td (+3) - (modified) clang/include/clang/Basic/LangOptions.def (+2) - (modified) clang/include/clang/Basic/LangOptions.h (+2) - (modified) clang/include/clang/Basic/TargetInfo.h (+4) - (modified) clang/include/clang/Driver/Options.td (+4) - (modified) clang/lib/Basic/TargetInfo.cpp (+5) - (modified) clang/lib/Basic/Targets/RISCV.cpp (+20) - (modified) clang/lib/Basic/Targets/RISCV.h (+11) - (modified) clang/lib/Basic/Targets/X86.h (+4) - (modified) clang/lib/Driver/ToolChains/Clang.cpp (+4) - (modified) clang/lib/Frontend/CompilerInvocation.cpp (+39) - (modified) clang/test/Preprocessor/riscv-target-features.c (+32) ``diff diff --git a/clang/include/clang/Basic/CFProtectionOptions.h b/clang/include/clang/Basic/CFProtectionOptions.h new file mode 100644 index 00..d97f8489c4631f --- /dev/null +++ b/clang/include/clang/Basic/CFProtectionOptions.h @@ -0,0 +1,22 @@ +//===--- CFProtectionOptions.h --*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// This file defines constants for -fcf-protection and other related flags. +// +//===--===// + +#ifndef LLVM_CLANG_BASIC_CFPROTECTIONOPTIONS_H +#define LLVM_CLANG_BASIC_CFPROTECTIONOPTIONS_H + +namespace clang { + +enum class CFBranchLabelSchemeKind { Default, Unlabeled, FuncSig }; + +} // namespace clang + +#endif // #ifndef LLVM_CLANG_BASIC_CFPROTECTIONOPTIONS_H diff --git a/clang/include/clang/Basic/CodeGenOptions.def b/clang/include/clang/Basic/CodeGenOptions.def index b600198998d85b..feda4260e320c2 100644 --- a/clang/include/clang/Basic/CodeGenOptions.def +++ b/clang/include/clang/Basic/CodeGenOptions.def @@ -110,6 +110,8 @@ CODEGENOPT(CFProtectionReturn , 1, 0) ///< if -fcf-protection is ///< set to full or return. CODEGENOPT(CFProtectionBranch , 1, 0) ///< if -fcf-protection is ///< set to full or branch. +ENUM_CODEGENOPT(CFBranchLabelScheme, CFBranchLabelSchemeKind, 2, +CFBranchLabelSchemeKind::Default) ///< if -fcf-branch-label-scheme is set. CODEGENOPT(FunctionReturnThunks, 1, 0) ///< -mfunction-return={keep|thunk-extern} CODEGENOPT(IndirectBranchCSPrefix, 1, 0) ///< if -mindirect-branch-cs-prefix ///< is set. diff --git a/clang/include/clang/Basic/CodeGenOptions.h b/clang/include/clang/Basic/CodeGenOptions.h index f2a707a8ba8d76..a6953c17a447ef 100644 --- a/clang/include/clang/Basic/CodeGenOptions.h +++ b/clang/include/clang/Basic/CodeGenOptions.h @@ -13,6 +13,7 @@ #ifndef LLVM_CLANG_BASIC_CODEGENOPTIONS_H #define LLVM_CLANG_BASIC_CODEGENOPTIONS_H +#include "clang/Basic/CFProtectionOptions.h" #include "clang/Basic/PointerAuthOptions.h" #include "clang/Basic/Sanitizers.h" #include "clang/Basic/XRayInstr.h" diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td index 97573fcf20c1fb..34676e02718fe1 100644 --- a/clang/include/clang/Basic/DiagnosticDriverKinds.td +++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td @@ -817,6 +817,9 @@ def err_drv_experimental_crel : Error< "-Wa,--allow-experimental-crel must be specified to use -Wa,--crel. " "CREL is experimental and uses a non-standard section type code">; +def warn_drv_opt_ignored_by_other : Warning<"ignoring option '%0' due to '%1'">, + InGroup; + def warn_android_unversioned_fallback : Warning< "using unversioned Android target directory %0 for target %1; unversioned " "directories will not be used in Clang 19 -- provide a versioned directory " diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def index fd3346d29f26a3..68db400c22e6c1 100644 --- a/clang/include/clang/Basic/LangOptions.def +++ b/clang/include/clang/Basic/LangOptions.def @@ -364,6 +364,8 @@ BENIGN_LANGOPT(CompatibilityQualifiedIdBlockParamTypeChecking, 1, 0, LANGOPT(ObjCDisableDirectMethodsForTesting, 1, 0, "Disable recognition of objc_dire
[clang] [flang] [Driver][X86] Add flang visibility for -m[no-]evex512 (PR #109598)
https://github.com/KanRobert commented: LGTM https://github.com/llvm/llvm-project/pull/109598 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Include LLVM CodeGen CMake file (PR #109601)
https://github.com/RossComputerGuy created https://github.com/llvm/llvm-project/pull/109601 Fixes a build failure with Clang being built from standalone sources (environments like Nix). Exact error: ``` CMake Error at /nix/store/h9yw8mg03z3dz6rgcjr7gbzkjysqc2sj-llvm-20.0.0-unstable-2024-09-22-dev/lib/cmake/llvm/AddLLVM.cmake:587 (add_dependencies): The dependency target "vt_gen" of target "obj.clangCodeGen" does not exist. Call Stack (most recent call first): cmake/modules/AddClang.cmake:109 (llvm_add_library) lib/CodeGen/CMakeLists.txt:57 (add_clang_library) CMake Error at /nix/store/h9yw8mg03z3dz6rgcjr7gbzkjysqc2sj-llvm-20.0.0-unstable-2024-09-22-dev/lib/cmake/llvm/AddLLVM.cmake:807 (add_dependencies): The dependency target "vt_gen" of target "clangCodeGen" does not exist. Call Stack (most recent call first): cmake/modules/AddClang.cmake:109 (llvm_add_library) lib/CodeGen/CMakeLists.txt:57 (add_clang_library) ``` This fix can be reproduced via the following script (just set out to some remote source and monorepoSrc to your LLVM source dir): ``` mkdir -p "$out" cp -r ${monorepoSrc}/cmake "$out" cp -r ${monorepoSrc}/${pname} "$out" cp -r ${monorepoSrc}/clang-tools-extra "$out" mkdir -p "$out/llvm/include/llvm/CodeGen" cp -r ${monorepoSrc}/llvm/include/llvm/CodeGen/CMakeLists.txt "$out/llvm/include/llvm/CodeGen/" mkdir -p "$out/clang/include/llvm" cp -r ${monorepoSrc}/llvm/include/llvm/CodeGen $out/clang/include/llvm/CodeGen ``` >From a64ba9cc4f2c70f6040c1954fedc5674bba96575 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Sun, 22 Sep 2024 21:02:12 -0700 Subject: [PATCH] [Clang] Include LLVM CodeGen CMake file --- clang/lib/CodeGen/CMakeLists.txt | 4 1 file changed, 4 insertions(+) diff --git a/clang/lib/CodeGen/CMakeLists.txt b/clang/lib/CodeGen/CMakeLists.txt index 868ec847b9634b..2b1be3f4c3035d 100644 --- a/clang/lib/CodeGen/CMakeLists.txt +++ b/clang/lib/CodeGen/CMakeLists.txt @@ -1,3 +1,7 @@ +if(EXISTS ${LLVM_MAIN_SRC_DIR}/include/llvm/CodeGen) + add_subdirectory(${LLVM_MAIN_SRC_DIR}/include/llvm/CodeGen llvm/lib/CodeGen) +endif() + set(LLVM_LINK_COMPONENTS AggressiveInstCombine Analysis ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Include LLVM CodeGen CMake file (PR #109601)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Tristan Ross (RossComputerGuy) Changes Fixes a build failure with Clang being built from standalone sources (environments like Nix). Exact error: ``` CMake Error at /nix/store/h9yw8mg03z3dz6rgcjr7gbzkjysqc2sj-llvm-20.0.0-unstable-2024-09-22-dev/lib/cmake/llvm/AddLLVM.cmake:587 (add_dependencies): The dependency target "vt_gen" of target "obj.clangCodeGen" does not exist. Call Stack (most recent call first): cmake/modules/AddClang.cmake:109 (llvm_add_library) lib/CodeGen/CMakeLists.txt:57 (add_clang_library) CMake Error at /nix/store/h9yw8mg03z3dz6rgcjr7gbzkjysqc2sj-llvm-20.0.0-unstable-2024-09-22-dev/lib/cmake/llvm/AddLLVM.cmake:807 (add_dependencies): The dependency target "vt_gen" of target "clangCodeGen" does not exist. Call Stack (most recent call first): cmake/modules/AddClang.cmake:109 (llvm_add_library) lib/CodeGen/CMakeLists.txt:57 (add_clang_library) ``` This fix can be reproduced via the following script (just set out to some remote source and monorepoSrc to your LLVM source dir): ``` mkdir -p "$out" cp -r ${monorepoSrc}/cmake "$out" cp -r ${monorepoSrc}/${pname} "$out" cp -r ${monorepoSrc}/clang-tools-extra "$out" mkdir -p "$out/llvm/include/llvm/CodeGen" cp -r ${monorepoSrc}/llvm/include/llvm/CodeGen/CMakeLists.txt "$out/llvm/include/llvm/CodeGen/" mkdir -p "$out/clang/include/llvm" cp -r ${monorepoSrc}/llvm/include/llvm/CodeGen $out/clang/include/llvm/CodeGen ``` --- Full diff: https://github.com/llvm/llvm-project/pull/109601.diff 1 Files Affected: - (modified) clang/lib/CodeGen/CMakeLists.txt (+4) ``diff diff --git a/clang/lib/CodeGen/CMakeLists.txt b/clang/lib/CodeGen/CMakeLists.txt index 868ec847b9634b..2b1be3f4c3035d 100644 --- a/clang/lib/CodeGen/CMakeLists.txt +++ b/clang/lib/CodeGen/CMakeLists.txt @@ -1,3 +1,7 @@ +if(EXISTS ${LLVM_MAIN_SRC_DIR}/include/llvm/CodeGen) + add_subdirectory(${LLVM_MAIN_SRC_DIR}/include/llvm/CodeGen llvm/lib/CodeGen) +endif() + set(LLVM_LINK_COMPONENTS AggressiveInstCombine Analysis `` https://github.com/llvm/llvm-project/pull/109601 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [AST] Avoid repeated hash lookups (NFC) (PR #109603)
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/109603 None >From 6d29a8a0d011a13a9ac17fa4bf53523cfc70992d Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Sun, 22 Sep 2024 07:54:30 -0700 Subject: [PATCH] [AST] Avoid repeated hash lookups (NFC) --- clang/lib/AST/ASTContext.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 8bd5abf2bf9643..fd8aa8de79b49f 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -12587,8 +12587,7 @@ void ASTContext::forEachMultiversionedFunctionVersion( FD->getDeclContext()->getRedeclContext()->lookup(FD->getDeclName())) { FunctionDecl *CurFD = CurDecl->getAsFunction()->getMostRecentDecl(); if (CurFD && hasSameType(CurFD->getType(), FD->getType()) && -!SeenDecls.contains(CurFD)) { - SeenDecls.insert(CurFD); +SeenDecls.insert(CurFD).second) { Pred(CurFD); } } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][RISCV] Add preprocessor macros for Zicfilp CFI scheme (PR #109600)
@@ -2022,6 +2035,22 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Name; } + if (const Arg *const A = Args.getLastArg(OPT_fcf_branch_label_scheme_EQ)) { kito-cheng wrote: ```suggestion if (const Arg *A = Args.getLastArg(OPT_fcf_branch_label_scheme_EQ)) { ``` For consistency with other site within this file. https://github.com/llvm/llvm-project/pull/109600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][RISCV] Add preprocessor macros for Zicfilp CFI scheme (PR #109600)
@@ -3952,6 +3981,16 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args, } } + if (const Arg *const A = Args.getLastArg(OPT_fcf_branch_label_scheme_EQ)) { kito-cheng wrote: ```suggestion if (const Arg *A = Args.getLastArg(OPT_fcf_branch_label_scheme_EQ)) { ``` ```suggestion if (const Arg *A = Args.getLastArg(OPT_fcf_branch_label_scheme_EQ)) { ``` For consistency with other site within this file. https://github.com/llvm/llvm-project/pull/109600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [AST] Avoid repeated hash lookups (NFC) (PR #109603)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Kazu Hirata (kazutakahirata) Changes --- Full diff: https://github.com/llvm/llvm-project/pull/109603.diff 1 Files Affected: - (modified) clang/lib/AST/ASTContext.cpp (+1-2) ``diff diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 8bd5abf2bf9643..fd8aa8de79b49f 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -12587,8 +12587,7 @@ void ASTContext::forEachMultiversionedFunctionVersion( FD->getDeclContext()->getRedeclContext()->lookup(FD->getDeclName())) { FunctionDecl *CurFD = CurDecl->getAsFunction()->getMostRecentDecl(); if (CurFD && hasSameType(CurFD->getType(), FD->getType()) && -!SeenDecls.contains(CurFD)) { - SeenDecls.insert(CurFD); +SeenDecls.insert(CurFD).second) { Pred(CurFD); } } `` https://github.com/llvm/llvm-project/pull/109603 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][RISCV] Add preprocessor macros for Zicfilp CFI scheme (PR #109600)
@@ -1781,3 +1781,35 @@ // RUN: %clang --target=riscv64-unknown-linux-gnu -mcpu=sifive-p450 -E -dM %s \ // RUN: -o - | FileCheck %s --check-prefix=CHECK-MISALIGNED-FAST // CHECK-MISALIGNED-FAST: __riscv_misaligned_fast 1 + +// Landing Pad + +// RUN: %clang --target=riscv32 -menable-experimental-extensions \ +// RUN: -march=rv32i_zicfilp1p0 -fcf-protection=branch \ +// RUN: -fcf-branch-label-scheme=unlabeled -E -dM %s -o - \ +// RUN: | FileCheck --check-prefix=CHECK-ZICFILP-UNLABELED %s +// RUN: %clang --target=riscv64 -menable-experimental-extensions \ +// RUN: -march=rv64i_zicfilp1p0 -fcf-protection=branch \ +// RUN: -fcf-branch-label-scheme=unlabeled -E -dM %s -o - \ +// RUN: | FileCheck --check-prefix=CHECK-ZICFILP-UNLABELED %s +// CHECK-ZICFILP-UNLABELED-DAG: __riscv_landing_pad 1{{$}} +// CHECK-ZICFILP-UNLABELED-DAG: __riscv_landing_pad_unlabeled 1{{$}} kito-cheng wrote: Add test case for 1. `-march=rv32i -fcf-protection=branch -fcf-branch-label-scheme=*` and `-march=rv64i -fcf-protection=branch -fcf-branch-label-scheme=*` 2. `-march=rv32i -fcf-branch-label-scheme=*` and `-march=rv64i -fcf-branch-label-scheme=*` 3. `-march=rv32i_zicfilp -fcf-branch-label-scheme=*` and `-march=rv64i_zicfilp -fcf-branch-label-scheme=*` https://github.com/llvm/llvm-project/pull/109600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Rewrite] Avoid repeated hash lookups (NFC) (PR #109605)
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/109605 None >From 50ce6d0114f8abd4b5580d2c277525eebdf25874 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Sun, 22 Sep 2024 08:05:27 -0700 Subject: [PATCH] [Rewrite] Avoid repeated hash lookups (NFC) --- clang/lib/Frontend/Rewrite/RewriteObjC.cpp | 8 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/clang/lib/Frontend/Rewrite/RewriteObjC.cpp b/clang/lib/Frontend/Rewrite/RewriteObjC.cpp index 180a0125023ee7..ac5baf72a65c90 100644 --- a/clang/lib/Frontend/Rewrite/RewriteObjC.cpp +++ b/clang/lib/Frontend/Rewrite/RewriteObjC.cpp @@ -4358,21 +4358,21 @@ Stmt *RewriteObjC::SynthBlockInitExpr(BlockExpr *Exp, for (unsigned i = 0; i < InnerBlockDeclRefs.size(); i++) { DeclRefExpr *Exp = InnerBlockDeclRefs[i]; ValueDecl *VD = Exp->getDecl(); - if (!VD->hasAttr() && !BlockByCopyDeclsPtrSet.count(VD)) { + if (!VD->hasAttr() && + BlockByCopyDeclsPtrSet.insert(VD).second) { // We need to save the copied-in variables in nested // blocks because it is needed at the end for some of the API // generations. See SynthesizeBlockLiterals routine. InnerDeclRefs.push_back(Exp); countOfInnerDecls++; BlockDeclRefs.push_back(Exp); -BlockByCopyDeclsPtrSet.insert(VD); BlockByCopyDecls.push_back(VD); } - if (VD->hasAttr() && !BlockByRefDeclsPtrSet.count(VD)) { + if (VD->hasAttr() && + BlockByRefDeclsPtrSet.insert(VD).second) { InnerDeclRefs.push_back(Exp); countOfInnerDecls++; BlockDeclRefs.push_back(Exp); -BlockByRefDeclsPtrSet.insert(VD); BlockByRefDecls.push_back(VD); } } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Rewrite] Avoid repeated hash lookups (NFC) (PR #109605)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Kazu Hirata (kazutakahirata) Changes --- Full diff: https://github.com/llvm/llvm-project/pull/109605.diff 1 Files Affected: - (modified) clang/lib/Frontend/Rewrite/RewriteObjC.cpp (+4-4) ``diff diff --git a/clang/lib/Frontend/Rewrite/RewriteObjC.cpp b/clang/lib/Frontend/Rewrite/RewriteObjC.cpp index 180a0125023ee7..ac5baf72a65c90 100644 --- a/clang/lib/Frontend/Rewrite/RewriteObjC.cpp +++ b/clang/lib/Frontend/Rewrite/RewriteObjC.cpp @@ -4358,21 +4358,21 @@ Stmt *RewriteObjC::SynthBlockInitExpr(BlockExpr *Exp, for (unsigned i = 0; i < InnerBlockDeclRefs.size(); i++) { DeclRefExpr *Exp = InnerBlockDeclRefs[i]; ValueDecl *VD = Exp->getDecl(); - if (!VD->hasAttr() && !BlockByCopyDeclsPtrSet.count(VD)) { + if (!VD->hasAttr() && + BlockByCopyDeclsPtrSet.insert(VD).second) { // We need to save the copied-in variables in nested // blocks because it is needed at the end for some of the API // generations. See SynthesizeBlockLiterals routine. InnerDeclRefs.push_back(Exp); countOfInnerDecls++; BlockDeclRefs.push_back(Exp); -BlockByCopyDeclsPtrSet.insert(VD); BlockByCopyDecls.push_back(VD); } - if (VD->hasAttr() && !BlockByRefDeclsPtrSet.count(VD)) { + if (VD->hasAttr() && + BlockByRefDeclsPtrSet.insert(VD).second) { InnerDeclRefs.push_back(Exp); countOfInnerDecls++; BlockDeclRefs.push_back(Exp); -BlockByRefDeclsPtrSet.insert(VD); BlockByRefDecls.push_back(VD); } } `` https://github.com/llvm/llvm-project/pull/109605 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Include LLVM CodeGen CMake file (PR #109601)
https://github.com/RossComputerGuy updated https://github.com/llvm/llvm-project/pull/109601 >From cab2a5cebdc63425ed03a31028e6eb2aee00e5d9 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Sun, 22 Sep 2024 21:02:12 -0700 Subject: [PATCH] [Clang] Include LLVM CodeGen CMake file --- clang/lib/CodeGen/CMakeLists.txt | 4 1 file changed, 4 insertions(+) diff --git a/clang/lib/CodeGen/CMakeLists.txt b/clang/lib/CodeGen/CMakeLists.txt index 868ec847b9634b..351a606f65b5be 100644 --- a/clang/lib/CodeGen/CMakeLists.txt +++ b/clang/lib/CodeGen/CMakeLists.txt @@ -1,3 +1,7 @@ +if(EXISTS ${LLVM_MAIN_SRC_DIR}/include/llvm/CodeGen AND CLANG_BUILT_STANDALONE) + add_subdirectory(${LLVM_MAIN_SRC_DIR}/include/llvm/CodeGen llvm/lib/CodeGen) +endif() + set(LLVM_LINK_COMPONENTS AggressiveInstCombine Analysis ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix regression with BlockIndent of Braced Initializers (PR #108717)
https://github.com/owenca approved this pull request. https://github.com/llvm/llvm-project/pull/108717 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] df935ff - [clang-format] Fix regression with BlockIndent of Braced Initializers (#108717)
Author: Gedare Bloom Date: 2024-09-22T14:31:19-07:00 New Revision: df935ff4eca91013553edbf3ca1d45b568f6709f URL: https://github.com/llvm/llvm-project/commit/df935ff4eca91013553edbf3ca1d45b568f6709f DIFF: https://github.com/llvm/llvm-project/commit/df935ff4eca91013553edbf3ca1d45b568f6709f.diff LOG: [clang-format] Fix regression with BlockIndent of Braced Initializers (#108717) Fixes #73584. Added: Modified: clang/lib/Format/ContinuationIndenter.cpp clang/unittests/Format/FormatTest.cpp Removed: diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index 4e9ae41b566f49..4df8dc89be459f 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -348,6 +348,13 @@ bool ContinuationIndenter::canBreak(const LineState &State) { } } + // Don't allow breaking before a closing brace of a block-indented braced list + // initializer if there isn't already a break. + if (Current.is(tok::r_brace) && Current.MatchingParen && + Current.isBlockIndentedInitRBrace(Style)) { +return CurrentState.BreakBeforeClosingBrace; + } + // If binary operators are moved to the next line (including commas for some // styles of constructor initializers), that's always ok. if (!Current.isOneOf(TT_BinaryOperator, tok::comma) && diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 53aa93a7a4fb01..5d386c1bbdbcd9 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -9441,6 +9441,11 @@ TEST_F(FormatTest, AlignsAfterOpenBracket) { "\n" ");", Style); + verifyFormat("aaa const aa{\n" + "a(aaa, )\n" + "};", + Style); + verifyFormat("bool aaa(\n" "const bool &a, const void *aa\n" ") const {\n" ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix regression with BlockIndent of Braced Initializers (PR #108717)
https://github.com/owenca closed https://github.com/llvm/llvm-project/pull/108717 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] clang-format: Add AlignFunctionDeclarations attribute to AlignConsecutiveDeclarations (PR #108241)
https://github.com/owenca edited https://github.com/llvm/llvm-project/pull/108241 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] clang-format: Add AlignFunctionDeclarations attribute to AlignConsecutiveDeclarations (PR #108241)
https://github.com/owenca edited https://github.com/llvm/llvm-project/pull/108241 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] clang-format: Add AlignFunctionDeclarations attribute to AlignConsecutiveDeclarations (PR #108241)
@@ -225,6 +225,21 @@ struct FormatStyle { /// bbb = 2; /// \endcode bool AlignCompound; +/// Only for ``AlignConsecutiveDeclarations``. Whether function declarations +/// are aligned. +/// \code +/// true: +/// unsigned int f1(void); +/// void f2(void); +/// size_t f3(void); +/// +/// false: +/// unsigned int f1(void); +/// void f2(void); +/// size_t f3(void); +/// \endcode +/// \version 20 owenca wrote: GitHub review comments is about the line above unless a range of lines are shown like in https://github.com/llvm/llvm-project/pull/106145/files#r1769761150. https://github.com/llvm/llvm-project/pull/108241 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] clang-format: Add AlignFunctionDeclarations attribute to AlignConsecutiveDeclarations (PR #108241)
@@ -409,6 +409,21 @@ the configuration (without a prefix: ``Auto``). int *p; int (*f)(); + * ``bool AlignFunctionDeclarations`` Only for ``AlignConsecutiveDeclarations``. Whether function declarations owenca wrote: Version badge is unsupported for sub-options. https://github.com/llvm/llvm-project/pull/108241 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] clang-format: Add AlignFunctionDeclarations attribute to AlignConsecutiveDeclarations (PR #108241)
@@ -225,6 +225,21 @@ struct FormatStyle { /// bbb = 2; /// \endcode bool AlignCompound; +/// Only for ``AlignConsecutiveDeclarations``. Whether function declarations +/// are aligned. +/// \code +/// true: +/// unsigned int f1(void); +/// void f2(void); +/// size_t f3(void); +/// +/// false: +/// unsigned int f1(void); +/// void f2(void); +/// size_t f3(void); +/// \endcode +/// \version 20 bradh352 wrote: ok, so omit the \version is what you're saying ... but @mydeveloperday said it should be versioned. Is the version annotation in the wrong place perhaps? Or maybe its just unsupported to version a sub attribute. https://github.com/llvm/llvm-project/pull/108241 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] clang-format: Add AlignFunctionDeclarations attribute to AlignConsecutiveDeclarations (PR #108241)
@@ -409,6 +409,21 @@ the configuration (without a prefix: ``Auto``). int *p; int (*f)(); + * ``bool AlignFunctionDeclarations`` Only for ``AlignConsecutiveDeclarations``. Whether function declarations bradh352 wrote: ah, gotcha https://github.com/llvm/llvm-project/pull/108241 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] clang-format: Add AlignFunctionDeclarations attribute to AlignConsecutiveDeclarations (PR #108241)
https://github.com/bradh352 updated https://github.com/llvm/llvm-project/pull/108241 >From 00cbf31807ca8d8e1c0c86c6a691c47835522fe9 Mon Sep 17 00:00:00 2001 From: Brad House Date: Wed, 11 Sep 2024 10:27:50 -0400 Subject: [PATCH 1/2] Add AlignFunctionDeclarations attribute to AlignConsecutiveDeclarations Enabling AlignConsecutiveDeclarations also aligns function prototypes or declarations. This is often unexpected as typically function prototypes, especially in public headers, don't use any padding. Setting AlignFunctionDeclarations to false will skip this alignment. It is by default set to true to keep compatibility with prior versions to not make unexpected changes. Signed-off-by: Brad House --- clang/docs/ClangFormatStyleOptions.rst | 112 + clang/include/clang/Format/Format.h| 16 +++ clang/lib/Format/Format.cpp| 31 -- clang/lib/Format/WhitespaceManager.cpp | 2 +- clang/unittests/Format/ConfigParseTest.cpp | 6 ++ clang/unittests/Format/FormatTest.cpp | 22 +++- 6 files changed, 179 insertions(+), 10 deletions(-) diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst index a427d7cd40fcdd..042c5f1b5f15b0 100644 --- a/clang/docs/ClangFormatStyleOptions.rst +++ b/clang/docs/ClangFormatStyleOptions.rst @@ -392,6 +392,22 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + Only for ``AlignConsecutiveDeclarations``. Whether function declarations +are aligned. + +.. code-block:: c++ + + true: + unsigned int f1(void); + void f2(void); + size_t f3(void); + + false: + unsigned int f1(void); + void f2(void); + size_t f3(void); + * ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveDeclarations``. Whether function pointers are aligned. @@ -534,6 +550,22 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + Only for ``AlignConsecutiveDeclarations``. Whether function declarations +are aligned. + +.. code-block:: c++ + + true: + unsigned int f1(void); + void f2(void); + size_t f3(void); + + false: + unsigned int f1(void); + void f2(void); + size_t f3(void); + * ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveDeclarations``. Whether function pointers are aligned. @@ -676,6 +708,22 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + Only for ``AlignConsecutiveDeclarations``. Whether function declarations +are aligned. + +.. code-block:: c++ + + true: + unsigned int f1(void); + void f2(void); + size_t f3(void); + + false: + unsigned int f1(void); + void f2(void); + size_t f3(void); + * ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveDeclarations``. Whether function pointers are aligned. @@ -819,6 +867,22 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + Only for ``AlignConsecutiveDeclarations``. Whether function declarations +are aligned. + +.. code-block:: c++ + + true: + unsigned int f1(void); + void f2(void); + size_t f3(void); + + false: + unsigned int f1(void); + void f2(void); + size_t f3(void); + * ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveDeclarations``. Whether function pointers are aligned. @@ -1081,6 +1145,22 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + Only for ``AlignConsecutiveDeclarations``. Whether function declarations +are aligned. + +.. code-block:: c++ + + true: + unsigned int f1(void); + void f2(void); + size_t f3(void); + + false: + unsigned int f1(void); + void f2(void); + size_t f3(void); + * ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveDeclarations``. Whether function pointers are aligned. @@ -1221,6 +1301,22 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + Only for ``AlignConsecutiveDeclarations``. Whether function declarations +are aligned. + +.. code-block:: c++ + + true: + unsigned int f1(void); + void f2(void); + size_t f3(void); + + false: + unsigned int f1(void); + void f2(void); + size_t f3(void); + * ``bool AlignFunctionPointers`` Only for ``AlignConsecu
[clang] clang-format: Add AlignFunctionDeclarations attribute to AlignConsecutiveDeclarations (PR #108241)
@@ -225,6 +225,21 @@ struct FormatStyle { /// bbb = 2; /// \endcode bool AlignCompound; +/// Only for ``AlignConsecutiveDeclarations``. Whether function declarations +/// are aligned. +/// \code +/// true: +/// unsigned int f1(void); +/// void f2(void); +/// size_t f3(void); +/// +/// false: +/// unsigned int f1(void); +/// void f2(void); +/// size_t f3(void); +/// \endcode +/// \version 20 bradh352 wrote: done, i see where you said sub options are not allowed to be versioned. https://github.com/llvm/llvm-project/pull/108241 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix regression with BlockIndent of Braced Initializers (PR #108717)
https://github.com/gedare updated https://github.com/llvm/llvm-project/pull/108717 >From a95b990e48df19b8b674fe9df6bea803415129bf Mon Sep 17 00:00:00 2001 From: Gedare Bloom Date: Sat, 14 Sep 2024 13:13:26 -0600 Subject: [PATCH 1/3] [clang-format] Fix regression with BlockIndent of Braced Initializers Fixes #73584. --- clang/lib/Format/ContinuationIndenter.cpp | 7 +++ clang/unittests/Format/FormatTest.cpp | 11 +++ 2 files changed, 18 insertions(+) diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index f29f8796ea9290..5c77af2da5add5 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -348,6 +348,13 @@ bool ContinuationIndenter::canBreak(const LineState &State) { } } + // Don't allow breaking before a closing right brace of a block-indented + // braced list initializer if there was not already a break. + if (Current.is(tok::r_brace) && Current.MatchingParen && + Current.isBlockIndentedInitRBrace(Style)) { +return CurrentState.BreakBeforeClosingBrace; + } + // If binary operators are moved to the next line (including commas for some // styles of constructor initializers), that's always ok. if (!Current.isOneOf(TT_BinaryOperator, tok::comma) && diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 5ebf0d7068dd6c..d1cb2b053e33d6 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -9336,6 +9336,9 @@ TEST_F(FormatTest, AlignsAfterOpenBracket) { "ccc(a, //\n" "b));", Style); + verifyFormat("aaa const aa{\n" + "a(aaa, )};", + Style); Style.ColumnLimit = 30; verifyFormat("for (int foo = 0; foo < FOO;\n" @@ -9395,6 +9398,9 @@ TEST_F(FormatTest, AlignsAfterOpenBracket) { "fooo(new FOO::BA(\n" "XXXZ()));", Style); + verifyFormat("aaa const aa{\n" + "a(aaa, )};", + Style); Style.AlignAfterOpenBracket = FormatStyle::BAS_BlockIndent; Style.BinPackArguments = false; @@ -9441,6 +9447,11 @@ TEST_F(FormatTest, AlignsAfterOpenBracket) { "\n" ");", Style); + verifyFormat("aaa const aa{\n" + "a(aaa, )\n" + "};", + Style); + verifyFormat("bool aaa(\n" "const bool &a, const void *aa\n" ") const {\n" >From f53155d15961be7e1f992814abe4eda53e9fa9cb Mon Sep 17 00:00:00 2001 From: Gedare Bloom Date: Sun, 22 Sep 2024 14:12:22 -0600 Subject: [PATCH 2/3] Remove superfluous test cases --- clang/unittests/Format/FormatTest.cpp | 6 -- 1 file changed, 6 deletions(-) diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index d1cb2b053e33d6..213631e29ae536 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -9336,9 +9336,6 @@ TEST_F(FormatTest, AlignsAfterOpenBracket) { "ccc(a, //\n" "b));", Style); - verifyFormat("aaa const aa{\n" - "a(aaa, )};", - Style); Style.ColumnLimit = 30; verifyFormat("for (int foo = 0; foo < FOO;\n" @@ -9398,9 +9395,6 @@ TEST_F(FormatTest, AlignsAfterOpenBracket) { "fooo(new FOO::BA(\n" "XXXZ()));", Style); - verifyFormat("aaa const aa{\n" - "a(aaa, )};", - Style); Style.AlignAfterOpenBracket = FormatStyle::BAS_BlockIndent; Style.BinPackArguments = false; >From 0738a90b387520a59a1d4c2dac28c96fe65c4548 Mon Sep 17 00:00:00 2001 From: Gedare Bloom Date: Sun, 22 Sep 2024 14:13:05 -0600 Subject: [PATCH 3/3] Update clang/lib/Format/ContinuationIndenter.cpp Co-authored-by: Owen Pan --- clang/lib/Format/ContinuationIndenter.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index 5c77af2da5add5..c04cb9d5843ce7 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -348,8 +348,8 @@ bool ContinuationIndenter::canBreak(const LineState &State) { } } - // Don't allow breaking before a closing right brace of a block-indented - // braced list initializer if there was not already a break. + // Don't allow
[clang] [clang-format] Fix regression with BlockIndent of Braced Initializers (PR #108717)
https://github.com/gedare updated https://github.com/llvm/llvm-project/pull/108717 >From a95b990e48df19b8b674fe9df6bea803415129bf Mon Sep 17 00:00:00 2001 From: Gedare Bloom Date: Sat, 14 Sep 2024 13:13:26 -0600 Subject: [PATCH 1/2] [clang-format] Fix regression with BlockIndent of Braced Initializers Fixes #73584. --- clang/lib/Format/ContinuationIndenter.cpp | 7 +++ clang/unittests/Format/FormatTest.cpp | 11 +++ 2 files changed, 18 insertions(+) diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index f29f8796ea9290..5c77af2da5add5 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -348,6 +348,13 @@ bool ContinuationIndenter::canBreak(const LineState &State) { } } + // Don't allow breaking before a closing right brace of a block-indented + // braced list initializer if there was not already a break. + if (Current.is(tok::r_brace) && Current.MatchingParen && + Current.isBlockIndentedInitRBrace(Style)) { +return CurrentState.BreakBeforeClosingBrace; + } + // If binary operators are moved to the next line (including commas for some // styles of constructor initializers), that's always ok. if (!Current.isOneOf(TT_BinaryOperator, tok::comma) && diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 5ebf0d7068dd6c..d1cb2b053e33d6 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -9336,6 +9336,9 @@ TEST_F(FormatTest, AlignsAfterOpenBracket) { "ccc(a, //\n" "b));", Style); + verifyFormat("aaa const aa{\n" + "a(aaa, )};", + Style); Style.ColumnLimit = 30; verifyFormat("for (int foo = 0; foo < FOO;\n" @@ -9395,6 +9398,9 @@ TEST_F(FormatTest, AlignsAfterOpenBracket) { "fooo(new FOO::BA(\n" "XXXZ()));", Style); + verifyFormat("aaa const aa{\n" + "a(aaa, )};", + Style); Style.AlignAfterOpenBracket = FormatStyle::BAS_BlockIndent; Style.BinPackArguments = false; @@ -9441,6 +9447,11 @@ TEST_F(FormatTest, AlignsAfterOpenBracket) { "\n" ");", Style); + verifyFormat("aaa const aa{\n" + "a(aaa, )\n" + "};", + Style); + verifyFormat("bool aaa(\n" "const bool &a, const void *aa\n" ") const {\n" >From f53155d15961be7e1f992814abe4eda53e9fa9cb Mon Sep 17 00:00:00 2001 From: Gedare Bloom Date: Sun, 22 Sep 2024 14:12:22 -0600 Subject: [PATCH 2/2] Remove superfluous test cases --- clang/unittests/Format/FormatTest.cpp | 6 -- 1 file changed, 6 deletions(-) diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index d1cb2b053e33d6..213631e29ae536 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -9336,9 +9336,6 @@ TEST_F(FormatTest, AlignsAfterOpenBracket) { "ccc(a, //\n" "b));", Style); - verifyFormat("aaa const aa{\n" - "a(aaa, )};", - Style); Style.ColumnLimit = 30; verifyFormat("for (int foo = 0; foo < FOO;\n" @@ -9398,9 +9395,6 @@ TEST_F(FormatTest, AlignsAfterOpenBracket) { "fooo(new FOO::BA(\n" "XXXZ()));", Style); - verifyFormat("aaa const aa{\n" - "a(aaa, )};", - Style); Style.AlignAfterOpenBracket = FormatStyle::BAS_BlockIndent; Style.BinPackArguments = false; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Create bugprone-incorrect-enable-shared-from-this check (PR #102299)
@@ -0,0 +1,92 @@ +//===--- IncorrectEnableSharedFromThisCheck.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 "IncorrectEnableSharedFromThisCheck.h" +#include "clang/AST/ASTContext.h" +#include "clang/AST/DeclCXX.h" +#include "clang/AST/RecursiveASTVisitor.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/Basic/Specifiers.h" +#include "llvm/ADT/SmallPtrSet.h" + +using namespace clang::ast_matchers; + +namespace clang::tidy::bugprone { + +void IncorrectEnableSharedFromThisCheck::registerMatchers(MatchFinder *Finder) { + Finder->addMatcher(translationUnitDecl(), this); +} + +void IncorrectEnableSharedFromThisCheck::check( +const MatchFinder::MatchResult &Result) { + + class Visitor : public RecursiveASTVisitor { +IncorrectEnableSharedFromThisCheck &Check; +llvm::SmallPtrSet EnableSharedClassSet; + + public: +explicit Visitor(IncorrectEnableSharedFromThisCheck &Check) +: Check(Check) {} + +bool VisitCXXRecordDecl(CXXRecordDecl *RDecl) { + if (!RDecl->hasDefinition()) +return true; + + if (isStdEnableSharedFromThis(RDecl)) +EnableSharedClassSet.insert(RDecl->getCanonicalDecl()); + + for (const auto &Base : RDecl->bases()) { +const auto *BaseRecord = EugeneZelenko wrote: `auto` should not be used - types is not spelled explicitly. https://github.com/llvm/llvm-project/pull/102299 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Add support for aligning BlockComments in declarations (PR #109497)
https://github.com/mydeveloperday requested changes to this pull request. You have not regenerated the rst https://github.com/llvm/llvm-project/pull/109497 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 6521945 - [RISCV][test] Fix incorrect check prefix in riscv32-toolchain.c and riscv64-toolchain.c. (#109390)
Author: Jim Lin Date: 2024-09-23T09:16:43+08:00 New Revision: 652194531c45682715503355676e39b5b57c9394 URL: https://github.com/llvm/llvm-project/commit/652194531c45682715503355676e39b5b57c9394 DIFF: https://github.com/llvm/llvm-project/commit/652194531c45682715503355676e39b5b57c9394.diff LOG: [RISCV][test] Fix incorrect check prefix in riscv32-toolchain.c and riscv64-toolchain.c. (#109390) Added: Modified: clang/test/Driver/riscv32-toolchain.c clang/test/Driver/riscv64-toolchain.c Removed: diff --git a/clang/test/Driver/riscv32-toolchain.c b/clang/test/Driver/riscv32-toolchain.c index 322a6ca2840fb9..50db13f8294c19 100644 --- a/clang/test/Driver/riscv32-toolchain.c +++ b/clang/test/Driver/riscv32-toolchain.c @@ -23,7 +23,7 @@ // C-RV32-BAREMETAL-ILP32: "{{.*}}Inputs/basic_riscv32_tree/lib/gcc/riscv32-unknown-elf/8.0.1/../../../../bin/riscv32-unknown-elf-ld" // C-RV32-BAREMETAL-ILP32: "--sysroot={{.*}}/Inputs/basic_riscv32_tree/riscv32-unknown-elf" -// C-RV64-BAREMETAL-LP64-SAME: "-X" +// C-RV32-BAREMETAL-ILP32: "-X" // C-RV32-BAREMETAL-ILP32: "{{.*}}/Inputs/basic_riscv32_tree/riscv32-unknown-elf/lib/crt0.o" // C-RV32-BAREMETAL-ILP32: "{{.*}}/Inputs/basic_riscv32_tree/lib/gcc/riscv32-unknown-elf/8.0.1/crtbegin.o" // C-RV32-BAREMETAL-ILP32: "-L{{.*}}/Inputs/basic_riscv32_tree/lib/gcc/riscv32-unknown-elf/8.0.1" diff --git a/clang/test/Driver/riscv64-toolchain.c b/clang/test/Driver/riscv64-toolchain.c index b3216de3075400..06d5f50f3f4086 100644 --- a/clang/test/Driver/riscv64-toolchain.c +++ b/clang/test/Driver/riscv64-toolchain.c @@ -23,7 +23,7 @@ // C-RV64-BAREMETAL-LP64: "{{.*}}Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1/../../../../bin/riscv64-unknown-elf-ld" // C-RV64-BAREMETAL-LP64: "--sysroot={{.*}}/Inputs/basic_riscv64_tree/riscv64-unknown-elf" -// C-RV64-BAREMETAL-LP64-SAME: "-X" +// C-RV64-BAREMETAL-LP64: "-X" // C-RV64-BAREMETAL-LP64: "{{.*}}/Inputs/basic_riscv64_tree/riscv64-unknown-elf/lib/crt0.o" // C-RV64-BAREMETAL-LP64: "{{.*}}/Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1/crtbegin.o" // C-RV64-BAREMETAL-LP64: "-L{{.*}}/Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1" ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [RISCV][test] Fix incorrect check prefix in riscv32-toolchain.c and riscv64-toolchain.c. (PR #109390)
https://github.com/tclin914 edited https://github.com/llvm/llvm-project/pull/109390 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [RISCV][test] Fix incorrect check prefix in riscv32-toolchain.c and riscv64-toolchain.c. (PR #109390)
https://github.com/tclin914 closed https://github.com/llvm/llvm-project/pull/109390 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [clang][CodeGen] Use byval for SystemZ indirect arguments (PR #66404)
https://github.com/efriedma-quic closed https://github.com/llvm/llvm-project/pull/66404 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [RISCV] Implement validateGlobalRegisterVariable. (PR #109596)
@@ -486,3 +486,15 @@ bool RISCVTargetInfo::validateCpuSupports(StringRef Feature) const { bool RISCVTargetInfo::isValidFeatureName(StringRef Name) const { return llvm::RISCVISAInfo::isSupportedExtensionFeature(Name); } + +bool RISCVTargetInfo::validateGlobalRegisterVariable( +StringRef RegName, unsigned RegSize, bool &HasSizeMismatch) const { + if (RegName == "ra" || RegName == "sp" || RegName == "gp" || dtcxzyw wrote: Should we accept `zero`? https://github.com/llvm/llvm-project/pull/109596 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [RISCV] Implement validateGlobalRegisterVariable. (PR #109596)
https://github.com/dtcxzyw edited https://github.com/llvm/llvm-project/pull/109596 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [RISCV] Implement validateGlobalRegisterVariable. (PR #109596)
https://github.com/dtcxzyw approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/109596 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] clang-format: Add AlignFunctionDeclarations attribute to AlignConsecutiveDeclarations (PR #108241)
@@ -225,6 +225,21 @@ struct FormatStyle { /// bbb = 2; /// \endcode bool AlignCompound; +/// Only for ``AlignConsecutiveDeclarations``. Whether function declarations +/// are aligned. +/// \code +/// true: +/// unsigned int f1(void); +/// void f2(void); +/// size_t f3(void); +/// +/// false: +/// unsigned int f1(void); +/// void f2(void); +/// size_t f3(void); +/// \endcode +/// \version 20 bradh352 wrote: Delete what? All docs related to the new functionality? Or just the \version which was requested by @mydeveloperday ... I don't understand. https://github.com/llvm/llvm-project/pull/108241 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] adding clang codegen (PR #109331)
https://github.com/joaosaffran updated https://github.com/llvm/llvm-project/pull/109331 >From 13a095ca2671cd69b120d9c394831b9ba8e20a50 Mon Sep 17 00:00:00 2001 From: Joao Saffran Date: Thu, 19 Sep 2024 00:13:51 + Subject: [PATCH] Codegen builtin --- clang/include/clang/Basic/Builtins.td | 6 ++ clang/lib/CodeGen/CGBuiltin.cpp | 38 + clang/lib/CodeGen/CGCall.cpp | 5 ++ clang/lib/CodeGen/CGExpr.cpp | 15 - clang/lib/CodeGen/CodeGenFunction.h | 10 +++- clang/lib/Headers/hlsl/hlsl_intrinsics.h | 20 +++ clang/lib/Sema/SemaHLSL.cpp | 56 --- .../builtins/asuint-splitdouble.hlsl | 10 llvm/include/llvm/IR/IntrinsicsDirectX.td | 5 ++ llvm/lib/Target/DirectX/DXIL.td | 1 + .../Target/DirectX/DXILIntrinsicExpansion.cpp | 13 + 11 files changed, 166 insertions(+), 13 deletions(-) create mode 100644 clang/test/CodeGenHLSL/builtins/asuint-splitdouble.hlsl diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td index 8c5d7ad763bf97..b38957f6e3f15d 100644 --- a/clang/include/clang/Basic/Builtins.td +++ b/clang/include/clang/Basic/Builtins.td @@ -4788,6 +4788,12 @@ def HLSLStep: LangBuiltin<"HLSL_LANG"> { let Prototype = "void(...)"; } +def HLSLAsUintSplitDouble: LangBuiltin<"HLSL_LANG"> { + let Spellings = ["__builtin_hlsl_asuint_splitdouble"]; + let Attributes = [NoThrow, Const]; + let Prototype = "void(...)"; +} + // Builtins for XRay. def XRayCustomEvent : Builtin { let Spellings = ["__xray_customevent"]; diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index e2711f1ba70239..768cfb7f3b30f6 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -18824,6 +18824,44 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: { retType, CGM.getHLSLRuntime().getSignIntrinsic(), ArrayRef{Op0}, nullptr, "hlsl.sign"); } + // This should only be called when targeting DXIL + case Builtin::BI__builtin_hlsl_asuint_splitdouble: { + +assert((E->getArg(0)->getType()->hasFloatingRepresentation() && +E->getArg(1)->getType()->hasUnsignedIntegerRepresentation() && +E->getArg(2)->getType()->hasUnsignedIntegerRepresentation()) && + "asuint operands types mismatch"); + +Value *Op0 = EmitScalarExpr(E->getArg(0)); +const HLSLOutArgExpr *OutArg1 = dyn_cast(E->getArg(1)); +const HLSLOutArgExpr *OutArg2 = dyn_cast(E->getArg(2)); + +CallArgList Args; +LValue Op1TmpLValue = EmitHLSLOutArgExpr(OutArg1, Args, OutArg1->getType()); +LValue Op2TmpLValue = EmitHLSLOutArgExpr(OutArg2, Args, OutArg2->getType()); + +llvm::Type *retType = llvm::StructType::get(Int32Ty, Int32Ty); +if (Op0->getType()->isVectorTy()) { + auto *XVecTy = E->getArg(0)->getType()->getAs(); + + llvm::VectorType *i32VecTy = llvm::VectorType::get( + Int32Ty, ElementCount::getFixed(XVecTy->getNumElements())); + + retType = llvm::StructType::get(i32VecTy, i32VecTy); +} + +CallInst *CI = +Builder.CreateIntrinsic(retType, llvm::Intrinsic::dx_asuint_splitdouble, +{Op0}, nullptr, "hlsl.asuint"); + +Value *arg0 = Builder.CreateExtractValue(CI, 0); +Value *arg1 = Builder.CreateExtractValue(CI, 1); + +Builder.CreateStore(arg0, Op1TmpLValue.getAddress()); +auto *s = Builder.CreateStore(arg1, Op2TmpLValue.getAddress()); +EmitWritebacks(*this, Args); +return s; + } } return nullptr; } diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index 4ae981e4013e9c..096bbafa4cc694 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -4681,6 +4681,11 @@ void CallArg::copyInto(CodeGenFunction &CGF, Address Addr) const { IsUsed = true; } +void CodeGenFunction::EmitWritebacks(CodeGenFunction &CGF, + const CallArgList &args) { + emitWritebacks(CGF, args); +} + void CodeGenFunction::EmitCallArg(CallArgList &args, const Expr *E, QualType type) { DisableDebugLocationUpdates Dis(*this, E); diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 35b5daaf6d4b55..d53aecbf9f4741 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -19,6 +19,7 @@ #include "CGObjCRuntime.h" #include "CGOpenMPRuntime.h" #include "CGRecordLayout.h" +#include "CGValue.h" #include "CodeGenFunction.h" #include "CodeGenModule.h" #include "ConstantEmitter.h" @@ -28,6 +29,7 @@ #include "clang/AST/DeclObjC.h" #include "clang/AST/NSAPI.h" #include "clang/AST/StmtVisitor.h" +#include "clang/AST/Type.h" #include "clang/Basic/Builtins.h" #include "clang/Basic/CodeGenOptions.h" #include "clang/Basic/SourceManager.h" @@ -5458,9 +5460,8 @@ LValue CodeGenFunction::EmitOpaqueValueLValue(c
[clang] [flang] [llvm] [mlir] Make MMIWP not have ownership over MMI + Make MMI Only Use an External MCContext (PR #105541)
arsenm wrote: > @aeubanks @arsenm after looking into this in more detail, I realized that the > `getContext` method of `MMI` is heavily used in the `AsmPrinter` to create > symbols. Also not having it makes it harder for the `MMI` to create machine > functions using `getOrCreateMachineFunction`. The AsmPrinter is just an ordinary ModulePass. The initialization can just set a MMI member? https://github.com/llvm/llvm-project/pull/105541 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [llvm] [mlir] Make MMIWP not have ownership over MMI + Make MMI Only Use an External MCContext (PR #105541)
matinraayai wrote: > > @aeubanks @arsenm after looking into this in more detail, I realized that > > the `getContext` method of `MMI` is heavily used in the `AsmPrinter` to > > create symbols. Also not having it makes it harder for the `MMI` to create > > machine functions using `getOrCreateMachineFunction`. > > The AsmPrinter is just an ordinary ModulePass. The initialization can just > set a MMI member? I agree that separating `MCContext` from `MMI` is not an issue for `AsmPrinter`; But I don't see a way to do that with `MachineModuleInfo::getOrCreateMachineFunction`, besides making it take an explicit `MCContext` argument here: ```c++ MachineFunction &MachineModuleInfo::getOrCreateMachineFunction(Function &F, MCContext &MCCtx) { // Shortcut for the common case where a sequence of MachineFunctionPasses // all query for the same Function. if (LastRequest == &F) return *LastResult; auto I = MachineFunctions.insert( std::make_pair(&F, std::unique_ptr())); MachineFunction *MF; if (I.second) { // No pre-existing machine function, create a new one. const TargetSubtargetInfo &STI = *TM.getSubtargetImpl(F); MF = new MachineFunction(F, TM, STI, MCCtx, NextFnNum++); MF->initTargetMachineFunctionInfo(STI); // MRI callback for target specific initializations. TM.registerMachineRegisterInfoCallback(*MF); // Update the set entry. I.first->second.reset(MF); } else { MF = I.first->second.get(); } LastRequest = &F; LastResult = MF; return *MF; } ``` Also the constructor for MMI sets the context's object file info here: ```c++ MachineModuleInfo::MachineModuleInfo(const LLVMTargetMachine *TM) : TM(*TM), Context(TM->getTargetTriple(), TM->getMCAsmInfo(), TM->getMCRegisterInfo(), TM->getMCSubtargetInfo(), nullptr, &TM->Options.MCOptions, false) { Context.setObjectFileInfo(TM->getObjFileLowering()); initialize(); } ``` Again, for both these cases, it's possible to remove the `MCContext` from `MMI`; However doing so will make it harder to use in my opinion. https://github.com/llvm/llvm-project/pull/105541 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][bytecode] Check allocation size limit for operator new (PR #109590)
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/109590 None >From 6b37086bbaa01e9daa069771a3e54c6b80bd7e5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Sun, 22 Sep 2024 22:33:05 +0200 Subject: [PATCH] [clang][bytecode] Check allocation size limit for operator new --- clang/lib/AST/ByteCode/InterpBuiltin.cpp | 11 +- clang/lib/AST/ByteCode/InterpFrame.cpp | 16 -- clang/test/AST/ByteCode/new-delete.cpp | 27 +++- 3 files changed, 50 insertions(+), 4 deletions(-) diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp index 51c77b7da1a655..523f5cb993dbc7 100644 --- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp +++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp @@ -1306,7 +1306,16 @@ static bool interp__builtin_operator_new(InterpState &S, CodePtr OpPC, return false; } - // FIXME: CheckArraySize for NumElems? + // NB: The same check we're using in CheckArraySize() + if (NumElems.getActiveBits() > + ConstantArrayType::getMaxSizeBits(S.getASTContext()) || + NumElems.ugt(Descriptor::MaxArrayElemBytes / ElemSize.getQuantity())) { +// FIXME: NoThrow check? +const SourceInfo &Loc = S.Current->getSource(OpPC); +S.FFDiag(Loc, diag::note_constexpr_new_too_large) +<< NumElems.getZExtValue(); +return false; + } std::optional ElemT = S.getContext().classify(ElemType); DynamicAllocator &Allocator = S.getAllocator(); diff --git a/clang/lib/AST/ByteCode/InterpFrame.cpp b/clang/lib/AST/ByteCode/InterpFrame.cpp index 28e189bb339e62..7c877a70fe6b97 100644 --- a/clang/lib/AST/ByteCode/InterpFrame.cpp +++ b/clang/lib/AST/ByteCode/InterpFrame.cpp @@ -102,14 +102,26 @@ static void print(llvm::raw_ostream &OS, const T &V, ASTContext &ASTCtx, V.toAPValue(ASTCtx).printPretty(OS, ASTCtx, Ty); } +static bool shouldSkipInBacktrace(const Function *F) { + if (F->isBuiltin()) +return true; + if (F->isLambdaStaticInvoker()) +return true; + + const FunctionDecl *FD = F->getDecl(); + if (FD->getDeclName().getCXXOverloadedOperator() == OO_New || + FD->getDeclName().getCXXOverloadedOperator() == OO_Array_New) +return true; + return false; +} + void InterpFrame::describe(llvm::raw_ostream &OS) const { // We create frames for builtin functions as well, but we can't reliably // diagnose them. The 'in call to' diagnostics for them add no value to the // user _and_ it doesn't generally work since the argument types don't always // match the function prototype. Just ignore them. // Similarly, for lambda static invokers, we would just print __invoke(). - if (const auto *F = getFunction(); - F && (F->isBuiltin() || F->isLambdaStaticInvoker())) + if (const auto *F = getFunction(); F && shouldSkipInBacktrace(F)) return; const Expr *CallExpr = Caller->getExpr(getRetPC()); diff --git a/clang/test/AST/ByteCode/new-delete.cpp b/clang/test/AST/ByteCode/new-delete.cpp index 2ba1286b250dc6..6cefbba307215a 100644 --- a/clang/test/AST/ByteCode/new-delete.cpp +++ b/clang/test/AST/ByteCode/new-delete.cpp @@ -592,7 +592,8 @@ namespace std { using size_t = decltype(sizeof(0)); template struct allocator { constexpr T *allocate(size_t N) { - return (T*)__builtin_operator_new(sizeof(T) * N); // both-note 2{{allocation performed here}} + return (T*)__builtin_operator_new(sizeof(T) * N); // both-note 2{{allocation performed here}} \ +// #alloc } constexpr void deallocate(void *p) { __builtin_operator_delete(p); // both-note 2{{std::allocator<...>::deallocate' used to delete pointer to object allocated with 'new'}} \ @@ -731,6 +732,30 @@ namespace Limits { return n; } static_assert(dynarray(5, 0) == 'f'); + + +#if __LP64__ + template + struct S { + constexpr S(unsigned long long N) + : data(nullptr){ + data = alloc.allocate(N); // both-note {{in call to 'this->alloc.allocate(18446744073709551615)}} + } + constexpr T operator[](std::size_t i) const { +return data[i]; + } + + constexpr ~S() { + alloc.deallocate(data); + } + std::allocator alloc; + T* data; + }; + + constexpr std::size_t s = S(~0UL)[42]; // both-error {{constexpr variable 's' must be initialized by a constant expression}} \ + // both-note@#alloc {{cannot allocate array; evaluated array bound 2305843009213693951 is too large}} \ + // both-note {{in call to}} +#endif } #else ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][bytecode] Check allocation size limit for operator new (PR #109590)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) Changes --- Full diff: https://github.com/llvm/llvm-project/pull/109590.diff 3 Files Affected: - (modified) clang/lib/AST/ByteCode/InterpBuiltin.cpp (+10-1) - (modified) clang/lib/AST/ByteCode/InterpFrame.cpp (+14-2) - (modified) clang/test/AST/ByteCode/new-delete.cpp (+26-1) ``diff diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp index 51c77b7da1a655..523f5cb993dbc7 100644 --- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp +++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp @@ -1306,7 +1306,16 @@ static bool interp__builtin_operator_new(InterpState &S, CodePtr OpPC, return false; } - // FIXME: CheckArraySize for NumElems? + // NB: The same check we're using in CheckArraySize() + if (NumElems.getActiveBits() > + ConstantArrayType::getMaxSizeBits(S.getASTContext()) || + NumElems.ugt(Descriptor::MaxArrayElemBytes / ElemSize.getQuantity())) { +// FIXME: NoThrow check? +const SourceInfo &Loc = S.Current->getSource(OpPC); +S.FFDiag(Loc, diag::note_constexpr_new_too_large) +<< NumElems.getZExtValue(); +return false; + } std::optional ElemT = S.getContext().classify(ElemType); DynamicAllocator &Allocator = S.getAllocator(); diff --git a/clang/lib/AST/ByteCode/InterpFrame.cpp b/clang/lib/AST/ByteCode/InterpFrame.cpp index 28e189bb339e62..7c877a70fe6b97 100644 --- a/clang/lib/AST/ByteCode/InterpFrame.cpp +++ b/clang/lib/AST/ByteCode/InterpFrame.cpp @@ -102,14 +102,26 @@ static void print(llvm::raw_ostream &OS, const T &V, ASTContext &ASTCtx, V.toAPValue(ASTCtx).printPretty(OS, ASTCtx, Ty); } +static bool shouldSkipInBacktrace(const Function *F) { + if (F->isBuiltin()) +return true; + if (F->isLambdaStaticInvoker()) +return true; + + const FunctionDecl *FD = F->getDecl(); + if (FD->getDeclName().getCXXOverloadedOperator() == OO_New || + FD->getDeclName().getCXXOverloadedOperator() == OO_Array_New) +return true; + return false; +} + void InterpFrame::describe(llvm::raw_ostream &OS) const { // We create frames for builtin functions as well, but we can't reliably // diagnose them. The 'in call to' diagnostics for them add no value to the // user _and_ it doesn't generally work since the argument types don't always // match the function prototype. Just ignore them. // Similarly, for lambda static invokers, we would just print __invoke(). - if (const auto *F = getFunction(); - F && (F->isBuiltin() || F->isLambdaStaticInvoker())) + if (const auto *F = getFunction(); F && shouldSkipInBacktrace(F)) return; const Expr *CallExpr = Caller->getExpr(getRetPC()); diff --git a/clang/test/AST/ByteCode/new-delete.cpp b/clang/test/AST/ByteCode/new-delete.cpp index 2ba1286b250dc6..6cefbba307215a 100644 --- a/clang/test/AST/ByteCode/new-delete.cpp +++ b/clang/test/AST/ByteCode/new-delete.cpp @@ -592,7 +592,8 @@ namespace std { using size_t = decltype(sizeof(0)); template struct allocator { constexpr T *allocate(size_t N) { - return (T*)__builtin_operator_new(sizeof(T) * N); // both-note 2{{allocation performed here}} + return (T*)__builtin_operator_new(sizeof(T) * N); // both-note 2{{allocation performed here}} \ +// #alloc } constexpr void deallocate(void *p) { __builtin_operator_delete(p); // both-note 2{{std::allocator<...>::deallocate' used to delete pointer to object allocated with 'new'}} \ @@ -731,6 +732,30 @@ namespace Limits { return n; } static_assert(dynarray(5, 0) == 'f'); + + +#if __LP64__ + template + struct S { + constexpr S(unsigned long long N) + : data(nullptr){ + data = alloc.allocate(N); // both-note {{in call to 'this->alloc.allocate(18446744073709551615)}} + } + constexpr T operator[](std::size_t i) const { +return data[i]; + } + + constexpr ~S() { + alloc.deallocate(data); + } + std::allocator alloc; + T* data; + }; + + constexpr std::size_t s = S(~0UL)[42]; // both-error {{constexpr variable 's' must be initialized by a constant expression}} \ + // both-note@#alloc {{cannot allocate array; evaluated array bound 2305843009213693951 is too large}} \ + // both-note {{in call to}} +#endif } #else `` https://github.com/llvm/llvm-project/pull/109590 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] riscv: Support -mstack-protector-guard=tls (PR #108942)
@@ -3644,13 +3645,28 @@ static void RenderSSPOptions(const Driver &D, const ToolChain &TC, << A->getOption().getName() << Value << "sysreg global"; return; } +if (EffectiveTriple.isRISCV()) { + if (Value != "tls" && Value != "global") { keith-packard wrote: Yes, that's the existing non-TLS version which uses `__stack_chk_guard`. It's the default mode. I could add a test to make sure it still works? https://github.com/llvm/llvm-project/pull/108942 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] riscv: Support -mstack-protector-guard=tls (PR #108942)
https://github.com/keith-packard updated https://github.com/llvm/llvm-project/pull/108942 >From a295c6d8057ddd712097e3bf659cdbe3bb4ec869 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 16 Sep 2024 15:41:38 +0200 Subject: [PATCH 1/3] riscv: Support -mstack-protector-guard=tls Add support for using a thread-local variable with a specified offset for holding the stack guard canary value. Signed-off-by: Keith Packard --- clang/lib/Driver/ToolChains/Clang.cpp | 28 ++--- llvm/lib/Target/RISCV/RISCVISelLowering.cpp | 8 ++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 3fe4ce5d893b8d..76692bf8176cf5 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -3604,7 +3604,8 @@ static void RenderSSPOptions(const Driver &D, const ToolChain &TC, if (Arg *A = Args.getLastArg(options::OPT_mstack_protector_guard_EQ)) { StringRef Value = A->getValue(); if (!EffectiveTriple.isX86() && !EffectiveTriple.isAArch64() && -!EffectiveTriple.isARM() && !EffectiveTriple.isThumb()) +!EffectiveTriple.isARM() && !EffectiveTriple.isThumb() && +!EffectiveTriple.isRISCV()) D.Diag(diag::err_drv_unsupported_opt_for_target) << A->getAsString(Args) << TripleStr; if ((EffectiveTriple.isX86() || EffectiveTriple.isARM() || @@ -3644,13 +3645,28 @@ static void RenderSSPOptions(const Driver &D, const ToolChain &TC, << A->getOption().getName() << Value << "sysreg global"; return; } +if (EffectiveTriple.isRISCV()) { + if (Value != "tls" && Value != "global") { +D.Diag(diag::err_drv_invalid_value_with_suggestion) +<< A->getOption().getName() << Value << "tls global"; +return; + } + if (Value == "tls") { +if (!Args.hasArg(options::OPT_mstack_protector_guard_offset_EQ)) { + D.Diag(diag::err_drv_ssp_missing_offset_argument) + << A->getAsString(Args); + return; +} + } +} A->render(Args, CmdArgs); } if (Arg *A = Args.getLastArg(options::OPT_mstack_protector_guard_offset_EQ)) { StringRef Value = A->getValue(); if (!EffectiveTriple.isX86() && !EffectiveTriple.isAArch64() && -!EffectiveTriple.isARM() && !EffectiveTriple.isThumb()) +!EffectiveTriple.isARM() && !EffectiveTriple.isThumb() && +!EffectiveTriple.isRISCV()) D.Diag(diag::err_drv_unsupported_opt_for_target) << A->getAsString(Args) << TripleStr; int Offset; @@ -3669,7 +3685,8 @@ static void RenderSSPOptions(const Driver &D, const ToolChain &TC, if (Arg *A = Args.getLastArg(options::OPT_mstack_protector_guard_reg_EQ)) { StringRef Value = A->getValue(); -if (!EffectiveTriple.isX86() && !EffectiveTriple.isAArch64()) +if (!EffectiveTriple.isX86() && !EffectiveTriple.isAArch64() && +!EffectiveTriple.isRISCV()) D.Diag(diag::err_drv_unsupported_opt_for_target) << A->getAsString(Args) << TripleStr; if (EffectiveTriple.isX86() && (Value != "fs" && Value != "gs")) { @@ -3681,6 +3698,11 @@ static void RenderSSPOptions(const Driver &D, const ToolChain &TC, D.Diag(diag::err_drv_invalid_value) << A->getOption().getName() << Value; return; } +if (EffectiveTriple.isRISCV() && Value != "tp") { + D.Diag(diag::err_drv_invalid_value_with_suggestion) + << A->getOption().getName() << Value << "tp"; + return; +} A->render(Args, CmdArgs); } diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp index 7d2a7b20ba2508..c52ef550495052 100644 --- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp +++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp @@ -21228,6 +21228,14 @@ Value *RISCVTargetLowering::getIRStackGuard(IRBuilderBase &IRB) const { if (Subtarget.isTargetAndroid()) return useTpOffset(IRB, -0x18); + Module *M = IRB.GetInsertBlock()->getParent()->getParent(); + + if (M->getStackProtectorGuard() == "tls") { +// Specially, some users may customize the base reg and offset. +int Offset = M->getStackProtectorGuardOffset(); +return useTpOffset(IRB, Offset); + } + return TargetLowering::getIRStackGuard(IRB); } >From 2453a5114aeae2b2661628f321c0af868b8c3c4e Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 16 Sep 2024 11:27:19 -0700 Subject: [PATCH 2/3] Driver: add stack protector tests for riscv Add tests ensuring that the driver correctly handles stack protector guard options for risc-v. Signed-off-by: Keith Packard --- clang/test/CodeGen/stack-protector-guard.c | 9 + clang/test/Driver/stack-protector-guard.c | 12 2 files changed, 21 insertions(+) diff --git a/clang/test/CodeGen/stack-protector-guard.c b/clang/test/CodeGen/stack-protector-guard.c index 5839ab06033a15..81e0ddc
[clang] [llvm] riscv: Support -mstack-protector-guard=tls (PR #108942)
@@ -3681,6 +3698,11 @@ static void RenderSSPOptions(const Driver &D, const ToolChain &TC, D.Diag(diag::err_drv_invalid_value) << A->getOption().getName() << Value; return; } +if (EffectiveTriple.isRISCV() && Value != "tp") { + D.Diag(diag::err_drv_invalid_value_with_suggestion) keith-packard wrote: Thanks, I missed that one. Added. https://github.com/llvm/llvm-project/pull/108942 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [RISCV] Implement validateGlobalRegisterVariable. (PR #109596)
https://github.com/topperc created https://github.com/llvm/llvm-project/pull/109596 Only allow GPR registers and verify the size is the same as XLen. This fixes the crash seen in #109588 by making it a frontend error. gcc does accept the code so we need to consider if we can fix the backend. Some other targets I tried appear to have similar issues so it might not be straightforward to fix. >From d44983b40a51745f88b04e28bb2e337ce30b1bf9 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Sun, 22 Sep 2024 17:44:14 -0700 Subject: [PATCH] [RISCV] Implement validateGlobalRegisterVariable. Only allow GPR registers and verify the size is the same as XLen. This fixes the crash seen in #109588 by making it a frontend error. gcc does accept the code so we need to consider if we can fix the backend. Some other targets I tried appear to have similar issues so it might not be straightforward to fix. --- clang/lib/Basic/Targets/RISCV.cpp | 12 clang/lib/Basic/Targets/RISCV.h | 3 +++ clang/test/Sema/riscv-asm.c | 17 +++-- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/clang/lib/Basic/Targets/RISCV.cpp b/clang/lib/Basic/Targets/RISCV.cpp index a4925e84784af9..b6ea4440507ea1 100644 --- a/clang/lib/Basic/Targets/RISCV.cpp +++ b/clang/lib/Basic/Targets/RISCV.cpp @@ -486,3 +486,15 @@ bool RISCVTargetInfo::validateCpuSupports(StringRef Feature) const { bool RISCVTargetInfo::isValidFeatureName(StringRef Name) const { return llvm::RISCVISAInfo::isSupportedExtensionFeature(Name); } + +bool RISCVTargetInfo::validateGlobalRegisterVariable( +StringRef RegName, unsigned RegSize, bool &HasSizeMismatch) const { + if (RegName == "ra" || RegName == "sp" || RegName == "gp" || + RegName == "tp" || RegName.starts_with("x") || RegName.starts_with("a") || + RegName.starts_with("s") || RegName.starts_with("t")) { +unsigned XLen = getTriple().isArch64Bit() ? 64 : 32; +HasSizeMismatch = RegSize != XLen; +return true; + } + return false; +} diff --git a/clang/lib/Basic/Targets/RISCV.h b/clang/lib/Basic/Targets/RISCV.h index b808ccc8e9cfe9..351ef21e197c4d 100644 --- a/clang/lib/Basic/Targets/RISCV.h +++ b/clang/lib/Basic/Targets/RISCV.h @@ -131,6 +131,9 @@ class RISCVTargetInfo : public TargetInfo { bool supportsCpuInit() const override { return getTriple().isOSLinux(); } bool validateCpuSupports(StringRef Feature) const override; bool isValidFeatureName(StringRef Name) const override; + + bool validateGlobalRegisterVariable(StringRef RegName, unsigned RegSize, + bool &HasSizeMismatch) const override; }; class LLVM_LIBRARY_VISIBILITY RISCV32TargetInfo : public RISCVTargetInfo { public: diff --git a/clang/test/Sema/riscv-asm.c b/clang/test/Sema/riscv-asm.c index 82664c013175d4..69ba3be3345d5a 100644 --- a/clang/test/Sema/riscv-asm.c +++ b/clang/test/Sema/riscv-asm.c @@ -1,8 +1,6 @@ // RUN: %clang_cc1 %s -triple riscv32 -verify -fsyntax-only // RUN: %clang_cc1 %s -triple riscv64 -verify -fsyntax-only -// expected-no-diagnostics - void i (void) { asm volatile ("" ::: "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7"); asm volatile ("" ::: "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15"); @@ -26,3 +24,18 @@ void f (void) { asm volatile ("" ::: "fa6", "fa7", "fs2", "fs3", "fs4", "fs5", "fs6", "fs7"); asm volatile ("" ::: "fs8", "fs9", "fs10", "fs11", "ft8", "ft9", "ft10", "ft11"); } + +register char i1 __asm__ ("x1"); // expected-error {{size of register 'x1' does not match variable size}} +#if __riscv_xlen == 32 +register long long ll2 __asm__ ("x2"); // expected-error {{size of register 'x2' does not match variable size}} +register int i2 __asm__ ("x3"); +#endif +register long l3 __asm__ ("x4"); +register long ra __asm__ ("ra"); +register long sp __asm__ ("sp"); +register int *gp __asm__ ("gp"); +register char *tp __asm__ ("tp"); +register long a7 __asm__ ("a7"); +register long s11 __asm__ ("s11"); +register long t5 __asm__ ("t5"); +register long* f1 __asm__ ("f1"); // expected-error {{register 'f1' unsuitable for global register variables on this target}} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [RISCV] Implement validateGlobalRegisterVariable. (PR #109596)
llvmbot wrote: @llvm/pr-subscribers-backend-risc-v Author: Craig Topper (topperc) Changes Only allow GPR registers and verify the size is the same as XLen. This fixes the crash seen in #109588 by making it a frontend error. gcc does accept the code so we may need to consider if we can fix the backend. Some other targets I tried appear to have similar issues so it might not be straightforward to fix. --- Full diff: https://github.com/llvm/llvm-project/pull/109596.diff 3 Files Affected: - (modified) clang/lib/Basic/Targets/RISCV.cpp (+12) - (modified) clang/lib/Basic/Targets/RISCV.h (+3) - (modified) clang/test/Sema/riscv-asm.c (+15-2) ``diff diff --git a/clang/lib/Basic/Targets/RISCV.cpp b/clang/lib/Basic/Targets/RISCV.cpp index a4925e84784af9..b6ea4440507ea1 100644 --- a/clang/lib/Basic/Targets/RISCV.cpp +++ b/clang/lib/Basic/Targets/RISCV.cpp @@ -486,3 +486,15 @@ bool RISCVTargetInfo::validateCpuSupports(StringRef Feature) const { bool RISCVTargetInfo::isValidFeatureName(StringRef Name) const { return llvm::RISCVISAInfo::isSupportedExtensionFeature(Name); } + +bool RISCVTargetInfo::validateGlobalRegisterVariable( +StringRef RegName, unsigned RegSize, bool &HasSizeMismatch) const { + if (RegName == "ra" || RegName == "sp" || RegName == "gp" || + RegName == "tp" || RegName.starts_with("x") || RegName.starts_with("a") || + RegName.starts_with("s") || RegName.starts_with("t")) { +unsigned XLen = getTriple().isArch64Bit() ? 64 : 32; +HasSizeMismatch = RegSize != XLen; +return true; + } + return false; +} diff --git a/clang/lib/Basic/Targets/RISCV.h b/clang/lib/Basic/Targets/RISCV.h index b808ccc8e9cfe9..351ef21e197c4d 100644 --- a/clang/lib/Basic/Targets/RISCV.h +++ b/clang/lib/Basic/Targets/RISCV.h @@ -131,6 +131,9 @@ class RISCVTargetInfo : public TargetInfo { bool supportsCpuInit() const override { return getTriple().isOSLinux(); } bool validateCpuSupports(StringRef Feature) const override; bool isValidFeatureName(StringRef Name) const override; + + bool validateGlobalRegisterVariable(StringRef RegName, unsigned RegSize, + bool &HasSizeMismatch) const override; }; class LLVM_LIBRARY_VISIBILITY RISCV32TargetInfo : public RISCVTargetInfo { public: diff --git a/clang/test/Sema/riscv-asm.c b/clang/test/Sema/riscv-asm.c index 82664c013175d4..69ba3be3345d5a 100644 --- a/clang/test/Sema/riscv-asm.c +++ b/clang/test/Sema/riscv-asm.c @@ -1,8 +1,6 @@ // RUN: %clang_cc1 %s -triple riscv32 -verify -fsyntax-only // RUN: %clang_cc1 %s -triple riscv64 -verify -fsyntax-only -// expected-no-diagnostics - void i (void) { asm volatile ("" ::: "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7"); asm volatile ("" ::: "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15"); @@ -26,3 +24,18 @@ void f (void) { asm volatile ("" ::: "fa6", "fa7", "fs2", "fs3", "fs4", "fs5", "fs6", "fs7"); asm volatile ("" ::: "fs8", "fs9", "fs10", "fs11", "ft8", "ft9", "ft10", "ft11"); } + +register char i1 __asm__ ("x1"); // expected-error {{size of register 'x1' does not match variable size}} +#if __riscv_xlen == 32 +register long long ll2 __asm__ ("x2"); // expected-error {{size of register 'x2' does not match variable size}} +register int i2 __asm__ ("x3"); +#endif +register long l3 __asm__ ("x4"); +register long ra __asm__ ("ra"); +register long sp __asm__ ("sp"); +register int *gp __asm__ ("gp"); +register char *tp __asm__ ("tp"); +register long a7 __asm__ ("a7"); +register long s11 __asm__ ("s11"); +register long t5 __asm__ ("t5"); +register long* f1 __asm__ ("f1"); // expected-error {{register 'f1' unsuitable for global register variables on this target}} `` https://github.com/llvm/llvm-project/pull/109596 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [RISCV] Implement validateGlobalRegisterVariable. (PR #109596)
https://github.com/topperc edited https://github.com/llvm/llvm-project/pull/109596 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] riscv: Support -mstack-protector-guard=tls (PR #108942)
https://github.com/keith-packard updated https://github.com/llvm/llvm-project/pull/108942 >From 60ad4f7793701bc50d1c65db4fe665558678fd7b Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 16 Sep 2024 15:41:38 +0200 Subject: [PATCH 1/3] riscv: Support -mstack-protector-guard=tls Add support for using a thread-local variable with a specified offset for holding the stack guard canary value. Signed-off-by: Keith Packard --- clang/lib/Driver/ToolChains/Clang.cpp | 28 ++--- llvm/lib/Target/RISCV/RISCVISelLowering.cpp | 8 ++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 3fe4ce5d893b8d..76692bf8176cf5 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -3604,7 +3604,8 @@ static void RenderSSPOptions(const Driver &D, const ToolChain &TC, if (Arg *A = Args.getLastArg(options::OPT_mstack_protector_guard_EQ)) { StringRef Value = A->getValue(); if (!EffectiveTriple.isX86() && !EffectiveTriple.isAArch64() && -!EffectiveTriple.isARM() && !EffectiveTriple.isThumb()) +!EffectiveTriple.isARM() && !EffectiveTriple.isThumb() && +!EffectiveTriple.isRISCV()) D.Diag(diag::err_drv_unsupported_opt_for_target) << A->getAsString(Args) << TripleStr; if ((EffectiveTriple.isX86() || EffectiveTriple.isARM() || @@ -3644,13 +3645,28 @@ static void RenderSSPOptions(const Driver &D, const ToolChain &TC, << A->getOption().getName() << Value << "sysreg global"; return; } +if (EffectiveTriple.isRISCV()) { + if (Value != "tls" && Value != "global") { +D.Diag(diag::err_drv_invalid_value_with_suggestion) +<< A->getOption().getName() << Value << "tls global"; +return; + } + if (Value == "tls") { +if (!Args.hasArg(options::OPT_mstack_protector_guard_offset_EQ)) { + D.Diag(diag::err_drv_ssp_missing_offset_argument) + << A->getAsString(Args); + return; +} + } +} A->render(Args, CmdArgs); } if (Arg *A = Args.getLastArg(options::OPT_mstack_protector_guard_offset_EQ)) { StringRef Value = A->getValue(); if (!EffectiveTriple.isX86() && !EffectiveTriple.isAArch64() && -!EffectiveTriple.isARM() && !EffectiveTriple.isThumb()) +!EffectiveTriple.isARM() && !EffectiveTriple.isThumb() && +!EffectiveTriple.isRISCV()) D.Diag(diag::err_drv_unsupported_opt_for_target) << A->getAsString(Args) << TripleStr; int Offset; @@ -3669,7 +3685,8 @@ static void RenderSSPOptions(const Driver &D, const ToolChain &TC, if (Arg *A = Args.getLastArg(options::OPT_mstack_protector_guard_reg_EQ)) { StringRef Value = A->getValue(); -if (!EffectiveTriple.isX86() && !EffectiveTriple.isAArch64()) +if (!EffectiveTriple.isX86() && !EffectiveTriple.isAArch64() && +!EffectiveTriple.isRISCV()) D.Diag(diag::err_drv_unsupported_opt_for_target) << A->getAsString(Args) << TripleStr; if (EffectiveTriple.isX86() && (Value != "fs" && Value != "gs")) { @@ -3681,6 +3698,11 @@ static void RenderSSPOptions(const Driver &D, const ToolChain &TC, D.Diag(diag::err_drv_invalid_value) << A->getOption().getName() << Value; return; } +if (EffectiveTriple.isRISCV() && Value != "tp") { + D.Diag(diag::err_drv_invalid_value_with_suggestion) + << A->getOption().getName() << Value << "tp"; + return; +} A->render(Args, CmdArgs); } diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp index 7d2a7b20ba2508..8fa85a684db5a4 100644 --- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp +++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp @@ -21228,6 +21228,14 @@ Value *RISCVTargetLowering::getIRStackGuard(IRBuilderBase &IRB) const { if (Subtarget.isTargetAndroid()) return useTpOffset(IRB, -0x18); + Module *M = IRB.GetInsertBlock()->getParent()->getParent(); + + if (M->getStackProtectorGuard() == "tls") { +// Users must specify the offset explicitly +int Offset = M->getStackProtectorGuardOffset(); +return useTpOffset(IRB, Offset); + } + return TargetLowering::getIRStackGuard(IRB); } >From 0689e2f930b59377ef9777482f316646557eaead Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 16 Sep 2024 11:27:19 -0700 Subject: [PATCH 2/3] Driver: add stack protector tests for riscv Add tests ensuring that the driver correctly handles stack protector guard options for risc-v. Signed-off-by: Keith Packard --- clang/test/CodeGen/stack-protector-guard.c | 9 + clang/test/Driver/stack-protector-guard.c | 12 2 files changed, 21 insertions(+) diff --git a/clang/test/CodeGen/stack-protector-guard.c b/clang/test/CodeGen/stack-protector-guard.c index 5839ab06033a15..81e0ddc8753966 100644 --- a
[clang] clang-format: Add "AllowShortNamespacesOnASingleLine" option (PR #105597)
@@ -972,6 +972,11 @@ struct FormatStyle { /// \version 3.7 bool AllowShortLoopsOnASingleLine; + /// If ``true``, ``namespace a { class b; }`` can be put on a single a single + /// line. owenca wrote: ```suggestion /// If ``true``, ``namespace a { class b; }`` can be put on a single line. ``` https://github.com/llvm/llvm-project/pull/105597 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] clang-format: Add "AllowShortNamespacesOnASingleLine" option (PR #105597)
@@ -616,6 +626,62 @@ class LineJoiner { return 1; } + unsigned tryMergeNamespace(SmallVectorImpl::const_iterator I, + SmallVectorImpl::const_iterator E, + unsigned Limit) { +if (Limit == 0) + return 0; +if (I[1]->InPPDirective != (*I)->InPPDirective || +(I[1]->InPPDirective && I[1]->First->HasUnescapedNewline)) { + return 0; +} +if (I + 2 == E || I[2]->Type == LT_Invalid) + return 0; + +Limit = limitConsideringMacros(I + 1, E, Limit); + +if (!nextTwoLinesFitInto(I, Limit)) + return 0; + +// Check if it's a namespace inside a namespace, and call recursively if so +// '3' is the sizes of the whitespace and closing brace for " _inner_ }". +if (I[1]->First->is(tok::kw_namespace)) { + if (I[1]->Last->is(TT_LineComment)) +return 0; + + const unsigned InnerLimit = Limit - I[1]->Last->TotalLength - 3; + const unsigned MergedLines = tryMergeNamespace(I + 1, E, InnerLimit); + if (!MergedLines) +return 0; + // Check if there is even a line after the inner result. + if (std::distance(I, E) <= MergedLines + 2) +return 0; + // Check that the line after the inner result starts with a closing brace + // which we are permitted to merge into one line. + if (I[2 + MergedLines]->First->is(tok::r_brace) && + !I[2 + MergedLines]->First->MustBreakBefore && + !I[1 + MergedLines]->Last->is(TT_LineComment) && + nextNLinesFitInto(I, I + 2 + MergedLines + 1, Limit)) { +return 2 + MergedLines; owenca wrote: ```suggestion if (I[N]->First->is(tok::r_brace) && !I[N]->First->MustBreakBefore && I[MergedLines + 1]->Last->isNot(tok::comment) && nextNLinesFitInto(I, I + N + 1, Limit)) { return N; ``` https://github.com/llvm/llvm-project/pull/105597 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] clang-format: Add "AllowShortNamespacesOnASingleLine" option (PR #105597)
@@ -616,6 +626,62 @@ class LineJoiner { return 1; } + unsigned tryMergeNamespace(SmallVectorImpl::const_iterator I, + SmallVectorImpl::const_iterator E, + unsigned Limit) { +if (Limit == 0) + return 0; +if (I[1]->InPPDirective != (*I)->InPPDirective || +(I[1]->InPPDirective && I[1]->First->HasUnescapedNewline)) { + return 0; +} +if (I + 2 == E || I[2]->Type == LT_Invalid) + return 0; + +Limit = limitConsideringMacros(I + 1, E, Limit); + +if (!nextTwoLinesFitInto(I, Limit)) + return 0; + +// Check if it's a namespace inside a namespace, and call recursively if so +// '3' is the sizes of the whitespace and closing brace for " _inner_ }". +if (I[1]->First->is(tok::kw_namespace)) { + if (I[1]->Last->is(TT_LineComment)) +return 0; + + const unsigned InnerLimit = Limit - I[1]->Last->TotalLength - 3; + const unsigned MergedLines = tryMergeNamespace(I + 1, E, InnerLimit); + if (!MergedLines) owenca wrote: ```suggestion const int InnerLimit = Limit - I[1]->Last->TotalLength - 3; const auto MergedLines = tryMergeNamespace(I + 1, E, InnerLimit); if (MergedLines == 0) ``` Use `int` to guard against underflow. https://github.com/llvm/llvm-project/pull/105597 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] clang-format: Add "AllowShortNamespacesOnASingleLine" option (PR #105597)
@@ -616,6 +626,62 @@ class LineJoiner { return 1; } + unsigned tryMergeNamespace(SmallVectorImpl::const_iterator I, + SmallVectorImpl::const_iterator E, + unsigned Limit) { +if (Limit == 0) + return 0; +if (I[1]->InPPDirective != (*I)->InPPDirective || +(I[1]->InPPDirective && I[1]->First->HasUnescapedNewline)) { + return 0; +} +if (I + 2 == E || I[2]->Type == LT_Invalid) + return 0; + +Limit = limitConsideringMacros(I + 1, E, Limit); + +if (!nextTwoLinesFitInto(I, Limit)) + return 0; + +// Check if it's a namespace inside a namespace, and call recursively if so +// '3' is the sizes of the whitespace and closing brace for " _inner_ }". +if (I[1]->First->is(tok::kw_namespace)) { + if (I[1]->Last->is(TT_LineComment)) owenca wrote: ```suggestion if (I[1]->Last->is(tok::comment)) ``` Does it make sense to merge if there's a trailing block comment? https://github.com/llvm/llvm-project/pull/105597 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] clang-format: Add "AllowShortNamespacesOnASingleLine" option (PR #105597)
@@ -27981,6 +27981,132 @@ TEST_F(FormatTest, BreakBinaryOperations) { Style); } +TEST_F(FormatTest, ShortNamespacesOption) { + auto BaseStyle = getLLVMStyle(); + BaseStyle.AllowShortNamespacesOnASingleLine = true; + BaseStyle.FixNamespaceComments = false; + + auto Style = BaseStyle; + + // Basic functionality. + verifyFormat("namespace foo { class bar; }", Style); + verifyFormat("namespace foo::bar { class baz; }", Style); + verifyFormat("namespace { class bar; }", Style); + verifyFormat("namespace foo {\n" + "class bar;\n" + "class baz;\n" + "}", + Style); + + // Trailing comments prevent merging. + verifyFormat("namespace foo {\n" + "namespace baz { class qux; } // comment\n" + "}", + Style); + + // Make sure code doesn't walk too far on unbalanced code. + verifyFormat("namespace foo {", Style); + verifyFormat("namespace foo {\n" + "class baz;", + Style); + verifyFormat("namespace foo {\n" + "namespace bar { class baz; }", + Style); + + // Nested namespaces. + verifyFormat("namespace foo { namespace bar { class baz; } }", Style); + verifyFormat("namespace foo {\n" + "namespace bar { class baz; }\n" + "namespace qux { class quux; }\n" + "}", + Style); + + // Varying inner content. + verifyFormat("namespace foo {\n" + "int f() { return 5; }\n" + "}", + Style); + verifyFormat("namespace foo { template struct bar; }", Style); + verifyFormat("namespace foo { constexpr int num = 42; }", Style); + + // Validate wrapping scenarios around the ColumnLimit. + Style.ColumnLimit = 64; + + // Validate just under the ColumnLimit. + verifyFormat( + "namespace foo { namespace bar { namespace baz { class qux; } } }", + Style); + + // Validate just over the ColumnLimit. + verifyFormat("namespace foo {\n" + "namespace bar { namespace baz { class quux; } }\n" + "}", + Style); + + verifyFormat("namespace foo {\n" + "namespace bar {\n" + "namespace baz { namespace qux { class quux; } }\n" + "}\n" + "}", + Style); + + // Validate that the ColumnLimit logic accounts for trailing content as well. + verifyFormat("namespace foo {\n" + "namespace bar { namespace baz { class qux; } }\n" + "} // extra", + Style); + + // No ColumnLimit, allows long nested one-liners, but also leaves multi-line + // instances alone. + Style.ColumnLimit = 0; + verifyFormat( + "namespace foo { namespace bar { namespace baz { class qux; } } }", + Style); + + verifyNoChange("namespace foo {\n" + "namespace bar { namespace baz { class qux; } }\n" + "}", + Style); owenca wrote: ```suggestion // FIXME #if 0 verifyNoChange("namespace foo {\n" "namespace bar { namespace baz { class qux; } }\n" "}", Style); #endif ``` Shouldn't this be merged as well? See this potential [bug](https://discourse.llvm.org/t/clang-format-compactnamespaces-in-combination-with-columnlimit-0/78808). https://github.com/llvm/llvm-project/pull/105597 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] clang-format: Add "AllowShortNamespacesOnASingleLine" option (PR #105597)
@@ -27981,6 +27981,132 @@ TEST_F(FormatTest, BreakBinaryOperations) { Style); } +TEST_F(FormatTest, ShortNamespacesOption) { + auto BaseStyle = getLLVMStyle(); + BaseStyle.AllowShortNamespacesOnASingleLine = true; + BaseStyle.FixNamespaceComments = false; + + auto Style = BaseStyle; + + // Basic functionality. + verifyFormat("namespace foo { class bar; }", Style); + verifyFormat("namespace foo::bar { class baz; }", Style); + verifyFormat("namespace { class bar; }", Style); + verifyFormat("namespace foo {\n" + "class bar;\n" + "class baz;\n" + "}", + Style); + + // Trailing comments prevent merging. + verifyFormat("namespace foo {\n" + "namespace baz { class qux; } // comment\n" + "}", + Style); + + // Make sure code doesn't walk too far on unbalanced code. + verifyFormat("namespace foo {", Style); + verifyFormat("namespace foo {\n" + "class baz;", + Style); + verifyFormat("namespace foo {\n" + "namespace bar { class baz; }", + Style); + + // Nested namespaces. + verifyFormat("namespace foo { namespace bar { class baz; } }", Style); + verifyFormat("namespace foo {\n" + "namespace bar { class baz; }\n" + "namespace qux { class quux; }\n" + "}", + Style); + + // Varying inner content. + verifyFormat("namespace foo {\n" + "int f() { return 5; }\n" + "}", + Style); + verifyFormat("namespace foo { template struct bar; }", Style); + verifyFormat("namespace foo { constexpr int num = 42; }", Style); + + // Validate wrapping scenarios around the ColumnLimit. + Style.ColumnLimit = 64; + + // Validate just under the ColumnLimit. + verifyFormat( + "namespace foo { namespace bar { namespace baz { class qux; } } }", + Style); + + // Validate just over the ColumnLimit. + verifyFormat("namespace foo {\n" + "namespace bar { namespace baz { class quux; } }\n" + "}", + Style); + + verifyFormat("namespace foo {\n" + "namespace bar {\n" + "namespace baz { namespace qux { class quux; } }\n" + "}\n" + "}", + Style); + + // Validate that the ColumnLimit logic accounts for trailing content as well. + verifyFormat("namespace foo {\n" + "namespace bar { namespace baz { class qux; } }\n" + "} // extra", + Style); + + // No ColumnLimit, allows long nested one-liners, but also leaves multi-line + // instances alone. + Style.ColumnLimit = 0; + verifyFormat( + "namespace foo { namespace bar { namespace baz { class qux; } } }", + Style); + + verifyNoChange("namespace foo {\n" + "namespace bar { namespace baz { class qux; } }\n" + "}", + Style); + + Style = BaseStyle; + Style.CompactNamespaces = true; + verifyFormat("namespace foo { namespace bar { class baz; } }", Style); + + // If we can't merge an outer nested namespaces, but can merge an inner + // nested namespace, then CompactNamespaces will merge the outer namespace + // first, preventing the merging of the inner namespace + verifyFormat("namespace foo { namespace baz {\n" + "class qux;\n" + "} // comment\n" + "}", + Style); + + // This option doesn't really work with FixNamespaceComments and nested + // namespaces. Code should use the concatenated namespace syntax. e.g. + // 'namespace foo::bar'. + Style = BaseStyle; + Style.FixNamespaceComments = true; + + verifyFormat( + "namespace foo {\n" + "namespace bar { namespace baz { class qux; } } // namespace bar\n" + "} // namespace foo", + "namespace foo { namespace bar { namespace baz { class qux; } } }", + Style); + + // This option doesn't really make any sense with ShortNamespaceLines = 0. + Style.ShortNamespaceLines = 0; + + verifyFormat( + "namespace foo {\n" + "namespace bar {\n" + "namespace baz { class qux; } // namespace baz\n" + "} // namespace bar\n" + "} // namespace foo", + "namespace foo { namespace bar { namespace baz { class qux; } } }", + Style); +} owenca wrote: IMO it makes more sense that `AllowShortNamespacesOnASingleLine` disables `FixNamespaceComments` on the merged closing braces. https://github.com/llvm/llvm-project/pull/105597 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] clang-format: Add "AllowShortNamespacesOnASingleLine" option (PR #105597)
@@ -27981,6 +27981,132 @@ TEST_F(FormatTest, BreakBinaryOperations) { Style); } +TEST_F(FormatTest, ShortNamespacesOption) { + auto BaseStyle = getLLVMStyle(); + BaseStyle.AllowShortNamespacesOnASingleLine = true; + BaseStyle.FixNamespaceComments = false; + + auto Style = BaseStyle; + + // Basic functionality. + verifyFormat("namespace foo { class bar; }", Style); + verifyFormat("namespace foo::bar { class baz; }", Style); + verifyFormat("namespace { class bar; }", Style); + verifyFormat("namespace foo {\n" + "class bar;\n" + "class baz;\n" + "}", + Style); + + // Trailing comments prevent merging. + verifyFormat("namespace foo {\n" + "namespace baz { class qux; } // comment\n" + "}", + Style); + + // Make sure code doesn't walk too far on unbalanced code. + verifyFormat("namespace foo {", Style); + verifyFormat("namespace foo {\n" + "class baz;", + Style); + verifyFormat("namespace foo {\n" + "namespace bar { class baz; }", + Style); + + // Nested namespaces. + verifyFormat("namespace foo { namespace bar { class baz; } }", Style); + verifyFormat("namespace foo {\n" + "namespace bar { class baz; }\n" + "namespace qux { class quux; }\n" + "}", + Style); + + // Varying inner content. + verifyFormat("namespace foo {\n" + "int f() { return 5; }\n" + "}", + Style); + verifyFormat("namespace foo { template struct bar; }", Style); + verifyFormat("namespace foo { constexpr int num = 42; }", Style); + + // Validate wrapping scenarios around the ColumnLimit. + Style.ColumnLimit = 64; + + // Validate just under the ColumnLimit. + verifyFormat( + "namespace foo { namespace bar { namespace baz { class qux; } } }", + Style); + + // Validate just over the ColumnLimit. + verifyFormat("namespace foo {\n" + "namespace bar { namespace baz { class quux; } }\n" + "}", + Style); + + verifyFormat("namespace foo {\n" + "namespace bar {\n" + "namespace baz { namespace qux { class quux; } }\n" + "}\n" + "}", + Style); + + // Validate that the ColumnLimit logic accounts for trailing content as well. + verifyFormat("namespace foo {\n" + "namespace bar { namespace baz { class qux; } }\n" + "} // extra", + Style); + + // No ColumnLimit, allows long nested one-liners, but also leaves multi-line + // instances alone. + Style.ColumnLimit = 0; + verifyFormat( + "namespace foo { namespace bar { namespace baz { class qux; } } }", + Style); + + verifyNoChange("namespace foo {\n" + "namespace bar { namespace baz { class qux; } }\n" + "}", + Style); + + Style = BaseStyle; + Style.CompactNamespaces = true; + verifyFormat("namespace foo { namespace bar { class baz; } }", Style); + + // If we can't merge an outer nested namespaces, but can merge an inner + // nested namespace, then CompactNamespaces will merge the outer namespace + // first, preventing the merging of the inner namespace owenca wrote: ```suggestion // first, preventing the merging of the inner namespace. ``` https://github.com/llvm/llvm-project/pull/105597 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] clang-format: Add "AllowShortNamespacesOnASingleLine" option (PR #105597)
@@ -616,6 +626,62 @@ class LineJoiner { return 1; } + unsigned tryMergeNamespace(SmallVectorImpl::const_iterator I, + SmallVectorImpl::const_iterator E, + unsigned Limit) { +if (Limit == 0) + return 0; +if (I[1]->InPPDirective != (*I)->InPPDirective || +(I[1]->InPPDirective && I[1]->First->HasUnescapedNewline)) { + return 0; +} +if (I + 2 == E || I[2]->Type == LT_Invalid) + return 0; + +Limit = limitConsideringMacros(I + 1, E, Limit); + +if (!nextTwoLinesFitInto(I, Limit)) + return 0; + +// Check if it's a namespace inside a namespace, and call recursively if so +// '3' is the sizes of the whitespace and closing brace for " _inner_ }". +if (I[1]->First->is(tok::kw_namespace)) { + if (I[1]->Last->is(TT_LineComment)) +return 0; + + const unsigned InnerLimit = Limit - I[1]->Last->TotalLength - 3; + const unsigned MergedLines = tryMergeNamespace(I + 1, E, InnerLimit); + if (!MergedLines) +return 0; + // Check if there is even a line after the inner result. + if (std::distance(I, E) <= MergedLines + 2) owenca wrote: ```suggestion if (std::distance(I, E) <= N) ``` https://github.com/llvm/llvm-project/pull/105597 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] clang-format: Add "AllowShortNamespacesOnASingleLine" option (PR #105597)
@@ -616,6 +626,62 @@ class LineJoiner { return 1; } + unsigned tryMergeNamespace(SmallVectorImpl::const_iterator I, + SmallVectorImpl::const_iterator E, + unsigned Limit) { +if (Limit == 0) owenca wrote: ```suggestion int Limit) { if (Limit <= 0) ``` See below. https://github.com/llvm/llvm-project/pull/105597 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] clang-format: Add "AllowShortNamespacesOnASingleLine" option (PR #105597)
@@ -361,9 +361,18 @@ class LineJoiner { const auto *FirstNonComment = TheLine->getFirstNonComment(); if (!FirstNonComment) return 0; + // FIXME: There are probably cases where we should use FirstNonComment // instead of TheLine->First. +if (TheLine->Last->is(tok::l_brace)) { + if (Style.AllowShortNamespacesOnASingleLine && + TheLine->First->is(tok::kw_namespace)) { +if (unsigned result = tryMergeNamespace(I, E, Limit)) + return result; owenca wrote: ```suggestion unsigned result = tryMergeNamespace(I, E, Limit); if (result > 0); return result; ``` https://github.com/llvm/llvm-project/pull/105597 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] clang-format: Add "AllowShortNamespacesOnASingleLine" option (PR #105597)
@@ -616,6 +626,62 @@ class LineJoiner { return 1; } + unsigned tryMergeNamespace(SmallVectorImpl::const_iterator I, + SmallVectorImpl::const_iterator E, + unsigned Limit) { +if (Limit == 0) + return 0; +if (I[1]->InPPDirective != (*I)->InPPDirective || +(I[1]->InPPDirective && I[1]->First->HasUnescapedNewline)) { + return 0; +} +if (I + 2 == E || I[2]->Type == LT_Invalid) + return 0; + +Limit = limitConsideringMacros(I + 1, E, Limit); + +if (!nextTwoLinesFitInto(I, Limit)) + return 0; + +// Check if it's a namespace inside a namespace, and call recursively if so owenca wrote: ```suggestion // Check if it's a namespace inside a namespace, and call recursively if so. ``` https://github.com/llvm/llvm-project/pull/105597 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] clang-format: Add "AllowShortNamespacesOnASingleLine" option (PR #105597)
@@ -616,6 +626,62 @@ class LineJoiner { return 1; } + unsigned tryMergeNamespace(SmallVectorImpl::const_iterator I, + SmallVectorImpl::const_iterator E, + unsigned Limit) { +if (Limit == 0) + return 0; +if (I[1]->InPPDirective != (*I)->InPPDirective || +(I[1]->InPPDirective && I[1]->First->HasUnescapedNewline)) { + return 0; +} +if (I + 2 == E || I[2]->Type == LT_Invalid) + return 0; + +Limit = limitConsideringMacros(I + 1, E, Limit); + +if (!nextTwoLinesFitInto(I, Limit)) + return 0; + +// Check if it's a namespace inside a namespace, and call recursively if so +// '3' is the sizes of the whitespace and closing brace for " _inner_ }". +if (I[1]->First->is(tok::kw_namespace)) { + if (I[1]->Last->is(TT_LineComment)) +return 0; + + const unsigned InnerLimit = Limit - I[1]->Last->TotalLength - 3; + const unsigned MergedLines = tryMergeNamespace(I + 1, E, InnerLimit); + if (!MergedLines) +return 0; owenca wrote: ```suggestion return 0; const auto N = MergedLines + 2; ``` https://github.com/llvm/llvm-project/pull/105597 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] [Driver] Ensure we error on lto with link.exe and target `*-windows-msvc` on non cl driver modes (PR #109607)
https://github.com/MaxEW707 created https://github.com/llvm/llvm-project/pull/109607 Similar to previous PRs I've done to change some `IsCLMode` checks to `isWindowsMSVCEnvironment`. I stumbled into this one accidentally last week. I did some greps and I think this is the last one for now. All the remaining `IsCLMode` checks are only valid for the cl driver mode. For the `*-windows-msvc` target MSVC link.exe and lld are supported. LTO isn't supported with MSVC link.exe and so we error when lto is enabled but MSVC link.exe is being used. However we only error if the driver mode is cl. If we are using the clang driver with the `*-windows-msvc` target then ensure an error is also emitted when LTO and MSVC link.exe are used together. >From 703262d8d0f7575e2913b0cfc55e0eac53d43779 Mon Sep 17 00:00:00 2001 From: MaxEW707 Date: Sat, 21 Sep 2024 18:46:40 -0700 Subject: [PATCH] Ensure we error on lto with link.exe on non-cl mode driver --- clang/lib/Driver/Driver.cpp | 3 ++- clang/test/Driver/cl-options.c | 2 ++ clang/test/Driver/clang_f_opts.c | 2 +- clang/test/Driver/lto.c | 2 +- clang/test/Driver/thinlto.c | 2 +- clang/test/Driver/thinlto.cu | 2 +- 6 files changed, 8 insertions(+), 5 deletions(-) diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 44548fa9d706fb..a9506cf911b950 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -4011,7 +4011,8 @@ void Driver::handleArguments(Compilation &C, DerivedArgList &Args, // Emitting LLVM while linking disabled except in HIPAMD Toolchain if (Args.hasArg(options::OPT_emit_llvm) && !Args.hasArg(options::OPT_hip_link)) Diag(clang::diag::err_drv_emit_llvm_link); -if (IsCLMode() && LTOMode != LTOK_None && +if (C.getDefaultToolChain().getTriple().isWindowsMSVCEnvironment() && +LTOMode != LTOK_None && !Args.getLastArgValue(options::OPT_fuse_ld_EQ) .equals_insensitive("lld")) Diag(clang::diag::err_drv_lto_without_lld); diff --git a/clang/test/Driver/cl-options.c b/clang/test/Driver/cl-options.c index a6f338533ad763..f0de6289d95223 100644 --- a/clang/test/Driver/cl-options.c +++ b/clang/test/Driver/cl-options.c @@ -626,6 +626,8 @@ // LTO-THIN: -flto=thin // RUN: not %clang_cl -### -Fe%t.exe -entry:main -flto -- %s 2>&1 | FileCheck -check-prefix=LTO-WITHOUT-LLD %s +// RUN: not %clang_cl -### -fuse-ld=link -Fe%t.exe -entry:main -flto -- %s 2>&1 | FileCheck -check-prefix=LTO-WITHOUT-LLD %s +// RUN: not %clang -### --target=x86_64-windows-msvc -fuse-ld=link -Fe%t.exe -entry:main -flto -- %s 2>&1 | FileCheck -check-prefix=LTO-WITHOUT-LLD %s // LTO-WITHOUT-LLD: LTO requires -fuse-ld=lld // RUN: %clang_cl -### -- %s 2>&1 | FileCheck -check-prefix=NOCFGUARD %s diff --git a/clang/test/Driver/clang_f_opts.c b/clang/test/Driver/clang_f_opts.c index adb6f075b6c15d..5dfd86f7515236 100644 --- a/clang/test/Driver/clang_f_opts.c +++ b/clang/test/Driver/clang_f_opts.c @@ -605,7 +605,7 @@ // RUN: %clang -### -S -fjmc -g -fno-jmc -target x86_64-pc-windows-msvc %s 2>&1 | FileCheck -check-prefix=CHECK_NOJMC %s // RUN: %clang -### -S -fjmc -g -target x86_64-unknown-linux %s 2>&1 | FileCheck -check-prefix=CHECK_JMC %s // RUN: %clang -### -S -fjmc -g -fno-jmc -target x86_64-unknown-linux %s 2>&1 | FileCheck -check-prefix=CHECK_NOJMC %s -// RUN: %clang -### -fjmc -g -flto -target x86_64-pc-windows-msvc %s 2>&1 | FileCheck -check-prefix=CHECK_NOJMC_LTO %s +// RUN: %clang -### -fjmc -g -flto -fuse-ld=lld -target x86_64-pc-windows-msvc %s 2>&1 | FileCheck -check-prefix=CHECK_NOJMC_LTO %s // RUN: %clang -### -fjmc -g -flto -target x86_64-unknown-linux %s 2>&1 | FileCheck -check-prefix=CHECK_JMC_LTO %s // RUN: %clang -### -fjmc -g -flto -fno-jmc -target x86_64-unknown-linux %s 2>&1 | FileCheck -check-prefix=CHECK_NOJMC_LTO %s // CHECK_JMC_WARN: -fjmc requires debug info. Use -g or debug options that enable debugger's stepping function; option ignored diff --git a/clang/test/Driver/lto.c b/clang/test/Driver/lto.c index b6c89eb99e2741..d3e22d9a1196b2 100644 --- a/clang/test/Driver/lto.c +++ b/clang/test/Driver/lto.c @@ -5,7 +5,7 @@ // CHECK-COMPILE-ACTIONS: 2: compiler, {1}, ir // CHECK-COMPILE-ACTIONS: 3: backend, {2}, lto-bc -// RUN: %clang -ccc-print-phases %s -flto 2> %t +// RUN: %clang -ccc-print-phases -fuse-ld=lld %s -flto 2> %t // RUN: FileCheck -check-prefix=CHECK-COMPILELINK-ACTIONS < %t %s // // CHECK-COMPILELINK-ACTIONS: 0: input, "{{.*}}lto.c", c diff --git a/clang/test/Driver/thinlto.c b/clang/test/Driver/thinlto.c index e08435f71cc0b0..b54ef307628851 100644 --- a/clang/test/Driver/thinlto.c +++ b/clang/test/Driver/thinlto.c @@ -5,7 +5,7 @@ // CHECK-COMPILE-ACTIONS: 2: compiler, {1}, ir // CHECK-COMPILE-ACTIONS: 3: backend, {2}, lto-bc -// RUN: %clang -ccc-print-phases %s -flto=thin 2> %t +// RUN: %clang -fuse-ld=lld -ccc-print-phases %s -flto=thin 2> %t // RUN: FileCheck -check-prefix=CHECK-COMPILEL
[clang] [clang] [Driver] Ensure we error on lto with link.exe and target `*-windows-msvc` on non cl driver modes (PR #109607)
llvmbot wrote: @llvm/pr-subscribers-clang-driver Author: Max Winkler (MaxEW707) Changes Similar to previous PRs I've done to change some `IsCLMode` checks to `isWindowsMSVCEnvironment`. I stumbled into this one accidentally last week. I did some greps and I think this is the last one for now. All the remaining `IsCLMode` checks are only valid for the cl driver mode. For the `*-windows-msvc` target MSVC link.exe and lld are supported. LTO isn't supported with MSVC link.exe and so we error when lto is enabled but MSVC link.exe is being used. However we only error if the driver mode is cl. If we are using the clang driver with the `*-windows-msvc` target then ensure an error is also emitted when LTO and MSVC link.exe are used together. --- Full diff: https://github.com/llvm/llvm-project/pull/109607.diff 6 Files Affected: - (modified) clang/lib/Driver/Driver.cpp (+2-1) - (modified) clang/test/Driver/cl-options.c (+2) - (modified) clang/test/Driver/clang_f_opts.c (+1-1) - (modified) clang/test/Driver/lto.c (+1-1) - (modified) clang/test/Driver/thinlto.c (+1-1) - (modified) clang/test/Driver/thinlto.cu (+1-1) ``diff diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 44548fa9d706fb..a9506cf911b950 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -4011,7 +4011,8 @@ void Driver::handleArguments(Compilation &C, DerivedArgList &Args, // Emitting LLVM while linking disabled except in HIPAMD Toolchain if (Args.hasArg(options::OPT_emit_llvm) && !Args.hasArg(options::OPT_hip_link)) Diag(clang::diag::err_drv_emit_llvm_link); -if (IsCLMode() && LTOMode != LTOK_None && +if (C.getDefaultToolChain().getTriple().isWindowsMSVCEnvironment() && +LTOMode != LTOK_None && !Args.getLastArgValue(options::OPT_fuse_ld_EQ) .equals_insensitive("lld")) Diag(clang::diag::err_drv_lto_without_lld); diff --git a/clang/test/Driver/cl-options.c b/clang/test/Driver/cl-options.c index a6f338533ad763..f0de6289d95223 100644 --- a/clang/test/Driver/cl-options.c +++ b/clang/test/Driver/cl-options.c @@ -626,6 +626,8 @@ // LTO-THIN: -flto=thin // RUN: not %clang_cl -### -Fe%t.exe -entry:main -flto -- %s 2>&1 | FileCheck -check-prefix=LTO-WITHOUT-LLD %s +// RUN: not %clang_cl -### -fuse-ld=link -Fe%t.exe -entry:main -flto -- %s 2>&1 | FileCheck -check-prefix=LTO-WITHOUT-LLD %s +// RUN: not %clang -### --target=x86_64-windows-msvc -fuse-ld=link -Fe%t.exe -entry:main -flto -- %s 2>&1 | FileCheck -check-prefix=LTO-WITHOUT-LLD %s // LTO-WITHOUT-LLD: LTO requires -fuse-ld=lld // RUN: %clang_cl -### -- %s 2>&1 | FileCheck -check-prefix=NOCFGUARD %s diff --git a/clang/test/Driver/clang_f_opts.c b/clang/test/Driver/clang_f_opts.c index adb6f075b6c15d..5dfd86f7515236 100644 --- a/clang/test/Driver/clang_f_opts.c +++ b/clang/test/Driver/clang_f_opts.c @@ -605,7 +605,7 @@ // RUN: %clang -### -S -fjmc -g -fno-jmc -target x86_64-pc-windows-msvc %s 2>&1 | FileCheck -check-prefix=CHECK_NOJMC %s // RUN: %clang -### -S -fjmc -g -target x86_64-unknown-linux %s 2>&1 | FileCheck -check-prefix=CHECK_JMC %s // RUN: %clang -### -S -fjmc -g -fno-jmc -target x86_64-unknown-linux %s 2>&1 | FileCheck -check-prefix=CHECK_NOJMC %s -// RUN: %clang -### -fjmc -g -flto -target x86_64-pc-windows-msvc %s 2>&1 | FileCheck -check-prefix=CHECK_NOJMC_LTO %s +// RUN: %clang -### -fjmc -g -flto -fuse-ld=lld -target x86_64-pc-windows-msvc %s 2>&1 | FileCheck -check-prefix=CHECK_NOJMC_LTO %s // RUN: %clang -### -fjmc -g -flto -target x86_64-unknown-linux %s 2>&1 | FileCheck -check-prefix=CHECK_JMC_LTO %s // RUN: %clang -### -fjmc -g -flto -fno-jmc -target x86_64-unknown-linux %s 2>&1 | FileCheck -check-prefix=CHECK_NOJMC_LTO %s // CHECK_JMC_WARN: -fjmc requires debug info. Use -g or debug options that enable debugger's stepping function; option ignored diff --git a/clang/test/Driver/lto.c b/clang/test/Driver/lto.c index b6c89eb99e2741..d3e22d9a1196b2 100644 --- a/clang/test/Driver/lto.c +++ b/clang/test/Driver/lto.c @@ -5,7 +5,7 @@ // CHECK-COMPILE-ACTIONS: 2: compiler, {1}, ir // CHECK-COMPILE-ACTIONS: 3: backend, {2}, lto-bc -// RUN: %clang -ccc-print-phases %s -flto 2> %t +// RUN: %clang -ccc-print-phases -fuse-ld=lld %s -flto 2> %t // RUN: FileCheck -check-prefix=CHECK-COMPILELINK-ACTIONS < %t %s // // CHECK-COMPILELINK-ACTIONS: 0: input, "{{.*}}lto.c", c diff --git a/clang/test/Driver/thinlto.c b/clang/test/Driver/thinlto.c index e08435f71cc0b0..b54ef307628851 100644 --- a/clang/test/Driver/thinlto.c +++ b/clang/test/Driver/thinlto.c @@ -5,7 +5,7 @@ // CHECK-COMPILE-ACTIONS: 2: compiler, {1}, ir // CHECK-COMPILE-ACTIONS: 3: backend, {2}, lto-bc -// RUN: %clang -ccc-print-phases %s -flto=thin 2> %t +// RUN: %clang -fuse-ld=lld -ccc-print-phases %s -flto=thin 2> %t // RUN: FileCheck -check-prefix=CHECK-COMPILELINK-ACTIONS < %t %s // // CHECK-COMPILELINK-ACTIONS: 0: input, "{{.*}}thinlto.c", c diff -
[clang] [clang] [Driver] Ensure we error on lto with link.exe and target `*-windows-msvc` on non cl driver modes (PR #109607)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Max Winkler (MaxEW707) Changes Similar to previous PRs I've done to change some `IsCLMode` checks to `isWindowsMSVCEnvironment`. I stumbled into this one accidentally last week. I did some greps and I think this is the last one for now. All the remaining `IsCLMode` checks are only valid for the cl driver mode. For the `*-windows-msvc` target MSVC link.exe and lld are supported. LTO isn't supported with MSVC link.exe and so we error when lto is enabled but MSVC link.exe is being used. However we only error if the driver mode is cl. If we are using the clang driver with the `*-windows-msvc` target then ensure an error is also emitted when LTO and MSVC link.exe are used together. --- Full diff: https://github.com/llvm/llvm-project/pull/109607.diff 6 Files Affected: - (modified) clang/lib/Driver/Driver.cpp (+2-1) - (modified) clang/test/Driver/cl-options.c (+2) - (modified) clang/test/Driver/clang_f_opts.c (+1-1) - (modified) clang/test/Driver/lto.c (+1-1) - (modified) clang/test/Driver/thinlto.c (+1-1) - (modified) clang/test/Driver/thinlto.cu (+1-1) ``diff diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 44548fa9d706fb..a9506cf911b950 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -4011,7 +4011,8 @@ void Driver::handleArguments(Compilation &C, DerivedArgList &Args, // Emitting LLVM while linking disabled except in HIPAMD Toolchain if (Args.hasArg(options::OPT_emit_llvm) && !Args.hasArg(options::OPT_hip_link)) Diag(clang::diag::err_drv_emit_llvm_link); -if (IsCLMode() && LTOMode != LTOK_None && +if (C.getDefaultToolChain().getTriple().isWindowsMSVCEnvironment() && +LTOMode != LTOK_None && !Args.getLastArgValue(options::OPT_fuse_ld_EQ) .equals_insensitive("lld")) Diag(clang::diag::err_drv_lto_without_lld); diff --git a/clang/test/Driver/cl-options.c b/clang/test/Driver/cl-options.c index a6f338533ad763..f0de6289d95223 100644 --- a/clang/test/Driver/cl-options.c +++ b/clang/test/Driver/cl-options.c @@ -626,6 +626,8 @@ // LTO-THIN: -flto=thin // RUN: not %clang_cl -### -Fe%t.exe -entry:main -flto -- %s 2>&1 | FileCheck -check-prefix=LTO-WITHOUT-LLD %s +// RUN: not %clang_cl -### -fuse-ld=link -Fe%t.exe -entry:main -flto -- %s 2>&1 | FileCheck -check-prefix=LTO-WITHOUT-LLD %s +// RUN: not %clang -### --target=x86_64-windows-msvc -fuse-ld=link -Fe%t.exe -entry:main -flto -- %s 2>&1 | FileCheck -check-prefix=LTO-WITHOUT-LLD %s // LTO-WITHOUT-LLD: LTO requires -fuse-ld=lld // RUN: %clang_cl -### -- %s 2>&1 | FileCheck -check-prefix=NOCFGUARD %s diff --git a/clang/test/Driver/clang_f_opts.c b/clang/test/Driver/clang_f_opts.c index adb6f075b6c15d..5dfd86f7515236 100644 --- a/clang/test/Driver/clang_f_opts.c +++ b/clang/test/Driver/clang_f_opts.c @@ -605,7 +605,7 @@ // RUN: %clang -### -S -fjmc -g -fno-jmc -target x86_64-pc-windows-msvc %s 2>&1 | FileCheck -check-prefix=CHECK_NOJMC %s // RUN: %clang -### -S -fjmc -g -target x86_64-unknown-linux %s 2>&1 | FileCheck -check-prefix=CHECK_JMC %s // RUN: %clang -### -S -fjmc -g -fno-jmc -target x86_64-unknown-linux %s 2>&1 | FileCheck -check-prefix=CHECK_NOJMC %s -// RUN: %clang -### -fjmc -g -flto -target x86_64-pc-windows-msvc %s 2>&1 | FileCheck -check-prefix=CHECK_NOJMC_LTO %s +// RUN: %clang -### -fjmc -g -flto -fuse-ld=lld -target x86_64-pc-windows-msvc %s 2>&1 | FileCheck -check-prefix=CHECK_NOJMC_LTO %s // RUN: %clang -### -fjmc -g -flto -target x86_64-unknown-linux %s 2>&1 | FileCheck -check-prefix=CHECK_JMC_LTO %s // RUN: %clang -### -fjmc -g -flto -fno-jmc -target x86_64-unknown-linux %s 2>&1 | FileCheck -check-prefix=CHECK_NOJMC_LTO %s // CHECK_JMC_WARN: -fjmc requires debug info. Use -g or debug options that enable debugger's stepping function; option ignored diff --git a/clang/test/Driver/lto.c b/clang/test/Driver/lto.c index b6c89eb99e2741..d3e22d9a1196b2 100644 --- a/clang/test/Driver/lto.c +++ b/clang/test/Driver/lto.c @@ -5,7 +5,7 @@ // CHECK-COMPILE-ACTIONS: 2: compiler, {1}, ir // CHECK-COMPILE-ACTIONS: 3: backend, {2}, lto-bc -// RUN: %clang -ccc-print-phases %s -flto 2> %t +// RUN: %clang -ccc-print-phases -fuse-ld=lld %s -flto 2> %t // RUN: FileCheck -check-prefix=CHECK-COMPILELINK-ACTIONS < %t %s // // CHECK-COMPILELINK-ACTIONS: 0: input, "{{.*}}lto.c", c diff --git a/clang/test/Driver/thinlto.c b/clang/test/Driver/thinlto.c index e08435f71cc0b0..b54ef307628851 100644 --- a/clang/test/Driver/thinlto.c +++ b/clang/test/Driver/thinlto.c @@ -5,7 +5,7 @@ // CHECK-COMPILE-ACTIONS: 2: compiler, {1}, ir // CHECK-COMPILE-ACTIONS: 3: backend, {2}, lto-bc -// RUN: %clang -ccc-print-phases %s -flto=thin 2> %t +// RUN: %clang -fuse-ld=lld -ccc-print-phases %s -flto=thin 2> %t // RUN: FileCheck -check-prefix=CHECK-COMPILELINK-ACTIONS < %t %s // // CHECK-COMPILELINK-ACTIONS: 0: input, "{{.*}}thinlto.c", c diff --git a/
[clang] [clang] [Driver] Ensure we error on lto with link.exe and target `*-windows-msvc` on non cl driver modes (PR #109607)
@@ -605,7 +605,7 @@ // RUN: %clang -### -S -fjmc -g -fno-jmc -target x86_64-pc-windows-msvc %s 2>&1 | FileCheck -check-prefix=CHECK_NOJMC %s // RUN: %clang -### -S -fjmc -g -target x86_64-unknown-linux %s 2>&1 | FileCheck -check-prefix=CHECK_JMC %s // RUN: %clang -### -S -fjmc -g -fno-jmc -target x86_64-unknown-linux %s 2>&1 | FileCheck -check-prefix=CHECK_NOJMC %s -// RUN: %clang -### -fjmc -g -flto -target x86_64-pc-windows-msvc %s 2>&1 | FileCheck -check-prefix=CHECK_NOJMC_LTO %s +// RUN: %clang -### -fjmc -g -flto -fuse-ld=lld -target x86_64-pc-windows-msvc %s 2>&1 | FileCheck -check-prefix=CHECK_NOJMC_LTO %s MaskRay wrote: `-fuse-ld=lld` would lead to a failure if lld is not found in program paths. This failure happens on Linux, not sure about Windows. https://github.com/llvm/llvm-project/pull/109607 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] [Driver] Ensure we error on lto with link.exe and target `*-windows-msvc` on non cl driver modes (PR #109607)
@@ -5,7 +5,7 @@ // CHECK-COMPILE-ACTIONS: 2: compiler, {1}, ir // CHECK-COMPILE-ACTIONS: 3: backend, {2}, lto-bc -// RUN: %clang -ccc-print-phases %s -flto 2> %t +// RUN: %clang -ccc-print-phases -fuse-ld=lld %s -flto 2> %t MaskRay wrote: This requirement is really non-obvious. The default target triple could be windows-msvc and without `-fuse-ld=lld` there would be an error? https://github.com/llvm/llvm-project/pull/109607 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [RISCV][FMV] Support target_version (PR #99040)
@@ -3056,6 +3056,45 @@ bool Sema::checkTargetVersionAttr(SourceLocation LiteralLoc, Decl *D, enum SecondParam { None }; enum ThirdParam { Target, TargetClones, TargetVersion }; llvm::SmallVector Features; + if (Context.getTargetInfo().getTriple().isRISCV()) { + +llvm::SmallVector AttrStrs; +AttrStr.split(AttrStrs, ';'); + +bool IsPriority = false; +bool IsDefault = false; +for (auto &AttrStr : AttrStrs) { + // Only support arch=+ext,... syntax. BeMg wrote: The `target_version("arch=rv64gc;default;")` attribute will raise an error with the message: `"unsupported '' in the 'target_version' attribute string; 'target_version' attribute ignored"`. This occurs due to an empty `AttrStr` appearing in the attribute. However, `target_version("arch=rv64gc;default")` will not raise an error and will now treat the version as default. To address this situation, I have added a `HasArch` guard. https://github.com/llvm/llvm-project/pull/99040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] [Driver] Ensure we error on lto with link.exe and target `*-windows-msvc` on non cl driver modes (PR #109607)
https://github.com/MaskRay edited https://github.com/llvm/llvm-project/pull/109607 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] [Driver] Ensure we error on lto with link.exe and target `*-windows-msvc` on non cl driver modes (PR #109607)
https://github.com/MaskRay edited https://github.com/llvm/llvm-project/pull/109607 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] [Driver] Ensure we error on lto with link.exe and target `*-windows-msvc` on non cl driver modes (PR #109607)
https://github.com/MaskRay edited https://github.com/llvm/llvm-project/pull/109607 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [KCFI][NFC] Rename the !kcfi_type Function metadata to !cfi_type (PR #109080)
MaskRay wrote: > > I feel that we should make such renaming at this time. > > But then you propose that we make the renaming now. (??) Sorry, it's a typo. We should not do the renaming, unless there is strong argument renaming is useful. https://github.com/llvm/llvm-project/pull/109080 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Include the clang-shlib CMake project when building for MSVC (PR #109457)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `llvm-clang-aarch64-darwin` running on `doug-worker-4` while building `clang` at step 6 "test-build-unified-tree-check-all". Full details are available at: https://lab.llvm.org/buildbot/#/builders/190/builds/6283 Here is the relevant piece of the build log for the reference ``` Step 6 (test-build-unified-tree-check-all) failure: test (failure) TEST 'LLVM-Unit :: Support/./SupportTests/4/11' FAILED Script(shard): -- GTEST_OUTPUT=json:/Users/buildbot/buildbot-root/aarch64-darwin/build/unittests/Support/./SupportTests-LLVM-Unit-34136-4-11.json GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=11 GTEST_SHARD_INDEX=4 /Users/buildbot/buildbot-root/aarch64-darwin/build/unittests/Support/./SupportTests -- Script: -- /Users/buildbot/buildbot-root/aarch64-darwin/build/unittests/Support/./SupportTests --gtest_filter=FileSystemTest.permissions -- Test Directory: /tmp/lit-tmp-p2lue5kg/file-system-test-7c567e /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/llvm/unittests/Support/Path.cpp:2325: Failure Value of: CheckPermissions(fs::set_gid_on_exe) Actual: false Expected: true /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/llvm/unittests/Support/Path.cpp:2340: Failure Value of: CheckPermissions(fs::set_uid_on_exe | fs::set_gid_on_exe | fs::sticky_bit) Actual: false Expected: true /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/llvm/unittests/Support/Path.cpp:2347: Failure Value of: CheckPermissions(fs::all_read | fs::set_uid_on_exe | fs::set_gid_on_exe | fs::sticky_bit) Actual: false Expected: true /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/llvm/unittests/Support/Path.cpp:2350: Failure Value of: CheckPermissions(fs::all_perms) Actual: false Expected: true /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/llvm/unittests/Support/Path.cpp:2355: Failure Value of: CheckPermissions(fs::all_perms & ~fs::sticky_bit) Actual: false Expected: true /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/llvm/unittests/Support/Path.cpp:2325 Value of: CheckPermissions(fs::set_gid_on_exe) Actual: false Expected: true /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/llvm/unittests/Support/Path.cpp:2340 Value of: CheckPermissions(fs::set_uid_on_exe | fs::set_gid_on_exe | fs::sticky_bit) Actual: false Expected: true /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/llvm/unittests/Support/Path.cpp:2347 Value of: CheckPermissions(fs::all_read | fs::set_uid_on_exe | fs::set_gid_on_exe | fs::sticky_bit) Actual: false ... ``` https://github.com/llvm/llvm-project/pull/109457 ___ 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 external examples (PR #106675)
SimplyDanny wrote: There is an error in doc generation. Is it caused by the new file being added? Is there a configuration that needs adaption? https://github.com/llvm/llvm-project/pull/106675 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [RISCV][FMV] Support target_version (PR #99040)
@@ -3056,6 +3056,45 @@ bool Sema::checkTargetVersionAttr(SourceLocation LiteralLoc, Decl *D, enum SecondParam { None }; enum ThirdParam { Target, TargetClones, TargetVersion }; llvm::SmallVector Features; + if (Context.getTargetInfo().getTriple().isRISCV()) { + +llvm::SmallVector AttrStrs; +AttrStr.split(AttrStrs, ';'); + +bool IsPriority = false; +bool IsDefault = false; +for (auto &AttrStr : AttrStrs) { + // Only support arch=+ext,... syntax. topperc wrote: `arch=rv64gc;default` was the case I was concerned about. I didn't mean to have a semicolon at the end. https://github.com/llvm/llvm-project/pull/99040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [RISCV][FMV] Support target_version (PR #99040)
https://github.com/BeMg updated https://github.com/llvm/llvm-project/pull/99040 >From 54b5d6833a52271dfd1ca3912d5d9e886b1970c2 Mon Sep 17 00:00:00 2001 From: Piyou Chen Date: Tue, 19 Mar 2024 02:02:35 -0700 Subject: [PATCH 1/9] [RISCV][FMV] Support target_version --- clang/lib/AST/ASTContext.cpp | 13 +- clang/lib/CodeGen/CodeGenModule.cpp | 6 +- clang/lib/Sema/SemaDecl.cpp | 43 +- clang/lib/Sema/SemaDeclAttr.cpp | 39 ++ .../attr-target-version-riscv-invalid.c | 13 + .../test/CodeGen/attr-target-version-riscv.c | 443 ++ .../CodeGenCXX/attr-target-version-riscv.cpp | 432 + .../SemaCXX/attr-target-version-riscv.cpp | 53 +++ 8 files changed, 1026 insertions(+), 16 deletions(-) create mode 100644 clang/test/CodeGen/attr-target-version-riscv-invalid.c create mode 100644 clang/test/CodeGen/attr-target-version-riscv.c create mode 100644 clang/test/CodeGenCXX/attr-target-version-riscv.cpp create mode 100644 clang/test/SemaCXX/attr-target-version-riscv.cpp diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 7cc69ca4a8a814..4f20ccd67c9493 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -14270,9 +14270,16 @@ void ASTContext::getFunctionFeatureMap(llvm::StringMap &FeatureMap, Target->initFeatureMap(FeatureMap, getDiagnostics(), TargetCPU, Features); } } else if (const auto *TV = FD->getAttr()) { -llvm::SmallVector Feats; -TV->getFeatures(Feats); -std::vector Features = getFMVBackendFeaturesFor(Feats); +std::vector Features; +if (Target->getTriple().isRISCV()) { + ParsedTargetAttr ParsedAttr = Target->parseTargetAttr(TV->getName()); + Features.insert(Features.begin(), ParsedAttr.Features.begin(), + ParsedAttr.Features.end()); +} else { + llvm::SmallVector Feats; + TV->getFeatures(Feats); + Features = getFMVBackendFeaturesFor(Feats); +} Features.insert(Features.begin(), Target->getTargetOpts().FeaturesAsWritten.begin(), Target->getTargetOpts().FeaturesAsWritten.end()); diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index ba2d6588900a11..618b3ac75a9c4a 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -4268,8 +4268,12 @@ void CodeGenModule::emitMultiVersionFunctions() { } else if (const auto *TVA = CurFD->getAttr()) { if (TVA->isDefaultVersion() && IsDefined) ShouldEmitResolver = true; -TVA->getFeatures(Feats); llvm::Function *Func = createFunction(CurFD); +if (getTarget().getTriple().isRISCV()) { + Feats.push_back(TVA->getName()); +} else { + TVA->getFeatures(Feats); +} Options.emplace_back(Func, /*Architecture*/ "", Feats); } else if (const auto *TC = CurFD->getAttr()) { if (IsDefined) diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 8557c25b93a8da..b2b2417b47b8d8 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -10319,8 +10319,10 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC, // Handle attributes. ProcessDeclAttributes(S, NewFD, D); const auto *NewTVA = NewFD->getAttr(); - if (NewTVA && !NewTVA->isDefaultVersion() && - !Context.getTargetInfo().hasFeature("fmv")) { + if (Context.getTargetInfo().getTriple().isRISCV()) { +// Go thought anyway. + } else if (NewTVA && !NewTVA->isDefaultVersion() && + !Context.getTargetInfo().hasFeature("fmv")) { // Don't add to scope fmv functions declarations if fmv disabled AddToScope = false; return NewFD; @@ -11027,13 +11029,27 @@ static bool CheckMultiVersionValue(Sema &S, const FunctionDecl *FD) { } if (TVA) { -llvm::SmallVector Feats; -TVA->getFeatures(Feats); -for (const auto &Feat : Feats) { - if (!TargetInfo.validateCpuSupports(Feat)) { -S.Diag(FD->getLocation(), diag::err_bad_multiversion_option) -<< Feature << Feat; -return true; +if (S.getASTContext().getTargetInfo().getTriple().isRISCV()) { + ParsedTargetAttr ParseInfo = + S.getASTContext().getTargetInfo().parseTargetAttr(TVA->getName()); + for (const auto &Feat : ParseInfo.Features) { +StringRef BareFeat = StringRef{Feat}.substr(1); + +if (!TargetInfo.isValidFeatureName(BareFeat)) { + S.Diag(FD->getLocation(), diag::err_bad_multiversion_option) + << Feature << BareFeat; + return true; +} + } +} else { + llvm::SmallVector Feats; + TVA->getFeatures(Feats); + for (const auto &Feat : Feats) { +if (!TargetInfo.validateCpuSupports(Feat)) { + S.Diag(FD->getLocation(), d
[clang] [RISCV][FMV] Support target_version (PR #99040)
@@ -14270,9 +14270,16 @@ void ASTContext::getFunctionFeatureMap(llvm::StringMap &FeatureMap, Target->initFeatureMap(FeatureMap, getDiagnostics(), TargetCPU, Features); } } else if (const auto *TV = FD->getAttr()) { -llvm::SmallVector Feats; -TV->getFeatures(Feats); -std::vector Features = getFMVBackendFeaturesFor(Feats); +std::vector Features; +if (Target->getTriple().isRISCV()) { + ParsedTargetAttr ParsedAttr = Target->parseTargetAttr(TV->getName()); + Features.insert(Features.begin(), ParsedAttr.Features.begin(), + ParsedAttr.Features.end()); +} else { + llvm::SmallVector Feats; BeMg wrote: Added. --- By the way, target_clones the similarly part use else for x86 target without the assert. https://github.com/llvm/llvm-project/blob/c3d3cef8d58377b02032b07b5f094a402a70435a/clang/lib/CodeGen/CodeGenModule.cpp#L4298. Should we add an assert as well? https://github.com/llvm/llvm-project/pull/99040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [RISCV][FMV] Support target_version (PR #99040)
@@ -4268,8 +4268,12 @@ void CodeGenModule::emitMultiVersionFunctions() { } else if (const auto *TVA = CurFD->getAttr()) { if (TVA->isDefaultVersion() && IsDefined) ShouldEmitResolver = true; -TVA->getFeatures(Feats); llvm::Function *Func = createFunction(CurFD); +if (getTarget().getTriple().isRISCV()) { + Feats.push_back(TVA->getName()); +} else { + TVA->getFeatures(Feats); BeMg wrote: Added. https://github.com/llvm/llvm-project/pull/99040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [RISCV][FMV] Support target_version (PR #99040)
@@ -15501,8 +15511,10 @@ Decl *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, Decl *D, FD->setInvalidDecl(); } if (const auto *Attr = FD->getAttr()) { -if (!Context.getTargetInfo().hasFeature("fmv") && -!Attr->isDefaultVersion()) { +if (Context.getTargetInfo().getTriple().isRISCV()) { BeMg wrote: Updated. https://github.com/llvm/llvm-project/pull/99040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [RISCV][FMV] Support target_version (PR #99040)
@@ -3056,6 +3056,45 @@ bool Sema::checkTargetVersionAttr(SourceLocation LiteralLoc, Decl *D, enum SecondParam { None }; enum ThirdParam { Target, TargetClones, TargetVersion }; llvm::SmallVector Features; + if (Context.getTargetInfo().getTriple().isRISCV()) { + +llvm::SmallVector AttrStrs; +AttrStr.split(AttrStrs, ';'); + +bool IsPriority = false; BeMg wrote: Updated. https://github.com/llvm/llvm-project/pull/99040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [RISCV] Implement validateGlobalRegisterVariable. (PR #109596)
@@ -486,3 +486,15 @@ bool RISCVTargetInfo::validateCpuSupports(StringRef Feature) const { bool RISCVTargetInfo::isValidFeatureName(StringRef Name) const { return llvm::RISCVISAInfo::isSupportedExtensionFeature(Name); } + +bool RISCVTargetInfo::validateGlobalRegisterVariable( +StringRef RegName, unsigned RegSize, bool &HasSizeMismatch) const { + if (RegName == "ra" || RegName == "sp" || RegName == "gp" || wangpc-pp wrote: `zero` is not writable/allocatable? https://github.com/llvm/llvm-project/pull/109596 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 80cdc37 - [Clang] Include the clang-shlib CMake project when building for MSVC (#109457)
Author: Thomas Fransham Date: 2024-09-23T07:24:04+02:00 New Revision: 80cdc3718036cd3ee33424953821ac01046d5278 URL: https://github.com/llvm/llvm-project/commit/80cdc3718036cd3ee33424953821ac01046d5278 DIFF: https://github.com/llvm/llvm-project/commit/80cdc3718036cd3ee33424953821ac01046d5278.diff LOG: [Clang] Include the clang-shlib CMake project when building for MSVC (#109457) Enable building clang-cpp shared library for windows when building with explicit visibility macros enabled and LLVM is built as a shared library(LLVM_BUILD_LLVM_DYLIB_VIS). This is part of the effort to support for enabling plugins on windows by adding better support for building LLVM and Clang as a DLL. Added: Modified: clang/tools/CMakeLists.txt Removed: diff --git a/clang/tools/CMakeLists.txt b/clang/tools/CMakeLists.txt index 9a3512712a28a4..88e29412e54350 100644 --- a/clang/tools/CMakeLists.txt +++ b/clang/tools/CMakeLists.txt @@ -22,7 +22,7 @@ add_clang_subdirectory(c-index-test) add_clang_subdirectory(clang-refactor) # For MinGW we only enable shared library if LLVM_LINK_LLVM_DYLIB=ON. # Without that option resulting library is too close to 2^16 DLL exports limit. -if(UNIX OR (MINGW AND LLVM_LINK_LLVM_DYLIB)) +if(UNIX OR (MSVC AND LLVM_BUILD_LLVM_DYLIB_VIS) OR (MINGW AND LLVM_LINK_LLVM_DYLIB)) add_clang_subdirectory(clang-shlib) endif() ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Include the clang-shlib CMake project when building for MSVC (PR #109457)
https://github.com/vgvassilev closed https://github.com/llvm/llvm-project/pull/109457 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Add explicit visibility symbol macros (PR #108276)
vgvassilev wrote: > > One thing I don't understand about this PR is why we need Compiler.h in > > Clang -- wouldn't the LLVM definitions in their Compiler.h work for Clang > > as well? (This would probably be worth explaining in the patch summary.) > > The symbol lookup in PE/COFF is two level and symmetric, bound to the module. > As a result, each module needs to explicitly specify the ABI interface > (contract). However, given that the interface is annotated differently > (`__declspec(dllexport)` for the producer, `__declspec(dllimport)` for the > consumer), we need to flip the definition. When doing so, we need to know > which module is being built. We cannot just use the conjunction of the module > identifier to select between the two variants as there may be > interdependencies with dynamic linking (e.g. `#if defined(A_ABI) || > defined(B_ABI)` doesn't work if B depends on A and dynamically links to A). > > I do agree that we could put this in the commit message, though, this is > likely something that deserves a note in the developer documentation because > I fear that other developers are going to have this question repeatedly once > this work is completed. The biggest point of contention with this work was > the fact that it involves an ongoing maintenance cost as the ABI boundary is > now being more rigidly defined which is/was not needed to support it on Unix > due to the (global) single level binding. @fsfod, can you capture this comment in the commit message and the documentation as suggested? https://github.com/llvm/llvm-project/pull/108276 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [RISCV][VCIX] Add vcix_state to GNU inline assembly register set (PR #106914)
@@ -44,7 +44,7 @@ ArrayRef RISCVTargetInfo::getGCCRegNames() const { "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", // CSRs - "fflags", "frm", "vtype", "vl", "vxsat", "vxrm" + "fflags", "frm", "vtype", "vl", "vxsat", "vxrm", "sf_vcix_state" 4vtomat wrote: Sure, let me add it! https://github.com/llvm/llvm-project/pull/106914 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] f8f0a26 - [clang][wasm] Replace the target integer sub saturate intrinsics with the equivalent generic `__builtin_elementwise_sub_sat` intrinsics (#109405)
Author: Simon Pilgrim Date: 2024-09-22T10:12:41+01:00 New Revision: f8f0a266e0c26cd940ccba9542aec4b5efed9821 URL: https://github.com/llvm/llvm-project/commit/f8f0a266e0c26cd940ccba9542aec4b5efed9821 DIFF: https://github.com/llvm/llvm-project/commit/f8f0a266e0c26cd940ccba9542aec4b5efed9821.diff LOG: [clang][wasm] Replace the target integer sub saturate intrinsics with the equivalent generic `__builtin_elementwise_sub_sat` intrinsics (#109405) Remove the Intrinsic::wasm_sub_sat_signed/wasm_sub_sat_unsigned entries and just use sub_sat_s/sub_sat_u directly Added: Modified: clang/include/clang/Basic/BuiltinsWebAssembly.def clang/lib/CodeGen/CGBuiltin.cpp clang/lib/Headers/wasm_simd128.h clang/test/CodeGen/builtins-wasm.c clang/test/Headers/wasm.c llvm/include/llvm/IR/IntrinsicsWebAssembly.td llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll Removed: diff --git a/clang/include/clang/Basic/BuiltinsWebAssembly.def b/clang/include/clang/Basic/BuiltinsWebAssembly.def index 90441a5d500120..ab480369b3820e 100644 --- a/clang/include/clang/Basic/BuiltinsWebAssembly.def +++ b/clang/include/clang/Basic/BuiltinsWebAssembly.def @@ -68,11 +68,6 @@ TARGET_BUILTIN(__builtin_wasm_trunc_saturate_u_i64_f64, "LLid", "nc", "nontrappi // SIMD builtins TARGET_BUILTIN(__builtin_wasm_swizzle_i8x16, "V16ScV16ScV16Sc", "nc", "simd128") -TARGET_BUILTIN(__builtin_wasm_sub_sat_s_i8x16, "V16ScV16ScV16Sc", "nc", "simd128") -TARGET_BUILTIN(__builtin_wasm_sub_sat_u_i8x16, "V16UcV16UcV16Uc", "nc", "simd128") -TARGET_BUILTIN(__builtin_wasm_sub_sat_s_i16x8, "V8sV8sV8s", "nc", "simd128") -TARGET_BUILTIN(__builtin_wasm_sub_sat_u_i16x8, "V8UsV8UsV8Us", "nc", "simd128") - TARGET_BUILTIN(__builtin_wasm_abs_i8x16, "V16ScV16Sc", "nc", "simd128") TARGET_BUILTIN(__builtin_wasm_abs_i16x8, "V8sV8s", "nc", "simd128") TARGET_BUILTIN(__builtin_wasm_abs_i32x4, "V4iV4i", "nc", "simd128") diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 3d1138b7773853..78b432474ba3b7 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -21443,28 +21443,6 @@ Value *CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID, Function *Callee = CGM.getIntrinsic(Intrinsic::wasm_swizzle); return Builder.CreateCall(Callee, {Src, Indices}); } - case WebAssembly::BI__builtin_wasm_sub_sat_s_i8x16: - case WebAssembly::BI__builtin_wasm_sub_sat_u_i8x16: - case WebAssembly::BI__builtin_wasm_sub_sat_s_i16x8: - case WebAssembly::BI__builtin_wasm_sub_sat_u_i16x8: { -unsigned IntNo; -switch (BuiltinID) { -case WebAssembly::BI__builtin_wasm_sub_sat_s_i8x16: -case WebAssembly::BI__builtin_wasm_sub_sat_s_i16x8: - IntNo = Intrinsic::wasm_sub_sat_signed; - break; -case WebAssembly::BI__builtin_wasm_sub_sat_u_i8x16: -case WebAssembly::BI__builtin_wasm_sub_sat_u_i16x8: - IntNo = Intrinsic::wasm_sub_sat_unsigned; - break; -default: - llvm_unreachable("unexpected builtin ID"); -} -Value *LHS = EmitScalarExpr(E->getArg(0)); -Value *RHS = EmitScalarExpr(E->getArg(1)); -Function *Callee = CGM.getIntrinsic(IntNo, ConvertType(E->getType())); -return Builder.CreateCall(Callee, {LHS, RHS}); - } case WebAssembly::BI__builtin_wasm_abs_i8x16: case WebAssembly::BI__builtin_wasm_abs_i16x8: case WebAssembly::BI__builtin_wasm_abs_i32x4: diff --git a/clang/lib/Headers/wasm_simd128.h b/clang/lib/Headers/wasm_simd128.h index b1bef7097800b9..08e39bf1a79b4f 100644 --- a/clang/lib/Headers/wasm_simd128.h +++ b/clang/lib/Headers/wasm_simd128.h @@ -997,12 +997,12 @@ static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i8x16_sub(v128_t __a, static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i8x16_sub_sat(v128_t __a, v128_t __b) { - return (v128_t)__builtin_wasm_sub_sat_s_i8x16((__i8x16)__a, (__i8x16)__b); + return (v128_t)__builtin_elementwise_sub_sat((__i8x16)__a, (__i8x16)__b); } static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_u8x16_sub_sat(v128_t __a, v128_t __b) { - return (v128_t)__builtin_wasm_sub_sat_u_i8x16((__u8x16)__a, (__u8x16)__b); + return (v128_t)__builtin_elementwise_sub_sat((__u8x16)__a, (__u8x16)__b); } static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i8x16_min(v128_t __a, @@ -1083,12 +1083,12 @@ static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i16x8_sub(v128_t __a, static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i16x8_sub_sat(v128_t __a, v128_t __b) { - return (v128_t)__builtin_wasm_sub_sat_s_i16x8((__i16x8)__a, (__i16x8)__b); + return (v128_t)__builtin_elementwise_sub_sat
[clang] [llvm] [clang][wasm] Replace the target integer sub saturate intrinsics with the equivalent generic `__builtin_elementwise_sub_sat` intrinsics (PR #109405)
https://github.com/RKSimon closed https://github.com/llvm/llvm-project/pull/109405 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] f5be5cd - [Clang] Add __builtin_common_type (#99473)
Author: Nikolas Klauser Date: 2024-09-22T09:25:52+02:00 New Revision: f5be5cdaad7edf52e39ad439cf5d608c930efca2 URL: https://github.com/llvm/llvm-project/commit/f5be5cdaad7edf52e39ad439cf5d608c930efca2 DIFF: https://github.com/llvm/llvm-project/commit/f5be5cdaad7edf52e39ad439cf5d608c930efca2.diff LOG: [Clang] Add __builtin_common_type (#99473) This implements the logic of the `common_type` base template as a builtin alias. If there should be no `type` member, an empty class is returned. Otherwise a specialization of a `type_identity`-like class is returned. The base template (i.e. `std::common_type`) as well as the empty class and `type_identity`-like struct are given as arguments to the builtin. Added: clang/test/SemaCXX/type-trait-common-type.cpp Modified: clang/docs/LanguageExtensions.rst clang/docs/ReleaseNotes.rst clang/include/clang/AST/ASTContext.h clang/include/clang/AST/DeclID.h clang/include/clang/Basic/Builtins.h clang/lib/AST/ASTContext.cpp clang/lib/AST/ASTImporter.cpp clang/lib/AST/DeclTemplate.cpp clang/lib/Lex/PPMacroExpansion.cpp clang/lib/Sema/SemaLookup.cpp clang/lib/Sema/SemaTemplate.cpp clang/lib/Serialization/ASTReader.cpp clang/lib/Serialization/ASTWriter.cpp libcxx/include/__type_traits/common_type.h libcxx/include/module.modulemap Removed: diff --git a/clang/docs/LanguageExtensions.rst b/clang/docs/LanguageExtensions.rst index f62f90fb9650a9..0c6b9b1b8f9ce4 100644 --- a/clang/docs/LanguageExtensions.rst +++ b/clang/docs/LanguageExtensions.rst @@ -1516,6 +1516,46 @@ Attributes (N2335) C2 ``#embed`` (N3017) C23 C89, C++ = = +Builtin type aliases + + +Clang provides a few builtin aliases to improve the throughput of certain metaprogramming facilities. + +__builtin_common_type +- + +.. code-block:: c++ + + template class BaseTemplate, +template class HasTypeMember, +class HasNoTypeMember, +class... Ts> + using __builtin_common_type = ...; + +This alias is used for implementing ``std::common_type``. If ``std::common_type`` should contain a ``type`` member, +it is an alias to ``HasTypeMember``. Otherwise it is an alias to ``HasNoTypeMember``. The +``BaseTemplate`` is usually ``std::common_type``. ``Ts`` are the arguments to ``std::common_type``. + +__type_pack_element +--- + +.. code-block:: c++ + + template + using __type_pack_element = ...; + +This alias returns the type at ``Index`` in the parameter pack ``Ts``. + +__make_integer_seq +-- + +.. code-block:: c++ + + template class IntSeq, class T, T N> + using __make_integer_seq = ...; + +This alias returns ``IntSeq`` instantiated with ``IntSeqT = T``and ``Ints`` being the pack ``0, ..., N - 1``. + Type Trait Primitives = diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 00d254b70277d4..da5205087fd821 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -123,6 +123,9 @@ C++ Language Changes - Add ``__builtin_elementwise_popcount`` builtin for integer types only. +- The builtin type alias ``__builtin_common_type`` has been added to improve the + performance of ``std::common_type``. + C++2c Feature Support ^ diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index b65a1f7dff5bc1..1984310df0442e 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -403,6 +403,9 @@ class ASTContext : public RefCountedBase { /// The identifier '__type_pack_element'. mutable IdentifierInfo *TypePackElementName = nullptr; + /// The identifier '__builtin_common_type'. + mutable IdentifierInfo *BuiltinCommonTypeName = nullptr; + QualType ObjCConstantStringType; mutable RecordDecl *CFConstantStringTagDecl = nullptr; mutable TypedefDecl *CFConstantStringTypeDecl = nullptr; @@ -610,6 +613,7 @@ class ASTContext : public RefCountedBase { mutable ExternCContextDecl *ExternCContext = nullptr; mutable BuiltinTemplateDecl *MakeIntegerSeqDecl = nullptr; mutable BuiltinTemplateDecl *TypePackElementDecl = nullptr; + mutable BuiltinTemplateDecl *BuiltinCommonTypeDecl = nullptr; /// The associated SourceManager object. SourceManager &SourceMgr; @@ -1134,6 +1138,7 @@ class ASTContext : public RefCountedBase { ExternCContextDecl *getExternCContextDecl() const; BuiltinTemplateDecl *getMakeIntegerSeqDecl() const; BuiltinTemplateDecl *getTypePackElementDecl() const; + BuiltinTemplateDecl *getBuiltinCommonTypeDecl() const; //