Skip to content

Commit

Permalink
additional checks
Browse files Browse the repository at this point in the history
  • Loading branch information
wrongnull committed Sep 30, 2024
1 parent 1e48ed3 commit a86f96b
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/aro/Parser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5492,6 +5492,9 @@ pub const Result = struct {
// if both aren't arithmetic one should be pointer and the other an integer
if (a_ptr == b_ptr or a_int == b_int) return a.invalidBinTy(tok, b, p);

if (a.ty.isVoidStar() or b.ty.isVoidStar())
try p.errTok(.gnu_pointer_arith, tok);

// Do integer promotions but nothing else
if (a_int) try a.intCast(p, a.ty.integerPromotion(p.comp), tok);
if (b_int) try b.intCast(p, b.ty.integerPromotion(p.comp), tok);
Expand All @@ -5504,7 +5507,7 @@ pub const Result = struct {
// if both aren't arithmetic then either both should be pointers or just a
if (!a_ptr or !(b_ptr or b_int)) return a.invalidBinTy(tok, b, p);

if (a.ty.isVoidStar() or b.ty.isVoidStar())
if (a.ty.isVoidStar())
try p.errTok(.gnu_pointer_arith, tok);

if (a_ptr and b_ptr) {
Expand Down Expand Up @@ -7153,6 +7156,8 @@ fn unExpr(p: *Parser) Error!Result {

var operand = try p.castExpr();
try operand.expect(p);
if (operand.ty.isVoidStar())
try p.errTok(.gnu_pointer_arith, tok);
if (!operand.ty.isScalar())
try p.errStr(.invalid_argument_un, tok, try p.typeStr(operand.ty));
if (operand.ty.isComplex())
Expand All @@ -7179,6 +7184,8 @@ fn unExpr(p: *Parser) Error!Result {

var operand = try p.castExpr();
try operand.expect(p);
if (operand.ty.isVoidStar())
try p.errTok(.gnu_pointer_arith, tok);
if (!operand.ty.isScalar())
try p.errStr(.invalid_argument_un, tok, try p.typeStr(operand.ty));
if (operand.ty.isComplex())
Expand Down Expand Up @@ -7478,6 +7485,8 @@ fn suffixExpr(p: *Parser, lhs: Result) Error!Result {
defer p.tok_i += 1;

var operand = lhs;
if (operand.ty.isVoidStar())
try p.errTok(.gnu_pointer_arith, p.tok_i);
if (!operand.ty.isScalar())
try p.errStr(.invalid_argument_un, p.tok_i, try p.typeStr(operand.ty));
if (operand.ty.isComplex())
Expand All @@ -7496,6 +7505,8 @@ fn suffixExpr(p: *Parser, lhs: Result) Error!Result {
defer p.tok_i += 1;

var operand = lhs;
if (operand.ty.isVoidStar())
try p.errTok(.gnu_pointer_arith, p.tok_i);
if (!operand.ty.isScalar())
try p.errStr(.invalid_argument_un, p.tok_i, try p.typeStr(operand.ty));
if (operand.ty.isComplex())
Expand Down

0 comments on commit a86f96b

Please sign in to comment.