Skip to content

Commit 5e8e74e

Browse files
Elvand-Lievgvassilev
authored andcommitted
Guard TBR analysis for untracked pointers
1 parent 5b0fbe0 commit 5e8e74e

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

lib/Differentiator/AnalysisBase.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,12 @@ bool AnalysisBase::getIDSequence(const clang::Expr* E, const VarDecl*& VD,
169169
QualType VDType = VD->getType();
170170
if (VDType->isLValueReferenceType() || VDType->isPointerType()) {
171171
VarData* refData = getVarDataFromDecl(VD);
172+
// Globals and other untracked declarations have no VarData.
173+
if (!refData) {
174+
IDSequence.clear();
175+
VD = nullptr;
176+
return false;
177+
}
172178
if (refData->m_Type == VarData::REF_TYPE) {
173179
std::set<const VarDecl*>& vars = *refData->m_Val.m_RefData;
174180
if (vars.size() == 1) {

test/Regressions/issue-1855.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %cladclang -fsyntax-only -std=c++17 -I%S/../../include %s
2+
3+
#include "clad/Differentiator/Differentiator.h"
4+
5+
int* global_ptr;
6+
7+
void use(int*) {}
8+
9+
double fn(double x) {
10+
use(global_ptr);
11+
return x * x;
12+
}
13+
14+
void test() {
15+
auto grad_fn = clad::gradient(fn);
16+
}

0 commit comments

Comments
 (0)