| author | |
| committer | |
| log | c090e38340f3b0df30e1affb838a6e171f943280 |
| tree | 3c023707bbdabbbc01cd933f9c97cb0510608ebd |
| parent | 98eea963deb85d2174262d5f45ddd614a7906231 |
| signature |
5 files changed, 67 insertions(+), 0 deletions(-)
src/clang.zig+5| ... | @@ -269,6 +269,11 @@ pub const CharacterLiteral = opaque { | ... | @@ -269,6 +269,11 @@ pub const CharacterLiteral = opaque { |
| 269 | extern fn ZigClangCharacterLiteral_getValue(*const CharacterLiteral) c_uint; | 269 | extern fn ZigClangCharacterLiteral_getValue(*const CharacterLiteral) c_uint; |
| 270 | }; | 270 | }; |
| 271 | 271 | ||
| 272 | pub const ChooseExpr = opaque { | ||
| 273 | pub const getChosenSubExpr = ZigClangChooseExpr_getChosenSubExpr; | ||
| 274 | extern fn ZigClangChooseExpr_getChosenSubExpr(*const ChooseExpr) *const Expr; | ||
| 275 | }; | ||
| 276 | |||
| 272 | pub const CompoundAssignOperator = opaque { | 277 | pub const CompoundAssignOperator = opaque { |
| 273 | pub const getType = ZigClangCompoundAssignOperator_getType; | 278 | pub const getType = ZigClangCompoundAssignOperator_getType; |
| 274 | extern fn ZigClangCompoundAssignOperator_getType(*const CompoundAssignOperator) QualType; | 279 | extern fn ZigClangCompoundAssignOperator_getType(*const CompoundAssignOperator) QualType; |
src/translate_c.zig+4| ... | @@ -1308,6 +1308,10 @@ fn transStmt( | ... | @@ -1308,6 +1308,10 @@ fn transStmt( |
| 1308 | const shuffle_vec_node = try transShuffleVectorExpr(c, scope, shuffle_vec_expr); | 1308 | const shuffle_vec_node = try transShuffleVectorExpr(c, scope, shuffle_vec_expr); |
| 1309 | return maybeSuppressResult(c, scope, result_used, shuffle_vec_node); | 1309 | return maybeSuppressResult(c, scope, result_used, shuffle_vec_node); |
| 1310 | }, | 1310 | }, |
| 1311 | .ChooseExprClass => { | ||
| 1312 | const choose_expr = @ptrCast(*const clang.ChooseExpr, stmt); | ||
| 1313 | return transExpr(c, scope, choose_expr.getChosenSubExpr(), result_used); | ||
| 1314 | }, | ||
| 1311 | // When adding new cases here, see comment for maybeBlockify() | 1315 | // When adding new cases here, see comment for maybeBlockify() |
| 1312 | .GCCAsmStmtClass, | 1316 | .GCCAsmStmtClass, |
| 1313 | .GotoStmtClass, | 1317 | .GotoStmtClass, |
src/zig_clang.cpp+5| ... | @@ -2832,6 +2832,11 @@ unsigned ZigClangCharacterLiteral_getValue(const struct ZigClangCharacterLiteral | ... | @@ -2832,6 +2832,11 @@ unsigned ZigClangCharacterLiteral_getValue(const struct ZigClangCharacterLiteral |
| 2832 | return casted->getValue(); | 2832 | return casted->getValue(); |
| 2833 | } | 2833 | } |
| 2834 | 2834 | ||
| 2835 | const struct ZigClangExpr *ZigClangChooseExpr_getChosenSubExpr(const struct ZigClangChooseExpr *self) { | ||
| 2836 | auto casted = reinterpret_cast<const clang::ChooseExpr *>(self); | ||
| 2837 | return reinterpret_cast<const ZigClangExpr *>(casted->getChosenSubExpr()); | ||
| 2838 | } | ||
| 2839 | |||
| 2835 | const struct ZigClangExpr *ZigClangAbstractConditionalOperator_getCond(const struct ZigClangAbstractConditionalOperator *self) { | 2840 | const struct ZigClangExpr *ZigClangAbstractConditionalOperator_getCond(const struct ZigClangAbstractConditionalOperator *self) { |
| 2836 | auto casted = reinterpret_cast<const clang::AbstractConditionalOperator *>(self); | 2841 | auto casted = reinterpret_cast<const clang::AbstractConditionalOperator *>(self); |
| 2837 | return reinterpret_cast<const struct ZigClangExpr *>(casted->getCond()); | 2842 | return reinterpret_cast<const struct ZigClangExpr *>(casted->getCond()); |
src/zig_clang.h+3| ... | @@ -104,6 +104,7 @@ struct ZigClangCStyleCastExpr; | ... | @@ -104,6 +104,7 @@ struct ZigClangCStyleCastExpr; |
| 104 | struct ZigClangCallExpr; | 104 | struct ZigClangCallExpr; |
| 105 | struct ZigClangCaseStmt; | 105 | struct ZigClangCaseStmt; |
| 106 | struct ZigClangCharacterLiteral; | 106 | struct ZigClangCharacterLiteral; |
| 107 | struct ZigClangChooseExpr; | ||
| 107 | struct ZigClangCompoundAssignOperator; | 108 | struct ZigClangCompoundAssignOperator; |
| 108 | struct ZigClangCompoundStmt; | 109 | struct ZigClangCompoundStmt; |
| 109 | struct ZigClangConditionalOperator; | 110 | struct ZigClangConditionalOperator; |
| ... | @@ -1242,6 +1243,8 @@ ZIG_EXTERN_C struct ZigClangSourceLocation ZigClangCharacterLiteral_getBeginLoc( | ... | @@ -1242,6 +1243,8 @@ ZIG_EXTERN_C struct ZigClangSourceLocation ZigClangCharacterLiteral_getBeginLoc( |
| 1242 | ZIG_EXTERN_C enum ZigClangCharacterLiteral_CharacterKind ZigClangCharacterLiteral_getKind(const struct ZigClangCharacterLiteral *); | 1243 | ZIG_EXTERN_C enum ZigClangCharacterLiteral_CharacterKind ZigClangCharacterLiteral_getKind(const struct ZigClangCharacterLiteral *); |
| 1243 | ZIG_EXTERN_C unsigned ZigClangCharacterLiteral_getValue(const struct ZigClangCharacterLiteral *); | 1244 | ZIG_EXTERN_C unsigned ZigClangCharacterLiteral_getValue(const struct ZigClangCharacterLiteral *); |
| 1244 | 1245 | ||
| 1246 | ZIG_EXTERN_C const struct ZigClangExpr *ZigClangChooseExpr_getChosenSubExpr(const struct ZigClangChooseExpr *); | ||
| 1247 | |||
| 1245 | ZIG_EXTERN_C const struct ZigClangExpr *ZigClangAbstractConditionalOperator_getCond(const struct ZigClangAbstractConditionalOperator *); | 1248 | ZIG_EXTERN_C const struct ZigClangExpr *ZigClangAbstractConditionalOperator_getCond(const struct ZigClangAbstractConditionalOperator *); |
| 1246 | ZIG_EXTERN_C const struct ZigClangExpr *ZigClangAbstractConditionalOperator_getTrueExpr(const struct ZigClangAbstractConditionalOperator *); | 1249 | ZIG_EXTERN_C const struct ZigClangExpr *ZigClangAbstractConditionalOperator_getTrueExpr(const struct ZigClangAbstractConditionalOperator *); |
| 1247 | ZIG_EXTERN_C const struct ZigClangExpr *ZigClangAbstractConditionalOperator_getFalseExpr(const struct ZigClangAbstractConditionalOperator *); | 1250 | ZIG_EXTERN_C const struct ZigClangExpr *ZigClangAbstractConditionalOperator_getFalseExpr(const struct ZigClangAbstractConditionalOperator *); |
test/run_translated_c.zig+50| ... | @@ -1659,4 +1659,54 @@ pub fn addCases(cases: *tests.RunTranslatedCContext) void { | ... | @@ -1659,4 +1659,54 @@ pub fn addCases(cases: *tests.RunTranslatedCContext) void { |
| 1659 | \\ return 0; | 1659 | \\ return 0; |
| 1660 | \\} | 1660 | \\} |
| 1661 | , ""); | 1661 | , ""); |
| 1662 | |||
| 1663 | cases.add("__builtin_choose_expr (unchosen expression is not evaluated)", | ||
| 1664 | \\#include <stdlib.h> | ||
| 1665 | \\int main(void) { | ||
| 1666 | \\ int x = 0.0; | ||
| 1667 | \\ int y = 0.0; | ||
| 1668 | \\ int res; | ||
| 1669 | \\ res = __builtin_choose_expr(1, 1, x / y); | ||
| 1670 | \\ if (res != 1) abort(); | ||
| 1671 | \\ res = __builtin_choose_expr(0, x / y, 2); | ||
| 1672 | \\ if (res != 2) abort(); | ||
| 1673 | \\ return 0; | ||
| 1674 | \\} | ||
| 1675 | , ""); | ||
| 1676 | |||
| 1677 | // TODO: add isnan check for long double once bitfield support is added | ||
| 1678 | // (needed for x86_64-windows-gnu) | ||
| 1679 | // TODO: add isinf check for long double once std.math.isInf supports c_longdouble | ||
| 1680 | cases.add("NAN and INFINITY", | ||
| 1681 | \\#include <math.h> | ||
| 1682 | \\#include <stdint.h> | ||
| 1683 | \\#include <stdlib.h> | ||
| 1684 | \\union uf { uint32_t u; float f; }; | ||
| 1685 | \\#define CHECK_NAN(STR, VAL) { \ | ||
| 1686 | \\ union uf unpack = {.f = __builtin_nanf(STR)}; \ | ||
| 1687 | \\ if (!isnan(unpack.f)) abort(); \ | ||
| 1688 | \\ if (unpack.u != VAL) abort(); \ | ||
| 1689 | \\} | ||
| 1690 | \\int main(void) { | ||
| 1691 | \\ float f_nan = NAN; | ||
| 1692 | \\ if (!isnan(f_nan)) abort(); | ||
| 1693 | \\ double d_nan = NAN; | ||
| 1694 | \\ if (!isnan(d_nan)) abort(); | ||
| 1695 | \\ CHECK_NAN("0", 0x7FC00000); | ||
| 1696 | \\ CHECK_NAN("", 0x7FC00000); | ||
| 1697 | \\ CHECK_NAN("1", 0x7FC00001); | ||
| 1698 | \\ CHECK_NAN("0x7FC00000", 0x7FC00000); | ||
| 1699 | \\ CHECK_NAN("0x7FC0000F", 0x7FC0000F); | ||
| 1700 | \\ CHECK_NAN("0x7FC000F0", 0x7FC000F0); | ||
| 1701 | \\ CHECK_NAN("0x7FC00F00", 0x7FC00F00); | ||
| 1702 | \\ CHECK_NAN("0x7FC0F000", 0x7FC0F000); | ||
| 1703 | \\ CHECK_NAN("0x7FCF0000", 0x7FCF0000); | ||
| 1704 | \\ CHECK_NAN("0xFFFFFFFF", 0x7FFFFFFF); | ||
| 1705 | \\ float f_inf = INFINITY; | ||
| 1706 | \\ if (!isinf(f_inf)) abort(); | ||
| 1707 | \\ double d_inf = INFINITY; | ||
| 1708 | \\ if (!isinf(d_inf)) abort(); | ||
| 1709 | \\ return 0; | ||
| 1710 | \\} | ||
| 1711 | , ""); | ||
| 1662 | } | 1712 | } |