[llvm] r368191 - [DataLayout] Check StackNatural and FunctionPtr alignments.

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 7 10:20:55 PDT 2019


Author: fhahn
Date: Wed Aug  7 10:20:55 2019
New Revision: 368191

URL: http://llvm.org/viewvc/llvm-project?rev=368191&view=rev
Log:
[DataLayout] Check StackNatural and FunctionPtr alignments.

MaybeAlignment asserts that the passed in value is == 0 or a power of 2.

Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=16272

Reviewers: michaelplatings, gchatelet, jakehehrlich, jfb

Reviewed By: gchatelet

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D65858

Added:
    llvm/trunk/test/Assembler/datalayout-invalid-function-ptr-alignment.ll
    llvm/trunk/test/Assembler/datalayout-invalid-stack-natural-alignment.ll
    llvm/trunk/test/Bitcode/invalid-functionptr-align.ll
    llvm/trunk/test/Bitcode/invalid-functionptr-align.ll.bc   (with props)
Modified:
    llvm/trunk/lib/IR/DataLayout.cpp

Modified: llvm/trunk/lib/IR/DataLayout.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DataLayout.cpp?rev=368191&r1=368190&r2=368191&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DataLayout.cpp (original)
+++ llvm/trunk/lib/IR/DataLayout.cpp Wed Aug  7 10:20:55 2019
@@ -378,7 +378,10 @@ void DataLayout::parseSpecifier(StringRe
       }
       break;
     case 'S': { // Stack natural alignment.
-      StackNaturalAlign = MaybeAlign(inBytes(getInt(Tok)));
+      uint64_t Alignment = inBytes(getInt(Tok));
+      if (Alignment != 0 && !llvm::isPowerOf2_64(Alignment))
+        report_fatal_error("Alignment is neither 0 nor a power of 2");
+      StackNaturalAlign = MaybeAlign(Alignment);
       break;
     }
     case 'F': {
@@ -394,7 +397,10 @@ void DataLayout::parseSpecifier(StringRe
                            "datalayout string");
       }
       Tok = Tok.substr(1);
-      FunctionPtrAlign = MaybeAlign(inBytes(getInt(Tok)));
+      uint64_t Alignment = inBytes(getInt(Tok));
+      if (Alignment != 0 && !llvm::isPowerOf2_64(Alignment))
+        report_fatal_error("Alignment is neither 0 nor a power of 2");
+      FunctionPtrAlign = MaybeAlign(Alignment);
       break;
     }
     case 'P': { // Function address space.

Added: llvm/trunk/test/Assembler/datalayout-invalid-function-ptr-alignment.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/datalayout-invalid-function-ptr-alignment.ll?rev=368191&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/datalayout-invalid-function-ptr-alignment.ll (added)
+++ llvm/trunk/test/Assembler/datalayout-invalid-function-ptr-alignment.ll Wed Aug  7 10:20:55 2019
@@ -0,0 +1,5 @@
+; RUN: not llvm-as %s 2>&1 | FileCheck %s
+
+; CHECK: LLVM ERROR: Alignment is neither 0 nor a power of 2
+
+target datalayout = "Fi24"

Added: llvm/trunk/test/Assembler/datalayout-invalid-stack-natural-alignment.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/datalayout-invalid-stack-natural-alignment.ll?rev=368191&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/datalayout-invalid-stack-natural-alignment.ll (added)
+++ llvm/trunk/test/Assembler/datalayout-invalid-stack-natural-alignment.ll Wed Aug  7 10:20:55 2019
@@ -0,0 +1,5 @@
+; RUN: not llvm-as %s 2>&1 | FileCheck %s
+
+; CHECK: LLVM ERROR: Alignment is neither 0 nor a power of 2
+
+target datalayout = "S24"

Added: llvm/trunk/test/Bitcode/invalid-functionptr-align.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bitcode/invalid-functionptr-align.ll?rev=368191&view=auto
==============================================================================
--- llvm/trunk/test/Bitcode/invalid-functionptr-align.ll (added)
+++ llvm/trunk/test/Bitcode/invalid-functionptr-align.ll Wed Aug  7 10:20:55 2019
@@ -0,0 +1,5 @@
+; Bitcode with invalid function pointer alignment.
+
+; RUN: not llvm-dis %s.bc -o - 2>&1 | FileCheck %s
+
+CHECK: LLVM ERROR: Alignment is neither 0 nor a power of 2

Added: llvm/trunk/test/Bitcode/invalid-functionptr-align.ll.bc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bitcode/invalid-functionptr-align.ll.bc?rev=368191&view=auto
==============================================================================
Binary file - no diff available.

Propchange: llvm/trunk/test/Bitcode/invalid-functionptr-align.ll.bc
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream




More information about the llvm-commits mailing list