[PATCH] D130366: [AsmPrinter] Reject ptrtoint to larger size in lowerConstant()

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 25 01:18:42 PDT 2022


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGfb7caa3c7b53: [AsmPrinter] Reject ptrtoint to larger size in lowerConstant() (authored by nikic).

Changed prior to commit:
  https://reviews.llvm.org/D130366?vs=446838&id=447214#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130366/new/

https://reviews.llvm.org/D130366

Files:
  llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
  llvm/test/CodeGen/X86/ptrtoint-constexpr-invalid.ll
  llvm/test/CodeGen/X86/ptrtoint-constexpr.ll


Index: llvm/test/CodeGen/X86/ptrtoint-constexpr.ll
===================================================================
--- llvm/test/CodeGen/X86/ptrtoint-constexpr.ll
+++ llvm/test/CodeGen/X86/ptrtoint-constexpr.ll
@@ -1,11 +1,11 @@
 ; RUN: llc < %s -mtriple=i386-linux | FileCheck %s
-	%union.x = type { i64 }
+	%union.x = type { i32 }
 
 ; CHECK:	.globl r
 ; CHECK: r:
-; CHECK: .quad	r&4294967295
+; CHECK: .long	r
 
- at r = global %union.x { i64 ptrtoint (ptr @r to i64) }, align 4
+ at r = global %union.x { i32 ptrtoint (ptr @r to i32) }, align 4
 
 ; CHECK:	.globl x
 ; CHECK: x:
Index: llvm/test/CodeGen/X86/ptrtoint-constexpr-invalid.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/X86/ptrtoint-constexpr-invalid.ll
@@ -0,0 +1,10 @@
+; RUN: not --crash llc < %s -mtriple=i386-linux 2>&1 | FileCheck %s
+
+; ptrtoint expressions that cast to a wider integer type are not supported.
+; A frontend can achieve a similar result by casting to the correct integer
+; type and explicitly zeroing any additional bytes.
+; { i32, i32 } { i32 ptrtoint (ptr @r to i32), i32 0 }
+
+; CHECK: LLVM ERROR: Unsupported expression in static initializer: ptrtoint (ptr @r to i64)
+
+ at r = global i64 ptrtoint (ptr @r to i64)
Index: llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
===================================================================
--- llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -2795,12 +2795,7 @@
         DL.getTypeAllocSize(Op->getType()).getFixedSize())
       return OpExpr;
 
-    // Otherwise the pointer is smaller than the resultant integer, mask off
-    // the high bits so we are sure to get a proper truncation if the input is
-    // a constant expr.
-    unsigned InBits = DL.getTypeAllocSizeInBits(Op->getType());
-    const MCExpr *MaskExpr = MCConstantExpr::create(~0ULL >> (64-InBits), Ctx);
-    return MCBinaryExpr::createAnd(OpExpr, MaskExpr, Ctx);
+    break; // Error
   }
 
   case Instruction::Sub: {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130366.447214.patch
Type: text/x-patch
Size: 2033 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220725/57e0e096/attachment.bin>


More information about the llvm-commits mailing list