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
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 @@
     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 @@
   (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 @@
   // 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 @@
 
 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()