{"action":"closed","issue":{"url":"https://api.github.com/repos/CTSRD-CHERI/clang/issues/77","labels_url":"https://api.github.com/repos/CTSRD-CHERI/clang/issues/77/labels{/name}","comments_url":"https://api.github.com/repos/CTSRD-CHERI/clang/issues/77/comments","events_url":"https://api.github.com/repos/CTSRD-CHERI/clang/issues/77/events","html_url":"https://github.com/CTSRD-CHERI/clang/issues/77","id":122413990,"number":77,"title":"wrong function pointer initialization in static initializer for array of structs","user":{"login":"brooksdavis","id":3629693,"avatar_url":"https://avatars.githubusercontent.com/u/3629693?v=3","gravatar_id":"","url":"https://api.github.com/users/brooksdavis","html_url":"https://github.com/brooksdavis","followers_url":"https://api.github.com/users/brooksdavis/followers","following_url":"https://api.github.com/users/brooksdavis/following{/other_user}","gists_url":"https://api.github.com/users/brooksdavis/gists{/gist_id}","starred_url":"https://api.github.com/users/brooksdavis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brooksdavis/subscriptions","organizations_url":"https://api.github.com/users/brooksdavis/orgs","repos_url":"https://api.github.com/users/brooksdavis/repos","events_url":"https://api.github.com/users/brooksdavis/events{/privacy}","received_events_url":"https://api.github.com/users/brooksdavis/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/CTSRD-CHERI/clang/labels/bug","name":"bug","color":"fc2929"},{"url":"https://api.github.com/repos/CTSRD-CHERI/clang/labels/Pure%20capability%20ABI","name":"Pure capability ABI","color":"bfd4f2"}],"state":"closed","locked":false,"assignee":{"login":"davidchisnall","id":404454,"avatar_url":"https://avatars.githubusercontent.com/u/404454?v=3","gravatar_id":"","url":"https://api.github.com/users/davidchisnall","html_url":"https://github.com/davidchisnall","followers_url":"https://api.github.com/users/davidchisnall/followers","following_url":"https://api.github.com/users/davidchisnall/following{/other_user}","gists_url":"https://api.github.com/users/davidchisnall/gists{/gist_id}","starred_url":"https://api.github.com/users/davidchisnall/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidchisnall/subscriptions","organizations_url":"https://api.github.com/users/davidchisnall/orgs","repos_url":"https://api.github.com/users/davidchisnall/repos","events_url":"https://api.github.com/users/davidchisnall/events{/privacy}","received_events_url":"https://api.github.com/users/davidchisnall/received_events","type":"User","site_admin":false},"milestone":null,"comments":4,"created_at":"2015-12-16T02:36:32Z","updated_at":"2015-12-16T11:32:18Z","closed_at":"2015-12-16T11:32:18Z","body":"This preprocessed file as compiled with the following command results in a bogus initialization of a function pointer in `compat_setgrent()`.\r\n\r\nhttps://gist.github.com/brooksdavis/d13440a27985fa717bf2\r\n\r\n```\r\n/home/bed22/git/llvm-cheri/Build/bin/clang -g -integrated-as --target=cheri-unknown-freebsd  -msoft-float --sysroot=/home/bed22/obj/mips.mips64/home/bed22/git/cheribsd/tmp -mabi=sandbox -cheri-linker  -O -pipe -G0   -I/home/bed22/git/cheribsd/lib/libc/include -I/home/bed22/git/cheribsd/lib/libc/../../include -I/home/bed22/git/cheribsd/lib/libc/mips -DNLS  -DSOFTFLOAT -D__DBINTERFACE_PRIVATE -I/home/bed22/git/cheribsd/lib/libc/../../contrib/gdtoa -I/home/bed22/git/cheribsd/lib/libc/../../contrib/libc-vis -DINET6 -I/home/bed22/obj/mips.mips64/home/bed22/git/cheribsd/worldcheri/home/bed22/git/cheribsd/lib/libc -I/home/bed22/git/cheribsd/lib/libc/resolv -D_ACL_PRIVATE -DPOSIX_MISTAKE -I/home/bed22/git/cheribsd/lib/libc/../libmd -I/home/bed22/git/cheribsd/lib/libc/../../contrib/tzcode/stdtime -I/home/bed22/git/cheribsd/lib/libc/stdtime  -I/home/bed22/git/cheribsd/lib/libc/locale -DBROKEN_DES -DPORTMAP -DDES_BUILTIN -I/home/bed22/git/cheribsd/lib/libc/rpc -I/home/bed22/git/cheribsd/lib/libc/mips/softfloat  -I/home/bed22/git/cheribsd/lib/libc/softfloat -DSOFTFLOAT_FOR_GCC -DYP -DNS_CACHING -DSYMBOL_VERSIONING -O0 -Wno-error  -std=gnu99 -Wsystem-headers -Werror -Wall -Wno-format-y2k -Wno-uninitialized -Wno-pointer-sign -Wno-empty-body -Wno-string-plus-int -Wno-unused-const-variable -Wno-tautological-compare -Wno-unused-value -Wno-parentheses-equality -Wno-unused-function -Wno-enum-conversion -Wno-unused-local-typedef -Wno-switch -Wno-switch-enum -Wno-knr-promoted-parameter -Qunused-arguments -I/home/bed22/git/cheribsd/lib/libutil -I/home/bed22/git/cheribsd/lib/msun/mips -I/home/bed22/git/cheribsd/lib/msun/src -c /home/bed22/git/cheribsd/lib/libc/gen/getgrent.c\r\n```\r\n\r\nSpecifically the function begins with:\r\n```\r\nstatic int\r\ncompat_setgrent(void *retval, void *mdata, va_list ap)\r\n{\r\n        static const ns_src compatsrc[] = {\r\n#ifdef YP\r\n                { NSSRC_NIS, NS_SUCCESS },\r\n#endif\r\n                { NULL, 0 }\r\n        };\r\n       ns_dtab dtab[] = {\r\n#ifdef HESIOD\r\n                { NSSRC_DNS, dns_setgrent, NULL },\r\n#endif\r\n#ifdef YP\r\n                { NSSRC_NIS, nis_setgrent, NULL },\r\n#endif\r\n                { NULL, NULL, NULL }\r\n        };\r\n```\r\n\r\nThe generated initialization of `dtab` is:\r\n```\r\n       ns_dtab dtab[] = {\r\n   120028738:   64228f48        daddiu  v0,at,-28856\r\n   12002873c:   48810087        cfromptr        c1,c0,v0  \r\n   120028740:   c8410003        cld     v0,zero,0(c1)\r\n   120028744:   48000807        cgetpcc c1\r\n   120028748:   49a10881        csetoffset      c1,c1,v0\r\n   12002874c:   49a33800        cmove   c3,c7\r\n   120028750:   00602825        move    a1,v1\r\n   120028754:   0020e025        move    gp,at\r\n   120028758:   67c60220        daddiu  a2,s8,544\r\n   12002875c:   f98b3000        csc     c12,a2,0(c11)\r\n   120028760:   49ac0800        cmove   c12,c1\r\n   120028764:   67c60218        daddiu  a2,s8,536\r\n   120028768:   e82b3003        csd     at,a2,0(c11)\r\n   12002876c:   f9abf1e0        csc     c13,s8,480(c11)  \r\n   120028770:   f94bf1c0        csc     c10,s8,448(c11)\r\n   120028774:   f90bf1a0        csc     c8,s8,416(c11)  \r\n   120028778:   f9cbf180        csc     c14,s8,384(c11)\r\n   12002877c:   f92bf160        csc     c9,s8,352(c11)   \r\n   120028780:   f8ebf140        csc     c7,s8,320(c11)  \r\n   120028784:   f9ebf120        csc     c15,s8,288(c11)\r\n   120028788:   f84bf100        csc     c2,s8,256(c11)   \r\n   12002878c:   f8cbf0e0        csc     c6,s8,224(c11)  \r\n   120028790:   48f16000        cjalr   c17,c12  \r\n   120028794:   00000000        nop\r\n   120028798:   67dc0218        daddiu  gp,s8,536\r\n   12002879c:   c82be003        cld     at,gp,0(c11)\r\n   1200287a0:   dc228048        ld      v0,-32696(at)\r\n   1200287a4:   64424140        daddiu  v0,v0,16704\r\n   1200287a8:   48810087        cfromptr        c1,c0,v0\r\n   1200287ac:   d84bf140        clc     c2,s8,320(c11)\r\n   1200287b0:   f8220000        csc     c1,zero,0(c2)\r\n   1200287b4:   dc228098        ld      v0,-32616(at)\r\n   1200287b8:   644284d8        daddiu  v0,v0,-31528\r\n   1200287bc:   48810087        cfromptr        c1,c0,v0  \r\n   1200287c0:   d84bf140        clc     c2,s8,320(c11)\r\n   1200287c4:   f8220020        csc     c1,zero,32(c2)\r\n```\r\nFrom examining a trace, I've determined that `1200287b8` results in `v0` being the offset of `nis_setgrent`.  `cfromptr` isn't totally wrong, but being relative to `c0` is.  My attempts to create a tests case from scratch have thus far done the right thing and done a `csetoffset` on the result of `cgetpcc`.\r\n"}}