From 2a351d54a0846ce1ef46f519582ab97e4fcba43d Mon Sep 17 00:00:00 2001 From: "Vikram S. Adve" Date: Fri, 27 Sep 2002 13:27:14 +0000 Subject: [PATCH] Simple test for constant expressions constructed from global addresses. llvm-svn: 3956 --- llvm/test/Regression/LLC/globalrefs.c | 40 +++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 llvm/test/Regression/LLC/globalrefs.c diff --git a/llvm/test/Regression/LLC/globalrefs.c b/llvm/test/Regression/LLC/globalrefs.c new file mode 100644 index 000000000000..3e3cd0910ddd --- /dev/null +++ b/llvm/test/Regression/LLC/globalrefs.c @@ -0,0 +1,40 @@ +/* globalrefs.c - Test constant expressions constructed from global + * addresses and index expressions into global addresses. + * Instead of printing absolute addresses, print out the differences in + * memory addresses to get output that matches that of the native compiler. + */ + +#include + +#define __STDC_LIMIT_MACROS 1 +#include + +struct test { + long A; + struct { unsigned X; unsigned Y; } S; + struct test* next; +}; + +struct test TestArray[10]; +struct test Test1; + +struct test* TestArrayPtr = TestArray; +long* Aptr = &Test1.A; +unsigned* Xptr = &Test1.S.X; + +int +main(int argc, char** argv) +{ + void* a1 = (void*) TestArrayPtr; + void* a2 = (void*) Aptr; + void* a3 = (void*) Xptr; + +#ifdef WANT_ABSOLUTE_ADDRESSES + printf("Aptr = 0x%lx, Xptr = 0x%lx, TestArrayPtr = 0x%lx\n", + Aptr, Xptr, TestArrayPtr); +#endif + + printf("Aptr - TestArrayPtr = 0x%lx, Xptr - Aptr = 0x%lx\n", + (uint64_t) a2 - (uint64_t) a1, (uint64_t) a3 - (uint64_t) a2); + return 0; +}