Changeset 5f210c0 for src


Ignore:
Timestamp:
Aug 4, 2024, 9:49:25 PM (5 months ago)
Author:
JiadaL <j82liang@…>
Branches:
master
Children:
7db4fcd4
Parents:
7ab24fef
Message:

Change enum pos to signed int to avoid underflow; operator on enum will not have range check (but succ and pred still have range check

Location:
src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/ControlStruct/TranslateEnumRange.cpp

    r7ab24fef r5f210c0  
    5151    // it wraps around and become unsigned max
    5252    ast::UntypedExpr * condition = ast::UntypedExpr::createCall( location,
    53         "?<=?",
     53        stmt->is_inc? "?<=?": "?>=?",
    5454        {   new ast::NameExpr( location, indexName ),
    55             ast::UntypedExpr::createCall( location, "upperBound", {} )  });
     55            stmt->is_inc?
     56                ast::UntypedExpr::createCall( location, "upperBound", {} ):
     57                ast::UntypedExpr::createCall( location, "lowerBound", {} )
     58        });
    5659    auto increment = ast::UntypedExpr::createCall( location,
    5760        stmt->is_inc? "succ_unsafe": "pred_unsafe",
  • src/Validate/ImplementEnumFunc.cpp

    r7ab24fef r5f210c0  
    2525                : decl(decl),
    2626                  functionNesting{functionNesting},
    27                 //   quasi_void_decl(new ast::StructDecl(decl->location,
    28                 //      "quasi_void", ast::AggregateDecl::Struct,
    29                 //      {}, ast::Linkage::AutoGen)),
    3027                  proto_linkage{ast::Linkage::Cforall} {}
    3128
     
    194191        {new ast::ObjectDecl(getLocation(), "_i", new ast::EnumInstType(decl))},
    195192        {new ast::ObjectDecl(getLocation(), "_ret",
    196             new ast::BasicType(ast::BasicKind::UnsignedInt))});
     193            new ast::BasicType(ast::BasicKind::SignedInt))});
    197194}
    198195
     
    229226        return genProto(
    230227                "fromInt_unsafe",
    231                 {new ast::ObjectDecl(getLocation(), "_i", new ast::BasicType(ast::BasicKind::UnsignedInt))},
     228                {new ast::ObjectDecl(getLocation(), "_i", new ast::BasicType(ast::BasicKind::SignedInt))},
    232229                {new ast::ObjectDecl(getLocation(), "_ret", new ast::EnumInstType(decl))}
    233230        );
     
    238235                "fromInstance",
    239236                {new ast::ObjectDecl(getLocation(), "_i", new ast::EnumInstType(decl))},
    240                 {new ast::ObjectDecl(getLocation(), "_ret", new ast::BasicType(ast::BasicKind::UnsignedInt))}
     237                {new ast::ObjectDecl(getLocation(), "_ret", new ast::BasicType(ast::BasicKind::SignedInt))}
    241238        );
    242239}
     
    285282                func->location,
    286283                new ast::VariableExpr(func->location, param),
    287                 new ast::BasicType(ast::BasicKind::UnsignedInt),
     284                new ast::BasicType(ast::BasicKind::SignedInt),
    288285                ast::GeneratedFlag::ExplicitCast
    289286        );
     
    383380                        func->location,
    384381                        new ast::VariableExpr( func->location, func->params.front() ),
    385                         new ast::BasicType( ast::BasicKind::UnsignedInt ),
     382                        new ast::BasicType( ast::BasicKind::SignedInt ),
    386383                        ast::GeneratedFlag::ExplicitCast
    387384                )});
     
    407404                func->location,
    408405                new ast::VariableExpr(func->location, func->params.front()),
    409                 new ast::BasicType( ast::BasicKind::UnsignedInt ),
     406                new ast::BasicType( ast::BasicKind::SignedInt ),
    410407                        ast::GeneratedFlag::ExplicitCast);
    411408        func->stmts = new ast::CompoundStmt(
Note: See TracChangeset for help on using the changeset viewer.