Skip to content

Commit 09e7d75

Browse files
committed
[clang][Interp] Don't add 'in call to' diagnostics for builtin frames
1 parent ac6b4c6 commit 09e7d75

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

clang/lib/AST/Interp/InterpFrame.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,13 @@ void print(llvm::raw_ostream &OS, const Pointer &P, ASTContext &Ctx,
152152
}
153153

154154
void InterpFrame::describe(llvm::raw_ostream &OS) const {
155+
// We create frames for builtin functions as well, but we can't reliably
156+
// diagnose them. The 'in call to' diagnostics for them add no value to the
157+
// user _and_ it doesn't generally work since the argument types don't always
158+
// match the function prototype. Just ignore them.
159+
if (const auto *F = getFunction(); F && F->isBuiltin())
160+
return;
161+
155162
const FunctionDecl *F = getCallee();
156163
if (const auto *M = dyn_cast<CXXMethodDecl>(F);
157164
M && M->isInstance() && !isa<CXXConstructorDecl>(F)) {

clang/lib/AST/Interp/State.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ void State::addCallStack(unsigned Limit) {
155155
SmallString<128> Buffer;
156156
llvm::raw_svector_ostream Out(Buffer);
157157
F->describe(Out);
158-
addDiag(CallRange.getBegin(), diag::note_constexpr_call_here)
159-
<< Out.str() << CallRange;
158+
if (!Buffer.empty())
159+
addDiag(CallRange.getBegin(), diag::note_constexpr_call_here)
160+
<< Out.str() << CallRange;
160161
}
161162
}

clang/test/AST/Interp/builtin-functions.cpp

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,13 @@ namespace strcmp {
2424
static_assert(__builtin_strcmp("abab", "abab\0banana") == 0, "");
2525
static_assert(__builtin_strcmp("abab\0banana", "abab\0canada") == 0, "");
2626
static_assert(__builtin_strcmp(0, "abab") == 0, ""); // both-error {{not an integral constant}} \
27-
// both-note {{dereferenced null}} \
28-
// expected-note {{in call to}}
27+
// both-note {{dereferenced null}}
2928
static_assert(__builtin_strcmp("abab", 0) == 0, ""); // both-error {{not an integral constant}} \
30-
// both-note {{dereferenced null}} \
31-
// expected-note {{in call to}}
29+
// both-note {{dereferenced null}}
3230

3331
static_assert(__builtin_strcmp(kFoobar, kFoobazfoobar) == -1, "");
3432
static_assert(__builtin_strcmp(kFoobar, kFoobazfoobar + 6) == 0, ""); // both-error {{not an integral constant}} \
35-
// both-note {{dereferenced one-past-the-end}} \
36-
// expected-note {{in call to}}
33+
// both-note {{dereferenced one-past-the-end}}
3734

3835
/// Used to assert because we're passing a dummy pointer to
3936
/// __builtin_strcmp() when evaluating the return statement.
@@ -72,14 +69,11 @@ constexpr const char *a = "foo\0quux";
7269
static_assert(check(c), "");
7370

7471
constexpr int over1 = __builtin_strlen(a + 9); // both-error {{constant expression}} \
75-
// both-note {{one-past-the-end}} \
76-
// expected-note {{in call to}}
72+
// both-note {{one-past-the-end}}
7773
constexpr int over2 = __builtin_strlen(b + 9); // both-error {{constant expression}} \
78-
// both-note {{one-past-the-end}} \
79-
// expected-note {{in call to}}
74+
// both-note {{one-past-the-end}}
8075
constexpr int over3 = __builtin_strlen(c + 9); // both-error {{constant expression}} \
81-
// both-note {{one-past-the-end}} \
82-
// expected-note {{in call to}}
76+
// both-note {{one-past-the-end}}
8377

8478
constexpr int under1 = __builtin_strlen(a - 1); // both-error {{constant expression}} \
8579
// both-note {{cannot refer to element -1}}
@@ -90,8 +84,7 @@ constexpr const char *a = "foo\0quux";
9084

9185
constexpr char d[] = { 'f', 'o', 'o' }; // no nul terminator.
9286
constexpr int bad = __builtin_strlen(d); // both-error {{constant expression}} \
93-
// both-note {{one-past-the-end}} \
94-
// expected-note {{in call to}}
87+
// both-note {{one-past-the-end}}
9588
}
9689

9790
namespace nan {
@@ -114,8 +107,7 @@ namespace nan {
114107
/// FIXME: Current interpreter misses diagnostics.
115108
constexpr char f2[] = {'0', 'x', 'A', 'E'}; /// No trailing 0 byte.
116109
constexpr double NaN7 = __builtin_nan(f2); // both-error {{must be initialized by a constant expression}} \
117-
// expected-note {{read of dereferenced one-past-the-end pointer}} \
118-
// expected-note {{in call to}}
110+
// expected-note {{read of dereferenced one-past-the-end pointer}}
119111
static_assert(!__builtin_issignaling(__builtin_nan("")), "");
120112
static_assert(__builtin_issignaling(__builtin_nans("")), "");
121113
}

0 commit comments

Comments
 (0)