-
Notifications
You must be signed in to change notification settings - Fork 80
reject non-pointer type for global #208
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
Comments
Definitely! This should be part of an Cheers, |
Just to clarify, what tool is reporting the error |
yes |
BTW, do you think https://github.com/dannypsnl/extend is a good way to do |
I consider dannypsnl/extend to be closer to For ref: #65 (comment) // Package sem performs semantic analysis of LLVM IR modules.
package sem
// Verify performs type-checking and semantic analysis of the given module to
// verify consistency and correctness.
func Verify(m *ir.Module) error Edit: for inspiration, here is a very primitive semantic analysis written for the uC programming language by @sangisos and me. uc/sem. It essentially traverses the AST tree, checking that various invariants hold, that the type checking gives no type errors, and that the semantics are not broken in obvious ways. |
https://github.com/llir/irsem solution |
re: https://github.com/llir/irsem/blob/cda51dc46b55de911196e57f5848c5c828edf1a9/verify.go#L11 @dannypsnl, are you sure this semantic is not valid in LLVM IR? I think it is. package main
import (
"fmt"
"log"
"github.com/llir/llvm/ir"
"github.com/llir/llvm/ir/constant"
"github.com/llir/llvm/ir/types"
)
func main() {
if err := foo(); err != nil {
log.Fatalf("%+v", err)
}
}
func foo() error {
m := ir.NewModule()
x := m.NewGlobalDef("x", constant.NewInt(types.I32, 42))
f := m.NewFunc("main", types.I32)
entry := f.NewBlock("entry")
result := entry.NewLoad(types.I32, x)
entry.NewRet(result)
fmt.Println(m)
log.Println("x.ContentType:", x.ContentType)
log.Println("x.Type():", x.Type())
return nil
} Outputs the debug message:
And the LLVM IR: @x = global i32 42
define i32 @main() {
entry:
%0 = load i32, i32* @x
ret i32 %0
} The output LLVM IR is valid when run through
As such, the type of Could you provide a full test case/example which demonstrates the broken behaviour? Cheers, |
mod := ir.NewModule()
mod.NewGlobal("hello", types.I8)
mod.NewGlobalDef("x", constant.NewInt(types.I32, 42))
mf := mod.NewFunc("main", types.I32)
mb := mf.NewBlock("")
mb.NewRet(constant.NewInt(types.I32, 0)) write to temporary llvm file @hello = global i8
@x = global i32 42
define i32 @main() {
0:
ret i32 0
} compile
|
But have to notice, if we only write mod.NewGlobal("hello", types.I8) compile produces
so this seems more like an inconsistent error report from |
Ah, it's missing -@hello = global i8
+@hello = external global i8
@x = global i32 42
define i32 @main() {
0:
ret i32 0
} Therefore, the |
Emmm, should we fix this automatically? Or check in irsem I think the check would be a global missing initializer should with external |
The check can be added to irsem. If |
Then please check 30da92f3d2381f91fd7af9edfbb5633b49a647d0, if ok then I close this issue. |
LGTM, with minor comment llir/irsem@30da92f#r62298445 |
If we define a new global
it would cause an error that
global variable reference must have pointer type
Thus, I think this check is acceptable.
The text was updated successfully, but these errors were encountered: