Skip to content

Commit 0219936

Browse files
authored
Pragma pack (#652)
* parser: emit #pragma pack * ignore unknown pragmas again * Docker: build with any user id * stdlib depends on the hardware-addresses file * WIP pack * move stuff to translation semantics * fix missing import * pragma pack * try fix Jenkinsfile * try fix Jenkinsfile * try fix Jenkinsfile * try fix Jenkinsfile * try fix jenkinsfile * try fix Jenkinsfile * try fix Jenkinsfile * Try fix Jenkinsfile * Try fix Jenkinsfile * see what happens * It looks like something strips the command * There is probably a newline comming from sh * cache MaxAlign in fieldInfo * Remove commented code
1 parent e068f19 commit 0219936

File tree

26 files changed

+243
-135
lines changed

26 files changed

+243
-135
lines changed

Diff for: Dockerfile

+6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ RUN git clone 'https://github.com/z3prover/z3' --branch=z3-4.8.7 \
2020
&& cd ../.. \
2121
&& rm -rf z3
2222

23+
ARG USER_ID=1000
24+
ARG GROUP_ID=1000
25+
2326
# This user is set up in the runtimeverificationinc/kframework:* images.
27+
RUN usermod -u $USER_ID user
2428
USER user:user
2529

2630
##################
@@ -58,3 +62,5 @@ RUN cd ${DEPS_DIR}/k \
5862
-Dcheckstyle.skip
5963

6064
ENV K_BIN="${DEPS_DIR}/k/k-distribution/target/release/k/bin"
65+
66+
ENTRYPOINT ["./scripts/docker-entrypoint.sh"]

Diff for: Jenkinsfile

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ pipeline {
2121
} }
2222
stage ( 'Build docker image' ) { steps {
2323
script {
24-
img = docker.build "c-semantics:${env.CHANGE_ID}"
24+
def uid = sh([returnStdout: true, script: 'id -u']).trim()
25+
def gid = sh([returnStdout: true, script: 'id -g']).trim()
26+
img = docker.build("c-semantics:${env.CHANGE_ID}", "--build-arg=USER_ID=${uid} --build-arg=GROUP_ID=${gid} .")
2527
}
2628
} }
2729
stage ( 'Compile' ) {

Diff for: Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ $(LIBSTDCXX_SO): $(call timestamp_of,c-cpp-linking) \
207207
$(call timestamp_of,cpp-translation) \
208208
$(wildcard $(PROFILE_DIR)/compiler-src/*.C) \
209209
$(foreach d,$(SUBPROFILE_DIRS),$(wildcard $(d)/compiler-src/*)) \
210+
$(OUTPUT_DIR)/hardware-addresses.timestamp \
210211
PROFILE_DEPS
211212
@$(LOGGER) "$(PROFILE): Translating the C++ standard library..."
212213
@cd $(PROFILE_DIR)/compiler-src && \
@@ -230,6 +231,7 @@ $(LIBC_SO): $(call timestamp_of,c-cpp-linking) \
230231
$(call timestamp_of,c-translation) \
231232
$(wildcard $(PROFILE_DIR)/src/*.c) \
232233
$(foreach d,$(SUBPROFILE_DIRS),$(wildcard $(d)/src/*.c)) \
234+
$(OUTPUT_DIR)/hardware-addresses.timestamp \
233235
PROFILE_DEPS
234236
@$(LOGGER) "$(PROFILE): Translating the C standard library..."
235237
@cd $(PROFILE_DIR)/src && \

Diff for: parser/cabs.ml

+1
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ and expression =
315315
| LTL_O of string * expression
316316
(* | LTL_UNTIL of expression * expression
317317
| LTL_RELEASE of expression * expression *)
318+
| PACK of expression
318319

319320
and generic_association =
320321
| GENERIC_PAIR of type_name * expression

Diff for: parser/clexer.mll

+2-1
Original file line numberDiff line numberDiff line change
@@ -612,10 +612,11 @@ and hash = parse
612612
(* A file name may follow *)
613613
file lexbuf }
614614
| "line" { addWhite lexbuf; hash lexbuf } (* MSVC line number info *)
615+
| "pragma" blank "pack" { PRAGMA_PACK }
615616
(* For pragmas with irregular syntax, like #pragma warning,
616617
* we parse them as a whole line. *)
617618
| "pragma" blank
618-
{ addWhite lexbuf; hash lexbuf }
619+
{ (*pragmaLine := true;*) PRAGMA (currentLoc ()) ; addWhite lexbuf; hash lexbuf }
619620
| _ { addWhite lexbuf; endline lexbuf}
620621

621622
and file = parse

Diff for: parser/cparser.mly

+7
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ let trd3 (_, _, result) = result
289289
%token<Cabs.cabsloc> BEGINANNOTATION ENDANNOTATION
290290
%token<Cabs.cabsloc> PROPERTY
291291
%token LTL ATOM LTL_BUILTIN_TOK
292+
%token PRAGMA_PACK
292293
%token BACKTICK BACKSLASH
293294

294295
/* sm: cabs tree transformation specification keywords */
@@ -1315,10 +1316,16 @@ pragma:
13151316
| PRAGMA attr SEMICOLON PRAGMA_EOL { PRAGMA ($2, $1) }
13161317
| PRAGMA_LINE { PRAGMA (VARIABLE (fst $1),
13171318
snd $1) }
1319+
| PRAGMA_PACK pragma_pack { $2 }
13181320
| PRAGMA LTL ltl_pragma PRAGMA_EOL { $3 }
13191321
| PRAGMA PRAGMA_EOL { PRAGMA (VARIABLE "", $1) }
13201322
;
13211323

1324+
pragma_pack:
1325+
| LPAREN RPAREN { PRAGMA (PACK NOTHING, $1) }
1326+
| LPAREN constant RPAREN { PRAGMA (PACK (CONSTANT (fst $2)), $1) }
1327+
1328+
13221329
ltl_pragma:
13231330
| IDENT COLON ltl_expression { LTL_ANNOTATION ((fst $1), (fst $3), (snd $1)) }
13241331

Diff for: parser/kPrinter.ml

+1
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,7 @@ and expression =
488488
| GNU_BODY blk -> kapply KItem "GnuBody" [lazy_block blk KItem]
489489
| BITMEMBEROF (exp, fld) -> kapply KItem "DotBit" [lazy_expression exp KItem; identifier fld CId]
490490
| EXPR_PATTERN s -> kapply KItem "ExpressionPattern" [ktoken_string s String]
491+
| PACK exp -> kapply KItem "PragmaPack" [lazy_expression exp KItem]
491492
and lazy_expression = fun a sort -> LazyPrinter ((fun aa -> expression aa sort), a)
492493

493494
and type_spec =

Diff for: profiles/x86-gcc-limited-libc/semantics/c-settings.k

+2-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ module C-SETTINGS
6565
rule cfg:alignofOversizedFloat => 16
6666
rule cfg:alignofPointer => 8
6767
// Max of the above.
68-
rule cfg:alignofMalloc => 16
68+
rule cfg:defaultMaxAlign => 16
69+
rule cfg:alignofMalloc => cfg:defaultMaxAlign
6970

7071
rule cfg:intToPointer(0, _) => NullPointer
7172
rule cfg:intToPointer(_, _) => trap [owise]

Diff for: scripts/docker-build

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
docker build --build-arg USER_ID=$(id -u) --build-arg GROUP_ID=$(id -g) -t old-c-semantics .
3+
docker run --rm --mount src=$(pwd),target=/home/user/c-semantics,type=bind --workdir=/home/user/c-semantics old-c-semantics make

Diff for: scripts/docker-entrypoint.sh

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
eval $(opam config env)
4+
eval $(perl -I "~/perl5/lib/perl5" -Mlocal::lib)
5+
exec "$@"

Diff for: scripts/rid

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
# run-in-docker (rid)
3+
docker run --rm --mount src=$(pwd),target=/home/user/c-semantics,type=bind --workdir=/home/user/c-semantics old-c-semantics "$@"

Diff for: semantics/c/language/common/alignment.k

+2-9
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,9 @@ module C-ALIGNMENT
6868
// TODO(dwightguth): make sure we correctly handle all the corner cases
6969
rule byteAlignofType'(_) => 1 [owise]
7070

71-
rule maxByteAlignofDecls(L:List) => maxByteAlignofDecls'(1, L)
72-
73-
syntax Int ::= "maxByteAlignofDecls'" "(" Int "," List ")" [function]
74-
rule maxByteAlignofDecls'(Sz::Int, ListItem(typedDeclaration(T::Type, _)) LL:List)
75-
=> maxByteAlignofDecls'(maxInt(Sz, byteAlignofType(T)), LL)
76-
rule maxByteAlignofDecls'(Sz::Int, .List) => Sz
77-
7871
syntax Int ::= byteAlignofTagged(TagInfo) [function]
79-
rule byteAlignofTagged(fieldInfo(Decls:List, _, _, _, _))
80-
=> maxByteAlignofDecls(Decls)
72+
rule byteAlignofTagged(fieldInfo(_, _, _, _, _, MaxAlign:Int))
73+
=> MaxAlign
8174
rule byteAlignofTagged(enumInfo(... enumAlias: T::SimpleIntegerType))
8275
=> byteAlignofType'(type(T))
8376
rule byteAlignofTagged(_) => 1 [owise]

Diff for: semantics/c/language/common/bitsize.k

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ module C-BITSIZE
6262
rule maxByteSizeofList'(Sz:Int, .List) => Sz
6363

6464
syntax Int ::= bitSizeofFields(FieldInfo) [function]
65-
rule bitSizeofFields(fieldInfo(_, NBits:Int, _, _, _)) => NBits
65+
rule bitSizeofFields(fieldInfo(_, NBits:Int, _, _, _, _)) => NBits
6666
rule bitSizeofFields(_) => 0 [owise]
6767

6868
endmodule

Diff for: semantics/c/language/common/memory/writing.k

+3-3
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ module C-MEMORY-WRITING
195195

196196
syntax KItem ::= initStructPadding(SymLoc, FieldInfo, Bool)
197197
rule (.K => initPaddingByte(Loc +bits I, Trap))
198-
~> initStructPadding(Loc::SymLoc, fieldInfo(_, Sz::Int, _, _, (SetItem(I::Int) => .Set) _), Trap::Bool)
199-
rule initStructPadding(_, fieldInfo(_, _, _, _, .Set), _) => .K
198+
~> initStructPadding(Loc::SymLoc, fieldInfo(_, Sz::Int, _, _, (SetItem(I::Int) => .Set) _, _), Trap::Bool)
199+
rule initStructPadding(_, fieldInfo(_, _, _, _, .Set, _), _) => .K
200200

201201
syntax K ::= initFieldPadding(SymLoc, Type, CId, Bool) [function]
202202
rule initFieldPadding(Loc::SymLoc, T::Type, F::CId, Trap::Bool)
@@ -347,7 +347,7 @@ module C-MEMORY-WRITING
347347
rule splitStructPartialBytes(_, _, 0) => .List
348348

349349
syntax Bool ::= isPaddingOffset(Int, K) [function]
350-
rule isPaddingOffset(Offset::Int, fieldInfo(_, _, _, _, PaddingOffs::Set))
350+
rule isPaddingOffset(Offset::Int, fieldInfo(_, _, _, _, PaddingOffs::Set, _))
351351
=> Offset *Int cfg:bitsPerByte in PaddingOffs
352352

353353
rule writeChars(Loc::SymLoc, S::String)

Diff for: semantics/c/language/common/settings.k

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ module C-SETTINGS-SYNTAX
4444
syntax Int ::= "cfg:alignofLongDouble" [function]
4545
syntax Int ::= "cfg:alignofOversizedFloat" [function]
4646
syntax Int ::= "cfg:alignofPointer" [function]
47+
syntax Int ::= "cfg:defaultMaxAlign" [function]
4748
syntax Int ::= "cfg:alignofMalloc" [function]
4849

4950
syntax UType

Diff for: semantics/c/language/common/typing.k

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ module C-TYPING-SYNTAX
6262

6363
// TODO(chathhorn): move?
6464
// Offsets and field names for structs and unions.
65-
syntax FieldInfo ::= fieldInfo(List, Int, Map, Map, Set)
65+
syntax FieldInfo ::= fieldInfo(List, Int, Map, Map, Set, Int)
6666
syntax EnumInfo ::= enumInfo(enumAlias: SimpleIntegerType, ctMap: Map)
6767
syntax TagInfo ::= FieldInfo | EnumInfo
6868
syntax SimpleIntegerType ::= getEnumAlias(TagId) [function]

Diff for: semantics/c/language/common/typing/common.k

+2-2
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ module C-TYPING-COMMON
115115

116116
syntax FieldInfo ::= toFieldInfo(TagInfo) [function]
117117
rule toFieldInfo(Fields:FieldInfo) => Fields
118-
rule toFieldInfo(_) => fieldInfo(.List, 0, .Map, .Map, .Set) [owise]
118+
rule toFieldInfo(_) => fieldInfo(.List, 0, .Map, .Map, .Set, 0) [owise]
119119

120120
syntax Bool ::= hasNoName(Map) [function]
121121
rule hasNoName((_:NoName |-> structOrUnionType) _::Map) => true
@@ -126,7 +126,7 @@ module C-TYPING-COMMON
126126
<global>... <tags> M::Map </tags> ...</global>
127127

128128
syntax TagInfo ::= extractTagInfo(K) [function]
129-
rule extractTagInfo(fieldInfo(L::List, I::Int, M1::Map, M2::Map, S::Set)) => fieldInfo(L, I, M1, M2, S)
129+
rule extractTagInfo(fieldInfo(L::List, I::Int, M1::Map, M2::Map, S::Set, MaxAlign::Int)) => fieldInfo(L, I, M1, M2, S, MaxAlign)
130130
rule extractTagInfo(enumInfo(...) #as EI::EnumInfo) => EI
131131
rule extractTagInfo(_) => #incomplete [owise]
132132

Diff for: semantics/c/language/common/typing/compatibility.k

+2-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ module C-TYPING-COMPATIBILITY
113113
Cache SetItem(kpair(S, S'))))
114114

115115
syntax Bool ::= #areStructsCompat(FieldInfo, FieldInfo, Set) [function, memo]
116-
rule #areStructsCompat(fieldInfo(Fs::List, _, _, _, _), fieldInfo(Fs'::List, _, _, _, _), Cache::Set)
116+
// TODO: are they compatible even if one was packed using attribute or pragma?
117+
rule #areStructsCompat(fieldInfo(Fs::List, _, _, _, _, _), fieldInfo(Fs'::List, _, _, _, _, _), Cache::Set)
117118
=> #areCompatFields(Fs, Fs', Cache)
118119
requires Fs =/=K .List andBool Fs' =/=K .List
119120
rule #areStructsCompat(_, _, _) => true [owise]

0 commit comments

Comments
 (0)