This is an archive of the discontinued LLVM Phabricator instance.

[libFuzzer] Create single template for visiting Inline8bitCounters
ClosedPublic

Authored by kevinwkt on Jul 17 2018, 2:03 PM.

Details

Summary

Created IterateInline8bitCounters, a single template for visiting Inline8bitCounters (nested for loop)
Made InitializeUnstableCounters and UpdateUnstableCounters both send a lambda to IterateInline8bitCounters.

Patch by Kyungtak Woo (@kevinwkt).

Diff Detail

Event Timeline

kevinwkt created this revision.Jul 17 2018, 2:03 PM
Dor1s added a comment.Jul 17 2018, 2:44 PM

Left some minor comments, but I think it's fine to ask Matt or Kostya to take a look and address all the feedback altogether, just to avoid changing things back and forth if we have different opinions.

lib/fuzzer/FuzzerTracePC.cpp
68–69

I don't like getting an address of an array element, IMO Beg + j would be better, but let's see what the code owners think.

77

change beg to Beg

and actually it's not a "beginning" anymore, needs another name, maybe CounterPtr or just Counter.

86–89

beg -> Beg

lib/fuzzer/FuzzerTracePC.h
182

nit: not a language expert myself, but maybe this should be IterateOverInline8bitCounters. Current version LGTM as well.

metzman accepted this revision.Jul 17 2018, 2:49 PM

LGTM with Max's suggestions

This revision is now accepted and ready to land.Jul 17 2018, 2:49 PM
kevinwkt updated this revision to Diff 155975.Jul 17 2018, 2:58 PM
kevinwkt marked 2 inline comments as done.
kevinwkt added reviewers: kcc, morehouse.

Changed beg to Counter for both InitializeUnstableCounters and UpdateUnstableCounters.

Maybe change the callback signature to take i, j, and UnstableIdx instead. Then we can also use IterateInline8bitCounters from UpdateObservedPCs.

lib/fuzzer/FuzzerTracePC.cpp
68–69

Can we just pass Beg[j] instead?

kevinwkt updated this revision to Diff 155982.EditedJul 17 2018, 4:21 PM

PTAL
Changed callback signature from "UnstableIdx, &Beg[j]" to "i, j, UnstableIdx".
Modified UpdateObservedPCs to use the template function.

Did not use template function for case: NumGuards == NumPCsInPCTables because of initial check in template function.

morehouse added inline comments.Jul 17 2018, 4:32 PM
lib/fuzzer/FuzzerTracePC.cpp
62

Maybe this should be an assert.

63

Since we've generalized this function, we might want to change this variable to a more general name (e.g., CounterIdx).

kevinwkt updated this revision to Diff 155987.EditedJul 17 2018, 4:45 PM
kevinwkt marked 4 inline comments as done.

ptal
Changed UnstableIdx to CounterIdx.
Moved initial " NumInline8bitCounters && NumInline8bitCounters == NumPCsInPCTables" out of "IterateInline8bitCounters" to use it also in case: NumGuards == NumPCsInPCTables within UpdateObservedPCs().

morehouse added inline comments.Jul 18 2018, 9:15 AM
lib/fuzzer/FuzzerTracePC.cpp
209

I don't think this will work. IterateInline8bitCounters iterates over ModuleCounters, not Modules.

kevinwkt updated this revision to Diff 156093.Jul 18 2018, 9:21 AM

ptal: fixed
Reverted for when Guards are used.
UnstableIdx is still changed to CounterIdx

morehouse accepted this revision.Jul 18 2018, 9:27 AM
Dor1s updated this revision to Diff 156100.Jul 18 2018, 9:51 AM

Rebase and getting ready to land.

Herald added subscribers: Restricted Project, llvm-commits, delcypher. · View Herald TranscriptJul 18 2018, 9:51 AM
Dor1s edited the summary of this revision. (Show Details)Jul 18 2018, 9:52 AM
kevinwkt updated this revision to Diff 156101.Jul 18 2018, 9:57 AM
kevinwkt marked an inline comment as done.

Fixed syntax error causing CounterIdx error.

This revision was automatically updated to reflect the committed changes.