brintos

brintos / llvm-project-archived public Read only

0
0
Text · 7.5 KiB · 0db82ef Raw
265 lines · c
1// RUN: %clang_analyze_cc1 -analyzer-checker=debug.DumpCFG -triple x86_64-apple-darwin12 -Wno-error=invalid-gnu-asm-cast %s > %t 2>&12// RUN: FileCheck --input-file=%t --check-prefix=CHECK %s3 4// RUN: %clang_analyze_cc1 -analyzer-checker=debug.DumpCFG -triple x86_64-apple-darwin12 -std=c2y -Wno-error=invalid-gnu-asm-cast %s > %t 2>&15// RUN: FileCheck --input-file=%t --check-prefixes=CHECK,SINCE-C26 %s6 7// This file is the C version of cfg.cpp.8// Tests that are C-specific should go into this file.9 10// CHECK-LABEL: void checkWrap(int i)11// CHECK: ENTRY12// CHECK-NEXT: Succs (1): B113// CHECK: [B1]14// CHECK: Succs (21): B2 B3 B4 B5 B6 B7 B8 B915// CHECK: B10 B11 B12 B13 B14 B15 B16 B17 B18 B1916// CHECK: B20 B21 B017// CHECK: [B0 (EXIT)]18// CHECK-NEXT: Preds (21): B2 B3 B4 B5 B6 B7 B8 B919// CHECK-NEXT: B10 B11 B12 B13 B14 B15 B16 B17 B18 B1920// CHECK-NEXT: B20 B21 B121void checkWrap(int i) {22  switch(i) {23    case 0: break;24    case 1: break;25    case 2: break;26    case 3: break;27    case 4: break;28    case 5: break;29    case 6: break;30    case 7: break;31    case 8: break;32    case 9: break;33    case 10: break;34    case 11: break;35    case 12: break;36    case 13: break;37    case 14: break;38    case 15: break;39    case 16: break;40    case 17: break;41    case 18: break;42    case 19: break;43  }44}45 46// CHECK-LABEL: void checkGCCAsmRValueOutput(void)47// CHECK: [B2 (ENTRY)]48// CHECK-NEXT: Succs (1): B149// CHECK: [B1]50// CHECK-NEXT:   1: int arg51// CHECK-NEXT:   2: arg52// CHECK-NEXT:   3: (int)[B1.2] (CStyleCastExpr, NoOp, int)53// CHECK-NEXT:   4: asm ("" : "=r" ([B1.3]));54// CHECK-NEXT:   5: arg55// CHECK-NEXT:   6: asm ("" : "=r" ([B1.5]));56void checkGCCAsmRValueOutput(void) {57  int arg;58  __asm__("" : "=r"((int)arg));  // rvalue output operand59  __asm__("" : "=r"(arg));       // lvalue output operand60}61 62// CHECK-LABEL: int overlap_compare(int x)63// CHECK: [B2]64// CHECK-NEXT:   1: 165// CHECK-NEXT:   2: return [B2.1];66// CHECK-NEXT:   Preds (1): B3(Unreachable)67// CHECK-NEXT:   Succs (1): B068// CHECK: [B3]69// CHECK-NEXT:   1: x70// CHECK-NEXT:   2: [B3.1] (ImplicitCastExpr, LValueToRValue, int)71// CHECK-NEXT:   3: 572// CHECK-NEXT:   4: [B3.2] > [B3.3]73// CHECK-NEXT:   T: if [B4.5] && [B3.4]74// CHECK-NEXT:   Preds (1): B475// CHECK-NEXT:   Succs (2): B2(Unreachable) B176int overlap_compare(int x) {77  if (x == -1 && x > 5)78    return 1;79 80  return 2;81}82 83// CHECK-LABEL: void vla_simple(int x)84// CHECK: [B1]85// CHECK-NEXT:   1: x86// CHECK-NEXT:   2: [B1.1] (ImplicitCastExpr, LValueToRValue, int)87// CHECK-NEXT:   3: int vla[x];88void vla_simple(int x) {89  int vla[x];90}91 92// CHECK-LABEL: void vla_typedef(int x)93// CHECK: [B1]94// CHECK-NEXT:   1: x95// CHECK-NEXT:   2: [B1.1] (ImplicitCastExpr, LValueToRValue, int)96// CHECK-NEXT:   3: typedef int VLA[x];97void vla_typedef(int x) {98  typedef int VLA[x];99}100 101// CHECK-LABEL: void vla_typedef_multi(int x, int y)102// CHECK:  [B1]103// CHECK-NEXT:   1: y104// CHECK-NEXT:   2: [B1.1] (ImplicitCastExpr, LValueToRValue, int)105// CHECK-NEXT:   3: x106// CHECK-NEXT:   4: [B1.3] (ImplicitCastExpr, LValueToRValue, int)107// CHECK-NEXT:   5: typedef int VLA[x][y];108void vla_typedef_multi(int x, int y) {109  typedef int VLA[x][y];110}111 112// CHECK-LABEL: void vla_type_indirect(int x)113// CHECK:  [B1]114// CHECK-NEXT:   1: int (*p_vla)[x];115// CHECK-NEXT:   2: void (*fp_vla)(int *);116void vla_type_indirect(int x) {117  // Should evaluate x118  // FIXME: does not work119  int (*p_vla)[x];120 121  // Do not evaluate x122  void (*fp_vla)(int[x]);123}124 125#if __STDC_VERSION__ >= 202400L // If C26 or above126// SINCE-C26:      int labeled_break_and_continue(int x)127// SINCE-C26-NEXT:  [B17 (ENTRY)]128// SINCE-C26-NEXT:    Succs (1): B2129// SINCE-C26-EMPTY:130// SINCE-C26-NEXT:  [B1]131// SINCE-C26-NEXT:    1: 0132// SINCE-C26-NEXT:    2: return [B1.1];133// SINCE-C26-NEXT:    Preds (1): B9134// SINCE-C26-NEXT:    Succs (1): B0135// SINCE-C26-EMPTY:136// SINCE-C26-NEXT:  [B2]137// SINCE-C26-NEXT:   a:138// SINCE-C26-NEXT:    1: x139// SINCE-C26-NEXT:    2: [B2.1] (ImplicitCastExpr, LValueToRValue, int)140// SINCE-C26-NEXT:    T: switch [B2.2]141// SINCE-C26-NEXT:    Preds (1): B17142// SINCE-C26-NEXT:    Succs (3): B9 B16 B8143// SINCE-C26-EMPTY:144// SINCE-C26-NEXT:  [B3]145// SINCE-C26-NEXT:    1: x146// SINCE-C26-NEXT:    2: [B3.1] (ImplicitCastExpr, LValueToRValue, int)147// SINCE-C26-NEXT:    3: 2148// SINCE-C26-NEXT:    4: [B3.2] + [B3.3]149// SINCE-C26-NEXT:    5: return [B3.4];150// SINCE-C26-NEXT:    Preds (3): B6 B7 B4151// SINCE-C26-NEXT:    Succs (1): B0152// SINCE-C26-EMPTY:153// SINCE-C26-NEXT:  [B4]154// SINCE-C26-NEXT:   c:155// SINCE-C26-NEXT:    1: x156// SINCE-C26-NEXT:    2: [B4.1] (ImplicitCastExpr, LValueToRValue, int)157// SINCE-C26-NEXT:    T: switch [B4.2]158// SINCE-C26-NEXT:    Preds (1): B8159// SINCE-C26-NEXT:    Succs (3): B6 B7 B3160// SINCE-C26-EMPTY:161// SINCE-C26-NEXT:  [B5]162// SINCE-C26-NEXT:    1: x163// SINCE-C26-NEXT:    2: [B5.1] (ImplicitCastExpr, LValueToRValue, int)164// SINCE-C26-NEXT:    3: 3165// SINCE-C26-NEXT:    4: [B5.2] + [B5.3]166// SINCE-C26-NEXT:    5: return [B5.4];167// SINCE-C26-NEXT:    Succs (1): B0168// SINCE-C26-EMPTY:169// SINCE-C26-NEXT:  [B6]170// SINCE-C26-NEXT:   case 30:171// SINCE-C26-NEXT:    T: break c;172// SINCE-C26-NEXT:    Preds (1): B4173// SINCE-C26-NEXT:    Succs (1): B3174// SINCE-C26-EMPTY:175// SINCE-C26-NEXT:  [B7]176// SINCE-C26-NEXT:   case 10:177// SINCE-C26-NEXT:    T: break a;178// SINCE-C26-NEXT:    Preds (1): B4179// SINCE-C26-NEXT:    Succs (1): B3180// SINCE-C26-EMPTY:181// SINCE-C26-NEXT:  [B8]182// SINCE-C26-NEXT:   default:183// SINCE-C26-NEXT:    Preds (1): B2184// SINCE-C26-NEXT:    Succs (1): B4185// SINCE-C26-EMPTY:186// SINCE-C26-NEXT:  [B9]187// SINCE-C26-NEXT:   case 2:188// SINCE-C26-NEXT:    T: break a;189// SINCE-C26-NEXT:    Preds (2): B2 B11190// SINCE-C26-NEXT:    Succs (1): B1191// SINCE-C26-EMPTY:192// SINCE-C26-NEXT:  [B10]193// SINCE-C26-NEXT:    1: 1194// SINCE-C26-NEXT:    T: do ... while [B10.1]195// SINCE-C26-NEXT:    Preds (1): B12196// SINCE-C26-NEXT:    Succs (2): B14 NULL197// SINCE-C26-EMPTY:198// SINCE-C26-NEXT:  [B11]199// SINCE-C26-NEXT:    T: break b;200// SINCE-C26-NEXT:    Preds (1): B13201// SINCE-C26-NEXT:    Succs (1): B9202// SINCE-C26-EMPTY:203// SINCE-C26-NEXT:  [B12]204// SINCE-C26-NEXT:    1: x205// SINCE-C26-NEXT:    2: ++[B12.1]206// SINCE-C26-NEXT:    T: continue b;207// SINCE-C26-NEXT:    Preds (1): B13208// SINCE-C26-NEXT:    Succs (1): B10209// SINCE-C26-EMPTY:210// SINCE-C26-NEXT:  [B13]211// SINCE-C26-NEXT:    1: x212// SINCE-C26-NEXT:    2: [B13.1] (ImplicitCastExpr, LValueToRValue, int)213// SINCE-C26-NEXT:    3: x214// SINCE-C26-NEXT:    4: [B13.3] (ImplicitCastExpr, LValueToRValue, int)215// SINCE-C26-NEXT:    5: [B13.2] * [B13.4]216// SINCE-C26-NEXT:    6: 100217// SINCE-C26-NEXT:    7: [B13.5] > [B13.6]218// SINCE-C26-NEXT:    T: if [B13.7]219// SINCE-C26-NEXT:    Preds (2): B14 B15220// SINCE-C26-NEXT:    Succs (2): B12 B11221// SINCE-C26-EMPTY:222// SINCE-C26-NEXT:  [B14]223// SINCE-C26-NEXT:    Preds (1): B10224// SINCE-C26-NEXT:    Succs (1): B13225// SINCE-C26-EMPTY:226// SINCE-C26-NEXT:  [B15]227// SINCE-C26-NEXT:   b:228// SINCE-C26-NEXT:    Preds (1): B16229// SINCE-C26-NEXT:    Succs (1): B13230// SINCE-C26-EMPTY:231// SINCE-C26-NEXT:  [B16]232// SINCE-C26-NEXT:   case 1:233// SINCE-C26-NEXT:    Preds (1): B2234// SINCE-C26-NEXT:    Succs (1): B15235// SINCE-C26-EMPTY:236// SINCE-C26-NEXT:  [B0 (EXIT)]237// SINCE-C26-NEXT:    Preds (3): B1 B3 B5238int labeled_break_and_continue(int x) {239  a: switch (x) {240    case 1:241      b: do {242        if (x * x > 100) {243          ++x;244          continue b;245        }246        break b;247      } while (1);248    case 2:249      break a;250    default:251    c: switch (x) {252      case 10:253        break a;254      case 30:255        break c;256      return x + 3; // dead code257    }258    return x + 2;259  }260 261  return 0;262}263 264#endif // __STDC_VERSION__ >= 202400L // If C26 or above265