This is an archive of the discontinued LLVM Phabricator instance.

Modify StepsLeft counter behaivior for constexprs
Needs ReviewPublic

Authored by wasiher on May 30 2019, 9:51 AM.

Details

Reviewers
rsmith
Group Reviewers
Restricted Project
Summary

When I was trying to remove limits from constexpr steps (I wanted to give compiler as much time as it it needs), I found -fconstexpr-steps option.
Naively i decided that -fconstexpr-steps=-1 is the best solution for this, because clang worked fine with my big constexpr function, and was not stopping. But when I checked source code, I understood that it is integer overflow, and compilation will stop with error some day even if I will try to compile "while(1);" like code.

In the source code step limit is accesed as signed interger:
Opts.ConstexprStepLimit = getLastArgIntValue(Args, OPT_fconstexpr_steps, 1048576, Diags);

But later unsigned variable StepsLeft based on ConstexprStepLimit used as counter.

So maybe it will be better to make StepsLeft signed int?
In the negative case StepsLeft decrement will be disabled.

I also thought about making zero value to have same behavior, but such behavior was not declared anywhere before, and zero value probably can be used by someone as disabler of constexpr for example. But in the current implementation of clang negative value is not prohibited, but usage probably would not produce right expectation for user.

Diff Detail

Event Timeline

wasiher created this revision.May 30 2019, 9:51 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 30 2019, 9:51 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
wasiher added a reviewer: Restricted Project.May 30 2019, 9:53 AM