-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Translate c arrays #1898
Translate c arrays #1898
Conversation
…izers and/or multi-dimensional arrays.
Can you add a translate-c test for this? It should be pretty straightforward - the infrastructure is already set up. |
As mentionned in the issue I wanted to, be the output of For example pub const __cplusplus = c_long(201402);
pub const __FLT16_MAX_EXP__ = 15;
pub const __BIGGEST_ALIGNMENT__ = 16;
pub const __SIZEOF_FLOAT__ = 4;
pub const __INT64_FMTd__ = c"lld";
pub const __INT_LEAST32_FMTi__ = c"i";
pub const __INT_LEAST8_FMTi__ = c"hhi";
pub const __LDBL_EPSILON__ = 0.000000;
pub const _NATIVE_NULLPTR_SUPPORTED = 1;
pub const __INT_LEAST32_FMTd__ = c"d";
pub const __STDC_UTF_32__ = 1;
pub const __SIG_ATOMIC_WIDTH__ = 32;
pub const __UINT_FAST64_FMTX__ = c"llX";
pub const __clang_version__ = c"7.0.0 (tags/RELEASE_700/rc3)";
pub const __UINT_LEAST8_FMTo__ = c"hho";
pub const __SIZEOF_DOUBLE__ = 8;
pub const __INTMAX_FMTd__ = c"lld";
pub const __CLANG_ATOMIC_CHAR_LOCK_FREE = 2;
pub const __INT_LEAST16_FMTi__ = c"hi";
pub const __MMX__ = 1;
pub const __SIZE_FMTX__ = c"llX";
pub const __cpp_attributes = c_long(200809);
pub const __WCHAR_WIDTH__ = 16;
pub const __cpp_aggregate_nsdmi = c_long(201304);
pub const __PTRDIFF_FMTd__ = c"lld";
pub const __DBL_MIN_EXP__ = -1021;
pub const __FLT_EVAL_METHOD__ = 0;
pub const __SSE_MATH__ = 1;
pub const __UINT_FAST8_FMTo__ = c"hho";
pub const _RVALUE_REFERENCES_SUPPORTED = 1;
pub const __UINT_LEAST64_MAX__ = c_ulonglong(18446744073709551615);
pub const __cpp_init_captures = c_long(201304);
pub const __UINT_LEAST64_FMTx__ = c"llx";
pub const __INT8_MAX__ = 127;
pub const __DBL_HAS_DENORM__ = 1;
pub const __FLT16_HAS_QUIET_NAN__ = 1;
pub const __ATOMIC_RELAXED = 0;
pub const __DBL_DECIMAL_DIG__ = 17;
pub const __SIZEOF_SHORT__ = 2;
pub const __UINT16_FMTX__ = c"hX";
pub const __UINT_FAST16_MAX__ = 65535;
pub const __CLANG_ATOMIC_SHORT_LOCK_FREE = 2;
pub const __CONSTANT_CFSTRINGS__ = 1;
pub const __WINT_MAX__ = 2147483647;
pub const __LDBL_MAX_EXP__ = 1024;
pub const __cpp_delegating_constructors = c_long(200604);
pub const __NO_MATH_INLINES = 1;
pub const _WIN64 = 1;
pub const __LONG_MAX__ = c_long(2147483647);
pub const __STDC_HOSTED__ = 1;
pub const __pic__ = 2;
pub const __INT_FAST16_FMTi__ = c"hi";
pub const __PTRDIFF_WIDTH__ = 64;
pub const __INT_LEAST32_TYPE__ = int;
pub const __SCHAR_MAX__ = 127;
pub const __LDBL_DENORM_MIN__ = 0.000000;
pub const __FLT16_MIN_EXP__ = -14;
pub const __INT64_C_SUFFIX__ = LL;
pub const __LDBL_MANT_DIG__ = 53;
pub const __CLANG_ATOMIC_INT_LOCK_FREE = 2;
pub const __SIZEOF_PTRDIFF_T__ = 8;
pub const __SIG_ATOMIC_MAX__ = 2147483647;
pub const __UINT64_FMTX__ = c"llX";
pub const __cpp_exceptions = c_long(199711);
pub const __UINT64_MAX__ = c_ulonglong(18446744073709551615);
pub const __DBL_MANT_DIG__ = 53;
pub const __FLT_DECIMAL_DIG__ = 9;
pub const __INT_LEAST32_MAX__ = 2147483647;
pub const __DBL_DIG__ = 15;
pub const __ATOMIC_ACQUIRE = 2;
pub const __OPENCL_MEMORY_SCOPE_WORK_GROUP = 1;
pub const __FLT16_HAS_DENORM__ = 1;
pub const __UINT_FAST16_FMTu__ = c"hu";
pub const __INTPTR_FMTi__ = c"lli";
pub const __UINT_FAST8_FMTX__ = c"hhX";
pub const __LITTLE_ENDIAN__ = 1;
pub const __SSE__ = 1;
pub const __FLT_HAS_QUIET_NAN__ = 1;
pub const __SIZEOF_SIZE_T__ = 8;
pub const __cpp_nsdmi = c_long(200809);
pub const __UINT_LEAST16_FMTo__ = c"ho";
pub const __UINT8_FMTo__ = c"hho";
pub const _MSC_FULL_VER = 191526729;
pub const __UINT_LEAST16_FMTx__ = c"hx";
pub const __CLANG_ATOMIC_WCHAR_T_LOCK_FREE = 2;
pub const __UINT_FAST16_FMTX__ = c"hX";
pub const __VERSION__ = c"4.2.1 Compatible Clang 7.0.0 (tags/RELEASE_700/rc3)";
pub const __UINT_FAST32_FMTx__ = c"x";
pub const __UINTPTR_MAX__ = c_ulonglong(18446744073709551615);
pub const __UINT_FAST8_FMTu__ = c"hhu";
pub const __UINT_LEAST8_FMTu__ = c"hhu";
pub const __UINT_LEAST64_FMTo__ = c"llo";
pub const __UINT_LEAST8_MAX__ = 255;
pub const __SIZEOF_WCHAR_T__ = 2;
pub const __cpp_user_defined_literals = c_long(200809);
pub const __LDBL_MAX__ = 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878;
pub const __UINT16_MAX__ = 65535;
pub const __x86_64 = 1;
pub const __SIZEOF_WINT_T__ = 4;
pub const __cpp_unicode_literals = c_long(200710);
pub const __FLT_DIG__ = 6;
pub const __UINTMAX_FMTo__ = c"llo";
pub const __UINT_LEAST8_FMTX__ = c"hhX";
pub const __INT16_MAX__ = 32767;
pub const __FLT_MAX_10_EXP__ = 38;
pub const __cpp_decltype = c_long(200707);
pub const __UINTPTR_FMTX__ = c"llX";
pub const __UINT_LEAST16_FMTu__ = c"hu";
pub const __CLANG_ATOMIC_POINTER_LOCK_FREE = 2;
pub const __WINT_WIDTH__ = 32;
pub const _MSC_EXTENSIONS = 1;
pub const __SHRT_MAX__ = 32767;
pub const _M_AMD64 = 100;
pub const __POINTER_WIDTH__ = 64;
pub const __PTRDIFF_MAX__ = c_longlong(9223372036854775807);
pub const __INT32_FMTd__ = c"d";
pub const __FLT16_DIG__ = 3;
pub const __DBL_MIN__ = 0.000000;
pub const __SIZEOF_LONG__ = 4;
pub const _WIN32 = 1;
pub const __INTPTR_WIDTH__ = 64;
pub const __FLT16_MAX_10_EXP__ = 4;
pub const __INT_FAST32_TYPE__ = int;
pub const __NO_INLINE__ = 1;
pub const __UINT_FAST32_FMTX__ = c"X";
pub const __INT_FAST32_MAX__ = 2147483647;
pub const __UINTMAX_FMTu__ = c"llu";
pub const __cpp_digit_separators = c_long(201309);
pub const __cpp_unicode_characters = c_long(200704);
pub const __FLT_RADIX__ = 2;
pub const __FLT16_HAS_INFINITY__ = 1;
pub const __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 = 1;
pub const __OPENCL_MEMORY_SCOPE_ALL_SVM_DEVICES = 3;
pub const __cpp_variadic_templates = c_long(200704);
pub const __FLT16_DECIMAL_DIG__ = 5;
pub const __INT_FAST8_FMTd__ = c"hhd";
pub const __PRAGMA_REDEFINE_EXTNAME = 1;
pub const __DEPRECATED = 1;
pub const __INT32_TYPE__ = int;
pub const __STDCPP_DEFAULT_NEW_ALIGNMENT__ = c_ulonglong(16);
pub const __UINTMAX_WIDTH__ = 64;
pub const __FLT_MIN__ = 0.000000;
pub const __INT64_FMTi__ = c"lli";
pub const __cpp_inheriting_constructors = c_long(201511);
pub const __UINT_FAST64_FMTu__ = c"llu";
pub const __INT8_FMTd__ = c"hhd";
pub const __INT_FAST16_TYPE__ = short;
pub const __FLT_MAX_EXP__ = 128;
pub const __DBL_MAX_10_EXP__ = 308;
pub const __LDBL_MIN__ = 0.000000;
pub const __INT_FAST64_FMTi__ = c"lli";
pub const __INT_LEAST8_FMTd__ = c"hhd";
pub const __CLANG_ATOMIC_LLONG_LOCK_FREE = 2;
pub const __UINT_LEAST32_FMTX__ = c"X";
pub const __PIC__ = 2;
pub const __UINTMAX_MAX__ = c_ulonglong(18446744073709551615);
pub const _MSC_BUILD = 1;
pub const __UINT_FAST16_FMTo__ = c"ho";
pub const __cpp_range_based_for = 200907;
pub const __cpp_return_type_deduction = c_long(201304);
pub const __LDBL_DECIMAL_DIG__ = 17;
pub const __UINT_LEAST64_FMTX__ = c"llX";
pub const __clang_minor__ = 0;
pub const __cpp_constexpr = c_long(201304);
pub const __UINT_FAST64_FMTo__ = c"llo";
pub const __SIZE_FMTx__ = c"llx";
pub const __DBL_MAX__ = 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878;
pub const __DBL_EPSILON__ = 0.000000;
pub const __UINT64_FMTx__ = c"llx";
pub const _MSC_VER = 1915;
pub const _HAS_CHAR16_T_LANGUAGE_SUPPORT = 1;
pub const __CHAR_BIT__ = 8;
pub const __BOOL_DEFINED = 1;
pub const __INT16_FMTi__ = c"hi";
pub const _DEBUG = 1;
pub const __UINT_FAST32_MAX__ = c_uint(4294967295);
pub const __UINT8_FMTX__ = c"hhX";
pub const __FLT_EPSILON__ = 0.000000;
pub const __UINTPTR_WIDTH__ = 64;
pub const __llvm__ = 1;
pub const __UINT_FAST64_MAX__ = c_ulonglong(18446744073709551615);
pub const __INT_FAST32_FMTi__ = c"i";
pub const __FLT_HAS_INFINITY__ = 1;
pub const __k8 = 1;
pub const __UINT8_FMTx__ = c"hhx";
pub const __INTMAX_C_SUFFIX__ = LL;
pub const __ORDER_LITTLE_ENDIAN__ = 1234;
pub const __INT16_FMTd__ = c"hd";
pub const __UINT32_FMTX__ = c"X";
pub const __cpp_lambdas = c_long(200907);
pub const __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 = 1;
pub const __UINT32_C_SUFFIX__ = U;
pub const __INT32_MAX__ = 2147483647;
pub const __INTMAX_WIDTH__ = 64;
pub const __CLANG_ATOMIC_BOOL_LOCK_FREE = 2;
pub const __SIZE_FMTo__ = c"llo";
pub const __DBL_HAS_QUIET_NAN__ = 1;
pub const __INT_FAST8_FMTi__ = c"hhi";
pub const __UINT_LEAST32_FMTo__ = c"o";
pub const __STDC_UTF_16__ = 1;
pub const __UINT_LEAST32_MAX__ = c_uint(4294967295);
pub const __ATOMIC_RELEASE = 3;
pub const __UINT_FAST16_FMTx__ = c"hx";
pub const __UINTMAX_C_SUFFIX__ = ULL;
pub const __FLT_MIN_EXP__ = -125;
pub const __cpp_rtti = c_long(199711);
pub const __SIZEOF_LONG_DOUBLE__ = 8;
pub const __UINT_LEAST64_FMTu__ = c"llu";
pub const __ORDER_PDP_ENDIAN__ = 3412;
pub const __INT_FAST64_FMTd__ = c"lld";
pub const __CLANG_ATOMIC_LONG_LOCK_FREE = 2;
pub const __cpp_ref_qualifiers = c_long(200710);
pub const __INT16_TYPE__ = short;
pub const _INTEGRAL_MAX_BITS = 64;
pub const __SSE2_MATH__ = 1;
pub const __FLT_MANT_DIG__ = 24;
pub const __UINT_FAST64_FMTx__ = c"llx";
pub const __INT_FAST8_MAX__ = 127;
pub const __INTPTR_FMTd__ = c"lld";
pub const __SIZE_WIDTH__ = 64;
pub const __UINT_LEAST8_FMTx__ = c"hhx";
pub const __INT_LEAST64_FMTi__ = c"lli";
pub const __INT_FAST16_MAX__ = 32767;
pub const __INTPTR_MAX__ = c_longlong(9223372036854775807);
pub const __WINT_TYPE__ = int;
pub const __CLANG_ATOMIC_CHAR16_T_LOCK_FREE = 2;
pub const __UINT64_FMTu__ = c"llu";
pub const __BYTE_ORDER__ = __ORDER_LITTLE_ENDIAN__;
pub const __SSE2__ = 1;
pub const __cpp_generic_lambdas = c_long(201304);
pub const __INT_MAX__ = 2147483647;
pub const __INTMAX_FMTi__ = c"lli";
pub const __DBL_DENORM_MIN__ = 0.000000;
pub const __cpp_threadsafe_static_init = c_long(200806);
pub const __clang_major__ = 7;
pub const __FLT16_MANT_DIG__ = 11;
pub const __UINT32_MAX__ = c_uint(4294967295);
pub const __FLT_DENORM_MIN__ = 0.000000;
pub const __DBL_MAX_EXP__ = 1024;
pub const __INT8_FMTi__ = c"hhi";
pub const __UINT_LEAST16_MAX__ = 65535;
pub const __LDBL_HAS_DENORM__ = 1;
pub const __FLT16_MIN_10_EXP__ = -13;
pub const _RVALUE_REFERENCES_V2_SUPPORTED = 1;
pub const __LDBL_HAS_QUIET_NAN__ = 1;
pub const _WCHAR_T_DEFINED = 1;
pub const __UINT_FAST8_MAX__ = 255;
pub const __DBL_MIN_10_EXP__ = -307;
pub const __UINT8_FMTu__ = c"hhu";
pub const __INT_FAST64_MAX__ = c_longlong(9223372036854775807);
pub const __UINT16_FMTu__ = c"hu";
pub const __ATOMIC_SEQ_CST = 5;
pub const __SIZE_FMTu__ = c"llu";
pub const __LDBL_MIN_EXP__ = -1021;
pub const __UINT_FAST32_FMTu__ = c"u";
pub const __clang_patchlevel__ = 0;
pub const __cpp_rvalue_references = c_long(200610);
pub const __SIZEOF_LONG_LONG__ = 8;
pub const __FXSR__ = 1;
pub const __UINT8_MAX__ = 255;
pub const __WCHAR_UNSIGNED__ = 1;
pub const __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 = 1;
pub const __UINT32_FMTx__ = c"x";
pub const __UINT16_FMTo__ = c"ho";
pub const __OPENCL_MEMORY_SCOPE_DEVICE = 2;
pub const __UINT32_FMTu__ = c"u";
pub const __SIZEOF_POINTER__ = 8;
pub const __SIZE_MAX__ = c_ulonglong(18446744073709551615);
pub const _CPPUNWIND = 1;
pub const __cpp_variable_templates = c_long(201304);
pub const __INT_FAST16_FMTd__ = c"hd";
pub const __UINT_LEAST32_FMTu__ = c"u";
pub const __FLT_MAX__ = 340282346999999984391321947108527833088.000000;
pub const __k8__ = 1;
pub const __ATOMIC_CONSUME = 1;
pub const __tune_k8__ = 1;
pub const __x86_64__ = 1;
pub const __LDBL_HAS_INFINITY__ = 1;
pub const __UINTMAX_FMTx__ = c"llx";
pub const __UINT64_C_SUFFIX__ = ULL;
pub const __FLT_MIN_10_EXP__ = -37;
pub const __INT_LEAST16_MAX__ = 32767;
pub const __cpp_decltype_auto = c_long(201304);
pub const __UINT32_FMTo__ = c"o";
pub const __UINTPTR_FMTo__ = c"llo";
pub const __INT_LEAST16_FMTd__ = c"hd";
pub const __UINTPTR_FMTx__ = c"llx";
pub const __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 = 1;
pub const __INT_LEAST64_FMTd__ = c"lld";
pub const __INT_LEAST16_TYPE__ = short;
pub const _NATIVE_WCHAR_T_DEFINED = 1;
pub const __ORDER_BIG_ENDIAN__ = 4321;
pub const __LDBL_MIN_10_EXP__ = -307;
pub const __INT_LEAST8_MAX__ = 127;
pub const __SIZEOF_INT__ = 4;
pub const __cpp_initializer_lists = c_long(200806);
pub const __amd64 = 1;
pub const __OBJC_BOOL_IS_BOOL = 0;
pub const __LDBL_MAX_10_EXP__ = 308;
pub const __SIZEOF_INT128__ = 16;
pub const __UINT_FAST8_FMTx__ = c"hhx";
pub const __cpp_alias_templates = c_long(200704);
pub const __cpp_binary_literals = c_long(201304);
pub const __UINT16_FMTx__ = c"hx";
pub const __UINTPTR_FMTu__ = c"llu";
pub const __UINT_LEAST16_FMTX__ = c"hX";
pub const __amd64__ = 1;
pub const __UINT_FAST32_FMTo__ = c"o";
pub const __clang__ = 1;
pub const __PTRDIFF_FMTi__ = c"lli";
pub const __LDBL_DIG__ = 15;
pub const __UINT64_FMTo__ = c"llo";
pub const __INT_FAST32_FMTd__ = c"d";
pub const __ATOMIC_ACQ_REL = 4;
pub const _MSVC_LANG = c_long(201402);
pub const __cpp_raw_strings = c_long(200710);
pub const __LONG_LONG_MAX__ = c_longlong(9223372036854775807);
pub const __OPENCL_MEMORY_SCOPE_SUB_GROUP = 4;
pub const __INTMAX_MAX__ = c_longlong(9223372036854775807);
pub const __cpp_static_assert = 200410;
pub const __UINT_LEAST32_FMTx__ = c"x";
pub const __WCHAR_MAX__ = 65535;
pub const __INT64_MAX__ = c_longlong(9223372036854775807);
pub const __CLANG_ATOMIC_CHAR32_T_LOCK_FREE = 2;
pub const __INT_LEAST64_MAX__ = c_longlong(9223372036854775807);
pub const __UINTMAX_FMTX__ = c"llX";
pub const _M_X64 = 100;
pub const __OPENCL_MEMORY_SCOPE_WORK_ITEM = 0;
pub const __FLT_HAS_DENORM__ = 1;
pub const _CPPRTTI = 1;
pub const __DECIMAL_DIG__ = __LDBL_DECIMAL_DIG__;
pub const __INT32_FMTi__ = c"i";
pub const __DBL_HAS_INFINITY__ = 1;
pub const __FINITE_MATH_ONLY__ = 0; |
Since we're testing translate-c with an intermediate Is translating C++ officially supported ? |
Sorry for the delayed response. It's a good question, whether c++ mode is supported at all. I don't have an answer at this time |
…empty until ziglang#646 is fixed.
@andrewrk The crash occurred when at some point in printing translated Zig code, we were dereferencing a null Note that the distinction between "C mode" and "C++11 mode" is that if not in C++11 mode, clang doesn't evaluate the initializers of the arrays. However as you noted by opening an issue on the subject, this is a hack in their implementation and shouldn't be the case. I assume they handle these initializers later, for example when generating llvm IR. So, in the context of Zig, ideally the initializers of arrays should not be tied to the input code being C or C++, that's just a side effect. This PR fixes the crash and other bugs (listed in commits), and add tests which we unfortunately can't enable yet because of clang. I think merging this is desirable because we want to be able to translate array initializers regardless of clang not doing everything it should. Then we would have to patch it, or find a workaround to access the missing information. |
Fixes #1743.