[cfe-dev] Problematic AST for switch with non constant case values in C++

Dávid Bolvanský via cfe-dev cfe-dev at lists.llvm.org
Tue Jun 18 03:45:49 PDT 2019


Hello,

Check this testcase:
https://github.com/llvm-mirror/clang/blob/329eb5c6baeca0a1bd6b1a5bd55e41de786f39fa//test/Sema/switch-1.c#L10

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: ...
}

Ideally here:
https://github.com/llvm-mirror/clang/blob/329eb5c6baeca0a1bd6b1a5bd55e41de786f39fa/lib/Sema/SemaStmt.cpp#L809

Since I am working on -Wswitch-unreachable, this problem blocks
https://reviews.llvm.org/D63423 now.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20190618/9bf31e77/attachment.html>


More information about the cfe-dev mailing list