Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/topic/vern/CPP-Oct22-maint'
Browse files Browse the repository at this point in the history
* origin/topic/vern/CPP-Oct22-maint:
  -O C++ maintenance updates to test suite
  -O gen-C++ maintenance: fixes for attributes & initializing globals
  • Loading branch information
timwoj committed Oct 17, 2022
2 parents ea57cac + f4c1309 commit 0143d0c
Show file tree
Hide file tree
Showing 18 changed files with 109 additions and 13 deletions.
6 changes: 6 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
5.2.0-dev.108 | 2022-10-17 16:18:55 -0700

* -O C++ maintenance updates to test suite (Vern Paxson, Corelight)

* -O gen-C++ maintenance: fixes for attributes & initializing globals (Vern Paxson, Corelight)

5.2.0-dev.105 | 2022-10-17 08:48:20 -0700

* Surface a better CMake error if the user passes an invalid sanitizer name (Tim Wojtulewicz, Corelight)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.2.0-dev.105
5.2.0-dev.108
10 changes: 10 additions & 0 deletions src/script_opt/CPP/Consts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ shared_ptr<CPP_InitInfo> CPPCompile::RegisterConstant(const ValPtr& vp, int& con
// render the same.
t->Describe(&d);

// Likewise, tables that have attributes.
if ( t->Tag() == TYPE_TABLE )
{
const auto& attrs = v->AsTableVal()->GetAttrs();
if ( attrs )
attrs->Describe(&d);
else
d.Add("<no-attrs>");
}

c_desc = d.Description();
}

Expand Down
14 changes: 10 additions & 4 deletions src/script_opt/CPP/Driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,11 @@ void CPPCompile::RegisterCompiledBody(const string& f)

void CPPCompile::GenEpilog()
{
NL();
InitializeGlobals();
if ( standalone )
{
NL();
InitializeGlobals();
}

NL();
for ( const auto& ii : init_infos )
Expand Down Expand Up @@ -472,8 +475,11 @@ void CPPCompile::GenFinishInit()
NL();
Emit("load_BiFs__CPP();");

NL();
Emit("init_globals__CPP();");
if ( standalone )
{
NL();
Emit("init_globals__CPP();");
}

EndBlock();
}
Expand Down
16 changes: 10 additions & 6 deletions src/script_opt/CPP/Inits.cc
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,7 @@ void CPPCompile::InitializeGlobals()
auto& init = ginit.Init();

if ( ic == INIT_NONE )
{
IDPtr gid = {NewRef{}, const_cast<ID*>(g)};
auto gn = make_intrusive<RefExpr>(make_intrusive<NameExpr>(gid));
auto ae = make_intrusive<AssignExpr>(gn, init, true);
Emit(GenExpr(ae.get(), GEN_NATIVE, true) + ";");
}
Emit(GenExpr(init, GEN_NATIVE, true) + ";");

else
{
Expand All @@ -227,6 +222,15 @@ void CPPCompile::InitializeGlobals()

Emit("%s->SetValue(%s, %s);", globals[g->Name()], GenExpr(init, GEN_NATIVE, true), ics);
}

const auto& attrs = g->GetAttrs();
if ( attrs )
{
string attr_tags;
string attr_vals;
BuildAttrs(attrs, attr_tags, attr_vals);
Emit("assign_attrs__CPP(%s, %s, %s);", globals[g->Name()], attr_tags, attr_vals);
}
}

EndBlock();
Expand Down
10 changes: 10 additions & 0 deletions src/script_opt/CPP/InitsInfo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,16 @@ TableConstInfo::TableConstInfo(CPPCompile* c, ValPtr v) : CompoundItemInfo(c, v)
{
auto tv = cast_intrusive<TableVal>(v);

auto gi = c->RegisterAttributes(tv->GetAttrs());
int attrs = -1;
if ( gi )
{
init_cohort = max(init_cohort, gi->InitCohort() + 1);
attrs = gi->Offset();
}

vals.emplace_back(std::to_string(attrs));

for ( auto& tv_i : tv->ToMap() )
{
vals.emplace_back(ValElem(c, tv_i.first)); // index
Expand Down
4 changes: 4 additions & 0 deletions src/script_opt/CPP/RuntimeInits.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,14 @@ void CPP_IndexedInits<T>::Generate(InitsManager* im, std::vector<TableValPtr>& i
auto iv_it = init_vals.begin();
auto iv_end = init_vals.end();
auto t = *(iv_it++);
auto attrs = *(iv_it++);

auto tt = cast_intrusive<TableType>(im->Types(t));
auto tv = make_intrusive<TableVal>(tt);

if ( attrs >= 0 )
tv->SetAttrs(im->Attributes(attrs));

while ( iv_it != iv_end )
{
auto index = im->ConstVals(*(iv_it++));
Expand Down
5 changes: 5 additions & 0 deletions src/script_opt/CPP/RuntimeOps.cc
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,11 @@ TableValPtr table_constructor__CPP(vector<ValPtr> indices, vector<ValPtr> vals,
return aggr;
}

void assign_attrs__CPP(IDPtr id, std::vector<int> attr_tags, std::vector<ValPtr> attr_vals)
{
id->SetAttrs(build_attrs__CPP(move(attr_tags), move(attr_vals)));
}

RecordValPtr record_constructor__CPP(vector<ValPtr> vals, RecordTypePtr t)
{
auto rv = make_intrusive<RecordVal>(t);
Expand Down
3 changes: 3 additions & 0 deletions src/script_opt/CPP/RuntimeOps.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ extern TableValPtr table_constructor__CPP(std::vector<ValPtr> indices, std::vect
TableTypePtr t, std::vector<int> attr_tags,
std::vector<ValPtr> attr_vals);

// Assigns a set of attributes to an identifier.
extern void assign_attrs__CPP(IDPtr id, std::vector<int> attr_tags, std::vector<ValPtr> attr_vals);

// Constructs a record of the given type, whose (ordered) fields are
// assigned to the corresponding elements of the given vector of values.
extern RecordValPtr record_constructor__CPP(std::vector<ValPtr> vals, RecordTypePtr t);
Expand Down
2 changes: 1 addition & 1 deletion src/script_opt/CPP/maint/README
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The maintenance workflow:
to check in updates to the list of how the compiler currently fares
on various btests (see end of this doc):

Thu Sep 29 14:49:49 PDT 2022
Wed Oct 12 11:36:46 PDT 2022

2. Run "find-test-files.sh" to generate a list (to stdout) of all of the
possible Zeek source files found in the test suite.
Expand Down
2 changes: 1 addition & 1 deletion src/script_opt/CPP/maint/check-CPP-gen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ gen_out=CPP-test/gen.$abbr
echo "fail"
exit 1
fi
if grep -E -q 'deprecated|skipping|cannot compile|no matching functions' $gen_out; then
if grep -E -q '(deprecated.*(when|vector))|skipping|cannot compile|no matching functions' $gen_out; then
echo "fail"
exit 1
fi
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
analyzer_confirmation_info, AllAnalyzers::ANALYZER_ANALYZER_FTP, [orig_h=2001:470:1f05:17a6:d69a:20ff:fefd:6b88, orig_p=24316/tcp, resp_h=2001:6a8:a40::21, resp_p=21/tcp], 3
analyzer_confirmation, AllAnalyzers::ANALYZER_ANALYZER_FTP, [orig_h=2001:470:1f05:17a6:d69a:20ff:fefd:6b88, orig_p=24316/tcp, resp_h=2001:6a8:a40::21, resp_p=21/tcp], 3
analyzer_violation_info, AllAnalyzers::ANALYZER_ANALYZER_FTP, non-numeric reply code, [orig_h=2001:470:1f05:17a6:d69a:20ff:fefd:6b88, orig_p=24316/tcp, resp_h=2001:6a8:a40::21, resp_p=21/tcp], 3, SSH-2.0-mod_sftp/0.9.7
analyzer_violation, AllAnalyzers::ANALYZER_ANALYZER_FTP, non-numeric reply code [SSH-2.0-mod_sftp/0.9.7], [orig_h=2001:470:1f05:17a6:d69a:20ff:fefd:6b88, orig_p=24316/tcp, resp_h=2001:6a8:a40::21, resp_p=21/tcp], 3
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
analyzer_confirmation_info, AllAnalyzers::ANALYZER_ANALYZER_SSL, [orig_h=1.1.1.1, orig_p=20394/tcp, resp_h=2.2.2.2, resp_p=443/tcp], 3
analyzer_confirmation, AllAnalyzers::ANALYZER_ANALYZER_SSL, [orig_h=1.1.1.1, orig_p=20394/tcp, resp_h=2.2.2.2, resp_p=443/tcp], 3
analyzer_violation_info, AllAnalyzers::ANALYZER_ANALYZER_SSL, Invalid version late in TLS connection. Packet reported version: 0, [orig_h=1.1.1.1, orig_p=20394/tcp, resp_h=2.2.2.2, resp_p=443/tcp], 3
analyzer_violation, AllAnalyzers::ANALYZER_ANALYZER_SSL, Invalid version late in TLS connection. Packet reported version: 0, [orig_h=1.1.1.1, orig_p=20394/tcp, resp_h=2.2.2.2, resp_p=443/tcp], 3
2 changes: 2 additions & 0 deletions testing/btest/Baseline.cpp/coverage.basic-no-errors/.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
<...>/pp-alarms.zeek, line 100: Hello, Zeek!
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
11 changes: 11 additions & 0 deletions testing/btest/Baseline.cpp/coverage.basic-no-errors/reporter.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
#separator \x09
#set_separator ,
#empty_field (empty)
#unset_field -
#path reporter
#open XXXX-XX-XX-XX-XX-XX
#fields ts level message location
#types time enum string string
XXXXXXXXXX.XXXXXX Reporter::INFO Hello, Zeek! <...>/pp-alarms.zeek, line 100
#close XXXX-XX-XX-XX-XX-XX
3 changes: 3 additions & 0 deletions testing/btest/Baseline.cpp/language.expire-expr-error/output
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
runtime error in compiled code: no such index
received termination signal
21 changes: 21 additions & 0 deletions testing/btest/Baseline.cpp/language.expire-func-undef/output
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
1299470395.000000 expression error in <no location>: value used but not set (segfault::scan_summary)
1299470405.000000 expression error in <no location>: value used but not set (segfault::scan_summary)
1299473995.000000 expression error in <no location>: value used but not set (segfault::scan_summary)
1299474005.000000 expression error in <no location>: value used but not set (segfault::scan_summary)
1299477595.000000 expression error in <no location>: value used but not set (segfault::scan_summary)
1299477605.000000 expression error in <no location>: value used but not set (segfault::scan_summary)
1299481195.000000 expression error in <no location>: value used but not set (segfault::scan_summary)
1299481205.000000 expression error in <no location>: value used but not set (segfault::scan_summary)
1299484795.000000 expression error in <no location>: value used but not set (segfault::scan_summary)
1299484805.000000 expression error in <no location>: value used but not set (segfault::scan_summary)
1299488395.000000 expression error in <no location>: value used but not set (segfault::scan_summary)
1299488405.000000 expression error in <no location>: value used but not set (segfault::scan_summary)
1299491995.000000 expression error in <no location>: value used but not set (segfault::scan_summary)
1299492005.000000 expression error in <no location>: value used but not set (segfault::scan_summary)
1299495595.000000 expression error in <no location>: value used but not set (segfault::scan_summary)
1299495605.000000 expression error in <no location>: value used but not set (segfault::scan_summary)
1299499195.000000 expression error in <no location>: value used but not set (segfault::scan_summary)
1299499205.000000 expression error in <no location>: value used but not set (segfault::scan_summary)
1299502795.000000 expression error in <no location>: value used but not set (segfault::scan_summary)
orig: 10.0.0.2: peers: {\x0a\x0910.0.0.3\x0a}

0 comments on commit 0143d0c

Please sign in to comment.