On 5/15/19 10:12 AM, Shubham Narlawar wrote: > Hello Martin and community, > > Below is attached patch for Function Attribute Aligned - > > The command line option to generate aligned attribute is - > --func-attr-aligned which can be found in ./csmith --help > > Please review the patch and suggest changes if any. > > The process of adding any extension is same - > 1. Implement an extension > 2. Send patch for review to community. > 3. Test GCC compiler and report bugs if found any. > 4. Push patch into github fork. > Continue. > > I have a query regarding C extension "function attribute alias". Is it > correct way to add aliasing for functions in csmith program as shown below - > > e.g. In csmith program, output aliasing below function declaration looks like > - > > //--------function-------declarations---------- > void func_1(); > void func_3(); > ..... > > void foo1() __attribute__ ((weak, alias("func_1"))); > void foo3() __attribute__ ((weak, alias("func_3"))); > ...... > > Looking forward to do this project with GCC community. > > Thanks > Shubham > > func_attr_aligned.patch > > diff --git a/src/CGOptions.cpp b/src/CGOptions.cpp > index b74375a..98c629b 100644 > --- a/src/CGOptions.cpp > +++ b/src/CGOptions.cpp > @@ -202,6 +202,7 @@ DEFINE_GETTER_SETTER_BOOL(fast_execution); > > //GCC C Extensions > DEFINE_GETTER_SETTER_BOOL(func_attr_inline); > +DEFINE_GETTER_SETTER_BOOL(func_attr_aligned); > > void > CGOptions::set_default_builtin_kinds() > diff --git a/src/CGOptions.h b/src/CGOptions.h > index 76887b8..a1aa389 100644 > --- a/src/CGOptions.h > +++ b/src/CGOptions.h > @@ -474,6 +474,9 @@ public: > static bool func_attr_inline(void); > static bool func_attr_inline(bool p); > > + static bool func_attr_aligned(void); > + static bool func_attr_aligned(bool p); > +
Hi. There you have a different indentation. > private: > static bool enabled_builtin_kind(const string &kind); > > @@ -623,6 +626,7 @@ private: > > //GCC C Extensions > static bool func_attr_inline_; > + static bool func_attr_aligned_; > private: > CGOptions(void); > CGOptions(CGOptions &cgo); > diff --git a/src/Function.cpp b/src/Function.cpp > index 9935552..1a769db 100644 > --- a/src/Function.cpp > +++ b/src/Function.cpp > @@ -396,6 +396,7 @@ Function::Function(const string &name, const Type > *return_type) > { > FuncList.push_back(this); // Add to global list > of functions. > func_attr_inline = false; > + func_attr_aligned = false; > } > > Function::Function(const string &name, const Type *return_type, bool builtin) > @@ -411,6 +412,7 @@ Function::Function(const string &name, const Type > *return_type, bool builtin) > { > FuncList.push_back(this); // Add to global list > of functions. > func_attr_inline = false; > + func_attr_aligned = false; > } > > Function * > @@ -434,8 +436,11 @@ Function::make_random_signature(const CGContext& > cg_context, const Type* type, c > if (CGOptions::inline_function() && rnd_flipcoin(InlineFunctionProb)) > f->is_inlined = true; > > - if(CGOptions::func_attr_inline() && rnd_flipcoin(InlineFunctionProb)) > + if(CGOptions::func_attr_inline() && rnd_flipcoin(FuncAttrInline)) > f->func_attr_inline = true; Are you sure here? Why are you removing InlineFunctionProb of an unrelated option (inline)? > + > + if(CGOptions::func_attr_aligned() && rnd_flipcoin(FuncAttrAligned)) > + f->func_attr_aligned = true; > return f; > }> > @@ -487,8 +492,11 @@ Function::make_first(void) > // collect info about global dangling pointers > fm->find_dangling_global_ptrs(f); > > - if(CGOptions::func_attr_inline() && rnd_flipcoin(InlineFunctionProb)) > + if(CGOptions::func_attr_inline() && rnd_flipcoin(FuncAttrInline)) > f->func_attr_inline = true; Same comment here. > + > + if(CGOptions::func_attr_aligned() && rnd_flipcoin(FuncAttrAligned)) > + f->func_attr_aligned = true; > return f; > } > > @@ -562,6 +570,43 @@ Function::OutputForwardDecl(std::ostream &out) > OutputHeader(out); > if(func_attr_inline) > out << " __attribute__((always_inline))"; > + if(func_attr_aligned){ > + int probability__BIGGEST_ALIGNMENT__ = 38; > + bool use__BIGGEST_ALIGNMENT__ = > rnd_flipcoin(probability__BIGGEST_ALIGNMENT__); > + if (use__BIGGEST_ALIGNMENT__) > + out << " > __attribute__((aligned(__BIGGEST_ALIGNMENT__)))"; > + else{ > + int value = 0; > + int power = rnd_upto(8); > + if (power == 0) > + power++; > + switch (power){ > + case 1: > + value = 2; > + break; > + case 2: > + value = 4; > + break; > + case 3: > + value = 8; > + break; > + case 4: > + value = 16; > + break; > + case 5: > + value = 32; > + break; > + case 6: > + value = 64; > + break; > + case 7: > + value = 128; > + break; You definitely want something like value = (1 << power). > + } > + out << " __attribute__((aligned(" <<value << ")))"; > + } > + > + } > out << ";"; > outputln(out); > } > diff --git a/src/Function.h b/src/Function.h > index 7e40e06..9863a9f 100644 > --- a/src/Function.h > +++ b/src/Function.h > @@ -125,6 +125,7 @@ public: > > //GCC C Extensions > bool func_attr_inline; > + bool func_attr_aligned; > > private: > static int deleteFunction(Function* func); > diff --git a/src/Probabilities.cpp b/src/Probabilities.cpp > index c0e0d27..fd076e8 100644 > --- a/src/Probabilities.cpp > +++ b/src/Probabilities.cpp > @@ -509,6 +509,9 @@ Probabilities::set_single_name_maps() > > //for choosing function attribute inline > set_single_name("func_attr_inline", pFuncAttrInline); > + > + //for choosing function attribute aligned > + set_single_name("func_attr_inline", pFuncAttrAligned); Typo here, "func_attr_inline". I'm going to test the patch in next iteration. Thanks, Martin > } > > void > @@ -551,6 +554,7 @@ Probabilities::initialize_single_probs() > > //GCC C Extensions > m[pFuncAttrInline] = 50; > + m[pFuncAttrAligned] = 50; > > if (CGOptions::volatiles()) > m[pRegularVolatileProb] = 50; > diff --git a/src/Probabilities.h b/src/Probabilities.h > index ef78de6..5ae1038 100644 > --- a/src/Probabilities.h > +++ b/src/Probabilities.h > @@ -149,6 +149,7 @@ enum ProbName { > > //for function attributes > pFuncAttrInline, > + pFuncAttrAligned, > > }; > > @@ -229,6 +230,9 @@ enum ProbName { > #define FuncAttrInline \ > Probabilities::get_prob(pFuncAttrInline) > > +#define FuncAttrAligned \ > + Probabilities::get_prob(pFuncAttrAligned) > + > ////////////////////////////////////////////////// > #define UNARY_OPS_PROB_FILTER \ > Probabilities::get_prob_filter(pUnaryOpsProb) > diff --git a/src/RandomProgramGenerator.cpp b/src/RandomProgramGenerator.cpp > index 442ac64..1f637e9 100644 > --- a/src/RandomProgramGenerator.cpp > +++ b/src/RandomProgramGenerator.cpp > @@ -824,6 +824,17 @@ main(int argc, char **argv) > continue; > } > > + if (strcmp (argv[i], "--func-attr-aligned") == 0) { > + CGOptions::func_attr_aligned(true); > + continue; > + } > + > + if (strcmp (argv[i], "--no-func-attr-aligned") == 0) { > + CGOptions::func_attr_aligned(false); > + continue; > + } > + > + > if (strcmp (argv[i], "--max-array-dim") ==0 ) { > unsigned long dim; > i++; >