commit 755c5580267b246983fc0b2b2fb8dccfc261b9a0 (tree)
parent f59069f3d0cf6204f15dbd9c707dbefebfe88e01
Author: Andrew Kelley <andrew@ziglang.org>
Date: Wed, 16 Dec 2020 14:24:36 -0700
Merge remote-tracking branch 'origin/master' into llvm12
Diffstat:
3 files changed, 35 insertions(+), 1 deletion(-)
diff --git a/lib/std/math.zig b/lib/std/math.zig
@@ -1169,7 +1169,7 @@ pub const Order = enum {
return switch (self) {
.lt => .gt,
.eq => .eq,
- .gt => .gt,
+ .gt => .lt,
};
}
@@ -1266,6 +1266,29 @@ test "compare between signed and unsigned" {
testing.expect(compare(@as(u8, 1), .eq, @as(u8, 1)));
}
+test "order" {
+ testing.expect(order(0, 0) == .eq);
+ testing.expect(order(1, 0) == .gt);
+ testing.expect(order(-1, 0) == .lt);
+}
+
+test "order.invert" {
+ testing.expect(Order.invert(order(0, 0)) == .eq);
+ testing.expect(Order.invert(order(1, 0)) == .lt);
+ testing.expect(Order.invert(order(-1, 0)) == .gt);
+}
+
+test "order.compare" {
+ testing.expect(order(-1, 0).compare(.lt));
+ testing.expect(order(-1, 0).compare(.lte));
+ testing.expect(order(0, 0).compare(.lte));
+ testing.expect(order(0, 0).compare(.eq));
+ testing.expect(order(0, 0).compare(.gte));
+ testing.expect(order(1, 0).compare(.gte));
+ testing.expect(order(1, 0).compare(.gt));
+ testing.expect(order(1, 0).compare(.neq));
+}
+
test "math.comptime" {
comptime const v = sin(@as(f32, 1)) + ln(@as(f32, 5));
testing.expect(v == sin(@as(f32, 1)) + ln(@as(f32, 5)));
diff --git a/src/translate_c.zig b/src/translate_c.zig
@@ -1797,6 +1797,10 @@ fn exprIsStringLiteral(expr: *const clang.Expr) bool {
const op_expr = @ptrCast(*const clang.UnaryOperator, expr).getSubExpr();
return exprIsStringLiteral(op_expr);
},
+ .ParenExprClass => {
+ const op_expr = @ptrCast(*const clang.ParenExpr, expr).getSubExpr();
+ return exprIsStringLiteral(op_expr);
+ },
else => return false,
}
}
diff --git a/test/run_translated_c.zig b/test/run_translated_c.zig
@@ -3,6 +3,13 @@ const tests = @import("tests.zig");
const nl = std.cstr.line_sep;
pub fn addCases(cases: *tests.RunTranslatedCContext) void {
+ cases.add("parenthesized string literal",
+ \\void foo(const char *s) {}
+ \\int main(void) {
+ \\ foo(("bar"));
+ \\}
+ , "");
+
cases.add("variable shadowing type type",
\\#include <stdlib.h>
\\int main() {