[PATCH] Fix assertion failure in global-merge with unused ConstantExpr

Oliver Stannard oliver.stannard at arm.com
Mon Jun 8 08:42:14 PDT 2015


Hi ab,

The global-merge pass was crashing because it assumes that all ConstantExprs (reached via the global variables that they use) have at least one user.
    
I haven't worked out a way to test this, as an unused ConstantExpr cannot be represented by serialised IR, and global-merge can only be run in llc, which does not run any passes which can make a ConstantExpr dead.

This (reduced to the point of silliness) C code triggers this bug when compiled for arm-none-eabi at -O1:
  static a = 7;
  static volatile b[10] = {&a};

  c;
  main() {
    c = 0;
    for (; c < 10;)
      printf(b[c]);
  }

REPOSITORY
  rL LLVM

http://reviews.llvm.org/D10314

Files:
  lib/CodeGen/GlobalMerge.cpp

Index: lib/CodeGen/GlobalMerge.cpp
===================================================================
--- lib/CodeGen/GlobalMerge.cpp
+++ lib/CodeGen/GlobalMerge.cpp
@@ -280,6 +280,8 @@
       // users, so look through ConstantExpr...
       Use *UI, *UE;
       if (ConstantExpr *CE = dyn_cast<ConstantExpr>(U.getUser())) {
+        if (CE->use_empty())
+          continue;
         UI = &*CE->use_begin();
         UE = nullptr;
       } else if (isa<Instruction>(U.getUser())) {

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D10314.27314.patch
Type: text/x-patch
Size: 484 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150608/9f050296/attachment.bin>


More information about the llvm-commits mailing list