Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some different crashes #689

Merged
merged 3 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/aro/Attribute.zig
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,7 @@ fn diagnoseField(
},
.bytes => |bytes| {
if (Wanted == Value) {
std.debug.assert(node.tag == .string_literal_expr);
if (!node.ty.elemType().is(.char) and !node.ty.elemType().is(.uchar)) {
if (node.tag != .string_literal_expr or (!node.ty.elemType().is(.char) and !node.ty.elemType().is(.uchar))) {
return .{
.tag = .attribute_requires_string,
.extra = .{ .str = decl.name },
Expand Down
6 changes: 6 additions & 0 deletions src/aro/Parser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6447,6 +6447,8 @@ fn landExpr(p: *Parser) Error!Result {
if (try lhs.adjustTypes(tok, &rhs, p, .boolean_logic)) {
const res = lhs.val.toBool(p.comp) and rhs.val.toBool(p.comp);
lhs.val = Value.fromBool(res);
} else {
lhs.val.boolCast(p.comp);
}
try lhs.boolRes(p, .bool_and_expr, rhs);
}
Expand Down Expand Up @@ -6516,6 +6518,8 @@ fn eqExpr(p: *Parser) Error!Result {
const op: std.math.CompareOperator = if (tag == .equal_expr) .eq else .neq;
const res = lhs.val.compare(op, rhs.val, p.comp);
lhs.val = Value.fromBool(res);
} else {
lhs.val.boolCast(p.comp);
}
try lhs.boolRes(p, tag, rhs);
}
Expand Down Expand Up @@ -6545,6 +6549,8 @@ fn compExpr(p: *Parser) Error!Result {
};
const res = lhs.val.compare(op, rhs.val, p.comp);
lhs.val = Value.fromBool(res);
} else {
lhs.val.boolCast(p.comp);
}
try lhs.boolRes(p, tag, rhs);
}
Expand Down
9 changes: 8 additions & 1 deletion src/aro/Preprocessor.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1356,7 +1356,14 @@ fn stringify(pp: *Preprocessor, tokens: []const TokenWithExpansionLocs) !void {
}

fn reconstructIncludeString(pp: *Preprocessor, param_toks: []const TokenWithExpansionLocs, embed_args: ?*[]const TokenWithExpansionLocs, first: TokenWithExpansionLocs) !?[]const u8 {
assert(param_toks.len != 0);
if (param_toks.len == 0) {
try pp.comp.addDiagnostic(.{
.tag = .expected_filename,
.loc = first.loc,
}, first.expansionSlice());
return null;
}

const char_top = pp.char_buf.items.len;
defer pp.char_buf.items.len = char_top;

Expand Down
3 changes: 3 additions & 0 deletions test/cases/binary expressions.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ _Static_assert((-1 ^ 0) == -1, "");
_Static_assert((-1 ^ -1) == 0, "");
_Static_assert((-2 ^ 2) == -4, "");

_Static_assert(2.0||(2.0 == 2.0), "");
_Static_assert(2.0||(3.0 > 2.0), "");
_Static_assert(2.0||(2.0 && 2.0), "");

#define EXPECTED_ERRORS "binary expressions.c:3:7: error: invalid operands to binary expression ('long' and 'float')" \
"binary expressions.c:6:13: error: invalid operands to binary expression ('char' and 'int *')" \
Expand Down
4 changes: 4 additions & 0 deletions test/cases/include pragma.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include _Pragma("once")

#define EXPECTED_ERRORS "include pragma.c:1:10: error: expected \"FILENAME\" or <FILENAME>" \

7 changes: 7 additions & 0 deletions test/cases/non string attribute.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
enum E {
is_deprecated_with_msg __attribute__((deprecated("I am deprecated" = 5 ))),
};

#define EXPECTED_ERRORS "non string attribute.c:2:71: error: expression is not assignable" \
"non string attribute.c:2:53: error: attribute 'deprecated' requires an ordinary string" \

Loading