[llvm-commits] [dragonegg] r171626 - in /dragonegg/trunk: src/ test/validator/c++/
Duncan Sands
baldrick at free.fr
Sat Jan 5 05:04:56 PST 2013
Author: baldrick
Date: Sat Jan 5 07:04:56 2013
New Revision: 171626
URL: http://llvm.org/viewvc/llvm-project?rev=171626&view=rev
Log:
Add support for NULLPTR_TYPE, which can occur when compiling C++11 code. Based
on a patch by Leo Yuriev. This fixes PR14777.
Added:
dragonegg/trunk/test/validator/c++/nullptr01.C
dragonegg/trunk/test/validator/c++/nullptr05.C
dragonegg/trunk/test/validator/c++/nullptr06.C
dragonegg/trunk/test/validator/c++/nullptr08.C
dragonegg/trunk/test/validator/c++/nullptr09.C
dragonegg/trunk/test/validator/c++/nullptr11.C
dragonegg/trunk/test/validator/c++/nullptr13.C
dragonegg/trunk/test/validator/c++/nullptr14.C
dragonegg/trunk/test/validator/c++/nullptr17.C
dragonegg/trunk/test/validator/c++/nullptr18.C
dragonegg/trunk/test/validator/c++/nullptr20.C
dragonegg/trunk/test/validator/c++/nullptr21.C
dragonegg/trunk/test/validator/c++/nullptr22.C
dragonegg/trunk/test/validator/c++/nullptr23.C
dragonegg/trunk/test/validator/c++/nullptr29.C
Modified:
dragonegg/trunk/src/ConstantConversion.cpp
dragonegg/trunk/src/Convert.cpp
dragonegg/trunk/src/Debug.cpp
dragonegg/trunk/src/TypeConversion.cpp
Modified: dragonegg/trunk/src/ConstantConversion.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/src/ConstantConversion.cpp?rev=171626&r1=171625&r2=171626&view=diff
==============================================================================
--- dragonegg/trunk/src/ConstantConversion.cpp (original)
+++ dragonegg/trunk/src/ConstantConversion.cpp Sat Jan 5 07:04:56 2013
@@ -544,6 +544,9 @@
return ConstantStruct::getAnon(Vals);
}
+#if (GCC_MINOR > 5)
+ case NULLPTR_TYPE:
+#endif
case OFFSET_TYPE:
case POINTER_TYPE:
case REFERENCE_TYPE:
@@ -632,6 +635,9 @@
break;
}
+#if (GCC_MINOR > 5)
+ case NULLPTR_TYPE:
+#endif
case OFFSET_TYPE:
case POINTER_TYPE:
case REFERENCE_TYPE:
Modified: dragonegg/trunk/src/Convert.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/src/Convert.cpp?rev=171626&r1=171625&r2=171626&view=diff
==============================================================================
--- dragonegg/trunk/src/Convert.cpp (original)
+++ dragonegg/trunk/src/Convert.cpp Sat Jan 5 07:04:56 2013
@@ -370,6 +370,9 @@
assert(RegTy->isIntegerTy() && "Expected an integer type!");
return true;
+#if (GCC_MINOR > 5)
+ case NULLPTR_TYPE:
+#endif
case POINTER_TYPE:
case REFERENCE_TYPE:
assert(RegTy->isPointerTy() && "Expected a pointer type!");
Modified: dragonegg/trunk/src/Debug.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/src/Debug.cpp?rev=171626&r1=171625&r2=171626&view=diff
==============================================================================
--- dragonegg/trunk/src/Debug.cpp (original)
+++ dragonegg/trunk/src/Debug.cpp Sat Jan 5 07:04:56 2013
@@ -1025,6 +1025,9 @@
return DIType();
}
+#if (GCC_MINOR > 5)
+ case NULLPTR_TYPE:
+#endif
case POINTER_TYPE:
case REFERENCE_TYPE:
// Do not cache pointer type. The pointer may point to forward declared
Modified: dragonegg/trunk/src/TypeConversion.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/src/TypeConversion.cpp?rev=171626&r1=171625&r2=171626&view=diff
==============================================================================
--- dragonegg/trunk/src/TypeConversion.cpp (original)
+++ dragonegg/trunk/src/TypeConversion.cpp Sat Jan 5 07:04:56 2013
@@ -156,6 +156,9 @@
case ENUMERAL_TYPE:
case FIXED_POINT_TYPE:
case INTEGER_TYPE:
+#if (GCC_MINOR > 5)
+ case NULLPTR_TYPE:
+#endif
case OFFSET_TYPE:
case REAL_TYPE:
case VOID_TYPE:
@@ -456,6 +459,11 @@
return StructType::get(EltTy, EltTy, NULL);
}
+#if (GCC_MINOR > 5)
+ case NULLPTR_TYPE:
+ return GetUnitPointerType(Context, TYPE_ADDR_SPACE(type));
+#endif
+
case OFFSET_TYPE:
return getDataLayout().getIntPtrType(Context, TYPE_ADDR_SPACE(type));
@@ -1269,6 +1277,9 @@
case ENUMERAL_TYPE:
case FIXED_POINT_TYPE:
case INTEGER_TYPE:
+#if (GCC_MINOR > 5)
+ case NULLPTR_TYPE:
+#endif
case OFFSET_TYPE:
case REAL_TYPE:
case VOID_TYPE:
@@ -1401,6 +1412,14 @@
return CheckTypeConversion(type, Ty);
}
+ case COMPLEX_TYPE: {
+ if (Type *Ty = getCachedType(type))
+ return CheckTypeConversion(type, Ty);
+ Type *Ty = ConvertTypeNonRecursive(main_type(type));
+ Ty = StructType::get(Ty, Ty, NULL);
+ return RememberTypeConversion(type, Ty);
+ }
+
case ENUMERAL_TYPE:
// If the enum is incomplete return a placeholder type.
if (!TYPE_SIZE(type))
@@ -1413,13 +1432,15 @@
return CheckTypeConversion(type, IntegerType::get(Context, Size));
}
- case COMPLEX_TYPE: {
- if (Type *Ty = getCachedType(type))
- return CheckTypeConversion(type, Ty);
- Type *Ty = ConvertTypeNonRecursive(main_type(type));
- Ty = StructType::get(Ty, Ty, NULL);
- return RememberTypeConversion(type, Ty);
+#if (GCC_MINOR > 5)
+ case NULLPTR_TYPE: {
+ // As NULLPTR_TYPE has an alignment of 1, output it as an array of bytes.
+ // FIXME: Instead we should use a pointer, and have a general mechanism
+ // for using a bunch of bytes instead for any type which is underaligned.
+ uint64_t Units = getInt64(TYPE_SIZE_UNIT(type), true);
+ return CheckTypeConversion(type, GetUnitType(Context, Units));
}
+#endif
case OFFSET_TYPE: {
// Handle OFFSET_TYPE specially. This is used for pointers to members,
@@ -1429,6 +1450,7 @@
unsigned AS = TYPE_ADDR_SPACE(type);
return CheckTypeConversion(type, getDataLayout().getIntPtrType(Context, AS));
}
+
case REAL_TYPE:
// Caching the type conversion is not worth it.
switch (TYPE_PRECISION(type)) {
Added: dragonegg/trunk/test/validator/c++/nullptr01.C
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/test/validator/c%2B%2B/nullptr01.C?rev=171626&view=auto
==============================================================================
--- dragonegg/trunk/test/validator/c++/nullptr01.C (added)
+++ dragonegg/trunk/test/validator/c++/nullptr01.C Sat Jan 5 07:04:56 2013
@@ -0,0 +1,8 @@
+// RUN: %dragonegg -xc++ -S -std=c++0x %s
+// XFAIL: gcc-4.5
+// PR14777
+char* const cp1 = nullptr;
+char* const cp2 = __null;
+char* const cp3 = 0;
+decltype(nullptr) mynull = 0;
+char* const cp4 = mynull;
Added: dragonegg/trunk/test/validator/c++/nullptr05.C
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/test/validator/c%2B%2B/nullptr05.C?rev=171626&view=auto
==============================================================================
--- dragonegg/trunk/test/validator/c++/nullptr05.C (added)
+++ dragonegg/trunk/test/validator/c++/nullptr05.C Sat Jan 5 07:04:56 2013
@@ -0,0 +1,12 @@
+// RUN: %dragonegg -xc++ -S -std=c++0x %s
+// XFAIL: gcc-4.5
+// PR14777
+class F { };
+
+typedef void (F::*pmf)();
+
+const pmf pmf1 = nullptr;
+const pmf pmf2 = __null;
+const pmf pmf3 = 0;
+decltype(nullptr) mynull = 0;
+const pmf pmf4 = mynull;
Added: dragonegg/trunk/test/validator/c++/nullptr06.C
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/test/validator/c%2B%2B/nullptr06.C?rev=171626&view=auto
==============================================================================
--- dragonegg/trunk/test/validator/c++/nullptr06.C (added)
+++ dragonegg/trunk/test/validator/c++/nullptr06.C Sat Jan 5 07:04:56 2013
@@ -0,0 +1,13 @@
+// RUN: %dragonegg -xc++ -S -std=c++0x %s
+// XFAIL: gcc-4.5
+// PR14777
+#define assert_true(b) do { char c[2 * bool(b) - 1]; } while(0)
+
+char* const cp1 = nullptr;
+
+void fun()
+{
+ assert_true(cp1 == nullptr);
+ decltype(nullptr) mynull = 0;
+ assert_true(cp1 == mynull);
+}
Added: dragonegg/trunk/test/validator/c++/nullptr08.C
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/test/validator/c%2B%2B/nullptr08.C?rev=171626&view=auto
==============================================================================
--- dragonegg/trunk/test/validator/c++/nullptr08.C (added)
+++ dragonegg/trunk/test/validator/c++/nullptr08.C Sat Jan 5 07:04:56 2013
@@ -0,0 +1,11 @@
+// RUN: %dragonegg -xc++ -S -std=c++0x %s
+// XFAIL: gcc-4.5
+// PR14777
+#define assert_true(b) do { char c[2 * bool(b) - 1]; } while(0)
+
+void fun()
+{
+ assert_true(nullptr ? false : true);
+ decltype(nullptr) mynull = 0;
+ assert_true(mynull ? false : true);
+}
Added: dragonegg/trunk/test/validator/c++/nullptr09.C
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/test/validator/c%2B%2B/nullptr09.C?rev=171626&view=auto
==============================================================================
--- dragonegg/trunk/test/validator/c++/nullptr09.C (added)
+++ dragonegg/trunk/test/validator/c++/nullptr09.C Sat Jan 5 07:04:56 2013
@@ -0,0 +1,9 @@
+// RUN: %dragonegg -xc++ -S -std=c++0x %s
+// XFAIL: gcc-4.5
+// PR14777
+void fun()
+{
+ if( nullptr == 0 );
+ decltype(nullptr) mynull = 0;
+ if( mynull == 0 );
+}
Added: dragonegg/trunk/test/validator/c++/nullptr11.C
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/test/validator/c%2B%2B/nullptr11.C?rev=171626&view=auto
==============================================================================
--- dragonegg/trunk/test/validator/c++/nullptr11.C (added)
+++ dragonegg/trunk/test/validator/c++/nullptr11.C Sat Jan 5 07:04:56 2013
@@ -0,0 +1,38 @@
+// RUN: %dragonegg -xc++ -S -std=c++0x %s
+// XFAIL: gcc-4.5
+// PR14777
+#define assert_true(b) do { char c[2 * bool(b) - 1]; } while(0)
+#define assert_false(b) do { char c[1 - 2 * bool(b)]; } while(0)
+
+void fun()
+{
+ assert_true(nullptr == nullptr);
+ assert_false(nullptr != nullptr);
+ assert_false(nullptr < nullptr);
+ assert_false(nullptr > nullptr);
+ assert_true(nullptr <= nullptr);
+ assert_true(nullptr >= nullptr);
+
+ decltype(nullptr) mynull = 0;
+
+ assert_true(mynull == nullptr);
+ assert_false(mynull != nullptr);
+ assert_false(mynull < nullptr);
+ assert_false(mynull > nullptr);
+ assert_true(mynull <= nullptr);
+ assert_true(mynull >= nullptr);
+
+ assert_true(nullptr == mynull);
+ assert_false(nullptr != mynull);
+ assert_false(nullptr < mynull);
+ assert_false(nullptr > mynull);
+ assert_true(nullptr <= mynull);
+ assert_true(nullptr >= mynull);
+
+ assert_true(mynull == mynull);
+ assert_false(mynull != mynull);
+ assert_false(mynull < mynull);
+ assert_false(mynull > mynull);
+ assert_true(mynull <= mynull);
+ assert_true(mynull >= mynull);
+}
Added: dragonegg/trunk/test/validator/c++/nullptr13.C
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/test/validator/c%2B%2B/nullptr13.C?rev=171626&view=auto
==============================================================================
--- dragonegg/trunk/test/validator/c++/nullptr13.C (added)
+++ dragonegg/trunk/test/validator/c++/nullptr13.C Sat Jan 5 07:04:56 2013
@@ -0,0 +1,14 @@
+// RUN: %dragonegg -xc++ -S -std=c++0x %s
+// XFAIL: gcc-4.5
+// PR14777
+#include <typeinfo>
+
+#define assert_true(b) do { char c[2 * bool(b) - 1]; } while(0)
+
+void fun()
+{
+ typeid(nullptr);
+ const decltype(nullptr) mynull = 0;
+ typeid(mynull);
+ assert_true(typeid(nullptr) == typeid(mynull));
+}
Added: dragonegg/trunk/test/validator/c++/nullptr14.C
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/test/validator/c%2B%2B/nullptr14.C?rev=171626&view=auto
==============================================================================
--- dragonegg/trunk/test/validator/c++/nullptr14.C (added)
+++ dragonegg/trunk/test/validator/c++/nullptr14.C Sat Jan 5 07:04:56 2013
@@ -0,0 +1,23 @@
+// RUN: %dragonegg -xc++ -S -std=c++0x %s
+// XFAIL: gcc-4.5
+// PR14777
+template <typename T, typename U> struct tType_equal;
+template <typename T> struct tType_equal<T, T> { typedef void type; };
+
+template <typename T, typename U>
+inline typename tType_equal<T, U>::type
+type_equal(U) { }
+
+char* f( char* );
+int f( int );
+long int f( long int );
+
+void test_f()
+{
+ // Overloading cases
+ //
+ type_equal<char*>(f(nullptr));
+ type_equal<int>(f(0));
+ decltype(nullptr) mynull = 0;
+ type_equal<char*>(f(mynull));
+}
Added: dragonegg/trunk/test/validator/c++/nullptr17.C
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/test/validator/c%2B%2B/nullptr17.C?rev=171626&view=auto
==============================================================================
--- dragonegg/trunk/test/validator/c++/nullptr17.C (added)
+++ dragonegg/trunk/test/validator/c++/nullptr17.C Sat Jan 5 07:04:56 2013
@@ -0,0 +1,21 @@
+// RUN: %dragonegg -xc++ -S -std=c++0x %s
+// XFAIL: gcc-4.5
+// PR14777
+template <typename T, typename U> struct tType_equal;
+template <typename T> struct tType_equal<T, T> { typedef void type; };
+
+template <typename T, typename U>
+inline typename tType_equal<T, U>::type
+type_equal(U) { }
+
+int i( int );
+long int i( long int );
+bool i( bool );
+
+void test_i()
+{
+ // Overload to bool, not int
+ type_equal<bool>(i(nullptr));
+ decltype(nullptr) mynull = 0;
+ type_equal<bool>(i(mynull));
+}
Added: dragonegg/trunk/test/validator/c++/nullptr18.C
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/test/validator/c%2B%2B/nullptr18.C?rev=171626&view=auto
==============================================================================
--- dragonegg/trunk/test/validator/c++/nullptr18.C (added)
+++ dragonegg/trunk/test/validator/c++/nullptr18.C Sat Jan 5 07:04:56 2013
@@ -0,0 +1,19 @@
+// RUN: %dragonegg -xc++ -S -std=c++0x %s
+// XFAIL: gcc-4.5
+// PR14777
+template <typename T, typename U> struct tType_equal;
+template <typename T> struct tType_equal<T, T> { typedef void type; };
+
+template <typename T, typename U>
+inline typename tType_equal<T, U>::type
+type_equal(U) { }
+
+char* j( char* );
+bool j( bool );
+
+void test_j()
+{
+ type_equal<char*>(j(nullptr));
+ decltype(nullptr) mynull = 0;
+ type_equal<char*>(j(mynull));
+}
Added: dragonegg/trunk/test/validator/c++/nullptr20.C
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/test/validator/c%2B%2B/nullptr20.C?rev=171626&view=auto
==============================================================================
--- dragonegg/trunk/test/validator/c++/nullptr20.C (added)
+++ dragonegg/trunk/test/validator/c++/nullptr20.C Sat Jan 5 07:04:56 2013
@@ -0,0 +1,18 @@
+// RUN: %dragonegg -xc++ -S -std=c++0x %s
+// XFAIL: gcc-4.5
+// PR14777
+#include <cstdio>
+#include <cstring>
+
+int main()
+{
+ char buf1[64];
+ char buf2[64];
+ char buf3[64];
+
+ std::sprintf(buf1, "%p", (void*)0);
+ std::sprintf(buf2, "%p", nullptr);
+ decltype(nullptr) mynull = 0;
+ std::sprintf(buf3, "%p", nullptr);
+ return std::strcmp(buf1, buf2) != 0 || std::strcmp(buf1, buf3) != 0;
+}
Added: dragonegg/trunk/test/validator/c++/nullptr21.C
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/test/validator/c%2B%2B/nullptr21.C?rev=171626&view=auto
==============================================================================
--- dragonegg/trunk/test/validator/c++/nullptr21.C (added)
+++ dragonegg/trunk/test/validator/c++/nullptr21.C Sat Jan 5 07:04:56 2013
@@ -0,0 +1,53 @@
+// RUN: %dragonegg -xc++ -S -std=c++0x %s
+// XFAIL: gcc-4.5
+// PR14777
+extern "C" void abort (void);
+
+typedef decltype(nullptr) nullptr_t;
+
+int result[2];
+
+void __attribute__((noinline))
+foo (int i, int j)
+{
+ result[i] = j;
+}
+
+int main()
+{
+ try {
+ throw nullptr;
+ } catch (void*) {
+ foo (0, 1);
+ } catch (bool) {
+ foo (0, 2);
+ } catch (int) {
+ foo (0, 3);
+ } catch (long int) {
+ foo (0, 4);
+ } catch (nullptr_t) {
+ foo (0, 5);
+ } catch (...) {
+ foo (0, 6);
+ }
+
+ nullptr_t mynull = 0;
+ try {
+ throw mynull;
+ } catch (void*) {
+ foo (1, 1);
+ } catch (bool) {
+ foo (1, 2);
+ } catch (int) {
+ foo (1, 3);
+ } catch (long int) {
+ foo (1, 4);
+ } catch (nullptr_t) {
+ foo (1, 5);
+ } catch (...) {
+ foo (1, 6);
+ }
+
+ if (result[0] != 5 || result[1] != 5)
+ abort ();
+}
Added: dragonegg/trunk/test/validator/c++/nullptr22.C
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/test/validator/c%2B%2B/nullptr22.C?rev=171626&view=auto
==============================================================================
--- dragonegg/trunk/test/validator/c++/nullptr22.C (added)
+++ dragonegg/trunk/test/validator/c++/nullptr22.C Sat Jan 5 07:04:56 2013
@@ -0,0 +1,18 @@
+// RUN: %dragonegg -xc++ -S -std=c++0x %s
+// XFAIL: gcc-4.5
+// PR14777
+void f1(const char*, ...) __attribute__((format(printf, 1, 2)));
+void f2(const char*) __attribute__((nonnull));
+void f3(const char*, ...) __attribute__((sentinel));
+
+void f()
+{
+ f1("%p", nullptr);
+ f2(nullptr);
+ f3("x", "y", __null);
+ f3("x", "y", nullptr);
+ decltype(nullptr) mynull = 0;
+ f1("%p", mynull);
+ f2(mynull);
+ f3("x", "y", mynull);
+}
Added: dragonegg/trunk/test/validator/c++/nullptr23.C
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/test/validator/c%2B%2B/nullptr23.C?rev=171626&view=auto
==============================================================================
--- dragonegg/trunk/test/validator/c++/nullptr23.C (added)
+++ dragonegg/trunk/test/validator/c++/nullptr23.C Sat Jan 5 07:04:56 2013
@@ -0,0 +1,24 @@
+// RUN: %dragonegg -xc++ -S -std=c++0x %s
+// XFAIL: gcc-4.5
+// PR14777
+#include <initializer_list>
+
+struct Foo
+{
+ Foo(std::initializer_list<Foo>) { };
+
+ template<class T> Foo(T t) { T u(t); };
+
+private:
+ union Data
+ {
+ Data() : null(nullptr) {}
+
+ std::nullptr_t null;
+ } u_;
+};
+
+int main()
+{
+ Foo f = { {} };
+}
Added: dragonegg/trunk/test/validator/c++/nullptr29.C
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/test/validator/c%2B%2B/nullptr29.C?rev=171626&view=auto
==============================================================================
--- dragonegg/trunk/test/validator/c++/nullptr29.C (added)
+++ dragonegg/trunk/test/validator/c++/nullptr29.C Sat Jan 5 07:04:56 2013
@@ -0,0 +1,4 @@
+// RUN: %dragonegg -xc++ -S -std=c++0x %s
+// XFAIL: gcc-4.5
+// PR14777
+void f(decltype(nullptr) &__restrict np) { }
More information about the llvm-commits
mailing list