HLSL: Allow macro expansions to create the 'defined' operator.
diff --git a/Test/baseResults/hlsl.pp.vert.out b/Test/baseResults/hlsl.pp.vert.out
new file mode 100755
index 0000000..5518636
--- /dev/null
+++ b/Test/baseResults/hlsl.pp.vert.out
@@ -0,0 +1,61 @@
+hlsl.pp.vert
+Shader version: 500
+0:? Sequence
+0:17  Function Definition: @main( ( temp void)
+0:17    Function Parameters: 
+0:17  Function Definition: main( ( temp void)
+0:17    Function Parameters: 
+0:?     Sequence
+0:17      Function Call: @main( ( temp void)
+0:?   Linker Objects
+0:?     'anon@0' (layout( row_major std140) uniform block{ uniform int goodGlobal1,  uniform int goodGlobal2})
+
+
+Linked vertex stage:
+
+
+Shader version: 500
+0:? Sequence
+0:17  Function Definition: @main( ( temp void)
+0:17    Function Parameters: 
+0:17  Function Definition: main( ( temp void)
+0:17    Function Parameters: 
+0:?     Sequence
+0:17      Function Call: @main( ( temp void)
+0:?   Linker Objects
+0:?     'anon@0' (layout( row_major std140) uniform block{ uniform int goodGlobal1,  uniform int goodGlobal2})
+
+// Module Version 10000
+// Generated by (magic number): 80001
+// Id's are bound by 13
+
+                              Capability Shader
+               1:             ExtInstImport  "GLSL.std.450"
+                              MemoryModel Logical GLSL450
+                              EntryPoint Vertex 4  "main"
+                              Source HLSL 500
+                              Name 4  "main"
+                              Name 6  "@main("
+                              Name 10  "$Global"
+                              MemberName 10($Global) 0  "goodGlobal1"
+                              MemberName 10($Global) 1  "goodGlobal2"
+                              Name 12  ""
+                              MemberDecorate 10($Global) 0 Offset 0
+                              MemberDecorate 10($Global) 1 Offset 4
+                              Decorate 10($Global) Block
+                              Decorate 12 DescriptorSet 0
+               2:             TypeVoid
+               3:             TypeFunction 2
+               9:             TypeInt 32 1
+     10($Global):             TypeStruct 9(int) 9(int)
+              11:             TypePointer Uniform 10($Global)
+              12:     11(ptr) Variable Uniform
+         4(main):           2 Function None 3
+               5:             Label
+               8:           2 FunctionCall 6(@main()
+                              Return
+                              FunctionEnd
+       6(@main():           2 Function None 3
+               7:             Label
+                              Return
+                              FunctionEnd
diff --git a/Test/hlsl.pp.vert b/Test/hlsl.pp.vert
new file mode 100644
index 0000000..4b0a451
--- /dev/null
+++ b/Test/hlsl.pp.vert
@@ -0,0 +1,17 @@
+#define A defined(B)
+
+#if A
+int badGlobal1;
+#else
+int goodGlobal1;
+#endif
+
+#define B
+
+#if A
+int goodGlobal2;
+#else
+int badGlobal2;
+#endif
+
+void main() {}
diff --git a/glslang/MachineIndependent/preprocessor/Pp.cpp b/glslang/MachineIndependent/preprocessor/Pp.cpp
index 5c6e247..34a9299 100644
--- a/glslang/MachineIndependent/preprocessor/Pp.cpp
+++ b/glslang/MachineIndependent/preprocessor/Pp.cpp
@@ -393,7 +393,7 @@
     TSourceLoc loc = ppToken->loc;  // because we sometimes read the newline before reporting the error
     if (token == PpAtomIdentifier) {
         if (strcmp("defined", ppToken->name) == 0) {
-            if (isMacroInput()) {
+            if (! parseContext.isReadingHLSL() && isMacroInput()) {
                 if (parseContext.relaxedErrors())
                     parseContext.ppWarn(ppToken->loc, "nonportable when expanded from macros for preprocessor expression",
                                                       "defined", "");
diff --git a/gtests/Hlsl.FromFile.cpp b/gtests/Hlsl.FromFile.cpp
index efd2000..51f9d49 100644
--- a/gtests/Hlsl.FromFile.cpp
+++ b/gtests/Hlsl.FromFile.cpp
@@ -200,6 +200,7 @@
         {"hlsl.params.default.frag", "main"},
         {"hlsl.params.default.negative.frag", "main"},
         {"hlsl.partialInit.frag", "PixelShaderFunction"},
+        {"hlsl.pp.vert", "main"},
         {"hlsl.pp.line.frag", "main"},
         {"hlsl.precise.frag", "main"},
         {"hlsl.promote.atomic.frag", "main"},