Skip to content

Commit a5fb785

Browse files
deadprogramaykevl
authored andcommitted
compiler: ensure that any passed in target, if it does not point to a .json file, is a full LLVM triple
Signed-off-by: Ron Evans <[email protected]>
1 parent 86b888f commit a5fb785

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

target.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ func LoadTarget(target string) (*TargetSpec, error) {
206206
// Load target from given triple, ignore GOOS/GOARCH environment
207207
// variables.
208208
tripleSplit := strings.Split(target, "-")
209-
if len(tripleSplit) == 1 {
209+
if len(tripleSplit) < 3 {
210210
return nil, errors.New("expected a full LLVM target or a custom target in -target flag")
211211
}
212212
goos := tripleSplit[2]

target_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package main
2+
3+
import "testing"
4+
5+
func TestLoadTarget(t *testing.T) {
6+
_, err := LoadTarget("arduino")
7+
if err != nil {
8+
t.Error("LoadTarget test failed:", err)
9+
}
10+
11+
_, err = LoadTarget("notexist")
12+
if err == nil {
13+
t.Error("LoadTarget should have failed with non existing target")
14+
}
15+
16+
if err.Error() != "expected a full LLVM target or a custom target in -target flag" {
17+
t.Error("LoadTarget failed for wrong reason:", err)
18+
}
19+
}

0 commit comments

Comments
 (0)