verify-prefixes.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #if GC
  2. # define GCONST const
  3. #else
  4. # define GCONST
  5. #endif
  6. // gconst-note@8 {{variable 'glb' declared const here}}
  7. GCONST int glb = 5;
  8. // Check various correct prefix spellings and combinations.
  9. //
  10. // RUN: %clang_cc1 -DGC -verify=gconst %s
  11. // RUN: %clang_cc1 -Wcast-qual -DLC -verify=lconst %s
  12. // RUN: %clang_cc1 -DSC -verify=expected %s
  13. // RUN: %clang_cc1 -DSC -verify %s
  14. // RUN: %clang_cc1 -DSC -verify -verify %s
  15. // RUN: %clang_cc1 -verify=nconst %s
  16. // RUN: %clang_cc1 -verify=n-const %s
  17. // RUN: %clang_cc1 -verify=n_const %s
  18. // RUN: %clang_cc1 -verify=NConst %s
  19. // RUN: %clang_cc1 -verify=NConst2 %s
  20. // RUN: %clang_cc1 -Wcast-qual -DGC -DLC -verify=gconst,lconst %s
  21. // RUN: %clang_cc1 -Wcast-qual -DGC -DLC -DSC -verify=gconst,lconst,expected %s
  22. // RUN: %clang_cc1 -Wcast-qual -DGC -DLC -verify=gconst -verify=lconst %s
  23. // RUN: %clang_cc1 -Wcast-qual -DGC -DLC -DSC -verify=gconst,lconst -verify %s
  24. // RUN: %clang_cc1 -DGC -DSC -verify -verify=gconst -verify %s
  25. //
  26. // Duplicate prefixes.
  27. // RUN: %clang_cc1 -Wcast-qual -DGC -DLC -verify=gconst,lconst,gconst %s
  28. // RUN: %clang_cc1 -DGC -verify=gconst -verify=gconst,gconst %s
  29. // RUN: %clang_cc1 -DSC -verify=expected -verify=expected %s
  30. // RUN: %clang_cc1 -DSC -verify -verify=expected %s
  31. //
  32. // Various tortured cases: multiple directives with different prefixes per
  33. // line, prefixes used as comments, prefixes prefixing prefixes, and prefixes
  34. // with special suffixes.
  35. // RUN: %clang_cc1 -Wcast-qual -DLC -verify=foo %s
  36. // RUN: %clang_cc1 -DSC -verify=bar %s
  37. // RUN: %clang_cc1 -Wcast-qual -DLC -DSC -verify=foo,bar %s
  38. // RUN: %clang_cc1 -Wcast-qual -DLC -DSC -verify=bar,foo %s
  39. // RUN: %clang_cc1 -DSC -verify=foo-bar %s
  40. // RUN: %clang_cc1 -Wcast-qual -DLC -verify=bar-foo %s
  41. // RUN: %clang_cc1 -Wcast-qual -DLC -DSC -verify=foo,foo-bar %s
  42. // RUN: %clang_cc1 -Wcast-qual -DLC -DSC -verify=foo-bar,foo %s
  43. // RUN: %clang_cc1 -Wcast-qual -DLC -DSC -verify=bar,bar-foo %s
  44. // RUN: %clang_cc1 -Wcast-qual -DLC -DSC -verify=bar-foo,bar %s
  45. // RUN: %clang_cc1 -Wcast-qual -DLC -DSC -verify=foo-bar,bar-foo %s
  46. // RUN: %clang_cc1 -DSC -verify=foo-warning %s
  47. // RUN: %clang_cc1 -Wcast-qual -DLC -verify=bar-warning-re %s
  48. // RUN: %clang_cc1 -Wcast-qual -DLC -DSC -verify=foo,foo-warning %s
  49. // RUN: %clang_cc1 -Wcast-qual -DLC -DSC -verify=foo-warning,foo %s
  50. // RUN: %clang_cc1 -Wcast-qual -DLC -DSC -verify=bar,bar-warning-re %s
  51. // RUN: %clang_cc1 -Wcast-qual -DLC -DSC -verify=bar-warning-re,bar %s
  52. // Check invalid prefixes. Check that there's no additional output, which
  53. // might indicate that diagnostic verification became enabled even though it
  54. // was requested incorrectly. Check that prefixes are reported in command-line
  55. // order.
  56. //
  57. // RUN: not %clang_cc1 -verify=5abc,-xy,foo,_k -verify='#a,b$' %s 2> %t
  58. // RUN: FileCheck --check-prefixes=ERR %s < %t
  59. //
  60. // ERR-NOT: {{.}}
  61. // ERR: error: invalid value '5abc' in '-verify='
  62. // ERR-NEXT: note: -verify prefixes must start with a letter and contain only alphanumeric characters, hyphens, and underscores
  63. // ERR-NEXT: error: invalid value '-xy' in '-verify='
  64. // ERR-NEXT: note: -verify prefixes must start with a letter and contain only alphanumeric characters, hyphens, and underscores
  65. // ERR-NEXT: error: invalid value '_k' in '-verify='
  66. // ERR-NEXT: note: -verify prefixes must start with a letter and contain only alphanumeric characters, hyphens, and underscores
  67. // ERR-NEXT: error: invalid value '#a' in '-verify='
  68. // ERR-NEXT: note: -verify prefixes must start with a letter and contain only alphanumeric characters, hyphens, and underscores
  69. // ERR-NEXT: error: invalid value 'b$' in '-verify='
  70. // ERR-NEXT: note: -verify prefixes must start with a letter and contain only alphanumeric characters, hyphens, and underscores
  71. // ERR-NOT: {{.}}
  72. // Check that our test code actually has expected diagnostics when there's no
  73. // -verify.
  74. //
  75. // RUN: not %clang_cc1 -Wcast-qual -DGC -DLC -DSC %s 2> %t
  76. // RUN: FileCheck --check-prefix=ALL %s < %t
  77. //
  78. // ALL: cannot assign to variable 'glb' with const-qualified type 'const int'
  79. // ALL: variable 'glb' declared const here
  80. // ALL: cast from 'const int *' to 'int *' drops const qualifier
  81. // ALL: initializing 'int *' with an expression of type 'const int *' discards qualifiers
  82. #if LC
  83. # define LCONST const
  84. #else
  85. # define LCONST
  86. #endif
  87. #if SC
  88. # define SCONST const
  89. #else
  90. # define SCONST
  91. #endif
  92. void foo() {
  93. LCONST int loc = 5;
  94. SCONST static int sta = 5;
  95. // We don't actually expect 1-2 occurrences of this error. We're just
  96. // checking the parsing.
  97. glb = 6; // gconst-error1-2 {{cannot assign to variable 'glb' with const-qualified type 'const int'}}
  98. *(int*)(&loc) = 6; // lconst-warning {{cast from 'const int *' to 'int *' drops const qualifier}}
  99. ; // Code, comments, and many directives with different prefixes per line, including cases where some prefixes (foo and bar) prefix others (such as foo-bar and bar-foo), such that some prefixes appear as normal comments and some have special suffixes (-warning and -re): foo-warning@-1 {{cast from 'const int *' to 'int *' drops const qualifier}} foo-bar-warning@+1 {{initializing 'int *' with an expression of type 'const int *' discards qualifiers}} foo-warning-warning@+1 {{initializing 'int *' with an expression of type 'const int *' discards qualifiers}} bar-warning-re-warning@-1 {{cast from 'const int *' to 'int *' drops const qualifier}} bar-foo-warning@-1 {{cast from 'const int *' to 'int *' drops const qualifier}} bar-warning@+1 {{initializing 'int *' with an expression of type 'const int *' discards qualifiers}}
  100. int *p = &sta; // expected-warning {{initializing 'int *' with an expression of type 'const int *' discards qualifiers}}
  101. }
  102. // nconst-no-diagnostics
  103. // n-const-no-diagnostics
  104. // n_const-no-diagnostics
  105. // NConst-no-diagnostics
  106. // NConst2-no-diagnostics