Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clang inserts pointer "between" checks on high optimization #149

Closed
karljs opened this issue Feb 5, 2019 · 6 comments
Closed

Clang inserts pointer "between" checks on high optimization #149

karljs opened this issue Feb 5, 2019 · 6 comments
Labels

Comments

@karljs
Copy link

karljs commented Feb 5, 2019

Running the Salsa20 SAW script example provided by @atomb for his tutorial leads to a pattern match failure for me by default.

$ saw salsa.saw
...
at :44:10: Pattern match failure in do expression at src/Lang/Crucible/LLVM/Translation/Instruction.hs:1271:14-20

When I add -O0 to the clang call in the Makefile, everything succeeds.

SAW build: nightly 2019-01-29

$ saw --version
0.2 (4099a6c)

This occurs with both clang/llvm 5.0 and 7.0 installed using Nix.

I can paste the SAW and C files if helpful, but they are contained in the saw-intro repository.

@robdockins
Copy link
Contributor

Can you post the generated .bc file? I'm not able to reproduce the error, seems like your clang may be generating different code than mine.

@karljs
Copy link
Author

karljs commented Feb 11, 2019

@robdockins Here's the bitcode. This is generated with clang/llvm 5.0, but I can also try other versions if that's helpful.

salsa20.bc.zip

@robdockins
Copy link
Contributor

Interesting... the version you sent me has done some pretty aggressive inlining and vectorization and loop elimination. I can reproduce the error with this version, I'll see if I can track down what's going on.

@robdockins
Copy link
Contributor

OK, so there are a number of interesting issues with this code.

  1. Clang has aggressively inlined all the interior functions, which means the compositional verification script doesn't work, but only the all-at-once verification script.
  2. There was a bug involving the shufflevector instruction where the vector size of the inputs were getting mixed up, causing incorrect crucible code generation.
  3. Value conversions (zext in particular) needed to be generalized over vector types.
  4. Clang has done some very exciting strength reduction in s20_expand32 and introduced some ordering comparison tests on pointers from different allocation regions.

Items 1 and 2 are now fixed in master crucible, and will get pulled into saw soon.

Item 3 is a different ball of wax. The C standard says these kinds of comparisons are undefined behavior... but clang is happy to perform them and assume that there is some total ordering on allocated regions. The particular test it is doing (a pointer betweenness check) is a special idiom that actually doesn't depend on the particular ordering of regions, but recognizing this is difficult. Not exactly sure what to do about this. I'm pretty surprised clang is willing to insert this construct, actually.

@robdockins robdockins changed the title Irrefutable pattern match failure when -O0 is not used Clang inserts pointer "between" checks on high optimization May 24, 2019
@robdockins
Copy link
Contributor

I think this issue can be resolved by the new lax pointer settings introduced in PR #294, once they get piped through to the SAW frontend.

@RyanGlScott
Copy link
Contributor

I've opened GaloisInc/saw-script#1308 to track the SAW-side changes needed to make this work. At this point, I don't think there is anything left to do Crucible-wise, so I'll close this in favor of GaloisInc/saw-script#1308.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants