Skip to content

Conversation

jansvoboda11
Copy link
Contributor

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.

@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 Oct 1, 2025
@llvmbot
Copy link
Member

llvmbot commented Oct 1, 2025

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-codegen

Author: Jan Svoboda (jansvoboda11)

Changes

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.


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

2 Files Affected:

  • (modified) clang/lib/CodeGen/CGOpenMPRuntime.cpp (+1-1)
  • (modified) clang/test/OpenMP/amdgcn_save_temps.c (-2)
diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 75bde3f72c4c2..8cda583313ca4 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -1542,7 +1542,7 @@ static llvm::TargetRegionEntryInfo getEntryInfoFromPresumedLoc(
     SourceManager &SM = CGM.getContext().getSourceManager();
     PresumedLoc PLoc = SM.getPresumedLoc(BeginLoc);
 
-    if (CGM.getFileSystem()->exists(PLoc.getFilename()))
+    if (!CGM.getFileSystem()->exists(PLoc.getFilename()))
       PLoc = SM.getPresumedLoc(BeginLoc, /*UseLineDirectives=*/false);
 
     return std::pair<std::string, uint64_t>(PLoc.getFilename(), PLoc.getLine());
diff --git a/clang/test/OpenMP/amdgcn_save_temps.c b/clang/test/OpenMP/amdgcn_save_temps.c
index ebf0d6031ee82..d838bb1166b6b 100644
--- a/clang/test/OpenMP/amdgcn_save_temps.c
+++ b/clang/test/OpenMP/amdgcn_save_temps.c
@@ -1,8 +1,6 @@
 
 // REQUIRES: amdgpu-registered-target
 
-// XFAIL: *
-
 // RUN: %clang_cc1 -E -fopenmp -x c -triple amdgcn-amd-amdhsa -fopenmp-targets=amdgcn-amd-amdhsa -save-temps=cwd %s -o %t-openmp-amdgcn-amd-amdhsa-gfx90a.i
 // RUN: %clang_cc1 -fopenmp  -x c -triple x86_64-unknown-unknown -fopenmp-targets=amdgcn-amd-amdhsa -save-temps=cwd -emit-llvm-bc %s -o %t-x86_64-unknown-unknown.bc
 // RUN: %clang_cc1 -fopenmp -x c -triple amdgcn-amd-amdhsa -fopenmp-targets=amdgcn-amd-amdhsa -save-temps=cwd -emit-llvm -fopenmp-is-target-device -x cpp-output %t-openmp-amdgcn-amd-amdhsa-gfx90a.i -fopenmp-host-ir-file-path %t-x86_64-unknown-unknown.bc -o - | FileCheck %s

Copy link
Member

@carlobertolli carlobertolli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the quick response.

@carlobertolli
Copy link
Member

One thing I would like to see is an example where the then statement is actually executed, i.e. what is that PLoc = .... false for?
Not urgent, merging this pr is more important.

@jansvoboda11
Copy link
Contributor Author

Looking at the code, this condition should kick in when BeginLoc is preceded by a #line that points to a file that doesn't exist - in that case we ask for the source location again, now ignoring that directive (i.e. resolving to the file the BeginLoc physically appears in). I agree more test coverage would be nice here, but I don't have more time to invest into chasing that.

@jansvoboda11 jansvoboda11 merged commit 39410df into llvm:main Oct 1, 2025
9 checks passed
@jansvoboda11 jansvoboda11 deleted the openmp-fix branch October 1, 2025 21:34
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 <ron.lieberman@amd.com>
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 <ron.lieberman@amd.com>
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