-
Notifications
You must be signed in to change notification settings - Fork 7
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
llvm-pretty-bc-parser
drops constant ptrtoint
expression
#266
Comments
I suspect the culprit involves how llvm-pretty-bc-parser/src/Data/LLVM/BitCode/IR/Constants.hs Lines 345 to 360 in 39b4a5f
The suspicious part is the use of the diff --git a/src/Data/LLVM/BitCode/IR/Constants.hs b/src/Data/LLVM/BitCode/IR/Constants.hs
index 24e1600..942037e 100644
--- a/src/Data/LLVM/BitCode/IR/Constants.hs
+++ b/src/Data/LLVM/BitCode/IR/Constants.hs
@@ -8,7 +8,6 @@ module Data.LLVM.BitCode.IR.Constants where
import qualified Data.LLVM.BitCode.Assert as Assert
import Data.LLVM.BitCode.Bitstream
-import Data.LLVM.BitCode.IR.Values
import Data.LLVM.BitCode.Match
import Data.LLVM.BitCode.Parse
import Data.LLVM.BitCode.Record
@@ -345,9 +344,12 @@ parseConstantEntry t (getTy,cs) (fromEntry -> Just r) =
-- [opty, opval, opval, pred]
17 -> label "CST_CODE_CE_CMP" $ do
let field = parseField r
- opty <- getType =<< field 0 numeric
- op0 <- getConstantFwdRefAdjustedId t opty =<< field 1 numeric
- op1 <- getConstantFwdRefAdjustedId t opty =<< field 2 numeric
+ opty <- getType =<< field 0 numeric
+ ix0 <- field 1 numeric
+ ix1 <- field 2 numeric
+ cxt <- getContext
+ let op0 = forwardRef cxt ix0 t
+ let op1 = forwardRef cxt ix1 t
let isFloat = isPrimTypeOf isFloatingPoint
cst <- if isFloat opty || isVectorOf isFloat opty Then round-tripping through |
I did a little more investigation into this:
Based on these findings, I feel much more confident in concluding that the operands of constant expressions use the absolute encodings, which suggests that they should use |
This function is unused and, as noted in #266 (comment), is almost certainly incorrect.
As noted in #266 (comment), the operand IDs in constant expressions use an absolute encoding. This means that parsing constant `icmp` expressions with `getConstantFwdRefAdjustedId` (which assumes a relative encoding) is incorrect. All forms of constant expressions besides constant `icmp` expressions use `forwardRef` (which assumes an absolute encoding) to parse their value operands, so constant `icmp` expressions are the odd one out. This patch fixes the parsing of constant `icmp` expression operands by (1) removing the `getConstantFwdRefAdjustedId` function, and (2) switching to using `forwardRef`. Fixes #266.
Nice analysis. I wish the in-file encoding indicated which type of encoding was being presented so that we could deterministically parse one or the other instead of just hoping we do it the same way that llvm is doing it. |
This function is unused and, as noted in #266 (comment), is almost certainly incorrect.
As noted in #266 (comment), the operand IDs in constant expressions use an absolute encoding. This means that parsing constant `icmp` expressions with `getConstantFwdRefAdjustedId` (which assumes a relative encoding) is incorrect. All forms of constant expressions besides constant `icmp` expressions use `forwardRef` (which assumes an absolute encoding) to parse their value operands, so constant `icmp` expressions are the odd one out. This patch fixes the parsing of constant `icmp` expression operands by (1) removing the `getConstantFwdRefAdjustedId` function, and (2) switching to using `forwardRef`. Fixes #266.
If you take this program:
Compile it to bitcode using
llvm-as
and roundtrip it throughllvm-pretty-bc-parser
, you'll get:Notice that
h
no longer uses a constantptrtoint
expression in the first argument toicmp
. This results in ill-typed LLVM code, whichllvm-as
rejects:This was originally noticed in #262 (comment), with a slightly different test case that uses opaque pointers.
The text was updated successfully, but these errors were encountered: