--- /dev/null
+// RUN: %clang_cc1 -emit-llvm %s -o /dev/null
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/types.h>
+
+int
+main(int argc, char** argv)
+{
+ char c1;
+ short s1, ssf1, ssd1;
+ unsigned char ubs0;
+ signed char bs0;
+ unsigned char ubc0, uc2;
+ unsigned short us2, usf1, usd1;
+ int ic3, is3, sif1, sid1;
+ unsigned int uic4, uis4, uif1, uid1;
+ long slf1, sld1;
+ unsigned long ulf1, uld1;
+ float f1;
+ double d1;
+
+ /* Test integer to integer conversions */
+
+ c1 = (char) (argc >= 2)? atoi(argv[1]) : 0xff64; /* 100 = 'd' */
+ s1 = (short) (argc >= 3)? atoi(argv[2]) : -769; /* 0xf7ff = -769 */
+
+ ubc0 = (unsigned char) c1; /* 100 = 'd' */
+ ubs0 = (unsigned char) s1; /* 0xff = 255 */
+ bs0 = (signed char) s1; /* 0xff = -1 */
+
+ uc2 = (unsigned char) c1; /* 100 = 'd' */
+ us2 = (unsigned short) s1; /* 0xf7ff = 64767 */
+
+ ic3 = (int) c1; /* 100 = 'd' */
+ is3 = (int) s1; /* 0xfffff7ff = -769 */
+
+ uic4 = (unsigned int) c1; /* 100 = 'd' */
+ uis4 = (unsigned int) s1; /* 0xfffff7ff = 4294966527 */
+
+ printf("ubc0 = '%c'\n", ubc0);
+ printf("ubs0 = %u\n", ubs0);
+ printf("bs0 = %d\n", bs0);
+ printf("c1 = '%c'\n", c1);
+ printf("s1 = %d\n", s1);
+ printf("uc2 = '%c'\n", uc2);
+ printf("us2 = %u\n", us2);
+ printf("ic3 = '%c'\n", ic3);
+ printf("is3 = %d\n", is3);
+ printf("uic4 = '%c'\n", uic4);
+ printf("uis4 = %u\n", uis4);
+
+ /* Test floating-point to integer conversions */
+ f1 = (float) (argc >= 4)? atof(argv[3]) : 1.0;
+ d1 = (argc >= 5)? atof(argv[4]) : 2.0;
+
+ usf1 = (unsigned short) f1;
+ usd1 = (unsigned short) d1;
+ uif1 = (unsigned int) f1;
+ uid1 = (unsigned int) d1;
+ ulf1 = (unsigned long) f1;
+ uld1 = (unsigned long) d1;
+
+ ssf1 = (short) f1;
+ ssd1 = (short) d1;
+ sif1 = (int) f1;
+ sid1 = (int) d1;
+ slf1 = (long) f1;
+ sld1 = (long) d1;
+
+ printf("usf1 = %u\n", usf1);
+ printf("usd1 = %u\n", usd1);
+ printf("uif1 = %u\n", uif1);
+ printf("uid1 = %u\n", uid1);
+ printf("ulf1 = %u\n", ulf1);
+ printf("uld1 = %u\n", uld1);
+
+ printf("ssf1 = %d\n", ssf1);
+ printf("ssd1 = %d\n", ssd1);
+ printf("sif1 = %d\n", sif1);
+ printf("sid1 = %d\n", sid1);
+ printf("slf1 = %d\n", slf1);
+ printf("sld1 = %d\n", sld1);
+
+ return 0;
+}
--- /dev/null
+// Test frontend handling of __sync builtins.
+// Modified from a gcc testcase.
+// RUN: %clang_cc1 -emit-llvm %s -o - | grep atomic | count 129
+// RUN: %clang_cc1 -emit-llvm %s -o - | grep p0i8 | count 43
+// RUN: %clang_cc1 -emit-llvm %s -o - | grep p0i16 | count 43
+// RUN: %clang_cc1 -emit-llvm %s -o - | grep p0i32 | count 43
+// RUN: %clang_cc1 -emit-llvm %s -o - | grep volatile | count 6
+
+// Currently this is implemented only for Alpha, X86, PowerPC.
+// Add your target here if it doesn't work.
+// This version of the test does not include long long.
+// XFAIL: sparc,arm
+
+signed char sc;
+unsigned char uc;
+signed short ss;
+unsigned short us;
+signed int si;
+unsigned int ui;
+
+void test_op_ignore (void)
+{
+ (void) __sync_fetch_and_add (&sc, 1);
+ (void) __sync_fetch_and_add (&uc, 1);
+ (void) __sync_fetch_and_add (&ss, 1);
+ (void) __sync_fetch_and_add (&us, 1);
+ (void) __sync_fetch_and_add (&si, 1);
+ (void) __sync_fetch_and_add (&ui, 1);
+
+ (void) __sync_fetch_and_sub (&sc, 1);
+ (void) __sync_fetch_and_sub (&uc, 1);
+ (void) __sync_fetch_and_sub (&ss, 1);
+ (void) __sync_fetch_and_sub (&us, 1);
+ (void) __sync_fetch_and_sub (&si, 1);
+ (void) __sync_fetch_and_sub (&ui, 1);
+
+ (void) __sync_fetch_and_or (&sc, 1);
+ (void) __sync_fetch_and_or (&uc, 1);
+ (void) __sync_fetch_and_or (&ss, 1);
+ (void) __sync_fetch_and_or (&us, 1);
+ (void) __sync_fetch_and_or (&si, 1);
+ (void) __sync_fetch_and_or (&ui, 1);
+
+ (void) __sync_fetch_and_xor (&sc, 1);
+ (void) __sync_fetch_and_xor (&uc, 1);
+ (void) __sync_fetch_and_xor (&ss, 1);
+ (void) __sync_fetch_and_xor (&us, 1);
+ (void) __sync_fetch_and_xor (&si, 1);
+ (void) __sync_fetch_and_xor (&ui, 1);
+
+ (void) __sync_fetch_and_and (&sc, 1);
+ (void) __sync_fetch_and_and (&uc, 1);
+ (void) __sync_fetch_and_and (&ss, 1);
+ (void) __sync_fetch_and_and (&us, 1);
+ (void) __sync_fetch_and_and (&si, 1);
+ (void) __sync_fetch_and_and (&ui, 1);
+
+}
+
+void test_fetch_and_op (void)
+{
+ sc = __sync_fetch_and_add (&sc, 11);
+ uc = __sync_fetch_and_add (&uc, 11);
+ ss = __sync_fetch_and_add (&ss, 11);
+ us = __sync_fetch_and_add (&us, 11);
+ si = __sync_fetch_and_add (&si, 11);
+ ui = __sync_fetch_and_add (&ui, 11);
+
+ sc = __sync_fetch_and_sub (&sc, 11);
+ uc = __sync_fetch_and_sub (&uc, 11);
+ ss = __sync_fetch_and_sub (&ss, 11);
+ us = __sync_fetch_and_sub (&us, 11);
+ si = __sync_fetch_and_sub (&si, 11);
+ ui = __sync_fetch_and_sub (&ui, 11);
+
+ sc = __sync_fetch_and_or (&sc, 11);
+ uc = __sync_fetch_and_or (&uc, 11);
+ ss = __sync_fetch_and_or (&ss, 11);
+ us = __sync_fetch_and_or (&us, 11);
+ si = __sync_fetch_and_or (&si, 11);
+ ui = __sync_fetch_and_or (&ui, 11);
+
+ sc = __sync_fetch_and_xor (&sc, 11);
+ uc = __sync_fetch_and_xor (&uc, 11);
+ ss = __sync_fetch_and_xor (&ss, 11);
+ us = __sync_fetch_and_xor (&us, 11);
+ si = __sync_fetch_and_xor (&si, 11);
+ ui = __sync_fetch_and_xor (&ui, 11);
+
+ sc = __sync_fetch_and_and (&sc, 11);
+ uc = __sync_fetch_and_and (&uc, 11);
+ ss = __sync_fetch_and_and (&ss, 11);
+ us = __sync_fetch_and_and (&us, 11);
+ si = __sync_fetch_and_and (&si, 11);
+ ui = __sync_fetch_and_and (&ui, 11);
+
+}
+
+void test_op_and_fetch (void)
+{
+ sc = __sync_add_and_fetch (&sc, uc);
+ uc = __sync_add_and_fetch (&uc, uc);
+ ss = __sync_add_and_fetch (&ss, uc);
+ us = __sync_add_and_fetch (&us, uc);
+ si = __sync_add_and_fetch (&si, uc);
+ ui = __sync_add_and_fetch (&ui, uc);
+
+ sc = __sync_sub_and_fetch (&sc, uc);
+ uc = __sync_sub_and_fetch (&uc, uc);
+ ss = __sync_sub_and_fetch (&ss, uc);
+ us = __sync_sub_and_fetch (&us, uc);
+ si = __sync_sub_and_fetch (&si, uc);
+ ui = __sync_sub_and_fetch (&ui, uc);
+
+ sc = __sync_or_and_fetch (&sc, uc);
+ uc = __sync_or_and_fetch (&uc, uc);
+ ss = __sync_or_and_fetch (&ss, uc);
+ us = __sync_or_and_fetch (&us, uc);
+ si = __sync_or_and_fetch (&si, uc);
+ ui = __sync_or_and_fetch (&ui, uc);
+
+ sc = __sync_xor_and_fetch (&sc, uc);
+ uc = __sync_xor_and_fetch (&uc, uc);
+ ss = __sync_xor_and_fetch (&ss, uc);
+ us = __sync_xor_and_fetch (&us, uc);
+ si = __sync_xor_and_fetch (&si, uc);
+ ui = __sync_xor_and_fetch (&ui, uc);
+
+ sc = __sync_and_and_fetch (&sc, uc);
+ uc = __sync_and_and_fetch (&uc, uc);
+ ss = __sync_and_and_fetch (&ss, uc);
+ us = __sync_and_and_fetch (&us, uc);
+ si = __sync_and_and_fetch (&si, uc);
+ ui = __sync_and_and_fetch (&ui, uc);
+
+}
+
+void test_compare_and_swap (void)
+{
+ sc = __sync_val_compare_and_swap (&sc, uc, sc);
+ uc = __sync_val_compare_and_swap (&uc, uc, sc);
+ ss = __sync_val_compare_and_swap (&ss, uc, sc);
+ us = __sync_val_compare_and_swap (&us, uc, sc);
+ si = __sync_val_compare_and_swap (&si, uc, sc);
+ ui = __sync_val_compare_and_swap (&ui, uc, sc);
+
+ ui = __sync_bool_compare_and_swap (&sc, uc, sc);
+ ui = __sync_bool_compare_and_swap (&uc, uc, sc);
+ ui = __sync_bool_compare_and_swap (&ss, uc, sc);
+ ui = __sync_bool_compare_and_swap (&us, uc, sc);
+ ui = __sync_bool_compare_and_swap (&si, uc, sc);
+ ui = __sync_bool_compare_and_swap (&ui, uc, sc);
+}
+
+void test_lock (void)
+{
+ sc = __sync_lock_test_and_set (&sc, 1);
+ uc = __sync_lock_test_and_set (&uc, 1);
+ ss = __sync_lock_test_and_set (&ss, 1);
+ us = __sync_lock_test_and_set (&us, 1);
+ si = __sync_lock_test_and_set (&si, 1);
+ ui = __sync_lock_test_and_set (&ui, 1);
+
+ __sync_synchronize ();
+
+ __sync_lock_release (&sc);
+ __sync_lock_release (&uc);
+ __sync_lock_release (&ss);
+ __sync_lock_release (&us);
+ __sync_lock_release (&si);
+ __sync_lock_release (&ui);
+}