Skip to content

Commit

Permalink
Merge pull request #830 from ehaas/sqlite-fixes
Browse files Browse the repository at this point in the history
Sqlite fixes
  • Loading branch information
Vexu authored Jan 7, 2025
2 parents a5c00e1 + 6484ccb commit aed93e2
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/aro/Attribute.zig
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ const attributes = struct {
pub const nonstring = struct {};
pub const noplt = struct {};
pub const @"noreturn" = struct {};
pub const nothrow = struct {};
// TODO: union args ?
// const optimize = struct {
// // optimize, // u32 | []const u8 -- optimize?
Expand Down Expand Up @@ -899,7 +900,7 @@ pub fn applyFunctionAttributes(p: *Parser, ty: Type, attr_buf_start: usize) !Typ
.noreturn, .unused, .used, .warning, .deprecated, .unavailable, .weak, .pure, .leaf,
.@"const", .warn_unused_result, .section, .returns_nonnull, .returns_twice, .@"error",
.externally_visible, .retain, .flatten, .gnu_inline, .alias, .asm_label, .nodiscard,
.reproducible, .unsequenced,
.reproducible, .unsequenced, .nothrow,
=> try p.attr_application_buf.append(p.gpa, attr),
// zig fmt: on
.hot => if (cold) {
Expand Down
4 changes: 4 additions & 0 deletions src/aro/Attribute/names.def
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@ noplt
.tag = .noplt
.gnu = true

nothrow
.tag = .nothrow
.gnu = true

# optimize
# .tag = .optimize
# .gnu = true
Expand Down
2 changes: 1 addition & 1 deletion src/aro/Parser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7065,7 +7065,7 @@ fn computeOffsetExtra(p: *Parser, node: Node.Index, offset_so_far: *Value) !Valu
switch (node.get(&p.tree)) {
.cast => |cast| {
return switch (cast.kind) {
.array_to_pointer => p.computeOffsetExtra(cast.operand, offset_so_far),
.array_to_pointer, .no_op, .bitcast => p.computeOffsetExtra(cast.operand, offset_so_far),
.lval_to_rval => .{},
else => unreachable,
};
Expand Down
10 changes: 9 additions & 1 deletion src/aro/Value.zig
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ pub const IntCastChangeKind = enum {
pub fn intCast(v: *Value, dest_ty: Type, comp: *Compilation) !IntCastChangeKind {
if (v.opt_ref == .none) return .none;
const key = comp.interner.get(v.ref());
if (key == .pointer) return .none;
if (key == .pointer or key == .bytes) return .none;

const dest_bits: usize = @intCast(dest_ty.bitSizeof(comp).?);
const dest_signed = dest_ty.signedness(comp) == .signed;
Expand Down Expand Up @@ -544,6 +544,10 @@ pub fn add(res: *Value, lhs: Value, rhs: Value, ty: Type, comp: *Compilation) !b
}
const lhs_key = comp.interner.get(lhs.ref());
const rhs_key = comp.interner.get(rhs.ref());
if (lhs_key == .bytes or rhs_key == .bytes) {
res.* = .{};
return false;
}
if (lhs_key == .pointer or rhs_key == .pointer) {
const rel, const index = if (lhs_key == .pointer)
.{ lhs_key.pointer, rhs }
Expand Down Expand Up @@ -613,6 +617,10 @@ pub fn sub(res: *Value, lhs: Value, rhs: Value, ty: Type, elem_size: u64, comp:
}
const lhs_key = comp.interner.get(lhs.ref());
const rhs_key = comp.interner.get(rhs.ref());
if (lhs_key == .bytes or rhs_key == .bytes) {
res.* = .{};
return false;
}
if (lhs_key == .pointer and rhs_key == .pointer) {
const lhs_pointer = lhs_key.pointer;
const rhs_pointer = rhs_key.pointer;
Expand Down
5 changes: 5 additions & 0 deletions test/cases/relocations.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ char *bar(char *p) {
char *p2 = &p[1];
return p2;
}

int casted[10];
_Static_assert(&((char *)casted)[4] == (char *)&casted[1], "");
_Static_assert(&((int *)casted)[1] == &casted[1], "");

#define EXPECTED_ERRORS "relocations.c:24:1: error: static assertion failed" \
"relocations.c:29:16: error: static_assert expression is not an integral constant expression" \
"relocations.c:30:16: error: static_assert expression is not an integral constant expression" \
Expand Down
4 changes: 4 additions & 0 deletions test/cases/strings.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ _Static_assert(1, "\u0060");
_Static_assert(1, "aaァ\e[1;");
#pragma GCC diagnostic pop

const char *s1 = (const char *)"hello";
const char *s2 = "hello" + 1;
const char *s3 = "hello" - 1;

#define EXPECTED_ERRORS "strings.c:2:29: error: escape sequence out of range" \
"strings.c:4:19: error: invalid universal character" \
"strings.c:5:19: error: character 'b' cannot be specified by a universal character name" \
Expand Down

0 comments on commit aed93e2

Please sign in to comment.