Skip to content

Commit 28c16bd

Browse files
committed
example.c+- compiles again
1 parent 43bf9d4 commit 28c16bd

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ $(OUTPUT): $(OBJECTS)
3737
$(COMPILER) -o $@ $^ $(LDFLAGS)
3838

3939
test: $(OUTPUT)
40-
./$(OUTPUT) examples/why.c+- -d
40+
./$(OUTPUT) examples/example.c+- -d
4141

4242
%.o: %.cpp $(PARSERHDR) $(WASMPARSERHDR)
4343
$(COMPILER) $(CFLAGS) -c $< -o $@

src/Expr.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1471,7 +1471,16 @@ void AccessExpr::compile(VregPtr destination, Function &function, const Context
14711471
array_type = PointerType::make(casted->subtype->copy());
14721472
else if (!array_type->is<PointerType>())
14731473
fail();
1474+
1475+
Type *subtype = nullptr;
1476+
if (auto super = array_type->ptrcast<SuperType>())
1477+
subtype = super->subtype;
1478+
else
1479+
fail();
1480+
14741481
compileAddress(destination, function, context);
1482+
destination->setType(*subtype);
1483+
14751484
function.add<LoadRInstruction>(destination, destination, getSize(context))->setDebug(*this);
14761485
if (multiplier != 1)
14771486
function.add<MultIInstruction>(destination, destination, size_t(multiplier))->setDebug(*this);
@@ -1484,8 +1493,11 @@ std::unique_ptr<Type> AccessExpr::getType(const Context &context) const {
14841493
auto array_type = array->getType(context);
14851494
if (const auto *casted = array_type->cast<const ArrayType>())
14861495
return std::unique_ptr<Type>(casted->subtype->copy());
1487-
if (const auto *casted = array_type->cast<const PointerType>())
1496+
if (const auto *casted = array_type->cast<const PointerType>()) {
1497+
if (const auto *subarray = casted->subtype->cast<const ArrayType>())
1498+
return std::unique_ptr<Type>(subarray->subtype->copy());
14881499
return std::unique_ptr<Type>(casted->subtype->copy());
1500+
}
14891501
fail();
14901502
return nullptr;
14911503
}

0 commit comments

Comments
 (0)