Skip to content

[llvm] Avoid out-of-order evaluation in DebugInfo #125116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 11, 2025

Conversation

elvinw-intel
Copy link
Contributor

This is an upstream proposal from intel/intel-graphics-compiler@e60884c
We observed malfunctioning StripNonLineTableDebugInfo during debugging and it's caused by out-of-order evaluation, this is a C++ level semantic ambiguity issue, refer https://en.cppreference.com/w/cpp/language/eval_order
Solution is simply separating one line into two.

Copy link

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.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot
Copy link
Member

llvmbot commented Jan 30, 2025

@llvm/pr-subscribers-llvm-transforms
@llvm/pr-subscribers-llvm-ir

@llvm/pr-subscribers-debuginfo

Author: Elvin Wang (elvinw-intel)

Changes

This is an upstream proposal from intel/intel-graphics-compiler@e60884c
We observed malfunctioning StripNonLineTableDebugInfo during debugging and it's caused by out-of-order evaluation, this is a C++ level semantic ambiguity issue, refer https://en.cppreference.com/w/cpp/language/eval_order
Solution is simply separating one line into two.


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

1 Files Affected:

  • (modified) llvm/lib/IR/DebugInfo.cpp (+5-1)
diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp
index 4ce518009bd3ea..ea1d79d436041f 100644
--- a/llvm/lib/IR/DebugInfo.cpp
+++ b/llvm/lib/IR/DebugInfo.cpp
@@ -798,7 +798,11 @@ class DebugTypeInfoRemoval {
 
       return getReplacementMDNode(N);
     };
-    Replacements[N] = doRemap(N);
+    // Seperate recursive doRemap and operator [] into 2 lines to avoid
+    // out-of-order evaluations since both of them can access the same memory
+    // location in map Replacements.
+    auto Value = doRemap(N);
+    Replacements[N] = Value;
   }
 
   /// Do the remapping traversal.

@elvinw-intel
Copy link
Contributor Author

We also added the culprit IR that can reproduce the issue on godbolt llvm 's opt14 and opt15, with arg --strip-nonlinetable-debuginfo

invalid output:

# Compilation provided by Compiler Explorer at https://godbolt.org/
source_filename = "/app/example.ll"

define void @main() {
  ret void, !dbg !5
}

!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!2, !3}
!llvm.ident = !{!4}

!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 3.7 (tags/RELEASE_370/final)", isOptimized: false, runtimeVersion: 0, emissionKind: LineTablesOnly)
!1 = !DIFile(filename: "no filename", directory: "")
!2 = !{i32 2, !"Dwarf Version", i32 4}
!3 = !{i32 2, !"Debug Info Version", i32 3}
!4 = !{!"clang version 3.7 (tags/RELEASE_370/final)"}
!5 = !DILocation(line: 604, column: 1, scope: null) ## it is invalid for scope to be null

correct output:

# Compilation provided by Compiler Explorer at https://godbolt.org/
source_filename = "/app/example.ll"

define void @main() !dbg !5 {
  ret void, !dbg !8
}

!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!2, !3}
!llvm.ident = !{!4}

!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 3.7 (tags/RELEASE_370/final)", isOptimized: false, runtimeVersion: 0, emissionKind: LineTablesOnly)
!1 = !DIFile(filename: "no filename", directory: "")
!2 = !{i32 2, !"Dwarf Version", i32 4}
!3 = !{i32 2, !"Debug Info Version", i32 3}
!4 = !{!"clang version 3.7 (tags/RELEASE_370/final)"}
!5 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 581, type: !6, scopeLine: 582, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0)
!6 = !DISubroutineType(types: !7)
!7 = !{}
!8 = !DILocation(line: 604, column: 1, scope: !5)

@dwblaikie
Copy link
Collaborator

We also added the culprit IR that can reproduce the issue on godbolt llvm 's opt14 and opt15, with arg --strip-nonlinetable-debuginfo

Can you include this in the PR as a regression test?

@elvinw-intel
Copy link
Contributor Author

Can you include this in the PR as a regression test?

Sure, where shall I add this lit test? under llvm/test/Transforms/StripNonLineTableDebugInfo or somewhere else?

@dwblaikie
Copy link
Collaborator

Can you include this in the PR as a regression test?

Sure, where shall I add this lit test? under llvm/test/Transforms/StripNonLineTableDebugInfo or somewhere else?

seems the existing functionality is tested in llvm/test/Transforms/strip-nonlinetable-debuginfo-* so, another file with that naming pattern, probably?

This is an upstream proposal from intel/intel-graphics-compiler@e60884c
We experienced malfunctioning StripNonLineTableDebugInfo during debugging and it's caused by out-of-order evaluation, this is a C++ level semantic ambiguity issue, refer https://en.cppreference.com/w/cpp/language/eval_order
Solution is simply separating one line into two.
@elvinw-intel
Copy link
Contributor Author

elvinw-intel commented Feb 5, 2025

seems the existing functionality is tested in llvm/test/Transforms/strip-nonlinetable-debuginfo-* so, another file with that naming pattern, probably?

added to llvm/test/Transforms/StripNonLineTableDebugInfo/ to follow the name pattern, file named pr125116.ll
( can u also add relevant maintainers to review? thanks

@dwblaikie
Copy link
Collaborator

seems the existing functionality is tested in llvm/test/Transforms/strip-nonlinetable-debuginfo-* so, another file with that naming pattern, probably?

added to llvm/test/Transforms/StripNonLineTableDebugInfo/ to follow the name pattern, file named pr125116.ll ( can u also add relevant maintainers to review? thanks

It looks like there isn't already an llvm/test/Transforms/StripNonLineTableDebugInfo directory, only tests named llvm/test/Transforms/Util/strip-nonlinetable-debuginfo-* (ah, sorry, in my previous comment I'd accidentally omitted the Util part) - could you rename the test to match that pattern? perhaps ./llvm/test/Transforms/Util/strip-nonlinetable-debuginfo-pr125116.ll?

@elvinw-intel
Copy link
Contributor Author

Hi @dwblaikie test was moved to Transform/Util last week, can u help with the process to move fwd.?

@dwblaikie dwblaikie merged commit 71e623d into llvm:main Feb 11, 2025
7 checks passed
Copy link

@elvinw-intel Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

Icohedron pushed a commit to Icohedron/llvm-project that referenced this pull request Feb 11, 2025
This is an upstream proposal from
intel/intel-graphics-compiler@e60884c
We observed malfunctioning StripNonLineTableDebugInfo during debugging
and it's caused by out-of-order evaluation, this is a C++ level semantic
ambiguity issue, refer
https://en.cppreference.com/w/cpp/language/eval_order
Solution is simply separating one line into two.
flovent pushed a commit to flovent/llvm-project that referenced this pull request Feb 13, 2025
This is an upstream proposal from
intel/intel-graphics-compiler@e60884c
We observed malfunctioning StripNonLineTableDebugInfo during debugging
and it's caused by out-of-order evaluation, this is a C++ level semantic
ambiguity issue, refer
https://en.cppreference.com/w/cpp/language/eval_order
Solution is simply separating one line into two.
joaosaffran pushed a commit to joaosaffran/llvm-project that referenced this pull request Feb 14, 2025
This is an upstream proposal from
intel/intel-graphics-compiler@e60884c
We observed malfunctioning StripNonLineTableDebugInfo during debugging
and it's caused by out-of-order evaluation, this is a C++ level semantic
ambiguity issue, refer
https://en.cppreference.com/w/cpp/language/eval_order
Solution is simply separating one line into two.
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Feb 24, 2025
This is an upstream proposal from
intel/intel-graphics-compiler@e60884c
We observed malfunctioning StripNonLineTableDebugInfo during debugging
and it's caused by out-of-order evaluation, this is a C++ level semantic
ambiguity issue, refer
https://en.cppreference.com/w/cpp/language/eval_order
Solution is simply separating one line into two.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants