aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Gross <dgross@google.com>2016-02-18 14:00:32 -0800
committerDavid Gross <dgross@google.com>2016-02-19 16:03:19 -0800
commit8d7fe847327eeb07c5a4770c31235dc28d570c97 (patch)
treecde573a34f3a229056e84b637a67aecc75b91ed1
parentc545d6f10fa4827de235b5f85b58e803eba725bc (diff)
downloadlibbcc-8d7fe847327eeb07c5a4770c31235dc28d570c97.tar.gz
Metadata extractor must tolerate missing accumulator function.
Looking up a general reduction accumulator function by name can fail, just as looking up a foreach kernel function by name can fail: One of the uses of MetadataExtractor is as part of the RSEmbedInfoPass, which bcc_compat runs sufficiently late in the phase order that RSKernelExpandPass has already run and the original (UNexpanded) accumulator function may have been deleted as having no references (if it has been inlined into the expanded accumulator function and is otherwise unreferenced). Bug: 23535724 (cherry picked from commit 34383a2fcec623b8696308d36e9522afb0c5b23d) Change-Id: If9eba2bfca4c591de7bd5a464cf76e45007b3295
-rw-r--r--bcinfo/MetadataExtractor.cpp22
1 files changed, 17 insertions, 5 deletions
diff --git a/bcinfo/MetadataExtractor.cpp b/bcinfo/MetadataExtractor.cpp
index 95ef57d..500dd5a 100644
--- a/bcinfo/MetadataExtractor.cpp
+++ b/bcinfo/MetadataExtractor.cpp
@@ -463,6 +463,14 @@ bool MetadataExtractor::populateForEachMetadata(
if (Name != nullptr && Name->getNumOperands() == 1) {
TmpNameList[i] = createStringFromValue(Name->getOperand(0));
+ // Note that looking up the function by name can fail: One of
+ // the uses of MetadataExtractor is as part of the
+ // RSEmbedInfoPass, which bcc_compat runs sufficiently late in
+ // the phase order that RSKernelExpandPass has already run and
+ // the original (UNexpanded) kernel function (TmpNameList[i])
+ // may have been deleted as having no references (if it has
+ // been inlined into the expanded kernel function and is
+ // otherwise unreferenced).
llvm::Function *Func =
mModule->getFunction(llvm::StringRef(TmpNameList[i]));
@@ -523,15 +531,19 @@ bool MetadataExtractor::populateReduceNewMetadata(const llvm::NamedMDNode *Reduc
ALOGE("Non-integer signature value in reduce metadata");
return false;
}
+ // Note that looking up the function by name can fail: One of the
+ // uses of MetadataExtractor is as part of the RSEmbedInfoPass,
+ // which bcc_compat runs sufficiently late in the phase order that
+ // RSKernelExpandPass has already run and the original
+ // (UNexpanded) accumulator function (mAccumulatorName) may have
+ // been deleted as having no references (if it has been inlined
+ // into the expanded accumulator function and is otherwise
+ // unreferenced).
llvm::Function *Func =
mModule->getFunction(llvm::StringRef(TmpReduceNewList[i].mAccumulatorName));
- if (!Func) {
- ALOGE("reduce metadata names missing accumulator function");
- return false;
- }
// Why calculateNumInputs() - 1? The "-1" is because we don't
// want to treat the accumulator argument as an input.
- TmpReduceNewList[i].mInputCount = calculateNumInputs(Func, TmpReduceNewList[i].mSignature) - 1;
+ TmpReduceNewList[i].mInputCount = (Func ? calculateNumInputs(Func, TmpReduceNewList[i].mSignature) - 1 : 0);
TmpReduceNewList[i].mInitializerName = createStringFromOptionalValue(Node, 3);
TmpReduceNewList[i].mCombinerName = createStringFromOptionalValue(Node, 4);