Skip to content
This repository has been archived by the owner on May 18, 2024. It is now read-only.

Commit

Permalink
compileDeclRefExpr bugfix: don't use ctx.getPubName
Browse files Browse the repository at this point in the history
  • Loading branch information
xushiwei committed Jul 22, 2022
1 parent 1c5ef51 commit 11e30ae
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
11 changes: 5 additions & 6 deletions cl/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,12 +377,11 @@ func compileFunc(ctx *blockCtx, fn *ast.Node) {
results = types.NewTuple(pkg.NewParam(token.NoPos, "", tyRet))
}
sig := gox.NewCSignature(types.NewTuple(params...), results, variadic)
static := ""
origName, rewritten := fnName, false
if !ctx.inHeader && fn.StorageClass == ast.Static {
static = fnName
fnName = ctx.autoStaticName(static)
fnName, rewritten = ctx.autoStaticName(origName), true
} else {
ctx.getPubName(&fnName)
rewritten = ctx.getPubName(&fnName)
}
if body != nil {
if ctx.checkExists(fnName) {
Expand Down Expand Up @@ -451,9 +450,9 @@ func compileFunc(ctx *blockCtx, fn *ast.Node) {
ctx.addExternFunc(fnName)
}
}
if static != "" {
if rewritten {
scope := pkg.Types.Scope()
substObj(pkg.Types, scope, static, scope, fnName)
substObj(pkg.Types, scope, origName, scope, fnName)
}
}

Expand Down
4 changes: 1 addition & 3 deletions cl/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,7 @@ func compileTypeCast(ctx *blockCtx, v *ast.Node, src goast.Node) {

func compileDeclRefExpr(ctx *blockCtx, v *ast.Node, lhs bool) {
name := v.ReferencedDecl.Name
if !ctx.getPubName(&name) {
avoidKeyword(&name)
}
avoidKeyword(&name)
obj := ctx.lookupParent(name)
if obj == nil {
log.Panicln("compileDeclRefExpr: not found -", name)
Expand Down
17 changes: 8 additions & 9 deletions cl/type_and_var.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,15 +270,15 @@ func compileEnumConst(ctx *blockCtx, cdecl *gox.ConstDefs, v *ast.Node, iotav in
}

func compileVarDecl(ctx *blockCtx, decl *ast.Node, global bool) {
origName, rewritten := decl.Name, false
if debugCompileDecl {
log.Println("varDecl", decl.Name, "-", decl.Loc.PresumedLine)
log.Println("varDecl", origName, "-", decl.Loc.PresumedLine)
}
if global {
ctx.getPubName(&decl.Name)
rewritten = ctx.getPubName(&decl.Name)
}
scope := ctx.cb.Scope()
flags := 0
static := ""
gblStatic := false
switch decl.StorageClass {
case ast.Extern:
Expand All @@ -289,8 +289,7 @@ func compileVarDecl(ctx *blockCtx, decl *ast.Node, global bool) {
} else { // local static variable
scope = ctx.pkg.Types.Scope()
}
static = decl.Name
decl.Name = ctx.autoStaticName(static)
decl.Name, rewritten = ctx.autoStaticName(origName), true
}
typ, kind, err := parseType(ctx, scope, nil, decl.Type, flags)
if err != nil {
Expand All @@ -304,14 +303,14 @@ func compileVarDecl(ctx *blockCtx, decl *ast.Node, global bool) {
scope.Insert(types.NewVar(ctx.goNodePos(decl), ctx.pkg.Types, decl.Name, typ))
} else {
if (kind&parser.KindFConst) != 0 && isInteger(typ) && tryNewConstInteger(ctx, typ, decl) {
if static != "" {
substObj(ctx.pkg.Types, ctx.cb.Scope(), static, scope, decl.Name)
if rewritten {
substObj(ctx.pkg.Types, ctx.cb.Scope(), origName, scope, decl.Name)
}
return
}
newVarAndInit(ctx, scope, typ, decl, global)
if static != "" {
substObj(ctx.pkg.Types, ctx.cb.Scope(), static, scope, decl.Name)
if rewritten {
substObj(ctx.pkg.Types, ctx.cb.Scope(), origName, scope, decl.Name)
} else if kind == parser.KindFVolatile && !global {
addr := gox.Lookup(scope, decl.Name)
ctx.cb.VarRef(nil).Val(addr).Assign(1) // musl: use volatile to mark unused
Expand Down

0 comments on commit 11e30ae

Please sign in to comment.