[clang] [llvm] [clang][CodeGen] `used` globals are fake (PR #93601)
https://github.com/arichardson approved this pull request. LGTM with the outstanding comments addressed. https://github.com/llvm/llvm-project/pull/93601 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Remove a bunch of unnecessary REQUIRES constraints (PR #94055)
Mhunter15 wrote: #94843 https://github.com/llvm/llvm-project/pull/94055 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [mlir] [OMPIRBuilder] - Handle dependencies in `createTarget` (PR #93977)
@@ -5229,13 +5362,288 @@ static void emitTargetOutlinedFunction( OMPBuilder.emitTargetRegionFunction(EntryInfo, GenerateOutlinedFunction, true, OutlinedFn, OutlinedFnID); } +OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::emitTargetTask( +Function *OutlinedFn, Value *OutlinedFnID, +EmitFallbackCallbackTy EmitTargetCallFallbackCB, TargetKernelArgs &Args, +Value *DeviceID, Value *RTLoc, OpenMPIRBuilder::InsertPointTy AllocaIP, +SmallVector &Dependencies, +bool HasNoWait) { + + // When we arrive at this function, the target region itself has been + // outlined into the function OutlinedFn. + // So at ths point, for + // -- + // void user_code_that_offloads(...) { + // omp target depend(..) map(from:a) map(to:b, c) + //a = b + c + // } + // + // -- + // + // we have + // + // -- + // + // void user_code_that_offloads(...) { + // %.offload_baseptrs = alloca [3 x ptr], align 8 + // %.offload_ptrs = alloca [3 x ptr], align 8 + // %.offload_mappers = alloca [3 x ptr], align 8 + // ;; target region has been outlined and now we need to + // ;; offload to it via a target task. + // } + // void outlined_device_function(ptr a, ptr b, ptr c) { + // *a = *b + *c + // } + // + // We have to now do the following + // (i) Make an offloading call to outlined_device_function using the OpenMP + // RTL. See 'kernel_launch_function' in the pseudo code below. This is + // emitted by emitKernelLaunch + // (ii) Create a task entry point function that calls kernel_launch_function + // and is the entry point for the target task. See + // '@.omp_target_task_proxy_func in the pseudocode below. + // (iii) Create a task with the task entry point created in (ii) + // + // That is we create the following + // + // void user_code_that_offloads(...) { + // %.offload_baseptrs = alloca [3 x ptr], align 8 + // %.offload_ptrs = alloca [3 x ptr], align 8 + // %.offload_mappers = alloca [3 x ptr], align 8 + // + // %structArg = alloca { ptr, ptr, ptr }, align 8 + // %strucArg[0] = %.offload_baseptrs + // %strucArg[1] = %.offload_ptrs + // %strucArg[2] = %.offload_mappers + // proxy_target_task = @__kmpc_omp_task_alloc(..., + // @.omp_target_task_proxy_func) + // memcpy(proxy_target_task->shareds, %structArg, sizeof(structArg)) + // dependencies_array = ... + // ;; if nowait not present + // call @__kmpc_omp_wait_deps(..., dependencies_array) + // call @__kmpc_omp_task_begin_if0(...) + // call @ @.omp_target_task_proxy_func(i32 thread_id, ptr + // %proxy_target_task) call @__kmpc_omp_task_complete_if0(...) + // } + // + // define internal void @.omp_target_task_proxy_func(i32 %thread.id, + // ptr %task) { + // %structArg = alloca {ptr, ptr, ptr} + // %shared_data = load (getelementptr %task, 0, 0) + // mempcy(%structArg, %shared_data, sizeof(structArg)) + // kernel_launch_function(%thread.id, %structArg) + // } + // + // We need the proxy function because the signature of the task entry point + // expected by kmpc_omp_task is always the same and will be different from + // that of the kernel_launch function. + // + // kernel_launch_function is generated by emitKernelLaunch and has the + // always_inline attribute. void kernel_launch_function(thread_id, + //structArg) + //alwaysinline { + // %kernel_args = alloca %struct.__tgt_kernel_arguments, align 8 + // offload_baseptrs = load(getelementptr structArg, 0, 0) + // offload_ptrs = load(getelementptr structArg, 0, 1) + // offload_mappers = load(getelementptr structArg, 0, 2) + // ; setup kernel_args using offload_baseptrs, offload_ptrs and + // ; offload_mappers + // call i32 @__tgt_target_kernel(..., + // outlined_device_function, + // ptr %kernel_args) + // } + // void outlined_device_function(ptr a, ptr b, ptr c) { + // *a = *b + *c + // } + // + BasicBlock *TargetTaskBodyBB = + splitBB(Builder, /*CreateBranch=*/true, "target.task.body"); + BasicBlock *TargetTaskAllocaBB = + splitBB(Builder, /*CreateBranch=*/true, "target.task.alloca"); + + InsertPointTy TargetTaskAllocaIP = + InsertPointTy(TargetTaskAllocaBB, TargetTaskAllocaBB->begin()); + InsertPointTy TargetTaskBodyIP = + InsertPointTy(TargetTaskBodyBB, TargetTaskBodyBB->begin()); + + OutlineInfo OI; + OI.En
[clang] [llvm] [mlir] [OMPIRBuilder] - Handle dependencies in `createTarget` (PR #93977)
@@ -1762,6 +1762,26 @@ class OpenMPIRBuilder { EmitFallbackCallbackTy EmitTargetCallFallbackCB, TargetKernelArgs &Args, Value *DeviceID, Value *RTLoc, InsertPointTy AllocaIP); + /// Generate a target-task for the target construct + /// + /// \param OutlinedFn The outlined device/target kernel function. + /// \param OutlinedFnID The ooulined function ID. + /// \param EmitTargetCallFallbackCB Call back function to generate host + ///fallback code. + /// \param Args Data structure holding information about the kernel arguments. + /// \param DeviceID Identifier for the device via the 'device' clause. + /// \param RTLoc Source location identifier + /// \param AllocaIP The insertion point to be used for alloca instructions. + /// \param Dependencies Vector of DependData objects holding information of + ///dependencies as specified by the 'depend' clause. + /// \param HasNoWait True if the target construct had 'nowait' on it, false + ///otherwise + InsertPointTy emitTargetTask( + Function *OutlinedFn, Value *OutlinedFnID, + EmitFallbackCallbackTy EmitTargetCallFallbackCB, TargetKernelArgs &Args, + Value *DeviceID, Value *RTLoc, InsertPointTy AllocaIP, + SmallVector &Dependencies, bool HasNoWait); bhandarkar-pranav wrote: I don't think this is safe. I capture Dependencies in a lambda so storing ArrayRef which doesnt manage the lifetime of the data pointer isn't safe. https://github.com/llvm/llvm-project/pull/93977 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-doc] Add basic e2e test (PR #93928)
@@ -0,0 +1,17 @@ +[ + { +"directory": "$test_dir/build", PeterChou1 wrote: I tried getting relative paths to work but it didn't seem to work https://github.com/llvm/llvm-project/pull/93928 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-doc] Add basic e2e test (PR #93928)
https://github.com/PeterChou1 edited https://github.com/llvm/llvm-project/pull/93928 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-doc] Add basic e2e test (PR #93928)
@@ -0,0 +1,361 @@ +// RUN: rm -rf %t && mkdir -p %t/build %t/include %t/src %t/docs +// RUN: sed 's|$test_dir|%/t|g' %S/Inputs/clang-doc-project1/database_template.json > %t/build/compile_commands.json +// RUN: cp %S/Inputs/clang-doc-project1/*.h %t/include +// RUN: cp %S/Inputs/clang-doc-project1/*.cpp %t/src +// RUN: cd %t +// RUN: clang-doc --format=html --executor=all-TUs --asset=%S/Inputs ./build/compile_commands.json PeterChou1 wrote: I removed the copying so the commands run should be simplified I based most of the commands off a test case I found here https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/test/clang-move/move-class.cpp its also why I used the .cpp extension for the test case 😅 https://github.com/llvm/llvm-project/pull/93928 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-doc] Add basic e2e test (PR #93928)
https://github.com/PeterChou1 updated https://github.com/llvm/llvm-project/pull/93928 >From 219df1820de43696dd51268f1aa22c397846c0a6 Mon Sep 17 00:00:00 2001 From: PeterChou1 Date: Fri, 7 Jun 2024 01:47:15 -0400 Subject: [PATCH 1/2] [clang-doc] add basic e2e test --- .../Inputs/clang-doc-default-stylesheet.css | 969 ++ .../Inputs/clang-doc-project1/Calculator.cpp | 21 + .../Inputs/clang-doc-project1/Calculator.h| 46 + .../Inputs/clang-doc-project1/Circle.cpp | 11 + .../Inputs/clang-doc-project1/Circle.h| 35 + .../Inputs/clang-doc-project1/Rectangle.cpp | 12 + .../Inputs/clang-doc-project1/Rectangle.h | 37 + .../Inputs/clang-doc-project1/Shape.h | 30 + .../clang-doc-project1/database_template.json | 17 + .../test/clang-doc/Inputs/index.js| 87 ++ .../test/clang-doc/clang-doc-project1.cpp | 361 +++ 11 files changed, 1626 insertions(+) create mode 100644 clang-tools-extra/test/clang-doc/Inputs/clang-doc-default-stylesheet.css create mode 100644 clang-tools-extra/test/clang-doc/Inputs/clang-doc-project1/Calculator.cpp create mode 100644 clang-tools-extra/test/clang-doc/Inputs/clang-doc-project1/Calculator.h create mode 100644 clang-tools-extra/test/clang-doc/Inputs/clang-doc-project1/Circle.cpp create mode 100644 clang-tools-extra/test/clang-doc/Inputs/clang-doc-project1/Circle.h create mode 100644 clang-tools-extra/test/clang-doc/Inputs/clang-doc-project1/Rectangle.cpp create mode 100644 clang-tools-extra/test/clang-doc/Inputs/clang-doc-project1/Rectangle.h create mode 100644 clang-tools-extra/test/clang-doc/Inputs/clang-doc-project1/Shape.h create mode 100644 clang-tools-extra/test/clang-doc/Inputs/clang-doc-project1/database_template.json create mode 100644 clang-tools-extra/test/clang-doc/Inputs/index.js create mode 100644 clang-tools-extra/test/clang-doc/clang-doc-project1.cpp diff --git a/clang-tools-extra/test/clang-doc/Inputs/clang-doc-default-stylesheet.css b/clang-tools-extra/test/clang-doc/Inputs/clang-doc-default-stylesheet.css new file mode 100644 index 0..8b335232b8048 --- /dev/null +++ b/clang-tools-extra/test/clang-doc/Inputs/clang-doc-default-stylesheet.css @@ -0,0 +1,969 @@ +.dark-primary-color{ background: #1976D2; } +.default-primary-color { background: #2196F3; } +.light-primary-color { background: #BBDEFB; } +.text-primary-color{ color: #FF; } +.accent-color { background: #00BCD4; } +.primary-text-color{ color: #212121; } +.secondary-text-color { color: #727272; } +.divider-color { border-color: #B6B6B6; } + +/* for layout */ +html, +body { + margin: 0; + padding: 0; + height: 100%; + width: 100%; + overflow: hidden; + box-sizing: border-box; +} + +*, *:before, *:after { + box-sizing: inherit; +} + +body { + display: flex; + flex-direction: column; + min-height: 100vh; +} + +header { + flex: 0 0 50px; + display: flex; + flex-direction: row; + align-items: center; + padding-left: 30px; +} + +header ol { + list-style: none; + margin: 0; + padding: 0; +} + +header ol li { + display: inline; +} + +header form { + display: flex; + flex: 1; + justify-content: flex-end; + padding-right: 30px; +} + +header#header-search-sidebar { + height: 50px; + margin-bottom: 25px; +} + +footer { + flex: 0 0 16px; + text-align: center; + padding: 16px 20px; +} + +main { + flex: 1; + display: flex; + flex-direction: row; + padding: 20px; + min-height: 0; +} + +.sidebar-offcanvas-left { + flex: 0 1 230px; + overflow-y: scroll; + padding: 20px 0 15px 30px; + margin: 5px 20px 0 0; + visibility: visible; /* shown by Javascript after scroll position restore */ +} + +::-webkit-scrollbar-button{ display: none; height: 13px; border-radius: 0px; background-color: #AAA; } +::-webkit-scrollbar-button:hover{ background-color: #AAA; } +::-webkit-scrollbar-thumb{ background-color: #CCC; } +::-webkit-scrollbar-thumb:hover{ background-color: #CCC; } +::-webkit-scrollbar{ width: 4px; } +/* ::-webkit-overflow-scrolling: touch; */ + +.main-content::-webkit-scrollbar{ width: 8px; } + +.main-content { + flex: 1; + overflow-y: scroll; + padding: 10px 20px 0 20px; + visibility: visible; /* shown by Javascript after scroll position restore */ +} + +.sidebar-offcanvas-right { + flex: 0 1 12em; + overflow-y: scroll; + padding: 20px 15px 15px 15px; + margin-top: 5px; + margin-right: 20px; + visibility: visible; /* shown by Javascript after scroll position restore */ +} +/* end for layout */ + +body { + -webkit-text-size-adjust: 100%; + overflow-x: hidden; + font-family: Roboto, sans-serif; + font-size: 16px; + line-height: 1.42857143; + color: #11; + background-color: #fff; +} + +/* some of this is to reset bootstrap */ +nav.navbar { + background-color: inherit; + min-height: 50px; + border: 0; +} + +@media (max-width: 768px) { + .hidden-xs { +display: none !important; + } +} + +@media (min-width: 769px) {
[clang] [lldb] [clang][AST] fix ast-print of extern with >=2 declarators, fixed (PR #93913)
https://github.com/temyurchenko updated https://github.com/llvm/llvm-project/pull/93913 >From 410c7ba9fb7667dabdfbc48fdbda427401ca8df0 Mon Sep 17 00:00:00 2001 From: Artem Yurchenko <44875844+temyurche...@users.noreply.github.com> Date: Thu, 30 May 2024 16:18:47 -0400 Subject: [PATCH 1/2] [clang][AST] fix ast-print of `extern ` with >=2 declarators (#93131) Problem: the printer used to ignore all but the first declarator for unbraced language linkage declarators. Furthemore, that one would be printed without the final semicolon. Solution: for unbraced case we traverse all declarators via `VisitDeclContext`. Furthermore, in appropriate visitors we query for whether they are a part of the unbraced extern language linkage spec, and if so, print appropriately. --- clang/lib/AST/DeclPrinter.cpp | 55 ++- clang/test/AST/ast-print-language-linkage.cpp | 31 +++ 2 files changed, 72 insertions(+), 14 deletions(-) create mode 100644 clang/test/AST/ast-print-language-linkage.cpp diff --git a/clang/lib/AST/DeclPrinter.cpp b/clang/lib/AST/DeclPrinter.cpp index 0cf4e64f83b8d..9250a7f6eceb2 100644 --- a/clang/lib/AST/DeclPrinter.cpp +++ b/clang/lib/AST/DeclPrinter.cpp @@ -633,7 +633,7 @@ static void printExplicitSpecifier(ExplicitSpecifier ES, llvm::raw_ostream &Out, Out << Proto; } -static void MaybePrintTagKeywordIfSupressingScopes(PrintingPolicy &Policy, +static void maybePrintTagKeywordIfSupressingScopes(PrintingPolicy &Policy, QualType T, llvm::raw_ostream &Out) { StringRef prefix = T->isClassType() ? "class " @@ -643,6 +643,22 @@ static void MaybePrintTagKeywordIfSupressingScopes(PrintingPolicy &Policy, Out << prefix; } +/// Return the language of the linkage spec of `D`, if applicable. +/// +/// \Return - "C" if `D` has been declared with unbraced `extern "C"` +/// - "C++" if `D` has been declared with unbraced `extern "C++"` +/// - nullptr in any other case +static const char *tryGetUnbracedLinkageLanguage(const Decl *D) { + const auto *SD = dyn_cast(D->getDeclContext()); + if (!SD || SD->hasBraces()) +return nullptr; + if (SD->getLanguage() == LinkageSpecLanguageIDs::C) +return "C"; + assert(SD->getLanguage() == LinkageSpecLanguageIDs::CXX && + "unknown language in linkage specification"); + return "C++"; +} + void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) { if (!D->getDescribedFunctionTemplate() && !D->isFunctionTemplateSpecialization()) { @@ -662,6 +678,11 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) { CXXConversionDecl *ConversionDecl = dyn_cast(D); CXXDeductionGuideDecl *GuideDecl = dyn_cast(D); if (!Policy.SuppressSpecifiers) { +if (const char *Lang = tryGetUnbracedLinkageLanguage(D)) { + // the "extern" specifier is implicit + assert(D->getStorageClass() == SC_None); + Out << "extern \"" << Lang << "\" "; +} switch (D->getStorageClass()) { case SC_None: break; case SC_Extern: Out << "extern "; break; @@ -807,7 +828,7 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) { } if (!Policy.SuppressTagKeyword && Policy.SuppressScope && !Policy.SuppressUnwrittenScope) -MaybePrintTagKeywordIfSupressingScopes(Policy, AFT->getReturnType(), +maybePrintTagKeywordIfSupressingScopes(Policy, AFT->getReturnType(), Out); AFT->getReturnType().print(Out, Policy, Proto); Proto.clear(); @@ -932,6 +953,11 @@ void DeclPrinter::VisitVarDecl(VarDecl *D) { : D->getASTContext().getUnqualifiedObjCPointerType(D->getType()); if (!Policy.SuppressSpecifiers) { +if (const char *Lang = tryGetUnbracedLinkageLanguage(D)) { + // the "extern" specifier is implicit + assert(D->getStorageClass() == SC_None); + Out << "extern \"" << Lang << "\" "; +} StorageClass SC = D->getStorageClass(); if (SC != SC_None) Out << VarDecl::getStorageClassSpecifierString(SC) << " "; @@ -961,7 +987,7 @@ void DeclPrinter::VisitVarDecl(VarDecl *D) { if (!Policy.SuppressTagKeyword && Policy.SuppressScope && !Policy.SuppressUnwrittenScope) -MaybePrintTagKeywordIfSupressingScopes(Policy, T, Out); +maybePrintTagKeywordIfSupressingScopes(Policy, T, Out); printDeclType(T, (isa(D) && Policy.CleanUglifiedParameters && D->getIdentifier()) @@ -1064,6 +1090,8 @@ void DeclPrinter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { void DeclPrinter::VisitEmptyDecl(EmptyDecl *D) { prettyPrintAttributes(D); + if (const char *Lang = tryGetUnbracedLinkageLanguage(D)) +Out << "extern \"" << Lang << "\";"; } void DeclPrinter::VisitCXXRecordDecl(CXXRecordDecl *D) { @@ -1136,22 +1164,21 @@ void DeclPrinter::VisitCXXRecordDecl(CXXRecordDecl *D) { } void DeclPrinter::VisitLinkageSpecDecl(Li
[clang] [lldb] [clang][AST] fix ast-print of extern with >=2 declarators, fixed (PR #93913)
https://github.com/temyurchenko updated https://github.com/llvm/llvm-project/pull/93913 >From f1951f3f2dd322123a1c49221c4252f4ea932242 Mon Sep 17 00:00:00 2001 From: Artem Yurchenko <44875844+temyurche...@users.noreply.github.com> Date: Thu, 30 May 2024 16:18:47 -0400 Subject: [PATCH 1/2] [clang][AST] fix ast-print of `extern ` with >=2 declarators (#93131) Problem: the printer used to ignore all but the first declarator for unbraced language linkage declarators. Furthemore, that one would be printed without the final semicolon. Solution: when there is more than one declarator, we print them in a braced `extern ` block. If the original declaration was unbraced and there is one or less declarator, we omit the braces, but add the semicolon. **N.B.** We are printing braces which were, in some cases, absent from the original CST. If that's an issue, I'll work on it. See the tests for the examples. --- clang/lib/AST/DeclPrinter.cpp | 55 ++- clang/test/AST/ast-print-language-linkage.cpp | 31 +++ 2 files changed, 72 insertions(+), 14 deletions(-) create mode 100644 clang/test/AST/ast-print-language-linkage.cpp diff --git a/clang/lib/AST/DeclPrinter.cpp b/clang/lib/AST/DeclPrinter.cpp index 0cf4e64f83b8d..9250a7f6eceb2 100644 --- a/clang/lib/AST/DeclPrinter.cpp +++ b/clang/lib/AST/DeclPrinter.cpp @@ -633,7 +633,7 @@ static void printExplicitSpecifier(ExplicitSpecifier ES, llvm::raw_ostream &Out, Out << Proto; } -static void MaybePrintTagKeywordIfSupressingScopes(PrintingPolicy &Policy, +static void maybePrintTagKeywordIfSupressingScopes(PrintingPolicy &Policy, QualType T, llvm::raw_ostream &Out) { StringRef prefix = T->isClassType() ? "class " @@ -643,6 +643,22 @@ static void MaybePrintTagKeywordIfSupressingScopes(PrintingPolicy &Policy, Out << prefix; } +/// Return the language of the linkage spec of `D`, if applicable. +/// +/// \Return - "C" if `D` has been declared with unbraced `extern "C"` +/// - "C++" if `D` has been declared with unbraced `extern "C++"` +/// - nullptr in any other case +static const char *tryGetUnbracedLinkageLanguage(const Decl *D) { + const auto *SD = dyn_cast(D->getDeclContext()); + if (!SD || SD->hasBraces()) +return nullptr; + if (SD->getLanguage() == LinkageSpecLanguageIDs::C) +return "C"; + assert(SD->getLanguage() == LinkageSpecLanguageIDs::CXX && + "unknown language in linkage specification"); + return "C++"; +} + void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) { if (!D->getDescribedFunctionTemplate() && !D->isFunctionTemplateSpecialization()) { @@ -662,6 +678,11 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) { CXXConversionDecl *ConversionDecl = dyn_cast(D); CXXDeductionGuideDecl *GuideDecl = dyn_cast(D); if (!Policy.SuppressSpecifiers) { +if (const char *Lang = tryGetUnbracedLinkageLanguage(D)) { + // the "extern" specifier is implicit + assert(D->getStorageClass() == SC_None); + Out << "extern \"" << Lang << "\" "; +} switch (D->getStorageClass()) { case SC_None: break; case SC_Extern: Out << "extern "; break; @@ -807,7 +828,7 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) { } if (!Policy.SuppressTagKeyword && Policy.SuppressScope && !Policy.SuppressUnwrittenScope) -MaybePrintTagKeywordIfSupressingScopes(Policy, AFT->getReturnType(), +maybePrintTagKeywordIfSupressingScopes(Policy, AFT->getReturnType(), Out); AFT->getReturnType().print(Out, Policy, Proto); Proto.clear(); @@ -932,6 +953,11 @@ void DeclPrinter::VisitVarDecl(VarDecl *D) { : D->getASTContext().getUnqualifiedObjCPointerType(D->getType()); if (!Policy.SuppressSpecifiers) { +if (const char *Lang = tryGetUnbracedLinkageLanguage(D)) { + // the "extern" specifier is implicit + assert(D->getStorageClass() == SC_None); + Out << "extern \"" << Lang << "\" "; +} StorageClass SC = D->getStorageClass(); if (SC != SC_None) Out << VarDecl::getStorageClassSpecifierString(SC) << " "; @@ -961,7 +987,7 @@ void DeclPrinter::VisitVarDecl(VarDecl *D) { if (!Policy.SuppressTagKeyword && Policy.SuppressScope && !Policy.SuppressUnwrittenScope) -MaybePrintTagKeywordIfSupressingScopes(Policy, T, Out); +maybePrintTagKeywordIfSupressingScopes(Policy, T, Out); printDeclType(T, (isa(D) && Policy.CleanUglifiedParameters && D->getIdentifier()) @@ -1064,6 +1090,8 @@ void DeclPrinter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { void DeclPrinter::VisitEmptyDecl(EmptyDecl *D) { prettyPrintAttributes(D); + if (const char *Lang = tryGetUnbracedLinkageLanguage(D)) +Out << "extern \"" << Lang << "\";"; } void DeclPrinter::VisitCXXRecordDecl(CXXReco
[clang] [llvm] [Offload][CUDA] Add initial cuda_runtime.h overlay (PR #94821)
@@ -0,0 +1,30 @@ +// RUN: %clang++ -foffload-via-llvm --offload-arch=native %s -o %t +// RUN: %t | %fcheck-generic + +// UNSUPPORTED: aarch64-unknown-linux-gnu +// UNSUPPORTED: aarch64-unknown-linux-gnu-LTO +// UNSUPPORTED: x86_64-pc-linux-gnu +// UNSUPPORTED: x86_64-pc-linux-gnu-LTO arsenm wrote: Better to enable supported cases? https://github.com/llvm/llvm-project/pull/94821 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AMDGPU] Add a new builtin type for buffer rsrc (PR #94830)
@@ -0,0 +1,9 @@ +// REQUIRES: amdgpu-registered-target +// RUN: %clang_cc1 -fclang-abi-compat=latest -triple amdgcn %s -emit-llvm -o - | FileCheck %s arsenm wrote: Why do you need -fclang-abi-compat=latest https://github.com/llvm/llvm-project/pull/94830 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AMDGPU] Add a new builtin type for buffer rsrc (PR #94830)
@@ -0,0 +1,21 @@ +//===-- AMDGPUTypes.def - Metadata about AMDGPU types ---*- 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 various AMDGPU builtin types. +// +//===--===// + +#ifndef AMDGPU_OPAQUE_TYPE +#define AMDGPU_OPAQUE_TYPE(Name, MangledName, Id, SingletonId) \ + AMDGPU_TYPE(Name, Id, SingletonId) +#endif + +AMDGPU_OPAQUE_TYPE("__buffer_rsrc_t", "__buffer_rsrc_t", AMDGPUBufferRsrc, AMDGPUBufferRsrcTy) arsenm wrote: Should it include an amdgpu prefix? https://github.com/llvm/llvm-project/pull/94830 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AMDGPU] Add a new builtin type for buffer rsrc (PR #94830)
https://github.com/arsenm edited https://github.com/llvm/llvm-project/pull/94830 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AMDGPU] Add a new builtin type for buffer rsrc (PR #94830)
@@ -2200,6 +2206,9 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const { Align = 8; \ break; #include "clang/Basic/WebAssemblyReferenceTypes.def" +case BuiltinType::AMDGPUBufferRsrc: + Width = 128; + Align = 128; arsenm wrote: If we were exposing the pointer, it would be 160/192 https://github.com/llvm/llvm-project/pull/94830 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AMDGPU] Add a new builtin type for buffer rsrc (PR #94830)
https://github.com/arsenm commented: Need stacked PR that adds the make_buffer_rsrc builtin that shows its use https://github.com/llvm/llvm-project/pull/94830 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AMDGPU] Add a new builtin type for buffer rsrc (PR #94830)
@@ -1091,6 +1091,9 @@ enum PredefinedTypeIDs { // \brief WebAssembly reference types with auto numeration #define WASM_TYPE(Name, Id, SingletonId) PREDEF_TYPE_##Id##_ID, #include "clang/Basic/WebAssemblyReferenceTypes.def" +// \breif AMDGPU types with auto numeration arsenm wrote: Typo breif https://github.com/llvm/llvm-project/pull/94830 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CMake] Update CMake cache file for the ARM/Aarch64 cross toolchain builds. NFC. (PR #94835)
https://github.com/vvereschaka closed https://github.com/llvm/llvm-project/pull/94835 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 5aabbf0 - [CMake] Update CMake cache file for the ARM/Aarch64 cross toolchain builds. NFC. (#94835)
Author: Vladimir Vereschaka Date: 2024-06-07T22:05:41-07:00 New Revision: 5aabbf0602c48b67bb89fd37f95bf97c95ded488 URL: https://github.com/llvm/llvm-project/commit/5aabbf0602c48b67bb89fd37f95bf97c95ded488 DIFF: https://github.com/llvm/llvm-project/commit/5aabbf0602c48b67bb89fd37f95bf97c95ded488.diff LOG: [CMake] Update CMake cache file for the ARM/Aarch64 cross toolchain builds. NFC. (#94835) * generate Clang configuration file with provided target sysroot (TOOLCHAIN_TARGET_SYSROOTFS) * explicitly pass provided target sysroot into the compiler-rt tests configuration. * added ability to configure a type of the build libraries -- shared or static (TOOLCHAIN_SHARED_LIBS, default OFF) In behalf of: #94284 Added: Modified: clang/cmake/caches/CrossWinToARMLinux.cmake Removed: diff --git a/clang/cmake/caches/CrossWinToARMLinux.cmake b/clang/cmake/caches/CrossWinToARMLinux.cmake index 6826d01f8b2a7..e4d0a0c2d14cb 100644 --- a/clang/cmake/caches/CrossWinToARMLinux.cmake +++ b/clang/cmake/caches/CrossWinToARMLinux.cmake @@ -6,21 +6,23 @@ # on Windows platform. # # NOTE: the build requires a development ARM Linux root filesystem to use -# proper target platform depended library and header files: -# - create directory and put the clang configuration -#file named .cfg into it. -# - add the `--sysroot=` argument into -#this configuration file. -# - add other necessary target depended clang arguments there, -#such as '-mcpu=cortex-a78' & etc. +# proper target platform depended library and header files. +# +# The build generates a proper clang configuration file with stored +# --sysroot argument for specified target triple. Also it is possible +# to specify configuration path via CMake arguments, such as +# -DCLANG_CONFIG_FILE_USER_DIR= +# and/or +# -DCLANG_CONFIG_FILE_SYSTEM_DIR= # # See more details here: https://clang.llvm.org/docs/UsersManual.html#configuration-files # # Configure: # cmake -G Ninja ^ # -DTOOLCHAIN_TARGET_TRIPLE=aarch64-unknown-linux-gnu ^ +# -DTOOLCHAIN_TARGET_SYSROOTFS= ^ +# -DTOOLCHAIN_SHARED_LIBS=OFF ^ # -DCMAKE_INSTALL_PREFIX=../install ^ -# -DCLANG_CONFIG_FILE_USER_DIR= ^ # -DCMAKE_CXX_FLAGS="-D__OPTIMIZE__" ^ # -DREMOTE_TEST_HOST="" ^ # -DREMOTE_TEST_USER="" ^ @@ -81,6 +83,20 @@ endif() message(STATUS "Toolchain target triple: ${TOOLCHAIN_TARGET_TRIPLE}") +if (DEFINED TOOLCHAIN_TARGET_SYSROOTFS) + message(STATUS "Toolchain target sysroot: ${TOOLCHAIN_TARGET_SYSROOTFS}") + # Store the --sysroot argument for the compiler-rt test flags. + set(sysroot_flags --sysroot='${TOOLCHAIN_TARGET_SYSROOTFS}') + # Generate the clang configuration file for the specified target triple + # and store --sysroot in this file. + file(WRITE "${CMAKE_BINARY_DIR}/bin/${TOOLCHAIN_TARGET_TRIPLE}.cfg" ${sysroot_flags}) +endif() + +# Build the shared libraries for libc++/libc++abi/libunwind. +if (NOT DEFINED TOOLCHAIN_SHARED_LIBS) + set(TOOLCHAIN_SHARED_LIBS OFF) +endif() + if (NOT DEFINED LLVM_TARGETS_TO_BUILD) if ("${TOOLCHAIN_TARGET_TRIPLE}" MATCHES "^(armv|arm32)+") set(LLVM_TARGETS_TO_BUILD "ARM" CACHE STRING "") @@ -183,20 +199,21 @@ set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_CAN_EXECUTE_TESTS set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_USE_BUILTINS_LIBRARY ON CACHE BOOL "") set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_CXX_LIBRARY libcxx CACHE STRING "") -# Tell Clang to seach C++ headers alongside with the just-built binaries for the C++ compiler-rt tests. -set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_TEST_COMPILER_CFLAGS "--stdlib=libc++" CACHE STRING "") - +# The compiler-rt tests disable the clang configuration files during the execution by setting CLANG_NO_DEFAULT_CONFIG=1 +# and drops out the --sysroot from there. Provide it explicity via the test flags here if target sysroot has been specified. +set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_TEST_COMPILER_CFLAGS "--stdlib=libc++ ${sysroot_flags}" CACHE STRING "") + set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBUNWIND_USE_COMPILER_RT ON CACHE BOOL "") -set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBUNWIND_ENABLE_SHARED OFF CACHE BOOL "") +set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBUNWIND_ENABLE_SHARED ${TOOLCHAIN_SHARED_LIBS} CACHE BOOL "") set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "") set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_ENABLE_STATIC_UNWINDER ON CACHE BOOL "") set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_USE_COMPILER_RT ON CACHE BOOL "") set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS OFF CACHE BOOL "") -set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_ENABLE_S
[clang] [llvm] [clang] Reland Add tanf16 builtin and support for tan constrained intrinsic (PR #94559)
https://github.com/farzonl updated https://github.com/llvm/llvm-project/pull/94559 >From 51247e430ad49c4729e2e3664104367b13fbad9e Mon Sep 17 00:00:00 2001 From: Farzon Lotfi Date: Fri, 24 May 2024 10:01:52 -0400 Subject: [PATCH 1/3] [clang] Add tanf16 builtin and support for tan constrained intrinsic --- clang/include/clang/Basic/Builtins.td | 6 ++-- clang/lib/CodeGen/CGBuiltin.cpp | 12 +++ clang/test/CodeGen/X86/math-builtins.c| 8 ++--- .../test/CodeGen/constrained-math-builtins.c | 13 +++ clang/test/CodeGen/math-libcalls.c| 12 +++ clang/test/CodeGenOpenCL/builtins-f16.cl | 3 ++ llvm/docs/LangRef.rst | 36 +++ llvm/include/llvm/IR/ConstrainedOps.def | 1 + llvm/include/llvm/IR/Intrinsics.td| 4 +++ llvm/test/Assembler/fp-intrinsics-attr.ll | 8 + llvm/test/Feature/fp-intrinsics.ll| 11 ++ 11 files changed, 101 insertions(+), 13 deletions(-) diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td index 11982af3fa609..7bef5fd7ad40f 100644 --- a/clang/include/clang/Basic/Builtins.td +++ b/clang/include/clang/Basic/Builtins.td @@ -482,11 +482,11 @@ def SqrtF16F128 : Builtin, F16F128MathTemplate { let Prototype = "T(T)"; } -def TanF128 : Builtin { - let Spellings = ["__builtin_tanf128"]; +def TanF16F128 : Builtin, F16F128MathTemplate { + let Spellings = ["__builtin_tan"]; let Attributes = [FunctionWithBuiltinPrefix, NoThrow, ConstIgnoringErrnoAndExceptions]; - let Prototype = "__float128(__float128)"; + let Prototype = "T(T)"; } def TanhF128 : Builtin { diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index c16b69ba87567..06e201fa71e6f 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -2923,6 +2923,18 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, SetSqrtFPAccuracy(Call); return RValue::get(Call); } + +case Builtin::BItan: +case Builtin::BItanf: +case Builtin::BItanl: +case Builtin::BI__builtin_tan: +case Builtin::BI__builtin_tanf: +case Builtin::BI__builtin_tanf16: +case Builtin::BI__builtin_tanl: +case Builtin::BI__builtin_tanf128: + return RValue::get(emitUnaryMaybeConstrainedFPBuiltin( + *this, E, Intrinsic::tan, Intrinsic::experimental_constrained_tan)); + case Builtin::BItrunc: case Builtin::BItruncf: case Builtin::BItruncl: diff --git a/clang/test/CodeGen/X86/math-builtins.c b/clang/test/CodeGen/X86/math-builtins.c index 093239b448260..1e0f129b98610 100644 --- a/clang/test/CodeGen/X86/math-builtins.c +++ b/clang/test/CodeGen/X86/math-builtins.c @@ -674,10 +674,10 @@ __builtin_sqrt(f); __builtin_sqrtf(f); __builtin_sqrtl(f); __builtin_ __builtin_tan(f);__builtin_tanf(f); __builtin_tanl(f); __builtin_tanf128(f); -// NO__ERRNO: declare double @tan(double noundef) [[READNONE]] -// NO__ERRNO: declare float @tanf(float noundef) [[READNONE]] -// NO__ERRNO: declare x86_fp80 @tanl(x86_fp80 noundef) [[READNONE]] -// NO__ERRNO: declare fp128 @tanf128(fp128 noundef) [[READNONE]] +// NO__ERRNO: declare double @llvm.tan.f64(double) [[READNONE_INTRINSIC]] +// NO__ERRNO: declare float @llvm.tan.f32(float) [[READNONE_INTRINSIC]] +// NO__ERRNO: declare x86_fp80 @llvm.tan.f80(x86_fp80) [[READNONE_INTRINSIC]] +// NO__ERRNO: declare fp128 @llvm.tan.f128(fp128) [[READNONE_INTRINSIC]] // HAS_ERRNO: declare double @tan(double noundef) [[NOT_READNONE]] // HAS_ERRNO: declare float @tanf(float noundef) [[NOT_READNONE]] // HAS_ERRNO: declare x86_fp80 @tanl(x86_fp80 noundef) [[NOT_READNONE]] diff --git a/clang/test/CodeGen/constrained-math-builtins.c b/clang/test/CodeGen/constrained-math-builtins.c index 2de832dd2b6ca..6cc3a10a1e794 100644 --- a/clang/test/CodeGen/constrained-math-builtins.c +++ b/clang/test/CodeGen/constrained-math-builtins.c @@ -183,6 +183,14 @@ void foo(double *d, float f, float *fp, long double *l, int *i, const char *c, _ // CHECK: call x86_fp80 @llvm.experimental.constrained.sqrt.f80(x86_fp80 %{{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict") // CHECK: call fp128 @llvm.experimental.constrained.sqrt.f128(fp128 %{{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict") + __builtin_tan(f);__builtin_tanf(f); __builtin_tanl(f); __builtin_tanf128(f); + +// CHECK: call double @llvm.experimental.constrained.tan.f64(double %{{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict") +// CHECK: call float @llvm.experimental.constrained.tan.f32(float %{{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict") +// CHECK: call x86_fp80 @llvm.experimental.constrained.tan.f80(x86_fp80 %{{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict") +// CHECK: call fp128 @llvm.experimental.constrained.tan.f128(fp
[clang] [HLSL] Use llvm::Triple::EnvironmentType instead of HLSLShaderAttr::ShaderType (PR #93847)
https://github.com/hekota closed https://github.com/llvm/llvm-project/pull/93847 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 5d87ba1 - [HLSL] Use llvm::Triple::EnvironmentType instead of HLSLShaderAttr::ShaderType (#93847)
Author: Helena Kotas Date: 2024-06-07T21:30:04-07:00 New Revision: 5d87ba1c1f584dfbd5afaf187099b43681b2206d URL: https://github.com/llvm/llvm-project/commit/5d87ba1c1f584dfbd5afaf187099b43681b2206d DIFF: https://github.com/llvm/llvm-project/commit/5d87ba1c1f584dfbd5afaf187099b43681b2206d.diff LOG: [HLSL] Use llvm::Triple::EnvironmentType instead of HLSLShaderAttr::ShaderType (#93847) `HLSLShaderAttr::ShaderType` enum is a subset of `llvm::Triple::EnvironmentType`. We can use `llvm::Triple::EnvironmentType` directly and avoid converting one enum to another. Added: Modified: clang/include/clang/Basic/Attr.td clang/include/clang/Sema/SemaHLSL.h clang/lib/CodeGen/CGHLSLRuntime.cpp clang/lib/Sema/SemaHLSL.cpp Removed: diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 17d9a710d948b..b70b0c8b836a5 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -4470,37 +4470,20 @@ def HLSLShader : InheritableAttr { let Subjects = SubjectList<[HLSLEntry]>; let LangOpts = [HLSL]; let Args = [ -EnumArgument<"Type", "ShaderType", /*is_string=*/true, +EnumArgument<"Type", "llvm::Triple::EnvironmentType", /*is_string=*/true, ["pixel", "vertex", "geometry", "hull", "domain", "compute", "raygeneration", "intersection", "anyhit", "closesthit", "miss", "callable", "mesh", "amplification"], ["Pixel", "Vertex", "Geometry", "Hull", "Domain", "Compute", "RayGeneration", "Intersection", "AnyHit", "ClosestHit", - "Miss", "Callable", "Mesh", "Amplification"]> + "Miss", "Callable", "Mesh", "Amplification"], + /*opt=*/0, /*fake=*/0, /*isExternalType=*/1> ]; let Documentation = [HLSLSV_ShaderTypeAttrDocs]; let AdditionalMembers = [{ - static const unsigned ShaderTypeMaxValue = (unsigned)HLSLShaderAttr::Amplification; - - static llvm::Triple::EnvironmentType getTypeAsEnvironment(HLSLShaderAttr::ShaderType ShaderType) { -switch (ShaderType) { - case HLSLShaderAttr::Pixel: return llvm::Triple::Pixel; - case HLSLShaderAttr::Vertex:return llvm::Triple::Vertex; - case HLSLShaderAttr::Geometry: return llvm::Triple::Geometry; - case HLSLShaderAttr::Hull: return llvm::Triple::Hull; - case HLSLShaderAttr::Domain:return llvm::Triple::Domain; - case HLSLShaderAttr::Compute: return llvm::Triple::Compute; - case HLSLShaderAttr::RayGeneration: return llvm::Triple::RayGeneration; - case HLSLShaderAttr::Intersection: return llvm::Triple::Intersection; - case HLSLShaderAttr::AnyHit:return llvm::Triple::AnyHit; - case HLSLShaderAttr::ClosestHit:return llvm::Triple::ClosestHit; - case HLSLShaderAttr::Miss: return llvm::Triple::Miss; - case HLSLShaderAttr::Callable: return llvm::Triple::Callable; - case HLSLShaderAttr::Mesh: return llvm::Triple::Mesh; - case HLSLShaderAttr::Amplification: return llvm::Triple::Amplification; -} -llvm_unreachable("unknown enumeration value"); + static bool isValidShaderType(llvm::Triple::EnvironmentType ShaderType) { +return ShaderType >= llvm::Triple::Pixel && ShaderType <= llvm::Triple::Amplification; } }]; } diff --git a/clang/include/clang/Sema/SemaHLSL.h b/clang/include/clang/Sema/SemaHLSL.h index e145f5e7f43f8..0e41a72e444ef 100644 --- a/clang/include/clang/Sema/SemaHLSL.h +++ b/clang/include/clang/Sema/SemaHLSL.h @@ -39,7 +39,7 @@ class SemaHLSL : public SemaBase { const AttributeCommonInfo &AL, int X, int Y, int Z); HLSLShaderAttr *mergeShaderAttr(Decl *D, const AttributeCommonInfo &AL, - HLSLShaderAttr::ShaderType ShaderType); + llvm::Triple::EnvironmentType ShaderType); HLSLParamModifierAttr * mergeParamModifierAttr(Decl *D, const AttributeCommonInfo &AL, HLSLParamModifierAttr::Spelling Spelling); @@ -48,8 +48,8 @@ class SemaHLSL : public SemaBase { void CheckSemanticAnnotation(FunctionDecl *EntryPoint, const Decl *Param, const HLSLAnnotationAttr *AnnotationAttr); void DiagnoseAttrStageMismatch( - const Attr *A, HLSLShaderAttr::ShaderType Stage, - std::initializer_list AllowedStages); + const Attr *A, llvm::Triple::EnvironmentType Stage, + std::initializer_list AllowedStages); void DiagnoseAvailabilityViolations(TranslationUnitDecl *TU); void handleNumThreadsAttr(Decl *D, const ParsedAttr &AL); diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp index 5e6a3dd4878f4..55ba21ae2ba69 100644 --- a/clan
[clang] [CMake] Update CMake cache file for the ARM/Aarch64 cross toolchain builds. NFC. (PR #94835)
https://github.com/vvereschaka updated https://github.com/llvm/llvm-project/pull/94835 >From 4135be7d1e1ca702324bd8a80c20acc034b18ecb Mon Sep 17 00:00:00 2001 From: Vladimir Vereschaka Date: Fri, 7 Jun 2024 20:58:10 -0700 Subject: [PATCH] [CMake] Update CMake cache file for the ARM/Aarch64 cross toolchain builds. NFC. * generate Clang configuration file with provided target sysroot (TOOLCHAIN_TARGET_SYSROOTFS) * explicitly pass provided target sysroot into the compiler-rt tests configuration. * added ability to configure a type of the build libraries -- shared or static (TOOLCHAIN_SHARED_LIBS, default OFF) --- clang/cmake/caches/CrossWinToARMLinux.cmake | 45 ++--- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/clang/cmake/caches/CrossWinToARMLinux.cmake b/clang/cmake/caches/CrossWinToARMLinux.cmake index 6826d01f8b2a7..e4d0a0c2d14cb 100644 --- a/clang/cmake/caches/CrossWinToARMLinux.cmake +++ b/clang/cmake/caches/CrossWinToARMLinux.cmake @@ -6,21 +6,23 @@ # on Windows platform. # # NOTE: the build requires a development ARM Linux root filesystem to use -# proper target platform depended library and header files: -# - create directory and put the clang configuration -#file named .cfg into it. -# - add the `--sysroot=` argument into -#this configuration file. -# - add other necessary target depended clang arguments there, -#such as '-mcpu=cortex-a78' & etc. +# proper target platform depended library and header files. +# +# The build generates a proper clang configuration file with stored +# --sysroot argument for specified target triple. Also it is possible +# to specify configuration path via CMake arguments, such as +# -DCLANG_CONFIG_FILE_USER_DIR= +# and/or +# -DCLANG_CONFIG_FILE_SYSTEM_DIR= # # See more details here: https://clang.llvm.org/docs/UsersManual.html#configuration-files # # Configure: # cmake -G Ninja ^ # -DTOOLCHAIN_TARGET_TRIPLE=aarch64-unknown-linux-gnu ^ +# -DTOOLCHAIN_TARGET_SYSROOTFS= ^ +# -DTOOLCHAIN_SHARED_LIBS=OFF ^ # -DCMAKE_INSTALL_PREFIX=../install ^ -# -DCLANG_CONFIG_FILE_USER_DIR= ^ # -DCMAKE_CXX_FLAGS="-D__OPTIMIZE__" ^ # -DREMOTE_TEST_HOST="" ^ # -DREMOTE_TEST_USER="" ^ @@ -81,6 +83,20 @@ endif() message(STATUS "Toolchain target triple: ${TOOLCHAIN_TARGET_TRIPLE}") +if (DEFINED TOOLCHAIN_TARGET_SYSROOTFS) + message(STATUS "Toolchain target sysroot: ${TOOLCHAIN_TARGET_SYSROOTFS}") + # Store the --sysroot argument for the compiler-rt test flags. + set(sysroot_flags --sysroot='${TOOLCHAIN_TARGET_SYSROOTFS}') + # Generate the clang configuration file for the specified target triple + # and store --sysroot in this file. + file(WRITE "${CMAKE_BINARY_DIR}/bin/${TOOLCHAIN_TARGET_TRIPLE}.cfg" ${sysroot_flags}) +endif() + +# Build the shared libraries for libc++/libc++abi/libunwind. +if (NOT DEFINED TOOLCHAIN_SHARED_LIBS) + set(TOOLCHAIN_SHARED_LIBS OFF) +endif() + if (NOT DEFINED LLVM_TARGETS_TO_BUILD) if ("${TOOLCHAIN_TARGET_TRIPLE}" MATCHES "^(armv|arm32)+") set(LLVM_TARGETS_TO_BUILD "ARM" CACHE STRING "") @@ -183,20 +199,21 @@ set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_CAN_EXECUTE_TESTS set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_USE_BUILTINS_LIBRARY ON CACHE BOOL "") set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_CXX_LIBRARY libcxx CACHE STRING "") -# Tell Clang to seach C++ headers alongside with the just-built binaries for the C++ compiler-rt tests. -set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_TEST_COMPILER_CFLAGS "--stdlib=libc++" CACHE STRING "") - +# The compiler-rt tests disable the clang configuration files during the execution by setting CLANG_NO_DEFAULT_CONFIG=1 +# and drops out the --sysroot from there. Provide it explicity via the test flags here if target sysroot has been specified. +set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_TEST_COMPILER_CFLAGS "--stdlib=libc++ ${sysroot_flags}" CACHE STRING "") + set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBUNWIND_USE_COMPILER_RT ON CACHE BOOL "") -set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBUNWIND_ENABLE_SHARED OFF CACHE BOOL "") +set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBUNWIND_ENABLE_SHARED ${TOOLCHAIN_SHARED_LIBS} CACHE BOOL "") set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "") set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_ENABLE_STATIC_UNWINDER ON CACHE BOOL "") set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_USE_COMPILER_RT ON CACHE BOOL "") set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS OFF CACHE BOOL "") -set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_ENABLE_SHARED OFF CACHE BOOL "") +set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_ENABLE_SHARED ${TOOLCHAIN_S
[clang] [CMake] Update CMake cache file for the ARM/Aarch64 cross toolchain builds. NFC. (PR #94835)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Vladimir Vereschaka (vvereschaka) Changes * generate Clang configuration file with provided target sysroot (TOOLCHAIN_TARGET_SYSROOTFS) * explicitly pass provided target sysroot into the compiler-rt tests configuration. * added ability to configure a type of the build libraries -- shared or static (TOOLCHAIN_SHARED_LIBS, default OFF) In behalf of: #94284 --- Full diff: https://github.com/llvm/llvm-project/pull/94835.diff 1 Files Affected: - (modified) clang/cmake/caches/CrossWinToARMLinux.cmake (+31-14) ``diff diff --git a/clang/cmake/caches/CrossWinToARMLinux.cmake b/clang/cmake/caches/CrossWinToARMLinux.cmake index 6826d01f8b2a7..e4d0a0c2d14cb 100644 --- a/clang/cmake/caches/CrossWinToARMLinux.cmake +++ b/clang/cmake/caches/CrossWinToARMLinux.cmake @@ -6,21 +6,23 @@ # on Windows platform. # # NOTE: the build requires a development ARM Linux root filesystem to use -# proper target platform depended library and header files: -# - create directory and put the clang configuration -#file named .cfg into it. -# - add the `--sysroot=` argument into -#this configuration file. -# - add other necessary target depended clang arguments there, -#such as '-mcpu=cortex-a78' & etc. +# proper target platform depended library and header files. +# +# The build generates a proper clang configuration file with stored +# --sysroot argument for specified target triple. Also it is possible +# to specify configuration path via CMake arguments, such as +# -DCLANG_CONFIG_FILE_USER_DIR= +# and/or +# -DCLANG_CONFIG_FILE_SYSTEM_DIR= # # See more details here: https://clang.llvm.org/docs/UsersManual.html#configuration-files # # Configure: # cmake -G Ninja ^ # -DTOOLCHAIN_TARGET_TRIPLE=aarch64-unknown-linux-gnu ^ +# -DTOOLCHAIN_TARGET_SYSROOTFS= ^ +# -DTOOLCHAIN_SHARED_LIBS=OFF ^ # -DCMAKE_INSTALL_PREFIX=../install ^ -# -DCLANG_CONFIG_FILE_USER_DIR= ^ # -DCMAKE_CXX_FLAGS="-D__OPTIMIZE__" ^ # -DREMOTE_TEST_HOST="" ^ # -DREMOTE_TEST_USER="" ^ @@ -81,6 +83,20 @@ endif() message(STATUS "Toolchain target triple: ${TOOLCHAIN_TARGET_TRIPLE}") +if (DEFINED TOOLCHAIN_TARGET_SYSROOTFS) + message(STATUS "Toolchain target sysroot: ${TOOLCHAIN_TARGET_SYSROOTFS}") + # Store the --sysroot argument for the compiler-rt test flags. + set(sysroot_flags --sysroot='${TOOLCHAIN_TARGET_SYSROOTFS}') + # Generate the clang configuration file for the specified target triple + # and store --sysroot in this file. + file(WRITE "${CMAKE_BINARY_DIR}/bin/${TOOLCHAIN_TARGET_TRIPLE}.cfg" ${sysroot_flags}) +endif() + +# Build the shared libraries for libc++/libc++abi/libunwind. +if (NOT DEFINED TOOLCHAIN_SHARED_LIBS) + set(TOOLCHAIN_SHARED_LIBS OFF) +endif() + if (NOT DEFINED LLVM_TARGETS_TO_BUILD) if ("${TOOLCHAIN_TARGET_TRIPLE}" MATCHES "^(armv|arm32)+") set(LLVM_TARGETS_TO_BUILD "ARM" CACHE STRING "") @@ -183,20 +199,21 @@ set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_CAN_EXECUTE_TESTS set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_USE_BUILTINS_LIBRARY ON CACHE BOOL "") set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_CXX_LIBRARY libcxx CACHE STRING "") -# Tell Clang to seach C++ headers alongside with the just-built binaries for the C++ compiler-rt tests. -set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_TEST_COMPILER_CFLAGS "--stdlib=libc++" CACHE STRING "") - +# The compiler-rt tests disable the clang configuration files during the execution by setting CLANG_NO_DEFAULT_CONFIG=1 +# and drops out the --sysroot from there. Provide it explicity via the test flags here if target sysroot has been specified. +set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_TEST_COMPILER_CFLAGS "--stdlib=libc++ ${sysroot_flags}" CACHE STRING "") + set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBUNWIND_USE_COMPILER_RT ON CACHE BOOL "") -set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBUNWIND_ENABLE_SHARED OFF CACHE BOOL "") +set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBUNWIND_ENABLE_SHARED ${TOOLCHAIN_SHARED_LIBS} CACHE BOOL "") set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "") set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_ENABLE_STATIC_UNWINDER ON CACHE BOOL "") set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_USE_COMPILER_RT ON CACHE BOOL "") set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS OFF CACHE BOOL "") -set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_ENABLE_SHARED OFF CACHE BOOL "") +set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_ENABLE_SHARED ${TOOLCHAIN_SHARED_LIBS} CACHE BOOL "") set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_USE_COMPILER_RT ON CACHE BOOL "") -set(RUNTIMES_${TOOLCHAIN_T
[clang] [CMake] Update CMake cache file for the ARM/Aarch64 cross toolchain builds. NFC. (PR #94835)
https://github.com/vvereschaka created https://github.com/llvm/llvm-project/pull/94835 * generate Clang configuration file with provided target sysroot (TOOLCHAIN_TARGET_SYSROOTFS) * explicitly pass provided target sysroot into the compiler-rt tests configuration. * added ability to configure a type of the build libraries -- shared or static (TOOLCHAIN_SHARED_LIBS, default OFF) In behalf of: #94284 >From 929abc43dae5af66d3f45b36eef84780ff7effae Mon Sep 17 00:00:00 2001 From: Vladimir Vereschaka Date: Fri, 7 Jun 2024 20:58:10 -0700 Subject: [PATCH] [CMake] Update CMake cache file for the ARM/Aarch64 cross toolchain builds. NFC. * generate Clang configuration file with provided target sysroot (TOOLCHAIN_TARGET_SYSROOTFS) * explicity pass provided target sysroot into the compiler-rt tests configuration. * added ability to configure a type of the build libraries -- sharead or static (TOOLCHAIN_SHARED_LIBS, default OFF) --- clang/cmake/caches/CrossWinToARMLinux.cmake | 45 ++--- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/clang/cmake/caches/CrossWinToARMLinux.cmake b/clang/cmake/caches/CrossWinToARMLinux.cmake index 6826d01f8b2a7..e4d0a0c2d14cb 100644 --- a/clang/cmake/caches/CrossWinToARMLinux.cmake +++ b/clang/cmake/caches/CrossWinToARMLinux.cmake @@ -6,21 +6,23 @@ # on Windows platform. # # NOTE: the build requires a development ARM Linux root filesystem to use -# proper target platform depended library and header files: -# - create directory and put the clang configuration -#file named .cfg into it. -# - add the `--sysroot=` argument into -#this configuration file. -# - add other necessary target depended clang arguments there, -#such as '-mcpu=cortex-a78' & etc. +# proper target platform depended library and header files. +# +# The build generates a proper clang configuration file with stored +# --sysroot argument for specified target triple. Also it is possible +# to specify configuration path via CMake arguments, such as +# -DCLANG_CONFIG_FILE_USER_DIR= +# and/or +# -DCLANG_CONFIG_FILE_SYSTEM_DIR= # # See more details here: https://clang.llvm.org/docs/UsersManual.html#configuration-files # # Configure: # cmake -G Ninja ^ # -DTOOLCHAIN_TARGET_TRIPLE=aarch64-unknown-linux-gnu ^ +# -DTOOLCHAIN_TARGET_SYSROOTFS= ^ +# -DTOOLCHAIN_SHARED_LIBS=OFF ^ # -DCMAKE_INSTALL_PREFIX=../install ^ -# -DCLANG_CONFIG_FILE_USER_DIR= ^ # -DCMAKE_CXX_FLAGS="-D__OPTIMIZE__" ^ # -DREMOTE_TEST_HOST="" ^ # -DREMOTE_TEST_USER="" ^ @@ -81,6 +83,20 @@ endif() message(STATUS "Toolchain target triple: ${TOOLCHAIN_TARGET_TRIPLE}") +if (DEFINED TOOLCHAIN_TARGET_SYSROOTFS) + message(STATUS "Toolchain target sysroot: ${TOOLCHAIN_TARGET_SYSROOTFS}") + # Store the --sysroot argument for the compiler-rt test flags. + set(sysroot_flags --sysroot='${TOOLCHAIN_TARGET_SYSROOTFS}') + # Generate the clang configuration file for the specified target triple + # and store --sysroot in this file. + file(WRITE "${CMAKE_BINARY_DIR}/bin/${TOOLCHAIN_TARGET_TRIPLE}.cfg" ${sysroot_flags}) +endif() + +# Build the shared libraries for libc++/libc++abi/libunwind. +if (NOT DEFINED TOOLCHAIN_SHARED_LIBS) + set(TOOLCHAIN_SHARED_LIBS OFF) +endif() + if (NOT DEFINED LLVM_TARGETS_TO_BUILD) if ("${TOOLCHAIN_TARGET_TRIPLE}" MATCHES "^(armv|arm32)+") set(LLVM_TARGETS_TO_BUILD "ARM" CACHE STRING "") @@ -183,20 +199,21 @@ set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_CAN_EXECUTE_TESTS set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_USE_BUILTINS_LIBRARY ON CACHE BOOL "") set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_CXX_LIBRARY libcxx CACHE STRING "") -# Tell Clang to seach C++ headers alongside with the just-built binaries for the C++ compiler-rt tests. -set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_TEST_COMPILER_CFLAGS "--stdlib=libc++" CACHE STRING "") - +# The compiler-rt tests disable the clang configuration files during the execution by setting CLANG_NO_DEFAULT_CONFIG=1 +# and drops out the --sysroot from there. Provide it explicity via the test flags here if target sysroot has been specified. +set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_TEST_COMPILER_CFLAGS "--stdlib=libc++ ${sysroot_flags}" CACHE STRING "") + set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBUNWIND_USE_COMPILER_RT ON CACHE BOOL "") -set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBUNWIND_ENABLE_SHARED OFF CACHE BOOL "") +set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBUNWIND_ENABLE_SHARED ${TOOLCHAIN_SHARED_LIBS} CACHE BOOL "") set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "") set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_ENABLE_STATIC_UNWINDER ON CACHE BOOL "") set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_USE_COMPILER_RT ON
[clang-tools-extra] [clang-tidy] In C++17, callee is guaranteed to be sequenced before arguments. (PR #93623)
https://github.com/tchaikov updated https://github.com/llvm/llvm-project/pull/93623 >From 00df70151da03f9a3d3c6ae3ee8078fd6ff654f0 Mon Sep 17 00:00:00 2001 From: martinboehme Date: Wed, 29 May 2024 07:23:35 +0800 Subject: [PATCH] [clang-tidy] Let bugprone-use-after-move ignore the moved variable in callee In C++17, callee is guaranteed to be sequenced before arguments. This eliminates false positives in bugprone-use-after-move where a variable is used in the callee and moved from in the arguments. We introduce one special case: If the callee is a MemberExpr with a DeclRefExpr as its base, we consider it to be sequenced after the arguments. This is because the variable referenced in the base will only actually be accessed when the call happens, i.e. once all of the arguments have been evaluated. This has no basis in the C++ standard, but it reflects actual behavior that is relevant to a use-after-move scenario: ``` a.bar(consumeA(std::move(a)); In this example, we end up accessing a after it has been moved from, even though nominally the callee a.bar is evaluated before the argument consumeA(std::move(a)). ``` Treating this scenario correctly has required rewriting the logic in bugprone-use-after-move that governs whether the use happens in a later loop iteration than the move. This was previously based on an unsound heuristic (does the use come lexically before the move?); we now use a more rigourous criterion based on reachability in the CFG. Fixes #57758 Fixes #59612 --- .../clang-tidy/bugprone/UseAfterMoveCheck.cpp | 40 --- .../clang-tidy/utils/ExprSequence.cpp | 68 +-- clang-tools-extra/docs/ReleaseNotes.rst | 5 +- .../checkers/bugprone/use-after-move.cpp | 50 +- 4 files changed, 147 insertions(+), 16 deletions(-) diff --git a/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp index b91ad0f182295..3072c709b3120 100644 --- a/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp @@ -11,9 +11,11 @@ #include "clang/AST/Expr.h" #include "clang/AST/ExprCXX.h" #include "clang/ASTMatchers/ASTMatchers.h" +#include "clang/Analysis/Analyses/CFGReachabilityAnalysis.h" #include "clang/Analysis/CFG.h" #include "clang/Lex/Lexer.h" #include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/SmallPtrSet.h" #include "../utils/ExprSequence.h" #include "../utils/Matchers.h" @@ -35,6 +37,11 @@ struct UseAfterMove { // Is the order in which the move and the use are evaluated undefined? bool EvaluationOrderUndefined; + + // Does the use happen in a later loop iteration than the move? + // + // We default to false and change it to true if required in find(). + bool UseHappensInLaterLoopIteration = false; }; /// Finds uses of a variable after a move (and maintains state required by the @@ -48,7 +55,7 @@ class UseAfterMoveFinder { // use-after-move is found, writes information about it to 'TheUseAfterMove'. // Returns whether a use-after-move was found. bool find(Stmt *CodeBlock, const Expr *MovingCall, -const ValueDecl *MovedVariable, UseAfterMove *TheUseAfterMove); +const DeclRefExpr *MovedVariable, UseAfterMove *TheUseAfterMove); private: bool findInternal(const CFGBlock *Block, const Expr *MovingCall, @@ -89,7 +96,7 @@ UseAfterMoveFinder::UseAfterMoveFinder(ASTContext *TheContext) : Context(TheContext) {} bool UseAfterMoveFinder::find(Stmt *CodeBlock, const Expr *MovingCall, - const ValueDecl *MovedVariable, + const DeclRefExpr *MovedVariable, UseAfterMove *TheUseAfterMove) { // Generate the CFG manually instead of through an AnalysisDeclContext because // it seems the latter can't be used to generate a CFG for the body of a @@ -110,15 +117,32 @@ bool UseAfterMoveFinder::find(Stmt *CodeBlock, const Expr *MovingCall, BlockMap = std::make_unique(TheCFG.get(), Context); Visited.clear(); - const CFGBlock *Block = BlockMap->blockContainingStmt(MovingCall); - if (!Block) { + const CFGBlock *MoveBlock = BlockMap->blockContainingStmt(MovingCall); + if (!MoveBlock) { // This can happen if MovingCall is in a constructor initializer, which is // not included in the CFG because the CFG is built only from the function // body. -Block = &TheCFG->getEntry(); +MoveBlock = &TheCFG->getEntry(); } - return findInternal(Block, MovingCall, MovedVariable, TheUseAfterMove); + bool Found = findInternal(MoveBlock, MovingCall, MovedVariable->getDecl(), +TheUseAfterMove); + + if (Found) { +if (const CFGBlock *UseBlock = +BlockMap->blockContainingStmt(TheUseAfterMove->DeclRef)) { + // Does the use happen in a later loop iteration than the move? + // - If they are in the same
[clang] Sema: Fix CXXRecordDecl::isTriviallyCopyable() for classes with all deleted special functions. (PR #94831)
MagentaTreehouse wrote: #38398 https://github.com/llvm/llvm-project/pull/94831 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] In C++17, callee is guaranteed to be sequenced before arguments. (PR #93623)
https://github.com/tchaikov edited https://github.com/llvm/llvm-project/pull/93623 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Sema: Fix CXXRecordDecl::isTriviallyCopyable() for classes with all deleted special functions. (PR #94831)
llvmbot wrote: @llvm/pr-subscribers-clang Author: None (pcc) Changes C++17 added the following requirement for a class to be trivially copyable: "that has at least one non-deleted copy constructor, move constructor, copy assignment operator, or move assignment operator". However, this was not implemented. Fix it. --- Full diff: https://github.com/llvm/llvm-project/pull/94831.diff 3 Files Affected: - (modified) clang/include/clang/AST/CXXRecordDeclDefinitionBits.def (+3) - (modified) clang/lib/AST/DeclCXX.cpp (+21-4) - (modified) clang/test/SemaCXX/type-traits.cpp (+8) ``diff diff --git a/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def b/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def index cdf0804680ad0..55cd45348d29d 100644 --- a/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def +++ b/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def @@ -249,4 +249,7 @@ FIELD(HasDeclaredCopyAssignmentWithConstParam, 1, MERGE_OR) /// base classes or fields have a no-return destructor FIELD(IsAnyDestructorNoReturn, 1, NO_MERGE) +/// The special members of this class which were deleted. +FIELD(HasDeletedSpecialMembers, 6, MERGE_OR) + #undef FIELD diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp index 7f2c786547b9b..a3de4d3654006 100644 --- a/clang/lib/AST/DeclCXX.cpp +++ b/clang/lib/AST/DeclCXX.cpp @@ -109,9 +109,9 @@ CXXRecordDecl::DefinitionData::DefinitionData(CXXRecordDecl *D) ImplicitCopyAssignmentHasConstParam(true), HasDeclaredCopyConstructorWithConstParam(false), HasDeclaredCopyAssignmentWithConstParam(false), - IsAnyDestructorNoReturn(false), IsLambda(false), - IsParsingBaseSpecifiers(false), ComputedVisibleConversions(false), - HasODRHash(false), Definition(D) {} + IsAnyDestructorNoReturn(false), HasDeletedSpecialMembers(0), + IsLambda(false), IsParsingBaseSpecifiers(false), + ComputedVisibleConversions(false), HasODRHash(false), Definition(D) {} CXXBaseSpecifier *CXXRecordDecl::DefinitionData::getBasesSlowCase() const { return Bases.get(Definition->getASTContext().getExternalSource()); @@ -586,6 +586,14 @@ bool CXXRecordDecl::isTriviallyCopyable() const { if (hasNonTrivialMoveAssignment()) return false; // -- has a trivial destructor. if (!hasTrivialDestructor()) return false; + // C++17 [class]p6: that has at least one non-deleted copy constructor, move + // constructor, copy assignment operator, or move assignment operator, + if (getASTContext().getLangOpts().CPlusPlus17 && + (data().HasDeletedSpecialMembers & + (SMF_CopyAssignment | SMF_CopyConstructor | SMF_MoveAssignment | +SMF_MoveConstructor)) == (SMF_CopyAssignment | SMF_CopyConstructor | + SMF_MoveAssignment | SMF_MoveConstructor)) +return false; return true; } @@ -1446,7 +1454,10 @@ void CXXRecordDecl::addedEligibleSpecialMemberFunction(const CXXMethodDecl *MD, // out whether it's trivial yet (not until we get to the end of the // class). We'll handle this method in // finishedDefaultedOrDeletedMember. - } else if (MD->isTrivial()) { +return; + } + + if (MD->isTrivial()) { data().HasTrivialSpecialMembers |= SMKind; data().HasTrivialSpecialMembersForCall |= SMKind; } else if (MD->isTrivialForCall()) { @@ -1462,6 +1473,10 @@ void CXXRecordDecl::addedEligibleSpecialMemberFunction(const CXXMethodDecl *MD, if (!MD->isUserProvided()) data().DeclaredNonTrivialSpecialMembersForCall |= SMKind; } + + if (MD->isDeleted()) { +data().HasDeletedSpecialMembers |= SMKind; + } } void CXXRecordDecl::finishedDefaultedOrDeletedMember(CXXMethodDecl *D) { @@ -1499,6 +1514,8 @@ void CXXRecordDecl::finishedDefaultedOrDeletedMember(CXXMethodDecl *D) { data().HasTrivialSpecialMembers |= SMKind; else data().DeclaredNonTrivialSpecialMembers |= SMKind; +if (D->isDeleted()) + data().HasDeletedSpecialMembers |= SMKind; } } diff --git a/clang/test/SemaCXX/type-traits.cpp b/clang/test/SemaCXX/type-traits.cpp index d40605f56f1ed..27b0d204d5690 100644 --- a/clang/test/SemaCXX/type-traits.cpp +++ b/clang/test/SemaCXX/type-traits.cpp @@ -1377,7 +1377,11 @@ void is_trivial2() static_assert(__is_trivial(UnionAr)); static_assert(__is_trivial(TrivialStruct)); static_assert(__is_trivial(AllDefaulted)); +#if __cplusplus >= 201703L + static_assert(!__is_trivial(AllDeleted)); +#else static_assert(__is_trivial(AllDeleted)); +#endif static_assert(!__is_trivial(void)); static_assert(!__is_trivial(NonTrivialStruct)); @@ -1419,7 +1423,11 @@ void is_trivially_copyable2() static_assert(__is_trivially_copyable(TrivialStruct)); static_assert(__is_trivially_copyable(NonTrivialStruct)); static_assert(__is_trivially_copyable(AllDefaulted)); +#if __cplusplus >= 201703L + static_assert(!__is_trivially_copyable(AllDeleted)); +#else static_assert(__is_trivially_copyable(AllDe
[clang] Sema: Fix CXXRecordDecl::isTriviallyCopyable() for classes with all deleted special functions. (PR #94831)
https://github.com/pcc created https://github.com/llvm/llvm-project/pull/94831 C++17 added the following requirement for a class to be trivially copyable: "that has at least one non-deleted copy constructor, move constructor, copy assignment operator, or move assignment operator". However, this was not implemented. Fix it. >From f725de0cd89b0dd90ce5209cb6b3d9632a52f3c9 Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Fri, 7 Jun 2024 20:14:15 -0700 Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?= =?UTF-8?q?l=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Created using spr 1.3.6-beta.1 --- .../clang/AST/CXXRecordDeclDefinitionBits.def | 3 +++ clang/lib/AST/DeclCXX.cpp | 25 --- clang/test/SemaCXX/type-traits.cpp| 8 ++ 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def b/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def index cdf0804680ad0..55cd45348d29d 100644 --- a/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def +++ b/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def @@ -249,4 +249,7 @@ FIELD(HasDeclaredCopyAssignmentWithConstParam, 1, MERGE_OR) /// base classes or fields have a no-return destructor FIELD(IsAnyDestructorNoReturn, 1, NO_MERGE) +/// The special members of this class which were deleted. +FIELD(HasDeletedSpecialMembers, 6, MERGE_OR) + #undef FIELD diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp index 7f2c786547b9b..a3de4d3654006 100644 --- a/clang/lib/AST/DeclCXX.cpp +++ b/clang/lib/AST/DeclCXX.cpp @@ -109,9 +109,9 @@ CXXRecordDecl::DefinitionData::DefinitionData(CXXRecordDecl *D) ImplicitCopyAssignmentHasConstParam(true), HasDeclaredCopyConstructorWithConstParam(false), HasDeclaredCopyAssignmentWithConstParam(false), - IsAnyDestructorNoReturn(false), IsLambda(false), - IsParsingBaseSpecifiers(false), ComputedVisibleConversions(false), - HasODRHash(false), Definition(D) {} + IsAnyDestructorNoReturn(false), HasDeletedSpecialMembers(0), + IsLambda(false), IsParsingBaseSpecifiers(false), + ComputedVisibleConversions(false), HasODRHash(false), Definition(D) {} CXXBaseSpecifier *CXXRecordDecl::DefinitionData::getBasesSlowCase() const { return Bases.get(Definition->getASTContext().getExternalSource()); @@ -586,6 +586,14 @@ bool CXXRecordDecl::isTriviallyCopyable() const { if (hasNonTrivialMoveAssignment()) return false; // -- has a trivial destructor. if (!hasTrivialDestructor()) return false; + // C++17 [class]p6: that has at least one non-deleted copy constructor, move + // constructor, copy assignment operator, or move assignment operator, + if (getASTContext().getLangOpts().CPlusPlus17 && + (data().HasDeletedSpecialMembers & + (SMF_CopyAssignment | SMF_CopyConstructor | SMF_MoveAssignment | +SMF_MoveConstructor)) == (SMF_CopyAssignment | SMF_CopyConstructor | + SMF_MoveAssignment | SMF_MoveConstructor)) +return false; return true; } @@ -1446,7 +1454,10 @@ void CXXRecordDecl::addedEligibleSpecialMemberFunction(const CXXMethodDecl *MD, // out whether it's trivial yet (not until we get to the end of the // class). We'll handle this method in // finishedDefaultedOrDeletedMember. - } else if (MD->isTrivial()) { +return; + } + + if (MD->isTrivial()) { data().HasTrivialSpecialMembers |= SMKind; data().HasTrivialSpecialMembersForCall |= SMKind; } else if (MD->isTrivialForCall()) { @@ -1462,6 +1473,10 @@ void CXXRecordDecl::addedEligibleSpecialMemberFunction(const CXXMethodDecl *MD, if (!MD->isUserProvided()) data().DeclaredNonTrivialSpecialMembersForCall |= SMKind; } + + if (MD->isDeleted()) { +data().HasDeletedSpecialMembers |= SMKind; + } } void CXXRecordDecl::finishedDefaultedOrDeletedMember(CXXMethodDecl *D) { @@ -1499,6 +1514,8 @@ void CXXRecordDecl::finishedDefaultedOrDeletedMember(CXXMethodDecl *D) { data().HasTrivialSpecialMembers |= SMKind; else data().DeclaredNonTrivialSpecialMembers |= SMKind; +if (D->isDeleted()) + data().HasDeletedSpecialMembers |= SMKind; } } diff --git a/clang/test/SemaCXX/type-traits.cpp b/clang/test/SemaCXX/type-traits.cpp index d40605f56f1ed..27b0d204d5690 100644 --- a/clang/test/SemaCXX/type-traits.cpp +++ b/clang/test/SemaCXX/type-traits.cpp @@ -1377,7 +1377,11 @@ void is_trivial2() static_assert(__is_trivial(UnionAr)); static_assert(__is_trivial(TrivialStruct)); static_assert(__is_trivial(AllDefaulted)); +#if __cplusplus >= 201703L + static_assert(!__is_trivial(AllDeleted)); +#else static_assert(__is_trivial(AllDeleted)); +#endif static_assert(!__is_trivial(void)); static_assert(!__is_trivial(NonTrivialStruct)); @@ -1419,7 +1423,11 @@ void is_trivially_co
[clang-tools-extra] [clang-tidy] In C++17, callee is guaranteed to be sequenced before arguments. (PR #93623)
tchaikov wrote: @5chmidti Thanks for your thoughtful review and suggestions! I've incorporated them into the latest revision, which I'd appreciate you taking another look at. https://github.com/llvm/llvm-project/pull/93623 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] In C++17, callee is guaranteed to be sequenced before arguments. (PR #93623)
https://github.com/tchaikov edited https://github.com/llvm/llvm-project/pull/93623 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] In C++17, callee is guaranteed to be sequenced before arguments. (PR #93623)
https://github.com/tchaikov edited https://github.com/llvm/llvm-project/pull/93623 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] In C++17, callee is guaranteed to be sequenced before arguments. (PR #93623)
https://github.com/tchaikov updated https://github.com/llvm/llvm-project/pull/93623 >From cb1dfa3c776e6c1c327acc6ec7f02c4bceb64069 Mon Sep 17 00:00:00 2001 From: martinboehme Date: Wed, 29 May 2024 07:23:35 +0800 Subject: [PATCH] [clang-tidy] Let bugprone-use-after-move ignore the moved variable in callee In C++17, callee is guaranteed to be sequenced before arguments. This eliminates false positives in bugprone-use-after-move where a variable is used in the callee and moved from in the arguments. We introduce one special case: If the callee is a MemberExpr with a DeclRefExpr as its base, we consider it to be sequenced after the arguments. This is because the variable referenced in the base will only actually be accessed when the call happens, i.e. once all of the arguments have been evaluated. This has no basis in the C++ standard, but it reflects actual behavior that is relevant to a use-after-move scenario: ``` a.bar(consumeA(std::move(a)); In this example, we end up accessing a after it has been moved from, even though nominally the callee a.bar is evaluated before the argument consumeA(std::move(a)). ``` Treating this scenario correctly has required rewriting the logic in bugprone-use-after-move that governs whether the use happens in a later loop iteration than the move. This was previously based on an unsound heuristic (does the use come lexically before the move?); we now use a more rigourous criterion based on reachability in the CFG. Fixes #57758 Fixes #59612 --- .../clang-tidy/bugprone/UseAfterMoveCheck.cpp | 39 --- .../clang-tidy/utils/ExprSequence.cpp | 68 +-- clang-tools-extra/docs/ReleaseNotes.rst | 5 +- .../checkers/bugprone/use-after-move.cpp | 50 +- 4 files changed, 146 insertions(+), 16 deletions(-) diff --git a/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp index b91ad0f182295..0130f4f17f5cc 100644 --- a/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp @@ -11,9 +11,11 @@ #include "clang/AST/Expr.h" #include "clang/AST/ExprCXX.h" #include "clang/ASTMatchers/ASTMatchers.h" +#include "clang/Analysis/Analyses/CFGReachabilityAnalysis.h" #include "clang/Analysis/CFG.h" #include "clang/Lex/Lexer.h" #include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/SmallPtrSet.h" #include "../utils/ExprSequence.h" #include "../utils/Matchers.h" @@ -35,6 +37,11 @@ struct UseAfterMove { // Is the order in which the move and the use are evaluated undefined? bool EvaluationOrderUndefined; + + // Does the use happen in a later loop iteration than the move? + // + // We default to false and change it to true if required in find(). + bool UseHappensInLaterLoopIteration = false; }; /// Finds uses of a variable after a move (and maintains state required by the @@ -48,7 +55,7 @@ class UseAfterMoveFinder { // use-after-move is found, writes information about it to 'TheUseAfterMove'. // Returns whether a use-after-move was found. bool find(Stmt *CodeBlock, const Expr *MovingCall, -const ValueDecl *MovedVariable, UseAfterMove *TheUseAfterMove); +const DeclRefExpr *MovedVariable, UseAfterMove *TheUseAfterMove); private: bool findInternal(const CFGBlock *Block, const Expr *MovingCall, @@ -89,7 +96,7 @@ UseAfterMoveFinder::UseAfterMoveFinder(ASTContext *TheContext) : Context(TheContext) {} bool UseAfterMoveFinder::find(Stmt *CodeBlock, const Expr *MovingCall, - const ValueDecl *MovedVariable, + const DeclRefExpr *MovedVariable, UseAfterMove *TheUseAfterMove) { // Generate the CFG manually instead of through an AnalysisDeclContext because // it seems the latter can't be used to generate a CFG for the body of a @@ -108,17 +115,33 @@ bool UseAfterMoveFinder::find(Stmt *CodeBlock, const Expr *MovingCall, Sequence = std::make_unique(TheCFG.get(), CodeBlock, Context); BlockMap = std::make_unique(TheCFG.get(), Context); + auto CFA = std::make_unique(*TheCFG); Visited.clear(); - const CFGBlock *Block = BlockMap->blockContainingStmt(MovingCall); - if (!Block) { + const CFGBlock *MoveBlock = BlockMap->blockContainingStmt(MovingCall); + if (!MoveBlock) { // This can happen if MovingCall is in a constructor initializer, which is // not included in the CFG because the CFG is built only from the function // body. -Block = &TheCFG->getEntry(); +MoveBlock = &TheCFG->getEntry(); } - return findInternal(Block, MovingCall, MovedVariable, TheUseAfterMove); + bool Found = findInternal(MoveBlock, MovingCall, MovedVariable->getDecl(), +TheUseAfterMove); + + if (Found) { +if (const CFGBlock *UseBlock = +BlockMap->blockContainingStmt(TheUseAfterMove->DeclRef))
[clang-tools-extra] [clang-tidy] In C++17, callee is guaranteed to be sequenced before arguments. (PR #93623)
@@ -175,6 +218,10 @@ bool UseAfterMoveFinder::findInternal(const CFGBlock *Block, MovingCall != nullptr && Sequence->potentiallyAfter(MovingCall, Use); +// We default to false here and change this to true if required in +// find(). +TheUseAfterMove->UseHappensInLaterLoopIteration = false; + tchaikov wrote: after a second thought, i am removing this initialization, and just set the default value in the `UseAfterMove`. and move the accompanied comment there. https://github.com/llvm/llvm-project/pull/93623 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] In C++17, callee is guaranteed to be sequenced before arguments. (PR #93623)
tchaikov wrote: v3: - trade `reaches()` helper for `CFGReverseBlockReachabilityAnalysis`. less repeating this way. - replace `argsContain()` helper with `llvm::is_contained()`. less repeating this way. - s/call/Call/. more consistent with the naming convention in LLVM. - initialize `EvaluationOrderUndefined` in-class https://github.com/llvm/llvm-project/pull/93623 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AMDGPU] Add builtins for instrinsic `llvm.amdgcn.raw.buffer.store` (PR #94576)
shiltian wrote: https://github.com/llvm/llvm-project/pull/94830 for buffer rsrc data type. Will update this patch afterwards. https://github.com/llvm/llvm-project/pull/94576 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] In C++17, callee is guaranteed to be sequenced before arguments. (PR #93623)
@@ -69,6 +73,30 @@ class UseAfterMoveFinder { llvm::SmallPtrSet Visited; }; +/// Returns whether the `Before` block can reach the `After` block. +bool reaches(const CFGBlock *Before, const CFGBlock *After) { + llvm::SmallVector Stack; + llvm::SmallPtrSet Visited; + + Stack.push_back(Before); + while (!Stack.empty()) { +const CFGBlock *Current = Stack.back(); +Stack.pop_back(); + +if (Current == After) + return true; + +Visited.insert(Current); + +for (const CFGBlock *Succ : Current->succs()) { + if (Succ && !Visited.contains(Succ)) +Stack.push_back(Succ); +} + } + + return false; +} + tchaikov wrote: yeah, it's equivalent to `reaches()`. will use it instead in the next revision. https://github.com/llvm/llvm-project/pull/93623 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AMDGPU] Add a new builtin type for buffer rsrc (PR #94830)
https://github.com/shiltian edited https://github.com/llvm/llvm-project/pull/94830 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AMDGPU] Add a new builtin type for buffer rsrc (PR #94830)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Shilei Tian (shiltian) Changes --- Patch is 23.90 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/94830.diff 30 Files Affected: - (modified) clang/include/clang/AST/ASTContext.h (+2) - (modified) clang/include/clang/AST/Type.h (+3) - (modified) clang/include/clang/AST/TypeProperties.td (+4) - (added) clang/include/clang/Basic/AMDGPUTypes.def (+21) - (modified) clang/include/clang/Basic/Builtins.def (+1) - (modified) clang/include/clang/Serialization/ASTBitCodes.h (+4-1) - (modified) clang/lib/AST/ASTContext.cpp (+15) - (modified) clang/lib/AST/ASTImporter.cpp (+4) - (modified) clang/lib/AST/ExprConstant.cpp (+2) - (modified) clang/lib/AST/ItaniumMangle.cpp (+6) - (modified) clang/lib/AST/MicrosoftMangle.cpp (+2) - (modified) clang/lib/AST/NSAPI.cpp (+2) - (modified) clang/lib/AST/PrintfFormatString.cpp (+2) - (modified) clang/lib/AST/Type.cpp (+6) - (modified) clang/lib/AST/TypeLoc.cpp (+2) - (modified) clang/lib/CodeGen/CGDebugInfo.cpp (+2-1) - (modified) clang/lib/CodeGen/CGDebugInfo.h (+2) - (modified) clang/lib/CodeGen/CodeGenTypes.cpp (+2) - (modified) clang/lib/CodeGen/ItaniumCXXABI.cpp (+2) - (modified) clang/lib/Index/USRGeneration.cpp (+4) - (modified) clang/lib/Sema/Sema.cpp (+6) - (modified) clang/lib/Sema/SemaExpr.cpp (+4) - (modified) clang/lib/Serialization/ASTCommon.cpp (+5) - (modified) clang/lib/Serialization/ASTReader.cpp (+5) - (added) clang/test/AST/ast-dump-amdgpu-types.c (+9) - (added) clang/test/CodeGen/amdgpu-buffer-rsrc-type.c (+8) - (added) clang/test/CodeGenCXX/amdgpu-buffer-rsrc-typeinfo.cpp (+8) - (added) clang/test/CodeGenOpenCL/amdgcn-buffer-rsrc-type.cl (+26) - (added) clang/test/SemaCXX/amdgpu-buffer-rsrc.cpp (+11) - (modified) clang/tools/libclang/CIndex.cpp (+2) ``diff diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index a1d1d1c51cd41..2328141b27e79 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -1147,6 +1147,8 @@ class ASTContext : public RefCountedBase { #include "clang/Basic/RISCVVTypes.def" #define WASM_TYPE(Name, Id, SingletonId) CanQualType SingletonId; #include "clang/Basic/WebAssemblyReferenceTypes.def" +#define AMDGPU_TYPE(Name, Id, SingletonId) CanQualType SingletonId; +#include "clang/Basic/AMDGPUTypes.def" // Types for deductions in C++0x [stmt.ranged]'s desugaring. Built on demand. mutable QualType AutoDeductTy; // Deduction against 'auto'. diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h index 9eb3f6c09e3d3..cbcd6d0f97efe 100644 --- a/clang/include/clang/AST/Type.h +++ b/clang/include/clang/AST/Type.h @@ -3015,6 +3015,9 @@ class BuiltinType : public Type { // WebAssembly reference types #define WASM_TYPE(Name, Id, SingletonId) Id, #include "clang/Basic/WebAssemblyReferenceTypes.def" +// AMDGPU types +#define AMDGPU_TYPE(Name, Id, SingletonId) Id, +#include "clang/Basic/AMDGPUTypes.def" // All other builtin types #define BUILTIN_TYPE(Id, SingletonId) Id, #define LAST_BUILTIN_TYPE(Id) LastKind = Id diff --git a/clang/include/clang/AST/TypeProperties.td b/clang/include/clang/AST/TypeProperties.td index 40dd16f080e2e..aba14b222a03a 100644 --- a/clang/include/clang/AST/TypeProperties.td +++ b/clang/include/clang/AST/TypeProperties.td @@ -861,6 +861,10 @@ let Class = BuiltinType in { case BuiltinType::ID: return ctx.SINGLETON_ID; #include "clang/Basic/WebAssemblyReferenceTypes.def" +#define AMDGPU_TYPE(NAME, ID, SINGLETON_ID) \ + case BuiltinType::ID: return ctx.SINGLETON_ID; +#include "clang/Basic/AMDGPUTypes.def" + #define BUILTIN_TYPE(ID, SINGLETON_ID) \ case BuiltinType::ID: return ctx.SINGLETON_ID; #include "clang/AST/BuiltinTypes.def" diff --git a/clang/include/clang/Basic/AMDGPUTypes.def b/clang/include/clang/Basic/AMDGPUTypes.def new file mode 100644 index 0..226e75480037c --- /dev/null +++ b/clang/include/clang/Basic/AMDGPUTypes.def @@ -0,0 +1,21 @@ +//===-- AMDGPUTypes.def - Metadata about AMDGPU types ---*- 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 various AMDGPU builtin types. +// +//===--===// + +#ifndef AMDGPU_OPAQUE_TYPE +#define AMDGPU_OPAQUE_TYPE(Name, MangledName, Id, SingletonId) \ + AMDGPU_TYPE(Name, Id, SingletonId) +#endif + +AMDGPU_OPAQUE_TYPE("__buffer_rsrc_t", "__buffer_rsrc_t", AMDGPUBufferRsrc, AMDGPUBufferRsrcTy) + +#undef AMDGPU_TYPE +#undef AMDGPU_OPAQUE_TYPE diff --git a/clang/include/clang/Basic/Builtins.def b/clang/include/clan
[clang] [Clang][AMDGPU] Add a new builtin type for buffer rsrc (PR #94830)
https://github.com/shiltian created https://github.com/llvm/llvm-project/pull/94830 None >From 891c37a3f6002c40aa0ded803330f61c3d16e6bb Mon Sep 17 00:00:00 2001 From: Shilei Tian Date: Fri, 7 Jun 2024 22:37:13 -0400 Subject: [PATCH] [Clang][AMDGPU] Add a new builtin type for buffer rsrc --- clang/include/clang/AST/ASTContext.h | 2 ++ clang/include/clang/AST/Type.h| 3 +++ clang/include/clang/AST/TypeProperties.td | 4 +++ clang/include/clang/Basic/AMDGPUTypes.def | 21 +++ clang/include/clang/Basic/Builtins.def| 1 + .../include/clang/Serialization/ASTBitCodes.h | 5 +++- clang/lib/AST/ASTContext.cpp | 15 +++ clang/lib/AST/ASTImporter.cpp | 4 +++ clang/lib/AST/ExprConstant.cpp| 2 ++ clang/lib/AST/ItaniumMangle.cpp | 6 + clang/lib/AST/MicrosoftMangle.cpp | 2 ++ clang/lib/AST/NSAPI.cpp | 2 ++ clang/lib/AST/PrintfFormatString.cpp | 2 ++ clang/lib/AST/Type.cpp| 6 + clang/lib/AST/TypeLoc.cpp | 2 ++ clang/lib/CodeGen/CGDebugInfo.cpp | 3 ++- clang/lib/CodeGen/CGDebugInfo.h | 2 ++ clang/lib/CodeGen/CodeGenTypes.cpp| 2 ++ clang/lib/CodeGen/ItaniumCXXABI.cpp | 2 ++ clang/lib/Index/USRGeneration.cpp | 4 +++ clang/lib/Sema/Sema.cpp | 6 + clang/lib/Sema/SemaExpr.cpp | 4 +++ clang/lib/Serialization/ASTCommon.cpp | 5 clang/lib/Serialization/ASTReader.cpp | 5 clang/test/AST/ast-dump-amdgpu-types.c| 9 +++ clang/test/CodeGen/amdgpu-buffer-rsrc-type.c | 8 ++ .../amdgpu-buffer-rsrc-typeinfo.cpp | 8 ++ .../CodeGenOpenCL/amdgcn-buffer-rsrc-type.cl | 26 +++ clang/test/SemaCXX/amdgpu-buffer-rsrc.cpp | 11 clang/tools/libclang/CIndex.cpp | 2 ++ 30 files changed, 172 insertions(+), 2 deletions(-) create mode 100644 clang/include/clang/Basic/AMDGPUTypes.def create mode 100644 clang/test/AST/ast-dump-amdgpu-types.c create mode 100644 clang/test/CodeGen/amdgpu-buffer-rsrc-type.c create mode 100644 clang/test/CodeGenCXX/amdgpu-buffer-rsrc-typeinfo.cpp create mode 100644 clang/test/CodeGenOpenCL/amdgcn-buffer-rsrc-type.cl create mode 100644 clang/test/SemaCXX/amdgpu-buffer-rsrc.cpp diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index a1d1d1c51cd41..2328141b27e79 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -1147,6 +1147,8 @@ class ASTContext : public RefCountedBase { #include "clang/Basic/RISCVVTypes.def" #define WASM_TYPE(Name, Id, SingletonId) CanQualType SingletonId; #include "clang/Basic/WebAssemblyReferenceTypes.def" +#define AMDGPU_TYPE(Name, Id, SingletonId) CanQualType SingletonId; +#include "clang/Basic/AMDGPUTypes.def" // Types for deductions in C++0x [stmt.ranged]'s desugaring. Built on demand. mutable QualType AutoDeductTy; // Deduction against 'auto'. diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h index 9eb3f6c09e3d3..cbcd6d0f97efe 100644 --- a/clang/include/clang/AST/Type.h +++ b/clang/include/clang/AST/Type.h @@ -3015,6 +3015,9 @@ class BuiltinType : public Type { // WebAssembly reference types #define WASM_TYPE(Name, Id, SingletonId) Id, #include "clang/Basic/WebAssemblyReferenceTypes.def" +// AMDGPU types +#define AMDGPU_TYPE(Name, Id, SingletonId) Id, +#include "clang/Basic/AMDGPUTypes.def" // All other builtin types #define BUILTIN_TYPE(Id, SingletonId) Id, #define LAST_BUILTIN_TYPE(Id) LastKind = Id diff --git a/clang/include/clang/AST/TypeProperties.td b/clang/include/clang/AST/TypeProperties.td index 40dd16f080e2e..aba14b222a03a 100644 --- a/clang/include/clang/AST/TypeProperties.td +++ b/clang/include/clang/AST/TypeProperties.td @@ -861,6 +861,10 @@ let Class = BuiltinType in { case BuiltinType::ID: return ctx.SINGLETON_ID; #include "clang/Basic/WebAssemblyReferenceTypes.def" +#define AMDGPU_TYPE(NAME, ID, SINGLETON_ID) \ + case BuiltinType::ID: return ctx.SINGLETON_ID; +#include "clang/Basic/AMDGPUTypes.def" + #define BUILTIN_TYPE(ID, SINGLETON_ID) \ case BuiltinType::ID: return ctx.SINGLETON_ID; #include "clang/AST/BuiltinTypes.def" diff --git a/clang/include/clang/Basic/AMDGPUTypes.def b/clang/include/clang/Basic/AMDGPUTypes.def new file mode 100644 index 0..226e75480037c --- /dev/null +++ b/clang/include/clang/Basic/AMDGPUTypes.def @@ -0,0 +1,21 @@ +//===-- AMDGPUTypes.def - Metadata about AMDGPU types ---*- 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 +// +//===---
[clang-tools-extra] [clang-tidy] In C++17, callee is guaranteed to be sequenced before arguments. (PR #93623)
@@ -175,6 +218,10 @@ bool UseAfterMoveFinder::findInternal(const CFGBlock *Block, MovingCall != nullptr && Sequence->potentiallyAfter(MovingCall, Use); +// We default to false here and change this to true if required in +// find(). +TheUseAfterMove->UseHappensInLaterLoopIteration = false; + tchaikov wrote: agreed. but practically, we reference `EvaluationOrderUndefined` only if `UseAfterMoveFinder::find()` returns `true`, which indicates a use-after-move is identified. see https://github.com/llvm/llvm-project/blob/4d95850d052336a785651030eafa0b24651801a0/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp#L498-L501, and the only two places where we return `true` in `UseAfterMoveFinder::findInternal()` are 1. https://github.com/llvm/llvm-project/blob/4d95850d052336a785651030eafa0b24651801a0/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp#L178 2. https://github.com/llvm/llvm-project/blob/4d95850d052336a785651030eafa0b24651801a0/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp#L188 the 2nd case is a recursive call to `UseAfterMoveFinder::findInternal()`. and the 1st case is where we set `UseHappensInLaterLoopIteration` to `false`. and we may set this member variable to `true` later on. probably a more readable implementation is to return an `optional` from `UseAfterMoveFinder::find()`, so that it's obvious that `UseAfterMove` is always initialized and returned if we find a use-after-move. but that'd be a cleanup, and not directly related to this PR. if it acceptable to piggy back it into this PR, i will do it. https://github.com/llvm/llvm-project/pull/93623 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Implement -Wmissing-include-dirs (PR #94827)
https://github.com/bradenhelmer edited https://github.com/llvm/llvm-project/pull/94827 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Implement -Wmissing-include-dirs (PR #94827)
llvmbot wrote: @llvm/pr-subscribers-clang-driver Author: Braden Helmer (bradenhelmer) Changes Implements -Wmissing-include-dirs #92015 This is my first contribution and would love some feedback. Thanks --- Full diff: https://github.com/llvm/llvm-project/pull/94827.diff 3 Files Affected: - (modified) clang/include/clang/Basic/DiagnosticDriverKinds.td (+3) - (modified) clang/include/clang/Basic/DiagnosticGroups.td (+1-1) - (modified) clang/lib/Driver/Driver.cpp (+6) ``diff diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td index 773b234cd68fe..b7d50e22cc0d0 100644 --- a/clang/include/clang/Basic/DiagnosticDriverKinds.td +++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td @@ -809,4 +809,7 @@ def warn_android_unversioned_fallback : Warning< def err_drv_triple_version_invalid : Error< "version '%0' in target triple '%1' is invalid">; + +def warn_missing_include_dirs : Warning < + "the included directory %0 is missing">, InGroup; } diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index 7d5ba7869ec34..9b37d4bd3205b 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -506,7 +506,7 @@ def MaxUnsignedZero : DiagGroup<"max-unsigned-zero">; def MissingBraces : DiagGroup<"missing-braces">; def MissingDeclarations: DiagGroup<"missing-declarations">; def : DiagGroup<"missing-format-attribute">; -def : DiagGroup<"missing-include-dirs">; +def MissingIncludeDirs : DiagGroup<"missing-include-dirs">; def MissingNoreturn : DiagGroup<"missing-noreturn">; def MultiChar : DiagGroup<"multichar">; def : DiagGroup<"nested-externs">; diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index f5ea73a04ae5c..5bc737a43338e 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -1271,6 +1271,12 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) { if (VFS->setCurrentWorkingDirectory(WD->getValue())) Diag(diag::err_drv_unable_to_set_working_directory) << WD->getValue(); + // Check for missing include directories + for (auto IncludeDir : Args.getAllArgValues(options::OPT_I_Group)) { +if (!llvm::sys::fs::is_directory(IncludeDir)) + Diag(diag::warn_missing_include_dirs) << IncludeDir; + } + // FIXME: This stuff needs to go into the Compilation, not the driver. bool CCCPrintPhases; `` https://github.com/llvm/llvm-project/pull/94827 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Implement -Wmissing-include-dirs (PR #94827)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Braden Helmer (bradenhelmer) Changes Implements -Wmissing-include-dirs #92015 This is my first contribution and would love some feedback. Thanks --- Full diff: https://github.com/llvm/llvm-project/pull/94827.diff 3 Files Affected: - (modified) clang/include/clang/Basic/DiagnosticDriverKinds.td (+3) - (modified) clang/include/clang/Basic/DiagnosticGroups.td (+1-1) - (modified) clang/lib/Driver/Driver.cpp (+6) ``diff diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td index 773b234cd68fe..b7d50e22cc0d0 100644 --- a/clang/include/clang/Basic/DiagnosticDriverKinds.td +++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td @@ -809,4 +809,7 @@ def warn_android_unversioned_fallback : Warning< def err_drv_triple_version_invalid : Error< "version '%0' in target triple '%1' is invalid">; + +def warn_missing_include_dirs : Warning < + "the included directory %0 is missing">, InGroup; } diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index 7d5ba7869ec34..9b37d4bd3205b 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -506,7 +506,7 @@ def MaxUnsignedZero : DiagGroup<"max-unsigned-zero">; def MissingBraces : DiagGroup<"missing-braces">; def MissingDeclarations: DiagGroup<"missing-declarations">; def : DiagGroup<"missing-format-attribute">; -def : DiagGroup<"missing-include-dirs">; +def MissingIncludeDirs : DiagGroup<"missing-include-dirs">; def MissingNoreturn : DiagGroup<"missing-noreturn">; def MultiChar : DiagGroup<"multichar">; def : DiagGroup<"nested-externs">; diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index f5ea73a04ae5c..5bc737a43338e 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -1271,6 +1271,12 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) { if (VFS->setCurrentWorkingDirectory(WD->getValue())) Diag(diag::err_drv_unable_to_set_working_directory) << WD->getValue(); + // Check for missing include directories + for (auto IncludeDir : Args.getAllArgValues(options::OPT_I_Group)) { +if (!llvm::sys::fs::is_directory(IncludeDir)) + Diag(diag::warn_missing_include_dirs) << IncludeDir; + } + // FIXME: This stuff needs to go into the Compilation, not the driver. bool CCCPrintPhases; `` https://github.com/llvm/llvm-project/pull/94827 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Implement -Wmissing-include-dirs (PR #94827)
github-actions[bot] wrote: Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using `@` followed by their GitHub username. If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the [LLVM GitHub User Guide](https://llvm.org/docs/GitHub.html). You can also ask questions in a comment on this PR, on the [LLVM Discord](https://discord.com/invite/xS7Z362) or on the [forums](https://discourse.llvm.org/). https://github.com/llvm/llvm-project/pull/94827 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Implement -Wmissing-include-dirs (PR #94827)
https://github.com/bradenhelmer created https://github.com/llvm/llvm-project/pull/94827 Implements -Wmissing-include-dirs #92015 This is my first contribution and would love some feedback. Thanks >From 317e4c2fe7fb0ee76f7917b64ee447ba3ed838bc Mon Sep 17 00:00:00 2001 From: Braden Helmer Date: Fri, 7 Jun 2024 21:38:04 -0400 Subject: [PATCH] Implement -Wmissing-include-dirs --- clang/include/clang/Basic/DiagnosticDriverKinds.td | 3 +++ clang/include/clang/Basic/DiagnosticGroups.td | 2 +- clang/lib/Driver/Driver.cpp| 6 ++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td index 773b234cd68fe..b7d50e22cc0d0 100644 --- a/clang/include/clang/Basic/DiagnosticDriverKinds.td +++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td @@ -809,4 +809,7 @@ def warn_android_unversioned_fallback : Warning< def err_drv_triple_version_invalid : Error< "version '%0' in target triple '%1' is invalid">; + +def warn_missing_include_dirs : Warning < + "the included directory %0 is missing">, InGroup; } diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index 7d5ba7869ec34..9b37d4bd3205b 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -506,7 +506,7 @@ def MaxUnsignedZero : DiagGroup<"max-unsigned-zero">; def MissingBraces : DiagGroup<"missing-braces">; def MissingDeclarations: DiagGroup<"missing-declarations">; def : DiagGroup<"missing-format-attribute">; -def : DiagGroup<"missing-include-dirs">; +def MissingIncludeDirs : DiagGroup<"missing-include-dirs">; def MissingNoreturn : DiagGroup<"missing-noreturn">; def MultiChar : DiagGroup<"multichar">; def : DiagGroup<"nested-externs">; diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index f5ea73a04ae5c..5bc737a43338e 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -1271,6 +1271,12 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) { if (VFS->setCurrentWorkingDirectory(WD->getValue())) Diag(diag::err_drv_unable_to_set_working_directory) << WD->getValue(); + // Check for missing include directories + for (auto IncludeDir : Args.getAllArgValues(options::OPT_I_Group)) { +if (!llvm::sys::fs::is_directory(IncludeDir)) + Diag(diag::warn_missing_include_dirs) << IncludeDir; + } + // FIXME: This stuff needs to go into the Compilation, not the driver. bool CCCPrintPhases; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [compiler-rt] [lldb] [llvm] [Memprof] Adds the option to collect AccessCountHistograms for memprof. (PR #94264)
@@ -140,12 +140,16 @@ static cl::opt ClDebugMin("memprof-debug-min", cl::desc("Debug min inst"), static cl::opt ClDebugMax("memprof-debug-max", cl::desc("Debug max inst"), cl::Hidden, cl::init(-1)); +static cl::opt ClHistogram("memprof-histogram", mattweingarten wrote: Use global variable `__memprof_histogram` in IR to set flag in runtime, and got rid of runtime flag. https://github.com/llvm/llvm-project/pull/94264 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [compiler-rt] [lldb] [llvm] [Memprof] Adds the option to collect AccessCountHistograms for memprof. (PR #94264)
https://github.com/mattweingarten updated https://github.com/llvm/llvm-project/pull/94264 error: too big or took too long to generate ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Make warning pragma override -Werror=foo and DefaultError warnings (PR #93647)
MaskRay wrote: > I think we should update our documentation: > > https://github.com/llvm/llvm-project/blob/b01ac5137c28fa5e1b44a5d850cb7a6ace7d8799/clang/docs/UsersManual.rst?plain=1#L1186 > > Overall, this seems like a sensible improvement to me and the code changes LG. Thx. Updated UserManual.rst https://github.com/llvm/llvm-project/pull/93647 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Make warning pragma override -Werror=foo and DefaultError warnings (PR #93647)
https://github.com/MaskRay edited https://github.com/llvm/llvm-project/pull/93647 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Make warning pragma override -Werror=foo and DefaultError warnings (PR #93647)
https://github.com/MaskRay updated https://github.com/llvm/llvm-project/pull/93647 >From 9770644e7db88cff2c16109ceb8cb446741d53ea Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Tue, 28 May 2024 21:33:55 -0700 Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?= =?UTF-8?q?l=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Created using spr 1.3.5-bogner --- clang/lib/Basic/Diagnostic.cpp | 5 +++-- .../implicit-built-Werror-using-W/convert.h | 4 .../Modules/implicit-built-Werror-using-W.cpp | 15 +++ clang/test/Preprocessor/pragma_diagnostic.c | 10 -- clang/test/Sema/implicit-decl.c | 17 + 5 files changed, 43 insertions(+), 8 deletions(-) diff --git a/clang/lib/Basic/Diagnostic.cpp b/clang/lib/Basic/Diagnostic.cpp index 10136b4cd9435..66776daa5e149 100644 --- a/clang/lib/Basic/Diagnostic.cpp +++ b/clang/lib/Basic/Diagnostic.cpp @@ -360,9 +360,10 @@ void DiagnosticsEngine::setSeverity(diag::kind Diag, diag::Severity Map, "Cannot map errors into warnings!"); assert((L.isInvalid() || SourceMgr) && "No SourceMgr for valid location"); - // Don't allow a mapping to a warning override an error/fatal mapping. + // A command line -Wfoo has an invalid L and cannot override error/fatal + // mapping, while a warning pragma can. bool WasUpgradedFromWarning = false; - if (Map == diag::Severity::Warning) { + if (Map == diag::Severity::Warning && L.isInvalid()) { DiagnosticMapping &Info = GetCurDiagState()->getOrAddMapping(Diag); if (Info.getSeverity() == diag::Severity::Error || Info.getSeverity() == diag::Severity::Fatal) { diff --git a/clang/test/Modules/Inputs/implicit-built-Werror-using-W/convert.h b/clang/test/Modules/Inputs/implicit-built-Werror-using-W/convert.h index 0ed02bc793bd1..532fd6e28ccc4 100644 --- a/clang/test/Modules/Inputs/implicit-built-Werror-using-W/convert.h +++ b/clang/test/Modules/Inputs/implicit-built-Werror-using-W/convert.h @@ -1,6 +1,10 @@ #ifdef USE_PRAGMA #pragma clang diagnostic push +#if USE_PRAGMA == 1 #pragma clang diagnostic warning "-Wshorten-64-to-32" +#else +#pragma clang diagnostic error "-Wshorten-64-to-32" +#endif #endif template int convert(T V) { return V; } #ifdef USE_PRAGMA diff --git a/clang/test/Modules/implicit-built-Werror-using-W.cpp b/clang/test/Modules/implicit-built-Werror-using-W.cpp index 9fb7a6bf0b035..973dbba130b7f 100644 --- a/clang/test/Modules/implicit-built-Werror-using-W.cpp +++ b/clang/test/Modules/implicit-built-Werror-using-W.cpp @@ -22,16 +22,23 @@ // RUN: | FileCheck %s -allow-empty // // In the presence of a warning pragma, build with -Werror and then without. -// RUN: not %clang_cc1 -triple x86_64-apple-darwin16 -fsyntax-only -fmodules \ -// RUN: -DUSE_PRAGMA -Werror=shorten-64-to-32 \ +// RUN: %clang_cc1 -triple x86_64-apple-darwin16 -fsyntax-only -fmodules \ +// RUN: -DUSE_PRAGMA=1 -Werror=shorten-64-to-32 \ // RUN: -I%S/Inputs/implicit-built-Werror-using-W -fimplicit-module-maps \ // RUN: -fmodules-cache-path=%t-pragma.cache -x c++ %s 2>&1 \ -// RUN: | FileCheck %s -check-prefix=CHECK-ERROR +// RUN: | FileCheck %s -check-prefix=CHECK-WARN // RUN: %clang_cc1 -triple x86_64-apple-darwin16 -fsyntax-only -fmodules \ -// RUN: -DUSE_PRAGMA \ +// RUN: -DUSE_PRAGMA=1 \ // RUN: -I%S/Inputs/implicit-built-Werror-using-W -fimplicit-module-maps \ // RUN: -fmodules-cache-path=%t-pragma.cache -x c++ %s 2>&1 \ // RUN: | FileCheck %s -check-prefix=CHECK-WARN + +// Test an error pragma. +// RUN: not %clang_cc1 -triple x86_64-apple-darwin16 -fsyntax-only -fmodules \ +// RUN: -DUSE_PRAGMA=2 -Wshorten-64-to-32 \ +// RUN: -I%S/Inputs/implicit-built-Werror-using-W -fimplicit-module-maps \ +// RUN: -fmodules-cache-path=%t-pragma.cache -x c++ %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix=CHECK-ERROR #include long long foo() { return convert(0); } diff --git a/clang/test/Preprocessor/pragma_diagnostic.c b/clang/test/Preprocessor/pragma_diagnostic.c index 8a5adcf6ab55b..ff379079b7baf 100644 --- a/clang/test/Preprocessor/pragma_diagnostic.c +++ b/clang/test/Preprocessor/pragma_diagnostic.c @@ -1,8 +1,14 @@ // RUN: %clang_cc1 -fsyntax-only -verify -Wno-undef %s // RUN: %clang_cc1 -fsyntax-only -verify -Wno-undef -Wno-unknown-warning-option -DAVOID_UNKNOWN_WARNING %s +// RUN: %clang_cc1 -fsyntax-only -verify -Werror=undef -DINITIAL_UNDEF %s +#ifdef INITIAL_UNDEF +#if FOO// expected-error {{'FOO' is not defined}} +#endif +#else #if FOO// ok. #endif +#endif #pragma GCC diagnostic warning "-Wundef" @@ -52,6 +58,6 @@ void ppq(void){} void ppr(void){} // expected-error {{no previous prototype for function 'ppr'}} // expected-note@-1{{declare 'static' if the function is not intended to be used outside of this translation unit}} -#pragma clang diagnostic warning "-Weverything" // This should not be
[clang] [llvm] Enable LLDB tests in Linux pre-merge CI (PR #94208)
mizvekov wrote: @Endilll This looks good, thanks! How will this affect test capacity? Right now, the Linux bots are lagging, while the Windows bot is breezing through. This is the opposite of the usual. Are we under-provisioned on Linux CI resources? How much worse will it get when we add this extra workload? https://github.com/llvm/llvm-project/pull/94208 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeGen] Make `UnqualPtrTy` truly unqualified (PR #94388)
AlexVlx wrote: > There are still quite a few references to UnqualPtrTy that you're not > changing yet are now wrong, no? > > ``` > $ git grep --count '\' origin/main clang > origin/main:clang/lib/CodeGen/CGAtomic.cpp:1 > origin/main:clang/lib/CodeGen/CGBlocks.cpp:1 > origin/main:clang/lib/CodeGen/CGBuiltin.cpp:13 > origin/main:clang/lib/CodeGen/CGCUDANV.cpp:1 > origin/main:clang/lib/CodeGen/CGExpr.cpp:2 > origin/main:clang/lib/CodeGen/CGObjCMac.cpp:1 > origin/main:clang/lib/CodeGen/CodeGenTypeCache.h:1 > origin/main:clang/lib/CodeGen/ItaniumCXXABI.cpp:10 > origin/main:clang/lib/CodeGen/Targets/PPC.cpp:1 > origin/main:clang/lib/CodeGen/Targets/Sparc.cpp:1 > ``` Right, going through these at the moment, I got sidetracked. https://github.com/llvm/llvm-project/pull/94388 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeGen] Make `UnqualPtrTy` truly unqualified (PR #94388)
AlexVlx wrote: > And I still strongly urge renaming what this is, given it is _not_ the type > for an unqualified C `void *`, as one would normally expect given it's in > Clang. Perhaps DummyPtrTy? DummyPtrTy seems mnemonic / on point, but it might trigger antibodies from the LLVM side:) Perhaps `NoAddrSpacePtrTy` or something to that extent? What makes this unqualified is it being just a `ptr` and not a `ptr addrspace(n)`. On the other hand, since today it's an unconditional alias for `ptr addrspace(0)`, perhaps `AS0PtrTy` or somesuch thing could also work? https://github.com/llvm/llvm-project/pull/94388 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Offload][CUDA] Add initial cuda_runtime.h overlay (PR #94821)
jdoerfert wrote: This includes the changes of #94549, I need to learn how to do stacked PRs... https://github.com/llvm/llvm-project/pull/94821 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Offload][CUDA] Allow CUDA kernels to use LLVM/Offload (PR #94549)
@@ -0,0 +1,31 @@ +/*===-- LLVM/Offload helpers for kernel languages (CUDA/HIP) -*- 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 + * + *===---=== + */ + +#include + +#define __host__ __attribute__((host)) +#define __device__ __attribute__((device)) +#define __global__ __attribute__((global)) +#define __shared__ __attribute__((shared)) +#define __constant__ __attribute__((constant)) +#define __managed__ __attribute__((managed)) + +extern "C" { + +typedef struct dim3 { + dim3() {} + dim3(unsigned x) : x(x) {} + unsigned x = 0, y = 0, z = 0; +} dim3; + +// TODO: For some reason the CUDA device compilation requires this declaration +// to be present but it should not. jdoerfert wrote: I mean that the device code generation never emits __XXXPushCallConfiguration. That is a host only call generated by the compiler. Nevertheless, it is set up such that the device side requires a valid declaration for now, which is, at least, weird. https://github.com/llvm/llvm-project/pull/94549 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Offload][CUDA] Allow CUDA kernels to use LLVM/Offload (PR #94549)
jdoerfert wrote: There seems to be some trouble with NVIDIA offload (I tested mainly AMDGPU) and f128, I'll make sure that works too. The nits are easy to address, I just copied the style around. I'll also add a IR test to match the new runtime calls and kernel argument passing. > Will kernels in TUs compiled with `-foffload-via-llvm` be interoperable with > code that wants to launch them from another TU compiled w/o > `-foffload-via-llvm` ? > > E.g.: > > * a.cu: `__global__ void kernel() { ... }` > * b.cu: `extern __global__ void kernel(); void func() { kernel<<<1,1>>>();}` > > This could use a test in the testsuite to actually check whether it works. I'll look into this. Intuitively, the kernel launch needs -foffload-via-llvm (which implies -foffload-new-driver) and the kernel definition needs -foffload-new-driver. Similarly, with the new driver flag device code should link fine. Right now, this defaults to gpu-rdc, as OpenMP does, but we can change that. On that note, non-rdc should actually internalize all but the kernels and thereby help the middle end as well. https://github.com/llvm/llvm-project/pull/94549 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-doc] Add --asset option to clang-doc (PR #94717)
@@ -0,0 +1,14 @@ +// RUN: rm -rf %t +// RUN: mkdir %t +// RUN: echo "" > %t/compile_flags.txt +// RUN: cp "%s" "%t/test.cpp" +// RUN: clang-doc --format=html --executor=standalone -p %t %t/test.cpp -output=%t/docs > %t/output.txt +// RUN: cat %t/output.txt | FileCheck %s --check-prefix=CHECK + +// CHECK: Emiting docs in html format. +// CHECK-NEXT: Using default asset: {{.*}}..\share\clang +// CHECK-NEXT: Mapping decls... +// CHECK-NEXT: Collecting infos... +// CHECK-NEXT: Reducing 0 infos... +// CHECK-NEXT: Generating docs... +// CHECK-NEXT: Generating assets for docs... ilovepi wrote: What are you testing here? if it's just `Using default asset: {{.*}}..\share\clang` then this is a more appropriate test. ```suggestion // CHECK: Using default asset: {{.*}}..\share\clang ``` https://github.com/llvm/llvm-project/pull/94717 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-doc] Add --asset option to clang-doc (PR #94717)
@@ -0,0 +1,14 @@ +// RUN: rm -rf %t +// RUN: mkdir %t +// RUN: echo "" > %t/compile_flags.txt +// RUN: cp "%s" "%t/test.cpp" +// RUN: clang-doc --format=html --executor=standalone -p %t %t/test.cpp -output=%t/docs > %t/output.txt +// RUN: cat %t/output.txt | FileCheck %s --check-prefix=CHECK ilovepi wrote: ```suggestion // RUN: clang-doc --format=html --executor=standalone -p %t %s -output=%t/docs 2>&1 | FileCheck %s ``` 1. No point in making an empty file. If it was necessary, `touch` would have been more appropriate. (BTW, what is compile_flags.txt?) 1. you can just reference this test file, just as well, without copying it at all. If there's some reason it has to be that way, write it down in comments. 1. no need for `output.txt`, just pipe it straight into `FileCheck`. If you need the file later, you still don't need to `cat`, you can just pass the file to `FileCheck` 2. You don't need to list `CHECK` under `--check-prefix=`. It's the default. https://github.com/llvm/llvm-project/pull/94717 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-doc] Add --asset option to clang-doc (PR #94717)
@@ -0,0 +1,14 @@ +// RUN: rm -rf %t +// RUN: mkdir %t ilovepi wrote: ```suggestion // RUN: rm -rf %t && mkdir %t ``` https://github.com/llvm/llvm-project/pull/94717 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeGen] Make `UnqualPtrTy` truly unqualified (PR #94388)
https://github.com/arichardson requested changes to this pull request. Ah I did not realize there were so many uses remaining. I that case those probably need auditing/changing before this change can land. https://github.com/llvm/llvm-project/pull/94388 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] deprecate alias, class templates without arg list after template kw (PR #94789)
evelez7 wrote: Looks like this heavily affects libcxx, will a `DefaultIgnore` silence the diagnostic? https://github.com/llvm/llvm-project/pull/94789 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Offload][CUDA] Add initial cuda_runtime.h overlay (PR #94821)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff bd815a54899d7fa83f6fb49d86c417e1e2e4d2ef 6a6809a50ac35e12416eb0602bdb18189c3054f3 -- clang/lib/Headers/llvm_offload_wrappers/__llvm_offload.h clang/lib/Headers/llvm_offload_wrappers/__llvm_offload_device.h clang/lib/Headers/llvm_offload_wrappers/__llvm_offload_host.h clang/lib/Headers/llvm_offload_wrappers/cuda_runtime.h offload/src/KernelLanguage/API.cpp clang/lib/CodeGen/CGCUDANV.cpp clang/lib/Driver/Driver.cpp clang/lib/Driver/ToolChains/Clang.cpp clang/lib/Driver/ToolChains/CommonArgs.cpp clang/lib/Headers/openmp_wrappers/__clang_openmp_device_functions.h clang/lib/Sema/SemaCUDA.cpp offload/include/Shared/APITypes.h offload/include/omptarget.h offload/plugins-nextgen/amdgpu/src/rtl.cpp offload/plugins-nextgen/common/src/PluginInterface.cpp `` View the diff from clang-format here. ``diff diff --git a/offload/src/KernelLanguage/API.cpp b/offload/src/KernelLanguage/API.cpp index e3c75ab67c..7b8e43e68e 100644 --- a/offload/src/KernelLanguage/API.cpp +++ b/offload/src/KernelLanguage/API.cpp @@ -8,7 +8,6 @@ // //===--===// - #include "Shared/APITypes.h" #include @@ -45,7 +44,7 @@ unsigned __llvmPushCallConfiguration(dim3 __grid_size, dim3 __block_size, unsigned __llvmPopCallConfiguration(dim3 *__grid_size, dim3 *__block_size, size_t *__shared_memory, void *__stream) { - __omp_kernel_t &__kernel = __current_kernel; + __omp_kernel_t &__kernel = __current_kernel; *__grid_size = __kernel.__grid_size; *__block_size = __kernel.__block_size; *__shared_memory = __kernel.__shared_memory; @@ -69,8 +68,7 @@ unsigned llvmLaunchKernel(const void *func, dim3 gridDim, dim3 blockDim, Args.ThreadLimit[2] = blockDim.z; Args.ArgPtrs = &args; Args.Flags.IsCUDA = true; - int rv = __tgt_target_kernel(nullptr, 0, gridDim.x, - blockDim.x, func, &Args); + int rv = __tgt_target_kernel(nullptr, 0, gridDim.x, blockDim.x, func, &Args); return rv; } } `` https://github.com/llvm/llvm-project/pull/94821 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Offload][CUDA] Add initial cuda_runtime.h overlay (PR #94821)
llvmbot wrote: @llvm/pr-subscribers-clang-driver Author: Johannes Doerfert (jdoerfert) Changes This provides the header overlay for cuda_runtime.h which is found before any CUDA installation (none is necessary). Some basic APIs are defined in terms of the omp_target_* ones, but with the pending LLVM/Offload API redesign the requirements of CUDA should be taken into account. Note: Async is not exposed by the existing runtime thus the streams are ignored. I'll address this in a follow up. --- Patch is 45.18 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/94821.diff 28 Files Affected: - (modified) clang/include/clang/Basic/LangOptions.def (+1) - (modified) clang/include/clang/Driver/Options.td (+6) - (modified) clang/lib/CodeGen/CGCUDANV.cpp (+62-15) - (modified) clang/lib/Driver/Driver.cpp (+12-7) - (modified) clang/lib/Driver/ToolChains/Clang.cpp (+26-4) - (modified) clang/lib/Driver/ToolChains/CommonArgs.cpp (+6-1) - (modified) clang/lib/Headers/CMakeLists.txt (+16-3) - (added) clang/lib/Headers/llvm_offload_wrappers/__llvm_offload.h (+31) - (added) clang/lib/Headers/llvm_offload_wrappers/__llvm_offload_device.h (+10) - (added) clang/lib/Headers/llvm_offload_wrappers/__llvm_offload_host.h (+15) - (added) clang/lib/Headers/llvm_offload_wrappers/cuda_runtime.h (+131) - (modified) clang/lib/Headers/openmp_wrappers/__clang_openmp_device_functions.h (+2-4) - (modified) clang/lib/Sema/SemaCUDA.cpp (+3) - (added) clang/test/Driver/cuda-via-liboffload.cu (+23) - (modified) offload/include/Shared/APITypes.h (+19-14) - (modified) offload/include/omptarget.h (+1-1) - (modified) offload/plugins-nextgen/amdgpu/src/rtl.cpp (+8-4) - (modified) offload/plugins-nextgen/common/src/PluginInterface.cpp (+11-3) - (modified) offload/src/CMakeLists.txt (+1) - (added) offload/src/KernelLanguage/API.cpp (+76) - (modified) offload/src/exports (+3) - (modified) offload/test/lit.cfg (+1-1) - (added) offload/test/offloading/CUDA/basic_api_malloc_free.cu (+41) - (added) offload/test/offloading/CUDA/basic_api_memcpy.cu (+46) - (added) offload/test/offloading/CUDA/basic_api_memset.cu (+43) - (added) offload/test/offloading/CUDA/basic_launch.cu (+29) - (added) offload/test/offloading/CUDA/basic_launch_blocks_and_threads.cu (+30) - (added) offload/test/offloading/CUDA/basic_launch_multi_arg.cu (+37) ``diff diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def index 4061451b2150a..8aff98867202e 100644 --- a/clang/include/clang/Basic/LangOptions.def +++ b/clang/include/clang/Basic/LangOptions.def @@ -288,6 +288,7 @@ LANGOPT(GPUMaxThreadsPerBlock, 32, 1024, "default max threads per block for kern LANGOPT(GPUDeferDiag, 1, 0, "defer host/device related diagnostic messages for CUDA/HIP") LANGOPT(GPUExcludeWrongSideOverloads, 1, 0, "always exclude wrong side overloads in overloading resolution for CUDA/HIP") LANGOPT(OffloadingNewDriver, 1, 0, "use the new driver for generating offloading code.") +LANGOPT(OffloadViaLLVM, 1, 0, "target LLVM/Offload as portable offloading runtime.") LANGOPT(SYCLIsDevice , 1, 0, "Generate code for SYCL device") LANGOPT(SYCLIsHost, 1, 0, "SYCL host compilation") diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 57f37c5023110..a09d75917ff98 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -1275,6 +1275,12 @@ def no_offload_compress : Flag<["--"], "no-offload-compress">; def offload_compression_level_EQ : Joined<["--"], "offload-compression-level=">, Flags<[HelpHidden]>, HelpText<"Compression level for offload device binaries (HIP only)">; + +defm offload_via_llvm : BoolFOption<"offload-via-llvm", + LangOpts<"OffloadViaLLVM">, DefaultFalse, + PosFlag, + NegFlag, + BothFlags<[], [ClangOption], " LLVM/Offload as portable offloading runtime.">>; } // CUDA options diff --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp index 43dfbbb90dd52..8e32aad88a26d 100644 --- a/clang/lib/CodeGen/CGCUDANV.cpp +++ b/clang/lib/CodeGen/CGCUDANV.cpp @@ -15,10 +15,12 @@ #include "CGCXXABI.h" #include "CodeGenFunction.h" #include "CodeGenModule.h" +#include "clang/AST/CharUnits.h" #include "clang/AST/Decl.h" #include "clang/Basic/Cuda.h" #include "clang/CodeGen/CodeGenABITypes.h" #include "clang/CodeGen/ConstantInitBuilder.h" +#include "llvm/ADT/StringRef.h" #include "llvm/Frontend/Offloading/Utility.h" #include "llvm/IR/BasicBlock.h" #include "llvm/IR/Constants.h" @@ -36,6 +38,11 @@ constexpr unsigned HIPFatMagic = 0x48495046; // "HIPF" class CGNVCUDARuntime : public CGCUDARuntime { + /// The prefix used for function calls and section names (CUDA, HIP, LLVM) + StringRef Prefix; + /// TODO: We should transition the OpenMP section to LLVM/Offload + StringRef SectionPrefix; + private: llvm::IntegerType *IntTy, *Siz
[clang] [llvm] [Offload][CUDA] Add initial cuda_runtime.h overlay (PR #94821)
https://github.com/jdoerfert created https://github.com/llvm/llvm-project/pull/94821 This provides the header overlay for cuda_runtime.h which is found before any CUDA installation (none is necessary). Some basic APIs are defined in terms of the omp_target_* ones, but with the pending LLVM/Offload API redesign the requirements of CUDA should be taken into account. Note: Async is not exposed by the existing runtime thus the streams are ignored. I'll address this in a follow up. >From 36618e65d94ffa3e83464b7d19ff6cd7d5855abf Mon Sep 17 00:00:00 2001 From: Johannes Doerfert Date: Wed, 5 Jun 2024 16:51:51 -0700 Subject: [PATCH 1/4] [Offload][NFCI] Initialize the KernelArgsTy to default values --- offload/include/Shared/APITypes.h | 30 +- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/offload/include/Shared/APITypes.h b/offload/include/Shared/APITypes.h index e8fc27785b6c2..fd315c6b992b9 100644 --- a/offload/include/Shared/APITypes.h +++ b/offload/include/Shared/APITypes.h @@ -89,22 +89,26 @@ struct __tgt_async_info { /// This struct contains all of the arguments to a target kernel region launch. struct KernelArgsTy { - uint32_t Version; // Version of this struct for ABI compatibility. - uint32_t NumArgs; // Number of arguments in each input pointer. - void **ArgBasePtrs; // Base pointer of each argument (e.g. a struct). - void **ArgPtrs; // Pointer to the argument data. - int64_t *ArgSizes; // Size of the argument data in bytes. - int64_t *ArgTypes; // Type of the data (e.g. to / from). - void **ArgNames;// Name of the data for debugging, possibly null. - void **ArgMappers; // User-defined mappers, possibly null. - uint64_t Tripcount; // Tripcount for the teams / distribute loop, 0 otherwise. + uint32_t Version = 0; // Version of this struct for ABI compatibility. + uint32_t NumArgs = 0; // Number of arguments in each input pointer. + void **ArgBasePtrs = + nullptr; // Base pointer of each argument (e.g. a struct). + void **ArgPtrs = nullptr;// Pointer to the argument data. + int64_t *ArgSizes = nullptr; // Size of the argument data in bytes. + int64_t *ArgTypes = nullptr; // Type of the data (e.g. to / from). + void **ArgNames = nullptr; // Name of the data for debugging, possibly null. + void **ArgMappers = nullptr; // User-defined mappers, possibly null. + uint64_t Tripcount = + 0; // Tripcount for the teams / distribute loop, 0 otherwise. struct { uint64_t NoWait : 1; // Was this kernel spawned with a `nowait` clause. uint64_t Unused : 63; - } Flags; - uint32_t NumTeams[3];// The number of teams (for x,y,z dimension). - uint32_t ThreadLimit[3]; // The number of threads (for x,y,z dimension). - uint32_t DynCGroupMem; // Amount of dynamic cgroup memory requested. + } Flags = {0, 0}; + uint32_t NumTeams[3] = {0, 0, + 0}; // The number of teams (for x,y,z dimension). + uint32_t ThreadLimit[3] = {0, 0, + 0}; // The number of threads (for x,y,z dimension). + uint32_t DynCGroupMem = 0; // Amount of dynamic cgroup memory requested. }; static_assert(sizeof(KernelArgsTy().Flags) == sizeof(uint64_t), "Invalid struct size"); >From 3d5c61a78e91ecb379a2bfac71988eaf8e5cd9cd Mon Sep 17 00:00:00 2001 From: Johannes Doerfert Date: Mon, 3 Jun 2024 19:52:12 -0700 Subject: [PATCH 2/4] [Offload][CUDA] Allow CUDA kernels to use LLVM/Offload MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Through the new `-foffload-via-llvm` flag, CUDA kernels can now be lowered to the LLVM/Offload API. On the Clang side, this is simply done by using the OpenMP offload toolchain and emitting calls to `llvm*` functions to orchestrate the kernel launch rather than `cuda*` functions. These `llvm*` functions are implemented on top of the existing LLVM/Offload API. As we are about to redefine the Offload API, this wil help us in the design process as a second offload language. We do not support any CUDA APIs yet, however, we could: https://www.osti.gov/servlets/purl/1892137 For proper host execution we need to resurrect/rebase https://tianshilei.me/wp-content/uploads/2021/12/llpp-2021.pdf (which was designed for debugging). ``` ❯❯❯ cat test.cu extern "C" { void *llvm_omp_target_alloc_shared(size_t Size, int DeviceNum); void llvm_omp_target_free_shared(void *DevicePtr, int DeviceNum); } __global__ void square(int *A) { *A = 42; } int main(int argc, char **argv) { int DevNo = 0; int *Ptr = reinterpret_cast(llvm_omp_target_alloc_shared(4, DevNo)); *Ptr = 7; printf("Ptr %p, *Ptr %i\n", Ptr, *Ptr); square<<<1, 1>>>(Ptr); printf("Ptr %p, *Ptr %i\n", Ptr, *Ptr); llvm_omp_target_free_shared(Ptr, DevNo); } ❯❯❯ clang++ test.cu -O3 -o test123 -foffload-via-llvm --offload-arch=native ❯❯❯ llvm-objdump --offloading test123 test123:file format elf64-x86-
[clang] [clang][CodeGen] Make `UnqualPtrTy` truly unqualified (PR #94388)
jrtc27 wrote: And I still strongly urge renaming what this is, given it is _not_ the type for an unqualified C `void *`, as one would normally expect given it's in Clang. https://github.com/llvm/llvm-project/pull/94388 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeGen] Make `UnqualPtrTy` truly unqualified (PR #94388)
jrtc27 wrote: There are still quite a few references to UnqualPtrTy that you're not changing yet are now wrong, no? https://github.com/llvm/llvm-project/pull/94388 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ExtractAPI][NFC] pass params by const reference (PR #94820)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Erick Velez (evelez7) Changes Change some parameters in DeclarationFragments.h to be passed by const reference. Caught by cppcheck. Fixes #92756 but doesn't address return value `RT` for `getTopLevelRecords`. I'm not sure we'd want a const return of the top records, and returning `RT` by reference makes clang complain about returning a temporary object. --- Full diff: https://github.com/llvm/llvm-project/pull/94820.diff 1 Files Affected: - (modified) clang/include/clang/ExtractAPI/DeclarationFragments.h (+5-4) ``diff diff --git a/clang/include/clang/ExtractAPI/DeclarationFragments.h b/clang/include/clang/ExtractAPI/DeclarationFragments.h index 535da90b98284..7dae4e2f8ac1d 100644 --- a/clang/include/clang/ExtractAPI/DeclarationFragments.h +++ b/clang/include/clang/ExtractAPI/DeclarationFragments.h @@ -199,7 +199,8 @@ class DeclarationFragments { return *this; } - DeclarationFragments &replace(std::string NewSpelling, unsigned Position) { + DeclarationFragments &replace(const std::string &NewSpelling, +unsigned Position) { Fragments.at(Position).Spelling = NewSpelling; return *this; } @@ -240,7 +241,7 @@ class DeclarationFragments { class AccessControl { public: - AccessControl(std::string Access) : Access(Access) {} + AccessControl(const std::string &Access) : Access(Access) {} AccessControl() : Access("public") {} const std::string &getAccess() const { return Access; } @@ -262,7 +263,7 @@ class FunctionSignature { std::string Name; DeclarationFragments Fragments; -Parameter(StringRef Name, DeclarationFragments Fragments) +Parameter(StringRef Name, const DeclarationFragments &Fragments) : Name(Name), Fragments(Fragments) {} }; @@ -275,7 +276,7 @@ class FunctionSignature { return *this; } - void setReturnType(DeclarationFragments RT) { ReturnType = RT; } + void setReturnType(const DeclarationFragments &RT) { ReturnType = RT; } /// Determine if the FunctionSignature is empty. /// `` https://github.com/llvm/llvm-project/pull/94820 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-doc] Add --asset option to clang-doc (PR #94717)
@@ -131,12 +137,55 @@ std::string GetExecutablePath(const char *Argv0, void *MainAddr) { return llvm::sys::fs::getMainExecutable(Argv0, MainAddr); } +void GetAssetFiles(clang::doc::ClangDocContext &CDCtx) { + std::error_code Code; + for (auto DirIt = llvm::sys::fs::directory_iterator( +std::string(UserAssetPath), Code), +dir_end = llvm::sys::fs::directory_iterator(); ilovepi wrote: I'm not sure this is resolved. I was expecting to see an initialization pattern, similar to the code example I linked, which is much more typical in our codebase. We also have a somewhat mixed policy on the use of `auto` (https://www.llvm.org/docs/CodingStandards.html#use-auto-type-deduction-to-make-code-more-readable). Typically, is more readable to use it in a for loop, or for initializing an iterator, but I'm always hesitant when `auto` is used for multiple initializations. ```c++ for (llvm::sys::fs::directory_iterator DirIt = llvm::sys::fs::directory_iterator( UserAssetPath, Code), DirEnd; ... ``` A using statement may also make this easier to read. https://github.com/llvm/llvm-project/pull/94717 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ExtractAPI][NFC] pass params by const reference (PR #94820)
https://github.com/evelez7 created https://github.com/llvm/llvm-project/pull/94820 Change some parameters in DeclarationFragments.h to be passed by const reference. Caught by cppcheck. Fixes #92756 but doesn't address return value `RT` for `getTopLevelRecords`. I'm not sure we'd want a const return of the top records, and returning `RT` by reference makes clang complain about returning a temporary object. >From 98840a10f31705ab684375bf77dcab46ba9009ee Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Fri, 7 Jun 2024 16:23:09 -0700 Subject: [PATCH] [clang][ExtractAPI][NFC] pass params by const reference --- clang/include/clang/ExtractAPI/DeclarationFragments.h | 9 + 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/ExtractAPI/DeclarationFragments.h b/clang/include/clang/ExtractAPI/DeclarationFragments.h index 535da90b98284..7dae4e2f8ac1d 100644 --- a/clang/include/clang/ExtractAPI/DeclarationFragments.h +++ b/clang/include/clang/ExtractAPI/DeclarationFragments.h @@ -199,7 +199,8 @@ class DeclarationFragments { return *this; } - DeclarationFragments &replace(std::string NewSpelling, unsigned Position) { + DeclarationFragments &replace(const std::string &NewSpelling, +unsigned Position) { Fragments.at(Position).Spelling = NewSpelling; return *this; } @@ -240,7 +241,7 @@ class DeclarationFragments { class AccessControl { public: - AccessControl(std::string Access) : Access(Access) {} + AccessControl(const std::string &Access) : Access(Access) {} AccessControl() : Access("public") {} const std::string &getAccess() const { return Access; } @@ -262,7 +263,7 @@ class FunctionSignature { std::string Name; DeclarationFragments Fragments; -Parameter(StringRef Name, DeclarationFragments Fragments) +Parameter(StringRef Name, const DeclarationFragments &Fragments) : Name(Name), Fragments(Fragments) {} }; @@ -275,7 +276,7 @@ class FunctionSignature { return *this; } - void setReturnType(DeclarationFragments RT) { ReturnType = RT; } + void setReturnType(const DeclarationFragments &RT) { ReturnType = RT; } /// Determine if the FunctionSignature is empty. /// ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeGen] Make `UnqualPtrTy` truly unqualified (PR #94388)
https://github.com/arichardson approved this pull request. This looks fine to me now, but I'd suggest a TODO comment that UnqualPtrTy should be removed in the future. https://github.com/llvm/llvm-project/pull/94388 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-doc] Add --asset option to clang-doc (PR #94717)
@@ -131,12 +137,55 @@ std::string GetExecutablePath(const char *Argv0, void *MainAddr) { return llvm::sys::fs::getMainExecutable(Argv0, MainAddr); } +void GetAssetFiles(clang::doc::ClangDocContext &CDCtx) { + std::error_code Code; + for (auto DirIt = llvm::sys::fs::directory_iterator( +std::string(UserAssetPath), Code), +dir_end = llvm::sys::fs::directory_iterator(); + !Code && DirIt != dir_end; DirIt.increment(Code)) { +llvm::SmallString<128> filePath = llvm::SmallString<128>(DirIt->path()); +if (llvm::sys::fs::is_regular_file(filePath)) { + if (filePath.ends_with(".css")) { +CDCtx.UserStylesheets.insert(CDCtx.UserStylesheets.begin(), + std::string(filePath)); + } else if (filePath.ends_with(".js")) { +CDCtx.FilesToCopy.emplace_back(filePath.str()); + } +} + } +} + +void GetDefaultAssetFiles(const char *Argv0, + clang::doc::ClangDocContext &CDCtx) { + void *MainAddr = (void *)(intptr_t)GetExecutablePath; + std::string ClangDocPath = GetExecutablePath(Argv0, MainAddr); + llvm::SmallString<128> NativeClangDocPath; + llvm::sys::path::native(ClangDocPath, NativeClangDocPath); + + llvm::SmallString<128> AssetsPath; + AssetsPath = llvm::sys::path::parent_path(NativeClangDocPath); + llvm::sys::path::append(AssetsPath, "..", "share", "clang"); + llvm::SmallString<128> DefaultStylesheet; + llvm::sys::path::native(AssetsPath, DefaultStylesheet); + llvm::sys::path::append(DefaultStylesheet, + "clang-doc-default-stylesheet.css"); + llvm::SmallString<128> IndexJS; + llvm::sys::path::native(AssetsPath, IndexJS); + llvm::sys::path::append(IndexJS, "index.js"); ilovepi wrote: so we did need to check, and you've added one now https://github.com/llvm/llvm-project/pull/94717 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)
@@ -1117,6 +1118,31 @@ NumericLiteralParser::NumericLiteralParser(StringRef TokSpelling, if (isImaginary) break; // Cannot be repeated. isImaginary = true; continue; // Success. +case '_': + if (isFPConstant) +break; // Invalid for floats + if (HasSize) +break; + if (DoubleUnderscore) +break; // Cannot be repeated. Sirraide wrote: > I'd definitely prefer not to have this be forgotten if we add a second double > underscore literal suffix And yeah, agreed. https://github.com/llvm/llvm-project/pull/86586 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)
@@ -1117,6 +1118,31 @@ NumericLiteralParser::NumericLiteralParser(StringRef TokSpelling, if (isImaginary) break; // Cannot be repeated. isImaginary = true; continue; // Success. +case '_': + if (isFPConstant) +break; // Invalid for floats + if (HasSize) +break; + if (DoubleUnderscore) +break; // Cannot be repeated. Sirraide wrote: An assertion would also make sense yeah. > whoever wants to do the work (For the record, I’m busy refactoring AST visitors so not me) https://github.com/llvm/llvm-project/pull/86586 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)
@@ -1117,6 +1118,31 @@ NumericLiteralParser::NumericLiteralParser(StringRef TokSpelling, if (isImaginary) break; // Cannot be repeated. isImaginary = true; continue; // Success. +case '_': + if (isFPConstant) +break; // Invalid for floats + if (HasSize) +break; + if (DoubleUnderscore) +break; // Cannot be repeated. erichkeane wrote: Hmm.. I'd definitely prefer not to have this be forgotten if we add a second double underscore literal suffix, but presumably there is something we could do to make it not active code. Perhaps we could replace it with a `assert(!DoubleUnderscore && "Doubleunderscore should be handled like above if we ever get a suffix that could hit this")` WDYT? I don't have the ability to do so, but just a suggestion and a 'patches welcome' to whoever wants to do the work (@js234 @mikerice1969 @Sirraide ). https://github.com/llvm/llvm-project/pull/86586 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] In C++17, callee is guaranteed to be sequenced before arguments. (PR #93623)
@@ -175,6 +218,10 @@ bool UseAfterMoveFinder::findInternal(const CFGBlock *Block, MovingCall != nullptr && Sequence->potentiallyAfter(MovingCall, Use); +// We default to false here and change this to true if required in +// find(). +TheUseAfterMove->UseHappensInLaterLoopIteration = false; + 5chmidti wrote: The initialization could also happen in the struct itself (we should initialize `EvaluationOrderUndefined` in the struct as well). https://github.com/llvm/llvm-project/pull/93623 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] In C++17, callee is guaranteed to be sequenced before arguments. (PR #93623)
@@ -55,12 +55,23 @@ bool isDescendantOrEqual(const Stmt *Descendant, const Stmt *Ancestor, ASTContext *Context) { if (Descendant == Ancestor) return true; - for (const Stmt *Parent : getParentStmts(Descendant, Context)) { -if (isDescendantOrEqual(Parent, Ancestor, Context)) - return true; - } + return llvm::any_of(getParentStmts(Descendant, Context), + [Ancestor, Context](const Stmt *Parent) { +return isDescendantOrEqual(Parent, Ancestor, Context); + }); +} - return false; +bool isDescendantOfArgs(const Stmt *Descendant, const CallExpr *Call, +ASTContext *Context) { + return llvm::any_of(Call->arguments(), + [Descendant, Context](const Expr *Arg) { +return isDescendantOrEqual(Descendant, Arg, Context); + }); +} + +bool argsContain(const CallExpr *Call, const Stmt *TheStmt) { + return std::find(Call->arguments().begin(), Call->arguments().end(), + TheStmt) != Call->arguments().end(); 5chmidti wrote: Please use `llvm::is_contained` https://github.com/llvm/llvm-project/pull/93623 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] In C++17, callee is guaranteed to be sequenced before arguments. (PR #93623)
@@ -95,9 +106,59 @@ bool ExprSequence::inSequence(const Stmt *Before, const Stmt *After) const { return true; } + SmallVector BeforeParents = getParentStmts(Before, Context); + + // Since C++17, the callee of a call expression is guaranteed to be sequenced + // before all of the arguments. + // We handle this as a special case rather than using the general + // `getSequenceSuccessor` logic above because the callee expression doesn't + // have an unambiguous successor; the order in which arguments are evaluated + // is indeterminate. + for (const Stmt *Parent : BeforeParents) { +// Special case: If the callee is a `MemberExpr` with a `DeclRefExpr` as its +// base, we consider it to be sequenced _after_ the arguments. This is +// because the variable referenced in the base will only actually be +// accessed when the call happens, i.e. once all of the arguments have been +// evaluated. This has no basis in the C++ standard, but it reflects actual +// behavior that is relevant to a use-after-move scenario: +// +// ``` +// a.bar(consumeA(std::move(a)); +// ``` +// +// In this example, we end up accessing `a` after it has been moved from, +// even though nominally the callee `a.bar` is evaluated before the argument +// `consumeA(std::move(a))`. Note that this is not specific to C++17, so +// we implement this logic unconditionally. +if (const auto *call = dyn_cast(Parent)) { 5chmidti wrote: `call` -> `Call` https://github.com/llvm/llvm-project/pull/93623 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] In C++17, callee is guaranteed to be sequenced before arguments. (PR #93623)
@@ -95,9 +106,59 @@ bool ExprSequence::inSequence(const Stmt *Before, const Stmt *After) const { return true; } + SmallVector BeforeParents = getParentStmts(Before, Context); + + // Since C++17, the callee of a call expression is guaranteed to be sequenced + // before all of the arguments. + // We handle this as a special case rather than using the general + // `getSequenceSuccessor` logic above because the callee expression doesn't + // have an unambiguous successor; the order in which arguments are evaluated + // is indeterminate. + for (const Stmt *Parent : BeforeParents) { +// Special case: If the callee is a `MemberExpr` with a `DeclRefExpr` as its +// base, we consider it to be sequenced _after_ the arguments. This is +// because the variable referenced in the base will only actually be +// accessed when the call happens, i.e. once all of the arguments have been +// evaluated. This has no basis in the C++ standard, but it reflects actual +// behavior that is relevant to a use-after-move scenario: +// +// ``` +// a.bar(consumeA(std::move(a)); +// ``` +// +// In this example, we end up accessing `a` after it has been moved from, +// even though nominally the callee `a.bar` is evaluated before the argument +// `consumeA(std::move(a))`. Note that this is not specific to C++17, so +// we implement this logic unconditionally. +if (const auto *call = dyn_cast(Parent)) { + if (argsContain(call, Before) && + isa( + call->getImplicitObjectArgument()->IgnoreParenImpCasts()) && + isDescendantOrEqual(After, call->getImplicitObjectArgument(), + Context)) +return true; + + // We need this additional early exit so that we don't fall through to the + // more general logic below. + if (const auto *Member = dyn_cast(Before); + Member && call->getCallee() == Member && + isa(Member->getBase()->IgnoreParenImpCasts()) && + isDescendantOfArgs(After, call, Context)) +return false; +} + +if (!Context->getLangOpts().CPlusPlus17) + continue; + +if (const auto *call = dyn_cast(Parent); +call && call->getCallee() == Before && +isDescendantOfArgs(After, call, Context)) + return true; + } 5chmidti wrote: `call` -> `Call` https://github.com/llvm/llvm-project/pull/93623 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] In C++17, callee is guaranteed to be sequenced before arguments. (PR #93623)
@@ -69,6 +73,30 @@ class UseAfterMoveFinder { llvm::SmallPtrSet Visited; }; +/// Returns whether the `Before` block can reach the `After` block. +bool reaches(const CFGBlock *Before, const CFGBlock *After) { + llvm::SmallVector Stack; + llvm::SmallPtrSet Visited; + + Stack.push_back(Before); + while (!Stack.empty()) { +const CFGBlock *Current = Stack.back(); +Stack.pop_back(); + +if (Current == After) + return true; + +Visited.insert(Current); + +for (const CFGBlock *Succ : Current->succs()) { + if (Succ && !Visited.contains(Succ)) +Stack.push_back(Succ); +} + } + + return false; +} + 5chmidti wrote: What do you think about using https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Analysis/Analyses/CFGReachabilityAnalysis.h? We are rebuilding the CFG a lot of times and don't cache anything, so the caching in `CFGReverseBlockReachabilityAnalysis` won't have any worth until we do, but it is an existing implementation of what you are doing here, so we should at least consider it. https://github.com/llvm/llvm-project/pull/93623 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)
@@ -1117,6 +1118,31 @@ NumericLiteralParser::NumericLiteralParser(StringRef TokSpelling, if (isImaginary) break; // Cannot be repeated. isImaginary = true; continue; // Success. +case '_': + if (isFPConstant) +break; // Invalid for floats + if (HasSize) +break; + if (DoubleUnderscore) +break; // Cannot be repeated. Sirraide wrote: This is presumably because there currently is only one suffix that uses the `DoubleUnderscore` flag, so the other flags that also get set when `__wb` is parsed (e.g. `HasSize`) would be enough to disallow repetition here, from what I can tell. I’d still keep `DoubleUnderscore` in case we decide to add more literal suffixes that contain double underscores. https://github.com/llvm/llvm-project/pull/86586 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang] Reland Add tanf16 builtin and support for tan constrained intrinsic (PR #94559)
https://github.com/farzonl updated https://github.com/llvm/llvm-project/pull/94559 >From 51247e430ad49c4729e2e3664104367b13fbad9e Mon Sep 17 00:00:00 2001 From: Farzon Lotfi Date: Fri, 24 May 2024 10:01:52 -0400 Subject: [PATCH 1/2] [clang] Add tanf16 builtin and support for tan constrained intrinsic --- clang/include/clang/Basic/Builtins.td | 6 ++-- clang/lib/CodeGen/CGBuiltin.cpp | 12 +++ clang/test/CodeGen/X86/math-builtins.c| 8 ++--- .../test/CodeGen/constrained-math-builtins.c | 13 +++ clang/test/CodeGen/math-libcalls.c| 12 +++ clang/test/CodeGenOpenCL/builtins-f16.cl | 3 ++ llvm/docs/LangRef.rst | 36 +++ llvm/include/llvm/IR/ConstrainedOps.def | 1 + llvm/include/llvm/IR/Intrinsics.td| 4 +++ llvm/test/Assembler/fp-intrinsics-attr.ll | 8 + llvm/test/Feature/fp-intrinsics.ll| 11 ++ 11 files changed, 101 insertions(+), 13 deletions(-) diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td index 11982af3fa609..7bef5fd7ad40f 100644 --- a/clang/include/clang/Basic/Builtins.td +++ b/clang/include/clang/Basic/Builtins.td @@ -482,11 +482,11 @@ def SqrtF16F128 : Builtin, F16F128MathTemplate { let Prototype = "T(T)"; } -def TanF128 : Builtin { - let Spellings = ["__builtin_tanf128"]; +def TanF16F128 : Builtin, F16F128MathTemplate { + let Spellings = ["__builtin_tan"]; let Attributes = [FunctionWithBuiltinPrefix, NoThrow, ConstIgnoringErrnoAndExceptions]; - let Prototype = "__float128(__float128)"; + let Prototype = "T(T)"; } def TanhF128 : Builtin { diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index c16b69ba87567..06e201fa71e6f 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -2923,6 +2923,18 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, SetSqrtFPAccuracy(Call); return RValue::get(Call); } + +case Builtin::BItan: +case Builtin::BItanf: +case Builtin::BItanl: +case Builtin::BI__builtin_tan: +case Builtin::BI__builtin_tanf: +case Builtin::BI__builtin_tanf16: +case Builtin::BI__builtin_tanl: +case Builtin::BI__builtin_tanf128: + return RValue::get(emitUnaryMaybeConstrainedFPBuiltin( + *this, E, Intrinsic::tan, Intrinsic::experimental_constrained_tan)); + case Builtin::BItrunc: case Builtin::BItruncf: case Builtin::BItruncl: diff --git a/clang/test/CodeGen/X86/math-builtins.c b/clang/test/CodeGen/X86/math-builtins.c index 093239b448260..1e0f129b98610 100644 --- a/clang/test/CodeGen/X86/math-builtins.c +++ b/clang/test/CodeGen/X86/math-builtins.c @@ -674,10 +674,10 @@ __builtin_sqrt(f); __builtin_sqrtf(f); __builtin_sqrtl(f); __builtin_ __builtin_tan(f);__builtin_tanf(f); __builtin_tanl(f); __builtin_tanf128(f); -// NO__ERRNO: declare double @tan(double noundef) [[READNONE]] -// NO__ERRNO: declare float @tanf(float noundef) [[READNONE]] -// NO__ERRNO: declare x86_fp80 @tanl(x86_fp80 noundef) [[READNONE]] -// NO__ERRNO: declare fp128 @tanf128(fp128 noundef) [[READNONE]] +// NO__ERRNO: declare double @llvm.tan.f64(double) [[READNONE_INTRINSIC]] +// NO__ERRNO: declare float @llvm.tan.f32(float) [[READNONE_INTRINSIC]] +// NO__ERRNO: declare x86_fp80 @llvm.tan.f80(x86_fp80) [[READNONE_INTRINSIC]] +// NO__ERRNO: declare fp128 @llvm.tan.f128(fp128) [[READNONE_INTRINSIC]] // HAS_ERRNO: declare double @tan(double noundef) [[NOT_READNONE]] // HAS_ERRNO: declare float @tanf(float noundef) [[NOT_READNONE]] // HAS_ERRNO: declare x86_fp80 @tanl(x86_fp80 noundef) [[NOT_READNONE]] diff --git a/clang/test/CodeGen/constrained-math-builtins.c b/clang/test/CodeGen/constrained-math-builtins.c index 2de832dd2b6ca..6cc3a10a1e794 100644 --- a/clang/test/CodeGen/constrained-math-builtins.c +++ b/clang/test/CodeGen/constrained-math-builtins.c @@ -183,6 +183,14 @@ void foo(double *d, float f, float *fp, long double *l, int *i, const char *c, _ // CHECK: call x86_fp80 @llvm.experimental.constrained.sqrt.f80(x86_fp80 %{{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict") // CHECK: call fp128 @llvm.experimental.constrained.sqrt.f128(fp128 %{{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict") + __builtin_tan(f);__builtin_tanf(f); __builtin_tanl(f); __builtin_tanf128(f); + +// CHECK: call double @llvm.experimental.constrained.tan.f64(double %{{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict") +// CHECK: call float @llvm.experimental.constrained.tan.f32(float %{{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict") +// CHECK: call x86_fp80 @llvm.experimental.constrained.tan.f80(x86_fp80 %{{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict") +// CHECK: call fp128 @llvm.experimental.constrained.tan.f128(fp
[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)
@@ -1117,6 +1118,31 @@ NumericLiteralParser::NumericLiteralParser(StringRef TokSpelling, if (isImaginary) break; // Cannot be repeated. isImaginary = true; continue; // Success. +case '_': + if (isFPConstant) +break; // Invalid for floats + if (HasSize) +break; + if (DoubleUnderscore) +break; // Cannot be repeated. mikerice1969 wrote: Hi @js324. our static verifier is reporting this 'break' as dead code saying that it will always be false. I removed all references to DoubleUnderscore and ran the lit tests and there are no fails. Do you have a test case in mind that exercises this condition? If so we should add a test for it. If not we can simplify this code and remove DoubleUnderscore. What do you think? https://github.com/llvm/llvm-project/pull/86586 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Change default linkage of HLSL functions and `groupshared` variables (PR #93336)
@@ -108,3 +108,16 @@ behavior between Clang and DXC. Some examples include: diagnostic notifying the user of the conversion rather than silently altering precision relative to the other overloads (as FXC does) or generating code that will fail validation (as DXC does). + +Correctness improvements (bug fixes) + + +Entry point functions & ``static`` keyword +-- +Marking a shader entry point function ``static`` will result in an error. + +This is idential to DXC behavior when an entry point is specified as compiler bharadwajy wrote: ```suggestion This is identical to DXC behavior when an entry point is specified as compiler ``` https://github.com/llvm/llvm-project/pull/93336 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Clang] Introduce [[clang::coro_structured_concurrency]] (PR #94693)
https://github.com/yuxuanchen1997 edited https://github.com/llvm/llvm-project/pull/94693 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] new check misc-use-internal-linkage (PR #90830)
https://github.com/HerrCai0907 closed https://github.com/llvm/llvm-project/pull/90830 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] c4f83a0 - [clang-tidy] new check misc-use-internal-linkage (#90830)
Author: Congcong Cai Date: 2024-06-08T06:46:39+08:00 New Revision: c4f83a004bf35bfc46fe89111fdca750bbc724da URL: https://github.com/llvm/llvm-project/commit/c4f83a004bf35bfc46fe89111fdca750bbc724da DIFF: https://github.com/llvm/llvm-project/commit/c4f83a004bf35bfc46fe89111fdca750bbc724da.diff LOG: [clang-tidy] new check misc-use-internal-linkage (#90830) Add new check misc-use-internal-linkage to detect variable and function can be marked as static. - Co-authored-by: Danny Mösch Added: clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.h clang-tools-extra/docs/clang-tidy/checks/misc/use-internal-linkage.rst clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/use-internal-linkage/func.h clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/use-internal-linkage/func_cpp.inc clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/use-internal-linkage/func_h.inc clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/use-internal-linkage/var.h clang-tools-extra/test/clang-tidy/checkers/misc/use-internal-linkage-func.cpp clang-tools-extra/test/clang-tidy/checkers/misc/use-internal-linkage-var.cpp Modified: clang-tools-extra/clang-tidy/misc/CMakeLists.txt clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp clang-tools-extra/docs/ReleaseNotes.rst clang-tools-extra/docs/clang-tidy/checks/list.rst Removed: diff --git a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt index 36fcd8fc1b277..1c1d3b836ea1b 100644 --- a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt @@ -41,6 +41,7 @@ add_clang_library(clangTidyMiscModule UnusedParametersCheck.cpp UnusedUsingDeclsCheck.cpp UseAnonymousNamespaceCheck.cpp + UseInternalLinkageCheck.cpp LINK_LIBS clangTidy diff --git a/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp b/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp index d8a88324ee63e..54bcebca7e186 100644 --- a/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp @@ -31,6 +31,7 @@ #include "UnusedParametersCheck.h" #include "UnusedUsingDeclsCheck.h" #include "UseAnonymousNamespaceCheck.h" +#include "UseInternalLinkageCheck.h" namespace clang::tidy { namespace misc { @@ -78,6 +79,8 @@ class MiscModule : public ClangTidyModule { "misc-unused-using-decls"); CheckFactories.registerCheck( "misc-use-anonymous-namespace"); +CheckFactories.registerCheck( +"misc-use-internal-linkage"); } }; diff --git a/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp b/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp new file mode 100644 index 0..70d0281df28fa --- /dev/null +++ b/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp @@ -0,0 +1,95 @@ +//===--- UseInternalLinkageCheck.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 "UseInternalLinkageCheck.h" +#include "../utils/FileExtensionsUtils.h" +#include "clang/AST/Decl.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/ASTMatchers/ASTMatchers.h" +#include "clang/ASTMatchers/ASTMatchersMacros.h" +#include "clang/Basic/SourceLocation.h" +#include "clang/Basic/Specifiers.h" +#include "llvm/ADT/STLExtras.h" + +using namespace clang::ast_matchers; + +namespace clang::tidy::misc { + +namespace { + +AST_MATCHER(Decl, isFirstDecl) { return Node.isFirstDecl(); } + +static bool isInMainFile(SourceLocation L, SourceManager &SM, + const FileExtensionsSet &HeaderFileExtensions) { + for (;;) { +if (utils::isSpellingLocInHeaderFile(L, SM, HeaderFileExtensions)) + return false; +if (SM.isInMainFile(L)) + return true; +// not in header file but not in main file +L = SM.getIncludeLoc(SM.getFileID(L)); +if (L.isValid()) + continue; +// Conservative about the unknown +return false; + } +} + +AST_MATCHER_P(Decl, isAllRedeclsInMainFile, FileExtensionsSet, + HeaderFileExtensions) { + return llvm::all_of(Node.redecls(), [&](const Decl *D) { +return isInMainFile(D->getLocation(), +Finder->getASTContext().getSourceManager(), +HeaderFileExtensions); + }); +} + +AST_POLYMORPHIC_MATCHER(isExternStorageClass, +AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl, +VarDecl))
[clang] [HLSL] Use llvm::Triple::EnvironmentType instead of HLSLShaderAttr::ShaderType (PR #93847)
https://github.com/hekota updated https://github.com/llvm/llvm-project/pull/93847 >From dd175a247480396b9d35cb995333fcd14152e347 Mon Sep 17 00:00:00 2001 From: Helena Kotas Date: Wed, 29 May 2024 18:38:45 -0700 Subject: [PATCH 1/4] [HLSL] Use llvm::Triple::EnvironmentType instead of ShaderType HLSLShaderAttr::ShaderType enum is a subset of llvm::Triple::EnvironmentType and is not needed. --- clang/include/clang/Basic/Attr.td | 29 +++- clang/include/clang/Sema/SemaHLSL.h | 6 +- clang/lib/CodeGen/CGHLSLRuntime.cpp | 2 +- clang/lib/Sema/SemaDeclAttr.cpp | 4 +- clang/lib/Sema/SemaHLSL.cpp | 105 +++- 5 files changed, 72 insertions(+), 74 deletions(-) diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 2665b7353ca4a..e373c073ec906 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -4469,36 +4469,23 @@ def HLSLShader : InheritableAttr { let Subjects = SubjectList<[HLSLEntry]>; let LangOpts = [HLSL]; let Args = [ -EnumArgument<"Type", "ShaderType", /*is_string=*/true, +EnumArgument<"Type", "llvm::Triple::EnvironmentType", /*is_string=*/true, ["pixel", "vertex", "geometry", "hull", "domain", "compute", "raygeneration", "intersection", "anyhit", "closesthit", "miss", "callable", "mesh", "amplification"], ["Pixel", "Vertex", "Geometry", "Hull", "Domain", "Compute", "RayGeneration", "Intersection", "AnyHit", "ClosestHit", - "Miss", "Callable", "Mesh", "Amplification"]> + "Miss", "Callable", "Mesh", "Amplification"], + /*opt=*/0, /*fake=*/0, /*isExternalType=*/1> ]; let Documentation = [HLSLSV_ShaderTypeAttrDocs]; let AdditionalMembers = [{ - static const unsigned ShaderTypeMaxValue = (unsigned)HLSLShaderAttr::Amplification; - - static llvm::Triple::EnvironmentType getTypeAsEnvironment(HLSLShaderAttr::ShaderType ShaderType) { -switch (ShaderType) { - case HLSLShaderAttr::Pixel: return llvm::Triple::Pixel; - case HLSLShaderAttr::Vertex:return llvm::Triple::Vertex; - case HLSLShaderAttr::Geometry: return llvm::Triple::Geometry; - case HLSLShaderAttr::Hull: return llvm::Triple::Hull; - case HLSLShaderAttr::Domain:return llvm::Triple::Domain; - case HLSLShaderAttr::Compute: return llvm::Triple::Compute; - case HLSLShaderAttr::RayGeneration: return llvm::Triple::RayGeneration; - case HLSLShaderAttr::Intersection: return llvm::Triple::Intersection; - case HLSLShaderAttr::AnyHit:return llvm::Triple::AnyHit; - case HLSLShaderAttr::ClosestHit:return llvm::Triple::ClosestHit; - case HLSLShaderAttr::Miss: return llvm::Triple::Miss; - case HLSLShaderAttr::Callable: return llvm::Triple::Callable; - case HLSLShaderAttr::Mesh: return llvm::Triple::Mesh; - case HLSLShaderAttr::Amplification: return llvm::Triple::Amplification; -} + static const llvm::Triple::EnvironmentType MinShaderTypeValue = llvm::Triple::Pixel; + static const llvm::Triple::EnvironmentType MaxShaderTypeValue = llvm::Triple::Amplification; + + static bool isValidShaderType(llvm::Triple::EnvironmentType ShaderType) { +return ShaderType >= MinShaderTypeValue && ShaderType <= MaxShaderTypeValue; } }]; } diff --git a/clang/include/clang/Sema/SemaHLSL.h b/clang/include/clang/Sema/SemaHLSL.h index eac1f7c07c85d..00df6c2bd15e4 100644 --- a/clang/include/clang/Sema/SemaHLSL.h +++ b/clang/include/clang/Sema/SemaHLSL.h @@ -38,7 +38,7 @@ class SemaHLSL : public SemaBase { const AttributeCommonInfo &AL, int X, int Y, int Z); HLSLShaderAttr *mergeShaderAttr(Decl *D, const AttributeCommonInfo &AL, - HLSLShaderAttr::ShaderType ShaderType); + llvm::Triple::EnvironmentType ShaderType); HLSLParamModifierAttr * mergeParamModifierAttr(Decl *D, const AttributeCommonInfo &AL, HLSLParamModifierAttr::Spelling Spelling); @@ -47,8 +47,8 @@ class SemaHLSL : public SemaBase { void CheckSemanticAnnotation(FunctionDecl *EntryPoint, const Decl *Param, const HLSLAnnotationAttr *AnnotationAttr); void DiagnoseAttrStageMismatch( - const Attr *A, HLSLShaderAttr::ShaderType Stage, - std::initializer_list AllowedStages); + const Attr *A, llvm::Triple::EnvironmentType Stage, + std::initializer_list AllowedStages); void DiagnoseAvailabilityViolations(TranslationUnitDecl *TU); }; diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp index 5e6a3dd4878f4..55ba21ae2ba69 100644 --- a/clang/lib/CodeGen/CGHLSLRuntime.cpp +++ b/clang/lib/CodeGen/CGHLSLRu
[clang] [HLSL] Change default linkage of HLSL functions and `groupshared` variables (PR #93336)
llvmbot wrote: @llvm/pr-subscribers-hlsl Author: Helena Kotas (hekota) Changes In DXC the default linkage of HLSL function is `internal` unless it is: 1. shader entry point function 2. marked with the `export` keyword (#92812) 3. does not have a definition This PR implements DXC behavior about function linkage in Clang. Note that because of the rule no.3 above, the linkage of functions cannot be determined until the whole translation unit is parsed. That is because during Clang Sema analysis the linkage of declarations is cached and cannot be changed during parsing based on whether a function definition is found or not. Therefore, all global HLSL functions have external linkage while in Clang Sema, and the final linkage is updated to `internal` based on the rules above during CodeGen. This PR also changes the linkage of `groupshared` variables `internal` to match DXC behavior. Global variables marked `static` already have `internal` linkage per C++ rules. Related spec update: microsoft/hlsl-specs#249 Fixes #92071 --- Patch is 140.62 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/93336.diff 41 Files Affected: - (modified) clang/docs/HLSL/ExpectedDifferences.rst (+13) - (modified) clang/lib/AST/Decl.cpp (+6) - (modified) clang/lib/CodeGen/CGHLSLRuntime.cpp (+15) - (modified) clang/lib/CodeGen/CGHLSLRuntime.h (+3-4) - (modified) clang/lib/CodeGen/CodeGenFunction.cpp (+4-3) - (modified) clang/test/CodeGenHLSL/ArrayTemporary.hlsl (+6-6) - (modified) clang/test/CodeGenHLSL/builtins/abs.hlsl (+28-28) - (modified) clang/test/CodeGenHLSL/builtins/all.hlsl (+80-80) - (modified) clang/test/CodeGenHLSL/builtins/any.hlsl (+80-80) - (modified) clang/test/CodeGenHLSL/builtins/ceil.hlsl (+12-12) - (modified) clang/test/CodeGenHLSL/builtins/clamp.hlsl (+40-40) - (modified) clang/test/CodeGenHLSL/builtins/cos.hlsl (+12-12) - (modified) clang/test/CodeGenHLSL/builtins/exp.hlsl (+12-12) - (modified) clang/test/CodeGenHLSL/builtins/exp2.hlsl (+12-12) - (modified) clang/test/CodeGenHLSL/builtins/floor.hlsl (+12-12) - (modified) clang/test/CodeGenHLSL/builtins/frac.hlsl (+12-12) - (modified) clang/test/CodeGenHLSL/builtins/isinf.hlsl (+8-8) - (modified) clang/test/CodeGenHLSL/builtins/log.hlsl (+12-12) - (modified) clang/test/CodeGenHLSL/builtins/log10.hlsl (+12-12) - (modified) clang/test/CodeGenHLSL/builtins/log2.hlsl (+12-12) - (modified) clang/test/CodeGenHLSL/builtins/max.hlsl (+40-40) - (modified) clang/test/CodeGenHLSL/builtins/min.hlsl (+40-40) - (modified) clang/test/CodeGenHLSL/builtins/pow.hlsl (+12-12) - (modified) clang/test/CodeGenHLSL/builtins/rcp.hlsl (+32-32) - (modified) clang/test/CodeGenHLSL/builtins/reversebits.hlsl (+12-12) - (modified) clang/test/CodeGenHLSL/builtins/round.hlsl (+12-12) - (modified) clang/test/CodeGenHLSL/builtins/rsqrt.hlsl (+12-12) - (modified) clang/test/CodeGenHLSL/builtins/sin.hlsl (+12-12) - (modified) clang/test/CodeGenHLSL/builtins/sqrt.hlsl (+12-12) - (modified) clang/test/CodeGenHLSL/builtins/trunc.hlsl (+12-12) - (modified) clang/test/CodeGenHLSL/builtins/wave_get_lane_index_do_while.hlsl (+1-1) - (modified) clang/test/CodeGenHLSL/builtins/wave_get_lane_index_simple.hlsl (+1-1) - (modified) clang/test/CodeGenHLSL/builtins/wave_get_lane_index_subcall.hlsl (+2-2) - (modified) clang/test/CodeGenHLSL/convergence/do.while.hlsl (+5-5) - (modified) clang/test/CodeGenHLSL/convergence/for.hlsl (+7-7) - (modified) clang/test/CodeGenHLSL/convergence/while.hlsl (+6-6) - (modified) clang/test/CodeGenHLSL/no_int_promotion.hlsl (+7-7) - (modified) clang/test/CodeGenHLSL/shift-mask.hlsl (+4-4) - (modified) clang/test/CodeGenHLSL/this-assignment-overload.hlsl (+2-2) - (modified) clang/test/CodeGenHLSL/this-assignment.hlsl (+2-2) - (modified) clang/test/Options/enable_16bit_types_validation_spirv.hlsl (+1-1) ``diff diff --git a/clang/docs/HLSL/ExpectedDifferences.rst b/clang/docs/HLSL/ExpectedDifferences.rst index d1b6010f10f43..e0de62345bd8c 100644 --- a/clang/docs/HLSL/ExpectedDifferences.rst +++ b/clang/docs/HLSL/ExpectedDifferences.rst @@ -108,3 +108,16 @@ behavior between Clang and DXC. Some examples include: diagnostic notifying the user of the conversion rather than silently altering precision relative to the other overloads (as FXC does) or generating code that will fail validation (as DXC does). + +Correctness improvements (bug fixes) + + +Entry point functions & ``static`` keyword +-- +Marking a shader entry point function ``static`` will result in an error. + +This is idential to DXC behavior when an entry point is specified as compiler +argument. However, DXC does not report an error when compiling a shader library +that has an entry point function with ``[shader("stage")]`` attribute that is +also marked ``static``. Additionally, this function definition is not i
[clang] [HLSL] Change default linkage of HLSL functions and `groupshared` variables (PR #93336)
llvmbot wrote: @llvm/pr-subscribers-clang-codegen Author: Helena Kotas (hekota) Changes In DXC the default linkage of HLSL function is `internal` unless it is: 1. shader entry point function 2. marked with the `export` keyword (#92812) 3. does not have a definition This PR implements DXC behavior about function linkage in Clang. Note that because of the rule no.3 above, the linkage of functions cannot be determined until the whole translation unit is parsed. That is because during Clang Sema analysis the linkage of declarations is cached and cannot be changed during parsing based on whether a function definition is found or not. Therefore, all global HLSL functions have external linkage while in Clang Sema, and the final linkage is updated to `internal` based on the rules above during CodeGen. This PR also changes the linkage of `groupshared` variables `internal` to match DXC behavior. Global variables marked `static` already have `internal` linkage per C++ rules. Related spec update: microsoft/hlsl-specs#249 Fixes #92071 --- Patch is 140.62 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/93336.diff 41 Files Affected: - (modified) clang/docs/HLSL/ExpectedDifferences.rst (+13) - (modified) clang/lib/AST/Decl.cpp (+6) - (modified) clang/lib/CodeGen/CGHLSLRuntime.cpp (+15) - (modified) clang/lib/CodeGen/CGHLSLRuntime.h (+3-4) - (modified) clang/lib/CodeGen/CodeGenFunction.cpp (+4-3) - (modified) clang/test/CodeGenHLSL/ArrayTemporary.hlsl (+6-6) - (modified) clang/test/CodeGenHLSL/builtins/abs.hlsl (+28-28) - (modified) clang/test/CodeGenHLSL/builtins/all.hlsl (+80-80) - (modified) clang/test/CodeGenHLSL/builtins/any.hlsl (+80-80) - (modified) clang/test/CodeGenHLSL/builtins/ceil.hlsl (+12-12) - (modified) clang/test/CodeGenHLSL/builtins/clamp.hlsl (+40-40) - (modified) clang/test/CodeGenHLSL/builtins/cos.hlsl (+12-12) - (modified) clang/test/CodeGenHLSL/builtins/exp.hlsl (+12-12) - (modified) clang/test/CodeGenHLSL/builtins/exp2.hlsl (+12-12) - (modified) clang/test/CodeGenHLSL/builtins/floor.hlsl (+12-12) - (modified) clang/test/CodeGenHLSL/builtins/frac.hlsl (+12-12) - (modified) clang/test/CodeGenHLSL/builtins/isinf.hlsl (+8-8) - (modified) clang/test/CodeGenHLSL/builtins/log.hlsl (+12-12) - (modified) clang/test/CodeGenHLSL/builtins/log10.hlsl (+12-12) - (modified) clang/test/CodeGenHLSL/builtins/log2.hlsl (+12-12) - (modified) clang/test/CodeGenHLSL/builtins/max.hlsl (+40-40) - (modified) clang/test/CodeGenHLSL/builtins/min.hlsl (+40-40) - (modified) clang/test/CodeGenHLSL/builtins/pow.hlsl (+12-12) - (modified) clang/test/CodeGenHLSL/builtins/rcp.hlsl (+32-32) - (modified) clang/test/CodeGenHLSL/builtins/reversebits.hlsl (+12-12) - (modified) clang/test/CodeGenHLSL/builtins/round.hlsl (+12-12) - (modified) clang/test/CodeGenHLSL/builtins/rsqrt.hlsl (+12-12) - (modified) clang/test/CodeGenHLSL/builtins/sin.hlsl (+12-12) - (modified) clang/test/CodeGenHLSL/builtins/sqrt.hlsl (+12-12) - (modified) clang/test/CodeGenHLSL/builtins/trunc.hlsl (+12-12) - (modified) clang/test/CodeGenHLSL/builtins/wave_get_lane_index_do_while.hlsl (+1-1) - (modified) clang/test/CodeGenHLSL/builtins/wave_get_lane_index_simple.hlsl (+1-1) - (modified) clang/test/CodeGenHLSL/builtins/wave_get_lane_index_subcall.hlsl (+2-2) - (modified) clang/test/CodeGenHLSL/convergence/do.while.hlsl (+5-5) - (modified) clang/test/CodeGenHLSL/convergence/for.hlsl (+7-7) - (modified) clang/test/CodeGenHLSL/convergence/while.hlsl (+6-6) - (modified) clang/test/CodeGenHLSL/no_int_promotion.hlsl (+7-7) - (modified) clang/test/CodeGenHLSL/shift-mask.hlsl (+4-4) - (modified) clang/test/CodeGenHLSL/this-assignment-overload.hlsl (+2-2) - (modified) clang/test/CodeGenHLSL/this-assignment.hlsl (+2-2) - (modified) clang/test/Options/enable_16bit_types_validation_spirv.hlsl (+1-1) ``diff diff --git a/clang/docs/HLSL/ExpectedDifferences.rst b/clang/docs/HLSL/ExpectedDifferences.rst index d1b6010f10f43..e0de62345bd8c 100644 --- a/clang/docs/HLSL/ExpectedDifferences.rst +++ b/clang/docs/HLSL/ExpectedDifferences.rst @@ -108,3 +108,16 @@ behavior between Clang and DXC. Some examples include: diagnostic notifying the user of the conversion rather than silently altering precision relative to the other overloads (as FXC does) or generating code that will fail validation (as DXC does). + +Correctness improvements (bug fixes) + + +Entry point functions & ``static`` keyword +-- +Marking a shader entry point function ``static`` will result in an error. + +This is idential to DXC behavior when an entry point is specified as compiler +argument. However, DXC does not report an error when compiling a shader library +that has an entry point function with ``[shader("stage")]`` attribute that is +also marked ``static``. Additionally, this function definition
[clang] [HLSL] Change default linkage of HLSL functions and `groupshared` variables (PR #93336)
https://github.com/hekota ready_for_review https://github.com/llvm/llvm-project/pull/93336 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Change default linkage of HLSL functions and `groupshared` variables (PR #93336)
https://github.com/hekota edited https://github.com/llvm/llvm-project/pull/93336 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix bad comment indentation before ifdef after braceless if (PR #94776)
@@ -796,6 +796,24 @@ TEST_F(FormatTestComments, ParsesCommentsAdjacentToPPDirectives) { format("namespace {}\n /* Test */#define A")); } + +TEST_F(FormatTestComments, DeIdentsCommentBeforeIfdefAfterBracelessIf) { + EXPECT_EQ("void f() {\n" Erich-Reitz wrote: Updated to do so. Not sure if I need to give a style. https://github.com/llvm/llvm-project/pull/94776 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix bad comment indentation before ifdef after braceless if (PR #94776)
https://github.com/Erich-Reitz updated https://github.com/llvm/llvm-project/pull/94776 >From 6c910c8b40be79e3d573f6953860f60ebd27b39f Mon Sep 17 00:00:00 2001 From: Erich Reitz Date: Fri, 7 Jun 2024 13:04:33 -0400 Subject: [PATCH 1/5] delay flushing comments before ifdef after braceless if; align with token that begins conditional --- clang/lib/Format/UnwrappedLineParser.cpp | 19 +++ clang/lib/Format/UnwrappedLineParser.h | 2 ++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index b15a87327240b..7bc066787bf46 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -354,6 +354,7 @@ bool UnwrappedLineParser::precededByCommentOrPPDirective() const { bool UnwrappedLineParser::parseLevel(const FormatToken *OpeningBrace, IfStmtKind *IfKind, FormatToken **IfLeftBrace) { + const bool InRequiresExpression = OpeningBrace && OpeningBrace->is(TT_RequiresExpressionLBrace); const bool IsPrecededByCommentOrPPDirective = @@ -385,6 +386,7 @@ bool UnwrappedLineParser::parseLevel(const FormatToken *OpeningBrace, }; switch (Kind) { + case tok::comment: nextToken(); addUnwrappedLine(); @@ -1419,6 +1421,7 @@ void UnwrappedLineParser::readTokenWithJavaScriptASI() { void UnwrappedLineParser::parseStructuralElement( const FormatToken *OpeningBrace, IfStmtKind *IfKind, FormatToken **IfLeftBrace, bool *HasDoWhile, bool *HasLabel) { + if (Style.Language == FormatStyle::LK_TableGen && FormatTok->is(tok::pp_include)) { nextToken(); @@ -1696,6 +1699,7 @@ void UnwrappedLineParser::parseStructuralElement( const bool InRequiresExpression = OpeningBrace && OpeningBrace->is(TT_RequiresExpressionLBrace); + do { const FormatToken *Previous = FormatTok->Previous; switch (FormatTok->Tok.getKind()) { @@ -2705,6 +2709,7 @@ void UnwrappedLineParser::parseUnbracedBody(bool CheckEOF) { addUnwrappedLine(); ++Line->Level; + ++UnBracedBodyDepth; parseStructuralElement(); if (Tok) { @@ -2719,11 +2724,11 @@ void UnwrappedLineParser::parseUnbracedBody(bool CheckEOF) { assert(Tok); ++Tok->BraceCount; } - if (CheckEOF && eof()) addUnwrappedLine(); --Line->Level; + --UnBracedBodyDepth; } static void markOptionalBraces(FormatToken *LeftBrace) { @@ -4736,6 +4741,7 @@ void UnwrappedLineParser::distributeComments( // the two lines about b form a maximal trail, so there are two sections, the // first one consisting of the single comment "// line about a" and the // second one consisting of the next two comments. + if (Comments.empty()) return; bool ShouldPushCommentsInCurrentLine = true; @@ -4811,8 +4817,10 @@ void UnwrappedLineParser::readToken(int LevelDifference) { (!Style.isVerilog() || Keywords.isVerilogPPDirective(*Tokens->peekNextToken())) && FirstNonCommentOnLine) { - distributeComments(Comments, FormatTok); - Comments.clear(); + if (!UnBracedBodyDepth) { +distributeComments(Comments, FormatTok); +Comments.clear(); + } // If there is an unfinished unwrapped line, we flush the preprocessor // directives only after that unwrapped line was finished later. bool SwitchToPreprocessorLines = !Line->Tokens.empty(); @@ -4828,7 +4836,10 @@ void UnwrappedLineParser::readToken(int LevelDifference) { PPBranchLevel > 0) { Line->Level += PPBranchLevel; } - flushComments(isOnNewLine(*FormatTok)); + if (!UnBracedBodyDepth) { +flushComments(isOnNewLine(*FormatTok)); + } + parsePPDirective(); PreviousWasComment = FormatTok->is(tok::comment); FirstNonCommentOnLine = IsFirstNonCommentOnLine( diff --git a/clang/lib/Format/UnwrappedLineParser.h b/clang/lib/Format/UnwrappedLineParser.h index d7963a4211bb9..4d87896870a3e 100644 --- a/clang/lib/Format/UnwrappedLineParser.h +++ b/clang/lib/Format/UnwrappedLineParser.h @@ -338,6 +338,8 @@ class UnwrappedLineParser { // `decltype(auto)`. bool IsDecltypeAutoFunction = false; + int UnBracedBodyDepth = 0; + // Represents preprocessor branch type, so we can find matching // #if/#else/#endif directives. enum PPBranchKind { >From b9d52022e1caf314cb3f24f03775c8baf5da1c4a Mon Sep 17 00:00:00 2001 From: Erich Reitz Date: Fri, 7 Jun 2024 13:08:13 -0400 Subject: [PATCH 2/5] whitespace formatting --- clang/lib/Format/UnwrappedLineParser.cpp | 7 +++ clang/lib/Format/UnwrappedLineParser.h | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index 7bc066787bf46..b17ef33f95e98 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/l
[clang] [HLSL] Change default linkage of HLSL functions and `groupshared` variables (PR #93336)
https://github.com/hekota edited https://github.com/llvm/llvm-project/pull/93336 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Change default linkage of HLSL functions and `groupshared` variables (PR #93336)
https://github.com/hekota edited https://github.com/llvm/llvm-project/pull/93336 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Offload][CUDA] Allow CUDA kernels to use LLVM/Offload (PR #94549)
@@ -0,0 +1,31 @@ +/*===-- LLVM/Offload helpers for kernel languages (CUDA/HIP) -*- 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 + * + *===---=== + */ + +#include + +#define __host__ __attribute__((host)) +#define __device__ __attribute__((device)) +#define __global__ __attribute__((global)) +#define __shared__ __attribute__((shared)) +#define __constant__ __attribute__((constant)) +#define __managed__ __attribute__((managed)) + +extern "C" { + +typedef struct dim3 { + dim3() {} + dim3(unsigned x) : x(x) {} + unsigned x = 0, y = 0, z = 0; +} dim3; + +// TODO: For some reason the CUDA device compilation requires this declaration +// to be present but it should not. Artem-B wrote: It's not clear what "it should not" refers to. Do you mean that CUDA compilation should not require this declaration? Or that the declaration should not be present, ever? The thing is that we need the correct signature for the function. It's easy enough to construct manually, when it only uses built-in types, but in case of more complicated types, especially those that are provided by CUDA headers, we can not do it by ourselves. So, we do need to rely on the front end to give it to us. https://github.com/llvm/llvm-project/pull/94549 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Offload][CUDA] Allow CUDA kernels to use LLVM/Offload (PR #94549)
https://github.com/Artem-B approved this pull request. LGTM in principle. Will kernels in TUs compiled with `-foffload-via-llvm` be interoperable with code that wants to launch them from another TU compiled w/o `-foffload-via-llvm` ? E.g.: - a.cu: `__global__ void kernel() { ... }` - b.cu: `extern __global__ void kernel(); void func() { kernel<<<1,1>>>();}` This could use a test in the testsuite to actually check whether it works. https://github.com/llvm/llvm-project/pull/94549 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Offload][CUDA] Allow CUDA kernels to use LLVM/Offload (PR #94549)
@@ -1125,6 +1125,22 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA, CmdArgs.push_back("__clang_openmp_device_functions.h"); } + if (Args.hasArg(options::OPT_foffload_via_llvm)) { +// Add llvm_wrappers/* to our system include path. This lets us wrap +// standard library headers and other headers. +SmallString<128> P(D.ResourceDir); +llvm::sys::path::append(P, "include"); +llvm::sys::path::append(P, "llvm_offload_wrappers"); Artem-B wrote: path::append accepts multiple components, so it can all be done in one call. https://github.com/llvm/llvm-project/pull/94549 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits