[llvm-dev] Possible soundness issue with available_externally (split from "RFC: Add guard intrinsics")

Sanjoy Das via llvm-dev llvm-dev at lists.llvm.org
Thu Feb 25 09:59:27 PST 2016


Couple of other examples:

  void @foo(i32* %ptr) available_externally {
    %discard = load i32, i32* %ptr
  }
  void bar() {
    call @foo(i32* %x)
  }

==>

  void @foo(i32* %ptr) available_externally {
  }
  void bar() {
    call @foo(i32* %x)
  }

==>

  void @foo(i32* %ptr) available_externally {
  }
  void bar() {
    call @foo(i32* undef) ;; non optimized @foo will crash
  }

  ;; Similar example if @foo was dividing something by an integer
  ;; argument

We've actually seen the above in our VM (though back then we
didn't realize that the problem was more general than the one
case above).

Another one involving `undef` (semantically same as "folding undef",
but different enough to state separately):

  void @foo(i32* %ptr) available_externally {
    store i32 undef, i32* %ptr
  }
  void bar() {
    %val = load i32, i32* %x
    call @foo(i32* %x)
  }

==>

  void @foo(i32* %ptr) readonly available_externally {
  }
  void bar() {
    %val = load i32, i32* %x
    call @foo(i32* %x)
  }

==>

  void @foo(i32* %ptr) readonly available_externally {
  }
  void bar() {
    call @foo(i32* %x)
    %val = load i32, i32* %x
  }

With a non-optimized @foo, %val can be garbage.


I'll also note we've not really had bug reports (that I'm aware of)
around this issue.  Given that, it is possible that this is a purely
theoretical problem.

-- Sanjoy


More information about the llvm-dev mailing list