LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 31054 - Global Variable Optimizer segmentation fault on valid input
Summary: Global Variable Optimizer segmentation fault on valid input
Status: RESOLVED FIXED
Alias: None
Product: clang
Classification: Unclassified
Component: Frontend (show other bugs)
Version: trunk
Hardware: PC Linux
: P normal
Assignee: Matthias Braun
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-11-18 06:24 PST by jhunold
Modified: 2017-01-10 12:10 PST (History)
6 users (show)

See Also:
Fixed By Commit(s):


Attachments
Reduced testcase with stackstrace and run script (3.85 KB, application/x-zip)
2016-11-18 06:24 PST, jhunold
Details

Note You need to log in before you can comment on or make changes to this bug.
Description jhunold 2016-11-18 06:24:08 PST
Created attachment 17610 [details]
Reduced testcase with stackstrace and run script

When compiling the attached reduced test case, current clang segfaults with

1.      <eof> parser at end of file
2.      Per-module optimization passes
3.      Running pass 'Global Variable Optimizer' on module 'report.ii'.
Segmentation fault (core dumped)

Full diagnostics in attached test case

It seems that the creation of a static variable after the assert() triggers this.
Comment 1 Davide Italiano 2016-11-19 15:33:53 PST
$ ./clang blah.cpp -O0 -emit-llvm -c -std=c++1y produces a module which doesn't pass the verifier.

```
Global is referenced by parentless instruction!
i64* @_ZGVZNK3Baz3fooERKNSt3__110shared_ptrI3FooEEE5stFoo
; ModuleID = 'blah.cpp'
  <badref> = load atomic i8, i8* bitcast (i64* @_ZGVZNK3Baz3fooERKNSt3__110shared_ptrI3FooEEE5stFoo to i8*) acquire, align 8
fatal error: error in backend: Broken module found, compilation aborted!
```

so it could be a bug in the frontend. CC:ing Richard Smith.
Comment 2 Davide Italiano 2016-11-19 16:52:40 PST
We only run `Add DWARF path discriminators` before the verifier runs.
I wasn't able to reproduce with `opt` standalone.
Comment 3 Matthias Braun 2017-01-09 18:40:47 PST
This is even easier and seems to trigger the same problem:

struct A { ~A(); };

void f(){
  return;
  static A k;
}
Comment 4 Matthias Braun 2017-01-09 19:22:22 PST
Seemed easy enough to fix: https://reviews.llvm.org/D28505
Comment 5 Matthias Braun 2017-01-10 12:10:34 PST
Fix landed in clang r291576