[llvm] r256105 - Assert that we have all use/users in the getters.

Ahmed Bougacha via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 21 20:04:11 PST 2015


Hi Rafael,

On Sat, Dec 19, 2015 at 12:03 PM, Rafael Espindola via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
> Author: rafael
> Date: Sat Dec 19 14:03:23 2015
> New Revision: 256105
>
> URL: http://llvm.org/viewvc/llvm-project?rev=256105&view=rev
> Log:
> Assert that we have all use/users in the getters.
>
> An error that is pretty easy to make is to use the lazy bitcode reader
> and then do something like
>
> if (V.use_empty())
>
> The problem is that uses in unmaterialized functions are not accounted
> for.
>
> This patch adds asserts that all uses are known.
>
> Modified:
>     llvm/trunk/include/llvm/IR/Module.h
>     llvm/trunk/include/llvm/IR/Value.h
>     llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
>     llvm/trunk/lib/IR/Module.cpp
>     llvm/trunk/lib/IR/Value.cpp
>     llvm/trunk/lib/IR/Verifier.cpp
>     llvm/trunk/tools/llvm-extract/llvm-extract.cpp
>
> Modified: llvm/trunk/lib/IR/Value.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Value.cpp?rev=256105&r1=256104&r2=256105&view=diff
> ==============================================================================
> --- llvm/trunk/lib/IR/Value.cpp (original)
> +++ llvm/trunk/lib/IR/Value.cpp Sat Dec 19 14:03:23 2015
> @@ -314,6 +314,16 @@ void Value::takeName(Value *V) {
>  }
>
>  #ifndef NDEBUG
> +void Value::assertModuleIsMaterialized() const {
> +  const GlobalValue *GV = dyn_cast<GlobalValue>(this);
> +  if (!GV)
> +    return;
> +  const Module *M = GV->getParent();
> +  if (!M)
> +    return;
> +  assert(M->isMaterialized());

This assertion fails when LTOing C++ because of Value::uses() calls in
analyzeGlobals. I filed PR25919; could you have a look?

Thanks!
-Ahmed


More information about the llvm-commits mailing list