From 5a4f80b31636d30d2a719dc7e840e5d8bc462570 Mon Sep 17 00:00:00 2001 From: Xusong Wang Date: Tue, 10 Nov 2020 11:25:05 -0800 Subject: Have slang emit a warning on renderscript deprecation. This CL modifies the slang compiler to emit a warning on renderscript deprecation. The warning can be suppressed by supplying "-Wno-deprecated-declarations". Bug: 183116940 Test: m Test: CtsRenderscriptTestCases Test: CtsRsCppTestCases Test: CtsRsBlasTestCases Change-Id: Idfd79040b56d256f11c4ece4a34c593296b2bb89 (cherry picked from commit 19ea0eb8a663643788314e71b3e0c058d833a420) --- llvm-rs-cc.cpp | 10 ++++++++++ rs_cc_options.cpp | 5 +++++ tests/P_warnings_deprecated/deprecated.rscript | 2 +- tests/P_warnings_deprecated/stderr.txt.expect | 1 + tests/slang_test.py | 2 +- 5 files changed, 18 insertions(+), 2 deletions(-) diff --git a/llvm-rs-cc.cpp b/llvm-rs-cc.cpp index a51e672..0c1143d 100644 --- a/llvm-rs-cc.cpp +++ b/llvm-rs-cc.cpp @@ -14,6 +14,7 @@ * limitations under the License. */ +#include "clang/Basic/AllDiagnostics.h" #include "clang/Basic/DiagnosticOptions.h" #include "clang/Driver/DriverDiagnostic.h" #include "clang/Driver/Options.h" @@ -223,6 +224,14 @@ extern "C" const char *__asan_default_options() { return "detect_leaks=0"; } +static void emitDeprecationWarning(clang::DiagnosticsEngine *DiagEngine) { + DiagEngine->Report(clang::diag::warn_deprecated_message) + << "Renderscript" + << "Please refer to the migration guide " + "(https://developer.android.com/guide/topics/renderscript/migration-guide) " + "for the proposed alternatives."; +} + int main(int argc, const char **argv) { llvm::llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. LLVMInitializeARMTargetInfo(); @@ -263,6 +272,7 @@ int main(int argc, const char **argv) { (void)DiagEngine.setSeverityForGroup(clang::diag::Flavor::WarningOrError, "implicit-function-declaration", clang::diag::Severity::Error); + emitDeprecationWarning(&DiagEngine); // Report error if no input file if (Inputs.empty()) { diff --git a/rs_cc_options.cpp b/rs_cc_options.cpp index f84294b..ad1dc13 100644 --- a/rs_cc_options.cpp +++ b/rs_cc_options.cpp @@ -133,6 +133,11 @@ bool ParseArguments(const llvm::ArrayRef &ArgsIn, // employ/encourage this extension for zero-initialization of structures. DiagOpts.Warnings.push_back("no-gnu-empty-initializer"); + // Always turn deprecation warning into a warning even if -Werror is specified. + // This is because we will always emit RenderScript deprecation warning, and turning + // it into an error will make the compilation always fail. + DiagOpts.Warnings.push_back("no-error=deprecated-declarations"); + for (llvm::opt::ArgList::const_iterator it = Args.begin(), ie = Args.end(); it != ie; ++it) { const llvm::opt::Arg *A = *it; diff --git a/tests/P_warnings_deprecated/deprecated.rscript b/tests/P_warnings_deprecated/deprecated.rscript index 4e5f5af..03f0185 100644 --- a/tests/P_warnings_deprecated/deprecated.rscript +++ b/tests/P_warnings_deprecated/deprecated.rscript @@ -1,4 +1,4 @@ -// -target-api 22 +// -target-api 22 -Wdeprecated-declarations #pragma version(1) #pragma rs java_package_name(foo) diff --git a/tests/P_warnings_deprecated/stderr.txt.expect b/tests/P_warnings_deprecated/stderr.txt.expect index ca4afee..4241202 100644 --- a/tests/P_warnings_deprecated/stderr.txt.expect +++ b/tests/P_warnings_deprecated/stderr.txt.expect @@ -1,3 +1,4 @@ +warning: Renderscript is deprecated: Please refer to the migration guide (https://developer.android.com/guide/topics/renderscript/migration-guide) for the proposed alternatives. deprecated.rscript:9:9: warning: 'rsClamp' is deprecated: Use clamp() instead. ../../../../../frameworks/rs/script_api/include/rs_math.rsh:6482:5: note: 'rsClamp' has been explicitly marked deprecated here deprecated.rscript:10:8: warning: 'rsGetAllocation' is deprecated: This function is deprecated and will be removed from the SDK in a future release. diff --git a/tests/slang_test.py b/tests/slang_test.py index 82593cc..628ec7f 100755 --- a/tests/slang_test.py +++ b/tests/slang_test.py @@ -163,7 +163,7 @@ GetOutDir.cache = None def CreateCmd(): """Creates the test command to run for the current test.""" - cmd_string = ('%s/bin/llvm-rs-cc -o tmp/ -p tmp/ -MD ' + cmd_string = ('%s/bin/llvm-rs-cc -o tmp/ -p tmp/ -MD -Wno-deprecated-declarations ' '-I ../../../../../frameworks/rs/script_api/include/ ' '-I ../../../../../external/clang/lib/Headers/') % GetOutDir() base_args = cmd_string.split() -- cgit v1.2.3