[clang] [clang][Lex] Use getBufferName() in isInPredefinedFile() (PR #141490)

via cfe-commits cfe-commits at lists.llvm.org
Mon May 26 05:52:48 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

<details>
<summary>Changes</summary>

I don't think this depends on #line directives, to it should be fine to use getBufferName.

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


1 Files Affected:

- (modified) clang/include/clang/Basic/SourceManager.h (+2-5) 


``````````diff
diff --git a/clang/include/clang/Basic/SourceManager.h b/clang/include/clang/Basic/SourceManager.h
index cd3dac9133223..cb5ed219bd000 100644
--- a/clang/include/clang/Basic/SourceManager.h
+++ b/clang/include/clang/Basic/SourceManager.h
@@ -1531,11 +1531,8 @@ class SourceManager : public RefCountedBase<SourceManager> {
 
   /// Returns whether \p Loc is located in a built-in or command line source.
   bool isInPredefinedFile(SourceLocation Loc) const {
-    PresumedLoc Presumed = getPresumedLoc(Loc);
-    if (Presumed.isInvalid())
-      return false;
-    StringRef Filename(Presumed.getFilename());
-    return Filename == "<built-in>" || Filename == "<command line>";
+    StringRef BufferName = getBufferName(Loc);
+    return BufferName == "<built-in>" || BufferName == "<command line>";
   }
 
   /// Returns if a SourceLocation is in a system header.

``````````

</details>


https://github.com/llvm/llvm-project/pull/141490


More information about the cfe-commits mailing list