This is an archive of the discontinued LLVM Phabricator instance.

[OpaquePtr][LLParser] Automatically detect opaque pointers in .ll files
ClosedPublic

Authored by aeubanks on Feb 10 2022, 2:11 PM.

Details

Summary

This allows us to not have to specify -opaque-pointers when updating
IR tests from typed pointers to opaque pointers.

We detect opaque pointers in .ll files by looking for relevant tokens,
either "ptr" or "*".

Diff Detail

Event Timeline

aeubanks created this revision.Feb 10 2022, 2:11 PM
aeubanks requested review of this revision.Feb 10 2022, 2:11 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 10 2022, 2:11 PM
aeubanks updated this revision to Diff 407678.Feb 10 2022, 2:14 PM

update tests

aeubanks added a reviewer: Restricted Project.Feb 10 2022, 2:21 PM
nikic added a subscriber: nikic.Feb 14 2022, 11:33 AM

I'm not really convinced by this. I think automatically going into opaque pointer mode if ptr is mentioned in .ll makes some sense, but I'm not a fan on determining the mode based on first constructed pointer. For bitcode, we can embed a marker for opaque pointer mode rather than guessing.

llvm/include/llvm/IR/LLVMContext.h
309

Why drop this? This is needed for per-frontend enablement, which we'll still need, right?

aeubanks edited the summary of this revision. (Show Details)Feb 22 2022, 11:35 AM
aeubanks added inline comments.
llvm/include/llvm/IR/LLVMContext.h
309

I was under the impression that frontends would just pass -mllvm -opaque-pointers (or whatever the frontend equivalent), since it doesn't seem necessary to support multiple LLVMContexts with different opaque pointers flags. But either way I've restored it in this change.

nikic accepted this revision.Mar 17 2022, 2:13 AM

LGTM

This revision is now accepted and ready to land.Mar 17 2022, 2:13 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 17 2022, 2:13 AM
This revision was landed with ongoing or failed builds.Mar 17 2022, 8:42 AM
This revision was automatically updated to reflect the committed changes.
hctim added a subscriber: hctim.Mar 21 2022, 4:03 PM
hctim added inline comments.
llvm/lib/IR/LLVMContextImpl.cpp
51

Hi, looks like this broke the ASan buildbot.

Help reproducing the bot can be found here. The init-order-fiasco bug is copied below for your convenience.

--
********************
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80..
FAIL: LLVM :: tools/llvm-stress/help.test (73153 of 82954)
******************** TEST 'LLVM :: tools/llvm-stress/help.test' FAILED ********************
Script:
--
: 'RUN: at line 1';   /b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/llvm-stress --help | /b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/FileCheck /b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/test/tools/llvm-stress/help.test --check-prefix HELP --implicit-check-not='{{[Oo]}}ptions:'
--
Exit Code: 2
Command Output (stderr):
--
=================================================================
==53409==ERROR: AddressSanitizer: initialization-order-fiasco on address 0x0000013b96a8 at pc 0x000000867d43 bp 0x7ffeb2c63cb0 sp 0x7ffeb2c63ca8
READ of size 2 at 0x0000013b96a8 thread T0
    #0 0x867d42 in getNumOccurrences /b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/include/llvm/Support/CommandLine.h:395:49
    #1 0x867d42 in llvm::LLVMContextImpl::LLVMContextImpl(llvm::LLVMContext&) /b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/lib/IR/LLVMContextImpl.cpp:51:24
    #2 0x85171e in llvm::LLVMContext::LLVMContext() /b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/lib/IR/LLVMContext.cpp:34:40
    #3 0x6c73bd in __cxx_global_var_init.12 /b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/tools/llvm-stress/llvm-stress.cpp:72:20
    #4 0x6c73bd in _GLOBAL__sub_I_llvm_stress.cpp /b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/tools/llvm-stress/llvm-stress.cpp
    #5 0xc025c4 in __libc_csu_init (/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/llvm-stress+0xc025c4)
    #6 0x7f634e91d029 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24029) (BuildId: 18b9a9a8c523e5cfe5b5d946d605d09242f09798)
    #7 0x5d8079 in _start (/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/llvm-stress+0x5d8079)
0x0000013b96a8 is located 8 bytes inside of global variable 'OpaquePointersCL' defined in '/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/lib/IR/LLVMContextImpl.cpp:38:5' (0x13b96a0) of size 224
  registered at:
    #0 0x5efcb0 in __asan_register_globals.part.19 /b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/compiler-rt/lib/asan/asan_globals.cpp:359:3
    #1 0x88520e in asan.module_ctor LLVMContextImpl.cpp
    #2 0xc025c4 in __libc_csu_init (/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/llvm-stress+0xc025c4)
SUMMARY: AddressSanitizer: initialization-order-fiasco /b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/include/llvm/Support/CommandLine.h:395:49 in getNumOccurrences
Shadow bytes around the buggy address:
  0x00008026f280: f6 f6 f6 f6 00 f9 f9 f9 00 f9 f9 f9 01 f9 f9 f9
  0x00008026f290: 01 f9 f9 f9 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6
  0x00008026f2a0: f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6
  0x00008026f2b0: f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6
  0x00008026f2c0: f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6
=>0x00008026f2d0: f6 f6 f6 f6 f6[f6]f6 f6 f6 f6 f6 f6 f6 f6 f6 f6
  0x00008026f2e0: f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6
  0x00008026f2f0: f6 f6 f6 f6 00 00 f9 f9 00 00 f9 f9 00 00 f9 f9
  0x00008026f300: f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6
  0x00008026f310: f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6
  0x00008026f320: f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07 
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
==53409==ABORTING
FileCheck error: '<stdin>' is empty.
FileCheck command line:  /b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/FileCheck /b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/test/tools/llvm-stress/help.test --check-prefix HELP --implicit-check-not={{[Oo]}}ptions:
--