cfg.cpp 17.9 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618
// RUN: %clang_analyze_cc1 -analyzer-checker=debug.DumpCFG -triple x86_64-apple-darwin12 -fheinous-gnu-extensions -std=c++11 -analyzer-config cfg-rich-constructors=false %s > %t 2>&1
// RUN: FileCheck --input-file=%t -check-prefixes=CHECK,WARNINGS %s
// RUN: %clang_analyze_cc1 -analyzer-checker=debug.DumpCFG -triple x86_64-apple-darwin12 -fheinous-gnu-extensions -std=c++11 -analyzer-config cfg-rich-constructors=true %s > %t 2>&1
// RUN: FileCheck --input-file=%t -check-prefixes=CHECK,ANALYZER %s

// This file tests how we construct two different flavors of the Clang CFG -
// the CFG used by the Sema analysis-based warnings and the CFG used by the
// static analyzer. The difference in the behavior is checked via FileCheck
// prefixes (WARNINGS and ANALYZER respectively). When introducing new analyzer
// flags, no new run lines should be added - just these flags would go to the
// respective line depending on where is it turned on and where is it turned
// off. Feel free to add tests that test only one of the CFG flavors if you're
// not sure how the other flavor is supposed to work in your case.

// CHECK-LABEL: void checkDeclStmts()
// CHECK: ENTRY
// CHECK-NEXT: Succs (1): B1
// CHECK: [B1]
// CHECK-NEXT:   1: int i;
// CHECK-NEXT:   2: int j;
// CHECK-NEXT:   3: 1
// CHECK-NEXT:   4: int k = 1;
// CHECK-NEXT:   5: int l;
// CHECK-NEXT:   6: 2
// CHECK-NEXT:   7: int m = 2;
// WARNINGS-NEXT: (CXXConstructExpr, struct standalone)
// ANALYZER-NEXT: (CXXConstructExpr, [B1.9], struct standalone)
// CHECK-NEXT:   9: struct standalone myStandalone;
// WARNINGS-NEXT: (CXXConstructExpr, struct (anonymous struct at {{.*}}))
// ANALYZER-NEXT: (CXXConstructExpr, [B1.11], struct (anonymous struct at {{.*}}))
// CHECK-NEXT:  11: struct (anonymous struct at {{.*}}) myAnon;
// WARNINGS-NEXT: (CXXConstructExpr, struct named)
// ANALYZER-NEXT: (CXXConstructExpr, [B1.13], struct named)
// CHECK-NEXT:  13: struct named myNamed;
// CHECK-NEXT:   Preds (1): B2
// CHECK-NEXT:   Succs (1): B0
void checkDeclStmts() {
  int i, j;
  int k = 1, l, m = 2;

  struct standalone { int x, y; };
  struct standalone myStandalone;

  struct { int x, y; } myAnon;

  struct named { int x, y; } myNamed;

  static_assert(1, "abc");
}

// CHECK-LABEL: void F(EmptyE e)
// CHECK: ENTRY
// CHECK-NEXT: Succs (1): B1
// CHECK: [B1]
// CHECK-NEXT:   1: e
// CHECK-NEXT:   2: [B1.1] (ImplicitCastExpr, LValueToRValue, enum EmptyE)
// CHECK-NEXT:   3: [B1.2] (ImplicitCastExpr, IntegralCast, int)
// CHECK-NEXT:   T: switch [B1.3]
// CHECK-NEXT:   Preds (1): B2
// CHECK-NEXT:   Succs (1): B0
// CHECK: [B0 (EXIT)]
// CHECK-NEXT:   Preds (1): B1
enum EmptyE {};
void F(EmptyE e) {
  switch (e) {}
}

// CHECK-LABEL: void testBuiltinSize()
// CHECK: ENTRY
// CHECK-NEXT: Succs (1): B1
// CHECK: [B1]
// CHECK-NEXT:   1: __builtin_object_size
// CHECK-NEXT:   2: [B1.1] (ImplicitCastExpr, BuiltinFnToFnPtr, unsigned long (*)(const void *, int) noexcept)
// CHECK-NEXT:   3: [B1.2](dummy(), 0)
// CHECK-NEXT:   4: (void)[B1.3] (CStyleCastExpr, ToVoid, void)
// CHECK-NEXT:   Preds (1): B2
// CHECK-NEXT:   Succs (1): B0
// CHECK: [B0 (EXIT)]
// CHECK-NEXT:   Preds (1): B1
void testBuiltinSize() {
  extern int *dummy();
  (void)__builtin_object_size(dummy(), 0);
}

class A {
public:
  A() {}
  ~A() {}
};

// CHECK-LABEL: void test_deletedtor()
// CHECK: [B2 (ENTRY)]
// CHECK-NEXT:   Succs (1): B1
// CHECK: [B1]
// CHECK-NEXT:   1:  CFGNewAllocator(A *)
// WARNINGS-NEXT:   2:  (CXXConstructExpr, class A)
// ANALYZER-NEXT:   2:  (CXXConstructExpr, [B1.3], class A)
// CHECK-NEXT:   3: new A([B1.2])
// CHECK-NEXT:   4: A *a = new A();
// CHECK-NEXT:   5: a
// CHECK-NEXT:   6: [B1.5] (ImplicitCastExpr, LValueToRValue, class A *)
// CHECK-NEXT:   7: [B1.6]->~A() (Implicit destructor)
// CHECK-NEXT:   8: delete [B1.6]
// CHECK-NEXT:   Preds (1): B2
// CHECK-NEXT:   Succs (1): B0
// CHECK: [B0 (EXIT)]
// CHECK-NEXT:   Preds (1): B1
void test_deletedtor() {
  A *a = new A();
  delete a;
}

// CHECK-LABEL: void test_deleteArraydtor()
// CHECK: [B2 (ENTRY)]
// CHECK-NEXT:   Succs (1): B1
// CHECK: [B1]
// CHECK-NEXT:   1: 5
// CHECK-NEXT:   2: CFGNewAllocator(A *)
// WARNINGS-NEXT:   3:  (CXXConstructExpr, class A [5])
// ANALYZER-NEXT:   3:  (CXXConstructExpr, [B1.4], class A [5])
// CHECK-NEXT:   4: new A {{\[\[}}B1.1]]
// CHECK-NEXT:   5: A *a = new A [5];
// CHECK-NEXT:   6: a
// CHECK-NEXT:   7: [B1.6] (ImplicitCastExpr, LValueToRValue, class A *)
// CHECK-NEXT:   8: [B1.7]->~A() (Implicit destructor)
// CHECK-NEXT:   9: delete [] [B1.7]
// CHECK-NEXT:   Preds (1): B2
// CHECK-NEXT:   Succs (1): B0
// CHECK: [B0 (EXIT)]
// CHECK-NEXT:   Preds (1): B1
void test_deleteArraydtor() {
  A *a = new A[5];
  delete[] a;
}


namespace NoReturnSingleSuccessor {
  struct A {
    A();
    ~A();
  };

  struct B : public A {
    B();
    ~B() __attribute__((noreturn));
  };

// CHECK-LABEL: int test1(int *x)
// CHECK: 1: 1
// CHECK-NEXT: 2: return
// CHECK-NEXT: ~NoReturnSingleSuccessor::B() (Implicit destructor)
// CHECK-NEXT: Preds (1)
// CHECK-NEXT: Succs (1): B0
  int test1(int *x) {
    B b;
    if (x)
      return 1;
  }

// CHECK-LABEL: int test2(int *x)
// CHECK: 1: 1
// CHECK-NEXT: 2: return
// CHECK-NEXT: destructor
// CHECK-NEXT: Preds (1)
// CHECK-NEXT: Succs (1): B0
  int test2(int *x) {
    const A& a = B();
    if (x)
      return 1;
  }
}

// Test CFG support for "extending" an enum.
// CHECK-LABEL: int test_enum_with_extension(enum MyEnum value)
// CHECK:  [B7 (ENTRY)]
// CHECK-NEXT:    Succs (1): B2
// CHECK:  [B1]
// CHECK-NEXT:    1: x
// CHECK-NEXT:    2: [B1.1] (ImplicitCastExpr, LValueToRValue, int)
// CHECK-NEXT:    3: return [B1.2];
// CHECK-NEXT:    Preds (5): B3 B4 B5 B6 B2(Unreachable)
// CHECK-NEXT:    Succs (1): B0
// CHECK:  [B2]
// CHECK-NEXT:    1: 0
// CHECK-NEXT:    2: int x = 0;
// CHECK-NEXT:    3: value
// CHECK-NEXT:    4: [B2.3] (ImplicitCastExpr, LValueToRValue, enum MyEnum)
// CHECK-NEXT:    5: [B2.4] (ImplicitCastExpr, IntegralCast, int)
// CHECK-NEXT:    T: switch [B2.5]
// CHECK-NEXT:    Preds (1): B7
// CHECK-NEXT:    Succs (5): B3 B4 B5 B6 B1(Unreachable)
// CHECK:  [B3]
// CHECK-NEXT:   case D:
// CHECK-NEXT:    1: 4
// CHECK-NEXT:    2: x
// CHECK-NEXT:    3: [B3.2] = [B3.1]
// CHECK-NEXT:    T: break;
// CHECK-NEXT:    Preds (1): B2
// CHECK-NEXT:    Succs (1): B1
// CHECK:  [B4]
// CHECK-NEXT:   case C:
// CHECK-NEXT:    1: 3
// CHECK-NEXT:    2: x
// CHECK-NEXT:    3: [B4.2] = [B4.1]
// CHECK-NEXT:    T: break;
// CHECK-NEXT:    Preds (1): B2
// CHECK-NEXT:    Succs (1): B1
// CHECK:  [B5]
// CHECK-NEXT:   case B:
// CHECK-NEXT:    1: 2
// CHECK-NEXT:    2: x
// CHECK-NEXT:    3: [B5.2] = [B5.1]
// CHECK-NEXT:    T: break;
// CHECK-NEXT:    Preds (1): B2
// CHECK-NEXT:    Succs (1): B1
// CHECK:  [B6]
// CHECK-NEXT:   case A:
// CHECK-NEXT:    1: 1
// CHECK-NEXT:    2: x
// CHECK-NEXT:    3: [B6.2] = [B6.1]
// CHECK-NEXT:    T: break;
// CHECK-NEXT:    Preds (1): B2
// CHECK-NEXT:    Succs (1): B1
// CHECK:  [B0 (EXIT)]
// CHECK-NEXT:    Preds (1): B1
enum MyEnum { A, B, C };
static const enum MyEnum D = (enum MyEnum) 32;

int test_enum_with_extension(enum MyEnum value) {
  int x = 0;
  switch (value) {
    case A: x = 1; break;
    case B: x = 2; break;
    case C: x = 3; break;
    case D: x = 4; break;
  }
  return x;
}

// CHECK-LABEL: int test_enum_with_extension_default(enum MyEnum value)
// CHECK:  [B7 (ENTRY)]
// CHECK-NEXT:    Succs (1): B2
// CHECK:  [B1]
// CHECK-NEXT:    1: x
// CHECK-NEXT:    2: [B1.1] (ImplicitCastExpr, LValueToRValue, int)
// CHECK-NEXT:    3: return [B1.2];
// CHECK-NEXT:    Preds (4): B3 B4 B5 B6
// CHECK-NEXT:    Succs (1): B0
// CHECK:  [B2]
// CHECK-NEXT:    1: 0
// CHECK-NEXT:    2: int x = 0;
// CHECK-NEXT:    3: value
// CHECK-NEXT:    4: [B2.3] (ImplicitCastExpr, LValueToRValue, enum MyEnum)
// CHECK-NEXT:    5: [B2.4] (ImplicitCastExpr, IntegralCast, int)
// CHECK-NEXT:    T: switch [B2.5]
// CHECK-NEXT:    Preds (1): B7
// CHECK-NEXT:    Succs (4): B4 B5 B6 B3(Unreachable)
// CHECK:  [B3]
// CHECK-NEXT:   default:
// CHECK-NEXT:    1: 4
// CHECK-NEXT:    2: x
// CHECK-NEXT:    3: [B3.2] = [B3.1]
// CHECK-NEXT:    T: break;
// CHECK-NEXT:    Preds (1): B2(Unreachable)
// CHECK-NEXT:    Succs (1): B1
// CHECK:  [B4]
// CHECK-NEXT:   case C:
// CHECK-NEXT:    1: 3
// CHECK-NEXT:    2: x
// CHECK-NEXT:    3: [B4.2] = [B4.1]
// CHECK-NEXT:    T: break;
// CHECK-NEXT:    Preds (1): B2
// CHECK-NEXT:    Succs (1): B1
// CHECK:  [B5]
// CHECK-NEXT:   case B:
// CHECK-NEXT:    1: 2
// CHECK-NEXT:    2: x
// CHECK-NEXT:    3: [B5.2] = [B5.1]
// CHECK-NEXT:    T: break;
// CHECK-NEXT:    Preds (1): B2
// CHECK-NEXT:    Succs (1): B1
// CHECK:  [B6]
// CHECK-NEXT:   case A:
// CHECK-NEXT:    1: 1
// CHECK-NEXT:    2: x
// CHECK-NEXT:    3: [B6.2] = [B6.1]
// CHECK-NEXT:    T: break;
// CHECK-NEXT:    Preds (1): B2
// CHECK-NEXT:    Succs (1): B1
// CHECK:  [B0 (EXIT)]
// CHECK-NEXT:    Preds (1): B1
int test_enum_with_extension_default(enum MyEnum value) {
  int x = 0;
  switch (value) {
    case A: x = 1; break;
    case B: x = 2; break;
    case C: x = 3; break;
    default: x = 4; break;
  }
  return x;
}

// CHECK-LABEL: void test_placement_new()
// CHECK:  [B2 (ENTRY)]
// CHECK-NEXT:  Succs (1): B1
// CHECK:  [B1]
// CHECK-NEXT:  1: int buffer[16];
// CHECK-NEXT:  2: buffer
// CHECK-NEXT:  3: [B1.2] (ImplicitCastExpr, ArrayToPointerDecay, int *)
// CHECK-NEXT:  4: [B1.3] (ImplicitCastExpr, BitCast, void *)
// CHECK-NEXT:  5: CFGNewAllocator(MyClass *)
// WARNINGS-NEXT:  6:  (CXXConstructExpr, class MyClass)
// ANALYZER-NEXT:  6:  (CXXConstructExpr, [B1.7], class MyClass)
// CHECK-NEXT:  7: new ([B1.4]) MyClass([B1.6])
// CHECK-NEXT:  8: MyClass *obj = new (buffer) MyClass();
// CHECK-NEXT:  Preds (1): B2
// CHECK-NEXT:  Succs (1): B0
// CHECK: [B0 (EXIT)]
// CHECK-NEXT:  Preds (1): B1

extern void* operator new (unsigned long sz, void* v);
extern void* operator new[] (unsigned long sz, void* ptr);

class MyClass {
public:
  MyClass() {}
  ~MyClass() {}
};

void test_placement_new() {
  int buffer[16];
  MyClass* obj = new (buffer) MyClass();
}

// CHECK-LABEL: void test_placement_new_array()
// CHECK:  [B2 (ENTRY)]
// CHECK-NEXT:  Succs (1): B1
// CHECK: [B1]
// CHECK-NEXT:  1: int buffer[16];
// CHECK-NEXT:  2: buffer
// CHECK-NEXT:  3: [B1.2] (ImplicitCastExpr, ArrayToPointerDecay, int *)
// CHECK-NEXT:  4: [B1.3] (ImplicitCastExpr, BitCast, void *)
// CHECK-NEXT:  5: 5
// CHECK-NEXT:  6: CFGNewAllocator(MyClass *)
// WARNINGS-NEXT:  7:  (CXXConstructExpr, class MyClass [5])
// ANALYZER-NEXT:  7:  (CXXConstructExpr, [B1.8], class MyClass [5])
// CHECK-NEXT:  8: new ([B1.4]) MyClass {{\[\[}}B1.5]]
// CHECK-NEXT:  9: MyClass *obj = new (buffer) MyClass [5];
// CHECK-NEXT:  Preds (1): B2
// CHECK-NEXT:  Succs (1): B0
// CHECK: [B0 (EXIT)]
// CHECK-NEXT:  Preds (1): B1

void test_placement_new_array() {
  int buffer[16];
  MyClass* obj = new (buffer) MyClass[5];
}


// CHECK-LABEL: void test_lifetime_extended_temporaries()
// CHECK: [B1]
struct LifetimeExtend { LifetimeExtend(int); ~LifetimeExtend(); };
struct Aggregate { const LifetimeExtend a; const LifetimeExtend b; };
struct AggregateRef { const LifetimeExtend &a; const LifetimeExtend &b; };
void test_lifetime_extended_temporaries() {
  // CHECK: LifetimeExtend(1);
  // CHECK-NEXT: : 1
  // CHECK-NEXT: ~LifetimeExtend()
  // CHECK-NOT: ~LifetimeExtend()
  {
    const LifetimeExtend &l = LifetimeExtend(1);
    1;
  }
  // CHECK: LifetimeExtend(2)
  // CHECK-NEXT: ~LifetimeExtend()
  // CHECK-NEXT: : 2
  // CHECK-NOT: ~LifetimeExtend()
  {
    // No life-time extension.
    const int &l = (LifetimeExtend(2), 2);
    2;
  }
  // CHECK: LifetimeExtend(3)
  // CHECK-NEXT: : 3
  // CHECK-NEXT: ~LifetimeExtend()
  // CHECK-NOT: ~LifetimeExtend()
  {
    // The last one is lifetime extended.
    const LifetimeExtend &l = (3, LifetimeExtend(3));
    3;
  }
  // CHECK: LifetimeExtend(4)
  // CHECK-NEXT: ~LifetimeExtend()
  // CHECK-NEXT: ~LifetimeExtend()
  // CHECK-NEXT: : 4
  // CHECK-NOT: ~LifetimeExtend()
  {
    Aggregate a{LifetimeExtend(4), LifetimeExtend(4)};
    4;
  }
  // CHECK: LifetimeExtend(5)
  // CHECK-NEXT: : 5
  // FIXME: We want to emit the destructors of the lifetime
  // extended variables here.
  // CHECK-NOT: ~LifetimeExtend()
  {
    AggregateRef a{LifetimeExtend(5), LifetimeExtend(5)};
    5;
  }
  // FIXME: Add tests for lifetime extension via subobject
  // references (LifetimeExtend().some_member).
}


// FIXME: The destructor for 'a' shouldn't be there because it's deleted
// in the union.
// CHECK-LABEL: void foo()
// CHECK:  [B2 (ENTRY)]
// CHECK-NEXT:    Succs (1): B1
// CHECK:  [B1]
// WARNINGS-NEXT:    1:  (CXXConstructExpr, struct pr37688_deleted_union_destructor::A)
// ANALYZER-NEXT:    1:  (CXXConstructExpr, [B1.2], struct pr37688_deleted_union_destructor::A)
// CHECK-NEXT:    2: pr37688_deleted_union_destructor::A a;
// CHECK-NEXT:    3: [B1.2].~pr37688_deleted_union_destructor::A() (Implicit destructor)
// CHECK-NEXT:    Preds (1): B2
// CHECK-NEXT:    Succs (1): B0
// CHECK:  [B0 (EXIT)]
// CHECK-NEXT:    Preds (1): B1

namespace pr37688_deleted_union_destructor {
struct S { ~S(); };
struct A {
  ~A() noexcept {}
  union {
    struct {
      S s;
    } ss;
  };
};
void foo() {
  A a;
}
} // end namespace pr37688_deleted_union_destructor


namespace return_statement_expression {
int unknown();

// CHECK-LABEL: int foo()
// CHECK:       [B6 (ENTRY)]
// CHECK-NEXT:    Succs (1): B5
// CHECK:       [B1]
// CHECK-NEXT:    1: 0
// CHECK-NEXT:    2: return [B1.1];
// CHECK-NEXT:    Preds (1): B5
// CHECK-NEXT:    Succs (1): B0
// CHECK:       [B2]
// CHECK-NEXT:    1: 0
// CHECK-NEXT:    2: ({ ... ; [B2.1] })
// CHECK-NEXT:    3: return [B2.2];
// CHECK-NEXT:    Preds (1): B4
// CHECK-NEXT:    Succs (1): B0
// FIXME: Why do we have [B3] at all?
// CHECK:       [B3]
// CHECK-NEXT:    Succs (1): B4
// CHECK:       [B4]
// CHECK-NEXT:    1: 0
// CHECK-NEXT:    2: [B4.1] (ImplicitCastExpr, IntegralToBoolean, _Bool)
// CHECK-NEXT:    T: while [B4.2]
// CHECK-NEXT:    Preds (2): B3 B5
// CHECK-NEXT:    Succs (2): NULL B2
// CHECK:       [B5]
// CHECK-NEXT:    1: unknown
// CHECK-NEXT:    2: [B5.1] (ImplicitCastExpr, FunctionToPointerDecay, int (*)(void))
// CHECK-NEXT:    3: [B5.2]()
// CHECK-NEXT:    4: [B5.3] (ImplicitCastExpr, IntegralToBoolean, _Bool)
// CHECK-NEXT:    T: if [B5.4]
// CHECK-NEXT:    Preds (1): B6
// CHECK-NEXT:    Succs (2): B4 B1
// CHECK:       [B0 (EXIT)]
// CHECK-NEXT:    Preds (2): B1 B2
int foo() {
  if (unknown())
    return ({
      while (0)
        ;
      0;
    });
  else
    return 0;
}
} // namespace statement_expression_in_return

// CHECK-LABEL: void vla_simple(int x)
// CHECK: [B1]
// CHECK-NEXT:   1: x
// CHECK-NEXT:   2: [B1.1] (ImplicitCastExpr, LValueToRValue, int)
// CHECK-NEXT:   3: int vla[x];
void vla_simple(int x) {
  int vla[x];
}

// CHECK-LABEL: void vla_typedef(int x)
// CHECK: [B1]
// CHECK-NEXT:   1: x
// CHECK-NEXT:   2: [B1.1] (ImplicitCastExpr, LValueToRValue, int)
// CHECK-NEXT:   3: typedef int VLA[x];
void vla_typedef(int x) {
  typedef int VLA[x];
}

// CHECK-LABEL: void vla_typealias(int x)
// CHECK: [B1]
// CHECK-NEXT:   1: x
// CHECK-NEXT:   2: [B1.1] (ImplicitCastExpr, LValueToRValue, int)
// CHECK-NEXT:   3: using VLA = int [x];
void vla_typealias(int x) {
  using VLA = int[x];
}

// CHECK-LABEL: void vla_typedef_multi(int x, int y)
// CHECK:  [B1]
// CHECK-NEXT:   1: y
// CHECK-NEXT:   2: [B1.1] (ImplicitCastExpr, LValueToRValue, int)
// CHECK-NEXT:   3: x
// CHECK-NEXT:   4: [B1.3] (ImplicitCastExpr, LValueToRValue, int)
// CHECK-NEXT:   5: typedef int VLA[x][y];
void vla_typedef_multi(int x, int y) {
  typedef int VLA[x][y];
}

// CHECK-LABEL: void vla_typedefname_multi(int x, int y)
// CHECK:  [B1]
// CHECK-NEXT:   1: x
// CHECK-NEXT:   2: [B1.1] (ImplicitCastExpr, LValueToRValue, int)
// CHECK-NEXT:   3: typedef int VLA[x];
// CHECK-NEXT:   4: y
// CHECK-NEXT:   5: [B1.4] (ImplicitCastExpr, LValueToRValue, int)
// CHECK-NEXT:   6: typedef VLA VLA1[y];
// CHECK-NEXT:   7: 3
// CHECK-NEXT:   8: using VLA2 = VLA1 [3];
// CHECK-NEXT:   9: 4
// CHECK-NEXT:  10: VLA2 vla[4];
void vla_typedefname_multi(int x, int y) {
  typedef int VLA[x];
  typedef VLA VLA1[y];
  using VLA2 = VLA1[3];
  VLA2 vla[4];
}

// CHECK-LABEL: int vla_evaluate(int x)
// CHECK:  [B1]
// CHECK-NEXT:   1: x
// CHECK-NEXT:   2: ++[B1.1]
// CHECK-NEXT:   3: [B1.2] (ImplicitCastExpr, LValueToRValue, int)
// CHECK-NEXT:   4: typedef int VLA[++x];
// CHECK-NEXT:   5: x
// CHECK-NEXT:   6: ++[B1.5]
// CHECK-NEXT:   7: [B1.6] (ImplicitCastExpr, LValueToRValue, int)
// CHECK-NEXT:   8: sizeof(int [++x])
// CHECK-NEXT:   9: alignof(int [++x])
// CHECK-NEXT:  10: 0
// CHECK-NEXT:  11: x
// CHECK-NEXT:  12: [B1.11] (ImplicitCastExpr, LValueToRValue, int)
// CHECK-NEXT:  13: return [B1.12];
int vla_evaluate(int x) {
  // Evaluates the ++x
  typedef int VLA[++x];
  sizeof(int[++x]);

  // Do not evaluate the ++x
  _Alignof(int[++x]);
  _Generic((int(*)[++x])0, default : 0);

  return x;
}

// CHECK-LABEL: void CommaTemp::f()
// CHECK:       [B1]
// CHECK-NEXT:    1: CommaTemp::A() (CXXConstructExpr,
// CHECK-NEXT:    2: [B1.1] (BindTemporary)
// CHECK-NEXT:    3: CommaTemp::B() (CXXConstructExpr,
// CHECK-NEXT:    4: [B1.3] (BindTemporary)
// CHECK-NEXT:    5: ... , [B1.4]
// CHECK-NEXT:    6: ~CommaTemp::B() (Temporary object destructor)
// CHECK-NEXT:    7: ~CommaTemp::A() (Temporary object destructor)
namespace CommaTemp {
  struct A { ~A(); };
  struct B { ~B(); };
  void f();
}
void CommaTemp::f() {
  A(), B();
}

// CHECK-LABEL: template<> int *PR18472<int>()
// CHECK: [B2 (ENTRY)]
// CHECK-NEXT:   Succs (1): B1
// CHECK: [B1]
// CHECK-NEXT:   1: 0
// CHECK-NEXT:   2: [B1.1] (ImplicitCastExpr, NullToPointer, PR18472_t)
// CHECK-NEXT:   3: (PR18472_t)[B1.2] (CStyleCastExpr, NoOp, PR18472_t)
// CHECK-NEXT:   4: CFGNewAllocator(int *)
// CHECK-NEXT:   5: new (([B1.3])) int
// CHECK-NEXT:   6: return [B1.5];
// CHECK-NEXT:   Preds (1): B2
// CHECK-NEXT:   Succs (1): B0
// CHECK: [B0 (EXIT)]
// CHECK-NEXT:   Preds (1): B1

extern "C" typedef int *PR18472_t;
void *operator new (unsigned long, PR18472_t);
template <class T> T *PR18472() {
  return new (((PR18472_t) 0)) T;
}
void PR18472_helper() {
  PR18472<int>();
}