Commit 0bb4d46
committed
[clang] perform semantic checking in constant context
Summary:
Since the addition of __builtin_is_constant_evaluated the result of an expression can change based on whether it is evaluated in constant context. a lot of semantic checking performs evaluations with out specifying context. which can lead to wrong diagnostics.
for example:
```
constexpr int i0 = (long long)__builtin_is_constant_evaluated() * (1ll << 33); //#1
constexpr int i1 = (long long)!__builtin_is_constant_evaluated() * (1ll << 33); //#2
```
before the patch, #2 was diagnosed incorrectly and #1 wasn't diagnosed.
after the patch #1 is diagnosed as it should and #2 isn't.
Changes:
- add a flag to Sema to passe in constant context mode.
- in SemaChecking.cpp calls to Expr::Evaluate* are now done in constant context when they should.
- in SemaChecking.cpp diagnostics for UB are not checked for in constant context because an error will be emitted by the constant evaluator.
- in SemaChecking.cpp diagnostics for construct that cannot appear in constant context are not checked for in constant context.
- in SemaChecking.cpp diagnostics on constant expression are always emitted because constant expression are always evaluated.
- semantic checking for initialization of constexpr variables is now done in constant context.
- adapt test that were depending on warning changes.
- add test.
Reviewers: rsmith
Reviewed By: rsmith
Subscribers: cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D62009
llvm-svn: 3634881 parent e1aa69f commit 0bb4d46
File tree
8 files changed
+215
-96
lines changed- clang
- include/clang
- AST
- Basic
- Sema
- lib
- AST
- Sema
- test/SemaCXX
8 files changed
+215
-96
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
599 | 599 | | |
600 | 600 | | |
601 | 601 | | |
602 | | - | |
| 602 | + | |
| 603 | + | |
603 | 604 | | |
604 | 605 | | |
605 | 606 | | |
| |||
611 | 612 | | |
612 | 613 | | |
613 | 614 | | |
614 | | - | |
| 615 | + | |
| 616 | + | |
615 | 617 | | |
616 | 618 | | |
617 | 619 | | |
618 | 620 | | |
619 | | - | |
620 | | - | |
621 | | - | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
622 | 624 | | |
623 | 625 | | |
624 | 626 | | |
625 | | - | |
626 | | - | |
627 | | - | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
628 | 630 | | |
629 | 631 | | |
630 | 632 | | |
| |||
660 | 662 | | |
661 | 663 | | |
662 | 664 | | |
663 | | - | |
| 665 | + | |
| 666 | + | |
664 | 667 | | |
665 | 668 | | |
666 | 669 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
| 88 | + | |
| 89 | + | |
88 | 90 | | |
89 | 91 | | |
90 | 92 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
797 | 797 | | |
798 | 798 | | |
799 | 799 | | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
800 | 809 | | |
801 | 810 | | |
802 | 811 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| 50 | + | |
50 | 51 | | |
51 | 52 | | |
52 | 53 | | |
| |||
5091 | 5092 | | |
5092 | 5093 | | |
5093 | 5094 | | |
5094 | | - | |
5095 | | - | |
| 5095 | + | |
| 5096 | + | |
5096 | 5097 | | |
| 5098 | + | |
| 5099 | + | |
| 5100 | + | |
| 5101 | + | |
| 5102 | + | |
| 5103 | + | |
| 5104 | + | |
| 5105 | + | |
| 5106 | + | |
| 5107 | + | |
| 5108 | + | |
| 5109 | + | |
| 5110 | + | |
| 5111 | + | |
| 5112 | + | |
| 5113 | + | |
5097 | 5114 | | |
5098 | 5115 | | |
5099 | 5116 | | |
| |||
5102 | 5119 | | |
5103 | 5120 | | |
5104 | 5121 | | |
| 5122 | + | |
| 5123 | + | |
| 5124 | + | |
| 5125 | + | |
| 5126 | + | |
| 5127 | + | |
| 5128 | + | |
5105 | 5129 | | |
5106 | 5130 | | |
5107 | 5131 | | |
| |||
5114 | 5138 | | |
5115 | 5139 | | |
5116 | 5140 | | |
5117 | | - | |
| 5141 | + | |
5118 | 5142 | | |
5119 | 5143 | | |
5120 | 5144 | | |
| |||
5338 | 5362 | | |
5339 | 5363 | | |
5340 | 5364 | | |
5341 | | - | |
| 5365 | + | |
5342 | 5366 | | |
5343 | 5367 | | |
5344 | 5368 | | |
| |||
11855 | 11879 | | |
11856 | 11880 | | |
11857 | 11881 | | |
11858 | | - | |
11859 | | - | |
| 11882 | + | |
| 11883 | + | |
11860 | 11884 | | |
11861 | 11885 | | |
11862 | 11886 | | |
11863 | | - | |
| 11887 | + | |
11864 | 11888 | | |
11865 | 11889 | | |
11866 | 11890 | | |
11867 | 11891 | | |
11868 | | - | |
| 11892 | + | |
| 11893 | + | |
11869 | 11894 | | |
11870 | 11895 | | |
11871 | 11896 | | |
| 11897 | + | |
11872 | 11898 | | |
11873 | 11899 | | |
11874 | 11900 | | |
11875 | 11901 | | |
11876 | | - | |
| 11902 | + | |
| 11903 | + | |
11877 | 11904 | | |
11878 | 11905 | | |
11879 | 11906 | | |
| 11907 | + | |
11880 | 11908 | | |
11881 | 11909 | | |
11882 | 11910 | | |
11883 | 11911 | | |
11884 | | - | |
| 11912 | + | |
| 11913 | + | |
11885 | 11914 | | |
11886 | 11915 | | |
11887 | 11916 | | |
11888 | 11917 | | |
11889 | 11918 | | |
11890 | 11919 | | |
11891 | 11920 | | |
11892 | | - | |
| 11921 | + | |
| 11922 | + | |
11893 | 11923 | | |
11894 | 11924 | | |
11895 | 11925 | | |
11896 | 11926 | | |
11897 | 11927 | | |
11898 | 11928 | | |
11899 | 11929 | | |
11900 | | - | |
| 11930 | + | |
| 11931 | + | |
11901 | 11932 | | |
11902 | 11933 | | |
11903 | 11934 | | |
11904 | 11935 | | |
11905 | | - | |
| 11936 | + | |
11906 | 11937 | | |
11907 | 11938 | | |
11908 | 11939 | | |
| |||
12685 | 12716 | | |
12686 | 12717 | | |
12687 | 12718 | | |
12688 | | - | |
| 12719 | + | |
12689 | 12720 | | |
12690 | 12721 | | |
12691 | 12722 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
158 | 158 | | |
159 | 159 | | |
160 | 160 | | |
| 161 | + | |
161 | 162 | | |
162 | 163 | | |
163 | 164 | | |
| |||
0 commit comments