builtins.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // RUN: %clang_cc1 -std=c++11 -triple x86_64-linux-gnu -ffreestanding -verify %s
  2. // RUN: %clang_cc1 -std=c++11 -triple i686-pc-linux-gnu -ffreestanding -verify %s
  3. // RUN: %clang_cc1 -std=c++11 -triple avr-unknown-unknown -ffreestanding -verify %s
  4. // expected-no-diagnostics
  5. // Test that checks that the builtins return the same type as the stdint.h type
  6. // withe the same witdh. This is done by first declaring a variable of a stdint
  7. // type of the correct width and the redeclaring the variable with the type that
  8. // the builting return. If the types are different you should the an error from
  9. // clang of the form:
  10. // "redefinition of '<varname>' with a different type: '<type1>' vs '<type2>'
  11. // (with gcc you get an error message
  12. // "conflicting declaration '<type> <varname>'").
  13. #include <stdint.h>
  14. extern uint16_t bswap16;
  15. decltype(__builtin_bswap16(0)) bswap16 = 42;
  16. extern uint32_t bswap32;
  17. decltype(__builtin_bswap32(0)) bswap32 = 42;
  18. extern uint64_t bswap64;
  19. decltype(__builtin_bswap64(0)) bswap64 = 42;
  20. #ifdef __clang__
  21. extern uint8_t bitrev8;
  22. decltype(__builtin_bitreverse8(0)) bitrev8 = 42;
  23. extern uint16_t bitrev16;
  24. decltype(__builtin_bitreverse16(0)) bitrev16 = 42;
  25. extern uint32_t bitrev32;
  26. decltype(__builtin_bitreverse32(0)) bitrev32 = 42;
  27. extern uint64_t bitrev64;
  28. decltype(__builtin_bitreverse64(0)) bitrev64 = 42;
  29. extern uint8_t rotl8;
  30. decltype(__builtin_rotateleft8(0,0)) rotl8 = 42;
  31. extern uint16_t rotl16;
  32. decltype(__builtin_rotateleft16(0,0)) rotl16 = 42;
  33. extern uint32_t rotl32;
  34. decltype(__builtin_rotateleft32(0,0)) rotl32 = 42;
  35. extern uint64_t rotl64;
  36. decltype(__builtin_rotateleft64(0,0)) rotl64 = 42;
  37. extern uint8_t rotr8;
  38. decltype(__builtin_rotateright8(0,0)) rotr8 = 42;
  39. extern uint16_t rotr16;
  40. decltype(__builtin_rotateright16(0,0)) rotr16 = 42;
  41. extern uint32_t rotr32;
  42. decltype(__builtin_rotateright32(0,0)) rotr32 = 42;
  43. extern uint64_t rotr64;
  44. decltype(__builtin_rotateright64(0,0)) rotr64 = 42;
  45. #endif