Skip to content

Conversation

jansvoboda11
Copy link
Contributor

This PR uses the VFS to get the OpenMP entry info instead of going straight to the real file system. This matches the behavior of other input files of the compiler.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:codegen IR generation bugs: mangling, exceptions, etc. clang:openmp OpenMP related changes to Clang labels Sep 26, 2025
@llvmbot
Copy link
Member

llvmbot commented Sep 26, 2025

@llvm/pr-subscribers-clang-codegen

Author: Jan Svoboda (jansvoboda11)

Changes

This PR uses the VFS to get the OpenMP entry info instead of going straight to the real file system. This matches the behavior of other input files of the compiler.


Full diff: https://github.com/llvm/llvm-project/pull/160935.diff

1 Files Affected:

  • (modified) clang/lib/CodeGen/CGOpenMPRuntime.cpp (+1-3)
diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 0136f69172aa5..75bde3f72c4c2 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -1542,10 +1542,8 @@ static llvm::TargetRegionEntryInfo getEntryInfoFromPresumedLoc(
     SourceManager &SM = CGM.getContext().getSourceManager();
     PresumedLoc PLoc = SM.getPresumedLoc(BeginLoc);
 
-    llvm::sys::fs::UniqueID ID;
-    if (llvm::sys::fs::getUniqueID(PLoc.getFilename(), ID)) {
+    if (CGM.getFileSystem()->exists(PLoc.getFilename()))
       PLoc = SM.getPresumedLoc(BeginLoc, /*UseLineDirectives=*/false);
-    }
 
     return std::pair<std::string, uint64_t>(PLoc.getFilename(), PLoc.getLine());
   };

@llvmbot
Copy link
Member

llvmbot commented Sep 26, 2025

@llvm/pr-subscribers-clang

Author: Jan Svoboda (jansvoboda11)

Changes

This PR uses the VFS to get the OpenMP entry info instead of going straight to the real file system. This matches the behavior of other input files of the compiler.


Full diff: https://github.com/llvm/llvm-project/pull/160935.diff

1 Files Affected:

  • (modified) clang/lib/CodeGen/CGOpenMPRuntime.cpp (+1-3)
diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 0136f69172aa5..75bde3f72c4c2 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -1542,10 +1542,8 @@ static llvm::TargetRegionEntryInfo getEntryInfoFromPresumedLoc(
     SourceManager &SM = CGM.getContext().getSourceManager();
     PresumedLoc PLoc = SM.getPresumedLoc(BeginLoc);
 
-    llvm::sys::fs::UniqueID ID;
-    if (llvm::sys::fs::getUniqueID(PLoc.getFilename(), ID)) {
+    if (CGM.getFileSystem()->exists(PLoc.getFilename()))
       PLoc = SM.getPresumedLoc(BeginLoc, /*UseLineDirectives=*/false);
-    }
 
     return std::pair<std::string, uint64_t>(PLoc.getFilename(), PLoc.getLine());
   };

@jansvoboda11 jansvoboda11 merged commit 220ad03 into llvm:main Sep 26, 2025
13 checks passed
@jansvoboda11 jansvoboda11 deleted the omp-entry-info-sloc branch September 26, 2025 21:54
searlmc1 pushed a commit to ROCm/llvm-project that referenced this pull request Sep 27, 2025
@carlobertolli
Copy link
Member

carlobertolli commented Sep 30, 2025

@jansvoboda11 this change breaks -save-temps builds.
Reproducer:

#include <stdio.h>
#include <omp.h>

int main()
{
  int N = 10;

  int a[N];
  int b[N];

  int i;

  for (i=0; i<N; i++)
    a[i]=0;

  for (i=0; i<N; i++)
    b[i]=i;

#pragma omp target parallel for
  {
    for (int j = 0; j< N; j++)
      a[j]=b[j];
  }

  int rc = 0;
  for (i=0; i<N; i++)
    if (a[i] != b[i] ) {
      rc++;
      printf ("Wrong varlue: a[%d]=%d\n", i, a[i]);
    }

  if (!rc)
    printf("Success\n");

  return rc;
}

Build without -save-temps and make llvm print out list of target regions it identified:
clang -mllvm -amdgpu-dump-hsa-metadata -O2 -fopenmp --offload-arch=gfx90a -D__OFFLOAD_ARCH_gfx90a__ veccopy.c

Excerpt from resulting diagnostic shows that there are multiple entry points:
.name: __omp_offloading_811_2ea3964_main_l19
.private_segment_fixed_size: 0
.sgpr_count: 14
.sgpr_spill_count: 0
.symbol: __omp_offloading_811_2ea3964_main_l19.kd

Build with -save-temps and make llvm print out list of target regions it identified:
clang -mllvm -amdgpu-dump-hsa-metadata -O2 -save-temps -fopenmp --offload-arch=gfx90a -D__OFFLOAD_ARCH_gfx90a__ veccopy.c

Excerpt from resulting diagnostic shows that there are no kernels AMDGPU HSA Metadata

amdhsa.kernels: []
amdhsa.target: amdgcn-amd-amdhsa--gfx90a
amdhsa.version:

  • 1
  • 2
    ...

Please fix?

Debugging showed me that this line
if (CGM.getFileSystem()->exists(PLoc.getFilename())) {
is now succeeding (it was not before and I presume that was incorrect, hence your fix).
When using -save-temps, the following statement
PLoc = SM.getPresumedLoc(BeginLoc, /*UseLineDirectives=*/false);
is now identifying the preprocessed <src_file>.i as the actual PLoc filename and not the input source file.

When not using -save-temps, the preprocessed <src_file>.i does not exist in the build folder and the source file remains the same.

For some reason, this has an effect on clang's ability to identify target regions when building for the host, which seems fragile at best.

@jansvoboda11
Copy link
Contributor Author

Thanks for bringing this to my attention, @carlobertolli. I'm happy to take a look, but I'm unable to reproduce on macOS. Could you please create a self-contained LIT test independent of the host platform?

@carlobertolli
Copy link
Member

here we go:
#161472

carlobertolli added a commit that referenced this pull request Oct 1, 2025
@carlobertolli
Copy link
Member

My guess as to why this stopped working is because the function in OMPIRBuilder.cpp
OpenMPIRBuilder::getTargetEntryUniqueInfo(FileIdentifierInfoCallbackTy CallBack,
vfs::FileSystem &VFS,
StringRef ParentName) {

is referring to the source_file.c instead of the preprocessed source_file.i, and when we scan for target regions, we cannot find a match.

llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Oct 1, 2025
jansvoboda11 added a commit to jansvoboda11/llvm-project that referenced this pull request Oct 1, 2025
jansvoboda11 added a commit that referenced this pull request Oct 1, 2025
The PR #160935 incorrectly replaced `llvm::sys::fs::getUniqueID()` with
`llvm::vfs::FileSystem::exists()` in a condition. That's incorrect,
since the first function returns `std::error_code` that evaluates to
`true` when there is an error (file doesn't exist), while the new code
does the opposite. This PR fixes that issue by inverting the
conditional.

Co-authored-by: ronlieb <[email protected]>
searlmc1 pushed a commit to ROCm/llvm-project that referenced this pull request Oct 2, 2025
This PR uses the VFS to get the OpenMP entry info instead of going
straight to the real file system. This matches the behavior of other
input files of the compiler.
searlmc1 pushed a commit to ROCm/llvm-project that referenced this pull request Oct 2, 2025
The PR llvm#160935 incorrectly replaced `llvm::sys::fs::getUniqueID()` with
`llvm::vfs::FileSystem::exists()` in a condition. That's incorrect,
since the first function returns `std::error_code` that evaluates to
`true` when there is an error (file doesn't exist), while the new code
does the opposite. This PR fixes that issue by inverting the
conditional.

Co-authored-by: ronlieb <[email protected]>
mahesh-attarde pushed a commit to mahesh-attarde/llvm-project that referenced this pull request Oct 3, 2025
This PR uses the VFS to get the OpenMP entry info instead of going
straight to the real file system. This matches the behavior of other
input files of the compiler.
mahesh-attarde pushed a commit to mahesh-attarde/llvm-project that referenced this pull request Oct 3, 2025
mahesh-attarde pushed a commit to mahesh-attarde/llvm-project that referenced this pull request Oct 3, 2025
The PR llvm#160935 incorrectly replaced `llvm::sys::fs::getUniqueID()` with
`llvm::vfs::FileSystem::exists()` in a condition. That's incorrect,
since the first function returns `std::error_code` that evaluates to
`true` when there is an error (file doesn't exist), while the new code
does the opposite. This PR fixes that issue by inverting the
conditional.

Co-authored-by: ronlieb <[email protected]>
jansvoboda11 added a commit to swiftlang/llvm-project that referenced this pull request Oct 18, 2025
This PR uses the VFS to get the OpenMP entry info instead of going
straight to the real file system. This matches the behavior of other
input files of the compiler.
jansvoboda11 added a commit to swiftlang/llvm-project that referenced this pull request Oct 18, 2025
The PR llvm#160935 incorrectly replaced `llvm::sys::fs::getUniqueID()` with
`llvm::vfs::FileSystem::exists()` in a condition. That's incorrect,
since the first function returns `std::error_code` that evaluates to
`true` when there is an error (file doesn't exist), while the new code
does the opposite. This PR fixes that issue by inverting the
conditional.

Co-authored-by: ronlieb <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:codegen IR generation bugs: mangling, exceptions, etc. clang:openmp OpenMP related changes to Clang clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants