[cfe-dev] SwitchStmt bug?

Per Viberg Per.Viberg at evidente.se
Mon Mar 10 07:23:38 PDT 2014


Hi all,

I was inspecting the AST dump of this switch:

void test_switch(int t) {
  switch(t)
  {
  case 1:
    y = 11;
  case 2:
    y = 9;
    x = 12;
    break;
  default:
    break;
  }
}

and I got something I didn't expect. The second CaseStmt does only contain the first statement that is under it's label. The "x=12;" gets its own Stmt outside the CaseStmt but inside the CompoundStmt inside the SwitchStmt. I would anticipate that all statements under a label either are: inside the CaseStmt or: outside but inside the CompoundStmt. Any reason for this?.


SwitchStmt 0x5bf6fe8
|-<<<NULL>>>
|-ImplicitCastExpr 0x5bf6fd0 'int' <LValueToRValue>
| `-DeclRefExpr 0x5bf6fa8 'int' lvalue ParmVar 0x5bf6e80 't' 'int'
`-CompoundStmt 0x5bf7258
  |-CaseStmt 0x5bf7038
  | |-IntegerLiteral 0x5bf7018 'int' 1
  | |-<<<NULL>>>
  | `-BinaryOperator 0x5bf70b8 'int' lvalue '='
  |   |-DeclRefExpr 0x5bf7070 'int' lvalue Var 0x5bf6cf0 'y' 'int'
  |   `-IntegerLiteral 0x5bf7098 'int' 11
  |-CaseStmt 0x5bf7100
  | |-IntegerLiteral 0x5bf70e0 'int' 2
  | |-<<<NULL>>>
  | `-BinaryOperator 0x5bf7180 'int' lvalue '='
  |   |-DeclRefExpr 0x5bf7138 'int' lvalue Var 0x5bf6cf0 'y' 'int'
  |   `-IntegerLiteral 0x5bf7160 'int' 9
  |-BinaryOperator 0x5bf71f0 'int' lvalue '='
  | |-DeclRefExpr 0x5bf71a8 'int' lvalue Var 0x5bf6e10 'x' 'int'
  | `-IntegerLiteral 0x5bf71d0 'int' 12
  |-BreakStmt 0x5bf7218
  `-DefaultStmt 0x5bf7238
    `-BreakStmt 0x5bf7228


Best regards,
Per Viberg

.......................................................................................................................
Per Viberg Senior Engineer
Evidente ES East AB  Warfvinges väg 34  SE-112 51 Stockholm  Sweden
Phone:    +46 (0)8 402 79 00
Mobile:    +46 (0)70 912 42 52
E-mail:     Per.Viberg at evidente.se<mailto:Per.Viberg at evidente.se>

www.evidente.se<http://www.evidente.se>
This e-mail, which might contain confidential information, is addressed to the above stated person/company. If you are not the correct addressee, employee or in any other way the person concerned, please notify the sender immediately. At the same time, please delete this e-mail and destroy any prints. Thank You.
________________________________

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140310/3201fb6f/attachment.html>


More information about the cfe-dev mailing list