Problematic AST for switch with non constant case values in C++

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Problematic AST for switch with non constant case values in C++

Nathan Ridge via cfe-dev
Hello,


clang -cc1 -ast-dump -x c++ /home/LLVM/llvm/tools/clang/test/Sema/switch-1.c
Produced AST:

CompoundStmt 0x55f5b7d68460 <col:14, line:51:3>
|   |   |-ReturnStmt 0x55f5b7d68060 <line:17:7, col:14>
|   |   | `-IntegerLiteral 0x55f5b7d68040 <col:14> 'int' 1
|   |   |-ReturnStmt 0x55f5b7d68120 <line:25:7, col:14>
|   |   | `-IntegerLiteral 0x55f5b7d68100 <col:14> 'int' 2
|   |   |-ReturnStmt 0x55f5b7d68210 <line:33:7, col:14>
|   |   | `-IntegerLiteral 0x55f5b7d681f0 <col:14> 'int' 3
|   |   |-ReturnStmt 0x55f5b7d683c0 <line:48:7, col:14>
|   |   | `-IntegerLiteral 0x55f5b7d683a0 <col:14> 'int' 4
|   |   `-CaseStmt 0x55f5b7d68408 <line:49:5, line:50:14>
|   |     |-ConstantExpr 0x55f5b7d683f0 <line:49:10> 'int'
|   |     | `-IntegerLiteral 0x55f5b7d683d0 <col:10> 'int' 2147483647
|   |     `-ReturnStmt 0x55f5b7d68450 <line:50:7, col:14>
|   |       `-IntegerLiteral 0x55f5b7d68430 <col:14> 'int' 0

The problem is how can we distinguish between this AST and AST for:
switch(x) {
   return 1;
   return 2;
   case 1: ...
}


Since I am working on -Wswitch-unreachable, this problem blocks https://reviews.llvm.org/D63423 now.

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev