[llvm] r271402 - [IR] Disallow loading and storing unsized types

Sanjoy Das via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 1 09:13:17 PDT 2016


Author: sanjoy
Date: Wed Jun  1 11:13:10 2016
New Revision: 271402

URL: http://llvm.org/viewvc/llvm-project?rev=271402&view=rev
Log:
[IR] Disallow loading and storing unsized types

Summary:
It isn't clear what is the operational meaning of loading or storing an
unsized types, since it cannot be lowered into something meaningful.
Since there does not seem to be any practical need for it either, make
such loads and stores illegal IR.

Reviewers: majnemer, chandlerc

Subscribers: mcrosier, llvm-commits

Differential Revision: http://reviews.llvm.org/D20846

Added:
    llvm/trunk/test/Verifier/unsized-types.ll
Modified:
    llvm/trunk/docs/LangRef.rst
    llvm/trunk/lib/IR/Verifier.cpp

Modified: llvm/trunk/docs/LangRef.rst
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/LangRef.rst?rev=271402&r1=271401&r2=271402&view=diff
==============================================================================
--- llvm/trunk/docs/LangRef.rst (original)
+++ llvm/trunk/docs/LangRef.rst Wed Jun  1 11:13:10 2016
@@ -6978,12 +6978,12 @@ The '``load``' instruction is used to re
 Arguments:
 """"""""""
 
-The argument to the ``load`` instruction specifies the memory address
-from which to load. The type specified must be a :ref:`first
-class <t_firstclass>` type. If the ``load`` is marked as ``volatile``,
-then the optimizer is not allowed to modify the number or order of
-execution of this ``load`` with other :ref:`volatile
-operations <volatile>`.
+The argument to the ``load`` instruction specifies the memory address from which
+to load. The type specified must be a :ref:`first class <t_firstclass>` type of
+known size (i.e. not containing an :ref:`opaque structural type <t_opaque>`). If
+the ``load`` is marked as ``volatile``, then the optimizer is not allowed to
+modify the number or order of execution of this ``load`` with other
+:ref:`volatile operations <volatile>`.
 
 If the ``load`` is marked as ``atomic``, it takes an extra :ref:`ordering
 <ordering>` and optional ``singlethread`` argument. The ``release`` and
@@ -7101,13 +7101,14 @@ The '``store``' instruction is used to w
 Arguments:
 """"""""""
 
-There are two arguments to the ``store`` instruction: a value to store
-and an address at which to store it. The type of the ``<pointer>``
-operand must be a pointer to the :ref:`first class <t_firstclass>` type of
-the ``<value>`` operand. If the ``store`` is marked as ``volatile``,
-then the optimizer is not allowed to modify the number or order of
-execution of this ``store`` with other :ref:`volatile
-operations <volatile>`.
+There are two arguments to the ``store`` instruction: a value to store and an
+address at which to store it. The type of the ``<pointer>`` operand must be a
+pointer to the :ref:`first class <t_firstclass>` type of the ``<value>``
+operand. If the ``store`` is marked as ``volatile``, then the optimizer is not
+allowed to modify the number or order of execution of this ``store`` with other
+:ref:`volatile operations <volatile>`.  Only values of :ref:`first class
+<t_firstclass>` types of known size (i.e. not containing an :ref:`opaque
+structural type <t_opaque>`) can be stored.
 
 If the ``store`` is marked as ``atomic``, it takes an extra :ref:`ordering
 <ordering>` and optional ``singlethread`` argument. The ``acquire`` and

Modified: llvm/trunk/lib/IR/Verifier.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Verifier.cpp?rev=271402&r1=271401&r2=271402&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Verifier.cpp (original)
+++ llvm/trunk/lib/IR/Verifier.cpp Wed Jun  1 11:13:10 2016
@@ -2963,6 +2963,7 @@ void Verifier::visitLoadInst(LoadInst &L
   Type *ElTy = LI.getType();
   Assert(LI.getAlignment() <= Value::MaximumAlignment,
          "huge alignment values are unsupported", &LI);
+  Assert(ElTy->isSized(), "loading unsized types is not allowed", &LI);
   if (LI.isAtomic()) {
     Assert(LI.getOrdering() != AtomicOrdering::Release &&
                LI.getOrdering() != AtomicOrdering::AcquireRelease,
@@ -2991,6 +2992,7 @@ void Verifier::visitStoreInst(StoreInst
          "Stored value type does not match pointer operand type!", &SI, ElTy);
   Assert(SI.getAlignment() <= Value::MaximumAlignment,
          "huge alignment values are unsupported", &SI);
+  Assert(ElTy->isSized(), "storing unsized types is not allowed", &SI);
   if (SI.isAtomic()) {
     Assert(SI.getOrdering() != AtomicOrdering::Acquire &&
                SI.getOrdering() != AtomicOrdering::AcquireRelease,

Added: llvm/trunk/test/Verifier/unsized-types.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Verifier/unsized-types.ll?rev=271402&view=auto
==============================================================================
--- llvm/trunk/test/Verifier/unsized-types.ll (added)
+++ llvm/trunk/test/Verifier/unsized-types.ll Wed Jun  1 11:13:10 2016
@@ -0,0 +1,24 @@
+; RUN: not opt -verify < %s 2>&1 | FileCheck %s
+
+%X = type opaque
+
+define void @f_0(%X* %ptr) {
+  %t = load %X, %X* %ptr
+  ret void
+; CHECK: loading unsized types is not allowed
+; CHECK-NEXT:  %t = load %X, %X* %ptr
+}
+
+define void @f_1(%X %val, %X* %ptr) {
+  store %X %val, %X* %ptr
+  ret void
+; CHECK: storing unsized types is not allowed
+; CHECK-NEXT:  store %X %val, %X* %ptr
+}
+
+define void @f_2() {
+  %t = alloca %X
+  ret void
+; CHECK: Cannot allocate unsized type
+; CHECK-NEXT:  %t = alloca %X
+}




More information about the llvm-commits mailing list