[PATCH] Support constant expressions, including non-type template parameters, in pragma loop hints

Aaron Ballman aaron at aaronballman.com
Wed Jul 30 15:12:37 PDT 2014


On Wed, Jul 30, 2014 at 5:58 PM, Tyler Nowicki <tnowicki at apple.com> wrote:
> Hi Aaron,
>
> Thanks for the review! I applied your suggestions except for the following.
>
>>> #include "clang/AST/Decl.h"
>>> +#include "clang/AST/Expr.h"
>>
>> This include should not be required here.
>
> This is required to call printPretty on the value expression in LoopHintAttr.

Ugh. That's unfortunate. Perhaps ClangAttrEmitter needs to understand
that some AdditionalMembers are meant for the class declaration
(Attrs.inc), and others are meant for the class definition
(AttrImpl.inc)...

>
>>> diff --git a/test/CodeGen/pragma-loop.cpp b/test/CodeGen/pragma-loop.cpp
>>> index b75c7ee..87f2d06 100644
>>> --- a/test/CodeGen/pragma-loop.cpp
>>> +++ b/test/CodeGen/pragma-loop.cpp
>>
>> This file should actually be in CodeGenCXX (especially since it now
>> has templates, etc). I hadn't noticed this before, sorry!
>
> I’ll commit this move first, separately. The attached patch doesn’t have the moved test in it though.

That's fine by me.

>
>> I'd like to see a test added for constant expressions that are a
>> nonsense parsing error, just to make sure we recover properly.
>
> I’m not exactly sure what you mean. I added:
>
> const int VV = 4;
> #pragma clang loop vectorize_width(VV +/ 2)
> #pragma clang loop vectorize_width(VV + undefined)
>
> And pre-existing were tests for
>
> #pragma clang loop vectorize_width(Vec) interleave_count(I)  //Vec is undefined
> #pragma clang loop vectorize_width(Vec) interleave_count(Int) //Int is undefined
> #pragma clang loop vectorize_width(1 +) 1
> #pragma clang loop vectorize_width(1) +1
> #pragma clang loop interleave(*)
> #pragma clang loop unroll(=)
> #pragma clang loop vectorize_width(^)
> #pragma clang loop interleave_count(/)
> #pragma clang loop unroll_count(==)
>
> Is there any other constant expressions you think I should test?

I was thinking of parsing nonsense (like a fuzzer):

#pragma clang loop vectorize_width(1+(^*/2 * ()
#pragma clang loop vectorize_width(1+(-0[0]))))))

Just to ensure that we always recover gracefully from crazy input.

~Aaron




More information about the cfe-commits mailing list