[clang] Support target names with dots in more utilities (PR #65812)
dankm wrote: Sounds good. Everything I want is in the pull request, I'm going to create a new pull request to update some tests as we discussed above. I'll update the description to be a bit more clear. Thanks for all help. https://github.com/llvm/llvm-project/pull/65812 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Support target names containing dots in all utilities (PR #65812)
https://github.com/dankm edited https://github.com/llvm/llvm-project/pull/65812 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Support target names containing dots in all utilities (PR #65812)
https://github.com/dankm edited https://github.com/llvm/llvm-project/pull/65812 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[flang] [clang] [clang-tools-extra] [llvm] [flang] Add EXECUTE_COMMAND_LINE runtime and lowering intrinsics implementation (PR #74077)
@@ -0,0 +1,206 @@ +//===-- runtime/execute.cpp ---===// +// +// 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 "flang/Runtime/execute.h" +#include "environment.h" +#include "stat.h" +#include "terminator.h" +#include "tools.h" +#include "flang/Runtime/descriptor.h" +#include +#include +#include +#ifdef _WIN32 +#define LEAN_AND_MEAN +#define NOMINMAX +#include +#else +#include +#include +#endif + +namespace Fortran::runtime { + +// cmdstat specified in 16.9.73 +// −1 if the processor does not support command line execution, +// a processor-dependent positive value if an error condition occurs +// −2 if no error condition occurs but WAIT is present with the value false +// and the processor does not support asynchronous execution. Otherwise it is +// assigned the value 0 +enum CMD_STAT { + ASYNC_NO_SUPPORT_ERR = -2, + NO_SUPPORT_ERR = -1, + CMD_EXECUTED = 0, + FORK_ERR = 1, + EXECL_ERR = 2, + INVALID_CL_ERR = 3, + SIGNAL_ERR = 4 +}; + +// Override CopyCharsToDescriptor in tools.h, pass string directly +void CopyCharsToDescriptor(const Descriptor &value, const char *rawValue) { + CopyCharsToDescriptor(value, rawValue, std::strlen(rawValue)); +} + +void CheckAndCopyCharsToDescriptor( +const Descriptor *value, const char *rawValue) { + if (value) { +CopyCharsToDescriptor(*value, rawValue); + } +} + +void CheckAndStoreIntToDescriptor( +const Descriptor *intVal, std::int64_t value, Terminator &terminator) { + if (intVal) { +StoreIntToDescriptor(intVal, value, terminator); + } +} + +// If a condition occurs that would assign a nonzero value to CMDSTAT but +// the CMDSTAT variable is not present, error termination is initiated. +int TerminationCheck(int status, const Descriptor *cmdstat, +const Descriptor *cmdmsg, Terminator &terminator) { + if (status == -1) { +if (!cmdstat) { + terminator.Crash("Execution error with system status code: %d", status); +} else { + CheckAndStoreIntToDescriptor(cmdstat, EXECL_ERR, terminator); + CopyCharsToDescriptor(*cmdmsg, "Execution error"); +} + } +#ifdef _WIN32 + // On WIN32 API std::system returns exit status directly + int exitStatusVal{status}; + if (exitStatusVal == 1) { +#else + int exitStatusVal{WEXITSTATUS(status)}; dankm wrote: Linux defines WEXITSTATUS in stdlib.h (and therefore cstdlib), but at least FreeBSD and NetBSD require including sys/wait.h. It should be harmless to always include sys/wait.h, so I'd suggest doing that. https://github.com/llvm/llvm-project/pull/74077 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[flang] [clang] [clang-tools-extra] [llvm] [flang] Add EXECUTE_COMMAND_LINE runtime and lowering intrinsics implementation (PR #74077)
@@ -0,0 +1,206 @@ +//===-- runtime/execute.cpp ---===// +// +// 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 "flang/Runtime/execute.h" +#include "environment.h" +#include "stat.h" +#include "terminator.h" +#include "tools.h" +#include "flang/Runtime/descriptor.h" +#include +#include +#include +#ifdef _WIN32 +#define LEAN_AND_MEAN +#define NOMINMAX +#include +#else +#include +#include +#endif + +namespace Fortran::runtime { + +// cmdstat specified in 16.9.73 +// −1 if the processor does not support command line execution, +// a processor-dependent positive value if an error condition occurs +// −2 if no error condition occurs but WAIT is present with the value false +// and the processor does not support asynchronous execution. Otherwise it is +// assigned the value 0 +enum CMD_STAT { + ASYNC_NO_SUPPORT_ERR = -2, + NO_SUPPORT_ERR = -1, + CMD_EXECUTED = 0, + FORK_ERR = 1, + EXECL_ERR = 2, + INVALID_CL_ERR = 3, + SIGNAL_ERR = 4 +}; + +// Override CopyCharsToDescriptor in tools.h, pass string directly +void CopyCharsToDescriptor(const Descriptor &value, const char *rawValue) { + CopyCharsToDescriptor(value, rawValue, std::strlen(rawValue)); +} + +void CheckAndCopyCharsToDescriptor( +const Descriptor *value, const char *rawValue) { + if (value) { +CopyCharsToDescriptor(*value, rawValue); + } +} + +void CheckAndStoreIntToDescriptor( +const Descriptor *intVal, std::int64_t value, Terminator &terminator) { + if (intVal) { +StoreIntToDescriptor(intVal, value, terminator); + } +} + +// If a condition occurs that would assign a nonzero value to CMDSTAT but +// the CMDSTAT variable is not present, error termination is initiated. +int TerminationCheck(int status, const Descriptor *cmdstat, +const Descriptor *cmdmsg, Terminator &terminator) { + if (status == -1) { +if (!cmdstat) { + terminator.Crash("Execution error with system status code: %d", status); +} else { + CheckAndStoreIntToDescriptor(cmdstat, EXECL_ERR, terminator); + CopyCharsToDescriptor(*cmdmsg, "Execution error"); +} + } +#ifdef _WIN32 + // On WIN32 API std::system returns exit status directly + int exitStatusVal{status}; + if (exitStatusVal == 1) { +#else + int exitStatusVal{WEXITSTATUS(status)}; dankm wrote: Created #77675 for this. https://github.com/llvm/llvm-project/pull/74077 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[flang] [lld] [libcxx] [clang] [mlir] [compiler-rt] [openmp] [llvm] [flang] include sys/wait.h for EXECUTE_COMMAND_LINE (PR #77675)
https://github.com/dankm updated https://github.com/llvm/llvm-project/pull/77675 >From 588e279c3a1c4dcbea9c2d262848eb1d7d49d0d2 Mon Sep 17 00:00:00 2001 From: Dan McGregor Date: Wed, 10 Jan 2024 13:33:37 -0600 Subject: [PATCH] [flang] include sys/wait.h for EXECUTE_COMMAND_LINE Linux defines WEXITSTATUS in stdlib.h, but at least FreeBSD and NetBSD only define it in sys/wait.h. Include this header unconditionally, since it is required on the BSDs and should be harmless on other platforms. --- flang/runtime/execute.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/flang/runtime/execute.cpp b/flang/runtime/execute.cpp index 48773ae8114b0b..246495dd4954ad 100644 --- a/flang/runtime/execute.cpp +++ b/flang/runtime/execute.cpp @@ -21,6 +21,7 @@ #include #else #include +#include #include #endif ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Support target names with dots in more utilities (PR #65812)
dankm wrote: No _good_ particular reason. I got hung up on the formatting issues then ran out of steam, and busy with $job. I just ran clang-format on this change and it came up clean. And now that I've done that the only reason I have left is I'm unable to merge my own changes. Would you mind, @jh7370? https://github.com/llvm/llvm-project/pull/65812 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Support target names with dots in more utilities (PR #65812)
dankm wrote: Hm. I have "fixup" commits in this branch, should I rebase those, or can we squash merge as-is? https://github.com/llvm/llvm-project/pull/65812 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Remap paths in OpenMP runtime calls (#82541) (PR #141250)
dankm wrote: Neat, the original was good, and apparently some tests don't run on my system. Going back to to that version :/ https://github.com/llvm/llvm-project/pull/141250 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Remap paths in OpenMP runtime calls (#82541) (PR #141250)
https://github.com/dankm updated https://github.com/llvm/llvm-project/pull/141250 >From e4fc23b1486180ec01a68f0d2c367d8d15aa8203 Mon Sep 17 00:00:00 2001 From: Dan McGregor Date: Fri, 23 May 2025 10:19:22 -0600 Subject: [PATCH] [Clang] Remap paths in OpenMP runtime calls Apply the debug prefix mapping to the OpenMP location strings. Fixes https://github.com/llvm/llvm-project/issues/82541 --- clang/lib/CodeGen/CGOpenMPRuntime.cpp | 23 ++- clang/test/CodeGen/openmp-prefix-map.c | 21 + 2 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 clang/test/CodeGen/openmp-prefix-map.c diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp index e458d437d085a..d77e624c5edbe 100644 --- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -1352,7 +1352,12 @@ static StringRef getIdentStringFromSourceLocation(CodeGenFunction &CGF, llvm::raw_svector_ostream OS(Buffer); // Build debug location PresumedLoc PLoc = CGF.getContext().getSourceManager().getPresumedLoc(Loc); - OS << ";" << PLoc.getFilename() << ";"; + OS << ";"; + if (CGF.getDebugInfo()) +OS << CGF.getDebugInfo()->remapDIPath(PLoc.getFilename()); + else +OS << PLoc.getFilename(); + OS << ";"; if (const auto *FD = dyn_cast_or_null(CGF.CurFuncDecl)) OS << FD->getQualifiedNameAsString(); OS << ";" << PLoc.getLine() << ";" << PLoc.getColumn() << ";;"; @@ -1370,10 +1375,14 @@ llvm::Value *CGOpenMPRuntime::emitUpdateLocation(CodeGenFunction &CGF, SrcLocStr = OMPBuilder.getOrCreateDefaultSrcLocStr(SrcLocStrSize); } else { std::string FunctionName; +std::string FileName; if (const auto *FD = dyn_cast_or_null(CGF.CurFuncDecl)) FunctionName = FD->getQualifiedNameAsString(); PresumedLoc PLoc = CGF.getContext().getSourceManager().getPresumedLoc(Loc); -const char *FileName = PLoc.getFilename(); +if (CGF.getDebugInfo()) + FileName = CGF.getDebugInfo()->remapDIPath(PLoc.getFilename()); +else + FileName = PLoc.getFilename(); unsigned Line = PLoc.getLine(); unsigned Column = PLoc.getColumn(); SrcLocStr = OMPBuilder.getOrCreateSrcLocStr(FunctionName, FileName, Line, @@ -8840,10 +8849,14 @@ emitMappingInformation(CodeGenFunction &CGF, llvm::OpenMPIRBuilder &OMPBuilder, ExprName = MapExprs.getMapDecl()->getNameAsString(); } + std::string FileName; PresumedLoc PLoc = CGF.getContext().getSourceManager().getPresumedLoc(Loc); - return OMPBuilder.getOrCreateSrcLocStr(PLoc.getFilename(), ExprName, - PLoc.getLine(), PLoc.getColumn(), - SrcLocStrSize); + if (CGF.getDebugInfo()) +FileName = CGF.getDebugInfo()->remapDIPath(PLoc.getFilename()); + else +FileName = PLoc.getFilename(); + return OMPBuilder.getOrCreateSrcLocStr(FileName, ExprName, PLoc.getLine(), + PLoc.getColumn(), SrcLocStrSize); } /// Emit the arrays used to pass the captures and map information to the /// offloading runtime library. If there is no map or capture information, diff --git a/clang/test/CodeGen/openmp-prefix-map.c b/clang/test/CodeGen/openmp-prefix-map.c new file mode 100644 index 0..be3429c267215 --- /dev/null +++ b/clang/test/CodeGen/openmp-prefix-map.c @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -triple i386-unknown-unknown -debug-info-kind=standalone -fopenmp %s -emit-llvm -o - -disable-llvm-optzns -fdebug-prefix-map=%S=.| FileCheck -DPREFIX=%S %s + +// CHECK-NOT: @{{[0-9]+}} = private unnamed_addr constant [{{[0-9]+}} x i8] c";[[PREFIX]]{{.*}}.c;foo;{{[0-9]+}};{{[0-9]+}};;\00" + +void work1(int, int); +void work2(int, int); +void work12(int, int); + +void foo(int q) { + int p = 2; + + #pragma omp parallel firstprivate(q, p) + work1(p, q); + + #pragma omp parallel for firstprivate(p, q) + for (int i = 0; i < q; i++) +work2(i, p); + + #pragma omp target teams firstprivate(p) + work12(p, p); +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Remap paths in OpenMP runtime calls (#82541) (PR #141250)
dankm wrote: @jdoerfert it looks like you wrote the original code I'm modifying here, so I'd like your feedback. Don't know who else would be interested here. https://github.com/llvm/llvm-project/pull/141250 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Remap paths in OpenMP runtime calls (#82541) (PR #141250)
@@ -1370,10 +1375,14 @@ llvm::Value *CGOpenMPRuntime::emitUpdateLocation(CodeGenFunction &CGF, SrcLocStr = OMPBuilder.getOrCreateDefaultSrcLocStr(SrcLocStrSize); } else { std::string FunctionName; +std::string FileName; if (const auto *FD = dyn_cast_or_null(CGF.CurFuncDecl)) FunctionName = FD->getQualifiedNameAsString(); PresumedLoc PLoc = CGF.getContext().getSourceManager().getPresumedLoc(Loc); -const char *FileName = PLoc.getFilename(); +if (CGF.getDebugInfo()) dankm wrote: And ran the full test suite, it is redundant. I'll replace it with an assertion. https://github.com/llvm/llvm-project/pull/141250 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Remap paths in OpenMP runtime calls (#82541) (PR #141250)
https://github.com/dankm updated https://github.com/llvm/llvm-project/pull/141250 >From 8e534d8fe14d70e4fa65dc6d8dad8ad4de73caae Mon Sep 17 00:00:00 2001 From: Dan McGregor Date: Fri, 23 May 2025 10:19:22 -0600 Subject: [PATCH] [Clang] Remap paths in OpenMP runtime calls Apply the debug prefix mapping to the OpenMP location strings. Fixes https://github.com/llvm/llvm-project/issues/82541 --- clang/lib/CodeGen/CGOpenMPRuntime.cpp | 19 ++- clang/test/CodeGen/openmp-prefix-map.c | 21 + 2 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 clang/test/CodeGen/openmp-prefix-map.c diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp index e458d437d085a..d0ac4de71524f 100644 --- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -1352,7 +1352,12 @@ static StringRef getIdentStringFromSourceLocation(CodeGenFunction &CGF, llvm::raw_svector_ostream OS(Buffer); // Build debug location PresumedLoc PLoc = CGF.getContext().getSourceManager().getPresumedLoc(Loc); - OS << ";" << PLoc.getFilename() << ";"; + OS << ";"; + if (CGF.getDebugInfo()) +OS << CGF.getDebugInfo()->remapDIPath(PLoc.getFilename()); + else +OS << PLoc.getFilename(); + OS << ";"; if (const auto *FD = dyn_cast_or_null(CGF.CurFuncDecl)) OS << FD->getQualifiedNameAsString(); OS << ";" << PLoc.getLine() << ";" << PLoc.getColumn() << ";;"; @@ -1373,7 +1378,9 @@ llvm::Value *CGOpenMPRuntime::emitUpdateLocation(CodeGenFunction &CGF, if (const auto *FD = dyn_cast_or_null(CGF.CurFuncDecl)) FunctionName = FD->getQualifiedNameAsString(); PresumedLoc PLoc = CGF.getContext().getSourceManager().getPresumedLoc(Loc); -const char *FileName = PLoc.getFilename(); +assert(CGF.getDebugInfo() && + "No debug information in current CodeGenFunction"); +std::string FileName = CGF.getDebugInfo()->remapDIPath(PLoc.getFilename()); unsigned Line = PLoc.getLine(); unsigned Column = PLoc.getColumn(); SrcLocStr = OMPBuilder.getOrCreateSrcLocStr(FunctionName, FileName, Line, @@ -8841,9 +8848,11 @@ emitMappingInformation(CodeGenFunction &CGF, llvm::OpenMPIRBuilder &OMPBuilder, } PresumedLoc PLoc = CGF.getContext().getSourceManager().getPresumedLoc(Loc); - return OMPBuilder.getOrCreateSrcLocStr(PLoc.getFilename(), ExprName, - PLoc.getLine(), PLoc.getColumn(), - SrcLocStrSize); + assert(CGF.getDebugInfo() && + "No debug information in current CodeGenFunction"); + return OMPBuilder.getOrCreateSrcLocStr( + CGF.getDebugInfo()->remapDIPath(PLoc.getFilename()), ExprName, + PLoc.getLine(), PLoc.getColumn(), SrcLocStrSize); } /// Emit the arrays used to pass the captures and map information to the /// offloading runtime library. If there is no map or capture information, diff --git a/clang/test/CodeGen/openmp-prefix-map.c b/clang/test/CodeGen/openmp-prefix-map.c new file mode 100644 index 0..be3429c267215 --- /dev/null +++ b/clang/test/CodeGen/openmp-prefix-map.c @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -triple i386-unknown-unknown -debug-info-kind=standalone -fopenmp %s -emit-llvm -o - -disable-llvm-optzns -fdebug-prefix-map=%S=.| FileCheck -DPREFIX=%S %s + +// CHECK-NOT: @{{[0-9]+}} = private unnamed_addr constant [{{[0-9]+}} x i8] c";[[PREFIX]]{{.*}}.c;foo;{{[0-9]+}};{{[0-9]+}};;\00" + +void work1(int, int); +void work2(int, int); +void work12(int, int); + +void foo(int q) { + int p = 2; + + #pragma omp parallel firstprivate(q, p) + work1(p, q); + + #pragma omp parallel for firstprivate(p, q) + for (int i = 0; i < q; i++) +work2(i, p); + + #pragma omp target teams firstprivate(p) + work12(p, p); +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Remap paths in OpenMP runtime calls (#82541) (PR #141250)
@@ -1352,7 +1352,12 @@ static StringRef getIdentStringFromSourceLocation(CodeGenFunction &CGF, llvm::raw_svector_ostream OS(Buffer); // Build debug location PresumedLoc PLoc = CGF.getContext().getSourceManager().getPresumedLoc(Loc); - OS << ";" << PLoc.getFilename() << ";"; + OS << ";"; + if (CGF.getDebugInfo()) +OS << CGF.getDebugInfo()->remapDIPath(PLoc.getFilename()); dankm wrote: Makes sense. Thanks. https://github.com/llvm/llvm-project/pull/141250 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Remap paths in OpenMP runtime calls (#82541) (PR #141250)
dankm wrote: > @jdoerfert it looks like you wrote the original code I'm modifying here, so > I'd like your feedback. Don't know who else would be interested here. Hm, @alexey-bataev looks like this is arguably conformance related too. https://github.com/llvm/llvm-project/pull/141250 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Remap paths in OpenMP runtime calls (#82541) (PR #141250)
dankm wrote: If people are good with this, I don't have commit access, so I'd appreciate somebody merging. https://github.com/llvm/llvm-project/pull/141250 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Remap paths in OpenMP runtime calls (#82541) (PR #141250)
dankm wrote: I do need to add tests for this, but wanted to get the general idea up for comments. https://github.com/llvm/llvm-project/pull/141250 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Remap paths in OpenMP runtime calls (#82541) (PR #141250)
https://github.com/dankm created https://github.com/llvm/llvm-project/pull/141250 Apply the debug prefix mapping to the OpenMP location strings. Fixes https://github.com/llvm/llvm-project/issues/82541 >From 6a6c63abc2ff2dd594f82a5ad92f01aee5bdd37a Mon Sep 17 00:00:00 2001 From: Dan McGregor Date: Fri, 23 May 2025 10:19:22 -0600 Subject: [PATCH] [Clang] Remap paths in OpenMP runtime calls Apply the debug prefix mapping to the OpenMP location strings. Fixes https://github.com/llvm/llvm-project/issues/82541 --- clang/lib/CodeGen/CGOpenMPRuntime.cpp | 20 +--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp index e458d437d085a..196c28071bfd6 100644 --- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -1352,7 +1352,12 @@ static StringRef getIdentStringFromSourceLocation(CodeGenFunction &CGF, llvm::raw_svector_ostream OS(Buffer); // Build debug location PresumedLoc PLoc = CGF.getContext().getSourceManager().getPresumedLoc(Loc); - OS << ";" << PLoc.getFilename() << ";"; + OS << ";"; + if (CGF.getDebugInfo()) +OS << CGF.getDebugInfo()->remapDIPath(PLoc.getFilename()); + else +OS << PLoc.getFilename(); + OS << ";"; if (const auto *FD = dyn_cast_or_null(CGF.CurFuncDecl)) OS << FD->getQualifiedNameAsString(); OS << ";" << PLoc.getLine() << ";" << PLoc.getColumn() << ";;"; @@ -1370,10 +1375,14 @@ llvm::Value *CGOpenMPRuntime::emitUpdateLocation(CodeGenFunction &CGF, SrcLocStr = OMPBuilder.getOrCreateDefaultSrcLocStr(SrcLocStrSize); } else { std::string FunctionName; +std::string FileName; if (const auto *FD = dyn_cast_or_null(CGF.CurFuncDecl)) FunctionName = FD->getQualifiedNameAsString(); PresumedLoc PLoc = CGF.getContext().getSourceManager().getPresumedLoc(Loc); -const char *FileName = PLoc.getFilename(); +if (CGF.getDebugInfo()) + FileName = CGF.getDebugInfo()->remapDIPath(PLoc.getFilename()); +else + FileName = PLoc.getFilename(); unsigned Line = PLoc.getLine(); unsigned Column = PLoc.getColumn(); SrcLocStr = OMPBuilder.getOrCreateSrcLocStr(FunctionName, FileName, Line, @@ -8840,8 +8849,13 @@ emitMappingInformation(CodeGenFunction &CGF, llvm::OpenMPIRBuilder &OMPBuilder, ExprName = MapExprs.getMapDecl()->getNameAsString(); } + std::string FileName; PresumedLoc PLoc = CGF.getContext().getSourceManager().getPresumedLoc(Loc); - return OMPBuilder.getOrCreateSrcLocStr(PLoc.getFilename(), ExprName, + if (CGF.getDebugInfo()) +FileName = CGF.getDebugInfo()->remapDIPath(PLoc.getFilename()); + else +FileName = PLoc.getFilename(); + return OMPBuilder.getOrCreateSrcLocStr(FileName, ExprName, PLoc.getLine(), PLoc.getColumn(), SrcLocStrSize); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Remap paths in OpenMP runtime calls (#82541) (PR #141250)
https://github.com/dankm updated https://github.com/llvm/llvm-project/pull/141250 >From 7fdc69f5c55074fa9d647b01f4a370a34c26f966 Mon Sep 17 00:00:00 2001 From: Dan McGregor Date: Fri, 23 May 2025 10:19:22 -0600 Subject: [PATCH] [Clang] Remap paths in OpenMP runtime calls Apply the debug prefix mapping to the OpenMP location strings. Fixes https://github.com/llvm/llvm-project/issues/82541 --- clang/lib/CodeGen/CGOpenMPRuntime.cpp | 23 ++- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp index e458d437d085a..d77e624c5edbe 100644 --- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -1352,7 +1352,12 @@ static StringRef getIdentStringFromSourceLocation(CodeGenFunction &CGF, llvm::raw_svector_ostream OS(Buffer); // Build debug location PresumedLoc PLoc = CGF.getContext().getSourceManager().getPresumedLoc(Loc); - OS << ";" << PLoc.getFilename() << ";"; + OS << ";"; + if (CGF.getDebugInfo()) +OS << CGF.getDebugInfo()->remapDIPath(PLoc.getFilename()); + else +OS << PLoc.getFilename(); + OS << ";"; if (const auto *FD = dyn_cast_or_null(CGF.CurFuncDecl)) OS << FD->getQualifiedNameAsString(); OS << ";" << PLoc.getLine() << ";" << PLoc.getColumn() << ";;"; @@ -1370,10 +1375,14 @@ llvm::Value *CGOpenMPRuntime::emitUpdateLocation(CodeGenFunction &CGF, SrcLocStr = OMPBuilder.getOrCreateDefaultSrcLocStr(SrcLocStrSize); } else { std::string FunctionName; +std::string FileName; if (const auto *FD = dyn_cast_or_null(CGF.CurFuncDecl)) FunctionName = FD->getQualifiedNameAsString(); PresumedLoc PLoc = CGF.getContext().getSourceManager().getPresumedLoc(Loc); -const char *FileName = PLoc.getFilename(); +if (CGF.getDebugInfo()) + FileName = CGF.getDebugInfo()->remapDIPath(PLoc.getFilename()); +else + FileName = PLoc.getFilename(); unsigned Line = PLoc.getLine(); unsigned Column = PLoc.getColumn(); SrcLocStr = OMPBuilder.getOrCreateSrcLocStr(FunctionName, FileName, Line, @@ -8840,10 +8849,14 @@ emitMappingInformation(CodeGenFunction &CGF, llvm::OpenMPIRBuilder &OMPBuilder, ExprName = MapExprs.getMapDecl()->getNameAsString(); } + std::string FileName; PresumedLoc PLoc = CGF.getContext().getSourceManager().getPresumedLoc(Loc); - return OMPBuilder.getOrCreateSrcLocStr(PLoc.getFilename(), ExprName, - PLoc.getLine(), PLoc.getColumn(), - SrcLocStrSize); + if (CGF.getDebugInfo()) +FileName = CGF.getDebugInfo()->remapDIPath(PLoc.getFilename()); + else +FileName = PLoc.getFilename(); + return OMPBuilder.getOrCreateSrcLocStr(FileName, ExprName, PLoc.getLine(), + PLoc.getColumn(), SrcLocStrSize); } /// Emit the arrays used to pass the captures and map information to the /// offloading runtime library. If there is no map or capture information, ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Remap paths in OpenMP runtime calls (#82541) (PR #141250)
https://github.com/dankm updated https://github.com/llvm/llvm-project/pull/141250 >From 1478c326a7e60b270f2a81e373c390183d1483ed Mon Sep 17 00:00:00 2001 From: Dan McGregor Date: Fri, 23 May 2025 10:19:22 -0600 Subject: [PATCH] [Clang] Remap paths in OpenMP runtime calls Apply the debug prefix mapping to the OpenMP location strings. Fixes https://github.com/llvm/llvm-project/issues/82541 --- clang/lib/CodeGen/CGOpenMPRuntime.cpp | 23 ++- clang/test/CodeGen/openmp-prefix-map.c | 21 + 2 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 clang/test/CodeGen/openmp-prefix-map.c diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp index e458d437d085a..d77e624c5edbe 100644 --- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -1352,7 +1352,12 @@ static StringRef getIdentStringFromSourceLocation(CodeGenFunction &CGF, llvm::raw_svector_ostream OS(Buffer); // Build debug location PresumedLoc PLoc = CGF.getContext().getSourceManager().getPresumedLoc(Loc); - OS << ";" << PLoc.getFilename() << ";"; + OS << ";"; + if (CGF.getDebugInfo()) +OS << CGF.getDebugInfo()->remapDIPath(PLoc.getFilename()); + else +OS << PLoc.getFilename(); + OS << ";"; if (const auto *FD = dyn_cast_or_null(CGF.CurFuncDecl)) OS << FD->getQualifiedNameAsString(); OS << ";" << PLoc.getLine() << ";" << PLoc.getColumn() << ";;"; @@ -1370,10 +1375,14 @@ llvm::Value *CGOpenMPRuntime::emitUpdateLocation(CodeGenFunction &CGF, SrcLocStr = OMPBuilder.getOrCreateDefaultSrcLocStr(SrcLocStrSize); } else { std::string FunctionName; +std::string FileName; if (const auto *FD = dyn_cast_or_null(CGF.CurFuncDecl)) FunctionName = FD->getQualifiedNameAsString(); PresumedLoc PLoc = CGF.getContext().getSourceManager().getPresumedLoc(Loc); -const char *FileName = PLoc.getFilename(); +if (CGF.getDebugInfo()) + FileName = CGF.getDebugInfo()->remapDIPath(PLoc.getFilename()); +else + FileName = PLoc.getFilename(); unsigned Line = PLoc.getLine(); unsigned Column = PLoc.getColumn(); SrcLocStr = OMPBuilder.getOrCreateSrcLocStr(FunctionName, FileName, Line, @@ -8840,10 +8849,14 @@ emitMappingInformation(CodeGenFunction &CGF, llvm::OpenMPIRBuilder &OMPBuilder, ExprName = MapExprs.getMapDecl()->getNameAsString(); } + std::string FileName; PresumedLoc PLoc = CGF.getContext().getSourceManager().getPresumedLoc(Loc); - return OMPBuilder.getOrCreateSrcLocStr(PLoc.getFilename(), ExprName, - PLoc.getLine(), PLoc.getColumn(), - SrcLocStrSize); + if (CGF.getDebugInfo()) +FileName = CGF.getDebugInfo()->remapDIPath(PLoc.getFilename()); + else +FileName = PLoc.getFilename(); + return OMPBuilder.getOrCreateSrcLocStr(FileName, ExprName, PLoc.getLine(), + PLoc.getColumn(), SrcLocStrSize); } /// Emit the arrays used to pass the captures and map information to the /// offloading runtime library. If there is no map or capture information, diff --git a/clang/test/CodeGen/openmp-prefix-map.c b/clang/test/CodeGen/openmp-prefix-map.c new file mode 100644 index 0..be3429c267215 --- /dev/null +++ b/clang/test/CodeGen/openmp-prefix-map.c @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -triple i386-unknown-unknown -debug-info-kind=standalone -fopenmp %s -emit-llvm -o - -disable-llvm-optzns -fdebug-prefix-map=%S=.| FileCheck -DPREFIX=%S %s + +// CHECK-NOT: @{{[0-9]+}} = private unnamed_addr constant [{{[0-9]+}} x i8] c";[[PREFIX]]{{.*}}.c;foo;{{[0-9]+}};{{[0-9]+}};;\00" + +void work1(int, int); +void work2(int, int); +void work12(int, int); + +void foo(int q) { + int p = 2; + + #pragma omp parallel firstprivate(q, p) + work1(p, q); + + #pragma omp parallel for firstprivate(p, q) + for (int i = 0; i < q; i++) +work2(i, p); + + #pragma omp target teams firstprivate(p) + work12(p, p); +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Remap paths in OpenMP runtime calls (#82541) (PR #141250)
@@ -1370,10 +1375,14 @@ llvm::Value *CGOpenMPRuntime::emitUpdateLocation(CodeGenFunction &CGF, SrcLocStr = OMPBuilder.getOrCreateDefaultSrcLocStr(SrcLocStrSize); } else { std::string FunctionName; +std::string FileName; if (const auto *FD = dyn_cast_or_null(CGF.CurFuncDecl)) FunctionName = FD->getQualifiedNameAsString(); PresumedLoc PLoc = CGF.getContext().getSourceManager().getPresumedLoc(Loc); -const char *FileName = PLoc.getFilename(); +if (CGF.getDebugInfo()) dankm wrote: I'm *fairly* sure that this check is redundant, because in this branch debug info should be available, but an extra null check seems safer than randomly crashing. I considered replacing this with an assert and running it through clang's test suite, but my machine is rather slow :/ https://github.com/llvm/llvm-project/pull/141250 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits