Skip to content
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

cmd/cgo: #define is not exportable in some situations #18720

Closed
hirochachacha opened this issue Jan 19, 2017 · 10 comments
Closed

cmd/cgo: #define is not exportable in some situations #18720

hirochachacha opened this issue Jan 19, 2017 · 10 comments
Milestone

Comments

@hirochachacha
Copy link
Contributor

Please answer these questions before submitting your issue. Thanks!

What did you do?

I know 4 failing scenarios.

package main

/*

#define PI 3.14

#define HELLO "hello"
#define WORLD "world"
#define HELLO_WORLD HELLO " " WORLD

#define VAR VAR1
#define VAR1 var

#define PAREN (var)
#define ADDR &var
#define ADDR_STAR *&var

int var = 5;

*/
import "C"

func testFloatConst() {
	if C.PI != 3.14 {
		panic("fail")
	}
}

func testStringConstPropagation() {
	if C.HELLO_WORLD != "hello world" {
		panic("fail")
	}
}

func testVariablePropagation() {
	if C.VAR != 5 {
		panic("fail")
	}
}

func testVariableIndirection() {
	if C.PAREN != 5 {
		panic("fail")
	}
	if *C.ADDR != 5 {
		panic("fail")
	}
	if C.ADDR_STAR != 5 {
		panic("fail")
	}
}

func main() {
	testFloatConst()
	testStringConstPropagation()
	testVariablePropagation()
	testVariableIndirection()
}

What did you expect to see?

no errors.

What did you see instead?

none of them can compile.

Does this issue reproduce with the latest release (go1.7.4)?

I think so.

System details

go version devel +d935b30 Tue Jan 17 12:56:29 2017 +0900 darwin/amd64
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/hiro/.go"
GORACE=""
GOROOT="/Users/hiro/go"
GOTOOLDIR="/Users/hiro/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/wq/dwn8hs0x7njbzty9f68y61700000gn/T/go-build288724185=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
GOROOT/bin/go version: go version devel +d935b30 Tue Jan 17 12:56:29 2017 +0900 darwin/amd64
GOROOT/bin/go tool compile -V: compile version devel +d935b30 Tue Jan 17 12:56:29 2017 +0900 X:framepointer
uname -v: Darwin Kernel Version 16.3.0: Thu Nov 17 20:23:58 PST 2016; root:xnu-3789.31.2~1/RELEASE_X86_64
ProductName:	Mac OS X
ProductVersion:	10.12.2
BuildVersion:	16C67
lldb --version: lldb-360.1.70
gdb --version: GNU gdb (GDB) 7.12
@minux
Copy link
Member

minux commented Jan 19, 2017 via email

@hirochachacha
Copy link
Contributor Author

Thank you for quick reply!

I think we can solve testVariablePropagation also.
for example:

x.h

#define VAR VAR1
#define VAR1 var

x.txt

#include "x.h"
"VAR" = VAR

gcc -P -E -xc -c x.txt

output:

"VAR" = var

So, we can get a finalized definition, instead of a shallow definition.
before

if isName(n.Define) {

@gopherbot
Copy link

CL https://golang.org/cl/35511 mentions this issue.

@bradfitz bradfitz added this to the Go1.9Maybe milestone Mar 21, 2017
@bradfitz
Copy link
Contributor

For @ianlancetaylor to decide/review.

gopherbot pushed a commit that referenced this issue Apr 7, 2017
Current code doesn't support floating point #define macros.
This CL compiles floats to a object file and retrive values from it.
That approach is the same work as we've already done for integers.

Updates #18720

Change-Id: I88b7ab174d0f73bda975cf90c5aeb797961fe034
Reviewed-on: https://go-review.googlesource.com/35511
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
lparth pushed a commit to lparth/go that referenced this issue Apr 13, 2017
Current code doesn't support floating point #define macros.
This CL compiles floats to a object file and retrive values from it.
That approach is the same work as we've already done for integers.

Updates golang#18720

Change-Id: I88b7ab174d0f73bda975cf90c5aeb797961fe034
Reviewed-on: https://go-review.googlesource.com/35511
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
@gopherbot
Copy link

CL https://golang.org/cl/41312 mentions this issue.

@gopherbot
Copy link

CL https://golang.org/cl/41910 mentions this issue.

@gopherbot
Copy link

CL https://golang.org/cl/43970 mentions this issue.

gopherbot pushed a commit that referenced this issue May 23, 2017
Current code cannot handle string #define macros if those macros are
defined via other macros. This CL solve the issue.

Updates #18720

Change-Id: Ibed0773d10db3d545bb246b97e81c0d19e3af3d5
Reviewed-on: https://go-review.googlesource.com/41312
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
@ALTree
Copy link
Member

ALTree commented Jun 3, 2017

No CL for this and we're deep in the freeze, moving to go1.10.

@ALTree ALTree modified the milestones: Go1.10, Go1.9Maybe Jun 3, 2017
@hirochachacha
Copy link
Contributor Author

I didn't complete that because it conflicts with https://go-review.googlesource.com/c/44290/
Now, I did.

@gopherbot
Copy link

Change https://golang.org/cl/86475 mentions this issue: cmd/cgo: support niladic macros for gccgo

gopherbot pushed a commit that referenced this issue Jan 10, 2018
https://golang.org/cl/43970 changed writeOutputFunc to support niladic
function-like macros; apply the corresponding change to
writeGccgoOutputFunc.

Updates #10715
Updates #18720

Change-Id: I5decb1d37ec71507466ade2eeda4b89c8785eaef
Reviewed-on: https://go-review.googlesource.com/86475
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Hiroshi Ioka <hirochachacha@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
@golang golang locked and limited conversation to collaborators Jan 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants