diff options
author | Evgenii Stepanov <eugenis@google.com> | 2020-02-06 15:07:20 -0800 |
---|---|---|
committer | Evgenii Stepanov <eugenis@google.com> | 2020-02-06 15:09:58 -0800 |
commit | 7dd2810907b87fbecb2ca7c111c2ad37bf1563e9 (patch) | |
tree | a10b705ef22b80136e8ccc74a2935f66a2846338 /llvm/lib/IR/Value.cpp | |
parent | ac8a12c874cc7fb133f470549a2a31c59bb4243e (diff) | |
download | llvm-7dd2810907b87fbecb2ca7c111c2ad37bf1563e9.zip llvm-7dd2810907b87fbecb2ca7c111c2ad37bf1563e9.tar.gz llvm-7dd2810907b87fbecb2ca7c111c2ad37bf1563e9.tar.bz2 |
Fix MSAN failure on Function destruction
Summary:
When Function is destroyed, GlobalValue base class is destroyed, then
Value destructor would call use_empty, which ultimately attempts to
downcast 'this' to GlobalValue. This is UB, and is caught my MSAN as
accessing uninitialized memory.
Call materialized_use_empty, which doesn't call
assertModuleIsMaterializedImpl().
Reviewers: eugenis
Reviewed By: eugenis
Subscribers: hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D74161
Patch by Antonio Maiorano.
Diffstat (limited to 'llvm/lib/IR/Value.cpp')
-rw-r--r-- | llvm/lib/IR/Value.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/llvm/lib/IR/Value.cpp b/llvm/lib/IR/Value.cpp index 8e2d49f..beb3989 100644 --- a/llvm/lib/IR/Value.cpp +++ b/llvm/lib/IR/Value.cpp @@ -83,13 +83,17 @@ Value::~Value() { // reference and something is wrong. This code is here to print out where // the value is still being referenced. // - if (!use_empty()) { + // Note that use_empty() cannot be called here, as it eventually downcasts + // 'this' to GlobalValue (derived class of Value), but GlobalValue has already + // been destructed, so accessing it is UB. + // + if (!materialized_use_empty()) { dbgs() << "While deleting: " << *VTy << " %" << getName() << "\n"; for (auto *U : users()) dbgs() << "Use still stuck around after Def is destroyed:" << *U << "\n"; } #endif - assert(use_empty() && "Uses remain when a value is destroyed!"); + assert(materialized_use_empty() && "Uses remain when a value is destroyed!"); // If this value is named, destroy the name. This should not be in a symtab // at this point. |