[llvm-bugs] [Bug 52552] New: Incorrect remapping of DIArgList for LocalAsMetadata

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Nov 18 17:59:40 PST 2021


https://bugs.llvm.org/show_bug.cgi?id=52552

            Bug ID: 52552
           Summary: Incorrect remapping of DIArgList for LocalAsMetadata
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Transformation Utilities
          Assignee: unassignedbugs at nondot.org
          Reporter: mark.p.mendell at intel.com
                CC: llvm-bugs at lists.llvm.org

Created attachment 25459
  --> https://bugs.llvm.org/attachment.cgi?id=25459&action=edit
foo.ll - sample file containing dbg.value with DIArgList

Mapper::mapValue doesn't handle LocalAsMetadata in a DIArgList.  It replaces it
with undef, which is not properly written/read by the BitCode handlers.
This can be shown using llvm-link which causes remapping to be done.
foo.ll contains:
  call void @llvm.dbg.value(metadata !DIArgList(i32 0, i32 %A), metadata !5,
metadata !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_minus,
DW_OP_stack_value)), !dbg !10

If it is linked with foo2.ll (nothing interesting in it), the result is
call void @llvm.dbg.value(metadata !DIArgList(i32 0, i32 undef), metadata !5,
metadata !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_minus,
DW_OP_stack_value)), !dbg !10
If you then try running llvm-dis on the resulting BC file, it will crash
llvm-link -o result.bc foo.ll foo2.ll
llvm-dis result.bc # boom

The contents of foo.ll debug information is mostly garbage, just left over from
a cut down failing test case.


Tested fix:
ValueMapper.cpp ====
***************
*** 400,412 ****
          // be mapped via mapValue (apart from constants when we have no
          // module level changes, which have an identity mapping).
          if ((Flags & RF_NoModuleLevelChanges) &&
isa<ConstantAsMetadata>(VAM)) {
            MappedArgs.push_back(VAM);
          } else if (Value *LV = mapValue(VAM->getValue())) {
            MappedArgs.push_back(
!               LV == VAM->getValue() ? VAM : ValueAsMetadata::get(LV));
          } else {
            // If we cannot map the value, set the argument as undef.
            MappedArgs.push_back(ValueAsMetadata::get(
                UndefValue::get(VAM->getValue()->getType())));
          }
        }
--- 400,414 ----
          // be mapped via mapValue (apart from constants when we have no
          // module level changes, which have an identity mapping).
          if ((Flags & RF_NoModuleLevelChanges) &&
isa<ConstantAsMetadata>(VAM)) {
            MappedArgs.push_back(VAM);
          } else if (Value *LV = mapValue(VAM->getValue())) {
            MappedArgs.push_back(
!               LV == VAM->getValue() ? VAM : ValueAsMetadata::get(LV));  
!         } else if (isa<LocalAsMetadata>(VAM)) {
!           MappedArgs.push_back(VAM);
          } else {
            // If we cannot map the value, set the argument as undef.
            MappedArgs.push_back(ValueAsMetadata::get(
                UndefValue::get(VAM->getValue()->getType())));
          }
        }

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20211119/b76299e8/attachment.html>


More information about the llvm-bugs mailing list