[llvm-bugs] [Bug 38070] New: Clang generates i32 type index instead of i64 for getelementptr when using structs

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Jul 5 07:31:23 PDT 2018


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

            Bug ID: 38070
           Summary: Clang generates i32 type index instead of i64 for
                    getelementptr when using structs
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: LLVM Codegen
          Assignee: unassignedclangbugs at nondot.org
          Reporter: janekvoirschot at gmail.com
                CC: llvm-bugs at lists.llvm.org

When using an array, GEP with i64 indices are emitted; however, when using a
struct, GEP with i32 indices are emitted.

Example:

typedef struct {
    unsigned a;
    unsigned b;
} structure;

unsigned f(structure s) {
    return s.b;
}

Compiled with: -S -emit-llvm
Results in:

%struct.structure = type { i32, i32 }

define dso_local i32 @f(i64 %s.coerce) #0 {
entry:
  %s = alloca %struct.structure, align 4
  %0 = bitcast %struct.structure* %s to i64*
  store i64 %s.coerce, i64* %0, align 4
  %b = getelementptr inbounds %struct.structure, %struct.structure* %s, i32 0,
i32 1
  %1 = load i32, i32* %b, align 4
  ret i32 %1
}

Whereas using an array as follows (using the same compiler flags):

unsigned f(unsigned a[50]) {
  return a[12];
}

results in:

define dso_local i32 @f(i32* %a) #0 {
entry:
  %a.addr = alloca i32*, align 8
  store i32* %a, i32** %a.addr, align 8
  %0 = load i32*, i32** %a.addr, align 8
  %arrayidx = getelementptr inbounds i32, i32* %0, i64 12
  %1 = load i32, i32* %arrayidx, align 4
  ret i32 %1
}

-- 
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/20180705/f2db225b/attachment.html>


More information about the llvm-bugs mailing list