[llvm-bugs] [Bug 32364] New: UBSan: No warning for constructing global reference to misaligned data

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Mar 21 15:09:22 PDT 2017


https://bugs.llvm.org/show_bug.cgi?id=32364

            Bug ID: 32364
           Summary: UBSan: No warning for constructing global reference to
                    misaligned data
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: LLVM Codegen
          Assignee: unassignedclangbugs at nondot.org
          Reporter: vsk at apple.com
                CC: llvm-bugs at lists.llvm.org

Currently, there is no compile-time diagnostic, and no run-time UBSan
diagnostic, for constructing a global reference to misaligned data. Test case:

```
// RUN: %clangxx -fsanitize=alignment %s -o %t -w
// RUN: %run %t 2>&1 | FileCheck %s

char padding[8] __attribute__((aligned(8)));

int &global = *(int *)&padding[1];

int main() {
  // >>> BUG <<<: No diagnostic for store into misaligned data.
  global = 42;

  // CHECK: [[@LINE+1]]:16: runtime error: reference binding to misaligned
address
  int &local = *(int *)&padding[1];

  return 0;
}
```

In the IR, we get:

@padding = global [8 x i8] zeroinitializer, align 8
@global = constant i32* bitcast (i8* getelementptr inbounds ([8 x i8], [8 x
i8]* @padding, i32 0, i64 1) to i32*), align 8

We could fix this by emitting the normal reference binding check in a static
initializer function.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170321/ba31e0a6/attachment.html>


More information about the llvm-bugs mailing list